Commit graph

36 commits

Author SHA1 Message Date
Alexandre Belloni
3542db1d1f rtc: pcf8523: use IRQ flags obtained from fwnode
Allow the IRQ type to be passed from the device tree if available as there
may be components changing the trigger type of the interrupt between the
RTC and the IRQ controller.

Link: https://lore.kernel.org/r/20230123200217.1236011-7-alexandre.belloni@bootlin.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2023-02-01 09:13:35 +01:00
paulmn
fe0157ba67 rtc: pcf8523: fix for stop bit
Bugfix for an issue detected when a goldcap capacitor gets
fully discharged due to a long absence of the power supply,
and then recharges again. The RTC failed to continue to keep
the real-time clock.

This was caused by the incorrect handling of the STOP bit in
the RTC internal register.  This fix solves the problem.

Signed-off-by: paulmn <paulmn@axis.com>
Link: https://lore.kernel.org/r/20220829124639.10906-1-paulmn@axis.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2022-11-16 23:20:30 +01:00
Stephen Kitt
3f4a332247 rtc: use simple i2c probe
All these drivers have an i2c probe function which doesn't use the
"struct i2c_device_id *id" parameter, so they can trivially be
converted to the "probe_new" style of probe with a single argument.

This change was done using the following Coccinelle script, and fixed
up for whitespace changes:

@ rule1 @
identifier fn;
identifier client, id;
@@

- static int fn(struct i2c_client *client, const struct i2c_device_id *id)
+ static int fn(struct i2c_client *client)
{
...when != id
}

@ rule2 depends on rule1 @
identifier rule1.fn;
identifier driver;
@@

struct i2c_driver driver = {
-	.probe
+	.probe_new
		=
(
		   fn
|
-		   &fn
+		   fn
)
		,
};

Signed-off-by: Stephen Kitt <steve@sk2.org>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20220610162346.4134094-1-steve@sk2.org
2022-06-24 21:24:02 +02:00
Alexandre Belloni
e51cdef081 rtc: pcf8523: let the core handle the alarm resolution
Set RTC_FEATURE_ALARM_RES_MINUTE, so the core knows alarms have a
resolution of a minute. Also, the core will properly round down the alarm
instead of up.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20220309162301.61679-15-alexandre.belloni@bootlin.com
2022-03-23 19:58:39 +01:00
Alexandre Belloni
c1325e730c rtc: pcf8523: switch to RTC_FEATURE_UPDATE_INTERRUPT
Stop using uie_unsupported and clear RTC_FEATURE_UPDATE_INTERRUPT instead.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20220309162301.61679-14-alexandre.belloni@bootlin.com
2022-03-23 19:58:39 +01:00
Victor Erminpour
85bcb01f14 rtc: pcf8523: Fix GCC 12 warning
When building with automatic stack variable initialization, GCC 12
complains about variables defined outside of switch case statements.
Move variables outside the switch, which silences warnings:

./drivers/rtc/rtc-pcf8523.c:284:20: error: statement will never be executed [-Werror=switch-unreachable]
  284 |                 u8 mode;
      |

./drivers/rtc/rtc-pcf8523.c:245:21: error: statement will never be executed [-Werror=switch-unreachable]
  245 |                 u32 value;
      |                     ^~~~~

Signed-off-by: Victor Erminpour <victor.erminpour@oracle.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/1644453027-886-1-git-send-email-victor.erminpour@oracle.com
2022-02-15 23:19:56 +01:00
Alexandre Belloni
f8d4e4fa51 rtc: pcf8523: add BSM support
Backup Switch Mode allows to select the strategy to use to switch from the
main power supply to the backup power supply. As before, the driver will
switch from standby mode to level mode but now only when it has never been
set.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20211018153651.82069-5-alexandre.belloni@bootlin.com
2021-10-18 17:38:06 +02:00
Alexandre Belloni
ebf48cbe32 rtc: pcf8523: allow usage on ACPI platforms
Always provide an OF table to ensure ACPI platforms can also use this
driver.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20211018153651.82069-4-alexandre.belloni@bootlin.com
2021-10-18 17:38:06 +02:00
Alexandre Belloni
7c176119ae rtc: pcf8523: remove unecessary ifdefery
If CONFIG_OF is not defined, of_property_read_bool will return false which
is our default value

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20211018153651.82069-3-alexandre.belloni@bootlin.com
2021-10-18 17:38:05 +02:00
Alexandre Belloni
5537752c53 rtc: pcf8523: always compile pcf8523_rtc_ioctl
Compiling out pcf8523_rtc_ioctl saves about 5% of the generated machine
code. However, it certainly never happens as the RTC character device
interface is the most useful one and is probably always compiled in.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20211018153651.82069-2-alexandre.belloni@bootlin.com
2021-10-18 17:38:05 +02:00
Alexandre Belloni
91f3849d95 rtc: pcf8523: switch to regmap
Use regmap to access the RTC registers, this is a huge reduction in code
lines and generated code. Values on ARMv7:

   text	   data	    bss	    dec	    hex
   5180	    132	      0	   5312	   14c0	before
   3900	    132	      0	   4032	    fc0	after

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20211018153651.82069-1-alexandre.belloni@bootlin.com
2021-10-18 17:38:05 +02:00
Alexandre Belloni
7d7234a4ff rtc: pcf8523: avoid reading BLF in pcf8523_rtc_read_time
BLF, battery low doesn't mean the time is imprecise or invalid, it simply mean
the backup battery has to be replaced. This information can be read using the
VL_READ ioctl.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20211015192400.818254-1-alexandre.belloni@bootlin.com
2021-10-18 17:21:05 +02:00
Alexandre Belloni
4aa90c036d rtc: pcf8523: rename register and bit defines
arch/arm/mach-ixp4xx/include/mach/platform.h now gets included indirectly
and defines REG_OFFSET. Rename the register and bit definition to something
specific to the driver.

