1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * QNAP TS-109/TS-209 Board Setup
5 * Maintainer: Byron Bradley <byron.bbradley@gmail.com>
7 #include <linux/gpio.h>
8 #include <linux/kernel.h>
9 #include <linux/init.h>
10 #include <linux/platform_device.h>
11 #include <linux/pci.h>
12 #include <linux/irq.h>
13 #include <linux/mtd/physmap.h>
14 #include <linux/mtd/rawnand.h>
15 #include <linux/mv643xx_eth.h>
16 #include <linux/gpio_keys.h>
17 #include <linux/input.h>
18 #include <linux/i2c.h>
19 #include <linux/serial_reg.h>
20 #include <linux/ata_platform.h>
21 #include <asm/mach-types.h>
22 #include <asm/mach/arch.h>
23 #include <asm/mach/pci.h>
27 #include "tsx09-common.h"
29 #define QNAP_TS209_NOR_BOOT_BASE 0xf4000000
30 #define QNAP_TS209_NOR_BOOT_SIZE SZ_8M
32 /****************************************************************************
33 * 8MiB NOR flash. The struct mtd_partition is not in the same order as the
34 * partitions on the device because we want to keep compatibility with
35 * existing QNAP firmware.
37 * Layout as used by QNAP:
38 * [2] 0x00000000-0x00200000 : "Kernel"
39 * [3] 0x00200000-0x00600000 : "RootFS1"
40 * [4] 0x00600000-0x00700000 : "RootFS2"
41 * [6] 0x00700000-0x00760000 : "NAS Config" (read-only)
42 * [5] 0x00760000-0x00780000 : "U-Boot Config"
43 * [1] 0x00780000-0x00800000 : "U-Boot" (read-only)
44 ***************************************************************************/
45 static struct mtd_partition qnap_ts209_partitions
[] = {
50 .mask_flags
= MTD_WRITEABLE
,
64 .name
= "U-Boot Config",
71 .mask_flags
= MTD_WRITEABLE
,
75 static struct physmap_flash_data qnap_ts209_nor_flash_data
= {
77 .parts
= qnap_ts209_partitions
,
78 .nr_parts
= ARRAY_SIZE(qnap_ts209_partitions
)
81 static struct resource qnap_ts209_nor_flash_resource
= {
82 .flags
= IORESOURCE_MEM
,
83 .start
= QNAP_TS209_NOR_BOOT_BASE
,
84 .end
= QNAP_TS209_NOR_BOOT_BASE
+ QNAP_TS209_NOR_BOOT_SIZE
- 1,
87 static struct platform_device qnap_ts209_nor_flash
= {
88 .name
= "physmap-flash",
91 .platform_data
= &qnap_ts209_nor_flash_data
,
93 .resource
= &qnap_ts209_nor_flash_resource
,
97 /*****************************************************************************
99 ****************************************************************************/
101 #define QNAP_TS209_PCI_SLOT0_OFFS 7
102 #define QNAP_TS209_PCI_SLOT0_IRQ_PIN 6
103 #define QNAP_TS209_PCI_SLOT1_IRQ_PIN 7
105 static void __init
qnap_ts209_pci_preinit(void)
110 * Configure PCI GPIO IRQ pins
112 pin
= QNAP_TS209_PCI_SLOT0_IRQ_PIN
;
113 if (gpio_request(pin
, "PCI Int1") == 0) {
114 if (gpio_direction_input(pin
) == 0) {
115 irq_set_irq_type(gpio_to_irq(pin
), IRQ_TYPE_LEVEL_LOW
);
117 printk(KERN_ERR
"qnap_ts209_pci_preinit failed to "
118 "set_irq_type pin %d\n", pin
);
122 printk(KERN_ERR
"qnap_ts209_pci_preinit failed to gpio_request "
126 pin
= QNAP_TS209_PCI_SLOT1_IRQ_PIN
;
127 if (gpio_request(pin
, "PCI Int2") == 0) {
128 if (gpio_direction_input(pin
) == 0) {
129 irq_set_irq_type(gpio_to_irq(pin
), IRQ_TYPE_LEVEL_LOW
);
131 printk(KERN_ERR
"qnap_ts209_pci_preinit failed "
132 "to set_irq_type pin %d\n", pin
);
136 printk(KERN_ERR
"qnap_ts209_pci_preinit failed to gpio_request "
141 static int __init
qnap_ts209_pci_map_irq(const struct pci_dev
*dev
, u8 slot
,
147 * Check for devices with hard-wired IRQs.
149 irq
= orion5x_pci_map_irq(dev
, slot
, pin
);
154 * PCI IRQs are connected via GPIOs.
156 switch (slot
- QNAP_TS209_PCI_SLOT0_OFFS
) {
158 return gpio_to_irq(QNAP_TS209_PCI_SLOT0_IRQ_PIN
);
160 return gpio_to_irq(QNAP_TS209_PCI_SLOT1_IRQ_PIN
);
166 static struct hw_pci qnap_ts209_pci __initdata
= {
168 .preinit
= qnap_ts209_pci_preinit
,
169 .setup
= orion5x_pci_sys_setup
,
170 .scan
= orion5x_pci_sys_scan_bus
,
171 .map_irq
= qnap_ts209_pci_map_irq
,
174 static int __init
qnap_ts209_pci_init(void)
176 if (machine_is_ts209())
177 pci_common_init(&qnap_ts209_pci
);
182 subsys_initcall(qnap_ts209_pci_init
);
184 /*****************************************************************************
185 * RTC S35390A on I2C bus
186 ****************************************************************************/
188 #define TS209_RTC_GPIO 3
190 static struct i2c_board_info __initdata qnap_ts209_i2c_rtc
= {
191 I2C_BOARD_INFO("s35390a", 0x30),
195 /****************************************************************************
197 * Power button is attached to the PIC microcontroller
198 ****************************************************************************/
200 #define QNAP_TS209_GPIO_KEY_MEDIA 1
201 #define QNAP_TS209_GPIO_KEY_RESET 2
203 static struct gpio_keys_button qnap_ts209_buttons
[] = {
206 .gpio
= QNAP_TS209_GPIO_KEY_MEDIA
,
207 .desc
= "USB Copy Button",
211 .gpio
= QNAP_TS209_GPIO_KEY_RESET
,
212 .desc
= "Reset Button",
217 static struct gpio_keys_platform_data qnap_ts209_button_data
= {
218 .buttons
= qnap_ts209_buttons
,
219 .nbuttons
= ARRAY_SIZE(qnap_ts209_buttons
),
222 static struct platform_device qnap_ts209_button_device
= {
227 .platform_data
= &qnap_ts209_button_data
,
231 /*****************************************************************************
233 ****************************************************************************/
234 static struct mv_sata_platform_data qnap_ts209_sata_data
= {
238 /*****************************************************************************
241 ****************************************************************************/
242 static unsigned int ts209_mpp_modes
[] __initdata
= {
244 MPP1_GPIO
, /* USB copy button */
245 MPP2_GPIO
, /* Load defaults button */
246 MPP3_GPIO
, /* GPIO RTC */
249 MPP6_GPIO
, /* PCI Int A */
250 MPP7_GPIO
, /* PCI Int B */
255 MPP12_SATA_LED
, /* SATA 0 presence */
256 MPP13_SATA_LED
, /* SATA 1 presence */
257 MPP14_SATA_LED
, /* SATA 0 active */
258 MPP15_SATA_LED
, /* SATA 1 active */
259 MPP16_UART
, /* UART1 RXD */
260 MPP17_UART
, /* UART1 TXD */
261 MPP18_GPIO
, /* SW_RST */
266 static void __init
qnap_ts209_init(void)
269 * Setup basic Orion functions. Need to be called early.
273 orion5x_mpp_conf(ts209_mpp_modes
);
276 * MPP[20] PCI clock 0
277 * MPP[21] PCI clock 1
278 * MPP[22] USB 0 over current
279 * MPP[23-25] Reserved
283 * Configure peripherals.
285 mvebu_mbus_add_window_by_id(ORION_MBUS_DEVBUS_BOOT_TARGET
,
286 ORION_MBUS_DEVBUS_BOOT_ATTR
,
287 QNAP_TS209_NOR_BOOT_BASE
,
288 QNAP_TS209_NOR_BOOT_SIZE
);
289 platform_device_register(&qnap_ts209_nor_flash
);
291 orion5x_ehci0_init();
292 orion5x_ehci1_init();
293 qnap_tsx09_find_mac_addr(QNAP_TS209_NOR_BOOT_BASE
+
294 qnap_ts209_partitions
[5].offset
,
295 qnap_ts209_partitions
[5].size
);
296 orion5x_eth_init(&qnap_tsx09_eth_data
);
298 orion5x_sata_init(&qnap_ts209_sata_data
);
299 orion5x_uart0_init();
300 orion5x_uart1_init();
303 platform_device_register(&qnap_ts209_button_device
);
305 /* Get RTC IRQ and register the chip */
306 if (gpio_request(TS209_RTC_GPIO
, "rtc") == 0) {
307 if (gpio_direction_input(TS209_RTC_GPIO
) == 0)
308 qnap_ts209_i2c_rtc
.irq
= gpio_to_irq(TS209_RTC_GPIO
);
310 gpio_free(TS209_RTC_GPIO
);
312 if (qnap_ts209_i2c_rtc
.irq
== 0)
313 pr_warn("qnap_ts209_init: failed to get RTC IRQ\n");
314 i2c_register_board_info(0, &qnap_ts209_i2c_rtc
, 1);
316 /* register tsx09 specific power-off method */
317 pm_power_off
= qnap_tsx09_power_off
;
320 MACHINE_START(TS209
, "QNAP TS-109/TS-209")
321 /* Maintainer: Byron Bradley <byron.bbradley@gmail.com> */
322 .atag_offset
= 0x100,
323 .nr_irqs
= ORION5X_NR_IRQS
,
324 .init_machine
= qnap_ts209_init
,
325 .map_io
= orion5x_map_io
,
326 .init_early
= orion5x_init_early
,
327 .init_irq
= orion5x_init_irq
,
328 .init_time
= orion5x_timer_init
,
329 .fixup
= tag_fixup_mem32
,
330 .restart
= orion5x_restart
,