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