[media] af9035: remove I2C client differently
[deliverable/linux.git] / drivers / media / usb / dvb-usb-v2 / af9035.c
index ec621338a6ef8d7cf2b7664189924e8abe6671b7..440ecb459b9ca43876f078ba588e16fb08603890 100644 (file)
@@ -330,15 +330,15 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap,
                if (msg[0].len > 40 || msg[1].len > 40) {
                        /* TODO: correct limits > 40 */
                        ret = -EOPNOTSUPP;
-               } else if ((msg[0].addr == state->af9033_config[0].i2c_addr) ||
-                          (msg[0].addr == state->af9033_config[1].i2c_addr) ||
+               } else if ((msg[0].addr == state->af9033_i2c_addr[0]) ||
+                          (msg[0].addr == state->af9033_i2c_addr[1]) ||
                           (state->chip_type == 0x9135)) {
                        /* demod access via firmware interface */
                        u32 reg = msg[0].buf[0] << 16 | msg[0].buf[1] << 8 |
                                        msg[0].buf[2];
 
-                       if (msg[0].addr == state->af9033_config[1].i2c_addr ||
-                           msg[0].addr == (state->af9033_config[1].i2c_addr >> 1))
+                       if (msg[0].addr == state->af9033_i2c_addr[1] ||
+                           msg[0].addr == (state->af9033_i2c_addr[1] >> 1))
                                reg |= 0x100000;
 
                        ret = af9035_rd_regs(d, reg, &msg[1].buf[0],
@@ -362,15 +362,15 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap,
                if (msg[0].len > 40) {
                        /* TODO: correct limits > 40 */
                        ret = -EOPNOTSUPP;
-               } else if ((msg[0].addr == state->af9033_config[0].i2c_addr) ||
-                          (msg[0].addr == state->af9033_config[1].i2c_addr) ||
+               } else if ((msg[0].addr == state->af9033_i2c_addr[0]) ||
+                          (msg[0].addr == state->af9033_i2c_addr[1]) ||
                           (state->chip_type == 0x9135)) {
                        /* demod access via firmware interface */
                        u32 reg = msg[0].buf[0] << 16 | msg[0].buf[1] << 8 |
                                        msg[0].buf[2];
 
-                       if (msg[0].addr == state->af9033_config[1].i2c_addr ||
-                           msg[0].addr == (state->af9033_config[1].i2c_addr >> 1))
+                       if (msg[0].addr == state->af9033_i2c_addr[1] ||
+                           msg[0].addr == (state->af9033_i2c_addr[1] >> 1))
                                reg |= 0x100000;
 
                        ret = af9035_wr_regs(d, reg, &msg[0].buf[3],
@@ -736,8 +736,8 @@ static int af9035_read_config(struct dvb_usb_device *d)
        u16 tmp16, addr;
 
        /* demod I2C "address" */
-       state->af9033_config[0].i2c_addr = 0x38;
-       state->af9033_config[1].i2c_addr = 0x3a;
+       state->af9033_i2c_addr[0] = 0x38;
+       state->af9033_i2c_addr[1] = 0x3a;
        state->af9033_config[0].adc_multiplier = AF9033_ADC_MULTIPLIER_2X;
        state->af9033_config[1].adc_multiplier = AF9033_ADC_MULTIPLIER_2X;
        state->af9033_config[0].ts_mode = AF9033_TS_MODE_USB;
@@ -789,7 +789,7 @@ static int af9035_read_config(struct dvb_usb_device *d)
                        goto err;
 
                if (tmp)
-                       state->af9033_config[1].i2c_addr = tmp;
+                       state->af9033_i2c_addr[1] = tmp;
 
                dev_dbg(&d->udev->dev, "%s: 2nd demod I2C addr=%02x\n",
                                __func__, tmp);
@@ -1074,15 +1074,13 @@ static int af9035_get_adapter_count(struct dvb_usb_device *d)
        return state->dual_mode + 1;
 }
 
-static void af9035_exit(struct dvb_usb_device *d);
-
 static int af9035_frontend_attach(struct dvb_usb_adapter *adap)
 {
        struct state *state = adap_to_priv(adap);
        struct dvb_usb_device *d = adap_to_d(adap);
        int ret;
 
-       dev_dbg(&d->udev->dev, "%s:\n", __func__);
+       dev_dbg(&d->udev->dev, "%s: adap->id=%d\n", __func__, adap->id);
 
        if (!state->af9033_config[adap->id].tuner) {
                /* unsupported tuner */
@@ -1092,8 +1090,7 @@ static int af9035_frontend_attach(struct dvb_usb_adapter *adap)
 
        state->af9033_config[adap->id].fe = &adap->fe[0];
        state->af9033_config[adap->id].ops = &state->ops;
-       ret = af9035_add_i2c_dev(d, "af9033",
-                       state->af9033_config[adap->id].i2c_addr,
+       ret = af9035_add_i2c_dev(d, "af9033", state->af9033_i2c_addr[adap->id],
                        &state->af9033_config[adap->id]);
        if (ret)
                goto err;
@@ -1110,12 +1107,48 @@ static int af9035_frontend_attach(struct dvb_usb_adapter *adap)
        return 0;
 
 err:
-       af9035_exit(d); /* remove I2C clients */
        dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
 
        return ret;
 }
 
+static int af9035_frontend_detach(struct dvb_usb_adapter *adap)
+{
+       struct state *state = adap_to_priv(adap);
+       struct dvb_usb_device *d = adap_to_d(adap);
+       int demod2;
+
+       dev_dbg(&d->udev->dev, "%s: adap->id=%d\n", __func__, adap->id);
+
+       /*
+        * For dual tuner devices we have to resolve 2nd demod client, as there
+        * is two different kind of tuner drivers; one is using I2C binding
+        * and the other is using DVB attach/detach binding.
+        */
+       switch (state->af9033_config[adap->id].tuner) {
+       case AF9033_TUNER_IT9135_38:
+       case AF9033_TUNER_IT9135_51:
+       case AF9033_TUNER_IT9135_52:
+       case AF9033_TUNER_IT9135_60:
+       case AF9033_TUNER_IT9135_61:
+       case AF9033_TUNER_IT9135_62:
+               demod2 = 2;
+               break;
+       default:
+               demod2 = 1;
+       }
+
+       if (adap->id == 1) {
+               if (state->i2c_client[demod2])
+                       af9035_del_i2c_dev(d);
+       } else if (adap->id == 0) {
+               if (state->i2c_client[0])
+                       af9035_del_i2c_dev(d);
+       }
+
+       return 0;
+}
+
 static struct tua9001_config af9035_tua9001_config = {
        .i2c_addr = 0x60,
 };
@@ -1175,7 +1208,7 @@ static int af9035_tuner_attach(struct dvb_usb_adapter *adap)
        struct i2c_msg msg[1];
        u8 tuner_addr;
 
-       dev_dbg(&d->udev->dev, "%s:\n", __func__);
+       dev_dbg(&d->udev->dev, "%s: adap->id=%d\n", __func__, adap->id);
 
        /*
         * XXX: Hack used in that function: we abuse unused I2C address bit [7]
@@ -1348,7 +1381,7 @@ static int af9035_tuner_attach(struct dvb_usb_adapter *adap)
                }
 
                ret = af9035_add_i2c_dev(d, "it913x",
-                               state->af9033_config[adap->id].i2c_addr >> 1,
+                               state->af9033_i2c_addr[adap->id] >> 1,
                                &it913x_config);
                if (ret)
                        goto err;
@@ -1373,7 +1406,7 @@ static int af9035_tuner_attach(struct dvb_usb_adapter *adap)
                }
 
                ret = af9035_add_i2c_dev(d, "it913x",
-                               state->af9033_config[adap->id].i2c_addr >> 1,
+                               state->af9033_i2c_addr[adap->id] >> 1,
                                &it913x_config);
                if (ret)
                        goto err;
@@ -1393,12 +1426,37 @@ static int af9035_tuner_attach(struct dvb_usb_adapter *adap)
        return 0;
 
 err:
-       af9035_exit(d); /* remove I2C clients */
        dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
 
        return ret;
 }
 
+static int af9035_tuner_detach(struct dvb_usb_adapter *adap)
+{
+       struct state *state = adap_to_priv(adap);
+       struct dvb_usb_device *d = adap_to_d(adap);
+
+       dev_dbg(&d->udev->dev, "%s: adap->id=%d\n", __func__, adap->id);
+
+       switch (state->af9033_config[adap->id].tuner) {
+       case AF9033_TUNER_IT9135_38:
+       case AF9033_TUNER_IT9135_51:
+       case AF9033_TUNER_IT9135_52:
+       case AF9033_TUNER_IT9135_60:
+       case AF9033_TUNER_IT9135_61:
+       case AF9033_TUNER_IT9135_62:
+               if (adap->id == 1) {
+                       if (state->i2c_client[3])
+                               af9035_del_i2c_dev(d);
+               } else if (adap->id == 0) {
+                       if (state->i2c_client[1])
+                               af9035_del_i2c_dev(d);
+               }
+       }
+
+       return 0;
+}
+
 static int af9035_init(struct dvb_usb_device *d)
 {
        struct state *state = d_to_priv(d);
@@ -1446,25 +1504,6 @@ err:
        return ret;
 }
 
-static void af9035_exit(struct dvb_usb_device *d)
-{
-       struct state *state = d_to_priv(d);
-
-       dev_dbg(&d->udev->dev, "%s:\n", __func__);
-
-       if (state->i2c_client[3])
-               af9035_del_i2c_dev(d);
-
-       if (state->i2c_client[2])
-               af9035_del_i2c_dev(d);
-
-       if (state->i2c_client[1])
-               af9035_del_i2c_dev(d);
-
-       if (state->i2c_client[0])
-               af9035_del_i2c_dev(d);
-}
-
 #if IS_ENABLED(CONFIG_RC_CORE)
 static int af9035_rc_query(struct dvb_usb_device *d)
 {
@@ -1637,11 +1676,12 @@ static const struct dvb_usb_device_properties af9035_props = {
        .i2c_algo = &af9035_i2c_algo,
        .read_config = af9035_read_config,
        .frontend_attach = af9035_frontend_attach,
+       .frontend_detach = af9035_frontend_detach,
        .tuner_attach = af9035_tuner_attach,
+       .tuner_detach = af9035_tuner_detach,
        .init = af9035_init,
        .get_rc_config = af9035_get_rc_config,
        .get_stream_config = af9035_get_stream_config,
-       .exit = af9035_exit,
 
        .get_adapter_count = af9035_get_adapter_count,
        .adapter = {
@@ -1729,9 +1769,9 @@ static const struct usb_device_id af9035_id_table[] = {
        { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xf900,
                &af9035_props, "Hauppauge WinTV-MiniStick 2", NULL) },
        { DVB_USB_DEVICE(USB_VID_PCTV, USB_PID_PCTV_78E,
-               &af9035_props, "PCTV 78e", RC_MAP_IT913X_V1) },
+               &af9035_props, "PCTV AndroiDTV (78e)", RC_MAP_IT913X_V1) },
        { DVB_USB_DEVICE(USB_VID_PCTV, USB_PID_PCTV_79E,
-               &af9035_props, "PCTV 79e", RC_MAP_IT913X_V2) },
+               &af9035_props, "PCTV microStick (79e)", RC_MAP_IT913X_V2) },
        { }
 };
 MODULE_DEVICE_TABLE(usb, af9035_id_table);
This page took 0.027885 seconds and 5 git commands to generate.