.. | .. |
---|
1 | 1 | // SPDX-License-Identifier: GPL-2.0 |
---|
2 | 2 | #include <net/mac80211.h> |
---|
3 | 3 | #include <linux/bcma/bcma_driver_chipcommon.h> |
---|
4 | | -#include <linux/gpio.h> |
---|
| 4 | +#include <linux/gpio/driver.h> |
---|
| 5 | +#include <linux/gpio/machine.h> |
---|
| 6 | +#include <linux/gpio/consumer.h> |
---|
5 | 7 | |
---|
6 | 8 | #include "mac80211_if.h" |
---|
7 | 9 | #include "pub.h" |
---|
.. | .. |
---|
19 | 21 | |
---|
20 | 22 | static void brcms_radio_led_ctrl(struct brcms_info *wl, bool state) |
---|
21 | 23 | { |
---|
22 | | - if (wl->radio_led.gpio == -1) |
---|
| 24 | + if (!wl->radio_led.gpiod) |
---|
23 | 25 | return; |
---|
24 | 26 | |
---|
25 | | - if (wl->radio_led.active_low) |
---|
26 | | - state = !state; |
---|
27 | | - |
---|
28 | 27 | if (state) |
---|
29 | | - gpio_set_value(wl->radio_led.gpio, 1); |
---|
| 28 | + gpiod_set_value(wl->radio_led.gpiod, 1); |
---|
30 | 29 | else |
---|
31 | | - gpio_set_value(wl->radio_led.gpio, 0); |
---|
| 30 | + gpiod_set_value(wl->radio_led.gpiod, 0); |
---|
32 | 31 | } |
---|
33 | 32 | |
---|
34 | 33 | |
---|
.. | .. |
---|
45 | 44 | { |
---|
46 | 45 | if (wl->led_dev.dev) |
---|
47 | 46 | led_classdev_unregister(&wl->led_dev); |
---|
48 | | - if (wl->radio_led.gpio != -1) |
---|
49 | | - gpio_free(wl->radio_led.gpio); |
---|
| 47 | + if (wl->radio_led.gpiod) |
---|
| 48 | + gpiochip_free_own_desc(wl->radio_led.gpiod); |
---|
50 | 49 | } |
---|
51 | 50 | |
---|
52 | 51 | int brcms_led_register(struct brcms_info *wl) |
---|
.. | .. |
---|
61 | 60 | &sprom->gpio1, |
---|
62 | 61 | &sprom->gpio2, |
---|
63 | 62 | &sprom->gpio3 }; |
---|
64 | | - unsigned gpio = -1; |
---|
65 | | - bool active_low = false; |
---|
66 | | - |
---|
67 | | - /* none by default */ |
---|
68 | | - radio_led->gpio = -1; |
---|
69 | | - radio_led->active_low = false; |
---|
| 63 | + int hwnum = -1; |
---|
| 64 | + enum gpio_lookup_flags lflags = GPIO_ACTIVE_HIGH; |
---|
70 | 65 | |
---|
71 | 66 | if (!bcma_gpio || !gpio_is_valid(bcma_gpio->base)) |
---|
72 | 67 | return -ENODEV; |
---|
.. | .. |
---|
75 | 70 | for (i = 0; i < BRCMS_LED_NO; i++) { |
---|
76 | 71 | u8 led = *leds[i]; |
---|
77 | 72 | if ((led & BRCMS_LED_BEH_MASK) == BRCMS_LED_RADIO) { |
---|
78 | | - gpio = bcma_gpio->base + i; |
---|
| 73 | + hwnum = i; |
---|
79 | 74 | if (led & BRCMS_LED_AL_MASK) |
---|
80 | | - active_low = true; |
---|
| 75 | + lflags = GPIO_ACTIVE_LOW; |
---|
81 | 76 | break; |
---|
82 | 77 | } |
---|
83 | 78 | } |
---|
84 | 79 | |
---|
85 | | - if (gpio == -1 || !gpio_is_valid(gpio)) |
---|
| 80 | + /* No LED, bail out */ |
---|
| 81 | + if (hwnum == -1) |
---|
86 | 82 | return -ENODEV; |
---|
87 | 83 | |
---|
88 | | - /* request and configure LED gpio */ |
---|
89 | | - err = gpio_request_one(gpio, |
---|
90 | | - active_low ? GPIOF_OUT_INIT_HIGH |
---|
91 | | - : GPIOF_OUT_INIT_LOW, |
---|
92 | | - "radio on"); |
---|
93 | | - if (err) { |
---|
94 | | - wiphy_err(wl->wiphy, "requesting led gpio %d failed (err: %d)\n", |
---|
95 | | - gpio, err); |
---|
96 | | - return err; |
---|
97 | | - } |
---|
98 | | - err = gpio_direction_output(gpio, 1); |
---|
99 | | - if (err) { |
---|
100 | | - wiphy_err(wl->wiphy, "cannot set led gpio %d to output (err: %d)\n", |
---|
101 | | - gpio, err); |
---|
| 84 | + /* Try to obtain this LED GPIO line */ |
---|
| 85 | + radio_led->gpiod = gpiochip_request_own_desc(bcma_gpio, hwnum, |
---|
| 86 | + "radio on", lflags, |
---|
| 87 | + GPIOD_OUT_LOW); |
---|
| 88 | + |
---|
| 89 | + if (IS_ERR(radio_led->gpiod)) { |
---|
| 90 | + err = PTR_ERR(radio_led->gpiod); |
---|
| 91 | + wiphy_err(wl->wiphy, "requesting led GPIO failed (err: %d)\n", |
---|
| 92 | + err); |
---|
102 | 93 | return err; |
---|
103 | 94 | } |
---|
104 | 95 | |
---|
.. | .. |
---|
117 | 108 | return err; |
---|
118 | 109 | } |
---|
119 | 110 | |
---|
120 | | - wiphy_info(wl->wiphy, "registered radio enabled led device: %s gpio: %d\n", |
---|
121 | | - wl->radio_led.name, |
---|
122 | | - gpio); |
---|
123 | | - radio_led->gpio = gpio; |
---|
124 | | - radio_led->active_low = active_low; |
---|
| 111 | + wiphy_info(wl->wiphy, "registered radio enabled led device: %s\n", |
---|
| 112 | + wl->radio_led.name); |
---|
125 | 113 | |
---|
126 | 114 | return 0; |
---|
127 | 115 | } |
---|