mach-rb91x.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. /*
  2. * MikroTik RouterBOARD 91X support
  3. *
  4. * Copyright (C) 2013 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. #define pr_fmt(fmt) "rb91x: " fmt
  11. #include <linux/phy.h>
  12. #include <linux/delay.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/ath9k_platform.h>
  15. #include <linux/mtd/mtd.h>
  16. #include <linux/mtd/nand.h>
  17. #include <linux/mtd/partitions.h>
  18. #include <linux/spi/spi.h>
  19. #include <linux/spi/74x164.h>
  20. #include <linux/spi/flash.h>
  21. #include <linux/routerboot.h>
  22. #include <linux/gpio.h>
  23. #include <linux/platform_data/gpio-latch.h>
  24. #include <linux/platform_data/rb91x_nand.h>
  25. #include <linux/platform_data/phy-at803x.h>
  26. #include <asm/prom.h>
  27. #include <asm/mach-ath79/ath79.h>
  28. #include <asm/mach-ath79/ath79_spi_platform.h>
  29. #include <asm/mach-ath79/ar71xx_regs.h>
  30. #include "common.h"
  31. #include "dev-eth.h"
  32. #include "dev-leds-gpio.h"
  33. #include "dev-nfc.h"
  34. #include "dev-usb.h"
  35. #include "dev-spi.h"
  36. #include "dev-wmac.h"
  37. #include "machtypes.h"
  38. #include "pci.h"
  39. #include "routerboot.h"
  40. #define RB_ROUTERBOOT_OFFSET 0x0000
  41. #define RB_ROUTERBOOT_MIN_SIZE 0xb000
  42. #define RB_HARD_CFG_SIZE 0x1000
  43. #define RB_BIOS_OFFSET 0xd000
  44. #define RB_BIOS_SIZE 0x1000
  45. #define RB_SOFT_CFG_OFFSET 0xf000
  46. #define RB_SOFT_CFG_SIZE 0x1000
  47. #define RB91X_FLAG_USB BIT(0)
  48. #define RB91X_FLAG_PCIE BIT(1)
  49. #define RB91X_LATCH_GPIO_BASE AR934X_GPIO_COUNT
  50. #define RB91X_LATCH_GPIO(_x) (RB91X_LATCH_GPIO_BASE + (_x))
  51. #define RB91X_SSR_GPIO_BASE (RB91X_LATCH_GPIO_BASE + AR934X_GPIO_COUNT)
  52. #define RB91X_SSR_GPIO(_x) (RB91X_SSR_GPIO_BASE + (_x))
  53. #define RB91X_SSR_BIT_LED1 0
  54. #define RB91X_SSR_BIT_LED2 1
  55. #define RB91X_SSR_BIT_LED3 2
  56. #define RB91X_SSR_BIT_LED4 3
  57. #define RB91X_SSR_BIT_LED5 4
  58. #define RB91X_SSR_BIT_5 5
  59. #define RB91X_SSR_BIT_USB_POWER 6
  60. #define RB91X_SSR_BIT_PCIE_POWER 7
  61. #define RB91X_GPIO_SSR_STROBE RB91X_LATCH_GPIO(0)
  62. #define RB91X_GPIO_LED_POWER RB91X_LATCH_GPIO(1)
  63. #define RB91X_GPIO_LED_USER RB91X_LATCH_GPIO(2)
  64. #define RB91X_GPIO_NAND_READ RB91X_LATCH_GPIO(3)
  65. #define RB91X_GPIO_NAND_RDY RB91X_LATCH_GPIO(4)
  66. #define RB91X_GPIO_NLE RB91X_LATCH_GPIO(11)
  67. #define RB91X_GPIO_NAND_NRW RB91X_LATCH_GPIO(12)
  68. #define RB91X_GPIO_NAND_NCE RB91X_LATCH_GPIO(13)
  69. #define RB91X_GPIO_NAND_CLE RB91X_LATCH_GPIO(14)
  70. #define RB91X_GPIO_NAND_ALE RB91X_LATCH_GPIO(15)
  71. #define RB91X_GPIO_LED_1 RB91X_SSR_GPIO(RB91X_SSR_BIT_LED1)
  72. #define RB91X_GPIO_LED_2 RB91X_SSR_GPIO(RB91X_SSR_BIT_LED2)
  73. #define RB91X_GPIO_LED_3 RB91X_SSR_GPIO(RB91X_SSR_BIT_LED3)
  74. #define RB91X_GPIO_LED_4 RB91X_SSR_GPIO(RB91X_SSR_BIT_LED4)
  75. #define RB91X_GPIO_LED_5 RB91X_SSR_GPIO(RB91X_SSR_BIT_LED5)
  76. #define RB91X_GPIO_USB_POWER RB91X_SSR_GPIO(RB91X_SSR_BIT_USB_POWER)
  77. #define RB91X_GPIO_PCIE_POWER RB91X_SSR_GPIO(RB91X_SSR_BIT_PCIE_POWER)
  78. struct rb_board_info {
  79. const char *name;
  80. u32 flags;
  81. };
  82. static struct mtd_partition rb711gr100_spi_partitions[] = {
  83. {
  84. .name = "routerboot",
  85. .offset = RB_ROUTERBOOT_OFFSET,
  86. .mask_flags = MTD_WRITEABLE,
  87. }, {
  88. .name = "hard_config",
  89. .size = RB_HARD_CFG_SIZE,
  90. .mask_flags = MTD_WRITEABLE,
  91. }, {
  92. .name = "bios",
  93. .offset = RB_BIOS_OFFSET,
  94. .size = RB_BIOS_SIZE,
  95. .mask_flags = MTD_WRITEABLE,
  96. }, {
  97. .name = "soft_config",
  98. .size = RB_SOFT_CFG_SIZE,
  99. }
  100. };
  101. static struct flash_platform_data rb711gr100_spi_flash_data = {
  102. .parts = rb711gr100_spi_partitions,
  103. .nr_parts = ARRAY_SIZE(rb711gr100_spi_partitions),
  104. };
  105. static int rb711gr100_gpio_latch_gpios[AR934X_GPIO_COUNT] __initdata = {
  106. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
  107. 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22
  108. };
  109. static struct gpio_latch_platform_data rb711gr100_gpio_latch_data __initdata = {
  110. .base = RB91X_LATCH_GPIO_BASE,
  111. .num_gpios = ARRAY_SIZE(rb711gr100_gpio_latch_gpios),
  112. .gpios = rb711gr100_gpio_latch_gpios,
  113. .le_gpio_index = 11,
  114. .le_active_low = true,
  115. };
  116. static struct rb91x_nand_platform_data rb711gr100_nand_data __initdata = {
  117. .gpio_nce = RB91X_GPIO_NAND_NCE,
  118. .gpio_ale = RB91X_GPIO_NAND_ALE,
  119. .gpio_cle = RB91X_GPIO_NAND_CLE,
  120. .gpio_rdy = RB91X_GPIO_NAND_RDY,
  121. .gpio_read = RB91X_GPIO_NAND_READ,
  122. .gpio_nrw = RB91X_GPIO_NAND_NRW,
  123. .gpio_nle = RB91X_GPIO_NLE,
  124. };
  125. static u8 rb711gr100_ssr_initdata[] __initdata = {
  126. BIT(RB91X_SSR_BIT_PCIE_POWER) |
  127. BIT(RB91X_SSR_BIT_USB_POWER) |
  128. BIT(RB91X_SSR_BIT_5)
  129. };
  130. static struct gen_74x164_chip_platform_data rb711gr100_ssr_data = {
  131. .base = RB91X_SSR_GPIO_BASE,
  132. .num_registers = ARRAY_SIZE(rb711gr100_ssr_initdata),
  133. .init_data = rb711gr100_ssr_initdata,
  134. };
  135. static struct ath79_spi_controller_data rb711gr100_spi0_cdata = {
  136. .cs_type = ATH79_SPI_CS_TYPE_INTERNAL,
  137. .cs_line = 0,
  138. .is_flash = true,
  139. };
  140. static struct ath79_spi_controller_data rb711gr100_spi1_cdata = {
  141. .cs_type = ATH79_SPI_CS_TYPE_GPIO,
  142. .cs_line = RB91X_GPIO_SSR_STROBE,
  143. };
  144. static struct spi_board_info rb711gr100_spi_info[] = {
  145. {
  146. .bus_num = 0,
  147. .chip_select = 0,
  148. .max_speed_hz = 25000000,
  149. .modalias = "m25p80",
  150. .platform_data = &rb711gr100_spi_flash_data,
  151. .controller_data = &rb711gr100_spi0_cdata
  152. }, {
  153. .bus_num = 0,
  154. .chip_select = 1,
  155. .max_speed_hz = 10000000,
  156. .modalias = "74x164",
  157. .platform_data = &rb711gr100_ssr_data,
  158. .controller_data = &rb711gr100_spi1_cdata
  159. }
  160. };
  161. static struct ath79_spi_platform_data rb711gr100_spi_data __initdata = {
  162. .bus_num = 0,
  163. .num_chipselect = 2,
  164. };
  165. static struct gpio_led rb711gr100_leds[] __initdata = {
  166. {
  167. .name = "rb:green:led1",
  168. .gpio = RB91X_GPIO_LED_1,
  169. .active_low = 0,
  170. },
  171. {
  172. .name = "rb:green:led2",
  173. .gpio = RB91X_GPIO_LED_2,
  174. .active_low = 0,
  175. },
  176. {
  177. .name = "rb:green:led3",
  178. .gpio = RB91X_GPIO_LED_3,
  179. .active_low = 0,
  180. },
  181. {
  182. .name = "rb:green:led4",
  183. .gpio = RB91X_GPIO_LED_4,
  184. .active_low = 0,
  185. },
  186. {
  187. .name = "rb:green:led5",
  188. .gpio = RB91X_GPIO_LED_5,
  189. .active_low = 0,
  190. },
  191. {
  192. .name = "rb:green:user",
  193. .gpio = RB91X_GPIO_LED_USER,
  194. .active_low = 0,
  195. },
  196. {
  197. .name = "rb:green:power",
  198. .gpio = RB91X_GPIO_LED_POWER,
  199. .active_low = 0,
  200. },
  201. };
  202. static struct at803x_platform_data rb91x_at803x_data = {
  203. .disable_smarteee = 1,
  204. .enable_rgmii_rx_delay = 1,
  205. .enable_rgmii_tx_delay = 1,
  206. };
  207. static struct mdio_board_info rb91x_mdio0_info[] = {
  208. {
  209. .bus_id = "ag71xx-mdio.0",
  210. .phy_addr = 0,
  211. .platform_data = &rb91x_at803x_data,
  212. },
  213. };
  214. static void __init rb711gr100_init_partitions(const struct rb_info *info)
  215. {
  216. rb711gr100_spi_partitions[0].size = info->hard_cfg_offs;
  217. rb711gr100_spi_partitions[1].offset = info->hard_cfg_offs;
  218. rb711gr100_spi_partitions[3].offset = info->soft_cfg_offs;
  219. }
  220. void __init rb711gr100_wlan_init(void)
  221. {
  222. char *caldata;
  223. u8 wlan_mac[ETH_ALEN];
  224. caldata = rb_get_wlan_data();
  225. if (caldata == NULL)
  226. return;
  227. ath79_init_mac(wlan_mac, ath79_mac_base, 1);
  228. ath79_register_wmac(caldata + 0x1000, wlan_mac);
  229. kfree(caldata);
  230. }
  231. #define RB_BOARD_INFO(_name, _flags) \
  232. { \
  233. .name = (_name), \
  234. .flags = (_flags), \
  235. }
  236. static const struct rb_board_info rb711gr100_boards[] __initconst = {
  237. RB_BOARD_INFO("911G-2HPnD", 0),
  238. RB_BOARD_INFO("911G-5HPnD", 0),
  239. RB_BOARD_INFO("912UAG-2HPnD", RB91X_FLAG_USB | RB91X_FLAG_PCIE),
  240. RB_BOARD_INFO("912UAG-5HPnD", RB91X_FLAG_USB | RB91X_FLAG_PCIE),
  241. };
  242. static u32 rb711gr100_get_flags(const struct rb_info *info)
  243. {
  244. int i;
  245. for (i = 0; i < ARRAY_SIZE(rb711gr100_boards); i++) {
  246. const struct rb_board_info *bi;
  247. bi = &rb711gr100_boards[i];
  248. if (strcmp(info->board_name, bi->name) == 0)
  249. return bi->flags;
  250. }
  251. return 0;
  252. }
  253. static void __init rb711gr100_setup(void)
  254. {
  255. const struct rb_info *info;
  256. char buf[64];
  257. u32 flags;
  258. info = rb_init_info((void *) KSEG1ADDR(0x1f000000), 0x10000);
  259. if (!info)
  260. return;
  261. scnprintf(buf, sizeof(buf), "Mikrotik RouterBOARD %s",
  262. (info->board_name) ? info->board_name : "");
  263. mips_set_machine_name(buf);
  264. rb711gr100_init_partitions(info);
  265. ath79_register_spi(&rb711gr100_spi_data, rb711gr100_spi_info,
  266. ARRAY_SIZE(rb711gr100_spi_info));
  267. ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_RGMII_GMAC0 |
  268. AR934X_ETH_CFG_RXD_DELAY |
  269. AR934X_ETH_CFG_SW_ONLY_MODE);
  270. ath79_register_mdio(0, 0x0);
  271. mdiobus_register_board_info(rb91x_mdio0_info,
  272. ARRAY_SIZE(rb91x_mdio0_info));
  273. ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
  274. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  275. ath79_eth0_data.phy_mask = BIT(0);
  276. ath79_eth0_pll_data.pll_1000 = 0x02000000;
  277. ath79_register_eth(0);
  278. rb711gr100_wlan_init();
  279. platform_device_register_data(NULL, "rb91x-nand", -1,
  280. &rb711gr100_nand_data,
  281. sizeof(rb711gr100_nand_data));
  282. platform_device_register_data(NULL, "gpio-latch", -1,
  283. &rb711gr100_gpio_latch_data,
  284. sizeof(rb711gr100_gpio_latch_data));
  285. ath79_register_leds_gpio(-1, ARRAY_SIZE(rb711gr100_leds),
  286. rb711gr100_leds);
  287. flags = rb711gr100_get_flags(info);
  288. if (flags & RB91X_FLAG_USB)
  289. ath79_register_usb();
  290. if (flags & RB91X_FLAG_PCIE)
  291. ath79_register_pci();
  292. }
  293. MIPS_MACHINE_NONAME(ATH79_MACH_RB_711GR100, "711Gr100", rb711gr100_setup);