ip101_driver.h
Go to the documentation of this file.
1 /**
2  * @file ip101_driver.h
3  * @brief IC+ IP101 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 _IP101_DRIVER_H
32 #define _IP101_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //PHY address
38 #ifndef IP101_PHY_ADDR
39  #define IP101_PHY_ADDR 1
40 #elif (IP101_PHY_ADDR < 0 || IP101_PHY_ADDR > 31)
41  #error IP101_PHY_ADDR parameter is not valid
42 #endif
43 
44 //IP101 PHY registers
45 #define IP101_BMCR 0x00
46 #define IP101_BMSR 0x01
47 #define IP101_PHYID1 0x02
48 #define IP101_PHYID2 0x03
49 #define IP101_ANAR 0x04
50 #define IP101_ANLPAR 0x05
51 #define IP101_ANER 0x06
52 #define IP101_ANNPTR 0x07
53 #define IP101_ANLPNPR 0x08
54 #define IP101_MMDACR 0x0D
55 #define IP101_MMDAADR 0x0E
56 #define IP101_PHYSCR 0x10
57 #define IP101_ICSR 0x11
58 #define IP101_PHYSMR 0x12
59 #define IP101_IOSCR 0x1D
60 #define IP101_PHYMCSSR 0x1E
61 
62 //IP101 MMD registers
63 #define IP101_PCS_CTRL1 0x03, 0x00
64 #define IP101_PCS_STAT1 0x03, 0x01
65 #define IP101_EEE_CAPABILITY 0x03, 0x14
66 #define IP101_EEE_WAKE_ERROR_COUNT 0x03, 0x16
67 #define IP101_EEE_ADV 0x07, 0x3C
68 #define IP101_EEE_LP_ABILITY 0x07, 0x3D
69 
70 //Control register
71 #define IP101_BMCR_RESET 0x8000
72 #define IP101_BMCR_LOOPBACK 0x4000
73 #define IP101_BMCR_SPEED_SEL 0x2000
74 #define IP101_BMCR_AN_EN 0x1000
75 #define IP101_BMCR_POWER_DOWN 0x0800
76 #define IP101_BMCR_ISOLATE 0x0400
77 #define IP101_BMCR_RESTART_AN 0x0200
78 #define IP101_BMCR_DUPLEX_MODE 0x0100
79 #define IP101_BMCR_COL_TEST 0x0080
80 
81 //Basic Status register
82 #define IP101_BMSR_100BT4 0x8000
83 #define IP101_BMSR_100BTX_FD 0x4000
84 #define IP101_BMSR_100BTX_HD 0x2000
85 #define IP101_BMSR_10BT_FD 0x1000
86 #define IP101_BMSR_10BT_HD 0x0800
87 #define IP101_BMSR_MF_PREAMBLE_SUPPR 0x0040
88 #define IP101_BMSR_AN_COMPLETE 0x0020
89 #define IP101_BMSR_REMOTE_FAULT 0x0010
90 #define IP101_BMSR_AN_CAPABLE 0x0008
91 #define IP101_BMSR_LINK_STATUS 0x0004
92 #define IP101_BMSR_JABBER_DETECT 0x0002
93 #define IP101_BMSR_EXTENDED_CAPABLE 0x0001
94 
95 //PHY Identifier 1 register
96 #define IP101_PHYID1_PHY_ID_MSB 0xFFFF
97 #define IP101_PHYID1_PHY_ID_MSB_DEFAULT 0x0243
98 
99 //PHY Identifier 2 register
100 #define IP101_PHYID2__DEFAULT 0xC54
101 
102 //Auto-Negotiation Advertisement register
103 #define IP101_ANAR_NEXT_PAGE 0x8000
104 #define IP101_ANAR_REMOTE_FAULT 0x2000
105 #define IP101_ANAR_ASYM_PAUSE 0x0800
106 #define IP101_ANAR_PAUSE 0x0400
107 #define IP101_ANAR_100BT4 0x0200
108 #define IP101_ANAR_100BTX_FD 0x0100
109 #define IP101_ANAR_100BTX_HD 0x0080
110 #define IP101_ANAR_10BT_FD 0x0040
111 #define IP101_ANAR_10BT_HD 0x0020
112 #define IP101_ANAR_SELECTOR 0x001F
113 #define IP101_ANAR_SELECTOR_DEFAULT 0x0001
114 
115 //Auto-Negotiation Link Partner Ability register
116 #define IP101_ANLPAR_NEXT_PAGE 0x8000
117 #define IP101_ANLPAR_ACK 0x4000
118 #define IP101_ANLPAR_REMOTE_FAULT 0x2000
119 #define IP101_ANLPAR_ASYM_PAUSE 0x0800
120 #define IP101_ANLPAR_PAUSE 0x0400
121 #define IP101_ANLPAR_100BT4 0x0200
122 #define IP101_ANLPAR_100BTX_FD 0x0100
123 #define IP101_ANLPAR_100BTX_HD 0x0080
124 #define IP101_ANLPAR_10BT_FD 0x0040
125 #define IP101_ANLPAR_10BT_HD 0x0020
126 #define IP101_ANLPAR_SELECTOR 0x001F
127 #define IP101_ANLPAR_SELECTOR_DEFAULT 0x0001
128 
129 //Auto-Negotiation Expansion register
130 #define IP101_ANER_MLF 0x0010
131 #define IP101_ANER_LP_NP_ABLE 0x0008
132 #define IP101_ANER_NP_ABLE 0x0004
133 #define IP101_ANER_PAGE_RX 0x0002
134 #define IP101_ANER_LP_AN_ABLE 0x0001
135 
136 //Auto-Negotiation Next Page Transmit register
137 #define IP101_ANNPTR_NEXT_PAGE 0x8000
138 #define IP101_ANNPTR_MSG_PAGE 0x2000
139 #define IP101_ANNPTR_ACK2 0x1000
140 #define IP101_ANNPTR_TOGGLE 0x0800
141 #define IP101_ANNPTR_MESSAGE 0x07FF
142 
143 //Auto-Negotiation Link Partner Next Page register
144 #define IP101_ANLPNPR_NEXT_PAGE 0x8000
145 #define IP101_ANLPNPR_ACK 0x4000
146 #define IP101_ANLPNPR_MSG_PAGE 0x2000
147 #define IP101_ANLPNPR_ACK2 0x1000
148 #define IP101_ANLPNPR_TOGGLE 0x0800
149 #define IP101_ANLPNPR_MESSAGE 0x07FF
150 
151 //MMD Access Control register
152 #define IP101_MMDACR_FUNC 0xC000
153 #define IP101_MMDACR_FUNC_ADDR 0x0000
154 #define IP101_MMDACR_FUNC_DATA_NO_POST_INC 0x4000
155 #define IP101_MMDACR_FUNC_DATA_POST_INC_RW 0x8000
156 #define IP101_MMDACR_FUNC_DATA_POST_INC_W 0xC000
157 #define IP101_MMDACR_DEVAD 0x001F
158 
159 //PHY Specific Control register
160 #define IP101_PHYSCR_RMII_V10 0x2000
161 #define IP101_PHYSCR_RMII_V12 0x1000
162 #define IP101_PHYSCR_AUTO_MDIX_DIS 0x0800
163 #define IP101_PHYSCR_JABBER_EN 0x0200
164 #define IP101_PHYSCR_FEF_DIS 0x0100
165 #define IP101_PHYSCR_NWAY_PSAVE_DIS 0x0080
166 #define IP101_PHYSCR_BYPASS_DSP_RESET 0x0020
167 #define IP101_PHYSCR_REPEATER_MODE 0x0004
168 #define IP101_PHYSCR_LDPS_EN 0x0002
169 #define IP101_PHYSCR_ANALOG_OFF 0x0001
170 
171 //Interrupt Control/Status register
172 #define IP101_ICSR_INTR_EN 0x8000
173 #define IP101_ICSR_ALL_MASK 0x0800
174 #define IP101_ICSR_SPEED_MASK 0x0400
175 #define IP101_ICSR_DUPLEX_MASK 0x0200
176 #define IP101_ICSR_LINK_MASK 0x0100
177 #define IP101_ICSR_INTR_STATUS 0x0008
178 #define IP101_ICSR_SPEED_CHANGE 0x0004
179 #define IP101_ICSR_DUPLEX_CHANGE 0x0002
180 #define IP101_ICSR_LINK_CHANGE 0x0001
181 
182 //PHY Status Monitoring register
183 #define IP101_PHYSMR_SPEED 0x4000
184 #define IP101_PHYSMR_DUPLEX 0x2000
185 #define IP101_PHYSMR_AN_COMPLETE 0x0800
186 #define IP101_PHYSMR_LINK_UP 0x0400
187 #define IP101_PHYSMR_MDIX 0x0200
188 #define IP101_PHYSMR_POLARITY 0x0100
189 #define IP101_PHYSMR_JABBER 0x0080
190 #define IP101_PHYSMR_AN_ARBIT_STATE 0x000F
191 
192 //Digital I/O Specific Control register
193 #define IP101_IOSCR_RMII_WITH_ER 0x0080
194 #define IP101_IOSCR_SEL_INTR32 0x0004
195 
196 //PHY MDI/MDIX Control and Specific Status register
197 #define IP101_PHYMCSSR_LINK_UP 0x0100
198 #define IP101_PHYMCSSR_FORCE_MDIX 0x0008
199 #define IP101_PHYMCSSR_OP_MODE 0x0007
200 #define IP101_PHYMCSSR_OP_MODE_LINK_OFF 0x0000
201 #define IP101_PHYMCSSR_OP_MODE_10M_HD 0x0001
202 #define IP101_PHYMCSSR_OP_MODE_100M_HD 0x0002
203 #define IP101_PHYMCSSR_OP_MODE_10M_FD 0x0005
204 #define IP101_PHYMCSSR_OP_MODE_100M_FD 0x0006
205 
206 //C++ guard
207 #ifdef __cplusplus
208 extern "C" {
209 #endif
210 
211 //IP101 Ethernet PHY driver
212 extern const PhyDriver ip101PhyDriver;
213 
214 //IP101 related functions
215 error_t ip101Init(NetInterface *interface);
216 void ip101InitHook(NetInterface *interface);
217 
218 void ip101Tick(NetInterface *interface);
219 
220 void ip101EnableIrq(NetInterface *interface);
221 void ip101DisableIrq(NetInterface *interface);
222 
223 void ip101EventHandler(NetInterface *interface);
224 
225 void ip101WritePhyReg(NetInterface *interface, uint8_t address,
226  uint16_t data);
227 
228 uint16_t ip101ReadPhyReg(NetInterface *interface, uint8_t address);
229 
230 void ip101DumpPhyReg(NetInterface *interface);
231 
232 void ip101WriteMmdReg(NetInterface *interface, uint8_t devAddr,
233  uint16_t regAddr, uint16_t data);
234 
235 uint16_t ip101ReadMmdReg(NetInterface *interface, uint8_t devAddr,
236  uint16_t regAddr);
237 
238 //C++ guard
239 #ifdef __cplusplus
240 }
241 #endif
242 
243 #endif
const PhyDriver ip101PhyDriver
IP101 Ethernet PHY driver.
Definition: ip101_driver.c:44
void ip101DumpPhyReg(NetInterface *interface)
Dump PHY registers for debugging purpose.
Definition: ip101_driver.c:289
Ethernet PHY driver.
Definition: nic.h:311
uint8_t data[]
Definition: ethernet.h:222
error_t ip101Init(NetInterface *interface)
IP101 PHY transceiver initialization.
Definition: ip101_driver.c:60
void ip101EnableIrq(NetInterface *interface)
Enable interrupts.
Definition: ip101_driver.c:151
void ip101Tick(NetInterface *interface)
IP101 timer handler.
Definition: ip101_driver.c:117
void ip101WritePhyReg(NetInterface *interface, uint8_t address, uint16_t data)
Write PHY register.
Definition: ip101_driver.c:239
uint16_t ip101ReadMmdReg(NetInterface *interface, uint8_t devAddr, uint16_t regAddr)
Read MMD register.
Definition: ip101_driver.c:341
error_t
Error codes.
Definition: error.h:43
void ip101WriteMmdReg(NetInterface *interface, uint8_t devAddr, uint16_t regAddr, uint16_t data)
Write MMD register.
Definition: ip101_driver.c:314
#define NetInterface
Definition: net.h:36
void ip101InitHook(NetInterface *interface)
IP101 custom configuration.
Definition: ip101_driver.c:107
void ip101DisableIrq(NetInterface *interface)
Disable interrupts.
Definition: ip101_driver.c:161
uint16_t regAddr
Ipv6Addr address[]
Definition: ipv6.h:325
Network interface controller abstraction layer.
uint16_t ip101ReadPhyReg(NetInterface *interface, uint8_t address)
Read PHY register.
Definition: ip101_driver.c:263
void ip101EventHandler(NetInterface *interface)
IP101 event handler.
Definition: ip101_driver.c:171