09 May, 2019

1 commit


04 Apr, 2019

2 commits


18 Mar, 2019

1 commit


19 Dec, 2018

1 commit


11 Dec, 2018

1 commit

  • Use %ptR instead of open coded variant to print content of
    struct rtc_time in human readable format.

    Note, we drop the validation option. This is only used in
    a deprecated ABI and is mostly wrong as many RTCs will still be valid
    after 2100.

    Cc: Arnd Bergmann
    Acked-by: Greg Kroah-Hartman
    Signed-off-by: Andy Shevchenko
    Signed-off-by: Alexandre Belloni

    Andy Shevchenko
     

13 Sep, 2018

1 commit

  • Stale mentions of irq_task are left in the kerneldoc after its removal.
    Remove them.

    There is still one indirect mention left but commit 3c8bb90efb6e ("rtc: Fix
    hrtimer deadlock") can probably be reverted now.

    Reported-by: Linus Torvalds
    Signed-off-by: Alexandre Belloni

    Alexandre Belloni
     

21 Aug, 2018

1 commit

  • Pull RTC updates from Alexandre Belloni:
    "It is now possible to add custom sysfs attributes while avoiding a
    possible race condition. Unused code has been removed resulting in a
    nice reduction of the code base. And more drivers have been switched
    to SPDX by their maintainers.

    Summary:

    Subsystem:
    - new helpers to add custom sysfs attributes
    - struct rtc_task removal along with rtc_irq_[un]register()
    - rtc_irq_set_state and rtc_irq_set_freq are not exported anymore

    Drivers:
    - armada38x: reset after rtc power loss
    - ds1307: now supports m41t11
    - isl1208: now supports isl1219 and tamper detection
    - pcf2127: internal SRAM support"

    * tag 'rtc-4.19' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: (34 commits)
    rtc: ds1307: simplify hwmon config
    rtc: s5m: Add SPDX license identifier
    rtc: maxim: Add SPDX license identifiers
    rtc: isl1219: add device tree documentation
    rtc: isl1208: set ev-evienb bit from device tree
    rtc: isl1208: Add "evdet" interrupt source for isl1219
    rtc: isl1208: add support for isl1219 with tamper detection
    rtc: sysfs: facilitate attribute add to rtc device
    rtc: remove struct rtc_task
    char: rtc: remove task handling
    rtc: pcf85063: preserve control register value between stop and start
    rtc: sh: remove unused variable rtc_dev
    rtc: unexport rtc_irq_set_*
    rtc: simplify rtc_irq_set_state/rtc_irq_set_freq
    rtc: remove irq_task and irq_task_lock
    rtc: remove rtc_irq_register/rtc_irq_unregister
    rtc: sh: remove dead code
    rtc: sa1100: don't set PIE frequency
    rtc: ds1307: support m41t11 variant
    rtc: ds1307: fix data pointer to m41t0
    ...

    Linus Torvalds
     

02 Aug, 2018

1 commit


26 Jul, 2018

4 commits


13 Jul, 2018

1 commit


08 Jun, 2018

1 commit

  • When using RTC_ALM_SET or RTC_WKALM_SET with rtc_wkalrm.enabled not set,
    rtc_timer_enqueue() is not called and rtc_set_alarm() may succeed but the
    subsequent RTC_AIE_ON ioctl will fail. RTC_ALM_READ would also fail in that
    case.

    Ensure rtc_set_alarm() fails when alarms are not supported to avoid letting
    programs think the alarms are working for a particular RTC when they are
    not.

    Signed-off-by: Alexandre Belloni

    Alexandre Belloni
     

17 Mar, 2018

3 commits

  • From our investigation for all RTC drivers, 1 driver will be expired before
    year 2017, 7 drivers will be expired before year 2038, 23 drivers will be
    expired before year 2069, 72 drivers will be expired before 2100 and 104
    drivers will be expired before 2106. Especially for these early expired
    drivers, we need to expand the RTC range to make the RTC can still work
    after the expired year.

    So we can expand the RTC range by adding one offset to the time when reading
    from hardware, and subtracting it when writing back. For example, if you have
    an RTC that can do 100 years, and currently is configured to be based in
    Jan 1 1970, so it can represents times from 1970 to 2069. Then if you change
    the start year from 1970 to 2000, which means it can represents times from
    2000 to 2099. By adding or subtracting the offset produced by moving the wrap
    point, all times between 1970 and 1999 from RTC hardware could get interpreted
    as times from 2070 to 2099, but the interpretation of dates between 2000 and
    2069 would not change.

    Signed-off-by: Baolin Wang
    Signed-off-by: Alexandre Belloni

    Baolin Wang
     
  • The RTC range validation code can be factored into rtc_valid_range()
    function to avoid duplicate code.

    Signed-off-by: Baolin Wang
    Signed-off-by: Alexandre Belloni

    Baolin Wang
     
  • Add a way for drivers to inform the core of the supported date/time range.
    The core can then check whether the date/time or alarm is in the range
    before calling ->set_time, ->set_mmss or ->set_alarm. It returns -ERANGE
    when the time is out of range.

    Signed-off-by: Alexandre Belloni

    Alexandre Belloni
     

14 Feb, 2018

1 commit

  • It will be more helpful to add some tracepoints to track RTC actions when
    debugging RTC driver. Below sample is that we set/read the RTC time, then
    set 2 alarms, so we can see the trace logs:

    set/read RTC time:
    kworker/0:1-67 [000] 21.814245: rtc_set_time: UTC (1510301580) (0)
    kworker/0:1-67 [000] 21.814312: rtc_read_time: UTC (1510301580) (0)

    set the first alarm timer:
    kworker/0:1-67 [000] 21.829238: rtc_timer_enqueue: RTC timer:(ffffffc15eb49bc8) expires:1510301700000000000 period:0
    kworker/0:1-67 [000] 22.018279: rtc_set_alarm: UTC (1510301700) (0)

    set the second alarm timer:
    kworker/0:1-67 [000] 22.230284: rtc_timer_enqueue: RTC timer:(ffffff80088e6430) expires:1510301820000000000 period:0

    the first alarm timer was expired:
    kworker/0:1-67 [000] 145.155584: rtc_timer_dequeue: RTC timer:(ffffffc15eb49bc8) expires:1510301700000000000 period:0
    kworker/0:1-67 [000] 145.155593: rtc_timer_fired: RTC timer:(ffffffc15eb49bc8) expires:1510301700000000000 period:0
    kworker/0:1-67 [000] 145.172504: rtc_set_alarm: UTC (1510301820) (0)

    the second alarm timer was expired:
    kworker/0:1-67 [000] 269.102353: rtc_timer_dequeue: RTC timer:(ffffff80088e6430) expires:1510301820000000000 period:0
    kworker/0:1-67 [000] 269.102360: rtc_timer_fired: RTC timer:(ffffff80088e6430) expires:1510301820000000000 period:0

    disable alarm irq:
    kworker/0:1-67 [000] 269.102469: rtc_alarm_irq_enable: disable RTC alarm IRQ (0)

    Signed-off-by: Baolin Wang
    Signed-off-by: Alexandre Belloni

    Baolin Wang
     

26 Oct, 2017

1 commit

  • The RTC offset correction documentation is not very clear about the
    exact relationship between "offset" and the effect it has on the RTC.
    Supplement the documentation with an equation giving the relationship.

    Signed-off-by: Russell King
    Signed-off-by: Alexandre Belloni

    Russell King
     

28 Sep, 2017

1 commit

  • If there is any non expired timer in the queue, the RTC alarm is never set.
    This is an issue when adding a timer that expires before the next non
    expired timer.

    Ensure the RTC alarm is set in that case.

    Fixes: 2b2f5ff00f63 ("rtc: interface: ignore expired timers when enqueuing new timers")
    Signed-off-by: Alexandre Belloni

    Alexandre Belloni
     

31 May, 2017

1 commit

  • In function __rtc_read_alarm() its possible for an alarm time-stamp to
    be invalid even after replacing missing components with current
    time-stamp. The condition 'alarm->time.tm_year < 70' will trigger this
    case and will cause the call to 'rtc_tm_to_time64(&alarm->time)'
    return a negative value for variable t_alm.

    While handling alarm rollover this negative t_alm (assumed to seconds
    offset from '1970-01-01 00:00:00') is converted back to rtc_time via
    rtc_time64_to_tm() which results in this error log with seemingly
    garbage values:

    "rtc rtc0: invalid alarm value: -2-1--1041528741
    2005511117:71582844:32"

    This error was generated when the rtc driver (rtc-opal in this case)
    returned an alarm time-stamp of '00-00-00 00:00:00' to indicate that
    the alarm is disabled. Though I have submitted a separate fix for the
    rtc-opal driver, this issue may potentially impact other
    existing/future rtc drivers.

    To fix this issue the patch validates the alarm time-stamp just after
    filling up the missing datetime components and if rtc_valid_tm() still
    reports it to be invalid then bails out of the function without
    handling the rollover.

    Reported-by: Steve Best
    Signed-off-by: Vaibhav Jain
    Signed-off-by: Alexandre Belloni

    Vaibhav Jain
     

26 Dec, 2016

2 commits

  • ktime_set(S,N) was required for the timespec storage type and is still
    useful for situations where a Seconds and Nanoseconds part of a time value
    needs to be converted. For anything where the Seconds argument is 0, this
    is pointless and can be replaced with a simple assignment.

    Signed-off-by: Thomas Gleixner
    Cc: Peter Zijlstra

    Thomas Gleixner
     
  • ktime is a union because the initial implementation stored the time in
    scalar nanoseconds on 64 bit machine and in a endianess optimized timespec
    variant for 32bit machines. The Y2038 cleanup removed the timespec variant
    and switched everything to scalar nanoseconds. The union remained, but
    become completely pointless.

    Get rid of the union and just keep ktime_t as simple typedef of type s64.

    The conversion was done with coccinelle and some manual mopping up.

    Signed-off-by: Thomas Gleixner
    Cc: Peter Zijlstra

    Thomas Gleixner
     

12 Jul, 2016

1 commit


04 Jun, 2016

1 commit

  • This patch fixes a RTC wakealarm issue, namely, the event fires during
    hibernate and is not cleared from the list, causing hwclock to block.

    The current enqueuing does not trigger an alarm if any expired timers
    already exist on the timerqueue. This can occur when a RTC wake alarm
    is used to wake a machine out of hibernate and the resumed state has
    old expired timers that have not been removed from the timer queue.
    This fix skips over any expired timers and triggers an alarm if there
    are no pending timers on the timerqueue. Note that the skipped expired
    timer will get reaped later on, so there is no need to clean it up
    immediately.

    The issue can be reproduced by putting a machine into hibernate and
    waking it with the RTC wakealarm. Running the example RTC test program
    from tools/testing/selftests/timers/rtctest.c after the hibernate will
    block indefinitely. With the fix, it no longer blocks after the
    hibernate resume.

    BugLink: http://bugs.launchpad.net/bugs/1333569

    Signed-off-by: Colin Ian King
    Signed-off-by: Alexandre Belloni

    Colin Ian King
     

30 May, 2016

1 commit


15 Mar, 2016

1 commit

  • A number of rtc devices, such as the NXP pcf2123 include a facility
    to adjust the clock in order to compensate for temperature or a
    crystal, capacitor, etc, that results in the rtc clock not running
    at exactly 32.768 kHz.

    Data sheets I have seen refer to this as a clock offset, and measure it
    in parts per million, however they often reference ppm to 2 digits of
    precision, which makes integer ppm less than ideal.

    We use parts per billion, which more than covers the precision needed
    and works nicely within 32 bits

    Signed-off-by: Joshua Clayton
    Signed-off-by: Alexandre Belloni

    Joshua Clayton
     

05 Sep, 2015

1 commit

  • IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there
    is no need to do that again from its callers. Drop it.

    gemini driver was using likely() for a failure case while the rtc driver
    is getting registered. That looks wrong and it should really be
    unlikely. But because we are killing all the unlikely() flags, lets kill
    that too.

    Signed-off-by: Viresh Kumar
    Acked-by: Hans Ulli Kroll
    Signed-off-by: Alexandre Belloni

    viresh kumar
     

25 Jun, 2015

1 commit


20 Jun, 2015

1 commit


17 Apr, 2015

1 commit

  • __rtc_read_time logs should be debug logs instead of error logs.

    For example, when the RTC clock is not set, it's not really useful
    to print a kernel error log every time someone tries to read the clock:

    ~ # hwclock -r
    [ 604.508263] rtc rtc0: read_time: fail to read
    hwclock: RTC_RD_TIME: Invalid argument

    If there's a real error, it's likely that lower level or higher level
    code will tell it anyway. Make these logs debug logs, and also print
    the error code for the read failure.

    Signed-off-by: Aaro Koskinen
    Acked-by: Alexandre Belloni
    Cc: Alessandro Zummo
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Aaro Koskinen
     

03 Apr, 2015

1 commit

  • Currently the rtc_class_op's set_mmss() function takes a 32-bit
    second value (on 32-bit systems), which is problematic for dates
    past y2038.

    This patch provides a safe version named set_mmss64() using
    y2038 safe time64_t.

    After this patch, set_mmss() is deprecated and all its users
    will be fixed to use set_mmss64(), it can be removed when having
    no users.

    Signed-off-by: Xunlei Pang
    [jstultz: Add whitespace fix for checkpatch]
    Signed-off-by: John Stultz
    Acked-by: Alessandro Zummo
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Link: http://lkml.kernel.org/r/1427945681-29972-8-git-send-email-john.stultz@linaro.org
    Signed-off-by: Ingo Molnar

    Xunlei Pang
     

24 Jan, 2015

1 commit

  • Currently, interface.c uses y2038 problematic rtc_tm_to_time()
    and rtc_time_to_tm(). So replace them with their corresponding
    y2038-safe versions: rtc_tm_to_time64() and rtc_time64_to_tm().

    Cc: pang.xunlei
    Cc: Arnd Bergmann
    Cc: Thomas Gleixner
    Cc: Ingo Molnar
    Signed-off-by: Xunlei Pang
    Signed-off-by: John Stultz

    Xunlei Pang
     

11 Dec, 2014

2 commits

  • rtc_timer_do_work() only judges -ETIME failure of__rtc_set_alarm(), but
    doesn't handle other failures like -EIO, -EBUSY, etc.

    If there is a failure other than -ETIME, the next rtc_timer will stay in
    the timerqueue. Then later rtc_timers will be enqueued directly because
    they have a later expires time, so the alarm irq will never be programmed.

    When such failures happen, this patch will retry __rtc_set_alarm(), if
    still can't program the alarm time, it will remove current rtc_timer from
    timerqueue and fetch next one, thus preventing it from affecting other rtc
    timers.

    Signed-off-by: Xunlei Pang
    Cc: Alessandro Zummo
    Cc: John Stultz
    Cc: Arnd Bergmann
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Xunlei Pang
     
  • Some rtc devices always return '0' when rtc_class_ops.read_time is
    called. So if rtc_time isn't verified in callback, rtc interface cannot
    know whether rtc_time is valid.

    Check rtc_time by using 'rtc_valid_tm' in '__rtc_read_time'. And add
    the message for debugging.

    Signed-off-by: Hyogi Gim
    Cc: Alessandro Zummo
    Cc: John Stultz
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Hyogi Gim
     

09 Aug, 2014

1 commit


07 Jun, 2014

1 commit

  • In __rtc_read_alarm(), if the alarm time retrieved by
    rtc_read_alarm_internal() from the device contains invalid values (e.g.
    month=2,mday=31) and the year not set (=-1), the initialization will
    loop infinitely because the year-fixing loop expects the time being
    invalid due to leap year.

    Fix reduces the loop to the leap years and adds final validity check.

    Signed-off-by: Ales Novak
    Acked-by: Alessandro Zummo
    Reported-by: Jiri Bohac
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Ales Novak
     

04 Apr, 2014

1 commit


23 Jul, 2013

1 commit

  • Current implementation of RTC interface allows for system suspend to
    occur in the following cases:
    (a) if a timer is set in the past and rtc_timer_do_work() is scheduled
    to handle it, and
    (b) if rtc_timer_do_work() is called to handle expired timers whose
    handlers implement a preemption point.

    A pending suspend request may be honoured in the above cases causing
    timer handling to be delayed until after the next resume. This is
    undesirable since timer handlers may have time-critical code to execute.

    This patch makes sure that the system stays awake until all expired
    timers are handled.

    Note that all calls to pm_stay_awake() are eventually paired with
    the single pm_relax() call in rtc_timer_do_work(), which is launched
    using schedule_work().

    Cc: Alessandro Zummo
    Cc: John Stultz
    Cc: Arve Hjonnevag
    Cc: Todd Poynor
    Signed-off-by: Zoran Markovic
    Signed-off-by: John Stultz

    Zoran Markovic