Skip to contentSkip to conversation

gpio: add support for Cypress CYUSBS234 USB-GPIO adapter

PATCH Superseded Muthu Mani 4 participants 8 messages Oct 6, 2014 – Oct 29, 2014

Subsystems (2)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Muthu Mani

author
#0 lore raw

PATCH v3 3/3 gpio: add support for Cypress CYUSBS234 USB-GPIO adapter

Adds support for USB-GPIO interface of Cypress Semiconductor CYUSBS234 USB-Serial Bridge controller.

The GPIO get/set can be done through vendor command on control endpoint for the configured gpios.

Details about the device can be found at:
http://www.cypress.com/?rID=84126

---
Changes since v2:
* added helper macros
* removed lock
* given gpio chip device for dev_xxx
* cleaned up the code

Changes since v1:
* allocated memory on heap for usb transfer data
* changed gpio label as platform device name to identify multiple devices

 drivers/gpio/Kconfig          |  13 ++++
 drivers/gpio/Makefile         |   1 +
 drivers/gpio/gpio-cyusbs23x.c | 174 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 188 insertions(+)
 create mode 100644 drivers/gpio/gpio-cyusbs23x.c
drivers/gpio/Kconfig +13 -0
index 9de1515..932e07c 100644
@@ -886,6 +886,19 @@ config GPIO_BCM_KONA
 
 comment "USB GPIO expanders:"
 
+config GPIO_CYUSBS23X
+	tristate "CYUSBS23x GPIO support"
+	depends on MFD_CYUSBS23X && USB
+	help
+	  Say yes here to access the GPIO signals of Cypress
+	  Semiconductor CYUSBS23x USB Serial Bridge Controller.
+
+	  This driver enables the GPIO interface of CYUSBS23x USB Serial
+	  Bridge controller.
+
+	  This driver can also be built as a module. If so, the module will be
+	  called gpio-cyusbs23x.
+
 config GPIO_VIPERBOARD
 	tristate "Viperboard GPIO a & b support"
 	depends on MFD_VIPERBOARD && USB
drivers/gpio/Makefile +1 -0
index 5d024e3..3ad89f1 100644
@@ -23,6 +23,7 @@ obj-$(CONFIG_GPIO_BT8XX)	+= gpio-bt8xx.o
 obj-$(CONFIG_GPIO_CLPS711X)	+= gpio-clps711x.o
 obj-$(CONFIG_GPIO_CS5535)	+= gpio-cs5535.o
 obj-$(CONFIG_GPIO_CRYSTAL_COVE)	+= gpio-crystalcove.o
+obj-$(CONFIG_GPIO_CYUSBS23X)	+= gpio-cyusbs23x.o
 obj-$(CONFIG_GPIO_DA9052)	+= gpio-da9052.o
 obj-$(CONFIG_GPIO_DA9055)	+= gpio-da9055.o
 obj-$(CONFIG_GPIO_DAVINCI)	+= gpio-davinci.o
drivers/gpio/gpio-cyusbs23x.c new file +174 -0

174 lines not on this page · raw message

Signature · 1 line
1.8.3.2
#1 lore raw

drivers/gpio/gpio-cyusbs23x.c line 113

Quoted 12 lines · Muthu Mani
drivers/gpio/gpio-cyusbs23x.c new file +12 -0
+
+static int cy_gpio_direction_input(struct gpio_chip *chip,
+                                       unsigned offset)
+{
+       return 0;
+}
+
+static int cy_gpio_direction_output(struct gpio_chip *chip,
+                                       unsigned offset, int value)
+{
+       return 0;
+}

If that chip is capable of both output and input, shouldn't these functions be implemented? I think this has already been pointed out in a previous version but you did not reply.

