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