Commit graph

2947 commits

Author SHA1 Message Date
Giulio Benetti
7e580769b7 rtc: ds1307: support m41t11 variant
The m41t11 variant is very similar to the already supported m41t00 and
m41t0, but it has also 56 bytes of NVRAM.

Add it to driver taking into account NVRAM section.

Signed-off-by: Giulio Benetti <giulio.benetti@micronovasrl.com>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-07-16 23:36:24 +02:00
Giulio Benetti
146a552c67 rtc: ds1307: fix data pointer to m41t0
data field points to m41t00, instead it should point to m41t0.
Driver works correctly because on both cases(m41t0 and m41t00) chip_desc
are equal.

Point to right enum m41t0 instead of m41t00.

Signed-off-by: Giulio Benetti <giulio.benetti@micronovasrl.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-07-16 23:36:23 +02:00
Greg Kroah-Hartman
83cf9cd6d5 Merge 4.18-rc5 into char-misc-next
We want the char-misc fixes in here as well.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-16 09:04:54 +02:00
Arnd Bergmann
5089ea15ba rtc: use ktime_get_real_ts64() instead of getnstimeofday64()
getnstimeofday64() is just a wrapper around the ktime accessor, so
we should use that directly.

I considered using ktime_get_boottime_ts64() (to avoid leap second
problems) or ktime_get_real_seconds() (to simplify the calculation,
but in the end concluded that the existing interface is probably
the most appropriate in this case.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-07-13 10:47:18 +02:00
Alexandre Belloni
fd6792bb02 rtc: fix alarm read and set offset
The offset needs to be added after reading the alarm value.

It also needs to be subtracted after the now < alarm test.

Tested-by: Jon Hunter <jonathanh@nvidia.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-07-13 10:37:54 +02:00
Colin Ian King
fed0b1bd1b rtc: m48t59: remove redundant pointer 'name'
Pointer 'name' is being assigned but is never used hence it is redundant
and can be removed.

Cleans up clang warning:
warning: variable 'name' set but not used [-Wunused-but-set-variable]

Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-07-12 21:17:36 +02:00
Johan Hovold
b9cfb3d120 rtc: omap: drop unnecessary register unlock around reads
Drop unnecessary register write-unlock around two read accesses.

Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-07-12 20:31:21 +02:00
Johan Hovold
4425070a5c rtc: omap: add missing register lock in error path
For completeness re-lock the registers also in the power-off error path.

Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-07-12 20:31:19 +02:00
Johan Hovold
551757eb05 rtc: omap: fix resource leak in registration error path
Make sure to deregister the pin controller in case rtc registration
fails.

Fixes: 5707275862 ("rtc: omap: switch to rtc_register_device")
Cc: stable <stable@vger.kernel.org>     # 4.14
Cc: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-07-12 20:31:18 +02:00
Johan Hovold
5c8b84f410 rtc: omap: fix potential crash on power off
Do not set the system power-off callback and omap power-off rtc pointer
until we're done setting up our device to avoid leaving stale pointers
around after a late probe error.

Fixes: 97ea1906b3 ("rtc: omap: Support ext_wakeup configuration")
Cc: stable <stable@vger.kernel.org>     # 4.9
Cc: Marcin Niestroj <m.niestroj@grinn-global.com>
Cc: Tony Lindgren <tony@atomide.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
Acked-by: Tony Lindgren <tony@atomide.com>
Reviewed-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-07-12 20:31:17 +02:00
Colin Ian King
2b4f07e99e rtc: test: make array pdev static
The array pdev is local to the source and does not need to be in
global scope, so make it static.

Cleans up sparse warning:
symbol 'pdev' was not declared. Should it be static?

Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-07-12 20:16:10 +02:00
Baruch Siach
1a990fefb6 rtc: armada38x: reset after rtc power loss
When the RTC block looses power it needs a reset sequence to make it
usable again. Otherwise, writes to the time register have no effect.

This reset sequence combines information from the mvebu_rtc driver in
the Marvell provided U-Boot, and the SolidRun provided U-Boot repo.

Tested on the Armada 388 based SolidRun Clearfog Base.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Acked-by: Gregory CLEMENT <gregory.clement@bootlin.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-07-12 20:16:08 +02:00
Uwe Kleine-König
dff700fa81 rtc: stmp3xxx: Don't reset the rtc in .probe() when watchdog is running
As pointed out in the added comment resetting the rtc also stops the
included watchdog. This is bad if the bootloader started the watchdog to
secure the boot process. So don't reset if the watchdog is running.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-07-11 20:42:08 +02:00
Uwe Kleine-König
d6c3029f32 rtc: pcf2127: add support for accessing internal static RAM
The PCF2127 has 512 bytes of internal static RAM and this patch expands
the driver to access this memory.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-07-11 20:41:22 +02:00
Trent Piepho
cd7f3a249d rtc: snvs: Add timeouts to avoid kernel lockups
In order to read correctly from asynchronously updated RTC registers,
it's necessary to read repeatedly until their values do not change from
read to read.  It's also necessary to wait for three RTC clock ticks for
certain operations.  There are no timeouts in this code and these
operations could possibly loop forever.

To avoid kernel hangs, put in timeouts.

The iMX7d can be configured to stop the SRTC on a tamper event, which
will lockup the kernel inside this driver as described above.

These hangs can happen when running under qemu, which doesn't emulate
the SNVS RTC, though currently the driver will refuse to load on qemu
due to a timeout in the driver probe method.

It could also happen if the SRTC block where somehow placed into reset
or the slow speed clock that drives the SRTC counter (but not the CPU)
were to stop.

The symptoms on a two core iMX7d are a work queue hang on
rtc_timer_do_work(), which eventually blocks a systemd fsnotify
operation that triggers a work queue flush, causing systemd to hang and
thus causing all services that should be started by systemd, like a
console getty, to fail to start or stop.

Also optimize the wait code to wait less.  It only needs to wait for the
clock to advance three ticks, not to see it change three times.

Cc: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Fabio Estevam <fabio.estevam@nxp.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Bryan O'Donoghue <pure.logic@nexus-software.ie>
Signed-off-by: Trent Piepho <tpiepho@impinj.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-07-11 20:41:09 +02:00
Zhouyang Jia
7874b91986 rtc: bq4802: add error handling for devm_ioremap
When devm_ioremap fails, the lack of error-handling code may
cause unexpected results.

This patch adds error-handling code after calling devm_ioremap.

Signed-off-by: Zhouyang Jia <jiazhouyang09@gmail.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-07-11 20:41:01 +02:00
Randy Dunlap
ac3167257b headers: separate linux/mod_devicetable.h from linux/platform_device.h
At over 4000 #includes, <linux/platform_device.h> is the 9th most
#included header file in the Linux kernel.  It does not need
<linux/mod_devicetable.h>, so drop that header and explicitly add
<linux/mod_devicetable.h> to source files that need it.

   4146 #include <linux/platform_device.h>

After this patch, there are 225 files that use <linux/mod_devicetable.h>,
for a reduction of around 3900 times that <linux/mod_devicetable.h>
does not have to be read & parsed.

    225 #include <linux/mod_devicetable.h>

This patch was build-tested on 20 different arch-es.

It also makes these drivers SubmitChecklist#1 compliant.

Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
Reported-by: kbuild test robot <lkp@intel.com> # drivers/media/platform/vimc/
Reported-by: kbuild test robot <lkp@intel.com> # drivers/pinctrl/pinctrl-u300.c
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-07 17:52:26 +02:00
Dan Carpenter
ca95ef7c98 rtc: mrst: fix error code in probe()
We should be returning "retval".  The "mrst_rtc.rtc" variable is a valid
pointer.

Fixes: 32b41f93dc ("rtc: mrst: switch to devm functions")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-06-20 12:43:11 +02:00
Alexandre Belloni
a41efe03e6 rtc: ds1685: remove sysfs access to control registers
Access to the control registers is mostly not needed and can cause runtime
issues (like missed interrupts). Remove this debugging interface.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-06-20 12:38:14 +02:00
Alexandre Belloni
30a5271d45 rtc: ds1685: remove improper datetime access ABI
The driver exposes an undocumented ABI to access the date and time
registers. It is not actually used by any userspace tools. Remove it.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-06-20 12:36:04 +02:00
Linus Torvalds
883cad5ba8 - New Device Support
- Add support for AXP813 ADC to AXP20x
    - Add support for PM8005, PM8998 and PMI8998
 
  - New Functionality
    - Add support for Battery Power Supply to AXP813
    - Add support for SYSCON to SPARD SC27XX SPI
    - Add support for RTC to ChromeOS Embedded-Controller
 
  - Fix-ups
    - Remove unused code; exynos{4,5}-pmu, cros_ec, cros_ec_acpi_gpe
    - Remove duplicate error messages (-ENOMEM, etc); htc-i2cpld, janz-cmodio,
 		max8997, rc5t583, sm501, smsc-ece1099, abx500-core, si476x-i2c,
 		ti_am335x_tscadc, tps65090, tps6586x, tps65910, tps80031,
 		twl6030-irq, viperboard
    - Succinctly use ptr to struct in sizeof(); rc5t583, abx500-core, sm501,
 		smsc-ece1099
    - Simplify syntax for NULL ptr checking; abx500-core, sm501
    - No not unnecessarily initialise variables; tps65910, tps65910
    - Reorganise and simplify driver data; omap-usb-tll
    - Move to SPDX license statement; tps68470
    - Probe ADCs via DT; axp20x
    - Use new GPIOD API; arizona-core
    - Constify things; axp20x
    - Reduce code-size (use MACROS, etc); axp20x, omap-usb-host
    - Add DT support/docs; motorola-cpcap
    - Remove VLAs; rave-sp
    - Use devm_* managed resources; cros_ec
    - Interrogate HW for firmware version; rave-sp
    - Provide ACPI support for ChromeOS Embedded-Controller
 
  - Bug Fixes
    - Reorder ordered (enum) device list; tps65218
    - Only accept valid data from the offset; rave-sp
    - Refrain from copying junk from failed SPI read; cros_ec_dev
    - Fix potential memory leaks; pcf50633-core
    - Fix clock initialisation; twl-core
    - Fix build-issue; tps65911
    - Fix off-by-one error; tps65911
    - Fix code ordering issues; intel-lpss
    - Fix COMPILE_TEST related issues; pwm-stm32
    - Fix broken MMC card detection; asic3
    - Fix clocking related issues; intel-lpss-pci
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEdrbJNaO+IJqU8IdIUa+KL4f8d2EFAlsea+sACgkQUa+KL4f8
 d2Fc+A//aaFlfHfJh337tvmJ6wC8w13jjXn0f2M2NrCvRS1CoMF/WqSmJbFGguET
 gwv4v8Yf5mWe9crJfSLR4b6hlNWfvzK9Rxwy1WJ8sfnN7a71SIS6LlapxQwZ0S5o
 3tQ8n2YKdIyy6feATKnxzRi6IvTjTsIe6BRYev2+m23cEqxoI7b6xo0H1CApVXez
 vEnPaT08421qZ2vuPx3UW3JgwWMTYe4iazq1BRkveZZBdyQC+GLpdpoJIO5/OziF
 Wgn01Hluu11YuAPidxtmLCAI23RcqLNcPB0zu6//CG5+ut71qnQRs6ua4R352nME
 G6aMRVCTR1b0XY48MK+IOLb7mPCCUByHdvdaonzBd48dIrX6k//kVzYxNKY1vlmk
 //l/cYhnHBZxGvJAvCmtyi+4AjGz0aLcabY6S7qHMvpNMQ7oNU9FDomJXxynjXg9
 ulDkA4EJy6jlWDS6h0u99xycyLuQ4wKo997/Sl5SU+9FBFrdOor2q7R4KfIXQsG9
 VGZXi2kWBO9V9oFbbo1oyZ52hDiCy2TKz6fk0rdRltOpVMd4PYluETc4nmnWDo5W
 hvjP3rIJSSSIcpggOoQMp5L03cONPGP4MdiuCXOREc6q476CFtpEgJMWApgaEUjw
 e1SE8HMKounqw0JYLVz3Lf0RbcHPuR1PN5HDbrchDb8LaAAyCcA=
 =NF/E
 -----END PGP SIGNATURE-----

Merge tag 'mfd-next-4.18' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd

Pull MFD updates from Lee Jones:
 "New Device Support:
   - Add support for AXP813 ADC to AXP20x
   - Add support for PM8005, PM8998 and PMI8998

  New Functionality:
   - Add support for Battery Power Supply to AXP813
   - Add support for SYSCON to SPARD SC27XX SPI
   - Add support for RTC to ChromeOS Embedded-Controller

  Fix-ups:
   - Remove unused code; exynos{4,5}-pmu, cros_ec, cros_ec_acpi_gpe
   - Remove duplicate error messages (-ENOMEM, etc); htc-i2cpld,
        janz-cmodio, max8997, rc5t583, sm501, smsc-ece1099, abx500-core,
        si476x-i2c, ti_am335x_tscadc, tps65090, tps6586x, tps65910,
        tps80031, twl6030-irq, viperboard
   - Succinctly use ptr to struct in sizeof(); rc5t583, abx500-core,
        sm501, smsc-ece1099
   - Simplify syntax for NULL ptr checking; abx500-core, sm501
   - No not unnecessarily initialise variables; tps65910, tps65910
   - Reorganise and simplify driver data; omap-usb-tll
   - Move to SPDX license statement; tps68470
   - Probe ADCs via DT; axp20x
   - Use new GPIOD API; arizona-core
   - Constify things; axp20x
   - Reduce code-size (use MACROS, etc); axp20x, omap-usb-host
   - Add DT support/docs; motorola-cpcap
   - Remove VLAs; rave-sp
   - Use devm_* managed resources; cros_ec
   - Interrogate HW for firmware version; rave-sp
   - Provide ACPI support for ChromeOS Embedded-Controller

  Bug Fixes:
   - Reorder ordered (enum) device list; tps65218
   - Only accept valid data from the offset; rave-sp
   - Refrain from copying junk from failed SPI read; cros_ec_dev
   - Fix potential memory leaks; pcf50633-core
   - Fix clock initialisation; twl-core
   - Fix build-issue; tps65911
   - Fix off-by-one error; tps65911
   - Fix code ordering issues; intel-lpss
   - Fix COMPILE_TEST related issues; pwm-stm32
   - Fix broken MMC card detection; asic3
   - Fix clocking related issues; intel-lpss-pci"

* tag 'mfd-next-4.18' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd: (84 commits)
  mfd: cros_ec: Remove unused __remove function
  mfd: wm97xx-core: Platform data can be NULL
  mfd: cros_ec_dev: Don't advertise junk features on failure
  mfd: cros_ec: Use devm_kzalloc for private data
  mfd: intel-lpss: Fix Intel Cannon Lake LPSS I2C input clock
  mfd: asic3: Fix broken MMC card detection
  mfd: timberdale: Fix spelling mistake "Uknown" -> "Unknown"
  mfd: omap-usb-host: Use match_string() helper
  mfd: stm32-timers: Fix pwm-stm32 linker issue with COMPILE_TEST
  pwm: stm32: Initialize raw local variables
  mfd: arizona: Update DT doc to support more standard Reset binding
  dt-bindings: mfd: Add bindings for DA9063L
  mfd: intel-lpss: Correct names of RESETS register bits
  mfd: qcom-spmi-pmic: Add support for pm8005, pm8998 and pmi8998
  mfd: intel-lpss: Program REMAP register in PIO mode
  mfd: cros_ec_i2c: Moving the system sleep pm ops to late
  mfd: cros_ec_i2c: Add ACPI module device table
  mfd: cros_ec_dev: Register shutdown function for debugfs
  mfd: cros_ec_dev: Register cros-ec-rtc driver as a subdevice
  mfd: cros_ec: Don't try to grab log when suspended
  ...
2018-06-11 07:20:17 -07:00
Linus Torvalds
1aaccb5fa0 RTC for 4.18
Subsystem:
  - rework of the rtc-test driver which allows to test the core more thoroughly
  - rtc_set_alarm() now fails early when alarms are not supported
 
 Drivers:
  - mktime is now replaced by mktime64
  - RTC range added for 88pm80x, ab-b5ze-s3, at91rm9200, brcmstb-waketimer,
    ds1685, ftrtc010, ls1x, mxc_v2, rx8581, sprd, st-lpc, tps6586x, tps65910 and
    vr41xx
  - Fixed a possible race condition in probe functions
  - pxa: fix the probe function that is broken since v4.3
  - stm32: now supports stm32mp1
 -----BEGIN PGP SIGNATURE-----
 
 iQIyBAABCgAdFiEEXx9Viay1+e7J/aM4AyWl4gNJNJIFAlsdkVAACgkQAyWl4gNJ
 NJJMfA/3YzFFxsZZdcf84e3LWMwgA12c/YNM24nlQ3S+Fo23bAerGZyKEroBAaiq
 HVL7j6OwYkVrGJHbqvq7J0UhI0J9Fjbtp8suj7Cj5wBKOG3wUeTkpzBiHZN42WBB
 PpPC97z9HRTVjxAOmWC0wbbf622ZBOZyEti3kMVh5DwER+8iNoPJWUS6nmZdOVqR
 PjT/c79WCT3q7n2j9t+ZjQfVOqPlqTTty3WuCpYDu3ce3W7uUO/cISc3M4HA4A5d
 dw6gDcd9WQcf4qZESjlci84pn4Ktha317fX5QlkaKM2ul3x33652pbH8Yv6ynZsq
 ZlmIyE9vSWThBWUj7R4lo9/y2IsVL5FtMRIN5bvG6ms/tPuZGeX/qAZEBgMggN+r
 PgFY5U+k/1WkOeSMd4OpuE9g308wzR3xGIhtuiJOa006hvHNvyMunIeMURDWjceW
 fh1uu1eUQqf4yKt8ceB9s38pYcPrvtEOh9006VcHMp/JJpoOjIn93jdsaxCmlUZc
 poDAYgH+RudVaaMZ4VvZjzlrD/diSwjh51MpBf0ImdQut4ehfZdGna4WOzddenAT
 1nsVKRp/qxR0b9kolQYCpSVsJKHME4pZPEKY0f5UyCZgEy/l3SkMPVOkjXlAzZAd
 ZX0l857UGeVbWP5sRDTc9J1sw2QAVO2oBsSOEeK0z9kvbuz/uQ==
 =I5F0
 -----END PGP SIGNATURE-----

Merge tag 'rtc-4.18' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux

Pull RTC updates from Alexandre Belloni:
 "Setting the supported range from drivers for RTCs failing soon has
  started. A few fixes are developed along the way. Some drivers have
  been switched to SPDX by their maintainers.

  Subsystem:

   - rework of the rtc-test driver which allows to test the core more
     thoroughly

   - rtc_set_alarm() now fails early when alarms are not supported

  Drivers:

   - mktime() is now replaced by mktime64()

   - RTC range added for 88pm80x, ab-b5ze-s3, at91rm9200,
     brcmstb-waketimer, ds1685, ftrtc010, ls1x, mxc_v2, rx8581, sprd,
     st-lpc, tps6586x, tps65910 and vr41xx

   - fixed a possible race condition in probe functions

   - pxa: fix the probe function that is broken since v4.3

   - stm32: now supports stm32mp1"

* tag 'rtc-4.18' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: (78 commits)
  rtc: pxa: fix probe function
  rtc: cros-ec: Switch to SPDX identifier.
  rtc: cros-ec: Make license text and module license match.
  rtc: ensure rtc_set_alarm fails when alarms are not supported
  rtc: test: remove alarm support from the first device
  rtc: test: convert to devm_rtc_allocate_device
  rtc: ftrtc010: let the core handle range
  rtc: ftrtc010: handle dates after 2106
  rtc: ftrtc010: switch to devm_rtc_allocate_device
  rtc: mrst: switch to devm functions
  rtc: sunxi: fix possible race condition
  rtc: test: remove irq sysfs file
  rtc: test: emulate alarms using timers
  rtc: test: store time as an offset to system time
  rtc: test: allow registering many devices
  rtc: test: remove useless proc info
  rtc: ds1685: Add range
  rtc: ds1685: fix possible race condition
  rtc: sprd: Add new RTC power down check method
  rtc: sun6i: Fix bit_idx value for clk_register_gate
  ...
2018-06-10 16:13:24 -07:00
Dan Carpenter
e4302aec8a rtc: pxa: fix probe function
This patch is from static analysis and I don't have the hardware to
to test it.  I think the test is reversed so now the probe function
will return success early and the last part of the function is dead
code.

Fixes: 3cdf4ad963 ("rtc: pxa: convert to use shared sa1100 functions")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-06-07 20:11:08 +02:00
Enric Balletbo i Serra
8ee4aee5b5 rtc: cros-ec: Switch to SPDX identifier.
Adopt the SPDX license identifier headers to ease license compliance
management.

Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-06-07 20:09:49 +02:00
Enric Balletbo i Serra
e6988d2348 rtc: cros-ec: Make license text and module license match.
The license text is specifying "GPLv2" but the MODULE_LICENSE is set to
GPL which means GNU Public License v2 or later. When MODULE_LICENSE and
boiler plate does not match, go for boiler plate license.

Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-06-07 20:09:49 +02:00
Alexandre Belloni
abfdff44bc rtc: ensure rtc_set_alarm fails when alarms are not supported
When using RTC_ALM_SET or RTC_WKALM_SET with rtc_wkalrm.enabled not set,
rtc_timer_enqueue() is not called and rtc_set_alarm() may succeed but the
subsequent RTC_AIE_ON ioctl will fail. RTC_ALM_READ would also fail in that
case.

Ensure rtc_set_alarm() fails when alarms are not supported to avoid letting
programs think the alarms are working for a particular RTC when they are
not.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-06-07 20:09:49 +02:00
Alexandre Belloni
1928906d12 rtc: test: remove alarm support from the first device
To test for issues with RTCs that don't provide an alarm, remove alarm
support from the first test RTC device.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-06-07 20:09:49 +02:00
Alexandre Belloni
0b472ad299 rtc: test: convert to devm_rtc_allocate_device
This allows further improvement of the driver.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-06-07 20:09:49 +02:00
Alexandre Belloni
b8e62b58bc rtc: ftrtc010: let the core handle range
The current range handling is highly suspicious. Anyway, let the core
handle it.
The RTC has a 32 bit counter on top of days + hh:mm:ss registers.

Acked-by: Hans Ulli Kroll <ulli.kroll@googlemail.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-06-07 20:10:17 +02:00
Alexandre Belloni
73318f8b6b rtc: ftrtc010: handle dates after 2106
Use correct types for offset and time and use
rtc_time64_to_tm/rtc_tm_to_time64 to handle dates after 2106 properly.

Acked-by: Hans Ulli Kroll <ulli.kroll@googlemail.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-06-07 20:10:11 +02:00
Alexandre Belloni
e38d161f51 rtc: ftrtc010: switch to devm_rtc_allocate_device
Switch to devm_rtc_allocate_device/rtc_register_device. This allow or
further improvement and simplifies ftrtc010_rtc_remove().

Acked-by: Hans Ulli Kroll <ulli.kroll@googlemail.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-06-07 20:09:49 +02:00
Linus Torvalds
2857676045 - Introduce arithmetic overflow test helper functions (Rasmus)
- Use overflow helpers in 2-factor allocators (Kees, Rasmus)
 - Introduce overflow test module (Rasmus, Kees)
 - Introduce saturating size helper functions (Matthew, Kees)
 - Treewide use of struct_size() for allocators (Kees)
 -----BEGIN PGP SIGNATURE-----
 Comment: Kees Cook <kees@outflux.net>
 
 iQJKBAABCgA0FiEEpcP2jyKd1g9yPm4TiXL039xtwCYFAlsYJ1gWHGtlZXNjb29r
 QGNocm9taXVtLm9yZwAKCRCJcvTf3G3AJlCTEACwdEeriAd2VwxknnsstojGD/3g
 8TTFA19vSu4Gxa6WiDkjGoSmIlfhXTlZo1Nlmencv16ytSvIVDNLUIB3uDxUIv1J
 2+dyHML9JpXYHHR7zLXXnGFJL0wazqjbsD3NYQgXqmun7EVVYnOsAlBZ7h/Lwiej
 jzEJd8DaHT3TA586uD3uggiFvQU0yVyvkDCDONIytmQx+BdtGdg9TYCzkBJaXuDZ
 YIthyKDvxIw5nh/UaG3L+SKo73tUr371uAWgAfqoaGQQCWe+mxnWL4HkCKsjFzZL
 u9ouxxF/n6pij3E8n6rb0i2fCzlsTDdDF+aqV1rQ4I4hVXCFPpHUZgjDPvBWbj7A
 m6AfRHVNnOgI8HGKqBGOfViV+2kCHlYeQh3pPW33dWzy/4d/uq9NIHKxE63LH+S4
 bY3oO2ela8oxRyvEgXLjqmRYGW1LB/ZU7FS6Rkx2gRzo4k8Rv+8K/KzUHfFVRX61
 jEbiPLzko0xL9D53kcEn0c+BhofK5jgeSWxItdmfuKjLTW4jWhLRlU+bcUXb6kSS
 S3G6aF+L+foSUwoq63AS8QxCuabuhreJSB+BmcGUyjthCbK/0WjXYC6W/IJiRfBa
 3ZTxBC/2vP3uq/AGRNh5YZoxHL8mSxDfn62F+2cqlJTTKR/O+KyDb1cusyvk3H04
 KCDVLYPxwQQqK1Mqig==
 =/3L8
 -----END PGP SIGNATURE-----

Merge tag 'overflow-v4.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux

Pull overflow updates from Kees Cook:
 "This adds the new overflow checking helpers and adds them to the
  2-factor argument allocators. And this adds the saturating size
  helpers and does a treewide replacement for the struct_size() usage.
  Additionally this adds the overflow testing modules to make sure
  everything works.

  I'm still working on the treewide replacements for allocators with
  "simple" multiplied arguments:

     *alloc(a * b, ...) -> *alloc_array(a, b, ...)

  and

     *zalloc(a * b, ...) -> *calloc(a, b, ...)

  as well as the more complex cases, but that's separable from this
  portion of the series. I expect to have the rest sent before -rc1
  closes; there are a lot of messy cases to clean up.

  Summary:

   - Introduce arithmetic overflow test helper functions (Rasmus)

   - Use overflow helpers in 2-factor allocators (Kees, Rasmus)

   - Introduce overflow test module (Rasmus, Kees)

   - Introduce saturating size helper functions (Matthew, Kees)

   - Treewide use of struct_size() for allocators (Kees)"

* tag 'overflow-v4.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux:
  treewide: Use struct_size() for devm_kmalloc() and friends
  treewide: Use struct_size() for vmalloc()-family
  treewide: Use struct_size() for kmalloc()-family
  device: Use overflow helpers for devm_kmalloc()
  mm: Use overflow helpers in kvmalloc()
  mm: Use overflow helpers in kmalloc_array*()
  test_overflow: Add memory allocation overflow tests
  overflow.h: Add allocation size calculation helpers
  test_overflow: Report test failures
  test_overflow: macrofy some more, do more tests for free
  lib: add runtime test of check_*_overflow functions
  compiler.h: enable builtin overflow checkers and add fallback code
2018-06-06 17:27:14 -07:00
Kees Cook
0ed2dd03b9 treewide: Use struct_size() for devm_kmalloc() and friends
Replaces open-coded struct size calculations with struct_size() for
devm_*, f2fs_*, and sock_* allocations. Automatically generated (and
manually adjusted) from the following Coccinelle script:

// Direct reference to struct field.
@@
identifier alloc =~ "devm_kmalloc|devm_kzalloc|sock_kmalloc|f2fs_kmalloc|f2fs_kzalloc";
expression HANDLE;
expression GFP;
identifier VAR, ELEMENT;
expression COUNT;
@@

- alloc(HANDLE, sizeof(*VAR) + COUNT * sizeof(*VAR->ELEMENT), GFP)
+ alloc(HANDLE, struct_size(VAR, ELEMENT, COUNT), GFP)

// mr = kzalloc(sizeof(*mr) + m * sizeof(mr->map[0]), GFP_KERNEL);
@@
identifier alloc =~ "devm_kmalloc|devm_kzalloc|sock_kmalloc|f2fs_kmalloc|f2fs_kzalloc";
expression HANDLE;
expression GFP;
identifier VAR, ELEMENT;
expression COUNT;
@@

- alloc(HANDLE, sizeof(*VAR) + COUNT * sizeof(VAR->ELEMENT[0]), GFP)
+ alloc(HANDLE, struct_size(VAR, ELEMENT, COUNT), GFP)

// Same pattern, but can't trivially locate the trailing element name,
// or variable name.
@@
identifier alloc =~ "devm_kmalloc|devm_kzalloc|sock_kmalloc|f2fs_kmalloc|f2fs_kzalloc";
expression HANDLE;
expression GFP;
expression SOMETHING, COUNT, ELEMENT;
@@

- alloc(HANDLE, sizeof(SOMETHING) + COUNT * sizeof(ELEMENT), GFP)
+ alloc(HANDLE, CHECKME_struct_size(&SOMETHING, ELEMENT, COUNT), GFP)

Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-06 11:15:43 -07:00
Alexandre Belloni
32b41f93dc rtc: mrst: switch to devm functions
Switch to devm managed functions to simplify error handling and device
removal

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-06-05 21:01:59 +02:00
Alexandre Belloni
29615d03cc rtc: sunxi: 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>
Acked-by: Maxime Ripard <maxime.ripard@bootlin.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-06-04 14:36:14 +02:00
Alexandre Belloni
696fa1d043 rtc: test: remove irq sysfs file
Now that alarms are emulated, remove the irq sysfs file that could be used
to send alarms.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-31 23:13:31 +02:00
Alexandre Belloni
8be0902994 rtc: test: emulate alarms using timers
Use timers to emulate alarms. Note that multiple alarms may happen if they
are set more than 15 days after the current RTC time.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-31 23:13:29 +02:00
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
Christoph Hellwig
59cacb8dd5 rtc/proc: switch to proc_create_single_data
And stop trying to get a reference on the submodule, procfs code deals
with release after an unloaded module and thus removed proc entry.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-05-16 07:24:30 +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
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
Nicholas Piggin
682e6b4da5 rtc: opal: Fix OPAL RTC driver OPAL_BUSY loops
The OPAL RTC driver does not sleep in case it gets OPAL_BUSY or
OPAL_BUSY_EVENT from firmware, which causes large scheduling
latencies, up to 50 seconds have been observed here when RTC stops
responding (BMC reboot can do it).

Fix this by converting it to the standard form OPAL_BUSY loop that
sleeps.

Fixes: 628daa8d5a ("powerpc/powernv: Add RTC and NVRAM support plus RTAS fallbacks")
Cc: stable@vger.kernel.org # v3.2+
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2018-04-25 13:24:13 +10: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