Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3303513pxb; Mon, 1 Nov 2021 11:24:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx2rK3i6L6BGSB6i9Opn8rnMGkZhUpREzS3mWt+WA4KiKHwiIm49tQ8xJVT3bM0fX//FEJw X-Received: by 2002:a05:6e02:1d9e:: with SMTP id h30mr14755598ila.138.1635791070139; Mon, 01 Nov 2021 11:24:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635791070; cv=none; d=google.com; s=arc-20160816; b=Nn1W9qrhdnbtHBvzruHbg9rZeCvqXLOqLVSkGM+hWBscu4NN2F2dDRx1S7Tl5AIbxu Ql7hOerWw1T+iifMv/7aH24AeNtna59lJuiwYkB46CQcJKbvf1N39u0SyYx+qiiJ+Sfi ruwkeeKQhIc08ZC/NINGAPsQCjEk46ycgTEZLwrbKAltYDq07SK6LH2FeSeAAheQ/1ql bN226ErNlxCSy1/oXV1HY6fLSVTQA0nr3OUTlTYcJh42/BoAXIRXyHLilg/IU4d5WBu5 jDTc/bcUaF4YHZy+Bu4W/zLKYwYnb8YppX5TBCAYTTBHyJUXV5/t0/8e3RKYVVO5QZFJ GyJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=K8CXUtfe5mCHtjYKYCuvrrYcM5X+quVPA/7zfM5Ag9A=; b=O57K8zuh3huMQdchOPgtW80JNS3fUyJzMIYIHpura2mrxr0fwj5hJIMX5ZfltlcpyW yp16RBNnCS8qGf6ZJ3u0/djK2MKnso5+/C9+Sh3hMdLXkQ3cIflTpM4Ie95afeh2EsqC m/nfa/koHRwiarDr5NflY64Y+xkn6u+/5yjpkFCPXW+Q8jUcuuWRJyaFnTXj/tRSbBnk QuZ30rNWwDjIK3/TQsl/CruxOYZMSoGWIwOc1KOp8VogMhOM15GhCCEHfV1IbMyU199v gCaED1Dmjzw225MV9bBMoA9h6J91hYRxG4sSQXp1y6HnycYRhOc+PyiT4E5KEE3RCdP9 yfKg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h6si16655424iow.74.2021.11.01.11.24.18; Mon, 01 Nov 2021 11:24:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231743AbhKASZz (ORCPT + 99 others); Mon, 1 Nov 2021 14:25:55 -0400 Received: from relay1-d.mail.gandi.net ([217.70.183.193]:45027 "EHLO relay1-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231533AbhKASZy (ORCPT ); Mon, 1 Nov 2021 14:25:54 -0400 Received: (Authenticated sender: alexandre.belloni@bootlin.com) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 7F356240009; Mon, 1 Nov 2021 18:23:13 +0000 (UTC) Date: Mon, 1 Nov 2021 19:23:13 +0100 From: Alexandre Belloni To: Pavel Modilaynen Cc: Pavel Modilaynen , "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 Subject: Re: [PATCH 1/2] rtc: rs5c372: Add support for trim configuration Message-ID: References: <20211030225054.32114-1-pavel.modilaynen@axis.com> <20211030225054.32114-2-pavel.modilaynen@axis.com> <6cc22970-fa11-ccb4-c155-62396a7e3890@axis.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <6cc22970-fa11-ccb4-c155-62396a7e3890@axis.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 31/10/2021 11:29:12+0100, Pavel Modilaynen wrote: > On 10/31/21 12:57 AM, Alexandre Belloni wrote: > > Hello, > > > > Please use the proper RTC interface by implementing .set_offset and > > .read_offset. > > I am not sure about .set/read_offset. It looks as runtime adjustment > interface, > however this Xtal trimming parameter is based on schematics and Xtal > capacitance (datasheet parameter). > It is found by calibration procedure based on RTC clock output (the > procedure and calculation of trimming parameter is described in datasheets). > So, I would like to say that this parameter is functionally close to > "quartz-load-femtofarads" for rtc-pcf8523/pcf85063. > quartz-load-femtofarads is for analog trimming which this RTC doesn't have, both CD and CG are set to 10pF. .set/read_offset are for digital trimming which is what you are configuring here. You definitively want to be able to do that at runtime as you need to adjust for temperature and ageing of the crystal (datasheet, page 14: "For those systems that have temperature detection precision of clock function may be increased by correcting clock error according to temperature fluctuations.") > > > > On 31/10/2021 00:50:53+0200, Pavel Modilaynen wrote: > > > From: Pavel Modilaynen > > > > > > 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 > > > --- > > > ? 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 > > > ? #include > > > ? #include > > > +#include > > > ? /* > > > ?? * 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 -- Alexandre Belloni, co-owner and COO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com