Quoted 13 lines
drivers/gpio/gpio-cyusbs23x.c new file +12 -0
+
+static int cyusbs23x_gpio_probe(struct platform_device *pdev)
+{
+       struct cyusbs23x *cyusbs;
+       struct cyusbs_gpio *cy_gpio;
+       int ret = 0;
+
+       dev_dbg(&pdev->dev, "%s\n", __func__);
 
+
+       cyusbs = dev_get_drvdata(pdev->dev.parent);
+
+       cy_gpio = devm_kzalloc(&pdev->dev, sizeof(*cy_gpio), GFP_KERNEL);

drivers/gpio/gpio-cyusbs23x.c line 135

Quoted 10 lines
drivers/gpio/gpio-cyusbs23x.c new file +10 -0
+       if (cy_gpio == NULL)
+               return -ENOMEM;
+
+       cy_gpio->cyusbs = cyusbs;
+       /* registering gpio */
+       cy_gpio->gpio.label = dev_name(&pdev->dev);
+       cy_gpio->gpio.dev = &pdev->dev;
+       cy_gpio->gpio.owner = THIS_MODULE;
+       cy_gpio->gpio.base = -1;
+       cy_gpio->gpio.ngpio = 12; /* total GPIOs */

Isn't there a way to get the number of GPIOs from a re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WNybyBhbmQgdXNl IGl0Lg0K
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
Quoted 27 lines · Muthu Mani
Quoted 12 lines

-----Original Message-----
From: Alexandre Courbot [mailto:[email protected]]
Sent: Tuesday, October 07, 2014 3:34 PM
To: Muthu Mani
Cc: Samuel Ortiz; Lee Jones; Wolfram Sang; Linus Walleij; Greg Kroah-
Hartman; [email protected]; [email protected]; linux- [email protected]; Linux Kernel Mailing List; Rajaram Regupathy; Johan Hovold
Subject: Re: [PATCH v3 3/3] gpio: add support for Cypress CYUSBS234 USB-
GPIO adapter

On Mon, Oct 6, 2014 at 11:47 PM, Muthu Mani <muth-+wT8y+m8/[email protected]> wrote:

Quoted 14 lines

drivers/gpio/gpio-cyusbs23x.c line 113

Quoted 10 lines
drivers/gpio/gpio-cyusbs23x.c new file +10 -0
+
+static int cy_gpio_direction_input(struct gpio_chip *chip,
+                                       unsigned offset) {
+       return 0;
+}
+
+static int cy_gpio_direction_output(struct gpio_chip *chip,
+                                       unsigned offset, int value) {
+       return 0;
+}

If that chip is capable of both output and input, shouldn't these functions be implemented? I think this has already been pointed out in a previous version but you did not reply.

Quoted 3 lines

Thanks for your inputs.

Only the GPIOs which are configured to be output GPIO can be set.

In that case cy_gpio_set() should return an error for GPIOs which are not configured as outputs. Is that guaranteed by the current implementation?

Quoted 3 lines

The set operation would fail trying to set the input or unconfigured GPIOs.
In this version of driver, this support is not added, it can be introduced in future versions. I will add a TODO note in the code.

Argh, no TODO please. Actual code that will turn this code into a solid driver that can be merged.

Can all GPIOs be set as input or output? If so, please implement cy_gpio_direction_*() and make sure that cy_gpio_set() behaves properly if a GPIO is not an output. If the input/output GPIOs are fixed, please make cy_gpio_direction_*() return an error if the GPIO capabilities does not correspond to what is asked, and again ensure that cy_gpio_set() works as expected.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
Quoted 36 lines · Alexandre Courbot
Quoted 27 lines · Muthu Mani
Quoted 12 lines

-----Original Message-----
From: Alexandre Courbot [mailto:[email protected]]
Sent: Tuesday, October 07, 2014 3:34 PM
To: Muthu Mani
Cc: Samuel Ortiz; Lee Jones; Wolfram Sang; Linus Walleij; Greg Kroah- Hartman; [email protected]; [email protected]; linux- [email protected]; Linux Kernel Mailing List; Rajaram Regupathy; Johan Hovold
Subject: Re: [PATCH v3 3/3] gpio: add support for Cypress CYUSBS234 USB- GPIO adapter

On Mon, Oct 6, 2014 at 11:47 PM, Muthu Mani <[email protected]> wrote:

Quoted 14 lines

drivers/gpio/gpio-cyusbs23x.c line 113

Quoted 10 lines
drivers/gpio/gpio-cyusbs23x.c new file +10 -0
+
+static int cy_gpio_direction_input(struct gpio_chip *chip,
+                                       unsigned offset) {
+       return 0;
+}
+
+static int cy_gpio_direction_output(struct gpio_chip *chip,
+                                       unsigned offset, int value) {
+       return 0;
+}

If that chip is capable of both output and input, shouldn't these functions be implemented? I think this has already been pointed out in a previous version but you did not reply.

Quoted 3 lines

Thanks for your inputs.

Only the GPIOs which are configured to be output GPIO can be set.

In that case cy_gpio_set() should return an error for GPIOs which are not configured as outputs. Is that guaranteed by the current implementation?

Quoted 6 lines
Quoted 3 lines

The set operation would fail trying to set the input or unconfigured GPIOs.
In this version of driver, this support is not added, it can be introduced in future versions. I will add a TODO note in the code.

Argh, no TODO please. Actual code that will turn this code into a solid driver that can be merged.

Does a driver targeted for a custom device has to implement every functionality in the 1st version ? My understanding is that Linux follows incremental model and allows incremental merge.

(On a side note the driver is functionally verified with the necessary hardware)

Please correct me if I am missing something

Quoted 12 lines

Can all GPIOs be set as input or output? If so, please implement cy_gpio_direction_*() and make sure that cy_gpio_set() behaves properly if a GPIO is not an output. If the input/output GPIOs are fixed, please make cy_gpio_direction_*() return an error if the GPIO capabilities does not correspond to what is asked, and again ensure that cy_gpio_set() works as expected.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#5 lore raw
Quoted 41 lines · RR
Quoted 40 lines · Alexandre Courbot
Quoted 27 lines · Muthu Mani
Quoted 12 lines

-----Original Message-----
From: Alexandre Courbot [mailto:[email protected]]
Sent: Tuesday, October 07, 2014 3:34 PM
To: Muthu Mani
Cc: Samuel Ortiz; Lee Jones; Wolfram Sang; Linus Walleij; Greg Kroah- Hartman; [email protected]; [email protected]; linux- [email protected]; Linux Kernel Mailing List; Rajaram Regupathy; Johan Hovold
Subject: Re: [PATCH v3 3/3] gpio: add support for Cypress CYUSBS234 USB- GPIO adapter

On Mon, Oct 6, 2014 at 11:47 PM, Muthu Mani <[email protected]> wrote:

Quoted 14 lines

drivers/gpio/gpio-cyusbs23x.c line 113

Quoted 10 lines
drivers/gpio/gpio-cyusbs23x.c new file +10 -0
+
+static int cy_gpio_direction_input(struct gpio_chip *chip,
+                                       unsigned offset) {
+       return 0;
+}
+
+static int cy_gpio_direction_output(struct gpio_chip *chip,
+                                       unsigned offset, int value) {
+       return 0;
+}

If that chip is capable of both output and input, shouldn't these functions be implemented? I think this has already been pointed out in a previous version but you did not reply.

Quoted 3 lines

Thanks for your inputs.

Only the GPIOs which are configured to be output GPIO can be set.

In that case cy_gpio_set() should return an error for GPIOs which are not configured as outputs. Is that guaranteed by the current implementation?

Quoted 3 lines

The set operation would fail trying to set the input or unconfigured GPIOs.
In this version of driver, this support is not added, it can be introduced in future versions. I will add a TODO note in the code.

Quoted 6 lines
Quoted 2 lines

Argh, no TODO please. Actual code that will turn this code into a solid driver that can be merged.

Does a driver targeted for a custom device has to implement every functionality in the 1st version ? My understanding is that Linux follows incremental model and allows incremental merge.

Certainly, but we are talking about very basic functionality here.

Right now this driver will incorrectly returns success when trying to set the direction of a GPIO, even though it did not do anything. There is also no hint that _set will return an error if called on an input/unconfigured GPIO.

So while we are not asking for a driver to be perfect on the first iteration, setting the direction of a GPIO is a very basic functionality that is essential for a GPIO driver to just work. Custom device or not, this is mainline. The rest of the driver seems to be ok, so please take the last few steps that will allow us to merge a featured driver.

#6 lore raw
In reply to RR
Quoted 24 lines · RR
Quoted 23 lines · Alexandre Courbot
Quoted 9 lines · Muthu Mani
Quoted 8 lines

drivers/gpio/gpio-cyusbs23x.c line 113

Quoted 4 lines
drivers/gpio/gpio-cyusbs23x.c new file +4 -0
+static int cy_gpio_direction_output(struct gpio_chip *chip,
+                                       unsigned offset, int value) {
+       return 0;
+}

If that chip is capable of both output and input, shouldn't these functions be implemented? I think this has already been pointed out in a previous version but you did not reply.

Quoted 3 lines

Thanks for your inputs.

Only the GPIOs which are configured to be output GPIO can be set.

In that case cy_gpio_set() should return an error for GPIOs which are not configured as outputs. Is that guaranteed by the current implementation?

Quoted 3 lines

The set operation would fail trying to set the input or unconfigured GPIOs.
In this version of driver, this support is not added, it can be introduced in future versions. I will add a TODO note in the code.

Quoted 5 lines
Quoted 2 lines

Argh, no TODO please. Actual code that will turn this code into a solid driver that can be merged.

Does a driver targeted for a custom device has to implement every functionality in the 1st version ?

When you post a driver to the GPIO maintainers it is *NOT* tageted at a consumer device, it is targeted at the kernel community and upstream maintainers.

Of course you can deliver add-on patches out-of-tree to your customers, it's generally a bad idea for the long term and maintenance of your driver, but it's your pick.

Yours,
Linus Walleij

#7 lore raw
Quoted 28 lines · Linus Walleij
Quoted 27 lines · RR
Quoted 25 lines · Alexandre Courbot
Quoted 9 lines · Muthu Mani
Quoted 8 lines

drivers/gpio/gpio-cyusbs23x.c line 113

Quoted 4 lines
drivers/gpio/gpio-cyusbs23x.c new file +4 -0
+static int cy_gpio_direction_output(struct gpio_chip *chip,
+                                       unsigned offset, int value) {
+       return 0;
+}

If that chip is capable of both output and input, shouldn't these functions be implemented? I think this has already been pointed out in a previous version but you did not reply.

Quoted 3 lines

Thanks for your inputs.

Only the GPIOs which are configured to be output GPIO can be set.

In that case cy_gpio_set() should return an error for GPIOs which are not configured as outputs. Is that guaranteed by the current implementation?

Quoted 3 lines

The set operation would fail trying to set the input or unconfigured GPIOs.
In this version of driver, this support is not added, it can be introduced in future versions. I will add a TODO note in the code.

Argh, no TODO please. Actual code that will turn this code into a solid driver that can be merged.

Quoted 6 lines
Quoted 2 lines

Does a driver targeted for a custom device has to implement every functionality in the 1st version ?

When you post a driver to the GPIO maintainers it is *NOT* tageted at a consumer device, it is targeted at the kernel community and upstream maintainers.

Totally agree. What I was conveying the patch has not modified any "core" kernel function and is specific to a device thus will not affect system.

Quoted 4 lines

Of course you can deliver add-on patches out-of-tree to your customers, it's generally a bad idea for the long term and maintenance of your driver, but it's your pick.

AFAIR In the recent past xHCI or gadget core or musb or dw3 patches were added in increments. May be my analogy is incorrect and I am ignorant of some philosophy here.

Sincerely I somehow was not convinced basic functionality is missing as referred in the review comment.We have tested the driver for most of the functionality of our DVK and is working perfectly.

Moreover currently we do not expect an user to set gpio direction as it involves vendor specific usb control commands.

Having said that we have taken the feedback and working to close this.

Quoted 3 lines

Yours,
Linus Walleij