mach-cf-e316n-v2.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. /*
  2. * Support for COMFAST boards:
  3. * - CF-E316N v2 (AR9341)
  4. * - CF-E320N v2 (QCA9531)
  5. * - CF-E380AC v1/v2 (QCA9558)
  6. * - CF-E520N/CF-E530N (QCA9531)
  7. *
  8. * Copyright (C) 2016 Piotr Dymacz <pepe2k@gmail.com>
  9. * Copyright (C) 2016 Gareth Parker <gareth41@orcon.net.nz>
  10. * Copyright (C) 2015 Paul Fertser <fercerpav@gmail.com>
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License version 2 as published
  14. * by the Free Software Foundation.
  15. */
  16. #include <linux/gpio.h>
  17. #include <linux/platform_data/phy-at803x.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/timer.h>
  20. #include <asm/mach-ath79/ath79.h>
  21. #include <asm/mach-ath79/ar71xx_regs.h>
  22. #include "common.h"
  23. #include "dev-ap9x-pci.h"
  24. #include "dev-eth.h"
  25. #include "dev-gpio-buttons.h"
  26. #include "dev-leds-gpio.h"
  27. #include "dev-m25p80.h"
  28. #include "dev-wmac.h"
  29. #include "dev-usb.h"
  30. #include "machtypes.h"
  31. #define CF_EXXXN_KEYS_POLL_INTERVAL 20
  32. #define CF_EXXXN_KEYS_DEBOUNCE_INTERVAL (3 * CF_EXXXN_KEYS_POLL_INTERVAL)
  33. /* CF-E316N v2 */
  34. #define CF_E316N_V2_GPIO_LED_DIAG_B 0
  35. #define CF_E316N_V2_GPIO_LED_DIAG_R 2
  36. #define CF_E316N_V2_GPIO_LED_DIAG_G 3
  37. #define CF_E316N_V2_GPIO_LED_WLAN 12
  38. #define CF_E316N_V2_GPIO_LED_WAN 17
  39. #define CF_E316N_V2_GPIO_LED_LAN 19
  40. #define CF_E316N_V2_GPIO_EXT_WDT 16
  41. #define CF_E316N_V2_GPIO_EXTERNAL_PA0 13
  42. #define CF_E316N_V2_GPIO_EXTERNAL_PA1 14
  43. #define CF_E316N_V2_GPIO_BTN_RESET 20
  44. static struct gpio_led cf_e316n_v2_leds_gpio[] __initdata = {
  45. {
  46. .name = "cf-e316n-v2:blue:diag",
  47. .gpio = CF_E316N_V2_GPIO_LED_DIAG_B,
  48. .active_low = 0,
  49. }, {
  50. .name = "cf-e316n-v2:red:diag",
  51. .gpio = CF_E316N_V2_GPIO_LED_DIAG_R,
  52. .active_low = 0,
  53. }, {
  54. .name = "cf-e316n-v2:green:diag",
  55. .gpio = CF_E316N_V2_GPIO_LED_DIAG_G,
  56. .active_low = 0,
  57. }, {
  58. .name = "cf-e316n-v2:blue:wlan",
  59. .gpio = CF_E316N_V2_GPIO_LED_WLAN,
  60. .active_low = 1,
  61. }, {
  62. .name = "cf-e316n-v2:blue:wan",
  63. .gpio = CF_E316N_V2_GPIO_LED_WAN,
  64. .active_low = 1,
  65. }, {
  66. .name = "cf-e316n-v2:blue:lan",
  67. .gpio = CF_E316N_V2_GPIO_LED_LAN,
  68. .active_low = 1,
  69. },
  70. };
  71. static struct gpio_keys_button cf_e316n_v2_gpio_keys[] __initdata = {
  72. {
  73. .desc = "reset",
  74. .type = EV_KEY,
  75. .code = KEY_RESTART,
  76. .debounce_interval = CF_EXXXN_KEYS_DEBOUNCE_INTERVAL,
  77. .gpio = CF_E316N_V2_GPIO_BTN_RESET,
  78. .active_low = 1,
  79. },
  80. };
  81. /* CF-E320N v2 */
  82. #define CF_E320N_V2_GPIO_LED_WLAN 0
  83. #define CF_E320N_V2_GPIO_LED_WAN 2
  84. #define CF_E320N_V2_GPIO_LED_LAN 3
  85. #define CF_E320N_V2_GPIO_HEADER_J9_1 14
  86. #define CF_E320N_V2_GPIO_HEADER_J9_2 12
  87. #define CF_E320N_V2_GPIO_HEADER_J9_3 11
  88. #define CF_E320N_V2_GPIO_HEADER_J9_4 16
  89. #define CF_E320N_V2_GPIO_EXT_WDT 13
  90. #define CF_E320N_V2_GPIO_BTN_RESET 17
  91. static struct gpio_led cf_e320n_v2_leds_gpio[] __initdata = {
  92. {
  93. .name = "cf-e320n-v2:green:lan",
  94. .gpio = CF_E320N_V2_GPIO_LED_LAN,
  95. .active_low = 0,
  96. }, {
  97. .name = "cf-e320n-v2:red:wan",
  98. .gpio = CF_E320N_V2_GPIO_LED_WAN,
  99. .active_low = 0,
  100. }, {
  101. .name = "cf-e320n-v2:blue:wlan",
  102. .gpio = CF_E320N_V2_GPIO_LED_WLAN,
  103. .active_low = 0,
  104. },
  105. };
  106. static struct gpio_keys_button cf_e320n_v2_gpio_keys[] __initdata = {
  107. {
  108. .desc = "Reset button",
  109. .type = EV_KEY,
  110. .code = KEY_RESTART,
  111. .debounce_interval = CF_EXXXN_KEYS_DEBOUNCE_INTERVAL,
  112. .gpio = CF_E320N_V2_GPIO_BTN_RESET,
  113. .active_low = 1,
  114. },
  115. };
  116. /* CF-E380AC v1/v2 */
  117. #define CF_E380AC_V1V2_GPIO_LED_LAN 0
  118. #define CF_E380AC_V1V2_GPIO_LED_WLAN2G 2
  119. #define CF_E380AC_V1V2_GPIO_LED_WLAN5G 3
  120. #define CF_E380AC_V1V2_GPIO_EXT_WDT 17
  121. #define CF_E380AC_V1V2_GPIO_BTN_RESET 19
  122. static struct gpio_led cf_e380ac_v1_leds_gpio[] __initdata = {
  123. {
  124. .name = "cf-e380ac-v1:green:lan",
  125. .gpio = CF_E380AC_V1V2_GPIO_LED_LAN,
  126. .active_low = 0,
  127. }, {
  128. .name = "cf-e380ac-v1:blue:wlan2g",
  129. .gpio = CF_E380AC_V1V2_GPIO_LED_WLAN2G,
  130. .active_low = 0,
  131. }, {
  132. .name = "cf-e380ac-v1:red:wlan5g",
  133. .gpio = CF_E380AC_V1V2_GPIO_LED_WLAN5G,
  134. .active_low = 0,
  135. },
  136. };
  137. static struct gpio_led cf_e380ac_v2_leds_gpio[] __initdata = {
  138. {
  139. .name = "cf-e380ac-v2:green:lan",
  140. .gpio = CF_E380AC_V1V2_GPIO_LED_LAN,
  141. .active_low = 0,
  142. }, {
  143. .name = "cf-e380ac-v2:blue:wlan2g",
  144. .gpio = CF_E380AC_V1V2_GPIO_LED_WLAN2G,
  145. .active_low = 0,
  146. }, {
  147. .name = "cf-e380ac-v2:red:wlan5g",
  148. .gpio = CF_E380AC_V1V2_GPIO_LED_WLAN5G,
  149. .active_low = 0,
  150. },
  151. };
  152. static struct gpio_keys_button cf_e380ac_v1v2_gpio_keys[] __initdata = {
  153. {
  154. .desc = "Reset button",
  155. .type = EV_KEY,
  156. .code = KEY_RESTART,
  157. .debounce_interval = CF_EXXXN_KEYS_DEBOUNCE_INTERVAL,
  158. .gpio = CF_E380AC_V1V2_GPIO_BTN_RESET,
  159. .active_low = 1,
  160. },
  161. };
  162. static struct at803x_platform_data cf_e380ac_v1v2_at803x_data = {
  163. .disable_smarteee = 1,
  164. };
  165. static struct mdio_board_info cf_e380ac_v1v2_mdio0_info[] = {
  166. {
  167. .bus_id = "ag71xx-mdio.0",
  168. .phy_addr = 0,
  169. .platform_data = &cf_e380ac_v1v2_at803x_data,
  170. },
  171. };
  172. /* CF-E520N/CF-E530N */
  173. #define CF_E5X0N_GPIO_LED_WAN 11
  174. #define CF_E5X0N_GPIO_BTN_RESET 17
  175. static struct gpio_led cf_e520n_leds_gpio[] __initdata = {
  176. {
  177. .name = "cf-e520n:blue:wan",
  178. .gpio = CF_E5X0N_GPIO_LED_WAN,
  179. .active_low = 1,
  180. }
  181. };
  182. static struct gpio_led cf_e530n_leds_gpio[] __initdata = {
  183. {
  184. .name = "cf-e530n:blue:wan",
  185. .gpio = CF_E5X0N_GPIO_LED_WAN,
  186. .active_low = 1,
  187. }
  188. };
  189. /*
  190. * Some COMFAST devices include external hardware watchdog chip,
  191. * Pericon Technology PT7A7514, connected to a selected GPIO
  192. * and WiSoC RESET_L input. Watchdog time-out is ~1.6 s.
  193. */
  194. #define CF_EXXXN_EXT_WDT_TIMEOUT_MS 500
  195. static struct timer_list gpio_wdt_timer;
  196. static void gpio_wdt_toggle(unsigned long gpio)
  197. {
  198. static int state;
  199. state = !state;
  200. gpio_set_value(gpio, state);
  201. mod_timer(&gpio_wdt_timer,
  202. jiffies + msecs_to_jiffies(CF_EXXXN_EXT_WDT_TIMEOUT_MS));
  203. }
  204. static void __init cf_exxxn_common_setup(unsigned long art_ofs, int gpio_wdt)
  205. {
  206. u8 *art = (u8 *) KSEG1ADDR(0x1f001000 + art_ofs);
  207. if (gpio_wdt > -1) {
  208. gpio_request_one(gpio_wdt, GPIOF_OUT_INIT_HIGH,
  209. "PT7A7514 watchdog");
  210. setup_timer(&gpio_wdt_timer, gpio_wdt_toggle, gpio_wdt);
  211. gpio_wdt_toggle(gpio_wdt);
  212. }
  213. ath79_register_m25p80(NULL);
  214. ath79_register_wmac(art, NULL);
  215. ath79_register_usb();
  216. }
  217. static void __init cf_e316n_v2_setup(void)
  218. {
  219. u8 *mac = (u8 *) KSEG1ADDR(0x1f010000);
  220. cf_exxxn_common_setup(0x10000, CF_E316N_V2_GPIO_EXT_WDT);
  221. ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_PHY_SWAP);
  222. ath79_register_mdio(1, 0x0);
  223. /* GMAC0 is connected to the PHY0 of the internal switch */
  224. ath79_switch_data.phy4_mii_en = 1;
  225. ath79_switch_data.phy_poll_mask = BIT(0);
  226. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  227. ath79_eth0_data.phy_mask = BIT(0);
  228. ath79_eth0_data.mii_bus_dev = &ath79_mdio1_device.dev;
  229. ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
  230. ath79_register_eth(0);
  231. /* GMAC1 is connected to the internal switch */
  232. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
  233. ath79_init_mac(ath79_eth1_data.mac_addr, mac, 2);
  234. ath79_register_eth(1);
  235. /* Enable 2x Skyworks SE2576L WLAN power amplifiers */
  236. gpio_request_one(CF_E316N_V2_GPIO_EXTERNAL_PA0, GPIOF_OUT_INIT_HIGH,
  237. "WLAN PA0");
  238. gpio_request_one(CF_E316N_V2_GPIO_EXTERNAL_PA1, GPIOF_OUT_INIT_HIGH,
  239. "WLAN PA1");
  240. ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e316n_v2_leds_gpio),
  241. cf_e316n_v2_leds_gpio);
  242. ath79_register_gpio_keys_polled(1, CF_EXXXN_KEYS_POLL_INTERVAL,
  243. ARRAY_SIZE(cf_e316n_v2_gpio_keys),
  244. cf_e316n_v2_gpio_keys);
  245. }
  246. MIPS_MACHINE(ATH79_MACH_CF_E316N_V2, "CF-E316N-V2", "COMFAST CF-E316N v2",
  247. cf_e316n_v2_setup);
  248. static void __init cf_exxxn_qca953x_eth_setup(void)
  249. {
  250. u8 *mac = (u8 *) KSEG1ADDR(0x1f010000);
  251. ath79_setup_ar933x_phy4_switch(false, false);
  252. ath79_register_mdio(0, 0x0);
  253. ath79_switch_data.phy4_mii_en = 1;
  254. ath79_switch_data.phy_poll_mask |= BIT(4);
  255. /* LAN */
  256. ath79_eth1_data.duplex = DUPLEX_FULL;
  257. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
  258. ath79_eth1_data.speed = SPEED_1000;
  259. ath79_init_mac(ath79_eth1_data.mac_addr, mac, 2);
  260. ath79_register_eth(1);
  261. /* WAN */
  262. ath79_eth0_data.duplex = DUPLEX_FULL;
  263. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  264. ath79_eth0_data.speed = SPEED_100;
  265. ath79_eth0_data.phy_mask = BIT(4);
  266. ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
  267. ath79_register_eth(0);
  268. }
  269. static void __init cf_e320n_v2_setup(void)
  270. {
  271. cf_exxxn_common_setup(0x10000, CF_E320N_V2_GPIO_EXT_WDT);
  272. cf_exxxn_qca953x_eth_setup();
  273. /* Disable JTAG (enables GPIO0-3) */
  274. ath79_gpio_function_enable(AR934X_GPIO_FUNC_JTAG_DISABLE);
  275. ath79_gpio_direction_select(CF_E320N_V2_GPIO_LED_LAN, true);
  276. ath79_gpio_direction_select(CF_E320N_V2_GPIO_LED_WAN, true);
  277. ath79_gpio_direction_select(CF_E320N_V2_GPIO_LED_WLAN, true);
  278. ath79_gpio_output_select(CF_E320N_V2_GPIO_LED_LAN, 0);
  279. ath79_gpio_output_select(CF_E320N_V2_GPIO_LED_WAN, 0);
  280. ath79_gpio_output_select(CF_E320N_V2_GPIO_LED_WLAN, 0);
  281. /* Enable GPIO function for GPIOs in J9 header */
  282. ath79_gpio_output_select(CF_E320N_V2_GPIO_HEADER_J9_1, 0);
  283. ath79_gpio_output_select(CF_E320N_V2_GPIO_HEADER_J9_2, 0);
  284. ath79_gpio_output_select(CF_E320N_V2_GPIO_HEADER_J9_3, 0);
  285. ath79_gpio_output_select(CF_E320N_V2_GPIO_HEADER_J9_4, 0);
  286. ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e320n_v2_leds_gpio),
  287. cf_e320n_v2_leds_gpio);
  288. ath79_register_gpio_keys_polled(-1, CF_EXXXN_KEYS_POLL_INTERVAL,
  289. ARRAY_SIZE(cf_e320n_v2_gpio_keys),
  290. cf_e320n_v2_gpio_keys);
  291. }
  292. MIPS_MACHINE(ATH79_MACH_CF_E320N_V2, "CF-E320N-V2", "COMFAST CF-E320N v2",
  293. cf_e320n_v2_setup);
  294. static void __init cf_e380ac_v1v2_common_setup(unsigned long art_ofs)
  295. {
  296. u8 *mac = (u8 *) KSEG1ADDR(0x1f000000 + art_ofs);
  297. cf_exxxn_common_setup(art_ofs, CF_E380AC_V1V2_GPIO_EXT_WDT);
  298. ath79_setup_qca955x_eth_cfg(QCA955X_ETH_CFG_RGMII_EN);
  299. ath79_register_mdio(0, 0x0);
  300. mdiobus_register_board_info(cf_e380ac_v1v2_mdio0_info,
  301. ARRAY_SIZE(cf_e380ac_v1v2_mdio0_info));
  302. /* LAN */
  303. ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
  304. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  305. ath79_eth0_data.phy_mask = BIT(0);
  306. ath79_eth0_pll_data.pll_1000 = 0xbe000000;
  307. ath79_eth0_pll_data.pll_100 = 0xb0000101;
  308. ath79_eth0_pll_data.pll_10 = 0xb0001313;
  309. ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
  310. ath79_register_eth(0);
  311. ap91_pci_init(mac + 0x5000, NULL);
  312. /* Disable JTAG (enables GPIO0-3) */
  313. ath79_gpio_function_enable(AR934X_GPIO_FUNC_JTAG_DISABLE);
  314. ath79_gpio_direction_select(CF_E380AC_V1V2_GPIO_LED_LAN, true);
  315. ath79_gpio_direction_select(CF_E380AC_V1V2_GPIO_LED_WLAN2G, true);
  316. ath79_gpio_direction_select(CF_E380AC_V1V2_GPIO_LED_WLAN5G, true);
  317. ath79_gpio_output_select(CF_E380AC_V1V2_GPIO_LED_LAN, 0);
  318. ath79_gpio_output_select(CF_E380AC_V1V2_GPIO_LED_WLAN2G, 0);
  319. ath79_gpio_output_select(CF_E380AC_V1V2_GPIO_LED_WLAN5G, 0);
  320. /* For J7-4 */
  321. ath79_gpio_function_disable(AR934X_GPIO_FUNC_CLK_OBS4_EN);
  322. ath79_register_gpio_keys_polled(-1, CF_EXXXN_KEYS_POLL_INTERVAL,
  323. ARRAY_SIZE(cf_e380ac_v1v2_gpio_keys),
  324. cf_e380ac_v1v2_gpio_keys);
  325. }
  326. static void __init cf_e380ac_v1_setup(void)
  327. {
  328. cf_e380ac_v1v2_common_setup(0x20000);
  329. ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e380ac_v1_leds_gpio),
  330. cf_e380ac_v1_leds_gpio);
  331. }
  332. MIPS_MACHINE(ATH79_MACH_CF_E380AC_V1, "CF-E380AC-V1", "COMFAST CF-E380AC v1",
  333. cf_e380ac_v1_setup);
  334. static void __init cf_e380ac_v2_setup(void)
  335. {
  336. cf_e380ac_v1v2_common_setup(0x40000);
  337. ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e380ac_v2_leds_gpio),
  338. cf_e380ac_v2_leds_gpio);
  339. }
  340. MIPS_MACHINE(ATH79_MACH_CF_E380AC_V2, "CF-E380AC-V2", "COMFAST CF-E380AC v2",
  341. cf_e380ac_v2_setup);
  342. static void __init cf_e5x0n_gpio_setup(void)
  343. {
  344. ath79_gpio_direction_select(CF_E5X0N_GPIO_LED_WAN, true);
  345. ath79_gpio_output_select(CF_E5X0N_GPIO_LED_WAN, 0);
  346. ath79_register_gpio_keys_polled(-1, CF_EXXXN_KEYS_POLL_INTERVAL,
  347. ARRAY_SIZE(cf_e320n_v2_gpio_keys),
  348. cf_e320n_v2_gpio_keys);
  349. }
  350. static void __init cf_e520n_setup(void)
  351. {
  352. cf_exxxn_common_setup(0x10000, -1);
  353. cf_exxxn_qca953x_eth_setup();
  354. cf_e5x0n_gpio_setup();
  355. ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e520n_leds_gpio),
  356. cf_e520n_leds_gpio);
  357. }
  358. MIPS_MACHINE(ATH79_MACH_CF_E520N, "CF-E520N", "COMFAST CF-E520N",
  359. cf_e520n_setup);
  360. static void __init cf_e530n_setup(void)
  361. {
  362. cf_exxxn_common_setup(0x10000, -1);
  363. cf_exxxn_qca953x_eth_setup();
  364. cf_e5x0n_gpio_setup();
  365. ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e530n_leds_gpio),
  366. cf_e530n_leds_gpio);
  367. }
  368. MIPS_MACHINE(ATH79_MACH_CF_E530N, "CF-E530N", "COMFAST CF-E530N",
  369. cf_e530n_setup);