aboutsummaryrefslogtreecommitdiff
path: root/arch/arm/mach-kirkwood/board-dnskw.c
blob: 4ab35065a144919ac264bd972f125dbf657120de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
 * Copyright 2012 (C), Jamie Lentin <jm@lentin.co.uk>
 *
 * arch/arm/mach-kirkwood/board-dnskw.c
 *
 * D-link DNS-320 & DNS-325 NAS Init for drivers not converted to
 * flattened device tree yet.
 *
 * This file is licensed under the terms of the GNU General Public
 * License version 2.  This program is licensed "as is" without any
 * warranty of any kind, whether express or implied.
 */

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/ata_platform.h>
#include <linux/mv643xx_eth.h>
#include <linux/of.h>
#include <linux/gpio.h>
#include <linux/input.h>
#include <linux/gpio-fan.h>
#include <linux/leds.h>
#include <asm/mach-types.h>
#include <asm/mach/arch.h>
#include <asm/mach/map.h>
#include <mach/kirkwood.h>
#include <mach/bridge-regs.h>
#include "common.h"
#include "mpp.h"

static struct mv643xx_eth_platform_data dnskw_ge00_data = {
	.phy_addr	= MV643XX_ETH_PHY_ADDR(8),
};

static unsigned int dnskw_mpp_config[] __initdata = {
	MPP13_UART1_TXD,	/* Custom ... */
	MPP14_UART1_RXD,	/* ... Controller (DNS-320 only) */
	MPP20_SATA1_ACTn,	/* LED: White Right HDD */
	MPP21_SATA0_ACTn,	/* LED: White Left HDD */
	MPP24_GPIO,
	MPP25_GPIO,
	MPP26_GPIO,	/* LED: Power */
	MPP27_GPIO,	/* LED: Red Right HDD */
	MPP28_GPIO,	/* LED: Red Left HDD */
	MPP29_GPIO,	/* LED: Red USB (DNS-325 only) */
	MPP30_GPIO,
	MPP31_GPIO,
	MPP32_GPIO,
	MPP33_GPO,
	MPP34_GPIO,	/* Button: Front power */
	MPP35_GPIO,	/* LED: Red USB (DNS-320 only) */
	MPP36_GPIO,	/* Power: Turn off board */
	MPP37_GPIO,	/* Power: Turn back on after power failure */
	MPP38_GPIO,
	MPP39_GPIO,	/* Power: SATA0 */
	MPP40_GPIO,	/* Power: SATA1 */
	MPP41_GPIO,	/* SATA0 present */
	MPP42_GPIO,	/* SATA1 present */
	MPP43_GPIO,	/* LED: White USB */
	MPP44_GPIO,	/* Fan: Tachometer Pin */
	MPP45_GPIO,	/* Fan: high speed */
	MPP46_GPIO,	/* Fan: low speed */
	MPP47_GPIO,	/* Button: Back unmount */
	MPP48_GPIO,	/* Button: Back reset */
	MPP49_GPIO,	/* Temp Alarm (DNS-325) Pin of U5 (DNS-320) */
	0
};

/* Fan: ADDA AD045HB-G73 40mm 6000rpm@5v */
static struct gpio_fan_speed dnskw_fan_speed[] = {
	{    0,  0 },
	{ 3000,	 1 },
	{ 6000,	 2 },
};
static unsigned dnskw_fan_pins[] = {46, 45};

static struct gpio_fan_platform_data dnskw_fan_data = {
	.num_ctrl	= ARRAY_SIZE(dnskw_fan_pins),
	.ctrl		= dnskw_fan_pins,
	.num_speed	= ARRAY_SIZE(dnskw_fan_speed),
	.speed		= dnskw_fan_speed,
};

static struct platform_device dnskw_fan_device = {
	.name	= "gpio-fan",
	.id	= -1,
	.dev	= {
		.platform_data	= &dnskw_fan_data,
	},
};

static void dnskw_power_off(void)
{
	gpio_set_value(36, 1);
}

/* Register any GPIO for output and set the value */
static void __init dnskw_gpio_register(unsigned gpio, char *name, int def)
{
	if (gpio_request(gpio, name) == 0 &&
	    gpio_direction_output(gpio, 0) == 0) {
		gpio_set_value(gpio, def);
		if (gpio_export(gpio, 0) != 0)
			pr_err("dnskw: Failed to export GPIO %s\n", name);
	} else
		pr_err("dnskw: Failed to register %s\n", name);
}

void __init dnskw_init(void)
{
	kirkwood_mpp_conf(dnskw_mpp_config);

	kirkwood_ehci_init();
	kirkwood_ge00_init(&dnskw_ge00_data);

	platform_device_register(&dnskw_fan_device);

	/* Register power-off GPIO. */
	if (gpio_request(36, "dnskw:power:off") == 0
	    && gpio_direction_output(36, 0) == 0)
		pm_power_off = dnskw_power_off;
	else
		pr_err("dnskw: failed to configure power-off GPIO\n");

	/* Ensure power is supplied to both HDDs */
	dnskw_gpio_register(39, "dnskw:power:sata0", 1);
	dnskw_gpio_register(40, "dnskw:power:sata1", 1);

	/* Set NAS to turn back on after a power failure */
	dnskw_gpio_register(37, "dnskw:power:recover", 1);
}