Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 33a2fde5f77b ("spi: Introduce spi-cs-setup-ns property")
Signed-off-by: Janne Grunau <j@jannau.net>
Signed-off-by: Hector Martin <marcan@marcan.st>
Link: https://lore.kernel.org/r/20230113102309.18308-2-marcan@marcan.st
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Janne Grunau and committed by
Mark Brown
f276aacf e0fe6a31

+18 -5
+18 -5
drivers/spi/spi.c
··· 2220 2220 /*-------------------------------------------------------------------------*/ 2221 2221 2222 2222 #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 + 2223 2239 static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi, 2224 2240 struct device_node *nc) 2225 2241 { 2226 2242 u32 value; 2227 - u16 cs_setup; 2228 2243 int rc; 2229 2244 2230 2245 /* Mode (clock phase/polarity/etc.) */ ··· 2325 2310 if (!of_property_read_u32(nc, "spi-max-frequency", &value)) 2326 2311 spi->max_speed_hz = value; 2327 2312 2328 - if (!of_property_read_u16(nc, "spi-cs-setup-delay-ns", &cs_setup)) { 2329 - spi->cs_setup.value = cs_setup; 2330 - spi->cs_setup.unit = SPI_DELAY_UNIT_NSECS; 2331 - } 2313 + /* Device CS delays */ 2314 + of_spi_parse_dt_cs_delay(nc, &spi->cs_setup, "spi-cs-setup-delay-ns"); 2332 2315 2333 2316 return 0; 2334 2317 }