Lines Matching +full:imx53 +full:- +full:rtc
1 // SPDX-License-Identifier: GPL-2.0
3 * Real Time Clock (RTC) Driver for i.MX53
4 * Copyright (c) 2004-2011 Freescale Semiconductor, Inc.
14 #include <linux/rtc.h>
26 #define SRTC_LPSR_NVES BIT(14) /* lp non-valid state exit status */
40 struct rtc_device *rtc; member
51 * The caller should hold the pdata->lock
63 if (!--timeout) { in mxc_rtc_sync_lp_locked()
71 /* This function is the RTC interrupt service routine. */
76 void __iomem *ioaddr = pdata->ioaddr; in mxc_rtc_interrupt()
81 spin_lock_irqsave(&pdata->lock, flags); in mxc_rtc_interrupt()
82 if (clk_enable(pdata->clk)) { in mxc_rtc_interrupt()
83 spin_unlock_irqrestore(&pdata->lock, flags); in mxc_rtc_interrupt()
93 rtc_update_irq(pdata->rtc, 1, RTC_AF | RTC_IRQF); in mxc_rtc_interrupt()
106 clk_disable(pdata->clk); in mxc_rtc_interrupt()
107 spin_unlock_irqrestore(&pdata->lock, flags); in mxc_rtc_interrupt()
113 * @return 0 if successful; non-zero otherwise.
119 spin_lock_irq(&pdata->lock); in mxc_rtc_lock()
120 ret = clk_enable(pdata->clk); in mxc_rtc_lock()
122 spin_unlock_irq(&pdata->lock); in mxc_rtc_lock()
130 clk_disable(pdata->clk); in mxc_rtc_unlock()
131 spin_unlock_irq(&pdata->lock); in mxc_rtc_unlock()
136 * This function reads the current RTC time into tm in Gregorian date.
138 * @param tm contains the RTC time value upon return
140 * @return 0 if successful; non-zero otherwise.
145 const int clk_failed = clk_enable(pdata->clk); in mxc_rtc_read_time()
148 const time64_t now = readl(pdata->ioaddr + SRTC_LPSCMR); in mxc_rtc_read_time()
151 clk_disable(pdata->clk); in mxc_rtc_read_time()
158 * This function sets the internal RTC time based on tm in Gregorian date.
160 * @param tm the time value to be set in the RTC
162 * @return 0 if successful; non-zero otherwise.
174 writel(time, pdata->ioaddr + SRTC_LPSCMR); in mxc_rtc_set_time()
175 mxc_rtc_sync_lp_locked(dev, pdata->ioaddr); in mxc_rtc_set_time()
184 * @param alrm contains the RTC alarm value upon return
186 * @return 0 if successful; non-zero otherwise.
191 void __iomem *ioaddr = pdata->ioaddr; in mxc_rtc_read_alarm()
198 rtc_time64_to_tm(readl(ioaddr + SRTC_LPSAR), &alrm->time); in mxc_rtc_read_alarm()
199 alrm->pending = !!(readl(ioaddr + SRTC_LPSR) & SRTC_LPSR_ALP); in mxc_rtc_read_alarm()
205 * The caller should hold the pdata->lock
210 u32 lp_cr = readl(pdata->ioaddr + SRTC_LPCR); in mxc_rtc_alarm_irq_enable_locked()
217 writel(lp_cr, pdata->ioaddr + SRTC_LPCR); in mxc_rtc_alarm_irq_enable_locked()
233 * This function sets the RTC alarm based on passed in alrm.
235 * @param alrm the alarm value to be set in the RTC
237 * @return 0 if successful; non-zero otherwise.
241 const time64_t time = rtc_tm_to_time64(&alrm->time); in mxc_rtc_set_alarm()
248 writel((u32)time, pdata->ioaddr + SRTC_LPSAR); in mxc_rtc_set_alarm()
251 writel(SRTC_LPSR_ALP, pdata->ioaddr + SRTC_LPSR); in mxc_rtc_set_alarm()
252 mxc_rtc_sync_lp_locked(dev, pdata->ioaddr); in mxc_rtc_set_alarm()
254 mxc_rtc_alarm_irq_enable_locked(pdata, alrm->enabled); in mxc_rtc_set_alarm()
255 mxc_rtc_sync_lp_locked(dev, pdata->ioaddr); in mxc_rtc_set_alarm()
273 if (!--timeout) in mxc_rtc_wait_for_flag()
274 return -EBUSY; in mxc_rtc_wait_for_flag()
285 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); in mxc_rtc_probe()
287 return -ENOMEM; in mxc_rtc_probe()
289 pdata->ioaddr = devm_platform_ioremap_resource(pdev, 0); in mxc_rtc_probe()
290 if (IS_ERR(pdata->ioaddr)) in mxc_rtc_probe()
291 return PTR_ERR(pdata->ioaddr); in mxc_rtc_probe()
293 ioaddr = pdata->ioaddr; in mxc_rtc_probe()
295 pdata->clk = devm_clk_get(&pdev->dev, NULL); in mxc_rtc_probe()
296 if (IS_ERR(pdata->clk)) { in mxc_rtc_probe()
297 dev_err(&pdev->dev, "unable to get rtc clock!\n"); in mxc_rtc_probe()
298 return PTR_ERR(pdata->clk); in mxc_rtc_probe()
301 spin_lock_init(&pdata->lock); in mxc_rtc_probe()
302 pdata->irq = platform_get_irq(pdev, 0); in mxc_rtc_probe()
303 if (pdata->irq < 0) in mxc_rtc_probe()
304 return pdata->irq; in mxc_rtc_probe()
306 device_init_wakeup(&pdev->dev, 1); in mxc_rtc_probe()
307 ret = dev_pm_set_wake_irq(&pdev->dev, pdata->irq); in mxc_rtc_probe()
309 dev_err(&pdev->dev, "failed to enable irq wake\n"); in mxc_rtc_probe()
311 ret = clk_prepare_enable(pdata->clk); in mxc_rtc_probe()
324 dev_err(&pdev->dev, "Timeout waiting for SRTC_LPSR_IES\n"); in mxc_rtc_probe()
325 clk_disable_unprepare(pdata->clk); in mxc_rtc_probe()
329 /* move out of non-valid state */ in mxc_rtc_probe()
334 dev_err(&pdev->dev, "Timeout waiting for SRTC_LPSR_NVES\n"); in mxc_rtc_probe()
335 clk_disable_unprepare(pdata->clk); in mxc_rtc_probe()
339 pdata->rtc = devm_rtc_allocate_device(&pdev->dev); in mxc_rtc_probe()
340 if (IS_ERR(pdata->rtc)) in mxc_rtc_probe()
341 return PTR_ERR(pdata->rtc); in mxc_rtc_probe()
343 pdata->rtc->ops = &mxc_rtc_ops; in mxc_rtc_probe()
344 pdata->rtc->range_max = U32_MAX; in mxc_rtc_probe()
346 clk_disable(pdata->clk); in mxc_rtc_probe()
349 devm_request_irq(&pdev->dev, pdata->irq, mxc_rtc_interrupt, 0, in mxc_rtc_probe()
350 pdev->name, &pdev->dev); in mxc_rtc_probe()
352 dev_err(&pdev->dev, "interrupt not available.\n"); in mxc_rtc_probe()
353 clk_unprepare(pdata->clk); in mxc_rtc_probe()
357 ret = rtc_register_device(pdata->rtc); in mxc_rtc_probe()
359 clk_unprepare(pdata->clk); in mxc_rtc_probe()
368 clk_disable_unprepare(pdata->clk); in mxc_rtc_remove()
373 { .compatible = "fsl,imx53-rtc", },
389 MODULE_DESCRIPTION("Real Time Clock (RTC) Driver for i.MX53");