lan8742_driver.h
Go to the documentation of this file.
1 /**
2  * @file lan8742_driver.h
3  * @brief LAN8742 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.4
29  **/
30 
31 #ifndef _LAN8742_DRIVER_H
32 #define _LAN8742_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //PHY address
38 #ifndef LAN8742_PHY_ADDR
39  #define LAN8742_PHY_ADDR 0
40 #elif (LAN8742_PHY_ADDR < 0 || LAN8742_PHY_ADDR > 31)
41  #error LAN8742_PHY_ADDR parameter is not valid
42 #endif
43 
44 //LAN8742 PHY registers
45 #define LAN8742_BMCR 0x00
46 #define LAN8742_BMSR 0x01
47 #define LAN8742_PHYID1 0x02
48 #define LAN8742_PHYID2 0x03
49 #define LAN8742_ANAR 0x04
50 #define LAN8742_ANLPAR 0x05
51 #define LAN8742_ANER 0x06
52 #define LAN8742_ANNPTR 0x07
53 #define LAN8742_ANNPRR 0x08
54 #define LAN8742_MMDACR 0x0D
55 #define LAN8742_MMDAADR 0x0E
56 #define LAN8742_ENCTR 0x10
57 #define LAN8742_MCSR 0x11
58 #define LAN8742_SMR 0x12
59 #define LAN8742_TDRPDCR 0x18
60 #define LAN8742_TDRCSR 0x19
61 #define LAN8742_SECR 0x1A
62 #define LAN8742_SCSIR 0x1B
63 #define LAN8742_CLR 0x1C
64 #define LAN8742_ISR 0x1D
65 #define LAN8742_IMR 0x1E
66 #define LAN8742_PSCSR 0x1F
67 
68 //LAN8742 MMD registers
69 #define LAN8742_PCS_MMD_DEV_PRES1 0x03, 0x0005
70 #define LAN8742_PCS_MMD_DEV_PRES2 0x03, 0x0006
71 #define LAN8742_WUCSR 0x03, 0x8010
72 #define LAN8742_WUF_CFGA 0x03, 0x8011
73 #define LAN8742_WUF_CFGB 0x03, 0x8012
74 #define LAN8742_WUF_MASK 0x03, 0x8021
75 #define LAN8742_RX_ADDRA 0x03, 0x8061
76 #define LAN8742_RX_ADDRB 0x03, 0x8062
77 #define LAN8742_RX_ADDRC 0x03, 0x8063
78 #define LAN8742_MCFGR 0x03, 0x8064
79 #define LAN8742_VENDOR_SPECIFIC_MMD1_DEV_ID1 0x1E, 0x0002
80 #define LAN8742_VENDOR_SPECIFIC_MMD1_DEV_ID2 0x1E, 0x0003
81 #define LAN8742_VENDOR_SPECIFIC_MMD1_DEV_PRES1 0x1E, 0x0005
82 #define LAN8742_VENDOR_SPECIFIC_MMD1_DEV_PRES2 0x1E, 0x0006
83 #define LAN8742_VENDOR_SPECIFIC_MMD1_STAT 0x1E, 0x0008
84 #define LAN8742_TDR_MATCH_THRESHOLD 0x1E, 0x000B
85 #define LAN8742_TDR_SHORT_OPEN_THRESHOLD 0x1E, 0x000C
86 #define LAN8742_VENDOR_SPECIFIC_MMD1_PKG_ID1 0x1E, 0x000E
87 #define LAN8742_VENDOR_SPECIFIC_MMD1_PKG_ID2 0x1E, 0x000F
88 
89 //Basic Control register
90 #define LAN8742_BMCR_RESET 0x8000
91 #define LAN8742_BMCR_LOOPBACK 0x4000
92 #define LAN8742_BMCR_SPEED_SEL 0x2000
93 #define LAN8742_BMCR_AN_EN 0x1000
94 #define LAN8742_BMCR_POWER_DOWN 0x0800
95 #define LAN8742_BMCR_ISOLATE 0x0400
96 #define LAN8742_BMCR_RESTART_AN 0x0200
97 #define LAN8742_BMCR_DUPLEX_MODE 0x0100
98 
99 //Basic Status register
100 #define LAN8742_BMSR_100BT4 0x8000
101 #define LAN8742_BMSR_100BTX_FD 0x4000
102 #define LAN8742_BMSR_100BTX_HD 0x2000
103 #define LAN8742_BMSR_10BT_FD 0x1000
104 #define LAN8742_BMSR_10BT_HD 0x0800
105 #define LAN8742_BMSR_100BT2_FD 0x0400
106 #define LAN8742_BMSR_100BT2_HD 0x0200
107 #define LAN8742_BMSR_EXTENDED_STATUS 0x0100
108 #define LAN8742_BMSR_AN_COMPLETE 0x0020
109 #define LAN8742_BMSR_REMOTE_FAULT 0x0010
110 #define LAN8742_BMSR_AN_CAPABLE 0x0008
111 #define LAN8742_BMSR_LINK_STATUS 0x0004
112 #define LAN8742_BMSR_JABBER_DETECT 0x0002
113 #define LAN8742_BMSR_EXTENDED_CAPABLE 0x0001
114 
115 //PHY Identifier 1 register
116 #define LAN8742_PHYID1_PHY_ID_MSB 0xFFFF
117 #define LAN8742_PHYID1_PHY_ID_MSB_DEFAULT 0x0007
118 
119 //PHY Identifier 2 register
120 #define LAN8742_PHYID2_PHY_ID_LSB 0xFC00
121 #define LAN8742_PHYID2_PHY_ID_LSB_DEFAULT 0xC000
122 #define LAN8742_PHYID2_MODEL_NUM 0x03F0
123 #define LAN8742_PHYID2_MODEL_NUM_DEFAULT 0x0130
124 #define LAN8742_PHYID2_REVISION_NUM 0x000F
125 
126 //Auto-Negotiation Advertisement register
127 #define LAN8742_ANAR_NEXT_PAGE 0x8000
128 #define LAN8742_ANAR_REMOTE_FAULT 0x2000
129 #define LAN8742_ANAR_PAUSE 0x0C00
130 #define LAN8742_ANAR_100BTX_FD 0x0100
131 #define LAN8742_ANAR_100BTX_HD 0x0080
132 #define LAN8742_ANAR_10BT_FD 0x0040
133 #define LAN8742_ANAR_10BT_HD 0x0020
134 #define LAN8742_ANAR_SELECTOR 0x001F
135 #define LAN8742_ANAR_SELECTOR_DEFAULT 0x0001
136 
137 //Auto-Negotiation Link Partner Ability register
138 #define LAN8742_ANLPAR_NEXT_PAGE 0x8000
139 #define LAN8742_ANLPAR_ACK 0x4000
140 #define LAN8742_ANLPAR_REMOTE_FAULT 0x2000
141 #define LAN8742_ANLPAR_PAUSE 0x0400
142 #define LAN8742_ANLPAR_100BT4 0x0200
143 #define LAN8742_ANLPAR_100BTX_FD 0x0100
144 #define LAN8742_ANLPAR_100BTX_HD 0x0080
145 #define LAN8742_ANLPAR_10BT_FD 0x0040
146 #define LAN8742_ANLPAR_10BT_HD 0x0020
147 #define LAN8742_ANLPAR_SELECTOR 0x001F
148 #define LAN8742_ANLPAR_SELECTOR_DEFAULT 0x0001
149 
150 //Auto-Negotiation Expansion register
151 #define LAN8742_ANER_RECEIVE_NP_LOC_ABLE 0x0040
152 #define LAN8742_ANER_RECEIVE_NP_STOR_LOC 0x0020
153 #define LAN8742_ANER_PAR_DETECT_FAULT 0x0010
154 #define LAN8742_ANER_LP_NEXT_PAGE_ABLE 0x0008
155 #define LAN8742_ANER_NEXT_PAGE_ABLE 0x0004
156 #define LAN8742_ANER_PAGE_RECEIVED 0x0002
157 #define LAN8742_ANER_LP_AN_ABLE 0x0001
158 
159 //Auto Negotiation Next Page TX register
160 #define LAN8742_ANNPTR_NEXT_PAGE 0x8000
161 #define LAN8742_ANNPTR_MSG_PAGE 0x2000
162 #define LAN8742_ANNPTR_ACK2 0x1000
163 #define LAN8742_ANNPTR_TOGGLE 0x0800
164 #define LAN8742_ANNPTR_MESSAGE 0x07FF
165 
166 //Auto Negotiation Next Page RX register
167 #define LAN8742_ANNPRR_NEXT_PAGE 0x8000
168 #define LAN8742_ANNPRR_ACK 0x4000
169 #define LAN8742_ANNPRR_MSG_PAGE 0x2000
170 #define LAN8742_ANNPRR_ACK2 0x1000
171 #define LAN8742_ANNPRR_TOGGLE 0x0800
172 #define LAN8742_ANNPRR_MESSAGE 0x07FF
173 
174 //MMD Access Control register
175 #define LAN8742_MMDACR_FUNC 0xC000
176 #define LAN8742_MMDACR_FUNC_ADDR 0x0000
177 #define LAN8742_MMDACR_FUNC_DATA_NO_POST_INC 0x4000
178 #define LAN8742_MMDACR_DEVAD 0x001F
179 
180 //EDPD NLP/Crossover Time Configuration register
181 #define LAN8742_ENCTR_EDPD_TX_NLP_EN 0x8000
182 #define LAN8742_ENCTR_EDPD_TX_NLP_ITS 0x6000
183 #define LAN8742_ENCTR_EDPD_RX_NLP_WAKE_EN 0x1000
184 #define LAN8742_ENCTR_EDPD_RX_NLP_MIDS 0x0C00
185 #define LAN8742_ENCTR_EDPD_EXT_CROSSOVER 0x0002
186 #define LAN8742_ENCTR_EXT_CROSSOVER_TIME 0x0001
187 
188 //Mode Control/Status register
189 #define LAN8742_MCSR_EDPWRDOWN 0x2000
190 #define LAN8742_MCSR_FARLOOPBACK 0x0200
191 #define LAN8742_MCSR_ALTINT 0x0040
192 #define LAN8742_MCSR_ENERGYON 0x0002
193 
194 //Special Modes register
195 #define LAN8742_SMR_MODE 0x00E0
196 #define LAN8742_SMR_PHYAD 0x001F
197 
198 //TDR Patterns/Delay Control register
199 #define LAN8742_TDRPDCR_DELAY_IN 0x8000
200 #define LAN8742_TDRPDCR_LINE_BREAK_COUNT 0x7000
201 #define LAN8742_TDRPDCR_PATTERN_HIGH 0x0FC0
202 #define LAN8742_TDRPDCR_PATTERN_LOW 0x003F
203 
204 //TDR Control/Status register
205 #define LAN8742_TDRCSR_TDR_EN 0x8000
206 #define LAN8742_TDRCSR_AD_FILTER_EN 0x4000
207 #define LAN8742_TDRCSR_CH_CABLE_TYPE 0x0600
208 #define LAN8742_TDRCSR_CH_STATUS 0x0100
209 #define LAN8742_TDRCSR_CH_LENGTH 0x00FF
210 
211 //Symbol Error Counter register
212 #define LAN8742_SECR_SYM_ERR_CNT 0xFFFF
213 
214 //Special Control/Status Indication register
215 #define LAN8742_SCSIR_AMDIXCTRL 0x8000
216 #define LAN8742_SCSIR_CH_SELECT 0x2000
217 #define LAN8742_SCSIR_SQEOFF 0x0800
218 #define LAN8742_SCSIR_XPOL 0x0010
219 
220 //Cable Length register
221 #define LAN8742_CLR_CBLN 0xF000
222 
223 //Interrupt Source Flag register
224 #define LAN8742_ISR_WOL 0x0100
225 #define LAN8742_ISR_ENERGYON 0x0080
226 #define LAN8742_ISR_AN_COMPLETE 0x0040
227 #define LAN8742_ISR_REMOTE_FAULT 0x0020
228 #define LAN8742_ISR_LINK_DOWN 0x0010
229 #define LAN8742_ISR_AN_LP_ACK 0x0008
230 #define LAN8742_ISR_PAR_DETECT_FAULT 0x0004
231 #define LAN8742_ISR_AN_PAGE_RECEIVED 0x0002
232 
233 //Interrupt Mask register
234 #define LAN8742_IMR_WOL 0x0100
235 #define LAN8742_IMR_ENERGYON 0x0080
236 #define LAN8742_IMR_AN_COMPLETE 0x0040
237 #define LAN8742_IMR_REMOTE_FAULT 0x0020
238 #define LAN8742_IMR_LINK_DOWN 0x0010
239 #define LAN8742_IMR_AN_LP_ACK 0x0008
240 #define LAN8742_IMR_PAR_DETECT_FAULT 0x0004
241 #define LAN8742_IMR_AN_PAGE_RECEIVED 0x0002
242 
243 //PHY Special Control/Status register
244 #define LAN8742_PSCSR_AUTODONE 0x1000
245 #define LAN8742_PSCSR_HCDSPEED 0x001C
246 #define LAN8742_PSCSR_HCDSPEED_10BT_HD 0x0004
247 #define LAN8742_PSCSR_HCDSPEED_100BTX_HD 0x0008
248 #define LAN8742_PSCSR_HCDSPEED_10BT_FD 0x0014
249 #define LAN8742_PSCSR_HCDSPEED_100BTX_FD 0x0018
250 
251 //C++ guard
252 #ifdef __cplusplus
253 extern "C" {
254 #endif
255 
256 //LAN8742 Ethernet PHY driver
257 extern const PhyDriver lan8742PhyDriver;
258 
259 //LAN8742 related functions
260 error_t lan8742Init(NetInterface *interface);
261 void lan8742InitHook(NetInterface *interface);
262 
263 void lan8742Tick(NetInterface *interface);
264 
265 void lan8742EnableIrq(NetInterface *interface);
266 void lan8742DisableIrq(NetInterface *interface);
267 
268 void lan8742EventHandler(NetInterface *interface);
269 
270 void lan8742WritePhyReg(NetInterface *interface, uint8_t address,
271  uint16_t data);
272 
273 uint16_t lan8742ReadPhyReg(NetInterface *interface, uint8_t address);
274 
275 void lan8742DumpPhyReg(NetInterface *interface);
276 
277 void lan8742WriteMmdReg(NetInterface *interface, uint8_t devAddr,
278  uint16_t regAddr, uint16_t data);
279 
280 uint16_t lan8742ReadMmdReg(NetInterface *interface, uint8_t devAddr,
281  uint16_t regAddr);
282 
283 //C++ guard
284 #ifdef __cplusplus
285 }
286 #endif
287 
288 #endif
const PhyDriver lan8742PhyDriver
LAN8742 Ethernet PHY driver.
void lan8742DisableIrq(NetInterface *interface)
Disable interrupts.
Ethernet PHY driver.
Definition: nic.h:311
uint8_t data[]
Definition: ethernet.h:222
void lan8742WriteMmdReg(NetInterface *interface, uint8_t devAddr, uint16_t regAddr, uint16_t data)
Write MMD register.
void lan8742EnableIrq(NetInterface *interface)
Enable interrupts.
uint16_t lan8742ReadMmdReg(NetInterface *interface, uint8_t devAddr, uint16_t regAddr)
Read MMD register.
void lan8742DumpPhyReg(NetInterface *interface)
Dump PHY registers for debugging purpose.
error_t
Error codes.
Definition: error.h:43
uint16_t lan8742ReadPhyReg(NetInterface *interface, uint8_t address)
Read PHY register.
#define NetInterface
Definition: net.h:36
void lan8742WritePhyReg(NetInterface *interface, uint8_t address, uint16_t data)
Write PHY register.
error_t lan8742Init(NetInterface *interface)
LAN8742 PHY transceiver initialization.
uint16_t regAddr
Ipv6Addr address[]
Definition: ipv6.h:325
void lan8742EventHandler(NetInterface *interface)
LAN8742 event handler.
Network interface controller abstraction layer.
void lan8742Tick(NetInterface *interface)
LAN8742 timer handler.
void lan8742InitHook(NetInterface *interface)
LAN8742 custom configuration.