xref: /openbmc/u-boot/board/LaCie/common/common.c (revision e8f80a5a)
1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
277ea071fSSimon Guinot /*
377ea071fSSimon Guinot  * Copyright (C) 2011 Simon Guinot <sguinot@lacie.com>
477ea071fSSimon Guinot  */
577ea071fSSimon Guinot 
677ea071fSSimon Guinot #include <common.h>
777ea071fSSimon Guinot #include <i2c.h>
877ea071fSSimon Guinot #include <miiphy.h>
977ea071fSSimon Guinot 
1077ea071fSSimon Guinot #if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R)
1177ea071fSSimon Guinot 
1237235496SSimon Guinot #define MII_MARVELL_PHY_PAGE		22
1337235496SSimon Guinot 
1477ea071fSSimon Guinot #define MV88E1116_LED_FCTRL_REG		10
1577ea071fSSimon Guinot #define MV88E1116_CPRSP_CR3_REG		21
1677ea071fSSimon Guinot #define MV88E1116_MAC_CTRL_REG		21
1777ea071fSSimon Guinot #define MV88E1116_RGMII_TXTM_CTRL	(1 << 4)
1877ea071fSSimon Guinot #define MV88E1116_RGMII_RXTM_CTRL	(1 << 5)
1977ea071fSSimon Guinot 
mv_phy_88e1116_init(const char * name,u16 phyaddr)20c59c0857SSimon Guinot void mv_phy_88e1116_init(const char *name, u16 phyaddr)
2177ea071fSSimon Guinot {
2277ea071fSSimon Guinot 	u16 reg;
2377ea071fSSimon Guinot 
2477ea071fSSimon Guinot 	if (miiphy_set_current_dev(name))
2577ea071fSSimon Guinot 		return;
2677ea071fSSimon Guinot 
2777ea071fSSimon Guinot 	/*
2877ea071fSSimon Guinot 	 * Enable RGMII delay on Tx and Rx for CPU port
2977ea071fSSimon Guinot 	 * Ref: sec 4.7.2 of chip datasheet
3077ea071fSSimon Guinot 	 */
3137235496SSimon Guinot 	miiphy_write(name, phyaddr, MII_MARVELL_PHY_PAGE, 2);
32c59c0857SSimon Guinot 	miiphy_read(name, phyaddr, MV88E1116_MAC_CTRL_REG, &reg);
3377ea071fSSimon Guinot 	reg |= (MV88E1116_RGMII_RXTM_CTRL | MV88E1116_RGMII_TXTM_CTRL);
34c59c0857SSimon Guinot 	miiphy_write(name, phyaddr, MV88E1116_MAC_CTRL_REG, reg);
3537235496SSimon Guinot 	miiphy_write(name, phyaddr, MII_MARVELL_PHY_PAGE, 0);
3677ea071fSSimon Guinot 
37c59c0857SSimon Guinot 	if (miiphy_reset(name, phyaddr) == 0)
3877ea071fSSimon Guinot 		printf("88E1116 Initialized on %s\n", name);
3977ea071fSSimon Guinot }
4037235496SSimon Guinot 
mv_phy_88e1318_init(const char * name,u16 phyaddr)4137235496SSimon Guinot void mv_phy_88e1318_init(const char *name, u16 phyaddr)
4237235496SSimon Guinot {
4337235496SSimon Guinot 	u16 reg;
4437235496SSimon Guinot 
4537235496SSimon Guinot 	if (miiphy_set_current_dev(name))
4637235496SSimon Guinot 		return;
4737235496SSimon Guinot 
4837235496SSimon Guinot 	/*
4937235496SSimon Guinot 	 * Set control mode 4 for LED[0].
5037235496SSimon Guinot 	 */
5137235496SSimon Guinot 	miiphy_write(name, phyaddr, MII_MARVELL_PHY_PAGE, 3);
5237235496SSimon Guinot 	miiphy_read(name, phyaddr, 16, &reg);
5337235496SSimon Guinot 	reg |= 0xf;
5437235496SSimon Guinot 	miiphy_write(name, phyaddr, 16, reg);
5537235496SSimon Guinot 
5637235496SSimon Guinot 	/*
5737235496SSimon Guinot 	 * Enable RGMII delay on Tx and Rx for CPU port
5837235496SSimon Guinot 	 * Ref: sec 4.7.2 of chip datasheet
5937235496SSimon Guinot 	 */
6037235496SSimon Guinot 	miiphy_write(name, phyaddr, MII_MARVELL_PHY_PAGE, 2);
6137235496SSimon Guinot 	miiphy_read(name, phyaddr, MV88E1116_MAC_CTRL_REG, &reg);
6237235496SSimon Guinot 	reg |= (MV88E1116_RGMII_TXTM_CTRL | MV88E1116_RGMII_RXTM_CTRL);
6337235496SSimon Guinot 	miiphy_write(name, phyaddr, MV88E1116_MAC_CTRL_REG, reg);
6437235496SSimon Guinot 	miiphy_write(name, phyaddr, MII_MARVELL_PHY_PAGE, 0);
6537235496SSimon Guinot 
6637235496SSimon Guinot 	if (miiphy_reset(name, phyaddr) == 0)
6737235496SSimon Guinot 		printf("88E1318 Initialized on %s\n", name);
6837235496SSimon Guinot }
6977ea071fSSimon Guinot #endif /* CONFIG_CMD_NET && CONFIG_RESET_PHY_R */
7077ea071fSSimon Guinot 
7177ea071fSSimon Guinot #if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR)
lacie_read_mac_address(uchar * mac_addr)7277ea071fSSimon Guinot int lacie_read_mac_address(uchar *mac_addr)
7377ea071fSSimon Guinot {
7477ea071fSSimon Guinot 	int ret;
7577ea071fSSimon Guinot 	ushort version;
7677ea071fSSimon Guinot 
7777ea071fSSimon Guinot 	/* I2C-0 for on-board EEPROM */
7877ea071fSSimon Guinot 	i2c_set_bus_num(0);
7977ea071fSSimon Guinot 
8077ea071fSSimon Guinot 	/* Check layout version for EEPROM data */
8177ea071fSSimon Guinot 	ret = i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0,
8277ea071fSSimon Guinot 			CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
8377ea071fSSimon Guinot 			(uchar *) &version, 2);
8477ea071fSSimon Guinot 	if (ret != 0) {
8577ea071fSSimon Guinot 		printf("Error: failed to read I2C EEPROM @%02x\n",
8677ea071fSSimon Guinot 			CONFIG_SYS_I2C_EEPROM_ADDR);
8777ea071fSSimon Guinot 		return ret;
8877ea071fSSimon Guinot 	}
8977ea071fSSimon Guinot 	version = be16_to_cpu(version);
9077ea071fSSimon Guinot 	if (version < 1 || version > 3) {
9177ea071fSSimon Guinot 		printf("Error: unknown version %d for EEPROM data\n",
9277ea071fSSimon Guinot 			version);
9377ea071fSSimon Guinot 		return -1;
9477ea071fSSimon Guinot 	}
9577ea071fSSimon Guinot 
9677ea071fSSimon Guinot 	/* Read Ethernet MAC address from EEPROM */
9777ea071fSSimon Guinot 	ret = i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 2,
9877ea071fSSimon Guinot 			CONFIG_SYS_I2C_EEPROM_ADDR_LEN, mac_addr, 6);
9977ea071fSSimon Guinot 	if (ret != 0)
10077ea071fSSimon Guinot 		printf("Error: failed to read I2C EEPROM @%02x\n",
10177ea071fSSimon Guinot 			CONFIG_SYS_I2C_EEPROM_ADDR);
10277ea071fSSimon Guinot 	return ret;
10377ea071fSSimon Guinot }
10477ea071fSSimon Guinot #endif /* CONFIG_CMD_I2C && CONFIG_SYS_I2C_EEPROM_ADDR */
105