Linux 2.6.25-rc4
[deliverable/linux.git] / arch / arm / mach-orion / ts209-setup.c
CommitLineData
3faf2ee8
BB
1/*
2 * QNAP TS-109/TS-209 Board Setup
3 *
4 * Maintainer: Byron Bradley <byron.bbradley@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12#include <linux/kernel.h>
13#include <linux/init.h>
14#include <linux/platform_device.h>
15#include <linux/pci.h>
16#include <linux/irq.h>
17#include <linux/mtd/physmap.h>
18#include <linux/mtd/nand.h>
19#include <linux/mv643xx_eth.h>
20#include <linux/gpio_keys.h>
21#include <linux/input.h>
22#include <linux/i2c.h>
8f86dda3 23#include <linux/serial_reg.h>
ee44391e 24#include <linux/ata_platform.h>
3faf2ee8
BB
25#include <asm/mach-types.h>
26#include <asm/gpio.h>
27#include <asm/mach/arch.h>
28#include <asm/mach/pci.h>
29#include <asm/arch/orion.h>
30#include <asm/arch/platform.h>
31#include "common.h"
32
33#define QNAP_TS209_NOR_BOOT_BASE 0xf4000000
34#define QNAP_TS209_NOR_BOOT_SIZE SZ_8M
35
36/****************************************************************************
37 * 8MiB NOR flash. The struct mtd_partition is not in the same order as the
38 * partitions on the device because we want to keep compatability with
39 * existing QNAP firmware.
40 *
41 * Layout as used by QNAP:
42 * [2] 0x00000000-0x00200000 : "Kernel"
43 * [3] 0x00200000-0x00600000 : "RootFS1"
44 * [4] 0x00600000-0x00700000 : "RootFS2"
45 * [6] 0x00700000-0x00760000 : "NAS Config" (read-only)
46 * [5] 0x00760000-0x00780000 : "U-Boot Config"
47 * [1] 0x00780000-0x00800000 : "U-Boot" (read-only)
48 ***************************************************************************/
49static struct mtd_partition qnap_ts209_partitions[] = {
50 {
51 .name = "U-Boot",
52 .size = 0x00080000,
53 .offset = 0x00780000,
54 .mask_flags = MTD_WRITEABLE,
55 }, {
56 .name = "Kernel",
57 .size = 0x00200000,
58 .offset = 0,
59 }, {
60 .name = "RootFS1",
61 .size = 0x00400000,
62 .offset = 0x00200000,
63 }, {
64 .name = "RootFS2",
65 .size = 0x00100000,
66 .offset = 0x00600000,
67 }, {
68 .name = "U-Boot Config",
69 .size = 0x00020000,
70 .offset = 0x00760000,
71 }, {
72 .name = "NAS Config",
73 .size = 0x00060000,
74 .offset = 0x00700000,
75 .mask_flags = MTD_WRITEABLE,
76 }
77};
78
79static struct physmap_flash_data qnap_ts209_nor_flash_data = {
80 .width = 1,
81 .parts = qnap_ts209_partitions,
82 .nr_parts = ARRAY_SIZE(qnap_ts209_partitions)
83};
84
85static struct resource qnap_ts209_nor_flash_resource = {
86 .flags = IORESOURCE_MEM,
87 .start = QNAP_TS209_NOR_BOOT_BASE,
88 .end = QNAP_TS209_NOR_BOOT_BASE + QNAP_TS209_NOR_BOOT_SIZE - 1,
89};
90
91static struct platform_device qnap_ts209_nor_flash = {
92 .name = "physmap-flash",
93 .id = 0,
94 .dev = { .platform_data = &qnap_ts209_nor_flash_data, },
95 .resource = &qnap_ts209_nor_flash_resource,
96 .num_resources = 1,
97};
98
99/*****************************************************************************
100 * PCI
101 ****************************************************************************/
102
103#define QNAP_TS209_PCI_SLOT0_OFFS 7
104#define QNAP_TS209_PCI_SLOT0_IRQ_PIN 6
105#define QNAP_TS209_PCI_SLOT1_IRQ_PIN 7
106
107void __init qnap_ts209_pci_preinit(void)
108{
109 int pin;
110
111 /*
112 * Configure PCI GPIO IRQ pins
113 */
114 pin = QNAP_TS209_PCI_SLOT0_IRQ_PIN;
115 if (gpio_request(pin, "PCI Int1") == 0) {
116 if (gpio_direction_input(pin) == 0) {
117 set_irq_type(gpio_to_irq(pin), IRQT_LOW);
118 } else {
119 printk(KERN_ERR "qnap_ts209_pci_preinit failed to "
120 "set_irq_type pin %d\n", pin);
121 gpio_free(pin);
122 }
123 } else {
124 printk(KERN_ERR "qnap_ts209_pci_preinit failed to gpio_request "
125 "%d\n", pin);
126 }
127
128 pin = QNAP_TS209_PCI_SLOT1_IRQ_PIN;
129 if (gpio_request(pin, "PCI Int2") == 0) {
130 if (gpio_direction_input(pin) == 0) {
131 set_irq_type(gpio_to_irq(pin), IRQT_LOW);
132 } else {
133 printk(KERN_ERR "qnap_ts209_pci_preinit failed "
134 "to set_irq_type pin %d\n", pin);
135 gpio_free(pin);
136 }
137 } else {
138 printk(KERN_ERR "qnap_ts209_pci_preinit failed to gpio_request "
139 "%d\n", pin);
140 }
141}
142
143static int __init qnap_ts209_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
144{
145 /*
146 * PCIE IRQ is connected internally (not GPIO)
147 */
148 if (dev->bus->number == orion_pcie_local_bus_nr())
149 return IRQ_ORION_PCIE0_INT;
150
151 /*
152 * PCI IRQs are connected via GPIOs
153 */
154 switch (slot - QNAP_TS209_PCI_SLOT0_OFFS) {
155 case 0:
156 return gpio_to_irq(QNAP_TS209_PCI_SLOT0_IRQ_PIN);
157 case 1:
158 return gpio_to_irq(QNAP_TS209_PCI_SLOT1_IRQ_PIN);
159 default:
160 return -1;
161 }
162}
163
164static struct hw_pci qnap_ts209_pci __initdata = {
165 .nr_controllers = 2,
166 .preinit = qnap_ts209_pci_preinit,
167 .swizzle = pci_std_swizzle,
168 .setup = orion_pci_sys_setup,
169 .scan = orion_pci_sys_scan_bus,
170 .map_irq = qnap_ts209_pci_map_irq,
171};
172
173static int __init qnap_ts209_pci_init(void)
174{
175 if (machine_is_ts_x09())
176 pci_common_init(&qnap_ts209_pci);
177
178 return 0;
179}
180
181subsys_initcall(qnap_ts209_pci_init);
182
183/*****************************************************************************
184 * Ethernet
185 ****************************************************************************/
186
187static struct mv643xx_eth_platform_data qnap_ts209_eth_data = {
188 .phy_addr = 8,
189 .force_phy_addr = 1,
190};
191
192/*****************************************************************************
193 * RTC S35390A on I2C bus
194 ****************************************************************************/
59e8ce57
BB
195
196#define TS209_RTC_GPIO 3
197
3faf2ee8
BB
198static struct i2c_board_info __initdata qnap_ts209_i2c_rtc = {
199 .driver_name = "rtc-s35390a",
200 .addr = 0x30,
59e8ce57 201 .irq = 0,
3faf2ee8
BB
202};
203
204/****************************************************************************
205 * GPIO Attached Keys
206 * Power button is attached to the PIC microcontroller
207 ****************************************************************************/
208
209#define QNAP_TS209_GPIO_KEY_MEDIA 1
210#define QNAP_TS209_GPIO_KEY_RESET 2
211
212static struct gpio_keys_button qnap_ts209_buttons[] = {
213 {
214 .code = KEY_RESTART,
215 .gpio = QNAP_TS209_GPIO_KEY_MEDIA,
216 .desc = "USB Copy Button",
217 .active_low = 1,
218 },
219 {
220 .code = KEY_POWER,
221 .gpio = QNAP_TS209_GPIO_KEY_RESET,
222 .desc = "Reset Button",
223 .active_low = 1,
224 }
225};
226
227static struct gpio_keys_platform_data qnap_ts209_button_data = {
228 .buttons = qnap_ts209_buttons,
229 .nbuttons = ARRAY_SIZE(qnap_ts209_buttons),
230};
231
232static struct platform_device qnap_ts209_button_device = {
233 .name = "gpio-keys",
234 .id = -1,
235 .num_resources = 0,
236 .dev = { .platform_data = &qnap_ts209_button_data, },
237};
238
239/*****************************************************************************
ee44391e
BB
240 * SATA
241 ****************************************************************************/
242static struct mv_sata_platform_data qnap_ts209_sata_data = {
243 .n_ports = 2,
244};
245
246/*****************************************************************************
247
3faf2ee8
BB
248 * General Setup
249 ****************************************************************************/
250
251static struct platform_device *qnap_ts209_devices[] __initdata = {
252 &qnap_ts209_nor_flash,
253 &qnap_ts209_button_device,
254};
255
8f86dda3
HVR
256/*
257 * QNAP TS-[12]09 specific power off method via UART1-attached PIC
258 */
259
7f74c2c7 260#define UART1_REG(x) (UART1_VIRT_BASE + ((UART_##x) << 2))
8f86dda3
HVR
261
262static void qnap_ts209_power_off(void)
263{
264 /* 19200 baud divisor */
265 const unsigned divisor = ((ORION_TCLK + (8 * 19200)) / (16 * 19200));
266
267 pr_info("%s: triggering power-off...\n", __func__);
268
269 /* hijack uart1 and reset into sane state (19200,8n1) */
270 orion_write(UART1_REG(LCR), 0x83);
271 orion_write(UART1_REG(DLL), divisor & 0xff);
272 orion_write(UART1_REG(DLM), (divisor >> 8) & 0xff);
273 orion_write(UART1_REG(LCR), 0x03);
274 orion_write(UART1_REG(IER), 0x00);
275 orion_write(UART1_REG(FCR), 0x00);
276 orion_write(UART1_REG(MCR), 0x00);
277
278 /* send the power-off command 'A' to PIC */
279 orion_write(UART1_REG(TX), 'A');
280}
281
3faf2ee8
BB
282static void __init qnap_ts209_init(void)
283{
284 /*
285 * Setup basic Orion functions. Need to be called early.
286 */
287 orion_init();
288
289 /*
290 * Setup flash mapping
291 */
292 orion_setup_cpu_win(ORION_DEV_BOOT, QNAP_TS209_NOR_BOOT_BASE,
293 QNAP_TS209_NOR_BOOT_SIZE, -1);
294
295 /*
296 * Open a special address decode windows for the PCIE WA.
297 */
7f74c2c7
LB
298 orion_write(ORION_REGS_VIRT_BASE | 0x20074, ORION_PCIE_WA_PHYS_BASE);
299 orion_write(ORION_REGS_VIRT_BASE | 0x20070, (0x7941 |
3faf2ee8
BB
300 (((ORION_PCIE_WA_SIZE >> 16) - 1)) << 16));
301
302 /*
303 * Setup Multiplexing Pins --
304 * MPP[0] Reserved
305 * MPP[1] USB copy button (0 active)
306 * MPP[2] Load defaults button (0 active)
307 * MPP[3] GPIO RTC
308 * MPP[4-5] Reserved
309 * MPP[6] PCI Int A
310 * MPP[7] PCI Int B
311 * MPP[8-11] Reserved
312 * MPP[12] SATA 0 presence
313 * MPP[13] SATA 1 presence
314 * MPP[14] SATA 0 active
315 * MPP[15] SATA 1 active
316 * MPP[16] UART1 RXD
317 * MPP[17] UART1 TXD
318 * MPP[18] SW_RST (0 active)
319 * MPP[19] Reserved
320 * MPP[20] PCI clock 0
321 * MPP[21] PCI clock 1
322 * MPP[22] USB 0 over current
323 * MPP[23-25] Reserved
324 */
325 orion_write(MPP_0_7_CTRL, 0x3);
326 orion_write(MPP_8_15_CTRL, 0x55550000);
327 orion_write(MPP_16_19_CTRL, 0x5500);
328 orion_gpio_set_valid_pins(0x3cc0fff);
329
8f86dda3
HVR
330 /* register ts209 specific power-off method */
331 pm_power_off = qnap_ts209_power_off;
332
3faf2ee8
BB
333 platform_add_devices(qnap_ts209_devices,
334 ARRAY_SIZE(qnap_ts209_devices));
59e8ce57
BB
335
336 /* Get RTC IRQ and register the chip */
337 if (gpio_request(TS209_RTC_GPIO, "rtc") == 0) {
338 if (gpio_direction_input(TS209_RTC_GPIO) == 0)
339 qnap_ts209_i2c_rtc.irq = gpio_to_irq(TS209_RTC_GPIO);
340 else
341 gpio_free(TS209_RTC_GPIO);
342 }
343 if (qnap_ts209_i2c_rtc.irq == 0)
344 pr_warning("qnap_ts209_init: failed to get RTC IRQ\n");
3faf2ee8 345 i2c_register_board_info(0, &qnap_ts209_i2c_rtc, 1);
59e8ce57 346
3faf2ee8 347 orion_eth_init(&qnap_ts209_eth_data);
ee44391e 348 orion_sata_init(&qnap_ts209_sata_data);
3faf2ee8
BB
349}
350
351MACHINE_START(TS209, "QNAP TS-109/TS-209")
352 /* Maintainer: Byron Bradley <byron.bbradley@gmail.com> */
7f74c2c7
LB
353 .phys_io = ORION_REGS_PHYS_BASE,
354 .io_pg_offst = ((ORION_REGS_VIRT_BASE) >> 18) & 0xFFFC,
3faf2ee8
BB
355 .boot_params = 0x00000100,
356 .init_machine = qnap_ts209_init,
357 .map_io = orion_map_io,
358 .init_irq = orion_init_irq,
359 .timer = &orion_timer,
360MACHINE_END
This page took 0.061356 seconds and 5 git commands to generate.