Commit Graph

737155 Commits

Author SHA1 Message Date
Alexandre Belloni
dd888c61c9 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>
2018-03-01 10:49:35 +01:00
Alexandre Belloni
a2fa9b8e5a 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>
2018-03-01 10:49:35 +01:00
Alexandre Belloni
68981fd151 rtc: tx4939: switch to rtc_register_device
This allows for future improvement of the driver.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-03-01 10:49:34 +01:00
Alexandre Belloni
faec5f7bcc 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>
2018-03-01 10:49:34 +01:00
Alexandre Belloni
a0151062ea 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>
2018-03-01 10:49:33 +01:00
Alexandre Belloni
d7ca4299d7 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>
2018-03-01 10:49:33 +01:00
Alexandre Belloni
8d3e6b55ce 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>
2018-03-01 10:49:32 +01:00
Alexandre Belloni
91cb6774f6 rtc: stk17ta8: switch to rtc_register_device
This allows for future improvement of the driver.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-03-01 10:49:32 +01:00
Alexandre Belloni
8f21092d65 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>
2018-03-01 10:49:31 +01:00
Alexandre Belloni
7335fb9be3 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>
2018-03-01 10:49:31 +01:00
Alexandre Belloni
bcdd559268 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>
2018-03-01 10:49:30 +01:00
Alexandre Belloni
87c78d9512 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>
2018-03-01 10:49:30 +01:00
Alexandre Belloni
1358e7b2b3 rtc: ds1742: switch to rtc_register_device
This allows for future improvement of the driver.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-03-01 10:49:29 +01:00
Alexandre Belloni
8b5b7958fd 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>
2018-03-01 10:49:29 +01:00
Alexandre Belloni
53d29e0a3a 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>
2018-03-01 10:49:29 +01:00
Alexandre Belloni
1af7068d2a 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>
2018-03-01 10:49:28 +01:00
Alexandre Belloni
3a9a06d44b 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>
2018-03-01 10:49:28 +01:00
Alexandre Belloni
18c88cc9b0 rtc: ds1553: switch to rtc_register_device
This allows for future improvement of the driver.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-03-01 10:49:27 +01:00
Alexandre Belloni
11ad0b613d 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>
2018-03-01 10:49:27 +01:00
Alexandre Belloni
0ff3565d88 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>
2018-03-01 10:49:26 +01:00
Alexandre Belloni
affb842b84 rtc: m48t59: switch to rtc_register_device
This allows for future improvement of the driver.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-03-01 10:49:26 +01:00
Alexandre Belloni
d7501f7094 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>
2018-03-01 10:49:25 +01:00
Alexandre Belloni
ab39286403 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>
2018-03-01 10:49:25 +01:00
Alexandre Belloni
1536f6dc9d rtc: ds1343: switch to rtc_register_device
This allows for future improvement of the driver.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-03-01 10:49:24 +01:00
Alexandre Belloni
b5086150a6 rtc: ds1343: simplify regmap initialization
Avoid using memset as gcc can properly initialize structures.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-03-01 10:49:24 +01:00
Alexandre Belloni
0391df74a6 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>
2018-03-01 10:49:23 +01:00
Alexandre Belloni
ce1ae8eb83 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>
2018-03-01 10:49:23 +01:00
Alexandre Belloni
c07fd9dea2 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>
2018-03-01 10:49:22 +01:00
Alexandre Belloni
88d3aadea0 rtc: rv8803: call rtc_nvmem_register()
Call rtc_nvmem_register instead of letting the core do it and stop using
the nvmem_config member of struct rtc_device.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-03-01 10:49:22 +01:00
Alexandre Belloni
0e7a412fa2 rtc: pcf85363: put struct nvmem_config on the stack
Avoid allocating memory for struct nvmem_config.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-03-01 10:49:21 +01:00
Alexandre Belloni
24849d177c rtc: pcf85363: call rtc_nvmem_register()
Call rtc_nvmem_register instead of letting the core do it and stop using
the nvmem_config member of struct rtc_device.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-03-01 10:49:20 +01:00
Alexandre Belloni
ce603842c2 rtc: omap: call rtc_nvmem_register()
Call rtc_nvmem_register instead of letting the core do it and stop using
the nvmem_config member of struct rtc_device.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-03-01 10:49:20 +01:00
Alexandre Belloni
e3f51c0d29 rtc: m48t86: put m48t86_nvmem_cfg on the stack
Move m48t86_nvmem_cfg to the stack of m48t86_rtc_probe. This results in a
very small code size reduction and make it safer on systems with two
similar RTCs:

   text	   data	    bss	    dec	    hex	filename
   1733	    164	      0	   1897	    769	drivers/rtc/rtc-m48t86.o.before
   1793	    100	      0	   1893	    765	drivers/rtc/rtc-m48t86.o.after

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-03-01 10:49:19 +01:00
Alexandre Belloni
3c1bb61fad rtc: m48t86: call rtc_nvmem_register()
Call rtc_nvmem_register instead of letting the core do it and stop using
the nvmem_config member of struct rtc_device.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-03-01 10:49:18 +01:00
Alexandre Belloni
71e19c5e25 rtc: ds1511: put ds1511_nvmem_cfg on the stack
Move ds1511_nvmem_cfg to the stack of ds1511_rtc_probe. This results in a
very small code size reduction and make it safer on systems with two
similar RTCs:

   text	   data	    bss	    dec	    hex	filename
   2128	    164	      4	   2296	    8f8	drivers/rtc/rtc-ds1511.o.before
   2175	    100	      4	   2279	    8e7	drivers/rtc/rtc-ds1511.o.after

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-03-01 10:49:18 +01:00
Alexandre Belloni
16fef39142 rtc: ds1511: call rtc_nvmem_register()
Call rtc_nvmem_register instead of letting the core do it and stop using
the nvmem_config member of struct rtc_device.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-03-01 10:49:17 +01:00
Alexandre Belloni
409baf1785 rtc: ds1307: put struct nvmem_config on the stack
Avoid allocating memory for struct nvmem_config as it is only necessary at
the nvmem registration.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-03-01 10:49:17 +01:00
Alexandre Belloni
e9fb7682fa rtc: ds1307: call rtc_nvmem_register()
Call rtc_nvmem_register instead of letting the core do it and stop using
the nvmem_config member of struct rtc_device.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-03-01 10:49:16 +01:00
Alexandre Belloni
eed9d7a335 rtc: ds1305: put ds1305_nvmem_cfg on the stack
This makes to code safer on system using two similar RTCs.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-03-01 10:49:16 +01:00
Alexandre Belloni
6910614f1e rtc: ds1305: call rtc_nvmem_register()
Call rtc_nvmem_register instead of letting the core do it and stop using
the nvmem_config member of struct rtc_device.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-03-01 10:49:15 +01:00
Alexandre Belloni
fd5cd21d99 rtc: export rtc_nvmem_register() to drivers
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>
2018-03-01 10:49:15 +01:00
Alexandre Belloni
ac75779b72 rtc: nvmem: allow registering the nvmem device before the rtc
Switch the parent of the nvmem device to the parent of the rtc device so it
can be registered before the RTC.

