Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1349641
| From | Peter Rosin <peda@lysator.liu.se> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH v4 02/18] i2c: i2c-mux-gpio: convert to use an explicit i2c mux core |
| Date | 2016-03-03 23:30 +0100 |
| Message-ID | <r8JUT-5sH-33@gated-at.bofh.it> (permalink) |
| References | <r8JUS-5sH-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
From: Peter Rosin <peda@axentia.se>
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.
Signed-off-by: Peter Rosin <peda@axentia.se>
---
drivers/i2c/muxes/i2c-mux-gpio.c | 54 ++++++++++++++++------------------------
1 file changed, 21 insertions(+), 33 deletions(-)
diff --git a/drivers/i2c/muxes/i2c-mux-gpio.c b/drivers/i2c/muxes/i2c-mux-gpio.c
index b8e11c16d98c..1bcc26737359 100644
--- a/drivers/i2c/muxes/i2c-mux-gpio.c
+++ b/drivers/i2c/muxes/i2c-mux-gpio.c
@@ -18,8 +18,6 @@
#include <linux/of_gpio.h>
struct gpiomux {
- struct i2c_adapter *parent;
- struct i2c_adapter **adap; /* child busses */
struct i2c_mux_gpio_platform_data data;
unsigned gpio_base;
};
@@ -33,18 +31,18 @@ static void i2c_mux_gpio_set(const struct gpiomux *mux, unsigned val)
val & (1 << i));
}
-static int i2c_mux_gpio_select(struct i2c_adapter *adap, void *data, u32 chan)
+static int i2c_mux_gpio_select(struct i2c_mux_core *muxc, u32 chan)
{
- struct gpiomux *mux = data;
+ struct gpiomux *mux = i2c_mux_priv(muxc);
i2c_mux_gpio_set(mux, chan);
return 0;
}
-static int i2c_mux_gpio_deselect(struct i2c_adapter *adap, void *data, u32 chan)
+static int i2c_mux_gpio_deselect(struct i2c_mux_core *muxc, u32 chan)
{
- struct gpiomux *mux = data;
+ struct gpiomux *mux = i2c_mux_priv(muxc);
i2c_mux_gpio_set(mux, mux->data.idle);
@@ -136,19 +134,19 @@ static int i2c_mux_gpio_probe_dt(struct gpiomux *mux,
static int i2c_mux_gpio_probe(struct platform_device *pdev)
{
+ struct i2c_mux_core *muxc;
struct gpiomux *mux;
struct i2c_adapter *parent;
- int (*deselect) (struct i2c_adapter *, void *, u32);
unsigned initial_state, gpio_base;
int i, ret;
- mux = devm_kzalloc(&pdev->dev, sizeof(*mux), GFP_KERNEL);
- if (!mux) {
- dev_err(&pdev->dev, "Cannot allocate gpiomux structure");
+ muxc = i2c_mux_alloc(NULL, &pdev->dev, sizeof(*mux), 0,
+ i2c_mux_gpio_select, NULL);
+ if (!muxc)
return -ENOMEM;
- }
+ mux = i2c_mux_priv(muxc);
- platform_set_drvdata(pdev, mux);
+ platform_set_drvdata(pdev, muxc);
if (!dev_get_platdata(&pdev->dev)) {
ret = i2c_mux_gpio_probe_dt(mux, pdev);
@@ -180,24 +178,18 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev)
if (!parent)
return -EPROBE_DEFER;
- mux->parent = parent;
+ muxc->parent = parent;
mux->gpio_base = gpio_base;
- mux->adap = devm_kzalloc(&pdev->dev,
- sizeof(*mux->adap) * mux->data.n_values,
- GFP_KERNEL);
- if (!mux->adap) {
- dev_err(&pdev->dev, "Cannot allocate i2c_adapter structure");
- ret = -ENOMEM;
+ ret = i2c_mux_reserve_adapters(muxc, mux->data.n_values);
+ if (ret)
goto alloc_failed;
- }
if (mux->data.idle != I2C_MUX_GPIO_NO_IDLE) {
initial_state = mux->data.idle;
- deselect = i2c_mux_gpio_deselect;
+ muxc->deselect = i2c_mux_gpio_deselect;
} else {
initial_state = mux->data.values[0];
- deselect = NULL;
}
for (i = 0; i < mux->data.n_gpios; i++) {
@@ -223,11 +215,8 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev)
u32 nr = mux->data.base_nr ? (mux->data.base_nr + i) : 0;
unsigned int class = mux->data.classes ? mux->data.classes[i] : 0;
- mux->adap[i] = i2c_add_mux_adapter(parent, &pdev->dev, mux, nr,
- mux->data.values[i], class,
- i2c_mux_gpio_select, deselect);
- if (!mux->adap[i]) {
- ret = -ENODEV;
+ ret = i2c_mux_add_adapter(muxc, nr, mux->data.values[i], class);
+ if (ret) {
dev_err(&pdev->dev, "Failed to add adapter %d\n", i);
goto add_adapter_failed;
}
@@ -239,8 +228,7 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev)
return 0;
add_adapter_failed:
- for (; i > 0; i--)
- i2c_del_mux_adapter(mux->adap[i - 1]);
+ i2c_mux_del_adapters(muxc);
i = mux->data.n_gpios;
err_request_gpio:
for (; i > 0; i--)
@@ -253,16 +241,16 @@ alloc_failed:
static int i2c_mux_gpio_remove(struct platform_device *pdev)
{
- struct gpiomux *mux = platform_get_drvdata(pdev);
+ struct i2c_mux_core *muxc = platform_get_drvdata(pdev);
+ struct gpiomux *mux = i2c_mux_priv(muxc);
int i;
- for (i = 0; i < mux->data.n_values; i++)
- i2c_del_mux_adapter(mux->adap[i]);
+ i2c_mux_del_adapters(muxc);
for (i = 0; i < mux->data.n_gpios; i++)
gpio_free(mux->gpio_base + mux->data.gpios[i]);
- i2c_put_adapter(mux->parent);
+ i2c_put_adapter(muxc->parent);
return 0;
}
--
2.1.4
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v4 00/18] i2c mux cleanup and locking update Peter Rosin <peda@lysator.liu.se> - 2016-03-03 23:30 +0100
[PATCH v4 10/18] [media] rtl2830: convert to use an explicit i2c mux core Peter Rosin <peda@lysator.liu.se> - 2016-03-03 23:30 +0100
[PATCH v4 12/18] [media] si2168: convert to use an explicit i2c mux core Peter Rosin <peda@lysator.liu.se> - 2016-03-03 23:30 +0100
[PATCH v4 05/18] i2c: i2c-mux-pca9541: convert to use an explicit i2c mux core Peter Rosin <peda@lysator.liu.se> - 2016-03-03 23:30 +0100
[PATCH v4 06/18] i2c: i2c-mux-pca954x: convert to use an explicit i2c mux core Peter Rosin <peda@lysator.liu.se> - 2016-03-03 23:30 +0100
[PATCH v4 11/18] [media] rtl2832: convert to use an explicit i2c mux core Peter Rosin <peda@lysator.liu.se> - 2016-03-03 23:30 +0100
[PATCH v4 04/18] i2c: i2c-arb-gpio-challenge: convert to use an explicit i2c mux core Peter Rosin <peda@lysator.liu.se> - 2016-03-03 23:30 +0100
[PATCH v4 02/18] i2c: i2c-mux-gpio: convert to use an explicit i2c mux core Peter Rosin <peda@lysator.liu.se> - 2016-03-03 23:30 +0100
[PATCH v4 03/18] i2c: i2c-mux-pinctrl: convert to use an explicit i2c mux core Peter Rosin <peda@lysator.liu.se> - 2016-03-03 23:30 +0100
[PATCH v4 18/18] i2c-mux: relax locking of the top i2c adapter during i2c controlled muxing Peter Rosin <peda@lysator.liu.se> - 2016-03-03 23:40 +0100
Re: [PATCH v4 18/18] i2c-mux: relax locking of the top i2c adapter during i2c controlled muxing kbuild test robot <lkp@intel.com> - 2016-03-04 06:30 +0100
Re: [PATCH v4 18/18] i2c-mux: relax locking of the top i2c adapter during i2c controlled muxing Peter Rosin <peda@lysator.liu.se> - 2016-03-04 08:20 +0100
[PATCH v4 15/18] i2c-mux: drop old unused i2c-mux api Peter Rosin <peda@lysator.liu.se> - 2016-03-03 23:40 +0100
[PATCH v4 13/18] [media] cx231xx: convert to use an explicit i2c mux core Peter Rosin <peda@lysator.liu.se> - 2016-03-03 23:40 +0100
[PATCH v4 09/18] [media] m88ds3103: convert to use an explicit i2c mux core Peter Rosin <peda@lysator.liu.se> - 2016-03-03 23:40 +0100
[PATCH v4 16/18] i2c: allow adapter drivers to override the adapter locking Peter Rosin <peda@lysator.liu.se> - 2016-03-03 23:40 +0100
Re: [PATCH v4 16/18] i2c: allow adapter drivers to override the adapter locking kbuild test robot <lkp@intel.com> - 2016-03-04 07:00 +0100
Re: [PATCH v4 16/18] i2c: allow adapter drivers to override the adapter locking Peter Rosin <peda@lysator.liu.se> - 2016-03-04 10:40 +0100
[PATCH v4 17/18] i2c: muxes always lock the parent adapter Peter Rosin <peda@lysator.liu.se> - 2016-03-03 23:40 +0100
[PATCH v4 14/18] of/unittest: convert to use an explicit i2c mux core Peter Rosin <peda@lysator.liu.se> - 2016-03-03 23:40 +0100
Re: [PATCH v4 00/18] i2c mux cleanup and locking update Peter Rosin <peda@lysator.liu.se> - 2016-03-04 12:10 +0100
Re: [PATCH v4 00/18] i2c mux cleanup and locking update Peter Rosin <peda@lysator.liu.se> - 2016-03-04 15:50 +0100
Re: [PATCH v4 00/18] i2c mux cleanup and locking update Peter Rosin <peda@lysator.liu.se> - 2016-03-15 15:20 +0100
Re: [PATCH v4 00/18] i2c mux cleanup and locking update Antti Palosaari <crope@iki.fi> - 2016-03-15 18:10 +0100
csiph-web