Lines Matching +full:imx21 +full:- +full:clock

1 // SPDX-License-Identifier: GPL-2.0+
3 // Copyright 2004-2008 Freescale Semiconductor, Inc. All Rights Reserved.
73 { .compatible = "fsl,imx1-rtc", .data = (const void *)IMX1_RTC },
74 { .compatible = "fsl,imx21-rtc", .data = (const void *)IMX21_RTC },
81 return data->devtype == IMX1_RTC; in is_imx1_rtc()
91 void __iomem *ioaddr = pdata->ioaddr; in get_alarm_or_time()
120 void __iomem *ioaddr = pdata->ioaddr; in set_alarm_or_time()
126 tod -= hr * 3600; in set_alarm_or_time()
130 sec = tod - min * 60; in set_alarm_or_time()
156 void __iomem *ioaddr = pdata->ioaddr; in rtc_update_alarm()
169 void __iomem *ioaddr = pdata->ioaddr; in mxc_rtc_irq_enable()
173 spin_lock_irqsave(&pdata->rtc->irq_lock, flags); in mxc_rtc_irq_enable()
182 spin_unlock_irqrestore(&pdata->rtc->irq_lock, flags); in mxc_rtc_irq_enable()
190 void __iomem *ioaddr = pdata->ioaddr; in mxc_rtc_interrupt()
194 spin_lock(&pdata->rtc->irq_lock); in mxc_rtc_interrupt()
202 /* RTC alarm should be one-shot */ in mxc_rtc_interrupt()
203 mxc_rtc_irq_enable(&pdev->dev, RTC_ALM_BIT, 0); in mxc_rtc_interrupt()
209 rtc_update_irq(pdata->rtc, 1, events); in mxc_rtc_interrupt()
210 spin_unlock(&pdata->rtc->irq_lock); in mxc_rtc_interrupt()
228 /* Avoid roll-over from reading the different registers */ in mxc_rtc_read_time()
245 /* Avoid roll-over from reading the different registers */ in mxc_rtc_set_time()
261 void __iomem *ioaddr = pdata->ioaddr; in mxc_rtc_read_alarm()
263 rtc_time64_to_tm(get_alarm_or_time(dev, MXC_RTC_ALARM), &alrm->time); in mxc_rtc_read_alarm()
264 alrm->pending = ((readw(ioaddr + RTC_RTCISR) & RTC_ALM_BIT)) ? 1 : 0; in mxc_rtc_read_alarm()
276 rtc_update_alarm(dev, &alrm->time); in mxc_rtc_set_alarm()
278 memcpy(&pdata->g_rtc_alarm, &alrm->time, sizeof(struct rtc_time)); in mxc_rtc_set_alarm()
279 mxc_rtc_irq_enable(dev, RTC_ALM_BIT, alrm->enabled); in mxc_rtc_set_alarm()
301 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); in mxc_rtc_probe()
303 return -ENOMEM; in mxc_rtc_probe()
305 pdata->devtype = (uintptr_t)of_device_get_match_data(&pdev->dev); in mxc_rtc_probe()
307 pdata->ioaddr = devm_platform_ioremap_resource(pdev, 0); in mxc_rtc_probe()
308 if (IS_ERR(pdata->ioaddr)) in mxc_rtc_probe()
309 return PTR_ERR(pdata->ioaddr); in mxc_rtc_probe()
311 rtc = devm_rtc_allocate_device(&pdev->dev); in mxc_rtc_probe()
315 pdata->rtc = rtc; in mxc_rtc_probe()
316 rtc->ops = &mxc_rtc_ops; in mxc_rtc_probe()
321 rtc->range_max = (1 << 9) * 86400 - 1; in mxc_rtc_probe()
328 rtc->start_secs = mktime64(tm.tm_year, 1, 1, 0, 0, 0); in mxc_rtc_probe()
329 rtc->set_start_time = true; in mxc_rtc_probe()
332 rtc->range_max = (1 << 16) * 86400ULL - 1; in mxc_rtc_probe()
335 pdata->clk_ipg = devm_clk_get_enabled(&pdev->dev, "ipg"); in mxc_rtc_probe()
336 if (IS_ERR(pdata->clk_ipg)) { in mxc_rtc_probe()
337 dev_err(&pdev->dev, "unable to get ipg clock!\n"); in mxc_rtc_probe()
338 return PTR_ERR(pdata->clk_ipg); in mxc_rtc_probe()
341 pdata->clk_ref = devm_clk_get_enabled(&pdev->dev, "ref"); in mxc_rtc_probe()
342 if (IS_ERR(pdata->clk_ref)) { in mxc_rtc_probe()
343 dev_err(&pdev->dev, "unable to get ref clock!\n"); in mxc_rtc_probe()
344 return PTR_ERR(pdata->clk_ref); in mxc_rtc_probe()
347 rate = clk_get_rate(pdata->clk_ref); in mxc_rtc_probe()
356 dev_err(&pdev->dev, "rtc clock is not valid (%lu)\n", rate); in mxc_rtc_probe()
357 return -EINVAL; in mxc_rtc_probe()
361 writew(reg, (pdata->ioaddr + RTC_RTCCTL)); in mxc_rtc_probe()
362 if (((readw(pdata->ioaddr + RTC_RTCCTL)) & RTC_ENABLE_BIT) == 0) { in mxc_rtc_probe()
363 dev_err(&pdev->dev, "hardware module can't be enabled!\n"); in mxc_rtc_probe()
364 return -EIO; in mxc_rtc_probe()
370 pdata->irq = platform_get_irq(pdev, 0); in mxc_rtc_probe()
372 if (pdata->irq >= 0 && in mxc_rtc_probe()
373 devm_request_irq(&pdev->dev, pdata->irq, mxc_rtc_interrupt, in mxc_rtc_probe()
374 IRQF_SHARED, pdev->name, pdev) < 0) { in mxc_rtc_probe()
375 dev_warn(&pdev->dev, "interrupt not available.\n"); in mxc_rtc_probe()
376 pdata->irq = -1; in mxc_rtc_probe()
379 if (pdata->irq >= 0) { in mxc_rtc_probe()
380 device_init_wakeup(&pdev->dev, true); in mxc_rtc_probe()
381 ret = dev_pm_set_wake_irq(&pdev->dev, pdata->irq); in mxc_rtc_probe()
383 dev_err(&pdev->dev, "failed to enable irq wake\n"); in mxc_rtc_probe()