2 * QNAP TS-109/TS-209 Board Setup
4 * Maintainer: Byron Bradley <byron.bbradley@gmail.com>
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.
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>
27 #include <asm/mach/arch.h>
28 #include <asm/mach/pci.h>
29 #include <asm/arch/orion.h>
30 #include <asm/arch/platform.h>
33 #define QNAP_TS209_NOR_BOOT_BASE 0xf4000000
34 #define QNAP_TS209_NOR_BOOT_SIZE SZ_8M
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.
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 ***************************************************************************/
49 static struct mtd_partition qnap_ts209_partitions[] = {
54 .mask_flags = MTD_WRITEABLE,
68 .name = "U-Boot Config",
75 .mask_flags = MTD_WRITEABLE,
79 static struct physmap_flash_data qnap_ts209_nor_flash_data = {
81 .parts = qnap_ts209_partitions,
82 .nr_parts = ARRAY_SIZE(qnap_ts209_partitions)
85 static 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,
91 static struct platform_device qnap_ts209_nor_flash = {
92 .name = "physmap-flash",
94 .dev = { .platform_data = &qnap_ts209_nor_flash_data, },
95 .resource = &qnap_ts209_nor_flash_resource,
99 /*****************************************************************************
101 ****************************************************************************/
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
107 void __init qnap_ts209_pci_preinit(void)
112 * Configure PCI GPIO IRQ pins
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);
119 printk(KERN_ERR "qnap_ts209_pci_preinit failed to "
120 "set_irq_type pin %d\n", pin);
124 printk(KERN_ERR "qnap_ts209_pci_preinit failed to gpio_request "
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);
133 printk(KERN_ERR "qnap_ts209_pci_preinit failed "
134 "to set_irq_type pin %d\n", pin);
138 printk(KERN_ERR "qnap_ts209_pci_preinit failed to gpio_request "
143 static int __init qnap_ts209_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
146 * PCIE IRQ is connected internally (not GPIO)
148 if (dev->bus->number == orion_pcie_local_bus_nr())
149 return IRQ_ORION_PCIE0_INT;
152 * PCI IRQs are connected via GPIOs
154 switch (slot - QNAP_TS209_PCI_SLOT0_OFFS) {
156 return gpio_to_irq(QNAP_TS209_PCI_SLOT0_IRQ_PIN);
158 return gpio_to_irq(QNAP_TS209_PCI_SLOT1_IRQ_PIN);
164 static struct hw_pci qnap_ts209_pci __initdata = {
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,
173 static int __init qnap_ts209_pci_init(void)
175 if (machine_is_ts_x09())
176 pci_common_init(&qnap_ts209_pci);
181 subsys_initcall(qnap_ts209_pci_init);
183 /*****************************************************************************
185 ****************************************************************************/
187 static struct mv643xx_eth_platform_data qnap_ts209_eth_data = {
192 /*****************************************************************************
193 * RTC S35390A on I2C bus
194 ****************************************************************************/
195 static struct i2c_board_info __initdata qnap_ts209_i2c_rtc = {
196 .driver_name = "rtc-s35390a",
200 /****************************************************************************
202 * Power button is attached to the PIC microcontroller
203 ****************************************************************************/
205 #define QNAP_TS209_GPIO_KEY_MEDIA 1
206 #define QNAP_TS209_GPIO_KEY_RESET 2
208 static struct gpio_keys_button qnap_ts209_buttons[] = {
211 .gpio = QNAP_TS209_GPIO_KEY_MEDIA,
212 .desc = "USB Copy Button",
217 .gpio = QNAP_TS209_GPIO_KEY_RESET,
218 .desc = "Reset Button",
223 static struct gpio_keys_platform_data qnap_ts209_button_data = {
224 .buttons = qnap_ts209_buttons,
225 .nbuttons = ARRAY_SIZE(qnap_ts209_buttons),
228 static struct platform_device qnap_ts209_button_device = {
232 .dev = { .platform_data = &qnap_ts209_button_data, },
235 /*****************************************************************************
237 ****************************************************************************/
238 static struct mv_sata_platform_data qnap_ts209_sata_data = {
242 /*****************************************************************************
245 ****************************************************************************/
247 static struct platform_device *qnap_ts209_devices[] __initdata = {
248 &qnap_ts209_nor_flash,
249 &qnap_ts209_button_device,
253 * QNAP TS-[12]09 specific power off method via UART1-attached PIC
256 #define UART1_REG(x) (UART1_VIRT_BASE + ((UART_##x) << 2))
258 static void qnap_ts209_power_off(void)
260 /* 19200 baud divisor */
261 const unsigned divisor = ((ORION_TCLK + (8 * 19200)) / (16 * 19200));
263 pr_info("%s: triggering power-off...\n", __func__);
265 /* hijack uart1 and reset into sane state (19200,8n1) */
266 orion_write(UART1_REG(LCR), 0x83);
267 orion_write(UART1_REG(DLL), divisor & 0xff);
268 orion_write(UART1_REG(DLM), (divisor >> 8) & 0xff);
269 orion_write(UART1_REG(LCR), 0x03);
270 orion_write(UART1_REG(IER), 0x00);
271 orion_write(UART1_REG(FCR), 0x00);
272 orion_write(UART1_REG(MCR), 0x00);
274 /* send the power-off command 'A' to PIC */
275 orion_write(UART1_REG(TX), 'A');
278 static void __init qnap_ts209_init(void)
281 * Setup basic Orion functions. Need to be called early.
286 * Setup flash mapping
288 orion_setup_cpu_win(ORION_DEV_BOOT, QNAP_TS209_NOR_BOOT_BASE,
289 QNAP_TS209_NOR_BOOT_SIZE, -1);
292 * Open a special address decode windows for the PCIE WA.
294 orion_write(ORION_REGS_VIRT_BASE | 0x20074, ORION_PCIE_WA_PHYS_BASE);
295 orion_write(ORION_REGS_VIRT_BASE | 0x20070, (0x7941 |
296 (((ORION_PCIE_WA_SIZE >> 16) - 1)) << 16));
299 * Setup Multiplexing Pins --
301 * MPP[1] USB copy button (0 active)
302 * MPP[2] Load defaults button (0 active)
308 * MPP[12] SATA 0 presence
309 * MPP[13] SATA 1 presence
310 * MPP[14] SATA 0 active
311 * MPP[15] SATA 1 active
314 * MPP[18] SW_RST (0 active)
316 * MPP[20] PCI clock 0
317 * MPP[21] PCI clock 1
318 * MPP[22] USB 0 over current
319 * MPP[23-25] Reserved
321 orion_write(MPP_0_7_CTRL, 0x3);
322 orion_write(MPP_8_15_CTRL, 0x55550000);
323 orion_write(MPP_16_19_CTRL, 0x5500);
324 orion_gpio_set_valid_pins(0x3cc0fff);
326 /* register ts209 specific power-off method */
327 pm_power_off = qnap_ts209_power_off;
329 platform_add_devices(qnap_ts209_devices,
330 ARRAY_SIZE(qnap_ts209_devices));
331 i2c_register_board_info(0, &qnap_ts209_i2c_rtc, 1);
332 orion_eth_init(&qnap_ts209_eth_data);
333 orion_sata_init(&qnap_ts209_sata_data);
336 MACHINE_START(TS209, "QNAP TS-109/TS-209")
337 /* Maintainer: Byron Bradley <byron.bbradley@gmail.com> */
338 .phys_io = ORION_REGS_PHYS_BASE,
339 .io_pg_offst = ((ORION_REGS_VIRT_BASE) >> 18) & 0xFFFC,
340 .boot_params = 0x00000100,
341 .init_machine = qnap_ts209_init,
342 .map_io = orion_map_io,
343 .init_irq = orion_init_irq,
344 .timer = &orion_timer,