From: Johan Hovold <johan@kernel.org>
To: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: Johan Hovold <johan+linaro@kernel.org>,
Bjorn Andersson <andersson@kernel.org>,
Andy Gross <agross@kernel.org>,
Konrad Dybcio <konrad.dybcio@linaro.org>,
Alessandro Zummo <a.zummo@towertech.it>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Maximilian Luz <luzmaximilian@gmail.com>,
linux-arm-msm@vger.kernel.org, linux-rtc@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 16/24] rtc: pm8xxx: add support for nvmem offset
Date: Fri, 27 Jan 2023 16:51:27 +0100 [thread overview]
Message-ID: <Y9Py/+GpI8x8ldDG@hovoldconsulting.com> (raw)
In-Reply-To: <Y9PpQkW3Rtm+bi2V@mail.local>
On Fri, Jan 27, 2023 at 04:09:54PM +0100, Alexandre Belloni wrote:
> On 26/01/2023 15:20:49+0100, Johan Hovold wrote:
> > On many Qualcomm platforms the PMIC RTC control and time registers are
> > read-only so that the RTC time can not be updated. Instead an offset
> > needs be stored in some machine-specific non-volatile memory, which the
> > driver can take into account.
> >
> > Add support for storing a 32-bit offset from the Epoch in an nvmem cell
> > so that the RTC time can be set on such platforms.
> >
> > Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
> > ---
> > drivers/rtc/rtc-pm8xxx.c | 134 +++++++++++++++++++++++++++++++++++----
> > 1 file changed, 123 insertions(+), 11 deletions(-)
> >
> > diff --git a/drivers/rtc/rtc-pm8xxx.c b/drivers/rtc/rtc-pm8xxx.c
> > index 922aef0f0241..09816b9f6282 100644
> > --- a/drivers/rtc/rtc-pm8xxx.c
> > +++ b/drivers/rtc/rtc-pm8xxx.c
> > @@ -3,6 +3,7 @@
> > */
> > #include <linux/of.h>
> > #include <linux/module.h>
> > +#include <linux/nvmem-consumer.h>
> > #include <linux/init.h>
> > #include <linux/rtc.h>
> > #include <linux/platform_device.h>
> > @@ -49,6 +50,8 @@ struct pm8xxx_rtc_regs {
> > * @alarm_irq: alarm irq number
> > * @regs: register description
> > * @dev: device structure
> > + * @nvmem_cell: nvmem cell for offset
> > + * @offset: offset from epoch in seconds
> > */
> > struct pm8xxx_rtc {
> > struct rtc_device *rtc;
> > @@ -57,8 +60,60 @@ struct pm8xxx_rtc {
> > int alarm_irq;
> > const struct pm8xxx_rtc_regs *regs;
> > struct device *dev;
> > + struct nvmem_cell *nvmem_cell;
> > + u32 offset;
> > };
> >
> > +static int pm8xxx_rtc_read_nvmem_offset(struct pm8xxx_rtc *rtc_dd)
> > +{
> > + size_t len;
> > + void *buf;
> > + int rc;
> > +
> > + buf = nvmem_cell_read(rtc_dd->nvmem_cell, &len);
> > + if (IS_ERR(buf)) {
> > + rc = PTR_ERR(buf);
> > + dev_err(rtc_dd->dev, "failed to read nvmem offset: %d\n", rc);
>
> You removed many dev_err strings in your previous patch and now this is
> verbose. Honestly, there is not much to do apart from reying the
> operation so I don't think the strings are worth it.
There's a difference. The SPMI ones are basically equivalent to mmio
reads, which we also don't expect to fail (and other spmi drivers also
ignore them).
These nvmem error paths I actually hit during development and it could
help someone trying to enable this feature on a new platform.
> > + return rc;
> > + }
> > +
> > + if (len != sizeof(u32)) {
> > + dev_err(rtc_dd->dev, "unexpected nvmem cell size %zu\n", len);
> > + kfree(buf);
> > + return -EINVAL;
> > + }
> > +
> > + rtc_dd->offset = get_unaligned_le32(buf);
> > +
> > + kfree(buf);
> > +
> > + return 0;
> > +}
> > @@ -380,9 +478,23 @@ static int pm8xxx_rtc_probe(struct platform_device *pdev)
> > rtc_dd->allow_set_time = of_property_read_bool(pdev->dev.of_node,
> > "allow-set-time");
> >
> > + rtc_dd->nvmem_cell = devm_nvmem_cell_get(&pdev->dev, "offset");
>
> Maybe we should get something more specific than just "offset" so this
> could be parsed in the RTC core at some point (this is the second RTC to
> behave like this)
Yes, that thought crossed my mind, but it's an nvmem cell name (label)
and not a generic devicetree property. If you look at the binding
document I think the name makes sense given the current description, and
I'm not sure changing to something like 'base' would be much of an
improvement.
I also don't expect there to be more broken RTCs out there like these
ones. Hopefully Qualcomm will even get this fixed at some point
themselves.
And I assume you were think of the old Atmel driver which uses a timer
counter and a scratch register as a base? That one is also a bit
different in that the timer can be reset, just not set.
> > + if (IS_ERR(rtc_dd->nvmem_cell)) {
> > + rc = PTR_ERR(rtc_dd->nvmem_cell);
> > + if (rc != -ENOENT)
> > + return rc;
> > + rtc_dd->nvmem_cell = NULL;
> > + }
Johan
next prev parent reply other threads:[~2023-01-27 15:51 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-26 14:20 [PATCH 00/24] rtc: pm8xxx: add support for setting time using nvmem Johan Hovold
2023-01-26 14:20 ` [PATCH 01/24] rtc: pm8xxx: fix set-alarm race Johan Hovold
2023-01-26 14:20 ` [PATCH 02/24] rtc: pm8xxx: drop spmi error messages Johan Hovold
2023-01-26 14:20 ` [PATCH 03/24] rtc: pm8xxx: use regmap_update_bits() Johan Hovold
2023-01-26 14:20 ` [PATCH 04/24] rtc: pm8xxx: drop bogus locking Johan Hovold
2023-01-26 14:20 ` [PATCH 05/24] rtc: pm8xxx: return IRQ_NONE on errors Johan Hovold
2023-01-26 14:20 ` [PATCH 06/24] rtc: pm8xxx: drop unused register defines Johan Hovold
2023-01-26 14:20 ` [PATCH 07/24] rtc: pm8xxx: use unaligned le32 helpers Johan Hovold
2023-01-26 14:20 ` [PATCH 08/24] rtc: pm8xxx: clean up time and alarm debugging Johan Hovold
2023-01-26 14:20 ` [PATCH 09/24] rtc: pm8xxx: rename struct device pointer Johan Hovold
2023-01-26 14:20 ` [PATCH 10/24] rtc: pm8xxx: rename alarm irq variable Johan Hovold
2023-01-26 14:20 ` [PATCH 11/24] rtc: pm8xxx: clean up comments Johan Hovold
2023-01-26 14:20 ` [PATCH 12/24] rtc: pm8xxx: use u32 for timestamps Johan Hovold
2023-01-26 14:20 ` [PATCH 13/24] rtc: pm8xxx: refactor read_time() Johan Hovold
2023-01-26 14:20 ` [PATCH 14/24] rtc: pm8xxx: clean up local declarations Johan Hovold
2023-01-26 14:20 ` [PATCH 15/24] dt-bindings: rtc: qcom-pm8xxx: add nvmem-cell offset Johan Hovold
2023-01-26 15:56 ` Krzysztof Kozlowski
2023-01-26 14:20 ` [PATCH 16/24] rtc: pm8xxx: add support for nvmem offset Johan Hovold
2023-01-27 14:13 ` Srinivas Kandagatla
2023-01-27 15:32 ` Johan Hovold
2023-01-27 15:09 ` Alexandre Belloni
2023-01-27 15:51 ` Johan Hovold [this message]
2023-01-27 16:05 ` Alexandre Belloni
2023-02-02 15:12 ` Johan Hovold
2023-02-02 15:21 ` Alexandre Belloni
2023-01-26 14:20 ` [PATCH 17/24] rtc: pm8xxx: add copyright notice Johan Hovold
2023-01-26 16:06 ` Alexandre Belloni
2023-01-27 13:04 ` Johan Hovold
2023-01-27 14:14 ` Krzysztof Kozlowski
2023-02-02 10:22 ` Johan Hovold
2023-01-26 14:20 ` [RFC 18/24] dt-bindings: rtc: qcom-pm8xxx: add uefi-variable offset Johan Hovold
2023-01-30 18:49 ` Rob Herring
2023-02-01 16:09 ` Johan Hovold
2023-02-09 16:59 ` Ard Biesheuvel
2023-01-26 14:20 ` [PATCH 19/24] rtc: pm8xxx: add support for uefi offset Johan Hovold
2023-01-26 14:27 ` Johan Hovold
2023-01-27 15:19 ` Alexandre Belloni
2023-01-27 15:26 ` Johan Hovold
2023-01-27 15:59 ` Alexandre Belloni
2023-01-26 14:20 ` [PATCH 20/24] arm64: defconfig: enable Qualcomm SDAM nvmem driver Johan Hovold
2023-01-26 14:20 ` [PATCH 21/24] arm64: dts: qcom: sc8280xp-pmics: add pmk8280 rtc Johan Hovold
2023-01-26 14:20 ` [PATCH 22/24] arm64: dts: qcom: sc8280xp-pmics: add pmk8280 sdam nvram Johan Hovold
2023-01-26 14:20 ` [PATCH 23/24] arm64: dts: qcom: sc8280xp-crd: enable rtc Johan Hovold
2023-01-26 14:20 ` [PATCH 24/24] arm64: dts: qcom: sc8280xp-x13s: " Johan Hovold
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y9Py/+GpI8x8ldDG@hovoldconsulting.com \
--to=johan@kernel.org \
--cc=a.zummo@towertech.it \
--cc=agross@kernel.org \
--cc=alexandre.belloni@bootlin.com \
--cc=andersson@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=johan+linaro@kernel.org \
--cc=konrad.dybcio@linaro.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
--cc=luzmaximilian@gmail.com \
--cc=robh+dt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).