IIO: Convert DT specific handling over to fwnode
Subsystems (6)
Jonathan Cameron
maintainercover IIO: Convert DT specific handling over to fwnode
From: Jonathan Cameron <[email protected]>
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.
Depends on:
[PATCH v4 00/15] device property / IIO: Use cleanup.h magic for fwnode_handle_put() handling.
https://lore.kernel.org/linux-iio/[email protected]/T/#t
Jonathan Cameron (8):
iio: adc: fsl-imx25-gcq: Switch from of specific handing to fwnode
based.
iio: adc: fsl-imx25-gcq: Use devm_* and dev_err_probe() to simplify
probe
iio: adc: ad7124: Switch from of specific to fwnode based property
handling
iio: adc: ad7292: Switch from of specific to fwnode property handling
iio: adc: ad7192: Convert from of specific to fwnode property handling
iio: accel: mma8452: Switch from of specific to fwnode property
handling.
iio: accel: fxls8962af: Switch from of specific to fwnode based
properties.
iio: adc: hx711: Switch from of specific to fwnode property handling.
drivers/iio/accel/fxls8962af-core.c | 10 +- drivers/iio/accel/mma8452.c | 6 +- drivers/iio/adc/ad7124.c | 55 +++++------ drivers/iio/adc/ad7192.c | 38 ++++---- drivers/iio/adc/ad7292.c | 13 ++- drivers/iio/adc/fsl-imx25-gcq.c | 140 +++++++++++----------------- drivers/iio/adc/hx711.c | 5 +- 7 files changed, 115 insertions(+), 152 deletions(-)
Signature · 1 line
2.43.2
Jonathan Cameron
maintainerPATCH 1/8 iio: adc: fsl-imx25-gcq: Switch from of specific handing to fwnode based.
From: Jonathan Cameron <[email protected]>
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
--- drivers/iio/adc/fsl-imx25-gcq.c | 54 +++++++++++++-------------------- 1 file changed, 21 insertions(+), 33 deletions(-)
drivers/iio/adc/fsl-imx25-gcq.c +21 -33
@@ -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 |
Signature · 1 line
2.43.2
Jonathan Cameron
maintainerPATCH 2/8 iio: adc: fsl-imx25-gcq: Use devm_* and dev_err_probe() to simplify probe
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/adc/fsl-imx25-gcq.c | 86 ++++++++++++++------------------- 1 file changed, 35 insertions(+), 51 deletions(-)
drivers/iio/adc/fsl-imx25-gcq.c +35 -51
@@ -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);
Signature · 1 line
2.43.2
Jonathan Cameron
maintainerPATCH 3/8 iio: adc: ad7124: Switch from of specific to fwnode based property handling
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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
--- drivers/iio/adc/ad7124.c | 55 +++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 32 deletions(-)
drivers/iio/adc/ad7124.c +23 -32
@@ -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;
Signature · 1 line
2.43.2
Jonathan Cameron
maintainerPATCH 4/8 iio: adc: ad7292: Switch from of specific to fwnode property handling
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/adc/ad7292.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/iio/adc/ad7292.c +6 -7
@@ -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) {
Signature · 1 line
2.43.2
Jonathan Cameron
maintainerPATCH 5/8 iio: adc: ad7192: Convert from of specific to fwnode property handling
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
Enables use of with other firmwware types.
Removes a case of device tree specific handlers that might get copied into new drivers.
--- drivers/iio/adc/ad7192.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-)
drivers/iio/adc/ad7192.c +19 -19
@@ -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;
Signature · 1 line
2.43.2
Jonathan Cameron
maintainerPATCH 6/8 iio: accel: mma8452: Switch from of specific to fwnode property handling.
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/accel/mma8452.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iio/accel/mma8452.c +3 -3
@@ -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" );
Signature · 1 line
2.43.2
Jonathan Cameron
maintainerPATCH 7/8 iio: accel: fxls8962af: Switch from of specific to fwnode based properties.
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
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.
--- drivers/iio/accel/fxls8962af-core.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/iio/accel/fxls8962af-core.c +6 -4
@@ -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 ;
Signature · 1 line
2.43.2
Jonathan Cameron
maintainerPATCH 8/8 iio: adc: hx711: Switch from of specific to fwnode property handling.
In reply to Jonathan CameronFrom: Jonathan Cameron <[email protected]>
Allows driver to be used with other firmware types and removes an example that might be copied into new IIO drivers.
--- drivers/iio/adc/hx711.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/iio/adc/hx711.c +2 -3
@@ -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);/*
Signature · 1 line
2.43.2
Re: [PATCH 3/8] iio: adc: ad7124: Switch from of specific to fwnode based property handling
In reply to Jonathan CameronQuoted 9 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
Using the generic firmware data access functions from
property.hprovides 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 forfwnode_handle
Quoted 4 lines
Cc Lars-Peter Clausen <[email protected]>Cc Michael Hennerich <[email protected]>Signed-off-by Jonathan Cameron <[email protected]>---
Just one minor nit from me... Still, fell free to add:
Quoted 103 lines
drivers/iio/adc/ad7124.c | 55 +++++++++++++++++-----------------------
1 file changed, 23 insertions(+), 32 deletions(-)drivers/iio/adc/ad7124.c +2
-1@@ -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>drivers/iio/adc/ad7124.c +0
-0@@ -807,22 +808,19 @@ static int ad7124_check_chip_id(struct ad7124_state *st) return 0; }drivers/iio/adc/ad7124.c +2
-2-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){
structad7124_state*st =iio_priv(indio_dev); structad7124_channel_config*cfg; structad7124_channel*channels;drivers/iio/adc/ad7124.c +0
-1-struct device_node *child;struct
iio_chan_spec*chan;
unsigned int ain[2], channel = 0, tmp;
int ret;drivers/iio/adc/ad7124.c +3
-5- 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);drivers/iio/adc/ad7124.c +0
-0@@ -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;drivers/iio/adc/ad7124.c +1
-1-for_each_available_child_of_node (np, child) { +device_for_each_child_node_scoped (dev, child) {cfg = &st->channels[channel].cfg;
drivers/iio/adc/ad7124.c +1
-1- ret =of_property_read_u32 (child,"reg" , &channel); + ret =fwnode_property_read_u32 (child,"reg" , &channel);if (ret)
drivers/iio/adc/ad7124.c +1
-1- goto err; +return ret;drivers/iio/adc/ad7124.c +2
-2-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");
drivers/iio/adc/ad7124.c +0
-3- ret = -EINVAL ; - goto err; - }drivers/iio/adc/ad7124.c +2
-2- ret =of_property_read_u32_array (child,"diff-channels" , - ain,2 ); + ret =fwnode_property_read_u32_array (child,"diff-channels" , + ain, 2);if (ret)
drivers/iio/adc/ad7124.c +1
-1- goto err; +return ret;
st->channels[channel].nr = channel; st->channels[channel].ain =AD7124_CHANNEL_AINP(ain[0])|AD7124_CHANNEL_AINM(ain[1]);drivers/iio/adc/ad7124.c +1
-1- cfg->bipolar =of_property_read_bool (child,"bipolar" ); + cfg->bipolar =fwnode_property_read_bool (child,"bipolar" );drivers/iio/adc/ad7124.c +0
-1- ret = of_property_read_u32(child, "adi,reference-select",&tmp);
drivers/iio/adc/ad7124.c +1
-0+ ret = fwnode_property_read_u32(child, "adi,reference-select",&tmp);
if (ret)
cfg->refsel=AD7124_INT_REF; else
cfg->refsel= tmp;drivers/iio/adc/ad7124.c +0
-1- cfg->buf_positive = of_property_read_bool(child,"adi,buffered-positive");
drivers/iio/adc/ad7124.c +0
-1- cfg->buf_negative = of_property_read_bool(child,"adi,buffered-negative");
drivers/iio/adc/ad7124.c +2
-0+ cfg->buf_positive = + fwnode_property_read_bool(child, "adi,buffered-positive");
drivers/iio/adc/ad7124.c +2
-0+ cfg->buf_negative = + fwnode_property_read_bool(child, "adi,buffered-
Quoted 1 line
negative");
I think this is one of those cases where 80col limit hurts readability...
- Nuno Sá
Re: [PATCH 4/8] iio: adc: ad7292: Switch from of specific to fwnode property handling
In reply to Jonathan CameronQuoted 10 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
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 thefwnode_handleon early exit from the loop.Cc Nuno Sá <[email protected]>Signed-off-by Jonathan Cameron <[email protected]>---
Quoted 43 lines
drivers/iio/adc/ad7292.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)drivers/iio/adc/ad7292.c +2
-1@@ -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>drivers/iio/adc/ad7292.c +0
-1@@ -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;drivers/iio/adc/ad7292.c +0
-0@@ -305,12 +305,11 @@ static int ad7292_probe(struct spi_device *spi) indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->info = &ad7292_info;drivers/iio/adc/ad7292.c +0
-2-for_each_available_child_of_node (spi->dev.of_node, child) { - diff_channels = of_property_read_bool(child, "diff-channels");
drivers/iio/adc/ad7292.c +4
-2-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;
drivers/iio/adc/ad7292.c +0
-1- }}
if (diff_channels) {
Re: [PATCH 5/8] iio: adc: ad7192: Convert from of specific to fwnode property handling
In reply to Jonathan CameronQuoted 9 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
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 <[email protected]>Signed-off-by Jonathan Cameron <[email protected]>---
One minor comment. Still:
drivers/iio/adc/ad7192.c line 20
Quoted 13 lines
drivers/iio/adc/ad7192.c | 38 +++++++++++++++++++-------------------
1 file changed, 19 insertions(+), 19 deletions(-)drivers/iio/adc/ad7192.c +1
-1@@ -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á
Re: [PATCH 3/8] iio: adc: ad7124: Switch from of specific to fwnode based property handling
In reply to Jonathan CameronQuoted 8 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
Using the generic firmware data access functions from
property.hprovides 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 forfwnode_handle
Similar remarks as per other patch series...
...
drivers/iio/adc/ad7124.c static int ad7124_check_chip_id(struct ad7124_state *st) · line 818
Quoted 6 lines
drivers/iio/adc/ad7124.c +0
-1struct 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?
Quoted 1 line
int ret;
...
drivers/iio/adc/ad7124.c static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev, · line 851
Quoted 2 lines
drivers/iio/adc/ad7124.c +2
-0+ ret =fwnode_property_read_u32_array (child,"diff-channels" , + ain,2 );
ARRAY_SIZE()
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 3/8] iio: adc: ad7124: Switch from of specific to fwnode based property handling
In reply to Nuno SáQuoted 1 line · Nuno Sá
On Sun, 2024-02-18 at 17:27 +0000, Jonathan Cameron wrote:
...
Quoted 8 lines
Quoted 6 lines
(quoted diff) +2
-0+ cfg->buf_positive = + fwnode_property_read_bool(child, "adi,buffered-positive");
(quoted diff) +2
-0+ 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 :-)
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 5/8] iio: adc: ad7192: Convert from of specific to fwnode property handling
In reply to Jonathan CameronQuoted 5 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
Enables use of with other firmwware types.
Removes a case of device tree specific handlers that might get copied into new drivers.
...
drivers/iio/adc/ad7192.c static int ad7192_setup(struct iio_dev *indio_dev, struct device_node *np) · line 413
Quoted 3 lines
drivers/iio/adc/ad7192.c +1
-1-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).
...
drivers/iio/adc/ad7192.c static int ad7192_setup(struct iio_dev *indio_dev, struct device_node *np) · line 440
Quoted 4 lines
drivers/iio/adc/ad7192.c +2
-2- 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");
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 7/8] iio: accel: fxls8962af: Switch from of specific to fwnode based properties.
In reply to Jonathan CameronQuoted 5 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
Only the irq was retrieved using an of specific accessor. Switch to the fwnode equivalent and adjust headers. Also include missing
mod_devicetable.handirq.h.
...
drivers/iio/accel/fxls8962af-core.c static void fxls8962af_pm_disable(void *dev_ptr) · line 1068
Quoted 3 lines
drivers/iio/accel/fxls8962af-core.c +1
-1-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.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 8/8] iio: adc: hx711: Switch from of specific to fwnode property handling.
In reply to Jonathan CameronQuoted 4 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
Allows driver to be used with other firmware types and removes an example that might be copied into new IIO drivers.
...
Quoted 1 line
struct device *dev =
&pdev->dev;
...
drivers/iio/adc/hx711.c static int hx711_probe(struct platform_device *pdev) · line 536
Quoted 3 lines
drivers/iio/adc/hx711.c +1
-1- 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.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 15 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
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.hbased handling anyway at which point thedevice_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_idtables. It probably doesn't make sense to move that custom handling over to fwnode.
Quoted 4 lines
I included one
devm_cleanup patch in here as I was touching the driver anyway.Suggested-by Andy Shevchenko <[email protected]>
Thank you!
I have some minor comments, but in general I like this series,
Signature · 2 lines
With Best Regards, Andy Shevchenko
RE: [PATCH 6/8] iio: accel: mma8452: Switch from of specific to fwnode property handling.
In reply to Jonathan CameronQuoted 18 lines
-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: 2024年2月19日 1:27
To: [email protected]; Andy Shevchenko <[email protected]>
Cc: Lars-Peter Clausen <[email protected]>; Michael Hennerich <[email protected]>; Nuno Sá <[email protected]>; Alisa-Dariana Roman <[email protected]>; Bough Chen <[email protected]>; Sean Nyekjaer <[email protected]>; Andreas Klinger <[email protected]>; Jonathan Cameron <[email protected]>
Subject: [PATCH 6/8] iio: accel: mma8452: Switch from of specific to fwnode property handling.From: Jonathan Cameron <[email protected]>
In this case only use was to get an irq so easily converted. Also include
linux/mod_devicetable.hfor structof_device_iddefinition.
Quoted 6 lines
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 <[email protected]>Signed-off-by Jonathan Cameron <[email protected]>
Quoted 33 lines
--- drivers/iio/accel/mma8452.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/iio/accel/mma8452.c index renamed from drivers/iio/accel/mma8452.c +0
-0
d3fd0318e47b..62e6369e2269100644drivers/iio/accel/mma8452.c +3
-2@@ -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
Jonathan Cameron
maintainerRe: [PATCH 3/8] iio: adc: ad7124: Switch from of specific to fwnode based property handling
In reply to Andy ShevchenkoQuoted 23 lines · On Mon, 19 Feb 2024 13:58:20 +0200 Andy Shevchenko…
Quoted 8 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
Using the generic firmware data access functions from
property.hprovides 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 forfwnode_handleSimilar remarks as per other patch series...
...
drivers/iio/adc/ad7124.c static int ad7124_check_chip_id(struct ad7124_state *st) · line 818
Quoted 6 lines
drivers/iio/adc/ad7124.c +0
-1struct 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?
Quoted 10 lines
Quoted 1 line
int ret;
...
drivers/iio/adc/ad7124.c static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev, · line 851
Quoted 2 lines
drivers/iio/adc/ad7124.c +2
-0+ 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
Jonathan Cameron
maintainerQuoted 16 lines · On Mon, 19 Feb 2024 14:06:54 +0200 Andy Shevchenko…
Quoted 15 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
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.hbased handling anyway at which point thedevice_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_idtables. It probably doesn't make sense to move that custom handling over to fwnode.
Quoted 9 lines
Quoted 4 lines
I included one
devm_cleanup patch in here as I was touching the driver anyway.Suggested-by Andy Shevchenko <[email protected]>Thank you!
I have some minor comments, but in general I like this series,Reviewed-by Andy Shevchenko <[email protected]>
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