1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
216b76705SSiddarth Gore /*
316b76705SSiddarth Gore  * (C) Copyright 2009
416b76705SSiddarth Gore  * Marvell Semiconductor <www.marvell.com>
516b76705SSiddarth Gore  * Written-by: Siddarth Gore <gores@marvell.com>
616b76705SSiddarth Gore  */
716b76705SSiddarth Gore 
816b76705SSiddarth Gore #include <common.h>
916b76705SSiddarth Gore #include <miiphy.h>
10c62db35dSSimon Glass #include <asm/mach-types.h>
11a7efd719SLei Wen #include <asm/arch/cpu.h>
123dc23f78SStefan Roese #include <asm/arch/soc.h>
1316b76705SSiddarth Gore #include <asm/arch/mpp.h>
1416b76705SSiddarth Gore #include "guruplug.h"
1516b76705SSiddarth Gore 
1616b76705SSiddarth Gore DECLARE_GLOBAL_DATA_PTR;
1716b76705SSiddarth Gore 
board_early_init_f(void)18754ae3fbSPrafulla Wadaskar int board_early_init_f(void)
1916b76705SSiddarth Gore {
2016b76705SSiddarth Gore 	/*
2116b76705SSiddarth Gore 	 * default gpio configuration
2216b76705SSiddarth Gore 	 * There are maximum 64 gpios controlled through 2 sets of registers
2316b76705SSiddarth Gore 	 * the  below configuration configures mainly initial LED status
2416b76705SSiddarth Gore 	 */
25d5c5132fSStefan Roese 	mvebu_config_gpio(GURUPLUG_OE_VAL_LOW,
2616b76705SSiddarth Gore 			  GURUPLUG_OE_VAL_HIGH,
2716b76705SSiddarth Gore 			  GURUPLUG_OE_LOW, GURUPLUG_OE_HIGH);
2816b76705SSiddarth Gore 
2916b76705SSiddarth Gore 	/* Multi-Purpose Pins Functionality configuration */
309d86f0c3SAlbert ARIBAUD 	static const u32 kwmpp_config[] = {
3116b76705SSiddarth Gore 		MPP0_NF_IO2,
3216b76705SSiddarth Gore 		MPP1_NF_IO3,
3316b76705SSiddarth Gore 		MPP2_NF_IO4,
3416b76705SSiddarth Gore 		MPP3_NF_IO5,
3516b76705SSiddarth Gore 		MPP4_NF_IO6,
3616b76705SSiddarth Gore 		MPP5_NF_IO7,
3716b76705SSiddarth Gore 		MPP6_SYSRST_OUTn,
3816b76705SSiddarth Gore 		MPP7_GPO,	/* GPIO_RST */
3916b76705SSiddarth Gore 		MPP8_TW_SDA,
4016b76705SSiddarth Gore 		MPP9_TW_SCK,
4116b76705SSiddarth Gore 		MPP10_UART0_TXD,
4216b76705SSiddarth Gore 		MPP11_UART0_RXD,
4316b76705SSiddarth Gore 		MPP12_SD_CLK,
4416b76705SSiddarth Gore 		MPP13_SD_CMD,
4516b76705SSiddarth Gore 		MPP14_SD_D0,
4616b76705SSiddarth Gore 		MPP15_SD_D1,
4716b76705SSiddarth Gore 		MPP16_SD_D2,
4816b76705SSiddarth Gore 		MPP17_SD_D3,
4916b76705SSiddarth Gore 		MPP18_NF_IO0,
5016b76705SSiddarth Gore 		MPP19_NF_IO1,
5116b76705SSiddarth Gore 		MPP20_GE1_0,
5216b76705SSiddarth Gore 		MPP21_GE1_1,
5316b76705SSiddarth Gore 		MPP22_GE1_2,
5416b76705SSiddarth Gore 		MPP23_GE1_3,
5516b76705SSiddarth Gore 		MPP24_GE1_4,
5616b76705SSiddarth Gore 		MPP25_GE1_5,
5716b76705SSiddarth Gore 		MPP26_GE1_6,
5816b76705SSiddarth Gore 		MPP27_GE1_7,
5916b76705SSiddarth Gore 		MPP28_GE1_8,
6016b76705SSiddarth Gore 		MPP29_GE1_9,
6116b76705SSiddarth Gore 		MPP30_GE1_10,
6216b76705SSiddarth Gore 		MPP31_GE1_11,
6316b76705SSiddarth Gore 		MPP32_GE1_12,
6416b76705SSiddarth Gore 		MPP33_GE1_13,
6516b76705SSiddarth Gore 		MPP34_GE1_14,
6616b76705SSiddarth Gore 		MPP35_GE1_15,
6716b76705SSiddarth Gore 		MPP36_GPIO,
6816b76705SSiddarth Gore 		MPP37_GPIO,
6916b76705SSiddarth Gore 		MPP38_GPIO,
7016b76705SSiddarth Gore 		MPP39_GPIO,
7116b76705SSiddarth Gore 		MPP40_TDM_SPI_SCK,
7216b76705SSiddarth Gore 		MPP41_TDM_SPI_MISO,
7316b76705SSiddarth Gore 		MPP42_TDM_SPI_MOSI,
7416b76705SSiddarth Gore 		MPP43_GPIO,
7516b76705SSiddarth Gore 		MPP44_GPIO,
7616b76705SSiddarth Gore 		MPP45_GPIO,
7716b76705SSiddarth Gore 		MPP46_GPIO, 	/* M_RLED */
7816b76705SSiddarth Gore 		MPP47_GPIO,	/* M_GLED */
7916b76705SSiddarth Gore 		MPP48_GPIO,	/* B_RLED */
8016b76705SSiddarth Gore 		MPP49_GPIO,	/* B_GLED */
8116b76705SSiddarth Gore 		0
8216b76705SSiddarth Gore 	};
8384683638SValentin Longchamp 	kirkwood_mpp_conf(kwmpp_config, NULL);
84754ae3fbSPrafulla Wadaskar 	return 0;
85754ae3fbSPrafulla Wadaskar }
8616b76705SSiddarth Gore 
board_init(void)87754ae3fbSPrafulla Wadaskar int board_init(void)
88754ae3fbSPrafulla Wadaskar {
8916b76705SSiddarth Gore 	/*
9016b76705SSiddarth Gore 	 * arch number of board
9116b76705SSiddarth Gore 	 */
9216b76705SSiddarth Gore 	gd->bd->bi_arch_number = MACH_TYPE_GURUPLUG;
9316b76705SSiddarth Gore 
9416b76705SSiddarth Gore 	/* adress of boot parameters */
9596c5f081SStefan Roese 	gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
9616b76705SSiddarth Gore 
9716b76705SSiddarth Gore 	return 0;
9816b76705SSiddarth Gore }
9916b76705SSiddarth Gore 
10016b76705SSiddarth Gore #ifdef CONFIG_RESET_PHY_R
mv_phy_88e1121_init(char * name)10116b76705SSiddarth Gore void mv_phy_88e1121_init(char *name)
10216b76705SSiddarth Gore {
10316b76705SSiddarth Gore 	u16 reg;
10416b76705SSiddarth Gore 	u16 devadr;
10516b76705SSiddarth Gore 
10616b76705SSiddarth Gore 	if (miiphy_set_current_dev(name))
10716b76705SSiddarth Gore 		return;
10816b76705SSiddarth Gore 
10916b76705SSiddarth Gore 	/* command to read PHY dev address */
11016b76705SSiddarth Gore 	if (miiphy_read(name, 0xEE, 0xEE, (u16 *) &devadr)) {
11116b76705SSiddarth Gore 		printf("Err..%s could not read PHY dev address\n",
11216b76705SSiddarth Gore 			__FUNCTION__);
11316b76705SSiddarth Gore 		return;
11416b76705SSiddarth Gore 	}
11516b76705SSiddarth Gore 
11616b76705SSiddarth Gore 	/*
11716b76705SSiddarth Gore 	 * Enable RGMII delay on Tx and Rx for CPU port
11816b76705SSiddarth Gore 	 * Ref: sec 4.7.2 of chip datasheet
11916b76705SSiddarth Gore 	 */
12016b76705SSiddarth Gore 	miiphy_write(name, devadr, MV88E1121_PGADR_REG, 2);
12116b76705SSiddarth Gore 	miiphy_read(name, devadr, MV88E1121_MAC_CTRL2_REG, &reg);
12216b76705SSiddarth Gore 	reg |= (MV88E1121_RGMII_RXTM_CTRL | MV88E1121_RGMII_TXTM_CTRL);
12316b76705SSiddarth Gore 	miiphy_write(name, devadr, MV88E1121_MAC_CTRL2_REG, reg);
12416b76705SSiddarth Gore 	miiphy_write(name, devadr, MV88E1121_PGADR_REG, 0);
12516b76705SSiddarth Gore 
12616b76705SSiddarth Gore 	/* reset the phy */
1273f786bb8SMahavir Jain 	miiphy_reset(name, devadr);
12816b76705SSiddarth Gore 
12916b76705SSiddarth Gore 	printf("88E1121 Initialized on %s\n", name);
13016b76705SSiddarth Gore }
13116b76705SSiddarth Gore 
reset_phy(void)13216b76705SSiddarth Gore void reset_phy(void)
13316b76705SSiddarth Gore {
13416b76705SSiddarth Gore 	/* configure and initialize both PHY's */
13516b76705SSiddarth Gore 	mv_phy_88e1121_init("egiga0");
13616b76705SSiddarth Gore 	mv_phy_88e1121_init("egiga1");
13716b76705SSiddarth Gore }
13816b76705SSiddarth Gore #endif /* CONFIG_RESET_PHY_R */
139