Commit Graph

752030 Commits

Author SHA1 Message Date
Fabio Estevam 75d01b75c2 rtc: mxc: Switch to SPDX identifier
Adopt the SPDX license identifier headers to ease license compliance
management.

Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-22 09:47:17 +02:00
Fabio Estevam 5874c7f16a rtc: snvs: Switch to SPDX identifier
Adopt the SPDX license identifier headers to ease license compliance
management.

Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-22 09:47:15 +02:00
Uwe Kleine-König 046dbb2420 rtc: nvmem: don't use IS_ERR_OR_NULL
nvmem_register() never returns NULL, so IS_ERR is good enough here.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-21 22:34:38 +02:00
Uwe Kleine-König 48e9a9b203 rtc: ds1742: don't explicitly specify word_size and stride of nvmem
nvmem_register() assumes these values to be 1 if unset, so they don't
need to be set explicitly.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-21 22:34:36 +02:00
Alexandre Belloni ded676666f rtc: brcmstb-waketimer: add range
Let the core handle the range.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-21 22:33:52 +02:00
Alexandre Belloni 2abf286a20 rtc: brcmstb-waketimer: switch to rtc_register_device
Switch to devm_rtc_allocate_device/rtc_register_device.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-21 22:33:50 +02:00
Alexandre Belloni 7e83f03fad rtc: mxc_v2: use rtc_time64_to_tm in mxc_rtc_read_alarm
Use the 64-bit version of rtc_time_to_tm in mxc_rtc_read_alarm

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-19 10:50:03 +02:00
Alexandre Belloni 95fbfa14b4 rtc: mxc_v2: let the core handle rtc range
This RTC is a 32-bit second counter.

This also solves an issue where mxc_rtc_set_alarm() can return with the
lock taken.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-19 10:47:46 +02:00
Alexandre Belloni 5490a1e018 rtc: mxc_v2: fix possible race condition
The IRQ is requested before the struct rtc is allocated and registered, but
this struct is used in the IRQ handler. This may lead to a NULL pointer
dereference.

Switch to devm_rtc_allocate_device/rtc_register_device to allocate the rtc
before requesting the IRQ.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-19 10:47:46 +02:00
Alexandre Belloni d759924500 rtc: ls1x: add range
While the year is encoded on 32 bits in SYS_TOYWRITE1i/SYS_TOYREAD1. The
Loongson 1c datasheet states that the range is from 0 to 99.

The current code exceeds this range and seems to be working, I deduce that
the leap year algorithm will fail in 2100.

Anyway, alarm registers only encode the year on 14 bits so with alarm
support, the range will always be limited to 0 to 16383.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-18 09:38:22 +02:00
Alexandre Belloni 14dc3ec520 rtc: ls1x: remove useless label and goto
The error handling in ls1x_rtc_probe used to release resources but since
it is using devm functions, it only returns a value. Make the code clearer
by returning directly instead of using goto.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-17 22:55:17 +02:00
Alexandre Belloni 52f0e7bc19 rtc: ls1x: switch to rtc_register_device
This allows for future improvement of the driver.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-17 22:55:16 +02:00
Alexandre Belloni 180c92c4ae rtc: tps6586x: let the core handle rtc range
Let the core handle offsetting and windowing the RTC range.

The RTC has a 40-bit counter counting at 1024 Hz. So its maximum value is
2^(40-10) - 1. Also, let the core handle the offset instead of coding it in
the callbacks. Keep the default epoch at the beginning of 2009 (this will
fail in 2043).

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-17 22:54:24 +02:00
Alexandre Belloni 63d2206307 rtc: tps6586x: fix possible race condition
The probe function is not allowed to fail after the RTC is registered
because the following may happen:

CPU0:                                CPU1:
sys_load_module()
 do_init_module()
  do_one_initcall()
   cmos_do_probe()
    rtc_device_register()
     __register_chrdev()
     cdev->owner = struct module*
                                     open("/dev/rtc0")
    rtc_device_unregister()
  module_put()
  free_module()
   module_free(mod->module_core)
   /* struct module *module is now
      freed */
                                      chrdev_open()
                                       spin_lock(cdev_lock)
                                       cdev_get()
                                        try_module_get()
                                         module_is_live()
                                         /* dereferences already
                                            freed struct module* */

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-17 22:54:22 +02:00
Alexandre Belloni 30d7891ae9 rtc: vr41xx: add range
The vr41xx RTC is a 48-bit counter counting at 32.768 kHz, giving a maximum
value of 2^(48-15)-1 seconds.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-17 22:54:21 +02:00
Alexandre Belloni 9a99247c9c rtc: vr41xx: fix possible race condition
The probe function is not allowed to fail after the RTC is registered
because the following may happen:

