Commit feff5c0a authored by Peter Rosin's avatar Peter Rosin Committed by Wolfram Sang

i2c: i2c-mux-gpio: update mux with gpiod_set_array_value_cansleep

If the gpio controller supports it and the gpio lines are concentrated
to one gpio chip, the mux controller pins will get updated simultaneously.
Signed-off-by: default avatarPeter Rosin <peda@axentia.se>
Signed-off-by: default avatarWolfram Sang <wsa@the-dreams.de>
parent bbf9d262
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
struct gpiomux { struct gpiomux {
struct i2c_mux_gpio_platform_data data; struct i2c_mux_gpio_platform_data data;
unsigned gpio_base; unsigned gpio_base;
struct gpio_desc **gpios;
int *values;
}; };
static void i2c_mux_gpio_set(const struct gpiomux *mux, unsigned val) static void i2c_mux_gpio_set(const struct gpiomux *mux, unsigned val)
...@@ -28,8 +30,10 @@ static void i2c_mux_gpio_set(const struct gpiomux *mux, unsigned val) ...@@ -28,8 +30,10 @@ static void i2c_mux_gpio_set(const struct gpiomux *mux, unsigned val)
int i; int i;
for (i = 0; i < mux->data.n_gpios; i++) for (i = 0; i < mux->data.n_gpios; i++)
gpio_set_value_cansleep(mux->gpio_base + mux->data.gpios[i], mux->values[i] = (val >> i) & 1;
val & (1 << i));
gpiod_set_array_value_cansleep(mux->data.n_gpios,
mux->gpios, mux->values);
} }
static int i2c_mux_gpio_select(struct i2c_mux_core *muxc, u32 chan) static int i2c_mux_gpio_select(struct i2c_mux_core *muxc, u32 chan)
...@@ -176,12 +180,16 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev) ...@@ -176,12 +180,16 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev)
if (!parent) if (!parent)
return -EPROBE_DEFER; return -EPROBE_DEFER;
muxc = i2c_mux_alloc(parent, &pdev->dev, mux->data.n_values, 0, 0, muxc = i2c_mux_alloc(parent, &pdev->dev, mux->data.n_values,
mux->data.n_gpios * sizeof(*mux->gpios) +
mux->data.n_gpios * sizeof(*mux->values), 0,
i2c_mux_gpio_select, NULL); i2c_mux_gpio_select, NULL);
if (!muxc) { if (!muxc) {
ret = -ENOMEM; ret = -ENOMEM;
goto alloc_failed; goto alloc_failed;
} }
mux->gpios = muxc->priv;
mux->values = (int *)(mux->gpios + mux->data.n_gpios);
muxc->priv = mux; muxc->priv = mux;
platform_set_drvdata(pdev, muxc); platform_set_drvdata(pdev, muxc);
...@@ -219,10 +227,12 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev) ...@@ -219,10 +227,12 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev)
goto err_request_gpio; goto err_request_gpio;
} }
gpio_desc = gpio_to_desc(gpio_base + mux->data.gpios[i]);
mux->gpios[i] = gpio_desc;
if (!muxc->mux_locked) if (!muxc->mux_locked)
continue; continue;
gpio_desc = gpio_to_desc(gpio_base + mux->data.gpios[i]);
gpio_dev = &gpio_desc->gdev->dev; gpio_dev = &gpio_desc->gdev->dev;
muxc->mux_locked = i2c_root_adapter(gpio_dev) == root; muxc->mux_locked = i2c_root_adapter(gpio_dev) == root;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment