Skip to contentSkip to conversation

PATCH New Rajat Jain 4 participants 5 messages Feb 11, 2020 – Feb 26, 2020

Subsystems (3)
lore
Share & tools
lore

Rajat Jain

author
#0 lore raw

From: Evan Green <[email protected]>

Date: Wed, 29 Jan 2020 13:54:16 -0800
Subject: [PATCH] spi: pxa2xx: Add CS control clock quirk

In some circumstances on Intel LPSS controllers, toggling the LPSS CS control register doesn't actually cause the CS line to toggle. This seems to be failure of dynamic clock gating that occurs after going through a suspend/resume transition, where the controller is sent through a reset transition. This ruins SPI transactions that either rely on delay_usecs, or toggle the CS line without sending data.

Whenever CS is toggled, momentarily set the clock gating register to "Force On" to poke the controller into acting on CS.

---
 drivers/spi/spi-pxa2xx.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
drivers/spi/spi-pxa2xx.c +23 -0
index 4c7a71f0fb3e..2e318158fca9 100644
@@ -70,6 +70,10 @@ MODULE_ALIAS("platform:pxa2xx-spi");
 #define LPSS_CAPS_CS_EN_SHIFT			9
 #define LPSS_CAPS_CS_EN_MASK			(0xf << LPSS_CAPS_CS_EN_SHIFT)
 
+#define LPSS_PRIV_CLOCK_GATE 0x38
+#define LPSS_PRIV_CLOCK_GATE_CLK_CTL_MASK 0x3
+#define LPSS_PRIV_CLOCK_GATE_CLK_CTL_FORCE_ON 0x3
+
 struct lpss_config {
 	/* LPSS offset from drv_data->ioaddr */
 	unsigned offset;
@@ -86,6 +90,8 @@ struct lpss_config {
 	unsigned cs_sel_shift;
 	unsigned cs_sel_mask;
 	unsigned cs_num;
+	/* Quirks */
+	unsigned cs_clk_stays_gated : 1;
 };
 
 /* Keep these sorted with enum pxa_ssp_type */
@@ -156,6 +162,7 @@ static const struct lpss_config lpss_platforms[] = {
 		.tx_threshold_hi = 56,
 		.cs_sel_shift = 8,
 		.cs_sel_mask = 3 << 8,
+		.cs_clk_stays_gated = true,
 	},
 };
 
@@ -383,6 +390,22 @@ static void lpss_ssp_cs_control(struct spi_device *spi, bool enable)
 	else
 		value |= LPSS_CS_CONTROL_CS_HIGH;
 	__lpss_ssp_write_priv(drv_data, config->reg_cs_ctrl, value);
+	if (config->cs_clk_stays_gated) {
+		u32 clkgate;
+
+		/*
+		 * Changing CS alone when dynamic clock gating is on won't
+		 * actually flip CS at that time. This ruins SPI transfers
+		 * that specify delays, or have no data. Toggle the clock mode
+		 * to force on briefly to poke the CS pin to move.
+		 */
+		clkgate = __lpss_ssp_read_priv(drv_data, LPSS_PRIV_CLOCK_GATE);
+		value = (clkgate & ~LPSS_PRIV_CLOCK_GATE_CLK_CTL_MASK) |
+			LPSS_PRIV_CLOCK_GATE_CLK_CTL_FORCE_ON;
+
+		__lpss_ssp_write_priv(drv_data, LPSS_PRIV_CLOCK_GATE, value);
+		__lpss_ssp_write_priv(drv_data, LPSS_PRIV_CLOCK_GATE, clkgate);
+	}
 }
 
 static void cs_assert(struct spi_device *spi)
Signature · 1 line
2.25.0.225.g125e21ebc7-goog
#1 lore raw

Hi

+ Andy

Quoted 5 lines · Rajat Jain

From: Evan Green <[email protected]>

Date: Wed, 29 Jan 2020 13:54:16 -0800
Subject: [PATCH] spi: pxa2xx: Add CS control clock quirk

This patch subject is missing from mail subject.

Quoted 11 lines

In some circumstances on Intel LPSS controllers, toggling the LPSS CS control register doesn't actually cause the CS line to toggle. This seems to be failure of dynamic clock gating that occurs after going through a suspend/resume transition, where the controller is sent through a reset transition. This ruins SPI transactions that either rely on delay_usecs, or toggle the CS line without sending data.

