Commit | Line | Data |
---|---|---|
47e9cffd SB |
1 | /* |
2 | * QNAP TS-409 Board Setup | |
3 | * | |
4 | * Maintainer: Sylver Bruneau <sylver.bruneau@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/mv643xx_eth.h> | |
19 | #include <linux/gpio_keys.h> | |
20 | #include <linux/input.h> | |
21 | #include <linux/i2c.h> | |
22 | #include <linux/serial_reg.h> | |
23 | #include <asm/mach-types.h> | |
24 | #include <asm/gpio.h> | |
25 | #include <asm/mach/arch.h> | |
26 | #include <asm/mach/pci.h> | |
27 | #include <asm/arch/orion5x.h> | |
28 | #include "common.h" | |
29 | #include "mpp.h" | |
530c854a | 30 | #include "tsx09-common.h" |
47e9cffd SB |
31 | |
32 | /***************************************************************************** | |
33 | * QNAP TS-409 Info | |
34 | ****************************************************************************/ | |
35 | ||
36 | /* | |
37 | * QNAP TS-409 hardware : | |
38 | * - Marvell 88F5281-D0 | |
39 | * - Marvell 88SX7042 SATA controller (PCIe) | |
40 | * - Marvell 88E1118 Gigabit Ethernet PHY | |
41 | * - RTC S35390A (@0x30) on I2C bus | |
42 | * - 8MB NOR flash | |
43 | * - 256MB of DDR-2 RAM | |
44 | */ | |
45 | ||
46 | /* | |
47 | * 8MB NOR flash Device bus boot chip select | |
48 | */ | |
49 | ||
50 | #define QNAP_TS409_NOR_BOOT_BASE 0xff800000 | |
51 | #define QNAP_TS409_NOR_BOOT_SIZE SZ_8M | |
52 | ||
53 | /**************************************************************************** | |
54 | * 8MiB NOR flash. The struct mtd_partition is not in the same order as the | |
55 | * partitions on the device because we want to keep compatability with | |
56 | * existing QNAP firmware. | |
57 | * | |
58 | * Layout as used by QNAP: | |
59 | * [2] 0x00000000-0x00200000 : "Kernel" | |
60 | * [3] 0x00200000-0x00600000 : "RootFS1" | |
61 | * [4] 0x00600000-0x00700000 : "RootFS2" | |
62 | * [6] 0x00700000-0x00760000 : "NAS Config" (read-only) | |
63 | * [5] 0x00760000-0x00780000 : "U-Boot Config" | |
64 | * [1] 0x00780000-0x00800000 : "U-Boot" (read-only) | |
65 | ***************************************************************************/ | |
66 | static struct mtd_partition qnap_ts409_partitions[] = { | |
67 | { | |
68 | .name = "U-Boot", | |
69 | .size = 0x00080000, | |
70 | .offset = 0x00780000, | |
71 | .mask_flags = MTD_WRITEABLE, | |
72 | }, { | |
73 | .name = "Kernel", | |
74 | .size = 0x00200000, | |
75 | .offset = 0, | |
76 | }, { | |
77 | .name = "RootFS1", | |
78 | .size = 0x00400000, | |
79 | .offset = 0x00200000, | |
80 | }, { | |
81 | .name = "RootFS2", | |
82 | .size = 0x00100000, | |
83 | .offset = 0x00600000, | |
84 | }, { | |
85 | .name = "U-Boot Config", | |
86 | .size = 0x00020000, | |
87 | .offset = 0x00760000, | |
88 | }, { | |
89 | .name = "NAS Config", | |
90 | .size = 0x00060000, | |
91 | .offset = 0x00700000, | |
92 | .mask_flags = MTD_WRITEABLE, | |
93 | }, | |
94 | }; | |
95 | ||
96 | static struct physmap_flash_data qnap_ts409_nor_flash_data = { | |
97 | .width = 1, | |
98 | .parts = qnap_ts409_partitions, | |
99 | .nr_parts = ARRAY_SIZE(qnap_ts409_partitions) | |
100 | }; | |
101 | ||
102 | static struct resource qnap_ts409_nor_flash_resource = { | |
103 | .flags = IORESOURCE_MEM, | |
104 | .start = QNAP_TS409_NOR_BOOT_BASE, | |
105 | .end = QNAP_TS409_NOR_BOOT_BASE + QNAP_TS409_NOR_BOOT_SIZE - 1, | |
106 | }; | |
107 | ||
108 | static struct platform_device qnap_ts409_nor_flash = { | |
109 | .name = "physmap-flash", | |
110 | .id = 0, | |
111 | .dev = { .platform_data = &qnap_ts409_nor_flash_data, }, | |
112 | .num_resources = 1, | |
113 | .resource = &qnap_ts409_nor_flash_resource, | |
114 | }; | |
115 | ||
116 | /***************************************************************************** | |
117 | * PCI | |
118 | ****************************************************************************/ | |
119 | ||
120 | static int __init qnap_ts409_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin) | |
121 | { | |
122 | int irq; | |
123 | ||
124 | /* | |
125 | * Check for devices with hard-wired IRQs. | |
126 | */ | |
127 | irq = orion5x_pci_map_irq(dev, slot, pin); | |
128 | if (irq != -1) | |
129 | return irq; | |
130 | ||
131 | /* | |
132 | * PCI isn't used on the TS-409 | |
133 | */ | |
134 | return -1; | |
135 | } | |
136 | ||
137 | static struct hw_pci qnap_ts409_pci __initdata = { | |
138 | .nr_controllers = 2, | |
139 | .swizzle = pci_std_swizzle, | |
140 | .setup = orion5x_pci_sys_setup, | |
141 | .scan = orion5x_pci_sys_scan_bus, | |
142 | .map_irq = qnap_ts409_pci_map_irq, | |
143 | }; | |
144 | ||
145 | static int __init qnap_ts409_pci_init(void) | |
146 | { | |
147 | if (machine_is_ts409()) | |
148 | pci_common_init(&qnap_ts409_pci); | |
149 | ||
150 | return 0; | |
151 | } | |
152 | ||
153 | subsys_initcall(qnap_ts409_pci_init); | |
154 | ||
47e9cffd SB |
155 | /***************************************************************************** |
156 | * RTC S35390A on I2C bus | |
157 | ****************************************************************************/ | |
158 | ||
159 | #define TS409_RTC_GPIO 10 | |
160 | ||
161 | static struct i2c_board_info __initdata qnap_ts409_i2c_rtc = { | |
162 | I2C_BOARD_INFO("s35390a", 0x30), | |
163 | }; | |
164 | ||
165 | /**************************************************************************** | |
166 | * GPIO Attached Keys | |
167 | * Power button is attached to the PIC microcontroller | |
168 | ****************************************************************************/ | |
169 | ||
170 | #define QNAP_TS409_GPIO_KEY_MEDIA 15 | |
171 | ||
172 | static struct gpio_keys_button qnap_ts409_buttons[] = { | |
173 | { | |
174 | .code = KEY_RESTART, | |
175 | .gpio = QNAP_TS409_GPIO_KEY_MEDIA, | |
176 | .desc = "USB Copy Button", | |
177 | .active_low = 1, | |
178 | }, | |
179 | }; | |
180 | ||
181 | static struct gpio_keys_platform_data qnap_ts409_button_data = { | |
182 | .buttons = qnap_ts409_buttons, | |
183 | .nbuttons = ARRAY_SIZE(qnap_ts409_buttons), | |
184 | }; | |
185 | ||
186 | static struct platform_device qnap_ts409_button_device = { | |
187 | .name = "gpio-keys", | |
188 | .id = -1, | |
189 | .num_resources = 0, | |
190 | .dev = { | |
191 | .platform_data = &qnap_ts409_button_data, | |
192 | }, | |
193 | }; | |
194 | ||
195 | /***************************************************************************** | |
196 | * General Setup | |
197 | ****************************************************************************/ | |
198 | static struct orion5x_mpp_mode ts409_mpp_modes[] __initdata = { | |
199 | { 0, MPP_UNUSED }, | |
200 | { 1, MPP_UNUSED }, | |
201 | { 2, MPP_UNUSED }, | |
202 | { 3, MPP_UNUSED }, | |
203 | { 4, MPP_GPIO }, /* HDD 1 status */ | |
204 | { 5, MPP_GPIO }, /* HDD 2 status */ | |
205 | { 6, MPP_GPIO }, /* HDD 3 status */ | |
206 | { 7, MPP_GPIO }, /* HDD 4 status */ | |
207 | { 8, MPP_UNUSED }, | |
208 | { 9, MPP_UNUSED }, | |
209 | { 10, MPP_GPIO }, /* RTC int */ | |
210 | { 11, MPP_UNUSED }, | |
211 | { 12, MPP_UNUSED }, | |
212 | { 13, MPP_UNUSED }, | |
213 | { 14, MPP_GPIO }, /* SW_RST */ | |
214 | { 15, MPP_GPIO }, /* USB copy button */ | |
215 | { 16, MPP_UART }, /* UART1 RXD */ | |
216 | { 17, MPP_UART }, /* UART1 TXD */ | |
217 | { 18, MPP_UNUSED }, | |
218 | { 19, MPP_UNUSED }, | |
219 | { -1 }, | |
220 | }; | |
221 | ||
47e9cffd SB |
222 | static void __init qnap_ts409_init(void) |
223 | { | |
224 | /* | |
225 | * Setup basic Orion functions. Need to be called early. | |
226 | */ | |
227 | orion5x_init(); | |
228 | ||
229 | orion5x_mpp_conf(ts409_mpp_modes); | |
230 | ||
231 | /* | |
232 | * Configure peripherals. | |
233 | */ | |
234 | orion5x_ehci0_init(); | |
530c854a SB |
235 | qnap_tsx09_find_mac_addr(QNAP_TS409_NOR_BOOT_BASE + |
236 | qnap_ts409_partitions[5].offset, | |
237 | qnap_ts409_partitions[5].size); | |
238 | orion5x_eth_init(&qnap_tsx09_eth_data); | |
47e9cffd SB |
239 | orion5x_i2c_init(); |
240 | orion5x_uart0_init(); | |
241 | ||
242 | orion5x_setup_dev_boot_win(QNAP_TS409_NOR_BOOT_BASE, | |
243 | QNAP_TS409_NOR_BOOT_SIZE); | |
244 | platform_device_register(&qnap_ts409_nor_flash); | |
245 | ||
246 | platform_device_register(&qnap_ts409_button_device); | |
247 | ||
248 | /* Get RTC IRQ and register the chip */ | |
249 | if (gpio_request(TS409_RTC_GPIO, "rtc") == 0) { | |
250 | if (gpio_direction_input(TS409_RTC_GPIO) == 0) | |
251 | qnap_ts409_i2c_rtc.irq = gpio_to_irq(TS409_RTC_GPIO); | |
252 | else | |
253 | gpio_free(TS409_RTC_GPIO); | |
254 | } | |
255 | if (qnap_ts409_i2c_rtc.irq == 0) | |
256 | pr_warning("qnap_ts409_init: failed to get RTC IRQ\n"); | |
257 | i2c_register_board_info(0, &qnap_ts409_i2c_rtc, 1); | |
258 | ||
530c854a SB |
259 | /* register tsx09 specific power-off method */ |
260 | pm_power_off = qnap_tsx09_power_off; | |
47e9cffd SB |
261 | } |
262 | ||
263 | MACHINE_START(TS409, "QNAP TS-409") | |
264 | /* Maintainer: Sylver Bruneau <sylver.bruneau@gmail.com> */ | |
265 | .phys_io = ORION5X_REGS_PHYS_BASE, | |
266 | .io_pg_offst = ((ORION5X_REGS_VIRT_BASE) >> 18) & 0xFFFC, | |
267 | .boot_params = 0x00000100, | |
268 | .init_machine = qnap_ts409_init, | |
269 | .map_io = orion5x_map_io, | |
270 | .init_irq = orion5x_init_irq, | |
271 | .timer = &orion5x_timer, | |
272 | .fixup = tag_fixup_mem32, | |
273 | MACHINE_END |