ksz8721_driver.h
Go to the documentation of this file.
1 /**
2  * @file ksz8721_driver.h
3  * @brief KSZ8721 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 _KSZ8721_DRIVER_H
32 #define _KSZ8721_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //PHY address
38 #ifndef KSZ8721_PHY_ADDR
39  #define KSZ8721_PHY_ADDR 1
40 #elif (KSZ8721_PHY_ADDR < 0 || KSZ8721_PHY_ADDR > 31)
41  #error KSZ8721_PHY_ADDR parameter is not valid
42 #endif
43 
44 //KSZ8721 PHY registers
45 #define KSZ8721_BMCR 0x00
46 #define KSZ8721_BMSR 0x01
47 #define KSZ8721_PHYID1 0x02
48 #define KSZ8721_PHYID2 0x03
49 #define KSZ8721_ANAR 0x04
50 #define KSZ8721_ANLPAR 0x05
51 #define KSZ8721_ANER 0x06
52 #define KSZ8721_ANNPR 0x07
53 #define KSZ8721_ANLPNPR 0x08
54 #define KSZ8721_RXERCTR 0x15
55 #define KSZ8721_ICSR 0x1B
56 #define KSZ8721_PHYCON 0x1F
57 
58 //Basic Control register
59 #define KSZ8721_BMCR_RESET 0x8000
60 #define KSZ8721_BMCR_LOOPBACK 0x4000
61 #define KSZ8721_BMCR_SPEED_SEL 0x2000
62 #define KSZ8721_BMCR_AN_EN 0x1000
63 #define KSZ8721_BMCR_POWER_DOWN 0x0800
64 #define KSZ8721_BMCR_ISOLATE 0x0400
65 #define KSZ8721_BMCR_RESTART_AN 0x0200
66 #define KSZ8721_BMCR_DUPLEX_MODE 0x0100
67 #define KSZ8721_BMCR_COL_TEST 0x0080
68 #define KSZ8721_BMCR_TX_DIS 0x0001
69 
70 //Basic Status register
71 #define KSZ8721_BMSR_100BT4 0x8000
72 #define KSZ8721_BMSR_100BTX_FD 0x4000
73 #define KSZ8721_BMSR_100BTX_HD 0x2000
74 #define KSZ8721_BMSR_10BT_FD 0x1000
75 #define KSZ8721_BMSR_10BT_HD 0x0800
76 #define KSZ8721_BMSR_NO_PREAMBLE 0x0040
77 #define KSZ8721_BMSR_AN_COMPLETE 0x0020
78 #define KSZ8721_BMSR_REMOTE_FAULT 0x0010
79 #define KSZ8721_BMSR_AN_CAPABLE 0x0008
80 #define KSZ8721_BMSR_LINK_STATUS 0x0004
81 #define KSZ8721_BMSR_JABBER_DETECT 0x0002
82 #define KSZ8721_BMSR_EXTENDED_CAPABLE 0x0001
83 
84 //PHY Identifier 1 register
85 #define KSZ8721_PHYID1_PHY_ID_MSB 0xFFFF
86 #define KSZ8721_PHYID1_PHY_ID_MSB_DEFAULT 0x0022
87 
88 //PHY Identifier 2 register
89 #define KSZ8721_PHYID2_PHY_ID_LSB 0xFC00
90 #define KSZ8721_PHYID2_PHY_ID_LSB_DEFAULT 0x1400
91 #define KSZ8721_PHYID2_MODEL_NUM 0x03F0
92 #define KSZ8721_PHYID2_MODEL_NUM_DEFAULT 0x0210
93 #define KSZ8721_PHYID2_REVISION_NUM 0x000F
94 
95 //Auto-Negotiation Advertisement register
96 #define KSZ8721_ANAR_NEXT_PAGE 0x8000
97 #define KSZ8721_ANAR_REMOTE_FAULT 0x2000
98 #define KSZ8721_ANAR_PAUSE 0x0C00
99 #define KSZ8721_ANAR_100BT4 0x0200
100 #define KSZ8721_ANAR_100BTX_FD 0x0100
101 #define KSZ8721_ANAR_100BTX_HD 0x0080
102 #define KSZ8721_ANAR_10BT_FD 0x0040
103 #define KSZ8721_ANAR_10BT_HD 0x0020
104 #define KSZ8721_ANAR_SELECTOR 0x001F
105 #define KSZ8721_ANAR_SELECTOR_DEFAULT 0x0001
106 
107 //Auto-Negotiation Link Partner Ability register
108 #define KSZ8721_ANLPAR_NEXT_PAGE 0x8000
109 #define KSZ8721_ANLPAR_ACK 0x4000
110 #define KSZ8721_ANLPAR_REMOTE_FAULT 0x2000
111 #define KSZ8721_ANLPAR_PAUSE 0x0C00
112 #define KSZ8721_ANLPAR_100BT4 0x0200
113 #define KSZ8721_ANLPAR_100BTX_FD 0x0100
114 #define KSZ8721_ANLPAR_100BTX_HD 0x0080
115 #define KSZ8721_ANLPAR_10BT_FD 0x0040
116 #define KSZ8721_ANLPAR_10BT_HD 0x0020
117 #define KSZ8721_ANLPAR_SELECTOR 0x001F
118 #define KSZ8721_ANLPAR_SELECTOR_DEFAULT 0x0001
119 
120 //Auto-Negotiation Expansion register
121 #define KSZ8721_ANER_PAR_DETECT_FAULT 0x0010
122 #define KSZ8721_ANER_LP_NEXT_PAGE_ABLE 0x0008
123 #define KSZ8721_ANER_NEXT_PAGE_ABLE 0x0004
124 #define KSZ8721_ANER_PAGE_RECEIVED 0x0002
125 #define KSZ8721_ANER_LP_AN_ABLE 0x0001
126 
127 //Auto-Negotiation Next Page register
128 #define KSZ8721_ANNPR_NEXT_PAGE 0x8000
129 #define KSZ8721_ANNPR_MSG_PAGE 0x2000
130 #define KSZ8721_ANNPR_ACK2 0x1000
131 #define KSZ8721_ANNPR_TOGGLE 0x0800
132 #define KSZ8721_ANNPR_MESSAGE 0x07FF
133 
134 //Link Partner Next Page Ability register
135 #define KSZ8721_ANLPNPR_NEXT_PAGE 0x8000
136 #define KSZ8721_ANLPNPR_ACK 0x4000
137 #define KSZ8721_ANLPNPR_MSG_PAGE 0x2000
138 #define KSZ8721_ANLPNPR_ACK2 0x1000
139 #define KSZ8721_ANLPNPR_TOGGLE 0x0800
140 #define KSZ8721_ANLPNPR_MESSAGE 0x07FF
141 
142 //Interrupt Control/Status register
143 #define KSZ8721_ICSR_JABBER_IE 0x8000
144 #define KSZ8721_ICSR_RECEIVE_ERROR_IE 0x4000
145 #define KSZ8721_ICSR_PAGE_RECEIVED_IE 0x2000
146 #define KSZ8721_ICSR_PAR_DETECT_FAULT_IE 0x1000
147 #define KSZ8721_ICSR_LP_ACK_IE 0x0800
148 #define KSZ8721_ICSR_LINK_DOWN_IE 0x0400
149 #define KSZ8721_ICSR_REMOTE_FAULT_IE 0x0200
150 #define KSZ8721_ICSR_LINK_UP_IE 0x0100
151 #define KSZ8721_ICSR_JABBER_IF 0x0080
152 #define KSZ8721_ICSR_RECEIVE_ERROR_IF 0x0040
153 #define KSZ8721_ICSR_PAGE_RECEIVED_IF 0x0020
154 #define KSZ8721_ICSR_PAR_DETECT_FAULT_IF 0x0010
155 #define KSZ8721_ICSR_LP_ACK_IF 0x0008
156 #define KSZ8721_ICSR_LINK_DOWN_IF 0x0004
157 #define KSZ8721_ICSR_REMOTE_FAULT_IF 0x0002
158 #define KSZ8721_ICSR_LINK_UP_IF 0x0001
159 
160 //100BASE-TX PHY Control register
161 #define KSZ8721_PHYCON_PAIR_SWAP_DIS 0x2000
162 #define KSZ8721_PHYCON_ENERGY_DETECT 0x1000
163 #define KSZ8721_PHYCON_FORCE_LINK 0x0800
164 #define KSZ8721_PHYCON_POWER_SAVING 0x0400
165 #define KSZ8721_PHYCON_INT_LEVEL 0x0200
166 #define KSZ8721_PHYCON_JABBER_EN 0x0100
167 #define KSZ8721_PHYCON_AN_COMPLETE 0x0080
168 #define KSZ8721_PHYCON_PAUSE_EN 0x0040
169 #define KSZ8721_PHYCON_PHY_ISOLATE 0x0020
170 #define KSZ8721_PHYCON_OP_MODE 0x001C
171 #define KSZ8721_PHYCON_OP_MODE_AN 0x0000
172 #define KSZ8721_PHYCON_OP_MODE_10BT_HD 0x0004
173 #define KSZ8721_PHYCON_OP_MODE_100BTX_HD 0x0008
174 #define KSZ8721_PHYCON_OP_MODE_10BT_FD 0x0014
175 #define KSZ8721_PHYCON_OP_MODE_100BTX_FD 0x0018
176 #define KSZ8721_PHYCON_OP_MODE_ISOLATE 0x001C
177 #define KSZ8721_PHYCON_SQE_TEST_EN 0x0002
178 #define KSZ8721_PHYCON_DATA_SCRAMBLING_DIS 0x0001
179 
180 //C++ guard
181 #ifdef __cplusplus
182 extern "C" {
183 #endif
184 
185 //KSZ8721 Ethernet PHY driver
186 extern const PhyDriver ksz8721PhyDriver;
187 
188 //KSZ8721 related functions
189 error_t ksz8721Init(NetInterface *interface);
190 
191 void ksz8721Tick(NetInterface *interface);
192 
193 void ksz8721EnableIrq(NetInterface *interface);
194 void ksz8721DisableIrq(NetInterface *interface);
195 
196 void ksz8721EventHandler(NetInterface *interface);
197 
198 void ksz8721WritePhyReg(NetInterface *interface, uint8_t address,
199  uint16_t data);
200 
201 uint16_t ksz8721ReadPhyReg(NetInterface *interface, uint8_t address);
202 
203 void ksz8721DumpPhyReg(NetInterface *interface);
204 
205 //C++ guard
206 #ifdef __cplusplus
207 }
208 #endif
209 
210 #endif
PHY driver.
Definition: nic.h:214
void ksz8721DumpPhyReg(NetInterface *interface)
Dump PHY registers for debugging purpose.
uint16_t ksz8721ReadPhyReg(NetInterface *interface, uint8_t address)
Read PHY register.
void ksz8721WritePhyReg(NetInterface *interface, uint8_t address, uint16_t data)
Write PHY register.
void ksz8721DisableIrq(NetInterface *interface)
Disable interrupts.
error_t
Error codes.
Definition: error.h:42
#define NetInterface
Definition: net.h:36
const PhyDriver ksz8721PhyDriver
KSZ8721 Ethernet PHY driver.
Network interface controller abstraction layer.
error_t ksz8721Init(NetInterface *interface)
KSZ8721 PHY transceiver initialization.
void ksz8721EnableIrq(NetInterface *interface)
Enable interrupts.
Ipv6Addr address
uint8_t data[]
Definition: dtls_misc.h:176
void ksz8721EventHandler(NetInterface *interface)
KSZ8721 event handler.
void ksz8721Tick(NetInterface *interface)
KSZ8721 timer handler.