mach-rb4xx.c 11 KB

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