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