Lines Matching +full:event +full:- +full:deep
4 * SPDX-License-Identifier: GPL-2.0
116 * alarm registers are used to set auxiliary alarm. Both alarm event and
117 * auxiliary alarm event can wake up system from deep sleep, but only alarm
118 * event can power up system from power down status.
128 return regmap_write(rtc->regmap, rtc->base + SPRD_RTC_INT_CLR, in sprd_rtc_clear_alarm_ints()
137 ret = regmap_read(rtc->regmap, rtc->base + SPRD_RTC_SPG_VALUE, &val); in sprd_rtc_lock_alarm()
147 ret = regmap_write(rtc->regmap, rtc->base + SPRD_RTC_SPG_UPD, val); in sprd_rtc_lock_alarm()
152 ret = regmap_read_poll_timeout(rtc->regmap, in sprd_rtc_lock_alarm()
153 rtc->base + SPRD_RTC_INT_RAW_STS, val, in sprd_rtc_lock_alarm()
158 dev_err(rtc->dev, "failed to update SPG value:%d\n", ret); in sprd_rtc_lock_alarm()
162 return regmap_write(rtc->regmap, rtc->base + SPRD_RTC_INT_CLR, in sprd_rtc_lock_alarm()
193 return -EINVAL; in sprd_rtc_get_secs()
196 ret = regmap_read(rtc->regmap, rtc->base + sec_reg, &val); in sprd_rtc_get_secs()
202 ret = regmap_read(rtc->regmap, rtc->base + min_reg, &val); in sprd_rtc_get_secs()
208 ret = regmap_read(rtc->regmap, rtc->base + hour_reg, &val); in sprd_rtc_get_secs()
214 ret = regmap_read(rtc->regmap, rtc->base + day_reg, &val); in sprd_rtc_get_secs()
233 rem -= hour * 3600; in sprd_rtc_set_secs()
235 sec = rem - min * 60; in sprd_rtc_set_secs()
260 return -EINVAL; in sprd_rtc_set_secs()
263 ret = regmap_write(rtc->regmap, rtc->base + sec_reg, sec); in sprd_rtc_set_secs()
267 ret = regmap_write(rtc->regmap, rtc->base + min_reg, min); in sprd_rtc_set_secs()
271 ret = regmap_write(rtc->regmap, rtc->base + hour_reg, hour); in sprd_rtc_set_secs()
275 ret = regmap_write(rtc->regmap, rtc->base + day_reg, day); in sprd_rtc_set_secs()
283 * Since the time and normal alarm registers are put in always-power-on in sprd_rtc_set_secs()
288 ret = regmap_read_poll_timeout(rtc->regmap, in sprd_rtc_set_secs()
289 rtc->base + SPRD_RTC_INT_RAW_STS, val, in sprd_rtc_set_secs()
294 dev_err(rtc->dev, "set time/alarm values timeout\n"); in sprd_rtc_set_secs()
298 return regmap_write(rtc->regmap, rtc->base + SPRD_RTC_INT_CLR, in sprd_rtc_set_secs()
313 rtc_time64_to_tm(secs, &alrm->time); in sprd_rtc_read_aux_alarm()
315 ret = regmap_read(rtc->regmap, rtc->base + SPRD_RTC_INT_EN, &val); in sprd_rtc_read_aux_alarm()
319 alrm->enabled = !!(val & SPRD_RTC_AUXALM_EN); in sprd_rtc_read_aux_alarm()
321 ret = regmap_read(rtc->regmap, rtc->base + SPRD_RTC_INT_RAW_STS, &val); in sprd_rtc_read_aux_alarm()
325 alrm->pending = !!(val & SPRD_RTC_AUXALM_EN); in sprd_rtc_read_aux_alarm()
332 time64_t secs = rtc_tm_to_time64(&alrm->time); in sprd_rtc_set_aux_alarm()
336 ret = regmap_write(rtc->regmap, rtc->base + SPRD_RTC_INT_CLR, in sprd_rtc_set_aux_alarm()
345 if (alrm->enabled) { in sprd_rtc_set_aux_alarm()
346 ret = regmap_update_bits(rtc->regmap, in sprd_rtc_set_aux_alarm()
347 rtc->base + SPRD_RTC_INT_EN, in sprd_rtc_set_aux_alarm()
351 ret = regmap_update_bits(rtc->regmap, in sprd_rtc_set_aux_alarm()
352 rtc->base + SPRD_RTC_INT_EN, in sprd_rtc_set_aux_alarm()
365 if (!rtc->valid) { in sprd_rtc_read_time()
367 return -EINVAL; in sprd_rtc_read_time()
388 if (!rtc->valid) { in sprd_rtc_set_time()
390 ret = regmap_write(rtc->regmap, rtc->base + SPRD_RTC_PWR_CTRL, in sprd_rtc_set_time()
399 ret = regmap_write(rtc->regmap, rtc->base + SPRD_RTC_PWR_CTRL, in sprd_rtc_set_time()
404 rtc->valid = true; in sprd_rtc_set_time()
425 if (rtc->rtc && rtc->rtc->registered && rtc->rtc->aie_timer.enabled == 0) in sprd_rtc_read_alarm()
432 rtc_time64_to_tm(secs, &alrm->time); in sprd_rtc_read_alarm()
434 ret = regmap_read(rtc->regmap, rtc->base + SPRD_RTC_INT_EN, &val); in sprd_rtc_read_alarm()
438 alrm->enabled = !!(val & SPRD_RTC_ALARM_EN); in sprd_rtc_read_alarm()
440 ret = regmap_read(rtc->regmap, rtc->base + SPRD_RTC_INT_RAW_STS, &val); in sprd_rtc_read_alarm()
444 alrm->pending = !!(val & SPRD_RTC_ALARM_EN); in sprd_rtc_read_alarm()
451 time64_t secs = rtc_tm_to_time64(&alrm->time); in sprd_rtc_set_alarm()
453 rtc_ktime_to_tm(rtc->rtc->aie_timer.node.expires); in sprd_rtc_set_alarm()
458 * both normal alarm event and auxiliary alarm event can wake up system in sprd_rtc_set_alarm()
459 * from deep sleep, but only alarm event can power up system from power in sprd_rtc_set_alarm()
462 * alarm when wake up system from deep sleep, and for other scenarios, in sprd_rtc_set_alarm()
467 * means it is just a wake event. in sprd_rtc_set_alarm()
469 if (!rtc->rtc->aie_timer.enabled || rtc_tm_sub(&aie_time, &alrm->time)) in sprd_rtc_set_alarm()
473 ret = regmap_write(rtc->regmap, rtc->base + SPRD_RTC_INT_CLR, in sprd_rtc_set_alarm()
482 if (alrm->enabled) { in sprd_rtc_set_alarm()
483 ret = regmap_update_bits(rtc->regmap, in sprd_rtc_set_alarm()
484 rtc->base + SPRD_RTC_INT_EN, in sprd_rtc_set_alarm()
493 regmap_update_bits(rtc->regmap, in sprd_rtc_set_alarm()
494 rtc->base + SPRD_RTC_INT_EN, in sprd_rtc_set_alarm()
498 * Lock the alarm function in case fake alarm event will power in sprd_rtc_set_alarm()
513 ret = regmap_update_bits(rtc->regmap, in sprd_rtc_alarm_irq_enable()
514 rtc->base + SPRD_RTC_INT_EN, in sprd_rtc_alarm_irq_enable()
522 regmap_update_bits(rtc->regmap, rtc->base + SPRD_RTC_INT_EN, in sprd_rtc_alarm_irq_enable()
548 rtc_update_irq(rtc->rtc, 1, RTC_AF | RTC_IRQF); in sprd_rtc_handler()
557 ret = regmap_read(rtc->regmap, rtc->base + SPRD_RTC_PWR_STS, &val); in sprd_rtc_check_power_down()
566 rtc->valid = val == SPRD_RTC_POWER_RESET_VALUE ? false : true; in sprd_rtc_check_power_down()
575 ret = regmap_read(rtc->regmap, rtc->base + SPRD_RTC_SPG_VALUE, &val); in sprd_rtc_check_alarm_int()
580 * The SPRD_RTC_INT_EN register is not put in always-power-on region in sprd_rtc_check_alarm_int()
585 * always-power-on region, that means we have set one alarm last time, in sprd_rtc_check_alarm_int()
592 return regmap_update_bits(rtc->regmap, rtc->base + SPRD_RTC_INT_EN, in sprd_rtc_check_alarm_int()
598 struct device_node *node = pdev->dev.of_node; in sprd_rtc_probe()
602 rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); in sprd_rtc_probe()
604 return -ENOMEM; in sprd_rtc_probe()
606 rtc->regmap = dev_get_regmap(pdev->dev.parent, NULL); in sprd_rtc_probe()
607 if (!rtc->regmap) in sprd_rtc_probe()
608 return -ENODEV; in sprd_rtc_probe()
610 ret = of_property_read_u32(node, "reg", &rtc->base); in sprd_rtc_probe()
612 dev_err(&pdev->dev, "failed to get RTC base address\n"); in sprd_rtc_probe()
616 rtc->irq = platform_get_irq(pdev, 0); in sprd_rtc_probe()
617 if (rtc->irq < 0) in sprd_rtc_probe()
618 return rtc->irq; in sprd_rtc_probe()
620 rtc->rtc = devm_rtc_allocate_device(&pdev->dev); in sprd_rtc_probe()
621 if (IS_ERR(rtc->rtc)) in sprd_rtc_probe()
622 return PTR_ERR(rtc->rtc); in sprd_rtc_probe()
624 rtc->dev = &pdev->dev; in sprd_rtc_probe()
630 dev_err(&pdev->dev, "failed to check RTC alarm interrupt\n"); in sprd_rtc_probe()
637 dev_err(&pdev->dev, "failed to check RTC time values\n"); in sprd_rtc_probe()
641 ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL, in sprd_rtc_probe()
644 pdev->name, rtc); in sprd_rtc_probe()
646 dev_err(&pdev->dev, "failed to request RTC irq\n"); in sprd_rtc_probe()
650 device_init_wakeup(&pdev->dev, 1); in sprd_rtc_probe()
652 rtc->rtc->ops = &sprd_rtc_ops; in sprd_rtc_probe()
653 rtc->rtc->range_min = 0; in sprd_rtc_probe()
654 rtc->rtc->range_max = 5662310399LL; in sprd_rtc_probe()
655 ret = rtc_register_device(rtc->rtc); in sprd_rtc_probe()
657 device_init_wakeup(&pdev->dev, 0); in sprd_rtc_probe()
665 { .compatible = "sprd,sc2731-rtc", },
672 .name = "sprd-rtc",