Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2311461pxp; Mon, 21 Mar 2022 16:36:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQDDbtLp601zUwjUmoyDqkGdfnT/JglLgHDJ5MYouQ2fJIRz9JmuexPVylLF6abaF6+aqS X-Received: by 2002:a63:4d18:0:b0:374:87b6:b6c3 with SMTP id a24-20020a634d18000000b0037487b6b6c3mr19730586pgb.405.1647905807197; Mon, 21 Mar 2022 16:36:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647905807; cv=none; d=google.com; s=arc-20160816; b=xZa8nCeQqJLzOAY+RbJ0jzIpwOVXkdb8gwX+wgs9HIXZUcU/S9nubtufvL0xZ43RLH TlpaBKAVQ7/Qc3TJYts8+yFHbxpSOV3D4s3JGBHSTffL9Of7pspMHvwOCPhRMJCDMPGw YARRAkbNoPCHlF7TqqGN+TLs2EZk1QVz+ZSmx68bJO7xwnZKyAu1WG5sC1tUiTfUxMvV YyF8zI5F7pZdlTzLGnhhW5EZiZ/Yh+l0iQxe8L4Kd1zz3mjHmxNAf3OmkB72KNyQ7cmi lI7NeGmE1NFVX3aK3oVosu6nlovxsk8ia3LzyKD0/LG5qKbi4vA9uRHefKfr4UaBaYTO SLlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:user-agent:from :references:in-reply-to:mime-version:dkim-signature; bh=yXYEBuW6VaDVgClKY3HKdDJSY8KyrlZEOVA56VtcWa4=; b=hThuVabSwfz1UBfBqWOU8lYcFrHmEshF/1462jqkEvpap5Qbpvbu0bTEG86pXKNTdd e4ez35UuX/OEGLNipc8Ee8d3VMibmqlz68mMylMEWlT+6gzftpo47y+QlYf0sI3/4zh0 tchB+VH3T0rh1ngKyx9rXTMbMkB1R0qltAk3jpqgn8p4TVsV+8y/aEDZx21H3e1QWOmh WveFEhsUnyvQvqi5Xfus5hn42yOfZCou2P71li71EXa717amybmO/uFsPcafEv/NJo14 Fu+i5azt7i4xgDuLjKMlpCTCbghHWGAEFuT7UkUx7dOvu1N1gKK7jBkNhO1UlByh5QFy P/cQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=AMClZKU3; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id u24-20020a17090ae01800b001c70d2622bbsi590494pjy.109.2022.03.21.16.36.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 16:36:47 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=AMClZKU3; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A30B744EA0F; Mon, 21 Mar 2022 15:36:34 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352227AbiCUSiC (ORCPT + 99 others); Mon, 21 Mar 2022 14:38:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345165AbiCUSiA (ORCPT ); Mon, 21 Mar 2022 14:38:00 -0400 Received: from mail-oo1-xc2d.google.com (mail-oo1-xc2d.google.com [IPv6:2607:f8b0:4864:20::c2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 381117CDEE for ; Mon, 21 Mar 2022 11:36:35 -0700 (PDT) Received: by mail-oo1-xc2d.google.com with SMTP id s203-20020a4a3bd4000000b003191c2dcbe8so20163951oos.9 for ; Mon, 21 Mar 2022 11:36:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:in-reply-to:references:from:user-agent:date:message-id :subject:to:cc; bh=yXYEBuW6VaDVgClKY3HKdDJSY8KyrlZEOVA56VtcWa4=; b=AMClZKU3SKzDzuaJpTabi6xrGsDRYAM73Jppk48lHzd5Ma/lHr8lXJh6zbwtJujY1g GEvaGdwRC5L+KCqVFgYYzHdGxuSuCTJs4B9LawELpTXpNAytnHhivXUlbApZ/KBvnmqP eDlEeAC9gzGFA7ALWMLyd7iG/Fe+t/5EV/AeA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:in-reply-to:references:from :user-agent:date:message-id:subject:to:cc; bh=yXYEBuW6VaDVgClKY3HKdDJSY8KyrlZEOVA56VtcWa4=; b=4D7Vdy34c5pmeCrB4yCCRDncftC/aBIWfuVMPWuMLenG/ga9yZrrfK4P/HBRFmxxC1 T/Dz0RvZ+aCZmD0ZPiq7pT2pZnDb75DC/ApX/DwVUoePWKtm48xFHCrCvHtrmDWWlR+f HdJOGl0k3CSAiFyx/F2sPkgG8bf/XDPdcNlwbIcLTdw8Ojha13MBYvfM8geIIC5JsWFn bEe1bXNs/U+2KXF/zw1gufyfOn11cXSHIt21XBK+BGb62z3geGZ1eeX+QtdsJMnPXYW+ hCLoRcW998l6JKzGiHhM/dBFDOtKV5MgXNwW0P0z58PZwSbnMbbJGZBX/em5p6Amxbp0 C7nw== X-Gm-Message-State: AOAM533y0teMJrD5Hx6sBLZq/rQrXUkDJBGObyfz9hS/19WLGEqLgrUi DIaVzC1NrCc3RY0uI9bvlS86j/NrpPQr5wr2vn1m1A== X-Received: by 2002:a05:6870:c0cb:b0:da:2bcc:aa09 with SMTP id e11-20020a056870c0cb00b000da2bccaa09mr194320oad.63.1647887794519; Mon, 21 Mar 2022 11:36:34 -0700 (PDT) Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Mon, 21 Mar 2022 19:36:33 +0100 MIME-Version: 1.0 In-Reply-To: <20220319152641.49d8b3e1@jic23-huawei> References: <20220318204808.3404542-1-swboyd@chromium.org> <20220319152641.49d8b3e1@jic23-huawei> From: Stephen Boyd User-Agent: alot/0.10 Date: Mon, 21 Mar 2022 19:36:33 +0100 Message-ID: Subject: Re: [PATCH] iio:proximity:sx9324: Fix hardware gain read/write To: Jonathan Cameron Cc: Lars-Peter Clausen , linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Gwendal Grignou Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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] > > > > > 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? [1] https://edit.wpgdadawant.com/uploads/news_file/program/2019/30184/tech_files/program_30184_suggest_other_file.pdf