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 ath79_register_usb();
177 MIPS_MACHINE(ATH79_MACH_RB_750
, "750i", "MikroTik RouterBOARD 750",
180 static struct ar8327_pad_cfg rb750gr3_ar8327_pad0_cfg
= {
181 .mode
= AR8327_PAD_MAC_RGMII
,
182 .txclk_delay_en
= true,
183 .rxclk_delay_en
= true,
184 .txclk_delay_sel
= AR8327_CLK_DELAY_SEL1
,
185 .rxclk_delay_sel
= AR8327_CLK_DELAY_SEL2
,
188 static struct ar8327_platform_data rb750gr3_ar8327_data
= {
189 .pad0_cfg
= &rb750gr3_ar8327_pad0_cfg
,
192 .speed
= AR8327_PORT_SPEED_1000
,
199 static struct mdio_board_info rb750g3_mdio_info
[] = {
201 .bus_id
= "ag71xx-mdio.0",
203 .platform_data
= &rb750gr3_ar8327_data
,
207 static void rb750gr3_nand_enable_pins(void)
209 ath79_gpio_function_setup(AR724X_GPIO_FUNC_JTAG_DISABLE
,
210 AR724X_GPIO_FUNC_SPI_EN
|
211 AR724X_GPIO_FUNC_SPI_CS_EN2
);
214 static void rb750gr3_nand_disable_pins(void)
216 ath79_gpio_function_setup(AR724X_GPIO_FUNC_SPI_EN
|
217 AR724X_GPIO_FUNC_SPI_CS_EN2
,
218 AR724X_GPIO_FUNC_JTAG_DISABLE
);
221 static void rb750gr3_latch_change(u32 mask_clr
, u32 mask_set
)
223 static DEFINE_SPINLOCK(lock
);
224 static u32 latch_set
= RB7XX_LED_ACT
;
225 static u32 latch_clr
;
226 void __iomem
*base
= ath79_gpio_base
;
230 spin_lock_irqsave(&lock
, flags
);
232 latch_set
= (latch_set
| mask_set
) & ~mask_clr
;
233 latch_clr
= (latch_clr
| mask_clr
) & ~mask_set
;
235 mask_set
= latch_set
& (RB7XX_USB_POWERON
| RB7XX_MONITOR
);
236 mask_clr
= latch_clr
& (RB7XX_USB_POWERON
| RB7XX_MONITOR
);
238 if ((latch_set
^ RB7XX_LED_ACT
) & RB7XX_LED_ACT
) {
239 /* enable output mode */
240 t
= __raw_readl(base
+ AR71XX_GPIO_REG_OE
);
242 __raw_writel(t
, base
+ AR71XX_GPIO_REG_OE
);
244 mask_clr
|= RB7XX_LED_ACT
;
246 /* disable output mode */
247 t
= __raw_readl(base
+ AR71XX_GPIO_REG_OE
);
249 __raw_writel(t
, base
+ AR71XX_GPIO_REG_OE
);
252 __raw_writel(mask_set
, base
+ AR71XX_GPIO_REG_SET
);
253 __raw_writel(mask_clr
, base
+ AR71XX_GPIO_REG_CLEAR
);
255 spin_unlock_irqrestore(&lock
, flags
);
258 static void __init
rb750gr3_setup(void)
260 ath79_register_mdio(0, 0x0);
261 mdiobus_register_board_info(rb750g3_mdio_info
,
262 ARRAY_SIZE(rb750g3_mdio_info
));
264 ath79_init_mac(ath79_eth0_data
.mac_addr
, ath79_mac_base
, 0);
265 ath79_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_RGMII
;
266 ath79_eth0_data
.phy_mask
= BIT(0);
267 ath79_eth0_pll_data
.pll_1000
= 0x62000000;
269 ath79_register_eth(0);
271 rb750_leds_data
.num_leds
= ARRAY_SIZE(rb750gr3_leds
);
272 rb750_leds_data
.leds
= rb750gr3_leds
;
273 rb750_leds_data
.latch_change
= rb750gr3_latch_change
;
274 platform_device_register(&rb750_leds_device
);
276 rb750_nand_data
.nce_line
= RB7XX_NAND_NCE
;
277 rb750_nand_data
.enable_pins
= rb750gr3_nand_enable_pins
;
278 rb750_nand_data
.disable_pins
= rb750gr3_nand_disable_pins
;
279 rb750_nand_data
.latch_change
= rb750gr3_latch_change
;
280 platform_device_register(&rb750_nand_device
);
283 MIPS_MACHINE(ATH79_MACH_RB_750G_R3
, "750Gr3", "MikroTik RouterBOARD 750GL",
286 #define RB751_HARDCONFIG 0x1f00b000
287 #define RB751_HARDCONFIG_SIZE 0x1000
289 static void __init
rb751_wlan_setup(void)
291 u8
*hardconfig
= (u8
*) KSEG1ADDR(RB751_HARDCONFIG
);
292 struct ath9k_platform_data
*wmac_data
;
299 wmac_data
= ap9x_pci_get_wmac_data(0);
301 pr_err("rb75x: unable to get address of wlan data\n");
305 ap9x_pci_setup_wmac_led_pin(0, 9);
307 err
= routerboot_find_tag(hardconfig
, RB751_HARDCONFIG_SIZE
,
308 RB_ID_WLAN_DATA
, &tag
, &tag_len
);
310 pr_err("rb75x: no calibration data found\n");
314 err
= rle_decode(tag
, tag_len
, (unsigned char *) wmac_data
->eeprom_data
,
315 sizeof(wmac_data
->eeprom_data
), NULL
, NULL
);
317 pr_err("rb75x: unable to decode wlan eeprom data\n");
321 err
= routerboot_find_tag(hardconfig
, RB751_HARDCONFIG_SIZE
,
322 RB_ID_MAC_ADDRESS_PACK
, &mac
, &mac_len
);
324 pr_err("rb75x: no mac address found\n");
328 ap91_pci_init(NULL
, mac
);
331 static void __init
rb751_setup(void)
334 ath79_register_usb();
338 MIPS_MACHINE(ATH79_MACH_RB_751
, "751", "MikroTik RouterBOARD 751",
341 static void __init
rb751g_setup(void)
344 ath79_register_usb();
348 MIPS_MACHINE(ATH79_MACH_RB_751G
, "751g", "MikroTik RouterBOARD 751G",