Skip to content

Commit 78c4e08

Browse files
herrnstmchehab
authored andcommitted
media: ngene: use common DVB I2C client handling helpers
Like in ddbridge, get rid of all duplicated I2C client handling constructs and rather make use of the newly added dvb_module_*() helpers. Makes things more clean and removes the (cosmetic) need for some variables. The check on a valid ptr on ci->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 c966453 commit 78c4e08

File tree

2 files changed

+15
-53
lines changed

2 files changed

+15
-53
lines changed

drivers/media/pci/ngene/ngene-cards.c

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -253,36 +253,21 @@ static int tuner_attach_tda18212(struct ngene_channel *chan, u32 dmdtype)
253253
.if_dvbt2_8 = 4000,
254254
.if_dvbc = 5000,
255255
};
256-
struct i2c_board_info board_info = {
257-
.type = "tda18212",
258-
.platform_data = &config,
259-
};
260-
261-
if (chan->number & 1)
262-
board_info.addr = 0x63;
263-
else
264-
board_info.addr = 0x60;
256+
u8 addr = (chan->number & 1) ? 0x63 : 0x60;
265257

266258
/*
267259
* due to a hardware quirk with the I2C gate on the stv0367+tda18212
268260
* combo, the tda18212 must be probed by reading it's id _twice_ when
269261
* cold started, or it very likely will fail.
270262
*/
271263
if (dmdtype == DEMOD_TYPE_STV0367)
272-
tuner_tda18212_ping(chan, i2c, board_info.addr);
273-
274-
request_module(board_info.type);
264+
tuner_tda18212_ping(chan, i2c, addr);
275265

276-
/* perform tuner init/attach */
277-
client = i2c_new_device(i2c, &board_info);
278-
if (!client || !client->dev.driver)
266+
/* perform tuner probe/init/attach */
267+
client = dvb_module_probe("tda18212", NULL, i2c, addr, &config);
268+
if (!client)
279269
goto err;
280270

281-
if (!try_module_get(client->dev.driver->owner)) {
282-
i2c_unregister_device(client);
283-
goto err;
284-
}
285-
286271
chan->i2c_client[0] = client;
287272
chan->i2c_client_fe = 1;
288273

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

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,6 @@ static void release_channel(struct ngene_channel *chan)
14081408
{
14091409
struct dvb_demux *dvbdemux = &chan->demux;
14101410
struct ngene *dev = chan->dev;
1411-
struct i2c_client *client;
14121411

14131412
if (chan->running)
14141413
set_transfer(chan, 0);
@@ -1427,12 +1426,9 @@ static void release_channel(struct ngene_channel *chan)
14271426
dvb_unregister_frontend(chan->fe);
14281427

14291428
/* release I2C client (tuner) if needed */
1430-
client = chan->i2c_client[0];
1431-
if (chan->i2c_client_fe && client) {
1432-
module_put(client->dev.driver->owner);
1433-
i2c_unregister_device(client);
1429+
if (chan->i2c_client_fe) {
1430+
dvb_module_release(chan->i2c_client[0]);
14341431
chan->i2c_client[0] = NULL;
1435-
client = NULL;
14361432
}
14371433

14381434
dvb_frontend_detach(chan->fe);
@@ -1584,11 +1580,6 @@ static void cxd_attach(struct ngene *dev)
15841580
struct ngene_ci *ci = &dev->ci;
15851581
struct cxd2099_cfg cxd_cfg = cxd_cfgtmpl;
15861582
struct i2c_client *client;
1587-
struct i2c_board_info board_info = {
1588-
.type = "cxd2099",
1589-
.addr = 0x40,
1590-
.platform_data = &cxd_cfg,
1591-
};
15921583
int ret;
15931584
u8 type;
15941585

@@ -1605,43 +1596,29 @@ static void cxd_attach(struct ngene *dev)
16051596
}
16061597

16071598
cxd_cfg.en = &ci->en;
1608-
1609-
request_module(board_info.type);
1610-
1611-
client = i2c_new_device(&dev->channel[0].i2c_adapter, &board_info);
1612-
if (!client || !client->dev.driver)
1613-
goto err_ret;
1614-
1615-
if (!try_module_get(client->dev.driver->owner))
1616-
goto err_i2c;
1617-
1618-
if (!ci->en)
1619-
goto err_i2c;
1599+
client = dvb_module_probe("cxd2099", NULL,
1600+
&dev->channel[0].i2c_adapter,
1601+
0x40, &cxd_cfg);
1602+
if (!client)
1603+
goto err;
16201604

16211605
ci->dev = dev;
16221606
dev->channel[0].i2c_client[0] = client;
16231607
return;
16241608

1625-
err_i2c:
1626-
i2c_unregister_device(client);
1627-
err_ret:
1609+
err:
16281610
dev_err(pdev, "CXD2099AR attach failed\n");
16291611
return;
16301612
}
16311613

16321614
static void cxd_detach(struct ngene *dev)
16331615
{
16341616
struct ngene_ci *ci = &dev->ci;
1635-
struct i2c_client *client;
16361617

16371618
dvb_ca_en50221_release(ci->en);
16381619

1639-
client = dev->channel[0].i2c_client[0];
1640-
if (client) {
1641-
module_put(client->dev.driver->owner);
1642-
i2c_unregister_device(client);
1643-
}
1644-
1620+
dvb_module_release(dev->channel[0].i2c_client[0]);
1621+
dev->channel[0].i2c_client[0] = NULL;
16451622
ci->en = NULL;
16461623
}
16471624

0 commit comments

Comments
 (0)