[PATCH] spi: dw: Use controller clock rate as maximum frequency

Kunihiko Hayashi hayashi.kunihiko at socionext.com
Wed Oct 25 09:49:51 CEST 2023


Currently the controller driver has maximum frequency in plat->frequency
that is specified by "spi-max-frequency" DT property in the controller
node. This is special to U-Boot and doesn't exist to Linux.

    spi {
        spi-max-frequency = <A>;
    };

Usually the frequency should be specified by "spi-max-frequency" at the
slave device node.

    spi {
        slave {
            spi-max-frequency = <B>;
        };
    };

The final maximum frequency is set to the smaller value of the controller
node (A) and the slave device node (B).

Currently, if the property in the controller node is omitted, the default
frequency is fixed at 500kHz. Even if the controller and the slave device
allow the higher frequency than 500kHz, the maximum frequency can't exceed
500kHz.

The upper limit of the maximum frequency should be determined by the clock
rate of the controller clock. And this patch determines the maximum
frequency based on the clock rate if the controller node property isn't
specified.

Signed-off-by: Kunihiko Hayashi <hayashi.kunihiko at socionext.com>
---
 drivers/spi/designware_spi.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/spi/designware_spi.c b/drivers/spi/designware_spi.c
index 1c7d0ca310b6..637ea57eba24 100644
--- a/drivers/spi/designware_spi.c
+++ b/drivers/spi/designware_spi.c
@@ -250,15 +250,13 @@ static int dw_spi_of_to_plat(struct udevice *bus)
 	if (!plat->regs)
 		return -EINVAL;
 
-	/* Use 500KHz as a suitable default */
+	/* Specify fixed max-frequency as default */
 	plat->frequency = dev_read_u32_default(bus, "spi-max-frequency",
-					       500000);
+					       0);
 
 	if (dev_read_bool(bus, "spi-slave"))
 		return -EINVAL;
 
-	dev_info(bus, "max-frequency=%d\n", plat->frequency);
-
 	return request_gpio_cs(bus);
 }
 
@@ -362,12 +360,17 @@ static int dw_spi_probe(struct udevice *bus)
 	u32 version;
 
 	priv->regs = plat->regs;
-	priv->freq = plat->frequency;
 
 	ret = dw_spi_get_clk(bus, &priv->bus_clk_rate);
 	if (ret)
 		return ret;
 
+	if (!plat->frequency)
+		plat->frequency = priv->bus_clk_rate;
+
+	dev_info(bus, "max-frequency=%d\n", plat->frequency);
+	priv->freq = plat->frequency;
+
 	ret = dw_spi_reset(bus);
 	if (ret)
 		return ret;
-- 
2.25.1



More information about the U-Boot mailing list