mach-wzr-hp-ag300h.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * Buffalo WZR-HP-AG300H board support
  3. *
  4. * Copyright (C) 2011 Felix Fietkau <nbd@nbd.name>
  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 <asm/mach-ath79/ath79.h>
  14. #include "dev-eth.h"
  15. #include "dev-ap9x-pci.h"
  16. #include "dev-gpio-buttons.h"
  17. #include "dev-leds-gpio.h"
  18. #include "dev-m25p80.h"
  19. #include "dev-usb.h"
  20. #include "machtypes.h"
  21. #define WZRHPAG300H_MAC_OFFSET 0x20c
  22. #define WZRHPAG300H_KEYS_POLL_INTERVAL 20 /* msecs */
  23. #define WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL (3 * WZRHPAG300H_KEYS_POLL_INTERVAL)
  24. static struct mtd_partition wzrhpag300h_flash_partitions[] = {
  25. {
  26. .name = "u-boot",
  27. .offset = 0,
  28. .size = 0x0040000,
  29. .mask_flags = MTD_WRITEABLE,
  30. }, {
  31. .name = "u-boot-env",
  32. .offset = 0x0040000,
  33. .size = 0x0010000,
  34. .mask_flags = MTD_WRITEABLE,
  35. }, {
  36. .name = "art",
  37. .offset = 0x0050000,
  38. .size = 0x0010000,
  39. .mask_flags = MTD_WRITEABLE,
  40. }, {
  41. .name = "firmware",
  42. .offset = 0x0060000,
  43. .size = 0x1f90000,
  44. }, {
  45. .name = "user_property",
  46. .offset = 0x1ff0000,
  47. .size = 0x0010000,
  48. .mask_flags = MTD_WRITEABLE,
  49. }
  50. };
  51. static struct flash_platform_data wzrhpag300h_flash_data = {
  52. .parts = wzrhpag300h_flash_partitions,
  53. .nr_parts = ARRAY_SIZE(wzrhpag300h_flash_partitions),
  54. };
  55. static struct gpio_led wzrhpag300h_leds_gpio[] __initdata = {
  56. {
  57. .name = "buffalo:red:diag",
  58. .gpio = 1,
  59. .active_low = 1,
  60. },
  61. };
  62. static struct gpio_led wzrhpag300h_wmac0_leds_gpio[] = {
  63. {
  64. .name = "buffalo:amber:band2g",
  65. .gpio = 1,
  66. .active_low = 1,
  67. },
  68. {
  69. .name = "buffalo:green:usb",
  70. .gpio = 3,
  71. .active_low = 1,
  72. },
  73. {
  74. .name = "buffalo:green:band2g",
  75. .gpio = 5,
  76. .active_low = 1,
  77. },
  78. };
  79. static struct gpio_led wzrhpag300h_wmac1_leds_gpio[] = {
  80. {
  81. .name = "buffalo:green:band5g",
  82. .gpio = 1,
  83. .active_low = 1,
  84. },
  85. {
  86. .name = "buffalo:green:router",
  87. .gpio = 3,
  88. .active_low = 1,
  89. },
  90. {
  91. .name = "buffalo:blue:movie_engine",
  92. .gpio = 4,
  93. .active_low = 1,
  94. },
  95. {
  96. .name = "buffalo:amber:band5g",
  97. .gpio = 5,
  98. .active_low = 1,
  99. },
  100. };
  101. static struct gpio_keys_button wzrhpag300h_gpio_keys[] __initdata = {
  102. {
  103. .desc = "reset",
  104. .type = EV_KEY,
  105. .code = KEY_RESTART,
  106. .debounce_interval = WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL,
  107. .gpio = 11,
  108. .active_low = 1,
  109. }, {
  110. .desc = "usb",
  111. .type = EV_KEY,
  112. .code = BTN_2,
  113. .debounce_interval = WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL,
  114. .gpio = 3,
  115. .active_low = 1,
  116. }, {
  117. .desc = "aoss",
  118. .type = EV_KEY,
  119. .code = KEY_WPS_BUTTON,
  120. .debounce_interval = WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL,
  121. .gpio = 5,
  122. .active_low = 1,
  123. }, {
  124. .desc = "router_auto",
  125. .type = EV_SW,
  126. .code = BTN_6,
  127. .debounce_interval = WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL,
  128. .gpio = 6,
  129. .active_low = 1,
  130. }, {
  131. .desc = "router_off",
  132. .type = EV_SW,
  133. .code = BTN_5,
  134. .debounce_interval = WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL,
  135. .gpio = 7,
  136. .active_low = 1,
  137. }, {
  138. .desc = "movie_engine",
  139. .type = EV_SW,
  140. .code = BTN_7,
  141. .debounce_interval = WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL,
  142. .gpio = 8,
  143. .active_low = 1,
  144. }
  145. };
  146. static void __init wzrhpag300h_setup(void)
  147. {
  148. u8 *eeprom1 = (u8 *) KSEG1ADDR(0x1f051000);
  149. u8 *eeprom2 = (u8 *) KSEG1ADDR(0x1f055000);
  150. u8 *mac1 = eeprom1 + WZRHPAG300H_MAC_OFFSET;
  151. u8 *mac2 = eeprom2 + WZRHPAG300H_MAC_OFFSET;
  152. ath79_init_mac(ath79_eth0_data.mac_addr, mac1, 0);
  153. ath79_init_mac(ath79_eth1_data.mac_addr, mac2, 1);
  154. ath79_register_mdio(0, ~(BIT(0) | BIT(4)));
  155. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  156. ath79_eth0_data.speed = SPEED_1000;
  157. ath79_eth0_data.duplex = DUPLEX_FULL;
  158. ath79_eth0_data.phy_mask = BIT(0);
  159. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  160. ath79_eth1_data.phy_mask = BIT(4);
  161. ath79_register_eth(0);
  162. ath79_register_eth(1);
  163. gpio_request_one(2, GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
  164. "USB power");
  165. ath79_register_usb();
  166. ath79_register_leds_gpio(-1, ARRAY_SIZE(wzrhpag300h_leds_gpio),
  167. wzrhpag300h_leds_gpio);
  168. ath79_register_gpio_keys_polled(-1, WZRHPAG300H_KEYS_POLL_INTERVAL,
  169. ARRAY_SIZE(wzrhpag300h_gpio_keys),
  170. wzrhpag300h_gpio_keys);
  171. ath79_register_m25p80_multi(&wzrhpag300h_flash_data);
  172. ap94_pci_init(eeprom1, mac1, eeprom2, mac2);
  173. ap9x_pci_setup_wmac_led_pin(0, 1);
  174. ap9x_pci_setup_wmac_led_pin(1, 5);
  175. ap9x_pci_setup_wmac_leds(0, wzrhpag300h_wmac0_leds_gpio,
  176. ARRAY_SIZE(wzrhpag300h_wmac0_leds_gpio));
  177. ap9x_pci_setup_wmac_leds(1, wzrhpag300h_wmac1_leds_gpio,
  178. ARRAY_SIZE(wzrhpag300h_wmac1_leds_gpio));
  179. }
  180. MIPS_MACHINE(ATH79_MACH_WZR_HP_AG300H, "WZR-HP-AG300H",
  181. "Buffalo WZR-HP-AG300H/WZR-600DHP", wzrhpag300h_setup);