Path: blob/master/arch/arm/mach-orion5x/net2big-setup.c
10817 views
/*1* arch/arm/mach-orion5x/net2big-setup.c2*3* LaCie 2Big Network NAS setup4*5* Copyright (C) 2009 Simon Guinot <[email protected]>6*7* This file is licensed under the terms of the GNU General Public8* License version 2. This program is licensed "as is" without any9* warranty of any kind, whether express or implied.10*/1112#include <linux/kernel.h>13#include <linux/init.h>14#include <linux/platform_device.h>15#include <linux/mtd/physmap.h>16#include <linux/mv643xx_eth.h>17#include <linux/leds.h>18#include <linux/gpio_keys.h>19#include <linux/input.h>20#include <linux/i2c.h>21#include <linux/ata_platform.h>22#include <linux/gpio.h>23#include <linux/delay.h>24#include <asm/mach-types.h>25#include <asm/mach/arch.h>26#include <mach/orion5x.h>27#include "common.h"28#include "mpp.h"2930/*****************************************************************************31* LaCie 2Big Network Info32****************************************************************************/3334/*35* 512KB NOR flash Device bus boot chip select36*/3738#define NET2BIG_NOR_BOOT_BASE 0xfff8000039#define NET2BIG_NOR_BOOT_SIZE SZ_512K4041/*****************************************************************************42* 512KB NOR Flash on Boot Device43****************************************************************************/4445/*46* TODO: Check write support on flash MX29LV400CBTC-70G47*/4849static struct mtd_partition net2big_partitions[] = {50{51.name = "Full512kb",52.size = MTDPART_SIZ_FULL,53.offset = 0x00000000,54.mask_flags = MTD_WRITEABLE,55},56};5758static struct physmap_flash_data net2big_nor_flash_data = {59.width = 1,60.parts = net2big_partitions,61.nr_parts = ARRAY_SIZE(net2big_partitions),62};6364static struct resource net2big_nor_flash_resource = {65.flags = IORESOURCE_MEM,66.start = NET2BIG_NOR_BOOT_BASE,67.end = NET2BIG_NOR_BOOT_BASE68+ NET2BIG_NOR_BOOT_SIZE - 1,69};7071static struct platform_device net2big_nor_flash = {72.name = "physmap-flash",73.id = 0,74.dev = {75.platform_data = &net2big_nor_flash_data,76},77.num_resources = 1,78.resource = &net2big_nor_flash_resource,79};8081/*****************************************************************************82* Ethernet83****************************************************************************/8485static struct mv643xx_eth_platform_data net2big_eth_data = {86.phy_addr = MV643XX_ETH_PHY_ADDR(8),87};8889/*****************************************************************************90* I2C devices91****************************************************************************/9293/*94* i2c addr | chip | description95* 0x32 | Ricoh 5C372b | RTC96* 0x50 | HT24LC08 | eeprom (1kB)97*/98static struct i2c_board_info __initdata net2big_i2c_devices[] = {99{100I2C_BOARD_INFO("rs5c372b", 0x32),101}, {102I2C_BOARD_INFO("24c08", 0x50),103},104};105106/*****************************************************************************107* SATA108****************************************************************************/109110static struct mv_sata_platform_data net2big_sata_data = {111.n_ports = 2,112};113114#define NET2BIG_GPIO_SATA_POWER_REQ 19115#define NET2BIG_GPIO_SATA0_POWER 23116#define NET2BIG_GPIO_SATA1_POWER 25117118static void __init net2big_sata_power_init(void)119{120int err;121122/* Configure GPIOs over MPP max number. */123orion_gpio_set_valid(NET2BIG_GPIO_SATA0_POWER, 1);124orion_gpio_set_valid(NET2BIG_GPIO_SATA1_POWER, 1);125126err = gpio_request(NET2BIG_GPIO_SATA0_POWER, "SATA0 power status");127if (err == 0) {128err = gpio_direction_input(NET2BIG_GPIO_SATA0_POWER);129if (err)130gpio_free(NET2BIG_GPIO_SATA0_POWER);131}132if (err) {133pr_err("net2big: failed to setup SATA0 power GPIO\n");134return;135}136137err = gpio_request(NET2BIG_GPIO_SATA1_POWER, "SATA1 power status");138if (err == 0) {139err = gpio_direction_input(NET2BIG_GPIO_SATA1_POWER);140if (err)141gpio_free(NET2BIG_GPIO_SATA1_POWER);142}143if (err) {144pr_err("net2big: failed to setup SATA1 power GPIO\n");145goto err_free_1;146}147148err = gpio_request(NET2BIG_GPIO_SATA_POWER_REQ, "SATA power request");149if (err == 0) {150err = gpio_direction_output(NET2BIG_GPIO_SATA_POWER_REQ, 0);151if (err)152gpio_free(NET2BIG_GPIO_SATA_POWER_REQ);153}154if (err) {155pr_err("net2big: failed to setup SATA power request GPIO\n");156goto err_free_2;157}158159if (gpio_get_value(NET2BIG_GPIO_SATA0_POWER) &&160gpio_get_value(NET2BIG_GPIO_SATA1_POWER)) {161return;162}163164/*165* SATA power up on both disk is done by pulling high the CPLD power166* request line. The 300ms delay is related to the CPLD clock and is167* needed to be sure that the CPLD has take into account the low line168* status.169*/170msleep(300);171gpio_set_value(NET2BIG_GPIO_SATA_POWER_REQ, 1);172pr_info("net2big: power up SATA hard disks\n");173174return;175176err_free_2:177gpio_free(NET2BIG_GPIO_SATA1_POWER);178err_free_1:179gpio_free(NET2BIG_GPIO_SATA0_POWER);180181return;182}183184/*****************************************************************************185* GPIO LEDs186****************************************************************************/187188/*189* The power front LEDs (blue and red) and SATA red LEDs are controlled via a190* single GPIO line and are compatible with the leds-gpio driver.191*192* The SATA blue LEDs have some hardware blink capabilities which are detailed193* in the following array:194*195* SATAx blue LED | SATAx activity | LED state196* | |197* 0 | 0 | blink (rate 300ms)198* 1 | 0 | off199* ? | 1 | on200*201* Notes: The blue and the red front LED's can't be on at the same time.202* Blue LED have priority.203*/204205#define NET2BIG_GPIO_PWR_RED_LED 6206#define NET2BIG_GPIO_PWR_BLUE_LED 16207#define NET2BIG_GPIO_PWR_LED_BLINK_STOP 7208209#define NET2BIG_GPIO_SATA0_RED_LED 11210#define NET2BIG_GPIO_SATA1_RED_LED 10211212#define NET2BIG_GPIO_SATA0_BLUE_LED 17213#define NET2BIG_GPIO_SATA1_BLUE_LED 13214215static struct gpio_led net2big_leds[] = {216{217.name = "net2big:red:power",218.gpio = NET2BIG_GPIO_PWR_RED_LED,219},220{221.name = "net2big:blue:power",222.gpio = NET2BIG_GPIO_PWR_BLUE_LED,223},224{225.name = "net2big:red:sata0",226.gpio = NET2BIG_GPIO_SATA0_RED_LED,227},228{229.name = "net2big:red:sata1",230.gpio = NET2BIG_GPIO_SATA1_RED_LED,231},232};233234static struct gpio_led_platform_data net2big_led_data = {235.num_leds = ARRAY_SIZE(net2big_leds),236.leds = net2big_leds,237};238239static struct platform_device net2big_gpio_leds = {240.name = "leds-gpio",241.id = -1,242.dev = {243.platform_data = &net2big_led_data,244},245};246247static void __init net2big_gpio_leds_init(void)248{249int err;250251/* Stop initial CPLD slow red/blue blinking on power LED. */252err = gpio_request(NET2BIG_GPIO_PWR_LED_BLINK_STOP,253"Power LED blink stop");254if (err == 0) {255err = gpio_direction_output(NET2BIG_GPIO_PWR_LED_BLINK_STOP, 1);256if (err)257gpio_free(NET2BIG_GPIO_PWR_LED_BLINK_STOP);258}259if (err)260pr_err("net2big: failed to setup power LED blink GPIO\n");261262/*263* Configure SATA0 and SATA1 blue LEDs to blink in relation with the264* hard disk activity.265*/266err = gpio_request(NET2BIG_GPIO_SATA0_BLUE_LED,267"SATA0 blue LED control");268if (err == 0) {269err = gpio_direction_output(NET2BIG_GPIO_SATA0_BLUE_LED, 1);270if (err)271gpio_free(NET2BIG_GPIO_SATA0_BLUE_LED);272}273if (err)274pr_err("net2big: failed to setup SATA0 blue LED GPIO\n");275276err = gpio_request(NET2BIG_GPIO_SATA1_BLUE_LED,277"SATA1 blue LED control");278if (err == 0) {279err = gpio_direction_output(NET2BIG_GPIO_SATA1_BLUE_LED, 1);280if (err)281gpio_free(NET2BIG_GPIO_SATA1_BLUE_LED);282}283if (err)284pr_err("net2big: failed to setup SATA1 blue LED GPIO\n");285286platform_device_register(&net2big_gpio_leds);287}288289/****************************************************************************290* GPIO keys291****************************************************************************/292293#define NET2BIG_GPIO_PUSH_BUTTON 18294#define NET2BIG_GPIO_POWER_SWITCH_ON 8295#define NET2BIG_GPIO_POWER_SWITCH_OFF 9296297#define NET2BIG_SWITCH_POWER_ON 0x1298#define NET2BIG_SWITCH_POWER_OFF 0x2299300static struct gpio_keys_button net2big_buttons[] = {301{302.type = EV_SW,303.code = NET2BIG_SWITCH_POWER_OFF,304.gpio = NET2BIG_GPIO_POWER_SWITCH_OFF,305.desc = "Power rocker switch (auto|off)",306.active_low = 0,307},308{309.type = EV_SW,310.code = NET2BIG_SWITCH_POWER_ON,311.gpio = NET2BIG_GPIO_POWER_SWITCH_ON,312.desc = "Power rocker switch (on|auto)",313.active_low = 0,314},315{316.type = EV_KEY,317.code = KEY_POWER,318.gpio = NET2BIG_GPIO_PUSH_BUTTON,319.desc = "Front Push Button",320.active_low = 0,321},322};323324static struct gpio_keys_platform_data net2big_button_data = {325.buttons = net2big_buttons,326.nbuttons = ARRAY_SIZE(net2big_buttons),327};328329static struct platform_device net2big_gpio_buttons = {330.name = "gpio-keys",331.id = -1,332.dev = {333.platform_data = &net2big_button_data,334},335};336337/*****************************************************************************338* General Setup339****************************************************************************/340341static unsigned int net2big_mpp_modes[] __initdata = {342MPP0_GPIO, /* Raid mode (bit 0) */343MPP1_GPIO, /* USB port 2 fuse (0 = Fail, 1 = Ok) */344MPP2_GPIO, /* Raid mode (bit 1) */345MPP3_GPIO, /* Board ID (bit 0) */346MPP4_GPIO, /* Fan activity (0 = Off, 1 = On) */347MPP5_GPIO, /* Fan fail detection */348MPP6_GPIO, /* Red front LED (0 = Off, 1 = On) */349MPP7_GPIO, /* Disable initial blinking on front LED */350MPP8_GPIO, /* Rear power switch (on|auto) */351MPP9_GPIO, /* Rear power switch (auto|off) */352MPP10_GPIO, /* SATA 1 red LED (0 = Off, 1 = On) */353MPP11_GPIO, /* SATA 0 red LED (0 = Off, 1 = On) */354MPP12_GPIO, /* Board ID (bit 1) */355MPP13_GPIO, /* SATA 1 blue LED blink control */356MPP14_SATA_LED,357MPP15_SATA_LED,358MPP16_GPIO, /* Blue front LED control */359MPP17_GPIO, /* SATA 0 blue LED blink control */360MPP18_GPIO, /* Front button (0 = Released, 1 = Pushed ) */361MPP19_GPIO, /* SATA{0,1} power On/Off request */3620,363/* 22: USB port 1 fuse (0 = Fail, 1 = Ok) */364/* 23: SATA 0 power status */365/* 24: Board power off */366/* 25: SATA 1 power status */367};368369#define NET2BIG_GPIO_POWER_OFF 24370371static void net2big_power_off(void)372{373gpio_set_value(NET2BIG_GPIO_POWER_OFF, 1);374}375376static void __init net2big_init(void)377{378/*379* Setup basic Orion functions. Need to be called early.380*/381orion5x_init();382383orion5x_mpp_conf(net2big_mpp_modes);384385/*386* Configure peripherals.387*/388orion5x_ehci0_init();389orion5x_ehci1_init();390orion5x_eth_init(&net2big_eth_data);391orion5x_i2c_init();392orion5x_uart0_init();393orion5x_xor_init();394395net2big_sata_power_init();396orion5x_sata_init(&net2big_sata_data);397398orion5x_setup_dev_boot_win(NET2BIG_NOR_BOOT_BASE,399NET2BIG_NOR_BOOT_SIZE);400platform_device_register(&net2big_nor_flash);401402platform_device_register(&net2big_gpio_buttons);403net2big_gpio_leds_init();404405i2c_register_board_info(0, net2big_i2c_devices,406ARRAY_SIZE(net2big_i2c_devices));407408orion_gpio_set_valid(NET2BIG_GPIO_POWER_OFF, 1);409410if (gpio_request(NET2BIG_GPIO_POWER_OFF, "power-off") == 0 &&411gpio_direction_output(NET2BIG_GPIO_POWER_OFF, 0) == 0)412pm_power_off = net2big_power_off;413else414pr_err("net2big: failed to configure power-off GPIO\n");415416pr_notice("net2big: Flash writing is not yet supported.\n");417}418419/* Warning: LaCie use a wrong mach-type (0x20e=526) in their bootloader. */420MACHINE_START(NET2BIG, "LaCie 2Big Network")421.boot_params = 0x00000100,422.init_machine = net2big_init,423.map_io = orion5x_map_io,424.init_early = orion5x_init_early,425.init_irq = orion5x_init_irq,426.timer = &orion5x_timer,427.fixup = tag_fixup_mem32,428MACHINE_END429430431432