ksz8061_driver.h
Go to the documentation of this file.
1 /**
2  * @file ksz8061_driver.h
3  * @brief KSZ8061 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 _KSZ8061_DRIVER_H
32 #define _KSZ8061_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //PHY address
38 #ifndef KSZ8061_PHY_ADDR
39  #define KSZ8061_PHY_ADDR 1
40 #elif (KSZ8061_PHY_ADDR < 0 || KSZ8061_PHY_ADDR > 31)
41  #error KSZ8061_PHY_ADDR parameter is not valid
42 #endif
43 
44 //KSZ8061 PHY registers
45 #define KSZ8061_BMCR 0x00
46 #define KSZ8061_BMSR 0x01
47 #define KSZ8061_PHYID1 0x02
48 #define KSZ8061_PHYID2 0x03
49 #define KSZ8061_ANAR 0x04
50 #define KSZ8061_ANLPAR 0x05
51 #define KSZ8061_ANER 0x06
52 #define KSZ8061_ANNPR 0x07
53 #define KSZ8061_ANLPNPR 0x08
54 #define KSZ8061_MMDACR 0x0D
55 #define KSZ8061_MMDAADR 0x0E
56 #define KSZ8061_DCON 0x10
57 #define KSZ8061_AFECON0 0x11
58 #define KSZ8061_AFECON1 0x12
59 #define KSZ8061_AFECON2 0x13
60 #define KSZ8061_AFECON3 0x14
61 #define KSZ8061_RXERCTR 0x15
62 #define KSZ8061_OM 0x16
63 #define KSZ8061_OMSS 0x17
64 #define KSZ8061_EXCON 0x18
65 #define KSZ8061_ICSR 0x1B
66 #define KSZ8061_FUNCON 0x1C
67 #define KSZ8061_LINKMD 0x1D
68 #define KSZ8061_PHYCON1 0x1E
69 #define KSZ8061_PHYCON2 0x1F
70 
71 //KSZ8061 MMD registers
72 #define KSZ8061_AFED_CTRL 0x1B, 0x00
73 #define KSZ8061_SIGNAL_QUALITY 0x1C, 0xAC
74 
75 //Basic Control register
76 #define KSZ8061_BMCR_RESET 0x8000
77 #define KSZ8061_BMCR_LOOPBACK 0x4000
78 #define KSZ8061_BMCR_SPEED_SEL 0x2000
79 #define KSZ8061_BMCR_AN_EN 0x1000
80 #define KSZ8061_BMCR_POWER_DOWN 0x0800
81 #define KSZ8061_BMCR_ISOLATE 0x0400
82 #define KSZ8061_BMCR_RESTART_AN 0x0200
83 #define KSZ8061_BMCR_DUPLEX_MODE 0x0100
84 #define KSZ8061_BMCR_COL_TEST 0x0080
85 
86 //Basic Status register
87 #define KSZ8061_BMSR_100BT4 0x8000
88 #define KSZ8061_BMSR_100BTX_FD 0x4000
89 #define KSZ8061_BMSR_100BTX_HD 0x2000
90 #define KSZ8061_BMSR_10BT_FD 0x1000
91 #define KSZ8061_BMSR_10BT_HD 0x0800
92 #define KSZ8061_BMSR_NO_PREAMBLE 0x0040
93 #define KSZ8061_BMSR_AN_COMPLETE 0x0020
94 #define KSZ8061_BMSR_REMOTE_FAULT 0x0010
95 #define KSZ8061_BMSR_AN_CAPABLE 0x0008
96 #define KSZ8061_BMSR_LINK_STATUS 0x0004
97 #define KSZ8061_BMSR_JABBER_DETECT 0x0002
98 #define KSZ8061_BMSR_EXTENDED_CAPABLE 0x0001
99 
100 //PHY Identifier 1 register
101 #define KSZ8061_PHYID1_PHY_ID_MSB 0xFFFF
102 #define KSZ8061_PHYID1_PHY_ID_MSB_DEFAULT 0x0022
103 
104 //PHY Identifier 2 register
105 #define KSZ8061_PHYID2_PHY_ID_LSB 0xFC00
106 #define KSZ8061_PHYID2_PHY_ID_LSB_DEFAULT 0x1400
107 #define KSZ8061_PHYID2_MODEL_NUM 0x03F0
108 #define KSZ8061_PHYID2_MODEL_NUM_DEFAULT 0x0170
109 #define KSZ8061_PHYID2_REVISION_NUM 0x000F
110 
111 //Auto-Negotiation Advertisement register
112 #define KSZ8061_ANAR_NEXT_PAGE 0x8000
113 #define KSZ8061_ANAR_REMOTE_FAULT 0x2000
114 #define KSZ8061_ANAR_PAUSE 0x0C00
115 #define KSZ8061_ANAR_100BT4 0x0200
116 #define KSZ8061_ANAR_100BTX_FD 0x0100
117 #define KSZ8061_ANAR_100BTX_HD 0x0080
118 #define KSZ8061_ANAR_10BT_FD 0x0040
119 #define KSZ8061_ANAR_10BT_HD 0x0020
120 #define KSZ8061_ANAR_SELECTOR 0x001F
121 #define KSZ8061_ANAR_SELECTOR_DEFAULT 0x0001
122 
123 //Auto-Negotiation Link Partner Ability register
124 #define KSZ8061_ANLPAR_NEXT_PAGE 0x8000
125 #define KSZ8061_ANLPAR_ACK 0x4000
126 #define KSZ8061_ANLPAR_REMOTE_FAULT 0x2000
127 #define KSZ8061_ANLPAR_PAUSE 0x0C00
128 #define KSZ8061_ANLPAR_100BT4 0x0200
129 #define KSZ8061_ANLPAR_100BTX_FD 0x0100
130 #define KSZ8061_ANLPAR_100BTX_HD 0x0080
131 #define KSZ8061_ANLPAR_10BT_FD 0x0040
132 #define KSZ8061_ANLPAR_10BT_HD 0x0020
133 #define KSZ8061_ANLPAR_SELECTOR 0x001F
134 #define KSZ8061_ANLPAR_SELECTOR_DEFAULT 0x0001
135 
136 //Auto-Negotiation Expansion register
137 #define KSZ8061_ANER_PAR_DETECT_FAULT 0x0010
138 #define KSZ8061_ANER_LP_NEXT_PAGE_ABLE 0x0008
139 #define KSZ8061_ANER_NEXT_PAGE_ABLE 0x0004
140 #define KSZ8061_ANER_PAGE_RECEIVED 0x0002
141 #define KSZ8061_ANER_LP_AN_ABLE 0x0001
142 
143 //Auto-Negotiation Next Page register
144 #define KSZ8061_ANNPR_NEXT_PAGE 0x8000
145 #define KSZ8061_ANNPR_MSG_PAGE 0x2000
146 #define KSZ8061_ANNPR_ACK2 0x1000
147 #define KSZ8061_ANNPR_TOGGLE 0x0800
148 #define KSZ8061_ANNPR_MESSAGE 0x07FF
149 
150 //Link Partner Next Page Ability register
151 #define KSZ8061_ANLPNPR_NEXT_PAGE 0x8000
152 #define KSZ8061_ANLPNPR_ACK 0x4000
153 #define KSZ8061_ANLPNPR_MSG_PAGE 0x2000
154 #define KSZ8061_ANLPNPR_ACK2 0x1000
155 #define KSZ8061_ANLPNPR_TOGGLE 0x0800
156 #define KSZ8061_ANLPNPR_MESSAGE 0x07FF
157 
158 //MMD Access Control register
159 #define KSZ8061_MMDACR_FUNC 0xC000
160 #define KSZ8061_MMDACR_FUNC_ADDR 0x0000
161 #define KSZ8061_MMDACR_FUNC_DATA_NO_POST_INC 0x4000
162 #define KSZ8061_MMDACR_FUNC_DATA_POST_INC_RW 0x8000
163 #define KSZ8061_MMDACR_FUNC_DATA_POST_INC_W 0xC000
164 #define KSZ8061_MMDACR_DEVAD 0x001F
165 
166 //Digital Control register
167 #define KSZ8061_DCON_PLL_OFF 0x0010
168 
169 //AFE Control 0 register
170 #define KSZ8061_AFECON0_SLOW_OSC_MODE_PD 0x0040
171 
172 //AFE Control 1 register
173 #define KSZ8061_AFECON1_100BT_AMPLITUDE 0xF000
174 
175 //AFE Control 2 register
176 #define KSZ8061_AFECON2_LINKMD_DETECT_THRESHOLD 0x8000
177 #define KSZ8061_AFECON2_SLOW_OSC_MODE_UDS 0x0001
178 
179 //AFE Control 3 register
180 #define KSZ8061_AFECON3_UDS_METHOD 0x0040
181 #define KSZ8061_AFECON3_MANUAL_UDS_MODE 0x0020
182 #define KSZ8061_AFECON3_NV_REG_ACCESS 0x0010
183 #define KSZ8061_AFECON3_UDS_MODE_SIGDET_EN 0x0008
184 #define KSZ8061_AFECON3_RX_INTERNAL_TERM_DIS 0x0004
185 #define KSZ8061_AFECON3_SIGDET_DEASSERT_DELAY 0x0002
186 #define KSZ8061_AFECON3_SIGDET_POL 0x0001
187 
188 //Operation Mode register
189 #define KSZ8061_OM_QWF_DIS 0x1000
190 
191 //Operation Mode Strap Status register
192 #define KSZ8061_OMSS_PHYAD 0xE000
193 #define KSZ8061_OMSS_QWF_STRAP_STATUS 0x0100
194 #define KSZ8061_OMSS_MII_BTB_STRAP_STATUS 0x0080
195 #define KSZ8061_OMSS_RMII_BTB_STRAP_STATUS 0x0040
196 #define KSZ8061_OMSS_NAND_TREE_STRAP_STATUS 0x0020
197 #define KSZ8061_OMSS_RMII_STRAP_STATUS 0x0002
198 #define KSZ8061_OMSS_MII_STRAP_STATUS 0x0001
199 
200 //Expanded Control register
201 #define KSZ8061_EXCON_EDPD_DIS 0x0800
202 #define KSZ8061_EXCON_RX_PHY_LATENCY 0x0400
203 #define KSZ8061_EXCON_10BT_PREAMBLE_EN 0x0040
204 
205 //Interrupt Control/Status register
206 #define KSZ8061_ICSR_JABBER_IE 0x8000
207 #define KSZ8061_ICSR_RECEIVE_ERROR_IE 0x4000
208 #define KSZ8061_ICSR_PAGE_RECEIVED_IE 0x2000
209 #define KSZ8061_ICSR_PAR_DETECT_FAULT_IE 0x1000
210 #define KSZ8061_ICSR_LP_ACK_IE 0x0800
211 #define KSZ8061_ICSR_LINK_DOWN_IE 0x0400
212 #define KSZ8061_ICSR_REMOTE_FAULT_IE 0x0200
213 #define KSZ8061_ICSR_LINK_UP_IE 0x0100
214 #define KSZ8061_ICSR_JABBER_IF 0x0080
215 #define KSZ8061_ICSR_RECEIVE_ERROR_IF 0x0040
216 #define KSZ8061_ICSR_PAGE_RECEIVED_IF 0x0020
217 #define KSZ8061_ICSR_PAR_DETECT_FAULT_IF 0x0010
218 #define KSZ8061_ICSR_LP_ACK_IF 0x0008
219 #define KSZ8061_ICSR_LINK_DOWN_IF 0x0004
220 #define KSZ8061_ICSR_REMOTE_FAULT_IF 0x0002
221 #define KSZ8061_ICSR_LINK_UP_IF 0x0001
222 
223 //Function Control register
224 #define KSZ8061_FUNCON_LOCAL_LOOPBACK 0x0020
225 
226 //LinkMD Control/Status register
227 #define KSZ8061_LINKMD_TEST_EN 0x8000
228 #define KSZ8061_LINKMD_RESULT 0x6000
229 #define KSZ8061_LINKMD_SHORT 0x1000
230 #define KSZ8061_LINKMD_FAULT_COUNT 0x01FF
231 
232 //PHY Control 1 register
233 #define KSZ8061_PHYCON1_PAUSE_EN 0x0200
234 #define KSZ8061_PHYCON1_LINK_STATUS 0x0100
235 #define KSZ8061_PHYCON1_POL_STATUS 0x0080
236 #define KSZ8061_PHYCON1_MDIX_STATE 0x0020
237 #define KSZ8061_PHYCON1_ENERGY_DETECT 0x0010
238 #define KSZ8061_PHYCON1_PHY_ISOLATE 0x0008
239 #define KSZ8061_PHYCON1_OP_MODE 0x0007
240 #define KSZ8061_PHYCON1_OP_MODE_AN 0x0000
241 #define KSZ8061_PHYCON1_OP_MODE_10BT_HD 0x0001
242 #define KSZ8061_PHYCON1_OP_MODE_100BTX_HD 0x0002
243 #define KSZ8061_PHYCON1_OP_MODE_10BT_FD 0x0005
244 #define KSZ8061_PHYCON1_OP_MODE_100BTX_FD 0x0006
245 
246 //PHY Control 2 register
247 #define KSZ8061_PHYCON2_HP_MDIX 0x8000
248 #define KSZ8061_PHYCON2_MDIX_SEL 0x4000
249 #define KSZ8061_PHYCON2_PAIR_SWAP_DIS 0x2000
250 #define KSZ8061_PHYCON2_FORCE_LINK 0x0800
251 #define KSZ8061_PHYCON2_POWER_SAVING 0x0400
252 #define KSZ8061_PHYCON2_INT_LEVEL 0x0200
253 #define KSZ8061_PHYCON2_JABBER_EN 0x0100
254 #define KSZ8061_PHYCON2_LED_MODE 0x0030
255 #define KSZ8061_PHYCON2_TX_DIS 0x0008
256 #define KSZ8061_PHYCON2_REMOTE_LOOPBACK 0x0004
257 #define KSZ8061_PHYCON2_SQE_TEST_EN 0x0002
258 #define KSZ8061_PHYCON2_DATA_SCRAMBLING_DIS 0x0001
259 
260 //AFED Control register
261 #define KSZ8061_AFED_CTRL_LINKMD_PULSE_AMPLITUDE 0x00F0
262 
263 //Signal Quality register
264 #define KSZ8061_SIGNAL_QUALITY_SIGNAL_QUALITY_IND 0x7F00
265 
266 //C++ guard
267 #ifdef __cplusplus
268 extern "C" {
269 #endif
270 
271 //KSZ8061 Ethernet PHY driver
272 extern const PhyDriver ksz8061PhyDriver;
273 
274 //KSZ8061 related functions
275 error_t ksz8061Init(NetInterface *interface);
276 void ksz8061InitHook(NetInterface *interface);
277 
278 void ksz8061Tick(NetInterface *interface);
279 
280 void ksz8061EnableIrq(NetInterface *interface);
281 void ksz8061DisableIrq(NetInterface *interface);
282 
283 void ksz8061EventHandler(NetInterface *interface);
284 
285 void ksz8061WritePhyReg(NetInterface *interface, uint8_t address,
286  uint16_t data);
287 
288 uint16_t ksz8061ReadPhyReg(NetInterface *interface, uint8_t address);
289 
290 void ksz8061DumpPhyReg(NetInterface *interface);
291 
292 void ksz8061WriteMmdReg(NetInterface *interface, uint8_t devAddr,
293  uint16_t regAddr, uint16_t data);
294 
295 uint16_t ksz8061ReadMmdReg(NetInterface *interface, uint8_t devAddr,
296  uint16_t regAddr);
297 
298 //C++ guard
299 #ifdef __cplusplus
300 }
301 #endif
302 
303 #endif
const PhyDriver ksz8061PhyDriver
KSZ8061 Ethernet PHY driver.
void ksz8061Tick(NetInterface *interface)
KSZ8061 timer handler.
Ethernet PHY driver.
Definition: nic.h:311
uint8_t data[]
Definition: ethernet.h:222
void ksz8061InitHook(NetInterface *interface)
KSZ8061 custom configuration.
uint16_t ksz8061ReadPhyReg(NetInterface *interface, uint8_t address)
Read PHY register.
error_t
Error codes.
Definition: error.h:43
#define NetInterface
Definition: net.h:36
void ksz8061DisableIrq(NetInterface *interface)
Disable interrupts.
error_t ksz8061Init(NetInterface *interface)
KSZ8061 PHY transceiver initialization.
void ksz8061WritePhyReg(NetInterface *interface, uint8_t address, uint16_t data)
Write PHY register.
uint16_t ksz8061ReadMmdReg(NetInterface *interface, uint8_t devAddr, uint16_t regAddr)
Read MMD register.
uint16_t regAddr
Ipv6Addr address[]
Definition: ipv6.h:325
Network interface controller abstraction layer.
void ksz8061DumpPhyReg(NetInterface *interface)
Dump PHY registers for debugging purpose.
void ksz8061EventHandler(NetInterface *interface)
KSZ8061 event handler.
void ksz8061EnableIrq(NetInterface *interface)
Enable interrupts.
void ksz8061WriteMmdReg(NetInterface *interface, uint8_t devAddr, uint16_t regAddr, uint16_t data)
Write MMD register.