Skip to contentSkip to conversation

spi: s3c64xx: fix broken "cs_gpios" usage in the driver

PATCH Superseded Naveen Krishna Chatradhi 6 participants 15 messages Jun 13, 2014 – Jul 11, 2014

Subsystems (4)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/3 spi: s3c64xx: fix broken "cs_gpios" usage in the driver

Since, (3146bee spi: s3c64xx: Added provision for dedicated cs pin)

spi-s3c64xx.c driver expects
1. chip select gpios from "cs-gpio"(singular) under the "controller-data" node of the client/slave device of the SPI.

2. "cs-gpio"(singular) entry to be present in the SPI device node.

Eg of current broken usage:

&spi_1 {
	cs-gpio <>;	/* this entry is checked during probe */
	...
	slave_node {
		controller-data {
			cs-gpio <&gpioa2 5 0>;
			/* This field is parsed during .setup() */
		}
	};
};

The following dts files which were using this driver. But, din't have the "cs-gpio" entry under SPI node.
-- arch/arm/boot/dts/exynos4210-smdkv310.dts
-- arch/arm/boot/dts/exynos4412-trats2.dts
-- arch/arm/boot/dts/exynos5250-smdk5250.dts

Also, the SPI core and many drivers moved on to using "cs-gpios" from SPI node and removed the gpio handling code from drivers (including spi-s3c64xx.c).

Hence, spi-s3c64xx.c is broken since "Jun 21 11:26:12 2013" and considering the time with no compliants about the breakage.

We are assuming it is safe to remove the "cs-gpio"(singular) usage from device tree binding of spi-samsung.txt and makes appropriate changes in the driver to use "cs-gpios"(plural) from SPI device node.

---
Changes since v4:
1. Added reviewed by from Javier and Tested by from Doug

Changes since v3:
1. Remove the sdd->cs_gpio and use gpio_is_valid(spi->cs_gpio) instead
2. Keep cs->line only for Non-DT platforms and use spi->cs_gpio for DT platforms

 .../devicetree/bindings/spi/spi-samsung.txt        |    8 ++--
 drivers/spi/spi-s3c64xx.c                          |   41 ++++++++------------
 2 files changed, 20 insertions(+), 29 deletions(-)
Documentation/devicetree/bindings/spi/spi-samsung.txt +3 -5
index 86aa061..2d29dac 100644
@@ -42,15 +42,13 @@ Optional Board Specific Properties:
 - num-cs: Specifies the number of chip select lines supported. If
   not specified, the default number of chip select lines is set to 1.
 
+- cs-gpios: should specify GPIOs used for chipselects (see spi-bus.txt)
+
 SPI Controller specific data in SPI slave nodes:
 
 - The spi slave nodes should provide the following information which is required
   by the spi controller.
 
-  - cs-gpio: A gpio specifier that specifies the gpio line used as
-    the slave select line by the spi controller. The format of the gpio
-    specifier depends on the gpio controller.
-
   - samsung,spi-feedback-delay: The sampling phase shift to be applied on the
     miso line (to account for any lag in the miso line). The following are the
     valid values.
@@ -85,6 +83,7 @@ Example:
 		#size-cells = <0>;
 		pinctrl-names = "default";
 		pinctrl-0 = <&spi0_bus>;
