974-ath10k_add-LED-and-GPIO-controlling-support-for-various-chipsets.patch 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. From: Sebastian Gottschall <[email protected]>
  2. Adds LED and GPIO Control support for 988x, 9887, 9888, 99x0, 9984 based
  3. chipsets with on chipset connected led's using WMI Firmware API. The LED
  4. device will get available named as "ath10k-phyX" at sysfs and can be controlled
  5. with various triggers. adds also debugfs interface for gpio control.
  6. This patch is specific for OpenWRt base, as is use old backported package
  7. with old wireless source. Support for QCA9984 is removed and a simbol
  8. is added to local-simbol file to export the actually compile the code
  9. with the ATH10K_LEDS simbol.
  10. Signed-off-by: Sebastian Gottschall <[email protected]>
  11. Reviewed-by: Steve deRosier <[email protected]>
  12. [kvalo: major reorg and cleanup]
  13. Signed-off-by: Kalle Valo <[email protected]>
  14. Signed-off-by: Ansuel Smith <[email protected]>
  15. ---
  16. v13:
  17. * only compile tested!
  18. * fix all checkpatch warnings
  19. * fix commit log
  20. * sizeof(struct ath10k_gpiocontrol) -> sizeof(*gpio)
  21. * unsigned -> unsigned int
  22. * remove GPIOLIB code, that should be added in a separate patch
  23. * rename gpio.c to leds.c
  24. * add leds.h
  25. * rename some functions:
  26. ath10k_attach_led() -> ath10k_leds_register()
  27. ath10k_unregister_led() -> ath10k_leds_unregister()
  28. ath10k_reset_led_pin() -> ath10k_leds_start()
  29. * call ath10k_leds_unregister() before ath10k_thermal_unregister() to preserve ordering
  30. * call ath10k_leds_start() only from ath10k_core_start() and not from mac.c
  31. * rename struct ath10k_gpiocontrol as anonymous function under struct
  32. ath10k::leds, no need for memory allocation
  33. * merge ath10k_add_led() to ath10k_attach_led(), which is it's only caller
  34. * remove #if IS_ENABLED() checks from most of places, memory savings from those were not worth it
  35. * Kconfig help text improvement and move it lower in the menu, also don't enable it by default
  36. * switch to set_brightness_blocking() so that the callback can sleep,
  37. then no need to use ath10k_wmi_cmd_send_nowait() and can take mutex
  38. to access ar->state
  39. * don't touch ath10k_wmi_pdev_get_temperature()
  40. * as QCA6174/QCA9377 are not (yet) supported don't add the command to WMI-TLV interface
  41. * remove debugfs interface, that should be added in another patch
  42. * cleanup includes
  43. drivers/net/wireless/ath/ath10k/Kconfig | 10 +++
  44. drivers/net/wireless/ath/ath10k/Makefile | 1 +
  45. drivers/net/wireless/ath/ath10k/core.c | 22 +++++++
  46. drivers/net/wireless/ath/ath10k/core.h | 9 ++-
  47. drivers/net/wireless/ath/ath10k/hw.h | 1 +
  48. drivers/net/wireless/ath/ath10k/leds.c | 103 ++++++++++++++++++++++++++++++
  49. drivers/net/wireless/ath/ath10k/leds.h | 45 +++++++++++++
  50. drivers/net/wireless/ath/ath10k/mac.c | 1 +
  51. drivers/net/wireless/ath/ath10k/wmi-ops.h | 32 ++++++++++
  52. drivers/net/wireless/ath/ath10k/wmi-tlv.c | 2 +
  53. drivers/net/wireless/ath/ath10k/wmi.c | 54 ++++++++++++++++
  54. drivers/net/wireless/ath/ath10k/wmi.h | 35 ++++++++++
  55. 12 files changed, 314 insertions(+), 1 deletion(-)
  56. create mode 100644 drivers/net/wireless/ath/ath10k/leds.c
  57. create mode 100644 drivers/net/wireless/ath/ath10k/leds.h
  58. --- a/drivers/net/wireless/ath/ath10k/Kconfig
  59. +++ b/drivers/net/wireless/ath/ath10k/Kconfig
  60. @@ -69,6 +69,16 @@ config ATH10K_DEBUGFS
  61. If unsure, say Y to make it easier to debug problems.
  62. +config ATH10K_LEDS
  63. + bool "Atheros ath10k LED support"
  64. + depends on ATH10K
  65. + select MAC80211_LEDS
  66. + select LEDS_CLASS
  67. + select NEW_LEDS
  68. + default y
  69. + ---help---
  70. + This option is necessary, if you want LED support for chipset connected led pins. If unsure, say N.
  71. +
  72. config ATH10K_SPECTRAL
  73. bool "Atheros ath10k spectral scan support"
  74. depends on ATH10K_DEBUGFS
  75. --- a/drivers/net/wireless/ath/ath10k/Makefile
  76. +++ b/drivers/net/wireless/ath/ath10k/Makefile
  77. @@ -19,6 +19,7 @@ ath10k_core-$(CPTCFG_ATH10K_SPECTRAL) +=
  78. ath10k_core-$(CPTCFG_NL80211_TESTMODE) += testmode.o
  79. ath10k_core-$(CPTCFG_ATH10K_TRACING) += trace.o
  80. ath10k_core-$(CPTCFG_ATH10K_THERMAL) += thermal.o
  81. +ath10k_core-$(CPTCFG_ATH10K_LEDS) += leds.o
  82. ath10k_core-$(CPTCFG_MAC80211_DEBUGFS) += debugfs_sta.o
  83. ath10k_core-$(CONFIG_PM) += wow.o
  84. ath10k_core-$(CONFIG_DEV_COREDUMP) += coredump.o
  85. --- a/local-symbols
  86. +++ b/local-symbols
  87. @@ -143,6 +143,7 @@ ATH10K_DEBUG=
  88. ATH10K_DEBUGFS=
  89. ATH10K_SPECTRAL=
  90. ATH10K_THERMAL=
  91. +ATH10K_LEDS=
  92. ATH10K_TRACING=
  93. ATH10K_DFS_CERTIFIED=
  94. WCN36XX=
  95. --- a/drivers/net/wireless/ath/ath10k/core.c
  96. +++ b/drivers/net/wireless/ath/ath10k/core.c
  97. @@ -34,6 +34,7 @@
  98. #include "testmode.h"
  99. #include "wmi-ops.h"
  100. #include "coredump.h"
  101. +#include "leds.h"
  102. unsigned int ath10k_debug_mask;
  103. static unsigned int ath10k_cryptmode_param;
  104. @@ -64,6 +65,7 @@ static const struct ath10k_hw_params ath
  105. .id = QCA988X_HW_2_0_VERSION,
  106. .dev_id = QCA988X_2_0_DEVICE_ID,
  107. .name = "qca988x hw2.0",
  108. + .led_pin = 1,
  109. .patch_load_addr = QCA988X_HW_2_0_PATCH_LOAD_ADDR,
  110. .uart_pin = 7,
  111. .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_ALL,
  112. @@ -129,6 +131,7 @@ static const struct ath10k_hw_params ath
  113. .id = QCA9887_HW_1_0_VERSION,
  114. .dev_id = QCA9887_1_0_DEVICE_ID,
  115. .name = "qca9887 hw1.0",
  116. + .led_pin = 1,
  117. .patch_load_addr = QCA9887_HW_1_0_PATCH_LOAD_ADDR,
  118. .uart_pin = 7,
  119. .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_ALL,
  120. @@ -293,6 +296,7 @@ static const struct ath10k_hw_params ath
  121. .id = QCA99X0_HW_2_0_DEV_VERSION,
  122. .dev_id = QCA99X0_2_0_DEVICE_ID,
  123. .name = "qca99x0 hw2.0",
  124. + .led_pin = 17,
  125. .patch_load_addr = QCA99X0_HW_2_0_PATCH_LOAD_ADDR,
  126. .uart_pin = 7,
  127. .otp_exe_param = 0x00000700,
  128. @@ -331,6 +335,7 @@ static const struct ath10k_hw_params ath
  129. .id = QCA9984_HW_1_0_DEV_VERSION,
  130. .dev_id = QCA9984_1_0_DEVICE_ID,
  131. .name = "qca9984/qca9994 hw1.0",
  132. + .led_pin = 17,
  133. .patch_load_addr = QCA9984_HW_1_0_PATCH_LOAD_ADDR,
  134. .uart_pin = 7,
  135. .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_EACH,
  136. @@ -374,6 +379,7 @@ static const struct ath10k_hw_params ath
  137. .id = QCA9888_HW_2_0_DEV_VERSION,
  138. .dev_id = QCA9888_2_0_DEVICE_ID,
  139. .name = "qca9888 hw2.0",
  140. + .led_pin = 17,
  141. .patch_load_addr = QCA9888_HW_2_0_PATCH_LOAD_ADDR,
  142. .uart_pin = 7,
  143. .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_EACH,
  144. @@ -2440,6 +2446,10 @@ int ath10k_core_start(struct ath10k *ar,
  145. if (status)
  146. goto err_hif_stop;
  147. + status = ath10k_leds_start(ar);
  148. + if (status)
  149. + goto err_hif_stop;
  150. +
  151. return 0;
  152. err_hif_stop:
  153. @@ -2694,9 +2704,18 @@ static void ath10k_core_register_work(st
  154. goto err_spectral_destroy;
  155. }
  156. + status = ath10k_leds_register(ar);
  157. + if (status) {
  158. + ath10k_err(ar, "could not register leds: %d\n",
  159. + status);
  160. + goto err_thermal_unregister;
  161. + }
  162. +
  163. set_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags);
  164. return;
  165. +err_thermal_unregister:
  166. + ath10k_thermal_unregister(ar);
  167. err_spectral_destroy:
  168. ath10k_spectral_destroy(ar);
  169. err_debug_destroy:
  170. @@ -2740,6 +2759,8 @@ void ath10k_core_unregister(struct ath10
  171. if (!test_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags))
  172. return;
  173. + ath10k_leds_unregister(ar);
  174. +
  175. ath10k_thermal_unregister(ar);
  176. /* Stop spectral before unregistering from mac80211 to remove the
  177. * relayfs debugfs file cleanly. Otherwise the parent debugfs tree
  178. --- a/drivers/net/wireless/ath/ath10k/core.h
  179. +++ b/drivers/net/wireless/ath/ath10k/core.h
  180. @@ -25,6 +25,7 @@
  181. #include <linux/pci.h>
  182. #include <linux/uuid.h>
  183. #include <linux/time.h>
  184. +#include <linux/leds.h>
  185. #include "htt.h"
  186. #include "htc.h"
  187. @@ -908,7 +909,6 @@ struct ath10k {
  188. u32 low_5ghz_chan;
  189. u32 high_5ghz_chan;
  190. bool ani_enabled;
  191. -
  192. bool p2p;
  193. struct {
  194. @@ -1099,6 +1099,13 @@ struct ath10k {
  195. } testmode;
  196. struct {
  197. + struct gpio_led wifi_led;
  198. + struct led_classdev cdev;
  199. + char label[48];
  200. + u32 gpio_state_pin;
  201. + } leds;
  202. +
  203. + struct {
  204. /* protected by data_lock */
  205. u32 fw_crash_counter;
  206. u32 fw_warm_reset_counter;
  207. --- a/drivers/net/wireless/ath/ath10k/hw.h
  208. +++ b/drivers/net/wireless/ath/ath10k/hw.h
  209. @@ -504,6 +504,7 @@ struct ath10k_hw_params {
  210. const char *name;
  211. u32 patch_load_addr;
  212. int uart_pin;
  213. + int led_pin;
  214. u32 otp_exe_param;
  215. /* Type of hw cycle counter wraparound logic, for more info
  216. --- /dev/null
  217. +++ b/drivers/net/wireless/ath/ath10k/leds.c
  218. @@ -0,0 +1,103 @@
  219. +/*
  220. + * Copyright (c) 2005-2011 Atheros Communications Inc.
  221. + * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
  222. + * Copyright (c) 2018 Sebastian Gottschall <[email protected]>
  223. + * Copyright (c) 2018, The Linux Foundation. All rights reserved.
  224. + *
  225. + * Permission to use, copy, modify, and/or distribute this software for any
  226. + * purpose with or without fee is hereby granted, provided that the above
  227. + * copyright notice and this permission notice appear in all copies.
  228. + *
  229. + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  230. + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  231. + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  232. + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  233. + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  234. + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  235. + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  236. + */
  237. +
  238. +#include <linux/leds.h>
  239. +
  240. +#include "core.h"
  241. +#include "wmi.h"
  242. +#include "wmi-ops.h"
  243. +
  244. +#include "leds.h"
  245. +
  246. +static int ath10k_leds_set_brightness_blocking(struct led_classdev *led_cdev,
  247. + enum led_brightness brightness)
  248. +{
  249. + struct ath10k *ar = container_of(led_cdev, struct ath10k,
  250. + leds.cdev);
  251. + struct gpio_led *led = &ar->leds.wifi_led;
  252. +
  253. + mutex_lock(&ar->conf_mutex);
  254. +
  255. + if (ar->state != ATH10K_STATE_ON)
  256. + goto out;
  257. +
  258. + ar->leds.gpio_state_pin = (brightness != LED_OFF) ^ led->active_low;
  259. + ath10k_wmi_gpio_output(ar, led->gpio, ar->leds.gpio_state_pin);
  260. +
  261. +out:
  262. + mutex_unlock(&ar->conf_mutex);
  263. +
  264. + return 0;
  265. +}
  266. +
  267. +int ath10k_leds_start(struct ath10k *ar)
  268. +{
  269. + if (ar->hw_params.led_pin == 0)
  270. + /* leds not supported */
  271. + return 0;
  272. +
  273. + /* under some circumstances, the gpio pin gets reconfigured
  274. + * to default state by the firmware, so we need to
  275. + * reconfigure it this behaviour has only ben seen on
  276. + * QCA9984 and QCA99XX devices so far
  277. + */
  278. + ath10k_wmi_gpio_config(ar, ar->hw_params.led_pin, 0,
  279. + WMI_GPIO_PULL_NONE, WMI_GPIO_INTTYPE_DISABLE);
  280. + ath10k_wmi_gpio_output(ar, ar->hw_params.led_pin, 1);
  281. +
  282. + return 0;
  283. +}
  284. +
  285. +int ath10k_leds_register(struct ath10k *ar)
  286. +{
  287. + int ret;
  288. +
  289. + if (ar->hw_params.led_pin == 0)
  290. + /* leds not supported */
  291. + return 0;
  292. +
  293. + snprintf(ar->leds.label, sizeof(ar->leds.label), "ath10k-%s",
  294. + wiphy_name(ar->hw->wiphy));
  295. + ar->leds.wifi_led.active_low = 1;
  296. + ar->leds.wifi_led.gpio = ar->hw_params.led_pin;
  297. + ar->leds.wifi_led.name = ar->leds.label;
  298. + ar->leds.wifi_led.default_state = LEDS_GPIO_DEFSTATE_KEEP;
  299. +
  300. + ar->leds.cdev.name = ar->leds.label;
  301. + ar->leds.cdev.brightness_set_blocking = ath10k_leds_set_brightness_blocking;
  302. +
  303. + /* FIXME: this assignment doesn't make sense as it's NULL, remove it? */
  304. + ar->leds.cdev.default_trigger = ar->leds.wifi_led.default_trigger;
  305. +
  306. + ret = led_classdev_register(wiphy_dev(ar->hw->wiphy), &ar->leds.cdev);
  307. + if (ret)
  308. + return ret;
  309. +
  310. + return 0;
  311. +}
  312. +
  313. +void ath10k_leds_unregister(struct ath10k *ar)
  314. +{
  315. + if (ar->hw_params.led_pin == 0)
  316. + /* leds not supported */
  317. + return;
  318. +
  319. + led_classdev_unregister(&ar->leds.cdev);
  320. +}
  321. +
  322. --- /dev/null
  323. +++ b/drivers/net/wireless/ath/ath10k/leds.h
  324. @@ -0,0 +1,41 @@
  325. +/*
  326. + * Copyright (c) 2018, The Linux Foundation. All rights reserved.
  327. + *
  328. + * Permission to use, copy, modify, and/or distribute this software for any
  329. + * purpose with or without fee is hereby granted, provided that the above
  330. + * copyright notice and this permission notice appear in all copies.
  331. + *
  332. + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  333. + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  334. + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  335. + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  336. + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  337. + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  338. + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  339. + */
  340. +#ifndef _LEDS_H_
  341. +#define _LEDS_H_
  342. +
  343. +#include "core.h"
  344. +
  345. +#ifdef CPTCFG_ATH10K_LEDS
  346. +void ath10k_leds_unregister(struct ath10k *ar);
  347. +int ath10k_leds_start(struct ath10k *ar);
  348. +int ath10k_leds_register(struct ath10k *ar);
  349. +#else
  350. +static inline void ath10k_leds_unregister(struct ath10k *ar)
  351. +{
  352. +}
  353. +
  354. +static inline int ath10k_leds_start(struct ath10k *ar)
  355. +{
  356. + return 0;
  357. +}
  358. +
  359. +static inline int ath10k_leds_register(struct ath10k *ar)
  360. +{
  361. + return 0;
  362. +}
  363. +
  364. +#endif
  365. +#endif /* _LEDS_H_ */
  366. --- a/drivers/net/wireless/ath/ath10k/mac.c
  367. +++ b/drivers/net/wireless/ath/ath10k/mac.c
  368. @@ -33,6 +33,7 @@
  369. #include "wmi-tlv.h"
  370. #include "wmi-ops.h"
  371. #include "wow.h"
  372. +#include "leds.h"
  373. /*********/
  374. /* Rates */
  375. --- a/drivers/net/wireless/ath/ath10k/wmi-ops.h
  376. +++ b/drivers/net/wireless/ath/ath10k/wmi-ops.h
  377. @@ -216,7 +216,10 @@ struct wmi_ops {
  378. struct sk_buff *(*gen_echo)(struct ath10k *ar, u32 value);
  379. struct sk_buff *(*gen_pdev_get_tpc_table_cmdid)(struct ath10k *ar,
  380. u32 param);
  381. + struct sk_buff *(*gen_gpio_config)(struct ath10k *ar, u32 gpio_num,
  382. + u32 input, u32 pull_type, u32 intr_mode);
  383. + struct sk_buff *(*gen_gpio_output)(struct ath10k *ar, u32 gpio_num, u32 set);
  384. };
  385. int ath10k_wmi_cmd_send(struct ath10k *ar, struct sk_buff *skb, u32 cmd_id);
  386. @@ -1054,6 +1057,35 @@ ath10k_wmi_force_fw_hang(struct ath10k *
  387. return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->force_fw_hang_cmdid);
  388. }
  389. +static inline int ath10k_wmi_gpio_config(struct ath10k *ar, u32 gpio_num,
  390. + u32 input, u32 pull_type, u32 intr_mode)
  391. +{
  392. + struct sk_buff *skb;
  393. +
  394. + if (!ar->wmi.ops->gen_gpio_config)
  395. + return -EOPNOTSUPP;
  396. +
  397. + skb = ar->wmi.ops->gen_gpio_config(ar, gpio_num, input, pull_type, intr_mode);
  398. + if (IS_ERR(skb))
  399. + return PTR_ERR(skb);
  400. +
  401. + return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->gpio_config_cmdid);
  402. +}
  403. +
  404. +static inline int ath10k_wmi_gpio_output(struct ath10k *ar, u32 gpio_num, u32 set)
  405. +{
  406. + struct sk_buff *skb;
  407. +
  408. + if (!ar->wmi.ops->gen_gpio_config)
  409. + return -EOPNOTSUPP;
  410. +
  411. + skb = ar->wmi.ops->gen_gpio_output(ar, gpio_num, set);
  412. + if (IS_ERR(skb))
  413. + return PTR_ERR(skb);
  414. +
  415. + return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->gpio_output_cmdid);
  416. +}
  417. +
  418. static inline int
  419. ath10k_wmi_dbglog_cfg(struct ath10k *ar, u64 module_enable, u32 log_level)
  420. {
  421. --- a/drivers/net/wireless/ath/ath10k/wmi-tlv.c
  422. +++ b/drivers/net/wireless/ath/ath10k/wmi-tlv.c
  423. @@ -3976,6 +3976,8 @@ static const struct wmi_ops wmi_tlv_ops
  424. .gen_echo = ath10k_wmi_tlv_op_gen_echo,
  425. .gen_vdev_spectral_conf = ath10k_wmi_tlv_op_gen_vdev_spectral_conf,
  426. .gen_vdev_spectral_enable = ath10k_wmi_tlv_op_gen_vdev_spectral_enable,
  427. + /* .gen_gpio_config not implemented */
  428. + /* .gen_gpio_output not implemented */
  429. };
  430. static const struct wmi_peer_flags_map wmi_tlv_peer_flags_map = {
  431. --- a/drivers/net/wireless/ath/ath10k/wmi.c
  432. +++ b/drivers/net/wireless/ath/ath10k/wmi.c
  433. @@ -7166,6 +7166,49 @@ ath10k_wmi_op_gen_peer_set_param(struct
  434. return skb;
  435. }
  436. +static struct sk_buff *ath10k_wmi_op_gen_gpio_config(struct ath10k *ar,
  437. + u32 gpio_num, u32 input,
  438. + u32 pull_type, u32 intr_mode)
  439. +{
  440. + struct wmi_gpio_config_cmd *cmd;
  441. + struct sk_buff *skb;
  442. +
  443. + skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
  444. + if (!skb)
  445. + return ERR_PTR(-ENOMEM);
  446. +
  447. + cmd = (struct wmi_gpio_config_cmd *)skb->data;
  448. + cmd->pull_type = __cpu_to_le32(pull_type);
  449. + cmd->gpio_num = __cpu_to_le32(gpio_num);
  450. + cmd->input = __cpu_to_le32(input);
  451. + cmd->intr_mode = __cpu_to_le32(intr_mode);
  452. +
  453. + 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",
  454. + gpio_num, input, pull_type, intr_mode);
  455. +
  456. + return skb;
  457. +}
  458. +
  459. +static struct sk_buff *ath10k_wmi_op_gen_gpio_output(struct ath10k *ar,
  460. + u32 gpio_num, u32 set)
  461. +{
  462. + struct wmi_gpio_output_cmd *cmd;
  463. + struct sk_buff *skb;
  464. +
  465. + skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
  466. + if (!skb)
  467. + return ERR_PTR(-ENOMEM);
  468. +
  469. + cmd = (struct wmi_gpio_output_cmd *)skb->data;
  470. + cmd->gpio_num = __cpu_to_le32(gpio_num);
  471. + cmd->set = __cpu_to_le32(set);
  472. +
  473. + ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi gpio_output gpio_num 0x%08x set 0x%08x\n",
  474. + gpio_num, set);
  475. +
  476. + return skb;
  477. +}
  478. +
  479. static struct sk_buff *
  480. ath10k_wmi_op_gen_set_psmode(struct ath10k *ar, u32 vdev_id,
  481. enum wmi_sta_ps_mode psmode)
  482. @@ -8777,6 +8820,9 @@ static const struct wmi_ops wmi_ops = {
  483. .fw_stats_fill = ath10k_wmi_main_op_fw_stats_fill,
  484. .get_vdev_subtype = ath10k_wmi_op_get_vdev_subtype,
  485. .gen_echo = ath10k_wmi_op_gen_echo,
  486. + .gen_gpio_config = ath10k_wmi_op_gen_gpio_config,
  487. + .gen_gpio_output = ath10k_wmi_op_gen_gpio_output,
  488. +
  489. /* .gen_bcn_tmpl not implemented */
  490. /* .gen_prb_tmpl not implemented */
  491. /* .gen_p2p_go_bcn_ie not implemented */
  492. @@ -8847,6 +8893,8 @@ static const struct wmi_ops wmi_10_1_ops
  493. .fw_stats_fill = ath10k_wmi_10x_op_fw_stats_fill,
  494. .get_vdev_subtype = ath10k_wmi_op_get_vdev_subtype,
  495. .gen_echo = ath10k_wmi_op_gen_echo,
  496. + .gen_gpio_config = ath10k_wmi_op_gen_gpio_config,
  497. + .gen_gpio_output = ath10k_wmi_op_gen_gpio_output,
  498. /* .gen_bcn_tmpl not implemented */
  499. /* .gen_prb_tmpl not implemented */
  500. /* .gen_p2p_go_bcn_ie not implemented */
  501. @@ -8918,6 +8966,8 @@ static const struct wmi_ops wmi_10_2_ops
  502. .gen_delba_send = ath10k_wmi_op_gen_delba_send,
  503. .fw_stats_fill = ath10k_wmi_10x_op_fw_stats_fill,
  504. .get_vdev_subtype = ath10k_wmi_op_get_vdev_subtype,
  505. + .gen_gpio_config = ath10k_wmi_op_gen_gpio_config,
  506. + .gen_gpio_output = ath10k_wmi_op_gen_gpio_output,
  507. /* .gen_pdev_enable_adaptive_cca not implemented */
  508. };
  509. @@ -8988,6 +9038,8 @@ static const struct wmi_ops wmi_10_2_4_o
  510. .gen_pdev_enable_adaptive_cca =
  511. ath10k_wmi_op_gen_pdev_enable_adaptive_cca,
  512. .get_vdev_subtype = ath10k_wmi_10_2_4_op_get_vdev_subtype,
  513. + .gen_gpio_config = ath10k_wmi_op_gen_gpio_config,
  514. + .gen_gpio_output = ath10k_wmi_op_gen_gpio_output,
  515. /* .gen_bcn_tmpl not implemented */
  516. /* .gen_prb_tmpl not implemented */
  517. /* .gen_p2p_go_bcn_ie not implemented */
  518. @@ -9067,6 +9119,8 @@ static const struct wmi_ops wmi_10_4_ops
  519. .gen_pdev_bss_chan_info_req = ath10k_wmi_10_2_op_gen_pdev_bss_chan_info,
  520. .gen_echo = ath10k_wmi_op_gen_echo,
  521. .gen_pdev_get_tpc_config = ath10k_wmi_10_2_4_op_gen_pdev_get_tpc_config,
  522. + .gen_gpio_config = ath10k_wmi_op_gen_gpio_config,
  523. + .gen_gpio_output = ath10k_wmi_op_gen_gpio_output,
  524. };
  525. int ath10k_wmi_attach(struct ath10k *ar)
  526. --- a/drivers/net/wireless/ath/ath10k/wmi.h
  527. +++ b/drivers/net/wireless/ath/ath10k/wmi.h
  528. @@ -2942,6 +2942,41 @@ enum wmi_10_4_feature_mask {
  529. };
  530. +/* WMI_GPIO_CONFIG_CMDID */
  531. +enum {
  532. + WMI_GPIO_PULL_NONE,
  533. + WMI_GPIO_PULL_UP,
  534. + WMI_GPIO_PULL_DOWN,
  535. +};
  536. +
  537. +enum {
  538. + WMI_GPIO_INTTYPE_DISABLE,
  539. + WMI_GPIO_INTTYPE_RISING_EDGE,
  540. + WMI_GPIO_INTTYPE_FALLING_EDGE,
  541. + WMI_GPIO_INTTYPE_BOTH_EDGE,
  542. + WMI_GPIO_INTTYPE_LEVEL_LOW,
  543. + WMI_GPIO_INTTYPE_LEVEL_HIGH
  544. +};
  545. +
  546. +/* WMI_GPIO_CONFIG_CMDID */
  547. +struct wmi_gpio_config_cmd {
  548. + __le32 gpio_num; /* GPIO number to be setup */
  549. + __le32 input; /* 0 - Output/ 1 - Input */
  550. + __le32 pull_type; /* Pull type defined above */
  551. + __le32 intr_mode; /* Interrupt mode defined above (Input) */
  552. +} __packed;
  553. +
  554. +/* WMI_GPIO_OUTPUT_CMDID */
  555. +struct wmi_gpio_output_cmd {
  556. + __le32 gpio_num; /* GPIO number to be setup */
  557. + __le32 set; /* Set the GPIO pin*/
  558. +} __packed;
  559. +
  560. +/* WMI_GPIO_INPUT_EVENTID */
  561. +struct wmi_gpio_input_event {
  562. + __le32 gpio_num; /* GPIO number which changed state */
  563. +} __packed;
  564. +
  565. struct wmi_ext_resource_config_10_4_cmd {
  566. /* contains enum wmi_host_platform_type */
  567. __le32 host_platform_config;