Skip to contentSkip to conversation

v4 ath10k: add LED and GPIO controlling support for various chipsets

PATCH New [email protected] 2 participants 2 messages Feb 16, 2018 – Feb 19, 2018 Qualcomm Atheros ATH10K wireless driver

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 v4 ath10k: add LED and GPIO controlling support for various chipsets

From: Sebastian Gottschall <[email protected]>

Adds LED and GPIO Control support for 988x, 9887, 9888, 99x0, 9984 and ipq4019 based chipsets with on chipset connected led's using WMI Firmware API.
The LED device will get available named as "ath10k-phyX" at sysfs and can be controlled with various triggers. adds also debugfs interface for gpio control.

---
 drivers/net/wireless/ath/ath10k/core.c    | 181 +++++++++++++++++++++++++++++-
 drivers/net/wireless/ath/ath10k/core.h    |  20 +++-
 drivers/net/wireless/ath/ath10k/debug.c   | 146 ++++++++++++++++++++++++
 drivers/net/wireless/ath/ath10k/hw.h      |   2 +
 drivers/net/wireless/ath/ath10k/mac.c     |   6 +
 drivers/net/wireless/ath/ath10k/wmi-ops.h |  36 +++++-
 drivers/net/wireless/ath/ath10k/wmi-tlv.c |  65 +++++++++++
 drivers/net/wireless/ath/ath10k/wmi.c     |  46 ++++++++
 drivers/net/wireless/ath/ath10k/wmi.h     |  36 ++++++
 9 files changed, 534 insertions(+), 4 deletions(-)
drivers/net/wireless/ath/ath10k/core.c +179 -2
index f3ec13b80b20..4a0453c0e02b 100644
@@ -21,6 +21,10 @@
 #include <linux/dmi.h>
 #include <linux/ctype.h>
 #include <asm/byteorder.h>
+#include <linux/leds.h>
+#include <linux/platform_device.h>
+
+#ifdef CONFIG_GPIOLIB
 
 #include "core.h"
 #include "mac.h"
@@ -65,6 +69,8 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
 		.id = QCA988X_HW_2_0_VERSION,
 		.dev_id = QCA988X_2_0_DEVICE_ID,
 		.name = "qca988x hw2.0",
+		.led_pin = 1,
+		.gpio_count = 24, 
 		.patch_load_addr = QCA988X_HW_2_0_PATCH_LOAD_ADDR,
 		.uart_pin = 7,
 		.cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_ALL,
@@ -94,6 +100,8 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
 		.id = QCA988X_HW_2_0_VERSION,
 		.dev_id = QCA988X_2_0_DEVICE_ID_UBNT,
 		.name = "qca988x hw2.0 ubiquiti",
+		.led_pin = 1,
+		.gpio_count = 24, 
 		.patch_load_addr = QCA988X_HW_2_0_PATCH_LOAD_ADDR,
 		.uart_pin = 7,
 		.cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_ALL,
@@ -123,6 +131,8 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
 		.id = QCA9887_HW_1_0_VERSION,
 		.dev_id = QCA9887_1_0_DEVICE_ID,
 		.name = "qca9887 hw1.0",
+		.led_pin = 1,
+		.gpio_count = 24, 
 		.patch_load_addr = QCA9887_HW_1_0_PATCH_LOAD_ADDR,
 		.uart_pin = 7,
 		.cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_ALL,
@@ -267,6 +277,8 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
 		.id = QCA99X0_HW_2_0_DEV_VERSION,
 		.dev_id = QCA99X0_2_0_DEVICE_ID,
 		.name = "qca99x0 hw2.0",
+		.led_pin = 17,
+		.gpio_count = 35, 
 		.patch_load_addr = QCA99X0_HW_2_0_PATCH_LOAD_ADDR,
 		.uart_pin = 7,
 		.otp_exe_param = 0x00000700,
@@ -301,6 +313,8 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
 		.id = QCA9984_HW_1_0_DEV_VERSION,
 		.dev_id = QCA9984_1_0_DEVICE_ID,
 		.name = "qca9984/qca9994 hw1.0",
+		.led_pin = 17,
+		.gpio_count = 35, 
 		.patch_load_addr = QCA9984_HW_1_0_PATCH_LOAD_ADDR,
 		.uart_pin = 7,
 		.cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_EACH,
@@ -340,6 +354,8 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
 		.id = QCA9888_HW_2_0_DEV_VERSION,
 		.dev_id = QCA9888_2_0_DEVICE_ID,
 		.name = "qca9888 hw2.0",
