Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp487993imm; Wed, 18 Jul 2018 05:50:09 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfpEZXxqxZmFsrY7X1wkaXi8pyWoWkQJ5MSSC7+um67s/bkr2xt4AP4ibrL/w3Ez54K7W+H X-Received: by 2002:a65:5086:: with SMTP id r6-v6mr5578204pgp.375.1531918209817; Wed, 18 Jul 2018 05:50:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531918209; cv=none; d=google.com; s=arc-20160816; b=dRdyw0o//ZhZuAcCqXGzqBkYI0PPT/0w0MlFbP/ZVy5K3lhD2ZXNqIHM/P0haDRpMm IS7D0zxTvCTmnF/f4RwGD/TngTdxUDLp0I06soiqdZYO25JIBLPf3Jt/WGGXAU1qhnR0 qHP4f6GHkla0fz53BIZn5inS/7tJCxpqMRRgQgxG9QJfKqrOXP9D23pTRG41frjcpdYO B7+P2yR1Xj2I+qrNEi71LEhBMIZUbsWErDiW3RTvhonqNsQvqPVjr6X5/Y7pvXcf6Eog RSDSC5kLyBjbjaFOCUvlZqAbFBL+e9h80YF5uvFCVpRAnYl5TpjtXaPS7P/KorDaBD0Q m4Ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=ORGVMhNOGvEGIRzn92jpA1tCbA7lkMVuBvcCCkuWZVQ=; b=rOK2yR2vGao/liM50/YXQrRVVYzSo10QcIO2Ha5ltgYCLTYzOElwDz1WiPPpNtWuOo as39e/BgjD66a+iEJpazc6QyX39B9esgfp3uLfKlZEU6JY1a+NFOrMdN8jKMacwh4JiO adOFv7zmjTV6i4cWXgkWCe3P24BNrqGUhz33B+JDJreJDj4ldAXbABzlVlDFkKvbetWJ eK35BhOHZKjYENxFfysOEZJoTSd5hBV5Xjs6Xi1S4fKg9CO1A+bPblEUeFQdCF2/6X5S vRajWb/D4b000yjVcPGwtBYd/3ThZseJeOvGvl17dtXTov15flmKcAbHDKoFuYBAY2jZ dWkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="cszzm5/W"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h65-v6si3228841pfg.197.2018.07.18.05.49.55; Wed, 18 Jul 2018 05:50:09 -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=pass header.i=@gmail.com header.s=20161025 header.b="cszzm5/W"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731398AbeGRNZo (ORCPT + 99 others); Wed, 18 Jul 2018 09:25:44 -0400 Received: from mail-vk0-f66.google.com ([209.85.213.66]:33421 "EHLO mail-vk0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729324AbeGRNZn (ORCPT ); Wed, 18 Jul 2018 09:25:43 -0400 Received: by mail-vk0-f66.google.com with SMTP id y70-v6so2412488vkc.0; Wed, 18 Jul 2018 05:47:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=ORGVMhNOGvEGIRzn92jpA1tCbA7lkMVuBvcCCkuWZVQ=; b=cszzm5/WgPY//Y3PL5PlrauKOYLhBbfDRdyQwVE+mHXhUIknpf1VLT5uFTjWJJNeum sQzHDcKEIhwqAmCkMKaHhJnGW4yLAU5WtzpTMXect2+7puCNostEfwz+hdASOjb1x5mz QsZ4SwRcc45kWSY9UNjCuhxvKmAYJGAdWQgxaMuVBFNb9SxkRG4+xxWMppzH31z8bHQe 1qmv0tq3hKdmMVNt4dFzHfB4J3Ntb5h8GjtellZ1HJz9i0XbIO1N+n2qMUQBq38lQ1KK aDfTxiHekUHT2/ftQdaotxm3YuIFnYUrGMGJAIW/PPIW4QzRaxeCmAM/tFetHESH+yuV aP0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=ORGVMhNOGvEGIRzn92jpA1tCbA7lkMVuBvcCCkuWZVQ=; b=jz3m+kDx1jfmVy+gsB2m/IBWzkOehblx8ppu1TWSiBe3ng3ZFCAU14mhxCbSsCa+iZ nwORoAFuuVLNDkNg8/qNO2U+bOTZ4n3c2pSDKnke/TYfYY9JNGkodhbysBZDlhie4E+U eFjxtriiyVz/ZdwHxoJ6Fqw4Tv2eBaVORunTzxWnqgtjHR1VrBEkfP5OgqLfeYz9hK8s Y9V8HPv70gP3qVCIpCg6ol4phM32VPTdi3sEpthveXENgqar4K95xuGL3hR0hPbYX8CR tkOVIJzHK9zVPE0AnrnGrSDoawFz0B0g8HCtvER69BoS6AGC5lcS49XZuVN97Z7olMt6 nmwA== X-Gm-Message-State: AOUpUlG01Cm8oriiWt4jQvNodY7ZOPM/2C6UoC1+Syj5oShE1GWBoJLp Ymkj932Z08mks6qmIODcsZJ3rmBFpy3U70fL+d4D2g== X-Received: by 2002:a1f:50c:: with SMTP id 12-v6mr3254739vkf.26.1531918076189; Wed, 18 Jul 2018 05:47:56 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a67:2149:0:0:0:0:0 with HTTP; Wed, 18 Jul 2018 05:47:54 -0700 (PDT) In-Reply-To: <20180718094006.105675-3-giulio.benetti@micronovasrl.com> References: <20180718094006.105675-1-giulio.benetti@micronovasrl.com> <20180718094006.105675-3-giulio.benetti@micronovasrl.com> From: Andy Shevchenko Date: Wed, 18 Jul 2018 15:47:54 +0300 Message-ID: Subject: Re: [PATCH v9 4/4] rtc: ds1307: add frequency_test_enable sysfs attribute to check tick on m41txx To: Giulio Benetti Cc: Alexandre Belloni , Alessandro Zummo , "open list:REAL TIME CLOCK (RTC) SUBSYSTEM" , open list Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 18, 2018 at 12:40 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. > +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); > + bool freq_test_en = 0; First of all, initialization of boolean using int is not very best style. Second, this is not needed. > + int ret; > + > + ret = kstrtobool(buf, &freq_test_en); > + if (ret == -EINVAL) { What kind of other error code you may expect and why they are not considered as no error? > + dev_err(dev, "Failed to store RTC Frequency Test attribute\n"); > + return ret; > + } > + > + regmap_update_bits(ds1307->regmap, M41TXX_REG_CONTROL, M41TXX_BIT_FT, > + freq_test_en ? M41TXX_BIT_FT : 0); > + > + return count; > +} > + > +static ssize_t frequency_test_enable_show(struct device *dev, > + struct device_attribute *attr, > + char *buf) > +{ > + struct ds1307 *ds1307 = dev_get_drvdata(dev); > + unsigned int ctrl_reg; > + > + regmap_read(ds1307->regmap, M41TXX_REG_CONTROL, &ctrl_reg); > + > + if (ctrl_reg & M41TXX_BIT_FT) > + return scnprintf(buf, PAGE_SIZE, "on\n"); > + else > + return scnprintf(buf, PAGE_SIZE, "off\n"); Entire condition might be one line. > +} > + > +static int ds1307_add_frequency_test(struct ds1307 *ds1307) > +{ > + int err = 0; Redundant assignment. See below. > + > + switch (ds1307->type) { > + case m41t0: > + case m41t00: > + case m41t11: > + /* Export sysfs entries */ > + err = sysfs_create_group(&(ds1307->dev)->kobj, > + &rtc_freq_test_attr_group); > + if (err) { > + dev_err(ds1307->dev, > + "Failed to create sysfs group: %d\n", > + err); > + return err; > + } > + > + err = devm_add_action_or_reset(ds1307->dev, > + rtc_calib_remove_sysfs_group, > + ds1307->dev); > + if (err) { > + dev_err(ds1307->dev, > + "Failed to add sysfs cleanup action: %d\n", > + err); > + sysfs_remove_group(&(ds1307->dev)->kobj, > + &rtc_freq_test_attr_group); > + return err; > + } > + break; > + default: > + break; > + } > + > + return err; return 0; -- With Best Regards, Andy Shevchenko