blob: 77d626393d5afc3139ecded374cd1e9ece2a7680 [file] [log] [blame]
Sumit Garg7c3be942023-02-01 19:28:55 +05301// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2022-2023 Sumit Garg <sumit.garg@linaro.org>
4 *
5 * Qcom DWMAC specific glue layer
6 */
7
Sumit Garg7c3be942023-02-01 19:28:55 +05308#include <asm/global_data.h>
9#include <asm/gpio.h>
10#include <asm/io.h>
11#include <clk.h>
12#include <dm.h>
13#include <dm/device_compat.h>
14#include <phy.h>
15#include <reset.h>
16#include <syscon.h>
17#include <linux/bitops.h>
18#include <linux/delay.h>
19
20#include "dwc_eth_qos.h"
21
22/* RGMII_IO_MACRO_CONFIG fields */
23#define RGMII_CONFIG_FUNC_CLK_EN BIT(30)
24#define RGMII_CONFIG_POS_NEG_DATA_SEL BIT(23)
25#define RGMII_CONFIG_GPIO_CFG_RX_INT GENMASK(21, 20)
26#define RGMII_CONFIG_GPIO_CFG_TX_INT GENMASK(19, 17)
27#define RGMII_CONFIG_MAX_SPD_PRG_9 GENMASK(16, 8)
28#define RGMII_CONFIG_MAX_SPD_PRG_2 GENMASK(7, 6)
29#define RGMII_CONFIG_INTF_SEL GENMASK(5, 4)
30#define RGMII_CONFIG_BYPASS_TX_ID_EN BIT(3)
31#define RGMII_CONFIG_LOOPBACK_EN BIT(2)
32#define RGMII_CONFIG_PROG_SWAP BIT(1)
33#define RGMII_CONFIG_DDR_MODE BIT(0)
34
35/* SDCC_HC_REG_DLL_CONFIG fields */
36#define SDCC_DLL_CONFIG_DLL_RST BIT(30)
37#define SDCC_DLL_CONFIG_PDN BIT(29)
38#define SDCC_DLL_CONFIG_MCLK_FREQ GENMASK(26, 24)
39#define SDCC_DLL_CONFIG_CDR_SELEXT GENMASK(23, 20)
40#define SDCC_DLL_CONFIG_CDR_EXT_EN BIT(19)
41#define SDCC_DLL_CONFIG_CK_OUT_EN BIT(18)
42#define SDCC_DLL_CONFIG_CDR_EN BIT(17)
43#define SDCC_DLL_CONFIG_DLL_EN BIT(16)
44#define SDCC_DLL_MCLK_GATING_EN BIT(5)
45#define SDCC_DLL_CDR_FINE_PHASE GENMASK(3, 2)
46
47/* SDCC_HC_REG_DDR_CONFIG fields */
48#define SDCC_DDR_CONFIG_PRG_DLY_EN BIT(31)
49#define SDCC_DDR_CONFIG_EXT_PRG_RCLK_DLY GENMASK(26, 21)
50#define SDCC_DDR_CONFIG_EXT_PRG_RCLK_DLY_CODE GENMASK(29, 27)
51#define SDCC_DDR_CONFIG_EXT_PRG_RCLK_DLY_EN BIT(30)
52#define SDCC_DDR_CONFIG_PRG_RCLK_DLY GENMASK(8, 0)
53
54/* SDCC_HC_REG_DLL_CONFIG2 fields */
55#define SDCC_DLL_CONFIG2_DLL_CLOCK_DIS BIT(21)
56#define SDCC_DLL_CONFIG2_MCLK_FREQ_CALC GENMASK(17, 10)
57#define SDCC_DLL_CONFIG2_DDR_TRAFFIC_INIT_SEL GENMASK(3, 2)
58#define SDCC_DLL_CONFIG2_DDR_TRAFFIC_INIT_SW BIT(1)
59#define SDCC_DLL_CONFIG2_DDR_CAL_EN BIT(0)
60
61/* SDC4_STATUS bits */
62#define SDC4_STATUS_DLL_LOCK BIT(7)
63
64/* RGMII_IO_MACRO_CONFIG2 fields */
65#define RGMII_CONFIG2_RSVD_CONFIG15 GENMASK(31, 17)
66#define RGMII_CONFIG2_RGMII_CLK_SEL_CFG BIT(16)
67#define RGMII_CONFIG2_TX_TO_RX_LOOPBACK_EN BIT(13)
68#define RGMII_CONFIG2_CLK_DIVIDE_SEL BIT(12)
69#define RGMII_CONFIG2_RX_PROG_SWAP BIT(7)
70#define RGMII_CONFIG2_DATA_DIVIDE_CLK_SEL BIT(6)
71#define RGMII_CONFIG2_TX_CLK_PHASE_SHIFT_EN BIT(5)
72
73struct dwmac_rgmii_regs {
74 u32 io_macro_config; /* 0x00 */
75 u32 sdcc_hc_dll_config; /* 0x04 */
76 u32 reserved_1; /* 0x08 */
77 u32 sdcc_hc_ddr_config; /* 0x0c */
78 u32 sdcc_hc_dll_config2; /* 0x10 */
79 u32 sdc4_status; /* 0x14 */
80 u32 sdcc_usr_ctl; /* 0x18 */
81 u32 io_macro_config2; /* 0x1c */
82 u32 io_macro_debug1; /* 0x20 */
83 u32 reserved_2; /* 0x24 */
84 u32 emac_sys_low_power_dbg; /* 0x28 */
85 u32 reserved_3[53]; /* upto 0x100 */
86};
87
88static struct dwmac_rgmii_regs emac_v2_3_0_por = {
89 .io_macro_config = 0x00C01343,
90 .sdcc_hc_dll_config = 0x2004642C,
91 .sdcc_hc_ddr_config = 0x00000000,
92 .sdcc_hc_dll_config2 = 0x00200000,
93 .sdcc_usr_ctl = 0x00010800,
94 .io_macro_config2 = 0x00002060
95};
96
97static void ethqos_set_func_clk_en(struct dwmac_rgmii_regs *regs)
98{
99 setbits_le32(&regs->io_macro_config, RGMII_CONFIG_FUNC_CLK_EN);
100}
101
102static int ethqos_dll_configure(struct udevice *dev,
103 struct dwmac_rgmii_regs *regs)
104{
105 unsigned int val;
106 int retry = 1000;
107
108 /* Set CDR_EN */
109 setbits_le32(&regs->sdcc_hc_dll_config, SDCC_DLL_CONFIG_CDR_EN);
110
111 /* Set CDR_EXT_EN */
112 setbits_le32(&regs->sdcc_hc_dll_config, SDCC_DLL_CONFIG_CDR_EXT_EN);
113
114 /* Clear CK_OUT_EN */
115 clrbits_le32(&regs->sdcc_hc_dll_config, SDCC_DLL_CONFIG_CK_OUT_EN);
116
117 /* Set DLL_EN */
118 setbits_le32(&regs->sdcc_hc_dll_config, SDCC_DLL_CONFIG_DLL_EN);
119
120 clrbits_le32(&regs->sdcc_hc_dll_config, SDCC_DLL_MCLK_GATING_EN);
121
122 clrbits_le32(&regs->sdcc_hc_dll_config, SDCC_DLL_CDR_FINE_PHASE);
123
124 /* Wait for CK_OUT_EN clear */
125 do {
126 val = readl(&regs->sdcc_hc_dll_config);
127 val &= SDCC_DLL_CONFIG_CK_OUT_EN;
128 if (!val)
129 break;
130 mdelay(1);
131 retry--;
132 } while (retry > 0);
133 if (!retry)
134 dev_err(dev, "Clear CK_OUT_EN timedout\n");
135
136 /* Set CK_OUT_EN */
137 setbits_le32(&regs->sdcc_hc_dll_config, SDCC_DLL_CONFIG_CK_OUT_EN);
138
139 /* Wait for CK_OUT_EN set */
140 retry = 1000;
141 do {
142 val = readl(&regs->sdcc_hc_dll_config);
143 val &= SDCC_DLL_CONFIG_CK_OUT_EN;
144 if (val)
145 break;
146 mdelay(1);
147 retry--;
148 } while (retry > 0);
149 if (!retry)
150 dev_err(dev, "Set CK_OUT_EN timedout\n");
151
152 /* Set DDR_CAL_EN */
153 setbits_le32(&regs->sdcc_hc_dll_config2, SDCC_DLL_CONFIG2_DDR_CAL_EN);
154
155 clrbits_le32(&regs->sdcc_hc_dll_config2,
156 SDCC_DLL_CONFIG2_DLL_CLOCK_DIS);
157
158 clrsetbits_le32(&regs->sdcc_hc_dll_config2,
159 SDCC_DLL_CONFIG2_MCLK_FREQ_CALC, 0x1A << 10);
160
161 clrsetbits_le32(&regs->sdcc_hc_dll_config2,
162 SDCC_DLL_CONFIG2_DDR_TRAFFIC_INIT_SEL, BIT(2));
163
164 setbits_le32(&regs->sdcc_hc_dll_config2,
165 SDCC_DLL_CONFIG2_DDR_TRAFFIC_INIT_SW);
166
167 return 0;
168}
169
170static int ethqos_rgmii_macro_init(struct udevice *dev,
171 struct dwmac_rgmii_regs *regs,
172 unsigned long speed)
173{
174 /* Disable loopback mode */
175 clrbits_le32(&regs->io_macro_config2,
176 RGMII_CONFIG2_TX_TO_RX_LOOPBACK_EN);
177
178 /* Select RGMII, write 0 to interface select */
179 clrbits_le32(&regs->io_macro_config, RGMII_CONFIG_INTF_SEL);
180
181 switch (speed) {
182 case SPEED_1000:
183 setbits_le32(&regs->io_macro_config, RGMII_CONFIG_DDR_MODE);
184 clrbits_le32(&regs->io_macro_config,
185 RGMII_CONFIG_BYPASS_TX_ID_EN);
186 setbits_le32(&regs->io_macro_config,
187 RGMII_CONFIG_POS_NEG_DATA_SEL);
188 setbits_le32(&regs->io_macro_config, RGMII_CONFIG_PROG_SWAP);
189
190 clrbits_le32(&regs->io_macro_config2,
191 RGMII_CONFIG2_DATA_DIVIDE_CLK_SEL);
192 setbits_le32(&regs->io_macro_config2,
193 RGMII_CONFIG2_TX_CLK_PHASE_SHIFT_EN);
194 clrbits_le32(&regs->io_macro_config2,
195 RGMII_CONFIG2_RSVD_CONFIG15);
196 setbits_le32(&regs->io_macro_config2,
197 RGMII_CONFIG2_RX_PROG_SWAP);
198
199 /* Set PRG_RCLK_DLY to 57 for 1.8 ns delay */
200 clrsetbits_le32(&regs->sdcc_hc_ddr_config,
201 SDCC_DDR_CONFIG_PRG_RCLK_DLY, 57);
202 setbits_le32(&regs->sdcc_hc_ddr_config, SDCC_DDR_CONFIG_PRG_DLY_EN);
203
204 setbits_le32(&regs->io_macro_config, RGMII_CONFIG_LOOPBACK_EN);
205 break;
206
207 case SPEED_100:
208 setbits_le32(&regs->io_macro_config, RGMII_CONFIG_DDR_MODE);
209 setbits_le32(&regs->io_macro_config,
210 RGMII_CONFIG_BYPASS_TX_ID_EN);
211 clrbits_le32(&regs->io_macro_config,
212 RGMII_CONFIG_POS_NEG_DATA_SEL);
213 clrbits_le32(&regs->io_macro_config, RGMII_CONFIG_PROG_SWAP);
214 clrsetbits_le32(&regs->io_macro_config,
215 RGMII_CONFIG_MAX_SPD_PRG_2, BIT(6));
216
217 clrbits_le32(&regs->io_macro_config2,
218 RGMII_CONFIG2_DATA_DIVIDE_CLK_SEL);
219 setbits_le32(&regs->io_macro_config2,
220 RGMII_CONFIG2_TX_CLK_PHASE_SHIFT_EN);
221 clrbits_le32(&regs->io_macro_config2,
222 RGMII_CONFIG2_RSVD_CONFIG15);
223 clrbits_le32(&regs->io_macro_config2,
224 RGMII_CONFIG2_RX_PROG_SWAP);
225
226 /* Write 0x5 to PRG_RCLK_DLY_CODE */
227 clrsetbits_le32(&regs->sdcc_hc_ddr_config,
228 SDCC_DDR_CONFIG_EXT_PRG_RCLK_DLY_CODE,
229 (BIT(29) | BIT(27)));
230 setbits_le32(&regs->sdcc_hc_ddr_config,
231 SDCC_DDR_CONFIG_EXT_PRG_RCLK_DLY);
232 setbits_le32(&regs->sdcc_hc_ddr_config,
233 SDCC_DDR_CONFIG_EXT_PRG_RCLK_DLY_EN);
234
235 setbits_le32(&regs->io_macro_config, RGMII_CONFIG_LOOPBACK_EN);
236 break;
237
238 case SPEED_10:
239 setbits_le32(&regs->io_macro_config, RGMII_CONFIG_DDR_MODE);
240 setbits_le32(&regs->io_macro_config,
241 RGMII_CONFIG_BYPASS_TX_ID_EN);
242 clrbits_le32(&regs->io_macro_config,
243 RGMII_CONFIG_POS_NEG_DATA_SEL);
244 clrbits_le32(&regs->io_macro_config, RGMII_CONFIG_PROG_SWAP);
245 clrsetbits_le32(&regs->io_macro_config,
246 RGMII_CONFIG_MAX_SPD_PRG_9,
247 BIT(12) | GENMASK(9, 8));
248
249 clrbits_le32(&regs->io_macro_config2,
250 RGMII_CONFIG2_DATA_DIVIDE_CLK_SEL);
251 clrbits_le32(&regs->io_macro_config2,
252 RGMII_CONFIG2_TX_CLK_PHASE_SHIFT_EN);
253 clrbits_le32(&regs->io_macro_config2,
254 RGMII_CONFIG2_RSVD_CONFIG15);
255 clrbits_le32(&regs->io_macro_config2,
256 RGMII_CONFIG2_RX_PROG_SWAP);
257
258 /* Write 0x5 to PRG_RCLK_DLY_CODE */
259 clrsetbits_le32(&regs->sdcc_hc_ddr_config,
260 SDCC_DDR_CONFIG_EXT_PRG_RCLK_DLY_CODE,
261 (BIT(29) | BIT(27)));
262 setbits_le32(&regs->sdcc_hc_ddr_config,
263 SDCC_DDR_CONFIG_EXT_PRG_RCLK_DLY);
264 setbits_le32(&regs->sdcc_hc_ddr_config,
265 SDCC_DDR_CONFIG_EXT_PRG_RCLK_DLY_EN);
266
267 setbits_le32(&regs->io_macro_config, RGMII_CONFIG_LOOPBACK_EN);
268 break;
269
270 default:
271 dev_err(dev, "Invalid speed %ld\n", speed);
272 return -EINVAL;
273 }
274
275 return 0;
276}
277
278static int ethqos_configure(struct udevice *dev,
279 struct dwmac_rgmii_regs *regs,
280 unsigned long speed)
281{
282 unsigned int retry = 1000;
283
284 /* Reset to POR values and enable clk */
285 writel(emac_v2_3_0_por.io_macro_config, &regs->io_macro_config);
286 writel(emac_v2_3_0_por.sdcc_hc_dll_config, &regs->sdcc_hc_dll_config);
287 writel(emac_v2_3_0_por.sdcc_hc_ddr_config, &regs->sdcc_hc_ddr_config);
288 writel(emac_v2_3_0_por.sdcc_hc_dll_config2, &regs->sdcc_hc_dll_config2);
289 writel(emac_v2_3_0_por.sdcc_usr_ctl, &regs->sdcc_usr_ctl);
290 writel(emac_v2_3_0_por.io_macro_config2, &regs->io_macro_config2);
291
292 ethqos_set_func_clk_en(regs);
293
294 /* Initialize the DLL first */
295
296 /* Set DLL_RST */
297 setbits_le32(&regs->sdcc_hc_dll_config, SDCC_DLL_CONFIG_DLL_RST);
298
299 /* Set PDN */
300 setbits_le32(&regs->sdcc_hc_dll_config, SDCC_DLL_CONFIG_PDN);
301
302 /* Clear DLL_RST */
303 clrbits_le32(&regs->sdcc_hc_dll_config, SDCC_DLL_CONFIG_DLL_RST);
304
305 /* Clear PDN */
306 clrbits_le32(&regs->sdcc_hc_dll_config, SDCC_DLL_CONFIG_PDN);
307
308 if (speed == SPEED_1000) {
309 /* Set DLL_EN */
310 setbits_le32(&regs->sdcc_hc_dll_config, SDCC_DLL_CONFIG_DLL_EN);
311
312 /* Set CK_OUT_EN */
313 setbits_le32(&regs->sdcc_hc_dll_config,
314 SDCC_DLL_CONFIG_CK_OUT_EN);
315
316 /* Set USR_CTL bit 26 with mask of 3 bits */
317 clrsetbits_le32(&regs->sdcc_usr_ctl, GENMASK(26, 24), BIT(26));
318
319 /* wait for DLL LOCK */
320 do {
321 mdelay(1);
322 if (readl(&regs->sdc4_status) & SDC4_STATUS_DLL_LOCK)
323 break;
324 retry--;
325 } while (retry > 0);
326 if (!retry)
327 dev_err(dev, "Timeout while waiting for DLL lock\n");
328
329 ethqos_dll_configure(dev, regs);
330 }
331
332 ethqos_rgmii_macro_init(dev, regs, speed);
333
334 return 0;
335}
336
337static void ethqos_rgmii_dump(struct udevice *dev,
338 struct dwmac_rgmii_regs *regs)
339{
340 dev_dbg(dev, "Rgmii register dump\n");
341 dev_dbg(dev, "RGMII_IO_MACRO_CONFIG: %08x\n",
342 readl(&regs->io_macro_config));
343 dev_dbg(dev, "SDCC_HC_REG_DLL_CONFIG: %08x\n",
344 readl(&regs->sdcc_hc_dll_config));
345 dev_dbg(dev, "SDCC_HC_REG_DDR_CONFIG: %08x\n",
346 readl(&regs->sdcc_hc_ddr_config));
347 dev_dbg(dev, "SDCC_HC_REG_DLL_CONFIG2: %08x\n",
348 readl(&regs->sdcc_hc_dll_config2));
349 dev_dbg(dev, "SDC4_STATUS: %08x\n",
350 readl(&regs->sdc4_status));
351 dev_dbg(dev, "SDCC_USR_CTL: %08x\n",
352 readl(&regs->sdcc_usr_ctl));
353 dev_dbg(dev, "RGMII_IO_MACRO_CONFIG2: %08x\n",
354 readl(&regs->io_macro_config2));
355 dev_dbg(dev, "RGMII_IO_MACRO_DEBUG1: %08x\n",
356 readl(&regs->io_macro_debug1));
357 dev_dbg(dev, "EMAC_SYSTEM_LOW_POWER_DEBUG: %08x\n",
358 readl(&regs->emac_sys_low_power_dbg));
359}
360
361static int qcom_eqos_rgmii_set_speed(struct udevice *dev,
362 void *rgmii_regs,
363 unsigned long speed)
364{
365 int ret;
366
367 ethqos_rgmii_dump(dev, rgmii_regs);
368
369 ret = ethqos_configure(dev, rgmii_regs, speed);
370 if (ret)
371 return ret;
372
373 ethqos_rgmii_dump(dev, rgmii_regs);
374
375 return 0;
376}
377
378static int qcom_eqos_rgmii_reset(struct udevice *dev, void *rgmii_regs)
379{
380 ethqos_set_func_clk_en(rgmii_regs);
381
382 return 0;
383}
384
385static int eqos_start_clks_qcom(struct udevice *dev)
386{
387 if (IS_ENABLED(CONFIG_CLK)) {
388 struct clk_bulk clocks;
389 int ret;
390
391 ret = clk_get_bulk(dev, &clocks);
392 if (ret)
393 return ret;
394
395 ret = clk_enable_bulk(&clocks);
396 if (ret)
397 return ret;
398 }
399
400 debug("%s: OK\n", __func__);
401 return 0;
402}
403
404static int eqos_stop_clks_qcom(struct udevice *dev)
405{
406 if (IS_ENABLED(CONFIG_CLK)) {
407 struct clk_bulk clocks;
408 int ret;
409
410 ret = clk_get_bulk(dev, &clocks);
411 if (ret)
412 return ret;
413
414 ret = clk_disable_bulk(&clocks);
415 if (ret)
416 return ret;
417 }
418
419 debug("%s: OK\n", __func__);
420 return 0;
421}
422
423static int eqos_start_resets_qcom(struct udevice *dev)
424{
425 struct eqos_priv *eqos = dev_get_priv(dev);
426 int ret;
427
428 debug("%s(dev=%p):\n", __func__, dev);
429
430 if (!eqos->phy) {
431 ret = dm_gpio_set_value(&eqos->phy_reset_gpio, 0);
432 if (ret < 0) {
433 pr_err("dm_gpio_set_value(phy_reset, assert) failed: %d", ret);
434 return ret;
435 }
436
437 udelay(eqos->reset_delays[0]);
438
439 ret = dm_gpio_set_value(&eqos->phy_reset_gpio, 1);
440 if (ret < 0) {
441 pr_err("dm_gpio_set_value(phy_reset, deassert) failed: %d", ret);
442 return ret;
443 }
444
445 udelay(eqos->reset_delays[1]);
446
447 ret = dm_gpio_set_value(&eqos->phy_reset_gpio, 0);
448 if (ret < 0) {
449 pr_err("dm_gpio_set_value(phy_reset, deassert) failed: %d", ret);
450 return ret;
451 }
452
453 udelay(eqos->reset_delays[2]);
454 }
455
456 ret = reset_deassert(&eqos->reset_ctl);
457 if (ret < 0) {
458 pr_err("reset_deassert() failed: %d", ret);
459 return ret;
460 }
461
462 ret = qcom_eqos_rgmii_reset(dev, eqos->eqos_qcom_rgmii_regs);
463 if (ret < 0) {
464 pr_err("qcom rgmii_reset failed: %d", ret);
465 return ret;
466 }
467
468 debug("%s: OK\n", __func__);
469 return 0;
470}
471
472/* Clock rates */
473#define RGMII_1000_NOM_CLK_FREQ (250 * 1000 * 1000UL)
474#define RGMII_ID_MODE_100_LOW_SVS_CLK_FREQ (50 * 1000 * 1000UL)
475#define RGMII_ID_MODE_10_LOW_SVS_CLK_FREQ (5 * 1000 * 1000UL)
476
477static int eqos_set_tx_clk_speed_qcom(struct udevice *dev)
478{
479 struct eqos_priv *eqos = dev_get_priv(dev);
480 ulong rate;
481 int ret;
482
483 debug("%s(dev=%p):\n", __func__, dev);
484
485 switch (eqos->phy->speed) {
486 case SPEED_1000:
487 rate = RGMII_1000_NOM_CLK_FREQ;
488 break;
489 case SPEED_100:
490 rate = RGMII_ID_MODE_100_LOW_SVS_CLK_FREQ;
491 break;
492 case SPEED_10:
493 rate = RGMII_ID_MODE_10_LOW_SVS_CLK_FREQ;
494 break;
495 default:
496 pr_err("invalid speed %d", eqos->phy->speed);
497 return -EINVAL;
498 }
499
500 ret = clk_set_rate(&eqos->clk_tx, rate);
501 if (ret < 0) {
502 pr_err("clk_set_rate(tx_clk, %lu) failed: %d", rate, ret);
503 return ret;
504 }
505
506 ret = qcom_eqos_rgmii_set_speed(dev, eqos->eqos_qcom_rgmii_regs,
507 eqos->phy->speed);
508 if (ret < 0) {
509 pr_err("qcom set_speed: %d, failed: %d", eqos->phy->speed, ret);
510 return ret;
511 }
512
513 return 0;
514}
515
516static int eqos_probe_resources_qcom(struct udevice *dev)
517{
518 struct eqos_priv *eqos = dev_get_priv(dev);
519 phy_interface_t interface;
520 int reset_flags = GPIOD_IS_OUT;
521 int ret;
522
523 debug("%s(dev=%p):\n", __func__, dev);
524
525 interface = eqos->config->interface(dev);
526
527 if (interface == PHY_INTERFACE_MODE_NA) {
528 pr_err("Invalid PHY interface\n");
529 return -EINVAL;
530 }
531
532 eqos->max_speed = dev_read_u32_default(dev, "max-speed", 0);
533
534 eqos->tx_fifo_sz = dev_read_u32_default(dev, "tx-fifo-depth", 0);
535 eqos->rx_fifo_sz = dev_read_u32_default(dev, "rx-fifo-depth", 0);
536
537 ret = reset_get_by_name(dev, "emac", &eqos->reset_ctl);
538 if (ret) {
539 pr_err("reset_get_by_name(rst) failed: %d", ret);
540 return ret;
541 }
542
543 if (dev_read_bool(dev, "snps,reset-active-low"))
544 reset_flags |= GPIOD_ACTIVE_LOW;
545
546 ret = gpio_request_by_name(dev, "snps,reset-gpio", 0,
547 &eqos->phy_reset_gpio, reset_flags);
548 if (ret == 0) {
549 ret = dev_read_u32_array(dev, "snps,reset-delays-us",
550 eqos->reset_delays, 3);
551 } else if (ret == -ENOENT) {
552 ret = 0;
553 }
554
555 eqos->eqos_qcom_rgmii_regs = (void *)dev_read_addr_name(dev, "rgmii");
556 if ((fdt_addr_t)eqos->eqos_qcom_rgmii_regs == FDT_ADDR_T_NONE) {
557 pr_err("Invalid RGMII address\n");
558 return -EINVAL;
559 }
560
561 ret = clk_get_by_name(dev, "rgmii", &eqos->clk_tx);
562 if (ret) {
563 pr_err("clk_get_by_name(tx) failed: %d", ret);
564 return -EINVAL;
565 }
566
567 debug("%s: OK\n", __func__);
568 return 0;
569}
570
571static int eqos_remove_resources_qcom(struct udevice *dev)
572{
573 struct eqos_priv *eqos = dev_get_priv(dev);
574
575 debug("%s(dev=%p):\n", __func__, dev);
576
Sumit Garg7c3be942023-02-01 19:28:55 +0530577 dm_gpio_free(dev, &eqos->phy_reset_gpio);
578 reset_free(&eqos->reset_ctl);
579
580 debug("%s: OK\n", __func__);
581 return 0;
582}
583
584static struct eqos_ops eqos_qcom_ops = {
585 .eqos_inval_desc = eqos_inval_desc_generic,
586 .eqos_flush_desc = eqos_flush_desc_generic,
587 .eqos_inval_buffer = eqos_inval_buffer_generic,
588 .eqos_flush_buffer = eqos_flush_buffer_generic,
589 .eqos_probe_resources = eqos_probe_resources_qcom,
590 .eqos_remove_resources = eqos_remove_resources_qcom,
591 .eqos_stop_resets = eqos_null_ops,
592 .eqos_start_resets = eqos_start_resets_qcom,
593 .eqos_stop_clks = eqos_stop_clks_qcom,
594 .eqos_start_clks = eqos_start_clks_qcom,
595 .eqos_calibrate_pads = eqos_null_ops,
596 .eqos_disable_calibration = eqos_null_ops,
597 .eqos_set_tx_clk_speed = eqos_set_tx_clk_speed_qcom,
598 .eqos_get_enetaddr = eqos_null_ops,
599};
600
601struct eqos_config __maybe_unused eqos_qcom_config = {
602 .reg_access_always_ok = false,
603 .mdio_wait = 10,
604 .swr_wait = 50,
605 .config_mac = EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_DCB,
606 .config_mac_mdio = EQOS_MAC_MDIO_ADDRESS_CR_250_300,
607 .axi_bus_width = EQOS_AXI_WIDTH_64,
608 .interface = dev_read_phy_mode,
609 .ops = &eqos_qcom_ops
610};