* [PATCH 1/8] iio: adc: fsl-imx25-gcq: Switch from of specific handing to fwnode based.
2024-02-18 17:27 [PATCH 0/8] IIO: Convert DT specific handling over to fwnode Jonathan Cameron
@ 2024-02-18 17:27 ` Jonathan Cameron
2024-02-18 17:27 ` [PATCH 2/8] iio: adc: fsl-imx25-gcq: Use devm_* and dev_err_probe() to simplify probe Jonathan Cameron
` (7 subsequent siblings)
8 siblings, 0 replies; 21+ messages in thread
From: Jonathan Cameron @ 2024-02-18 17:27 UTC (permalink / raw)
To: linux-iio, Andy Shevchenko
Cc: Lars-Peter Clausen, Michael Hennerich, Nuno Sá,
Alisa-Dariana Roman, Haibo Chen, Sean Nyekjaer, Andreas Klinger,
Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Using the generic firmware data access functions from property.h
provides a number of advantages:
1) Works with different firmware types.
2) Doesn't provide a 'bad' example for new IIO drivers.
3) Lets us use the new _scoped() loops with automatic reference count
cleanup for fwnode_handle
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/iio/adc/fsl-imx25-gcq.c | 54 +++++++++++++--------------------
1 file changed, 21 insertions(+), 33 deletions(-)
diff --git a/drivers/iio/adc/fsl-imx25-gcq.c b/drivers/iio/adc/fsl-imx25-gcq.c
index 68c813de0605..534e73a24eb4 100644
--- a/drivers/iio/adc/fsl-imx25-gcq.c
+++ b/drivers/iio/adc/fsl-imx25-gcq.c
@@ -12,8 +12,9 @@
#include <linux/interrupt.h>
#include <linux/mfd/imx25-tsadc.h>
#include <linux/module.h>
-#include <linux/of.h>
+#include <linux/mod_devicetable.h>
#include <linux/platform_device.h>
+#include <linux/property.h>
#include <linux/regmap.h>
#include <linux/regulator/consumer.h>
@@ -198,8 +199,6 @@ static int mx25_gcq_ext_regulator_setup(struct device *dev,
static int mx25_gcq_setup_cfgs(struct platform_device *pdev,
struct mx25_gcq_priv *priv)
{
- struct device_node *np = pdev->dev.of_node;
- struct device_node *child;
struct device *dev = &pdev->dev;
int ret, i;
@@ -216,37 +215,30 @@ static int mx25_gcq_setup_cfgs(struct platform_device *pdev,
MX25_ADCQ_CFG_IN(i) |
MX25_ADCQ_CFG_REFN_NGND2);
- for_each_child_of_node(np, child) {
+ device_for_each_child_node_scoped(dev, child) {
u32 reg;
u32 refp = MX25_ADCQ_CFG_REFP_INT;
u32 refn = MX25_ADCQ_CFG_REFN_NGND2;
- ret = of_property_read_u32(child, "reg", ®);
- if (ret) {
- dev_err(dev, "Failed to get reg property\n");
- of_node_put(child);
- return ret;
- }
+ ret = fwnode_property_read_u32(child, "reg", ®);
+ if (ret)
+ return dev_err_probe(dev, ret,
+ "Failed to get reg property\n");
- if (reg >= MX25_NUM_CFGS) {
- dev_err(dev,
+ if (reg >= MX25_NUM_CFGS)
+ return dev_err_probe(dev, -EINVAL,
"reg value is greater than the number of available configuration registers\n");
- of_node_put(child);
- return -EINVAL;
- }
- of_property_read_u32(child, "fsl,adc-refp", &refp);
- of_property_read_u32(child, "fsl,adc-refn", &refn);
+ fwnode_property_read_u32(child, "fsl,adc-refp", &refp);
+ fwnode_property_read_u32(child, "fsl,adc-refn", &refn);
switch (refp) {
case MX25_ADC_REFP_EXT:
case MX25_ADC_REFP_XP:
case MX25_ADC_REFP_YP:
ret = mx25_gcq_ext_regulator_setup(&pdev->dev, priv, refp);
- if (ret) {
- of_node_put(child);
+ if (ret)
return ret;
- }
priv->channel_vref_mv[reg] =
regulator_get_voltage(priv->vref[refp]);
/* Conversion from uV to mV */
@@ -256,9 +248,8 @@ static int mx25_gcq_setup_cfgs(struct platform_device *pdev,
priv->channel_vref_mv[reg] = 2500;
break;
default:
- dev_err(dev, "Invalid positive reference %d\n", refp);
- of_node_put(child);
- return -EINVAL;
+ return dev_err_probe(dev, -EINVAL,
+ "Invalid positive reference %d\n", refp);
}
/*
@@ -268,16 +259,13 @@ static int mx25_gcq_setup_cfgs(struct platform_device *pdev,
refp = MX25_ADCQ_CFG_REFP(refp);
refn = MX25_ADCQ_CFG_REFN(refn);
- if ((refp & MX25_ADCQ_CFG_REFP_MASK) != refp) {
- dev_err(dev, "Invalid fsl,adc-refp property value\n");
- of_node_put(child);
- return -EINVAL;
- }
- if ((refn & MX25_ADCQ_CFG_REFN_MASK) != refn) {
- dev_err(dev, "Invalid fsl,adc-refn property value\n");
- of_node_put(child);
- return -EINVAL;
- }
+ if ((refp & MX25_ADCQ_CFG_REFP_MASK) != refp)
+ return dev_err_probe(dev, -EINVAL,
+ "Invalid fsl,adc-refp property value\n");
+
+ if ((refn & MX25_ADCQ_CFG_REFN_MASK) != refn)
+ return dev_err_probe(dev, -EINVAL,
+ "Invalid fsl,adc-refn property value\n");
regmap_update_bits(priv->regs, MX25_ADCQ_CFG(reg),
MX25_ADCQ_CFG_REFP_MASK |
--
2.43.2
^ permalink raw reply related [flat|nested] 21+ messages in thread* [PATCH 2/8] iio: adc: fsl-imx25-gcq: Use devm_* and dev_err_probe() to simplify probe
2024-02-18 17:27 [PATCH 0/8] IIO: Convert DT specific handling over to fwnode Jonathan Cameron
2024-02-18 17:27 ` [PATCH 1/8] iio: adc: fsl-imx25-gcq: Switch from of specific handing to fwnode based Jonathan Cameron
@ 2024-02-18 17:27 ` Jonathan Cameron
2024-02-18 17:27 ` [PATCH 3/8] iio: adc: ad7124: Switch from of specific to fwnode based property handling Jonathan Cameron
` (6 subsequent siblings)
8 siblings, 0 replies; 21+ messages in thread
From: Jonathan Cameron @ 2024-02-18 17:27 UTC (permalink / raw)
To: linux-iio, Andy Shevchenko
Cc: Lars-Peter Clausen, Michael Hennerich, Nuno Sá,
Alisa-Dariana Roman, Haibo Chen, Sean Nyekjaer, Andreas Klinger,
Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Custom callbacks are need for regulators (so there is a handle to read
the voltage from) and the clk because it is retrieved from the parent
rather than directly from firmware description.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/iio/adc/fsl-imx25-gcq.c | 86 ++++++++++++++-------------------
1 file changed, 35 insertions(+), 51 deletions(-)
diff --git a/drivers/iio/adc/fsl-imx25-gcq.c b/drivers/iio/adc/fsl-imx25-gcq.c
index 534e73a24eb4..394396b91630 100644
--- a/drivers/iio/adc/fsl-imx25-gcq.c
+++ b/drivers/iio/adc/fsl-imx25-gcq.c
@@ -282,6 +282,17 @@ static int mx25_gcq_setup_cfgs(struct platform_device *pdev,
return 0;
}
+static void mx25_gcq_reg_disable(void *reg)
+{
+ regulator_disable(reg);
+}
+
+/* Custom handling needed as this driver doesn't own the clock */
+static void mx25_gcq_clk_disable(void *clk)
+{
+ clk_disable_unprepare(clk);
+}
+
static int mx25_gcq_probe(struct platform_device *pdev)
{
struct iio_dev *indio_dev;
@@ -303,10 +314,9 @@ static int mx25_gcq_probe(struct platform_device *pdev)
return PTR_ERR(mem);
priv->regs = devm_regmap_init_mmio(dev, mem, &mx25_gcq_regconfig);
- if (IS_ERR(priv->regs)) {
- dev_err(dev, "Failed to initialize regmap\n");
- return PTR_ERR(priv->regs);
- }
+ if (IS_ERR(priv->regs))
+ return dev_err_probe(dev, PTR_ERR(priv->regs),
+ "Failed to initialize regmap\n");
mutex_init(&priv->lock);
@@ -322,69 +332,44 @@ static int mx25_gcq_probe(struct platform_device *pdev)
ret = regulator_enable(priv->vref[i]);
if (ret)
- goto err_regulator_disable;
+ return ret;
+
+ ret = devm_add_action_or_reset(dev, mx25_gcq_reg_disable,
+ priv->vref[i]);
+ if (ret)
+ return ret;
}
priv->clk = tsadc->clk;
ret = clk_prepare_enable(priv->clk);
- if (ret) {
- dev_err(dev, "Failed to enable clock\n");
- goto err_vref_disable;
- }
+ if (ret)
+ return dev_err_probe(dev, ret, "Failed to enable clock\n");
+
+ ret = devm_add_action_or_reset(dev, mx25_gcq_clk_disable,
+ priv->clk);
+ if (ret)
+ return ret;
ret = platform_get_irq(pdev, 0);
if (ret < 0)
- goto err_clk_unprepare;
+ return ret;
priv->irq = ret;
- ret = request_irq(priv->irq, mx25_gcq_irq, 0, pdev->name, priv);
- if (ret) {
- dev_err(dev, "Failed requesting IRQ\n");
- goto err_clk_unprepare;
- }
+ ret = devm_request_irq(dev, priv->irq, mx25_gcq_irq, 0, pdev->name,
+ priv);
+ if (ret)
+ return dev_err_probe(dev, ret, "Failed requesting IRQ\n");
indio_dev->channels = mx25_gcq_channels;
indio_dev->num_channels = ARRAY_SIZE(mx25_gcq_channels);
indio_dev->info = &mx25_gcq_iio_info;
indio_dev->name = driver_name;
- ret = iio_device_register(indio_dev);
- if (ret) {
- dev_err(dev, "Failed to register iio device\n");
- goto err_irq_free;
- }
-
- platform_set_drvdata(pdev, indio_dev);
+ ret = devm_iio_device_register(dev, indio_dev);
+ if (ret)
+ return dev_err_probe(dev, ret, "Failed to register iio device\n");
return 0;
-
-err_irq_free:
- free_irq(priv->irq, priv);
-err_clk_unprepare:
- clk_disable_unprepare(priv->clk);
-err_vref_disable:
- i = 4;
-err_regulator_disable:
- for (; i-- > 0;) {
- if (priv->vref[i])
- regulator_disable(priv->vref[i]);
- }
- return ret;
-}
-
-static void mx25_gcq_remove(struct platform_device *pdev)
-{
- struct iio_dev *indio_dev = platform_get_drvdata(pdev);
- struct mx25_gcq_priv *priv = iio_priv(indio_dev);
- int i;
-
- iio_device_unregister(indio_dev);
- free_irq(priv->irq, priv);
- clk_disable_unprepare(priv->clk);
- for (i = 4; i-- > 0;) {
- if (priv->vref[i])
- regulator_disable(priv->vref[i]);
- }
}
static const struct of_device_id mx25_gcq_ids[] = {
@@ -399,7 +384,6 @@ static struct platform_driver mx25_gcq_driver = {
.of_match_table = mx25_gcq_ids,
},
.probe = mx25_gcq_probe,
- .remove_new = mx25_gcq_remove,
};
module_platform_driver(mx25_gcq_driver);
--
2.43.2
^ permalink raw reply related [flat|nested] 21+ messages in thread* [PATCH 3/8] iio: adc: ad7124: Switch from of specific to fwnode based property handling
2024-02-18 17:27 [PATCH 0/8] IIO: Convert DT specific handling over to fwnode Jonathan Cameron
2024-02-18 17:27 ` [PATCH 1/8] iio: adc: fsl-imx25-gcq: Switch from of specific handing to fwnode based Jonathan Cameron
2024-02-18 17:27 ` [PATCH 2/8] iio: adc: fsl-imx25-gcq: Use devm_* and dev_err_probe() to simplify probe Jonathan Cameron
@ 2024-02-18 17:27 ` Jonathan Cameron
2024-02-19 9:24 ` Nuno Sá
2024-02-19 11:58 ` Andy Shevchenko
2024-02-18 17:27 ` [PATCH 4/8] iio: adc: ad7292: Switch from of specific to fwnode " Jonathan Cameron
` (5 subsequent siblings)
8 siblings, 2 replies; 21+ messages in thread
From: Jonathan Cameron @ 2024-02-18 17:27 UTC (permalink / raw)
To: linux-iio, Andy Shevchenko
Cc: Lars-Peter Clausen, Michael Hennerich, Nuno Sá,
Alisa-Dariana Roman, Haibo Chen, Sean Nyekjaer, Andreas Klinger,
Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Using the generic firmware data access functions from property.h
provides a number of advantages:
1) Works with different firmware types.
2) Doesn't provide a 'bad' example for new IIO drivers.
3) Lets us use the new _scoped() loops with automatic reference count
cleanup for fwnode_handle
Cc: Lars-Peter Clausen <lars@metafoo.de>
Cc: Michael Hennerich <Michael.Hennerich@analog.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/iio/adc/ad7124.c | 55 +++++++++++++++++-----------------------
1 file changed, 23 insertions(+), 32 deletions(-)
diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
index b9b206fcd748..e7b1d517d3de 100644
--- a/drivers/iio/adc/ad7124.c
+++ b/drivers/iio/adc/ad7124.c
@@ -14,7 +14,8 @@
#include <linux/kernel.h>
#include <linux/kfifo.h>
#include <linux/module.h>
-#include <linux/of.h>
+#include <linux/mod_devicetable.h>
+#include <linux/property.h>
#include <linux/regulator/consumer.h>
#include <linux/spi/spi.h>
@@ -807,22 +808,19 @@ static int ad7124_check_chip_id(struct ad7124_state *st)
return 0;
}
-static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev,
- struct device_node *np)
+static int ad7124_parse_channel_config(struct iio_dev *indio_dev,
+ struct device *dev)
{
struct ad7124_state *st = iio_priv(indio_dev);
struct ad7124_channel_config *cfg;
struct ad7124_channel *channels;
- struct device_node *child;
struct iio_chan_spec *chan;
unsigned int ain[2], channel = 0, tmp;
int ret;
- st->num_channels = of_get_available_child_count(np);
- if (!st->num_channels) {
- dev_err(indio_dev->dev.parent, "no channel children\n");
- return -ENODEV;
- }
+ st->num_channels = device_get_child_node_count(dev);
+ if (!st->num_channels)
+ return dev_err_probe(dev, -ENODEV, "no channel children\n");
chan = devm_kcalloc(indio_dev->dev.parent, st->num_channels,
sizeof(*chan), GFP_KERNEL);
@@ -838,39 +836,38 @@ static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev,
indio_dev->num_channels = st->num_channels;
st->channels = channels;
- for_each_available_child_of_node(np, child) {
+ device_for_each_child_node_scoped(dev, child) {
cfg = &st->channels[channel].cfg;
- ret = of_property_read_u32(child, "reg", &channel);
+ ret = fwnode_property_read_u32(child, "reg", &channel);
if (ret)
- goto err;
+ return ret;
- if (channel >= indio_dev->num_channels) {
- dev_err(indio_dev->dev.parent,
+ if (channel >= indio_dev->num_channels)
+ return dev_err_probe(dev, -EINVAL,
"Channel index >= number of channels\n");
- ret = -EINVAL;
- goto err;
- }
- ret = of_property_read_u32_array(child, "diff-channels",
- ain, 2);
+ ret = fwnode_property_read_u32_array(child, "diff-channels",
+ ain, 2);
if (ret)
- goto err;
+ return ret;
st->channels[channel].nr = channel;
st->channels[channel].ain = AD7124_CHANNEL_AINP(ain[0]) |
AD7124_CHANNEL_AINM(ain[1]);
- cfg->bipolar = of_property_read_bool(child, "bipolar");
+ cfg->bipolar = fwnode_property_read_bool(child, "bipolar");
- ret = of_property_read_u32(child, "adi,reference-select", &tmp);
+ ret = fwnode_property_read_u32(child, "adi,reference-select", &tmp);
if (ret)
cfg->refsel = AD7124_INT_REF;
else
cfg->refsel = tmp;
- cfg->buf_positive = of_property_read_bool(child, "adi,buffered-positive");
- cfg->buf_negative = of_property_read_bool(child, "adi,buffered-negative");
+ cfg->buf_positive =
+ fwnode_property_read_bool(child, "adi,buffered-positive");
+ cfg->buf_negative =
+ fwnode_property_read_bool(child, "adi,buffered-negative");
chan[channel] = ad7124_channel_template;
chan[channel].address = channel;
@@ -880,10 +877,6 @@ static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev,
}
return 0;
-err:
- of_node_put(child);
-
- return ret;
}
static int ad7124_setup(struct ad7124_state *st)
@@ -943,9 +936,7 @@ static int ad7124_probe(struct spi_device *spi)
struct iio_dev *indio_dev;
int i, ret;
- info = of_device_get_match_data(&spi->dev);
- if (!info)
- info = (void *)spi_get_device_id(spi)->driver_data;
+ info = spi_get_device_match_data(spi);
if (!info)
return -ENODEV;
@@ -965,7 +956,7 @@ static int ad7124_probe(struct spi_device *spi)
if (ret < 0)
return ret;
- ret = ad7124_of_parse_channel_config(indio_dev, spi->dev.of_node);
+ ret = ad7124_parse_channel_config(indio_dev, &spi->dev);
if (ret < 0)
return ret;
--
2.43.2
^ permalink raw reply related [flat|nested] 21+ messages in thread* Re: [PATCH 3/8] iio: adc: ad7124: Switch from of specific to fwnode based property handling
2024-02-18 17:27 ` [PATCH 3/8] iio: adc: ad7124: Switch from of specific to fwnode based property handling Jonathan Cameron
@ 2024-02-19 9:24 ` Nuno Sá
2024-02-19 11:59 ` Andy Shevchenko
2024-02-19 11:58 ` Andy Shevchenko
1 sibling, 1 reply; 21+ messages in thread
From: Nuno Sá @ 2024-02-19 9:24 UTC (permalink / raw)
To: Jonathan Cameron, linux-iio, Andy Shevchenko
Cc: Lars-Peter Clausen, Michael Hennerich, Nuno Sá,
Alisa-Dariana Roman, Haibo Chen, Sean Nyekjaer, Andreas Klinger,
Jonathan Cameron
On Sun, 2024-02-18 at 17:27 +0000, Jonathan Cameron wrote:
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> Using the generic firmware data access functions from property.h
> provides a number of advantages:
> 1) Works with different firmware types.
> 2) Doesn't provide a 'bad' example for new IIO drivers.
> 3) Lets us use the new _scoped() loops with automatic reference count
> cleanup for fwnode_handle
>
> Cc: Lars-Peter Clausen <lars@metafoo.de>
> Cc: Michael Hennerich <Michael.Hennerich@analog.com>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
Just one minor nit from me... Still, fell free to add:
Reviewed-by: Nuno Sa <nuno.sa@analog.com>
> drivers/iio/adc/ad7124.c | 55 +++++++++++++++++-----------------------
> 1 file changed, 23 insertions(+), 32 deletions(-)
>
> diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
> index b9b206fcd748..e7b1d517d3de 100644
> --- a/drivers/iio/adc/ad7124.c
> +++ b/drivers/iio/adc/ad7124.c
> @@ -14,7 +14,8 @@
> #include <linux/kernel.h>
> #include <linux/kfifo.h>
> #include <linux/module.h>
> -#include <linux/of.h>
> +#include <linux/mod_devicetable.h>
> +#include <linux/property.h>
> #include <linux/regulator/consumer.h>
> #include <linux/spi/spi.h>
>
> @@ -807,22 +808,19 @@ static int ad7124_check_chip_id(struct ad7124_state *st)
> return 0;
> }
>
> -static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev,
> - struct device_node *np)
> +static int ad7124_parse_channel_config(struct iio_dev *indio_dev,
> + struct device *dev)
> {
> struct ad7124_state *st = iio_priv(indio_dev);
> struct ad7124_channel_config *cfg;
> struct ad7124_channel *channels;
> - struct device_node *child;
> struct iio_chan_spec *chan;
> unsigned int ain[2], channel = 0, tmp;
> int ret;
>
> - st->num_channels = of_get_available_child_count(np);
> - if (!st->num_channels) {
> - dev_err(indio_dev->dev.parent, "no channel children\n");
> - return -ENODEV;
> - }
> + st->num_channels = device_get_child_node_count(dev);
> + if (!st->num_channels)
> + return dev_err_probe(dev, -ENODEV, "no channel children\n");
>
> chan = devm_kcalloc(indio_dev->dev.parent, st->num_channels,
> sizeof(*chan), GFP_KERNEL);
> @@ -838,39 +836,38 @@ static int ad7124_of_parse_channel_config(struct iio_dev
> *indio_dev,
> indio_dev->num_channels = st->num_channels;
> st->channels = channels;
>
> - for_each_available_child_of_node(np, child) {
> + device_for_each_child_node_scoped(dev, child) {
> cfg = &st->channels[channel].cfg;
>
> - ret = of_property_read_u32(child, "reg", &channel);
> + ret = fwnode_property_read_u32(child, "reg", &channel);
> if (ret)
> - goto err;
> + return ret;
>
> - if (channel >= indio_dev->num_channels) {
> - dev_err(indio_dev->dev.parent,
> + if (channel >= indio_dev->num_channels)
> + return dev_err_probe(dev, -EINVAL,
> "Channel index >= number of channels\n");
> - ret = -EINVAL;
> - goto err;
> - }
>
> - ret = of_property_read_u32_array(child, "diff-channels",
> - ain, 2);
> + ret = fwnode_property_read_u32_array(child, "diff-channels",
> + ain, 2);
> if (ret)
> - goto err;
> + return ret;
>
> st->channels[channel].nr = channel;
> st->channels[channel].ain = AD7124_CHANNEL_AINP(ain[0]) |
>
> AD7124_CHANNEL_AINM(ain[1]);
>
> - cfg->bipolar = of_property_read_bool(child, "bipolar");
> + cfg->bipolar = fwnode_property_read_bool(child, "bipolar");
>
> - ret = of_property_read_u32(child, "adi,reference-select",
> &tmp);
> + ret = fwnode_property_read_u32(child, "adi,reference-select",
> &tmp);
> if (ret)
> cfg->refsel = AD7124_INT_REF;
> else
> cfg->refsel = tmp;
>
> - cfg->buf_positive = of_property_read_bool(child,
> "adi,buffered-positive");
> - cfg->buf_negative = of_property_read_bool(child,
> "adi,buffered-negative");
> + cfg->buf_positive =
> + fwnode_property_read_bool(child, "adi,buffered-
> positive");
> + cfg->buf_negative =
> + fwnode_property_read_bool(child, "adi,buffered-
> negative");
I think this is one of those cases where 80col limit hurts readability...
- Nuno Sá
^ permalink raw reply [flat|nested] 21+ messages in thread* Re: [PATCH 3/8] iio: adc: ad7124: Switch from of specific to fwnode based property handling
2024-02-19 9:24 ` Nuno Sá
@ 2024-02-19 11:59 ` Andy Shevchenko
0 siblings, 0 replies; 21+ messages in thread
From: Andy Shevchenko @ 2024-02-19 11:59 UTC (permalink / raw)
To: Nuno Sá
Cc: Jonathan Cameron, linux-iio, Lars-Peter Clausen,
Michael Hennerich, Nuno Sá, Alisa-Dariana Roman, Haibo Chen,
Sean Nyekjaer, Andreas Klinger, Jonathan Cameron
On Mon, Feb 19, 2024 at 10:24:59AM +0100, Nuno Sá wrote:
> On Sun, 2024-02-18 at 17:27 +0000, Jonathan Cameron wrote:
...
> > + cfg->buf_positive =
> > + fwnode_property_read_bool(child, "adi,buffered-
> > positive");
> > + cfg->buf_negative =
> > + fwnode_property_read_bool(child, "adi,buffered-
> > negative");
>
> I think this is one of those cases where 80col limit hurts readability...
I like long lines, but to be honest this is also usual pattern on how to
split long lines. I leave this to you, folks, to solve :-)
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 3/8] iio: adc: ad7124: Switch from of specific to fwnode based property handling
2024-02-18 17:27 ` [PATCH 3/8] iio: adc: ad7124: Switch from of specific to fwnode based property handling Jonathan Cameron
2024-02-19 9:24 ` Nuno Sá
@ 2024-02-19 11:58 ` Andy Shevchenko
2024-02-24 15:19 ` Jonathan Cameron
1 sibling, 1 reply; 21+ messages in thread
From: Andy Shevchenko @ 2024-02-19 11:58 UTC (permalink / raw)
To: Jonathan Cameron
Cc: linux-iio, Lars-Peter Clausen, Michael Hennerich, Nuno Sá,
Alisa-Dariana Roman, Haibo Chen, Sean Nyekjaer, Andreas Klinger,
Jonathan Cameron
On Sun, Feb 18, 2024 at 05:27:26PM +0000, Jonathan Cameron wrote:
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> Using the generic firmware data access functions from property.h
> provides a number of advantages:
> 1) Works with different firmware types.
> 2) Doesn't provide a 'bad' example for new IIO drivers.
> 3) Lets us use the new _scoped() loops with automatic reference count
> cleanup for fwnode_handle
Similar remarks as per other patch series...
...
> struct ad7124_state *st = iio_priv(indio_dev);
> struct ad7124_channel_config *cfg;
> struct ad7124_channel *channels;
> - struct device_node *child;
> struct iio_chan_spec *chan;
> unsigned int ain[2], channel = 0, tmp;
Shouldn't ain be u32?
> int ret;
...
> + ret = fwnode_property_read_u32_array(child, "diff-channels",
> + ain, 2);
ARRAY_SIZE()
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 3/8] iio: adc: ad7124: Switch from of specific to fwnode based property handling
2024-02-19 11:58 ` Andy Shevchenko
@ 2024-02-24 15:19 ` Jonathan Cameron
0 siblings, 0 replies; 21+ messages in thread
From: Jonathan Cameron @ 2024-02-24 15:19 UTC (permalink / raw)
To: Andy Shevchenko
Cc: linux-iio, Lars-Peter Clausen, Michael Hennerich, Nuno Sá,
Alisa-Dariana Roman, Haibo Chen, Sean Nyekjaer, Andreas Klinger,
Jonathan Cameron
On Mon, 19 Feb 2024 13:58:20 +0200
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> On Sun, Feb 18, 2024 at 05:27:26PM +0000, Jonathan Cameron wrote:
> > From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> >
> > Using the generic firmware data access functions from property.h
> > provides a number of advantages:
> > 1) Works with different firmware types.
> > 2) Doesn't provide a 'bad' example for new IIO drivers.
> > 3) Lets us use the new _scoped() loops with automatic reference count
> > cleanup for fwnode_handle
>
> Similar remarks as per other patch series...
>
> ...
>
> > struct ad7124_state *st = iio_priv(indio_dev);
> > struct ad7124_channel_config *cfg;
> > struct ad7124_channel *channels;
> > - struct device_node *child;
> > struct iio_chan_spec *chan;
> > unsigned int ain[2], channel = 0, tmp;
>
> Shouldn't ain be u32?
>
> > int ret;
>
> ...
>
> > + ret = fwnode_property_read_u32_array(child, "diff-channels",
> > + ain, 2);
>
> ARRAY_SIZE()
>
>
Agreed. Nuno or other Analog folk, want to clean these up?
Jonathan
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 4/8] iio: adc: ad7292: Switch from of specific to fwnode property handling
2024-02-18 17:27 [PATCH 0/8] IIO: Convert DT specific handling over to fwnode Jonathan Cameron
` (2 preceding siblings ...)
2024-02-18 17:27 ` [PATCH 3/8] iio: adc: ad7124: Switch from of specific to fwnode based property handling Jonathan Cameron
@ 2024-02-18 17:27 ` Jonathan Cameron
2024-02-19 9:26 ` Nuno Sá
2024-02-18 17:27 ` [PATCH 5/8] iio: adc: ad7192: Convert " Jonathan Cameron
` (4 subsequent siblings)
8 siblings, 1 reply; 21+ messages in thread
From: Jonathan Cameron @ 2024-02-18 17:27 UTC (permalink / raw)
To: linux-iio, Andy Shevchenko
Cc: Lars-Peter Clausen, Michael Hennerich, Nuno Sá,
Alisa-Dariana Roman, Haibo Chen, Sean Nyekjaer, Andreas Klinger,
Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This reduces the wrong of device tree only IIO drivers that might
be copied by converting over this simple case.
Makes use of the new _scoped() handling to automatically release
the fwnode_handle on early exit from the loop.
Cc: Nuno Sá <nuno.sa@analog.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/iio/adc/ad7292.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/drivers/iio/adc/ad7292.c b/drivers/iio/adc/ad7292.c
index cccacec5db6d..6aadd14f459d 100644
--- a/drivers/iio/adc/ad7292.c
+++ b/drivers/iio/adc/ad7292.c
@@ -8,7 +8,8 @@
#include <linux/bitfield.h>
#include <linux/device.h>
#include <linux/module.h>
-#include <linux/of.h>
+#include <linux/mod_devicetable.h>
+#include <linux/property.h>
#include <linux/regulator/consumer.h>
#include <linux/spi/spi.h>
@@ -260,7 +261,6 @@ static int ad7292_probe(struct spi_device *spi)
{
struct ad7292_state *st;
struct iio_dev *indio_dev;
- struct device_node *child;
bool diff_channels = false;
int ret;
@@ -305,12 +305,11 @@ static int ad7292_probe(struct spi_device *spi)
indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->info = &ad7292_info;
- for_each_available_child_of_node(spi->dev.of_node, child) {
- diff_channels = of_property_read_bool(child, "diff-channels");
- if (diff_channels) {
- of_node_put(child);
+ device_for_each_child_node_scoped(&spi->dev, child) {
+ diff_channels = fwnode_property_read_bool(child,
+ "diff-channels");
+ if (diff_channels)
break;
- }
}
if (diff_channels) {
--
2.43.2
^ permalink raw reply related [flat|nested] 21+ messages in thread* Re: [PATCH 4/8] iio: adc: ad7292: Switch from of specific to fwnode property handling
2024-02-18 17:27 ` [PATCH 4/8] iio: adc: ad7292: Switch from of specific to fwnode " Jonathan Cameron
@ 2024-02-19 9:26 ` Nuno Sá
0 siblings, 0 replies; 21+ messages in thread
From: Nuno Sá @ 2024-02-19 9:26 UTC (permalink / raw)
To: Jonathan Cameron, linux-iio, Andy Shevchenko
Cc: Lars-Peter Clausen, Michael Hennerich, Nuno Sá,
Alisa-Dariana Roman, Haibo Chen, Sean Nyekjaer, Andreas Klinger,
Jonathan Cameron
On Sun, 2024-02-18 at 17:27 +0000, Jonathan Cameron wrote:
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> This reduces the wrong of device tree only IIO drivers that might
> be copied by converting over this simple case.
> Makes use of the new _scoped() handling to automatically release
> the fwnode_handle on early exit from the loop.
>
> Cc: Nuno Sá <nuno.sa@analog.com>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
Reviewed-by: Nuno Sa <nuno.sa@analog.com>
> drivers/iio/adc/ad7292.c | 13 ++++++-------
> 1 file changed, 6 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/iio/adc/ad7292.c b/drivers/iio/adc/ad7292.c
> index cccacec5db6d..6aadd14f459d 100644
> --- a/drivers/iio/adc/ad7292.c
> +++ b/drivers/iio/adc/ad7292.c
> @@ -8,7 +8,8 @@
> #include <linux/bitfield.h>
> #include <linux/device.h>
> #include <linux/module.h>
> -#include <linux/of.h>
> +#include <linux/mod_devicetable.h>
> +#include <linux/property.h>
> #include <linux/regulator/consumer.h>
> #include <linux/spi/spi.h>
>
> @@ -260,7 +261,6 @@ static int ad7292_probe(struct spi_device *spi)
> {
> struct ad7292_state *st;
> struct iio_dev *indio_dev;
> - struct device_node *child;
> bool diff_channels = false;
> int ret;
>
> @@ -305,12 +305,11 @@ static int ad7292_probe(struct spi_device *spi)
> indio_dev->modes = INDIO_DIRECT_MODE;
> indio_dev->info = &ad7292_info;
>
> - for_each_available_child_of_node(spi->dev.of_node, child) {
> - diff_channels = of_property_read_bool(child, "diff-
> channels");
> - if (diff_channels) {
> - of_node_put(child);
> + device_for_each_child_node_scoped(&spi->dev, child) {
> + diff_channels = fwnode_property_read_bool(child,
> + "diff-channels");
> + if (diff_channels)
> break;
> - }
> }
>
> if (diff_channels) {
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 5/8] iio: adc: ad7192: Convert from of specific to fwnode property handling
2024-02-18 17:27 [PATCH 0/8] IIO: Convert DT specific handling over to fwnode Jonathan Cameron
` (3 preceding siblings ...)
2024-02-18 17:27 ` [PATCH 4/8] iio: adc: ad7292: Switch from of specific to fwnode " Jonathan Cameron
@ 2024-02-18 17:27 ` Jonathan Cameron
2024-02-19 9:30 ` Nuno Sá
2024-02-19 12:02 ` Andy Shevchenko
2024-02-18 17:27 ` [PATCH 6/8] iio: accel: mma8452: Switch " Jonathan Cameron
` (3 subsequent siblings)
8 siblings, 2 replies; 21+ messages in thread
From: Jonathan Cameron @ 2024-02-18 17:27 UTC (permalink / raw)
To: linux-iio, Andy Shevchenko
Cc: Lars-Peter Clausen, Michael Hennerich, Nuno Sá,
Alisa-Dariana Roman, Haibo Chen, Sean Nyekjaer, Andreas Klinger,
Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Enables use of with other firmwware types.
Removes a case of device tree specific handlers that might get copied
into new drivers.
Cc: Alisa-Dariana Roman <alisa.roman@analog.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/iio/adc/ad7192.c | 38 +++++++++++++++++++-------------------
1 file changed, 19 insertions(+), 19 deletions(-)
diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c
index adc3cbe92d6e..7bcc7e2aa2a2 100644
--- a/drivers/iio/adc/ad7192.c
+++ b/drivers/iio/adc/ad7192.c
@@ -17,7 +17,9 @@
#include <linux/err.h>
#include <linux/sched.h>
#include <linux/delay.h>
-#include <linux/of.h>
+#include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/property.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
@@ -364,19 +366,19 @@ static inline bool ad7192_valid_external_frequency(u32 freq)
freq <= AD7192_EXT_FREQ_MHZ_MAX);
}
-static int ad7192_of_clock_select(struct ad7192_state *st)
+static int ad7192_clock_select(struct ad7192_state *st)
{
- struct device_node *np = st->sd.spi->dev.of_node;
+ struct device *dev = &st->sd.spi->dev;
unsigned int clock_sel;
clock_sel = AD7192_CLK_INT;
/* use internal clock */
if (!st->mclk) {
- if (of_property_read_bool(np, "adi,int-clock-output-enable"))
+ if (device_property_read_bool(dev, "adi,int-clock-output-enable"))
clock_sel = AD7192_CLK_INT_CO;
} else {
- if (of_property_read_bool(np, "adi,clock-xtal"))
+ if (device_property_read_bool(dev, "adi,clock-xtal"))
clock_sel = AD7192_CLK_EXT_MCLK1_2;
else
clock_sel = AD7192_CLK_EXT_MCLK2;
@@ -385,7 +387,7 @@ static int ad7192_of_clock_select(struct ad7192_state *st)
return clock_sel;
}
-static int ad7192_setup(struct iio_dev *indio_dev, struct device_node *np)
+static int ad7192_setup(struct iio_dev *indio_dev, struct device *dev)
{
struct ad7192_state *st = iio_priv(indio_dev);
bool rej60_en, refin2_en;
@@ -407,7 +409,7 @@ static int ad7192_setup(struct iio_dev *indio_dev, struct device_node *np)
id = FIELD_GET(AD7192_ID_MASK, id);
if (id != st->chip_info->chip_id)
- dev_warn(&st->sd.spi->dev, "device ID query failed (0x%X != 0x%X)\n",
+ dev_warn(dev, "device ID query failed (0x%X != 0x%X)\n",
id, st->chip_info->chip_id);
st->mode = FIELD_PREP(AD7192_MODE_SEL_MASK, AD7192_MODE_IDLE) |
@@ -416,30 +418,30 @@ static int ad7192_setup(struct iio_dev *indio_dev, struct device_node *np)
st->conf = FIELD_PREP(AD7192_CONF_GAIN_MASK, 0);
- rej60_en = of_property_read_bool(np, "adi,rejection-60-Hz-enable");
+ rej60_en = device_property_read_bool(dev, "adi,rejection-60-Hz-enable");
if (rej60_en)
st->mode |= AD7192_MODE_REJ60;
- refin2_en = of_property_read_bool(np, "adi,refin2-pins-enable");
+ refin2_en = device_property_read_bool(dev, "adi,refin2-pins-enable");
if (refin2_en && st->chip_info->chip_id != CHIPID_AD7195)
st->conf |= AD7192_CONF_REFSEL;
st->conf &= ~AD7192_CONF_CHOP;
- buf_en = of_property_read_bool(np, "adi,buffer-enable");
+ buf_en = device_property_read_bool(dev, "adi,buffer-enable");
if (buf_en)
st->conf |= AD7192_CONF_BUF;
- bipolar = of_property_read_bool(np, "bipolar");
+ bipolar = device_property_read_bool(dev, "bipolar");
if (!bipolar)
st->conf |= AD7192_CONF_UNIPOLAR;
- burnout_curr_en = of_property_read_bool(np,
- "adi,burnout-currents-enable");
+ burnout_curr_en = device_property_read_bool(dev,
+ "adi,burnout-currents-enable");
if (burnout_curr_en && buf_en) {
st->conf |= AD7192_CONF_BURN;
} else if (burnout_curr_en) {
- dev_warn(&st->sd.spi->dev,
+ dev_warn(dev,
"Can't enable burnout currents: see CHOP or buffer\n");
}
@@ -1117,9 +1119,7 @@ static int ad7192_probe(struct spi_device *spi)
}
st->int_vref_mv = ret / 1000;
- st->chip_info = of_device_get_match_data(&spi->dev);
- if (!st->chip_info)
- st->chip_info = (void *)spi_get_device_id(spi)->driver_data;
+ st->chip_info = spi_get_device_match_data(spi);
indio_dev->name = st->chip_info->name;
indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->channels = st->chip_info->channels;
@@ -1140,7 +1140,7 @@ static int ad7192_probe(struct spi_device *spi)
if (IS_ERR(st->mclk))
return PTR_ERR(st->mclk);
- st->clock_sel = ad7192_of_clock_select(st);
+ st->clock_sel = ad7192_clock_select(st);
if (st->clock_sel == AD7192_CLK_EXT_MCLK1_2 ||
st->clock_sel == AD7192_CLK_EXT_MCLK2) {
@@ -1152,7 +1152,7 @@ static int ad7192_probe(struct spi_device *spi)
}
}
- ret = ad7192_setup(indio_dev, spi->dev.of_node);
+ ret = ad7192_setup(indio_dev, &spi->dev);
if (ret)
return ret;
--
2.43.2
^ permalink raw reply related [flat|nested] 21+ messages in thread* Re: [PATCH 5/8] iio: adc: ad7192: Convert from of specific to fwnode property handling
2024-02-18 17:27 ` [PATCH 5/8] iio: adc: ad7192: Convert " Jonathan Cameron
@ 2024-02-19 9:30 ` Nuno Sá
2024-02-19 12:02 ` Andy Shevchenko
1 sibling, 0 replies; 21+ messages in thread
From: Nuno Sá @ 2024-02-19 9:30 UTC (permalink / raw)
To: Jonathan Cameron, linux-iio, Andy Shevchenko
Cc: Lars-Peter Clausen, Michael Hennerich, Nuno Sá,
Alisa-Dariana Roman, Haibo Chen, Sean Nyekjaer, Andreas Klinger,
Jonathan Cameron
On Sun, 2024-02-18 at 17:27 +0000, Jonathan Cameron wrote:
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> Enables use of with other firmwware types.
> Removes a case of device tree specific handlers that might get copied
> into new drivers.
>
> Cc: Alisa-Dariana Roman <alisa.roman@analog.com>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
One minor comment. Still:
Reviewed-by: Nuno Sa <nuno.sa@analog.com>
> drivers/iio/adc/ad7192.c | 38 +++++++++++++++++++-------------------
> 1 file changed, 19 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c
> index adc3cbe92d6e..7bcc7e2aa2a2 100644
> --- a/drivers/iio/adc/ad7192.c
> +++ b/drivers/iio/adc/ad7192.c
> @@ -17,7 +17,9 @@
> #include <linux/err.h>
> #include <linux/sched.h>
> #include <linux/delay.h>
> -#include <linux/of.h>
> +#include <linux/module.h>
Seems unrelated... maybe mentioning it in the commit message would make sense.
- Nuno Sá
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 5/8] iio: adc: ad7192: Convert from of specific to fwnode property handling
2024-02-18 17:27 ` [PATCH 5/8] iio: adc: ad7192: Convert " Jonathan Cameron
2024-02-19 9:30 ` Nuno Sá
@ 2024-02-19 12:02 ` Andy Shevchenko
1 sibling, 0 replies; 21+ messages in thread
From: Andy Shevchenko @ 2024-02-19 12:02 UTC (permalink / raw)
To: Jonathan Cameron
Cc: linux-iio, Lars-Peter Clausen, Michael Hennerich, Nuno Sá,
Alisa-Dariana Roman, Haibo Chen, Sean Nyekjaer, Andreas Klinger,
Jonathan Cameron
On Sun, Feb 18, 2024 at 05:27:28PM +0000, Jonathan Cameron wrote:
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> Enables use of with other firmwware types.
> Removes a case of device tree specific handlers that might get copied
> into new drivers.
...
> - dev_warn(&st->sd.spi->dev, "device ID query failed (0x%X != 0x%X)\n",
> + dev_warn(dev, "device ID query failed (0x%X != 0x%X)\n",
> id, st->chip_info->chip_id);
Now id can be moved to the previous line (but it's up to you as you may argue
that this is the logical split).
...
> - burnout_curr_en = of_property_read_bool(np,
> - "adi,burnout-currents-enable");
> + burnout_curr_en = device_property_read_bool(dev,
> + "adi,burnout-currents-enable");
Same pattern as in the other patch?
burnout_curr_en =
device_property_read_bool(dev, "adi,burnout-currents-enable");
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 6/8] iio: accel: mma8452: Switch from of specific to fwnode property handling.
2024-02-18 17:27 [PATCH 0/8] IIO: Convert DT specific handling over to fwnode Jonathan Cameron
` (4 preceding siblings ...)
2024-02-18 17:27 ` [PATCH 5/8] iio: adc: ad7192: Convert " Jonathan Cameron
@ 2024-02-18 17:27 ` Jonathan Cameron
2024-02-23 11:10 ` Bough Chen
2024-02-18 17:27 ` [PATCH 7/8] iio: accel: fxls8962af: Switch from of specific to fwnode based properties Jonathan Cameron
` (2 subsequent siblings)
8 siblings, 1 reply; 21+ messages in thread
From: Jonathan Cameron @ 2024-02-18 17:27 UTC (permalink / raw)
To: linux-iio, Andy Shevchenko
Cc: Lars-Peter Clausen, Michael Hennerich, Nuno Sá,
Alisa-Dariana Roman, Haibo Chen, Sean Nyekjaer, Andreas Klinger,
Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
In this case only use was to get an irq so easily converted.
Also include linux/mod_devicetable.h for struct of_device_id definition.
Using the generic firmware handling, this driver may be used with other
firmware types. This also removes an example that might get copied into
other drivers leaving them unable to be used with alternative firmware
types.
Cc: Haibo Chen <haibo.chen@nxp.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/iio/accel/mma8452.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
index d3fd0318e47b..62e6369e2269 100644
--- a/drivers/iio/accel/mma8452.c
+++ b/drivers/iio/accel/mma8452.c
@@ -19,6 +19,8 @@
*/
#include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/property.h>
#include <linux/i2c.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
@@ -28,8 +30,6 @@
#include <linux/iio/triggered_buffer.h>
#include <linux/iio/events.h>
#include <linux/delay.h>
-#include <linux/of.h>
-#include <linux/of_irq.h>
#include <linux/pm_runtime.h>
#include <linux/regulator/consumer.h>
@@ -1642,7 +1642,7 @@ static int mma8452_probe(struct i2c_client *client)
if (client->irq) {
int irq2;
- irq2 = of_irq_get_byname(client->dev.of_node, "INT2");
+ irq2 = fwnode_irq_get_byname(dev_fwnode(&client->dev), "INT2");
if (irq2 == client->irq) {
dev_dbg(&client->dev, "using interrupt line INT2\n");
--
2.43.2
^ permalink raw reply related [flat|nested] 21+ messages in thread* RE: [PATCH 6/8] iio: accel: mma8452: Switch from of specific to fwnode property handling.
2024-02-18 17:27 ` [PATCH 6/8] iio: accel: mma8452: Switch " Jonathan Cameron
@ 2024-02-23 11:10 ` Bough Chen
0 siblings, 0 replies; 21+ messages in thread
From: Bough Chen @ 2024-02-23 11:10 UTC (permalink / raw)
To: Jonathan Cameron, linux-iio@vger.kernel.org, Andy Shevchenko
Cc: Lars-Peter Clausen, Michael Hennerich, Nuno Sá,
Alisa-Dariana Roman, Sean Nyekjaer, Andreas Klinger,
Jonathan Cameron
> -----Original Message-----
> From: Jonathan Cameron <jic23@kernel.org>
> Sent: 2024年2月19日 1:27
> To: linux-iio@vger.kernel.org; Andy Shevchenko
> <andriy.shevchenko@linux.intel.com>
> Cc: Lars-Peter Clausen <lars@metafoo.de>; Michael Hennerich
> <Michael.Hennerich@analog.com>; Nuno Sá <nuno.sa@analog.com>;
> Alisa-Dariana Roman <alisa.roman@analog.com>; Bough Chen
> <haibo.chen@nxp.com>; Sean Nyekjaer <sean@geanix.com>; Andreas Klinger
> <ak@it-klinger.de>; Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Subject: [PATCH 6/8] iio: accel: mma8452: Switch from of specific to fwnode
> property handling.
>
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> In this case only use was to get an irq so easily converted.
> Also include linux/mod_devicetable.h for struct of_device_id definition.
>
> Using the generic firmware handling, this driver may be used with other
> firmware types. This also removes an example that might get copied into other
> drivers leaving them unable to be used with alternative firmware types.
>
> Cc: Haibo Chen <haibo.chen@nxp.com>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-and-tested-by: Haibo Chen <haibo.chen@nxp.com>
> ---
> drivers/iio/accel/mma8452.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c index
> d3fd0318e47b..62e6369e2269 100644
> --- a/drivers/iio/accel/mma8452.c
> +++ b/drivers/iio/accel/mma8452.c
> @@ -19,6 +19,8 @@
> */
>
> #include <linux/module.h>
> +#include <linux/mod_devicetable.h>
> +#include <linux/property.h>
> #include <linux/i2c.h>
> #include <linux/iio/iio.h>
> #include <linux/iio/sysfs.h>
> @@ -28,8 +30,6 @@
> #include <linux/iio/triggered_buffer.h> #include <linux/iio/events.h>
> #include <linux/delay.h> -#include <linux/of.h> -#include <linux/of_irq.h>
> #include <linux/pm_runtime.h> #include <linux/regulator/consumer.h>
>
> @@ -1642,7 +1642,7 @@ static int mma8452_probe(struct i2c_client *client)
> if (client->irq) {
> int irq2;
>
> - irq2 = of_irq_get_byname(client->dev.of_node, "INT2");
> + irq2 = fwnode_irq_get_byname(dev_fwnode(&client->dev), "INT2");
>
> if (irq2 == client->irq) {
> dev_dbg(&client->dev, "using interrupt line INT2\n");
> --
> 2.43.2
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 7/8] iio: accel: fxls8962af: Switch from of specific to fwnode based properties.
2024-02-18 17:27 [PATCH 0/8] IIO: Convert DT specific handling over to fwnode Jonathan Cameron
` (5 preceding siblings ...)
2024-02-18 17:27 ` [PATCH 6/8] iio: accel: mma8452: Switch " Jonathan Cameron
@ 2024-02-18 17:27 ` Jonathan Cameron
2024-02-19 12:03 ` Andy Shevchenko
2024-02-18 17:27 ` [PATCH 8/8] iio: adc: hx711: Switch from of specific to fwnode property handling Jonathan Cameron
2024-02-19 12:06 ` [PATCH 0/8] IIO: Convert DT specific handling over to fwnode Andy Shevchenko
8 siblings, 1 reply; 21+ messages in thread
From: Jonathan Cameron @ 2024-02-18 17:27 UTC (permalink / raw)
To: linux-iio, Andy Shevchenko
Cc: Lars-Peter Clausen, Michael Hennerich, Nuno Sá,
Alisa-Dariana Roman, Haibo Chen, Sean Nyekjaer, Andreas Klinger,
Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Only the irq was retrieved using an of specific accessor. Switch to the
fwnode equivalent and adjust headers. Also include missing mod_devicetable.h
and irq.h.
Cc: Sean Nyekjaer <sean@geanix.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/iio/accel/fxls8962af-core.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/accel/fxls8962af-core.c b/drivers/iio/accel/fxls8962af-core.c
index be8a15cb945f..4fbc01bda62e 100644
--- a/drivers/iio/accel/fxls8962af-core.c
+++ b/drivers/iio/accel/fxls8962af-core.c
@@ -15,9 +15,11 @@
#include <linux/bits.h>
#include <linux/bitfield.h>
#include <linux/i2c.h>
+#include <linux/irq.h>
#include <linux/module.h>
-#include <linux/of_irq.h>
+#include <linux/mod_devicetable.h>
#include <linux/pm_runtime.h>
+#include <linux/property.h>
#include <linux/regulator/consumer.h>
#include <linux/regmap.h>
@@ -1062,12 +1064,12 @@ static void fxls8962af_pm_disable(void *dev_ptr)
fxls8962af_standby(iio_priv(indio_dev));
}
-static void fxls8962af_get_irq(struct device_node *of_node,
+static void fxls8962af_get_irq(struct device *dev,
enum fxls8962af_int_pin *pin)
{
int irq;
- irq = of_irq_get_byname(of_node, "INT2");
+ irq = fwnode_irq_get_byname(dev_fwnode(dev), "INT2");
if (irq > 0) {
*pin = FXLS8962AF_PIN_INT2;
return;
@@ -1086,7 +1088,7 @@ static int fxls8962af_irq_setup(struct iio_dev *indio_dev, int irq)
u8 int_pin_sel;
int ret;
- fxls8962af_get_irq(dev->of_node, &int_pin);
+ fxls8962af_get_irq(dev, &int_pin);
switch (int_pin) {
case FXLS8962AF_PIN_INT1:
int_pin_sel = FXLS8962AF_INT_PIN_SEL_INT1;
--
2.43.2
^ permalink raw reply related [flat|nested] 21+ messages in thread* Re: [PATCH 7/8] iio: accel: fxls8962af: Switch from of specific to fwnode based properties.
2024-02-18 17:27 ` [PATCH 7/8] iio: accel: fxls8962af: Switch from of specific to fwnode based properties Jonathan Cameron
@ 2024-02-19 12:03 ` Andy Shevchenko
0 siblings, 0 replies; 21+ messages in thread
From: Andy Shevchenko @ 2024-02-19 12:03 UTC (permalink / raw)
To: Jonathan Cameron
Cc: linux-iio, Lars-Peter Clausen, Michael Hennerich, Nuno Sá,
Alisa-Dariana Roman, Haibo Chen, Sean Nyekjaer, Andreas Klinger,
Jonathan Cameron
On Sun, Feb 18, 2024 at 05:27:30PM +0000, Jonathan Cameron wrote:
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> Only the irq was retrieved using an of specific accessor. Switch to the
> fwnode equivalent and adjust headers. Also include missing mod_devicetable.h
> and irq.h.
...
> -static void fxls8962af_get_irq(struct device_node *of_node,
> +static void fxls8962af_get_irq(struct device *dev,
> enum fxls8962af_int_pin *pin)
Now it seems perfectly 80 on one line.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 8/8] iio: adc: hx711: Switch from of specific to fwnode property handling.
2024-02-18 17:27 [PATCH 0/8] IIO: Convert DT specific handling over to fwnode Jonathan Cameron
` (6 preceding siblings ...)
2024-02-18 17:27 ` [PATCH 7/8] iio: accel: fxls8962af: Switch from of specific to fwnode based properties Jonathan Cameron
@ 2024-02-18 17:27 ` Jonathan Cameron
2024-02-19 12:06 ` Andy Shevchenko
2024-02-19 12:06 ` [PATCH 0/8] IIO: Convert DT specific handling over to fwnode Andy Shevchenko
8 siblings, 1 reply; 21+ messages in thread
From: Jonathan Cameron @ 2024-02-18 17:27 UTC (permalink / raw)
To: linux-iio, Andy Shevchenko
Cc: Lars-Peter Clausen, Michael Hennerich, Nuno Sá,
Alisa-Dariana Roman, Haibo Chen, Sean Nyekjaer, Andreas Klinger,
Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Allows driver to be used with other firmware types and removes an
example that might be copied into new IIO drivers.
Cc: Andreas Klinger <ak@it-klinger.de>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
drivers/iio/adc/hx711.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c
index c80c55fb8c6c..fef97c1d226a 100644
--- a/drivers/iio/adc/hx711.c
+++ b/drivers/iio/adc/hx711.c
@@ -7,7 +7,7 @@
#include <linux/err.h>
#include <linux/kernel.h>
#include <linux/module.h>
-#include <linux/of.h>
+#include <linux/mod_devicetable.h>
#include <linux/platform_device.h>
#include <linux/property.h>
#include <linux/slab.h>
@@ -459,7 +459,6 @@ static const struct iio_chan_spec hx711_chan_spec[] = {
static int hx711_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
- struct device_node *np = dev->of_node;
struct hx711_data *hx711_data;
struct iio_dev *indio_dev;
int ret;
@@ -533,7 +532,7 @@ static int hx711_probe(struct platform_device *pdev)
hx711_data->gain_chan_a = 128;
hx711_data->clock_frequency = 400000;
- ret = of_property_read_u32(np, "clock-frequency",
+ ret = device_property_read_u32(&pdev->dev, "clock-frequency",
&hx711_data->clock_frequency);
/*
--
2.43.2
^ permalink raw reply related [flat|nested] 21+ messages in thread* Re: [PATCH 8/8] iio: adc: hx711: Switch from of specific to fwnode property handling.
2024-02-18 17:27 ` [PATCH 8/8] iio: adc: hx711: Switch from of specific to fwnode property handling Jonathan Cameron
@ 2024-02-19 12:06 ` Andy Shevchenko
0 siblings, 0 replies; 21+ messages in thread
From: Andy Shevchenko @ 2024-02-19 12:06 UTC (permalink / raw)
To: Jonathan Cameron
Cc: linux-iio, Lars-Peter Clausen, Michael Hennerich, Nuno Sá,
Alisa-Dariana Roman, Haibo Chen, Sean Nyekjaer, Andreas Klinger,
Jonathan Cameron
On Sun, Feb 18, 2024 at 05:27:31PM +0000, Jonathan Cameron wrote:
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> Allows driver to be used with other firmware types and removes an
> example that might be copied into new IIO drivers.
...
> struct device *dev = &pdev->dev;
...
> - ret = of_property_read_u32(np, "clock-frequency",
> + ret = device_property_read_u32(&pdev->dev, "clock-frequency",
> &hx711_data->clock_frequency);
You have dev, use it!
ret = device_property_read_u32(dev, "clock-frequency",
&hx711_data->clock_frequency);
Also seems the indentation of the second line is broken.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 0/8] IIO: Convert DT specific handling over to fwnode
2024-02-18 17:27 [PATCH 0/8] IIO: Convert DT specific handling over to fwnode Jonathan Cameron
` (7 preceding siblings ...)
2024-02-18 17:27 ` [PATCH 8/8] iio: adc: hx711: Switch from of specific to fwnode property handling Jonathan Cameron
@ 2024-02-19 12:06 ` Andy Shevchenko
2024-02-24 15:31 ` Jonathan Cameron
8 siblings, 1 reply; 21+ messages in thread
From: Andy Shevchenko @ 2024-02-19 12:06 UTC (permalink / raw)
To: Jonathan Cameron
Cc: linux-iio, Lars-Peter Clausen, Michael Hennerich, Nuno Sá,
Alisa-Dariana Roman, Haibo Chen, Sean Nyekjaer, Andreas Klinger,
Jonathan Cameron
On Sun, Feb 18, 2024 at 05:27:23PM +0000, Jonathan Cameron wrote:
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> Andy pointed out that some of the drivers I was using as examples for
> "[PATCH 0/8] of: automate of_node_put() - new approach to loops."
> should be converted over to fwnode / property.h based handling anyway
> at which point the device_for_each_child_node_scoped() handler could be
> used instead. He correctly observed that it made more sense to make this
> transition directly than to improve the device tree specific handling.
>
> So this series does that and also some of the other drivers that were still
> using device tree specific handling. Note the rcar-adc remains DT
> specific due to it directly handling maching against of_device_id tables.
> It probably doesn't make sense to move that custom handling over to
> fwnode.
>
> I included one devm_ cleanup patch in here as I was touching the
> driver anyway.
>
> Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Thank you!
I have some minor comments, but in general I like this series,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 21+ messages in thread* Re: [PATCH 0/8] IIO: Convert DT specific handling over to fwnode
2024-02-19 12:06 ` [PATCH 0/8] IIO: Convert DT specific handling over to fwnode Andy Shevchenko
@ 2024-02-24 15:31 ` Jonathan Cameron
0 siblings, 0 replies; 21+ messages in thread
From: Jonathan Cameron @ 2024-02-24 15:31 UTC (permalink / raw)
To: Andy Shevchenko
Cc: linux-iio, Lars-Peter Clausen, Michael Hennerich, Nuno Sá,
Alisa-Dariana Roman, Haibo Chen, Sean Nyekjaer, Andreas Klinger,
Jonathan Cameron
On Mon, 19 Feb 2024 14:06:54 +0200
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> On Sun, Feb 18, 2024 at 05:27:23PM +0000, Jonathan Cameron wrote:
> > From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> >
> > Andy pointed out that some of the drivers I was using as examples for
> > "[PATCH 0/8] of: automate of_node_put() - new approach to loops."
> > should be converted over to fwnode / property.h based handling anyway
> > at which point the device_for_each_child_node_scoped() handler could be
> > used instead. He correctly observed that it made more sense to make this
> > transition directly than to improve the device tree specific handling.
> >
> > So this series does that and also some of the other drivers that were still
> > using device tree specific handling. Note the rcar-adc remains DT
> > specific due to it directly handling maching against of_device_id tables.
> > It probably doesn't make sense to move that custom handling over to
> > fwnode.
> >
> > I included one devm_ cleanup patch in here as I was touching the
> > driver anyway.
> >
> > Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>
> Thank you!
> I have some minor comments, but in general I like this series,
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>
Applied with various suggestions acted on (even if that is asking
Nuno to send a patch to tidy them up at a later date :)
Applied to the togreg branch of iio.git and pushed out as testing
to see what I missed.
Thanks,
Jonathan
^ permalink raw reply [flat|nested] 21+ messages in thread