Commit Graph

2857 Commits

Author SHA1 Message Date
Alexandre Belloni 4dc2403bed rtc: test: store time as an offset to system time
Store the time as an offset to system time. As the offset is in second, it
is currently always synced with system time.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-31 23:13:28 +02:00
Alexandre Belloni 5b257571cd rtc: test: allow registering many devices
Use a loop to register RTC devices

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-31 23:13:26 +02:00
Alexandre Belloni 9394270ef9 rtc: test: remove useless proc info
The rtc proc callback is useless for two reasosn:
 - the test RTC is often not the first RTC so it will never be used
 - all the info is available in the name file of the RTC sys folder

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-31 23:13:25 +02:00
Alexandre Belloni c36b52ed18 rtc: ds1685: Add range
Useful range is 2000-2099 because leap year fails on centuries.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-31 23:02:11 +02:00
Alexandre Belloni a2ae8323a8 rtc: ds1685: 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.

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-31 23:02:11 +02:00
Baolin Wang a0defd7cfc rtc: sprd: Add new RTC power down check method
We should use the new method to check if RTC was powered down, which
is more solid. Since we have introduced power control and power status
registers, and we just check if the power status is the default value
(0x96), if yes that means the RTC has been powered down. Meanwhile We
can set the power control register to be one valid value to change
the power status to indicate RTC device is valid now.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-31 23:02:11 +02:00
Michael Trimarchi 09018d4bd7 rtc: sun6i: Fix bit_idx value for clk_register_gate
clk-gate core will take bit_idx through clk_register_gate
and then do clk_gate_ops by using BIT(bit_idx), but rtc-sun6i
is passing bit_idx as BIT(bit_idx) it becomes BIT(BIT(bit_idx)
which is wrong and eventually external gate clock is not enabling.

This patch fixed by passing bit index and the original change
introduced from below commit.
"rtc: sun6i: Add support for the external oscillator gate"
(sha1: 	17ecd24641)

Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com>
Fixes: 17ecd24641 ("rtc: sun6i: Add support for the external oscillator gate")
Cc: stable@vger.kernel.org
Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>
Acked-by: Maxime Ripard <maxime.ripard@bootlin.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-31 23:02:11 +02:00
Mathieu Malaterre b9ef86084d rtc: jz4740: Fix a typo in Kconfig
Fix typo introduced for RTC_DRV_JZ4740 in commit 586655d278 ("rtc:
jz4740: make the driver buildable as a module again").

Signed-off-by: Mathieu Malaterre <malat@debian.org>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-31 23:02:11 +02:00
Alexandre Belloni 7841768200 rtc: test: remove obsolete .set_mmss
There is no point in testing .set_mmss versus .set_mmss64 as there are both
taking the exact same argument (truncated for set_mmss though).

Also, this allows to constify struct rtc_ops.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-26 04:06:42 +02:00
Alexandre Belloni b64c984ac8 rtc: st-lpc: add range
The RTC has a 64 bit counter.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Acked-by: Patrice Chotard <patrice.chotard@st.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-23 09:26:19 +02:00
Alexandre Belloni d482510fee rtc: st-lpc: 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.

Acked-by: Patrice Chotard <patrice.chotard@st.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-23 09:25:27 +02:00
Amelie Delaunay b72252b658 rtc: stm32: add stm32mp1 rtc support
This patch adds support for stm32mp1 RTC.
Some common registers with previous RTC version have a different offset.
It is the case for Control Register (CR) and ALaRMA Register (ALRMAR).
There are also new registers regarding event flags: now, Alarm event flag
is in Status Register (SR) and write 1 in Status Clear Register (SCR) is
required to clear the event.

Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-22 20:10:54 +02:00
Amelie Delaunay 02b0cc345c rtc: stm32: rework register management to prepare other version of RTC
This patch reworks register/bits management because next version of RTC
uses the same way of working but with different register's offset or bits
moved in new registers.

Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-22 20:10:52 +02:00
Amelie Delaunay 819cbde521 rtc: stm32: fix misspelling and misalignment issues
This patch cleans the following checkpatch complaints:

CHECK: 'initalized' may be misspelled - perhaps 'initialized'?
#644: FILE: drivers/rtc/rtc-stm32.c:644:
+	 * the calendar has been initalized or not. INITS flag is reset by a

CHECK: Alignment should match open parenthesis
#669: FILE: drivers/rtc/rtc-stm32.c:669:
+	rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, pdev->name,
+			&stm32_rtc_ops, THIS_MODULE);

Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-22 20:10:50 +02:00
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
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 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