mach-wzr-hp-g300nh.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /*
  2. * Buffalo WZR-HP-G300NH board support
  3. *
  4. * Copyright (C) 2010-2012 Gabor Juhos <juhosg@openwrt.org>
  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/platform_device.h>
  11. #include <linux/mtd/mtd.h>
  12. #include <linux/mtd/partitions.h>
  13. #include <linux/mtd/physmap.h>
  14. #include <linux/nxp_74hc153.h>
  15. #include <linux/rtl8366.h>
  16. #include <asm/mach-ath79/ath79.h>
  17. #include "dev-eth.h"
  18. #include "dev-gpio-buttons.h"
  19. #include "dev-leds-gpio.h"
  20. #include "dev-usb.h"
  21. #include "dev-wmac.h"
  22. #include "machtypes.h"
  23. #define WZRHPG300NH_GPIO_LED_USB 0
  24. #define WZRHPG300NH_GPIO_LED_DIAG 1
  25. #define WZRHPG300NH_GPIO_LED_WIRELESS 6
  26. #define WZRHPG300NH_GPIO_LED_SECURITY 17
  27. #define WZRHPG300NH_GPIO_LED_ROUTER 18
  28. #define WZRHPG300NH_GPIO_RTL8366_SDA 19
  29. #define WZRHPG300NH_GPIO_RTL8366_SCK 20
  30. #define WZRHPG300NH_GPIO_74HC153_S0 9
  31. #define WZRHPG300NH_GPIO_74HC153_S1 11
  32. #define WZRHPG300NH_GPIO_74HC153_1Y 12
  33. #define WZRHPG300NH_GPIO_74HC153_2Y 14
  34. #define WZRHPG300NH_GPIO_EXP_BASE 32
  35. #define WZRHPG300NH_GPIO_BTN_AOSS (WZRHPG300NH_GPIO_EXP_BASE + 0)
  36. #define WZRHPG300NH_GPIO_BTN_RESET (WZRHPG300NH_GPIO_EXP_BASE + 1)
  37. #define WZRHPG300NH_GPIO_BTN_ROUTER_ON (WZRHPG300NH_GPIO_EXP_BASE + 2)
  38. #define WZRHPG300NH_GPIO_BTN_QOS_ON (WZRHPG300NH_GPIO_EXP_BASE + 3)
  39. #define WZRHPG300NH_GPIO_BTN_USB (WZRHPG300NH_GPIO_EXP_BASE + 5)
  40. #define WZRHPG300NH_GPIO_BTN_ROUTER_AUTO (WZRHPG300NH_GPIO_EXP_BASE + 6)
  41. #define WZRHPG300NH_GPIO_BTN_QOS_OFF (WZRHPG300NH_GPIO_EXP_BASE + 7)
  42. #define WZRHPG300NH_KEYS_POLL_INTERVAL 20 /* msecs */
  43. #define WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL (3 * WZRHPG300NH_KEYS_POLL_INTERVAL)
  44. #define WZRHPG300NH_MAC_OFFSET 0x20c
  45. static struct mtd_partition wzrhpg300nh_flash_partitions[] = {
  46. {
  47. .name = "u-boot",
  48. .offset = 0,
  49. .size = 0x0040000,
  50. .mask_flags = MTD_WRITEABLE,
  51. }, {
  52. .name = "u-boot-env",
  53. .offset = 0x0040000,
  54. .size = 0x0020000,
  55. .mask_flags = MTD_WRITEABLE,
  56. }, {
  57. .name = "firmware",
  58. .offset = 0x0060000,
  59. .size = 0x1f60000,
  60. }, {
  61. .name = "user_property",
  62. .offset = 0x1fc0000,
  63. .size = 0x0020000,
  64. .mask_flags = MTD_WRITEABLE,
  65. }, {
  66. .name = "art",
  67. .offset = 0x1fe0000,
  68. .size = 0x0020000,
  69. .mask_flags = MTD_WRITEABLE,
  70. }
  71. };
  72. static struct physmap_flash_data wzrhpg300nh_flash_data = {
  73. .width = 2,
  74. .parts = wzrhpg300nh_flash_partitions,
  75. .nr_parts = ARRAY_SIZE(wzrhpg300nh_flash_partitions),
  76. };
  77. #define WZRHPG300NH_FLASH_BASE 0x1e000000
  78. #define WZRHPG300NH_FLASH_SIZE (32 * 1024 * 1024)
  79. static struct resource wzrhpg300nh_flash_resources[] = {
  80. [0] = {
  81. .start = WZRHPG300NH_FLASH_BASE,
  82. .end = WZRHPG300NH_FLASH_BASE + WZRHPG300NH_FLASH_SIZE - 1,
  83. .flags = IORESOURCE_MEM,
  84. },
  85. };
  86. static struct platform_device wzrhpg300nh_flash_device = {
  87. .name = "physmap-flash",
  88. .id = -1,
  89. .resource = wzrhpg300nh_flash_resources,
  90. .num_resources = ARRAY_SIZE(wzrhpg300nh_flash_resources),
  91. .dev = {
  92. .platform_data = &wzrhpg300nh_flash_data,
  93. }
  94. };
  95. static struct gpio_led wzrhpg300nh_leds_gpio[] __initdata = {
  96. {
  97. .name = "buffalo:orange:security",
  98. .gpio = WZRHPG300NH_GPIO_LED_SECURITY,
  99. .active_low = 1,
  100. }, {
  101. .name = "buffalo:green:wireless",
  102. .gpio = WZRHPG300NH_GPIO_LED_WIRELESS,
  103. .active_low = 1,
  104. }, {
  105. .name = "buffalo:green:router",
  106. .gpio = WZRHPG300NH_GPIO_LED_ROUTER,
  107. .active_low = 1,
  108. }, {
  109. .name = "buffalo:red:diag",
  110. .gpio = WZRHPG300NH_GPIO_LED_DIAG,
  111. .active_low = 1,
  112. }, {
  113. .name = "buffalo:blue:usb",
  114. .gpio = WZRHPG300NH_GPIO_LED_USB,
  115. .active_low = 1,
  116. }
  117. };
  118. static struct gpio_keys_button wzrhpg300nh_gpio_keys[] __initdata = {
  119. {
  120. .desc = "reset",
  121. .type = EV_KEY,
  122. .code = KEY_RESTART,
  123. .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL,
  124. .gpio = WZRHPG300NH_GPIO_BTN_RESET,
  125. .active_low = 1,
  126. }, {
  127. .desc = "aoss",
  128. .type = EV_KEY,
  129. .code = KEY_WPS_BUTTON,
  130. .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL,
  131. .gpio = WZRHPG300NH_GPIO_BTN_AOSS,
  132. .active_low = 1,
  133. }, {
  134. .desc = "usb",
  135. .type = EV_KEY,
  136. .code = BTN_2,
  137. .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL,
  138. .gpio = WZRHPG300NH_GPIO_BTN_USB,
  139. .active_low = 1,
  140. }, {
  141. .desc = "qos_on",
  142. .type = EV_KEY,
  143. .code = BTN_3,
  144. .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL,
  145. .gpio = WZRHPG300NH_GPIO_BTN_QOS_ON,
  146. .active_low = 0,
  147. }, {
  148. .desc = "qos_off",
  149. .type = EV_KEY,
  150. .code = BTN_4,
  151. .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL,
  152. .gpio = WZRHPG300NH_GPIO_BTN_QOS_OFF,
  153. .active_low = 0,
  154. }, {
  155. .desc = "router_on",
  156. .type = EV_KEY,
  157. .code = BTN_5,
  158. .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL,
  159. .gpio = WZRHPG300NH_GPIO_BTN_ROUTER_ON,
  160. .active_low = 0,
  161. }, {
  162. .desc = "router_auto",
  163. .type = EV_KEY,
  164. .code = BTN_6,
  165. .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL,
  166. .gpio = WZRHPG300NH_GPIO_BTN_ROUTER_AUTO,
  167. .active_low = 0,
  168. }
  169. };
  170. static struct nxp_74hc153_platform_data wzrhpg300nh_74hc153_data = {
  171. .gpio_base = WZRHPG300NH_GPIO_EXP_BASE,
  172. .gpio_pin_s0 = WZRHPG300NH_GPIO_74HC153_S0,
  173. .gpio_pin_s1 = WZRHPG300NH_GPIO_74HC153_S1,
  174. .gpio_pin_1y = WZRHPG300NH_GPIO_74HC153_1Y,
  175. .gpio_pin_2y = WZRHPG300NH_GPIO_74HC153_2Y,
  176. };
  177. static struct platform_device wzrhpg300nh_74hc153_device = {
  178. .name = NXP_74HC153_DRIVER_NAME,
  179. .id = -1,
  180. .dev = {
  181. .platform_data = &wzrhpg300nh_74hc153_data,
  182. }
  183. };
  184. static struct rtl8366_platform_data wzrhpg300nh_rtl8366_data = {
  185. .gpio_sda = WZRHPG300NH_GPIO_RTL8366_SDA,
  186. .gpio_sck = WZRHPG300NH_GPIO_RTL8366_SCK,
  187. };
  188. static struct platform_device wzrhpg300nh_rtl8366s_device = {
  189. .name = RTL8366S_DRIVER_NAME,
  190. .id = -1,
  191. .dev = {
  192. .platform_data = &wzrhpg300nh_rtl8366_data,
  193. }
  194. };
  195. static struct platform_device wzrhpg300nh_rtl8366rb_device = {
  196. .name = RTL8366RB_DRIVER_NAME,
  197. .id = -1,
  198. .dev = {
  199. .platform_data = &wzrhpg300nh_rtl8366_data,
  200. }
  201. };
  202. static void __init wzrhpg300nh_setup(void)
  203. {
  204. u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  205. u8 *mac = eeprom + WZRHPG300NH_MAC_OFFSET;
  206. bool hasrtl8366rb = false;
  207. ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
  208. ath79_init_mac(ath79_eth1_data.mac_addr, mac, 1);
  209. if (rtl8366_smi_detect(&wzrhpg300nh_rtl8366_data) == RTL8366_TYPE_RB)
  210. hasrtl8366rb = true;
  211. if (hasrtl8366rb) {
  212. ath79_eth0_pll_data.pll_1000 = 0x1f000000;
  213. ath79_eth0_data.mii_bus_dev = &wzrhpg300nh_rtl8366rb_device.dev;
  214. ath79_eth1_pll_data.pll_1000 = 0x100;
  215. ath79_eth1_data.mii_bus_dev = &wzrhpg300nh_rtl8366rb_device.dev;
  216. } else {
  217. ath79_eth0_pll_data.pll_1000 = 0x1e000100;
  218. ath79_eth0_data.mii_bus_dev = &wzrhpg300nh_rtl8366s_device.dev;
  219. ath79_eth1_pll_data.pll_1000 = 0x1e000100;
  220. ath79_eth1_data.mii_bus_dev = &wzrhpg300nh_rtl8366s_device.dev;
  221. }
  222. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  223. ath79_eth0_data.speed = SPEED_1000;
  224. ath79_eth0_data.duplex = DUPLEX_FULL;
  225. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  226. ath79_eth1_data.phy_mask = 0x10;
  227. ath79_register_eth(0);
  228. ath79_register_eth(1);
  229. ath79_register_usb();
  230. ath79_register_wmac(eeprom, NULL);
  231. platform_device_register(&wzrhpg300nh_74hc153_device);
  232. platform_device_register(&wzrhpg300nh_flash_device);
  233. if (hasrtl8366rb)
  234. platform_device_register(&wzrhpg300nh_rtl8366rb_device);
  235. else
  236. platform_device_register(&wzrhpg300nh_rtl8366s_device);
  237. ath79_register_leds_gpio(-1, ARRAY_SIZE(wzrhpg300nh_leds_gpio),
  238. wzrhpg300nh_leds_gpio);
  239. ath79_register_gpio_keys_polled(-1, WZRHPG300NH_KEYS_POLL_INTERVAL,
  240. ARRAY_SIZE(wzrhpg300nh_gpio_keys),
  241. wzrhpg300nh_gpio_keys);
  242. }
  243. MIPS_MACHINE(ATH79_MACH_WZR_HP_G300NH, "WZR-HP-G300NH",
  244. "Buffalo WZR-HP-G300NH", wzrhpg300nh_setup);