Whenever CS is toggled, momentarily set the clock gating register to "Force On" to poke the controller into acting on CS.

Could you share the test case how to trigger this? What's the platform here? I'd like to check does this reproduce on other Intel LPSS platforms so is there need to add quirk for them too.

Quoted 50 lines
---
  drivers/spi/spi-pxa2xx.c | 23 +++++++++++++++++++++++
  1 file changed, 23 insertions(+)
drivers/spi/spi-pxa2xx.c +15 -0
index 4c7a71f0fb3e..2e318158fca9 100644
@@ -70,6 +70,10 @@ MODULE_ALIAS("platform:pxa2xx-spi");
  #define LPSS_CAPS_CS_EN_SHIFT			9
  #define LPSS_CAPS_CS_EN_MASK			(0xf << LPSS_CAPS_CS_EN_SHIFT)
 
+#define LPSS_PRIV_CLOCK_GATE 0x38
+#define LPSS_PRIV_CLOCK_GATE_CLK_CTL_MASK 0x3
+#define LPSS_PRIV_CLOCK_GATE_CLK_CTL_FORCE_ON 0x3
+
  struct lpss_config {
  	/* LPSS offset from drv_data->ioaddr */
  	unsigned offset;
@@ -86,6 +90,8 @@ struct lpss_config {
  	unsigned cs_sel_shift;
  	unsigned cs_sel_mask;
  	unsigned cs_num;
+	/* Quirks */
+	unsigned cs_clk_stays_gated : 1;
  };
 
  /* Keep these sorted with enum pxa_ssp_type */
@@ -156,6 +162,7 @@ static const struct lpss_config lpss_platforms[] = {
  		.tx_threshold_hi = 56,
  		.cs_sel_shift = 8,
  		.cs_sel_mask = 3 << 8,
+		.cs_clk_stays_gated = true,
  	},
  };
 
@@ -383,6 +390,22 @@ static void lpss_ssp_cs_control(struct spi_device *spi, bool enable)
  	else
  		value |= LPSS_CS_CONTROL_CS_HIGH;
  	__lpss_ssp_write_priv(drv_data, config->reg_cs_ctrl, value);
+	if (config->cs_clk_stays_gated) {
+		u32 clkgate;
+
+		/*
+		 * Changing CS alone when dynamic clock gating is on won't
+		 * actually flip CS at that time. This ruins SPI transfers
+		 * that specify delays, or have no data. Toggle the clock mode
+		 * to force on briefly to poke the CS pin to move.

drivers/spi/spi-pxa2xx.c static void lpss_ssp_cs_control(struct spi_device *spi, bool enable) · line 410

Quoted 10 lines
drivers/spi/spi-pxa2xx.c +8 -0
+		 */
+		clkgate = __lpss_ssp_read_priv(drv_data, LPSS_PRIV_CLOCK_GATE);
+		value = (clkgate & ~LPSS_PRIV_CLOCK_GATE_CLK_CTL_MASK) |
+			LPSS_PRIV_CLOCK_GATE_CLK_CTL_FORCE_ON;
+
+		__lpss_ssp_write_priv(drv_data, LPSS_PRIV_CLOCK_GATE, value);
+		__lpss_ssp_write_priv(drv_data, LPSS_PRIV_CLOCK_GATE, clkgate);
+	}
  }
 

I wonder is it enough to have this quick toggling only or is time or actually number of clock cycles dependent? Now there is no delay between but I'm thinking if it needs certain number cycles does this still work when using low ssp_clk rates similar than in commit d0283eb2dbc1 ("spi: pxa2xx: Add output control for multiple Intel LPSS chip selects").

I'm thinking can this be done only once after resume and may other LPSS blocks need the same? I.e. should this be done in drivers/mfd/intel-lpss.c?

Jarkko

#2 lore raw
Quoted 6 lines · Jarkko Nikula

On 2/12/20 12:34 AM, Rajat Jain wrote:

This patch subject is missing from mail subject.

I'm thinking can this be done only once after resume and may other LPSS blocks need the same? I.e. should this be done in drivers/mfd/intel-lpss.c?

On resume we restore the previously saved context, can we be sure that values we saved during suspend are correct?