CPU0:                                CPU1:
sys_load_module()
 do_init_module()
  do_one_initcall()
   cmos_do_probe()
    rtc_device_register()
     __register_chrdev()
     cdev->owner = struct module*
                                     open("/dev/rtc0")
    rtc_device_unregister()
  module_put()
  free_module()
   module_free(mod->module_core)
   /* struct module *module is now
      freed */
                                      chrdev_open()
                                       spin_lock(cdev_lock)
                                       cdev_get()
                                        try_module_get()
                                         module_is_live()
                                         /* dereferences already
                                            freed struct module* */

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-17 22:54:19 +02:00
Alexandre Belloni 94389b28ba rtc: rx8581: switch to regmap
Switch to regmap to simplify handling block read/write.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-17 22:43:22 +02:00
Alexandre Belloni 6e6111f6c0 rtc: rx8581: error out when time invalid
Return an error when the date is unreliable because the battery is low.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-17 22:43:22 +02:00
Alexandre Belloni ed87c6d86d rtc: rx8581: remove useless declaration
The rx8581_driver forward declaration is useless, remove it.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-17 22:37:19 +02:00
Alexandre Belloni 2d2b300b38 rtc: rx8581: remove useless indirection
rx8581_get_datetime and rx8581_set_datetime are only used after casting dev
to an i2c_client. Remove that useless indirection.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-17 22:37:18 +02:00
Alexandre Belloni c6e3c297a1 rtc: rx8581: let the core handle rtc range
Let the core handle offsetting and windowing the RTC range.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-17 22:37:16 +02:00
Alexandre Belloni 86c54ef6e6 rtc: rx8581: add RTC range
The rx8581 can support dates from 01/01/2000 to 31/12/2099.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-17 22:37:14 +02:00
Alexandre Belloni b815716820 rtc: rx8581: switch to rtc_register_device
This allows for future improvement of the driver.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-17 22:37:12 +02:00
Alexandre Belloni 57ad9e6925 rtc: tps65910: add range
The tps65910 RTC can support dates from 01/01/2000 to 31/12/2099.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-17 22:37:11 +02:00
Alexandre Belloni ee366c7a0e rtc: tps65910: allow platform power up
Currently, the IRQs are disabled when the rtc driver is removed (e.g. when
shutting down the platform).
This means that the RTC will be unable to power up the platform.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-17 22:37:09 +02:00
Alexandre Belloni e6000a438e rtc: tps65910: fix possible race condition
The IRQ is requested before the struct rtc is allocated and registered, but
this struct is used in the IRQ handler. This may lead to a NULL pointer
dereference.

Switch to devm_rtc_allocate_device/rtc_register_device to allocate the rtc
before requesting the IRQ.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-17 22:37:07 +02:00
Alexandre Belloni c402f8ead6 rtc: ab-b5ze-s3: let the core handle the RTC range
The ab-b5ze-s3 RTC is storing the year in an 8bit bcd coded register so it
can handle dates from year 2000 to year 2099.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-17 22:23:25 +02:00
Alexandre Belloni 8bde032b28 rtc: ab-b5ze-s3: fix possible race conditions
The IRQ is requested before the struct rtc is allocated and registered, but
this struct is used in the IRQ handler. This may lead to a NULL pointer
dereference.

Also, the probe function is not allowed to fail after the RTC is registered
because the following may happen:

CPU0:                                CPU1:
sys_load_module()
 do_init_module()
  do_one_initcall()
   cmos_do_probe()
    rtc_device_register()
     __register_chrdev()
     cdev->owner = struct module*
                                     open("/dev/rtc0")
    rtc_device_unregister()
  module_put()
  free_module()
   module_free(mod->module_core)
   /* struct module *module is now
      freed */
                                      chrdev_open()
                                       spin_lock(cdev_lock)
                                       cdev_get()
                                        try_module_get()
                                         module_is_live()
                                         /* dereferences already
                                            freed struct module* */

Switch to devm_rtc_allocate_device/rtc_register_device to allocate the rtc
before requesting the IRQ and register the RTC as late as possible.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-17 22:23:23 +02:00
Alexandre Belloni 02f3712f1f rtc: 88pm80x: convert to rtc_tm_to_time64/rtc_time64_to_tm
Now that the RTC range is properly checked, convert the driver to
rtc_tm_to_time64/rtc_time64_to_tm

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-17 22:23:21 +02:00
Alexandre Belloni 39ba69427a rtc: 88pm80x: let the core handle the RTC range
The 88pm80x RTC is storing the time as a 32bit offset from a 32bit counter
so it can handle dates from 0 to U32_MAX.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-17 22:23:20 +02:00
Alexandre Belloni 661eb89a11 rtc: 88pm80x: fix possible race condition
The IRQ is requested before the struct rtc is allocated and registered, but
this struct is used in the IRQ handler. This may lead to a NULL pointer
dereference.

