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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D17F0C6FD1D for ; Fri, 7 Apr 2023 17:15:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=50bTcMBLgQX0FExS0WHjHFpcj2Z+3oefOSzCORbavYQ=; b=bGFHEgvo+2GurR /eNPv8V5nzybHIoctwdcjqcCrB5BeienpwydQR6XE7yyQYbq7TJqgiV9g8c3+iUwa8OiHvK/gBR/X XhR2fxu/8aZu9CjPVJ06QNqlxEBk9DQxKGwGj2vYYovf9r35J2m33p2G81f756q+xCj16n+vEumS1 QYMjpjd7Ys8Dx1KgHkg+nh5OiA78rjl1wiUEJvhzuj8FvnJuibNeOsI1ywOCdTj721K4tFMhwez/O 3nWNcEl1LVTB+AhvY2QbA6mzfzUo1A5gpsPCHNw2ECQQfIhZn6Eje9KhKJBNI1WLLR5kdQn/xTtaN DmvOZ94SdEsGU1XUIzew==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pkpfM-00AmsE-0F; Fri, 07 Apr 2023 17:14:24 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pkpfJ-00Amrj-0M; Fri, 07 Apr 2023 17:14:22 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E80A064111; Fri, 7 Apr 2023 17:14:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B40FC433EF; Fri, 7 Apr 2023 17:14:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680887659; bh=mTjUkJHoStDJ71hbzUhqyq+k2a+V8FszEAxAcLGiYWM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=aSGMFG98DXYw1cTVW5PzUBQ0l55Y85Qgsiay2RUWlJehbqwgVynC0iwEp/6qvTY8+ KAGGQoffpOVP23UE8Y7GcKbHd8cche03jj118059pctdckzCtY+ygaWb/B8qTRdh5a PSY5x5S/dW16H4g9qL57UdojQXRjjNTx5tqrRmqBEMo53aG6m1DqnZYr6b4Fe+jjez b83olozb9+YdaqqwiyIShCzPHQN2bK3RC+DbHAi05/rW6gvfq5vJ+2eALhllSUBlH7 FoGbR05ust3wg2sfeuL7GBKk4IGTLi4OfWQGPgcAsoNsgIVxtlSZbnf8nr4EwyQsoR golPKZe7UYtKw== Date: Fri, 7 Apr 2023 18:29:34 +0100 From: Jonathan Cameron To: ChiaEn Wu Cc: , , , , , , , , Subject: Re: [PATCH v2] iio: adc: mt6370: Fix ibus and ibat scaling value of some specific vendor ID chips Message-ID: <20230407182934.271cbfe4@jic23-huawei> In-Reply-To: <1680750531-29365-1-git-send-email-chiaen_wu@richtek.com> References: <1680750531-29365-1-git-send-email-chiaen_wu@richtek.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.37; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230407_101421_243925_046B456E X-CRM114-Status: GOOD ( 29.54 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, 6 Apr 2023 11:08:51 +0800 ChiaEn Wu wrote: > The scale value of ibus and ibat on the datasheet is incorrect due to the > customer report after the experimentation with some specific vendor ID > chips. > > Signed-off-by: ChiaEn Wu Hi, Please give a fixes tag to aid backporting to right stable branches. A minor formatting suggestion inline. Otherwise looks fine to me. Thanks, Jonathan > --- > v2: > - Move 'get_vendor_info' after iio_priv allocation done > - For the special case, bypass indent, make it out-of-line > - For a simple return, add a blank line > - Drop else > --- > drivers/iio/adc/mt6370-adc.c | 45 ++++++++++++++++++++++++++++++++++++++++++-- > 1 file changed, 43 insertions(+), 2 deletions(-) > > diff --git a/drivers/iio/adc/mt6370-adc.c b/drivers/iio/adc/mt6370-adc.c > index bc62e5a..ae5cdff 100644 > --- a/drivers/iio/adc/mt6370-adc.c > +++ b/drivers/iio/adc/mt6370-adc.c > @@ -19,6 +19,7 @@ > > #include > > +#define MT6370_REG_DEV_INFO 0x100 > #define MT6370_REG_CHG_CTRL3 0x113 > #define MT6370_REG_CHG_CTRL7 0x117 > #define MT6370_REG_CHG_ADC 0x121 > @@ -27,6 +28,7 @@ > #define MT6370_ADC_START_MASK BIT(0) > #define MT6370_ADC_IN_SEL_MASK GENMASK(7, 4) > #define MT6370_AICR_ICHG_MASK GENMASK(7, 2) > +#define MT6370_VENID_MASK GENMASK(7, 4) > > #define MT6370_AICR_100_mA 0x0 > #define MT6370_AICR_150_mA 0x1 > @@ -47,6 +49,10 @@ > #define ADC_CONV_TIME_MS 35 > #define ADC_CONV_POLLING_TIME_US 1000 > > +#define MT6370_VID_RT5081 0x8 > +#define MT6370_VID_RT5081A 0xA > +#define MT6370_VID_MT6370 0xE > + > struct mt6370_adc_data { > struct device *dev; > struct regmap *regmap; > @@ -55,6 +61,7 @@ struct mt6370_adc_data { > * from being read at the same time. > */ > struct mutex adc_lock; > + unsigned int vid; > }; > > static int mt6370_adc_read_channel(struct mt6370_adc_data *priv, int chan, > @@ -98,6 +105,22 @@ static int mt6370_adc_read_channel(struct mt6370_adc_data *priv, int chan, > return ret; > } > > +static int mt6370_adc_get_ibus_scale(struct mt6370_adc_data *priv) > +{ > + if (priv->vid == MT6370_VID_RT5081 || priv->vid == MT6370_VID_RT5081A || priv->vid == MT6370_VID_MT6370) > + return 3350; > + > + return 3875; > +} > + > +static int mt6370_adc_get_ibat_scale(struct mt6370_adc_data *priv) > +{ > + if (priv->vid == MT6370_VID_RT5081 || priv->vid == MT6370_VID_RT5081A || priv->vid == MT6370_VID_MT6370) Line too long. You could wrap it, but perhaps even better to just make this a switch statement as that will be easier to enhance if we have more cases in future without a lot of churn. switch (priv->vid) { case MT6370_VID_RT5081: case MT6370_VID_RT5081A: case MT6370_VID_RT6370: return 2680; default: return 3870; } Same for the other similar case above. > + return 2680; > + > + return 3870; > +} > + > static int mt6370_adc_read_scale(struct mt6370_adc_data *priv, > int chan, int *val1, int *val2) > { > @@ -123,7 +146,7 @@ static int mt6370_adc_read_scale(struct mt6370_adc_data *priv, > case MT6370_AICR_250_mA: > case MT6370_AICR_300_mA: > case MT6370_AICR_350_mA: > - *val1 = 3350; > + *val1 = mt6370_adc_get_ibus_scale(priv); > break; > default: > *val1 = 5000; > @@ -150,7 +173,7 @@ static int mt6370_adc_read_scale(struct mt6370_adc_data *priv, > case MT6370_ICHG_600_mA: > case MT6370_ICHG_700_mA: > case MT6370_ICHG_800_mA: > - *val1 = 2680; > + *val1 = mt6370_adc_get_ibat_scale(priv); > break; > default: > *val1 = 5000; > @@ -251,6 +274,20 @@ static const struct iio_chan_spec mt6370_adc_channels[] = { > MT6370_ADC_CHAN(TEMP_JC, IIO_TEMP, 12, BIT(IIO_CHAN_INFO_OFFSET)), > }; > > +static int mt6370_get_vendor_info(struct mt6370_adc_data *priv) > +{ > + unsigned int dev_info; > + int ret; > + > + ret = regmap_read(priv->regmap, MT6370_REG_DEV_INFO, &dev_info); > + if (ret) > + return ret; > + > + priv->vid = FIELD_GET(MT6370_VENID_MASK, dev_info); > + > + return 0; > +} > + > static int mt6370_adc_probe(struct platform_device *pdev) > { > struct device *dev = &pdev->dev; > @@ -272,6 +309,10 @@ static int mt6370_adc_probe(struct platform_device *pdev) > priv->regmap = regmap; > mutex_init(&priv->adc_lock); > > + ret = mt6370_get_vendor_info(priv); > + if (ret) > + return dev_err_probe(dev, ret, "Failed to get vid\n"); > + > ret = regmap_write(priv->regmap, MT6370_REG_CHG_ADC, 0); > if (ret) > return dev_err_probe(dev, ret, "Failed to reset ADC\n"); _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel