Import the spi_controller set_cs_timing() hook to make it easier to port Linux spi drivers. Signed-off-by: Marco Felsch <m.felsch@xxxxxxxxxxxxxx> --- Changelog: v2: - add spi_set_cs_timing() drivers/spi/spi.c | 20 ++++++++++++++++++++ include/spi/spi.h | 12 ++++++++++++ 2 files changed, 32 insertions(+) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 78569301776f..425c35759045 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -34,6 +34,22 @@ struct boardinfo { static LIST_HEAD(board_list); static LIST_HEAD(spi_controller_list); +/** + * spi_set_cs_timing - configure CS setup, hold, and inactive delays + * @spi: the device that requires specific CS timing configuration + * + * Return: zero on success, else a negative error code. + */ +static int spi_set_cs_timing(struct spi_device *spi) +{ + int status = 0; + + if (spi->controller->set_cs_timing && !spi->cs_gpiod) + status = spi->controller->set_cs_timing(spi); + + return status; +} + /** * spi_new_device - instantiate one new SPI device * @master: Controller to which device is connected @@ -101,6 +117,10 @@ struct spi_device *spi_new_device(struct spi_controller *ctrl, goto fail; } + status = spi_set_cs_timing(proxy); + if (status) + goto fail; + status = register_device(&proxy->dev); if (status) goto fail; diff --git a/include/spi/spi.h b/include/spi/spi.h index a8bbf55e0a5a..106cca664068 100644 --- a/include/spi/spi.h +++ b/include/spi/spi.h @@ -179,6 +179,9 @@ static inline void spi_set_ctldata(struct spi_device *spi, void *state) * must fail if an unrecognized or unsupported mode is requested. * It's always safe to call this unless transfers are pending on * the device whose settings are being modified. + * @set_cs_timing: optional hook for SPI devices to request SPI master + * controller for configuring specific CS setup time, hold time and inactive + * delay interms of clock counts * @transfer: adds a message to the controller's transfer queue. * @cleanup: frees controller-specific state * @cs_gpiods: Array of GPIO descriptors to use as chip select lines; one per CS @@ -249,6 +252,15 @@ struct spi_controller { /* setup mode and clock, etc (spi driver may call many times) */ int (*setup)(struct spi_device *spi); + /* + * set_cs_timing() method is for SPI controllers that supports + * configuring CS timing. + * + * This hook allows SPI client drivers to request SPI controllers + * to configure specific CS timing through spi_set_cs_timing(). + */ + int (*set_cs_timing)(struct spi_device *spi); + /* bidirectional bulk transfers * * + The transfer() method may not sleep; its main role is -- 2.39.5