• Home
  • Raw
  • Download

Lines Matching full:rtc

3  * RTC subsystem, base class
15 #include <linux/rtc.h>
21 #include "rtc-core.h"
28 struct rtc_device *rtc = to_rtc_device(dev); in rtc_device_release() local
29 struct timerqueue_head *head = &rtc->timerqueue; in rtc_device_release()
32 mutex_lock(&rtc->ops_lock); in rtc_device_release()
35 mutex_unlock(&rtc->ops_lock); in rtc_device_release()
37 cancel_work_sync(&rtc->irqwork); in rtc_device_release()
39 ida_simple_remove(&rtc_ida, rtc->id); in rtc_device_release()
40 kfree(rtc); in rtc_device_release()
44 /* Result of the last RTC to system clock attempt. */
47 /* IMPORTANT: the RTC only stores whole seconds. It is arbitrary
51 * in an rtc sync function, to read both xtime.tv_sec and
58 static void rtc_hctosys(struct rtc_device *rtc) in rtc_hctosys() argument
66 err = rtc_read_time(rtc, &tm); in rtc_hctosys()
68 dev_err(rtc->dev.parent, in rtc_hctosys()
84 dev_info(rtc->dev.parent, "setting system clock to %ptR UTC (%lld)\n", in rtc_hctosys()
94 * On suspend(), measure the delta between one RTC and the
102 struct rtc_device *rtc = to_rtc_device(dev); in rtc_suspend() local
110 if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0) in rtc_suspend()
113 /* snapshot the current RTC and system time at suspend*/ in rtc_suspend()
114 err = rtc_read_time(rtc, &tm); in rtc_suspend()
116 pr_debug("%s: fail to read rtc time\n", dev_name(&rtc->dev)); in rtc_suspend()
127 * and rtc time stays close to constant. in rtc_suspend()
147 struct rtc_device *rtc = to_rtc_device(dev); in rtc_resume() local
157 if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0) in rtc_resume()
160 /* snapshot the current rtc and system time at resume */ in rtc_resume()
162 err = rtc_read_time(rtc, &tm); in rtc_resume()
164 pr_debug("%s: fail to read rtc time\n", dev_name(&rtc->dev)); in rtc_resume()
172 pr_debug("%s: time travel!\n", dev_name(&rtc->dev)); in rtc_resume()
176 /* calculate the RTC time delta (sleep time)*/ in rtc_resume()
180 * Since these RTC suspend/resume handlers are not called in rtc_resume()
204 struct rtc_device *rtc; in rtc_allocate_device() local
206 rtc = kzalloc(sizeof(*rtc), GFP_KERNEL); in rtc_allocate_device()
207 if (!rtc) in rtc_allocate_device()
210 device_initialize(&rtc->dev); in rtc_allocate_device()
213 rtc->set_offset_nsec = NSEC_PER_SEC / 2; in rtc_allocate_device()
215 rtc->irq_freq = 1; in rtc_allocate_device()
216 rtc->max_user_freq = 64; in rtc_allocate_device()
217 rtc->dev.class = rtc_class; in rtc_allocate_device()
218 rtc->dev.groups = rtc_get_dev_attribute_groups(); in rtc_allocate_device()
219 rtc->dev.release = rtc_device_release; in rtc_allocate_device()
221 mutex_init(&rtc->ops_lock); in rtc_allocate_device()
222 spin_lock_init(&rtc->irq_lock); in rtc_allocate_device()
223 init_waitqueue_head(&rtc->irq_queue); in rtc_allocate_device()
226 timerqueue_init_head(&rtc->timerqueue); in rtc_allocate_device()
227 INIT_WORK(&rtc->irqwork, rtc_timer_do_work); in rtc_allocate_device()
229 rtc_timer_init(&rtc->aie_timer, rtc_aie_update_irq, rtc); in rtc_allocate_device()
231 rtc_timer_init(&rtc->uie_rtctimer, rtc_uie_update_irq, rtc); in rtc_allocate_device()
233 hrtimer_init(&rtc->pie_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); in rtc_allocate_device()
234 rtc->pie_timer.function = rtc_pie_update_irq; in rtc_allocate_device()
235 rtc->pie_enabled = 0; in rtc_allocate_device()
237 return rtc; in rtc_allocate_device()
245 of_id = of_alias_get_id(dev->of_node, "rtc"); in rtc_device_get_id()
247 of_id = of_alias_get_id(dev->parent->of_node, "rtc"); in rtc_device_get_id()
261 static void rtc_device_get_offset(struct rtc_device *rtc) in rtc_device_get_offset() argument
268 * If RTC driver did not implement the range of RTC hardware device, in rtc_device_get_offset()
269 * then we can not expand the RTC range by adding or subtracting one in rtc_device_get_offset()
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()
283 * If user did not implement the start time for RTC driver, then no in rtc_device_get_offset()
284 * need to expand the RTC range. 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()
292 * If the start_secs is larger than the maximum seconds (rtc->range_max) in rtc_device_get_offset()
293 * supported by RTC hardware or the maximum seconds of new expanded in rtc_device_get_offset()
294 * range (start_secs + rtc->range_max - rtc->range_min) is less than in rtc_device_get_offset()
295 * rtc->range_min, which means the minimum seconds (rtc->range_min) of in rtc_device_get_offset()
296 * RTC hardware will be mapped to start_secs by adding one offset, so in rtc_device_get_offset()
298 * rtc->offset_secs = rtc->start_secs - rtc->range_min; in rtc_device_get_offset()
300 * If the start_secs is larger than the minimum seconds (rtc->range_min) in rtc_device_get_offset()
301 * supported by RTC hardware, then there is one region is overlapped in rtc_device_get_offset()
302 * between the original RTC hardware range and the new expanded range, in rtc_device_get_offset()
304 * expanded range due to it is valid for RTC device. So the minimum in rtc_device_get_offset()
305 * seconds of RTC hardware (rtc->range_min) should be mapped to in rtc_device_get_offset()
306 * rtc->range_max + 1, then the offset seconds formula should be: in rtc_device_get_offset()
307 * rtc->offset_secs = rtc->range_max - rtc->range_min + 1; in rtc_device_get_offset()
309 * If the start_secs is less than the minimum seconds (rtc->range_min), in rtc_device_get_offset()
311 * start_secs + rtc->range_max - rtc->range_min + 1, then the in rtc_device_get_offset()
313 * rtc->offset_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()
329 * rtc_device_unregister - removes the previously registered RTC class device
331 * @rtc: the RTC class device to destroy
333 static void rtc_device_unregister(struct rtc_device *rtc) in rtc_device_unregister() argument
335 mutex_lock(&rtc->ops_lock); in rtc_device_unregister()
337 * Remove innards of this RTC, then disable it, before in rtc_device_unregister()
340 rtc_proc_del_device(rtc); in rtc_device_unregister()
341 cdev_device_del(&rtc->char_dev, &rtc->dev); in rtc_device_unregister()
342 rtc->ops = NULL; in rtc_device_unregister()
343 mutex_unlock(&rtc->ops_lock); in rtc_device_unregister()
344 put_device(&rtc->dev); in rtc_device_unregister()
349 struct rtc_device *rtc = *(struct rtc_device **)res; in devm_rtc_release_device() local
351 rtc_nvmem_unregister(rtc); in devm_rtc_release_device()
353 if (rtc->registered) in devm_rtc_release_device()
354 rtc_device_unregister(rtc); in devm_rtc_release_device()
356 put_device(&rtc->dev); in devm_rtc_release_device()
361 struct rtc_device **ptr, *rtc; in devm_rtc_allocate_device() local
374 rtc = rtc_allocate_device(); in devm_rtc_allocate_device()
375 if (!rtc) { in devm_rtc_allocate_device()
380 *ptr = rtc; in devm_rtc_allocate_device()
383 rtc->id = id; in devm_rtc_allocate_device()
384 rtc->dev.parent = dev; in devm_rtc_allocate_device()
385 dev_set_name(&rtc->dev, "rtc%d", id); in devm_rtc_allocate_device()
387 return rtc; in devm_rtc_allocate_device()
397 int __rtc_register_device(struct module *owner, struct rtc_device *rtc) in __rtc_register_device() argument
402 if (!rtc->ops) { in __rtc_register_device()
403 dev_dbg(&rtc->dev, "no ops set\n"); in __rtc_register_device()
407 rtc->owner = owner; in __rtc_register_device()
408 rtc_device_get_offset(rtc); in __rtc_register_device()
411 err = __rtc_read_alarm(rtc, &alrm); in __rtc_register_device()
413 rtc_initialize_alarm(rtc, &alrm); in __rtc_register_device()
415 rtc_dev_prepare(rtc); in __rtc_register_device()
417 err = cdev_device_add(&rtc->char_dev, &rtc->dev); in __rtc_register_device()
419 dev_warn(rtc->dev.parent, "failed to add char device %d:%d\n", in __rtc_register_device()
420 MAJOR(rtc->dev.devt), rtc->id); in __rtc_register_device()
422 dev_dbg(rtc->dev.parent, "char device (%d:%d)\n", in __rtc_register_device()
423 MAJOR(rtc->dev.devt), rtc->id); in __rtc_register_device()
425 rtc_proc_add_device(rtc); in __rtc_register_device()
427 rtc->registered = true; in __rtc_register_device()
428 dev_info(rtc->dev.parent, "registered as %s\n", in __rtc_register_device()
429 dev_name(&rtc->dev)); in __rtc_register_device()
432 if (!strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE)) in __rtc_register_device()
433 rtc_hctosys(rtc); in __rtc_register_device()
444 * @ops: the rtc operations structure
447 * @return a struct rtc on success, or an ERR_PTR on error
459 struct rtc_device *rtc; in devm_rtc_device_register() local
462 rtc = devm_rtc_allocate_device(dev); in devm_rtc_device_register()
463 if (IS_ERR(rtc)) in devm_rtc_device_register()
464 return rtc; in devm_rtc_device_register()
466 rtc->ops = ops; in devm_rtc_device_register()
468 err = __rtc_register_device(owner, rtc); in devm_rtc_device_register()
472 return rtc; in devm_rtc_device_register()
478 rtc_class = class_create(THIS_MODULE, "rtc"); in rtc_init()