Skip to content

Commit f276aac

Browse files
jannaubroonie
authored andcommitted
spi: Use a 32-bit DT property for spi-cs-setup-delay-ns
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: 33a2fde ("spi: Introduce spi-cs-setup-ns property") Signed-off-by: Janne Grunau <[email protected]> Signed-off-by: Hector Martin <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent e0fe6a3 commit f276aac

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

drivers/spi/spi.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,11 +2220,26 @@ void spi_flush_queue(struct spi_controller *ctlr)
22202220
/*-------------------------------------------------------------------------*/
22212221

22222222
#if defined(CONFIG_OF)
2223+
static void of_spi_parse_dt_cs_delay(struct device_node *nc,
2224+
struct spi_delay *delay, const char *prop)
2225+
{
2226+
u32 value;
2227+
2228+
if (!of_property_read_u32(nc, prop, &value)) {
2229+
if (value > U16_MAX) {
2230+
delay->value = DIV_ROUND_UP(value, 1000);
2231+
delay->unit = SPI_DELAY_UNIT_USECS;
2232+
} else {
2233+
delay->value = value;
2234+
delay->unit = SPI_DELAY_UNIT_NSECS;
2235+
}
2236+
}
2237+
}
2238+
22232239
static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi,
22242240
struct device_node *nc)
22252241
{
22262242
u32 value;
2227-
u16 cs_setup;
22282243
int rc;
22292244

22302245
/* Mode (clock phase/polarity/etc.) */
@@ -2310,10 +2325,8 @@ static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi,
23102325
if (!of_property_read_u32(nc, "spi-max-frequency", &value))
23112326
spi->max_speed_hz = value;
23122327

2313-
if (!of_property_read_u16(nc, "spi-cs-setup-delay-ns", &cs_setup)) {
2314-
spi->cs_setup.value = cs_setup;
2315-
spi->cs_setup.unit = SPI_DELAY_UNIT_NSECS;
2316-
}
2328+
/* Device CS delays */
2329+
of_spi_parse_dt_cs_delay(nc, &spi->cs_setup, "spi-cs-setup-delay-ns");
23172330

23182331
return 0;
23192332
}

0 commit comments

Comments
 (0)