mach-rb91x.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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 spi_board_info rb711gr100_spi_info[] = {
  136. {
  137. .bus_num = 0,
  138. .chip_select = 0,
  139. .max_speed_hz = 25000000,
  140. .modalias = "m25p80",
  141. .platform_data = &rb711gr100_spi_flash_data,
  142. }, {
  143. .bus_num = 0,
  144. .chip_select = 1,
  145. .max_speed_hz = 10000000,
  146. .modalias = "74x164",
  147. .platform_data = &rb711gr100_ssr_data,
  148. }
  149. };
  150. static int rb711gr100_spi_cs_gpios[2] = {
  151. -ENOENT,
  152. RB91X_GPIO_SSR_STROBE,
  153. };
  154. static struct ath79_spi_platform_data rb711gr100_spi_data __initdata = {
  155. .bus_num = 0,
  156. .num_chipselect = 2,
  157. .cs_gpios = rb711gr100_spi_cs_gpios,
  158. };
  159. static struct gpio_led rb711gr100_leds[] __initdata = {
  160. {
  161. .name = "rb:green:led1",
  162. .gpio = RB91X_GPIO_LED_1,
  163. .active_low = 0,
  164. },
  165. {
  166. .name = "rb:green:led2",
  167. .gpio = RB91X_GPIO_LED_2,
  168. .active_low = 0,
  169. },
  170. {
  171. .name = "rb:green:led3",
  172. .gpio = RB91X_GPIO_LED_3,
  173. .active_low = 0,
  174. },
  175. {
  176. .name = "rb:green:led4",
  177. .gpio = RB91X_GPIO_LED_4,
  178. .active_low = 0,
  179. },
  180. {
  181. .name = "rb:green:led5",
  182. .gpio = RB91X_GPIO_LED_5,
  183. .active_low = 0,
  184. },
  185. {
  186. .name = "rb:green:user",
  187. .gpio = RB91X_GPIO_LED_USER,
  188. .active_low = 0,
  189. },
  190. {
  191. .name = "rb:green:power",
  192. .gpio = RB91X_GPIO_LED_POWER,
  193. .active_low = 0,
  194. },
  195. };
  196. static struct at803x_platform_data rb91x_at803x_data = {
  197. .disable_smarteee = 1,
  198. .enable_rgmii_rx_delay = 1,
  199. .enable_rgmii_tx_delay = 1,
  200. };
  201. static struct mdio_board_info rb91x_mdio0_info[] = {
  202. {
  203. .bus_id = "ag71xx-mdio.0",
  204. .phy_addr = 0,
  205. .platform_data = &rb91x_at803x_data,
  206. },
  207. };
  208. static void __init rb711gr100_init_partitions(const struct rb_info *info)
  209. {
  210. rb711gr100_spi_partitions[0].size = info->hard_cfg_offs;
  211. rb711gr100_spi_partitions[1].offset = info->hard_cfg_offs;
  212. rb711gr100_spi_partitions[3].offset = info->soft_cfg_offs;
  213. }
  214. void __init rb711gr100_wlan_init(void)
  215. {
  216. char *caldata;
  217. u8 wlan_mac[ETH_ALEN];
  218. caldata = rb_get_wlan_data();
  219. if (caldata == NULL)
  220. return;
  221. ath79_init_mac(wlan_mac, ath79_mac_base, 1);
  222. ath79_register_wmac(caldata + 0x1000, wlan_mac);
  223. kfree(caldata);
  224. }
  225. #define RB_BOARD_INFO(_name, _flags) \
  226. { \
  227. .name = (_name), \
  228. .flags = (_flags), \
  229. }
  230. static const struct rb_board_info rb711gr100_boards[] __initconst = {
  231. RB_BOARD_INFO("911G-2HPnD", 0),
  232. RB_BOARD_INFO("911G-5HPnD", 0),
  233. RB_BOARD_INFO("912UAG-2HPnD", RB91X_FLAG_USB | RB91X_FLAG_PCIE),
  234. RB_BOARD_INFO("912UAG-5HPnD", RB91X_FLAG_USB | RB91X_FLAG_PCIE),
  235. };
  236. static u32 rb711gr100_get_flags(const struct rb_info *info)
  237. {
  238. int i;
  239. for (i = 0; i < ARRAY_SIZE(rb711gr100_boards); i++) {
  240. const struct rb_board_info *bi;
  241. bi = &rb711gr100_boards[i];
  242. if (strcmp(info->board_name, bi->name) == 0)
  243. return bi->flags;
  244. }
  245. return 0;
  246. }
  247. static void __init rb711gr100_setup(void)
  248. {
  249. const struct rb_info *info;
  250. char buf[64];
  251. u32 flags;
  252. info = rb_init_info((void *) KSEG1ADDR(0x1f000000), 0x10000);
  253. if (!info)
  254. return;
  255. scnprintf(buf, sizeof(buf), "Mikrotik RouterBOARD %s",
  256. (info->board_name) ? info->board_name : "");
  257. mips_set_machine_name(buf);
  258. rb711gr100_init_partitions(info);
  259. ath79_register_spi(&rb711gr100_spi_data, rb711gr100_spi_info,
  260. ARRAY_SIZE(rb711gr100_spi_info));
  261. ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_RGMII_GMAC0 |
  262. AR934X_ETH_CFG_RXD_DELAY |
  263. AR934X_ETH_CFG_SW_ONLY_MODE);
  264. ath79_register_mdio(0, 0x0);
  265. mdiobus_register_board_info(rb91x_mdio0_info,
  266. ARRAY_SIZE(rb91x_mdio0_info));
  267. ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
  268. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  269. ath79_eth0_data.phy_mask = BIT(0);
  270. ath79_eth0_pll_data.pll_1000 = 0x02000000;
  271. ath79_register_eth(0);
  272. rb711gr100_wlan_init();
  273. platform_device_register_data(NULL, "rb91x-nand", -1,
  274. &rb711gr100_nand_data,
  275. sizeof(rb711gr100_nand_data));
  276. platform_device_register_data(NULL, "gpio-latch", -1,
  277. &rb711gr100_gpio_latch_data,
  278. sizeof(rb711gr100_gpio_latch_data));
  279. ath79_register_leds_gpio(-1, ARRAY_SIZE(rb711gr100_leds),
  280. rb711gr100_leds);
  281. flags = rb711gr100_get_flags(info);
  282. if (flags & RB91X_FLAG_USB)
  283. ath79_register_usb();
  284. if (flags & RB91X_FLAG_PCIE)
  285. ath79_register_pci();
  286. }
  287. MIPS_MACHINE_NONAME(ATH79_MACH_RB_711GR100, "711Gr100", rb711gr100_setup);