Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2503042imm; Wed, 16 May 2018 14:02:45 -0700 (PDT) X-Google-Smtp-Source: AB8JxZob1TuSnawrIQxCF84taAq+m1aXbpF8LLUqTni2vKO1GKl9luOSzrBuUfmk4WDJUsPvHhQi X-Received: by 2002:a62:1fc8:: with SMTP id l69-v6mr2518004pfj.49.1526504565843; Wed, 16 May 2018 14:02:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526504565; cv=none; d=google.com; s=arc-20160816; b=edOBCsJXxyk2IXMFgvoCq2s69TIXJ3Dq1tPyGZuiH968h6QXdMW2RaouvyxGAfMJD8 EQo4lBWJjTYmlHhy+1yvM0EXqjYvjR1VNXLA6cI5tWmZDLbb8Y9pyu4XL4pYbNZUZcF5 sY13niwMdSQqw3BHKi0IKxZ+rmc89ikJeqkaAVOYRHdbRzt/Z0RnkhzVtSPfptxDmeCV QLmJNGPrr0nzXGpsr5PBNBJMF8y2t+O2pWsZrV9ga/qAWffLwnBVJen0g7GzArlP/MsB D+I3peIvNXQ7RjDx33KAgosXDfQRkUrWlKixUMQCxYUsweZvQUAmQYBAnTIFDd3McBJK M2Eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=URDMyQhtETvIreEnruZxCATrsMLoHLqQLmEDzfkX8Dk=; b=kD9vC4ChPGdO5XKIIdueHytk6bx1QPu0WtLqX6CFmOijwIUTHBKVhqGcigt/TjdKUT QIZIj81zWaD840t4lVwInrTgHDcHigrtqNp4JDpruCjM5iRvTbBGYUhJxXDGDATQCXu9 yvirbayBHlSOKeVsA3J7KKIx1fWWZwg1tkKA9pWr/Xp1UbD2O6TNdASzX0FDQuzRloVF 7TRVweBEOCSjSTf7ufptgt8Db52/kX48fecSH154R/iWPMsol4RJvQPisGt/M1MBe4AL BLa/T1dhARwfNoDWAui+PGuY7Qk9hM/ZHhmb/vXt0aHmpFtkRaiygL7OBu2jSdSNCTTX P8PQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=temperror (no key for signature) header.i=@micronovasrl.com header.s=dkim header.b=Fp1QeLEQ; 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 t5-v6si3405260ply.598.2018.05.16.14.02.31; Wed, 16 May 2018 14:02:45 -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; dkim=temperror (no key for signature) header.i=@micronovasrl.com header.s=dkim header.b=Fp1QeLEQ; 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 S1751370AbeEPVCU (ORCPT + 99 others); Wed, 16 May 2018 17:02:20 -0400 Received: from mail.micronovasrl.com ([212.103.203.10]:54898 "EHLO mail.micronovasrl.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751013AbeEPVCS (ORCPT ); Wed, 16 May 2018 17:02:18 -0400 Received: from mail.micronovasrl.com (mail.micronovasrl.com [127.0.0.1]) by mail.micronovasrl.com (Postfix) with ESMTP id 98F32B00883 for ; Wed, 16 May 2018 23:02:17 +0200 (CEST) Authentication-Results: mail.micronovasrl.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=micronovasrl.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=micronovasrl.com; h=content-transfer-encoding:content-language:content-type :content-type:in-reply-to:mime-version:user-agent:date:date :message-id:from:from:references:to:subject:subject; s=dkim; t= 1526504537; x=1527368538; bh=27EPm2c8oUigJaAGFQTkHINz/hc2oK5igxb K2HEhjrg=; b=Fp1QeLEQjbsrSmwZewtAROw9PzEBuNA0KBjyAE7jhageCVPn+dS /8BJVLBQJ3cClMqeuZ+BT1Z/vbiVoTkKf3orsZUcethIUt8+PKI642Ev9dHF8b4c x0urFigjnKqQoJ/JJnWYRL2LsAQifFu4njow5K7oc+orBavh3OVt0xqc= X-Virus-Scanned: Debian amavisd-new at mail.micronovasrl.com X-Spam-Flag: NO X-Spam-Score: -2.9 X-Spam-Level: X-Spam-Status: No, score=-2.9 tagged_above=-10 required=4.5 tests=[ALL_TRUSTED=-1, BAYES_00=-1.9] autolearn=unavailable autolearn_force=no Received: from mail.micronovasrl.com ([127.0.0.1]) by mail.micronovasrl.com (mail.micronovasrl.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id bMTmCibrSLdW for ; Wed, 16 May 2018 23:02:17 +0200 (CEST) Received: from [192.168.123.79] (unknown [192.168.123.79]) by mail.micronovasrl.com (Postfix) with ESMTPSA id BAF1AB000D8; Wed, 16 May 2018 23:02:15 +0200 (CEST) Subject: Re: [PATCH v5 4/4] rtc: ds1307: add frequency_test_enable sysfs attribute to check tick on m41txx To: Andy Shevchenko Cc: Alessandro Zummo , alexandre.belloni@bootlin.com, Rob Herring , Mark Rutland , linux-rtc@vger.kernel.org, devicetree , Linux Kernel Mailing List References: <20180516103251.74707-1-giulio.benetti@micronovasrl.com> <20180516103251.74707-4-giulio.benetti@micronovasrl.com> From: Giulio Benetti Message-ID: <836407b4-8c51-5efa-8e29-f487bbcb528d@micronovasrl.com> Date: Wed, 16 May 2018 23:02:16 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: it Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Il 16/05/2018 22:22, Andy Shevchenko ha scritto: > On Wed, May 16, 2018 at 1:32 PM, Giulio Benetti > wrote: >> On m41txx you can enable open-drain OUT pin to check if offset is ok. >> Enabling OUT pin with frequency_test_enable attribute, OUT pin will tick >> 512 times faster than 1s tick base. >> >> Enable or Disable FT bit on CONTROL register if freq_test is 1 or 0. >> >> Signed-off-by: Giulio Benetti > >> +static ssize_t frequency_test_enable_store(struct device *dev, >> + struct device_attribute *attr, >> + const char *buf, size_t count) >> +{ >> + struct ds1307 *ds1307 = dev_get_drvdata(dev); >> + unsigned long freq_test = 0; >> + int retval; >> + >> + retval = kstrtoul(buf, 10, &freq_test); >> + if ((retval < 0) || (retval > 1)) { > > kstrtobool() then? Yes, you're right. > >> + dev_err(dev, "Failed to store RTC Frequency Test attribute\n"); > >> + return -EINVAL; > > ...and do not shadow actual error code. Ok > >> + } >> + >> + regmap_update_bits(ds1307->regmap, M41TXX_REG_CONTROL, M41TXX_BIT_FT, >> + freq_test ? M41TXX_BIT_FT : 0); >> + > >> + return retval ? retval : count; > > Does the condition make any sense? You're right, not at all. I changed it into: "return count;" > >> +} > >> +static ssize_t frequency_test_enable_show(struct device *dev, >> + struct device_attribute *attr, >> + char *buf) >> +{ > >> + int freq_test_en = 0; > >> + if (ctrl_reg & M41TXX_BIT_FT) >> + freq_test_en = true; >> + else >> + freq_test_en = false; >> + >> + return sprintf(buf, "%d\n", freq_test_en); > > So, is it boolean or integer? This code makes it confusing a lot. It is a boolean, so now I've updated with this: if (ctrl_reg & M41TXX_BIT_FT) return scnprintf(buf, PAGE_SIZE, "on\n"); else return scnprintf(buf, PAGE_SIZE, "off\n"); > >> +} > Thank you very much for review Giulio Benetti