Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp1000759imc; Mon, 11 Mar 2019 04:23:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqyLNNNBUiEUBpsQ/CZrrpWCrmb4yrEfaHwcsE8jMC2+TdLLki2EDY0Z6MTjd/JPyisb03pl X-Received: by 2002:a17:902:f01:: with SMTP id 1mr32874674ply.41.1552303439004; Mon, 11 Mar 2019 04:23:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552303438; cv=none; d=google.com; s=arc-20160816; b=Q0UyKu/NU8Oo9eUynv7yYdZ/isP3TpwGc3r2vpcOhOWbz2kEtE5k8kJ8WiiU5UoN4t G+GgvfUOHNODmn/foaFY8OJkcFsQHdrOUZk4DlCT11gUiyulmxKFRbVicC/VzQaCFqJS CrmByApdD81dkgOBQfyeZP1e04opuxS9yQ9ch2yhvYQRVSlA5Yic9HQj1LDqQaz5l0WI D35XaCivO4f0SsmtDOik2nvKgsAgfJEWDA//1r/7anhSvItaS3Oe+NtsQpLhJtGw8IAE ORqibTxZJniSuHzBl3GrQ2rPPCqGNU8Sj3w3jtGLQonEZnFIohJCiH/iY3Rge0gdJx5w l+Gw== 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 :in-reply-to:references:mime-version:dkim-signature; bh=EJcU2Bab04hznGrdFV1DSsCxIpb4sAD6RZmk3PYCkaE=; b=p+txhvq/2hUbwQZ9LWpV5eorBoHg7oQFpwigbW6eoNiYgT6PYq/Zg1QyeuiFSIxabT uBM0ojlFG3jbBpyaRgIenbBxTdhZgA91bQsEDoj6wN0PzwxWAKB3uz3XTCupMn1zeghx Xc+Sc4vYPD2kC4bC4/NYY8KEygH+D1bG4MTjn3myTekwQ7qLmGzKjXyvAB36rC0B23EA DfWs8YfZ00zslBOgJhXc2xdMGfv4hiE0Gi4Q4H6hCB8cmk8GCiuFqS2dSFsnkqdkim2s aJCOOjc9w5wG6qX5oBOxG0BJK15ztiDW2oJH6l0CWv+/zBeo2tByF2CKZlkAJ7rSly9J e7xQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@essensium-com.20150623.gappssmtp.com header.s=20150623 header.b=Hww2FaCD; 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 c24si4716989pgg.534.2019.03.11.04.23.42; Mon, 11 Mar 2019 04:23:58 -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=@essensium-com.20150623.gappssmtp.com header.s=20150623 header.b=Hww2FaCD; 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 S1727477AbfCKLWa (ORCPT + 99 others); Mon, 11 Mar 2019 07:22:30 -0400 Received: from mail-yw1-f65.google.com ([209.85.161.65]:37626 "EHLO mail-yw1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727421AbfCKLW2 (ORCPT ); Mon, 11 Mar 2019 07:22:28 -0400 Received: by mail-yw1-f65.google.com with SMTP id k14so3528185ywe.4 for ; Mon, 11 Mar 2019 04:22:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=essensium-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=EJcU2Bab04hznGrdFV1DSsCxIpb4sAD6RZmk3PYCkaE=; b=Hww2FaCDAoeODwd+DJyT0zRFkn6zQIp7+8WVBujK5ve1F1142fTV4d7CPSXehnBTYg uNK7UT7Qjhfk33FQx5FBvLndQcaFgEfaNr6pHCku8hyLxDGa5xVU9T0ADzUGYyfaSQnf DX1LIcv3foHV0eRhLTt1cWKrHwqJvn/b2dSXk96X0btn0qD2oZ6S0lDMX6sXDHQDUMWO Ff/ABjfcwdb2uncueHYx7+u676OFNC3Y5hor/cLfhe+10SbNNZaZmFdLt8BGYEj4YgCo L0PBNhpiCsuBh8lij3RCOv6hIG2wWlqNT8KeMg2MZzNMZ2Sjlix1c4rDmjqsoex+EmsE 2n2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=EJcU2Bab04hznGrdFV1DSsCxIpb4sAD6RZmk3PYCkaE=; b=geiBu91QCimdlXWzQTeFtnCJRwv9hpBS8WgFEKv7PTNdkSFW7xqLfb2VDRjfLkpz16 X4SeUz1q1hR15s6DUxnlXSN+5DSm5zv9sUtyK7tdhYaM4VYsfrgH2CuzxsYdMSyWtQzZ oRyrYMZHNomBdrJfQ2//QDzC6/UQ4BxMasOZZlLekUVOJ1I1g6ecGnwxphwWggoFi/tr zzl0PGL4eEMlDI3bDpwWKa8588uzt6M3Lzhoxg1nEvdPjUaT2W856nzqNfHX52n+bJ7U sr88RssQwzQ6vjS2fC1KLzHI1oPqbdZkvztegXsjVo6wSyElOmijs5k3Uwnq1wN4JAfR 5EOg== X-Gm-Message-State: APjAAAV/A8XaYgcPaLGtFYFiHCMaCaCbDlws9feDEuX9tVixRUcyDtcN yu4Ei/NEUdUkH6KYhbu8zSeBXs4I9Y8u6JySIVMv5A== X-Received: by 2002:a25:3ca:: with SMTP id 193mr26437201ybd.498.1552303347474; Mon, 11 Mar 2019 04:22:27 -0700 (PDT) MIME-Version: 1.0 References: <20190306111208.7454-1-patrick.havelange@essensium.com> <20190306111208.7454-6-patrick.havelange@essensium.com> <20190307113147.GA7851@icarus> In-Reply-To: <20190307113147.GA7851@icarus> From: Patrick Havelange Date: Mon, 11 Mar 2019 12:22:16 +0100 Message-ID: Subject: Re: [PATCH v2 5/7] counter: add FlexTimer Module Quadrature decoder counter driver To: William Breathitt Gray Cc: Rob Herring , Mark Rutland , Shawn Guo , Li Yang , Daniel Lezcano , Thomas Gleixner , Thierry Reding , Esben Haabendal , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pwm@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Jonathan Cameron 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 Thu, Mar 7, 2019 at 12:32 PM William Breathitt Gray wrote: > > +/* > > + * take mutex > > + * call ftm_clear_write_protection > > + * update settings > > + * call ftm_set_write_protection > > + * release mutex > > + */ > > Jonathan mentioned it before in the previous review, and I think I agree > too, that this comment block is superfluous: the context of this code is > simple enough that the function call order is naturally obvious (i.e. > write protection must be cleared before settings are modified). > > The only important thing to mention here is that the mutex must be held > before the write protection state is modified so a comment along the > following lines should suffice: > > /* hold mutex before modifying write protection state */ I think that keeping the more verbose comments is better. You directly see what operations are needed, and is a good reminder, especially if you are not familiar with the driver. I'll use your comment on the next version if you insist (see below for why new versoion). > > +static void ftm_quaddec_disable(struct ftm_quaddec *ftm) > > +{ > > + ftm_write(ftm, FTM_MODE, 0); > > +} > > The ftm_quaddec_disable function is only used for cleanup when the > driver is being removed. Is disabling the FTM counter on removal > actually something we need to do? It might provide some power-saving, so I would keep that function. > > While it's true that the register will keep updating, since the driver > is no longer loaded, we don't care about that register value. Once we > take control of the hardware again (by reloading our driver or via a new > one), we reinitialize the counter and set the count value back to 0 > anyway -- so whatever value the register had no longer matters. > Indeed the previous values at start do not matter. It's there just to shut down the device properly. This discussion made me verify again the specs and in its current form the disable doesn't even work at all : - That register should be written with write protection disabled (duh!) - It doesn't even stop the FTM from running, the clock must be disabled for that. So I'll probably provide a fix for that (in some days/weeks). > > + > > +enum ftm_quaddec_count_function { > > + FTM_QUADDEC_COUNT_ENCODER_MODE_1, > > +}; > > The FlexTimer Module supports more than just a quadrature counter mode > doesn't it? > > We should keep this initial patch simple since we are still introducing > the Counter subsystem, but it'll be nice to add support in the future > for the other counter modes such as single-edge capture. yes it provides more features, those are in a backlog ;). I would prefer if this simple version(I mean, with the disable/shutdown fixed) of the driver could be merged already before extending support. > > > + > > +static struct counter_signal ftm_quaddec_signals[] = { > > + { > > + .id = 0, > > + .name = "Channel 1 Quadrature A" > > + }, > > + { > > + .id = 1, > > + .name = "Channel 1 Quadrature B" > > + } > > +}; > > If possible, these names should match the FTM datasheet naming > convention. The reason is to make it easier for users to match the > input signals described in the datasheet with the Signal data provided > by the Generic Counter interface. > > I think the FTM datasheet describes these signals as "Phase A" and > "Phase B", so perhaps "Channel 1 Phase A" and "Channel 1 Phase B" may be > more appropriate names in this case. I'll verify those, > > +static int ftm_quaddec_remove(struct platform_device *pdev) > > +{ > > + struct ftm_quaddec *ftm = platform_get_drvdata(pdev); > > + > > + counter_unregister(&ftm->counter); > > + > > + ftm_quaddec_disable(ftm); > > + > > + return 0; > > +} > > If the ftm_quaddec_disable is not necessary, then we can eliminate the > ftm_quaddec_remove function as well by replacing the counter_register > call with a devm_counter_register call. yes, but as stated before, I would keep it for potential energy saving. Thanks for your feedback :)