platform/kernel/linux-rpi.git
6 years agortc: 88pm80x: remove artificial limitation
Alexandre Belloni [Sat, 10 Mar 2018 13:29:28 +0000 (14:29 +0100)]
rtc: 88pm80x: remove artificial limitation

The 88pm80x supports time up to 2106 (it is a 32 bit counter). Also, the
year will never be before 1970 as the RTC core forbids that.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: st-lpc: remove artificial limitation
Alexandre Belloni [Sat, 10 Mar 2018 05:35:08 +0000 (06:35 +0100)]
rtc: st-lpc: remove artificial limitation

The LPC RTC supports dates way beyond 2038, don't limit it artificially as
the kernel handles dates after 2038 properly.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: mrst: remove artificial limitation
Alexandre Belloni [Sat, 10 Mar 2018 05:32:00 +0000 (06:32 +0100)]
rtc: mrst: remove artificial limitation

The hardware supports years up to 100 so don't limit the year to 2038
artificially.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: mv: remove artificial limitation
Alexandre Belloni [Thu, 8 Mar 2018 22:32:51 +0000 (23:32 +0100)]
rtc: mv: remove artificial limitation

Dates after 2038 actually fit on 32 bits. The counter will overflow in
2106. Also, it is bad practice to reset the RTC to a default value.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: hctosys: Ensure system time doesn't overflow time_t
Alexandre Belloni [Thu, 8 Mar 2018 22:27:31 +0000 (23:27 +0100)]
rtc: hctosys: Ensure system time doesn't overflow time_t

On 32bit platforms, time_t is still a signed 32bit long. If it is
overflowed, userspace and the kernel cant agree on the current system time.
This causes multiple issues, in particular with systemd:
https://github.com/systemd/systemd/issues/1143

A good workaround is to simply avoid using hctosys which is something I
greatly encourage as the time is better set by userspace.

However, many distribution enable it and use systemd which is rendering the
system unusable in case the RTC holds a date after 2038 (and more so after
2106). Many drivers have workaround for this case and they should be
eliminated so there is only one place left to fix when userspace is able to
cope with dates after the 31bit overflow.

Acked-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agoparisc: time: stop validating rtc_time in .read_time
Alexandre Belloni [Wed, 21 Feb 2018 21:40:23 +0000 (22:40 +0100)]
parisc: time: stop validating rtc_time in .read_time

The RTC core is always calling rtc_valid_tm after the read_time callback.
It is not necessary to call it just before returning from the callback.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Acked-by: Helge Deller <deller@gmx.de>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: pcf85063: fix clearing bits in pcf85063_start_clock
Michael McCormick [Wed, 21 Feb 2018 22:29:24 +0000 (11:29 +1300)]
rtc: pcf85063: fix clearing bits in pcf85063_start_clock

Bit clear operation was missing ~

Signed-off-by: Michael McCormick <michael.mccormick@enatel.net>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: at91sam9: Set name of regmap_config
Jeffy Chen [Mon, 12 Mar 2018 09:51:40 +0000 (17:51 +0800)]
rtc: at91sam9: Set name of regmap_config

We are now allowing to register debugfs without a valid device, and not
having a valid name will end up using "dummy*" to create debugfs dir.

Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: s5m: Remove VLA usage
Gustavo A. R. Silva [Sat, 10 Mar 2018 06:27:35 +0000 (00:27 -0600)]
rtc: s5m: Remove VLA usage

In preparation to enabling -Wvla, remove VLAs and replace them
with fixed-length arrays instead.

>From a security viewpoint, the use of Variable Length Arrays can be
a vector for stack overflow attacks. Also, in general, as the code
evolves it is easy to lose track of how big a VLA can get. Thus, we
can end up having segfaults that are hard to debug.

Also, fixed as part of the directive to remove all VLAs from
the kernel: https://lkml.org/lkml/2018/3/7/621

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: s5m: Move enum from rtc.h to rtc-s5m.c
Gustavo A. R. Silva [Sat, 10 Mar 2018 06:27:15 +0000 (00:27 -0600)]
rtc: s5m: Move enum from rtc.h to rtc-s5m.c

Move this enum to rtc-s5m.c once it is meaningless to others drivers [1].

[1] https://marc.info/?l=linux-rtc&m=152060068925948&w=2

Suggested-by: Krzysztof Kozlowski <krzk@kernel.org>
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org>
Acked-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: remove VLA usage
Gustavo A. R. Silva [Thu, 8 Mar 2018 02:27:56 +0000 (20:27 -0600)]
rtc: remove VLA usage

In preparation to enabling -Wvla, remove VLA and replace it
with a fixed-length array instead.

>From a security viewpoint, the use of Variable Length Arrays can be
a vector for stack overflow attacks. Also, in general, as the code
evolves it is easy to lose track of how big a VLA can get. Thus, we
can end up having segfaults that are hard to debug.

Also, fixed as part of the directive to remove all VLAs from
the kernel: https://lkml.org/lkml/2018/3/7/621

Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: Add useful timestamp definitions
Alexandre Belloni [Wed, 7 Mar 2018 23:13:52 +0000 (00:13 +0100)]
rtc: Add useful timestamp definitions

