ksz8091_driver.h
Go to the documentation of this file.
1 /**
2  * @file ksz8091_driver.h
3  * @brief KSZ8091 Ethernet PHY transceiver
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2019 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.6
29  **/
30 
31 #ifndef _KSZ8091_DRIVER_H
32 #define _KSZ8091_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //PHY address
38 #ifndef KSZ8091_PHY_ADDR
39  #define KSZ8091_PHY_ADDR 7
40 #elif (KSZ8091_PHY_ADDR < 0 || KSZ8091_PHY_ADDR > 31)
41  #error KSZ8091_PHY_ADDR parameter is not valid
42 #endif
43 
44 //KSZ8091 PHY registers
45 #define KSZ8091_BMCR 0x00
46 #define KSZ8091_BMSR 0x01
47 #define KSZ8091_PHYID1 0x02
48 #define KSZ8091_PHYID2 0x03
49 #define KSZ8091_ANAR 0x04
50 #define KSZ8091_ANLPAR 0x05
51 #define KSZ8091_ANER 0x06
52 #define KSZ8091_ANNPR 0x07
53 #define KSZ8091_ANLPNPR 0x08
54 #define KSZ8091_MMDACR 0x0D
55 #define KSZ8091_MMDAADR 0x0E
56 #define KSZ8091_DRCON 0x10
57 #define KSZ8091_AFECON1 0x11
58 #define KSZ8091_AFECON4 0x13
59 #define KSZ8091_RXERCTR 0x15
60 #define KSZ8091_OMSO 0x16
61 #define KSZ8091_OMSS 0x17
62 #define KSZ8091_EXCON 0x18
63 #define KSZ8091_ICSR 0x1B
64 #define KSZ8091_LINKMD 0x1D
65 #define KSZ8091_PHYCON1 0x1E
66 #define KSZ8091_PHYCON2 0x1F
67 
68 //Basic Control register
69 #define KSZ8091_BMCR_RESET 0x8000
70 #define KSZ8091_BMCR_LOOPBACK 0x4000
71 #define KSZ8091_BMCR_SPEED_SEL 0x2000
72 #define KSZ8091_BMCR_AN_EN 0x1000
73 #define KSZ8091_BMCR_POWER_DOWN 0x0800
74 #define KSZ8091_BMCR_ISOLATE 0x0400
75 #define KSZ8091_BMCR_RESTART_AN 0x0200
76 #define KSZ8091_BMCR_DUPLEX_MODE 0x0100
77 #define KSZ8091_BMCR_COL_TEST 0x0080
78 
79 //Basic Status register
80 #define KSZ8091_BMSR_100BT4 0x8000
81 #define KSZ8091_BMSR_100BTX_FD 0x4000
82 #define KSZ8091_BMSR_100BTX_HD 0x2000
83 #define KSZ8091_BMSR_10BT_FD 0x1000
84 #define KSZ8091_BMSR_10BT_HD 0x0800
85 #define KSZ8091_BMSR_NO_PREAMBLE 0x0040
86 #define KSZ8091_BMSR_AN_COMPLETE 0x0020
87 #define KSZ8091_BMSR_REMOTE_FAULT 0x0010
88 #define KSZ8091_BMSR_AN_CAPABLE 0x0008
89 #define KSZ8091_BMSR_LINK_STATUS 0x0004
90 #define KSZ8091_BMSR_JABBER_DETECT 0x0002
91 #define KSZ8091_BMSR_EXTENDED_CAPABLE 0x0001
92 
93 //PHY Identifier 1 register
94 #define KSZ8091_PHYID1_PHY_ID_MSB 0xFFFF
95 #define KSZ8091_PHYID1_PHY_ID_MSB_DEFAULT 0x0022
96 
97 //PHY Identifier 2 register
98 #define KSZ8091_PHYID2_PHY_ID_LSB 0xFC00
99 #define KSZ8091_PHYID2_PHY_ID_LSB_DEFAULT 0x1400
100 #define KSZ8091_PHYID2_MODEL_NUM 0x03F0
101 #define KSZ8091_PHYID2_MODEL_NUM_DEFAULT 0x0160
102 #define KSZ8091_PHYID2_REVISION_NUM 0x000F
103 
104 //Auto-Negotiation Advertisement register
105 #define KSZ8091_ANAR_NEXT_PAGE 0x8000
106 #define KSZ8091_ANAR_REMOTE_FAULT 0x2000
107 #define KSZ8091_ANAR_PAUSE 0x0C00
108 #define KSZ8091_ANAR_100BT4 0x0200
109 #define KSZ8091_ANAR_100BTX_FD 0x0100
110 #define KSZ8091_ANAR_100BTX_HD 0x0080
111 #define KSZ8091_ANAR_10BT_FD 0x0040
112 #define KSZ8091_ANAR_10BT_HD 0x0020
113 #define KSZ8091_ANAR_SELECTOR 0x001F
114 #define KSZ8091_ANAR_SELECTOR_DEFAULT 0x0001
115 
116 //Auto-Negotiation Link Partner Ability register
117 #define KSZ8091_ANLPAR_NEXT_PAGE 0x8000
118 #define KSZ8091_ANLPAR_ACK 0x4000
119 #define KSZ8091_ANLPAR_REMOTE_FAULT 0x2000
120 #define KSZ8091_ANLPAR_PAUSE 0x0C00
121 #define KSZ8091_ANLPAR_100BT4 0x0200
122 #define KSZ8091_ANLPAR_100BTX_FD 0x0100
123 #define KSZ8091_ANLPAR_100BTX_HD 0x0080
124 #define KSZ8091_ANLPAR_10BT_FD 0x0040
125 #define KSZ8091_ANLPAR_10BT_HD 0x0020
126 #define KSZ8091_ANLPAR_SELECTOR 0x001F
127 #define KSZ8091_ANLPAR_SELECTOR_DEFAULT 0x0001
128 
129 //Auto-Negotiation Expansion register
130 #define KSZ8091_ANER_PAR_DETECT_FAULT 0x0010
131 #define KSZ8091_ANER_LP_NEXT_PAGE_ABLE 0x0008
132 #define KSZ8091_ANER_NEXT_PAGE_ABLE 0x0004
133 #define KSZ8091_ANER_PAGE_RECEIVED 0x0002
134 #define KSZ8091_ANER_LP_AN_ABLE 0x0001
135 
136 //Auto-Negotiation Next Page register
137 #define KSZ8091_ANNPR_NEXT_PAGE 0x8000
138 #define KSZ8091_ANNPR_MSG_PAGE 0x2000
139 #define KSZ8091_ANNPR_ACK2 0x1000
140 #define KSZ8091_ANNPR_TOGGLE 0x0800
141 #define KSZ8091_ANNPR_MESSAGE 0x07FF
142 
143 //Link Partner Next Page Ability register
144 #define KSZ8091_ANLPNPR_NEXT_PAGE 0x8000
145 #define KSZ8091_ANLPNPR_ACK 0x4000
146 #define KSZ8091_ANLPNPR_MSG_PAGE 0x2000
147 #define KSZ8091_ANLPNPR_ACK2 0x1000
148 #define KSZ8091_ANLPNPR_TOGGLE 0x0800
149 #define KSZ8091_ANLPNPR_MESSAGE 0x07FF
150 
151 //MMD Access Control register
152 #define KSZ8091_MMDACR_FUNC 0xC000
153 #define KSZ8091_MMDACR_FUNC_ADDR 0x0000
154 #define KSZ8091_MMDACR_FUNC_DATA_NO_POST_INC 0x4000
155 #define KSZ8091_MMDACR_FUNC_DATA_POST_INC_RW 0x8000
156 #define KSZ8091_MMDACR_FUNC_DATA_POST_INC_W 0xC000
157 #define KSZ8091_MMDACR_DEVAD 0x001F
158 
159 //Digital Reserved Control register
160 #define KSZ8091_DRCON_PLL_OFF 0x0010
161 
162 //AFE Control 1 register
163 #define KSZ8091_AFECON1_SLOW_OSC_MODE_EN 0x0020
164 
165 //Operation Mode Strap Override register
166 #define KSZ8091_OMSO_PME_EN 0x8000
167 #define KSZ8091_OMSO_BCAST_OFF_OVERRIDE 0x0200
168 #define KSZ8091_OMSO_MII_BTB_OVERRIDE 0x0080
169 #define KSZ8091_OMSO_RMII_BTB_OVERRIDE 0x0040
170 #define KSZ8091_OMSO_NAND_TREE_OVERRIDE 0x0020
171 #define KSZ8091_OMSO_RMII_OVERRIDE 0x0002
172 #define KSZ8091_OMSO_MII_OVERRIDE 0x0001
173 
174 //Operation Mode Strap Status register
175 #define KSZ8091_OMSS_PHYAD 0xE000
176 #define KSZ8091_OMSS_BCAST_OFF_STRAP_STATUS 0x0200
177 #define KSZ8091_OMSS_MII_BTB_STRAP_STATUS 0x0080
178 #define KSZ8091_OMSS_RMII_BTB_STRAP_STATUS 0x0040
179 #define KSZ8091_OMSS_NAND_TREE_STRAP_STATUS 0x0020
180 #define KSZ8091_OMSS_RMII_STRAP_STATUS 0x0002
181 #define KSZ8091_OMSS_MII_STRAP_STATUS 0x0001
182 
183 //Expanded Control register
184 #define KSZ8091_EXCON_EDPD_DIS 0x0800
185 #define KSZ8091_EXCON_100BTX_LATENCY 0x0400
186 #define KSZ8091_EXCON_10BT_PREAMBLE_RESTORE 0x0040
187 
188 //Interrupt Control/Status register
189 #define KSZ8091_ICSR_JABBER_IE 0x8000
190 #define KSZ8091_ICSR_RECEIVE_ERROR_IE 0x4000
191 #define KSZ8091_ICSR_PAGE_RECEIVED_IE 0x2000
192 #define KSZ8091_ICSR_PAR_DETECT_FAULT_IE 0x1000
193 #define KSZ8091_ICSR_LP_ACK_IE 0x0800
194 #define KSZ8091_ICSR_LINK_DOWN_IE 0x0400
195 #define KSZ8091_ICSR_REMOTE_FAULT_IE 0x0200
196 #define KSZ8091_ICSR_LINK_UP_IE 0x0100
197 #define KSZ8091_ICSR_JABBER_IF 0x0080
198 #define KSZ8091_ICSR_RECEIVE_ERROR_IF 0x0040
199 #define KSZ8091_ICSR_PAGE_RECEIVED_IF 0x0020
200 #define KSZ8091_ICSR_PAR_DETECT_FAULT_IF 0x0010
201 #define KSZ8091_ICSR_LP_ACK_IF 0x0008
202 #define KSZ8091_ICSR_LINK_DOWN_IF 0x0004
203 #define KSZ8091_ICSR_REMOTE_FAULT_IF 0x0002
204 #define KSZ8091_ICSR_LINK_UP_IF 0x0001
205 
206 //LinkMD Control/Status register
207 #define KSZ8091_LINKMD_TEST_EN 0x8000
208 #define KSZ8091_LINKMD_RESULT 0x6000
209 #define KSZ8091_LINKMD_SHORT 0x1000
210 #define KSZ8091_LINKMD_FAULT_COUNT 0x01FF
211 
212 //PHY Control 1 register
213 #define KSZ8091_PHYCON1_PAUSE_EN 0x0200
214 #define KSZ8091_PHYCON1_LINK_STATUS 0x0100
215 #define KSZ8091_PHYCON1_POL_STATUS 0x0080
216 #define KSZ8091_PHYCON1_MDIX_STATE 0x0020
217 #define KSZ8091_PHYCON1_ENERGY_DETECT 0x0010
218 #define KSZ8091_PHYCON1_PHY_ISOLATE 0x0008
219 #define KSZ8091_PHYCON1_OP_MODE 0x0007
220 #define KSZ8091_PHYCON1_OP_MODE_AN 0x0000
221 #define KSZ8091_PHYCON1_OP_MODE_10BT_HD 0x0001
222 #define KSZ8091_PHYCON1_OP_MODE_100BTX_HD 0x0002
223 #define KSZ8091_PHYCON1_OP_MODE_10BT_FD 0x0005
224 #define KSZ8091_PHYCON1_OP_MODE_100BTX_FD 0x0006
225 
226 //PHY Control 2 register
227 #define KSZ8091_PHYCON2_HP_MDIX 0x8000
228 #define KSZ8091_PHYCON2_MDIX_SEL 0x4000
229 #define KSZ8091_PHYCON2_PAIR_SWAP_DIS 0x2000
230 #define KSZ8091_PHYCON2_FORCE_LINK 0x0800
231 #define KSZ8091_PHYCON2_POWER_SAVING 0x0400
232 #define KSZ8091_PHYCON2_INT_LEVEL 0x0200
233 #define KSZ8091_PHYCON2_JABBER_EN 0x0100
234 #define KSZ8091_PHYCON2_RMII_REF_CLK_SEL 0x0080
235 #define KSZ8091_PHYCON2_LED_MODE 0x0030
236 #define KSZ8091_PHYCON2_TX_DIS 0x0008
237 #define KSZ8091_PHYCON2_REMOTE_LOOPBACK 0x0004
238 #define KSZ8091_PHYCON2_SQE_TEST_EN 0x0002
239 #define KSZ8091_PHYCON2_DATA_SCRAMBLING_DIS 0x0001
240 
241 //C++ guard
242 #ifdef __cplusplus
243 extern "C" {
244 #endif
245 
246 //KSZ8091 Ethernet PHY driver
247 extern const PhyDriver ksz8091PhyDriver;
248 
249 //KSZ8091 related functions
250 error_t ksz8091Init(NetInterface *interface);
251 
252 void ksz8091Tick(NetInterface *interface);
253 
254 void ksz8091EnableIrq(NetInterface *interface);
255 void ksz8091DisableIrq(NetInterface *interface);
256 
257 void ksz8091EventHandler(NetInterface *interface);
258 
259 void ksz8091WritePhyReg(NetInterface *interface, uint8_t address,
260  uint16_t data);
261 
262 uint16_t ksz8091ReadPhyReg(NetInterface *interface, uint8_t address);
263 
264 void ksz8091DumpPhyReg(NetInterface *interface);
265 
266 //C++ guard
267 #ifdef __cplusplus
268 }
269 #endif
270 
271 #endif
PHY driver.
Definition: nic.h:214
void ksz8091EventHandler(NetInterface *interface)
KSZ8091 event handler.
void ksz8091EnableIrq(NetInterface *interface)
Enable interrupts.
void ksz8091DisableIrq(NetInterface *interface)
Disable interrupts.
error_t
Error codes.
Definition: error.h:42
error_t ksz8091Init(NetInterface *interface)
KSZ8091 PHY transceiver initialization.
#define NetInterface
Definition: net.h:36
void ksz8091WritePhyReg(NetInterface *interface, uint8_t address, uint16_t data)
Write PHY register.
void ksz8091Tick(NetInterface *interface)
KSZ8091 timer handler.
const PhyDriver ksz8091PhyDriver
KSZ8091 Ethernet PHY driver.
void ksz8091DumpPhyReg(NetInterface *interface)
Dump PHY registers for debugging purpose.
Network interface controller abstraction layer.
Ipv6Addr address
uint8_t data[]
Definition: dtls_misc.h:176
uint16_t ksz8091ReadPhyReg(NetInterface *interface, uint8_t address)
Read PHY register.