Switch to devm_rtc_allocate_device/rtc_register_device to allocate the rtc
before requesting the IRQ.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-17 22:23:18 +02:00
Alexandre Belloni ba78d51bdf rtc: 88pm80x: remove unused pm80x_rtc_info members
pm80x_rtc_info.calib_work and pm80x_rtc_info.vrtc are never used, remove
them.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-17 22:23:17 +02:00
Alexandre Belloni 48b29c7fc2 rtc: 88pm80x: stop setting a default time
It doesn't make sense to set the RTC to a default value at probe time. Let
the core handle invalid date and time.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-17 22:23:15 +02:00
Alexandre Belloni 6c78a872a6 rtc: at91rm9200: add range
The at91rm9200 RTC can support dates from 1900-01-01 00:00:00 to 2099-12-31
23:59:59.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-17 22:23:14 +02:00
Alexandre Belloni c59b3715ac rtc: nvmem: don't return an error when not enabled
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-05-16 21:08:42 +02:00
Fabio Estevam 5aa6a62d11 dt-bindings: rtc-2123: Make the node name generic
According to Devicetree Specification v0.2 document:

"The name of a node should be somewhat generic, reflecting the function
of the device and not its precise programming model."

Do as suggested in the binding example.

Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-14 15:27:50 +02:00
Amelie Delaunay 22cb47c1ea rtc: stm32: get DBP register and mask from DT st, syscfg property
RTC driver should not be aware of the PWR registers offset and bits
position. Furthermore, we can imagine that DBP relative register and bit
mask could change depending on the SoC.
So this patch introduces 2 parameters, dbp_reg and dbp_mask, allowing to
get PWR_CR and PWR_CR_DBP from device tree. And it prepares next RTC
version, backup domain write protection is disabled only if needed.

Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-06 22:22:43 +02:00
Amelie Delaunay deb7dcfbf0 dt-bindings: rtc: update stm32-rtc documentation for st, syscfg property
RTC driver should not be aware of the PWR registers offset and bits
position. Furthermore, we can imagine that Disable Backup Protection (DBP)
relative register and bit mask could change depending on the SoC. So this
patch moves st,syscfg property from single pwrcfg phandle to pwrcfg
phandle/offset/mask triplet.

Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
Acked-by: Alexandre TORGUE <alexandre.torgue@st.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-06 22:22:42 +02:00
Amelie Delaunay d213217d21 rtc: stm32: fix alarm interrupt flags by removing IRQF_TRIGGER_RISING
RTC alarm interrupt is active high and already configured by device tree.
So remove IRQF_TRIGGER_RISING from driver.

Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-06 22:22:40 +02:00
Amelie Delaunay 2480564572 rtc: stm32: fix copyright and adopt SPDX identifier
Fix copyright by removing "SA" and "for STMicroelectronics", not required.
Adopt SPDX identifier.

Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-06 22:22:39 +02:00
Arnd Bergmann 7982df8671 rtc: tps6586x: remove mktime usage
The tps6586x use a 64-bit 'epoch_start' value, but then computes that
value using an 'mktime()', which has a smaller range and overflows
in 2106 at the latest. As both the hardware and the subsystem interface
support wider than 32-bit ranges for rtc times here, let's change all
the operations on 'seconds' to time64_t.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-03 22:46:25 +02:00
Arnd Bergmann 337fa19cc3 rtc: ls1x: remove mktime usage
The loongson1 platform is 32-bit, so storing a time value in 32 bits
suffers from limited range. In this case it is likely to be correct
until 2106, but it's better to avoid the limitation and just use
the time64_t based mktime64() and rtc_time64_to_tm() interfaces.

The hardware uses a 32-bit year number, and time64_t can cover that
entire range.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-03 22:46:25 +02:00
Arnd Bergmann 0d1c655380 rtc: vr41xx: remove mktime usage
This driver uses mktime() and rtc_time_to_tm() to convert between time
values. This works fine on 64-bit kernels over the whole supported
range, and the vr41xx chip is a 64-bit MIPS implementation, but it is
inconsistent because it doesn't do the same thing on 32-bit kernels that
overflow in 2106 or 2038.

