Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: adc: qcom-pm8xxx-xoadc: convert to device properties

Make the conversion to firmware agnostic device properties. As part of
the conversion the IIO inkern interface 'of_xlate()' is also converted to
'fwnode_xlate()'. The goal is to completely drop 'of_xlate' and hence OF
dependencies from IIO.

Signed-off-by: Nuno Sá <nuno.sa@analog.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20220715122903.332535-11-nuno.sa@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Nuno Sá and committed by
Jonathan Cameron
9e90c177 34b6eb89

+28 -30
+28 -30
drivers/iio/adc/qcom-pm8xxx-xoadc.c
··· 14 14 #include <linux/iio/iio.h> 15 15 #include <linux/iio/sysfs.h> 16 16 #include <linux/module.h> 17 - #include <linux/of.h> 18 - #include <linux/of_device.h> 17 + #include <linux/mod_devicetable.h> 19 18 #include <linux/platform_device.h> 19 + #include <linux/property.h> 20 20 #include <linux/regmap.h> 21 21 #include <linux/init.h> 22 22 #include <linux/interrupt.h> ··· 694 694 } 695 695 } 696 696 697 - static int pm8xxx_of_xlate(struct iio_dev *indio_dev, 698 - const struct of_phandle_args *iiospec) 697 + static int pm8xxx_fwnode_xlate(struct iio_dev *indio_dev, 698 + const struct fwnode_reference_args *iiospec) 699 699 { 700 700 struct pm8xxx_xoadc *adc = iio_priv(indio_dev); 701 701 u8 pre_scale_mux; ··· 706 706 * First cell is prescaler or premux, second cell is analog 707 707 * mux. 708 708 */ 709 - if (iiospec->args_count != 2) { 710 - dev_err(&indio_dev->dev, "wrong number of arguments for %pOFn need 2 got %d\n", 711 - iiospec->np, 712 - iiospec->args_count); 709 + if (iiospec->nargs != 2) { 710 + dev_err(&indio_dev->dev, "wrong number of arguments for %pfwP need 2 got %d\n", 711 + iiospec->fwnode, 712 + iiospec->nargs); 713 713 return -EINVAL; 714 714 } 715 715 pre_scale_mux = (u8)iiospec->args[0]; ··· 727 727 } 728 728 729 729 static const struct iio_info pm8xxx_xoadc_info = { 730 - .of_xlate = pm8xxx_of_xlate, 730 + .fwnode_xlate = pm8xxx_fwnode_xlate, 731 731 .read_raw = pm8xxx_read_raw, 732 732 }; 733 733 734 734 static int pm8xxx_xoadc_parse_channel(struct device *dev, 735 - struct device_node *np, 735 + struct fwnode_handle *fwnode, 736 736 const struct xoadc_channel *hw_channels, 737 737 struct iio_chan_spec *iio_chan, 738 738 struct pm8xxx_chan_info *ch) 739 739 { 740 - const char *name = np->name; 740 + const char *name = fwnode_get_name(fwnode); 741 741 const struct xoadc_channel *hwchan; 742 - u32 pre_scale_mux, amux_channel; 742 + u32 pre_scale_mux, amux_channel, reg[2]; 743 743 u32 rsv, dec; 744 744 int ret; 745 745 int chid; 746 746 747 - ret = of_property_read_u32_index(np, "reg", 0, &pre_scale_mux); 747 + ret = fwnode_property_read_u32_array(fwnode, "reg", reg, 748 + ARRAY_SIZE(reg)); 748 749 if (ret) { 749 - dev_err(dev, "invalid pre scale/mux number %s\n", name); 750 + dev_err(dev, "invalid pre scale/mux or amux channel number %s\n", 751 + name); 750 752 return ret; 751 753 } 752 - ret = of_property_read_u32_index(np, "reg", 1, &amux_channel); 753 - if (ret) { 754 - dev_err(dev, "invalid amux channel number %s\n", name); 755 - return ret; 756 - } 754 + 755 + pre_scale_mux = reg[0]; 756 + amux_channel = reg[1]; 757 757 758 758 /* Find the right channel setting */ 759 759 chid = 0; ··· 778 778 /* Everyone seems to use default ("type 2") decimation */ 779 779 ch->decimation = VADC_DEF_DECIMATION; 780 780 781 - if (!of_property_read_u32(np, "qcom,ratiometric", &rsv)) { 781 + if (!fwnode_property_read_u32(fwnode, "qcom,ratiometric", &rsv)) { 782 782 ch->calibration = VADC_CALIB_RATIOMETRIC; 783 783 if (rsv > XOADC_RSV_MAX) { 784 784 dev_err(dev, "%s too large RSV value %d\n", name, rsv); ··· 791 791 } 792 792 793 793 /* Optional decimation, if omitted we use the default */ 794 - ret = of_property_read_u32(np, "qcom,decimation", &dec); 794 + ret = fwnode_property_read_u32(fwnode, "qcom,decimation", &dec); 795 795 if (!ret) { 796 796 ret = qcom_vadc_decimation_from_dt(dec); 797 797 if (ret < 0) { ··· 820 820 return 0; 821 821 } 822 822 823 - static int pm8xxx_xoadc_parse_channels(struct pm8xxx_xoadc *adc, 824 - struct device_node *np) 823 + static int pm8xxx_xoadc_parse_channels(struct pm8xxx_xoadc *adc) 825 824 { 826 - struct device_node *child; 825 + struct fwnode_handle *child; 827 826 struct pm8xxx_chan_info *ch; 828 827 int ret; 829 828 int i; 830 829 831 - adc->nchans = of_get_available_child_count(np); 830 + adc->nchans = device_get_child_node_count(adc->dev); 832 831 if (!adc->nchans) { 833 832 dev_err(adc->dev, "no channel children\n"); 834 833 return -ENODEV; ··· 845 846 return -ENOMEM; 846 847 847 848 i = 0; 848 - for_each_available_child_of_node(np, child) { 849 + device_for_each_child_node(adc->dev, child) { 849 850 ch = &adc->chans[i]; 850 851 ret = pm8xxx_xoadc_parse_channel(adc->dev, child, 851 852 adc->variant->channels, 852 853 &adc->iio_chans[i], 853 854 ch); 854 855 if (ret) { 855 - of_node_put(child); 856 + fwnode_handle_put(child); 856 857 return ret; 857 858 } 858 859 i++; ··· 883 884 const struct xoadc_variant *variant; 884 885 struct pm8xxx_xoadc *adc; 885 886 struct iio_dev *indio_dev; 886 - struct device_node *np = pdev->dev.of_node; 887 887 struct regmap *map; 888 888 struct device *dev = &pdev->dev; 889 889 int ret; 890 890 891 - variant = of_device_get_match_data(dev); 891 + variant = device_get_match_data(dev); 892 892 if (!variant) 893 893 return -ENODEV; 894 894 ··· 902 904 init_completion(&adc->complete); 903 905 mutex_init(&adc->lock); 904 906 905 - ret = pm8xxx_xoadc_parse_channels(adc, np); 907 + ret = pm8xxx_xoadc_parse_channels(adc); 906 908 if (ret) 907 909 return ret; 908 910