[PATCH v2 4/6] iio: adc: mt6359: Move reference voltage to platform data

AngeloGioacchino Del Regno posted 6 patches 3 months ago
[PATCH v2 4/6] iio: adc: mt6359: Move reference voltage to platform data
Posted by AngeloGioacchino Del Regno 3 months ago
In preparation to add support for new PMICs, add a `vref_mv`
member to struct mtk_pmic_auxadc_info and use it in place of
the AUXADC_VOLT_FULL definition.

As a consequence, the definition was also removed.

Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
 drivers/iio/adc/mt6359-auxadc.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/adc/mt6359-auxadc.c b/drivers/iio/adc/mt6359-auxadc.c
index 2ccc64e6c126..914c9a22cd14 100644
--- a/drivers/iio/adc/mt6359-auxadc.c
+++ b/drivers/iio/adc/mt6359-auxadc.c
@@ -28,7 +28,6 @@
 #define AUXADC_AVG_TIME_US		10
 #define AUXADC_POLL_DELAY_US		100
 #define AUXADC_TIMEOUT_US		32000
-#define AUXADC_VOLT_FULL		1800
 #define IMP_STOP_DELAY_US		150
 #define IMP_POLL_DELAY_US		1000
 
@@ -123,6 +122,7 @@ struct mtk_pmic_auxadc_chan {
  * @desc:           PMIC AUXADC channel data
  * @regs:           List of PMIC specific registers
  * @sec_unlock_key: Security unlock key for HK_TOP writes
+ * @vref_mv:        AUXADC Reference Voltage (VREF) in millivolts
  * @imp_adc_num:    ADC channel for battery impedance readings
  * @read_imp:       Callback to read impedance channels
  */
@@ -133,6 +133,7 @@ struct mtk_pmic_auxadc_info {
 	const struct mtk_pmic_auxadc_chan *desc;
 	const u16 *regs;
 	u16 sec_unlock_key;
+	u32 vref_mv;
 	u8 imp_adc_num;
 	int (*read_imp)(struct mt6359_auxadc *adc_dev,
 			const struct iio_chan_spec *chan, int *vbat, int *ibat);
@@ -416,6 +417,7 @@ static const struct mtk_pmic_auxadc_info mt6357_chip_info = {
 	.regs = mt6357_auxadc_regs,
 	.imp_adc_num = MT6357_IMP_ADC_NUM,
 	.read_imp = mt6358_read_imp,
+	.vref_mv = 1800,
 };
 
 static const struct mtk_pmic_auxadc_info mt6358_chip_info = {
@@ -426,6 +428,7 @@ static const struct mtk_pmic_auxadc_info mt6358_chip_info = {
 	.regs = mt6358_auxadc_regs,
 	.imp_adc_num = MT6358_IMP_ADC_NUM,
 	.read_imp = mt6358_read_imp,
+	.vref_mv = 1800,
 };
 
 static const struct mtk_pmic_auxadc_info mt6359_chip_info = {
@@ -436,6 +439,7 @@ static const struct mtk_pmic_auxadc_info mt6359_chip_info = {
 	.regs = mt6359_auxadc_regs,
 	.sec_unlock_key = 0x6359,
 	.read_imp = mt6359_read_imp,
+	.vref_mv = 1800,
 };
 
 static void mt6359_auxadc_reset(struct mt6359_auxadc *adc_dev)
@@ -505,7 +509,7 @@ static int mt6359_auxadc_read_raw(struct iio_dev *indio_dev,
 	int ret;
 
 	if (mask == IIO_CHAN_INFO_SCALE) {
-		*val = desc->r_ratio.numerator * AUXADC_VOLT_FULL;
+		*val = desc->r_ratio.numerator * cinfo->vref_mv;
 
 		if (desc->r_ratio.denominator > 1) {
 			*val2 = desc->r_ratio.denominator;
-- 
2.49.0
Re: [PATCH v2 4/6] iio: adc: mt6359: Move reference voltage to platform data
Posted by Andy Shevchenko 3 months ago
On Thu, Jul 03, 2025 at 04:11:44PM +0200, AngeloGioacchino Del Regno wrote:
> In preparation to add support for new PMICs, add a `vref_mv`

I still think that the vref_mV is a better naming.

> the AUXADC_VOLT_FULL definition.
> 
> As a consequence, the definition was also removed.

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v2 4/6] iio: adc: mt6359: Move reference voltage to platform data
Posted by AngeloGioacchino Del Regno 3 months ago
Il 03/07/25 16:28, Andy Shevchenko ha scritto:
> On Thu, Jul 03, 2025 at 04:11:44PM +0200, AngeloGioacchino Del Regno wrote:
>> In preparation to add support for new PMICs, add a `vref_mv`
> 
> I still think that the vref_mV is a better naming.
> 

Ouch, I think I missed that comment; if there's nothing else to change,
I wonder if the capital V can be fixed while applying?

Otherwise I can send a v3...

Cheers,
Angelo

>> the AUXADC_VOLT_FULL definition.
>>
>> As a consequence, the definition was also removed.
>
Re: [PATCH v2 4/6] iio: adc: mt6359: Move reference voltage to platform data
Posted by Jonathan Cameron 3 months ago
On Thu, 3 Jul 2025 16:40:38 +0200
AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> wrote:

> Il 03/07/25 16:28, Andy Shevchenko ha scritto:
> > On Thu, Jul 03, 2025 at 04:11:44PM +0200, AngeloGioacchino Del Regno wrote:  
> >> In preparation to add support for new PMICs, add a `vref_mv`  
> > 
> > I still think that the vref_mV is a better naming.
> >   
> 
> Ouch, I think I missed that comment; if there's nothing else to change,
> I wonder if the capital V can be fixed while applying?
> 
> Otherwise I can send a v3...
> 

If that's all that comes up I'll tweak whilst applying.

J

> Cheers,
> Angelo
> 
> >> the AUXADC_VOLT_FULL definition.
> >>
> >> As a consequence, the definition was also removed.  
> >   
> 
>