ath10k-ct: Use ath10k-ct version 5.4
[oweals/openwrt.git] / package / kernel / ath10k-ct / patches / 201-ath10k-4.16_add-LED-and-GPIO-controlling-support-for-various-chipsets.patch
1 From: Sebastian Gottschall <s.gottschall@newmedia-net.de>
2
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.
7
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
11
12
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>
18 ---
19
20 v13:
21
22 * only compile tested!
23
24 * fix all checkpatch warnings
25
26 * fix commit log
27
28 * sizeof(struct ath10k_gpiocontrol) -> sizeof(*gpio)
29
30 * unsigned -> unsigned int
31
32 * remove GPIOLIB code, that should be added in a separate patch
33
34 * rename gpio.c to leds.c
35
36 * add leds.h
37
38 * rename some functions:
39
40   ath10k_attach_led() -> ath10k_leds_register()
41   ath10k_unregister_led() -> ath10k_leds_unregister()
42   ath10k_reset_led_pin() -> ath10k_leds_start()
43
44 * call ath10k_leds_unregister() before ath10k_thermal_unregister() to preserve ordering
45
46 * call ath10k_leds_start() only from ath10k_core_start() and not from mac.c
47
48 * rename struct ath10k_gpiocontrol as anonymous function under struct
49   ath10k::leds, no need for memory allocation
50
51 * merge ath10k_add_led() to ath10k_attach_led(), which is it's only caller
52
53 * remove #if IS_ENABLED() checks from most of places, memory savings from those were not worth it
54
55 * Kconfig help text improvement and move it lower in the menu, also don't enable it by default
56
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
59   to access ar->state
60
61 * don't touch ath10k_wmi_pdev_get_temperature()
62
63 * as QCA6174/QCA9377 are not (yet) supported don't add the command to WMI-TLV interface
64
65 * remove debugfs interface, that should be added in another patch
66
67 * cleanup includes
68
69
70  ath10k-4.16/Kconfig   |  10 +++
71  ath10k-4.16/Makefile  |   1 +
72  ath10k-4.16/core.c    |  22 +++++++
73  ath10k-4.16/core.h    |   9 ++-
74  ath10k-4.16/hw.h      |   1 +
75  ath10k-4.16/leds.c    | 103 ++++++++++++++++++++++++++++++
76  ath10k-4.16/leds.h    |  45 +++++++++++++
77  ath10k-4.16/mac.c     |   1 +
78  ath10k-4.16/wmi-ops.h |  32 ++++++++++
79  ath10k-4.16/wmi-tlv.c |   2 +
80  ath10k-4.16/wmi.c     |  54 ++++++++++++++++
81  ath10k-4.16/wmi.h     |  35 ++++++++++
82  12 files changed, 314 insertions(+), 1 deletion(-)
83  create mode 100644 ath10k-4.16/leds.c
84  create mode 100644 ath10k-4.16/leds.h
85 --- a/ath10k-4.19/Kconfig
86 +++ b/ath10k-4.19/Kconfig
87 @@ -64,6 +64,16 @@ config ATH10K_DEBUGFS
88  
89           If unsure, say Y to make it easier to debug problems.
90  
91 +config ATH10K_LEDS
92 +       bool "Atheros ath10k LED support"
93 +       depends on ATH10K
94 +       select MAC80211_LEDS
95 +       select LEDS_CLASS
96 +       select NEW_LEDS
97 +       default y
98 +       ---help---
99 +         This option is necessary, if you want LED support for chipset connected led pins. If unsure, say N.
100 +
101  config ATH10K_SPECTRAL
102         bool "Atheros ath10k spectral scan support"
103         depends on ATH10K_DEBUGFS
104 --- a/ath10k-4.19/Makefile
105 +++ b/ath10k-4.19/Makefile
106 @@ -19,6 +19,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_DEV_COREDUMP) += coredump.o
114 --- a/ath10k-4.19/core.c
115 +++ b/ath10k-4.19/core.c
116 @@ -35,6 +35,7 @@
117  #include "testmode.h"
118  #include "wmi-ops.h"
119  #include "coredump.h"
120 +#include "leds.h"
121  
122  /* Disable ath10k-ct DBGLOG output by default */
123  unsigned int ath10k_debug_mask = ATH10K_DBG_NO_DBGLOG;
124 @@ -72,6 +73,7 @@ static const struct ath10k_hw_params ath
125                 .id = QCA988X_HW_2_0_VERSION,
126                 .dev_id = QCA988X_2_0_DEVICE_ID,
127                 .name = "qca988x hw2.0",
128 +               .led_pin = 1,
129                 .patch_load_addr = QCA988X_HW_2_0_PATCH_LOAD_ADDR,
130                 .uart_pin = 7,
131                 .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_ALL,
132 @@ -137,6 +139,7 @@ static const struct ath10k_hw_params ath
133                 .id = QCA9887_HW_1_0_VERSION,
134                 .dev_id = QCA9887_1_0_DEVICE_ID,
135                 .name = "qca9887 hw1.0",
136 +               .led_pin = 1,
137                 .patch_load_addr = QCA9887_HW_1_0_PATCH_LOAD_ADDR,
138                 .uart_pin = 7,
139                 .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_ALL,
140 @@ -301,6 +304,7 @@ static const struct ath10k_hw_params ath
141                 .id = QCA99X0_HW_2_0_DEV_VERSION,
142                 .dev_id = QCA99X0_2_0_DEVICE_ID,
143                 .name = "qca99x0 hw2.0",
144 +               .led_pin = 17,
145                 .patch_load_addr = QCA99X0_HW_2_0_PATCH_LOAD_ADDR,
146                 .uart_pin = 7,
147                 .otp_exe_param = 0x00000700,
148 @@ -339,6 +343,7 @@ static const struct ath10k_hw_params ath
149                 .id = QCA9984_HW_1_0_DEV_VERSION,
150                 .dev_id = QCA9984_1_0_DEVICE_ID,
151                 .name = "qca9984/qca9994 hw1.0",
152 +               .led_pin = 17,
153                 .patch_load_addr = QCA9984_HW_1_0_PATCH_LOAD_ADDR,
154                 .uart_pin = 7,
155                 .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_EACH,
156 @@ -382,6 +387,7 @@ static const struct ath10k_hw_params ath
157                 .id = QCA9888_HW_2_0_DEV_VERSION,
158                 .dev_id = QCA9888_2_0_DEVICE_ID,
159                 .name = "qca9888 hw2.0",
160 +               .led_pin = 17,
161                 .patch_load_addr = QCA9888_HW_2_0_PATCH_LOAD_ADDR,
162                 .uart_pin = 7,
163                 .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_EACH,
164 @@ -3176,6 +3182,10 @@ int ath10k_core_start(struct ath10k *ar,
165                         ath10k_wmi_check_apply_board_power_ctl_table(ar);
166         }
167  
168 +       status = ath10k_leds_start(ar);
169 +       if (status)
170 +               goto err_hif_stop;
171 +
172         return 0;
173  
174  err_hif_stop:
175 @@ -3430,9 +3440,18 @@ static void ath10k_core_register_work(st
176                 goto err_spectral_destroy;
177         }
178  
179 +       status = ath10k_leds_register(ar);
180 +       if (status) {
181 +               ath10k_err(ar, "could not register leds: %d\n",
182 +                          status);
183 +               goto err_thermal_unregister;
184 +       }
185 +
186         set_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags);
187         return;
188  
189 +err_thermal_unregister:
190 +       ath10k_thermal_unregister(ar);
191  err_spectral_destroy:
192         ath10k_spectral_destroy(ar);
193  err_debug_destroy:
194 @@ -3490,6 +3509,8 @@ void ath10k_core_unregister(struct ath10
195         if (!test_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags))
196                 return;
197  
198 +       ath10k_leds_unregister(ar);
199 +
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-4.19/core.h
204 +++ b/ath10k-4.19/core.h
205 @@ -25,6 +25,7 @@
206  #include <linux/pci.h>
207  #include <linux/uuid.h>
208  #include <linux/time.h>
209 +#include <linux/leds.h>
210  
211  #include "htt.h"
212  #include "htc.h"
213 @@ -1138,7 +1139,6 @@ struct ath10k {
214         u32 low_5ghz_chan;
215         u32 high_5ghz_chan;
216         bool ani_enabled;
217 -
218         bool p2p;
219         bool ct_all_pkts_htt; /* CT firmware only: native-wifi for all pkts */
220  
221 @@ -1391,6 +1391,13 @@ struct ath10k {
222         } testmode;
223  
224         struct {
225 +               struct gpio_led wifi_led;
226 +               struct led_classdev cdev;
227 +               char label[48];
228 +               u32 gpio_state_pin;
229 +       } leds;
230 +
231 +       struct {
232                 /* protected by data_lock */
233                 u32 fw_crash_counter;
234                 u32 fw_warm_reset_counter;
235 --- a/ath10k-4.19/hw.h
236 +++ b/ath10k-4.19/hw.h
237 @@ -508,6 +508,7 @@ struct ath10k_hw_params {
238         const char *name;
239         u32 patch_load_addr;
240         int uart_pin;
241 +       int led_pin;
242         u32 otp_exe_param;
243  
244         /* Type of hw cycle counter wraparound logic, for more info
245 --- /dev/null
246 +++ b/ath10k-4.19/leds.c
247 @@ -0,0 +1,103 @@
248 +/*
249 + * Copyright (c) 2005-2011 Atheros Communications Inc.
250 + * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
251 + * Copyright (c) 2018 Sebastian Gottschall <s.gottschall@dd-wrt.com>
252 + * Copyright (c) 2018, The Linux Foundation. All rights reserved.
253 + *
254 + * Permission to use, copy, modify, and/or distribute this software for any
255 + * purpose with or without fee is hereby granted, provided that the above
256 + * copyright notice and this permission notice appear in all copies.
257 + *
258 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
259 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
260 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
261 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
262 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
263 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
264 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
265 + */
266 +
267 +#include <linux/leds.h>
268 +
269 +#include "core.h"
270 +#include "wmi.h"
271 +#include "wmi-ops.h"
272 +
273 +#include "leds.h"
274 +
275 +static int ath10k_leds_set_brightness_blocking(struct led_classdev *led_cdev,
276 +                                              enum led_brightness brightness)
277 +{
278 +       struct ath10k *ar = container_of(led_cdev, struct ath10k,
279 +                                        leds.cdev);
280 +       struct gpio_led *led = &ar->leds.wifi_led;
281 +
282 +       mutex_lock(&ar->conf_mutex);
283 +
284 +       if (ar->state != ATH10K_STATE_ON)
285 +               goto out;
286 +
287 +       ar->leds.gpio_state_pin = (brightness != LED_OFF) ^ led->active_low;
288 +       ath10k_wmi_gpio_output(ar, led->gpio, ar->leds.gpio_state_pin);
289 +
290 +out:
291 +       mutex_unlock(&ar->conf_mutex);
292 +
293 +       return 0;
294 +}
295 +
296 +int ath10k_leds_start(struct ath10k *ar)
297 +{
298 +       if (ar->hw_params.led_pin == 0)
299 +               /* leds not supported */
300 +               return 0;
301 +
302 +       /* under some circumstances, the gpio pin gets reconfigured
303 +        * to default state by the firmware, so we need to
304 +        * reconfigure it this behaviour has only ben seen on
305 +        * QCA9984 and QCA99XX devices so far
306 +        */
307 +       ath10k_wmi_gpio_config(ar, ar->hw_params.led_pin, 0,
308 +                              WMI_GPIO_PULL_NONE, WMI_GPIO_INTTYPE_DISABLE);
309 +       ath10k_wmi_gpio_output(ar, ar->hw_params.led_pin, 1);
310 +
311 +       return 0;
312 +}
313 +
314 +int ath10k_leds_register(struct ath10k *ar)
315 +{
316 +       int ret;
317 +
318 +       if (ar->hw_params.led_pin == 0)
319 +               /* leds not supported */
320 +               return 0;
321 +
322 +       snprintf(ar->leds.label, sizeof(ar->leds.label), "ath10k-%s",
323 +                wiphy_name(ar->hw->wiphy));
324 +       ar->leds.wifi_led.active_low = 1;
325 +       ar->leds.wifi_led.gpio = ar->hw_params.led_pin;
326 +       ar->leds.wifi_led.name = ar->leds.label;
327 +       ar->leds.wifi_led.default_state = LEDS_GPIO_DEFSTATE_KEEP;
328 +
329 +       ar->leds.cdev.name = ar->leds.label;
330 +       ar->leds.cdev.brightness_set_blocking = ath10k_leds_set_brightness_blocking;
331 +
332 +       /* FIXME: this assignment doesn't make sense as it's NULL, remove it? */
333 +       ar->leds.cdev.default_trigger = ar->leds.wifi_led.default_trigger;
334 +
335 +       ret = led_classdev_register(wiphy_dev(ar->hw->wiphy), &ar->leds.cdev);
336 +       if (ret)
337 +               return ret;
338 +
339 +       return 0;
340 +}
341 +
342 +void ath10k_leds_unregister(struct ath10k *ar)
343 +{
344 +       if (ar->hw_params.led_pin == 0)
345 +               /* leds not supported */
346 +               return;
347 +
348 +       led_classdev_unregister(&ar->leds.cdev);
349 +}
350 +
351 --- /dev/null
352 +++ b/ath10k-4.19/leds.h
353 @@ -0,0 +1,41 @@
354 +/*
355 + * Copyright (c) 2018, The Linux Foundation. All rights reserved.
356 + *
357 + * Permission to use, copy, modify, and/or distribute this software for any
358 + * purpose with or without fee is hereby granted, provided that the above
359 + * copyright notice and this permission notice appear in all copies.
360 + *
361 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
362 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
363 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
364 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
365 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
366 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
367 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
368 + */
369 +#ifndef _LEDS_H_
370 +#define _LEDS_H_
371 +
372 +#include "core.h"
373 +
374 +#ifdef CONFIG_ATH10K_LEDS
375 +void ath10k_leds_unregister(struct ath10k *ar);
376 +int ath10k_leds_start(struct ath10k *ar);
377 +int ath10k_leds_register(struct ath10k *ar);
378 +#else
379 +static inline void ath10k_leds_unregister(struct ath10k *ar)
380 +{
381 +}
382 +
383 +static inline int ath10k_leds_start(struct ath10k *ar)
384 +{
385 +       return 0;
386 +}
387 +
388 +static inline int ath10k_leds_register(struct ath10k *ar)
389 +{
390 +       return 0;
391 +}
392 +
393 +#endif
394 +#endif /* _LEDS_H_ */
395 --- a/ath10k-4.19/mac.c
396 +++ b/ath10k-4.19/mac.c
397 @@ -34,6 +34,7 @@
398  #include "wmi-tlv.h"
399  #include "wmi-ops.h"
400  #include "wow.h"
401 +#include "leds.h"
402  
403  /*********/
404  /* Rates */
405 --- a/ath10k-4.19/wmi-ops.h
406 +++ b/ath10k-4.19/wmi-ops.h
407 @@ -218,7 +218,10 @@ struct wmi_ops {
408         struct sk_buff *(*gen_echo)(struct ath10k *ar, u32 value);
409         struct sk_buff *(*gen_pdev_get_tpc_table_cmdid)(struct ath10k *ar,
410                                                         u32 param);
411 +       struct sk_buff *(*gen_gpio_config)(struct ath10k *ar, u32 gpio_num,
412 +                                          u32 input, u32 pull_type, u32 intr_mode);
413  
414 +       struct sk_buff *(*gen_gpio_output)(struct ath10k *ar, u32 gpio_num, u32 set);
415  };
416  
417  int ath10k_wmi_cmd_send(struct ath10k *ar, struct sk_buff *skb, u32 cmd_id);
418 @@ -1079,6 +1082,35 @@ ath10k_wmi_force_fw_hang(struct ath10k *
419         return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->force_fw_hang_cmdid);
420  }
421  
422 +static inline int ath10k_wmi_gpio_config(struct ath10k *ar, u32 gpio_num,
423 +                                        u32 input, u32 pull_type, u32 intr_mode)
424 +{
425 +       struct sk_buff *skb;
426 +
427 +       if (!ar->wmi.ops->gen_gpio_config)
428 +               return -EOPNOTSUPP;
429 +
430 +       skb = ar->wmi.ops->gen_gpio_config(ar, gpio_num, input, pull_type, intr_mode);
431 +       if (IS_ERR(skb))
432 +               return PTR_ERR(skb);
433 +
434 +       return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->gpio_config_cmdid);
435 +}
436 +
437 +static inline int ath10k_wmi_gpio_output(struct ath10k *ar, u32 gpio_num, u32 set)
438 +{
439 +       struct sk_buff *skb;
440 +
441 +       if (!ar->wmi.ops->gen_gpio_config)
442 +               return -EOPNOTSUPP;
443 +
444 +       skb = ar->wmi.ops->gen_gpio_output(ar, gpio_num, set);
445 +       if (IS_ERR(skb))
446 +               return PTR_ERR(skb);
447 +
448 +       return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->gpio_output_cmdid);
449 +}
450 +
451  static inline int
452  ath10k_wmi_dbglog_cfg(struct ath10k *ar, u64 module_enable, u32 log_level)
453  {
454 --- a/ath10k-4.19/wmi-tlv.c
455 +++ b/ath10k-4.19/wmi-tlv.c
456 @@ -3976,6 +3976,8 @@ static const struct wmi_ops wmi_tlv_ops
457         .gen_echo = ath10k_wmi_tlv_op_gen_echo,
458         .gen_vdev_spectral_conf = ath10k_wmi_tlv_op_gen_vdev_spectral_conf,
459         .gen_vdev_spectral_enable = ath10k_wmi_tlv_op_gen_vdev_spectral_enable,
460 +       /* .gen_gpio_config not implemented */
461 +       /* .gen_gpio_output not implemented */
462  };
463  
464  static const struct wmi_peer_flags_map wmi_tlv_peer_flags_map = {
465 --- a/ath10k-4.19/wmi.c
466 +++ b/ath10k-4.19/wmi.c
467 @@ -8071,6 +8071,49 @@ ath10k_wmi_op_gen_peer_set_param(struct
468         return skb;
469  }
470  
471 +static struct sk_buff *ath10k_wmi_op_gen_gpio_config(struct ath10k *ar,
472 +                                                    u32 gpio_num, u32 input,
473 +                                                    u32 pull_type, u32 intr_mode)
474 +{
475 +       struct wmi_gpio_config_cmd *cmd;
476 +       struct sk_buff *skb;
477 +
478 +       skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
479 +       if (!skb)
480 +               return ERR_PTR(-ENOMEM);
481 +
482 +       cmd = (struct wmi_gpio_config_cmd *)skb->data;
483 +       cmd->pull_type = __cpu_to_le32(pull_type);
484 +       cmd->gpio_num = __cpu_to_le32(gpio_num);
485 +       cmd->input = __cpu_to_le32(input);
486 +       cmd->intr_mode = __cpu_to_le32(intr_mode);
487 +
488 +       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",
489 +                  gpio_num, input, pull_type, intr_mode);
490 +
491 +       return skb;
492 +}
493 +
494 +static struct sk_buff *ath10k_wmi_op_gen_gpio_output(struct ath10k *ar,
495 +                                                    u32 gpio_num, u32 set)
496 +{
497 +       struct wmi_gpio_output_cmd *cmd;
498 +       struct sk_buff *skb;
499 +
500 +       skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
501 +       if (!skb)
502 +               return ERR_PTR(-ENOMEM);
503 +
504 +       cmd = (struct wmi_gpio_output_cmd *)skb->data;
505 +       cmd->gpio_num = __cpu_to_le32(gpio_num);
506 +       cmd->set = __cpu_to_le32(set);
507 +
508 +       ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi gpio_output gpio_num 0x%08x set 0x%08x\n",
509 +                  gpio_num, set);
510 +
511 +       return skb;
512 +}
513 +
514  static struct sk_buff *
515  ath10k_wmi_op_gen_set_psmode(struct ath10k *ar, u32 vdev_id,
516                              enum wmi_sta_ps_mode psmode)
517 @@ -9824,6 +9867,9 @@ static const struct wmi_ops wmi_ops = {
518         .fw_stats_fill = ath10k_wmi_main_op_fw_stats_fill,
519         .get_vdev_subtype = ath10k_wmi_op_get_vdev_subtype,
520         .gen_echo = ath10k_wmi_op_gen_echo,
521 +       .gen_gpio_config = ath10k_wmi_op_gen_gpio_config,
522 +       .gen_gpio_output = ath10k_wmi_op_gen_gpio_output,
523 +
524         /* .gen_bcn_tmpl not implemented */
525         /* .gen_prb_tmpl not implemented */
526         /* .gen_p2p_go_bcn_ie not implemented */
527 @@ -9894,6 +9940,8 @@ static const struct wmi_ops wmi_10_1_ops
528         .fw_stats_fill = ath10k_wmi_10x_op_fw_stats_fill,
529         .get_vdev_subtype = ath10k_wmi_op_get_vdev_subtype,
530         .gen_echo = ath10k_wmi_op_gen_echo,
531 +       .gen_gpio_config = ath10k_wmi_op_gen_gpio_config,
532 +       .gen_gpio_output = ath10k_wmi_op_gen_gpio_output,
533         /* .gen_bcn_tmpl not implemented */
534         /* .gen_prb_tmpl not implemented */
535         /* .gen_p2p_go_bcn_ie not implemented */
536 @@ -9972,6 +10020,8 @@ static const struct wmi_ops wmi_10_2_ops
537         .gen_delba_send = ath10k_wmi_op_gen_delba_send,
538         .fw_stats_fill = ath10k_wmi_10x_op_fw_stats_fill,
539         .get_vdev_subtype = ath10k_wmi_op_get_vdev_subtype,
540 +       .gen_gpio_config = ath10k_wmi_op_gen_gpio_config,
541 +       .gen_gpio_output = ath10k_wmi_op_gen_gpio_output,
542         /* .gen_pdev_enable_adaptive_cca not implemented */
543  };
544  
545 @@ -10042,6 +10092,8 @@ static const struct wmi_ops wmi_10_2_4_o
546         .gen_pdev_enable_adaptive_cca =
547                 ath10k_wmi_op_gen_pdev_enable_adaptive_cca,
548         .get_vdev_subtype = ath10k_wmi_10_2_4_op_get_vdev_subtype,
549 +       .gen_gpio_config = ath10k_wmi_op_gen_gpio_config,
550 +       .gen_gpio_output = ath10k_wmi_op_gen_gpio_output,
551         /* .gen_bcn_tmpl not implemented */
552         /* .gen_prb_tmpl not implemented */
553         /* .gen_p2p_go_bcn_ie not implemented */
554 @@ -10122,6 +10174,8 @@ static const struct wmi_ops wmi_10_4_ops
555         .gen_pdev_bss_chan_info_req = ath10k_wmi_10_2_op_gen_pdev_bss_chan_info,
556         .gen_echo = ath10k_wmi_op_gen_echo,
557         .gen_pdev_get_tpc_config = ath10k_wmi_10_2_4_op_gen_pdev_get_tpc_config,
558 +       .gen_gpio_config = ath10k_wmi_op_gen_gpio_config,
559 +       .gen_gpio_output = ath10k_wmi_op_gen_gpio_output,
560  };
561  
562  int ath10k_wmi_attach(struct ath10k *ar)
563 --- a/ath10k-4.19/wmi.h
564 +++ b/ath10k-4.19/wmi.h
565 @@ -3084,6 +3084,41 @@ enum wmi_10_4_feature_mask {
566  
567  };
568  
569 +/* WMI_GPIO_CONFIG_CMDID */
570 +enum {
571 +       WMI_GPIO_PULL_NONE,
572 +       WMI_GPIO_PULL_UP,
573 +       WMI_GPIO_PULL_DOWN,
574 +};
575 +
576 +enum {
577 +       WMI_GPIO_INTTYPE_DISABLE,
578 +       WMI_GPIO_INTTYPE_RISING_EDGE,
579 +       WMI_GPIO_INTTYPE_FALLING_EDGE,
580 +       WMI_GPIO_INTTYPE_BOTH_EDGE,
581 +       WMI_GPIO_INTTYPE_LEVEL_LOW,
582 +       WMI_GPIO_INTTYPE_LEVEL_HIGH
583 +};
584 +
585 +/* WMI_GPIO_CONFIG_CMDID */
586 +struct wmi_gpio_config_cmd {
587 +       __le32 gpio_num;             /* GPIO number to be setup */
588 +       __le32 input;                /* 0 - Output/ 1 - Input */
589 +       __le32 pull_type;            /* Pull type defined above */
590 +       __le32 intr_mode;            /* Interrupt mode defined above (Input) */
591 +} __packed;
592 +
593 +/* WMI_GPIO_OUTPUT_CMDID */
594 +struct wmi_gpio_output_cmd {
595 +       __le32 gpio_num;    /* GPIO number to be setup */
596 +       __le32 set;         /* Set the GPIO pin*/
597 +} __packed;
598 +
599 +/* WMI_GPIO_INPUT_EVENTID */
600 +struct wmi_gpio_input_event {
601 +       __le32 gpio_num;    /* GPIO number which changed state */
602 +} __packed;
603 +
604  struct wmi_ext_resource_config_10_4_cmd {
605         /* contains enum wmi_host_platform_type */
606         __le32 host_platform_config;
607 --- a/ath10k-5.2/Kconfig
608 +++ b/ath10k-5.2/Kconfig
609 @@ -66,6 +66,16 @@ config ATH10K_DEBUGFS
610  
611           If unsure, say Y to make it easier to debug problems.
612  
613 +config ATH10K_LEDS
614 +       bool "Atheros ath10k LED support"
615 +       depends on ATH10K
616 +       select MAC80211_LEDS
617 +       select LEDS_CLASS
618 +       select NEW_LEDS
619 +       default y
620 +       ---help---
621 +         This option is necessary, if you want LED support for chipset connected led pins. If unsure, say N.
622 +
623  config ATH10K_SPECTRAL
624         bool "Atheros ath10k spectral scan support"
625         depends on ATH10K_DEBUGFS
626 --- a/ath10k-5.2/Makefile
627 +++ b/ath10k-5.2/Makefile
628 @@ -19,6 +19,7 @@ ath10k_core-$(CONFIG_ATH10K_SPECTRAL) +=
629  ath10k_core-$(CONFIG_NL80211_TESTMODE) += testmode.o
630  ath10k_core-$(CONFIG_ATH10K_TRACING) += trace.o
631  ath10k_core-$(CONFIG_THERMAL) += thermal.o
632 +ath10k_core-$(CONFIG_ATH10K_LEDS) += leds.o
633  ath10k_core-$(CONFIG_MAC80211_DEBUGFS) += debugfs_sta.o
634  ath10k_core-$(CONFIG_PM) += wow.o
635  ath10k_core-$(CONFIG_DEV_COREDUMP) += coredump.o
636 --- a/ath10k-5.2/core.c
637 +++ b/ath10k-5.2/core.c
638 @@ -25,6 +25,7 @@
639  #include "testmode.h"
640  #include "wmi-ops.h"
641  #include "coredump.h"
642 +#include "leds.h"
643  
644  /* Disable ath10k-ct DBGLOG output by default */
645  unsigned int ath10k_debug_mask = ATH10K_DBG_NO_DBGLOG;
646 @@ -63,6 +64,7 @@ static const struct ath10k_hw_params ath
647                 .dev_id = QCA988X_2_0_DEVICE_ID,
648                 .bus = ATH10K_BUS_PCI,
649                 .name = "qca988x hw2.0",
650 +               .led_pin = 1,
651                 .patch_load_addr = QCA988X_HW_2_0_PATCH_LOAD_ADDR,
652                 .uart_pin = 7,
653                 .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_ALL,
654 @@ -131,6 +133,7 @@ static const struct ath10k_hw_params ath
655                 .dev_id = QCA9887_1_0_DEVICE_ID,
656                 .bus = ATH10K_BUS_PCI,
657                 .name = "qca9887 hw1.0",
658 +               .led_pin = 1,
659                 .patch_load_addr = QCA9887_HW_1_0_PATCH_LOAD_ADDR,
660                 .uart_pin = 7,
661                 .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_ALL,
662 @@ -305,6 +308,7 @@ static const struct ath10k_hw_params ath
663                 .dev_id = QCA99X0_2_0_DEVICE_ID,
664                 .bus = ATH10K_BUS_PCI,
665                 .name = "qca99x0 hw2.0",
666 +               .led_pin = 17,
667                 .patch_load_addr = QCA99X0_HW_2_0_PATCH_LOAD_ADDR,
668                 .uart_pin = 7,
669                 .otp_exe_param = 0x00000700,
670 @@ -345,6 +349,7 @@ static const struct ath10k_hw_params ath
671                 .dev_id = QCA9984_1_0_DEVICE_ID,
672                 .bus = ATH10K_BUS_PCI,
673                 .name = "qca9984/qca9994 hw1.0",
674 +               .led_pin = 17,
675                 .patch_load_addr = QCA9984_HW_1_0_PATCH_LOAD_ADDR,
676                 .uart_pin = 7,
677                 .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_EACH,
678 @@ -392,6 +397,7 @@ static const struct ath10k_hw_params ath
679                 .dev_id = QCA9888_2_0_DEVICE_ID,
680                 .bus = ATH10K_BUS_PCI,
681                 .name = "qca9888 hw2.0",
682 +               .led_pin = 17,
683                 .patch_load_addr = QCA9888_HW_2_0_PATCH_LOAD_ADDR,
684                 .uart_pin = 7,
685                 .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_EACH,
686 @@ -3503,6 +3509,10 @@ int ath10k_core_start(struct ath10k *ar,
687                         ath10k_wmi_check_apply_board_power_ctl_table(ar);
688         }
689  
690 +       status = ath10k_leds_start(ar);
691 +       if (status)
692 +               goto err_hif_stop;
693 +
694         return 0;
695  
696  err_hif_stop:
697 @@ -3759,9 +3769,18 @@ static void ath10k_core_register_work(st
698                 goto err_spectral_destroy;
699         }
700  
701 +       status = ath10k_leds_register(ar);
702 +       if (status) {
703 +               ath10k_err(ar, "could not register leds: %d\n",
704 +                          status);
705 +               goto err_thermal_unregister;
706 +       }
707 +
708         set_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags);
709         return;
710  
711 +err_thermal_unregister:
712 +       ath10k_thermal_unregister(ar);
713  err_spectral_destroy:
714         ath10k_spectral_destroy(ar);
715  err_debug_destroy:
716 @@ -3821,6 +3840,8 @@ void ath10k_core_unregister(struct ath10
717         if (!test_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags))
718                 return;
719  
720 +       ath10k_leds_unregister(ar);
721 +
722         ath10k_thermal_unregister(ar);
723         /* Stop spectral before unregistering from mac80211 to remove the
724          * relayfs debugfs file cleanly. Otherwise the parent debugfs tree
725 --- a/ath10k-5.2/core.h
726 +++ b/ath10k-5.2/core.h
727 @@ -14,6 +14,7 @@
728  #include <linux/pci.h>
729  #include <linux/uuid.h>
730  #include <linux/time.h>
731 +#include <linux/leds.h>
732  
733  #include "htt.h"
734  #include "htc.h"
735 @@ -1449,6 +1450,13 @@ struct ath10k {
736         } testmode;
737  
738         struct {
739 +               struct gpio_led wifi_led;
740 +               struct led_classdev cdev;
741 +               char label[48];
742 +               u32 gpio_state_pin;
743 +       } leds;
744 +
745 +       struct {
746                 /* protected by data_lock */
747                 u32 fw_crash_counter;
748                 u32 fw_warm_reset_counter;
749 --- a/ath10k-5.2/hw.h
750 +++ b/ath10k-5.2/hw.h
751 @@ -515,6 +515,7 @@ struct ath10k_hw_params {
752         const char *name;
753         u32 patch_load_addr;
754         int uart_pin;
755 +       int led_pin;
756         u32 otp_exe_param;
757  
758         /* Type of hw cycle counter wraparound logic, for more info
759 --- /dev/null
760 +++ b/ath10k-5.2/leds.c
761 @@ -0,0 +1,103 @@
762 +/*
763 + * Copyright (c) 2005-2011 Atheros Communications Inc.
764 + * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
765 + * Copyright (c) 2018 Sebastian Gottschall <s.gottschall@dd-wrt.com>
766 + * Copyright (c) 2018, The Linux Foundation. All rights reserved.
767 + *
768 + * Permission to use, copy, modify, and/or distribute this software for any
769 + * purpose with or without fee is hereby granted, provided that the above
770 + * copyright notice and this permission notice appear in all copies.
771 + *
772 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
773 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
774 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
775 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
776 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
777 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
778 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
779 + */
780 +
781 +#include <linux/leds.h>
782 +
783 +#include "core.h"
784 +#include "wmi.h"
785 +#include "wmi-ops.h"
786 +
787 +#include "leds.h"
788 +
789 +static int ath10k_leds_set_brightness_blocking(struct led_classdev *led_cdev,
790 +                                              enum led_brightness brightness)
791 +{
792 +       struct ath10k *ar = container_of(led_cdev, struct ath10k,
793 +                                        leds.cdev);
794 +       struct gpio_led *led = &ar->leds.wifi_led;
795 +
796 +       mutex_lock(&ar->conf_mutex);
797 +
798 +       if (ar->state != ATH10K_STATE_ON)
799 +               goto out;
800 +
801 +       ar->leds.gpio_state_pin = (brightness != LED_OFF) ^ led->active_low;
802 +       ath10k_wmi_gpio_output(ar, led->gpio, ar->leds.gpio_state_pin);
803 +
804 +out:
805 +       mutex_unlock(&ar->conf_mutex);
806 +
807 +       return 0;
808 +}
809 +
810 +int ath10k_leds_start(struct ath10k *ar)
811 +{
812 +       if (ar->hw_params.led_pin == 0)
813 +               /* leds not supported */
814 +               return 0;
815 +
816 +       /* under some circumstances, the gpio pin gets reconfigured
817 +        * to default state by the firmware, so we need to
818 +        * reconfigure it this behaviour has only ben seen on
819 +        * QCA9984 and QCA99XX devices so far
820 +        */
821 +       ath10k_wmi_gpio_config(ar, ar->hw_params.led_pin, 0,
822 +                              WMI_GPIO_PULL_NONE, WMI_GPIO_INTTYPE_DISABLE);
823 +       ath10k_wmi_gpio_output(ar, ar->hw_params.led_pin, 1);
824 +
825 +       return 0;
826 +}
827 +
828 +int ath10k_leds_register(struct ath10k *ar)
829 +{
830 +       int ret;
831 +
832 +       if (ar->hw_params.led_pin == 0)
833 +               /* leds not supported */
834 +               return 0;
835 +
836 +       snprintf(ar->leds.label, sizeof(ar->leds.label), "ath10k-%s",
837 +                wiphy_name(ar->hw->wiphy));
838 +       ar->leds.wifi_led.active_low = 1;
839 +       ar->leds.wifi_led.gpio = ar->hw_params.led_pin;
840 +       ar->leds.wifi_led.name = ar->leds.label;
841 +       ar->leds.wifi_led.default_state = LEDS_GPIO_DEFSTATE_KEEP;
842 +
843 +       ar->leds.cdev.name = ar->leds.label;
844 +       ar->leds.cdev.brightness_set_blocking = ath10k_leds_set_brightness_blocking;
845 +
846 +       /* FIXME: this assignment doesn't make sense as it's NULL, remove it? */
847 +       ar->leds.cdev.default_trigger = ar->leds.wifi_led.default_trigger;
848 +
849 +       ret = led_classdev_register(wiphy_dev(ar->hw->wiphy), &ar->leds.cdev);
850 +       if (ret)
851 +               return ret;
852 +
853 +       return 0;
854 +}
855 +
856 +void ath10k_leds_unregister(struct ath10k *ar)
857 +{
858 +       if (ar->hw_params.led_pin == 0)
859 +               /* leds not supported */
860 +               return;
861 +
862 +       led_classdev_unregister(&ar->leds.cdev);
863 +}
864 +
865 --- /dev/null
866 +++ b/ath10k-5.2/leds.h
867 @@ -0,0 +1,41 @@
868 +/*
869 + * Copyright (c) 2018, The Linux Foundation. All rights reserved.
870 + *
871 + * Permission to use, copy, modify, and/or distribute this software for any
872 + * purpose with or without fee is hereby granted, provided that the above
873 + * copyright notice and this permission notice appear in all copies.
874 + *
875 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
876 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
877 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
878 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
879 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
880 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
881 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
882 + */
883 +#ifndef _LEDS_H_
884 +#define _LEDS_H_
885 +
886 +#include "core.h"
887 +
888 +#ifdef CONFIG_ATH10K_LEDS
889 +void ath10k_leds_unregister(struct ath10k *ar);
890 +int ath10k_leds_start(struct ath10k *ar);
891 +int ath10k_leds_register(struct ath10k *ar);
892 +#else
893 +static inline void ath10k_leds_unregister(struct ath10k *ar)
894 +{
895 +}
896 +
897 +static inline int ath10k_leds_start(struct ath10k *ar)
898 +{
899 +       return 0;
900 +}
901 +
902 +static inline int ath10k_leds_register(struct ath10k *ar)
903 +{
904 +       return 0;
905 +}
906 +
907 +#endif
908 +#endif /* _LEDS_H_ */
909 --- a/ath10k-5.2/mac.c
910 +++ b/ath10k-5.2/mac.c
911 @@ -24,6 +24,7 @@
912  #include "wmi-tlv.h"
913  #include "wmi-ops.h"
914  #include "wow.h"
915 +#include "leds.h"
916  
917  /*********/
918  /* Rates */
919 --- a/ath10k-5.2/wmi-ops.h
920 +++ b/ath10k-5.2/wmi-ops.h
921 @@ -218,7 +218,10 @@ struct wmi_ops {
922         struct sk_buff *(*gen_bb_timing)
923                         (struct ath10k *ar,
924                          const struct wmi_bb_timing_cfg_arg *arg);
925 +       struct sk_buff *(*gen_gpio_config)(struct ath10k *ar, u32 gpio_num,
926 +                                          u32 input, u32 pull_type, u32 intr_mode);
927  
928 +       struct sk_buff *(*gen_gpio_output)(struct ath10k *ar, u32 gpio_num, u32 set);
929  };
930  
931  int ath10k_wmi_cmd_send(struct ath10k *ar, struct sk_buff *skb, u32 cmd_id);
932 @@ -1105,6 +1108,35 @@ ath10k_wmi_force_fw_hang(struct ath10k *
933         return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->force_fw_hang_cmdid);
934  }
935  
936 +static inline int ath10k_wmi_gpio_config(struct ath10k *ar, u32 gpio_num,
937 +                                        u32 input, u32 pull_type, u32 intr_mode)
938 +{
939 +       struct sk_buff *skb;
940 +
941 +       if (!ar->wmi.ops->gen_gpio_config)
942 +               return -EOPNOTSUPP;
943 +
944 +       skb = ar->wmi.ops->gen_gpio_config(ar, gpio_num, input, pull_type, intr_mode);
945 +       if (IS_ERR(skb))
946 +               return PTR_ERR(skb);
947 +
948 +       return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->gpio_config_cmdid);
949 +}
950 +
951 +static inline int ath10k_wmi_gpio_output(struct ath10k *ar, u32 gpio_num, u32 set)
952 +{
953 +       struct sk_buff *skb;
954 +
955 +       if (!ar->wmi.ops->gen_gpio_config)
956 +               return -EOPNOTSUPP;
957 +
958 +       skb = ar->wmi.ops->gen_gpio_output(ar, gpio_num, set);
959 +       if (IS_ERR(skb))
960 +               return PTR_ERR(skb);
961 +
962 +       return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->gpio_output_cmdid);
963 +}
964 +
965  static inline int
966  ath10k_wmi_dbglog_cfg(struct ath10k *ar, u64 module_enable, u32 log_level)
967  {
968 --- a/ath10k-5.2/wmi-tlv.c
969 +++ b/ath10k-5.2/wmi-tlv.c
970 @@ -4311,6 +4311,8 @@ static const struct wmi_ops wmi_tlv_ops
971         .gen_echo = ath10k_wmi_tlv_op_gen_echo,
972         .gen_vdev_spectral_conf = ath10k_wmi_tlv_op_gen_vdev_spectral_conf,
973         .gen_vdev_spectral_enable = ath10k_wmi_tlv_op_gen_vdev_spectral_enable,
974 +       /* .gen_gpio_config not implemented */
975 +       /* .gen_gpio_output not implemented */
976  };
977  
978  static const struct wmi_peer_flags_map wmi_tlv_peer_flags_map = {
979 --- a/ath10k-5.2/wmi.c
980 +++ b/ath10k-5.2/wmi.c
981 @@ -8295,6 +8295,49 @@ ath10k_wmi_op_gen_peer_set_param(struct
982         return skb;
983  }
984  
985 +static struct sk_buff *ath10k_wmi_op_gen_gpio_config(struct ath10k *ar,
986 +                                                    u32 gpio_num, u32 input,
987 +                                                    u32 pull_type, u32 intr_mode)
988 +{
989 +       struct wmi_gpio_config_cmd *cmd;
990 +       struct sk_buff *skb;
991 +
992 +       skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
993 +       if (!skb)
994 +               return ERR_PTR(-ENOMEM);
995 +
996 +       cmd = (struct wmi_gpio_config_cmd *)skb->data;
997 +       cmd->pull_type = __cpu_to_le32(pull_type);
998 +       cmd->gpio_num = __cpu_to_le32(gpio_num);
999 +       cmd->input = __cpu_to_le32(input);
1000 +       cmd->intr_mode = __cpu_to_le32(intr_mode);
1001 +
1002 +       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",
1003 +                  gpio_num, input, pull_type, intr_mode);
1004 +
1005 +       return skb;
1006 +}
1007 +
1008 +static struct sk_buff *ath10k_wmi_op_gen_gpio_output(struct ath10k *ar,
1009 +                                                    u32 gpio_num, u32 set)
1010 +{
1011 +       struct wmi_gpio_output_cmd *cmd;
1012 +       struct sk_buff *skb;
1013 +
1014 +       skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
1015 +       if (!skb)
1016 +               return ERR_PTR(-ENOMEM);
1017 +
1018 +       cmd = (struct wmi_gpio_output_cmd *)skb->data;
1019 +       cmd->gpio_num = __cpu_to_le32(gpio_num);
1020 +       cmd->set = __cpu_to_le32(set);
1021 +
1022 +       ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi gpio_output gpio_num 0x%08x set 0x%08x\n",
1023 +                  gpio_num, set);
1024 +
1025 +       return skb;
1026 +}
1027 +
1028  static struct sk_buff *
1029  ath10k_wmi_op_gen_set_psmode(struct ath10k *ar, u32 vdev_id,
1030                              enum wmi_sta_ps_mode psmode)
1031 @@ -10069,6 +10112,9 @@ static const struct wmi_ops wmi_ops = {
1032         .fw_stats_fill = ath10k_wmi_main_op_fw_stats_fill,
1033         .get_vdev_subtype = ath10k_wmi_op_get_vdev_subtype,
1034         .gen_echo = ath10k_wmi_op_gen_echo,
1035 +       .gen_gpio_config = ath10k_wmi_op_gen_gpio_config,
1036 +       .gen_gpio_output = ath10k_wmi_op_gen_gpio_output,
1037 +
1038         /* .gen_bcn_tmpl not implemented */
1039         /* .gen_prb_tmpl not implemented */
1040         /* .gen_p2p_go_bcn_ie not implemented */
1041 @@ -10139,6 +10185,8 @@ static const struct wmi_ops wmi_10_1_ops
1042         .fw_stats_fill = ath10k_wmi_10x_op_fw_stats_fill,
1043         .get_vdev_subtype = ath10k_wmi_op_get_vdev_subtype,
1044         .gen_echo = ath10k_wmi_op_gen_echo,
1045 +       .gen_gpio_config = ath10k_wmi_op_gen_gpio_config,
1046 +       .gen_gpio_output = ath10k_wmi_op_gen_gpio_output,
1047         /* .gen_bcn_tmpl not implemented */
1048         /* .gen_prb_tmpl not implemented */
1049         /* .gen_p2p_go_bcn_ie not implemented */
1050 @@ -10218,6 +10266,8 @@ static const struct wmi_ops wmi_10_2_ops
1051         .gen_delba_send = ath10k_wmi_op_gen_delba_send,
1052         .fw_stats_fill = ath10k_wmi_10x_op_fw_stats_fill,
1053         .get_vdev_subtype = ath10k_wmi_op_get_vdev_subtype,
1054 +       .gen_gpio_config = ath10k_wmi_op_gen_gpio_config,
1055 +       .gen_gpio_output = ath10k_wmi_op_gen_gpio_output,
1056         /* .gen_pdev_enable_adaptive_cca not implemented */
1057  };
1058  
1059 @@ -10289,6 +10339,8 @@ static const struct wmi_ops wmi_10_2_4_o
1060                 ath10k_wmi_op_gen_pdev_enable_adaptive_cca,
1061         .get_vdev_subtype = ath10k_wmi_10_2_4_op_get_vdev_subtype,
1062         .gen_bb_timing = ath10k_wmi_10_2_4_op_gen_bb_timing,
1063 +       .gen_gpio_config = ath10k_wmi_op_gen_gpio_config,
1064 +       .gen_gpio_output = ath10k_wmi_op_gen_gpio_output,
1065         /* .gen_bcn_tmpl not implemented */
1066         /* .gen_prb_tmpl not implemented */
1067         /* .gen_p2p_go_bcn_ie not implemented */
1068 @@ -10370,6 +10422,8 @@ static const struct wmi_ops wmi_10_4_ops
1069         .gen_pdev_bss_chan_info_req = ath10k_wmi_10_2_op_gen_pdev_bss_chan_info,
1070         .gen_echo = ath10k_wmi_op_gen_echo,
1071         .gen_pdev_get_tpc_config = ath10k_wmi_10_2_4_op_gen_pdev_get_tpc_config,
1072 +       .gen_gpio_config = ath10k_wmi_op_gen_gpio_config,
1073 +       .gen_gpio_output = ath10k_wmi_op_gen_gpio_output,
1074  };
1075  
1076  int ath10k_wmi_attach(struct ath10k *ar)
1077 --- a/ath10k-5.2/wmi.h
1078 +++ b/ath10k-5.2/wmi.h
1079 @@ -3103,6 +3103,41 @@ enum wmi_10_4_feature_mask {
1080  
1081  };
1082  
1083 +/* WMI_GPIO_CONFIG_CMDID */
1084 +enum {
1085 +       WMI_GPIO_PULL_NONE,
1086 +       WMI_GPIO_PULL_UP,
1087 +       WMI_GPIO_PULL_DOWN,
1088 +};
1089 +
1090 +enum {
1091 +       WMI_GPIO_INTTYPE_DISABLE,
1092 +       WMI_GPIO_INTTYPE_RISING_EDGE,
1093 +       WMI_GPIO_INTTYPE_FALLING_EDGE,
1094 +       WMI_GPIO_INTTYPE_BOTH_EDGE,
1095 +       WMI_GPIO_INTTYPE_LEVEL_LOW,
1096 +       WMI_GPIO_INTTYPE_LEVEL_HIGH
1097 +};
1098 +
1099 +/* WMI_GPIO_CONFIG_CMDID */
1100 +struct wmi_gpio_config_cmd {
1101 +       __le32 gpio_num;             /* GPIO number to be setup */
1102 +       __le32 input;                /* 0 - Output/ 1 - Input */
1103 +       __le32 pull_type;            /* Pull type defined above */
1104 +       __le32 intr_mode;            /* Interrupt mode defined above (Input) */
1105 +} __packed;
1106 +
1107 +/* WMI_GPIO_OUTPUT_CMDID */
1108 +struct wmi_gpio_output_cmd {
1109 +       __le32 gpio_num;    /* GPIO number to be setup */
1110 +       __le32 set;         /* Set the GPIO pin*/
1111 +} __packed;
1112 +
1113 +/* WMI_GPIO_INPUT_EVENTID */
1114 +struct wmi_gpio_input_event {
1115 +       __le32 gpio_num;    /* GPIO number which changed state */
1116 +} __packed;
1117 +
1118  struct wmi_ext_resource_config_10_4_cmd {
1119         /* contains enum wmi_host_platform_type */
1120         __le32 host_platform_config;
1121 --- a/ath10k-5.4/Kconfig
1122 +++ b/ath10k-5.4/Kconfig
1123 @@ -66,6 +66,16 @@ config ATH10K_DEBUGFS
1124  
1125           If unsure, say Y to make it easier to debug problems.
1126  
1127 +config ATH10K_LEDS
1128 +       bool "Atheros ath10k LED support"
1129 +       depends on ATH10K
1130 +       select MAC80211_LEDS
1131 +       select LEDS_CLASS
1132 +       select NEW_LEDS
1133 +       default y
1134 +       ---help---
1135 +         This option is necessary, if you want LED support for chipset connected led pins. If unsure, say N.
1136 +
1137  config ATH10K_SPECTRAL
1138         bool "Atheros ath10k spectral scan support"
1139         depends on ATH10K_DEBUGFS
1140 --- a/ath10k-5.4/Makefile
1141 +++ b/ath10k-5.4/Makefile
1142 @@ -19,6 +19,7 @@ ath10k_core-$(CONFIG_ATH10K_SPECTRAL) +=
1143  ath10k_core-$(CONFIG_NL80211_TESTMODE) += testmode.o
1144  ath10k_core-$(CONFIG_ATH10K_TRACING) += trace.o
1145  ath10k_core-$(CONFIG_THERMAL) += thermal.o
1146 +ath10k_core-$(CONFIG_ATH10K_LEDS) += leds.o
1147  ath10k_core-$(CONFIG_MAC80211_DEBUGFS) += debugfs_sta.o
1148  ath10k_core-$(CONFIG_PM) += wow.o
1149  ath10k_core-$(CONFIG_DEV_COREDUMP) += coredump.o
1150 --- a/ath10k-5.4/core.c
1151 +++ b/ath10k-5.4/core.c
1152 @@ -25,6 +25,7 @@
1153  #include "testmode.h"
1154  #include "wmi-ops.h"
1155  #include "coredump.h"
1156 +#include "leds.h"
1157  
1158  /* Disable ath10k-ct DBGLOG output by default */
1159  unsigned int ath10k_debug_mask = ATH10K_DBG_NO_DBGLOG;
1160 @@ -67,6 +68,7 @@ static const struct ath10k_hw_params ath
1161                 .dev_id = QCA988X_2_0_DEVICE_ID,
1162                 .bus = ATH10K_BUS_PCI,
1163                 .name = "qca988x hw2.0",
1164 +               .led_pin = 1,
1165                 .patch_load_addr = QCA988X_HW_2_0_PATCH_LOAD_ADDR,
1166                 .uart_pin = 7,
1167                 .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_ALL,
1168 @@ -137,6 +139,7 @@ static const struct ath10k_hw_params ath
1169                 .dev_id = QCA9887_1_0_DEVICE_ID,
1170                 .bus = ATH10K_BUS_PCI,
1171                 .name = "qca9887 hw1.0",
1172 +               .led_pin = 1,
1173                 .patch_load_addr = QCA9887_HW_1_0_PATCH_LOAD_ADDR,
1174                 .uart_pin = 7,
1175                 .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_ALL,
1176 @@ -344,6 +347,7 @@ static const struct ath10k_hw_params ath
1177                 .dev_id = QCA99X0_2_0_DEVICE_ID,
1178                 .bus = ATH10K_BUS_PCI,
1179                 .name = "qca99x0 hw2.0",
1180 +               .led_pin = 17,
1181                 .patch_load_addr = QCA99X0_HW_2_0_PATCH_LOAD_ADDR,
1182                 .uart_pin = 7,
1183                 .otp_exe_param = 0x00000700,
1184 @@ -385,6 +389,7 @@ static const struct ath10k_hw_params ath
1185                 .dev_id = QCA9984_1_0_DEVICE_ID,
1186                 .bus = ATH10K_BUS_PCI,
1187                 .name = "qca9984/qca9994 hw1.0",
1188 +               .led_pin = 17,
1189                 .patch_load_addr = QCA9984_HW_1_0_PATCH_LOAD_ADDR,
1190                 .uart_pin = 7,
1191                 .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_EACH,
1192 @@ -433,6 +438,7 @@ static const struct ath10k_hw_params ath
1193                 .dev_id = QCA9888_2_0_DEVICE_ID,
1194                 .bus = ATH10K_BUS_PCI,
1195                 .name = "qca9888 hw2.0",
1196 +               .led_pin = 17,
1197                 .patch_load_addr = QCA9888_HW_2_0_PATCH_LOAD_ADDR,
1198                 .uart_pin = 7,
1199                 .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_EACH,
1200 @@ -3573,6 +3579,10 @@ int ath10k_core_start(struct ath10k *ar,
1201                         ath10k_wmi_check_apply_board_power_ctl_table(ar);
1202         }
1203  
1204 +       status = ath10k_leds_start(ar);
1205 +       if (status)
1206 +               goto err_hif_stop;
1207 +
1208         return 0;
1209  
1210  err_hif_stop:
1211 @@ -3829,9 +3839,18 @@ static void ath10k_core_register_work(st
1212                 goto err_spectral_destroy;
1213         }
1214  
1215 +       status = ath10k_leds_register(ar);
1216 +       if (status) {
1217 +               ath10k_err(ar, "could not register leds: %d\n",
1218 +                          status);
1219 +               goto err_thermal_unregister;
1220 +       }
1221 +
1222         set_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags);
1223         return;
1224  
1225 +err_thermal_unregister:
1226 +       ath10k_thermal_unregister(ar);
1227  err_spectral_destroy:
1228         ath10k_spectral_destroy(ar);
1229  err_debug_destroy:
1230 @@ -3891,6 +3910,8 @@ void ath10k_core_unregister(struct ath10
1231         if (!test_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags))
1232                 return;
1233  
1234 +       ath10k_leds_unregister(ar);
1235 +
1236         ath10k_thermal_unregister(ar);
1237         /* Stop spectral before unregistering from mac80211 to remove the
1238          * relayfs debugfs file cleanly. Otherwise the parent debugfs tree
1239 --- a/ath10k-5.4/core.h
1240 +++ b/ath10k-5.4/core.h
1241 @@ -14,6 +14,7 @@
1242  #include <linux/pci.h>
1243  #include <linux/uuid.h>
1244  #include <linux/time.h>
1245 +#include <linux/leds.h>
1246  
1247  #include "htt.h"
1248  #include "htc.h"
1249 @@ -1469,6 +1470,13 @@ struct ath10k {
1250         } testmode;
1251  
1252         struct {
1253 +               struct gpio_led wifi_led;
1254 +               struct led_classdev cdev;
1255 +               char label[48];
1256 +               u32 gpio_state_pin;
1257 +       } leds;
1258 +
1259 +       struct {
1260                 /* protected by data_lock */
1261                 u32 fw_crash_counter;
1262                 u32 fw_warm_reset_counter;
1263 --- a/ath10k-5.4/hw.h
1264 +++ b/ath10k-5.4/hw.h
1265 @@ -518,6 +518,7 @@ struct ath10k_hw_params {
1266         const char *name;
1267         u32 patch_load_addr;
1268         int uart_pin;
1269 +       int led_pin;
1270         u32 otp_exe_param;
1271  
1272         /* Type of hw cycle counter wraparound logic, for more info
1273 --- /dev/null
1274 +++ b/ath10k-5.4/leds.c
1275 @@ -0,0 +1,103 @@
1276 +/*
1277 + * Copyright (c) 2005-2011 Atheros Communications Inc.
1278 + * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
1279 + * Copyright (c) 2018 Sebastian Gottschall <s.gottschall@dd-wrt.com>
1280 + * Copyright (c) 2018, The Linux Foundation. All rights reserved.
1281 + *
1282 + * Permission to use, copy, modify, and/or distribute this software for any
1283 + * purpose with or without fee is hereby granted, provided that the above
1284 + * copyright notice and this permission notice appear in all copies.
1285 + *
1286 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1287 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1288 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1289 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1290 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1291 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1292 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1293 + */
1294 +
1295 +#include <linux/leds.h>
1296 +
1297 +#include "core.h"
1298 +#include "wmi.h"
1299 +#include "wmi-ops.h"
1300 +
1301 +#include "leds.h"
1302 +
1303 +static int ath10k_leds_set_brightness_blocking(struct led_classdev *led_cdev,
1304 +                                              enum led_brightness brightness)
1305 +{
1306 +       struct ath10k *ar = container_of(led_cdev, struct ath10k,
1307 +                                        leds.cdev);
1308 +       struct gpio_led *led = &ar->leds.wifi_led;
1309 +
1310 +       mutex_lock(&ar->conf_mutex);
1311 +
1312 +       if (ar->state != ATH10K_STATE_ON)
1313 +               goto out;
1314 +
1315 +       ar->leds.gpio_state_pin = (brightness != LED_OFF) ^ led->active_low;
1316 +       ath10k_wmi_gpio_output(ar, led->gpio, ar->leds.gpio_state_pin);
1317 +
1318 +out:
1319 +       mutex_unlock(&ar->conf_mutex);
1320 +
1321 +       return 0;
1322 +}
1323 +
1324 +int ath10k_leds_start(struct ath10k *ar)
1325 +{
1326 +       if (ar->hw_params.led_pin == 0)
1327 +               /* leds not supported */
1328 +               return 0;
1329 +
1330 +       /* under some circumstances, the gpio pin gets reconfigured
1331 +        * to default state by the firmware, so we need to
1332 +        * reconfigure it this behaviour has only ben seen on
1333 +        * QCA9984 and QCA99XX devices so far
1334 +        */
1335 +       ath10k_wmi_gpio_config(ar, ar->hw_params.led_pin, 0,
1336 +                              WMI_GPIO_PULL_NONE, WMI_GPIO_INTTYPE_DISABLE);
1337 +       ath10k_wmi_gpio_output(ar, ar->hw_params.led_pin, 1);
1338 +
1339 +       return 0;
1340 +}
1341 +
1342 +int ath10k_leds_register(struct ath10k *ar)
1343 +{
1344 +       int ret;
1345 +
1346 +       if (ar->hw_params.led_pin == 0)
1347 +               /* leds not supported */
1348 +               return 0;
1349 +
1350 +       snprintf(ar->leds.label, sizeof(ar->leds.label), "ath10k-%s",
1351 +                wiphy_name(ar->hw->wiphy));
1352 +       ar->leds.wifi_led.active_low = 1;
1353 +       ar->leds.wifi_led.gpio = ar->hw_params.led_pin;
1354 +       ar->leds.wifi_led.name = ar->leds.label;
1355 +       ar->leds.wifi_led.default_state = LEDS_GPIO_DEFSTATE_KEEP;
1356 +
1357 +       ar->leds.cdev.name = ar->leds.label;
1358 +       ar->leds.cdev.brightness_set_blocking = ath10k_leds_set_brightness_blocking;
1359 +
1360 +       /* FIXME: this assignment doesn't make sense as it's NULL, remove it? */
1361 +       ar->leds.cdev.default_trigger = ar->leds.wifi_led.default_trigger;
1362 +
1363 +       ret = led_classdev_register(wiphy_dev(ar->hw->wiphy), &ar->leds.cdev);
1364 +       if (ret)
1365 +               return ret;
1366 +
1367 +       return 0;
1368 +}
1369 +
1370 +void ath10k_leds_unregister(struct ath10k *ar)
1371 +{
1372 +       if (ar->hw_params.led_pin == 0)
1373 +               /* leds not supported */
1374 +               return;
1375 +
1376 +       led_classdev_unregister(&ar->leds.cdev);
1377 +}
1378 +
1379 --- /dev/null
1380 +++ b/ath10k-5.4/leds.h
1381 @@ -0,0 +1,41 @@
1382 +/*
1383 + * Copyright (c) 2018, The Linux Foundation. All rights reserved.
1384 + *
1385 + * Permission to use, copy, modify, and/or distribute this software for any
1386 + * purpose with or without fee is hereby granted, provided that the above
1387 + * copyright notice and this permission notice appear in all copies.
1388 + *
1389 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1390 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1391 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1392 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1393 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1394 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1395 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1396 + */
1397 +#ifndef _LEDS_H_
1398 +#define _LEDS_H_
1399 +
1400 +#include "core.h"
1401 +
1402 +#ifdef CONFIG_ATH10K_LEDS
1403 +void ath10k_leds_unregister(struct ath10k *ar);
1404 +int ath10k_leds_start(struct ath10k *ar);
1405 +int ath10k_leds_register(struct ath10k *ar);
1406 +#else
1407 +static inline void ath10k_leds_unregister(struct ath10k *ar)
1408 +{
1409 +}
1410 +
1411 +static inline int ath10k_leds_start(struct ath10k *ar)
1412 +{
1413 +       return 0;
1414 +}
1415 +
1416 +static inline int ath10k_leds_register(struct ath10k *ar)
1417 +{
1418 +       return 0;
1419 +}
1420 +
1421 +#endif
1422 +#endif /* _LEDS_H_ */
1423 --- a/ath10k-5.4/mac.c
1424 +++ b/ath10k-5.4/mac.c
1425 @@ -24,6 +24,7 @@
1426  #include "wmi-tlv.h"
1427  #include "wmi-ops.h"
1428  #include "wow.h"
1429 +#include "leds.h"
1430  
1431  /*********/
1432  /* Rates */
1433 --- a/ath10k-5.4/wmi-ops.h
1434 +++ b/ath10k-5.4/wmi-ops.h
1435 @@ -218,7 +218,10 @@ struct wmi_ops {
1436         struct sk_buff *(*gen_bb_timing)
1437                         (struct ath10k *ar,
1438                          const struct wmi_bb_timing_cfg_arg *arg);
1439 +       struct sk_buff *(*gen_gpio_config)(struct ath10k *ar, u32 gpio_num,
1440 +                                          u32 input, u32 pull_type, u32 intr_mode);
1441  
1442 +       struct sk_buff *(*gen_gpio_output)(struct ath10k *ar, u32 gpio_num, u32 set);
1443  };
1444  
1445  int ath10k_wmi_cmd_send(struct ath10k *ar, struct sk_buff *skb, u32 cmd_id);
1446 @@ -1105,6 +1108,35 @@ ath10k_wmi_force_fw_hang(struct ath10k *
1447         return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->force_fw_hang_cmdid);
1448  }
1449  
1450 +static inline int ath10k_wmi_gpio_config(struct ath10k *ar, u32 gpio_num,
1451 +                                        u32 input, u32 pull_type, u32 intr_mode)
1452 +{
1453 +       struct sk_buff *skb;
1454 +
1455 +       if (!ar->wmi.ops->gen_gpio_config)
1456 +               return -EOPNOTSUPP;
1457 +
1458 +       skb = ar->wmi.ops->gen_gpio_config(ar, gpio_num, input, pull_type, intr_mode);
1459 +       if (IS_ERR(skb))
1460 +               return PTR_ERR(skb);
1461 +
1462 +       return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->gpio_config_cmdid);
1463 +}
1464 +
1465 +static inline int ath10k_wmi_gpio_output(struct ath10k *ar, u32 gpio_num, u32 set)
1466 +{
1467 +       struct sk_buff *skb;
1468 +
1469 +       if (!ar->wmi.ops->gen_gpio_config)
1470 +               return -EOPNOTSUPP;
1471 +
1472 +       skb = ar->wmi.ops->gen_gpio_output(ar, gpio_num, set);
1473 +       if (IS_ERR(skb))
1474 +               return PTR_ERR(skb);
1475 +
1476 +       return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->gpio_output_cmdid);
1477 +}
1478 +
1479  static inline int
1480  ath10k_wmi_dbglog_cfg(struct ath10k *ar, u64 module_enable, u32 log_level)
1481  {
1482 --- a/ath10k-5.4/wmi-tlv.c
1483 +++ b/ath10k-5.4/wmi-tlv.c
1484 @@ -4364,6 +4364,8 @@ static const struct wmi_ops wmi_tlv_ops
1485         .gen_echo = ath10k_wmi_tlv_op_gen_echo,
1486         .gen_vdev_spectral_conf = ath10k_wmi_tlv_op_gen_vdev_spectral_conf,
1487         .gen_vdev_spectral_enable = ath10k_wmi_tlv_op_gen_vdev_spectral_enable,
1488 +       /* .gen_gpio_config not implemented */
1489 +       /* .gen_gpio_output not implemented */
1490  };
1491  
1492  static const struct wmi_peer_flags_map wmi_tlv_peer_flags_map = {
1493 --- a/ath10k-5.4/wmi.c
1494 +++ b/ath10k-5.4/wmi.c
1495 @@ -8295,6 +8295,49 @@ ath10k_wmi_op_gen_peer_set_param(struct
1496         return skb;
1497  }
1498  
1499 +static struct sk_buff *ath10k_wmi_op_gen_gpio_config(struct ath10k *ar,
1500 +                                                    u32 gpio_num, u32 input,
1501 +                                                    u32 pull_type, u32 intr_mode)
1502 +{
1503 +       struct wmi_gpio_config_cmd *cmd;
1504 +       struct sk_buff *skb;
1505 +
1506 +       skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
1507 +       if (!skb)
1508 +               return ERR_PTR(-ENOMEM);
1509 +
1510 +       cmd = (struct wmi_gpio_config_cmd *)skb->data;
1511 +       cmd->pull_type = __cpu_to_le32(pull_type);
1512 +       cmd->gpio_num = __cpu_to_le32(gpio_num);
1513 +       cmd->input = __cpu_to_le32(input);
1514 +       cmd->intr_mode = __cpu_to_le32(intr_mode);
1515 +
1516 +       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",
1517 +                  gpio_num, input, pull_type, intr_mode);
1518 +
1519 +       return skb;
1520 +}
1521 +
1522 +static struct sk_buff *ath10k_wmi_op_gen_gpio_output(struct ath10k *ar,
1523 +                                                    u32 gpio_num, u32 set)
1524 +{
1525 +       struct wmi_gpio_output_cmd *cmd;
1526 +       struct sk_buff *skb;
1527 +
1528 +       skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
1529 +       if (!skb)
1530 +               return ERR_PTR(-ENOMEM);
1531 +
1532 +       cmd = (struct wmi_gpio_output_cmd *)skb->data;
1533 +       cmd->gpio_num = __cpu_to_le32(gpio_num);
1534 +       cmd->set = __cpu_to_le32(set);
1535 +
1536 +       ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi gpio_output gpio_num 0x%08x set 0x%08x\n",
1537 +                  gpio_num, set);
1538 +
1539 +       return skb;
1540 +}
1541 +
1542  static struct sk_buff *
1543  ath10k_wmi_op_gen_set_psmode(struct ath10k *ar, u32 vdev_id,
1544                              enum wmi_sta_ps_mode psmode)
1545 @@ -10094,6 +10137,9 @@ static const struct wmi_ops wmi_ops = {
1546         .fw_stats_fill = ath10k_wmi_main_op_fw_stats_fill,
1547         .get_vdev_subtype = ath10k_wmi_op_get_vdev_subtype,
1548         .gen_echo = ath10k_wmi_op_gen_echo,
1549 +       .gen_gpio_config = ath10k_wmi_op_gen_gpio_config,
1550 +       .gen_gpio_output = ath10k_wmi_op_gen_gpio_output,
1551 +
1552         /* .gen_bcn_tmpl not implemented */
1553         /* .gen_prb_tmpl not implemented */
1554         /* .gen_p2p_go_bcn_ie not implemented */
1555 @@ -10164,6 +10210,8 @@ static const struct wmi_ops wmi_10_1_ops
1556         .fw_stats_fill = ath10k_wmi_10x_op_fw_stats_fill,
1557         .get_vdev_subtype = ath10k_wmi_op_get_vdev_subtype,
1558         .gen_echo = ath10k_wmi_op_gen_echo,
1559 +       .gen_gpio_config = ath10k_wmi_op_gen_gpio_config,
1560 +       .gen_gpio_output = ath10k_wmi_op_gen_gpio_output,
1561         /* .gen_bcn_tmpl not implemented */
1562         /* .gen_prb_tmpl not implemented */
1563         /* .gen_p2p_go_bcn_ie not implemented */
1564 @@ -10243,6 +10291,8 @@ static const struct wmi_ops wmi_10_2_ops
1565         .gen_delba_send = ath10k_wmi_op_gen_delba_send,
1566         .fw_stats_fill = ath10k_wmi_10x_op_fw_stats_fill,
1567         .get_vdev_subtype = ath10k_wmi_op_get_vdev_subtype,
1568 +       .gen_gpio_config = ath10k_wmi_op_gen_gpio_config,
1569 +       .gen_gpio_output = ath10k_wmi_op_gen_gpio_output,
1570         /* .gen_pdev_enable_adaptive_cca not implemented */
1571  };
1572  
1573 @@ -10314,6 +10364,8 @@ static const struct wmi_ops wmi_10_2_4_o
1574                 ath10k_wmi_op_gen_pdev_enable_adaptive_cca,
1575         .get_vdev_subtype = ath10k_wmi_10_2_4_op_get_vdev_subtype,
1576         .gen_bb_timing = ath10k_wmi_10_2_4_op_gen_bb_timing,
1577 +       .gen_gpio_config = ath10k_wmi_op_gen_gpio_config,
1578 +       .gen_gpio_output = ath10k_wmi_op_gen_gpio_output,
1579         /* .gen_bcn_tmpl not implemented */
1580         /* .gen_prb_tmpl not implemented */
1581         /* .gen_p2p_go_bcn_ie not implemented */
1582 @@ -10395,6 +10447,8 @@ static const struct wmi_ops wmi_10_4_ops
1583         .gen_pdev_bss_chan_info_req = ath10k_wmi_10_2_op_gen_pdev_bss_chan_info,
1584         .gen_echo = ath10k_wmi_op_gen_echo,
1585         .gen_pdev_get_tpc_config = ath10k_wmi_10_2_4_op_gen_pdev_get_tpc_config,
1586 +       .gen_gpio_config = ath10k_wmi_op_gen_gpio_config,
1587 +       .gen_gpio_output = ath10k_wmi_op_gen_gpio_output,
1588  };
1589  
1590  int ath10k_wmi_attach(struct ath10k *ar)
1591 --- a/ath10k-5.4/wmi.h
1592 +++ b/ath10k-5.4/wmi.h
1593 @@ -3110,6 +3110,41 @@ enum wmi_10_4_feature_mask {
1594  
1595  };
1596  
1597 +/* WMI_GPIO_CONFIG_CMDID */
1598 +enum {
1599 +       WMI_GPIO_PULL_NONE,
1600 +       WMI_GPIO_PULL_UP,
1601 +       WMI_GPIO_PULL_DOWN,
1602 +};
1603 +
1604 +enum {
1605 +       WMI_GPIO_INTTYPE_DISABLE,
1606 +       WMI_GPIO_INTTYPE_RISING_EDGE,
1607 +       WMI_GPIO_INTTYPE_FALLING_EDGE,
1608 +       WMI_GPIO_INTTYPE_BOTH_EDGE,
1609 +       WMI_GPIO_INTTYPE_LEVEL_LOW,
1610 +       WMI_GPIO_INTTYPE_LEVEL_HIGH
1611 +};
1612 +
1613 +/* WMI_GPIO_CONFIG_CMDID */
1614 +struct wmi_gpio_config_cmd {
1615 +       __le32 gpio_num;             /* GPIO number to be setup */
1616 +       __le32 input;                /* 0 - Output/ 1 - Input */
1617 +       __le32 pull_type;            /* Pull type defined above */
1618 +       __le32 intr_mode;            /* Interrupt mode defined above (Input) */
1619 +} __packed;
1620 +
1621 +/* WMI_GPIO_OUTPUT_CMDID */
1622 +struct wmi_gpio_output_cmd {
1623 +       __le32 gpio_num;    /* GPIO number to be setup */
1624 +       __le32 set;         /* Set the GPIO pin*/
1625 +} __packed;
1626 +
1627 +/* WMI_GPIO_INPUT_EVENTID */
1628 +struct wmi_gpio_input_event {
1629 +       __le32 gpio_num;    /* GPIO number which changed state */
1630 +} __packed;
1631 +
1632  struct wmi_ext_resource_config_10_4_cmd {
1633         /* contains enum wmi_host_platform_type */
1634         __le32 host_platform_config;