blob: 002fb8113b25ffab35a4fa3724765288ea7f9636 [file] [log] [blame]
Wolfgang Denk46263f22013-07-28 22:12:45 +02001/*
Wolfgang Denk1b387ef2013-09-17 11:24:06 +02002 * SPDX-License-Identifier: GPL-2.0 IBM-pibs
Wolfgang Denk46263f22013-07-28 22:12:45 +02003 */
Wolfgang Denkba94a1b2006-05-30 15:56:48 +02004/*-----------------------------------------------------------------------------+
5 |
6 | File Name: miiphy.c
7 |
8 | Function: This module has utilities for accessing the MII PHY through
9 | the EMAC3 macro.
10 |
11 | Author: Mark Wisner
12 |
13 | Change Activity-
14 |
15 | Date Description of Change BY
16 | --------- --------------------- ---
17 | 05-May-99 Created MKW
Wolfgang Denk8ed44d92008-10-19 02:35:50 +020018 | 01-Jul-99 Changed clock setting of sta_reg from 66MHz to 50MHz to
Wolfgang Denkba94a1b2006-05-30 15:56:48 +020019 | better match OPB speed. Also modified delay times. JWB
20 | 29-Jul-99 Added Full duplex support MKW
21 | 24-Aug-99 Removed printf from dp83843_duplex() JWB
22 | 19-Jul-00 Ported to esd cpci405 sr
23 | 23-Dec-03 Ported from miiphy.c to 440GX Travis Sawyer TBS
24 | <travis.sawyer@sandburst.com>
25 |
26 +-----------------------------------------------------------------------------*/
27
28#include <common.h>
29#include <miiphy.h>
30#include "IxOsal.h"
31#include "IxEthAcc.h"
32#include "IxEthAcc_p.h"
33#include "IxEthAccMac_p.h"
34#include "IxEthAccMii_p.h"
35
36/***********************************************************/
37/* Dump out to the screen PHY regs */
38/***********************************************************/
39
40void miiphy_dump (char *devname, unsigned char addr)
41{
42 unsigned long i;
43 unsigned short data;
44
45
46 for (i = 0; i < 0x1A; i++) {
47 if (miiphy_read (devname, addr, i, &data)) {
48 printf ("read error for reg %lx\n", i);
49 return;
50 }
51 printf ("Phy reg %lx ==> %4x\n", i, data);
52
53 /* jump to the next set of regs */
54 if (i == 0x07)
55 i = 0x0f;
56
57 } /* end for loop */
58} /* end dump */
59
60
61/***********************************************************/
62/* (Re)start autonegotiation */
63/***********************************************************/
64int phy_setup_aneg (char *devname, unsigned char addr)
65{
66 unsigned short ctl, adv;
67
68 /* Setup standard advertise */
Mike Frysinger8ef583a2010-12-23 15:40:12 -050069 miiphy_read (devname, addr, MII_ADVERTISE, &adv);
70 adv |= (LPA_LPACK | LPA_RFAULT | LPA_100BASE4 |
71 LPA_100FULL | LPA_100HALF | LPA_10FULL |
72 LPA_10HALF);
73 miiphy_write (devname, addr, MII_ADVERTISE, adv);
Wolfgang Denkba94a1b2006-05-30 15:56:48 +020074
75 /* Start/Restart aneg */
Mike Frysinger8ef583a2010-12-23 15:40:12 -050076 miiphy_read (devname, addr, MII_BMCR, &ctl);
77 ctl |= (BMCR_ANENABLE | BMCR_ANRESTART);
78 miiphy_write (devname, addr, MII_BMCR, ctl);
Wolfgang Denkba94a1b2006-05-30 15:56:48 +020079
80 return 0;
81}
82
83
Mike Frysinger5700bb62010-07-27 18:35:08 -040084int npe_miiphy_read (const char *devname, unsigned char addr,
Wolfgang Denkba94a1b2006-05-30 15:56:48 +020085 unsigned char reg, unsigned short *value)
86{
87 u16 val;
88
89 ixEthAccMiiReadRtn(addr, reg, &val);
90 *value = val;
91
92 return 0;
93} /* phy_read */
94
95
Mike Frysinger5700bb62010-07-27 18:35:08 -040096int npe_miiphy_write (const char *devname, unsigned char addr,
Wolfgang Denkba94a1b2006-05-30 15:56:48 +020097 unsigned char reg, unsigned short value)
98{
99 ixEthAccMiiWriteRtn(addr, reg, value);
100 return 0;
101} /* phy_write */