dp83865_driver.h
Go to the documentation of this file.
1 /**
2  * @file dp83865_driver.h
3  * @brief DP83865 Gigabit Ethernet PHY driver
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2026 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.6.0
29  **/
30 
31 #ifndef _DP83865_DRIVER_H
32 #define _DP83865_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //PHY address
38 #ifndef DP83865_PHY_ADDR
39  #define DP83865_PHY_ADDR 0
40 #elif (DP83865_PHY_ADDR < 0 || DP83865_PHY_ADDR > 31)
41  #error DP83865_PHY_ADDR parameter is not valid
42 #endif
43 
44 //DP83865 PHY registers
45 #define DP83865_BMCR 0x00
46 #define DP83865_BMSR 0x01
47 #define DP83865_PHYIDR1 0x02
48 #define DP83865_PHYIDR2 0x03
49 #define DP83865_ANAR 0x04
50 #define DP83865_ANLPAR 0x05
51 #define DP83865_ANER 0x06
52 #define DP83865_ANNPTR 0x07
53 #define DP83865_ANNPRR 0x08
54 #define DP83865_1KTCR 0x09
55 #define DP83865_1KSTSR 0x0A
56 #define DP83865_1KSCR 0x0F
57 #define DP83865_STRAP_REG 0x10
58 #define DP83865_LINK_AN 0x11
59 #define DP83865_AUX_CTRL 0x12
60 #define DP83865_LED_CTRL 0x13
61 #define DP83865_INT_STATUS 0x14
62 #define DP83865_INT_MASK 0x15
63 #define DP83865_EXP_MEM_CTL 0x16
64 #define DP83865_INT_CLEAR 0x17
65 #define DP83865_BIST_CNT 0x18
66 #define DP83865_BIST_CFG1 0x19
67 #define DP83865_BIST_CFG2 0x1A
68 #define DP83865_EXP_MEM_DATA 0x1D
69 #define DP83865_EXP_MEM_ADDR 0x1E
70 #define DP83865_PHY_SUP 0x1F
71 
72 //Basic Mode Control register
73 #define DP83865_BMCR_RESET 0x8000
74 #define DP83865_BMCR_LOOPBACK 0x4000
75 #define DP83865_BMCR_SPEED_LSB 0x2000
76 #define DP83865_BMCR_AN_EN 0x1000
77 #define DP83865_BMCR_POWER_DOWN 0x0800
78 #define DP83865_BMCR_ISOLATE 0x0400
79 #define DP83865_BMCR_RESTART_AN 0x0200
80 #define DP83865_BMCR_DUPLEX 0x0100
81 #define DP83865_BMCR_COL_TEST 0x0080
82 #define DP83865_BMCR_SPEED_MSB 0x0040
83 
84 //Basic Mode Status register
85 #define DP83865_BMSR_100BT4 0x8000
86 #define DP83865_BMSR_100BTX_FD 0x4000
87 #define DP83865_BMSR_100BTX_HD 0x2000
88 #define DP83865_BMSR_10BT_FD 0x1000
89 #define DP83865_BMSR_10BT_HD 0x0800
90 #define DP83865_BMSR_100BT2_FD 0x0400
91 #define DP83865_BMSR_100BT2_HD 0x0200
92 #define DP83865_BMSR_EXTENDED_STATUS 0x0100
93 #define DP83865_BMSR_PREAMBLE_SUPPR 0x0040
94 #define DP83865_BMSR_AN_COMPLETE 0x0020
95 #define DP83865_BMSR_REMOTE_FAULT 0x0010
96 #define DP83865_BMSR_AN_CAPABLE 0x0008
97 #define DP83865_BMSR_LINK_STATUS 0x0004
98 #define DP83865_BMSR_JABBER_DETECT 0x0002
99 #define DP83865_BMSR_EXTENDED_CAPABLE 0x0001
100 
101 //PHY Identifier 1 register
102 #define DP83865_PHYIDR1_OUI_MSB 0xFFFF
103 #define DP83865_PHYIDR1_OUI_MSB_DEFAULT 0x2000
104 
105 //PHY Identifier 2 register
106 #define DP83865_PHYIDR2_OUI_LSB 0xFC00
107 #define DP83865_PHYIDR2_OUI_LSB_DEFAULT 0x5C00
108 #define DP83865_PHYIDR2_VNDR_MDL 0x03F0
109 #define DP83865_PHYIDR2_VNDR_MDL_DEFAULT 0x0070
110 #define DP83865_PHYIDR2_MDL_REV 0x000F
111 #define DP83865_PHYIDR2_MDL_REV_DEFAULT 0x000A
112 
113 //Auto-Negotiation Advertisement register
114 #define DP83865_ANAR_NP 0x8000
115 #define DP83865_ANAR_RF 0x2000
116 #define DP83865_ANAR_ASY_PAUSE 0x0800
117 #define DP83865_ANAR_PAUSE 0x0400
118 #define DP83865_ANAR_100BT4 0x0200
119 #define DP83865_ANAR_100BTX_FD 0x0100
120 #define DP83865_ANAR_100BTX_HD 0x0080
121 #define DP83865_ANAR_10BT_FD 0x0040
122 #define DP83865_ANAR_10BT_HD 0x0020
123 #define DP83865_ANAR_PSB 0x001F
124 
125 //Auto-Negotiation Link Partner Ability register
126 #define DP83865_ANLPAR_NP 0x8000
127 #define DP83865_ANLPAR_ACK 0x4000
128 #define DP83865_ANLPAR_RF 0x2000
129 #define DP83865_ANLPAR_ASY_PAUSE 0x0800
130 #define DP83865_ANLPAR_PAUSE 0x0400
131 #define DP83865_ANLPAR_100BT4 0x0200
132 #define DP83865_ANLPAR_100BTX_FD 0x0100
133 #define DP83865_ANLPAR_100BTX_HD 0x0080
134 #define DP83865_ANLPAR_10BT_FD 0x0040
135 #define DP83865_ANLPAR_10BT_HD 0x0020
136 #define DP83865_ANLPAR_PSB 0x001F
137 
138 //Auto-Negotiation Expansion register
139 #define DP83865_ANER_PDF 0x0010
140 #define DP83865_ANER_LP_NP_ABLE 0x0008
141 #define DP83865_ANER_NP_ABLE 0x0004
142 #define DP83865_ANER_PAGE_RX 0x0002
143 #define DP83865_ANER_LP_AN_ABLE 0x0001
144 
145 //Auto-Negotiation Next Page TX register
146 #define DP83865_ANNPTR_NP 0x8000
147 #define DP83865_ANNPTR_ACK 0x4000
148 #define DP83865_ANNPTR_MP 0x2000
149 #define DP83865_ANNPTR_ACK2 0x1000
150 #define DP83865_ANNPTR_TOG_TX 0x0800
151 #define DP83865_ANNPTR_CODE 0x07FF
152 
153 //Auto-Negotiation Next Page RX register
154 #define DP83865_ANNPRR_NP 0x8000
155 #define DP83865_ANNPRR_ACK 0x4000
156 #define DP83865_ANNPRR_MP 0x2000
157 #define DP83865_ANNPRR_ACK2 0x1000
158 #define DP83865_ANNPRR_TOGGLE 0x0800
159 #define DP83865_ANNPRR_CODE 0x07FF
160 
161 //1000BASE-T Control register
162 #define DP83865_1KTCR_TEST_MODE 0xE000
163 #define DP83865_1KTCR_TEST_MODE_NORMAL 0x0000
164 #define DP83865_1KTCR_TEST_MODE_1 0x2000
165 #define DP83865_1KTCR_TEST_MODE_2 0x4000
166 #define DP83865_1KTCR_TEST_MODE_3 0x6000
167 #define DP83865_1KTCR_TEST_MODE_4 0x8000
168 #define DP83865_1KTCR_MS_MAN_CONF_EN 0x1000
169 #define DP83865_1KTCR_MS_MAN_CONF_VAL 0x0800
170 #define DP83865_1KTCR_REPEATER_DT 0x0400
171 #define DP83865_1KTCR_1000BT_FD 0x0200
172 #define DP83865_1KTCR_1000BT_HD 0x0100
173 
174 //1000BASE-T Status register
175 #define DP83865_1KSTSR_MS_CONF_FAULT 0x8000
176 #define DP83865_1KSTSR_MS_CONF_RES 0x4000
177 #define DP83865_1KSTSR_LOCAL_RECEIVER_STATUS 0x2000
178 #define DP83865_1KSTSR_REMOTE_RECEIVER_STATUS 0x1000
179 #define DP83865_1KSTSR_LP_1000BT_FD 0x0800
180 #define DP83865_1KSTSR_LP_1000BT_HD 0x0400
181 #define DP83865_1KSTSR_IDLE_ERR_COUNT 0x00FF
182 
183 //1000BASE-T Extended Status register
184 #define DP83865_1KSCR_1000BX_FD 0x8000
185 #define DP83865_1KSCR_1000BX_HD 0x4000
186 #define DP83865_1KSCR_1000BT_FD 0x2000
187 #define DP83865_1KSCR_1000BT_HD 0x1000
188 
189 //Strap Options register
190 #define DP83865_STRAP_REG_AN_EN 0x8000
191 #define DP83865_STRAP_REG_DUPLEX_MODE 0x4000
192 #define DP83865_STRAP_REG_SPEED 0x3000
193 #define DP83865_STRAP_REG_NC_MODE_EN 0x0400
194 #define DP83865_STRAP_REG_MAC_CLOCK_EN 0x0080
195 #define DP83865_STRAP_REG_MDIX_EN 0x0040
196 #define DP83865_STRAP_REG_MULTI_EN 0x0020
197 #define DP83865_STRAP_REG_PHYADDR 0x001F
198 
199 //Link and Auto-Negotiation Status register
200 #define DP83865_LINK_AN_TP_POLARITY 0xF000
201 #define DP83865_LINK_AN_POWER_DOWN_STATUS 0x0800
202 #define DP83865_LINK_AN_MDIX_STATUS 0x0400
203 #define DP83865_LINK_AN_FIFO_ERROR 0x0200
204 #define DP83865_LINK_AN_SHALLOW_LOOPBACK_STATUS 0x0080
205 #define DP83865_LINK_AN_DEEP_LOOPBACK_STATUS 0x0040
206 #define DP83865_LINK_AN_NON_COMPLIANT_MODE_STATUS 0x0020
207 #define DP83865_LINK_AN_SPEED_STATUS 0x0018
208 #define DP83865_LINK_AN_SPEED_STATUS_10MBPS 0x0000
209 #define DP83865_LINK_AN_SPEED_STATUS_100MBPS 0x0008
210 #define DP83865_LINK_AN_SPEED_STATUS_1000MBPS 0x0010
211 #define DP83865_LINK_AN_LINK_STATUS 0x0004
212 #define DP83865_LINK_AN_DUPLEX_STATUS 0x0002
213 #define DP83865_LINK_AN_MS_CONF_STATUS 0x0001
214 
215 //Auxiliary Control register
216 #define DP83865_AUX_CTRL_AUTO_MDIX_EN 0x8000
217 #define DP83865_AUX_CTRL_MANUAL_MDIX_VALUE 0x4000
218 #define DP83865_AUX_CTRL_RGMII_EN 0x3000
219 #define DP83865_AUX_CTRL_RGMII_EN_GMII_MODE 0x0000
220 #define DP83865_AUX_CTRL_RGMII_EN_RGMII_HP_MODE 0x2000
221 #define DP83865_AUX_CTRL_RGMII_EN_RGMII_3COM_MODE 0x3000
222 #define DP83865_AUX_CTRL_NON_COMPLIANT_MODE 0x0200
223 #define DP83865_AUX_CTRL_RGMII_INBAND_STATUS_EN 0x0100
224 #define DP83865_AUX_CTRL_TX_TCLK_EN 0x0080
225 #define DP83865_AUX_CTRL_TX_TRIGGER_SYN_EN 0x0040
226 #define DP83865_AUX_CTRL_SHALLOW_DEEP_LOOPBACK_EN 0x0020
227 #define DP83865_AUX_CTRL_X_MAC 0x0010
228 #define DP83865_AUX_CTRL_JABBER_DIS 0x0001
229 
230 //LED Control register
231 #define DP83865_LED_CTRL_ACT_LED 0xC000
232 #define DP83865_LED_CTRL_ACT_LED_NORMAL 0x0000
233 #define DP83865_LED_CTRL_ACT_LED_FORCED_OFF 0x4000
234 #define DP83865_LED_CTRL_ACT_LED_BLINK_MODE 0x8000
235 #define DP83865_LED_CTRL_ACT_LED_FORCED_ON 0xC000
236 #define DP83865_LED_CTRL_LINK10_LED 0x3000
237 #define DP83865_LED_CTRL_LINK10_LED_NORMAL 0x0000
238 #define DP83865_LED_CTRL_LINK10_LED_FORCED_OFF 0x1000
239 #define DP83865_LED_CTRL_LINK10_LED_BLINK_MODE 0x2000
240 #define DP83865_LED_CTRL_LINK10_LED_FORCED_ON 0x3000
241 #define DP83865_LED_CTRL_LINK100_LED 0x0C00
242 #define DP83865_LED_CTRL_LINK100_LED_NORMAL 0x0000
243 #define DP83865_LED_CTRL_LINK100_LED_FORCED_OFF 0x0400
244 #define DP83865_LED_CTRL_LINK100_LED_BLINK_MODE 0x0800
245 #define DP83865_LED_CTRL_LINK100_LED_FORCED_ON 0x0C00
246 #define DP83865_LED_CTRL_LINK1000_LED 0x0300
247 #define DP83865_LED_CTRL_LINK1000_LED_NORMAL 0x0000
248 #define DP83865_LED_CTRL_LINK1000_LED_FORCED_OFF 0x0100
249 #define DP83865_LED_CTRL_LINK1000_LED_BLINK_MODE 0x0200
250 #define DP83865_LED_CTRL_LINK1000_LED_FORCED_ON 0x0300
251 #define DP83865_LED_CTRL_DUPLEX_LED 0x00C0
252 #define DP83865_LED_CTRL_DUPLEX_LED_NORMAL 0x0000
253 #define DP83865_LED_CTRL_DUPLEX_LED_FORCED_OFF 0x0040
254 #define DP83865_LED_CTRL_DUPLEX_LED_BLINK_MODE 0x0080
255 #define DP83865_LED_CTRL_DUPLEX_LED_FORCED_ON 0x00C0
256 #define DP83865_LED_CTRL_REDUCED_LED_EN 0x0020
257 #define DP83865_LED_CTRL_LED_ON_CRC 0x0010
258 #define DP83865_LED_CTRL_LED_ON_IE 0x0008
259 #define DP83865_LED_CTRL_AN_FALLBACK_AN 0x0004
260 #define DP83865_LED_CTRL_AN_FALLBACK_CRC 0x0002
261 #define DP83865_LED_CTRL_AN_FALLBACK_IE 0x0001
262 
263 //Interrupt Status register
264 #define DP83865_INT_STATUS_SPD_CNG_INT 0x8000
265 #define DP83865_INT_STATUS_LNK_CNG_INT 0x4000
266 #define DP83865_INT_STATUS_DPLX_CNG_INT 0x2000
267 #define DP83865_INT_STATUS_MDIX_CNG_INT 0x1000
268 #define DP83865_INT_STATUS_POL_CNG_INT 0x0800
269 #define DP83865_INT_STATUS_PRL_DET_FLT_INT 0x0400
270 #define DP83865_INT_STATUS_MAS_SLA_ERR_INT 0x0200
271 #define DP83865_INT_STATUS_NO_HCD_INT 0x0100
272 #define DP83865_INT_STATUS_NO_LNK_INT 0x0080
273 #define DP83865_INT_STATUS_JABBER_CNG_INT 0x0040
274 #define DP83865_INT_STATUS_NXT_PG_RCVD_INT 0x0020
275 #define DP83865_INT_STATUS_AN_CMPL_INT 0x0010
276 #define DP83865_INT_STATUS_REM_FLT_CNG_INT 0x0008
277 
278 //Interrupt Mask register
279 #define DP83865_INT_MASK_SPD_CNG_INT_MSK 0x8000
280 #define DP83865_INT_MASK_LNK_CNG_INT_MSK 0x4000
281 #define DP83865_INT_MASK_DPLX_CNG_INT_MSK 0x2000
282 #define DP83865_INT_MASK_MDIX_CNG_INT_MSK 0x1000
283 #define DP83865_INT_MASK_POL_CNG_INT_MSK 0x0800
284 #define DP83865_INT_MASK_PRL_DET_FLT_INT_MSK 0x0400
285 #define DP83865_INT_MASK_MAS_SLA_ERR_INT_MSK 0x0200
286 #define DP83865_INT_MASK_NO_HCD_INT_MSK 0x0100
287 #define DP83865_INT_MASK_NO_LNK_INT_MSK 0x0080
288 #define DP83865_INT_MASK_JABBER_CNG_INT_MSK 0x0040
289 #define DP83865_INT_MASK_NXT_PG_RCVD_INT_MSK 0x0020
290 #define DP83865_INT_MASK_AN_CMPL_INT_MSK 0x0010
291 #define DP83865_INT_MASK_REM_FLT_CNG_INT_MSK 0x0008
292 
293 //Expanded Memory Access Control register
294 #define DP83865_EXP_MEM_CTL_GLOBAL_RESET 0x8000
295 #define DP83865_EXP_MEM_CTL_BROADCAST_EN 0x0080
296 #define DP83865_EXP_MEM_CTL_ADDRESS_CONTROL 0x0003
297 
298 //Interrupt Clear register
299 #define DP83865_INT_CLEAR_SPD_CNG_INT_CLR 0x8000
300 #define DP83865_INT_CLEAR_LNK_CNG_INT_CLR 0x4000
301 #define DP83865_INT_CLEAR_DPLX_CNG_INT_CLR 0x2000
302 #define DP83865_INT_CLEAR_MDIX_CNG_INT_CLR 0x1000
303 #define DP83865_INT_CLEAR_POL_CNG_INT_CLR 0x0800
304 #define DP83865_INT_CLEAR_PRL_DET_FLT_INT_CLR 0x0400
305 #define DP83865_INT_CLEAR_MAS_SLA_ERR_INT_CLR 0x0200
306 #define DP83865_INT_CLEAR_NO_HCD_INT_CLR 0x0100
307 #define DP83865_INT_CLEAR_NO_LNK_INT_CLR 0x0080
308 #define DP83865_INT_CLEAR_JABBER_CNG_INT_CLR 0x0040
309 #define DP83865_INT_CLEAR_NXT_PG_RCVD_INT_CLR 0x0020
310 #define DP83865_INT_CLEAR_AN_CMPL_INT_CLR 0x0010
311 #define DP83865_INT_CLEAR_REM_FLT_CNG_INT_CLR 0x0008
312 
313 //BIST Configuration 1 register
314 #define DP83865_BIST_CFG1_BIST_CNT_TYPE 0x8000
315 #define DP83865_BIST_CFG1_BIST_CNT_CLR 0x4000
316 #define DP83865_BIST_CFG1_TX_BIST_PAK_LEN 0x2000
317 #define DP83865_BIST_CFG1_TX_BIST_IFG 0x1000
318 #define DP83865_BIST_CFG1_TX_BIST_EN 0x0800
319 #define DP83865_BIST_CFG1_TX_BIST_PAK_TYPE 0x0400
320 #define DP83865_BIST_CFG1_TX_BIST_PAK 0x00FF
321 
322 //BIST Configuration 2 register
323 #define DP83865_BIST_CFG2_RX_BIST_EN 0x8000
324 #define DP83865_BIST_CFG2_BIST_CNT_SEL 0x4000
325 #define DP83865_BIST_CFG2_TX_BIST_PAK_CNT 0x3800
326 #define DP83865_BIST_CFG2_LINK_LINK_ACT_SEL 0x0001
327 
328 //PHY Support register
329 #define DP83865_PHY_SUP_PHY_ADDR 0x001F
330 
331 //C++ guard
332 #ifdef __cplusplus
333 extern "C" {
334 #endif
335 
336 //DP83865 Ethernet PHY driver
337 extern const PhyDriver dp83865PhyDriver;
338 
339 //DP83865 related functions
340 error_t dp83865Init(NetInterface *interface);
341 void dp83865InitHook(NetInterface *interface);
342 
343 void dp83865Tick(NetInterface *interface);
344 
345 void dp83865EnableIrq(NetInterface *interface);
346 void dp83865DisableIrq(NetInterface *interface);
347 
348 void dp83865EventHandler(NetInterface *interface);
349 
350 void dp83865WritePhyReg(NetInterface *interface, uint8_t address,
351  uint16_t data);
352 
353 uint16_t dp83865ReadPhyReg(NetInterface *interface, uint8_t address);
354 
355 void dp83865DumpPhyReg(NetInterface *interface);
356 
357 //C++ guard
358 #ifdef __cplusplus
359 }
360 #endif
361 
362 #endif
void dp83865DumpPhyReg(NetInterface *interface)
Dump PHY registers for debugging purpose.
Ethernet PHY driver.
Definition: nic.h:311
uint8_t data[]
Definition: ethernet.h:224
void dp83865EventHandler(NetInterface *interface)
DP83865 event handler.
void dp83865DisableIrq(NetInterface *interface)
Disable interrupts.
uint16_t dp83865ReadPhyReg(NetInterface *interface, uint8_t address)
Read PHY register.
error_t dp83865Init(NetInterface *interface)
DP83865 PHY transceiver initialization.
error_t
Error codes.
Definition: error.h:43
#define NetInterface
Definition: net.h:40
void dp83865EnableIrq(NetInterface *interface)
Enable interrupts.
const PhyDriver dp83865PhyDriver
DP83865 Ethernet PHY driver.
Ipv6Addr address[]
Definition: ipv6.h:345
Network interface controller abstraction layer.
void dp83865WritePhyReg(NetInterface *interface, uint8_t address, uint16_t data)
Write PHY register.
void dp83865InitHook(NetInterface *interface)
DP83865 custom configuration.
void dp83865Tick(NetInterface *interface)
DP83865 timer handler.