linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 0/3] spi: gpio: Convert to be used outside of OF
@ 2024-05-17 19:42 Andy Shevchenko
  2024-05-17 19:42 ` [PATCH v1 1/3] spi: gpio: Make use of device properties Andy Shevchenko
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Andy Shevchenko @ 2024-05-17 19:42 UTC (permalink / raw)
  To: Mark Brown, Andy Shevchenko, linux-spi, linux-kernel

Convert the driver to be used outside of OF and a couple of cleanups.

Andy Shevchenko (3):
  spi: gpio: Make use of device properties
  spi: gpio: Use traditional pattern when checking error codes
  spi: gpio: Make num_chipselect 8-bit in the struct
    spi_gpio_platform_data

 drivers/spi/spi-gpio.c       | 66 ++++++++++++++----------------------
 include/linux/spi/spi_gpio.h |  2 +-
 2 files changed, 26 insertions(+), 42 deletions(-)

-- 
2.43.0.rc1.1336.g36b5255a03ac


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

* [PATCH v1 1/3] spi: gpio: Make use of device properties
  2024-05-17 19:42 [PATCH v1 0/3] spi: gpio: Convert to be used outside of OF Andy Shevchenko
@ 2024-05-17 19:42 ` Andy Shevchenko
  2024-05-17 19:42 ` [PATCH v1 2/3] spi: gpio: Use traditional pattern when checking error codes Andy Shevchenko
  2024-05-17 19:42 ` [PATCH v1 3/3] spi: gpio: Make num_chipselect 8-bit in the struct spi_gpio_platform_data Andy Shevchenko
  2 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2024-05-17 19:42 UTC (permalink / raw)
  To: Mark Brown, Andy Shevchenko, linux-spi, linux-kernel

Convert the module to be property provider agnostic and allow
it to be used on non-OF platforms.

Include mod_devicetable.h explicitly to replace the dropped of.h
which included mod_devicetable.h indirectly.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/spi/spi-gpio.c | 51 +++++++++++++++---------------------------
 1 file changed, 18 insertions(+), 33 deletions(-)

diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c
index 909cce109bba..abf426711c22 100644
--- a/drivers/spi/spi-gpio.c
+++ b/drivers/spi/spi-gpio.c
@@ -5,17 +5,17 @@
  * Copyright (C) 2006,2008 David Brownell
  * Copyright (C) 2017 Linus Walleij
  */
+#include <linux/gpio/consumer.h>
 #include <linux/kernel.h>
+#include <linux/mod_devicetable.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
-#include <linux/gpio/consumer.h>
-#include <linux/of.h>
+#include <linux/property.h>
 
 #include <linux/spi/spi.h>
 #include <linux/spi/spi_bitbang.h>
 #include <linux/spi/spi_gpio.h>
 
