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>
44 #define RTC_HOURMIN 0x00 /* 32bit rtc hour/min counter reg */
45 #define RTC_SECOND 0x04 /* 32bit rtc seconds counter reg */
46 #define RTC_ALRM_HM 0x08 /* 32bit rtc alarm hour/min reg */
47 #define RTC_ALRM_SEC 0x0C /* 32bit rtc alarm seconds reg */
48 #define RTC_RTCCTL 0x10 /* 32bit rtc control reg */
49 #define RTC_RTCISR 0x14 /* 32bit rtc interrupt status reg */
50 #define RTC_RTCIENR 0x18 /* 32bit rtc interrupt enable reg */
51 #define RTC_STPWCH 0x1C /* 32bit rtc stopwatch min reg */
52 #define RTC_DAYR 0x20 /* 32bit rtc days counter reg */
53 #define RTC_DAYALARM 0x24 /* 32bit rtc day alarm reg */
54 #define RTC_TEST1 0x28 /* 32bit rtc test reg 1 */
55 #define RTC_TEST2 0x2C /* 32bit rtc test reg 2 */
56 #define RTC_TEST3 0x30 /* 32bit rtc test reg 3 */
64 struct rtc_device *rtc; member
74 { .compatible = "fsl,imx1-rtc", .data = (const void *)IMX1_RTC },
75 { .compatible = "fsl,imx21-rtc", .data = (const void *)IMX21_RTC },
82 return data->devtype == IMX1_RTC; in is_imx1_rtc()
86 * This function is used to obtain the RTC time or the alarm value in
92 void __iomem *ioaddr = pdata->ioaddr; in get_alarm_or_time()
115 * This function sets the RTC alarm value or the time value.
121 void __iomem *ioaddr = pdata->ioaddr; in set_alarm_or_time()
127 tod -= hr * 3600; in set_alarm_or_time()
131 sec = tod - min * 60; in set_alarm_or_time()
150 * This function updates the RTC alarm registers and then clears all the
157 void __iomem *ioaddr = pdata->ioaddr; in rtc_update_alarm()
170 void __iomem *ioaddr = pdata->ioaddr; in mxc_rtc_irq_enable()
174 spin_lock_irqsave(&pdata->rtc->irq_lock, flags); in mxc_rtc_irq_enable()
183 spin_unlock_irqrestore(&pdata->rtc->irq_lock, flags); in mxc_rtc_irq_enable()
186 /* This function is the RTC interrupt service routine. */
191 void __iomem *ioaddr = pdata->ioaddr; in mxc_rtc_interrupt()
195 spin_lock(&pdata->rtc->irq_lock); in mxc_rtc_interrupt()
203 /* RTC alarm should be one-shot */ in mxc_rtc_interrupt()
204 mxc_rtc_irq_enable(&pdev->dev, RTC_ALM_BIT, 0); in mxc_rtc_interrupt()
210 rtc_update_irq(pdata->rtc, 1, events); in mxc_rtc_interrupt()
211 spin_unlock(&pdata->rtc->irq_lock); in mxc_rtc_interrupt()
223 * This function reads the current RTC time into tm in Gregorian date.
229 /* Avoid roll-over from reading the different registers */ in mxc_rtc_read_time()
240 * This function sets the internal RTC time based on tm in Gregorian date.
246 /* Avoid roll-over from reading the different registers */ in mxc_rtc_set_time()
262 void __iomem *ioaddr = pdata->ioaddr; in mxc_rtc_read_alarm()
264 rtc_time64_to_tm(get_alarm_or_time(dev, MXC_RTC_ALARM), &alrm->time); in mxc_rtc_read_alarm()
265 alrm->pending = ((readw(ioaddr + RTC_RTCISR) & RTC_ALM_BIT)) ? 1 : 0; in mxc_rtc_read_alarm()
271 * This function sets the RTC alarm based on passed in alrm.
277 rtc_update_alarm(dev, &alrm->time); in mxc_rtc_set_alarm()
279 memcpy(&pdata->g_rtc_alarm, &alrm->time, sizeof(struct rtc_time)); in mxc_rtc_set_alarm()
280 mxc_rtc_irq_enable(dev, RTC_ALM_BIT, alrm->enabled); in mxc_rtc_set_alarm()
285 /* RTC layer */
298 clk_disable_unprepare(pdata->clk_ref); in mxc_rtc_action()
299 clk_disable_unprepare(pdata->clk_ipg); in mxc_rtc_action()
304 struct rtc_device *rtc; in mxc_rtc_probe() local
310 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); in mxc_rtc_probe()
312 return -ENOMEM; in mxc_rtc_probe()
314 pdata->devtype = (enum imx_rtc_type)of_device_get_match_data(&pdev->dev); in mxc_rtc_probe()
316 pdata->ioaddr = devm_platform_ioremap_resource(pdev, 0); in mxc_rtc_probe()
317 if (IS_ERR(pdata->ioaddr)) in mxc_rtc_probe()
318 return PTR_ERR(pdata->ioaddr); in mxc_rtc_probe()
320 rtc = devm_rtc_allocate_device(&pdev->dev); in mxc_rtc_probe()
321 if (IS_ERR(rtc)) in mxc_rtc_probe()
322 return PTR_ERR(rtc); in mxc_rtc_probe()
324 pdata->rtc = rtc; in mxc_rtc_probe()
325 rtc->ops = &mxc_rtc_ops; in mxc_rtc_probe()
330 rtc->range_max = (1 << 9) * 86400 - 1; in mxc_rtc_probe()
337 rtc->start_secs = mktime64(tm.tm_year, 1, 1, 0, 0, 0); in mxc_rtc_probe()
338 rtc->set_start_time = true; in mxc_rtc_probe()
341 rtc->range_max = (1 << 16) * 86400ULL - 1; in mxc_rtc_probe()
344 pdata->clk_ipg = devm_clk_get(&pdev->dev, "ipg"); in mxc_rtc_probe()
345 if (IS_ERR(pdata->clk_ipg)) { in mxc_rtc_probe()
346 dev_err(&pdev->dev, "unable to get ipg clock!\n"); in mxc_rtc_probe()
347 return PTR_ERR(pdata->clk_ipg); in mxc_rtc_probe()
350 ret = clk_prepare_enable(pdata->clk_ipg); in mxc_rtc_probe()
354 pdata->clk_ref = devm_clk_get(&pdev->dev, "ref"); in mxc_rtc_probe()
355 if (IS_ERR(pdata->clk_ref)) { in mxc_rtc_probe()
356 clk_disable_unprepare(pdata->clk_ipg); in mxc_rtc_probe()
357 dev_err(&pdev->dev, "unable to get ref clock!\n"); in mxc_rtc_probe()
358 return PTR_ERR(pdata->clk_ref); in mxc_rtc_probe()
361 ret = clk_prepare_enable(pdata->clk_ref); in mxc_rtc_probe()
363 clk_disable_unprepare(pdata->clk_ipg); in mxc_rtc_probe()
367 ret = devm_add_action_or_reset(&pdev->dev, mxc_rtc_action, pdata); in mxc_rtc_probe()
371 rate = clk_get_rate(pdata->clk_ref); in mxc_rtc_probe()
380 dev_err(&pdev->dev, "rtc clock is not valid (%lu)\n", rate); in mxc_rtc_probe()
381 return -EINVAL; in mxc_rtc_probe()
385 writew(reg, (pdata->ioaddr + RTC_RTCCTL)); in mxc_rtc_probe()
386 if (((readw(pdata->ioaddr + RTC_RTCCTL)) & RTC_ENABLE_BIT) == 0) { in mxc_rtc_probe()
387 dev_err(&pdev->dev, "hardware module can't be enabled!\n"); in mxc_rtc_probe()
388 return -EIO; in mxc_rtc_probe()
393 /* Configure and enable the RTC */ in mxc_rtc_probe()
394 pdata->irq = platform_get_irq(pdev, 0); in mxc_rtc_probe()
396 if (pdata->irq >= 0 && in mxc_rtc_probe()
397 devm_request_irq(&pdev->dev, pdata->irq, mxc_rtc_interrupt, in mxc_rtc_probe()
398 IRQF_SHARED, pdev->name, pdev) < 0) { in mxc_rtc_probe()
399 dev_warn(&pdev->dev, "interrupt not available.\n"); in mxc_rtc_probe()
400 pdata->irq = -1; in mxc_rtc_probe()
403 if (pdata->irq >= 0) { in mxc_rtc_probe()
404 device_init_wakeup(&pdev->dev, 1); in mxc_rtc_probe()
405 ret = dev_pm_set_wake_irq(&pdev->dev, pdata->irq); in mxc_rtc_probe()
407 dev_err(&pdev->dev, "failed to enable irq wake\n"); in mxc_rtc_probe()
410 ret = devm_rtc_register_device(rtc); in mxc_rtc_probe()
426 MODULE_DESCRIPTION("RTC driver for Freescale MXC");