From nobody Fri Sep 20 20:36:27 2024 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 CCF0AC7619A for ; Thu, 6 Apr 2023 03:09:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234908AbjDFDJc (ORCPT ); Wed, 5 Apr 2023 23:09:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234597AbjDFDJ3 (ORCPT ); Wed, 5 Apr 2023 23:09:29 -0400 Received: from mg.richtek.com (mg.richtek.com [220.130.44.152]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 39760198; Wed, 5 Apr 2023 20:09:25 -0700 (PDT) X-MailGates: (flag:4,DYNAMIC,BADHELO,RELAY,NOHOST:PASS)(compute_score:DE LIVER,40,3) Received: from 192.168.10.46 by mg.richtek.com with MailGates ESMTP Server V5.0(9460:0:AUTH_RELAY) (envelope-from ); Thu, 06 Apr 2023 11:08:56 +0800 (CST) Received: from ex4.rt.l (192.168.10.47) by ex3.rt.l (192.168.10.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.25; Thu, 6 Apr 2023 11:08:55 +0800 Received: from linuxcarl2.richtek.com (192.168.10.154) by ex4.rt.l (192.168.10.45) with Microsoft SMTP Server id 15.2.1118.25 via Frontend Transport; Thu, 6 Apr 2023 11:08:55 +0800 From: ChiaEn Wu To: , , , CC: , , , , , , ChiaEn Wu Subject: [PATCH v2] iio: adc: mt6370: Fix ibus and ibat scaling value of some specific vendor ID chips Date: Thu, 6 Apr 2023 11:08:51 +0800 Message-ID: <1680750531-29365-1-git-send-email-chiaen_wu@richtek.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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 @@ =20 #include =20 +#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) =20 #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 =20 +#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; }; =20 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_da= ta *priv, int chan, return ret; } =20 +static int mt6370_adc_get_ibus_scale(struct mt6370_adc_data *priv) +{ + if (priv->vid =3D=3D MT6370_VID_RT5081 || priv->vid =3D=3D MT6370_VID_RT= 5081A || priv->vid =3D=3D MT6370_VID_MT6370) + return 3350; + + return 3875; +} + +static int mt6370_adc_get_ibat_scale(struct mt6370_adc_data *priv) +{ + if (priv->vid =3D=3D MT6370_VID_RT5081 || priv->vid =3D=3D MT6370_VID_RT= 5081A || priv->vid =3D=3D MT6370_VID_MT6370) + 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 =3D 3350; + *val1 =3D mt6370_adc_get_ibus_scale(priv); break; default: *val1 =3D 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 =3D 2680; + *val1 =3D mt6370_adc_get_ibat_scale(priv); break; default: *val1 =3D 5000; @@ -251,6 +274,20 @@ static const struct iio_chan_spec mt6370_adc_channels[= ] =3D { MT6370_ADC_CHAN(TEMP_JC, IIO_TEMP, 12, BIT(IIO_CHAN_INFO_OFFSET)), }; =20 +static int mt6370_get_vendor_info(struct mt6370_adc_data *priv) +{ + unsigned int dev_info; + int ret; + + ret =3D regmap_read(priv->regmap, MT6370_REG_DEV_INFO, &dev_info); + if (ret) + return ret; + + priv->vid =3D FIELD_GET(MT6370_VENID_MASK, dev_info); + + return 0; +} + static int mt6370_adc_probe(struct platform_device *pdev) { struct device *dev =3D &pdev->dev; @@ -272,6 +309,10 @@ static int mt6370_adc_probe(struct platform_device *pd= ev) priv->regmap =3D regmap; mutex_init(&priv->adc_lock); =20 + ret =3D mt6370_get_vendor_info(priv); + if (ret) + return dev_err_probe(dev, ret, "Failed to get vid\n"); + ret =3D regmap_write(priv->regmap, MT6370_REG_CHG_ADC, 0); if (ret) return dev_err_probe(dev, ret, "Failed to reset ADC\n"); --=20 2.7.4