Changing it to use mktime64/rtc_time64_to_tm() should have no visible
impact on vr41xx but gets us closer to removing the 32-bit interfaces.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-03 22:46:25 +02:00
Andrea Greco 51ed73eb99 rtc: ds1340: Add support for trickle charger.
Add support Dallas DS1340 trickle charger function.

Signed-off-by: Andrea Greco <a.greco@4sigma.it>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-03 22:46:25 +02:00
Baolin Wang 149aa91cd6 rtc: sprd: Add RTC hardware range
The SC27xx RTC can support dates from 1970-01-01 00:00:00 to 2149-06-06
23:59:59.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-03 22:11:50 +02:00
Baolin Wang 369a30a5f1 rtc: sprd: Change to use devm_rtc_allocate_device()
This is a preparation patch, changing to use devm_rtc_allocate_device()
that can allow driver to set 'range_max' and 'range_min' for the RTC
device.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-03 22:11:49 +02:00
Wolfram Sang 85368bb9de rtc: simplify getting .drvdata
We should get drvdata from struct device directly. Going via
platform_device is an unneeded step back and forth.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Acked-by: Michal Simek <michal.simek@xilinx.com> (for zynqmp)
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-03 22:08:00 +02:00
Zhang Rui 36d91a4d40 rtc: cmos: introduce quirks to enable use_acpi_alarm mode
Use ACPI for RTC Alarm only for Intel platforms
1. with Low Power S0 support
2. with HPET RTC emulation enabled
3. no earlier than 2015

Note that, during the test, it is found that this patch
1. works in 4.15-rc kernel
2. hangs the platform after suspend-to-idle for 2 or 3 times, in 4.15.0
3. works again in 4.16-rc3 kernel.
4. works in the latest 4.15.12 stable kernel.

Thus although this patch breaks 4.15.0 kernel for some unknown reason,
still, it is safe for both upstream and backport.

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-04-19 18:01:50 +02:00
Zhang Rui c6d3a278cc rtc: cmos: acknowledge ACPI driven wake alarms upon resume
Previously, the RTC alarm is acknowledged either by the cmos rtc irq
handler, or by the hpet rtc irq handler.

When using ACPI RTC Fixed event as the RTC alarm, the RTC alarm is
acknowledged by the ACPI RTC event handler, as addressed in the previous
patch.
But, when resume from suspend-to-ram (ACPI S3), the ACPI SCI is cleared
right after resume, thus the ACPI RTC event handler is not invoked at all,
results in the RTC Alarm unacknowledged.

Handle this by comparing the current time and the RTC Alarm time in the
rtc_cmos driver .resume() callback
1. Assume the wakeup event has already been fired if the RTC Alarm time
   is earlier than/equal to the current time, and ACK the RTC Alarm.
2. Assume the wakeup event has not been fired if the RTC Alarm time
   is later than current time, and re-arm it if needed.

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-04-19 18:01:50 +02:00
Zhang Rui 311ee9c151 rtc: cmos: allow using ACPI for RTC alarm instead of HPET
It's found that the HPET timer prevents the platform from entering
Low Power S0 on some new Intel platforms.

This means that
1. users can still use RTC wake Alarm for suspend-to-idle, but the system
   never enters Low Power S0, which is a waste of power.
or
2. if users want to put the system into Low Power S0, they can not use
   RTC as the wakeup source.

To fix this, we need to stop using the HPET timer for wake alarm.
But disabling CONFIG_HPET_EMULATE_RTC is not an option because HPET
emulates PIT at the same time, and this is needed on some of these
platforms.

Thus, introduce a new mode (use_acpi_alarm) to the rtc_cmos driver,
so that, even with CONFIG_HPET_EMULATE_RTC enabled, it's still possible to
use ACPI SCI for RTC Alarm, including UIE/AIE/wkalrm, instead of HPET.

Only necessary changes are made for the new "use_acpi_alarm" mode, including
1. drop all the calls to HPET emulation code, including the HPET irq
   handler for rtc interrupt.
2. enabling/disabling ACPI RTC Fixed event upon RTC UIE/AIE request.
3. acknowledge the RTC Alarm in ACPI RTC Fixed event handler.

There is no functional change made in this patch if the new mode is not
enabled.

Note: this "use_acpi_alarm" mode is made based on the assumption that
ACPI RTC Fixed event is reliable both at runtime and during system wakeup.
And this has been verified on a couple of platforms I have, including
a MS Surface Pro 4 (SKL), a Lenovo Yoga 900 (SKL), and a HP 9360 (KBL).

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-04-19 18:01:50 +02:00