From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5ECBBC433F5 for ; Tue, 22 Mar 2022 20:38:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229614AbiCVUkS (ORCPT ); Tue, 22 Mar 2022 16:40:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234154AbiCVUkR (ORCPT ); Tue, 22 Mar 2022 16:40:17 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A6DA69293; Tue, 22 Mar 2022 13:38:49 -0700 (PDT) Received: from fraeml705-chm.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4KNNYv3qvVz687Yd; Wed, 23 Mar 2022 04:36:35 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by fraeml705-chm.china.huawei.com (10.206.15.54) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2375.24; Tue, 22 Mar 2022 21:38:47 +0100 Received: from localhost (10.47.75.191) by lhreml710-chm.china.huawei.com (10.201.108.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Tue, 22 Mar 2022 20:38:46 +0000 Date: Tue, 22 Mar 2022 20:38:44 +0000 From: Jonathan Cameron To: Stephen Boyd CC: Jonathan Cameron , Lars-Peter Clausen , , , Gwendal Grignou Subject: Re: [PATCH] iio:proximity:sx9324: Fix hardware gain read/write Message-ID: <20220322203844.0000466f@Huawei.com> In-Reply-To: References: <20220318204808.3404542-1-swboyd@chromium.org> <20220319152641.49d8b3e1@jic23-huawei> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.29; i686-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.47.75.191] X-ClientProxiedBy: lhreml742-chm.china.huawei.com (10.201.108.192) To lhreml710-chm.china.huawei.com (10.201.108.61) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org On Mon, 21 Mar 2022 19:36:33 +0100 Stephen Boyd wrote: > Quoting Jonathan Cameron (2022-03-19 08:26:41) > > On Fri, 18 Mar 2022 13:48:08 -0700 > > Stephen Boyd wrote: > > > > Hi Stephen, > > > > > > > There are four possible gain values according to sx9324_gain_vals[]: 1, > > > 2, 4, and 8. When writing and reading the register the values are off by > > > one. > > > The bits should be set according to this equation: > > > > > > ilog2() + 1 > > > > > > so that a gain of 8 is 0x3 in the register field and a gain of 4 is 0x2 > > > in the register field, etc. Fix up the functions. > > > > So is the 0 value reserved? I can't find an sx9324 datasheet but he > > 9320 is online and that seems to be the case there. If so please state > > that in this description as well. > > Yes 0 is reserved. The top of this driver's C file has the datasheet > link[1] Ah. Thanks ;) > > > > > > > > > Fixes: 4c18a890dff8 ("iio:proximity:sx9324: Add SX9324 support") > > > Cc: Gwendal Grignou > > > Signed-off-by: Stephen Boyd > > > --- > > > drivers/iio/proximity/sx9324.c | 7 +++++-- > > > 1 file changed, 5 insertions(+), 2 deletions(-) > > > > > > diff --git a/drivers/iio/proximity/sx9324.c b/drivers/iio/proximity/sx9324.c > > > index 0d9bbbb50cb4..a3c8e02f5a56 100644 > > > --- a/drivers/iio/proximity/sx9324.c > > > +++ b/drivers/iio/proximity/sx9324.c > > > @@ -379,7 +379,10 @@ static int sx9324_read_gain(struct sx_common_data *data, > > > if (ret) > > > return ret; > > > > > > - *val = 1 << FIELD_GET(SX9324_REG_PROX_CTRL0_GAIN_MASK, regval); > > > + regval = FIELD_GET(SX9324_REG_PROX_CTRL0_GAIN_MASK, regval); > > > + if (regval) > > > > If 0 is reserved then I'd return and error code here to indicate > > we don't know what the gain is rather than carrying on regardless. > > Or is this going to cause problems as it will be an ABI change (error > > return possible when it wasn't really before)? > > > > That sounds OK to me. The driver is only being introduced now so we can > still fix it to reject a gain of 0. Unless 0 should mean "off", i.e. > hardware gain of 1? No. I don't think we want to add that sort of fiddly definition. So error is the way to go - I'd forgotten we only just introduced this so no ABI breakage risk. Jonathan > > [1] https://edit.wpgdadawant.com/uploads/news_file/program/2019/30184/tech_files/program_30184_suggest_other_file.pdf