0083-ar71xx-WNR2200-enable-control-of-all-LEDs-and-buttons.patch 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. From: Matthias Schiffer <mschiffer@universe-factory.net>
  2. Date: Sun, 29 May 2016 11:50:03 +0200
  3. Subject: ar71xx: WNR2200: enable control of all LEDs and buttons
  4. This patch provides full GPIO support for WNR2200 (LEDs and buttons).
  5. It exposes all LEDs to operating system, including Ethernet ones.
  6. Signed-off-by: Michal Cieslakiewicz <michal.cieslakiewicz@wp.pl>
  7. Backport of r49101
  8. diff --git a/target/linux/ar71xx/base-files/etc/uci-defaults/01_leds b/target/linux/ar71xx/base-files/etc/uci-defaults/01_leds
  9. index 9a768cd..ae17853 100644
  10. --- a/target/linux/ar71xx/base-files/etc/uci-defaults/01_leds
  11. +++ b/target/linux/ar71xx/base-files/etc/uci-defaults/01_leds
  12. @@ -590,6 +590,21 @@ wnr2000-v4)
  13. ucidef_set_led_usbdev "usb" "USB" "netgear:amber:status" "1-1"
  14. ;;
  15. +wnr2200)
  16. + ucidef_set_led_netdev "wan-amber" "WAN (amber)" "netgear:amber:wan" "eth0"
  17. + ucidef_set_led_default "wan-green" "WAN (green)" "netgear:green:wan" "0"
  18. + ucidef_set_led_netdev "wlan" "WLAN" "netgear:blue:wlan" "wlan0"
  19. + ucidef_set_led_switch "lan1green" "LAN1 (green)" "netgear:green:lan1" "switch0" "0x02" "0x04"
  20. + ucidef_set_led_switch "lan2green" "LAN2 (green)" "netgear:green:lan2" "switch0" "0x04" "0x04"
  21. + ucidef_set_led_switch "lan3green" "LAN3 (green)" "netgear:green:lan3" "switch0" "0x08" "0x04"
  22. + ucidef_set_led_switch "lan4green" "LAN4 (green)" "netgear:green:lan4" "switch0" "0x10" "0x04"
  23. + ucidef_set_led_switch "lan1amber" "LAN1 (amber)" "netgear:amber:lan1" "switch0" "0x02" "0x02"
  24. + ucidef_set_led_switch "lan2amber" "LAN2 (amber)" "netgear:amber:lan2" "switch0" "0x04" "0x02"
  25. + ucidef_set_led_switch "lan3amber" "LAN3 (amber)" "netgear:amber:lan3" "switch0" "0x08" "0x02"
  26. + ucidef_set_led_switch "lan4amber" "LAN4 (amber)" "netgear:amber:lan4" "switch0" "0x10" "0x02"
  27. + ucidef_set_led_usbdev "usb" "USB" "netgear:green:usb" "1-1"
  28. + ;;
  29. +
  30. wpn824n)
  31. ucidef_set_led_netdev "wan-amber" "WAN (amber)" "netgear:amber:wan" "eth0"
  32. ucidef_set_led_wlan "wlan" "WLAN" "netgear:blue:wlan" "phy0tpt"
  33. diff --git a/target/linux/ar71xx/files/arch/mips/ath79/mach-wnr2200.c b/target/linux/ar71xx/files/arch/mips/ath79/mach-wnr2200.c
  34. index 37ffc4c..258d254 100644
  35. --- a/target/linux/ar71xx/files/arch/mips/ath79/mach-wnr2200.c
  36. +++ b/target/linux/ar71xx/files/arch/mips/ath79/mach-wnr2200.c
  37. @@ -15,6 +15,8 @@
  38. #include <linux/kernel.h> /* for max() macro */
  39. #include <asm/mach-ath79/ath79.h>
  40. +#include <asm/mach-ath79/ar71xx_regs.h> /* needed to disable switch LEDs */
  41. +#include "common.h" /* needed to disable switch LEDs */
  42. #include "dev-ap9x-pci.h"
  43. #include "dev-eth.h"
  44. @@ -24,21 +26,28 @@
  45. #include "dev-usb.h"
  46. #include "machtypes.h"
  47. +/* WNR2200 - connected through AR7241 */
  48. #define WNR2200_GPIO_LED_LAN2_AMBER 0
  49. #define WNR2200_GPIO_LED_LAN4_AMBER 1
  50. -#define WNR2200_GPIO_LED_WPS 5
  51. -#define WNR2200_GPIO_LED_WAN_GREEN 7
  52. -#define WNR2200_GPIO_LED_USB 8
  53. +#define WNR2200_GPIO_LED_LAN1_AMBER 6 /* AR724X_GPIO_FUNC_JTAG_DISABLE */
  54. +#define WNR2200_GPIO_LED_WPS_GREEN 7 /* AR724X_GPIO_FUNC_JTAG_DISABLE */
  55. +#define WNR2200_GPIO_LED_USB_GREEN 8 /* AR724X_GPIO_FUNC_JTAG_DISABLE */
  56. #define WNR2200_GPIO_LED_LAN3_AMBER 11
  57. #define WNR2200_GPIO_LED_WAN_AMBER 12
  58. -#define WNR2200_GPIO_LED_LAN1_GREEN 13
  59. -#define WNR2200_GPIO_LED_LAN2_GREEN 14
  60. -#define WNR2200_GPIO_LED_LAN3_GREEN 15
  61. -#define WNR2200_GPIO_LED_LAN4_GREEN 16
  62. -#define WNR2200_GPIO_LED_PWR_AMBER 21
  63. -#define WNR2200_GPIO_LED_PWR_GREEN 22
  64. -#define WNR2200_GPIO_USB_5V 4
  65. -#define WNR2200_GPIO_USB_POWER 24
  66. +#define WNR2200_GPIO_LED_LAN1_GREEN 13 /* AR724X_..._ETH_SWITCH_LED0 */
  67. +#define WNR2200_GPIO_LED_LAN2_GREEN 14 /* AR724X_..._ETH_SWITCH_LED1 */
  68. +#define WNR2200_GPIO_LED_LAN3_GREEN 15 /* AR724X_..._ETH_SWITCH_LED2 */
  69. +#define WNR2200_GPIO_LED_LAN4_GREEN 16 /* AR724X_..._ETH_SWITCH_LED3 */
  70. +#define WNR2200_GPIO_LED_WAN_GREEN 17 /* AR724X_..._ETH_SWITCH_LED4 */
  71. +
  72. +/* WNR2200 - connected through AR9287 */
  73. +#define WNR2200_GPIO_WMAC_LED_WLAN_BLUE 0
  74. +#define WNR2200_GPIO_WMAC_LED_TEST_AMBER 1
  75. +#define WNR2200_GPIO_WMAC_LED_POWER_GREEN 2
  76. +#define WNR2200_GPIO_WMAC_BTN_RFKILL 3
  77. +#define WNR2200_GPIO_WMAC_USB_5V 4
  78. +#define WNR2200_GPIO_WMAC_BTN_WPS 5
  79. +#define WNR2200_GPIO_WMAC_BTN_RESET 6
  80. #define WNR2200_KEYS_POLL_INTERVAL 20 /* msecs */
  81. #define WNR2200_KEYS_DEBOUNCE_INTERVAL (3 * WNR2200_KEYS_POLL_INTERVAL)
  82. @@ -50,30 +59,22 @@
  83. static struct gpio_led wnr2200_leds_gpio[] __initdata = {
  84. {
  85. - .name = "netgear:amber:lan2",
  86. - .gpio = WNR2200_GPIO_LED_LAN2_AMBER,
  87. - .active_low = 1,
  88. - }, {
  89. - .name = "netgear:amber:lan4",
  90. - .gpio = WNR2200_GPIO_LED_LAN4_AMBER,
  91. - .active_low = 1,
  92. - }, {
  93. - .name = "netgear:green:wps",
  94. - .gpio = WNR2200_GPIO_LED_WPS,
  95. - .active_low = 1,
  96. - }, {
  97. - .name = "netgear:green:wan",
  98. - .gpio = WNR2200_GPIO_LED_WAN_GREEN,
  99. + .name = "netgear:amber:lan1",
  100. + .gpio = WNR2200_GPIO_LED_LAN1_AMBER,
  101. .active_low = 1,
  102. }, {
  103. - .name = "netgear:green:usb",
  104. - .gpio = WNR2200_GPIO_LED_USB,
  105. + .name = "netgear:amber:lan2",
  106. + .gpio = WNR2200_GPIO_LED_LAN2_AMBER,
  107. .active_low = 1,
  108. }, {
  109. .name = "netgear:amber:lan3",
  110. .gpio = WNR2200_GPIO_LED_LAN3_AMBER,
  111. .active_low = 1,
  112. }, {
  113. + .name = "netgear:amber:lan4",
  114. + .gpio = WNR2200_GPIO_LED_LAN4_AMBER,
  115. + .active_low = 1,
  116. + }, {
  117. .name = "netgear:amber:wan",
  118. .gpio = WNR2200_GPIO_LED_WAN_AMBER,
  119. .active_low = 1,
  120. @@ -94,12 +95,56 @@ static struct gpio_led wnr2200_leds_gpio[] __initdata = {
  121. .gpio = WNR2200_GPIO_LED_LAN4_GREEN,
  122. .active_low = 1,
  123. }, {
  124. - .name = "netgear:amber:power",
  125. - .gpio = WNR2200_GPIO_LED_PWR_AMBER,
  126. + .name = "netgear:green:usb",
  127. + .gpio = WNR2200_GPIO_LED_USB_GREEN,
  128. + .active_low = 1,
  129. + }, {
  130. + .name = "netgear:green:wan",
  131. + .gpio = WNR2200_GPIO_LED_WAN_GREEN,
  132. + .active_low = 1,
  133. + }, {
  134. + .name = "netgear:green:wps",
  135. + .gpio = WNR2200_GPIO_LED_WPS_GREEN,
  136. + .active_low = 1,
  137. + }
  138. +};
  139. +
  140. +static const char *wnr2200_wmac_led_name = "netgear:blue:wlan";
  141. +
  142. +static struct gpio_led wnr2200_wmac_leds_gpio[] = {
  143. + {
  144. + .name = "netgear:amber:test",
  145. + .gpio = WNR2200_GPIO_WMAC_LED_TEST_AMBER,
  146. .active_low = 1,
  147. }, {
  148. .name = "netgear:green:power",
  149. - .gpio = WNR2200_GPIO_LED_PWR_GREEN,
  150. + .gpio = WNR2200_GPIO_WMAC_LED_POWER_GREEN,
  151. + .active_low = 1,
  152. + .default_state = LEDS_GPIO_DEFSTATE_ON,
  153. + }
  154. +};
  155. +
  156. +static struct gpio_keys_button wnr2200_wmac_keys_gpio[] = {
  157. + {
  158. + .desc = "reset",
  159. + .type = EV_KEY,
  160. + .code = KEY_RESTART,
  161. + .debounce_interval = WNR2200_KEYS_DEBOUNCE_INTERVAL,
  162. + .gpio = WNR2200_GPIO_WMAC_BTN_RESET,
  163. + .active_low = 1,
  164. + }, {
  165. + .desc = "rfkill",
  166. + .type = EV_KEY,
  167. + .code = KEY_RFKILL,
  168. + .debounce_interval = WNR2200_KEYS_DEBOUNCE_INTERVAL,
  169. + .gpio = WNR2200_GPIO_WMAC_BTN_RFKILL,
  170. + .active_low = 1,
  171. + }, {
  172. + .desc = "wps",
  173. + .type = EV_KEY,
  174. + .code = KEY_WPS_BUTTON,
  175. + .debounce_interval = WNR2200_KEYS_DEBOUNCE_INTERVAL,
  176. + .gpio = WNR2200_GPIO_WMAC_BTN_WPS,
  177. .active_low = 1,
  178. }
  179. };
  180. @@ -139,14 +184,32 @@ static void __init wnr2200_setup(void)
  181. u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
  182. u8 wlan_mac_addr[6];
  183. + /*
  184. + * Disable JTAG to use all AR724X GPIO LEDs. Disable CLKs.
  185. + * Allow OS to control all link LEDs.
  186. + */
  187. + ath79_gpio_function_setup(AR724X_GPIO_FUNC_JTAG_DISABLE |
  188. + AR724X_GPIO_FUNC_UART_EN,
  189. + AR724X_GPIO_FUNC_CLK_OBS1_EN |
  190. + AR724X_GPIO_FUNC_CLK_OBS2_EN |
  191. + AR724X_GPIO_FUNC_CLK_OBS3_EN |
  192. + AR724X_GPIO_FUNC_CLK_OBS4_EN |
  193. + AR724X_GPIO_FUNC_CLK_OBS5_EN |
  194. + AR724X_GPIO_FUNC_GE0_MII_CLK_EN |
  195. + AR724X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
  196. + AR724X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
  197. + AR724X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
  198. + AR724X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
  199. + AR724X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
  200. +
  201. ath79_register_mdio(0, 0x0);
  202. - ath79_init_mac(ath79_eth0_data.mac_addr, art+WNR2200_MAC0_OFFSET, 0);
  203. + ath79_init_mac(ath79_eth0_data.mac_addr, art + WNR2200_MAC0_OFFSET, 0);
  204. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  205. ath79_eth0_data.speed = SPEED_100;
  206. ath79_eth0_data.duplex = DUPLEX_FULL;
  207. - ath79_init_mac(ath79_eth1_data.mac_addr, art+WNR2200_MAC1_OFFSET, 0);
  208. + ath79_init_mac(ath79_eth1_data.mac_addr, art + WNR2200_MAC1_OFFSET, 0);
  209. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  210. ath79_eth1_data.phy_mask = 0x10;
  211. @@ -160,12 +223,22 @@ static void __init wnr2200_setup(void)
  212. ap91_pci_init(art + WNR2200_PCIE_CALDATA_OFFSET, wlan_mac_addr);
  213. ath79_register_leds_gpio(-1, ARRAY_SIZE(wnr2200_leds_gpio),
  214. - wnr2200_leds_gpio);
  215. + wnr2200_leds_gpio);
  216. +
  217. + ap9x_pci_setup_wmac_led_pin(0, WNR2200_GPIO_WMAC_LED_WLAN_BLUE);
  218. + ap9x_pci_setup_wmac_led_name(0, wnr2200_wmac_led_name);
  219. +
  220. + ap9x_pci_setup_wmac_leds(0, wnr2200_wmac_leds_gpio,
  221. + ARRAY_SIZE(wnr2200_wmac_leds_gpio));
  222. +
  223. + /* All 3 buttons are connected to wireless chip */
  224. + ap9x_pci_setup_wmac_btns(0, wnr2200_wmac_keys_gpio,
  225. + ARRAY_SIZE(wnr2200_wmac_keys_gpio),
  226. + WNR2200_KEYS_POLL_INTERVAL);
  227. /* enable power for the USB port */
  228. - ap9x_pci_setup_wmac_gpio(0,
  229. - BIT(WNR2200_GPIO_USB_5V),
  230. - BIT(WNR2200_GPIO_USB_5V));
  231. + ap9x_pci_setup_wmac_gpio(0, BIT(WNR2200_GPIO_WMAC_USB_5V),
  232. + BIT(WNR2200_GPIO_WMAC_USB_5V));
  233. ath79_register_usb();
  234. }