Thread (22 messages) 22 messages, 5 authors, 2026-01-22

Re: [PATCH net-next 3/3] net: stmmac: Add glue layer for Spacemit K3 SoC

From: Andrew Lunn <andrew@lunn.ch>
Date: 2026-01-20 13:56:56
Also in: linux-devicetree, linux-riscv, lkml, netdev, spacemit

+/* Note: the delay step value is at 0.1ps */
+static const unsigned int k3_delay_step_10x[4] = {
+	367, 493, 559, 685
+};
Am i reading it correctly that RGMII delays are limited to these four
values?

If so, please add this list to the DT binding.
+static int spacemit_dwmac_detected_delay_value(unsigned int delay,
+					       unsigned int *config)
+{
+	int i;
+	int code, best_code = 0;
+	unsigned int best_delay = 0;
+	unsigned int best_config = 0;
+
+	if (delay == 0)
+		return 0;
+
+	for (i = 0; i < ARRAY_SIZE(k3_delay_step_10x); i++) {
+		unsigned int step = k3_delay_step_10x[i];
+
+		for (code = 1; code <= MAX_DLINE_DELAY_CODE; code++) {
+			/*
+			 * Note K3 require a specific factor for calculate
+			 * the delay, in this scenario it is 0.9. So the
+			 * formula is code * step / 10 * 0.9
+			 */
+			unsigned int tmp = code * step * 9 / 10 / 10;
+
+			if (abs(tmp - delay) < abs(best_delay - delay)) {
+				best_code = code;
+				best_delay = tmp;
+				best_config = i;
+			}
+		}
+	}
With the four values listed in DT, i would make this a straight match,
not the nearest, and return -EINVAL otherwise.

    Andrew
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help