aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc/rtc-ds1307.c
AgeCommit message (Collapse)AuthorFilesLines
2023-08-16rtc: ds1307: fix Wvoid-pointer-to-enum-cast warningKrzysztof Kozlowski1-1/+1
'type' is an enum, thus cast of pointer on 64-bit compile test with W=1 causes: rtc-ds1307.c:1747:18: error: cast to smaller integer type 'enum ds_type' from 'const void *' [-Werror,-Wvoid-pointer-to-enum-cast] Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> Link: https://lore.kernel.org/r/20230810103902.151145-1-krzysztof.kozlowski@linaro.org Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2023-06-06rtc: Switch i2c drivers back to use .probe()Uwe Kleine-König1-1/+1
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-01-09rtc: ds1307: Convert to i2c's .probe_new()Uwe Kleine-König1-3/+3
.probe_new() doesn't get the i2c_device_id * parameter, so determine that explicitly in the probe function. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Link: https://lore.kernel.org/r/20221118224540.619276-561-uwe@kleine-koenig.org Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2022-12-15rtc: ds1307: use sysfs_emit() to instead of scnprintf()ye xingchen1-2/+1
Follow the advice of the Documentation/filesystems/sysfs.rst and show() should only use sysfs_emit() or sysfs_emit_at() when formatting the value to be returned to user space. Signed-off-by: ye xingchen <ye.xingchen@zte.com.cn> Link: https://lore.kernel.org/r/202212051134455911470@zte.com.cn Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2022-11-15rtc: Include <linux/kstrtox.h> when appropriateChristophe JAILLET1-0/+1
The kstrto<something>() functions have been moved from kernel.h to kstrtox.h. So, include the latter directly in the appropriate files. Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> Link: https://lore.kernel.org/r/786421fd0435a32206288904a1f879436a717529.1667721637.git.christophe.jaillet@wanadoo.fr Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2022-03-23rtc: ds1307: switch to RTC_FEATURE_UPDATE_INTERRUPTAlexandre Belloni1-1/+1
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-3-alexandre.belloni@bootlin.com
2021-04-29rtc: ds1307: Fix wday settings for rx8130Nobuhiro Iwamatsu1-2/+10
rx8130 wday specifies the bit position, not BCD. Fixes: ee0981be7704 ("rtc: ds1307: Add support for Epson RX8130CE") Signed-off-by: Nobuhiro Iwamatsu <nobuhiro1.iwamatsu@toshiba.co.jp> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Link: https://lore.kernel.org/r/20210420023917.1949066-1-nobuhiro1.iwamatsu@toshiba.co.jp
2021-04-29rtc: ds1307: remove flagsAlexandre Belloni1-2/+0
flags is now unused, drop it. Tested-by: Łukasz Stelmach <l.stelmach@samsung.com> Reviewed-by: Łukasz Stelmach <l.stelmach@samsung.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Link: https://lore.kernel.org/r/20210418000023.995758-2-alexandre.belloni@bootlin.com
2021-04-29rtc: ds1307: replace HAS_ALARM by RTC_FEATURE_ALARMAlexandre Belloni1-35/+7
The core now has RTC_FEATURE_ALARM for the driver to indicate whether alarms are available. Use that instead of HAS_ALARM to ensure the alarm callbacks are not even called. Tested-by: Łukasz Stelmach <l.stelmach@samsung.com> Reviewed-by: Łukasz Stelmach <l.stelmach@samsung.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Link: https://lore.kernel.org/r/20210418000023.995758-1-alexandre.belloni@bootlin.com
2021-01-25rtc: ds1307: use rtc_lock/rtc_unlockAlexandre Belloni1-3/+2
Avoid accessing directly rtc->ops_lock and use the RTC core helpers. Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Link: https://lore.kernel.org/r/20210119220653.677750-4-alexandre.belloni@bootlin.com
2020-11-19rtc: rework rtc_register_device() resource managementBartosz Golaszewski1-1/+1
rtc_register_device() is a managed interface but it doesn't use devres by itself - instead it marks an rtc_device as "registered" and the devres callback for devm_rtc_allocate_device() takes care of resource release. This doesn't correspond with the design behind devres where managed structures should not be aware of being managed. The correct solution here is to register a separate devres callback for unregistering the device. While at it: rename rtc_register_device() to devm_rtc_register_device() and add it to the list of managed interfaces in devres.rst. This way we can avoid any potential confusion of driver developers who may expect there to exist a corresponding unregister function. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Link: https://lore.kernel.org/r/20201109163409.24301-8-brgl@bgdev.pl
2020-11-19rtc: add devm_ prefix to rtc_nvmem_register()Bartosz Golaszewski1-1/+1
rtc_nvmem_register() is a managed interface. It doesn't require any release function to be called at driver detach. To avoid confusing driver authors, let's rename it to devm_rtc_nvmem_register() and add it to the list of managed interfaces in Documentation/. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Link: https://lore.kernel.org/r/20201109163409.24301-6-brgl@bgdev.pl
2020-11-19rtc: nvmem: remove nvram ABIAlexandre Belloni1-1/+0
The nvram sysfs attributes have been deprecated at least since v4.13, more than 3 years ago and nobody ever complained about the deprecation warning. Remove the sysfs attributes now. [Bartosz: remove the declaration of rtc_nvmem_unregister()] Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Link: https://lore.kernel.org/r/20201109163409.24301-5-brgl@bgdev.pl
2020-11-17rtc: ds1307: Drop of_match_ptr and CONFIG_OF protectionsAndy Shevchenko1-4/+2
These prevent use of this driver with ACPI via PRP0001. Drop them to remove this restriction. Also added mod_devicetable.h include given use of struct of_device_id. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Link: https://lore.kernel.org/r/20201116142859.31257-3-andriy.shevchenko@linux.intel.com
2020-11-17rtc: ds1307: Make use of device propertiesAndy Shevchenko1-17/+21
Device property API allows to gather device resources from different sources, such as ACPI. Convert the drivers to unleash the power of device property API. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Link: https://lore.kernel.org/r/20201116142859.31257-2-andriy.shevchenko@linux.intel.com
2020-11-17rtc: ds1307: Remove non-valid ACPI IDsAndy Shevchenko1-35/+1
The commit 9c19b8930d2c ("rtc: ds1307: Add ACPI support") added invalid ACPI IDs (all of them are abusing ACPI specification). Moreover there is not even a single evidence that vendor registered any of such devices. Remove broken ACPI IDs from the driver. For prototyping one may use PRP0001 with device properties adhering to a DT binding. The following patches will add support of that to the driver. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Cc: Tin Huynh <tnhuynh@apm.com> Link: https://uefi.org/PNP_ACPI_Registry Link: https://lore.kernel.org/r/20201116142859.31257-1-andriy.shevchenko@linux.intel.com
2020-09-24rtc: ds1307: enable rx8130's backup battery, make it chargeable optionallyBastian Krause1-0/+15
The ds1307 charger infrastructure now allows to add a rx8130 charger setup that.. - does not depend on trickle-resistor-ohms - does not use DS13XX_TRICKLE_CHARGER_MAGIC trickle-charge select (TCS) bits - keeps previous no-charge behavior for device trees without aux-voltage-chargeable Make that happen. Signed-off-by: Bastian Krause <bst@pengutronix.de> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Link: https://lore.kernel.org/r/20200917183246.19446-9-bst@pengutronix.de
2020-09-24rtc: ds1307: consider aux-voltage-chargeableBastian Krause1-2/+21
Prefer aux-voltage-chargeable over trickle-diode-disable and set diode accordingly. This is then passed to the chip's appropriate charge setup function. Signed-off-by: Bastian Krause <bst@pengutronix.de> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Link: https://lore.kernel.org/r/20200917183246.19446-8-bst@pengutronix.de
2020-09-24rtc: ds1307: store previous charge default per chipBastian Krause1-1/+8
Some RTC's batteries and supercaps were charged by default until now. In contrast other RTCs allow charging but the driver did not configure them to do so until now. These must not be charged by default to stay backwards compatible. In order to do that, store the charge default per chip. Signed-off-by: Bastian Krause <bst@pengutronix.de> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Link: https://lore.kernel.org/r/20200917183246.19446-7-bst@pengutronix.de
2020-09-24rtc: ds1307: introduce requires_trickle_resistor per chipBastian Krause1-1/+7
Make trickle-resistor-ohms optional for charging setups that do not require specifying ROUT bits (specifying the resistor value between Vcc and Vbackup). In order to allow specifying that, introduce requires_trickle_resistor per chip. Signed-off-by: Bastian Krause <bst@pengutronix.de> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Link: https://lore.kernel.org/r/20200917183246.19446-6-bst@pengutronix.de
2020-09-24rtc: ds1307: apply DS13XX_TRICKLE_CHARGER_MAGIC only conditionallyBastian Krause1-1/+2
DS13XX_TRICKLE_CHARGER_MAGIC sets the trickle-charge select (TCS) bits (7..4). The datasheet of Maxim Integrated's DS1339 [1] for instance reads: "To prevent accidental enabling, only a pattern on 1010 enables the trickle charger. All other patterns disable the trickle charger." Since not all RTCs connected to a backup battery or supercap use these bits DS13XX_TRICKLE_CHARGER_MAGIC should not get applied for all charger setups unconditionally. Epson's RX8130 is such an example: Instead of TCS bits "SMPTSEL1", "SMPTSEL0", "CHGEN" and "INIEN" are expected as bit 7..4. DS1339 and DS1340 are currently the only RTCs in the ds1307 driver that apply DS13XX_TRICKLE_CHARGER_MAGIC to their setup register value. So apply DS13XX_TRICKLE_CHARGER_MAGIC in do_trickle_setup_ds1339() which is used by both RTCs. [1] https://datasheets.maximintegrated.com/en/ds/DS1339-DS1339U.pdf [2] https://support.epson.biz/td/api/doc_check.php?dl=app_RX8130CE Signed-off-by: Bastian Krause <bst@pengutronix.de> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Link: https://lore.kernel.org/r/20200917183246.19446-5-bst@pengutronix.de
2020-08-21rtc: ds1307: Clear OSF flag on DS1388 when setting timeChris Packham1-0/+4
Ensure the OSF flag is cleared on the DS1388 when the clock is set. Fixes: df11b323b16f ("rtc: ds1307: handle oscillator failure flags for ds1388 variant") Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Link: https://lore.kernel.org/r/20200818013543.4283-1-chris.packham@alliedtelesis.co.nz
2020-08-21rtc: ds1307: Ensure oscillator is enabled for DS1388Chris Packham1-0/+14
Similar to the other variants the DS1388 has a bit to stop the oscillator to reduce the power consumption from VBAT. Ensure that the oscillator is enabled when the system is up. Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Link: https://lore.kernel.org/r/20200816235731.21071-1-chris.packham@alliedtelesis.co.nz
2020-08-05rtc: ds1307: provide an indication that the watchdog has firedChris Packham1-0/+6
There's not much feedback when the ds1388 watchdog fires. Generally it yanks on the reset line and the board reboots. Capture the fact that the watchdog has fired in the past so that userspace can retrieve it via WDIOC_GETBOOTSTATUS. This should help distinguish a watchdog triggered reset from a power interruption. Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Link: https://lore.kernel.org/r/20200727034615.19755-1-chris.packham@alliedtelesis.co.nz
2020-04-03rtc: ds1307: check for failed memory allocation on wdtColin Ian King1-0/+2
Currently a failed memory allocation will lead to a null pointer dereference on point wdt. Fix this by checking for a failed allocation and just returning. Addresses-Coverity: ("Dereference null return") Fixes: fd90d48db037 ("rtc: ds1307: add support for watchdog timer on ds1388") Signed-off-by: Colin Ian King <colin.king@canonical.com> Link: https://lore.kernel.org/r/20200403110437.57420-1-colin.king@canonical.com Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2020-04-01rtc: ds1307: add support for watchdog timer on ds1388Chris Packham1-0/+115
The DS1388 variant has watchdog timer capabilities. When using a DS1388 and having enabled CONFIG_WATCHDOG_CORE register a watchdog device for the DS1388. Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Link: https://lore.kernel.org/r/20200330025500.6991-1-chris.packham@alliedtelesis.co.nz Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2020-03-22rtc: ds1307: handle oscillator failure flags for ds1388 variantChris Packham1-0/+9
The FLAG register is at a different location to the other supported RTCs so this requires an extra case in the existing switch statement. Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz> Link: https://lore.kernel.org/r/20200207031812.14424-2-chris.packham@alliedtelesis.co.nz Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2019-07-17Merge tag 'rtc-5.3' of ↵Linus Torvalds1-71/+58
git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux Pull RTC updates from Alexandre Belloni: "A quiet cycle this time. - ds1307: properly handle oscillator failure flags - imx-sc: alarm support - pcf2123: alarm support, correct offset handling - sun6i: add R40 support - simplify getting the adapter of an i2c client" * tag 'rtc-5.3' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: (37 commits) rtc: wm831x: Add IRQF_ONESHOT flag rtc: stm32: remove one condition check in stm32_rtc_set_alarm() rtc: pcf2123: Fix build error rtc: interface: Change type of 'count' from int to u64 rtc: pcf8563: Clear event flags and disable interrupts before requesting irq rtc: pcf8563: Fix interrupt trigger method rtc: pcf2123: fix negative offset rounding rtc: pcf2123: add alarm support rtc: pcf2123: use %ptR rtc: pcf2123: port to regmap rtc: pcf2123: remove sysfs register view rtc: rx8025: simplify getting the adapter of a client rtc: rx8010: simplify getting the adapter of a client rtc: rv8803: simplify getting the adapter of a client rtc: m41t80: simplify getting the adapter of a client rtc: fm3130: simplify getting the adapter of a client rtc: tegra: Drop MODULE_ALIAS rtc: sun6i: Add R40 compatible dt-bindings: rtc: sun6i: Add the R40 RTC compatible dt-bindings: rtc: Convert Allwinner A31 RTC to a schema ...
2019-06-19treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500Thomas Gleixner1-4/+1
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-05-23rtc: ds1307: properly handle oscillator failure flagsAlexandre Belloni1-71/+58
Stop enabling the oscillator and removing the oscillator failure flags in probe. Instead, return -EINVAL in .read_time when the oscillaotr is not start or when it failed at some point. The oscillator gets enabled on the first .set_time after failure and the failure flags are cleared. This also removes the possibility of an infinite loop at probe where a failing RTC will make the goto read_rtc to be taken every time. Tested on mcp79411. Reported-by: Mastro Gippo <gipmad@gmail.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2019-02-07rtc: ds1307: rx8130: Fix alarm handlingUwe Kleine-König1-4/+3
When the EXTENSION.WADA bit is set, register 0x19 contains a bitmap of week days, not a day of month. As Linux only handles a single alarm without repetition using day of month is more flexible, so clear this bit. (Otherwise a value depending on time.tm_wday would have to be written to register 0x19.) Also optimize setting the AIE bit to use a single register write instead of a bulk write of three registers. Fixes: ee0981be7704 ("rtc: ds1307: Add support for Epson RX8130CE") Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2019-02-07rtc: ds1307: rx8130: honor Voltage Loss Flag when reading the timeUwe Kleine-König1-0/+25
When voltage dropped since the RTC was last set the reported time is not reliable. In this case return an error indicator instead of a bogus time. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2019-02-07rtc: ds1307: correct register offset for rx8130Uwe Kleine-König1-6/+7
While rx8130 has a register offset of 0x10 in its chip_desc, this isn't used when regmap accesses are done. So add 0x10 to access the right locations. Fixes: ee0981be7704 ("rtc: ds1307: Add support for Epson RX8130CE") Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2019-02-07rtc: ds1307: forward declare chips array instead of a bunch of functionsUwe Kleine-König1-325/+297
There used to be 16 declarations for static functions. By just adding a declaration for the chips array and reordering the functions the 16 function declarations can be dropped. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2019-02-07rtc: ds1307: Move register definitions to start of fileUwe Kleine-König1-26/+26
This allows to use the register offsets in all functions which is needed in one of the next patches. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-10-22rtc: ds1307: fix ds1339 wakealarm supportSoeren Moch1-1/+0
Commit 51ed73eb998a1c79a2b0e9bed68f75a8a2c93b9b ("rtc: ds1340: Add support for trickle charger.") breaks ds1339 wakealarm support by limiting accessible registers. Fix this. Fixes: 51ed73eb998a ("rtc: ds1340: Add support for trickle charger.") Cc: stable@vger.kernel.org Signed-off-by: Soeren Moch <smoch@web.de> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-09-28rtc: ds1307: use rtc_add_groupAlexandre Belloni1-39/+14
Register frequency test using rtc_add_group to avoid a possible race condition and simplify the code. This also moves the attribute to its proper location under the rtc device instead of the i2c parent device. Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-09-28rtc: ds1307: add frequency_test_enable attribute on m41txxGiulio Benetti1-0/+92
On m41txx you can enable open-drain OUT pin to check if offset is ok. Enabling OUT pin with frequency_test_enable attribute, OUT pin will tick 512 times faster than 1s tick base. Enable or Disable FT bit on CONTROL register if freq_test is 1 or 0. Signed-off-by: Giulio Benetti <giulio.benetti@micronovasrl.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-09-28rtc: ds1307: add offset sysfs for mt41txx chips.Giulio Benetti1-0/+77
m41txx chips can hold a calibration value to get correct clock bias. Add offset handling (ranging between -63ppm and 126ppm) via sysfs. Signed-off-by: Giulio Benetti <giulio.benetti@micronovasrl.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-08-16rtc: ds1307: simplify hwmon configHeiner Kallweit1-1/+1
We don't have to define an extra config symbol, IS_REACHABLE does what we need. And having this config symbol just to save the few bytes of hwmon support on non-DS3231 chips isn't worth it IMO (especially as the symbol is set per default). Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2018-07-16rtc: ds1307: support m41t11 variantGiulio Benetti1-0/+14
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-16rtc: ds1307: fix data pointer to m41t0Giulio Benetti1-1/+1
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-05-03rtc: ds1340: Add support for trickle charger.Andrea Greco1-0/+2
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-03-02rtc: stop validating rtc_time in .read_timeAlexandre Belloni1-2/+1
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-01rtc: ds1307: put struct nvmem_config on the stackAlexandre Belloni1-9/+10
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-01rtc: ds1307: call rtc_nvmem_register()Alexandre Belloni1-6/+6
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>
2017-10-26rtc: ds1307: add OF and ACPI entries for Epson RX8130Bastian Stender1-0/+5
Make Epson RX8130 device tree and ACPI aware. Fixes: ee0981be7704 ("rtc: ds1307: Add support for Epson RX8130CE") Signed-off-by: Bastian Stender <bst@pengutronix.de> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-10-12rtc: ds1307: improve weekday handlingHeiner Kallweit1-26/+26
The current code for checking and fixing the weekday in ds1307_probe faces some issues: - This check is applied to all chips even if its applicable (AFAIK) to mcp794xx only - The check uses MCP794XX constants for registers and bits even though it's executed also on other chips (ok, this could be fixed easily) - It relies on tm_wday being properly populated when core calls set_time and set_alarm. This is not guaranteed at all. First two issue we could solve by moving the check to the mcp794xx-specific initialization (where also VBATEN flag is set). The proposed alternative is in the set_alarm path for mcp794xx only and calculates the alarm weekday based on the current weekday in the RTC timekeeping regs and the difference between alarm date and current date. So we are fine with any weekday even if it doesn't match the date. Still there are cases where this could fail, e.g.: - rtc date/time + weekday have power-on-reset default values - alarm is set to actual date/time + x - set_time is called (may change diff between rtc weekday and actual weekday) But similar issues we have with the current code too: - rtc date/time + weekday have power-on-reset default values - alarm is set to rtc date/time + x - set_time is called before the alarm triggers Using random rtc date/time with relative alarms simply can interfere with set_time. I'm not totally convinced of either option yet. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-09-13Merge tag 'rtc-4.14' of ↵Linus Torvalds1-225/+232
git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux Pull RTC updates from Alexandre Belloni: "Subsystem: - remove .open() and .release() RTC ops - constify i2c_device_id New driver: - Realtek RTD1295 - Android emulator (goldfish) RTC Drivers: - ds1307: Beginning of a huge cleanup - s35390a: handle invalid RTC time - sun6i: external oscillator gate support" * tag 'rtc-4.14' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: (40 commits) rtc: ds1307: use octal permissions rtc: ds1307: fix braces rtc: ds1307: fix alignments and blank lines rtc: ds1307: use BIT rtc: ds1307: use u32 rtc: ds1307: use sizeof rtc: ds1307: remove regs member rtc: Add Realtek RTD1295 dt-bindings: rtc: Add Realtek RTD1295 rtc: sun6i: Add support for the external oscillator gate rtc: goldfish: Add RTC driver for Android emulator dt-bindings: Add device tree binding for Goldfish RTC driver rtc: ds1307: add basic support for ds1341 chip rtc: ds1307: remove member nvram_offset from struct ds1307 rtc: ds1307: factor out offset to struct chip_desc rtc: ds1307: factor out rtc_ops to struct chip_desc rtc: ds1307: factor out irq_handler to struct chip_desc rtc: ds1307: improve irq setup rtc: ds1307: constify struct chip_desc variables rtc: ds1307: improve trickle charger initialization ...
2017-09-05rtc: ds1307: use octal permissionsAlexandre Belloni1-1/+1
Octal permissions are preferred over symbolic permissions. Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-09-05rtc: ds1307: fix bracesAlexandre Belloni1-3/+3
Fix unnecessary or unbalanced braces. Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-09-05rtc: ds1307: fix alignments and blank linesAlexandre Belloni1-11/+10
Alignment should always match open parenthesis. Also remove two unnecessary blank lines Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-09-05rtc: ds1307: use BITAlexandre Belloni1-9/+9
Use the BIT macro were possbiel. Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-09-05rtc: ds1307: use u32Alexandre Belloni1-4/+4
u32 should be used instead of uint32_t Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-09-05rtc: ds1307: use sizeofAlexandre Belloni1-8/+16
Use sizeof where possible to ensure we don't read/write more than the allocated buffer. Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-09-05rtc: ds1307: remove regs memberAlexandre Belloni1-100/+107
ds1307->regs is never used before being read or initialized locally. There is no point in keeping a copy in memory. Also limit the size of the read buffer to what is really used, rename buf to regs for consistency and use sizeof() where possible. Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-09-01rtc: ds1307: add basic support for ds1341 chipNikita Yushchenko1-0/+12
This adds support for reading and writing date/time from/to ds1341 chip. ds1341 chip has other features - alarms, input clock (can be used instead of intercal oscillator for better accuracy), output clock ("square wave generation"). However, not all of that is available at the same time. Same chip pins, CLKIN/nINTA and SQW/nINTB, can be used either for input/output clocks, or for alarm interrupts. Role of these pins on particular board depends on hardware wiring. We can add device tree properties that describe if each of pins is wired as clock, or as interrupt, or left unconnected, and enable support for corresponding functionality based on that. But that is cumbersome, requires hardware for testing, and has to deal with bit enabling/disabling output clock also affects which pins alarm interrupts are routed to. Another factor is that there are hardware setups (i.e. ZII RDU2) that power DS1341 from SuperCap, which makes power saving critical. For such setups, kernel driver should leave register bits that control mentioned pins in the state configured by bootloader. Given all that, it was decided to limit support to "only date/time" for now. That is enough for common use case. Full (and cumbersome) implementation can be added later if ever needed. Signed-off-by: Nikita Yushchenko <nikita.yoush@cogentembedded.com> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Tested-by: Aleksander Morgado <aleksander@aleksander.es> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-09-01rtc: ds1307: remove member nvram_offset from struct ds1307Heiner Kallweit1-4/+4
Remove member nvram_offset from struct ds1307 and use the value stored in struct chip_desc directly. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-09-01rtc: ds1307: factor out offset to struct chip_descHeiner Kallweit1-11/+7
Factor out offset to struct chip_desc and remove it from struct ds1307. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-09-01rtc: ds1307: factor out rtc_ops to struct chip_descHeiner Kallweit1-23/+28
Factor out rtc_ops to struct chip_desc and use ds13xx_rtc_ops as default. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-09-01rtc: ds1307: factor out irq_handler to struct chip_descHeiner Kallweit1-8/+7
Factor out irq_handler to struct chip_desc and use ds1307_irq as default. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-09-01rtc: ds1307: improve irq setupHeiner Kallweit1-17/+10
Change the usage of variable want_irq to reflect its name. Don't set it to true in case wakeup is enabled but no interrupt number is given. In addition set variable ds1307_can_wakeup_device if chip->alarm is set only. This allows to simplify the code and make it better understandable. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-09-01rtc: ds1307: constify struct chip_desc variablesHeiner Kallweit1-3/+3
Constify struct chip_desc variables. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-09-01rtc: ds1307: improve trickle charger initializationHeiner Kallweit1-17/+16
Instead of storing the trickle_charger_setup value in struct chip_desc we can let function ds1307_trickle_init return it because it's used in the probe function only. This allows us to constify struct chip_desc variables in a next step. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-09-01rtc: ds1307: factor out bbsqi bit to struct chip_descHeiner Kallweit1-7/+4
Factor out the bbsqi bit to struct chip_desc. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-09-01rtc: ds1307: remove member irq from struct ds1307Heiner Kallweit1-7/+5
The irq number is used in the probe function only, so we don't have to store it in struct ds1307. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-08-21rtc: ds1307: fix regmap configHeiner Kallweit1-1/+0
Current max_register setting breaks reading nvram on certain chips and also reading the standard registers on RX8130 where register map starts at 0x10. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Fixes: 11e5890b5342 "rtc: ds1307: convert driver to regmap" Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-07-31rtc: ds1307: remove legacy check for "isil, irq2-can-wakeup-machine" propertyHeiner Kallweit1-7/+1
Commit 8b44f5be20fd ("ARM: dts: armada: replace isil,irq2-can-wakeup-machine with wakeup-source property") removed the last usage of "isil,irq2-can-wakeup-machine" almost two years ago. So I think we can get rid of supporting this legacy binding. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Acked-by: Rob Herring <robh@kernel.org> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-07-07rtc: ds1307: remove ds1307_removeAlexandre Belloni1-6/+0
ds1307_remove() is now empty, remove it Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-07-07rtc: ds1307: use generic nvmemAlexandre Belloni1-66/+22
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@free-electrons.com>
2017-07-07rtc: ds1307: switch to rtc_register_deviceAlexandre Belloni1-2/+7
This removes a possible race condition and crash and allows for further improvement of the driver. Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-07-06rtc: ds1307: add ds1308 variantSean Nyekjaer1-0/+12
The ds1308 variant is very similar to the already supported ds1338 variant, it have more debug registers and a square wave clock output. Signed-off-by: Sean Nyekjaer <sean.nyekjaer@prevas.dk> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-07-06rtc: ds1307: factor out century bit handlingHeiner Kallweit1-46/+27
The driver has lots of places with chip-specific code what doesn't necessarily facilitate maintenance. Let's describe chip-specific differences in century bit handling in struct chip_desc to improve this. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-07-05rtc: ds1307: use regmap_update_bits where applicableHeiner Kallweit1-62/+20
After the switch to regmap we can now make use of regmap_update_bits to simplify read/modify/write ops. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-06-24rtc: ds1307: Add support for Epson RX8130CEMarek Vasut1-0/+175
Add support for yet another RTC chip, Epson RX8130CE. This time around, the chip has slightly permutated registers and also the register starts at 0x10 instead of 0x0 . So far, we only support the RTC and NVRAM parts of the chip, Alarm and Timer is not supported. Signed-off-by: Marek Vasut <marex@denx.de> Cc: Alexandre Belloni <alexandre.belloni@free-electrons.com> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Felipe Balbi <balbi@ti.com> Cc: Nishanth Menon <nm@ti.com> Cc: Tony Lindgren <tony@atomide.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-06-03rtc: ds1307: avoid using rtc-nameAlexandre Belloni1-1/+1
ds1307->rtc->name is a copy of ds1307->name, use it instead. Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-05-31rtc: rtc-ds1307: enable support for mcp794xx as a wakeup source without IRQDavid Lowe1-1/+2
This patch extends the fixes for ds1337, ds1339, ds3231 in commit 8bc2a40730ec ("rtc: ds1307: add support for the DT property 'wakeup-source'") to mcp794xx devices, so that those parts can similarly be used as a wakeup source without an IRQ to the processor. Tested on Raspberry Pi ZeroW with MCP79400. Signed-off-by: David Lowe <dave-lowe@ntlworld.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-05-26rtc: ds1307: convert driver to regmapHeiner Kallweit1-382/+221
This patch converts the ds1307 driver to using regmap. It's a rather big patch and I can test with DS3231 only. With this chip it's working fine. I'd appreciate if people with other supported hardware could test as well. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-04-14rtc: ds1307: Add m41t0 to OF device ID tableAlexandre Belloni1-0/+4
m41t0 was added to the I2C device ID table but not the OF table. Fix that. Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-04-14rtc: ds1307: support m41t0 variantStefan Agner1-0/+13
The m41t0 variant is very similar to the already supported m41t00 variant, with the notable exception of the oscillator fail bit. The data sheet notes: If the oscillator fail (OF) bit is internally set to a '1,' this indicates that the oscillator has either stopped, or was stopped for some period of time and can be used to judge the validity of the clock and date data. The bit will get cleared with a regular write of the system time, so no changes are needed to clear it. Signed-off-by: Stefan Agner <stefan@agner.ch> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2017-03-09rtc: ds1307: Add OF device ID tableJavier Martinez Canillas1-1/+67
The driver doesn't have a struct of_device_id table but supported devices are registered via Device Trees. This is working on the assumption that a I2C device registered via OF will always match a legacy I2C device ID and that the MODALIAS reported will always be of the form i2c:<device>. But this could change in the future so the correct approach is to have an OF device ID table if the devices are registered via OF. Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2016-12-19rtc: ds1307: Add ACPI supportTin Huynh1-9/+43
This patch enables ACPI support for rtc-ds1307 driver. Signed-off-by: Tin Huynh <tnhuynh@apm.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2016-08-31rtc: ds1307: add Intersil ISL12057 supportAlexandre Belloni1-0/+6
Intersil ISL12057 is a drop-in replacement for DS1337. It can be supported by the ds1307 driver. Acked-by: Arnaud Ebalard <arno@natisbad.org> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2016-08-31rtc: ds1307: fix century bit supportAlexandre Belloni1-5/+43
Add an option to properly support the century bit of ds1337 and compatibles and ds1340. Because the driver had a bug until now, it is not possible to switch users to the fixed code directly as RTCs in the field will wrongly have the century bit set. Acked-by: Arnaud Ebalard <arno@natisbad.org> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2016-07-09rtc: simplify implementations of read_alarmUwe Kleine-König1-5/+0
Since commit d68778b80dd7 ("rtc: initialize output parameter for read alarm to "uninitialized"") there is no need to explicitly set unsupported members to -1. So drop the respective assignments from drivers. Signed-off-by: Uwe Kleine-König <uwe@kleine-koenig.org> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2016-07-09rtc: ds1307: Fix relying on reset value for weekdayKeerthy1-1/+27
The reset value of weekday is 0x1. This is wrong since the reset values of the day/month/year make up to Jan 1 2001. When computed weekday comes out to be Monday. On a scale of 1-7(Sunday - Saturday) it should be 0x2. So we should not be relying on the reset value. Hence compute the wday using the current date/month/year values. Check if reset wday is any different from the computed wday, If different then set the wday which we computed using date/month/year values. Document Referred: http://ww1.microchip.com/downloads/en/DeviceDoc/20002266F.pdf Fixes: 1d1945d261a2af "drivers/rtc/rtc-ds1307.c: add alarm support for mcp7941x chips" Signed-off-by: Keerthy <j-keerthy@ti.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2016-05-20rtc: ds1307: Remove CLK_IS_ROOTStephen Boyd1-2/+0
This flag is a no-op now (see commit 47b0eeb3dc8a "clk: Deprecate CLK_IS_ROOT", 2016-02-02) so remove it. Cc: Akinobu Mita <akinobu.mita@gmail.com> Cc: Michael Tatarinov <kukabu@gmail.com> Signed-off-by: Stephen Boyd <sboyd@codeaurora.org> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2016-05-20rtc: ds1307: ensure that any pending alarm is cleared before a new alarm is ↵Nicolas Boullis1-5/+8
enabled If a previously-set alarm was disabled and then triggered, it may still be pending when a new alarm is configured. Then, if the alarm is enabled before the pending alarm is cleared, then an interrupt is immediately raised. Unfortunately, when the alarm is cleared and enabled during the same I²C block write, the chip (at least the DS1339 I have) considers that the alarm is enabled before it is cleared, and raises an interrupt. This patch ensures that the pending alarm is cleared before the alarm is enabled. Signed-off-by: Nicolas Boullis <nboullis@debian.org> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2016-05-20rtc: ds1307: fix ds1307_native_smbus_read_block_data functionNicolas Boullis1-2/+6
The i2c_smbus_read_i2c_block_data function returns 0 on success, not the number of bytes written. Hence, when there are 32 bytes or less to send, the ds1307_native_smbus_write_block_data function returns 0 on success, while it returns the number of bytes when there are more than 32. The ds1307_write_block_data always returns the number of bytes on success. Signed-off-by: Nicolas Boullis <nboullis@debian.org> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2016-04-21rtc: ds1307: Use irq when available for wakeup-source deviceNishanth Menon1-1/+1
With commit 8bc2a40730ec ("rtc: ds1307: add support for the DT property 'wakeup-source'") we lost the ability for rtc irq functionality for devices that are actually hooked on a real IRQ line and have capability to wakeup as well. This is not an expected behavior. So, instead of just not requesting IRQ, skip the IRQ requirement only if interrupts are not defined for the device. Fixes: 8bc2a40730ec ("rtc: ds1307: add support for the DT property 'wakeup-source'") Reported-by: Tony Lindgren <tony@atomide.com> Cc: Michael Lange <linuxstuff@milaw.biz> Cc: Alexandre Belloni <alexandre.belloni@free-electrons.com> Signed-off-by: Nishanth Menon <nm@ti.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2016-04-21rtc: ds1307: ds3231 temperature s16 overflowZhuang Yuyao1-2/+2
while retrieving temperature from ds3231, the result may be overflow since s16 is too small for a multiplication with 250. ie. if temp_buf[0] == 0x2d, the result (s16 temp) will be negative. Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Tested-by: Michael Tatarinov <kukabu@gmail.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2016-03-14rtc: ds1307: add clock provider support for DS3231Akinobu Mita1-1/+295
DS3231 has programmable square-wave output signal. This enables to use this feature as a clock provider of common clock framework. Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Reviewed-by: Michael Turquette <mturquette@baylibre.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2016-02-04rtc: ds1307: add temperature sensor support for ds3231Akinobu Mita1-0/+88
DS3231 has the temperature registers with a resolution of 0.25 degree celsius. This enables to get the value through hwmon. # cat /sys/class/i2c-adapter/i2c-2/2-0068/hwmon/hwmon0/temp1_input 21000 Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Acked-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2016-02-04rtc: ds1307: add support for the DT property 'wakeup-source'Michael Lange1-2/+27
For RTC chips with no IRQ directly connected to the SoC, the RTC chip can be forced as a wakeup source by stating that explicitly in the device's .dts file using the "wakeup-source" boolean property. This will guarantee the 'wakealarm' sysfs entry is available on the device, if supported by the RTC. With these changes to the driver rtc-ds1307 and the necessary entries in the .dts file, I get an working ds1337 RTC on the Witty Pi extension board by UUGear for the Raspberry Pi. An example for the entry in the .dts file: rtc: ds1337@68 { compatible = "dallas,ds1337"; reg = <0x68>; wakeup-source; If the "wakeup-source" property is set, do not request an IRQ. Set also UIE mode to unsupported, to get a working 'hwclock' binary. Signed-off-by: Michael Lange <linuxstuff@milaw.biz> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2016-01-11rtc: use %ph for short hex dumpsRasmus Villemoes1-13/+4
This makes the generated code slightly smaller. Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2015-11-26rtc: ds1307: fix alarm reading at probe timeSimon Guinot1-5/+7
With the actual code, read_alarm() always returns -EINVAL when called during the RTC device registration. This prevents from retrieving an already configured alarm in hardware. This patch fixes the issue by moving the HAS_ALARM bit configuration (if supported by the hardware) above the rtc_device_register() call. Signed-off-by: Simon Guinot <simon.guinot@sequanux.org> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2015-11-25rtc: ds1307: fix kernel splat due to wakeup irq handlingFelipe Balbi1-33/+3
Since commit 3fffd1283927 ("i2c: allow specifying separate wakeup interrupt in device tree") we have automatic wakeup irq support for i2c devices. That commit missed the fact that rtc-1307 had its own wakeup irq handling and ended up introducing a kernel splat for at least Beagle x15 boards. Fix that by reverting original commit _and_ passing correct interrupt names on DTS so i2c-core can choose correct IRQ as wakeup. Now that we have automatic wakeirq support, we can revert the original commit which did it manually. Fixes the following warning: [ 10.346582] WARNING: CPU: 1 PID: 263 at linux/drivers/base/power/wakeirq.c:43 dev_pm_attach_wake_irq+0xbc/0xd4() [ 10.359244] rtc-ds1307 2-006f: wake irq already initialized Cc: Tony Lindgren <tony@atomide.com> Cc: Nishanth Menon <nm@ti.com> Signed-off-by: Felipe Balbi <balbi@ti.com> Acked-by: Tony Lindgren <tony@atomide.com> Acked-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2015-11-08rtc: ds1307: Fix alarm programming for mcp794xxTero Kristo1-2/+2
mcp794xx alarm registers must be written in BCD format. However, the alarm programming logic neglected this by adding one to the value after bin2bcd conversion has been already done, writing bad values to month register in case the alarm being set is in October. In this case, the alarm month value becomes 0x0a instead of the expected 0x10. Fix by moving the +1 addition within the bin2bcd call also. Fixes: 1d1945d261a2 ("drivers/rtc/rtc-ds1307.c: add alarm support for mcp7941x chips") Signed-off-by: Tero Kristo <t-kristo@ti.com> Acked-by: Nishanth Menon <nm@ti.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2015-09-05rtc: ds1307: clean up ds1307_nvram_read()/ds1307_nvram_write()Vladimir Zapolskiy1-14/+0
The change removes redundant sysfs binary file boundary checks, since this task is already done on caller side in fs/sysfs/file.c Signed-off-by: Vladimir Zapolskiy <vz@mleia.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2015-09-05rtc: Drop owner assignment from i2c_driverKrzysztof Kozlowski1-1/+0
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-05rtc: ds1307: Support optional wakeup interrupt sourceNishanth Menon1-3/+33
With the recent pinctrl-single changes, SoCs such as Texas Instrument's OMAP processors can treat wake-up events from deeper idle states as interrupts. Let's add support for the optional second interrupt for wake-up using the generic wakeirq support added in commit 4990d4fe327b ("PM / Wakeirq: Add automated device wake IRQ handling") Finally, to pass the wake-up interrupt in the dts file, interrupts-extended property needs to be passed. This is similar in approach to commit 2a0b965cfb6e ("serial: omap: Add support for optional wake-up") + ee83bd3b6483 ("serial: omap: Switch wake-up interrupt to generic wakeirq") Signed-off-by: Nishanth Menon <nm@ti.com> Reviewed-by: Grygorii Strashko <grygorii.strashko@ti.com> Acked-by: Tony Lindgren <tony@atomide.com> Acked-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2015-09-05rtc: ds1307: Sort the headersNishanth Menon1-5/+5
It is always a good practice to keep the #includes sorted Signed-off-by: Nishanth Menon <nm@ti.com> Acked-by: Felipe Balbi <balbi@ti.com> Reviewed-by: Grygorii Strashko <grygorii.strashko@ti.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2015-09-05rtc: ds1307: Switch to managed irq allocationNishanth Menon1-6/+4
Since we are not doing anything fancy in remove function that requires us to sequence IRQ free operation, we might as well switch over to devm_ equivalent of managed IRQ allocation and remove the explicit free_irq since it'd be done automatically at remove. Signed-off-by: Nishanth Menon <nm@ti.com> Acked-by: Felipe Balbi <balbi@ti.com> Reviewed-by: Grygorii Strashko <grygorii.strashko@ti.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2015-09-05rtc: ds1307: Convert to threaded IRQFelipe Balbi1-40/+19
The driver currently emulates the concept of threaded IRQ using a workqueue, which it really does not need to. Instead, switch over to threaded_irq handlers which is meant precisely for the same purpose. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Nishanth Menon <nm@ti.com> Reviewed-by: Grygorii Strashko <grygorii.strashko@ti.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2015-06-25rtc: ds1307: Enable the mcp794xx alarm after programming timeNishanth Menon1-6/+6
Alarm interrupt enable register is at offset 0x7, while the time registers for the alarm follow that. When we program Alarm interrupt enable prior to programming the time, it is possible that previous time value could be close or match at the time of alarm enable resulting in interrupt trigger which is unexpected (and does not match the time we expect it to trigger). To prevent this scenario from occuring, program the ALM0_EN bit only after the alarm time is appropriately programmed. Ofcourse, I2C programming is non-atomic, so there are loopholes where the interrupt wont trigger if the time requested is in the past at the time of programming the ALM0_EN bit. However, we will not have unexpected interrupts while the time is programmed after the interrupt are enabled. Signed-off-by: Nishanth Menon <nm@ti.com> Reviewed-by: Grygorii Strashko <grygorii.strashko@linaro.org> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2014-12-10rtc: ds1307: add support for mcp7940x chipsTomas Novotny1-63/+64
MCP7940x is same RTC as MCP7941x. The difference is that MCP7941x chips contain additional EEPROM on a different i2c address. DS1307 driver already supports MCP7941x, so just add a new i2c device id and rename functions and defines accordingly. Signed-off-by: Tomas Novotny <tomas@novotny.cz> Cc: Alessandro Zummo <a.zummo@towertech.it> Cc: Grant Likely <grant.likely@linaro.org> Cc: Rob Herring <robh+dt@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-10-14rtc: ds1307: add trickle charger device tree bindingMatti Vaittinen1-4/+63
Some DS13XX devices have "trickle chargers". Introduce a device tree binding for specifying the trickle charger configuration for ds1339. Only ds1339 dt binding is supported because this is the only chip I have. I _assume_ the code would have worked on other allready supported chips. However I cannot check the resistor values for the other chips or test them. For other chips the driver code works as earlier Eg. it does not check the dt bindings at all Signed-off-by: Matti Vaittinen <matti.vaittinen@nsn.com> Cc: Rob Herring <robh+dt@kernel.org> Cc: Pawel Moll <pawel.moll@arm.com> Cc: Jason Cooper <jason@lakedaemon.net> Cc: Guenter Roeck <linux@roeck-us.net> Cc: Alessandro Zummo <a.zummo@towertech.it> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Pavel Machek <pavel@denx.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-03drivers/rtc/rtc-ds1307.c: add alarm support for mcp7941x chipsSimon Guinot1-1/+182
Add alarm support for the Microchip RTC devices MCP794xx. Note that two programmable alarms are provided by the chip but only one is used by the driver. Signed-off-by: Simon Guinot <simon.guinot@sequanux.org> Cc: Jason Cooper <jason@lakedaemon.net> Cc: Andrew Lunn <andrew@lunn.ch> Cc: Gregory Clement <gregory.clement@free-electrons.com> Cc: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-03drivers/rtc/rtc-ds1307.c: fix sysfs wakealarm attribute creationSimon Guinot1-1/+1
In order to allow the creation of the sysfs attribute wakealarm, this patch moves the device_set_wakeup_capable() call above the RTC device registration. Signed-off-by: Simon Guinot <simon.guinot@sequanux.org> Cc: Jason Cooper <jason@lakedaemon.net> Cc: Andrew Lunn <andrew@lunn.ch> Cc: Gregory Clement <gregory.clement@free-electrons.com> Cc: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-03rtc: fix potential race conditionAlessandro Zummo1-27/+33
RTC drivers must not return an error after device registration. [akpm@linux-foundation.org: coding-style fixes] Signed-off-by: Alessandro Zummo <a.zummo@towertech.it> Reported-by: Ales Novak <alnovak@suse.cz> Cc: Alexander Shiyan <shc_work@mail.ru> Cc: Atsushi Nemoto <anemo@mba.ocn.ne.jp> Cc: Jiri Kosina <jkosina@suse.cz> Cc: Srikanth Srinivasan <srikanth.srinivasan@freescale.com> Cc: Lee Jones <lee.jones@linaro.org> Cc: Sascha Hauer <s.hauer@pengutronix.de> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-11-13drivers/rtc/rtc-ds1307.c: change variable type to boolPeter Senna Tschudin1-1/+1
The variable want_irq is only assigned the values true and false. Change its type to bool. The simplified semantic patch that find this problem is as follows (http://coccinelle.lip6.fr/): @exists@ type T; identifier b; @@ - T + bool b = ...; ... when any b = \(true\|false\) Signed-off-by: Peter Senna Tschudin <peter.senna@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-11-13drivers/rtc/rtc-ds1307.c: use dev_get_platdata()Jingoo Han1-1/+1
Use the wrapper function for retrieving the platform data instead of accessing dev->platform_data directly. This is a cosmetic change to make the code simpler and enhance the readability. 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-11-13drivers/rtc/rtc-ds1307.c: release irq on errorSachin Kamat1-2/+4
'client->irq' was not released on error. Fix it. Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org> Cc: 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-07-03rtc: rtc-ds1307: use devm_*() functionsJingoo Han1-26/+17
Use devm_*() functions to make 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-29drivers/rtc/rtc-ds1307.c: change sysfs function pointer assignmentSteffen Trumtrar1-2/+2
The current usage of commas instead of semicolons is not wrong, but affects the readability of the code. Also, the code would break, if someone puts something between those two assignments. Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> Cc: Austin Boyle <Austin.Boyle@aviatnet.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-04-29rtc: rtc-ds1307: use dev_dbg() instead of pr_debug()Jingoo Han1-5/+5
dev_dbg() is preferred to pr_debug(). 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-29drivers/rtc/rtc-ds1307.c: long block operations bugfixBertrand Achard1-4/+56
The rtc-ds1307 driver does not properly handle block operations bigger than 32 bytes in either of the two modes supported (SMbus native, or emulated if not supported by the SMbus platform driver). It also does not properly handle userland-supplied input (block operation length) through sysfs and may suffer a type of buffer overrun. The driver has been modified with proper input validation, buffer sizes, and now splits block transfers bigger than 32 bytes into separate transfers. Explanation : Buffer size allocated is I2C_SMBUS_BLOCK_MAX which equals to 32 as per the SMbus spec. Reads and write may be up to 56 bytes (to the NVRAM). This patch allocated a 255 byte buffer, the maximum allowable (address is an u8). It's not only a buffer problem, SMbus only supports up to 32 bytes transfer at once, so it's needed to split bigger transfers. Patch successfully tested on 3.2.27; cleanly applies on 3.7-rc4. [akpm@linux-foundation.org: rework code to avoid 80-column overflows] Signed-off-by: Bertrand Achard <ba@cykian.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-21drivers/rtc: dump small buffers via %*phAndy Shevchenko1-9/+2
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-01-03Drivers: rtc: remove __dev* attributes.Greg Kroah-Hartman1-4/+4
CONFIG_HOTPLUG is going away as an option. As a result, the __dev* markings need to be removed. This change removes the use of __devinit, __devexit_p, __devinitdata, __devinitconst, and __devexit from these drivers. Based on patches originally written by Bill Pemberton, but redone by me in order to handle some of the coding style issues better, by hand. Cc: Bill Pemberton <wfp5p@virginia.edu> Cc: Alessandro Zummo <a.zummo@towertech.it> Cc: Srinidhi Kasagar <srinidhi.kasagar@stericsson.com> Cc: Linus Walleij <linus.walleij@linaro.org> Cc: Mike Frysinger <vapier.adi@gmail.com> Cc: Wan ZongShun <mcuos.com@gmail.com> Cc: Guan Xuetao <gxt@mprc.pku.edu.cn> Cc: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-05-29rtc: ds1307: add trickle charger supportWolfram Sang1-3/+16
Some DS13XX devices have "trickle chargers". Its configuration register is at different locations, the setup is the same, though. Since the configuration is board specific, introduce a platform_data to this driver. Tested with a DS1339 on a custom board. Signed-off-by: Wolfram Sang <w.sang@pengutronix.de> Cc: Alessandro Zummo <alessandro.zummo@towertech.it> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-05-29rtc: ds1307: remove superfluous initializationWolfram Sang1-1/+0
ds1307 was kzalloced, so no need to zero members of the struct. Signed-off-by: Wolfram Sang <w.sang@pengutronix.de> Acked-by: Joakim Tjernlund <Joakim.Tjernlund@transmode.se> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-04-25drivers/rtc/rtc-ds1307.c: fix BUG shown with lock debugging enabledAnatolij Gustschin1-0/+1
Add struct bin_attribute initialization to fix the following bug: rtc-ds1307 3-0068: rtc core: registered ds1307 as rtc0 BUG: key cfb14fcc not in .data! ------------[ cut here ]------------ WARNING: at kernel/lockdep.c:2986 sysfs_add_file_mode+0x84/0xdc() Modules linked in: [<c0018d94>] (unwind_backtrace+0x0/0xf8) from [<c0031f7c>] (warn_slowpath_common+0x4c/0x64) [<c0031f7c>] (warn_slowpath_common+0x4c/0x64) from [<c0031fb0>] (warn_slowpath_null+0x1c/0x24) [<c0031fb0>] (warn_slowpath_null+0x1c/0x24) from [<c012f7ac>] (sysfs_add_file_mode+0x84/0xdc) [<c012f7ac>] (sysfs_add_file_mode+0x84/0xdc) from [<c04b11e4>] (ds1307_probe+0x5e4/0x6ac) [<c04b11e4>] (ds1307_probe+0x5e4/0x6ac) from [<c036e600>] (i2c_device_probe+0xdc/0x108) [<c036e600>] (i2c_device_probe+0xdc/0x108) from [<c02cdf84>] (driver_probe_device+0x90/0x210) [<c02cdf84>] (driver_probe_device+0x90/0x210) from [<c02ce198>] (__driver_attach+0x94/0x98) [<c02ce198>] (__driver_attach+0x94/0x98) from [<c02cc824>] (bus_for_each_dev+0x50/0x7c) [<c02cc824>] (bus_for_each_dev+0x50/0x7c) from [<c02cd780>] (bus_add_driver+0x184/0x244) [<c02cd780>] (bus_add_driver+0x184/0x244) from [<c02ce43c>] (driver_register+0x78/0x12c) [<c02ce43c>] (driver_register+0x78/0x12c) from [<c03701ac>] (i2c_register_driver+0x2c/0xb4) [<c03701ac>] (i2c_register_driver+0x2c/0xb4) from [<c0008798>] (do_one_initcall+0x34/0x178) [<c0008798>] (do_one_initcall+0x34/0x178) from [<c0691860>] (kernel_init+0xdc/0x194) [<c0691860>] (kernel_init+0xdc/0x194) from [<c0013cf0>] (kernel_thread_exit+0x0/0x8) Since commit 6992f5334995af4 ("sysfs: Use one lockdep class per sysfs attribute") this initialization is required. Reported-by: Stefano Babic <sbabic@denx.de> Tested-by: Stefano Babic <sbabic@denx.de> Signed-off-by: Anatolij Gustschin <agust@denx.de> Cc: Alessandro Zummo <a.zummo@towertech.it> Cc: Stefano Babic <sbabic@denx.de> Cc: Eric W. Biederman <ebiederm@xmission.com> Cc: Greg Kroah-Hartman <gregkh@suse.de> Acked-by: Wolfram Sang <w.sang@pengutronix.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-03-23rtc: ds1307: generalise ram size and offsetAustin Boyle1-31/+47
Generalise NVRAM to support RAM with other size and offset, such as the 64 bytes of SRAM on the mcp7941x. [rdunlap@xenotime.net: fix printk format warning] Signed-off-by: Austin Boyle <Austin.Boyle@aviatnet.com> Signed-off-by: Wolfram Sang <w.sang@pengutronix.de> Signed-off-by: Randy Dunlap <rdunlap@xenotime.net> Cc: David Anders <danders.dev@gmail.com> Cc: Alessandro Zummo <alessandro.zummo@towertech.it> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-03-23rtc: ds1307: comment and format cleanupDavid Anders1-13/+24
Do some cleanup of the comment sections as well as correct some formatting issues reported by checkpatch.pl. Signed-off-by: David Anders <x0132446@ti.com> Signed-off-by: Wolfram Sang <w.sang@pengutronix.de> Cc: Austin Boyle <Austin.Boyle@aviatnet.com> Cc: Alessandro Zummo <alessandro.zummo@towertech.it> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-03-23rtc: ds1307: simplify irq setup codeWolfram Sang1-6/+5
No need to have two seperate if-blocks for setting up the irq. Signed-off-by: Wolfram Sang <w.sang@pengutronix.de> Tested-by: David Anders <danders.dev@gmail.com> Cc: Austin Boyle <Austin.Boyle@aviatnet.com> Cc: Alessandro Zummo <alessandro.zummo@towertech.it> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-03-23rtc: ds1307: refactor chip_desc tableWolfram Sang1-29/+19
The chip_desc table is suboptimal. Currently it requires an entry for every new chip type, even if it is empty. This has already been forgotten for the ds1388. Refactor the code, so new entries are only needed, when they chip type really needs a (non-empty) description. Also make the table visually more appealing. Signed-off-by: Wolfram Sang <w.sang@pengutronix.de> Cc: Austin Boyle <Austin.Boyle@aviatnet.com> Cc: David Anders <danders.dev@gmail.com> Cc: Alessandro Zummo <alessandro.zummo@towertech.it> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-03-23rtc: convert rtc i2c drivers to module_i2c_driverAxel Lin1-11/+1
Factor out some boilerplate code for i2c driver registration into module_i2c_driver. Signed-off-by: Axel Lin <axel.lin@gmail.com> Cc: Piotr Ziecik <kosmo@semihalf.com> Cc: Alessandro Zummo <a.zummo@towertech.it> Cc: Scott Wood <scottwood@freescale.com> Cc: Srikanth Srinivasan <srikanth.srinivasan@freescale.com> Cc: Mike Rapoport <mike@compulab.co.il> Cc: Sergey Lapin <slapin@ossfans.org> Cc: Roman Fietze <roman.fietze@telemotive.de> Cc: Herbert Valerio Riedel <hvr@gnu.org> Cc: Alexander Bigga <ab@mycable.de> Cc: Dale Farnsworth <dale@farnsworth.org> Cc: Gregory Hermant <gregory.hermant@calao-systems.com> Cc: Wolfgang Grandegger <wg@grandegger.com> Cc: Martyn Welch <martyn.welch@ge.com> Cc: Byron Bradley <byron.bbradley@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-11-02rtc: add initial support for mcp7941x partsDavid Anders1-0/+27
Add initial support for the microchip mcp7941x series of real time clocks. The mcp7941x series is generally compatible with the ds1307 and ds1337 rtc devices from dallas semiconductor. minor differences include a backup battery enable bit, and the polarity of the oscillator enable bit. Signed-off-by: David Anders <danders.dev@gmail.com> Cc: Alessandro Zummo <a.zummo@towertech.it> Reviewed-by: Wolfram Sang <w.sang@pengutronix.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-06-27drivers/rtc/rtc-ds1307.c: add support for RTC device pt7c4338Priyanka Jain1-0/+1
PT7C4338 chip is being manufactured by Pericom Technology Inc. It is a serial real-time clock which provides: 1) Low-power clock/calendar. 2) Programmable square-wave output. It has 56 bytes of nonvolatile RAM. Its register set is same as that of rtc device: DS1307. Signed-off-by: Priyanka Jain <Priyanka.Jain@freescale.com> Acked-by: Timur Tabi <timur@freescale.com> Reviewed-by: Wolfram Sang <w.sang@pengutronix.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-02-03RTC: Convert rtc drivers to use the alarm_irq_enable methodJohn Stultz1-36/+13
Some rtc drivers use the ioctl method instead of the alarm_irq_enable method for enabling alarm interupts. With the new virtualized RTC rework, its important for drivers to use the alarm_irq_enable instead. This patch converts the drivers that use the AIE ioctl method to use the alarm_irq_enable method. Other ioctl cmds are left untouched. I have not been able to test or even compile most of these drivers. Any help to make sure this change is correct would be appreciated! CC: Alessandro Zummo <a.zummo@towertech.it> CC: Thomas Gleixner <tglx@linutronix.de> CC: Marcelo Roberto Jimenez <mroberto@cpti.cetuc.puc-rio.br> Reported-by: Marcelo Roberto Jimenez <mroberto@cpti.cetuc.puc-rio.br> Tested-by: Marcelo Roberto Jimenez <mroberto@cpti.cetuc.puc-rio.br> Signed-off-by: John Stultz <john.stultz@linaro.org>
2011-01-10i2c: Constify i2c_client where possibleJean Delvare1-6/+6
Helper functions for I2C and SMBus transactions don't modify the i2c_client that is passed to them, so it can be marked const. Signed-off-by: Jean Delvare <khali@linux-fr.org>
2010-06-29rtc: fix ds1388 time corruptionJoakim Tjernlund1-2/+2
The ds1307 driver misreads the ds1388 registers when checking for 12 or 24 hour mode. Instead of checking the hour register it reads the minute register. Therefore the driver thinks minutes >= 40 has the 12HR bit set and resets the minute register by zeroing the high bits. This results in minutes are reset to 0-9, jumping back in time 40 or 50 minutes. The time jump is also written back to the RTC. Signed-off-by: Joakim Tjernlund <Joakim.Tjernlund@transmode.se> Cc: Wan ZongShun <mcuos.com@gmail.com> Cc: Alessandro Zummo <a.zummo@towertech.it> Cc: Paul Gortmaker <p_gortmaker@yahoo.com> Cc: <stable@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2010-05-21sysfs: add struct file* to bin_attr callbacksChris Wright1-2/+4
This allows bin_attr->read,write,mmap callbacks to check file specific data (such as inode owner) as part of any privilege validation. Signed-off-by: Chris Wright <chrisw@sous-sol.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2009-12-17rtc: set wakeup capability for I2C and SPI RTC driversAnton Vorontsov1-0/+2
RTC core won't allow wakeup alarms to be set if RTC devices' parent (i.e. i2c_client or spi_device) isn't wakeup capable. For I2C devices there is I2C_CLIENT_WAKE flag exists that we can pass via board info, and if set, I2C core will initialize wakeup capability. For SPI devices there is no such flag at all. I believe that it's not platform code responsibility to allow or disallow wakeups, instead, drivers themselves should set the capability if a device can trigger wakeups. That's what drivers/base/power/sysfs.c says: * It is the responsibility of device drivers to enable (or disable) * wakeup signaling as part of changing device power states, respecting * the policy choices provided through the driver model. I2C and SPI RTC devices send wakeup events via interrupt lines, so we should set the wakeup capability if IRQ is routed. Ideally we should also check irq for wakeup capability before setting device's capability, i.e. if (can_irq_wake(irq)) device_set_wakeup_capable(&client->dev, 1); But there is no can_irq_wake() call exist, and it is not that trivial to implement it for all interrupts controllers and complex/cascaded setups. drivers/base/power/sysfs.c also covers these cases: * Devices may not be able to generate wakeup events from all power * states. Also, the events may be ignored in some configurations; * for example, they might need help from other devices that aren't * active So there is no guarantee that wakeup will actually work, and so I think there is no point in being pedantic wrt checking IRQ wakeup capability. Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com> Cc: David Brownell <dbrownell@users.sourceforge.net> Cc: Ben Dooks <ben-linux@fluff.org> Cc: Jean Delvare <khali@linux-fr.org> 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>
2009-12-16rtc: ds1307 make it possible to share an irqDmitry Eremin-Solenikov1-1/+1
It's possible to have RTC irq shared with other device (e.g. mpc8349e-mitx board shares ds1339 irq with phy one). Handle this in driver. Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> Signed-off-by: Alessandro Zummo <a.zummo@towertech.it> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2009-09-23drivers/rtc: correct error-handling codeJulia Lawall1-2/+1
This code is not executed before ds1307->rtc has been successfully initialized to the result of calling rtc_device_register. Thus the test that ds1307->rtc is not NULL is always true. A simplified version of the semantic match that finds this problem is as follows: (http://coccinelle.lip6.fr/) // <smpl> @match exists@ expression x, E; statement S1, S2; @@ x = rtc_device_register(...) ... when != x = E ( * if (x == NULL || ...) S1 else S2 | * if (x == NULL && ...) S1 else S2 ) // </smpl> Signed-off-by: Julia Lawall <julia@diku.dk> Acked-by: Wolfram Sang <w.sang@pengutronix.de> Cc: David Brownell <david-b@pacbell.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2009-06-19rtc: make rtc_update_irq callable with irqs enabledAtsushi Nemoto1-5/+0
The rtc_update_irq() might be called with irqs enabled, if a interrupt handler was registered without IRQF_DISABLED. Use spin_lock_irqsave/spin_unlock_irqrestore instead of spin_lock/spin_unlock. Also update kerneldoc and drivers which do extra work to follow the current interface spec, as suggestted by David Brownell. Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp> Cc: Alessandro Zummo <a.zummo@towertech.it> Cc: David Brownell <david-b@pacbell.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2009-06-18rtc: rtc-ds1307 add ds3231Wolfram Sang1-4/+18
Add ds3231 variant. For that, the BBSQI bit position was changed from a simple define into a lookup-array as it differs. This also removes writing to an unused bit in case of the ds1337. Signed-off-by: Wolfram Sang <w.sang@pengutronix.de> Acked-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Alessandro Zummo <a.zummo@towertech.it> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2009-06-18rtc: rtc-ds1307 add ds1388Joakim Tjernlund1-4/+15
Extend the ds1307 driver to support ds1388 too. Signed-off-by: Joakim Tjernlund <Joakim.Tjernlund@transmode.se> Signed-off-by: Alessandro Zummo <a.zummo@towertech.it> Cc: David Brownell <david-b@pacbell.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2009-04-01rtc: add EPSON RX8025 support to DS1307 RTC driverMatthias Fuchs1-0/+80
Add support for the EPSON RX8025 RTC. The date/time registers of this chip are compatible with the DS1307. Signed-off-by: Matthias Fuchs <matthias.fuchs@esd-electronics.com> Signed-off-by: Alessandro Zummo <a.zummo@towertech.it> Cc: David Brownell <david-b@pacbell.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2009-04-01rtc-ds1307: true SMBus compatibilityEd Swierk1-12/+97
Allow the rtc-ds1307 driver to work with SMBus controllers like nforce2 that do not support i2c block transfers. Signed-off-by: Ed Swierk <eswierk@aristanetworks.com> Acked-by: Jean Delvare <khali@linux-fr.org> Acked-by: David Brownell <dbrownell@users.sourceforge.net> Cc: Alessandro Zummo <a.zummo@towertech.it> Cc: BARRE Sebastien <sbarre@sdelcc.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2009-01-08rtc-ds1307: remove legacy probe() checksJüri Reitel1-27/+4
Remove RTC register value checks from the rtc-ds1307 probe() function. They were left over from the legacy style I2C driver, which had to defend against finding a non-RTC chip when the driver was probed. Also fix a minor glitch in the alarm support: DS1307 chips don't have alarms, so name those methods after one of the chips which actually *do* have alarms (DS1337). Signed-off-by: Jüri Reitel <juri.reitel@liewenthal.ee> Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Cc: Sebastien Barre <sbarre@sdelcc.com> Cc: Alessandro Zummo <a.zummo@towertech.it> Acked-by: Jean Delvare <khali@linux-fr.org> Cc: Rodolfo Giometti <giometti@enneenne.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2009-01-08rtc-ds1307: SMBus compatibilityBARRE Sebastien1-88/+35
Change i2c access functions to SMBus access functions in order to use the ds1307 with SMBus adapter. Signed-off-by: Sebastien Barre <sbarre@sdelcc.com> Acked-by: David Brownell <david-b@pacbell.net> Tested-by: David Brownell <david-b@pacbell.net> Acked-by: Alessandro Zummo <a.zummo@towertech.it> Acked-by: Jean Delvare <khali@linux-fr.org> Cc: Rodolfo Giometti <giometti@enneenne.com> Tested-by: Sebastien Barre <sbarre@sdelcc.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-10-20x86: sysfs: kill owner field from attributeParag Warudkar1-1/+0
Tejun's commit 7b595756ec1f49e0049a9e01a1298d53a7faaa15 made sysfs attribute->owner unnecessary. But the field was left in the structure to ease the merge. It's been over a year since that change and it is now time to start killing attribute->owner along with its users - one arch at a time! This patch is attempt #1 to get rid of attribute->owner only for CONFIG_X86_64 or CONFIG_X86_32 . We will deal with other arches later on as and when possible - avr32 will be the next since that is something I can test. Compile (make allyesconfig / make allmodconfig / custom config) and boot tested. akpm: the idea is that we put the declaration of sttribute.owner inside `#ifndef CONFIG_X86'. But that proved to be too ambitious for now because new usages kept on turning up in subsystem trees. [akpm: remove the ifdef for now] Signed-off-by: Parag Warudkar <parag.lkml@gmail.com> Cc: Greg KH <greg@kroah.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Tejun Heo <htejun@gmail.com> Cc: Len Brown <lenb@kernel.org> Cc: Jens Axboe <jens.axboe@oracle.com> Cc: Jean Delvare <khali@linux-fr.org> Cc: Roland Dreier <rolandd@cisco.com> Cc: David Brownell <david-b@pacbell.net> 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>
2008-10-20drivers/rtc/: use bcd2bin/bin2bcdAdrian Bunk1-20/+20
Change drivers/rtc/ to use the new bcd2bin/bin2bcd functions instead of the obsolete BCD_TO_BIN/BIN_TO_BCD/BCD2BIN/BIN2BCD macros. Signed-off-by: Adrian Bunk <bunk@kernel.org> Acked-by: Alessandro Zummo <a.zummo@towertech.it> Cc: David Brownell <david-b@pacbell.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-10-16rtc-ds1307: alarm support for ds1337/ds1339Rodolfo Giometti1-13/+295
Update the ds1307 driver with alarm support for ds1337/ds1339. This uses the first alarm (there are two), and matches on seconds, minutes, hours, and day-of-month. Tested on ds1339. [dbrownell@users.sourceforge.net: add comments; fixup style, valid irq checks, debug dumps; lock; more careful IRQ shutdown; switch BCD2BIN to bcd2bin (and vice versa); ENOTTY not EINVAL.] Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Rodolfo Giometti <giometti@linux.it> 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>
2008-04-29i2c: Convert most new-style drivers to use module aliasingJean Delvare1-38/+25
Based on earlier work by Jon Smirl and Jochen Friedrich. Update most new-style i2c drivers to use standard module aliasing instead of the old driver_name/type driver matching scheme. I've left the video drivers apart (except for SoC camera drivers) as they're a bit more diffcult to deal with, they'll have their own patch later. Signed-off-by: Jean Delvare <khali@linux-fr.org> Cc: Jon Smirl <jonsmirl@gmail.com> Cc: Jochen Friedrich <jochen@scram.de>
2008-04-29i2c: Add support for device alias namesJean Delvare1-1/+2
Based on earlier work by Jon Smirl and Jochen Friedrich. This patch allows new-style i2c chip drivers to have alias names using the official kernel aliasing system and MODULE_DEVICE_TABLE(). At this point, the old i2c driver binding scheme (driver_name/type) is still supported. Signed-off-by: Jean Delvare <khali@linux-fr.org> Cc: Jochen Friedrich <jochen@scram.de> Cc: Jon Smirl <jonsmirl@gmail.com> Cc: Kay Sievers <kay.sievers@vrfy.org>
2008-02-06rtc ds1307: ds_1340 change initfrederic Rodo1-7/+20
For DS140, clear the oscillator fault flag as needed. Signed-off-by: Frederic RODO <f.rodo@til-technologies.fr> [ And remove some "sparse" warnings. ] Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-11-14rtc-ds1307 exports NVRAMDavid Brownell1-0/+93
Export the NVRAM on DS1307 and DS1338 chips, like several of the other drivers do for such combination RTC-and-NVRAM chips. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Acked-by: Alessandro Zummo <a.zummo@towertech.it> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-26rtc-ds1307: typo fix found by coverityDavid Brownell1-1/+1
Fix a typo turned up by a Coverity check: referring to the wrong register, which could cause problems with DS1338 RTCs whose oscillators halted. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-17rtc-ds1307 becomes new-style i2c driverDavid Brownell1-75/+53
Convert the rtc-ds1307 driver into a "new style" driver. Also improve probe() checks: be more correct about switching out of AM/PM mode, and issue a (debug) diagnostic when failing due to bogus register values. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Cc: Andrew Victor <andrew@sanpeople.com> Cc: Bill Gatliff <bgat@billgatliff.com> Cc: Alessandro Zummo <a.zummo@towertech.it> Cc: Paul Mackerras <paulus@samba.org> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Kumar Gala <galak@gate.crashing.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-17rtc-ds1307: oscillator restart for ds13{37,38,39,40}Rodolfo Giometti1-21/+45
When we find a ds1337 or ds1339 with the oscillator powered off, turn it on. If the oscillator fault flag was set, clear it and warn that the clock needs to be set. David Brownell: Bugfixes; provide corresponding update for ds1338, and the core of the fix for ds1340. Use a common warning message ("SET TIME!") whenever the clock needs to be set after oscillator fault (or oscillator enable, if fault is not a separate status). Signed-off-by: Rodolfo Giometti <giometti@linux.it> Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-17rtc-ds1307 cleanupsDavid Brownell1-52/+124
This updates the rtc-ds1307 driver so that converting it to a "new style" driver (driver model, not legacy i2c model) will involve fewer changes. - Use pointer to i2c_client almost everywhere, so that it's easy to let the i2c core create that object; - Avoid using i2c_client.adapter, since that field is redundant and thus may go away (same object as i2c_client.dev.parent). - Extend type enum to include various RTCs this is expected to work with, and include register support for them. It also cleans up the support for multiple chip types, and fixes a glitch that could appear with an un-initialized RTC. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2006-10-04[PATCH] RTC: build fixesJeff Garzik1-3/+3
Fix obvious build breakage revealed by 'make allyesconfig' in current -git. Signed-off-by: Jeff Garzik <jeff@garzik.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-10-01[PATCH] constify rtc_class_ops: update driversDavid Brownell1-1/+1
Update RTC framework so that drivers can constify their method tables, moving them from ".data" to ".rodata". Then update the drivers. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Cc: Alessandro Zummo <a.zummo@towertech.it> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-06-25[PATCH] "RTC-framework" driver for DS1307 and similar RTC chipsDavid Brownell1-0/+388
This is an "RTC-framework" driver for DS1307 and similar RTC chips, It should be a full replacement for the existing ds1337.c driver (using the older RTC glue), giving a net increase in the number of RTC chips that work out-of-the-box. There's a whole cluster of RTCs that are very similar, but the 1337 driver was a bit too picky to work with most of them. Still no support for RTC alarm IRQs (on chips that support them). Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: James Chapman <jchapman@katalix.com> Signed-off-by: Alessandro Zummo <a.zummo@towertech.it> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>