Path: blob/master/arch/arm/mach-orion5x/terastation_pro2-setup.c
10817 views
/*1* Buffalo Terastation Pro II/Live Board Setup2*3* Maintainer: Sylver Bruneau <[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/delay.h>17#include <linux/mtd/physmap.h>18#include <linux/mv643xx_eth.h>19#include <linux/i2c.h>20#include <linux/serial_reg.h>21#include <asm/mach-types.h>22#include <asm/gpio.h>23#include <asm/mach/arch.h>24#include <asm/mach/pci.h>25#include <mach/orion5x.h>26#include "common.h"27#include "mpp.h"2829/*****************************************************************************30* Terastation Pro 2/Live Info31****************************************************************************/3233/*34* Terastation Pro 2 hardware :35* - Marvell 88F5281-D036* - Marvell 88SX6042 SATA controller (PCI)37* - Marvell 88E1118 Gigabit Ethernet PHY38* - 256KB NOR flash39* - 128MB of DDR RAM40* - PCIe port (not equipped)41*/4243/*44* 256K NOR flash Device bus boot chip select45*/4647#define TSP2_NOR_BOOT_BASE 0xf400000048#define TSP2_NOR_BOOT_SIZE SZ_256K4950/*****************************************************************************51* 256KB NOR Flash on BOOT Device52****************************************************************************/5354static struct physmap_flash_data tsp2_nor_flash_data = {55.width = 1,56};5758static struct resource tsp2_nor_flash_resource = {59.flags = IORESOURCE_MEM,60.start = TSP2_NOR_BOOT_BASE,61.end = TSP2_NOR_BOOT_BASE + TSP2_NOR_BOOT_SIZE - 1,62};6364static struct platform_device tsp2_nor_flash = {65.name = "physmap-flash",66.id = 0,67.dev = {68.platform_data = &tsp2_nor_flash_data,69},70.num_resources = 1,71.resource = &tsp2_nor_flash_resource,72};7374/*****************************************************************************75* PCI76****************************************************************************/77#define TSP2_PCI_SLOT0_OFFS 778#define TSP2_PCI_SLOT0_IRQ_PIN 117980void __init tsp2_pci_preinit(void)81{82int pin;8384/*85* Configure PCI GPIO IRQ pins86*/87pin = TSP2_PCI_SLOT0_IRQ_PIN;88if (gpio_request(pin, "PCI Int1") == 0) {89if (gpio_direction_input(pin) == 0) {90irq_set_irq_type(gpio_to_irq(pin), IRQ_TYPE_LEVEL_LOW);91} else {92printk(KERN_ERR "tsp2_pci_preinit failed "93"to set_irq_type pin %d\n", pin);94gpio_free(pin);95}96} else {97printk(KERN_ERR "tsp2_pci_preinit failed to "98"gpio_request %d\n", pin);99}100}101102static int __init tsp2_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin)103{104int irq;105106/*107* Check for devices with hard-wired IRQs.108*/109irq = orion5x_pci_map_irq(dev, slot, pin);110if (irq != -1)111return irq;112113/*114* PCI IRQs are connected via GPIOs.115*/116if (slot == TSP2_PCI_SLOT0_OFFS)117return gpio_to_irq(TSP2_PCI_SLOT0_IRQ_PIN);118119return -1;120}121122static struct hw_pci tsp2_pci __initdata = {123.nr_controllers = 2,124.preinit = tsp2_pci_preinit,125.swizzle = pci_std_swizzle,126.setup = orion5x_pci_sys_setup,127.scan = orion5x_pci_sys_scan_bus,128.map_irq = tsp2_pci_map_irq,129};130131static int __init tsp2_pci_init(void)132{133if (machine_is_terastation_pro2())134pci_common_init(&tsp2_pci);135136return 0;137}138139subsys_initcall(tsp2_pci_init);140141/*****************************************************************************142* Ethernet143****************************************************************************/144145static struct mv643xx_eth_platform_data tsp2_eth_data = {146.phy_addr = 0,147};148149/*****************************************************************************150* RTC 5C372a on I2C bus151****************************************************************************/152153#define TSP2_RTC_GPIO 9154155static struct i2c_board_info __initdata tsp2_i2c_rtc = {156I2C_BOARD_INFO("rs5c372a", 0x32),157};158159/*****************************************************************************160* Terastation Pro II specific power off method via UART1-attached161* microcontroller162****************************************************************************/163164#define UART1_REG(x) (UART1_VIRT_BASE + ((UART_##x) << 2))165166static int tsp2_miconread(unsigned char *buf, int count)167{168int i;169int timeout;170171for (i = 0; i < count; i++) {172timeout = 10;173174while (!(readl(UART1_REG(LSR)) & UART_LSR_DR)) {175if (--timeout == 0)176break;177udelay(1000);178}179180if (timeout == 0)181break;182buf[i] = readl(UART1_REG(RX));183}184185/* return read bytes */186return i;187}188189static int tsp2_miconwrite(const unsigned char *buf, int count)190{191int i = 0;192193while (count--) {194while (!(readl(UART1_REG(LSR)) & UART_LSR_THRE))195barrier();196writel(buf[i++], UART1_REG(TX));197}198199return 0;200}201202static int tsp2_miconsend(const unsigned char *data, int count)203{204int i;205unsigned char checksum = 0;206unsigned char recv_buf[40];207unsigned char send_buf[40];208unsigned char correct_ack[3];209int retry = 2;210211/* Generate checksum */212for (i = 0; i < count; i++)213checksum -= data[i];214215do {216/* Send data */217tsp2_miconwrite(data, count);218219/* send checksum */220tsp2_miconwrite(&checksum, 1);221222if (tsp2_miconread(recv_buf, sizeof(recv_buf)) <= 3) {223printk(KERN_ERR ">%s: receive failed.\n", __func__);224225/* send preamble to clear the receive buffer */226memset(&send_buf, 0xff, sizeof(send_buf));227tsp2_miconwrite(send_buf, sizeof(send_buf));228229/* make dummy reads */230mdelay(100);231tsp2_miconread(recv_buf, sizeof(recv_buf));232} else {233/* Generate expected ack */234correct_ack[0] = 0x01;235correct_ack[1] = data[1];236correct_ack[2] = 0x00;237238/* checksum Check */239if ((recv_buf[0] + recv_buf[1] + recv_buf[2] +240recv_buf[3]) & 0xFF) {241printk(KERN_ERR ">%s: Checksum Error : "242"Received data[%02x, %02x, %02x, %02x]"243"\n", __func__, recv_buf[0],244recv_buf[1], recv_buf[2], recv_buf[3]);245} else {246/* Check Received Data */247if (correct_ack[0] == recv_buf[0] &&248correct_ack[1] == recv_buf[1] &&249correct_ack[2] == recv_buf[2]) {250/* Interval for next command */251mdelay(10);252253/* Receive ACK */254return 0;255}256}257/* Received NAK or illegal Data */258printk(KERN_ERR ">%s: Error : NAK or Illegal Data "259"Received\n", __func__);260}261} while (retry--);262263/* Interval for next command */264mdelay(10);265266return -1;267}268269static void tsp2_power_off(void)270{271const unsigned char watchdogkill[] = {0x01, 0x35, 0x00};272const unsigned char shutdownwait[] = {0x00, 0x0c};273const unsigned char poweroff[] = {0x00, 0x06};274/* 38400 baud divisor */275const unsigned divisor = ((orion5x_tclk + (8 * 38400)) / (16 * 38400));276277pr_info("%s: triggering power-off...\n", __func__);278279/* hijack uart1 and reset into sane state (38400,8n1,even parity) */280writel(0x83, UART1_REG(LCR));281writel(divisor & 0xff, UART1_REG(DLL));282writel((divisor >> 8) & 0xff, UART1_REG(DLM));283writel(0x1b, UART1_REG(LCR));284writel(0x00, UART1_REG(IER));285writel(0x07, UART1_REG(FCR));286writel(0x00, UART1_REG(MCR));287288/* Send the commands to shutdown the Terastation Pro II */289tsp2_miconsend(watchdogkill, sizeof(watchdogkill)) ;290tsp2_miconsend(shutdownwait, sizeof(shutdownwait)) ;291tsp2_miconsend(poweroff, sizeof(poweroff));292}293294/*****************************************************************************295* General Setup296****************************************************************************/297static unsigned int tsp2_mpp_modes[] __initdata = {298MPP0_PCIE_RST_OUTn,299MPP1_UNUSED,300MPP2_UNUSED,301MPP3_UNUSED,302MPP4_NAND, /* BOOT NAND Flash REn */303MPP5_NAND, /* BOOT NAND Flash WEn */304MPP6_NAND, /* BOOT NAND Flash HREn[0] */305MPP7_NAND, /* BOOT NAND Flash WEn[0] */306MPP8_GPIO, /* MICON int */307MPP9_GPIO, /* RTC int */308MPP10_UNUSED,309MPP11_GPIO, /* PCI Int A */310MPP12_UNUSED,311MPP13_GPIO, /* UPS on UART0 enable */312MPP14_GPIO, /* UPS low battery detection */313MPP15_UNUSED,314MPP16_UART, /* UART1 RXD */315MPP17_UART, /* UART1 TXD */316MPP18_UART, /* UART1 CTSn */317MPP19_UART, /* UART1 RTSn */3180,319};320321static void __init tsp2_init(void)322{323/*324* Setup basic Orion functions. Need to be called early.325*/326orion5x_init();327328orion5x_mpp_conf(tsp2_mpp_modes);329330/*331* Configure peripherals.332*/333orion5x_setup_dev_boot_win(TSP2_NOR_BOOT_BASE,334TSP2_NOR_BOOT_SIZE);335platform_device_register(&tsp2_nor_flash);336337orion5x_ehci0_init();338orion5x_eth_init(&tsp2_eth_data);339orion5x_i2c_init();340orion5x_uart0_init();341orion5x_uart1_init();342343/* Get RTC IRQ and register the chip */344if (gpio_request(TSP2_RTC_GPIO, "rtc") == 0) {345if (gpio_direction_input(TSP2_RTC_GPIO) == 0)346tsp2_i2c_rtc.irq = gpio_to_irq(TSP2_RTC_GPIO);347else348gpio_free(TSP2_RTC_GPIO);349}350if (tsp2_i2c_rtc.irq == 0)351pr_warning("tsp2_init: failed to get RTC IRQ\n");352i2c_register_board_info(0, &tsp2_i2c_rtc, 1);353354/* register Terastation Pro II specific power-off method */355pm_power_off = tsp2_power_off;356}357358MACHINE_START(TERASTATION_PRO2, "Buffalo Terastation Pro II/Live")359/* Maintainer: Sylver Bruneau <[email protected]> */360.boot_params = 0x00000100,361.init_machine = tsp2_init,362.map_io = orion5x_map_io,363.init_early = orion5x_init_early,364.init_irq = orion5x_init_irq,365.timer = &orion5x_timer,366.fixup = tag_fixup_mem32,367MACHINE_END368369370