ar71xx: add platform data for the RB750 NAND driver
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-rb750.c
1 /*
2 * MikroTik RouterBOARD 750/750GL support
3 *
4 * Copyright (C) 2010-2012 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/export.h>
12 #include <linux/platform_device.h>
13
14 #include <asm/mach-ath79/ar71xx_regs.h>
15 #include <asm/mach-ath79/ath79.h>
16 #include <asm/mach-ath79/mach-rb750.h>
17
18 #include "common.h"
19 #include "dev-eth.h"
20 #include "machtypes.h"
21
22 static struct rb750_led_data rb750_leds[] = {
23 {
24 .name = "rb750:green:act",
25 .mask = RB750_LED_ACT,
26 .active_low = 1,
27 }, {
28 .name = "rb750:green:port1",
29 .mask = RB750_LED_PORT5,
30 .active_low = 1,
31 }, {
32 .name = "rb750:green:port2",
33 .mask = RB750_LED_PORT4,
34 .active_low = 1,
35 }, {
36 .name = "rb750:green:port3",
37 .mask = RB750_LED_PORT3,
38 .active_low = 1,
39 }, {
40 .name = "rb750:green:port4",
41 .mask = RB750_LED_PORT2,
42 .active_low = 1,
43 }, {
44 .name = "rb750:green:port5",
45 .mask = RB750_LED_PORT1,
46 .active_low = 1,
47 }
48 };
49
50 static struct rb750_led_platform_data rb750_leds_data = {
51 .num_leds = ARRAY_SIZE(rb750_leds),
52 .leds = rb750_leds,
53 };
54
55 static struct platform_device rb750_leds_device = {
56 .name = "leds-rb750",
57 .dev = {
58 .platform_data = &rb750_leds_data,
59 }
60 };
61
62 static struct rb7xx_nand_platform_data rb750_nand_data;
63 static struct platform_device rb750_nand_device = {
64 .name = "rb750-nand",
65 .id = -1,
66 .dev = {
67 .platform_data = &rb750_nand_data,
68 }
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(ath79_gpio_base + AR71XX_GPIO_REG_OE);
93
94 if (likely(latch_set & RB750_LVC573_LE)) {
95 void __iomem *base = ath79_gpio_base;
96
97 t = __raw_readl(base + AR71XX_GPIO_REG_OE);
98 t |= mask_clr | latch_oe | mask_set;
99
100 __raw_writel(t, base + AR71XX_GPIO_REG_OE);
101 __raw_writel(latch_clr, base + AR71XX_GPIO_REG_CLEAR);
102 __raw_writel(latch_set, base + AR71XX_GPIO_REG_SET);
103 } else if (mask_clr & RB750_LVC573_LE) {
104 void __iomem *base = ath79_gpio_base;
105
106 latch_oe = __raw_readl(base + AR71XX_GPIO_REG_OE);
107 __raw_writel(RB750_LVC573_LE, base + AR71XX_GPIO_REG_CLEAR);
108 /* flush write */
109 __raw_readl(base + AR71XX_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 rb750_nand_enable_pins(void)
121 {
122 rb750_latch_change(RB750_LVC573_LE, 0);
123 ath79_gpio_function_setup(AR724X_GPIO_FUNC_JTAG_DISABLE,
124 AR724X_GPIO_FUNC_SPI_EN);
125 }
126
127 static void rb750_nand_disable_pins(void)
128 {
129 ath79_gpio_function_setup(AR724X_GPIO_FUNC_SPI_EN,
130 AR724X_GPIO_FUNC_JTAG_DISABLE);
131 rb750_latch_change(0, RB750_LVC573_LE);
132 }
133
134 static void rb750_nand_latch_change(u32 clear, u32 set)
135 {
136 rb750_latch_change(clear, set);
137 }
138
139 static void __init rb750_setup(void)
140 {
141 ath79_gpio_function_disable(AR724X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
142 AR724X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
143 AR724X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
144 AR724X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
145 AR724X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
146
147 ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
148 ath79_init_mac(ath79_eth1_data.mac_addr, ath79_mac_base, 1);
149
150 ath79_register_mdio(0, 0x0);
151
152 /* LAN ports */
153 ath79_register_eth(1);
154
155 /* WAN port */
156 ath79_register_eth(0);
157
158 platform_device_register(&rb750_leds_device);
159
160 rb750_nand_data.nce_line = RB750_NAND_NCE;
161 rb750_nand_data.enable_pins = rb750_nand_enable_pins;
162 rb750_nand_data.disable_pins = rb750_nand_disable_pins;
163 rb750_nand_data.latch_change = rb750_nand_latch_change;
164 platform_device_register(&rb750_nand_device);
165 }
166
167 MIPS_MACHINE(ATH79_MACH_RB_750, "750i", "MikroTik RouterBOARD 750",
168 rb750_setup);