ar8035_driver.h
Go to the documentation of this file.
1 /**
2  * @file ar8035_driver.h
3  * @brief AR8035 Gigabit Ethernet PHY driver
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2020 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.8
29  **/
30 
31 #ifndef _AR8035_DRIVER_H
32 #define _AR8035_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //PHY address
38 #ifndef AR8035_PHY_ADDR
39  #define AR8035_PHY_ADDR 0
40 #elif (AR8035_PHY_ADDR < 0 || AR8035_PHY_ADDR > 31)
41  #error AR8035_PHY_ADDR parameter is not valid
42 #endif
43 
44 //AR8035 PHY registers
45 #define AR8035_BMCR 0x00
46 #define AR8035_BMSR 0x01
47 #define AR8035_PHYID1 0x02
48 #define AR8035_PHYID2 0x03
49 #define AR8035_ANAR 0x04
50 #define AR8035_ANLPAR 0x05
51 #define AR8035_ANER 0x06
52 #define AR8035_ANNPR 0x07
53 #define AR8035_ANLPNPR 0x08
54 #define AR8035_GBCR 0x09
55 #define AR8035_GBSR 0x0A
56 #define AR8035_MMDACR 0x0D
57 #define AR8035_MMDAADR 0x0E
58 #define AR8035_GBESR 0x0F
59 #define AR8035_FUNC_CTRL 0x10
60 #define AR8035_PHY_STATUS 0x11
61 #define AR8035_INT_EN 0x12
62 #define AR8035_INT_STATUS 0x13
63 #define AR8035_SMART_SPEED 0x14
64 #define AR8035_CDT_CTRL 0x16
65 #define AR8035_LED_CTRL 0x18
66 #define AR8035_CDT_STATUS 0x1C
67 #define AR8035_DBG_PORT_ADDR_OFFSET 0x1D
68 #define AR8035_DBG_PORT_DATA 0x1E
69 
70 //Control register
71 #define AR8035_BMCR_RESET 0x8000
72 #define AR8035_BMCR_LOOPBACK 0x4000
73 #define AR8035_BMCR_SPEED_SEL_LSB 0x2000
74 #define AR8035_BMCR_AN_EN 0x1000
75 #define AR8035_BMCR_POWER_DOWN 0x0800
76 #define AR8035_BMCR_ISOLATE 0x0400
77 #define AR8035_BMCR_RESTART_AN 0x0200
78 #define AR8035_BMCR_DUPLEX_MODE 0x0100
79 #define AR8035_BMCR_COL_TEST 0x0080
80 #define AR8035_BMCR_SPEED_SEL_MSB 0x0040
81 
82 //Status register
83 #define AR8035_BMSR_100BT4 0x8000
84 #define AR8035_BMSR_100BTX_FD 0x4000
85 #define AR8035_BMSR_100BTX_HD 0x2000
86 #define AR8035_BMSR_10BT_FD 0x1000
87 #define AR8035_BMSR_10BT_HD 0x0800
88 #define AR8035_BMSR_100BT2_FD 0x0400
89 #define AR8035_BMSR_100BT2_HD 0x0200
90 #define AR8035_BMSR_EXTENDED_STATUS 0x0100
91 #define AR8035_BMSR_MF_PREAMBLE_SUPPR 0x0040
92 #define AR8035_BMSR_AN_COMPLETE 0x0020
93 #define AR8035_BMSR_REMOTE_FAULT 0x0010
94 #define AR8035_BMSR_AN_CAPABLE 0x0008
95 #define AR8035_BMSR_LINK_STATUS 0x0004
96 #define AR8035_BMSR_JABBER_DETECT 0x0002
97 #define AR8035_BMSR_EXTENDED_CAPABLE 0x0001
98 
99 //PHY Identifier 1 register
100 #define AR8035_PHYID1_OUI_MSB 0xFFFF
101 #define AR8035_PHYID1_OUI_MSB_DEFAULT 0x004D
102 
103 //PHY Identifier 2 register
104 #define AR8035_PHYID2_OUI_LSB 0xFC00
105 #define AR8035_PHYID2_OUI_LSB_DEFAULT 0xD000
106 #define AR8035_PHYID2_MODEL_NUM 0x03F0
107 #define AR8035_PHYID2_MODEL_NUM_DEFAULT 0x0070
108 #define AR8035_PHYID2_REVISION_NUM 0x000F
109 
110 //Auto-Negotiation Advertisement register
111 #define AR8035_ANAR_NEXT_PAGE 0x8000
112 #define AR8035_ANAR_ACK 0x4000
113 #define AR8035_ANAR_REMOTE_FAULT 0x2000
114 #define AR8035_ANAR_XNP_ABLE 0x1000
115 #define AR8035_ANAR_ASYM_PAUSE 0x0800
116 #define AR8035_ANAR_PAUSE 0x0400
117 #define AR8035_ANAR_100BT4 0x0200
118 #define AR8035_ANAR_100BTX_FD 0x0100
119 #define AR8035_ANAR_100BTX_HD 0x0080
120 #define AR8035_ANAR_10BT_FD 0x0040
121 #define AR8035_ANAR_10BT_HD 0x0020
122 #define AR8035_ANAR_SELECTOR 0x001F
123 #define AR8035_ANAR_SELECTOR_DEFAULT 0x0001
124 
125 //Link Partner Ability register
126 #define AR8035_ANLPAR_NEXT_PAGE 0x8000
127 #define AR8035_ANLPAR_ACK 0x4000
128 #define AR8035_ANLPAR_REMOTE_FAULT 0x2000
129 #define AR8035_ANLPAR_ASYM_PAUSE 0x0800
130 #define AR8035_ANLPAR_PAUSE 0x0400
131 #define AR8035_ANLPAR_100BT4 0x0200
132 #define AR8035_ANLPAR_100BTX_FD 0x0100
133 #define AR8035_ANLPAR_100BTX_HD 0x0080
134 #define AR8035_ANLPAR_10BT_FD 0x0040
135 #define AR8035_ANLPAR_10BT_HD 0x0020
136 #define AR8035_ANLPAR_SELECTOR 0x001F
137 #define AR8035_ANLPAR_SELECTOR_DEFAULT 0x0001
138 
139 //Auto-Negotiation Expansion register
140 #define AR8035_ANER_PAR_DETECT_FAULT 0x0010
141 #define AR8035_ANER_LP_NEXT_PAGE_ABLE 0x0008
142 #define AR8035_ANER_NEXT_PAGE_ABLE 0x0004
143 #define AR8035_ANER_PAGE_RECEIVED 0x0002
144 #define AR8035_ANER_LP_AN_ABLE 0x0001
145 
146 //Auto-Negotiation Next Page Transmit register
147 #define AR8035_ANNPR_NEXT_PAGE 0x8000
148 #define AR8035_ANNPR_MSG_PAGE 0x2000
149 #define AR8035_ANNPR_ACK2 0x1000
150 #define AR8035_ANNPR_TOGGLE 0x0800
151 #define AR8035_ANNPR_MESSAGE 0x07FF
152 
153 //Link Partner Next Page register
154 #define AR8035_ANLPNPR_NEXT_PAGE 0x8000
155 #define AR8035_ANLPNPR_ACK 0x4000
156 #define AR8035_ANLPNPR_MSG_PAGE 0x2000
157 #define AR8035_ANLPNPR_ACK2 0x1000
158 #define AR8035_ANLPNPR_TOGGLE 0x0800
159 #define AR8035_ANLPNPR_MESSAGE 0x07FF
160 
161 //1000BASE-T Control register
162 #define AR8035_GBCR_TEST_MODE 0xE000
163 #define AR8035_GBCR_MS_MAN_CONF_EN 0x1000
164 #define AR8035_GBCR_MS_MAN_CONF_VAL 0x0800
165 #define AR8035_GBCR_PORT_TYPE 0x0400
166 #define AR8035_GBCR_1000BT_FD 0x0200
167 #define AR8035_GBCR_1000BT_HD 0x0100
168 
169 //1000BASE-T Status register
170 #define AR8035_GBSR_MS_CONF_FAULT 0x8000
171 #define AR8035_GBSR_MS_CONF_RES 0x4000
172 #define AR8035_GBSR_LOCAL_RECEIVER_STATUS 0x2000
173 #define AR8035_GBSR_REMOTE_RECEIVER_STATUS 0x1000
174 #define AR8035_GBSR_LP_1000BT_FD 0x0800
175 #define AR8035_GBSR_LP_1000BT_HD 0x0400
176 #define AR8035_GBSR_IDLE_ERR_COUNT 0x00FF
177 
178 //MMD Access Control register
179 #define AR8035_MMDACR_FUNC 0xC000
180 #define AR8035_MMDACR_FUNC_ADDR 0x0000
181 #define AR8035_MMDACR_FUNC_DATA_NO_POST_INC 0x4000
182 #define AR8035_MMDACR_FUNC_DATA_POST_INC_RW 0x8000
183 #define AR8035_MMDACR_FUNC_DATA_POST_INC_W 0xC000
184 #define AR8035_MMDACR_DEVAD 0x001F
185 
186 //Extended Status register
187 #define AR8035_GBESR_1000BX_FD 0x8000
188 #define AR8035_GBESR_1000BX_HD 0x4000
189 #define AR8035_GBESR_1000BT_FD 0x2000
190 #define AR8035_GBESR_1000BT_HD 0x1000
191 
192 //Function Control register
193 #define AR8035_FUNC_CTRL_ASSERT_CRS_ON_TX 0x0800
194 #define AR8035_FUNC_CTRL_MDIX_MODE 0x0060
195 #define AR8035_FUNC_CTRL_MDIX_MODE_MANUAL_MDI 0x0000
196 #define AR8035_FUNC_CTRL_MDIX_MODE_MANUAL_MDIX 0x0020
197 #define AR8035_FUNC_CTRL_MDIX_MODE_AUTO 0x0060
198 #define AR8035_FUNC_CTRL_SQE_TEST 0x0004
199 #define AR8035_FUNC_CTRL_POLARITY_REVERSAL 0x0002
200 #define AR8035_FUNC_CTRL_JABBER_DIS 0x0001
201 
202 //PHY-Specific Status register
203 #define AR8035_PHY_STATUS_SPEED 0xC000
204 #define AR8035_PHY_STATUS_SPEED_10MBPS 0x0000
205 #define AR8035_PHY_STATUS_SPEED_100MBPS 0x4000
206 #define AR8035_PHY_STATUS_SPEED_1000MBPS 0x8000
207 #define AR8035_PHY_STATUS_DUPLEX 0x2000
208 #define AR8035_PHY_STATUS_PAGE_RECEIVED 0x1000
209 #define AR8035_PHY_STATUS_SPEED_DUPLEX_RESOLVED 0x0800
210 #define AR8035_PHY_STATUS_LINK 0x0400
211 #define AR8035_PHY_STATUS_MDI_CROSSOVER_STATUS 0x0040
212 #define AR8035_PHY_STATUS_WIRESPEED_DOWNGRADE 0x0020
213 #define AR8035_PHY_STATUS_TX_PAUSE_EN 0x0008
214 #define AR8035_PHY_STATUS_RX_PAUSE_EN 0x0004
215 #define AR8035_PHY_STATUS_POLARITY 0x0002
216 #define AR8035_PHY_STATUS_JABBER 0x0001
217 
218 //Interrupt Enable Register register
219 #define AR8035_INT_EN_AN_ERROR 0x8000
220 #define AR8035_INT_EN_SPEED_CHANGED 0x4000
221 #define AR8035_INT_EN_DUPLEX_CHANGED 0x2000
222 #define AR8035_INT_EN_PAGE_RECEIVED 0x1000
223 #define AR8035_INT_EN_LINK_FAIL 0x0800
224 #define AR8035_INT_EN_LINK_SUCCESS 0x0400
225 #define AR8035_INT_EN_WIRESPEED_DOWNGRADE 0x0020
226 #define AR8035_INT_EN_POLARITY_CHANGED 0x0002
227 #define AR8035_INT_EN_WOL_PTP 0x0001
228 
229 //Interrupt Status register
230 #define AR8035_INT_STATUS_AN_ERROR 0x8000
231 #define AR8035_INT_STATUS_SPEED_CHANGED 0x4000
232 #define AR8035_INT_STATUS_DUPLEX_CHANGED 0x2000
233 #define AR8035_INT_STATUS_PAGE_RECEIVED 0x1000
234 #define AR8035_INT_STATUS_LINK_FAIL 0x0800
235 #define AR8035_INT_STATUS_LINK_SUCCESS 0x0400
236 #define AR8035_INT_STATUS_WIRESPEED_DOWNGRADE 0x0020
237 #define AR8035_INT_STATUS_POLARITY_CHANGED 0x0002
238 #define AR8035_INT_STATUS_WOL_PTP 0x0001
239 
240 //Smart Speed register
241 #define AR8035_SMART_SPEED_EN 0x0020
242 #define AR8035_SMART_SPEED_RETRY_LIMIT 0x001C
243 #define AR8035_SMART_SPEED_BYPASS_TIMER 0x0002
244 
245 //Cable Diagnostic Tester (CDT) Control register
246 #define AR8035_CDT_CTRL_MDI_PAIR_SELECT 0x0300
247 #define AR8035_CDT_CTRL_TEST_EN 0x0001
248 
249 //LED Control register
250 #define AR8035_LED_CTRL_LED_ON_TIME 0x7000
251 #define AR8035_LED_CTRL_LED_OFF_TIME 0x0700
252 
253 //Cable Diagnostic Tester Status register
254 #define AR8035_CDT_STATUS_STATUS 0x0300
255 #define AR8035_CDT_STATUS_DELTA_TIME 0x00FF
256 
257 //C++ guard
258 #ifdef __cplusplus
259 extern "C" {
260 #endif
261 
262 //AR8035 Ethernet PHY driver
263 extern const PhyDriver ar8035PhyDriver;
264 
265 //AR8035 related functions
266 error_t ar8035Init(NetInterface *interface);
267 
268 void ar8035Tick(NetInterface *interface);
269 
270 void ar8035EnableIrq(NetInterface *interface);
271 void ar8035DisableIrq(NetInterface *interface);
272 
273 void ar8035EventHandler(NetInterface *interface);
274 
275 void ar8035WritePhyReg(NetInterface *interface, uint8_t address,
276  uint16_t data);
277 
278 uint16_t ar8035ReadPhyReg(NetInterface *interface, uint8_t address);
279 
280 void ar8035DumpPhyReg(NetInterface *interface);
281 
282 //C++ guard
283 #ifdef __cplusplus
284 }
285 #endif
286 
287 #endif
uint8_t data[]
Definition: ethernet.h:209
error_t ar8035Init(NetInterface *interface)
AR8035 PHY transceiver initialization.
Definition: ar8035_driver.c:60
Ethernet PHY driver.
Definition: nic.h:292
void ar8035EventHandler(NetInterface *interface)
AR8035 event handler.
void ar8035EnableIrq(NetInterface *interface)
Enable interrupts.
error_t
Error codes.
Definition: error.h:42
void ar8035DumpPhyReg(NetInterface *interface)
Dump PHY registers for debugging purpose.
#define NetInterface
Definition: net.h:36
void ar8035WritePhyReg(NetInterface *interface, uint8_t address, uint16_t data)
Write PHY register.
void ar8035Tick(NetInterface *interface)
AR8035 timer handler.
uint16_t ar8035ReadPhyReg(NetInterface *interface, uint8_t address)
Read PHY register.
Network interface controller abstraction layer.
void ar8035DisableIrq(NetInterface *interface)
Disable interrupts.
Ipv6Addr address
const PhyDriver ar8035PhyDriver
AR8035 Ethernet PHY driver.
Definition: ar8035_driver.c:44