spi: add devm_spi_optimize_message() helper
Subsystems (6)
David Lechner
reviewercover spi: add devm_spi_optimize_message() helper
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.
---
David Lechner (3):
Documentation: devres: add missing SPI helpers
spi: add devm_spi_optimize_message() helper
iio: adc: ad7944: use devm_spi_optimize_message()
Documentation/driver-api/driver-model/devres.rst | 3 +++ drivers/iio/adc/ad7944.c | 26 +++-------------------- drivers/spi/spi.c | 27 ++++++++++++++++++++++++ include/linux/spi/spi.h | 2 ++ 4 files changed, 35 insertions(+), 23 deletions(-)
---
base-commit: 0ca645ab5b1528666f6662a0e620140355b5aea3
change-id: 20240621-devm_spi_optimize_message-ebbde029dd7a
David Lechner
reviewerPATCH 1/3 Documentation: devres: add missing SPI helpers
A few SPI devm_* helpers were missing from the devres documentation. This patch adds them.
--- Documentation/driver-api/driver-model/devres.rst | 2 ++ 1 file changed, 2 insertions(+)
Documentation/driver-api/driver-model/devres.rst +2 -0
@@ -465,6 +465,8 @@ SPI devm_spi_alloc_master() devm_spi_alloc_slave() devm_spi_register_controller() + devm_spi_register_host() + devm_spi_register_target() WATCHDOG devm_watchdog_register_device()
Signature · 1 line
2.45.2
David Lechner
reviewerPATCH 2/3 spi: add devm_spi_optimize_message() helper
In reply to David LechnerThis adds a new helper function devm_spi_optimize_message() that automatically registers spi_unoptimize_message() to be called when the device is removed.
--- Documentation/driver-api/driver-model/devres.rst | 1 + drivers/spi/spi.c | 27 ++++++++++++++++++++++++ include/linux/spi/spi.h | 2 ++ 3 files changed, 30 insertions(+)
Documentation/driver-api/driver-model/devres.rst +1 -0
@@ -464,6 +464,7 @@ 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()
drivers/spi/spi.c +27 -0
@@ -4358,6 +4358,33 @@ 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); +} +/** * spi_async - asynchronous SPI transfer * @spi: device with which data will be exchanged
include/linux/spi/spi.h +2 -0
@@ -1272,6 +1272,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);
Signature · 1 line
2.45.2
Jonathan Cameron
maintainerQuoted 5 lines · On Fri, 21 Jun 2024 15:51:31 -0500 David Lechner <[email protected]> wrote:
This adds a new helper function
devm_spi_optimize_message()that automatically registersspi_unoptimize_message()to be called when the device is removed.Signed-off-by David Lechner <[email protected]>
The new function can be called from modules and doesn't have an EXPORT_SYMBOL_GPL()
I failed to spot this but a build test immediately noticed!
Jonathan
Quoted 42 lines
--- Documentation/driver-api/driver-model/devres.rst | 1 + drivers/spi/spi.c | 27 ++++++++++++++++++++++++ include/linux/spi/spi.h | 2 ++ 3 files changed, 30 insertions(+)Documentation/driver-api/driver-model/devres.rst +1
-0@@ -464,6 +464,7 @@ 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()drivers/spi/spi.c +16
-0@@ -4358,6 +4358,33 @@ 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,
drivers/spi/spi.c static int __spi_async(struct spi_device *spi, struct spi_message *message) · line 4386
Quoted 10 lines
drivers/spi/spi.c +10
-0+ 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); +}
Missing an export.
Quoted 18 lines
drivers/spi/spi.c +1
-0+/** * spi_async - asynchronous SPI transfer * @spi: device with which data will be exchanged include/linux/spi/spi.h +2
-0@@ -1272,6 +1272,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);
David Lechner
reviewerPATCH 3/3 iio: adc: ad7944: use devm_spi_optimize_message()
In reply to David LechnerUse new devm_spi_optimize_message() helper to simplify repeated code in the ad7944 driver.
--- drivers/iio/adc/ad7944.c | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-)
drivers/iio/adc/ad7944.c +3 -23
@@ -134,18 +134,12 @@ AD7944_DEFINE_CHIP_INFO(ad7985, ad7944, 16, 0);/* fully differential */ AD7944_DEFINE_CHIP_INFO (ad7986, ad7986,18 ,1 ); -static void ad7944_unoptimize_msg (void *msg) -{ -spi_unoptimize_message (msg); -} -static int ad7944_3wire_cs_mode_init_msg (struct device *dev,struct ad7944_adc *adc,const struct iio_chan_spec *chan) {unsigned int t_conv_ns = adc->always_turbo ? adc->timing_spec->turbo_conv_ns : adc->timing_spec->conv_ns;struct spi_transfer *xfers = adc->xfers; -int ret;/* * NB: can get better performance from some SPI controllers if we use
@@ -175,11 +169,7 @@ static int ad7944_3wire_cs_mode_init_msg(struct device *dev, struct ad7944_adc *spi_message_init_with_transfers (&adc->msg, xfers,3 ); - ret =spi_optimize_message (adc->spi, &adc->msg); -if (ret) -return ret; - -return devm_add_action_or_reset (dev, ad7944_unoptimize_msg, &adc->msg); +return devm_spi_optimize_message (dev, adc->spi, &adc->msg); } static int ad7944_4wire_mode_init_msg(struct device *dev, struct ad7944_adc *adc,
@@ -188,7 +178,6 @@ static int ad7944_4wire_mode_init_msg(struct device *dev, struct ad7944_adc *adcunsigned int t_conv_ns = adc->always_turbo ? adc->timing_spec->turbo_conv_ns : adc->timing_spec->conv_ns;struct spi_transfer *xfers = adc->xfers; -int ret;/* * NB: can get better performance from some SPI controllers if we use
@@ -209,11 +198,7 @@ static int ad7944_4wire_mode_init_msg(struct device *dev, struct ad7944_adc *adcspi_message_init_with_transfers (&adc->msg, xfers,2 ); - ret =spi_optimize_message (adc->spi, &adc->msg); -if (ret) -return ret; - -return devm_add_action_or_reset (dev, ad7944_unoptimize_msg, &adc->msg); +return devm_spi_optimize_message (dev, adc->spi, &adc->msg); } static int ad7944_chain_mode_init_msg(struct device *dev, struct ad7944_adc *adc,
@@ -221,7 +206,6 @@ static int ad7944_chain_mode_init_msg(struct device *dev, struct ad7944_adc *adc u32 n_chain_dev) {struct spi_transfer *xfers = adc->xfers; -int ret;/* * NB: SCLK has to be low before we toggle CS to avoid triggering the
@@ -249,11 +233,7 @@ static int ad7944_chain_mode_init_msg(struct device *dev, struct ad7944_adc *adcspi_message_init_with_transfers (&adc->msg, xfers,2 ); - ret =spi_optimize_message (adc->spi, &adc->msg); -if (ret) -return ret; - -return devm_add_action_or_reset (dev, ad7944_unoptimize_msg, &adc->msg); +return devm_spi_optimize_message (dev, adc->spi, &adc->msg); }/**
Signature · 1 line
2.45.2
Jonathan Cameron
maintainerQuoted 4 lines · On Fri, 21 Jun 2024 15:51:29 -0500 David Lechner <[email protected]> wrote:
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 adevm_spi_optimize_message()helper to simplify this common pattern.
Looks good to me. Obviously I need Mark's ack or an immutable branch to pick these up though.
Thanks
Jonathan
Quoted 15 lines
---
David Lechner (3):
Documentation: devres: add missing SPI helpers
spi: adddevm_spi_optimize_message()helper
iio: adc: ad7944: usedevm_spi_optimize_message()Documentation/driver-api/driver-model/devres.rst | 3 +++ drivers/iio/adc/ad7944.c | 26 +++-------------------- drivers/spi/spi.c | 27 ++++++++++++++++++++++++ include/linux/spi/spi.h | 2 ++ 4 files changed, 35 insertions(+), 23 deletions(-)---
base-commit:0ca645ab5b1528666f6662a0e620140355b5aea3
change-id: 20240621-devm_spi_optimize_message-ebbde029dd7a
Mark Brown
maintainerRe: (subset) [PATCH 0/3] spi: add devm_spi_optimize_message() helper
In reply to David LechnerQuoted 5 lines · David Lechner
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 adevm_spi_optimize_message()helper to simplify this common pattern.
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next
Thanks!
[1/3] Documentation: devres: add missing SPI helpers
commit: 9b894d65e9788ece0d51e76d2c184524900f5ec9
[2/3] spi: add devm_spi_optimize_message() helper
commit: 17436001a6bc42c7f55dc547ca5b1a873208d91dAll being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Mark Brown
maintainerQuoted 4 lines · David Lechner
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 adevm_spi_optimize_message()helper to simplify this common pattern.
The following changes since commit 6ba59ff4227927d3a8530fc2973b80e94b54d58f:
Linux 6.10-rc4 (2024-06-16 13:40:16 -0700)
are available in the Git repository at:
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git tags/spi-devm-optimize
for you to fetch changes up to d4a0055fdc22381fa256e345095e88d134e354c5:
spi: add devm_spi_optimize_message() helper (2024-06-22 12:14:33 +0100)
----------------------------------------------------------------
spi: add devm_spi_optimize_message() helper
Helper from David Lechner <[email protected]>:
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.
----------------------------------------------------------------
David Lechner (2):
Documentation: devres: add missing SPI helpers
spi: add devm_spi_optimize_message() helper
Documentation/driver-api/driver-model/devres.rst | 3 +++ drivers/spi/spi.c | 27 ++++++++++++++++++++++++ include/linux/spi/spi.h | 2 ++ 3 files changed, 32 insertions(+)
Jonathan Cameron
maintainerQuoted 6 lines · On Sun, 23 Jun 2024 18:20:39 +0100 Mark Brown <[email protected]> wrote:
Quoted 4 lines · David Lechner
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 adevm_spi_optimize_message()helper to simplify this common pattern.
Quoted 7 lines
The following changes since commit
6ba59ff4227927d3a8530fc2973b80e94b54d58f:Linux 6.10-rc4 (2024-06-16 13:40:16 -0700)
are available in the Git repository at:
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git tags/spi-devm-optimize
Thanks. Applied patch 3 on a merge of that tag into the togreg branch of iio.git which I've pushed out as testing to see if anything went horribly wrong ;)
Jonathan
Quoted 24 lines
for you to fetch changes up to
d4a0055fdc22381fa256e345095e88d134e354c5:spi: add
devm_spi_optimize_message()helper (2024-06-22 12:14:33 +0100)----------------------------------------------------------------
spi: adddevm_spi_optimize_message()helperHelper from David Lechner <[email protected]>:
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 adevm_spi_optimize_message()helper to simplify this common pattern.----------------------------------------------------------------
David Lechner (2):
Documentation: devres: add missing SPI helpers
spi: adddevm_spi_optimize_message()helperDocumentation/driver-api/driver-model/devres.rst | 3 +++ drivers/spi/spi.c | 27 ++++++++++++++++++++++++ include/linux/spi/spi.h | 2 ++ 3 files changed, 32 insertions(+)
Jonathan Cameron
maintainerQuoted 13 lines · On Mon, 24 Jun 2024 20:39:18 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 10 lines · On Sun, 23 Jun 2024 18:20:39 +0100 Mark Brown <[email protected]> wrote:
Quoted 4 lines · David Lechner
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 adevm_spi_optimize_message()helper to simplify this common pattern.The following changes since commit
6ba59ff4227927d3a8530fc2973b80e94b54d58f:Linux 6.10-rc4 (2024-06-16 13:40:16 -0700)
Quoted 8 lines
Quoted 3 lines
are available in the Git repository at:
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git tags/spi-devm-optimize
Thanks. Applied patch 3 on a merge of that tag into the togreg branch of iio.git which I've pushed out as testing to see if anything went horribly wrong ;)
Hit send too soon. The new devm_spi_optmize_message() is missing an EXPORT_SYMBOL_* so my local build test with modules failed.
Jonathan
Quoted 27 lines
Jonathan
Quoted 24 lines
for you to fetch changes up to
d4a0055fdc22381fa256e345095e88d134e354c5:spi: add
devm_spi_optimize_message()helper (2024-06-22 12:14:33 +0100)----------------------------------------------------------------
spi: adddevm_spi_optimize_message()helperHelper from David Lechner <[email protected]>:
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 adevm_spi_optimize_message()helper to simplify this common pattern.----------------------------------------------------------------
David Lechner (2):
Documentation: devres: add missing SPI helpers
spi: adddevm_spi_optimize_message()helperDocumentation/driver-api/driver-model/devres.rst | 3 +++ drivers/spi/spi.c | 27 ++++++++++++++++++++++++ include/linux/spi/spi.h | 2 ++ 3 files changed, 32 insertions(+)