1 // SPDX-License-Identifier: GPL-2.0
2 #include <net/mac80211.h>
3 #include <linux/bcma/bcma_driver_chipcommon.h>
4 #include <linux/gpio/driver.h>
5 #include <linux/gpio/machine.h>
6 #include <linux/gpio/consumer.h>
8 #include "mac80211_if.h"
14 #define BRCMS_LED_NO 4
16 #define BRCMS_LED_BEH_MASK 0x7f
17 /* activelow (polarity) bit */
18 #define BRCMS_LED_AL_MASK 0x80
20 #define BRCMS_LED_RADIO 3
22 static void brcms_radio_led_ctrl(struct brcms_info *wl, bool state)
24 if (!wl->radio_led.gpiod)
28 gpiod_set_value(wl->radio_led.gpiod, 1);
30 gpiod_set_value(wl->radio_led.gpiod, 0);
34 /* Callback from the LED subsystem. */
35 static void brcms_led_brightness_set(struct led_classdev *led_dev,
36 enum led_brightness brightness)
38 struct brcms_info *wl = container_of(led_dev,
39 struct brcms_info, led_dev);
40 brcms_radio_led_ctrl(wl, brightness);
43 void brcms_led_unregister(struct brcms_info *wl)
46 led_classdev_unregister(&wl->led_dev);
47 if (wl->radio_led.gpiod)
48 gpiochip_free_own_desc(wl->radio_led.gpiod);
51 int brcms_led_register(struct brcms_info *wl)
54 struct brcms_led *radio_led = &wl->radio_led;
56 struct bcma_drv_cc *cc_drv = &wl->wlc->hw->d11core->bus->drv_cc;
57 struct gpio_chip *bcma_gpio = &cc_drv->gpio;
58 struct ssb_sprom *sprom = &wl->wlc->hw->d11core->bus->sprom;
59 u8 *leds[] = { &sprom->gpio0,
64 enum gpio_lookup_flags lflags = GPIO_ACTIVE_HIGH;
66 if (!bcma_gpio || !gpio_is_valid(bcma_gpio->base))
69 /* find radio enabled LED */
70 for (i = 0; i < BRCMS_LED_NO; i++) {
72 if ((led & BRCMS_LED_BEH_MASK) == BRCMS_LED_RADIO) {
74 if (led & BRCMS_LED_AL_MASK)
75 lflags = GPIO_ACTIVE_LOW;
80 /* No LED, bail out */
84 /* Try to obtain this LED GPIO line */
85 radio_led->gpiod = gpiochip_request_own_desc(bcma_gpio, hwnum,
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",
96 snprintf(wl->radio_led.name, sizeof(wl->radio_led.name),
97 "brcmsmac-%s:radio", wiphy_name(wl->wiphy));
99 wl->led_dev.name = wl->radio_led.name;
100 wl->led_dev.default_trigger =
101 ieee80211_get_radio_led_name(wl->pub->ieee_hw);
102 wl->led_dev.brightness_set = brcms_led_brightness_set;
103 err = led_classdev_register(wiphy_dev(wl->wiphy), &wl->led_dev);
106 wiphy_err(wl->wiphy, "cannot register led device: %s (err: %d)\n",
107 wl->radio_led.name, err);
111 wiphy_info(wl->wiphy, "registered radio enabled led device: %s\n",