diff options
author | Anton Vorontsov <avorontsov@ru.mvista.com> | 2010-06-08 09:48:16 -0400 |
---|---|---|
committer | Grant Likely <grant.likely@secretlab.ca> | 2010-07-05 18:14:30 -0400 |
commit | a19e3da5bc5fc6c10ab73f310bea80f3845b4531 (patch) | |
tree | 49b6e952f48e56d9701f92e0c24044a14b676a34 /drivers/of | |
parent | cedb1881ba32f7e9cd49250bd79debccbe52b094 (diff) |
of/gpio: Kill of_gpio_chip and add members directly to gpio_chip
The OF gpio infrastructure is great for describing GPIO connections within
the device tree. However, using a GPIO binding still requires changes to
the gpio controller just to add an of_gpio structure. In most cases, the
gpio controller doesn't actually need any special support and the simple
OF gpio mapping function is more than sufficient. Additional, the current
scheme of using of_gpio_chip requires a convoluted scheme to maintain
1:1 mappings between of_gpio_chip and gpio_chip instances.
If the struct of_gpio_chip data members were moved into struct gpio_chip,
then it would simplify the processing of OF gpio bindings, and it would
make it trivial to use device tree OF connections on existing gpiolib
controller drivers.
This patch eliminates the of_gpio_chip structure and moves the relevant
fields into struct gpio_chip (conditional on CONFIG_OF_GPIO). This move
simplifies the existing code and prepares for adding automatic device tree
support to existing drivers.
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>
Diffstat (limited to 'drivers/of')
-rw-r--r-- | drivers/of/gpio.c | 50 |
1 files changed, 24 insertions, 26 deletions
diff --git a/drivers/of/gpio.c b/drivers/of/gpio.c index a1b31a4abae..fde53a3a45a 100644 --- a/drivers/of/gpio.c +++ b/drivers/of/gpio.c | |||
@@ -33,32 +33,32 @@ int of_get_gpio_flags(struct device_node *np, int index, | |||
33 | enum of_gpio_flags *flags) | 33 | enum of_gpio_flags *flags) |
34 | { | 34 | { |
35 | int ret; | 35 | int ret; |
36 | struct device_node *gc; | 36 | struct device_node *gpio_np; |
37 | struct of_gpio_chip *of_gc = NULL; | 37 | struct gpio_chip *gc; |
38 | int size; | 38 | int size; |
39 | const void *gpio_spec; | 39 | const void *gpio_spec; |
40 | const __be32 *gpio_cells; | 40 | const __be32 *gpio_cells; |
41 | 41 | ||
42 | ret = of_parse_phandles_with_args(np, "gpios", "#gpio-cells", index, | 42 | ret = of_parse_phandles_with_args(np, "gpios", "#gpio-cells", index, |
43 | &gc, &gpio_spec); | 43 | &gpio_np, &gpio_spec); |
44 | if (ret) { | 44 | if (ret) { |
45 | pr_debug("%s: can't parse gpios property\n", __func__); | 45 | pr_debug("%s: can't parse gpios property\n", __func__); |
46 | goto err0; | 46 | goto err0; |
47 | } | 47 | } |
48 | 48 | ||
49 | of_gc = gc->data; | 49 | gc = gpio_np->data; |
50 | if (!of_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, gc->full_name); | 52 | np->full_name, gpio_np->full_name); |
53 | ret = -ENODEV; | 53 | ret = -ENODEV; |
54 | goto err1; | 54 | goto err1; |
55 | } | 55 | } |
56 | 56 | ||
57 | gpio_cells = of_get_property(gc, "#gpio-cells", &size); | 57 | gpio_cells = of_get_property(gpio_np, "#gpio-cells", &size); |
58 | if (!gpio_cells || size != sizeof(*gpio_cells) || | 58 | if (!gpio_cells || size != sizeof(*gpio_cells) || |
59 | be32_to_cpup(gpio_cells) != of_gc->gpio_cells) { | 59 | be32_to_cpup(gpio_cells) != gc->of_gpio_n_cells) { |
60 | pr_debug("%s: wrong #gpio-cells for %s\n", | 60 | pr_debug("%s: wrong #gpio-cells for %s\n", |
61 | np->full_name, gc->full_name); | 61 | np->full_name, gpio_np->full_name); |
62 | ret = -EINVAL; | 62 | ret = -EINVAL; |
63 | goto err1; | 63 | goto err1; |
64 | } | 64 | } |
@@ -67,13 +67,13 @@ int of_get_gpio_flags(struct device_node *np, int index, | |||
67 | if (flags) | 67 | if (flags) |
68 | *flags = 0; | 68 | *flags = 0; |
69 | 69 | ||
70 | ret = of_gc->xlate(of_gc, np, gpio_spec, flags); | 70 | ret = gc->of_xlate(gc, np, gpio_spec, flags); |
71 | if (ret < 0) | 71 | if (ret < 0) |
72 | goto err1; | 72 | goto err1; |
73 | 73 | ||
74 | ret += of_gc->gc.base; | 74 | ret += gc->base; |
75 | err1: | 75 | err1: |
76 | of_node_put(gc); | 76 | of_node_put(gpio_np); |
77 | err0: | 77 | err0: |
78 | pr_debug("%s exited with status %d\n", __func__, ret); | 78 | pr_debug("%s exited with status %d\n", __func__, ret); |
79 | return ret; | 79 | return ret; |
@@ -116,7 +116,7 @@ EXPORT_SYMBOL(of_gpio_count); | |||
116 | 116 | ||
117 | /** | 117 | /** |
118 | * of_gpio_simple_xlate - translate gpio_spec to the GPIO number and flags | 118 | * of_gpio_simple_xlate - translate gpio_spec to the GPIO number and flags |
119 | * @of_gc: pointer to the of_gpio_chip structure | 119 | * @gc: pointer to the gpio_chip structure |
120 | * @np: device node of the GPIO chip | 120 | * @np: device node of the GPIO chip |
121 | * @gpio_spec: gpio specifier as found in the device tree | 121 | * @gpio_spec: gpio specifier as found in the device tree |
122 | * @flags: a flags pointer to fill in | 122 | * @flags: a flags pointer to fill in |
@@ -125,8 +125,8 @@ EXPORT_SYMBOL(of_gpio_count); | |||
125 | * gpio chips. This function performs only one sanity check: whether gpio | 125 | * gpio chips. This function performs only one sanity check: whether gpio |
126 | * is less than ngpios (that is specified in the gpio_chip). | 126 | * is less than ngpios (that is specified in the gpio_chip). |
127 | */ | 127 | */ |
128 | int of_gpio_simple_xlate(struct of_gpio_chip *of_gc, struct device_node *np, | 128 | int of_gpio_simple_xlate(struct gpio_chip *gc, struct device_node *np, |
129 | const void *gpio_spec, enum of_gpio_flags *flags) | 129 | const void *gpio_spec, u32 *flags) |
130 | { | 130 | { |
131 | const __be32 *gpio = gpio_spec; | 131 | const __be32 *gpio = gpio_spec; |
132 | const u32 n = be32_to_cpup(gpio); | 132 | const u32 n = be32_to_cpup(gpio); |
@@ -137,12 +137,12 @@ int of_gpio_simple_xlate(struct of_gpio_chip *of_gc, struct device_node *np, | |||
137 | * number and the flags from a single gpio cell -- this is possible, | 137 | * number and the flags from a single gpio cell -- this is possible, |
138 | * but not recommended). | 138 | * but not recommended). |
139 | */ | 139 | */ |
140 | if (of_gc->gpio_cells < 2) { | 140 | if (gc->of_gpio_n_cells < 2) { |
141 | WARN_ON(1); | 141 | WARN_ON(1); |
142 | return -EINVAL; | 142 | return -EINVAL; |
143 | } | 143 | } |
144 | 144 | ||
145 | if (n > of_gc->gc.ngpio) | 145 | if (n > gc->ngpio) |
146 | return -EINVAL; | 146 | return -EINVAL; |
147 | 147 | ||
148 | if (flags) | 148 | if (flags) |
@@ -161,10 +161,8 @@ EXPORT_SYMBOL(of_gpio_simple_xlate); | |||
161 | * | 161 | * |
162 | * 1) In the gpio_chip structure: | 162 | * 1) In the gpio_chip structure: |
163 | * - all the callbacks | 163 | * - all the callbacks |
164 | * | 164 | * - of_gpio_n_cells |
165 | * 2) In the of_gpio_chip structure: | 165 | * - of_xlate callback (optional) |
166 | * - gpio_cells | ||
167 | * - xlate callback (optional) | ||
168 | * | 166 | * |
169 | * 3) In the of_mm_gpio_chip structure: | 167 | * 3) In the of_mm_gpio_chip structure: |
170 | * - save_regs callback (optional) | 168 | * - save_regs callback (optional) |
@@ -177,8 +175,7 @@ int of_mm_gpiochip_add(struct device_node *np, | |||
177 | struct of_mm_gpio_chip *mm_gc) | 175 | struct of_mm_gpio_chip *mm_gc) |
178 | { | 176 | { |
179 | int ret = -ENOMEM; | 177 | int ret = -ENOMEM; |
180 | struct of_gpio_chip *of_gc = &mm_gc->of_gc; | 178 | struct gpio_chip *gc = &mm_gc->gc; |
181 | struct gpio_chip *gc = &of_gc->gc; | ||
182 | 179 | ||
183 | gc->label = kstrdup(np->full_name, GFP_KERNEL); | 180 | gc->label = kstrdup(np->full_name, GFP_KERNEL); |
184 | if (!gc->label) | 181 | if (!gc->label) |
@@ -190,13 +187,14 @@ int of_mm_gpiochip_add(struct device_node *np, | |||
190 | 187 | ||
191 | gc->base = -1; | 188 | gc->base = -1; |
192 | 189 | ||
193 | if (!of_gc->xlate) | 190 | if (!gc->of_xlate) |
194 | of_gc->xlate = of_gpio_simple_xlate; | 191 | gc->of_xlate = of_gpio_simple_xlate; |
195 | 192 | ||
196 | if (mm_gc->save_regs) | 193 | if (mm_gc->save_regs) |
197 | mm_gc->save_regs(mm_gc); | 194 | mm_gc->save_regs(mm_gc); |
198 | 195 | ||
199 | np->data = of_gc; | 196 | np->data = &mm_gc->gc; |
197 | mm_gc->gc.of_node = np; | ||
200 | 198 | ||
201 | ret = gpiochip_add(gc); | 199 | ret = gpiochip_add(gc); |
202 | if (ret) | 200 | if (ret) |