179642098SSimon Guinot /*
279642098SSimon Guinot * Copyright (C) 2011 Simon Guinot <sguinot@lacie.com>
379642098SSimon Guinot *
479642098SSimon Guinot * Based on Kirkwood support:
579642098SSimon Guinot * (C) Copyright 2009
679642098SSimon Guinot * Marvell Semiconductor <www.marvell.com>
779642098SSimon Guinot * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
879642098SSimon Guinot *
91a459660SWolfgang Denk * SPDX-License-Identifier: GPL-2.0+
1079642098SSimon Guinot */
1179642098SSimon Guinot
1279642098SSimon Guinot #include <common.h>
1379642098SSimon Guinot #include <command.h>
14c62db35dSSimon Glass #include <asm/mach-types.h>
15fc168cc5SAnatolij Gustschin #include <asm/arch/cpu.h>
163dc23f78SStefan Roese #include <asm/arch/soc.h>
1779642098SSimon Guinot #include <asm/arch/mpp.h>
1879642098SSimon Guinot #include <asm/arch/gpio.h>
1977ea071fSSimon Guinot
2079642098SSimon Guinot #include "netspace_v2.h"
2177ea071fSSimon Guinot #include "../common/common.h"
2279642098SSimon Guinot
2379642098SSimon Guinot DECLARE_GLOBAL_DATA_PTR;
2479642098SSimon Guinot
board_early_init_f(void)2579642098SSimon Guinot int board_early_init_f(void)
2679642098SSimon Guinot {
2779642098SSimon Guinot /* Gpio configuration */
28d5c5132fSStefan Roese mvebu_config_gpio(NETSPACE_V2_OE_VAL_LOW, NETSPACE_V2_OE_VAL_HIGH,
2979642098SSimon Guinot NETSPACE_V2_OE_LOW, NETSPACE_V2_OE_HIGH);
3079642098SSimon Guinot
3179642098SSimon Guinot /* Multi-Purpose Pins Functionality configuration */
329d86f0c3SAlbert ARIBAUD static const u32 kwmpp_config[] = {
3379642098SSimon Guinot MPP0_SPI_SCn,
3479642098SSimon Guinot MPP1_SPI_MOSI,
3579642098SSimon Guinot MPP2_SPI_SCK,
3679642098SSimon Guinot MPP3_SPI_MISO,
3779642098SSimon Guinot MPP4_NF_IO6,
3879642098SSimon Guinot MPP5_NF_IO7,
3979642098SSimon Guinot MPP6_SYSRST_OUTn,
4079642098SSimon Guinot MPP7_GPO, /* Fan speed (bit 1) */
4179642098SSimon Guinot MPP8_TW_SDA,
4279642098SSimon Guinot MPP9_TW_SCK,
4379642098SSimon Guinot MPP10_UART0_TXD,
4479642098SSimon Guinot MPP11_UART0_RXD,
4579642098SSimon Guinot MPP12_GPO, /* Red led */
4679642098SSimon Guinot MPP14_GPIO, /* USB fuse */
4779642098SSimon Guinot MPP16_GPIO, /* SATA 0 power */
4879642098SSimon Guinot MPP17_GPIO, /* SATA 1 power */
4979642098SSimon Guinot MPP18_NF_IO0,
5079642098SSimon Guinot MPP19_NF_IO1,
5179642098SSimon Guinot MPP20_SATA1_ACTn,
5279642098SSimon Guinot MPP21_SATA0_ACTn,
5379642098SSimon Guinot MPP22_GPIO, /* Fan speed (bit 0) */
5479642098SSimon Guinot MPP23_GPIO, /* Fan power */
5579642098SSimon Guinot MPP24_GPIO, /* USB mode select */
5679642098SSimon Guinot MPP25_GPIO, /* Fan rotation fail */
5779642098SSimon Guinot MPP26_GPIO, /* USB vbus-in detection */
5879642098SSimon Guinot MPP28_GPIO, /* USB enable vbus-out */
5979642098SSimon Guinot MPP29_GPIO, /* Blue led (slow register) */
6079642098SSimon Guinot MPP30_GPIO, /* Blue led (command register) */
6179642098SSimon Guinot MPP31_GPIO, /* Board power off */
6279642098SSimon Guinot MPP32_GPIO, /* Button (0 = Released, 1 = Pushed) */
6379642098SSimon Guinot MPP33_GPIO, /* Fan speed (bit 2) */
6479642098SSimon Guinot 0
6579642098SSimon Guinot };
6684683638SValentin Longchamp kirkwood_mpp_conf(kwmpp_config, NULL);
6779642098SSimon Guinot
6879642098SSimon Guinot return 0;
6979642098SSimon Guinot }
7079642098SSimon Guinot
board_init(void)7179642098SSimon Guinot int board_init(void)
7279642098SSimon Guinot {
7379642098SSimon Guinot /* Machine number */
7479642098SSimon Guinot gd->bd->bi_arch_number = CONFIG_MACH_TYPE;
7579642098SSimon Guinot
7679642098SSimon Guinot /* Boot parameters address */
7796c5f081SStefan Roese gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
7879642098SSimon Guinot
7979642098SSimon Guinot return 0;
8079642098SSimon Guinot }
8179642098SSimon Guinot
8277ea071fSSimon Guinot #if defined(CONFIG_MISC_INIT_R)
misc_init_r(void)830bfb66b6SSimon Guinot int misc_init_r(void)
840bfb66b6SSimon Guinot {
850bfb66b6SSimon Guinot #if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR)
86*00caae6dSSimon Glass if (!env_get("ethaddr")) {
870bfb66b6SSimon Guinot uchar mac[6];
8877ea071fSSimon Guinot if (lacie_read_mac_address(mac) == 0)
89fd1e959eSSimon Glass eth_env_set_enetaddr("ethaddr", mac);
900bfb66b6SSimon Guinot }
9177ea071fSSimon Guinot #endif
920bfb66b6SSimon Guinot return 0;
930bfb66b6SSimon Guinot }
9477ea071fSSimon Guinot #endif
950bfb66b6SSimon Guinot
9677ea071fSSimon Guinot #if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R)
9779642098SSimon Guinot /* Configure and initialize PHY */
reset_phy(void)9879642098SSimon Guinot void reset_phy(void)
9979642098SSimon Guinot {
10037235496SSimon Guinot #if defined(CONFIG_NETSPACE_LITE_V2) || defined(CONFIG_NETSPACE_MINI_V2)
10137235496SSimon Guinot mv_phy_88e1318_init("egiga0", 0);
10237235496SSimon Guinot #else
103c59c0857SSimon Guinot mv_phy_88e1116_init("egiga0", 8);
10437235496SSimon Guinot #endif
10579642098SSimon Guinot }
10677ea071fSSimon Guinot #endif
10779642098SSimon Guinot
10877ea071fSSimon Guinot #if defined(CONFIG_KIRKWOOD_GPIO)
10979642098SSimon Guinot /* Return GPIO button status */
11079642098SSimon Guinot static int
do_read_button(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])11179642098SSimon Guinot do_read_button(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
11279642098SSimon Guinot {
11379642098SSimon Guinot return kw_gpio_get_value(NETSPACE_V2_GPIO_BUTTON);
11479642098SSimon Guinot }
11579642098SSimon Guinot
11679642098SSimon Guinot U_BOOT_CMD(button, 1, 1, do_read_button,
11779642098SSimon Guinot "Return GPIO button status 0=off 1=on", "");
11877ea071fSSimon Guinot #endif
119