1 #include <net/mac80211.h>
2 #include <linux/bcma/bcma_driver_chipcommon.h>
3 #include <linux/gpio.h>
5 #include "mac80211_if.h"
11 #define BRCMS_LED_NO 4
13 #define BRCMS_LED_BEH_MASK 0x7f
14 /* activelow (polarity) bit */
15 #define BRCMS_LED_AL_MASK 0x80
17 #define BRCMS_LED_RADIO 3
19 static void brcms_radio_led_ctrl(struct brcms_info
*wl
, bool state
)
21 if (wl
->radio_led
.gpio
== -1)
24 if (wl
->radio_led
.active_low
)
28 gpio_set_value(wl
->radio_led
.gpio
, 1);
30 gpio_set_value(wl
->radio_led
.gpio
, 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
.gpio
!= -1)
48 gpio_free(wl
->radio_led
.gpio
);
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 bool active_low
= false;
68 radio_led
->active_low
= false;
70 if (!bcma_gpio
|| !gpio_is_valid(bcma_gpio
->base
))
73 /* find radio enabled LED */
74 for (i
= 0; i
< BRCMS_LED_NO
; i
++) {
76 if ((led
& BRCMS_LED_BEH_MASK
) == BRCMS_LED_RADIO
) {
77 gpio
= bcma_gpio
->base
+ i
;
78 if (led
& BRCMS_LED_AL_MASK
)
84 if (gpio
== -1 || !gpio_is_valid(gpio
))
87 /* request and configure LED gpio */
88 err
= gpio_request_one(gpio
,
89 active_low
? GPIOF_OUT_INIT_HIGH
93 wiphy_err(wl
->wiphy
, "requesting led gpio %d failed (err: %d)\n",
97 err
= gpio_direction_output(gpio
, 1);
99 wiphy_err(wl
->wiphy
, "cannot set led gpio %d to output (err: %d)\n",
104 snprintf(wl
->radio_led
.name
, sizeof(wl
->radio_led
.name
),
105 "brcmsmac-%s:radio", wiphy_name(wl
->wiphy
));
107 wl
->led_dev
.name
= wl
->radio_led
.name
;
108 wl
->led_dev
.default_trigger
=
109 ieee80211_get_radio_led_name(wl
->pub
->ieee_hw
);
110 wl
->led_dev
.brightness_set
= brcms_led_brightness_set
;
111 err
= led_classdev_register(wiphy_dev(wl
->wiphy
), &wl
->led_dev
);
114 wiphy_err(wl
->wiphy
, "cannot register led device: %s (err: %d)\n",
115 wl
->radio_led
.name
, err
);
119 wiphy_info(wl
->wiphy
, "registered radio enabled led device: %s gpio: %d\n",
122 radio_led
->gpio
= gpio
;
123 radio_led
->active_low
= active_low
;