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