mach-om2p.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. /*
  2. * OpenMesh OM2P support
  3. *
  4. * Copyright (C) 2011 Marek Lindner <marek@open-mesh.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published
  8. * by the Free Software Foundation.
  9. */
  10. #include <linux/gpio.h>
  11. #include <linux/mtd/mtd.h>
  12. #include <linux/mtd/partitions.h>
  13. #include <linux/platform_device.h>
  14. #include <asm/mach-ath79/ar71xx_regs.h>
  15. #include <asm/mach-ath79/ath79.h>
  16. #include "common.h"
  17. #include "dev-ap9x-pci.h"
  18. #include "dev-eth.h"
  19. #include "dev-gpio-buttons.h"
  20. #include "dev-leds-gpio.h"
  21. #include "dev-m25p80.h"
  22. #include "dev-wmac.h"
  23. #include "machtypes.h"
  24. #define OM2P_GPIO_LED_POWER 0
  25. #define OM2P_GPIO_LED_GREEN 13
  26. #define OM2P_GPIO_LED_RED 14
  27. #define OM2P_GPIO_LED_YELLOW 15
  28. #define OM2P_GPIO_LED_LAN 16
  29. #define OM2P_GPIO_LED_WAN 17
  30. #define OM2P_GPIO_BTN_RESET 1
  31. #define OM2P_KEYS_POLL_INTERVAL 20 /* msecs */
  32. #define OM2P_KEYS_DEBOUNCE_INTERVAL (3 * OM2P_KEYS_POLL_INTERVAL)
  33. #define OM2P_WAN_PHYMASK BIT(4)
  34. #define OM2P_LC_GPIO_LED_POWER 1
  35. #define OM2P_LC_GPIO_LED_GREEN 15
  36. #define OM2P_LC_GPIO_LED_RED 16
  37. #define OM2P_LC_GPIO_LED_YELLOW 0
  38. #define OM2P_LC_GPIO_LED_LAN 13
  39. #define OM2P_LC_GPIO_LED_WAN 17
  40. #define OM2P_LC_GPIO_BTN_RESET 12
  41. #define OM2Pv4_GPIO_LED_POWER 0
  42. #define OM2Pv4_GPIO_LED_GREEN 2
  43. #define OM2Pv4_GPIO_LED_RED 4
  44. #define OM2Pv4_GPIO_LED_YELLOW 3
  45. #define OM2Pv4_GPIO_LED_LAN 14
  46. #define OM2Pv4_GPIO_LED_WAN 13
  47. #define OM2Pv4_GPIO_BTN_RESET 1
  48. #define OM2P_WMAC_CALDATA_OFFSET 0x1000
  49. static struct flash_platform_data om2p_flash_data = {
  50. .type = "s25sl12800",
  51. .name = "ar7240-nor0",
  52. };
  53. static struct gpio_led om2p_leds_gpio[] __initdata = {
  54. {
  55. .name = "om2p:blue:power",
  56. .gpio = OM2P_GPIO_LED_POWER,
  57. .active_low = 1,
  58. }, {
  59. .name = "om2p:red:wifi",
  60. .gpio = OM2P_GPIO_LED_RED,
  61. .active_low = 1,
  62. }, {
  63. .name = "om2p:yellow:wifi",
  64. .gpio = OM2P_GPIO_LED_YELLOW,
  65. .active_low = 1,
  66. }, {
  67. .name = "om2p:green:wifi",
  68. .gpio = OM2P_GPIO_LED_GREEN,
  69. .active_low = 1,
  70. }, {
  71. .name = "om2p:blue:lan",
  72. .gpio = OM2P_GPIO_LED_LAN,
  73. .active_low = 1,
  74. }, {
  75. .name = "om2p:blue:wan",
  76. .gpio = OM2P_GPIO_LED_WAN,
  77. .active_low = 1,
  78. }
  79. };
  80. static struct gpio_keys_button om2p_gpio_keys[] __initdata = {
  81. {
  82. .desc = "reset",
  83. .type = EV_KEY,
  84. .code = KEY_RESTART,
  85. .debounce_interval = OM2P_KEYS_DEBOUNCE_INTERVAL,
  86. .gpio = OM2P_GPIO_BTN_RESET,
  87. .active_low = 1,
  88. }
  89. };
  90. static void __init om2p_setup(void)
  91. {
  92. u8 *mac1 = (u8 *)KSEG1ADDR(0x1ffc0000);
  93. u8 *mac2 = (u8 *)KSEG1ADDR(0x1ffc0000 + ETH_ALEN);
  94. u8 *ee = (u8 *)KSEG1ADDR(0x1ffc1000);
  95. ath79_gpio_function_disable(AR724X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
  96. AR724X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
  97. AR724X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
  98. AR724X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
  99. AR724X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
  100. ath79_register_m25p80(&om2p_flash_data);
  101. ath79_register_mdio(0, ~OM2P_WAN_PHYMASK);
  102. ath79_init_mac(ath79_eth0_data.mac_addr, mac1, 0);
  103. ath79_init_mac(ath79_eth1_data.mac_addr, mac2, 0);
  104. ath79_register_eth(0);
  105. ath79_register_eth(1);
  106. ap91_pci_init(ee, NULL);
  107. ath79_register_leds_gpio(-1, ARRAY_SIZE(om2p_leds_gpio),
  108. om2p_leds_gpio);
  109. ath79_register_gpio_keys_polled(-1, OM2P_KEYS_POLL_INTERVAL,
  110. ARRAY_SIZE(om2p_gpio_keys),
  111. om2p_gpio_keys);
  112. }
  113. MIPS_MACHINE(ATH79_MACH_OM2P, "OM2P", "OpenMesh OM2P", om2p_setup);
  114. static struct flash_platform_data om2p_lc_flash_data = {
  115. .type = "s25sl12800",
  116. };
  117. static void __init om2p_lc_setup(void)
  118. {
  119. u8 *mac1 = (u8 *)KSEG1ADDR(0x1ffc0000);
  120. u8 *mac2 = (u8 *)KSEG1ADDR(0x1ffc0000 + ETH_ALEN);
  121. u8 *art = (u8 *)KSEG1ADDR(0x1ffc1000);
  122. u32 t;
  123. ath79_gpio_function_disable(AR933X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
  124. AR933X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
  125. AR933X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
  126. AR933X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
  127. AR933X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
  128. t = ath79_reset_rr(AR933X_RESET_REG_BOOTSTRAP);
  129. t |= AR933X_BOOTSTRAP_MDIO_GPIO_EN;
  130. ath79_reset_wr(AR933X_RESET_REG_BOOTSTRAP, t);
  131. ath79_register_m25p80(&om2p_lc_flash_data);
  132. om2p_leds_gpio[0].gpio = OM2P_LC_GPIO_LED_POWER;
  133. om2p_leds_gpio[1].gpio = OM2P_LC_GPIO_LED_RED;
  134. om2p_leds_gpio[2].gpio = OM2P_LC_GPIO_LED_YELLOW;
  135. om2p_leds_gpio[3].gpio = OM2P_LC_GPIO_LED_GREEN;
  136. om2p_leds_gpio[4].gpio = OM2P_LC_GPIO_LED_LAN;
  137. om2p_leds_gpio[5].gpio = OM2P_LC_GPIO_LED_WAN;
  138. ath79_register_leds_gpio(-1, ARRAY_SIZE(om2p_leds_gpio),
  139. om2p_leds_gpio);
  140. om2p_gpio_keys[0].gpio = OM2P_LC_GPIO_BTN_RESET;
  141. ath79_register_gpio_keys_polled(-1, OM2P_KEYS_POLL_INTERVAL,
  142. ARRAY_SIZE(om2p_gpio_keys),
  143. om2p_gpio_keys);
  144. ath79_init_mac(ath79_eth0_data.mac_addr, mac1, 0);
  145. ath79_init_mac(ath79_eth1_data.mac_addr, mac2, 0);
  146. ath79_register_mdio(0, 0x0);
  147. ath79_register_eth(0);
  148. ath79_register_eth(1);
  149. ath79_register_wmac(art, NULL);
  150. }
  151. MIPS_MACHINE(ATH79_MACH_OM2P_LC, "OM2P-LC", "OpenMesh OM2P LC", om2p_lc_setup);
  152. MIPS_MACHINE(ATH79_MACH_OM2Pv2, "OM2Pv2", "OpenMesh OM2Pv2", om2p_lc_setup);
  153. static void __init om2p_hs_setup(void)
  154. {
  155. u8 *mac1 = (u8 *)KSEG1ADDR(0x1ffc0000);
  156. u8 *mac2 = (u8 *)KSEG1ADDR(0x1ffc0000 + ETH_ALEN);
  157. u8 *art = (u8 *)KSEG1ADDR(0x1ffc1000);
  158. /* make lan / wan leds software controllable */
  159. ath79_gpio_output_select(OM2P_GPIO_LED_LAN, AR934X_GPIO_OUT_GPIO);
  160. ath79_gpio_output_select(OM2P_GPIO_LED_WAN, AR934X_GPIO_OUT_GPIO);
  161. /* enable reset button */
  162. ath79_gpio_output_select(OM2P_GPIO_BTN_RESET, AR934X_GPIO_OUT_GPIO);
  163. ath79_gpio_function_enable(AR934X_GPIO_FUNC_JTAG_DISABLE);
  164. om2p_leds_gpio[4].gpio = OM2P_GPIO_LED_WAN;
  165. om2p_leds_gpio[5].gpio = OM2P_GPIO_LED_LAN;
  166. ath79_register_m25p80(&om2p_lc_flash_data);
  167. ath79_register_leds_gpio(-1, ARRAY_SIZE(om2p_leds_gpio),
  168. om2p_leds_gpio);
  169. ath79_register_gpio_keys_polled(-1, OM2P_KEYS_POLL_INTERVAL,
  170. ARRAY_SIZE(om2p_gpio_keys),
  171. om2p_gpio_keys);
  172. ath79_register_wmac(art, NULL);
  173. ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_PHY_SWAP);
  174. ath79_register_mdio(1, 0x0);
  175. ath79_init_mac(ath79_eth0_data.mac_addr, mac1, 0);
  176. ath79_init_mac(ath79_eth1_data.mac_addr, mac2, 0);
  177. /* GMAC0 is connected to the PHY0 of the internal switch */
  178. ath79_switch_data.phy4_mii_en = 1;
  179. ath79_switch_data.phy_poll_mask = BIT(0);
  180. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  181. ath79_eth0_data.phy_mask = BIT(0);
  182. ath79_eth0_data.mii_bus_dev = &ath79_mdio1_device.dev;
  183. ath79_register_eth(0);
  184. /* GMAC1 is connected to the internal switch */
  185. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
  186. ath79_register_eth(1);
  187. }
  188. MIPS_MACHINE(ATH79_MACH_OM2P_HS, "OM2P-HS", "OpenMesh OM2P HS", om2p_hs_setup);
  189. MIPS_MACHINE(ATH79_MACH_OM2P_HSv2, "OM2P-HSv2", "OpenMesh OM2P HSv2", om2p_hs_setup);
  190. MIPS_MACHINE(ATH79_MACH_OM2P_HSv3, "OM2P-HSv3", "OpenMesh OM2P HSv3", om2p_hs_setup);
  191. static struct flash_platform_data om2pv4_flash_data = {
  192. .type = "s25sl12800",
  193. };
  194. static struct gpio_led om2pv4_leds_gpio[] __initdata = {
  195. {
  196. .name = "om2p:blue:power",
  197. .gpio = OM2Pv4_GPIO_LED_POWER,
  198. .active_low = 1,
  199. }, {
  200. .name = "om2p:red:wifi",
  201. .gpio = OM2Pv4_GPIO_LED_RED,
  202. .active_low = 1,
  203. }, {
  204. .name = "om2p:yellow:wifi",
  205. .gpio = OM2Pv4_GPIO_LED_YELLOW,
  206. .active_low = 1,
  207. }, {
  208. .name = "om2p:green:wifi",
  209. .gpio = OM2Pv4_GPIO_LED_GREEN,
  210. .active_low = 1,
  211. }, {
  212. .name = "om2p:blue:lan",
  213. .gpio = OM2Pv4_GPIO_LED_LAN,
  214. .active_low = 1,
  215. }, {
  216. .name = "om2p:blue:wan",
  217. .gpio = OM2Pv4_GPIO_LED_WAN,
  218. .active_low = 1,
  219. }
  220. };
  221. static struct gpio_keys_button om2pv4_gpio_keys[] __initdata = {
  222. {
  223. .desc = "reset",
  224. .type = EV_KEY,
  225. .code = KEY_RESTART,
  226. .debounce_interval = OM2P_KEYS_DEBOUNCE_INTERVAL,
  227. .gpio = OM2Pv4_GPIO_BTN_RESET,
  228. .active_low = 1,
  229. }
  230. };
  231. static void __init om2pv4_setup(void)
  232. {
  233. u8 *mac1 = (u8 *)KSEG1ADDR(0x1ffc0000);
  234. u8 *mac2 = (u8 *)KSEG1ADDR(0x1ffc0000 + ETH_ALEN);
  235. u8 *art = (u8 *)KSEG1ADDR(0x1ffc0000);
  236. u8 wmac[6];
  237. ath79_register_m25p80(&om2pv4_flash_data);
  238. ath79_register_leds_gpio(-1, ARRAY_SIZE(om2pv4_leds_gpio),
  239. om2pv4_leds_gpio);
  240. ath79_register_gpio_keys_polled(-1, OM2P_KEYS_POLL_INTERVAL,
  241. ARRAY_SIZE(om2pv4_gpio_keys),
  242. om2pv4_gpio_keys);
  243. ath79_init_mac(wmac, art, 0x02);
  244. ath79_register_wmac(art + OM2P_WMAC_CALDATA_OFFSET, wmac);
  245. ath79_setup_ar933x_phy4_switch(false, false);
  246. ath79_register_mdio(0, 0x0);
  247. /* LAN */
  248. ath79_switch_data.phy4_mii_en = 1;
  249. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  250. ath79_eth0_data.duplex = DUPLEX_FULL;
  251. ath79_eth0_data.speed = SPEED_100;
  252. ath79_eth0_data.phy_mask = BIT(4);
  253. ath79_init_mac(ath79_eth1_data.mac_addr, mac2, 0);
  254. ath79_register_eth(0);
  255. /* WAN */
  256. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
  257. ath79_eth1_data.duplex = DUPLEX_FULL;
  258. ath79_switch_data.phy_poll_mask |= BIT(4);
  259. ath79_init_mac(ath79_eth0_data.mac_addr, mac1, 0);
  260. ath79_register_eth(1);
  261. }
  262. MIPS_MACHINE(ATH79_MACH_OM2Pv4, "OM2Pv4", "OpenMesh OM2Pv4", om2pv4_setup);
  263. MIPS_MACHINE(ATH79_MACH_OM2P_HSv4, "OM2P-HSv4", "OpenMesh OM2P HSv4", om2pv4_setup);