xref: /openbmc/u-boot/board/LaCie/common/common.c (revision 9b914727)
1 /*
2  * Copyright (C) 2011 Simon Guinot <sguinot@lacie.com>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of
7  * the License, or (at your option) any later version.
8  */
9 
10 #include <common.h>
11 #include <i2c.h>
12 #include <miiphy.h>
13 
14 #if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R)
15 
16 #define MII_MARVELL_PHY_PAGE		22
17 
18 #define MV88E1116_LED_FCTRL_REG		10
19 #define MV88E1116_CPRSP_CR3_REG		21
20 #define MV88E1116_MAC_CTRL_REG		21
21 #define MV88E1116_RGMII_TXTM_CTRL	(1 << 4)
22 #define MV88E1116_RGMII_RXTM_CTRL	(1 << 5)
23 
24 void mv_phy_88e1116_init(const char *name, u16 phyaddr)
25 {
26 	u16 reg;
27 
28 	if (miiphy_set_current_dev(name))
29 		return;
30 
31 	/*
32 	 * Enable RGMII delay on Tx and Rx for CPU port
33 	 * Ref: sec 4.7.2 of chip datasheet
34 	 */
35 	miiphy_write(name, phyaddr, MII_MARVELL_PHY_PAGE, 2);
36 	miiphy_read(name, phyaddr, MV88E1116_MAC_CTRL_REG, &reg);
37 	reg |= (MV88E1116_RGMII_RXTM_CTRL | MV88E1116_RGMII_TXTM_CTRL);
38 	miiphy_write(name, phyaddr, MV88E1116_MAC_CTRL_REG, reg);
39 	miiphy_write(name, phyaddr, MII_MARVELL_PHY_PAGE, 0);
40 
41 	if (miiphy_reset(name, phyaddr) == 0)
42 		printf("88E1116 Initialized on %s\n", name);
43 }
44 
45 void mv_phy_88e1318_init(const char *name, u16 phyaddr)
46 {
47 	u16 reg;
48 
49 	if (miiphy_set_current_dev(name))
50 		return;
51 
52 	/*
53 	 * Set control mode 4 for LED[0].
54 	 */
55 	miiphy_write(name, phyaddr, MII_MARVELL_PHY_PAGE, 3);
56 	miiphy_read(name, phyaddr, 16, &reg);
57 	reg |= 0xf;
58 	miiphy_write(name, phyaddr, 16, reg);
59 
60 	/*
61 	 * Enable RGMII delay on Tx and Rx for CPU port
62 	 * Ref: sec 4.7.2 of chip datasheet
63 	 */
64 	miiphy_write(name, phyaddr, MII_MARVELL_PHY_PAGE, 2);
65 	miiphy_read(name, phyaddr, MV88E1116_MAC_CTRL_REG, &reg);
66 	reg |= (MV88E1116_RGMII_TXTM_CTRL | MV88E1116_RGMII_RXTM_CTRL);
67 	miiphy_write(name, phyaddr, MV88E1116_MAC_CTRL_REG, reg);
68 	miiphy_write(name, phyaddr, MII_MARVELL_PHY_PAGE, 0);
69 
70 	if (miiphy_reset(name, phyaddr) == 0)
71 		printf("88E1318 Initialized on %s\n", name);
72 }
73 #endif /* CONFIG_CMD_NET && CONFIG_RESET_PHY_R */
74 
75 #if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR)
76 int lacie_read_mac_address(uchar *mac_addr)
77 {
78 	int ret;
79 	ushort version;
80 
81 	/* I2C-0 for on-board EEPROM */
82 	i2c_set_bus_num(0);
83 
84 	/* Check layout version for EEPROM data */
85 	ret = i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0,
86 			CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
87 			(uchar *) &version, 2);
88 	if (ret != 0) {
89 		printf("Error: failed to read I2C EEPROM @%02x\n",
90 			CONFIG_SYS_I2C_EEPROM_ADDR);
91 		return ret;
92 	}
93 	version = be16_to_cpu(version);
94 	if (version < 1 || version > 3) {
95 		printf("Error: unknown version %d for EEPROM data\n",
96 			version);
97 		return -1;
98 	}
99 
100 	/* Read Ethernet MAC address from EEPROM */
101 	ret = i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 2,
102 			CONFIG_SYS_I2C_EEPROM_ADDR_LEN, mac_addr, 6);
103 	if (ret != 0)
104 		printf("Error: failed to read I2C EEPROM @%02x\n",
105 			CONFIG_SYS_I2C_EEPROM_ADDR);
106 	return ret;
107 }
108 #endif /* CONFIG_CMD_I2C && CONFIG_SYS_I2C_EEPROM_ADDR */
109