This is a small change in the ABI as the nvmem moves out of the
/sys/class/rtc/rtcX folder to be under the parent device folder (that is
where the previous nvram files where registered).

However, it is still available under its correct location,
/sys/bus/nvmem/devices which is the one that should be used by userspace
applications.

The other benefit is that the nvmem device can stay registered even if the
rtc registration fails. Or it is possible to not register the rtc if the
nvmem registration failed.

Finally, it makes a lot of sense for devices that actually have different
i2c or spi addresses for the RTC and the EEPROM. That is basically how it
would end up when using MFD or even completely separate devices.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-03-01 10:49:14 +01:00
Alexandre Belloni
ab3ea36eda rtc: nvmem: disallow registering nvmem more than once
Make rtc_nvmem_register return -EBUSY when an nvmem is already registered
for that RTC.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-02-14 20:58:16 +01:00
Alexandre Belloni
2cc8212198 rtc: nvmem: return error values
In case of error, make rtc_nvmem_register() able to return an error value
to its caller.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-02-14 20:58:13 +01:00
Alexandre Belloni
4cce9d3988 rtc: nvmem: pass nvmem_config to rtc_nvmem_register()
To be able to remove nvmem_config from struct rtc_device, pass it as a
parameter to rtc_nvmem_register.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-02-14 20:58:11 +01:00
Alexandre Belloni
7b21db9184 rtc: documentation: correct nvmem date and version
The nvmem interface appaeared in linux 4.13

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-02-14 20:58:10 +01:00
Colin Ian King
5134d2fd9f rtc: ds1302: remove redundant initializations of pointer bp
Pointe bp is being initialized and this value is never read, it
is being updated to the same value later just before it is going to
be used. Remove the initialization as it is never read and keep
the setting of bp closer to the use of bp.

Cleans up clang warnings:
drivers/rtc/rtc-ds1302.c:115:7: warning: Value stored to 'bp' during
its initialization is never read
drivers/rtc/rtc-ds1302.c:46:7: warning: Value stored to 'bp' during
its initialization is never read

Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-02-13 21:46:06 +01:00
James Hogan
82d632b85e rtc: goldfish: Add missing MODULE_LICENSE
Fix the following warning in MIPS allmodconfig by adding a
MODULE_LICENSE() at the end of rtc-goldfish.c, based on the file header
comment which says GNU General Public License version 2:

WARNING: modpost: missing MODULE_LICENSE() in drivers/rtc/rtc-goldfish.o

Fixes: f22d9cdcb5 ("rtc: goldfish: Add RTC driver for Android emulator")
Signed-off-by: James Hogan <jhogan@kernel.org>
Cc: Miodrag Dinic <miodrag.dinic@mips.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Cc: linux-rtc@vger.kernel.org
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-02-13 21:46:04 +01:00
Baolin Wang
36d46cdb43 rtc: Fix overflow when converting time64_t to rtc_time
If we convert one large time values to rtc_time, in the original formula
'days * 86400' can be overflowed in 'unsigned int' type to make the formula
get one incorrect remain seconds value. Thus we can use div_s64_rem()
function to avoid this situation.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-02-13 21:30:28 +01:00
Baolin Wang
29a1f599c0 rtc: Add tracepoints for RTC system
It will be more helpful to add some tracepoints to track RTC actions when
debugging RTC driver. Below sample is that we set/read the RTC time, then
set 2 alarms, so we can see the trace logs:

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

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

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

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

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

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

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-02-13 21:30:22 +01:00