Commit 4f291b30 authored by Jonathan Cameron's avatar Jonathan Cameron

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.
parents ebe061b9 7e74a45c
...@@ -464,7 +464,10 @@ SLAVE DMA ENGINE ...@@ -464,7 +464,10 @@ SLAVE DMA ENGINE
SPI SPI
devm_spi_alloc_master() devm_spi_alloc_master()
devm_spi_alloc_slave() devm_spi_alloc_slave()
devm_spi_optimize_message()
devm_spi_register_controller() devm_spi_register_controller()
devm_spi_register_host()
devm_spi_register_target()
WATCHDOG WATCHDOG
devm_watchdog_register_device() devm_watchdog_register_device()
...@@ -4378,6 +4378,34 @@ static int __spi_async(struct spi_device *spi, struct spi_message *message) ...@@ -4378,6 +4378,34 @@ static int __spi_async(struct spi_device *spi, struct spi_message *message)
return ctlr->transfer(spi, 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_async - asynchronous SPI transfer
* @spi: device with which data will be exchanged * @spi: device with which data will be exchanged
......
...@@ -1268,6 +1268,8 @@ static inline void spi_message_free(struct spi_message *m) ...@@ -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 int spi_optimize_message(struct spi_device *spi, struct spi_message *msg);
extern void spi_unoptimize_message(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_setup(struct spi_device *spi);
extern int spi_async(struct spi_device *spi, struct spi_message *message); extern int spi_async(struct spi_device *spi, struct spi_message *message);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment