Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2620525pxb; Sun, 17 Oct 2021 20:44:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzAFqnVtOJXnoIZmCgQmGk6E8h5ZsDo168KvdCDml2H5QnnXf2gKOn/qjQQeomRPov8+uvE X-Received: by 2002:a63:6d43:: with SMTP id i64mr12930592pgc.277.1634528654638; Sun, 17 Oct 2021 20:44:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634528654; cv=none; d=google.com; s=arc-20160816; b=cpSp+7QpZ5zJFvVNHVkJR0Lx3P5KJRmndJU9wleYlNLXVl+7EQIp02j7uqBes/TeRe G0MXpPcD12hLn94zkUXdptafZysOSfA2wtidYt58Bksyekghb9sIgYscXlyKTzJmoaaz nv277QCA4rriorRYyS7os8hnO7x6KSg2ZS+G1h0n3jVql/+MmqemPo/UNPgtJ65+3ayT WN4EKDjNISx+nuRcXFbgrg50kW/n8F+hqAwsiIM/hYZjb+BV2dR+ClBR7WRoCjQi+lhd eR4yBHATjqPiXdLLiw8belFNWj+MMFzqnSkLDbWUwHdOw+fivyO2K0vHNDVJTzu1jZ64 oMUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=VhfS8Gdz/T0De4Yuu4ccyOTFghyYP5ieQqFTki8qWK4=; b=0ARKX2BxDo1SHULB4r791wBt78AP4OFx+kgIeL1QdTuncAuICyA09qSjDoriBUVS09 EWAyPrs8r76Np5rcneDA61c7AqeDtmCELczJyASN2uTG88YgAggoioEZqvkAaWhT5PP7 Oj5I9DbzVM4NkBF65JsNnpjGVj/2TT8dH/CE52hAKW0P/7keeQ4K6yHsR8RK+T9pPTq/ /J2d5wxSDQPvzg13nKh9zpU/KLBlaLODpeasrsW4Od8jCu2BikBFS7GFzzIFAtD9gVrv X7z1QjEKsDzwRtTGyQh53uo0tFGGzEuoJDTns30ONrpAgv3yC0NtLgHEBZNX4fMarm89 3loA== 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w1si2158272plz.130.2021.10.17.20.44.02; Sun, 17 Oct 2021 20:44:14 -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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245399AbhJQLSm (ORCPT + 98 others); Sun, 17 Oct 2021 07:18:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:47030 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237065AbhJQLSl (ORCPT ); Sun, 17 Oct 2021 07:18:41 -0400 Received: from jic23-huawei (cpc108967-cmbg20-2-0-cust86.5-4.cable.virginm.net [81.101.6.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8484360F46; Sun, 17 Oct 2021 11:16:30 +0000 (UTC) Date: Sun, 17 Oct 2021 12:20:43 +0100 From: Jonathan Cameron To: David Lechner Cc: linux-iio@vger.kernel.org, William Breathitt Gray , Robert Nelson , linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/8] counter/ti-eqep: add support for unit timer Message-ID: <20211017122043.731858d3@jic23-huawei> In-Reply-To: <20211017013343.3385923-4-david@lechnology.com> References: <20211017013343.3385923-1-david@lechnology.com> <20211017013343.3385923-4-david@lechnology.com> X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 16 Oct 2021 20:33:38 -0500 David Lechner wrote: > This adds support to the TI eQEP counter driver for the Unit Timer. > The Unit Timer is a device-level extension that provides a timer to be > used for speed calculations. The sysfs interface for the Unit Timer is > new and will be documented in a later commit. It contains a R/W time > attribute for the current time, a R/W period attribute for the timeout > period and a R/W enable attribute to start/stop the timer. It also > implements a timeout event on the chrdev interface that is triggered > each time the period timeout is reached. > > Signed-off-by: David Lechner No comments on the interface in here as leaving that for William / later. A few minor comments on the implementation. Thanks, Jonathan > --- > drivers/counter/ti-eqep.c | 132 ++++++++++++++++++++++++++++++++++- > include/uapi/linux/counter.h | 2 + > 2 files changed, 133 insertions(+), 1 deletion(-) ... > +static int ti_eqep_unit_timer_time_write(struct counter_device *counter, > + u64 value) > +{ > + struct ti_eqep_cnt *priv = counter->priv; > + u32 qutmr; > + > + /* convert nanoseconds to timer ticks */ > + qutmr = value = mul_u64_u32_div(value, priv->sysclkout_rate, NSEC_PER_SEC); Hmm. This pattern strikes me as 'too clever' and also likely to trip up static checkers who will moan about the truncation if they don't understand this trick. I think I'd prefer you just put the answer in an u64 and then do a simple bounds check before casting down. > + if (qutmr != value) > + return -ERANGE; > + > + regmap_write(priv->regmap32, QUTMR, qutmr); > + > + return 0; > +} > + ... > static irqreturn_t ti_eqep_irq_handler(int irq, void *dev_id) > { > struct ti_eqep_cnt *priv = dev_id; > @@ -474,6 +580,8 @@ static irqreturn_t ti_eqep_irq_handler(int irq, void *dev_id) > if (qflg & QFLG_QDC) > counter_push_event(counter, COUNTER_EVENT_DIRECTION_CHANGE, 0); > > + if (qflg & QFLG_UTO) > + counter_push_event(counter, COUNTER_EVENT_TIMEOUT, 0); > > regmap_set_bits(priv->regmap16, QCLR, ~0); > > @@ -500,6 +608,7 @@ static int ti_eqep_probe(struct platform_device *pdev) > { > struct device *dev = &pdev->dev; > struct ti_eqep_cnt *priv; > + struct clk *clk; > void __iomem *base; > int err; > int irq; > @@ -508,6 +617,24 @@ static int ti_eqep_probe(struct platform_device *pdev) > if (!priv) > return -ENOMEM; > > + clk = devm_clk_get(dev, "sysclkout"); > + if (IS_ERR(clk)) { > + if (PTR_ERR(clk) != -EPROBE_DEFER) > + dev_err(dev, "failed to get sysclkout"); dev_err_probe() which both removes most of this boilerplate and stashes the reason for the deferred probe such that it can be checked when debugging. > + return PTR_ERR(clk); > + } No need to enable the clock? > + > + priv->sysclkout_rate = clk_get_rate(clk); > + if (priv->sysclkout_rate == 0) { > + dev_err(dev, "failed to get sysclkout rate"); > + /* prevent divide by zero */ > + priv->sysclkout_rate = 1; > + /* > + * This error is not expected and the driver is mostly usable > + * without clock rate anyway, so don't exit here. > + */ > + } > + > > /**