Skip to contentSkip to conversation

spi: tegra: fix CS polarity setup

PATCH New Svyatoslav Ryhel 1 participant 2 messages Mar 30, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover spi: tegra: fix CS polarity setup

Add missing configuration of chip select polarity. Default polarity is LOW, which satisfies most cases but some devices require HIGH polarity and will not work.

Svyatoslav Ryhel (1):
spi: tegra20_slink: fix CS polarity setup

 drivers/spi/tegra20_slink.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/1 spi: tegra20_slink: fix CS polarity setup

Add missing configuration of chip select polarity. Default polarity is LOW, which satisfies most cases but some devices require HIGH polarity and will not work.

---
 drivers/spi/tegra20_slink.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
drivers/spi/tegra20_slink.c +18 -0
index d54a5049205..097d9164175 100644
@@ -29,7 +29,10 @@ DECLARE_GLOBAL_DATA_PTR;
 #define SLINK_CMD_IDLE_SCLK_PULL_LOW	(2 << 24)
 #define SLINK_CMD_IDLE_SCLK_PULL_HIGH	(3 << 24)
 #define SLINK_CMD_IDLE_SCLK_MASK	(3 << 24)
+#define SLINK_CMD_CS_POL3		BIT(23)
+#define SLINK_CMD_CS_POL2		BIT(22)
 #define SLINK_CMD_CK_SDA		BIT(21)
+#define SLINK_CMD_CS_POL1		BIT(20)
 #define SLINK_CMD_CS_POL		BIT(13)
 #define SLINK_CMD_CS_VAL		BIT(12)
 #define SLINK_CMD_CS_SOFT		BIT(11)
@@ -64,6 +67,13 @@ DECLARE_GLOBAL_DATA_PTR;
 #define SPI_TIMEOUT		1000
 #define TEGRA_SPI_MAX_FREQ	52000000
 
+unsigned int cmd_cs_pol_bit[] = {
+	SLINK_CMD_CS_POL,
+	SLINK_CMD_CS_POL1,
+	SLINK_CMD_CS_POL2,
+	SLINK_CMD_CS_POL3,
+};
+
 struct spi_regs {
 	u32 command;	/* SLINK_COMMAND_0 register  */
 	u32 command2;	/* SLINK_COMMAND2_0 reg */
@@ -155,6 +165,14 @@ static int tegra30_spi_claim_bus(struct udevice *dev)
 	writel(reg, &regs->status);
 	debug("%s: STATUS = %08x\n", __func__, readl(&regs->status));
 
+	/* Update the polarity bits */
+	if (priv->mode & SPI_CS_HIGH)
+		setbits_le32(&priv->regs->command,
+			     cmd_cs_pol_bit[spi_chip_select(dev)]);
+	else
+		clrbits_le32(&priv->regs->command,
+			     cmd_cs_pol_bit[spi_chip_select(dev)]);
+
 	/* Set master mode and sw controlled CS */
 	reg = readl(&regs->command);
 	reg |= SLINK_CMD_M_S | SLINK_CMD_CS_SOFT;
Signature · 1 line
2.43.0