Lines Matching +full:ls1088a +full:- +full:ftm +full:- +full:alarm

1 // SPDX-License-Identifier: GPL-2.0+
3 * Freescale FlexTimer Module (FTM) alarm device driver.
6 * Copyright 2019-2020 NXP
17 #include <linux/fsl/ftm.h>
47 if (dev->big_endian) in rtc_readl()
48 return ioread32be(dev->base + reg); in rtc_readl()
50 return ioread32(dev->base + reg); in rtc_readl()
55 if (dev->big_endian) in rtc_writel()
56 iowrite32be(val, dev->base + reg); in rtc_writel()
58 iowrite32(val, dev->base + reg); in rtc_writel()
87 *Fix errata A-007728 for flextimer in ftm_irq_acknowledge()
88 * If the FTM counter reaches the FTM_MOD value between in ftm_irq_acknowledge()
100 * FTMx_CONF[NUMTOF] was seted as nonzero and FTM counter in ftm_irq_acknowledge()
104 * (FTM counter doesn't always reache the FTM_MOD anyway), in ftm_irq_acknowledge()
107 while ((FTM_SC_TOF & rtc_readl(rtc, FTM_SC)) && timeout--) in ftm_irq_acknowledge()
132 * The CNT register contains the FTM counter value. in ftm_reset_counter()
153 rtc_update_irq(rtc->rtc_dev, 1, RTC_IRQF | RTC_AF); in ftm_rtc_alarm_interrupt()
179 * get time to setup alarm, so we are using system time
203 * So max alarm value is 262 (65536 / 250) seconds
211 alm_time = rtc_tm_to_time64(&alm->time); in ftm_rtc_set_alarm()
214 cycle = (alm_time - ktime_get_real_seconds()) * rtc->alarm_freq; in ftm_rtc_set_alarm()
216 pr_err("Out of alarm range {0~262} seconds.\n"); in ftm_rtc_set_alarm()
217 return -ERANGE; in ftm_rtc_set_alarm()
225 * The TOF (the overflow flag) bit is set when the FTM counter in ftm_rtc_set_alarm()
226 * changes from MOD to CNTIN. So we should using the cycle - 1. in ftm_rtc_set_alarm()
228 rtc_writel(rtc, FTM_MOD, cycle - 1); in ftm_rtc_set_alarm()
250 rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); in ftm_rtc_probe()
252 dev_err(&pdev->dev, "cannot alloc memory for rtc\n"); in ftm_rtc_probe()
253 return -ENOMEM; in ftm_rtc_probe()
258 rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev); in ftm_rtc_probe()
259 if (IS_ERR(rtc->rtc_dev)) in ftm_rtc_probe()
260 return PTR_ERR(rtc->rtc_dev); in ftm_rtc_probe()
262 rtc->base = devm_platform_ioremap_resource(pdev, 0); in ftm_rtc_probe()
263 if (IS_ERR(rtc->base)) { in ftm_rtc_probe()
264 dev_err(&pdev->dev, "cannot ioremap resource for rtc\n"); in ftm_rtc_probe()
265 return PTR_ERR(rtc->base); in ftm_rtc_probe()
272 ret = devm_request_irq(&pdev->dev, irq, ftm_rtc_alarm_interrupt, in ftm_rtc_probe()
273 0, dev_name(&pdev->dev), rtc); in ftm_rtc_probe()
275 dev_err(&pdev->dev, "failed to request irq\n"); in ftm_rtc_probe()
279 rtc->big_endian = in ftm_rtc_probe()
280 device_property_read_bool(&pdev->dev, "big-endian"); in ftm_rtc_probe()
282 rtc->alarm_freq = (u32)FIXED_FREQ_CLK / (u32)MAX_FREQ_DIV; in ftm_rtc_probe()
283 rtc->rtc_dev->ops = &ftm_rtc_ops; in ftm_rtc_probe()
285 device_init_wakeup(&pdev->dev, true); in ftm_rtc_probe()
286 ret = dev_pm_set_wake_irq(&pdev->dev, irq); in ftm_rtc_probe()
288 dev_err(&pdev->dev, "failed to enable irq wake\n"); in ftm_rtc_probe()
290 ret = devm_rtc_register_device(rtc->rtc_dev); in ftm_rtc_probe()
292 dev_err(&pdev->dev, "can't register rtc device\n"); in ftm_rtc_probe()
300 { .compatible = "fsl,ls1012a-ftm-alarm", },
301 { .compatible = "fsl,ls1021a-ftm-alarm", },
302 { .compatible = "fsl,ls1028a-ftm-alarm", },
303 { .compatible = "fsl,ls1043a-ftm-alarm", },
304 { .compatible = "fsl,ls1046a-ftm-alarm", },
305 { .compatible = "fsl,ls1088a-ftm-alarm", },
306 { .compatible = "fsl,ls208xa-ftm-alarm", },
307 { .compatible = "fsl,lx2160a-ftm-alarm", },
321 .name = "ftm-alarm",
329 MODULE_DESCRIPTION("NXP/Freescale FlexTimer alarm driver");