Dave Liu | e732e9c | 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 | 87b3d4b | 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 | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 9 | * |
Wolfgang Denk | 87b3d4b | 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 | e732e9c | 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 | |
| 29 | #if defined(CONFIG_QE) |
| 30 | |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 31 | #define ugphy_printk(format, arg...) \ |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 32 | printf(format "\n", ## arg) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 33 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 34 | #define ugphy_dbg(format, arg...) \ |
| 35 | ugphy_printk(format , ## arg) |
| 36 | #define ugphy_err(format, arg...) \ |
| 37 | ugphy_printk(format , ## arg) |
| 38 | #define ugphy_info(format, arg...) \ |
| 39 | ugphy_printk(format , ## arg) |
| 40 | #define ugphy_warn(format, arg...) \ |
| 41 | ugphy_printk(format , ## arg) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 42 | |
| 43 | #ifdef UEC_VERBOSE_DEBUG |
| 44 | #define ugphy_vdbg ugphy_dbg |
| 45 | #else |
| 46 | #define ugphy_vdbg(ugeth, fmt, args...) do { } while (0) |
| 47 | #endif /* UEC_VERBOSE_DEBUG */ |
| 48 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 49 | static void config_genmii_advert (struct uec_mii_info *mii_info); |
| 50 | static void genmii_setup_forced (struct uec_mii_info *mii_info); |
| 51 | static void genmii_restart_aneg (struct uec_mii_info *mii_info); |
| 52 | static int gbit_config_aneg (struct uec_mii_info *mii_info); |
| 53 | static int genmii_config_aneg (struct uec_mii_info *mii_info); |
| 54 | static int genmii_update_link (struct uec_mii_info *mii_info); |
| 55 | static int genmii_read_status (struct uec_mii_info *mii_info); |
| 56 | u16 phy_read (struct uec_mii_info *mii_info, u16 regnum); |
| 57 | void phy_write (struct uec_mii_info *mii_info, u16 regnum, u16 val); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 58 | |
| 59 | /* Write value to the PHY for this device to the register at regnum, */ |
| 60 | /* waiting until the write is done before it returns. All PHY */ |
| 61 | /* configuration has to be done through the TSEC1 MIIM regs */ |
Andy Fleming | ee0e917 | 2007-08-14 00:14:25 -0500 | [diff] [blame] | 62 | void uec_write_phy_reg (struct eth_device *dev, int mii_id, int regnum, int value) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 63 | { |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 64 | uec_private_t *ugeth = (uec_private_t *) dev->priv; |
Andy Fleming | ee0e917 | 2007-08-14 00:14:25 -0500 | [diff] [blame] | 65 | uec_mii_t *ug_regs; |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 66 | enet_tbi_mii_reg_e mii_reg = (enet_tbi_mii_reg_e) regnum; |
| 67 | u32 tmp_reg; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 68 | |
Andy Fleming | ee0e917 | 2007-08-14 00:14:25 -0500 | [diff] [blame] | 69 | ug_regs = ugeth->uec_mii_regs; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 70 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 71 | /* Stop the MII management read cycle */ |
| 72 | out_be32 (&ug_regs->miimcom, 0); |
| 73 | /* Setting up the MII Mangement Address Register */ |
| 74 | tmp_reg = ((u32) mii_id << MIIMADD_PHY_ADDRESS_SHIFT) | mii_reg; |
| 75 | out_be32 (&ug_regs->miimadd, tmp_reg); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 76 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 77 | /* Setting up the MII Mangement Control Register with the value */ |
| 78 | out_be32 (&ug_regs->miimcon, (u32) value); |
Kim Phillips | d986cba | 2008-01-15 14:11:00 -0600 | [diff] [blame] | 79 | sync(); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 80 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 81 | /* Wait till MII management write is complete */ |
| 82 | while ((in_be32 (&ug_regs->miimind)) & MIIMIND_BUSY); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | /* Reads from register regnum in the PHY for device dev, */ |
| 86 | /* returning the value. Clears miimcom first. All PHY */ |
| 87 | /* configuration has to be done through the TSEC1 MIIM regs */ |
Andy Fleming | ee0e917 | 2007-08-14 00:14:25 -0500 | [diff] [blame] | 88 | int uec_read_phy_reg (struct eth_device *dev, int mii_id, int regnum) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 89 | { |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 90 | uec_private_t *ugeth = (uec_private_t *) dev->priv; |
Andy Fleming | ee0e917 | 2007-08-14 00:14:25 -0500 | [diff] [blame] | 91 | uec_mii_t *ug_regs; |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 92 | enet_tbi_mii_reg_e mii_reg = (enet_tbi_mii_reg_e) regnum; |
| 93 | u32 tmp_reg; |
| 94 | u16 value; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 95 | |
Andy Fleming | ee0e917 | 2007-08-14 00:14:25 -0500 | [diff] [blame] | 96 | ug_regs = ugeth->uec_mii_regs; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 97 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 98 | /* Setting up the MII Mangement Address Register */ |
| 99 | tmp_reg = ((u32) mii_id << MIIMADD_PHY_ADDRESS_SHIFT) | mii_reg; |
| 100 | out_be32 (&ug_regs->miimadd, tmp_reg); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 101 | |
Kim Phillips | d986cba | 2008-01-15 14:11:00 -0600 | [diff] [blame] | 102 | /* clear MII management command cycle */ |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 103 | out_be32 (&ug_regs->miimcom, 0); |
Kim Phillips | d986cba | 2008-01-15 14:11:00 -0600 | [diff] [blame] | 104 | sync(); |
| 105 | |
| 106 | /* Perform an MII management read cycle */ |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 107 | out_be32 (&ug_regs->miimcom, MIIMCOM_READ_CYCLE); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 108 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 109 | /* Wait till MII management write is complete */ |
| 110 | while ((in_be32 (&ug_regs->miimind)) & |
| 111 | (MIIMIND_NOT_VALID | MIIMIND_BUSY)); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 112 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 113 | /* Read MII management status */ |
| 114 | value = (u16) in_be32 (&ug_regs->miimstat); |
| 115 | if (value == 0xffff) |
Joakim Tjernlund | 3d7f255 | 2008-01-16 09:40:41 +0100 | [diff] [blame] | 116 | ugphy_vdbg |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 117 | ("read wrong value : mii_id %d,mii_reg %d, base %08x", |
| 118 | mii_id, mii_reg, (u32) & (ug_regs->miimcfg)); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 119 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 120 | return (value); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 121 | } |
| 122 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 123 | void mii_clear_phy_interrupt (struct uec_mii_info *mii_info) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 124 | { |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 125 | if (mii_info->phyinfo->ack_interrupt) |
| 126 | mii_info->phyinfo->ack_interrupt (mii_info); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 127 | } |
| 128 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 129 | void mii_configure_phy_interrupt (struct uec_mii_info *mii_info, |
| 130 | u32 interrupts) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 131 | { |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 132 | mii_info->interrupts = interrupts; |
| 133 | if (mii_info->phyinfo->config_intr) |
| 134 | mii_info->phyinfo->config_intr (mii_info); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | /* Writes MII_ADVERTISE with the appropriate values, after |
| 138 | * sanitizing advertise to make sure only supported features |
| 139 | * are advertised |
| 140 | */ |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 141 | static void config_genmii_advert (struct uec_mii_info *mii_info) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 142 | { |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 143 | u32 advertise; |
| 144 | u16 adv; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 145 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 146 | /* Only allow advertising what this PHY supports */ |
| 147 | mii_info->advertising &= mii_info->phyinfo->features; |
| 148 | advertise = mii_info->advertising; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 149 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 150 | /* Setup standard advertisement */ |
| 151 | adv = phy_read (mii_info, PHY_ANAR); |
| 152 | adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4); |
| 153 | if (advertise & ADVERTISED_10baseT_Half) |
| 154 | adv |= ADVERTISE_10HALF; |
| 155 | if (advertise & ADVERTISED_10baseT_Full) |
| 156 | adv |= ADVERTISE_10FULL; |
| 157 | if (advertise & ADVERTISED_100baseT_Half) |
| 158 | adv |= ADVERTISE_100HALF; |
| 159 | if (advertise & ADVERTISED_100baseT_Full) |
| 160 | adv |= ADVERTISE_100FULL; |
| 161 | phy_write (mii_info, PHY_ANAR, adv); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 162 | } |
| 163 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 164 | static void genmii_setup_forced (struct uec_mii_info *mii_info) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 165 | { |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 166 | u16 ctrl; |
| 167 | u32 features = mii_info->phyinfo->features; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 168 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 169 | ctrl = phy_read (mii_info, PHY_BMCR); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 170 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 171 | ctrl &= ~(PHY_BMCR_DPLX | PHY_BMCR_100_MBPS | |
| 172 | PHY_BMCR_1000_MBPS | PHY_BMCR_AUTON); |
| 173 | ctrl |= PHY_BMCR_RESET; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 174 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 175 | switch (mii_info->speed) { |
| 176 | case SPEED_1000: |
| 177 | if (features & (SUPPORTED_1000baseT_Half |
| 178 | | SUPPORTED_1000baseT_Full)) { |
| 179 | ctrl |= PHY_BMCR_1000_MBPS; |
| 180 | break; |
| 181 | } |
| 182 | mii_info->speed = SPEED_100; |
| 183 | case SPEED_100: |
| 184 | if (features & (SUPPORTED_100baseT_Half |
| 185 | | SUPPORTED_100baseT_Full)) { |
| 186 | ctrl |= PHY_BMCR_100_MBPS; |
| 187 | break; |
| 188 | } |
| 189 | mii_info->speed = SPEED_10; |
| 190 | case SPEED_10: |
| 191 | if (features & (SUPPORTED_10baseT_Half |
| 192 | | SUPPORTED_10baseT_Full)) |
| 193 | break; |
| 194 | default: /* Unsupported speed! */ |
| 195 | ugphy_err ("%s: Bad speed!", mii_info->dev->name); |
| 196 | break; |
| 197 | } |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 198 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 199 | phy_write (mii_info, PHY_BMCR, ctrl); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | /* Enable and Restart Autonegotiation */ |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 203 | static void genmii_restart_aneg (struct uec_mii_info *mii_info) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 204 | { |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 205 | u16 ctl; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 206 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 207 | ctl = phy_read (mii_info, PHY_BMCR); |
| 208 | ctl |= (PHY_BMCR_AUTON | PHY_BMCR_RST_NEG); |
| 209 | phy_write (mii_info, PHY_BMCR, ctl); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 210 | } |
| 211 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 212 | static int gbit_config_aneg (struct uec_mii_info *mii_info) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 213 | { |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 214 | u16 adv; |
| 215 | u32 advertise; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 216 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 217 | if (mii_info->autoneg) { |
| 218 | /* Configure the ADVERTISE register */ |
| 219 | config_genmii_advert (mii_info); |
| 220 | advertise = mii_info->advertising; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 221 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 222 | adv = phy_read (mii_info, MII_1000BASETCONTROL); |
| 223 | adv &= ~(MII_1000BASETCONTROL_FULLDUPLEXCAP | |
| 224 | MII_1000BASETCONTROL_HALFDUPLEXCAP); |
| 225 | if (advertise & SUPPORTED_1000baseT_Half) |
| 226 | adv |= MII_1000BASETCONTROL_HALFDUPLEXCAP; |
| 227 | if (advertise & SUPPORTED_1000baseT_Full) |
| 228 | adv |= MII_1000BASETCONTROL_FULLDUPLEXCAP; |
| 229 | phy_write (mii_info, MII_1000BASETCONTROL, adv); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 230 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 231 | /* Start/Restart aneg */ |
| 232 | genmii_restart_aneg (mii_info); |
| 233 | } else |
| 234 | genmii_setup_forced (mii_info); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 235 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 236 | return 0; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 237 | } |
| 238 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 239 | static int marvell_config_aneg (struct uec_mii_info *mii_info) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 240 | { |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 241 | /* The Marvell PHY has an errata which requires |
| 242 | * that certain registers get written in order |
| 243 | * to restart autonegotiation */ |
| 244 | phy_write (mii_info, PHY_BMCR, PHY_BMCR_RESET); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 245 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 246 | phy_write (mii_info, 0x1d, 0x1f); |
| 247 | phy_write (mii_info, 0x1e, 0x200c); |
| 248 | phy_write (mii_info, 0x1d, 0x5); |
| 249 | phy_write (mii_info, 0x1e, 0); |
| 250 | phy_write (mii_info, 0x1e, 0x100); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 251 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 252 | gbit_config_aneg (mii_info); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 253 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 254 | return 0; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 255 | } |
| 256 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 257 | static int genmii_config_aneg (struct uec_mii_info *mii_info) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 258 | { |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 259 | if (mii_info->autoneg) { |
| 260 | config_genmii_advert (mii_info); |
| 261 | genmii_restart_aneg (mii_info); |
| 262 | } else |
| 263 | genmii_setup_forced (mii_info); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 264 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 265 | return 0; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 266 | } |
| 267 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 268 | static int genmii_update_link (struct uec_mii_info *mii_info) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 269 | { |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 270 | u16 status; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 271 | |
Kim Phillips | d986cba | 2008-01-15 14:11:00 -0600 | [diff] [blame] | 272 | /* Status is read once to clear old link state */ |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 273 | phy_read (mii_info, PHY_BMSR); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 274 | |
Kim Phillips | d986cba | 2008-01-15 14:11:00 -0600 | [diff] [blame] | 275 | /* |
| 276 | * Wait if the link is up, and autonegotiation is in progress |
| 277 | * (ie - we're capable and it's not done) |
| 278 | */ |
| 279 | status = phy_read(mii_info, PHY_BMSR); |
| 280 | if ((status & PHY_BMSR_LS) && (status & PHY_BMSR_AUTN_ABLE) |
| 281 | && !(status & PHY_BMSR_AUTN_COMP)) { |
| 282 | int i = 0; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 283 | |
Kim Phillips | d986cba | 2008-01-15 14:11:00 -0600 | [diff] [blame] | 284 | while (!(status & PHY_BMSR_AUTN_COMP)) { |
| 285 | /* |
| 286 | * Timeout reached ? |
| 287 | */ |
| 288 | if (i > UGETH_AN_TIMEOUT) { |
| 289 | mii_info->link = 0; |
| 290 | return 0; |
| 291 | } |
| 292 | |
Kim Phillips | b5da427 | 2008-02-27 16:08:22 -0600 | [diff] [blame^] | 293 | i++; |
Kim Phillips | d986cba | 2008-01-15 14:11:00 -0600 | [diff] [blame] | 294 | udelay(1000); /* 1 ms */ |
| 295 | status = phy_read(mii_info, PHY_BMSR); |
| 296 | } |
| 297 | mii_info->link = 1; |
| 298 | udelay(500000); /* another 500 ms (results in faster booting) */ |
| 299 | } else { |
| 300 | if (status & PHY_BMSR_LS) |
| 301 | mii_info->link = 1; |
| 302 | else |
| 303 | mii_info->link = 0; |
| 304 | } |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 305 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 306 | return 0; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 307 | } |
| 308 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 309 | static int genmii_read_status (struct uec_mii_info *mii_info) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 310 | { |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 311 | u16 status; |
| 312 | int err; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 313 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 314 | /* Update the link, but return if there |
| 315 | * was an error */ |
| 316 | err = genmii_update_link (mii_info); |
| 317 | if (err) |
| 318 | return err; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 319 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 320 | if (mii_info->autoneg) { |
| 321 | status = phy_read (mii_info, PHY_ANLPAR); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 322 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 323 | if (status & (PHY_ANLPAR_10FD | PHY_ANLPAR_TXFD)) |
| 324 | mii_info->duplex = DUPLEX_FULL; |
| 325 | else |
| 326 | mii_info->duplex = DUPLEX_HALF; |
| 327 | if (status & (PHY_ANLPAR_TXFD | PHY_ANLPAR_TX)) |
| 328 | mii_info->speed = SPEED_100; |
| 329 | else |
| 330 | mii_info->speed = SPEED_10; |
| 331 | mii_info->pause = 0; |
| 332 | } |
| 333 | /* On non-aneg, we assume what we put in BMCR is the speed, |
| 334 | * though magic-aneg shouldn't prevent this case from occurring |
| 335 | */ |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 336 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 337 | return 0; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 338 | } |
| 339 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 340 | static int marvell_read_status (struct uec_mii_info *mii_info) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 341 | { |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 342 | u16 status; |
| 343 | int err; |
| 344 | |
| 345 | /* Update the link, but return if there |
| 346 | * was an error */ |
| 347 | err = genmii_update_link (mii_info); |
| 348 | if (err) |
| 349 | return err; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 350 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 351 | /* If the link is up, read the speed and duplex */ |
| 352 | /* If we aren't autonegotiating, assume speeds |
| 353 | * are as set */ |
| 354 | if (mii_info->autoneg && mii_info->link) { |
| 355 | int speed; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 356 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 357 | status = phy_read (mii_info, MII_M1011_PHY_SPEC_STATUS); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 358 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 359 | /* Get the duplexity */ |
| 360 | if (status & MII_M1011_PHY_SPEC_STATUS_FULLDUPLEX) |
| 361 | mii_info->duplex = DUPLEX_FULL; |
| 362 | else |
| 363 | mii_info->duplex = DUPLEX_HALF; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 364 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 365 | /* Get the speed */ |
| 366 | speed = status & MII_M1011_PHY_SPEC_STATUS_SPD_MASK; |
| 367 | switch (speed) { |
| 368 | case MII_M1011_PHY_SPEC_STATUS_1000: |
| 369 | mii_info->speed = SPEED_1000; |
| 370 | break; |
| 371 | case MII_M1011_PHY_SPEC_STATUS_100: |
| 372 | mii_info->speed = SPEED_100; |
| 373 | break; |
| 374 | default: |
| 375 | mii_info->speed = SPEED_10; |
| 376 | break; |
| 377 | } |
| 378 | mii_info->pause = 0; |
| 379 | } |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 380 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 381 | return 0; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 382 | } |
| 383 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 384 | static int marvell_ack_interrupt (struct uec_mii_info *mii_info) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 385 | { |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 386 | /* Clear the interrupts by reading the reg */ |
| 387 | phy_read (mii_info, MII_M1011_IEVENT); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 388 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 389 | return 0; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 390 | } |
| 391 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 392 | static int marvell_config_intr (struct uec_mii_info *mii_info) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 393 | { |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 394 | if (mii_info->interrupts == MII_INTERRUPT_ENABLED) |
| 395 | phy_write (mii_info, MII_M1011_IMASK, MII_M1011_IMASK_INIT); |
| 396 | else |
| 397 | phy_write (mii_info, MII_M1011_IMASK, MII_M1011_IMASK_CLEAR); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 398 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 399 | return 0; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 400 | } |
| 401 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 402 | static int dm9161_init (struct uec_mii_info *mii_info) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 403 | { |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 404 | /* Reset the PHY */ |
| 405 | phy_write (mii_info, PHY_BMCR, phy_read (mii_info, PHY_BMCR) | |
| 406 | PHY_BMCR_RESET); |
| 407 | /* PHY and MAC connect */ |
| 408 | phy_write (mii_info, PHY_BMCR, phy_read (mii_info, PHY_BMCR) & |
| 409 | ~PHY_BMCR_ISO); |
Kim Phillips | d986cba | 2008-01-15 14:11:00 -0600 | [diff] [blame] | 410 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 411 | phy_write (mii_info, MII_DM9161_SCR, MII_DM9161_SCR_INIT); |
Kim Phillips | d986cba | 2008-01-15 14:11:00 -0600 | [diff] [blame] | 412 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 413 | config_genmii_advert (mii_info); |
| 414 | /* Start/restart aneg */ |
| 415 | genmii_config_aneg (mii_info); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 416 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 417 | return 0; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 418 | } |
| 419 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 420 | static int dm9161_config_aneg (struct uec_mii_info *mii_info) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 421 | { |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 422 | return 0; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 423 | } |
| 424 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 425 | static int dm9161_read_status (struct uec_mii_info *mii_info) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 426 | { |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 427 | u16 status; |
| 428 | int err; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 429 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 430 | /* Update the link, but return if there was an error */ |
| 431 | err = genmii_update_link (mii_info); |
| 432 | if (err) |
| 433 | return err; |
| 434 | /* If the link is up, read the speed and duplex |
| 435 | If we aren't autonegotiating assume speeds are as set */ |
| 436 | if (mii_info->autoneg && mii_info->link) { |
| 437 | status = phy_read (mii_info, MII_DM9161_SCSR); |
| 438 | if (status & (MII_DM9161_SCSR_100F | MII_DM9161_SCSR_100H)) |
| 439 | mii_info->speed = SPEED_100; |
| 440 | else |
| 441 | mii_info->speed = SPEED_10; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 442 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 443 | if (status & (MII_DM9161_SCSR_100F | MII_DM9161_SCSR_10F)) |
| 444 | mii_info->duplex = DUPLEX_FULL; |
| 445 | else |
| 446 | mii_info->duplex = DUPLEX_HALF; |
| 447 | } |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 448 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 449 | return 0; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 450 | } |
| 451 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 452 | static int dm9161_ack_interrupt (struct uec_mii_info *mii_info) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 453 | { |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 454 | /* Clear the interrupt by reading the reg */ |
| 455 | phy_read (mii_info, MII_DM9161_INTR); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 456 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 457 | return 0; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 458 | } |
| 459 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 460 | static int dm9161_config_intr (struct uec_mii_info *mii_info) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 461 | { |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 462 | if (mii_info->interrupts == MII_INTERRUPT_ENABLED) |
| 463 | phy_write (mii_info, MII_DM9161_INTR, MII_DM9161_INTR_INIT); |
| 464 | else |
| 465 | phy_write (mii_info, MII_DM9161_INTR, MII_DM9161_INTR_STOP); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 466 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 467 | return 0; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 468 | } |
| 469 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 470 | static void dm9161_close (struct uec_mii_info *mii_info) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 471 | { |
| 472 | } |
| 473 | |
| 474 | static struct phy_info phy_info_dm9161 = { |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 475 | .phy_id = 0x0181b880, |
| 476 | .phy_id_mask = 0x0ffffff0, |
| 477 | .name = "Davicom DM9161E", |
| 478 | .init = dm9161_init, |
| 479 | .config_aneg = dm9161_config_aneg, |
| 480 | .read_status = dm9161_read_status, |
| 481 | .close = dm9161_close, |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 482 | }; |
| 483 | |
| 484 | static struct phy_info phy_info_dm9161a = { |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 485 | .phy_id = 0x0181b8a0, |
| 486 | .phy_id_mask = 0x0ffffff0, |
| 487 | .name = "Davicom DM9161A", |
| 488 | .features = MII_BASIC_FEATURES, |
| 489 | .init = dm9161_init, |
| 490 | .config_aneg = dm9161_config_aneg, |
| 491 | .read_status = dm9161_read_status, |
| 492 | .ack_interrupt = dm9161_ack_interrupt, |
| 493 | .config_intr = dm9161_config_intr, |
| 494 | .close = dm9161_close, |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 495 | }; |
| 496 | |
| 497 | static struct phy_info phy_info_marvell = { |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 498 | .phy_id = 0x01410c00, |
| 499 | .phy_id_mask = 0xffffff00, |
| 500 | .name = "Marvell 88E11x1", |
| 501 | .features = MII_GBIT_FEATURES, |
| 502 | .config_aneg = &marvell_config_aneg, |
| 503 | .read_status = &marvell_read_status, |
| 504 | .ack_interrupt = &marvell_ack_interrupt, |
| 505 | .config_intr = &marvell_config_intr, |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 506 | }; |
| 507 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 508 | static struct phy_info phy_info_genmii = { |
| 509 | .phy_id = 0x00000000, |
| 510 | .phy_id_mask = 0x00000000, |
| 511 | .name = "Generic MII", |
| 512 | .features = MII_BASIC_FEATURES, |
| 513 | .config_aneg = genmii_config_aneg, |
| 514 | .read_status = genmii_read_status, |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 515 | }; |
| 516 | |
| 517 | static struct phy_info *phy_info[] = { |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 518 | &phy_info_dm9161, |
| 519 | &phy_info_dm9161a, |
| 520 | &phy_info_marvell, |
| 521 | &phy_info_genmii, |
| 522 | NULL |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 523 | }; |
| 524 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 525 | u16 phy_read (struct uec_mii_info *mii_info, u16 regnum) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 526 | { |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 527 | return mii_info->mdio_read (mii_info->dev, mii_info->mii_id, regnum); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 528 | } |
| 529 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 530 | void phy_write (struct uec_mii_info *mii_info, u16 regnum, u16 val) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 531 | { |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 532 | mii_info->mdio_write (mii_info->dev, mii_info->mii_id, regnum, val); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | /* Use the PHY ID registers to determine what type of PHY is attached |
| 536 | * to device dev. return a struct phy_info structure describing that PHY |
| 537 | */ |
Andy Fleming | ee0e917 | 2007-08-14 00:14:25 -0500 | [diff] [blame] | 538 | struct phy_info *uec_get_phy_info (struct uec_mii_info *mii_info) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 539 | { |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 540 | u16 phy_reg; |
| 541 | u32 phy_ID; |
| 542 | int i; |
| 543 | struct phy_info *theInfo = NULL; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 544 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 545 | /* Grab the bits from PHYIR1, and put them in the upper half */ |
| 546 | phy_reg = phy_read (mii_info, PHY_PHYIDR1); |
| 547 | phy_ID = (phy_reg & 0xffff) << 16; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 548 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 549 | /* Grab the bits from PHYIR2, and put them in the lower half */ |
| 550 | phy_reg = phy_read (mii_info, PHY_PHYIDR2); |
| 551 | phy_ID |= (phy_reg & 0xffff); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 552 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 553 | /* loop through all the known PHY types, and find one that */ |
| 554 | /* matches the ID we read from the PHY. */ |
| 555 | for (i = 0; phy_info[i]; i++) |
| 556 | if (phy_info[i]->phy_id == |
| 557 | (phy_ID & phy_info[i]->phy_id_mask)) { |
| 558 | theInfo = phy_info[i]; |
| 559 | break; |
| 560 | } |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 561 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 562 | /* This shouldn't happen, as we have generic PHY support */ |
| 563 | if (theInfo == NULL) { |
| 564 | ugphy_info ("UEC: PHY id %x is not supported!", phy_ID); |
| 565 | return NULL; |
| 566 | } else { |
| 567 | ugphy_info ("UEC: PHY is %s (%x)", theInfo->name, phy_ID); |
| 568 | } |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 569 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 570 | return theInfo; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 571 | } |
| 572 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 573 | void marvell_phy_interface_mode (struct eth_device *dev, |
| 574 | enet_interface_e mode) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 575 | { |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 576 | uec_private_t *uec = (uec_private_t *) dev->priv; |
| 577 | struct uec_mii_info *mii_info; |
Kim Phillips | 2108405 | 2008-02-27 15:06:39 -0600 | [diff] [blame] | 578 | u16 status; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 579 | |
| 580 | if (!uec->mii_info) { |
Kim Phillips | b5da427 | 2008-02-27 16:08:22 -0600 | [diff] [blame^] | 581 | printf ("%s: the PHY not initialized\n", __FUNCTION__); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 582 | return; |
| 583 | } |
| 584 | mii_info = uec->mii_info; |
| 585 | |
| 586 | if (mode == ENET_100_RGMII) { |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 587 | phy_write (mii_info, 0x00, 0x9140); |
| 588 | phy_write (mii_info, 0x1d, 0x001f); |
| 589 | phy_write (mii_info, 0x1e, 0x200c); |
| 590 | phy_write (mii_info, 0x1d, 0x0005); |
| 591 | phy_write (mii_info, 0x1e, 0x0000); |
| 592 | phy_write (mii_info, 0x1e, 0x0100); |
| 593 | phy_write (mii_info, 0x09, 0x0e00); |
| 594 | phy_write (mii_info, 0x04, 0x01e1); |
| 595 | phy_write (mii_info, 0x00, 0x9140); |
| 596 | phy_write (mii_info, 0x00, 0x1000); |
| 597 | udelay (100000); |
| 598 | phy_write (mii_info, 0x00, 0x2900); |
| 599 | phy_write (mii_info, 0x14, 0x0cd2); |
| 600 | phy_write (mii_info, 0x00, 0xa100); |
| 601 | phy_write (mii_info, 0x09, 0x0000); |
| 602 | phy_write (mii_info, 0x1b, 0x800b); |
| 603 | phy_write (mii_info, 0x04, 0x05e1); |
| 604 | phy_write (mii_info, 0x00, 0xa100); |
| 605 | phy_write (mii_info, 0x00, 0x2100); |
| 606 | udelay (1000000); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 607 | } else if (mode == ENET_10_RGMII) { |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 608 | phy_write (mii_info, 0x14, 0x8e40); |
| 609 | phy_write (mii_info, 0x1b, 0x800b); |
| 610 | phy_write (mii_info, 0x14, 0x0c82); |
| 611 | phy_write (mii_info, 0x00, 0x8100); |
| 612 | udelay (1000000); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 613 | } |
Kim Phillips | 2108405 | 2008-02-27 15:06:39 -0600 | [diff] [blame] | 614 | |
| 615 | /* handle 88e1111 rev.B2 erratum 5.6 */ |
| 616 | if (mii_info->autoneg) { |
| 617 | status = phy_read (mii_info, PHY_BMCR); |
| 618 | phy_write (mii_info, PHY_BMCR, status | PHY_BMCR_AUTON); |
| 619 | } |
| 620 | /* now the B2 will correctly report autoneg completion status */ |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 621 | } |
| 622 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 623 | void change_phy_interface_mode (struct eth_device *dev, enet_interface_e mode) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 624 | { |
| 625 | #ifdef CONFIG_PHY_MODE_NEED_CHANGE |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 626 | marvell_phy_interface_mode (dev, mode); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 627 | #endif |
| 628 | } |
| 629 | #endif /* CONFIG_QE */ |