blob: 94253797946117304b3f4d9b275529dbbf512d5b [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Dave Liue732e9c2006-11-03 12:11:15 -06002/*
Kumar Gala09036992011-01-19 03:36:40 -06003 * Copyright (C) 2005,2010-2011 Freescale Semiconductor, Inc.
Dave Liue732e9c2006-11-03 12:11:15 -06004 *
5 * Author: Shlomi Gridish
6 *
7 * Description: UCC GETH Driver -- PHY handling
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +01008 * Driver for UEC on QE
9 * Based on 8260_io/fcc_enet.c
Dave Liue732e9c2006-11-03 12:11:15 -060010 */
11
Masahiro Yamadaadae2ec2016-09-21 11:28:53 +090012#include <common.h>
13#include <net.h>
14#include <malloc.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090015#include <linux/errno.h>
Masahiro Yamadaadae2ec2016-09-21 11:28:53 +090016#include <linux/immap_qe.h>
17#include <asm/io.h>
Dave Liue732e9c2006-11-03 12:11:15 -060018#include "uccf.h"
19#include "uec.h"
20#include "uec_phy.h"
21#include "miiphy.h"
Qianyu Gongae6a7582016-02-18 13:01:59 +080022#include <fsl_qe.h>
Andy Fleming7832a462011-04-13 00:37:12 -050023#include <phy.h>
Dave Liue732e9c2006-11-03 12:11:15 -060024
Dave Liue732e9c2006-11-03 12:11:15 -060025#define ugphy_printk(format, arg...) \
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +010026 printf(format "\n", ## arg)
Dave Liue732e9c2006-11-03 12:11:15 -060027
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +010028#define ugphy_dbg(format, arg...) \
29 ugphy_printk(format , ## arg)
30#define ugphy_err(format, arg...) \
31 ugphy_printk(format , ## arg)
32#define ugphy_info(format, arg...) \
33 ugphy_printk(format , ## arg)
34#define ugphy_warn(format, arg...) \
35 ugphy_printk(format , ## arg)
Dave Liue732e9c2006-11-03 12:11:15 -060036
37#ifdef UEC_VERBOSE_DEBUG
38#define ugphy_vdbg ugphy_dbg
39#else
40#define ugphy_vdbg(ugeth, fmt, args...) do { } while (0)
41#endif /* UEC_VERBOSE_DEBUG */
42
Richard Retanubun9a45dcc2008-10-23 09:08:18 -040043/*--------------------------------------------------------------------+
44 * Fixed PHY (PHY-less) support for Ethernet Ports.
45 *
Stefan Roese88fbf932010-04-15 16:07:28 +020046 * Copied from arch/powerpc/cpu/ppc4xx/4xx_enet.c
Richard Retanubun9a45dcc2008-10-23 09:08:18 -040047 *--------------------------------------------------------------------*/
48
49/*
Richard Retanubun2e75df72009-07-01 14:04:05 -040050 * Some boards do not have a PHY for each ethernet port. These ports are known
51 * as Fixed PHY (or PHY-less) ports. For such ports, set the appropriate
52 * CONFIG_SYS_UECx_PHY_ADDR equal to CONFIG_FIXED_PHY_ADDR (an unused address)
53 * When the drver tries to identify the PHYs, CONFIG_FIXED_PHY will be returned
54 * and the driver will search CONFIG_SYS_FIXED_PHY_PORTS to find what network
55 * speed and duplex should be for the port.
Richard Retanubun9a45dcc2008-10-23 09:08:18 -040056 *
Richard Retanubun2e75df72009-07-01 14:04:05 -040057 * Example board header configuration file:
Richard Retanubun9a45dcc2008-10-23 09:08:18 -040058 * #define CONFIG_FIXED_PHY 0xFFFFFFFF
Richard Retanubun2e75df72009-07-01 14:04:05 -040059 * #define CONFIG_SYS_FIXED_PHY_ADDR 0x1E (pick an unused phy address)
Richard Retanubun9a45dcc2008-10-23 09:08:18 -040060 *
Richard Retanubun2e75df72009-07-01 14:04:05 -040061 * #define CONFIG_SYS_UEC1_PHY_ADDR CONFIG_SYS_FIXED_PHY_ADDR
62 * #define CONFIG_SYS_UEC2_PHY_ADDR 0x02
63 * #define CONFIG_SYS_UEC3_PHY_ADDR CONFIG_SYS_FIXED_PHY_ADDR
64 * #define CONFIG_SYS_UEC4_PHY_ADDR 0x04
Richard Retanubun9a45dcc2008-10-23 09:08:18 -040065 *
Richard Retanubun2e75df72009-07-01 14:04:05 -040066 * #define CONFIG_SYS_FIXED_PHY_PORT(name,speed,duplex) \
67 * {name, speed, duplex},
Richard Retanubun9a45dcc2008-10-23 09:08:18 -040068 *
69 * #define CONFIG_SYS_FIXED_PHY_PORTS \
Kim Phillipsb42cf5f2010-07-26 18:34:57 -050070 * CONFIG_SYS_FIXED_PHY_PORT("UEC0",SPEED_100,DUPLEX_FULL) \
71 * CONFIG_SYS_FIXED_PHY_PORT("UEC2",SPEED_100,DUPLEX_HALF)
Richard Retanubun9a45dcc2008-10-23 09:08:18 -040072 */
73
74#ifndef CONFIG_FIXED_PHY
75#define CONFIG_FIXED_PHY 0xFFFFFFFF /* Fixed PHY (PHY-less) */
76#endif
77
78#ifndef CONFIG_SYS_FIXED_PHY_PORTS
79#define CONFIG_SYS_FIXED_PHY_PORTS /* default is an empty array */
80#endif
81
82struct fixed_phy_port {
Mike Frysinger6b300dc2011-11-10 14:11:04 +000083 char name[16]; /* ethernet port name */
Richard Retanubun9a45dcc2008-10-23 09:08:18 -040084 unsigned int speed; /* specified speed 10,100 or 1000 */
85 unsigned int duplex; /* specified duplex FULL or HALF */
86};
87
88static const struct fixed_phy_port fixed_phy_port[] = {
89 CONFIG_SYS_FIXED_PHY_PORTS /* defined in board configuration file */
90};
91
Richard Retanubun15e467c2009-06-17 16:00:41 -040092/*--------------------------------------------------------------------+
93 * BitBang MII support for ethernet ports
94 *
95 * Based from MPC8560ADS implementation
96 *--------------------------------------------------------------------*/
97/*
98 * Example board header file to define bitbang ethernet ports:
99 *
100 * #define CONFIG_SYS_BITBANG_PHY_PORT(name) name,
Kim Phillipsb42cf5f2010-07-26 18:34:57 -0500101 * #define CONFIG_SYS_BITBANG_PHY_PORTS CONFIG_SYS_BITBANG_PHY_PORT("UEC0")
Richard Retanubun15e467c2009-06-17 16:00:41 -0400102*/
103#ifndef CONFIG_SYS_BITBANG_PHY_PORTS
104#define CONFIG_SYS_BITBANG_PHY_PORTS /* default is an empty array */
105#endif
106
107#if defined(CONFIG_BITBANGMII)
108static const char *bitbang_phy_port[] = {
109 CONFIG_SYS_BITBANG_PHY_PORTS /* defined in board configuration file */
110};
111#endif /* CONFIG_BITBANGMII */
112
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100113static void config_genmii_advert (struct uec_mii_info *mii_info);
114static void genmii_setup_forced (struct uec_mii_info *mii_info);
115static void genmii_restart_aneg (struct uec_mii_info *mii_info);
116static int gbit_config_aneg (struct uec_mii_info *mii_info);
117static int genmii_config_aneg (struct uec_mii_info *mii_info);
118static int genmii_update_link (struct uec_mii_info *mii_info);
119static int genmii_read_status (struct uec_mii_info *mii_info);
Andy Fleming0d2df962011-03-22 22:49:13 -0500120u16 uec_phy_read(struct uec_mii_info *mii_info, u16 regnum);
121void uec_phy_write(struct uec_mii_info *mii_info, u16 regnum, u16 val);
Dave Liue732e9c2006-11-03 12:11:15 -0600122
123/* Write value to the PHY for this device to the register at regnum, */
124/* waiting until the write is done before it returns. All PHY */
125/* configuration has to be done through the TSEC1 MIIM regs */
Andy Flemingee0e9172007-08-14 00:14:25 -0500126void uec_write_phy_reg (struct eth_device *dev, int mii_id, int regnum, int value)
Dave Liue732e9c2006-11-03 12:11:15 -0600127{
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100128 uec_private_t *ugeth = (uec_private_t *) dev->priv;
Andy Flemingee0e9172007-08-14 00:14:25 -0500129 uec_mii_t *ug_regs;
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100130 enet_tbi_mii_reg_e mii_reg = (enet_tbi_mii_reg_e) regnum;
131 u32 tmp_reg;
Dave Liue732e9c2006-11-03 12:11:15 -0600132
Richard Retanubun15e467c2009-06-17 16:00:41 -0400133
134#if defined(CONFIG_BITBANGMII)
135 u32 i = 0;
136
137 for (i = 0; i < ARRAY_SIZE(bitbang_phy_port); i++) {
138 if (strncmp(dev->name, bitbang_phy_port[i],
139 sizeof(dev->name)) == 0) {
140 (void)bb_miiphy_write(NULL, mii_id, regnum, value);
141 return;
142 }
143 }
144#endif /* CONFIG_BITBANGMII */
145
Andy Flemingee0e9172007-08-14 00:14:25 -0500146 ug_regs = ugeth->uec_mii_regs;
Dave Liue732e9c2006-11-03 12:11:15 -0600147
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100148 /* Stop the MII management read cycle */
149 out_be32 (&ug_regs->miimcom, 0);
150 /* Setting up the MII Mangement Address Register */
151 tmp_reg = ((u32) mii_id << MIIMADD_PHY_ADDRESS_SHIFT) | mii_reg;
152 out_be32 (&ug_regs->miimadd, tmp_reg);
Dave Liue732e9c2006-11-03 12:11:15 -0600153
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100154 /* Setting up the MII Mangement Control Register with the value */
155 out_be32 (&ug_regs->miimcon, (u32) value);
Kim Phillipsd986cba2008-01-15 14:11:00 -0600156 sync();
Dave Liue732e9c2006-11-03 12:11:15 -0600157
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100158 /* Wait till MII management write is complete */
159 while ((in_be32 (&ug_regs->miimind)) & MIIMIND_BUSY);
Dave Liue732e9c2006-11-03 12:11:15 -0600160}
161
162/* Reads from register regnum in the PHY for device dev, */
163/* returning the value. Clears miimcom first. All PHY */
164/* configuration has to be done through the TSEC1 MIIM regs */
Andy Flemingee0e9172007-08-14 00:14:25 -0500165int uec_read_phy_reg (struct eth_device *dev, int mii_id, int regnum)
Dave Liue732e9c2006-11-03 12:11:15 -0600166{
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100167 uec_private_t *ugeth = (uec_private_t *) dev->priv;
Andy Flemingee0e9172007-08-14 00:14:25 -0500168 uec_mii_t *ug_regs;
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100169 enet_tbi_mii_reg_e mii_reg = (enet_tbi_mii_reg_e) regnum;
170 u32 tmp_reg;
171 u16 value;
Dave Liue732e9c2006-11-03 12:11:15 -0600172
Richard Retanubun15e467c2009-06-17 16:00:41 -0400173
174#if defined(CONFIG_BITBANGMII)
175 u32 i = 0;
176
177 for (i = 0; i < ARRAY_SIZE(bitbang_phy_port); i++) {
178 if (strncmp(dev->name, bitbang_phy_port[i],
179 sizeof(dev->name)) == 0) {
180 (void)bb_miiphy_read(NULL, mii_id, regnum, &value);
181 return (value);
182 }
183 }
184#endif /* CONFIG_BITBANGMII */
185
Andy Flemingee0e9172007-08-14 00:14:25 -0500186 ug_regs = ugeth->uec_mii_regs;
Dave Liue732e9c2006-11-03 12:11:15 -0600187
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100188 /* Setting up the MII Mangement Address Register */
189 tmp_reg = ((u32) mii_id << MIIMADD_PHY_ADDRESS_SHIFT) | mii_reg;
190 out_be32 (&ug_regs->miimadd, tmp_reg);
Dave Liue732e9c2006-11-03 12:11:15 -0600191
Kim Phillipsd986cba2008-01-15 14:11:00 -0600192 /* clear MII management command cycle */
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100193 out_be32 (&ug_regs->miimcom, 0);
Kim Phillipsd986cba2008-01-15 14:11:00 -0600194 sync();
195
196 /* Perform an MII management read cycle */
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100197 out_be32 (&ug_regs->miimcom, MIIMCOM_READ_CYCLE);
Dave Liue732e9c2006-11-03 12:11:15 -0600198
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100199 /* Wait till MII management write is complete */
200 while ((in_be32 (&ug_regs->miimind)) &
201 (MIIMIND_NOT_VALID | MIIMIND_BUSY));
Dave Liue732e9c2006-11-03 12:11:15 -0600202
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100203 /* Read MII management status */
204 value = (u16) in_be32 (&ug_regs->miimstat);
205 if (value == 0xffff)
Joakim Tjernlund3d7f2552008-01-16 09:40:41 +0100206 ugphy_vdbg
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100207 ("read wrong value : mii_id %d,mii_reg %d, base %08x",
208 mii_id, mii_reg, (u32) & (ug_regs->miimcfg));
Dave Liue732e9c2006-11-03 12:11:15 -0600209
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100210 return (value);
Dave Liue732e9c2006-11-03 12:11:15 -0600211}
212
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100213void mii_clear_phy_interrupt (struct uec_mii_info *mii_info)
Dave Liue732e9c2006-11-03 12:11:15 -0600214{
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100215 if (mii_info->phyinfo->ack_interrupt)
216 mii_info->phyinfo->ack_interrupt (mii_info);
Dave Liue732e9c2006-11-03 12:11:15 -0600217}
218
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100219void mii_configure_phy_interrupt (struct uec_mii_info *mii_info,
220 u32 interrupts)
Dave Liue732e9c2006-11-03 12:11:15 -0600221{
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100222 mii_info->interrupts = interrupts;
223 if (mii_info->phyinfo->config_intr)
224 mii_info->phyinfo->config_intr (mii_info);
Dave Liue732e9c2006-11-03 12:11:15 -0600225}
226
227/* Writes MII_ADVERTISE with the appropriate values, after
228 * sanitizing advertise to make sure only supported features
229 * are advertised
230 */
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100231static void config_genmii_advert (struct uec_mii_info *mii_info)
Dave Liue732e9c2006-11-03 12:11:15 -0600232{
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100233 u32 advertise;
234 u16 adv;
Dave Liue732e9c2006-11-03 12:11:15 -0600235
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100236 /* Only allow advertising what this PHY supports */
237 mii_info->advertising &= mii_info->phyinfo->features;
238 advertise = mii_info->advertising;
Dave Liue732e9c2006-11-03 12:11:15 -0600239
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100240 /* Setup standard advertisement */
Andy Fleming0d2df962011-03-22 22:49:13 -0500241 adv = uec_phy_read(mii_info, MII_ADVERTISE);
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100242 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4);
243 if (advertise & ADVERTISED_10baseT_Half)
244 adv |= ADVERTISE_10HALF;
245 if (advertise & ADVERTISED_10baseT_Full)
246 adv |= ADVERTISE_10FULL;
247 if (advertise & ADVERTISED_100baseT_Half)
248 adv |= ADVERTISE_100HALF;
249 if (advertise & ADVERTISED_100baseT_Full)
250 adv |= ADVERTISE_100FULL;
Andy Fleming0d2df962011-03-22 22:49:13 -0500251 uec_phy_write(mii_info, MII_ADVERTISE, adv);
Dave Liue732e9c2006-11-03 12:11:15 -0600252}
253
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100254static void genmii_setup_forced (struct uec_mii_info *mii_info)
Dave Liue732e9c2006-11-03 12:11:15 -0600255{
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100256 u16 ctrl;
257 u32 features = mii_info->phyinfo->features;
Dave Liue732e9c2006-11-03 12:11:15 -0600258
Andy Fleming0d2df962011-03-22 22:49:13 -0500259 ctrl = uec_phy_read(mii_info, MII_BMCR);
Dave Liue732e9c2006-11-03 12:11:15 -0600260
Mike Frysingerd63ee712010-12-23 15:40:12 -0500261 ctrl &= ~(BMCR_FULLDPLX | BMCR_SPEED100 |
262 BMCR_SPEED1000 | BMCR_ANENABLE);
263 ctrl |= BMCR_RESET;
Dave Liue732e9c2006-11-03 12:11:15 -0600264
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100265 switch (mii_info->speed) {
266 case SPEED_1000:
267 if (features & (SUPPORTED_1000baseT_Half
268 | SUPPORTED_1000baseT_Full)) {
Mike Frysingerd63ee712010-12-23 15:40:12 -0500269 ctrl |= BMCR_SPEED1000;
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100270 break;
271 }
272 mii_info->speed = SPEED_100;
273 case SPEED_100:
274 if (features & (SUPPORTED_100baseT_Half
275 | SUPPORTED_100baseT_Full)) {
Mike Frysingerd63ee712010-12-23 15:40:12 -0500276 ctrl |= BMCR_SPEED100;
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100277 break;
278 }
279 mii_info->speed = SPEED_10;
280 case SPEED_10:
281 if (features & (SUPPORTED_10baseT_Half
282 | SUPPORTED_10baseT_Full))
283 break;
284 default: /* Unsupported speed! */
285 ugphy_err ("%s: Bad speed!", mii_info->dev->name);
286 break;
287 }
Dave Liue732e9c2006-11-03 12:11:15 -0600288
Andy Fleming0d2df962011-03-22 22:49:13 -0500289 uec_phy_write(mii_info, MII_BMCR, ctrl);
Dave Liue732e9c2006-11-03 12:11:15 -0600290}
291
292/* Enable and Restart Autonegotiation */
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100293static void genmii_restart_aneg (struct uec_mii_info *mii_info)
Dave Liue732e9c2006-11-03 12:11:15 -0600294{
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100295 u16 ctl;
Dave Liue732e9c2006-11-03 12:11:15 -0600296
Andy Fleming0d2df962011-03-22 22:49:13 -0500297 ctl = uec_phy_read(mii_info, MII_BMCR);
Mike Frysingerd63ee712010-12-23 15:40:12 -0500298 ctl |= (BMCR_ANENABLE | BMCR_ANRESTART);
Andy Fleming0d2df962011-03-22 22:49:13 -0500299 uec_phy_write(mii_info, MII_BMCR, ctl);
Dave Liue732e9c2006-11-03 12:11:15 -0600300}
301
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100302static int gbit_config_aneg (struct uec_mii_info *mii_info)
Dave Liue732e9c2006-11-03 12:11:15 -0600303{
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100304 u16 adv;
305 u32 advertise;
Dave Liue732e9c2006-11-03 12:11:15 -0600306
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100307 if (mii_info->autoneg) {
308 /* Configure the ADVERTISE register */
309 config_genmii_advert (mii_info);
310 advertise = mii_info->advertising;
Dave Liue732e9c2006-11-03 12:11:15 -0600311
Andy Fleming0d2df962011-03-22 22:49:13 -0500312 adv = uec_phy_read(mii_info, MII_CTRL1000);
Kumar Gala09036992011-01-19 03:36:40 -0600313 adv &= ~(ADVERTISE_1000FULL |
314 ADVERTISE_1000HALF);
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100315 if (advertise & SUPPORTED_1000baseT_Half)
Kumar Gala09036992011-01-19 03:36:40 -0600316 adv |= ADVERTISE_1000HALF;
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100317 if (advertise & SUPPORTED_1000baseT_Full)
Kumar Gala09036992011-01-19 03:36:40 -0600318 adv |= ADVERTISE_1000FULL;
Andy Fleming0d2df962011-03-22 22:49:13 -0500319 uec_phy_write(mii_info, MII_CTRL1000, adv);
Dave Liue732e9c2006-11-03 12:11:15 -0600320
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100321 /* Start/Restart aneg */
322 genmii_restart_aneg (mii_info);
323 } else
324 genmii_setup_forced (mii_info);
Dave Liue732e9c2006-11-03 12:11:15 -0600325
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100326 return 0;
Dave Liue732e9c2006-11-03 12:11:15 -0600327}
328
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100329static int marvell_config_aneg (struct uec_mii_info *mii_info)
Dave Liue732e9c2006-11-03 12:11:15 -0600330{
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100331 /* The Marvell PHY has an errata which requires
332 * that certain registers get written in order
333 * to restart autonegotiation */
Andy Fleming0d2df962011-03-22 22:49:13 -0500334 uec_phy_write(mii_info, MII_BMCR, BMCR_RESET);
Dave Liue732e9c2006-11-03 12:11:15 -0600335
Andy Fleming0d2df962011-03-22 22:49:13 -0500336 uec_phy_write(mii_info, 0x1d, 0x1f);
337 uec_phy_write(mii_info, 0x1e, 0x200c);
338 uec_phy_write(mii_info, 0x1d, 0x5);
339 uec_phy_write(mii_info, 0x1e, 0);
340 uec_phy_write(mii_info, 0x1e, 0x100);
Dave Liue732e9c2006-11-03 12:11:15 -0600341
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100342 gbit_config_aneg (mii_info);
Dave Liue732e9c2006-11-03 12:11:15 -0600343
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100344 return 0;
Dave Liue732e9c2006-11-03 12:11:15 -0600345}
346
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100347static int genmii_config_aneg (struct uec_mii_info *mii_info)
Dave Liue732e9c2006-11-03 12:11:15 -0600348{
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100349 if (mii_info->autoneg) {
Joakim Tjernlund69554e12010-08-10 16:36:49 +0200350 /* Speed up the common case, if link is already up, speed and
351 duplex match, skip auto neg as it already matches */
352 if (!genmii_read_status(mii_info) && mii_info->link)
353 if (mii_info->duplex == DUPLEX_FULL &&
354 mii_info->speed == SPEED_100)
355 if (mii_info->advertising &
356 ADVERTISED_100baseT_Full)
357 return 0;
358
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100359 config_genmii_advert (mii_info);
360 genmii_restart_aneg (mii_info);
361 } else
362 genmii_setup_forced (mii_info);
Dave Liue732e9c2006-11-03 12:11:15 -0600363
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100364 return 0;
Dave Liue732e9c2006-11-03 12:11:15 -0600365}
366
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100367static int genmii_update_link (struct uec_mii_info *mii_info)
Dave Liue732e9c2006-11-03 12:11:15 -0600368{
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100369 u16 status;
Dave Liue732e9c2006-11-03 12:11:15 -0600370
Kim Phillipsd986cba2008-01-15 14:11:00 -0600371 /* Status is read once to clear old link state */
Andy Fleming0d2df962011-03-22 22:49:13 -0500372 uec_phy_read(mii_info, MII_BMSR);
Dave Liue732e9c2006-11-03 12:11:15 -0600373
Kim Phillipsd986cba2008-01-15 14:11:00 -0600374 /*
375 * Wait if the link is up, and autonegotiation is in progress
376 * (ie - we're capable and it's not done)
377 */
Andy Fleming0d2df962011-03-22 22:49:13 -0500378 status = uec_phy_read(mii_info, MII_BMSR);
Mike Frysingerd63ee712010-12-23 15:40:12 -0500379 if ((status & BMSR_LSTATUS) && (status & BMSR_ANEGCAPABLE)
380 && !(status & BMSR_ANEGCOMPLETE)) {
Kim Phillipsd986cba2008-01-15 14:11:00 -0600381 int i = 0;
Dave Liue732e9c2006-11-03 12:11:15 -0600382
Mike Frysingerd63ee712010-12-23 15:40:12 -0500383 while (!(status & BMSR_ANEGCOMPLETE)) {
Kim Phillipsd986cba2008-01-15 14:11:00 -0600384 /*
385 * Timeout reached ?
386 */
387 if (i > UGETH_AN_TIMEOUT) {
388 mii_info->link = 0;
389 return 0;
390 }
391
Kim Phillipsb5da4272008-02-27 16:08:22 -0600392 i++;
Kim Phillipsd986cba2008-01-15 14:11:00 -0600393 udelay(1000); /* 1 ms */
Andy Fleming0d2df962011-03-22 22:49:13 -0500394 status = uec_phy_read(mii_info, MII_BMSR);
Kim Phillipsd986cba2008-01-15 14:11:00 -0600395 }
396 mii_info->link = 1;
Kim Phillipsd986cba2008-01-15 14:11:00 -0600397 } else {
Mike Frysingerd63ee712010-12-23 15:40:12 -0500398 if (status & BMSR_LSTATUS)
Kim Phillipsd986cba2008-01-15 14:11:00 -0600399 mii_info->link = 1;
400 else
401 mii_info->link = 0;
402 }
Dave Liue732e9c2006-11-03 12:11:15 -0600403
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100404 return 0;
Dave Liue732e9c2006-11-03 12:11:15 -0600405}
406
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100407static int genmii_read_status (struct uec_mii_info *mii_info)
Dave Liue732e9c2006-11-03 12:11:15 -0600408{
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100409 u16 status;
410 int err;
Dave Liue732e9c2006-11-03 12:11:15 -0600411
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100412 /* Update the link, but return if there
413 * was an error */
414 err = genmii_update_link (mii_info);
415 if (err)
416 return err;
Dave Liue732e9c2006-11-03 12:11:15 -0600417
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100418 if (mii_info->autoneg) {
Andy Fleming0d2df962011-03-22 22:49:13 -0500419 status = uec_phy_read(mii_info, MII_STAT1000);
Anton Vorontsov951800b2008-03-24 20:46:24 +0300420
421 if (status & (LPA_1000FULL | LPA_1000HALF)) {
422 mii_info->speed = SPEED_1000;
423 if (status & LPA_1000FULL)
424 mii_info->duplex = DUPLEX_FULL;
425 else
426 mii_info->duplex = DUPLEX_HALF;
427 } else {
Andy Fleming0d2df962011-03-22 22:49:13 -0500428 status = uec_phy_read(mii_info, MII_LPA);
Dave Liue732e9c2006-11-03 12:11:15 -0600429
Mike Frysingerd63ee712010-12-23 15:40:12 -0500430 if (status & (LPA_10FULL | LPA_100FULL))
Anton Vorontsov951800b2008-03-24 20:46:24 +0300431 mii_info->duplex = DUPLEX_FULL;
432 else
433 mii_info->duplex = DUPLEX_HALF;
Mike Frysingerd63ee712010-12-23 15:40:12 -0500434 if (status & (LPA_100FULL | LPA_100HALF))
Anton Vorontsov951800b2008-03-24 20:46:24 +0300435 mii_info->speed = SPEED_100;
436 else
437 mii_info->speed = SPEED_10;
438 }
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100439 mii_info->pause = 0;
440 }
441 /* On non-aneg, we assume what we put in BMCR is the speed,
442 * though magic-aneg shouldn't prevent this case from occurring
443 */
Dave Liue732e9c2006-11-03 12:11:15 -0600444
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100445 return 0;
Dave Liue732e9c2006-11-03 12:11:15 -0600446}
447
Anton Vorontsov98003732008-03-24 20:46:34 +0300448static int bcm_init(struct uec_mii_info *mii_info)
449{
450 struct eth_device *edev = mii_info->dev;
451 uec_private_t *uec = edev->priv;
452
453 gbit_config_aneg(mii_info);
454
Andy Fleming7832a462011-04-13 00:37:12 -0500455 if ((uec->uec_info->enet_interface_type ==
456 PHY_INTERFACE_MODE_RGMII_RXID) &&
457 (uec->uec_info->speed == SPEED_1000)) {
Anton Vorontsov98003732008-03-24 20:46:34 +0300458 u16 val;
459 int cnt = 50;
460
461 /* Wait for aneg to complete. */
462 do
Andy Fleming0d2df962011-03-22 22:49:13 -0500463 val = uec_phy_read(mii_info, MII_BMSR);
Mike Frysingerd63ee712010-12-23 15:40:12 -0500464 while (--cnt && !(val & BMSR_ANEGCOMPLETE));
Anton Vorontsov98003732008-03-24 20:46:34 +0300465
466 /* Set RDX clk delay. */
Andy Fleming0d2df962011-03-22 22:49:13 -0500467 uec_phy_write(mii_info, 0x18, 0x7 | (7 << 12));
Anton Vorontsov98003732008-03-24 20:46:34 +0300468
Andy Fleming0d2df962011-03-22 22:49:13 -0500469 val = uec_phy_read(mii_info, 0x18);
Anton Vorontsov98003732008-03-24 20:46:34 +0300470 /* Set RDX-RXC skew. */
471 val |= (1 << 8);
472 val |= (7 | (7 << 12));
473 /* Write bits 14:0. */
474 val |= (1 << 15);
Andy Fleming0d2df962011-03-22 22:49:13 -0500475 uec_phy_write(mii_info, 0x18, val);
Anton Vorontsov98003732008-03-24 20:46:34 +0300476 }
477
478 return 0;
479}
480
Andy Fleming0d2df962011-03-22 22:49:13 -0500481static int uec_marvell_init(struct uec_mii_info *mii_info)
Haiying Wang024e1e72008-09-24 11:42:12 -0500482{
483 struct eth_device *edev = mii_info->dev;
484 uec_private_t *uec = edev->priv;
Andy Fleming7832a462011-04-13 00:37:12 -0500485 phy_interface_t iface = uec->uec_info->enet_interface_type;
Heiko Schocher40b44bc2010-01-20 09:04:28 +0100486 int speed = uec->uec_info->speed;
Haiying Wang024e1e72008-09-24 11:42:12 -0500487
Andy Fleming7832a462011-04-13 00:37:12 -0500488 if ((speed == SPEED_1000) &&
489 (iface == PHY_INTERFACE_MODE_RGMII_ID ||
490 iface == PHY_INTERFACE_MODE_RGMII_RXID ||
491 iface == PHY_INTERFACE_MODE_RGMII_TXID)) {
Haiying Wang024e1e72008-09-24 11:42:12 -0500492 int temp;
493
Andy Fleming0d2df962011-03-22 22:49:13 -0500494 temp = uec_phy_read(mii_info, MII_M1111_PHY_EXT_CR);
Andy Fleming7832a462011-04-13 00:37:12 -0500495 if (iface == PHY_INTERFACE_MODE_RGMII_ID) {
Anton Vorontsov1b8a3362009-09-16 23:21:53 +0400496 temp |= MII_M1111_RX_DELAY | MII_M1111_TX_DELAY;
Andy Fleming7832a462011-04-13 00:37:12 -0500497 } else if (iface == PHY_INTERFACE_MODE_RGMII_RXID) {
Anton Vorontsov1b8a3362009-09-16 23:21:53 +0400498 temp &= ~MII_M1111_TX_DELAY;
499 temp |= MII_M1111_RX_DELAY;
Andy Fleming7832a462011-04-13 00:37:12 -0500500 } else if (iface == PHY_INTERFACE_MODE_RGMII_TXID) {
Anton Vorontsov1b8a3362009-09-16 23:21:53 +0400501 temp &= ~MII_M1111_RX_DELAY;
502 temp |= MII_M1111_TX_DELAY;
503 }
Andy Fleming0d2df962011-03-22 22:49:13 -0500504 uec_phy_write(mii_info, MII_M1111_PHY_EXT_CR, temp);
Haiying Wang024e1e72008-09-24 11:42:12 -0500505
Andy Fleming0d2df962011-03-22 22:49:13 -0500506 temp = uec_phy_read(mii_info, MII_M1111_PHY_EXT_SR);
Haiying Wang024e1e72008-09-24 11:42:12 -0500507 temp &= ~MII_M1111_HWCFG_MODE_MASK;
508 temp |= MII_M1111_HWCFG_MODE_RGMII;
Andy Fleming0d2df962011-03-22 22:49:13 -0500509 uec_phy_write(mii_info, MII_M1111_PHY_EXT_SR, temp);
Haiying Wang024e1e72008-09-24 11:42:12 -0500510
Andy Fleming0d2df962011-03-22 22:49:13 -0500511 uec_phy_write(mii_info, MII_BMCR, BMCR_RESET);
Haiying Wang024e1e72008-09-24 11:42:12 -0500512 }
513
514 return 0;
515}
516
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100517static int marvell_read_status (struct uec_mii_info *mii_info)
Dave Liue732e9c2006-11-03 12:11:15 -0600518{
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100519 u16 status;
520 int err;
521
522 /* Update the link, but return if there
523 * was an error */
524 err = genmii_update_link (mii_info);
525 if (err)
526 return err;
Dave Liue732e9c2006-11-03 12:11:15 -0600527
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100528 /* If the link is up, read the speed and duplex */
529 /* If we aren't autonegotiating, assume speeds
530 * are as set */
531 if (mii_info->autoneg && mii_info->link) {
532 int speed;
Dave Liue732e9c2006-11-03 12:11:15 -0600533
Andy Fleming0d2df962011-03-22 22:49:13 -0500534 status = uec_phy_read(mii_info, MII_M1011_PHY_SPEC_STATUS);
Dave Liue732e9c2006-11-03 12:11:15 -0600535
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100536 /* Get the duplexity */
537 if (status & MII_M1011_PHY_SPEC_STATUS_FULLDUPLEX)
538 mii_info->duplex = DUPLEX_FULL;
539 else
540 mii_info->duplex = DUPLEX_HALF;
Dave Liue732e9c2006-11-03 12:11:15 -0600541
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100542 /* Get the speed */
543 speed = status & MII_M1011_PHY_SPEC_STATUS_SPD_MASK;
544 switch (speed) {
545 case MII_M1011_PHY_SPEC_STATUS_1000:
546 mii_info->speed = SPEED_1000;
547 break;
548 case MII_M1011_PHY_SPEC_STATUS_100:
549 mii_info->speed = SPEED_100;
550 break;
551 default:
552 mii_info->speed = SPEED_10;
553 break;
554 }
555 mii_info->pause = 0;
556 }
Dave Liue732e9c2006-11-03 12:11:15 -0600557
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100558 return 0;
Dave Liue732e9c2006-11-03 12:11:15 -0600559}
560
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100561static int marvell_ack_interrupt (struct uec_mii_info *mii_info)
Dave Liue732e9c2006-11-03 12:11:15 -0600562{
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100563 /* Clear the interrupts by reading the reg */
Andy Fleming0d2df962011-03-22 22:49:13 -0500564 uec_phy_read(mii_info, MII_M1011_IEVENT);
Dave Liue732e9c2006-11-03 12:11:15 -0600565
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100566 return 0;
Dave Liue732e9c2006-11-03 12:11:15 -0600567}
568
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100569static int marvell_config_intr (struct uec_mii_info *mii_info)
Dave Liue732e9c2006-11-03 12:11:15 -0600570{
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100571 if (mii_info->interrupts == MII_INTERRUPT_ENABLED)
Andy Fleming0d2df962011-03-22 22:49:13 -0500572 uec_phy_write(mii_info, MII_M1011_IMASK, MII_M1011_IMASK_INIT);
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100573 else
Andy Fleming0d2df962011-03-22 22:49:13 -0500574 uec_phy_write(mii_info, MII_M1011_IMASK,
575 MII_M1011_IMASK_CLEAR);
Dave Liue732e9c2006-11-03 12:11:15 -0600576
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100577 return 0;
Dave Liue732e9c2006-11-03 12:11:15 -0600578}
579
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100580static int dm9161_init (struct uec_mii_info *mii_info)
Dave Liue732e9c2006-11-03 12:11:15 -0600581{
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100582 /* Reset the PHY */
Andy Fleming0d2df962011-03-22 22:49:13 -0500583 uec_phy_write(mii_info, MII_BMCR, uec_phy_read(mii_info, MII_BMCR) |
Mike Frysingerd63ee712010-12-23 15:40:12 -0500584 BMCR_RESET);
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100585 /* PHY and MAC connect */
Andy Fleming0d2df962011-03-22 22:49:13 -0500586 uec_phy_write(mii_info, MII_BMCR, uec_phy_read(mii_info, MII_BMCR) &
Mike Frysingerd63ee712010-12-23 15:40:12 -0500587 ~BMCR_ISOLATE);
Kim Phillipsd986cba2008-01-15 14:11:00 -0600588
Andy Fleming0d2df962011-03-22 22:49:13 -0500589 uec_phy_write(mii_info, MII_DM9161_SCR, MII_DM9161_SCR_INIT);
Kim Phillipsd986cba2008-01-15 14:11:00 -0600590
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100591 config_genmii_advert (mii_info);
592 /* Start/restart aneg */
593 genmii_config_aneg (mii_info);
Dave Liue732e9c2006-11-03 12:11:15 -0600594
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100595 return 0;
Dave Liue732e9c2006-11-03 12:11:15 -0600596}
597
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100598static int dm9161_config_aneg (struct uec_mii_info *mii_info)
Dave Liue732e9c2006-11-03 12:11:15 -0600599{
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100600 return 0;
Dave Liue732e9c2006-11-03 12:11:15 -0600601}
602
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100603static int dm9161_read_status (struct uec_mii_info *mii_info)
Dave Liue732e9c2006-11-03 12:11:15 -0600604{
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100605 u16 status;
606 int err;
Dave Liue732e9c2006-11-03 12:11:15 -0600607
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100608 /* Update the link, but return if there was an error */
609 err = genmii_update_link (mii_info);
610 if (err)
611 return err;
612 /* If the link is up, read the speed and duplex
613 If we aren't autonegotiating assume speeds are as set */
614 if (mii_info->autoneg && mii_info->link) {
Andy Fleming0d2df962011-03-22 22:49:13 -0500615 status = uec_phy_read(mii_info, MII_DM9161_SCSR);
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100616 if (status & (MII_DM9161_SCSR_100F | MII_DM9161_SCSR_100H))
617 mii_info->speed = SPEED_100;
618 else
619 mii_info->speed = SPEED_10;
Dave Liue732e9c2006-11-03 12:11:15 -0600620
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100621 if (status & (MII_DM9161_SCSR_100F | MII_DM9161_SCSR_10F))
622 mii_info->duplex = DUPLEX_FULL;
623 else
624 mii_info->duplex = DUPLEX_HALF;
625 }
Dave Liue732e9c2006-11-03 12:11:15 -0600626
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100627 return 0;
Dave Liue732e9c2006-11-03 12:11:15 -0600628}
629
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100630static int dm9161_ack_interrupt (struct uec_mii_info *mii_info)
Dave Liue732e9c2006-11-03 12:11:15 -0600631{
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100632 /* Clear the interrupt by reading the reg */
Andy Fleming0d2df962011-03-22 22:49:13 -0500633 uec_phy_read(mii_info, MII_DM9161_INTR);
Dave Liue732e9c2006-11-03 12:11:15 -0600634
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100635 return 0;
Dave Liue732e9c2006-11-03 12:11:15 -0600636}
637
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100638static int dm9161_config_intr (struct uec_mii_info *mii_info)
Dave Liue732e9c2006-11-03 12:11:15 -0600639{
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100640 if (mii_info->interrupts == MII_INTERRUPT_ENABLED)
Andy Fleming0d2df962011-03-22 22:49:13 -0500641 uec_phy_write(mii_info, MII_DM9161_INTR, MII_DM9161_INTR_INIT);
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100642 else
Andy Fleming0d2df962011-03-22 22:49:13 -0500643 uec_phy_write(mii_info, MII_DM9161_INTR, MII_DM9161_INTR_STOP);
Dave Liue732e9c2006-11-03 12:11:15 -0600644
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100645 return 0;
Dave Liue732e9c2006-11-03 12:11:15 -0600646}
647
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100648static void dm9161_close (struct uec_mii_info *mii_info)
Dave Liue732e9c2006-11-03 12:11:15 -0600649{
650}
651
Richard Retanubun9a45dcc2008-10-23 09:08:18 -0400652static int fixed_phy_aneg (struct uec_mii_info *mii_info)
653{
654 mii_info->autoneg = 0; /* Turn off auto negotiation for fixed phy */
655 return 0;
656}
657
658static int fixed_phy_read_status (struct uec_mii_info *mii_info)
659{
660 int i = 0;
661
662 for (i = 0; i < ARRAY_SIZE(fixed_phy_port); i++) {
Richard Retanubun2e75df72009-07-01 14:04:05 -0400663 if (strncmp(mii_info->dev->name, fixed_phy_port[i].name,
664 strlen(mii_info->dev->name)) == 0) {
Richard Retanubun9a45dcc2008-10-23 09:08:18 -0400665 mii_info->speed = fixed_phy_port[i].speed;
666 mii_info->duplex = fixed_phy_port[i].duplex;
667 mii_info->link = 1; /* Link is always UP */
668 mii_info->pause = 0;
669 break;
670 }
671 }
672 return 0;
673}
674
Heiko Schocher3be3b9f2008-11-20 09:57:14 +0100675static int smsc_config_aneg (struct uec_mii_info *mii_info)
676{
677 return 0;
678}
679
680static int smsc_read_status (struct uec_mii_info *mii_info)
681{
682 u16 status;
683 int err;
684
685 /* Update the link, but return if there
686 * was an error */
687 err = genmii_update_link (mii_info);
688 if (err)
689 return err;
690
691 /* If the link is up, read the speed and duplex */
692 /* If we aren't autonegotiating, assume speeds
693 * are as set */
694 if (mii_info->autoneg && mii_info->link) {
695 int val;
696
Andy Fleming0d2df962011-03-22 22:49:13 -0500697 status = uec_phy_read(mii_info, 0x1f);
Heiko Schocher3be3b9f2008-11-20 09:57:14 +0100698 val = (status & 0x1c) >> 2;
699
700 switch (val) {
701 case 1:
702 mii_info->duplex = DUPLEX_HALF;
703 mii_info->speed = SPEED_10;
704 break;
705 case 5:
706 mii_info->duplex = DUPLEX_FULL;
707 mii_info->speed = SPEED_10;
708 break;
709 case 2:
710 mii_info->duplex = DUPLEX_HALF;
711 mii_info->speed = SPEED_100;
712 break;
713 case 6:
714 mii_info->duplex = DUPLEX_FULL;
715 mii_info->speed = SPEED_100;
716 break;
717 }
718 mii_info->pause = 0;
719 }
720
721 return 0;
722}
723
Dave Liue732e9c2006-11-03 12:11:15 -0600724static struct phy_info phy_info_dm9161 = {
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100725 .phy_id = 0x0181b880,
726 .phy_id_mask = 0x0ffffff0,
727 .name = "Davicom DM9161E",
728 .init = dm9161_init,
729 .config_aneg = dm9161_config_aneg,
730 .read_status = dm9161_read_status,
731 .close = dm9161_close,
Dave Liue732e9c2006-11-03 12:11:15 -0600732};
733
734static struct phy_info phy_info_dm9161a = {
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100735 .phy_id = 0x0181b8a0,
736 .phy_id_mask = 0x0ffffff0,
737 .name = "Davicom DM9161A",
738 .features = MII_BASIC_FEATURES,
739 .init = dm9161_init,
740 .config_aneg = dm9161_config_aneg,
741 .read_status = dm9161_read_status,
742 .ack_interrupt = dm9161_ack_interrupt,
743 .config_intr = dm9161_config_intr,
744 .close = dm9161_close,
Dave Liue732e9c2006-11-03 12:11:15 -0600745};
746
747static struct phy_info phy_info_marvell = {
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100748 .phy_id = 0x01410c00,
749 .phy_id_mask = 0xffffff00,
750 .name = "Marvell 88E11x1",
751 .features = MII_GBIT_FEATURES,
Andy Fleming0d2df962011-03-22 22:49:13 -0500752 .init = &uec_marvell_init,
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100753 .config_aneg = &marvell_config_aneg,
754 .read_status = &marvell_read_status,
755 .ack_interrupt = &marvell_ack_interrupt,
756 .config_intr = &marvell_config_intr,
Dave Liue732e9c2006-11-03 12:11:15 -0600757};
758
Anton Vorontsov98003732008-03-24 20:46:34 +0300759static struct phy_info phy_info_bcm5481 = {
760 .phy_id = 0x0143bca0,
761 .phy_id_mask = 0xffffff0,
762 .name = "Broadcom 5481",
763 .features = MII_GBIT_FEATURES,
764 .read_status = genmii_read_status,
765 .init = bcm_init,
766};
767
Richard Retanubun9a45dcc2008-10-23 09:08:18 -0400768static struct phy_info phy_info_fixedphy = {
769 .phy_id = CONFIG_FIXED_PHY,
770 .phy_id_mask = CONFIG_FIXED_PHY,
771 .name = "Fixed PHY",
772 .config_aneg = fixed_phy_aneg,
773 .read_status = fixed_phy_read_status,
774};
775
Heiko Schocher3be3b9f2008-11-20 09:57:14 +0100776static struct phy_info phy_info_smsclan8700 = {
777 .phy_id = 0x0007c0c0,
778 .phy_id_mask = 0xfffffff0,
779 .name = "SMSC LAN8700",
780 .features = MII_BASIC_FEATURES,
781 .config_aneg = smsc_config_aneg,
782 .read_status = smsc_read_status,
783};
784
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100785static struct phy_info phy_info_genmii = {
786 .phy_id = 0x00000000,
787 .phy_id_mask = 0x00000000,
788 .name = "Generic MII",
789 .features = MII_BASIC_FEATURES,
790 .config_aneg = genmii_config_aneg,
791 .read_status = genmii_read_status,
Dave Liue732e9c2006-11-03 12:11:15 -0600792};
793
794static struct phy_info *phy_info[] = {
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100795 &phy_info_dm9161,
796 &phy_info_dm9161a,
797 &phy_info_marvell,
Anton Vorontsov98003732008-03-24 20:46:34 +0300798 &phy_info_bcm5481,
Heiko Schocher3be3b9f2008-11-20 09:57:14 +0100799 &phy_info_smsclan8700,
Richard Retanubun9a45dcc2008-10-23 09:08:18 -0400800 &phy_info_fixedphy,
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100801 &phy_info_genmii,
802 NULL
Dave Liue732e9c2006-11-03 12:11:15 -0600803};
804
Andy Fleming0d2df962011-03-22 22:49:13 -0500805u16 uec_phy_read(struct uec_mii_info *mii_info, u16 regnum)
Dave Liue732e9c2006-11-03 12:11:15 -0600806{
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100807 return mii_info->mdio_read (mii_info->dev, mii_info->mii_id, regnum);
Dave Liue732e9c2006-11-03 12:11:15 -0600808}
809
Andy Fleming0d2df962011-03-22 22:49:13 -0500810void uec_phy_write(struct uec_mii_info *mii_info, u16 regnum, u16 val)
Dave Liue732e9c2006-11-03 12:11:15 -0600811{
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100812 mii_info->mdio_write (mii_info->dev, mii_info->mii_id, regnum, val);
Dave Liue732e9c2006-11-03 12:11:15 -0600813}
814
815/* Use the PHY ID registers to determine what type of PHY is attached
816 * to device dev. return a struct phy_info structure describing that PHY
817 */
Andy Flemingee0e9172007-08-14 00:14:25 -0500818struct phy_info *uec_get_phy_info (struct uec_mii_info *mii_info)
Dave Liue732e9c2006-11-03 12:11:15 -0600819{
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100820 u16 phy_reg;
821 u32 phy_ID;
822 int i;
823 struct phy_info *theInfo = NULL;
Dave Liue732e9c2006-11-03 12:11:15 -0600824
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100825 /* Grab the bits from PHYIR1, and put them in the upper half */
Andy Fleming0d2df962011-03-22 22:49:13 -0500826 phy_reg = uec_phy_read(mii_info, MII_PHYSID1);
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100827 phy_ID = (phy_reg & 0xffff) << 16;
Dave Liue732e9c2006-11-03 12:11:15 -0600828
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100829 /* Grab the bits from PHYIR2, and put them in the lower half */
Andy Fleming0d2df962011-03-22 22:49:13 -0500830 phy_reg = uec_phy_read(mii_info, MII_PHYSID2);
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100831 phy_ID |= (phy_reg & 0xffff);
Dave Liue732e9c2006-11-03 12:11:15 -0600832
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100833 /* loop through all the known PHY types, and find one that */
834 /* matches the ID we read from the PHY. */
835 for (i = 0; phy_info[i]; i++)
836 if (phy_info[i]->phy_id ==
837 (phy_ID & phy_info[i]->phy_id_mask)) {
838 theInfo = phy_info[i];
839 break;
840 }
Dave Liue732e9c2006-11-03 12:11:15 -0600841
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100842 /* This shouldn't happen, as we have generic PHY support */
843 if (theInfo == NULL) {
844 ugphy_info ("UEC: PHY id %x is not supported!", phy_ID);
845 return NULL;
846 } else {
847 ugphy_info ("UEC: PHY is %s (%x)", theInfo->name, phy_ID);
848 }
Dave Liue732e9c2006-11-03 12:11:15 -0600849
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100850 return theInfo;
Dave Liue732e9c2006-11-03 12:11:15 -0600851}
852
Andy Fleming7832a462011-04-13 00:37:12 -0500853void marvell_phy_interface_mode(struct eth_device *dev, phy_interface_t type,
854 int speed)
Dave Liue732e9c2006-11-03 12:11:15 -0600855{
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100856 uec_private_t *uec = (uec_private_t *) dev->priv;
857 struct uec_mii_info *mii_info;
Kim Phillips21084052008-02-27 15:06:39 -0600858 u16 status;
Dave Liue732e9c2006-11-03 12:11:15 -0600859
860 if (!uec->mii_info) {
Kim Phillipsb5da4272008-02-27 16:08:22 -0600861 printf ("%s: the PHY not initialized\n", __FUNCTION__);
Dave Liue732e9c2006-11-03 12:11:15 -0600862 return;
863 }
864 mii_info = uec->mii_info;
865
Andy Fleming7832a462011-04-13 00:37:12 -0500866 if (type == PHY_INTERFACE_MODE_RGMII) {
867 if (speed == SPEED_100) {
Andy Fleming0d2df962011-03-22 22:49:13 -0500868 uec_phy_write(mii_info, 0x00, 0x9140);
869 uec_phy_write(mii_info, 0x1d, 0x001f);
870 uec_phy_write(mii_info, 0x1e, 0x200c);
871 uec_phy_write(mii_info, 0x1d, 0x0005);
872 uec_phy_write(mii_info, 0x1e, 0x0000);
873 uec_phy_write(mii_info, 0x1e, 0x0100);
874 uec_phy_write(mii_info, 0x09, 0x0e00);
875 uec_phy_write(mii_info, 0x04, 0x01e1);
876 uec_phy_write(mii_info, 0x00, 0x9140);
877 uec_phy_write(mii_info, 0x00, 0x1000);
Heiko Schocher40b44bc2010-01-20 09:04:28 +0100878 udelay (100000);
Andy Fleming0d2df962011-03-22 22:49:13 -0500879 uec_phy_write(mii_info, 0x00, 0x2900);
880 uec_phy_write(mii_info, 0x14, 0x0cd2);
881 uec_phy_write(mii_info, 0x00, 0xa100);
882 uec_phy_write(mii_info, 0x09, 0x0000);
883 uec_phy_write(mii_info, 0x1b, 0x800b);
884 uec_phy_write(mii_info, 0x04, 0x05e1);
885 uec_phy_write(mii_info, 0x00, 0xa100);
886 uec_phy_write(mii_info, 0x00, 0x2100);
Heiko Schocher40b44bc2010-01-20 09:04:28 +0100887 udelay (1000000);
Andy Fleming7832a462011-04-13 00:37:12 -0500888 } else if (speed == SPEED_10) {
Andy Fleming0d2df962011-03-22 22:49:13 -0500889 uec_phy_write(mii_info, 0x14, 0x8e40);
890 uec_phy_write(mii_info, 0x1b, 0x800b);
891 uec_phy_write(mii_info, 0x14, 0x0c82);
892 uec_phy_write(mii_info, 0x00, 0x8100);
Heiko Schocher40b44bc2010-01-20 09:04:28 +0100893 udelay (1000000);
894 }
Dave Liue732e9c2006-11-03 12:11:15 -0600895 }
Kim Phillips21084052008-02-27 15:06:39 -0600896
897 /* handle 88e1111 rev.B2 erratum 5.6 */
898 if (mii_info->autoneg) {
Andy Fleming0d2df962011-03-22 22:49:13 -0500899 status = uec_phy_read(mii_info, MII_BMCR);
900 uec_phy_write(mii_info, MII_BMCR, status | BMCR_ANENABLE);
Kim Phillips21084052008-02-27 15:06:39 -0600901 }
902 /* now the B2 will correctly report autoneg completion status */
Dave Liue732e9c2006-11-03 12:11:15 -0600903}
904
Heiko Schocher40b44bc2010-01-20 09:04:28 +0100905void change_phy_interface_mode (struct eth_device *dev,
Andy Fleming7832a462011-04-13 00:37:12 -0500906 phy_interface_t type, int speed)
Dave Liue732e9c2006-11-03 12:11:15 -0600907{
908#ifdef CONFIG_PHY_MODE_NEED_CHANGE
Heiko Schocher40b44bc2010-01-20 09:04:28 +0100909 marvell_phy_interface_mode (dev, type, speed);
Dave Liue732e9c2006-11-03 12:11:15 -0600910#endif
911}