Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2005 Freescale Semiconductor, Inc. |
| 3 | * |
| 4 | * Author: Shlomi Gridish |
| 5 | * |
| 6 | * Description: UCC GETH Driver -- PHY handling |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 7 | * Driver for UEC on QE |
| 8 | * Based on 8260_io/fcc_enet.c |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 9 | * |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License as published by the |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 12 | * Free Software Foundation; either version 2 of the License, or (at your |
| 13 | * option) any later version. |
| 14 | * |
| 15 | */ |
| 16 | |
| 17 | #include "common.h" |
| 18 | #include "net.h" |
| 19 | #include "malloc.h" |
| 20 | #include "asm/errno.h" |
| 21 | #include "asm/immap_qe.h" |
| 22 | #include "asm/io.h" |
| 23 | #include "qe.h" |
| 24 | #include "uccf.h" |
| 25 | #include "uec.h" |
| 26 | #include "uec_phy.h" |
| 27 | #include "miiphy.h" |
| 28 | |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 29 | #define ugphy_printk(format, arg...) \ |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 30 | printf(format "\n", ## arg) |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 31 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 32 | #define ugphy_dbg(format, arg...) \ |
| 33 | ugphy_printk(format , ## arg) |
| 34 | #define ugphy_err(format, arg...) \ |
| 35 | ugphy_printk(format , ## arg) |
| 36 | #define ugphy_info(format, arg...) \ |
| 37 | ugphy_printk(format , ## arg) |
| 38 | #define ugphy_warn(format, arg...) \ |
| 39 | ugphy_printk(format , ## arg) |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 40 | |
| 41 | #ifdef UEC_VERBOSE_DEBUG |
| 42 | #define ugphy_vdbg ugphy_dbg |
| 43 | #else |
| 44 | #define ugphy_vdbg(ugeth, fmt, args...) do { } while (0) |
| 45 | #endif /* UEC_VERBOSE_DEBUG */ |
| 46 | |
Richard Retanubun | edf3fe7 | 2008-10-23 09:08:18 -0400 | [diff] [blame] | 47 | /*--------------------------------------------------------------------+ |
| 48 | * Fixed PHY (PHY-less) support for Ethernet Ports. |
| 49 | * |
| 50 | * Copied from cpu/ppc4xx/4xx_enet.c |
| 51 | *--------------------------------------------------------------------*/ |
| 52 | |
| 53 | /* |
| 54 | * Some boards do not have a PHY for each ethernet port. These ports |
| 55 | * are known as Fixed PHY (or PHY-less) ports. For such ports, set |
| 56 | * the appropriate CONFIG_PHY_ADDR equal to CONFIG_FIXED_PHY and |
| 57 | * then define CONFIG_SYS_FIXED_PHY_PORTS to define what the speed and |
| 58 | * duplex should be for these ports in the board configuration |
| 59 | * file. |
| 60 | * |
| 61 | * For Example: |
| 62 | * #define CONFIG_FIXED_PHY 0xFFFFFFFF |
| 63 | * |
| 64 | * #define CONFIG_PHY_ADDR CONFIG_FIXED_PHY |
| 65 | * #define CONFIG_PHY1_ADDR 1 |
| 66 | * #define CONFIG_PHY2_ADDR CONFIG_FIXED_PHY |
| 67 | * #define CONFIG_PHY3_ADDR 3 |
| 68 | * |
| 69 | * #define CONFIG_SYS_FIXED_PHY_PORT(devnum,speed,duplex) \ |
| 70 | * {devnum, speed, duplex}, |
| 71 | * |
| 72 | * #define CONFIG_SYS_FIXED_PHY_PORTS \ |
| 73 | * CONFIG_SYS_FIXED_PHY_PORT(0,SPEED_100,DUPLEX_FULL) \ |
| 74 | * CONFIG_SYS_FIXED_PHY_PORT(2,SPEED_100,DUPLEX_HALF) |
| 75 | */ |
| 76 | |
| 77 | #ifndef CONFIG_FIXED_PHY |
| 78 | #define CONFIG_FIXED_PHY 0xFFFFFFFF /* Fixed PHY (PHY-less) */ |
| 79 | #endif |
| 80 | |
| 81 | #ifndef CONFIG_SYS_FIXED_PHY_PORTS |
| 82 | #define CONFIG_SYS_FIXED_PHY_PORTS /* default is an empty array */ |
| 83 | #endif |
| 84 | |
| 85 | struct fixed_phy_port { |
| 86 | unsigned int devnum; /* ethernet port */ |
| 87 | unsigned int speed; /* specified speed 10,100 or 1000 */ |
| 88 | unsigned int duplex; /* specified duplex FULL or HALF */ |
| 89 | }; |
| 90 | |
| 91 | static const struct fixed_phy_port fixed_phy_port[] = { |
| 92 | CONFIG_SYS_FIXED_PHY_PORTS /* defined in board configuration file */ |
| 93 | }; |
| 94 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 95 | static void config_genmii_advert (struct uec_mii_info *mii_info); |
| 96 | static void genmii_setup_forced (struct uec_mii_info *mii_info); |
| 97 | static void genmii_restart_aneg (struct uec_mii_info *mii_info); |
| 98 | static int gbit_config_aneg (struct uec_mii_info *mii_info); |
| 99 | static int genmii_config_aneg (struct uec_mii_info *mii_info); |
| 100 | static int genmii_update_link (struct uec_mii_info *mii_info); |
| 101 | static int genmii_read_status (struct uec_mii_info *mii_info); |
| 102 | u16 phy_read (struct uec_mii_info *mii_info, u16 regnum); |
| 103 | void phy_write (struct uec_mii_info *mii_info, u16 regnum, u16 val); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 104 | |
| 105 | /* Write value to the PHY for this device to the register at regnum, */ |
| 106 | /* waiting until the write is done before it returns. All PHY */ |
| 107 | /* configuration has to be done through the TSEC1 MIIM regs */ |
Andy Fleming | da9d461 | 2007-08-14 00:14:25 -0500 | [diff] [blame] | 108 | void uec_write_phy_reg (struct eth_device *dev, int mii_id, int regnum, int value) |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 109 | { |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 110 | uec_private_t *ugeth = (uec_private_t *) dev->priv; |
Andy Fleming | da9d461 | 2007-08-14 00:14:25 -0500 | [diff] [blame] | 111 | uec_mii_t *ug_regs; |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 112 | enet_tbi_mii_reg_e mii_reg = (enet_tbi_mii_reg_e) regnum; |
| 113 | u32 tmp_reg; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 114 | |
Andy Fleming | da9d461 | 2007-08-14 00:14:25 -0500 | [diff] [blame] | 115 | ug_regs = ugeth->uec_mii_regs; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 116 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 117 | /* Stop the MII management read cycle */ |
| 118 | out_be32 (&ug_regs->miimcom, 0); |
| 119 | /* Setting up the MII Mangement Address Register */ |
| 120 | tmp_reg = ((u32) mii_id << MIIMADD_PHY_ADDRESS_SHIFT) | mii_reg; |
| 121 | out_be32 (&ug_regs->miimadd, tmp_reg); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 122 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 123 | /* Setting up the MII Mangement Control Register with the value */ |
| 124 | out_be32 (&ug_regs->miimcon, (u32) value); |
Kim Phillips | ee62ed3 | 2008-01-15 14:11:00 -0600 | [diff] [blame] | 125 | sync(); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 126 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 127 | /* Wait till MII management write is complete */ |
| 128 | while ((in_be32 (&ug_regs->miimind)) & MIIMIND_BUSY); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | /* Reads from register regnum in the PHY for device dev, */ |
| 132 | /* returning the value. Clears miimcom first. All PHY */ |
| 133 | /* configuration has to be done through the TSEC1 MIIM regs */ |
Andy Fleming | da9d461 | 2007-08-14 00:14:25 -0500 | [diff] [blame] | 134 | int uec_read_phy_reg (struct eth_device *dev, int mii_id, int regnum) |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 135 | { |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 136 | uec_private_t *ugeth = (uec_private_t *) dev->priv; |
Andy Fleming | da9d461 | 2007-08-14 00:14:25 -0500 | [diff] [blame] | 137 | uec_mii_t *ug_regs; |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 138 | enet_tbi_mii_reg_e mii_reg = (enet_tbi_mii_reg_e) regnum; |
| 139 | u32 tmp_reg; |
| 140 | u16 value; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 141 | |
Andy Fleming | da9d461 | 2007-08-14 00:14:25 -0500 | [diff] [blame] | 142 | ug_regs = ugeth->uec_mii_regs; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 143 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 144 | /* Setting up the MII Mangement Address Register */ |
| 145 | tmp_reg = ((u32) mii_id << MIIMADD_PHY_ADDRESS_SHIFT) | mii_reg; |
| 146 | out_be32 (&ug_regs->miimadd, tmp_reg); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 147 | |
Kim Phillips | ee62ed3 | 2008-01-15 14:11:00 -0600 | [diff] [blame] | 148 | /* clear MII management command cycle */ |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 149 | out_be32 (&ug_regs->miimcom, 0); |
Kim Phillips | ee62ed3 | 2008-01-15 14:11:00 -0600 | [diff] [blame] | 150 | sync(); |
| 151 | |
| 152 | /* Perform an MII management read cycle */ |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 153 | out_be32 (&ug_regs->miimcom, MIIMCOM_READ_CYCLE); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 154 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 155 | /* Wait till MII management write is complete */ |
| 156 | while ((in_be32 (&ug_regs->miimind)) & |
| 157 | (MIIMIND_NOT_VALID | MIIMIND_BUSY)); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 158 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 159 | /* Read MII management status */ |
| 160 | value = (u16) in_be32 (&ug_regs->miimstat); |
| 161 | if (value == 0xffff) |
Joakim Tjernlund | 84a3047 | 2008-01-16 09:40:41 +0100 | [diff] [blame] | 162 | ugphy_vdbg |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 163 | ("read wrong value : mii_id %d,mii_reg %d, base %08x", |
| 164 | mii_id, mii_reg, (u32) & (ug_regs->miimcfg)); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 165 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 166 | return (value); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 167 | } |
| 168 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 169 | void mii_clear_phy_interrupt (struct uec_mii_info *mii_info) |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 170 | { |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 171 | if (mii_info->phyinfo->ack_interrupt) |
| 172 | mii_info->phyinfo->ack_interrupt (mii_info); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 173 | } |
| 174 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 175 | void mii_configure_phy_interrupt (struct uec_mii_info *mii_info, |
| 176 | u32 interrupts) |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 177 | { |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 178 | mii_info->interrupts = interrupts; |
| 179 | if (mii_info->phyinfo->config_intr) |
| 180 | mii_info->phyinfo->config_intr (mii_info); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | /* Writes MII_ADVERTISE with the appropriate values, after |
| 184 | * sanitizing advertise to make sure only supported features |
| 185 | * are advertised |
| 186 | */ |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 187 | static void config_genmii_advert (struct uec_mii_info *mii_info) |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 188 | { |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 189 | u32 advertise; |
| 190 | u16 adv; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 191 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 192 | /* Only allow advertising what this PHY supports */ |
| 193 | mii_info->advertising &= mii_info->phyinfo->features; |
| 194 | advertise = mii_info->advertising; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 195 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 196 | /* Setup standard advertisement */ |
| 197 | adv = phy_read (mii_info, PHY_ANAR); |
| 198 | adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4); |
| 199 | if (advertise & ADVERTISED_10baseT_Half) |
| 200 | adv |= ADVERTISE_10HALF; |
| 201 | if (advertise & ADVERTISED_10baseT_Full) |
| 202 | adv |= ADVERTISE_10FULL; |
| 203 | if (advertise & ADVERTISED_100baseT_Half) |
| 204 | adv |= ADVERTISE_100HALF; |
| 205 | if (advertise & ADVERTISED_100baseT_Full) |
| 206 | adv |= ADVERTISE_100FULL; |
| 207 | phy_write (mii_info, PHY_ANAR, adv); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 208 | } |
| 209 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 210 | static void genmii_setup_forced (struct uec_mii_info *mii_info) |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 211 | { |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 212 | u16 ctrl; |
| 213 | u32 features = mii_info->phyinfo->features; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 214 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 215 | ctrl = phy_read (mii_info, PHY_BMCR); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 216 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 217 | ctrl &= ~(PHY_BMCR_DPLX | PHY_BMCR_100_MBPS | |
| 218 | PHY_BMCR_1000_MBPS | PHY_BMCR_AUTON); |
| 219 | ctrl |= PHY_BMCR_RESET; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 220 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 221 | switch (mii_info->speed) { |
| 222 | case SPEED_1000: |
| 223 | if (features & (SUPPORTED_1000baseT_Half |
| 224 | | SUPPORTED_1000baseT_Full)) { |
| 225 | ctrl |= PHY_BMCR_1000_MBPS; |
| 226 | break; |
| 227 | } |
| 228 | mii_info->speed = SPEED_100; |
| 229 | case SPEED_100: |
| 230 | if (features & (SUPPORTED_100baseT_Half |
| 231 | | SUPPORTED_100baseT_Full)) { |
| 232 | ctrl |= PHY_BMCR_100_MBPS; |
| 233 | break; |
| 234 | } |
| 235 | mii_info->speed = SPEED_10; |
| 236 | case SPEED_10: |
| 237 | if (features & (SUPPORTED_10baseT_Half |
| 238 | | SUPPORTED_10baseT_Full)) |
| 239 | break; |
| 240 | default: /* Unsupported speed! */ |
| 241 | ugphy_err ("%s: Bad speed!", mii_info->dev->name); |
| 242 | break; |
| 243 | } |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 244 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 245 | phy_write (mii_info, PHY_BMCR, ctrl); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | /* Enable and Restart Autonegotiation */ |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 249 | static void genmii_restart_aneg (struct uec_mii_info *mii_info) |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 250 | { |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 251 | u16 ctl; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 252 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 253 | ctl = phy_read (mii_info, PHY_BMCR); |
| 254 | ctl |= (PHY_BMCR_AUTON | PHY_BMCR_RST_NEG); |
| 255 | phy_write (mii_info, PHY_BMCR, ctl); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 256 | } |
| 257 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 258 | static int gbit_config_aneg (struct uec_mii_info *mii_info) |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 259 | { |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 260 | u16 adv; |
| 261 | u32 advertise; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 262 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 263 | if (mii_info->autoneg) { |
| 264 | /* Configure the ADVERTISE register */ |
| 265 | config_genmii_advert (mii_info); |
| 266 | advertise = mii_info->advertising; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 267 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 268 | adv = phy_read (mii_info, MII_1000BASETCONTROL); |
| 269 | adv &= ~(MII_1000BASETCONTROL_FULLDUPLEXCAP | |
| 270 | MII_1000BASETCONTROL_HALFDUPLEXCAP); |
| 271 | if (advertise & SUPPORTED_1000baseT_Half) |
| 272 | adv |= MII_1000BASETCONTROL_HALFDUPLEXCAP; |
| 273 | if (advertise & SUPPORTED_1000baseT_Full) |
| 274 | adv |= MII_1000BASETCONTROL_FULLDUPLEXCAP; |
| 275 | phy_write (mii_info, MII_1000BASETCONTROL, adv); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 276 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 277 | /* Start/Restart aneg */ |
| 278 | genmii_restart_aneg (mii_info); |
| 279 | } else |
| 280 | genmii_setup_forced (mii_info); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 281 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 282 | return 0; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 283 | } |
| 284 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 285 | static int marvell_config_aneg (struct uec_mii_info *mii_info) |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 286 | { |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 287 | /* The Marvell PHY has an errata which requires |
| 288 | * that certain registers get written in order |
| 289 | * to restart autonegotiation */ |
| 290 | phy_write (mii_info, PHY_BMCR, PHY_BMCR_RESET); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 291 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 292 | phy_write (mii_info, 0x1d, 0x1f); |
| 293 | phy_write (mii_info, 0x1e, 0x200c); |
| 294 | phy_write (mii_info, 0x1d, 0x5); |
| 295 | phy_write (mii_info, 0x1e, 0); |
| 296 | phy_write (mii_info, 0x1e, 0x100); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 297 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 298 | gbit_config_aneg (mii_info); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 299 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 300 | return 0; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 301 | } |
| 302 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 303 | static int genmii_config_aneg (struct uec_mii_info *mii_info) |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 304 | { |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 305 | if (mii_info->autoneg) { |
| 306 | config_genmii_advert (mii_info); |
| 307 | genmii_restart_aneg (mii_info); |
| 308 | } else |
| 309 | genmii_setup_forced (mii_info); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 310 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 311 | return 0; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 312 | } |
| 313 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 314 | static int genmii_update_link (struct uec_mii_info *mii_info) |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 315 | { |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 316 | u16 status; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 317 | |
Kim Phillips | ee62ed3 | 2008-01-15 14:11:00 -0600 | [diff] [blame] | 318 | /* Status is read once to clear old link state */ |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 319 | phy_read (mii_info, PHY_BMSR); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 320 | |
Kim Phillips | ee62ed3 | 2008-01-15 14:11:00 -0600 | [diff] [blame] | 321 | /* |
| 322 | * Wait if the link is up, and autonegotiation is in progress |
| 323 | * (ie - we're capable and it's not done) |
| 324 | */ |
| 325 | status = phy_read(mii_info, PHY_BMSR); |
| 326 | if ((status & PHY_BMSR_LS) && (status & PHY_BMSR_AUTN_ABLE) |
| 327 | && !(status & PHY_BMSR_AUTN_COMP)) { |
| 328 | int i = 0; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 329 | |
Kim Phillips | ee62ed3 | 2008-01-15 14:11:00 -0600 | [diff] [blame] | 330 | while (!(status & PHY_BMSR_AUTN_COMP)) { |
| 331 | /* |
| 332 | * Timeout reached ? |
| 333 | */ |
| 334 | if (i > UGETH_AN_TIMEOUT) { |
| 335 | mii_info->link = 0; |
| 336 | return 0; |
| 337 | } |
| 338 | |
Kim Phillips | f30b6154 | 2008-02-27 16:08:22 -0600 | [diff] [blame] | 339 | i++; |
Kim Phillips | ee62ed3 | 2008-01-15 14:11:00 -0600 | [diff] [blame] | 340 | udelay(1000); /* 1 ms */ |
| 341 | status = phy_read(mii_info, PHY_BMSR); |
| 342 | } |
| 343 | mii_info->link = 1; |
| 344 | udelay(500000); /* another 500 ms (results in faster booting) */ |
| 345 | } else { |
| 346 | if (status & PHY_BMSR_LS) |
| 347 | mii_info->link = 1; |
| 348 | else |
| 349 | mii_info->link = 0; |
| 350 | } |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 351 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 352 | return 0; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 353 | } |
| 354 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 355 | static int genmii_read_status (struct uec_mii_info *mii_info) |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 356 | { |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 357 | u16 status; |
| 358 | int err; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 359 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 360 | /* Update the link, but return if there |
| 361 | * was an error */ |
| 362 | err = genmii_update_link (mii_info); |
| 363 | if (err) |
| 364 | return err; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 365 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 366 | if (mii_info->autoneg) { |
Anton Vorontsov | 91cdaa3 | 2008-03-24 20:46:24 +0300 | [diff] [blame] | 367 | status = phy_read(mii_info, MII_1000BASETSTATUS); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 368 | |
Anton Vorontsov | 91cdaa3 | 2008-03-24 20:46:24 +0300 | [diff] [blame] | 369 | if (status & (LPA_1000FULL | LPA_1000HALF)) { |
| 370 | mii_info->speed = SPEED_1000; |
| 371 | if (status & LPA_1000FULL) |
| 372 | mii_info->duplex = DUPLEX_FULL; |
| 373 | else |
| 374 | mii_info->duplex = DUPLEX_HALF; |
| 375 | } else { |
| 376 | status = phy_read(mii_info, PHY_ANLPAR); |
| 377 | |
| 378 | if (status & (PHY_ANLPAR_10FD | PHY_ANLPAR_TXFD)) |
| 379 | mii_info->duplex = DUPLEX_FULL; |
| 380 | else |
| 381 | mii_info->duplex = DUPLEX_HALF; |
| 382 | if (status & (PHY_ANLPAR_TXFD | PHY_ANLPAR_TX)) |
| 383 | mii_info->speed = SPEED_100; |
| 384 | else |
| 385 | mii_info->speed = SPEED_10; |
| 386 | } |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 387 | mii_info->pause = 0; |
| 388 | } |
| 389 | /* On non-aneg, we assume what we put in BMCR is the speed, |
| 390 | * though magic-aneg shouldn't prevent this case from occurring |
| 391 | */ |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 392 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 393 | return 0; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 394 | } |
| 395 | |
Anton Vorontsov | 300615d | 2008-03-24 20:46:34 +0300 | [diff] [blame] | 396 | static int bcm_init(struct uec_mii_info *mii_info) |
| 397 | { |
| 398 | struct eth_device *edev = mii_info->dev; |
| 399 | uec_private_t *uec = edev->priv; |
| 400 | |
| 401 | gbit_config_aneg(mii_info); |
| 402 | |
| 403 | if (uec->uec_info->enet_interface == ENET_1000_RGMII_RXID) { |
| 404 | u16 val; |
| 405 | int cnt = 50; |
| 406 | |
| 407 | /* Wait for aneg to complete. */ |
| 408 | do |
| 409 | val = phy_read(mii_info, PHY_BMSR); |
| 410 | while (--cnt && !(val & PHY_BMSR_AUTN_COMP)); |
| 411 | |
| 412 | /* Set RDX clk delay. */ |
| 413 | phy_write(mii_info, 0x18, 0x7 | (7 << 12)); |
| 414 | |
| 415 | val = phy_read(mii_info, 0x18); |
| 416 | /* Set RDX-RXC skew. */ |
| 417 | val |= (1 << 8); |
| 418 | val |= (7 | (7 << 12)); |
| 419 | /* Write bits 14:0. */ |
| 420 | val |= (1 << 15); |
| 421 | phy_write(mii_info, 0x18, val); |
| 422 | } |
| 423 | |
| 424 | return 0; |
| 425 | } |
| 426 | |
Haiying Wang | 41410ee | 2008-09-24 11:42:12 -0500 | [diff] [blame] | 427 | static int marvell_init(struct uec_mii_info *mii_info) |
| 428 | { |
| 429 | struct eth_device *edev = mii_info->dev; |
| 430 | uec_private_t *uec = edev->priv; |
| 431 | |
| 432 | if (uec->uec_info->enet_interface == ENET_1000_RGMII_ID) { |
| 433 | int temp; |
| 434 | |
| 435 | temp = phy_read(mii_info, MII_M1111_PHY_EXT_CR); |
| 436 | temp |= (MII_M1111_RX_DELAY | MII_M1111_TX_DELAY); |
| 437 | phy_write(mii_info, MII_M1111_PHY_EXT_CR, temp); |
| 438 | |
| 439 | temp = phy_read(mii_info, MII_M1111_PHY_EXT_SR); |
| 440 | temp &= ~MII_M1111_HWCFG_MODE_MASK; |
| 441 | temp |= MII_M1111_HWCFG_MODE_RGMII; |
| 442 | phy_write(mii_info, MII_M1111_PHY_EXT_SR, temp); |
| 443 | |
| 444 | phy_write(mii_info, PHY_BMCR, PHY_BMCR_RESET); |
| 445 | } |
| 446 | |
| 447 | return 0; |
| 448 | } |
| 449 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 450 | static int marvell_read_status (struct uec_mii_info *mii_info) |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 451 | { |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 452 | u16 status; |
| 453 | int err; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 454 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 455 | /* Update the link, but return if there |
| 456 | * was an error */ |
| 457 | err = genmii_update_link (mii_info); |
| 458 | if (err) |
| 459 | return err; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 460 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 461 | /* If the link is up, read the speed and duplex */ |
| 462 | /* If we aren't autonegotiating, assume speeds |
| 463 | * are as set */ |
| 464 | if (mii_info->autoneg && mii_info->link) { |
| 465 | int speed; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 466 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 467 | status = phy_read (mii_info, MII_M1011_PHY_SPEC_STATUS); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 468 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 469 | /* Get the duplexity */ |
| 470 | if (status & MII_M1011_PHY_SPEC_STATUS_FULLDUPLEX) |
| 471 | mii_info->duplex = DUPLEX_FULL; |
| 472 | else |
| 473 | mii_info->duplex = DUPLEX_HALF; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 474 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 475 | /* Get the speed */ |
| 476 | speed = status & MII_M1011_PHY_SPEC_STATUS_SPD_MASK; |
| 477 | switch (speed) { |
| 478 | case MII_M1011_PHY_SPEC_STATUS_1000: |
| 479 | mii_info->speed = SPEED_1000; |
| 480 | break; |
| 481 | case MII_M1011_PHY_SPEC_STATUS_100: |
| 482 | mii_info->speed = SPEED_100; |
| 483 | break; |
| 484 | default: |
| 485 | mii_info->speed = SPEED_10; |
| 486 | break; |
| 487 | } |
| 488 | mii_info->pause = 0; |
| 489 | } |
| 490 | |
| 491 | return 0; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 492 | } |
| 493 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 494 | static int marvell_ack_interrupt (struct uec_mii_info *mii_info) |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 495 | { |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 496 | /* Clear the interrupts by reading the reg */ |
| 497 | phy_read (mii_info, MII_M1011_IEVENT); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 498 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 499 | return 0; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 500 | } |
| 501 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 502 | static int marvell_config_intr (struct uec_mii_info *mii_info) |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 503 | { |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 504 | if (mii_info->interrupts == MII_INTERRUPT_ENABLED) |
| 505 | phy_write (mii_info, MII_M1011_IMASK, MII_M1011_IMASK_INIT); |
| 506 | else |
| 507 | phy_write (mii_info, MII_M1011_IMASK, MII_M1011_IMASK_CLEAR); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 508 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 509 | return 0; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 510 | } |
| 511 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 512 | static int dm9161_init (struct uec_mii_info *mii_info) |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 513 | { |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 514 | /* Reset the PHY */ |
| 515 | phy_write (mii_info, PHY_BMCR, phy_read (mii_info, PHY_BMCR) | |
| 516 | PHY_BMCR_RESET); |
| 517 | /* PHY and MAC connect */ |
| 518 | phy_write (mii_info, PHY_BMCR, phy_read (mii_info, PHY_BMCR) & |
| 519 | ~PHY_BMCR_ISO); |
Kim Phillips | ee62ed3 | 2008-01-15 14:11:00 -0600 | [diff] [blame] | 520 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 521 | phy_write (mii_info, MII_DM9161_SCR, MII_DM9161_SCR_INIT); |
Kim Phillips | ee62ed3 | 2008-01-15 14:11:00 -0600 | [diff] [blame] | 522 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 523 | config_genmii_advert (mii_info); |
| 524 | /* Start/restart aneg */ |
| 525 | genmii_config_aneg (mii_info); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 526 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 527 | return 0; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 528 | } |
| 529 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 530 | static int dm9161_config_aneg (struct uec_mii_info *mii_info) |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 531 | { |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 532 | return 0; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 533 | } |
| 534 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 535 | static int dm9161_read_status (struct uec_mii_info *mii_info) |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 536 | { |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 537 | u16 status; |
| 538 | int err; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 539 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 540 | /* Update the link, but return if there was an error */ |
| 541 | err = genmii_update_link (mii_info); |
| 542 | if (err) |
| 543 | return err; |
| 544 | /* If the link is up, read the speed and duplex |
| 545 | If we aren't autonegotiating assume speeds are as set */ |
| 546 | if (mii_info->autoneg && mii_info->link) { |
| 547 | status = phy_read (mii_info, MII_DM9161_SCSR); |
| 548 | if (status & (MII_DM9161_SCSR_100F | MII_DM9161_SCSR_100H)) |
| 549 | mii_info->speed = SPEED_100; |
| 550 | else |
| 551 | mii_info->speed = SPEED_10; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 552 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 553 | if (status & (MII_DM9161_SCSR_100F | MII_DM9161_SCSR_10F)) |
| 554 | mii_info->duplex = DUPLEX_FULL; |
| 555 | else |
| 556 | mii_info->duplex = DUPLEX_HALF; |
| 557 | } |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 558 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 559 | return 0; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 560 | } |
| 561 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 562 | static int dm9161_ack_interrupt (struct uec_mii_info *mii_info) |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 563 | { |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 564 | /* Clear the interrupt by reading the reg */ |
| 565 | phy_read (mii_info, MII_DM9161_INTR); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 566 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 567 | return 0; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 568 | } |
| 569 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 570 | static int dm9161_config_intr (struct uec_mii_info *mii_info) |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 571 | { |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 572 | if (mii_info->interrupts == MII_INTERRUPT_ENABLED) |
| 573 | phy_write (mii_info, MII_DM9161_INTR, MII_DM9161_INTR_INIT); |
| 574 | else |
| 575 | phy_write (mii_info, MII_DM9161_INTR, MII_DM9161_INTR_STOP); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 576 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 577 | return 0; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 578 | } |
| 579 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 580 | static void dm9161_close (struct uec_mii_info *mii_info) |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 581 | { |
| 582 | } |
| 583 | |
Richard Retanubun | edf3fe7 | 2008-10-23 09:08:18 -0400 | [diff] [blame] | 584 | static int fixed_phy_aneg (struct uec_mii_info *mii_info) |
| 585 | { |
| 586 | mii_info->autoneg = 0; /* Turn off auto negotiation for fixed phy */ |
| 587 | return 0; |
| 588 | } |
| 589 | |
| 590 | static int fixed_phy_read_status (struct uec_mii_info *mii_info) |
| 591 | { |
| 592 | int i = 0; |
| 593 | |
| 594 | for (i = 0; i < ARRAY_SIZE(fixed_phy_port); i++) { |
| 595 | if (mii_info->mii_id == fixed_phy_port[i].devnum) { |
| 596 | mii_info->speed = fixed_phy_port[i].speed; |
| 597 | mii_info->duplex = fixed_phy_port[i].duplex; |
| 598 | mii_info->link = 1; /* Link is always UP */ |
| 599 | mii_info->pause = 0; |
| 600 | break; |
| 601 | } |
| 602 | } |
| 603 | return 0; |
| 604 | } |
| 605 | |
Heiko Schocher | 8b69b56 | 2008-11-20 09:57:14 +0100 | [diff] [blame] | 606 | static int smsc_config_aneg (struct uec_mii_info *mii_info) |
| 607 | { |
| 608 | return 0; |
| 609 | } |
| 610 | |
| 611 | static int smsc_read_status (struct uec_mii_info *mii_info) |
| 612 | { |
| 613 | u16 status; |
| 614 | int err; |
| 615 | |
| 616 | /* Update the link, but return if there |
| 617 | * was an error */ |
| 618 | err = genmii_update_link (mii_info); |
| 619 | if (err) |
| 620 | return err; |
| 621 | |
| 622 | /* If the link is up, read the speed and duplex */ |
| 623 | /* If we aren't autonegotiating, assume speeds |
| 624 | * are as set */ |
| 625 | if (mii_info->autoneg && mii_info->link) { |
| 626 | int val; |
| 627 | |
| 628 | status = phy_read (mii_info, 0x1f); |
| 629 | val = (status & 0x1c) >> 2; |
| 630 | |
| 631 | switch (val) { |
| 632 | case 1: |
| 633 | mii_info->duplex = DUPLEX_HALF; |
| 634 | mii_info->speed = SPEED_10; |
| 635 | break; |
| 636 | case 5: |
| 637 | mii_info->duplex = DUPLEX_FULL; |
| 638 | mii_info->speed = SPEED_10; |
| 639 | break; |
| 640 | case 2: |
| 641 | mii_info->duplex = DUPLEX_HALF; |
| 642 | mii_info->speed = SPEED_100; |
| 643 | break; |
| 644 | case 6: |
| 645 | mii_info->duplex = DUPLEX_FULL; |
| 646 | mii_info->speed = SPEED_100; |
| 647 | break; |
| 648 | } |
| 649 | mii_info->pause = 0; |
| 650 | } |
| 651 | |
| 652 | return 0; |
| 653 | } |
| 654 | |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 655 | static struct phy_info phy_info_dm9161 = { |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 656 | .phy_id = 0x0181b880, |
| 657 | .phy_id_mask = 0x0ffffff0, |
| 658 | .name = "Davicom DM9161E", |
| 659 | .init = dm9161_init, |
| 660 | .config_aneg = dm9161_config_aneg, |
| 661 | .read_status = dm9161_read_status, |
| 662 | .close = dm9161_close, |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 663 | }; |
| 664 | |
| 665 | static struct phy_info phy_info_dm9161a = { |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 666 | .phy_id = 0x0181b8a0, |
| 667 | .phy_id_mask = 0x0ffffff0, |
| 668 | .name = "Davicom DM9161A", |
| 669 | .features = MII_BASIC_FEATURES, |
| 670 | .init = dm9161_init, |
| 671 | .config_aneg = dm9161_config_aneg, |
| 672 | .read_status = dm9161_read_status, |
| 673 | .ack_interrupt = dm9161_ack_interrupt, |
| 674 | .config_intr = dm9161_config_intr, |
| 675 | .close = dm9161_close, |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 676 | }; |
| 677 | |
| 678 | static struct phy_info phy_info_marvell = { |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 679 | .phy_id = 0x01410c00, |
| 680 | .phy_id_mask = 0xffffff00, |
| 681 | .name = "Marvell 88E11x1", |
| 682 | .features = MII_GBIT_FEATURES, |
Haiying Wang | 41410ee | 2008-09-24 11:42:12 -0500 | [diff] [blame] | 683 | .init = &marvell_init, |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 684 | .config_aneg = &marvell_config_aneg, |
| 685 | .read_status = &marvell_read_status, |
| 686 | .ack_interrupt = &marvell_ack_interrupt, |
| 687 | .config_intr = &marvell_config_intr, |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 688 | }; |
| 689 | |
Anton Vorontsov | 300615d | 2008-03-24 20:46:34 +0300 | [diff] [blame] | 690 | static struct phy_info phy_info_bcm5481 = { |
| 691 | .phy_id = 0x0143bca0, |
| 692 | .phy_id_mask = 0xffffff0, |
| 693 | .name = "Broadcom 5481", |
| 694 | .features = MII_GBIT_FEATURES, |
| 695 | .read_status = genmii_read_status, |
| 696 | .init = bcm_init, |
| 697 | }; |
| 698 | |
Richard Retanubun | edf3fe7 | 2008-10-23 09:08:18 -0400 | [diff] [blame] | 699 | static struct phy_info phy_info_fixedphy = { |
| 700 | .phy_id = CONFIG_FIXED_PHY, |
| 701 | .phy_id_mask = CONFIG_FIXED_PHY, |
| 702 | .name = "Fixed PHY", |
| 703 | .config_aneg = fixed_phy_aneg, |
| 704 | .read_status = fixed_phy_read_status, |
| 705 | }; |
| 706 | |
Heiko Schocher | 8b69b56 | 2008-11-20 09:57:14 +0100 | [diff] [blame] | 707 | static struct phy_info phy_info_smsclan8700 = { |
| 708 | .phy_id = 0x0007c0c0, |
| 709 | .phy_id_mask = 0xfffffff0, |
| 710 | .name = "SMSC LAN8700", |
| 711 | .features = MII_BASIC_FEATURES, |
| 712 | .config_aneg = smsc_config_aneg, |
| 713 | .read_status = smsc_read_status, |
| 714 | }; |
| 715 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 716 | static struct phy_info phy_info_genmii = { |
| 717 | .phy_id = 0x00000000, |
| 718 | .phy_id_mask = 0x00000000, |
| 719 | .name = "Generic MII", |
| 720 | .features = MII_BASIC_FEATURES, |
| 721 | .config_aneg = genmii_config_aneg, |
| 722 | .read_status = genmii_read_status, |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 723 | }; |
| 724 | |
| 725 | static struct phy_info *phy_info[] = { |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 726 | &phy_info_dm9161, |
| 727 | &phy_info_dm9161a, |
| 728 | &phy_info_marvell, |
Anton Vorontsov | 300615d | 2008-03-24 20:46:34 +0300 | [diff] [blame] | 729 | &phy_info_bcm5481, |
Heiko Schocher | 8b69b56 | 2008-11-20 09:57:14 +0100 | [diff] [blame] | 730 | &phy_info_smsclan8700, |
Richard Retanubun | edf3fe7 | 2008-10-23 09:08:18 -0400 | [diff] [blame] | 731 | &phy_info_fixedphy, |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 732 | &phy_info_genmii, |
| 733 | NULL |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 734 | }; |
| 735 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 736 | u16 phy_read (struct uec_mii_info *mii_info, u16 regnum) |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 737 | { |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 738 | return mii_info->mdio_read (mii_info->dev, mii_info->mii_id, regnum); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 739 | } |
| 740 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 741 | void phy_write (struct uec_mii_info *mii_info, u16 regnum, u16 val) |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 742 | { |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 743 | mii_info->mdio_write (mii_info->dev, mii_info->mii_id, regnum, val); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | /* Use the PHY ID registers to determine what type of PHY is attached |
| 747 | * to device dev. return a struct phy_info structure describing that PHY |
| 748 | */ |
Andy Fleming | da9d461 | 2007-08-14 00:14:25 -0500 | [diff] [blame] | 749 | struct phy_info *uec_get_phy_info (struct uec_mii_info *mii_info) |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 750 | { |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 751 | u16 phy_reg; |
| 752 | u32 phy_ID; |
| 753 | int i; |
| 754 | struct phy_info *theInfo = NULL; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 755 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 756 | /* Grab the bits from PHYIR1, and put them in the upper half */ |
| 757 | phy_reg = phy_read (mii_info, PHY_PHYIDR1); |
| 758 | phy_ID = (phy_reg & 0xffff) << 16; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 759 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 760 | /* Grab the bits from PHYIR2, and put them in the lower half */ |
| 761 | phy_reg = phy_read (mii_info, PHY_PHYIDR2); |
| 762 | phy_ID |= (phy_reg & 0xffff); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 763 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 764 | /* loop through all the known PHY types, and find one that */ |
| 765 | /* matches the ID we read from the PHY. */ |
| 766 | for (i = 0; phy_info[i]; i++) |
| 767 | if (phy_info[i]->phy_id == |
| 768 | (phy_ID & phy_info[i]->phy_id_mask)) { |
| 769 | theInfo = phy_info[i]; |
| 770 | break; |
| 771 | } |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 772 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 773 | /* This shouldn't happen, as we have generic PHY support */ |
| 774 | if (theInfo == NULL) { |
| 775 | ugphy_info ("UEC: PHY id %x is not supported!", phy_ID); |
| 776 | return NULL; |
| 777 | } else { |
| 778 | ugphy_info ("UEC: PHY is %s (%x)", theInfo->name, phy_ID); |
| 779 | } |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 780 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 781 | return theInfo; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 782 | } |
| 783 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 784 | void marvell_phy_interface_mode (struct eth_device *dev, |
| 785 | enet_interface_e mode) |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 786 | { |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 787 | uec_private_t *uec = (uec_private_t *) dev->priv; |
| 788 | struct uec_mii_info *mii_info; |
Kim Phillips | f655ade | 2008-02-27 15:06:39 -0600 | [diff] [blame] | 789 | u16 status; |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 790 | |
| 791 | if (!uec->mii_info) { |
Kim Phillips | f30b6154 | 2008-02-27 16:08:22 -0600 | [diff] [blame] | 792 | printf ("%s: the PHY not initialized\n", __FUNCTION__); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 793 | return; |
| 794 | } |
| 795 | mii_info = uec->mii_info; |
| 796 | |
| 797 | if (mode == ENET_100_RGMII) { |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 798 | phy_write (mii_info, 0x00, 0x9140); |
| 799 | phy_write (mii_info, 0x1d, 0x001f); |
| 800 | phy_write (mii_info, 0x1e, 0x200c); |
| 801 | phy_write (mii_info, 0x1d, 0x0005); |
| 802 | phy_write (mii_info, 0x1e, 0x0000); |
| 803 | phy_write (mii_info, 0x1e, 0x0100); |
| 804 | phy_write (mii_info, 0x09, 0x0e00); |
| 805 | phy_write (mii_info, 0x04, 0x01e1); |
| 806 | phy_write (mii_info, 0x00, 0x9140); |
| 807 | phy_write (mii_info, 0x00, 0x1000); |
| 808 | udelay (100000); |
| 809 | phy_write (mii_info, 0x00, 0x2900); |
| 810 | phy_write (mii_info, 0x14, 0x0cd2); |
| 811 | phy_write (mii_info, 0x00, 0xa100); |
| 812 | phy_write (mii_info, 0x09, 0x0000); |
| 813 | phy_write (mii_info, 0x1b, 0x800b); |
| 814 | phy_write (mii_info, 0x04, 0x05e1); |
| 815 | phy_write (mii_info, 0x00, 0xa100); |
| 816 | phy_write (mii_info, 0x00, 0x2100); |
| 817 | udelay (1000000); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 818 | } else if (mode == ENET_10_RGMII) { |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 819 | phy_write (mii_info, 0x14, 0x8e40); |
| 820 | phy_write (mii_info, 0x1b, 0x800b); |
| 821 | phy_write (mii_info, 0x14, 0x0c82); |
| 822 | phy_write (mii_info, 0x00, 0x8100); |
| 823 | udelay (1000000); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 824 | } |
Kim Phillips | f655ade | 2008-02-27 15:06:39 -0600 | [diff] [blame] | 825 | |
| 826 | /* handle 88e1111 rev.B2 erratum 5.6 */ |
| 827 | if (mii_info->autoneg) { |
| 828 | status = phy_read (mii_info, PHY_BMCR); |
| 829 | phy_write (mii_info, PHY_BMCR, status | PHY_BMCR_AUTON); |
| 830 | } |
| 831 | /* now the B2 will correctly report autoneg completion status */ |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 832 | } |
| 833 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 834 | void change_phy_interface_mode (struct eth_device *dev, enet_interface_e mode) |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 835 | { |
| 836 | #ifdef CONFIG_PHY_MODE_NEED_CHANGE |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 837 | marvell_phy_interface_mode (dev, mode); |
Dave Liu | 7737d5c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 838 | #endif |
| 839 | } |