diff options
author | Grant Likely <grant.likely@secretlab.ca> | 2011-12-12 11:25:57 -0500 |
---|---|---|
committer | Grant Likely <grant.likely@secretlab.ca> | 2011-12-12 15:40:16 -0500 |
commit | 1a2d397a6eb5cf40c382d9e3d4bc04aaeb025336 (patch) | |
tree | de928bf30efd84464d173359ae29f6a48b545b31 /arch/powerpc | |
parent | fe9f68449a507e03d41bee4500456bbfa22095d3 (diff) |
gpio/powerpc: Eliminate duplication of of_get_named_gpio_flags()
A large chunk of qe_pin_request() is unnecessarily cut-and-paste
directly from of_get_named_gpio_flags(). This patch cuts out the
duplicate code and replaces it with a call to of_get_gpio().
v2: fixed compile error due to missing gpio_to_chip()
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Kumar Gala <galak@kernel.crashing.org>
Diffstat (limited to 'arch/powerpc')
-rw-r--r-- | arch/powerpc/sysdev/qe_lib/gpio.c | 42 |
1 files changed, 8 insertions, 34 deletions
diff --git a/arch/powerpc/sysdev/qe_lib/gpio.c b/arch/powerpc/sysdev/qe_lib/gpio.c index e23f23cf9f5c..521e67a49dc4 100644 --- a/arch/powerpc/sysdev/qe_lib/gpio.c +++ b/arch/powerpc/sysdev/qe_lib/gpio.c | |||
@@ -139,14 +139,10 @@ struct qe_pin { | |||
139 | struct qe_pin *qe_pin_request(struct device_node *np, int index) | 139 | struct qe_pin *qe_pin_request(struct device_node *np, int index) |
140 | { | 140 | { |
141 | struct qe_pin *qe_pin; | 141 | struct qe_pin *qe_pin; |
142 | struct device_node *gpio_np; | ||
143 | struct gpio_chip *gc; | 142 | struct gpio_chip *gc; |
144 | struct of_mm_gpio_chip *mm_gc; | 143 | struct of_mm_gpio_chip *mm_gc; |
145 | struct qe_gpio_chip *qe_gc; | 144 | struct qe_gpio_chip *qe_gc; |
146 | int err; | 145 | int err; |
147 | int size; | ||
148 | const void *gpio_spec; | ||
149 | const u32 *gpio_cells; | ||
150 | unsigned long flags; | 146 | unsigned long flags; |
151 | 147 | ||
152 | qe_pin = kzalloc(sizeof(*qe_pin), GFP_KERNEL); | 148 | qe_pin = kzalloc(sizeof(*qe_pin), GFP_KERNEL); |
@@ -155,45 +151,25 @@ struct qe_pin *qe_pin_request(struct device_node *np, int index) | |||
155 | return ERR_PTR(-ENOMEM); | 151 | return ERR_PTR(-ENOMEM); |
156 | } | 152 | } |
157 | 153 | ||
158 | err = of_parse_phandles_with_args(np, "gpios", "#gpio-cells", index, | 154 | err = of_get_gpio(np, index); |
159 | &gpio_np, &gpio_spec); | 155 | if (err < 0) |
160 | if (err) { | 156 | goto err0; |
161 | pr_debug("%s: can't parse gpios property\n", __func__); | 157 | gc = gpio_to_chip(err); |
158 | if (WARN_ON(!gc)) | ||
162 | goto err0; | 159 | goto err0; |
163 | } | ||
164 | 160 | ||
165 | if (!of_device_is_compatible(gpio_np, "fsl,mpc8323-qe-pario-bank")) { | 161 | if (!of_device_is_compatible(gc->of_node, "fsl,mpc8323-qe-pario-bank")) { |
166 | pr_debug("%s: tried to get a non-qe pin\n", __func__); | 162 | pr_debug("%s: tried to get a non-qe pin\n", __func__); |
167 | err = -EINVAL; | 163 | err = -EINVAL; |
168 | goto err1; | 164 | goto err0; |
169 | } | ||
170 | |||
171 | gc = of_node_to_gpiochip(gpio_np); | ||
172 | if (!gc) { | ||
173 | pr_debug("%s: gpio controller %s isn't registered\n", | ||
174 | np->full_name, gpio_np->full_name); | ||
175 | err = -ENODEV; | ||
176 | goto err1; | ||
177 | } | ||
178 | |||
179 | gpio_cells = of_get_property(gpio_np, "#gpio-cells", &size); | ||
180 | if (!gpio_cells || size != sizeof(*gpio_cells) || | ||
181 | *gpio_cells != gc->of_gpio_n_cells) { | ||
182 | pr_debug("%s: wrong #gpio-cells for %s\n", | ||
183 | np->full_name, gpio_np->full_name); | ||
184 | err = -EINVAL; | ||
185 | goto err1; | ||
186 | } | 165 | } |
187 | 166 | ||
188 | err = gc->of_xlate(gc, np, gpio_spec, NULL); | ||
189 | if (err < 0) | ||
190 | goto err1; | ||
191 | |||
192 | mm_gc = to_of_mm_gpio_chip(gc); | 167 | mm_gc = to_of_mm_gpio_chip(gc); |
193 | qe_gc = to_qe_gpio_chip(mm_gc); | 168 | qe_gc = to_qe_gpio_chip(mm_gc); |
194 | 169 | ||
195 | spin_lock_irqsave(&qe_gc->lock, flags); | 170 | spin_lock_irqsave(&qe_gc->lock, flags); |
196 | 171 | ||
172 | err -= gc->base; | ||
197 | if (test_and_set_bit(QE_PIN_REQUESTED, &qe_gc->pin_flags[err]) == 0) { | 173 | if (test_and_set_bit(QE_PIN_REQUESTED, &qe_gc->pin_flags[err]) == 0) { |
198 | qe_pin->controller = qe_gc; | 174 | qe_pin->controller = qe_gc; |
199 | qe_pin->num = err; | 175 | qe_pin->num = err; |
@@ -206,8 +182,6 @@ struct qe_pin *qe_pin_request(struct device_node *np, int index) | |||
206 | 182 | ||
207 | if (!err) | 183 | if (!err) |
208 | return qe_pin; | 184 | return qe_pin; |
209 | err1: | ||
210 | of_node_put(gpio_np); | ||
211 | err0: | 185 | err0: |
212 | kfree(qe_pin); | 186 | kfree(qe_pin); |
213 | pr_debug("%s failed with status %d\n", __func__, err); | 187 | pr_debug("%s failed with status %d\n", __func__, err); |