Fixes: 7fd70c65fa ("ARM: irqstat: Get rid of duplicated declaration")
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20210710211431.1393589-1-alexandre.belloni@bootlin.com
2021-07-10 23:18:30 +02:00
Alexandre Belloni
a1cfe7cc38 rtc: pcf8523: report oscillator failures
Report oscillator failures and invalid date/time on RTC_VL_READ.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20210418002023.1000265-3-alexandre.belloni@bootlin.com
2021-04-29 23:37:18 +02:00
Alexandre Belloni
13e37b7fb7 rtc: pcf8523: add alarm support
Alarm support requires unconditionally disabling clock out because it is
using the int1 pin.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20210418002023.1000265-2-alexandre.belloni@bootlin.com
2021-04-29 23:37:18 +02:00
Alexandre Belloni
94959a3a04 rtc: pcf8523: remove useless define
Drop DRIVER_NAME as it is only used once

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20210418002023.1000265-1-alexandre.belloni@bootlin.com
2021-04-29 23:04:47 +02:00
Alexandre Belloni
673536cc5f rtc: pcf8523: use BIT
Use the BIT macro to define register bits.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20201118002747.1346504-3-alexandre.belloni@bootlin.com
2020-11-19 12:52:25 +01:00
Alexandre Belloni
219cc0f918 rtc: pcf8523: set range
Set the th RTC range, it is a classic BCD RTC, considering 00 as a leap
year. Let the core handle range checking.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20201118002747.1346504-2-alexandre.belloni@bootlin.com
2020-11-19 12:52:25 +01:00
Alexandre Belloni
886144058d rtc: pcf8523: switch to devm_rtc_allocate_device
Switch to devm_rtc_allocate_device/devm_rtc_register_device, this allows
for further improvement of the driver.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20201118002747.1346504-1-alexandre.belloni@bootlin.com
2020-11-19 12:52:25 +01:00
Gustavo A. R. Silva
df561f6688 treewide: Use fallthrough pseudo-keyword
Replace the existing /* fall through */ comments and its variants with
the new pseudo-keyword macro fallthrough[1]. Also, remove unnecessary
fall-through markings when it is the case.

[1] https://www.kernel.org/doc/html/v5.7/process/deprecated.html?highlight=fallthrough#implicit-switch-case-fall-through

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
2020-08-23 17:36:59 -05:00
Alexandre Belloni
244cf8f0ed rtc: pcf8523: return meaningful value for RTC_VL_READ
REG_CONTROL3_BLF indicates the battery is low and needs to be replaced
soon.

Link: https://lore.kernel.org/r/20191214220259.621996-6-alexandre.belloni@bootlin.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2019-12-18 10:37:25 +01:00
Nobuhiro Iwamatsu
93966243cf rtc: pcf8523: Remove struct pcf8523
struct pcf8523 is referenced only by pcf8523_probe(). And member variable in
this is not referenced by any function. Remove struct pcf8523.

Signed-off-by: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
Link: https://lore.kernel.org/r/20191123090838.1619-1-nobuhiro1.iwamatsu@toshiba.co.jp
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2019-11-27 09:31:14 +01:00
Thomas Gleixner
d2912cb15b treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500
Based on 2 normalized pattern(s):

  this program is free software you can redistribute it and or modify
  it under the terms of the gnu general public license version 2 as
  published by the free software foundation

  this program is free software you can redistribute it and or modify
  it under the terms of the gnu general public license version 2 as
  published by the free software foundation #

extracted by the scancode license scanner the SPDX license identifier

  GPL-2.0-only

