Path: blob/master/arch/arm/mach-orion5x/ts209-setup.c
10819 views
/*1* QNAP TS-109/TS-209 Board Setup2*3* Maintainer: Byron Bradley <[email protected]>4*5* This program is free software; you can redistribute it and/or6* modify it under the terms of the GNU General Public License7* as published by the Free Software Foundation; either version8* 2 of the License, or (at your option) any later version.9*/1011#include <linux/kernel.h>12#include <linux/init.h>13#include <linux/platform_device.h>14#include <linux/pci.h>15#include <linux/irq.h>16#include <linux/mtd/physmap.h>17#include <linux/mtd/nand.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 <linux/ata_platform.h>24#include <asm/mach-types.h>25#include <asm/gpio.h>26#include <asm/mach/arch.h>27#include <asm/mach/pci.h>28#include <mach/orion5x.h>29#include "common.h"30#include "mpp.h"31#include "tsx09-common.h"3233#define QNAP_TS209_NOR_BOOT_BASE 0xf400000034#define QNAP_TS209_NOR_BOOT_SIZE SZ_8M3536/****************************************************************************37* 8MiB NOR flash. The struct mtd_partition is not in the same order as the38* partitions on the device because we want to keep compatibility with39* existing QNAP firmware.40*41* Layout as used by QNAP:42* [2] 0x00000000-0x00200000 : "Kernel"43* [3] 0x00200000-0x00600000 : "RootFS1"44* [4] 0x00600000-0x00700000 : "RootFS2"45* [6] 0x00700000-0x00760000 : "NAS Config" (read-only)46* [5] 0x00760000-0x00780000 : "U-Boot Config"47* [1] 0x00780000-0x00800000 : "U-Boot" (read-only)48***************************************************************************/49static struct mtd_partition qnap_ts209_partitions[] = {50{51.name = "U-Boot",52.size = 0x00080000,53.offset = 0x00780000,54.mask_flags = MTD_WRITEABLE,55}, {56.name = "Kernel",57.size = 0x00200000,58.offset = 0,59}, {60.name = "RootFS1",61.size = 0x00400000,62.offset = 0x00200000,63}, {64.name = "RootFS2",65.size = 0x00100000,66.offset = 0x00600000,67}, {68.name = "U-Boot Config",69.size = 0x00020000,70.offset = 0x00760000,71}, {72.name = "NAS Config",73.size = 0x00060000,74.offset = 0x00700000,75.mask_flags = MTD_WRITEABLE,76},77};7879static struct physmap_flash_data qnap_ts209_nor_flash_data = {80.width = 1,81.parts = qnap_ts209_partitions,82.nr_parts = ARRAY_SIZE(qnap_ts209_partitions)83};8485static struct resource qnap_ts209_nor_flash_resource = {86.flags = IORESOURCE_MEM,87.start = QNAP_TS209_NOR_BOOT_BASE,88.end = QNAP_TS209_NOR_BOOT_BASE + QNAP_TS209_NOR_BOOT_SIZE - 1,89};9091static struct platform_device qnap_ts209_nor_flash = {92.name = "physmap-flash",93.id = 0,94.dev = {95.platform_data = &qnap_ts209_nor_flash_data,96},97.resource = &qnap_ts209_nor_flash_resource,98.num_resources = 1,99};100101/*****************************************************************************102* PCI103****************************************************************************/104105#define QNAP_TS209_PCI_SLOT0_OFFS 7106#define QNAP_TS209_PCI_SLOT0_IRQ_PIN 6107#define QNAP_TS209_PCI_SLOT1_IRQ_PIN 7108109void __init qnap_ts209_pci_preinit(void)110{111int pin;112113/*114* Configure PCI GPIO IRQ pins115*/116pin = QNAP_TS209_PCI_SLOT0_IRQ_PIN;117if (gpio_request(pin, "PCI Int1") == 0) {118if (gpio_direction_input(pin) == 0) {119irq_set_irq_type(gpio_to_irq(pin), IRQ_TYPE_LEVEL_LOW);120} else {121printk(KERN_ERR "qnap_ts209_pci_preinit failed to "122"set_irq_type pin %d\n", pin);123gpio_free(pin);124}125} else {126printk(KERN_ERR "qnap_ts209_pci_preinit failed to gpio_request "127"%d\n", pin);128}129130pin = QNAP_TS209_PCI_SLOT1_IRQ_PIN;131if (gpio_request(pin, "PCI Int2") == 0) {132if (gpio_direction_input(pin) == 0) {133irq_set_irq_type(gpio_to_irq(pin), IRQ_TYPE_LEVEL_LOW);134} else {135printk(KERN_ERR "qnap_ts209_pci_preinit failed "136"to set_irq_type pin %d\n", pin);137gpio_free(pin);138}139} else {140printk(KERN_ERR "qnap_ts209_pci_preinit failed to gpio_request "141"%d\n", pin);142}143}144145static int __init qnap_ts209_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin)146{147int irq;148149/*150* Check for devices with hard-wired IRQs.151*/152irq = orion5x_pci_map_irq(dev, slot, pin);153if (irq != -1)154return irq;155156/*157* PCI IRQs are connected via GPIOs.158*/159switch (slot - QNAP_TS209_PCI_SLOT0_OFFS) {160case 0:161return gpio_to_irq(QNAP_TS209_PCI_SLOT0_IRQ_PIN);162case 1:163return gpio_to_irq(QNAP_TS209_PCI_SLOT1_IRQ_PIN);164default:165return -1;166}167}168169static struct hw_pci qnap_ts209_pci __initdata = {170.nr_controllers = 2,171.preinit = qnap_ts209_pci_preinit,172.swizzle = pci_std_swizzle,173.setup = orion5x_pci_sys_setup,174.scan = orion5x_pci_sys_scan_bus,175.map_irq = qnap_ts209_pci_map_irq,176};177178static int __init qnap_ts209_pci_init(void)179{180if (machine_is_ts_x09())181pci_common_init(&qnap_ts209_pci);182183return 0;184}185186subsys_initcall(qnap_ts209_pci_init);187188/*****************************************************************************189* RTC S35390A on I2C bus190****************************************************************************/191192#define TS209_RTC_GPIO 3193194static struct i2c_board_info __initdata qnap_ts209_i2c_rtc = {195I2C_BOARD_INFO("s35390a", 0x30),196.irq = 0,197};198199/****************************************************************************200* GPIO Attached Keys201* Power button is attached to the PIC microcontroller202****************************************************************************/203204#define QNAP_TS209_GPIO_KEY_MEDIA 1205#define QNAP_TS209_GPIO_KEY_RESET 2206207static struct gpio_keys_button qnap_ts209_buttons[] = {208{209.code = KEY_COPY,210.gpio = QNAP_TS209_GPIO_KEY_MEDIA,211.desc = "USB Copy Button",212.active_low = 1,213}, {214.code = KEY_RESTART,215.gpio = QNAP_TS209_GPIO_KEY_RESET,216.desc = "Reset Button",217.active_low = 1,218},219};220221static struct gpio_keys_platform_data qnap_ts209_button_data = {222.buttons = qnap_ts209_buttons,223.nbuttons = ARRAY_SIZE(qnap_ts209_buttons),224};225226static struct platform_device qnap_ts209_button_device = {227.name = "gpio-keys",228.id = -1,229.num_resources = 0,230.dev = {231.platform_data = &qnap_ts209_button_data,232},233};234235/*****************************************************************************236* SATA237****************************************************************************/238static struct mv_sata_platform_data qnap_ts209_sata_data = {239.n_ports = 2,240};241242/*****************************************************************************243244* General Setup245****************************************************************************/246static unsigned int ts209_mpp_modes[] __initdata = {247MPP0_UNUSED,248MPP1_GPIO, /* USB copy button */249MPP2_GPIO, /* Load defaults button */250MPP3_GPIO, /* GPIO RTC */251MPP4_UNUSED,252MPP5_UNUSED,253MPP6_GPIO, /* PCI Int A */254MPP7_GPIO, /* PCI Int B */255MPP8_UNUSED,256MPP9_UNUSED,257MPP10_UNUSED,258MPP11_UNUSED,259MPP12_SATA_LED, /* SATA 0 presence */260MPP13_SATA_LED, /* SATA 1 presence */261MPP14_SATA_LED, /* SATA 0 active */262MPP15_SATA_LED, /* SATA 1 active */263MPP16_UART, /* UART1 RXD */264MPP17_UART, /* UART1 TXD */265MPP18_GPIO, /* SW_RST */266MPP19_UNUSED,2670,268};269270static void __init qnap_ts209_init(void)271{272/*273* Setup basic Orion functions. Need to be called early.274*/275orion5x_init();276277orion5x_mpp_conf(ts209_mpp_modes);278279/*280* MPP[20] PCI clock 0281* MPP[21] PCI clock 1282* MPP[22] USB 0 over current283* MPP[23-25] Reserved284*/285286/*287* Configure peripherals.288*/289orion5x_setup_dev_boot_win(QNAP_TS209_NOR_BOOT_BASE,290QNAP_TS209_NOR_BOOT_SIZE);291platform_device_register(&qnap_ts209_nor_flash);292293orion5x_ehci0_init();294orion5x_ehci1_init();295qnap_tsx09_find_mac_addr(QNAP_TS209_NOR_BOOT_BASE +296qnap_ts209_partitions[5].offset,297qnap_ts209_partitions[5].size);298orion5x_eth_init(&qnap_tsx09_eth_data);299orion5x_i2c_init();300orion5x_sata_init(&qnap_ts209_sata_data);301orion5x_uart0_init();302orion5x_uart1_init();303orion5x_xor_init();304305platform_device_register(&qnap_ts209_button_device);306307/* Get RTC IRQ and register the chip */308if (gpio_request(TS209_RTC_GPIO, "rtc") == 0) {309if (gpio_direction_input(TS209_RTC_GPIO) == 0)310qnap_ts209_i2c_rtc.irq = gpio_to_irq(TS209_RTC_GPIO);311else312gpio_free(TS209_RTC_GPIO);313}314if (qnap_ts209_i2c_rtc.irq == 0)315pr_warning("qnap_ts209_init: failed to get RTC IRQ\n");316i2c_register_board_info(0, &qnap_ts209_i2c_rtc, 1);317318/* register tsx09 specific power-off method */319pm_power_off = qnap_tsx09_power_off;320}321322MACHINE_START(TS209, "QNAP TS-109/TS-209")323/* Maintainer: Byron Bradley <[email protected]> */324.boot_params = 0x00000100,325.init_machine = qnap_ts209_init,326.map_io = orion5x_map_io,327.init_early = orion5x_init_early,328.init_irq = orion5x_init_irq,329.timer = &orion5x_timer,330.fixup = tag_fixup_mem32,331MACHINE_END332333334