ar71xx: override lan port names on the RB750
[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 "dev-ap91-eth.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 const char *rb750_port_names[AP91_ETH_NUM_PORT_NAMES] __initdata = {
59 "port5",
60 "port4",
61 "port3",
62 "port2",
63 };
64
65 static struct platform_device rb750_nand_device = {
66 .name = "rb750-nand",
67 .id = -1,
68 };
69
70 int rb750_latch_change(u32 mask_clr, u32 mask_set)
71 {
72 static DEFINE_SPINLOCK(lock);
73 static u32 latch_set = RB750_LED_BITS | RB750_LVC573_LE;
74 static u32 latch_oe;
75 static u32 latch_clr;
76 unsigned long flags;
77 u32 t;
78 int ret = 0;
79
80 spin_lock_irqsave(&lock, flags);
81
82 if ((mask_clr & BIT(31)) != 0 &&
83 (latch_set & RB750_LVC573_LE) == 0) {
84 goto unlock;
85 }
86
87 latch_set = (latch_set | mask_set) & ~mask_clr;
88 latch_clr = (latch_clr | mask_clr) & ~mask_set;
89
90 if (latch_oe == 0)
91 latch_oe = __raw_readl(ar71xx_gpio_base + GPIO_REG_OE);
92
93 if (likely(latch_set & RB750_LVC573_LE)) {
94 void __iomem *base = ar71xx_gpio_base;
95
96 t = __raw_readl(base + GPIO_REG_OE);
97 t |= mask_clr | latch_oe | mask_set;
98
99 __raw_writel(t, base + GPIO_REG_OE);
100 __raw_writel(latch_clr, base + GPIO_REG_CLEAR);
101 __raw_writel(latch_set, base + GPIO_REG_SET);
102 } else if (mask_clr & RB750_LVC573_LE) {
103 void __iomem *base = ar71xx_gpio_base;
104
105 latch_oe = __raw_readl(base + GPIO_REG_OE);
106 __raw_writel(RB750_LVC573_LE, base + GPIO_REG_CLEAR);
107 /* flush write */
108 __raw_readl(base + GPIO_REG_CLEAR);
109 }
110
111 ret = 1;
112
113 unlock:
114 spin_unlock_irqrestore(&lock, flags);
115 return ret;
116 }
117 EXPORT_SYMBOL_GPL(rb750_latch_change);
118
119 static void __init rb750_setup(void)
120 {
121 ar71xx_gpio_function_disable(AR724X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
122 AR724X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
123 AR724X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
124 AR724X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
125 AR724X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
126
127 ap91_eth_init(NULL, rb750_port_names);
128 platform_device_register(&rb750_leds_device);
129 platform_device_register(&rb750_nand_device);
130 }
131
132 MIPS_MACHINE(AR71XX_MACH_RB_750, "750i", "MikroTik RouterBOARD 750",
133 rb750_setup);