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/platform_device.h>
13 #include <linux/phy.h>
14 #include <linux/ar8216_platform.h>
16 #include <asm/mach-ath79/ar71xx_regs.h>
17 #include <asm/mach-ath79/ath79.h>
18 #include <asm/mach-ath79/mach-rb750.h>
22 #include "machtypes.h"
24 static struct rb750_led_data rb750_leds
[] = {
26 .name
= "rb750:green:act",
27 .mask
= RB750_LED_ACT
,
30 .name
= "rb750:green:port1",
31 .mask
= RB750_LED_PORT5
,
34 .name
= "rb750:green:port2",
35 .mask
= RB750_LED_PORT4
,
38 .name
= "rb750:green:port3",
39 .mask
= RB750_LED_PORT3
,
42 .name
= "rb750:green:port4",
43 .mask
= RB750_LED_PORT2
,
46 .name
= "rb750:green:port5",
47 .mask
= RB750_LED_PORT1
,
52 static struct rb750_led_data rb750gr3_leds
[] = {
54 .name
= "rb750:green:act",
55 .mask
= RB7XX_LED_ACT
,
60 static struct rb750_led_platform_data rb750_leds_data
;
61 static struct platform_device rb750_leds_device
= {
64 .platform_data
= &rb750_leds_data
,
68 static struct rb7xx_nand_platform_data rb750_nand_data
;
69 static struct platform_device rb750_nand_device
= {
73 .platform_data
= &rb750_nand_data
,
77 static void rb750_latch_change(u32 mask_clr
, u32 mask_set
)
79 static DEFINE_SPINLOCK(lock
);
80 static u32 latch_set
= RB750_LED_BITS
| RB750_LVC573_LE
;
86 spin_lock_irqsave(&lock
, flags
);
88 if ((mask_clr
& BIT(31)) != 0 &&
89 (latch_set
& RB750_LVC573_LE
) == 0) {
93 latch_set
= (latch_set
| mask_set
) & ~mask_clr
;
94 latch_clr
= (latch_clr
| mask_clr
) & ~mask_set
;
97 latch_oe
= __raw_readl(ath79_gpio_base
+ AR71XX_GPIO_REG_OE
);
99 if (likely(latch_set
& RB750_LVC573_LE
)) {
100 void __iomem
*base
= ath79_gpio_base
;
102 t
= __raw_readl(base
+ AR71XX_GPIO_REG_OE
);
103 t
|= mask_clr
| latch_oe
| mask_set
;
105 __raw_writel(t
, base
+ AR71XX_GPIO_REG_OE
);
106 __raw_writel(latch_clr
, base
+ AR71XX_GPIO_REG_CLEAR
);
107 __raw_writel(latch_set
, base
+ AR71XX_GPIO_REG_SET
);
108 } else if (mask_clr
& RB750_LVC573_LE
) {
109 void __iomem
*base
= ath79_gpio_base
;
111 latch_oe
= __raw_readl(base
+ AR71XX_GPIO_REG_OE
);
112 __raw_writel(RB750_LVC573_LE
, base
+ AR71XX_GPIO_REG_CLEAR
);
114 __raw_readl(base
+ AR71XX_GPIO_REG_CLEAR
);
118 spin_unlock_irqrestore(&lock
, flags
);
121 static void rb750_nand_enable_pins(void)
123 rb750_latch_change(RB750_LVC573_LE
, 0);
124 ath79_gpio_function_setup(AR724X_GPIO_FUNC_JTAG_DISABLE
,
125 AR724X_GPIO_FUNC_SPI_EN
);
128 static void rb750_nand_disable_pins(void)
130 ath79_gpio_function_setup(AR724X_GPIO_FUNC_SPI_EN
,
131 AR724X_GPIO_FUNC_JTAG_DISABLE
);
132 rb750_latch_change(0, RB750_LVC573_LE
);
135 static void __init
rb750_setup(void)
137 ath79_gpio_function_disable(AR724X_GPIO_FUNC_ETH_SWITCH_LED0_EN
|
138 AR724X_GPIO_FUNC_ETH_SWITCH_LED1_EN
|
139 AR724X_GPIO_FUNC_ETH_SWITCH_LED2_EN
|
140 AR724X_GPIO_FUNC_ETH_SWITCH_LED3_EN
|
141 AR724X_GPIO_FUNC_ETH_SWITCH_LED4_EN
);
143 ath79_init_mac(ath79_eth0_data
.mac_addr
, ath79_mac_base
, 0);
144 ath79_init_mac(ath79_eth1_data
.mac_addr
, ath79_mac_base
, 1);
146 ath79_register_mdio(0, 0x0);
149 ath79_register_eth(1);
152 ath79_register_eth(0);
154 rb750_leds_data
.num_leds
= ARRAY_SIZE(rb750_leds
);
155 rb750_leds_data
.leds
= rb750_leds
;
156 rb750_leds_data
.latch_change
= rb750_latch_change
;
157 platform_device_register(&rb750_leds_device
);
159 rb750_nand_data
.nce_line
= RB750_NAND_NCE
;
160 rb750_nand_data
.enable_pins
= rb750_nand_enable_pins
;
161 rb750_nand_data
.disable_pins
= rb750_nand_disable_pins
;
162 rb750_nand_data
.latch_change
= rb750_latch_change
;
163 platform_device_register(&rb750_nand_device
);
166 MIPS_MACHINE(ATH79_MACH_RB_750
, "750i", "MikroTik RouterBOARD 750",
169 static struct ar8327_pad_cfg rb750gr3_ar8327_pad0_cfg
= {
170 .mode
= AR8327_PAD_MAC_RGMII
,
171 .txclk_delay_en
= true,
172 .rxclk_delay_en
= true,
173 .txclk_delay_sel
= AR8327_CLK_DELAY_SEL1
,
174 .rxclk_delay_sel
= AR8327_CLK_DELAY_SEL2
,
177 static struct ar8327_platform_data rb750gr3_ar8327_data
= {
178 .pad0_cfg
= &rb750gr3_ar8327_pad0_cfg
,
181 .speed
= AR8327_PORT_SPEED_100
,
188 static struct mdio_board_info rb750g3_mdio_info
[] = {
190 .bus_id
= "ag71xx-mdio.0",
192 .platform_data
= &rb750gr3_ar8327_data
,
196 static void rb750gr3_nand_enable_pins(void)
198 ath79_gpio_function_setup(AR724X_GPIO_FUNC_JTAG_DISABLE
,
199 AR724X_GPIO_FUNC_SPI_EN
|
200 AR724X_GPIO_FUNC_SPI_CS_EN2
);
203 static void rb750gr3_nand_disable_pins(void)
205 ath79_gpio_function_setup(AR724X_GPIO_FUNC_SPI_EN
|
206 AR724X_GPIO_FUNC_SPI_CS_EN2
,
207 AR724X_GPIO_FUNC_JTAG_DISABLE
);
210 static void rb750gr3_latch_change(u32 mask_clr
, u32 mask_set
)
212 static DEFINE_SPINLOCK(lock
);
213 static u32 latch_set
= RB7XX_LED_ACT
;
214 static u32 latch_clr
;
215 void __iomem
*base
= ath79_gpio_base
;
219 spin_lock_irqsave(&lock
, flags
);
221 latch_set
= (latch_set
| mask_set
) & ~mask_clr
;
222 latch_clr
= (latch_clr
| mask_clr
) & ~mask_set
;
224 mask_set
= latch_set
& (RB7XX_USB_POWERON
| RB7XX_MONITOR
);
225 mask_clr
= latch_clr
& (RB7XX_USB_POWERON
| RB7XX_MONITOR
);
227 if ((latch_set
^ RB7XX_LED_ACT
) & RB7XX_LED_ACT
) {
228 /* enable output mode */
229 t
= __raw_readl(base
+ AR71XX_GPIO_REG_OE
);
231 __raw_writel(t
, base
+ AR71XX_GPIO_REG_OE
);
233 mask_clr
|= RB7XX_LED_ACT
;
235 /* disable output mode */
236 t
= __raw_readl(base
+ AR71XX_GPIO_REG_OE
);
238 __raw_writel(t
, base
+ AR71XX_GPIO_REG_OE
);
241 __raw_writel(mask_set
, base
+ AR71XX_GPIO_REG_SET
);
242 __raw_writel(mask_clr
, base
+ AR71XX_GPIO_REG_CLEAR
);
244 spin_unlock_irqrestore(&lock
, flags
);
247 static void __init
rb750gr3_setup(void)
249 ath79_register_mdio(0, 0x0);
250 mdiobus_register_board_info(rb750g3_mdio_info
,
251 ARRAY_SIZE(rb750g3_mdio_info
));
253 ath79_init_mac(ath79_eth0_data
.mac_addr
, ath79_mac_base
, 0);
254 ath79_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_RGMII
;
255 ath79_eth0_data
.phy_mask
= BIT(0);
257 ath79_register_eth(0);
259 rb750_leds_data
.num_leds
= ARRAY_SIZE(rb750gr3_leds
);
260 rb750_leds_data
.leds
= rb750gr3_leds
;
261 rb750_leds_data
.latch_change
= rb750gr3_latch_change
;
262 platform_device_register(&rb750_leds_device
);
264 rb750_nand_data
.nce_line
= RB7XX_NAND_NCE
;
265 rb750_nand_data
.enable_pins
= rb750gr3_nand_enable_pins
;
266 rb750_nand_data
.disable_pins
= rb750gr3_nand_disable_pins
;
267 rb750_nand_data
.latch_change
= rb750gr3_latch_change
;
268 platform_device_register(&rb750_nand_device
);
271 MIPS_MACHINE(ATH79_MACH_RB_750G_R3
, "750Gr3", "MikroTik RouterBOARD 750GL",