ksz9131_driver.h
Go to the documentation of this file.
1 /**
2  * @file ksz9131_driver.h
3  * @brief KSZ9131 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 _KSZ9131_DRIVER_H
32 #define _KSZ9131_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //PHY address
38 #ifndef KSZ9131_PHY_ADDR
39  #define KSZ9131_PHY_ADDR 3
40 #elif (KSZ9131_PHY_ADDR < 0 || KSZ9131_PHY_ADDR > 31)
41  #error KSZ9131_PHY_ADDR parameter is not valid
42 #endif
43 
44 //KSZ9131 PHY registers
45 #define KSZ9131_BMCR 0x00
46 #define KSZ9131_BMSR 0x01
47 #define KSZ9131_PHYID1 0x02
48 #define KSZ9131_PHYID2 0x03
49 #define KSZ9131_ANAR 0x04
50 #define KSZ9131_ANLPAR 0x05
51 #define KSZ9131_ANER 0x06
52 #define KSZ9131_ANNPTR 0x07
53 #define KSZ9131_ANNPRR 0x08
54 #define KSZ9131_GBCR 0x09
55 #define KSZ9131_GBSR 0x0A
56 #define KSZ9131_MMDACR 0x0D
57 #define KSZ9131_MMDAADR 0x0E
58 #define KSZ9131_GBESR 0x0F
59 #define KSZ9131_RLB 0x11
60 #define KSZ9131_LINKMD 0x12
61 #define KSZ9131_DPMAPCSS 0x13
62 #define KSZ9131_RXERCTR 0x15
63 #define KSZ9131_LED_MODE_SEL 0x16
64 #define KSZ9131_LED_BEHAVIOR 0x17
65 #define KSZ9131_MDIO_DRIVE 0x19
66 #define KSZ9131_LEGACY_LED_MODE 0x1A
67 #define KSZ9131_ICSR 0x1B
68 #define KSZ9131_AUTOMDI 0x1C
69 #define KSZ9131_SPDC 0x1D
70 #define KSZ9131_EXT_LOOPBACK 0x1E
71 #define KSZ9131_PHYCON 0x1F
72 
73 //KSZ9131 MMD registers
74 #define KSZ9131_MEAN_SLICER_ERROR 0x01, 0xE1
75 #define KSZ9131_DCQ_MEAN_SQUARE_ERROR 0x01, 0xE2
76 #define KSZ9131_DCQ_MEAN_SQUARE_ERROR_WORST_CASE 0x01, 0xE3
77 #define KSZ9131_DCQ_SQI 0x01, 0xE4
78 #define KSZ9131_DCQ_PEAK_MSE 0x01, 0xE5
79 #define KSZ9131_DCQ_CTRL 0x01, 0xE6
80 #define KSZ9131_DCQ_CONFIG 0x01, 0xE7
81 #define KSZ9131_DCQ_SQI_TABLE 0x01, 0xE8
82 #define KSZ9131_COMMON_CTRL 0x02, 0x00
83 #define KSZ9131_STRAP_STAT 0x02, 0x01
84 #define KSZ9131_OP_MODE_STRAP_OVERRIDE 0x02, 0x02
85 #define KSZ9131_OP_MODE_STRAP 0x02, 0x03
86 #define KSZ9131_CLOCK_INV_CTRL_SIGNAL_PAD_SKEW 0x02, 0x04
87 #define KSZ9131_RGMII_RX_DATA_PAD_SKEW 0x02, 0x05
88 #define KSZ9131_RGMII_TX_DATA_PAD_SKEW 0x02, 0x06
89 #define KSZ9131_CLK_PAD_SKEW 0x02, 0x08
90 #define KSZ9131_SELF_TEST_PKT_COUNT_LO 0x02, 0x09
91 #define KSZ9131_SELF_TEST_PKT_COUNT_HI 0x02, 0x0A
92 #define KSZ9131_SELF_TEST_STAT 0x02, 0x0B
93 #define KSZ9131_SELF_TEST_FRAME_COUNT_EN 0x02, 0x0C
94 #define KSZ9131_SELF_TEST_PGEN_EN 0x02, 0x0D
95 #define KSZ9131_SELF_TEST_EN 0x02, 0x0E
96 #define KSZ9131_WOL_CTRL 0x02, 0x10
97 #define KSZ9131_WOL_MAC_LO 0x02, 0x11
98 #define KSZ9131_WOL_MAC_MI 0x02, 0x12
99 #define KSZ9131_WOL_MAC_HI 0x02, 0x13
100 #define KSZ9131_CUSTOM_PKT0_CRC_LO 0x02, 0x14
101 #define KSZ9131_CUSTOM_PKT0_CRC_HI 0x02, 0x15
102 #define KSZ9131_CUSTOM_PKT1_CRC_LO 0x02, 0x16
103 #define KSZ9131_CUSTOM_PKT1_CRC_HI 0x02, 0x17
104 #define KSZ9131_CUSTOM_PKT2_CRC_LO 0x02, 0x18
105 #define KSZ9131_CUSTOM_PKT2_CRC_HI 0x02, 0x19
106 #define KSZ9131_CUSTOM_PKT3_CRC_LO 0x02, 0x1A
107 #define KSZ9131_CUSTOM_PKT3_CRC_HI 0x02, 0x1B
108 #define KSZ9131_CUSTOM_PKT0_MASK_LL 0x02, 0x1C
109 #define KSZ9131_CUSTOM_PKT0_MASK_LH 0x02, 0x1D
110 #define KSZ9131_CUSTOM_PKT0_MASK_HL 0x02, 0x1E
111 #define KSZ9131_CUSTOM_PKT0_MASK_HH 0x02, 0x1F
112 #define KSZ9131_CUSTOM_PKT1_MASK_LL 0x02, 0x20
113 #define KSZ9131_CUSTOM_PKT1_MASK_LH 0x02, 0x21
114 #define KSZ9131_CUSTOM_PKT1_MASK_HL 0x02, 0x22
115 #define KSZ9131_CUSTOM_PKT1_MASK_HH 0x02, 0x23
116 #define KSZ9131_CUSTOM_PKT2_MASK_LL 0x02, 0x24
117 #define KSZ9131_CUSTOM_PKT2_MASK_LH 0x02, 0x25
118 #define KSZ9131_CUSTOM_PKT2_MASK_HL 0x02, 0x26
119 #define KSZ9131_CUSTOM_PKT2_MASK_HH 0x02, 0x27
120 #define KSZ9131_CUSTOM_PKT3_MASK_LL 0x02, 0x28
121 #define KSZ9131_CUSTOM_PKT3_MASK_LH 0x02, 0x29
122 #define KSZ9131_CUSTOM_PKT3_MASK_HL 0x02, 0x2A
123 #define KSZ9131_CUSTOM_PKT3_MASK_HH 0x02, 0x2B
124 #define KSZ9131_WOL_CTRL_STAT 0x02, 0x2C
125 #define KSZ9131_WOL_CUSTOM_PKT_RECEIVE_STAT 0x02, 0x2D
126 #define KSZ9131_WOL_MAGIC_PKT_RECEIVE_STAT 0x02, 0x2E
127 #define KSZ9131_WOL_DATA_MODULE_STAT 0x02, 0x2F
128 #define KSZ9131_CUSTOM_PKT0_RCVD_CRC_L 0x02, 0x30
129 #define KSZ9131_CUSTOM_PKT0_RCVD_CRC_H 0x02, 0x31
130 #define KSZ9131_CUSTOM_PKT1_RCVD_CRC_L 0x02, 0x32
131 #define KSZ9131_CUSTOM_PKT1_RCVD_CRC_H 0x02, 0x33
132 #define KSZ9131_CUSTOM_PKT2_RCVD_CRC_L 0x02, 0x34
133 #define KSZ9131_CUSTOM_PKT2_RCVD_CRC_H 0x02, 0x35
134 #define KSZ9131_CUSTOM_PKT3_RCVD_CRC_L 0x02, 0x36
135 #define KSZ9131_CUSTOM_PKT3_RCVD_CRC_H 0x02, 0x37
136 #define KSZ9131_SELF_TEST_CORRECT_COUNT_LO 0x02, 0x3C
137 #define KSZ9131_SELF_TEST_CORRECT_COUNT_HI 0x02, 0x3D
138 #define KSZ9131_SELF_TEST_ERROR_COUNT_LO 0x02, 0x3E
139 #define KSZ9131_SELF_TEST_ERROR_COUNT_HI 0x02, 0x3F
140 #define KSZ9131_SELF_TEST_BAD_SFD_COUNT_LO 0x02, 0x40
141 #define KSZ9131_SELF_TEST_BAD_SFD_COUNT_HI 0x02, 0x41
142 #define KSZ9131_RX_DLL_CTRL 0x02, 0x4C
143 #define KSZ9131_TX_DLL_CTRL 0x02, 0x4D
144 #define KSZ9131_PCS_CTRL1 0x03, 0x00
145 #define KSZ9131_PCS_STAT1 0x03, 0x01
146 #define KSZ9131_EEE_QUIET_TIMER 0x03, 0x08
147 #define KSZ9131_EEE_UPDATE_TIMER 0x03, 0x09
148 #define KSZ9131_EEE_LINK_FAIL_TIMER 0x03, 0x0A
149 #define KSZ9131_EEE_POST_UPDATE_TIMER 0x03, 0x0B
150 #define KSZ9131_EEE_WAIT_WQ_TIMER 0x03, 0x0C
151 #define KSZ9131_EEE_WAKE_TIMER 0x03, 0x0D
152 #define KSZ9131_EEE_WAKE_TX_TIMER 0x03, 0x0E
153 #define KSZ9131_EEE_WAKE_MZ_TIMER 0x03, 0x0F
154 #define KSZ9131_EEE_CTRL_CAPABILITY 0x03, 0x14
155 #define KSZ9131_EEE_WAKE_ERROR_COUNTER 0x03, 0x16
156 #define KSZ9131_EEE_100_TIMER0 0x03, 0x18
157 #define KSZ9131_EEE_100_TIMER1 0x03, 0x19
158 #define KSZ9131_EEE_100_TIMER2 0x03, 0x1A
159 #define KSZ9131_EEE_100_TIMER3 0x03, 0x1B
160 #define KSZ9131_EEE_ADV 0x07, 0x3C
161 #define KSZ9131_EEE_LP_ABILITY 0x07, 0x3D
162 #define KSZ9131_EEE_LP_ABILITY_OVERRIDE 0x07, 0x3E
163 #define KSZ9131_EEE_MSG_CODE 0x07, 0x3F
164 #define KSZ9131_XTAL_CTRL 0x1C, 0x01
165 #define KSZ9131_AFED_CTRL 0x1C, 0x09
166 #define KSZ9131_LDO_CTRL 0x1C, 0x0E
167 #define KSZ9131_EDPD_CTRL 0x1C, 0x24
168 #define KSZ9131_EMITX_CTRL 0x1C, 0x25
169 #define KSZ9131_EMITX_COEFF 0x1C, 0x26
170 #define KSZ9131_MMD31_REG19 0x1F, 0x13
171 
172 //Basic Control register
173 #define KSZ9131_BMCR_RESET 0x8000
174 #define KSZ9131_BMCR_LOOPBACK 0x4000
175 #define KSZ9131_BMCR_SPEED_SEL_LSB 0x2000
176 #define KSZ9131_BMCR_AN_EN 0x1000
177 #define KSZ9131_BMCR_POWER_DOWN 0x0800
178 #define KSZ9131_BMCR_ISOLATE 0x0400
179 #define KSZ9131_BMCR_RESTART_AN 0x0200
180 #define KSZ9131_BMCR_DUPLEX_MODE 0x0100
181 #define KSZ9131_BMCR_COL_TEST 0x0080
182 #define KSZ9131_BMCR_SPEED_SEL_MSB 0x0040
183 
184 //Basic Status register
185 #define KSZ9131_BMSR_100BT4 0x8000
186 #define KSZ9131_BMSR_100BTX_FD 0x4000
187 #define KSZ9131_BMSR_100BTX_HD 0x2000
188 #define KSZ9131_BMSR_10BT_FD 0x1000
189 #define KSZ9131_BMSR_10BT_HD 0x0800
190 #define KSZ9131_BMSR_100BT2_FD 0x0400
191 #define KSZ9131_BMSR_100BT2_HD 0x0200
192 #define KSZ9131_BMSR_EXTENDED_STATUS 0x0100
193 #define KSZ9131_BMSR_UNIDIRECTIONAL_ABLE 0x0080
194 #define KSZ9131_BMSR_MF_PREAMBLE_SUPPR 0x0040
195 #define KSZ9131_BMSR_AN_COMPLETE 0x0020
196 #define KSZ9131_BMSR_REMOTE_FAULT 0x0010
197 #define KSZ9131_BMSR_AN_CAPABLE 0x0008
198 #define KSZ9131_BMSR_LINK_STATUS 0x0004
199 #define KSZ9131_BMSR_JABBER_DETECT 0x0002
200 #define KSZ9131_BMSR_EXTENDED_CAPABLE 0x0001
201 
202 //PHY Identifier 1 register
203 #define KSZ9131_PHYID1_PHY_ID_MSB 0xFFFF
204 #define KSZ9131_PHYID1_PHY_ID_MSB_DEFAULT 0x0022
205 
206 //PHY Identifier 2 register
207 #define KSZ9131_PHYID2_PHY_ID_LSB 0xFC00
208 #define KSZ9131_PHYID2_PHY_ID_LSB_DEFAULT 0x1400
209 #define KSZ9131_PHYID2_MODEL_NUM 0x03F0
210 #define KSZ9131_PHYID2_MODEL_NUM_DEFAULT 0x0240
211 #define KSZ9131_PHYID2_REVISION_NUM 0x000F
212 
213 //Auto-Negotiation Advertisement register
214 #define KSZ9131_ANAR_NEXT_PAGE 0x8000
215 #define KSZ9131_ANAR_REMOTE_FAULT 0x2000
216 #define KSZ9131_ANAR_EXTENDED_NEXT_PAGE 0x1000
217 #define KSZ9131_ANAR_ASYM_PAUSE 0x0800
218 #define KSZ9131_ANAR_SYM_PAUSE 0x0400
219 #define KSZ9131_ANAR_100BT4 0x0200
220 #define KSZ9131_ANAR_100BTX_FD 0x0100
221 #define KSZ9131_ANAR_100BTX_HD 0x0080
222 #define KSZ9131_ANAR_10BT_FD 0x0040
223 #define KSZ9131_ANAR_10BT_HD 0x0020
224 #define KSZ9131_ANAR_SELECTOR 0x001F
225 #define KSZ9131_ANAR_SELECTOR_DEFAULT 0x0001
226 
227 //Auto-Negotiation Link Partner Ability register
228 #define KSZ9131_ANLPAR_NEXT_PAGE 0x8000
229 #define KSZ9131_ANLPAR_ACK 0x4000
230 #define KSZ9131_ANLPAR_REMOTE_FAULT 0x2000
231 #define KSZ9131_ANLPAR_EXTENDED_NEXT_PAGE 0x1000
232 #define KSZ9131_ANLPAR_ASYM_PAUSE 0x0800
233 #define KSZ9131_ANLPAR_PAUSE 0x0400
234 #define KSZ9131_ANLPAR_100BT4 0x0200
235 #define KSZ9131_ANLPAR_100BTX_FD 0x0100
236 #define KSZ9131_ANLPAR_100BTX_HD 0x0080
237 #define KSZ9131_ANLPAR_10BT_FD 0x0040
238 #define KSZ9131_ANLPAR_10BT_HD 0x0020
239 #define KSZ9131_ANLPAR_SELECTOR 0x001F
240 #define KSZ9131_ANLPAR_SELECTOR_DEFAULT 0x0001
241 
242 //Auto-Negotiation Expansion register
243 #define KSZ9131_ANER_RECEIVE_NP_LOC_ABLE 0x0040
244 #define KSZ9131_ANER_RECEIVE_NP_STOR_LOC 0x0020
245 #define KSZ9131_ANER_PAR_DETECT_FAULT 0x0010
246 #define KSZ9131_ANER_LP_NEXT_PAGE_ABLE 0x0008
247 #define KSZ9131_ANER_NEXT_PAGE_ABLE 0x0004
248 #define KSZ9131_ANER_PAGE_RECEIVED 0x0002
249 #define KSZ9131_ANER_LP_AN_ABLE 0x0001
250 
251 //Auto-Negotiation Next Page TX register
252 #define KSZ9131_ANNPTR_NEXT_PAGE 0x8000
253 #define KSZ9131_ANNPTR_MSG_PAGE 0x2000
254 #define KSZ9131_ANNPTR_ACK2 0x1000
255 #define KSZ9131_ANNPTR_TOGGLE 0x0800
256 #define KSZ9131_ANNPTR_MESSAGE 0x07FF
257 
258 //Auto-Negotiation Next Page RX register
259 #define KSZ9131_ANNPRR_NEXT_PAGE 0x8000
260 #define KSZ9131_ANNPRR_ACK 0x4000
261 #define KSZ9131_ANNPRR_MSG_PAGE 0x2000
262 #define KSZ9131_ANNPRR_ACK2 0x1000
263 #define KSZ9131_ANNPRR_TOGGLE 0x0800
264 #define KSZ9131_ANNPRR_MESSAGE 0x07FF
265 
266 //Auto-Negotiation Master Slave Control register
267 #define KSZ9131_GBCR_TEST_MODE 0xE000
268 #define KSZ9131_GBCR_MS_MAN_CONF_EN 0x1000
269 #define KSZ9131_GBCR_MS_MAN_CONF_VAL 0x0800
270 #define KSZ9131_GBCR_PORT_TYPE 0x0400
271 #define KSZ9131_GBCR_1000BT_FD 0x0200
272 #define KSZ9131_GBCR_1000BT_HD 0x0100
273 
274 //Auto-Negotiation Master Slave Status register
275 #define KSZ9131_GBSR_MS_CONF_FAULT 0x8000
276 #define KSZ9131_GBSR_MS_CONF_RES 0x4000
277 #define KSZ9131_GBSR_LOCAL_RECEIVER_STATUS 0x2000
278 #define KSZ9131_GBSR_REMOTE_RECEIVER_STATUS 0x1000
279 #define KSZ9131_GBSR_LP_1000BT_FD 0x0800
280 #define KSZ9131_GBSR_LP_1000BT_HD 0x0400
281 #define KSZ9131_GBSR_IDLE_ERR_COUNT 0x00FF
282 
283 //MMD Access Control register
284 #define KSZ9131_MMDACR_FUNC 0xC000
285 #define KSZ9131_MMDACR_FUNC_ADDR 0x0000
286 #define KSZ9131_MMDACR_FUNC_DATA_NO_POST_INC 0x4000
287 #define KSZ9131_MMDACR_FUNC_DATA_POST_INC_RW 0x8000
288 #define KSZ9131_MMDACR_FUNC_DATA_POST_INC_W 0xC000
289 #define KSZ9131_MMDACR_DEVAD 0x001F
290 
291 //Extended Status register
292 #define KSZ9131_GBESR_1000BX_FD 0x8000
293 #define KSZ9131_GBESR_1000BX_HD 0x4000
294 #define KSZ9131_GBESR_1000BT_FD 0x2000
295 #define KSZ9131_GBESR_1000BT_HD 0x1000
296 
297 //Remote Loopback register
298 #define KSZ9131_RLB_REMOTE_LOOPBACK 0x0100
299 
300 //LinkMD Cable Diagnostic register
301 #define KSZ9131_LINKMD_TEST_EN 0x8000
302 #define KSZ9131_LINKMD_TX_DIS 0x4000
303 #define KSZ9131_LINKMD_PAIR 0x3000
304 #define KSZ9131_LINKMD_PAIR_A 0x0000
305 #define KSZ9131_LINKMD_PAIR_B 0x1000
306 #define KSZ9131_LINKMD_PAIR_C 0x2000
307 #define KSZ9131_LINKMD_PAIR_D 0x3000
308 #define KSZ9131_LINKMD_SEL 0x0C00
309 #define KSZ9131_LINKMD_STATUS 0x0300
310 #define KSZ9131_LINKMD_STATUS_NORMAL 0x0000
311 #define KSZ9131_LINKMD_STATUS_OPEN 0x0100
312 #define KSZ9131_LINKMD_STATUS_SHORT 0x0200
313 #define KSZ9131_LINKMD_STATUS_TEST_FAILED 0x0300
314 #define KSZ9131_LINKMD_FAULT_DATA 0x00FF
315 
316 //Digital PMA/PCS Status register
317 #define KSZ9131_DPMAPCSS_1000BT_LINK_STATUS 0x0002
318 #define KSZ9131_DPMAPCSS_100BTX_LINK_STATUS 0x0001
319 
320 //LED Mode Select register
321 #define KSZ9131_LED_MODE_SEL_LED2_CONFIG 0x00F0
322 #define KSZ9131_LED_MODE_SEL_LED1_CONFIG 0x000F
323 
324 //LED Behavior register
325 #define KSZ9131_LED_BEHAVIOR_LED_ACT_OUT_SEL 0x4000
326 #define KSZ9131_LED_BEHAVIOR_LED_PULSING_EN 0x1000
327 #define KSZ9131_LED_BEHAVIOR_LED_BLINK_RATE 0x0C00
328 #define KSZ9131_LED_BEHAVIOR_LED_BLINK_RATE_2_5HZ 0x0000
329 #define KSZ9131_LED_BEHAVIOR_LED_BLINK_RATE_5HZ 0x0400
330 #define KSZ9131_LED_BEHAVIOR_LED_BLINK_RATE_10HZ 0x0800
331 #define KSZ9131_LED_BEHAVIOR_LED_BLINK_RATE_20HZ 0x0C00
332 #define KSZ9131_LED_BEHAVIOR_LED_PULSE_STRECH_EN 0x0060
333 #define KSZ9131_LED_BEHAVIOR_LED_PULSE_STRECH_EN_LED2 0x0040
334 #define KSZ9131_LED_BEHAVIOR_LED_PULSE_STRECH_EN_LED1 0x0020
335 #define KSZ9131_LED_BEHAVIOR_LED_COMBINATION_DIS 0x0003
336 #define KSZ9131_LED_BEHAVIOR_LED_COMBINATION_DIS_LED2 0x0002
337 #define KSZ9131_LED_BEHAVIOR_LED_COMBINATION_DIS_LED1 0x0001
338 
339 //MDIO Drive register
340 #define KSZ9131_MDIO_DRIVE_MDIO_DRIVE 0x0002
341 
342 //KSZ9031 LED Mode register
343 #define KSZ9131_LEGACY_LED_MODE_KSZ9031_LED_MODE 0x4000
344 
345 //Interrupt Control/Status register
346 #define KSZ9131_ICSR_JABBER_IE 0x8000
347 #define KSZ9131_ICSR_RECEIVE_ERROR_IE 0x4000
348 #define KSZ9131_ICSR_PAGE_RECEIVED_IE 0x2000
349 #define KSZ9131_ICSR_PAR_DETECT_FAULT_IE 0x1000
350 #define KSZ9131_ICSR_LP_ACK_IE 0x0800
351 #define KSZ9131_ICSR_LINK_DOWN_IE 0x0400
352 #define KSZ9131_ICSR_REMOTE_FAULT_IE 0x0200
353 #define KSZ9131_ICSR_LINK_UP_IE 0x0100
354 #define KSZ9131_ICSR_JABBER_IF 0x0080
355 #define KSZ9131_ICSR_RECEIVE_ERROR_IF 0x0040
356 #define KSZ9131_ICSR_PAGE_RECEIVED_IF 0x0020
357 #define KSZ9131_ICSR_PAR_DETECT_FAULT_IF 0x0010
358 #define KSZ9131_ICSR_LP_ACK_IF 0x0008
359 #define KSZ9131_ICSR_LINK_DOWN_IF 0x0004
360 #define KSZ9131_ICSR_REMOTE_FAULT_IF 0x0002
361 #define KSZ9131_ICSR_LINK_UP_IF 0x0001
362 
363 //Auto MDI/MDI-X register
364 #define KSZ9131_AUTOMDI_MDI_SET 0x0080
365 #define KSZ9131_AUTOMDI_SWAP_OFF 0x0040
366 
367 //Software Power Down Control register
368 #define KSZ9131_SPDC_CLK_GATE_OVERRIDE 0x0800
369 #define KSZ9131_SPDC_PLL_DIS 0x0400
370 #define KSZ9131_SPDC_IO_DC_TEST_EN 0x0080
371 #define KSZ9131_SPDC_VOH 0x0040
372 
373 //External Loopback register
374 #define KSZ9131_EXT_LOOPBACK_EXT_LPBK 0x0008
375 
376 //Control register
377 #define KSZ9131_PHYCON_INT_POL_INVERT 0x4000
378 #define KSZ9131_PHYCON_JABBER_EN 0x0200
379 #define KSZ9131_PHYCON_SQE_TEST_EN 0x0100
380 #define KSZ9131_PHYCON_SPEED_1000BT 0x0040
381 #define KSZ9131_PHYCON_SPEED_100BTX 0x0020
382 #define KSZ9131_PHYCON_SPEED_10BT 0x0010
383 #define KSZ9131_PHYCON_DUPLEX_STATUS 0x0008
384 #define KSZ9131_PHYCON_1000BT_MS_STATUS 0x0004
385 #define KSZ9131_PHYCON_SOFT_RESET 0x0002
386 #define KSZ9131_PHYCON_LINK_STATUS_CHECK_FAIL 0x0001
387 
388 //RX DLL Control register
389 #define KSZ9131_RX_DLL_CTRL_RXDLL_TUNE_DIS 0x4000
390 #define KSZ9131_RX_DLL_CTRL_RXDLL_RESET 0x2000
391 #define KSZ9131_RX_DLL_CTRL_BYPASS_RXDLL 0x1000
392 #define KSZ9131_RX_DLL_CTRL_RXDLL_TAP_SEL 0x0FC0
393 #define KSZ9131_RX_DLL_CTRL_RXDLL_TAP_SEL_DEFAULT 0x06C0
394 #define KSZ9131_RX_DLL_CTRL_RXDLL_TAP_ADJ 0x003F
395 #define KSZ9131_RX_DLL_CTRL_RXDLL_TAP_ADJ_DEFAULT 0x0011
396 
397 //TX DLL Control register
398 #define KSZ9131_TX_DLL_CTRL_TXDLL_TUNE_DIS 0x4000
399 #define KSZ9131_TX_DLL_CTRL_TXDLL_RESET 0x2000
400 #define KSZ9131_TX_DLL_CTRL_BYPASS_TXDLL 0x1000
401 #define KSZ9131_TX_DLL_CTRL_TXDLL_TAP_SEL 0x0FC0
402 #define KSZ9131_TX_DLL_CTRL_TXDLL_TAP_SEL_DEFAULT 0x0440
403 #define KSZ9131_TX_DLL_CTRL_TXDLL_TAP_ADJ 0x003F
404 #define KSZ9131_TX_DLL_CTRL_TXDLL_TAP_ADJ_DEFAULT 0x0011
405 
406 //C++ guard
407 #ifdef __cplusplus
408 extern "C" {
409 #endif
410 
411 //KSZ9131 Ethernet PHY driver
412 extern const PhyDriver ksz9131PhyDriver;
413 
414 //KSZ9131 related functions
415 error_t ksz9131Init(NetInterface *interface);
416 void ksz9131InitHook(NetInterface *interface);
417 
418 void ksz9131Tick(NetInterface *interface);
419 
420 void ksz9131EnableIrq(NetInterface *interface);
421 void ksz9131DisableIrq(NetInterface *interface);
422 
423 void ksz9131EventHandler(NetInterface *interface);
424 
425 void ksz9131WritePhyReg(NetInterface *interface, uint8_t address,
426  uint16_t data);
427 
428 uint16_t ksz9131ReadPhyReg(NetInterface *interface, uint8_t address);
429 
430 void ksz9131DumpPhyReg(NetInterface *interface);
431 
432 void ksz9131WriteMmdReg(NetInterface *interface, uint8_t devAddr,
433  uint16_t regAddr, uint16_t data);
434 
435 uint16_t ksz9131ReadMmdReg(NetInterface *interface, uint8_t devAddr,
436  uint16_t regAddr);
437 
438 //C++ guard
439 #ifdef __cplusplus
440 }
441 #endif
442 
443 #endif
void ksz9131EnableIrq(NetInterface *interface)
Enable interrupts.
void ksz9131InitHook(NetInterface *interface)
KSZ9131 custom configuration.
Ethernet PHY driver.
Definition: nic.h:311
uint8_t data[]
Definition: ethernet.h:222
void ksz9131WritePhyReg(NetInterface *interface, uint8_t address, uint16_t data)
Write PHY register.
uint16_t ksz9131ReadMmdReg(NetInterface *interface, uint8_t devAddr, uint16_t regAddr)
Read MMD register.
error_t
Error codes.
Definition: error.h:43
const PhyDriver ksz9131PhyDriver
KSZ9131 Ethernet PHY driver.
void ksz9131WriteMmdReg(NetInterface *interface, uint8_t devAddr, uint16_t regAddr, uint16_t data)
Write MMD register.
#define NetInterface
Definition: net.h:36
error_t ksz9131Init(NetInterface *interface)
KSZ9131 PHY transceiver initialization.
void ksz9131DumpPhyReg(NetInterface *interface)
Dump PHY registers for debugging purpose.
void ksz9131EventHandler(NetInterface *interface)
KSZ9131 event handler.
void ksz9131DisableIrq(NetInterface *interface)
Disable interrupts.
uint16_t regAddr
Ipv6Addr address[]
Definition: ipv6.h:325
Network interface controller abstraction layer.
void ksz9131Tick(NetInterface *interface)
KSZ9131 timer handler.
uint16_t ksz9131ReadPhyReg(NetInterface *interface, uint8_t address)
Read PHY register.