-
 /*
  * This bitbanging SPI host driver should help make systems usable
  * when a native hardware SPI engine is not available, perhaps because
@@ -326,29 +326,6 @@ static int spi_gpio_request(struct device *dev, struct spi_gpio *spi_gpio)
 	return PTR_ERR_OR_ZERO(spi_gpio->sck);
 }
 
-#ifdef CONFIG_OF
-static const struct of_device_id spi_gpio_dt_ids[] = {
-	{ .compatible = "spi-gpio" },
-	{}
-};
-MODULE_DEVICE_TABLE(of, spi_gpio_dt_ids);
-
-static int spi_gpio_probe_dt(struct platform_device *pdev,
-			     struct spi_controller *host)
-{
-	host->dev.of_node = pdev->dev.of_node;
-	host->use_gpio_descriptors = true;
-
-	return 0;
-}
-#else
-static inline int spi_gpio_probe_dt(struct platform_device *pdev,
-				    struct spi_controller *host)
-{
-	return 0;
-}
-#endif
-
 static int spi_gpio_probe_pdata(struct platform_device *pdev,
 				struct spi_controller *host)
 {
@@ -389,19 +366,21 @@ static int spi_gpio_probe(struct platform_device *pdev)
 	struct spi_controller		*host;
 	struct spi_gpio			*spi_gpio;
 	struct device			*dev = &pdev->dev;
+	struct fwnode_handle		*fwnode = dev_fwnode(dev);
 	struct spi_bitbang		*bb;
 
 	host = devm_spi_alloc_host(dev, sizeof(*spi_gpio));
 	if (!host)
 		return -ENOMEM;
 
-	if (pdev->dev.of_node)
-		status = spi_gpio_probe_dt(pdev, host);
-	else
+	if (fwnode) {
+		device_set_node(&host->dev, fwnode);
+		host->use_gpio_descriptors = true;
+	} else {
 		status = spi_gpio_probe_pdata(pdev, host);
-
-	if (status)
-		return status;
+		if (status)
+			return status;
+	}
 
 	spi_gpio = spi_controller_get_devdata(host);
 
@@ -459,10 +438,16 @@ static int spi_gpio_probe(struct platform_device *pdev)
 
 MODULE_ALIAS("platform:" DRIVER_NAME);
 
+static const struct of_device_id spi_gpio_dt_ids[] = {
+	{ .compatible = "spi-gpio" },
+	{}
+};
+MODULE_DEVICE_TABLE(of, spi_gpio_dt_ids);
+
 static struct platform_driver spi_gpio_driver = {
 	.driver = {
 		.name	= DRIVER_NAME,
-		.of_match_table = of_match_ptr(spi_gpio_dt_ids),
+		.of_match_table = spi_gpio_dt_ids,
 	},
 	.probe		= spi_gpio_probe,
 };
-- 
2.43.0.rc1.1336.g36b5255a03ac


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

* [PATCH v1 2/3] spi: gpio: Use traditional pattern when checking error codes
  2024-05-17 19:42 [PATCH v1 0/3] spi: gpio: Convert to be used outside of OF Andy Shevchenko
  2024-05-17 19:42 ` [PATCH v1 1/3] spi: gpio: Make use of device properties Andy Shevchenko
@ 2024-05-17 19:42 ` Andy Shevchenko
  2024-05-17 19:42 ` [PATCH v1 3/3] spi: gpio: Make num_chipselect 8-bit in the struct spi_gpio_platform_data Andy Shevchenko
  2 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2024-05-17 19:42 UTC (permalink / raw)
  To: Mark Brown, Andy Shevchenko, linux-spi, linux-kernel

Instead of 'if (!ret)' switch to "check for the error first" rule.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/spi/spi-gpio.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c
index abf426711c22..36c587be9e28 100644
--- a/drivers/spi/spi-gpio.c
+++ b/drivers/spi/spi-gpio.c
@@ -239,8 +239,8 @@ static void spi_gpio_chipselect(struct spi_device *spi, int is_active)
 static int spi_gpio_setup(struct spi_device *spi)
 {
 	struct gpio_desc	*cs;
-	int			status = 0;
 	struct spi_gpio		*spi_gpio = spi_to_spi_gpio(spi);
+	int ret;
 
 	/*
 	 * The CS GPIOs have already been
@@ -248,15 +248,14 @@ static int spi_gpio_setup(struct spi_device *spi)
 	 */
 	if (spi_gpio->cs_gpios) {
 		cs = spi_gpio->cs_gpios[spi_get_chipselect(spi, 0)];
-		if (!spi->controller_state && cs)
-			status = gpiod_direction_output(cs,
-						  !(spi->mode & SPI_CS_HIGH));
+		if (!spi->controller_state && cs) {
+			ret = gpiod_direction_output(cs, !(spi->mode & SPI_CS_HIGH));
+			if (ret)
+				return ret;
+		}
 	}
 
-	if (!status)
-		status = spi_bitbang_setup(spi);
-
-	return status;
+	return spi_bitbang_setup(spi);
 }
 
 static int spi_gpio_set_direction(struct spi_device *spi, bool output)
-- 
2.43.0.rc1.1336.g36b5255a03ac


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

* [PATCH v1 3/3] spi: gpio: Make num_chipselect 8-bit in the struct spi_gpio_platform_data
  2024-05-17 19:42 [PATCH v1 0/3] spi: gpio: Convert to be used outside of OF Andy Shevchenko
  2024-05-17 19:42 ` [PATCH v1 1/3] spi: gpio: Make use of device properties Andy Shevchenko
  2024-05-17 19:42 ` [PATCH v1 2/3] spi: gpio: Use traditional pattern when checking error codes Andy Shevchenko
@ 2024-05-17 19:42 ` Andy Shevchenko
  2024-05-17 21:55   ` Mark Brown
  2 siblings, 1 reply; 9+ messages in thread
From: Andy Shevchenko @ 2024-05-17 19:42 UTC (permalink / raw)
  To: Mark Brown, Andy Shevchenko, linux-spi, linux-kernel

There is no use for whole 16-bit for the number of chip select pins.
Drop it to 8 bits.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 include/linux/spi/spi_gpio.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/spi/spi_gpio.h b/include/linux/spi/spi_gpio.h
index 5f0e1407917a..30f29df811a4 100644
--- a/include/linux/spi/spi_gpio.h
+++ b/include/linux/spi/spi_gpio.h
@@ -19,7 +19,7 @@
  * @num_chipselect: how many target devices to allow
  */
 struct spi_gpio_platform_data {
-	u16		num_chipselect;
+	u8	num_chipselect;
 };
 
 #endif /* __LINUX_SPI_GPIO_H */
-- 
2.43.0.rc1.1336.g36b5255a03ac


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

* Re: [PATCH v1 3/3] spi: gpio: Make num_chipselect 8-bit in the struct spi_gpio_platform_data
  2024-05-17 19:42 ` [PATCH v1 3/3] spi: gpio: Make num_chipselect 8-bit in the struct spi_gpio_platform_data Andy Shevchenko
@ 2024-05-17 21:55   ` Mark Brown
  2024-05-20  9:28     ` Andy Shevchenko
  0 siblings, 1 reply; 9+ messages in thread
From: Mark Brown @ 2024-05-17 21:55 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: linux-spi, linux-kernel

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

On Fri, May 17, 2024 at 10:42:03PM +0300, Andy Shevchenko wrote:
> There is no use for whole 16-bit for the number of chip select pins.
> Drop it to 8 bits.

because...?  It's the only field in the struct so it's not like it makes
any meaningful different to struct layout.

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

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

* Re: [PATCH v1 3/3] spi: gpio: Make num_chipselect 8-bit in the struct spi_gpio_platform_data
  2024-05-17 21:55   ` Mark Brown
