xref: /rk3399_rockchip-uboot/board/LaCie/netspace_v2/netspace_v2.c (revision 9d86f0c30bd7e6a7f7a93bc7f12b69ef48a4de19)
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  *
979642098SSimon Guinot  * See file CREDITS for list of people who contributed to this
1079642098SSimon Guinot  * project.
1179642098SSimon Guinot  *
1279642098SSimon Guinot  * This program is free software; you can redistribute it and/or
1379642098SSimon Guinot  * modify it under the terms of the GNU General Public License as
1479642098SSimon Guinot  * published by the Free Software Foundation; either version 2 of
1579642098SSimon Guinot  * the License, or (at your option) any later version.
1679642098SSimon Guinot  *
1779642098SSimon Guinot  * This program is distributed in the hope that it will be useful,
1879642098SSimon Guinot  * but WITHOUT ANY WARRANTY; without even the implied warranty of
1979642098SSimon Guinot  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2079642098SSimon Guinot  * GNU General Public License for more details.
2179642098SSimon Guinot  */
2279642098SSimon Guinot 
2379642098SSimon Guinot #include <common.h>
2479642098SSimon Guinot #include <command.h>
25fc168cc5SAnatolij Gustschin #include <asm/arch/cpu.h>
2679642098SSimon Guinot #include <asm/arch/kirkwood.h>
2779642098SSimon Guinot #include <asm/arch/mpp.h>
2879642098SSimon Guinot #include <asm/arch/gpio.h>
2977ea071fSSimon Guinot 
3079642098SSimon Guinot #include "netspace_v2.h"
3177ea071fSSimon Guinot #include "../common/common.h"
3279642098SSimon Guinot 
3379642098SSimon Guinot DECLARE_GLOBAL_DATA_PTR;
3479642098SSimon Guinot 
3579642098SSimon Guinot int board_early_init_f(void)
3679642098SSimon Guinot {
3779642098SSimon Guinot 	/* Gpio configuration */
3879642098SSimon Guinot 	kw_config_gpio(NETSPACE_V2_OE_VAL_LOW, NETSPACE_V2_OE_VAL_HIGH,
3979642098SSimon Guinot 			NETSPACE_V2_OE_LOW, NETSPACE_V2_OE_HIGH);
4079642098SSimon Guinot 
4179642098SSimon Guinot 	/* Multi-Purpose Pins Functionality configuration */
42*9d86f0c3SAlbert ARIBAUD 	static const u32 kwmpp_config[] = {
4379642098SSimon Guinot 		MPP0_SPI_SCn,
4479642098SSimon Guinot 		MPP1_SPI_MOSI,
4579642098SSimon Guinot 		MPP2_SPI_SCK,
4679642098SSimon Guinot 		MPP3_SPI_MISO,
4779642098SSimon Guinot 		MPP4_NF_IO6,
4879642098SSimon Guinot 		MPP5_NF_IO7,
4979642098SSimon Guinot 		MPP6_SYSRST_OUTn,
5079642098SSimon Guinot 		MPP7_GPO,		/* Fan speed (bit 1) */
5179642098SSimon Guinot 		MPP8_TW_SDA,
5279642098SSimon Guinot 		MPP9_TW_SCK,
5379642098SSimon Guinot 		MPP10_UART0_TXD,
5479642098SSimon Guinot 		MPP11_UART0_RXD,
5579642098SSimon Guinot 		MPP12_GPO,		/* Red led */
5679642098SSimon Guinot 		MPP14_GPIO,		/* USB fuse */
5779642098SSimon Guinot 		MPP16_GPIO,		/* SATA 0 power */
5879642098SSimon Guinot 		MPP17_GPIO,		/* SATA 1 power */
5979642098SSimon Guinot 		MPP18_NF_IO0,
6079642098SSimon Guinot 		MPP19_NF_IO1,
6179642098SSimon Guinot 		MPP20_SATA1_ACTn,
6279642098SSimon Guinot 		MPP21_SATA0_ACTn,
6379642098SSimon Guinot 		MPP22_GPIO,		/* Fan speed (bit 0) */
6479642098SSimon Guinot 		MPP23_GPIO,		/* Fan power */
6579642098SSimon Guinot 		MPP24_GPIO,		/* USB mode select */
6679642098SSimon Guinot 		MPP25_GPIO,		/* Fan rotation fail */
6779642098SSimon Guinot 		MPP26_GPIO,		/* USB vbus-in detection */
6879642098SSimon Guinot 		MPP28_GPIO,		/* USB enable vbus-out */
6979642098SSimon Guinot 		MPP29_GPIO,		/* Blue led (slow register) */
7079642098SSimon Guinot 		MPP30_GPIO,		/* Blue led (command register) */
7179642098SSimon Guinot 		MPP31_GPIO,		/* Board power off */
7279642098SSimon Guinot 		MPP32_GPIO,		/* Button (0 = Released, 1 = Pushed) */
7379642098SSimon Guinot 		MPP33_GPIO,		/* Fan speed (bit 2) */
7479642098SSimon Guinot 		0
7579642098SSimon Guinot 	};
7684683638SValentin Longchamp 	kirkwood_mpp_conf(kwmpp_config, NULL);
7779642098SSimon Guinot 
7879642098SSimon Guinot 	return 0;
7979642098SSimon Guinot }
8079642098SSimon Guinot 
8179642098SSimon Guinot int board_init(void)
8279642098SSimon Guinot {
8379642098SSimon Guinot 	/* Machine number */
8479642098SSimon Guinot 	gd->bd->bi_arch_number = CONFIG_MACH_TYPE;
8579642098SSimon Guinot 
8679642098SSimon Guinot 	/* Boot parameters address */
8779642098SSimon Guinot 	gd->bd->bi_boot_params = kw_sdram_bar(0) + 0x100;
8879642098SSimon Guinot 
8979642098SSimon Guinot 	return 0;
9079642098SSimon Guinot }
9179642098SSimon Guinot 
9277ea071fSSimon Guinot #if defined(CONFIG_MISC_INIT_R)
930bfb66b6SSimon Guinot int misc_init_r(void)
940bfb66b6SSimon Guinot {
950bfb66b6SSimon Guinot #if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR)
960bfb66b6SSimon Guinot 	if (!getenv("ethaddr")) {
970bfb66b6SSimon Guinot 		uchar mac[6];
9877ea071fSSimon Guinot 		if (lacie_read_mac_address(mac) == 0)
990bfb66b6SSimon Guinot 			eth_setenv_enetaddr("ethaddr", mac);
1000bfb66b6SSimon Guinot 	}
10177ea071fSSimon Guinot #endif
1020bfb66b6SSimon Guinot 	return 0;
1030bfb66b6SSimon Guinot }
10477ea071fSSimon Guinot #endif
1050bfb66b6SSimon Guinot 
10677ea071fSSimon Guinot #if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R)
10779642098SSimon Guinot /* Configure and initialize PHY */
10879642098SSimon Guinot void reset_phy(void)
10979642098SSimon Guinot {
11037235496SSimon Guinot #if defined(CONFIG_NETSPACE_LITE_V2) || defined(CONFIG_NETSPACE_MINI_V2)
11137235496SSimon Guinot 	mv_phy_88e1318_init("egiga0", 0);
11237235496SSimon Guinot #else
113c59c0857SSimon Guinot 	mv_phy_88e1116_init("egiga0", 8);
11437235496SSimon Guinot #endif
11579642098SSimon Guinot }
11677ea071fSSimon Guinot #endif
11779642098SSimon Guinot 
11877ea071fSSimon Guinot #if defined(CONFIG_KIRKWOOD_GPIO)
11979642098SSimon Guinot /* Return GPIO button status */
12079642098SSimon Guinot static int
12179642098SSimon Guinot do_read_button(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
12279642098SSimon Guinot {
12379642098SSimon Guinot 	return kw_gpio_get_value(NETSPACE_V2_GPIO_BUTTON);
12479642098SSimon Guinot }
12579642098SSimon Guinot 
12679642098SSimon Guinot U_BOOT_CMD(button, 1, 1, do_read_button,
12779642098SSimon Guinot 	   "Return GPIO button status 0=off 1=on", "");
12877ea071fSSimon Guinot #endif
129