aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc/rtc-sa1100.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-03-27 19:41:24 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-03-27 19:41:24 -0400
commit34800598b2eebe061445216473b1e4c2ff5cba99 (patch)
treea6d0eb6fe45d9480888d7ddb34840e172ed80e56 /drivers/rtc/rtc-sa1100.c
parent46b407ca4a6149c8d27fcec1881d4f184bec7c77 (diff)
parent511f1cb6d426938fabf9c6d69ce4861b66ffd919 (diff)
Merge tag 'drivers' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc
Pull "ARM: driver specific updates" from Arnd Bergmann: "These are all specific to some driver. They are typically the platform side of a change in the drivers directory, such as adding a new driver or extending the interface to the platform. In cases where there is no maintainer for the driver, or the maintainer prefers to have the platform changes in the same branch as the driver changes, the patches to the drivers are included as well. A much smaller set of driver updates that depend on other branches getting merged first will be sent later. The new export of tegra_chip_uid conflicts with other changes in fuse.c. In rtc-sa1100.c, the global removal of IRQF_DISABLED conflicts with the cleanup of the interrupt handling of that driver. Signed-off-by: Arnd Bergmann <arnd@arndb.de>" Fixed up aforementioned trivial conflicts. * tag 'drivers' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc: (94 commits) ARM: SAMSUNG: change the name from s3c-sdhci to exynos4-sdhci mmc: sdhci-s3c: add platform data for the second capability ARM: SAMSUNG: support the second capability for samsung-soc ARM: EXYNOS: add support DMA for EXYNOS4X12 SoC ARM: EXYNOS: Add apb_pclk clkdev entry for mdma1 ARM: EXYNOS: Enable MDMA driver regulator: Remove bq24022 regulator driver rtc: sa1100: add OF support pxa: magician/hx4700: Convert to gpio-regulator from bq24022 ARM: OMAP3+: SmartReflex: fix error handling ARM: OMAP3+: SmartReflex: fix the use of debugfs_create_* API ARM: OMAP3+: SmartReflex: micro-optimization for sanity check ARM: OMAP3+: SmartReflex: misc cleanups ARM: OMAP3+: SmartReflex: move late_initcall() closer to its argument ARM: OMAP3+: SmartReflex: add missing platform_set_drvdata() ARM: OMAP3+: hwmod: add SmartReflex IRQs ARM: OMAP3+: SmartReflex: clear ERRCONFIG_VPBOUNDINTST only on a need ARM: OMAP3+: SmartReflex: Fix status masking in ERRCONFIG register ARM: OMAP3+: SmartReflex: Add a shutdown hook ARM: OMAP3+: SmartReflex Class3: disable errorgen before disable VP ... Conflicts: arch/arm/mach-tegra/Makefile arch/arm/mach-tegra/fuse.c drivers/rtc/rtc-sa1100.c
Diffstat (limited to 'drivers/rtc/rtc-sa1100.c')
-rw-r--r--drivers/rtc/rtc-sa1100.c127
1 files changed, 94 insertions, 33 deletions
diff --git a/drivers/rtc/rtc-sa1100.c b/drivers/rtc/rtc-sa1100.c
index 44cd81c72ea1..fa512ed42017 100644
--- a/drivers/rtc/rtc-sa1100.c
+++ b/drivers/rtc/rtc-sa1100.c
@@ -23,35 +23,44 @@
23 23
24#include <linux/platform_device.h> 24#include <linux/platform_device.h>
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/clk.h>
26#include <linux/rtc.h> 27#include <linux/rtc.h>
27#include <linux/init.h> 28#include <linux/init.h>
28#include <linux/fs.h> 29#include <linux/fs.h>
29#include <linux/interrupt.h> 30#include <linux/interrupt.h>
31#include <linux/slab.h>
30#include <linux/string.h> 32#include <linux/string.h>
33#include <linux/of.h>
31#include <linux/pm.h> 34#include <linux/pm.h>
32#include <linux/bitops.h> 35#include <linux/bitops.h>
33 36
34#include <mach/hardware.h> 37#include <mach/hardware.h>
35#include <asm/irq.h> 38#include <asm/irq.h>
36 39
37#ifdef CONFIG_ARCH_PXA 40#if defined(CONFIG_ARCH_PXA) || defined(CONFIG_ARCH_MMP)
38#include <mach/regs-rtc.h> 41#include <mach/regs-rtc.h>
39#endif 42#endif
40 43
41#define RTC_DEF_DIVIDER (32768 - 1) 44#define RTC_DEF_DIVIDER (32768 - 1)
42#define RTC_DEF_TRIM 0 45#define RTC_DEF_TRIM 0
43 46#define RTC_FREQ 1024
44static const unsigned long RTC_FREQ = 1024; 47
45static DEFINE_SPINLOCK(sa1100_rtc_lock); 48struct sa1100_rtc {
49 spinlock_t lock;
50 int irq_1hz;
51 int irq_alarm;
52 struct rtc_device *rtc;
53 struct clk *clk;
54};
46 55
47static irqreturn_t sa1100_rtc_interrupt(int irq, void *dev_id) 56static irqreturn_t sa1100_rtc_interrupt(int irq, void *dev_id)
48{ 57{
49 struct platform_device *pdev = to_platform_device(dev_id); 58 struct sa1100_rtc *info = dev_get_drvdata(dev_id);
50 struct rtc_device *rtc = platform_get_drvdata(pdev); 59 struct rtc_device *rtc = info->rtc;
51 unsigned int rtsr; 60 unsigned int rtsr;
52 unsigned long events = 0; 61 unsigned long events = 0;
53 62
54 spin_lock(&sa1100_rtc_lock); 63 spin_lock(&info->lock);
55 64
56 rtsr = RTSR; 65 rtsr = RTSR;
57 /* clear interrupt sources */ 66 /* clear interrupt sources */
@@ -87,26 +96,28 @@ static irqreturn_t sa1100_rtc_interrupt(int irq, void *dev_id)
87 96
88 rtc_update_irq(rtc, 1, events); 97 rtc_update_irq(rtc, 1, events);
89 98
90 spin_unlock(&sa1100_rtc_lock); 99 spin_unlock(&info->lock);
91 100
92 return IRQ_HANDLED; 101 return IRQ_HANDLED;
93} 102}
94 103
95static int sa1100_rtc_open(struct device *dev) 104static int sa1100_rtc_open(struct device *dev)
96{ 105{
106 struct sa1100_rtc *info = dev_get_drvdata(dev);
107 struct rtc_device *rtc = info->rtc;
97 int ret; 108 int ret;
98 struct platform_device *plat_dev = to_platform_device(dev);
99 struct rtc_device *rtc = platform_get_drvdata(plat_dev);
100 109
101 ret = request_irq(IRQ_RTC1Hz, sa1100_rtc_interrupt, 0, "rtc 1Hz", dev); 110 ret = clk_prepare_enable(info->clk);
111 if (ret)
112 goto fail_clk;
113 ret = request_irq(info->irq_1hz, sa1100_rtc_interrupt, 0, "rtc 1Hz", dev);
102 if (ret) { 114 if (ret) {
103 dev_err(dev, "IRQ %d already in use.\n", IRQ_RTC1Hz); 115 dev_err(dev, "IRQ %d already in use.\n", info->irq_1hz);
104 goto fail_ui; 116 goto fail_ui;
105 } 117 }
106 ret = request_irq(IRQ_RTCAlrm, sa1100_rtc_interrupt, 0, 118 ret = request_irq(info->irq_alarm, sa1100_rtc_interrupt, 0, "rtc Alrm", dev);
107 "rtc Alrm", dev);
108 if (ret) { 119 if (ret) {
109 dev_err(dev, "IRQ %d already in use.\n", IRQ_RTCAlrm); 120 dev_err(dev, "IRQ %d already in use.\n", info->irq_alarm);
110 goto fail_ai; 121 goto fail_ai;
111 } 122 }
112 rtc->max_user_freq = RTC_FREQ; 123 rtc->max_user_freq = RTC_FREQ;
@@ -115,29 +126,36 @@ static int sa1100_rtc_open(struct device *dev)
115 return 0; 126 return 0;
116 127
117 fail_ai: 128 fail_ai:
118 free_irq(IRQ_RTC1Hz, dev); 129 free_irq(info->irq_1hz, dev);
119 fail_ui: 130 fail_ui:
131 clk_disable_unprepare(info->clk);
132 fail_clk:
120 return ret; 133 return ret;
121} 134}
122 135
123static void sa1100_rtc_release(struct device *dev) 136static void sa1100_rtc_release(struct device *dev)
124{ 137{
125 spin_lock_irq(&sa1100_rtc_lock); 138 struct sa1100_rtc *info = dev_get_drvdata(dev);
139
140 spin_lock_irq(&info->lock);
126 RTSR = 0; 141 RTSR = 0;
127 spin_unlock_irq(&sa1100_rtc_lock); 142 spin_unlock_irq(&info->lock);
128 143
129 free_irq(IRQ_RTCAlrm, dev); 144 free_irq(info->irq_alarm, dev);
130 free_irq(IRQ_RTC1Hz, dev); 145 free_irq(info->irq_1hz, dev);
146 clk_disable_unprepare(info->clk);
131} 147}
132 148
133static int sa1100_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) 149static int sa1100_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
134{ 150{
135 spin_lock_irq(&sa1100_rtc_lock); 151 struct sa1100_rtc *info = dev_get_drvdata(dev);
152
153 spin_lock_irq(&info->lock);
136 if (enabled) 154 if (enabled)
137 RTSR |= RTSR_ALE; 155 RTSR |= RTSR_ALE;
138 else 156 else
139 RTSR &= ~RTSR_ALE; 157 RTSR &= ~RTSR_ALE;
140 spin_unlock_irq(&sa1100_rtc_lock); 158 spin_unlock_irq(&info->lock);
141 return 0; 159 return 0;
142} 160}
143 161
@@ -170,10 +188,11 @@ static int sa1100_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
170 188
171static int sa1100_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) 189static int sa1100_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
172{ 190{
191 struct sa1100_rtc *info = dev_get_drvdata(dev);
173 unsigned long time; 192 unsigned long time;
174 int ret; 193 int ret;
175 194
176 spin_lock_irq(&sa1100_rtc_lock); 195 spin_lock_irq(&info->lock);
177 ret = rtc_tm_to_time(&alrm->time, &time); 196 ret = rtc_tm_to_time(&alrm->time, &time);
178 if (ret != 0) 197 if (ret != 0)
179 goto out; 198 goto out;
@@ -184,7 +203,7 @@ static int sa1100_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
184 else 203 else
185 RTSR &= ~RTSR_ALE; 204 RTSR &= ~RTSR_ALE;
186out: 205out:
187 spin_unlock_irq(&sa1100_rtc_lock); 206 spin_unlock_irq(&info->lock);
188 207
189 return ret; 208 return ret;
190} 209}
@@ -211,6 +230,27 @@ static const struct rtc_class_ops sa1100_rtc_ops = {
211static int sa1100_rtc_probe(struct platform_device *pdev) 230static int sa1100_rtc_probe(struct platform_device *pdev)
212{ 231{
213 struct rtc_device *rtc; 232 struct rtc_device *rtc;
233 struct sa1100_rtc *info;
234 int irq_1hz, irq_alarm, ret = 0;
235
236 irq_1hz = platform_get_irq_byname(pdev, "rtc 1Hz");
237 irq_alarm = platform_get_irq_byname(pdev, "rtc alarm");
238 if (irq_1hz < 0 || irq_alarm < 0)
239 return -ENODEV;
240
241 info = kzalloc(sizeof(struct sa1100_rtc), GFP_KERNEL);
242 if (!info)
243 return -ENOMEM;
244 info->clk = clk_get(&pdev->dev, NULL);
245 if (IS_ERR(info->clk)) {
246 dev_err(&pdev->dev, "failed to find rtc clock source\n");
247 ret = PTR_ERR(info->clk);
248 goto err_clk;
249 }
250 info->irq_1hz = irq_1hz;
251 info->irq_alarm = irq_alarm;
252 spin_lock_init(&info->lock);
253 platform_set_drvdata(pdev, info);
214 254
215 /* 255 /*
216 * According to the manual we should be able to let RTTR be zero 256 * According to the manual we should be able to let RTTR be zero
@@ -232,10 +272,11 @@ static int sa1100_rtc_probe(struct platform_device *pdev)
232 rtc = rtc_device_register(pdev->name, &pdev->dev, &sa1100_rtc_ops, 272 rtc = rtc_device_register(pdev->name, &pdev->dev, &sa1100_rtc_ops,
233 THIS_MODULE); 273 THIS_MODULE);
234 274
235 if (IS_ERR(rtc)) 275 if (IS_ERR(rtc)) {
236 return PTR_ERR(rtc); 276 ret = PTR_ERR(rtc);
237 277 goto err_dev;
238 platform_set_drvdata(pdev, rtc); 278 }
279 info->rtc = rtc;
239 280
240 /* Fix for a nasty initialization problem the in SA11xx RTSR register. 281 /* Fix for a nasty initialization problem the in SA11xx RTSR register.
241 * See also the comments in sa1100_rtc_interrupt(). 282 * See also the comments in sa1100_rtc_interrupt().
@@ -262,14 +303,24 @@ static int sa1100_rtc_probe(struct platform_device *pdev)
262 RTSR = RTSR_AL | RTSR_HZ; 303 RTSR = RTSR_AL | RTSR_HZ;
263 304
264 return 0; 305 return 0;
306err_dev:
307 platform_set_drvdata(pdev, NULL);
308 clk_put(info->clk);
309err_clk:
310 kfree(info);
311 return ret;
265} 312}
266 313
267static int sa1100_rtc_remove(struct platform_device *pdev) 314static int sa1100_rtc_remove(struct platform_device *pdev)
268{ 315{
269 struct rtc_device *rtc = platform_get_drvdata(pdev); 316 struct sa1100_rtc *info = platform_get_drvdata(pdev);
270 317
271 if (rtc) 318 if (info) {
272 rtc_device_unregister(rtc); 319 rtc_device_unregister(info->rtc);
320 clk_put(info->clk);
321 platform_set_drvdata(pdev, NULL);
322 kfree(info);
323 }
273 324
274 return 0; 325 return 0;
275} 326}
@@ -277,15 +328,17 @@ static int sa1100_rtc_remove(struct platform_device *pdev)
277#ifdef CONFIG_PM 328#ifdef CONFIG_PM
278static int sa1100_rtc_suspend(struct device *dev) 329static int sa1100_rtc_suspend(struct device *dev)
279{ 330{
331 struct sa1100_rtc *info = dev_get_drvdata(dev);
280 if (device_may_wakeup(dev)) 332 if (device_may_wakeup(dev))
281 enable_irq_wake(IRQ_RTCAlrm); 333 enable_irq_wake(info->irq_alarm);
282 return 0; 334 return 0;
283} 335}
284 336
285static int sa1100_rtc_resume(struct device *dev) 337static int sa1100_rtc_resume(struct device *dev)
286{ 338{
339 struct sa1100_rtc *info = dev_get_drvdata(dev);
287 if (device_may_wakeup(dev)) 340 if (device_may_wakeup(dev))
288 disable_irq_wake(IRQ_RTCAlrm); 341 disable_irq_wake(info->irq_alarm);
289 return 0; 342 return 0;
290} 343}
291 344
@@ -295,6 +348,13 @@ static const struct dev_pm_ops sa1100_rtc_pm_ops = {
295}; 348};
296#endif 349#endif
297 350
351static struct of_device_id sa1100_rtc_dt_ids[] = {
352 { .compatible = "mrvl,sa1100-rtc", },
353 { .compatible = "mrvl,mmp-rtc", },
354 {}
355};
356MODULE_DEVICE_TABLE(of, sa1100_rtc_dt_ids);
357
298static struct platform_driver sa1100_rtc_driver = { 358static struct platform_driver sa1100_rtc_driver = {
299 .probe = sa1100_rtc_probe, 359 .probe = sa1100_rtc_probe,
300 .remove = sa1100_rtc_remove, 360 .remove = sa1100_rtc_remove,
@@ -303,6 +363,7 @@ static struct platform_driver sa1100_rtc_driver = {
303#ifdef CONFIG_PM 363#ifdef CONFIG_PM
304 .pm = &sa1100_rtc_pm_ops, 364 .pm = &sa1100_rtc_pm_ops,
305#endif 365#endif
366 .of_match_table = sa1100_rtc_dt_ids,
306 }, 367 },
307}; 368};
308 369