If above won't show any issue, it might be best place to have this quirk applied in intel_lpss_suspend() / intel_lpss_resume() callbacks as Jarkko suggested.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw

Patchwork summary for: spi-devel-general

In reply to Rajat Jain
The following patches were marked "accepted", because they were applied to broonie/spi.git (refs/heads/for-next):

Hello:

The following patches were marked "accepted", because they were applied to broonie/spi.git (refs/heads/for-next):

Patch: spi: pxa2xx: Add CS control clock quirk
Submitter: Rajat Jain <[email protected]>
Patchwork: https://patchwork.kernel.org/project/spi-devel-general/list/?series=240023

Patch:
Submitter: Rajat Jain <[email protected]>
Patchwork: https://patchwork.kernel.org/project/spi-devel-general/list/?series=240019

Total patches: 2

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.wiki.kernel.org/userdoc/pwbot
author
#4 lore raw

PATCH 1/1 spi: pxa2xx: Add CS control clock quirk

From: Evan Green <[email protected]>

In some circumstances on Intel LPSS controllers, toggling the LPSS CS control register doesn't actually cause the CS line to toggle. This seems to be failure of dynamic clock gating that occurs after going through a suspend/resume transition, where the controller is sent through a reset transition. This ruins SPI transactions that either rely on delay_usecs, or toggle the CS line without sending data.

Whenever CS is toggled, momentarily set the clock gating register to "Force On" to poke the controller into acting on CS.

---
 drivers/spi/spi-pxa2xx.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
drivers/spi/spi-pxa2xx.c +23 -0
index 4c7a71f0fb3e..2e318158fca9 100644
@@ -70,6 +70,10 @@ MODULE_ALIAS("platform:pxa2xx-spi");
 #define LPSS_CAPS_CS_EN_SHIFT			9
 #define LPSS_CAPS_CS_EN_MASK			(0xf << LPSS_CAPS_CS_EN_SHIFT)
 
+#define LPSS_PRIV_CLOCK_GATE 0x38
+#define LPSS_PRIV_CLOCK_GATE_CLK_CTL_MASK 0x3
+#define LPSS_PRIV_CLOCK_GATE_CLK_CTL_FORCE_ON 0x3
+
 struct lpss_config {
 	/* LPSS offset from drv_data->ioaddr */
 	unsigned offset;
@@ -86,6 +90,8 @@ struct lpss_config {
 	unsigned cs_sel_shift;
 	unsigned cs_sel_mask;
 	unsigned cs_num;
+	/* Quirks */
+	unsigned cs_clk_stays_gated : 1;
 };
 
 /* Keep these sorted with enum pxa_ssp_type */
@@ -156,6 +162,7 @@ static const struct lpss_config lpss_platforms[] = {
 		.tx_threshold_hi = 56,
 		.cs_sel_shift = 8,
 		.cs_sel_mask = 3 << 8,
+		.cs_clk_stays_gated = true,
 	},
 };
 
@@ -383,6 +390,22 @@ static void lpss_ssp_cs_control(struct spi_device *spi, bool enable)
 	else
 		value |= LPSS_CS_CONTROL_CS_HIGH;
 	__lpss_ssp_write_priv(drv_data, config->reg_cs_ctrl, value);
+	if (config->cs_clk_stays_gated) {
+		u32 clkgate;
+
+		/*
+		 * Changing CS alone when dynamic clock gating is on won't
+		 * actually flip CS at that time. This ruins SPI transfers
+		 * that specify delays, or have no data. Toggle the clock mode
+		 * to force on briefly to poke the CS pin to move.
+		 */
+		clkgate = __lpss_ssp_read_priv(drv_data, LPSS_PRIV_CLOCK_GATE);
+		value = (clkgate & ~LPSS_PRIV_CLOCK_GATE_CLK_CTL_MASK) |
+			LPSS_PRIV_CLOCK_GATE_CLK_CTL_FORCE_ON;
+
+		__lpss_ssp_write_priv(drv_data, LPSS_PRIV_CLOCK_GATE, value);
+		__lpss_ssp_write_priv(drv_data, LPSS_PRIV_CLOCK_GATE, clkgate);
+	}
 }
 
 static void cs_assert(struct spi_device *spi)
Signature · 1 line
2.25.0.225.g125e21ebc7-goog