has been chosen to replace the boilerplate/reference in 4122 file(s).

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Enrico Weigelt <info@metux.net>
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Allison Randal <allison@lohutok.net>
Cc: linux-spdx@vger.kernel.org
Link: https://lkml.kernel.org/r/20190604081206.933168790@linutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-06-19 17:09:55 +02:00
Sam Ravnborg
189927e719 rtc: pcf8523: set xtal load capacitance from DT
Add support for specifying the xtal load capacitance in the DT node.
The pcf8523 supports xtal load capacitance of 7pF or 12.5pF.
If the rtc has the wrong configuration the time will
drift several hours/week.

The driver use the default value 12.5pF.

The DT may specify either 7000fF or 12500fF.
(The DT uses femto Farad to avoid decimal numbers).
Other values are warned and the driver uses the default value.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2019-01-22 18:57:08 +01:00
Alexandre Belloni
7c617e0c5f rtc: pcf8523: Add rv8523 compatible
The Microcrystal RV-8523 is compatible with the PCF8523.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2019-01-10 21:51:24 +01:00
Baruch Siach
ecb4a353d3 rtc: pcf8523: don't return invalid date when battery is low
The RTC_VL_READ ioctl reports the low battery condition. Still,
pcf8523_rtc_read_time() happily returns invalid dates in this case.
Check the battery health on pcf8523_rtc_read_time() to avoid that.

Reported-by: Erik Čuk <erik.cuk@domel.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-12-11 00:46:53 +01:00
Alexandre Belloni
22652ba724 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>
2018-03-02 10:09:58 +01:00
Russell King
bc3bee0252 rtc: pcf8523: add support for trimming the RTC oscillator
Add support for reading and writing the RTC offset register, converting
it to the corresponding parts-per-billion value.

When setting the drift, the PCF8523 has two modes: one applies the
adjustment every two hours, the other applies the adjustment every
minute.  We select between these two modes according to which ever
gives the closest PPB value to the one requested.

Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-10-25 23:05:52 +02:00
Alexandre Belloni
ede44c908d rtc: pcf8523: properly handle oscillator stop bit
The time and date register of the pcf8223 are undefined after a power
reset. Properly handle the OS bit and return -EINVAL when that bit is set.

It is properly removed when setting the time.

This solves an issue where the time and date may be valid for
rtc_valid_tm() but is not the current time.

Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2016-03-14 17:08:30 +01:00
Uwe Kleine-König
fbbf53f702 rtc: pcf8523: refuse to write dates later than 2099
When the chip increments the YEAR register and it already holds
bin2bcd(99) it reads as 0 afterwards. With this behaviour the last valid
day (without trickery) that has a representation is 2099-12-31 23:59:59.
So refuse to write later dates.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2016-01-11 20:19:54 +01:00
Krzysztof Kozlowski
b28845433e rtc: Drop owner assignment from i2c_driver
i2c_driver does not need to set an owner because i2c_register_driver()
will set it.

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2015-09-05 13:19:06 +02:00
Chris Cui
35738392b6 drivers/rtc/rtc-pcf8523.c: fix month definition
PCF8523 uses 1-12 to represent month according to datasheet.
link: www.nxp.com/documents/data_sheet/PCF8523.pdf.

Signed-off-by: Chris Cui <chris.wei.cui@gmail.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-05-06 13:04:58 -07:00
Sachin Kamat
af99ef9ccc drivers/rtc/rtc-pcf8523.c: remove empty function
After the switch to devm_* functions and the removal of
rtc_device_unregister(), the 'remove' function does not do anything.
Delete it.

Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
Acked-by: Thierry Reding <thierry.reding@avionic-design.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 16:07:57 -07:00
Jingoo Han
288031bfef rtc: rtc-pcf8523: use devm_rtc_device_register()
devm_rtc_device_register() is device managed and makes cleanup
paths simpler.

Signed-off-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-04-29 18:28:26 -07:00
Jesper Nilsson
f32bc70d5f rtc-pcf8523: add low battery voltage support
Implement reading of the battery voltage low signal for rtc-pcf8523.

The bit is read-only and cannot be cleared by software, so no
clear function is implemented.

[akpm@linux-foundation.org: omit pcf8563_rtc_ioctl() if CONFIG_RTC_INTF_DEV=n]
Signed-off-by: Jesper Nilsson <jesper.nilsson@axis.com>
Reviewed-by: Thierry Reding <thierry.reding@avionic-design.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-21 17:22:27 -08:00
Thierry Reding
f803f0d079 rtc: add NXP PCF8523 support
Add an RTC driver for PCF8523 chips by NXP Semiconductors.  No support is
currently provided for the alarm and interrupt functions.  Only the time
and date functionality is implemented.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-12-17 17:15:21 -08:00