gpio: Add block GPIO
Subsystems (11)
v14 cover gpio: Add block GPIO
This set of patches adds:
* Block GPIO API to gpiolib
* Sysfs support for GPIO API, to provide userland access
* Device interface for userland access (alternative to sysfs)
* Devicetree support to instantiate GPIO blocks via DT
* Example implementations in several gpio drivers since they need special accessor functions for block wise GPIO access (only for some selected drivers since the feature is optional and not suitable for all GPIO hardware)
* Fix for race condition in gpiolib on device creation
Tested by: Wolfgang Grandegger <[email protected]> --
Testing branch available at: git://git.antcom.de/linux-2.6.git blockgpio
Applies to v3.8-rc4
Changes since v13:
* Adjusted __raw_readl to readl_relaxed, __raw_writel to writel_relaxed (forward porting of pinctrl-at91.c)
* Adjusted to mainline change: Removed __devinit and __devinitdata
Changes since v12:
* Added support for gpio drivers ge, ks8695, mc33880, ml-ioh, mpc5200 and mpc8xxx
* Added support for pinctrl driver at91
Changes since v11:
* Removed support for at91, since this one is currently in the migration process to pinctrl implementation
* Fixed mask setting via sysfs
* Device interface: declare gpio_block_fop_poll() static
Changes since v10:
* gpioblock-of.c: Catch <1 specified GPIOs
* gpioblock-of.c: Fixed memory leak in probe()'s error path
* gpioblock-of.c: Fixed block node's refcount via of_node_put()
* Added driver support for samsung, mm-lantiq and sa1100
* Added driver support for at91 (by Wolfgang Grandegger)
* Added pinctrl driver support for pinctl-nomadik
Changed since v9:
* Changed IRQ flags for device interface's poll() from IRQF_TRIGGER_FALLING to IRQF_SHARED
* Use block name on gpio_request
* Added spinlock for ISR manipulated data (dev interface / poll())
Changed since v8:
* Added poll() function to dev interface for IRQ handling
* Fixed gpio_block_register() in case of missing CONFIG_GPIO_SYSFS
* Fixed mask handling in sysfs interface
* Fixed get_user/put_user pointer (cast)
Changes since v7:
* Fixed error in API documentation (name arg missing in prototype)
* Fixed compile error if sysfs is missing: Moved gpio_block_is_output() out of sysfs-ifdef
* Added error handling to gpio_block_register()
* Added mask attribute to sysfs (although dev interface exists now)
Changes since v6:
* Changed realloc to list handling
* Added mask to kernel API
* Added device interface as userspace API
* Changed sizeof() to BITS_PER_LONG
* Fixed multiline comment style
* Documented direction setting by the user
* Documented order of handled chips in case of multiple chips in one block
Changes since v5:
* Documented sysfs: elaborated on "exported" and "values" attributes
* Documented sysfs: gpiochip is a separate class now
* Aggregated driver support patches for block gpio into one single patch
* Added gpio block driver support for twl6040 and pch
Changes since v4:
* Documented word width
* Bugfix: export/unexport on register/unregister
* Using default dev_attrs for gpio_block_class
* Fix gpiolib: race condition on device creation
* Added driver support for ucb14500, vt8500, xilinx
Changes since v3:
* Added driver support for pca953x, em, pl061, max732x, pcf857x
* Coding style improvements
* Fixed krealloc memory leak in error case
* sysfs: values in hex
* Register blocks in a list
* Narrowing lock scope
* Use S_IWUSR and S_IRUGO instead of direct octal values
* Use for_each_set_bit()
* Change from unsigned to unsigned long for masks and values
Changes since v2:
* Added sysfs support
* Added devicetree support
* Added support for lpc32xx, generic
* Added functions for GPIO block registration
* Added more error checking
* Bit remapping bugfix
Changes since v1:
* API change to 32/64 bit word, bit masks
Thanks to Ryan Mallon, Linus Walleij, Stijn Devriendt, Jean-Christophe Plagniol-Villard, Mark Brown, Greg Kroah-Hartman, Grant Likely, Stefan Roese, Wolfgang Grandegger, Tobias Rutz, Fengguang Wu, Mark Rutland and Nicolas Ferre for reviewing and testing!
Roland Stigge (6):
gpio: Add a block GPIO API to gpiolib
gpio: Add sysfs support to block GPIO API
gpio: Add userland device interface to block GPIO
gpiolib: Fix default attributes for class
gpio: Add device tree support to block GPIO API
gpio: Add block gpio to several gpio drivers
Documentation/ABI/testing/dev-gpioblock | 34 Documentation/ABI/testing/sysfs-gpio | 31 Documentation/devicetree/bindings/gpio/gpio-block.txt | 36 Documentation/gpio.txt | 58 + drivers/gpio/Kconfig | 2 drivers/gpio/Makefile | 1 drivers/gpio/gpio-em.c | 23 drivers/gpio/gpio-ge.c | 29 drivers/gpio/gpio-generic.c | 56 + drivers/gpio/gpio-ks8695.c | 34 drivers/gpio/gpio-lpc32xx.c | 82 + drivers/gpio/gpio-max730x.c | 61 + drivers/gpio/gpio-max732x.c | 59 + drivers/gpio/gpio-mc33880.c | 16 drivers/gpio/gpio-ml-ioh.c | 27 drivers/gpio/gpio-mm-lantiq.c | 22 drivers/gpio/gpio-mpc5200.c | 64 + drivers/gpio/gpio-mpc8xxx.c | 41 drivers/gpio/gpio-pca953x.c | 64 + drivers/gpio/gpio-pcf857x.c | 24 drivers/gpio/gpio-pch.c | 27 drivers/gpio/gpio-pl061.c | 17 drivers/gpio/gpio-sa1100.c | 20 drivers/gpio/gpio-samsung.c | 31 drivers/gpio/gpio-twl6040.c | 32 drivers/gpio/gpio-ucb1400.c | 23 drivers/gpio/gpio-vt8500.c | 24 drivers/gpio/gpio-xilinx.c | 44 + drivers/gpio/gpioblock-of.c | 100 ++ drivers/gpio/gpiolib.c | 782 ++++++++++++++++-- drivers/pinctrl/pinctrl-at91.c | 29 drivers/pinctrl/pinctrl-nomadik.c | 36 include/asm-generic/gpio.h | 28 include/linux/gpio.h | 125 ++ 34 files changed, 2035 insertions(+), 47 deletions(-)
PATCH v14 1/6 gpio: Add a block GPIO API to gpiolib
The recurring task of providing simultaneous access to GPIO lines (especially for bit banging protocols) needs an appropriate API.
This patch adds a kernel internal "Block GPIO" API that enables simultaneous access to several GPIOs. This is done by abstracting GPIOs to an n-bit word:
Once requested, it provides access to a group of GPIOs which can range over multiple GPIO chips.
---
Documentation/gpio.txt | 58 +++++++++++ drivers/gpio/gpiolib.c | 227 +++++++++++++++++++++++++++++++++++++++++++++ include/asm-generic/gpio.h | 17 +++ include/linux/gpio.h | 97 +++++++++++++++++++ 4 files changed, 399 insertions(+)
Documentation/gpio.txt +58 -0
@@ -481,6 +481,64 @@ exact name string of pinctrl device has argument to this routine. +Block GPIO +---------- + +The above described interface concentrates on handling single GPIOs. However, +in applications where it is critical to set several GPIOs at once, this +interface doesn't work well, e.g. bit-banging protocols via grouped GPIO lines. +Consider a GPIO controller that is connected via a slow I2C line. When +switching two or more GPIOs one after another, there can be considerable time +between those events. This is solved by an interface called Block GPIO: + +struct gpio_block *gpio_block_create(unsigned int *gpios, size_t size, + const char *name); + +This creates a new block of GPIOs as a list of GPIO numbers with the specified +size which are accessible via the returned struct gpio_block and the accessor +functions described below. Please note that you need to request the GPIOs +separately via gpio_request(). Similarly, the direction of the used GPIOs need +to be set by the user before using the block. An arbitrary list of globally +valid GPIOs can be specified, even ranging over several gpio_chips. Actual +handling of I/O operations will be done on a best effort base, i.e. +simultaneous I/O only where possible by hardware and implemented in the +respective GPIO driver. The number of GPIOs in one block is limited to the +number of bits in an unsigned long, or BITS_PER_LONG, of the respective +platform, i.e. typically at least 32 on a 32 bit system, and at least 64 on a +64 bit system. However, several blocks can be defined at once. + +unsigned long gpio_block_get(struct gpio_block *block, unsigned long mask); +void gpio_block_set(struct gpio_block *block, unsigned long mask, + unsigned long values); + +With those accessor functions, setting and getting the GPIO values is possible, +analogous to gpio_get_value() and gpio_set_value(). Each bit in the return +value of gpio_block_get() and in the value argument of gpio_block_set() +corresponds to a bit specified on gpio_block_create(). The mask parameters +specify which bits in the block are acted upon. This is useful to let some bits +untouched when doing a set operation on the block. + +Block operations in hardware are only possible where the respective GPIO driver +implements it, falling back to using single GPIO operations where the driver +only implements single GPIO access. + +If a GPIO block includes GPIOs from several chips, the chips are handled one +after another in the order of first specification in the list of GPIOs defined +in the GPIO block, starting with bit 0. Note that in this case, you typically +can't assume simultaneous access. + +void gpio_block_free(struct gpio_block *block); + +After the GPIO block isn't used anymore, it should be free'd via +gpio_block_free(). + +int gpio_block_register(struct gpio_block *block); +void gpio_block_unregister(struct gpio_block *block); + +These functions can be used to register a GPIO block. Blocks registered this +way will be available via userspace API. + + What do these conventions omit? =============================== One of the biggest things these conventions omit is pin multiplexing, since
drivers/gpio/gpiolib.c +227 -0
245 lines not on this page · raw message
include/asm-generic/gpio.h +17 -0
@@ -44,6 +44,7 @@ static inline bool gpio_is_valid(int numstruct device ;struct gpio ; +struct gpio_block ;struct seq_file ;struct module ;struct device_node ;
@@ -109,6 +110,8 @@ struct gpio_chip { unsigned offset);int (*get)(struct gpio_chip *chip,unsigned offset); +unsigned long (*get_block)(struct gpio_chip *chip, +unsigned long mask);int (*direction_output)(struct gpio_chip *chip,unsigned offset,int value); int (*set_debounce)(struct gpio_chip *chip,
@@ -116,6 +119,9 @@ struct gpio_chip {void (*set)(struct gpio_chip *chip,unsigned offset,int value); +void (*set_block)(struct gpio_chip *chip, +unsigned long mask, +unsigned long values);int (*to_irq)(struct gpio_chip *chip,unsigned offset);
@@ -184,6 +190,17 @@ extern void gpio_set_value_cansleep(unsiextern int __gpio_get_value (unsigned gpio);extern void __gpio_set_value (unsigned gpio,int value); +extern struct gpio_block *gpio_block_create (unsigned *gpio,size_t size, +const char *name); +extern void gpio_block_free (struct gpio_block *block); +extern unsigned long gpio_block_get (const struct gpio_block *block, +unsigned long mask); +extern void gpio_block_set (struct gpio_block *block,unsigned long mask, +unsigned long values); +extern struct gpio_block *gpio_block_find_by_name (const char *name); +extern int gpio_block_register (struct gpio_block *block); +extern void gpio_block_unregister (struct gpio_block *block); +extern int __gpio_cansleep (unsigned gpio);extern int __gpio_to_irq (unsigned gpio);
include/linux/gpio.h +97 -0
115 lines not on this page · raw message
Re: [PATCH 1/6 v14] gpio: Add a block GPIO API to gpiolib
Quoted 31 lines · Roland Stigge
The recurring task of providing simultaneous access to GPIO lines (especially for bit banging protocols) needs an appropriate API.
This patch adds a kernel internal "Block GPIO" API that enables simultaneous access to several GPIOs. This is done by abstracting GPIOs to an n-bit word:
Once requested, it provides access to a group of GPIOs which can range over multiple GPIO chips.Signed-off-by Roland Stigge <[email protected]>---
Documentation/gpio.txt | 58 +++++++++++ drivers/gpio/gpiolib.c | 227 +++++++++++++++++++++++++++++++++++++++++++++ include/asm-generic/gpio.h | 17 +++ include/linux/gpio.h | 97 +++++++++++++++++++ 4 files changed, 399 insertions(+)Documentation/gpio.txt +8
-0@@ -481,6 +481,64 @@ exact name string of pinctrl device has argument to this routine. +Block GPIO +---------- + +The above described interface concentrates on handling single GPIOs. However, +in applications where it is critical to set several GPIOs at once, this +interface doesn't work well, e.g. bit-banging protocols via grouped GPIO lines. +Consider a GPIO controller that is connected via a slow I2C line. When +switching two or more GPIOs one after another, there can be considerable time
Documentation/gpio.txt exact name string of pinctrl device has · line 501
Quoted 10 lines
Documentation/gpio.txt +10
-0+between those events. This is solved by an interface called Block GPIO: + +struct gpio_block *gpio_block_create(unsigned int *gpios, size_t size, + const char *name); + +This creates a new block of GPIOs as a list of GPIO numbers with the specified +size which are accessible via the returned struct gpio_block and the accessor +functions described below. Please note that you need to request the GPIOs +separately via gpio_request(). Similarly, the direction of the used GPIOs need +to be set by the user before using the block.
Is there anything holding you back from letting gpio_block_create() do the request
for all the pins?
Also, wouldn't it make sense to have a gpio_block_direction_input() and _output()
variant? On the other hand, for things like I2C and SPI emulation, some pins will
naturally be always output (like clock lines) while other could be switched between
in and output (like the i2c data line).
Regards,
Stijn
Quoted 461 lines
Documentation/gpio.txt +41
-0+An arbitrary list of globally +valid GPIOs can be specified, even ranging over several gpio_chips. Actual +handling of I/O operations will be done on a best effort base, i.e. +simultaneous I/O only where possible by hardware and implemented in the +respective GPIO driver. The number of GPIOs in one block is limited to the +number of bits in an unsigned long, or BITS_PER_LONG, of the respective +platform, i.e. typically at least 32 on a 32 bit system, and at least 64 on a +64 bit system. However, several blocks can be defined at once. + +unsigned long gpio_block_get(struct gpio_block *block, unsigned long mask); +void gpio_block_set(struct gpio_block *block, unsigned long mask, + unsigned long values); + +With those accessor functions, setting and getting the GPIO values is possible, +analogous to gpio_get_value() and gpio_set_value(). Each bit in the return +value of gpio_block_get() and in the value argument of gpio_block_set() +corresponds to a bit specified on gpio_block_create(). The mask parameters +specify which bits in the block are acted upon. This is useful to let some bits +untouched when doing a set operation on the block. + +Block operations in hardware are only possible where the respective GPIO driver +implements it, falling back to using single GPIO operations where the driver +only implements single GPIO access. + +If a GPIO block includes GPIOs from several chips, the chips are handled one +after another in the order of first specification in the list of GPIOs defined +in the GPIO block, starting with bit 0. Note that in this case, you typically +can't assume simultaneous access. + +void gpio_block_free(struct gpio_block *block); + +After the GPIO block isn't used anymore, it should be free'd via +gpio_block_free(). + +int gpio_block_register(struct gpio_block *block); +void gpio_block_unregister(struct gpio_block *block); + +These functions can be used to register a GPIO block. Blocks registered this +way will be available via userspace API. + + What do these conventions omit? =============================== One of the biggest things these conventions omit is pin multiplexing, sincedrivers/gpio/gpiolib.c +227
-0@@ -83,6 +83,8 @@ static inline void desc_set_label(struct#endif } +static LIST_HEAD (gpio_block_list); +/* Warn when drivers omit gpio_request() calls -- legal but ill-advised * when setting direction, and otherwise illegal. Until board setup code * and drivers use explicit requests everywhere (which won't happen when @@ -217,6 +219,16 @@ static int gpio_get_direction(unsigned greturn status; } +static bool gpio_block_is_output (struct gpio_block *block) +{ +int i; + +for (i =0 ; i < block->ngpio; i++) +if (!test_bit (FLAG_IS_OUT , &gpio_desc[block->gpio[i]].flags)) +return false; +return true; +} +#ifdef CONFIG_GPIO_SYSFS /* lock protects against unexport_gpio() being called while @@ -1799,6 +1811,221 @@ void __gpio_set_value(unsigned gpio, int }EXPORT_SYMBOL_GPL (__gpio_set_value); +static struct gpio_block_chip *gpio_block_chip_get (struct gpio_block *block, +struct gpio_chip *gc) +{ +struct gpio_block_chip *i; + +list_for_each_entry (i, &block->gbc_list, list) +if (i->gc == gc) +return i; +return NULL ; +} + +struct gpio_block *gpio_block_create (unsigned *gpios,size_t size, +const char *name) +{ +struct gpio_block *block; +struct gpio_block_chip *gbc; +struct gpio_remap *remap; +int i; + +if (size <1 || size >BITS_PER_LONG ) +return ERR_PTR (-EINVAL ); + +for (i =0 ; i < size; i++) +if (!gpio_is_valid (gpios[i])) +return ERR_PTR (-EINVAL ); + + block =kzalloc (sizeof (struct gpio_block ),GFP_KERNEL ); +if (!block) +return ERR_PTR (-ENOMEM ); + + block->name = name; + block->ngpio = size; +INIT_LIST_HEAD (&block->gbc_list); + block->gpio =kzalloc (sizeof (*block->gpio) * size,GFP_KERNEL ); +if (!block->gpio) + goto err; + +memcpy (block->gpio, gpios,sizeof (*block->gpio) * size); + +for (i =0 ; i < size; i++) { +struct gpio_chip *gc =gpio_to_chip (gpios[i]); +int bit = gpios[i] - gc->base; + gbc =gpio_block_chip_get (block, gc); + +if (!gbc) { + gbc =kzalloc (sizeof (struct gpio_block_chip ), +GFP_KERNEL ); +if (!gbc) + goto err; +list_add_tail (&gbc->list, &block->gbc_list); + gbc->gc = gc; +INIT_LIST_HEAD (&gbc->remap_list); + } + +/* +* represents the mask necessary on calls to the driver's +* .get_block() and .set_block() +*/ + gbc->mask |=BIT (bit); + +/* +* collect gpios that are specified together, represented by +* neighboring bits +* +* get last element and create new element if list empty or +* new element necessary +*/ + remap = list_entry(gbc->remap_list.prev, struct gpio_remap, + list); +if (list_empty (&gbc->remap_list) || + (bit - i != remap->offset)) { + remap =kzalloc (sizeof (struct gpio_remap ),GFP_KERNEL ); +if (!remap) + goto err; +list_add_tail (&remap->list, &gbc->remap_list); + remap->offset = bit - i; + } + +/* +* represents the mask necessary for bit reordering between +* gpio_block (i.e. as specified on gpio_block_get() and +* gpio_block_set()) and gpio_chip domain (i.e. as specified on +* the driver's .set_block() and .get_block()) +*/ + remap->mask |=BIT (i); + } + +return block; +err: +gpio_block_free (block); +return ERR_PTR (-ENOMEM ); +} +EXPORT_SYMBOL_GPL (gpio_block_create); + +void gpio_block_free (struct gpio_block *block) +{ +struct list_head *i, *itmp, *j, *jtmp; +struct gpio_block_chip *gbc; +struct gpio_remap *remap; + +list_for_each_safe (i, itmp, &block->gbc_list) { + gbc = list_entry(i, struct gpio_block_chip, list); +list_del (i); +list_for_each_safe (j, jtmp, &gbc->remap_list) { + remap = list_entry(j, struct gpio_remap, list); +list_del (j); +kfree (remap); + } +kfree (gbc); + } + +kfree (block->gpio); +kfree (block); +} +EXPORT_SYMBOL_GPL (gpio_block_free); + +unsigned long gpio_block_get (const struct gpio_block *block,unsigned long mask) +{ +struct gpio_block_chip *gbc; +unsigned long values =0 ; + +list_for_each_entry (gbc, &block->gbc_list, list) { +struct gpio_remap *remap; +int i; +unsigned long remapped =0 ; +unsigned long remapped_mask =0 ; + +list_for_each_entry (remap, &gbc->remap_list, list) + remapped_mask |= (mask & remap->mask) << remap->offset; + remapped_mask &= gbc->mask; + +if (!remapped_mask) +continue ; + +if (gbc->gc->get_block) + remapped = gbc->gc->get_block (gbc->gc, remapped_mask); +else +/* emulate */ +for_each_set_bit (i, &remapped_mask,BITS_PER_LONG ) + remapped |= gbc->gc->get (gbc->gc, + gbc->gc->base + i) << i; + +list_for_each_entry (remap, &gbc->remap_list, list) + values |= (remapped >> remap->offset) & remap->mask; + } + +return values; +} +EXPORT_SYMBOL_GPL (gpio_block_get); + +void gpio_block_set (struct gpio_block *block,unsigned long mask, +unsigned long values) +{ +struct gpio_block_chip *gbc; + +list_for_each_entry (gbc, &block->gbc_list, list) { +struct gpio_remap *remap; +int i; +unsigned long remapped =0 ; +unsigned long remapped_mask =0 ; + +list_for_each_entry (remap, &gbc->remap_list, list) { + remapped |= (values & remap->mask) << remap->offset; + remapped_mask |= (mask & remap->mask) << remap->offset; + } + remapped_mask &= gbc->mask; + +if (!remapped_mask) +continue ; + +if (gbc->gc->set_block) + gbc->gc->set_block (gbc->gc, remapped_mask, remapped); +else +/* emulate */ +for_each_set_bit (i, &remapped_mask,BITS_PER_LONG ) + gbc->gc->set (gbc->gc, gbc->gc->base + i, + (remapped >> i) &1 ); + } +} +EXPORT_SYMBOL_GPL (gpio_block_set); + +struct gpio_block *gpio_block_find_by_name (const char *name) +{ +struct gpio_block *i; + +list_for_each_entry (i, &gpio_block_list, list) +if (!strcmp (i->name, name)) +return i; +return NULL ; +} +EXPORT_SYMBOL_GPL (gpio_block_find_by_name); + +int gpio_block_register (struct gpio_block *block) +{ +if (gpio_block_find_by_name (block->name)) +return -EBUSY ; + +list_add (&block->list, &gpio_block_list); + +return 0 ; +} +EXPORT_SYMBOL_GPL (gpio_block_register); + +void gpio_block_unregister (struct gpio_block *block) +{ +struct gpio_block *i; + +list_for_each_entry (i, &gpio_block_list, list) +if (i == block) { +list_del (&i->list); +break ; + } +} +EXPORT_SYMBOL_GPL (gpio_block_unregister); +/** * __gpio_cansleep() - report whether gpio value access will sleep * @gpio: gpio in question include/asm-generic/gpio.h +17
-0@@ -44,6 +44,7 @@ static inline bool gpio_is_valid(int numstruct device ;struct gpio ; +struct gpio_block ;struct seq_file ;struct module ;struct device_node ;@@ -109,6 +110,8 @@ struct gpio_chip { unsigned offset);int (*get)(struct gpio_chip *chip,unsigned offset); +unsigned long (*get_block)(struct gpio_chip *chip, +unsigned long mask);int (*direction_output)(struct gpio_chip *chip,unsigned offset,int value); int (*set_debounce)(struct gpio_chip *chip,@@ -116,6 +119,9 @@ struct gpio_chip {void (*set)(struct gpio_chip *chip,unsigned offset,int value); +void (*set_block)(struct gpio_chip *chip, +unsigned long mask, +unsigned long values);int (*to_irq)(struct gpio_chip *chip,unsigned offset);@@ -184,6 +190,17 @@ extern void gpio_set_value_cansleep(unsiextern int __gpio_get_value (unsigned gpio);extern void __gpio_set_value (unsigned gpio,int value); +extern struct gpio_block *gpio_block_create (unsigned *gpio,size_t size, +const char *name); +extern void gpio_block_free (struct gpio_block *block); +extern unsigned long gpio_block_get (const struct gpio_block *block, +unsigned long mask); +extern void gpio_block_set (struct gpio_block *block,unsigned long mask, +unsigned long values); +extern struct gpio_block *gpio_block_find_by_name (const char *name); +extern int gpio_block_register (struct gpio_block *block); +extern void gpio_block_unregister (struct gpio_block *block); +extern int __gpio_cansleep (unsigned gpio);extern int __gpio_to_irq (unsigned gpio);include/linux/gpio.h +97
-0@@ -2,6 +2,8 @@#define __LINUX_GPIO_H#include <linux/errno.h> +#include <linux/types.h> +#include <linux/list.h> /* see Documentation/gpio.txt */ @@ -39,6 +41,64 @@ struct gpio {const char *label; }; +/** +* struct gpio_remap - a structure for describing a bit mapping +* @mask: a bit mask, relevant for a (partial) mapping +* @offset: how many bits to shift to the left (negative: to the right) +* @list: several remappings are internally collected in a list +* +* When we are mapping bit values from one word to another (here: from GPIO +* block domain to GPIO driver domain) we first mask them out with mask and +* shift them as specified with offset. More complicated mappings are done by +* grouping several of those structs and adding the results together. +*/ +struct gpio_remap { +unsigned long mask; +int offset; + +struct list_head list; +}; + +/** +* struct gpio_block_chip - a structure representing chip specific data in a +* gpio block +* @gc: the chip +* @remap_list: list of remappings, there are several necessary if the bits +* are not consecutive +* @mask: chip specific mask, used for propagating to the driver's +* get_block() and set_block() functions +* @list: list collecting potentially multiple chips in one block +* +* This structure holds information about remapping and masking of gpios within +* one chip. There can be several of those in one block. +*/ +struct gpio_block_chip { +struct gpio_chip *gc; +struct list_head remap_list; +unsigned long mask; + +struct list_head list; +}; + +/** +* struct gpio_block - a structure describing a list of GPIOs for simultaneous +* operations +* @gbc_list: list of chips in this block, typically just one +* @name: the name of this block +* @ngpio: number of gpios in this block +* @gpio: list of gpios in this block +* @list: global list of blocks, maintained by gpiolib +*/ +struct gpio_block { +struct list_head gbc_list; +const char *name; + +int ngpio; +unsigned *gpio; + +struct list_head list; +}; +#ifdef CONFIG_GENERIC_GPIO #ifdef CONFIG_ARCH_HAVE_CUSTOM_GPIO_H @@ -169,6 +229,43 @@ static inline void gpio_set_value(unsignWARN_ON (1 ); } +static inline +struct gpio_block *gpio_block_create (unsigned *gpios,size_t size, +const char *name) +{ +WARN_ON (1 ); +return NULL ; +} + +static inline void gpio_block_free (struct gpio_block *block) +{ +WARN_ON (1 ); +} + +static inline unsigned long gpio_block_get (const struct gpio_block *block, +unsigned long mask) +{ +WARN_ON (1 ); +return 0 ; +} + +static inline void gpio_block_set (struct gpio_block *block,unsigned long mask, +unsigned long values) +{ +WARN_ON (1 ); +} + +static inline int gpio_block_register (struct gpio_block *block) +{ +WARN_ON (1 ); +return 0 ; +} + +static inline void gpio_block_unregister (struct gpio_block *block) +{ +WARN_ON (1 ); +} +static inline int gpio_cansleep (unsigned gpio) {/* GPIO can never have been requested or set as {in,out}put */
Re: [PATCH 1/6 v14] gpio: Add a block GPIO API to gpiolib
Quoted 14 lines · Stijn Devriendt
Quoted 14 lines
Documentation/gpio.txt +14
-0+Block GPIO +---------- + +The above described interface concentrates on handling single GPIOs. However, +in applications where it is critical to set several GPIOs at once, this +interface doesn't work well, e.g. bit-banging protocols via grouped GPIO lines. +Consider a GPIO controller that is connected via a slow I2C line. When +switching two or more GPIOs one after another, there can be considerable time +between those events. This is solved by an interface called Block GPIO: + +struct gpio_block *gpio_block_create(unsigned int *gpios, size_t size, + const char *name); + +This creates a new block of GPIOs as a list of GPIO numbers with the specified
Quoted 8 lines
Documentation/gpio.txt exact name string of pinctrl device has
Quoted 4 lines
Documentation/gpio.txt +4
-0+size which are accessible via the returned struct gpio_block and the accessor +functions described below. Please note that you need to request the GPIOs +separately via gpio_request(). Similarly, the direction of the used GPIOs need +to be set by the user before using the block.Is there anything holding you back from letting
gpio_block_create()do the request
for all the pins?
It's analoguous to plain GPIOs: They exist, but are not requested (by whom?) by default.
Quoted 7 lines
Also, wouldn't it make sense to have a
gpio_block_direction_input()and_output()
variant? On the other hand, for things like I2C and SPI emulation, some pins will
naturally be always output (like clock lines) while other could be switched between
in and output (like the i2c data line).
Right. Current implementation emphasizes on switching, not direction or other convenience functions, which could be added, nevertheless.
Roland
Re: [PATCH 1/6 v14] gpio: Add a block GPIO API to gpiolib
Quoted 24 lines · Roland Stigge
Quoted 14 lines · Stijn Devriendt
Quoted 14 lines
Documentation/gpio.txt +14
-0+Block GPIO +---------- + +The above described interface concentrates on handling single GPIOs. However, +in applications where it is critical to set several GPIOs at once, this +interface doesn't work well, e.g. bit-banging protocols via grouped GPIO lines. +Consider a GPIO controller that is connected via a slow I2C line. When +switching two or more GPIOs one after another, there can be considerable time +between those events. This is solved by an interface called Block GPIO: + +struct gpio_block *gpio_block_create(unsigned int *gpios, size_t size, + const char *name); + +This creates a new block of GPIOs as a list of GPIO numbers with the specifiedQuoted 8 lines
Documentation/gpio.txt exact name string of pinctrl device has
Quoted 4 lines
Documentation/gpio.txt +4
-0+size which are accessible via the returned struct gpio_block and the accessor +functions described below. Please note that you need to request the GPIOs +separately via gpio_request(). Similarly, the direction of the used GPIOs need +to be set by the user before using the block.Is there anything holding you back from letting
gpio_block_create()do the request
for all the pins?
Quoted 3 lines
It's analoguous to plain GPIOs: They exist, but are not requested (by whom?) by default.
This is one of the warts of the GPIO API, if you ask me (and probably others too).
Using a resource without allocating it first is just asking for trouble. It's one of those
things pinctl was designed to solve... I've been thinking about spending spare time
sending out patches converting all implicit requests and then removing the implicit
request, but spare time is limited...
Regards,
Stijn
Quoted 12 lines
Quoted 7 lines
Also, wouldn't it make sense to have a
gpio_block_direction_input()and_output()
variant? On the other hand, for things like I2C and SPI emulation, some pins will
naturally be always output (like clock lines) while other could be switched between
in and output (like the i2c data line).Right. Current implementation emphasizes on switching, not direction or other convenience functions, which could be added, nevertheless.
Roland
Re: [PATCH 1/6 v14] gpio: Add a block GPIO API to gpiolib
Quoted 9 lines · Stijn Devriendt
This is one of the warts of the GPIO API, if you ask me (and probably others too).
Using a resource without allocating it first is just asking for trouble. It's one of those
things pinctl was designed to solve... I've been thinking about spending spare time
sending out patches converting all implicit requests and then removing the implicit
request, but spare time is limited...
It would be much appreciated. We can make good use of all help we can get in this area...
Yours,
Linus Walleij
PATCH v14 2/6 gpio: Add sysfs support to block GPIO API
In reply to Roland StiggeThis patch adds sysfs support to the block GPIO API.
--- Documentation/ABI/testing/sysfs-gpio | 20 ++ drivers/gpio/gpiolib.c | 252 ++++++++++++++++++++++++++++++++++- include/asm-generic/gpio.h | 11 + include/linux/gpio.h | 15 ++ 4 files changed, 297 insertions(+), 1 deletion(-)
Documentation/ABI/testing/sysfs-gpio +20 -0
@@ -25,3 +25,23 @@ Description: /label ... (r/o) descriptive, not necessarily unique /ngpio ... (r/o) number of GPIOs; numbered N to N + (ngpio - 1) +What: /sys/class/gpioblock/ +Date: October 2012 +KernelVersion: 3.7 +Contact: Roland Stigge <[email protected]> +Description: + + Block GPIO devices are visible in sysfs as soon as they are registered + (e.g. via devicetree definition). For actual I/O use, their "exported" + boolean attribute must be set to "1". Then, the attribute "values" is + created and at the same time, the GPIOs in the block are requested for + exclusive use by sysfs. + + /sys/class/gpioblock + /BLOCKNAME ... for each GPIO block name + /ngpio ... (r/o) number of GPIOs in this group + /exported ... sysfs export state of this group (0, 1) + /value ... current value as 32 or 64 bit integer in hex + (only available if /exported is 1) + /mask ... current mask as 32 or 64 bit integer in hex + (only available if /exported is 1)
drivers/gpio/gpiolib.c +251 -1
294 lines not on this page · raw message
include/asm-generic/gpio.h +11 -0
@@ -226,6 +226,8 @@ extern int gpio_export_link(struct devic unsigned gpio);extern int gpio_sysfs_set_active_low (unsigned gpio,int value);extern void gpio_unexport (unsigned gpio); +extern int gpio_block_export (struct gpio_block *block); +extern void gpio_block_unexport (struct gpio_block *block);#endif /* CONFIG_GPIO_SYSFS */
@@ -285,6 +287,15 @@ static inline int gpio_sysfs_set_active_static inline void gpio_unexport (unsigned gpio) { } + +static inline int gpio_block_export (struct gpio_block *block) +{ +return -ENOSYS ; +} + +static inline void gpio_block_unexport (struct gpio_block *block) +{ +}#endif /* CONFIG_GPIO_SYSFS */ #ifdef CONFIG_PINCTRL
include/linux/gpio.h +15 -0
@@ -88,6 +88,7 @@ struct gpio_block_chip {* @ngpio: number of gpios in this block * @gpio: list of gpios in this block * @list: global list of blocks, maintained by gpiolib +* @cur_mask: currently used gpio mask used by userspace API */ struct gpio_block {struct list_head gbc_list;
@@ -97,6 +98,7 @@ struct gpio_block {unsigned *gpio;struct list_head list; +unsigned long cur_mask; };#ifdef CONFIG_GENERIC_GPIO
@@ -314,6 +316,19 @@ static inline void gpio_unexport(unsigneWARN_ON (1 ); } +static inline int gpio_block_export (struct gpio_block *block) +{ +/* GPIO block can never have been requested or set as {in,out}put */ +WARN_ON (1 ); +return -EINVAL ; +} + +static inline void gpio_block_unexport (struct gpio_block *block) +{ +/* GPIO block can never have been exported */ +WARN_ON (1 ); +} +static inline int gpio_to_irq (unsigned gpio) {/* GPIO can never have been requested or set as input */
PATCH v14 3/6 gpio: Add userland device interface to block GPIO
In reply to Roland StiggeThis patch adds a character device interface to the block GPIO system.
--- Documentation/ABI/testing/dev-gpioblock | 34 ++++ drivers/gpio/gpiolib.c | 225 +++++++++++++++++++++++++++++++- include/linux/gpio.h | 13 + 3 files changed, 271 insertions(+), 1 deletion(-)
Documentation/ABI/testing/dev-gpioblock new file +34 -0
@@ -0,0 +1,34 @@ +What: /dev/<gpioblock> +Date: Nov 2012 +KernelVersion: 3.7 +Contact: Roland Stigge <[email protected]> +Description: The /dev/<gpioblock> character device node provides userspace + access to GPIO blocks, named exactly as the block, e.g. + /dev/block0. + + Reading: + When reading sizeof(unsigned long) bytes from the device, the + current state of the block, masked by the current mask (see + below) can be obtained as a word. When the device is opened + with O_NONBLOCK, read() always returns with data immediately, + otherwise it blocks until data is available, see IRQ handling + below. + + Writing: + By writing sizeof(unsigned long) bytes to the device, the + current state of the block can be set. This operation is + masked by the current mask (see below). + + IRQ handling: + When one or more IRQs in the block are IRQ capable, you can + poll() on the device to check/wait for this IRQ. If no IRQ + is available, poll() returns -ENOSYS and userspace needs to + (busy) poll itself if necessary. + + Setting the mask (default: all bits set): + By doing an ioctl(fd, 0, &mask) with an unsigned long mask, the + current mask for read and write operations on this gpio block + can be set. + + See also Documentation/gpio.txt for an explanation of block + GPIO.
drivers/gpio/gpiolib.c +224 -1
254 lines not on this page · raw message
include/linux/gpio.h +13 -0
@@ -4,6 +4,9 @@#include <linux/errno.h> #include <linux/types.h> #include <linux/list.h> +#include <linux/sched.h> +#include <linux/miscdevice.h> +#include <linux/spinlock.h> /* see Documentation/gpio.txt */
@@ -89,6 +92,11 @@ struct gpio_block_chip {* @gpio: list of gpios in this block * @list: global list of blocks, maintained by gpiolib * @cur_mask: currently used gpio mask used by userspace API +* @miscdev: userspace API: device +* @wait_queue: userspace API: wait queue waiting for IRQ +* @irq_controlled: userspace API: flag: using IRQ or not +* @got_int: userspace API: change detection via IRQ +* @lock: userspace API: spinlock for IRQ manipulated data */ struct gpio_block {struct list_head gbc_list;
@@ -99,6 +107,11 @@ struct gpio_block {struct list_head list;unsigned long cur_mask; +struct miscdevice miscdev; +wait_queue_head_t wait_queue; +bool irq_controlled; +bool got_int; +spinlock_t lock; };#ifdef CONFIG_GENERIC_GPIO
Jonathan Corbet
maintainerRe: [PATCH 3/6 v14] gpio: Add userland device interface to block GPIO
Quoted 1 line · On Tue, 22 Jan 2013 13:06:41 +0100 Roland Stigge <[email protected]> wrote:
This patch adds a character device interface to the block GPIO system.
So I was looking at this, and a couple of things caught my eye...
drivers/gpio/gpiolib.c struct gpio_block *gpio_block_find_by_na · line 2291
Quoted 13 lines
drivers/gpio/gpiolib.c +13
-0+static int gpio_block_fop_open (struct inode *in,struct file *f) +{ +int i; +struct gpio_block *block =gpio_block_find_by_minor (MINOR (in->i_rdev)); +int status; +int irq; + +if (!block) +return -ENOENT ; + + block->irq_controlled = false; + block->got_int = false; +spin_lock_init (&block->lock);
So... there is no protection I can find against multiple opens here. Meaning that the second process to open the device will reinitialize the lock (and other variables), regardless of their current state.
More to the point, though, I'm not at all clear on what this lock protects? It seems to be restricted to the got_int flag, which could be manipulated - without locks - with bitops? Or am I missing something?
drivers/gpio/gpiolib.c struct gpio_block *gpio_block_find_by_na · line 2296
Quoted 5 lines
drivers/gpio/gpiolib.c +5
-0+init_waitqueue_head (&block->wait_queue); + f->private_data = block; + +for (i =0 ; i < block->ngpio; i++) { + status =gpio_request (block->gpio[i], block->name);
Hmm... the documentation for the API says that gpio_request() has to be called separately. But now you're doing it here? That's probably OK, but calling gpio_free() at close time could lead to interesting results if the code that set up the block expects them to still be allocated. It seems like the API should be consistent with regard to this - either call gpio_request() when the block is created, or always require the caller to do it.
A quick look shows that the sysfs interface does the same thing? So now you're already double-requesting and freeing the gpios?
Quoted 6 lines
drivers/gpio/gpiolib.c +6
-0+if (status) + goto err1; + + irq =gpio_to_irq (block->gpio[i]); + if (irq >= 0 && + !test_bit(FLAG_IS_OUT, &gpio_desc[block->gpio[i]].flags) &&
drivers/gpio/gpiolib.c struct gpio_block *gpio_block_find_by_na · line 2312
Quoted 10 lines
drivers/gpio/gpiolib.c +10
-0+ !gpio_block_is_irq_duplicate(block, i)) { + status =request_irq (irq, gpio_block_irq_handler, +IRQF_SHARED , + block->name, block); +if (status) + goto err2; + + block->irq_controlled = true; + } + }
This forces the block to work in the IRQ-driven mode if a line is capable of it, regardless of whether the creator (or the process calling open()) wants that. It seems like that should be controllable separately?
Quoted 4 lines
drivers/gpio/gpiolib.c +4
-0+ +return 0 ; + +err1:
drivers/gpio/gpiolib.c struct gpio_block *gpio_block_find_by_na · line 2326
Quoted 10 lines
drivers/gpio/gpiolib.c +10
-0+while (i >0 ) { + i--; + + irq =gpio_to_irq (block->gpio[i]); +if (irq >=0 && + !test_bit (FLAG_IS_OUT , &gpio_desc[block->gpio[i]].flags) && + !gpio_block_is_irq_duplicate (block, i)) +free_irq (irq, block); +err2: +gpio_free (block->gpio[i]);
Um...wait...you're jumping into the middle of the while loop? I guess that will work, but ... hmm...
drivers/gpio/gpiolib.c struct gpio_block *gpio_block_find_by_na · line 2334
Quoted 8 lines
drivers/gpio/gpiolib.c +8
-0+ } +return status; +} + +static int gpio_block_fop_release (struct inode *in,struct file *f) +{ +int i; +struct gpio_block *block = (struct gpio_block *)f->private_data;
Is there anything that will have prevented a call to gpio_block_free() while the device is open? This seems like a concern for all of the fops here.
Quoted 12 lines
drivers/gpio/gpiolib.c +12
-0+for (i =0 ; i < block->ngpio; i++) { +int irq =gpio_to_irq (block->gpio[i]); + +if (irq >=0 && + !test_bit (FLAG_IS_OUT , &gpio_desc[block->gpio[i]].flags) && + !gpio_block_is_irq_duplicate (block, i)) +free_irq (irq, block); + +gpio_free (block->gpio[i]); + } + +return 0 ;
drivers/gpio/gpiolib.c struct gpio_block *gpio_block_find_by_na · line 2357
Quoted 10 lines
drivers/gpio/gpiolib.c +10
-0+} + +static int got_int (struct gpio_block *block) +{ +unsigned long flags; +int result; + +spin_lock_irqsave (&block->lock, flags); + result = block->got_int; +spin_unlock_irqrestore (&block->lock, flags);
The lock doesn't really buy you much here. Might you have wanted to reset block->got_int here too?
Quoted 9 lines
drivers/gpio/gpiolib.c +9
-0+ +return result; +} + +static ssize_t gpio_block_fop_read (struct file *f,char __user *buf,size_t n, +loff_t *offset) +{ +struct gpio_block *block = (struct gpio_block *)f->private_data; +int err;
drivers/gpio/gpiolib.c struct gpio_block *gpio_block_find_by_na · line 2376
Quoted 10 lines
drivers/gpio/gpiolib.c +10
-0+unsigned long flags; + +if (block->irq_controlled) { +if (!(f->f_flags &O_NONBLOCK )) +wait_event_interruptible (block->wait_queue, +got_int (block)); +spin_lock_irqsave (&block->lock, flags); + block->got_int =0 ; +spin_unlock_irqrestore (&block->lock, flags); + }
If two processes are waiting on the device, they might both wake up on the same interrupt. The second might even reset block->got_int after *another* interrupt has arrived, causing it to be lost. Or am I missing something?
drivers/gpio/gpiolib.c struct gpio_block *gpio_block_find_by_na · line 2387
Quoted 10 lines
drivers/gpio/gpiolib.c +10
-0+if (n >=sizeof (unsigned long )) { +unsigned long values =gpio_block_get (block, block->cur_mask); + + err =put_user (values, (unsigned long __user *)buf); +if (err) +return err; + +return sizeof (unsigned long ); + } +return 0 ;
And here you've consumed the interrupt even in the case where you'll not actually return the gpios or return any data. This one could maybe be considered to be user-space programmer error, but still...
Quoted 8 lines
drivers/gpio/gpiolib.c +8
-0+} + +static ssize_t gpio_block_fop_write (struct file *f,const char __user *buf, +size_t n,loff_t *offset) +{ +struct gpio_block *block = (struct gpio_block *)f->private_data; +int err; +
drivers/gpio/gpiolib.c struct gpio_block *gpio_block_find_by_na · line 2405
Quoted 10 lines
drivers/gpio/gpiolib.c +10
-0+if (n >=sizeof (unsigned long )) { +unsigned long values; + + err =get_user (values, (unsigned long __user *)buf); +if (err) +return err; +if (gpio_block_is_output (block)) +gpio_block_set (block, block->cur_mask, values); +else +return -EPERM ;
Is EPERM right? Or maybe EINVAL?
drivers/gpio/gpiolib.c struct gpio_block *gpio_block_find_by_na · line 2418
Quoted 13 lines
drivers/gpio/gpiolib.c +13
-0+return sizeof (unsigned long ); + } +return 0 ; +} + +static long gpio_block_fop_ioctl (struct file *f,unsigned int cmd, +unsigned long arg) +{ +struct gpio_block *block = (struct gpio_block *)f->private_data; +unsigned long __user *x = (unsigned long __user *)arg; + +if (cmd ==0 ) +return get_user (block->cur_mask, x);
...and this is a little weird. It seems you should define a proper ioctl() command code like everybody else does.
drivers/gpio/gpiolib.c struct gpio_block *gpio_block_find_by_na · line 2429
Quoted 10 lines
drivers/gpio/gpiolib.c +10
-0+return -EINVAL ; +} + +static unsigned int gpio_block_fop_poll (struct file *f, +struct poll_table_struct *pt) +{ +struct gpio_block *block = (struct gpio_block *)f->private_data; + +if (!block->irq_controlled) +return -ENOSYS ;
Is that what you want, or should you just return POLLIN|POLLOUT in this case?
drivers/gpio/gpiolib.c struct gpio_block *gpio_block_find_by_na · line 2435
Quoted 5 lines
drivers/gpio/gpiolib.c +5
-0+if (!got_int (block)) +poll_wait (f, &block->wait_queue, pt); + +if (got_int (block)) +return POLLIN ;
How about
if (got_int(block))
return POLLIN;
poll_wait(f, &block->wait_queue, pt);?
jon
Re: [PATCH 3/6 v14] gpio: Add userland device interface to block GPIO
Quoted 6 lines · Jonathan Corbet
Quoted 1 line · On Tue, 22 Jan 2013 13:06:41 +0100 Roland Stigge <[email protected]> wrote:
This patch adds a character device interface to the block GPIO system.
So I was looking at this, and a couple of things caught my eye...
Good points you mentioned. Will address them on a subsequent update.
Thanks,
Roland
Re: [PATCH 3/6 v14] gpio: Add userland device interface to block GPIO
In reply to Roland StiggeQuoted 25 lines · Roland Stigge
This patch adds a character device interface to the block GPIO system.
Signed-off-by Roland Stigge <[email protected]>--- Documentation/ABI/testing/dev-gpioblock | 34 ++++ drivers/gpio/gpiolib.c | 225 +++++++++++++++++++++++++++++++- include/linux/gpio.h | 13 + 3 files changed, 271 insertions(+), 1 deletion(-)Documentation/ABI/testing/dev-gpioblock new file +13
-0@@ -0,0 +1,34 @@ +What: /dev/<gpioblock> +Date: Nov 2012 +KernelVersion: 3.7 +Contact: Roland Stigge <[email protected]> +Description: The /dev/<gpioblock> character device node provides userspace + access to GPIO blocks, named exactly as the block, e.g. + /dev/block0. + + Reading: + When reading sizeof(unsigned long) bytes from the device, the + current state of the block, masked by the current mask (see + below) can be obtained as a word. When the device is opened + with O_NONBLOCK, read() always returns with data immediately,
Documentation/ABI/testing/dev-gpioblock line 23
Quoted 10 lines
Documentation/ABI/testing/dev-gpioblock new file +10
-0+ otherwise it blocks until data is available, see IRQ handling + below. + + Writing: + By writing sizeof(unsigned long) bytes to the device, the + current state of the block can be set. This operation is + masked by the current mask (see below). + + IRQ handling: + When one or more IRQs in the block are IRQ capable, you can
^^^^
I think this should be GPIOs
Documentation/ABI/testing/dev-gpioblock line 34
Quoted 11 lines
Documentation/ABI/testing/dev-gpioblock new file +11
-0+static long gpio_block_fop_ioctl(struct file *f, unsigned int cmd, + unsigned long arg) +{ + struct gpio_block *block = (struct gpio_block *)f->private_data; + unsigned long __user *x = (unsigned long __user *)arg; + + if (cmd == 0) + return get_user(block->cur_mask, x); + + return -EINVAL; +}
So there is no way from userspace to create/remove GPIO blocks? I know support in sysfs is problematic due to formatting, but an IOCTL for that would be nice.
Best regards,
Alexander
PATCH v14 4/6 gpiolib: Fix default attributes for class
In reply to Roland StiggeThere is a race condition between creating a gpio or gpiochip device and adding default attributes. This patch fixes this by defining the default attributes as dev_attrs of the class. For this, it was necessary to create a separate gpiochip_class besides gpio_class.
--- Documentation/ABI/testing/sysfs-gpio | 11 ++++ drivers/gpio/gpiolib.c | 78 ++++++++++++++--------------------- 2 files changed, 44 insertions(+), 45 deletions(-)
Documentation/ABI/testing/sysfs-gpio +11 -0
@@ -20,6 +20,17 @@ Description: /value ... always readable, writes fail for input GPIOs /direction ... r/w as: in, out (default low); write: high, low /edge ... r/w as: none, falling, rising, both + +What: /sys/class/gpiochip/ +Date: October 2012 +KernelVersion: 3.7 +Contact: Roland Stigge <[email protected]> +Description: + + Each gpiochip is represented by a separate device having the following + attributes: + + /sys/class/gpiochip /gpiochipN ... for each gpiochip; #N is its first GPIO /base ... (r/o) same as N /label ... (r/o) descriptive, not necessarily unique
drivers/gpio/gpiolib.c +33 -45
152 lines not on this page · raw message
PATCH v14 5/6 gpio: Add device tree support to block GPIO API
In reply to Roland StiggeThis patch adds device tree support to the block GPIO API.
--- Documentation/devicetree/bindings/gpio/gpio-block.txt | 36 ++++++ drivers/gpio/Makefile | 1 drivers/gpio/gpioblock-of.c | 100 ++++++++++++++++++ 3 files changed, 137 insertions(+)
Documentation/devicetree/bindings/gpio/gpio-block.txt new file +36 -0
@@ -0,0 +1,36 @@ +Block GPIO definition +===================== + +This binding specifies arbitrary blocks of gpios, combining gpios from one or +more GPIO controllers together, to form a word for r/w access. + +Required property: +- compatible: must be "linux,gpio-block" + +Required subnodes: +- the name will be the registered name of the block +- property "gpios" is a list of gpios for the respective block + +Example: + + blockgpio { + compatible = "linux,gpio-block"; + + block0 { + gpios = <&gpio 3 0 0>, + <&gpio 3 1 0>; + }; + block1 { + gpios = <&gpio 4 1 0>, + <&gpio 4 3 0>, + <&gpio 4 2 0>, + <&gpio 4 4 0>, + <&gpio 4 5 0>, + <&gpio 4 6 0>, + <&gpio 4 7 0>, + <&gpio 4 8 0>, + <&gpio 4 9 0>, + <&gpio 4 10 0>, + <&gpio 4 19 0>; + }; + };
drivers/gpio/Makefile +1 -0
@@ -5,6 +5,7 @@ ccflags-$(CONFIG_DEBUG_GPIO) += -DDEBUG obj-$(CONFIG_GPIOLIB) += gpiolib.o devres.o obj-$(CONFIG_OF_GPIO) += gpiolib-of.o obj-$(CONFIG_GPIO_ACPI) += gpiolib-acpi.o +obj-$(CONFIG_OF_GPIO) += gpioblock-of.o # Device drivers. Generally keep list sorted alphabetically obj-$(CONFIG_GPIO_GENERIC) += gpio-generic.o
drivers/gpio/gpioblock-of.c new file +100 -0
100 lines not on this page · raw message
Re: [PATCH 5/6 v14] gpio: Add device tree support to block GPIO API
Quoted 39 lines · Roland Stigge
This patch adds device tree support to the block GPIO API.
Signed-off-by Roland Stigge <[email protected]>--- Documentation/devicetree/bindings/gpio/gpio-block.txt | 36 ++++++ drivers/gpio/Makefile | 1 drivers/gpio/gpioblock-of.c | 100 ++++++++++++++++++ 3 files changed, 137 insertions(+)Documentation/devicetree/bindings/gpio/gpio-block.txt new file +26
-0@@ -0,0 +1,36 @@ +Block GPIO definition +===================== + +This binding specifies arbitrary blocks of gpios, combining gpios from one or +more GPIO controllers together, to form a word for r/w access. + +Required property: +- compatible: must be "linux,gpio-block" + +Required subnodes: +- the name will be the registered name of the block +- property "gpios" is a list of gpios for the respective block + +Example: + + blockgpio { + compatible = "linux,gpio-block"; + + block0 { + gpios = <&gpio 3 0 0>, + <&gpio 3 1 0>; + }; + block1 { + gpios = <&gpio 4 1 0>, + <&gpio 4 3 0>, + <&gpio 4 2 0>,
Documentation/devicetree/bindings/gpio/gpio-block.txt line 36
Quoted 10 lines
Documentation/devicetree/bindings/gpio/gpio-block.txt new file +10
-0+ <&gpio 4 4 0>, + <&gpio 4 5 0>, + <&gpio 4 6 0>, + <&gpio 4 7 0>, + <&gpio 4 8 0>, + <&gpio 4 9 0>, + <&gpio 4 10 0>, + <&gpio 4 19 0>; + }; + };
How do you see bindings for other kinds of drivers?
In my patchset, it's possible for other drivers to use gpio-blocks. One example we have is a power sequencer with 2 pins attached to GPIO pins. These 2 pins form a 2bit word to select power margining. These 2 pins need to be set synchronously (as otherwise when going from profile 0 to profile 3 you pass either profile 1 or profile 2 which could be bad for hardware)
In the device-tree this is specified as:
powr at 0x20 {
// other properties
gpios = <&gpio 4 0
&gpio 5 0>; };
Is this kind of integration also possible?
Regards,
Stijn
Quoted 113 lines
drivers/gpio/Makefile +1
-0@@ -5,6 +5,7 @@ ccflags-$(CONFIG_DEBUG_GPIO) += -DDEBUG obj-$(CONFIG_GPIOLIB) += gpiolib.o devres.o obj-$(CONFIG_OF_GPIO) += gpiolib-of.o obj-$(CONFIG_GPIO_ACPI) += gpiolib-acpi.o +obj-$(CONFIG_OF_GPIO) += gpioblock-of.o # Device drivers. Generally keep list sorted alphabetically obj-$(CONFIG_GPIO_GENERIC) += gpio-generic.odrivers/gpio/gpioblock-of.c new file +100
-0@@ -0,0 +1,100 @@ +/* +* OF implementation for Block GPIO +* +* Copyright (C) 2012 Roland Stigge <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/gpio.h> +#include <linux/of.h> +#include <linux/of_gpio.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/err.h> + +static int gpioblock_of_probe (struct platform_device *pdev) +{ +struct device_node *block; +unsigned *gpios; +int ngpio; +int ret; +struct gpio_block *gb; + +for_each_available_child_of_node (pdev->dev.of_node, block) { +int i; + + ngpio =of_gpio_count (block); +if (ngpio <1 ) { + ret = -ENODEV ; + goto err1; + } + + gpios =kzalloc (ngpio *sizeof (*gpios),GFP_KERNEL ); +if (!gpios) { + ret = -ENOMEM ; + goto err1; + } + +for (i =0 ; i < ngpio; i++) { + ret =of_get_gpio (block, i); +if (ret <0 ) + goto err2;/* expect -EPROBE_DEFER */ + gpios[i] = ret; + } + gb =gpio_block_create (gpios, ngpio, block->name); +if (IS_ERR (gb)) { +dev_err (&pdev->dev, +"Error creating GPIO block from device tree\n" ); + ret =PTR_ERR (gb); + goto err2; + } + ret =gpio_block_register (gb); +if (ret <0 ) + goto err3; + +kfree (gpios); +dev_info (&pdev->dev,"Registered gpio block %s: %d gpios\n" , + block->name, ngpio); + } +return 0 ; + +err3: +gpio_block_free (gb); +err2: +kfree (gpios); +err1: +of_node_put (block); +return ret; +} + +#ifdef CONFIG_OF +static struct of_device_id gpioblock_of_match[] = { + { .compatible ="linux,gpio-block" , }, + { }, +}; +MODULE_DEVICE_TABLE (of, gpioblock_of_match); +#endif + +static struct platform_driver gpioblock_of_driver = { + .driver = { + .name ="gpio-block" , + .owner =THIS_MODULE , + .of_match_table =of_match_ptr (gpioblock_of_match), + + }, + .probe = gpioblock_of_probe, +}; + +module_platform_driver (gpioblock_of_driver); + +MODULE_DESCRIPTION ("GPIO Block driver" ); +MODULE_AUTHOR ("Roland Stigge <[email protected]>" ); +MODULE_LICENSE ("GPL" ); +MODULE_ALIAS ("platform:gpioblock-of" );
Re: [PATCH 5/6 v14] gpio: Add device tree support to block GPIO API
Quoted 35 lines · Stijn Devriendt
Quoted 13 lines
Documentation/devicetree/bindings/gpio/gpio-block.txt new file +13
-0+Example: + + blockgpio { + compatible = "linux,gpio-block"; + + block0 { + gpios = <&gpio 3 0 0>, + <&gpio 3 1 0>; + }; + block1 { + gpios = <&gpio 4 1 0>, + <&gpio 4 3 0>, + <&gpio 4 2 0>,Documentation/devicetree/bindings/gpio/gpio-block.txt line 36
Quoted 10 lines
Documentation/devicetree/bindings/gpio/gpio-block.txt new file +10
-0+ <&gpio 4 4 0>, + <&gpio 4 5 0>, + <&gpio 4 6 0>, + <&gpio 4 7 0>, + <&gpio 4 8 0>, + <&gpio 4 9 0>, + <&gpio 4 10 0>, + <&gpio 4 19 0>; + }; + };How do you see bindings for other kinds of drivers?
In my patchset, it's possible for other drivers to use gpio-blocks. One example we have is a power sequencer with 2 pins attached to GPIO pins. These 2 pins form a 2bit word to select power margining. These 2 pins need to be set synchronously (as otherwise when going from profile 0 to profile 3 you pass either profile 1 or profile 2 which could be bad for hardware)
In the device-tree this is specified as:
Quoted 8 lines
powr at 0x20 { // other propertiesgpios = <&gpio 4 0
&gpio 5 0>; };Is this kind of integration also possible?
You can reference the gpio block via a phandle, e.g.:
blockgpio {
compatible = "linux,gpio-block";
selector1 {
gpios = <&gpio 4 0>,
<&gpio 5 0>;
};
};
powr at 0x20 {
// ...
gpios = <&selector1>;
};In the driver, you can get the gpio block like this:
block = gpio_block_find_by_name(of_parse_phandle(powr, "gpios", 0)->name);
(Simplified by removed error/NULL handling!)
If this turns out to be a common pattern, I can add a convenience "get" function for this.
Roland
Re: [PATCH 5/6 v14] gpio: Add device tree support to block GPIO API
Quoted 63 lines · Roland Stigge
Quoted 35 lines · Stijn Devriendt
Quoted 13 lines
Documentation/devicetree/bindings/gpio/gpio-block.txt new file +13
-0+Example: + + blockgpio { + compatible = "linux,gpio-block"; + + block0 { + gpios = <&gpio 3 0 0>, + <&gpio 3 1 0>; + }; + block1 { + gpios = <&gpio 4 1 0>, + <&gpio 4 3 0>, + <&gpio 4 2 0>,Documentation/devicetree/bindings/gpio/gpio-block.txt line 36
Quoted 10 lines
Documentation/devicetree/bindings/gpio/gpio-block.txt new file +10
-0+ <&gpio 4 4 0>, + <&gpio 4 5 0>, + <&gpio 4 6 0>, + <&gpio 4 7 0>, + <&gpio 4 8 0>, + <&gpio 4 9 0>, + <&gpio 4 10 0>, + <&gpio 4 19 0>; + }; + };How do you see bindings for other kinds of drivers?
In my patchset, it's possible for other drivers to use gpio-blocks. One example we have is a power sequencer with 2 pins attached to GPIO pins. These 2 pins form a 2bit word to select power margining. These 2 pins need to be set synchronously (as otherwise when going from profile 0 to profile 3 you pass either profile 1 or profile 2 which could be bad for hardware)
In the device-tree this is specified as:
Quoted 8 lines
powr at 0x20 { // other propertiesgpios = <&gpio 4 0
&gpio 5 0>; };Is this kind of integration also possible?
You can reference the gpio block via a phandle, e.g.:
blockgpio { compatible = "linux,gpio-block"; selector1 { gpios = <&gpio 4 0>, <&gpio 5 0>; }; }; powr at 0x20 { // ... gpios = <&selector1>; };
Quoted 8 lines
In the driver, you can get the gpio block like this:
block =
gpio_block_find_by_name(of_parse_phandle(powr, "gpios", 0)->name);(Simplified by removed error/NULL handling!)
If this turns out to be a common pattern, I can add a convenience "get" function for this.
Given the pick-up of device-tree in ARM and MIPS, I think this stands a good chance
of becoming a common pattern. Do mind the "gpios" name; it's already used by the normal GPIO request functions...
This is one of the things I liked about my patch, there's little difference between
using a group of GPIOs versus multiple separate GPIOs. The device-tree description
is the same, only the driver handles them differently.
You could ask the question whether the device-tree should make a difference between
1 GPIO, 2 separate GPIOs or 3 GPIOs in a block. For a H/W description language it's
all the same. It is an implementation detail of the OS/drivers whether they handle them
as a block or as separate GPIOs.
Regards,
Stijn
Re: [PATCH 5/6 v14] gpio: Add device tree support to block GPIO API
Quoted 35 lines · Stijn Devriendt
Quoted 35 lines
Quoted 10 lines
In the device-tree this is specified as:
powr at 0x20 { // other propertiesgpios = <&gpio 4 0
&gpio 5 0>; };Is this kind of integration also possible?
You can reference the gpio block via a phandle, e.g.:
blockgpio { compatible = "linux,gpio-block"; selector1 { gpios = <&gpio 4 0>, <&gpio 5 0>; }; }; powr at 0x20 { // ... gpios = <&selector1>; };In the driver, you can get the gpio block like this:
block =
gpio_block_find_by_name(of_parse_phandle(powr, "gpios", 0)->name);(Simplified by removed error/NULL handling!)
Quoted 7 lines
Quoted 2 lines
If this turns out to be a common pattern, I can add a convenience "get" function for this.
Given the pick-up of device-tree in ARM and MIPS, I think this stands a good chance
of becoming a common pattern. Do mind the "gpios" name; it's already used by the normal GPIO request functions...
Right, when providing the respective convenience function, I'll better use sth. like "gpioblock" as property name.
Specifying a traditional list of GPIOs instead is easy, actually. The respective driver just needs to allocate a gpio block explicitly (insteady of implicitly via phandle as above). Unfortunately, gpio blocks that should be exported and available to userspace can't be specified this way. Therefore the strategy as above.
Roland
PATCH v14 6/6 gpio: Add block gpio to several gpio drivers
In reply to Roland StiggeThis patch adds block GPIO support to several gpio drivers.
This implements block GPIO only for some selected drivers since block GPIO is an optional feature which may not be suitable for every GPIO hardware. (With automatic fallback to the single GPIO functions if not available in a driver.)
For pinctrl-at91.c:
--- drivers/gpio/Kconfig | 2 drivers/gpio/gpio-em.c | 23 ++++++++++ drivers/gpio/gpio-ge.c | 29 +++++++++++++ drivers/gpio/gpio-generic.c | 56 +++++++++++++++++++++++++ drivers/gpio/gpio-ks8695.c | 34 +++++++++++++++ drivers/gpio/gpio-lpc32xx.c | 82 ++++++++++++++++++++++++++++++++++++++ drivers/gpio/gpio-max730x.c | 61 ++++++++++++++++++++++++++++ drivers/gpio/gpio-max732x.c | 59 +++++++++++++++++++++++++++ drivers/gpio/gpio-mc33880.c | 16 +++++++ drivers/gpio/gpio-ml-ioh.c | 27 ++++++++++++ drivers/gpio/gpio-mm-lantiq.c | 22 ++++++++++ drivers/gpio/gpio-mpc5200.c | 64 +++++++++++++++++++++++++++++ drivers/gpio/gpio-mpc8xxx.c | 41 +++++++++++++++++++ drivers/gpio/gpio-pca953x.c | 64 +++++++++++++++++++++++++++++ drivers/gpio/gpio-pcf857x.c | 24 +++++++++++ drivers/gpio/gpio-pch.c | 27 ++++++++++++ drivers/gpio/gpio-pl061.c | 17 +++++++ drivers/gpio/gpio-sa1100.c | 20 +++++++++ drivers/gpio/gpio-samsung.c | 31 ++++++++++++++ drivers/gpio/gpio-twl6040.c | 32 ++++++++++++++ drivers/gpio/gpio-ucb1400.c | 23 ++++++++++ drivers/gpio/gpio-vt8500.c | 24 +++++++++++ drivers/gpio/gpio-xilinx.c | 44 ++++++++++++++++++++ drivers/pinctrl/pinctrl-at91.c | 29 +++++++++++++ drivers/pinctrl/pinctrl-nomadik.c | 36 ++++++++++++++++ 25 files changed, 887 insertions(+)
drivers/gpio/Kconfig +2 -0
@@ -144,11 +144,13 @@ config GPIO_MM_LANTIQ config GPIO_MPC5200 def_bool y depends on PPC_MPC52xx + select BITREVERSE config GPIO_MPC8XXX bool "MPC512x/MPC8xxx GPIO support" depends on PPC_MPC512x || PPC_MPC831x || PPC_MPC834x || PPC_MPC837x || \ FSL_SOC_BOOKE || PPC_86xx + select BITREVERSE help Say Y here if you're going to use hardware that connects to the MPC512x/831x/834x/837x/8572/8610 GPIOs.
drivers/gpio/gpio-em.c +23 -0
@@ -202,6 +202,27 @@ static void em_gio_set(struct gpio_chip__em_gio_set (chip,GIO_OH , offset -16 , value); } +static unsigned long em_gio_get_block (struct gpio_chip *chip, +unsigned long mask) +{ +return (int )(em_gio_read (gpio_to_priv (chip),GIO_I ) & mask); +} + +static void em_gio_set_block (struct gpio_chip *chip,unsigned long mask, +unsigned long values) +{ +unsigned long mask_ol = mask &0xFFFF ; +unsigned long mask_oh = mask >>16 ; + +unsigned long values_ol = values & mask_ol; +unsigned long values_oh = (values >>16 ) & mask_oh; + +em_gio_write (gpio_to_priv (chip),GIO_OL , + mask_ol <<16 | values_ol); +em_gio_write (gpio_to_priv (chip),GIO_OH , + mask_oh <<16 | values_oh); +} +static int em_gio_direction_output (struct gpio_chip *chip,unsigned offset,int value) {
@@ -282,8 +303,10 @@ static int em_gio_probe(struct platform_ gpio_chip = &p->gpio_chip; gpio_chip->direction_input = em_gio_direction_input; gpio_chip->get = em_gio_get; + gpio_chip->get_block = em_gio_get_block; gpio_chip->direction_output = em_gio_direction_output; gpio_chip->set = em_gio_set; + gpio_chip->set_block = em_gio_set_block; gpio_chip->to_irq = em_gio_to_irq; gpio_chip->label = name; gpio_chip->owner =THIS_MODULE ;
drivers/gpio/gpio-ge.c +29 -0
@@ -100,6 +100,29 @@ static void gef_gpio_set(struct gpio_chi_gef_gpio_set (mmchip->regs +GEF_GPIO_OUT , offset, value); } +static unsigned long gef_gpio_get_block (struct gpio_chip *chip, +unsigned long mask) +{ +struct of_mm_gpio_chip *mmchip =to_of_mm_gpio_chip (chip); + +return ioread32be (mmchip->regs +GEF_GPIO_IN ) & mask; +} + +static void gef_gpio_set_block (struct gpio_chip *chip, +unsigned long mask,unsigned long values) +{ +struct of_mm_gpio_chip *mmchip =to_of_mm_gpio_chip (chip); +void __iomem *reg = mmchip->regs +GEF_GPIO_OUT ; +unsigned int data; + + data =ioread32be (reg); + + data &= ~mask; + data |= values & mask; + +iowrite32be (data, reg); +} +static int __init gef_gpio_init (void ) {struct device_node *np;
@@ -125,6 +148,8 @@ static int __init gef_gpio_init(void) gef_gpio_chip->gc.direction_output = gef_gpio_dir_out; gef_gpio_chip->gc.get = gef_gpio_get; gef_gpio_chip->gc.set = gef_gpio_set; + gef_gpio_chip->gc.get_block = gef_gpio_get_block; + gef_gpio_chip->gc.set_block = gef_gpio_set_block;/* This function adds a memory mapped GPIO chip */ retval =of_mm_gpiochip_add (np, gef_gpio_chip);
@@ -153,6 +178,8 @@ static int __init gef_gpio_init(void) gef_gpio_chip->gc.direction_output = gef_gpio_dir_out; gef_gpio_chip->gc.get = gef_gpio_get; gef_gpio_chip->gc.set = gef_gpio_set; + gef_gpio_chip->gc.get_block = gef_gpio_get_block; + gef_gpio_chip->gc.set_block = gef_gpio_set_block;/* This function adds a memory mapped GPIO chip */ retval =of_mm_gpiochip_add (np, gef_gpio_chip);
@@ -181,6 +208,8 @@ static int __init gef_gpio_init(void) gef_gpio_chip->gc.direction_output = gef_gpio_dir_out; gef_gpio_chip->gc.get = gef_gpio_get; gef_gpio_chip->gc.set = gef_gpio_set; + gef_gpio_chip->gc.get_block = gef_gpio_get_block; + gef_gpio_chip->gc.set_block = gef_gpio_set_block;/* This function adds a memory mapped GPIO chip */ retval =of_mm_gpiochip_add (np, gef_gpio_chip);
drivers/gpio/gpio-generic.c +56 -0
82 lines not on this page · raw message
drivers/gpio/gpio-ks8695.c +34 -0
@@ -195,6 +195,38 @@ static int ks8695_gpio_get_value(struct/* +* Set the state of GPIO lines simultaneously. +*/ +static void ks8695_gpio_set_block (struct gpio_chip *gc, +unsigned long mask,unsigned long values) +{ +unsigned long x, flags; + +local_irq_save (flags); + +/* set output line state */ + x =__raw_readl (KS8695_GPIO_VA +KS8695_IOPD ); + + x &= ~mask; + x |= values & mask; + +__raw_writel (x,KS8695_GPIO_VA +KS8695_IOPD ); + +local_irq_restore (flags); +} + + +/* +* Read the state of GPIO lines simultaneously. +*/ +static unsigned long ks8695_gpio_get_block (struct gpio_chip *gc, +unsigned long mask) +{ +return __raw_readl (KS8695_GPIO_VA +KS8695_IOPD ) & mask; +} + + +/* * Map GPIO line to IRQ number. */ static int ks8695_gpio_to_irq (struct gpio_chip *gc,unsigned int pin)
@@ -225,6 +257,8 @@ static struct gpio_chip ks8695_gpio_chip .direction_output = ks8695_gpio_direction_output, .get = ks8695_gpio_get_value, .set = ks8695_gpio_set_value, + .get_block = ks8695_gpio_get_block, + .set_block = ks8695_gpio_set_block, .to_irq = ks8695_gpio_to_irq, .base = 0, .ngpio = 16,
drivers/gpio/gpio-lpc32xx.c +82 -0
151 lines not on this page · raw message
drivers/gpio/gpio-max730x.c +61 -0
81 lines not on this page · raw message
drivers/gpio/gpio-max732x.c +59 -0
73 lines not on this page · raw message
drivers/gpio/gpio-mc33880.c +16 -0
@@ -80,6 +80,21 @@ static void mc33880_set(struct gpio_chipmutex_unlock (&mc->lock); } +static void mc33880_set_block (struct gpio_chip *chip,unsigned long mask, +unsigned long values) +{ + struct mc33880 *mc = container_of(chip, struct mc33880, chip); + +mutex_lock (&mc->lock); + + mc->port_config &= ~mask; + mc->port_config |= values & mask; + +mc33880_write_config (mc); + +mutex_unlock (&mc->lock); +} +static int mc33880_probe (struct spi_device *spi) {struct mc33880 *mc;
@@ -113,6 +128,7 @@ static int mc33880_probe(struct spi_devi mc->chip.label =DRIVER_NAME , mc->chip.set = mc33880_set; + mc->chip.set_block = mc33880_set_block; mc->chip.base = pdata->base; mc->chip.ngpio =PIN_NUMBER ; mc->chip.can_sleep =1 ;
drivers/gpio/gpio-ml-ioh.c +27 -0
@@ -127,6 +127,31 @@ static int ioh_gpio_get(struct gpio_chipreturn ioread32 (&chip->reg->regs[chip->ch].pi) & (1 << nr); } +static void ioh_gpio_set_block (struct gpio_chip *gpio,unsigned long mask, +unsigned long values) +{ +u32 reg_val; + struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio); +unsigned long flags; + +spin_lock_irqsave (&chip->spinlock, flags); + reg_val =ioread32 (&chip->reg->regs[chip->ch].po); + + reg_val &= ~mask; + reg_val |= values & mask; + +iowrite32 (reg_val, &chip->reg->regs[chip->ch].po); +spin_unlock_irqrestore (&chip->spinlock, flags); +} + +static unsigned long ioh_gpio_get_block (struct gpio_chip *gpio, +unsigned long mask) +{ + struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio); + +return ioread32 (&chip->reg->regs[chip->ch].pi) & mask; +} +static int ioh_gpio_direction_output (struct gpio_chip *gpio,unsigned nr,int val) {
@@ -237,8 +262,10 @@ static void ioh_gpio_setup(struct ioh_gp gpio->owner =THIS_MODULE ; gpio->direction_input = ioh_gpio_direction_input; gpio->get = ioh_gpio_get; + gpio->get_block = ioh_gpio_get_block; gpio->direction_output = ioh_gpio_direction_output; gpio->set = ioh_gpio_set; + gpio->set_block = ioh_gpio_set_block; gpio->dbg_show =NULL ; gpio->base =-1 ; gpio->ngpio = num_port;
drivers/gpio/gpio-mm-lantiq.c +22 -0
@@ -73,6 +73,27 @@ static void ltq_mm_set(struct gpio_chip }/** +* ltq_mm_set_block() - gpio_chip->set_block - set gpios simultaneously. +* @gc: Pointer to gpio_chip device structure. +* @mask: Bit map of masked GPIOs in this gpio_chip. +* @values: Values to be written to the specified signals. +* +* Set the shadow values and call ltq_mm_apply. +*/ +static void ltq_mm_set_block (struct gpio_chip *gc,unsigned long mask, +unsigned long values) +{ +struct of_mm_gpio_chip *mm_gc =to_of_mm_gpio_chip (gc); +struct ltq_mm *chip = + container_of(mm_gc, struct ltq_mm, mmchip); + + chip->shadow &= ~mask; + chip->shadow |= values & mask; + +ltq_mm_apply (chip); +} + +/** * ltq_mm_dir_out() - gpio_chip->dir_out - set gpio direction. * @gc: Pointer to gpio_chip device structure. * @gpio: GPIO signal number.
@@ -122,6 +143,7 @@ static int ltq_mm_probe(struct platform_ chip->mmchip.gc.label ="gpio-mm-ltq" ; chip->mmchip.gc.direction_output = ltq_mm_dir_out; chip->mmchip.gc.set = ltq_mm_set; + chip->mmchip.gc.set_block = ltq_mm_set_block; chip->mmchip.save_regs = ltq_mm_save_regs;/* store the shadow value if one was passed by the devicetree */
drivers/gpio/gpio-mpc5200.c +64 -0
94 lines not on this page · raw message
drivers/gpio/gpio-mpc8xxx.c +41 -0
59 lines not on this page · raw message
drivers/gpio/gpio-pca953x.c +64 -0
76 lines not on this page · raw message
drivers/gpio/gpio-pcf857x.c +24 -0
@@ -158,6 +158,28 @@ static void pcf857x_set(struct gpio_chippcf857x_output (chip, offset, value); } +static unsigned long pcf857x_get_block (struct gpio_chip *chip, +unsigned long mask) +{ + struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); +int value; + + value = gpio->read (gpio->client); +return (value <0 ) ?0 : (value & mask); +} + +static void pcf857x_set_block (struct gpio_chip *chip,unsigned long mask, +unsigned long values) +{ + struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); + +mutex_lock (&gpio->lock); + gpio->out &= ~mask; + gpio->out |= values & mask; + gpio->write (gpio->client, gpio->out); +mutex_unlock (&gpio->lock); +} +/*-------------------------------------------------------------------------*/ static int pcf857x_to_irq (struct gpio_chip *chip,unsigned offset)
@@ -280,6 +302,8 @@ static int pcf857x_probe(struct i2c_clie gpio->chip.owner =THIS_MODULE ; gpio->chip.get = pcf857x_get; gpio->chip.set = pcf857x_set; + gpio->chip.get_block = pcf857x_get_block; + gpio->chip.set_block = pcf857x_set_block; gpio->chip.direction_input = pcf857x_input; gpio->chip.direction_output = pcf857x_output; gpio->chip.ngpio = id->driver_data;
drivers/gpio/gpio-pch.c +27 -0
@@ -122,6 +122,23 @@ static void pch_gpio_set(struct gpio_chispin_unlock_irqrestore (&chip->spinlock, flags); } +static void pch_gpio_set_block (struct gpio_chip *gpio,unsigned long mask, +unsigned long values) +{ +u32 reg_val; + struct pch_gpio *chip = container_of(gpio, struct pch_gpio, gpio); +unsigned long flags; + +spin_lock_irqsave (&chip->spinlock, flags); + reg_val =ioread32 (&chip->reg->po); + + reg_val &= ~mask; + reg_val |= values & mask; + +iowrite32 (reg_val, &chip->reg->po); +spin_unlock_irqrestore (&chip->spinlock, flags); +} +static int pch_gpio_get (struct gpio_chip *gpio,unsigned nr) { struct pch_gpio *chip = container_of(gpio, struct pch_gpio, gpio);
@@ -129,6 +146,14 @@ static int pch_gpio_get(struct gpio_chipreturn ioread32 (&chip->reg->pi) & (1 << nr); } +static unsigned long pch_gpio_get_block (struct gpio_chip *gpio, +unsigned long mask) +{ + struct pch_gpio *chip = container_of(gpio, struct pch_gpio, gpio); + +return ioread32 (&chip->reg->pi) & mask; +} +static int pch_gpio_direction_output (struct gpio_chip *gpio,unsigned nr,int val) {
@@ -219,8 +244,10 @@ static void pch_gpio_setup(struct pch_gp gpio->owner =THIS_MODULE ; gpio->direction_input = pch_gpio_direction_input; gpio->get = pch_gpio_get; + gpio->get_block = pch_gpio_get_block; gpio->direction_output = pch_gpio_direction_output; gpio->set = pch_gpio_set; + gpio->set_block = pch_gpio_set_block; gpio->dbg_show =NULL ; gpio->base =-1 ; gpio->ngpio = gpio_pins[chip->ioh];
drivers/gpio/gpio-pl061.c +17 -0
@@ -118,6 +118,21 @@ static void pl061_set_value(struct gpio_writeb (!!value << offset, chip->base + (1 << (offset +2 ))); } +static unsigned long pl061_get_block (struct gpio_chip *gc,unsigned long mask) +{ + struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); + +return !!readb (chip->base + (mask <<2 )); +} + +static void pl061_set_block (struct gpio_chip *gc,unsigned long mask, +unsigned long values) +{ + struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); + +writeb (values & mask, chip->base + (mask <<2 )); +} +static int pl061_to_irq (struct gpio_chip *gc,unsigned offset) { struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc);
@@ -246,6 +261,8 @@ static int pl061_probe(struct amba_devic chip->gc.direction_output = pl061_direction_output; chip->gc.get = pl061_get_value; chip->gc.set = pl061_set_value; + chip->gc.get_block = pl061_get_block; + chip->gc.set_block = pl061_set_block; chip->gc.to_irq = pl061_to_irq; chip->gc.ngpio =PL061_GPIO_NR ; chip->gc.label =dev_name (dev);
drivers/gpio/gpio-sa1100.c +20 -0
@@ -27,6 +27,24 @@ static void sa1100_gpio_set(struct gpio_GPCR =GPIO_GPIO (offset); } +static unsigned long sa1100_gpio_get_block (struct gpio_chip *chip, +unsigned long mask) +{ +return GPLR & mask; +} + +static void sa1100_gpio_set_block (struct gpio_chip *chip,unsigned long mask, +unsigned long values) +{ +unsigned long set_bits = values & mask; +unsigned long clr_bits = ~values & mask; + +if (set_bits) +GPSR = set_bits; +if (clr_bits) +GPCR = clr_bits; +} +static int sa1100_direction_input (struct gpio_chip *chip,unsigned offset) {unsigned long flags;
@@ -59,6 +77,8 @@ static struct gpio_chip sa1100_gpio_chip .direction_output = sa1100_direction_output, .set = sa1100_gpio_set, .get = sa1100_gpio_get, + .set_block = sa1100_gpio_set_block, + .get_block = sa1100_gpio_get_block, .to_irq = sa1100_to_irq, .base = 0, .ngpio = GPIO_MAX + 1,
drivers/gpio/gpio-samsung.c +31 -0
@@ -862,6 +862,33 @@ static int samsung_gpiolib_get(struct gpreturn val; } +static void samsung_gpiolib_set_block (struct gpio_chip *chip, +unsigned long mask, +unsigned long values) +{ +struct samsung_gpio_chip *ourchip =to_samsung_gpio (chip); +void __iomem *base = ourchip->base; +unsigned long flags; +unsigned long dat; + +samsung_gpio_lock (ourchip, flags); + + dat =__raw_readl (base +0x04 ); + dat &= ~mask; + dat |= values & mask; +__raw_writel (dat, base +0x04 ); + +samsung_gpio_unlock (ourchip, flags); +} + +static unsigned long samsung_gpiolib_get_block (struct gpio_chip *chip, +unsigned long mask) +{ +struct samsung_gpio_chip *ourchip =to_samsung_gpio (chip); + +return __raw_readl (ourchip->base +0x04 ) & mask; +} +/* * CONFIG_S3C_GPIO_TRACK enables the tracking of the s3c specific gpios * for use with the configuration calls, and other parts of the s3c gpiolib
@@ -919,6 +946,10 @@ static void __init samsung_gpiolib_add(s gc->set = samsung_gpiolib_set;if (!gc->get) gc->get = samsung_gpiolib_get; +if (!gc->set_block) + gc->set_block = samsung_gpiolib_set_block; +if (!gc->get_block) + gc->get_block = samsung_gpiolib_get_block;#ifdef CONFIG_PM if (chip->pm !=NULL ) {
drivers/gpio/gpio-twl6040.c +32 -0
@@ -46,6 +46,19 @@ static int twl6040gpo_get(struct gpio_chreturn (ret >> offset) &1 ; } +static unsigned long twl6040gpo_get_block (struct gpio_chip *chip, +unsigned long mask) +{ +struct twl6040 *twl6040 =dev_get_drvdata (chip->dev->parent); +int ret =0 ; + + ret =twl6040_reg_read (twl6040,TWL6040_REG_GPOCTL ); +if (ret <0 ) +return 0 ; + +return ret & mask; +} +static int twl6040gpo_direction_out (struct gpio_chip *chip,unsigned offset,int value) {
@@ -71,12 +84,31 @@ static void twl6040gpo_set(struct gpio_ctwl6040_reg_write (twl6040,TWL6040_REG_GPOCTL , gpoctl); } +static void twl6040gpo_set_block (struct gpio_chip *chip,unsigned long mask, +unsigned long values) +{ +struct twl6040 *twl6040 =dev_get_drvdata (chip->dev->parent); +int ret; +u8 gpoctl; + + ret =twl6040_reg_read (twl6040,TWL6040_REG_GPOCTL ); +if (ret <0 ) +return ; + + gpoctl = ret & ~mask; + gpoctl |= values & mask; + +twl6040_reg_write (twl6040,TWL6040_REG_GPOCTL , gpoctl); +} +static struct gpio_chip twl6040gpo_chip = { .label ="twl6040" , .owner =THIS_MODULE , .get = twl6040gpo_get, + .get_block = twl6040gpo_get_block, .direction_output = twl6040gpo_direction_out, .set = twl6040gpo_set, + .set_block = twl6040gpo_set_block, .can_sleep =1 , };
drivers/gpio/gpio-ucb1400.c +23 -0
@@ -45,6 +45,27 @@ static void ucb1400_gpio_set(struct gpioucb1400_gpio_set_value (gpio->ac97, off, val); } +static unsigned long ucb1400_gpio_get_block (struct gpio_chip *gc, +unsigned long mask) +{ +struct ucb1400_gpio *gpio; + gpio = container_of(gc, struct ucb1400_gpio, gc); +return ucb1400_reg_read (gpio->ac97,UCB_IO_DATA ) & mask; +} + +static void ucb1400_gpio_set_block (struct gpio_chip *gc,unsigned long mask, +unsigned long values) +{ +struct ucb1400_gpio *gpio; +u16 tmp; + gpio = container_of(gc, struct ucb1400_gpio, gc); + + tmp =ucb1400_reg_read (gpio->ac97,UCB_IO_DATA ) & ~mask; + tmp |= values & mask; + +ucb1400_reg_write (gpio->ac97,UCB_IO_DATA , tmp); +} +static int ucb1400_gpio_probe (struct platform_device *dev) {struct ucb1400_gpio *ucb = dev->dev.platform_data;
@@ -66,6 +87,8 @@ static int ucb1400_gpio_probe(struct pla ucb->gc.direction_output = ucb1400_gpio_dir_out; ucb->gc.get = ucb1400_gpio_get; ucb->gc.set = ucb1400_gpio_set; + ucb->gc.get_block = ucb1400_gpio_get_block; + ucb->gc.set_block = ucb1400_gpio_set_block; ucb->gc.can_sleep =1 ; err =gpiochip_add (&ucb->gc);
drivers/gpio/gpio-vt8500.c +24 -0
@@ -211,6 +211,28 @@ static void vt8500_gpio_set_value(structwritel_relaxed (val, vt8500_chip->base + vt8500_chip->regs->data_out); } +static unsigned long vt8500_gpio_get_block (struct gpio_chip *chip, +unsigned long mask) +{ +struct vt8500_gpio_chip *vt8500_chip =to_vt8500 (chip); + +return readl_relaxed (vt8500_chip->base + vt8500_chip->regs->data_in) & + mask; +} + +static void vt8500_gpio_set_block (struct gpio_chip *chip,unsigned long mask, +unsigned long values) +{ +struct vt8500_gpio_chip *vt8500_chip =to_vt8500 (chip); + +u32 val =readl_relaxed (vt8500_chip->base + + vt8500_chip->regs->data_out); + val &= ~mask; + val |= values & mask; + +writel_relaxed (val, vt8500_chip->base + vt8500_chip->regs->data_out); +} +static int vt8500_of_xlate (struct gpio_chip *gc,const struct of_phandle_args *gpiospec,u32 *flags) {
@@ -253,6 +275,8 @@ static int vt8500_add_chips(struct platf chip->direction_output = vt8500_gpio_direction_output; chip->get = vt8500_gpio_get_value; chip->set = vt8500_gpio_set_value; + chip->get_block = vt8500_gpio_get_block; + chip->set_block = vt8500_gpio_set_block; chip->can_sleep =0 ; chip->base = pin_cnt; chip->ngpio = data->banks[i].ngpio;
drivers/gpio/gpio-xilinx.c +44 -0
62 lines not on this page · raw message
drivers/pinctrl/pinctrl-at91.c +29 -0
@@ -49,6 +49,7 @@ struct at91_gpio_chip {struct clk *clock;/* associated clock */ struct irq_domain *domain;/* associated irq domain */ struct at91_pinctrl_mux_ops *ops;/* ops */ +unsigned long mask_cache;/* cached mask for block gpio */ };#define to_at91_gpio_chip (c) container_of(c, struct at91_gpio_chip, chip)
@@ -1124,6 +1125,32 @@ static void at91_gpio_set(struct gpio_chwritel_relaxed (mask, pio + (val ?PIO_SODR :PIO_CODR )); } +static unsigned long at91_gpio_get_block (struct gpio_chip *chip, +unsigned long mask) +{ +struct at91_gpio_chip *at91_gpio =to_at91_gpio_chip (chip); +void __iomem *pio = at91_gpio->regbase; +u32 pdsr; + + pdsr =readl_relaxed (pio +PIO_PDSR ); +return pdsr & mask; +} + +static void at91_gpio_set_block (struct gpio_chip *chip,unsigned long mask, +unsigned long val) +{ +struct at91_gpio_chip *at91_gpio =to_at91_gpio_chip (chip); +void __iomem *pio = at91_gpio->regbase; + +/* Do synchronous data output with a single write access */ +if (mask != at91_gpio->mask_cache) { + at91_gpio->mask_cache = mask; +writel_relaxed (~mask, pio +PIO_OWDR ); +writel_relaxed (mask, pio +PIO_OWER ); + } +writel_relaxed (val, pio +PIO_ODSR ); +} +static int at91_gpio_direction_output (struct gpio_chip *chip,unsigned offset,int val) {
@@ -1434,8 +1461,10 @@ static struct gpio_chip at91_gpio_templa .free = at91_gpio_free, .direction_input = at91_gpio_direction_input, .get = at91_gpio_get, + .get_block = at91_gpio_get_block, .direction_output = at91_gpio_direction_output, .set = at91_gpio_set, + .set_block = at91_gpio_set_block, .to_irq = at91_gpio_to_irq, .dbg_show = at91_gpio_dbg_show, .can_sleep = 0,
drivers/pinctrl/pinctrl-nomadik.c +36 -0
@@ -1069,6 +1069,40 @@ static void nmk_gpio_set_output(struct gclk_disable (nmk_chip->clk); } +static unsigned long nmk_gpio_get_block (struct gpio_chip *chip, +unsigned long mask) +{ +struct nmk_gpio_chip *nmk_chip = + container_of(chip, struct nmk_gpio_chip, chip); +unsigned long values; + +clk_enable (nmk_chip->clk); + + values =readl (nmk_chip->addr +NMK_GPIO_DAT ); + +clk_disable (nmk_chip->clk); + +return values & mask; +} + +static void nmk_gpio_set_block (struct gpio_chip *chip,unsigned long mask, +unsigned long values) +{ +struct nmk_gpio_chip *nmk_chip = + container_of(chip, struct nmk_gpio_chip, chip); +unsigned long set_bits = values & mask; +unsigned long clr_bits = ~values & mask; + +clk_enable (nmk_chip->clk); + +if (set_bits) +writel (set_bits, nmk_chip->addr +NMK_GPIO_DATS ); +if (clr_bits) +writel (clr_bits, nmk_chip->addr +NMK_GPIO_DATC ); + +clk_disable (nmk_chip->clk); +} +static int nmk_gpio_make_output (struct gpio_chip *chip,unsigned offset,int val) {
@@ -1188,8 +1222,10 @@ static struct gpio_chip nmk_gpio_templat .free = nmk_gpio_free, .direction_input = nmk_gpio_make_input, .get = nmk_gpio_get_input, + .get_block = nmk_gpio_get_block, .direction_output = nmk_gpio_make_output, .set = nmk_gpio_set_output, + .set_block = nmk_gpio_set_block, .to_irq = nmk_gpio_to_irq, .dbg_show = nmk_gpio_dbg_show, .can_sleep = 0,
Re: [PATCH 6/6 v14] gpio: Add block gpio to several gpio drivers
Quoted 24 lines · Roland Stigge
This patch adds block GPIO support to several gpio drivers.
This implements block GPIO only for some selected drivers since block GPIO is an optional feature which may not be suitable for every GPIO hardware. (With automatic fallback to the single GPIO functions if not available in a driver.)
Signed-off-by Roland Stigge <[email protected]>For
pinctrl-at91.c:Acked-by Nicolas Ferre <[email protected]>---
drivers/gpio/gpio-lpc32xx.c +11
-0+static void lpc32xx_gpio_set_block_p3 (struct gpio_chip *chip, +unsigned long mask, +unsigned long values) +{ +struct lpc32xx_gpio_chip *group =to_lpc32xx_gpio (chip); +u32 set_bits = values & mask; +u32 clr_bits = ~values & mask; + +/* States of GPIO 0-5 start at bit 25 */ + set_bits <<=25 ; + clr_bits <<=25 ;
drivers/gpio/gpio-lpc32xx.c static void lpc32xx_gpio_set_value_p3(st · line 399
Quoted 10 lines
drivers/gpio/gpio-lpc32xx.c +10
-0+ +/* Note: On LPC32xx, GPOs can only be set at once or cleared at once, +* but not set and cleared at once +*/ +if (set_bits) +__raw_writel (set_bits, group->gpio_grp->outp_set); +if (clr_bits) +__raw_writel (clr_bits, group->gpio_grp->outp_clr); +} +
In my patch, I go out of the way of this kind of thing for a simple reason:
You may generate incorrect timing by doing this.
As a fictive example, consider the i2c-bitbang driver, which you could optimize by using block-gpio with sda/scl in a single block. By offering the block-gpio API
even when you cannot set all bits at once, you could cause timing issues. You might be toggling the clock line before pushing out data, for example.
The same holds below, for a driver that has separate hi/lo bits.
Regards,
Stijn
Re: [PATCH 6/6 v14] gpio: Add block gpio to several gpio drivers
Quoted 7 lines · Stijn Devriendt
As a fictive example, consider the i2c-bitbang driver, which you could optimize by using block-gpio with sda/scl in a single block. By offering the block-gpio API
even when you cannot set all bits at once, you could cause timing issues. You might be toggling the clock line before pushing out data, for example.The same holds below, for a driver that has separate hi/lo bits.
If there's a strict ordering requirement on updates then I would expect
a user to explictly code that in hardware otherwise there may be
hardware level issues with unpredictable results; besides in general it
seems silly to force users to open code both versions if they don't want
to rely on this API.
-------------- 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/20130124/6f8b79d6/attachment.sig>
Re: [PATCH 6/6 v14] gpio: Add block gpio to several gpio drivers
In reply to Stijn DevriendtQuoted 16 lines · Stijn Devriendt
Quoted 16 lines
drivers/gpio/gpio-lpc32xx.c +16
-0+static void lpc32xx_gpio_set_block_p3 (struct gpio_chip *chip, +unsigned long mask, +unsigned long values) +{ +struct lpc32xx_gpio_chip *group =to_lpc32xx_gpio (chip); +u32 set_bits = values & mask; +u32 clr_bits = ~values & mask; + +/* States of GPIO 0-5 start at bit 25 */ + set_bits <<=25 ; + clr_bits <<=25 ; + +/* Note: On LPC32xx, GPOs can only be set at once or cleared at once, +* but not set and cleared at once +*/ +if (set_bits)
Quoted 8 lines
drivers/gpio/gpio-lpc32xx.c static void lpc32xx_gpio_set_value_p3(st · line 399
Quoted 5 lines
drivers/gpio/gpio-lpc32xx.c +5
-0+__raw_writel (set_bits, group->gpio_grp->outp_set); +if (clr_bits) +__raw_writel (clr_bits, group->gpio_grp->outp_clr); +} +In my patch, I go out of the way of this kind of thing for a simple reason:
You may generate incorrect timing by doing this.
You are right, certain things like synchronous on+off is not really possible.
However, the above at least supports switching on simulaneously, and switching off simultaneously, which is an improvement in certain cases (and this certain hardware part doesn't support more). Maybe this certain driver behaviour can be documented even better than just in the driver source.
If there is consensus that everything else in the patch set is settled, and we just don't want to support behaviour like the above - well, we can still drop it.
Thanks for the note,
Roland
Re: [PATCH 6/6 v14] gpio: Add block gpio to several gpio drivers
Quoted 26 lines · Roland Stigge
Quoted 16 lines · Stijn Devriendt
Quoted 16 lines
drivers/gpio/gpio-lpc32xx.c +16
-0+static void lpc32xx_gpio_set_block_p3 (struct gpio_chip *chip, +unsigned long mask, +unsigned long values) +{ +struct lpc32xx_gpio_chip *group =to_lpc32xx_gpio (chip); +u32 set_bits = values & mask; +u32 clr_bits = ~values & mask; + +/* States of GPIO 0-5 start at bit 25 */ + set_bits <<=25 ; + clr_bits <<=25 ; + +/* Note: On LPC32xx, GPOs can only be set at once or cleared at once, +* but not set and cleared at once +*/ +if (set_bits)Quoted 8 lines
drivers/gpio/gpio-lpc32xx.c static void lpc32xx_gpio_set_value_p3(st · line 399
Quoted 5 lines
drivers/gpio/gpio-lpc32xx.c +5
-0+__raw_writel (set_bits, group->gpio_grp->outp_set); +if (clr_bits) +__raw_writel (clr_bits, group->gpio_grp->outp_clr); +} +In my patch, I go out of the way of this kind of thing for a simple reason:
You may generate incorrect timing by doing this.
Quoted 9 lines
You are right, certain things like synchronous on+off is not really possible.
However, the above at least supports switching on simulaneously, and switching off simultaneously, which is an improvement in certain cases (and this certain hardware part doesn't support more). Maybe this certain driver behaviour can be documented even better than just in the driver source.
The question here is: do you expect a user of the block-GPIO API to go look into the base-driver code to see what will be supported?
In my version of the patch this means:
- do not provide a single GPIO-block that crosses multiple base-drivers
- only provide gpio_block_get/set for GPIO drivers that support the complete operation in a single go. (for example, in the above example there would be no gpio_block_set() function)
Perhaps the best approach is to make this explicit: Allow drivers to expose their capabilities wrt timing and allow users to request strict-timing or loose-timing. Loose-timing allows multiple gpio-drivers to be combined and allows drivers with separate set/clear, hi/lo registers to be used. Of course, for a first version you may as well leave it out. Perhaps the use-cases for cross-GPIO-driver blocks are not worth the extra complexity as of today?
Regards,
Stijn
Quoted 8 lines
If there is consensus that everything else in the patch set is settled, and we just don't want to support behaviour like the above - well, we can still drop it.
Thanks for the note,
Roland
Re: [PATCH 6/6 v14] gpio: Add block gpio to several gpio drivers
Quoted 22 lines · Stijn Devriendt
Quoted 12 lines
Quoted 2 lines
In my patch, I go out of the way of this kind of thing for a simple reason:
You may generate incorrect timing by doing this.You are right, certain things like synchronous on+off is not really possible.
However, the above at least supports switching on simulaneously, and switching off simultaneously, which is an improvement in certain cases (and this certain hardware part doesn't support more). Maybe this certain driver behaviour can be documented even better than just in the driver source.
The question here is: do you expect a user of the block-GPIO API to go look into the base-driver code to see what will be supported?
In my version of the patch this means:
- do not provide a single GPIO-block that crosses multiple base-drivers
- only provide gpio_block_get/set for GPIO drivers that support the complete operation in a single go. (for example, in the above example there would be nogpio_block_set()function)
Quoted 4 lines
Perhaps the best approach is to make this explicit: Allow drivers to expose their capabilities wrt timing and allow users to request strict-timing or loose-timing. Loose-timing allows multiple gpio-drivers to be combined and allows drivers with separate set/clear, hi/lo registers to be used.
Interesting idea. However, it will be difficult to agree on good metrics here. As Mark Brown pointed out, even when hardware seems to support "simultaneousness" by registers, this doesn't actually mean that voltage levels are switched simultaneously wrt. sub-nanosecond timing.
Also, it depends on further wiring between the actually supported GPIO hardware chip and the integrated device's I/O connections.
Resulting in scenarios where GPIO chips (in terms of Linux drivers) without explicit I/O set registers (e.g., set/clear regs) could be "more simultaneous" than those having explicit I/O regs but hardware wiring leading to bad "simultaneousness" behaviour.
Questionable if the kernel could address those details.
Quoted 3 lines
Of course, for a first version you may as well leave it out. Perhaps the use-cases for cross-GPIO-driver blocks are not worth the extra complexity as of today?
I actually started the current block gpio patches to support this kind of use case. :-)
Roland
Re: [PATCH 6/6 v14] gpio: Add block gpio to several gpio drivers
Quoted 36 lines · Roland Stigge
Quoted 22 lines · Stijn Devriendt
Quoted 12 lines
Quoted 2 lines
In my patch, I go out of the way of this kind of thing for a simple reason:
You may generate incorrect timing by doing this.You are right, certain things like synchronous on+off is not really possible.
However, the above at least supports switching on simulaneously, and switching off simultaneously, which is an improvement in certain cases (and this certain hardware part doesn't support more). Maybe this certain driver behaviour can be documented even better than just in the driver source.
The question here is: do you expect a user of the block-GPIO API to go look into the base-driver code to see what will be supported?
In my version of the patch this means:
- do not provide a single GPIO-block that crosses multiple base-drivers
- only provide gpio_block_get/set for GPIO drivers that support the complete operation in a single go. (for example, in the above example there would be nogpio_block_set()function)Quoted 4 lines
Perhaps the best approach is to make this explicit: Allow drivers to expose their capabilities wrt timing and allow users to request strict-timing or loose-timing. Loose-timing allows multiple gpio-drivers to be combined and allows drivers with separate set/clear, hi/lo registers to be used.
Interesting idea. However, it will be difficult to agree on good metrics here. As Mark Brown pointed out, even when hardware seems to support "simultaneousness" by registers, this doesn't actually mean that voltage levels are switched simultaneously wrt. sub-nanosecond timing.
Also, it depends on further wiring between the actually supported GPIO hardware chip and the integrated device's I/O connections.
Quoted 7 lines
Resulting in scenarios where GPIO chips (in terms of Linux drivers) without explicit I/O set registers (e.g., set/clear regs) could be "more simultaneous" than those having explicit I/O regs but hardware wiring leading to bad "simultaneousness" behaviour.
Questionable if the kernel could address those details.
True, but does the kernel _need_ to address that? If this is fixed at the kernel level, at least the kernel is not the cause of the effect. Strict-timing could mean as much as "the kernel will do everything it can (int this case impose limits) to make sure timings are strict - actual results may
depend on your H/W".
It allows graceful degradation at the driver level (e.g. fallback to requesting separate pins and toggling them in the right order - or calling the request function again with loose-timing + dev_warn(... "things may break!") )
OTOH, is it worth it? There may be extra work involved when doing the latter. Usage of block GPIO for things like emulating busses will need testing anyway.
Quoted 6 lines
Quoted 3 lines
Of course, for a first version you may as well leave it out. Perhaps the use-cases for cross-GPIO-driver blocks are not worth the extra complexity as of today?
I actually started the current block gpio patches to support this kind of use case. :-)
Right, our use-cases were less advanced... ;)
Regards,
Stijn
Quoted 2 lines
Roland