Lines Matching +full:normal +full:- +full:power
1 // SPDX-License-Identifier: GPL-2.0
92 /* power control/status definition */
113 * The Spreadtrum RTC controller has 3 groups registers, including time, normal
115 * the normal alarm registers are used to set normal alarm, and the auxiliary
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()
305 time64_t secs = rtc_tm_to_time64(&alrm->time); in sprd_rtc_set_aux_alarm()
309 ret = regmap_write(rtc->regmap, rtc->base + SPRD_RTC_INT_CLR, in sprd_rtc_set_aux_alarm()
318 if (alrm->enabled) { in sprd_rtc_set_aux_alarm()
319 ret = regmap_update_bits(rtc->regmap, in sprd_rtc_set_aux_alarm()
320 rtc->base + SPRD_RTC_INT_EN, in sprd_rtc_set_aux_alarm()
324 ret = regmap_update_bits(rtc->regmap, in sprd_rtc_set_aux_alarm()
325 rtc->base + SPRD_RTC_INT_EN, in sprd_rtc_set_aux_alarm()
338 if (!rtc->valid) { in sprd_rtc_read_time()
340 return -EINVAL; in sprd_rtc_read_time()
361 if (!rtc->valid) { in sprd_rtc_set_time()
362 /* Clear RTC power status firstly */ in sprd_rtc_set_time()
363 ret = regmap_write(rtc->regmap, rtc->base + SPRD_RTC_PWR_CTRL, in sprd_rtc_set_time()
369 * Set RTC power status to indicate now RTC has valid time in sprd_rtc_set_time()
372 ret = regmap_write(rtc->regmap, rtc->base + SPRD_RTC_PWR_CTRL, in sprd_rtc_set_time()
377 rtc->valid = true; in sprd_rtc_set_time()
392 * hardware, and we always read the normal alarm at this time. in sprd_rtc_read_alarm()
398 rtc_time64_to_tm(secs, &alrm->time); in sprd_rtc_read_alarm()
400 ret = regmap_read(rtc->regmap, rtc->base + SPRD_RTC_INT_EN, &val); in sprd_rtc_read_alarm()
404 alrm->enabled = !!(val & SPRD_RTC_ALARM_EN); in sprd_rtc_read_alarm()
406 ret = regmap_read(rtc->regmap, rtc->base + SPRD_RTC_INT_RAW_STS, &val); in sprd_rtc_read_alarm()
410 alrm->pending = !!(val & SPRD_RTC_ALARM_EN); in sprd_rtc_read_alarm()
417 time64_t secs = rtc_tm_to_time64(&alrm->time); in sprd_rtc_set_alarm()
419 rtc_ktime_to_tm(rtc->rtc->aie_timer.node.expires); in sprd_rtc_set_alarm()
423 * We have 2 groups alarms: normal alarm and auxiliary alarm. Since in sprd_rtc_set_alarm()
424 * both normal alarm event and auxiliary alarm event can wake up system in sprd_rtc_set_alarm()
425 * from deep sleep, but only alarm event can power up system from power in sprd_rtc_set_alarm()
429 * we should set normal alarm with polling status. in sprd_rtc_set_alarm()
432 * should set normal alarm, if not, we should set auxiliary alarm which in sprd_rtc_set_alarm()
435 if (!rtc->rtc->aie_timer.enabled || rtc_tm_sub(&aie_time, &alrm->time)) in sprd_rtc_set_alarm()
439 ret = regmap_write(rtc->regmap, rtc->base + SPRD_RTC_INT_CLR, in sprd_rtc_set_alarm()
448 if (alrm->enabled) { in sprd_rtc_set_alarm()
449 ret = regmap_update_bits(rtc->regmap, in sprd_rtc_set_alarm()
450 rtc->base + SPRD_RTC_INT_EN, in sprd_rtc_set_alarm()
459 regmap_update_bits(rtc->regmap, in sprd_rtc_set_alarm()
460 rtc->base + SPRD_RTC_INT_EN, in sprd_rtc_set_alarm()
464 * Lock the alarm function in case fake alarm event will power in sprd_rtc_set_alarm()
479 ret = regmap_update_bits(rtc->regmap, in sprd_rtc_alarm_irq_enable()
480 rtc->base + SPRD_RTC_INT_EN, in sprd_rtc_alarm_irq_enable()
488 regmap_update_bits(rtc->regmap, rtc->base + SPRD_RTC_INT_EN, in sprd_rtc_alarm_irq_enable()
514 rtc_update_irq(rtc->rtc, 1, RTC_AF | RTC_IRQF); in sprd_rtc_handler()
523 ret = regmap_read(rtc->regmap, rtc->base + SPRD_RTC_PWR_STS, &val); in sprd_rtc_check_power_down()
528 * If the RTC power status value is SPRD_RTC_POWER_RESET_VALUE, which in sprd_rtc_check_power_down()
532 rtc->valid = val != SPRD_RTC_POWER_RESET_VALUE; in sprd_rtc_check_power_down()
541 ret = regmap_read(rtc->regmap, rtc->base + SPRD_RTC_SPG_VALUE, &val); in sprd_rtc_check_alarm_int()
546 * The SPRD_RTC_INT_EN register is not put in always-power-on region in sprd_rtc_check_alarm_int()
551 * always-power-on region, that means we have set one alarm last time, in sprd_rtc_check_alarm_int()
558 return regmap_update_bits(rtc->regmap, rtc->base + SPRD_RTC_INT_EN, in sprd_rtc_check_alarm_int()
564 struct device_node *node = pdev->dev.of_node; in sprd_rtc_probe()
568 rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); in sprd_rtc_probe()
570 return -ENOMEM; in sprd_rtc_probe()
572 rtc->regmap = dev_get_regmap(pdev->dev.parent, NULL); in sprd_rtc_probe()
573 if (!rtc->regmap) in sprd_rtc_probe()
574 return -ENODEV; in sprd_rtc_probe()
576 ret = of_property_read_u32(node, "reg", &rtc->base); in sprd_rtc_probe()
578 dev_err(&pdev->dev, "failed to get RTC base address\n"); in sprd_rtc_probe()
582 rtc->irq = platform_get_irq(pdev, 0); in sprd_rtc_probe()
583 if (rtc->irq < 0) in sprd_rtc_probe()
584 return rtc->irq; in sprd_rtc_probe()
586 rtc->rtc = devm_rtc_allocate_device(&pdev->dev); in sprd_rtc_probe()
587 if (IS_ERR(rtc->rtc)) in sprd_rtc_probe()
588 return PTR_ERR(rtc->rtc); in sprd_rtc_probe()
590 rtc->dev = &pdev->dev; in sprd_rtc_probe()
596 dev_err(&pdev->dev, "failed to check RTC alarm interrupt\n"); in sprd_rtc_probe()
603 dev_err(&pdev->dev, "failed to check RTC time values\n"); in sprd_rtc_probe()
607 ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL, in sprd_rtc_probe()
610 pdev->name, rtc); in sprd_rtc_probe()
612 dev_err(&pdev->dev, "failed to request RTC irq\n"); in sprd_rtc_probe()
616 device_init_wakeup(&pdev->dev, 1); in sprd_rtc_probe()
618 rtc->rtc->ops = &sprd_rtc_ops; in sprd_rtc_probe()
619 rtc->rtc->range_min = 0; in sprd_rtc_probe()
620 rtc->rtc->range_max = 5662310399LL; in sprd_rtc_probe()
621 ret = devm_rtc_register_device(rtc->rtc); in sprd_rtc_probe()
623 device_init_wakeup(&pdev->dev, 0); in sprd_rtc_probe()
631 { .compatible = "sprd,sc2731-rtc", },
638 .name = "sprd-rtc",