mach-rb95x.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /*
  2. * MikroTik RouterBOARD 95X support
  3. *
  4. * Copyright (C) 2012 Stijn Tintel <stijn@linux-ipv6.be>
  5. * Copyright (C) 2012 Gabor Juhos <juhosg@openwrt.org>
  6. * Copyright (C) 2013 Kamil Trzcinski <ayufan@ayufan.eu>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License version 2 as published
  10. * by the Free Software Foundation.
  11. */
  12. #define pr_fmt(fmt) "rb95x: " fmt
  13. #include <linux/phy.h>
  14. #include <linux/delay.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/ath9k_platform.h>
  17. #include <linux/ar8216_platform.h>
  18. #include <linux/mtd/mtd.h>
  19. #include <linux/mtd/nand.h>
  20. #include <linux/mtd/partitions.h>
  21. #include <linux/spi/spi.h>
  22. #include <linux/spi/flash.h>
  23. #include <linux/routerboot.h>
  24. #include <linux/gpio.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. #include "dev-leds-gpio.h"
  36. #define RB95X_GPIO_NAND_NCE 14
  37. static struct mtd_partition rb95x_nand_partitions[] = {
  38. {
  39. .name = "booter",
  40. .offset = 0,
  41. .size = (256 * 1024),
  42. .mask_flags = MTD_WRITEABLE,
  43. },
  44. {
  45. .name = "kernel",
  46. .offset = (256 * 1024),
  47. .size = (4 * 1024 * 1024) - (256 * 1024),
  48. },
  49. {
  50. .name = "ubi",
  51. .offset = MTDPART_OFS_NXTBLK,
  52. .size = MTDPART_SIZ_FULL,
  53. },
  54. };
  55. static struct gpio_led rb951ui_leds_gpio[] __initdata = {
  56. {
  57. .name = "rb:green:wlan",
  58. .gpio = 11,
  59. .active_low = 1,
  60. }, {
  61. .name = "rb:green:act",
  62. .gpio = 3,
  63. .active_low = 1,
  64. }, {
  65. .name = "rb:green:port1",
  66. .gpio = 13,
  67. .active_low = 1,
  68. }, {
  69. .name = "rb:green:port2",
  70. .gpio = 12,
  71. .active_low = 1,
  72. }, {
  73. .name = "rb:green:port3",
  74. .gpio = 4,
  75. .active_low = 1,
  76. }, {
  77. .name = "rb:green:port4",
  78. .gpio = 21,
  79. .active_low = 1,
  80. }, {
  81. .name = "rb:green:port5",
  82. .gpio = 16,
  83. .active_low = 1,
  84. }
  85. };
  86. static struct ar8327_pad_cfg rb95x_ar8327_pad0_cfg = {
  87. .mode = AR8327_PAD_MAC_RGMII,
  88. .txclk_delay_en = true,
  89. .rxclk_delay_en = true,
  90. .txclk_delay_sel = AR8327_CLK_DELAY_SEL1,
  91. .rxclk_delay_sel = AR8327_CLK_DELAY_SEL2,
  92. };
  93. static struct ar8327_platform_data rb95x_ar8327_data = {
  94. .pad0_cfg = &rb95x_ar8327_pad0_cfg,
  95. .port0_cfg = {
  96. .force_link = 1,
  97. .speed = AR8327_PORT_SPEED_1000,
  98. .duplex = 1,
  99. .txpause = 1,
  100. .rxpause = 1,
  101. }
  102. };
  103. static struct mdio_board_info rb95x_mdio0_info[] = {
  104. {
  105. .bus_id = "ag71xx-mdio.0",
  106. .phy_addr = 0,
  107. .platform_data = &rb95x_ar8327_data,
  108. },
  109. };
  110. void __init rb95x_wlan_init(void)
  111. {
  112. char *art_buf;
  113. u8 wlan_mac[ETH_ALEN];
  114. art_buf = rb_get_wlan_data();
  115. if (art_buf == NULL)
  116. return;
  117. ath79_init_mac(wlan_mac, ath79_mac_base, 11);
  118. ath79_register_wmac(art_buf + 0x1000, wlan_mac);
  119. kfree(art_buf);
  120. }
  121. static void rb95x_nand_select_chip(int chip_no)
  122. {
  123. switch (chip_no) {
  124. case 0:
  125. gpio_set_value(RB95X_GPIO_NAND_NCE, 0);
  126. break;
  127. default:
  128. gpio_set_value(RB95X_GPIO_NAND_NCE, 1);
  129. break;
  130. }
  131. ndelay(500);
  132. }
  133. static struct nand_ecclayout rb95x_nand_ecclayout = {
  134. .eccbytes = 6,
  135. .eccpos = { 8, 9, 10, 13, 14, 15 },
  136. .oobavail = 9,
  137. .oobfree = { { 0, 4 }, { 6, 2 }, { 11, 2 }, { 4, 1 } }
  138. };
  139. static int rb95x_nand_scan_fixup(struct mtd_info *mtd)
  140. {
  141. struct nand_chip *chip = mtd->priv;
  142. if (mtd->writesize == 512) {
  143. /*
  144. * Use the OLD Yaffs-1 OOB layout, otherwise RouterBoot
  145. * will not be able to find the kernel that we load.
  146. */
  147. chip->ecc.layout = &rb95x_nand_ecclayout;
  148. }
  149. chip->options = NAND_NO_SUBPAGE_WRITE;
  150. return 0;
  151. }
  152. void __init rb95x_nand_init(void)
  153. {
  154. gpio_request_one(RB95X_GPIO_NAND_NCE, GPIOF_OUT_INIT_HIGH, "NAND nCE");
  155. ath79_nfc_set_scan_fixup(rb95x_nand_scan_fixup);
  156. ath79_nfc_set_parts(rb95x_nand_partitions,
  157. ARRAY_SIZE(rb95x_nand_partitions));
  158. ath79_nfc_set_select_chip(rb95x_nand_select_chip);
  159. ath79_nfc_set_swap_dma(true);
  160. ath79_register_nfc();
  161. }
  162. static int __init rb95x_setup(void)
  163. {
  164. const struct rb_info *info;
  165. info = rb_init_info((void *)(KSEG1ADDR(AR71XX_SPI_BASE)), 0x10000);
  166. if (!info)
  167. return -EINVAL;
  168. rb95x_nand_init();
  169. return 0;
  170. }
  171. static void __init rb951g_setup(void)
  172. {
  173. if (rb95x_setup())
  174. return;
  175. ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_RGMII_GMAC0 |
  176. AR934X_ETH_CFG_SW_ONLY_MODE);
  177. ath79_register_mdio(0, 0x0);
  178. mdiobus_register_board_info(rb95x_mdio0_info,
  179. ARRAY_SIZE(rb95x_mdio0_info));
  180. ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
  181. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  182. ath79_eth0_data.phy_mask = BIT(0);
  183. ath79_register_eth(0);
  184. rb95x_wlan_init();
  185. ath79_register_usb();
  186. }
  187. MIPS_MACHINE(ATH79_MACH_RB_951G, "951G", "MikroTik RouterBOARD 951G-2HnD",
  188. rb951g_setup);
  189. static void __init rb951ui_setup(void)
  190. {
  191. if (rb95x_setup())
  192. return;
  193. ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_ONLY_MODE);
  194. ath79_register_mdio(1, 0x0);
  195. ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
  196. ath79_init_mac(ath79_eth1_data.mac_addr, ath79_mac_base, 1);
  197. ath79_switch_data.phy4_mii_en = 1;
  198. ath79_switch_data.phy_poll_mask = BIT(4);
  199. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  200. ath79_eth0_data.phy_mask = BIT(4);
  201. ath79_eth0_data.mii_bus_dev = &ath79_mdio1_device.dev;
  202. ath79_register_eth(0);
  203. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
  204. ath79_register_eth(1);
  205. gpio_request_one(20, GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
  206. "USB power");
  207. gpio_request_one(2, GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
  208. "POE power");
  209. rb95x_wlan_init();
  210. ath79_register_usb();
  211. ath79_register_leds_gpio(-1, ARRAY_SIZE(rb951ui_leds_gpio),
  212. rb951ui_leds_gpio);
  213. }
  214. MIPS_MACHINE(ATH79_MACH_RB_951U, "951HnD", "MikroTik RouterBOARD 951Ui-2HnD",
  215. rb951ui_setup);