Path: blob/master/arch/arm/mach-orion5x/net2big-setup.c
26292 views
// SPDX-License-Identifier: GPL-2.0-only1/*2* arch/arm/mach-orion5x/net2big-setup.c3*4* LaCie 2Big Network NAS setup5*6* Copyright (C) 2009 Simon Guinot <[email protected]>7*/89#include <linux/kernel.h>10#include <linux/init.h>11#include <linux/platform_device.h>12#include <linux/mtd/physmap.h>13#include <linux/mv643xx_eth.h>14#include <linux/leds.h>15#include <linux/gpio_keys.h>16#include <linux/input.h>17#include <linux/i2c.h>18#include <linux/ata_platform.h>19#include <linux/gpio.h>20#include <linux/gpio/machine.h>21#include <linux/delay.h>22#include <asm/mach-types.h>23#include <asm/mach/arch.h>24#include <plat/orion-gpio.h>25#include "common.h"26#include "mpp.h"27#include "orion5x.h"2829/*****************************************************************************30* LaCie 2Big Network Info31****************************************************************************/3233/*34* 512KB NOR flash Device bus boot chip select35*/3637#define NET2BIG_NOR_BOOT_BASE 0xfff8000038#define NET2BIG_NOR_BOOT_SIZE SZ_512K3940/*****************************************************************************41* 512KB NOR Flash on Boot Device42****************************************************************************/4344/*45* TODO: Check write support on flash MX29LV400CBTC-70G46*/4748static struct mtd_partition net2big_partitions[] = {49{50.name = "Full512kb",51.size = MTDPART_SIZ_FULL,52.offset = 0x00000000,53.mask_flags = MTD_WRITEABLE,54},55};5657static struct physmap_flash_data net2big_nor_flash_data = {58.width = 1,59.parts = net2big_partitions,60.nr_parts = ARRAY_SIZE(net2big_partitions),61};6263static struct resource net2big_nor_flash_resource = {64.flags = IORESOURCE_MEM,65.start = NET2BIG_NOR_BOOT_BASE,66.end = NET2BIG_NOR_BOOT_BASE67+ NET2BIG_NOR_BOOT_SIZE - 1,68};6970static struct platform_device net2big_nor_flash = {71.name = "physmap-flash",72.id = 0,73.dev = {74.platform_data = &net2big_nor_flash_data,75},76.num_resources = 1,77.resource = &net2big_nor_flash_resource,78};7980/*****************************************************************************81* Ethernet82****************************************************************************/8384static struct mv643xx_eth_platform_data net2big_eth_data = {85.phy_addr = MV643XX_ETH_PHY_ADDR(8),86};8788/*****************************************************************************89* I2C devices90****************************************************************************/9192/*93* i2c addr | chip | description94* 0x32 | Ricoh 5C372b | RTC95* 0x50 | HT24LC08 | eeprom (1kB)96*/97static struct i2c_board_info __initdata net2big_i2c_devices[] = {98{99I2C_BOARD_INFO("rs5c372b", 0x32),100}, {101I2C_BOARD_INFO("24c08", 0x50),102},103};104105/*****************************************************************************106* SATA107****************************************************************************/108109static struct mv_sata_platform_data net2big_sata_data = {110.n_ports = 2,111};112113#define NET2BIG_GPIO_SATA_POWER_REQ 19114#define NET2BIG_GPIO_SATA0_POWER 23115#define NET2BIG_GPIO_SATA1_POWER 25116117static void __init net2big_sata_power_init(void)118{119int err;120121/* Configure GPIOs over MPP max number. */122orion_gpio_set_valid(NET2BIG_GPIO_SATA0_POWER, 1);123orion_gpio_set_valid(NET2BIG_GPIO_SATA1_POWER, 1);124125err = gpio_request(NET2BIG_GPIO_SATA0_POWER, "SATA0 power status");126if (err == 0) {127err = gpio_direction_input(NET2BIG_GPIO_SATA0_POWER);128if (err)129gpio_free(NET2BIG_GPIO_SATA0_POWER);130}131if (err) {132pr_err("net2big: failed to setup SATA0 power GPIO\n");133return;134}135136err = gpio_request(NET2BIG_GPIO_SATA1_POWER, "SATA1 power status");137if (err == 0) {138err = gpio_direction_input(NET2BIG_GPIO_SATA1_POWER);139if (err)140gpio_free(NET2BIG_GPIO_SATA1_POWER);141}142if (err) {143pr_err("net2big: failed to setup SATA1 power GPIO\n");144goto err_free_1;145}146147err = gpio_request(NET2BIG_GPIO_SATA_POWER_REQ, "SATA power request");148if (err == 0) {149err = gpio_direction_output(NET2BIG_GPIO_SATA_POWER_REQ, 0);150if (err)151gpio_free(NET2BIG_GPIO_SATA_POWER_REQ);152}153if (err) {154pr_err("net2big: failed to setup SATA power request GPIO\n");155goto err_free_2;156}157158if (gpio_get_value(NET2BIG_GPIO_SATA0_POWER) &&159gpio_get_value(NET2BIG_GPIO_SATA1_POWER)) {160return;161}162163/*164* SATA power up on both disk is done by pulling high the CPLD power165* request line. The 300ms delay is related to the CPLD clock and is166* needed to be sure that the CPLD has take into account the low line167* status.168*/169msleep(300);170gpio_set_value(NET2BIG_GPIO_SATA_POWER_REQ, 1);171pr_info("net2big: power up SATA hard disks\n");172173return;174175err_free_2:176gpio_free(NET2BIG_GPIO_SATA1_POWER);177err_free_1:178gpio_free(NET2BIG_GPIO_SATA0_POWER);179180return;181}182183/*****************************************************************************184* GPIO LEDs185****************************************************************************/186187/*188* The power front LEDs (blue and red) and SATA red LEDs are controlled via a189* single GPIO line and are compatible with the leds-gpio driver.190*191* The SATA blue LEDs have some hardware blink capabilities which are detailed192* in the following array:193*194* SATAx blue LED | SATAx activity | LED state195* | |196* 0 | 0 | blink (rate 300ms)197* 1 | 0 | off198* ? | 1 | on199*200* Notes: The blue and the red front LED's can't be on at the same time.201* Blue LED have priority.202*/203204#define NET2BIG_GPIO_PWR_RED_LED 6205#define NET2BIG_GPIO_PWR_BLUE_LED 16206#define NET2BIG_GPIO_PWR_LED_BLINK_STOP 7207208#define NET2BIG_GPIO_SATA0_RED_LED 11209#define NET2BIG_GPIO_SATA1_RED_LED 10210211#define NET2BIG_GPIO_SATA0_BLUE_LED 17212#define NET2BIG_GPIO_SATA1_BLUE_LED 13213214static struct gpio_led net2big_leds[] = {215{216.name = "net2big:red:power",217},218{219.name = "net2big:blue:power",220},221{222.name = "net2big:red:sata0",223},224{225.name = "net2big:red:sata1",226},227};228229static struct gpiod_lookup_table net2big_leds_gpio_table = {230.dev_id = "leds-gpio",231.table = {232GPIO_LOOKUP_IDX("orion_gpio0", NET2BIG_GPIO_PWR_RED_LED, NULL,2330, GPIO_ACTIVE_HIGH),234GPIO_LOOKUP_IDX("orion_gpio0", NET2BIG_GPIO_PWR_BLUE_LED, NULL,2351, GPIO_ACTIVE_HIGH),236GPIO_LOOKUP_IDX("orion_gpio0", NET2BIG_GPIO_SATA0_RED_LED, NULL,2372, GPIO_ACTIVE_HIGH),238GPIO_LOOKUP_IDX("orion_gpio0", NET2BIG_GPIO_SATA1_RED_LED, NULL,2393, GPIO_ACTIVE_HIGH),240{ },241},242};243244static struct gpio_led_platform_data net2big_led_data = {245.num_leds = ARRAY_SIZE(net2big_leds),246.leds = net2big_leds,247};248249static struct platform_device net2big_gpio_leds = {250.name = "leds-gpio",251.id = -1,252.dev = {253.platform_data = &net2big_led_data,254},255};256257static void __init net2big_gpio_leds_init(void)258{259int err;260261/* Stop initial CPLD slow red/blue blinking on power LED. */262err = gpio_request(NET2BIG_GPIO_PWR_LED_BLINK_STOP,263"Power LED blink stop");264if (err == 0) {265err = gpio_direction_output(NET2BIG_GPIO_PWR_LED_BLINK_STOP, 1);266if (err)267gpio_free(NET2BIG_GPIO_PWR_LED_BLINK_STOP);268}269if (err)270pr_err("net2big: failed to setup power LED blink GPIO\n");271272/*273* Configure SATA0 and SATA1 blue LEDs to blink in relation with the274* hard disk activity.275*/276err = gpio_request(NET2BIG_GPIO_SATA0_BLUE_LED,277"SATA0 blue LED control");278if (err == 0) {279err = gpio_direction_output(NET2BIG_GPIO_SATA0_BLUE_LED, 1);280if (err)281gpio_free(NET2BIG_GPIO_SATA0_BLUE_LED);282}283if (err)284pr_err("net2big: failed to setup SATA0 blue LED GPIO\n");285286err = gpio_request(NET2BIG_GPIO_SATA1_BLUE_LED,287"SATA1 blue LED control");288if (err == 0) {289err = gpio_direction_output(NET2BIG_GPIO_SATA1_BLUE_LED, 1);290if (err)291gpio_free(NET2BIG_GPIO_SATA1_BLUE_LED);292}293if (err)294pr_err("net2big: failed to setup SATA1 blue LED GPIO\n");295296gpiod_add_lookup_table(&net2big_leds_gpio_table);297platform_device_register(&net2big_gpio_leds);298}299300/****************************************************************************301* GPIO keys302****************************************************************************/303304#define NET2BIG_GPIO_PUSH_BUTTON 18305#define NET2BIG_GPIO_POWER_SWITCH_ON 8306#define NET2BIG_GPIO_POWER_SWITCH_OFF 9307308#define NET2BIG_SWITCH_POWER_ON 0x1309#define NET2BIG_SWITCH_POWER_OFF 0x2310311static struct gpio_keys_button net2big_buttons[] = {312{313.type = EV_SW,314.code = NET2BIG_SWITCH_POWER_OFF,315.gpio = NET2BIG_GPIO_POWER_SWITCH_OFF,316.desc = "Power rocker switch (auto|off)",317.active_low = 0,318},319{320.type = EV_SW,321.code = NET2BIG_SWITCH_POWER_ON,322.gpio = NET2BIG_GPIO_POWER_SWITCH_ON,323.desc = "Power rocker switch (on|auto)",324.active_low = 0,325},326{327.type = EV_KEY,328.code = KEY_POWER,329.gpio = NET2BIG_GPIO_PUSH_BUTTON,330.desc = "Front Push Button",331.active_low = 0,332},333};334335static struct gpio_keys_platform_data net2big_button_data = {336.buttons = net2big_buttons,337.nbuttons = ARRAY_SIZE(net2big_buttons),338};339340static struct platform_device net2big_gpio_buttons = {341.name = "gpio-keys",342.id = -1,343.dev = {344.platform_data = &net2big_button_data,345},346};347348/*****************************************************************************349* General Setup350****************************************************************************/351352static unsigned int net2big_mpp_modes[] __initdata = {353MPP0_GPIO, /* Raid mode (bit 0) */354MPP1_GPIO, /* USB port 2 fuse (0 = Fail, 1 = Ok) */355MPP2_GPIO, /* Raid mode (bit 1) */356MPP3_GPIO, /* Board ID (bit 0) */357MPP4_GPIO, /* Fan activity (0 = Off, 1 = On) */358MPP5_GPIO, /* Fan fail detection */359MPP6_GPIO, /* Red front LED (0 = Off, 1 = On) */360MPP7_GPIO, /* Disable initial blinking on front LED */361MPP8_GPIO, /* Rear power switch (on|auto) */362MPP9_GPIO, /* Rear power switch (auto|off) */363MPP10_GPIO, /* SATA 1 red LED (0 = Off, 1 = On) */364MPP11_GPIO, /* SATA 0 red LED (0 = Off, 1 = On) */365MPP12_GPIO, /* Board ID (bit 1) */366MPP13_GPIO, /* SATA 1 blue LED blink control */367MPP14_SATA_LED,368MPP15_SATA_LED,369MPP16_GPIO, /* Blue front LED control */370MPP17_GPIO, /* SATA 0 blue LED blink control */371MPP18_GPIO, /* Front button (0 = Released, 1 = Pushed ) */372MPP19_GPIO, /* SATA{0,1} power On/Off request */3730,374/* 22: USB port 1 fuse (0 = Fail, 1 = Ok) */375/* 23: SATA 0 power status */376/* 24: Board power off */377/* 25: SATA 1 power status */378};379380#define NET2BIG_GPIO_POWER_OFF 24381382static void net2big_power_off(void)383{384gpio_set_value(NET2BIG_GPIO_POWER_OFF, 1);385}386387static void __init net2big_init(void)388{389/*390* Setup basic Orion functions. Need to be called early.391*/392orion5x_init();393394orion5x_mpp_conf(net2big_mpp_modes);395396/*397* Configure peripherals.398*/399orion5x_ehci0_init();400orion5x_ehci1_init();401orion5x_eth_init(&net2big_eth_data);402orion5x_i2c_init();403orion5x_uart0_init();404orion5x_xor_init();405406net2big_sata_power_init();407orion5x_sata_init(&net2big_sata_data);408409mvebu_mbus_add_window_by_id(ORION_MBUS_DEVBUS_BOOT_TARGET,410ORION_MBUS_DEVBUS_BOOT_ATTR,411NET2BIG_NOR_BOOT_BASE,412NET2BIG_NOR_BOOT_SIZE);413platform_device_register(&net2big_nor_flash);414415platform_device_register(&net2big_gpio_buttons);416net2big_gpio_leds_init();417418i2c_register_board_info(0, net2big_i2c_devices,419ARRAY_SIZE(net2big_i2c_devices));420421orion_gpio_set_valid(NET2BIG_GPIO_POWER_OFF, 1);422423if (gpio_request(NET2BIG_GPIO_POWER_OFF, "power-off") == 0 &&424gpio_direction_output(NET2BIG_GPIO_POWER_OFF, 0) == 0)425register_platform_power_off(net2big_power_off);426else427pr_err("net2big: failed to configure power-off GPIO\n");428429pr_notice("net2big: Flash writing is not yet supported.\n");430}431432/* Warning: LaCie use a wrong mach-type (0x20e=526) in their bootloader. */433MACHINE_START(NET2BIG, "LaCie 2Big Network")434.atag_offset = 0x100,435.nr_irqs = ORION5X_NR_IRQS,436.init_machine = net2big_init,437.map_io = orion5x_map_io,438.init_early = orion5x_init_early,439.init_irq = orion5x_init_irq,440.init_time = orion5x_timer_init,441.fixup = tag_fixup_mem32,442.restart = orion5x_restart,443MACHINE_END444445446