blob: 123f98d5d5324eb883a3b4b58056c4b350f90ae5 [file] [log] [blame]
Peng Fanc0a59952022-07-26 16:41:14 +08001/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Copyright 2022 NXP
4 */
5
Philip Oberfichtner091338f2024-08-02 11:25:36 +02006#include <asm/gpio.h>
7#include <clk.h>
Peng Fanc0a59952022-07-26 16:41:14 +08008#include <linux/bitops.h>
Philip Oberfichtner091338f2024-08-02 11:25:36 +02009#include <phy_interface.h>
10#include <reset.h>
Peng Fanc0a59952022-07-26 16:41:14 +080011
12/* Core registers */
13
14#define EQOS_MAC_REGS_BASE 0x000
15struct eqos_mac_regs {
16 u32 configuration; /* 0x000 */
17 u32 unused_004[(0x070 - 0x004) / 4]; /* 0x004 */
18 u32 q0_tx_flow_ctrl; /* 0x070 */
19 u32 unused_070[(0x090 - 0x074) / 4]; /* 0x074 */
20 u32 rx_flow_ctrl; /* 0x090 */
21 u32 unused_094; /* 0x094 */
22 u32 txq_prty_map0; /* 0x098 */
23 u32 unused_09c; /* 0x09c */
24 u32 rxq_ctrl0; /* 0x0a0 */
25 u32 unused_0a4; /* 0x0a4 */
26 u32 rxq_ctrl2; /* 0x0a8 */
27 u32 unused_0ac[(0x0dc - 0x0ac) / 4]; /* 0x0ac */
28 u32 us_tic_counter; /* 0x0dc */
29 u32 unused_0e0[(0x11c - 0x0e0) / 4]; /* 0x0e0 */
30 u32 hw_feature0; /* 0x11c */
31 u32 hw_feature1; /* 0x120 */
32 u32 hw_feature2; /* 0x124 */
33 u32 unused_128[(0x200 - 0x128) / 4]; /* 0x128 */
34 u32 mdio_address; /* 0x200 */
35 u32 mdio_data; /* 0x204 */
36 u32 unused_208[(0x300 - 0x208) / 4]; /* 0x208 */
37 u32 address0_high; /* 0x300 */
38 u32 address0_low; /* 0x304 */
39};
40
41#define EQOS_MAC_CONFIGURATION_GPSLCE BIT(23)
42#define EQOS_MAC_CONFIGURATION_CST BIT(21)
43#define EQOS_MAC_CONFIGURATION_ACS BIT(20)
44#define EQOS_MAC_CONFIGURATION_WD BIT(19)
45#define EQOS_MAC_CONFIGURATION_JD BIT(17)
46#define EQOS_MAC_CONFIGURATION_JE BIT(16)
47#define EQOS_MAC_CONFIGURATION_PS BIT(15)
48#define EQOS_MAC_CONFIGURATION_FES BIT(14)
49#define EQOS_MAC_CONFIGURATION_DM BIT(13)
50#define EQOS_MAC_CONFIGURATION_LM BIT(12)
51#define EQOS_MAC_CONFIGURATION_TE BIT(1)
52#define EQOS_MAC_CONFIGURATION_RE BIT(0)
53
54#define EQOS_MAC_Q0_TX_FLOW_CTRL_PT_SHIFT 16
55#define EQOS_MAC_Q0_TX_FLOW_CTRL_PT_MASK 0xffff
56#define EQOS_MAC_Q0_TX_FLOW_CTRL_TFE BIT(1)
57
58#define EQOS_MAC_RX_FLOW_CTRL_RFE BIT(0)
59
60#define EQOS_MAC_TXQ_PRTY_MAP0_PSTQ0_SHIFT 0
61#define EQOS_MAC_TXQ_PRTY_MAP0_PSTQ0_MASK 0xff
62
63#define EQOS_MAC_RXQ_CTRL0_RXQ0EN_SHIFT 0
64#define EQOS_MAC_RXQ_CTRL0_RXQ0EN_MASK 3
65#define EQOS_MAC_RXQ_CTRL0_RXQ0EN_NOT_ENABLED 0
66#define EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_DCB 2
67#define EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_AV 1
68
69#define EQOS_MAC_RXQ_CTRL2_PSRQ0_SHIFT 0
70#define EQOS_MAC_RXQ_CTRL2_PSRQ0_MASK 0xff
71
72#define EQOS_MAC_HW_FEATURE0_MMCSEL_SHIFT 8
73#define EQOS_MAC_HW_FEATURE0_HDSEL_SHIFT 2
74#define EQOS_MAC_HW_FEATURE0_GMIISEL_SHIFT 1
75#define EQOS_MAC_HW_FEATURE0_MIISEL_SHIFT 0
76
77#define EQOS_MAC_HW_FEATURE1_TXFIFOSIZE_SHIFT 6
78#define EQOS_MAC_HW_FEATURE1_TXFIFOSIZE_MASK 0x1f
79#define EQOS_MAC_HW_FEATURE1_RXFIFOSIZE_SHIFT 0
80#define EQOS_MAC_HW_FEATURE1_RXFIFOSIZE_MASK 0x1f
81
82#define EQOS_MAC_HW_FEATURE3_ASP_SHIFT 28
83#define EQOS_MAC_HW_FEATURE3_ASP_MASK 0x3
84
Philip Oberfichtnerabed3722024-05-07 11:42:37 +020085#define EQOS_MAC_MDIO_ADDRESS_PA_MASK GENMASK(25, 21)
86#define EQOS_MAC_MDIO_ADDRESS_RDA_MASK GENMASK(20, 16)
87#define EQOS_MAC_MDIO_ADDRESS_CR_MASK GENMASK(11, 8)
Jonas Karlman098ee4f2023-10-01 19:17:19 +000088#define EQOS_MAC_MDIO_ADDRESS_CR_100_150 1
Peng Fanc0a59952022-07-26 16:41:14 +080089#define EQOS_MAC_MDIO_ADDRESS_CR_20_35 2
90#define EQOS_MAC_MDIO_ADDRESS_CR_250_300 5
91#define EQOS_MAC_MDIO_ADDRESS_SKAP BIT(4)
Philip Oberfichtnerabed3722024-05-07 11:42:37 +020092#define EQOS_MAC_MDIO_ADDRESS_GOC_MASK GENMASK(3, 2)
Peng Fanc0a59952022-07-26 16:41:14 +080093#define EQOS_MAC_MDIO_ADDRESS_GOC_READ 3
94#define EQOS_MAC_MDIO_ADDRESS_GOC_WRITE 1
95#define EQOS_MAC_MDIO_ADDRESS_C45E BIT(1)
96#define EQOS_MAC_MDIO_ADDRESS_GB BIT(0)
97
Philip Oberfichtnerabed3722024-05-07 11:42:37 +020098#define EQOS_MAC_MDIO_DATA_RA_MASK GENMASK(31, 16)
Peng Fanc0a59952022-07-26 16:41:14 +080099#define EQOS_MAC_MDIO_DATA_GD_MASK 0xffff
100
101#define EQOS_MTL_REGS_BASE 0xd00
102struct eqos_mtl_regs {
103 u32 txq0_operation_mode; /* 0xd00 */
104 u32 unused_d04; /* 0xd04 */
105 u32 txq0_debug; /* 0xd08 */
106 u32 unused_d0c[(0xd18 - 0xd0c) / 4]; /* 0xd0c */
107 u32 txq0_quantum_weight; /* 0xd18 */
108 u32 unused_d1c[(0xd30 - 0xd1c) / 4]; /* 0xd1c */
109 u32 rxq0_operation_mode; /* 0xd30 */
110 u32 unused_d34; /* 0xd34 */
111 u32 rxq0_debug; /* 0xd38 */
112};
113
114#define EQOS_MTL_TXQ0_OPERATION_MODE_TQS_SHIFT 16
115#define EQOS_MTL_TXQ0_OPERATION_MODE_TQS_MASK 0x1ff
116#define EQOS_MTL_TXQ0_OPERATION_MODE_TXQEN_SHIFT 2
117#define EQOS_MTL_TXQ0_OPERATION_MODE_TXQEN_MASK 3
118#define EQOS_MTL_TXQ0_OPERATION_MODE_TXQEN_ENABLED 2
119#define EQOS_MTL_TXQ0_OPERATION_MODE_TSF BIT(1)
120#define EQOS_MTL_TXQ0_OPERATION_MODE_FTQ BIT(0)
121
122#define EQOS_MTL_TXQ0_DEBUG_TXQSTS BIT(4)
123#define EQOS_MTL_TXQ0_DEBUG_TRCSTS_SHIFT 1
124#define EQOS_MTL_TXQ0_DEBUG_TRCSTS_MASK 3
125
126#define EQOS_MTL_RXQ0_OPERATION_MODE_RQS_SHIFT 20
127#define EQOS_MTL_RXQ0_OPERATION_MODE_RQS_MASK 0x3ff
128#define EQOS_MTL_RXQ0_OPERATION_MODE_RFD_SHIFT 14
129#define EQOS_MTL_RXQ0_OPERATION_MODE_RFD_MASK 0x3f
130#define EQOS_MTL_RXQ0_OPERATION_MODE_RFA_SHIFT 8
131#define EQOS_MTL_RXQ0_OPERATION_MODE_RFA_MASK 0x3f
132#define EQOS_MTL_RXQ0_OPERATION_MODE_EHFC BIT(7)
133#define EQOS_MTL_RXQ0_OPERATION_MODE_RSF BIT(5)
134
135#define EQOS_MTL_RXQ0_DEBUG_PRXQ_SHIFT 16
136#define EQOS_MTL_RXQ0_DEBUG_PRXQ_MASK 0x7fff
137#define EQOS_MTL_RXQ0_DEBUG_RXQSTS_SHIFT 4
138#define EQOS_MTL_RXQ0_DEBUG_RXQSTS_MASK 3
139
140#define EQOS_DMA_REGS_BASE 0x1000
141struct eqos_dma_regs {
142 u32 mode; /* 0x1000 */
143 u32 sysbus_mode; /* 0x1004 */
144 u32 unused_1008[(0x1100 - 0x1008) / 4]; /* 0x1008 */
145 u32 ch0_control; /* 0x1100 */
146 u32 ch0_tx_control; /* 0x1104 */
147 u32 ch0_rx_control; /* 0x1108 */
148 u32 unused_110c; /* 0x110c */
149 u32 ch0_txdesc_list_haddress; /* 0x1110 */
150 u32 ch0_txdesc_list_address; /* 0x1114 */
151 u32 ch0_rxdesc_list_haddress; /* 0x1118 */
152 u32 ch0_rxdesc_list_address; /* 0x111c */
153 u32 ch0_txdesc_tail_pointer; /* 0x1120 */
154 u32 unused_1124; /* 0x1124 */
155 u32 ch0_rxdesc_tail_pointer; /* 0x1128 */
156 u32 ch0_txdesc_ring_length; /* 0x112c */
157 u32 ch0_rxdesc_ring_length; /* 0x1130 */
158};
159
160#define EQOS_DMA_MODE_SWR BIT(0)
161
162#define EQOS_DMA_SYSBUS_MODE_RD_OSR_LMT_SHIFT 16
163#define EQOS_DMA_SYSBUS_MODE_RD_OSR_LMT_MASK 0xf
164#define EQOS_DMA_SYSBUS_MODE_EAME BIT(11)
165#define EQOS_DMA_SYSBUS_MODE_BLEN16 BIT(3)
166#define EQOS_DMA_SYSBUS_MODE_BLEN8 BIT(2)
167#define EQOS_DMA_SYSBUS_MODE_BLEN4 BIT(1)
168
169#define EQOS_DMA_CH0_CONTROL_DSL_SHIFT 18
Marek Vasut3e8a1be2022-10-09 17:51:46 +0200170#define EQOS_DMA_CH0_CONTROL_DSL_MASK 0x7
Peng Fanc0a59952022-07-26 16:41:14 +0800171#define EQOS_DMA_CH0_CONTROL_PBLX8 BIT(16)
172
173#define EQOS_DMA_CH0_TX_CONTROL_TXPBL_SHIFT 16
174#define EQOS_DMA_CH0_TX_CONTROL_TXPBL_MASK 0x3f
175#define EQOS_DMA_CH0_TX_CONTROL_OSP BIT(4)
176#define EQOS_DMA_CH0_TX_CONTROL_ST BIT(0)
177
178#define EQOS_DMA_CH0_RX_CONTROL_RXPBL_SHIFT 16
179#define EQOS_DMA_CH0_RX_CONTROL_RXPBL_MASK 0x3f
180#define EQOS_DMA_CH0_RX_CONTROL_RBSZ_SHIFT 1
181#define EQOS_DMA_CH0_RX_CONTROL_RBSZ_MASK 0x3fff
182#define EQOS_DMA_CH0_RX_CONTROL_SR BIT(0)
183
184/* These registers are Tegra186-specific */
185#define EQOS_TEGRA186_REGS_BASE 0x8800
186struct eqos_tegra186_regs {
187 u32 sdmemcomppadctrl; /* 0x8800 */
188 u32 auto_cal_config; /* 0x8804 */
189 u32 unused_8808; /* 0x8808 */
190 u32 auto_cal_status; /* 0x880c */
191};
192
193#define EQOS_SDMEMCOMPPADCTRL_PAD_E_INPUT_OR_E_PWRD BIT(31)
194
195#define EQOS_AUTO_CAL_CONFIG_START BIT(31)
196#define EQOS_AUTO_CAL_CONFIG_ENABLE BIT(29)
197
198#define EQOS_AUTO_CAL_STATUS_ACTIVE BIT(31)
199
200/* Descriptors */
201#define EQOS_DESCRIPTORS_TX 4
202#define EQOS_DESCRIPTORS_RX 4
203#define EQOS_DESCRIPTORS_NUM (EQOS_DESCRIPTORS_TX + EQOS_DESCRIPTORS_RX)
204#define EQOS_BUFFER_ALIGN ARCH_DMA_MINALIGN
205#define EQOS_MAX_PACKET_SIZE ALIGN(1568, ARCH_DMA_MINALIGN)
206#define EQOS_RX_BUFFER_SIZE (EQOS_DESCRIPTORS_RX * EQOS_MAX_PACKET_SIZE)
207
208struct eqos_desc {
209 u32 des0;
210 u32 des1;
211 u32 des2;
212 u32 des3;
213};
214
215#define EQOS_DESC3_OWN BIT(31)
216#define EQOS_DESC3_FD BIT(29)
217#define EQOS_DESC3_LD BIT(28)
218#define EQOS_DESC3_BUF1V BIT(24)
219
220#define EQOS_AXI_WIDTH_32 4
221#define EQOS_AXI_WIDTH_64 8
222#define EQOS_AXI_WIDTH_128 16
223
224struct eqos_config {
225 bool reg_access_always_ok;
226 int mdio_wait;
227 int swr_wait;
228 int config_mac;
229 int config_mac_mdio;
230 unsigned int axi_bus_width;
231 phy_interface_t (*interface)(const struct udevice *dev);
232 struct eqos_ops *ops;
233};
234
235struct eqos_ops {
236 void (*eqos_inval_desc)(void *desc);
237 void (*eqos_flush_desc)(void *desc);
238 void (*eqos_inval_buffer)(void *buf, size_t size);
239 void (*eqos_flush_buffer)(void *buf, size_t size);
240 int (*eqos_probe_resources)(struct udevice *dev);
241 int (*eqos_remove_resources)(struct udevice *dev);
242 int (*eqos_stop_resets)(struct udevice *dev);
243 int (*eqos_start_resets)(struct udevice *dev);
244 int (*eqos_stop_clks)(struct udevice *dev);
245 int (*eqos_start_clks)(struct udevice *dev);
246 int (*eqos_calibrate_pads)(struct udevice *dev);
247 int (*eqos_disable_calibration)(struct udevice *dev);
248 int (*eqos_set_tx_clk_speed)(struct udevice *dev);
Peng Fanbf69a7b92022-07-26 16:41:17 +0800249 int (*eqos_get_enetaddr)(struct udevice *dev);
Peng Fanc0a59952022-07-26 16:41:14 +0800250 ulong (*eqos_get_tick_clk_rate)(struct udevice *dev);
Erik Schumacherbc84dba2024-10-28 15:29:42 +0000251 void (*eqos_fix_soc_reset)(struct udevice *dev);
Peng Fanc0a59952022-07-26 16:41:14 +0800252};
253
254struct eqos_priv {
255 struct udevice *dev;
256 const struct eqos_config *config;
257 fdt_addr_t regs;
258 struct eqos_mac_regs *mac_regs;
259 struct eqos_mtl_regs *mtl_regs;
260 struct eqos_dma_regs *dma_regs;
261 struct eqos_tegra186_regs *tegra186_regs;
Sumit Garg7c3be942023-02-01 19:28:55 +0530262 void *eqos_qcom_rgmii_regs;
Peng Fanc0a59952022-07-26 16:41:14 +0800263 struct reset_ctl reset_ctl;
264 struct gpio_desc phy_reset_gpio;
265 struct clk clk_master_bus;
266 struct clk clk_rx;
267 struct clk clk_ptp_ref;
268 struct clk clk_tx;
269 struct clk clk_ck;
270 struct clk clk_slave_bus;
271 struct mii_dev *mii;
272 struct phy_device *phy;
Ye Li2f2aa482022-07-26 16:41:16 +0800273 ofnode phy_of_node;
Peng Fanc0a59952022-07-26 16:41:14 +0800274 u32 max_speed;
Marek Vasut90cc13a2022-10-09 17:51:45 +0200275 void *tx_descs;
276 void *rx_descs;
Peng Fanc0a59952022-07-26 16:41:14 +0800277 int tx_desc_idx, rx_desc_idx;
278 unsigned int desc_size;
Marek Vasut3e8a1be2022-10-09 17:51:46 +0200279 unsigned int desc_per_cacheline;
Peng Fanc0a59952022-07-26 16:41:14 +0800280 void *tx_dma_buf;
281 void *rx_dma_buf;
Peng Fanc0a59952022-07-26 16:41:14 +0800282 bool started;
283 bool reg_access_ok;
284 bool clk_ck_enabled;
Sumit Garg4d5c9652023-02-01 19:28:54 +0530285 unsigned int tx_fifo_sz, rx_fifo_sz;
Sumit Garg7c3be942023-02-01 19:28:55 +0530286 u32 reset_delays[3];
Peng Fanc0a59952022-07-26 16:41:14 +0800287};
288
289void eqos_inval_desc_generic(void *desc);
290void eqos_flush_desc_generic(void *desc);
291void eqos_inval_buffer_generic(void *buf, size_t size);
292void eqos_flush_buffer_generic(void *buf, size_t size);
Philip Oberfichtnerd6d22da2024-08-02 11:25:37 +0200293int eqos_get_base_addr_dt(struct udevice *dev);
Philip Oberfichtner42460352024-08-02 11:25:39 +0200294int eqos_get_base_addr_pci(struct udevice *dev);
Peng Fanc0a59952022-07-26 16:41:14 +0800295int eqos_null_ops(struct udevice *dev);
Philip Oberfichtnerd6d22da2024-08-02 11:25:37 +0200296void *eqos_get_driver_data(struct udevice *dev);
Peng Fan5721a822022-07-26 16:41:15 +0800297
298extern struct eqos_config eqos_imx_config;
Jonas Karlman098ee4f2023-10-01 19:17:19 +0000299extern struct eqos_config eqos_rockchip_config;
Sumit Garg7c3be942023-02-01 19:28:55 +0530300extern struct eqos_config eqos_qcom_config;
Christophe Roullier25a16862024-03-26 13:07:31 +0100301extern struct eqos_config eqos_stm32mp13_config;
Marek Vasut944ba372024-03-26 13:07:23 +0100302extern struct eqos_config eqos_stm32mp15_config;
Yanhong Wang1f502ee2023-06-15 17:36:43 +0800303extern struct eqos_config eqos_jh7110_config;