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/orion5x.h>
32 #define QNAP_TS209_NOR_BOOT_BASE 0xf4000000
33 #define QNAP_TS209_NOR_BOOT_SIZE SZ_8M
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.
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 ***************************************************************************/
48 static struct mtd_partition qnap_ts209_partitions[] = {
53 .mask_flags = MTD_WRITEABLE,
67 .name = "U-Boot Config",
74 .mask_flags = MTD_WRITEABLE,
78 static struct physmap_flash_data qnap_ts209_nor_flash_data = {
80 .parts = qnap_ts209_partitions,
81 .nr_parts = ARRAY_SIZE(qnap_ts209_partitions)
84 static 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,
90 static struct platform_device qnap_ts209_nor_flash = {
91 .name = "physmap-flash",
94 .platform_data = &qnap_ts209_nor_flash_data,
96 .resource = &qnap_ts209_nor_flash_resource,
100 /*****************************************************************************
102 ****************************************************************************/
104 #define QNAP_TS209_PCI_SLOT0_OFFS 7
105 #define QNAP_TS209_PCI_SLOT0_IRQ_PIN 6
106 #define QNAP_TS209_PCI_SLOT1_IRQ_PIN 7
108 void __init qnap_ts209_pci_preinit(void)
113 * Configure PCI GPIO IRQ pins
115 pin = QNAP_TS209_PCI_SLOT0_IRQ_PIN;
116 if (gpio_request(pin, "PCI Int1") == 0) {
117 if (gpio_direction_input(pin) == 0) {
118 set_irq_type(gpio_to_irq(pin), IRQT_LOW);
120 printk(KERN_ERR "qnap_ts209_pci_preinit failed to "
121 "set_irq_type pin %d\n", pin);
125 printk(KERN_ERR "qnap_ts209_pci_preinit failed to gpio_request "
129 pin = QNAP_TS209_PCI_SLOT1_IRQ_PIN;
130 if (gpio_request(pin, "PCI Int2") == 0) {
131 if (gpio_direction_input(pin) == 0) {
132 set_irq_type(gpio_to_irq(pin), IRQT_LOW);
134 printk(KERN_ERR "qnap_ts209_pci_preinit failed "
135 "to set_irq_type pin %d\n", pin);
139 printk(KERN_ERR "qnap_ts209_pci_preinit failed to gpio_request "
144 static int __init qnap_ts209_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
149 * Check for devices with hard-wired IRQs.
151 irq = orion5x_pci_map_irq(dev, slot, pin);
156 * PCI IRQs are connected via GPIOs.
158 switch (slot - QNAP_TS209_PCI_SLOT0_OFFS) {
160 return gpio_to_irq(QNAP_TS209_PCI_SLOT0_IRQ_PIN);
162 return gpio_to_irq(QNAP_TS209_PCI_SLOT1_IRQ_PIN);
168 static struct hw_pci qnap_ts209_pci __initdata = {
170 .preinit = qnap_ts209_pci_preinit,
171 .swizzle = pci_std_swizzle,
172 .setup = orion5x_pci_sys_setup,
173 .scan = orion5x_pci_sys_scan_bus,
174 .map_irq = qnap_ts209_pci_map_irq,
177 static int __init qnap_ts209_pci_init(void)
179 if (machine_is_ts_x09())
180 pci_common_init(&qnap_ts209_pci);
185 subsys_initcall(qnap_ts209_pci_init);
187 /*****************************************************************************
189 ****************************************************************************/
191 static struct mv643xx_eth_platform_data qnap_ts209_eth_data = {
196 static int __init parse_hex_nibble(char n)
198 if (n >= '0' && n <= '9')
201 if (n >= 'A' && n <= 'F')
204 if (n >= 'a' && n <= 'f')
210 static int __init parse_hex_byte(const char *b)
215 hi = parse_hex_nibble(b[0]);
216 lo = parse_hex_nibble(b[1]);
218 if (hi < 0 || lo < 0)
221 return (hi << 4) | lo;
224 static int __init check_mac_addr(const char *addr_str)
229 for (i = 0; i < 6; i++) {
233 * Enforce "xx:xx:xx:xx:xx:xx\n" format.
235 if (addr_str[(i * 3) + 2] != ((i < 5) ? ':' : '\n'))
238 byte = parse_hex_byte(addr_str + (i * 3));
244 printk(KERN_INFO "ts209: found ethernet mac address ");
245 for (i = 0; i < 6; i++)
246 printk("%.2x%s", addr[i], (i < 5) ? ":" : ".\n");
248 memcpy(qnap_ts209_eth_data.mac_addr, addr, 6);
254 * The 'NAS Config' flash partition has an ext2 filesystem which
255 * contains a file that has the ethernet MAC address in plain text
256 * (format "xx:xx:xx:xx:xx:xx\n".)
258 static void __init ts209_find_mac_addr(void)
262 for (addr = 0x00700000; addr < 0x00760000; addr += 1024) {
266 nor_page = ioremap(QNAP_TS209_NOR_BOOT_BASE + addr, 1024);
267 if (nor_page != NULL) {
268 ret = check_mac_addr(nor_page);
277 /*****************************************************************************
278 * RTC S35390A on I2C bus
279 ****************************************************************************/
281 #define TS209_RTC_GPIO 3
283 static struct i2c_board_info __initdata qnap_ts209_i2c_rtc = {
284 I2C_BOARD_INFO("s35390a", 0x30),
288 /****************************************************************************
290 * Power button is attached to the PIC microcontroller
291 ****************************************************************************/
293 #define QNAP_TS209_GPIO_KEY_MEDIA 1
294 #define QNAP_TS209_GPIO_KEY_RESET 2
296 static struct gpio_keys_button qnap_ts209_buttons[] = {
299 .gpio = QNAP_TS209_GPIO_KEY_MEDIA,
300 .desc = "USB Copy Button",
304 .gpio = QNAP_TS209_GPIO_KEY_RESET,
305 .desc = "Reset Button",
310 static struct gpio_keys_platform_data qnap_ts209_button_data = {
311 .buttons = qnap_ts209_buttons,
312 .nbuttons = ARRAY_SIZE(qnap_ts209_buttons),
315 static struct platform_device qnap_ts209_button_device = {
320 .platform_data = &qnap_ts209_button_data,
324 /*****************************************************************************
326 ****************************************************************************/
327 static struct mv_sata_platform_data qnap_ts209_sata_data = {
331 /*****************************************************************************
334 ****************************************************************************/
336 static struct platform_device *qnap_ts209_devices[] __initdata = {
337 &qnap_ts209_nor_flash,
338 &qnap_ts209_button_device,
342 * QNAP TS-[12]09 specific power off method via UART1-attached PIC
345 #define UART1_REG(x) (UART1_VIRT_BASE + ((UART_##x) << 2))
347 static void qnap_ts209_power_off(void)
349 /* 19200 baud divisor */
350 const unsigned divisor = ((ORION5X_TCLK + (8 * 19200)) / (16 * 19200));
352 pr_info("%s: triggering power-off...\n", __func__);
354 /* hijack uart1 and reset into sane state (19200,8n1) */
355 orion5x_write(UART1_REG(LCR), 0x83);
356 orion5x_write(UART1_REG(DLL), divisor & 0xff);
357 orion5x_write(UART1_REG(DLM), (divisor >> 8) & 0xff);
358 orion5x_write(UART1_REG(LCR), 0x03);
359 orion5x_write(UART1_REG(IER), 0x00);
360 orion5x_write(UART1_REG(FCR), 0x00);
361 orion5x_write(UART1_REG(MCR), 0x00);
363 /* send the power-off command 'A' to PIC */
364 orion5x_write(UART1_REG(TX), 'A');
367 static void __init qnap_ts209_init(void)
370 * Setup basic Orion functions. Need to be called early.
375 * Setup flash mapping
377 orion5x_setup_dev_boot_win(QNAP_TS209_NOR_BOOT_BASE,
378 QNAP_TS209_NOR_BOOT_SIZE);
381 * Open a special address decode windows for the PCIe WA.
383 orion5x_setup_pcie_wa_win(ORION5X_PCIE_WA_PHYS_BASE,
384 ORION5X_PCIE_WA_SIZE);
387 * Setup Multiplexing Pins --
389 * MPP[1] USB copy button (0 active)
390 * MPP[2] Load defaults button (0 active)
396 * MPP[12] SATA 0 presence
397 * MPP[13] SATA 1 presence
398 * MPP[14] SATA 0 active
399 * MPP[15] SATA 1 active
402 * MPP[18] SW_RST (0 active)
404 * MPP[20] PCI clock 0
405 * MPP[21] PCI clock 1
406 * MPP[22] USB 0 over current
407 * MPP[23-25] Reserved
409 orion5x_write(MPP_0_7_CTRL, 0x3);
410 orion5x_write(MPP_8_15_CTRL, 0x55550000);
411 orion5x_write(MPP_16_19_CTRL, 0x5500);
412 orion5x_gpio_set_valid_pins(0x3cc0fff);
414 /* register ts209 specific power-off method */
415 pm_power_off = qnap_ts209_power_off;
417 platform_add_devices(qnap_ts209_devices,
418 ARRAY_SIZE(qnap_ts209_devices));
420 /* Get RTC IRQ and register the chip */
421 if (gpio_request(TS209_RTC_GPIO, "rtc") == 0) {
422 if (gpio_direction_input(TS209_RTC_GPIO) == 0)
423 qnap_ts209_i2c_rtc.irq = gpio_to_irq(TS209_RTC_GPIO);
425 gpio_free(TS209_RTC_GPIO);
427 if (qnap_ts209_i2c_rtc.irq == 0)
428 pr_warning("qnap_ts209_init: failed to get RTC IRQ\n");
429 i2c_register_board_info(0, &qnap_ts209_i2c_rtc, 1);
431 ts209_find_mac_addr();
432 orion5x_eth_init(&qnap_ts209_eth_data);
434 orion5x_sata_init(&qnap_ts209_sata_data);
437 MACHINE_START(TS209, "QNAP TS-109/TS-209")
438 /* Maintainer: Byron Bradley <byron.bbradley@gmail.com> */
439 .phys_io = ORION5X_REGS_PHYS_BASE,
440 .io_pg_offst = ((ORION5X_REGS_VIRT_BASE) >> 18) & 0xFFFC,
441 .boot_params = 0x00000100,
442 .init_machine = qnap_ts209_init,
443 .map_io = orion5x_map_io,
444 .init_irq = orion5x_init_irq,
445 .timer = &orion5x_timer,
446 .fixup = tag_fixup_mem32,