Lines Matching +full:resume +full:- +full:offset
1 // SPDX-License-Identifier: GPL-2.0
21 #include "rtc-core.h"
30 ida_simple_remove(&rtc_ida, rtc->id); in rtc_device_release()
31 mutex_destroy(&rtc->ops_lock); in rtc_device_release()
37 int rtc_hctosys_ret = -ENODEV;
60 dev_err(rtc->dev.parent, in rtc_hctosys()
69 err = -ERANGE; in rtc_hctosys()
76 dev_info(rtc->dev.parent, "setting system clock to %ptR UTC (%lld)\n", in rtc_hctosys()
87 * system's wall clock; restore it on resume().
102 if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0) in rtc_suspend()
108 pr_debug("%s: fail to read rtc time\n", dev_name(&rtc->dev)); in rtc_suspend()
123 if (delta_delta.tv_sec < -2 || delta_delta.tv_sec >= 2) { in rtc_suspend()
148 rtc_hctosys_ret = -ENODEV; in rtc_resume()
149 if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0) in rtc_resume()
152 /* snapshot the current rtc and system time at resume */ in rtc_resume()
156 pr_debug("%s: fail to read rtc time\n", dev_name(&rtc->dev)); in rtc_resume()
164 pr_debug("%s: time travel!\n", dev_name(&rtc->dev)); in rtc_resume()
172 * Since these RTC suspend/resume handlers are not called in rtc_resume()
173 * at the very end of suspend or the start of resume, in rtc_resume()
174 * some run-time may pass on either sides of the sleep time in rtc_resume()
175 * so subtract kernel run-time between rtc_suspend to rtc_resume in rtc_resume()
202 device_initialize(&rtc->dev); in rtc_allocate_device()
210 rtc->set_offset_nsec = NSEC_PER_SEC + 5 * NSEC_PER_MSEC; in rtc_allocate_device()
212 rtc->irq_freq = 1; in rtc_allocate_device()
213 rtc->max_user_freq = 64; in rtc_allocate_device()
214 rtc->dev.class = rtc_class; in rtc_allocate_device()
215 rtc->dev.groups = rtc_get_dev_attribute_groups(); in rtc_allocate_device()
216 rtc->dev.release = rtc_device_release; in rtc_allocate_device()
218 mutex_init(&rtc->ops_lock); in rtc_allocate_device()
219 spin_lock_init(&rtc->irq_lock); in rtc_allocate_device()
220 init_waitqueue_head(&rtc->irq_queue); in rtc_allocate_device()
223 timerqueue_init_head(&rtc->timerqueue); in rtc_allocate_device()
224 INIT_WORK(&rtc->irqwork, rtc_timer_do_work); in rtc_allocate_device()
226 rtc_timer_init(&rtc->aie_timer, rtc_aie_update_irq, rtc); in rtc_allocate_device()
228 rtc_timer_init(&rtc->uie_rtctimer, rtc_uie_update_irq, rtc); in rtc_allocate_device()
230 hrtimer_init(&rtc->pie_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); in rtc_allocate_device()
231 rtc->pie_timer.function = rtc_pie_update_irq; in rtc_allocate_device()
232 rtc->pie_enabled = 0; in rtc_allocate_device()
234 set_bit(RTC_FEATURE_ALARM, rtc->features); in rtc_allocate_device()
241 int of_id = -1, id = -1; in rtc_device_get_id()
243 if (dev->of_node) in rtc_device_get_id()
244 of_id = of_alias_get_id(dev->of_node, "rtc"); in rtc_device_get_id()
245 else if (dev->parent && dev->parent->of_node) in rtc_device_get_id()
246 of_id = of_alias_get_id(dev->parent->of_node, "rtc"); in rtc_device_get_id()
269 * offset. in rtc_device_get_offset()
271 if (rtc->range_min == rtc->range_max) in rtc_device_get_offset()
274 ret = device_property_read_u32(rtc->dev.parent, "start-year", in rtc_device_get_offset()
277 rtc->start_secs = mktime64(start_year, 1, 1, 0, 0, 0); in rtc_device_get_offset()
278 rtc->set_start_time = true; in rtc_device_get_offset()
285 if (!rtc->set_start_time) in rtc_device_get_offset()
288 range_secs = rtc->range_max - rtc->range_min + 1; in rtc_device_get_offset()
291 * If the start_secs is larger than the maximum seconds (rtc->range_max) in rtc_device_get_offset()
293 * range (start_secs + rtc->range_max - rtc->range_min) is less than in rtc_device_get_offset()
294 * rtc->range_min, which means the minimum seconds (rtc->range_min) of in rtc_device_get_offset()
295 * RTC hardware will be mapped to start_secs by adding one offset, so in rtc_device_get_offset()
296 * the offset seconds calculation formula should be: in rtc_device_get_offset()
297 * rtc->offset_secs = rtc->start_secs - rtc->range_min; in rtc_device_get_offset()
299 * If the start_secs is larger than the minimum seconds (rtc->range_min) in rtc_device_get_offset()
304 * seconds of RTC hardware (rtc->range_min) should be mapped to in rtc_device_get_offset()
305 * rtc->range_max + 1, then the offset seconds formula should be: in rtc_device_get_offset()
306 * rtc->offset_secs = rtc->range_max - rtc->range_min + 1; in rtc_device_get_offset()
308 * If the start_secs is less than the minimum seconds (rtc->range_min), in rtc_device_get_offset()
310 * start_secs + rtc->range_max - rtc->range_min + 1, then the in rtc_device_get_offset()
311 * offset seconds formula should be: in rtc_device_get_offset()
312 * rtc->offset_secs = -(rtc->range_max - rtc->range_min + 1); in rtc_device_get_offset()
314 * Otherwise the offset seconds should be 0. in rtc_device_get_offset()
316 if (rtc->start_secs > rtc->range_max || in rtc_device_get_offset()
317 rtc->start_secs + range_secs - 1 < rtc->range_min) in rtc_device_get_offset()
318 rtc->offset_secs = rtc->start_secs - rtc->range_min; in rtc_device_get_offset()
319 else if (rtc->start_secs > rtc->range_min) in rtc_device_get_offset()
320 rtc->offset_secs = range_secs; in rtc_device_get_offset()
321 else if (rtc->start_secs < rtc->range_min) in rtc_device_get_offset()
322 rtc->offset_secs = -range_secs; in rtc_device_get_offset()
324 rtc->offset_secs = 0; in rtc_device_get_offset()
331 mutex_lock(&rtc->ops_lock); in devm_rtc_unregister_device()
337 cdev_device_del(&rtc->char_dev, &rtc->dev); in devm_rtc_unregister_device()
338 rtc->ops = NULL; in devm_rtc_unregister_device()
339 mutex_unlock(&rtc->ops_lock); in devm_rtc_unregister_device()
346 put_device(&rtc->dev); in devm_rtc_release_device()
361 return ERR_PTR(-ENOMEM); in devm_rtc_allocate_device()
364 rtc->id = id; in devm_rtc_allocate_device()
365 rtc->dev.parent = dev; in devm_rtc_allocate_device()
366 dev_set_name(&rtc->dev, "rtc%d", id); in devm_rtc_allocate_device()
381 if (!rtc->ops) { in __devm_rtc_register_device()
382 dev_dbg(&rtc->dev, "no ops set\n"); in __devm_rtc_register_device()
383 return -EINVAL; in __devm_rtc_register_device()
386 if (!rtc->ops->set_alarm) in __devm_rtc_register_device()
387 clear_bit(RTC_FEATURE_ALARM, rtc->features); in __devm_rtc_register_device()
389 rtc->owner = owner; in __devm_rtc_register_device()
399 err = cdev_device_add(&rtc->char_dev, &rtc->dev); in __devm_rtc_register_device()
401 dev_warn(rtc->dev.parent, "failed to add char device %d:%d\n", in __devm_rtc_register_device()
402 MAJOR(rtc->dev.devt), rtc->id); in __devm_rtc_register_device()
404 dev_dbg(rtc->dev.parent, "char device (%d:%d)\n", in __devm_rtc_register_device()
405 MAJOR(rtc->dev.devt), rtc->id); in __devm_rtc_register_device()
409 dev_info(rtc->dev.parent, "registered as %s\n", in __devm_rtc_register_device()
410 dev_name(&rtc->dev)); in __devm_rtc_register_device()
413 if (!strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE)) in __devm_rtc_register_device()
417 return devm_add_action_or_reset(rtc->dev.parent, in __devm_rtc_register_device()
423 * devm_rtc_device_register - resource managed rtc_device_register()
448 rtc->ops = ops; in devm_rtc_device_register()
465 rtc_class->pm = RTC_CLASS_DEV_PM_OPS; in rtc_init()