diff options
Diffstat (limited to 'drivers/rtc/rtc-coh901331.c')
| -rw-r--r-- | drivers/rtc/rtc-coh901331.c | 126 | 
1 files changed, 42 insertions, 84 deletions
diff --git a/drivers/rtc/rtc-coh901331.c b/drivers/rtc/rtc-coh901331.c index 316f484999b..869cae27379 100644 --- a/drivers/rtc/rtc-coh901331.c +++ b/drivers/rtc/rtc-coh901331.c @@ -43,11 +43,9 @@  struct coh901331_port {  	struct rtc_device *rtc;  	struct clk *clk; -	u32 phybase; -	u32 physize;  	void __iomem *virtbase;  	int irq; -#ifdef CONFIG_PM +#ifdef CONFIG_PM_SLEEP  	u32 irqmaskstore;  #endif  }; @@ -152,17 +150,10 @@ static struct rtc_class_ops coh901331_ops = {  static int __exit coh901331_remove(struct platform_device *pdev)  { -	struct coh901331_port *rtap = dev_get_drvdata(&pdev->dev); - -	if (rtap) { -		free_irq(rtap->irq, rtap); -		rtc_device_unregister(rtap->rtc); -		clk_put(rtap->clk); -		iounmap(rtap->virtbase); -		release_mem_region(rtap->phybase, rtap->physize); -		platform_set_drvdata(pdev, NULL); -		kfree(rtap); -	} +	struct coh901331_port *rtap = platform_get_drvdata(pdev); + +	if (rtap) +		clk_unprepare(rtap->clk);  	return 0;  } @@ -174,90 +165,62 @@ static int __init coh901331_probe(struct platform_device *pdev)  	struct coh901331_port *rtap;  	struct resource *res; -	rtap = kzalloc(sizeof(struct coh901331_port), GFP_KERNEL); +	rtap = devm_kzalloc(&pdev->dev, +			    sizeof(struct coh901331_port), GFP_KERNEL);  	if (!rtap)  		return -ENOMEM;  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0); -	if (!res) { -		ret = -ENOENT; -		goto out_no_resource; -	} -	rtap->phybase = res->start; -	rtap->physize = resource_size(res); - -	if (request_mem_region(rtap->phybase, rtap->physize, -			       "rtc-coh901331") == NULL) { -		ret = -EBUSY; -		goto out_no_memregion; -	} - -	rtap->virtbase = ioremap(rtap->phybase, rtap->physize); -	if (!rtap->virtbase) { -		ret = -ENOMEM; -		goto out_no_remap; -	} +	rtap->virtbase  = devm_ioremap_resource(&pdev->dev, res); +	if (IS_ERR(rtap->virtbase)) +		return PTR_ERR(rtap->virtbase);  	rtap->irq = platform_get_irq(pdev, 0); -	if (request_irq(rtap->irq, coh901331_interrupt, IRQF_DISABLED, -			"RTC COH 901 331 Alarm", rtap)) { -		ret = -EIO; -		goto out_no_irq; -	} +	if (devm_request_irq(&pdev->dev, rtap->irq, coh901331_interrupt, 0, +			     "RTC COH 901 331 Alarm", rtap)) +		return -EIO; -	rtap->clk = clk_get(&pdev->dev, NULL); +	rtap->clk = devm_clk_get(&pdev->dev, NULL);  	if (IS_ERR(rtap->clk)) {  		ret = PTR_ERR(rtap->clk);  		dev_err(&pdev->dev, "could not get clock\n"); -		goto out_no_clk; +		return ret;  	}  	/* We enable/disable the clock only to assure it works */ -	ret = clk_enable(rtap->clk); +	ret = clk_prepare_enable(rtap->clk);  	if (ret) {  		dev_err(&pdev->dev, "could not enable clock\n"); -		goto out_no_clk_enable; +		return ret;  	}  	clk_disable(rtap->clk); -	rtap->rtc = rtc_device_register("coh901331", &pdev->dev, &coh901331_ops, -					 THIS_MODULE); +	platform_set_drvdata(pdev, rtap); +	rtap->rtc = devm_rtc_device_register(&pdev->dev, "coh901331", +					&coh901331_ops, THIS_MODULE);  	if (IS_ERR(rtap->rtc)) {  		ret = PTR_ERR(rtap->rtc);  		goto out_no_rtc;  	} -	platform_set_drvdata(pdev, rtap); -  	return 0;   out_no_rtc: - out_no_clk_enable: -	clk_put(rtap->clk); - out_no_clk: -	free_irq(rtap->irq, rtap); - out_no_irq: -	iounmap(rtap->virtbase); - out_no_remap: -	platform_set_drvdata(pdev, NULL); - out_no_memregion: -	release_mem_region(rtap->phybase, SZ_4K); - out_no_resource: -	kfree(rtap); +	clk_unprepare(rtap->clk);  	return ret;  } -#ifdef CONFIG_PM -static int coh901331_suspend(struct platform_device *pdev, pm_message_t state) +#ifdef CONFIG_PM_SLEEP +static int coh901331_suspend(struct device *dev)  { -	struct coh901331_port *rtap = dev_get_drvdata(&pdev->dev); +	struct coh901331_port *rtap = dev_get_drvdata(dev);  	/*  	 * If this RTC alarm will be used for waking the system up,  	 * don't disable it of course. Else we just disable the alarm  	 * and await suspension.  	 */ -	if (device_may_wakeup(&pdev->dev)) { +	if (device_may_wakeup(dev)) {  		enable_irq_wake(rtap->irq);  	} else {  		clk_enable(rtap->clk); @@ -265,14 +228,16 @@ static int coh901331_suspend(struct platform_device *pdev, pm_message_t state)  		writel(0, rtap->virtbase + COH901331_IRQ_MASK);  		clk_disable(rtap->clk);  	} +	clk_unprepare(rtap->clk);  	return 0;  } -static int coh901331_resume(struct platform_device *pdev) +static int coh901331_resume(struct device *dev)  { -	struct coh901331_port *rtap = dev_get_drvdata(&pdev->dev); +	struct coh901331_port *rtap = dev_get_drvdata(dev); -	if (device_may_wakeup(&pdev->dev)) { +	clk_prepare(rtap->clk); +	if (device_may_wakeup(dev)) {  		disable_irq_wake(rtap->irq);  	} else {  		clk_enable(rtap->clk); @@ -281,43 +246,36 @@ static int coh901331_resume(struct platform_device *pdev)  	}  	return 0;  } -#else -#define coh901331_suspend NULL -#define coh901331_resume NULL  #endif +static SIMPLE_DEV_PM_OPS(coh901331_pm_ops, coh901331_suspend, coh901331_resume); +  static void coh901331_shutdown(struct platform_device *pdev)  { -	struct coh901331_port *rtap = dev_get_drvdata(&pdev->dev); +	struct coh901331_port *rtap = platform_get_drvdata(pdev);  	clk_enable(rtap->clk);  	writel(0, rtap->virtbase + COH901331_IRQ_MASK); -	clk_disable(rtap->clk); +	clk_disable_unprepare(rtap->clk);  } +static const struct of_device_id coh901331_dt_match[] = { +	{ .compatible = "stericsson,coh901331" }, +	{}, +}; +  static struct platform_driver coh901331_driver = {  	.driver = {  		.name = "rtc-coh901331",  		.owner = THIS_MODULE, +		.pm = &coh901331_pm_ops, +		.of_match_table = coh901331_dt_match,  	},  	.remove = __exit_p(coh901331_remove), -	.suspend = coh901331_suspend, -	.resume = coh901331_resume,  	.shutdown = coh901331_shutdown,  }; -static int __init coh901331_init(void) -{ -	return platform_driver_probe(&coh901331_driver, coh901331_probe); -} - -static void __exit coh901331_exit(void) -{ -	platform_driver_unregister(&coh901331_driver); -} - -module_init(coh901331_init); -module_exit(coh901331_exit); +module_platform_driver_probe(coh901331_driver, coh901331_probe);  MODULE_AUTHOR("Linus Walleij <linus.walleij@stericsson.com>");  MODULE_DESCRIPTION("ST-Ericsson AB COH 901 331 RTC Driver");  | 
