linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 0/5] spi: moving to struct gpio_desc
@ 2017-05-25  4:30 Chris Packham
  2017-05-25  4:30 ` [RFC PATCH 1/5] spi: use gpio_desc instead of numeric gpio Chris Packham
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Chris Packham @ 2017-05-25  4:30 UTC (permalink / raw)
  To: broonie, andy.shevchenko, linux-spi, linux-kernel, rmallon, shawnguo
  Cc: linux, Chris Packham

This is my attempt to move spi over to using struct gpio_desc. I've
stopped at converting struct spi_master to gather some feedback.

ep93xx wasn't as hard as I'd expected so I'm pretty happy with those
changes. imx on the other hand has an annoying habit of conflating the GPIO
and native chip-select so I'm pretty sure that's broken.

I've compile tested ep93xx_defconfig and multi_v5_defconfig.

Looking ahead to converting struct spi_device there are a number of drivers
that re-use cs_gpio to reference the native chip-select so that still poses
issues I don't have a plan to solve. Happily most of the changes are deleting
code that requests the GPIO since that's now taken care of in core.

Chris Packham (5):
  spi: use gpio_desc instead of numeric gpio
  ARM: ep93xx: add gpiod_lookup_table for spi chip-selects
  ARM: imx: add gpiod_lookup_table for spi chip-selects
  spi: core: convert spi_master to use gpio_desc
  ARM: ep93xx: remove chipselect from ep93xx_spi_info

 arch/arm/mach-ep93xx/edb93xx.c           | 15 +++++++++++----
 arch/arm/mach-ep93xx/simone.c            | 14 ++++++++++----
 arch/arm/mach-ep93xx/vision_ep9307.c     | 20 ++++++++++++++------
 arch/arm/mach-imx/mach-mx27_3ds.c        | 21 +++++++++++++++++++++
 arch/arm/mach-imx/mach-pca100.c          | 13 +++++++++++++
 drivers/spi/spi-ep93xx.c                 | 18 ++++++++----------
 drivers/spi/spi-imx.c                    | 25 +++++++++----------------
 drivers/spi/spi-mt65xx.c                 | 13 -------------
 drivers/spi/spi.c                        | 29 +++++++++++++++++++++--------
 include/linux/platform_data/spi-ep93xx.h |  4 +---
 include/linux/spi/spi.h                  |  2 +-
 11 files changed, 109 insertions(+), 65 deletions(-)

-- 
2.13.0

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

* [RFC PATCH 1/5] spi: use gpio_desc instead of numeric gpio
  2017-05-25  4:30 [RFC PATCH 0/5] spi: moving to struct gpio_desc Chris Packham
@ 2017-05-25  4:30 ` Chris Packham
  2017-05-25  4:30 ` [RFC PATCH 2/5] ARM: ep93xx: add gpiod_lookup_table for spi chip-selects Chris Packham
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Chris Packham @ 2017-05-25  4:30 UTC (permalink / raw)
  To: broonie, andy.shevchenko, linux-spi, linux-kernel, rmallon, shawnguo
  Cc: linux, Chris Packham

By using a gpio_desc and gpiod_set_value() instead of a numeric gpio and
gpio_set_value() the gpio flags are taken into account. This is useful
when using a gpio chip-select to supplement a controllers native
chip-select.

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
(I've included this in this series for context, ultimately it should not be
needed once everything is using gpio_desc)

My specific use-case is I have a board that uses the spi-orion driver but
only has one CS pin available. In order to access two spi slave devices the
board has a 1-of-2 decoder/demultiplexer which is driven via a gpio.

The problem is that for one of the 2 slave devices the gpio level required
is opposite to the chip-select so I can't simply specify "spi-cs-high".
With this change I can flag the gpio as active low and the gpio subsystem
takes care of the additional inversion required.

 drivers/spi/spi.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 6f87fec409b5..b39c0f9956dd 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -725,7 +725,10 @@ static void spi_set_cs(struct spi_device *spi, bool enable)
 		enable = !enable;
 
 	if (gpio_is_valid(spi->cs_gpio)) {
-		gpio_set_value(spi->cs_gpio, !enable);
+		struct gpio_desc *gpio = gpio_to_desc(spi->cs_gpio);
+
+		if (gpio)
+			gpiod_set_value(gpio, !enable);
 		/* Some SPI masters need both GPIO CS & slave_select */
 		if ((spi->master->flags & SPI_MASTER_GPIO_SS) &&
 		    spi->master->set_cs)
-- 
2.13.0

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

* [RFC PATCH 2/5] ARM: ep93xx: add gpiod_lookup_table for spi chip-selects
  2017-05-25  4:30 [RFC PATCH 0/5] spi: moving to struct gpio_desc Chris Packham
  2017-05-25  4:30 ` [RFC PATCH 1/5] spi: use gpio_desc instead of numeric gpio Chris Packham
