Lines Matching refs:rtc

15 #include <linux/rtc.h>
21 #include "rtc-core.h"
28 struct rtc_device *rtc = to_rtc_device(dev);
29 struct timerqueue_head *head = &rtc->timerqueue;
32 mutex_lock(&rtc->ops_lock);
35 mutex_unlock(&rtc->ops_lock);
37 cancel_work_sync(&rtc->irqwork);
39 ida_free(&rtc_ida, rtc->id);
40 mutex_destroy(&rtc->ops_lock);
41 kfree(rtc);
52 * in an rtc sync function, to read both xtime.tv_sec and
59 static void rtc_hctosys(struct rtc_device *rtc)
67 err = rtc_read_time(rtc, &tm);
69 dev_err(rtc->dev.parent,
85 dev_info(rtc->dev.parent, "setting system clock to %ptR UTC (%lld)\n",
103 struct rtc_device *rtc = to_rtc_device(dev);
111 if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0)
115 err = rtc_read_time(rtc, &tm);
117 pr_debug("%s: fail to read rtc time\n", dev_name(&rtc->dev));
128 * and rtc time stays close to constant.
148 struct rtc_device *rtc = to_rtc_device(dev);
158 if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0)
161 /* snapshot the current rtc and system time at resume */
163 err = rtc_read_time(rtc, &tm);
165 pr_debug("%s: fail to read rtc time\n", dev_name(&rtc->dev));
173 pr_debug("%s: time travel!\n", dev_name(&rtc->dev));
205 struct rtc_device *rtc;
207 rtc = kzalloc(sizeof(*rtc), GFP_KERNEL);
208 if (!rtc)
211 device_initialize(&rtc->dev);
219 rtc->set_offset_nsec = NSEC_PER_SEC + 5 * NSEC_PER_MSEC;
221 rtc->irq_freq = 1;
222 rtc->max_user_freq = 64;
223 rtc->dev.class = rtc_class;
224 rtc->dev.groups = rtc_get_dev_attribute_groups();
225 rtc->dev.release = rtc_device_release;
227 mutex_init(&rtc->ops_lock);
228 spin_lock_init(&rtc->irq_lock);
229 init_waitqueue_head(&rtc->irq_queue);
232 timerqueue_init_head(&rtc->timerqueue);
233 INIT_WORK(&rtc->irqwork, rtc_timer_do_work);
235 rtc_timer_init(&rtc->aie_timer, rtc_aie_update_irq, rtc);
237 rtc_timer_init(&rtc->uie_rtctimer, rtc_uie_update_irq, rtc);
239 hrtimer_init(&rtc->pie_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
240 rtc->pie_timer.function = rtc_pie_update_irq;
241 rtc->pie_enabled = 0;
243 set_bit(RTC_FEATURE_ALARM, rtc->features);
244 set_bit(RTC_FEATURE_UPDATE_INTERRUPT, rtc->features);
246 return rtc;
254 of_id = of_alias_get_id(dev->of_node, "rtc");
256 of_id = of_alias_get_id(dev->parent->of_node, "rtc");
270 static void rtc_device_get_offset(struct rtc_device *rtc)
281 if (rtc->range_min == rtc->range_max)
284 ret = device_property_read_u32(rtc->dev.parent, "start-year",
287 rtc->start_secs = mktime64(start_year, 1, 1, 0, 0, 0);
288 rtc->set_start_time = true;
295 if (!rtc->set_start_time)
298 range_secs = rtc->range_max - rtc->range_min + 1;
301 * If the start_secs is larger than the maximum seconds (rtc->range_max)
303 * range (start_secs + rtc->range_max - rtc->range_min) is less than
304 * rtc->range_min, which means the minimum seconds (rtc->range_min) of
307 * rtc->offset_secs = rtc->start_secs - rtc->range_min;
309 * If the start_secs is larger than the minimum seconds (rtc->range_min)
314 * seconds of RTC hardware (rtc->range_min) should be mapped to
315 * rtc->range_max + 1, then the offset seconds formula should be:
316 * rtc->offset_secs = rtc->range_max - rtc->range_min + 1;
318 * If the start_secs is less than the minimum seconds (rtc->range_min),
320 * start_secs + rtc->range_max - rtc->range_min + 1, then the
322 * rtc->offset_secs = -(rtc->range_max - rtc->range_min + 1);
326 if (rtc->start_secs > rtc->range_max ||
327 rtc->start_secs + range_secs - 1 < rtc->range_min)
328 rtc->offset_secs = rtc->start_secs - rtc->range_min;
329 else if (rtc->start_secs > rtc->range_min)
330 rtc->offset_secs = range_secs;
331 else if (rtc->start_secs < rtc->range_min)
332 rtc->offset_secs = -range_secs;
334 rtc->offset_secs = 0;
339 struct rtc_device *rtc = data;
341 mutex_lock(&rtc->ops_lock);
346 rtc_proc_del_device(rtc);
347 if (!test_bit(RTC_NO_CDEV, &rtc->flags))
348 cdev_device_del(&rtc->char_dev, &rtc->dev);
349 rtc->ops = NULL;
350 mutex_unlock(&rtc->ops_lock);
355 struct rtc_device *rtc = res;
357 put_device(&rtc->dev);
362 struct rtc_device *rtc;
369 rtc = rtc_allocate_device();
370 if (!rtc) {
375 rtc->id = id;
376 rtc->dev.parent = dev;
377 err = devm_add_action_or_reset(dev, devm_rtc_release_device, rtc);
381 err = dev_set_name(&rtc->dev, "rtc%d", id);
385 return rtc;
389 int __devm_rtc_register_device(struct module *owner, struct rtc_device *rtc)
394 if (!rtc->ops) {
395 dev_dbg(&rtc->dev, "no ops set\n");
399 if (!rtc->ops->set_alarm)
400 clear_bit(RTC_FEATURE_ALARM, rtc->features);
402 if (rtc->ops->set_offset)
403 set_bit(RTC_FEATURE_CORRECTION, rtc->features);
405 rtc->owner = owner;
406 rtc_device_get_offset(rtc);
409 err = __rtc_read_alarm(rtc, &alrm);
411 rtc_initialize_alarm(rtc, &alrm);
413 rtc_dev_prepare(rtc);
415 err = cdev_device_add(&rtc->char_dev, &rtc->dev);
417 set_bit(RTC_NO_CDEV, &rtc->flags);
418 dev_warn(rtc->dev.parent, "failed to add char device %d:%d\n",
419 MAJOR(rtc->dev.devt), rtc->id);
421 dev_dbg(rtc->dev.parent, "char device (%d:%d)\n",
422 MAJOR(rtc->dev.devt), rtc->id);
425 rtc_proc_add_device(rtc);
427 dev_info(rtc->dev.parent, "registered as %s\n",
428 dev_name(&rtc->dev));
431 if (!strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE))
432 rtc_hctosys(rtc);
435 return devm_add_action_or_reset(rtc->dev.parent,
436 devm_rtc_unregister_device, rtc);
444 * @ops: the rtc operations structure
447 * @return a struct rtc on success, or an ERR_PTR on error
459 struct rtc_device *rtc;
462 rtc = devm_rtc_allocate_device(dev);
463 if (IS_ERR(rtc))
464 return rtc;
466 rtc->ops = ops;
468 err = __devm_rtc_register_device(owner, rtc);
472 return rtc;
478 rtc_class = class_create("rtc");