Sylver Bruneau | 47e9cff | 2008-04-26 02:35:29 +0200 | [diff] [blame] | 1 | /* |
| 2 | * QNAP TS-409 Board Setup |
| 3 | * |
| 4 | * Maintainer: Sylver Bruneau <sylver.bruneau@gmail.com> |
| 5 | * |
Martin Michlmayr | 4a4e30a | 2008-07-21 19:58:48 +0300 | [diff] [blame] | 6 | * Copyright (C) 2008 Sylver Bruneau <sylver.bruneau@gmail.com> |
| 7 | * Copyright (C) 2008 Martin Michlmayr <tbm@cyrius.com> |
| 8 | * |
Sylver Bruneau | 47e9cff | 2008-04-26 02:35:29 +0200 | [diff] [blame] | 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License |
| 11 | * as published by the Free Software Foundation; either version |
| 12 | * 2 of the License, or (at your option) any later version. |
| 13 | */ |
| 14 | |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/pci.h> |
| 19 | #include <linux/irq.h> |
| 20 | #include <linux/mtd/physmap.h> |
| 21 | #include <linux/mv643xx_eth.h> |
Martin Michlmayr | 4a4e30a | 2008-07-21 19:58:48 +0300 | [diff] [blame] | 22 | #include <linux/leds.h> |
Sylver Bruneau | 47e9cff | 2008-04-26 02:35:29 +0200 | [diff] [blame] | 23 | #include <linux/gpio_keys.h> |
| 24 | #include <linux/input.h> |
| 25 | #include <linux/i2c.h> |
| 26 | #include <linux/serial_reg.h> |
| 27 | #include <asm/mach-types.h> |
| 28 | #include <asm/gpio.h> |
| 29 | #include <asm/mach/arch.h> |
| 30 | #include <asm/mach/pci.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 31 | #include <mach/orion5x.h> |
Sylver Bruneau | 47e9cff | 2008-04-26 02:35:29 +0200 | [diff] [blame] | 32 | #include "common.h" |
| 33 | #include "mpp.h" |
Sylver Bruneau | 530c854 | 2008-05-31 18:21:49 +0200 | [diff] [blame] | 34 | #include "tsx09-common.h" |
Sylver Bruneau | 47e9cff | 2008-04-26 02:35:29 +0200 | [diff] [blame] | 35 | |
| 36 | /***************************************************************************** |
| 37 | * QNAP TS-409 Info |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | /* |
| 41 | * QNAP TS-409 hardware : |
| 42 | * - Marvell 88F5281-D0 |
| 43 | * - Marvell 88SX7042 SATA controller (PCIe) |
| 44 | * - Marvell 88E1118 Gigabit Ethernet PHY |
| 45 | * - RTC S35390A (@0x30) on I2C bus |
| 46 | * - 8MB NOR flash |
| 47 | * - 256MB of DDR-2 RAM |
| 48 | */ |
| 49 | |
| 50 | /* |
| 51 | * 8MB NOR flash Device bus boot chip select |
| 52 | */ |
| 53 | |
| 54 | #define QNAP_TS409_NOR_BOOT_BASE 0xff800000 |
| 55 | #define QNAP_TS409_NOR_BOOT_SIZE SZ_8M |
| 56 | |
| 57 | /**************************************************************************** |
| 58 | * 8MiB NOR flash. The struct mtd_partition is not in the same order as the |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 59 | * partitions on the device because we want to keep compatibility with |
Sylver Bruneau | 47e9cff | 2008-04-26 02:35:29 +0200 | [diff] [blame] | 60 | * existing QNAP firmware. |
| 61 | * |
| 62 | * Layout as used by QNAP: |
| 63 | * [2] 0x00000000-0x00200000 : "Kernel" |
| 64 | * [3] 0x00200000-0x00600000 : "RootFS1" |
| 65 | * [4] 0x00600000-0x00700000 : "RootFS2" |
| 66 | * [6] 0x00700000-0x00760000 : "NAS Config" (read-only) |
| 67 | * [5] 0x00760000-0x00780000 : "U-Boot Config" |
| 68 | * [1] 0x00780000-0x00800000 : "U-Boot" (read-only) |
| 69 | ***************************************************************************/ |
| 70 | static struct mtd_partition qnap_ts409_partitions[] = { |
| 71 | { |
| 72 | .name = "U-Boot", |
| 73 | .size = 0x00080000, |
| 74 | .offset = 0x00780000, |
| 75 | .mask_flags = MTD_WRITEABLE, |
| 76 | }, { |
| 77 | .name = "Kernel", |
| 78 | .size = 0x00200000, |
| 79 | .offset = 0, |
| 80 | }, { |
| 81 | .name = "RootFS1", |
| 82 | .size = 0x00400000, |
| 83 | .offset = 0x00200000, |
| 84 | }, { |
| 85 | .name = "RootFS2", |
| 86 | .size = 0x00100000, |
| 87 | .offset = 0x00600000, |
| 88 | }, { |
| 89 | .name = "U-Boot Config", |
| 90 | .size = 0x00020000, |
| 91 | .offset = 0x00760000, |
| 92 | }, { |
| 93 | .name = "NAS Config", |
| 94 | .size = 0x00060000, |
| 95 | .offset = 0x00700000, |
| 96 | .mask_flags = MTD_WRITEABLE, |
| 97 | }, |
| 98 | }; |
| 99 | |
| 100 | static struct physmap_flash_data qnap_ts409_nor_flash_data = { |
| 101 | .width = 1, |
| 102 | .parts = qnap_ts409_partitions, |
| 103 | .nr_parts = ARRAY_SIZE(qnap_ts409_partitions) |
| 104 | }; |
| 105 | |
| 106 | static struct resource qnap_ts409_nor_flash_resource = { |
| 107 | .flags = IORESOURCE_MEM, |
| 108 | .start = QNAP_TS409_NOR_BOOT_BASE, |
| 109 | .end = QNAP_TS409_NOR_BOOT_BASE + QNAP_TS409_NOR_BOOT_SIZE - 1, |
| 110 | }; |
| 111 | |
| 112 | static struct platform_device qnap_ts409_nor_flash = { |
| 113 | .name = "physmap-flash", |
| 114 | .id = 0, |
| 115 | .dev = { .platform_data = &qnap_ts409_nor_flash_data, }, |
| 116 | .num_resources = 1, |
| 117 | .resource = &qnap_ts409_nor_flash_resource, |
| 118 | }; |
| 119 | |
| 120 | /***************************************************************************** |
| 121 | * PCI |
| 122 | ****************************************************************************/ |
| 123 | |
| 124 | static int __init qnap_ts409_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin) |
| 125 | { |
| 126 | int irq; |
| 127 | |
| 128 | /* |
| 129 | * Check for devices with hard-wired IRQs. |
| 130 | */ |
| 131 | irq = orion5x_pci_map_irq(dev, slot, pin); |
| 132 | if (irq != -1) |
| 133 | return irq; |
| 134 | |
| 135 | /* |
| 136 | * PCI isn't used on the TS-409 |
| 137 | */ |
| 138 | return -1; |
| 139 | } |
| 140 | |
| 141 | static struct hw_pci qnap_ts409_pci __initdata = { |
| 142 | .nr_controllers = 2, |
| 143 | .swizzle = pci_std_swizzle, |
| 144 | .setup = orion5x_pci_sys_setup, |
| 145 | .scan = orion5x_pci_sys_scan_bus, |
| 146 | .map_irq = qnap_ts409_pci_map_irq, |
| 147 | }; |
| 148 | |
| 149 | static int __init qnap_ts409_pci_init(void) |
| 150 | { |
| 151 | if (machine_is_ts409()) |
| 152 | pci_common_init(&qnap_ts409_pci); |
| 153 | |
| 154 | return 0; |
| 155 | } |
| 156 | |
| 157 | subsys_initcall(qnap_ts409_pci_init); |
| 158 | |
| 159 | /***************************************************************************** |
Sylver Bruneau | 47e9cff | 2008-04-26 02:35:29 +0200 | [diff] [blame] | 160 | * RTC S35390A on I2C bus |
| 161 | ****************************************************************************/ |
| 162 | |
| 163 | #define TS409_RTC_GPIO 10 |
| 164 | |
| 165 | static struct i2c_board_info __initdata qnap_ts409_i2c_rtc = { |
| 166 | I2C_BOARD_INFO("s35390a", 0x30), |
| 167 | }; |
| 168 | |
Martin Michlmayr | 4a4e30a | 2008-07-21 19:58:48 +0300 | [diff] [blame] | 169 | /***************************************************************************** |
| 170 | * LEDs attached to GPIO |
| 171 | ****************************************************************************/ |
| 172 | |
| 173 | static struct gpio_led ts409_led_pins[] = { |
| 174 | { |
| 175 | .name = "ts409:red:sata1", |
| 176 | .gpio = 4, |
| 177 | .active_low = 1, |
| 178 | }, { |
| 179 | .name = "ts409:red:sata2", |
| 180 | .gpio = 5, |
| 181 | .active_low = 1, |
| 182 | }, { |
| 183 | .name = "ts409:red:sata3", |
| 184 | .gpio = 6, |
| 185 | .active_low = 1, |
| 186 | }, { |
| 187 | .name = "ts409:red:sata4", |
| 188 | .gpio = 7, |
| 189 | .active_low = 1, |
| 190 | }, |
| 191 | }; |
| 192 | |
| 193 | static struct gpio_led_platform_data ts409_led_data = { |
| 194 | .leds = ts409_led_pins, |
| 195 | .num_leds = ARRAY_SIZE(ts409_led_pins), |
| 196 | }; |
| 197 | |
| 198 | static struct platform_device ts409_leds = { |
| 199 | .name = "leds-gpio", |
| 200 | .id = -1, |
| 201 | .dev = { |
| 202 | .platform_data = &ts409_led_data, |
| 203 | }, |
| 204 | }; |
| 205 | |
Sylver Bruneau | 47e9cff | 2008-04-26 02:35:29 +0200 | [diff] [blame] | 206 | /**************************************************************************** |
| 207 | * GPIO Attached Keys |
| 208 | * Power button is attached to the PIC microcontroller |
| 209 | ****************************************************************************/ |
| 210 | |
Martin Michlmayr | 5cebbd0 | 2008-07-31 07:38:08 +0300 | [diff] [blame] | 211 | #define QNAP_TS409_GPIO_KEY_RESET 14 |
Sylver Bruneau | 47e9cff | 2008-04-26 02:35:29 +0200 | [diff] [blame] | 212 | #define QNAP_TS409_GPIO_KEY_MEDIA 15 |
| 213 | |
| 214 | static struct gpio_keys_button qnap_ts409_buttons[] = { |
| 215 | { |
Martin Michlmayr | 5cebbd0 | 2008-07-31 07:38:08 +0300 | [diff] [blame] | 216 | .code = KEY_RESTART, |
| 217 | .gpio = QNAP_TS409_GPIO_KEY_RESET, |
| 218 | .desc = "Reset Button", |
| 219 | .active_low = 1, |
| 220 | }, { |
Martin Michlmayr | 28ca8c8 | 2008-07-22 01:49:22 +0300 | [diff] [blame] | 221 | .code = KEY_COPY, |
Sylver Bruneau | 47e9cff | 2008-04-26 02:35:29 +0200 | [diff] [blame] | 222 | .gpio = QNAP_TS409_GPIO_KEY_MEDIA, |
| 223 | .desc = "USB Copy Button", |
| 224 | .active_low = 1, |
| 225 | }, |
| 226 | }; |
| 227 | |
| 228 | static struct gpio_keys_platform_data qnap_ts409_button_data = { |
| 229 | .buttons = qnap_ts409_buttons, |
| 230 | .nbuttons = ARRAY_SIZE(qnap_ts409_buttons), |
| 231 | }; |
| 232 | |
| 233 | static struct platform_device qnap_ts409_button_device = { |
| 234 | .name = "gpio-keys", |
| 235 | .id = -1, |
| 236 | .num_resources = 0, |
| 237 | .dev = { |
| 238 | .platform_data = &qnap_ts409_button_data, |
| 239 | }, |
| 240 | }; |
| 241 | |
| 242 | /***************************************************************************** |
| 243 | * General Setup |
| 244 | ****************************************************************************/ |
Andrew Lunn | 554cdae | 2011-05-15 13:32:53 +0200 | [diff] [blame] | 245 | static unsigned int ts409_mpp_modes[] __initdata = { |
| 246 | MPP0_UNUSED, |
| 247 | MPP1_UNUSED, |
| 248 | MPP2_UNUSED, |
| 249 | MPP3_UNUSED, |
| 250 | MPP4_GPIO, /* HDD 1 status */ |
| 251 | MPP5_GPIO, /* HDD 2 status */ |
| 252 | MPP6_GPIO, /* HDD 3 status */ |
| 253 | MPP7_GPIO, /* HDD 4 status */ |
| 254 | MPP8_UNUSED, |
| 255 | MPP9_UNUSED, |
| 256 | MPP10_GPIO, /* RTC int */ |
| 257 | MPP11_UNUSED, |
| 258 | MPP12_UNUSED, |
| 259 | MPP13_UNUSED, |
| 260 | MPP14_GPIO, /* SW_RST */ |
| 261 | MPP15_GPIO, /* USB copy button */ |
| 262 | MPP16_UART, /* UART1 RXD */ |
| 263 | MPP17_UART, /* UART1 TXD */ |
| 264 | MPP18_UNUSED, |
| 265 | MPP19_UNUSED, |
| 266 | 0, |
Sylver Bruneau | 47e9cff | 2008-04-26 02:35:29 +0200 | [diff] [blame] | 267 | }; |
| 268 | |
Sylver Bruneau | 47e9cff | 2008-04-26 02:35:29 +0200 | [diff] [blame] | 269 | static void __init qnap_ts409_init(void) |
| 270 | { |
| 271 | /* |
| 272 | * Setup basic Orion functions. Need to be called early. |
| 273 | */ |
| 274 | orion5x_init(); |
| 275 | |
| 276 | orion5x_mpp_conf(ts409_mpp_modes); |
| 277 | |
| 278 | /* |
| 279 | * Configure peripherals. |
| 280 | */ |
Martin Michlmayr | 35228e8 | 2008-08-09 18:13:33 +0300 | [diff] [blame] | 281 | orion5x_setup_dev_boot_win(QNAP_TS409_NOR_BOOT_BASE, |
| 282 | QNAP_TS409_NOR_BOOT_SIZE); |
| 283 | platform_device_register(&qnap_ts409_nor_flash); |
| 284 | |
Sylver Bruneau | 47e9cff | 2008-04-26 02:35:29 +0200 | [diff] [blame] | 285 | orion5x_ehci0_init(); |
Sylver Bruneau | 530c854 | 2008-05-31 18:21:49 +0200 | [diff] [blame] | 286 | qnap_tsx09_find_mac_addr(QNAP_TS409_NOR_BOOT_BASE + |
| 287 | qnap_ts409_partitions[5].offset, |
| 288 | qnap_ts409_partitions[5].size); |
| 289 | orion5x_eth_init(&qnap_tsx09_eth_data); |
Sylver Bruneau | 47e9cff | 2008-04-26 02:35:29 +0200 | [diff] [blame] | 290 | orion5x_i2c_init(); |
| 291 | orion5x_uart0_init(); |
Martin Michlmayr | e45772b | 2008-08-13 10:46:11 +0300 | [diff] [blame] | 292 | orion5x_uart1_init(); |
Sylver Bruneau | 47e9cff | 2008-04-26 02:35:29 +0200 | [diff] [blame] | 293 | |
Sylver Bruneau | 47e9cff | 2008-04-26 02:35:29 +0200 | [diff] [blame] | 294 | platform_device_register(&qnap_ts409_button_device); |
| 295 | |
| 296 | /* Get RTC IRQ and register the chip */ |
| 297 | if (gpio_request(TS409_RTC_GPIO, "rtc") == 0) { |
| 298 | if (gpio_direction_input(TS409_RTC_GPIO) == 0) |
| 299 | qnap_ts409_i2c_rtc.irq = gpio_to_irq(TS409_RTC_GPIO); |
| 300 | else |
| 301 | gpio_free(TS409_RTC_GPIO); |
| 302 | } |
| 303 | if (qnap_ts409_i2c_rtc.irq == 0) |
| 304 | pr_warning("qnap_ts409_init: failed to get RTC IRQ\n"); |
| 305 | i2c_register_board_info(0, &qnap_ts409_i2c_rtc, 1); |
Martin Michlmayr | 4a4e30a | 2008-07-21 19:58:48 +0300 | [diff] [blame] | 306 | platform_device_register(&ts409_leds); |
Sylver Bruneau | 47e9cff | 2008-04-26 02:35:29 +0200 | [diff] [blame] | 307 | |
Sylver Bruneau | 530c854 | 2008-05-31 18:21:49 +0200 | [diff] [blame] | 308 | /* register tsx09 specific power-off method */ |
| 309 | pm_power_off = qnap_tsx09_power_off; |
Sylver Bruneau | 47e9cff | 2008-04-26 02:35:29 +0200 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | MACHINE_START(TS409, "QNAP TS-409") |
| 313 | /* Maintainer: Sylver Bruneau <sylver.bruneau@gmail.com> */ |
Sylver Bruneau | 47e9cff | 2008-04-26 02:35:29 +0200 | [diff] [blame] | 314 | .boot_params = 0x00000100, |
| 315 | .init_machine = qnap_ts409_init, |
| 316 | .map_io = orion5x_map_io, |
Lennert Buytenhek | 4ee1f6b | 2010-10-15 16:50:26 +0200 | [diff] [blame] | 317 | .init_early = orion5x_init_early, |
Sylver Bruneau | 47e9cff | 2008-04-26 02:35:29 +0200 | [diff] [blame] | 318 | .init_irq = orion5x_init_irq, |
| 319 | .timer = &orion5x_timer, |
| 320 | .fixup = tag_fixup_mem32, |
| 321 | MACHINE_END |