[media] cx231xx: register i2c mux adapters for bus 1
authorMatthias Schwarzott <zzam@gentoo.org>
Thu, 2 Oct 2014 05:21:03 +0000 (02:21 -0300)
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>
Thu, 30 Oct 2014 19:38:43 +0000 (17:38 -0200)
I2C bus 1 has internally a switch. Use it as I2C_1_MUX_1 and
I2C_1_MUX_3, letting the I2C core handling the switch.

Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
Reviewed-by: Antti Palosaari <crope@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
drivers/media/usb/cx231xx/Kconfig
drivers/media/usb/cx231xx/cx231xx-core.c
drivers/media/usb/cx231xx/cx231xx-i2c.c
drivers/media/usb/cx231xx/cx231xx.h

index 569aa298c03f9d744cee5a0760c2807d8b0d8ea6..173c0e287a08d528c91f9a810b869f38619d4454 100644 (file)
@@ -7,6 +7,7 @@ config VIDEO_CX231XX
        select VIDEOBUF_VMALLOC
        select VIDEO_CX25840
        select VIDEO_CX2341X
+       select I2C_MUX
 
        ---help---
          This is a video4linux driver for Conexant 231xx USB based TV cards.
index 180103e48036727e322399c53437599ced61b8c5..c8a6d20c9a23e8578edde437fefdca0d2a5d5980 100644 (file)
@@ -1300,6 +1300,9 @@ int cx231xx_dev_init(struct cx231xx *dev)
        cx231xx_i2c_register(&dev->i2c_bus[1]);
        cx231xx_i2c_register(&dev->i2c_bus[2]);
 
+       cx231xx_i2c_mux_register(dev, 0);
+       cx231xx_i2c_mux_register(dev, 1);
+
        /* init hardware */
        /* Note : with out calling set power mode function,
        afe can not be set up correctly */
@@ -1414,6 +1417,8 @@ EXPORT_SYMBOL_GPL(cx231xx_dev_init);
 void cx231xx_dev_uninit(struct cx231xx *dev)
 {
        /* Un Initialize I2C bus */
+       cx231xx_i2c_mux_unregister(dev, 1);
+       cx231xx_i2c_mux_unregister(dev, 0);
        cx231xx_i2c_unregister(&dev->i2c_bus[2]);
        cx231xx_i2c_unregister(&dev->i2c_bus[1]);
        cx231xx_i2c_unregister(&dev->i2c_bus[0]);
index 9ade3acbc8775b4b7d14bff55d750eb47eed4399..3e9dfd808518bd671c865cdaf2d03179b9b72eb5 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/kernel.h>
 #include <linux/usb.h>
 #include <linux/i2c.h>
+#include <linux/i2c-mux.h>
 #include <media/v4l2-common.h>
 #include <media/tuner.h>
 
@@ -547,6 +548,46 @@ int cx231xx_i2c_unregister(struct cx231xx_i2c *bus)
        return 0;
 }
 
+/*
+ * cx231xx_i2c_mux_select()
+ * switch i2c master number 1 between port1 and port3
+ */
+static int cx231xx_i2c_mux_select(struct i2c_adapter *adap,
+                       void *mux_priv, u32 chan_id)
+{
+       struct cx231xx *dev = mux_priv;
+
+       return cx231xx_enable_i2c_port_3(dev, chan_id);
+}
+
+int cx231xx_i2c_mux_register(struct cx231xx *dev, int mux_no)
+{
+       struct i2c_adapter *i2c_parent = &dev->i2c_bus[1].i2c_adap;
+       /* what is the correct mux_dev? */
+       struct device *mux_dev = &dev->udev->dev;
+
+       dev->i2c_mux_adap[mux_no] = i2c_add_mux_adapter(i2c_parent,
+                               mux_dev,
+                               dev /* mux_priv */,
+                               0,
+                               mux_no /* chan_id */,
+                               0 /* class */,
+                               &cx231xx_i2c_mux_select,
+                               NULL);
+
+       if (!dev->i2c_mux_adap[mux_no])
+               cx231xx_warn("%s: i2c mux %d register FAILED\n",
+                            dev->name, mux_no);
+
+       return 0;
+}
+
+void cx231xx_i2c_mux_unregister(struct cx231xx *dev, int mux_no)
+{
+       i2c_del_mux_adapter(dev->i2c_mux_adap[mux_no]);
+       dev->i2c_mux_adap[mux_no] = NULL;
+}
+
 struct i2c_adapter *cx231xx_get_i2c_adap(struct cx231xx *dev, int i2c_port)
 {
        switch (i2c_port) {
@@ -557,8 +598,9 @@ struct i2c_adapter *cx231xx_get_i2c_adap(struct cx231xx *dev, int i2c_port)
        case I2C_2:
                return &dev->i2c_bus[2].i2c_adap;
        case I2C_1_MUX_1:
+               return dev->i2c_mux_adap[0];
        case I2C_1_MUX_3:
-               return &dev->i2c_bus[1].i2c_adap;
+               return dev->i2c_mux_adap[1];
        default:
                return NULL;
        }
index 8a3c97b4e89539940286b244ec2a57251e2c8b88..c90aa44a6826bfa166211052dab6fa9c68417435 100644 (file)
@@ -628,6 +628,8 @@ struct cx231xx {
 
        /* I2C adapters: Master 1 & 2 (External) & Master 3 (Internal only) */
        struct cx231xx_i2c i2c_bus[3];
+       struct i2c_adapter *i2c_mux_adap[2];
+
        unsigned int xc_fw_load_done:1;
        unsigned int port_3_switch_enabled:1;
        /* locks */
@@ -755,6 +757,8 @@ int cx231xx_reset_analog_tuner(struct cx231xx *dev);
 void cx231xx_do_i2c_scan(struct cx231xx *dev, int i2c_port);
 int cx231xx_i2c_register(struct cx231xx_i2c *bus);
 int cx231xx_i2c_unregister(struct cx231xx_i2c *bus);
+int cx231xx_i2c_mux_register(struct cx231xx *dev, int mux_no);
+void cx231xx_i2c_mux_unregister(struct cx231xx *dev, int mux_no);
 struct i2c_adapter *cx231xx_get_i2c_adap(struct cx231xx *dev, int i2c_port);
 
 /* Internal block control functions */