ar71xx: sync ethernet driver changes with trunk to fix MDIO issues on ar7240
[10.03/openwrt.git] / target / linux / ar71xx / files / arch / mips / ar71xx / mach-rb750.c
1 /*
2  *  MikroTik RouterBOARD 750 support
3  *
4  *  Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
5  *
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.
9  */
10
11 #include <linux/platform_device.h>
12 #include <asm/mach-ar71xx/ar71xx.h>
13 #include <asm/mach-ar71xx/mach-rb750.h>
14
15 #include "devices.h"
16 #include "machtype.h"
17
18 static struct rb750_led_data rb750_leds[] = {
19         {
20                 .name           = "rb750:green:act",
21                 .mask           = RB750_LED_ACT,
22                 .active_low     = 1,
23         }, {
24                 .name           = "rb750:green:port1",
25                 .mask           = RB750_LED_PORT5,
26                 .active_low     = 1,
27         }, {
28                 .name           = "rb750:green:port2",
29                 .mask           = RB750_LED_PORT4,
30                 .active_low     = 1,
31         }, {
32                 .name           = "rb750:green:port3",
33                 .mask           = RB750_LED_PORT3,
34                 .active_low     = 1,
35         }, {
36                 .name           = "rb750:green:port4",
37                 .mask           = RB750_LED_PORT2,
38                 .active_low     = 1,
39         }, {
40                 .name           = "rb750:green:port5",
41                 .mask           = RB750_LED_PORT1,
42                 .active_low     = 1,
43         }
44 };
45
46 static struct rb750_led_platform_data rb750_leds_data = {
47         .num_leds       = ARRAY_SIZE(rb750_leds),
48         .leds           = rb750_leds,
49 };
50
51 static struct platform_device rb750_leds_device = {
52         .name   = "leds-rb750",
53         .dev    = {
54                 .platform_data = &rb750_leds_data,
55         }
56 };
57
58 static struct platform_device rb750_nand_device = {
59         .name   = "rb750-nand",
60         .id     = -1,
61 };
62
63 int rb750_latch_change(u32 mask_clr, u32 mask_set)
64 {
65         static DEFINE_SPINLOCK(lock);
66         static u32 latch_set = RB750_LED_BITS | RB750_LVC573_LE;
67         static u32 latch_oe;
68         static u32 latch_clr;
69         unsigned long flags;
70         u32 t;
71         int ret = 0;
72
73         spin_lock_irqsave(&lock, flags);
74
75         if ((mask_clr & BIT(31)) != 0 &&
76             (latch_set & RB750_LVC573_LE) == 0) {
77                 goto unlock;
78         }
79
80         latch_set = (latch_set | mask_set) & ~mask_clr;
81         latch_clr = (latch_clr | mask_clr) & ~mask_set;
82
83         if (latch_oe == 0)
84                 latch_oe = __raw_readl(ar71xx_gpio_base + GPIO_REG_OE);
85
86         if (likely(latch_set & RB750_LVC573_LE)) {
87                 void __iomem *base = ar71xx_gpio_base;
88
89                 t = __raw_readl(base + GPIO_REG_OE);
90                 t |= mask_clr | latch_oe | mask_set;
91
92                 __raw_writel(t, base + GPIO_REG_OE);
93                 __raw_writel(latch_clr, base + GPIO_REG_CLEAR);
94                 __raw_writel(latch_set, base + GPIO_REG_SET);
95         } else if (mask_clr & RB750_LVC573_LE) {
96                 void __iomem *base = ar71xx_gpio_base;
97
98                 latch_oe = __raw_readl(base + GPIO_REG_OE);
99                 __raw_writel(RB750_LVC573_LE, base + GPIO_REG_CLEAR);
100                 /* flush write */
101                 __raw_readl(base + GPIO_REG_CLEAR);
102         }
103
104         ret = 1;
105
106  unlock:
107         spin_unlock_irqrestore(&lock, flags);
108         return ret;
109 }
110 EXPORT_SYMBOL_GPL(rb750_latch_change);
111
112 static void __init rb750_setup(void)
113 {
114         ar71xx_gpio_function_disable(AR724X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
115                                      AR724X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
116                                      AR724X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
117                                      AR724X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
118                                      AR724X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
119
120         /* WAN port */
121         ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
122         ar71xx_eth0_data.speed = SPEED_100;
123         ar71xx_eth0_data.duplex = DUPLEX_FULL;
124         ar71xx_eth0_data.phy_mask = BIT(4);
125
126         /* LAN ports */
127         ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
128         ar71xx_eth1_data.speed = SPEED_1000;
129         ar71xx_eth1_data.duplex = DUPLEX_FULL;
130         ar71xx_eth1_data.has_ar7240_switch = 1;
131
132         ar71xx_add_device_mdio(0x0);
133         ar71xx_add_device_eth(1);
134         ar71xx_add_device_eth(0);
135
136         platform_device_register(&rb750_leds_device);
137         platform_device_register(&rb750_nand_device);
138 }
139
140 MIPS_MACHINE(AR71XX_MACH_RB_750, "750i", "MikroTik RouterBOARD 750",
141              rb750_setup);