[processor-sdk/performance-audio-sr.git] / pdk_k2g_1_0_1 / packages / ti / board / src / skAM437x / device / enet_phy.h
1 /**
2 * enet_phy.h
3 *
4 *
5 * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the
17 * distribution.
18 *
19 * Neither the name of Texas Instruments Incorporated nor the names of
20 * its contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 */
36 #ifndef _ENETPHY_H
37 #define _ENETPHY_H
39 //#include "cpsw_nimu_eth.h"
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
45 /***************************************************************************
46 **
47 ** M D I O R E G I S T E R A C C E S S M A C R O S
48 **
49 ***************************************************************************/
51 #define MDIO_USERACCESS_DATA (0xFFFF)
52 #define MDIO_USERPHYSEL_LINKSEL (1 << 7)
54 /****************************************************************************/
55 /* */
56 /* P H Y R E G I S T E R D E F I N I T I O N S */
57 /* */
58 /****************************************************************************/
60 /* PHY register offset definitions */
61 #define ENETPHY_BCR (0u)
62 #define ENETPHY_BSR (1u)
63 #define ENETPHY_ID1 (2u)
64 #define ENETPHY_ID2 (3u)
65 #define ENETPHY_AUTONEG_ADV (4u)
66 #define ENETPHY_LINK_PARTNER_ABLTY (5u)
67 #define ENETPHY_1000BT_CONTROL (9u)
68 #define ENETPHY_1000BT_STATUS (0x0A)
70 /* PHY status definitions */
71 #define ENETPHY_ID_SHIFT (16u)
72 #define ENETPHY_SOFTRESET (0x8000)
73 #define ENETPHY_AUTONEG_ENABLE (0x1000u)
74 #define ENETPHY_AUTONEG_RESTART (0x0200u)
75 #define ENETPHY_AUTONEG_COMPLETE (0x0020u)
76 #define ENETPHY_AUTONEG_INCOMPLETE (0x0000u)
77 #define ENETPHY_AUTONEG_STATUS (0x0020u)
78 #define ENETPHY_AUTONEG_ABLE (0x0008u)
79 #define ENETPHY_LPBK_ENABLE (0x4000u)
80 #define ENETPHY_LINK_STATUS (0x0004u)
82 /* PHY ID. The LSB nibble will vary between different phy revisions */
83 #define ENETPHY_ID_REV_MASK (0x0000000Fu)
85 /* Pause operations */
86 #define ENETPHY_PAUSE_NIL (0x0000u)
87 #define ENETPHY_PAUSE_SYM (0x0400u)
88 #define ENETPHY_PAUSE_ASYM (0x0800u)
89 #define ENETPHY_PAUSE_BOTH_SYM_ASYM (0x0C00u)
91 /* 1000 Base-T capabilities */
92 #define ENETPHY_NO_1000BT (0x0000u)
93 #define ENETPHY_1000BT_HD (0x0100u)
94 #define ENETPHY_1000BT_FD (0x0200u)
96 /* 100 Base TX Full Duplex capablity */
97 #define ENETPHY_100BTX_HD (0x0000u)
98 #define ENETPHY_100BTX_FD (0x0100u)
100 /* 100 Base TX capability */
101 #define ENETPHY_NO_100BTX (0x0000u)
102 #define ENETPHY_100BTX (0x0080u)
104 /* 10 BaseT duplex capabilities */
105 #define ENETPHY_10BT_HD (0x0000u)
106 #define ENETPHY_10BT_FD (0x0040u)
108 /* 10 BaseT ability*/
109 #define ENETPHY_NO_10BT (0x0000u)
110 #define ENETPHY_10BT (0x0020u)
112 #define ENETPHY_LINK_PARTNER_1000BT_FD (0x0800u)
113 #define ENETPHY_LINK_PARTNER_1000BT_HD (0x0400u)
115 /* Speed settings for BCR register */
116 #define ENETPHY_SPEED_MASK (0xDFBF)
117 #define ENETPHY_SPEED_10MBPS (0x0000u)
118 #define ENETPHY_SPEED_100MBPS (0x2000u)
119 #define ENETPHY_SPEED_1000MBPS (0x0040)
121 /* Duplex settings for BCR register */
122 #define ENETPHY_FULL_DUPLEX (0x0100)
124 #define ENETPHY_CONTROL_REG 0
125 #define MII_ENETPHY_RESET (1<<15)
126 #define MII_ENETPHY_LOOP (1<<14)
127 #define MII_ENETPHY_100 (1<<13)
128 #define MII_AUTO_NEGOTIATE_EN (1<<12)
129 #define MII_ENETPHY_PDOWN (1<<11)
130 #define MII_ENETPHY_ISOLATE (1<<10)
131 #define MII_RENEGOTIATE (1<<9)
132 #define MII_ENETPHY_FD (1<<8)
133 #define MII_ENETPHY_1000 (1<<6)
135 #define ENETPHY_STATUS_REG 1
136 #define MII_NWAY_COMPLETE (1<<5)
137 #define MII_NWAY_CAPABLE (1<<3)
138 #define MII_ENETPHY_LINKED (1<<2)
140 #define ENETPHY_IDENT_REG 2
141 #define NWAY_ADVERTIZE_REG 4
142 #define NWAY_REMADVERTISE_REG 5
143 #define MII_NWAY_FD100 (1<<8)
144 #define MII_NWAY_HD100 (1<<7)
145 #define MII_NWAY_FD10 (1<<6)
146 #define MII_NWAY_HD10 (1<<5)
147 #define MII_NWAY_SEL (1<<0)
149 #define NWAY_1000BT_ADVERTISE_REG 9
150 #define MII_NWAY_MY_FD1000 (1<<9)
151 #define MII_NWAY_MY_HD1000 (1<<8)
152 #define NWAY_1000BT_REMADVERTISE_REG 10
153 #define MII_NWAY_REM_FD1000 (1<<11)
154 #define MII_NWAY_REM_HD1000 (1<<10)
156 #define ENETPHY_CNTRL_REG 0x0019
158 #define ENETPHY_CONFIG_REG 22
159 #define SYSTEM_CLOCK_ENABLE_125MHZ (1<<4)
160 #define TRANSMIT_CLOCK_ENABLE_1000BASET (1<<5)
161 #define GMII_CLOCKED_BY_GTX_CLK (1<<1)
163 #define ENETPHY_LED_CONTROL_REG 28
165 /* Phy Mode Values */
166 #define NWAY_AUTOMDIX (1u << 16u)
167 #define NWAY_FD1000 (1u<<13u)
168 #define NWAY_HD1000 (1u<<12u)
169 #define NWAY_NOPHY (1u<<10u)
170 #define NWAY_LPBK (1u<<9u)
171 #define NWAY_FD100 (1u<<8u)
172 #define NWAY_HD100 (1u<<7u)
173 #define NWAY_FD10 (1u<<6u)
174 #define NWAY_HD10 (1u<<5u)
175 #define NWAY_AUTO (1u<<0u)
177 #define NWAY_AUTOMDIX_ENABLE (1u<<15)
179 /* Tic() return values */
180 #define _MIIMDIO_MDIXFLIP (1u<<28u)
181 #define _AUTOMDIX_DELAY_MIN 80u /* milli-seconds*/
182 #define _AUTOMDIX_DELAY_MAX 200u /* milli-seconds*/
184 /*-----------------------------------------------------------------------
185 * MDIO Events
186 *
187 * These events are returned as result param by ENETPHY_Tic() to allow the application
188 * (or EMAC) to track MDIO status.
189 *-----------------------------------------------------------------------*/
190 #define MDIO_EVENT_NOCHANGE 0u /* No change from previous status */
191 #define MDIO_EVENT_LINKDOWN 1u /* Link down event */
192 #define MDIO_EVENT_LINKUP 2u /* Link (or re-link) event */
193 #define MDIO_EVENT_PHYERROR 3u /* No PHY connected */
195 /*-----------------------------------------------------------------------
196 * MDIO Link Status Values
197 *
198 * These values indicate current PHY link status.
199 * Codes are constructed as follows
200 * Bit0: 0 for HD, 1 for FullDuplex
201 * Bit[2:1]: 10Mbps- 1, 100Mbps - 2, 1000Mbps - 3
202 *
203 *-----------------------------------------------------------------------*/
204 #define MDIO_LINKSTATUS_NOLINK 0u
205 #define MDIO_LINKSTATUS_HD10 2u
206 #define MDIO_LINKSTATUS_FD10 3u
207 #define MDIO_LINKSTATUS_HD100 4u
208 #define MDIO_LINKSTATUS_FD100 5u
209 #define MDIO_LINKSTATUS_FD1000 7u
211 typedef void *ENETPHY_Handle;
213 typedef struct _cpsw_phy_device
214 {
215 Uint32 miibase;
216 Uint32 inst;
217 Uint32 PhyState;
218 Uint32 MdixMask;
219 Uint32 PhyMask;
220 Uint32 MLinkMask;
221 Uint32 PhyMode;
222 Uint32 SPEED_1000; /* set to 1 for gig capable phys */
223 } ENETPHY_DEVICE;
225 /*Version Information */
226 void ENETPHY_GetVer(Uint32 miiBase, Uint32 *ModID, Uint32 *RevMaj, Uint32 *RevMin);
228 /*Called once at the begining of time */
229 int ENETPHY_GetPhyDevSize(void); /*Called first to get size of storage needed!*/
231 int ENETPHY_Init(ENETPHY_Handle hPhyDev, Uint32 miibase, Uint32 inst, Uint32 PhyMask,
232 Uint32 MLinkMask, Uint32 MdixMask, Uint32 PhyAddr, Uint32 ResetBit, Uint32 MdioBusFreq,
233 Uint32 MdioClockFreq,int verbose);
235 /*Called every 100 milli Seconds, returns TRUE if there has been a mode change */
236 int ENETPHY_Tic(ENETPHY_Handle hPhyDev, Uint32* mdioStatus);
238 /*Called to set Phy mode */
239 void ENETPHY_SetPhyMode(ENETPHY_Handle hPhyDev,Uint32 PhyMode);
241 /*Called to Get Phy mode */
242 Uint32 ENETPHY_GetPhyMode(ENETPHY_Handle hPhyDev);
244 /*Calls to retreive info after a mode change! */
245 int ENETPHY_GetDuplex(ENETPHY_Handle hPhyDev);
246 int ENETPHY_GetSpeed(ENETPHY_Handle hPhyDev);
247 int ENETPHY_GetPhyNum(ENETPHY_Handle hPhyDev);
248 int ENETPHY_GetLinked(ENETPHY_Handle hPhyDev);
249 void ENETPHY_LinkChange(ENETPHY_Handle hPhyDev);
250 int ENETPHY_GetLoopback(ENETPHY_Handle hPhyDev);
252 /* Shut Down */
253 void ENETPHY_Close(ENETPHY_Handle hPhyDev, int Full);
255 /* Expert Use Functions (exported) */
256 Uint32 _ENETPHY_UserAccessRead (ENETPHY_Handle hPhyDev, Uint32 regadr, Uint32 phyadr, Uint32 *data);
257 void _ENETPHY_UserAccessWrite(ENETPHY_Handle hPhyDev, Uint32 regadr, Uint32 phyadr, Uint32 data);
259 #ifdef __cplusplus
260 }
261 #endif
263 #endif /*_CPSW_MIIMDIO_H*/