summaryrefslogtreecommitdiff
path: root/include/linux/rtc.h
AgeCommit message (Collapse)AuthorFilesLines
2021-01-17rtc: introduce features bitfieldAlexandre Belloni1-0/+2
Introduce a bitfield to allow the drivers to announce the available features for an RTC. The main use case would be to better handle alarms, that could be present or not or have a minute resolution or may need a correct week day to be set. Use the newly introduced RTC_FEATURE_ALARM bit to then test whether alarms are available instead of relying on the presence of ops->set_alarm. Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Link: https://lore.kernel.org/r/20210110231752.1418816-2-alexandre.belloni@bootlin.com
2020-12-20Merge tag 'rtc-5.11' of ↵Linus Torvalds1-15/+7
git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux Pull RTC updates from Alexandre Belloni: "Subsystem: - Remove nvram ABI. There was no complaints about the deprecation for the last 3 years. - Improve RTC device allocation and registration - Now available for ARCH=um Drivers: - at91rm9200: correction and sam9x60 support - ds1307: improve ACPI support - mxc: now DT only - pcf2127: watchdog support now needs the reset-source property - pcf8523: set range - rx6110: i2c support" * tag 'rtc-5.11' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: (43 commits) rtc: pcf2127: only use watchdog when explicitly available dt-bindings: rtc: add reset-source property rtc: fix RTC removal rtc: s3c: Remove dead code related to periodic tick handling rtc: s3c: Disable all enable (RTC, tick) bits in the probe rtc: ep93xx: Fix NULL pointer dereference in ep93xx_rtc_read_time rtc: test: remove debug message rtc: mxc{,_v2}: enable COMPILE_TEST rtc: enable RTC framework on ARCH=um rtc: pcf8523: use BIT rtc: pcf8523: set range rtc: pcf8523: switch to devm_rtc_allocate_device rtc: destroy mutex when releasing the device rtc: shrink devm_rtc_allocate_device() rtc: rework rtc_register_device() resource management rtc: nvmem: emit an error message when nvmem registration fails rtc: add devm_ prefix to rtc_nvmem_register() rtc: nvmem: remove nvram ABI Documentation: list RTC devres helpers in devres.rst rtc: omap: use devm_pinctrl_register() ...
2020-12-11ntp: Make the RTC sync offset less obscureThomas Gleixner1-6/+29
The current RTC set_offset_nsec value is not really intuitive to understand. tsched twrite(t2.tv_sec - 1) t2 (seconds increment) The offset is calculated from twrite based on the assumption that t2 - twrite == 1s. That means for the MC146818 RTC the offset needs to be negative so that the write happens 500ms before t2. It's easier to understand when the whole calculation is based on t2. That avoids negative offsets and the meaning is obvious: t2 - twrite: The time defined by the chip when seconds increment after the write. twrite - tsched: The time for the transport to the point where the chip is updated. ==> set_offset_nsec = t2 - tsched ttransport = twrite - tsched tRTCinc = t2 - twrite ==> set_offset_nsec = ttransport + tRTCinc tRTCinc is a chip property and can be obtained from the data sheet. ttransport depends on how the RTC is connected. It is close to 0 for directly accessible RTCs. For RTCs behind a slow bus, e.g. i2c, it's the time required to send the update over the bus. This can be estimated or even calibrated, but that's a different problem. Adjust the implementation and update comments accordingly. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Link: https://lore.kernel.org/r/20201206220542.263204937@linutronix.de
2020-12-11ntp, rtc: Move rtc_set_ntp_time() to ntp codeThomas Gleixner1-34/+0
rtc_set_ntp_time() is not really RTC functionality as the code is just a user of RTC. Move it into the NTP code which allows further cleanups. Requested-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Link: https://lore.kernel.org/r/20201206220542.166871172@linutronix.de
2020-11-19rtc: rework rtc_register_device() resource managementBartosz Golaszewski1-5/+3
rtc_register_device() is a managed interface but it doesn't use devres by itself - instead it marks an rtc_device as "registered" and the devres callback for devm_rtc_allocate_device() takes care of resource release. This doesn't correspond with the design behind devres where managed structures should not be aware of being managed. The correct solution here is to register a separate devres callback for unregistering the device. While at it: rename rtc_register_device() to devm_rtc_register_device() and add it to the list of managed interfaces in devres.rst. This way we can avoid any potential confusion of driver developers who may expect there to exist a corresponding unregister function. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Link: https://lore.kernel.org/r/20201109163409.24301-8-brgl@bgdev.pl
2020-11-19rtc: add devm_ prefix to rtc_nvmem_register()Bartosz Golaszewski1-4/+4
rtc_nvmem_register() is a managed interface. It doesn't require any release function to be called at driver detach. To avoid confusing driver authors, let's rename it to devm_rtc_nvmem_register() and add it to the list of managed interfaces in Documentation/. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Link: https://lore.kernel.org/r/20201109163409.24301-6-brgl@bgdev.pl
2020-11-19rtc: nvmem: remove nvram ABIAlexandre Belloni1-6/+0
The nvram sysfs attributes have been deprecated at least since v4.13, more than 3 years ago and nobody ever complained about the deprecation warning. Remove the sysfs attributes now. [Bartosz: remove the declaration of rtc_nvmem_unregister()] Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Link: https://lore.kernel.org/r/20201109163409.24301-5-brgl@bgdev.pl
2020-07-16rtc: cleanup obsolete comment about struct rtc_class_opsMisono Tomohiro1-4/+0
Commit ea369ea6d828 ("rtc: remove .open() and .release()") removes open/release callback from struct rtc_class_ops. Also commit 80d4bb515b78 ("RTC: Cleanup rtc_class_ops->irq_set_state") and commit 696160fec162 ("RTC: Cleanup rtc_class_ops->irq_set_freq()") removes irq callbacks. So, just remove related comments so that readers will not be confused. Signed-off-by: Misono Tomohiro <misono.tomohiro@jp.fujitsu.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Link: https://lore.kernel.org/r/20200710080003.7986-1-misono.tomohiro@jp.fujitsu.com
2020-04-02rtc: remove rtc_time_to_tm and rtc_tm_to_timeAlexandre Belloni1-12/+0
There are no callers of the 32bit versions of rtc_time conversion functions, drop them. Link: https://lore.kernel.org/r/20200330201510.861217-1-alexandre.belloni@bootlin.com Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2019-12-18rtc: rv3029: let the core handle rtc rangeAlexandre Belloni1-0/+1
Despite the comment, the RV3029 uses a 7bit BCD register for the year, making 2079 the last supported year. Link: https://lore.kernel.org/r/20191214221022.622482-14-alexandre.belloni@bootlin.com Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2019-10-19rtc: introduce lock helpersAlexandre Belloni1-0/+3
Introduce rtc_lock and rtc_unlock to shorten the code when locking and unlocking ops_lock from drivers. Link: https://lore.kernel.org/r/20191019205034.6382-1-alexandre.belloni@bootlin.com Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2019-10-19rtc: add timestamp for end of 2199Alexandre Belloni1-0/+1
Some RTCs handle date up to 2199. Link: https://lore.kernel.org/r/20191016201626.31309-1-alexandre.belloni@bootlin.com Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2019-10-07rtc: add a timestamp for year 0Alexandre Belloni1-0/+1
A few RTCs handle dates from year 0 to year 9999. Add a timestamp even if years before 1970 will probably never be used. Link: https://lore.kernel.org/r/20191007134724.15505-1-alexandre.belloni@bootlin.com Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2019-05-08rtc: drop set_mms and set_mmss64Alexandre Belloni1-2/+0
There are no users of set_mms and set_mmss64 as they have all been converted to set_time and are handling the tm to time conversion on their own. Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2019-04-04rtc: Fix timestamp value for RTC_TIMESTAMP_BEGIN_1900Geert Uytterhoeven1-1/+1
Printing "mktime64(1900, 1, 1, 0, 0, 0)" gives -2208988800. Fixes: 83bbc5ac63326433 ("rtc: Add useful timestamp definitions") Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2019-04-04rtc: da9063: set rangeAlexandre Belloni1-0/+1
The DA9062 and DA9063 have a year register that can go up to 0x3F. Acked-by: Steve Twiss <stwiss.opensource@diasemi.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2019-04-04rtc: sh: set rangeAlexandre Belloni1-0/+1
The SH RTC is a BCD RTC with some version having 4 digits for the year. The range for the RTCs with only 2 digits for the year was unfortunately shifted to handle 1999 to 2098. Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2019-02-25rtc: remove rtc_class_ops.read_callbackAlexandre Belloni1-2/+1
Since commit 416f0e8056f7 ("RTC: sa1100: Update the sa1100 RTC driver."), the last user of .read_callback is gone. It has been 8 years and now new user appeared. Simply remove it. Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-12-19rtc: enforce rtc_timer_init private_data typeAlexandre Belloni1-6/+8
All the remaining users of rtc_timers are passing the rtc_device as private data. Enforce that and rename private_data to rtc. Suggested-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-11-22rtc: nvmem: remove nvmem from struct rtc_deviceAlexandre Belloni1-1/+0
Using devm_nvmem_register allows to avoid tracking the nvmem pointer in the rtc_device structure. This ultimately allows to register multiple nvmem devices from an RTC driver. Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-11-13rtc: class: remove devm_rtc_device_unregisterAlexandre Belloni1-2/+0
devm_rtc_device_unregister is not used by any driver and should not be used by any new driver. Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-09-28rtc: move rtc_add_group/s definitionsAlexandre Belloni1-0/+16
Move rtc_add_group and rtc_add_groups definition to rtc.h that is available for all RTC drivers. Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-09-13rtc: unexport non devm managed registrationAlexandre Belloni1-5/+0
Ensure the non managed version of the un/registration functions is not used anymore. No driver is using it anymore and they should not be necessary. Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-08-02rtc: remove struct rtc_taskAlexandre Belloni1-7/+2
Include rtc_task members directly in rtc_timer member. Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-07-26rtc: simplify rtc_irq_set_state/rtc_irq_set_freqAlexandre Belloni1-4/+2
The PIE doesn't handle tasks anymore, remove the pointer from the interface. Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-07-26rtc: remove irq_task and irq_task_lockAlexandre Belloni1-2/+0
There is no way to set a periodic task anymore, remove task pointer and lock. Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-07-26rtc: remove rtc_irq_register/rtc_irq_unregisterAlexandre Belloni1-4/+0
The rtc_irq_* interface is not used from outside the RTC subsytem since 2016. Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-16rtc: nvmem: don't return an error when not enabledAlexandre Belloni1-1/+1
Avoid reporting an error when RTC_NVMEM is not selected. Reported-by: kernel test robot <xiaolong.ye@intel.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-03-17rtc: Add useful timestamp definitionsAlexandre Belloni1-0/+5
Add commonly used timestamps for range definition. Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-03-17rtc: Add one offset seconds to expand RTC rangeBaolin Wang1-0/+3
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 <baolin.wang@linaro.org> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-03-17rtc: Add RTC rangeAlexandre Belloni1-0/+3
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@bootlin.com>
2018-03-01char: rtc: remove unused rtc_control() APIAlexandre Belloni1-4/+0
Since commit 34ce71a96dcb ("ALSA: timer: remove legacy rtctimer"), the rtc_register/rtc_control/rtc_unregister API is unused. As it is highly unlikely to be needed again, remove it. Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Acked-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-03-01rtc: remove nvmem_configAlexandre Belloni1-1/+0
Because nvmem_config is only used and copied at nvmem registration, remove it from struct rtc_device. All the rtc drivers using nvmem are now calling rtc_nvmem_register directly. Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-03-01rtc: export rtc_nvmem_register() to driversAlexandre Belloni1-0/+13
Export rtc_nvmem_register() so it can be called from drivers instead of only the core. Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2017-11-30rtc: Remove unused RTC_DEVICE_NAME_SIZECole Robinson1-1/+0
The last usage was removed in 5c82a6ae0 when rtc_device.name was removed Signed-off-by: Cole Robinson <crobinso@redhat.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-11-14Merge branch 'timers-core-for-linus' of ↵Linus Torvalds1-1/+42
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip Pull timer updates from Thomas Gleixner: "Yet another big pile of changes: - More year 2038 work from Arnd slowly reaching the point where we need to think about the syscalls themself. - A new timer function which allows to conditionally (re)arm a timer only when it's either not running or the new expiry time is sooner than the armed expiry time. This allows to use a single timer for multiple timeout requirements w/o caring about the first expiry time at the call site. - A new NMI safe accessor to clock real time for the printk timestamp work. Can be used by tracing, perf as well if required. - A large number of timer setup conversions from Kees which got collected here because either maintainers requested so or they simply got ignored. As Kees pointed out already there are a few trivial merge conflicts and some redundant commits which was unavoidable due to the size of this conversion effort. - Avoid a redundant iteration in the timer wheel softirq processing. - Provide a mechanism to treat RTC implementations depending on their hardware properties, i.e. don't inflict the write at the 0.5 seconds boundary which originates from the PC CMOS RTC to all RTCs. No functional change as drivers need to be updated separately. - The usual small updates to core code clocksource drivers. Nothing really exciting" * 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (111 commits) timers: Add a function to start/reduce a timer pstore: Use ktime_get_real_fast_ns() instead of __getnstimeofday() timer: Prepare to change all DEFINE_TIMER() callbacks netfilter: ipvs: Convert timers to use timer_setup() scsi: qla2xxx: Convert timers to use timer_setup() block/aoe: discover_timer: Convert timers to use timer_setup() ide: Convert timers to use timer_setup() drbd: Convert timers to use timer_setup() mailbox: Convert timers to use timer_setup() crypto: Convert timers to use timer_setup() drivers/pcmcia: omap1: Fix error in automated timer conversion ARM: footbridge: Fix typo in timer conversion drivers/sgi-xp: Convert timers to use timer_setup() drivers/pcmcia: Convert timers to use timer_setup() drivers/memstick: Convert timers to use timer_setup() drivers/macintosh: Convert timers to use timer_setup() hwrng/xgene-rng: Convert timers to use timer_setup() auxdisplay: Convert timers to use timer_setup() sparc/led: Convert timers to use timer_setup() mips: ip22/32: Convert timers to use timer_setup() ...
2017-11-02License cleanup: add SPDX GPL-2.0 license identifier to files with no licenseGreg Kroah-Hartman1-0/+1
Many source files in the tree are missing licensing information, which makes it harder for compliance tools to determine the correct license. By default all files without license information are under the default license of the kernel, which is GPL version 2. Update the files which contain no license information with the 'GPL-2.0' SPDX license identifier. The SPDX identifier is a legally binding shorthand, which can be used instead of the full boiler plate text. This patch is based on work done by Thomas Gleixner and Kate Stewart and Philippe Ombredanne. How this work was done: Patches were generated and checked against linux-4.14-rc6 for a subset of the use cases: - file had no licensing information it it. - file was a */uapi/* one with no licensing information in it, - file was a */uapi/* one with existing licensing information, Further patches will be generated in subsequent months to fix up cases where non-standard license headers were used, and references to license had to be inferred by heuristics based on keywords. The analysis to determine which SPDX License Identifier to be applied to a file was done in a spreadsheet of side by side results from of the output of two independent scanners (ScanCode & Windriver) producing SPDX tag:value files created by Philippe Ombredanne. Philippe prepared the base worksheet, and did an initial spot review of a few 1000 files. The 4.13 kernel was the starting point of the analysis with 60,537 files assessed. Kate Stewart did a file by file comparison of the scanner results in the spreadsheet to determine which SPDX license identifier(s) to be applied to the file. She confirmed any determination that was not immediately clear with lawyers working with the Linux Foundation. Criteria used to select files for SPDX license identifier tagging was: - Files considered eligible had to be source code files. - Make and config files were included as candidates if they contained >5 lines of source - File already had some variant of a license header in it (even if <5 lines). All documentation files were explicitly excluded. The following heuristics were used to determine which SPDX license identifiers to apply. - when both scanners couldn't find any license traces, file was considered to have no license information in it, and the top level COPYING file license applied. For non */uapi/* files that summary was: SPDX license identifier # files ---------------------------------------------------|------- GPL-2.0 11139 and resulted in the first patch in this series. If that file was a */uapi/* path one, it was "GPL-2.0 WITH Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was: SPDX license identifier # files ---------------------------------------------------|------- GPL-2.0 WITH Linux-syscall-note 930 and resulted in the second patch in this series. - if a file had some form of licensing information in it, and was one of the */uapi/* ones, it was denoted with the Linux-syscall-note if any GPL family license was found in the file or had no licensing in it (per prior point). Results summary: SPDX license identifier # files ---------------------------------------------------|------ GPL-2.0 WITH Linux-syscall-note 270 GPL-2.0+ WITH Linux-syscall-note 169 ((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21 ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17 LGPL-2.1+ WITH Linux-syscall-note 15 GPL-1.0+ WITH Linux-syscall-note 14 ((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5 LGPL-2.0+ WITH Linux-syscall-note 4 LGPL-2.1 WITH Linux-syscall-note 3 ((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3 ((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1 and that resulted in the third patch in this series. - when the two scanners agreed on the detected license(s), that became the concluded license(s). - when there was disagreement between the two scanners (one detected a license but the other didn't, or they both detected different licenses) a manual inspection of the file occurred. - In most cases a manual inspection of the information in the file resulted in a clear resolution of the license that should apply (and which scanner probably needed to revisit its heuristics). - When it was not immediately clear, the license identifier was confirmed with lawyers working with the Linux Foundation. - If there was any question as to the appropriate license identifier, the file was flagged for further research and to be revisited later in time. In total, over 70 hours of logged manual review was done on the spreadsheet to determine the SPDX license identifiers to apply to the source files by Kate, Philippe, Thomas and, in some cases, confirmation by lawyers working with the Linux Foundation. Kate also obtained a third independent scan of the 4.13 code base from FOSSology, and compared selected files where the other two scanners disagreed against that SPDX file, to see if there was new insights. The Windriver scanner is based on an older version of FOSSology in part, so they are related. Thomas did random spot checks in about 500 files from the spreadsheets for the uapi headers and agreed with SPDX license identifier in the files he inspected. For the non-uapi files Thomas did random spot checks in about 15000 files. In initial set of patches against 4.14-rc6, 3 files were found to have copy/paste license identifier errors, and have been fixed to reflect the correct identifier. Additionally Philippe spent 10 hours this week doing a detailed manual inspection and review of the 12,461 patched files from the initial patch version early this week with: - a full scancode scan run, collecting the matched texts, detected license ids and scores - reviewing anything where there was a license detected (about 500+ files) to ensure that the applied SPDX license was correct - reviewing anything where there was no detection but the patch license was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied SPDX license was correct This produced a worksheet with 20 files needing minor correction. This worksheet was then exported into 3 different .csv files for the different types of files to be modified. These .csv files were then reviewed by Greg. Thomas wrote a script to parse the csv files and add the proper SPDX tag to the file, in the format that the file expected. This script was further refined by Greg based on the output to detect more types of files automatically and to distinguish between header and source .c files (which need different comment types.) Finally Greg ran the script using the .csv files to generate the patches. Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org> Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-10-31rtc: Allow rtc drivers to specify the tv_nsec value for ntpJason Gunthorpe1-1/+42
ntp is currently hardwired to try and call the rtc set when wall clock tv_nsec is 0.5 seconds. This historical behaviour works well with certain PC RTCs, but is not universal to all rtc hardware. Change how this works by introducing the driver specific concept of set_offset_nsec, the delay between current wall clock time and the target time to set (with a 0 tv_nsecs). For x86-style CMOS set_offset_nsec should be -0.5 s which causes the last second to be written 0.5 s after it has started. For compat with the old rtc_set_ntp_time, the value is defaulted to + 0.5 s, which causes the next second to be written 0.5s before it starts, as things were before this patch. Testing shows many non-x86 RTCs would like set_offset_nsec ~= 0, so ultimately each RTC driver should set the set_offset_nsec according to its needs, and non x86 architectures should stop using update_persistent_clock64 in order to access this feature. Future patches will revise the drivers as needed. Since CMOS and RTC now have very different handling they are split into two dedicated code paths, sharing the support code, and ifdefs are replaced with IS_ENABLED. Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@kernel.org> Cc: Miroslav Lichvar <mlichvar@redhat.com> Cc: Richard Cochran <richardcochran@gmail.com> Cc: Prarit Bhargava <prarit@redhat.com> Cc: Stephen Boyd <stephen.boyd@linaro.org> Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com> Signed-off-by: John Stultz <john.stultz@linaro.org>
2017-08-24rtc: remove .open() and .release()Alexandre Belloni1-2/+0
There are no driver left using .open and .release. There is no good use case for them as there is nothing the character device interface does that should not be done in the sysfs interface or in-kernel interface. Remove those callbacks now to avoid future confusion. Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-07-13rtc: Remove wrong deprecation commentAlexandre Belloni1-6/+0
rtc_time_to_tm and rtc_tm_to_time are not deprecated and make perfect sense for RTCs that are simple 32bit counters. Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-07-07rtc: add generic nvmem supportAlexandre Belloni1-0/+7
Many RTCs have an on board non volatile storage. It can be battery backed RAM or an EEPROM. Use the nvmem subsystem to export it to both userspace and in-kernel consumers. This stays compatible with the previous (non documented) ABI that was using /sys/class/rtc/rtcx/device/nvram to export that memory. But will warn about the deprecation. Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-07-07rtc: introduce new registration methodAlexandre Belloni1-0/+7
Introduce rtc_register_device() to register an already allocated and initialized struct rtc_device. It automatically sets up the owner and the two steps allocation/registration will allow to remove race conditions in the IRQ handling of some driver. It also allows to properly extend the core without adding more arguments to rtc_device_register(). Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-06-03rtc: remove rtc_device.nameAlexandre Belloni1-1/+0
rtc->name is only used in messages were it is superfluous. Remove it completely from the structure. Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2016-03-14rtc: Add functions to set and read rtc offsetJoshua Clayton1-0/+4
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 <stillcompiling@gmail.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2015-06-25rtc: interface: Remove rtc_set_mmss()Xunlei Pang1-1/+0
Now rtc_set_mmss() has no users, just remove it. We still have rtc_set_time() doing similar things. Signed-off-by: Xunlei Pang <pang.xunlei@linaro.org> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2015-06-25rtc: Introduce rtc_tm_sub() helper functionXunlei Pang1-0/+8
There're many sites need comparing the two rtc_time variants for many rtc drivers, especially in the instances of rtc_class_ops::set_alarm(). So add this common helper function to make things easy. Suggested-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Xunlei Pang <pang.xunlei@linaro.org> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2015-06-19rtc: interface: Remove unused return value from rtc_timer_cancel()Krzysztof Kozlowski1-1/+1
The rtc_timer_cancel() always returns 0 and cannot fail (calls only other void-returning functions). Signed-off-by: Krzysztof Kozlowski <k.kozlowski.k@gmail.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2015-06-19rtc: interface: Fix coding style violationsKrzysztof Kozlowski1-6/+5
Fix issues reported by checkpatch: ERROR: open brace '{' following struct go on the same line ERROR: "foo* bar" should be "foo *bar" Additionally adjust alignment of wrapped function arguments. Signed-off-by: Krzysztof Kozlowski <k.kozlowski.k@gmail.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2015-04-03drivers/rtc: Provide y2038 safe rtc_class_ops.set_mmss() replacementXunlei Pang1-0/+1
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 <pang.xunlei@linaro.org> [jstultz: Add whitespace fix for checkpatch] Signed-off-by: John Stultz <john.stultz@linaro.org> Acked-by: Alessandro Zummo <a.zummo@towertech.it> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/1427945681-29972-8-git-send-email-john.stultz@linaro.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-01-24rtc: Convert rtc_set_ntp_time() to use timespec64Xunlei Pang1-1/+1
rtc_set_ntp_time() uses timespec which is y2038-unsafe, so modify to use timespec64 which is y2038-safe, then replace rtc_time_to_tm() with rtc_time64_to_tm(). Also adjust all its call sites(only NTP uses it) accordingly. Cc: pang.xunlei <pang.xunlei@linaro.org> Cc: Arnd Bergmann <arnd.bergmann@linaro.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@kernel.org> Signed-off-by: Xunlei Pang <pang.xunlei@linaro.org> Signed-off-by: John Stultz <john.stultz@linaro.org>