0001
0002
0003
0004
0005
0006
0007 #include <linux/gpio.h>
0008 #include <linux/kernel.h>
0009 #include <linux/init.h>
0010 #include <linux/platform_device.h>
0011 #include <linux/pci.h>
0012 #include <linux/irq.h>
0013 #include <linux/mtd/physmap.h>
0014 #include <linux/mtd/rawnand.h>
0015 #include <linux/mv643xx_eth.h>
0016 #include <linux/gpio_keys.h>
0017 #include <linux/input.h>
0018 #include <linux/i2c.h>
0019 #include <linux/serial_reg.h>
0020 #include <linux/ata_platform.h>
0021 #include <asm/mach-types.h>
0022 #include <asm/mach/arch.h>
0023 #include <asm/mach/pci.h>
0024 #include "common.h"
0025 #include "mpp.h"
0026 #include "orion5x.h"
0027 #include "tsx09-common.h"
0028
0029 #define QNAP_TS209_NOR_BOOT_BASE 0xf4000000
0030 #define QNAP_TS209_NOR_BOOT_SIZE SZ_8M
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045 static struct mtd_partition qnap_ts209_partitions[] = {
0046 {
0047 .name = "U-Boot",
0048 .size = 0x00080000,
0049 .offset = 0x00780000,
0050 .mask_flags = MTD_WRITEABLE,
0051 }, {
0052 .name = "Kernel",
0053 .size = 0x00200000,
0054 .offset = 0,
0055 }, {
0056 .name = "RootFS1",
0057 .size = 0x00400000,
0058 .offset = 0x00200000,
0059 }, {
0060 .name = "RootFS2",
0061 .size = 0x00100000,
0062 .offset = 0x00600000,
0063 }, {
0064 .name = "U-Boot Config",
0065 .size = 0x00020000,
0066 .offset = 0x00760000,
0067 }, {
0068 .name = "NAS Config",
0069 .size = 0x00060000,
0070 .offset = 0x00700000,
0071 .mask_flags = MTD_WRITEABLE,
0072 },
0073 };
0074
0075 static struct physmap_flash_data qnap_ts209_nor_flash_data = {
0076 .width = 1,
0077 .parts = qnap_ts209_partitions,
0078 .nr_parts = ARRAY_SIZE(qnap_ts209_partitions)
0079 };
0080
0081 static struct resource qnap_ts209_nor_flash_resource = {
0082 .flags = IORESOURCE_MEM,
0083 .start = QNAP_TS209_NOR_BOOT_BASE,
0084 .end = QNAP_TS209_NOR_BOOT_BASE + QNAP_TS209_NOR_BOOT_SIZE - 1,
0085 };
0086
0087 static struct platform_device qnap_ts209_nor_flash = {
0088 .name = "physmap-flash",
0089 .id = 0,
0090 .dev = {
0091 .platform_data = &qnap_ts209_nor_flash_data,
0092 },
0093 .resource = &qnap_ts209_nor_flash_resource,
0094 .num_resources = 1,
0095 };
0096
0097
0098
0099
0100
0101 #define QNAP_TS209_PCI_SLOT0_OFFS 7
0102 #define QNAP_TS209_PCI_SLOT0_IRQ_PIN 6
0103 #define QNAP_TS209_PCI_SLOT1_IRQ_PIN 7
0104
0105 static void __init qnap_ts209_pci_preinit(void)
0106 {
0107 int pin;
0108
0109
0110
0111
0112 pin = QNAP_TS209_PCI_SLOT0_IRQ_PIN;
0113 if (gpio_request(pin, "PCI Int1") == 0) {
0114 if (gpio_direction_input(pin) == 0) {
0115 irq_set_irq_type(gpio_to_irq(pin), IRQ_TYPE_LEVEL_LOW);
0116 } else {
0117 printk(KERN_ERR "qnap_ts209_pci_preinit failed to "
0118 "set_irq_type pin %d\n", pin);
0119 gpio_free(pin);
0120 }
0121 } else {
0122 printk(KERN_ERR "qnap_ts209_pci_preinit failed to gpio_request "
0123 "%d\n", pin);
0124 }
0125
0126 pin = QNAP_TS209_PCI_SLOT1_IRQ_PIN;
0127 if (gpio_request(pin, "PCI Int2") == 0) {
0128 if (gpio_direction_input(pin) == 0) {
0129 irq_set_irq_type(gpio_to_irq(pin), IRQ_TYPE_LEVEL_LOW);
0130 } else {
0131 printk(KERN_ERR "qnap_ts209_pci_preinit failed "
0132 "to set_irq_type pin %d\n", pin);
0133 gpio_free(pin);
0134 }
0135 } else {
0136 printk(KERN_ERR "qnap_ts209_pci_preinit failed to gpio_request "
0137 "%d\n", pin);
0138 }
0139 }
0140
0141 static int __init qnap_ts209_pci_map_irq(const struct pci_dev *dev, u8 slot,
0142 u8 pin)
0143 {
0144 int irq;
0145
0146
0147
0148
0149 irq = orion5x_pci_map_irq(dev, slot, pin);
0150 if (irq != -1)
0151 return irq;
0152
0153
0154
0155
0156 switch (slot - QNAP_TS209_PCI_SLOT0_OFFS) {
0157 case 0:
0158 return gpio_to_irq(QNAP_TS209_PCI_SLOT0_IRQ_PIN);
0159 case 1:
0160 return gpio_to_irq(QNAP_TS209_PCI_SLOT1_IRQ_PIN);
0161 default:
0162 return -1;
0163 }
0164 }
0165
0166 static struct hw_pci qnap_ts209_pci __initdata = {
0167 .nr_controllers = 2,
0168 .preinit = qnap_ts209_pci_preinit,
0169 .setup = orion5x_pci_sys_setup,
0170 .scan = orion5x_pci_sys_scan_bus,
0171 .map_irq = qnap_ts209_pci_map_irq,
0172 };
0173
0174 static int __init qnap_ts209_pci_init(void)
0175 {
0176 if (machine_is_ts209())
0177 pci_common_init(&qnap_ts209_pci);
0178
0179 return 0;
0180 }
0181
0182 subsys_initcall(qnap_ts209_pci_init);
0183
0184
0185
0186
0187
0188 #define TS209_RTC_GPIO 3
0189
0190 static struct i2c_board_info __initdata qnap_ts209_i2c_rtc = {
0191 I2C_BOARD_INFO("s35390a", 0x30),
0192 .irq = 0,
0193 };
0194
0195
0196
0197
0198
0199
0200 #define QNAP_TS209_GPIO_KEY_MEDIA 1
0201 #define QNAP_TS209_GPIO_KEY_RESET 2
0202
0203 static struct gpio_keys_button qnap_ts209_buttons[] = {
0204 {
0205 .code = KEY_COPY,
0206 .gpio = QNAP_TS209_GPIO_KEY_MEDIA,
0207 .desc = "USB Copy Button",
0208 .active_low = 1,
0209 }, {
0210 .code = KEY_RESTART,
0211 .gpio = QNAP_TS209_GPIO_KEY_RESET,
0212 .desc = "Reset Button",
0213 .active_low = 1,
0214 },
0215 };
0216
0217 static struct gpio_keys_platform_data qnap_ts209_button_data = {
0218 .buttons = qnap_ts209_buttons,
0219 .nbuttons = ARRAY_SIZE(qnap_ts209_buttons),
0220 };
0221
0222 static struct platform_device qnap_ts209_button_device = {
0223 .name = "gpio-keys",
0224 .id = -1,
0225 .num_resources = 0,
0226 .dev = {
0227 .platform_data = &qnap_ts209_button_data,
0228 },
0229 };
0230
0231
0232
0233
0234 static struct mv_sata_platform_data qnap_ts209_sata_data = {
0235 .n_ports = 2,
0236 };
0237
0238
0239
0240
0241
0242 static unsigned int ts209_mpp_modes[] __initdata = {
0243 MPP0_UNUSED,
0244 MPP1_GPIO,
0245 MPP2_GPIO,
0246 MPP3_GPIO,
0247 MPP4_UNUSED,
0248 MPP5_UNUSED,
0249 MPP6_GPIO,
0250 MPP7_GPIO,
0251 MPP8_UNUSED,
0252 MPP9_UNUSED,
0253 MPP10_UNUSED,
0254 MPP11_UNUSED,
0255 MPP12_SATA_LED,
0256 MPP13_SATA_LED,
0257 MPP14_SATA_LED,
0258 MPP15_SATA_LED,
0259 MPP16_UART,
0260 MPP17_UART,
0261 MPP18_GPIO,
0262 MPP19_UNUSED,
0263 0,
0264 };
0265
0266 static void __init qnap_ts209_init(void)
0267 {
0268
0269
0270
0271 orion5x_init();
0272
0273 orion5x_mpp_conf(ts209_mpp_modes);
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285 mvebu_mbus_add_window_by_id(ORION_MBUS_DEVBUS_BOOT_TARGET,
0286 ORION_MBUS_DEVBUS_BOOT_ATTR,
0287 QNAP_TS209_NOR_BOOT_BASE,
0288 QNAP_TS209_NOR_BOOT_SIZE);
0289 platform_device_register(&qnap_ts209_nor_flash);
0290
0291 orion5x_ehci0_init();
0292 orion5x_ehci1_init();
0293 qnap_tsx09_find_mac_addr(QNAP_TS209_NOR_BOOT_BASE +
0294 qnap_ts209_partitions[5].offset,
0295 qnap_ts209_partitions[5].size);
0296 orion5x_eth_init(&qnap_tsx09_eth_data);
0297 orion5x_i2c_init();
0298 orion5x_sata_init(&qnap_ts209_sata_data);
0299 orion5x_uart0_init();
0300 orion5x_uart1_init();
0301 orion5x_xor_init();
0302
0303 platform_device_register(&qnap_ts209_button_device);
0304
0305
0306 if (gpio_request(TS209_RTC_GPIO, "rtc") == 0) {
0307 if (gpio_direction_input(TS209_RTC_GPIO) == 0)
0308 qnap_ts209_i2c_rtc.irq = gpio_to_irq(TS209_RTC_GPIO);
0309 else
0310 gpio_free(TS209_RTC_GPIO);
0311 }
0312 if (qnap_ts209_i2c_rtc.irq == 0)
0313 pr_warn("qnap_ts209_init: failed to get RTC IRQ\n");
0314 i2c_register_board_info(0, &qnap_ts209_i2c_rtc, 1);
0315
0316
0317 pm_power_off = qnap_tsx09_power_off;
0318 }
0319
0320 MACHINE_START(TS209, "QNAP TS-109/TS-209")
0321
0322 .atag_offset = 0x100,
0323 .nr_irqs = ORION5X_NR_IRQS,
0324 .init_machine = qnap_ts209_init,
0325 .map_io = orion5x_map_io,
0326 .init_early = orion5x_init_early,
0327 .init_irq = orion5x_init_irq,
0328 .init_time = orion5x_timer_init,
0329 .fixup = tag_fixup_mem32,
0330 .restart = orion5x_restart,
0331 MACHINE_END