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/irq.h>
21 #include <asm/mach-ath79/mach-rb750.h>
24 #include "dev-ap9x-pci.h"
27 #include "machtypes.h"
29 static struct rb750_led_data rb750_leds[] = {
31 .name = "rb750:green:act",
32 .mask = RB750_LED_ACT,
35 .name = "rb750:green:port1",
36 .mask = RB750_LED_PORT5,
39 .name = "rb750:green:port2",
40 .mask = RB750_LED_PORT4,
43 .name = "rb750:green:port3",
44 .mask = RB750_LED_PORT3,
47 .name = "rb750:green:port4",
48 .mask = RB750_LED_PORT2,
51 .name = "rb750:green:port5",
52 .mask = RB750_LED_PORT1,
57 static struct rb750_led_data rb750gr3_leds[] = {
59 .name = "rb750:green:act",
60 .mask = RB7XX_LED_ACT,
65 static struct rb750_led_platform_data rb750_leds_data;
66 static struct platform_device rb750_leds_device = {
69 .platform_data = &rb750_leds_data,
73 static struct rb7xx_nand_platform_data rb750_nand_data;
74 static struct platform_device rb750_nand_device = {
78 .platform_data = &rb750_nand_data,
82 static void rb750_latch_change(u32 mask_clr, u32 mask_set)
84 static DEFINE_SPINLOCK(lock);
85 static u32 latch_set = RB750_LED_BITS | RB750_LVC573_LE;
91 spin_lock_irqsave(&lock, flags);
93 if ((mask_clr & BIT(31)) != 0 &&
94 (latch_set & RB750_LVC573_LE) == 0) {
98 latch_set = (latch_set | mask_set) & ~mask_clr;
99 latch_clr = (latch_clr | mask_clr) & ~mask_set;
102 latch_oe = __raw_readl(ath79_gpio_base + AR71XX_GPIO_REG_OE);
104 if (likely(latch_set & RB750_LVC573_LE)) {
105 void __iomem *base = ath79_gpio_base;
107 t = __raw_readl(base + AR71XX_GPIO_REG_OE);
108 t |= mask_clr | latch_oe | mask_set;
110 __raw_writel(t, base + AR71XX_GPIO_REG_OE);
111 __raw_writel(latch_clr, base + AR71XX_GPIO_REG_CLEAR);
112 __raw_writel(latch_set, base + AR71XX_GPIO_REG_SET);
113 } else if (mask_clr & RB750_LVC573_LE) {
114 void __iomem *base = ath79_gpio_base;
116 latch_oe = __raw_readl(base + AR71XX_GPIO_REG_OE);
117 __raw_writel(RB750_LVC573_LE, base + AR71XX_GPIO_REG_CLEAR);
119 __raw_readl(base + AR71XX_GPIO_REG_CLEAR);
123 spin_unlock_irqrestore(&lock, flags);
126 static void rb750_nand_enable_pins(void)
128 rb750_latch_change(RB750_LVC573_LE, 0);
129 ath79_gpio_function_setup(AR724X_GPIO_FUNC_JTAG_DISABLE,
130 AR724X_GPIO_FUNC_SPI_EN);
133 static void rb750_nand_disable_pins(void)
135 ath79_gpio_function_setup(AR724X_GPIO_FUNC_SPI_EN,
136 AR724X_GPIO_FUNC_JTAG_DISABLE);
137 rb750_latch_change(0, RB750_LVC573_LE);
140 static void __init rb750_setup(void)
142 ath79_gpio_function_disable(AR724X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
143 AR724X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
144 AR724X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
145 AR724X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
146 AR724X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
148 ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
149 ath79_init_mac(ath79_eth1_data.mac_addr, ath79_mac_base, 1);
151 ath79_register_mdio(0, 0x0);
154 ath79_register_eth(1);
157 ath79_register_eth(0);
159 rb750_leds_data.num_leds = ARRAY_SIZE(rb750_leds);
160 rb750_leds_data.leds = rb750_leds;
161 rb750_leds_data.latch_change = rb750_latch_change;
162 platform_device_register(&rb750_leds_device);
164 rb750_nand_data.nce_line = RB750_NAND_NCE;
165 rb750_nand_data.enable_pins = rb750_nand_enable_pins;
166 rb750_nand_data.disable_pins = rb750_nand_disable_pins;
167 rb750_nand_data.latch_change = rb750_latch_change;
168 platform_device_register(&rb750_nand_device);
171 MIPS_MACHINE(ATH79_MACH_RB_750, "750i", "MikroTik RouterBOARD 750",
174 static struct ar8327_pad_cfg rb750gr3_ar8327_pad0_cfg = {
175 .mode = AR8327_PAD_MAC_RGMII,
176 .txclk_delay_en = true,
177 .rxclk_delay_en = true,
178 .txclk_delay_sel = AR8327_CLK_DELAY_SEL1,
179 .rxclk_delay_sel = AR8327_CLK_DELAY_SEL2,
182 static struct ar8327_platform_data rb750gr3_ar8327_data = {
183 .pad0_cfg = &rb750gr3_ar8327_pad0_cfg,
186 .speed = AR8327_PORT_SPEED_100,
193 static struct mdio_board_info rb750g3_mdio_info[] = {
195 .bus_id = "ag71xx-mdio.0",
197 .platform_data = &rb750gr3_ar8327_data,
201 static void rb750gr3_nand_enable_pins(void)
203 ath79_gpio_function_setup(AR724X_GPIO_FUNC_JTAG_DISABLE,
204 AR724X_GPIO_FUNC_SPI_EN |
205 AR724X_GPIO_FUNC_SPI_CS_EN2);
208 static void rb750gr3_nand_disable_pins(void)
210 ath79_gpio_function_setup(AR724X_GPIO_FUNC_SPI_EN |
211 AR724X_GPIO_FUNC_SPI_CS_EN2,
212 AR724X_GPIO_FUNC_JTAG_DISABLE);
215 static void rb750gr3_latch_change(u32 mask_clr, u32 mask_set)
217 static DEFINE_SPINLOCK(lock);
218 static u32 latch_set = RB7XX_LED_ACT;
219 static u32 latch_clr;
220 void __iomem *base = ath79_gpio_base;
224 spin_lock_irqsave(&lock, flags);
226 latch_set = (latch_set | mask_set) & ~mask_clr;
227 latch_clr = (latch_clr | mask_clr) & ~mask_set;
229 mask_set = latch_set & (RB7XX_USB_POWERON | RB7XX_MONITOR);
230 mask_clr = latch_clr & (RB7XX_USB_POWERON | RB7XX_MONITOR);
232 if ((latch_set ^ RB7XX_LED_ACT) & RB7XX_LED_ACT) {
233 /* enable output mode */
234 t = __raw_readl(base + AR71XX_GPIO_REG_OE);
236 __raw_writel(t, base + AR71XX_GPIO_REG_OE);
238 mask_clr |= RB7XX_LED_ACT;
240 /* disable output mode */
241 t = __raw_readl(base + AR71XX_GPIO_REG_OE);
243 __raw_writel(t, base + AR71XX_GPIO_REG_OE);
246 __raw_writel(mask_set, base + AR71XX_GPIO_REG_SET);
247 __raw_writel(mask_clr, base + AR71XX_GPIO_REG_CLEAR);
249 spin_unlock_irqrestore(&lock, flags);
252 static void __init rb750gr3_setup(void)
254 ath79_register_mdio(0, 0x0);
255 mdiobus_register_board_info(rb750g3_mdio_info,
256 ARRAY_SIZE(rb750g3_mdio_info));
258 ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
259 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
260 ath79_eth0_data.phy_mask = BIT(0);
262 ath79_register_eth(0);
264 rb750_leds_data.num_leds = ARRAY_SIZE(rb750gr3_leds);
265 rb750_leds_data.leds = rb750gr3_leds;
266 rb750_leds_data.latch_change = rb750gr3_latch_change;
267 platform_device_register(&rb750_leds_device);
269 rb750_nand_data.nce_line = RB7XX_NAND_NCE;
270 rb750_nand_data.enable_pins = rb750gr3_nand_enable_pins;
271 rb750_nand_data.disable_pins = rb750gr3_nand_disable_pins;
272 rb750_nand_data.latch_change = rb750gr3_latch_change;
273 platform_device_register(&rb750_nand_device);
276 MIPS_MACHINE(ATH79_MACH_RB_750G_R3, "750Gr3", "MikroTik RouterBOARD 750GL",
279 static int decode_rle(char *output, int len, char *in)
282 char *end = output + len;
295 } else if (*in > 0) {
309 #define RB751_HARDCONFIG 0x1f00b000
310 #define RB751_MAC_ADDRESS_OFFSET 0xE80
311 #define RB751_CALDATA_OFFSET 0x27C
313 static void __init rb751_wlan_setup(void)
315 u8 *hardconfig = (u8 *) KSEG1ADDR(RB751_HARDCONFIG);
316 struct ath9k_platform_data *wmac_data;
319 wmac_data = ap9x_pci_get_wmac_data(0);
321 pr_err("rb75x: unable to get address of wlan data\n");
325 ap9x_pci_setup_wmac_led_pin(0, 9);
327 dec_size = decode_rle((char *) wmac_data->eeprom_data,
328 sizeof(wmac_data->eeprom_data),
329 hardconfig + RB751_CALDATA_OFFSET);
330 if (dec_size != sizeof(wmac_data->eeprom_data)) {
331 pr_err("rb75x: unable to decode wlan eeprom data\n");
335 ap91_pci_init(NULL, hardconfig + RB751_MAC_ADDRESS_OFFSET);
338 static void __init rb751_setup(void)
341 ath79_register_usb();
345 MIPS_MACHINE(ATH79_MACH_RB_751, "751", "MikroTik RouterBOARD 751",
348 static void __init rb751g_setup(void)
351 ath79_register_usb();
355 MIPS_MACHINE(ATH79_MACH_RB_751G, "751g", "MikroTik RouterBOARD 751G",