Lines Matching +full:pxa +full:- +full:rtc
1 // SPDX-License-Identifier: GPL-2.0-or-later
11 #include <linux/rtc.h>
18 #include "rtc-sa1100.h"
20 #define RTC_DEF_DIVIDER (32768 - 1)
25 * PXA Registers and bits definitions
30 #define RTSR_SWALE2 (1 << 11) /* RTC stopwatch alarm2 enable */
31 #define RTSR_SWAL2 (1 << 10) /* RTC stopwatch alarm2 detected */
32 #define RTSR_SWALE1 (1 << 9) /* RTC stopwatch alarm1 enable */
33 #define RTSR_SWAL1 (1 << 8) /* RTC stopwatch alarm1 detected */
34 #define RTSR_RDALE2 (1 << 7) /* RTC alarm2 enable */
35 #define RTSR_RDAL2 (1 << 6) /* RTC alarm2 detected */
36 #define RTSR_RDALE1 (1 << 5) /* RTC alarm1 enable */
37 #define RTSR_RDAL1 (1 << 4) /* RTC alarm1 detected */
39 #define RTSR_ALE (1 << 2) /* RTC alarm interrupt enable */
40 #define RTSR_HZ (1 << 1) /* HZ rising-edge detected */
41 #define RTSR_AL (1 << 0) /* RTC alarm detected */
69 __raw_readl((pxa_rtc)->base + (reg))
71 __raw_writel((value), (pxa_rtc)->base + (reg))
77 struct rtc_device *rtc; member
84 return ((tm->tm_year + 1900) << RYxR_YEAR_S) in ryxr_calc()
85 | ((tm->tm_mon + 1) << RYxR_MONTH_S) in ryxr_calc()
86 | tm->tm_mday; in ryxr_calc()
91 return ((((tm->tm_mday + 6) / 7) << RDxR_WOM_S) & RDxR_WOM_MASK) in rdxr_calc()
92 | (((tm->tm_wday + 1) << RDxR_DOW_S) & RDxR_DOW_MASK) in rdxr_calc()
93 | (tm->tm_hour << RDxR_HOUR_S) in rdxr_calc()
94 | (tm->tm_min << RDxR_MIN_S) in rdxr_calc()
95 | tm->tm_sec; in rdxr_calc()
100 tm->tm_year = ((rycr & RYxR_YEAR_MASK) >> RYxR_YEAR_S) - 1900; in tm_calc()
101 tm->tm_mon = (((rycr & RYxR_MONTH_MASK) >> RYxR_MONTH_S)) - 1; in tm_calc()
102 tm->tm_mday = (rycr & RYxR_DAY_MASK); in tm_calc()
103 tm->tm_wday = ((rycr & RDxR_DOW_MASK) >> RDxR_DOW_S) - 1; in tm_calc()
104 tm->tm_hour = (rdcr & RDxR_HOUR_MASK) >> RDxR_HOUR_S; in tm_calc()
105 tm->tm_min = (rdcr & RDxR_MIN_MASK) >> RDxR_MIN_S; in tm_calc()
106 tm->tm_sec = rdcr & RDxR_SEC_MASK; in tm_calc()
135 spin_lock(&pxa_rtc->lock); in pxa_rtc_irq()
141 /* temporary disable rtc interrupts */ in pxa_rtc_irq()
156 rtc_update_irq(pxa_rtc->rtc, 1, events); in pxa_rtc_irq()
158 /* enable back rtc interrupts */ in pxa_rtc_irq()
161 spin_unlock(&pxa_rtc->lock); in pxa_rtc_irq()
170 ret = request_irq(pxa_rtc->sa1100_rtc.irq_1hz, pxa_rtc_irq, 0, in pxa_rtc_open()
171 "rtc 1Hz", dev); in pxa_rtc_open()
174 pxa_rtc->sa1100_rtc.irq_1hz, ret); in pxa_rtc_open()
177 ret = request_irq(pxa_rtc->sa1100_rtc.irq_alarm, pxa_rtc_irq, 0, in pxa_rtc_open()
178 "rtc Alrm", dev); in pxa_rtc_open()
181 pxa_rtc->sa1100_rtc.irq_alarm, ret); in pxa_rtc_open()
188 free_irq(pxa_rtc->sa1100_rtc.irq_1hz, dev); in pxa_rtc_open()
197 spin_lock_irq(&pxa_rtc->lock); in pxa_rtc_release()
199 spin_unlock_irq(&pxa_rtc->lock); in pxa_rtc_release()
201 free_irq(pxa_rtc->sa1100_rtc.irq_1hz, dev); in pxa_rtc_release()
202 free_irq(pxa_rtc->sa1100_rtc.irq_alarm, dev); in pxa_rtc_release()
209 spin_lock_irq(&pxa_rtc->lock); in pxa_alarm_irq_enable()
216 spin_unlock_irq(&pxa_rtc->lock); in pxa_alarm_irq_enable()
249 tm_calc(ryar, rdar, &alrm->time); in pxa_rtc_read_alarm()
252 alrm->enabled = (rtsr & RTSR_RDALE1) ? 1 : 0; in pxa_rtc_read_alarm()
253 alrm->pending = (rtsr & RTSR_RDAL1) ? 1 : 0; in pxa_rtc_read_alarm()
262 spin_lock_irq(&pxa_rtc->lock); in pxa_rtc_set_alarm()
264 rtc_writel(pxa_rtc, RYAR1, ryxr_calc(&alrm->time)); in pxa_rtc_set_alarm()
265 rtc_writel(pxa_rtc, RDAR1, rdxr_calc(&alrm->time)); in pxa_rtc_set_alarm()
268 if (alrm->enabled) in pxa_rtc_set_alarm()
274 spin_unlock_irq(&pxa_rtc->lock); in pxa_rtc_set_alarm()
304 struct device *dev = &pdev->dev; in pxa_rtc_probe()
311 return -ENOMEM; in pxa_rtc_probe()
312 sa1100_rtc = &pxa_rtc->sa1100_rtc; in pxa_rtc_probe()
314 spin_lock_init(&pxa_rtc->lock); in pxa_rtc_probe()
317 pxa_rtc->ress = platform_get_resource(pdev, IORESOURCE_MEM, 0); in pxa_rtc_probe()
318 if (!pxa_rtc->ress) { in pxa_rtc_probe()
320 return -ENXIO; in pxa_rtc_probe()
323 sa1100_rtc->irq_1hz = platform_get_irq(pdev, 0); in pxa_rtc_probe()
324 if (sa1100_rtc->irq_1hz < 0) in pxa_rtc_probe()
325 return -ENXIO; in pxa_rtc_probe()
326 sa1100_rtc->irq_alarm = platform_get_irq(pdev, 1); in pxa_rtc_probe()
327 if (sa1100_rtc->irq_alarm < 0) in pxa_rtc_probe()
328 return -ENXIO; in pxa_rtc_probe()
330 sa1100_rtc->rtc = devm_rtc_allocate_device(&pdev->dev); in pxa_rtc_probe()
331 if (IS_ERR(sa1100_rtc->rtc)) in pxa_rtc_probe()
332 return PTR_ERR(sa1100_rtc->rtc); in pxa_rtc_probe()
334 pxa_rtc->base = devm_ioremap(dev, pxa_rtc->ress->start, in pxa_rtc_probe()
335 resource_size(pxa_rtc->ress)); in pxa_rtc_probe()
336 if (!pxa_rtc->base) { in pxa_rtc_probe()
337 dev_err(dev, "Unable to map pxa RTC I/O memory\n"); in pxa_rtc_probe()
338 return -ENOMEM; in pxa_rtc_probe()
343 sa1100_rtc->rcnr = pxa_rtc->base + 0x0; in pxa_rtc_probe()
344 sa1100_rtc->rtsr = pxa_rtc->base + 0x8; in pxa_rtc_probe()
345 sa1100_rtc->rtar = pxa_rtc->base + 0x4; in pxa_rtc_probe()
346 sa1100_rtc->rttr = pxa_rtc->base + 0xc; in pxa_rtc_probe()
349 dev_err(dev, "Unable to init SA1100 RTC sub-device\n"); in pxa_rtc_probe()
355 pxa_rtc->rtc = devm_rtc_device_register(&pdev->dev, "pxa-rtc", in pxa_rtc_probe()
357 if (IS_ERR(pxa_rtc->rtc)) { in pxa_rtc_probe()
358 ret = PTR_ERR(pxa_rtc->rtc); in pxa_rtc_probe()
359 dev_err(dev, "Failed to register RTC device -> %d\n", ret); in pxa_rtc_probe()
370 struct device *dev = &pdev->dev; in pxa_rtc_remove()
377 { .compatible = "marvell,pxa-rtc" },
389 enable_irq_wake(pxa_rtc->sa1100_rtc.irq_alarm); in pxa_rtc_suspend()
398 disable_irq_wake(pxa_rtc->sa1100_rtc.irq_alarm); in pxa_rtc_resume()
414 .name = "pxa-rtc",
423 MODULE_DESCRIPTION("PXA27x/PXA3xx Realtime Clock Driver (RTC)");
425 MODULE_ALIAS("platform:pxa-rtc");