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