lan8700_driver.h
Go to the documentation of this file.
1 /**
2  * @file lan8700_driver.h
3  * @brief LAN8700 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.0
29  **/
30 
31 #ifndef _LAN8700_DRIVER_H
32 #define _LAN8700_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //PHY address
38 #ifndef LAN8700_PHY_ADDR
39  #define LAN8700_PHY_ADDR 0
40 #elif (LAN8700_PHY_ADDR < 0 || LAN8700_PHY_ADDR > 31)
41  #error LAN8700_PHY_ADDR parameter is not valid
42 #endif
43 
44 //LAN8700 PHY registers
45 #define LAN8700_BMCR 0x00
46 #define LAN8700_BMSR 0x01
47 #define LAN8700_PHYID1 0x02
48 #define LAN8700_PHYID2 0x03
49 #define LAN8700_ANAR 0x04
50 #define LAN8700_ANLPAR 0x05
51 #define LAN8700_ANER 0x06
52 #define LAN8700_SRR 0x10
53 #define LAN8700_MCSR 0x11
54 #define LAN8700_SMR 0x12
55 #define LAN8700_SECR 0x1A
56 #define LAN8700_SCSIR 0x1B
57 #define LAN8700_ISR 0x1D
58 #define LAN8700_IMR 0x1E
59 #define LAN8700_PSCSR 0x1F
60 
61 //Basic Control register
62 #define LAN8700_BMCR_RESET 0x8000
63 #define LAN8700_BMCR_LOOPBACK 0x4000
64 #define LAN8700_BMCR_SPEED_SEL 0x2000
65 #define LAN8700_BMCR_AN_EN 0x1000
66 #define LAN8700_BMCR_POWER_DOWN 0x0800
67 #define LAN8700_BMCR_ISOLATE 0x0400
68 #define LAN8700_BMCR_RESTART_AN 0x0200
69 #define LAN8700_BMCR_DUPLEX_MODE 0x0100
70 #define LAN8700_BMCR_COL_TEST 0x0080
71 
72 //Basic Status register
73 #define LAN8700_BMSR_100BT4 0x8000
74 #define LAN8700_BMSR_100BTX_FD 0x4000
75 #define LAN8700_BMSR_100BTX_HD 0x2000
76 #define LAN8700_BMSR_10BT_FD 0x1000
77 #define LAN8700_BMSR_10BT_HD 0x0800
78 #define LAN8700_BMSR_AN_COMPLETE 0x0020
79 #define LAN8700_BMSR_REMOTE_FAULT 0x0010
80 #define LAN8700_BMSR_AN_CAPABLE 0x0008
81 #define LAN8700_BMSR_LINK_STATUS 0x0004
82 #define LAN8700_BMSR_JABBER_DETECT 0x0002
83 #define LAN8700_BMSR_EXTENDED_CAPABLE 0x0001
84 
85 //PHY Identifier 1 register
86 #define LAN8700_PHYID1_PHY_ID_MSB 0xFFFF
87 #define LAN8700_PHYID1_PHY_ID_MSB_DEFAULT 0x0007
88 
89 //PHY Identifier 2 register
90 #define LAN8700_PHYID2_PHY_ID_LSB 0xFC00
91 #define LAN8700_PHYID2_PHY_ID_LSB_DEFAULT 0xC000
92 #define LAN8700_PHYID2_MODEL_NUM 0x03F0
93 #define LAN8700_PHYID2_MODEL_NUM_DEFAULT 0x00C0
94 #define LAN8700_PHYID2_REVISION_NUM 0x000F
95 
96 //Auto-Negotiation Advertisement register
97 #define LAN8700_ANAR_NEXT_PAGE 0x8000
98 #define LAN8700_ANAR_REMOTE_FAULT 0x2000
99 #define LAN8700_ANAR_PAUSE 0x0C00
100 #define LAN8700_ANAR_100BT4 0x0200
101 #define LAN8700_ANAR_100BTX_FD 0x0100
102 #define LAN8700_ANAR_100BTX_HD 0x0080
103 #define LAN8700_ANAR_10BT_FD 0x0040
104 #define LAN8700_ANAR_10BT_HD 0x0020
105 #define LAN8700_ANAR_SELECTOR 0x001F
106 #define LAN8700_ANAR_SELECTOR_DEFAULT 0x0001
107 
108 //Auto-Negotiation Link Partner Ability register
109 #define LAN8700_ANLPAR_NEXT_PAGE 0x8000
110 #define LAN8700_ANLPAR_ACK 0x4000
111 #define LAN8700_ANLPAR_REMOTE_FAULT 0x2000
112 #define LAN8700_ANLPAR_PAUSE 0x0400
113 #define LAN8700_ANLPAR_100BT4 0x0200
114 #define LAN8700_ANLPAR_100BTX_FD 0x0100
115 #define LAN8700_ANLPAR_100BTX_HD 0x0080
116 #define LAN8700_ANLPAR_10BT_FD 0x0040
117 #define LAN8700_ANLPAR_10BT_HD 0x0020
118 #define LAN8700_ANLPAR_SELECTOR 0x001F
119 #define LAN8700_ANLPAR_SELECTOR_DEFAULT 0x0001
120 
121 //Auto-Negotiation Expansion register
122 #define LAN8700_ANER_PAR_DETECT_FAULT 0x0010
123 #define LAN8700_ANER_LP_NEXT_PAGE_ABLE 0x0008
124 #define LAN8700_ANER_NEXT_PAGE_ABLE 0x0004
125 #define LAN8700_ANER_PAGE_RECEIVED 0x0002
126 #define LAN8700_ANER_LP_AN_ABLE 0x0001
127 
128 //Silicon Revision register
129 #define LAN8700_SRR_SILICON_REV 0x03C0
130 
131 //Mode Control/Status register
132 #define LAN8700_MCSR_EDPWRDOWN 0x2000
133 #define LAN8700_MCSR_LOWSQEN 0x0800
134 #define LAN8700_MCSR_MDPREBP 0x0400
135 #define LAN8700_MCSR_FARLOOPBACK 0x0200
136 #define LAN8700_MCSR_ALTINT 0x0040
137 #define LAN8700_MCSR_PHYADBP 0x0008
138 #define LAN8700_MCSR_FORCE_GOOD_LINK_STATUS 0x0004
139 #define LAN8700_MCSR_ENERGYON 0x0002
140 
141 //Special Modes register
142 #define LAN8700_SMR_MIIMODE 0x4000
143 #define LAN8700_SMR_MODE 0x00E0
144 #define LAN8700_SMR_PHYAD 0x001F
145 
146 //Symbol Error Counter register
147 #define LAN8700_SECR_SYM_ERR_CNT 0xFFFF
148 
149 //Special Control/Status Indication register
150 #define LAN8700_SCSIR_AMDIXCTRL 0x8000
151 #define LAN8700_SCSIR_CH_SELECT 0x2000
152 #define LAN8700_SCSIR_SQEOFF 0x0800
153 #define LAN8700_SCSIR_XPOL 0x0010
154 
155 //Interrupt Source register
156 #define LAN8700_ISR_ENERGYON 0x0080
157 #define LAN8700_ISR_AN_COMPLETE 0x0040
158 #define LAN8700_ISR_REMOTE_FAULT 0x0020
159 #define LAN8700_ISR_LINK_DOWN 0x0010
160 #define LAN8700_ISR_AN_LP_ACK 0x0008
161 #define LAN8700_ISR_PAR_DETECT_FAULT 0x0004
162 #define LAN8700_ISR_AN_PAGE_RECEIVED 0x0002
163 
164 //Interrupt Mask register
165 #define LAN8700_IMR_ENERGYON 0x0080
166 #define LAN8700_IMR_AN_COMPLETE 0x0040
167 #define LAN8700_IMR_REMOTE_FAULT 0x0020
168 #define LAN8700_IMR_LINK_DOWN 0x0010
169 #define LAN8700_IMR_AN_LP_ACK 0x0008
170 #define LAN8700_IMR_PAR_DETECT_FAULT 0x0004
171 #define LAN8700_IMR_AN_PAGE_RECEIVED 0x0002
172 
173 //PHY Special Control/Status register
174 #define LAN8700_PSCSR_AUTODONE 0x1000
175 #define LAN8700_PSCSR_4B5B_EN 0x0040
176 #define LAN8700_PSCSR_HCDSPEED 0x001C
177 #define LAN8700_PSCSR_HCDSPEED_10BT_HD 0x0004
178 #define LAN8700_PSCSR_HCDSPEED_100BTX_HD 0x0008
179 #define LAN8700_PSCSR_HCDSPEED_10BT_FD 0x0014
180 #define LAN8700_PSCSR_HCDSPEED_100BTX_FD 0x0018
181 #define LAN8700_PSCSR_SCRAMBLE_DIS 0x0001
182 
183 //C++ guard
184 #ifdef __cplusplus
185 extern "C" {
186 #endif
187 
188 //LAN8700 Ethernet PHY driver
189 extern const PhyDriver lan8700PhyDriver;
190 
191 //LAN8700 related functions
192 error_t lan8700Init(NetInterface *interface);
193 void lan8700InitHook(NetInterface *interface);
194 
195 void lan8700Tick(NetInterface *interface);
196 
197 void lan8700EnableIrq(NetInterface *interface);
198 void lan8700DisableIrq(NetInterface *interface);
199 
200 void lan8700EventHandler(NetInterface *interface);
201 
202 void lan8700WritePhyReg(NetInterface *interface, uint8_t address,
203  uint16_t data);
204 
205 uint16_t lan8700ReadPhyReg(NetInterface *interface, uint8_t address);
206 
207 void lan8700DumpPhyReg(NetInterface *interface);
208 
209 //C++ guard
210 #ifdef __cplusplus
211 }
212 #endif
213 
214 #endif
error_t
Error codes.
Definition: error.h:43
uint8_t data[]
Definition: ethernet.h:222
Ipv6Addr address[]
Definition: ipv6.h:316
uint16_t lan8700ReadPhyReg(NetInterface *interface, uint8_t address)
Read PHY register.
void lan8700Tick(NetInterface *interface)
LAN8700 timer handler.
void lan8700InitHook(NetInterface *interface)
LAN8700 custom configuration.
void lan8700WritePhyReg(NetInterface *interface, uint8_t address, uint16_t data)
Write PHY register.
void lan8700EventHandler(NetInterface *interface)
LAN8700 event handler.
error_t lan8700Init(NetInterface *interface)
LAN8700 PHY transceiver initialization.
void lan8700EnableIrq(NetInterface *interface)
Enable interrupts.
void lan8700DisableIrq(NetInterface *interface)
Disable interrupts.
void lan8700DumpPhyReg(NetInterface *interface)
Dump PHY registers for debugging purpose.
const PhyDriver lan8700PhyDriver
LAN8700 Ethernet PHY driver.
#define NetInterface
Definition: net.h:36
Network interface controller abstraction layer.
Ethernet PHY driver.
Definition: nic.h:308