Commit ac75779b authored by Alexandre Belloni's avatar Alexandre Belloni

rtc: nvmem: allow registering the nvmem device before the rtc

Switch the parent of the nvmem device to the parent of the rtc device so it
can be registered before the RTC.

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

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

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

Finally, it makes a lot of sense for devices that actually have different
i2c or spi addresses for the RTC and the EEPROM. That is basically how it
would end up when using MFD or even completely separate devices.
Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
parent ab3ea36e
...@@ -57,14 +57,6 @@ Contact: linux-rtc@vger.kernel.org ...@@ -57,14 +57,6 @@ Contact: linux-rtc@vger.kernel.org
Description: Description:
(RO) RTC-provided time in 24-hour notation (hh:mm:ss) (RO) RTC-provided time in 24-hour notation (hh:mm:ss)
What: /sys/class/rtc/rtcX/*/nvmem
Date: July 2017
KernelVersion: 4.13
Contact: linux-rtc@vger.kernel.org
Description:
(RW) The non volatile storage exported as a raw file, as
described in Documentation/nvmem/nvmem.txt
What: /sys/class/rtc/rtcX/offset What: /sys/class/rtc/rtcX/offset
Date: February 2016 Date: February 2016
KernelVersion: 4.6 KernelVersion: 4.6
......
...@@ -293,8 +293,6 @@ EXPORT_SYMBOL_GPL(rtc_device_register); ...@@ -293,8 +293,6 @@ EXPORT_SYMBOL_GPL(rtc_device_register);
*/ */
void rtc_device_unregister(struct rtc_device *rtc) void rtc_device_unregister(struct rtc_device *rtc)
{ {
rtc_nvmem_unregister(rtc);
mutex_lock(&rtc->ops_lock); mutex_lock(&rtc->ops_lock);
/* /*
* Remove innards of this RTC, then disable it, before * Remove innards of this RTC, then disable it, before
...@@ -312,6 +310,7 @@ static void devm_rtc_device_release(struct device *dev, void *res) ...@@ -312,6 +310,7 @@ static void devm_rtc_device_release(struct device *dev, void *res)
{ {
struct rtc_device *rtc = *(struct rtc_device **)res; struct rtc_device *rtc = *(struct rtc_device **)res;
rtc_nvmem_unregister(rtc);
rtc_device_unregister(rtc); rtc_device_unregister(rtc);
} }
...@@ -382,6 +381,8 @@ static void devm_rtc_release_device(struct device *dev, void *res) ...@@ -382,6 +381,8 @@ static void devm_rtc_release_device(struct device *dev, void *res)
{ {
struct rtc_device *rtc = *(struct rtc_device **)res; struct rtc_device *rtc = *(struct rtc_device **)res;
rtc_nvmem_unregister(rtc);
if (rtc->registered) if (rtc->registered)
rtc_device_unregister(rtc); rtc_device_unregister(rtc);
else else
......
...@@ -93,7 +93,7 @@ int rtc_nvmem_register(struct rtc_device *rtc, ...@@ -93,7 +93,7 @@ int rtc_nvmem_register(struct rtc_device *rtc,
if (!nvmem_config) if (!nvmem_config)
return -ENODEV; return -ENODEV;
nvmem_config->dev = &rtc->dev; nvmem_config->dev = rtc->dev.parent;
nvmem_config->owner = rtc->owner; nvmem_config->owner = rtc->owner;
rtc->nvmem = nvmem_register(nvmem_config); rtc->nvmem = nvmem_register(nvmem_config);
if (IS_ERR_OR_NULL(rtc->nvmem)) if (IS_ERR_OR_NULL(rtc->nvmem))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment