Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * arch/arm/mach-orion5x/net2big-setup.c
0004  *
0005  * LaCie 2Big Network NAS setup
0006  *
0007  * Copyright (C) 2009 Simon Guinot <sguinot@lacie.com>
0008  */
0009 
0010 #include <linux/kernel.h>
0011 #include <linux/init.h>
0012 #include <linux/platform_device.h>
0013 #include <linux/mtd/physmap.h>
0014 #include <linux/mv643xx_eth.h>
0015 #include <linux/leds.h>
0016 #include <linux/gpio_keys.h>
0017 #include <linux/input.h>
0018 #include <linux/i2c.h>
0019 #include <linux/ata_platform.h>
0020 #include <linux/gpio.h>
0021 #include <linux/delay.h>
0022 #include <asm/mach-types.h>
0023 #include <asm/mach/arch.h>
0024 #include <plat/orion-gpio.h>
0025 #include "common.h"
0026 #include "mpp.h"
0027 #include "orion5x.h"
0028 
0029 /*****************************************************************************
0030  * LaCie 2Big Network Info
0031  ****************************************************************************/
0032 
0033 /*
0034  * 512KB NOR flash Device bus boot chip select
0035  */
0036 
0037 #define NET2BIG_NOR_BOOT_BASE       0xfff80000
0038 #define NET2BIG_NOR_BOOT_SIZE       SZ_512K
0039 
0040 /*****************************************************************************
0041  * 512KB NOR Flash on Boot Device
0042  ****************************************************************************/
0043 
0044 /*
0045  * TODO: Check write support on flash MX29LV400CBTC-70G
0046  */
0047 
0048 static struct mtd_partition net2big_partitions[] = {
0049     {
0050         .name       = "Full512kb",
0051         .size       = MTDPART_SIZ_FULL,
0052         .offset     = 0x00000000,
0053         .mask_flags = MTD_WRITEABLE,
0054     },
0055 };
0056 
0057 static struct physmap_flash_data net2big_nor_flash_data = {
0058     .width      = 1,
0059     .parts      = net2big_partitions,
0060     .nr_parts   = ARRAY_SIZE(net2big_partitions),
0061 };
0062 
0063 static struct resource net2big_nor_flash_resource = {
0064     .flags          = IORESOURCE_MEM,
0065     .start          = NET2BIG_NOR_BOOT_BASE,
0066     .end            = NET2BIG_NOR_BOOT_BASE
0067                     + NET2BIG_NOR_BOOT_SIZE - 1,
0068 };
0069 
0070 static struct platform_device net2big_nor_flash = {
0071     .name           = "physmap-flash",
0072     .id         = 0,
0073     .dev        = {
0074         .platform_data  = &net2big_nor_flash_data,
0075     },
0076     .num_resources      = 1,
0077     .resource       = &net2big_nor_flash_resource,
0078 };
0079 
0080 /*****************************************************************************
0081  * Ethernet
0082  ****************************************************************************/
0083 
0084 static struct mv643xx_eth_platform_data net2big_eth_data = {
0085     .phy_addr   = MV643XX_ETH_PHY_ADDR(8),
0086 };
0087 
0088 /*****************************************************************************
0089  * I2C devices
0090  ****************************************************************************/
0091 
0092 /*
0093  * i2c addr | chip         | description
0094  * 0x32     | Ricoh 5C372b | RTC
0095  * 0x50     | HT24LC08     | eeprom (1kB)
0096  */
0097 static struct i2c_board_info __initdata net2big_i2c_devices[] = {
0098     {
0099         I2C_BOARD_INFO("rs5c372b", 0x32),
0100     }, {
0101         I2C_BOARD_INFO("24c08", 0x50),
0102     },
0103 };
0104 
0105 /*****************************************************************************
0106  * SATA
0107  ****************************************************************************/
0108 
0109 static struct mv_sata_platform_data net2big_sata_data = {
0110     .n_ports    = 2,
0111 };
0112 
0113 #define NET2BIG_GPIO_SATA_POWER_REQ 19
0114 #define NET2BIG_GPIO_SATA0_POWER    23
0115 #define NET2BIG_GPIO_SATA1_POWER    25
0116 
0117 static void __init net2big_sata_power_init(void)
0118 {
0119     int err;
0120 
0121     /* Configure GPIOs over MPP max number. */
0122     orion_gpio_set_valid(NET2BIG_GPIO_SATA0_POWER, 1);
0123     orion_gpio_set_valid(NET2BIG_GPIO_SATA1_POWER, 1);
0124 
0125     err = gpio_request(NET2BIG_GPIO_SATA0_POWER, "SATA0 power status");
0126     if (err == 0) {
0127         err = gpio_direction_input(NET2BIG_GPIO_SATA0_POWER);
0128         if (err)
0129             gpio_free(NET2BIG_GPIO_SATA0_POWER);
0130     }
0131     if (err) {
0132         pr_err("net2big: failed to setup SATA0 power GPIO\n");
0133         return;
0134     }
0135 
0136     err = gpio_request(NET2BIG_GPIO_SATA1_POWER, "SATA1 power status");
0137     if (err == 0) {
0138         err = gpio_direction_input(NET2BIG_GPIO_SATA1_POWER);
0139         if (err)
0140             gpio_free(NET2BIG_GPIO_SATA1_POWER);
0141     }
0142     if (err) {
0143         pr_err("net2big: failed to setup SATA1 power GPIO\n");
0144         goto err_free_1;
0145     }
0146 
0147     err = gpio_request(NET2BIG_GPIO_SATA_POWER_REQ, "SATA power request");
0148     if (err == 0) {
0149         err = gpio_direction_output(NET2BIG_GPIO_SATA_POWER_REQ, 0);
0150         if (err)
0151             gpio_free(NET2BIG_GPIO_SATA_POWER_REQ);
0152     }
0153     if (err) {
0154         pr_err("net2big: failed to setup SATA power request GPIO\n");
0155         goto err_free_2;
0156     }
0157 
0158     if (gpio_get_value(NET2BIG_GPIO_SATA0_POWER) &&
0159         gpio_get_value(NET2BIG_GPIO_SATA1_POWER)) {
0160         return;
0161     }
0162 
0163     /*
0164      * SATA power up on both disk is done by pulling high the CPLD power
0165      * request line. The 300ms delay is related to the CPLD clock and is
0166      * needed to be sure that the CPLD has take into account the low line
0167      * status.
0168      */
0169     msleep(300);
0170     gpio_set_value(NET2BIG_GPIO_SATA_POWER_REQ, 1);
0171     pr_info("net2big: power up SATA hard disks\n");
0172 
0173     return;
0174 
0175 err_free_2:
0176     gpio_free(NET2BIG_GPIO_SATA1_POWER);
0177 err_free_1:
0178     gpio_free(NET2BIG_GPIO_SATA0_POWER);
0179 
0180     return;
0181 }
0182 
0183 /*****************************************************************************
0184  * GPIO LEDs
0185  ****************************************************************************/
0186 
0187 /*
0188  * The power front LEDs (blue and red) and SATA red LEDs are controlled via a
0189  * single GPIO line and are compatible with the leds-gpio driver.
0190  *
0191  * The SATA blue LEDs have some hardware blink capabilities which are detailed
0192  * in the following array:
0193  *
0194  * SATAx blue LED | SATAx activity | LED state
0195  *                |                |
0196  *       0        |       0        |  blink (rate 300ms)
0197  *       1        |       0        |  off
0198  *       ?        |       1        |  on
0199  *
0200  * Notes: The blue and the red front LED's can't be on at the same time.
0201  *        Blue LED have priority.
0202  */
0203 
0204 #define NET2BIG_GPIO_PWR_RED_LED    6
0205 #define NET2BIG_GPIO_PWR_BLUE_LED   16
0206 #define NET2BIG_GPIO_PWR_LED_BLINK_STOP 7
0207 
0208 #define NET2BIG_GPIO_SATA0_RED_LED  11
0209 #define NET2BIG_GPIO_SATA1_RED_LED  10
0210 
0211 #define NET2BIG_GPIO_SATA0_BLUE_LED 17
0212 #define NET2BIG_GPIO_SATA1_BLUE_LED 13
0213 
0214 static struct gpio_led net2big_leds[] = {
0215     {
0216         .name = "net2big:red:power",
0217         .gpio = NET2BIG_GPIO_PWR_RED_LED,
0218     },
0219     {
0220         .name = "net2big:blue:power",
0221         .gpio = NET2BIG_GPIO_PWR_BLUE_LED,
0222     },
0223     {
0224         .name = "net2big:red:sata0",
0225         .gpio = NET2BIG_GPIO_SATA0_RED_LED,
0226     },
0227     {
0228         .name = "net2big:red:sata1",
0229         .gpio = NET2BIG_GPIO_SATA1_RED_LED,
0230     },
0231 };
0232 
0233 static struct gpio_led_platform_data net2big_led_data = {
0234     .num_leds = ARRAY_SIZE(net2big_leds),
0235     .leds = net2big_leds,
0236 };
0237 
0238 static struct platform_device net2big_gpio_leds = {
0239     .name           = "leds-gpio",
0240     .id             = -1,
0241     .dev            = {
0242         .platform_data  = &net2big_led_data,
0243     },
0244 };
0245 
0246 static void __init net2big_gpio_leds_init(void)
0247 {
0248     int err;
0249 
0250     /* Stop initial CPLD slow red/blue blinking on power LED. */
0251     err = gpio_request(NET2BIG_GPIO_PWR_LED_BLINK_STOP,
0252                "Power LED blink stop");
0253     if (err == 0) {
0254         err = gpio_direction_output(NET2BIG_GPIO_PWR_LED_BLINK_STOP, 1);
0255         if (err)
0256             gpio_free(NET2BIG_GPIO_PWR_LED_BLINK_STOP);
0257     }
0258     if (err)
0259         pr_err("net2big: failed to setup power LED blink GPIO\n");
0260 
0261     /*
0262      * Configure SATA0 and SATA1 blue LEDs to blink in relation with the
0263      * hard disk activity.
0264      */
0265     err = gpio_request(NET2BIG_GPIO_SATA0_BLUE_LED,
0266                "SATA0 blue LED control");
0267     if (err == 0) {
0268         err = gpio_direction_output(NET2BIG_GPIO_SATA0_BLUE_LED, 1);
0269         if (err)
0270             gpio_free(NET2BIG_GPIO_SATA0_BLUE_LED);
0271     }
0272     if (err)
0273         pr_err("net2big: failed to setup SATA0 blue LED GPIO\n");
0274 
0275     err = gpio_request(NET2BIG_GPIO_SATA1_BLUE_LED,
0276                "SATA1 blue LED control");
0277     if (err == 0) {
0278         err = gpio_direction_output(NET2BIG_GPIO_SATA1_BLUE_LED, 1);
0279         if (err)
0280             gpio_free(NET2BIG_GPIO_SATA1_BLUE_LED);
0281     }
0282     if (err)
0283         pr_err("net2big: failed to setup SATA1 blue LED GPIO\n");
0284 
0285     platform_device_register(&net2big_gpio_leds);
0286 }
0287 
0288 /****************************************************************************
0289  * GPIO keys
0290  ****************************************************************************/
0291 
0292 #define NET2BIG_GPIO_PUSH_BUTTON    18
0293 #define NET2BIG_GPIO_POWER_SWITCH_ON    8
0294 #define NET2BIG_GPIO_POWER_SWITCH_OFF   9
0295 
0296 #define NET2BIG_SWITCH_POWER_ON     0x1
0297 #define NET2BIG_SWITCH_POWER_OFF    0x2
0298 
0299 static struct gpio_keys_button net2big_buttons[] = {
0300     {
0301         .type       = EV_SW,
0302         .code       = NET2BIG_SWITCH_POWER_OFF,
0303         .gpio       = NET2BIG_GPIO_POWER_SWITCH_OFF,
0304         .desc       = "Power rocker switch (auto|off)",
0305         .active_low = 0,
0306     },
0307     {
0308         .type       = EV_SW,
0309         .code       = NET2BIG_SWITCH_POWER_ON,
0310         .gpio       = NET2BIG_GPIO_POWER_SWITCH_ON,
0311         .desc       = "Power rocker switch (on|auto)",
0312         .active_low = 0,
0313     },
0314     {
0315         .type       = EV_KEY,
0316         .code       = KEY_POWER,
0317         .gpio       = NET2BIG_GPIO_PUSH_BUTTON,
0318         .desc       = "Front Push Button",
0319         .active_low = 0,
0320     },
0321 };
0322 
0323 static struct gpio_keys_platform_data net2big_button_data = {
0324     .buttons    = net2big_buttons,
0325     .nbuttons   = ARRAY_SIZE(net2big_buttons),
0326 };
0327 
0328 static struct platform_device net2big_gpio_buttons = {
0329     .name       = "gpio-keys",
0330     .id     = -1,
0331     .dev        = {
0332         .platform_data  = &net2big_button_data,
0333     },
0334 };
0335 
0336 /*****************************************************************************
0337  * General Setup
0338  ****************************************************************************/
0339 
0340 static unsigned int net2big_mpp_modes[] __initdata = {
0341     MPP0_GPIO,  /* Raid mode (bit 0) */
0342     MPP1_GPIO,  /* USB port 2 fuse (0 = Fail, 1 = Ok) */
0343     MPP2_GPIO,  /* Raid mode (bit 1) */
0344     MPP3_GPIO,  /* Board ID (bit 0) */
0345     MPP4_GPIO,  /* Fan activity (0 = Off, 1 = On) */
0346     MPP5_GPIO,  /* Fan fail detection */
0347     MPP6_GPIO,  /* Red front LED (0 = Off, 1 = On) */
0348     MPP7_GPIO,  /* Disable initial blinking on front LED */
0349     MPP8_GPIO,  /* Rear power switch (on|auto) */
0350     MPP9_GPIO,  /* Rear power switch (auto|off) */
0351     MPP10_GPIO, /* SATA 1 red LED (0 = Off, 1 = On) */
0352     MPP11_GPIO, /* SATA 0 red LED (0 = Off, 1 = On) */
0353     MPP12_GPIO, /* Board ID (bit 1) */
0354     MPP13_GPIO, /* SATA 1 blue LED blink control */
0355     MPP14_SATA_LED,
0356     MPP15_SATA_LED,
0357     MPP16_GPIO, /* Blue front LED control */
0358     MPP17_GPIO, /* SATA 0 blue LED blink control */
0359     MPP18_GPIO, /* Front button (0 = Released, 1 = Pushed ) */
0360     MPP19_GPIO, /* SATA{0,1} power On/Off request */
0361     0,
0362     /* 22: USB port 1 fuse (0 = Fail, 1 = Ok) */
0363     /* 23: SATA 0 power status */
0364     /* 24: Board power off */
0365     /* 25: SATA 1 power status */
0366 };
0367 
0368 #define NET2BIG_GPIO_POWER_OFF      24
0369 
0370 static void net2big_power_off(void)
0371 {
0372     gpio_set_value(NET2BIG_GPIO_POWER_OFF, 1);
0373 }
0374 
0375 static void __init net2big_init(void)
0376 {
0377     /*
0378      * Setup basic Orion functions. Need to be called early.
0379      */
0380     orion5x_init();
0381 
0382     orion5x_mpp_conf(net2big_mpp_modes);
0383 
0384     /*
0385      * Configure peripherals.
0386      */
0387     orion5x_ehci0_init();
0388     orion5x_ehci1_init();
0389     orion5x_eth_init(&net2big_eth_data);
0390     orion5x_i2c_init();
0391     orion5x_uart0_init();
0392     orion5x_xor_init();
0393 
0394     net2big_sata_power_init();
0395     orion5x_sata_init(&net2big_sata_data);
0396 
0397     mvebu_mbus_add_window_by_id(ORION_MBUS_DEVBUS_BOOT_TARGET,
0398                     ORION_MBUS_DEVBUS_BOOT_ATTR,
0399                     NET2BIG_NOR_BOOT_BASE,
0400                     NET2BIG_NOR_BOOT_SIZE);
0401     platform_device_register(&net2big_nor_flash);
0402 
0403     platform_device_register(&net2big_gpio_buttons);
0404     net2big_gpio_leds_init();
0405 
0406     i2c_register_board_info(0, net2big_i2c_devices,
0407                 ARRAY_SIZE(net2big_i2c_devices));
0408 
0409     orion_gpio_set_valid(NET2BIG_GPIO_POWER_OFF, 1);
0410 
0411     if (gpio_request(NET2BIG_GPIO_POWER_OFF, "power-off") == 0 &&
0412         gpio_direction_output(NET2BIG_GPIO_POWER_OFF, 0) == 0)
0413         pm_power_off = net2big_power_off;
0414     else
0415         pr_err("net2big: failed to configure power-off GPIO\n");
0416 
0417     pr_notice("net2big: Flash writing is not yet supported.\n");
0418 }
0419 
0420 /* Warning: LaCie use a wrong mach-type (0x20e=526) in their bootloader. */
0421 MACHINE_START(NET2BIG, "LaCie 2Big Network")
0422     .atag_offset    = 0x100,
0423     .nr_irqs    = ORION5X_NR_IRQS,
0424     .init_machine   = net2big_init,
0425     .map_io     = orion5x_map_io,
0426     .init_early = orion5x_init_early,
0427     .init_irq   = orion5x_init_irq,
0428     .init_time  = orion5x_timer_init,
0429     .fixup      = tag_fixup_mem32,
0430     .restart    = orion5x_restart,
0431 MACHINE_END