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>
18 #include <asm/mach-ath79/ar71xx_regs.h>
19 #include <asm/mach-ath79/ath79.h>
20 #include <asm/mach-ath79/pci.h>
21 #include <asm/mach-ath79/irq.h>
22 #include <asm/mach-ath79/mach-rb750.h>
27 #include "machtypes.h"
28 #include "pci-ath9k-fixup.h"
31 static struct rb750_led_data rb750_leds[] = {
33 .name = "rb750:green:act",
34 .mask = RB750_LED_ACT,
37 .name = "rb750:green:port1",
38 .mask = RB750_LED_PORT5,
41 .name = "rb750:green:port2",
42 .mask = RB750_LED_PORT4,
45 .name = "rb750:green:port3",
46 .mask = RB750_LED_PORT3,
49 .name = "rb750:green:port4",
50 .mask = RB750_LED_PORT2,
53 .name = "rb750:green:port5",
54 .mask = RB750_LED_PORT1,
59 static struct rb750_led_data rb750gr3_leds[] = {
61 .name = "rb750:green:act",
62 .mask = RB7XX_LED_ACT,
67 static struct rb750_led_platform_data rb750_leds_data;
68 static struct platform_device rb750_leds_device = {
71 .platform_data = &rb750_leds_data,
75 static struct rb7xx_nand_platform_data rb750_nand_data;
76 static struct platform_device rb750_nand_device = {
80 .platform_data = &rb750_nand_data,
84 static void rb750_latch_change(u32 mask_clr, u32 mask_set)
86 static DEFINE_SPINLOCK(lock);
87 static u32 latch_set = RB750_LED_BITS | RB750_LVC573_LE;
93 spin_lock_irqsave(&lock, flags);
95 if ((mask_clr & BIT(31)) != 0 &&
96 (latch_set & RB750_LVC573_LE) == 0) {
100 latch_set = (latch_set | mask_set) & ~mask_clr;
101 latch_clr = (latch_clr | mask_clr) & ~mask_set;
104 latch_oe = __raw_readl(ath79_gpio_base + AR71XX_GPIO_REG_OE);
106 if (likely(latch_set & RB750_LVC573_LE)) {
107 void __iomem *base = ath79_gpio_base;
109 t = __raw_readl(base + AR71XX_GPIO_REG_OE);
110 t |= mask_clr | latch_oe | mask_set;
112 __raw_writel(t, base + AR71XX_GPIO_REG_OE);
113 __raw_writel(latch_clr, base + AR71XX_GPIO_REG_CLEAR);
114 __raw_writel(latch_set, base + AR71XX_GPIO_REG_SET);
115 } else if (mask_clr & RB750_LVC573_LE) {
116 void __iomem *base = ath79_gpio_base;
118 latch_oe = __raw_readl(base + AR71XX_GPIO_REG_OE);
119 __raw_writel(RB750_LVC573_LE, base + AR71XX_GPIO_REG_CLEAR);
121 __raw_readl(base + AR71XX_GPIO_REG_CLEAR);
125 spin_unlock_irqrestore(&lock, flags);
128 static void rb750_nand_enable_pins(void)
130 rb750_latch_change(RB750_LVC573_LE, 0);
131 ath79_gpio_function_setup(AR724X_GPIO_FUNC_JTAG_DISABLE,
132 AR724X_GPIO_FUNC_SPI_EN);
135 static void rb750_nand_disable_pins(void)
137 ath79_gpio_function_setup(AR724X_GPIO_FUNC_SPI_EN,
138 AR724X_GPIO_FUNC_JTAG_DISABLE);
139 rb750_latch_change(0, RB750_LVC573_LE);
142 static void __init rb750_setup(void)
144 ath79_gpio_function_disable(AR724X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
145 AR724X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
146 AR724X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
147 AR724X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
148 AR724X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
150 ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
151 ath79_init_mac(ath79_eth1_data.mac_addr, ath79_mac_base, 1);
153 ath79_register_mdio(0, 0x0);
156 ath79_register_eth(1);
159 ath79_register_eth(0);
161 rb750_leds_data.num_leds = ARRAY_SIZE(rb750_leds);
162 rb750_leds_data.leds = rb750_leds;
163 rb750_leds_data.latch_change = rb750_latch_change;
164 platform_device_register(&rb750_leds_device);
166 rb750_nand_data.nce_line = RB750_NAND_NCE;
167 rb750_nand_data.enable_pins = rb750_nand_enable_pins;
168 rb750_nand_data.disable_pins = rb750_nand_disable_pins;
169 rb750_nand_data.latch_change = rb750_latch_change;
170 platform_device_register(&rb750_nand_device);
173 MIPS_MACHINE(ATH79_MACH_RB_750, "750i", "MikroTik RouterBOARD 750",
176 static struct ar8327_pad_cfg rb750gr3_ar8327_pad0_cfg = {
177 .mode = AR8327_PAD_MAC_RGMII,
178 .txclk_delay_en = true,
179 .rxclk_delay_en = true,
180 .txclk_delay_sel = AR8327_CLK_DELAY_SEL1,
181 .rxclk_delay_sel = AR8327_CLK_DELAY_SEL2,
184 static struct ar8327_platform_data rb750gr3_ar8327_data = {
185 .pad0_cfg = &rb750gr3_ar8327_pad0_cfg,
188 .speed = AR8327_PORT_SPEED_100,
195 static struct mdio_board_info rb750g3_mdio_info[] = {
197 .bus_id = "ag71xx-mdio.0",
199 .platform_data = &rb750gr3_ar8327_data,
203 static void rb750gr3_nand_enable_pins(void)
205 ath79_gpio_function_setup(AR724X_GPIO_FUNC_JTAG_DISABLE,
206 AR724X_GPIO_FUNC_SPI_EN |
207 AR724X_GPIO_FUNC_SPI_CS_EN2);
210 static void rb750gr3_nand_disable_pins(void)
212 ath79_gpio_function_setup(AR724X_GPIO_FUNC_SPI_EN |
213 AR724X_GPIO_FUNC_SPI_CS_EN2,
214 AR724X_GPIO_FUNC_JTAG_DISABLE);
217 static void rb750gr3_latch_change(u32 mask_clr, u32 mask_set)
219 static DEFINE_SPINLOCK(lock);
220 static u32 latch_set = RB7XX_LED_ACT;
221 static u32 latch_clr;
222 void __iomem *base = ath79_gpio_base;
226 spin_lock_irqsave(&lock, flags);
228 latch_set = (latch_set | mask_set) & ~mask_clr;
229 latch_clr = (latch_clr | mask_clr) & ~mask_set;
231 mask_set = latch_set & (RB7XX_USB_POWERON | RB7XX_MONITOR);
232 mask_clr = latch_clr & (RB7XX_USB_POWERON | RB7XX_MONITOR);
234 if ((latch_set ^ RB7XX_LED_ACT) & RB7XX_LED_ACT) {
235 /* enable output mode */
236 t = __raw_readl(base + AR71XX_GPIO_REG_OE);
238 __raw_writel(t, base + AR71XX_GPIO_REG_OE);
240 mask_clr |= RB7XX_LED_ACT;
242 /* disable output mode */
243 t = __raw_readl(base + AR71XX_GPIO_REG_OE);
245 __raw_writel(t, base + AR71XX_GPIO_REG_OE);
248 __raw_writel(mask_set, base + AR71XX_GPIO_REG_SET);
249 __raw_writel(mask_clr, base + AR71XX_GPIO_REG_CLEAR);
251 spin_unlock_irqrestore(&lock, flags);
254 static void __init rb750gr3_setup(void)
256 ath79_register_mdio(0, 0x0);
257 mdiobus_register_board_info(rb750g3_mdio_info,
258 ARRAY_SIZE(rb750g3_mdio_info));
260 ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
261 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
262 ath79_eth0_data.phy_mask = BIT(0);
264 ath79_register_eth(0);
266 rb750_leds_data.num_leds = ARRAY_SIZE(rb750gr3_leds);
267 rb750_leds_data.leds = rb750gr3_leds;
268 rb750_leds_data.latch_change = rb750gr3_latch_change;
269 platform_device_register(&rb750_leds_device);
271 rb750_nand_data.nce_line = RB7XX_NAND_NCE;
272 rb750_nand_data.enable_pins = rb750gr3_nand_enable_pins;
273 rb750_nand_data.disable_pins = rb750gr3_nand_disable_pins;
274 rb750_nand_data.latch_change = rb750gr3_latch_change;
275 platform_device_register(&rb750_nand_device);
278 MIPS_MACHINE(ATH79_MACH_RB_750G_R3, "750Gr3", "MikroTik RouterBOARD 750GL",
281 static struct ath9k_platform_data rb751_wmac_data = {
285 static u8 rb751_wmac_mac[6];
287 static int rb751_pci_plat_dev_init(struct pci_dev *dev)
289 switch (PCI_SLOT(dev->devfn)) {
291 dev->dev.platform_data = &rb751_wmac_data;
298 static int decode_rle(char *output, int len, char *in)
301 char *end = output + len;
310 } else if (*in > 0) {
323 #define RB751_HARDCONFIG 0x1f00b000
324 #define RB751_MAC_ADDRESS_OFFSET 0xE80
325 #define RB751_CALDATA_OFFSET 0x27C
327 static void __init rb751_wlan_and_usb_setup(void)
329 u8 *hardconfig = (u8 *) KSEG1ADDR(RB751_HARDCONFIG);
331 ath79_register_usb();
333 ath79_pci_set_plat_dev_init(rb751_pci_plat_dev_init);
334 ath79_register_pci();
336 rb751_wmac_data.macaddr = memcpy(rb751_wmac_mac,
337 hardconfig + RB751_MAC_ADDRESS_OFFSET, 6);
339 if (decode_rle((char *)rb751_wmac_data.eeprom_data,
340 sizeof(rb751_wmac_data.eeprom_data),
341 hardconfig + RB751_CALDATA_OFFSET) ==
342 sizeof(rb751_wmac_data.eeprom_data)) {
343 pr_info("rb7xx: calibration data found\n");
344 pci_enable_ath9k_fixup(0, rb751_wmac_data.eeprom_data);
348 static void __init rb751_setup(void)
351 rb751_wlan_and_usb_setup();
354 MIPS_MACHINE(ATH79_MACH_RB_751, "751", "MikroTik RouterBOARD 751",
357 static void __init rb751g_setup(void)
360 rb751_wlan_and_usb_setup();
363 MIPS_MACHINE(ATH79_MACH_RB_751G, "751g", "MikroTik RouterBOARD 751G",