Path: blob/master/arch/arm/mach-ixp4xx/nas100d-setup.c
10817 views
/*1* arch/arm/mach-ixp4xx/nas100d-setup.c2*3* NAS 100d board-setup4*5* Copyright (C) 2008 Rod Whitby <[email protected]>6*7* based on ixdp425-setup.c:8* Copyright (C) 2003-2004 MontaVista Software, Inc.9* based on nas100d-power.c:10* Copyright (C) 2005 Tower Technologies11* based on nas100d-io.c12* Copyright (C) 2004 Karen Spearel13*14* Author: Alessandro Zummo <[email protected]>15* Author: Rod Whitby <[email protected]>16* Maintainers: http://www.nslu2-linux.org/17*18*/1920#include <linux/if_ether.h>21#include <linux/irq.h>22#include <linux/jiffies.h>23#include <linux/timer.h>24#include <linux/serial.h>25#include <linux/serial_8250.h>26#include <linux/leds.h>27#include <linux/reboot.h>28#include <linux/i2c.h>29#include <linux/i2c-gpio.h>30#include <linux/io.h>31#include <asm/mach-types.h>32#include <asm/mach/arch.h>33#include <asm/mach/flash.h>34#include <asm/gpio.h>3536#define NAS100D_SDA_PIN 537#define NAS100D_SCL_PIN 63839/* Buttons */40#define NAS100D_PB_GPIO 14 /* power button */41#define NAS100D_RB_GPIO 4 /* reset button */4243/* Power control */44#define NAS100D_PO_GPIO 12 /* power off */4546/* LEDs */47#define NAS100D_LED_WLAN_GPIO 048#define NAS100D_LED_DISK_GPIO 349#define NAS100D_LED_PWR_GPIO 155051static struct flash_platform_data nas100d_flash_data = {52.map_name = "cfi_probe",53.width = 2,54};5556static struct resource nas100d_flash_resource = {57.flags = IORESOURCE_MEM,58};5960static struct platform_device nas100d_flash = {61.name = "IXP4XX-Flash",62.id = 0,63.dev.platform_data = &nas100d_flash_data,64.num_resources = 1,65.resource = &nas100d_flash_resource,66};6768static struct i2c_board_info __initdata nas100d_i2c_board_info [] = {69{70I2C_BOARD_INFO("pcf8563", 0x51),71},72};7374static struct gpio_led nas100d_led_pins[] = {75{76.name = "nas100d:green:wlan",77.gpio = NAS100D_LED_WLAN_GPIO,78.active_low = true,79},80{81.name = "nas100d:blue:power", /* (off=flashing) */82.gpio = NAS100D_LED_PWR_GPIO,83.active_low = true,84},85{86.name = "nas100d:yellow:disk",87.gpio = NAS100D_LED_DISK_GPIO,88.active_low = true,89},90};9192static struct gpio_led_platform_data nas100d_led_data = {93.num_leds = ARRAY_SIZE(nas100d_led_pins),94.leds = nas100d_led_pins,95};9697static struct platform_device nas100d_leds = {98.name = "leds-gpio",99.id = -1,100.dev.platform_data = &nas100d_led_data,101};102103static struct i2c_gpio_platform_data nas100d_i2c_gpio_data = {104.sda_pin = NAS100D_SDA_PIN,105.scl_pin = NAS100D_SCL_PIN,106};107108static struct platform_device nas100d_i2c_gpio = {109.name = "i2c-gpio",110.id = 0,111.dev = {112.platform_data = &nas100d_i2c_gpio_data,113},114};115116static struct resource nas100d_uart_resources[] = {117{118.start = IXP4XX_UART1_BASE_PHYS,119.end = IXP4XX_UART1_BASE_PHYS + 0x0fff,120.flags = IORESOURCE_MEM,121},122{123.start = IXP4XX_UART2_BASE_PHYS,124.end = IXP4XX_UART2_BASE_PHYS + 0x0fff,125.flags = IORESOURCE_MEM,126}127};128129static struct plat_serial8250_port nas100d_uart_data[] = {130{131.mapbase = IXP4XX_UART1_BASE_PHYS,132.membase = (char *)IXP4XX_UART1_BASE_VIRT + REG_OFFSET,133.irq = IRQ_IXP4XX_UART1,134.flags = UPF_BOOT_AUTOCONF,135.iotype = UPIO_MEM,136.regshift = 2,137.uartclk = IXP4XX_UART_XTAL,138},139{140.mapbase = IXP4XX_UART2_BASE_PHYS,141.membase = (char *)IXP4XX_UART2_BASE_VIRT + REG_OFFSET,142.irq = IRQ_IXP4XX_UART2,143.flags = UPF_BOOT_AUTOCONF,144.iotype = UPIO_MEM,145.regshift = 2,146.uartclk = IXP4XX_UART_XTAL,147},148{ }149};150151static struct platform_device nas100d_uart = {152.name = "serial8250",153.id = PLAT8250_DEV_PLATFORM,154.dev.platform_data = nas100d_uart_data,155.num_resources = 2,156.resource = nas100d_uart_resources,157};158159/* Built-in 10/100 Ethernet MAC interfaces */160static struct eth_plat_info nas100d_plat_eth[] = {161{162.phy = 0,163.rxq = 3,164.txreadyq = 20,165}166};167168static struct platform_device nas100d_eth[] = {169{170.name = "ixp4xx_eth",171.id = IXP4XX_ETH_NPEB,172.dev.platform_data = nas100d_plat_eth,173}174};175176static struct platform_device *nas100d_devices[] __initdata = {177&nas100d_i2c_gpio,178&nas100d_flash,179&nas100d_leds,180&nas100d_eth[0],181};182183static void nas100d_power_off(void)184{185/* This causes the box to drop the power and go dead. */186187/* enable the pwr cntl gpio */188gpio_line_config(NAS100D_PO_GPIO, IXP4XX_GPIO_OUT);189190/* do the deed */191gpio_line_set(NAS100D_PO_GPIO, IXP4XX_GPIO_HIGH);192}193194/* This is used to make sure the power-button pusher is serious. The button195* must be held until the value of this counter reaches zero.196*/197static int power_button_countdown;198199/* Must hold the button down for at least this many counts to be processed */200#define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */201202static void nas100d_power_handler(unsigned long data);203static DEFINE_TIMER(nas100d_power_timer, nas100d_power_handler, 0, 0);204205static void nas100d_power_handler(unsigned long data)206{207/* This routine is called twice per second to check the208* state of the power button.209*/210211if (gpio_get_value(NAS100D_PB_GPIO)) {212213/* IO Pin is 1 (button pushed) */214if (power_button_countdown > 0)215power_button_countdown--;216217} else {218219/* Done on button release, to allow for auto-power-on mods. */220if (power_button_countdown == 0) {221/* Signal init to do the ctrlaltdel action,222* this will bypass init if it hasn't started223* and do a kernel_restart.224*/225ctrl_alt_del();226227/* Change the state of the power LED to "blink" */228gpio_line_set(NAS100D_LED_PWR_GPIO, IXP4XX_GPIO_LOW);229} else {230power_button_countdown = PBUTTON_HOLDDOWN_COUNT;231}232}233234mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));235}236237static irqreturn_t nas100d_reset_handler(int irq, void *dev_id)238{239/* This is the paper-clip reset, it shuts the machine down directly. */240machine_power_off();241242return IRQ_HANDLED;243}244245static void __init nas100d_init(void)246{247uint8_t __iomem *f;248int i;249250ixp4xx_sys_init();251252/* gpio 14 and 15 are _not_ clocks */253*IXP4XX_GPIO_GPCLKR = 0;254255nas100d_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);256nas100d_flash_resource.end =257IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;258259i2c_register_board_info(0, nas100d_i2c_board_info,260ARRAY_SIZE(nas100d_i2c_board_info));261262/*263* This is only useful on a modified machine, but it is valuable264* to have it first in order to see debug messages, and so that265* it does *not* get removed if platform_add_devices fails!266*/267(void)platform_device_register(&nas100d_uart);268269platform_add_devices(nas100d_devices, ARRAY_SIZE(nas100d_devices));270271pm_power_off = nas100d_power_off;272273if (request_irq(gpio_to_irq(NAS100D_RB_GPIO), &nas100d_reset_handler,274IRQF_DISABLED | IRQF_TRIGGER_LOW,275"NAS100D reset button", NULL) < 0) {276277printk(KERN_DEBUG "Reset Button IRQ %d not available\n",278gpio_to_irq(NAS100D_RB_GPIO));279}280281/* The power button on the Iomega NAS100d is on GPIO 14, but282* it cannot handle interrupts on that GPIO line. So we'll283* have to poll it with a kernel timer.284*/285286/* Make sure that the power button GPIO is set up as an input */287gpio_line_config(NAS100D_PB_GPIO, IXP4XX_GPIO_IN);288289/* Set the initial value for the power button IRQ handler */290power_button_countdown = PBUTTON_HOLDDOWN_COUNT;291292mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));293294/*295* Map in a portion of the flash and read the MAC address.296* Since it is stored in BE in the flash itself, we need to297* byteswap it if we're in LE mode.298*/299f = ioremap(IXP4XX_EXP_BUS_BASE(0), 0x1000000);300if (f) {301for (i = 0; i < 6; i++)302#ifdef __ARMEB__303nas100d_plat_eth[0].hwaddr[i] = readb(f + 0xFC0FD8 + i);304#else305nas100d_plat_eth[0].hwaddr[i] = readb(f + 0xFC0FD8 + (i^3));306#endif307iounmap(f);308}309printk(KERN_INFO "NAS100D: Using MAC address %pM for port 0\n",310nas100d_plat_eth[0].hwaddr);311312}313314MACHINE_START(NAS100D, "Iomega NAS 100d")315/* Maintainer: www.nslu2-linux.org */316.boot_params = 0x00000100,317.map_io = ixp4xx_map_io,318.init_irq = ixp4xx_init_irq,319.timer = &ixp4xx_timer,320.init_machine = nas100d_init,321MACHINE_END322323324