From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: Pavel Modilaynen <pavel.modilaynen@axis.com>
Cc: a.zummo@towertech.it, robh+dt@kernel.org,
linux-rtc@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, lkml@axis.com, kernel@axis.com,
Pavel Modilaynen <pavelmn@axis.com>
Subject: Re: [PATCH 1/2] rtc: rs5c372: Add support for trim configuration
Date: Sun, 31 Oct 2021 00:57:57 +0200 [thread overview]
Message-ID: <YX3N9b6P4w1kSGfp@piout.net> (raw)
In-Reply-To: <20211030225054.32114-2-pavel.modilaynen@axis.com>
Hello,
Please use the proper RTC interface by implementing .set_offset and
.read_offset.
On 31/10/2021 00:50:53+0200, Pavel Modilaynen wrote:
> From: Pavel Modilaynen <pavelmn@axis.com>
>
> Add support for oscillation adjustment register RS5C372_REG_TRIM
> setting that is needed to accommodate for effective crystal
> capacitance.
>
> Use optional property ricoh,trim that should contain
> raw value to setup this register. According to
> datasheets for RS5C372, R2025S/D, RV5C38[67] and R222[13]
> the value will be converted to a number of ticks that
> is to be subtracted or added when the second digits read
> 00, 20 or 40 seconds.
>
> Signed-off-by: Pavel Modilaynen <pavelmn@axis.com>
> ---
> drivers/rtc/rtc-rs5c372.c | 18 +++++++++++++++++-
> 1 file changed, 17 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/rtc/rtc-rs5c372.c b/drivers/rtc/rtc-rs5c372.c
> index 80980414890c..3a2db0326669 100644
> --- a/drivers/rtc/rtc-rs5c372.c
> +++ b/drivers/rtc/rtc-rs5c372.c
> @@ -13,6 +13,7 @@
> #include <linux/slab.h>
> #include <linux/module.h>
> #include <linux/of_device.h>
> +#include <linux/of.h>
>
> /*
> * Ricoh has a family of I2C based RTCs, which differ only slightly from
> @@ -560,6 +561,8 @@ static int rs5c_oscillator_setup(struct rs5c372 *rs5c372)
> {
> unsigned char buf[2];
> int addr, i, ret = 0;
> + struct i2c_client *client = rs5c372->client;
> + u8 trim = 0;
>
> addr = RS5C_ADDR(RS5C_REG_CTRL1);
> buf[0] = rs5c372->regs[RS5C_REG_CTRL1];
> @@ -599,9 +602,22 @@ static int rs5c_oscillator_setup(struct rs5c372 *rs5c372)
> break;
> }
>
> + /* optional setup of xtal trimming */
> + if (!of_property_read_u8(client->dev.of_node, "ricoh,trim", &trim)) {
> + if (rs5c372->type != rtc_r2221tl && (trim & ~RS5C372_TRIM_MASK)) {
> + dev_warn(&client->dev, "Erroneous setting for ricoh,trim in devicetree\n");
> + } else {
> + int addr = RS5C_ADDR(RS5C372_REG_TRIM);
> + int ret = i2c_smbus_write_byte_data(client, addr, trim);
> +
> + if (unlikely(ret < 0))
> + return ret;
> + }
> + }
> +
> for (i = 0; i < sizeof(buf); i++) {
> addr = RS5C_ADDR(RS5C_REG_CTRL1 + i);
> - ret = i2c_smbus_write_byte_data(rs5c372->client, addr, buf[i]);
> + ret = i2c_smbus_write_byte_data(client, addr, buf[i]);
> if (unlikely(ret < 0))
> return ret;
> }
> --
> 2.20.1
>
--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
next prev parent reply other threads:[~2021-10-30 22:58 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-30 22:50 [PATCH 0/2] *** Ricoh RS5C372: add support for Xtal trimming configuration *** Pavel Modilaynen
2021-10-30 22:50 ` [PATCH 1/2] rtc: rs5c372: Add support for trim configuration Pavel Modilaynen
2021-10-30 22:57 ` Alexandre Belloni [this message]
2021-10-31 10:29 ` Pavel Modilaynen
2021-11-01 18:23 ` Alexandre Belloni
2021-11-01 23:14 ` Pavel Modilaynen
2021-11-05 15:26 ` Alexandre Belloni
2021-10-30 22:50 ` [PATCH 2/2] dt-bindings: rtc: Add bindings for Ricoh rs5c372 Pavel Modilaynen
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=YX3N9b6P4w1kSGfp@piout.net \
--to=alexandre.belloni@bootlin.com \
--cc=a.zummo@towertech.it \
--cc=devicetree@vger.kernel.org \
--cc=kernel@axis.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
--cc=lkml@axis.com \
--cc=pavel.modilaynen@axis.com \
--cc=pavelmn@axis.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).