1 From: Sylver Bruneau <sylver.bruneau@googlemail.com>
3 Signed-off-by: Lennert Buytenhek <buytenh@marvell.com>
5 arch/arm/mach-orion5x/Kconfig | 6 +
6 arch/arm/mach-orion5x/Makefile | 1 +
7 arch/arm/mach-orion5x/ts409-setup.c | 383 +++++++++++++++++++++++++++++++++++
8 3 files changed, 390 insertions(+), 0 deletions(-)
9 create mode 100644 arch/arm/mach-orion5x/ts409-setup.c
11 --- a/arch/arm/mach-orion5x/Kconfig
12 +++ b/arch/arm/mach-orion5x/Kconfig
14 Buffalo Linkstation Pro/Live platform. Both v1 and
15 v2 devices are supported.
20 + Say 'Y' here if you want your kernel to support the
21 + QNAP TS-409 platform.
26 --- a/arch/arm/mach-orion5x/Makefile
27 +++ b/arch/arm/mach-orion5x/Makefile
29 obj-$(CONFIG_MACH_LINKSTATION_PRO) += kurobox_pro-setup.o
30 obj-$(CONFIG_MACH_DNS323) += dns323-setup.o
31 obj-$(CONFIG_MACH_TS209) += ts209-setup.o
32 +obj-$(CONFIG_MACH_TS409) += ts409-setup.o
34 +++ b/arch/arm/mach-orion5x/ts409-setup.c
37 + * QNAP TS-409 Board Setup
39 + * Maintainer: Sylver Bruneau <sylver.bruneau@gmail.com>
41 + * This program is free software; you can redistribute it and/or
42 + * modify it under the terms of the GNU General Public License
43 + * as published by the Free Software Foundation; either version
44 + * 2 of the License, or (at your option) any later version.
47 +#include <linux/kernel.h>
48 +#include <linux/init.h>
49 +#include <linux/platform_device.h>
50 +#include <linux/pci.h>
51 +#include <linux/irq.h>
52 +#include <linux/mtd/physmap.h>
53 +#include <linux/mv643xx_eth.h>
54 +#include <linux/gpio_keys.h>
55 +#include <linux/input.h>
56 +#include <linux/i2c.h>
57 +#include <linux/serial_reg.h>
58 +#include <asm/mach-types.h>
59 +#include <asm/gpio.h>
60 +#include <asm/mach/arch.h>
61 +#include <asm/mach/pci.h>
62 +#include <asm/arch/orion5x.h>
66 +/*****************************************************************************
68 + ****************************************************************************/
71 + * QNAP TS-409 hardware :
72 + * - Marvell 88F5281-D0
73 + * - Marvell 88SX7042 SATA controller (PCIe)
74 + * - Marvell 88E1118 Gigabit Ethernet PHY
75 + * - RTC S35390A (@0x30) on I2C bus
77 + * - 256MB of DDR-2 RAM
81 + * 8MB NOR flash Device bus boot chip select
84 +#define QNAP_TS409_NOR_BOOT_BASE 0xff800000
85 +#define QNAP_TS409_NOR_BOOT_SIZE SZ_8M
87 +/****************************************************************************
88 + * 8MiB NOR flash. The struct mtd_partition is not in the same order as the
89 + * partitions on the device because we want to keep compatability with
90 + * existing QNAP firmware.
92 + * Layout as used by QNAP:
93 + * [2] 0x00000000-0x00200000 : "Kernel"
94 + * [3] 0x00200000-0x00600000 : "RootFS1"
95 + * [4] 0x00600000-0x00700000 : "RootFS2"
96 + * [6] 0x00700000-0x00760000 : "NAS Config" (read-only)
97 + * [5] 0x00760000-0x00780000 : "U-Boot Config"
98 + * [1] 0x00780000-0x00800000 : "U-Boot" (read-only)
99 + ***************************************************************************/
100 +static struct mtd_partition qnap_ts409_partitions[] = {
103 + .size = 0x00080000,
104 + .offset = 0x00780000,
105 + .mask_flags = MTD_WRITEABLE,
108 + .size = 0x00200000,
112 + .size = 0x00400000,
113 + .offset = 0x00200000,
116 + .size = 0x00100000,
117 + .offset = 0x00600000,
119 + .name = "U-Boot Config",
120 + .size = 0x00020000,
121 + .offset = 0x00760000,
123 + .name = "NAS Config",
124 + .size = 0x00060000,
125 + .offset = 0x00700000,
126 + .mask_flags = MTD_WRITEABLE,
130 +static struct physmap_flash_data qnap_ts409_nor_flash_data = {
132 + .parts = qnap_ts409_partitions,
133 + .nr_parts = ARRAY_SIZE(qnap_ts409_partitions)
136 +static struct resource qnap_ts409_nor_flash_resource = {
137 + .flags = IORESOURCE_MEM,
138 + .start = QNAP_TS409_NOR_BOOT_BASE,
139 + .end = QNAP_TS409_NOR_BOOT_BASE + QNAP_TS409_NOR_BOOT_SIZE - 1,
142 +static struct platform_device qnap_ts409_nor_flash = {
143 + .name = "physmap-flash",
145 + .dev = { .platform_data = &qnap_ts409_nor_flash_data, },
146 + .num_resources = 1,
147 + .resource = &qnap_ts409_nor_flash_resource,
150 +/*****************************************************************************
152 + ****************************************************************************/
154 +static int __init qnap_ts409_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
159 + * Check for devices with hard-wired IRQs.
161 + irq = orion5x_pci_map_irq(dev, slot, pin);
166 + * PCI isn't used on the TS-409
168 + printk(KERN_ERR "kurobox_pro_pci_map_irq failed, unknown bus\n");
172 +static struct hw_pci qnap_ts409_pci __initdata = {
173 + .nr_controllers = 2,
174 + .swizzle = pci_std_swizzle,
175 + .setup = orion5x_pci_sys_setup,
176 + .scan = orion5x_pci_sys_scan_bus,
177 + .map_irq = qnap_ts409_pci_map_irq,
180 +static int __init qnap_ts409_pci_init(void)
182 + if (machine_is_ts409())
183 + pci_common_init(&qnap_ts409_pci);
188 +subsys_initcall(qnap_ts409_pci_init);
190 +/*****************************************************************************
192 + ****************************************************************************/
194 +static struct mv643xx_eth_platform_data qnap_ts409_eth_data = {
198 +static int __init parse_hex_nibble(char n)
200 + if (n >= '0' && n <= '9')
203 + if (n >= 'A' && n <= 'F')
204 + return n - 'A' + 10;
206 + if (n >= 'a' && n <= 'f')
207 + return n - 'a' + 10;
212 +static int __init parse_hex_byte(const char *b)
217 + hi = parse_hex_nibble(b[0]);
218 + lo = parse_hex_nibble(b[1]);
220 + if (hi < 0 || lo < 0)
223 + return (hi << 4) | lo;
226 +static int __init check_mac_addr(const char *addr_str)
231 + for (i = 0; i < 6; i++) {
235 + * Enforce "xx:xx:xx:xx:xx:xx\n" format.
237 + if (addr_str[(i * 3) + 2] != ((i < 5) ? ':' : '\n'))
240 + byte = parse_hex_byte(addr_str + (i * 3));
246 + printk(KERN_INFO "ts409: found ethernet mac address ");
247 + for (i = 0; i < 6; i++)
248 + printk("%.2x%s", addr[i], (i < 5) ? ":" : ".\n");
250 + memcpy(qnap_ts409_eth_data.mac_addr, addr, 6);
256 + * The 'NAS Config' flash partition has an ext2 filesystem which
257 + * contains a file that has the ethernet MAC address in plain text
258 + * (format "xx:xx:xx:xx:xx:xx\n".)
260 +static void __init ts409_find_mac_addr(void)
262 + unsigned long addr;
264 + for (addr = 0x00700000; addr < 0x00760000; addr += 1024) {
268 + nor_page = ioremap(QNAP_TS409_NOR_BOOT_BASE + addr, 1024);
269 + if (nor_page != NULL) {
270 + ret = check_mac_addr(nor_page);
279 +/*****************************************************************************
280 + * RTC S35390A on I2C bus
281 + ****************************************************************************/
283 +#define TS409_RTC_GPIO 10
285 +static struct i2c_board_info __initdata qnap_ts409_i2c_rtc = {
286 + I2C_BOARD_INFO("s35390a", 0x30),
290 +/****************************************************************************
291 + * GPIO Attached Keys
292 + * Power button is attached to the PIC microcontroller
293 + ****************************************************************************/
295 +#define QNAP_TS409_GPIO_KEY_MEDIA 15
297 +static struct gpio_keys_button qnap_ts409_buttons[] = {
299 + .code = KEY_RESTART,
300 + .gpio = QNAP_TS409_GPIO_KEY_MEDIA,
301 + .desc = "USB Copy Button",
306 +static struct gpio_keys_platform_data qnap_ts409_button_data = {
307 + .buttons = qnap_ts409_buttons,
308 + .nbuttons = ARRAY_SIZE(qnap_ts409_buttons),
311 +static struct platform_device qnap_ts409_button_device = {
312 + .name = "gpio-keys",
314 + .num_resources = 0,
316 + .platform_data = &qnap_ts409_button_data,
320 +/*****************************************************************************
322 + ****************************************************************************/
325 + * QNAP TS-409 specific power off method via UART1-attached PIC
328 +#define UART1_REG(x) (UART1_VIRT_BASE + ((UART_##x) << 2))
330 +static void qnap_ts409_power_off(void)
332 + /* 19200 baud divisor */
333 + const unsigned divisor = ((ORION5X_TCLK + (8 * 19200)) / (16 * 19200));
335 + pr_info("%s: triggering power-off...\n", __func__);
337 + /* hijack uart1 and reset into sane state (19200,8n1) */
338 + writel(0x83, UART1_REG(LCR));
339 + writel(divisor & 0xff, UART1_REG(DLL));
340 + writel((divisor >> 8) & 0xff, UART1_REG(DLM));
341 + writel(0x03, UART1_REG(LCR));
342 + writel(0x00, UART1_REG(IER));
343 + writel(0x00, UART1_REG(FCR));
344 + writel(0x00, UART1_REG(MCR));
346 + /* send the power-off command 'A' to PIC */
347 + writel('A', UART1_REG(TX));
350 +static void __init qnap_ts409_init(void)
353 + * Setup basic Orion functions. Need to be called early.
357 + orion5x_mpp_conf(0, MPP_UNUSED);
358 + orion5x_mpp_conf(1, MPP_UNUSED);
359 + orion5x_mpp_conf(2, MPP_UNUSED);
360 + orion5x_mpp_conf(3, MPP_UNUSED);
361 + orion5x_mpp_conf(4, MPP_GPIO); /* HDD 1 status */
362 + orion5x_mpp_conf(5, MPP_GPIO); /* HDD 2 status */
363 + orion5x_mpp_conf(6, MPP_GPIO); /* HDD 3 status */
364 + orion5x_mpp_conf(7, MPP_GPIO); /* HDD 4 status */
365 + orion5x_mpp_conf(8, MPP_UNUSED);
366 + orion5x_mpp_conf(9, MPP_UNUSED);
367 + orion5x_mpp_conf(10, MPP_GPIO); /* RTC int */
368 + orion5x_mpp_conf(11, MPP_UNUSED);
369 + orion5x_mpp_conf(12, MPP_UNUSED);
370 + orion5x_mpp_conf(13, MPP_UNUSED);
371 + orion5x_mpp_conf(14, MPP_GPIO); /* SW_RST */
372 + orion5x_mpp_conf(15, MPP_GPIO); /* USB copy button */
373 + orion5x_mpp_conf(16, MPP_UART); /* UART1 RXD */
374 + orion5x_mpp_conf(17, MPP_UART); /* UART1 TXD */
375 + orion5x_mpp_conf(18, MPP_UNUSED);
376 + orion5x_mpp_conf(19, MPP_UNUSED);
379 + * Configure peripherals.
381 + orion5x_ehci0_init();
382 + ts409_find_mac_addr();
383 + orion5x_eth_init(&qnap_ts409_eth_data);
384 + orion5x_i2c_init();
385 + orion5x_uart0_init();
387 + orion5x_setup_dev_boot_win(QNAP_TS409_NOR_BOOT_BASE,
388 + QNAP_TS409_NOR_BOOT_SIZE);
389 + platform_device_register(&qnap_ts409_nor_flash);
391 + platform_device_register(&qnap_ts409_button_device);
393 + /* Get RTC IRQ and register the chip */
394 + if (gpio_request(TS409_RTC_GPIO, "rtc") == 0) {
395 + if (gpio_direction_input(TS409_RTC_GPIO) == 0)
396 + qnap_ts409_i2c_rtc.irq = gpio_to_irq(TS409_RTC_GPIO);
398 + gpio_free(TS409_RTC_GPIO);
400 + if (qnap_ts409_i2c_rtc.irq == 0)
401 + pr_warning("qnap_ts409_init: failed to get RTC IRQ\n");
402 + i2c_register_board_info(0, &qnap_ts409_i2c_rtc, 1);
404 + /* register ts409 specific power-off method */
405 + pm_power_off = qnap_ts409_power_off;
408 +MACHINE_START(TS409, "QNAP TS-409")
409 + /* Maintainer: Sylver Bruneau <sylver.bruneau@gmail.com> */
410 + .phys_io = ORION5X_REGS_PHYS_BASE,
411 + .io_pg_offst = ((ORION5X_REGS_VIRT_BASE) >> 18) & 0xFFFC,
412 + .boot_params = 0x00000100,
413 + .init_machine = qnap_ts409_init,
414 + .map_io = orion5x_map_io,
415 + .init_irq = orion5x_init_irq,
416 + .timer = &orion5x_timer,
417 + .fixup = tag_fixup_mem32,