mach-ap83.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /*
  2. * Atheros AP83 board support
  3. *
  4. * Copyright (C) 2008-2012 Gabor Juhos <juhosg@openwrt.org>
  5. * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published
  9. * by the Free Software Foundation.
  10. */
  11. #include <linux/delay.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/mtd/mtd.h>
  14. #include <linux/mtd/partitions.h>
  15. #include <linux/mtd/physmap.h>
  16. #include <linux/spi/spi.h>
  17. #include <linux/spi/spi_gpio.h>
  18. #include <linux/spi/vsc7385.h>
  19. #include <asm/mach-ath79/ar71xx_regs.h>
  20. #include <asm/mach-ath79/ath79.h>
  21. #include "dev-eth.h"
  22. #include "dev-gpio-buttons.h"
  23. #include "dev-leds-gpio.h"
  24. #include "dev-usb.h"
  25. #include "dev-wmac.h"
  26. #include "machtypes.h"
  27. #define AP83_GPIO_LED_WLAN 6
  28. #define AP83_GPIO_LED_POWER 14
  29. #define AP83_GPIO_LED_JUMPSTART 15
  30. #define AP83_GPIO_BTN_JUMPSTART 12
  31. #define AP83_GPIO_BTN_RESET 21
  32. #define AP83_050_GPIO_VSC7385_CS 1
  33. #define AP83_050_GPIO_VSC7385_MISO 3
  34. #define AP83_050_GPIO_VSC7385_MOSI 16
  35. #define AP83_050_GPIO_VSC7385_SCK 17
  36. #define AP83_KEYS_POLL_INTERVAL 20 /* msecs */
  37. #define AP83_KEYS_DEBOUNCE_INTERVAL (3 * AP83_KEYS_POLL_INTERVAL)
  38. static struct mtd_partition ap83_flash_partitions[] = {
  39. {
  40. .name = "u-boot",
  41. .offset = 0,
  42. .size = 0x040000,
  43. .mask_flags = MTD_WRITEABLE,
  44. }, {
  45. .name = "u-boot-env",
  46. .offset = 0x040000,
  47. .size = 0x020000,
  48. .mask_flags = MTD_WRITEABLE,
  49. }, {
  50. .name = "kernel",
  51. .offset = 0x060000,
  52. .size = 0x140000,
  53. }, {
  54. .name = "rootfs",
  55. .offset = 0x1a0000,
  56. .size = 0x650000,
  57. }, {
  58. .name = "art",
  59. .offset = 0x7f0000,
  60. .size = 0x010000,
  61. .mask_flags = MTD_WRITEABLE,
  62. }, {
  63. .name = "firmware",
  64. .offset = 0x060000,
  65. .size = 0x790000,
  66. }
  67. };
  68. static struct physmap_flash_data ap83_flash_data = {
  69. .width = 2,
  70. .parts = ap83_flash_partitions,
  71. .nr_parts = ARRAY_SIZE(ap83_flash_partitions),
  72. };
  73. static struct resource ap83_flash_resources[] = {
  74. [0] = {
  75. .start = AR71XX_SPI_BASE,
  76. .end = AR71XX_SPI_BASE + AR71XX_SPI_SIZE - 1,
  77. .flags = IORESOURCE_MEM,
  78. },
  79. };
  80. static struct platform_device ap83_flash_device = {
  81. .name = "ar91xx-flash",
  82. .id = -1,
  83. .resource = ap83_flash_resources,
  84. .num_resources = ARRAY_SIZE(ap83_flash_resources),
  85. .dev = {
  86. .platform_data = &ap83_flash_data,
  87. }
  88. };
  89. static struct gpio_led ap83_leds_gpio[] __initdata = {
  90. {
  91. .name = "ap83:green:jumpstart",
  92. .gpio = AP83_GPIO_LED_JUMPSTART,
  93. .active_low = 0,
  94. }, {
  95. .name = "ap83:green:power",
  96. .gpio = AP83_GPIO_LED_POWER,
  97. .active_low = 0,
  98. }, {
  99. .name = "ap83:green:wlan",
  100. .gpio = AP83_GPIO_LED_WLAN,
  101. .active_low = 0,
  102. },
  103. };
  104. static struct gpio_keys_button ap83_gpio_keys[] __initdata = {
  105. {
  106. .desc = "soft_reset",
  107. .type = EV_KEY,
  108. .code = KEY_RESTART,
  109. .debounce_interval = AP83_KEYS_DEBOUNCE_INTERVAL,
  110. .gpio = AP83_GPIO_BTN_RESET,
  111. .active_low = 1,
  112. }, {
  113. .desc = "jumpstart",
  114. .type = EV_KEY,
  115. .code = KEY_WPS_BUTTON,
  116. .debounce_interval = AP83_KEYS_DEBOUNCE_INTERVAL,
  117. .gpio = AP83_GPIO_BTN_JUMPSTART,
  118. .active_low = 1,
  119. }
  120. };
  121. static struct resource ap83_040_spi_resources[] = {
  122. [0] = {
  123. .start = AR71XX_SPI_BASE,
  124. .end = AR71XX_SPI_BASE + AR71XX_SPI_SIZE - 1,
  125. .flags = IORESOURCE_MEM,
  126. },
  127. };
  128. static struct platform_device ap83_040_spi_device = {
  129. .name = "ap83-spi",
  130. .id = 0,
  131. .resource = ap83_040_spi_resources,
  132. .num_resources = ARRAY_SIZE(ap83_040_spi_resources),
  133. };
  134. static struct spi_gpio_platform_data ap83_050_spi_data = {
  135. .miso = AP83_050_GPIO_VSC7385_MISO,
  136. .mosi = AP83_050_GPIO_VSC7385_MOSI,
  137. .sck = AP83_050_GPIO_VSC7385_SCK,
  138. .num_chipselect = 1,
  139. };
  140. static struct platform_device ap83_050_spi_device = {
  141. .name = "spi_gpio",
  142. .id = 0,
  143. .dev = {
  144. .platform_data = &ap83_050_spi_data,
  145. }
  146. };
  147. static void ap83_vsc7385_reset(void)
  148. {
  149. ath79_device_reset_set(AR71XX_RESET_GE1_PHY);
  150. udelay(10);
  151. ath79_device_reset_clear(AR71XX_RESET_GE1_PHY);
  152. mdelay(50);
  153. }
  154. static struct vsc7385_platform_data ap83_vsc7385_data = {
  155. .reset = ap83_vsc7385_reset,
  156. .ucode_name = "vsc7385_ucode_ap83.bin",
  157. .mac_cfg = {
  158. .tx_ipg = 6,
  159. .bit2 = 0,
  160. .clk_sel = 3,
  161. },
  162. };
  163. static struct spi_board_info ap83_spi_info[] = {
  164. {
  165. .bus_num = 0,
  166. .chip_select = 0,
  167. .max_speed_hz = 25000000,
  168. .modalias = "spi-vsc7385",
  169. .platform_data = &ap83_vsc7385_data,
  170. .controller_data = (void *) AP83_050_GPIO_VSC7385_CS,
  171. }
  172. };
  173. static void __init ap83_generic_setup(void)
  174. {
  175. u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
  176. ath79_register_mdio(0, 0xfffffffe);
  177. ath79_init_mac(ath79_eth0_data.mac_addr, eeprom, 0);
  178. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  179. ath79_eth0_data.phy_mask = 0x1;
  180. ath79_register_eth(0);
  181. ath79_init_mac(ath79_eth1_data.mac_addr, eeprom, 1);
  182. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  183. ath79_eth1_data.speed = SPEED_1000;
  184. ath79_eth1_data.duplex = DUPLEX_FULL;
  185. ath79_eth1_pll_data.pll_1000 = 0x1f000000;
  186. ath79_register_eth(1);
  187. ath79_register_leds_gpio(-1, ARRAY_SIZE(ap83_leds_gpio),
  188. ap83_leds_gpio);
  189. ath79_register_gpio_keys_polled(-1, AP83_KEYS_POLL_INTERVAL,
  190. ARRAY_SIZE(ap83_gpio_keys),
  191. ap83_gpio_keys);
  192. ath79_register_usb();
  193. ath79_register_wmac(eeprom, NULL);
  194. platform_device_register(&ap83_flash_device);
  195. spi_register_board_info(ap83_spi_info, ARRAY_SIZE(ap83_spi_info));
  196. }
  197. static void ap83_040_flash_lock(struct platform_device *pdev)
  198. {
  199. ath79_flash_acquire();
  200. }
  201. static void ap83_040_flash_unlock(struct platform_device *pdev)
  202. {
  203. ath79_flash_release();
  204. }
  205. static void __init ap83_040_setup(void)
  206. {
  207. ap83_flash_data.lock = ap83_040_flash_lock;
  208. ap83_flash_data.unlock = ap83_040_flash_unlock;
  209. ap83_generic_setup();
  210. platform_device_register(&ap83_040_spi_device);
  211. }
  212. static void __init ap83_050_setup(void)
  213. {
  214. ap83_generic_setup();
  215. platform_device_register(&ap83_050_spi_device);
  216. }
  217. static void __init ap83_setup(void)
  218. {
  219. u8 *board_id = (u8 *) KSEG1ADDR(0x1fff1244);
  220. unsigned int board_version;
  221. board_version = (unsigned int)(board_id[0] - '0');
  222. board_version += ((unsigned int)(board_id[1] - '0')) * 10;
  223. switch (board_version) {
  224. case 40:
  225. ap83_040_setup();
  226. break;
  227. case 50:
  228. ap83_050_setup();
  229. break;
  230. default:
  231. printk(KERN_WARNING "AP83-%03u board is not yet supported\n",
  232. board_version);
  233. }
  234. }
  235. MIPS_MACHINE(ATH79_MACH_AP83, "AP83", "Atheros AP83", ap83_setup);