aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/plat-omap/dmtimer.c
diff options
context:
space:
mode:
authorTarun Kanti DebBarma <tarun.kanti@ti.com>2012-04-20 08:39:20 -0400
committerTony Lindgren <tony@atomide.com>2012-07-05 05:15:55 -0400
commit74dd9ec627582bfd4477f01ceeaaa3f54e3748b8 (patch)
treedad19ae8fe028e4924dc14e63100dc42490abc11 /arch/arm/plat-omap/dmtimer.c
parentac5b0ea3d00d231dd9cedd45636b29defc368a4c (diff)
ARM: OMAP: dmtimer: use devm_ API and do some cleanup in probe()
Replace the regular kzalloc and ioremap with the devm_ equivalent to simplify error handling. We don't need kree() any more in omap_dm_timer_remove(). Also added *dev* pointer to reference pdev->dev which makes the usage shorter in code. Cc: Cousson, Benoit <b-cousson@ti.com> Cc: Paul Walmsley <paul@pwsan.com> Cc: Kevin Hilman <khilman@ti.com> Cc: Rajendra Nayak <rnayak@ti.com> Cc: Santosh Shilimkar <santosh.shilimkar@ti.com> Signed-off-by: Tarun Kanti DebBarma <tarun.kanti@ti.com> Signed-off-by: Tony Lindgren <tony@atomide.com>
Diffstat (limited to 'arch/arm/plat-omap/dmtimer.c')
-rw-r--r--arch/arm/plat-omap/dmtimer.c53
1 files changed, 17 insertions, 36 deletions
diff --git a/arch/arm/plat-omap/dmtimer.c b/arch/arm/plat-omap/dmtimer.c
index 54ed4e6e429..626ad8cad7a 100644
--- a/arch/arm/plat-omap/dmtimer.c
+++ b/arch/arm/plat-omap/dmtimer.c
@@ -37,7 +37,7 @@
37 37
38#include <linux/module.h> 38#include <linux/module.h>
39#include <linux/io.h> 39#include <linux/io.h>
40#include <linux/slab.h> 40#include <linux/device.h>
41#include <linux/err.h> 41#include <linux/err.h>
42#include <linux/pm_runtime.h> 42#include <linux/pm_runtime.h>
43 43
@@ -689,49 +689,39 @@ EXPORT_SYMBOL_GPL(omap_dm_timers_active);
689 */ 689 */
690static int __devinit omap_dm_timer_probe(struct platform_device *pdev) 690static int __devinit omap_dm_timer_probe(struct platform_device *pdev)
691{ 691{
692 int ret;
693 unsigned long flags; 692 unsigned long flags;
694 struct omap_dm_timer *timer; 693 struct omap_dm_timer *timer;
695 struct resource *mem, *irq, *ioarea; 694 struct resource *mem, *irq;
695 struct device *dev = &pdev->dev;
696 struct dmtimer_platform_data *pdata = pdev->dev.platform_data; 696 struct dmtimer_platform_data *pdata = pdev->dev.platform_data;
697 697
698 if (!pdata) { 698 if (!pdata) {
699 dev_err(&pdev->dev, "%s: no platform data.\n", __func__); 699 dev_err(dev, "%s: no platform data.\n", __func__);
700 return -ENODEV; 700 return -ENODEV;
701 } 701 }
702 702
703 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 703 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
704 if (unlikely(!irq)) { 704 if (unlikely(!irq)) {
705 dev_err(&pdev->dev, "%s: no IRQ resource.\n", __func__); 705 dev_err(dev, "%s: no IRQ resource.\n", __func__);
706 return -ENODEV; 706 return -ENODEV;
707 } 707 }
708 708
709 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 709 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
710 if (unlikely(!mem)) { 710 if (unlikely(!mem)) {
711 dev_err(&pdev->dev, "%s: no memory resource.\n", __func__); 711 dev_err(dev, "%s: no memory resource.\n", __func__);
712 return -ENODEV; 712 return -ENODEV;
713 } 713 }
714 714
715 ioarea = request_mem_region(mem->start, resource_size(mem), 715 timer = devm_kzalloc(dev, sizeof(struct omap_dm_timer), GFP_KERNEL);
716 pdev->name);
717 if (!ioarea) {
718 dev_err(&pdev->dev, "%s: region already claimed.\n", __func__);
719 return -EBUSY;
720 }
721
722 timer = kzalloc(sizeof(struct omap_dm_timer), GFP_KERNEL);
723 if (!timer) { 716 if (!timer) {
724 dev_err(&pdev->dev, "%s: no memory for omap_dm_timer.\n", 717 dev_err(dev, "%s: memory alloc failed!\n", __func__);
725 __func__); 718 return -ENOMEM;
726 ret = -ENOMEM;
727 goto err_free_ioregion;
728 } 719 }
729 720
730 timer->io_base = ioremap(mem->start, resource_size(mem)); 721 timer->io_base = devm_request_and_ioremap(dev, mem);
731 if (!timer->io_base) { 722 if (!timer->io_base) {
732 dev_err(&pdev->dev, "%s: ioremap failed.\n", __func__); 723 dev_err(dev, "%s: region already claimed.\n", __func__);
733 ret = -ENOMEM; 724 return -ENOMEM;
734 goto err_free_mem;
735 } 725 }
736 726
737 timer->id = pdev->id; 727 timer->id = pdev->id;
@@ -742,14 +732,14 @@ static int __devinit omap_dm_timer_probe(struct platform_device *pdev)
742 732
743 /* Skip pm_runtime_enable for OMAP1 */ 733 /* Skip pm_runtime_enable for OMAP1 */
744 if (!(timer->capability & OMAP_TIMER_NEEDS_RESET)) { 734 if (!(timer->capability & OMAP_TIMER_NEEDS_RESET)) {
745 pm_runtime_enable(&pdev->dev); 735 pm_runtime_enable(dev);
746 pm_runtime_irq_safe(&pdev->dev); 736 pm_runtime_irq_safe(dev);
747 } 737 }
748 738
749 if (!timer->reserved) { 739 if (!timer->reserved) {
750 pm_runtime_get_sync(&pdev->dev); 740 pm_runtime_get_sync(dev);
751 __omap_dm_timer_init_regs(timer); 741 __omap_dm_timer_init_regs(timer);
752 pm_runtime_put(&pdev->dev); 742 pm_runtime_put(dev);
753 } 743 }
754 744
755 /* add the timer element to the list */ 745 /* add the timer element to the list */
@@ -757,17 +747,9 @@ static int __devinit omap_dm_timer_probe(struct platform_device *pdev)
757 list_add_tail(&timer->node, &omap_timer_list); 747 list_add_tail(&timer->node, &omap_timer_list);
758 spin_unlock_irqrestore(&dm_timer_lock, flags); 748 spin_unlock_irqrestore(&dm_timer_lock, flags);
759 749
760 dev_dbg(&pdev->dev, "Device Probed.\n"); 750 dev_dbg(dev, "Device Probed.\n");
761 751
762 return 0; 752 return 0;
763
764err_free_mem:
765 kfree(timer);
766
767err_free_ioregion:
768 release_mem_region(mem->start, resource_size(mem));
769
770 return ret;
771} 753}
772 754
773/** 755/**
@@ -788,7 +770,6 @@ static int __devexit omap_dm_timer_remove(struct platform_device *pdev)
788 list_for_each_entry(timer, &omap_timer_list, node) 770 list_for_each_entry(timer, &omap_timer_list, node)
789 if (timer->pdev->id == pdev->id) { 771 if (timer->pdev->id == pdev->id) {
790 list_del(&timer->node); 772 list_del(&timer->node);
791 kfree(timer);
792 ret = 0; 773 ret = 0;
793 break; 774 break;
794 } 775 }