mach-rb750.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. /*
  2. * MikroTik RouterBOARD 750/750GL support
  3. *
  4. * Copyright (C) 2010-2012 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. #include <linux/export.h>
  11. #include <linux/pci.h>
  12. #include <linux/ath9k_platform.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/phy.h>
  15. #include <linux/ar8216_platform.h>
  16. #include <linux/rle.h>
  17. #include <linux/routerboot.h>
  18. #include <asm/mach-ath79/ar71xx_regs.h>
  19. #include <asm/mach-ath79/ath79.h>
  20. #include <asm/mach-ath79/irq.h>
  21. #include <asm/mach-ath79/mach-rb750.h>
  22. #include "common.h"
  23. #include "dev-ap9x-pci.h"
  24. #include "dev-usb.h"
  25. #include "dev-eth.h"
  26. #include "machtypes.h"
  27. #include "routerboot.h"
  28. static struct rb750_led_data rb750_leds[] = {
  29. {
  30. .name = "rb750:green:act",
  31. .mask = RB750_LED_ACT,
  32. .active_low = 1,
  33. }, {
  34. .name = "rb750:green:port1",
  35. .mask = RB750_LED_PORT5,
  36. .active_low = 1,
  37. }, {
  38. .name = "rb750:green:port2",
  39. .mask = RB750_LED_PORT4,
  40. .active_low = 1,
  41. }, {
  42. .name = "rb750:green:port3",
  43. .mask = RB750_LED_PORT3,
  44. .active_low = 1,
  45. }, {
  46. .name = "rb750:green:port4",
  47. .mask = RB750_LED_PORT2,
  48. .active_low = 1,
  49. }, {
  50. .name = "rb750:green:port5",
  51. .mask = RB750_LED_PORT1,
  52. .active_low = 1,
  53. }
  54. };
  55. static struct rb750_led_data rb750gr3_leds[] = {
  56. {
  57. .name = "rb750:green:act",
  58. .mask = RB7XX_LED_ACT,
  59. .active_low = 1,
  60. },
  61. };
  62. static struct rb750_led_platform_data rb750_leds_data;
  63. static struct platform_device rb750_leds_device = {
  64. .name = "leds-rb750",
  65. .dev = {
  66. .platform_data = &rb750_leds_data,
  67. }
  68. };
  69. static struct rb7xx_nand_platform_data rb750_nand_data;
  70. static struct platform_device rb750_nand_device = {
  71. .name = "rb750-nand",
  72. .id = -1,
  73. .dev = {
  74. .platform_data = &rb750_nand_data,
  75. }
  76. };
  77. static void rb750_latch_change(u32 mask_clr, u32 mask_set)
  78. {
  79. static DEFINE_SPINLOCK(lock);
  80. static u32 latch_set = RB750_LED_BITS | RB750_LVC573_LE;
  81. static u32 latch_oe;
  82. static u32 latch_clr;
  83. unsigned long flags;
  84. u32 t;
  85. spin_lock_irqsave(&lock, flags);
  86. if ((mask_clr & BIT(31)) != 0 &&
  87. (latch_set & RB750_LVC573_LE) == 0) {
  88. goto unlock;
  89. }
  90. latch_set = (latch_set | mask_set) & ~mask_clr;
  91. latch_clr = (latch_clr | mask_clr) & ~mask_set;
  92. if (latch_oe == 0)
  93. latch_oe = __raw_readl(ath79_gpio_base + AR71XX_GPIO_REG_OE);
  94. if (likely(latch_set & RB750_LVC573_LE)) {
  95. void __iomem *base = ath79_gpio_base;
  96. t = __raw_readl(base + AR71XX_GPIO_REG_OE);
  97. t |= mask_clr | latch_oe | mask_set;
  98. __raw_writel(t, base + AR71XX_GPIO_REG_OE);
  99. __raw_writel(latch_clr, base + AR71XX_GPIO_REG_CLEAR);
  100. __raw_writel(latch_set, base + AR71XX_GPIO_REG_SET);
  101. } else if (mask_clr & RB750_LVC573_LE) {
  102. void __iomem *base = ath79_gpio_base;
  103. latch_oe = __raw_readl(base + AR71XX_GPIO_REG_OE);
  104. __raw_writel(RB750_LVC573_LE, base + AR71XX_GPIO_REG_CLEAR);
  105. /* flush write */
  106. __raw_readl(base + AR71XX_GPIO_REG_CLEAR);
  107. }
  108. unlock:
  109. spin_unlock_irqrestore(&lock, flags);
  110. }
  111. static void rb750_nand_enable_pins(void)
  112. {
  113. rb750_latch_change(RB750_LVC573_LE, 0);
  114. ath79_gpio_function_setup(AR724X_GPIO_FUNC_JTAG_DISABLE,
  115. AR724X_GPIO_FUNC_SPI_EN);
  116. }
  117. static void rb750_nand_disable_pins(void)
  118. {
  119. ath79_gpio_function_setup(AR724X_GPIO_FUNC_SPI_EN,
  120. AR724X_GPIO_FUNC_JTAG_DISABLE);
  121. rb750_latch_change(0, RB750_LVC573_LE);
  122. }
  123. static void __init rb750_setup(void)
  124. {
  125. ath79_gpio_function_disable(AR724X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
  126. AR724X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
  127. AR724X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
  128. AR724X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
  129. AR724X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
  130. ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
  131. ath79_init_mac(ath79_eth1_data.mac_addr, ath79_mac_base, 1);
  132. ath79_register_mdio(0, 0x0);
  133. /* LAN ports */
  134. ath79_register_eth(1);
  135. /* WAN port */
  136. ath79_register_eth(0);
  137. rb750_leds_data.num_leds = ARRAY_SIZE(rb750_leds);
  138. rb750_leds_data.leds = rb750_leds;
  139. rb750_leds_data.latch_change = rb750_latch_change;
  140. platform_device_register(&rb750_leds_device);
  141. rb750_nand_data.nce_line = RB750_NAND_NCE;
  142. rb750_nand_data.enable_pins = rb750_nand_enable_pins;
  143. rb750_nand_data.disable_pins = rb750_nand_disable_pins;
  144. rb750_nand_data.latch_change = rb750_latch_change;
  145. platform_device_register(&rb750_nand_device);
  146. }
  147. MIPS_MACHINE(ATH79_MACH_RB_750, "750i", "MikroTik RouterBOARD 750",
  148. rb750_setup);
  149. static struct ar8327_pad_cfg rb750gr3_ar8327_pad0_cfg = {
  150. .mode = AR8327_PAD_MAC_RGMII,
  151. .txclk_delay_en = true,
  152. .rxclk_delay_en = true,
  153. .txclk_delay_sel = AR8327_CLK_DELAY_SEL1,
  154. .rxclk_delay_sel = AR8327_CLK_DELAY_SEL2,
  155. };
  156. static struct ar8327_platform_data rb750gr3_ar8327_data = {
  157. .pad0_cfg = &rb750gr3_ar8327_pad0_cfg,
  158. .port0_cfg = {
  159. .force_link = 1,
  160. .speed = AR8327_PORT_SPEED_1000,
  161. .duplex = 1,
  162. .txpause = 1,
  163. .rxpause = 1,
  164. }
  165. };
  166. static struct mdio_board_info rb750g3_mdio_info[] = {
  167. {
  168. .bus_id = "ag71xx-mdio.0",
  169. .phy_addr = 0,
  170. .platform_data = &rb750gr3_ar8327_data,
  171. },
  172. };
  173. static void rb750gr3_nand_enable_pins(void)
  174. {
  175. ath79_gpio_function_setup(AR724X_GPIO_FUNC_JTAG_DISABLE,
  176. AR724X_GPIO_FUNC_SPI_EN |
  177. AR724X_GPIO_FUNC_SPI_CS_EN2);
  178. }
  179. static void rb750gr3_nand_disable_pins(void)
  180. {
  181. ath79_gpio_function_setup(AR724X_GPIO_FUNC_SPI_EN |
  182. AR724X_GPIO_FUNC_SPI_CS_EN2,
  183. AR724X_GPIO_FUNC_JTAG_DISABLE);
  184. }
  185. static void rb750gr3_latch_change(u32 mask_clr, u32 mask_set)
  186. {
  187. static DEFINE_SPINLOCK(lock);
  188. static u32 latch_set = RB7XX_LED_ACT;
  189. static u32 latch_clr;
  190. void __iomem *base = ath79_gpio_base;
  191. unsigned long flags;
  192. u32 t;
  193. spin_lock_irqsave(&lock, flags);
  194. latch_set = (latch_set | mask_set) & ~mask_clr;
  195. latch_clr = (latch_clr | mask_clr) & ~mask_set;
  196. mask_set = latch_set & (RB7XX_USB_POWERON | RB7XX_MONITOR);
  197. mask_clr = latch_clr & (RB7XX_USB_POWERON | RB7XX_MONITOR);
  198. if ((latch_set ^ RB7XX_LED_ACT) & RB7XX_LED_ACT) {
  199. /* enable output mode */
  200. t = __raw_readl(base + AR71XX_GPIO_REG_OE);
  201. t |= RB7XX_LED_ACT;
  202. __raw_writel(t, base + AR71XX_GPIO_REG_OE);
  203. mask_clr |= RB7XX_LED_ACT;
  204. } else {
  205. /* disable output mode */
  206. t = __raw_readl(base + AR71XX_GPIO_REG_OE);
  207. t &= ~RB7XX_LED_ACT;
  208. __raw_writel(t, base + AR71XX_GPIO_REG_OE);
  209. }
  210. __raw_writel(mask_set, base + AR71XX_GPIO_REG_SET);
  211. __raw_writel(mask_clr, base + AR71XX_GPIO_REG_CLEAR);
  212. spin_unlock_irqrestore(&lock, flags);
  213. }
  214. static void __init rb750gr3_setup(void)
  215. {
  216. ath79_register_mdio(0, 0x0);
  217. mdiobus_register_board_info(rb750g3_mdio_info,
  218. ARRAY_SIZE(rb750g3_mdio_info));
  219. ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
  220. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  221. ath79_eth0_data.phy_mask = BIT(0);
  222. ath79_eth0_pll_data.pll_1000 = 0x62000000;
  223. ath79_register_eth(0);
  224. rb750_leds_data.num_leds = ARRAY_SIZE(rb750gr3_leds);
  225. rb750_leds_data.leds = rb750gr3_leds;
  226. rb750_leds_data.latch_change = rb750gr3_latch_change;
  227. platform_device_register(&rb750_leds_device);
  228. rb750_nand_data.nce_line = RB7XX_NAND_NCE;
  229. rb750_nand_data.enable_pins = rb750gr3_nand_enable_pins;
  230. rb750_nand_data.disable_pins = rb750gr3_nand_disable_pins;
  231. rb750_nand_data.latch_change = rb750gr3_latch_change;
  232. platform_device_register(&rb750_nand_device);
  233. }
  234. MIPS_MACHINE(ATH79_MACH_RB_750G_R3, "750Gr3", "MikroTik RouterBOARD 750GL",
  235. rb750gr3_setup);
  236. #define RB751_HARDCONFIG 0x1f00b000
  237. #define RB751_HARDCONFIG_SIZE 0x1000
  238. static void __init rb751_wlan_setup(void)
  239. {
  240. u8 *hardconfig = (u8 *) KSEG1ADDR(RB751_HARDCONFIG);
  241. struct ath9k_platform_data *wmac_data;
  242. u16 tag_len;
  243. u8 *tag;
  244. u16 mac_len;
  245. u8 *mac;
  246. int err;
  247. wmac_data = ap9x_pci_get_wmac_data(0);
  248. if (!wmac_data) {
  249. pr_err("rb75x: unable to get address of wlan data\n");
  250. return;
  251. }
  252. ap9x_pci_setup_wmac_led_pin(0, 9);
  253. err = routerboot_find_tag(hardconfig, RB751_HARDCONFIG_SIZE,
  254. RB_ID_WLAN_DATA, &tag, &tag_len);
  255. if (err) {
  256. pr_err("rb75x: no calibration data found\n");
  257. return;
  258. }
  259. err = rle_decode(tag, tag_len, (unsigned char *) wmac_data->eeprom_data,
  260. sizeof(wmac_data->eeprom_data), NULL, NULL);
  261. if (err) {
  262. pr_err("rb75x: unable to decode wlan eeprom data\n");
  263. return;
  264. }
  265. err = routerboot_find_tag(hardconfig, RB751_HARDCONFIG_SIZE,
  266. RB_ID_MAC_ADDRESS_PACK, &mac, &mac_len);
  267. if (err) {
  268. pr_err("rb75x: no mac address found\n");
  269. return;
  270. }
  271. ap91_pci_init(NULL, mac);
  272. }
  273. static void __init rb751_setup(void)
  274. {
  275. rb750_setup();
  276. ath79_register_usb();
  277. rb751_wlan_setup();
  278. }
  279. MIPS_MACHINE(ATH79_MACH_RB_751, "751", "MikroTik RouterBOARD 751",
  280. rb751_setup);
  281. static void __init rb751g_setup(void)
  282. {
  283. rb750gr3_setup();
  284. ath79_register_usb();
  285. rb751_wlan_setup();
  286. }
  287. MIPS_MACHINE(ATH79_MACH_RB_751G, "751g", "MikroTik RouterBOARD 751G",
  288. rb751g_setup);