@ 2024-05-20  9:28     ` Andy Shevchenko
  2024-06-05 21:09       ` Andy Shevchenko
  0 siblings, 1 reply; 9+ messages in thread
From: Andy Shevchenko @ 2024-05-20  9:28 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-spi, linux-kernel

On Fri, May 17, 2024 at 10:55:55PM +0100, Mark Brown wrote:
> On Fri, May 17, 2024 at 10:42:03PM +0300, Andy Shevchenko wrote:
> > There is no use for whole 16-bit for the number of chip select pins.
> > Drop it to 8 bits.
> 
> because...?

To make the type stricter, but since there is no other benefits and
this one likely won't help to catch the (incorrect) use of big numbers
I think we don't need it.

> It's the only field in the struct so it's not like it makes
> any meaningful different to struct layout.

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v1 3/3] spi: gpio: Make num_chipselect 8-bit in the struct spi_gpio_platform_data
  2024-05-20  9:28     ` Andy Shevchenko
@ 2024-06-05 21:09       ` Andy Shevchenko
  2024-06-05 21:22         ` Mark Brown
  0 siblings, 1 reply; 9+ messages in thread
From: Andy Shevchenko @ 2024-06-05 21:09 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-spi, linux-kernel

On Mon, May 20, 2024 at 12:28:12PM +0300, Andy Shevchenko wrote:
> On Fri, May 17, 2024 at 10:55:55PM +0100, Mark Brown wrote:
> > On Fri, May 17, 2024 at 10:42:03PM +0300, Andy Shevchenko wrote:
> > > There is no use for whole 16-bit for the number of chip select pins.
> > > Drop it to 8 bits.
> > 
> > because...?
> 
> To make the type stricter, but since there is no other benefits and
> this one likely won't help to catch the (incorrect) use of big numbers
> I think we don't need it.
> 
> > It's the only field in the struct so it's not like it makes
> > any meaningful different to struct layout.

Should I do something about the first two patches or is it fine to get them in?

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v1 3/3] spi: gpio: Make num_chipselect 8-bit in the struct spi_gpio_platform_data
  2024-06-05 21:09       ` Andy Shevchenko
@ 2024-06-05 21:22         ` Mark Brown
  2024-06-06 10:48           ` Andy Shevchenko
  0 siblings, 1 reply; 9+ messages in thread
From: Mark Brown @ 2024-06-05 21:22 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: linux-spi, linux-kernel

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

On Thu, Jun 06, 2024 at 12:09:24AM +0300, Andy Shevchenko wrote:

> Should I do something about the first two patches or is it fine to get them in?

Please don't send content free pings and please allow a reasonable time
for review.  People get busy, go on holiday, attend conferences and so 
on so unless there is some reason for urgency (like critical bug fixes)
please allow at least a couple of weeks for review.  If there have been
review comments then people may be waiting for those to be addressed.

Sending content free pings adds to the mail volume (if they are seen at
all) which is often the problem and since they can't be reviewed
directly if something has gone wrong you'll have to resend the patches
anyway, so sending again is generally a better approach though there are
some other maintainers who like them - if in doubt look at how patches
for the subsystem are normally handled.

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

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

* Re: [PATCH v1 3/3] spi: gpio: Make num_chipselect 8-bit in the struct spi_gpio_platform_data
  2024-06-05 21:22         ` Mark Brown
@ 2024-06-06 10:48           ` Andy Shevchenko
  0 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2024-06-06 10:48 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-spi, linux-kernel

On Wed, Jun 05, 2024 at 10:22:44PM +0100, Mark Brown wrote:
> On Thu, Jun 06, 2024 at 12:09:24AM +0300, Andy Shevchenko wrote:
> 
> > Should I do something about the first two patches or is it fine to get them in?

Found them, it's just an announce is missing.
Thanks!

-- 
With Best Regards,
Andy Shevchenko



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

end of thread, other threads:[~2024-06-06 10:48 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-17 19:42 [PATCH v1 0/3] spi: gpio: Convert to be used outside of OF Andy Shevchenko
2024-05-17 19:42 ` [PATCH v1 1/3] spi: gpio: Make use of device properties Andy Shevchenko
2024-05-17 19:42 ` [PATCH v1 2/3] spi: gpio: Use traditional pattern when checking error codes Andy Shevchenko
2024-05-17 19:42 ` [PATCH v1 3/3] spi: gpio: Make num_chipselect 8-bit in the struct spi_gpio_platform_data Andy Shevchenko
2024-05-17 21:55   ` Mark Brown
2024-05-20  9:28     ` Andy Shevchenko
2024-06-05 21:09       ` Andy Shevchenko
2024-06-05 21:22         ` Mark Brown
2024-06-06 10:48           ` Andy Shevchenko

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