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
75 .name = "imx1-rtc",
78 .name = "imx21-rtc",
88 { .compatible = "fsl,imx1-rtc", .data = (const void *)IMX1_RTC },
89 { .compatible = "fsl,imx21-rtc", .data = (const void *)IMX21_RTC },
97 return data->devtype == IMX1_RTC; in is_imx1_rtc()
101 * This function is used to obtain the RTC time or the alarm value in
107 void __iomem *ioaddr = pdata->ioaddr; in get_alarm_or_time()
130 * This function sets the RTC alarm value or the time value.
136 void __iomem *ioaddr = pdata->ioaddr; in set_alarm_or_time()
142 tod -= hr * 3600; in set_alarm_or_time()
146 sec = tod - min * 60; in set_alarm_or_time()
165 * This function updates the RTC alarm registers and then clears all the
172 void __iomem *ioaddr = pdata->ioaddr; in rtc_update_alarm()
185 void __iomem *ioaddr = pdata->ioaddr; in mxc_rtc_irq_enable()
189 spin_lock_irqsave(&pdata->rtc->irq_lock, flags); in mxc_rtc_irq_enable()
198 spin_unlock_irqrestore(&pdata->rtc->irq_lock, flags); in mxc_rtc_irq_enable()
201 /* This function is the RTC interrupt service routine. */
206 void __iomem *ioaddr = pdata->ioaddr; in mxc_rtc_interrupt()
211 spin_lock_irqsave(&pdata->rtc->irq_lock, flags); in mxc_rtc_interrupt()
219 /* RTC alarm should be one-shot */ in mxc_rtc_interrupt()
220 mxc_rtc_irq_enable(&pdev->dev, RTC_ALM_BIT, 0); in mxc_rtc_interrupt()
226 rtc_update_irq(pdata->rtc, 1, events); in mxc_rtc_interrupt()
227 spin_unlock_irqrestore(&pdata->rtc->irq_lock, flags); in mxc_rtc_interrupt()
239 * This function reads the current RTC time into tm in Gregorian date.
245 /* Avoid roll-over from reading the different registers */ in mxc_rtc_read_time()
256 * This function sets the internal RTC time based on tm in Gregorian date.
262 /* Avoid roll-over from reading the different registers */ in mxc_rtc_set_time()
278 void __iomem *ioaddr = pdata->ioaddr; in mxc_rtc_read_alarm()
280 rtc_time64_to_tm(get_alarm_or_time(dev, MXC_RTC_ALARM), &alrm->time); in mxc_rtc_read_alarm()
281 alrm->pending = ((readw(ioaddr + RTC_RTCISR) & RTC_ALM_BIT)) ? 1 : 0; in mxc_rtc_read_alarm()
287 * This function sets the RTC alarm based on passed in alrm.
293 rtc_update_alarm(dev, &alrm->time); in mxc_rtc_set_alarm()
295 memcpy(&pdata->g_rtc_alarm, &alrm->time, sizeof(struct rtc_time)); in mxc_rtc_set_alarm()
296 mxc_rtc_irq_enable(dev, RTC_ALM_BIT, alrm->enabled); in mxc_rtc_set_alarm()
301 /* RTC layer */
314 clk_disable_unprepare(pdata->clk_ref); in mxc_rtc_action()
315 clk_disable_unprepare(pdata->clk_ipg); in mxc_rtc_action()
320 struct rtc_device *rtc; in mxc_rtc_probe() local
327 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); in mxc_rtc_probe()
329 return -ENOMEM; in mxc_rtc_probe()
331 of_id = of_match_device(imx_rtc_dt_ids, &pdev->dev); in mxc_rtc_probe()
333 pdata->devtype = (enum imx_rtc_type)of_id->data; in mxc_rtc_probe()
335 pdata->devtype = pdev->id_entry->driver_data; in mxc_rtc_probe()
337 pdata->ioaddr = devm_platform_ioremap_resource(pdev, 0); in mxc_rtc_probe()
338 if (IS_ERR(pdata->ioaddr)) in mxc_rtc_probe()
339 return PTR_ERR(pdata->ioaddr); in mxc_rtc_probe()
341 rtc = devm_rtc_allocate_device(&pdev->dev); in mxc_rtc_probe()
342 if (IS_ERR(rtc)) in mxc_rtc_probe()
343 return PTR_ERR(rtc); in mxc_rtc_probe()
345 pdata->rtc = rtc; in mxc_rtc_probe()
346 rtc->ops = &mxc_rtc_ops; in mxc_rtc_probe()
351 rtc->range_max = (1 << 9) * 86400 - 1; in mxc_rtc_probe()
358 rtc->start_secs = mktime64(tm.tm_year, 1, 1, 0, 0, 0); in mxc_rtc_probe()
359 rtc->set_start_time = true; in mxc_rtc_probe()
362 rtc->range_max = (1 << 16) * 86400ULL - 1; in mxc_rtc_probe()
365 pdata->clk_ipg = devm_clk_get(&pdev->dev, "ipg"); in mxc_rtc_probe()
366 if (IS_ERR(pdata->clk_ipg)) { in mxc_rtc_probe()
367 dev_err(&pdev->dev, "unable to get ipg clock!\n"); in mxc_rtc_probe()
368 return PTR_ERR(pdata->clk_ipg); in mxc_rtc_probe()
371 ret = clk_prepare_enable(pdata->clk_ipg); in mxc_rtc_probe()
375 pdata->clk_ref = devm_clk_get(&pdev->dev, "ref"); in mxc_rtc_probe()
376 if (IS_ERR(pdata->clk_ref)) { in mxc_rtc_probe()
377 clk_disable_unprepare(pdata->clk_ipg); in mxc_rtc_probe()
378 dev_err(&pdev->dev, "unable to get ref clock!\n"); in mxc_rtc_probe()
379 return PTR_ERR(pdata->clk_ref); in mxc_rtc_probe()
382 ret = clk_prepare_enable(pdata->clk_ref); in mxc_rtc_probe()
384 clk_disable_unprepare(pdata->clk_ipg); in mxc_rtc_probe()
388 ret = devm_add_action_or_reset(&pdev->dev, mxc_rtc_action, pdata); in mxc_rtc_probe()
392 rate = clk_get_rate(pdata->clk_ref); in mxc_rtc_probe()
401 dev_err(&pdev->dev, "rtc clock is not valid (%lu)\n", rate); in mxc_rtc_probe()
402 return -EINVAL; in mxc_rtc_probe()
406 writew(reg, (pdata->ioaddr + RTC_RTCCTL)); in mxc_rtc_probe()
407 if (((readw(pdata->ioaddr + RTC_RTCCTL)) & RTC_ENABLE_BIT) == 0) { in mxc_rtc_probe()
408 dev_err(&pdev->dev, "hardware module can't be enabled!\n"); in mxc_rtc_probe()
409 return -EIO; in mxc_rtc_probe()
414 /* Configure and enable the RTC */ in mxc_rtc_probe()
415 pdata->irq = platform_get_irq(pdev, 0); in mxc_rtc_probe()
417 if (pdata->irq >= 0 && in mxc_rtc_probe()
418 devm_request_irq(&pdev->dev, pdata->irq, mxc_rtc_interrupt, in mxc_rtc_probe()
419 IRQF_SHARED, pdev->name, pdev) < 0) { in mxc_rtc_probe()
420 dev_warn(&pdev->dev, "interrupt not available.\n"); in mxc_rtc_probe()
421 pdata->irq = -1; in mxc_rtc_probe()
424 if (pdata->irq >= 0) { in mxc_rtc_probe()
425 device_init_wakeup(&pdev->dev, 1); in mxc_rtc_probe()
426 ret = dev_pm_set_wake_irq(&pdev->dev, pdata->irq); in mxc_rtc_probe()
428 dev_err(&pdev->dev, "failed to enable irq wake\n"); in mxc_rtc_probe()
431 ret = rtc_register_device(rtc); in mxc_rtc_probe()
448 MODULE_DESCRIPTION("RTC driver for Freescale MXC");