Full support for Ginger Console
[linux-ginger.git] / arch / arm / mach-orion5x / d2net-setup.c
blob9d4bf763f25b0cc54e054fe0d45c4112a5e4c860
1 /*
2 * arch/arm/mach-orion5x/d2net-setup.c
4 * LaCie d2Network and Big Disk Network NAS setup
6 * Copyright (C) 2009 Simon Guinot <sguinot@lacie.com>
8 * This file is licensed under the terms of the GNU General Public
9 * License version 2. This program is licensed "as is" without any
10 * warranty of any kind, whether express or implied.
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/platform_device.h>
16 #include <linux/pci.h>
17 #include <linux/irq.h>
18 #include <linux/mtd/physmap.h>
19 #include <linux/mv643xx_eth.h>
20 #include <linux/leds.h>
21 #include <linux/gpio_keys.h>
22 #include <linux/input.h>
23 #include <linux/i2c.h>
24 #include <linux/ata_platform.h>
25 #include <linux/gpio.h>
26 #include <asm/mach-types.h>
27 #include <asm/mach/arch.h>
28 #include <asm/mach/pci.h>
29 #include <mach/orion5x.h>
30 #include "common.h"
31 #include "mpp.h"
33 /*****************************************************************************
34 * LaCie d2 Network Info
35 ****************************************************************************/
38 * 512KB NOR flash Device bus boot chip select
41 #define D2NET_NOR_BOOT_BASE 0xfff80000
42 #define D2NET_NOR_BOOT_SIZE SZ_512K
44 /*****************************************************************************
45 * 512KB NOR Flash on Boot Device
46 ****************************************************************************/
49 * TODO: Check write support on flash MX29LV400CBTC-70G
52 static struct mtd_partition d2net_partitions[] = {
54 .name = "Full512kb",
55 .size = MTDPART_SIZ_FULL,
56 .offset = 0,
57 .mask_flags = MTD_WRITEABLE,
61 static struct physmap_flash_data d2net_nor_flash_data = {
62 .width = 1,
63 .parts = d2net_partitions,
64 .nr_parts = ARRAY_SIZE(d2net_partitions),
67 static struct resource d2net_nor_flash_resource = {
68 .flags = IORESOURCE_MEM,
69 .start = D2NET_NOR_BOOT_BASE,
70 .end = D2NET_NOR_BOOT_BASE
71 + D2NET_NOR_BOOT_SIZE - 1,
74 static struct platform_device d2net_nor_flash = {
75 .name = "physmap-flash",
76 .id = 0,
77 .dev = {
78 .platform_data = &d2net_nor_flash_data,
80 .num_resources = 1,
81 .resource = &d2net_nor_flash_resource,
84 /*****************************************************************************
85 * Ethernet
86 ****************************************************************************/
88 static struct mv643xx_eth_platform_data d2net_eth_data = {
89 .phy_addr = MV643XX_ETH_PHY_ADDR(8),
92 /*****************************************************************************
93 * I2C devices
94 ****************************************************************************/
97 * i2c addr | chip | description
98 * 0x32 | Ricoh 5C372b | RTC
99 * 0x3e | GMT G762 | PWM fan controller
100 * 0x50 | HT24LC08 | eeprom (1kB)
102 * TODO: Add G762 support to the g760a driver.
104 static struct i2c_board_info __initdata d2net_i2c_devices[] = {
106 I2C_BOARD_INFO("rs5c372b", 0x32),
107 }, {
108 I2C_BOARD_INFO("24c08", 0x50),
112 /*****************************************************************************
113 * SATA
114 ****************************************************************************/
116 static struct mv_sata_platform_data d2net_sata_data = {
117 .n_ports = 2,
120 #define D2NET_GPIO_SATA0_POWER 3
121 #define D2NET_GPIO_SATA1_POWER 12
123 static void __init d2net_sata_power_init(void)
125 int err;
127 err = gpio_request(D2NET_GPIO_SATA0_POWER, "SATA0 power");
128 if (err == 0) {
129 err = gpio_direction_output(D2NET_GPIO_SATA0_POWER, 1);
130 if (err)
131 gpio_free(D2NET_GPIO_SATA0_POWER);
133 if (err)
134 pr_err("d2net: failed to configure SATA0 power GPIO\n");
136 err = gpio_request(D2NET_GPIO_SATA1_POWER, "SATA1 power");
137 if (err == 0) {
138 err = gpio_direction_output(D2NET_GPIO_SATA1_POWER, 1);
139 if (err)
140 gpio_free(D2NET_GPIO_SATA1_POWER);
142 if (err)
143 pr_err("d2net: failed to configure SATA1 power GPIO\n");
146 /*****************************************************************************
147 * GPIO LED's
148 ****************************************************************************/
151 * The blue front LED is wired to the CPLD and can blink in relation with the
152 * SATA activity. This feature is disabled to make this LED compatible with
153 * the leds-gpio driver: MPP14 and MPP15 are configured to act like output
154 * GPIO's and have to stay in an active state. This is needed to set the blue
155 * LED in a "fix on" state regardless of the SATA activity.
157 * The following array detail the different LED registers and the combination
158 * of their possible values:
160 * led_off | blink_ctrl | SATA active | LED state
161 * | | |
162 * 1 | x | x | off
163 * 0 | 0 | 0 | off
164 * 0 | 1 | 0 | blink (rate 300ms)
165 * 0 | x | 1 | on
167 * Notes: The blue and the red front LED's can't be on at the same time.
168 * Red LED have priority.
171 #define D2NET_GPIO_RED_LED 6
172 #define D2NET_GPIO_BLUE_LED_BLINK_CTRL 16
173 #define D2NET_GPIO_BLUE_LED_OFF 23
174 #define D2NET_GPIO_SATA0_ACT 14
175 #define D2NET_GPIO_SATA1_ACT 15
177 static struct gpio_led d2net_leds[] = {
179 .name = "d2net:blue:power",
180 .gpio = D2NET_GPIO_BLUE_LED_OFF,
181 .active_low = 1,
184 .name = "d2net:red:fail",
185 .gpio = D2NET_GPIO_RED_LED,
189 static struct gpio_led_platform_data d2net_led_data = {
190 .num_leds = ARRAY_SIZE(d2net_leds),
191 .leds = d2net_leds,
194 static struct platform_device d2net_gpio_leds = {
195 .name = "leds-gpio",
196 .id = -1,
197 .dev = {
198 .platform_data = &d2net_led_data,
202 static void __init d2net_gpio_leds_init(void)
204 /* Configure GPIO over MPP max number. */
205 orion_gpio_set_valid(D2NET_GPIO_BLUE_LED_OFF, 1);
207 if (gpio_request(D2NET_GPIO_SATA0_ACT, "LED SATA0 activity") != 0)
208 return;
209 if (gpio_direction_output(D2NET_GPIO_SATA0_ACT, 1) != 0)
210 goto err_free_1;
211 if (gpio_request(D2NET_GPIO_SATA1_ACT, "LED SATA1 activity") != 0)
212 goto err_free_1;
213 if (gpio_direction_output(D2NET_GPIO_SATA1_ACT, 1) != 0)
214 goto err_free_2;
215 platform_device_register(&d2net_gpio_leds);
216 return;
218 err_free_2:
219 gpio_free(D2NET_GPIO_SATA1_ACT);
220 err_free_1:
221 gpio_free(D2NET_GPIO_SATA0_ACT);
222 return;
225 /****************************************************************************
226 * GPIO keys
227 ****************************************************************************/
229 #define D2NET_GPIO_PUSH_BUTTON 18
230 #define D2NET_GPIO_POWER_SWITCH_ON 8
231 #define D2NET_GPIO_POWER_SWITCH_OFF 9
233 #define D2NET_SWITCH_POWER_ON 0x1
234 #define D2NET_SWITCH_POWER_OFF 0x2
236 static struct gpio_keys_button d2net_buttons[] = {
238 .type = EV_SW,
239 .code = D2NET_SWITCH_POWER_OFF,
240 .gpio = D2NET_GPIO_POWER_SWITCH_OFF,
241 .desc = "Power rocker switch (auto|off)",
242 .active_low = 0,
245 .type = EV_SW,
246 .code = D2NET_SWITCH_POWER_ON,
247 .gpio = D2NET_GPIO_POWER_SWITCH_ON,
248 .desc = "Power rocker switch (on|auto)",
249 .active_low = 0,
252 .type = EV_KEY,
253 .code = KEY_POWER,
254 .gpio = D2NET_GPIO_PUSH_BUTTON,
255 .desc = "Front Push Button",
256 .active_low = 0,
260 static struct gpio_keys_platform_data d2net_button_data = {
261 .buttons = d2net_buttons,
262 .nbuttons = ARRAY_SIZE(d2net_buttons),
265 static struct platform_device d2net_gpio_buttons = {
266 .name = "gpio-keys",
267 .id = -1,
268 .dev = {
269 .platform_data = &d2net_button_data,
273 /*****************************************************************************
274 * General Setup
275 ****************************************************************************/
277 static struct orion5x_mpp_mode d2net_mpp_modes[] __initdata = {
278 { 0, MPP_GPIO }, /* Board ID (bit 0) */
279 { 1, MPP_GPIO }, /* Board ID (bit 1) */
280 { 2, MPP_GPIO }, /* Board ID (bit 2) */
281 { 3, MPP_GPIO }, /* SATA 0 power */
282 { 4, MPP_UNUSED },
283 { 5, MPP_GPIO }, /* Fan fail detection */
284 { 6, MPP_GPIO }, /* Red front LED */
285 { 7, MPP_UNUSED },
286 { 8, MPP_GPIO }, /* Rear power switch (on|auto) */
287 { 9, MPP_GPIO }, /* Rear power switch (auto|off) */
288 { 10, MPP_UNUSED },
289 { 11, MPP_UNUSED },
290 { 12, MPP_GPIO }, /* SATA 1 power */
291 { 13, MPP_UNUSED },
292 { 14, MPP_GPIO }, /* SATA 0 active */
293 { 15, MPP_GPIO }, /* SATA 1 active */
294 { 16, MPP_GPIO }, /* Blue front LED blink control */
295 { 17, MPP_UNUSED },
296 { 18, MPP_GPIO }, /* Front button (0 = Released, 1 = Pushed ) */
297 { 19, MPP_UNUSED },
298 { -1 }
299 /* 22: USB port 1 fuse (0 = Fail, 1 = Ok) */
300 /* 23: Blue front LED off */
301 /* 24: Inhibit board power off (0 = Disabled, 1 = Enabled) */
304 static void __init d2net_init(void)
307 * Setup basic Orion functions. Need to be called early.
309 orion5x_init();
311 orion5x_mpp_conf(d2net_mpp_modes);
314 * Configure peripherals.
316 orion5x_ehci0_init();
317 orion5x_eth_init(&d2net_eth_data);
318 orion5x_i2c_init();
319 orion5x_uart0_init();
321 d2net_sata_power_init();
322 orion5x_sata_init(&d2net_sata_data);
324 orion5x_setup_dev_boot_win(D2NET_NOR_BOOT_BASE,
325 D2NET_NOR_BOOT_SIZE);
326 platform_device_register(&d2net_nor_flash);
328 platform_device_register(&d2net_gpio_buttons);
330 d2net_gpio_leds_init();
332 pr_notice("d2net: Flash write are not yet supported.\n");
334 i2c_register_board_info(0, d2net_i2c_devices,
335 ARRAY_SIZE(d2net_i2c_devices));
338 /* Warning: LaCie use a wrong mach-type (0x20e=526) in their bootloader. */
340 #ifdef CONFIG_MACH_D2NET
341 MACHINE_START(D2NET, "LaCie d2 Network")
342 .phys_io = ORION5X_REGS_PHYS_BASE,
343 .io_pg_offst = ((ORION5X_REGS_VIRT_BASE) >> 18) & 0xFFFC,
344 .boot_params = 0x00000100,
345 .init_machine = d2net_init,
346 .map_io = orion5x_map_io,
347 .init_irq = orion5x_init_irq,
348 .timer = &orion5x_timer,
349 .fixup = tag_fixup_mem32,
350 MACHINE_END
351 #endif
353 #ifdef CONFIG_MACH_BIGDISK
354 MACHINE_START(BIGDISK, "LaCie Big Disk Network")
355 .phys_io = ORION5X_REGS_PHYS_BASE,
356 .io_pg_offst = ((ORION5X_REGS_VIRT_BASE) >> 18) & 0xFFFC,
357 .boot_params = 0x00000100,
358 .init_machine = d2net_init,
359 .map_io = orion5x_map_io,
360 .init_irq = orion5x_init_irq,
361 .timer = &orion5x_timer,
362 .fixup = tag_fixup_mem32,
363 MACHINE_END
364 #endif