• Home
  • Raw
  • Download

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.
13 #include <linux/rtc.h>
25 #define SRTC_LPSR_NVES BIT(14) /* lp non-valid state exit status */
39 struct rtc_device *rtc; member
50 * The caller should hold the pdata->lock
62 if (!--timeout) { in mxc_rtc_sync_lp_locked()
70 /* This function is the RTC interrupt service routine. */
75 void __iomem *ioaddr = pdata->ioaddr; in mxc_rtc_interrupt()
80 spin_lock_irqsave(&pdata->lock, flags); in mxc_rtc_interrupt()
81 if (clk_enable(pdata->clk)) { in mxc_rtc_interrupt()
82 spin_unlock_irqrestore(&pdata->lock, flags); in mxc_rtc_interrupt()
92 rtc_update_irq(pdata->rtc, 1, RTC_AF | RTC_IRQF); in mxc_rtc_interrupt()
105 clk_disable(pdata->clk); in mxc_rtc_interrupt()
106 spin_unlock_irqrestore(&pdata->lock, flags); in mxc_rtc_interrupt()
112 * @return 0 if successful; non-zero otherwise.
118 spin_lock_irq(&pdata->lock); in mxc_rtc_lock()
119 ret = clk_enable(pdata->clk); in mxc_rtc_lock()
121 spin_unlock_irq(&pdata->lock); in mxc_rtc_lock()
129 clk_disable(pdata->clk); in mxc_rtc_unlock()
130 spin_unlock_irq(&pdata->lock); in mxc_rtc_unlock()
135 * This function reads the current RTC time into tm in Gregorian date.
137 * @param tm contains the RTC time value upon return
139 * @return 0 if successful; non-zero otherwise.
144 const int clk_failed = clk_enable(pdata->clk); in mxc_rtc_read_time()
147 const time64_t now = readl(pdata->ioaddr + SRTC_LPSCMR); in mxc_rtc_read_time()
150 clk_disable(pdata->clk); in mxc_rtc_read_time()
157 * This function sets the internal RTC time based on tm in Gregorian date.
159 * @param tm the time value to be set in the RTC
161 * @return 0 if successful; non-zero otherwise.
173 writel(time, pdata->ioaddr + SRTC_LPSCMR); in mxc_rtc_set_time()
174 mxc_rtc_sync_lp_locked(dev, pdata->ioaddr); in mxc_rtc_set_time()
183 * @param alrm contains the RTC alarm value upon return
185 * @return 0 if successful; non-zero otherwise.
190 void __iomem *ioaddr = pdata->ioaddr; in mxc_rtc_read_alarm()
197 rtc_time64_to_tm(readl(ioaddr + SRTC_LPSAR), &alrm->time); in mxc_rtc_read_alarm()
198 alrm->pending = !!(readl(ioaddr + SRTC_LPSR) & SRTC_LPSR_ALP); in mxc_rtc_read_alarm()
204 * The caller should hold the pdata->lock
209 u32 lp_cr = readl(pdata->ioaddr + SRTC_LPCR); in mxc_rtc_alarm_irq_enable_locked()
216 writel(lp_cr, pdata->ioaddr + SRTC_LPCR); in mxc_rtc_alarm_irq_enable_locked()
232 * This function sets the RTC alarm based on passed in alrm.
234 * @param alrm the alarm value to be set in the RTC
236 * @return 0 if successful; non-zero otherwise.
240 const time64_t time = rtc_tm_to_time64(&alrm->time); in mxc_rtc_set_alarm()
247 writel((u32)time, pdata->ioaddr + SRTC_LPSAR); in mxc_rtc_set_alarm()
250 writel(SRTC_LPSR_ALP, pdata->ioaddr + SRTC_LPSR); in mxc_rtc_set_alarm()
251 mxc_rtc_sync_lp_locked(dev, pdata->ioaddr); in mxc_rtc_set_alarm()
253 mxc_rtc_alarm_irq_enable_locked(pdata, alrm->enabled); in mxc_rtc_set_alarm()
254 mxc_rtc_sync_lp_locked(dev, pdata->ioaddr); in mxc_rtc_set_alarm()
272 if (!--timeout) in mxc_rtc_wait_for_flag()
273 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()
290 pdata->ioaddr = devm_ioremap_resource(&pdev->dev, res); in mxc_rtc_probe()
291 if (IS_ERR(pdata->ioaddr)) in mxc_rtc_probe()
292 return PTR_ERR(pdata->ioaddr); in mxc_rtc_probe()
294 ioaddr = pdata->ioaddr; in mxc_rtc_probe()
296 pdata->clk = devm_clk_get(&pdev->dev, NULL); in mxc_rtc_probe()
297 if (IS_ERR(pdata->clk)) { in mxc_rtc_probe()
298 dev_err(&pdev->dev, "unable to get rtc clock!\n"); in mxc_rtc_probe()
299 return PTR_ERR(pdata->clk); in mxc_rtc_probe()
302 spin_lock_init(&pdata->lock); in mxc_rtc_probe()
303 pdata->irq = platform_get_irq(pdev, 0); in mxc_rtc_probe()
304 if (pdata->irq < 0) in mxc_rtc_probe()
305 return pdata->irq; in mxc_rtc_probe()
307 device_init_wakeup(&pdev->dev, 1); in mxc_rtc_probe()
309 ret = clk_prepare_enable(pdata->clk); in mxc_rtc_probe()
322 dev_err(&pdev->dev, "Timeout waiting for SRTC_LPSR_IES\n"); in mxc_rtc_probe()
323 clk_disable_unprepare(pdata->clk); in mxc_rtc_probe()
327 /* move out of non-valid state */ in mxc_rtc_probe()
332 dev_err(&pdev->dev, "Timeout waiting for SRTC_LPSR_NVES\n"); in mxc_rtc_probe()
333 clk_disable_unprepare(pdata->clk); in mxc_rtc_probe()
337 pdata->rtc = devm_rtc_allocate_device(&pdev->dev); in mxc_rtc_probe()
338 if (IS_ERR(pdata->rtc)) in mxc_rtc_probe()
339 return PTR_ERR(pdata->rtc); in mxc_rtc_probe()
341 pdata->rtc->ops = &mxc_rtc_ops; in mxc_rtc_probe()
342 pdata->rtc->range_max = U32_MAX; in mxc_rtc_probe()
344 clk_disable(pdata->clk); in mxc_rtc_probe()
347 devm_request_irq(&pdev->dev, pdata->irq, mxc_rtc_interrupt, 0, in mxc_rtc_probe()
348 pdev->name, &pdev->dev); in mxc_rtc_probe()
350 dev_err(&pdev->dev, "interrupt not available.\n"); in mxc_rtc_probe()
351 clk_unprepare(pdata->clk); in mxc_rtc_probe()
355 ret = rtc_register_device(pdata->rtc); in mxc_rtc_probe()
357 clk_unprepare(pdata->clk); in mxc_rtc_probe()
366 clk_disable_unprepare(pdata->clk); in mxc_rtc_remove()
376 enable_irq_wake(pdata->irq); in mxc_rtc_suspend()
386 disable_irq_wake(pdata->irq); in mxc_rtc_resume()
395 { .compatible = "fsl,imx53-rtc", },
412 MODULE_DESCRIPTION("Real Time Clock (RTC) Driver for i.MX53");