Skip to content

Commit 805d5a0

Browse files
committed
media: si2157: get rid of chiptype data
The driver should be capable of autodetecting its type, so no need to pass it via device driver's data. While here, improve documentation of some of the part_id specific code. Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent 1c35ba3 commit 805d5a0

File tree

2 files changed

+28
-24
lines changed

2 files changed

+28
-24
lines changed

drivers/media/tuners/si2157.c

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ static int si2157_find_and_load_firmware(struct dvb_frontend *fe)
185185
return -EINVAL;
186186
}
187187

188+
/* Update the part id based on device's report */
189+
dev->part_id = part_id;
190+
188191
dev_info(&client->dev,
189192
"found a 'Silicon Labs Si21%d-%c%c%c ROM 0x%02x'\n",
190193
part_id, cmd.args[1], cmd.args[3], cmd.args[4], rom_id);
@@ -235,10 +238,12 @@ static int si2157_init(struct dvb_frontend *fe)
235238
dev->if_frequency = 0; /* we no longer know current tuner state */
236239

237240
/* power up */
238-
if (dev->chiptype == SI2157_CHIPTYPE_SI2146) {
241+
if (dev->part_id == SI2146) {
242+
/* clock_mode = XTAL, clock_freq = 24MHz */
239243
memcpy(cmd.args, "\xc0\x05\x01\x00\x00\x0b\x00\x00\x01", 9);
240244
cmd.wlen = 9;
241-
} else if (dev->chiptype == SI2157_CHIPTYPE_SI2141) {
245+
} else if (dev->part_id == SI2141) {
246+
/* clock_mode: XTAL, xout enabled */
242247
memcpy(cmd.args, "\xc0\x00\x0d\x0e\x00\x01\x01\x01\x01\x03", 10);
243248
cmd.wlen = 10;
244249
} else {
@@ -247,11 +252,11 @@ static int si2157_init(struct dvb_frontend *fe)
247252
}
248253
cmd.rlen = 1;
249254
ret = si2157_cmd_execute(client, &cmd);
250-
if (ret && (dev->chiptype != SI2157_CHIPTYPE_SI2141 || ret != -EAGAIN))
255+
if (ret && (dev->part_id != SI2141 || ret != -EAGAIN))
251256
goto err;
252257

253-
/* Si2141 needs a second command before it answers the revision query */
254-
if (dev->chiptype == SI2157_CHIPTYPE_SI2141) {
258+
/* Si2141 needs a wake up command */
259+
if (dev->part_id == SI2141) {
255260
memcpy(cmd.args, "\xc0\x08\x01\x02\x00\x00\x01", 7);
256261
cmd.wlen = 7;
257262
ret = si2157_cmd_execute(client, &cmd);
@@ -493,7 +498,8 @@ static int si2157_set_params(struct dvb_frontend *fe)
493498
if (ret)
494499
goto err;
495500

496-
if (dev->chiptype == SI2157_CHIPTYPE_SI2146)
501+
/* On SI2146, set DTV AGC source to DLIF_AGC_3DB */
502+
if (dev->part_id == SI2146)
497503
memcpy(cmd.args, "\x14\x00\x02\x07\x00\x01", 6);
498504
else
499505
memcpy(cmd.args, "\x14\x00\x02\x07\x00\x00", 6);
@@ -560,9 +566,9 @@ static int si2157_set_analog_params(struct dvb_frontend *fe,
560566
u8 color = 0; /* 0=NTSC/PAL, 0x10=SECAM */
561567
u8 invert_analog = 1; /* analog tuner spectrum; 0=normal, 1=inverted */
562568

563-
if (dev->chiptype != SI2157_CHIPTYPE_SI2157) {
564-
dev_info(&client->dev, "Analog tuning not supported for chiptype=%u\n",
565-
dev->chiptype);
569+
if (dev->part_id != SI2157) {
570+
dev_info(&client->dev, "Analog tuning not supported yet for Si21%d\n",
571+
dev->part_id);
566572
ret = -EINVAL;
567573
goto err;
568574
}
@@ -874,7 +880,7 @@ static int si2157_probe(struct i2c_client *client,
874880
dev->inversion = cfg->inversion;
875881
dev->dont_load_firmware = cfg->dont_load_firmware;
876882
dev->if_port = cfg->if_port;
877-
dev->chiptype = (u8)id->driver_data;
883+
dev->part_id = (u8)id->driver_data;
878884
dev->if_frequency = 5000000; /* default value of property 0x0706 */
879885
mutex_init(&dev->i2c_mutex);
880886
INIT_DELAYED_WORK(&dev->stat_work, si2157_stat_work);
@@ -917,10 +923,8 @@ static int si2157_probe(struct i2c_client *client,
917923
}
918924
#endif
919925

920-
dev_info(&client->dev, "Silicon Labs %s successfully attached\n",
921-
dev->chiptype == SI2157_CHIPTYPE_SI2141 ? "Si2141" :
922-
dev->chiptype == SI2157_CHIPTYPE_SI2146 ?
923-
"Si2146" : "Si2147/2148/2157/2158");
926+
dev_info(&client->dev, "Silicon Labs Si21%d successfully attached\n",
927+
dev->part_id);
924928

925929
return 0;
926930

@@ -953,11 +957,16 @@ static int si2157_remove(struct i2c_client *client)
953957
return 0;
954958
}
955959

960+
/*
961+
* The part_id used here will only be used on buggy devices that don't
962+
* accept firmware uploads. Non-buggy devices should just use "si2157" for
963+
* all SiLabs TER tuners, as the driver should auto-detect it.
964+
*/
956965
static const struct i2c_device_id si2157_id_table[] = {
957-
{"si2157", SI2157_CHIPTYPE_SI2157},
958-
{"si2146", SI2157_CHIPTYPE_SI2146},
959-
{"si2141", SI2157_CHIPTYPE_SI2141},
960-
{"si2177", SI2157_CHIPTYPE_SI2177},
966+
{"si2157", SI2157},
967+
{"si2146", SI2146},
968+
{"si2141", SI2141},
969+
{"si2177", SI2177},
961970
{}
962971
};
963972
MODULE_DEVICE_TABLE(i2c, si2157_id_table);

drivers/media/tuners/si2157_priv.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct si2157_dev {
2626
unsigned int active:1;
2727
unsigned int inversion:1;
2828
unsigned int dont_load_firmware:1;
29-
u8 chiptype;
29+
u8 part_id;
3030
u8 if_port;
3131
u32 if_frequency;
3232
u32 bandwidth;
@@ -58,11 +58,6 @@ struct si2157_tuner_info {
5858
const char *fw_name, *fw_alt_name;
5959
};
6060

61-
#define SI2157_CHIPTYPE_SI2157 0
62-
#define SI2157_CHIPTYPE_SI2146 1
63-
#define SI2157_CHIPTYPE_SI2141 2
64-
#define SI2157_CHIPTYPE_SI2177 3
65-
6661
/* firmware command struct */
6762
#define SI2157_ARGLEN 30
6863
struct si2157_cmd {

0 commit comments

Comments
 (0)