Commit 78c4e082 authored by Daniel Scheller's avatar Daniel Scheller Committed by Mauro Carvalho Chehab

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: default avatarDaniel Scheller <d.scheller@gmx.net>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
parent c966453b
...@@ -253,15 +253,7 @@ static int tuner_attach_tda18212(struct ngene_channel *chan, u32 dmdtype) ...@@ -253,15 +253,7 @@ static int tuner_attach_tda18212(struct ngene_channel *chan, u32 dmdtype)
.if_dvbt2_8 = 4000, .if_dvbt2_8 = 4000,
.if_dvbc = 5000, .if_dvbc = 5000,
}; };
struct i2c_board_info board_info = { u8 addr = (chan->number & 1) ? 0x63 : 0x60;
.type = "tda18212",
.platform_data = &config,
};
if (chan->number & 1)
board_info.addr = 0x63;
else
board_info.addr = 0x60;
/* /*
* due to a hardware quirk with the I2C gate on the stv0367+tda18212 * due to a hardware quirk with the I2C gate on the stv0367+tda18212
...@@ -269,19 +261,12 @@ static int tuner_attach_tda18212(struct ngene_channel *chan, u32 dmdtype) ...@@ -269,19 +261,12 @@ static int tuner_attach_tda18212(struct ngene_channel *chan, u32 dmdtype)
* cold started, or it very likely will fail. * cold started, or it very likely will fail.
*/ */
if (dmdtype == DEMOD_TYPE_STV0367) if (dmdtype == DEMOD_TYPE_STV0367)
tuner_tda18212_ping(chan, i2c, board_info.addr); tuner_tda18212_ping(chan, i2c, addr);
request_module(board_info.type); /* perform tuner probe/init/attach */
client = dvb_module_probe("tda18212", NULL, i2c, addr, &config);
/* perform tuner init/attach */ if (!client)
client = i2c_new_device(i2c, &board_info);
if (!client || !client->dev.driver)
goto err;
if (!try_module_get(client->dev.driver->owner)) {
i2c_unregister_device(client);
goto err; goto err;
}
chan->i2c_client[0] = client; chan->i2c_client[0] = client;
chan->i2c_client_fe = 1; chan->i2c_client_fe = 1;
......
...@@ -1408,7 +1408,6 @@ static void release_channel(struct ngene_channel *chan) ...@@ -1408,7 +1408,6 @@ static void release_channel(struct ngene_channel *chan)
{ {
struct dvb_demux *dvbdemux = &chan->demux; struct dvb_demux *dvbdemux = &chan->demux;
struct ngene *dev = chan->dev; struct ngene *dev = chan->dev;
struct i2c_client *client;
if (chan->running) if (chan->running)
set_transfer(chan, 0); set_transfer(chan, 0);
...@@ -1427,12 +1426,9 @@ static void release_channel(struct ngene_channel *chan) ...@@ -1427,12 +1426,9 @@ static void release_channel(struct ngene_channel *chan)
dvb_unregister_frontend(chan->fe); dvb_unregister_frontend(chan->fe);
/* release I2C client (tuner) if needed */ /* release I2C client (tuner) if needed */
client = chan->i2c_client[0]; if (chan->i2c_client_fe) {
if (chan->i2c_client_fe && client) { dvb_module_release(chan->i2c_client[0]);
module_put(client->dev.driver->owner);
i2c_unregister_device(client);
chan->i2c_client[0] = NULL; chan->i2c_client[0] = NULL;
client = NULL;
} }
dvb_frontend_detach(chan->fe); dvb_frontend_detach(chan->fe);
...@@ -1584,11 +1580,6 @@ static void cxd_attach(struct ngene *dev) ...@@ -1584,11 +1580,6 @@ static void cxd_attach(struct ngene *dev)
struct ngene_ci *ci = &dev->ci; struct ngene_ci *ci = &dev->ci;
struct cxd2099_cfg cxd_cfg = cxd_cfgtmpl; struct cxd2099_cfg cxd_cfg = cxd_cfgtmpl;
struct i2c_client *client; struct i2c_client *client;
struct i2c_board_info board_info = {
.type = "cxd2099",
.addr = 0x40,
.platform_data = &cxd_cfg,
};
int ret; int ret;
u8 type; u8 type;
...@@ -1605,26 +1596,17 @@ static void cxd_attach(struct ngene *dev) ...@@ -1605,26 +1596,17 @@ static void cxd_attach(struct ngene *dev)
} }
cxd_cfg.en = &ci->en; cxd_cfg.en = &ci->en;
client = dvb_module_probe("cxd2099", NULL,
request_module(board_info.type); &dev->channel[0].i2c_adapter,
0x40, &cxd_cfg);
client = i2c_new_device(&dev->channel[0].i2c_adapter, &board_info); if (!client)
if (!client || !client->dev.driver) goto err;
goto err_ret;
if (!try_module_get(client->dev.driver->owner))
goto err_i2c;
if (!ci->en)
goto err_i2c;
ci->dev = dev; ci->dev = dev;
dev->channel[0].i2c_client[0] = client; dev->channel[0].i2c_client[0] = client;
return; return;
err_i2c: err:
i2c_unregister_device(client);
err_ret:
dev_err(pdev, "CXD2099AR attach failed\n"); dev_err(pdev, "CXD2099AR attach failed\n");
return; return;
} }
...@@ -1632,16 +1614,11 @@ static void cxd_attach(struct ngene *dev) ...@@ -1632,16 +1614,11 @@ static void cxd_attach(struct ngene *dev)
static void cxd_detach(struct ngene *dev) static void cxd_detach(struct ngene *dev)
{ {
struct ngene_ci *ci = &dev->ci; struct ngene_ci *ci = &dev->ci;
struct i2c_client *client;
dvb_ca_en50221_release(ci->en); dvb_ca_en50221_release(ci->en);
client = dev->channel[0].i2c_client[0]; dvb_module_release(dev->channel[0].i2c_client[0]);
if (client) { dev->channel[0].i2c_client[0] = NULL;
module_put(client->dev.driver->owner);
i2c_unregister_device(client);
}
ci->en = NULL; ci->en = NULL;
} }
......
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