mach-rb4xx.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. /*
  2. * MikroTik RouterBOARD 4xx series 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/platform_device.h>
  12. #include <linux/irq.h>
  13. #include <linux/mdio-gpio.h>
  14. #include <linux/mmc/host.h>
  15. #include <linux/spi/spi.h>
  16. #include <linux/spi/flash.h>
  17. #include <linux/spi/mmc_spi.h>
  18. #include <linux/mtd/mtd.h>
  19. #include <linux/mtd/partitions.h>
  20. #include <asm/mach-ath79/ar71xx_regs.h>
  21. #include <asm/mach-ath79/ath79.h>
  22. #include <asm/mach-ath79/rb4xx_cpld.h>
  23. #include "common.h"
  24. #include "dev-eth.h"
  25. #include "dev-gpio-buttons.h"
  26. #include "dev-leds-gpio.h"
  27. #include "dev-usb.h"
  28. #include "machtypes.h"
  29. #include "pci.h"
  30. #define RB4XX_GPIO_USER_LED 4
  31. #define RB4XX_GPIO_RESET_SWITCH 7
  32. #define RB4XX_GPIO_CPLD_BASE 32
  33. #define RB4XX_GPIO_CPLD_LED1 (RB4XX_GPIO_CPLD_BASE + CPLD_GPIO_nLED1)
  34. #define RB4XX_GPIO_CPLD_LED2 (RB4XX_GPIO_CPLD_BASE + CPLD_GPIO_nLED2)
  35. #define RB4XX_GPIO_CPLD_LED3 (RB4XX_GPIO_CPLD_BASE + CPLD_GPIO_nLED3)
  36. #define RB4XX_GPIO_CPLD_LED4 (RB4XX_GPIO_CPLD_BASE + CPLD_GPIO_nLED4)
  37. #define RB4XX_GPIO_CPLD_LED5 (RB4XX_GPIO_CPLD_BASE + CPLD_GPIO_nLED5)
  38. #define RB4XX_KEYS_POLL_INTERVAL 20 /* msecs */
  39. #define RB4XX_KEYS_DEBOUNCE_INTERVAL (3 * RB4XX_KEYS_POLL_INTERVAL)
  40. static struct gpio_led rb4xx_leds_gpio[] __initdata = {
  41. {
  42. .name = "rb4xx:yellow:user",
  43. .gpio = RB4XX_GPIO_USER_LED,
  44. .active_low = 0,
  45. }, {
  46. .name = "rb4xx:green:led1",
  47. .gpio = RB4XX_GPIO_CPLD_LED1,
  48. .active_low = 1,
  49. }, {
  50. .name = "rb4xx:green:led2",
  51. .gpio = RB4XX_GPIO_CPLD_LED2,
  52. .active_low = 1,
  53. }, {
  54. .name = "rb4xx:green:led3",
  55. .gpio = RB4XX_GPIO_CPLD_LED3,
  56. .active_low = 1,
  57. }, {
  58. .name = "rb4xx:green:led4",
  59. .gpio = RB4XX_GPIO_CPLD_LED4,
  60. .active_low = 1,
  61. }, {
  62. .name = "rb4xx:green:led5",
  63. .gpio = RB4XX_GPIO_CPLD_LED5,
  64. .active_low = 0,
  65. },
  66. };
  67. static struct gpio_keys_button rb4xx_gpio_keys[] __initdata = {
  68. {
  69. .desc = "reset_switch",
  70. .type = EV_KEY,
  71. .code = KEY_RESTART,
  72. .debounce_interval = RB4XX_KEYS_DEBOUNCE_INTERVAL,
  73. .gpio = RB4XX_GPIO_RESET_SWITCH,
  74. .active_low = 1,
  75. }
  76. };
  77. static struct platform_device rb4xx_nand_device = {
  78. .name = "rb4xx-nand",
  79. .id = -1,
  80. };
  81. static struct ath79_pci_irq rb4xx_pci_irqs[] __initdata = {
  82. {
  83. .slot = 17,
  84. .pin = 1,
  85. .irq = ATH79_PCI_IRQ(2),
  86. }, {
  87. .slot = 18,
  88. .pin = 1,
  89. .irq = ATH79_PCI_IRQ(0),
  90. }, {
  91. .slot = 18,
  92. .pin = 2,
  93. .irq = ATH79_PCI_IRQ(1),
  94. }, {
  95. .slot = 19,
  96. .pin = 1,
  97. .irq = ATH79_PCI_IRQ(1),
  98. }, {
  99. .slot = 19,
  100. .pin = 2,
  101. .irq = ATH79_PCI_IRQ(2),
  102. }, {
  103. .slot = 20,
  104. .pin = 1,
  105. .irq = ATH79_PCI_IRQ(2),
  106. }, {
  107. .slot = 20,
  108. .pin = 2,
  109. .irq = ATH79_PCI_IRQ(0),
  110. }, {
  111. .slot = 21,
  112. .pin = 1,
  113. .irq = ATH79_PCI_IRQ(0),
  114. }, {
  115. .slot = 22,
  116. .pin = 1,
  117. .irq = ATH79_PCI_IRQ(1),
  118. }, {
  119. .slot = 22,
  120. .pin = 2,
  121. .irq = ATH79_PCI_IRQ(2),
  122. }, {
  123. .slot = 23,
  124. .pin = 1,
  125. .irq = ATH79_PCI_IRQ(2),
  126. }, {
  127. .slot = 23,
  128. .pin = 2,
  129. .irq = ATH79_PCI_IRQ(0),
  130. }
  131. };
  132. static struct mtd_partition rb4xx_partitions[] = {
  133. {
  134. .name = "routerboot",
  135. .offset = 0,
  136. .size = 0x0b000,
  137. .mask_flags = MTD_WRITEABLE,
  138. }, {
  139. .name = "hard_config",
  140. .offset = 0x0b000,
  141. .size = 0x01000,
  142. .mask_flags = MTD_WRITEABLE,
  143. }, {
  144. .name = "bios",
  145. .offset = 0x0d000,
  146. .size = 0x02000,
  147. .mask_flags = MTD_WRITEABLE,
  148. }, {
  149. .name = "soft_config",
  150. .offset = 0x0f000,
  151. .size = 0x01000,
  152. }
  153. };
  154. static struct flash_platform_data rb4xx_flash_data = {
  155. .type = "pm25lv512",
  156. .parts = rb4xx_partitions,
  157. .nr_parts = ARRAY_SIZE(rb4xx_partitions),
  158. };
  159. static struct rb4xx_cpld_platform_data rb4xx_cpld_data = {
  160. .gpio_base = RB4XX_GPIO_CPLD_BASE,
  161. };
  162. static struct mmc_spi_platform_data rb4xx_mmc_data = {
  163. .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
  164. };
  165. static struct spi_board_info rb4xx_spi_info[] = {
  166. {
  167. .bus_num = 0,
  168. .chip_select = 0,
  169. .max_speed_hz = 25000000,
  170. .modalias = "m25p80",
  171. .platform_data = &rb4xx_flash_data,
  172. }, {
  173. .bus_num = 0,
  174. .chip_select = 1,
  175. .max_speed_hz = 25000000,
  176. .modalias = "spi-rb4xx-cpld",
  177. .platform_data = &rb4xx_cpld_data,
  178. }
  179. };
  180. static struct spi_board_info rb4xx_microsd_info[] = {
  181. {
  182. .bus_num = 0,
  183. .chip_select = 2,
  184. .max_speed_hz = 25000000,
  185. .modalias = "mmc_spi",
  186. .platform_data = &rb4xx_mmc_data,
  187. }
  188. };
  189. static struct resource rb4xx_spi_resources[] = {
  190. {
  191. .start = AR71XX_SPI_BASE,
  192. .end = AR71XX_SPI_BASE + AR71XX_SPI_SIZE - 1,
  193. .flags = IORESOURCE_MEM,
  194. },
  195. };
  196. static struct platform_device rb4xx_spi_device = {
  197. .name = "rb4xx-spi",
  198. .id = -1,
  199. .resource = rb4xx_spi_resources,
  200. .num_resources = ARRAY_SIZE(rb4xx_spi_resources),
  201. };
  202. static void __init rb4xx_generic_setup(void)
  203. {
  204. ath79_gpio_function_enable(AR71XX_GPIO_FUNC_SPI_CS1_EN |
  205. AR71XX_GPIO_FUNC_SPI_CS2_EN);
  206. ath79_register_leds_gpio(-1, ARRAY_SIZE(rb4xx_leds_gpio),
  207. rb4xx_leds_gpio);
  208. ath79_register_gpio_keys_polled(-1, RB4XX_KEYS_POLL_INTERVAL,
  209. ARRAY_SIZE(rb4xx_gpio_keys),
  210. rb4xx_gpio_keys);
  211. spi_register_board_info(rb4xx_spi_info, ARRAY_SIZE(rb4xx_spi_info));
  212. platform_device_register(&rb4xx_spi_device);
  213. platform_device_register(&rb4xx_nand_device);
  214. }
  215. static void __init rb411_setup(void)
  216. {
  217. rb4xx_generic_setup();
  218. spi_register_board_info(rb4xx_microsd_info,
  219. ARRAY_SIZE(rb4xx_microsd_info));
  220. ath79_register_mdio(0, 0xfffffffc);
  221. ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
  222. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  223. ath79_eth0_data.phy_mask = 0x00000003;
  224. ath79_register_eth(0);
  225. ath79_pci_set_irq_map(ARRAY_SIZE(rb4xx_pci_irqs), rb4xx_pci_irqs);
  226. ath79_register_pci();
  227. }
  228. MIPS_MACHINE(ATH79_MACH_RB_411, "411", "MikroTik RouterBOARD 411/A/AH",
  229. rb411_setup);
  230. static void __init rb411u_setup(void)
  231. {
  232. rb411_setup();
  233. ath79_register_usb();
  234. }
  235. MIPS_MACHINE(ATH79_MACH_RB_411U, "411U", "MikroTik RouterBOARD 411U",
  236. rb411u_setup);
  237. #define RB433_LAN_PHYMASK BIT(0)
  238. #define RB433_WAN_PHYMASK BIT(4)
  239. #define RB433_MDIO_PHYMASK (RB433_LAN_PHYMASK | RB433_WAN_PHYMASK)
  240. static void __init rb433_setup(void)
  241. {
  242. rb4xx_generic_setup();
  243. spi_register_board_info(rb4xx_microsd_info,
  244. ARRAY_SIZE(rb4xx_microsd_info));
  245. ath79_register_mdio(0, ~RB433_MDIO_PHYMASK);
  246. ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 1);
  247. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  248. ath79_eth0_data.phy_mask = RB433_LAN_PHYMASK;
  249. ath79_init_mac(ath79_eth1_data.mac_addr, ath79_mac_base, 0);
  250. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  251. ath79_eth1_data.phy_mask = RB433_WAN_PHYMASK;
  252. ath79_register_eth(1);
  253. ath79_register_eth(0);
  254. ath79_pci_set_irq_map(ARRAY_SIZE(rb4xx_pci_irqs), rb4xx_pci_irqs);
  255. ath79_register_pci();
  256. }
  257. MIPS_MACHINE(ATH79_MACH_RB_433, "433", "MikroTik RouterBOARD 433/AH",
  258. rb433_setup);
  259. static void __init rb433u_setup(void)
  260. {
  261. rb433_setup();
  262. ath79_register_usb();
  263. }
  264. MIPS_MACHINE(ATH79_MACH_RB_433U, "433U", "MikroTik RouterBOARD 433UAH",
  265. rb433u_setup);
  266. static void __init rb435g_setup(void)
  267. {
  268. rb4xx_generic_setup();
  269. spi_register_board_info(rb4xx_microsd_info,
  270. ARRAY_SIZE(rb4xx_microsd_info));
  271. ath79_register_mdio(0, ~RB433_MDIO_PHYMASK);
  272. ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 1);
  273. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  274. ath79_eth0_data.phy_mask = RB433_LAN_PHYMASK;
  275. ath79_init_mac(ath79_eth1_data.mac_addr, ath79_mac_base, 0);
  276. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  277. ath79_eth1_data.phy_mask = RB433_WAN_PHYMASK;
  278. ath79_register_eth(1);
  279. ath79_register_eth(0);
  280. ath79_pci_set_irq_map(ARRAY_SIZE(rb4xx_pci_irqs), rb4xx_pci_irqs);
  281. ath79_register_pci();
  282. ath79_register_usb();
  283. }
  284. MIPS_MACHINE(ATH79_MACH_RB_435G, "435G", "MikroTik RouterBOARD 435G",
  285. rb435g_setup);
  286. #define RB450_LAN_PHYMASK BIT(0)
  287. #define RB450_WAN_PHYMASK BIT(4)
  288. #define RB450_MDIO_PHYMASK (RB450_LAN_PHYMASK | RB450_WAN_PHYMASK)
  289. static void __init rb450_generic_setup(int gige)
  290. {
  291. rb4xx_generic_setup();
  292. ath79_register_mdio(0, ~RB450_MDIO_PHYMASK);
  293. ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 1);
  294. ath79_eth0_data.phy_if_mode = (gige) ?
  295. PHY_INTERFACE_MODE_RGMII : PHY_INTERFACE_MODE_MII;
  296. ath79_eth0_data.phy_mask = RB450_LAN_PHYMASK;
  297. ath79_init_mac(ath79_eth1_data.mac_addr, ath79_mac_base, 0);
  298. ath79_eth1_data.phy_if_mode = (gige) ?
  299. PHY_INTERFACE_MODE_RGMII : PHY_INTERFACE_MODE_RMII;
  300. ath79_eth1_data.phy_mask = RB450_WAN_PHYMASK;
  301. ath79_register_eth(1);
  302. ath79_register_eth(0);
  303. }
  304. static void __init rb450_setup(void)
  305. {
  306. rb450_generic_setup(0);
  307. }
  308. MIPS_MACHINE(ATH79_MACH_RB_450, "450", "MikroTik RouterBOARD 450",
  309. rb450_setup);
  310. static void __init rb450g_setup(void)
  311. {
  312. rb450_generic_setup(1);
  313. spi_register_board_info(rb4xx_microsd_info,
  314. ARRAY_SIZE(rb4xx_microsd_info));
  315. }
  316. MIPS_MACHINE(ATH79_MACH_RB_450G, "450G", "MikroTik RouterBOARD 450G",
  317. rb450g_setup);
  318. static void __init rb493_setup(void)
  319. {
  320. rb4xx_generic_setup();
  321. ath79_register_mdio(0, 0x3fffff00);
  322. ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
  323. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  324. ath79_eth0_data.speed = SPEED_100;
  325. ath79_eth0_data.duplex = DUPLEX_FULL;
  326. ath79_init_mac(ath79_eth1_data.mac_addr, ath79_mac_base, 1);
  327. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  328. ath79_eth1_data.phy_mask = 0x00000001;
  329. ath79_register_eth(0);
  330. ath79_register_eth(1);
  331. ath79_pci_set_irq_map(ARRAY_SIZE(rb4xx_pci_irqs), rb4xx_pci_irqs);
  332. ath79_register_pci();
  333. }
  334. MIPS_MACHINE(ATH79_MACH_RB_493, "493", "MikroTik RouterBOARD 493/AH",
  335. rb493_setup);
  336. #define RB493G_GPIO_MDIO_MDC 7
  337. #define RB493G_GPIO_MDIO_DATA 8
  338. #define RB493G_MDIO_PHYMASK BIT(0)
  339. static struct mdio_gpio_platform_data rb493g_mdio_data = {
  340. .mdc = RB493G_GPIO_MDIO_MDC,
  341. .mdio = RB493G_GPIO_MDIO_DATA,
  342. .phy_mask = ~RB493G_MDIO_PHYMASK,
  343. };
  344. static struct platform_device rb493g_mdio_device = {
  345. .name = "mdio-gpio",
  346. .id = -1,
  347. .dev = {
  348. .platform_data = &rb493g_mdio_data,
  349. },
  350. };
  351. static void __init rb493g_setup(void)
  352. {
  353. ath79_gpio_function_enable(AR71XX_GPIO_FUNC_SPI_CS1_EN |
  354. AR71XX_GPIO_FUNC_SPI_CS2_EN);
  355. ath79_register_leds_gpio(-1, ARRAY_SIZE(rb4xx_leds_gpio),
  356. rb4xx_leds_gpio);
  357. spi_register_board_info(rb4xx_spi_info, ARRAY_SIZE(rb4xx_spi_info));
  358. spi_register_board_info(rb4xx_microsd_info,
  359. ARRAY_SIZE(rb4xx_microsd_info));
  360. platform_device_register(&rb4xx_spi_device);
  361. platform_device_register(&rb4xx_nand_device);
  362. ath79_register_mdio(0, ~RB493G_MDIO_PHYMASK);
  363. ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
  364. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  365. ath79_eth0_data.phy_mask = RB493G_MDIO_PHYMASK;
  366. ath79_eth0_data.speed = SPEED_1000;
  367. ath79_eth0_data.duplex = DUPLEX_FULL;
  368. ath79_init_mac(ath79_eth1_data.mac_addr, ath79_mac_base, 1);
  369. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  370. ath79_eth1_data.mii_bus_dev = &rb493g_mdio_device.dev;
  371. ath79_eth1_data.phy_mask = RB493G_MDIO_PHYMASK;
  372. ath79_eth1_data.speed = SPEED_1000;
  373. ath79_eth1_data.duplex = DUPLEX_FULL;
  374. platform_device_register(&rb493g_mdio_device);
  375. ath79_register_eth(1);
  376. ath79_register_eth(0);
  377. ath79_register_usb();
  378. ath79_pci_set_irq_map(ARRAY_SIZE(rb4xx_pci_irqs), rb4xx_pci_irqs);
  379. ath79_register_pci();
  380. }
  381. MIPS_MACHINE(ATH79_MACH_RB_493G, "493G", "MikroTik RouterBOARD 493G",
  382. rb493g_setup);