mdio-mux-gpio: Use GPIO descriptor interface and new gpiod_set_array function
Convert mdio-mux-gpio to the GPIO descriptor interface and use the new gpiod_set_array function to set all output signals simultaneously. Signed-off-by: Rojhalat Ibrahim <imr@rtschenk.de> Acked-by: David S. Miller <davem@davemloft.net> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
This commit is contained in:
committed by
Linus Walleij
parent
8e53b0f190
commit
441e002624
@@ -14,13 +14,13 @@
|
|||||||
#include <linux/mdio-mux.h>
|
#include <linux/mdio-mux.h>
|
||||||
#include <linux/of_gpio.h>
|
#include <linux/of_gpio.h>
|
||||||
|
|
||||||
#define DRV_VERSION "1.0"
|
#define DRV_VERSION "1.1"
|
||||||
#define DRV_DESCRIPTION "GPIO controlled MDIO bus multiplexer driver"
|
#define DRV_DESCRIPTION "GPIO controlled MDIO bus multiplexer driver"
|
||||||
|
|
||||||
#define MDIO_MUX_GPIO_MAX_BITS 8
|
#define MDIO_MUX_GPIO_MAX_BITS 8
|
||||||
|
|
||||||
struct mdio_mux_gpio_state {
|
struct mdio_mux_gpio_state {
|
||||||
int gpio[MDIO_MUX_GPIO_MAX_BITS];
|
struct gpio_desc *gpio[MDIO_MUX_GPIO_MAX_BITS];
|
||||||
unsigned int num_gpios;
|
unsigned int num_gpios;
|
||||||
void *mux_handle;
|
void *mux_handle;
|
||||||
};
|
};
|
||||||
@@ -28,29 +28,23 @@ struct mdio_mux_gpio_state {
|
|||||||
static int mdio_mux_gpio_switch_fn(int current_child, int desired_child,
|
static int mdio_mux_gpio_switch_fn(int current_child, int desired_child,
|
||||||
void *data)
|
void *data)
|
||||||
{
|
{
|
||||||
int change;
|
int values[MDIO_MUX_GPIO_MAX_BITS];
|
||||||
unsigned int n;
|
unsigned int n;
|
||||||
struct mdio_mux_gpio_state *s = data;
|
struct mdio_mux_gpio_state *s = data;
|
||||||
|
|
||||||
if (current_child == desired_child)
|
if (current_child == desired_child)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
change = current_child == -1 ? -1 : current_child ^ desired_child;
|
|
||||||
|
|
||||||
for (n = 0; n < s->num_gpios; n++) {
|
for (n = 0; n < s->num_gpios; n++) {
|
||||||
if (change & 1)
|
values[n] = (desired_child >> n) & 1;
|
||||||
gpio_set_value_cansleep(s->gpio[n],
|
|
||||||
(desired_child & 1) != 0);
|
|
||||||
change >>= 1;
|
|
||||||
desired_child >>= 1;
|
|
||||||
}
|
}
|
||||||
|
gpiod_set_array_cansleep(s->num_gpios, s->gpio, values);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mdio_mux_gpio_probe(struct platform_device *pdev)
|
static int mdio_mux_gpio_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
enum of_gpio_flags f;
|
|
||||||
struct mdio_mux_gpio_state *s;
|
struct mdio_mux_gpio_state *s;
|
||||||
int num_gpios;
|
int num_gpios;
|
||||||
unsigned int n;
|
unsigned int n;
|
||||||
@@ -70,22 +64,14 @@ static int mdio_mux_gpio_probe(struct platform_device *pdev)
|
|||||||
s->num_gpios = num_gpios;
|
s->num_gpios = num_gpios;
|
||||||
|
|
||||||
for (n = 0; n < num_gpios; ) {
|
for (n = 0; n < num_gpios; ) {
|
||||||
int gpio = of_get_gpio_flags(pdev->dev.of_node, n, &f);
|
struct gpio_desc *gpio = gpiod_get_index(&pdev->dev, NULL, n,
|
||||||
if (gpio < 0) {
|
GPIOD_OUT_LOW);
|
||||||
r = (gpio == -ENODEV) ? -EPROBE_DEFER : gpio;
|
if (IS_ERR(gpio)) {
|
||||||
|
r = PTR_ERR(gpio);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
s->gpio[n] = gpio;
|
s->gpio[n] = gpio;
|
||||||
|
|
||||||
n++;
|
n++;
|
||||||
|
|
||||||
r = gpio_request(gpio, "mdio_mux_gpio");
|
|
||||||
if (r)
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
r = gpio_direction_output(gpio, 0);
|
|
||||||
if (r)
|
|
||||||
goto err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
r = mdio_mux_init(&pdev->dev,
|
r = mdio_mux_init(&pdev->dev,
|
||||||
@@ -98,15 +84,18 @@ static int mdio_mux_gpio_probe(struct platform_device *pdev)
|
|||||||
err:
|
err:
|
||||||
while (n) {
|
while (n) {
|
||||||
n--;
|
n--;
|
||||||
gpio_free(s->gpio[n]);
|
gpiod_put(s->gpio[n]);
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mdio_mux_gpio_remove(struct platform_device *pdev)
|
static int mdio_mux_gpio_remove(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
|
unsigned int n;
|
||||||
struct mdio_mux_gpio_state *s = dev_get_platdata(&pdev->dev);
|
struct mdio_mux_gpio_state *s = dev_get_platdata(&pdev->dev);
|
||||||
mdio_mux_uninit(s->mux_handle);
|
mdio_mux_uninit(s->mux_handle);
|
||||||
|
for (n = 0; n < s->num_gpios; n++)
|
||||||
|
gpiod_put(s->gpio[n]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user