@ 2017-05-25  4:30 ` Chris Packham
  2017-05-25  4:30 ` [RFC PATCH 3/5] ARM: imx: " Chris Packham
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Chris Packham @ 2017-05-25  4:30 UTC (permalink / raw)
  To: broonie, andy.shevchenko, linux-spi, linux-kernel, rmallon, shawnguo
  Cc: linux, Chris Packham, Hartley Sweeten, linux-arm-kernel

This is a preparatory step which will allow the conversion of
spi-ep93xx.c to gpiod.

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
 arch/arm/mach-ep93xx/edb93xx.c       | 12 ++++++++++++
 arch/arm/mach-ep93xx/simone.c        | 11 +++++++++++
 arch/arm/mach-ep93xx/vision_ep9307.c | 15 +++++++++++++++
 3 files changed, 38 insertions(+)

diff --git a/arch/arm/mach-ep93xx/edb93xx.c b/arch/arm/mach-ep93xx/edb93xx.c
index 0ac176386789..9042adfe03de 100644
--- a/arch/arm/mach-ep93xx/edb93xx.c
+++ b/arch/arm/mach-ep93xx/edb93xx.c
@@ -27,6 +27,8 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/platform_device.h>
+#include <linux/gpio.h>
+#include <linux/gpio/machine.h>
 #include <linux/i2c.h>
 #include <linux/i2c-gpio.h>
 #include <linux/spi/spi.h>
@@ -116,6 +118,15 @@ static struct spi_board_info edb93xx_spi_board_info[] __initdata = {
 	},
 };
 
+static struct gpiod_lookup_table edb93xx_gpios_table = {
+	.dev_id = "spi.0",
+	.table = {
+		GPIO_LOOKUP("gpio-ep93xx", EP93XX_GPIO_LINE_EGPIO6,
+			    "spi-cs", GPIO_ACTIVE_HIGH),
+		{},
+	},
+};
+
 static int edb93xx_spi_chipselects[] __initdata = {
 	EP93XX_GPIO_LINE_EGPIO6,
 };
@@ -134,6 +145,7 @@ static void __init edb93xx_register_spi(void)
 	else if (machine_is_edb9315a())
 		edb93xx_cs4271_data.gpio_nreset = EP93XX_GPIO_LINE_EGPIO14;
 
+	gpiod_add_lookup_table(&edb93xx_gpios_table);
 	ep93xx_register_spi(&edb93xx_spi_info, edb93xx_spi_board_info,
 			    ARRAY_SIZE(edb93xx_spi_board_info));
 }
diff --git a/arch/arm/mach-ep93xx/simone.c b/arch/arm/mach-ep93xx/simone.c
index c7a40f245892..f297a7a89ed9 100644
--- a/arch/arm/mach-ep93xx/simone.c
+++ b/arch/arm/mach-ep93xx/simone.c
@@ -26,6 +26,7 @@
 #include <linux/platform_data/video-ep93xx.h>
 #include <linux/platform_data/spi-ep93xx.h>
 #include <linux/gpio.h>
+#include <linux/gpio/machine.h>
 
 #include <mach/hardware.h>
 #include <mach/gpio-ep93xx.h>
