1 // SPDX-License-Identifier: GPL-2.0
2 #include <net/mac80211.h>
3 #include <linux/bcma/bcma_driver_chipcommon.h>
4 #include <linux/gpio.h>
6 #include "mac80211_if.h"
12 #define BRCMS_LED_NO 4
14 #define BRCMS_LED_BEH_MASK 0x7f
15 /* activelow (polarity) bit */
16 #define BRCMS_LED_AL_MASK 0x80
18 #define BRCMS_LED_RADIO 3
20 static void brcms_radio_led_ctrl(struct brcms_info
*wl
, bool state
)
22 if (wl
->radio_led
.gpio
== -1)
25 if (wl
->radio_led
.active_low
)
29 gpio_set_value(wl
->radio_led
.gpio
, 1);
31 gpio_set_value(wl
->radio_led
.gpio
, 0);
35 /* Callback from the LED subsystem. */
36 static void brcms_led_brightness_set(struct led_classdev
*led_dev
,
37 enum led_brightness brightness
)
39 struct brcms_info
*wl
= container_of(led_dev
,
40 struct brcms_info
, led_dev
);
41 brcms_radio_led_ctrl(wl
, brightness
);
44 void brcms_led_unregister(struct brcms_info
*wl
)
47 led_classdev_unregister(&wl
->led_dev
);
48 if (wl
->radio_led
.gpio
!= -1)
49 gpio_free(wl
->radio_led
.gpio
);
52 int brcms_led_register(struct brcms_info
*wl
)
55 struct brcms_led
*radio_led
= &wl
->radio_led
;
57 struct bcma_drv_cc
*cc_drv
= &wl
->wlc
->hw
->d11core
->bus
->drv_cc
;
58 struct gpio_chip
*bcma_gpio
= &cc_drv
->gpio
;
59 struct ssb_sprom
*sprom
= &wl
->wlc
->hw
->d11core
->bus
->sprom
;
60 u8
*leds
[] = { &sprom
->gpio0
,
65 bool active_low
= false;
69 radio_led
->active_low
= false;
71 if (!bcma_gpio
|| !gpio_is_valid(bcma_gpio
->base
))
74 /* find radio enabled LED */
75 for (i
= 0; i
< BRCMS_LED_NO
; i
++) {
77 if ((led
& BRCMS_LED_BEH_MASK
) == BRCMS_LED_RADIO
) {
78 gpio
= bcma_gpio
->base
+ i
;
79 if (led
& BRCMS_LED_AL_MASK
)
85 if (gpio
== -1 || !gpio_is_valid(gpio
))
88 /* request and configure LED gpio */
89 err
= gpio_request_one(gpio
,
90 active_low
? GPIOF_OUT_INIT_HIGH
94 wiphy_err(wl
->wiphy
, "requesting led gpio %d failed (err: %d)\n",
98 err
= gpio_direction_output(gpio
, 1);
100 wiphy_err(wl
->wiphy
, "cannot set led gpio %d to output (err: %d)\n",
105 snprintf(wl
->radio_led
.name
, sizeof(wl
->radio_led
.name
),
106 "brcmsmac-%s:radio", wiphy_name(wl
->wiphy
));
108 wl
->led_dev
.name
= wl
->radio_led
.name
;
109 wl
->led_dev
.default_trigger
=
110 ieee80211_get_radio_led_name(wl
->pub
->ieee_hw
);
111 wl
->led_dev
.brightness_set
= brcms_led_brightness_set
;
112 err
= led_classdev_register(wiphy_dev(wl
->wiphy
), &wl
->led_dev
);
115 wiphy_err(wl
->wiphy
, "cannot register led device: %s (err: %d)\n",
116 wl
->radio_led
.name
, err
);
120 wiphy_info(wl
->wiphy
, "registered radio enabled led device: %s gpio: %d\n",
123 radio_led
->gpio
= gpio
;
124 radio_led
->active_low
= active_low
;