Commit b4248081 authored by Linus Walleij's avatar Linus Walleij Committed by Kalle Valo

brcm80211: brcmsmac: Move LEDs to GPIO descriptors

The code in the BRCM80211 BRCMSMAC driver is using the legacy
GPIO API to to a complex check of the validity of the base of
the GPIO chip and whether it is present at all and then adding
an offset to the base of the chip.

Use the existing function to obtain a GPIO line internally
from a GPIO chip so we can use the offset directly and
modernize the code to use GPIO descriptors instead of integers
from the global GPIO numberspace.

Cc: Wright Feng <wright.feng@cypress.com>
Cc: Frank Kao <frank.kao@cypress.com>
Cc: Kalle Valo <kvalo@codeaurora.org>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20200711210150.4943-1-linus.walleij@linaro.org
parent 29e354eb
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include <net/mac80211.h> #include <net/mac80211.h>
#include <linux/bcma/bcma_driver_chipcommon.h> #include <linux/bcma/bcma_driver_chipcommon.h>
#include <linux/gpio.h> #include <linux/gpio/driver.h>
#include <linux/gpio/machine.h>
#include <linux/gpio/consumer.h>
#include "mac80211_if.h" #include "mac80211_if.h"
#include "pub.h" #include "pub.h"
...@@ -19,16 +21,13 @@ ...@@ -19,16 +21,13 @@
static void brcms_radio_led_ctrl(struct brcms_info *wl, bool state) static void brcms_radio_led_ctrl(struct brcms_info *wl, bool state)
{ {
if (wl->radio_led.gpio == -1) if (!wl->radio_led.gpiod)
return; return;
if (wl->radio_led.active_low)
state = !state;
if (state) if (state)
gpio_set_value(wl->radio_led.gpio, 1); gpiod_set_value(wl->radio_led.gpiod, 1);
else else
gpio_set_value(wl->radio_led.gpio, 0); gpiod_set_value(wl->radio_led.gpiod, 0);
} }
...@@ -45,8 +44,8 @@ void brcms_led_unregister(struct brcms_info *wl) ...@@ -45,8 +44,8 @@ void brcms_led_unregister(struct brcms_info *wl)
{ {
if (wl->led_dev.dev) if (wl->led_dev.dev)
led_classdev_unregister(&wl->led_dev); led_classdev_unregister(&wl->led_dev);
if (wl->radio_led.gpio != -1) if (wl->radio_led.gpiod)
gpio_free(wl->radio_led.gpio); gpiochip_free_own_desc(wl->radio_led.gpiod);
} }
int brcms_led_register(struct brcms_info *wl) int brcms_led_register(struct brcms_info *wl)
...@@ -61,12 +60,8 @@ int brcms_led_register(struct brcms_info *wl) ...@@ -61,12 +60,8 @@ int brcms_led_register(struct brcms_info *wl)
&sprom->gpio1, &sprom->gpio1,
&sprom->gpio2, &sprom->gpio2,
&sprom->gpio3 }; &sprom->gpio3 };
unsigned gpio = -1; int hwnum = -1;
bool active_low = false; enum gpio_lookup_flags lflags = GPIO_ACTIVE_HIGH;
/* none by default */
radio_led->gpio = -1;
radio_led->active_low = false;
if (!bcma_gpio || !gpio_is_valid(bcma_gpio->base)) if (!bcma_gpio || !gpio_is_valid(bcma_gpio->base))
return -ENODEV; return -ENODEV;
...@@ -75,30 +70,26 @@ int brcms_led_register(struct brcms_info *wl) ...@@ -75,30 +70,26 @@ int brcms_led_register(struct brcms_info *wl)
for (i = 0; i < BRCMS_LED_NO; i++) { for (i = 0; i < BRCMS_LED_NO; i++) {
u8 led = *leds[i]; u8 led = *leds[i];
if ((led & BRCMS_LED_BEH_MASK) == BRCMS_LED_RADIO) { if ((led & BRCMS_LED_BEH_MASK) == BRCMS_LED_RADIO) {
gpio = bcma_gpio->base + i; hwnum = i;
if (led & BRCMS_LED_AL_MASK) if (led & BRCMS_LED_AL_MASK)
active_low = true; lflags = GPIO_ACTIVE_LOW;
break; break;
} }
} }
if (gpio == -1 || !gpio_is_valid(gpio)) /* No LED, bail out */
if (hwnum == -1)
return -ENODEV; return -ENODEV;
/* request and configure LED gpio */ /* Try to obtain this LED GPIO line */
err = gpio_request_one(gpio, radio_led->gpiod = gpiochip_request_own_desc(bcma_gpio, hwnum,
active_low ? GPIOF_OUT_INIT_HIGH "radio on", lflags,
: GPIOF_OUT_INIT_LOW, GPIOD_OUT_LOW);
"radio on");
if (err) { if (IS_ERR(radio_led->gpiod)) {
wiphy_err(wl->wiphy, "requesting led gpio %d failed (err: %d)\n", err = PTR_ERR(radio_led->gpiod);
gpio, err); wiphy_err(wl->wiphy, "requesting led GPIO failed (err: %d)\n",
return err; err);
}
err = gpio_direction_output(gpio, 1);
if (err) {
wiphy_err(wl->wiphy, "cannot set led gpio %d to output (err: %d)\n",
gpio, err);
return err; return err;
} }
...@@ -117,11 +108,8 @@ int brcms_led_register(struct brcms_info *wl) ...@@ -117,11 +108,8 @@ int brcms_led_register(struct brcms_info *wl)
return err; return err;
} }
wiphy_info(wl->wiphy, "registered radio enabled led device: %s gpio: %d\n", wiphy_info(wl->wiphy, "registered radio enabled led device: %s\n",
wl->radio_led.name, wl->radio_led.name);
gpio);
radio_led->gpio = gpio;
radio_led->active_low = active_low;
return 0; return 0;
} }
...@@ -16,10 +16,12 @@ ...@@ -16,10 +16,12 @@
#ifndef _BRCM_LED_H_ #ifndef _BRCM_LED_H_
#define _BRCM_LED_H_ #define _BRCM_LED_H_
struct gpio_desc;
struct brcms_led { struct brcms_led {
char name[32]; char name[32];
unsigned gpio; struct gpio_desc *gpiod;
bool active_low;
}; };
#ifdef CONFIG_BCMA_DRIVER_GPIO #ifdef CONFIG_BCMA_DRIVER_GPIO
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment