lan8740_driver.h
Go to the documentation of this file.
1 /**
2  * @file lan8740_driver.h
3  * @brief LAN8740 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 _LAN8740_DRIVER_H
32 #define _LAN8740_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //PHY address
38 #ifndef LAN8740_PHY_ADDR
39  #define LAN8740_PHY_ADDR 0
40 #elif (LAN8740_PHY_ADDR < 0 || LAN8740_PHY_ADDR > 31)
41  #error LAN8740_PHY_ADDR parameter is not valid
42 #endif
43 
44 //LAN8740 PHY registers
45 #define LAN8740_BMCR 0x00
46 #define LAN8740_BMSR 0x01
47 #define LAN8740_PHYID1 0x02
48 #define LAN8740_PHYID2 0x03
49 #define LAN8740_ANAR 0x04
50 #define LAN8740_ANLPAR 0x05
51 #define LAN8740_ANER 0x06
52 #define LAN8740_ANNPTR 0x07
53 #define LAN8740_ANNPRR 0x08
54 #define LAN8740_MMDACR 0x0D
55 #define LAN8740_MMDAADR 0x0E
56 #define LAN8740_ENCTECR 0x10
57 #define LAN8740_MCSR 0x11
58 #define LAN8740_SMR 0x12
59 #define LAN8740_TDRPDCR 0x18
60 #define LAN8740_TDRCSR 0x19
61 #define LAN8740_SECR 0x1A
62 #define LAN8740_SCSIR 0x1B
63 #define LAN8740_CLR 0x1C
64 #define LAN8740_ISR 0x1D
65 #define LAN8740_IMR 0x1E
66 #define LAN8740_PSCSR 0x1F
67 
68 //LAN8740 MMD registers
69 #define LAN8740_PCS_CTRL1 0x03, 0x0000
70 #define LAN8740_PCS_STAT1 0x03, 0x0001
71 #define LAN8740_PCS_MMD_DEV_PRES1 0x03, 0x0005
72 #define LAN8740_PCS_MMD_DEV_PRES2 0x03, 0x0006
73 #define LAN8740_EEE_CAPABILITY 0x03, 0x0014
74 #define LAN8740_EEE_WAKE_ERROR 0x03, 0x0016
75 #define LAN8740_WUCSR 0x03, 0x8010
76 #define LAN8740_WUF_CFGA 0x03, 0x8011
77 #define LAN8740_WUF_CFGB 0x03, 0x8012
78 #define LAN8740_WUF_MASK 0x03, 0x8021
79 #define LAN8740_RX_ADDRA 0x03, 0x8061
80 #define LAN8740_RX_ADDRB 0x03, 0x8062
81 #define LAN8740_RX_ADDRC 0x03, 0x8063
82 #define LAN8740_MCFGR 0x03, 0x8064
83 #define LAN8740_AN_MMD_DEV_PRES1 0x07, 0x0005
84 #define LAN8740_AN_MMD_DEV_PRES2 0x07, 0x0006
85 #define LAN8740_EEE_ADV 0x07, 0x003C
86 #define LAN8740_EEE_LP_ADV 0x07, 0x003D
87 #define LAN8740_VENDOR_SPECIFIC_MMD1_DEV_ID1 0x1E, 0x0002
88 #define LAN8740_VENDOR_SPECIFIC_MMD1_DEV_ID2 0x1E, 0x0003
89 #define LAN8740_VENDOR_SPECIFIC_MMD1_DEV_PRES1 0x1E, 0x0005
90 #define LAN8740_VENDOR_SPECIFIC_MMD1_DEV_PRES2 0x1E, 0x0006
91 #define LAN8740_VENDOR_SPECIFIC_MMD1_STAT 0x1E, 0x0008
92 #define LAN8740_TDR_MATCH_THRESHOLD 0x1E, 0x000B
93 #define LAN8740_TDR_SHORT_OPEN_THRESHOLD 0x1E, 0x000C
94 #define LAN8740_VENDOR_SPECIFIC_MMD1_PKG_ID1 0x1E, 0x000E
95 #define LAN8740_VENDOR_SPECIFIC_MMD1_PKG_ID2 0x1E, 0x000F
96 
97 //Basic Control register
98 #define LAN8740_BMCR_RESET 0x8000
99 #define LAN8740_BMCR_LOOPBACK 0x4000
100 #define LAN8740_BMCR_SPEED_SEL 0x2000
101 #define LAN8740_BMCR_AN_EN 0x1000
102 #define LAN8740_BMCR_POWER_DOWN 0x0800
103 #define LAN8740_BMCR_ISOLATE 0x0400
104 #define LAN8740_BMCR_RESTART_AN 0x0200
105 #define LAN8740_BMCR_DUPLEX_MODE 0x0100
106 #define LAN8740_BMCR_COL_TEST 0x0080
107 
108 //Basic Status register
109 #define LAN8740_BMSR_100BT4 0x8000
110 #define LAN8740_BMSR_100BTX_FD 0x4000
111 #define LAN8740_BMSR_100BTX_HD 0x2000
112 #define LAN8740_BMSR_10BT_FD 0x1000
113 #define LAN8740_BMSR_10BT_HD 0x0800
114 #define LAN8740_BMSR_100BT2_FD 0x0400
115 #define LAN8740_BMSR_100BT2_HD 0x0200
116 #define LAN8740_BMSR_EXTENDED_STATUS 0x0100
117 #define LAN8740_BMSR_AN_COMPLETE 0x0020
118 #define LAN8740_BMSR_REMOTE_FAULT 0x0010
119 #define LAN8740_BMSR_AN_CAPABLE 0x0008
120 #define LAN8740_BMSR_LINK_STATUS 0x0004
121 #define LAN8740_BMSR_JABBER_DETECT 0x0002
122 #define LAN8740_BMSR_EXTENDED_CAPABLE 0x0001
123 
124 //PHY Identifier 1 register
125 #define LAN8740_PHYID1_PHY_ID_MSB 0xFFFF
126 #define LAN8740_PHYID1_PHY_ID_MSB_DEFAULT 0x0007
127 
128 //PHY Identifier 2 register
129 #define LAN8740_PHYID2_PHY_ID_LSB 0xFC00
130 #define LAN8740_PHYID2_PHY_ID_LSB_DEFAULT 0xC000
131 #define LAN8740_PHYID2_MODEL_NUM 0x03F0
132 #define LAN8740_PHYID2_MODEL_NUM_DEFAULT 0x0110
133 #define LAN8740_PHYID2_REVISION_NUM 0x000F
134 
135 //Auto-Negotiation Advertisement register
136 #define LAN8740_ANAR_NEXT_PAGE 0x8000
137 #define LAN8740_ANAR_REMOTE_FAULT 0x2000
138 #define LAN8740_ANAR_PAUSE 0x0C00
139 #define LAN8740_ANAR_100BTX_FD 0x0100
140 #define LAN8740_ANAR_100BTX_HD 0x0080
141 #define LAN8740_ANAR_10BT_FD 0x0040
142 #define LAN8740_ANAR_10BT_HD 0x0020
143 #define LAN8740_ANAR_SELECTOR 0x001F
144 #define LAN8740_ANAR_SELECTOR_DEFAULT 0x0001
145 
146 //Auto-Negotiation Link Partner Ability register
147 #define LAN8740_ANLPAR_NEXT_PAGE 0x8000
148 #define LAN8740_ANLPAR_ACK 0x4000
149 #define LAN8740_ANLPAR_REMOTE_FAULT 0x2000
150 #define LAN8740_ANLPAR_PAUSE 0x0400
151 #define LAN8740_ANLPAR_100BT4 0x0200
152 #define LAN8740_ANLPAR_100BTX_FD 0x0100
153 #define LAN8740_ANLPAR_100BTX_HD 0x0080
154 #define LAN8740_ANLPAR_10BT_FD 0x0040
155 #define LAN8740_ANLPAR_10BT_HD 0x0020
156 #define LAN8740_ANLPAR_SELECTOR 0x001F
157 #define LAN8740_ANLPAR_SELECTOR_DEFAULT 0x0001
158 
159 //Auto-Negotiation Expansion register
160 #define LAN8740_ANER_RECEIVE_NP_LOC_ABLE 0x0040
161 #define LAN8740_ANER_RECEIVE_NP_STOR_LOC 0x0020
162 #define LAN8740_ANER_PAR_DETECT_FAULT 0x0010
163 #define LAN8740_ANER_LP_NEXT_PAGE_ABLE 0x0008
164 #define LAN8740_ANER_NEXT_PAGE_ABLE 0x0004
165 #define LAN8740_ANER_PAGE_RECEIVED 0x0002
166 #define LAN8740_ANER_LP_AN_ABLE 0x0001
167 
168 //Auto Negotiation Next Page TX register
169 #define LAN8740_ANNPTR_NEXT_PAGE 0x8000
170 #define LAN8740_ANNPTR_MSG_PAGE 0x2000
171 #define LAN8740_ANNPTR_ACK2 0x1000
172 #define LAN8740_ANNPTR_TOGGLE 0x0800
173 #define LAN8740_ANNPTR_MESSAGE 0x07FF
174 
175 //Auto Negotiation Next Page RX register
176 #define LAN8740_ANNPRR_NEXT_PAGE 0x8000
177 #define LAN8740_ANNPRR_ACK 0x4000
178 #define LAN8740_ANNPRR_MSG_PAGE 0x2000
179 #define LAN8740_ANNPRR_ACK2 0x1000
180 #define LAN8740_ANNPRR_TOGGLE 0x0800
181 #define LAN8740_ANNPRR_MESSAGE 0x07FF
182 
183 //MMD Access Control register
184 #define LAN8740_MMDACR_FUNC 0xC000
185 #define LAN8740_MMDACR_FUNC_ADDR 0x0000
186 #define LAN8740_MMDACR_FUNC_DATA_NO_POST_INC 0x4000
187 #define LAN8740_MMDACR_DEVAD 0x001F
188 
189 //EDPD NLP/Crossover Time/EEE Configuration register
190 #define LAN8740_ENCTECR_EDPD_TX_NLP_EN 0x8000
191 #define LAN8740_ENCTECR_EDPD_TX_NLP_ITS 0x6000
192 #define LAN8740_ENCTECR_RX_NLP_WAKE_EN 0x1000
193 #define LAN8740_ENCTECR_RX_NLP_MIDS 0x0C00
194 #define LAN8740_ENCTECR_PHY_EEE_EN 0x0004
195 #define LAN8740_ENCTECR_EDPD_EXT_CROSSOVER 0x0002
196 #define LAN8740_ENCTECR_EXT_CROSSOVER_TIME 0x0001
197 
198 //Mode Control/Status register
199 #define LAN8740_MCSR_EDPWRDOWN 0x2000
200 #define LAN8740_MCSR_FARLOOPBACK 0x0200
201 #define LAN8740_MCSR_ALTINT 0x0040
202 #define LAN8740_MCSR_ENERGYON 0x0002
203 
204 //Special Modes register
205 #define LAN8740_SMR_MIIMODE 0x4000
206 #define LAN8740_SMR_MODE 0x00E0
207 #define LAN8740_SMR_PHYAD 0x001F
208 
209 //TDR Patterns/Delay Control register
210 #define LAN8740_TDRPDCR_DELAY_IN 0x8000
211 #define LAN8740_TDRPDCR_LINE_BREAK_COUNT 0x7000
212 #define LAN8740_TDRPDCR_PATTERN_HIGH 0x0FC0
213 #define LAN8740_TDRPDCR_PATTERN_LOW 0x003F
214 
215 //TDR Control/Status register
216 #define LAN8740_TDRCSR_TDR_EN 0x8000
217 #define LAN8740_TDRCSR_AD_FILTER_EN 0x4000
218 #define LAN8740_TDRCSR_CH_CABLE_TYPE 0x0600
219 #define LAN8740_TDRCSR_CH_STATUS 0x0100
220 #define LAN8740_TDRCSR_CH_LENGTH 0x00FF
221 
222 //Symbol Error Counter register
223 #define LAN8740_SECR_SYM_ERR_CNT 0xFFFF
224 
225 //Special Control/Status Indication register
226 #define LAN8740_SCSIR_AMDIXCTRL 0x8000
227 #define LAN8740_SCSIR_CH_SELECT 0x2000
228 #define LAN8740_SCSIR_SQEOFF 0x0800
229 #define LAN8740_SCSIR_XPOL 0x0010
230 
231 //Cable Length register
232 #define LAN8740_CLR_CBLN 0xF000
233 
234 //Interrupt Source Flag register
235 #define LAN8740_ISR_WOL 0x0100
236 #define LAN8740_ISR_ENERGYON 0x0080
237 #define LAN8740_ISR_AN_COMPLETE 0x0040
238 #define LAN8740_ISR_REMOTE_FAULT 0x0020
239 #define LAN8740_ISR_LINK_DOWN 0x0010
240 #define LAN8740_ISR_AN_LP_ACK 0x0008
241 #define LAN8740_ISR_PAR_DETECT_FAULT 0x0004
242 #define LAN8740_ISR_AN_PAGE_RECEIVED 0x0002
243 
244 //Interrupt Mask register
245 #define LAN8740_IMR_WOL 0x0100
246 #define LAN8740_IMR_ENERGYON 0x0080
247 #define LAN8740_IMR_AN_COMPLETE 0x0040
248 #define LAN8740_IMR_REMOTE_FAULT 0x0020
249 #define LAN8740_IMR_LINK_DOWN 0x0010
250 #define LAN8740_IMR_AN_LP_ACK 0x0008
251 #define LAN8740_IMR_PAR_DETECT_FAULT 0x0004
252 #define LAN8740_IMR_AN_PAGE_RECEIVED 0x0002
253 
254 //PHY Special Control/Status register
255 #define LAN8740_PSCSR_AUTODONE 0x1000
256 #define LAN8740_PSCSR_4B5B_EN 0x0040
257 #define LAN8740_PSCSR_HCDSPEED 0x001C
258 #define LAN8740_PSCSR_HCDSPEED_10BT_HD 0x0004
259 #define LAN8740_PSCSR_HCDSPEED_100BTX_HD 0x0008
260 #define LAN8740_PSCSR_HCDSPEED_10BT_FD 0x0014
261 #define LAN8740_PSCSR_HCDSPEED_100BTX_FD 0x0018
262 
263 //C++ guard
264 #ifdef __cplusplus
265 extern "C" {
266 #endif
267 
268 //LAN8740 Ethernet PHY driver
269 extern const PhyDriver lan8740PhyDriver;
270 
271 //LAN8740 related functions
272 error_t lan8740Init(NetInterface *interface);
273 void lan8740InitHook(NetInterface *interface);
274 
275 void lan8740Tick(NetInterface *interface);
276 
277 void lan8740EnableIrq(NetInterface *interface);
278 void lan8740DisableIrq(NetInterface *interface);
279 
280 void lan8740EventHandler(NetInterface *interface);
281 
282 void lan8740WritePhyReg(NetInterface *interface, uint8_t address,
283  uint16_t data);
284 
285 uint16_t lan8740ReadPhyReg(NetInterface *interface, uint8_t address);
286 
287 void lan8740DumpPhyReg(NetInterface *interface);
288 
289 void lan8740WriteMmdReg(NetInterface *interface, uint8_t devAddr,
290  uint16_t regAddr, uint16_t data);
291 
292 uint16_t lan8740ReadMmdReg(NetInterface *interface, uint8_t devAddr,
293  uint16_t regAddr);
294 
295 //C++ guard
296 #ifdef __cplusplus
297 }
298 #endif
299 
300 #endif
error_t
Error codes.
Definition: error.h:43
uint8_t data[]
Definition: ethernet.h:222
Ipv6Addr address[]
Definition: ipv6.h:316
void lan8740DisableIrq(NetInterface *interface)
Disable interrupts.
void lan8740WritePhyReg(NetInterface *interface, uint8_t address, uint16_t data)
Write PHY register.
error_t lan8740Init(NetInterface *interface)
LAN8740 PHY transceiver initialization.
void lan8740WriteMmdReg(NetInterface *interface, uint8_t devAddr, uint16_t regAddr, uint16_t data)
Write MMD register.
void lan8740EnableIrq(NetInterface *interface)
Enable interrupts.
void lan8740InitHook(NetInterface *interface)
LAN8740 custom configuration.
uint16_t lan8740ReadMmdReg(NetInterface *interface, uint8_t devAddr, uint16_t regAddr)
Read MMD register.
uint16_t lan8740ReadPhyReg(NetInterface *interface, uint8_t address)
Read PHY register.
void lan8740Tick(NetInterface *interface)
LAN8740 timer handler.
const PhyDriver lan8740PhyDriver
LAN8740 Ethernet PHY driver.
void lan8740DumpPhyReg(NetInterface *interface)
Dump PHY registers for debugging purpose.
void lan8740EventHandler(NetInterface *interface)
LAN8740 event handler.
uint16_t regAddr
#define NetInterface
Definition: net.h:36
Network interface controller abstraction layer.
Ethernet PHY driver.
Definition: nic.h:308