LCOV - code coverage report
Current view: top level - drivers/rtc - systohc.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 8 10 80.0 %
Date: 2014-02-18 Functions: 1 1 100.0 %
Branches: 4 10 40.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * This program is free software; you can redistribute it and/or modify it
       3                 :            :  * under the terms of the GNU General Public License version 2 as published by
       4                 :            :  * the Free Software Foundation.
       5                 :            :  *
       6                 :            :  */
       7                 :            : #include <linux/rtc.h>
       8                 :            : #include <linux/time.h>
       9                 :            : 
      10                 :            : /**
      11                 :            :  * rtc_set_ntp_time - Save NTP synchronized time to the RTC
      12                 :            :  * @now: Current time of day
      13                 :            :  *
      14                 :            :  * Replacement for the NTP platform function update_persistent_clock
      15                 :            :  * that stores time for later retrieval by rtc_hctosys.
      16                 :            :  *
      17                 :            :  * Returns 0 on successful RTC update, -ENODEV if a RTC update is not
      18                 :            :  * possible at all, and various other -errno for specific temporary failure
      19                 :            :  * cases.
      20                 :            :  *
      21                 :            :  * If temporary failure is indicated the caller should try again 'soon'
      22                 :            :  */
      23                 :          0 : int rtc_set_ntp_time(struct timespec now)
      24                 :            : {
      25                 :            :         struct rtc_device *rtc;
      26                 :            :         struct rtc_time tm;
      27                 :            :         int err = -ENODEV;
      28                 :            : 
      29         [ +  - ]:          1 :         if (now.tv_nsec < (NSEC_PER_SEC >> 1))
      30                 :          1 :                 rtc_time_to_tm(now.tv_sec, &tm);
      31                 :            :         else
      32                 :          0 :                 rtc_time_to_tm(now.tv_sec + 1, &tm);
      33                 :            : 
      34                 :          1 :         rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE);
      35         [ +  - ]:          1 :         if (rtc) {
      36                 :            :                 /* rtc_hctosys exclusively uses UTC, so we call set_time here,
      37                 :            :                  * not set_mmss. */
      38 [ +  - ][ -  + ]:          1 :                 if (rtc->ops && (rtc->ops->set_time || rtc->ops->set_mmss))
                 [ #  # ]
      39                 :          1 :                         err = rtc_set_time(rtc, &tm);
      40                 :          1 :                 rtc_class_close(rtc);
      41                 :            :         }
      42                 :            : 
      43                 :          1 :         return err;
      44                 :            : }

Generated by: LCOV version 1.9