aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio
diff options
context:
space:
mode:
authorPeter Rosin <peda@axentia.se>2016-04-20 02:40:49 -0400
committerWolfram Sang <wsa@the-dreams.de>2016-04-22 09:00:05 -0400
commit51f97f6dd73d9349f8e6a1d36ac5f7371d275fb3 (patch)
tree465e4f2fbbbffe07736f19e55a9c7b7b087dd6b2 /drivers/iio
parent193304aef8523265884f08144b1f98ad272e2d7e (diff)
iio: imu: inv_mpu6050: convert to use an explicit i2c mux core
Allocate an explicit i2c mux core to handle parent and child adapters etc. Update the select/deselect ops to be in terms of the i2c mux core instead of the child adapter. Acked-by: Jonathan Cameron <jic23@kernel.org> Tested-by: Crestez Dan Leonard <leonard.crestez@intel.com> Signed-off-by: Peter Rosin <peda@axentia.se> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Diffstat (limited to 'drivers/iio')
-rw-r--r--drivers/iio/imu/inv_mpu6050/inv_mpu_acpi.c2
-rw-r--r--drivers/iio/imu/inv_mpu6050/inv_mpu_core.c1
-rw-r--r--drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c33
-rw-r--r--drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h3
4 files changed, 19 insertions, 20 deletions
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_acpi.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_acpi.c
index 2771106fd650..f62b8bd9ad7e 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_acpi.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_acpi.c
@@ -183,7 +183,7 @@ int inv_mpu_acpi_create_mux_client(struct i2c_client *client)
183 } else 183 } else
184 return 0; /* no secondary addr, which is OK */ 184 return 0; /* no secondary addr, which is OK */
185 } 185 }
186 st->mux_client = i2c_new_device(st->mux_adapter, &info); 186 st->mux_client = i2c_new_device(st->muxc->adapter[0], &info);
187 if (!st->mux_client) 187 if (!st->mux_client)
188 return -ENODEV; 188 return -ENODEV;
189 } 189 }
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index d192953e9a38..0c2bded2b5b7 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -23,7 +23,6 @@
23#include <linux/kfifo.h> 23#include <linux/kfifo.h>
24#include <linux/spinlock.h> 24#include <linux/spinlock.h>
25#include <linux/iio/iio.h> 25#include <linux/iio/iio.h>
26#include <linux/i2c-mux.h>
27#include <linux/acpi.h> 26#include <linux/acpi.h>
28#include "inv_mpu_iio.h" 27#include "inv_mpu_iio.h"
29 28
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
index f581256d9d4c..3a078df84224 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
@@ -15,7 +15,6 @@
15#include <linux/delay.h> 15#include <linux/delay.h>
16#include <linux/err.h> 16#include <linux/err.h>
17#include <linux/i2c.h> 17#include <linux/i2c.h>
18#include <linux/i2c-mux.h>
19#include <linux/iio/iio.h> 18#include <linux/iio/iio.h>
20#include <linux/module.h> 19#include <linux/module.h>
21#include "inv_mpu_iio.h" 20#include "inv_mpu_iio.h"
@@ -52,10 +51,9 @@ static int inv_mpu6050_write_reg_unlocked(struct i2c_client *client,
52 return 0; 51 return 0;
53} 52}
54 53
55static int inv_mpu6050_select_bypass(struct i2c_adapter *adap, void *mux_priv, 54static int inv_mpu6050_select_bypass(struct i2c_mux_core *muxc, u32 chan_id)
56 u32 chan_id)
57{ 55{
58 struct i2c_client *client = mux_priv; 56 struct i2c_client *client = i2c_mux_priv(muxc);
59 struct iio_dev *indio_dev = dev_get_drvdata(&client->dev); 57 struct iio_dev *indio_dev = dev_get_drvdata(&client->dev);
60 struct inv_mpu6050_state *st = iio_priv(indio_dev); 58 struct inv_mpu6050_state *st = iio_priv(indio_dev);
61 int ret = 0; 59 int ret = 0;
@@ -84,10 +82,9 @@ write_error:
84 return ret; 82 return ret;
85} 83}
86 84
87static int inv_mpu6050_deselect_bypass(struct i2c_adapter *adap, 85static int inv_mpu6050_deselect_bypass(struct i2c_mux_core *muxc, u32 chan_id)
88 void *mux_priv, u32 chan_id)
89{ 86{
90 struct i2c_client *client = mux_priv; 87 struct i2c_client *client = i2c_mux_priv(muxc);
91 struct iio_dev *indio_dev = dev_get_drvdata(&client->dev); 88 struct iio_dev *indio_dev = dev_get_drvdata(&client->dev);
92 struct inv_mpu6050_state *st = iio_priv(indio_dev); 89 struct inv_mpu6050_state *st = iio_priv(indio_dev);
93 90
@@ -136,16 +133,18 @@ static int inv_mpu_probe(struct i2c_client *client,
136 return result; 133 return result;
137 134
138 st = iio_priv(dev_get_drvdata(&client->dev)); 135 st = iio_priv(dev_get_drvdata(&client->dev));
139 st->mux_adapter = i2c_add_mux_adapter(client->adapter, 136 st->muxc = i2c_mux_alloc(client->adapter, &client->dev,
140 &client->dev, 137 1, 0, 0,
141 client, 138 inv_mpu6050_select_bypass,
142 0, 0, 0, 139 inv_mpu6050_deselect_bypass);
143 inv_mpu6050_select_bypass, 140 if (!st->muxc) {
144 inv_mpu6050_deselect_bypass); 141 result = -ENOMEM;
145 if (!st->mux_adapter) {
146 result = -ENODEV;
147 goto out_unreg_device; 142 goto out_unreg_device;
148 } 143 }
144 st->muxc->priv = dev_get_drvdata(&client->dev);
145 result = i2c_mux_add_adapter(st->muxc, 0, 0, 0);
146 if (result)
147 goto out_unreg_device;
149 148
150 result = inv_mpu_acpi_create_mux_client(client); 149 result = inv_mpu_acpi_create_mux_client(client);
151 if (result) 150 if (result)
@@ -154,7 +153,7 @@ static int inv_mpu_probe(struct i2c_client *client,
154 return 0; 153 return 0;
155 154
156out_del_mux: 155out_del_mux:
157 i2c_del_mux_adapter(st->mux_adapter); 156 i2c_mux_del_adapters(st->muxc);
158out_unreg_device: 157out_unreg_device:
159 inv_mpu_core_remove(&client->dev); 158 inv_mpu_core_remove(&client->dev);
160 return result; 159 return result;
@@ -166,7 +165,7 @@ static int inv_mpu_remove(struct i2c_client *client)
166 struct inv_mpu6050_state *st = iio_priv(indio_dev); 165 struct inv_mpu6050_state *st = iio_priv(indio_dev);
167 166
168 inv_mpu_acpi_delete_mux_client(client); 167 inv_mpu_acpi_delete_mux_client(client);
169 i2c_del_mux_adapter(st->mux_adapter); 168 i2c_mux_del_adapters(st->muxc);
170 169
171 return inv_mpu_core_remove(&client->dev); 170 return inv_mpu_core_remove(&client->dev);
172} 171}
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
index e302a49703bf..bb3cef6d7059 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
@@ -11,6 +11,7 @@
11* GNU General Public License for more details. 11* GNU General Public License for more details.
12*/ 12*/
13#include <linux/i2c.h> 13#include <linux/i2c.h>
14#include <linux/i2c-mux.h>
14#include <linux/kfifo.h> 15#include <linux/kfifo.h>
15#include <linux/spinlock.h> 16#include <linux/spinlock.h>
16#include <linux/iio/iio.h> 17#include <linux/iio/iio.h>
@@ -127,7 +128,7 @@ struct inv_mpu6050_state {
127 const struct inv_mpu6050_hw *hw; 128 const struct inv_mpu6050_hw *hw;
128 enum inv_devices chip_type; 129 enum inv_devices chip_type;
129 spinlock_t time_stamp_lock; 130 spinlock_t time_stamp_lock;
130 struct i2c_adapter *mux_adapter; 131 struct i2c_mux_core *muxc;
131 struct i2c_client *mux_client; 132 struct i2c_client *mux_client;
132 unsigned int powerup_count; 133 unsigned int powerup_count;
133 struct inv_mpu6050_platform_data plat_data; 134 struct inv_mpu6050_platform_data plat_data;