• Home
  • Raw
  • Download

Lines Matching +full:close +full:- +full:range

1 // SPDX-License-Identifier: GPL-2.0
21 #include "rtc-core.h"
30 ida_simple_remove(&rtc_ida, rtc->id); in rtc_device_release()
36 int rtc_hctosys_ret = -ENODEV;
39 * whether it stores the most close value or the value with partial
44 * of >32bits is not possible. So storing the most close value would
59 dev_err(rtc->dev.parent, in rtc_hctosys()
68 err = -ERANGE; in rtc_hctosys()
75 dev_info(rtc->dev.parent, "setting system clock to %ptR UTC (%lld)\n", in rtc_hctosys()
101 if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0) in rtc_suspend()
107 pr_debug("%s: fail to read rtc time\n", dev_name(&rtc->dev)); in rtc_suspend()
118 * and rtc time stays close to constant. in rtc_suspend()
122 if (delta_delta.tv_sec < -2 || delta_delta.tv_sec >= 2) { in rtc_suspend()
147 rtc_hctosys_ret = -ENODEV; in rtc_resume()
148 if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0) in rtc_resume()
155 pr_debug("%s: fail to read rtc time\n", dev_name(&rtc->dev)); in rtc_resume()
163 pr_debug("%s: time travel!\n", dev_name(&rtc->dev)); in rtc_resume()
173 * some run-time may pass on either sides of the sleep time in rtc_resume()
174 * so subtract kernel run-time between rtc_suspend to rtc_resume in rtc_resume()
201 device_initialize(&rtc->dev); in rtc_allocate_device()
204 rtc->set_offset_nsec = NSEC_PER_SEC / 2; in rtc_allocate_device()
206 rtc->irq_freq = 1; in rtc_allocate_device()
207 rtc->max_user_freq = 64; in rtc_allocate_device()
208 rtc->dev.class = rtc_class; in rtc_allocate_device()
209 rtc->dev.groups = rtc_get_dev_attribute_groups(); in rtc_allocate_device()
210 rtc->dev.release = rtc_device_release; in rtc_allocate_device()
212 mutex_init(&rtc->ops_lock); in rtc_allocate_device()
213 spin_lock_init(&rtc->irq_lock); in rtc_allocate_device()
214 init_waitqueue_head(&rtc->irq_queue); in rtc_allocate_device()
217 timerqueue_init_head(&rtc->timerqueue); in rtc_allocate_device()
218 INIT_WORK(&rtc->irqwork, rtc_timer_do_work); in rtc_allocate_device()
220 rtc_timer_init(&rtc->aie_timer, rtc_aie_update_irq, rtc); in rtc_allocate_device()
222 rtc_timer_init(&rtc->uie_rtctimer, rtc_uie_update_irq, rtc); in rtc_allocate_device()
224 hrtimer_init(&rtc->pie_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); in rtc_allocate_device()
225 rtc->pie_timer.function = rtc_pie_update_irq; in rtc_allocate_device()
226 rtc->pie_enabled = 0; in rtc_allocate_device()
233 int of_id = -1, id = -1; in rtc_device_get_id()
235 if (dev->of_node) in rtc_device_get_id()
236 of_id = of_alias_get_id(dev->of_node, "rtc"); in rtc_device_get_id()
237 else if (dev->parent && dev->parent->of_node) in rtc_device_get_id()
238 of_id = of_alias_get_id(dev->parent->of_node, "rtc"); in rtc_device_get_id()
259 * If RTC driver did not implement the range of RTC hardware device, in rtc_device_get_offset()
260 * then we can not expand the RTC range by adding or subtracting one in rtc_device_get_offset()
263 if (rtc->range_min == rtc->range_max) in rtc_device_get_offset()
266 ret = device_property_read_u32(rtc->dev.parent, "start-year", in rtc_device_get_offset()
269 rtc->start_secs = mktime64(start_year, 1, 1, 0, 0, 0); in rtc_device_get_offset()
270 rtc->set_start_time = true; in rtc_device_get_offset()
275 * need to expand the RTC range. in rtc_device_get_offset()
277 if (!rtc->set_start_time) in rtc_device_get_offset()
280 range_secs = rtc->range_max - rtc->range_min + 1; in rtc_device_get_offset()
283 * If the start_secs is larger than the maximum seconds (rtc->range_max) in rtc_device_get_offset()
285 * range (start_secs + rtc->range_max - rtc->range_min) is less than in rtc_device_get_offset()
286 * rtc->range_min, which means the minimum seconds (rtc->range_min) of in rtc_device_get_offset()
289 * rtc->offset_secs = rtc->start_secs - rtc->range_min; in rtc_device_get_offset()
291 * If the start_secs is larger than the minimum seconds (rtc->range_min) in rtc_device_get_offset()
293 * between the original RTC hardware range and the new expanded range, in rtc_device_get_offset()
295 * expanded range due to it is valid for RTC device. So the minimum in rtc_device_get_offset()
296 * seconds of RTC hardware (rtc->range_min) should be mapped to in rtc_device_get_offset()
297 * rtc->range_max + 1, then the offset seconds formula should be: in rtc_device_get_offset()
298 * rtc->offset_secs = rtc->range_max - rtc->range_min + 1; in rtc_device_get_offset()
300 * If the start_secs is less than the minimum seconds (rtc->range_min), in rtc_device_get_offset()
302 * start_secs + rtc->range_max - rtc->range_min + 1, then the in rtc_device_get_offset()
304 * rtc->offset_secs = -(rtc->range_max - rtc->range_min + 1); in rtc_device_get_offset()
308 if (rtc->start_secs > rtc->range_max || in rtc_device_get_offset()
309 rtc->start_secs + range_secs - 1 < rtc->range_min) in rtc_device_get_offset()
310 rtc->offset_secs = rtc->start_secs - rtc->range_min; in rtc_device_get_offset()
311 else if (rtc->start_secs > rtc->range_min) in rtc_device_get_offset()
312 rtc->offset_secs = range_secs; in rtc_device_get_offset()
313 else if (rtc->start_secs < rtc->range_min) in rtc_device_get_offset()
314 rtc->offset_secs = -range_secs; in rtc_device_get_offset()
316 rtc->offset_secs = 0; in rtc_device_get_offset()
320 * rtc_device_unregister - removes the previously registered RTC class device
326 mutex_lock(&rtc->ops_lock); in rtc_device_unregister()
332 cdev_device_del(&rtc->char_dev, &rtc->dev); in rtc_device_unregister()
333 rtc->ops = NULL; in rtc_device_unregister()
334 mutex_unlock(&rtc->ops_lock); in rtc_device_unregister()
335 put_device(&rtc->dev); in rtc_device_unregister()
344 if (rtc->registered) in devm_rtc_release_device()
347 put_device(&rtc->dev); in devm_rtc_release_device()
361 err = -ENOMEM; in devm_rtc_allocate_device()
367 err = -ENOMEM; in devm_rtc_allocate_device()
374 rtc->id = id; in devm_rtc_allocate_device()
375 rtc->dev.parent = dev; in devm_rtc_allocate_device()
376 dev_set_name(&rtc->dev, "rtc%d", id); in devm_rtc_allocate_device()
393 if (!rtc->ops) { in __rtc_register_device()
394 dev_dbg(&rtc->dev, "no ops set\n"); in __rtc_register_device()
395 return -EINVAL; in __rtc_register_device()
398 rtc->owner = owner; in __rtc_register_device()
408 err = cdev_device_add(&rtc->char_dev, &rtc->dev); in __rtc_register_device()
410 dev_warn(rtc->dev.parent, "failed to add char device %d:%d\n", in __rtc_register_device()
411 MAJOR(rtc->dev.devt), rtc->id); in __rtc_register_device()
413 dev_dbg(rtc->dev.parent, "char device (%d:%d)\n", in __rtc_register_device()
414 MAJOR(rtc->dev.devt), rtc->id); in __rtc_register_device()
418 rtc->registered = true; in __rtc_register_device()
419 dev_info(rtc->dev.parent, "registered as %s\n", in __rtc_register_device()
420 dev_name(&rtc->dev)); in __rtc_register_device()
423 if (!strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE)) in __rtc_register_device()
432 * devm_rtc_device_register - resource managed rtc_device_register()
457 rtc->ops = ops; in devm_rtc_device_register()
474 rtc_class->pm = RTC_CLASS_DEV_PM_OPS; in rtc_init()