Lines Matching full:rtc
11 #include <linux/rtc.h>
51 struct rtc_device *rtc; member
58 struct lpc32xx_rtc *rtc = dev_get_drvdata(dev); in lpc32xx_rtc_read_time() local
60 elapsed_sec = rtc_readl(rtc, LPC32XX_RTC_UCOUNT); in lpc32xx_rtc_read_time()
68 struct lpc32xx_rtc *rtc = dev_get_drvdata(dev); in lpc32xx_rtc_set_time() local
72 spin_lock_irq(&rtc->lock); in lpc32xx_rtc_set_time()
74 /* RTC must be disabled during count update */ in lpc32xx_rtc_set_time()
75 tmp = rtc_readl(rtc, LPC32XX_RTC_CTRL); in lpc32xx_rtc_set_time()
76 rtc_writel(rtc, LPC32XX_RTC_CTRL, tmp | LPC32XX_RTC_CTRL_CNTR_DIS); in lpc32xx_rtc_set_time()
77 rtc_writel(rtc, LPC32XX_RTC_UCOUNT, secs); in lpc32xx_rtc_set_time()
78 rtc_writel(rtc, LPC32XX_RTC_DCOUNT, 0xFFFFFFFF - secs); in lpc32xx_rtc_set_time()
79 rtc_writel(rtc, LPC32XX_RTC_CTRL, tmp &= ~LPC32XX_RTC_CTRL_CNTR_DIS); in lpc32xx_rtc_set_time()
81 spin_unlock_irq(&rtc->lock); in lpc32xx_rtc_set_time()
89 struct lpc32xx_rtc *rtc = dev_get_drvdata(dev); in lpc32xx_rtc_read_alarm() local
91 rtc_time64_to_tm(rtc_readl(rtc, LPC32XX_RTC_MATCH0), &wkalrm->time); in lpc32xx_rtc_read_alarm()
92 wkalrm->enabled = rtc->alarm_enabled; in lpc32xx_rtc_read_alarm()
93 wkalrm->pending = !!(rtc_readl(rtc, LPC32XX_RTC_INTSTAT) & in lpc32xx_rtc_read_alarm()
102 struct lpc32xx_rtc *rtc = dev_get_drvdata(dev); in lpc32xx_rtc_set_alarm() local
108 spin_lock_irq(&rtc->lock); in lpc32xx_rtc_set_alarm()
111 tmp = rtc_readl(rtc, LPC32XX_RTC_CTRL); in lpc32xx_rtc_set_alarm()
112 rtc_writel(rtc, LPC32XX_RTC_CTRL, tmp & ~LPC32XX_RTC_CTRL_MATCH0); in lpc32xx_rtc_set_alarm()
114 rtc_writel(rtc, LPC32XX_RTC_MATCH0, alarmsecs); in lpc32xx_rtc_set_alarm()
116 rtc->alarm_enabled = wkalrm->enabled; in lpc32xx_rtc_set_alarm()
118 rtc_writel(rtc, LPC32XX_RTC_INTSTAT, in lpc32xx_rtc_set_alarm()
120 rtc_writel(rtc, LPC32XX_RTC_CTRL, tmp | in lpc32xx_rtc_set_alarm()
124 spin_unlock_irq(&rtc->lock); in lpc32xx_rtc_set_alarm()
132 struct lpc32xx_rtc *rtc = dev_get_drvdata(dev); in lpc32xx_rtc_alarm_irq_enable() local
135 spin_lock_irq(&rtc->lock); in lpc32xx_rtc_alarm_irq_enable()
136 tmp = rtc_readl(rtc, LPC32XX_RTC_CTRL); in lpc32xx_rtc_alarm_irq_enable()
139 rtc->alarm_enabled = 1; in lpc32xx_rtc_alarm_irq_enable()
142 rtc->alarm_enabled = 0; in lpc32xx_rtc_alarm_irq_enable()
146 rtc_writel(rtc, LPC32XX_RTC_CTRL, tmp); in lpc32xx_rtc_alarm_irq_enable()
147 spin_unlock_irq(&rtc->lock); in lpc32xx_rtc_alarm_irq_enable()
154 struct lpc32xx_rtc *rtc = dev; in lpc32xx_rtc_alarm_interrupt() local
156 spin_lock(&rtc->lock); in lpc32xx_rtc_alarm_interrupt()
159 rtc_writel(rtc, LPC32XX_RTC_CTRL, in lpc32xx_rtc_alarm_interrupt()
160 rtc_readl(rtc, LPC32XX_RTC_CTRL) & in lpc32xx_rtc_alarm_interrupt()
162 rtc->alarm_enabled = 0; in lpc32xx_rtc_alarm_interrupt()
165 * Write a large value to the match value so the RTC won't in lpc32xx_rtc_alarm_interrupt()
168 rtc_writel(rtc, LPC32XX_RTC_MATCH0, 0xFFFFFFFF); in lpc32xx_rtc_alarm_interrupt()
169 rtc_writel(rtc, LPC32XX_RTC_INTSTAT, LPC32XX_RTC_INTSTAT_MATCH0); in lpc32xx_rtc_alarm_interrupt()
171 spin_unlock(&rtc->lock); in lpc32xx_rtc_alarm_interrupt()
173 rtc_update_irq(rtc->rtc, 1, RTC_IRQF | RTC_AF); in lpc32xx_rtc_alarm_interrupt()
188 struct lpc32xx_rtc *rtc; in lpc32xx_rtc_probe() local
192 rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); in lpc32xx_rtc_probe()
193 if (unlikely(!rtc)) in lpc32xx_rtc_probe()
196 rtc->rtc_base = devm_platform_ioremap_resource(pdev, 0); in lpc32xx_rtc_probe()
197 if (IS_ERR(rtc->rtc_base)) in lpc32xx_rtc_probe()
198 return PTR_ERR(rtc->rtc_base); in lpc32xx_rtc_probe()
200 spin_lock_init(&rtc->lock); in lpc32xx_rtc_probe()
203 * The RTC is on a separate power domain and can keep it's state in lpc32xx_rtc_probe()
204 * across a chip power cycle. If the RTC has never been previously in lpc32xx_rtc_probe()
207 tmp = rtc_readl(rtc, LPC32XX_RTC_CTRL); in lpc32xx_rtc_probe()
208 if (rtc_readl(rtc, LPC32XX_RTC_KEY) != LPC32XX_RTC_KEY_ONSW_LOADVAL) { in lpc32xx_rtc_probe()
216 rtc_writel(rtc, LPC32XX_RTC_CTRL, tmp); in lpc32xx_rtc_probe()
219 rtc_writel(rtc, LPC32XX_RTC_MATCH0, 0xFFFFFFFF); in lpc32xx_rtc_probe()
220 rtc_writel(rtc, LPC32XX_RTC_INTSTAT, in lpc32xx_rtc_probe()
225 /* Write key value to RTC so it won't reload on reset */ in lpc32xx_rtc_probe()
226 rtc_writel(rtc, LPC32XX_RTC_KEY, in lpc32xx_rtc_probe()
229 rtc_writel(rtc, LPC32XX_RTC_CTRL, in lpc32xx_rtc_probe()
233 platform_set_drvdata(pdev, rtc); in lpc32xx_rtc_probe()
235 rtc->rtc = devm_rtc_allocate_device(&pdev->dev); in lpc32xx_rtc_probe()
236 if (IS_ERR(rtc->rtc)) in lpc32xx_rtc_probe()
237 return PTR_ERR(rtc->rtc); in lpc32xx_rtc_probe()
239 rtc->rtc->ops = &lpc32xx_rtc_ops; in lpc32xx_rtc_probe()
240 rtc->rtc->range_max = U32_MAX; in lpc32xx_rtc_probe()
242 err = devm_rtc_register_device(rtc->rtc); in lpc32xx_rtc_probe()
250 rtc->irq = platform_get_irq(pdev, 0); in lpc32xx_rtc_probe()
251 if (rtc->irq < 0) { in lpc32xx_rtc_probe()
254 if (devm_request_irq(&pdev->dev, rtc->irq, in lpc32xx_rtc_probe()
256 0, pdev->name, rtc) < 0) { in lpc32xx_rtc_probe()
258 rtc->irq = -1; in lpc32xx_rtc_probe()
270 struct lpc32xx_rtc *rtc = dev_get_drvdata(dev); in lpc32xx_rtc_suspend() local
272 if (rtc->irq >= 0) { in lpc32xx_rtc_suspend()
274 enable_irq_wake(rtc->irq); in lpc32xx_rtc_suspend()
276 disable_irq_wake(rtc->irq); in lpc32xx_rtc_suspend()
284 struct lpc32xx_rtc *rtc = dev_get_drvdata(dev); in lpc32xx_rtc_resume() local
286 if (rtc->irq >= 0 && device_may_wakeup(dev)) in lpc32xx_rtc_resume()
287 disable_irq_wake(rtc->irq); in lpc32xx_rtc_resume()
295 struct lpc32xx_rtc *rtc = dev_get_drvdata(dev); in lpc32xx_rtc_freeze() local
297 spin_lock_irq(&rtc->lock); in lpc32xx_rtc_freeze()
299 rtc_writel(rtc, LPC32XX_RTC_CTRL, in lpc32xx_rtc_freeze()
300 rtc_readl(rtc, LPC32XX_RTC_CTRL) & in lpc32xx_rtc_freeze()
303 spin_unlock_irq(&rtc->lock); in lpc32xx_rtc_freeze()
310 struct lpc32xx_rtc *rtc = dev_get_drvdata(dev); in lpc32xx_rtc_thaw() local
312 if (rtc->alarm_enabled) { in lpc32xx_rtc_thaw()
313 spin_lock_irq(&rtc->lock); in lpc32xx_rtc_thaw()
315 rtc_writel(rtc, LPC32XX_RTC_CTRL, in lpc32xx_rtc_thaw()
316 rtc_readl(rtc, LPC32XX_RTC_CTRL) | in lpc32xx_rtc_thaw()
319 spin_unlock_irq(&rtc->lock); in lpc32xx_rtc_thaw()
340 { .compatible = "nxp,lpc3220-rtc" },
349 .name = "rtc-lpc32xx",
358 MODULE_DESCRIPTION("RTC driver for the LPC32xx SoC");
360 MODULE_ALIAS("platform:rtc-lpc32xx");