@@ -119,6 +120,15 @@ static struct spi_board_info simone_spi_devices[] __initdata = {
  * low between multi-message command blocks. From v1.4, it uses a GPIO instead.
  * v1.3 parts will still work, since the signal on SFRMOUT is automatic.
  */
+static struct gpiod_lookup_table simone_gpios_table = {
+	.dev_id = "spi.0",
+	.table = {
+		GPIO_LOOKUP("gpio-ep93xx", EP93XX_GPIO_LINE_EGPIO1,
+			    "spi-cs", GPIO_ACTIVE_HIGH),
+		{},
+	},
+};
+
 static int simone_spi_chipselects[] __initdata = {
 	EP93XX_GPIO_LINE_EGPIO1,
 };
@@ -163,6 +173,7 @@ static void __init simone_init_machine(void)
 	ep93xx_register_fb(&simone_fb_info);
 	ep93xx_register_i2c(&simone_i2c_gpio_data, simone_i2c_board_info,
 			    ARRAY_SIZE(simone_i2c_board_info));
+	gpiod_add_lookup_table(&simone_gpios_table);
 	ep93xx_register_spi(&simone_spi_info, simone_spi_devices,
 			    ARRAY_SIZE(simone_spi_devices));
 	simone_register_audio();
diff --git a/arch/arm/mach-ep93xx/vision_ep9307.c b/arch/arm/mach-ep93xx/vision_ep9307.c
index 1daf9441058c..3d9c66bbf2af 100644
--- a/arch/arm/mach-ep93xx/vision_ep9307.c
+++ b/arch/arm/mach-ep93xx/vision_ep9307.c
@@ -18,6 +18,7 @@
 #include <linux/platform_device.h>
 #include <linux/irq.h>
 #include <linux/gpio.h>
+#include <linux/gpio/machine.h>
 #include <linux/fb.h>
 #include <linux/io.h>
 #include <linux/mtd/partitions.h>
@@ -242,6 +243,19 @@ static struct spi_board_info vision_spi_board_info[] __initdata = {
 	},
 };
 
