aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/of/gpio.c
diff options
context:
space:
mode:
authorGrant Likely <grant.likely@secretlab.ca>2010-06-08 09:48:16 -0400
committerGrant Likely <grant.likely@secretlab.ca>2010-07-05 18:14:30 -0400
commit594fa265e084073443390c5b93d5410fd28e9bcd (patch)
tree42c0e5536ae2fd016159e1e1bd1f27f0a9f3cac2 /drivers/of/gpio.c
parenta19e3da5bc5fc6c10ab73f310bea80f3845b4531 (diff)
of/gpio: stop using device_node data pointer to find gpio_chip
Currently the kernel uses the struct device_node.data pointer to resolve a struct gpio_chip pointer from a device tree node. However, the .data member doesn't provide any type checking and there aren't any rules enforced on what it should be used for. There's no guarantee that the data stored in it actually points to an gpio_chip pointer. Instead of relying on the .data pointer, this patch modifies the code to add a lookup function which scans through the registered gpio_chips and returns the gpio_chip that has a pointer to the specified device_node. Signed-off-by: Grant Likely <grant.likely@secretlab.ca> CC: Andrew Morton <akpm@linux-foundation.org> CC: Anton Vorontsov <avorontsov@ru.mvista.com> CC: Grant Likely <grant.likely@secretlab.ca> CC: David Brownell <dbrownell@users.sourceforge.net> CC: Bill Gatliff <bgat@billgatliff.com> CC: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> CC: Benjamin Herrenschmidt <benh@kernel.crashing.org> CC: Jean Delvare <khali@linux-fr.org> CC: linux-kernel@vger.kernel.org CC: devicetree-discuss@lists.ozlabs.org
Diffstat (limited to 'drivers/of/gpio.c')
-rw-r--r--drivers/of/gpio.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/drivers/of/gpio.c b/drivers/of/gpio.c
index fde53a3a45a3..c8618d3282cf 100644
--- a/drivers/of/gpio.c
+++ b/drivers/of/gpio.c
@@ -46,7 +46,7 @@ int of_get_gpio_flags(struct device_node *np, int index,
46 goto err0; 46 goto err0;
47 } 47 }
48 48
49 gc = gpio_np->data; 49 gc = of_node_to_gpiochip(gpio_np);
50 if (!gc) { 50 if (!gc) {
51 pr_debug("%s: gpio controller %s isn't registered\n", 51 pr_debug("%s: gpio controller %s isn't registered\n",
52 np->full_name, gpio_np->full_name); 52 np->full_name, gpio_np->full_name);
@@ -193,7 +193,6 @@ int of_mm_gpiochip_add(struct device_node *np,
193 if (mm_gc->save_regs) 193 if (mm_gc->save_regs)
194 mm_gc->save_regs(mm_gc); 194 mm_gc->save_regs(mm_gc);
195 195
196 np->data = &mm_gc->gc;
197 mm_gc->gc.of_node = np; 196 mm_gc->gc.of_node = np;
198 197
199 ret = gpiochip_add(gc); 198 ret = gpiochip_add(gc);
@@ -207,7 +206,6 @@ int of_mm_gpiochip_add(struct device_node *np,
207 np->full_name, gc->base); 206 np->full_name, gc->base);
208 return 0; 207 return 0;
209err2: 208err2:
210 np->data = NULL;
211 iounmap(mm_gc->regs); 209 iounmap(mm_gc->regs);
212err1: 210err1:
213 kfree(gc->label); 211 kfree(gc->label);
@@ -217,3 +215,14 @@ err0:
217 return ret; 215 return ret;
218} 216}
219EXPORT_SYMBOL(of_mm_gpiochip_add); 217EXPORT_SYMBOL(of_mm_gpiochip_add);
218
219/* Private function for resolving node pointer to gpio_chip */
220static int of_gpiochip_is_match(struct gpio_chip *chip, void *data)
221{
222 return chip->of_node == data;
223}
224
225struct gpio_chip *of_node_to_gpiochip(struct device_node *np)
226{
227 return gpiochip_find(np, of_gpiochip_is_match);
228}