+		.led_pin = 17,
+		.gpio_count = 35, 
 		.patch_load_addr = QCA9888_HW_2_0_PATCH_LOAD_ADDR,
 		.uart_pin = 7,
 		.cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_EACH,
@@ -2132,12 +2148,146 @@ static int ath10k_core_reset_rx_filter(struct ath10k *ar)
 	return 0;
 }
 
+static int ath10k_gpio_pin_cfg_input(struct gpio_chip *chip, unsigned offset)
+{
+	struct ath10k_gpiocontrol *gpio = container_of(chip, struct ath10k_gpiocontrol, gchip);
+	ath10k_wmi_gpio_config(gpio->ar, offset, 1, WMI_GPIO_PULL_NONE, WMI_GPIO_INTTYPE_DISABLE); // configure to input
+	gpio->gpio_state_dir = 1;
+	return 0;
+}
+
+/* gpio_chip handler : set GPIO to output */
+static int ath10k_gpio_pin_cfg_output(struct gpio_chip *chip, unsigned offset,
+				     int value)
+{
+	struct ath10k_gpiocontrol *gpio = container_of(chip, struct ath10k_gpiocontrol, gchip);
+
+	ath10k_wmi_gpio_config(gpio->ar, offset, 0, WMI_GPIO_PULL_NONE, WMI_GPIO_INTTYPE_DISABLE); // configure to output
+	ath10k_wmi_gpio_output(gpio->ar, offset, value);
+	gpio->gpio_state_dir = 0;
+	gpio->gpio_state_pin = value;
+	return 0;
+}
+
+/* gpio_chip handler : query GPIO direction (0=out, 1=in) */
+static int ath10k_gpio_pin_get_dir(struct gpio_chip *chip, unsigned offset)
+{
+	struct ath10k_gpiocontrol *gpio = container_of(chip, struct ath10k_gpiocontrol, gchip);
+
+	return gpio->gpio_state_dir;
+}
+
+/* gpio_chip handler : get GPIO pin value */
+static int ath10k_gpio_pin_get(struct gpio_chip *chip, unsigned offset)
+{
+	struct ath10k_gpiocontrol *gpio = container_of(chip, struct ath10k_gpiocontrol, gchip);
+
+	return gpio->gpio_state_pin;
+}
+
+/* gpio_chip handler : set GPIO pin to value */
+static void ath10k_gpio_pin_set(struct gpio_chip *chip, unsigned offset,
+			       int value)
+{
+	struct ath10k_gpiocontrol *gpio = container_of(chip, struct ath10k_gpiocontrol, gchip);
+
+	ath10k_wmi_gpio_output(gpio->ar, offset, value);
+	gpio->gpio_state_pin = value;
+}
+
+/* register GPIO chip */
+static int ath10k_register_gpio_chip(struct ath10k *ar)
+{
+	struct ath10k_gpiocontrol *gpio;
+	gpio = kzalloc(sizeof(struct ath10k_gpiocontrol), GFP_KERNEL);
+	if (!gpio) {
+		return -1;
+	}
+ 
+	snprintf(gpio->label, sizeof(gpio->label), "ath10k-%s",
+		 wiphy_name(ar->hw->wiphy));
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,5,0)
+	gpio->gchip.parent = ar->dev;
+#else
+	gpio->gchip.dev = ar->dev;
+#endif
+	gpio->gchip.base = -1;	/* determine base automatically */
+	gpio->gchip.ngpio = ar->hw_params.gpio_count;
+	gpio->gchip.label = gpio->label;
+	gpio->gchip.direction_input = ath10k_gpio_pin_cfg_input;
+	gpio->gchip.direction_output = ath10k_gpio_pin_cfg_output;
+	gpio->gchip.get_direction = ath10k_gpio_pin_get_dir;
+	gpio->gchip.get = ath10k_gpio_pin_get;
+	gpio->gchip.set = ath10k_gpio_pin_set;
+
+	if (gpiochip_add(&gpio->gchip)) {
+		printk(KERN_ERR "Error while registering gpio chip\n");
+		return -1;
+	}
+	gpio->gchip.owner = NULL;
+	ar->gpio = gpio;
+	gpio->ar = ar;
+	return 0;
+}
+
+#ifdef CONFIG_LEDS_CLASS
+static void ath10k_led_brightness(struct led_classdev *led_cdev,
+			       enum led_brightness brightness)
+{
+	struct ath10k_gpiocontrol *gpio = container_of(led_cdev, struct ath10k_gpiocontrol, cdev);
+	struct gpio_led *led = &gpio->wifi_led;
+	if (gpio->ar->state == ATH10K_STATE_ON) {
+		gpio->gpio_state_pin = (brightness != LED_OFF) ^ led->active_low;
+		ath10k_wmi_gpio_output(gpio->ar, led->gpio, gpio->gpio_state_pin);
+	}
+}
+
+static int ath10k_add_led(struct ath10k *ar, struct gpio_led *gpioled)
+{
+	int ret;
+	struct ath10k_gpiocontrol *gpio = ar->gpio; 
+	if (!gpio)
+		return -1;
+	gpio->cdev.name = gpioled->name;
+	gpio->cdev.default_trigger = gpioled->default_trigger;
+	gpio->cdev.brightness_set = ath10k_led_brightness;
+
+	ret = led_classdev_register(wiphy_dev(ar->hw->wiphy), &gpio->cdev);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+#endif
+
+#endif
+
+/* remove GPIO chip */
+static void ath10k_unregister_gpio_chip(struct ath10k *ar)
+{
+#ifdef CONFIG_GPIOLIB
+	struct ath10k_gpiocontrol *gpio = ar->gpio; 
+	if (gpio) {
+		gpiochip_remove(&gpio->gchip);
+		kfree(gpio);
+	}
+#endif
+}
+
+static void ath10k_unregister_led(struct ath10k *ar)
+{
+#ifdef CONFIG_GPIOLIB
+	if (ar->gpio)
+		led_classdev_unregister(&ar->gpio->cdev);
+#endif
+}
+
+
 int ath10k_core_start(struct ath10k *ar, enum ath10k_firmware_mode mode,
 		      const struct ath10k_fw_components *fw)
 {
 	int status;
 	u32 val;
-
 	lockdep_assert_held(&ar->conf_mutex);
 
 	clear_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags);
@@ -2372,8 +2522,32 @@ int ath10k_core_start(struct ath10k *ar, enum ath10k_firmware_mode mode,
 	if (status)
 		goto err_hif_stop;
 
-	return 0;
 
+#ifdef CONFIG_GPIOLIB
+	/* LED Code */
+	if (ar->hw_params.led_pin) { // only configure if non zero
+		if (!ar->gpio_attached) {
+			status = ath10k_register_gpio_chip(ar);
+			if (status) {
+				goto err_no_led;
+			}
+#ifdef CONFIG_LEDS_CLASS
+			ar->gpio_attached = 1;
+			ar->gpio->wifi_led.active_low = 1;
+			ar->gpio->wifi_led.gpio = ar->hw_params.led_pin;
+			ar->gpio->wifi_led.name = ar->gpio->label;
+			ar->gpio->wifi_led.default_state = LEDS_GPIO_DEFSTATE_KEEP;
+		
+			ath10k_add_led(ar, &ar->gpio->wifi_led);
+#endif
+		}
+		ath10k_wmi_gpio_config(ar, ar->hw_params.led_pin, 0, WMI_GPIO_PULL_NONE, WMI_GPIO_INTTYPE_DISABLE); // configure to output
+		ath10k_wmi_gpio_output(ar, ar->hw_params.led_pin, 1);
+	}
+#endif
+err_no_led:;
+	
+	return 0;
 err_hif_stop:
 	ath10k_hif_stop(ar);
 err_htt_rx_detach:
@@ -2673,6 +2847,9 @@ void ath10k_core_unregister(struct ath10k *ar)
 	ath10k_core_free_board_files(ar);
 
 	ath10k_debug_unregister(ar);
+
+	ath10k_unregister_led(ar);
+	ath10k_unregister_gpio_chip(ar);
 }
 EXPORT_SYMBOL(ath10k_core_unregister);
 
drivers/net/wireless/ath/ath10k/core.h +19 -1
index c624b96f8b84..7baa29e87c00 100644
@@ -25,6 +25,8 @@
 #include <linux/pci.h>
 #include <linux/uuid.h>
 #include <linux/time.h>
+#include <linux/gpio.h>
+#include <linux/leds.h>
 
 #include "htt.h"
 #include "htc.h"
@@ -812,6 +814,19 @@ struct ath10k_per_peer_tx_stats {
 	u32	reserved2;
 };
 
+struct ath10k_gpiocontrol {
+	struct ath10k *ar;
+	u32 gpio_set_num, gpio_num, gpio_input, gpio_pull_type, gpio_intr_mode, gpio_set; /* since we have no gpio read method, these are the state variables for debugfs.  */
+	struct gpio_led wifi_led;
+	struct gpio_chip gchip;
+#ifdef CONFIG_LEDS_CLASS
+	struct led_classdev cdev;
+#endif
+	char label[48];
+	u32 gpio_state_dir; /* same as for debugfs, but for gpiochip implementation */
+	u32 gpio_state_pin;
+};
+
 struct ath10k {
 	struct ath_common ath_common;
 	struct ieee80211_hw *hw;
@@ -840,7 +855,10 @@ struct ath10k {
 	u32 low_5ghz_chan;
 	u32 high_5ghz_chan;
 	bool ani_enabled;
-
+#ifdef CONFIG_GPIOLIB
+	struct ath10k_gpiocontrol *gpio;
+	int gpio_attached;
+#endif
 	bool p2p;
 
 	struct {
drivers/net/wireless/ath/ath10k/debug.c +146 -0

164 lines not on this page · raw message

drivers/net/wireless/ath/ath10k/hw.h +2 -0
index 413b1b4321f7..b1b053abc4e9 100644
@@ -495,6 +495,8 @@ struct ath10k_hw_params {
 	const char *name;
 	u32 patch_load_addr;
 	int uart_pin;
+	int led_pin; // 1 for peregrine, 17 for beeliner
+	int gpio_count; // 24 for peregrine, 35 for beeliner
 	u32 otp_exe_param;
 
 	/* Type of hw cycle counter wraparound logic, for more info
drivers/net/wireless/ath/ath10k/mac.c +6 -0
index ebb3f1b046f3..f1932cc9f153 100644
@@ -4601,6 +4601,12 @@ static int ath10k_start(struct ieee80211_hw *hw)
 	switch (ar->state) {
 	case ATH10K_STATE_OFF:
 		ar->state = ATH10K_STATE_ON;
+
+		/* need to reset gpio state */
+		if (ar->hw_params.led_pin) { 
+			ath10k_wmi_gpio_config(ar, ar->hw_params.led_pin, 0, WMI_GPIO_PULL_NONE, WMI_GPIO_INTTYPE_DISABLE);
+			ath10k_wmi_gpio_output(ar, ar->hw_params.led_pin, 1);
+		}
 		break;
 	case ATH10K_STATE_RESTARTING:
 		ar->state = ATH10K_STATE_RESTARTED;
drivers/net/wireless/ath/ath10k/wmi-ops.h +35 -1
index 14093cfdc505..a38d6a8f7ec5 100644
@@ -197,8 +197,13 @@ struct wmi_ops {
 					(struct ath10k *ar,
 					 enum wmi_bss_survey_req_type type);
 	struct sk_buff *(*gen_echo)(struct ath10k *ar, u32 value);
+
+	struct sk_buff *(*gen_gpio_config)(struct ath10k *ar, u32 gpio_num, u32 input, u32 pull_type, u32 intr_mode);
+
+	struct sk_buff *(*gen_gpio_output)(struct ath10k *ar, u32 gpio_num, u32 set);
 };
 
+
 int ath10k_wmi_cmd_send(struct ath10k *ar, struct sk_buff *skb, u32 cmd_id);
 
 static inline int
@@ -957,6 +962,35 @@ ath10k_wmi_force_fw_hang(struct ath10k *ar,
 
 	return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->force_fw_hang_cmdid);
 }
+static inline int 
+ath10k_wmi_gpio_config(struct ath10k *ar, u32 gpio_num, u32 input, u32 pull_type, u32 intr_mode)
+{
+	struct sk_buff *skb;
+
+	if (!ar->wmi.ops->gen_gpio_config)
+		return -EOPNOTSUPP;
+
+	skb = ar->wmi.ops->gen_gpio_config(ar, gpio_num, input, pull_type, intr_mode);
+	if (IS_ERR(skb))
+		return PTR_ERR(skb);
+
+	return ath10k_wmi_cmd_send_nowait(ar, skb, ar->wmi.cmd->gpio_config_cmdid);
+}
+
+static inline int 
+ath10k_wmi_gpio_output(struct ath10k *ar, u32 gpio_num, u32 set)
+{
+	struct sk_buff *skb;
+
+	if (!ar->wmi.ops->gen_gpio_config)
+		return -EOPNOTSUPP;
+
+	skb = ar->wmi.ops->gen_gpio_output(ar, gpio_num, set);
+	if (IS_ERR(skb))
+		return PTR_ERR(skb);
+
+	return ath10k_wmi_cmd_send_nowait(ar, skb, ar->wmi.cmd->gpio_output_cmdid);
+}
 
 static inline int
 ath10k_wmi_dbglog_cfg(struct ath10k *ar, u64 module_enable, u32 log_level)
@@ -1034,7 +1068,7 @@ ath10k_wmi_pdev_get_temperature(struct ath10k *ar)
 	if (IS_ERR(skb))
 		return PTR_ERR(skb);
 
-	return ath10k_wmi_cmd_send(ar, skb,
+	return ath10k_wmi_cmd_send_nowait(ar, skb,
 				   ar->wmi.cmd->pdev_get_temperature_cmdid);
 }
 
drivers/net/wireless/ath/ath10k/wmi-tlv.c +65 -0

77 lines not on this page · raw message

drivers/net/wireless/ath/ath10k/wmi.c +46 -0

82 lines not on this page · raw message

drivers/net/wireless/ath/ath10k/wmi.h +36 -0
index c7b30ed9015d..dc180a86dc3b 100644
@@ -2906,6 +2906,42 @@ enum wmi_10_4_feature_mask {
 
 };
 
+/* WMI_GPIO_CONFIG_CMDID */
+enum {
+    WMI_GPIO_PULL_NONE,
+    WMI_GPIO_PULL_UP,
+    WMI_GPIO_PULL_DOWN,
+};
+
+enum {
+    WMI_GPIO_INTTYPE_DISABLE,
+    WMI_GPIO_INTTYPE_RISING_EDGE,
+    WMI_GPIO_INTTYPE_FALLING_EDGE,
+    WMI_GPIO_INTTYPE_BOTH_EDGE,
+    WMI_GPIO_INTTYPE_LEVEL_LOW,
+    WMI_GPIO_INTTYPE_LEVEL_HIGH
+};
+
+/* WMI_GPIO_CONFIG_CMDID */
+struct wmi_gpio_config_cmd {
+    __le32 gpio_num;             /* GPIO number to be setup */
+    __le32 input;                /* 0 - Output/ 1 - Input */
+    __le32 pull_type;            /* Pull type defined above */
+    __le32 intr_mode;            /* Interrupt mode defined above (Input) */
+} __packed;
+
+/* WMI_GPIO_OUTPUT_CMDID */
+struct wmi_gpio_output_cmd {
+    __le32 gpio_num;    /* GPIO number to be setup */
+    __le32 set;         /* Set the GPIO pin*/
+} __packed;
+
+/* WMI_GPIO_INPUT_EVENTID */
+struct wmi_gpio_input_event {
+    __le32 gpio_num;    /* GPIO number which changed state */
+} __packed;
+
+
 struct wmi_ext_resource_config_10_4_cmd {
 	/* contains enum wmi_host_platform_type */
 	__le32 host_platform_config;
Signature · 1 line
2.14.1
#1 lore raw
Thank you for the patch! Yet something to improve:

Hi Sebastian,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on v4.16-rc2]
[also build test ERROR on next-20180216]
[cannot apply to ath6kl/ath-next]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/s-gottschall-dd-wrt-com/v4-ath10k-add-LED-and-GPIO-controlling-support-for-various-chipsets/20180219-113151
config: x86_64-allmodconfig (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:

        # save the attached .config to linux build tree
        make ARCH=x86_64 

All errors (new ones prefixed by >>):

drivers/net/wireless/ath/ath10k/core.c:2209:41: sparse: not a function <noident> drivers/net/wireless/ath/ath10k/core.c:2209:24: sparse: bad constant expression type drivers/net/wireless/ath/ath10k/core.c:2212:20: sparse: no member 'dev' in struct gpio_chip drivers/net/wireless/ath/ath10k/core.c:2281:50: sparse: no member 'cdev' in struct ath10k_gpiocontrol drivers/net/wireless/ath/ath10k/core.c: In function 'ath10k_register_gpio_chip':
drivers/net/wireless/ath/ath10k/core.c:2209:5: warning: "LINUX_VERSION_CODE" is not defined, evaluates to 0 [-Wundef]

    #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,5,0)
        ^~~~~~~~~~~~~~~~~~
   drivers/net/wireless/ath/ath10k/core.c:2209:27: warning: "KERNEL_VERSION" is not defined, evaluates to 0 [-Wundef]
    #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,5,0)
                              ^~~~~~~~~~~~~~
   drivers/net/wireless/ath/ath10k/core.c:2209:41: error: missing binary operator before token "("
    #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,5,0)
                                            ^
   drivers/net/wireless/ath/ath10k/core.c:2212:13: error: 'struct gpio_chip' has no member named 'dev'
     gpio->gchip.dev = ar->dev;
                ^
   drivers/net/wireless/ath/ath10k/core.c: In function 'ath10k_unregister_led':
>> drivers/net/wireless/ath/ath10k/core.c:2281:36: error: 'struct ath10k_gpiocontrol' has no member named 'cdev'
      led_classdev_unregister(&ar->gpio->cdev);
                                       ^~

vim +2281 drivers/net/wireless/ath/ath10k/core.c

2197
2198 /* register GPIO chip */
2199 static int ath10k_register_gpio_chip(struct ath10k *ar)
2200 {
2201 struct ath10k_gpiocontrol *gpio;
2202 gpio = kzalloc(sizeof(struct ath10k_gpiocontrol), GFP_KERNEL);
2203 if (!gpio) {
2204 return -1;
2205 }
2206
2207 snprintf(gpio->label, sizeof(gpio->label), "ath10k-%s",
2208 wiphy_name(ar->hw->wiphy));

> 2209	#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,5,0)
  2210		gpio->gchip.parent = ar->dev;
  2211	#else
  2212		gpio->gchip.dev = ar->dev;
  2213	#endif
  2214		gpio->gchip.base = -1;	/* determine base automatically */
  2215		gpio->gchip.ngpio = ar->hw_params.gpio_count;
  2216		gpio->gchip.label = gpio->label;
  2217		gpio->gchip.direction_input = ath10k_gpio_pin_cfg_input;
  2218		gpio->gchip.direction_output = ath10k_gpio_pin_cfg_output;
  2219		gpio->gchip.get_direction = ath10k_gpio_pin_get_dir;
  2220		gpio->gchip.get = ath10k_gpio_pin_get;
  2221		gpio->gchip.set = ath10k_gpio_pin_set;
  2222	
  2223		if (gpiochip_add(&gpio->gchip)) {
  2224			printk(KERN_ERR "Error while registering gpio chip\n");
  2225			return -1;
  2226		}
  2227		gpio->gchip.owner = NULL;
  2228		ar->gpio = gpio;
  2229		gpio->ar = ar;
  2230		return 0;
  2231	}
  2232	
  2233	#ifdef CONFIG_LEDS_CLASS
  2234	static void ath10k_led_brightness(struct led_classdev *led_cdev,
  2235				       enum led_brightness brightness)
  2236	{
  2237		struct ath10k_gpiocontrol *gpio = container_of(led_cdev, struct ath10k_gpiocontrol, cdev);
  2238		struct gpio_led *led = &gpio->wifi_led;
  2239		if (gpio->ar->state == ATH10K_STATE_ON) {
  2240			gpio->gpio_state_pin = (brightness != LED_OFF) ^ led->active_low;
  2241			ath10k_wmi_gpio_output(gpio->ar, led->gpio, gpio->gpio_state_pin);
  2242		}
  2243	}
  2244	
  2245	static int ath10k_add_led(struct ath10k *ar, struct gpio_led *gpioled)
  2246	{
  2247		int ret;
  2248		struct ath10k_gpiocontrol *gpio = ar->gpio; 
  2249		if (!gpio)
  2250			return -1;
  2251		gpio->cdev.name = gpioled->name;
  2252		gpio->cdev.default_trigger = gpioled->default_trigger;
  2253		gpio->cdev.brightness_set = ath10k_led_brightness;
  2254	
  2255		ret = led_classdev_register(wiphy_dev(ar->hw->wiphy), &gpio->cdev);
  2256		if (ret < 0)
  2257			return ret;
  2258	
  2259		return 0;
  2260	}
  2261	#endif
  2262	
  2263	#endif
  2264	
  2265	/* remove GPIO chip */
  2266	static void ath10k_unregister_gpio_chip(struct ath10k *ar)
  2267	{
  2268	#ifdef CONFIG_GPIOLIB
  2269		struct ath10k_gpiocontrol *gpio = ar->gpio; 
  2270		if (gpio) {
  2271			gpiochip_remove(&gpio->gchip);
  2272			kfree(gpio);
  2273		}
  2274	#endif
  2275	}
  2276	
  2277	static void ath10k_unregister_led(struct ath10k *ar)
  2278	{
  2279	#ifdef CONFIG_GPIOLIB
  2280		if (ar->gpio)
> 2281			led_classdev_unregister(&ar->gpio->cdev);

2282 #endif
2283 }
2284

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation