ar71xx: change mac address initialization
[openwrt/svn-archive/archive.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 "machtype.h"
16 #include "devices.h"
17 #include "dev-ap91-eth.h"
18
19 static struct rb750_led_data rb750_leds[] = {
20 {
21 .name = "rb750:green:act",
22 .mask = RB750_LED_ACT,
23 .active_low = 1,
24 }, {
25 .name = "rb750:green:port1",
26 .mask = RB750_LED_PORT5,
27 .active_low = 1,
28 }, {
29 .name = "rb750:green:port2",
30 .mask = RB750_LED_PORT4,
31 .active_low = 1,
32 }, {
33 .name = "rb750:green:port3",
34 .mask = RB750_LED_PORT3,
35 .active_low = 1,
36 }, {
37 .name = "rb750:green:port4",
38 .mask = RB750_LED_PORT2,
39 .active_low = 1,
40 }, {
41 .name = "rb750:green:port5",
42 .mask = RB750_LED_PORT1,
43 .active_low = 1,
44 }
45 };
46
47 static struct rb750_led_platform_data rb750_leds_data = {
48 .num_leds = ARRAY_SIZE(rb750_leds),
49 .leds = rb750_leds,
50 };
51
52 static struct platform_device rb750_leds_device = {
53 .name = "leds-rb750",
54 .dev = {
55 .platform_data = &rb750_leds_data,
56 }
57 };
58
59 static const char *rb750_port_names[AP91_ETH_NUM_PORT_NAMES] __initdata = {
60 "port5",
61 "port4",
62 "port3",
63 "port2",
64 };
65
66 static struct platform_device rb750_nand_device = {
67 .name = "rb750-nand",
68 .id = -1,
69 };
70
71 int rb750_latch_change(u32 mask_clr, u32 mask_set)
72 {
73 static DEFINE_SPINLOCK(lock);
74 static u32 latch_set = RB750_LED_BITS | RB750_LVC573_LE;
75 static u32 latch_oe;
76 static u32 latch_clr;
77 unsigned long flags;
78 u32 t;
79 int ret = 0;
80
81 spin_lock_irqsave(&lock, flags);
82
83 if ((mask_clr & BIT(31)) != 0 &&
84 (latch_set & RB750_LVC573_LE) == 0) {
85 goto unlock;
86 }
87
88 latch_set = (latch_set | mask_set) & ~mask_clr;
89 latch_clr = (latch_clr | mask_clr) & ~mask_set;
90
91 if (latch_oe == 0)
92 latch_oe = __raw_readl(ar71xx_gpio_base + GPIO_REG_OE);
93
94 if (likely(latch_set & RB750_LVC573_LE)) {
95 void __iomem *base = ar71xx_gpio_base;
96
97 t = __raw_readl(base + GPIO_REG_OE);
98 t |= mask_clr | latch_oe | mask_set;
99
100 __raw_writel(t, base + GPIO_REG_OE);
101 __raw_writel(latch_clr, base + GPIO_REG_CLEAR);
102 __raw_writel(latch_set, base + GPIO_REG_SET);
103 } else if (mask_clr & RB750_LVC573_LE) {
104 void __iomem *base = ar71xx_gpio_base;
105
106 latch_oe = __raw_readl(base + GPIO_REG_OE);
107 __raw_writel(RB750_LVC573_LE, base + GPIO_REG_CLEAR);
108 /* flush write */
109 __raw_readl(base + GPIO_REG_CLEAR);
110 }
111
112 ret = 1;
113
114 unlock:
115 spin_unlock_irqrestore(&lock, flags);
116 return ret;
117 }
118 EXPORT_SYMBOL_GPL(rb750_latch_change);
119
120 static void __init rb750_setup(void)
121 {
122 ar71xx_gpio_function_disable(AR724X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
123 AR724X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
124 AR724X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
125 AR724X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
126 AR724X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
127
128 ar71xx_init_mac(ar71xx_eth0_data.mac_addr, ar71xx_mac_base, 0);
129 ar71xx_init_mac(ar71xx_eth1_data.mac_addr, ar71xx_mac_base, 1);
130 ap91_eth_init(rb750_port_names);
131
132 platform_device_register(&rb750_leds_device);
133 platform_device_register(&rb750_nand_device);
134 }
135
136 MIPS_MACHINE(AR71XX_MACH_RB_750, "750i", "MikroTik RouterBOARD 750",
137 rb750_setup);