blob: 78d0edc66d8384ac4a44a25bd8d6d2cfd0976a1e [file] [log] [blame]
Simon Guinota35cb4c2011-11-21 19:25:47 +05301/*
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 MV88E1116_LED_FCTRL_REG 10
17#define MV88E1116_CPRSP_CR3_REG 21
18#define MV88E1116_MAC_CTRL_REG 21
19#define MV88E1116_PGADR_REG 22
20#define MV88E1116_RGMII_TXTM_CTRL (1 << 4)
21#define MV88E1116_RGMII_RXTM_CTRL (1 << 5)
22
Simon Guinot0473b682012-06-05 13:16:00 +000023void mv_phy_88e1116_init(const char *name, u16 phyaddr)
Simon Guinota35cb4c2011-11-21 19:25:47 +053024{
25 u16 reg;
Simon Guinota35cb4c2011-11-21 19:25:47 +053026
27 if (miiphy_set_current_dev(name))
28 return;
29
Simon Guinota35cb4c2011-11-21 19:25:47 +053030 /*
31 * Enable RGMII delay on Tx and Rx for CPU port
32 * Ref: sec 4.7.2 of chip datasheet
33 */
Simon Guinot0473b682012-06-05 13:16:00 +000034 miiphy_write(name, phyaddr, MV88E1116_PGADR_REG, 2);
35 miiphy_read(name, phyaddr, MV88E1116_MAC_CTRL_REG, &reg);
Simon Guinota35cb4c2011-11-21 19:25:47 +053036 reg |= (MV88E1116_RGMII_RXTM_CTRL | MV88E1116_RGMII_TXTM_CTRL);
Simon Guinot0473b682012-06-05 13:16:00 +000037 miiphy_write(name, phyaddr, MV88E1116_MAC_CTRL_REG, reg);
38 miiphy_write(name, phyaddr, MV88E1116_PGADR_REG, 0);
Simon Guinota35cb4c2011-11-21 19:25:47 +053039
Simon Guinot0473b682012-06-05 13:16:00 +000040 if (miiphy_reset(name, phyaddr) == 0)
41 printf("88E1116 Initialized on %s\n", name);
Simon Guinota35cb4c2011-11-21 19:25:47 +053042}
43#endif /* CONFIG_CMD_NET && CONFIG_RESET_PHY_R */
44
45#if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR)
46int lacie_read_mac_address(uchar *mac_addr)
47{
48 int ret;
49 ushort version;
50
51 /* I2C-0 for on-board EEPROM */
52 i2c_set_bus_num(0);
53
54 /* Check layout version for EEPROM data */
55 ret = i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0,
56 CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
57 (uchar *) &version, 2);
58 if (ret != 0) {
59 printf("Error: failed to read I2C EEPROM @%02x\n",
60 CONFIG_SYS_I2C_EEPROM_ADDR);
61 return ret;
62 }
63 version = be16_to_cpu(version);
64 if (version < 1 || version > 3) {
65 printf("Error: unknown version %d for EEPROM data\n",
66 version);
67 return -1;
68 }
69
70 /* Read Ethernet MAC address from EEPROM */
71 ret = i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 2,
72 CONFIG_SYS_I2C_EEPROM_ADDR_LEN, mac_addr, 6);
73 if (ret != 0)
74 printf("Error: failed to read I2C EEPROM @%02x\n",
75 CONFIG_SYS_I2C_EEPROM_ADDR);
76 return ret;
77}
78#endif /* CONFIG_CMD_I2C && CONFIG_SYS_I2C_EEPROM_ADDR */