Add commonly used timestamps for range definition.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: Add one offset seconds to expand RTC range
Baolin Wang [Mon, 8 Jan 2018 06:04:50 +0000 (14:04 +0800)]
rtc: Add one offset seconds to expand RTC range

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>
6 years agortc: Factor out the RTC range validation into rtc_valid_range()
Baolin Wang [Mon, 8 Jan 2018 06:04:49 +0000 (14:04 +0800)]
rtc: Factor out the RTC range validation into rtc_valid_range()

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

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: Add RTC range
Alexandre Belloni [Sat, 17 Feb 2018 13:58:40 +0000 (14:58 +0100)]
rtc: Add RTC range

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>
6 years agortc: isl1208: switch to rtc_register_device
Denis Osterland [Mon, 5 Mar 2018 10:43:53 +0000 (10:43 +0000)]
rtc: isl1208: switch to rtc_register_device

Fix possible race condition.
It is not allowed to return with an error code after RTC is registered.

Suggested-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Signed-off-by: Denis Osterland <Denis.Osterland@diehl.com>
Reviewed-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: isl1208: enable interrupt after context preparation
Michael Grzeschik [Mon, 5 Mar 2018 10:43:53 +0000 (10:43 +0000)]
rtc: isl1208: enable interrupt after context preparation

The interrupt handler got enabled very early. If the interrupt cause is
triggering immediately before the context is fully prepared. This can
lead to undefined behaviour. Therefor we move the interrupt enable code
to the end of the probe function.

Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
Signed-off-by: Denis Osterland <Denis.Osterland@diehl.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: cros-ec: return -ETIME when refused to set alarms in the past
Jeffy Chen [Tue, 27 Feb 2018 02:50:03 +0000 (10:50 +0800)]
rtc: cros-ec: return -ETIME when refused to set alarms in the past

Since accessing a Chrome OS EC based rtc is a slow operation, there is a
race window where if the alarm is set for the next second and the second
ticks over right before calculating the alarm offset.

In this case the current driver is setting a 0-second alarm, which would
be considered as disabling alarms by the EC(EC_RTC_ALARM_CLEAR).

This breaks, e.g., hwclock which relies on RTC_UIE_ON ->
rtc_update_irq_enable(), which sets a 1-second alarm and expects it to
fire an interrupt.

So return -ETIME when the alarm is in the past, follow __rtc_set_alarm().

Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
Reviewed-by: Brian Norris <briannorris@chromium.org>
Tested-by: Brian Norris <briannorris@chromium.org>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: pm8xxx: Fix issue in RTC write path
Mohit Aggarwal [Mon, 5 Mar 2018 09:05:58 +0000 (14:35 +0530)]
rtc: pm8xxx: Fix issue in RTC write path

In order to set time in rtc, need to disable
rtc hw before writing into rtc registers.

Also fixes disabling of alarm while setting
rtc time.

Signed-off-by: Mohit Aggarwal <maggarwa@codeaurora.org>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: at91sam: add 'depends on HAS_IOMEM' to fix unmet dependency
Masahiro Yamada [Tue, 6 Mar 2018 11:08:11 +0000 (20:08 +0900)]
rtc: at91sam: add 'depends on HAS_IOMEM' to fix unmet dependency

This config select's MFD_SYSCON, but does not depend on HAS_IOMEM.

Compile testing on architecture without HAS_IOMEM causes "unmet
direct dependencies" in Kconfig phase.

Detected by "make ARCH=score allyesconfig".

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: isl12026: fixup nvmem registration
Alexandre Belloni [Fri, 2 Mar 2018 23:50:29 +0000 (00:50 +0100)]
rtc: isl12026: fixup nvmem registration

The probe function must not fail after rtc_register_device. Also, rename
the nvmem device so it is easily identifiable in /sys/bus/nvmem.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: isl12026: new driver.
David Daney [Thu, 22 Feb 2018 20:04:32 +0000 (12:04 -0800)]
rtc: isl12026: new driver.

The ISL12026 is a combination RTC and EEPROM device with I2C
interface.  The standard RTC driver interface is provided.  The EEPROM
is accessed via the NVMEM interface.

Reviewed-by: Rob Herring <robh@kernel.org>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: David Daney <david.daney@cavium.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: brcmstb-waketimer: Set wktmr prescaler
Justin Chen [Mon, 26 Feb 2018 20:09:58 +0000 (12:09 -0800)]
rtc: brcmstb-waketimer: Set wktmr prescaler

The HW default is one tick per second, however instead of assuming this,
lets make sure the waketimer is actually one tick per second before
arming the alarm.

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Justin Chen <justinpopo6@gmail.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: fix rtc_time64_to_tm for 3477
Alexandre Belloni [Wed, 28 Feb 2018 21:50:53 +0000 (22:50 +0100)]
rtc: fix rtc_time64_to_tm for 3477

