Commit 707ecf46 authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

V4L/DVB (8941): mxb/tda9840: cleanups, use module saa7115 instead of saa7111.

Cleanup tda9840 and use a v4l2 API to get the tuner subchannels.
Do some cleanups in mxb and switch to saa7115 instead of the saa7111
module.
Signed-off-by: default avatarHans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 6bd6dff6
...@@ -691,7 +691,7 @@ config VIDEO_MXB ...@@ -691,7 +691,7 @@ config VIDEO_MXB
depends on PCI && VIDEO_V4L1 && I2C depends on PCI && VIDEO_V4L1 && I2C
select VIDEO_SAA7146_VV select VIDEO_SAA7146_VV
select VIDEO_TUNER select VIDEO_TUNER
select VIDEO_SAA7111 if VIDEO_HELPER_CHIPS_AUTO select VIDEO_SAA7115 if VIDEO_HELPER_CHIPS_AUTO
select VIDEO_TDA9840 if VIDEO_HELPER_CHIPS_AUTO select VIDEO_TDA9840 if VIDEO_HELPER_CHIPS_AUTO
select VIDEO_TEA6415C if VIDEO_HELPER_CHIPS_AUTO select VIDEO_TEA6415C if VIDEO_HELPER_CHIPS_AUTO
select VIDEO_TEA6420 if VIDEO_HELPER_CHIPS_AUTO select VIDEO_TEA6420 if VIDEO_HELPER_CHIPS_AUTO
......
This diff is collapsed.
...@@ -47,6 +47,15 @@ MODULE_PARM_DESC(debug, "Debug level (0-1)"); ...@@ -47,6 +47,15 @@ MODULE_PARM_DESC(debug, "Debug level (0-1)");
#define STEREO_ADJUST 0x03 #define STEREO_ADJUST 0x03
#define TEST 0x04 #define TEST 0x04
#define TDA9840_SET_MUTE 0x00
#define TDA9840_SET_MONO 0x10
#define TDA9840_SET_STEREO 0x2a
#define TDA9840_SET_LANG1 0x12
#define TDA9840_SET_LANG2 0x1e
#define TDA9840_SET_BOTH 0x1a
#define TDA9840_SET_BOTH_R 0x16
#define TDA9840_SET_EXTERNAL 0x7a
/* addresses to scan, found only at 0x42 (7-Bit) */ /* addresses to scan, found only at 0x42 (7-Bit) */
static unsigned short normal_i2c[] = { I2C_ADDR_TDA9840, I2C_CLIENT_END }; static unsigned short normal_i2c[] = { I2C_ADDR_TDA9840, I2C_CLIENT_END };
...@@ -62,26 +71,74 @@ static void tda9840_write(struct i2c_client *client, u8 reg, u8 val) ...@@ -62,26 +71,74 @@ static void tda9840_write(struct i2c_client *client, u8 reg, u8 val)
static int tda9840_command(struct i2c_client *client, unsigned cmd, void *arg) static int tda9840_command(struct i2c_client *client, unsigned cmd, void *arg)
{ {
int result; int result = 0;
int byte = *(int *)arg; int byte = *(int *)arg;
switch (cmd) { switch (cmd) {
case TDA9840_SWITCH: case VIDIOC_S_TUNER: {
struct v4l2_tuner *t = arg;
int byte;
if (t->index)
return -EINVAL;
switch (t->audmode) {
case V4L2_TUNER_MODE_STEREO:
byte = TDA9840_SET_STEREO;
break;
case V4L2_TUNER_MODE_LANG1_LANG2:
byte = TDA9840_SET_BOTH;
break;
case V4L2_TUNER_MODE_LANG1:
byte = TDA9840_SET_LANG1;
break;
case V4L2_TUNER_MODE_LANG2:
byte = TDA9840_SET_LANG2;
break;
default:
byte = TDA9840_SET_MONO;
break;
}
v4l_dbg(1, debug, client, "TDA9840_SWITCH: 0x%02x\n", byte); v4l_dbg(1, debug, client, "TDA9840_SWITCH: 0x%02x\n", byte);
tda9840_write(client, SWITCH, byte);
break;
}
case VIDIOC_G_TUNER: {
struct v4l2_tuner *t = arg;
u8 byte;
if (byte != TDA9840_SET_MONO t->rxsubchans = V4L2_TUNER_SUB_MONO;
&& byte != TDA9840_SET_MUTE if (1 != i2c_master_recv(client, &byte, 1)) {
&& byte != TDA9840_SET_STEREO v4l_dbg(1, debug, client,
&& byte != TDA9840_SET_LANG1 "i2c_master_recv() failed\n");
&& byte != TDA9840_SET_LANG2 return -EIO;
&& byte != TDA9840_SET_BOTH }
&& byte != TDA9840_SET_BOTH_R
&& byte != TDA9840_SET_EXTERNAL) { if (byte & 0x80) {
v4l_dbg(1, debug, client,
"TDA9840_DETECT: register contents invalid\n");
return -EINVAL; return -EINVAL;
} }
tda9840_write(client, SWITCH, byte); v4l_dbg(1, debug, client, "TDA9840_DETECT: byte: 0x%02x\n", byte);
switch (byte & 0x60) {
case 0x00:
t->rxsubchans = V4L2_TUNER_SUB_MONO;
break;
case 0x20:
t->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
break;
case 0x40:
t->rxsubchans = V4L2_TUNER_SUB_STEREO | V4L2_TUNER_SUB_MONO;
break;
default: /* Incorrect detect */
t->rxsubchans = V4L2_TUNER_MODE_MONO;
break;
}
break; break;
}
case TDA9840_LEVEL_ADJUST: case TDA9840_LEVEL_ADJUST:
v4l_dbg(1, debug, client, "TDA9840_LEVEL_ADJUST: %d\n", byte); v4l_dbg(1, debug, client, "TDA9840_LEVEL_ADJUST: %d\n", byte);
...@@ -115,36 +172,6 @@ static int tda9840_command(struct i2c_client *client, unsigned cmd, void *arg) ...@@ -115,36 +172,6 @@ static int tda9840_command(struct i2c_client *client, unsigned cmd, void *arg)
tda9840_write(client, STEREO_ADJUST, byte); tda9840_write(client, STEREO_ADJUST, byte);
break; break;
case TDA9840_DETECT: {
int *ret = (int *)arg;
byte = i2c_smbus_read_byte_data(client, STEREO_ADJUST);
if (byte == -1) {
v4l_dbg(1, debug, client,
"i2c_smbus_read_byte_data() failed\n");
return -EIO;
}
if (byte & 0x80) {
v4l_dbg(1, debug, client,
"TDA9840_DETECT: register contents invalid\n");
return -EINVAL;
}
v4l_dbg(1, debug, client, "TDA9840_DETECT: byte: 0x%02x\n", byte);
*ret = (byte & 0x60) >> 5;
result = 0;
break;
}
case TDA9840_TEST:
v4l_dbg(1, debug, client, "TDA9840_TEST: 0x%02x\n", byte);
/* mask out irrelevant bits */
byte &= 0x3;
tda9840_write(client, TEST, byte);
break;
default: default:
return -ENOIOCTLCMD; return -ENOIOCTLCMD;
} }
...@@ -174,8 +201,7 @@ static int tda9840_probe(struct i2c_client *client, ...@@ -174,8 +201,7 @@ static int tda9840_probe(struct i2c_client *client,
byte = 0; byte = 0;
result = tda9840_command(client, TDA9840_LEVEL_ADJUST, &byte); result = tda9840_command(client, TDA9840_LEVEL_ADJUST, &byte);
result += tda9840_command(client, TDA9840_STEREO_ADJUST, &byte); result += tda9840_command(client, TDA9840_STEREO_ADJUST, &byte);
byte = TDA9840_SET_MONO; tda9840_write(client, SWITCH, TDA9840_SET_STEREO);
result = tda9840_command(client, TDA9840_SWITCH, &byte);
if (result) { if (result) {
v4l_dbg(1, debug, client, "could not initialize tda9840\n"); v4l_dbg(1, debug, client, "could not initialize tda9840\n");
return -ENODEV; return -ENODEV;
......
...@@ -3,24 +3,6 @@ ...@@ -3,24 +3,6 @@
#define I2C_ADDR_TDA9840 0x42 #define I2C_ADDR_TDA9840 0x42
#define TDA9840_DETECT _IOR('v',1,int)
/* return values for TDA9840_DETCT */
#define TDA9840_MONO_DETECT 0x0
#define TDA9840_DUAL_DETECT 0x1
#define TDA9840_STEREO_DETECT 0x2
#define TDA9840_INCORRECT_DETECT 0x3
#define TDA9840_SWITCH _IOW('v',2,int)
/* modes than can be set with TDA9840_SWITCH */
#define TDA9840_SET_MUTE 0x00
#define TDA9840_SET_MONO 0x10
#define TDA9840_SET_STEREO 0x2a
#define TDA9840_SET_LANG1 0x12
#define TDA9840_SET_LANG2 0x1e
#define TDA9840_SET_BOTH 0x1a
#define TDA9840_SET_BOTH_R 0x16
#define TDA9840_SET_EXTERNAL 0x7a
/* values may range between +2.5 and -2.0; /* values may range between +2.5 and -2.0;
the value has to be multiplied with 10 */ the value has to be multiplied with 10 */
#define TDA9840_LEVEL_ADJUST _IOW('v',3,int) #define TDA9840_LEVEL_ADJUST _IOW('v',3,int)
...@@ -29,7 +11,4 @@ ...@@ -29,7 +11,4 @@
the value has to be multiplied with 10 */ the value has to be multiplied with 10 */
#define TDA9840_STEREO_ADJUST _IOW('v',4,int) #define TDA9840_STEREO_ADJUST _IOW('v',4,int)
/* currently not implemented */
#define TDA9840_TEST _IOW('v',5,int)
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment