lan8740_driver.h
Go to the documentation of this file.
1 /**
2  * @file lan8740_driver.h
3  * @brief LAN8740 Ethernet PHY transceiver
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2019 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 1.9.6
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_ANNPR 0x07
53 #define LAN8740_ANLPNPR 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 //Basic Control register
69 #define LAN8740_BMCR_RESET 0x8000
70 #define LAN8740_BMCR_LOOPBACK 0x4000
71 #define LAN8740_BMCR_SPEED_SEL 0x2000
72 #define LAN8740_BMCR_AN_EN 0x1000
73 #define LAN8740_BMCR_POWER_DOWN 0x0800
74 #define LAN8740_BMCR_ISOLATE 0x0400
75 #define LAN8740_BMCR_RESTART_AN 0x0200
76 #define LAN8740_BMCR_DUPLEX_MODE 0x0100
77 #define LAN8740_BMCR_COL_TEST 0x0080
78 
79 //Basic Status register
80 #define LAN8740_BMSR_100BT4 0x8000
81 #define LAN8740_BMSR_100BTX_FD 0x4000
82 #define LAN8740_BMSR_100BTX_HD 0x2000
83 #define LAN8740_BMSR_10BT_FD 0x1000
84 #define LAN8740_BMSR_10BT_HD 0x0800
85 #define LAN8740_BMSR_100BT2_FD 0x0400
86 #define LAN8740_BMSR_100BT2_HD 0x0200
87 #define LAN8740_BMSR_EXTENDED_STATUS 0x0100
88 #define LAN8740_BMSR_AN_COMPLETE 0x0020
89 #define LAN8740_BMSR_REMOTE_FAULT 0x0010
90 #define LAN8740_BMSR_AN_CAPABLE 0x0008
91 #define LAN8740_BMSR_LINK_STATUS 0x0004
92 #define LAN8740_BMSR_JABBER_DETECT 0x0002
93 #define LAN8740_BMSR_EXTENDED_CAPABLE 0x0001
94 
95 //PHY Identifier 1 register
96 #define LAN8740_PHYID1_PHY_ID_MSB 0xFFFF
97 #define LAN8740_PHYID1_PHY_ID_MSB_DEFAULT 0x0007
98 
99 //PHY Identifier 2 register
100 #define LAN8740_PHYID2_PHY_ID_LSB 0xFC00
101 #define LAN8740_PHYID2_PHY_ID_LSB_DEFAULT 0xC000
102 #define LAN8740_PHYID2_MODEL_NUM 0x03F0
103 #define LAN8740_PHYID2_MODEL_NUM_DEFAULT 0x0110
104 #define LAN8740_PHYID2_REVISION_NUM 0x000F
105 
106 //Auto-Negotiation Advertisement register
107 #define LAN8740_ANAR_NEXT_PAGE 0x8000
108 #define LAN8740_ANAR_REMOTE_FAULT 0x2000
109 #define LAN8740_ANAR_PAUSE 0x0C00
110 #define LAN8740_ANAR_100BTX_FD 0x0100
111 #define LAN8740_ANAR_100BTX_HD 0x0080
112 #define LAN8740_ANAR_10BT_FD 0x0040
113 #define LAN8740_ANAR_10BT_HD 0x0020
114 #define LAN8740_ANAR_SELECTOR 0x001F
115 #define LAN8740_ANAR_SELECTOR_DEFAULT 0x0001
116 
117 //Auto-Negotiation Link Partner Ability register
118 #define LAN8740_ANLPAR_NEXT_PAGE 0x8000
119 #define LAN8740_ANLPAR_ACK 0x4000
120 #define LAN8740_ANLPAR_REMOTE_FAULT 0x2000
121 #define LAN8740_ANLPAR_PAUSE 0x0400
122 #define LAN8740_ANLPAR_100BT4 0x0200
123 #define LAN8740_ANLPAR_100BTX_FD 0x0100
124 #define LAN8740_ANLPAR_100BTX_HD 0x0080
125 #define LAN8740_ANLPAR_10BT_FD 0x0040
126 #define LAN8740_ANLPAR_10BT_HD 0x0020
127 #define LAN8740_ANLPAR_SELECTOR 0x001F
128 #define LAN8740_ANLPAR_SELECTOR_DEFAULT 0x0001
129 
130 //Auto-Negotiation Expansion register
131 #define LAN8740_ANER_RECEIVE_NP_LOC_ABLE 0x0040
132 #define LAN8740_ANER_RECEIVE_NP_STOR_LOC 0x0020
133 #define LAN8740_ANER_PAR_DETECT_FAULT 0x0010
134 #define LAN8740_ANER_LP_NEXT_PAGE_ABLE 0x0008
135 #define LAN8740_ANER_NEXT_PAGE_ABLE 0x0004
136 #define LAN8740_ANER_PAGE_RECEIVED 0x0002
137 #define LAN8740_ANER_LP_AN_ABLE 0x0001
138 
139 //Auto Negotiation Next Page TX register
140 #define LAN8740_ANNPR_NEXT_PAGE 0x8000
141 #define LAN8740_ANNPR_MSG_PAGE 0x2000
142 #define LAN8740_ANNPR_ACK2 0x1000
143 #define LAN8740_ANNPR_TOGGLE 0x0800
144 #define LAN8740_ANNPR_MESSAGE 0x07FF
145 
146 //Auto Negotiation Next Page RX register
147 #define LAN8740_ANLPNPR_NEXT_PAGE 0x8000
148 #define LAN8740_ANLPNPR_ACK 0x4000
149 #define LAN8740_ANLPNPR_MSG_PAGE 0x2000
150 #define LAN8740_ANLPNPR_ACK2 0x1000
151 #define LAN8740_ANLPNPR_TOGGLE 0x0800
152 #define LAN8740_ANLPNPR_MESSAGE 0x07FF
153 
154 //MMD Access Control register
155 #define LAN8740_MMDACR_FUNC 0xC000
156 #define LAN8740_MMDACR_FUNC_ADDR 0x0000
157 #define LAN8740_MMDACR_FUNC_DATA_NO_POST_INC 0x4000
158 #define LAN8740_MMDACR_DEVAD 0x001F
159 
160 //EDPD NLP/Crossover Time/EEE Configuration register
161 #define LAN8740_ENCTECR_EDPD_TX_NLP_EN 0x8000
162 #define LAN8740_ENCTECR_EDPD_TX_NLP_ITS 0x6000
163 #define LAN8740_ENCTECR_RX_NLP_WAKE_EN 0x1000
164 #define LAN8740_ENCTECR_RX_NLP_MIDS 0x0C00
165 #define LAN8740_ENCTECR_PHY_EEE_EN 0x0004
166 #define LAN8740_ENCTECR_EDPD_EXT_CROSSOVER 0x0002
167 #define LAN8740_ENCTECR_EXT_CROSSOVER_TIME 0x0001
168 
169 //Mode Control/Status register
170 #define LAN8740_MCSR_EDPWRDOWN 0x2000
171 #define LAN8740_MCSR_FARLOOPBACK 0x0200
172 #define LAN8740_MCSR_ALTINT 0x0040
173 #define LAN8740_MCSR_ENERGYON 0x0002
174 
175 //Special Modes register
176 #define LAN8740_SMR_MIIMODE 0x4000
177 #define LAN8740_SMR_MODE 0x00E0
178 #define LAN8740_SMR_PHYAD 0x001F
179 
180 //TDR Patterns/Delay Control register
181 #define LAN8740_TDRPDCR_DELAY_IN 0x8000
182 #define LAN8740_TDRPDCR_LINE_BREAK_COUNT 0x7000
183 #define LAN8740_TDRPDCR_PATTERN_HIGH 0x0FC0
184 #define LAN8740_TDRPDCR_PATTERN_LOW 0x003F
185 
186 //TDR Control/Status register
187 #define LAN8740_TDRCSR_TDR_EN 0x8000
188 #define LAN8740_TDRCSR_AD_FILTER_EN 0x4000
189 #define LAN8740_TDRCSR_CH_CABLE_TYPE 0x0600
190 #define LAN8740_TDRCSR_CH_STATUS 0x0100
191 #define LAN8740_TDRCSR_CH_LENGTH 0x00FF
192 
193 //Symbol Error Counter register
194 #define LAN8740_SECR_SYM_ERR_CNT 0xFFFF
195 
196 //Special Control/Status Indication register
197 #define LAN8740_SCSIR_AMDIXCTRL 0x8000
198 #define LAN8740_SCSIR_CH_SELECT 0x2000
199 #define LAN8740_SCSIR_SQEOFF 0x0800
200 #define LAN8740_SCSIR_XPOL 0x0010
201 
202 //Cable Length register
203 #define LAN8740_CLR_CBLN 0xF000
204 
205 //Interrupt Source Flag register
206 #define LAN8740_ISR_WOL 0x0100
207 #define LAN8740_ISR_ENERGYON 0x0080
208 #define LAN8740_ISR_AN_COMPLETE 0x0040
209 #define LAN8740_ISR_REMOTE_FAULT 0x0020
210 #define LAN8740_ISR_LINK_DOWN 0x0010
211 #define LAN8740_ISR_AN_LP_ACK 0x0008
212 #define LAN8740_ISR_PAR_DETECT_FAULT 0x0004
213 #define LAN8740_ISR_AN_PAGE_RECEIVED 0x0002
214 
215 //Interrupt Mask register
216 #define LAN8740_IMR_WOL 0x0100
217 #define LAN8740_IMR_ENERGYON 0x0080
218 #define LAN8740_IMR_AN_COMPLETE 0x0040
219 #define LAN8740_IMR_REMOTE_FAULT 0x0020
220 #define LAN8740_IMR_LINK_DOWN 0x0010
221 #define LAN8740_IMR_AN_LP_ACK 0x0008
222 #define LAN8740_IMR_PAR_DETECT_FAULT 0x0004
223 #define LAN8740_IMR_AN_PAGE_RECEIVED 0x0002
224 
225 //PHY Special Control/Status register
226 #define LAN8740_PSCSR_AUTODONE 0x1000
227 #define LAN8740_PSCSR_4B5B_EN 0x0040
228 #define LAN8740_PSCSR_HCDSPEED 0x001C
229 #define LAN8740_PSCSR_HCDSPEED_10BT_HD 0x0004
230 #define LAN8740_PSCSR_HCDSPEED_100BTX_HD 0x0008
231 #define LAN8740_PSCSR_HCDSPEED_10BT_FD 0x0014
232 #define LAN8740_PSCSR_HCDSPEED_100BTX_FD 0x0018
233 
234 //C++ guard
235 #ifdef __cplusplus
236 extern "C" {
237 #endif
238 
239 //LAN8740 Ethernet PHY driver
240 extern const PhyDriver lan8740PhyDriver;
241 
242 //LAN8740 related functions
243 error_t lan8740Init(NetInterface *interface);
244 
245 void lan8740Tick(NetInterface *interface);
246 
247 void lan8740EnableIrq(NetInterface *interface);
248 void lan8740DisableIrq(NetInterface *interface);
249 
250 void lan8740EventHandler(NetInterface *interface);
251 
252 void lan8740WritePhyReg(NetInterface *interface, uint8_t address,
253  uint16_t data);
254 
255 uint16_t lan8740ReadPhyReg(NetInterface *interface, uint8_t address);
256 
257 void lan8740DumpPhyReg(NetInterface *interface);
258 
259 //C++ guard
260 #ifdef __cplusplus
261 }
262 #endif
263 
264 #endif
const PhyDriver lan8740PhyDriver
LAN8740 Ethernet PHY driver.
void lan8740DumpPhyReg(NetInterface *interface)
Dump PHY registers for debugging purpose.
PHY driver.
Definition: nic.h:214
void lan8740Tick(NetInterface *interface)
LAN8740 timer handler.
error_t
Error codes.
Definition: error.h:42
#define NetInterface
Definition: net.h:36
void lan8740EnableIrq(NetInterface *interface)
Enable interrupts.
uint16_t lan8740ReadPhyReg(NetInterface *interface, uint8_t address)
Read PHY register.
void lan8740WritePhyReg(NetInterface *interface, uint8_t address, uint16_t data)
Write PHY register.
error_t lan8740Init(NetInterface *interface)
LAN8740 PHY transceiver initialization.
Network interface controller abstraction layer.
Ipv6Addr address
void lan8740DisableIrq(NetInterface *interface)
Disable interrupts.
void lan8740EventHandler(NetInterface *interface)
LAN8740 event handler.
uint8_t data[]
Definition: dtls_misc.h:176