* [PATCH v3 1/2] iio: adc: vf610_adc: use devm_* and dev_err_probe() to simple code
@ 2024-11-07 19:18 Frank Li
2024-11-07 19:18 ` [PATCH v3 2/2] iio: adc: vf610_adc: limit i.MX6SX's channel number to 4 Frank Li
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Frank Li @ 2024-11-07 19:18 UTC (permalink / raw)
To: Haibo Chen, Jonathan Cameron, Lars-Peter Clausen,
open list:NXP i.MX 7D/6SX/6UL/93 AND VF610 ADC DRIVER,
open list:NXP i.MX 7D/6SX/6UL/93 AND VF610 ADC DRIVER, open list
Use devm_* and dev_err_probe() simplify probe function and remove
vf610_adc_remove(). Change type of 'vref_uv' to int because
regulator_get_voltage() return type is int.
Reviewed-by: Haibo Chen <haibo.chen@nxp.com>
Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
Change from v2 to v3
- change vref_uv to int from u32 to fix below warning
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202411070633.NIrO7Ert-lkp@intel.com/
smatch warnings:
drivers/iio/adc/vf610_adc.c:857 vf610_adc_probe() warn: unsigned 'info->vref_uv' is never less than zero.
vim +857 drivers/iio/adc/vf610_adc.c
Change from v1 to v2
- add Haibo's review tag
---
drivers/iio/adc/vf610_adc.c | 79 ++++++++++---------------------------
1 file changed, 20 insertions(+), 59 deletions(-)
diff --git a/drivers/iio/adc/vf610_adc.c b/drivers/iio/adc/vf610_adc.c
index 4d83c12975c53..a6a0ada8a102f 100644
--- a/drivers/iio/adc/vf610_adc.c
+++ b/drivers/iio/adc/vf610_adc.c
@@ -160,7 +160,7 @@ struct vf610_adc {
/* lock to protect against multiple access to the device */
struct mutex lock;
- u32 vref_uv;
+ int vref_uv;
u32 value;
struct regulator *vref;
@@ -823,10 +823,8 @@ static int vf610_adc_probe(struct platform_device *pdev)
int ret;
indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(struct vf610_adc));
- if (!indio_dev) {
- dev_err(&pdev->dev, "Failed allocating iio device\n");
- return -ENOMEM;
- }
+ if (!indio_dev)
+ return dev_err_probe(&pdev->dev, -ENOMEM, "Failed allocating iio device\n");
info = iio_priv(indio_dev);
info->dev = &pdev->dev;
@@ -842,27 +840,22 @@ static int vf610_adc_probe(struct platform_device *pdev)
ret = devm_request_irq(info->dev, irq,
vf610_adc_isr, 0,
dev_name(&pdev->dev), indio_dev);
- if (ret < 0) {
- dev_err(&pdev->dev, "failed requesting irq, irq = %d\n", irq);
- return ret;
- }
+ if (ret < 0)
+ dev_err_probe(&pdev->dev, ret, "failed requesting irq, irq = %d\n", irq);
- info->clk = devm_clk_get(&pdev->dev, "adc");
- if (IS_ERR(info->clk)) {
- dev_err(&pdev->dev, "failed getting clock, err = %ld\n",
- PTR_ERR(info->clk));
- return PTR_ERR(info->clk);
- }
+ info->clk = devm_clk_get_enabled(&pdev->dev, "adc");
+ if (IS_ERR(info->clk))
+ return dev_err_probe(&pdev->dev, PTR_ERR(info->clk),
+ "failed getting clock, err = %ld\n",
+ PTR_ERR(info->clk));
info->vref = devm_regulator_get(&pdev->dev, "vref");
if (IS_ERR(info->vref))
return PTR_ERR(info->vref);
- ret = regulator_enable(info->vref);
- if (ret)
- return ret;
-
- info->vref_uv = regulator_get_voltage(info->vref);
+ info->vref_uv = devm_regulator_get_enable_read_voltage(&pdev->dev, "vref");
+ if (info->vref_uv < 0)
+ return info->vref_uv;
device_property_read_u32_array(dev, "fsl,adck-max-frequency", info->max_adck_rate, 3);
@@ -879,52 +872,21 @@ static int vf610_adc_probe(struct platform_device *pdev)
indio_dev->channels = vf610_adc_iio_channels;
indio_dev->num_channels = ARRAY_SIZE(vf610_adc_iio_channels);
- ret = clk_prepare_enable(info->clk);
- if (ret) {
- dev_err(&pdev->dev,
- "Could not prepare or enable the clock.\n");
- goto error_adc_clk_enable;
- }
-
vf610_adc_cfg_init(info);
vf610_adc_hw_init(info);
- ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
- NULL, &iio_triggered_buffer_setup_ops);
- if (ret < 0) {
- dev_err(&pdev->dev, "Couldn't initialise the buffer\n");
- goto error_iio_device_register;
- }
+ ret = devm_iio_triggered_buffer_setup(&pdev->dev, indio_dev, &iio_pollfunc_store_time,
+ NULL, &iio_triggered_buffer_setup_ops);
+ if (ret < 0)
+ return dev_err_probe(&pdev->dev, ret, "Couldn't initialise the buffer\n");
mutex_init(&info->lock);
- ret = iio_device_register(indio_dev);
- if (ret) {
- dev_err(&pdev->dev, "Couldn't register the device.\n");
- goto error_adc_buffer_init;
- }
+ ret = devm_iio_device_register(&pdev->dev, indio_dev);
+ if (ret)
+ return dev_err_probe(&pdev->dev, ret, "Couldn't register the device.\n");
return 0;
-
-error_adc_buffer_init:
- iio_triggered_buffer_cleanup(indio_dev);
-error_iio_device_register:
- clk_disable_unprepare(info->clk);
-error_adc_clk_enable:
- regulator_disable(info->vref);
-
- return ret;
-}
-
-static void vf610_adc_remove(struct platform_device *pdev)
-{
- struct iio_dev *indio_dev = platform_get_drvdata(pdev);
- struct vf610_adc *info = iio_priv(indio_dev);
-
- iio_device_unregister(indio_dev);
- iio_triggered_buffer_cleanup(indio_dev);
- regulator_disable(info->vref);
- clk_disable_unprepare(info->clk);
}
static int vf610_adc_suspend(struct device *dev)
@@ -972,7 +934,6 @@ static DEFINE_SIMPLE_DEV_PM_OPS(vf610_adc_pm_ops, vf610_adc_suspend,
static struct platform_driver vf610_adc_driver = {
.probe = vf610_adc_probe,
- .remove = vf610_adc_remove,
.driver = {
.name = DRIVER_NAME,
.of_match_table = vf610_adc_match,
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v3 2/2] iio: adc: vf610_adc: limit i.MX6SX's channel number to 4
2024-11-07 19:18 [PATCH v3 1/2] iio: adc: vf610_adc: use devm_* and dev_err_probe() to simple code Frank Li
@ 2024-11-07 19:18 ` Frank Li
2024-11-09 13:11 ` Jonathan Cameron
2024-11-07 19:38 ` [PATCH v3 1/2] iio: adc: vf610_adc: use devm_* and dev_err_probe() to simple code Christophe JAILLET
2024-11-09 13:07 ` Jonathan Cameron
2 siblings, 1 reply; 9+ messages in thread
From: Frank Li @ 2024-11-07 19:18 UTC (permalink / raw)
To: Haibo Chen, Jonathan Cameron, Lars-Peter Clausen,
open list:NXP i.MX 7D/6SX/6UL/93 AND VF610 ADC DRIVER,
open list:NXP i.MX 7D/6SX/6UL/93 AND VF610 ADC DRIVER, open list
i.MX6SX only has 4 ADC channels, so limit channel numbers to 4 for
compatible string 'fsl,imx6sx-adc'.
Reviewed-by: Haibo Chen <haibo.chen@nxp.com>
Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
compatible string 'fsl,imx6sx-adc' already document in
Documentation/devicetree/bindings/iio/adc/fsl,vf610-adc.yaml
Change from v2 to v3
- none
Change from v1 to v2
- Add Haibo Chen <haibo.chen@nxp.com>
- change cast to uintptr_t to fix below warning
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202411052345.gyJaM3h4-lkp@intel.com/
All warnings (new ones prefixed by >>):
In file included from drivers/iio/adc/vf610_adc.c:20: In file included from include/linux/regulator/consumer.h:35:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:21:
In file included from include/linux/mm.h:2213:
include/linux/vmstat.h:518:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
518 | return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
| ~~~~~~~~~~~ ^ ~~~>> drivers/iio/adc/vf610_adc.c:874:28: warning: cast to smaller integer type 'u32' (aka 'unsigned int') from 'const void *' [-Wvoid-pointer-to-int-cast]
874 | indio_dev->num_channels = (u32)device_get_match_data(dev);
|
---
drivers/iio/adc/vf610_adc.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/adc/vf610_adc.c b/drivers/iio/adc/vf610_adc.c
index a6a0ada8a102f..36f6132bf5ba4 100644
--- a/drivers/iio/adc/vf610_adc.c
+++ b/drivers/iio/adc/vf610_adc.c
@@ -809,7 +809,8 @@ static const struct iio_info vf610_adc_iio_info = {
};
static const struct of_device_id vf610_adc_match[] = {
- { .compatible = "fsl,vf610-adc", },
+ { .compatible = "fsl,imx6sx-adc", .data = (void *)4},
+ { .compatible = "fsl,vf610-adc", .data = (void *)ARRAY_SIZE(vf610_adc_iio_channels)},
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, vf610_adc_match);
@@ -870,7 +871,7 @@ static int vf610_adc_probe(struct platform_device *pdev)
indio_dev->info = &vf610_adc_iio_info;
indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->channels = vf610_adc_iio_channels;
- indio_dev->num_channels = ARRAY_SIZE(vf610_adc_iio_channels);
+ indio_dev->num_channels = (uintptr_t)device_get_match_data(dev);
vf610_adc_cfg_init(info);
vf610_adc_hw_init(info);
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v3 1/2] iio: adc: vf610_adc: use devm_* and dev_err_probe() to simple code
2024-11-07 19:18 [PATCH v3 1/2] iio: adc: vf610_adc: use devm_* and dev_err_probe() to simple code Frank Li
2024-11-07 19:18 ` [PATCH v3 2/2] iio: adc: vf610_adc: limit i.MX6SX's channel number to 4 Frank Li
@ 2024-11-07 19:38 ` Christophe JAILLET
2024-11-07 19:49 ` Frank Li
2024-11-09 13:07 ` Jonathan Cameron
2 siblings, 1 reply; 9+ messages in thread
From: Christophe JAILLET @ 2024-11-07 19:38 UTC (permalink / raw)
To: Frank Li
Cc: Haibo Chen, Jonathan Cameron, Lars-Peter Clausen, linux-iio, imx,
linux-kernel@vger.kernel.org
Le 07/11/2024 à 20:18, Frank Li a écrit :
> Use devm_* and dev_err_probe() simplify probe function and remove
> vf610_adc_remove(). Change type of 'vref_uv' to int because
> regulator_get_voltage() return type is int.
>
> Reviewed-by: Haibo Chen <haibo.chen-3arQi8VN3Tc@public.gmane.org>
> Signed-off-by: Frank Li <Frank.Li-3arQi8VN3Tc@public.gmane.org>
> ---
> Change from v2 to v3
> - change vref_uv to int from u32 to fix below warning
> | Reported-by: kernel test robot <lkp-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202411070633.NIrO7Ert-lkp-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org/
> smatch warnings:
> drivers/iio/adc/vf610_adc.c:857 vf610_adc_probe() warn: unsigned 'info->vref_uv' is never less than zero.
>
> vim +857 drivers/iio/adc/vf610_adc.c
>
> Change from v1 to v2
> - add Haibo's review tag
> ---
> drivers/iio/adc/vf610_adc.c | 79 ++++++++++---------------------------
> 1 file changed, 20 insertions(+), 59 deletions(-)
>
> diff --git a/drivers/iio/adc/vf610_adc.c b/drivers/iio/adc/vf610_adc.c
> index 4d83c12975c53..a6a0ada8a102f 100644
> --- a/drivers/iio/adc/vf610_adc.c
> +++ b/drivers/iio/adc/vf610_adc.c
> @@ -160,7 +160,7 @@ struct vf610_adc {
> /* lock to protect against multiple access to the device */
> struct mutex lock;
>
> - u32 vref_uv;
> + int vref_uv;
> u32 value;
> struct regulator *vref;
>
> @@ -823,10 +823,8 @@ static int vf610_adc_probe(struct platform_device *pdev)
> int ret;
>
> indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(struct vf610_adc));
> - if (!indio_dev) {
> - dev_err(&pdev->dev, "Failed allocating iio device\n");
> - return -ENOMEM;
> - }
> + if (!indio_dev)
> + return dev_err_probe(&pdev->dev, -ENOMEM, "Failed allocating iio device\n");
>
> info = iio_priv(indio_dev);
> info->dev = &pdev->dev;
> @@ -842,27 +840,22 @@ static int vf610_adc_probe(struct platform_device *pdev)
> ret = devm_request_irq(info->dev, irq,
> vf610_adc_isr, 0,
> dev_name(&pdev->dev), indio_dev);
> - if (ret < 0) {
> - dev_err(&pdev->dev, "failed requesting irq, irq = %d\n", irq);
> - return ret;
> - }
> + if (ret < 0)
> + dev_err_probe(&pdev->dev, ret, "failed requesting irq, irq = %d\n", irq);
missing return?
>
> - info->clk = devm_clk_get(&pdev->dev, "adc");
> - if (IS_ERR(info->clk)) {
> - dev_err(&pdev->dev, "failed getting clock, err = %ld\n",
> - PTR_ERR(info->clk));
> - return PTR_ERR(info->clk);
> - }
> + info->clk = devm_clk_get_enabled(&pdev->dev, "adc");
> + if (IS_ERR(info->clk))
> + return dev_err_probe(&pdev->dev, PTR_ERR(info->clk),
> + "failed getting clock, err = %ld\n",
> + PTR_ERR(info->clk));
No need to add an extra PTR_ERR(info->clk)
>
> info->vref = devm_regulator_get(&pdev->dev, "vref");
With the change to devm_regulator_get_enable_read_voltage(), is it still
needed?
CJ
> if (IS_ERR(info->vref))
> return PTR_ERR(info->vref);
>
> - ret = regulator_enable(info->vref);
> - if (ret)
> - return ret;
> -
> - info->vref_uv = regulator_get_voltage(info->vref);
> + info->vref_uv = devm_regulator_get_enable_read_voltage(&pdev->dev, "vref");
> + if (info->vref_uv < 0)
> + return info->vref_uv;
>
> device_property_read_u32_array(dev, "fsl,adck-max-frequency", info->max_adck_rate, 3);
>
...
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 1/2] iio: adc: vf610_adc: use devm_* and dev_err_probe() to simple code
2024-11-07 19:38 ` [PATCH v3 1/2] iio: adc: vf610_adc: use devm_* and dev_err_probe() to simple code Christophe JAILLET
@ 2024-11-07 19:49 ` Frank Li
2024-11-08 6:13 ` Christophe JAILLET
0 siblings, 1 reply; 9+ messages in thread
From: Frank Li @ 2024-11-07 19:49 UTC (permalink / raw)
To: Christophe JAILLET
Cc: Haibo Chen, Jonathan Cameron, Lars-Peter Clausen, linux-iio, imx,
linux-kernel@vger.kernel.org
On Thu, Nov 07, 2024 at 08:38:20PM +0100, Christophe JAILLET wrote:
> Le 07/11/2024 à 20:18, Frank Li a écrit :
> > Use devm_* and dev_err_probe() simplify probe function and remove
> > vf610_adc_remove(). Change type of 'vref_uv' to int because
> > regulator_get_voltage() return type is int.
> >
> > Reviewed-by: Haibo Chen <haibo.chen-3arQi8VN3Tc@public.gmane.org>
> > Signed-off-by: Frank Li <Frank.Li-3arQi8VN3Tc@public.gmane.org>
> > ---
> > Change from v2 to v3
> > - change vref_uv to int from u32 to fix below warning
> > | Reported-by: kernel test robot <lkp-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
> > | Closes: https://lore.kernel.org/oe-kbuild-all/202411070633.NIrO7Ert-lkp-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org/
> > smatch warnings:
> > drivers/iio/adc/vf610_adc.c:857 vf610_adc_probe() warn: unsigned 'info->vref_uv' is never less than zero.
> >
> > vim +857 drivers/iio/adc/vf610_adc.c
> >
> > Change from v1 to v2
> > - add Haibo's review tag
> > ---
> > drivers/iio/adc/vf610_adc.c | 79 ++++++++++---------------------------
> > 1 file changed, 20 insertions(+), 59 deletions(-)
> >
> > diff --git a/drivers/iio/adc/vf610_adc.c b/drivers/iio/adc/vf610_adc.c
> > index 4d83c12975c53..a6a0ada8a102f 100644
> > --- a/drivers/iio/adc/vf610_adc.c
> > +++ b/drivers/iio/adc/vf610_adc.c
> > @@ -160,7 +160,7 @@ struct vf610_adc {
> > /* lock to protect against multiple access to the device */
> > struct mutex lock;
> > - u32 vref_uv;
> > + int vref_uv;
> > u32 value;
> > struct regulator *vref;
> > @@ -823,10 +823,8 @@ static int vf610_adc_probe(struct platform_device *pdev)
> > int ret;
> > indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(struct vf610_adc));
> > - if (!indio_dev) {
> > - dev_err(&pdev->dev, "Failed allocating iio device\n");
> > - return -ENOMEM;
> > - }
> > + if (!indio_dev)
> > + return dev_err_probe(&pdev->dev, -ENOMEM, "Failed allocating iio device\n");
> > info = iio_priv(indio_dev);
> > info->dev = &pdev->dev;
> > @@ -842,27 +840,22 @@ static int vf610_adc_probe(struct platform_device *pdev)
> > ret = devm_request_irq(info->dev, irq,
> > vf610_adc_isr, 0,
> > dev_name(&pdev->dev), indio_dev);
> > - if (ret < 0) {
> > - dev_err(&pdev->dev, "failed requesting irq, irq = %d\n", irq);
> > - return ret;
> > - }
> > + if (ret < 0)
> > + dev_err_probe(&pdev->dev, ret, "failed requesting irq, irq = %d\n", irq);
>
> missing return?
Yes, thank you find it.
>
> > - info->clk = devm_clk_get(&pdev->dev, "adc");
> > - if (IS_ERR(info->clk)) {
> > - dev_err(&pdev->dev, "failed getting clock, err = %ld\n",
> > - PTR_ERR(info->clk));
> > - return PTR_ERR(info->clk);
> > - }
> > + info->clk = devm_clk_get_enabled(&pdev->dev, "adc");
> > + if (IS_ERR(info->clk))
> > + return dev_err_probe(&pdev->dev, PTR_ERR(info->clk),
> > + "failed getting clock, err = %ld\n",
> > + PTR_ERR(info->clk));
>
> No need to add an extra PTR_ERR(info->clk)
yes, dev_err_probe() already print error code. So "err= %ld" can be removed
also.
>
> > info->vref = devm_regulator_get(&pdev->dev, "vref");
>
> With the change to devm_regulator_get_enable_read_voltage(), is it still
> needed?
Suspend function need vref to disable regulator.
>
> CJ
>
> > if (IS_ERR(info->vref))
> > return PTR_ERR(info->vref);
> > - ret = regulator_enable(info->vref);
> > - if (ret)
> > - return ret;
> > -
> > - info->vref_uv = regulator_get_voltage(info->vref);
> > + info->vref_uv = devm_regulator_get_enable_read_voltage(&pdev->dev, "vref");
> > + if (info->vref_uv < 0)
> > + return info->vref_uv;
> > device_property_read_u32_array(dev, "fsl,adck-max-frequency", info->max_adck_rate, 3);
>
> ...
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 1/2] iio: adc: vf610_adc: use devm_* and dev_err_probe() to simple code
2024-11-07 19:49 ` Frank Li
@ 2024-11-08 6:13 ` Christophe JAILLET
2024-11-08 19:12 ` Frank Li
0 siblings, 1 reply; 9+ messages in thread
From: Christophe JAILLET @ 2024-11-08 6:13 UTC (permalink / raw)
To: Frank Li; +Cc: Haibo Chen, Jonathan Cameron, Lars-Peter Clausen, linux-iio, imx
Le 07/11/2024 à 20:49, Frank Li a écrit :
> On Thu, Nov 07, 2024 at 08:38:20PM +0100, Christophe JAILLET wrote:
>> Le 07/11/2024 à 20:18, Frank Li a écrit :
>>> Use devm_* and dev_err_probe() simplify probe function and remove
>>> vf610_adc_remove(). Change type of 'vref_uv' to int because
>>> regulator_get_voltage() return type is int.
>>>
>>> Reviewed-by: Haibo Chen <haibo.chen-3arQi8VN3Tc-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org>
>>> Signed-off-by: Frank Li <Frank.Li-3arQi8VN3Tc-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org>
>>> ---
...
>>
>>> info->vref = devm_regulator_get(&pdev->dev, "vref");
>>
>> With the change to devm_regulator_get_enable_read_voltage(), is it still
>> needed?
>
> Suspend function need vref to disable regulator.
Ok.
But why switch to devm_regulator_get_enable_read_voltage() then?
Shouldn't keeping regulator_get_voltage() be enough and simpler?
CJ
>
>>
>> CJ
>>
>>> if (IS_ERR(info->vref))
>>> return PTR_ERR(info->vref);
>>> - ret = regulator_enable(info->vref);
>>> - if (ret)
>>> - return ret;
>>> -
>>> - info->vref_uv = regulator_get_voltage(info->vref);
>>> + info->vref_uv = devm_regulator_get_enable_read_voltage(&pdev->dev, "vref");
>>> + if (info->vref_uv < 0)
>>> + return info->vref_uv;
>>> device_property_read_u32_array(dev, "fsl,adck-max-frequency", info->max_adck_rate, 3);
>>
>> ...
>>
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 1/2] iio: adc: vf610_adc: use devm_* and dev_err_probe() to simple code
2024-11-08 6:13 ` Christophe JAILLET
@ 2024-11-08 19:12 ` Frank Li
2024-11-09 13:04 ` Jonathan Cameron
0 siblings, 1 reply; 9+ messages in thread
From: Frank Li @ 2024-11-08 19:12 UTC (permalink / raw)
To: Christophe JAILLET
Cc: Haibo Chen, Jonathan Cameron, Lars-Peter Clausen, linux-iio, imx
On Fri, Nov 08, 2024 at 07:13:20AM +0100, Christophe JAILLET wrote:
> Le 07/11/2024 à 20:49, Frank Li a écrit :
> > On Thu, Nov 07, 2024 at 08:38:20PM +0100, Christophe JAILLET wrote:
> > > Le 07/11/2024 à 20:18, Frank Li a écrit :
> > > > Use devm_* and dev_err_probe() simplify probe function and remove
> > > > vf610_adc_remove(). Change type of 'vref_uv' to int because
> > > > regulator_get_voltage() return type is int.
> > > >
> > > > Reviewed-by: Haibo Chen <haibo.chen-3arQi8VN3Tc-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org>
> > > > Signed-off-by: Frank Li <Frank.Li-3arQi8VN3Tc-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org>
> > > > ---
>
> ...
>
> > >
> > > > info->vref = devm_regulator_get(&pdev->dev, "vref");
> > >
> > > With the change to devm_regulator_get_enable_read_voltage(), is it still
> > > needed?
> >
> > Suspend function need vref to disable regulator.
>
> Ok.
>
> But why switch to devm_regulator_get_enable_read_voltage() then?
> Shouldn't keeping regulator_get_voltage() be enough and simpler?
Avoid goto err after devm_regulator_get_enable_read_voltage(), if use
regulator_enable(), it needs regulator_disable() in err handle branch after
it.
Frank
>
> CJ
>
> >
> > >
> > > CJ
> > >
> > > > if (IS_ERR(info->vref))
> > > > return PTR_ERR(info->vref);
> > > > - ret = regulator_enable(info->vref);
> > > > - if (ret)
> > > > - return ret;
> > > > -
> > > > - info->vref_uv = regulator_get_voltage(info->vref);
> > > > + info->vref_uv = devm_regulator_get_enable_read_voltage(&pdev->dev, "vref");
> > > > + if (info->vref_uv < 0)
> > > > + return info->vref_uv;
> > > > device_property_read_u32_array(dev, "fsl,adck-max-frequency", info->max_adck_rate, 3);
> > >
> > > ...
> > >
> >
> >
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 1/2] iio: adc: vf610_adc: use devm_* and dev_err_probe() to simple code
2024-11-08 19:12 ` Frank Li
@ 2024-11-09 13:04 ` Jonathan Cameron
0 siblings, 0 replies; 9+ messages in thread
From: Jonathan Cameron @ 2024-11-09 13:04 UTC (permalink / raw)
To: Frank Li; +Cc: Christophe JAILLET, Haibo Chen, Lars-Peter Clausen, linux-iio,
imx
On Fri, 8 Nov 2024 14:12:29 -0500
Frank Li <Frank.li@nxp.com> wrote:
> On Fri, Nov 08, 2024 at 07:13:20AM +0100, Christophe JAILLET wrote:
> > Le 07/11/2024 à 20:49, Frank Li a écrit :
> > > On Thu, Nov 07, 2024 at 08:38:20PM +0100, Christophe JAILLET wrote:
> > > > Le 07/11/2024 à 20:18, Frank Li a écrit :
> > > > > Use devm_* and dev_err_probe() simplify probe function and remove
> > > > > vf610_adc_remove(). Change type of 'vref_uv' to int because
> > > > > regulator_get_voltage() return type is int.
> > > > >
> > > > > Reviewed-by: Haibo Chen <haibo.chen-3arQi8VN3Tc-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org>
> > > > > Signed-off-by: Frank Li <Frank.Li-3arQi8VN3Tc-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org>
> > > > > ---
> >
> > ...
> >
> > > >
> > > > > info->vref = devm_regulator_get(&pdev->dev, "vref");
> > > >
> > > > With the change to devm_regulator_get_enable_read_voltage(), is it still
> > > > needed?
> > >
> > > Suspend function need vref to disable regulator.
> >
> > Ok.
> >
> > But why switch to devm_regulator_get_enable_read_voltage() then?
> > Shouldn't keeping regulator_get_voltage() be enough and simpler?
>
> Avoid goto err after devm_regulator_get_enable_read_voltage(), if use
> regulator_enable(), it needs regulator_disable() in err handle branch after
> it.
Don't get the same regulator twice - that works but is likely to be error
prone in the long run and is a bit too subtle.
This isn't an appropriate use of devm_regulator_get_enable_read_voltage()
Instead just use a local callback and
devm_add_action_or_reset() to disable the regulator in the devm tear down path.
Jonathan
>
> Frank
>
> >
> > CJ
> >
> > >
> > > >
> > > > CJ
> > > >
> > > > > if (IS_ERR(info->vref))
> > > > > return PTR_ERR(info->vref);
> > > > > - ret = regulator_enable(info->vref);
> > > > > - if (ret)
> > > > > - return ret;
> > > > > -
> > > > > - info->vref_uv = regulator_get_voltage(info->vref);
> > > > > + info->vref_uv = devm_regulator_get_enable_read_voltage(&pdev->dev, "vref");
> > > > > + if (info->vref_uv < 0)
> > > > > + return info->vref_uv;
> > > > > device_property_read_u32_array(dev, "fsl,adck-max-frequency", info->max_adck_rate, 3);
> > > >
> > > > ...
> > > >
> > >
> > >
> >
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 1/2] iio: adc: vf610_adc: use devm_* and dev_err_probe() to simple code
2024-11-07 19:18 [PATCH v3 1/2] iio: adc: vf610_adc: use devm_* and dev_err_probe() to simple code Frank Li
2024-11-07 19:18 ` [PATCH v3 2/2] iio: adc: vf610_adc: limit i.MX6SX's channel number to 4 Frank Li
2024-11-07 19:38 ` [PATCH v3 1/2] iio: adc: vf610_adc: use devm_* and dev_err_probe() to simple code Christophe JAILLET
@ 2024-11-09 13:07 ` Jonathan Cameron
2 siblings, 0 replies; 9+ messages in thread
From: Jonathan Cameron @ 2024-11-09 13:07 UTC (permalink / raw)
To: Frank Li
Cc: Haibo Chen, Lars-Peter Clausen,
open list:NXP i.MX 7D/6SX/6UL/93 AND VF610 ADC DRIVER,
open list:NXP i.MX 7D/6SX/6UL/93 AND VF610 ADC DRIVER, open list
On Thu, 7 Nov 2024 14:18:40 -0500
Frank Li <Frank.Li@nxp.com> wrote:
> Use devm_* and dev_err_probe() simplify probe function and remove
> vf610_adc_remove(). Change type of 'vref_uv' to int because
> regulator_get_voltage() return type is int.
>
> Reviewed-by: Haibo Chen <haibo.chen@nxp.com>
> Signed-off-by: Frank Li <Frank.Li@nxp.com>
One comment inline.
> ---
> Change from v2 to v3
> - change vref_uv to int from u32 to fix below warning
That's not the nicest way to fix the issue. See below.
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202411070633.NIrO7Ert-lkp@intel.com/
> smatch warnings:
> drivers/iio/adc/vf610_adc.c:857 vf610_adc_probe() warn: unsigned 'info->vref_uv' is never less than zero.
>
> vim +857 drivers/iio/adc/vf610_adc.c
>
> Change from v1 to v2
> - add Haibo's review tag
> ---
> drivers/iio/adc/vf610_adc.c | 79 ++++++++++---------------------------
> 1 file changed, 20 insertions(+), 59 deletions(-)
>
> diff --git a/drivers/iio/adc/vf610_adc.c b/drivers/iio/adc/vf610_adc.c
> index 4d83c12975c53..a6a0ada8a102f 100644
> --- a/drivers/iio/adc/vf610_adc.c
> +++ b/drivers/iio/adc/vf610_adc.c
> @@ -160,7 +160,7 @@ struct vf610_adc {
> /* lock to protect against multiple access to the device */
> struct mutex lock;
>
> - u32 vref_uv;
> + int vref_uv;
> u32 value;
> struct regulator *vref;
>
> @@ -823,10 +823,8 @@ static int vf610_adc_probe(struct platform_device *pdev)
> int ret;
>
> indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(struct vf610_adc));
> - if (!indio_dev) {
> - dev_err(&pdev->dev, "Failed allocating iio device\n");
> - return -ENOMEM;
> - }
> + if (!indio_dev)
> + return dev_err_probe(&pdev->dev, -ENOMEM, "Failed allocating iio device\n");
>
> info = iio_priv(indio_dev);
> info->dev = &pdev->dev;
> @@ -842,27 +840,22 @@ static int vf610_adc_probe(struct platform_device *pdev)
> ret = devm_request_irq(info->dev, irq,
> vf610_adc_isr, 0,
> dev_name(&pdev->dev), indio_dev);
> - if (ret < 0) {
> - dev_err(&pdev->dev, "failed requesting irq, irq = %d\n", irq);
> - return ret;
> - }
> + if (ret < 0)
> + dev_err_probe(&pdev->dev, ret, "failed requesting irq, irq = %d\n", irq);
>
> - info->clk = devm_clk_get(&pdev->dev, "adc");
> - if (IS_ERR(info->clk)) {
> - dev_err(&pdev->dev, "failed getting clock, err = %ld\n",
> - PTR_ERR(info->clk));
> - return PTR_ERR(info->clk);
> - }
> + info->clk = devm_clk_get_enabled(&pdev->dev, "adc");
> + if (IS_ERR(info->clk))
> + return dev_err_probe(&pdev->dev, PTR_ERR(info->clk),
> + "failed getting clock, err = %ld\n",
> + PTR_ERR(info->clk));
>
> info->vref = devm_regulator_get(&pdev->dev, "vref");
> if (IS_ERR(info->vref))
> return PTR_ERR(info->vref);
>
> - ret = regulator_enable(info->vref);
> - if (ret)
> - return ret;
> -
> - info->vref_uv = regulator_get_voltage(info->vref);
> + info->vref_uv = devm_regulator_get_enable_read_voltage(&pdev->dev, "vref");
> + if (info->vref_uv < 0)
> + return info->vref_uv;
whilst I've suggested not doing this in this fashion anyway so this code will probably
go away but in general prefer this sort of handling done as
ret = devm_regulator_get_enable_read_voltage();
if (ret < 0)
return ret;
info->vref_uv = ret;
so that we don't bounce a potential error code through a state variable and have
to change the type as you have done here.
>
> device_property_read_u32_array(dev, "fsl,adck-max-frequency", info->max_adck_rate, 3);
>
> @@ -879,52 +872,21 @@ static int vf610_adc_probe(struct platform_device *pdev)
> indio_dev->channels = vf610_adc_iio_channels;
> indio_dev->num_channels = ARRAY_SIZE(vf610_adc_iio_channels);
>
> - ret = clk_prepare_enable(info->clk);
> - if (ret) {
> - dev_err(&pdev->dev,
> - "Could not prepare or enable the clock.\n");
> - goto error_adc_clk_enable;
> - }
> -
> vf610_adc_cfg_init(info);
> vf610_adc_hw_init(info);
>
> - ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
> - NULL, &iio_triggered_buffer_setup_ops);
> - if (ret < 0) {
> - dev_err(&pdev->dev, "Couldn't initialise the buffer\n");
> - goto error_iio_device_register;
> - }
> + ret = devm_iio_triggered_buffer_setup(&pdev->dev, indio_dev, &iio_pollfunc_store_time,
> + NULL, &iio_triggered_buffer_setup_ops);
> + if (ret < 0)
> + return dev_err_probe(&pdev->dev, ret, "Couldn't initialise the buffer\n");
>
> mutex_init(&info->lock);
>
> - ret = iio_device_register(indio_dev);
> - if (ret) {
> - dev_err(&pdev->dev, "Couldn't register the device.\n");
> - goto error_adc_buffer_init;
> - }
> + ret = devm_iio_device_register(&pdev->dev, indio_dev);
> + if (ret)
> + return dev_err_probe(&pdev->dev, ret, "Couldn't register the device.\n");
>
> return 0;
> -
> -error_adc_buffer_init:
> - iio_triggered_buffer_cleanup(indio_dev);
> -error_iio_device_register:
> - clk_disable_unprepare(info->clk);
> -error_adc_clk_enable:
> - regulator_disable(info->vref);
> -
> - return ret;
> -}
> -
> -static void vf610_adc_remove(struct platform_device *pdev)
> -{
> - struct iio_dev *indio_dev = platform_get_drvdata(pdev);
> - struct vf610_adc *info = iio_priv(indio_dev);
> -
> - iio_device_unregister(indio_dev);
> - iio_triggered_buffer_cleanup(indio_dev);
> - regulator_disable(info->vref);
> - clk_disable_unprepare(info->clk);
> }
>
> static int vf610_adc_suspend(struct device *dev)
> @@ -972,7 +934,6 @@ static DEFINE_SIMPLE_DEV_PM_OPS(vf610_adc_pm_ops, vf610_adc_suspend,
>
> static struct platform_driver vf610_adc_driver = {
> .probe = vf610_adc_probe,
> - .remove = vf610_adc_remove,
> .driver = {
> .name = DRIVER_NAME,
> .of_match_table = vf610_adc_match,
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 2/2] iio: adc: vf610_adc: limit i.MX6SX's channel number to 4
2024-11-07 19:18 ` [PATCH v3 2/2] iio: adc: vf610_adc: limit i.MX6SX's channel number to 4 Frank Li
@ 2024-11-09 13:11 ` Jonathan Cameron
0 siblings, 0 replies; 9+ messages in thread
From: Jonathan Cameron @ 2024-11-09 13:11 UTC (permalink / raw)
To: Frank Li
Cc: Haibo Chen, Lars-Peter Clausen,
open list:NXP i.MX 7D/6SX/6UL/93 AND VF610 ADC DRIVER,
open list:NXP i.MX 7D/6SX/6UL/93 AND VF610 ADC DRIVER, open list
On Thu, 7 Nov 2024 14:18:41 -0500
Frank Li <Frank.Li@nxp.com> wrote:
> i.MX6SX only has 4 ADC channels, so limit channel numbers to 4 for
> compatible string 'fsl,imx6sx-adc'.
>
> Reviewed-by: Haibo Chen <haibo.chen@nxp.com>
> Signed-off-by: Frank Li <Frank.Li@nxp.com>
I'm pretty strongly against putting integers in the id match
data variables. Instead use a much more easily extended structure
(which will have one element for now)
struct vf610_chip_info {
u8 num_channels;
};
and then pointers to that structure in the tables.
The integer path regularly goes wrong (0 causes trouble with error handling)
and so I push back on people doing this in new code.
One other comment inline.
Jonathan
> ---
> compatible string 'fsl,imx6sx-adc' already document in
> Documentation/devicetree/bindings/iio/adc/fsl,vf610-adc.yaml
>
> Change from v2 to v3
> - none
>
> Change from v1 to v2
> - Add Haibo Chen <haibo.chen@nxp.com>
> - change cast to uintptr_t to fix below warning
>
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202411052345.gyJaM3h4-lkp@intel.com/
> All warnings (new ones prefixed by >>):
>
> In file included from drivers/iio/adc/vf610_adc.c:20: In file included from include/linux/regulator/consumer.h:35:
> In file included from include/linux/suspend.h:5:
> In file included from include/linux/swap.h:9:
> In file included from include/linux/memcontrol.h:21:
> In file included from include/linux/mm.h:2213:
> include/linux/vmstat.h:518:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
> 518 | return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
> | ~~~~~~~~~~~ ^ ~~~>> drivers/iio/adc/vf610_adc.c:874:28: warning: cast to smaller integer type 'u32' (aka 'unsigned int') from 'const void *' [-Wvoid-pointer-to-int-cast]
> 874 | indio_dev->num_channels = (u32)device_get_match_data(dev);
> |
> ---
> drivers/iio/adc/vf610_adc.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/adc/vf610_adc.c b/drivers/iio/adc/vf610_adc.c
> index a6a0ada8a102f..36f6132bf5ba4 100644
> --- a/drivers/iio/adc/vf610_adc.c
> +++ b/drivers/iio/adc/vf610_adc.c
> @@ -809,7 +809,8 @@ static const struct iio_info vf610_adc_iio_info = {
> };
>
> static const struct of_device_id vf610_adc_match[] = {
> - { .compatible = "fsl,vf610-adc", },
> + { .compatible = "fsl,imx6sx-adc", .data = (void *)4},
> + { .compatible = "fsl,vf610-adc", .data = (void *)ARRAY_SIZE(vf610_adc_iio_channels)},
> { /* sentinel */ }
> };
> MODULE_DEVICE_TABLE(of, vf610_adc_match);
> @@ -870,7 +871,7 @@ static int vf610_adc_probe(struct platform_device *pdev)
> indio_dev->info = &vf610_adc_iio_info;
> indio_dev->modes = INDIO_DIRECT_MODE;
> indio_dev->channels = vf610_adc_iio_channels;
> - indio_dev->num_channels = ARRAY_SIZE(vf610_adc_iio_channels);
> + indio_dev->num_channels = (uintptr_t)device_get_match_data(dev);
That can in theory fail and return NULL. Which here would be interpreted
as 0 channels and probably cause trouble later.
>
> vf610_adc_cfg_init(info);
> vf610_adc_hw_init(info);
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-11-09 13:11 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-07 19:18 [PATCH v3 1/2] iio: adc: vf610_adc: use devm_* and dev_err_probe() to simple code Frank Li
2024-11-07 19:18 ` [PATCH v3 2/2] iio: adc: vf610_adc: limit i.MX6SX's channel number to 4 Frank Li
2024-11-09 13:11 ` Jonathan Cameron
2024-11-07 19:38 ` [PATCH v3 1/2] iio: adc: vf610_adc: use devm_* and dev_err_probe() to simple code Christophe JAILLET
2024-11-07 19:49 ` Frank Li
2024-11-08 6:13 ` Christophe JAILLET
2024-11-08 19:12 ` Frank Li
2024-11-09 13:04 ` Jonathan Cameron
2024-11-09 13:07 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox