]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/ATSAM4E/ethernet_phy.h
8ea5fa0c720aac048405c24158e80f3e5814cf43
[freertos] / FreeRTOS-Plus / Source / FreeRTOS-Plus-TCP / portable / NetworkInterface / ATSAM4E / ethernet_phy.h
1 /**\r
2  * \file\r
3  *\r
4  * \brief KSZ8051MNL (Ethernet PHY) driver for SAM.\r
5  *\r
6  * Copyright (c) 2013 Atmel Corporation. All rights reserved.\r
7  *\r
8  * \asf_license_start\r
9  *\r
10  * \page License\r
11  *\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
14  *\r
15  * 1. Redistributions of source code must retain the above copyright notice,\r
16  *    this list of conditions and the following disclaimer.\r
17  *\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
21  *\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
24  *\r
25  * 4. This software may only be redistributed and used in connection with an\r
26  *    Atmel microcontroller product.\r
27  *\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
39  *\r
40  * \asf_license_stop\r
41  *\r
42  */\r
43 \r
44 #ifndef ETHERNET_PHY_H_INCLUDED\r
45 #define ETHERNET_PHY_H_INCLUDED\r
46 \r
47 #include "compiler.h"\r
48 \r
49 #ifdef __cplusplus\r
50 extern "C" {\r
51 #endif\r
52 \r
53 // IEEE defined Registers\r
54 #define GMII_BMCR        0x00   // Basic Control\r
55 #define GMII_BMSR        0x01   // Basic Status\r
56 #define GMII_PHYID1      0x02   // PHY Idendifier 1\r
57 #define GMII_PHYID2      0x03   // PHY Idendifier 2\r
58 #define GMII_ANAR        0x04   // Auto_Negotiation Advertisement\r
59 #define GMII_ANLPAR      0x05   // Auto_negotiation Link Partner Ability\r
60 #define GMII_ANER        0x06   // Auto-negotiation Expansion\r
61 #define GMII_ANNPR       0x07   // Auto-negotiation Next Page\r
62 #define GMII_ANLPNPAR    0x08   // Link Partner Next Page Ability\r
63 //#define GMII_1000BTCR    9   // 1000Base-T Control  // Reserved\r
64 //#define GMII_1000BTSR   10   // 1000Base-T Status   // Reserved\r
65 #define GMII_AFECR1        0x11   // AFE Control 1\r
66 //#define GMII_ERDWR      12   // Extend Register - Data Write Register\r
67 //#define GMII_ERDRR      13   // Extend Register - Data Read Register\r
68 //14    reserved\r
69 #define GMII_RXERCR        0x15   // RXER Counter\r
70 \r
71         #define PHY_REG_01_BMSR            0x01 // Basic mode status register\r
72         #define PHY_REG_02_PHYSID1         0x02 // PHYS ID 1\r
73         #define PHY_REG_03_PHYSID2         0x03 // PHYS ID 2\r
74         #define PHY_REG_04_ADVERTISE       0x04 // Advertisement control reg\r
75         #define PHY_REG_05_LPA             0x05 // Link partner ability reg\r
76         #define PHY_REG_06_ANER            0x06 //      6       RW              Auto-Negotiation Expansion Register\r
77         #define PHY_REG_07_ANNPTR          0x07 //      7       RW              Auto-Negotiation Next Page TX\r
78         #define PHY_REG_08_RESERVED0       0x08 // 0x08..0x0Fh  8-15    RW              RESERVED\r
79 \r
80         #define PHY_REG_10_PHYSTS     0x10      // 16   RO              PHY Status Register\r
81         #define PHY_REG_11_MICR       0x11      // 17   RW              MII Interrupt Control Register\r
82         #define PHY_REG_12_MISR       0x12      // 18   RO              MII Interrupt Status Register\r
83         #define PHY_REG_13_RESERVED1  0x13      // 19   RW              RESERVED\r
84         #define PHY_REG_14_FCSCR      0x14      // 20   RO              False Carrier Sense Counter Register\r
85         #define PHY_REG_15_RECR       0x15      // 21   RO              Receive Error Counter Register\r
86         #define PHY_REG_16_PCSR       0x16      // 22   RW              PCS Sub-Layer Configuration and Status Register\r
87         #define PHY_REG_17_RBR        0x17      // 23   RW              RMII and Bypass Register\r
88         #define PHY_REG_18_LEDCR      0x18      // 24   RW              LED Direct Control Register\r
89         #define PHY_REG_19_PHYCR      0x19      // 25   RW              PHY Control Register\r
90         #define PHY_REG_1A_10BTSCR    0x1A      // 26   RW              10Base-T Status/Control Register\r
91         #define PHY_REG_1B_CDCTRL1    0x1B      // 27   RW              CD Test Control Register and BIST Extensions Register\r
92         #define PHY_REG_1B_INT_CTRL   0x1B      // 27   RW              KSZ8041NL interrupt control\r
93         #define PHY_REG_1C_RESERVED2  0x1C      // 28   RW              RESERVED\r
94         #define PHY_REG_1D_EDCR       0x1D      // 29   RW              Energy Detect Control Register\r
95         #define PHY_REG_1E_RESERVED3  0x1E      //\r
96         #define PHY_REG_1F_RESERVED4  0x1F      // 30-31        RW              RESERVED\r
97 \r
98         #define PHY_REG_1E_PHYCR_1    0x1E      //\r
99         #define PHY_REG_1F_PHYCR_2    0x1F      //\r
100 \r
101         #define PHY_SPEED_10       1\r
102         #define PHY_SPEED_100      2\r
103         #define PHY_SPEED_AUTO     (PHY_SPEED_10|PHY_SPEED_100)\r
104 \r
105         #define PHY_MDIX_DIRECT    1\r
106         #define PHY_MDIX_CROSSED   2\r
107         #define PHY_MDIX_AUTO      (PHY_MDIX_CROSSED|PHY_MDIX_DIRECT)\r
108 \r
109         #define PHY_DUPLEX_HALF    1\r
110         #define PHY_DUPLEX_FULL    2\r
111         #define PHY_DUPLEX_AUTO    (PHY_DUPLEX_FULL|PHY_DUPLEX_HALF)\r
112 \r
113         typedef struct _SPhyProps {\r
114                 unsigned char speed;\r
115                 unsigned char mdix;\r
116                 unsigned char duplex;\r
117                 unsigned char spare;\r
118         } SPhyProps;\r
119 \r
120         const char *phyPrintable (const SPhyProps *apProps);\r
121 \r
122         extern SPhyProps phyProps;\r
123 \r
124 #define GMII_OMSOR        0x16   // Operation Mode Strap Override\r
125 #define GMII_OMSSR       0x17   // Operation Mode Strap Status\r
126 #define GMII_ECR      0x18   // Expanded Control\r
127 //#define GMII_DPPSR      19   // Digital PMA/PCS Status\r
128 //20    reserved\r
129 //#define GMII_RXERCR     21   // RXER Counter Register\r
130 //22-26 reserved\r
131 #define GMII_ICSR        0x1B   // Interrupt Control/Status\r
132 //#define GMII_DDC1R       28   // Digital Debug Control 1 Register\r
133 #define GMII_LCSR        0x1D   // LinkMD Control/Status\r
134 \r
135 //29-30 reserved\r
136 #define GMII_PCR1       0x1E   // PHY Control 1\r
137 #define GMII_PCR2       0x1F   // PHY Control 2\r
138 \r
139 /*\r
140 //Extend Registers\r
141 #define GMII_CCR        256  // Common Control Register\r
142 #define GMII_SSR        257  // Strap Status Register\r
143 #define GMII_OMSOR      258  // Operation Mode Strap Override Register\r
144 #define GMII_OMSSR      259  // Operation Mode Strap Status Register\r
145 #define GMII_RCCPSR     260  // RGMII Clock and Control Pad Skew Register\r
146 #define GMII_RRDPSR     261  // RGMII RX Data Pad Skew Register\r
147 #define GMII_ATR        263  // Analog Test Register\r
148 */\r
149 \r
150 \r
151 // Bit definitions: GMII_BMCR 0x00 Basic Control\r
152 #define GMII_RESET             (1 << 15) // 1= Software Reset; 0=Normal Operation\r
153 #define GMII_LOOPBACK          (1 << 14) // 1=loopback Enabled; 0=Normal Operation\r
154 #define GMII_SPEED_SELECT      (1 << 13) // 1=100Mbps; 0=10Mbps\r
155 #define GMII_AUTONEG           (1 << 12) // Auto-negotiation Enable\r
156 #define GMII_POWER_DOWN        (1 << 11) // 1=Power down 0=Normal operation\r
157 #define GMII_ISOLATE           (1 << 10) // 1 = Isolates 0 = Normal operation\r
158 #define GMII_RESTART_AUTONEG   (1 << 9)  // 1 = Restart auto-negotiation 0 = Normal operation\r
159 #define GMII_DUPLEX_MODE       (1 << 8)  // 1 = Full duplex operation 0 = Normal operation\r
160 #define GMII_COLLISION_TEST    (1 << 7)  // 1 = Enable COL test; 0 = Disable COL test\r
161 //#define GMII_SPEED_SELECT_MSB  (1 << 6)  // Reserved\r
162 //      Reserved                6 to 0   // Read as 0, ignore on write\r
163 \r
164 // Bit definitions: GMII_BMSR 0x01 Basic Status\r
165 #define GMII_100BASE_T4        (1 << 15) // 100BASE-T4 Capable\r
166 #define GMII_100BASE_TX_FD     (1 << 14) // 100BASE-TX Full Duplex Capable\r
167 #define GMII_100BASE_T4_HD     (1 << 13) // 100BASE-TX Half Duplex Capable\r
168 #define GMII_10BASE_T_FD       (1 << 12) // 10BASE-T Full Duplex Capable\r
169 #define GMII_10BASE_T_HD       (1 << 11) // 10BASE-T Half Duplex Capable\r
170 //      Reserved                10 to79  // Read as 0, ignore on write\r
171 //#define GMII_EXTEND_STATUS     (1 << 8)  // 1 = Extend Status Information In Reg 15\r
172 //      Reserved                7\r
173 #define GMII_MF_PREAMB_SUPPR   (1 << 6)  // MII Frame Preamble Suppression\r
174 #define GMII_AUTONEG_COMP      (1 << 5)  // Auto-negotiation Complete\r
175 #define GMII_REMOTE_FAULT      (1 << 4)  // Remote Fault\r
176 #define GMII_AUTONEG_ABILITY   (1 << 3)  // Auto Configuration Ability\r
177 #define GMII_LINK_STATUS       (1 << 2)  // Link Status\r
178 #define GMII_JABBER_DETECT     (1 << 1)  // Jabber Detect\r
179 #define GMII_EXTEND_CAPAB      (1 << 0)  // Extended Capability\r
180 \r
181 \r
182 // Bit definitions: GMII_PHYID1 0x02 PHY Idendifier 1\r
183 // Bit definitions: GMII_PHYID2 0x03 PHY Idendifier 2\r
184 #define GMII_LSB_MASK           0x3F\r
185 #define GMII_OUI_MSB            0x0022\r
186 #define GMII_OUI_LSB            0x05\r
187 \r
188 \r
189 // Bit definitions: GMII_ANAR   0x04 Auto_Negotiation Advertisement\r
190 // Bit definitions: GMII_ANLPAR 0x05 Auto_negotiation Link Partner Ability\r
191 #define GMII_NP               (1 << 15) // Next page Indication\r
192 //      Reserved               7\r
193 #define GMII_RF               (1 << 13) // Remote Fault\r
194 //      Reserved               12       // Write as 0, ignore on read\r
195 #define GMII_PAUSE_MASK       (3 << 11) // 0,0 = No Pause 1,0 = Asymmetric Pause(link partner)\r
196                                         // 0,1 = Symmetric Pause 1,1 = Symmetric&Asymmetric Pause(local device)\r
197 #define GMII_100T4               (1 << 9)  // 100BASE-T4 Support\r
198 #define GMII_100TX_FDX           (1 << 8)  // 100BASE-TX Full Duplex Support\r
199 #define GMII_100TX_HDX           (1 << 7)  // 100BASE-TX Support\r
200 #define GMII_10_FDX           (1 << 6)  // 10BASE-T Full Duplex Support\r
201 #define GMII_10_HDX           (1 << 5)  // 10BASE-T Support\r
202 //      Selector                 4 to 0   // Protocol Selection Bits\r
203 #define GMII_AN_IEEE_802_3      0x0001    // [00001] = IEEE 802.3\r
204 \r
205 \r
206 // Bit definitions: GMII_ANER 0x06 Auto-negotiation Expansion\r
207 //      Reserved                15 to 5  // Read as 0, ignore on write\r
208 #define GMII_PDF              (1 << 4) // Local Device Parallel Detection Fault\r
209 #define GMII_LP_NP_ABLE       (1 << 3) // Link Partner Next Page Able\r
210 #define GMII_NP_ABLE          (1 << 2) // Local Device Next Page Able\r
211 #define GMII_PAGE_RX          (1 << 1) // New Page Received\r
212 #define GMII_LP_AN_ABLE       (1 << 0) // Link Partner Auto-negotiation Able\r
213 \r
214 /**\r
215  * \brief Perform a HW initialization to the PHY and set up clocks.\r
216  *\r
217  * This should be called only once to initialize the PHY pre-settings.\r
218  * The PHY address is the reset status of CRS, RXD[3:0] (the GmacPins' pullups).\r
219  * The COL pin is used to select MII mode on reset (pulled up for Reduced MII).\r
220  * The RXDV pin is used to select test mode on reset (pulled up for test mode).\r
221  * The above pins should be predefined for corresponding settings in resetPins.\r
222  * The GMAC peripheral pins are configured after the reset is done.\r
223  *\r
224  * \param p_gmac   Pointer to the GMAC instance.\r
225  * \param uc_phy_addr PHY address.\r
226  * \param ul_mck GMAC MCK.\r
227  *\r
228  * Return GMAC_OK if successfully, GMAC_TIMEOUT if timeout.\r
229  */\r
230 uint8_t ethernet_phy_init(Gmac *p_gmac, uint8_t uc_phy_addr, uint32_t ul_mck);\r
231 \r
232 \r
233 /**\r
234  * \brief Get the Link & speed settings, and automatically set up the GMAC with the\r
235  * settings.\r
236  *\r
237  * \param p_gmac   Pointer to the GMAC instance.\r
238  * \param uc_phy_addr PHY address.\r
239  * \param uc_apply_setting_flag Set to 0 to not apply the PHY configurations, else to apply.\r
240  *\r
241  * Return GMAC_OK if successfully, GMAC_TIMEOUT if timeout.\r
242  */\r
243 uint8_t ethernet_phy_set_link(Gmac *p_gmac, uint8_t uc_phy_addr,\r
244                 uint8_t uc_apply_setting_flag);\r
245 \r
246 \r
247 /**\r
248  * \brief Issue an auto negotiation of the PHY.\r
249  *\r
250  * \param p_gmac   Pointer to the GMAC instance.\r
251  * \param uc_phy_addr PHY address.\r
252  *\r
253  * Return GMAC_OK if successfully, GMAC_TIMEOUT if timeout.\r
254  */\r
255 uint8_t ethernet_phy_auto_negotiate(Gmac *p_gmac, uint8_t uc_phy_addr);\r
256 \r
257 /**\r
258  * \brief Issue a SW reset to reset all registers of the PHY.\r
259  *\r
260  * \param p_gmac   Pointer to the GMAC instance.\r
261  * \param uc_phy_addr PHY address.\r
262  *\r
263  * \Return GMAC_OK if successfully, GMAC_TIMEOUT if timeout.\r
264  */\r
265 uint8_t ethernet_phy_reset(Gmac *p_gmac, uint8_t uc_phy_addr);\r
266 \r
267 typedef struct xPHY_PROPS {\r
268         signed char phy_result;\r
269         uint32_t phy_params;\r
270         uint32_t phy_stat1;\r
271         uint32_t phy_stat2;\r
272         unsigned char phy_chn;\r
273 } PhyProps_t;\r
274 extern PhyProps_t phy_props;\r
275 \r
276 #ifdef __cplusplus\r
277 } /* extern "C" */\r
278 #endif\r
279 \r
280 #endif /* #ifndef ETHERNET_PHY_H_INCLUDED */\r
281 \r