rtl8201_driver.h
Go to the documentation of this file.
1 /**
2  * @file rtl8201_driver.h
3  * @brief RTL8201 Gigabit 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 _RTL8201_DRIVER_H
32 #define _RTL8201_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //PHY address
38 #ifndef RTL8201_PHY_ADDR
39  #define RTL8201_PHY_ADDR 1
40 #elif (RTL8201_PHY_ADDR < 0 || RTL8201_PHY_ADDR > 31)
41  #error RTL8201_PHY_ADDR parameter is not valid
42 #endif
43 
44 //RTL8201 PHY registers
45 #define RTL8201_BMCR 0x00
46 #define RTL8201_BMSR 0x01
47 #define RTL8201_PHYID1 0x02
48 #define RTL8201_PHYID2 0x03
49 #define RTL8201_ANAR 0x04
50 #define RTL8201_ANLPAR 0x05
51 #define RTL8201_ANER 0x06
52 #define RTL8201_MACR 0x0D
53 #define RTL8201_MAADR 0x0E
54 #define RTL8201_PSMR 0x18
55 #define RTL8201_FMLR 0x1C
56 #define RTL8201_IISDR 0x1E
57 #define RTL8201_PDR 0x1F
58 
59 //RTL8201 Extended registers (page 4)
60 #define RTL8201_EEECER 0x10
61 #define RTL8201_EEECR 0x15
62 
63 //RTL8201 Extended registers (page 7)
64 #define RTL8201_RMSR 0x10
65 #define RTL8201_CLSR 0x11
66 #define RTL8201_EEELER 0x12
67 #define RTL8201_IWELFR 0x13
68 #define RTL8201_MTIR 0x14
69 #define RTL8201_SSCR 0x18
70 
71 //RTL8201 MMD registers
72 #define RTL8201_EEEPC1R 0x03, 0x00
73 #define RTL8201_EEEPS1R 0x03, 0x01
74 #define RTL8201_EEECR2 0x03, 0x14
75 #define RTL8201_EEEWER 0x03, 0x16
76 #define RTL8201_EEEAR 0x07, 0x3C
77 #define RTL8201_EEELPAR 0x07, 0x3D
78 
79 //Basic Mode Control register
80 #define RTL8201_BMCR_RESET 0x8000
81 #define RTL8201_BMCR_LOOPBACK 0x4000
82 #define RTL8201_BMCR_SPEED_SEL_LSB 0x2000
83 #define RTL8201_BMCR_AN_EN 0x1000
84 #define RTL8201_BMCR_POWER_DOWN 0x0800
85 #define RTL8201_BMCR_ISOLATE 0x0400
86 #define RTL8201_BMCR_RESTART_AN 0x0200
87 #define RTL8201_BMCR_DUPLEX_MODE 0x0100
88 #define RTL8201_BMCR_COL_TEST 0x0080
89 #define RTL8201_BMCR_SPEED_SEL_MSB 0x0040
90 
91 //Basic Mode Status register
92 #define RTL8201_BMSR_100BT4 0x8000
93 #define RTL8201_BMSR_100BTX_FD 0x4000
94 #define RTL8201_BMSR_100BTX_HD 0x2000
95 #define RTL8201_BMSR_10BT_FD 0x1000
96 #define RTL8201_BMSR_10BT_HD 0x0800
97 #define RTL8201_BMSR_MF_PREAMBLE_SUPPR 0x0040
98 #define RTL8201_BMSR_AN_COMPLETE 0x0020
99 #define RTL8201_BMSR_REMOTE_FAULT 0x0010
100 #define RTL8201_BMSR_AN_CAPABLE 0x0008
101 #define RTL8201_BMSR_LINK_STATUS 0x0004
102 #define RTL8201_BMSR_JABBER_DETECT 0x0002
103 #define RTL8201_BMSR_EXTENDED_CAPABLE 0x0001
104 
105 //PHY Identifier 1 register
106 #define RTL8201_PHYID1_OUI_MSB 0xFFFF
107 #define RTL8201_PHYID1_OUI_MSB_DEFAULT 0x001C
108 
109 //PHY Identifier 2 register
110 #define RTL8201_PHYID2_OUI_LSB 0xFC00
111 #define RTL8201_PHYID2_OUI_LSB_DEFAULT 0xC800
112 #define RTL8201_PHYID2_MODEL_NUM 0x03F0
113 #define RTL8201_PHYID2_MODEL_NUM_DEFAULT 0x0010
114 #define RTL8201_PHYID2_REVISION_NUM 0x000F
115 #define RTL8201_PHYID2_REVISION_NUM_DEFAULT 0x0006
116 
117 //Auto-Negotiation Advertisement register
118 #define RTL8201_ANAR_NEXT_PAGE 0x8000
119 #define RTL8201_ANAR_ACK 0x4000
120 #define RTL8201_ANAR_REMOTE_FAULT 0x2000
121 #define RTL8201_ANAR_ASYM_PAUSE 0x0800
122 #define RTL8201_ANAR_PAUSE 0x0400
123 #define RTL8201_ANAR_100BT4 0x0200
124 #define RTL8201_ANAR_100BTX_FD 0x0100
125 #define RTL8201_ANAR_100BTX_HD 0x0080
126 #define RTL8201_ANAR_10BT_FD 0x0040
127 #define RTL8201_ANAR_10BT_HD 0x0020
128 #define RTL8201_ANAR_SELECTOR 0x001F
129 #define RTL8201_ANAR_SELECTOR_DEFAULT 0x0001
130 
131 //Auto-Negotiation Link Partner Ability register
132 #define RTL8201_ANLPAR_NEXT_PAGE 0x8000
133 #define RTL8201_ANLPAR_ACK 0x4000
134 #define RTL8201_ANLPAR_REMOTE_FAULT 0x2000
135 #define RTL8201_ANLPAR_ASYM_PAUSE 0x0800
136 #define RTL8201_ANLPAR_PAUSE 0x0400
137 #define RTL8201_ANLPAR_100BT4 0x0200
138 #define RTL8201_ANLPAR_100BTX_FD 0x0100
139 #define RTL8201_ANLPAR_100BTX_HD 0x0080
140 #define RTL8201_ANLPAR_10BT_FD 0x0040
141 #define RTL8201_ANLPAR_10BT_HD 0x0020
142 #define RTL8201_ANLPAR_SELECTOR 0x001F
143 #define RTL8201_ANLPAR_SELECTOR_DEFAULT 0x0001
144 
145 //Auto-Negotiation Expansion register
146 #define RTL8201_ANER_PAR_DETECT_FAULT 0x0010
147 #define RTL8201_ANER_LP_NEXT_PAGE_ABLE 0x0008
148 #define RTL8201_ANER_NEXT_PAGE_ABLE 0x0004
149 #define RTL8201_ANER_PAGE_RECEIVED 0x0002
150 #define RTL8201_ANER_LP_AN_ABLE 0x0001
151 
152 //MMD Access Control register
153 #define RTL8201_MACR_FUNC 0xC000
154 #define RTL8201_MACR_FUNC_ADDR 0x0000
155 #define RTL8201_MACR_FUNC_DATA_NO_POST_INC 0x4000
156 #define RTL8201_MACR_FUNC_DATA_POST_INC_RW 0x8000
157 #define RTL8201_MACR_FUNC_DATA_POST_INC_W 0xC000
158 #define RTL8201_MACR_DEVAD 0x001F
159 
160 //Power Saving Mode register
161 #define RTL8201_PSMR_EN_PWR_SAVE 0x8000
162 
163 //Fiber Mode and Loopback register
164 #define RTL8201_FMLR_FX_MODE 0x0020
165 #define RTL8201_FMLR_EN_AUTO_MDIX 0x0004
166 #define RTL8201_FMLR_FORCE_MDI 0x0002
167 
168 //Interrupt Indicators and SNR Display register
169 #define RTL8201_IISDR_AN_ERR 0x8000
170 #define RTL8201_IISDR_SPD_CHG 0x4000
171 #define RTL8201_IISDR_DUPLEX_CHG 0x2000
172 #define RTL8201_IISDR_LINK_STATUS_CHG 0x0800
173 #define RTL8201_IISDR_SNR_O 0x000F
174 
175 //Page Select register
176 #define RTL8201_PDR_PAGE_SEL 0x00FF
177 
178 //EEE Capability Enable register
179 #define RTL8201_EEECER_EEE_10_CAP 0x2000
180 #define RTL8201_EEECER_EEE_NWAY_EN 0x1000
181 #define RTL8201_EEECER_TX_QUIET_EN 0x0200
182 #define RTL8201_EEECER_RX_QUIET_EN 0x0100
183 
184 //EEE Capability register
185 #define RTL8201_EEECR_RG_DIS_LDVT 0x1000
186 #define RTL8201_EEECR_EEE_100_CAP 0x0001
187 
188 //RMII Mode Setting register
189 #define RTL8201_RMSR_RG_RMII_CLKDIR 0x1000
190 #define RTL8201_RMSR_RG_RMII_TX_OFFSET 0x0F00
191 #define RTL8201_RMSR_RG_RMII_RX_OFFSET 0x00F0
192 #define RTL8201_RMSR_RG_RMII_RXDV_SEL 0x0004
193 #define RTL8201_RMSR_RG_RMII_RXDSEL 0x0002
194 
195 //Customized LEDs Setting register
196 #define RTL8201_CLSR_LED_SEL1 0x00F0
197 #define RTL8201_CLSR_LED_SEL1_ACT 0x0080
198 #define RTL8201_CLSR_LED_SEL1_LINK_100M 0x0020
199 #define RTL8201_CLSR_LED_SEL1_LINK_10M 0x0010
200 #define RTL8201_CLSR_LED_SEL0 0x000F
201 #define RTL8201_CLSR_LED_SEL0_ACT 0x0008
202 #define RTL8201_CLSR_LED_SEL0_LINK_100M 0x0002
203 #define RTL8201_CLSR_LED_SEL0_LINK_10M 0x0001
204 
205 //EEE LEDs Enable register
206 #define RTL8201_EEELER_EEE_LED_EN1 0x0002
207 #define RTL8201_EEELER_EEE_LED_EN0 0x0001
208 
209 //Interrupt, WOL Enable, and LEDs Function register
210 #define RTL8201_IWELFR_INT_LINK_CHG 0x2000
211 #define RTL8201_IWELFR_INT_DUP_CHG 0x1000
212 #define RTL8201_IWELFR_INT_AN_ERR 0x0800
213 #define RTL8201_IWELFR_RG_LED0_WOL_SEL 0x0400
214 #define RTL8201_IWELFR_LED_SEL 0x0030
215 #define RTL8201_IWELFR_CUSTOMIZED_LED 0x0008
216 #define RTL8201_IWELFR_EN_10M_LPI 0x0001
217 
218 //MII TX Isolate register
219 #define RTL8201_MTIR_RG_TX_ISOLATE_EN 0x8000
220 
221 //Spread Spectrum Clock register
222 #define RTL8201_SSCR_RG_DIS_SSC 0x0001
223 
224 //PCS Control 1 register
225 #define RTL8201_EEEPC1R_CLOCK_STOP_EN 0x0400
226 
227 //PCS Status 1 register
228 #define RTL8201_EEEPS1R_TX_LPI_RCVD 0x0800
229 #define RTL8201_EEEPS1R_RX_LPI_RCVD 0x0400
230 #define RTL8201_EEEPS1R_TX_LPI_IND 0x0200
231 #define RTL8201_EEEPS1R_RX_LPI_IND 0x0100
232 #define RTL8201_EEEPS1R_CLK_STOP_CAPABLE 0x0040
233 
234 //EEE Capability 2 register
235 #define RTL8201_EEECR2_100BTX_EEE 0x0002
236 
237 //EEE Wake Error register
238 #define RTL8201_EEEWER_EEE_WAKE_ERROR_COUNTER 0xFFFF
239 
240 //EEE Advertisement register
241 #define RTL8201_EEEAR_100BTX_EEE 0x0002
242 
243 //EEE Link Partner Ability register
244 #define RTL8201_EEELPAR_LP_100BTX_EEE 0x0002
245 
246 //C++ guard
247 #ifdef __cplusplus
248 extern "C" {
249 #endif
250 
251 //RTL8201 Ethernet PHY driver
252 extern const PhyDriver rtl8201PhyDriver;
253 
254 //RTL8201 related functions
255 error_t rtl8201Init(NetInterface *interface);
256 void rtl8201InitHook(NetInterface *interface);
257 
258 void rtl8201Tick(NetInterface *interface);
259 
260 void rtl8201EnableIrq(NetInterface *interface);
261 void rtl8201DisableIrq(NetInterface *interface);
262 
263 void rtl8201EventHandler(NetInterface *interface);
264 
265 void rtl8201WritePhyReg(NetInterface *interface, uint8_t address,
266  uint16_t data);
267 
268 uint16_t rtl8201ReadPhyReg(NetInterface *interface, uint8_t address);
269 
270 void rtl8201DumpPhyReg(NetInterface *interface);
271 
272 void rtl8201WriteMmdReg(NetInterface *interface, uint8_t devAddr,
273  uint16_t regAddr, uint16_t data);
274 
275 uint16_t rtl8201ReadMmdReg(NetInterface *interface, uint8_t devAddr,
276  uint16_t regAddr);
277 
278 //C++ guard
279 #ifdef __cplusplus
280 }
281 #endif
282 
283 #endif
Ethernet PHY driver.
Definition: nic.h:311
uint8_t data[]
Definition: ethernet.h:222
void rtl8201Tick(NetInterface *interface)
RTL8201 timer handler.
void rtl8201EnableIrq(NetInterface *interface)
Enable interrupts.
error_t rtl8201Init(NetInterface *interface)
RTL8201 PHY transceiver initialization.
void rtl8201DumpPhyReg(NetInterface *interface)
Dump PHY registers for debugging purpose.
error_t
Error codes.
Definition: error.h:43
void rtl8201WriteMmdReg(NetInterface *interface, uint8_t devAddr, uint16_t regAddr, uint16_t data)
Write MMD register.
#define NetInterface
Definition: net.h:36
void rtl8201DisableIrq(NetInterface *interface)
Disable interrupts.
void rtl8201EventHandler(NetInterface *interface)
RTL8201 event handler.
const PhyDriver rtl8201PhyDriver
RTL8201 Ethernet PHY driver.
uint16_t regAddr
Ipv6Addr address[]
Definition: ipv6.h:325
void rtl8201InitHook(NetInterface *interface)
RTL8201 custom configuration.
Network interface controller abstraction layer.
void rtl8201WritePhyReg(NetInterface *interface, uint8_t address, uint16_t data)
Write PHY register.
uint16_t rtl8201ReadPhyReg(NetInterface *interface, uint8_t address)
Read PHY register.
uint16_t rtl8201ReadMmdReg(NetInterface *interface, uint8_t devAddr, uint16_t regAddr)
Read MMD register.