]> git.karo-electronics.de Git - karo-tx-linux.git/blob - arch/arm/mach-kirkwood/board-dnskw.c
ARM: Kirkwood: Use DT to configure SATA device.
[karo-tx-linux.git] / arch / arm / mach-kirkwood / board-dnskw.c
1 /*
2  * Copyright 2012 (C), Jamie Lentin <jm@lentin.co.uk>
3  *
4  * arch/arm/mach-kirkwood/board-dnskw.c
5  *
6  * D-link DNS-320 & DNS-325 NAS Init for drivers not converted to
7  * flattened device tree yet.
8  *
9  * This file is licensed under the terms of the GNU General Public
10  * License version 2.  This program is licensed "as is" without any
11  * warranty of any kind, whether express or implied.
12  */
13
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/platform_device.h>
17 #include <linux/i2c.h>
18 #include <linux/ata_platform.h>
19 #include <linux/mv643xx_eth.h>
20 #include <linux/of.h>
21 #include <linux/gpio.h>
22 #include <linux/input.h>
23 #include <linux/gpio_keys.h>
24 #include <linux/gpio-fan.h>
25 #include <linux/leds.h>
26 #include <asm/mach-types.h>
27 #include <asm/mach/arch.h>
28 #include <asm/mach/map.h>
29 #include <mach/kirkwood.h>
30 #include <mach/bridge-regs.h>
31 #include "common.h"
32 #include "mpp.h"
33
34 static struct mv643xx_eth_platform_data dnskw_ge00_data = {
35         .phy_addr       = MV643XX_ETH_PHY_ADDR(8),
36 };
37
38 static unsigned int dnskw_mpp_config[] __initdata = {
39         MPP13_UART1_TXD,        /* Custom ... */
40         MPP14_UART1_RXD,        /* ... Controller (DNS-320 only) */
41         MPP20_SATA1_ACTn,       /* LED: White Right HDD */
42         MPP21_SATA0_ACTn,       /* LED: White Left HDD */
43         MPP24_GPIO,
44         MPP25_GPIO,
45         MPP26_GPIO,     /* LED: Power */
46         MPP27_GPIO,     /* LED: Red Right HDD */
47         MPP28_GPIO,     /* LED: Red Left HDD */
48         MPP29_GPIO,     /* LED: Red USB (DNS-325 only) */
49         MPP30_GPIO,
50         MPP31_GPIO,
51         MPP32_GPIO,
52         MPP33_GPO,
53         MPP34_GPIO,     /* Button: Front power */
54         MPP35_GPIO,     /* LED: Red USB (DNS-320 only) */
55         MPP36_GPIO,     /* Power: Turn off board */
56         MPP37_GPIO,     /* Power: Turn back on after power failure */
57         MPP38_GPIO,
58         MPP39_GPIO,     /* Power: SATA0 */
59         MPP40_GPIO,     /* Power: SATA1 */
60         MPP41_GPIO,     /* SATA0 present */
61         MPP42_GPIO,     /* SATA1 present */
62         MPP43_GPIO,     /* LED: White USB */
63         MPP44_GPIO,     /* Fan: Tachometer Pin */
64         MPP45_GPIO,     /* Fan: high speed */
65         MPP46_GPIO,     /* Fan: low speed */
66         MPP47_GPIO,     /* Button: Back unmount */
67         MPP48_GPIO,     /* Button: Back reset */
68         MPP49_GPIO,     /* Temp Alarm (DNS-325) Pin of U5 (DNS-320) */
69         0
70 };
71
72 static struct gpio_led dns325_led_pins[] = {
73         {
74                 .name   = "dns325:white:power",
75                 .gpio   = 26,
76                 .active_low = 1,
77                 .default_trigger = "default-on",
78         },
79         {
80                 .name   = "dns325:white:usb",
81                 .gpio   = 43,
82                 .active_low = 1,
83         },
84         {
85                 .name   = "dns325:red:l_hdd",
86                 .gpio   = 28,
87                 .active_low = 1,
88         },
89         {
90                 .name   = "dns325:red:r_hdd",
91                 .gpio   = 27,
92                 .active_low = 1,
93         },
94         {
95                 .name   = "dns325:red:usb",
96                 .gpio   = 29,
97                 .active_low = 1,
98         },
99 };
100
101 static struct gpio_led_platform_data dns325_led_data = {
102         .num_leds       = ARRAY_SIZE(dns325_led_pins),
103         .leds           = dns325_led_pins,
104 };
105
106 static struct platform_device dns325_led_device = {
107         .name           = "leds-gpio",
108         .id             = -1,
109         .dev            = {
110                 .platform_data  = &dns325_led_data,
111         },
112 };
113
114 static struct gpio_led dns320_led_pins[] = {
115         {
116                 .name   = "dns320:blue:power",
117                 .gpio   = 26,
118                 .active_low = 1,
119                 .default_trigger = "default-on",
120         },
121         {
122                 .name   = "dns320:blue:usb",
123                 .gpio   = 43,
124                 .active_low = 1,
125         },
126         {
127                 .name   = "dns320:orange:l_hdd",
128                 .gpio   = 28,
129                 .active_low = 1,
130         },
131         {
132                 .name   = "dns320:orange:r_hdd",
133                 .gpio   = 27,
134                 .active_low = 1,
135         },
136         {
137                 .name   = "dns320:orange:usb",
138                 .gpio   = 35,
139                 .active_low = 1,
140         },
141 };
142
143 static struct gpio_led_platform_data dns320_led_data = {
144         .num_leds       = ARRAY_SIZE(dns320_led_pins),
145         .leds           = dns320_led_pins,
146 };
147
148 static struct platform_device dns320_led_device = {
149         .name           = "leds-gpio",
150         .id             = -1,
151         .dev            = {
152                 .platform_data  = &dns320_led_data,
153         },
154 };
155
156 static struct i2c_board_info dns325_i2c_board_info[] __initdata = {
157         {
158                 I2C_BOARD_INFO("lm75", 0x48),
159         },
160         /* Something at 0x0c also */
161 };
162
163 static struct gpio_keys_button dnskw_button_pins[] = {
164         {
165                 .code           = KEY_POWER,
166                 .gpio           = 34,
167                 .desc           = "Power button",
168                 .active_low     = 1,
169         },
170         {
171                 .code           = KEY_EJECTCD,
172                 .gpio           = 47,
173                 .desc           = "USB unmount button",
174                 .active_low     = 1,
175         },
176         {
177                 .code           = KEY_RESTART,
178                 .gpio           = 48,
179                 .desc           = "Reset button",
180                 .active_low     = 1,
181         },
182 };
183
184 static struct gpio_keys_platform_data dnskw_button_data = {
185         .buttons        = dnskw_button_pins,
186         .nbuttons       = ARRAY_SIZE(dnskw_button_pins),
187 };
188
189 static struct platform_device dnskw_button_device = {
190         .name           = "gpio-keys",
191         .id             = -1,
192         .num_resources  = 0,
193         .dev            = {
194                 .platform_data  = &dnskw_button_data,
195         }
196 };
197
198 /* Fan: ADDA AD045HB-G73 40mm 6000rpm@5v */
199 static struct gpio_fan_speed dnskw_fan_speed[] = {
200         {    0,  0 },
201         { 3000,  1 },
202         { 6000,  2 },
203 };
204 static unsigned dnskw_fan_pins[] = {46, 45};
205
206 static struct gpio_fan_platform_data dnskw_fan_data = {
207         .num_ctrl       = ARRAY_SIZE(dnskw_fan_pins),
208         .ctrl           = dnskw_fan_pins,
209         .num_speed      = ARRAY_SIZE(dnskw_fan_speed),
210         .speed          = dnskw_fan_speed,
211 };
212
213 static struct platform_device dnskw_fan_device = {
214         .name   = "gpio-fan",
215         .id     = -1,
216         .dev    = {
217                 .platform_data  = &dnskw_fan_data,
218         },
219 };
220
221 static void dnskw_power_off(void)
222 {
223         gpio_set_value(36, 1);
224 }
225
226 /* Register any GPIO for output and set the value */
227 static void __init dnskw_gpio_register(unsigned gpio, char *name, int def)
228 {
229         if (gpio_request(gpio, name) == 0 &&
230             gpio_direction_output(gpio, 0) == 0) {
231                 gpio_set_value(gpio, def);
232                 if (gpio_export(gpio, 0) != 0)
233                         pr_err("dnskw: Failed to export GPIO %s\n", name);
234         } else
235                 pr_err("dnskw: Failed to register %s\n", name);
236 }
237
238 void __init dnskw_init(void)
239 {
240         kirkwood_mpp_conf(dnskw_mpp_config);
241
242         kirkwood_ehci_init();
243         kirkwood_ge00_init(&dnskw_ge00_data);
244         kirkwood_i2c_init();
245
246         platform_device_register(&dnskw_button_device);
247         platform_device_register(&dnskw_fan_device);
248
249         if (of_machine_is_compatible("dlink,dns-325")) {
250                 i2c_register_board_info(0, dns325_i2c_board_info,
251                                         ARRAY_SIZE(dns325_i2c_board_info));
252                 platform_device_register(&dns325_led_device);
253
254         } else if (of_machine_is_compatible("dlink,dns-320"))
255                 platform_device_register(&dns320_led_device);
256
257         /* Register power-off GPIO. */
258         if (gpio_request(36, "dnskw:power:off") == 0
259             && gpio_direction_output(36, 0) == 0)
260                 pm_power_off = dnskw_power_off;
261         else
262                 pr_err("dnskw: failed to configure power-off GPIO\n");
263
264         /* Ensure power is supplied to both HDDs */
265         dnskw_gpio_register(39, "dnskw:power:sata0", 1);
266         dnskw_gpio_register(40, "dnskw:power:sata1", 1);
267
268         /* Set NAS to turn back on after a power failure */
269         dnskw_gpio_register(37, "dnskw:power:recover", 1);
270 }