4 * \brief KSZ8051MNL (Ethernet PHY) driver for SAM.
\r
6 * Copyright (c) 2013 Atmel Corporation. All rights reserved.
\r
12 * Redistribution and use in source and binary forms, with or without
\r
13 * modification, are permitted provided that the following conditions are met:
\r
15 * 1. Redistributions of source code must retain the above copyright notice,
\r
16 * this list of conditions and the following disclaimer.
\r
18 * 2. Redistributions in binary form must reproduce the above copyright notice,
\r
19 * this list of conditions and the following disclaimer in the documentation
\r
20 * and/or other materials provided with the distribution.
\r
22 * 3. The name of Atmel may not be used to endorse or promote products derived
\r
23 * from this software without specific prior written permission.
\r
25 * 4. This software may only be redistributed and used in connection with an
\r
26 * Atmel microcontroller product.
\r
28 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
\r
29 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
\r
30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
\r
31 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
\r
32 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
\r
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
\r
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
\r
36 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
\r
37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
\r
38 * POSSIBILITY OF SUCH DAMAGE.
\r
44 #ifndef ETHERNET_PHY_H_INCLUDED
\r
45 #define ETHERNET_PHY_H_INCLUDED
\r
47 #include "compiler.h"
\r
49 // IEEE defined Registers
\r
50 #define GMII_BMCR 0x00 // Basic Control
\r
51 #define GMII_BMSR 0x01 // Basic Status
\r
52 #define GMII_PHYID1 0x02 // PHY Idendifier 1
\r
53 #define GMII_PHYID2 0x03 // PHY Idendifier 2
\r
54 #define GMII_ANAR 0x04 // Auto_Negotiation Advertisement
\r
55 #define GMII_ANLPAR 0x05 // Auto_negotiation Link Partner Ability
\r
56 #define GMII_ANER 0x06 // Auto-negotiation Expansion
\r
57 #define GMII_ANNPR 0x07 // Auto-negotiation Next Page
\r
58 #define GMII_ANLPNPAR 0x08 // Link Partner Next Page Ability
\r
59 //#define GMII_1000BTCR 9 // 1000Base-T Control // Reserved
\r
60 //#define GMII_1000BTSR 10 // 1000Base-T Status // Reserved
\r
61 #define GMII_AFECR1 0x11 // AFE Control 1
\r
62 //#define GMII_ERDWR 12 // Extend Register - Data Write Register
\r
63 //#define GMII_ERDRR 13 // Extend Register - Data Read Register
\r
65 #define GMII_RXERCR 0x15 // RXER Counter
\r
67 #define GMII_OMSOR 0x16 // Operation Mode Strap Override
\r
68 #define GMII_OMSSR 0x17 // Operation Mode Strap Status
\r
69 #define GMII_ECR 0x18 // Expanded Control
\r
70 //#define GMII_DPPSR 19 // Digital PMA/PCS Status
\r
72 //#define GMII_RXERCR 21 // RXER Counter Register
\r
74 #define GMII_ICSR 0x1B // Interrupt Control/Status
\r
75 //#define GMII_DDC1R 28 // Digital Debug Control 1 Register
\r
76 #define GMII_LCSR 0x1D // LinkMD Control/Status
\r
79 #define GMII_PCR1 0x1E // PHY Control 1
\r
80 #define GMII_PCR2 0x1F // PHY Control 2
\r
84 #define GMII_CCR 256 // Common Control Register
\r
85 #define GMII_SSR 257 // Strap Status Register
\r
86 #define GMII_OMSOR 258 // Operation Mode Strap Override Register
\r
87 #define GMII_OMSSR 259 // Operation Mode Strap Status Register
\r
88 #define GMII_RCCPSR 260 // RGMII Clock and Control Pad Skew Register
\r
89 #define GMII_RRDPSR 261 // RGMII RX Data Pad Skew Register
\r
90 #define GMII_ATR 263 // Analog Test Register
\r
94 // Bit definitions: GMII_BMCR 0x00 Basic Control
\r
95 #define GMII_RESET (1 << 15) // 1= Software Reset; 0=Normal Operation
\r
96 #define GMII_LOOPBACK (1 << 14) // 1=loopback Enabled; 0=Normal Operation
\r
97 #define GMII_SPEED_SELECT (1 << 13) // 1=100Mbps; 0=10Mbps
\r
98 #define GMII_AUTONEG (1 << 12) // Auto-negotiation Enable
\r
99 #define GMII_POWER_DOWN (1 << 11) // 1=Power down 0=Normal operation
\r
100 #define GMII_ISOLATE (1 << 10) // 1 = Isolates 0 = Normal operation
\r
101 #define GMII_RESTART_AUTONEG (1 << 9) // 1 = Restart auto-negotiation 0 = Normal operation
\r
102 #define GMII_DUPLEX_MODE (1 << 8) // 1 = Full duplex operation 0 = Normal operation
\r
103 #define GMII_COLLISION_TEST (1 << 7) // 1 = Enable COL test; 0 = Disable COL test
\r
104 //#define GMII_SPEED_SELECT_MSB (1 << 6) // Reserved
\r
105 // Reserved 6 to 0 // Read as 0, ignore on write
\r
107 // Bit definitions: GMII_BMSR 0x01 Basic Status
\r
108 #define GMII_100BASE_T4 (1 << 15) // 100BASE-T4 Capable
\r
109 #define GMII_100BASE_TX_FD (1 << 14) // 100BASE-TX Full Duplex Capable
\r
110 #define GMII_100BASE_T4_HD (1 << 13) // 100BASE-TX Half Duplex Capable
\r
111 #define GMII_10BASE_T_FD (1 << 12) // 10BASE-T Full Duplex Capable
\r
112 #define GMII_10BASE_T_HD (1 << 11) // 10BASE-T Half Duplex Capable
\r
113 // Reserved 10 to79 // Read as 0, ignore on write
\r
114 //#define GMII_EXTEND_STATUS (1 << 8) // 1 = Extend Status Information In Reg 15
\r
116 #define GMII_MF_PREAMB_SUPPR (1 << 6) // MII Frame Preamble Suppression
\r
117 #define GMII_AUTONEG_COMP (1 << 5) // Auto-negotiation Complete
\r
118 #define GMII_REMOTE_FAULT (1 << 4) // Remote Fault
\r
119 #define GMII_AUTONEG_ABILITY (1 << 3) // Auto Configuration Ability
\r
120 #define GMII_LINK_STATUS (1 << 2) // Link Status
\r
121 #define GMII_JABBER_DETECT (1 << 1) // Jabber Detect
\r
122 #define GMII_EXTEND_CAPAB (1 << 0) // Extended Capability
\r
125 // Bit definitions: GMII_PHYID1 0x02 PHY Idendifier 1
\r
126 // Bit definitions: GMII_PHYID2 0x03 PHY Idendifier 2
\r
127 #define GMII_LSB_MASK 0x3F
\r
128 #define GMII_OUI_MSB 0x0022
\r
129 #define GMII_OUI_LSB 0x05
\r
132 // Bit definitions: GMII_ANAR 0x04 Auto_Negotiation Advertisement
\r
133 // Bit definitions: GMII_ANLPAR 0x05 Auto_negotiation Link Partner Ability
\r
134 #define GMII_NP (1 << 15) // Next page Indication
\r
136 #define GMII_RF (1 << 13) // Remote Fault
\r
137 // Reserved 12 // Write as 0, ignore on read
\r
138 #define GMII_PAUSE_MASK (3 << 11) // 0,0 = No Pause 1,0 = Asymmetric Pause(link partner)
\r
139 // 0,1 = Symmetric Pause 1,1 = Symmetric&Asymmetric Pause(local device)
\r
140 #define GMII_100T4 (1 << 9) // 100BASE-T4 Support
\r
141 #define GMII_100TX_FDX (1 << 8) // 100BASE-TX Full Duplex Support
\r
142 #define GMII_100TX_HDX (1 << 7) // 100BASE-TX Support
\r
143 #define GMII_10_FDX (1 << 6) // 10BASE-T Full Duplex Support
\r
144 #define GMII_10_HDX (1 << 5) // 10BASE-T Support
\r
145 // Selector 4 to 0 // Protocol Selection Bits
\r
146 #define GMII_AN_IEEE_802_3 0x0001 // [00001] = IEEE 802.3
\r
149 // Bit definitions: GMII_ANER 0x06 Auto-negotiation Expansion
\r
150 // Reserved 15 to 5 // Read as 0, ignore on write
\r
151 #define GMII_PDF (1 << 4) // Local Device Parallel Detection Fault
\r
152 #define GMII_LP_NP_ABLE (1 << 3) // Link Partner Next Page Able
\r
153 #define GMII_NP_ABLE (1 << 2) // Local Device Next Page Able
\r
154 #define GMII_PAGE_RX (1 << 1) // New Page Received
\r
155 #define GMII_LP_AN_ABLE (1 << 0) // Link Partner Auto-negotiation Able
\r
158 * \brief Perform a HW initialization to the PHY and set up clocks.
\r
160 * This should be called only once to initialize the PHY pre-settings.
\r
161 * The PHY address is the reset status of CRS, RXD[3:0] (the GmacPins' pullups).
\r
162 * The COL pin is used to select MII mode on reset (pulled up for Reduced MII).
\r
163 * The RXDV pin is used to select test mode on reset (pulled up for test mode).
\r
164 * The above pins should be predefined for corresponding settings in resetPins.
\r
165 * The GMAC peripheral pins are configured after the reset is done.
\r
167 * \param p_gmac Pointer to the GMAC instance.
\r
168 * \param uc_phy_addr PHY address.
\r
169 * \param ul_mck GMAC MCK.
\r
171 * Return GMAC_OK if successfully, GMAC_TIMEOUT if timeout.
\r
173 uint8_t ethernet_phy_init(Gmac *p_gmac, uint8_t uc_phy_addr, uint32_t ul_mck);
\r
177 * \brief Get the Link & speed settings, and automatically set up the GMAC with the
\r
180 * \param p_gmac Pointer to the GMAC instance.
\r
181 * \param uc_phy_addr PHY address.
\r
182 * \param uc_apply_setting_flag Set to 0 to not apply the PHY configurations, else to apply.
\r
184 * Return GMAC_OK if successfully, GMAC_TIMEOUT if timeout.
\r
186 uint8_t ethernet_phy_set_link(Gmac *p_gmac, uint8_t uc_phy_addr,
\r
187 uint8_t uc_apply_setting_flag);
\r
191 * \brief Issue an auto negotiation of the PHY.
\r
193 * \param p_gmac Pointer to the GMAC instance.
\r
194 * \param uc_phy_addr PHY address.
\r
196 * Return GMAC_OK if successfully, GMAC_TIMEOUT if timeout.
\r
198 uint8_t ethernet_phy_auto_negotiate(Gmac *p_gmac, uint8_t uc_phy_addr);
\r
201 * \brief Issue a SW reset to reset all registers of the PHY.
\r
203 * \param p_gmac Pointer to the GMAC instance.
\r
204 * \param uc_phy_addr PHY address.
\r
206 * \Return GMAC_OK if successfully, GMAC_TIMEOUT if timeout.
\r
208 uint8_t ethernet_phy_reset(Gmac *p_gmac, uint8_t uc_phy_addr);
\r
210 #endif /* #ifndef ETHERNET_PHY_H_INCLUDED */
\r