lan8741_driver.h
Go to the documentation of this file.
1 /**
2  * @file lan8741_driver.h
3  * @brief LAN8741 Ethernet PHY driver
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.0
29  **/
30 
31 #ifndef _LAN8741_DRIVER_H
32 #define _LAN8741_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //PHY address
38 #ifndef LAN8741_PHY_ADDR
39  #define LAN8741_PHY_ADDR 0
40 #elif (LAN8741_PHY_ADDR < 0 || LAN8741_PHY_ADDR > 31)
41  #error LAN8741_PHY_ADDR parameter is not valid
42 #endif
43 
44 //LAN8741 PHY registers
45 #define LAN8741_BMCR 0x00
46 #define LAN8741_BMSR 0x01
47 #define LAN8741_PHYID1 0x02
48 #define LAN8741_PHYID2 0x03
49 #define LAN8741_ANAR 0x04
50 #define LAN8741_ANLPAR 0x05
51 #define LAN8741_ANER 0x06
52 #define LAN8741_ANNPTR 0x07
53 #define LAN8741_ANNPRR 0x08
54 #define LAN8741_MMDACR 0x0D
55 #define LAN8741_MMDAADR 0x0E
56 #define LAN8741_ENCTECR 0x10
57 #define LAN8741_MCSR 0x11
58 #define LAN8741_SMR 0x12
59 #define LAN8741_SECR 0x1A
60 #define LAN8741_SCSIR 0x1B
61 #define LAN8741_ISR 0x1D
62 #define LAN8741_IMR 0x1E
63 #define LAN8741_PSCSR 0x1F
64 
65 //LAN8741 MMD registers
66 #define LAN8741_PCS_CTRL1 0x03, 0x00
67 #define LAN8741_PCS_STAT1 0x03, 0x01
68 #define LAN8741_PCS_MMD_DEV_PRES1 0x03, 0x05
69 #define LAN8741_PCS_MMD_DEV_PRES2 0x03, 0x06
70 #define LAN8741_EEE_CAPABILITY 0x03, 0x14
71 #define LAN8741_EEE_WAKE_ERROR 0x03, 0x16
72 #define LAN8741_AN_MMD_DEV_PRES1 0x07, 0x05
73 #define LAN8741_AN_MMD_DEV_PRES2 0x07, 0x06
74 #define LAN8741_EEE_ADV 0x07, 0x3C
75 #define LAN8741_EEE_LP_ADV 0x07, 0x3D
76 #define LAN8741_VENDOR_SPECIFIC_MMD1_DEV_ID1 0x1E, 0x02
77 #define LAN8741_VENDOR_SPECIFIC_MMD1_DEV_ID2 0x1E, 0x03
78 #define LAN8741_VENDOR_SPECIFIC_MMD1_DEV_PRES1 0x1E, 0x05
79 #define LAN8741_VENDOR_SPECIFIC_MMD1_DEV_PRES2 0x1E, 0x06
80 #define LAN8741_VENDOR_SPECIFIC_MMD1_STAT 0x1E, 0x08
81 #define LAN8741_TDR_MATCH_THRESHOLD 0x1E, 0x0B
82 #define LAN8741_TDR_SHORT_OPEN_THRESHOLD 0x1E, 0x0C
83 #define LAN8741_VENDOR_SPECIFIC_MMD1_PKG_ID1 0x1E, 0x0E
84 #define LAN8741_VENDOR_SPECIFIC_MMD1_PKG_ID2 0x1E, 0x0F
85 
86 //Basic Control register
87 #define LAN8741_BMCR_RESET 0x8000
88 #define LAN8741_BMCR_LOOPBACK 0x4000
89 #define LAN8741_BMCR_SPEED_SEL 0x2000
90 #define LAN8741_BMCR_AN_EN 0x1000
91 #define LAN8741_BMCR_POWER_DOWN 0x0800
92 #define LAN8741_BMCR_ISOLATE 0x0400
93 #define LAN8741_BMCR_RESTART_AN 0x0200
94 #define LAN8741_BMCR_DUPLEX_MODE 0x0100
95 #define LAN8741_BMCR_COL_TEST 0x0080
96 
97 //Basic Status register
98 #define LAN8741_BMSR_100BT4 0x8000
99 #define LAN8741_BMSR_100BTX_FD 0x4000
100 #define LAN8741_BMSR_100BTX_HD 0x2000
101 #define LAN8741_BMSR_10BT_FD 0x1000
102 #define LAN8741_BMSR_10BT_HD 0x0800
103 #define LAN8741_BMSR_100BT2_FD 0x0400
104 #define LAN8741_BMSR_100BT2_HD 0x0200
105 #define LAN8741_BMSR_EXTENDED_STATUS 0x0100
106 #define LAN8741_BMSR_AN_COMPLETE 0x0020
107 #define LAN8741_BMSR_REMOTE_FAULT 0x0010
108 #define LAN8741_BMSR_AN_CAPABLE 0x0008
109 #define LAN8741_BMSR_LINK_STATUS 0x0004
110 #define LAN8741_BMSR_JABBER_DETECT 0x0002
111 #define LAN8741_BMSR_EXTENDED_CAPABLE 0x0001
112 
113 //PHY Identifier 1 register
114 #define LAN8741_PHYID1_PHY_ID_MSB 0xFFFF
115 #define LAN8741_PHYID1_PHY_ID_MSB_DEFAULT 0x0007
116 
117 //PHY Identifier 2 register
118 #define LAN8741_PHYID2_PHY_ID_LSB 0xFC00
119 #define LAN8741_PHYID2_PHY_ID_LSB_DEFAULT 0xC000
120 #define LAN8741_PHYID2_MODEL_NUM 0x03F0
121 #define LAN8741_PHYID2_MODEL_NUM_DEFAULT 0x0120
122 #define LAN8741_PHYID2_REVISION_NUM 0x000F
123 
124 //Auto-Negotiation Advertisement register
125 #define LAN8741_ANAR_NEXT_PAGE 0x8000
126 #define LAN8741_ANAR_REMOTE_FAULT 0x2000
127 #define LAN8741_ANAR_PAUSE 0x0C00
128 #define LAN8741_ANAR_100BTX_FD 0x0100
129 #define LAN8741_ANAR_100BTX_HD 0x0080
130 #define LAN8741_ANAR_10BT_FD 0x0040
131 #define LAN8741_ANAR_10BT_HD 0x0020
132 #define LAN8741_ANAR_SELECTOR 0x001F
133 #define LAN8741_ANAR_SELECTOR_DEFAULT 0x0001
134 
135 //Auto-Negotiation Link Partner Ability register
136 #define LAN8741_ANLPAR_NEXT_PAGE 0x8000
137 #define LAN8741_ANLPAR_ACK 0x4000
138 #define LAN8741_ANLPAR_REMOTE_FAULT 0x2000
139 #define LAN8741_ANLPAR_PAUSE 0x0400
140 #define LAN8741_ANLPAR_100BT4 0x0200
141 #define LAN8741_ANLPAR_100BTX_FD 0x0100
142 #define LAN8741_ANLPAR_100BTX_HD 0x0080
143 #define LAN8741_ANLPAR_10BT_FD 0x0040
144 #define LAN8741_ANLPAR_10BT_HD 0x0020
145 #define LAN8741_ANLPAR_SELECTOR 0x001F
146 #define LAN8741_ANLPAR_SELECTOR_DEFAULT 0x0001
147 
148 //Auto-Negotiation Expansion register
149 #define LAN8741_ANER_RECEIVE_NP_LOC_ABLE 0x0040
150 #define LAN8741_ANER_RECEIVE_NP_STOR_LOC 0x0020
151 #define LAN8741_ANER_PAR_DETECT_FAULT 0x0010
152 #define LAN8741_ANER_LP_NEXT_PAGE_ABLE 0x0008
153 #define LAN8741_ANER_NEXT_PAGE_ABLE 0x0004
154 #define LAN8741_ANER_PAGE_RECEIVED 0x0002
155 #define LAN8741_ANER_LP_AN_ABLE 0x0001
156 
157 //Auto Negotiation Next Page TX register
158 #define LAN8741_ANNPTR_NEXT_PAGE 0x8000
159 #define LAN8741_ANNPTR_MSG_PAGE 0x2000
160 #define LAN8741_ANNPTR_ACK2 0x1000
161 #define LAN8741_ANNPTR_TOGGLE 0x0800
162 #define LAN8741_ANNPTR_MESSAGE 0x07FF
163 
164 //Auto Negotiation Next Page RX register
165 #define LAN8741_ANNPRR_NEXT_PAGE 0x8000
166 #define LAN8741_ANNPRR_ACK 0x4000
167 #define LAN8741_ANNPRR_MSG_PAGE 0x2000
168 #define LAN8741_ANNPRR_ACK2 0x1000
169 #define LAN8741_ANNPRR_TOGGLE 0x0800
170 #define LAN8741_ANNPRR_MESSAGE 0x07FF
171 
172 //MMD Access Control register
173 #define LAN8741_MMDACR_FUNC 0xC000
174 #define LAN8741_MMDACR_FUNC_ADDR 0x0000
175 #define LAN8741_MMDACR_FUNC_DATA_NO_POST_INC 0x4000
176 #define LAN8741_MMDACR_DEVAD 0x001F
177 
178 //EDPD NLP/Crossover Time/EEE Configuration register
179 #define LAN8741_ENCTECR_EDPD_TX_NLP_EN 0x8000
180 #define LAN8741_ENCTECR_EDPD_TX_NLP_ITS 0x6000
181 #define LAN8741_ENCTECR_EDPD_RX_NLP_WAKE_EN 0x1000
182 #define LAN8741_ENCTECR_EDPD_RX_NLP_MIDS 0x0C00
183 #define LAN8741_ENCTECR_PHY_EEE_EN 0x0004
184 #define LAN8741_ENCTECR_EDPD_EXT_CROSSOVER 0x0002
185 #define LAN8741_ENCTECR_EXT_CROSSOVER_TIME 0x0001
186 
187 //Mode Control/Status register
188 #define LAN8741_MCSR_EDPWRDOWN 0x2000
189 #define LAN8741_MCSR_FARLOOPBACK 0x0200
190 #define LAN8741_MCSR_ALTINT 0x0040
191 #define LAN8741_MCSR_ENERGYON 0x0002
192 
193 //Special Modes register
194 #define LAN8741_SMR_MIIMODE 0x4000
195 #define LAN8741_SMR_MODE 0x00E0
196 #define LAN8741_SMR_PHYAD 0x001F
197 
198 //Symbol Error Counter register
199 #define LAN8741_SECR_SYM_ERR_CNT 0xFFFF
200 
201 //Special Control/Status Indication register
202 #define LAN8741_SCSIR_AMDIXCTRL 0x8000
203 #define LAN8741_SCSIR_CH_SELECT 0x2000
204 #define LAN8741_SCSIR_SQEOFF 0x0800
205 #define LAN8741_SCSIR_XPOL 0x0010
206 
207 //Interrupt Source Flag register
208 #define LAN8741_ISR_ENERGYON 0x0080
209 #define LAN8741_ISR_AN_COMPLETE 0x0040
210 #define LAN8741_ISR_REMOTE_FAULT 0x0020
211 #define LAN8741_ISR_LINK_DOWN 0x0010
212 #define LAN8741_ISR_AN_LP_ACK 0x0008
213 #define LAN8741_ISR_PAR_DETECT_FAULT 0x0004
214 #define LAN8741_ISR_AN_PAGE_RECEIVED 0x0002
215 
216 //Interrupt Mask register
217 #define LAN8741_IMR_ENERGYON 0x0080
218 #define LAN8741_IMR_AN_COMPLETE 0x0040
219 #define LAN8741_IMR_REMOTE_FAULT 0x0020
220 #define LAN8741_IMR_LINK_DOWN 0x0010
221 #define LAN8741_IMR_AN_LP_ACK 0x0008
222 #define LAN8741_IMR_PAR_DETECT_FAULT 0x0004
223 #define LAN8741_IMR_AN_PAGE_RECEIVED 0x0002
224 
225 //PHY Special Control/Status register
226 #define LAN8741_PSCSR_AUTODONE 0x1000
227 #define LAN8741_PSCSR_4B5B_EN 0x0040
228 #define LAN8741_PSCSR_HCDSPEED 0x001C
229 #define LAN8741_PSCSR_HCDSPEED_10BT_HD 0x0004
230 #define LAN8741_PSCSR_HCDSPEED_100BTX_HD 0x0008
231 #define LAN8741_PSCSR_HCDSPEED_10BT_FD 0x0014
232 #define LAN8741_PSCSR_HCDSPEED_100BTX_FD 0x0018
233 
234 //C++ guard
235 #ifdef __cplusplus
236 extern "C" {
237 #endif
238 
239 //LAN8741 Ethernet PHY driver
240 extern const PhyDriver lan8741PhyDriver;
241 
242 //LAN8741 related functions
243 error_t lan8741Init(NetInterface *interface);
244 void lan8741InitHook(NetInterface *interface);
245 
246 void lan8741Tick(NetInterface *interface);
247 
248 void lan8741EnableIrq(NetInterface *interface);
249 void lan8741DisableIrq(NetInterface *interface);
250 
251 void lan8741EventHandler(NetInterface *interface);
252 
253 void lan8741WritePhyReg(NetInterface *interface, uint8_t address,
254  uint16_t data);
255 
256 uint16_t lan8741ReadPhyReg(NetInterface *interface, uint8_t address);
257 
258 void lan8741DumpPhyReg(NetInterface *interface);
259 
260 void lan8741WriteMmdReg(NetInterface *interface, uint8_t devAddr,
261  uint16_t regAddr, uint16_t data);
262 
263 uint16_t lan8741ReadMmdReg(NetInterface *interface, uint8_t devAddr,
264  uint16_t regAddr);
265 
266 //C++ guard
267 #ifdef __cplusplus
268 }
269 #endif
270 
271 #endif
error_t
Error codes.
Definition: error.h:43
uint8_t data[]
Definition: ethernet.h:222
Ipv6Addr address[]
Definition: ipv6.h:316
error_t lan8741Init(NetInterface *interface)
LAN8741 PHY transceiver initialization.
void lan8741EventHandler(NetInterface *interface)
LAN8741 event handler.
void lan8741WriteMmdReg(NetInterface *interface, uint8_t devAddr, uint16_t regAddr, uint16_t data)
Write MMD register.
const PhyDriver lan8741PhyDriver
LAN8741 Ethernet PHY driver.
uint16_t lan8741ReadMmdReg(NetInterface *interface, uint8_t devAddr, uint16_t regAddr)
Read MMD register.
void lan8741DisableIrq(NetInterface *interface)
Disable interrupts.
void lan8741Tick(NetInterface *interface)
LAN8741 timer handler.
void lan8741WritePhyReg(NetInterface *interface, uint8_t address, uint16_t data)
Write PHY register.
void lan8741DumpPhyReg(NetInterface *interface)
Dump PHY registers for debugging purpose.
uint16_t lan8741ReadPhyReg(NetInterface *interface, uint8_t address)
Read PHY register.
void lan8741EnableIrq(NetInterface *interface)
Enable interrupts.
void lan8741InitHook(NetInterface *interface)
LAN8741 custom configuration.
uint16_t regAddr
#define NetInterface
Definition: net.h:36
Network interface controller abstraction layer.
Ethernet PHY driver.
Definition: nic.h:308