of_gpio: enchance simple gpio binding with remove function
Subsystems (4)
Quoted 5 lines · Dmitry Eremin-Solenikov
Add
of_simple_gpiochip_remove()- a pair toof_simple_gpiochip_addthat can remove simple gpiochip binding.Signed-off-by Dmitry Eremin-Solenikov <[email protected]>---
[...]
Quoted 9 lines
(quoted diff) +9
-0+int of_simple_gpiochip_add(struct device_node *np, + struct of_gpio_chip *of_gc) +{ + int ret = -ENOMEM; + struct gpio_chip *gc = &of_gc->gc; + + gc->base = -1; + + if (!of_gc->xlate)
Review
Quoted 10 lines
(quoted diff) +10
-0+ of_gc->xlate = of_gpio_simple_xlate; + + np->data = of_gc; + + /* We don't want to lose the node and its ->data */ + of_node_get(np); + + ret = gpiochip_add(gc); + if (ret) + goto err;
I don't think OF stuff should register gpiochips.
Previously we did this, but if you look into platform gpio drivers (e.g. drivers/gpio/pc{a,f}*.c), you'll notice that they already register GPIO chips, and call pdata hooks afterwards.
Our aim is to only register OF part in the pdata hook, and don't mess with generic gpiochip handling.
I started the work, but never actually find time to continue. I'm attaching the unfinished patches as an example of how I think it should be done, but I doubt they apply to the latest kernels, but nonetheless you might want to borrow some ideas.
Thanks!
Signature · 3 lines
Anton Vorontsov email: [email protected] irc://irc.freenode.net/bd2
Quoted 1 line
From
3e19b9a6d8c753aaaadc1aad80e055672b888f79Mon Sep 17 00:00:00 2001
From: Anton Vorontsov <[email protected]>
Date: Fri, 1 May 2009 18:36:09 +0400
Subject: [PATCH 1/4] of/gpio: add support for two-stage registration for the of_gpio_chips
Currently there are two ways to register OF GPIO controllers:
1. Allocating the of_gpio_chip structure and passing the &of_gc->gc pointer to the gpiochip_add. (Can use container_of to convert the gpio_chip to the of_gpio_chip.)
2. Allocating and registering the gpio_chip structure separately from the of_gpio_chip. (Since two allocations are separate, container_of won't work.)
As time goes by we'll kill the first option.
--- arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c | 1 + drivers/of/gpio.c | 23 +++++++++++++++++++++-- include/linux/of_gpio.h | 1 + 3 files changed, 23 insertions(+), 2 deletions(-)
arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c +1 -0
@@ -93,6 +93,7 @@ static int mcu_gpiochip_add(struct mcu *mcu) gc->base =-1 ; gc->set = mcu_gpio_set; gc->direction_output = mcu_gpio_dir_out; + of_gc->chip = gc; of_gc->gpio_cells =2 ; of_gc->xlate = of_gpio_simple_xlate;
drivers/of/gpio.c +21 -2
@@ -70,7 +70,7 @@ int of_get_gpio_flags(struct device_node *np, int index,if (ret <0 ) goto err1; - ret += of_gc->gc.base; + ret += of_gc->chip->base; err1:of_node_put (gc); err0:
@@ -140,7 +140,7 @@ int of_gpio_simple_xlate(struct of_gpio_chip *of_gc, struct device_node *np,return -EINVAL ; } -if (*gpio > of_gc->gc.ngpio) +if (*gpio > of_gc->chip->ngpio)return -EINVAL ;if (flags)
@@ -178,6 +178,25 @@ int of_mm_gpiochip_add(struct device_node *np,struct of_gpio_chip *of_gc = &mm_gc->of_gc;struct gpio_chip *gc = &of_gc->gc; +/* +* Currently there are two ways to register OF GPIO controllers: +* +* 1. Allocating the of_gpio_chip structure and passing the +* &of_gc->gc pointer to the gpiochip_add. (Can use container_of +* to convert the gpio_chip to the of_gpio_chip.) +* +* 2. Allocating and registering the gpio_chip structure separately +* from the of_gpio_chip. (Since two allocations are separate, +* container_of won't work.) +* +* As time goes by we'll kill the first option. For now just check +* if it's "new-style" registration or "old-style" one. +*/ +if (!of_gc->chip) + of_gc->chip = gc; +else + gc = of_gc->chip; + gc->label =kstrdup (np->full_name,GFP_KERNEL );if (!gc->label) goto err0;
include/linux/of_gpio.h +1 -0
@@ -37,6 +37,7 @@ enum of_gpio_flags {*/ struct of_gpio_chip {struct gpio_chip gc; +struct gpio_chip *chip;int gpio_cells;int (*xlate)(struct of_gpio_chip *of_gc,struct device_node *np,const void *gpio_spec,enum of_gpio_flags *flags);
Signature · 1 line
1.6.3.3
Quoted 1 line
From
265a4a0e3574f5a610a33a04717532cd2603e17bMon Sep 17 00:00:00 2001
From: Anton Vorontsov <[email protected]>
Date: Fri, 1 May 2009 18:36:09 +0400
Subject: [PATCH 2/4] of/gpio: implement of_dev_gpiochip_{add,remove} calls
And let the gpiolib forward all dev_gpiochip_ calls to of_ versions, there we can glue the gpiochips with the device tree.
--- drivers/of/gpio.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/of_gpio.h | 4 +++ 2 files changed, 60 insertions(+), 0 deletions(-)
drivers/of/gpio.c +56 -0
59 lines not on this page · raw message
include/linux/of_gpio.h +4 -0
@@ -70,6 +70,10 @@ extern unsigned int of_gpio_count(struct device_node *np);extern int of_mm_gpiochip_add (struct device_node *np,struct of_mm_gpio_chip *mm_gc); +extern int of_gpiochip_register_simple (struct gpio_chip *chip, +struct device_node *np); +extern void of_gpiochip_unregister (struct gpio_chip *chip, +struct device_node *np); extern int of_gpio_simple_xlate(struct of_gpio_chip *of_gc, struct device_node *np, const void *gpio_spec,
Signature · 1 line
1.6.3.3
Quoted 1 line
From
2e27423e56561e74d438814a8ecb757024019d8eMon Sep 17 00:00:00 2001
From: Anton Vorontsov <[email protected]>
Date: Fri, 1 May 2009 18:36:10 +0400
Subject: [PATCH 3/4] i2c/mcu_mpc8349emitx: Use new OF GPIO helpers
With the new OF GPIO helpers it's much easier to handle I2C GPIO controllers. Now drivers don't need to deal with the OF-specific bits.
--- arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c | 78 +++++++---------------- 1 files changed, 24 insertions(+), 54 deletions(-)
arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c +24 -54
132 lines not on this page · raw message
Signature · 1 line
1.6.3.3
Quoted 1 line
From
64abcde84f722c280872a389369e2113f507569eMon Sep 17 00:00:00 2001
From: Anton Vorontsov <[email protected]>
Date: Mon, 16 Nov 2009 17:41:27 +0300
Subject: [PATCH 4/4] gpio/pca953x: pass gpio_chip pointer to the setup/teardown callbacks
This is needed so that the platform code could register the chip with the platform internal structures.
While at it, also change gpio_base to the signed type (we'll pass -1 for the dynamic allocation).
--- drivers/gpio/pca953x.c | 7 +++---- include/linux/i2c/pca953x.h | 8 +++++--- 2 files changed, 8 insertions(+), 7 deletions(-)
drivers/gpio/pca953x.c +3 -4
@@ -239,8 +239,7 @@ static int __devinit pca953x_probe(struct i2c_client *client, goto out_failed;if (pdata->setup) { - ret = pdata->setup (client, chip->gpio_chip.base, - chip->gpio_chip.ngpio, pdata->context); + ret = pdata->setup (client, &chip->gpio_chip, pdata->context);if (ret <0 )dev_warn (&client->dev,"setup failed, %d\n" , ret); }
@@ -260,8 +259,8 @@ static int pca953x_remove(struct i2c_client *client)int ret =0 ;if (pdata->teardown) { - ret = pdata->teardown (client, chip->gpio_chip.base, - chip->gpio_chip.ngpio, pdata->context); + ret = pdata->teardown (client, &chip->gpio_chip, + pdata->context);if (ret <0 ) {dev_err (&client->dev,"%s failed, %d\n" ,"teardown" , ret);
include/linux/i2c/pca953x.h +5 -3
@@ -1,8 +1,10 @@/* platform data for the PCA9539 16-bit I/O expander driver */ +struct gpio_chip ; +struct pca953x_platform_data {/* number of the first GPIO */ -unsigned gpio_base; +int gpio_base;/* initial polarity inversion setting */ uint16_t invert;
@@ -10,9 +12,9 @@ struct pca953x_platform_data {void *context;/* param to setup/teardown */ int (*setup)(struct i2c_client *client, -unsigned gpio,unsigned ngpio, +struct gpio_chip *chip,void *context);int (*teardown)(struct i2c_client *client, -unsigned gpio,unsigned ngpio, +struct gpio_chip *chip,void *context); };
Signature · 1 line
1.6.3.3
_______________________________________________
devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss