Skip to content

Commit c966453

Browse files
herrnstmchehab
authored andcommitted
media: ddbridge: use common DVB I2C client handling helpers
Instead of keeping duplicated I2C client handling construct, make use of the newly introduced dvb_module_*() helpers. This not only keeps things way cleaner and removes the need for duplicated I2C client attach code, but even allows to get rid of some variables that won't help in making things look cleaner anymore. The check on a valid ptr on port->en isn't really needed since the cxd2099 driver will set it at a time where it is going to return successfully from probing. Signed-off-by: Daniel Scheller <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent a31b86b commit c966453

File tree

2 files changed

+14
-55
lines changed

2 files changed

+14
-55
lines changed

drivers/media/pci/ddbridge/ddbridge-ci.c

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -324,34 +324,20 @@ static int ci_cxd2099_attach(struct ddb_port *port, u32 bitrate)
324324
{
325325
struct cxd2099_cfg cxd_cfg = cxd_cfgtmpl;
326326
struct i2c_client *client;
327-
struct i2c_board_info board_info = {
328-
.type = "cxd2099",
329-
.addr = 0x40,
330-
.platform_data = &cxd_cfg,
331-
};
332327

333328
cxd_cfg.bitrate = bitrate;
334329
cxd_cfg.en = &port->en;
335330

336-
request_module(board_info.type);
337-
338-
client = i2c_new_device(&port->i2c->adap, &board_info);
339-
if (!client || !client->dev.driver)
340-
goto err_ret;
341-
342-
if (!try_module_get(client->dev.driver->owner))
343-
goto err_i2c;
344-
345-
if (!port->en)
346-
goto err_i2c;
331+
client = dvb_module_probe("cxd2099", NULL, &port->i2c->adap,
332+
0x40, &cxd_cfg);
333+
if (!client)
334+
goto err;
347335

348336
port->dvb[0].i2c_client[0] = client;
349337
port->en_freedata = 0;
350338
return 0;
351339

352-
err_i2c:
353-
i2c_unregister_device(client);
354-
err_ret:
340+
err:
355341
dev_err(port->dev->dev, "CXD2099AR attach failed\n");
356342
return -ENODEV;
357343
}
@@ -385,18 +371,13 @@ int ddb_ci_attach(struct ddb_port *port, u32 bitrate)
385371

386372
void ddb_ci_detach(struct ddb_port *port)
387373
{
388-
struct i2c_client *client;
389-
390374
if (port->dvb[0].dev)
391375
dvb_unregister_device(port->dvb[0].dev);
392376
if (port->en) {
393377
dvb_ca_en50221_release(port->en);
394378

395-
client = port->dvb[0].i2c_client[0];
396-
if (client) {
397-
module_put(client->dev.driver->owner);
398-
i2c_unregister_device(client);
399-
}
379+
dvb_module_release(port->dvb[0].i2c_client[0]);
380+
port->dvb[0].i2c_client[0] = NULL;
400381

401382
/* free alloc'ed memory if needed */
402383
if (port->en_freedata)

drivers/media/pci/ddbridge/ddbridge-core.c

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -999,37 +999,21 @@ static int tuner_attach_tda18212(struct ddb_input *input, u32 porttype)
999999
.if_dvbt2_8 = 4000,
10001000
.if_dvbc = 5000,
10011001
};
1002-
struct i2c_board_info board_info = {
1003-
.type = "tda18212",
1004-
.platform_data = &config,
1005-
};
1006-
1007-
if (input->nr & 1)
1008-
board_info.addr = 0x63;
1009-
else
1010-
board_info.addr = 0x60;
1002+
u8 addr = (input->nr & 1) ? 0x63 : 0x60;
10111003

10121004
/* due to a hardware quirk with the I2C gate on the stv0367+tda18212
10131005
* combo, the tda18212 must be probed by reading it's id _twice_ when
10141006
* cold started, or it very likely will fail.
10151007
*/
10161008
if (porttype == DDB_TUNER_DVBCT_ST)
1017-
tuner_tda18212_ping(input, board_info.addr);
1018-
1019-
request_module(board_info.type);
1020-
1021-
/* perform tuner init/attach */
1022-
client = i2c_new_device(adapter, &board_info);
1023-
if (!client || !client->dev.driver)
1024-
goto err;
1009+
tuner_tda18212_ping(input, addr);
10251010

1026-
if (!try_module_get(client->dev.driver->owner)) {
1027-
i2c_unregister_device(client);
1011+
/* perform tuner probe/init/attach */
1012+
client = dvb_module_probe("tda18212", NULL, adapter, addr, &config);
1013+
if (!client)
10281014
goto err;
1029-
}
10301015

10311016
dvb->i2c_client[0] = client;
1032-
10331017
return 0;
10341018
err:
10351019
dev_err(dev, "TDA18212 tuner not found. Device is not fully operational.\n");
@@ -1253,7 +1237,6 @@ static void dvb_input_detach(struct ddb_input *input)
12531237
{
12541238
struct ddb_dvb *dvb = &input->port->dvb[input->nr & 1];
12551239
struct dvb_demux *dvbdemux = &dvb->demux;
1256-
struct i2c_client *client;
12571240

12581241
switch (dvb->attached) {
12591242
case 0x31:
@@ -1263,13 +1246,8 @@ static void dvb_input_detach(struct ddb_input *input)
12631246
dvb_unregister_frontend(dvb->fe);
12641247
/* fallthrough */
12651248
case 0x30:
1266-
client = dvb->i2c_client[0];
1267-
if (client) {
1268-
module_put(client->dev.driver->owner);
1269-
i2c_unregister_device(client);
1270-
dvb->i2c_client[0] = NULL;
1271-
client = NULL;
1272-
}
1249+
dvb_module_release(dvb->i2c_client[0]);
1250+
dvb->i2c_client[0] = NULL;
12731251

12741252
if (dvb->fe2)
12751253
dvb_frontend_detach(dvb->fe2);

0 commit comments

Comments
 (0)