]> git.karo-electronics.de Git - karo-tx-linux.git/blob - arch/arm/mach-kirkwood/board-dnskw.c
Merge tag 'v3.6-rc5' into for-linus
[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/ata_platform.h>
18 #include <linux/mv643xx_eth.h>
19 #include <linux/of.h>
20 #include <linux/gpio.h>
21 #include <linux/input.h>
22 #include <linux/gpio-fan.h>
23 #include <linux/leds.h>
24 #include <asm/mach-types.h>
25 #include <asm/mach/arch.h>
26 #include <asm/mach/map.h>
27 #include <mach/kirkwood.h>
28 #include <mach/bridge-regs.h>
29 #include "common.h"
30 #include "mpp.h"
31
32 static struct mv643xx_eth_platform_data dnskw_ge00_data = {
33         .phy_addr       = MV643XX_ETH_PHY_ADDR(8),
34 };
35
36 static unsigned int dnskw_mpp_config[] __initdata = {
37         MPP13_UART1_TXD,        /* Custom ... */
38         MPP14_UART1_RXD,        /* ... Controller (DNS-320 only) */
39         MPP20_SATA1_ACTn,       /* LED: White Right HDD */
40         MPP21_SATA0_ACTn,       /* LED: White Left HDD */
41         MPP24_GPIO,
42         MPP25_GPIO,
43         MPP26_GPIO,     /* LED: Power */
44         MPP27_GPIO,     /* LED: Red Right HDD */
45         MPP28_GPIO,     /* LED: Red Left HDD */
46         MPP29_GPIO,     /* LED: Red USB (DNS-325 only) */
47         MPP30_GPIO,
48         MPP31_GPIO,
49         MPP32_GPIO,
50         MPP33_GPO,
51         MPP34_GPIO,     /* Button: Front power */
52         MPP35_GPIO,     /* LED: Red USB (DNS-320 only) */
53         MPP36_GPIO,     /* Power: Turn off board */
54         MPP37_GPIO,     /* Power: Turn back on after power failure */
55         MPP38_GPIO,
56         MPP39_GPIO,     /* Power: SATA0 */
57         MPP40_GPIO,     /* Power: SATA1 */
58         MPP41_GPIO,     /* SATA0 present */
59         MPP42_GPIO,     /* SATA1 present */
60         MPP43_GPIO,     /* LED: White USB */
61         MPP44_GPIO,     /* Fan: Tachometer Pin */
62         MPP45_GPIO,     /* Fan: high speed */
63         MPP46_GPIO,     /* Fan: low speed */
64         MPP47_GPIO,     /* Button: Back unmount */
65         MPP48_GPIO,     /* Button: Back reset */
66         MPP49_GPIO,     /* Temp Alarm (DNS-325) Pin of U5 (DNS-320) */
67         0
68 };
69
70 /* Fan: ADDA AD045HB-G73 40mm 6000rpm@5v */
71 static struct gpio_fan_speed dnskw_fan_speed[] = {
72         {    0,  0 },
73         { 3000,  1 },
74         { 6000,  2 },
75 };
76 static unsigned dnskw_fan_pins[] = {46, 45};
77
78 static struct gpio_fan_platform_data dnskw_fan_data = {
79         .num_ctrl       = ARRAY_SIZE(dnskw_fan_pins),
80         .ctrl           = dnskw_fan_pins,
81         .num_speed      = ARRAY_SIZE(dnskw_fan_speed),
82         .speed          = dnskw_fan_speed,
83 };
84
85 static struct platform_device dnskw_fan_device = {
86         .name   = "gpio-fan",
87         .id     = -1,
88         .dev    = {
89                 .platform_data  = &dnskw_fan_data,
90         },
91 };
92
93 static void dnskw_power_off(void)
94 {
95         gpio_set_value(36, 1);
96 }
97
98 /* Register any GPIO for output and set the value */
99 static void __init dnskw_gpio_register(unsigned gpio, char *name, int def)
100 {
101         if (gpio_request(gpio, name) == 0 &&
102             gpio_direction_output(gpio, 0) == 0) {
103                 gpio_set_value(gpio, def);
104                 if (gpio_export(gpio, 0) != 0)
105                         pr_err("dnskw: Failed to export GPIO %s\n", name);
106         } else
107                 pr_err("dnskw: Failed to register %s\n", name);
108 }
109
110 void __init dnskw_init(void)
111 {
112         kirkwood_mpp_conf(dnskw_mpp_config);
113
114         kirkwood_ehci_init();
115         kirkwood_ge00_init(&dnskw_ge00_data);
116
117         platform_device_register(&dnskw_fan_device);
118
119         /* Register power-off GPIO. */
120         if (gpio_request(36, "dnskw:power:off") == 0
121             && gpio_direction_output(36, 0) == 0)
122                 pm_power_off = dnskw_power_off;
123         else
124                 pr_err("dnskw: failed to configure power-off GPIO\n");
125
126         /* Ensure power is supplied to both HDDs */
127         dnskw_gpio_register(39, "dnskw:power:sata0", 1);
128         dnskw_gpio_register(40, "dnskw:power:sata1", 1);
129
130         /* Set NAS to turn back on after a power failure */
131         dnskw_gpio_register(37, "dnskw:power:recover", 1);
132 }