2 * MikroTik RouterBOARD 750/750GL support
4 * Copyright (C) 2010-2012 Gabor Juhos <juhosg@openwrt.org>
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.
11 #include <linux/export.h>
12 #include <linux/pci.h>
13 #include <linux/ath9k_platform.h>
14 #include <linux/platform_device.h>
15 #include <linux/phy.h>
16 #include <linux/ar8216_platform.h>
17 #include <linux/rle.h>
18 #include <linux/routerboot.h>
20 #include <asm/mach-ath79/ar71xx_regs.h>
21 #include <asm/mach-ath79/ath79.h>
22 #include <asm/mach-ath79/irq.h>
23 #include <asm/mach-ath79/mach-rb750.h>
26 #include "dev-ap9x-pci.h"
29 #include "machtypes.h"
30 #include "routerboot.h"
32 static struct rb750_led_data rb750_leds[] = {
34 .name = "rb750:green:act",
35 .mask = RB750_LED_ACT,
38 .name = "rb750:green:port1",
39 .mask = RB750_LED_PORT5,
42 .name = "rb750:green:port2",
43 .mask = RB750_LED_PORT4,
46 .name = "rb750:green:port3",
47 .mask = RB750_LED_PORT3,
50 .name = "rb750:green:port4",
51 .mask = RB750_LED_PORT2,
54 .name = "rb750:green:port5",
55 .mask = RB750_LED_PORT1,
60 static struct rb750_led_data rb750gr3_leds[] = {
62 .name = "rb750:green:act",
63 .mask = RB7XX_LED_ACT,
68 static struct rb750_led_platform_data rb750_leds_data;
69 static struct platform_device rb750_leds_device = {
72 .platform_data = &rb750_leds_data,
76 static struct rb7xx_nand_platform_data rb750_nand_data;
77 static struct platform_device rb750_nand_device = {
81 .platform_data = &rb750_nand_data,
85 static void rb750_latch_change(u32 mask_clr, u32 mask_set)
87 static DEFINE_SPINLOCK(lock);
88 static u32 latch_set = RB750_LED_BITS | RB750_LVC573_LE;
94 spin_lock_irqsave(&lock, flags);
96 if ((mask_clr & BIT(31)) != 0 &&
97 (latch_set & RB750_LVC573_LE) == 0) {
101 latch_set = (latch_set | mask_set) & ~mask_clr;
102 latch_clr = (latch_clr | mask_clr) & ~mask_set;
105 latch_oe = __raw_readl(ath79_gpio_base + AR71XX_GPIO_REG_OE);
107 if (likely(latch_set & RB750_LVC573_LE)) {
108 void __iomem *base = ath79_gpio_base;
110 t = __raw_readl(base + AR71XX_GPIO_REG_OE);
111 t |= mask_clr | latch_oe | mask_set;
113 __raw_writel(t, base + AR71XX_GPIO_REG_OE);
114 __raw_writel(latch_clr, base + AR71XX_GPIO_REG_CLEAR);
115 __raw_writel(latch_set, base + AR71XX_GPIO_REG_SET);
116 } else if (mask_clr & RB750_LVC573_LE) {
117 void __iomem *base = ath79_gpio_base;
119 latch_oe = __raw_readl(base + AR71XX_GPIO_REG_OE);
120 __raw_writel(RB750_LVC573_LE, base + AR71XX_GPIO_REG_CLEAR);
122 __raw_readl(base + AR71XX_GPIO_REG_CLEAR);
126 spin_unlock_irqrestore(&lock, flags);
129 static void rb750_nand_enable_pins(void)
131 rb750_latch_change(RB750_LVC573_LE, 0);
132 ath79_gpio_function_setup(AR724X_GPIO_FUNC_JTAG_DISABLE,
133 AR724X_GPIO_FUNC_SPI_EN);
136 static void rb750_nand_disable_pins(void)
138 ath79_gpio_function_setup(AR724X_GPIO_FUNC_SPI_EN,
139 AR724X_GPIO_FUNC_JTAG_DISABLE);
140 rb750_latch_change(0, RB750_LVC573_LE);
143 static void __init rb750_setup(void)
145 ath79_gpio_function_disable(AR724X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
146 AR724X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
147 AR724X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
148 AR724X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
149 AR724X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
151 ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
152 ath79_init_mac(ath79_eth1_data.mac_addr, ath79_mac_base, 1);
154 ath79_register_mdio(0, 0x0);
157 ath79_register_eth(1);
160 ath79_register_eth(0);
162 rb750_leds_data.num_leds = ARRAY_SIZE(rb750_leds);
163 rb750_leds_data.leds = rb750_leds;
164 rb750_leds_data.latch_change = rb750_latch_change;
165 platform_device_register(&rb750_leds_device);
167 rb750_nand_data.nce_line = RB750_NAND_NCE;
168 rb750_nand_data.enable_pins = rb750_nand_enable_pins;
169 rb750_nand_data.disable_pins = rb750_nand_disable_pins;
170 rb750_nand_data.latch_change = rb750_latch_change;
171 platform_device_register(&rb750_nand_device);
174 MIPS_MACHINE(ATH79_MACH_RB_750, "750i", "MikroTik RouterBOARD 750",
177 static struct ar8327_pad_cfg rb750gr3_ar8327_pad0_cfg = {
178 .mode = AR8327_PAD_MAC_RGMII,
179 .txclk_delay_en = true,
180 .rxclk_delay_en = true,
181 .txclk_delay_sel = AR8327_CLK_DELAY_SEL1,
182 .rxclk_delay_sel = AR8327_CLK_DELAY_SEL2,
185 static struct ar8327_platform_data rb750gr3_ar8327_data = {
186 .pad0_cfg = &rb750gr3_ar8327_pad0_cfg,
189 .speed = AR8327_PORT_SPEED_1000,
196 static struct mdio_board_info rb750g3_mdio_info[] = {
198 .bus_id = "ag71xx-mdio.0",
200 .platform_data = &rb750gr3_ar8327_data,
204 static void rb750gr3_nand_enable_pins(void)
206 ath79_gpio_function_setup(AR724X_GPIO_FUNC_JTAG_DISABLE,
207 AR724X_GPIO_FUNC_SPI_EN |
208 AR724X_GPIO_FUNC_SPI_CS_EN2);
211 static void rb750gr3_nand_disable_pins(void)
213 ath79_gpio_function_setup(AR724X_GPIO_FUNC_SPI_EN |
214 AR724X_GPIO_FUNC_SPI_CS_EN2,
215 AR724X_GPIO_FUNC_JTAG_DISABLE);
218 static void rb750gr3_latch_change(u32 mask_clr, u32 mask_set)
220 static DEFINE_SPINLOCK(lock);
221 static u32 latch_set = RB7XX_LED_ACT;
222 static u32 latch_clr;
223 void __iomem *base = ath79_gpio_base;
227 spin_lock_irqsave(&lock, flags);
229 latch_set = (latch_set | mask_set) & ~mask_clr;
230 latch_clr = (latch_clr | mask_clr) & ~mask_set;
232 mask_set = latch_set & (RB7XX_USB_POWERON | RB7XX_MONITOR);
233 mask_clr = latch_clr & (RB7XX_USB_POWERON | RB7XX_MONITOR);
235 if ((latch_set ^ RB7XX_LED_ACT) & RB7XX_LED_ACT) {
236 /* enable output mode */
237 t = __raw_readl(base + AR71XX_GPIO_REG_OE);
239 __raw_writel(t, base + AR71XX_GPIO_REG_OE);
241 mask_clr |= RB7XX_LED_ACT;
243 /* disable output mode */
244 t = __raw_readl(base + AR71XX_GPIO_REG_OE);
246 __raw_writel(t, base + AR71XX_GPIO_REG_OE);
249 __raw_writel(mask_set, base + AR71XX_GPIO_REG_SET);
250 __raw_writel(mask_clr, base + AR71XX_GPIO_REG_CLEAR);
252 spin_unlock_irqrestore(&lock, flags);
255 static void __init rb750gr3_setup(void)
257 ath79_register_mdio(0, 0x0);
258 mdiobus_register_board_info(rb750g3_mdio_info,
259 ARRAY_SIZE(rb750g3_mdio_info));
261 ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
262 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
263 ath79_eth0_data.phy_mask = BIT(0);
264 ath79_eth0_pll_data.pll_1000 = 0x62000000;
266 ath79_register_eth(0);
268 rb750_leds_data.num_leds = ARRAY_SIZE(rb750gr3_leds);
269 rb750_leds_data.leds = rb750gr3_leds;
270 rb750_leds_data.latch_change = rb750gr3_latch_change;
271 platform_device_register(&rb750_leds_device);
273 rb750_nand_data.nce_line = RB7XX_NAND_NCE;
274 rb750_nand_data.enable_pins = rb750gr3_nand_enable_pins;
275 rb750_nand_data.disable_pins = rb750gr3_nand_disable_pins;
276 rb750_nand_data.latch_change = rb750gr3_latch_change;
277 platform_device_register(&rb750_nand_device);
280 MIPS_MACHINE(ATH79_MACH_RB_750G_R3, "750Gr3", "MikroTik RouterBOARD 750GL",
283 #define RB751_HARDCONFIG 0x1f00b000
284 #define RB751_HARDCONFIG_SIZE 0x1000
286 static void __init rb751_wlan_setup(void)
288 u8 *hardconfig = (u8 *) KSEG1ADDR(RB751_HARDCONFIG);
289 struct ath9k_platform_data *wmac_data;
296 wmac_data = ap9x_pci_get_wmac_data(0);
298 pr_err("rb75x: unable to get address of wlan data\n");
302 ap9x_pci_setup_wmac_led_pin(0, 9);
304 err = routerboot_find_tag(hardconfig, RB751_HARDCONFIG_SIZE,
305 RB_ID_WLAN_DATA, &tag, &tag_len);
307 pr_err("rb75x: no calibration data found\n");
311 err = rle_decode(tag, tag_len, (unsigned char *) wmac_data->eeprom_data,
312 sizeof(wmac_data->eeprom_data), NULL, NULL);
314 pr_err("rb75x: unable to decode wlan eeprom data\n");
318 err = routerboot_find_tag(hardconfig, RB751_HARDCONFIG_SIZE,
319 RB_ID_MAC_ADDRESS_PACK, &mac, &mac_len);
321 pr_err("rb75x: no mac address found\n");
325 ap91_pci_init(NULL, mac);
328 static void __init rb751_setup(void)
331 ath79_register_usb();
335 MIPS_MACHINE(ATH79_MACH_RB_751, "751", "MikroTik RouterBOARD 751",
338 static void __init rb751g_setup(void)
341 ath79_register_usb();
345 MIPS_MACHINE(ATH79_MACH_RB_751G, "751g", "MikroTik RouterBOARD 751G",