aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpio-em.c
diff options
context:
space:
mode:
authorMagnus Damm <damm@opensource.se>2013-03-13 07:06:30 -0400
committerLinus Walleij <linus.walleij@linaro.org>2013-03-27 11:05:09 -0400
commit1cfe6f8cb1078039a0f8dfc833a4ae752220d2db (patch)
tree8dc62e21a9fc3dee5cf772f56bb4ad992e1ae47d /drivers/gpio/gpio-em.c
parent977d16b87a78844f090af0565cbd2e3a94fd6337 (diff)
gpio: em: Make use of devm functions
Update the Emma Mobile GPIO driver to make use of devm functions. This simplifies the error handling and makes the code more compact. Signed-off-by: Magnus Damm <damm@opensource.se> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio/gpio-em.c')
-rw-r--r--drivers/gpio/gpio-em.c53
1 files changed, 19 insertions, 34 deletions
diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
index d05369735857..5cba855638bf 100644
--- a/drivers/gpio/gpio-em.c
+++ b/drivers/gpio/gpio-em.c
@@ -245,7 +245,7 @@ static int em_gio_probe(struct platform_device *pdev)
245 const char *name = dev_name(&pdev->dev); 245 const char *name = dev_name(&pdev->dev);
246 int ret; 246 int ret;
247 247
248 p = kzalloc(sizeof(*p), GFP_KERNEL); 248 p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL);
249 if (!p) { 249 if (!p) {
250 dev_err(&pdev->dev, "failed to allocate driver data\n"); 250 dev_err(&pdev->dev, "failed to allocate driver data\n");
251 ret = -ENOMEM; 251 ret = -ENOMEM;
@@ -264,21 +264,23 @@ static int em_gio_probe(struct platform_device *pdev)
264 if (!io[0] || !io[1] || !irq[0] || !irq[1]) { 264 if (!io[0] || !io[1] || !irq[0] || !irq[1]) {
265 dev_err(&pdev->dev, "missing IRQ or IOMEM\n"); 265 dev_err(&pdev->dev, "missing IRQ or IOMEM\n");
266 ret = -EINVAL; 266 ret = -EINVAL;
267 goto err1; 267 goto err0;
268 } 268 }
269 269
270 p->base0 = ioremap_nocache(io[0]->start, resource_size(io[0])); 270 p->base0 = devm_ioremap_nocache(&pdev->dev, io[0]->start,
271 resource_size(io[0]));
271 if (!p->base0) { 272 if (!p->base0) {
272 dev_err(&pdev->dev, "failed to remap low I/O memory\n"); 273 dev_err(&pdev->dev, "failed to remap low I/O memory\n");
273 ret = -ENXIO; 274 ret = -ENXIO;
274 goto err1; 275 goto err0;
275 } 276 }
276 277
277 p->base1 = ioremap_nocache(io[1]->start, resource_size(io[1])); 278 p->base1 = devm_ioremap_nocache(&pdev->dev, io[1]->start,
279 resource_size(io[1]));
278 if (!p->base1) { 280 if (!p->base1) {
279 dev_err(&pdev->dev, "failed to remap high I/O memory\n"); 281 dev_err(&pdev->dev, "failed to remap high I/O memory\n");
280 ret = -ENXIO; 282 ret = -ENXIO;
281 goto err2; 283 goto err0;
282 } 284 }
283 285
284 if (!pdata) { 286 if (!pdata) {
@@ -289,13 +291,13 @@ static int em_gio_probe(struct platform_device *pdev)
289 &pdata->number_of_pins)) { 291 &pdata->number_of_pins)) {
290 dev_err(&pdev->dev, "Missing ngpios OF property\n"); 292 dev_err(&pdev->dev, "Missing ngpios OF property\n");
291 ret = -EINVAL; 293 ret = -EINVAL;
292 goto err3; 294 goto err0;
293 } 295 }
294 296
295 ret = of_alias_get_id(pdev->dev.of_node, "gpio"); 297 ret = of_alias_get_id(pdev->dev.of_node, "gpio");
296 if (ret < 0) { 298 if (ret < 0) {
297 dev_err(&pdev->dev, "Couldn't get OF id\n"); 299 dev_err(&pdev->dev, "Couldn't get OF id\n");
298 goto err3; 300 goto err0;
299 } 301 }
300 pdata->gpio_base = ret * 32; /* 32 GPIOs per instance */ 302 pdata->gpio_base = ret * 32; /* 32 GPIOs per instance */
301 } 303 }
@@ -327,40 +329,32 @@ static int em_gio_probe(struct platform_device *pdev)
327 if (!p->irq_domain) { 329 if (!p->irq_domain) {
328 ret = -ENXIO; 330 ret = -ENXIO;
329 dev_err(&pdev->dev, "cannot initialize irq domain\n"); 331 dev_err(&pdev->dev, "cannot initialize irq domain\n");
330 goto err3; 332 goto err0;
331 } 333 }
332 334
333 if (request_irq(irq[0]->start, em_gio_irq_handler, 0, name, p)) { 335 if (devm_request_irq(&pdev->dev, irq[0]->start,
336 em_gio_irq_handler, 0, name, p)) {
334 dev_err(&pdev->dev, "failed to request low IRQ\n"); 337 dev_err(&pdev->dev, "failed to request low IRQ\n");
335 ret = -ENOENT; 338 ret = -ENOENT;
336 goto err4; 339 goto err1;
337 } 340 }
338 341
339 if (request_irq(irq[1]->start, em_gio_irq_handler, 0, name, p)) { 342 if (devm_request_irq(&pdev->dev, irq[1]->start,
343 em_gio_irq_handler, 0, name, p)) {
340 dev_err(&pdev->dev, "failed to request high IRQ\n"); 344 dev_err(&pdev->dev, "failed to request high IRQ\n");
341 ret = -ENOENT; 345 ret = -ENOENT;
342 goto err5; 346 goto err1;
343 } 347 }
344 348
345 ret = gpiochip_add(gpio_chip); 349 ret = gpiochip_add(gpio_chip);
346 if (ret) { 350 if (ret) {
347 dev_err(&pdev->dev, "failed to add GPIO controller\n"); 351 dev_err(&pdev->dev, "failed to add GPIO controller\n");
348 goto err6; 352 goto err1;
349 } 353 }
350 return 0; 354 return 0;
351 355
352err6:
353 free_irq(irq[1]->start, pdev);
354err5:
355 free_irq(irq[0]->start, pdev);
356err4:
357 irq_domain_remove(p->irq_domain);
358err3:
359 iounmap(p->base1);
360err2:
361 iounmap(p->base0);
362err1: 356err1:
363 kfree(p); 357 irq_domain_remove(p->irq_domain);
364err0: 358err0:
365 return ret; 359 return ret;
366} 360}
@@ -368,22 +362,13 @@ err0:
368static int em_gio_remove(struct platform_device *pdev) 362static int em_gio_remove(struct platform_device *pdev)
369{ 363{
370 struct em_gio_priv *p = platform_get_drvdata(pdev); 364 struct em_gio_priv *p = platform_get_drvdata(pdev);
371 struct resource *irq[2];
372 int ret; 365 int ret;
373 366
374 ret = gpiochip_remove(&p->gpio_chip); 367 ret = gpiochip_remove(&p->gpio_chip);
375 if (ret) 368 if (ret)
376 return ret; 369 return ret;
377 370
378 irq[0] = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
379 irq[1] = platform_get_resource(pdev, IORESOURCE_IRQ, 1);
380
381 free_irq(irq[1]->start, pdev);
382 free_irq(irq[0]->start, pdev);
383 irq_domain_remove(p->irq_domain); 371 irq_domain_remove(p->irq_domain);
384 iounmap(p->base1);
385 iounmap(p->base0);
386 kfree(p);
387 return 0; 372 return 0;
388} 373}
389 374