The current correction for leap years will fail in 3477. 3476-12-31 being
3477-01-00 because this is 366 leap years after 1970 and 3477 isn't a leap
year.

Fix that by looping over until days is positive or zero.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: ac100: Fix ac100 determine rate bug
Philipp Rossak [Mon, 26 Feb 2018 21:19:01 +0000 (22:19 +0100)]
rtc: ac100: Fix ac100 determine rate bug

This patch fixes a bug, that prevents the Allwinner A83T and the A80
from a successful boot.

The bug is there since v4.16-rc1 and appeared after the clk branch was
merged.

You can find the shortend trace below:

Unable to handle kernel NULL pointer dereference at virtual address
00000000
pgd = (ptrval)
[00000000] *pgd=00000000
Internal error: Oops: 5 [#1] SMP ARM
Modules linked in:
CPU: 0 PID: 49 Comm: kworker/0:1 Not tainted 4.15.0-10190-gb89e32ccd1be #2
Hardware name: Allwinner sun8i Family
Workqueue: events deferred_probe_work_func
PC is at clk_hw_get_rate+0x0/0x34
LR is at ac100_clkout_determine_rate+0x48/0x19c

[ ... ]

(clk_hw_get_rate) from (ac100_clkout_determine_rate+0x48/0x19c)
(ac100_clkout_determine_rate) from  (clk_core_set_rate_nolock+0x3c/0x1a0)
(clk_core_set_rate_nolock) from (clk_set_rate+0x30/0x88)
(clk_set_rate) from (of_clk_set_defaults+0x200/0x364)
(of_clk_set_defaults) from (platform_drv_probe+0x18/0xb0)

To fix that bug, we first check if the return of the
clk_hw_get_parent_by_index is non zero. If it is zero we skip that
clock parent.

The BUG report could be found here: https://lkml.org/lkml/2018/2/10/198

Fixes: 04940631b8d2 ("rtc: ac100: Add clk output support")

Signed-off-by: Philipp Rossak <embed3d@gmail.com>
Acked-by: Maxime Ripard <maxime.ripard@bootlin.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: pcf85363: set time accurately
Alexandre Belloni [Sat, 24 Feb 2018 00:08:53 +0000 (01:08 +0100)]
rtc: pcf85363: set time accurately

As per 8.2.6 Setting and reading the time in RTC mode, first stop the clok,
then reset it before setting the date and time registers. Finally, start
the clock.

This uses register address wrap around from 0x2f to 0x00 for efficiency.

This allows to set the clock with a millisecond accuracy (drift is not
corrected in this example):

RTC        System
1325388767 1325388767.000029180
1325388768 1325388768.000018362
1325388769 1325388769.000006544
1325388770 1325388769.999992725
1325388771 1325388770.999974544

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: pcf85363: add alarm support
Alexandre Belloni [Thu, 1 Mar 2018 00:42:19 +0000 (01:42 +0100)]
rtc: pcf85363: add alarm support

Handle alarms, currently only on INTA

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: pcf85363: add .max_register in regmap_config
Alexandre Belloni [Sat, 24 Feb 2018 00:08:50 +0000 (01:08 +0100)]
rtc: pcf85363: add .max_register in regmap_config

This helps debugging as it allows reading registers from debugfs.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: m41t80: remove useless indirection
Alexandre Belloni [Sun, 25 Feb 2018 22:15:00 +0000 (23:15 +0100)]
rtc: m41t80: remove useless indirection

m41t80_get_datetime and m41t80_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>
6 years agortc: m41t80: fix race conditions
Alexandre Belloni [Sun, 25 Feb 2018 20:14:31 +0000 (21:14 +0100)]
rtc: m41t80: fix race conditions

The IRQ is requested before the struct rtc is allocated and registered, but
this struct is used in the IRQ handler, leading to:

Unable to handle kernel NULL pointer dereference at virtual address 0000017c
pgd = a38a2f9b
[0000017c] *pgd=00000000
Internal error: Oops: 5 [#1] ARM
Modules linked in:
CPU: 0 PID: 613 Comm: irq/48-m41t80 Not tainted 4.16.0-rc1+ #42
Hardware name: Atmel SAMA5
PC is at mutex_lock+0x14/0x38
LR is at m41t80_handle_irq+0x1c/0x9c
pc : [<c06e864c>]    lr : [<c04b70f0>]    psr: 20000013
sp : dec73f30  ip : 00000000  fp : dec56d98
r10: df437cf0  r9 : c0a03008  r8 : c0145ffc
r7 : df5c4300  r6 : dec568d0  r5 : df593000  r4 : 0000017c
r3 : df592800  r2 : 60000013  r1 : df593000  r0 : 0000017c
Flags: nzCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment none
Control: 10c53c7d  Table: 20004059  DAC: 00000051
Process irq/48-m41t80 (pid: 613, stack limit = 0xb52d091e)
Stack: (0xdec73f30 to 0xdec74000)
3f20:                                     dec56840 df5c4300 00000001 df5c4300
3f40: c0145ffc c0146018 dec56840 ffffe000 00000001 c0146290 dec567c0 00000000
3f60: c0146084 ed7c9a62 c014615c dec56d80 dec567c0 00000000 dec72000 dec56840
3f80: c014615c c012ffc0 dec72000 dec567c0 c012fe80 00000000 00000000 00000000
3fa0: 00000000 00000000 00000000 c01010e8 00000000 00000000 00000000 00000000
3fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
3fe0: 00000000 00000000 00000000 00000000 00000013 00000000 29282726 2d2c2b2a
[<c06e864c>] (mutex_lock) from [<c04b70f0>] (m41t80_handle_irq+0x1c/0x9c)
[<c04b70f0>] (m41t80_handle_irq) from [<c0146018>] (irq_thread_fn+0x1c/0x54)
[<c0146018>] (irq_thread_fn) from [<c0146290>] (irq_thread+0x134/0x1c0)
[<c0146290>] (irq_thread) from [<c012ffc0>] (kthread+0x140/0x148)
[<c012ffc0>] (kthread) from [<c01010e8>] (ret_from_fork+0x14/0x2c)
Exception stack(0xdec73fb0 to 0xdec73ff8)
3fa0:                                     00000000 00000000 00000000 00000000
3fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
3fe0: 00000000 00000000 00000000 00000000 00000013 00000000
Code: e3c33d7f e3c3303f f5d0f000 e593300c (e1901f9f)
---[ end trace 22b027302eb7c604 ]---
genirq: exiting task "irq/48-m41t80" (613) is an active IRQ thread (irq 48)

Also, there is another 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* */

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

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: m41t80: move m41t80_rtc_mutex to the block where it is used
Sebastian Andrzej Siewior [Fri, 9 Feb 2018 18:05:34 +0000 (19:05 +0100)]
rtc: m41t80: move m41t80_rtc_mutex to the block where it is used

Without CONFIG_RTC_DRV_M41T80_WDT the compiler complains:

|drivers/rtc/rtc-m41t80.c:76 â€˜m41t80_rtc_mutex’ defined but not used [-Wunused-variable]

Move the variable to the block where it is used.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: pcf85063: remove useless indirection
Alexandre Belloni [Wed, 21 Feb 2018 15:09:27 +0000 (16:09 +0100)]
rtc: pcf85063: remove useless indirection

pcf85063_get_datetime and pcf85063_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>
6 years agortc: pcf85063: stop validating rtc_time in .read_time
Alexandre Belloni [Wed, 21 Feb 2018 15:07:34 +0000 (16:07 +0100)]
rtc: pcf85063: stop validating rtc_time in .read_time

The RTC core is always calling rtc_valid_tm after the read_time callback.
It is not necessary to call it before returning from the callback.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: max6900: remove useless indirection
Alexandre Belloni [Wed, 21 Feb 2018 15:04:27 +0000 (16:04 +0100)]
rtc: max6900: remove useless indirection

max6900_i2c_read_time and max6900_i2c_set_time are only used after casting
dev to an i2c_client. Remove that useless indirection.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: max6900: stop validating rtc_time in .read_time
Alexandre Belloni [Wed, 21 Feb 2018 15:01:52 +0000 (16:01 +0100)]
rtc: max6900: stop validating rtc_time in .read_time

The RTC core is always calling rtc_valid_tm after the read_time callback.
It is not necessary to call it before returning from the callback.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: rs5c372: remove useless indirection
Alexandre Belloni [Wed, 21 Feb 2018 14:47:14 +0000 (15:47 +0100)]
rtc: rs5c372: remove useless indirection

rs5c372_get_datetime and rs5c372_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>
6 years agortc: rs5c372: stop validating rtc_time in .read_time
Alexandre Belloni [Wed, 21 Feb 2018 14:43:53 +0000 (15:43 +0100)]
rtc: rs5c372: stop validating rtc_time in .read_time

The RTC core is always calling rtc_valid_tm after the read_time callback.
It is not necessary to call it before returning from the callback.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: rs5c372: remove useless message
Alexandre Belloni [Wed, 21 Feb 2018 14:42:32 +0000 (15:42 +0100)]
rtc: rs5c372: remove useless message

It is not necessary to print a message when the time is invalid as
userspace will already get an error (and an optional dev_dbg message).

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: s35390a: remove useless indirection
Alexandre Belloni [Wed, 21 Feb 2018 13:00:18 +0000 (14:00 +0100)]
rtc: s35390a: remove useless indirection

s35390a_set_datetime, s35390a_get_datetime, s35390a_set_alarm and
s35390a_read_alarm are only used after casting dev to an i2c_client. Remove
that useless indirection.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: s35390a: stop validating rtc_time in .read_time
Alexandre Belloni [Wed, 21 Feb 2018 12:54:46 +0000 (13:54 +0100)]
rtc: s35390a: stop validating rtc_time in .read_time

The RTC core is always calling rtc_valid_tm after the read_time callback.
It is not necessary to call it before returning from the callback.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: s35390a: remove useless message
Alexandre Belloni [Wed, 21 Feb 2018 12:52:35 +0000 (13:52 +0100)]
rtc: s35390a: remove useless message

It is not necessary to print a message when the time is invalid as
userspace will already get an error (and an optional dev_dbg message).

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: rk808: fix possible race condition
Alexandre Belloni [Wed, 21 Feb 2018 10:57:05 +0000 (11:57 +0100)]
rtc: rk808: fix possible race condition

The probe function is not allowed to fail after registering the RTC 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 register the rtc
as late as possible.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: rk808: remove useless debug message
Alexandre Belloni [Wed, 21 Feb 2018 10:48:46 +0000 (11:48 +0100)]
rtc: rk808: remove useless debug message

At probe time, printing a message when the time is invalid doesn't have
much value. Also, as the comment suggest, this is a leftover from
development wherhe this was used to set the RTc to a default time.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: rx8581: remove useless message
Alexandre Belloni [Tue, 20 Feb 2018 23:25:18 +0000 (00:25 +0100)]
rtc: rx8581: remove useless message

It is not necessary to print a message when the time is invalid as
userspace will already get an error (and an optional dev_dbg message).

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: rx4581: remove useless message
Alexandre Belloni [Tue, 20 Feb 2018 23:23:31 +0000 (00:23 +0100)]
rtc: rx4581: remove useless message

It is not necessary to print a message when the time is invalid as
userspace will already get an error (and an optional dev_dbg message).

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: pm8xxx: remove useless message
Alexandre Belloni [Tue, 20 Feb 2018 23:10:41 +0000 (00:10 +0100)]
rtc: pm8xxx: remove useless message

It is not necessary to print a message when the time is invalid as
userspace will already get an error (and an optional dev_dbg message).

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: abx80x: remove useless message
Alexandre Belloni [Tue, 20 Feb 2018 22:42:27 +0000 (23:42 +0100)]
rtc: abx80x: remove useless message

It is not necessary to print a message when the time is invalid as
userspace will already get an error (and an optional dev_dbg message).

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: tegra: stop validating rtc_time in .set_time
Alexandre Belloni [Wed, 21 Feb 2018 10:03:49 +0000 (11:03 +0100)]
rtc: tegra: stop validating rtc_time in .set_time

The RTC core is always validating the rtc_time struct before calling
.set_time. It is not necessary to do it again in .set_time.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: spear: stop validating rtc_time in .set_time and .set_alarm
Alexandre Belloni [Wed, 21 Feb 2018 10:23:19 +0000 (11:23 +0100)]
rtc: spear: stop validating rtc_time in .set_time and .set_alarm

The RTC core is always validating the rtc_time struct before calling
.set_time or .set_alarm. It is not necessary to do it again.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: omap: stop validating rtc_time in .set_time and .set_alarm
Alexandre Belloni [Wed, 21 Feb 2018 10:33:37 +0000 (11:33 +0100)]
rtc: omap: stop validating rtc_time in .set_time and .set_alarm

The RTC core is always validating the rtc_time struct before calling
.set_time or .set_alarm. It is not necessary to do it again.
Also, rtc_time_to_tm never generates an invalid rtc_tm (it can be out of
range though).

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: max77686: stop validating rtc_time in .read_time
Alexandre Belloni [Tue, 20 Feb 2018 23:05:20 +0000 (00:05 +0100)]
rtc: max77686: stop validating rtc_time in .read_time

The RTC core is always calling rtc_valid_tm after the read_time callback.
It is not necessary to call it just before returning from the callback.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: m41t93: stop validating rtc_time in .read_time
Alexandre Belloni [Tue, 20 Feb 2018 23:02:08 +0000 (00:02 +0100)]
rtc: m41t93: stop validating rtc_time in .read_time

The RTC core is always calling rtc_valid_tm after the read_time callback.
It is not necessary to call it just before returning from the callback.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: isl12022: remove useless indirection
Alexandre Belloni [Tue, 20 Feb 2018 22:55:40 +0000 (23:55 +0100)]
rtc: isl12022: remove useless indirection

isl12022_get_datetime and isl12022_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>
6 years agortc: sc27xx: stop validating rtc_time in .read_time
Alexandre Belloni [Mon, 19 Feb 2018 15:24:19 +0000 (16:24 +0100)]
rtc: sc27xx: stop validating rtc_time in .read_time

rtc_time64_to_tm never generates an invalid tm. It is not necessary to
validate it. Also, the RTC core is always calling rtc_valid_tm after the
read_time callback.

Reviewed-by: Baolin Wang <baolin.wang@linaro.org>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: r7301: stop validating rtc_time in .read_time
Alexandre Belloni [Tue, 20 Feb 2018 23:18:23 +0000 (00:18 +0100)]
rtc: r7301: stop validating rtc_time in .read_time

The RTC core is always calling rtc_valid_tm after the read_time callback.
It is not necessary to call it just before returning from the callback.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: nuc900: stop validating rtc_time in .read_time
Alexandre Belloni [Wed, 21 Feb 2018 10:27:10 +0000 (11:27 +0100)]
rtc: nuc900: stop validating rtc_time in .read_time

The RTC core is always calling rtc_valid_tm after the read_time callback.
It is not necessary to call it before returning from the callback.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: diasemi: stop validating rtc_time in .read_time
Alexandre Belloni [Fri, 2 Mar 2018 09:08:47 +0000 (10:08 +0100)]
rtc: diasemi: stop validating rtc_time in .read_time

The RTC core is always calling rtc_valid_tm after the read_time callback.
It is not necessary to call it before returning from the callback.

Acked-by: Steve Twiss <stwiss.opensource@diasemi.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: cpcap: stop validating rtc_time in .read_time
Alexandre Belloni [Mon, 19 Feb 2018 15:23:57 +0000 (16:23 +0100)]
rtc: cpcap: stop validating rtc_time in .read_time

The RTC core is always calling rtc_valid_tm after the read_time callback.
It is not necessary to call it just before returning from the callback.

Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: ab-b5ze-s3: stop validating rtc_time in .read_time
Alexandre Belloni [Mon, 19 Feb 2018 15:23:54 +0000 (16:23 +0100)]
rtc: ab-b5ze-s3: stop validating rtc_time in .read_time

The RTC core is always calling rtc_valid_tm after the read_time callback.
It is not necessary to call it just before returning from the callback.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: stop validating rtc_time in .read_time
Alexandre Belloni [Mon, 19 Feb 2018 15:23:56 +0000 (16:23 +0100)]
rtc: stop validating rtc_time in .read_time

The RTC core is always calling rtc_valid_tm after the read_time callback.
It is not necessary to call it just before returning from the callback.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: stop validating rtc_time after rtc_time_to_tm
Alexandre Belloni [Mon, 19 Feb 2018 15:23:55 +0000 (16:23 +0100)]
rtc: stop validating rtc_time after rtc_time_to_tm

rtc_time_to_tm never generates an invalid tm. It is not necessary to
validate it.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: stop validating rtc_time after rtc_time64_to_tm
Alexandre Belloni [Mon, 19 Feb 2018 15:23:55 +0000 (16:23 +0100)]
rtc: stop validating rtc_time after rtc_time64_to_tm

rtc_time64_to_tm never generates an invalid tm. It is not necessary to
validate it.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: stk17ta8: let the core handle invalid time
Alexandre Belloni [Sun, 18 Feb 2018 22:36:18 +0000 (23:36 +0100)]
rtc: stk17ta8: let the core handle invalid time

Returning a valid time when the time is invalid is a bad practice, because
then userspace is not able to react on the information. Also, it doesn't
make sense to return epoch because it is already the default time.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: rs5c348: let the core handle invalid time
Alexandre Belloni [Tue, 20 Feb 2018 23:20:43 +0000 (00:20 +0100)]
rtc: rs5c348: let the core handle invalid time

Returning a valid time when the time is invalid is a bad practice, because
then userspace is not able to react on the information. Also, it doesn't
make sense to return epoch because it is already the default time.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: cmos: let the core handle invalid time
Alexandre Belloni [Wed, 21 Feb 2018 10:44:26 +0000 (11:44 +0100)]
rtc: cmos: let the core handle invalid time

Setting the rtc to a valid time when the time is invalid is a bad practice,
because then userspace doesn't know it shouldn't trust the RTC.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: ds1553: let the core handle invalid time
Alexandre Belloni [Tue, 20 Feb 2018 22:43:09 +0000 (23:43 +0100)]
rtc: ds1553: let the core handle invalid time

Returning a valid time when the time is invalid is a bad practice, because
then userspace is not able to react on the information. Also, it doesn't
make sense to return epoch because it is already the default time.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: ds1511: let the core handle invalid time
Alexandre Belloni [Tue, 20 Feb 2018 21:05:29 +0000 (22:05 +0100)]
rtc: ds1511: let the core handle invalid time

Returning a valid time when the time is invalid is a bad practice, because
then userspace is not able to react on the information. Also, it doesn't
make sense to return epoch because it is already the default time.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: tx4939: avoid unintended sign extension on a 24 bit shift
Colin Ian King [Thu, 15 Feb 2018 19:36:14 +0000 (19:36 +0000)]
rtc: tx4939: avoid unintended sign extension on a 24 bit shift

The shifting of buf[5] by 24 bits to the left will be promoted to
a 32 bit signed int and then sign-extended to an unsigned long. If
the top bit of buf[5] is set then all then all the upper bits sec
end up as also being set because of the sign-extension. Fix this by
casting buf[5] to an unsigned long before the shift.

Detected by CoverityScan, CID#1465292 ("Unintended sign extension")

Fixes: 0e1492330cd2 ("rtc: add rtc-tx4939 driver")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agoMAINTAINERS: rtc: update my email address
Alexandre Belloni [Fri, 16 Feb 2018 10:06:00 +0000 (11:06 +0100)]
MAINTAINERS: rtc: update my email address

Free Electrons is now Bootlin.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agochar: rtc: remove unused rtc_control() API
Alexandre Belloni [Tue, 6 Feb 2018 22:12:26 +0000 (23:12 +0100)]
char: rtc: remove unused rtc_control() API

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>
6 years agortc: mxc_v2: Fix _iomem pointer notation
Fabio Estevam [Mon, 12 Feb 2018 02:38:46 +0000 (00:38 -0200)]
rtc: mxc_v2: Fix _iomem pointer notation

Fix the iomem pointer notation in order to fix the following sparse
warnings:

drivers/rtc/rtc-mxc_v2.c:280:18: warning: incorrect type in argument 1 (different address spaces)
drivers/rtc/rtc-mxc_v2.c:280:18:    expected void const volatile [noderef] <asn:2>*addr
drivers/rtc/rtc-mxc_v2.c:280:18:    got void *[noderef] <asn:2>ioaddr
drivers/rtc/rtc-mxc_v2.c:329:44: warning: incorrect type in argument 1 (different address spaces)
drivers/rtc/rtc-mxc_v2.c:329:44:    expected void *[noderef] <asn:2>ioaddr
drivers/rtc/rtc-mxc_v2.c:329:44:    got void [noderef] <asn:2>*
drivers/rtc/rtc-mxc_v2.c:339:44: warning: incorrect type in argument 1 (different address spaces)
drivers/rtc/rtc-mxc_v2.c:339:44:    expected void *[noderef] <asn:2>ioaddr
drivers/rtc/rtc-mxc_v2.c:339:44:    got void [noderef] <asn:2>*

Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: isl1208: Fix unintended clear of SR bits
Denis Osterland [Tue, 23 Jan 2018 12:17:58 +0000 (13:17 +0100)]
rtc: isl1208: Fix unintended clear of SR bits

After successful
sr = isl1208_i2c_set_regs(client, 0, regs, ISL1208_RTC_SECTION_LEN);
sr will be 0.
As a result
sr = i2c_smbus_write_byte_data(client, ISL1208_REG_SR,
sr & ~ISL1208_REG_SR_WRTC);
is equal to
sr = i2c_smbus_write_byte_data(client, ISL1208_REG_SR, 0);
which clears all flags in SR.

Add an additional read of SR, to have value of SR in sr again.

Signed-off-by: Denis Osterland <Denis.Osterland@diehl.com>
Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: tx4939: use generic nvmem
Alexandre Belloni [Mon, 12 Feb 2018 22:47:59 +0000 (23:47 +0100)]
rtc: tx4939: use generic nvmem

Instead of adding a binary sysfs attribute from the driver, use the core to
register an nvmem device.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: tx4939: fix possible race condition
Alexandre Belloni [Mon, 12 Feb 2018 22:47:58 +0000 (23:47 +0100)]
rtc: tx4939: fix possible race condition

The probe function is not allowed to fail after registering the RTC. Call
rtc_register_device() at the end.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: tx4939: switch to rtc_register_device
Alexandre Belloni [Mon, 12 Feb 2018 22:47:57 +0000 (23:47 +0100)]
rtc: tx4939: switch to rtc_register_device

This allows for future improvement of the driver.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: tx4939: extend test coverage
Alexandre Belloni [Mon, 12 Feb 2018 22:47:56 +0000 (23:47 +0100)]
rtc: tx4939: extend test coverage

The rtc-tx4939 driver now compiles correctly on other architectures, add
COMPILE_TEST to improve code coverage.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: tx4939: remove arch/mips dependency
Alexandre Belloni [Mon, 12 Feb 2018 22:47:55 +0000 (23:47 +0100)]
rtc: tx4939: remove arch/mips dependency

Copy RTC definitions from arch/mips/include/asm/txx9/tx4939.h to the RTC
driver so it doesn't depend on arch/mips anymore.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: stk17ta8: use generic nvmem
Alexandre Belloni [Mon, 12 Feb 2018 22:47:54 +0000 (23:47 +0100)]
rtc: stk17ta8: use generic nvmem

Instead of adding a binary sysfs attribute from the driver, use the core to
register an nvmem device.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: stk17ta8: fix possible race condition
Alexandre Belloni [Mon, 12 Feb 2018 22:47:53 +0000 (23:47 +0100)]
rtc: stk17ta8: fix possible race condition

The probe function is not allowed to fail after registering the RTC. Call
rtc_register_device() at the end.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: stk17ta8: switch to rtc_register_device
Alexandre Belloni [Mon, 12 Feb 2018 22:47:52 +0000 (23:47 +0100)]
rtc: stk17ta8: switch to rtc_register_device

This allows for future improvement of the driver.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: stk17ta8: make alarms useful
Alexandre Belloni [Mon, 12 Feb 2018 22:47:51 +0000 (23:47 +0100)]
rtc: stk17ta8: make alarms useful

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 wakeup the platform.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: rp5c01: use generic nvmem
Alexandre Belloni [Mon, 12 Feb 2018 22:47:50 +0000 (23:47 +0100)]
rtc: rp5c01: use generic nvmem

Instead of adding a binary sysfs attribute from the driver, use the core to
register an nvmem device.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: rp5c01: fix possible race condition
Alexandre Belloni [Mon, 12 Feb 2018 22:47:49 +0000 (23:47 +0100)]
rtc: rp5c01: fix possible race condition

The probe function is not allowed to fail after registering the RTC 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 register the rtc
as late as possible.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: ds1742: use generic nvmem
Alexandre Belloni [Mon, 12 Feb 2018 22:47:48 +0000 (23:47 +0100)]
rtc: ds1742: use generic nvmem

Instead of adding a binary sysfs attribute from the driver (which suffers
from a race condition as the attribute appears after the device), use the
core to register an nvmem device.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: ds1742: switch to rtc_register_device
Alexandre Belloni [Mon, 12 Feb 2018 22:47:47 +0000 (23:47 +0100)]
rtc: ds1742: switch to rtc_register_device

This allows for future improvement of the driver.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: cmos: use generic nvmem
Alexandre Belloni [Mon, 12 Feb 2018 22:47:46 +0000 (23:47 +0100)]
rtc: cmos: use generic nvmem

Instead of adding a binary sysfs attribute from the driver, use the
core to register an nvmem device. This allows to use the in-kernel
interface to access the nvram.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: cmos: fix possible race condition
Alexandre Belloni [Mon, 12 Feb 2018 22:47:45 +0000 (23:47 +0100)]
rtc: cmos: fix possible race condition

The probe function is not allowed to fail after registering the RTC 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 register the rtc
as late as possible.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: ds1553: make alarms useful
Alexandre Belloni [Mon, 12 Feb 2018 22:47:44 +0000 (23:47 +0100)]
rtc: ds1553: make alarms useful

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 wakeup the platform.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: ds1553: use generic nvmem
Alexandre Belloni [Mon, 12 Feb 2018 22:47:43 +0000 (23:47 +0100)]
rtc: ds1553: use generic nvmem

Instead of adding a binary sysfs attribute from the driver (which suffers
from a race condition as the attribute appears after the device), use the
core to register an nvmem device.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: ds1553: switch to rtc_register_device
Alexandre Belloni [Mon, 12 Feb 2018 22:47:42 +0000 (23:47 +0100)]
rtc: ds1553: switch to rtc_register_device

This allows for future improvement of the driver.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: sirfsoc: remove useless sirfsoc_rtc_ioctl
Alexandre Belloni [Mon, 12 Feb 2018 22:47:41 +0000 (23:47 +0100)]
rtc: sirfsoc: remove useless sirfsoc_rtc_ioctl

sirfsoc_rtc_ioctl() doesn't implement any actual ioctl, remove it.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: m48t59: use generic nvmem
Alexandre Belloni [Mon, 12 Feb 2018 22:47:40 +0000 (23:47 +0100)]
rtc: m48t59: use generic nvmem

Instead of adding a binary sysfs attribute from the driver (which suffers
from a race condition as the attribute appears after the device), use the
core to register an nvmem device.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: m48t59: switch to rtc_register_device
Alexandre Belloni [Mon, 12 Feb 2018 22:47:39 +0000 (23:47 +0100)]
rtc: m48t59: switch to rtc_register_device

This allows for future improvement of the driver.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: ds1343: use generic nvmem
Alexandre Belloni [Mon, 12 Feb 2018 22:47:38 +0000 (23:47 +0100)]
rtc: ds1343: use generic nvmem

Instead of adding a binary sysfs attribute from the driver (which suffers
from a race condition as the attribute appears after the device), use the
core to register an nvmem device.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: ds1343: remove undocumented and useless sysfs files
Alexandre Belloni [Mon, 12 Feb 2018 22:47:37 +0000 (23:47 +0100)]
rtc: ds1343: remove undocumented and useless sysfs files

A documented ABI already exists to get information about the alarm. It is
the only one that is used.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: ds1343: switch to rtc_register_device
Alexandre Belloni [Mon, 12 Feb 2018 22:47:36 +0000 (23:47 +0100)]
rtc: ds1343: switch to rtc_register_device

This allows for future improvement of the driver.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: ds1343: simplify regmap initialization
Alexandre Belloni [Mon, 12 Feb 2018 22:47:35 +0000 (23:47 +0100)]
rtc: ds1343: simplify regmap initialization

Avoid using memset as gcc can properly initialize structures.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: remove nvmem_config
Alexandre Belloni [Mon, 12 Feb 2018 22:47:34 +0000 (23:47 +0100)]
rtc: remove nvmem_config

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>
6 years agortc: rv8803: fix possible race condition
Alexandre Belloni [Mon, 12 Feb 2018 22:47:33 +0000 (23:47 +0100)]
rtc: rv8803: fix possible race condition

The probe function is not allowed to fail after registering the RTC. Call
rtc_register_device() at the end.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
6 years agortc: rv8803: put struct nvmem_config on the stack
Alexandre Belloni [Mon, 12 Feb 2018 22:47:32 +0000 (23:47 +0100)]
rtc: rv8803: put struct nvmem_config on the stack

Avoid allocating memory for struct nvmem_config.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>