xref: /rk3399_rockchip-uboot/board/Seagate/dockstar/dockstar.c (revision 36aaa91850e96e384d184b9785b8da1fd7b63d8f)
138041db7SEric Cooper /*
238041db7SEric Cooper  * Copyright (C) 2010  Eric C. Cooper <ecc@cmu.edu>
338041db7SEric Cooper  *
438041db7SEric Cooper  * Based on sheevaplug.c originally written by
538041db7SEric Cooper  * Prafulla Wadaskar <prafulla@marvell.com>
638041db7SEric Cooper  * (C) Copyright 2009
738041db7SEric Cooper  * Marvell Semiconductor <www.marvell.com>
838041db7SEric Cooper  *
938041db7SEric Cooper  * See file CREDITS for list of people who contributed to this
1038041db7SEric Cooper  * project.
1138041db7SEric Cooper  *
1238041db7SEric Cooper  * This program is free software; you can redistribute it and/or
1338041db7SEric Cooper  * modify it under the terms of the GNU General Public License as
1438041db7SEric Cooper  * published by the Free Software Foundation; either version 2 of
1538041db7SEric Cooper  * the License, or (at your option) any later version.
1638041db7SEric Cooper  *
1738041db7SEric Cooper  * This program is distributed in the hope that it will be useful,
1838041db7SEric Cooper  * but WITHOUT ANY WARRANTY; without even the implied warranty of
1938041db7SEric Cooper  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2038041db7SEric Cooper  * GNU General Public License for more details.
2138041db7SEric Cooper  *
2238041db7SEric Cooper  * You should have received a copy of the GNU General Public License
2338041db7SEric Cooper  * along with this program; if not, write to the Free Software
2438041db7SEric Cooper  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
2538041db7SEric Cooper  * MA 02110-1301 USA
2638041db7SEric Cooper  */
2738041db7SEric Cooper 
2838041db7SEric Cooper #include <common.h>
2938041db7SEric Cooper #include <miiphy.h>
3038041db7SEric Cooper #include <asm/arch/kirkwood.h>
3138041db7SEric Cooper #include <asm/arch/mpp.h>
32*36aaa918SAnatolij Gustschin #include <asm/arch/cpu.h>
33*36aaa918SAnatolij Gustschin #include <asm/io.h>
3438041db7SEric Cooper #include "dockstar.h"
3538041db7SEric Cooper 
3638041db7SEric Cooper DECLARE_GLOBAL_DATA_PTR;
3738041db7SEric Cooper 
3838041db7SEric Cooper int board_early_init_f(void)
3938041db7SEric Cooper {
4038041db7SEric Cooper 	/*
4138041db7SEric Cooper 	 * default gpio configuration
4238041db7SEric Cooper 	 * There are maximum 64 gpios controlled through 2 sets of registers
4338041db7SEric Cooper 	 * the  below configuration configures mainly initial LED status
4438041db7SEric Cooper 	 */
4538041db7SEric Cooper 	kw_config_gpio(DOCKSTAR_OE_VAL_LOW,
4638041db7SEric Cooper 			DOCKSTAR_OE_VAL_HIGH,
4738041db7SEric Cooper 			DOCKSTAR_OE_LOW, DOCKSTAR_OE_HIGH);
4838041db7SEric Cooper 
4938041db7SEric Cooper 	/* Multi-Purpose Pins Functionality configuration */
5038041db7SEric Cooper 	u32 kwmpp_config[] = {
5138041db7SEric Cooper 		MPP0_NF_IO2,
5238041db7SEric Cooper 		MPP1_NF_IO3,
5338041db7SEric Cooper 		MPP2_NF_IO4,
5438041db7SEric Cooper 		MPP3_NF_IO5,
5538041db7SEric Cooper 		MPP4_NF_IO6,
5638041db7SEric Cooper 		MPP5_NF_IO7,
5738041db7SEric Cooper 		MPP6_SYSRST_OUTn,
5838041db7SEric Cooper 		MPP7_GPO,
5938041db7SEric Cooper 		MPP8_UART0_RTS,
6038041db7SEric Cooper 		MPP9_UART0_CTS,
6138041db7SEric Cooper 		MPP10_UART0_TXD,
6238041db7SEric Cooper 		MPP11_UART0_RXD,
6338041db7SEric Cooper 		MPP12_SD_CLK,
6438041db7SEric Cooper 		MPP13_SD_CMD,
6538041db7SEric Cooper 		MPP14_SD_D0,
6638041db7SEric Cooper 		MPP15_SD_D1,
6738041db7SEric Cooper 		MPP16_SD_D2,
6838041db7SEric Cooper 		MPP17_SD_D3,
6938041db7SEric Cooper 		MPP18_NF_IO0,
7038041db7SEric Cooper 		MPP19_NF_IO1,
7138041db7SEric Cooper 		MPP20_GPIO,
7238041db7SEric Cooper 		MPP21_GPIO,
7338041db7SEric Cooper 		MPP22_GPIO,
7438041db7SEric Cooper 		MPP23_GPIO,
7538041db7SEric Cooper 		MPP24_GPIO,
7638041db7SEric Cooper 		MPP25_GPIO,
7738041db7SEric Cooper 		MPP26_GPIO,
7838041db7SEric Cooper 		MPP27_GPIO,
7938041db7SEric Cooper 		MPP28_GPIO,
8038041db7SEric Cooper 		MPP29_TSMP9,
8138041db7SEric Cooper 		MPP30_GPIO,
8238041db7SEric Cooper 		MPP31_GPIO,
8338041db7SEric Cooper 		MPP32_GPIO,
8438041db7SEric Cooper 		MPP33_GPIO,
8538041db7SEric Cooper 		MPP34_GPIO,
8638041db7SEric Cooper 		MPP35_GPIO,
8738041db7SEric Cooper 		MPP36_GPIO,
8838041db7SEric Cooper 		MPP37_GPIO,
8938041db7SEric Cooper 		MPP38_GPIO,
9038041db7SEric Cooper 		MPP39_GPIO,
9138041db7SEric Cooper 		MPP40_GPIO,
9238041db7SEric Cooper 		MPP41_GPIO,
9338041db7SEric Cooper 		MPP42_GPIO,
9438041db7SEric Cooper 		MPP43_GPIO,
9538041db7SEric Cooper 		MPP44_GPIO,
9638041db7SEric Cooper 		MPP45_GPIO,
9738041db7SEric Cooper 		MPP46_GPIO,
9838041db7SEric Cooper 		MPP47_GPIO,
9938041db7SEric Cooper 		MPP48_GPIO,
10038041db7SEric Cooper 		MPP49_GPIO,
10138041db7SEric Cooper 		0
10238041db7SEric Cooper 	};
10338041db7SEric Cooper 	kirkwood_mpp_conf(kwmpp_config);
10438041db7SEric Cooper 	return 0;
10538041db7SEric Cooper }
10638041db7SEric Cooper 
10738041db7SEric Cooper int board_init(void)
10838041db7SEric Cooper {
10938041db7SEric Cooper 	/*
11038041db7SEric Cooper 	 * arch number of board
11138041db7SEric Cooper 	 */
11238041db7SEric Cooper 	gd->bd->bi_arch_number = MACH_TYPE_DOCKSTAR;
11338041db7SEric Cooper 
11438041db7SEric Cooper 	/* address of boot parameters */
11538041db7SEric Cooper 	gd->bd->bi_boot_params = kw_sdram_bar(0) + 0x100;
11638041db7SEric Cooper 
11738041db7SEric Cooper 	return 0;
11838041db7SEric Cooper }
11938041db7SEric Cooper 
12038041db7SEric Cooper #ifdef CONFIG_RESET_PHY_R
12138041db7SEric Cooper /* Configure and enable MV88E1116 PHY */
12238041db7SEric Cooper void reset_phy(void)
12338041db7SEric Cooper {
12438041db7SEric Cooper 	u16 reg;
12538041db7SEric Cooper 	u16 devadr;
12638041db7SEric Cooper 	char *name = "egiga0";
12738041db7SEric Cooper 
12838041db7SEric Cooper 	if (miiphy_set_current_dev(name))
12938041db7SEric Cooper 		return;
13038041db7SEric Cooper 
13138041db7SEric Cooper 	/* command to read PHY dev address */
13238041db7SEric Cooper 	if (miiphy_read(name, 0xEE, 0xEE, (u16 *) &devadr)) {
13338041db7SEric Cooper 		printf("Err..%s could not read PHY dev address\n",
13438041db7SEric Cooper 			__FUNCTION__);
13538041db7SEric Cooper 		return;
13638041db7SEric Cooper 	}
13738041db7SEric Cooper 
13838041db7SEric Cooper 	/*
13938041db7SEric Cooper 	 * Enable RGMII delay on Tx and Rx for CPU port
14038041db7SEric Cooper 	 * Ref: sec 4.7.2 of chip datasheet
14138041db7SEric Cooper 	 */
14238041db7SEric Cooper 	miiphy_write(name, devadr, MV88E1116_PGADR_REG, 2);
14338041db7SEric Cooper 	miiphy_read(name, devadr, MV88E1116_MAC_CTRL_REG, &reg);
14438041db7SEric Cooper 	reg |= (MV88E1116_RGMII_RXTM_CTRL | MV88E1116_RGMII_TXTM_CTRL);
14538041db7SEric Cooper 	miiphy_write(name, devadr, MV88E1116_MAC_CTRL_REG, reg);
14638041db7SEric Cooper 	miiphy_write(name, devadr, MV88E1116_PGADR_REG, 0);
14738041db7SEric Cooper 
14838041db7SEric Cooper 	/* reset the phy */
14938041db7SEric Cooper 	miiphy_reset(name, devadr);
15038041db7SEric Cooper 
15138041db7SEric Cooper 	printf("88E1116 Initialized on %s\n", name);
15238041db7SEric Cooper }
15338041db7SEric Cooper #endif /* CONFIG_RESET_PHY_R */
15438041db7SEric Cooper 
15538041db7SEric Cooper #define GREEN_LED	(1 << 14)
15638041db7SEric Cooper #define ORANGE_LED	(1 << 15)
15738041db7SEric Cooper #define BOTH_LEDS	(GREEN_LED | ORANGE_LED)
15838041db7SEric Cooper #define NEITHER_LED	0
15938041db7SEric Cooper 
16038041db7SEric Cooper static void set_leds(u32 leds, u32 blinking)
16138041db7SEric Cooper {
16238041db7SEric Cooper 	struct kwgpio_registers *r = (struct kwgpio_registers *)KW_GPIO1_BASE;
16338041db7SEric Cooper 	u32 oe = readl(&r->oe) | BOTH_LEDS;
16438041db7SEric Cooper 	writel(oe & ~leds, &r->oe);	/* active low */
16538041db7SEric Cooper 	u32 bl = readl(&r->blink_en) & ~BOTH_LEDS;
16638041db7SEric Cooper 	writel(bl | blinking, &r->blink_en);
16738041db7SEric Cooper }
16838041db7SEric Cooper 
16938041db7SEric Cooper void show_boot_progress(int val)
17038041db7SEric Cooper {
17138041db7SEric Cooper 	switch (val) {
17238041db7SEric Cooper 	case 15:		/* booting Linux */
17338041db7SEric Cooper 		set_leds(BOTH_LEDS, NEITHER_LED);
17438041db7SEric Cooper 		break;
17538041db7SEric Cooper 	case 64:		/* Ethernet initialization */
17638041db7SEric Cooper 		set_leds(GREEN_LED, GREEN_LED);
17738041db7SEric Cooper 		break;
17838041db7SEric Cooper 	default:
17938041db7SEric Cooper 		if (val < 0)	/* error */
18038041db7SEric Cooper 			set_leds(ORANGE_LED, ORANGE_LED);
18138041db7SEric Cooper 		break;
18238041db7SEric Cooper 	}
18338041db7SEric Cooper }
184