Lines Matching +full:interrupt +full:- +full:clk
1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright (c) 2004-2011 Freescale Semiconductor, Inc.
8 #include <linux/clk.h>
26 #define SRTC_LPSR_NVES BIT(14) /* lp non-valid state exit status */
42 struct clk *clk; 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()
80 spin_lock(&pdata->lock); in mxc_rtc_interrupt()
81 if (clk_enable(pdata->clk)) { in mxc_rtc_interrupt()
82 spin_unlock(&pdata->lock); in mxc_rtc_interrupt()
92 rtc_update_irq(pdata->rtc, 1, RTC_AF | RTC_IRQF); in mxc_rtc_interrupt()
98 /* Update interrupt enables */ in mxc_rtc_interrupt()
101 /* clear interrupt status */ in mxc_rtc_interrupt()
105 clk_disable(pdata->clk); in mxc_rtc_interrupt()
106 spin_unlock(&pdata->lock); in mxc_rtc_interrupt()
111 * Enable clk and aquire spinlock
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()
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()
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()
181 * an alarm interrupt occurs or not.
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()
203 * Enable/Disable alarm interrupt
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()
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()
249 /* clear alarm interrupt status bit */ 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()
284 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); in mxc_rtc_probe()
286 return -ENOMEM; in mxc_rtc_probe()
288 pdata->ioaddr = devm_platform_ioremap_resource(pdev, 0); in mxc_rtc_probe()
289 if (IS_ERR(pdata->ioaddr)) in mxc_rtc_probe()
290 return PTR_ERR(pdata->ioaddr); in mxc_rtc_probe()
292 ioaddr = pdata->ioaddr; in mxc_rtc_probe()
294 pdata->clk = devm_clk_get(&pdev->dev, NULL); in mxc_rtc_probe()
295 if (IS_ERR(pdata->clk)) { in mxc_rtc_probe()
296 dev_err(&pdev->dev, "unable to get rtc clock!\n"); in mxc_rtc_probe()
297 return PTR_ERR(pdata->clk); in mxc_rtc_probe()
300 spin_lock_init(&pdata->lock); in mxc_rtc_probe()
301 pdata->irq = platform_get_irq(pdev, 0); in mxc_rtc_probe()
302 if (pdata->irq < 0) in mxc_rtc_probe()
303 return pdata->irq; in mxc_rtc_probe()
305 device_init_wakeup(&pdev->dev, 1); in mxc_rtc_probe()
306 ret = dev_pm_set_wake_irq(&pdev->dev, pdata->irq); in mxc_rtc_probe()
308 dev_err(&pdev->dev, "failed to enable irq wake\n"); in mxc_rtc_probe()
310 ret = clk_prepare_enable(pdata->clk); in mxc_rtc_probe()
316 /* clear lp interrupt status */ in mxc_rtc_probe()
323 dev_err(&pdev->dev, "Timeout waiting for SRTC_LPSR_IES\n"); in mxc_rtc_probe()
324 clk_disable_unprepare(pdata->clk); in mxc_rtc_probe()
328 /* move out of non-valid state */ in mxc_rtc_probe()
333 dev_err(&pdev->dev, "Timeout waiting for SRTC_LPSR_NVES\n"); in mxc_rtc_probe()
334 clk_disable_unprepare(pdata->clk); in mxc_rtc_probe()
338 pdata->rtc = devm_rtc_allocate_device(&pdev->dev); in mxc_rtc_probe()
339 if (IS_ERR(pdata->rtc)) { in mxc_rtc_probe()
340 clk_disable_unprepare(pdata->clk); in mxc_rtc_probe()
341 return PTR_ERR(pdata->rtc); in mxc_rtc_probe()
344 pdata->rtc->ops = &mxc_rtc_ops; in mxc_rtc_probe()
345 pdata->rtc->range_max = U32_MAX; in mxc_rtc_probe()
347 clk_disable(pdata->clk); in mxc_rtc_probe()
350 devm_request_irq(&pdev->dev, pdata->irq, mxc_rtc_interrupt, 0, in mxc_rtc_probe()
351 pdev->name, &pdev->dev); in mxc_rtc_probe()
353 dev_err(&pdev->dev, "interrupt not available.\n"); in mxc_rtc_probe()
354 clk_unprepare(pdata->clk); in mxc_rtc_probe()
358 ret = devm_rtc_register_device(pdata->rtc); in mxc_rtc_probe()
360 clk_unprepare(pdata->clk); in mxc_rtc_probe()
369 clk_disable_unprepare(pdata->clk); in mxc_rtc_remove()
373 { .compatible = "fsl,imx53-rtc", },