ar8031_driver.h
Go to the documentation of this file.
1 /**
2  * @file ar8031_driver.h
3  * @brief AR8031 Gigabit 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 _AR8031_DRIVER_H
32 #define _AR8031_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //PHY address
38 #ifndef AR8031_PHY_ADDR
39  #define AR8031_PHY_ADDR 0
40 #elif (AR8031_PHY_ADDR < 0 || AR8031_PHY_ADDR > 31)
41  #error AR8031_PHY_ADDR parameter is not valid
42 #endif
43 
44 //AR8031 PHY registers
45 #define AR8031_BMCR 0x00
46 #define AR8031_BMSR 0x01
47 #define AR8031_PHYID1 0x02
48 #define AR8031_PHYID2 0x03
49 #define AR8031_ANAR 0x04
50 #define AR8031_ANLPAR 0x05
51 #define AR8031_ANER 0x06
52 #define AR8031_ANNPR 0x07
53 #define AR8031_ANLPNPR 0x08
54 #define AR8031_GBCR 0x09
55 #define AR8031_GBSR 0x0A
56 #define AR8031_MMDACR 0x0D
57 #define AR8031_MMDAADR 0x0E
58 #define AR8031_GBESR 0x0F
59 #define AR8031_FUNC_CTRL 0x10
60 #define AR8031_PHY_STATUS 0x11
61 #define AR8031_INT_EN 0x12
62 #define AR8031_INT_STATUS 0x13
63 #define AR8031_SMART_SPEED 0x14
64 #define AR8031_CDT_CTRL 0x16
65 #define AR8031_LED_CTRL 0x18
66 #define AR8031_MAN_LED_OVERRIDE 0x19
67 #define AR8031_COPPER_FIBER_STATUS 0x1B
68 #define AR8031_CDT_STATUS 0x1C
69 #define AR8031_DBG_PORT_ADDR_OFFSET 0x1D
70 #define AR8031_DBG_PORT_DATA 0x1E
71 #define AR8031_CHIP_CONF 0x1F
72 
73 //Control register
74 #define AR8031_BMCR_RESET 0x8000
75 #define AR8031_BMCR_LOOPBACK 0x4000
76 #define AR8031_BMCR_SPEED_SEL_LSB 0x2000
77 #define AR8031_BMCR_AN_EN 0x1000
78 #define AR8031_BMCR_POWER_DOWN 0x0800
79 #define AR8031_BMCR_ISOLATE 0x0400
80 #define AR8031_BMCR_RESTART_AN 0x0200
81 #define AR8031_BMCR_DUPLEX_MODE 0x0100
82 #define AR8031_BMCR_COL_TEST 0x0080
83 #define AR8031_BMCR_SPEED_SEL_MSB 0x0040
84 
85 //Status register
86 #define AR8031_BMSR_100BT4 0x8000
87 #define AR8031_BMSR_100BTX_FD 0x4000
88 #define AR8031_BMSR_100BTX_HD 0x2000
89 #define AR8031_BMSR_10BT_FD 0x1000
90 #define AR8031_BMSR_10BT_HD 0x0800
91 #define AR8031_BMSR_100BT2_FD 0x0400
92 #define AR8031_BMSR_100BT2_HD 0x0200
93 #define AR8031_BMSR_EXTENDED_STATUS 0x0100
94 #define AR8031_BMSR_MF_PREAMBLE_SUPPR 0x0040
95 #define AR8031_BMSR_AN_COMPLETE 0x0020
96 #define AR8031_BMSR_REMOTE_FAULT 0x0010
97 #define AR8031_BMSR_AN_CAPABLE 0x0008
98 #define AR8031_BMSR_LINK_STATUS 0x0004
99 #define AR8031_BMSR_JABBER_DETECT 0x0002
100 #define AR8031_BMSR_EXTENDED_CAPABLE 0x0001
101 
102 //PHY Identifier 1 register
103 #define AR8031_PHYID1_OUI_MSB 0xFFFF
104 #define AR8031_PHYID1_OUI_MSB_DEFAULT 0x004D
105 
106 //PHY Identifier 2 register
107 #define AR8031_PHYID2_OUI_LSB 0xFC00
108 #define AR8031_PHYID2_OUI_LSB_DEFAULT 0xD000
109 #define AR8031_PHYID2_MODEL_NUM 0x03F0
110 #define AR8031_PHYID2_MODEL_NUM_DEFAULT 0x0070
111 #define AR8031_PHYID2_REVISION_NUM 0x000F
112 
113 //Auto-Negotiation Advertisement register
114 #define AR8031_ANAR_NEXT_PAGE 0x8000
115 #define AR8031_ANAR_ACK 0x4000
116 #define AR8031_ANAR_REMOTE_FAULT 0x2000
117 #define AR8031_ANAR_XNP_ABLE 0x1000
118 #define AR8031_ANAR_ASYM_PAUSE 0x0800
119 #define AR8031_ANAR_PAUSE 0x0400
120 #define AR8031_ANAR_100BT4 0x0200
121 #define AR8031_ANAR_100BTX_FD 0x0100
122 #define AR8031_ANAR_100BTX_HD 0x0080
123 #define AR8031_ANAR_10BT_FD 0x0040
124 #define AR8031_ANAR_10BT_HD 0x0020
125 #define AR8031_ANAR_SELECTOR 0x001F
126 #define AR8031_ANAR_SELECTOR_DEFAULT 0x0001
127 
128 //Link Partner Ability register
129 #define AR8031_ANLPAR_NEXT_PAGE 0x8000
130 #define AR8031_ANLPAR_ACK 0x4000
131 #define AR8031_ANLPAR_REMOTE_FAULT 0x2000
132 #define AR8031_ANLPAR_ASYM_PAUSE 0x0800
133 #define AR8031_ANLPAR_PAUSE 0x0400
134 #define AR8031_ANLPAR_100BT4 0x0200
135 #define AR8031_ANLPAR_100BTX_FD 0x0100
136 #define AR8031_ANLPAR_100BTX_HD 0x0080
137 #define AR8031_ANLPAR_10BT_FD 0x0040
138 #define AR8031_ANLPAR_10BT_HD 0x0020
139 #define AR8031_ANLPAR_SELECTOR 0x001F
140 #define AR8031_ANLPAR_SELECTOR_DEFAULT 0x0001
141 
142 //Auto-Negotiation Expansion register
143 #define AR8031_ANER_PAR_DETECT_FAULT 0x0010
144 #define AR8031_ANER_LP_NEXT_PAGE_ABLE 0x0008
145 #define AR8031_ANER_NEXT_PAGE_ABLE 0x0004
146 #define AR8031_ANER_PAGE_RECEIVED 0x0002
147 #define AR8031_ANER_LP_AN_ABLE 0x0001
148 
149 //Auto-Negotiation Next Page Transmit register
150 #define AR8031_ANNPR_NEXT_PAGE 0x8000
151 #define AR8031_ANNPR_MSG_PAGE 0x2000
152 #define AR8031_ANNPR_ACK2 0x1000
153 #define AR8031_ANNPR_TOGGLE 0x0800
154 #define AR8031_ANNPR_MESSAGE 0x07FF
155 
156 //Link Partner Next Page register
157 #define AR8031_ANLPNPR_NEXT_PAGE 0x8000
158 #define AR8031_ANLPNPR_MSG_PAGE 0x2000
159 #define AR8031_ANLPNPR_ACK2 0x1000
160 #define AR8031_ANLPNPR_TOGGLE 0x0800
161 #define AR8031_ANLPNPR_MESSAGE 0x07FF
162 
163 //1000BASE-T Control register
164 #define AR8031_GBCR_TEST_MODE 0xE000
165 #define AR8031_GBCR_MS_MAN_CONF_EN 0x1000
166 #define AR8031_GBCR_MS_MAN_CONF_VAL 0x0800
167 #define AR8031_GBCR_PORT_TYPE 0x0400
168 #define AR8031_GBCR_1000BT_FD 0x0200
169 #define AR8031_GBCR_1000BT_HD 0x0100
170 
171 //1000BASE-T Status register
172 #define AR8031_GBSR_MS_CONF_FAULT 0x8000
173 #define AR8031_GBSR_MS_CONF_RES 0x4000
174 #define AR8031_GBSR_LOCAL_RECEIVER_STATUS 0x2000
175 #define AR8031_GBSR_REMOTE_RECEIVER_STATUS 0x1000
176 #define AR8031_GBSR_LP_1000BT_FD 0x0800
177 #define AR8031_GBSR_LP_1000BT_HD 0x0400
178 #define AR8031_GBSR_IDLE_ERR_COUNT 0x00FF
179 
180 //MMD Access Control register
181 #define AR8031_MMDACR_FUNC 0xC000
182 #define AR8031_MMDACR_FUNC_ADDR 0x0000
183 #define AR8031_MMDACR_FUNC_DATA_NO_POST_INC 0x4000
184 #define AR8031_MMDACR_FUNC_DATA_POST_INC_RW 0x8000
185 #define AR8031_MMDACR_FUNC_DATA_POST_INC_W 0xC000
186 #define AR8031_MMDACR_DEVAD 0x001F
187 
188 //Extended Status register
189 #define AR8031_GBESR_1000BX_FD 0x8000
190 #define AR8031_GBESR_1000BX_HD 0x4000
191 #define AR8031_GBESR_1000BT_FD 0x2000
192 #define AR8031_GBESR_1000BT_HD 0x1000
193 
194 //Function Control register
195 #define AR8031_FUNC_CTRL_ASSERT_CRS_ON_TX 0x0800
196 #define AR8031_FUNC_CTRL_FORCE_LINK 0x0400
197 #define AR8031_FUNC_CTRL_MDIX_MODE 0x0060
198 #define AR8031_FUNC_CTRL_MDIX_MODE_MANUAL_MDI 0x0000
199 #define AR8031_FUNC_CTRL_MDIX_MODE_MANUAL_MDIX 0x0020
200 #define AR8031_FUNC_CTRL_MDIX_MODE_AUTO 0x0060
201 #define AR8031_FUNC_CTRL_SQE_TEST 0x0004
202 #define AR8031_FUNC_CTRL_POLARITY_REVERSAL 0x0002
203 #define AR8031_FUNC_CTRL_JABBER_DIS 0x0001
204 
205 //PHY-Specific Status register
206 #define AR8031_PHY_STATUS_SPEED 0xC000
207 #define AR8031_PHY_STATUS_SPEED_10MBPS 0x0000
208 #define AR8031_PHY_STATUS_SPEED_100MBPS 0x4000
209 #define AR8031_PHY_STATUS_SPEED_1000MBPS 0x8000
210 #define AR8031_PHY_STATUS_DUPLEX 0x2000
211 #define AR8031_PHY_STATUS_PAGE_RECEIVED 0x1000
212 #define AR8031_PHY_STATUS_SPEED_DUPLEX_RESOLVED 0x0800
213 #define AR8031_PHY_STATUS_LINK 0x0400
214 #define AR8031_PHY_STATUS_MDI_CROSSOVER_STATUS 0x0040
215 #define AR8031_PHY_STATUS_WIRESPEED_DOWNGRADE 0x0020
216 #define AR8031_PHY_STATUS_TX_PAUSE_EN 0x0008
217 #define AR8031_PHY_STATUS_RX_PAUSE_EN 0x0004
218 #define AR8031_PHY_STATUS_POLARITY 0x0002
219 #define AR8031_PHY_STATUS_JABBER 0x0001
220 
221 //Interrupt Enable Register register
222 #define AR8031_INT_EN_AN_ERROR 0x8000
223 #define AR8031_INT_EN_SPEED_CHANGED 0x4000
224 #define AR8031_INT_EN_PAGE_RECEIVED 0x1000
225 #define AR8031_INT_EN_LINK_FAIL 0x0800
226 #define AR8031_INT_EN_LINK_SUCCESS 0x0400
227 #define AR8031_INT_EN_FAST_LINK_DOWN1 0x0200
228 #define AR8031_INT_EN_LINK_FAIL_BX 0x0100
229 #define AR8031_INT_EN_LINK_SUCCESS_BX 0x0080
230 #define AR8031_INT_EN_FAST_LINK_DOWN0 0x0040
231 #define AR8031_INT_EN_WIRESPEED_DOWNGRADE 0x0020
232 #define AR8031_INT_EN_10MS_PTP 0x0010
233 #define AR8031_INT_EN_RX_PTP 0x0008
234 #define AR8031_INT_EN_TX_PTP 0x0004
235 #define AR8031_INT_EN_POLARITY_CHANGED 0x0002
236 #define AR8031_INT_EN_WOL_PTP 0x0001
237 
238 //Interrupt Status register
239 #define AR8031_INT_STATUS_AN_ERROR 0x8000
240 #define AR8031_INT_STATUS_SPEED_CHANGED 0x4000
241 #define AR8031_INT_STATUS_PAGE_RECEIVED 0x1000
242 #define AR8031_INT_STATUS_LINK_FAIL 0x0800
243 #define AR8031_INT_STATUS_LINK_SUCCESS 0x0400
244 #define AR8031_INT_STATUS_FAST_LINK_DOWN1 0x0200
245 #define AR8031_INT_STATUS_LINK_FAIL_BX 0x0100
246 #define AR8031_INT_STATUS_LINK_SUCCESS_BX 0x0080
247 #define AR8031_INT_STATUS_FAST_LINK_DOWN0 0x0040
248 #define AR8031_INT_STATUS_WIRESPEED_DOWNGRADE 0x0020
249 #define AR8031_INT_STATUS_10MS_PTP 0x0010
250 #define AR8031_INT_STATUS_RX_PTP 0x0008
251 #define AR8031_INT_STATUS_TX_PTP 0x0004
252 #define AR8031_INT_STATUS_POLARITY_CHANGED 0x0002
253 #define AR8031_INT_STATUS_WOL_PTP 0x0001
254 
255 //Smart Speed register
256 #define AR8031_SMART_SPEED_EN 0x0020
257 #define AR8031_SMART_SPEED_RETRY_LIMIT 0x001C
258 #define AR8031_SMART_SPEED_BYPASS_TIMER 0x0002
259 
260 //Cable Diagnostic Tester (CDT) Control register
261 #define AR8031_CDT_CTRL_MDI_PAIR_SELECT 0x0300
262 #define AR8031_CDT_CTRL_TEST_EN 0x0001
263 
264 //LED Control register
265 #define AR8031_LED_CTRL_LED_DIS 0x8000
266 #define AR8031_LED_CTRL_LED_ON_TIME 0x7000
267 #define AR8031_LED_CTRL_LED_OFF_TIME 0x0700
268 #define AR8031_LED_CTRL_LED_LINK_CTRL 0x0018
269 #define AR8031_LED_CTRL_LED_ACT_CTRL 0x0004
270 
271 //Manual LED Override register
272 #define AR8031_MAN_LED_OVERRIDE_LED_ACT 0x1000
273 #define AR8031_MAN_LED_OVERRIDE_LED_LINK10_100_CTRL 0x00C0
274 #define AR8031_MAN_LED_OVERRIDE_LED_RX_CTRL 0x000C
275 #define AR8031_MAN_LED_OVERRIDE_LED_TX_CTRL 0x0003
276 
277 //Copper/Fiber Status register
278 #define AR8031_COPPER_FIBER_STATUS_TX_PAUSE_EN_BX 0x2000
279 #define AR8031_COPPER_FIBER_STATUS_RX_PAUSE_EN_BX 0x1000
280 #define AR8031_COPPER_FIBER_STATUS_LINK_ESTABLISHED_BX 0x0800
281 #define AR8031_COPPER_FIBER_STATUS_FD_MODE_BX 0x0400
282 #define AR8031_COPPER_FIBER_STATUS_SPEED_MODE_BX 0x0300
283 #define AR8031_COPPER_FIBER_STATUS_TX_PAUSE_EN_BT 0x0020
284 #define AR8031_COPPER_FIBER_STATUS_RX_PAUSE_EN_BT 0x0010
285 #define AR8031_COPPER_FIBER_STATUS_LINK_ESTABLISHED_BT 0x0008
286 #define AR8031_COPPER_FIBER_STATUS_FD_MODE_BT 0x0004
287 #define AR8031_COPPER_FIBER_STATUS_SPEED_MODE_BT 0x0003
288 
289 //Cable Diagnostic Tester Status register
290 #define AR8031_CDT_STATUS_STATUS 0x0300
291 #define AR8031_CDT_STATUS_DELTA_TIME 0x00FF
292 
293 //Chip Configure register
294 #define AR8031_CHIP_CONF_BT_BX_REG_SEL 0x8000
295 #define AR8031_CHIP_CONF_SMII_IMP_50_75_AUTO 0x4000
296 #define AR8031_CHIP_CONF_SGMII_RXIMP_50_75 0x2000
297 #define AR8031_CHIP_CONF_SGMII_TXIMP_50_75 0x1000
298 #define AR8031_CHIP_CONF_PRIORITY_SEL 0x0400
299 #define AR8031_CHIP_CONF_FIBER_MODE_AUTO 0x0100
300 #define AR8031_CHIP_CONF_MODE_CFG_QUAL 0x00F0
301 #define AR8031_CHIP_CONF_MODE_CFG 0x000F
302 
303 //C++ guard
304 #ifdef __cplusplus
305 extern "C" {
306 #endif
307 
308 //AR8031 Ethernet PHY driver
309 extern const PhyDriver ar8031PhyDriver;
310 
311 //AR8031 related functions
312 error_t ar8031Init(NetInterface *interface);
313 
314 void ar8031Tick(NetInterface *interface);
315 
316 void ar8031EnableIrq(NetInterface *interface);
317 void ar8031DisableIrq(NetInterface *interface);
318 
319 void ar8031EventHandler(NetInterface *interface);
320 
321 void ar8031WritePhyReg(NetInterface *interface, uint8_t address,
322  uint16_t data);
323 
324 uint16_t ar8031ReadPhyReg(NetInterface *interface, uint8_t address);
325 
326 void ar8031DumpPhyReg(NetInterface *interface);
327 
328 //C++ guard
329 #ifdef __cplusplus
330 }
331 #endif
332 
333 #endif
void ar8031EventHandler(NetInterface *interface)
AR8031 event handler.
void ar8031EnableIrq(NetInterface *interface)
Enable interrupts.
PHY driver.
Definition: nic.h:214
const PhyDriver ar8031PhyDriver
AR8031 Ethernet PHY driver.
Definition: ar8031_driver.c:44
void ar8031Tick(NetInterface *interface)
AR8031 timer handler.
void ar8031WritePhyReg(NetInterface *interface, uint8_t address, uint16_t data)
Write PHY register.
error_t ar8031Init(NetInterface *interface)
AR8031 PHY transceiver initialization.
Definition: ar8031_driver.c:62
error_t
Error codes.
Definition: error.h:42
#define NetInterface
Definition: net.h:36
void ar8031DisableIrq(NetInterface *interface)
Disable interrupts.
uint16_t ar8031ReadPhyReg(NetInterface *interface, uint8_t address)
Read PHY register.
Network interface controller abstraction layer.
Ipv6Addr address
void ar8031DumpPhyReg(NetInterface *interface)
Dump PHY registers for debugging purpose.
uint8_t data[]
Definition: dtls_misc.h:176