dm9162_driver.h
Go to the documentation of this file.
1 /**
2  * @file dm9162_driver.h
3  * @brief DM9162 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 _DM9162_DRIVER_H
32 #define _DM9162_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //PHY address
38 #ifndef DM9162_PHY_ADDR
39  #define DM9162_PHY_ADDR 0
40 #elif (DM9162_PHY_ADDR < 0 || DM9162_PHY_ADDR > 31)
41  #error DM9162_PHY_ADDR parameter is not valid
42 #endif
43 
44 //DM9162 PHY registers
45 #define DM9162_BMCR 0x00
46 #define DM9162_BMSR 0x01
47 #define DM9162_PHYID1 0x02
48 #define DM9162_PHYID2 0x03
49 #define DM9162_ANAR 0x04
50 #define DM9162_ANLPAR 0x05
51 #define DM9162_ANER 0x06
52 #define DM9162_DSCR 0x10
53 #define DM9162_DSCSR 0x11
54 #define DM9162_10BTCSR 0x12
55 #define DM9162_PWDOR 0x13
56 #define DM9162_SCR 0x14
57 #define DM9162_MDINTR 0x15
58 #define DM9162_RECR 0x16
59 #define DM9162_DISCR 0x17
60 #define DM9162_RLSR 0x18
61 #define DM9162_PSCR 0x1D
62 
63 //Basic Mode Control register
64 #define DM9162_BMCR_RESET 0x8000
65 #define DM9162_BMCR_LOOPBACK 0x4000
66 #define DM9162_BMCR_SPEED_SEL 0x2000
67 #define DM9162_BMCR_AN_EN 0x1000
68 #define DM9162_BMCR_POWER_DOWN 0x0800
69 #define DM9162_BMCR_ISOLATE 0x0400
70 #define DM9162_BMCR_RESTART_AN 0x0200
71 #define DM9162_BMCR_DUPLEX_MODE 0x0100
72 #define DM9162_BMCR_COL_TEST 0x0080
73 
74 //Basic Mode Status register
75 #define DM9162_BMSR_100BT4 0x8000
76 #define DM9162_BMSR_100BTX_FD 0x4000
77 #define DM9162_BMSR_100BTX_HD 0x2000
78 #define DM9162_BMSR_10BT_FD 0x1000
79 #define DM9162_BMSR_10BT_HD 0x0800
80 #define DM9162_BMSR_MF_PREAMBLE_SUPPR 0x0040
81 #define DM9162_BMSR_AN_COMPLETE 0x0020
82 #define DM9162_BMSR_REMOTE_FAULT 0x0010
83 #define DM9162_BMSR_AN_CAPABLE 0x0008
84 #define DM9162_BMSR_LINK_STATUS 0x0004
85 #define DM9162_BMSR_JABBER_DETECT 0x0002
86 #define DM9162_BMSR_EXTENDED_CAPABLE 0x0001
87 
88 //PHY Identifier 1 register
89 #define DM9162_PHYID1_OUI_MSB 0xFFFF
90 #define DM9162_PHYID1_OUI_MSB_DEFAULT 0x0181
91 
92 //PHY Identifier 2 register
93 #define DM9162_PHYID2_OUI_LSB 0xFC00
94 #define DM9162_PHYID2_OUI_LSB_DEFAULT 0xB800
95 #define DM9162_PHYID2_VNDR_MDL 0x03F0
96 #define DM9162_PHYID2_VNDR_MDL_DEFAULT 0x00A0
97 #define DM9162_PHYID2_MDL_REV 0x000F
98 
99 //Auto-Negotiation Advertisement register
100 #define DM9162_ANAR_NEXT_PAGE 0x8000
101 #define DM9162_ANAR_ACK 0x4000
102 #define DM9162_ANAR_REMOTE_FAULT 0x2000
103 #define DM9162_ANAR_FCS 0x0400
104 #define DM9162_ANAR_100BT4 0x0200
105 #define DM9162_ANAR_100BTX_FD 0x0100
106 #define DM9162_ANAR_100BTX_HD 0x0080
107 #define DM9162_ANAR_10BT_FD 0x0040
108 #define DM9162_ANAR_10BT_HD 0x0020
109 #define DM9162_ANAR_SELECTOR 0x001F
110 #define DM9162_ANAR_SELECTOR_DEFAULT 0x0001
111 
112 //Auto-Negotiation Link Partner Ability register
113 #define DM9162_ANLPAR_NEXT_PAGE 0x8000
114 #define DM9162_ANLPAR_ACK 0x4000
115 #define DM9162_ANLPAR_REMOTE_FAULT 0x2000
116 #define DM9162_ANLPAR_FCS 0x0400
117 #define DM9162_ANLPAR_100BT4 0x0200
118 #define DM9162_ANLPAR_100BTX_FD 0x0100
119 #define DM9162_ANLPAR_100BTX_HD 0x0080
120 #define DM9162_ANLPAR_10BT_FD 0x0040
121 #define DM9162_ANLPAR_10BT_HD 0x0020
122 #define DM9162_ANLPAR_SELECTOR 0x001F
123 #define DM9162_ANLPAR_SELECTOR_DEFAULT 0x0000
124 
125 //Auto-Negotiation Expansion register
126 #define DM9162_ANER_PAR_DETECT_FAULT 0x0010
127 #define DM9162_ANER_LP_NP_ABLE 0x0008
128 #define DM9162_ANER_NP_ABLE 0x0004
129 #define DM9162_ANER_PAGE_RX 0x0002
130 #define DM9162_ANER_LP_AN_ABLE 0x0001
131 
132 //DAVICOM Specified Configuration register
133 #define DM9162_DSCR_BP_4B5B 0x8000
134 #define DM9162_DSCR_BP_SCR 0x4000
135 #define DM9162_DSCR_BP_ALIGN 0x2000
136 #define DM9162_DSCR_BP_ADPOK 0x1000
137 #define DM9162_DSCR_REPEATER 0x0800
138 #define DM9162_DSCR_TX 0x0400
139 #define DM9162_DSCR_RMII_EN 0x0100
140 #define DM9162_DSCR_F_LINK_100 0x0080
141 #define DM9162_DSCR_SPLED_CTL 0x0040
142 #define DM9162_DSCR_COLLED_CTL 0x0020
143 #define DM9162_DSCR_RPDCTR_EN 0x0010
144 #define DM9162_DSCR_SMRST 0x0008
145 #define DM9162_DSCR_MFPSC 0x0004
146 #define DM9162_DSCR_SLEEP 0x0002
147 #define DM9162_DSCR_RLOUT 0x0001
148 
149 //DAVICOM Specified Configuration and Status register
150 #define DM9162_DSCSR_100FDX 0x8000
151 #define DM9162_DSCSR_100HDX 0x4000
152 #define DM9162_DSCSR_10FDX 0x2000
153 #define DM9162_DSCSR_10HDX 0x1000
154 #define DM9162_DSCSR_PHYADR 0x01F0
155 #define DM9162_DSCSR_ANMB 0x000F
156 #define DM9162_DSCSR_ANMB_IDLE 0x0000
157 #define DM9162_DSCSR_ANMB_ABILITY_MATCH 0x0001
158 #define DM9162_DSCSR_ANMB_ACK_MATCH 0x0002
159 #define DM9162_DSCSR_ANMB_ACK_MATCH_FAIL 0x0003
160 #define DM9162_DSCSR_ANMB_CONSIST_MATCH 0x0004
161 #define DM9162_DSCSR_ANMB_CONSIST_MATCH_FAIL 0x0005
162 #define DM9162_DSCSR_ANMB_LINK_READY 0x0006
163 #define DM9162_DSCSR_ANMB_LINK_READY_FAIL 0x0007
164 #define DM9162_DSCSR_ANMB_AN_COMPLETE 0x0008
165 
166 //10BASE-T Configuration/Status register
167 #define DM9162_10BTCSR_LP_EN 0x4000
168 #define DM9162_10BTCSR_HBE 0x2000
169 #define DM9162_10BTCSR_SQUELCH 0x1000
170 #define DM9162_10BTCSR_JABEN 0x0800
171 #define DM9162_10BTCSR_10BT_SER 0x0400
172 #define DM9162_10BTCSR_POLR 0x0001
173 
174 //Power-Down Control register
175 #define DM9162_PWDOR_PD_10DRV 0x0100
176 #define DM9162_PWDOR_PD_100DL 0x0080
177 #define DM9162_PWDOR_PD_CHIP 0x0040
178 #define DM9162_PWDOR_PD_COM 0x0020
179 #define DM9162_PWDOR_PD_AEQ 0x0010
180 #define DM9162_PWDOR_PD_DRV 0x0008
181 #define DM9162_PWDOR_PD_EDI 0x0004
182 #define DM9162_PWDOR_PD_EDO 0x0002
183 #define DM9162_PWDOR_PD_10 0x0001
184 
185 //DAVICOM Specified Configuration register
186 #define DM9162_SCR_TSTSE1 0x8000
187 #define DM9162_SCR_TSTSE2 0x4000
188 #define DM9162_SCR_STSEL3 0x1000
189 #define DM9162_SCR_PREAMBLEX 0x0800
190 #define DM9162_SCR_TX10M_PWR 0x0400
191 #define DM9162_SCR_NWAY_PWR 0x0200
192 #define DM9162_SCR_MDIX_CNTL 0x0080
193 #define DM9162_SCR_AUTONEG_DPBK 0x0040
194 #define DM9162_SCR_MDIX_FIX_VALUE 0x0020
195 #define DM9162_SCR_MDIX_DOWN 0x0010
196 #define DM9162_SCR_MONSEL1 0x0008
197 #define DM9162_SCR_MONSEL0 0x0004
198 #define DM9162_SCR_RMII_VER 0x0002
199 #define DM9162_SCR_PD_VALUE 0x0001
200 
201 //DAVICOM Specified Interrupt register
202 #define DM9162_MDINTR_INTR_PEND 0x8000
203 #define DM9162_MDINTR_FDX_MASK 0x0800
204 #define DM9162_MDINTR_SPD_MASK 0x0400
205 #define DM9162_MDINTR_LINK_MASK 0x0200
206 #define DM9162_MDINTR_INTR_MASK 0x0100
207 #define DM9162_MDINTR_FDX_CHANGE 0x0010
208 #define DM9162_MDINTR_SPD_CHANGE 0x0008
209 #define DM9162_MDINTR_LINK_CHANGE 0x0004
210 #define DM9162_MDINTR_INTR_STATUS 0x0001
211 
212 //DAVICOM Specified Receive Error Counter register
213 #define DM9162_RECR_RCV_ERR_CNT 0xFFFF
214 
215 //DAVICOM Specified Disconnect Counter register
216 #define DM9162_DISCR_DISCONNECT_COUNT 0x00FF
217 
218 //DAVICOM Hardware Reset Latch State register
219 #define DM9162_RLSR_LH_LEDMODE 0x8000
220 #define DM9162_RLSR_LH_MDINTR 0x4000
221 #define DM9162_RLSR_LH_CSTS 0x2000
222 #define DM9162_RLSR_LH_ISO 0x1000
223 #define DM9162_RLSR_LH_RMII 0x0800
224 #define DM9162_RLSR_LH_TP10SER 0x0400
225 #define DM9162_RLSR_LH_REPTR 0x0200
226 #define DM9162_RLSR_LH_TSTMOD 0x0100
227 #define DM9162_RLSR_LH_OP 0x00E0
228 #define DM9162_RLSR_LH_PH 0x001F
229 
230 //Power Saving Control register
231 #define DM9162_PSCR_PREAMBLEX 0x0800
232 #define DM9162_PSCR_TX_PWR 0x0200
233 
234 //C++ guard
235 #ifdef __cplusplus
236 extern "C" {
237 #endif
238 
239 //DM9162 Ethernet PHY driver
240 extern const PhyDriver dm9162PhyDriver;
241 
242 //DM9162 related functions
243 error_t dm9162Init(NetInterface *interface);
244 void dm9162InitHook(NetInterface *interface);
245 
246 void dm9162Tick(NetInterface *interface);
247 
248 void dm9162EnableIrq(NetInterface *interface);
249 void dm9162DisableIrq(NetInterface *interface);
250 
251 void dm9162EventHandler(NetInterface *interface);
252 
253 void dm9162WritePhyReg(NetInterface *interface, uint8_t address,
254  uint16_t data);
255 
256 uint16_t dm9162ReadPhyReg(NetInterface *interface, uint8_t address);
257 
258 void dm9162DumpPhyReg(NetInterface *interface);
259 
260 //C++ guard
261 #ifdef __cplusplus
262 }
263 #endif
264 
265 #endif
void dm9162Tick(NetInterface *interface)
DM9162 timer handler.
const PhyDriver dm9162PhyDriver
DM9162 Ethernet PHY driver.
Definition: dm9162_driver.c:44
Ethernet PHY driver.
Definition: nic.h:311
uint8_t data[]
Definition: ethernet.h:222
void dm9162DumpPhyReg(NetInterface *interface)
Dump PHY registers for debugging purpose.
void dm9162WritePhyReg(NetInterface *interface, uint8_t address, uint16_t data)
Write PHY register.
error_t
Error codes.
Definition: error.h:43
void dm9162DisableIrq(NetInterface *interface)
Disable interrupts.
#define NetInterface
Definition: net.h:36
error_t dm9162Init(NetInterface *interface)
DM9162 PHY transceiver initialization.
Definition: dm9162_driver.c:60
Ipv6Addr address[]
Definition: ipv6.h:325
Network interface controller abstraction layer.
void dm9162EnableIrq(NetInterface *interface)
Enable interrupts.
void dm9162InitHook(NetInterface *interface)
DM9162 custom configuration.
void dm9162EventHandler(NetInterface *interface)
DM9162 event handler.
uint16_t dm9162ReadPhyReg(NetInterface *interface, uint8_t address)
Read PHY register.