Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Guinot | a35cb4c | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2011 Simon Guinot <sguinot@lacie.com> |
Simon Guinot | a35cb4c | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 4 | */ |
| 5 | |
Simon Guinot | a35cb4c | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 6 | #include <i2c.h> |
| 7 | #include <miiphy.h> |
| 8 | |
| 9 | #if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R) |
| 10 | |
Simon Guinot | 13c5ae6 | 2012-09-06 10:51:42 +0000 | [diff] [blame] | 11 | #define MII_MARVELL_PHY_PAGE 22 |
| 12 | |
Simon Guinot | a35cb4c | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 13 | #define MV88E1116_LED_FCTRL_REG 10 |
| 14 | #define MV88E1116_CPRSP_CR3_REG 21 |
| 15 | #define MV88E1116_MAC_CTRL_REG 21 |
Simon Guinot | a35cb4c | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 16 | #define MV88E1116_RGMII_TXTM_CTRL (1 << 4) |
| 17 | #define MV88E1116_RGMII_RXTM_CTRL (1 << 5) |
| 18 | |
Simon Guinot | 0473b68 | 2012-06-05 13:16:00 +0000 | [diff] [blame] | 19 | void mv_phy_88e1116_init(const char *name, u16 phyaddr) |
Simon Guinot | a35cb4c | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 20 | { |
| 21 | u16 reg; |
Simon Guinot | a35cb4c | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 22 | |
| 23 | if (miiphy_set_current_dev(name)) |
| 24 | return; |
| 25 | |
Simon Guinot | a35cb4c | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 26 | /* |
| 27 | * Enable RGMII delay on Tx and Rx for CPU port |
| 28 | * Ref: sec 4.7.2 of chip datasheet |
| 29 | */ |
Simon Guinot | 13c5ae6 | 2012-09-06 10:51:42 +0000 | [diff] [blame] | 30 | miiphy_write(name, phyaddr, MII_MARVELL_PHY_PAGE, 2); |
Simon Guinot | 0473b68 | 2012-06-05 13:16:00 +0000 | [diff] [blame] | 31 | miiphy_read(name, phyaddr, MV88E1116_MAC_CTRL_REG, ®); |
Simon Guinot | a35cb4c | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 32 | reg |= (MV88E1116_RGMII_RXTM_CTRL | MV88E1116_RGMII_TXTM_CTRL); |
Simon Guinot | 0473b68 | 2012-06-05 13:16:00 +0000 | [diff] [blame] | 33 | miiphy_write(name, phyaddr, MV88E1116_MAC_CTRL_REG, reg); |
Simon Guinot | 13c5ae6 | 2012-09-06 10:51:42 +0000 | [diff] [blame] | 34 | miiphy_write(name, phyaddr, MII_MARVELL_PHY_PAGE, 0); |
Simon Guinot | a35cb4c | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 35 | |
Simon Guinot | 0473b68 | 2012-06-05 13:16:00 +0000 | [diff] [blame] | 36 | if (miiphy_reset(name, phyaddr) == 0) |
| 37 | printf("88E1116 Initialized on %s\n", name); |
Simon Guinot | a35cb4c | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 38 | } |
Simon Guinot | 13c5ae6 | 2012-09-06 10:51:42 +0000 | [diff] [blame] | 39 | |
| 40 | void mv_phy_88e1318_init(const char *name, u16 phyaddr) |
| 41 | { |
| 42 | u16 reg; |
| 43 | |
| 44 | if (miiphy_set_current_dev(name)) |
| 45 | return; |
| 46 | |
| 47 | /* |
| 48 | * Set control mode 4 for LED[0]. |
| 49 | */ |
| 50 | miiphy_write(name, phyaddr, MII_MARVELL_PHY_PAGE, 3); |
| 51 | miiphy_read(name, phyaddr, 16, ®); |
| 52 | reg |= 0xf; |
| 53 | miiphy_write(name, phyaddr, 16, reg); |
| 54 | |
| 55 | /* |
| 56 | * Enable RGMII delay on Tx and Rx for CPU port |
| 57 | * Ref: sec 4.7.2 of chip datasheet |
| 58 | */ |
| 59 | miiphy_write(name, phyaddr, MII_MARVELL_PHY_PAGE, 2); |
| 60 | miiphy_read(name, phyaddr, MV88E1116_MAC_CTRL_REG, ®); |
| 61 | reg |= (MV88E1116_RGMII_TXTM_CTRL | MV88E1116_RGMII_RXTM_CTRL); |
| 62 | miiphy_write(name, phyaddr, MV88E1116_MAC_CTRL_REG, reg); |
| 63 | miiphy_write(name, phyaddr, MII_MARVELL_PHY_PAGE, 0); |
| 64 | |
| 65 | if (miiphy_reset(name, phyaddr) == 0) |
| 66 | printf("88E1318 Initialized on %s\n", name); |
| 67 | } |
Simon Guinot | a35cb4c | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 68 | #endif /* CONFIG_CMD_NET && CONFIG_RESET_PHY_R */ |
| 69 | |
| 70 | #if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR) |
| 71 | int lacie_read_mac_address(uchar *mac_addr) |
| 72 | { |
| 73 | int ret; |
| 74 | ushort version; |
| 75 | |
| 76 | /* I2C-0 for on-board EEPROM */ |
| 77 | i2c_set_bus_num(0); |
| 78 | |
| 79 | /* Check layout version for EEPROM data */ |
| 80 | ret = i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, |
| 81 | CONFIG_SYS_I2C_EEPROM_ADDR_LEN, |
| 82 | (uchar *) &version, 2); |
| 83 | if (ret != 0) { |
| 84 | printf("Error: failed to read I2C EEPROM @%02x\n", |
| 85 | CONFIG_SYS_I2C_EEPROM_ADDR); |
| 86 | return ret; |
| 87 | } |
| 88 | version = be16_to_cpu(version); |
| 89 | if (version < 1 || version > 3) { |
| 90 | printf("Error: unknown version %d for EEPROM data\n", |
| 91 | version); |
| 92 | return -1; |
| 93 | } |
| 94 | |
| 95 | /* Read Ethernet MAC address from EEPROM */ |
| 96 | ret = i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 2, |
| 97 | CONFIG_SYS_I2C_EEPROM_ADDR_LEN, mac_addr, 6); |
| 98 | if (ret != 0) |
| 99 | printf("Error: failed to read I2C EEPROM @%02x\n", |
| 100 | CONFIG_SYS_I2C_EEPROM_ADDR); |
| 101 | return ret; |
| 102 | } |
| 103 | #endif /* CONFIG_CMD_I2C && CONFIG_SYS_I2C_EEPROM_ADDR */ |