Skip to content

Commit af29486

Browse files
Jean DelvareJean Delvare
authored andcommitted
i2c: Convert remaining new-style drivers to use module aliasing
Update all the remaining new-style i2c drivers to use standard module aliasing instead of the old driver_name/type driver matching scheme. Note that the tuner driver is a bit quirky at the moment, as it overwrites i2c_client.name with arbitrary strings. We write "tuner" back on remove, to make sure that driver cycling will work properly, but there may still be troublesome corner cases. Signed-off-by: Jean Delvare <khali@linux-fr.org>
1 parent 238a871 commit af29486

16 files changed

Lines changed: 143 additions & 39 deletions

File tree

‎drivers/media/video/cs5345.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,17 @@ static int cs5345_probe(struct i2c_client *client,
160160

161161
/* ----------------------------------------------------------------------- */
162162

163+
static const struct i2c_device_id cs5345_id[] = {
164+
{ "cs5345", 0 },
165+
{ }
166+
};
167+
MODULE_DEVICE_TABLE(i2c, cs5345_id);
168+
163169
static struct v4l2_i2c_driver_data v4l2_i2c_data = {
164170
.name = "cs5345",
165171
.driverid = I2C_DRIVERID_CS5345,
166172
.command = cs5345_command,
167173
.probe = cs5345_probe,
174+
.id_table = cs5345_id,
168175
};
169176

‎drivers/media/video/cs53l32a.c‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ static int cs53l32a_probe(struct i2c_client *client,
144144
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
145145
return -EIO;
146146

147-
snprintf(client->name, sizeof(client->name) - 1, "cs53l32a");
147+
if (!id)
148+
strlcpy(client->name, "cs53l32a", sizeof(client->name));
148149

149150
v4l_info(client, "chip found @ 0x%x (%s)\n",
150151
client->addr << 1, client->adapter->name);
@@ -175,10 +176,17 @@ static int cs53l32a_probe(struct i2c_client *client,
175176
return 0;
176177
}
177178

179+
static const struct i2c_device_id cs53l32a_id[] = {
180+
{ "cs53l32a", 0 },
181+
{ }
182+
};
183+
MODULE_DEVICE_TABLE(i2c, cs53l32a_id);
184+
178185
static struct v4l2_i2c_driver_data v4l2_i2c_data = {
179186
.name = "cs53l32a",
180187
.driverid = I2C_DRIVERID_CS53L32A,
181188
.command = cs53l32a_command,
182189
.probe = cs53l32a_probe,
190+
.id_table = cs53l32a_id,
183191
};
184192

‎drivers/media/video/cx18/cx18-i2c.c‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static const u8 hw_bus[] = {
7474
};
7575

7676
/* This array should match the CX18_HW_ defines */
77-
static const char * const hw_drivernames[] = {
77+
static const char * const hw_devicenames[] = {
7878
"tuner",
7979
"tveeprom",
8080
"cs5345",
@@ -95,8 +95,7 @@ int cx18_i2c_register(struct cx18 *cx, unsigned idx)
9595
id = hw_driverids[idx];
9696
bus = hw_bus[idx];
9797
memset(&info, 0, sizeof(info));
98-
strlcpy(info.driver_name, hw_drivernames[idx],
99-
sizeof(info.driver_name));
98+
strlcpy(info.type, hw_devicenames[idx], sizeof(info.type));
10099
info.addr = hw_addrs[idx];
101100
for (i = 0; i < I2C_CLIENTS_MAX; i++)
102101
if (cx->i2c_clients[i] == NULL)
@@ -279,7 +278,7 @@ static const char *cx18_i2c_id_name(u32 id)
279278

280279
for (i = 0; i < ARRAY_SIZE(hw_driverids); i++)
281280
if (hw_driverids[i] == id)
282-
return hw_drivernames[i];
281+
return hw_devicenames[i];
283282
return "unknown device";
284283
}
285284

@@ -290,7 +289,7 @@ static const char *cx18_i2c_hw_name(u32 hw)
290289

291290
for (i = 0; i < ARRAY_SIZE(hw_driverids); i++)
292291
if (1 << i == hw)
293-
return hw_drivernames[i];
292+
return hw_devicenames[i];
294293
return "unknown device";
295294
}
296295

‎drivers/media/video/cx25840/cx25840-core.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,10 +1284,17 @@ static int cx25840_remove(struct i2c_client *client)
12841284
return 0;
12851285
}
12861286

1287+
static const struct i2c_device_id cx25840_id[] = {
1288+
{ "cx25840", 0 },
1289+
{ }
1290+
};
1291+
MODULE_DEVICE_TABLE(i2c, cx25840_id);
1292+
12871293
static struct v4l2_i2c_driver_data v4l2_i2c_data = {
12881294
.name = "cx25840",
12891295
.driverid = I2C_DRIVERID_CX25840,
12901296
.command = cx25840_command,
12911297
.probe = cx25840_probe,
12921298
.remove = cx25840_remove,
1299+
.id_table = cx25840_id,
12931300
};

‎drivers/media/video/ivtv/ivtv-i2c.c‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ static const u8 hw_addrs[] = {
136136
};
137137

138138
/* This array should match the IVTV_HW_ defines */
139-
static const char * const hw_drivernames[] = {
139+
static const char * const hw_devicenames[] = {
140140
"cx25840",
141141
"saa7115",
142142
"saa7127",
@@ -145,7 +145,7 @@ static const char * const hw_drivernames[] = {
145145
"wm8775",
146146
"cs53l32a",
147147
"tveeprom",
148-
"saa7115",
148+
"saa7114",
149149
"upd64031a",
150150
"upd64083",
151151
"saa717x",
@@ -167,8 +167,7 @@ int ivtv_i2c_register(struct ivtv *itv, unsigned idx)
167167
return -1;
168168
id = hw_driverids[idx];
169169
memset(&info, 0, sizeof(info));
170-
strlcpy(info.driver_name, hw_drivernames[idx],
171-
sizeof(info.driver_name));
170+
strlcpy(info.type, hw_devicenames[idx], sizeof(info.type));
172171
info.addr = hw_addrs[idx];
173172
for (i = 0; itv->i2c_clients[i] && i < I2C_CLIENTS_MAX; i++) {}
174173

@@ -657,7 +656,7 @@ static const char *ivtv_i2c_id_name(u32 id)
657656

658657
for (i = 0; i < ARRAY_SIZE(hw_driverids); i++)
659658
if (hw_driverids[i] == id)
660-
return hw_drivernames[i];
659+
return hw_devicenames[i];
661660
return "unknown device";
662661
}
663662

@@ -668,7 +667,7 @@ static const char *ivtv_i2c_hw_name(u32 hw)
668667

669668
for (i = 0; i < ARRAY_SIZE(hw_driverids); i++)
670669
if (1 << i == hw)
671-
return hw_drivernames[i];
670+
return hw_devicenames[i];
672671
return "unknown device";
673672
}
674673

@@ -770,7 +769,7 @@ int init_ivtv_i2c(struct ivtv *itv)
770769
* same size and GPIO must be the last entry.
771770
*/
772771
if (ARRAY_SIZE(hw_driverids) != ARRAY_SIZE(hw_addrs) ||
773-
ARRAY_SIZE(hw_drivernames) != ARRAY_SIZE(hw_addrs) ||
772+
ARRAY_SIZE(hw_devicenames) != ARRAY_SIZE(hw_addrs) ||
774773
IVTV_HW_GPIO != (1 << (ARRAY_SIZE(hw_addrs) - 1)) ||
775774
hw_driverids[ARRAY_SIZE(hw_addrs) - 1]) {
776775
IVTV_ERR("Mismatched I2C hardware arrays\n");

‎drivers/media/video/m52790.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ static int m52790_probe(struct i2c_client *client,
135135
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
136136
return -EIO;
137137

138-
snprintf(client->name, sizeof(client->name) - 1, "m52790");
139-
140138
v4l_info(client, "chip found @ 0x%x (%s)\n",
141139
client->addr << 1, client->adapter->name);
142140

@@ -159,11 +157,18 @@ static int m52790_remove(struct i2c_client *client)
159157

160158
/* ----------------------------------------------------------------------- */
161159

160+
static const struct i2c_device_id m52790_id[] = {
161+
{ "m52790", 0 },
162+
{ }
163+
};
164+
MODULE_DEVICE_TABLE(i2c, m52790_id);
165+
162166
static struct v4l2_i2c_driver_data v4l2_i2c_data = {
163167
.name = "m52790",
164168
.driverid = I2C_DRIVERID_M52790,
165169
.command = m52790_command,
166170
.probe = m52790_probe,
167171
.remove = m52790_remove,
172+
.id_table = m52790_id,
168173
};
169174

‎drivers/media/video/msp3400-driver.c‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,8 @@ static int msp_probe(struct i2c_client *client, const struct i2c_device_id *id)
815815
int msp_product, msp_prod_hi, msp_prod_lo;
816816
int msp_rom;
817817

818-
snprintf(client->name, sizeof(client->name) - 1, "msp3400");
818+
if (!id)
819+
strlcpy(client->name, "msp3400", sizeof(client->name));
819820

820821
if (msp_reset(client) == -1) {
821822
v4l_dbg(1, msp_debug, client, "msp3400 not found\n");
@@ -864,9 +865,6 @@ static int msp_probe(struct i2c_client *client, const struct i2c_device_id *id)
864865
msp_revision = (state->rev1 & 0x0f) + '@';
865866
msp_hard = ((state->rev1 >> 8) & 0xff) + '@';
866867
msp_rom = state->rev2 & 0x1f;
867-
snprintf(client->name, sizeof(client->name), "MSP%d4%02d%c-%c%d",
868-
msp_family, msp_product,
869-
msp_revision, msp_hard, msp_rom);
870868
/* Rev B=2, C=3, D=4, G=7 */
871869
state->ident = msp_family * 10000 + 4000 + msp_product * 10 +
872870
msp_revision - '@';
@@ -931,7 +929,9 @@ static int msp_probe(struct i2c_client *client, const struct i2c_device_id *id)
931929
}
932930

933931
/* hello world :-) */
934-
v4l_info(client, "%s found @ 0x%x (%s)\n", client->name,
932+
v4l_info(client, "MSP%d4%02d%c-%c%d found @ 0x%x (%s)\n",
933+
msp_family, msp_product,
934+
msp_revision, msp_hard, msp_rom,
935935
client->addr << 1, client->adapter->name);
936936
v4l_info(client, "%s ", client->name);
937937
if (state->has_nicam && state->has_radio)
@@ -987,6 +987,12 @@ static int msp_remove(struct i2c_client *client)
987987

988988
/* ----------------------------------------------------------------------- */
989989

990+
static const struct i2c_device_id msp_id[] = {
991+
{ "msp3400", 0 },
992+
{ }
993+
};
994+
MODULE_DEVICE_TABLE(i2c, msp_id);
995+
990996
static struct v4l2_i2c_driver_data v4l2_i2c_data = {
991997
.name = "msp3400",
992998
.driverid = I2C_DRIVERID_MSP3400,
@@ -995,6 +1001,7 @@ static struct v4l2_i2c_driver_data v4l2_i2c_data = {
9951001
.remove = msp_remove,
9961002
.suspend = msp_suspend,
9971003
.resume = msp_resume,
1004+
.id_table = msp_id,
9981005
};
9991006

10001007

‎drivers/media/video/saa7115.c‎

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,14 +1456,13 @@ static int saa7115_probe(struct i2c_client *client,
14561456
struct saa711x_state *state;
14571457
int i;
14581458
char name[17];
1459-
u8 chip_id;
1459+
char chip_id;
1460+
int autodetect = !id || id->driver_data == 1;
14601461

14611462
/* Check if the adapter supports the needed features */
14621463
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
14631464
return -EIO;
14641465

1465-
snprintf(client->name, sizeof(client->name) - 1, "saa7115");
1466-
14671466
for (i = 0; i < 0x0f; i++) {
14681467
saa711x_write(client, 0, i);
14691468
name[i] = (saa711x_read(client, 0) & 0x0f) + '0';
@@ -1472,8 +1471,7 @@ static int saa7115_probe(struct i2c_client *client,
14721471
}
14731472
name[i] = '\0';
14741473

1475-
saa711x_write(client, 0, 5);
1476-
chip_id = saa711x_read(client, 0) & 0x0f;
1474+
chip_id = name[5];
14771475

14781476
/* Check whether this chip is part of the saa711x series */
14791477
if (memcmp(name, "1f711", 5)) {
@@ -1482,8 +1480,14 @@ static int saa7115_probe(struct i2c_client *client,
14821480
return -ENODEV;
14831481
}
14841482

1485-
snprintf(client->name, sizeof(client->name) - 1, "saa711%d",chip_id);
1486-
v4l_info(client, "saa711%d found (%s) @ 0x%x (%s)\n", chip_id, name, client->addr << 1, client->adapter->name);
1483+
/* Safety check */
1484+
if (!autodetect && id->name[6] != chip_id) {
1485+
v4l_warn(client, "found saa711%c while %s was expected\n",
1486+
chip_id, id->name);
1487+
}
1488+
snprintf(client->name, sizeof(client->name), "saa711%c", chip_id);
1489+
v4l_info(client, "saa711%c found (%s) @ 0x%x (%s)\n", chip_id, name,
1490+
client->addr << 1, client->adapter->name);
14871491

14881492
state = kzalloc(sizeof(struct saa711x_state), GFP_KERNEL);
14891493
i2c_set_clientdata(client, state);
@@ -1499,19 +1503,19 @@ static int saa7115_probe(struct i2c_client *client,
14991503
state->hue = 0;
15001504
state->sat = 64;
15011505
switch (chip_id) {
1502-
case 1:
1506+
case '1':
15031507
state->ident = V4L2_IDENT_SAA7111;
15041508
break;
1505-
case 3:
1509+
case '3':
15061510
state->ident = V4L2_IDENT_SAA7113;
15071511
break;
1508-
case 4:
1512+
case '4':
15091513
state->ident = V4L2_IDENT_SAA7114;
15101514
break;
1511-
case 5:
1515+
case '5':
15121516
state->ident = V4L2_IDENT_SAA7115;
15131517
break;
1514-
case 8:
1518+
case '8':
15151519
state->ident = V4L2_IDENT_SAA7118;
15161520
break;
15171521
default:
@@ -1553,12 +1557,24 @@ static int saa7115_remove(struct i2c_client *client)
15531557
return 0;
15541558
}
15551559

1560+
static const struct i2c_device_id saa7115_id[] = {
1561+
{ "saa711x", 1 }, /* autodetect */
1562+
{ "saa7111", 0 },
1563+
{ "saa7113", 0 },
1564+
{ "saa7114", 0 },
1565+
{ "saa7115", 0 },
1566+
{ "saa7118", 0 },
1567+
{ }
1568+
};
1569+
MODULE_DEVICE_TABLE(i2c, saa7115_id);
1570+
15561571
static struct v4l2_i2c_driver_data v4l2_i2c_data = {
15571572
.name = "saa7115",
15581573
.driverid = I2C_DRIVERID_SAA711X,
15591574
.command = saa7115_command,
15601575
.probe = saa7115_probe,
15611576
.remove = saa7115_remove,
15621577
.legacy_class = I2C_CLASS_TV_ANALOG | I2C_CLASS_TV_DIGITAL,
1578+
.id_table = saa7115_id,
15631579
};
15641580

‎drivers/media/video/saa7127.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,8 +672,6 @@ static int saa7127_probe(struct i2c_client *client,
672672
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
673673
return -EIO;
674674

675-
snprintf(client->name, sizeof(client->name) - 1, "saa7127");
676-
677675
v4l_dbg(1, debug, client, "detecting saa7127 client on address 0x%x\n",
678676
client->addr << 1);
679677

@@ -741,11 +739,18 @@ static int saa7127_remove(struct i2c_client *client)
741739

742740
/* ----------------------------------------------------------------------- */
743741

742+
static struct i2c_device_id saa7127_id[] = {
743+
{ "saa7127", 0 },
744+
{ }
745+
};
746+
MODULE_DEVICE_TABLE(i2c, saa7127_id);
747+
744748
static struct v4l2_i2c_driver_data v4l2_i2c_data = {
745749
.name = "saa7127",
746750
.driverid = I2C_DRIVERID_SAA7127,
747751
.command = saa7127_command,
748752
.probe = saa7127_probe,
749753
.remove = saa7127_remove,
754+
.id_table = saa7127_id,
750755
};
751756

‎drivers/media/video/saa717x.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,8 +1429,6 @@ static int saa717x_probe(struct i2c_client *client,
14291429
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
14301430
return -EIO;
14311431

1432-
snprintf(client->name, sizeof(client->name) - 1, "saa717x");
1433-
14341432
if (saa717x_write(client, 0x5a4, 0xfe) &&
14351433
saa717x_write(client, 0x5a5, 0x0f) &&
14361434
saa717x_write(client, 0x5a6, 0x00) &&
@@ -1507,11 +1505,18 @@ static int saa717x_remove(struct i2c_client *client)
15071505

15081506
/* ----------------------------------------------------------------------- */
15091507

1508+
static const struct i2c_device_id saa717x_id[] = {
1509+
{ "saa717x", 0 },
1510+
{ }
1511+
};
1512+
MODULE_DEVICE_TABLE(i2c, saa717x_id);
1513+
15101514
static struct v4l2_i2c_driver_data v4l2_i2c_data = {
15111515
.name = "saa717x",
15121516
.driverid = I2C_DRIVERID_SAA717X,
15131517
.command = saa717x_command,
15141518
.probe = saa717x_probe,
15151519
.remove = saa717x_remove,
15161520
.legacy_class = I2C_CLASS_TV_ANALOG | I2C_CLASS_TV_DIGITAL,
1521+
.id_table = saa717x_id,
15171522
};

0 commit comments

Comments
 (0)