Skip to content

Commit 00ffdd6

Browse files
ChiaEn Wujic23
authored andcommitted
iio: adc: mt6370: Fix ibus and ibat scaling value of some specific vendor ID chips
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. Fixes: c1404d1 ("iio: adc: mt6370: Add MediaTek MT6370 support") Signed-off-by: ChiaEn Wu <chiaen_wu@richtek.com> Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com> Link: https://lore.kernel.org/r/1681122862-1994-1-git-send-email-chiaen_wu@richtek.com Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 20f291b commit 00ffdd6

1 file changed

Lines changed: 51 additions & 2 deletions

File tree

drivers/iio/adc/mt6370-adc.c

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <dt-bindings/iio/adc/mediatek,mt6370_adc.h>
2121

22+
#define MT6370_REG_DEV_INFO 0x100
2223
#define MT6370_REG_CHG_CTRL3 0x113
2324
#define MT6370_REG_CHG_CTRL7 0x117
2425
#define MT6370_REG_CHG_ADC 0x121
@@ -27,6 +28,7 @@
2728
#define MT6370_ADC_START_MASK BIT(0)
2829
#define MT6370_ADC_IN_SEL_MASK GENMASK(7, 4)
2930
#define MT6370_AICR_ICHG_MASK GENMASK(7, 2)
31+
#define MT6370_VENID_MASK GENMASK(7, 4)
3032

3133
#define MT6370_AICR_100_mA 0x0
3234
#define MT6370_AICR_150_mA 0x1
@@ -47,6 +49,10 @@
4749
#define ADC_CONV_TIME_MS 35
4850
#define ADC_CONV_POLLING_TIME_US 1000
4951

52+
#define MT6370_VID_RT5081 0x8
53+
#define MT6370_VID_RT5081A 0xA
54+
#define MT6370_VID_MT6370 0xE
55+
5056
struct mt6370_adc_data {
5157
struct device *dev;
5258
struct regmap *regmap;
@@ -55,6 +61,7 @@ struct mt6370_adc_data {
5561
* from being read at the same time.
5662
*/
5763
struct mutex adc_lock;
64+
unsigned int vid;
5865
};
5966

6067
static int mt6370_adc_read_channel(struct mt6370_adc_data *priv, int chan,
@@ -98,6 +105,30 @@ static int mt6370_adc_read_channel(struct mt6370_adc_data *priv, int chan,
98105
return ret;
99106
}
100107

108+
static int mt6370_adc_get_ibus_scale(struct mt6370_adc_data *priv)
109+
{
110+
switch (priv->vid) {
111+
case MT6370_VID_RT5081:
112+
case MT6370_VID_RT5081A:
113+
case MT6370_VID_MT6370:
114+
return 3350;
115+
default:
116+
return 3875;
117+
}
118+
}
119+
120+
static int mt6370_adc_get_ibat_scale(struct mt6370_adc_data *priv)
121+
{
122+
switch (priv->vid) {
123+
case MT6370_VID_RT5081:
124+
case MT6370_VID_RT5081A:
125+
case MT6370_VID_MT6370:
126+
return 2680;
127+
default:
128+
return 3870;
129+
}
130+
}
131+
101132
static int mt6370_adc_read_scale(struct mt6370_adc_data *priv,
102133
int chan, int *val1, int *val2)
103134
{
@@ -123,7 +154,7 @@ static int mt6370_adc_read_scale(struct mt6370_adc_data *priv,
123154
case MT6370_AICR_250_mA:
124155
case MT6370_AICR_300_mA:
125156
case MT6370_AICR_350_mA:
126-
*val1 = 3350;
157+
*val1 = mt6370_adc_get_ibus_scale(priv);
127158
break;
128159
default:
129160
*val1 = 5000;
@@ -150,7 +181,7 @@ static int mt6370_adc_read_scale(struct mt6370_adc_data *priv,
150181
case MT6370_ICHG_600_mA:
151182
case MT6370_ICHG_700_mA:
152183
case MT6370_ICHG_800_mA:
153-
*val1 = 2680;
184+
*val1 = mt6370_adc_get_ibat_scale(priv);
154185
break;
155186
default:
156187
*val1 = 5000;
@@ -251,6 +282,20 @@ static const struct iio_chan_spec mt6370_adc_channels[] = {
251282
MT6370_ADC_CHAN(TEMP_JC, IIO_TEMP, 12, BIT(IIO_CHAN_INFO_OFFSET)),
252283
};
253284

285+
static int mt6370_get_vendor_info(struct mt6370_adc_data *priv)
286+
{
287+
unsigned int dev_info;
288+
int ret;
289+
290+
ret = regmap_read(priv->regmap, MT6370_REG_DEV_INFO, &dev_info);
291+
if (ret)
292+
return ret;
293+
294+
priv->vid = FIELD_GET(MT6370_VENID_MASK, dev_info);
295+
296+
return 0;
297+
}
298+
254299
static int mt6370_adc_probe(struct platform_device *pdev)
255300
{
256301
struct device *dev = &pdev->dev;
@@ -272,6 +317,10 @@ static int mt6370_adc_probe(struct platform_device *pdev)
272317
priv->regmap = regmap;
273318
mutex_init(&priv->adc_lock);
274319

320+
ret = mt6370_get_vendor_info(priv);
321+
if (ret)
322+
return dev_err_probe(dev, ret, "Failed to get vid\n");
323+
275324
ret = regmap_write(priv->regmap, MT6370_REG_CHG_ADC, 0);
276325
if (ret)
277326
return dev_err_probe(dev, ret, "Failed to reset ADC\n");

0 commit comments

Comments
 (0)