2002-08-17 09:36:01 +00:00
|
|
|
/*-----------------------------------------------------------------------------+
|
|
|
|
|
|
2005-08-16 16:18:00 +00:00
|
|
|
| This source code has been made available to you by IBM on an AS-IS
|
|
|
|
| basis. Anyone receiving this source is licensed under IBM
|
|
|
|
| copyrights to use it in any way he or she deems fit, including
|
|
|
|
| copying it, modifying it, compiling it, and redistributing it either
|
|
|
|
| with or without modifications. No license under IBM patents or
|
|
|
|
| patent applications is to be implied by the copyright license.
|
2002-08-17 09:36:01 +00:00
|
|
|
|
|
2005-08-16 16:18:00 +00:00
|
|
|
| Any user of this software should understand that IBM cannot provide
|
|
|
|
| technical support for this software and will not be responsible for
|
|
|
|
| any consequences resulting from the use of this software.
|
2002-08-17 09:36:01 +00:00
|
|
|
|
|
2005-08-16 16:18:00 +00:00
|
|
|
| Any person who transfers this source code or any derivative work
|
|
|
|
| must include the IBM copyright notice, this paragraph, and the
|
|
|
|
| preceding two paragraphs in the transferred software.
|
2002-08-17 09:36:01 +00:00
|
|
|
|
|
2005-08-16 16:18:00 +00:00
|
|
|
| COPYRIGHT I B M CORPORATION 1995
|
|
|
|
| LICENSED MATERIAL - PROGRAM PROPERTY OF I B M
|
2002-08-17 09:36:01 +00:00
|
|
|
+-----------------------------------------------------------------------------*/
|
|
|
|
/*-----------------------------------------------------------------------------+
|
|
|
|
|
|
2005-08-16 16:18:00 +00:00
|
|
|
| File Name: miiphy.c
|
2002-08-17 09:36:01 +00:00
|
|
|
|
|
2005-08-16 16:18:00 +00:00
|
|
|
| Function: This module has utilities for accessing the MII PHY through
|
2002-08-17 09:36:01 +00:00
|
|
|
| the EMAC3 macro.
|
|
|
|
|
|
2005-08-16 16:18:00 +00:00
|
|
|
| Author: Mark Wisner
|
2002-08-17 09:36:01 +00:00
|
|
|
|
|
|
|
|
+-----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <asm/processor.h>
|
2007-10-23 12:03:17 +00:00
|
|
|
#include <asm/io.h>
|
2002-08-17 09:36:01 +00:00
|
|
|
#include <ppc_asm.tmpl>
|
|
|
|
#include <commproc.h>
|
2005-08-16 16:18:00 +00:00
|
|
|
#include <ppc4xx_enet.h>
|
2002-08-17 09:36:01 +00:00
|
|
|
#include <405_mal.h>
|
|
|
|
#include <miiphy.h>
|
|
|
|
|
2006-06-30 14:30:46 +00:00
|
|
|
#undef ET_DEBUG
|
2002-08-17 09:36:01 +00:00
|
|
|
/***********************************************************/
|
2005-08-16 16:18:00 +00:00
|
|
|
/* Dump out to the screen PHY regs */
|
2002-08-17 09:36:01 +00:00
|
|
|
/***********************************************************/
|
|
|
|
|
2005-10-28 20:30:33 +00:00
|
|
|
void miiphy_dump (char *devname, unsigned char addr)
|
2002-08-17 09:36:01 +00:00
|
|
|
{
|
|
|
|
unsigned long i;
|
|
|
|
unsigned short data;
|
|
|
|
|
|
|
|
for (i = 0; i < 0x1A; i++) {
|
2005-10-28 20:30:33 +00:00
|
|
|
if (miiphy_read (devname, addr, i, &data)) {
|
2002-08-17 09:36:01 +00:00
|
|
|
printf ("read error for reg %lx\n", i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf ("Phy reg %lx ==> %4x\n", i, data);
|
|
|
|
|
|
|
|
/* jump to the next set of regs */
|
|
|
|
if (i == 0x07)
|
|
|
|
i = 0x0f;
|
|
|
|
|
2005-08-16 16:18:00 +00:00
|
|
|
} /* end for loop */
|
|
|
|
} /* end dump */
|
2002-08-17 09:36:01 +00:00
|
|
|
|
|
|
|
/***********************************************************/
|
2005-08-16 16:18:00 +00:00
|
|
|
/* (Re)start autonegotiation */
|
2002-08-17 09:36:01 +00:00
|
|
|
/***********************************************************/
|
2005-10-28 20:30:33 +00:00
|
|
|
int phy_setup_aneg (char *devname, unsigned char addr)
|
2005-08-16 16:18:00 +00:00
|
|
|
{
|
2007-12-27 15:50:55 +00:00
|
|
|
u16 bmcr;
|
|
|
|
|
|
|
|
#if defined(CONFIG_PHY_DYNAMIC_ANEG)
|
|
|
|
/*
|
|
|
|
* Set up advertisement based on capablilities reported by the PHY.
|
|
|
|
* This should work for both copper and fiber.
|
|
|
|
*/
|
|
|
|
u16 bmsr;
|
|
|
|
#if defined(CONFIG_PHY_GIGE)
|
|
|
|
u16 exsr = 0x0000;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
miiphy_read (devname, addr, PHY_BMSR, &bmsr);
|
|
|
|
|
|
|
|
#if defined(CONFIG_PHY_GIGE)
|
|
|
|
if (bmsr & PHY_BMSR_EXT_STAT)
|
|
|
|
miiphy_read (devname, addr, PHY_EXSR, &exsr);
|
|
|
|
|
|
|
|
if (exsr & (PHY_EXSR_1000XF | PHY_EXSR_1000XH)) {
|
|
|
|
/* 1000BASE-X */
|
|
|
|
u16 anar = 0x0000;
|
|
|
|
|
|
|
|
if (exsr & PHY_EXSR_1000XF)
|
|
|
|
anar |= PHY_X_ANLPAR_FD;
|
|
|
|
|
|
|
|
if (exsr & PHY_EXSR_1000XH)
|
|
|
|
anar |= PHY_X_ANLPAR_HD;
|
|
|
|
|
|
|
|
miiphy_write (devname, addr, PHY_ANAR, anar);
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
u16 anar, btcr;
|
|
|
|
|
|
|
|
miiphy_read (devname, addr, PHY_ANAR, &anar);
|
|
|
|
anar &= ~(0x5000 | PHY_ANLPAR_T4 | PHY_ANLPAR_TXFD |
|
|
|
|
PHY_ANLPAR_TX | PHY_ANLPAR_10FD | PHY_ANLPAR_10);
|
|
|
|
|
|
|
|
miiphy_read (devname, addr, PHY_1000BTCR, &btcr);
|
|
|
|
btcr &= ~(0x00FF | PHY_1000BTCR_1000FD | PHY_1000BTCR_1000HD);
|
|
|
|
|
|
|
|
if (bmsr & PHY_BMSR_100T4)
|
|
|
|
anar |= PHY_ANLPAR_T4;
|
|
|
|
|
|
|
|
if (bmsr & PHY_BMSR_100TXF)
|
|
|
|
anar |= PHY_ANLPAR_TXFD;
|
|
|
|
|
|
|
|
if (bmsr & PHY_BMSR_100TXH)
|
|
|
|
anar |= PHY_ANLPAR_TX;
|
|
|
|
|
|
|
|
if (bmsr & PHY_BMSR_10TF)
|
|
|
|
anar |= PHY_ANLPAR_10FD;
|
|
|
|
|
|
|
|
if (bmsr & PHY_BMSR_10TH)
|
|
|
|
anar |= PHY_ANLPAR_10;
|
|
|
|
|
|
|
|
miiphy_write (devname, addr, PHY_ANAR, anar);
|
|
|
|
|
|
|
|
#if defined(CONFIG_PHY_GIGE)
|
|
|
|
if (exsr & PHY_EXSR_1000TF)
|
|
|
|
btcr |= PHY_1000BTCR_1000FD;
|
|
|
|
|
|
|
|
if (exsr & PHY_EXSR_1000TH)
|
|
|
|
btcr |= PHY_1000BTCR_1000HD;
|
|
|
|
|
|
|
|
miiphy_write (devname, addr, PHY_1000BTCR, btcr);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* defined(CONFIG_PHY_DYNAMIC_ANEG) */
|
|
|
|
/*
|
|
|
|
* Set up standard advertisement
|
|
|
|
*/
|
|
|
|
u16 adv;
|
2005-08-16 16:18:00 +00:00
|
|
|
|
2005-10-28 20:30:33 +00:00
|
|
|
miiphy_read (devname, addr, PHY_ANAR, &adv);
|
2005-08-16 16:18:00 +00:00
|
|
|
adv |= (PHY_ANLPAR_ACK | PHY_ANLPAR_RF | PHY_ANLPAR_T4 |
|
|
|
|
PHY_ANLPAR_TXFD | PHY_ANLPAR_TX | PHY_ANLPAR_10FD |
|
|
|
|
PHY_ANLPAR_10);
|
2005-10-28 20:30:33 +00:00
|
|
|
miiphy_write (devname, addr, PHY_ANAR, adv);
|
2002-08-17 09:36:01 +00:00
|
|
|
|
2006-06-30 14:30:46 +00:00
|
|
|
miiphy_read (devname, addr, PHY_1000BTCR, &adv);
|
|
|
|
adv |= (0x0300);
|
|
|
|
miiphy_write (devname, addr, PHY_1000BTCR, adv);
|
|
|
|
|
2007-12-27 15:50:55 +00:00
|
|
|
#endif /* defined(CONFIG_PHY_DYNAMIC_ANEG) */
|
|
|
|
|
2005-08-16 16:18:00 +00:00
|
|
|
/* Start/Restart aneg */
|
2007-12-27 15:50:55 +00:00
|
|
|
miiphy_read (devname, addr, PHY_BMCR, &bmcr);
|
|
|
|
bmcr |= (PHY_BMCR_AUTON | PHY_BMCR_RST_NEG);
|
|
|
|
miiphy_write (devname, addr, PHY_BMCR, bmcr);
|
2005-08-16 16:18:00 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************/
|
|
|
|
/* read a phy reg and return the value with a rc */
|
|
|
|
/***********************************************************/
|
|
|
|
unsigned int miiphy_getemac_offset (void)
|
2002-08-17 09:36:01 +00:00
|
|
|
{
|
2006-06-30 14:30:46 +00:00
|
|
|
#if (defined(CONFIG_440) && !defined(CONFIG_440SP) && !defined(CONFIG_440SPE)) && defined(CONFIG_NET_MULTI)
|
2005-08-16 16:18:00 +00:00
|
|
|
unsigned long zmii;
|
|
|
|
unsigned long eoffset;
|
|
|
|
|
|
|
|
/* Need to find out which mdi port we're using */
|
2007-10-23 12:03:17 +00:00
|
|
|
zmii = in_be32((void *)ZMII_FER);
|
2005-08-16 16:18:00 +00:00
|
|
|
|
2007-12-27 15:50:55 +00:00
|
|
|
if (zmii & (ZMII_FER_MDI << ZMII_FER_V (0)))
|
2005-08-16 16:18:00 +00:00
|
|
|
/* using port 0 */
|
|
|
|
eoffset = 0;
|
2007-12-27 15:50:55 +00:00
|
|
|
|
|
|
|
else if (zmii & (ZMII_FER_MDI << ZMII_FER_V (1)))
|
2005-08-16 16:18:00 +00:00
|
|
|
/* using port 1 */
|
|
|
|
eoffset = 0x100;
|
2007-12-27 15:50:55 +00:00
|
|
|
|
|
|
|
else if (zmii & (ZMII_FER_MDI << ZMII_FER_V (2)))
|
2005-08-16 16:18:00 +00:00
|
|
|
/* using port 2 */
|
|
|
|
eoffset = 0x400;
|
2007-12-27 15:50:55 +00:00
|
|
|
|
|
|
|
else if (zmii & (ZMII_FER_MDI << ZMII_FER_V (3)))
|
2005-08-16 16:18:00 +00:00
|
|
|
/* using port 3 */
|
|
|
|
eoffset = 0x600;
|
2007-12-27 15:50:55 +00:00
|
|
|
|
|
|
|
else {
|
2005-08-16 16:18:00 +00:00
|
|
|
/* None of the mdi ports are enabled! */
|
|
|
|
/* enable port 0 */
|
|
|
|
zmii |= ZMII_FER_MDI << ZMII_FER_V (0);
|
2007-10-23 12:03:17 +00:00
|
|
|
out_be32((void *)ZMII_FER, zmii);
|
2005-08-16 16:18:00 +00:00
|
|
|
eoffset = 0;
|
|
|
|
/* need to soft reset port 0 */
|
2007-10-23 12:03:17 +00:00
|
|
|
zmii = in_be32((void *)EMAC_M0);
|
2005-08-16 16:18:00 +00:00
|
|
|
zmii |= EMAC_M0_SRST;
|
2007-10-23 12:03:17 +00:00
|
|
|
out_be32((void *)EMAC_M0, zmii);
|
2005-08-16 16:18:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (eoffset);
|
|
|
|
#else
|
2007-10-05 15:10:59 +00:00
|
|
|
|
|
|
|
#if defined(CONFIG_NET_MULTI) && defined(CONFIG_405EX)
|
|
|
|
unsigned long rgmii;
|
|
|
|
int devnum = 1;
|
|
|
|
|
2007-10-23 12:03:17 +00:00
|
|
|
rgmii = in_be32((void *)RGMII_FER);
|
2007-10-05 15:10:59 +00:00
|
|
|
if (rgmii & (1 << (19 - devnum)))
|
|
|
|
return 0x100;
|
|
|
|
#endif
|
|
|
|
|
2005-08-16 16:18:00 +00:00
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-12-27 15:50:55 +00:00
|
|
|
int emac4xx_miiphy_read (char *devname, unsigned char addr, unsigned char reg,
|
|
|
|
unsigned short *value)
|
2005-08-16 16:18:00 +00:00
|
|
|
{
|
|
|
|
unsigned long sta_reg; /* STA scratch area */
|
2002-08-17 09:36:01 +00:00
|
|
|
unsigned long i;
|
2005-08-16 16:18:00 +00:00
|
|
|
unsigned long emac_reg;
|
|
|
|
|
|
|
|
emac_reg = miiphy_getemac_offset ();
|
2002-08-17 09:36:01 +00:00
|
|
|
/* see if it is ready for 1000 nsec */
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
/* see if it is ready for sec */
|
2007-12-27 15:50:55 +00:00
|
|
|
while ((in_be32((void *)EMAC_STACR + emac_reg) & EMAC_STACR_OC) ==
|
|
|
|
EMAC_STACR_OC_MASK) {
|
2002-08-17 09:36:01 +00:00
|
|
|
udelay (7);
|
|
|
|
if (i > 5) {
|
2006-06-30 14:30:46 +00:00
|
|
|
#ifdef ET_DEBUG
|
2007-10-23 12:03:17 +00:00
|
|
|
sta_reg = in_be32((void *)EMAC_STACR + emac_reg);
|
2006-06-30 14:30:46 +00:00
|
|
|
printf ("read : EMAC_STACR=0x%0x\n", sta_reg); /* test-only */
|
2002-08-17 09:36:01 +00:00
|
|
|
printf ("read err 1\n");
|
2003-12-09 14:57:03 +00:00
|
|
|
#endif
|
2002-08-17 09:36:01 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
2005-08-16 16:18:00 +00:00
|
|
|
sta_reg = reg; /* reg address */
|
2002-08-17 09:36:01 +00:00
|
|
|
/* set clock (50Mhz) and read flags */
|
2006-09-07 09:51:23 +00:00
|
|
|
#if defined(CONFIG_440GX) || defined(CONFIG_440SPE) || \
|
2007-10-05 15:10:59 +00:00
|
|
|
defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
|
|
|
|
defined(CONFIG_405EX)
|
2007-12-27 15:50:55 +00:00
|
|
|
#if defined(CONFIG_IBM_EMAC4_V4) /* EMAC4 V4 changed bit setting */
|
|
|
|
sta_reg = (sta_reg & ~EMAC_STACR_OP_MASK) | EMAC_STACR_READ;
|
2006-06-30 14:30:46 +00:00
|
|
|
#else
|
2007-12-27 15:50:55 +00:00
|
|
|
sta_reg |= EMAC_STACR_READ;
|
2006-06-30 14:30:46 +00:00
|
|
|
#endif
|
2005-08-16 16:18:00 +00:00
|
|
|
#else
|
2002-08-17 09:36:01 +00:00
|
|
|
sta_reg = (sta_reg | EMAC_STACR_READ) & ~EMAC_STACR_CLK_100MHZ;
|
2005-08-16 16:18:00 +00:00
|
|
|
#endif
|
|
|
|
|
2006-09-07 09:51:23 +00:00
|
|
|
#if defined(CONFIG_PHY_CLK_FREQ) && !defined(CONFIG_440GX) && \
|
|
|
|
!defined(CONFIG_440SP) && !defined(CONFIG_440SPE) && \
|
2007-10-05 15:10:59 +00:00
|
|
|
!defined(CONFIG_440EPX) && !defined(CONFIG_440GRX) && \
|
|
|
|
!defined(CONFIG_405EX)
|
2003-09-02 22:48:03 +00:00
|
|
|
sta_reg = sta_reg | CONFIG_PHY_CLK_FREQ;
|
2003-09-02 23:08:13 +00:00
|
|
|
#endif
|
2002-08-17 09:36:01 +00:00
|
|
|
sta_reg = sta_reg | (addr << 5); /* Phy address */
|
2006-06-30 14:30:46 +00:00
|
|
|
sta_reg = sta_reg | EMAC_STACR_OC_MASK; /* new IBM emac v4 */
|
2007-10-23 12:03:17 +00:00
|
|
|
out_be32((void *)EMAC_STACR + emac_reg, sta_reg);
|
2006-06-30 14:30:46 +00:00
|
|
|
#ifdef ET_DEBUG
|
2002-08-17 09:36:01 +00:00
|
|
|
printf ("a2: write: EMAC_STACR=0x%0x\n", sta_reg); /* test-only */
|
|
|
|
#endif
|
|
|
|
|
2007-10-23 12:03:17 +00:00
|
|
|
sta_reg = in_be32((void *)EMAC_STACR + emac_reg);
|
2006-06-30 14:30:46 +00:00
|
|
|
#ifdef ET_DEBUG
|
2007-12-27 15:50:55 +00:00
|
|
|
printf ("a21: read : EMAC_STACR=0x%0x\n", sta_reg); /* test-only */
|
2006-06-30 14:30:46 +00:00
|
|
|
#endif
|
2002-08-17 09:36:01 +00:00
|
|
|
i = 0;
|
2006-06-30 14:30:46 +00:00
|
|
|
while ((sta_reg & EMAC_STACR_OC) == EMAC_STACR_OC_MASK) {
|
2002-08-17 09:36:01 +00:00
|
|
|
udelay (7);
|
2007-12-27 15:50:55 +00:00
|
|
|
if (i > 5)
|
2002-08-17 09:36:01 +00:00
|
|
|
return -1;
|
2007-12-27 15:50:55 +00:00
|
|
|
|
2002-08-17 09:36:01 +00:00
|
|
|
i++;
|
2007-10-23 12:03:17 +00:00
|
|
|
sta_reg = in_be32((void *)EMAC_STACR + emac_reg);
|
2006-06-30 14:30:46 +00:00
|
|
|
#ifdef ET_DEBUG
|
|
|
|
printf ("a22: read : EMAC_STACR=0x%0x\n", sta_reg); /* test-only */
|
|
|
|
#endif
|
2002-08-17 09:36:01 +00:00
|
|
|
}
|
2007-12-27 15:50:55 +00:00
|
|
|
if ((sta_reg & EMAC_STACR_PHYE) != 0)
|
2002-08-17 09:36:01 +00:00
|
|
|
return -1;
|
|
|
|
|
2007-12-27 15:50:55 +00:00
|
|
|
*value = *(short *)(&sta_reg);
|
2002-08-17 09:36:01 +00:00
|
|
|
return 0;
|
|
|
|
|
2005-08-16 16:18:00 +00:00
|
|
|
} /* phy_read */
|
2002-08-17 09:36:01 +00:00
|
|
|
|
|
|
|
/***********************************************************/
|
2005-08-16 16:18:00 +00:00
|
|
|
/* write a phy reg and return the value with a rc */
|
2002-08-17 09:36:01 +00:00
|
|
|
/***********************************************************/
|
|
|
|
|
2007-12-27 15:50:55 +00:00
|
|
|
int emac4xx_miiphy_write (char *devname, unsigned char addr, unsigned char reg,
|
|
|
|
unsigned short value)
|
2002-08-17 09:36:01 +00:00
|
|
|
{
|
2005-08-16 16:18:00 +00:00
|
|
|
unsigned long sta_reg; /* STA scratch area */
|
2002-08-17 09:36:01 +00:00
|
|
|
unsigned long i;
|
2005-08-16 16:18:00 +00:00
|
|
|
unsigned long emac_reg;
|
2002-08-17 09:36:01 +00:00
|
|
|
|
2005-08-16 16:18:00 +00:00
|
|
|
emac_reg = miiphy_getemac_offset ();
|
2002-08-17 09:36:01 +00:00
|
|
|
/* see if it is ready for 1000 nsec */
|
|
|
|
i = 0;
|
|
|
|
|
2007-12-27 15:50:55 +00:00
|
|
|
while ((in_be32((void *)EMAC_STACR + emac_reg) & EMAC_STACR_OC) ==
|
|
|
|
EMAC_STACR_OC_MASK) {
|
2002-08-17 09:36:01 +00:00
|
|
|
if (i > 5)
|
|
|
|
return -1;
|
2007-12-27 15:50:55 +00:00
|
|
|
|
2002-08-17 09:36:01 +00:00
|
|
|
udelay (7);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
sta_reg = 0;
|
2005-08-16 16:18:00 +00:00
|
|
|
sta_reg = reg; /* reg address */
|
2002-08-17 09:36:01 +00:00
|
|
|
/* set clock (50Mhz) and read flags */
|
2006-09-07 09:51:23 +00:00
|
|
|
#if defined(CONFIG_440GX) || defined(CONFIG_440SPE) || \
|
2007-10-05 15:10:59 +00:00
|
|
|
defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
|
|
|
|
defined(CONFIG_405EX)
|
2007-12-27 15:50:55 +00:00
|
|
|
#if defined(CONFIG_IBM_EMAC4_V4) /* EMAC4 V4 changed bit setting */
|
|
|
|
sta_reg = (sta_reg & ~EMAC_STACR_OP_MASK) | EMAC_STACR_WRITE;
|
2006-06-30 14:30:46 +00:00
|
|
|
#else
|
2007-12-27 15:50:55 +00:00
|
|
|
sta_reg |= EMAC_STACR_WRITE;
|
2006-06-30 14:30:46 +00:00
|
|
|
#endif
|
2005-08-16 16:18:00 +00:00
|
|
|
#else
|
2002-08-17 09:36:01 +00:00
|
|
|
sta_reg = (sta_reg | EMAC_STACR_WRITE) & ~EMAC_STACR_CLK_100MHZ;
|
2005-08-16 16:18:00 +00:00
|
|
|
#endif
|
|
|
|
|
2006-09-07 09:51:23 +00:00
|
|
|
#if defined(CONFIG_PHY_CLK_FREQ) && !defined(CONFIG_440GX) && \
|
|
|
|
!defined(CONFIG_440SP) && !defined(CONFIG_440SPE) && \
|
2007-10-05 15:10:59 +00:00
|
|
|
!defined(CONFIG_440EPX) && !defined(CONFIG_440GRX) && \
|
|
|
|
!defined(CONFIG_405EX)
|
2005-08-16 16:18:00 +00:00
|
|
|
sta_reg = sta_reg | CONFIG_PHY_CLK_FREQ; /* Set clock frequency (PLB freq. dependend) */
|
2003-09-02 23:08:13 +00:00
|
|
|
#endif
|
2007-12-27 15:50:55 +00:00
|
|
|
sta_reg = sta_reg | ((unsigned long)addr << 5); /* Phy address */
|
|
|
|
sta_reg = sta_reg | EMAC_STACR_OC_MASK; /* new IBM emac v4 */
|
2002-08-17 09:36:01 +00:00
|
|
|
memcpy (&sta_reg, &value, 2); /* put in data */
|
|
|
|
|
2007-10-23 12:03:17 +00:00
|
|
|
out_be32((void *)EMAC_STACR + emac_reg, sta_reg);
|
2002-08-17 09:36:01 +00:00
|
|
|
|
|
|
|
/* wait for completion */
|
|
|
|
i = 0;
|
2007-10-23 12:03:17 +00:00
|
|
|
sta_reg = in_be32((void *)EMAC_STACR + emac_reg);
|
2006-06-30 14:30:46 +00:00
|
|
|
#ifdef ET_DEBUG
|
2007-12-27 15:50:55 +00:00
|
|
|
printf ("a31: read : EMAC_STACR=0x%0x\n", sta_reg); /* test-only */
|
2006-06-30 14:30:46 +00:00
|
|
|
#endif
|
|
|
|
while ((sta_reg & EMAC_STACR_OC) == EMAC_STACR_OC_MASK) {
|
2002-08-17 09:36:01 +00:00
|
|
|
udelay (7);
|
|
|
|
if (i > 5)
|
|
|
|
return -1;
|
2007-12-27 15:50:55 +00:00
|
|
|
|
2002-08-17 09:36:01 +00:00
|
|
|
i++;
|
2007-10-23 12:03:17 +00:00
|
|
|
sta_reg = in_be32((void *)EMAC_STACR + emac_reg);
|
2006-06-30 14:30:46 +00:00
|
|
|
#ifdef ET_DEBUG
|
|
|
|
printf ("a32: read : EMAC_STACR=0x%0x\n", sta_reg); /* test-only */
|
|
|
|
#endif
|
2002-08-17 09:36:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((sta_reg & EMAC_STACR_PHYE) != 0)
|
|
|
|
return -1;
|
2007-12-27 15:50:55 +00:00
|
|
|
|
2002-08-17 09:36:01 +00:00
|
|
|
return 0;
|
|
|
|
|
2007-12-27 15:50:55 +00:00
|
|
|
} /* phy_write */
|