Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * QNAP TS-409 Board Setup
0004  *
0005  * Maintainer: Sylver Bruneau <sylver.bruneau@gmail.com>
0006  *
0007  * Copyright (C) 2008  Sylver Bruneau <sylver.bruneau@gmail.com>
0008  * Copyright (C) 2008  Martin Michlmayr <tbm@cyrius.com>
0009  */
0010 #include <linux/gpio.h>
0011 #include <linux/kernel.h>
0012 #include <linux/init.h>
0013 #include <linux/platform_device.h>
0014 #include <linux/pci.h>
0015 #include <linux/irq.h>
0016 #include <linux/mtd/physmap.h>
0017 #include <linux/mv643xx_eth.h>
0018 #include <linux/leds.h>
0019 #include <linux/gpio_keys.h>
0020 #include <linux/input.h>
0021 #include <linux/i2c.h>
0022 #include <linux/serial_reg.h>
0023 #include <asm/mach-types.h>
0024 #include <asm/mach/arch.h>
0025 #include <asm/mach/pci.h>
0026 #include "common.h"
0027 #include "mpp.h"
0028 #include "orion5x.h"
0029 #include "tsx09-common.h"
0030 
0031 /*****************************************************************************
0032  * QNAP TS-409 Info
0033  ****************************************************************************/
0034 
0035 /*
0036  * QNAP TS-409 hardware :
0037  * - Marvell 88F5281-D0
0038  * - Marvell 88SX7042 SATA controller (PCIe)
0039  * - Marvell 88E1118 Gigabit Ethernet PHY
0040  * - RTC S35390A (@0x30) on I2C bus
0041  * - 8MB NOR flash
0042  * - 256MB of DDR-2 RAM
0043  */
0044 
0045 /*
0046  * 8MB NOR flash Device bus boot chip select
0047  */
0048 
0049 #define QNAP_TS409_NOR_BOOT_BASE 0xff800000
0050 #define QNAP_TS409_NOR_BOOT_SIZE SZ_8M
0051 
0052 /****************************************************************************
0053  * 8MiB NOR flash. The struct mtd_partition is not in the same order as the
0054  *     partitions on the device because we want to keep compatibility with
0055  *     existing QNAP firmware.
0056  *
0057  * Layout as used by QNAP:
0058  *  [2] 0x00000000-0x00200000 : "Kernel"
0059  *  [3] 0x00200000-0x00600000 : "RootFS1"
0060  *  [4] 0x00600000-0x00700000 : "RootFS2"
0061  *  [6] 0x00700000-0x00760000 : "NAS Config" (read-only)
0062  *  [5] 0x00760000-0x00780000 : "U-Boot Config"
0063  *  [1] 0x00780000-0x00800000 : "U-Boot" (read-only)
0064  ***************************************************************************/
0065 static struct mtd_partition qnap_ts409_partitions[] = {
0066     {
0067         .name       = "U-Boot",
0068         .size       = 0x00080000,
0069         .offset     = 0x00780000,
0070         .mask_flags = MTD_WRITEABLE,
0071     }, {
0072         .name       = "Kernel",
0073         .size       = 0x00200000,
0074         .offset     = 0,
0075     }, {
0076         .name       = "RootFS1",
0077         .size       = 0x00400000,
0078         .offset     = 0x00200000,
0079     }, {
0080         .name       = "RootFS2",
0081         .size       = 0x00100000,
0082         .offset     = 0x00600000,
0083     }, {
0084         .name       = "U-Boot Config",
0085         .size       = 0x00020000,
0086         .offset     = 0x00760000,
0087     }, {
0088         .name       = "NAS Config",
0089         .size       = 0x00060000,
0090         .offset     = 0x00700000,
0091         .mask_flags = MTD_WRITEABLE,
0092     },
0093 };
0094 
0095 static struct physmap_flash_data qnap_ts409_nor_flash_data = {
0096     .width      = 1,
0097     .parts      = qnap_ts409_partitions,
0098     .nr_parts   = ARRAY_SIZE(qnap_ts409_partitions)
0099 };
0100 
0101 static struct resource qnap_ts409_nor_flash_resource = {
0102     .flags  = IORESOURCE_MEM,
0103     .start  = QNAP_TS409_NOR_BOOT_BASE,
0104     .end    = QNAP_TS409_NOR_BOOT_BASE + QNAP_TS409_NOR_BOOT_SIZE - 1,
0105 };
0106 
0107 static struct platform_device qnap_ts409_nor_flash = {
0108     .name       = "physmap-flash",
0109     .id     = 0,
0110     .dev        = { .platform_data = &qnap_ts409_nor_flash_data, },
0111     .num_resources  = 1,
0112     .resource   = &qnap_ts409_nor_flash_resource,
0113 };
0114 
0115 /*****************************************************************************
0116  * PCI
0117  ****************************************************************************/
0118 
0119 static int __init qnap_ts409_pci_map_irq(const struct pci_dev *dev, u8 slot,
0120     u8 pin)
0121 {
0122     int irq;
0123 
0124     /*
0125      * Check for devices with hard-wired IRQs.
0126      */
0127     irq = orion5x_pci_map_irq(dev, slot, pin);
0128     if (irq != -1)
0129         return irq;
0130 
0131     /*
0132      * PCI isn't used on the TS-409
0133      */
0134     return -1;
0135 }
0136 
0137 static struct hw_pci qnap_ts409_pci __initdata = {
0138     .nr_controllers = 2,
0139     .setup      = orion5x_pci_sys_setup,
0140     .scan       = orion5x_pci_sys_scan_bus,
0141     .map_irq    = qnap_ts409_pci_map_irq,
0142 };
0143 
0144 static int __init qnap_ts409_pci_init(void)
0145 {
0146     if (machine_is_ts409())
0147         pci_common_init(&qnap_ts409_pci);
0148 
0149     return 0;
0150 }
0151 
0152 subsys_initcall(qnap_ts409_pci_init);
0153 
0154 /*****************************************************************************
0155  * RTC S35390A on I2C bus
0156  ****************************************************************************/
0157 
0158 #define TS409_RTC_GPIO  10
0159 
0160 static struct i2c_board_info __initdata qnap_ts409_i2c_rtc = {
0161     I2C_BOARD_INFO("s35390a", 0x30),
0162 };
0163 
0164 /*****************************************************************************
0165  * LEDs attached to GPIO
0166  ****************************************************************************/
0167 
0168 static struct gpio_led ts409_led_pins[] = {
0169     {
0170         .name       = "ts409:red:sata1",
0171         .gpio       = 4,
0172         .active_low = 1,
0173     }, {
0174         .name       = "ts409:red:sata2",
0175         .gpio       = 5,
0176         .active_low = 1,
0177     }, {
0178         .name       = "ts409:red:sata3",
0179         .gpio       = 6,
0180         .active_low = 1,
0181     }, {
0182         .name       = "ts409:red:sata4",
0183         .gpio       = 7,
0184         .active_low = 1,
0185     },
0186 };
0187 
0188 static struct gpio_led_platform_data ts409_led_data = {
0189     .leds       = ts409_led_pins,
0190     .num_leds   = ARRAY_SIZE(ts409_led_pins),
0191 };
0192 
0193 static struct platform_device ts409_leds = {
0194     .name   = "leds-gpio",
0195     .id = -1,
0196     .dev    = {
0197         .platform_data  = &ts409_led_data,
0198     },
0199 };
0200 
0201 /****************************************************************************
0202  * GPIO Attached Keys
0203  *     Power button is attached to the PIC microcontroller
0204  ****************************************************************************/
0205 
0206 #define QNAP_TS409_GPIO_KEY_RESET   14
0207 #define QNAP_TS409_GPIO_KEY_MEDIA   15
0208 
0209 static struct gpio_keys_button qnap_ts409_buttons[] = {
0210     {
0211         .code       = KEY_RESTART,
0212         .gpio       = QNAP_TS409_GPIO_KEY_RESET,
0213         .desc       = "Reset Button",
0214         .active_low = 1,
0215     }, {
0216         .code       = KEY_COPY,
0217         .gpio       = QNAP_TS409_GPIO_KEY_MEDIA,
0218         .desc       = "USB Copy Button",
0219         .active_low = 1,
0220     },
0221 };
0222 
0223 static struct gpio_keys_platform_data qnap_ts409_button_data = {
0224     .buttons    = qnap_ts409_buttons,
0225     .nbuttons   = ARRAY_SIZE(qnap_ts409_buttons),
0226 };
0227 
0228 static struct platform_device qnap_ts409_button_device = {
0229     .name       = "gpio-keys",
0230     .id     = -1,
0231     .num_resources  = 0,
0232     .dev        = {
0233         .platform_data  = &qnap_ts409_button_data,
0234     },
0235 };
0236 
0237 /*****************************************************************************
0238  * General Setup
0239  ****************************************************************************/
0240 static unsigned int ts409_mpp_modes[] __initdata = {
0241     MPP0_UNUSED,
0242     MPP1_UNUSED,
0243     MPP2_UNUSED,
0244     MPP3_UNUSED,
0245     MPP4_GPIO,      /* HDD 1 status */
0246     MPP5_GPIO,      /* HDD 2 status */
0247     MPP6_GPIO,      /* HDD 3 status */
0248     MPP7_GPIO,      /* HDD 4 status */
0249     MPP8_UNUSED,
0250     MPP9_UNUSED,
0251     MPP10_GPIO,     /* RTC int */
0252     MPP11_UNUSED,
0253     MPP12_UNUSED,
0254     MPP13_UNUSED,
0255     MPP14_GPIO,     /* SW_RST */
0256     MPP15_GPIO,     /* USB copy button */
0257     MPP16_UART,     /* UART1 RXD */
0258     MPP17_UART,     /* UART1 TXD */
0259     MPP18_UNUSED,
0260     MPP19_UNUSED,
0261     0,
0262 };
0263 
0264 static void __init qnap_ts409_init(void)
0265 {
0266     /*
0267      * Setup basic Orion functions. Need to be called early.
0268      */
0269     orion5x_init();
0270 
0271     orion5x_mpp_conf(ts409_mpp_modes);
0272 
0273     /*
0274      * Configure peripherals.
0275      */
0276     mvebu_mbus_add_window_by_id(ORION_MBUS_DEVBUS_BOOT_TARGET,
0277                     ORION_MBUS_DEVBUS_BOOT_ATTR,
0278                     QNAP_TS409_NOR_BOOT_BASE,
0279                     QNAP_TS409_NOR_BOOT_SIZE);
0280     platform_device_register(&qnap_ts409_nor_flash);
0281 
0282     orion5x_ehci0_init();
0283     qnap_tsx09_find_mac_addr(QNAP_TS409_NOR_BOOT_BASE +
0284                  qnap_ts409_partitions[5].offset,
0285                  qnap_ts409_partitions[5].size);
0286     orion5x_eth_init(&qnap_tsx09_eth_data);
0287     orion5x_i2c_init();
0288     orion5x_uart0_init();
0289     orion5x_uart1_init();
0290 
0291     platform_device_register(&qnap_ts409_button_device);
0292 
0293     /* Get RTC IRQ and register the chip */
0294     if (gpio_request(TS409_RTC_GPIO, "rtc") == 0) {
0295         if (gpio_direction_input(TS409_RTC_GPIO) == 0)
0296             qnap_ts409_i2c_rtc.irq = gpio_to_irq(TS409_RTC_GPIO);
0297         else
0298             gpio_free(TS409_RTC_GPIO);
0299     }
0300     if (qnap_ts409_i2c_rtc.irq == 0)
0301         pr_warn("qnap_ts409_init: failed to get RTC IRQ\n");
0302     i2c_register_board_info(0, &qnap_ts409_i2c_rtc, 1);
0303     platform_device_register(&ts409_leds);
0304 
0305     /* register tsx09 specific power-off method */
0306     pm_power_off = qnap_tsx09_power_off;
0307 }
0308 
0309 MACHINE_START(TS409, "QNAP TS-409")
0310     /* Maintainer:  Sylver Bruneau <sylver.bruneau@gmail.com> */
0311     .atag_offset    = 0x100,
0312     .nr_irqs    = ORION5X_NR_IRQS,
0313     .init_machine   = qnap_ts409_init,
0314     .map_io     = orion5x_map_io,
0315     .init_early = orion5x_init_early,
0316     .init_irq   = orion5x_init_irq,
0317     .init_time  = orion5x_timer_init,
0318     .fixup      = tag_fixup_mem32,
0319     .restart    = orion5x_restart,
0320 MACHINE_END