summaryrefslogtreecommitdiff
path: root/drivers/rtc/rtc-pcf8523.c
AgeCommit message (Collapse)Author
2024-03-26rtc: pcf8523: provide set_offset_nsecRussell King
When we set the time, we set the STOP bit, set the time, and then clear the STOP bit. Concerning the timing, the PCF8523 data sheet says: "The first increment of the time circuits is between 0.499878s and 0.500000s after STOP is released." However, practical measurement shows this is not the case - with the I2C bus speed at 100kHz on iMX6, it takes about 5ms for the rtclib call for setting the time to complete. However, reading back when the second actually flips shows that there's an additional 10ms which can't be accounted for by the read - a read of the RTC takes 1.7 to 1.8 ms. Practical measurement shows that the first increment occurs about 515ms after the write, which means we need to set the current second 485ms after it has started. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
2023-06-06rtc: Switch i2c drivers back to use .probe()Uwe Kleine-König
After commit b8a1a4cd5a98 ("i2c: Provide a temporary .probe_new() call-back type"), all drivers being converted to .probe_new() and then 03c835f498b5 ("i2c: Switch .probe() to not take an id parameter") convert back to (the new) .probe() to be able to eventually drop .probe_new() from struct i2c_driver. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Link: https://lore.kernel.org/r/20230505121136.1185653-1-u.kleine-koenig@pengutronix.de Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2023-03-17rtc: pcf8523: remove unnecessary OR operationJavier Carrasco
The value variable is initialized to 0 and it is not used to set any other bits rather than the one that defines the capacitor value. Setting this capacitor value is the only purpose of the function where the variable is defined and therefore the OR operation does not apply as a way to foresee functionality extensions either. Signed-off-by: Javier Carrasco <javier.carrasco@wolfvision.net> Link: https://lore.kernel.org/r/20230315082021.2104452-3-javier.carrasco@wolfvision.net Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2023-03-17rtc: pcf8523: fix coding-style issuesJavier Carrasco
Minor modifications for coding-style correctness (tabs, spaces and blank lines before and after brackets). In total 7 errors, 3 warnings and 1 check where removed from the checkpatch output without damaging code readability. Signed-off-by: Javier Carrasco <javier.carrasco@wolfvision.net> Link: https://lore.kernel.org/r/20230315082021.2104452-2-javier.carrasco@wolfvision.net Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2023-02-01rtc: pcf8523: use IRQ flags obtained from fwnodeAlexandre Belloni
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>
2022-11-16rtc: pcf8523: fix for stop bitpaulmn
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-06-24rtc: use simple i2c probeStephen Kitt
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-03-23rtc: pcf8523: let the core handle the alarm resolutionAlexandre Belloni
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-23rtc: pcf8523: switch to RTC_FEATURE_UPDATE_INTERRUPTAlexandre Belloni
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-02-15rtc: pcf8523: Fix GCC 12 warningVictor Erminpour
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
2021-10-18rtc: pcf8523: add BSM supportAlexandre Belloni
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-18rtc: pcf8523: allow usage on ACPI platformsAlexandre Belloni
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-18rtc: pcf8523: remove unecessary ifdeferyAlexandre Belloni
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-18rtc: pcf8523: always compile pcf8523_rtc_ioctlAlexandre Belloni
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-18rtc: pcf8523: switch to regmapAlexandre Belloni
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-18rtc: pcf8523: avoid reading BLF in pcf8523_rtc_read_timeAlexandre Belloni
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-07-10rtc: pcf8523: rename register and bit definesAlexandre Belloni
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: 7fd70c65faac ("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-04-29rtc: pcf8523: report oscillator failuresAlexandre Belloni
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-29rtc: pcf8523: add alarm supportAlexandre Belloni
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-29rtc: pcf8523: remove useless defineAlexandre Belloni
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
2020-11-19rtc: pcf8523: use BITAlexandre Belloni
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-19rtc: pcf8523: set rangeAlexandre Belloni
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-19rtc: pcf8523: switch to devm_rtc_allocate_deviceAlexandre Belloni
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-08-23treewide: Use fallthrough pseudo-keywordGustavo A. R. Silva
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>
2019-12-18rtc: pcf8523: return meaningful value for RTC_VL_READAlexandre Belloni
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-11-27rtc: pcf8523: Remove struct pcf8523Nobuhiro Iwamatsu
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-06-19treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500Thomas Gleixner
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-01-22rtc: pcf8523: set xtal load capacitance from DTSam Ravnborg
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-10rtc: pcf8523: Add rv8523 compatibleAlexandre Belloni
The Microcrystal RV-8523 is compatible with the PCF8523. Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-12-11rtc: pcf8523: don't return invalid date when battery is lowBaruch Siach
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-03-02rtc: stop validating rtc_time in .read_timeAlexandre Belloni
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>
2017-10-25rtc: pcf8523: add support for trimming the RTC oscillatorRussell King
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>
2016-03-14rtc: pcf8523: properly handle oscillator stop bitAlexandre Belloni
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-01-11rtc: pcf8523: refuse to write dates later than 2099Uwe Kleine-König
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>
2015-09-05rtc: Drop owner assignment from i2c_driverKrzysztof Kozlowski
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>
2014-05-06drivers/rtc/rtc-pcf8523.c: fix month definitionChris Cui
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>
2013-07-03drivers/rtc/rtc-pcf8523.c: remove empty functionSachin Kamat
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-04-29rtc: rtc-pcf8523: use devm_rtc_device_register()Jingoo Han
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-02-21rtc-pcf8523: add low battery voltage supportJesper Nilsson
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>
2012-12-17rtc: add NXP PCF8523 supportThierry Reding
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>