mach-rb2011.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. /*
  2. * MikroTik RouterBOARD 2011 support
  3. *
  4. * Copyright (C) 2012 Stijn Tintel <stijn@linux-ipv6.be>
  5. * Copyright (C) 2012 Gabor Juhos <juhosg@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. #define pr_fmt(fmt) "rb2011: " fmt
  12. #include <linux/phy.h>
  13. #include <linux/delay.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/ath9k_platform.h>
  16. #include <linux/ar8216_platform.h>
  17. #include <linux/mtd/mtd.h>
  18. #include <linux/mtd/nand.h>
  19. #include <linux/mtd/partitions.h>
  20. #include <linux/spi/spi.h>
  21. #include <linux/spi/flash.h>
  22. #include <linux/routerboot.h>
  23. #include <linux/gpio.h>
  24. #include <asm/prom.h>
  25. #include <asm/mach-ath79/ath79.h>
  26. #include <asm/mach-ath79/ar71xx_regs.h>
  27. #include "common.h"
  28. #include "dev-eth.h"
  29. #include "dev-m25p80.h"
  30. #include "dev-nfc.h"
  31. #include "dev-usb.h"
  32. #include "dev-wmac.h"
  33. #include "machtypes.h"
  34. #include "routerboot.h"
  35. #define RB2011_GPIO_NAND_NCE 14
  36. #define RB2011_GPIO_SFP_LOS 21
  37. #define RB_ROUTERBOOT_OFFSET 0x0000
  38. #define RB_ROUTERBOOT_MIN_SIZE 0xb000
  39. #define RB_HARD_CFG_SIZE 0x1000
  40. #define RB_BIOS_OFFSET 0xd000
  41. #define RB_BIOS_SIZE 0x1000
  42. #define RB_SOFT_CFG_OFFSET 0xf000
  43. #define RB_SOFT_CFG_SIZE 0x1000
  44. #define RB_ART_SIZE 0x10000
  45. #define RB2011_FLAG_SFP BIT(0)
  46. #define RB2011_FLAG_USB BIT(1)
  47. #define RB2011_FLAG_WLAN BIT(2)
  48. static struct mtd_partition rb2011_spi_partitions[] = {
  49. {
  50. .name = "routerboot",
  51. .offset = RB_ROUTERBOOT_OFFSET,
  52. .mask_flags = MTD_WRITEABLE,
  53. }, {
  54. .name = "hard_config",
  55. .size = RB_HARD_CFG_SIZE,
  56. .mask_flags = MTD_WRITEABLE,
  57. }, {
  58. .name = "bios",
  59. .offset = RB_BIOS_OFFSET,
  60. .size = RB_BIOS_SIZE,
  61. .mask_flags = MTD_WRITEABLE,
  62. }, {
  63. .name = "soft_config",
  64. .size = RB_SOFT_CFG_SIZE,
  65. }
  66. };
  67. static void __init rb2011_init_partitions(const struct rb_info *info)
  68. {
  69. rb2011_spi_partitions[0].size = info->hard_cfg_offs;
  70. rb2011_spi_partitions[1].offset = info->hard_cfg_offs;
  71. rb2011_spi_partitions[3].offset = info->soft_cfg_offs;
  72. }
  73. static struct mtd_partition rb2011_nand_partitions[] = {
  74. {
  75. .name = "booter",
  76. .offset = 0,
  77. .size = (256 * 1024),
  78. .mask_flags = MTD_WRITEABLE,
  79. },
  80. {
  81. .name = "kernel",
  82. .offset = (256 * 1024),
  83. .size = (4 * 1024 * 1024) - (256 * 1024),
  84. },
  85. {
  86. .name = "ubi",
  87. .offset = MTDPART_OFS_NXTBLK,
  88. .size = MTDPART_SIZ_FULL,
  89. },
  90. };
  91. static struct flash_platform_data rb2011_spi_flash_data = {
  92. .parts = rb2011_spi_partitions,
  93. .nr_parts = ARRAY_SIZE(rb2011_spi_partitions),
  94. };
  95. static struct ar8327_pad_cfg rb2011_ar8327_pad0_cfg = {
  96. .mode = AR8327_PAD_MAC_RGMII,
  97. .txclk_delay_en = true,
  98. .rxclk_delay_en = true,
  99. .txclk_delay_sel = AR8327_CLK_DELAY_SEL3,
  100. .rxclk_delay_sel = AR8327_CLK_DELAY_SEL0,
  101. };
  102. static struct ar8327_pad_cfg rb2011_ar8327_pad6_cfg;
  103. static struct ar8327_sgmii_cfg rb2011_ar8327_sgmii_cfg;
  104. static struct ar8327_led_cfg rb2011_ar8327_led_cfg = {
  105. .led_ctrl0 = 0xc731c731,
  106. .led_ctrl1 = 0x00000000,
  107. .led_ctrl2 = 0x00000000,
  108. .led_ctrl3 = 0x0030c300,
  109. .open_drain = false,
  110. };
  111. static const struct ar8327_led_info rb2011_ar8327_leds[] __initconst = {
  112. AR8327_LED_INFO(PHY0_0, HW, "rb:green:eth1"),
  113. AR8327_LED_INFO(PHY1_0, HW, "rb:green:eth2"),
  114. AR8327_LED_INFO(PHY2_0, HW, "rb:green:eth3"),
  115. AR8327_LED_INFO(PHY3_0, HW, "rb:green:eth4"),
  116. AR8327_LED_INFO(PHY4_0, HW, "rb:green:eth5"),
  117. AR8327_LED_INFO(PHY0_1, SW, "rb:green:eth6"),
  118. AR8327_LED_INFO(PHY1_1, SW, "rb:green:eth7"),
  119. AR8327_LED_INFO(PHY2_1, SW, "rb:green:eth8"),
  120. AR8327_LED_INFO(PHY3_1, SW, "rb:green:eth9"),
  121. AR8327_LED_INFO(PHY4_1, SW, "rb:green:eth10"),
  122. AR8327_LED_INFO(PHY4_2, SW, "rb:green:usr"),
  123. };
  124. static struct ar8327_platform_data rb2011_ar8327_data = {
  125. .pad0_cfg = &rb2011_ar8327_pad0_cfg,
  126. .port0_cfg = {
  127. .force_link = 1,
  128. .speed = AR8327_PORT_SPEED_1000,
  129. .duplex = 1,
  130. .txpause = 1,
  131. .rxpause = 1,
  132. },
  133. .led_cfg = &rb2011_ar8327_led_cfg,
  134. .num_leds = ARRAY_SIZE(rb2011_ar8327_leds),
  135. .leds = rb2011_ar8327_leds,
  136. };
  137. static struct mdio_board_info rb2011_mdio0_info[] = {
  138. {
  139. .bus_id = "ag71xx-mdio.0",
  140. .phy_addr = 0,
  141. .platform_data = &rb2011_ar8327_data,
  142. },
  143. };
  144. static void __init rb2011_wlan_init(void)
  145. {
  146. char *art_buf;
  147. u8 wlan_mac[ETH_ALEN];
  148. art_buf = rb_get_wlan_data();
  149. if (art_buf == NULL)
  150. return;
  151. ath79_init_mac(wlan_mac, ath79_mac_base, 11);
  152. ath79_register_wmac(art_buf + 0x1000, wlan_mac);
  153. kfree(art_buf);
  154. }
  155. static void rb2011_nand_select_chip(int chip_no)
  156. {
  157. switch (chip_no) {
  158. case 0:
  159. gpio_set_value(RB2011_GPIO_NAND_NCE, 0);
  160. break;
  161. default:
  162. gpio_set_value(RB2011_GPIO_NAND_NCE, 1);
  163. break;
  164. }
  165. ndelay(500);
  166. }
  167. static struct nand_ecclayout rb2011_nand_ecclayout = {
  168. .eccbytes = 6,
  169. .eccpos = { 8, 9, 10, 13, 14, 15 },
  170. .oobavail = 9,
  171. .oobfree = { { 0, 4 }, { 6, 2 }, { 11, 2 }, { 4, 1 } }
  172. };
  173. static int rb2011_nand_scan_fixup(struct mtd_info *mtd)
  174. {
  175. struct nand_chip *chip = mtd->priv;
  176. if (mtd->writesize == 512) {
  177. /*
  178. * Use the OLD Yaffs-1 OOB layout, otherwise RouterBoot
  179. * will not be able to find the kernel that we load.
  180. */
  181. chip->ecc.layout = &rb2011_nand_ecclayout;
  182. }
  183. return 0;
  184. }
  185. static void __init rb2011_nand_init(void)
  186. {
  187. gpio_request_one(RB2011_GPIO_NAND_NCE, GPIOF_OUT_INIT_HIGH, "NAND nCE");
  188. ath79_nfc_set_scan_fixup(rb2011_nand_scan_fixup);
  189. ath79_nfc_set_parts(rb2011_nand_partitions,
  190. ARRAY_SIZE(rb2011_nand_partitions));
  191. ath79_nfc_set_select_chip(rb2011_nand_select_chip);
  192. ath79_nfc_set_swap_dma(true);
  193. ath79_register_nfc();
  194. }
  195. static int rb2011_get_port_link(unsigned port)
  196. {
  197. if (port != 6)
  198. return -EINVAL;
  199. /* The Loss of signal line is active low */
  200. return !gpio_get_value(RB2011_GPIO_SFP_LOS);
  201. }
  202. static void __init rb2011_sfp_init(void)
  203. {
  204. gpio_request_one(RB2011_GPIO_SFP_LOS, GPIOF_IN, "SFP LOS");
  205. rb2011_ar8327_pad6_cfg.mode = AR8327_PAD_MAC_SGMII;
  206. rb2011_ar8327_data.pad6_cfg = &rb2011_ar8327_pad6_cfg;
  207. rb2011_ar8327_sgmii_cfg.sgmii_ctrl = 0xc70167d0;
  208. rb2011_ar8327_sgmii_cfg.serdes_aen = true;
  209. rb2011_ar8327_data.sgmii_cfg = &rb2011_ar8327_sgmii_cfg;
  210. rb2011_ar8327_data.port6_cfg.force_link = 1;
  211. rb2011_ar8327_data.port6_cfg.speed = AR8327_PORT_SPEED_1000;
  212. rb2011_ar8327_data.port6_cfg.duplex = 1;
  213. rb2011_ar8327_data.get_port_link = rb2011_get_port_link;
  214. }
  215. static int __init rb2011_setup(u32 flags)
  216. {
  217. const struct rb_info *info;
  218. char buf[64];
  219. info = rb_init_info((void *) KSEG1ADDR(0x1f000000), 0x10000);
  220. if (!info)
  221. return -ENODEV;
  222. scnprintf(buf, sizeof(buf), "Mikrotik RouterBOARD %s",
  223. (info->board_name) ? info->board_name : "");
  224. mips_set_machine_name(buf);
  225. rb2011_init_partitions(info);
  226. ath79_register_m25p80(&rb2011_spi_flash_data);
  227. rb2011_nand_init();
  228. ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_RGMII_GMAC0 |
  229. AR934X_ETH_CFG_SW_ONLY_MODE);
  230. ath79_register_mdio(1, 0x0);
  231. ath79_register_mdio(0, 0x0);
  232. mdiobus_register_board_info(rb2011_mdio0_info,
  233. ARRAY_SIZE(rb2011_mdio0_info));
  234. /* GMAC0 is connected to an ar8327 switch */
  235. ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
  236. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  237. ath79_eth0_data.phy_mask = BIT(0);
  238. ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
  239. ath79_eth0_pll_data.pll_1000 = 0x06000000;
  240. ath79_register_eth(0);
  241. /* GMAC1 is connected to the internal switch */
  242. ath79_init_mac(ath79_eth1_data.mac_addr, ath79_mac_base, 5);
  243. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
  244. ath79_eth1_data.speed = SPEED_1000;
  245. ath79_eth1_data.duplex = DUPLEX_FULL;
  246. ath79_register_eth(1);
  247. if (flags & RB2011_FLAG_SFP)
  248. rb2011_sfp_init();
  249. if (flags & RB2011_FLAG_WLAN)
  250. rb2011_wlan_init();
  251. if (flags & RB2011_FLAG_USB)
  252. ath79_register_usb();
  253. return 0;
  254. }
  255. static void __init rb2011l_setup(void)
  256. {
  257. rb2011_setup(0);
  258. }
  259. MIPS_MACHINE_NONAME(ATH79_MACH_RB_2011L, "2011L", rb2011l_setup);
  260. static void __init rb2011us_setup(void)
  261. {
  262. rb2011_setup(RB2011_FLAG_SFP | RB2011_FLAG_USB);
  263. }
  264. MIPS_MACHINE_NONAME(ATH79_MACH_RB_2011US, "2011US", rb2011us_setup);
  265. static void __init rb2011r5_setup(void)
  266. {
  267. rb2011_setup(RB2011_FLAG_SFP | RB2011_FLAG_USB | RB2011_FLAG_WLAN);
  268. }
  269. MIPS_MACHINE_NONAME(ATH79_MACH_RB_2011R5, "2011r5", rb2011r5_setup);
  270. static void __init rb2011g_setup(void)
  271. {
  272. rb2011_setup(RB2011_FLAG_SFP |
  273. RB2011_FLAG_USB |
  274. RB2011_FLAG_WLAN);
  275. }
  276. MIPS_MACHINE_NONAME(ATH79_MACH_RB_2011G, "2011G", rb2011g_setup);