xref: /rk3399_rockchip-uboot/board/LaCie/net2big_v2/net2big_v2.c (revision 00caae6d47645e68d6e5277aceb69592b49381a6)
15628fb75SSimon Guinot /*
25628fb75SSimon Guinot  * Copyright (C) 2011 Simon Guinot <sguinot@lacie.com>
35628fb75SSimon Guinot  *
45628fb75SSimon Guinot  * Based on Kirkwood support:
55628fb75SSimon Guinot  * (C) Copyright 2009
65628fb75SSimon Guinot  * Marvell Semiconductor <www.marvell.com>
75628fb75SSimon Guinot  * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
85628fb75SSimon Guinot  *
91a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
105628fb75SSimon Guinot  */
115628fb75SSimon Guinot 
125628fb75SSimon Guinot #include <common.h>
135628fb75SSimon Guinot #include <command.h>
142af4d0f4SSimon Guinot #include <i2c.h>
15c62db35dSSimon Glass #include <asm/mach-types.h>
165628fb75SSimon Guinot #include <asm/arch/cpu.h>
173dc23f78SStefan Roese #include <asm/arch/soc.h>
185628fb75SSimon Guinot #include <asm/arch/mpp.h>
195628fb75SSimon Guinot #include <asm/arch/gpio.h>
2077ea071fSSimon Guinot 
215628fb75SSimon Guinot #include "net2big_v2.h"
2277ea071fSSimon Guinot #include "../common/common.h"
237737c994SSimon Guinot #include "../common/cpld-gpio-bus.h"
245628fb75SSimon Guinot 
255628fb75SSimon Guinot DECLARE_GLOBAL_DATA_PTR;
265628fb75SSimon Guinot 
board_early_init_f(void)275628fb75SSimon Guinot int board_early_init_f(void)
285628fb75SSimon Guinot {
295628fb75SSimon Guinot 	/* GPIO configuration */
30d5c5132fSStefan Roese 	mvebu_config_gpio(NET2BIG_V2_OE_VAL_LOW, NET2BIG_V2_OE_VAL_HIGH,
315628fb75SSimon Guinot 			  NET2BIG_V2_OE_LOW, NET2BIG_V2_OE_HIGH);
325628fb75SSimon Guinot 
335628fb75SSimon Guinot 	/* Multi-Purpose Pins Functionality configuration */
349d86f0c3SAlbert ARIBAUD 	static const u32 kwmpp_config[] = {
355628fb75SSimon Guinot 		MPP0_SPI_SCn,
365628fb75SSimon Guinot 		MPP1_SPI_MOSI,
375628fb75SSimon Guinot 		MPP2_SPI_SCK,
385628fb75SSimon Guinot 		MPP3_SPI_MISO,
395628fb75SSimon Guinot 		MPP6_SYSRST_OUTn,
405628fb75SSimon Guinot 		MPP7_GPO,		/* Request power-off */
415628fb75SSimon Guinot 		MPP8_TW_SDA,
425628fb75SSimon Guinot 		MPP9_TW_SCK,
435628fb75SSimon Guinot 		MPP10_UART0_TXD,
445628fb75SSimon Guinot 		MPP11_UART0_RXD,
455628fb75SSimon Guinot 		MPP13_GPIO,		/* Rear power switch (on|auto) */
465628fb75SSimon Guinot 		MPP14_GPIO,		/* USB fuse alarm */
475628fb75SSimon Guinot 		MPP15_GPIO,		/* Rear power switch (auto|off) */
485628fb75SSimon Guinot 		MPP16_GPIO,		/* SATA HDD1 power */
495628fb75SSimon Guinot 		MPP17_GPIO,		/* SATA HDD2 power */
505628fb75SSimon Guinot 		MPP20_SATA1_ACTn,
515628fb75SSimon Guinot 		MPP21_SATA0_ACTn,
525628fb75SSimon Guinot 		MPP24_GPIO,		/* USB mode select */
535628fb75SSimon Guinot 		MPP26_GPIO,		/* USB device vbus */
545628fb75SSimon Guinot 		MPP28_GPIO,		/* USB enable host vbus */
557737c994SSimon Guinot 		MPP29_GPIO,		/* CPLD GPIO bus ALE */
565628fb75SSimon Guinot 		MPP34_GPIO,		/* Rear Push button 0=on 1=off */
575628fb75SSimon Guinot 		MPP35_GPIO,		/* Inhibit switch power-off */
585628fb75SSimon Guinot 		MPP36_GPIO,		/* SATA HDD1 presence */
595628fb75SSimon Guinot 		MPP37_GPIO,		/* SATA HDD2 presence */
605628fb75SSimon Guinot 		MPP40_GPIO,		/* eSATA presence */
617737c994SSimon Guinot 		MPP44_GPIO,		/* CPLD GPIO bus (data 0) */
627737c994SSimon Guinot 		MPP45_GPIO,		/* CPLD GPIO bus (data 1) */
637737c994SSimon Guinot 		MPP46_GPIO,		/* CPLD GPIO bus (data 2) */
647737c994SSimon Guinot 		MPP47_GPIO,		/* CPLD GPIO bus (addr 0) */
657737c994SSimon Guinot 		MPP48_GPIO,		/* CPLD GPIO bus (addr 1) */
667737c994SSimon Guinot 		MPP49_GPIO,		/* CPLD GPIO bus (addr 2) */
675628fb75SSimon Guinot 		0
685628fb75SSimon Guinot 	};
695628fb75SSimon Guinot 
7084683638SValentin Longchamp 	kirkwood_mpp_conf(kwmpp_config, NULL);
715628fb75SSimon Guinot 
725628fb75SSimon Guinot 	return 0;
735628fb75SSimon Guinot }
745628fb75SSimon Guinot 
board_init(void)755628fb75SSimon Guinot int board_init(void)
765628fb75SSimon Guinot {
775628fb75SSimon Guinot 	/* Machine number */
785628fb75SSimon Guinot 	gd->bd->bi_arch_number = MACH_TYPE_NET2BIG_V2;
795628fb75SSimon Guinot 
805628fb75SSimon Guinot 	/* Boot parameters address */
8196c5f081SStefan Roese 	gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
825628fb75SSimon Guinot 
835628fb75SSimon Guinot 	return 0;
845628fb75SSimon Guinot }
855628fb75SSimon Guinot 
8677ea071fSSimon Guinot #if defined(CONFIG_MISC_INIT_R)
872af4d0f4SSimon Guinot 
882af4d0f4SSimon Guinot #if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_G762_ADDR)
892af4d0f4SSimon Guinot /*
902af4d0f4SSimon Guinot  * Start I2C fan (GMT G762 controller)
912af4d0f4SSimon Guinot  */
init_fan(void)922af4d0f4SSimon Guinot static void init_fan(void)
932af4d0f4SSimon Guinot {
942af4d0f4SSimon Guinot 	u8 data;
952af4d0f4SSimon Guinot 
962af4d0f4SSimon Guinot 	i2c_set_bus_num(0);
972af4d0f4SSimon Guinot 
982af4d0f4SSimon Guinot 	/* Enable open-loop and PWM modes */
992af4d0f4SSimon Guinot 	data = 0x20;
1002af4d0f4SSimon Guinot 	if (i2c_write(CONFIG_SYS_I2C_G762_ADDR,
1012af4d0f4SSimon Guinot 		      G762_REG_FAN_CMD1, 1, &data, 1) != 0)
1022af4d0f4SSimon Guinot 		goto err;
1032af4d0f4SSimon Guinot 	data = 0;
1042af4d0f4SSimon Guinot 	if (i2c_write(CONFIG_SYS_I2C_G762_ADDR,
1052af4d0f4SSimon Guinot 		      G762_REG_SET_CNT, 1, &data, 1) != 0)
1062af4d0f4SSimon Guinot 		goto err;
1072af4d0f4SSimon Guinot 	/*
1082af4d0f4SSimon Guinot 	 * RPM to PWM (set_out register) fan speed conversion array:
1092af4d0f4SSimon Guinot 	 * 0    0x00
1102af4d0f4SSimon Guinot 	 * 1500	0x04
1112af4d0f4SSimon Guinot 	 * 2800	0x08
1122af4d0f4SSimon Guinot 	 * 3400	0x0C
1132af4d0f4SSimon Guinot 	 * 3700	0x10
1142af4d0f4SSimon Guinot 	 * 4400	0x20
1152af4d0f4SSimon Guinot 	 * 4700	0x30
1162af4d0f4SSimon Guinot 	 * 4800	0x50
1172af4d0f4SSimon Guinot 	 * 5200	0x80
1182af4d0f4SSimon Guinot 	 * 5400	0xC0
1192af4d0f4SSimon Guinot 	 * 5500	0xFF
1202af4d0f4SSimon Guinot 	 *
1212af4d0f4SSimon Guinot 	 * Start fan at low speed (2800 RPM):
1222af4d0f4SSimon Guinot 	 */
1232af4d0f4SSimon Guinot 	data = 0x08;
1242af4d0f4SSimon Guinot 	if (i2c_write(CONFIG_SYS_I2C_G762_ADDR,
1252af4d0f4SSimon Guinot 		      G762_REG_SET_OUT, 1, &data, 1) != 0)
1262af4d0f4SSimon Guinot 		goto err;
1272af4d0f4SSimon Guinot 
1282af4d0f4SSimon Guinot 	return;
1292af4d0f4SSimon Guinot err:
1302af4d0f4SSimon Guinot 	printf("Error: failed to start I2C fan @%02x\n",
1312af4d0f4SSimon Guinot 	       CONFIG_SYS_I2C_G762_ADDR);
1322af4d0f4SSimon Guinot }
1332af4d0f4SSimon Guinot #else
init_fan(void)1342af4d0f4SSimon Guinot static void init_fan(void) {}
1352af4d0f4SSimon Guinot #endif /* CONFIG_CMD_I2C && CONFIG_SYS_I2C_G762_ADDR */
1362af4d0f4SSimon Guinot 
1377737c994SSimon Guinot #if defined(CONFIG_NET2BIG_V2) && defined(CONFIG_KIRKWOOD_GPIO)
1387737c994SSimon Guinot /*
1397737c994SSimon Guinot  * CPLD GPIO bus:
1407737c994SSimon Guinot  *
1417737c994SSimon Guinot  * - address register : bit [0-2] -> GPIO [47-49]
1427737c994SSimon Guinot  * - data register    : bit [0-2] -> GPIO [44-46]
1437737c994SSimon Guinot  * - enable register  : GPIO 29
1447737c994SSimon Guinot  */
1457737c994SSimon Guinot static unsigned cpld_gpio_bus_addr[] = { 47, 48, 49 };
1467737c994SSimon Guinot static unsigned cpld_gpio_bus_data[] = { 44, 45, 46 };
1477737c994SSimon Guinot 
1487737c994SSimon Guinot static struct cpld_gpio_bus cpld_gpio_bus = {
1497737c994SSimon Guinot 	.addr		= cpld_gpio_bus_addr,
1507737c994SSimon Guinot 	.num_addr	= ARRAY_SIZE(cpld_gpio_bus_addr),
1517737c994SSimon Guinot 	.data		= cpld_gpio_bus_data,
1527737c994SSimon Guinot 	.num_data	= ARRAY_SIZE(cpld_gpio_bus_data),
1537737c994SSimon Guinot 	.enable		= 29,
1547737c994SSimon Guinot };
1557737c994SSimon Guinot 
1567737c994SSimon Guinot /*
1577737c994SSimon Guinot  * LEDs configuration:
1587737c994SSimon Guinot  *
1597737c994SSimon Guinot  * The LEDs are controlled by a CPLD and can be configured through
1607737c994SSimon Guinot  * the CPLD GPIO bus.
1617737c994SSimon Guinot  *
1627737c994SSimon Guinot  * Address register selection:
1637737c994SSimon Guinot  *
1647737c994SSimon Guinot  * addr | register
1657737c994SSimon Guinot  * ----------------------------
1667737c994SSimon Guinot  *   0  | front LED
1677737c994SSimon Guinot  *   1  | front LED brightness
1687737c994SSimon Guinot  *   2  | SATA LED brightness
1697737c994SSimon Guinot  *   3  | SATA0 LED
1707737c994SSimon Guinot  *   4  | SATA1 LED
1717737c994SSimon Guinot  *   5  | SATA2 LED
1727737c994SSimon Guinot  *   6  | SATA3 LED
1737737c994SSimon Guinot  *   7  | SATA4 LED
1747737c994SSimon Guinot  *
1757737c994SSimon Guinot  * Data register configuration:
1767737c994SSimon Guinot  *
1777737c994SSimon Guinot  * data | LED brightness
1787737c994SSimon Guinot  * -------------------------------------------------
1797737c994SSimon Guinot  *   0  | min (off)
1807737c994SSimon Guinot  *   -  | -
1817737c994SSimon Guinot  *   7  | max
1827737c994SSimon Guinot  *
1837737c994SSimon Guinot  * data | front LED mode
1847737c994SSimon Guinot  * -------------------------------------------------
1857737c994SSimon Guinot  *   0  | fix off
1867737c994SSimon Guinot  *   1  | fix blue on
1877737c994SSimon Guinot  *   2  | fix red on
1887737c994SSimon Guinot  *   3  | blink blue on=1 sec and blue off=1 sec
1897737c994SSimon Guinot  *   4  | blink red on=1 sec and red off=1 sec
1907737c994SSimon Guinot  *   5  | blink blue on=2.5 sec and red on=0.5 sec
1917737c994SSimon Guinot  *   6  | blink blue on=1 sec and red on=1 sec
1927737c994SSimon Guinot  *   7  | blink blue on=0.5 sec and blue off=2.5 sec
1937737c994SSimon Guinot  *
1947737c994SSimon Guinot  * data | SATA LED mode
1957737c994SSimon Guinot  * -------------------------------------------------
1967737c994SSimon Guinot  *   0  | fix off
1977737c994SSimon Guinot  *   1  | SATA activity blink
1987737c994SSimon Guinot  *   2  | fix red on
1997737c994SSimon Guinot  *   3  | blink blue on=1 sec and blue off=1 sec
2007737c994SSimon Guinot  *   4  | blink red on=1 sec and red off=1 sec
2017737c994SSimon Guinot  *   5  | blink blue on=2.5 sec and red on=0.5 sec
2027737c994SSimon Guinot  *   6  | blink blue on=1 sec and red on=1 sec
2037737c994SSimon Guinot  *   7  | fix blue on
2047737c994SSimon Guinot  */
init_leds(void)2057737c994SSimon Guinot static void init_leds(void)
2067737c994SSimon Guinot {
2077737c994SSimon Guinot 	/* Enable the front blue LED */
2087737c994SSimon Guinot 	cpld_gpio_bus_write(&cpld_gpio_bus, 0, 1);
2097737c994SSimon Guinot 	cpld_gpio_bus_write(&cpld_gpio_bus, 1, 3);
2107737c994SSimon Guinot 
2117737c994SSimon Guinot 	/* Configure SATA LEDs to blink in relation with the SATA activity */
2127737c994SSimon Guinot 	cpld_gpio_bus_write(&cpld_gpio_bus, 3, 1);
2137737c994SSimon Guinot 	cpld_gpio_bus_write(&cpld_gpio_bus, 4, 1);
2147737c994SSimon Guinot 	cpld_gpio_bus_write(&cpld_gpio_bus, 2, 3);
2157737c994SSimon Guinot }
2167737c994SSimon Guinot #else
init_leds(void)2177737c994SSimon Guinot static void init_leds(void) {}
2187737c994SSimon Guinot #endif /* CONFIG_NET2BIG_V2 && CONFIG_KIRKWOOD_GPIO */
2197737c994SSimon Guinot 
misc_init_r(void)2205628fb75SSimon Guinot int misc_init_r(void)
2215628fb75SSimon Guinot {
2222af4d0f4SSimon Guinot 	init_fan();
22377ea071fSSimon Guinot #if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR)
224*00caae6dSSimon Glass 	if (!env_get("ethaddr")) {
2255628fb75SSimon Guinot 		uchar mac[6];
22677ea071fSSimon Guinot 		if (lacie_read_mac_address(mac) == 0)
227fd1e959eSSimon Glass 			eth_env_set_enetaddr("ethaddr", mac);
2285628fb75SSimon Guinot 	}
22977ea071fSSimon Guinot #endif
2307737c994SSimon Guinot 	init_leds();
2317737c994SSimon Guinot 
2325628fb75SSimon Guinot 	return 0;
2335628fb75SSimon Guinot }
2342af4d0f4SSimon Guinot #endif /* CONFIG_MISC_INIT_R */
2355628fb75SSimon Guinot 
23677ea071fSSimon Guinot #if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R)
2375628fb75SSimon Guinot /* Configure and initialize PHY */
reset_phy(void)2385628fb75SSimon Guinot void reset_phy(void)
2395628fb75SSimon Guinot {
240c59c0857SSimon Guinot 	mv_phy_88e1116_init("egiga0", 8);
2415628fb75SSimon Guinot }
24277ea071fSSimon Guinot #endif
2435628fb75SSimon Guinot 
24477ea071fSSimon Guinot #if defined(CONFIG_KIRKWOOD_GPIO)
2455628fb75SSimon Guinot /* Return GPIO push button status */
2465628fb75SSimon Guinot static int
do_read_push_button(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])2475628fb75SSimon Guinot do_read_push_button(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
2485628fb75SSimon Guinot {
2495628fb75SSimon Guinot 	return !kw_gpio_get_value(NET2BIG_V2_GPIO_PUSH_BUTTON);
2505628fb75SSimon Guinot }
2515628fb75SSimon Guinot 
2525628fb75SSimon Guinot U_BOOT_CMD(button, 1, 1, do_read_push_button,
2535628fb75SSimon Guinot 	   "Return GPIO push button status 0=off 1=on", "");
25477ea071fSSimon Guinot #endif
255