Lines Matching +full:imx21 +full:- +full:rtc

1 // SPDX-License-Identifier: GPL-2.0+
3 // Copyright 2004-2008 Freescale Semiconductor, Inc. All Rights Reserved.
6 #include <linux/rtc.h>
43 #define RTC_HOURMIN 0x00 /* 32bit rtc hour/min counter reg */
44 #define RTC_SECOND 0x04 /* 32bit rtc seconds counter reg */
45 #define RTC_ALRM_HM 0x08 /* 32bit rtc alarm hour/min reg */
46 #define RTC_ALRM_SEC 0x0C /* 32bit rtc alarm seconds reg */
47 #define RTC_RTCCTL 0x10 /* 32bit rtc control reg */
48 #define RTC_RTCISR 0x14 /* 32bit rtc interrupt status reg */
49 #define RTC_RTCIENR 0x18 /* 32bit rtc interrupt enable reg */
50 #define RTC_STPWCH 0x1C /* 32bit rtc stopwatch min reg */
51 #define RTC_DAYR 0x20 /* 32bit rtc days counter reg */
52 #define RTC_DAYALARM 0x24 /* 32bit rtc day alarm reg */
53 #define RTC_TEST1 0x28 /* 32bit rtc test reg 1 */
54 #define RTC_TEST2 0x2C /* 32bit rtc test reg 2 */
55 #define RTC_TEST3 0x30 /* 32bit rtc test reg 3 */
63 struct rtc_device *rtc; member
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()
85 * This function is used to obtain the RTC time or the alarm value in
91 void __iomem *ioaddr = pdata->ioaddr; in get_alarm_or_time()
114 * This function sets the RTC alarm value or the time value.
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()
149 * This function updates the RTC alarm registers and then clears all the
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()
185 /* This function is the RTC interrupt service routine. */
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()
222 * This function reads the current RTC time into tm in Gregorian date.
228 /* Avoid roll-over from reading the different registers */ in mxc_rtc_read_time()
239 * This function sets the internal RTC time based on tm in Gregorian date.
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()
270 * This function sets the RTC alarm based on passed in alrm.
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()
284 /* RTC layer */
295 struct rtc_device *rtc; in mxc_rtc_probe() local
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()
312 if (IS_ERR(rtc)) in mxc_rtc_probe()
313 return PTR_ERR(rtc); 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()
369 /* Configure and enable the RTC */ 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()
386 ret = devm_rtc_register_device(rtc); in mxc_rtc_probe()
402 MODULE_DESCRIPTION("RTC driver for Freescale MXC");