linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] spi: add devm_spi_optimize_message() helper
@ 2024-06-24 20:10 David Lechner
  2024-06-24 20:10 ` [PATCH v2 1/2] spi: add EXPORT_SYMBOL_GPL(devm_spi_optimize_message) David Lechner
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: David Lechner @ 2024-06-24 20:10 UTC (permalink / raw)
  To: Mark Brown, Jonathan Cameron
  Cc: David Lechner, Michael Hennerich, Nuno Sá, Marcelo Schmitt,
	Jonathan Corbet, linux-doc, linux-kernel, linux-spi, linux-iio

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.

---
Changes in v2:
- Dropped already applied SPI patches.
- Added patch to fix missing EXPORT_SYMBOL_GPL.
- Link to v1: https://lore.kernel.org/r/20240621-devm_spi_optimize_message-v1-0-3f9dcba6e95e@baylibre.com

---
David Lechner (2):
      spi: add EXPORT_SYMBOL_GPL(devm_spi_optimize_message)
      iio: adc: ad7944: use devm_spi_optimize_message()

 drivers/iio/adc/ad7944.c | 26 +++-----------------------
 drivers/spi/spi.c        |  1 +
 2 files changed, 4 insertions(+), 23 deletions(-)
---
base-commit: 17436001a6bc42c7f55dc547ca5b1a873208d91d
change-id: 20240621-devm_spi_optimize_message-ebbde029dd7a

Best regards,
-- 
David Lechner <dlechner@baylibre.com>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/2] spi: add EXPORT_SYMBOL_GPL(devm_spi_optimize_message)
  2024-06-24 20:10 [PATCH v2 0/2] spi: add devm_spi_optimize_message() helper David Lechner
@ 2024-06-24 20:10 ` David Lechner
  2024-06-24 20:19   ` Mark Brown
  2024-06-25 16:24   ` Mark Brown
  2024-06-24 20:10 ` [PATCH v2 2/2] iio: adc: ad7944: use devm_spi_optimize_message() David Lechner
  2024-06-25 18:46 ` (subset) [PATCH v2 0/2] spi: add devm_spi_optimize_message() helper Mark Brown
  2 siblings, 2 replies; 6+ messages in thread
From: David Lechner @ 2024-06-24 20:10 UTC (permalink / raw)
  To: Mark Brown, Jonathan Cameron
  Cc: David Lechner, Michael Hennerich, Nuno Sá, Marcelo Schmitt,
	Jonathan Corbet, linux-doc, linux-kernel, linux-spi, linux-iio

devm_spi_optimize_message() is a public function and needs
EXPORT_SYMBOL_GPL.

Reported-by: Jonathan Cameron <jic23@kernel.org>
Closes: https://lore.kernel.org/linux-iio/20240624204424.6a91a5e4@jic23-huawei/
Fixes: 17436001a6bc ("spi: add devm_spi_optimize_message() helper")
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
 drivers/spi/spi.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 3f953504244b..814d66fc9753 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -4384,6 +4384,7 @@ int devm_spi_optimize_message(struct device *dev, struct spi_device *spi,
 
 	return devm_add_action_or_reset(dev, devm_spi_unoptimize_message, msg);
 }
