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