ksz8081_driver.h
Go to the documentation of this file.
1 /**
2  * @file ksz8081_driver.h
3  * @brief KSZ8081 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 _KSZ8081_DRIVER_H
32 #define _KSZ8081_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //PHY address
38 #ifndef KSZ8081_PHY_ADDR
39  #define KSZ8081_PHY_ADDR 0
40 #elif (KSZ8081_PHY_ADDR < 0 || KSZ8081_PHY_ADDR > 31)
41  #error KSZ8081_PHY_ADDR parameter is not valid
42 #endif
43 
44 //50MHz clock mode support
45 #ifndef KSZ8081_50MHZ_CLOCK_MODE_SUPPORT
46  #define KSZ8081_50MHZ_CLOCK_MODE_SUPPORT DISABLED
47 #elif (KSZ8081_50MHZ_CLOCK_MODE_SUPPORT != ENABLED && KSZ8081_50MHZ_CLOCK_MODE_SUPPORT != DISABLED)
48  #error KSZ8081_50MHZ_CLOCK_MODE_SUPPORT parameter is not valid
49 #endif
50 
51 //KSZ8081 PHY registers
52 #define KSZ8081_BMCR 0x00
53 #define KSZ8081_BMSR 0x01
54 #define KSZ8081_PHYID1 0x02
55 #define KSZ8081_PHYID2 0x03
56 #define KSZ8081_ANAR 0x04
57 #define KSZ8081_ANLPAR 0x05
58 #define KSZ8081_ANER 0x06
59 #define KSZ8081_ANNPR 0x07
60 #define KSZ8081_ANLPNPR 0x08
61 #define KSZ8081_DRCON 0x10
62 #define KSZ8081_AFECON1 0x11
63 #define KSZ8081_RXERCTR 0x15
64 #define KSZ8081_OMSO 0x16
65 #define KSZ8081_OMSS 0x17
66 #define KSZ8081_EXCON 0x18
67 #define KSZ8081_ICSR 0x1B
68 #define KSZ8081_LINKMD 0x1D
69 #define KSZ8081_PHYCON1 0x1E
70 #define KSZ8081_PHYCON2 0x1F
71 
72 //Basic Control register
73 #define KSZ8081_BMCR_RESET 0x8000
74 #define KSZ8081_BMCR_LOOPBACK 0x4000
75 #define KSZ8081_BMCR_SPEED_SEL 0x2000
76 #define KSZ8081_BMCR_AN_EN 0x1000
77 #define KSZ8081_BMCR_POWER_DOWN 0x0800
78 #define KSZ8081_BMCR_ISOLATE 0x0400
79 #define KSZ8081_BMCR_RESTART_AN 0x0200
80 #define KSZ8081_BMCR_DUPLEX_MODE 0x0100
81 #define KSZ8081_BMCR_COL_TEST 0x0080
82 
83 //Basic Status register
84 #define KSZ8081_BMSR_100BT4 0x8000
85 #define KSZ8081_BMSR_100BTX_FD 0x4000
86 #define KSZ8081_BMSR_100BTX_HD 0x2000
87 #define KSZ8081_BMSR_10BT_FD 0x1000
88 #define KSZ8081_BMSR_10BT_HD 0x0800
89 #define KSZ8081_BMSR_NO_PREAMBLE 0x0040
90 #define KSZ8081_BMSR_AN_COMPLETE 0x0020
91 #define KSZ8081_BMSR_REMOTE_FAULT 0x0010
92 #define KSZ8081_BMSR_AN_CAPABLE 0x0008
93 #define KSZ8081_BMSR_LINK_STATUS 0x0004
94 #define KSZ8081_BMSR_JABBER_DETECT 0x0002
95 #define KSZ8081_BMSR_EXTENDED_CAPABLE 0x0001
96 
97 //PHY Identifier 1 register
98 #define KSZ8081_PHYID1_PHY_ID_MSB 0xFFFF
99 #define KSZ8081_PHYID1_PHY_ID_MSB_DEFAULT 0x0022
100 
101 //PHY Identifier 2 register
102 #define KSZ8081_PHYID2_PHY_ID_LSB 0xFC00
103 #define KSZ8081_PHYID2_PHY_ID_LSB_DEFAULT 0x1400
104 #define KSZ8081_PHYID2_MODEL_NUM 0x03F0
105 #define KSZ8081_PHYID2_MODEL_NUM_DEFAULT 0x0160
106 #define KSZ8081_PHYID2_REVISION_NUM 0x000F
107 
108 //Auto-Negotiation Advertisement register
109 #define KSZ8081_ANAR_NEXT_PAGE 0x8000
110 #define KSZ8081_ANAR_REMOTE_FAULT 0x2000
111 #define KSZ8081_ANAR_PAUSE 0x0C00
112 #define KSZ8081_ANAR_100BT4 0x0200
113 #define KSZ8081_ANAR_100BTX_FD 0x0100
114 #define KSZ8081_ANAR_100BTX_HD 0x0080
115 #define KSZ8081_ANAR_10BT_FD 0x0040
116 #define KSZ8081_ANAR_10BT_HD 0x0020
117 #define KSZ8081_ANAR_SELECTOR 0x001F
118 #define KSZ8081_ANAR_SELECTOR_DEFAULT 0x0001
119 
120 //Auto-Negotiation Link Partner Ability register
121 #define KSZ8081_ANLPAR_NEXT_PAGE 0x8000
122 #define KSZ8081_ANLPAR_ACK 0x4000
123 #define KSZ8081_ANLPAR_REMOTE_FAULT 0x2000
124 #define KSZ8081_ANLPAR_PAUSE 0x0C00
125 #define KSZ8081_ANLPAR_100BT4 0x0200
126 #define KSZ8081_ANLPAR_100BTX_FD 0x0100
127 #define KSZ8081_ANLPAR_100BTX_HD 0x0080
128 #define KSZ8081_ANLPAR_10BT_FD 0x0040
129 #define KSZ8081_ANLPAR_10BT_HD 0x0020
130 #define KSZ8081_ANLPAR_SELECTOR 0x001F
131 #define KSZ8081_ANLPAR_SELECTOR_DEFAULT 0x0001
132 
133 //Auto-Negotiation Expansion register
134 #define KSZ8081_ANER_PAR_DETECT_FAULT 0x0010
135 #define KSZ8081_ANER_LP_NEXT_PAGE_ABLE 0x0008
136 #define KSZ8081_ANER_NEXT_PAGE_ABLE 0x0004
137 #define KSZ8081_ANER_PAGE_RECEIVED 0x0002
138 #define KSZ8081_ANER_LP_AN_ABLE 0x0001
139 
140 //Auto-Negotiation Next Page register
141 #define KSZ8081_ANNPR_MSG_PAGE 0x2000
142 #define KSZ8081_ANNPR_ACK2 0x1000
143 #define KSZ8081_ANNPR_TOGGLE 0x0800
144 #define KSZ8081_ANNPR_MESSAGE 0x07FF
145 
146 //Link Partner Next Page Ability register
147 #define KSZ8081_ANLPNPR_NEXT_PAGE 0x8000
148 #define KSZ8081_ANLPNPR_ACK 0x4000
149 #define KSZ8081_ANLPNPR_MSG_PAGE 0x2000
150 #define KSZ8081_ANLPNPR_ACK2 0x1000
151 #define KSZ8081_ANLPNPR_TOGGLE 0x0800
152 #define KSZ8081_ANLPNPR_MESSAGE 0x07FF
153 
154 //Digital Reserved Control register
155 #define KSZ8081_DRCON_PLL_OFF 0x0010
156 
157 //AFE Control 1 register
158 #define KSZ8081_AFECON1_SLOW_OSC_MODE_EN 0x0020
159 
160 //Operation Mode Strap Override register
161 #define KSZ8081_OMSO_FACTORY_TEST_MODE 0x8000
162 #define KSZ8081_OMSO_BCAST_OFF_OVERRIDE 0x0200
163 #define KSZ8081_OMSO_MII_BTB_OVERRIDE 0x0080
164 #define KSZ8081_OMSO_RMII_BTB_OVERRIDE 0x0040
165 #define KSZ8081_OMSO_NAND_TREE_OVERRIDE 0x0020
166 #define KSZ8081_OMSO_RMII_OVERRIDE 0x0002
167 #define KSZ8081_OMSO_MII_OVERRIDE 0x0001
168 
169 //Operation Mode Strap Status register
170 #define KSZ8081_OMSS_PHYAD 0xE000
171 #define KSZ8081_OMSS_BCAST_OFF_STRAP_STATUS 0x0200
172 #define KSZ8081_OMSS_MII_BTB_STRAP_STATUS 0x0080
173 #define KSZ8081_OMSS_RMII_BTB_STRAP_STATUS 0x0040
174 #define KSZ8081_OMSS_NAND_TREE_STRAP_STATUS 0x0020
175 #define KSZ8081_OMSS_RMII_STRAP_STATUS 0x0002
176 #define KSZ8081_OMSS_MII_STRAP_STATUS 0x0001
177 
178 //Expanded Control register
179 #define KSZ8081_EXCON_EDPD_DIS 0x0800
180 #define KSZ8081_EXCON_100BTX_LATENCY 0x0400
181 #define KSZ8081_EXCON_10BT_PREAMBLE_RESTORE 0x0040
182 
183 //Interrupt Control/Status register
184 #define KSZ8081_ICSR_JABBER_IE 0x8000
185 #define KSZ8081_ICSR_RECEIVE_ERROR_IE 0x4000
186 #define KSZ8081_ICSR_PAGE_RECEIVED_IE 0x2000
187 #define KSZ8081_ICSR_PAR_DETECT_FAULT_IE 0x1000
188 #define KSZ8081_ICSR_LP_ACK_IE 0x0800
189 #define KSZ8081_ICSR_LINK_DOWN_IE 0x0400
190 #define KSZ8081_ICSR_REMOTE_FAULT_IE 0x0200
191 #define KSZ8081_ICSR_LINK_UP_IE 0x0100
192 #define KSZ8081_ICSR_JABBER_IF 0x0080
193 #define KSZ8081_ICSR_RECEIVE_ERROR_IF 0x0040
194 #define KSZ8081_ICSR_PAGE_RECEIVED_IF 0x0020
195 #define KSZ8081_ICSR_PAR_DETECT_FAULT_IF 0x0010
196 #define KSZ8081_ICSR_LP_ACK_IF 0x0008
197 #define KSZ8081_ICSR_LINK_DOWN_IF 0x0004
198 #define KSZ8081_ICSR_REMOTE_FAULT_IF 0x0002
199 #define KSZ8081_ICSR_LINK_UP_IF 0x0001
200 
201 //LinkMD Control/Status register
202 #define KSZ8081_LINKMD_TEST_EN 0x8000
203 #define KSZ8081_LINKMD_RESULT 0x6000
204 #define KSZ8081_LINKMD_SHORT 0x1000
205 #define KSZ8081_LINKMD_FAULT_COUNT 0x01FF
206 
207 //PHY Control 1 register
208 #define KSZ8081_PHYCON1_PAUSE_EN 0x0200
209 #define KSZ8081_PHYCON1_LINK_STATUS 0x0100
210 #define KSZ8081_PHYCON1_POL_STATUS 0x0080
211 #define KSZ8081_PHYCON1_MDIX_STATE 0x0020
212 #define KSZ8081_PHYCON1_ENERGY_DETECT 0x0010
213 #define KSZ8081_PHYCON1_PHY_ISOLATE 0x0008
214 #define KSZ8081_PHYCON1_OP_MODE 0x0007
215 #define KSZ8081_PHYCON1_OP_MODE_AN 0x0000
216 #define KSZ8081_PHYCON1_OP_MODE_10BT_HD 0x0001
217 #define KSZ8081_PHYCON1_OP_MODE_100BTX_HD 0x0002
218 #define KSZ8081_PHYCON1_OP_MODE_10BT_FD 0x0005
219 #define KSZ8081_PHYCON1_OP_MODE_100BTX_FD 0x0006
220 
221 //PHY Control 2 register
222 #define KSZ8081_PHYCON2_HP_MDIX 0x8000
223 #define KSZ8081_PHYCON2_MDIX_SEL 0x4000
224 #define KSZ8081_PHYCON2_PAIR_SWAP_DIS 0x2000
225 #define KSZ8081_PHYCON2_FORCE_LINK 0x0800
226 #define KSZ8081_PHYCON2_POWER_SAVING 0x0400
227 #define KSZ8081_PHYCON2_INT_LEVEL 0x0200
228 #define KSZ8081_PHYCON2_JABBER_EN 0x0100
229 #define KSZ8081_PHYCON2_RMII_REF_CLK_SEL 0x0080
230 #define KSZ8081_PHYCON2_LED_MODE 0x0030
231 #define KSZ8081_PHYCON2_TX_DIS 0x0008
232 #define KSZ8081_PHYCON2_REMOTE_LOOPBACK 0x0004
233 #define KSZ8081_PHYCON2_SQE_TEST_EN 0x0002
234 #define KSZ8081_PHYCON2_DATA_SCRAMBLING_DIS 0x0001
235 
236 //C++ guard
237 #ifdef __cplusplus
238 extern "C" {
239 #endif
240 
241 //KSZ8081 Ethernet PHY driver
242 extern const PhyDriver ksz8081PhyDriver;
243 
244 //KSZ8081 related functions
245 error_t ksz8081Init(NetInterface *interface);
246 void ksz8081InitHook(NetInterface *interface);
247 
248 void ksz8081Tick(NetInterface *interface);
249 
250 void ksz8081EnableIrq(NetInterface *interface);
251 void ksz8081DisableIrq(NetInterface *interface);
252 
253 void ksz8081EventHandler(NetInterface *interface);
254 
255 void ksz8081WritePhyReg(NetInterface *interface, uint8_t address,
256  uint16_t data);
257 
258 uint16_t ksz8081ReadPhyReg(NetInterface *interface, uint8_t address);
259 
260 void ksz8081DumpPhyReg(NetInterface *interface);
261 
262 //C++ guard
263 #ifdef __cplusplus
264 }
265 #endif
266 
267 #endif
uint16_t ksz8081ReadPhyReg(NetInterface *interface, uint8_t address)
Read PHY register.
void ksz8081EnableIrq(NetInterface *interface)
Enable interrupts.
Ethernet PHY driver.
Definition: nic.h:311
uint8_t data[]
Definition: ethernet.h:222
void ksz8081InitHook(NetInterface *interface)
KSZ8081 custom configuration.
void ksz8081Tick(NetInterface *interface)
KSZ8081 timer handler.
void ksz8081WritePhyReg(NetInterface *interface, uint8_t address, uint16_t data)
Write PHY register.
void ksz8081DisableIrq(NetInterface *interface)
Disable interrupts.
error_t
Error codes.
Definition: error.h:43
#define NetInterface
Definition: net.h:36
const PhyDriver ksz8081PhyDriver
KSZ8081 Ethernet PHY driver.
void ksz8081DumpPhyReg(NetInterface *interface)
Dump PHY registers for debugging purpose.
Ipv6Addr address[]
Definition: ipv6.h:325
Network interface controller abstraction layer.
error_t ksz8081Init(NetInterface *interface)
KSZ8081 PHY transceiver initialization.
void ksz8081EventHandler(NetInterface *interface)
KSZ8081 event handler.