tja1103_driver.h
Go to the documentation of this file.
1 /**
2  * @file tja1103_driver.h
3  * @brief TJA1103 100Base-T1 Ethernet PHY driver
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2026 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.6.0
29  **/
30 
31 #ifndef _TJA1103_DRIVER_H
32 #define _TJA1103_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //PHY address
38 #ifndef TJA1103_PHY_ADDR
39  #define TJA1103_PHY_ADDR 0
40 #elif (TJA1103_PHY_ADDR < 0 || TJA1103_PHY_ADDR > 31)
41  #error TJA1103_PHY_ADDR parameter is not valid
42 #endif
43 
44 //TJA1103 PHY registers
45 #define TJA1103_PHY_ID_1 0x02
46 #define TJA1103_PHY_ID_2 0x03
47 #define TJA1103_CL45_ACCESS_CONTROL 0x0D
48 #define TJA1103_CL45_ADDRESS_DATA 0x0E
49 #define TJA1103_CL45_ADDRESS 0x1E
50 #define TJA1103_ALWAYS_ACCESSIBLE 0x1F
51 
52 //TJA1103 MMD registers
53 #define TJA1103_BASE_T1_PMA_CONTROL 0x01, 0x0834
54 #define TJA1103_PCS_CONTROL1 0x03, 0x0000
55 #define TJA1103_DEVICE_IDENTIFIER3 0x1E, 0x0004
56 #define TJA1103_DEVICE_CONTROL 0x1E, 0x0040
57 #define TJA1103_DEVICE_CONFIG 0x1E, 0x0048
58 #define TJA1103_PTP_CONFIG 0x1E, 0x1102
59 #define TJA1103_RX_TS_INSRT_CTRL 0x1E, 0x114D
60 #define TJA1103_EGR_RING_DATA_0 0x1E, 0x114E
61 #define TJA1103_EGR_RING_CTRL 0x1E, 0x1154
62 #define TJA1103_GPIO0_FUNC_CONFIG 0x1E, 0x2C40
63 #define TJA1103_PORT_PTP_CONTROL 0x1E, 0x9000
64 #define TJA1103_PORT_INFRA_CONTROL 0x1E, 0xAC00
65 #define TJA1103_XMII_ABILITIES 0x1E, 0xAFC4
66 #define TJA1103_MII_BASIC_CONFIG 0x1E, 0xAFC6
67 #define TJA1103_RGMII_TXC_DELAY_CONFIG 0x1E, 0xAFCC
68 #define TJA1103_RGMII_RXC_DELAY_CONFIG 0x1E, 0xAFCD
69 #define TJA1103_RX_PREAMBLE_COUNT 0x1E, 0xAFCE
70 #define TJA1103_TX_PREAMBLE_COUNT 0x1E, 0xAFCF
71 #define TJA1103_RX_IPG_LENGTH 0x1E, 0xAFD0
72 #define TJA1103_TX_IPG_LENGTH 0x1E, 0xAFD1
73 #define TJA1103_SGMII_BASIC_CONTROL 0x1E, 0xB000
74 
75 //TJA1103 Shared MMD registers
76 #define TJA1103_PORT_CONTROL 0x1E, 0x8040
77 #define TJA1103_PORT_ABILITIES 0x1E, 0x8046
78 #define TJA1103_PORT_FUNC_IRQ_ENABLE 0x1E, 0x807A
79 #define TJA1103_EPHY_FUNC_IRQ_SOURCE 0x1E, 0x80A0
80 #define TJA1103_EPHY_FUNC_IRQ_ENABLE 0x1E, 0x80A1
81 #define TJA1103_EPHY_FUNC_IRQ_MSTATUS 0x1E, 0x80A2
82 #define TJA1103_PHY_CONTROL 0x1E, 0x8100
83 #define TJA1103_PHY_STATUS 0x1E, 0x8102
84 #define TJA1103_PHY_CONFIG 0x1E, 0x8108
85 #define TJA1103_SIGNAL_QUALITY 0x1E, 0x8320
86 #define TJA1103_CABLE_TEST 0x1E, 0x8330
87 #define TJA1103_SYMBOL_ERROR_COUNTER 0x1E, 0x8350
88 #define TJA1103_ERROR_COUNTER_MISC 0x1E, 0x8352
89 #define TJA1103_LINK_LOSSES_AND_FAILURES 0x1E, 0x8353
90 
91 //PHY Identification 1 register
92 #define TJA1103_PHY_ID_1_OUI_BITS_3_TO_18 0xFFFF
93 #define TJA1103_PHY_ID_1_OUI_BITS_3_TO_18_DEFAULT 0x001B
94 
95 //PHY Identification 2 register
96 #define TJA1103_PHY_ID_2_OUI_BITS_19_TO_24 0xFC00
97 #define TJA1103_PHY_ID_2_OUI_BITS_19_TO_24_DEFAULT 0xB000
98 #define TJA1103_PHY_ID_2_MODEL 0x03F0
99 #define TJA1103_PHY_ID_2_MODEL_DEFAULT 0x0010
100 #define TJA1103_PHY_ID_2_REVISION 0x000F
101 
102 //CL45 Access Control register
103 #define TJA1103_CL45_ACCESS_CONTROL_OP 0xC000
104 #define TJA1103_CL45_ACCESS_CONTROL_OP_ADDR 0x0000
105 #define TJA1103_CL45_ACCESS_CONTROL_OP_DATA_NO_POST_INC 0x4000
106 #define TJA1103_CL45_ACCESS_CONTROL_OP_DATA_POST_INC_RW 0x8000
107 #define TJA1103_CL45_ACCESS_CONTROL_OP_DATA_POST_INC_W 0xC000
108 #define TJA1103_CL45_ACCESS_CONTROL_MMD 0x001F
109 #define TJA1103_CL45_ACCESS_CONTROL_MMD_PMA_PMD 0x0001
110 #define TJA1103_CL45_ACCESS_CONTROL_MMD_PCS 0x0003
111 #define TJA1103_CL45_ACCESS_CONTROL_MMD_VENDOR_SPECIFIC 0x001E
112 
113 //CL45 Address Data register
114 #define TJA1103_CL45_ADDRESS_DATA_ADDRESS_DATA 0xFFFF
115 
116 //CL45 Address register
117 #define TJA1103_CL45_ADDRESS_ADDRESS 0xFFFF
118 
119 //Always-Accessible register
120 #define TJA1103_ALWAYS_ACCESSIBLE_FUSA_PASS_IRQ 0x0010
121 
122 //BASE-T1 PMA Control register
123 #define TJA1103_BASE_T1_PMA_CONTROL_MANUAL_MASTER_SLAVE_CONFIG 0x8000
124 #define TJA1103_BASE_T1_PMA_CONTROL_MASTER_SLAVE 0x4000
125 
126 //PCS Control 1 register
127 #define TJA1103_PCS_CONTROL1_RESET 0x8000
128 #define TJA1103_PCS_CONTROL1_LOOPBACK 0x4000
129 #define TJA1103_PCS_CONTROL1_SPEED_SELECT_LSB 0x2000
130 #define TJA1103_PCS_CONTROL1_LOW_POWER 0x0800
131 #define TJA1103_PCS_CONTROL1_SPEED_SELECT_MSB 0x0040
132 
133 //Device Identifier 3 register
134 #define TJA1103_DEVICE_IDENTIFIER3_TJA1103A 0x1091
135 #define TJA1103_DEVICE_IDENTIFIER3_TJA1103B 0x2401
136 
137 //Device Control register
138 #define TJA1103_DEVICE_CONTROL_DEVICE_RESET 0x8000
139 #define TJA1103_DEVICE_CONTROL_GLOBAL_CONFIG_ENABLE 0x4000
140 #define TJA1103_DEVICE_CONTROL_SUPER_CONFIG_ENABLE 0x2000
141 
142 //PTP Configuration register
143 #define TJA1103_PTP_CONFIG_PPS_OUT_EN 0x0008
144 #define TJA1103_PTP_CONFIG_PPS_OUT_POL 0x0004
145 #define TJA1103_PTP_CONFIG_EXT_TRG_EDGE_SEL 0x0002
146 
147 //GPIO0 Function Configuration register
148 #define TJA1103_GPIO0_FUNC_CONFIG_ENABLE 0x8000
149 #define TJA1103_GPIO0_FUNC_CONFIG_SIGNAL_SELECT 0x001F
150 #define TJA1103_GPIO0_FUNC_CONFIG_SIGNAL_SELECT_PTP_TRIGGER 0x0001
151 #define TJA1103_GPIO0_FUNC_CONFIG_SIGNAL_SELECT_PPS_OUT 0x0012
152 
153 //Port PTP Control register
154 #define TJA1103_PORT_PTP_CONTROL_BYPASS 0x0800
155 
156 //Port Infrastructure Control register
157 #define TJA1103_PORT_INFRA_CONTROL_RESET 0x8000
158 #define TJA1103_PORT_INFRA_CONTROL_CONFIG_ENABLE 0x4000
159 
160 //XMII Abilities register
161 #define TJA1103_XMII_ABILITIES_RGMII_ID_ABILITY 0x8000
162 #define TJA1103_XMII_ABILITIES_RGMII_ABILITY 0x4000
163 #define TJA1103_XMII_ABILITIES_RMII_MASTER_ABILITY 0x0800
164 #define TJA1103_XMII_ABILITIES_RMII_SLAVE_ABILITY 0x0400
165 #define TJA1103_XMII_ABILITIES_MII_SLAVE_ABILITY 0x0200
166 #define TJA1103_XMII_ABILITIES_MII_MASTER_ABILITY 0x0100
167 #define TJA1103_XMII_ABILITIES_SGMII_ABILITY 0x0001
168 
169 //MII Basic Configuration register
170 #define TJA1103_MII_BASIC_CONFIG_ROLE 0x0010
171 #define TJA1103_MII_BASIC_CONFIG_XMII_MODE 0x000F
172 #define TJA1103_MII_BASIC_CONFIG_XMII_MODE_MII 0x0004
173 #define TJA1103_MII_BASIC_CONFIG_XMII_MODE_RMII 0x0005
174 #define TJA1103_MII_BASIC_CONFIG_XMII_MODE_RGMII 0x0007
175 #define TJA1103_MII_BASIC_CONFIG_XMII_MODE_SGMII 0x0008
176 
177 //RGMII TXC Delay Configuration register
178 #define TJA1103_RGMII_TXC_DELAY_CONFIG_ENABLE 0x8000
179 #define TJA1103_RGMII_TXC_DELAY_CONFIG_PHASE_SHIFT 0x001F
180 #define TJA1103_RGMII_TXC_DELAY_CONFIG_PHASE_SHIFT_DEFAULT 0x0012
181 
182 //RGMII RXC Delay Configuration register
183 #define TJA1103_RGMII_RXC_DELAY_CONFIG_ENABLE 0x8000
184 #define TJA1103_RGMII_RXC_DELAY_CONFIG_PHASE_SHIFT 0x001F
185 #define TJA1103_RGMII_RXC_DELAY_CONFIG_PHASE_SHIFT_DEFAULT 0x0012
186 
187 //RX Preamble Counter register
188 #define TJA1103_RX_PREAMBLE_COUNT_ENABLE 0x8000
189 #define TJA1103_RX_PREAMBLE_COUNT_COUNT 0x003F
190 
191 //TX Preamble Counter register
192 #define TJA1103_TX_PREAMBLE_COUNT_ENABLE 0x8000
193 #define TJA1103_TX_PREAMBLE_COUNT_COUNT 0x003F
194 
195 //RX IPG Length Capture register
196 #define TJA1103_RX_IPG_LENGTH_ENABLE 0x8000
197 #define TJA1103_RX_IPG_LENGTH_LENGTH 0x01FF
198 
199 //TX IPG Length Capture register
200 #define TJA1103_TX_IPG_LENGTH_ENABLE 0x8000
201 #define TJA1103_TX_IPG_LENGTH_LENGTH 0x01FF
202 
203 //SGMII Basic Control register
204 #define TJA1103_SGMII_BASIC_CONTROL_LPM 0x0800
205 
206 //Port Control register
207 #define TJA1103_PORT_CONTROL_CONFIG_ENABLE 0x4000
208 
209 //Port Abilities register
210 #define TJA1103_PORT_ABILITIES_PTP_ABILITY 0x0008
211 
212 //Port-Level IRQ Enable register
213 #define TJA1103_PORT_FUNC_IRQ_ENABLE_PTP_IRQ 0x0008
214 
215 //Ethernet PHY Functional IRQ Source register
216 #define TJA1103_EPHY_FUNC_IRQ_SOURCE_LINK_AVAILABLE_EVENT 0x0004
217 #define TJA1103_EPHY_FUNC_IRQ_SOURCE_LINK_STATUS_EVENT 0x0002
218 
219 //Ethernet PHY Functional IRQ Enable register
220 #define TJA1103_EPHY_FUNC_IRQ_ENABLE_LINK_AVAILABLE_EVENT 0x0004
221 #define TJA1103_EPHY_FUNC_IRQ_ENABLE_LINK_STATUS_EVENT 0x0002
222 
223 //Ethernet PHY Functional IRQ Masked Status register
224 #define TJA1103_EPHY_FUNC_IRQ_MSTATUS_LINK_AVAILABLE_EVENT 0x0004
225 #define TJA1103_EPHY_FUNC_IRQ_MSTATUS_LINK_STATUS_EVENT 0x0002
226 
227 //PHY Control register
228 #define TJA1103_PHY_CONTROL_CONFIG_ENABLE 0x4000
229 #define TJA1103_PHY_CONTROL_START_OPERATION 0x0001
230 
231 //PHY Status register
232 #define TJA1103_PHY_STATUS_LINK_STATUS 0x0004
233 
234 //PHY Configuration register
235 #define TJA1103_PHY_CONFIG_AUTO_OPERATION 0x0001
236 
237 //Signal Quality register
238 #define TJA1103_SIGNAL_QUALITY_VALID 0x4000
239 #define TJA1103_SIGNAL_QUALITY_SQI 0x0007
240 
241 //Cable Test register
242 #define TJA1103_CABLE_TEST_ENABLE 0x8000
243 #define TJA1103_CABLE_TEST_START 0x4000
244 #define TJA1103_CABLE_TEST_VALID 0x2000
245 #define TJA1103_CABLE_TEST_FAULT_TYPE 0x0007
246 #define TJA1103_CABLE_TEST_FAULT_TYPE_OK 0x0000
247 #define TJA1103_CABLE_TEST_FAULT_TYPE_SHORTED 0x0001
248 #define TJA1103_CABLE_TEST_FAULT_TYPE_OPEN 0x0002
249 #define TJA1103_CABLE_TEST_FAULT_TYPE_UNKNOWN 0x0007
250 
251 //Symbol Error Counter register
252 #define TJA1103_SYMBOL_ERROR_COUNTER_SYMBOL_ERRORS 0xFFFF
253 
254 //Error Counter Miscellaneous register
255 #define TJA1103_ERROR_COUNTER_MISC_COUNTER_ENABLE 0x8000
256 #define TJA1103_ERROR_COUNTER_MISC_LINK_STATUS_DROPS 0x3F00
257 #define TJA1103_ERROR_COUNTER_MISC_LINK_AVAILABLE_DROPS 0x003F
258 
259 //Link Losses And Failures Counter register
260 #define TJA1103_LINK_LOSSES_AND_FAILURES_LINK_LOSSES 0xFC00
261 #define TJA1103_LINK_LOSSES_AND_FAILURES_LINK_FAILURES 0x03FF
262 
263 //C++ guard
264 #ifdef __cplusplus
265 extern "C" {
266 #endif
267 
268 //TJA1103 Ethernet PHY driver
269 extern const PhyDriver tja1103PhyDriver;
270 
271 //TJA1103 related functions
272 error_t tja1103Init(NetInterface *interface);
273 void tja1103InitHook(NetInterface *interface);
274 
275 void tja1103Tick(NetInterface *interface);
276 
277 void tja1103EnableIrq(NetInterface *interface);
278 void tja1103DisableIrq(NetInterface *interface);
279 
280 void tja1103EventHandler(NetInterface *interface);
281 
282 void tja1103WritePhyReg(NetInterface *interface, uint8_t address,
283  uint16_t data);
284 
285 uint16_t tja1103ReadPhyReg(NetInterface *interface, uint8_t address);
286 
287 void tja1103DumpPhyReg(NetInterface *interface);
288 
289 void tja1103WriteMmdReg(NetInterface *interface, uint8_t devAddr,
290  uint16_t regAddr, uint16_t data);
291 
292 uint16_t tja1103ReadMmdReg(NetInterface *interface, uint8_t devAddr,
293  uint16_t regAddr);
294 
295 //C++ guard
296 #ifdef __cplusplus
297 }
298 #endif
299 
300 #endif
uint16_t tja1103ReadMmdReg(NetInterface *interface, uint8_t devAddr, uint16_t regAddr)
Read MMD register.
const PhyDriver tja1103PhyDriver
TJA1103 Ethernet PHY driver.
Ethernet PHY driver.
Definition: nic.h:311
uint8_t data[]
Definition: ethernet.h:224
void tja1103InitHook(NetInterface *interface)
TJA1103 custom configuration.
void tja1103EventHandler(NetInterface *interface)
TJA1103 event handler.
error_t
Error codes.
Definition: error.h:43
error_t tja1103Init(NetInterface *interface)
TJA1103 PHY transceiver initialization.
void tja1103EnableIrq(NetInterface *interface)
Enable interrupts.
#define NetInterface
Definition: net.h:40
void tja1103Tick(NetInterface *interface)
TJA1103 timer handler.
uint16_t regAddr
Ipv6Addr address[]
Definition: ipv6.h:345
Network interface controller abstraction layer.
void tja1103DisableIrq(NetInterface *interface)
Disable interrupts.
void tja1103WriteMmdReg(NetInterface *interface, uint8_t devAddr, uint16_t regAddr, uint16_t data)
Write MMD register.
void tja1103DumpPhyReg(NetInterface *interface)
Dump PHY registers for debugging purpose.
uint16_t tja1103ReadPhyReg(NetInterface *interface, uint8_t address)
Read PHY register.
void tja1103WritePhyReg(NetInterface *interface, uint8_t address, uint16_t data)
Write PHY register.