Go to the documentation of this file.
31 #ifndef _KSZ9031_DRIVER_H
32 #define _KSZ9031_DRIVER_H
38 #ifndef KSZ9031_PHY_ADDR
39 #define KSZ9031_PHY_ADDR 7
40 #elif (KSZ9031_PHY_ADDR < 0 || KSZ9031_PHY_ADDR > 31)
41 #error KSZ9031_PHY_ADDR parameter is not valid
45 #define KSZ9031_BMCR 0x00
46 #define KSZ9031_BMSR 0x01
47 #define KSZ9031_PHYID1 0x02
48 #define KSZ9031_PHYID2 0x03
49 #define KSZ9031_ANAR 0x04
50 #define KSZ9031_ANLPAR 0x05
51 #define KSZ9031_ANER 0x06
52 #define KSZ9031_ANNPR 0x07
53 #define KSZ9031_ANLPNPR 0x08
54 #define KSZ9031_GBCR 0x09
55 #define KSZ9031_GBSR 0x0A
56 #define KSZ9031_MMDACR 0x0D
57 #define KSZ9031_MMDAADR 0x0E
58 #define KSZ9031_GBESR 0x0F
59 #define KSZ9031_RLB 0x11
60 #define KSZ9031_LINKMD 0x12
61 #define KSZ9031_DPMAPCSS 0x13
62 #define KSZ9031_RXERCTR 0x15
63 #define KSZ9031_ICSR 0x1B
64 #define KSZ9031_AUTOMDI 0x1C
65 #define KSZ9031_PHYCON 0x1F
68 #define KSZ9031_AN_FLP_BURST_TRANSMIT_LO 0x00, 0x03
69 #define KSZ9031_AN_FLP_BURST_TRANSMIT_HI 0x00, 0x04
70 #define KSZ9031_1000BASE_T_LINK_UP_TIME_CTRL 0x01, 0x5A
71 #define KSZ9031_COMMON_CTRL 0x02, 0x00
72 #define KSZ9031_STRAP_STAT 0x02, 0x01
73 #define KSZ9031_OP_MODE_STRAP_OVERRIDE 0x02, 0x02
74 #define KSZ9031_OP_MODE_STRAP_STAT 0x02, 0x03
75 #define KSZ9031_RGMII_CTRL_SIGNAL_PAD_SKEW 0x02, 0x04
76 #define KSZ9031_RGMII_RX_DATA_PAD_SKEW 0x02, 0x05
77 #define KSZ9031_RGMII_TX_DATA_PAD_SKEW 0x02, 0x06
78 #define KSZ9031_GMII_CLK_PAD_SKEW 0x02, 0x08
79 #define KSZ9031_WOL_CTRL 0x02, 0x10
80 #define KSZ9031_WOL_MAGIC_PKT_MAC_DA0 0x02, 0x11
81 #define KSZ9031_WOL_MAGIC_PKT_MAC_DA1 0x02, 0x12
82 #define KSZ9031_WOL_MAGIC_PKT_MAC_DA2 0x02, 0x13
83 #define KSZ9031_WOL_CUSTOM_PKT_TYPE0_CRC0 0x02, 0x14
84 #define KSZ9031_WOL_CUSTOM_PKT_TYPE0_CRC1 0x02, 0x15
85 #define KSZ9031_WOL_CUSTOM_PKT_TYPE1_CRC0 0x02, 0x16
86 #define KSZ9031_WOL_CUSTOM_PKT_TYPE1_CRC1 0x02, 0x17
87 #define KSZ9031_WOL_CUSTOM_PKT_TYPE2_CRC0 0x02, 0x18
88 #define KSZ9031_WOL_CUSTOM_PKT_TYPE2_CRC1 0x02, 0x19
89 #define KSZ9031_WOL_CUSTOM_PKT_TYPE3_CRC0 0x02, 0x1A
90 #define KSZ9031_WOL_CUSTOM_PKT_TYPE3_CRC1 0x02, 0x1B
91 #define KSZ9031_WOL_CUSTOM_PKT_TYPE0_MASK0 0x02, 0x1C
92 #define KSZ9031_WOL_CUSTOM_PKT_TYPE0_MASK1 0x02, 0x1D
93 #define KSZ9031_WOL_CUSTOM_PKT_TYPE0_MASK2 0x02, 0x1E
94 #define KSZ9031_WOL_CUSTOM_PKT_TYPE0_MASK3 0x02, 0x1F
95 #define KSZ9031_WOL_CUSTOM_PKT_TYPE1_MASK0 0x02, 0x20
96 #define KSZ9031_WOL_CUSTOM_PKT_TYPE1_MASK1 0x02, 0x21
97 #define KSZ9031_WOL_CUSTOM_PKT_TYPE1_MASK2 0x02, 0x22
98 #define KSZ9031_WOL_CUSTOM_PKT_TYPE1_MASK3 0x02, 0x23
99 #define KSZ9031_WOL_CUSTOM_PKT_TYPE2_MASK0 0x02, 0x24
100 #define KSZ9031_WOL_CUSTOM_PKT_TYPE2_MASK1 0x02, 0x25
101 #define KSZ9031_WOL_CUSTOM_PKT_TYPE2_MASK2 0x02, 0x26
102 #define KSZ9031_WOL_CUSTOM_PKT_TYPE2_MASK3 0x02, 0x27
103 #define KSZ9031_WOL_CUSTOM_PKT_TYPE3_MASK0 0x02, 0x28
104 #define KSZ9031_WOL_CUSTOM_PKT_TYPE3_MASK1 0x02, 0x29
105 #define KSZ9031_WOL_CUSTOM_PKT_TYPE3_MASK2 0x02, 0x2A
106 #define KSZ9031_WOL_CUSTOM_PKT_TYPE3_MASK3 0x02, 0x2B
107 #define KSZ9031_ANALOG_CTRL4 0x1C, 0x04
108 #define KSZ9031_EDPD_CTRL 0x1C, 0x23
111 #define KSZ9031_BMCR_RESET 0x8000
112 #define KSZ9031_BMCR_LOOPBACK 0x4000
113 #define KSZ9031_BMCR_SPEED_SEL_LSB 0x2000
114 #define KSZ9031_BMCR_AN_EN 0x1000
115 #define KSZ9031_BMCR_POWER_DOWN 0x0800
116 #define KSZ9031_BMCR_ISOLATE 0x0400
117 #define KSZ9031_BMCR_RESTART_AN 0x0200
118 #define KSZ9031_BMCR_DUPLEX_MODE 0x0100
119 #define KSZ9031_BMCR_SPEED_SEL_MSB 0x0040
122 #define KSZ9031_BMSR_100BT4 0x8000
123 #define KSZ9031_BMSR_100BTX_FD 0x4000
124 #define KSZ9031_BMSR_100BTX_HD 0x2000
125 #define KSZ9031_BMSR_10BT_FD 0x1000
126 #define KSZ9031_BMSR_10BT_HD 0x0800
127 #define KSZ9031_BMSR_EXTENDED_STATUS 0x0100
128 #define KSZ9031_BMSR_NO_PREAMBLE 0x0040
129 #define KSZ9031_BMSR_AN_COMPLETE 0x0020
130 #define KSZ9031_BMSR_REMOTE_FAULT 0x0010
131 #define KSZ9031_BMSR_AN_CAPABLE 0x0008
132 #define KSZ9031_BMSR_LINK_STATUS 0x0004
133 #define KSZ9031_BMSR_JABBER_DETECT 0x0002
134 #define KSZ9031_BMSR_EXTENDED_CAPABLE 0x0001
137 #define KSZ9031_PHYID1_PHY_ID_MSB 0xFFFF
138 #define KSZ9031_PHYID1_PHY_ID_MSB_DEFAULT 0x0022
141 #define KSZ9031_PHYID2_PHY_ID_LSB 0xFC00
142 #define KSZ9031_PHYID2_PHY_ID_LSB_DEFAULT 0x1400
143 #define KSZ9031_PHYID2_MODEL_NUM 0x03F0
144 #define KSZ9031_PHYID2_MODEL_NUM_DEFAULT 0x0220
145 #define KSZ9031_PHYID2_REVISION_NUM 0x000F
148 #define KSZ9031_ANAR_NEXT_PAGE 0x8000
149 #define KSZ9031_ANAR_REMOTE_FAULT 0x2000
150 #define KSZ9031_ANAR_PAUSE 0x0C00
151 #define KSZ9031_ANAR_100BT4 0x0200
152 #define KSZ9031_ANAR_100BTX_FD 0x0100
153 #define KSZ9031_ANAR_100BTX_HD 0x0080
154 #define KSZ9031_ANAR_10BT_FD 0x0040
155 #define KSZ9031_ANAR_10BT_HD 0x0020
156 #define KSZ9031_ANAR_SELECTOR 0x001F
157 #define KSZ9031_ANAR_SELECTOR_DEFAULT 0x0001
160 #define KSZ9031_ANLPAR_NEXT_PAGE 0x8000
161 #define KSZ9031_ANLPAR_ACK 0x4000
162 #define KSZ9031_ANLPAR_REMOTE_FAULT 0x2000
163 #define KSZ9031_ANLPAR_PAUSE 0x0C00
164 #define KSZ9031_ANLPAR_100BT4 0x0200
165 #define KSZ9031_ANLPAR_100BTX_FD 0x0100
166 #define KSZ9031_ANLPAR_100BTX_HD 0x0080
167 #define KSZ9031_ANLPAR_10BT_FD 0x0040
168 #define KSZ9031_ANLPAR_10BT_HD 0x0020
169 #define KSZ9031_ANLPAR_SELECTOR 0x001F
170 #define KSZ9031_ANLPAR_SELECTOR_DEFAULT 0x0001
173 #define KSZ9031_ANER_PAR_DETECT_FAULT 0x0010
174 #define KSZ9031_ANER_LP_NEXT_PAGE_ABLE 0x0008
175 #define KSZ9031_ANER_NEXT_PAGE_ABLE 0x0004
176 #define KSZ9031_ANER_PAGE_RECEIVED 0x0002
177 #define KSZ9031_ANER_LP_AN_ABLE 0x0001
180 #define KSZ9031_ANNPR_NEXT_PAGE 0x8000
181 #define KSZ9031_ANNPR_MSG_PAGE 0x2000
182 #define KSZ9031_ANNPR_ACK2 0x1000
183 #define KSZ9031_ANNPR_TOGGLE 0x0800
184 #define KSZ9031_ANNPR_MESSAGE 0x07FF
187 #define KSZ9031_ANLPNPR_NEXT_PAGE 0x8000
188 #define KSZ9031_ANLPNPR_ACK 0x4000
189 #define KSZ9031_ANLPNPR_MSG_PAGE 0x2000
190 #define KSZ9031_ANLPNPR_ACK2 0x1000
191 #define KSZ9031_ANLPNPR_TOGGLE 0x0800
192 #define KSZ9031_ANLPNPR_MESSAGE 0x07FF
195 #define KSZ9031_GBCR_TEST_MODE 0xE000
196 #define KSZ9031_GBCR_MS_MAN_CONF_EN 0x1000
197 #define KSZ9031_GBCR_MS_MAN_CONF_VAL 0x0800
198 #define KSZ9031_GBCR_PORT_TYPE 0x0400
199 #define KSZ9031_GBCR_1000BT_FD 0x0200
200 #define KSZ9031_GBCR_1000BT_HD 0x0100
203 #define KSZ9031_GBSR_MS_CONF_FAULT 0x8000
204 #define KSZ9031_GBSR_MS_CONF_RES 0x4000
205 #define KSZ9031_GBSR_LOCAL_RECEIVER_STATUS 0x2000
206 #define KSZ9031_GBSR_REMOTE_RECEIVER_STATUS 0x1000
207 #define KSZ9031_GBSR_LP_1000BT_FD 0x0800
208 #define KSZ9031_GBSR_LP_1000BT_HD 0x0400
209 #define KSZ9031_GBSR_IDLE_ERR_COUNT 0x00FF
212 #define KSZ9031_MMDACR_FUNC 0xC000
213 #define KSZ9031_MMDACR_FUNC_ADDR 0x0000
214 #define KSZ9031_MMDACR_FUNC_DATA_NO_POST_INC 0x4000
215 #define KSZ9031_MMDACR_FUNC_DATA_POST_INC_RW 0x8000
216 #define KSZ9031_MMDACR_FUNC_DATA_POST_INC_W 0xC000
217 #define KSZ9031_MMDACR_DEVAD 0x001F
220 #define KSZ9031_GBESR_1000BX_FD 0x8000
221 #define KSZ9031_GBESR_1000BX_HD 0x4000
222 #define KSZ9031_GBESR_1000BT_FD 0x2000
223 #define KSZ9031_GBESR_1000BT_HD 0x1000
226 #define KSZ9031_RLB_REMOTE_LOOPBACK 0x0100
229 #define KSZ9031_LINKMD_TEST_EN 0x8000
230 #define KSZ9031_LINKMD_PAIR 0x3000
231 #define KSZ9031_LINKMD_PAIR_A 0x0000
232 #define KSZ9031_LINKMD_PAIR_B 0x1000
233 #define KSZ9031_LINKMD_PAIR_C 0x2000
234 #define KSZ9031_LINKMD_PAIR_D 0x3000
235 #define KSZ9031_LINKMD_STATUS 0x0300
236 #define KSZ9031_LINKMD_STATUS_NORMAL 0x0000
237 #define KSZ9031_LINKMD_STATUS_OPEN 0x0100
238 #define KSZ9031_LINKMD_STATUS_SHORT 0x0200
239 #define KSZ9031_LINKMD_FAULT_DATA 0x00FF
242 #define KSZ9031_DPMAPCSS_1000BT_LINK_STATUS 0x0004
243 #define KSZ9031_DPMAPCSS_100BTX_LINK_STATUS 0x0002
246 #define KSZ9031_ICSR_JABBER_IE 0x8000
247 #define KSZ9031_ICSR_RECEIVE_ERROR_IE 0x4000
248 #define KSZ9031_ICSR_PAGE_RECEIVED_IE 0x2000
249 #define KSZ9031_ICSR_PAR_DETECT_FAULT_IE 0x1000
250 #define KSZ9031_ICSR_LP_ACK_IE 0x0800
251 #define KSZ9031_ICSR_LINK_DOWN_IE 0x0400
252 #define KSZ9031_ICSR_REMOTE_FAULT_IE 0x0200
253 #define KSZ9031_ICSR_LINK_UP_IE 0x0100
254 #define KSZ9031_ICSR_JABBER_IF 0x0080
255 #define KSZ9031_ICSR_RECEIVE_ERROR_IF 0x0040
256 #define KSZ9031_ICSR_PAGE_RECEIVED_IF 0x0020
257 #define KSZ9031_ICSR_PAR_DETECT_FAULT_IF 0x0010
258 #define KSZ9031_ICSR_LP_ACK_IF 0x0008
259 #define KSZ9031_ICSR_LINK_DOWN_IF 0x0004
260 #define KSZ9031_ICSR_REMOTE_FAULT_IF 0x0002
261 #define KSZ9031_ICSR_LINK_UP_IF 0x0001
264 #define KSZ9031_AUTOMDI_MDI_SET 0x0080
265 #define KSZ9031_AUTOMDI_SWAP_OFF 0x0040
268 #define KSZ9031_PHYCON_INT_LEVEL 0x4000
269 #define KSZ9031_PHYCON_JABBER_EN 0x0200
270 #define KSZ9031_PHYCON_SPEED_1000BT 0x0040
271 #define KSZ9031_PHYCON_SPEED_100BTX 0x0020
272 #define KSZ9031_PHYCON_SPEED_10BT 0x0010
273 #define KSZ9031_PHYCON_DUPLEX_STATUS 0x0008
274 #define KSZ9031_PHYCON_1000BT_MS_STATUS 0x0004
275 #define KSZ9031_PHYCON_LINK_STATUS_CHECK_FAIL 0x0001
278 #define KSZ9031_1000BASE_T_LINK_UP_TIME_CTRL_1000BASE_T_LINK_UP_TIME 0x000E
281 #define KSZ9031_COMMON_CTRL_LED_MODE_OVERRIDE 0x0010
282 #define KSZ9031_COMMON_CTRL_LED_MODE 0x0008
283 #define KSZ9031_COMMON_CTRL_CLK125_EN_STATUS 0x0002
286 #define KSZ9031_STRAP_STAT_LED_MODE_STARP_IN_STATUS 0x0080
287 #define KSZ9031_STRAP_STAT_CLK125_EN_STRAP_IN_STATUS 0x0020
288 #define KSZ9031_STRAP_STAT_PHYAD_STRAP_IN_VALUE 0x0007
291 #define KSZ9031_OP_MODE_STRAP_OVERRIDE_PME_N2_OUT_EN 0x0400
292 #define KSZ9031_OP_MODE_STRAP_OVERRIDE_PME_N1_OUT_EN 0x0100
293 #define KSZ9031_OP_MODE_STRAP_OVERRIDE_CHIP_PD_OVERRIDE 0x0080
294 #define KSZ9031_OP_MODE_STRAP_OVERRIDE_NAND_TREE_OVERRIDE 0x0010
295 #define KSZ9031_OP_MODE_STRAP_OVERRIDE_GMII_MII_OVERRIDE 0x0002
298 #define KSZ9031_OP_MODE_STRAP_STAT_CHIP_PD_STRAP_IN_STATUS 0x0080
299 #define KSZ9031_OP_MODE_STRAP_STAT_NAND_TREE_STRAP_IN_STATUS 0x0010
300 #define KSZ9031_OP_MODE_STRAP_STAT_GMII_MII_STRAP_IN_STATUS 0x0002
303 #define KSZ9031_RGMII_CTRL_SIGNAL_PAD_SKEW_RX_DV 0x00F0
304 #define KSZ9031_RGMII_CTRL_SIGNAL_PAD_SKEW_RX_DV_DEFAULT 0x0070
305 #define KSZ9031_RGMII_CTRL_SIGNAL_PAD_SKEW_TX_EN 0x000F
306 #define KSZ9031_RGMII_CTRL_SIGNAL_PAD_SKEW_TX_EN_DEFAULT 0x0007
309 #define KSZ9031_RGMII_RX_DATA_PAD_SKEW_RXD3 0xF000
310 #define KSZ9031_RGMII_RX_DATA_PAD_SKEW_RXD3_DEFAULT 0x7000
311 #define KSZ9031_RGMII_RX_DATA_PAD_SKEW_RXD2 0x0F00
312 #define KSZ9031_RGMII_RX_DATA_PAD_SKEW_RXD2_DEFAULT 0x0700
313 #define KSZ9031_RGMII_RX_DATA_PAD_SKEW_RXD1 0x00F0
314 #define KSZ9031_RGMII_RX_DATA_PAD_SKEW_RXD1_DEFAULT 0x0070
315 #define KSZ9031_RGMII_RX_DATA_PAD_SKEW_RXD0 0x000F
316 #define KSZ9031_RGMII_RX_DATA_PAD_SKEW_RXD0_DEFAULT 0x0007
319 #define KSZ9031_RGMII_TX_DATA_PAD_SKEW_TXD3 0xF000
320 #define KSZ9031_RGMII_TX_DATA_PAD_SKEW_TXD3_DEFAULT 0x7000
321 #define KSZ9031_RGMII_TX_DATA_PAD_SKEW_TXD2 0x0F00
322 #define KSZ9031_RGMII_TX_DATA_PAD_SKEW_TXD2_DEFAULT 0x0700
323 #define KSZ9031_RGMII_TX_DATA_PAD_SKEW_TXD1 0x00F0
324 #define KSZ9031_RGMII_TX_DATA_PAD_SKEW_TXD1_DEFAULT 0x0070
325 #define KSZ9031_RGMII_TX_DATA_PAD_SKEW_TXD0 0x000F
326 #define KSZ9031_RGMII_TX_DATA_PAD_SKEW_TXD0_DEFAULT 0x0007
329 #define KSZ9031_GMII_CLK_PAD_SKEW_GTX_CLK 0x03E0
330 #define KSZ9031_GMII_CLK_PAD_SKEW_GTX_CLK_DEFAULT 0x01E0
331 #define KSZ9031_GMII_CLK_PAD_SKEW_RX_CLK 0x001F
332 #define KSZ9031_GMII_CLK_PAD_SKEW_RX_CLK_DEFAULT 0x000F
335 #define KSZ9031_WOL_CTRL_PME_OUT_SEL 0xC000
336 #define KSZ9031_WOL_CTRL_MAGIC_PKT_DETECT_EN 0x0040
337 #define KSZ9031_WOL_CTRL_CUSTOM_PKT_TYPE_3_DETECT_EN 0x0020
338 #define KSZ9031_WOL_CTRL_CUSTOM_PKT_TYPE_2_DETECT_EN 0x0010
339 #define KSZ9031_WOL_CTRL_CUSTOM_PKT_TYPE_1_DETECT_EN 0x0008
340 #define KSZ9031_WOL_CTRL_CUSTOM_PKT_TYPE_0_DETECT_EN 0x0004
341 #define KSZ9031_WOL_CTRL_LINK_DOWN_DETECT_EN 0x0002
342 #define KSZ9031_WOL_CTRL_LINK_UP_DETECT_EN 0x0001
345 #define KSZ9031_ANALOG_CTRL4_10BASE_TE_MODE 0x0400
348 #define KSZ9031_EDPD_CTRL_EDPD_MODE_EN 0x0001
uint16_t ksz9031ReadMmdReg(NetInterface *interface, uint8_t devAddr, uint16_t regAddr)
Read MMD register.
void ksz9031EventHandler(NetInterface *interface)
KSZ9031 event handler.
void ksz9031DisableIrq(NetInterface *interface)
Disable interrupts.
void ksz9031Tick(NetInterface *interface)
KSZ9031 timer handler.
void ksz9031WriteMmdReg(NetInterface *interface, uint8_t devAddr, uint16_t regAddr, uint16_t data)
Write MMD register.
void ksz9031InitHook(NetInterface *interface)
KSZ9031 custom configuration.
void ksz9031DumpPhyReg(NetInterface *interface)
Dump PHY registers for debugging purpose.
void ksz9031EnableIrq(NetInterface *interface)
Enable interrupts.
const PhyDriver ksz9031PhyDriver
KSZ9031 Ethernet PHY driver.
void ksz9031WritePhyReg(NetInterface *interface, uint8_t address, uint16_t data)
Write PHY register.
Network interface controller abstraction layer.
uint16_t ksz9031ReadPhyReg(NetInterface *interface, uint8_t address)
Read PHY register.
error_t ksz9031Init(NetInterface *interface)
KSZ9031 PHY transceiver initialization.