1 From: Sebastian Gottschall <s.gottschall@newmedia-net.de>
3 Adds LED and GPIO Control support for 988x, 9887, 9888, 99x0, 9984 based
4 chipsets with on chipset connected led's using WMI Firmware API. The LED
5 device will get available named as "ath10k-phyX" at sysfs and can be controlled
6 with various triggers. adds also debugfs interface for gpio control.
8 This patch is specific for OpenWRt base, as is use old backported package
9 with old wireless source. Support for QCA9984 is removed.
10 Reworked to use ath10k-ct custom source
13 Signed-off-by: Sebastian Gottschall <s.gottschall@dd-wrt.com>
14 Reviewed-by: Steve deRosier <derosier@cal-sierra.com>
15 [kvalo: major reorg and cleanup]
16 Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
17 Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
22 * only compile tested!
24 * fix all checkpatch warnings
28 * sizeof(struct ath10k_gpiocontrol) -> sizeof(*gpio)
30 * unsigned -> unsigned int
32 * remove GPIOLIB code, that should be added in a separate patch
34 * rename gpio.c to leds.c
38 * rename some functions:
40 ath10k_attach_led() -> ath10k_leds_register()
41 ath10k_unregister_led() -> ath10k_leds_unregister()
42 ath10k_reset_led_pin() -> ath10k_leds_start()
44 * call ath10k_leds_unregister() before ath10k_thermal_unregister() to preserve ordering
46 * call ath10k_leds_start() only from ath10k_core_start() and not from mac.c
48 * rename struct ath10k_gpiocontrol as anonymous function under struct
49 ath10k::leds, no need for memory allocation
51 * merge ath10k_add_led() to ath10k_attach_led(), which is it's only caller
53 * remove #if IS_ENABLED() checks from most of places, memory savings from those were not worth it
55 * Kconfig help text improvement and move it lower in the menu, also don't enable it by default
57 * switch to set_brightness_blocking() so that the callback can sleep,
58 then no need to use ath10k_wmi_cmd_send_nowait() and can take mutex
61 * don't touch ath10k_wmi_pdev_get_temperature()
63 * as QCA6174/QCA9377 are not (yet) supported don't add the command to WMI-TLV interface
65 * remove debugfs interface, that should be added in another patch
69 ath10k-6.2/Kconfig | 10 +++
70 ath10k-6.2/Makefile | 1 +
71 ath10k-6.2/core.c | 22 +++++++
72 ath10k-6.2/core.h | 9 ++-
74 ath10k-6.2/leds.c | 103 ++++++++++++++++++++++++++++++
75 ath10k-6.2/leds.h | 45 +++++++++++++
76 ath10k-6.2/mac.c | 1 +
77 ath10k-6.2/wmi-ops.h | 32 ++++++++++
78 ath10k-6.2/wmi-tlv.c | 2 +
79 ath10k-6.2/wmi.c | 54 ++++++++++++++++
80 ath10k-6.2/wmi.h | 35 ++++++++++
81 12 files changed, 314 insertions(+), 1 deletion(-)
82 create mode 100644 ath10k-6.2/leds.c
83 create mode 100644 ath10k-6.2/leds.h
85 --- a/ath10k-6.2/Kconfig
86 +++ b/ath10k-6.2/Kconfig
87 @@ -67,6 +67,16 @@ config ATH10K_DEBUGFS
89 If unsure, say Y to make it easier to debug problems.
92 + bool "Atheros ath10k LED support"
94 + select MAC80211_LEDS
99 + This option is necessary, if you want LED support for chipset connected led pins. If unsure, say N.
101 config ATH10K_SPECTRAL
102 bool "Atheros ath10k spectral scan support"
103 depends on ATH10K_DEBUGFS
104 --- a/ath10k-6.2/Makefile
105 +++ b/ath10k-6.2/Makefile
106 @@ -20,6 +20,7 @@ ath10k_core-$(CONFIG_ATH10K_SPECTRAL) +=
107 ath10k_core-$(CONFIG_NL80211_TESTMODE) += testmode.o
108 ath10k_core-$(CONFIG_ATH10K_TRACING) += trace.o
109 ath10k_core-$(CONFIG_THERMAL) += thermal.o
110 +ath10k_core-$(CONFIG_ATH10K_LEDS) += leds.o
111 ath10k_core-$(CONFIG_MAC80211_DEBUGFS) += debugfs_sta.o
112 ath10k_core-$(CONFIG_PM) += wow.o
113 ath10k_core-$(CONFIG_ATH10K_CE) += ce.o
114 --- a/ath10k-6.2/core.c
115 +++ b/ath10k-6.2/core.c
117 #include "testmode.h"
119 #include "coredump.h"
122 /* Disable ath10k-ct DBGLOG output by default */
123 unsigned int ath10k_debug_mask = ATH10K_DBG_NO_DBGLOG;
124 @@ -78,6 +79,7 @@ static const struct ath10k_hw_params ath
125 .dev_id = QCA988X_2_0_DEVICE_ID,
126 .bus = ATH10K_BUS_PCI,
127 .name = "qca988x hw2.0",
129 .patch_load_addr = QCA988X_HW_2_0_PATCH_LOAD_ADDR,
131 .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_ALL,
132 @@ -159,6 +161,7 @@ static const struct ath10k_hw_params ath
133 .dev_id = QCA9887_1_0_DEVICE_ID,
134 .bus = ATH10K_BUS_PCI,
135 .name = "qca9887 hw1.0",
137 .patch_load_addr = QCA9887_HW_1_0_PATCH_LOAD_ADDR,
139 .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_ALL,
140 @@ -400,6 +403,7 @@ static const struct ath10k_hw_params ath
141 .dev_id = QCA99X0_2_0_DEVICE_ID,
142 .bus = ATH10K_BUS_PCI,
143 .name = "qca99x0 hw2.0",
145 .patch_load_addr = QCA99X0_HW_2_0_PATCH_LOAD_ADDR,
147 .otp_exe_param = 0x00000700,
148 @@ -446,6 +450,7 @@ static const struct ath10k_hw_params ath
149 .dev_id = QCA9984_1_0_DEVICE_ID,
150 .bus = ATH10K_BUS_PCI,
151 .name = "qca9984/qca9994 hw1.0",
153 .patch_load_addr = QCA9984_HW_1_0_PATCH_LOAD_ADDR,
155 .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_EACH,
156 @@ -499,6 +504,7 @@ static const struct ath10k_hw_params ath
157 .dev_id = QCA9888_2_0_DEVICE_ID,
158 .bus = ATH10K_BUS_PCI,
159 .name = "qca9888 hw2.0",
161 .patch_load_addr = QCA9888_HW_2_0_PATCH_LOAD_ADDR,
163 .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_EACH,
164 @@ -4080,6 +4086,10 @@ int ath10k_core_start(struct ath10k *ar,
165 ath10k_wmi_check_apply_board_power_ctl_table(ar);
168 + status = ath10k_leds_start(ar);
175 @@ -4341,9 +4351,18 @@ static void ath10k_core_register_work(st
176 goto err_spectral_destroy;
179 + status = ath10k_leds_register(ar);
181 + ath10k_err(ar, "could not register leds: %d\n",
183 + goto err_thermal_unregister;
186 set_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags);
189 +err_thermal_unregister:
190 + ath10k_thermal_unregister(ar);
191 err_spectral_destroy:
192 ath10k_spectral_destroy(ar);
194 @@ -4403,6 +4422,8 @@ void ath10k_core_unregister(struct ath10
195 if (!test_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags))
198 + ath10k_leds_unregister(ar);
200 ath10k_thermal_unregister(ar);
201 /* Stop spectral before unregistering from mac80211 to remove the
202 * relayfs debugfs file cleanly. Otherwise the parent debugfs tree
203 --- a/ath10k-6.2/core.h
204 +++ b/ath10k-6.2/core.h
206 #include <linux/pci.h>
207 #include <linux/uuid.h>
208 #include <linux/time.h>
209 +#include <linux/leds.h>
213 @@ -1586,6 +1587,13 @@ struct ath10k {
217 + struct gpio_led wifi_led;
218 + struct led_classdev cdev;
220 + u32 gpio_state_pin;
224 /* protected by data_lock */
226 u32 fw_crash_counter;
227 --- a/ath10k-6.2/hw.h
228 +++ b/ath10k-6.2/hw.h
229 @@ -523,6 +523,7 @@ struct ath10k_hw_params {
236 /* Type of hw cycle counter wraparound logic, for more info
238 +++ b/ath10k-6.2/leds.c
241 + * Copyright (c) 2005-2011 Atheros Communications Inc.
242 + * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
243 + * Copyright (c) 2018 Sebastian Gottschall <s.gottschall@dd-wrt.com>
244 + * Copyright (c) 2018, The Linux Foundation. All rights reserved.
246 + * Permission to use, copy, modify, and/or distribute this software for any
247 + * purpose with or without fee is hereby granted, provided that the above
248 + * copyright notice and this permission notice appear in all copies.
250 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
251 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
252 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
253 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
254 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
255 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
256 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
259 +#include <linux/leds.h>
263 +#include "wmi-ops.h"
267 +static int ath10k_leds_set_brightness_blocking(struct led_classdev *led_cdev,
268 + enum led_brightness brightness)
270 + struct ath10k *ar = container_of(led_cdev, struct ath10k,
272 + struct gpio_led *led = &ar->leds.wifi_led;
274 + mutex_lock(&ar->conf_mutex);
276 + if (ar->state != ATH10K_STATE_ON)
279 + ar->leds.gpio_state_pin = (brightness != LED_OFF) ^ led->active_low;
280 + ath10k_wmi_gpio_output(ar, led->gpio, ar->leds.gpio_state_pin);
283 + mutex_unlock(&ar->conf_mutex);
288 +int ath10k_leds_start(struct ath10k *ar)
290 + if (ar->hw_params.led_pin == 0)
291 + /* leds not supported */
294 + /* under some circumstances, the gpio pin gets reconfigured
295 + * to default state by the firmware, so we need to
296 + * reconfigure it this behaviour has only ben seen on
297 + * QCA9984 and QCA99XX devices so far
299 + ath10k_wmi_gpio_config(ar, ar->hw_params.led_pin, 0,
300 + WMI_GPIO_PULL_NONE, WMI_GPIO_INTTYPE_DISABLE);
301 + ath10k_wmi_gpio_output(ar, ar->hw_params.led_pin, 1);
306 +int ath10k_leds_register(struct ath10k *ar)
310 + if (ar->hw_params.led_pin == 0)
311 + /* leds not supported */
314 + snprintf(ar->leds.label, sizeof(ar->leds.label), "ath10k-%s",
315 + wiphy_name(ar->hw->wiphy));
316 + ar->leds.wifi_led.active_low = 1;
317 + ar->leds.wifi_led.gpio = ar->hw_params.led_pin;
318 + ar->leds.wifi_led.name = ar->leds.label;
319 + ar->leds.wifi_led.default_state = LEDS_GPIO_DEFSTATE_KEEP;
321 + ar->leds.cdev.name = ar->leds.label;
322 + ar->leds.cdev.brightness_set_blocking = ath10k_leds_set_brightness_blocking;
324 + /* FIXME: this assignment doesn't make sense as it's NULL, remove it? */
325 + ar->leds.cdev.default_trigger = ar->leds.wifi_led.default_trigger;
327 + ret = led_classdev_register(wiphy_dev(ar->hw->wiphy), &ar->leds.cdev);
334 +void ath10k_leds_unregister(struct ath10k *ar)
336 + if (ar->hw_params.led_pin == 0)
337 + /* leds not supported */
340 + led_classdev_unregister(&ar->leds.cdev);
344 +++ b/ath10k-6.2/leds.h
347 + * Copyright (c) 2018, The Linux Foundation. All rights reserved.
349 + * Permission to use, copy, modify, and/or distribute this software for any
350 + * purpose with or without fee is hereby granted, provided that the above
351 + * copyright notice and this permission notice appear in all copies.
353 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
354 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
355 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
356 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
357 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
358 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
359 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
366 +#ifdef CONFIG_ATH10K_LEDS
367 +void ath10k_leds_unregister(struct ath10k *ar);
368 +int ath10k_leds_start(struct ath10k *ar);
369 +int ath10k_leds_register(struct ath10k *ar);
371 +static inline void ath10k_leds_unregister(struct ath10k *ar)
375 +static inline int ath10k_leds_start(struct ath10k *ar)
380 +static inline int ath10k_leds_register(struct ath10k *ar)
386 +#endif /* _LEDS_H_ */
387 --- a/ath10k-6.2/mac.c
388 +++ b/ath10k-6.2/mac.c
397 --- a/ath10k-6.2/wmi-ops.h
398 +++ b/ath10k-6.2/wmi-ops.h
399 @@ -228,7 +228,10 @@ struct wmi_ops {
400 const struct wmi_bb_timing_cfg_arg *arg);
401 struct sk_buff *(*gen_per_peer_per_tid_cfg)(struct ath10k *ar,
402 const struct wmi_per_peer_per_tid_cfg_arg *arg);
403 + struct sk_buff *(*gen_gpio_config)(struct ath10k *ar, u32 gpio_num,
404 + u32 input, u32 pull_type, u32 intr_mode);
406 + struct sk_buff *(*gen_gpio_output)(struct ath10k *ar, u32 gpio_num, u32 set);
409 int ath10k_wmi_cmd_send(struct ath10k *ar, struct sk_buff *skb, u32 cmd_id);
410 @@ -1147,6 +1150,35 @@ ath10k_wmi_force_fw_hang(struct ath10k *
411 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->force_fw_hang_cmdid);
414 +static inline int ath10k_wmi_gpio_config(struct ath10k *ar, u32 gpio_num,
415 + u32 input, u32 pull_type, u32 intr_mode)
417 + struct sk_buff *skb;
419 + if (!ar->wmi.ops->gen_gpio_config)
420 + return -EOPNOTSUPP;
422 + skb = ar->wmi.ops->gen_gpio_config(ar, gpio_num, input, pull_type, intr_mode);
424 + return PTR_ERR(skb);
426 + return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->gpio_config_cmdid);
429 +static inline int ath10k_wmi_gpio_output(struct ath10k *ar, u32 gpio_num, u32 set)
431 + struct sk_buff *skb;
433 + if (!ar->wmi.ops->gen_gpio_config)
434 + return -EOPNOTSUPP;
436 + skb = ar->wmi.ops->gen_gpio_output(ar, gpio_num, set);
438 + return PTR_ERR(skb);
440 + return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->gpio_output_cmdid);
444 ath10k_wmi_dbglog_cfg(struct ath10k *ar, u64 module_enable, u32 log_level)
446 --- a/ath10k-6.2/wmi-tlv.c
447 +++ b/ath10k-6.2/wmi-tlv.c
448 @@ -4601,6 +4601,8 @@ static const struct wmi_ops wmi_tlv_ops
449 .gen_echo = ath10k_wmi_tlv_op_gen_echo,
450 .gen_vdev_spectral_conf = ath10k_wmi_tlv_op_gen_vdev_spectral_conf,
451 .gen_vdev_spectral_enable = ath10k_wmi_tlv_op_gen_vdev_spectral_enable,
452 + /* .gen_gpio_config not implemented */
453 + /* .gen_gpio_output not implemented */
456 static const struct wmi_peer_flags_map wmi_tlv_peer_flags_map = {
457 --- a/ath10k-6.2/wmi.c
458 +++ b/ath10k-6.2/wmi.c
459 @@ -8438,6 +8438,49 @@ ath10k_wmi_op_gen_peer_set_param(struct
463 +static struct sk_buff *ath10k_wmi_op_gen_gpio_config(struct ath10k *ar,
464 + u32 gpio_num, u32 input,
465 + u32 pull_type, u32 intr_mode)
467 + struct wmi_gpio_config_cmd *cmd;
468 + struct sk_buff *skb;
470 + skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
472 + return ERR_PTR(-ENOMEM);
474 + cmd = (struct wmi_gpio_config_cmd *)skb->data;
475 + cmd->pull_type = __cpu_to_le32(pull_type);
476 + cmd->gpio_num = __cpu_to_le32(gpio_num);
477 + cmd->input = __cpu_to_le32(input);
478 + cmd->intr_mode = __cpu_to_le32(intr_mode);
480 + ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi gpio_config gpio_num 0x%08x input 0x%08x pull_type 0x%08x intr_mode 0x%08x\n",
481 + gpio_num, input, pull_type, intr_mode);
486 +static struct sk_buff *ath10k_wmi_op_gen_gpio_output(struct ath10k *ar,
487 + u32 gpio_num, u32 set)
489 + struct wmi_gpio_output_cmd *cmd;
490 + struct sk_buff *skb;
492 + skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
494 + return ERR_PTR(-ENOMEM);
496 + cmd = (struct wmi_gpio_output_cmd *)skb->data;
497 + cmd->gpio_num = __cpu_to_le32(gpio_num);
498 + cmd->set = __cpu_to_le32(set);
500 + ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi gpio_output gpio_num 0x%08x set 0x%08x\n",
506 static struct sk_buff *
507 ath10k_wmi_op_gen_set_psmode(struct ath10k *ar, u32 vdev_id,
508 enum wmi_sta_ps_mode psmode)
509 @@ -10269,6 +10312,9 @@ static const struct wmi_ops wmi_ops = {
510 .fw_stats_fill = ath10k_wmi_main_op_fw_stats_fill,
511 .get_vdev_subtype = ath10k_wmi_op_get_vdev_subtype,
512 .gen_echo = ath10k_wmi_op_gen_echo,
513 + .gen_gpio_config = ath10k_wmi_op_gen_gpio_config,
514 + .gen_gpio_output = ath10k_wmi_op_gen_gpio_output,
516 /* .gen_bcn_tmpl not implemented */
517 /* .gen_prb_tmpl not implemented */
518 /* .gen_p2p_go_bcn_ie not implemented */
519 @@ -10339,6 +10385,8 @@ static const struct wmi_ops wmi_10_1_ops
520 .fw_stats_fill = ath10k_wmi_10x_op_fw_stats_fill,
521 .get_vdev_subtype = ath10k_wmi_op_get_vdev_subtype,
522 .gen_echo = ath10k_wmi_op_gen_echo,
523 + .gen_gpio_config = ath10k_wmi_op_gen_gpio_config,
524 + .gen_gpio_output = ath10k_wmi_op_gen_gpio_output,
525 /* .gen_bcn_tmpl not implemented */
526 /* .gen_prb_tmpl not implemented */
527 /* .gen_p2p_go_bcn_ie not implemented */
528 @@ -10418,6 +10466,8 @@ static const struct wmi_ops wmi_10_2_ops
529 .gen_delba_send = ath10k_wmi_op_gen_delba_send,
530 .fw_stats_fill = ath10k_wmi_10x_op_fw_stats_fill,
531 .get_vdev_subtype = ath10k_wmi_op_get_vdev_subtype,
532 + .gen_gpio_config = ath10k_wmi_op_gen_gpio_config,
533 + .gen_gpio_output = ath10k_wmi_op_gen_gpio_output,
534 /* .gen_pdev_enable_adaptive_cca not implemented */
537 @@ -10489,6 +10539,8 @@ static const struct wmi_ops wmi_10_2_4_o
538 ath10k_wmi_op_gen_pdev_enable_adaptive_cca,
539 .get_vdev_subtype = ath10k_wmi_10_2_4_op_get_vdev_subtype,
540 .gen_bb_timing = ath10k_wmi_10_2_4_op_gen_bb_timing,
541 + .gen_gpio_config = ath10k_wmi_op_gen_gpio_config,
542 + .gen_gpio_output = ath10k_wmi_op_gen_gpio_output,
543 /* .gen_bcn_tmpl not implemented */
544 /* .gen_prb_tmpl not implemented */
545 /* .gen_p2p_go_bcn_ie not implemented */
546 @@ -10571,6 +10623,8 @@ static const struct wmi_ops wmi_10_4_ops
547 .gen_pdev_bss_chan_info_req = ath10k_wmi_10_2_op_gen_pdev_bss_chan_info,
548 .gen_echo = ath10k_wmi_op_gen_echo,
549 .gen_pdev_get_tpc_config = ath10k_wmi_10_2_4_op_gen_pdev_get_tpc_config,
550 + .gen_gpio_config = ath10k_wmi_op_gen_gpio_config,
551 + .gen_gpio_output = ath10k_wmi_op_gen_gpio_output,
554 int ath10k_wmi_attach(struct ath10k *ar)
555 --- a/ath10k-6.2/wmi.h
556 +++ b/ath10k-6.2/wmi.h
557 @@ -3133,6 +3133,41 @@ enum wmi_10_4_feature_mask {
561 +/* WMI_GPIO_CONFIG_CMDID */
563 + WMI_GPIO_PULL_NONE,
565 + WMI_GPIO_PULL_DOWN,
569 + WMI_GPIO_INTTYPE_DISABLE,
570 + WMI_GPIO_INTTYPE_RISING_EDGE,
571 + WMI_GPIO_INTTYPE_FALLING_EDGE,
572 + WMI_GPIO_INTTYPE_BOTH_EDGE,
573 + WMI_GPIO_INTTYPE_LEVEL_LOW,
574 + WMI_GPIO_INTTYPE_LEVEL_HIGH
577 +/* WMI_GPIO_CONFIG_CMDID */
578 +struct wmi_gpio_config_cmd {
579 + __le32 gpio_num; /* GPIO number to be setup */
580 + __le32 input; /* 0 - Output/ 1 - Input */
581 + __le32 pull_type; /* Pull type defined above */
582 + __le32 intr_mode; /* Interrupt mode defined above (Input) */
585 +/* WMI_GPIO_OUTPUT_CMDID */
586 +struct wmi_gpio_output_cmd {
587 + __le32 gpio_num; /* GPIO number to be setup */
588 + __le32 set; /* Set the GPIO pin*/
591 +/* WMI_GPIO_INPUT_EVENTID */
592 +struct wmi_gpio_input_event {
593 + __le32 gpio_num; /* GPIO number which changed state */
596 struct wmi_ext_resource_config_10_4_cmd {
597 /* contains enum wmi_host_platform_type */
598 __le32 host_platform_config;