Received: by 10.192.165.148 with SMTP id m20csp4677925imm; Tue, 8 May 2018 12:21:39 -0700 (PDT) X-Google-Smtp-Source: AB8JxZroWxKazfgpFFuZGcOISg2PR5e7OLZFPWVcVJPBWQ+/7TP1ss2E+RSxxkdM7sEALeRVqjOU X-Received: by 10.98.72.29 with SMTP id v29mr35471293pfa.57.1525807299866; Tue, 08 May 2018 12:21:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525807299; cv=none; d=google.com; s=arc-20160816; b=m9qu8ET8G00MD6LNwwNaJPQbP2xLtE/rab3hiKg6/IdELM7FcF/w5tJQNqA0APGzcv RkH8pyJoFCskLdmS1D3tZyn6N4rWWauaUMGCwp2z/whF0nMVYdHvJ2s/rWBxS8Ud9EAS VaRHBjBQRHl67KRrVFDzY2tRtC3ZQhOwyegRlmK33+PnroO9+0XuzXP5lLfEVvAMugEp OpJ2njgLMqWobtzuX1fs24ie70hp6QfMiJ9Hu8QJKsOo0k2wVL2ZGtsXsNDGqDoC0QSB 0aq3A3MYiiRdwhzf5cUfANmByENg3Qxp6I8bmH9D2pTDx7bws6Nj+pr+mDqvEOGfccvw WyaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=Kj+uepnMqntnxxCT41HFqXMstykYSvwecQVA7Hg4Lzo=; b=YMbu00TYPeSIeYUjktiAt7lbdWqgj7BFhr7Z8DJHBhW0LsNH43us8God4yf1uuhdIz aOmUjlP7STp5IpKQ6LWaMFAG8UdYKcMl9pIDHqmhIDtzZS9zxGdHHkh7DRww2/ELH32g uN80K04Yf6uAh3cE6OsSuMx+xTvBdnzsASYvsg8g7ZmOvSBwswRsge4K2iXJQdPIsqUz c1XzmzZ2QcOSxCCO41qkpL749DKeXDF2dw23A6qTc7fRxHa4ZdKJ2nFlIAispiz/JqGt ybzKYgBVcPKOPe9dECqpERff9qd8TxnCrKPqBMjjYvuaxQE1+XjvLNp0qvH5I65nE4Kl YRJw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h33-v6si24478834plh.483.2018.05.08.12.21.25; Tue, 08 May 2018 12:21:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755188AbeEHTUK (ORCPT + 99 others); Tue, 8 May 2018 15:20:10 -0400 Received: from mail.bootlin.com ([62.4.15.54]:35703 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751464AbeEHTUI (ORCPT ); Tue, 8 May 2018 15:20:08 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 19D7D20737; Tue, 8 May 2018 21:20:06 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost (unknown [88.191.26.124]) by mail.bootlin.com (Postfix) with ESMTPSA id DB91220730; Tue, 8 May 2018 21:19:55 +0200 (CEST) Date: Tue, 8 May 2018 21:19:56 +0200 From: Alexandre Belloni To: Giulio Benetti Cc: a.zummo@towertech.it, robh+dt@kernel.org, mark.rutland@arm.com, linux-rtc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/4] rtc: ds1307: add calibration of_ for mt41txx chips. Message-ID: <20180508191956.GP10960@piout.net> References: <20180508145611.49072-1-giulio.benetti@micronovasrl.com> <20180508145611.49072-3-giulio.benetti@micronovasrl.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180508145611.49072-3-giulio.benetti@micronovasrl.com> User-Agent: Mutt/1.9.5 (2018-04-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, There is a sysfs interface for calibration, please use it. this is especially useful since the calibration value probably depend on temperature so it has to be updated dynamically to be really useful. See https://elixir.bootlin.com/linux/v4.16.7/source/Documentation/ABI/testing/sysfs-class-rtc#L68 and https://elixir.bootlin.com/linux/v4.16.7/source/drivers/rtc/interface.c#L999 On 08/05/2018 16:56:10+0200, Giulio Benetti wrote: > m41txx chips can hold a calibration value to get really near to real > tick value. > > Add calibration property(ranging between (-31) and 31), so on every probe > calibration value will be written to rtc. > This is because ic could loose supply due to low battery. > > Signed-off-by: Giulio Benetti > --- > .../devicetree/bindings/rtc/rtc-ds1307.txt | 2 ++ > drivers/rtc/rtc-ds1307.c | 33 +++++++++++++++++++ > 2 files changed, 35 insertions(+) > > diff --git a/Documentation/devicetree/bindings/rtc/rtc-ds1307.txt b/Documentation/devicetree/bindings/rtc/rtc-ds1307.txt > index ce6469c1a516..d3d70a5495c5 100644 > --- a/Documentation/devicetree/bindings/rtc/rtc-ds1307.txt > +++ b/Documentation/devicetree/bindings/rtc/rtc-ds1307.txt > @@ -34,6 +34,8 @@ Optional properties: > - trickle-diode-disable : ds1339, ds1340 and ds 1388 only > Do not use internal trickle charger diode > Should be given if internal trickle charger diode should be disabled > +- calibration: m41t0, m41t00, m41t11 only > + Set calibration value to correct external bias, ranging between (-31) and 31. > > Example: > rtc1: ds1339@68 { > diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c > index 0ab0c166da83..9cda52589c0f 100644 > --- a/drivers/rtc/rtc-ds1307.c > +++ b/drivers/rtc/rtc-ds1307.c > @@ -114,6 +114,12 @@ enum ds_type { > # define RX8025_BIT_VDET 0x40 > # define RX8025_BIT_XST 0x20 > > +#define M41TXX_REG_CONTROL 0x07 > +# define M41TXX_BIT_OUT 0x80 > +# define M41TXX_BIT_FT 0x40 > +# define M41TXX_BIT_CALIB_SIGN 0x20 > +# define M41TXX_M_CALIBRATION 0x1f > + > struct ds1307 { > enum ds_type type; > unsigned long flags; > @@ -1397,6 +1403,7 @@ static int ds1307_probe(struct i2c_client *client, > unsigned char regs[8]; > struct ds1307_platform_data *pdata = dev_get_platdata(&client->dev); > u8 trickle_charger_setup = 0; > + s32 calib; > > ds1307 = devm_kzalloc(&client->dev, sizeof(struct ds1307), GFP_KERNEL); > if (!ds1307) > @@ -1460,6 +1467,32 @@ static int ds1307_probe(struct i2c_client *client, > if (chip->alarm && of_property_read_bool(client->dev.of_node, > "wakeup-source")) > ds1307_can_wakeup_device = true; > + > + /* retrieve calibration value if provided */ > + if (!of_property_read_s32(client->dev.of_node, "calibration", > + &calib)) { > + switch (ds1307->type) { > + case m41t0: > + case m41t00: > + case m41t11: > + { > + /* > + * Set calibration value every power-on since rtc > + * could have shut off(low battery) > + */ > + u8 out_byte = abs(calib) & M41TXX_M_CALIBRATION; > + > + if (calib >= 0) > + out_byte |= M41TXX_BIT_CALIB_SIGN; > + > + regmap_write(ds1307->regmap, M41TXX_REG_CONTROL, > + out_byte); > + } > + break; > + default: > + break; > + } > + } > #endif > > switch (ds1307->type) { > -- > 2.17.0 > -- Alexandre Belloni, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com