aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
authorRojhalat Ibrahim <imr@rtschenk.de>2015-04-27 04:37:31 -0400
committerDavid S. Miller <davem@davemloft.net>2015-04-27 13:35:40 -0400
commit33df10e2ee414183953cc89453bf9c85027a188b (patch)
treea860ce3d20ae4fa26f4159df1154309660a8b58f /drivers/net
parent129d23a56623eea0947a05288158d76dc7f2f0ac (diff)
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>
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/phy/mdio-mux-gpio.c60
1 files changed, 17 insertions, 43 deletions
diff --git a/drivers/net/phy/mdio-mux-gpio.c b/drivers/net/phy/mdio-mux-gpio.c
index 1a87a585e74d..66edd99bc302 100644
--- a/drivers/net/phy/mdio-mux-gpio.c
+++ b/drivers/net/phy/mdio-mux-gpio.c
@@ -12,33 +12,30 @@
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/phy.h> 13#include <linux/phy.h>
14#include <linux/mdio-mux.h> 14#include <linux/mdio-mux.h>
15#include <linux/of_gpio.h> 15#include <linux/gpio/consumer.h>
16 16
17#define DRV_VERSION "1.1" 17#define DRV_VERSION "1.1"
18#define DRV_DESCRIPTION "GPIO controlled MDIO bus multiplexer driver" 18#define DRV_DESCRIPTION "GPIO controlled MDIO bus multiplexer driver"
19 19
20#define MDIO_MUX_GPIO_MAX_BITS 8
21
22struct mdio_mux_gpio_state { 20struct mdio_mux_gpio_state {
23 struct gpio_desc *gpio[MDIO_MUX_GPIO_MAX_BITS]; 21 struct gpio_descs *gpios;
24 unsigned int num_gpios;
25 void *mux_handle; 22 void *mux_handle;
26}; 23};
27 24
28static int mdio_mux_gpio_switch_fn(int current_child, int desired_child, 25static int mdio_mux_gpio_switch_fn(int current_child, int desired_child,
29 void *data) 26 void *data)
30{ 27{
31 int values[MDIO_MUX_GPIO_MAX_BITS];
32 unsigned int n;
33 struct mdio_mux_gpio_state *s = data; 28 struct mdio_mux_gpio_state *s = data;
29 int values[s->gpios->ndescs];
30 unsigned int n;
34 31
35 if (current_child == desired_child) 32 if (current_child == desired_child)
36 return 0; 33 return 0;
37 34
38 for (n = 0; n < s->num_gpios; n++) { 35 for (n = 0; n < s->gpios->ndescs; n++)
39 values[n] = (desired_child >> n) & 1; 36 values[n] = (desired_child >> n) & 1;
40 } 37
41 gpiod_set_array_cansleep(s->num_gpios, s->gpio, values); 38 gpiod_set_array_cansleep(s->gpios->ndescs, s->gpios->desc, values);
42 39
43 return 0; 40 return 0;
44} 41}
@@ -46,56 +43,33 @@ static int mdio_mux_gpio_switch_fn(int current_child, int desired_child,
46static int mdio_mux_gpio_probe(struct platform_device *pdev) 43static int mdio_mux_gpio_probe(struct platform_device *pdev)
47{ 44{
48 struct mdio_mux_gpio_state *s; 45 struct mdio_mux_gpio_state *s;
49 int num_gpios;
50 unsigned int n;
51 int r; 46 int r;
52 47
53 if (!pdev->dev.of_node)
54 return -ENODEV;
55
56 num_gpios = of_gpio_count(pdev->dev.of_node);
57 if (num_gpios <= 0 || num_gpios > MDIO_MUX_GPIO_MAX_BITS)
58 return -ENODEV;
59
60 s = devm_kzalloc(&pdev->dev, sizeof(*s), GFP_KERNEL); 48 s = devm_kzalloc(&pdev->dev, sizeof(*s), GFP_KERNEL);
61 if (!s) 49 if (!s)
62 return -ENOMEM; 50 return -ENOMEM;
63 51
64 s->num_gpios = num_gpios; 52 s->gpios = gpiod_get_array(&pdev->dev, NULL, GPIOD_OUT_LOW);
65 53 if (IS_ERR(s->gpios))
66 for (n = 0; n < num_gpios; ) { 54 return PTR_ERR(s->gpios);
67 struct gpio_desc *gpio = gpiod_get_index(&pdev->dev, NULL, n,
68 GPIOD_OUT_LOW);
69 if (IS_ERR(gpio)) {
70 r = PTR_ERR(gpio);
71 goto err;
72 }
73 s->gpio[n] = gpio;
74 n++;
75 }
76 55
77 r = mdio_mux_init(&pdev->dev, 56 r = mdio_mux_init(&pdev->dev,
78 mdio_mux_gpio_switch_fn, &s->mux_handle, s); 57 mdio_mux_gpio_switch_fn, &s->mux_handle, s);
79 58
80 if (r == 0) { 59 if (r != 0) {
81 pdev->dev.platform_data = s; 60 gpiod_put_array(s->gpios);
82 return 0; 61 return r;
83 }
84err:
85 while (n) {
86 n--;
87 gpiod_put(s->gpio[n]);
88 } 62 }
89 return r; 63
64 pdev->dev.platform_data = s;
65 return 0;
90} 66}
91 67
92static int mdio_mux_gpio_remove(struct platform_device *pdev) 68static int mdio_mux_gpio_remove(struct platform_device *pdev)
93{ 69{
94 unsigned int n;
95 struct mdio_mux_gpio_state *s = dev_get_platdata(&pdev->dev); 70 struct mdio_mux_gpio_state *s = dev_get_platdata(&pdev->dev);
96 mdio_mux_uninit(s->mux_handle); 71 mdio_mux_uninit(s->mux_handle);
97 for (n = 0; n < s->num_gpios; n++) 72 gpiod_put_array(s->gpios);
98 gpiod_put(s->gpio[n]);
99 return 0; 73 return 0;
100} 74}
101 75