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.
11 #include <linux/gpio.h>
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/mach/arch.h>
27 #include <asm/mach/pci.h>
28 #include <mach/orion5x.h>
31 #include "tsx09-common.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 compatibility 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",
95 .platform_data
= &qnap_ts209_nor_flash_data
,
97 .resource
= &qnap_ts209_nor_flash_resource
,
101 /*****************************************************************************
103 ****************************************************************************/
105 #define QNAP_TS209_PCI_SLOT0_OFFS 7
106 #define QNAP_TS209_PCI_SLOT0_IRQ_PIN 6
107 #define QNAP_TS209_PCI_SLOT1_IRQ_PIN 7
109 void __init
qnap_ts209_pci_preinit(void)
114 * Configure PCI GPIO IRQ pins
116 pin
= QNAP_TS209_PCI_SLOT0_IRQ_PIN
;
117 if (gpio_request(pin
, "PCI Int1") == 0) {
118 if (gpio_direction_input(pin
) == 0) {
119 irq_set_irq_type(gpio_to_irq(pin
), IRQ_TYPE_LEVEL_LOW
);
121 printk(KERN_ERR
"qnap_ts209_pci_preinit failed to "
122 "set_irq_type pin %d\n", pin
);
126 printk(KERN_ERR
"qnap_ts209_pci_preinit failed to gpio_request "
130 pin
= QNAP_TS209_PCI_SLOT1_IRQ_PIN
;
131 if (gpio_request(pin
, "PCI Int2") == 0) {
132 if (gpio_direction_input(pin
) == 0) {
133 irq_set_irq_type(gpio_to_irq(pin
), IRQ_TYPE_LEVEL_LOW
);
135 printk(KERN_ERR
"qnap_ts209_pci_preinit failed "
136 "to set_irq_type pin %d\n", pin
);
140 printk(KERN_ERR
"qnap_ts209_pci_preinit failed to gpio_request "
145 static int __init
qnap_ts209_pci_map_irq(const struct pci_dev
*dev
, u8 slot
,
151 * Check for devices with hard-wired IRQs.
153 irq
= orion5x_pci_map_irq(dev
, slot
, pin
);
158 * PCI IRQs are connected via GPIOs.
160 switch (slot
- QNAP_TS209_PCI_SLOT0_OFFS
) {
162 return gpio_to_irq(QNAP_TS209_PCI_SLOT0_IRQ_PIN
);
164 return gpio_to_irq(QNAP_TS209_PCI_SLOT1_IRQ_PIN
);
170 static struct hw_pci qnap_ts209_pci __initdata
= {
172 .preinit
= qnap_ts209_pci_preinit
,
173 .swizzle
= pci_std_swizzle
,
174 .setup
= orion5x_pci_sys_setup
,
175 .scan
= orion5x_pci_sys_scan_bus
,
176 .map_irq
= qnap_ts209_pci_map_irq
,
179 static int __init
qnap_ts209_pci_init(void)
181 if (machine_is_ts_x09())
182 pci_common_init(&qnap_ts209_pci
);
187 subsys_initcall(qnap_ts209_pci_init
);
189 /*****************************************************************************
190 * RTC S35390A on I2C bus
191 ****************************************************************************/
193 #define TS209_RTC_GPIO 3
195 static struct i2c_board_info __initdata qnap_ts209_i2c_rtc
= {
196 I2C_BOARD_INFO("s35390a", 0x30),
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",
216 .gpio
= QNAP_TS209_GPIO_KEY_RESET
,
217 .desc
= "Reset Button",
222 static struct gpio_keys_platform_data qnap_ts209_button_data
= {
223 .buttons
= qnap_ts209_buttons
,
224 .nbuttons
= ARRAY_SIZE(qnap_ts209_buttons
),
227 static struct platform_device qnap_ts209_button_device
= {
232 .platform_data
= &qnap_ts209_button_data
,
236 /*****************************************************************************
238 ****************************************************************************/
239 static struct mv_sata_platform_data qnap_ts209_sata_data
= {
243 /*****************************************************************************
246 ****************************************************************************/
247 static unsigned int ts209_mpp_modes
[] __initdata
= {
249 MPP1_GPIO
, /* USB copy button */
250 MPP2_GPIO
, /* Load defaults button */
251 MPP3_GPIO
, /* GPIO RTC */
254 MPP6_GPIO
, /* PCI Int A */
255 MPP7_GPIO
, /* PCI Int B */
260 MPP12_SATA_LED
, /* SATA 0 presence */
261 MPP13_SATA_LED
, /* SATA 1 presence */
262 MPP14_SATA_LED
, /* SATA 0 active */
263 MPP15_SATA_LED
, /* SATA 1 active */
264 MPP16_UART
, /* UART1 RXD */
265 MPP17_UART
, /* UART1 TXD */
266 MPP18_GPIO
, /* SW_RST */
271 static void __init
qnap_ts209_init(void)
274 * Setup basic Orion functions. Need to be called early.
278 orion5x_mpp_conf(ts209_mpp_modes
);
281 * MPP[20] PCI clock 0
282 * MPP[21] PCI clock 1
283 * MPP[22] USB 0 over current
284 * MPP[23-25] Reserved
288 * Configure peripherals.
290 orion5x_setup_dev_boot_win(QNAP_TS209_NOR_BOOT_BASE
,
291 QNAP_TS209_NOR_BOOT_SIZE
);
292 platform_device_register(&qnap_ts209_nor_flash
);
294 orion5x_ehci0_init();
295 orion5x_ehci1_init();
296 qnap_tsx09_find_mac_addr(QNAP_TS209_NOR_BOOT_BASE
+
297 qnap_ts209_partitions
[5].offset
,
298 qnap_ts209_partitions
[5].size
);
299 orion5x_eth_init(&qnap_tsx09_eth_data
);
301 orion5x_sata_init(&qnap_ts209_sata_data
);
302 orion5x_uart0_init();
303 orion5x_uart1_init();
306 platform_device_register(&qnap_ts209_button_device
);
308 /* Get RTC IRQ and register the chip */
309 if (gpio_request(TS209_RTC_GPIO
, "rtc") == 0) {
310 if (gpio_direction_input(TS209_RTC_GPIO
) == 0)
311 qnap_ts209_i2c_rtc
.irq
= gpio_to_irq(TS209_RTC_GPIO
);
313 gpio_free(TS209_RTC_GPIO
);
315 if (qnap_ts209_i2c_rtc
.irq
== 0)
316 pr_warning("qnap_ts209_init: failed to get RTC IRQ\n");
317 i2c_register_board_info(0, &qnap_ts209_i2c_rtc
, 1);
319 /* register tsx09 specific power-off method */
320 pm_power_off
= qnap_tsx09_power_off
;
323 MACHINE_START(TS209
, "QNAP TS-109/TS-209")
324 /* Maintainer: Byron Bradley <byron.bbradley@gmail.com> */
325 .atag_offset
= 0x100,
326 .init_machine
= qnap_ts209_init
,
327 .map_io
= orion5x_map_io
,
328 .init_early
= orion5x_init_early
,
329 .init_irq
= orion5x_init_irq
,
330 .timer
= &orion5x_timer
,
331 .fixup
= tag_fixup_mem32
,