[PATCH 16/27] sunxi: spi: restore bus speed and mode after reset

Yifan Gu me at yifangu.com
Mon Jul 26 01:16:25 CEST 2021


From: George Hilliard <thirtythreeforty at gmail.com>

The sunxi SPI peripheral driver resets the device completely (disabling
clocks and power) when the bus is released and turns it back on when
claiming.  On the F1C100s (and maybe others), the peripheral resets back
to default register settings, losing speed and mode settings.

Restore these settings when resetting the peripheral.

Signed-off-by: George Hilliard <thirtythreeforty at gmail.com>
Signed-off-by: Yifan Gu <me at yifangu.com>
---
 drivers/spi/spi-sunxi.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi-sunxi.c b/drivers/spi/spi-sunxi.c
index 4ca5d3a93a..aa392502b7 100644
--- a/drivers/spi/spi-sunxi.c
+++ b/drivers/spi/spi-sunxi.c
@@ -39,6 +39,10 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+/* Forward declarations of some reused functions */
+static int sun4i_spi_set_speed(struct udevice *dev, uint speed);
+static int sun4i_spi_set_mode(struct udevice *dev, uint mode);
+
 /* sun4i spi registers */
 #define SUN4I_RXDATA_REG		0x00
 #define SUN4I_TXDATA_REG		0x04
@@ -304,7 +308,8 @@ err_ahb:
 
 static int sun4i_spi_claim_bus(struct udevice *dev)
 {
-	struct sun4i_spi_priv *priv = dev_get_priv(dev->parent);
+	struct udevice *bus = dev->parent;
+	struct sun4i_spi_priv *priv = dev_get_priv(bus);
 	int ret;
 
 	ret = sun4i_spi_set_clock(dev->parent, true);
@@ -321,6 +326,9 @@ static int sun4i_spi_claim_bus(struct udevice *dev)
 	setbits_le32(SPI_REG(priv, SPI_TCR), SPI_BIT(priv, SPI_TCR_CS_MANUAL) |
 		     SPI_BIT(priv, SPI_TCR_CS_ACTIVE_LOW));
 
+	sun4i_spi_set_speed(bus, priv->freq);
+	sun4i_spi_set_mode(bus, priv->mode);
+
 	return 0;
 }
 
-- 
2.25.1



More information about the U-Boot mailing list