Lines Matching +full:non +full:- +full:secure

1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright (c) 2004-2011 Freescale Semiconductor, Inc.
21 #define SRTC_LPCR_NSA BIT(11) /* lp non secure access */
22 #define SRTC_LPCR_NVE BIT(14) /* lp non valid state exit bit */
26 #define SRTC_LPSR_NVES BIT(14) /* lp non-valid state exit status */
29 #define SRTC_LPSCMR 0x00 /* LP Secure Counter MSB Reg */
30 #define SRTC_LPSCLR 0x04 /* LP Secure Counter LSB Reg */
31 #define SRTC_LPSAR 0x08 /* LP Secure Alarm Reg */
51 * The caller should hold the pdata->lock
63 if (!--timeout) { in mxc_rtc_sync_lp_locked()
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()
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()
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()
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()
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", },