2
0
mirror of https://github.com/edk2-porting/linux-next.git synced 2024-12-14 16:23:51 +08:00

mdio-mux-gpio: use new gpiod_get_array and gpiod_put_array functions

Use the new gpiod_get_array and gpiod_put_array functions
(added to mainline in the v4.1 merge window) for obtaining and
disposing of GPIO descriptors.

Cc: David Miller <davem@davemloft.net>
Cc: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Rojhalat Ibrahim <imr@rtschenk.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Rojhalat Ibrahim 2015-04-27 10:37:31 +02:00 committed by David S. Miller
parent 129d23a566
commit 33df10e2ee

View File

@ -12,33 +12,30 @@
#include <linux/module.h>
#include <linux/phy.h>
#include <linux/mdio-mux.h>
#include <linux/of_gpio.h>
#include <linux/gpio/consumer.h>
#define DRV_VERSION "1.1"
#define DRV_DESCRIPTION "GPIO controlled MDIO bus multiplexer driver"
#define MDIO_MUX_GPIO_MAX_BITS 8
struct mdio_mux_gpio_state {
struct gpio_desc *gpio[MDIO_MUX_GPIO_MAX_BITS];
unsigned int num_gpios;
struct gpio_descs *gpios;
void *mux_handle;
};
static int mdio_mux_gpio_switch_fn(int current_child, int desired_child,
void *data)
{
int values[MDIO_MUX_GPIO_MAX_BITS];
unsigned int n;
struct mdio_mux_gpio_state *s = data;
int values[s->gpios->ndescs];
unsigned int n;
if (current_child == desired_child)
return 0;
for (n = 0; n < s->num_gpios; n++) {
for (n = 0; n < s->gpios->ndescs; n++)
values[n] = (desired_child >> n) & 1;
}
gpiod_set_array_cansleep(s->num_gpios, s->gpio, values);
gpiod_set_array_cansleep(s->gpios->ndescs, s->gpios->desc, values);
return 0;
}
@ -46,56 +43,33 @@ static int mdio_mux_gpio_switch_fn(int current_child, int desired_child,
static int mdio_mux_gpio_probe(struct platform_device *pdev)
{
struct mdio_mux_gpio_state *s;
int num_gpios;
unsigned int n;
int r;
if (!pdev->dev.of_node)
return -ENODEV;
num_gpios = of_gpio_count(pdev->dev.of_node);
if (num_gpios <= 0 || num_gpios > MDIO_MUX_GPIO_MAX_BITS)
return -ENODEV;
s = devm_kzalloc(&pdev->dev, sizeof(*s), GFP_KERNEL);
if (!s)
return -ENOMEM;
s->num_gpios = num_gpios;
for (n = 0; n < num_gpios; ) {
struct gpio_desc *gpio = gpiod_get_index(&pdev->dev, NULL, n,
GPIOD_OUT_LOW);
if (IS_ERR(gpio)) {
r = PTR_ERR(gpio);
goto err;
}
s->gpio[n] = gpio;
n++;
}
s->gpios = gpiod_get_array(&pdev->dev, NULL, GPIOD_OUT_LOW);
if (IS_ERR(s->gpios))
return PTR_ERR(s->gpios);
r = mdio_mux_init(&pdev->dev,
mdio_mux_gpio_switch_fn, &s->mux_handle, s);
if (r == 0) {
pdev->dev.platform_data = s;
return 0;
if (r != 0) {
gpiod_put_array(s->gpios);
return r;
}
err:
while (n) {
n--;
gpiod_put(s->gpio[n]);
}
return r;
pdev->dev.platform_data = s;
return 0;
}
static int mdio_mux_gpio_remove(struct platform_device *pdev)
{
unsigned int n;
struct mdio_mux_gpio_state *s = dev_get_platdata(&pdev->dev);
mdio_mux_uninit(s->mux_handle);
for (n = 0; n < s->num_gpios; n++)
gpiod_put(s->gpio[n]);
gpiod_put_array(s->gpios);
return 0;
}