• Home
  • Raw
  • Download

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
74 .name = "imx1-rtc",
77 .name = "imx21-rtc",
87 { .compatible = "fsl,imx1-rtc", .data = (const void *)IMX1_RTC },
88 { .compatible = "fsl,imx21-rtc", .data = (const void *)IMX21_RTC },
96 return data->devtype == IMX1_RTC; in is_imx1_rtc()
100 * This function is used to obtain the RTC time or the alarm value in
106 void __iomem *ioaddr = pdata->ioaddr; in get_alarm_or_time()
129 * This function sets the RTC alarm value or the time value.
135 void __iomem *ioaddr = pdata->ioaddr; in set_alarm_or_time()
141 tod -= hr * 3600; in set_alarm_or_time()
145 sec = tod - min * 60; in set_alarm_or_time()
164 * This function updates the RTC alarm registers and then clears all the
171 void __iomem *ioaddr = pdata->ioaddr; in rtc_update_alarm()
184 void __iomem *ioaddr = pdata->ioaddr; in mxc_rtc_irq_enable()
187 spin_lock_irq(&pdata->rtc->irq_lock); in mxc_rtc_irq_enable()
196 spin_unlock_irq(&pdata->rtc->irq_lock); in mxc_rtc_irq_enable()
199 /* This function is the RTC interrupt service routine. */
204 void __iomem *ioaddr = pdata->ioaddr; in mxc_rtc_interrupt()
209 spin_lock_irqsave(&pdata->rtc->irq_lock, flags); in mxc_rtc_interrupt()
217 /* RTC alarm should be one-shot */ in mxc_rtc_interrupt()
218 mxc_rtc_irq_enable(&pdev->dev, RTC_ALM_BIT, 0); in mxc_rtc_interrupt()
224 rtc_update_irq(pdata->rtc, 1, events); in mxc_rtc_interrupt()
225 spin_unlock_irqrestore(&pdata->rtc->irq_lock, flags); in mxc_rtc_interrupt()
237 * This function reads the current RTC time into tm in Gregorian date.
243 /* Avoid roll-over from reading the different registers */ in mxc_rtc_read_time()
254 * This function sets the internal RTC time based on tm in Gregorian date.
261 * TTC_DAYR register is 9-bit in MX1 SoC, save time and day of year only in mxc_rtc_set_mmss()
271 /* Avoid roll-over from reading the different registers */ in mxc_rtc_set_mmss()
287 void __iomem *ioaddr = pdata->ioaddr; in mxc_rtc_read_alarm()
289 rtc_time64_to_tm(get_alarm_or_time(dev, MXC_RTC_ALARM), &alrm->time); in mxc_rtc_read_alarm()
290 alrm->pending = ((readw(ioaddr + RTC_RTCISR) & RTC_ALM_BIT)) ? 1 : 0; in mxc_rtc_read_alarm()
296 * This function sets the RTC alarm based on passed in alrm.
302 rtc_update_alarm(dev, &alrm->time); in mxc_rtc_set_alarm()
304 memcpy(&pdata->g_rtc_alarm, &alrm->time, sizeof(struct rtc_time)); in mxc_rtc_set_alarm()
305 mxc_rtc_irq_enable(dev, RTC_ALM_BIT, alrm->enabled); in mxc_rtc_set_alarm()
310 /* RTC layer */
322 struct rtc_device *rtc; in mxc_rtc_probe() local
329 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); in mxc_rtc_probe()
331 return -ENOMEM; in mxc_rtc_probe()
333 of_id = of_match_device(imx_rtc_dt_ids, &pdev->dev); in mxc_rtc_probe()
335 pdata->devtype = (enum imx_rtc_type)of_id->data; in mxc_rtc_probe()
337 pdata->devtype = pdev->id_entry->driver_data; in mxc_rtc_probe()
340 pdata->ioaddr = devm_ioremap_resource(&pdev->dev, res); in mxc_rtc_probe()
341 if (IS_ERR(pdata->ioaddr)) in mxc_rtc_probe()
342 return PTR_ERR(pdata->ioaddr); 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 dev_err(&pdev->dev, "unable to get ref clock!\n"); in mxc_rtc_probe()
357 ret = PTR_ERR(pdata->clk_ref); in mxc_rtc_probe()
361 ret = clk_prepare_enable(pdata->clk_ref); in mxc_rtc_probe()
365 rate = clk_get_rate(pdata->clk_ref); in mxc_rtc_probe()
374 dev_err(&pdev->dev, "rtc clock is not valid (%lu)\n", rate); in mxc_rtc_probe()
375 ret = -EINVAL; in mxc_rtc_probe()
380 writew(reg, (pdata->ioaddr + RTC_RTCCTL)); in mxc_rtc_probe()
381 if (((readw(pdata->ioaddr + RTC_RTCCTL)) & RTC_ENABLE_BIT) == 0) { in mxc_rtc_probe()
382 dev_err(&pdev->dev, "hardware module can't be enabled!\n"); in mxc_rtc_probe()
383 ret = -EIO; in mxc_rtc_probe()
389 /* Configure and enable the RTC */ in mxc_rtc_probe()
390 pdata->irq = platform_get_irq(pdev, 0); in mxc_rtc_probe()
392 if (pdata->irq >= 0 && in mxc_rtc_probe()
393 devm_request_irq(&pdev->dev, pdata->irq, mxc_rtc_interrupt, in mxc_rtc_probe()
394 IRQF_SHARED, pdev->name, pdev) < 0) { in mxc_rtc_probe()
395 dev_warn(&pdev->dev, "interrupt not available.\n"); in mxc_rtc_probe()
396 pdata->irq = -1; in mxc_rtc_probe()
399 if (pdata->irq >= 0) in mxc_rtc_probe()
400 device_init_wakeup(&pdev->dev, 1); in mxc_rtc_probe()
402 rtc = devm_rtc_device_register(&pdev->dev, pdev->name, &mxc_rtc_ops, in mxc_rtc_probe()
404 if (IS_ERR(rtc)) { in mxc_rtc_probe()
405 ret = PTR_ERR(rtc); in mxc_rtc_probe()
409 pdata->rtc = rtc; in mxc_rtc_probe()
414 clk_disable_unprepare(pdata->clk_ref); in mxc_rtc_probe()
416 clk_disable_unprepare(pdata->clk_ipg); in mxc_rtc_probe()
425 clk_disable_unprepare(pdata->clk_ref); in mxc_rtc_remove()
426 clk_disable_unprepare(pdata->clk_ipg); in mxc_rtc_remove()
437 enable_irq_wake(pdata->irq); in mxc_rtc_suspend()
447 disable_irq_wake(pdata->irq); in mxc_rtc_resume()
469 MODULE_DESCRIPTION("RTC driver for Freescale MXC");