Lines Matching refs:rtc
28 struct rtc_device *rtc = to_rtc_device(dev); in rtc_device_release() local
30 ida_simple_remove(&rtc_ida, rtc->id); in rtc_device_release()
31 mutex_destroy(&rtc->ops_lock); in rtc_device_release()
32 kfree(rtc); in rtc_device_release()
50 static void rtc_hctosys(struct rtc_device *rtc) in rtc_hctosys() argument
58 err = rtc_read_time(rtc, &tm); in rtc_hctosys()
60 dev_err(rtc->dev.parent, in rtc_hctosys()
76 dev_info(rtc->dev.parent, "setting system clock to %ptR UTC (%lld)\n", in rtc_hctosys()
94 struct rtc_device *rtc = to_rtc_device(dev); in rtc_suspend() local
102 if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0) in rtc_suspend()
106 err = rtc_read_time(rtc, &tm); in rtc_suspend()
108 pr_debug("%s: fail to read rtc time\n", dev_name(&rtc->dev)); in rtc_suspend()
139 struct rtc_device *rtc = to_rtc_device(dev); in rtc_resume() local
149 if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0) in rtc_resume()
154 err = rtc_read_time(rtc, &tm); 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()
196 struct rtc_device *rtc; in rtc_allocate_device() local
198 rtc = kzalloc(sizeof(*rtc), GFP_KERNEL); in rtc_allocate_device()
199 if (!rtc) in rtc_allocate_device()
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()
235 set_bit(RTC_FEATURE_UPDATE_INTERRUPT, rtc->features); in rtc_allocate_device()
237 return rtc; in rtc_allocate_device()
261 static void rtc_device_get_offset(struct rtc_device *rtc) in rtc_device_get_offset() argument
272 if (rtc->range_min == rtc->range_max) in rtc_device_get_offset()
275 ret = device_property_read_u32(rtc->dev.parent, "start-year", in rtc_device_get_offset()
278 rtc->start_secs = mktime64(start_year, 1, 1, 0, 0, 0); in rtc_device_get_offset()
279 rtc->set_start_time = true; in rtc_device_get_offset()
286 if (!rtc->set_start_time) in rtc_device_get_offset()
289 range_secs = rtc->range_max - rtc->range_min + 1; in rtc_device_get_offset()
317 if (rtc->start_secs > rtc->range_max || in rtc_device_get_offset()
318 rtc->start_secs + range_secs - 1 < rtc->range_min) in rtc_device_get_offset()
319 rtc->offset_secs = rtc->start_secs - rtc->range_min; in rtc_device_get_offset()
320 else if (rtc->start_secs > rtc->range_min) in rtc_device_get_offset()
321 rtc->offset_secs = range_secs; in rtc_device_get_offset()
322 else if (rtc->start_secs < rtc->range_min) in rtc_device_get_offset()
323 rtc->offset_secs = -range_secs; in rtc_device_get_offset()
325 rtc->offset_secs = 0; in rtc_device_get_offset()
330 struct rtc_device *rtc = data; in devm_rtc_unregister_device() local
332 mutex_lock(&rtc->ops_lock); in devm_rtc_unregister_device()
337 rtc_proc_del_device(rtc); in devm_rtc_unregister_device()
338 if (!test_bit(RTC_NO_CDEV, &rtc->flags)) in devm_rtc_unregister_device()
339 cdev_device_del(&rtc->char_dev, &rtc->dev); in devm_rtc_unregister_device()
340 rtc->ops = NULL; in devm_rtc_unregister_device()
341 mutex_unlock(&rtc->ops_lock); in devm_rtc_unregister_device()
346 struct rtc_device *rtc = res; in devm_rtc_release_device() local
348 put_device(&rtc->dev); in devm_rtc_release_device()
353 struct rtc_device *rtc; in devm_rtc_allocate_device() local
360 rtc = rtc_allocate_device(); in devm_rtc_allocate_device()
361 if (!rtc) { in devm_rtc_allocate_device()
366 rtc->id = id; in devm_rtc_allocate_device()
367 rtc->dev.parent = dev; in devm_rtc_allocate_device()
368 err = dev_set_name(&rtc->dev, "rtc%d", id); in devm_rtc_allocate_device()
372 err = devm_add_action_or_reset(dev, devm_rtc_release_device, rtc); in devm_rtc_allocate_device()
376 return rtc; in devm_rtc_allocate_device()
380 int __devm_rtc_register_device(struct module *owner, struct rtc_device *rtc) in __devm_rtc_register_device() argument
385 if (!rtc->ops) { in __devm_rtc_register_device()
386 dev_dbg(&rtc->dev, "no ops set\n"); in __devm_rtc_register_device()
390 if (!rtc->ops->set_alarm) in __devm_rtc_register_device()
391 clear_bit(RTC_FEATURE_ALARM, rtc->features); in __devm_rtc_register_device()
393 if (rtc->uie_unsupported) in __devm_rtc_register_device()
394 clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, rtc->features); in __devm_rtc_register_device()
396 if (rtc->ops->set_offset) in __devm_rtc_register_device()
397 set_bit(RTC_FEATURE_CORRECTION, rtc->features); in __devm_rtc_register_device()
399 rtc->owner = owner; in __devm_rtc_register_device()
400 rtc_device_get_offset(rtc); in __devm_rtc_register_device()
403 err = __rtc_read_alarm(rtc, &alrm); in __devm_rtc_register_device()
405 rtc_initialize_alarm(rtc, &alrm); in __devm_rtc_register_device()
407 rtc_dev_prepare(rtc); in __devm_rtc_register_device()
409 err = cdev_device_add(&rtc->char_dev, &rtc->dev); in __devm_rtc_register_device()
411 set_bit(RTC_NO_CDEV, &rtc->flags); in __devm_rtc_register_device()
412 dev_warn(rtc->dev.parent, "failed to add char device %d:%d\n", in __devm_rtc_register_device()
413 MAJOR(rtc->dev.devt), rtc->id); in __devm_rtc_register_device()
415 dev_dbg(rtc->dev.parent, "char device (%d:%d)\n", in __devm_rtc_register_device()
416 MAJOR(rtc->dev.devt), rtc->id); in __devm_rtc_register_device()
419 rtc_proc_add_device(rtc); in __devm_rtc_register_device()
421 dev_info(rtc->dev.parent, "registered as %s\n", in __devm_rtc_register_device()
422 dev_name(&rtc->dev)); in __devm_rtc_register_device()
425 if (!strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE)) in __devm_rtc_register_device()
426 rtc_hctosys(rtc); in __devm_rtc_register_device()
429 return devm_add_action_or_reset(rtc->dev.parent, in __devm_rtc_register_device()
430 devm_rtc_unregister_device, rtc); in __devm_rtc_register_device()
453 struct rtc_device *rtc; in devm_rtc_device_register() local
456 rtc = devm_rtc_allocate_device(dev); in devm_rtc_device_register()
457 if (IS_ERR(rtc)) in devm_rtc_device_register()
458 return rtc; in devm_rtc_device_register()
460 rtc->ops = ops; in devm_rtc_device_register()
462 err = __devm_rtc_register_device(owner, rtc); in devm_rtc_device_register()
466 return rtc; in devm_rtc_device_register()