gpio: Add block GPIO
Subsystems (11)
v10 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
* Fix for race condition in gpiolib on device creation
Tested by: Wolfgang Grandegger <[email protected]> --
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 and Wolfgang Grandegger for reviewing!
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/Makefile | 1 drivers/gpio/gpio-em.c | 23 drivers/gpio/gpio-generic.c | 56 + drivers/gpio/gpio-lpc32xx.c | 82 + drivers/gpio/gpio-max730x.c | 61 + drivers/gpio/gpio-max732x.c | 59 + 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-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 | 84 + drivers/gpio/gpiolib.c | 780 ++++++++++++++++-- include/asm-generic/gpio.h | 28 include/linux/gpio.h | 125 ++ 22 files changed, 1666 insertions(+), 47 deletions(-)
PATCH RESEND v10 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
@@ -439,6 +439,64 @@ slower clock delays the rising edge of S signaling rate accordingly. +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
@@ -43,6 +43,7 @@ static inline bool gpio_is_valid(int numstruct device ;struct gpio ; +struct gpio_block ;struct seq_file ;struct module ;struct device_node ;
@@ -105,6 +106,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,
@@ -112,6 +115,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);
@@ -171,6 +177,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
PATCH RESEND v10 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 | 250 ++++++++++++++++++++++++++++++++++- include/asm-generic/gpio.h | 11 + include/linux/gpio.h | 15 ++ 4 files changed, 295 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 +249 -1
292 lines not on this page · raw message
include/asm-generic/gpio.h +11 -0
@@ -213,6 +213,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 */
@@ -272,6 +274,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 */ #endif /* _ASM_GENERIC_GPIO_H */
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 RESEND v10 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 | 224 +++++++++++++++++++++++++++++++- include/linux/gpio.h | 13 + 3 files changed, 270 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 +223 -1
253 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
PATCH RESEND v10 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 | 79 +++++++++++++++-------------------- 2 files changed, 45 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 +34 -45
153 lines not on this page · raw message
PATCH RESEND v10 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 | 84 ++++++++++++++++++ 3 files changed, 121 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
@@ -4,6 +4,7 @@ ccflags-$(CONFIG_DEBUG_GPIO) += -DDEBUG obj-$(CONFIG_GPIOLIB) += gpiolib.o devres.o obj-$(CONFIG_OF_GPIO) += gpiolib-of.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 +84 -0
84 lines not on this page · raw message
Re: [PATCH RESEND 5/6 v10] gpio: Add device tree support to block GPIO API
Hi,
I have a few comments on the parsing code.
Quoted 86 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 | 84 ++++++++++++++++++ 3 files changed, 121 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@@ -4,6 +4,7 @@ ccflags-$(CONFIG_DEBUG_GPIO) += -DDEBUG obj-$(CONFIG_GPIOLIB) += gpiolib.o devres.o obj-$(CONFIG_OF_GPIO) += gpiolib-of.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 +24
-0@@ -0,0 +1,84 @@ +/* +* 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 __devinit gpioblock_of_probe (struct platform_device *pdev) +{ +struct device_node *block;
drivers/gpio/gpioblock-of.c line 34
Quoted 10 lines
drivers/gpio/gpioblock-of.c new file +10
-0+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); + gpios =kzalloc (ngpio *sizeof (*gpios),GFP_KERNEL );
What if the block node is malformed? ngpio might be -ENOENT or -EINVAL.
drivers/gpio/gpioblock-of.c line 47
Quoted 13 lines
drivers/gpio/gpioblock-of.c new file +13
-0+if (!gpios) +return -ENOMEM ; +for (i =0 ; i < ngpio; i++) { + ret =of_get_gpio (block, i); +if (ret <0 ) +return ret;/* 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" ); +return PTR_ERR (gb);
Won't this leak the memory for the gpios object we kzalloc'd earlier?
drivers/gpio/gpioblock-of.c line 52
Quoted 5 lines
drivers/gpio/gpioblock-of.c new file +5
-0+ } + ret =gpio_block_register (gb); +if (ret <0 ) { +gpio_block_free (gb); +return ret;
Same here.
drivers/gpio/gpioblock-of.c line 56
Quoted 4 lines
drivers/gpio/gpioblock-of.c new file +4
-0+ } +kfree (gpios); +dev_info (&pdev->dev,"Registered gpio block %s: %d gpios\n" , + block->name, ngpio);
Any of the returns in this block will leave the block node's refcount incremented.
Quoted 19 lines
drivers/gpio/gpioblock-of.c new file +18
-0+ } +return 0 ; +} + +#ifdef CONFIG_OF +static struct of_device_id gpioblock_of_match[]__devinitdata = { + { .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), +
drivers/gpio/gpioblock-of.c line 84
Quoted 10 lines
drivers/gpio/gpioblock-of.c new file +10
-0+ }, + .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" );
Thanks,
Mark.
Re: [PATCH RESEND 5/6 v10] gpio: Add device tree support to block GPIO API
Hi Mark,
Quoted 7 lines · Mark Rutland
Quoted 7 lines
drivers/gpio/gpioblock-of.c new file +7
-0+static int __devinit gpioblock_of_probe (struct platform_device *pdev) +{ +struct device_node *block; +unsigned *gpios; +int ngpio; +int ret; +struct gpio_block *gb;
Quoted 8 lines
drivers/gpio/gpioblock-of.c line 34
Quoted 6 lines
drivers/gpio/gpioblock-of.c new file +6
-0+ +for_each_available_child_of_node (pdev->dev.of_node, block) { +int i; + + ngpio =of_gpio_count (block); + gpios =kzalloc (ngpio *sizeof (*gpios),GFP_KERNEL );What if the block node is malformed? ngpio might be
-ENOENTor-EINVAL.
AFAICS, of_gpio_count() always returns at least 0. Both if CONFIG_OF_GPIO is y, m or n. And called of_gpio_named_count() also currently doesn't return error values. Further, other drivers using of_gpio_count() don't expect or catch <0.
However, it's reasonable to guard against of_gpio_count() < 1 since probing without provided blocks should be void.
Will change this for the next patch update together with your leakage findings.
Thanks for reporting!
Roland
Re: [PATCH RESEND 5/6 v10] gpio: Add device tree support to block GPIO API
Quoted 19 lines · Roland Stigge
Hi Mark,
Quoted 7 lines · Mark Rutland
Quoted 7 lines
drivers/gpio/gpioblock-of.c new file +7
-0+static int __devinit gpioblock_of_probe (struct platform_device *pdev) +{ +struct device_node *block; +unsigned *gpios; +int ngpio; +int ret; +struct gpio_block *gb;Quoted 8 lines
drivers/gpio/gpioblock-of.c line 34
Quoted 6 lines
drivers/gpio/gpioblock-of.c new file +6
-0+ +for_each_available_child_of_node (pdev->dev.of_node, block) { +int i; + + ngpio =of_gpio_count (block); + gpios =kzalloc (ngpio *sizeof (*gpios),GFP_KERNEL );What if the block node is malformed? ngpio might be
-ENOENTor-EINVAL.
Quoted 4 lines
AFAICS,
of_gpio_count()always returns at least 0. Both ifCONFIG_OF_GPIOis y, m or n. And calledof_gpio_named_count()also currently doesn't return error values. Further, other drivers usingof_gpio_count()don't expect or catch <0.
Whoops. I'd managed to misread the logic in of_gpio_named_count, sorry.
Quoted 9 lines
However, it's reasonable to guard against
of_gpio_count()< 1 since probing without provided blocks should be void.Will change this for the next patch update together with your leakage findings.
Thanks for reporting!
Roland
Sounds good!
Thanks,
Mark.
PATCH RESEND v10 6/6 gpio: Add block gpio to several gpio drivers
In reply to Roland StiggeThis patch adds block GPIO support to several gpio drivers.
--- drivers/gpio/gpio-em.c | 23 ++++++++++++ drivers/gpio/gpio-generic.c | 56 ++++++++++++++++++++++++++++++ drivers/gpio/gpio-lpc32xx.c | 82 ++++++++++++++++++++++++++++++++++++++++++++ drivers/gpio/gpio-max730x.c | 61 ++++++++++++++++++++++++++++++++ drivers/gpio/gpio-max732x.c | 59 +++++++++++++++++++++++++++++++ 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-twl6040.c | 32 +++++++++++++++++ drivers/gpio/gpio-ucb1400.c | 23 ++++++++++++ drivers/gpio/gpio-vt8500.c | 24 ++++++++++++ drivers/gpio/gpio-xilinx.c | 44 +++++++++++++++++++++++ 13 files changed, 536 insertions(+)
drivers/gpio/gpio-em.c +23 -0
@@ -203,6 +203,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) {
@@ -317,8 +338,10 @@ static int __devinit em_gio_probe(struct 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-generic.c +56 -0
82 lines not on this page · raw message
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-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) {
@@ -218,8 +243,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
@@ -123,6 +123,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);
@@ -256,6 +271,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->dev);
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
@@ -209,6 +209,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) {
@@ -251,6 +273,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
Quoted 10 lines · Roland Stigge
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
* Fix for race condition in gpiolib on device creation
Quoted 2 lines
Signed-off-by Roland Stigge <[email protected]>Tested by: Wolfgang Grandegger <[email protected]>
I'm going to re-test this version next week. Attached you will find my GPIO block adoptions for the AT91.
Wolfgang
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-gpio-add-GPIO-block-callback-functions-for-AT91.patch
Type: text/x-diff
Size: 2721 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20121214/29dc065d/attachment-0001.bin>
Hi Wolfgang,
thank you for the patch!
Review
Quoted 8 lines · Wolfgang Grandegger
(quoted diff) +8
-0+static void at91_gpiolib_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; + + __raw_writel(mask, pio + (val ? PIO_SODR : PIO_CODR)); +} +
Without having an AT91 available right now, I guess the hardware interface of this GPIO chip is different from the GPIO block API. While the hardware has clear and set registers, the val parameter of at91_gpiolib_set_block() should be interpreted as the actual output values. See lpc32xx_gpo_set_block() for an example for handling set and clear registers like this: First, set_bits and clear_bits words are calculated from mask and val parameters, and finally written to the respective hardware registers.
Note that one .set_block() can result in writing both the set and clear registers of the hardware when val contains both 0s and 1s in respectively masked positions.
Roland
Quoted 9 lines · Roland Stigge
Without having an AT91 available right now, I guess the hardware interface of this GPIO chip is different from the GPIO block API. While the hardware has clear and set registers, the val parameter of
at91_gpiolib_set_block()should be interpreted as the actual output values. Seelpc32xx_gpo_set_block()for an example for handling set and clear registers like this: First,set_bitsandclear_bitswords are calculated from mask and val parameters, and finally written to the respective hardware registers.
Quoted 3 lines
Note that one .set_block() can result in writing both the set and clear registers of the hardware when val contains both 0s and 1s in respectively masked positions.
Note also that if this is the same IP as found in SAM3N devices, that it's possible to write the bit values directly through the OWER/OWDR (output write enable register/disable register) plus the ODSR (output data status register) which will synchronously change the state of all the write-enabled output pins. That may be important for some applications.
Hi Roland,
Quoted 23 lines · Roland Stigge
Hi Wolfgang,
thank you for the patch!
Review
Quoted 8 lines · Wolfgang Grandegger
(quoted diff) +8
-0+static void at91_gpiolib_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; + + __raw_writel(mask, pio + (val ? PIO_SODR : PIO_CODR)); +} +Without having an AT91 available right now, I guess the hardware interface of this GPIO chip is different from the GPIO block API. While the hardware has clear and set registers, the val parameter of
at91_gpiolib_set_block()should be interpreted as the actual output values. Seelpc32xx_gpo_set_block()for an example for handling set and clear registers like this: First,set_bitsandclear_bitswords are calculated from mask and val parameters, and finally written to the respective hardware registers.
Quoted 3 lines
Note that one .set_block() can result in writing both the set and clear registers of the hardware when val contains both 0s and 1s in respectively masked positions.
Oops, I obviously did not test GPIO block write. The patch below does work now. Feel free to add it to the next version of your series.
I tested with a block having both, inputs and outputs. The handling of such a mixed block is clumsy because both, read and write do depend on "block->cur_mask". It needs to be re-set when switching from read to write or vice versa. Defining two blocks, one for input and the other for output seems to be the better solution.
Hope this block gpio support will show up in mainline soon.
Thanks.
Wolfgang.
Quoted 1 line
From
6249995d129b290704cacb2c0114782414abeba7Mon Sep 17 00:00:00 2001
From: Wolfgang Grandegger <[email protected]>
Date: Mon, 3 Dec 2012 08:31:55 +0100
Subject: [PATCH 1/2] gpio: add GPIO block callback functions for AT91
--- arch/arm/mach-at91/gpio.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
arch/arm/mach-at91/gpio.c +28 -0
@@ -48,7 +48,9 @@ struct at91_gpio_chip {static void at91_gpiolib_dbg_show (struct seq_file *s,struct gpio_chip *chip);static void at91_gpiolib_set (struct gpio_chip *chip,unsigned offset,int val); +static void at91_gpiolib_set_block (struct gpio_chip *chip,unsigned long mask,unsigned long val);static int at91_gpiolib_get (struct gpio_chip *chip,unsigned offset); +static unsigned long at91_gpiolib_get_block (struct gpio_chip *chip,unsigned long mask);static int at91_gpiolib_direction_output (struct gpio_chip *chip,unsigned offset,int val); static int at91_gpiolib_direction_input(struct gpio_chip *chip,
@@ -62,7 +64,9 @@ static int at91_gpiolib_to_irq(struct gpio_chip *chip, unsigned offset); .direction_input = at91_gpiolib_direction_input, \ .direction_output = at91_gpiolib_direction_output, \ .get = at91_gpiolib_get, \ + .get_block = at91_gpiolib_get_block, \ .set = at91_gpiolib_set, \ + .set_block = at91_gpiolib_set_block, \ .dbg_show = at91_gpiolib_dbg_show, \ .to_irq = at91_gpiolib_to_irq, \ .ngpio = nr_gpio, \
@@ -896,6 +900,16 @@ static int at91_gpiolib_get(struct gpio_chip *chip, unsigned offset)return (pdsr & mask) !=0 ; } +static unsigned long at91_gpiolib_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 =__raw_readl (pio +PIO_PDSR ); +return pdsr & mask; +} +static void at91_gpiolib_set (struct gpio_chip *chip,unsigned offset,int val) {struct at91_gpio_chip *at91_gpio =to_at91_gpio_chip (chip);
@@ -905,6 +919,20 @@ static void at91_gpiolib_set(struct gpio_chip *chip, unsigned offset, int val)__raw_writel (mask, pio + (val ?PIO_SODR :PIO_CODR )); } +static void at91_gpiolib_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; +u32 set_bits = values & mask; +u32 clr_bits = ~values & mask; + +/* GPIO outputs can only be set at once or cleared at once */ +if (set_bits) +__raw_writel (set_bits, pio +PIO_SODR ); +if (clr_bits) +__raw_writel (clr_bits, pio +PIO_CODR ); +} +static void at91_gpiolib_dbg_show (struct seq_file *s,struct gpio_chip *chip) {int i;
Signature · 1 line
1.7.9.5
Quoted 26 lines · Wolfgang Grandegger
Hi Roland,
Quoted 23 lines · Roland Stigge
Hi Wolfgang,
thank you for the patch!
Review
Quoted 8 lines · Wolfgang Grandegger
(quoted diff) +8
-0+static void at91_gpiolib_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; + + __raw_writel(mask, pio + (val ? PIO_SODR : PIO_CODR)); +} +Without having an AT91 available right now, I guess the hardware interface of this GPIO chip is different from the GPIO block API. While the hardware has clear and set registers, the val parameter of
at91_gpiolib_set_block()should be interpreted as the actual output values. Seelpc32xx_gpo_set_block()for an example for handling set and clear registers like this: First,set_bitsandclear_bitswords are calculated from mask and val parameters, and finally written to the respective hardware registers.
Quoted 6 lines
Quoted 3 lines
Note that one .set_block() can result in writing both the set and clear registers of the hardware when val contains both 0s and 1s in respectively masked positions.
Oops, I obviously did not test GPIO block write. The patch below does work now. Feel free to add it to the next version of your series.
The patch lacks an important fix, sorry. Please consider the updated patch below.
Wolfgang.
Quoted 1 line
From
a1f93ddea9c6c9c6a80d7a02d3c8d9902823fe47Mon Sep 17 00:00:00 2001
From: Wolfgang Grandegger <[email protected]>
Date: Mon, 3 Dec 2012 08:31:55 +0100
Subject: [PATCH 1/2] gpio: add GPIO block callback functions for AT91
--- arch/arm/mach-at91/gpio.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
arch/arm/mach-at91/gpio.c +28 -0
@@ -48,7 +48,9 @@ struct at91_gpio_chip {static void at91_gpiolib_dbg_show (struct seq_file *s,struct gpio_chip *chip);static void at91_gpiolib_set (struct gpio_chip *chip,unsigned offset,int val); +static void at91_gpiolib_set_block (struct gpio_chip *chip,unsigned long mask,unsigned long val);static int at91_gpiolib_get (struct gpio_chip *chip,unsigned offset); +static unsigned long at91_gpiolib_get_block (struct gpio_chip *chip,unsigned long mask);static int at91_gpiolib_direction_output (struct gpio_chip *chip,unsigned offset,int val); static int at91_gpiolib_direction_input(struct gpio_chip *chip,
@@ -62,7 +64,9 @@ static int at91_gpiolib_to_irq(struct gpio_chip *chip, unsigned offset); .direction_input = at91_gpiolib_direction_input, \ .direction_output = at91_gpiolib_direction_output, \ .get = at91_gpiolib_get, \ + .get_block = at91_gpiolib_get_block, \ .set = at91_gpiolib_set, \ + .set_block = at91_gpiolib_set_block, \ .dbg_show = at91_gpiolib_dbg_show, \ .to_irq = at91_gpiolib_to_irq, \ .ngpio = nr_gpio, \
@@ -896,6 +900,16 @@ static int at91_gpiolib_get(struct gpio_chip *chip, unsigned offset)return (pdsr & mask) !=0 ; } +static unsigned long at91_gpiolib_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 =__raw_readl (pio +PIO_PDSR ); +return pdsr & mask; +} +static void at91_gpiolib_set (struct gpio_chip *chip,unsigned offset,int val) {struct at91_gpio_chip *at91_gpio =to_at91_gpio_chip (chip);
@@ -905,6 +919,20 @@ static void at91_gpiolib_set(struct gpio_chip *chip, unsigned offset, int val)__raw_writel (mask, pio + (val ?PIO_SODR :PIO_CODR )); } +static void at91_gpiolib_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; +u32 set_bits = val & mask; +u32 clr_bits = ~val & mask; + +/* GPIO outputs can only be set at once or cleared at once */ +if (set_bits) +__raw_writel (set_bits, pio +PIO_SODR ); +if (clr_bits) +__raw_writel (clr_bits, pio +PIO_CODR ); +} +static void at91_gpiolib_dbg_show (struct seq_file *s,struct gpio_chip *chip) {int i;
Signature · 1 line
1.7.9.5
arch/arm/mach-at91/gpio.c static void at91_gpiolib_set(struct gpio_chip *chip, unsigned offset, int val) · line 934
Quoted 13 lines · Wolfgang Grandegger
arch/arm/mach-at91/gpio.c +13
-0+static void at91_gpiolib_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; +u32 set_bits = val & mask; +u32 clr_bits = ~val & mask; + +/* GPIO outputs can only be set at once or cleared at once */ +if (set_bits) +__raw_writel (set_bits, pio +PIO_SODR ); +if (clr_bits) +__raw_writel (clr_bits, pio +PIO_CODR ); +}
You obviously didn't see my email...
Quoted 16 lines · Russell King - ARM Linux
arch/arm/mach-at91/gpio.c static void at91_gpiolib_set(struct gpio_chip *chip, unsigned offset, int val) · line 934
Quoted 13 lines · Wolfgang Grandegger
arch/arm/mach-at91/gpio.c +13
-0+static void at91_gpiolib_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; +u32 set_bits = val & mask; +u32 clr_bits = ~val & mask; + +/* GPIO outputs can only be set at once or cleared at once */ +if (set_bits) +__raw_writel (set_bits, pio +PIO_SODR ); +if (clr_bits) +__raw_writel (clr_bits, pio +PIO_CODR ); +}You obviously didn't see my email...
Well, I did read you mail but it was not obvious to me how to maintain compatibility with the existing "set" method... at a first glance. But the synchronous data output is important and it's even simpler than I thought. The block-set callback can directly write to ODSR because "at91_set_gpio_output()" already has set OWER. Will give that a try later today.
Wolfgang.
Quoted 13 lines · Wolfgang Grandegger
Quoted 13 lines
Quoted 12 lines
Without having an AT91 available right now, I guess the hardware interface of this GPIO chip is different from the GPIO block API. While the hardware has clear and set registers, the val parameter of
at91_gpiolib_set_block()should be interpreted as the actual output values. Seelpc32xx_gpo_set_block()for an example for handling set and clear registers like this: First,set_bitsandclear_bitswords are calculated from mask and val parameters, and finally written to the respective hardware registers.Note that one .set_block() can result in writing both the set and clear registers of the hardware when val contains both 0s and 1s in respectively masked positions.
Quoted 5 lines
Quoted 2 lines
Oops, I obviously did not test GPIO block write. The patch below does work now. Feel free to add it to the next version of your series.
The patch lacks an important fix, sorry. Please consider the updated patch below.
Thanks!
And I guess Russell is right: If possible, we should write outputs simultaneously via ODSR (plus OWER/OWDR/OWSR) instead of separate set/clear.
I wonder if we need to save/restore the state of OWSR at every write operation or if we need/can cache it. Assuming that block GPIO are the only code in the kernel that manipulates ODSR.
Further: Can we include this patch for arch/arm/mach-at91 via the gpio subsystem or does it need to go separately via arm-soc.git?
Thanks,
Roland
Hi Wolfgang,
Quoted 6 lines · Roland Stigge
And I guess Russell is right: If possible, we should write outputs simultaneously via ODSR (plus OWER/OWDR/OWSR) instead of separate set/clear.
I wonder if we need to save/restore the state of OWSR at every write operation or if we need/can cache it. Assuming that block GPIO are the only code in the kernel that manipulates ODSR.
Can you please test the following:
+static void at91_gpiolib_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;
+
+ __raw_writel(~mask, pio + PIO_OWDR); + __raw_writel(mask, pio + PIO_OWER); + __raw_writel(val, pio + PIO_ODSR);
+}
Would caching OWSR be a significant speedup here?
Thanks in advance,
Roland
Quoted 12 lines · Roland Stigge
Hi Wolfgang,
Quoted 6 lines · Roland Stigge
And I guess Russell is right: If possible, we should write outputs simultaneously via ODSR (plus OWER/OWDR/OWSR) instead of separate set/clear.
I wonder if we need to save/restore the state of OWSR at every write operation or if we need/can cache it. Assuming that block GPIO are the only code in the kernel that manipulates ODSR.
Can you please test the following:
arch/arm/mach-at91/gpio.c static void at91_gpiolib_set(struct gpio_chip *chip, unsigned offset, int val)
Quoted 6 lines
arch/arm/mach-at91/gpio.c +6
-0+static void at91_gpiolib_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; + +__raw_writel (~mask, pio +PIO_OWDR );
This would also disable normal GPIOs configured for output! From the manual I understand that if the pin is configured for output, we could either use PIO_SODR/PIO_CODR to set/clear the bits individually or PIO_ODSR for synchronous data output. But than we need to care about the non-block GPIO outputs as well... requiring a read-modify-write cycle :(.
Wolfgang.
Quoted 24 lines · Wolfgang Grandegger
Quoted 10 lines · Roland Stigge
Hi Wolfgang,
Quoted 6 lines
And I guess Russell is right: If possible, we should write outputs simultaneously via ODSR (plus OWER/OWDR/OWSR) instead of separate set/clear.
I wonder if we need to save/restore the state of OWSR at every write operation or if we need/can cache it. Assuming that block GPIO are the only code in the kernel that manipulates ODSR.
Can you please test the following:
arch/arm/mach-at91/gpio.c static void at91_gpiolib_set(struct gpio_chip *chip, unsigned offset, int val)
Quoted 6 lines
arch/arm/mach-at91/gpio.c +6
-0+static void at91_gpiolib_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; + +__raw_writel (~mask, pio +PIO_OWDR );This would also disable normal GPIOs configured for output! From the manual I understand that if the pin is configured for output, we could either use PIO_SODR/PIO_CODR to set/clear the bits individually or
PIO_ODSRfor synchronous data output. But than we need to care about the non-block GPIO outputs as well... requiring a read-modify-write cycle :(.
Quoted 1 line
From the manual, I read about OWER: "Enables writing
PIO_ODSRfor the
I/O line" (analogous for OWDR). Would interpret this as affecting ODSR (for block GPIO) but not SODR/CODR (as currently with single GPIOs).
Have you tried? ;-)
Thanks in advance,
Roland
Quoted 25 lines · Roland Stigge
Quoted 23 lines · Wolfgang Grandegger
Quoted 10 lines · Roland Stigge
Hi Wolfgang,
Quoted 6 lines
And I guess Russell is right: If possible, we should write outputs simultaneously via ODSR (plus OWER/OWDR/OWSR) instead of separate set/clear.
I wonder if we need to save/restore the state of OWSR at every write operation or if we need/can cache it. Assuming that block GPIO are the only code in the kernel that manipulates ODSR.
Can you please test the following:
arch/arm/mach-at91/gpio.c static void at91_gpiolib_set(struct gpio_chip *chip, unsigned offset, int val)
Quoted 6 lines
arch/arm/mach-at91/gpio.c +6
-0+static void at91_gpiolib_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; + +__raw_writel (~mask, pio +PIO_OWDR );This would also disable normal GPIOs configured for output! From the manual I understand that if the pin is configured for output, we could either use PIO_SODR/PIO_CODR to set/clear the bits individually or
PIO_ODSRfor synchronous data output. But than we need to care about the non-block GPIO outputs as well... requiring a read-modify-write cycle :(.
Quoted 5 lines
Quoted 1 line
From the manual, I read about OWER: "Enables writing
PIO_ODSRfor theI/O line" (analogous for OWDR). Would interpret this as affecting ODSR (for block GPIO) but not SODR/CODR (as currently with single GPIOs).
Have you tried? ;-)
Grrr, I mixed OER with OWER, sorry for the noise. Back to your approach, which works.
/* Do synchronous data output with a single write access */ __raw_writel(~mask, pio + PIO_OWDR); __raw_writel(mask, pio + PIO_OWER); __raw_writel(val, pio + PIO_ODSR);
For caching we would need a storage. Not sure if it's worth compared to a context switch into the kernel.
Wolfgang.
Quoted 7 lines · Wolfgang Grandegger
/* Do synchronous data output with a single write access */ __raw_writel(~mask, pio + PIO_OWDR); __raw_writel(mask, pio + PIO_OWER); __raw_writel(val, pio + PIO_ODSR);For caching we would need a storage. Not sure if it's worth compared to a context switch into the kernel.
Block GPIO is not only for you in userspace. ;-) You can also implement efficient n-bit bus I/O in kernel drivers, n-bit-banging. :-) So not always context switches involved.
Roland
Quoted 6 lines · Roland Stigge
Quoted 5 lines · Wolfgang Grandegger
/* Do synchronous data output with a single write access */ __raw_writel(~mask, pio + PIO_OWDR); __raw_writel(mask, pio + PIO_OWER); __raw_writel(val, pio + PIO_ODSR);
Quoted 6 lines
Quoted 2 lines
For caching we would need a storage. Not sure if it's worth compared to a context switch into the kernel.
Block GPIO is not only for you in userspace. ;-) You can also implement efficient n-bit bus I/O in kernel drivers, n-bit-banging. :-) So not always context switches involved.
OK, what do you think about the following untested patch:
Quoted 1 line
From
b44cad16cbbca84715dffd4cb5268497216add25Mon Sep 17 00:00:00 2001
From: Wolfgang Grandegger <[email protected]>
Date: Mon, 3 Dec 2012 08:31:55 +0100
Subject: [PATCH 1/2] gpio: add GPIO block callback functions for AT91
--- arch/arm/mach-at91/gpio.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
arch/arm/mach-at91/gpio.c +29 -0
@@ -42,13 +42,16 @@ struct at91_gpio_chip {void __iomem *regbase;/* PIO bank virtual address */ struct clk *clock;/* associated clock */ struct irq_domain *domain;/* associated irq domain */ +unsigned long mask_shadow;/* synchronous data output */ };#define to_at91_gpio_chip (c) container_of(c, struct at91_gpio_chip, chip)static void at91_gpiolib_dbg_show (struct seq_file *s,struct gpio_chip *chip);static void at91_gpiolib_set (struct gpio_chip *chip,unsigned offset,int val); +static void at91_gpiolib_set_block (struct gpio_chip *chip,unsigned long mask,unsigned long val);static int at91_gpiolib_get (struct gpio_chip *chip,unsigned offset); +static unsigned long at91_gpiolib_get_block (struct gpio_chip *chip,unsigned long mask);static int at91_gpiolib_direction_output (struct gpio_chip *chip,unsigned offset,int val); static int at91_gpiolib_direction_input(struct gpio_chip *chip,
@@ -62,7 +65,9 @@ static int at91_gpiolib_to_irq(struct gpio_chip *chip, unsigned offset); .direction_input = at91_gpiolib_direction_input, \ .direction_output = at91_gpiolib_direction_output, \ .get = at91_gpiolib_get, \ + .get_block = at91_gpiolib_get_block, \ .set = at91_gpiolib_set, \ + .set_block = at91_gpiolib_set_block, \ .dbg_show = at91_gpiolib_dbg_show, \ .to_irq = at91_gpiolib_to_irq, \ .ngpio = nr_gpio, \
@@ -896,6 +901,16 @@ static int at91_gpiolib_get(struct gpio_chip *chip, unsigned offset)return (pdsr & mask) !=0 ; } +static unsigned long at91_gpiolib_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 =__raw_readl (pio +PIO_PDSR ); +return pdsr & mask; +} +static void at91_gpiolib_set (struct gpio_chip *chip,unsigned offset,int val) {struct at91_gpio_chip *at91_gpio =to_at91_gpio_chip (chip);
@@ -905,6 +920,20 @@ static void at91_gpiolib_set(struct gpio_chip *chip, unsigned offset, int val)__raw_writel (mask, pio + (val ?PIO_SODR :PIO_CODR )); } +static void at91_gpiolib_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_shadow) { + at91_gpio->mask_shadow = mask; +__raw_writel (~mask, pio +PIO_OWDR ); +__raw_writel (mask, pio +PIO_OWER ); + } +__raw_writel (val, pio +PIO_ODSR ); +} +static void at91_gpiolib_dbg_show (struct seq_file *s,struct gpio_chip *chip) {int i;
Signature · 1 line
1.7.9.5
Quoted 7 lines · Wolfgang Grandegger
Quoted 6 lines · Roland Stigge
Quoted 5 lines · Wolfgang Grandegger
/* Do synchronous data output with a single write access */ __raw_writel(~mask, pio + PIO_OWDR); __raw_writel(mask, pio + PIO_OWER); __raw_writel(val, pio + PIO_ODSR);
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
For caching we would need a storage. Not sure if it's worth compared to a context switch into the kernel.
Block GPIO is not only for you in userspace. ;-) You can also implement efficient n-bit bus I/O in kernel drivers, n-bit-banging. :-) So not always context switches involved.
OK, what do you think about the following untested patch:
Looks good!
Why "untested"? ;-)
Thanks,
Roland
Quoted 79 lines
Quoted 1 line
From
b44cad16cbbca84715dffd4cb5268497216add25Mon Sep 17 00:00:00 2001From: Wolfgang Grandegger <[email protected]>
Date: Mon, 3 Dec 2012 08:31:55 +0100
Subject: [PATCH 1/2] gpio: add GPIO block callback functions for AT91Signed-off-by Wolfgang Grandegger <[email protected]>--- arch/arm/mach-at91/gpio.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)arch/arm/mach-at91/gpio.c +29
-0@@ -42,13 +42,16 @@ struct at91_gpio_chip {void __iomem *regbase;/* PIO bank virtual address */ struct clk *clock;/* associated clock */ struct irq_domain *domain;/* associated irq domain */ +unsigned long mask_shadow;/* synchronous data output */ };#define to_at91_gpio_chip (c) container_of(c, struct at91_gpio_chip, chip)static void at91_gpiolib_dbg_show (struct seq_file *s,struct gpio_chip *chip);static void at91_gpiolib_set (struct gpio_chip *chip,unsigned offset,int val); +static void at91_gpiolib_set_block (struct gpio_chip *chip,unsigned long mask,unsigned long val);static int at91_gpiolib_get (struct gpio_chip *chip,unsigned offset); +static unsigned long at91_gpiolib_get_block (struct gpio_chip *chip,unsigned long mask);static int at91_gpiolib_direction_output (struct gpio_chip *chip,unsigned offset,int val); static int at91_gpiolib_direction_input(struct gpio_chip *chip,@@ -62,7 +65,9 @@ static int at91_gpiolib_to_irq(struct gpio_chip *chip, unsigned offset); .direction_input = at91_gpiolib_direction_input, \ .direction_output = at91_gpiolib_direction_output, \ .get = at91_gpiolib_get, \ + .get_block = at91_gpiolib_get_block, \ .set = at91_gpiolib_set, \ + .set_block = at91_gpiolib_set_block, \ .dbg_show = at91_gpiolib_dbg_show, \ .to_irq = at91_gpiolib_to_irq, \ .ngpio = nr_gpio, \@@ -896,6 +901,16 @@ static int at91_gpiolib_get(struct gpio_chip *chip, unsigned offset)return (pdsr & mask) !=0 ; } +static unsigned long at91_gpiolib_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 =__raw_readl (pio +PIO_PDSR ); +return pdsr & mask; +} +static void at91_gpiolib_set (struct gpio_chip *chip,unsigned offset,int val) {struct at91_gpio_chip *at91_gpio =to_at91_gpio_chip (chip);@@ -905,6 +920,20 @@ static void at91_gpiolib_set(struct gpio_chip *chip, unsigned offset, int val)__raw_writel (mask, pio + (val ?PIO_SODR :PIO_CODR )); } +static void at91_gpiolib_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_shadow) { + at91_gpio->mask_shadow = mask; +__raw_writel (~mask, pio +PIO_OWDR ); +__raw_writel (mask, pio +PIO_OWER ); + } +__raw_writel (val, pio +PIO_ODSR ); +} +static void at91_gpiolib_dbg_show (struct seq_file *s,struct gpio_chip *chip) {int i;
Quoted 15 lines · Roland Stigge
Quoted 14 lines · Wolfgang Grandegger
Quoted 12 lines · Roland Stigge
Quoted 7 lines · Wolfgang Grandegger
/* Do synchronous data output with a single write access */ __raw_writel(~mask, pio + PIO_OWDR); __raw_writel(mask, pio + PIO_OWER); __raw_writel(val, pio + PIO_ODSR);For caching we would need a storage. Not sure if it's worth compared to a context switch into the kernel.
Block GPIO is not only for you in userspace. ;-) You can also implement efficient n-bit bus I/O in kernel drivers, n-bit-banging. :-) So not always context switches involved.
Quoted 5 lines
Quoted 1 line
OK, what do you think about the following untested patch:
Looks good!
Why "untested"? ;-)
Because I didn't have a chance to test it yet. Will do tomorrow.
Wolfgang.
Quoted 81 lines · Wolfgang Grandegger
Quoted 6 lines · Roland Stigge
Quoted 5 lines · Wolfgang Grandegger
/* Do synchronous data output with a single write access */ __raw_writel(~mask, pio + PIO_OWDR); __raw_writel(mask, pio + PIO_OWER); __raw_writel(val, pio + PIO_ODSR);Quoted 6 lines
Quoted 2 lines
For caching we would need a storage. Not sure if it's worth compared to a context switch into the kernel.
Block GPIO is not only for you in userspace. ;-) You can also implement efficient n-bit bus I/O in kernel drivers, n-bit-banging. :-) So not always context switches involved.
OK, what do you think about the following untested patch:
From
b44cad16cbbca84715dffd4cb5268497216add25Mon Sep 17 00:00:00 2001
From: Wolfgang Grandegger <[email protected]>
Date: Mon, 3 Dec 2012 08:31:55 +0100
Subject: [PATCH 1/2] gpio: add GPIO block callback functions for AT91Signed-off-by Wolfgang Grandegger <[email protected]>--- arch/arm/mach-at91/gpio.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)arch/arm/mach-at91/gpio.c +18
-0@@ -42,13 +42,16 @@ struct at91_gpio_chip {void __iomem *regbase;/* PIO bank virtual address */ struct clk *clock;/* associated clock */ struct irq_domain *domain;/* associated irq domain */ +unsigned long mask_shadow;/* synchronous data output */ };#define to_at91_gpio_chip (c) container_of(c, struct at91_gpio_chip, chip)static void at91_gpiolib_dbg_show (struct seq_file *s,struct gpio_chip *chip);static void at91_gpiolib_set (struct gpio_chip *chip,unsigned offset,int val); +static void at91_gpiolib_set_block (struct gpio_chip *chip,unsigned long mask,unsigned long val);static int at91_gpiolib_get (struct gpio_chip *chip,unsigned offset); +static unsigned long at91_gpiolib_get_block (struct gpio_chip *chip,unsigned long mask);static int at91_gpiolib_direction_output (struct gpio_chip *chip,unsigned offset,int val); static int at91_gpiolib_direction_input(struct gpio_chip *chip,@@ -62,7 +65,9 @@ static int at91_gpiolib_to_irq(struct gpio_chip *chip, unsigned offset); .direction_input = at91_gpiolib_direction_input, \ .direction_output = at91_gpiolib_direction_output, \ .get = at91_gpiolib_get, \ + .get_block = at91_gpiolib_get_block, \ .set = at91_gpiolib_set, \ + .set_block = at91_gpiolib_set_block, \ .dbg_show = at91_gpiolib_dbg_show, \ .to_irq = at91_gpiolib_to_irq, \ .ngpio = nr_gpio, \@@ -896,6 +901,16 @@ static int at91_gpiolib_get(struct gpio_chip *chip, unsigned offset)return (pdsr & mask) !=0 ; } +static unsigned long at91_gpiolib_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 =__raw_readl (pio +PIO_PDSR ); +return pdsr & mask; +} +static void at91_gpiolib_set (struct gpio_chip *chip,unsigned offset,int val) {struct at91_gpio_chip *at91_gpio =to_at91_gpio_chip (chip);@@ -905,6 +920,20 @@ static void at91_gpiolib_set(struct gpio_chip *chip, unsigned offset, int val)__raw_writel (mask, pio + (val ?PIO_SODR :PIO_CODR )); } +static void at91_gpiolib_set_block (struct gpio_chip *chip,unsigned long mask,unsigned long val) +{ +struct at91_gpio_chip *at91_gpio =to_at91_gpio_chip (chip);
arch/arm/mach-at91/gpio.c static void at91_gpiolib_set(struct gpio_chip *chip, unsigned offset, int val) · line 935
Quoted 10 lines
arch/arm/mach-at91/gpio.c +10
-0+void __iomem *pio = at91_gpio->regbase; + +/* Do synchronous data output with a single write access */ +if (mask != at91_gpio->mask_shadow) { + at91_gpio->mask_shadow = mask; +__raw_writel (~mask, pio +PIO_OWDR ); +__raw_writel (mask, pio +PIO_OWER ); + } +__raw_writel (val, pio +PIO_ODSR ); +}
this driver is only for old at91 platfrom if you touch at91 you need to update the pinctrl too
Best Regards,
J.
Quoted 8 lines
arch/arm/mach-at91/gpio.c +1
-0+static void at91_gpiolib_dbg_show (struct seq_file *s,struct gpio_chip *chip) {int i;Signature · 1 line
1.7.9.5
Quoted 79 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 78 lines · Wolfgang Grandegger
Quoted 6 lines · Roland Stigge
Quoted 5 lines · Wolfgang Grandegger
/* Do synchronous data output with a single write access */ __raw_writel(~mask, pio + PIO_OWDR); __raw_writel(mask, pio + PIO_OWER); __raw_writel(val, pio + PIO_ODSR);Quoted 6 lines
Quoted 2 lines
For caching we would need a storage. Not sure if it's worth compared to a context switch into the kernel.
Block GPIO is not only for you in userspace. ;-) You can also implement efficient n-bit bus I/O in kernel drivers, n-bit-banging. :-) So not always context switches involved.
OK, what do you think about the following untested patch:
From
b44cad16cbbca84715dffd4cb5268497216add25Mon Sep 17 00:00:00 2001
From: Wolfgang Grandegger <[email protected]>
Date: Mon, 3 Dec 2012 08:31:55 +0100
Subject: [PATCH 1/2] gpio: add GPIO block callback functions for AT91Signed-off-by Wolfgang Grandegger <[email protected]>--- arch/arm/mach-at91/gpio.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)arch/arm/mach-at91/gpio.c +15
-0@@ -42,13 +42,16 @@ struct at91_gpio_chip {void __iomem *regbase;/* PIO bank virtual address */ struct clk *clock;/* associated clock */ struct irq_domain *domain;/* associated irq domain */ +unsigned long mask_shadow;/* synchronous data output */ };#define to_at91_gpio_chip (c) container_of(c, struct at91_gpio_chip, chip)static void at91_gpiolib_dbg_show (struct seq_file *s,struct gpio_chip *chip);static void at91_gpiolib_set (struct gpio_chip *chip,unsigned offset,int val); +static void at91_gpiolib_set_block (struct gpio_chip *chip,unsigned long mask,unsigned long val);static int at91_gpiolib_get (struct gpio_chip *chip,unsigned offset); +static unsigned long at91_gpiolib_get_block (struct gpio_chip *chip,unsigned long mask);static int at91_gpiolib_direction_output (struct gpio_chip *chip,unsigned offset,int val); static int at91_gpiolib_direction_input(struct gpio_chip *chip,@@ -62,7 +65,9 @@ static int at91_gpiolib_to_irq(struct gpio_chip *chip, unsigned offset); .direction_input = at91_gpiolib_direction_input, \ .direction_output = at91_gpiolib_direction_output, \ .get = at91_gpiolib_get, \ + .get_block = at91_gpiolib_get_block, \ .set = at91_gpiolib_set, \ + .set_block = at91_gpiolib_set_block, \ .dbg_show = at91_gpiolib_dbg_show, \ .to_irq = at91_gpiolib_to_irq, \ .ngpio = nr_gpio, \@@ -896,6 +901,16 @@ static int at91_gpiolib_get(struct gpio_chip *chip, unsigned offset)return (pdsr & mask) !=0 ; } +static unsigned long at91_gpiolib_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 =__raw_readl (pio +PIO_PDSR ); +return pdsr & mask; +} +static void at91_gpiolib_set (struct gpio_chip *chip,unsigned offset,int val) {struct at91_gpio_chip *at91_gpio =to_at91_gpio_chip (chip);@@ -905,6 +920,20 @@ static void at91_gpiolib_set(struct gpio_chip *chip, unsigned offset, int val)__raw_writel (mask, pio + (val ?PIO_SODR :PIO_CODR )); }
Quoted 15 lines
arch/arm/mach-at91/gpio.c static void at91_gpiolib_set(struct gpio_chip *chip, unsigned offset, int val) · line 935
Quoted 13 lines
arch/arm/mach-at91/gpio.c +13
-0+static void at91_gpiolib_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_shadow) { + at91_gpio->mask_shadow = mask; +__raw_writel (~mask, pio +PIO_OWDR ); +__raw_writel (mask, pio +PIO_OWER ); + } +__raw_writel (val, pio +PIO_ODSR ); +}this driver is only for old at91 platfrom if you touch at91 you need to update the pinctrl too
Well, the patch is for the hardware I have at hand and I can test. There are many other GPIO hardware interfaces which could be enhanced with block gpio. Roland only did it for the interfaces in driver/gpio. Also, I think, an ACK for this patch series would be nice before we continue.
Wolfgang.
Quoted 96 lines · Wolfgang Grandegger
Quoted 79 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 78 lines · Wolfgang Grandegger
Quoted 6 lines · Roland Stigge
Quoted 5 lines · Wolfgang Grandegger
/* Do synchronous data output with a single write access */ __raw_writel(~mask, pio + PIO_OWDR); __raw_writel(mask, pio + PIO_OWER); __raw_writel(val, pio + PIO_ODSR);Quoted 6 lines
Quoted 2 lines
For caching we would need a storage. Not sure if it's worth compared to a context switch into the kernel.
Block GPIO is not only for you in userspace. ;-) You can also implement efficient n-bit bus I/O in kernel drivers, n-bit-banging. :-) So not always context switches involved.
OK, what do you think about the following untested patch:
From
b44cad16cbbca84715dffd4cb5268497216add25Mon Sep 17 00:00:00 2001
From: Wolfgang Grandegger <[email protected]>
Date: Mon, 3 Dec 2012 08:31:55 +0100
Subject: [PATCH 1/2] gpio: add GPIO block callback functions for AT91Signed-off-by Wolfgang Grandegger <[email protected]>--- arch/arm/mach-at91/gpio.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)arch/arm/mach-at91/gpio.c +15
-0@@ -42,13 +42,16 @@ struct at91_gpio_chip {void __iomem *regbase;/* PIO bank virtual address */ struct clk *clock;/* associated clock */ struct irq_domain *domain;/* associated irq domain */ +unsigned long mask_shadow;/* synchronous data output */ };#define to_at91_gpio_chip (c) container_of(c, struct at91_gpio_chip, chip)static void at91_gpiolib_dbg_show (struct seq_file *s,struct gpio_chip *chip);static void at91_gpiolib_set (struct gpio_chip *chip,unsigned offset,int val); +static void at91_gpiolib_set_block (struct gpio_chip *chip,unsigned long mask,unsigned long val);static int at91_gpiolib_get (struct gpio_chip *chip,unsigned offset); +static unsigned long at91_gpiolib_get_block (struct gpio_chip *chip,unsigned long mask);static int at91_gpiolib_direction_output (struct gpio_chip *chip,unsigned offset,int val); static int at91_gpiolib_direction_input(struct gpio_chip *chip,@@ -62,7 +65,9 @@ static int at91_gpiolib_to_irq(struct gpio_chip *chip, unsigned offset); .direction_input = at91_gpiolib_direction_input, \ .direction_output = at91_gpiolib_direction_output, \ .get = at91_gpiolib_get, \ + .get_block = at91_gpiolib_get_block, \ .set = at91_gpiolib_set, \ + .set_block = at91_gpiolib_set_block, \ .dbg_show = at91_gpiolib_dbg_show, \ .to_irq = at91_gpiolib_to_irq, \ .ngpio = nr_gpio, \@@ -896,6 +901,16 @@ static int at91_gpiolib_get(struct gpio_chip *chip, unsigned offset)return (pdsr & mask) !=0 ; } +static unsigned long at91_gpiolib_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 =__raw_readl (pio +PIO_PDSR ); +return pdsr & mask; +} +static void at91_gpiolib_set (struct gpio_chip *chip,unsigned offset,int val) {struct at91_gpio_chip *at91_gpio =to_at91_gpio_chip (chip);@@ -905,6 +920,20 @@ static void at91_gpiolib_set(struct gpio_chip *chip, unsigned offset, int val)__raw_writel (mask, pio + (val ?PIO_SODR :PIO_CODR )); }Quoted 15 lines
arch/arm/mach-at91/gpio.c static void at91_gpiolib_set(struct gpio_chip *chip, unsigned offset, int val) · line 935
Quoted 13 lines
arch/arm/mach-at91/gpio.c +13
-0+static void at91_gpiolib_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_shadow) { + at91_gpio->mask_shadow = mask; +__raw_writel (~mask, pio +PIO_OWDR ); +__raw_writel (mask, pio +PIO_OWER ); + } +__raw_writel (val, pio +PIO_ODSR ); +}this driver is only for old at91 platfrom if you touch at91 you need to update the pinctrl too
Quoted 4 lines
Well, the patch is for the hardware I have at hand and I can test. There are many other GPIO hardware interfaces which could be enhanced with block gpio. Roland only did it for the interfaces in driver/gpio. Also, I think, an ACK for this patch series would be nice before we continue.
no sorry the support of the pinctrl is mandatory
check drivers/pinctrl/pinctrl-at91.c
as this new drivers include both pinctrl & gpio
Best Regards,
J.