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