diff options
author | Axel Lin <axel.lin@ingics.com> | 2014-12-11 23:17:41 -0500 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2015-01-15 11:23:18 -0500 |
commit | 5b6a342ba9594f1636f85e4c58004d87de9570ab (patch) | |
tree | 2cdffca89ebedf8cf183a9d28b920b52aa455e55 /drivers/gpio/gpio-vx855.c | |
parent | c458e45045da96b4d3506ba2acab02af8c98c8c2 (diff) |
gpio: vx855: Switch to use managed resources APIs
Use devm_* APIs to simplify the code a bit.
Signed-off-by: Axel Lin <axel.lin@ingics.com>
Acked-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio/gpio-vx855.c')
-rw-r--r-- | drivers/gpio/gpio-vx855.c | 44 |
1 files changed, 6 insertions, 38 deletions
diff --git a/drivers/gpio/gpio-vx855.c b/drivers/gpio/gpio-vx855.c index 9d21d2fcc327..57b470d5b39e 100644 --- a/drivers/gpio/gpio-vx855.c +++ b/drivers/gpio/gpio-vx855.c | |||
@@ -52,8 +52,6 @@ struct vx855_gpio { | |||
52 | spinlock_t lock; | 52 | spinlock_t lock; |
53 | u32 io_gpi; | 53 | u32 io_gpi; |
54 | u32 io_gpo; | 54 | u32 io_gpo; |
55 | bool gpi_reserved; | ||
56 | bool gpo_reserved; | ||
57 | }; | 55 | }; |
58 | 56 | ||
59 | /* resolve a GPIx into the corresponding bit position */ | 57 | /* resolve a GPIx into the corresponding bit position */ |
@@ -224,14 +222,13 @@ static int vx855gpio_probe(struct platform_device *pdev) | |||
224 | struct resource *res_gpi; | 222 | struct resource *res_gpi; |
225 | struct resource *res_gpo; | 223 | struct resource *res_gpo; |
226 | struct vx855_gpio *vg; | 224 | struct vx855_gpio *vg; |
227 | int ret; | ||
228 | 225 | ||
229 | res_gpi = platform_get_resource(pdev, IORESOURCE_IO, 0); | 226 | res_gpi = platform_get_resource(pdev, IORESOURCE_IO, 0); |
230 | res_gpo = platform_get_resource(pdev, IORESOURCE_IO, 1); | 227 | res_gpo = platform_get_resource(pdev, IORESOURCE_IO, 1); |
231 | if (!res_gpi || !res_gpo) | 228 | if (!res_gpi || !res_gpo) |
232 | return -EBUSY; | 229 | return -EBUSY; |
233 | 230 | ||
234 | vg = kzalloc(sizeof(*vg), GFP_KERNEL); | 231 | vg = devm_kzalloc(&pdev->dev, sizeof(*vg), GFP_KERNEL); |
235 | if (!vg) | 232 | if (!vg) |
236 | return -ENOMEM; | 233 | return -ENOMEM; |
237 | 234 | ||
@@ -250,56 +247,27 @@ static int vx855gpio_probe(struct platform_device *pdev) | |||
250 | * succeed. Ignore and continue. | 247 | * succeed. Ignore and continue. |
251 | */ | 248 | */ |
252 | 249 | ||
253 | if (!request_region(res_gpi->start, resource_size(res_gpi), | 250 | if (!devm_request_region(&pdev->dev, res_gpi->start, |
254 | MODULE_NAME "_gpi")) | 251 | resource_size(res_gpi), MODULE_NAME "_gpi")) |
255 | dev_warn(&pdev->dev, | 252 | dev_warn(&pdev->dev, |
256 | "GPI I/O resource busy, probably claimed by ACPI\n"); | 253 | "GPI I/O resource busy, probably claimed by ACPI\n"); |
257 | else | ||
258 | vg->gpi_reserved = true; | ||
259 | 254 | ||
260 | if (!request_region(res_gpo->start, resource_size(res_gpo), | 255 | if (!devm_request_region(&pdev->dev, res_gpo->start, |
261 | MODULE_NAME "_gpo")) | 256 | resource_size(res_gpo), MODULE_NAME "_gpo")) |
262 | dev_warn(&pdev->dev, | 257 | dev_warn(&pdev->dev, |
263 | "GPO I/O resource busy, probably claimed by ACPI\n"); | 258 | "GPO I/O resource busy, probably claimed by ACPI\n"); |
264 | else | ||
265 | vg->gpo_reserved = true; | ||
266 | 259 | ||
267 | vx855gpio_gpio_setup(vg); | 260 | vx855gpio_gpio_setup(vg); |
268 | 261 | ||
269 | ret = gpiochip_add(&vg->gpio); | 262 | return gpiochip_add(&vg->gpio); |
270 | if (ret) { | ||
271 | dev_err(&pdev->dev, "failed to register GPIOs\n"); | ||
272 | goto out_release; | ||
273 | } | ||
274 | |||
275 | return 0; | ||
276 | |||
277 | out_release: | ||
278 | if (vg->gpi_reserved) | ||
279 | release_region(res_gpi->start, resource_size(res_gpi)); | ||
280 | if (vg->gpo_reserved) | ||
281 | release_region(res_gpi->start, resource_size(res_gpo)); | ||
282 | kfree(vg); | ||
283 | return ret; | ||
284 | } | 263 | } |
285 | 264 | ||
286 | static int vx855gpio_remove(struct platform_device *pdev) | 265 | static int vx855gpio_remove(struct platform_device *pdev) |
287 | { | 266 | { |
288 | struct vx855_gpio *vg = platform_get_drvdata(pdev); | 267 | struct vx855_gpio *vg = platform_get_drvdata(pdev); |
289 | struct resource *res; | ||
290 | 268 | ||
291 | gpiochip_remove(&vg->gpio); | 269 | gpiochip_remove(&vg->gpio); |
292 | 270 | ||
293 | if (vg->gpi_reserved) { | ||
294 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | ||
295 | release_region(res->start, resource_size(res)); | ||
296 | } | ||
297 | if (vg->gpo_reserved) { | ||
298 | res = platform_get_resource(pdev, IORESOURCE_IO, 1); | ||
299 | release_region(res->start, resource_size(res)); | ||
300 | } | ||
301 | |||
302 | kfree(vg); | ||
303 | return 0; | 271 | return 0; |
304 | } | 272 | } |
305 | 273 | ||