spi: add devm_spi_optimize_message() helper

Helper from David Lechner <dlechner@baylibre.com>:
 
     In the IIO subsystem, we are finding that it is common to call
     spi_optimize_message() during driver probe since the SPI message
     doesn't change for the lifetime of the driver. This patch adds a
     devm_spi_optimize_message() helper to simplify this common pattern.
 -----BEGIN PGP SIGNATURE-----
 
 iQEzBAABCgAdFiEEreZoqmdXGLWf4p/qJNaLcl1Uh9AFAmZ67wYACgkQJNaLcl1U
 h9DxbggAhOXNRXFzzQZ7bB+gQc0rLm6zKMwoEYMZSy5uoqZH3kby/P0tvhjCKAFe
 61Ox/77tOJIGQU8Pj3zHQOMrGRhnMADlKEhiN3qCLVJrsE3c2a/Ml8+/NI4udESW
 1A5zBLIFBk8YVQRAA+jpwH2VuSrumDR5v+j/4zfE3AkLwcROnrQuSK9Nkv7lEYtv
 zTE+rA7vJb+J4TrludrIU5uwogFYijv1bmNXNsJvq/uYNaap0DDXxBvYF9XNb075
 AQoJQyDNAJmhg5r1n1GFEXpIRSXx/i5ciLxI+iIZpuNHThEQX8AuNmpkngsnq/SC
 7s2U6Esihuq2ocUvugHfPKS8Z8IiFg==
 =A7WZ
 -----END PGP SIGNATURE-----

Merge tag 'spi-devm-optimize' into togreg

spi: add devm_spi_optimize_message() helper

Helper from David Lechner <dlechner@baylibre.com>:

    In the IIO subsystem, we are finding that it is common to call
    spi_optimize_message() during driver probe since the SPI message
    doesn't change for the lifetime of the driver. This patch adds a
    devm_spi_optimize_message() helper to simplify this common pattern.
This commit is contained in:
Jonathan Cameron 2024-06-30 11:36:58 +01:00
commit 4f291b3016
3 changed files with 33 additions and 0 deletions

View File

@ -464,7 +464,10 @@ SLAVE DMA ENGINE
SPI
devm_spi_alloc_master()
devm_spi_alloc_slave()
devm_spi_optimize_message()
devm_spi_register_controller()
devm_spi_register_host()
devm_spi_register_target()
WATCHDOG
devm_watchdog_register_device()

View File

@ -4378,6 +4378,34 @@ static int __spi_async(struct spi_device *spi, struct spi_message *message)
return ctlr->transfer(spi, message);
}
static void devm_spi_unoptimize_message(void *msg)
{
spi_unoptimize_message(msg);
}
/**
* devm_spi_optimize_message - managed version of spi_optimize_message()
* @dev: the device that manages @msg (usually @spi->dev)
* @spi: the device that will be used for the message
* @msg: the message to optimize
* Return: zero on success, else a negative error code
*
* spi_unoptimize_message() will automatically be called when the device is
* removed.
*/
int devm_spi_optimize_message(struct device *dev, struct spi_device *spi,
struct spi_message *msg)
{
int ret;
ret = spi_optimize_message(spi, msg);
if (ret)
return ret;
return devm_add_action_or_reset(dev, devm_spi_unoptimize_message, msg);
}
EXPORT_SYMBOL_GPL(devm_spi_optimize_message);
/**
* spi_async - asynchronous SPI transfer
* @spi: device with which data will be exchanged

View File

@ -1268,6 +1268,8 @@ static inline void spi_message_free(struct spi_message *m)
extern int spi_optimize_message(struct spi_device *spi, struct spi_message *msg);
extern void spi_unoptimize_message(struct spi_message *msg);
extern int devm_spi_optimize_message(struct device *dev, struct spi_device *spi,
struct spi_message *msg);
extern int spi_setup(struct spi_device *spi);
extern int spi_async(struct spi_device *spi, struct spi_message *message);