mach-rb95x.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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 = "rootfs",
  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. return 0;
  150. }
  151. void __init rb95x_nand_init(void)
  152. {
  153. gpio_request_one(RB95X_GPIO_NAND_NCE, GPIOF_OUT_INIT_HIGH, "NAND nCE");
  154. ath79_nfc_set_scan_fixup(rb95x_nand_scan_fixup);
  155. ath79_nfc_set_parts(rb95x_nand_partitions,
  156. ARRAY_SIZE(rb95x_nand_partitions));
  157. ath79_nfc_set_select_chip(rb95x_nand_select_chip);
  158. ath79_nfc_set_swap_dma(true);
  159. ath79_register_nfc();
  160. }
  161. static int __init rb95x_setup(void)
  162. {
  163. const struct rb_info *info;
  164. info = rb_init_info((void *)(KSEG1ADDR(AR71XX_SPI_BASE)), 0x10000);
  165. if (!info)
  166. return -EINVAL;
  167. rb95x_nand_init();
  168. return 0;
  169. }
  170. static void __init rb951g_setup(void)
  171. {
  172. if (rb95x_setup())
  173. return;
  174. ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_RGMII_GMAC0 |
  175. AR934X_ETH_CFG_SW_ONLY_MODE);
  176. ath79_register_mdio(0, 0x0);
  177. mdiobus_register_board_info(rb95x_mdio0_info,
  178. ARRAY_SIZE(rb95x_mdio0_info));
  179. ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
  180. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  181. ath79_eth0_data.phy_mask = BIT(0);
  182. ath79_register_eth(0);
  183. rb95x_wlan_init();
  184. ath79_register_usb();
  185. }
  186. MIPS_MACHINE(ATH79_MACH_RB_951G, "951G", "MikroTik RouterBOARD 951G-2HnD",
  187. rb951g_setup);
  188. static void __init rb951ui_setup(void)
  189. {
  190. if (rb95x_setup())
  191. return;
  192. ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_ONLY_MODE);
  193. ath79_register_mdio(1, 0x0);
  194. ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
  195. ath79_init_mac(ath79_eth1_data.mac_addr, ath79_mac_base, 1);
  196. ath79_switch_data.phy4_mii_en = 1;
  197. ath79_switch_data.phy_poll_mask = BIT(4);
  198. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  199. ath79_eth0_data.phy_mask = BIT(4);
  200. ath79_eth0_data.mii_bus_dev = &ath79_mdio1_device.dev;
  201. ath79_register_eth(0);
  202. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
  203. ath79_register_eth(1);
  204. gpio_request_one(20, GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
  205. "USB power");
  206. gpio_request_one(2, GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
  207. "POE power");
  208. rb95x_wlan_init();
  209. ath79_register_usb();
  210. ath79_register_leds_gpio(-1, ARRAY_SIZE(rb951ui_leds_gpio),
  211. rb951ui_leds_gpio);
  212. }
  213. MIPS_MACHINE(ATH79_MACH_RB_951U, "951HnD", "MikroTik RouterBOARD 951Ui-2HnD",
  214. rb951ui_setup);