blob: 809132de31d213d2177e5e8de031a749f863e5fc [file] [log] [blame]
Byron Bradley3faf2ee2007-12-15 20:05:49 +00001/*
2 * QNAP TS-109/TS-209 Board Setup
3 *
4 * Maintainer: Byron Bradley <byron.bbradley@gmail.com>
5 *
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.
10 */
11
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>
Herbert Valerio Riedel8f86dda2007-12-16 17:42:31 +010023#include <linux/serial_reg.h>
Byron Bradleyee443912008-02-08 18:20:23 +000024#include <linux/ata_platform.h>
Byron Bradley3faf2ee2007-12-15 20:05:49 +000025#include <asm/mach-types.h>
26#include <asm/gpio.h>
27#include <asm/mach/arch.h>
28#include <asm/mach/pci.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010029#include <mach/orion5x.h>
Byron Bradley3faf2ee2007-12-15 20:05:49 +000030#include "common.h"
Lennert Buytenhek19cfd5c2008-05-10 23:25:46 +020031#include "mpp.h"
Sylver Bruneau530c8542008-05-31 18:21:49 +020032#include "tsx09-common.h"
Byron Bradley3faf2ee2007-12-15 20:05:49 +000033
34#define QNAP_TS209_NOR_BOOT_BASE 0xf4000000
35#define QNAP_TS209_NOR_BOOT_SIZE SZ_8M
36
37/****************************************************************************
38 * 8MiB NOR flash. The struct mtd_partition is not in the same order as the
39 * partitions on the device because we want to keep compatability with
40 * existing QNAP firmware.
41 *
42 * Layout as used by QNAP:
43 * [2] 0x00000000-0x00200000 : "Kernel"
44 * [3] 0x00200000-0x00600000 : "RootFS1"
45 * [4] 0x00600000-0x00700000 : "RootFS2"
46 * [6] 0x00700000-0x00760000 : "NAS Config" (read-only)
47 * [5] 0x00760000-0x00780000 : "U-Boot Config"
48 * [1] 0x00780000-0x00800000 : "U-Boot" (read-only)
49 ***************************************************************************/
50static struct mtd_partition qnap_ts209_partitions[] = {
51 {
Lennert Buytenheke7068ad2008-05-10 16:30:01 +020052 .name = "U-Boot",
53 .size = 0x00080000,
54 .offset = 0x00780000,
55 .mask_flags = MTD_WRITEABLE,
Byron Bradley3faf2ee2007-12-15 20:05:49 +000056 }, {
Lennert Buytenheke7068ad2008-05-10 16:30:01 +020057 .name = "Kernel",
58 .size = 0x00200000,
59 .offset = 0,
Byron Bradley3faf2ee2007-12-15 20:05:49 +000060 }, {
Lennert Buytenheke7068ad2008-05-10 16:30:01 +020061 .name = "RootFS1",
62 .size = 0x00400000,
63 .offset = 0x00200000,
Byron Bradley3faf2ee2007-12-15 20:05:49 +000064 }, {
Lennert Buytenheke7068ad2008-05-10 16:30:01 +020065 .name = "RootFS2",
66 .size = 0x00100000,
67 .offset = 0x00600000,
Byron Bradley3faf2ee2007-12-15 20:05:49 +000068 }, {
Lennert Buytenheke7068ad2008-05-10 16:30:01 +020069 .name = "U-Boot Config",
70 .size = 0x00020000,
71 .offset = 0x00760000,
Byron Bradley3faf2ee2007-12-15 20:05:49 +000072 }, {
Lennert Buytenheke7068ad2008-05-10 16:30:01 +020073 .name = "NAS Config",
74 .size = 0x00060000,
75 .offset = 0x00700000,
76 .mask_flags = MTD_WRITEABLE,
77 },
Byron Bradley3faf2ee2007-12-15 20:05:49 +000078};
79
80static struct physmap_flash_data qnap_ts209_nor_flash_data = {
Lennert Buytenheke7068ad2008-05-10 16:30:01 +020081 .width = 1,
82 .parts = qnap_ts209_partitions,
83 .nr_parts = ARRAY_SIZE(qnap_ts209_partitions)
Byron Bradley3faf2ee2007-12-15 20:05:49 +000084};
85
86static struct resource qnap_ts209_nor_flash_resource = {
Lennert Buytenheke7068ad2008-05-10 16:30:01 +020087 .flags = IORESOURCE_MEM,
88 .start = QNAP_TS209_NOR_BOOT_BASE,
89 .end = QNAP_TS209_NOR_BOOT_BASE + QNAP_TS209_NOR_BOOT_SIZE - 1,
Byron Bradley3faf2ee2007-12-15 20:05:49 +000090};
91
92static struct platform_device qnap_ts209_nor_flash = {
Lennert Buytenheke7068ad2008-05-10 16:30:01 +020093 .name = "physmap-flash",
94 .id = 0,
95 .dev = {
96 .platform_data = &qnap_ts209_nor_flash_data,
97 },
98 .resource = &qnap_ts209_nor_flash_resource,
99 .num_resources = 1,
Byron Bradley3faf2ee2007-12-15 20:05:49 +0000100};
101
102/*****************************************************************************
103 * PCI
104 ****************************************************************************/
105
106#define QNAP_TS209_PCI_SLOT0_OFFS 7
107#define QNAP_TS209_PCI_SLOT0_IRQ_PIN 6
108#define QNAP_TS209_PCI_SLOT1_IRQ_PIN 7
109
110void __init qnap_ts209_pci_preinit(void)
111{
112 int pin;
113
114 /*
115 * Configure PCI GPIO IRQ pins
116 */
117 pin = QNAP_TS209_PCI_SLOT0_IRQ_PIN;
118 if (gpio_request(pin, "PCI Int1") == 0) {
119 if (gpio_direction_input(pin) == 0) {
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100120 set_irq_type(gpio_to_irq(pin), IRQ_TYPE_LEVEL_LOW);
Byron Bradley3faf2ee2007-12-15 20:05:49 +0000121 } else {
122 printk(KERN_ERR "qnap_ts209_pci_preinit failed to "
123 "set_irq_type pin %d\n", pin);
124 gpio_free(pin);
125 }
126 } else {
127 printk(KERN_ERR "qnap_ts209_pci_preinit failed to gpio_request "
128 "%d\n", pin);
129 }
130
131 pin = QNAP_TS209_PCI_SLOT1_IRQ_PIN;
132 if (gpio_request(pin, "PCI Int2") == 0) {
133 if (gpio_direction_input(pin) == 0) {
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100134 set_irq_type(gpio_to_irq(pin), IRQ_TYPE_LEVEL_LOW);
Byron Bradley3faf2ee2007-12-15 20:05:49 +0000135 } else {
136 printk(KERN_ERR "qnap_ts209_pci_preinit failed "
137 "to set_irq_type pin %d\n", pin);
138 gpio_free(pin);
139 }
140 } else {
141 printk(KERN_ERR "qnap_ts209_pci_preinit failed to gpio_request "
142 "%d\n", pin);
143 }
144}
145
146static int __init qnap_ts209_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
147{
Lennert Buytenhek92b913b2008-04-25 16:28:33 -0400148 int irq;
Byron Bradley3faf2ee2007-12-15 20:05:49 +0000149
150 /*
Lennert Buytenhek92b913b2008-04-25 16:28:33 -0400151 * Check for devices with hard-wired IRQs.
152 */
153 irq = orion5x_pci_map_irq(dev, slot, pin);
154 if (irq != -1)
155 return irq;
156
157 /*
158 * PCI IRQs are connected via GPIOs.
Byron Bradley3faf2ee2007-12-15 20:05:49 +0000159 */
160 switch (slot - QNAP_TS209_PCI_SLOT0_OFFS) {
161 case 0:
162 return gpio_to_irq(QNAP_TS209_PCI_SLOT0_IRQ_PIN);
163 case 1:
164 return gpio_to_irq(QNAP_TS209_PCI_SLOT1_IRQ_PIN);
165 default:
166 return -1;
167 }
168}
169
170static struct hw_pci qnap_ts209_pci __initdata = {
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200171 .nr_controllers = 2,
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,
Byron Bradley3faf2ee2007-12-15 20:05:49 +0000177};
178
179static int __init qnap_ts209_pci_init(void)
180{
181 if (machine_is_ts_x09())
182 pci_common_init(&qnap_ts209_pci);
183
184 return 0;
185}
186
187subsys_initcall(qnap_ts209_pci_init);
188
189/*****************************************************************************
Byron Bradley3faf2ee2007-12-15 20:05:49 +0000190 * RTC S35390A on I2C bus
191 ****************************************************************************/
Byron Bradley59e8ce52008-02-10 22:31:09 +0100192
193#define TS209_RTC_GPIO 3
194
Byron Bradley3faf2ee2007-12-15 20:05:49 +0000195static struct i2c_board_info __initdata qnap_ts209_i2c_rtc = {
Jean Delvare3760f732008-04-29 23:11:40 +0200196 I2C_BOARD_INFO("s35390a", 0x30),
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200197 .irq = 0,
Byron Bradley3faf2ee2007-12-15 20:05:49 +0000198};
199
200/****************************************************************************
201 * GPIO Attached Keys
202 * Power button is attached to the PIC microcontroller
203 ****************************************************************************/
204
205#define QNAP_TS209_GPIO_KEY_MEDIA 1
206#define QNAP_TS209_GPIO_KEY_RESET 2
207
208static struct gpio_keys_button qnap_ts209_buttons[] = {
209 {
210 .code = KEY_RESTART,
211 .gpio = QNAP_TS209_GPIO_KEY_MEDIA,
212 .desc = "USB Copy Button",
213 .active_low = 1,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200214 }, {
Byron Bradley3faf2ee2007-12-15 20:05:49 +0000215 .code = KEY_POWER,
216 .gpio = QNAP_TS209_GPIO_KEY_RESET,
217 .desc = "Reset Button",
218 .active_low = 1,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200219 },
Byron Bradley3faf2ee2007-12-15 20:05:49 +0000220};
221
222static struct gpio_keys_platform_data qnap_ts209_button_data = {
223 .buttons = qnap_ts209_buttons,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200224 .nbuttons = ARRAY_SIZE(qnap_ts209_buttons),
Byron Bradley3faf2ee2007-12-15 20:05:49 +0000225};
226
227static struct platform_device qnap_ts209_button_device = {
228 .name = "gpio-keys",
229 .id = -1,
230 .num_resources = 0,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200231 .dev = {
232 .platform_data = &qnap_ts209_button_data,
233 },
Byron Bradley3faf2ee2007-12-15 20:05:49 +0000234};
235
236/*****************************************************************************
Byron Bradleyee443912008-02-08 18:20:23 +0000237 * SATA
238 ****************************************************************************/
239static struct mv_sata_platform_data qnap_ts209_sata_data = {
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200240 .n_ports = 2,
Byron Bradleyee443912008-02-08 18:20:23 +0000241};
242
243/*****************************************************************************
244
Byron Bradley3faf2ee2007-12-15 20:05:49 +0000245 * General Setup
246 ****************************************************************************/
Lennert Buytenhek19cfd5c2008-05-10 23:25:46 +0200247static struct orion5x_mpp_mode ts209_mpp_modes[] __initdata = {
248 { 0, MPP_UNUSED },
249 { 1, MPP_GPIO }, /* USB copy button */
250 { 2, MPP_GPIO }, /* Load defaults button */
251 { 3, MPP_GPIO }, /* GPIO RTC */
252 { 4, MPP_UNUSED },
253 { 5, MPP_UNUSED },
254 { 6, MPP_GPIO }, /* PCI Int A */
255 { 7, MPP_GPIO }, /* PCI Int B */
256 { 8, MPP_UNUSED },
257 { 9, MPP_UNUSED },
258 { 10, MPP_UNUSED },
259 { 11, MPP_UNUSED },
260 { 12, MPP_SATA_LED }, /* SATA 0 presence */
261 { 13, MPP_SATA_LED }, /* SATA 1 presence */
262 { 14, MPP_SATA_LED }, /* SATA 0 active */
263 { 15, MPP_SATA_LED }, /* SATA 1 active */
264 { 16, MPP_UART }, /* UART1 RXD */
265 { 17, MPP_UART }, /* UART1 TXD */
266 { 18, MPP_GPIO }, /* SW_RST */
267 { 19, MPP_UNUSED },
268 { -1 },
269};
270
Byron Bradley3faf2ee2007-12-15 20:05:49 +0000271static void __init qnap_ts209_init(void)
272{
273 /*
274 * Setup basic Orion functions. Need to be called early.
275 */
Lennert Buytenhek9dd0b192008-03-27 14:51:41 -0400276 orion5x_init();
Byron Bradley3faf2ee2007-12-15 20:05:49 +0000277
Lennert Buytenhek19cfd5c2008-05-10 23:25:46 +0200278 orion5x_mpp_conf(ts209_mpp_modes);
279
Byron Bradley3faf2ee2007-12-15 20:05:49 +0000280 /*
Byron Bradley3faf2ee2007-12-15 20:05:49 +0000281 * MPP[20] PCI clock 0
282 * MPP[21] PCI clock 1
283 * MPP[22] USB 0 over current
284 * MPP[23-25] Reserved
285 */
Byron Bradley3faf2ee2007-12-15 20:05:49 +0000286
Lennert Buytenhek044f6c72008-04-22 05:37:12 +0200287 /*
288 * Configure peripherals.
289 */
290 orion5x_ehci0_init();
291 orion5x_ehci1_init();
Sylver Bruneau530c8542008-05-31 18:21:49 +0200292 qnap_tsx09_find_mac_addr(QNAP_TS209_NOR_BOOT_BASE +
293 qnap_ts209_partitions[5].offset,
294 qnap_ts209_partitions[5].size);
295 orion5x_eth_init(&qnap_tsx09_eth_data);
Lennert Buytenhek044f6c72008-04-22 05:37:12 +0200296 orion5x_i2c_init();
297 orion5x_sata_init(&qnap_ts209_sata_data);
298 orion5x_uart0_init();
Herbert Valerio Riedel8f86dda2007-12-16 17:42:31 +0100299
Lennert Buytenhek044f6c72008-04-22 05:37:12 +0200300 orion5x_setup_dev_boot_win(QNAP_TS209_NOR_BOOT_BASE,
301 QNAP_TS209_NOR_BOOT_SIZE);
302 platform_device_register(&qnap_ts209_nor_flash);
303
304 platform_device_register(&qnap_ts209_button_device);
Byron Bradley59e8ce52008-02-10 22:31:09 +0100305
306 /* Get RTC IRQ and register the chip */
307 if (gpio_request(TS209_RTC_GPIO, "rtc") == 0) {
308 if (gpio_direction_input(TS209_RTC_GPIO) == 0)
309 qnap_ts209_i2c_rtc.irq = gpio_to_irq(TS209_RTC_GPIO);
310 else
311 gpio_free(TS209_RTC_GPIO);
312 }
313 if (qnap_ts209_i2c_rtc.irq == 0)
314 pr_warning("qnap_ts209_init: failed to get RTC IRQ\n");
Byron Bradley3faf2ee2007-12-15 20:05:49 +0000315 i2c_register_board_info(0, &qnap_ts209_i2c_rtc, 1);
Byron Bradley59e8ce52008-02-10 22:31:09 +0100316
Sylver Bruneau530c8542008-05-31 18:21:49 +0200317 /* register tsx09 specific power-off method */
318 pm_power_off = qnap_tsx09_power_off;
Byron Bradley3faf2ee2007-12-15 20:05:49 +0000319}
320
321MACHINE_START(TS209, "QNAP TS-109/TS-209")
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200322 /* Maintainer: Byron Bradley <byron.bbradley@gmail.com> */
Lennert Buytenhek9dd0b192008-03-27 14:51:41 -0400323 .phys_io = ORION5X_REGS_PHYS_BASE,
324 .io_pg_offst = ((ORION5X_REGS_VIRT_BASE) >> 18) & 0xFFFC,
Byron Bradley3faf2ee2007-12-15 20:05:49 +0000325 .boot_params = 0x00000100,
326 .init_machine = qnap_ts209_init,
Lennert Buytenhek9dd0b192008-03-27 14:51:41 -0400327 .map_io = orion5x_map_io,
328 .init_irq = orion5x_init_irq,
329 .timer = &orion5x_timer,
Guennadi Liakhovetskibe73a342008-02-29 21:12:57 +0100330 .fixup = tag_fixup_mem32,
Byron Bradley3faf2ee2007-12-15 20:05:49 +0000331MACHINE_END