mach-om2p.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. static struct flash_platform_data om2p_flash_data = {
  42. .type = "s25sl12800",
  43. .name = "ar7240-nor0",
  44. };
  45. static struct gpio_led om2p_leds_gpio[] __initdata = {
  46. {
  47. .name = "om2p:blue:power",
  48. .gpio = OM2P_GPIO_LED_POWER,
  49. .active_low = 1,
  50. }, {
  51. .name = "om2p:red:wifi",
  52. .gpio = OM2P_GPIO_LED_RED,
  53. .active_low = 1,
  54. }, {
  55. .name = "om2p:yellow:wifi",
  56. .gpio = OM2P_GPIO_LED_YELLOW,
  57. .active_low = 1,
  58. }, {
  59. .name = "om2p:green:wifi",
  60. .gpio = OM2P_GPIO_LED_GREEN,
  61. .active_low = 1,
  62. }, {
  63. .name = "om2p:blue:lan",
  64. .gpio = OM2P_GPIO_LED_LAN,
  65. .active_low = 1,
  66. }, {
  67. .name = "om2p:blue:wan",
  68. .gpio = OM2P_GPIO_LED_WAN,
  69. .active_low = 1,
  70. }
  71. };
  72. static struct gpio_keys_button om2p_gpio_keys[] __initdata = {
  73. {
  74. .desc = "reset",
  75. .type = EV_KEY,
  76. .code = KEY_RESTART,
  77. .debounce_interval = OM2P_KEYS_DEBOUNCE_INTERVAL,
  78. .gpio = OM2P_GPIO_BTN_RESET,
  79. .active_low = 1,
  80. }
  81. };
  82. static void __init om2p_setup(void)
  83. {
  84. u8 *mac1 = (u8 *)KSEG1ADDR(0x1ffc0000);
  85. u8 *mac2 = (u8 *)KSEG1ADDR(0x1ffc0000 + ETH_ALEN);
  86. u8 *ee = (u8 *)KSEG1ADDR(0x1ffc1000);
  87. ath79_gpio_function_disable(AR724X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
  88. AR724X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
  89. AR724X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
  90. AR724X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
  91. AR724X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
  92. ath79_register_m25p80(&om2p_flash_data);
  93. ath79_register_mdio(0, ~OM2P_WAN_PHYMASK);
  94. ath79_init_mac(ath79_eth0_data.mac_addr, mac1, 0);
  95. ath79_init_mac(ath79_eth1_data.mac_addr, mac2, 0);
  96. ath79_register_eth(0);
  97. ath79_register_eth(1);
  98. ap91_pci_init(ee, NULL);
  99. ath79_register_leds_gpio(-1, ARRAY_SIZE(om2p_leds_gpio),
  100. om2p_leds_gpio);
  101. ath79_register_gpio_keys_polled(-1, OM2P_KEYS_POLL_INTERVAL,
  102. ARRAY_SIZE(om2p_gpio_keys),
  103. om2p_gpio_keys);
  104. }
  105. MIPS_MACHINE(ATH79_MACH_OM2P, "OM2P", "OpenMesh OM2P", om2p_setup);
  106. static struct flash_platform_data om2p_lc_flash_data = {
  107. .type = "s25sl12800",
  108. };
  109. static void __init om2p_lc_setup(void)
  110. {
  111. u8 *mac1 = (u8 *)KSEG1ADDR(0x1ffc0000);
  112. u8 *mac2 = (u8 *)KSEG1ADDR(0x1ffc0000 + ETH_ALEN);
  113. u8 *art = (u8 *)KSEG1ADDR(0x1ffc1000);
  114. u32 t;
  115. ath79_gpio_function_disable(AR933X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
  116. AR933X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
  117. AR933X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
  118. AR933X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
  119. AR933X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
  120. t = ath79_reset_rr(AR933X_RESET_REG_BOOTSTRAP);
  121. t |= AR933X_BOOTSTRAP_MDIO_GPIO_EN;
  122. ath79_reset_wr(AR933X_RESET_REG_BOOTSTRAP, t);
  123. ath79_register_m25p80(&om2p_lc_flash_data);
  124. om2p_leds_gpio[0].gpio = OM2P_LC_GPIO_LED_POWER;
  125. om2p_leds_gpio[1].gpio = OM2P_LC_GPIO_LED_RED;
  126. om2p_leds_gpio[2].gpio = OM2P_LC_GPIO_LED_YELLOW;
  127. om2p_leds_gpio[3].gpio = OM2P_LC_GPIO_LED_GREEN;
  128. om2p_leds_gpio[4].gpio = OM2P_LC_GPIO_LED_LAN;
  129. om2p_leds_gpio[5].gpio = OM2P_LC_GPIO_LED_WAN;
  130. ath79_register_leds_gpio(-1, ARRAY_SIZE(om2p_leds_gpio),
  131. om2p_leds_gpio);
  132. om2p_gpio_keys[0].gpio = OM2P_LC_GPIO_BTN_RESET;
  133. ath79_register_gpio_keys_polled(-1, OM2P_KEYS_POLL_INTERVAL,
  134. ARRAY_SIZE(om2p_gpio_keys),
  135. om2p_gpio_keys);
  136. ath79_init_mac(ath79_eth0_data.mac_addr, mac1, 0);
  137. ath79_init_mac(ath79_eth1_data.mac_addr, mac2, 0);
  138. ath79_register_mdio(0, 0x0);
  139. ath79_register_eth(0);
  140. ath79_register_eth(1);
  141. ath79_register_wmac(art, NULL);
  142. }
  143. MIPS_MACHINE(ATH79_MACH_OM2P_LC, "OM2P-LC", "OpenMesh OM2P LC", om2p_lc_setup);
  144. MIPS_MACHINE(ATH79_MACH_OM2Pv2, "OM2Pv2", "OpenMesh OM2Pv2", om2p_lc_setup);
  145. static void __init om2p_hs_setup(void)
  146. {
  147. u8 *mac1 = (u8 *)KSEG1ADDR(0x1ffc0000);
  148. u8 *mac2 = (u8 *)KSEG1ADDR(0x1ffc0000 + ETH_ALEN);
  149. u8 *art = (u8 *)KSEG1ADDR(0x1ffc1000);
  150. /* make lan / wan leds software controllable */
  151. ath79_gpio_output_select(OM2P_GPIO_LED_LAN, AR934X_GPIO_OUT_GPIO);
  152. ath79_gpio_output_select(OM2P_GPIO_LED_WAN, AR934X_GPIO_OUT_GPIO);
  153. /* enable reset button */
  154. ath79_gpio_output_select(OM2P_GPIO_BTN_RESET, AR934X_GPIO_OUT_GPIO);
  155. ath79_gpio_function_enable(AR934X_GPIO_FUNC_JTAG_DISABLE);
  156. om2p_leds_gpio[4].gpio = OM2P_GPIO_LED_WAN;
  157. om2p_leds_gpio[5].gpio = OM2P_GPIO_LED_LAN;
  158. ath79_register_m25p80(&om2p_lc_flash_data);
  159. ath79_register_leds_gpio(-1, ARRAY_SIZE(om2p_leds_gpio),
  160. om2p_leds_gpio);
  161. ath79_register_gpio_keys_polled(-1, OM2P_KEYS_POLL_INTERVAL,
  162. ARRAY_SIZE(om2p_gpio_keys),
  163. om2p_gpio_keys);
  164. ath79_register_wmac(art, NULL);
  165. ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_PHY_SWAP);
  166. ath79_register_mdio(1, 0x0);
  167. ath79_init_mac(ath79_eth0_data.mac_addr, mac1, 0);
  168. ath79_init_mac(ath79_eth1_data.mac_addr, mac2, 0);
  169. /* GMAC0 is connected to the PHY0 of the internal switch */
  170. ath79_switch_data.phy4_mii_en = 1;
  171. ath79_switch_data.phy_poll_mask = BIT(0);
  172. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  173. ath79_eth0_data.phy_mask = BIT(0);
  174. ath79_eth0_data.mii_bus_dev = &ath79_mdio1_device.dev;
  175. ath79_register_eth(0);
  176. /* GMAC1 is connected to the internal switch */
  177. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
  178. ath79_register_eth(1);
  179. }
  180. MIPS_MACHINE(ATH79_MACH_OM2P_HS, "OM2P-HS", "OpenMesh OM2P HS", om2p_hs_setup);
  181. MIPS_MACHINE(ATH79_MACH_OM2P_HSv2, "OM2P-HSv2", "OpenMesh OM2P HSv2", om2p_hs_setup);
  182. MIPS_MACHINE(ATH79_MACH_OM2P_HSv3, "OM2P-HSv3", "OpenMesh OM2P HSv3", om2p_hs_setup);