2 * Copyright 2012 (C), Jamie Lentin <jm@lentin.co.uk>
4 * arch/arm/mach-kirkwood/board-dnskw.c
6 * D-link DNS-320 & DNS-325 NAS Init for drivers not converted to
7 * flattened device tree yet.
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.
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>
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>
34 static struct mv643xx_eth_platform_data dnskw_ge00_data
= {
35 .phy_addr
= MV643XX_ETH_PHY_ADDR(8),
38 static struct mv_sata_platform_data dnskw_sata_data
= {
42 static unsigned int dnskw_mpp_config
[] __initdata
= {
43 MPP13_UART1_TXD
, /* Custom ... */
44 MPP14_UART1_RXD
, /* ... Controller (DNS-320 only) */
45 MPP20_SATA1_ACTn
, /* LED: White Right HDD */
46 MPP21_SATA0_ACTn
, /* LED: White Left HDD */
49 MPP26_GPIO
, /* LED: Power */
50 MPP27_GPIO
, /* LED: Red Right HDD */
51 MPP28_GPIO
, /* LED: Red Left HDD */
52 MPP29_GPIO
, /* LED: Red USB (DNS-325 only) */
57 MPP34_GPIO
, /* Button: Front power */
58 MPP35_GPIO
, /* LED: Red USB (DNS-320 only) */
59 MPP36_GPIO
, /* Power: Turn off board */
60 MPP37_GPIO
, /* Power: Turn back on after power failure */
62 MPP39_GPIO
, /* Power: SATA0 */
63 MPP40_GPIO
, /* Power: SATA1 */
64 MPP41_GPIO
, /* SATA0 present */
65 MPP42_GPIO
, /* SATA1 present */
66 MPP43_GPIO
, /* LED: White USB */
67 MPP44_GPIO
, /* Fan: Tachometer Pin */
68 MPP45_GPIO
, /* Fan: high speed */
69 MPP46_GPIO
, /* Fan: low speed */
70 MPP47_GPIO
, /* Button: Back unmount */
71 MPP48_GPIO
, /* Button: Back reset */
72 MPP49_GPIO
, /* Temp Alarm (DNS-325) Pin of U5 (DNS-320) */
76 static struct gpio_led dns325_led_pins
[] = {
78 .name
= "dns325:white:power",
81 .default_trigger
= "default-on",
84 .name
= "dns325:white:usb",
89 .name
= "dns325:red:l_hdd",
94 .name
= "dns325:red:r_hdd",
99 .name
= "dns325:red:usb",
105 static struct gpio_led_platform_data dns325_led_data
= {
106 .num_leds
= ARRAY_SIZE(dns325_led_pins
),
107 .leds
= dns325_led_pins
,
110 static struct platform_device dns325_led_device
= {
114 .platform_data
= &dns325_led_data
,
118 static struct gpio_led dns320_led_pins
[] = {
120 .name
= "dns320:blue:power",
123 .default_trigger
= "default-on",
126 .name
= "dns320:blue:usb",
131 .name
= "dns320:orange:l_hdd",
136 .name
= "dns320:orange:r_hdd",
141 .name
= "dns320:orange:usb",
147 static struct gpio_led_platform_data dns320_led_data
= {
148 .num_leds
= ARRAY_SIZE(dns320_led_pins
),
149 .leds
= dns320_led_pins
,
152 static struct platform_device dns320_led_device
= {
156 .platform_data
= &dns320_led_data
,
160 static struct i2c_board_info dns325_i2c_board_info
[] __initdata
= {
162 I2C_BOARD_INFO("lm75", 0x48),
164 /* Something at 0x0c also */
167 static struct gpio_keys_button dnskw_button_pins
[] = {
171 .desc
= "Power button",
177 .desc
= "USB unmount button",
183 .desc
= "Reset button",
188 static struct gpio_keys_platform_data dnskw_button_data
= {
189 .buttons
= dnskw_button_pins
,
190 .nbuttons
= ARRAY_SIZE(dnskw_button_pins
),
193 static struct platform_device dnskw_button_device
= {
198 .platform_data
= &dnskw_button_data
,
202 /* Fan: ADDA AD045HB-G73 40mm 6000rpm@5v */
203 static struct gpio_fan_speed dnskw_fan_speed
[] = {
208 static unsigned dnskw_fan_pins
[] = {46, 45};
210 static struct gpio_fan_platform_data dnskw_fan_data
= {
211 .num_ctrl
= ARRAY_SIZE(dnskw_fan_pins
),
212 .ctrl
= dnskw_fan_pins
,
213 .num_speed
= ARRAY_SIZE(dnskw_fan_speed
),
214 .speed
= dnskw_fan_speed
,
217 static struct platform_device dnskw_fan_device
= {
221 .platform_data
= &dnskw_fan_data
,
225 static void dnskw_power_off(void)
227 gpio_set_value(36, 1);
230 /* Register any GPIO for output and set the value */
231 static void __init
dnskw_gpio_register(unsigned gpio
, char *name
, int def
)
233 if (gpio_request(gpio
, name
) == 0 &&
234 gpio_direction_output(gpio
, 0) == 0) {
235 gpio_set_value(gpio
, def
);
236 if (gpio_export(gpio
, 0) != 0)
237 pr_err("dnskw: Failed to export GPIO %s\n", name
);
239 pr_err("dnskw: Failed to register %s\n", name
);
242 void __init
dnskw_init(void)
244 kirkwood_mpp_conf(dnskw_mpp_config
);
246 kirkwood_ehci_init();
247 kirkwood_ge00_init(&dnskw_ge00_data
);
248 kirkwood_sata_init(&dnskw_sata_data
);
251 platform_device_register(&dnskw_button_device
);
252 platform_device_register(&dnskw_fan_device
);
254 if (of_machine_is_compatible("dlink,dns-325")) {
255 i2c_register_board_info(0, dns325_i2c_board_info
,
256 ARRAY_SIZE(dns325_i2c_board_info
));
257 platform_device_register(&dns325_led_device
);
259 } else if (of_machine_is_compatible("dlink,dns-320"))
260 platform_device_register(&dns320_led_device
);
262 /* Register power-off GPIO. */
263 if (gpio_request(36, "dnskw:power:off") == 0
264 && gpio_direction_output(36, 0) == 0)
265 pm_power_off
= dnskw_power_off
;
267 pr_err("dnskw: failed to configure power-off GPIO\n");
269 /* Ensure power is supplied to both HDDs */
270 dnskw_gpio_register(39, "dnskw:power:sata0", 1);
271 dnskw_gpio_register(40, "dnskw:power:sata1", 1);
273 /* Set NAS to turn back on after a power failure */
274 dnskw_gpio_register(37, "dnskw:power:recover", 1);