lan8720_driver.h
Go to the documentation of this file.
1 /**
2  * @file lan8720_driver.h
3  * @brief LAN8720 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 _LAN8720_DRIVER_H
32 #define _LAN8720_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //PHY address
38 #ifndef LAN8720_PHY_ADDR
39  #define LAN8720_PHY_ADDR 0
40 #elif (LAN8720_PHY_ADDR < 0 || LAN8720_PHY_ADDR > 31)
41  #error LAN8720_PHY_ADDR parameter is not valid
42 #endif
43 
44 //LAN8720 PHY registers
45 #define LAN8720_BMCR 0x00
46 #define LAN8720_BMSR 0x01
47 #define LAN8720_PHYID1 0x02
48 #define LAN8720_PHYID2 0x03
49 #define LAN8720_ANAR 0x04
50 #define LAN8720_ANLPAR 0x05
51 #define LAN8720_ANER 0x06
52 #define LAN8720_MCSR 0x11
53 #define LAN8720_SMR 0x12
54 #define LAN8720_SECR 0x1A
55 #define LAN8720_SCSIR 0x1B
56 #define LAN8720_ISR 0x1D
57 #define LAN8720_IMR 0x1E
58 #define LAN8720_PSCSR 0x1F
59 
60 //Basic Control register
61 #define LAN8720_BMCR_RESET 0x8000
62 #define LAN8720_BMCR_LOOPBACK 0x4000
63 #define LAN8720_BMCR_SPEED_SEL 0x2000
64 #define LAN8720_BMCR_AN_EN 0x1000
65 #define LAN8720_BMCR_POWER_DOWN 0x0800
66 #define LAN8720_BMCR_ISOLATE 0x0400
67 #define LAN8720_BMCR_RESTART_AN 0x0200
68 #define LAN8720_BMCR_DUPLEX_MODE 0x0100
69 
70 //Basic Status register
71 #define LAN8720_BMSR_100BT4 0x8000
72 #define LAN8720_BMSR_100BTX_FD 0x4000
73 #define LAN8720_BMSR_100BTX_HD 0x2000
74 #define LAN8720_BMSR_10BT_FD 0x1000
75 #define LAN8720_BMSR_10BT_HD 0x0800
76 #define LAN8720_BMSR_100BT2_FD 0x0400
77 #define LAN8720_BMSR_100BT2_HD 0x0200
78 #define LAN8720_BMSR_EXTENDED_STATUS 0x0100
79 #define LAN8720_BMSR_AN_COMPLETE 0x0020
80 #define LAN8720_BMSR_REMOTE_FAULT 0x0010
81 #define LAN8720_BMSR_AN_CAPABLE 0x0008
82 #define LAN8720_BMSR_LINK_STATUS 0x0004
83 #define LAN8720_BMSR_JABBER_DETECT 0x0002
84 #define LAN8720_BMSR_EXTENDED_CAPABLE 0x0001
85 
86 //PHY Identifier 1 register
87 #define LAN8720_PHYID1_PHY_ID_MSB 0xFFFF
88 #define LAN8720_PHYID1_PHY_ID_MSB_DEFAULT 0x0007
89 
90 //PHY Identifier 2 register
91 #define LAN8720_PHYID2_PHY_ID_LSB 0xFC00
92 #define LAN8720_PHYID2_PHY_ID_LSB_DEFAULT 0xC000
93 #define LAN8720_PHYID2_MODEL_NUM 0x03F0
94 #define LAN8720_PHYID2_MODEL_NUM_DEFAULT 0x00F0
95 #define LAN8720_PHYID2_REVISION_NUM 0x000F
96 
97 //Auto-Negotiation Advertisement register
98 #define LAN8720_ANAR_REMOTE_FAULT 0x2000
99 #define LAN8720_ANAR_PAUSE 0x0C00
100 #define LAN8720_ANAR_100BTX_FD 0x0100
101 #define LAN8720_ANAR_100BTX_HD 0x0080
102 #define LAN8720_ANAR_10BT_FD 0x0040
103 #define LAN8720_ANAR_10BT_HD 0x0020
104 #define LAN8720_ANAR_SELECTOR 0x001F
105 #define LAN8720_ANAR_SELECTOR_DEFAULT 0x0001
106 
107 //Auto-Negotiation Link Partner Ability register
108 #define LAN8720_ANLPAR_NEXT_PAGE 0x8000
109 #define LAN8720_ANLPAR_ACK 0x4000
110 #define LAN8720_ANLPAR_REMOTE_FAULT 0x2000
111 #define LAN8720_ANLPAR_PAUSE 0x0400
112 #define LAN8720_ANLPAR_100BT4 0x0200
113 #define LAN8720_ANLPAR_100BTX_FD 0x0100
114 #define LAN8720_ANLPAR_100BTX_HD 0x0080
115 #define LAN8720_ANLPAR_10BT_FD 0x0040
116 #define LAN8720_ANLPAR_10BT_HD 0x0020
117 #define LAN8720_ANLPAR_SELECTOR 0x001F
118 #define LAN8720_ANLPAR_SELECTOR_DEFAULT 0x0001
119 
120 //Auto-Negotiation Expansion register
121 #define LAN8720_ANER_PAR_DETECT_FAULT 0x0010
122 #define LAN8720_ANER_LP_NEXT_PAGE_ABLE 0x0008
123 #define LAN8720_ANER_NEXT_PAGE_ABLE 0x0004
124 #define LAN8720_ANER_PAGE_RECEIVED 0x0002
125 #define LAN8720_ANER_LP_AN_ABLE 0x0001
126 
127 //Mode Control/Status register
128 #define LAN8720_MCSR_EDPWRDOWN 0x2000
129 #define LAN8720_MCSR_FARLOOPBACK 0x0200
130 #define LAN8720_MCSR_ALTINT 0x0040
131 #define LAN8720_MCSR_ENERGYON 0x0002
132 
133 //Special Modes register
134 #define LAN8720_SMR_MODE 0x00E0
135 #define LAN8720_SMR_PHYAD 0x001F
136 
137 //Symbol Error Counter register
138 #define LAN8720_SECR_SYM_ERR_CNT 0xFFFF
139 
140 //Special Control/Status Indication register
141 #define LAN8720_SCSIR_AMDIXCTRL 0x8000
142 #define LAN8720_SCSIR_CH_SELECT 0x2000
143 #define LAN8720_SCSIR_SQEOFF 0x0800
144 #define LAN8720_SCSIR_XPOL 0x0010
145 
146 //Interrupt Source register
147 #define LAN8720_ISR_ENERGYON 0x0080
148 #define LAN8720_ISR_AN_COMPLETE 0x0040
149 #define LAN8720_ISR_REMOTE_FAULT 0x0020
150 #define LAN8720_ISR_LINK_DOWN 0x0010
151 #define LAN8720_ISR_AN_LP_ACK 0x0008
152 #define LAN8720_ISR_PAR_DETECT_FAULT 0x0004
153 #define LAN8720_ISR_AN_PAGE_RECEIVED 0x0002
154 
155 //Interrupt Mask register
156 #define LAN8720_IMR_ENERGYON 0x0080
157 #define LAN8720_IMR_AN_COMPLETE 0x0040
158 #define LAN8720_IMR_REMOTE_FAULT 0x0020
159 #define LAN8720_IMR_LINK_DOWN 0x0010
160 #define LAN8720_IMR_AN_LP_ACK 0x0008
161 #define LAN8720_IMR_PAR_DETECT_FAULT 0x0004
162 #define LAN8720_IMR_AN_PAGE_RECEIVED 0x0002
163 
164 //PHY Special Control/Status register
165 #define LAN8720_PSCSR_AUTODONE 0x1000
166 #define LAN8720_PSCSR_HCDSPEED 0x001C
167 #define LAN8720_PSCSR_HCDSPEED_10BT_HD 0x0004
168 #define LAN8720_PSCSR_HCDSPEED_100BTX_HD 0x0008
169 #define LAN8720_PSCSR_HCDSPEED_10BT_FD 0x0014
170 #define LAN8720_PSCSR_HCDSPEED_100BTX_FD 0x0018
171 
172 //C++ guard
173 #ifdef __cplusplus
174 extern "C" {
175 #endif
176 
177 //LAN8720 Ethernet PHY driver
178 extern const PhyDriver lan8720PhyDriver;
179 
180 //LAN8720 related functions
181 error_t lan8720Init(NetInterface *interface);
182 void lan8720InitHook(NetInterface *interface);
183 
184 void lan8720Tick(NetInterface *interface);
185 
186 void lan8720EnableIrq(NetInterface *interface);
187 void lan8720DisableIrq(NetInterface *interface);
188 
189 void lan8720EventHandler(NetInterface *interface);
190 
191 void lan8720WritePhyReg(NetInterface *interface, uint8_t address,
192  uint16_t data);
193 
194 uint16_t lan8720ReadPhyReg(NetInterface *interface, uint8_t address);
195 
196 void lan8720DumpPhyReg(NetInterface *interface);
197 
198 //C++ guard
199 #ifdef __cplusplus
200 }
201 #endif
202 
203 #endif
void lan8720DumpPhyReg(NetInterface *interface)
Dump PHY registers for debugging purpose.
void lan8720Tick(NetInterface *interface)
LAN8720 timer handler.
Ethernet PHY driver.
Definition: nic.h:311
uint8_t data[]
Definition: ethernet.h:222
error_t lan8720Init(NetInterface *interface)
LAN8720 PHY transceiver initialization.
uint16_t lan8720ReadPhyReg(NetInterface *interface, uint8_t address)
Read PHY register.
const PhyDriver lan8720PhyDriver
LAN8720 Ethernet PHY driver.
error_t
Error codes.
Definition: error.h:43
void lan8720WritePhyReg(NetInterface *interface, uint8_t address, uint16_t data)
Write PHY register.
#define NetInterface
Definition: net.h:36
void lan8720EventHandler(NetInterface *interface)
LAN8720 event handler.
void lan8720DisableIrq(NetInterface *interface)
Disable interrupts.
void lan8720InitHook(NetInterface *interface)
LAN8720 custom configuration.
Ipv6Addr address[]
Definition: ipv6.h:325
Network interface controller abstraction layer.
void lan8720EnableIrq(NetInterface *interface)
Enable interrupts.