[3/5] spi: Use a 32-bit DT property for spi-cs-setup-delay-ns

Message ID 20230104093631.15611-4-marcan@marcan.st
State New
Headers
Series SPI core CS delay fixes and additions |

Commit Message

Hector Martin Jan. 4, 2023, 9:36 a.m. UTC
  From: Janne Grunau <j@jannau.net>

65us is not a reasonable maximum for this property, as some devices
might need a much longer setup time (e.g. those driven by firmware on
the other end). Plus, device tree property values are in 32-bit cells
and smaller widths should not be used without good reason.

Also move the logic to a helper function, since this will later be used
to parse other CS delay properties too.

Fixes: 33a2fde5f77b ("spi: Introduce spi-cs-setup-ns property")
Signed-off-by: Janne Grunau <j@jannau.net>
Signed-off-by: Hector Martin <marcan@marcan.st>
---
 drivers/spi/spi.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
  

Comments

Mark Brown Jan. 6, 2023, 4:26 p.m. UTC | #1
On Wed, Jan 04, 2023 at 06:36:29PM +0900, Janne Grunau wrote:

> 65us is not a reasonable maximum for this property, as some devices
> might need a much longer setup time (e.g. those driven by firmware on
> the other end). Plus, device tree property values are in 32-bit cells
> and smaller widths should not be used without good reason.

This breaks allmodconfig builds (I tested x86 but this should happen
for anything with -Werror):

/build/stage/linux/drivers/spi/spi.c: In function ‘of_spi_parse_dt’:
/build/stage/linux/drivers/spi/spi.c:2243:13: error: unused variable ‘cs_setup’ [-Werror=unused-variable]
 2243 |         u16 cs_setup;
      |             ^~~~~~~~
cc1: all warnings being treated as errors
  
Hector Martin Jan. 6, 2023, 4:40 p.m. UTC | #2
On 07/01/2023 01.26, Mark Brown wrote:
> On Wed, Jan 04, 2023 at 06:36:29PM +0900, Janne Grunau wrote:
> 
>> 65us is not a reasonable maximum for this property, as some devices
>> might need a much longer setup time (e.g. those driven by firmware on
>> the other end). Plus, device tree property values are in 32-bit cells
>> and smaller widths should not be used without good reason.
> 
> This breaks allmodconfig builds (I tested x86 but this should happen
> for anything with -Werror):
> 
> /build/stage/linux/drivers/spi/spi.c: In function ‘of_spi_parse_dt’:
> /build/stage/linux/drivers/spi/spi.c:2243:13: error: unused variable ‘cs_setup’ [-Werror=unused-variable]
>  2243 |         u16 cs_setup;
>       |             ^~~~~~~~
> cc1: all warnings being treated as errors

Yeah, the kernel test robot caught this one too. Sorry for missing it
(it got buried in warning noise in a rather large rebuild on my side).
That line should've been removed in #3 :(

I see two patches got applied already. Do you want me to just respin #3-#5?

- Hector
  
Mark Brown Jan. 6, 2023, 6:34 p.m. UTC | #3
On Sat, Jan 07, 2023 at 01:40:49AM +0900, Hector Martin wrote:

> Yeah, the kernel test robot caught this one too. Sorry for missing it
> (it got buried in warning noise in a rather large rebuild on my side).
> That line should've been removed in #3 :(

> I see two patches got applied already. Do you want me to just respin #3-#5?

Yes, please.
  

Patch

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 15f174f4e056..370e4c85dc54 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -2220,6 +2220,22 @@  void spi_flush_queue(struct spi_controller *ctlr)
 /*-------------------------------------------------------------------------*/
 
 #if defined(CONFIG_OF)
+static void of_spi_parse_dt_cs_delay(struct device_node *nc,
+				     struct spi_delay *delay, const char *prop)
+{
+	u32 value;
+
+	if (!of_property_read_u32(nc, prop, &value)) {
+		if (value > U16_MAX) {
+			delay->value = DIV_ROUND_UP(value, 1000);
+			delay->unit = SPI_DELAY_UNIT_USECS;
+		} else {
+			delay->value = value;
+			delay->unit = SPI_DELAY_UNIT_NSECS;
+		}
+	}
+}
+
 static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi,
 			   struct device_node *nc)
 {
@@ -2310,10 +2326,8 @@  static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi,
 	if (!of_property_read_u32(nc, "spi-max-frequency", &value))
 		spi->max_speed_hz = value;
 
-	if (!of_property_read_u16(nc, "spi-cs-setup-delay-ns", &cs_setup)) {
-		spi->cs_setup.value = cs_setup;
-		spi->cs_setup.unit = SPI_DELAY_UNIT_NSECS;
-	}
+	/* Device CS delays */
+	of_spi_parse_dt_cs_delay(nc, &spi->cs_setup, "spi-cs-setup-delay-ns");
 
 	return 0;
 }