1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2005,2010-2011 Freescale Semiconductor, Inc.
5 * Author: Shlomi Gridish
7 * Description: UCC GETH Driver -- PHY handling
9 * Based on 8260_io/fcc_enet.c
15 #include <linux/errno.h>
16 #include <linux/immap_qe.h>
25 #define ugphy_printk(format, arg...) \
26 printf(format "\n", ## arg)
28 #define ugphy_dbg(format, arg...) \
29 ugphy_printk(format , ## arg)
30 #define ugphy_err(format, arg...) \
31 ugphy_printk(format , ## arg)
32 #define ugphy_info(format, arg...) \
33 ugphy_printk(format , ## arg)
34 #define ugphy_warn(format, arg...) \
35 ugphy_printk(format , ## arg)
37 #ifdef UEC_VERBOSE_DEBUG
38 #define ugphy_vdbg ugphy_dbg
40 #define ugphy_vdbg(ugeth, fmt, args...) do { } while (0)
41 #endif /* UEC_VERBOSE_DEBUG */
43 /*--------------------------------------------------------------------+
44 * Fixed PHY (PHY-less) support for Ethernet Ports.
46 * Copied from arch/powerpc/cpu/ppc4xx/4xx_enet.c
47 *--------------------------------------------------------------------*/
50 * Some boards do not have a PHY for each ethernet port. These ports are known
51 * as Fixed PHY (or PHY-less) ports. For such ports, set the appropriate
52 * CONFIG_SYS_UECx_PHY_ADDR equal to CONFIG_FIXED_PHY_ADDR (an unused address)
53 * When the drver tries to identify the PHYs, CONFIG_FIXED_PHY will be returned
54 * and the driver will search CONFIG_SYS_FIXED_PHY_PORTS to find what network
55 * speed and duplex should be for the port.
57 * Example board header configuration file:
58 * #define CONFIG_FIXED_PHY 0xFFFFFFFF
59 * #define CONFIG_SYS_FIXED_PHY_ADDR 0x1E (pick an unused phy address)
61 * #define CONFIG_SYS_UEC1_PHY_ADDR CONFIG_SYS_FIXED_PHY_ADDR
62 * #define CONFIG_SYS_UEC2_PHY_ADDR 0x02
63 * #define CONFIG_SYS_UEC3_PHY_ADDR CONFIG_SYS_FIXED_PHY_ADDR
64 * #define CONFIG_SYS_UEC4_PHY_ADDR 0x04
66 * #define CONFIG_SYS_FIXED_PHY_PORT(name,speed,duplex) \
67 * {name, speed, duplex},
69 * #define CONFIG_SYS_FIXED_PHY_PORTS \
70 * CONFIG_SYS_FIXED_PHY_PORT("UEC0",SPEED_100,DUPLEX_FULL) \
71 * CONFIG_SYS_FIXED_PHY_PORT("UEC2",SPEED_100,DUPLEX_HALF)
74 #ifndef CONFIG_FIXED_PHY
75 #define CONFIG_FIXED_PHY 0xFFFFFFFF /* Fixed PHY (PHY-less) */
78 #ifndef CONFIG_SYS_FIXED_PHY_PORTS
79 #define CONFIG_SYS_FIXED_PHY_PORTS /* default is an empty array */
82 struct fixed_phy_port {
83 char name[16]; /* ethernet port name */
84 unsigned int speed; /* specified speed 10,100 or 1000 */
85 unsigned int duplex; /* specified duplex FULL or HALF */
88 static const struct fixed_phy_port fixed_phy_port[] = {
89 CONFIG_SYS_FIXED_PHY_PORTS /* defined in board configuration file */
92 /*--------------------------------------------------------------------+
93 * BitBang MII support for ethernet ports
95 * Based from MPC8560ADS implementation
96 *--------------------------------------------------------------------*/
98 * Example board header file to define bitbang ethernet ports:
100 * #define CONFIG_SYS_BITBANG_PHY_PORT(name) name,
101 * #define CONFIG_SYS_BITBANG_PHY_PORTS CONFIG_SYS_BITBANG_PHY_PORT("UEC0")
103 #ifndef CONFIG_SYS_BITBANG_PHY_PORTS
104 #define CONFIG_SYS_BITBANG_PHY_PORTS /* default is an empty array */
107 #if defined(CONFIG_BITBANGMII)
108 static const char *bitbang_phy_port[] = {
109 CONFIG_SYS_BITBANG_PHY_PORTS /* defined in board configuration file */
111 #endif /* CONFIG_BITBANGMII */
113 static void config_genmii_advert (struct uec_mii_info *mii_info);
114 static void genmii_setup_forced (struct uec_mii_info *mii_info);
115 static void genmii_restart_aneg (struct uec_mii_info *mii_info);
116 static int gbit_config_aneg (struct uec_mii_info *mii_info);
117 static int genmii_config_aneg (struct uec_mii_info *mii_info);
118 static int genmii_update_link (struct uec_mii_info *mii_info);
119 static int genmii_read_status (struct uec_mii_info *mii_info);
120 u16 uec_phy_read(struct uec_mii_info *mii_info, u16 regnum);
121 void uec_phy_write(struct uec_mii_info *mii_info, u16 regnum, u16 val);
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 */
126 void uec_write_phy_reg (struct eth_device *dev, int mii_id, int regnum, int value)
128 uec_private_t *ugeth = (uec_private_t *) dev->priv;
130 enet_tbi_mii_reg_e mii_reg = (enet_tbi_mii_reg_e) regnum;
134 #if defined(CONFIG_BITBANGMII)
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);
144 #endif /* CONFIG_BITBANGMII */
146 ug_regs = ugeth->uec_mii_regs;
148 /* Stop the MII management read cycle */
149 out_be32 (&ug_regs->miimcom, 0);
150 /* Setting up the MII Mangement Address Register */
151 tmp_reg = ((u32) mii_id << MIIMADD_PHY_ADDRESS_SHIFT) | mii_reg;
152 out_be32 (&ug_regs->miimadd, tmp_reg);
154 /* Setting up the MII Mangement Control Register with the value */
155 out_be32 (&ug_regs->miimcon, (u32) value);
158 /* Wait till MII management write is complete */
159 while ((in_be32 (&ug_regs->miimind)) & MIIMIND_BUSY);
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 */
165 int uec_read_phy_reg (struct eth_device *dev, int mii_id, int regnum)
167 uec_private_t *ugeth = (uec_private_t *) dev->priv;
169 enet_tbi_mii_reg_e mii_reg = (enet_tbi_mii_reg_e) regnum;
174 #if defined(CONFIG_BITBANGMII)
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);
184 #endif /* CONFIG_BITBANGMII */
186 ug_regs = ugeth->uec_mii_regs;
188 /* Setting up the MII Mangement Address Register */
189 tmp_reg = ((u32) mii_id << MIIMADD_PHY_ADDRESS_SHIFT) | mii_reg;
190 out_be32 (&ug_regs->miimadd, tmp_reg);
192 /* clear MII management command cycle */
193 out_be32 (&ug_regs->miimcom, 0);
196 /* Perform an MII management read cycle */
197 out_be32 (&ug_regs->miimcom, MIIMCOM_READ_CYCLE);
199 /* Wait till MII management write is complete */
200 while ((in_be32 (&ug_regs->miimind)) &
201 (MIIMIND_NOT_VALID | MIIMIND_BUSY));
203 /* Read MII management status */
204 value = (u16) in_be32 (&ug_regs->miimstat);
207 ("read wrong value : mii_id %d,mii_reg %d, base %08x",
208 mii_id, mii_reg, (u32) & (ug_regs->miimcfg));
213 void mii_clear_phy_interrupt (struct uec_mii_info *mii_info)
215 if (mii_info->phyinfo->ack_interrupt)
216 mii_info->phyinfo->ack_interrupt (mii_info);
219 void mii_configure_phy_interrupt (struct uec_mii_info *mii_info,
222 mii_info->interrupts = interrupts;
223 if (mii_info->phyinfo->config_intr)
224 mii_info->phyinfo->config_intr (mii_info);
227 /* Writes MII_ADVERTISE with the appropriate values, after
228 * sanitizing advertise to make sure only supported features
231 static void config_genmii_advert (struct uec_mii_info *mii_info)
236 /* Only allow advertising what this PHY supports */
237 mii_info->advertising &= mii_info->phyinfo->features;
238 advertise = mii_info->advertising;
240 /* Setup standard advertisement */
241 adv = uec_phy_read(mii_info, MII_ADVERTISE);
242 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4);
243 if (advertise & ADVERTISED_10baseT_Half)
244 adv |= ADVERTISE_10HALF;
245 if (advertise & ADVERTISED_10baseT_Full)
246 adv |= ADVERTISE_10FULL;
247 if (advertise & ADVERTISED_100baseT_Half)
248 adv |= ADVERTISE_100HALF;
249 if (advertise & ADVERTISED_100baseT_Full)
250 adv |= ADVERTISE_100FULL;
251 uec_phy_write(mii_info, MII_ADVERTISE, adv);
254 static void genmii_setup_forced (struct uec_mii_info *mii_info)
257 u32 features = mii_info->phyinfo->features;
259 ctrl = uec_phy_read(mii_info, MII_BMCR);
261 ctrl &= ~(BMCR_FULLDPLX | BMCR_SPEED100 |
262 BMCR_SPEED1000 | BMCR_ANENABLE);
265 switch (mii_info->speed) {
267 if (features & (SUPPORTED_1000baseT_Half
268 | SUPPORTED_1000baseT_Full)) {
269 ctrl |= BMCR_SPEED1000;
272 mii_info->speed = SPEED_100;
274 if (features & (SUPPORTED_100baseT_Half
275 | SUPPORTED_100baseT_Full)) {
276 ctrl |= BMCR_SPEED100;
279 mii_info->speed = SPEED_10;
281 if (features & (SUPPORTED_10baseT_Half
282 | SUPPORTED_10baseT_Full))
284 default: /* Unsupported speed! */
285 ugphy_err ("%s: Bad speed!", mii_info->dev->name);
289 uec_phy_write(mii_info, MII_BMCR, ctrl);
292 /* Enable and Restart Autonegotiation */
293 static void genmii_restart_aneg (struct uec_mii_info *mii_info)
297 ctl = uec_phy_read(mii_info, MII_BMCR);
298 ctl |= (BMCR_ANENABLE | BMCR_ANRESTART);
299 uec_phy_write(mii_info, MII_BMCR, ctl);
302 static int gbit_config_aneg (struct uec_mii_info *mii_info)
307 if (mii_info->autoneg) {
308 /* Configure the ADVERTISE register */
309 config_genmii_advert (mii_info);
310 advertise = mii_info->advertising;
312 adv = uec_phy_read(mii_info, MII_CTRL1000);
313 adv &= ~(ADVERTISE_1000FULL |
315 if (advertise & SUPPORTED_1000baseT_Half)
316 adv |= ADVERTISE_1000HALF;
317 if (advertise & SUPPORTED_1000baseT_Full)
318 adv |= ADVERTISE_1000FULL;
319 uec_phy_write(mii_info, MII_CTRL1000, adv);
321 /* Start/Restart aneg */
322 genmii_restart_aneg (mii_info);
324 genmii_setup_forced (mii_info);
329 static int marvell_config_aneg (struct uec_mii_info *mii_info)
331 /* The Marvell PHY has an errata which requires
332 * that certain registers get written in order
333 * to restart autonegotiation */
334 uec_phy_write(mii_info, MII_BMCR, BMCR_RESET);
336 uec_phy_write(mii_info, 0x1d, 0x1f);
337 uec_phy_write(mii_info, 0x1e, 0x200c);
338 uec_phy_write(mii_info, 0x1d, 0x5);
339 uec_phy_write(mii_info, 0x1e, 0);
340 uec_phy_write(mii_info, 0x1e, 0x100);
342 gbit_config_aneg (mii_info);
347 static int genmii_config_aneg (struct uec_mii_info *mii_info)
349 if (mii_info->autoneg) {
350 /* Speed up the common case, if link is already up, speed and
351 duplex match, skip auto neg as it already matches */
352 if (!genmii_read_status(mii_info) && mii_info->link)
353 if (mii_info->duplex == DUPLEX_FULL &&
354 mii_info->speed == SPEED_100)
355 if (mii_info->advertising &
356 ADVERTISED_100baseT_Full)
359 config_genmii_advert (mii_info);
360 genmii_restart_aneg (mii_info);
362 genmii_setup_forced (mii_info);
367 static int genmii_update_link (struct uec_mii_info *mii_info)
371 /* Status is read once to clear old link state */
372 uec_phy_read(mii_info, MII_BMSR);
375 * Wait if the link is up, and autonegotiation is in progress
376 * (ie - we're capable and it's not done)
378 status = uec_phy_read(mii_info, MII_BMSR);
379 if ((status & BMSR_LSTATUS) && (status & BMSR_ANEGCAPABLE)
380 && !(status & BMSR_ANEGCOMPLETE)) {
383 while (!(status & BMSR_ANEGCOMPLETE)) {
387 if (i > UGETH_AN_TIMEOUT) {
393 udelay(1000); /* 1 ms */
394 status = uec_phy_read(mii_info, MII_BMSR);
398 if (status & BMSR_LSTATUS)
407 static int genmii_read_status (struct uec_mii_info *mii_info)
412 /* Update the link, but return if there
414 err = genmii_update_link (mii_info);
418 if (mii_info->autoneg) {
419 status = uec_phy_read(mii_info, MII_STAT1000);
421 if (status & (LPA_1000FULL | LPA_1000HALF)) {
422 mii_info->speed = SPEED_1000;
423 if (status & LPA_1000FULL)
424 mii_info->duplex = DUPLEX_FULL;
426 mii_info->duplex = DUPLEX_HALF;
428 status = uec_phy_read(mii_info, MII_LPA);
430 if (status & (LPA_10FULL | LPA_100FULL))
431 mii_info->duplex = DUPLEX_FULL;
433 mii_info->duplex = DUPLEX_HALF;
434 if (status & (LPA_100FULL | LPA_100HALF))
435 mii_info->speed = SPEED_100;
437 mii_info->speed = SPEED_10;
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
448 static int bcm_init(struct uec_mii_info *mii_info)
450 struct eth_device *edev = mii_info->dev;
451 uec_private_t *uec = edev->priv;
453 gbit_config_aneg(mii_info);
455 if ((uec->uec_info->enet_interface_type ==
456 PHY_INTERFACE_MODE_RGMII_RXID) &&
457 (uec->uec_info->speed == SPEED_1000)) {
461 /* Wait for aneg to complete. */
463 val = uec_phy_read(mii_info, MII_BMSR);
464 while (--cnt && !(val & BMSR_ANEGCOMPLETE));
466 /* Set RDX clk delay. */
467 uec_phy_write(mii_info, 0x18, 0x7 | (7 << 12));
469 val = uec_phy_read(mii_info, 0x18);
470 /* Set RDX-RXC skew. */
472 val |= (7 | (7 << 12));
473 /* Write bits 14:0. */
475 uec_phy_write(mii_info, 0x18, val);
481 static int uec_marvell_init(struct uec_mii_info *mii_info)
483 struct eth_device *edev = mii_info->dev;
484 uec_private_t *uec = edev->priv;
485 phy_interface_t iface = uec->uec_info->enet_interface_type;
486 int speed = uec->uec_info->speed;
488 if ((speed == SPEED_1000) &&
489 (iface == PHY_INTERFACE_MODE_RGMII_ID ||
490 iface == PHY_INTERFACE_MODE_RGMII_RXID ||
491 iface == PHY_INTERFACE_MODE_RGMII_TXID)) {
494 temp = uec_phy_read(mii_info, MII_M1111_PHY_EXT_CR);
495 if (iface == PHY_INTERFACE_MODE_RGMII_ID) {
496 temp |= MII_M1111_RX_DELAY | MII_M1111_TX_DELAY;
497 } else if (iface == PHY_INTERFACE_MODE_RGMII_RXID) {
498 temp &= ~MII_M1111_TX_DELAY;
499 temp |= MII_M1111_RX_DELAY;
500 } else if (iface == PHY_INTERFACE_MODE_RGMII_TXID) {
501 temp &= ~MII_M1111_RX_DELAY;
502 temp |= MII_M1111_TX_DELAY;
504 uec_phy_write(mii_info, MII_M1111_PHY_EXT_CR, temp);
506 temp = uec_phy_read(mii_info, MII_M1111_PHY_EXT_SR);
507 temp &= ~MII_M1111_HWCFG_MODE_MASK;
508 temp |= MII_M1111_HWCFG_MODE_RGMII;
509 uec_phy_write(mii_info, MII_M1111_PHY_EXT_SR, temp);
511 uec_phy_write(mii_info, MII_BMCR, BMCR_RESET);
517 static int marvell_read_status (struct uec_mii_info *mii_info)
522 /* Update the link, but return if there
524 err = genmii_update_link (mii_info);
528 /* If the link is up, read the speed and duplex */
529 /* If we aren't autonegotiating, assume speeds
531 if (mii_info->autoneg && mii_info->link) {
534 status = uec_phy_read(mii_info, MII_M1011_PHY_SPEC_STATUS);
536 /* Get the duplexity */
537 if (status & MII_M1011_PHY_SPEC_STATUS_FULLDUPLEX)
538 mii_info->duplex = DUPLEX_FULL;
540 mii_info->duplex = DUPLEX_HALF;
543 speed = status & MII_M1011_PHY_SPEC_STATUS_SPD_MASK;
545 case MII_M1011_PHY_SPEC_STATUS_1000:
546 mii_info->speed = SPEED_1000;
548 case MII_M1011_PHY_SPEC_STATUS_100:
549 mii_info->speed = SPEED_100;
552 mii_info->speed = SPEED_10;
561 static int marvell_ack_interrupt (struct uec_mii_info *mii_info)
563 /* Clear the interrupts by reading the reg */
564 uec_phy_read(mii_info, MII_M1011_IEVENT);
569 static int marvell_config_intr (struct uec_mii_info *mii_info)
571 if (mii_info->interrupts == MII_INTERRUPT_ENABLED)
572 uec_phy_write(mii_info, MII_M1011_IMASK, MII_M1011_IMASK_INIT);
574 uec_phy_write(mii_info, MII_M1011_IMASK,
575 MII_M1011_IMASK_CLEAR);
580 static int dm9161_init (struct uec_mii_info *mii_info)
583 uec_phy_write(mii_info, MII_BMCR, uec_phy_read(mii_info, MII_BMCR) |
585 /* PHY and MAC connect */
586 uec_phy_write(mii_info, MII_BMCR, uec_phy_read(mii_info, MII_BMCR) &
589 uec_phy_write(mii_info, MII_DM9161_SCR, MII_DM9161_SCR_INIT);
591 config_genmii_advert (mii_info);
592 /* Start/restart aneg */
593 genmii_config_aneg (mii_info);
598 static int dm9161_config_aneg (struct uec_mii_info *mii_info)
603 static int dm9161_read_status (struct uec_mii_info *mii_info)
608 /* Update the link, but return if there was an error */
609 err = genmii_update_link (mii_info);
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) {
615 status = uec_phy_read(mii_info, MII_DM9161_SCSR);
616 if (status & (MII_DM9161_SCSR_100F | MII_DM9161_SCSR_100H))
617 mii_info->speed = SPEED_100;
619 mii_info->speed = SPEED_10;
621 if (status & (MII_DM9161_SCSR_100F | MII_DM9161_SCSR_10F))
622 mii_info->duplex = DUPLEX_FULL;
624 mii_info->duplex = DUPLEX_HALF;
630 static int dm9161_ack_interrupt (struct uec_mii_info *mii_info)
632 /* Clear the interrupt by reading the reg */
633 uec_phy_read(mii_info, MII_DM9161_INTR);
638 static int dm9161_config_intr (struct uec_mii_info *mii_info)
640 if (mii_info->interrupts == MII_INTERRUPT_ENABLED)
641 uec_phy_write(mii_info, MII_DM9161_INTR, MII_DM9161_INTR_INIT);
643 uec_phy_write(mii_info, MII_DM9161_INTR, MII_DM9161_INTR_STOP);
648 static void dm9161_close (struct uec_mii_info *mii_info)
652 static int fixed_phy_aneg (struct uec_mii_info *mii_info)
654 mii_info->autoneg = 0; /* Turn off auto negotiation for fixed phy */
658 static int fixed_phy_read_status (struct uec_mii_info *mii_info)
662 for (i = 0; i < ARRAY_SIZE(fixed_phy_port); i++) {
663 if (strncmp(mii_info->dev->name, fixed_phy_port[i].name,
664 strlen(mii_info->dev->name)) == 0) {
665 mii_info->speed = fixed_phy_port[i].speed;
666 mii_info->duplex = fixed_phy_port[i].duplex;
667 mii_info->link = 1; /* Link is always UP */
675 static int smsc_config_aneg (struct uec_mii_info *mii_info)
680 static int smsc_read_status (struct uec_mii_info *mii_info)
685 /* Update the link, but return if there
687 err = genmii_update_link (mii_info);
691 /* If the link is up, read the speed and duplex */
692 /* If we aren't autonegotiating, assume speeds
694 if (mii_info->autoneg && mii_info->link) {
697 status = uec_phy_read(mii_info, 0x1f);
698 val = (status & 0x1c) >> 2;
702 mii_info->duplex = DUPLEX_HALF;
703 mii_info->speed = SPEED_10;
706 mii_info->duplex = DUPLEX_FULL;
707 mii_info->speed = SPEED_10;
710 mii_info->duplex = DUPLEX_HALF;
711 mii_info->speed = SPEED_100;
714 mii_info->duplex = DUPLEX_FULL;
715 mii_info->speed = SPEED_100;
724 static struct phy_info phy_info_dm9161 = {
725 .phy_id = 0x0181b880,
726 .phy_id_mask = 0x0ffffff0,
727 .name = "Davicom DM9161E",
729 .config_aneg = dm9161_config_aneg,
730 .read_status = dm9161_read_status,
731 .close = dm9161_close,
734 static struct phy_info phy_info_dm9161a = {
735 .phy_id = 0x0181b8a0,
736 .phy_id_mask = 0x0ffffff0,
737 .name = "Davicom DM9161A",
738 .features = MII_BASIC_FEATURES,
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,
747 static struct phy_info phy_info_marvell = {
748 .phy_id = 0x01410c00,
749 .phy_id_mask = 0xffffff00,
750 .name = "Marvell 88E11x1",
751 .features = MII_GBIT_FEATURES,
752 .init = &uec_marvell_init,
753 .config_aneg = &marvell_config_aneg,
754 .read_status = &marvell_read_status,
755 .ack_interrupt = &marvell_ack_interrupt,
756 .config_intr = &marvell_config_intr,
759 static struct phy_info phy_info_bcm5481 = {
760 .phy_id = 0x0143bca0,
761 .phy_id_mask = 0xffffff0,
762 .name = "Broadcom 5481",
763 .features = MII_GBIT_FEATURES,
764 .read_status = genmii_read_status,
768 static struct phy_info phy_info_fixedphy = {
769 .phy_id = CONFIG_FIXED_PHY,
770 .phy_id_mask = CONFIG_FIXED_PHY,
772 .config_aneg = fixed_phy_aneg,
773 .read_status = fixed_phy_read_status,
776 static struct phy_info phy_info_smsclan8700 = {
777 .phy_id = 0x0007c0c0,
778 .phy_id_mask = 0xfffffff0,
779 .name = "SMSC LAN8700",
780 .features = MII_BASIC_FEATURES,
781 .config_aneg = smsc_config_aneg,
782 .read_status = smsc_read_status,
785 static struct phy_info phy_info_genmii = {
786 .phy_id = 0x00000000,
787 .phy_id_mask = 0x00000000,
788 .name = "Generic MII",
789 .features = MII_BASIC_FEATURES,
790 .config_aneg = genmii_config_aneg,
791 .read_status = genmii_read_status,
794 static struct phy_info *phy_info[] = {
799 &phy_info_smsclan8700,
805 u16 uec_phy_read(struct uec_mii_info *mii_info, u16 regnum)
807 return mii_info->mdio_read (mii_info->dev, mii_info->mii_id, regnum);
810 void uec_phy_write(struct uec_mii_info *mii_info, u16 regnum, u16 val)
812 mii_info->mdio_write (mii_info->dev, mii_info->mii_id, regnum, val);
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
818 struct phy_info *uec_get_phy_info (struct uec_mii_info *mii_info)
823 struct phy_info *theInfo = NULL;
825 /* Grab the bits from PHYIR1, and put them in the upper half */
826 phy_reg = uec_phy_read(mii_info, MII_PHYSID1);
827 phy_ID = (phy_reg & 0xffff) << 16;
829 /* Grab the bits from PHYIR2, and put them in the lower half */
830 phy_reg = uec_phy_read(mii_info, MII_PHYSID2);
831 phy_ID |= (phy_reg & 0xffff);
833 /* loop through all the known PHY types, and find one that */
834 /* matches the ID we read from the PHY. */
835 for (i = 0; phy_info[i]; i++)
836 if (phy_info[i]->phy_id ==
837 (phy_ID & phy_info[i]->phy_id_mask)) {
838 theInfo = phy_info[i];
842 /* This shouldn't happen, as we have generic PHY support */
843 if (theInfo == NULL) {
844 ugphy_info ("UEC: PHY id %x is not supported!", phy_ID);
847 ugphy_info ("UEC: PHY is %s (%x)", theInfo->name, phy_ID);
853 void marvell_phy_interface_mode(struct eth_device *dev, phy_interface_t type,
856 uec_private_t *uec = (uec_private_t *) dev->priv;
857 struct uec_mii_info *mii_info;
860 if (!uec->mii_info) {
861 printf ("%s: the PHY not initialized\n", __FUNCTION__);
864 mii_info = uec->mii_info;
866 if (type == PHY_INTERFACE_MODE_RGMII) {
867 if (speed == SPEED_100) {
868 uec_phy_write(mii_info, 0x00, 0x9140);
869 uec_phy_write(mii_info, 0x1d, 0x001f);
870 uec_phy_write(mii_info, 0x1e, 0x200c);
871 uec_phy_write(mii_info, 0x1d, 0x0005);
872 uec_phy_write(mii_info, 0x1e, 0x0000);
873 uec_phy_write(mii_info, 0x1e, 0x0100);
874 uec_phy_write(mii_info, 0x09, 0x0e00);
875 uec_phy_write(mii_info, 0x04, 0x01e1);
876 uec_phy_write(mii_info, 0x00, 0x9140);
877 uec_phy_write(mii_info, 0x00, 0x1000);
879 uec_phy_write(mii_info, 0x00, 0x2900);
880 uec_phy_write(mii_info, 0x14, 0x0cd2);
881 uec_phy_write(mii_info, 0x00, 0xa100);
882 uec_phy_write(mii_info, 0x09, 0x0000);
883 uec_phy_write(mii_info, 0x1b, 0x800b);
884 uec_phy_write(mii_info, 0x04, 0x05e1);
885 uec_phy_write(mii_info, 0x00, 0xa100);
886 uec_phy_write(mii_info, 0x00, 0x2100);
888 } else if (speed == SPEED_10) {
889 uec_phy_write(mii_info, 0x14, 0x8e40);
890 uec_phy_write(mii_info, 0x1b, 0x800b);
891 uec_phy_write(mii_info, 0x14, 0x0c82);
892 uec_phy_write(mii_info, 0x00, 0x8100);
897 /* handle 88e1111 rev.B2 erratum 5.6 */
898 if (mii_info->autoneg) {
899 status = uec_phy_read(mii_info, MII_BMCR);
900 uec_phy_write(mii_info, MII_BMCR, status | BMCR_ANENABLE);
902 /* now the B2 will correctly report autoneg completion status */
905 void change_phy_interface_mode (struct eth_device *dev,
906 phy_interface_t type, int speed)
908 #ifdef CONFIG_PHY_MODE_NEED_CHANGE
909 marvell_phy_interface_mode (dev, type, speed);