@@ -26,6 +26,7 @@
#include "dvbdev.h"
#include "dvb_demux.h"
#include "dvb_frontend.h"
+#include "dvb_i2c.h"
#include "pt3.h"
@@ -103,12 +104,12 @@ pt3_demod_write(struct pt3_adapter *adap, const struct reg_val *data, int num)
int i, ret;
ret = 0;
- msg.addr = adap->i2c_demod->addr;
+ msg.addr = adap->fe->fe_i2c_client->addr;
msg.flags = 0;
msg.len = 2;
for (i = 0; i < num; i++) {
msg.buf = (u8 *)&data[i];
- ret = i2c_transfer(adap->i2c_demod->adapter, &msg, 1);
+ ret = i2c_transfer(adap->fe->fe_i2c_client->adapter, &msg, 1);
if (ret == 0)
ret = -EREMOTE;
if (ret < 0)
@@ -375,67 +376,38 @@ static int pt3_fe_init(struct pt3_board *pt3)
static int pt3_attach_fe(struct pt3_board *pt3, int i)
{
- struct i2c_board_info info;
- struct tc90522_config cfg;
- struct i2c_client *cl;
+ struct dvb_frontend *fe;
+ struct tc90522_out *out;
+ struct i2c_client *tuner_cl;
struct dvb_adapter *dvb_adap;
int ret;
- info = adap_conf[i].demod_info;
- cfg = adap_conf[i].demod_cfg;
- cfg.tuner_i2c = NULL;
- info.platform_data = &cfg;
+ out = NULL;
+ fe = dvb_i2c_attach_fe(&pt3->i2c_adap, &adap_conf[i].demod_info,
+ &adap_conf[i].demod_cfg, (void **)&out);
+ if (!fe)
+ return -ENODEV;
ret = -ENODEV;
- request_module("tc90522");
- cl = i2c_new_device(&pt3->i2c_adap, &info);
- if (!cl || !cl->dev.driver)
- return -ENODEV;
- pt3->adaps[i]->i2c_demod = cl;
- if (!try_module_get(cl->dev.driver->owner))
- goto err_demod_i2c_unregister_device;
-
- if (!strncmp(cl->name, TC90522_I2C_DEV_SAT, sizeof(cl->name))) {
- struct qm1d1c0042_config tcfg;
-
- tcfg = adap_conf[i].tuner_cfg.qm1d1c0042;
- tcfg.fe = cfg.fe;
- info = adap_conf[i].tuner_info;
- info.platform_data = &tcfg;
- request_module("qm1d1c0042");
- cl = i2c_new_device(cfg.tuner_i2c, &info);
- } else {
- struct mxl301rf_config tcfg;
-
- tcfg = adap_conf[i].tuner_cfg.mxl301rf;
- tcfg.fe = cfg.fe;
- info = adap_conf[i].tuner_info;
- info.platform_data = &tcfg;
- request_module("mxl301rf");
- cl = i2c_new_device(cfg.tuner_i2c, &info);
- }
- if (!cl || !cl->dev.driver)
- goto err_demod_module_put;
- pt3->adaps[i]->i2c_tuner = cl;
- if (!try_module_get(cl->dev.driver->owner))
- goto err_tuner_i2c_unregister_device;
+ if (!out)
+ goto err;
+ tuner_cl = dvb_i2c_attach_tuner(&(out->demod_bus),
+ &adap_conf[i].tuner_info, fe,
+ &adap_conf[i].tuner_cfg, NULL);
+ if (!tuner_cl)
+ goto err;
dvb_adap = &pt3->adaps[one_adapter ? 0 : i]->dvb_adap;
- ret = dvb_register_frontend(dvb_adap, cfg.fe);
+ ret = dvb_register_frontend(dvb_adap, fe);
if (ret < 0)
- goto err_tuner_module_put;
- pt3->adaps[i]->fe = cfg.fe;
+ goto err;
+ pt3->adaps[i]->fe = fe;
return 0;
-err_tuner_module_put:
- module_put(pt3->adaps[i]->i2c_tuner->dev.driver->owner);
-err_tuner_i2c_unregister_device:
- i2c_unregister_device(pt3->adaps[i]->i2c_tuner);
-err_demod_module_put:
- module_put(pt3->adaps[i]->i2c_demod->dev.driver->owner);
-err_demod_i2c_unregister_device:
- i2c_unregister_device(pt3->adaps[i]->i2c_demod);
-
+err:
+ /* tuner i2c_client is unregister'ed as well, */
+ /* because it is a (grand) child of the demod i2c_client device */
+ i2c_unregister_device(fe->fe_i2c_client);
return ret;
}
@@ -630,17 +602,10 @@ static void pt3_cleanup_adapter(struct pt3_board *pt3, int index)
dmx = &adap->demux.dmx;
dmx->close(dmx);
if (adap->fe) {
- adap->fe->callback = NULL;
if (adap->fe->frontend_priv)
dvb_unregister_frontend(adap->fe);
- if (adap->i2c_tuner) {
- module_put(adap->i2c_tuner->dev.driver->owner);
- i2c_unregister_device(adap->i2c_tuner);
- }
- if (adap->i2c_demod) {
- module_put(adap->i2c_demod->dev.driver->owner);
- i2c_unregister_device(adap->i2c_demod);
- }
+ if (adap->fe->fe_i2c_client)
+ i2c_unregister_device(adap->fe->fe_i2c_client);
}
pt3_free_dmabuf(adap);
dvb_dmxdev_release(&adap->dmxdev);
@@ -104,15 +104,17 @@ struct dma_data_buffer {
/*
* device things
*/
+union pt3_tuner_config {
+ struct qm1d1c0042_config qm1d1c0042;
+ struct mxl301rf_config mxl301rf;
+};
+
struct pt3_adap_config {
struct i2c_board_info demod_info;
struct tc90522_config demod_cfg;
struct i2c_board_info tuner_info;
- union tuner_config {
- struct qm1d1c0042_config qm1d1c0042;
- struct mxl301rf_config mxl301rf;
- } tuner_cfg;
+ union pt3_tuner_config tuner_cfg;
u32 init_freq;
};
@@ -123,8 +125,6 @@ struct pt3_adapter {
struct dvb_demux demux;
struct dmxdev dmxdev;
struct dvb_frontend *fe;
- struct i2c_client *i2c_demod;
- struct i2c_client *i2c_tuner;
/* data fetch thread */
struct task_struct *thread;