aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio
diff options
context:
space:
mode:
authorabdoulaye berthe <berthe.ab@gmail.com>2014-05-12 21:21:42 -0400
committerLinus Walleij <linus.walleij@linaro.org>2014-05-16 11:52:37 -0400
commit0ed3398ed8086597ff53d119fa48fa466f2f2754 (patch)
tree67c2c3c4576f6e414a36947bd8e7226118cf3176 /drivers/gpio
parenta435e1802b3620c830ee27a3f5cdbf936dac469d (diff)
gpio: timberdale: use devm functions
This eases memory allocation and provides appropriate logging. Signed-off-by: abdoulaye berthe <berthe.ab@gmail.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio')
-rw-r--r--drivers/gpio/gpio-timberdale.c47
1 files changed, 16 insertions, 31 deletions
diff --git a/drivers/gpio/gpio-timberdale.c b/drivers/gpio/gpio-timberdale.c
index f9a8fbde108e..efc7c129016d 100644
--- a/drivers/gpio/gpio-timberdale.c
+++ b/drivers/gpio/gpio-timberdale.c
@@ -224,6 +224,7 @@ static struct irq_chip timbgpio_irqchip = {
224static int timbgpio_probe(struct platform_device *pdev) 224static int timbgpio_probe(struct platform_device *pdev)
225{ 225{
226 int err, i; 226 int err, i;
227 struct device *dev = &pdev->dev;
227 struct gpio_chip *gc; 228 struct gpio_chip *gc;
228 struct timbgpio *tgpio; 229 struct timbgpio *tgpio;
229 struct resource *iomem; 230 struct resource *iomem;
@@ -231,35 +232,35 @@ static int timbgpio_probe(struct platform_device *pdev)
231 int irq = platform_get_irq(pdev, 0); 232 int irq = platform_get_irq(pdev, 0);
232 233
233 if (!pdata || pdata->nr_pins > 32) { 234 if (!pdata || pdata->nr_pins > 32) {
234 err = -EINVAL; 235 dev_err(dev, "Invalid platform data\n");
235 goto err_mem; 236 return -EINVAL;
236 } 237 }
237 238
238 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 239 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
239 if (!iomem) { 240 if (!iomem) {
240 err = -EINVAL; 241 dev_err(dev, "Unable to get resource\n");
241 goto err_mem; 242 return -EINVAL;
242 } 243 }
243 244
244 tgpio = kzalloc(sizeof(*tgpio), GFP_KERNEL); 245 tgpio = devm_kzalloc(dev, sizeof(struct timbgpio), GFP_KERNEL);
245 if (!tgpio) { 246 if (!tgpio) {
246 err = -EINVAL; 247 dev_err(dev, "Memory alloc failed\n");
247 goto err_mem; 248 return -EINVAL;
248 } 249 }
249 tgpio->irq_base = pdata->irq_base; 250 tgpio->irq_base = pdata->irq_base;
250 251
251 spin_lock_init(&tgpio->lock); 252 spin_lock_init(&tgpio->lock);
252 253
253 if (!request_mem_region(iomem->start, resource_size(iomem), 254 if (!devm_request_mem_region(dev, iomem->start, resource_size(iomem),
254 DRIVER_NAME)) { 255 DRIVER_NAME)) {
255 err = -EBUSY; 256 dev_err(dev, "Region already claimed\n");
256 goto err_request; 257 return -EBUSY;
257 } 258 }
258 259
259 tgpio->membase = ioremap(iomem->start, resource_size(iomem)); 260 tgpio->membase = devm_ioremap(dev, iomem->start, resource_size(iomem));
260 if (!tgpio->membase) { 261 if (!tgpio->membase) {
261 err = -ENOMEM; 262 dev_err(dev, "Cannot ioremap\n");
262 goto err_ioremap; 263 return -ENOMEM;
263 } 264 }
264 265
265 gc = &tgpio->gpio; 266 gc = &tgpio->gpio;
@@ -279,7 +280,7 @@ static int timbgpio_probe(struct platform_device *pdev)
279 280
280 err = gpiochip_add(gc); 281 err = gpiochip_add(gc);
281 if (err) 282 if (err)
282 goto err_chipadd; 283 return err;
283 284
284 platform_set_drvdata(pdev, tgpio); 285 platform_set_drvdata(pdev, tgpio);
285 286
@@ -302,17 +303,6 @@ static int timbgpio_probe(struct platform_device *pdev)
302 irq_set_chained_handler(irq, timbgpio_irq); 303 irq_set_chained_handler(irq, timbgpio_irq);
303 304
304 return 0; 305 return 0;
305
306err_chipadd:
307 iounmap(tgpio->membase);
308err_ioremap:
309 release_mem_region(iomem->start, resource_size(iomem));
310err_request:
311 kfree(tgpio);
312err_mem:
313 printk(KERN_ERR DRIVER_NAME": Failed to register GPIOs: %d\n", err);
314
315 return err;
316} 306}
317 307
318static int timbgpio_remove(struct platform_device *pdev) 308static int timbgpio_remove(struct platform_device *pdev)
@@ -320,7 +310,6 @@ static int timbgpio_remove(struct platform_device *pdev)
320 int err; 310 int err;
321 struct timbgpio_platform_data *pdata = dev_get_platdata(&pdev->dev); 311 struct timbgpio_platform_data *pdata = dev_get_platdata(&pdev->dev);
322 struct timbgpio *tgpio = platform_get_drvdata(pdev); 312 struct timbgpio *tgpio = platform_get_drvdata(pdev);
323 struct resource *iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
324 int irq = platform_get_irq(pdev, 0); 313 int irq = platform_get_irq(pdev, 0);
325 314
326 if (irq >= 0 && tgpio->irq_base > 0) { 315 if (irq >= 0 && tgpio->irq_base > 0) {
@@ -338,10 +327,6 @@ static int timbgpio_remove(struct platform_device *pdev)
338 if (err) 327 if (err)
339 printk(KERN_ERR DRIVER_NAME": failed to remove gpio_chip\n"); 328 printk(KERN_ERR DRIVER_NAME": failed to remove gpio_chip\n");
340 329
341 iounmap(tgpio->membase);
342 release_mem_region(iomem->start, resource_size(iomem));
343 kfree(tgpio);
344
345 return 0; 330 return 0;
346} 331}
347 332