mach-rb750.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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. /* USB */
  147. ath79_register_usb();
  148. }
  149. MIPS_MACHINE(ATH79_MACH_RB_750, "750i", "MikroTik RouterBOARD 750",
  150. rb750_setup);
  151. static struct ar8327_pad_cfg rb750gr3_ar8327_pad0_cfg = {
  152. .mode = AR8327_PAD_MAC_RGMII,
  153. .txclk_delay_en = true,
  154. .rxclk_delay_en = true,
  155. .txclk_delay_sel = AR8327_CLK_DELAY_SEL1,
  156. .rxclk_delay_sel = AR8327_CLK_DELAY_SEL2,
  157. };
  158. static struct ar8327_platform_data rb750gr3_ar8327_data = {
  159. .pad0_cfg = &rb750gr3_ar8327_pad0_cfg,
  160. .port0_cfg = {
  161. .force_link = 1,
  162. .speed = AR8327_PORT_SPEED_1000,
  163. .duplex = 1,
  164. .txpause = 1,
  165. .rxpause = 1,
  166. }
  167. };
  168. static struct mdio_board_info rb750g3_mdio_info[] = {
  169. {
  170. .bus_id = "ag71xx-mdio.0",
  171. .phy_addr = 0,
  172. .platform_data = &rb750gr3_ar8327_data,
  173. },
  174. };
  175. static void rb750gr3_nand_enable_pins(void)
  176. {
  177. ath79_gpio_function_setup(AR724X_GPIO_FUNC_JTAG_DISABLE,
  178. AR724X_GPIO_FUNC_SPI_EN |
  179. AR724X_GPIO_FUNC_SPI_CS_EN2);
  180. }
  181. static void rb750gr3_nand_disable_pins(void)
  182. {
  183. ath79_gpio_function_setup(AR724X_GPIO_FUNC_SPI_EN |
  184. AR724X_GPIO_FUNC_SPI_CS_EN2,
  185. AR724X_GPIO_FUNC_JTAG_DISABLE);
  186. }
  187. static void rb750gr3_latch_change(u32 mask_clr, u32 mask_set)
  188. {
  189. static DEFINE_SPINLOCK(lock);
  190. static u32 latch_set = RB7XX_LED_ACT;
  191. static u32 latch_clr;
  192. void __iomem *base = ath79_gpio_base;
  193. unsigned long flags;
  194. u32 t;
  195. spin_lock_irqsave(&lock, flags);
  196. latch_set = (latch_set | mask_set) & ~mask_clr;
  197. latch_clr = (latch_clr | mask_clr) & ~mask_set;
  198. mask_set = latch_set & (RB7XX_USB_POWERON | RB7XX_MONITOR);
  199. mask_clr = latch_clr & (RB7XX_USB_POWERON | RB7XX_MONITOR);
  200. if ((latch_set ^ RB7XX_LED_ACT) & RB7XX_LED_ACT) {
  201. /* enable output mode */
  202. t = __raw_readl(base + AR71XX_GPIO_REG_OE);
  203. t |= RB7XX_LED_ACT;
  204. __raw_writel(t, base + AR71XX_GPIO_REG_OE);
  205. mask_clr |= RB7XX_LED_ACT;
  206. } else {
  207. /* disable output mode */
  208. t = __raw_readl(base + AR71XX_GPIO_REG_OE);
  209. t &= ~RB7XX_LED_ACT;
  210. __raw_writel(t, base + AR71XX_GPIO_REG_OE);
  211. }
  212. __raw_writel(mask_set, base + AR71XX_GPIO_REG_SET);
  213. __raw_writel(mask_clr, base + AR71XX_GPIO_REG_CLEAR);
  214. spin_unlock_irqrestore(&lock, flags);
  215. }
  216. static void __init rb750gr3_setup(void)
  217. {
  218. ath79_register_mdio(0, 0x0);
  219. mdiobus_register_board_info(rb750g3_mdio_info,
  220. ARRAY_SIZE(rb750g3_mdio_info));
  221. ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
  222. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  223. ath79_eth0_data.phy_mask = BIT(0);
  224. ath79_eth0_pll_data.pll_1000 = 0x62000000;
  225. ath79_register_eth(0);
  226. rb750_leds_data.num_leds = ARRAY_SIZE(rb750gr3_leds);
  227. rb750_leds_data.leds = rb750gr3_leds;
  228. rb750_leds_data.latch_change = rb750gr3_latch_change;
  229. platform_device_register(&rb750_leds_device);
  230. rb750_nand_data.nce_line = RB7XX_NAND_NCE;
  231. rb750_nand_data.enable_pins = rb750gr3_nand_enable_pins;
  232. rb750_nand_data.disable_pins = rb750gr3_nand_disable_pins;
  233. rb750_nand_data.latch_change = rb750gr3_latch_change;
  234. platform_device_register(&rb750_nand_device);
  235. }
  236. MIPS_MACHINE(ATH79_MACH_RB_750G_R3, "750Gr3", "MikroTik RouterBOARD 750GL",
  237. rb750gr3_setup);
  238. #define RB751_HARDCONFIG 0x1f00b000
  239. #define RB751_HARDCONFIG_SIZE 0x1000
  240. static void __init rb751_wlan_setup(void)
  241. {
  242. u8 *hardconfig = (u8 *) KSEG1ADDR(RB751_HARDCONFIG);
  243. struct ath9k_platform_data *wmac_data;
  244. u16 tag_len;
  245. u8 *tag;
  246. u16 mac_len;
  247. u8 *mac;
  248. int err;
  249. wmac_data = ap9x_pci_get_wmac_data(0);
  250. if (!wmac_data) {
  251. pr_err("rb75x: unable to get address of wlan data\n");
  252. return;
  253. }
  254. ap9x_pci_setup_wmac_led_pin(0, 9);
  255. err = routerboot_find_tag(hardconfig, RB751_HARDCONFIG_SIZE,
  256. RB_ID_WLAN_DATA, &tag, &tag_len);
  257. if (err) {
  258. pr_err("rb75x: no calibration data found\n");
  259. return;
  260. }
  261. err = rle_decode(tag, tag_len, (unsigned char *) wmac_data->eeprom_data,
  262. sizeof(wmac_data->eeprom_data), NULL, NULL);
  263. if (err) {
  264. pr_err("rb75x: unable to decode wlan eeprom data\n");
  265. return;
  266. }
  267. err = routerboot_find_tag(hardconfig, RB751_HARDCONFIG_SIZE,
  268. RB_ID_MAC_ADDRESS_PACK, &mac, &mac_len);
  269. if (err) {
  270. pr_err("rb75x: no mac address found\n");
  271. return;
  272. }
  273. ap91_pci_init(NULL, mac);
  274. }
  275. static void __init rb751_setup(void)
  276. {
  277. rb750_setup();
  278. ath79_register_usb();
  279. rb751_wlan_setup();
  280. }
  281. MIPS_MACHINE(ATH79_MACH_RB_751, "751", "MikroTik RouterBOARD 751",
  282. rb751_setup);
  283. static void __init rb751g_setup(void)
  284. {
  285. rb750gr3_setup();
  286. ath79_register_usb();
  287. rb751_wlan_setup();
  288. }
  289. MIPS_MACHINE(ATH79_MACH_RB_751G, "751g", "MikroTik RouterBOARD 751G",
  290. rb751g_setup);