+static struct gpiod_lookup_table vision_gpios_table = {
+	.dev_id = "spi.0",
+	.table = {
+		GPIO_LOOKUP_IDX("gpio-ep93xx", EP93XX_GPIO_LINE_EGPIO6,
+				"spi-cs", 0, GPIO_ACTIVE_HIGH),
+		GPIO_LOOKUP_IDX("gpio-ep93xx", EP93XX_GPIO_LINE_EGPIO7,
+				"spi-cs", 1, GPIO_ACTIVE_HIGH),
+		GPIO_LOOKUP_IDX("gpio-ep93xx", EP93XX_GPIO_LINE_G(2),
+				"spi-cs", 2, GPIO_ACTIVE_HIGH),
+		{},
+	},
+};
+
 static int vision_spi_chipselects[] __initdata = {
 	EP93XX_GPIO_LINE_EGPIO6,
 	EP93XX_GPIO_LINE_EGPIO7,
@@ -291,6 +305,7 @@ static void __init vision_init_machine(void)
 
 	ep93xx_register_i2c(&vision_i2c_gpio_data, vision_i2c_info,
 				ARRAY_SIZE(vision_i2c_info));
+	gpiod_add_lookup_table(&vision_gpios_table);
 	ep93xx_register_spi(&vision_spi_master, vision_spi_board_info,
 				ARRAY_SIZE(vision_spi_board_info));
 	vision_register_i2s();
-- 
2.13.0

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

* [RFC PATCH 3/5] ARM: imx: add gpiod_lookup_table for spi chip-selects
  2017-05-25  4:30 [RFC PATCH 0/5] spi: moving to struct gpio_desc Chris Packham
  2017-05-25  4:30 ` [RFC PATCH 1/5] spi: use gpio_desc instead of numeric gpio Chris Packham
  2017-05-25  4:30 ` [RFC PATCH 2/5] ARM: ep93xx: add gpiod_lookup_table for spi chip-selects Chris Packham
@ 2017-05-25  4:30 ` Chris Packham
  2017-05-25  4:30 ` [RFC PATCH 4/5] spi: core: convert spi_master to use gpio_desc Chris Packham
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Chris Packham @ 2017-05-25  4:30 UTC (permalink / raw)
  To: broonie, andy.shevchenko, linux-spi, linux-kernel, rmallon, shawnguo
  Cc: linux, Chris Packham, Sascha Hauer, Fabio Estevam, linux-arm-kernel

This is a preparatory step which will allow the conversion of
spi-imx.c to gpiod.

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
 arch/arm/mach-imx/mach-mx27_3ds.c | 21 +++++++++++++++++++++
 arch/arm/mach-imx/mach-pca100.c   | 13 +++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/arch/arm/mach-imx/mach-mx27_3ds.c b/arch/arm/mach-imx/mach-mx27_3ds.c
index 45e16bd7e2f2..46d67be124f0 100644
--- a/arch/arm/mach-imx/mach-mx27_3ds.c
+++ b/arch/arm/mach-imx/mach-mx27_3ds.c
@@ -22,6 +22,7 @@
 
 #include <linux/platform_device.h>
 #include <linux/gpio.h>
+#include <linux/gpio/machine.h>
 #include <linux/irq.h>
 #include <linux/usb/otg.h>
 #include <linux/usb/ulpi.h>
@@ -313,6 +314,15 @@ static struct imx_ssi_platform_data mx27_3ds_ssi_pdata = {
 };
 
 /* SPI */
+static struct gpiod_lookup_table spi1_cs_gpio_table = {
+	.dev_id = "spi.0",
+	.table = {
+		GPIO_LOOKUP("gpio-mxc", SPI1_SS0,
+			    "spi-cs", GPIO_ACTIVE_HIGH),
+		{ },
+	},
+};
+
 static int spi1_chipselect[] = {SPI1_SS0};
 
 static const struct spi_imx_master spi1_pdata __initconst = {
@@ -320,6 +330,15 @@ static const struct spi_imx_master spi1_pdata __initconst = {
 	.num_chipselect	= ARRAY_SIZE(spi1_chipselect),
 };
 
+static struct gpiod_lookup_table spi2_cs_gpio_table = {
+	.dev_id = "spi.1",
+	.table = {
+		GPIO_LOOKUP("gpio-mxc", SPI2_SS0,
+			    "spi-cs", GPIO_ACTIVE_HIGH),
+		{ },
+	},
+};
+
 static int spi2_chipselect[] = {SPI2_SS0};
 
 static const struct spi_imx_master spi2_pdata __initconst = {
@@ -398,7 +417,9 @@ static void __init mx27pdk_init(void)
 	imx27_add_imx_keypad(&mx27_3ds_keymap_data);
 	imx27_add_imx2_wdt();
 
+	gpiod_add_lookup_table(&spi2_cs_gpio_table);
 	imx27_add_spi_imx1(&spi2_pdata);
+	gpiod_add_lookup_table(&spi1_cs_gpio_table);
 	imx27_add_spi_imx0(&spi1_pdata);
 
 	imx27_add_imx_i2c(0, &mx27_3ds_i2c0_data);
diff --git a/arch/arm/mach-imx/mach-pca100.c b/arch/arm/mach-imx/mach-pca100.c
index ed675863655b..8a2b5860f327 100644
--- a/arch/arm/mach-imx/mach-pca100.c
+++ b/arch/arm/mach-imx/mach-pca100.c
@@ -27,6 +27,7 @@
 #include <linux/irq.h>
 #include <linux/delay.h>
 #include <linux/gpio.h>
+#include <linux/gpio/machine.h>
 #include <linux/usb/otg.h>
 #include <linux/usb/ulpi.h>
 
@@ -202,6 +203,17 @@ static struct spi_board_info pca100_spi_board_info[] __initdata = {
 	},
 };
 
+static struct gpiod_lookup_table pca100_spi_cs_gpio_table = {
+	.dev_id = "spi.0",
+	.table = {
+		GPIO_LOOKUP_IDX("gpio-mxc", SPI1_SS0,
+				"spi-cs", 0, GPIO_ACTIVE_HIGH),
+		GPIO_LOOKUP_IDX("gpio-mxc", SPI1_SS1,
+				"spi-cs", 1, GPIO_ACTIVE_HIGH),
+		{ },
+	},
+};
+
 static int pca100_spi_cs[] = {SPI1_SS0, SPI1_SS1};
 
 static const struct spi_imx_master pca100_spi0_data __initconst = {
@@ -376,6 +388,7 @@ static void __init pca100_init(void)
 	mxc_gpio_mode(GPIO_PORTD | 27 | GPIO_GPIO | GPIO_IN);
 	spi_register_board_info(pca100_spi_board_info,
 				ARRAY_SIZE(pca100_spi_board_info));
+	gpiod_add_lookup_table(&pca100_spi_cs_gpio_table);
 	imx27_add_spi_imx0(&pca100_spi0_data);
 
 	imx27_add_imx_fb(&pca100_fb_data);
-- 
2.13.0

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

* [RFC PATCH 4/5] spi: core: convert spi_master to use gpio_desc
  2017-05-25  4:30 [RFC PATCH 0/5] spi: moving to struct gpio_desc Chris Packham
                   ` (2 preceding siblings ...)
  2017-05-25  4:30 ` [RFC PATCH 3/5] ARM: imx: " Chris Packham
@ 2017-05-25  4:30 ` Chris Packham
  2017-05-25  4:30 ` [RFC PATCH 5/5] ARM: ep93xx: remove chipselect from ep93xx_spi_info Chris Packham
  2017-05-29 13:36 ` [RFC PATCH 0/5] spi: moving to struct gpio_desc Mark Brown
  5 siblings, 0 replies; 7+ messages in thread
From: Chris Packham @ 2017-05-25  4:30 UTC (permalink / raw)
  To: broonie, andy.shevchenko, linux-spi, linux-kernel, rmallon, shawnguo
  Cc: linux, Chris Packham

Instead of numeric gpios make struct spi_master hold an array of struct
gpio_desc. For now struct spi_device still maintains a numeric gpio
which will be updated in a subsequent change.

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
 drivers/spi/spi-ep93xx.c | 18 ++++++++----------
 drivers/spi/spi-imx.c    | 25 +++++++++----------------
 drivers/spi/spi-mt65xx.c | 13 -------------
 drivers/spi/spi.c        | 24 +++++++++++++++++-------
 include/linux/spi/spi.h  |  2 +-
 5 files changed, 35 insertions(+), 47 deletions(-)

diff --git a/drivers/spi/spi-ep93xx.c b/drivers/spi/spi-ep93xx.c
index b5d766064b7b..8ff795e65b38 100644
--- a/drivers/spi/spi-ep93xx.c
+++ b/drivers/spi/spi-ep93xx.c
@@ -816,7 +816,7 @@ static int ep93xx_spi_probe(struct platform_device *pdev)
 
 	master->num_chipselect = info->num_chipselect;
 	master->cs_gpios = devm_kzalloc(&master->dev,
-					sizeof(int) * master->num_chipselect,
+					sizeof(*master->cs_gpios) * master->num_chipselect,
 					GFP_KERNEL);
 	if (!master->cs_gpios) {
 		error = -ENOMEM;
@@ -824,19 +824,17 @@ static int ep93xx_spi_probe(struct platform_device *pdev)
 	}
 
 	for (i = 0; i < master->num_chipselect; i++) {
-		master->cs_gpios[i] = info->chipselect[i];
+		struct gpio_desc *cs;
 
-		if (!gpio_is_valid(master->cs_gpios[i]))
-			continue;
-
-		error = devm_gpio_request_one(&pdev->dev, master->cs_gpios[i],
-					      GPIOF_OUT_INIT_HIGH,
-					      "ep93xx-spi");
-		if (error) {
+		cs = devm_gpiod_get_index(&pdev->dev, "spi-cs", i,
+					  GPIOD_OUT_HIGH);
+		if (IS_ERR(cs)) {
 			dev_err(&pdev->dev, "could not request cs gpio %d\n",
-				master->cs_gpios[i]);
+				i);
+			error = PTR_ERR(cs);
 			goto fail_release_master;
 		}
+		master->cs_gpios[i] = cs;
 	}
 
 	platform_set_drvdata(pdev, master);
diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index 19b30cf7d2b7..efbf03ac7cf1 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -1360,12 +1360,18 @@ static int spi_imx_probe(struct platform_device *pdev)
 	if (mxc_platform_info) {
 		master->num_chipselect = mxc_platform_info->num_chipselect;
 		master->cs_gpios = devm_kzalloc(&master->dev,
-			sizeof(int) * master->num_chipselect, GFP_KERNEL);
+			sizeof(*master->cs_gpios) * master->num_chipselect, GFP_KERNEL);
 		if (!master->cs_gpios)
 			return -ENOMEM;
 
-		for (i = 0; i < master->num_chipselect; i++)
-			master->cs_gpios[i] = mxc_platform_info->chipselect[i];
+		for (i = 0; i < master->num_chipselect; i++) {
+			struct gpio_desc *cs;
+
+			cs = devm_gpiod_get_index(&pdev->dev, "spi-cs", i,
+						  GPIOD_OUT_HIGH);
+			if (!IS_ERR(cs))
+				master->cs_gpios[i] = cs;
+		}
  	}
 
 	spi_imx->bitbang.chipselect = spi_imx_chipselect;
@@ -1456,19 +1462,6 @@ static int spi_imx_probe(struct platform_device *pdev)
 		goto out_clk_put;
 	}
 
-	for (i = 0; i < master->num_chipselect; i++) {
-		if (!gpio_is_valid(master->cs_gpios[i]))
-			continue;
-
-		ret = devm_gpio_request(&pdev->dev, master->cs_gpios[i],
-					DRIVER_NAME);
-		if (ret) {
-			dev_err(&pdev->dev, "Can't get CS GPIO %i\n",
-				master->cs_gpios[i]);
-			goto out_clk_put;
-		}
-	}
-
 	dev_info(&pdev->dev, "probed\n");
 
 	clk_disable(spi_imx->clk_ipg);
diff --git a/drivers/spi/spi-mt65xx.c b/drivers/spi/spi-mt65xx.c
index 278867a31950..36e0d865fd02 100644
--- a/drivers/spi/spi-mt65xx.c
+++ b/drivers/spi/spi-mt65xx.c
@@ -681,19 +681,6 @@ static int mtk_spi_probe(struct platform_device *pdev)
 			ret = -EINVAL;
 			goto err_disable_runtime_pm;
 		}
-
-		if (master->cs_gpios) {
-			for (i = 0; i < master->num_chipselect; i++) {
-				ret = devm_gpio_request(&pdev->dev,
-							master->cs_gpios[i],
-							dev_name(&pdev->dev));
-				if (ret) {
-					dev_err(&pdev->dev,
-						"can't get CS GPIO %i\n", i);
-					goto err_disable_runtime_pm;
-				}
-			}
-		}
 	}
 
 	return 0;
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index b39c0f9956dd..8be01520b02e 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -40,6 +40,7 @@
 #include <linux/ioport.h>
 #include <linux/acpi.h>
 #include <linux/highmem.h>
+#include <linux/gpio/consumer.h>
 
 #define CREATE_TRACE_POINTS
 #include <trace/events/spi.h>
@@ -531,8 +532,10 @@ int spi_add_device(struct spi_device *spi)
 		goto done;
 	}
 
-	if (master->cs_gpios)
-		spi->cs_gpio = master->cs_gpios[spi->chip_select];
+	if (master->cs_gpios[spi->chip_select])
+		spi->cs_gpio = desc_to_gpio(master->cs_gpios[spi->chip_select]);
+	else
+		spi->cs_gpio = -ENOENT;
 
 	/* Drivers may modify this initial i/o setup, but will
 	 * normally rely on the device being setup.  Devices
@@ -1878,7 +1881,8 @@ EXPORT_SYMBOL_GPL(spi_alloc_master);
 #ifdef CONFIG_OF
 static int of_spi_register_master(struct spi_master *master)
 {
-	int nb, i, *cs;
+	int nb, i;
+	struct gpio_desc **cs;
 	struct device_node *np = master->dev.of_node;
 
 	if (!np)
@@ -1894,7 +1898,7 @@ static int of_spi_register_master(struct spi_master *master)
 		return nb;
 
 	cs = devm_kzalloc(&master->dev,
-			  sizeof(int) * master->num_chipselect,
+			  sizeof(*master->cs_gpios) * master->num_chipselect,
 			  GFP_KERNEL);
 	master->cs_gpios = cs;
 
@@ -1902,10 +1906,16 @@ static int of_spi_register_master(struct spi_master *master)
 		return -ENOMEM;
 
 	for (i = 0; i < master->num_chipselect; i++)
-		cs[i] = -ENOENT;
+		cs[i] = NULL;
+
+	for (i = 0; i < nb; i++) {
+		struct gpio_desc *gpio;
 
-	for (i = 0; i < nb; i++)
-		cs[i] = of_get_named_gpio(np, "cs-gpios", i);
+		gpio = devm_gpiod_get_index(&master->dev, "cs", i,
+					    GPIOD_OUT_HIGH);
+		if (!IS_ERR(gpio))
+			cs[i] = gpio;
+	}
 
 	return 0;
 }
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 935bd2854ff1..46960ca62d5b 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -556,7 +556,7 @@ struct spi_master {
 			   struct spi_message *message);
 
 	/* gpio chip select */
-	int			*cs_gpios;
+	struct gpio_desc	**cs_gpios;
 
 	/* statistics */
 	struct spi_statistics	statistics;
-- 
2.13.0

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

* [RFC PATCH 5/5] ARM: ep93xx: remove chipselect from ep93xx_spi_info
  2017-05-25  4:30 [RFC PATCH 0/5] spi: moving to struct gpio_desc Chris Packham
                   ` (3 preceding siblings ...)
  2017-05-25  4:30 ` [RFC PATCH 4/5] spi: core: convert spi_master to use gpio_desc Chris Packham
@ 2017-05-25  4:30 ` Chris Packham
  2017-05-29 13:36 ` [RFC PATCH 0/5] spi: moving to struct gpio_desc Mark Brown
  5 siblings, 0 replies; 7+ messages in thread
From: Chris Packham @ 2017-05-25  4:30 UTC (permalink / raw)
  To: broonie, andy.shevchenko, linux-spi, linux-kernel, rmallon, shawnguo
  Cc: linux, Chris Packham, Hartley Sweeten, linux-arm-kernel

Now that the driver has been updated to use gpiod there is no need to
have platform data to define the SPI chipselects. We still need to
define the number of chipselects used.

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
 arch/arm/mach-ep93xx/edb93xx.c           | 7 +------
 arch/arm/mach-ep93xx/simone.c            | 7 +------
 arch/arm/mach-ep93xx/vision_ep9307.c     | 9 +--------
 include/linux/platform_data/spi-ep93xx.h | 4 +---
 4 files changed, 4 insertions(+), 23 deletions(-)

diff --git a/arch/arm/mach-ep93xx/edb93xx.c b/arch/arm/mach-ep93xx/edb93xx.c
index 9042adfe03de..b8d354fc27f5 100644
--- a/arch/arm/mach-ep93xx/edb93xx.c
+++ b/arch/arm/mach-ep93xx/edb93xx.c
@@ -127,13 +127,8 @@ static struct gpiod_lookup_table edb93xx_gpios_table = {
 	},
 };
 
-static int edb93xx_spi_chipselects[] __initdata = {
-	EP93XX_GPIO_LINE_EGPIO6,
-};
-
 static struct ep93xx_spi_info edb93xx_spi_info __initdata = {
-	.chipselect	= edb93xx_spi_chipselects,
-	.num_chipselect	= ARRAY_SIZE(edb93xx_spi_chipselects),
+	.num_chipselect	= 1,
 };
 
 static void __init edb93xx_register_spi(void)
diff --git a/arch/arm/mach-ep93xx/simone.c b/arch/arm/mach-ep93xx/simone.c
index f297a7a89ed9..cb6bc2e1670a 100644
--- a/arch/arm/mach-ep93xx/simone.c
+++ b/arch/arm/mach-ep93xx/simone.c
@@ -129,13 +129,8 @@ static struct gpiod_lookup_table simone_gpios_table = {
 	},
 };
 
-static int simone_spi_chipselects[] __initdata = {
-	EP93XX_GPIO_LINE_EGPIO1,
-};
-
 static struct ep93xx_spi_info simone_spi_info __initdata = {
-	.chipselect	= simone_spi_chipselects,
-	.num_chipselect	= ARRAY_SIZE(simone_spi_chipselects),
+	.num_chipselect	= 1,
 	.use_dma = 1,
 };
 
diff --git a/arch/arm/mach-ep93xx/vision_ep9307.c b/arch/arm/mach-ep93xx/vision_ep9307.c
index 3d9c66bbf2af..494c55080472 100644
--- a/arch/arm/mach-ep93xx/vision_ep9307.c
+++ b/arch/arm/mach-ep93xx/vision_ep9307.c
@@ -256,15 +256,8 @@ static struct gpiod_lookup_table vision_gpios_table = {
 	},
 };
 
-static int vision_spi_chipselects[] __initdata = {
-	EP93XX_GPIO_LINE_EGPIO6,
-	EP93XX_GPIO_LINE_EGPIO7,
-	EP93XX_GPIO_LINE_G(2),
-};
-
 static struct ep93xx_spi_info vision_spi_master __initdata = {
-	.chipselect	= vision_spi_chipselects,
-	.num_chipselect	= ARRAY_SIZE(vision_spi_chipselects),
+	.num_chipselect	= 3,
 	.use_dma	= 1,
 };
 
diff --git a/include/linux/platform_data/spi-ep93xx.h b/include/linux/platform_data/spi-ep93xx.h
index 171a271c2cbd..efcf33eff851 100644
--- a/include/linux/platform_data/spi-ep93xx.h
+++ b/include/linux/platform_data/spi-ep93xx.h
@@ -5,12 +5,10 @@ struct spi_device;
 
 /**
  * struct ep93xx_spi_info - EP93xx specific SPI descriptor
- * @chipselect: array of gpio numbers to use as chip selects
- * @num_chipselect: ARRAY_SIZE(chipselect)
+ * @num_chipselect: number chip selects supported
  * @use_dma: use DMA for the transfers
  */
 struct ep93xx_spi_info {
-	int	*chipselect;
 	int	num_chipselect;
 	bool	use_dma;
 };
-- 
2.13.0

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

* Re: [RFC PATCH 0/5] spi: moving to struct gpio_desc
  2017-05-25  4:30 [RFC PATCH 0/5] spi: moving to struct gpio_desc Chris Packham
                   ` (4 preceding siblings ...)
  2017-05-25  4:30 ` [RFC PATCH 5/5] ARM: ep93xx: remove chipselect from ep93xx_spi_info Chris Packham
@ 2017-05-29 13:36 ` Mark Brown
  5 siblings, 0 replies; 7+ messages in thread
From: Mark Brown @ 2017-05-29 13:36 UTC (permalink / raw)
  To: Chris Packham
  Cc: andy.shevchenko, linux-spi, linux-kernel, rmallon, shawnguo, linux

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

On Thu, May 25, 2017 at 04:30:38PM +1200, Chris Packham wrote:

> ep93xx wasn't as hard as I'd expected so I'm pretty happy with those
> changes. imx on the other hand has an annoying habit of conflating the GPIO
> and native chip-select so I'm pretty sure that's broken.

So, I was just looking at the list archives and I found that there's a
series that Hartley posted back in February modernizing the ep93xx
driver which didn't get copied to me so it's not being reviewed.  Can
you take a look and see if that helps with your updates to the driver?
The subject for the cover letter is "spi: spi-ep93xx: cleanup and update
driver to modern API".

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

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

end of thread, other threads:[~2017-05-29 13:37 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-25  4:30 [RFC PATCH 0/5] spi: moving to struct gpio_desc Chris Packham
2017-05-25  4:30 ` [RFC PATCH 1/5] spi: use gpio_desc instead of numeric gpio Chris Packham
2017-05-25  4:30 ` [RFC PATCH 2/5] ARM: ep93xx: add gpiod_lookup_table for spi chip-selects Chris Packham
2017-05-25  4:30 ` [RFC PATCH 3/5] ARM: imx: " Chris Packham
2017-05-25  4:30 ` [RFC PATCH 4/5] spi: core: convert spi_master to use gpio_desc Chris Packham
2017-05-25  4:30 ` [RFC PATCH 5/5] ARM: ep93xx: remove chipselect from ep93xx_spi_info Chris Packham
2017-05-29 13:36 ` [RFC PATCH 0/5] spi: moving to struct gpio_desc 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).