gpio: add support for Cypress CYUSBS234 USB-GPIO adapter
Subsystems (2)
PATCH 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.
Details about the device can be found at:
http://www.cypress.com/?rID=84126
--- drivers/gpio/Kconfig | 13 +++ drivers/gpio/Makefile | 1 + drivers/gpio/gpio-cyusbs23x.c | 190 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 204 insertions(+) create mode 100644 drivers/gpio/gpio-cyusbs23x.c
drivers/gpio/Kconfig +13 -0
@@ -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
@@ -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 +190 -0
190 lines not on this page · raw message
Signature · 1 line
1.8.3.2
Quoted 91 lines · Muthu Mani
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.
Details about the device can be found at:
http://www.cypress.com/?rID=84126Signed-off-by Muthu Mani <[email protected]>Signed-off-by Rajaram Regupathy <[email protected]>--- drivers/gpio/Kconfig | 13 +++ drivers/gpio/Makefile | 1 + drivers/gpio/gpio-cyusbs23x.c | 190 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 204 insertions(+) create mode 100644 drivers/gpio/gpio-cyusbs23x.cdrivers/gpio/Kconfig +13
-0@@ -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 && USBdrivers/gpio/Makefile +1
-0@@ -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.odrivers/gpio/gpio-cyusbs23x.c new file +31
-0@@ -0,0 +1,190 @@ +/* +* Cypress USB-Serial Bridge Controller GPIO driver +* +* Copyright (c) 2014 Cypress Semiconductor Corporation. +* +* Author: +* Muthu Mani <[email protected]> +* +* Additional contributors include: +* Rajaram Regupathy <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 as published by +* the Free Software Foundation. +*/ + +#include <linux/kernel.h> +#include <linux/errno.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/types.h> +#include <linux/mutex.h> +#include <linux/platform_device.h> + +#include <linux/usb.h> +#include <linux/gpio.h> + +#include <linux/mfd/cyusbs23x.h> + +#define CY_GPIO_GET_LEN (2) +
drivers/gpio/gpio-cyusbs23x.c line 41
Quoted 10 lines
drivers/gpio/gpio-cyusbs23x.c new file +10
-0+struct cyusbs_gpio { +struct gpio_chip gpio; +struct cyusbs23x *cyusbs; +}; + +static int cy_gpio_get (struct gpio_chip *chip, +unsigned offset) +{ +int ret; +char buf[CY_GPIO_GET_LEN ];
Buffers used for USB (DMA) transfers cannot be allocated on the stack. Use kmalloc and friends.
drivers/gpio/gpio-cyusbs23x.c line 42
Quoted 1 line
drivers/gpio/gpio-cyusbs23x.c new file +1
-0+__u16 wIndex, wValue;
u16 throughout.
Quoted 52 lines
drivers/gpio/gpio-cyusbs23x.c new file +52
-0+struct cyusbs_gpio *gpio = + container_of(chip, struct cyusbs_gpio, gpio); +struct cyusbs23x *cyusbs = gpio->cyusbs; + +dev_dbg (&cyusbs->usb_intf->dev,"%s: %d\n" , __func__, + offset); + wValue = offset; + wIndex =0 ; + +mutex_lock (&cyusbs->lock); + ret =usb_control_msg (cyusbs->usb_dev, +usb_rcvctrlpipe (cyusbs->usb_dev,0 ), +CY_GPIO_GET_VALUE_CMD , +USB_TYPE_VENDOR |USB_RECIP_DEVICE |USB_DIR_IN , + wValue, wIndex, buf,CY_GPIO_GET_LEN ,2000 ); +mutex_unlock (&cyusbs->lock); + +dev_dbg (&cyusbs->usb_intf->dev,"%s: %d %02x %02x\n" , __func__, + ret, buf[0 ], buf[1 ]); + +if (ret ==CY_GPIO_GET_LEN ) { +if (buf[0 ] ==0 ) + ret = buf[1 ]; +else + ret = -EINVAL ; + }else { + ret = -EREMOTEIO ; + } + +return ret; +} + +static void cy_gpio_set (struct gpio_chip *chip, +unsigned offset,int value) +{ +int ret; +__u16 wIndex, wValue; +struct cyusbs_gpio *gpio = + container_of(chip, struct cyusbs_gpio, gpio); +struct cyusbs23x *cyusbs = gpio->cyusbs; + +dev_dbg (&cyusbs->usb_intf->dev,"%s: %d\n" , __func__, + offset); + wValue = offset; + wIndex = value; + +mutex_lock (&cyusbs->lock); + ret =usb_control_msg (cyusbs->usb_dev, +usb_sndctrlpipe (cyusbs->usb_dev,0 ), +CY_GPIO_SET_VALUE_CMD , +USB_TYPE_VENDOR |USB_RECIP_DEVICE |USB_DIR_IN , + wValue, wIndex,NULL ,0 ,2000 );
drivers/gpio/gpio-cyusbs23x.c line 104
Quoted 10 lines
drivers/gpio/gpio-cyusbs23x.c new file +10
-0+mutex_unlock (&cyusbs->lock); + +if (ret <0 ) +dev_err (&cyusbs->usb_intf->dev,"error setting gpio:%d\n" , ret); +} + +static int cy_gpio_direction_input (struct gpio_chip *chip, +unsigned offset) +{ +return 0 ;
Aren't the GPIOs output-only?
Quoted 19 lines
drivers/gpio/gpio-cyusbs23x.c new file +19
-0+} + +static int cy_gpio_direction_output (struct gpio_chip *chip, +unsigned offset,int value) +{ +return 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 133
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 ="cyusbs23x gpio" ; + cy_gpio->gpio.dev = &pdev->dev; + cy_gpio->gpio.owner =THIS_MODULE ; + cy_gpio->gpio.base =-1 ; + cy_gpio->gpio.ngpio =12 ;/* total GPIOs */
I think you need to read out the gpio config from the device eeprom and implement a request() callback where you verify that a requested gpio is actually available (mode dependent, and there are never more than 10 gpios availble).
Quoted 40 lines
drivers/gpio/gpio-cyusbs23x.c new file +40
-0+ cy_gpio->gpio.can_sleep = true; + cy_gpio->gpio.set = cy_gpio_set; + cy_gpio->gpio.get = cy_gpio_get; + cy_gpio->gpio.direction_input = cy_gpio_direction_input; + cy_gpio->gpio.direction_output = cy_gpio_direction_output; + ret =gpiochip_add (&cy_gpio->gpio); +if (ret <0 ) { +dev_err (cy_gpio->gpio.dev,"could not add gpio" ); + goto error; + } + +platform_set_drvdata (pdev, cy_gpio); + +dev_dbg (&pdev->dev,"added GPIO\n" ); +return ret; + +error: +dev_dbg (&pdev->dev,"error occured %d\n" , ret); +return ret; +} + +static int cyusbs23x_gpio_remove (struct platform_device *pdev) +{ +struct cyusbs_gpio *cy_gpio =platform_get_drvdata (pdev); + +dev_dbg (&pdev->dev,"%s\n" , __func__); + +gpiochip_remove (&cy_gpio->gpio); + +return 0 ; +} + +static struct platform_driver cyusbs23x_gpio_driver = { + .driver.name ="cyusbs23x-gpio" , + .driver.owner =THIS_MODULE , + .probe = cyusbs23x_gpio_probe, + .remove = cyusbs23x_gpio_remove, +}; + +static int __init cyusbs23x_gpio_init (void )
drivers/gpio/gpio-cyusbs23x.c line 183
Quoted 10 lines
drivers/gpio/gpio-cyusbs23x.c new file +10
-0+{ +return platform_driver_register (&cyusbs23x_gpio_driver); +} +subsys_initcall (cyusbs23x_gpio_init); + +static void __exit cyusbs23x_gpio_exit(void) +{ +platform_driver_unregister (&cyusbs23x_gpio_driver); +} +module_exit (cyusbs23x_gpio_exit);
module_platform_driver
drivers/gpio/gpio-cyusbs23x.c line 188
Quoted 5 lines
drivers/gpio/gpio-cyusbs23x.c new file +5
-0+ +MODULE_AUTHOR ("Rajaram Regupathy <[email protected]>" ); +MODULE_AUTHOR ("Muthu Mani <[email protected]>" ); +MODULE_DESCRIPTION ("gpio-cyusbs23x driver v0.1" ); +MODULE_LICENSE ("GPL" );
Description and license comments from i2c patch apply here as well.
drivers/gpio/gpio-cyusbs23x.c line 190
Quoted 2 lines
drivers/gpio/gpio-cyusbs23x.c new file +2
-0+MODULE_ALIAS ("platform:cyusbs23x-gpio" ); +
Stray new line.
Johan
Quoted 110 lines
-----Original Message-----
From: Johan Hovold [mailto:[email protected]] On Behalf Of Johan Hovold
Sent: Monday, September 22, 2014 5:14 PM
To: Muthu Mani
Cc: Samuel Ortiz; Lee Jones; Wolfram Sang; [email protected]; Linus Walleij; Alexandre Courbot; [email protected]; [email protected]; [email protected]; linux- [email protected]; Rajaram Regupathy
Subject: Re: [PATCH 3/3] gpio: add support for Cypress CYUSBS234 USB-GPIO adapterQuoted 98 lines · Muthu Mani
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.
Details about the device can be found at:
http://www.cypress.com/?rID=84126Signed-off-by Muthu Mani <[email protected]>Signed-off-by Rajaram Regupathy <[email protected]>--- drivers/gpio/Kconfig | 13 +++ drivers/gpio/Makefile | 1 + drivers/gpio/gpio-cyusbs23x.c | 190 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 204 insertions(+) create mode 100644 drivers/gpio/gpio-cyusbs23x.cdrivers/gpio/Kconfig index renamed from drivers/gpio/Kconfig +0
-09de1515..932e07c 100644
drivers/gpio/Kconfig +13
-0@@ -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 diff --gita/drivers/gpio/Makefile b/drivers/gpio/Makefile index 5d024e3..3ad89f1 100644
drivers/gpio/Makefile +1
-0@@ -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(quoted diff) +0
-0
b/drivers/gpio/gpio-cyusbs23x.cnew file mode 100644 index 0000000..8aa3ab6drivers/gpio/gpio-cyusbs23x.c new file +37
-0@@ -0,0 +1,190 @@ +/* +* Cypress USB-Serial Bridge Controller GPIO driver +* +* Copyright (c) 2014 Cypress Semiconductor Corporation. +* +* Author: +* Muthu Mani <[email protected]> +* +* Additional contributors include: +* Rajaram Regupathy <[email protected]> +* +* This program is free software; you can redistribute it and/or +modify it +* under the terms of the GNU General Public License version 2 as +published by +* the Free Software Foundation. +*/ + +#include <linux/kernel.h> +#include <linux/errno.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/types.h> +#include <linux/mutex.h> +#include <linux/platform_device.h> + +#include <linux/usb.h> +#include <linux/gpio.h> + +#include <linux/mfd/cyusbs23x.h> + +#define CY_GPIO_GET_LEN (2) + +struct cyusbs_gpio { +struct gpio_chip gpio; +struct cyusbs23x *cyusbs; +};
Quoted 8 lines
drivers/gpio/gpio-cyusbs23x.c line 41
Quoted 5 lines
drivers/gpio/gpio-cyusbs23x.c new file +5
-0+ +static int cy_gpio_get (struct gpio_chip *chip, +unsigned offset) { +int ret; +char buf[CY_GPIO_GET_LEN ];Buffers used for USB (DMA) transfers cannot be allocated on the stack. Use kmalloc and friends.
Ok, will update it.
Quoted 4 lines
drivers/gpio/gpio-cyusbs23x.c line 43
Quoted 2 lines
drivers/gpio/gpio-cyusbs23x.c new file +1
-0+__u16 wIndex, wValue;u16 throughout.
Ok.
Quoted 55 lines
Quoted 55 lines
drivers/gpio/gpio-cyusbs23x.c new file +54
-0+struct cyusbs_gpio *gpio = + container_of(chip, struct cyusbs_gpio, gpio); +struct cyusbs23x *cyusbs = gpio->cyusbs; + +dev_dbg (&cyusbs->usb_intf->dev,"%s: %d\n" , __func__, + offset); + wValue = offset; + wIndex =0 ; + +mutex_lock (&cyusbs->lock); + ret =usb_control_msg (cyusbs->usb_dev, +usb_rcvctrlpipe (cyusbs->usb_dev,0 ), +CY_GPIO_GET_VALUE_CMD , +USB_TYPE_VENDOR |USB_RECIP_DEVICE |USB_DIR_IN , + wValue, wIndex, buf,CY_GPIO_GET_LEN ,2000 ); +mutex_unlock (&cyusbs->lock); + +dev_dbg (&cyusbs->usb_intf->dev,"%s: %d %02x %02x\n" , __func__, + ret, buf[0 ], buf[1 ]); + +if (ret ==CY_GPIO_GET_LEN ) { +if (buf[0 ] ==0 ) + ret = buf[1 ]; +else + ret = -EINVAL ; + }else { + ret = -EREMOTEIO ; + } + +return ret; +} + +static void cy_gpio_set (struct gpio_chip *chip, +unsigned offset,int value) { +int ret; +__u16 wIndex, wValue; +struct cyusbs_gpio *gpio = + container_of(chip, struct cyusbs_gpio, gpio); +struct cyusbs23x *cyusbs = gpio->cyusbs; + +dev_dbg (&cyusbs->usb_intf->dev,"%s: %d\n" , __func__, + offset); + wValue = offset; + wIndex = value; + +mutex_lock (&cyusbs->lock); + ret =usb_control_msg (cyusbs->usb_dev, +usb_sndctrlpipe (cyusbs->usb_dev,0 ), +CY_GPIO_SET_VALUE_CMD , +USB_TYPE_VENDOR |USB_RECIP_DEVICE |USB_DIR_IN , + wValue, wIndex,NULL ,0 ,2000 ); +mutex_unlock (&cyusbs->lock); + +if (ret <0 )
Quoted 8 lines
drivers/gpio/gpio-cyusbs23x.c line 104
Quoted 6 lines
drivers/gpio/gpio-cyusbs23x.c new file +6
-0+dev_err (&cyusbs->usb_intf->dev,"error setting +gpio:%d\n", ret); } + +static int cy_gpio_direction_input (struct gpio_chip *chip, +unsigned offset) { +return 0 ;Aren't the GPIOs output-only?
No.
Quoted 25 lines
Quoted 25 lines
drivers/gpio/gpio-cyusbs23x.c new file +24
-0+} + +static int cy_gpio_direction_output (struct gpio_chip *chip, +unsigned offset,int value) { +return 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 ); +if (cy_gpio ==NULL ) +return -ENOMEM ; + + cy_gpio->cyusbs = cyusbs; +/* registering gpio */ + cy_gpio->gpio.label ="cyusbs23x gpio" ; + cy_gpio->gpio.dev = &pdev->dev;
Quoted 8 lines
drivers/gpio/gpio-cyusbs23x.c line 133
Quoted 3 lines
drivers/gpio/gpio-cyusbs23x.c new file +3
-0+ cy_gpio->gpio.owner =THIS_MODULE ; + cy_gpio->gpio.base =-1 ; + cy_gpio->gpio.ngpio =12 ;/* total GPIOs */ I think you need to read out the gpio config from the device eeprom and implement a
request()callback where you verify that a requested gpio is actually available (mode dependent, and there are never more than 10 gpios availble).
In this initial driver, all GPIOs are made available to user space. Additional functionalities will be added in the next version of the driver.
Quoted 42 lines
Quoted 42 lines
drivers/gpio/gpio-cyusbs23x.c new file +41
-0+ cy_gpio->gpio.can_sleep = true; + cy_gpio->gpio.set = cy_gpio_set; + cy_gpio->gpio.get = cy_gpio_get; + cy_gpio->gpio.direction_input = cy_gpio_direction_input; + cy_gpio->gpio.direction_output = cy_gpio_direction_output; + ret =gpiochip_add (&cy_gpio->gpio); +if (ret <0 ) { +dev_err (cy_gpio->gpio.dev,"could not add gpio" ); + goto error; + } + +platform_set_drvdata (pdev, cy_gpio); + +dev_dbg (&pdev->dev,"added GPIO\n" ); +return ret; + +error: +dev_dbg (&pdev->dev,"error occured %d\n" , ret); +return ret; +} + +static int cyusbs23x_gpio_remove (struct platform_device *pdev) { +struct cyusbs_gpio *cy_gpio =platform_get_drvdata (pdev); + +dev_dbg (&pdev->dev,"%s\n" , __func__); + +gpiochip_remove (&cy_gpio->gpio); + +return 0 ; +} + +static struct platform_driver cyusbs23x_gpio_driver = { + .driver.name ="cyusbs23x-gpio" , + .driver.owner =THIS_MODULE , + .probe = cyusbs23x_gpio_probe, + .remove = cyusbs23x_gpio_remove, +}; + +static int __init cyusbs23x_gpio_init (void ) { +return platform_driver_register (&cyusbs23x_gpio_driver); +}
Quoted 8 lines
drivers/gpio/gpio-cyusbs23x.c line 183
Quoted 6 lines
drivers/gpio/gpio-cyusbs23x.c new file +6
-0+subsys_initcall (cyusbs23x_gpio_init); + +static void __exit cyusbs23x_gpio_exit(void) { +platform_driver_unregister (&cyusbs23x_gpio_driver); +} +module_exit (cyusbs23x_gpio_exit);
module_platform_driver
Ok.
Quoted 8 lines
drivers/gpio/gpio-cyusbs23x.c line 188
Quoted 6 lines
drivers/gpio/gpio-cyusbs23x.c new file +5
-0+ +MODULE_AUTHOR ("Rajaram Regupathy <[email protected]>" ); +MODULE_AUTHOR ("Muthu Mani <[email protected]>" ); +MODULE_DESCRIPTION ("gpio-cyusbs23x driver v0.1" ); +MODULE_LICENSE ("GPL" );Description and license comments from i2c patch apply here as well.
Ok, will update it.
Quoted 5 lines
drivers/gpio/gpio-cyusbs23x.c line 190
Quoted 3 lines
drivers/gpio/gpio-cyusbs23x.c new file +2
-0+MODULE_ALIAS ("platform:cyusbs23x-gpio" ); +Stray new line.
Ok, will remove it.
I will send the v2 patch soon.
Quoted 2 lines
Johan
Quoted 10 lines · Muthu Mani
Quoted 8 lines
-----Original Message-----
From: Johan Hovold [mailto:[email protected]] On Behalf Of Johan Hovolddrivers/gpio/gpio-cyusbs23x.c line 104
Quoted 3 lines
drivers/gpio/gpio-cyusbs23x.c new file +3
-0+static int cy_gpio_direction_input (struct gpio_chip *chip, +unsigned offset) { +return 0 ;Aren't the GPIOs output-only?
No.
Then you should implement this callback to configure the pin as an input.
Or can the configuration only be made through your configuration tools and stored in eeprom?
Then you need to retrieve the actual config and implement these callbacks (e.g. fail if not matching the eeprom config) along with get_direction().
Quoted 33 lines
Quoted 24 lines
Quoted 24 lines
drivers/gpio/gpio-cyusbs23x.c new file +24
-0+} + +static int cy_gpio_direction_output (struct gpio_chip *chip, +unsigned offset,int value) { +return 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 ); +if (cy_gpio ==NULL ) +return -ENOMEM ; + + cy_gpio->cyusbs = cyusbs; +/* registering gpio */ + cy_gpio->gpio.label ="cyusbs23x gpio" ; + cy_gpio->gpio.dev = &pdev->dev;Quoted 8 lines
drivers/gpio/gpio-cyusbs23x.c line 133
Quoted 3 lines
drivers/gpio/gpio-cyusbs23x.c new file +3
-0+ cy_gpio->gpio.owner =THIS_MODULE ; + cy_gpio->gpio.base =-1 ; + cy_gpio->gpio.ngpio =12 ;/* total GPIOs */ I think you need to read out the gpio config from the device eeprom and implement a
request()callback where you verify that a requested gpio is actually available (mode dependent, and there are never more than 10 gpios availble).
Quoted 2 lines
In this initial driver, all GPIOs are made available to user space. Additional functionalities will be added in the next version of the driver.
I think this needs to be implemented now. It's needed for direction handling as well as mentioned above.
Quoted 10 lines
Quoted 10 lines
drivers/gpio/gpio-cyusbs23x.c line 143
Quoted 10 lines
drivers/gpio/gpio-cyusbs23x.c new file +10
-0+ cy_gpio->gpio.can_sleep = true; + cy_gpio->gpio.set = cy_gpio_set; + cy_gpio->gpio.get = cy_gpio_get; + cy_gpio->gpio.direction_input = cy_gpio_direction_input; + cy_gpio->gpio.direction_output = cy_gpio_direction_output; + ret =gpiochip_add (&cy_gpio->gpio); +if (ret <0 ) { +dev_err (cy_gpio->gpio.dev,"could not add gpio" ); + goto error; + }
Thanks,
Johan