+EXPORT_SYMBOL_GPL(devm_spi_optimize_message);
 
 /**
  * spi_async - asynchronous SPI transfer

-- 
2.45.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/2] iio: adc: ad7944: use devm_spi_optimize_message()
  2024-06-24 20:10 [PATCH v2 0/2] spi: add devm_spi_optimize_message() helper David Lechner
  2024-06-24 20:10 ` [PATCH v2 1/2] spi: add EXPORT_SYMBOL_GPL(devm_spi_optimize_message) David Lechner
@ 2024-06-24 20:10 ` David Lechner
  2024-06-25 18:46 ` (subset) [PATCH v2 0/2] spi: add devm_spi_optimize_message() helper Mark Brown
  2 siblings, 0 replies; 6+ messages in thread
From: David Lechner @ 2024-06-24 20:10 UTC (permalink / raw)
  To: Mark Brown, Jonathan Cameron
  Cc: David Lechner, Michael Hennerich, Nuno Sá, Marcelo Schmitt,
	Jonathan Corbet, linux-doc, linux-kernel, linux-spi, linux-iio

Use new devm_spi_optimize_message() helper to simplify repeated code
in the ad7944 driver.

Signed-off-by: David Lechner <dlechner@baylibre.com>
---
 drivers/iio/adc/ad7944.c | 26 +++-----------------------
 1 file changed, 3 insertions(+), 23 deletions(-)

diff --git a/drivers/iio/adc/ad7944.c b/drivers/iio/adc/ad7944.c
index 4602ab5ed2a6..a6ac17c13a29 100644
--- a/drivers/iio/adc/ad7944.c
+++ b/drivers/iio/adc/ad7944.c
@@ -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 *adc
 	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
@@ -209,11 +198,7 @@ static int ad7944_4wire_mode_init_msg(struct device *dev, struct ad7944_adc *adc
 
 	spi_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 *adc
 
 	spi_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);
 }
 
 /**

-- 
2.45.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 1/2] spi: add EXPORT_SYMBOL_GPL(devm_spi_optimize_message)
  2024-06-24 20:10 ` [PATCH v2 1/2] spi: add EXPORT_SYMBOL_GPL(devm_spi_optimize_message) David Lechner
@ 2024-06-24 20:19   ` Mark Brown
  2024-06-25 16:24   ` Mark Brown
  1 sibling, 0 replies; 6+ messages in thread
From: Mark Brown @ 2024-06-24 20:19 UTC (permalink / raw)
  To: David Lechner
  Cc: Jonathan Cameron, Michael Hennerich, Nuno Sá,
	Marcelo Schmitt, Jonathan Corbet, linux-doc, linux-kernel,
	linux-spi, linux-iio

[-- Attachment #1: Type: text/plain, Size: 200 bytes --]

On Mon, Jun 24, 2024 at 03:10:30PM -0500, David Lechner wrote:

> Fixes: 17436001a6bc ("spi: add devm_spi_optimize_message() helper")

That's the merge commit for the branch, not the affected commit.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 1/2] spi: add EXPORT_SYMBOL_GPL(devm_spi_optimize_message)
  2024-06-24 20:10 ` [PATCH v2 1/2] spi: add EXPORT_SYMBOL_GPL(devm_spi_optimize_message) David Lechner
  2024-06-24 20:19   ` Mark Brown
@ 2024-06-25 16:24   ` Mark Brown
  1 sibling, 0 replies; 6+ messages in thread
From: Mark Brown @ 2024-06-25 16:24 UTC (permalink / raw)
  To: David Lechner
  Cc: Jonathan Cameron, Michael Hennerich, Nuno Sá,
	Marcelo Schmitt, Jonathan Corbet, linux-doc, linux-kernel,
	linux-spi, linux-iio

[-- Attachment #1: Type: text/plain, Size: 1480 bytes --]

On Mon, Jun 24, 2024 at 03:10:30PM -0500, David Lechner wrote:
> devm_spi_optimize_message() is a public function and needs
> EXPORT_SYMBOL_GPL.

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 7e74a45c7afdd8a9f82d14fd79ae0383bbaaed1e:

  spi: add EXPORT_SYMBOL_GPL(devm_spi_optimize_message) (2024-06-24 21:25:57 +0100)

----------------------------------------------------------------
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.

----------------------------------------------------------------
David Lechner (3):
      Documentation: devres: add missing SPI helpers
      spi: add devm_spi_optimize_message() helper
      spi: add EXPORT_SYMBOL_GPL(devm_spi_optimize_message)

 Documentation/driver-api/driver-model/devres.rst |  3 +++
 drivers/spi/spi.c                                | 28 ++++++++++++++++++++++++
 include/linux/spi/spi.h                          |  2 ++
 3 files changed, 33 insertions(+)

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: (subset) [PATCH v2 0/2] spi: add devm_spi_optimize_message() helper
  2024-06-24 20:10 [PATCH v2 0/2] spi: add devm_spi_optimize_message() helper David Lechner
  2024-06-24 20:10 ` [PATCH v2 1/2] spi: add EXPORT_SYMBOL_GPL(devm_spi_optimize_message) David Lechner
  2024-06-24 20:10 ` [PATCH v2 2/2] iio: adc: ad7944: use devm_spi_optimize_message() David Lechner
@ 2024-06-25 18:46 ` Mark Brown
  2 siblings, 0 replies; 6+ messages in thread
From: Mark Brown @ 2024-06-25 18:46 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner
  Cc: Michael Hennerich, Nuno Sá, Marcelo Schmitt, Jonathan Corbet,
	linux-doc, linux-kernel, linux-spi, linux-iio

On Mon, 24 Jun 2024 15:10:29 -0500, David Lechner 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 a
> devm_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/2] spi: add EXPORT_SYMBOL_GPL(devm_spi_optimize_message)
      commit: 7e74a45c7afdd8a9f82d14fd79ae0383bbaaed1e

All 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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-06-25 18:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-24 20:10 [PATCH v2 0/2] spi: add devm_spi_optimize_message() helper David Lechner
2024-06-24 20:10 ` [PATCH v2 1/2] spi: add EXPORT_SYMBOL_GPL(devm_spi_optimize_message) David Lechner
2024-06-24 20:19   ` Mark Brown
2024-06-25 16:24   ` Mark Brown
2024-06-24 20:10 ` [PATCH v2 2/2] iio: adc: ad7944: use devm_spi_optimize_message() David Lechner
2024-06-25 18:46 ` (subset) [PATCH v2 0/2] spi: add devm_spi_optimize_message() helper Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).