Simon Guinot | 77ea071 | 2011-11-21 19:25:47 +0530 | [diff] [blame^] | 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 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 | |
| 23 | void mv_phy_88e1116_init(const char *name) |
| 24 | { |
| 25 | u16 reg; |
| 26 | u16 devadr; |
| 27 | |
| 28 | if (miiphy_set_current_dev(name)) |
| 29 | return; |
| 30 | |
| 31 | /* command to read PHY dev address */ |
| 32 | if (miiphy_read(name, 0xEE, 0xEE, (u16 *) &devadr)) { |
| 33 | printf("Err..(%s) could not read PHY dev address\n", __func__); |
| 34 | return; |
| 35 | } |
| 36 | |
| 37 | /* |
| 38 | * Enable RGMII delay on Tx and Rx for CPU port |
| 39 | * Ref: sec 4.7.2 of chip datasheet |
| 40 | */ |
| 41 | miiphy_write(name, devadr, MV88E1116_PGADR_REG, 2); |
| 42 | miiphy_read(name, devadr, MV88E1116_MAC_CTRL_REG, ®); |
| 43 | reg |= (MV88E1116_RGMII_RXTM_CTRL | MV88E1116_RGMII_TXTM_CTRL); |
| 44 | miiphy_write(name, devadr, MV88E1116_MAC_CTRL_REG, reg); |
| 45 | miiphy_write(name, devadr, MV88E1116_PGADR_REG, 0); |
| 46 | |
| 47 | /* reset the phy */ |
| 48 | miiphy_reset(name, devadr); |
| 49 | |
| 50 | printf("88E1116 Initialized on %s\n", name); |
| 51 | } |
| 52 | #endif /* CONFIG_CMD_NET && CONFIG_RESET_PHY_R */ |
| 53 | |
| 54 | #if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR) |
| 55 | int lacie_read_mac_address(uchar *mac_addr) |
| 56 | { |
| 57 | int ret; |
| 58 | ushort version; |
| 59 | |
| 60 | /* I2C-0 for on-board EEPROM */ |
| 61 | i2c_set_bus_num(0); |
| 62 | |
| 63 | /* Check layout version for EEPROM data */ |
| 64 | ret = i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, |
| 65 | CONFIG_SYS_I2C_EEPROM_ADDR_LEN, |
| 66 | (uchar *) &version, 2); |
| 67 | if (ret != 0) { |
| 68 | printf("Error: failed to read I2C EEPROM @%02x\n", |
| 69 | CONFIG_SYS_I2C_EEPROM_ADDR); |
| 70 | return ret; |
| 71 | } |
| 72 | version = be16_to_cpu(version); |
| 73 | if (version < 1 || version > 3) { |
| 74 | printf("Error: unknown version %d for EEPROM data\n", |
| 75 | version); |
| 76 | return -1; |
| 77 | } |
| 78 | |
| 79 | /* Read Ethernet MAC address from EEPROM */ |
| 80 | ret = i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 2, |
| 81 | CONFIG_SYS_I2C_EEPROM_ADDR_LEN, mac_addr, 6); |
| 82 | if (ret != 0) |
| 83 | printf("Error: failed to read I2C EEPROM @%02x\n", |
| 84 | CONFIG_SYS_I2C_EEPROM_ADDR); |
| 85 | return ret; |
| 86 | } |
| 87 | #endif /* CONFIG_CMD_I2C && CONFIG_SYS_I2C_EEPROM_ADDR */ |