+		cs-gpios = <&gpa2 5 0>;
 
 		w25q80bw at 0 {
 			#address-cells = <1>;
@@ -94,7 +93,6 @@ Example:
 			spi-max-frequency = <10000>;
 
 			controller-data {
-				cs-gpio = <&gpa2 5 1 0 3>;
 				samsung,spi-feedback-delay = <0>;
 			};
 
drivers/spi/spi-s3c64xx.c +17 -24

92 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v5 2/3 spi: s3c64xx: for DT platofrms always get the chipselect info from DT node

Use controller_data structure only for the Non Device tree platforms. For Device tree platforms, always derive the chipselect info from DT node.

---
Changes since v4:
1. Added reviewed by from Javier and Tested by from Doug

Changes since v3:
New change

 drivers/spi/spi-s3c64xx.c |   11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/spi/spi-s3c64xx.c +6 -5
index b888c66..f27e15d 100644
@@ -795,14 +795,15 @@ static int s3c64xx_spi_setup(struct spi_device *spi)
 	int err;
 
 	sdd = spi_master_get_devdata(spi->master);
-	if (!cs && spi->dev.of_node) {
+	if (spi->dev.of_node) {
 		cs = s3c64xx_get_slave_ctrldata(spi);
 		spi->controller_data = cs;
-	}
-
-	/* For the non-DT platforms derive chip selects from controller data */
-	if (!spi->dev.of_node)
+	} else {
+		/* For the non-DT platforms derive chip
+		 * selects from controller data
+		 */
 		spi->cs_gpio = cs->line;
+	}
 
 	if (IS_ERR_OR_NULL(cs)) {
 		dev_err(&spi->dev, "No CS for SPI(%d)\n", spi->chip_select);
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH v5 3/3 ARM: DTS: fix the chip select gpios definition in the SPI nodes

In reply to Naveen Krishna Chatradhi

This patch replaces the "cs-gpio" from "controller-data" node as was specified in the old binding and use the standard "cs-gpios" property expected by the SPI core as is defined in the new binding.

Respective changes are preposed to spi-s3c64xx.c driver. @ http://www.spinics.net/lists/linux-samsung-soc/msg32282.html

---
Changes since v4:
1. Added reviewed by from Javier and Doug.
2. Maintained the "status" and "cs-gpios" ordering

Changes since v3:
None

 arch/arm/boot/dts/exynos4210-smdkv310.dts |    2 +-
 arch/arm/boot/dts/exynos4412-trats2.dts   |    2 +-
 arch/arm/boot/dts/exynos5250-smdk5250.dts |    2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
arch/arm/boot/dts/exynos4210-smdkv310.dts +1 -1
index 636d166..676e6e0 100644
@@ -168,6 +168,7 @@
 	};
 
 	spi_2: spi at 13940000 {
+		cs-gpios = <&gpc1 2 0>;
 		status = "okay";
 
 		w25x80 at 0 {
@@ -178,7 +179,6 @@
 			spi-max-frequency = <1000000>;
 
 			controller-data {
-				cs-gpio = <&gpc1 2 0>;
 				samsung,spi-feedback-delay = <0>;
 			};
 
arch/arm/boot/dts/exynos4412-trats2.dts +1 -1
index 8a558b7..204b0de 100644
@@ -512,6 +512,7 @@
 	spi_1: spi at 13930000 {
 		pinctrl-names = "default";
 		pinctrl-0 = <&spi1_bus>;
+		cs-gpios = <&gpb 5 0>;
 		status = "okay";
 
 		s5c73m3_spi: s5c73m3 {
@@ -519,7 +520,6 @@
 			spi-max-frequency = <50000000>;
 			reg = <0>;
 			controller-data {
-				cs-gpio = <&gpb 5 0>;
 				samsung,spi-feedback-delay = <2>;
 			};
 		};
arch/arm/boot/dts/exynos5250-smdk5250.dts +1 -1
index a794a70..0c6433a 100644
@@ -316,6 +316,7 @@
 	};
 
 	spi_1: spi at 12d30000 {
+		cs-gpios = <&gpa2 5 0>;
 		status = "okay";
 
 		w25q80bw at 0 {
@@ -326,7 +327,6 @@
 			spi-max-frequency = <1000000>;
 
 			controller-data {
-				cs-gpio = <&gpa2 5 0>;
 				samsung,spi-feedback-delay = <0>;
 			};
 
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH v5 1/3 spi: s3c64xx: fix broken "cs_gpios" usage in the driver

In reply to Naveen Krishna Chatradhi

Mark or Kukjin,

Quoted 47 lines · Naveen Krishna Chatradhi

Since, (3146bee spi: s3c64xx: Added provision for dedicated cs pin)

spi-s3c64xx.c driver expects
1. chip select gpios from "cs-gpio"(singular) under the "controller-data" node of the client/slave device of the SPI.

2. "cs-gpio"(singular) entry to be present in the SPI device node.

Eg of current broken usage:

&spi_1 {
        cs-gpio <>;     /* this entry is checked during probe */
        ...
        slave_node {
                controller-data {
                        cs-gpio <&gpioa2 5 0>;
                        /* This field is parsed during .setup() */
                }
        };
};

The following dts files which were using this driver. But, din't have the "cs-gpio" entry under SPI node.
-- arch/arm/boot/dts/exynos4210-smdkv310.dts
-- arch/arm/boot/dts/exynos4412-trats2.dts
-- arch/arm/boot/dts/exynos5250-smdk5250.dts

Also, the SPI core and many drivers moved on to using "cs-gpios" from SPI node and removed the gpio handling code from drivers (including spi-s3c64xx.c).

Hence, spi-s3c64xx.c is broken since "Jun 21 11:26:12 2013" and considering the time with no compliants about the breakage.

We are assuming it is safe to remove the "cs-gpio"(singular) usage from device tree binding of spi-samsung.txt and makes appropriate changes in the driver to use "cs-gpios"(plural) from SPI device node.

---
Changes since v4:
1. Added reviewed by from Javier and Tested by from Doug

Quoted 8 lines

Changes since v3:
1. Remove the sdd->cs_gpio and use gpio_is_valid(spi->cs_gpio) instead
2. Keep cs->line only for Non-DT platforms and use spi->cs_gpio for DT platforms

 .../devicetree/bindings/spi/spi-samsung.txt        |    8 ++--
 drivers/spi/spi-s3c64xx.c                          |   41 ++++++++------------
 2 files changed, 20 insertions(+), 29 deletions(-)

Is one of you two planning to apply (parts 1 and 2)? I know that Kukjin needs to handle the part 3 (the .dts files)...

Ideally it seems like it could go to 3.16 since it is a bugfix...

Thanks!

-Doug

maintainer
#4 lore raw

PATCH v5 1/3 spi: s3c64xx: fix broken "cs_gpios" usage in the driver

Quoted 4 lines · Doug Anderson

Is one of you two planning to apply (parts 1 and 2)? I know that Kukjin needs to handle the part 3 (the .dts files)...

Ideally it seems like it could go to 3.16 since it is a bugfix...

Don't nag, it just means yet more mail to look at which makes things worse not better. Given all the problems the DT code for this driver has I need to review carefully, and the fact that this has got to v5 before I had a chance to look at it sets off alarm bells too.

There's a couple of months to get bug fixes in yet.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140621/32b5cc67/attachment.sig>

#5 lore raw

PATCH v5 1/3 spi: s3c64xx: fix broken "cs_gpios" usage in the driver

Hello Mark,

Quoted 11 lines · Mark Brown
Quoted 4 lines · Doug Anderson

Is one of you two planning to apply (parts 1 and 2)? I know that Kukjin needs to handle the part 3 (the .dts files)...

Ideally it seems like it could go to 3.16 since it is a bugfix...

Don't nag, it just means yet more mail to look at which makes things worse not better. Given all the problems the DT code for this driver has I need to review carefully, and the fact that this has got to v5 before I had a chance to look at it sets off alarm bells too.

The revisions were pretty quick
v1 to v2 : Updated DT Documentation for the change
v2 to v3 : use spi->cs_gpio in the driver
v3 to v4 : use gpio_is_valid() instead of using sdd->cs_gpio (local variable,

              also remove sdd->cs_gpio)

v4 to v5 : Added Acked-by and Revewied-by from Javier and Rob Herring

Major discussion in this thread was about keeping the old DT bindings to support legacy or move on with the new bindings.

Tomasz Figa, Javier Martinez Canillas, Doug Anderson and Rob Herring agreed with the latter.

Kindly review and let us know your comments.

Thanks

Quoted 2 lines

There's a couple of months to get bug fixes in yet.

Signature · 2 lines
Shine bright,
(: Nav :)
maintainer
#6 lore raw

PATCH v5 1/3 spi: s3c64xx: fix broken "cs_gpios" usage in the driver

Quoted 1 line · Naveen Krishna Ch

The revisions were pretty quick

Yes, this is part of what I'm concerned about - it often means that there are problems, either the review wasn't very detailed or the code is being written too hastily. In this case this is coupled with the fact that it's an area of the code that has had problems in general is setting off alarm bells.

Quoted 1 line

v4 to v5 : Added Acked-by and Revewied-by from Javier and Rob Herring

Don't resend for tags - you should include tags if you do resend but they're not a good reason to do so.

Quoted 1 line

Kindly review and let us know your comments.

I will review it when I get to it, this isn't the only thing I've got
sitting for review.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140622/f6900888/attachment.sig>

#7 lore raw

PATCH v5 1/3 spi: s3c64xx: fix broken "cs_gpios" usage in the driver

In reply to Doug Anderson
Quoted 3 lines · Doug Anderson

Mark or Kukjin,

Hi,

Quoted 54 lines
Quoted 52 lines · Naveen Krishna Chatradhi

Since, (3146bee spi: s3c64xx: Added provision for dedicated cs pin)

spi-s3c64xx.c driver expects
1. chip select gpios from "cs-gpio"(singular) under the "controller-data" node of the client/slave device of the SPI.

2. "cs-gpio"(singular) entry to be present in the SPI device node.

Eg of current broken usage:

&spi_1 {
        cs-gpio <>;     /* this entry is checked during probe */
        ...
        slave_node {
                controller-data {
                        cs-gpio <&gpioa2 5 0>;
                        /* This field is parsed during .setup() */
                }
        };
};

The following dts files which were using this driver. But, din't have the "cs-gpio" entry under SPI node.
-- arch/arm/boot/dts/exynos4210-smdkv310.dts
-- arch/arm/boot/dts/exynos4412-trats2.dts
-- arch/arm/boot/dts/exynos5250-smdk5250.dts

Also, the SPI core and many drivers moved on to using "cs-gpios" from SPI node and removed the gpio handling code from drivers (including spi-s3c64xx.c).

Hence, spi-s3c64xx.c is broken since "Jun 21 11:26:12 2013" and considering the time with no compliants about the breakage.

We are assuming it is safe to remove the "cs-gpio"(singular) usage from device tree binding of spi-samsung.txt and makes appropriate changes in the driver to use "cs-gpios"(plural) from SPI device node.

---
Changes since v4:
1. Added reviewed by from Javier and Tested by from Doug

Changes since v3:
1. Remove the sdd->cs_gpio and use gpio_is_valid(spi->cs_gpio) instead
2. Keep cs->line only for Non-DT platforms and use spi->cs_gpio for DT platforms

Quoted 7 lines
Quoted 3 lines
 .../devicetree/bindings/spi/spi-samsung.txt        |    8 ++--
 drivers/spi/spi-s3c64xx.c                          |   41 ++++++++------------
 2 files changed, 20 insertions(+), 29 deletions(-)

Is one of you two planning to apply (parts 1 and 2)? I know that Kukjin needs to handle the part 3 (the .dts files)...

Once Mark takes spi driver related patches, I will pick DT related patches into samsung tree.

Quoted 2 lines

Ideally it seems like it could go to 3.16 since it is a bugfix...

I think so but it depends on Mark's comments ;-)

Thanks,
Kukjin

maintainer
#8 lore raw

PATCH v5 1/3 spi: s3c64xx: fix broken "cs_gpios" usage in the driver

In reply to Naveen Krishna Chatradhi
Quoted 2 lines · Naveen Krishna Chatradhi

Hence, spi-s3c64xx.c is broken since "Jun 21 11:26:12 2013" and considering the time with no compliants about the breakage.

I'm not clear what the breakage is? Some boards are broken but what's the driver issue?

Quoted 12 lines
drivers/spi/spi-s3c64xx.c +4 -3
 	if (!spi_get_ctldata(spi)) {
 		/* Request gpio only if cs line is asserted by gpio pins */
-		if (sdd->cs_gpio) {
-			err = gpio_request_one(cs->line, GPIOF_OUT_INIT_HIGH,
-					dev_name(&spi->dev));
+		if (gpio_is_valid(spi->cs_gpio)) {
+			err = gpio_request_one(spi->cs_gpio,
+						GPIOF_OUT_INIT_HIGH,
+						dev_name(&spi->dev));
 			if (err) {
 				dev_err(&spi->dev,
 					"Failed to get /CS gpio [%d]: %d\n",

drivers/spi/spi-s3c64xx.c static int s3c64xx_spi_setup(struct spi_device *spi) · line 827

Quoted 10 lines
drivers/spi/spi-s3c64xx.c +4 -3
-					cs->line, err);
+					spi->cs_gpio, err);
 				goto err_gpio_req;
 			}
-
-			spi->cs_gpio = cs->line;
+		} else {
+			dev_err(&spi->dev, "chip select gpio is invalid\n");
+			return -EINVAL;
 		}

This appears to be making it mandatory to specify a GPIO when previously it was not mandatory which I believe breaks some SoCs - the native chip select has to be used on some devices as there is no pinmux option to make it a GPIO (this was why the native chip select support was added).

Also I'd need to check but are you sure that GPIO 0 is not valid?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140702/78876b08/attachment.sig>

#9 lore raw

PATCH v5 1/3 spi: s3c64xx: fix broken "cs_gpios" usage in the driver

Hello Mark,

Thanks for the review.

Quoted 7 lines · Mark Brown
Quoted 2 lines · Naveen Krishna Chatradhi

Hence, spi-s3c64xx.c is broken since "Jun 21 11:26:12 2013" and considering the time with no compliants about the breakage.

I'm not clear what the breakage is? Some boards are broken but what's the driver issue?

ToT was broken for few boards
exynos4412-trats2.dts, exynos4210-smdkv310.dts and exynos5250-smdk5250.dts

With some DTS changes SPI works well, spi-s3c64xx.c driver had no issues.

Quoted 24 lines
Quoted 13 lines
      if (!spi_get_ctldata(spi)) {
              /* Request gpio only if cs line is asserted by gpio pins */
drivers/spi/spi-s3c64xx.c +4 -3
-             if (sdd->cs_gpio) {
-                     err = gpio_request_one(cs->line, GPIOF_OUT_INIT_HIGH,
-                                     dev_name(&spi->dev));
+             if (gpio_is_valid(spi->cs_gpio)) {
+                     err = gpio_request_one(spi->cs_gpio,
+                                             GPIOF_OUT_INIT_HIGH,
+                                             dev_name(&spi->dev));
                      if (err) {
                              dev_err(&spi->dev,
                                      "Failed to get /CS gpio [%d]: %d\n",

drivers/spi/spi-s3c64xx.c static int s3c64xx_spi_setup(struct spi_device *spi) · line 827

Quoted 10 lines
drivers/spi/spi-s3c64xx.c +4 -3
-                                     cs->line, err);
+                                     spi->cs_gpio, err);
                              goto err_gpio_req;
                      }
-
-                     spi->cs_gpio = cs->line;
+             } else {
+                     dev_err(&spi->dev, "chip select gpio is invalid\n");
+                     return -EINVAL;
              }
Quoted 4 lines

This appears to be making it mandatory to specify a GPIO when previously it was not mandatory which I believe breaks some SoCs - the native chip select has to be used on some devices as there is no pinmux option to make it a GPIO (this was why the native chip select support was added).

I read the commit "3146beec21b64f4551fcf0ac148381d54dc41b1b" "spi: s3c64xx: Added provision for dedicated cs pin"

I understand "cs_gpio" shouldn't be mandatory. Will remove the else part.

Quoted 2 lines

Also I'd need to check but are you sure that GPIO 0 is not valid?

gpio_is_valid() returns true for
"number >= 0 && number < ARCH_NR_GPIOS"

Signature · 2 lines
Shine bright,
(: Nav :)
maintainer
#10 lore raw

PATCH v5 1/3 spi: s3c64xx: fix broken "cs_gpios" usage in the driver

Quoted 6 lines · Naveen Krishna Ch
Quoted 4 lines · Mark Brown
Quoted 2 lines · Naveen Krishna Chatradhi

Hence, spi-s3c64xx.c is broken since "Jun 21 11:26:12 2013" and considering the time with no compliants about the breakage.

Quoted 7 lines
Quoted 2 lines

I'm not clear what the breakage is? Some boards are broken but what's the driver issue?

ToT was broken for few boards
exynos4412-trats2.dts, exynos4210-smdkv310.dts and exynos5250-smdk5250.dts

With some DTS changes SPI works well, spi-s3c64xx.c driver had no issues.

No, you're not answering my question - to repeat, what is the breakage?

Quoted 4 lines
Quoted 1 line

Also I'd need to check but are you sure that GPIO 0 is not valid?

gpio_is_valid() returns true for
"number >= 0 && number < ARCH_NR_GPIOS"

Right, so this means that any board that is using the internal chip
select with zero as default in their platform data is broken by this
change.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140707/462d6fc2/attachment.sig>

#11 lore raw

PATCH v5 1/3 spi: s3c64xx: fix broken "cs_gpios" usage in the driver

Hello Mark,

Quoted 10 lines · Mark Brown
Quoted 8 lines · Naveen Krishna Ch
Quoted 7 lines · Mark Brown
Quoted 2 lines · Naveen Krishna Chatradhi

Hence, spi-s3c64xx.c is broken since "Jun 21 11:26:12 2013" and considering the time with no compliants about the breakage.

I'm not clear what the breakage is? Some boards are broken but what's the driver issue?

Quoted 6 lines
Quoted 4 lines

ToT was broken for few boards
exynos4412-trats2.dts, exynos4210-smdkv310.dts and exynos5250-smdk5250.dts

With some DTS changes SPI works well, spi-s3c64xx.c driver had no issues.

No, you're not answering my question - to repeat, what is the breakage?

The Documentation/devicetree/bindings/spi/spi-samsung.txt describes "cs-gpio" as a controller specific property.

The dts entries for SPI in exynos4412-trats2.dts, exynos4210-smdkv310.dts and exynos5250-smdk5250.dts boards have the "cs-gpio" property defined under controller-data node, which is inside the SPI device node &spi_1 {

  controller-data {
    cs-gpio = <>;

};
};

But, _probe() of spi-s3c64xx.c driver looks for "cs-gpio" in the SPI device node and
sets a flag "sdd->cs_gpio = false" (If the property is not available) &spi_1 {
cs-gpio = <>;
};

the sdd->cs_gpio flag is checked before actually getting the gpios from the controller-data node

       if (sdd->cs_gpio)
                cs->line = of_get_named_gpio(data_np, "cs-gpio", 0);

Hence, SPI was failing on those boards.

1. As the SPI core and several drivers were changed to work with DT property "cs-gpios" (plural) defined under SPI node.
2. Since the commit 3146beec21b64f4551fcf0ac148381d54dc41b1b "spi: s3c64xx: Added provision for dedicated cs pin"
Dated: Fri Jun 21 11:26:12 2013 +0530

For the above 2 reasons, It was decided to drop the backward compatibility of using "cs-gpio"(singular) in controller-data.
Instead, start supporting "cs-gpios"(plural) in the SPI node.

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Also I'd need to check but are you sure that GPIO 0 is not valid?

gpio_is_valid() returns true for
"number >= 0 && number < ARCH_NR_GPIOS"

Right, so this means that any board that is using the internal chip select with zero as default in their platform data is broken by this change.

using gpio_is_valid() to "sdd->cs_gpio" flag every where to check for the validity was a review comment.
Which seems to fail for internal chip select with zero.

I can submit another version with"sdd->cs_gpio" flag for this purpose.

Signature · 2 lines
Thanks & Regards,
(: Nav :)
#12 lore raw

PATCH v5 1/3 spi: s3c64xx: fix broken "cs_gpios" usage in the driver

Hello Naveen and Mark,

Quoted 18 lines · Naveen Krishna Ch

Hello Mark,

Quoted 15 lines · Mark Brown
Quoted 13 lines · Naveen Krishna Ch
Quoted 7 lines · Mark Brown
Quoted 2 lines · Naveen Krishna Chatradhi

Hence, spi-s3c64xx.c is broken since "Jun 21 11:26:12 2013" and considering the time with no compliants about the breakage.

I'm not clear what the breakage is? Some boards are broken but what's the driver issue?

ToT was broken for few boards
exynos4412-trats2.dts, exynos4210-smdkv310.dts and exynos5250-smdk5250.dts

With some DTS changes SPI works well, spi-s3c64xx.c driver had no issues.

Correct me if I'm wrong but I think that the driver does have issues since the commit mentioned (3146bee) broke DT backward compatibility.

Quoted 2 lines
Quoted 1 line

No, you're not answering my question - to repeat, what is the breakage?

As far as I understand, the breakage is that any DTS that followed the DT binding documented in Documentation/devicetree/bindings/spi/spi-samsung.txt is not working with the current driver. So is not that some boards are broken, is that the driver is broken and it has been broken for more than a year (the commit date is Jun 21 2013).

Quoted 19 lines

The Documentation/devicetree/bindings/spi/spi-samsung.txt describes "cs-gpio" as a controller specific property.

The dts entries for SPI in exynos4412-trats2.dts, exynos4210-smdkv310.dts and exynos5250-smdk5250.dts boards have the "cs-gpio" property defined under controller-data node, which is inside the SPI device node &spi_1 {

  controller-data {
    cs-gpio = <>;

};
};

But, _probe() of spi-s3c64xx.c driver looks for "cs-gpio" in the SPI device node and
sets a flag "sdd->cs_gpio = false" (If the property is not available) &spi_1 {
cs-gpio = <>;
};

Quoted 5 lines

the sdd->cs_gpio flag is checked before actually getting the gpios from the controller-data node

       if (sdd->cs_gpio)
                cs->line = of_get_named_gpio(data_np, "cs-gpio", 0);

I think that if changing the binding is not possible, at least we should document this new "cs-gpio" property that is looked in the top level SPI node after commit 3146bee and also revert the default in order to allow DTs using the old binding to keep working.

By default not having the "cs-gpio" property in the SPI dev node should mean that the "cs-gpio" property in the controller-data node should be used to signal the chip-select and having the "cs-gpio" property in the SPI node should mean that the native chip select should be used instead of a GPIO. That preserves the old DT binding semantic while making the GPIO to be optional.

Of course in that case the property name does not make too much sense, so probably should be changed to "cs-native" or something like that. But I still don't understand why this is needed in the first place since according to Documentation/devicetree/bindings/spi/spi-bus.txt you can use the cs-gpios property to specify that a native chip-select will be used instead of a GPIO by doing:

cs-gpios = <&gpio1 0 0> <0>

cs0 : &gpio1 0 0
cs1 : native

Quoted 8 lines

Hence, SPI was failing on those boards.

1. As the SPI core and several drivers were changed to work with DT property "cs-gpios" (plural) defined under SPI node.
2. Since the commit 3146beec21b64f4551fcf0ac148381d54dc41b1b "spi: s3c64xx: Added provision for dedicated cs pin"
Dated: Fri Jun 21 11:26:12 2013 +0530

Quoted 4 lines

For the above 2 reasons, It was decided to drop the backward compatibility of using "cs-gpio"(singular) in controller-data.
Instead, start supporting "cs-gpios"(plural) in the SPI node.

Right, since the DT binding has been broken for a year and because is not consistent with the bindings used by all other SPI drivers, many agreed that it was one of the exceptional cases where the DT binding can be rethought and changed to use the generic "cs-gpios" property already supported by SPI core. It breaks backward compatibility that's true but the DT binding has been broken anyways and nobody noticed before.

The other option is what I said above, fixing the DT binding compatibility breakage while keeping the custom binding for this SPI driver.

Quoted 10 lines
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Also I'd need to check but are you sure that GPIO 0 is not valid?

gpio_is_valid() returns true for
"number >= 0 && number < ARCH_NR_GPIOS"

Right, so this means that any board that is using the internal chip select with zero as default in their platform data is broken by this change.

I think this problem could be present in other SPI drivers as well? So maybe the right fix for this is to convert the SPI core gpio handling to use the new descriptor-based gpio API instead of the integer-base one?

Quoted 10 lines

using gpio_is_valid() to "sdd->cs_gpio" flag every where to check for the validity was a review comment.
Which seems to fail for internal chip select with zero.

I can submit another version with"sdd->cs_gpio" flag for this purpose.

--
Thanks & Regards,
(: Nav :)
--

Best regards,
Javier

#13 lore raw

PATCH v5 1/3 spi: s3c64xx: fix broken "cs_gpios" usage in the driver

Hello Naveen and Mark,

Quoted 113 lines · Javier Martinez Canillas
Quoted 4 lines · Naveen Krishna Ch
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Hence, spi-s3c64xx.c is broken since "Jun 21 11:26:12 2013" and considering the time with no compliants about the breakage.

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

I'm not clear what the breakage is? Some boards are broken but what's the driver issue?

ToT was broken for few boards
exynos4412-trats2.dts, exynos4210-smdkv310.dts and exynos5250-smdk5250.dts

With some DTS changes SPI works well, spi-s3c64xx.c driver had no issues.

Correct me if I'm wrong but I think that the driver does have issues since the commit mentioned (3146bee) broke DT backward compatibility.

Quoted 2 lines
Quoted 1 line

No, you're not answering my question - to repeat, what is the breakage?

As far as I understand, the breakage is that any DTS that followed the DT binding documented in Documentation/devicetree/bindings/spi/spi-samsung.txt is not working with the current driver. So is not that some boards are broken, is that the driver is broken and it has been broken for more than a year (the commit date is Jun 21 2013).

Quoted 19 lines

The Documentation/devicetree/bindings/spi/spi-samsung.txt describes "cs-gpio" as a controller specific property.

The dts entries for SPI in exynos4412-trats2.dts, exynos4210-smdkv310.dts and exynos5250-smdk5250.dts boards have the "cs-gpio" property defined under controller-data node, which is inside the SPI device node &spi_1 {

  controller-data {
    cs-gpio = <>;

};
};

But, _probe() of spi-s3c64xx.c driver looks for "cs-gpio" in the SPI device node and
sets a flag "sdd->cs_gpio = false" (If the property is not available) &spi_1 {
cs-gpio = <>;
};

Quoted 5 lines

the sdd->cs_gpio flag is checked before actually getting the gpios from the controller-data node

       if (sdd->cs_gpio)
                cs->line = of_get_named_gpio(data_np, "cs-gpio", 0);

I think that if changing the binding is not possible, at least we should document this new "cs-gpio" property that is looked in the top level SPI node after commit 3146bee and also revert the default in order to allow DTs using the old binding to keep working.

By default not having the "cs-gpio" property in the SPI dev node should mean that the "cs-gpio" property in the controller-data node should be used to signal the chip-select and having the "cs-gpio" property in the SPI node should mean that the native chip select should be used instead of a GPIO. That preserves the old DT binding semantic while making the GPIO to be optional.

Of course in that case the property name does not make too much sense, so probably should be changed to "cs-native" or something like that. But I still don't understand why this is needed in the first place since according to Documentation/devicetree/bindings/spi/spi-bus.txt you can use the cs-gpios property to specify that a native chip-select will be used instead of a GPIO by doing:

cs-gpios = <&gpio1 0 0> <0>

cs0 : &gpio1 0 0
cs1 : native

Quoted 8 lines

Hence, SPI was failing on those boards.

1. As the SPI core and several drivers were changed to work with DT property "cs-gpios" (plural) defined under SPI node.
2. Since the commit 3146beec21b64f4551fcf0ac148381d54dc41b1b "spi: s3c64xx: Added provision for dedicated cs pin"
Dated: Fri Jun 21 11:26:12 2013 +0530

Quoted 4 lines

For the above 2 reasons, It was decided to drop the backward compatibility of using "cs-gpio"(singular) in controller-data.
Instead, start supporting "cs-gpios"(plural) in the SPI node.

Right, since the DT binding has been broken for a year and because is not consistent with the bindings used by all other SPI drivers, many agreed that it was one of the exceptional cases where the DT binding can be rethought and changed to use the generic "cs-gpios" property already supported by SPI core. It breaks backward compatibility that's true but the DT binding has been broken anyways and nobody noticed before.

The other option is what I said above, fixing the DT binding compatibility breakage while keeping the custom binding for this SPI driver.

Quoted 10 lines
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Also I'd need to check but are you sure that GPIO 0 is not valid?

gpio_is_valid() returns true for
"number >= 0 && number < ARCH_NR_GPIOS"

Right, so this means that any board that is using the internal chip select with zero as default in their platform data is broken by this change.

Quoted 15 lines

I think this problem could be present in other SPI drivers as well? So maybe the right fix for this is to convert the SPI core gpio handling to use the new descriptor-based gpio API instead of the integer-base one?

Quoted 10 lines

using gpio_is_valid() to "sdd->cs_gpio" flag every where to check for the validity was a review comment.
Which seems to fail for internal chip select with zero.

I can submit another version with"sdd->cs_gpio" flag for this purpose.

--
Thanks & Regards,
(: Nav :)
--

Any more opinions on this issue?

It would be great if we can move this forward since there are other series that depend on these fixes.

Best regards,
Javier

maintainer
#14 lore raw

PATCH v5 1/3 spi: s3c64xx: fix broken "cs_gpios" usage in the driver

Quoted 5 lines · Javier Martinez Canillas

Hello Naveen and Mark,

Quoted 2 lines · Javier Martinez Canillas

On Mon, Jul 7, 2014 at 10:31 AM, Naveen Krishna Ch <[email protected]> wrote:

Please delete irrelevant context from your replies, this mail is over a hundred lines long and has only three lines of new content.

Quoted 4 lines

Any more opinions on this issue?

It would be great if we can move this forward since there are other series that depend on these fixes.

Well, the bug with making a GPIO chip select mandatory needs to be
fixed.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140711/842d413e/attachment.sig>