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

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: default avatarDaniel Scheller <d.scheller@gmx.net>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
parent a31b86b1
...@@ -324,34 +324,20 @@ static int ci_cxd2099_attach(struct ddb_port *port, u32 bitrate) ...@@ -324,34 +324,20 @@ static int ci_cxd2099_attach(struct ddb_port *port, u32 bitrate)
{ {
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,
};
cxd_cfg.bitrate = bitrate; cxd_cfg.bitrate = bitrate;
cxd_cfg.en = &port->en; cxd_cfg.en = &port->en;
request_module(board_info.type); client = dvb_module_probe("cxd2099", NULL, &port->i2c->adap,
0x40, &cxd_cfg);
client = i2c_new_device(&port->i2c->adap, &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 (!port->en)
goto err_i2c;
port->dvb[0].i2c_client[0] = client; port->dvb[0].i2c_client[0] = client;
port->en_freedata = 0; port->en_freedata = 0;
return 0; return 0;
err_i2c: err:
i2c_unregister_device(client);
err_ret:
dev_err(port->dev->dev, "CXD2099AR attach failed\n"); dev_err(port->dev->dev, "CXD2099AR attach failed\n");
return -ENODEV; return -ENODEV;
} }
...@@ -385,18 +371,13 @@ int ddb_ci_attach(struct ddb_port *port, u32 bitrate) ...@@ -385,18 +371,13 @@ int ddb_ci_attach(struct ddb_port *port, u32 bitrate)
void ddb_ci_detach(struct ddb_port *port) void ddb_ci_detach(struct ddb_port *port)
{ {
struct i2c_client *client;
if (port->dvb[0].dev) if (port->dvb[0].dev)
dvb_unregister_device(port->dvb[0].dev); dvb_unregister_device(port->dvb[0].dev);
if (port->en) { if (port->en) {
dvb_ca_en50221_release(port->en); dvb_ca_en50221_release(port->en);
client = port->dvb[0].i2c_client[0]; dvb_module_release(port->dvb[0].i2c_client[0]);
if (client) { port->dvb[0].i2c_client[0] = NULL;
module_put(client->dev.driver->owner);
i2c_unregister_device(client);
}
/* free alloc'ed memory if needed */ /* free alloc'ed memory if needed */
if (port->en_freedata) if (port->en_freedata)
......
...@@ -999,37 +999,21 @@ static int tuner_attach_tda18212(struct ddb_input *input, u32 porttype) ...@@ -999,37 +999,21 @@ static int tuner_attach_tda18212(struct ddb_input *input, u32 porttype)
.if_dvbt2_8 = 4000, .if_dvbt2_8 = 4000,
.if_dvbc = 5000, .if_dvbc = 5000,
}; };
struct i2c_board_info board_info = { u8 addr = (input->nr & 1) ? 0x63 : 0x60;
.type = "tda18212",
.platform_data = &config,
};
if (input->nr & 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
* combo, the tda18212 must be probed by reading it's id _twice_ when * combo, the tda18212 must be probed by reading it's id _twice_ when
* cold started, or it very likely will fail. * cold started, or it very likely will fail.
*/ */
if (porttype == DDB_TUNER_DVBCT_ST) if (porttype == DDB_TUNER_DVBCT_ST)
tuner_tda18212_ping(input, board_info.addr); tuner_tda18212_ping(input, addr);
request_module(board_info.type);
/* perform tuner init/attach */
client = i2c_new_device(adapter, &board_info);
if (!client || !client->dev.driver)
goto err;
if (!try_module_get(client->dev.driver->owner)) { /* perform tuner probe/init/attach */
i2c_unregister_device(client); client = dvb_module_probe("tda18212", NULL, adapter, addr, &config);
if (!client)
goto err; goto err;
}
dvb->i2c_client[0] = client; dvb->i2c_client[0] = client;
return 0; return 0;
err: err:
dev_err(dev, "TDA18212 tuner not found. Device is not fully operational.\n"); 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) ...@@ -1253,7 +1237,6 @@ static void dvb_input_detach(struct ddb_input *input)
{ {
struct ddb_dvb *dvb = &input->port->dvb[input->nr & 1]; struct ddb_dvb *dvb = &input->port->dvb[input->nr & 1];
struct dvb_demux *dvbdemux = &dvb->demux; struct dvb_demux *dvbdemux = &dvb->demux;
struct i2c_client *client;
switch (dvb->attached) { switch (dvb->attached) {
case 0x31: case 0x31:
...@@ -1263,13 +1246,8 @@ static void dvb_input_detach(struct ddb_input *input) ...@@ -1263,13 +1246,8 @@ static void dvb_input_detach(struct ddb_input *input)
dvb_unregister_frontend(dvb->fe); dvb_unregister_frontend(dvb->fe);
/* fallthrough */ /* fallthrough */
case 0x30: case 0x30:
client = dvb->i2c_client[0]; dvb_module_release(dvb->i2c_client[0]);
if (client) {
module_put(client->dev.driver->owner);
i2c_unregister_device(client);
dvb->i2c_client[0] = NULL; dvb->i2c_client[0] = NULL;
client = NULL;
}
if (dvb->fe2) if (dvb->fe2)
dvb_frontend_detach(dvb->fe2); dvb_frontend_detach(dvb->fe2);
......
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