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