]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: adc: adi-axi-adc: add platform children support
authorAngelo Dureghello <adureghello@baylibre.com>
Mon, 10 Feb 2025 16:10:55 +0000 (17:10 +0100)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Tue, 11 Feb 2025 19:56:25 +0000 (19:56 +0000)
This is a preparation for the next commit adding support for register
read and write functions on AD7606.
Since sometimes a bus will be used, it has been agreed during ad3552's
driver implementation that the device's driver bus is the backend, whose
device node will be a child node.
To provide the special callbacks for setting the register, axi-adc needs
to pass them to the child device's driver through platform data.

Signed-off-by: Angelo Dureghello <adureghello@baylibre.com>
Link: https://patch.msgid.link/20250210-wip-bl-ad7606_add_backend_sw_mode-v4-5-160df18b1da7@baylibre.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/ad7606_bus_iface.h [new file with mode: 0644]
drivers/iio/adc/adi-axi-adc.c

diff --git a/drivers/iio/adc/ad7606_bus_iface.h b/drivers/iio/adc/ad7606_bus_iface.h
new file mode 100644 (file)
index 0000000..f2c979a
--- /dev/null
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (c) 2010-2024 Analog Devices Inc.
+ * Copyright (c) 2025 Baylibre, SAS
+ */
+#ifndef __LINUX_PLATFORM_DATA_AD7606_H__
+#define __LINUX_PLATFORM_DATA_AD7606_H__
+
+struct iio_backend;
+
+struct ad7606_platform_data {
+       int (*bus_reg_read)(struct iio_backend *back, u32 reg, u32 *val);
+       int (*bus_reg_write)(struct iio_backend *back, u32 reg, u32 val);
+};
+
+#endif /* __LINUX_PLATFORM_DATA_AD7606_H__ */
index 04f7d7d3890b8e7da33df400eebff5f1f326b6b7..182ad14e4949b8f914a1cbf2b2e4a0ea59fae1ac 100644 (file)
@@ -334,6 +334,36 @@ static const struct regmap_config axi_adc_regmap_config = {
        .reg_stride = 4,
 };
 
+static void axi_adc_child_remove(void *data)
+{
+       platform_device_unregister(data);
+}
+
+static int axi_adc_create_platform_device(struct adi_axi_adc_state *st,
+                                         struct fwnode_handle *child)
+{
+       struct platform_device_info pi = {
+           .parent = st->dev,
+           .name = fwnode_get_name(child),
+           .id = PLATFORM_DEVID_AUTO,
+           .fwnode = child,
+           .data = st->info->pdata,
+           .size_data = st->info->pdata_sz,
+       };
+       struct platform_device *pdev;
+       int ret;
+
+       pdev = platform_device_register_full(&pi);
+       if (IS_ERR(pdev))
+               return PTR_ERR(pdev);
+
+       ret = devm_add_action_or_reset(st->dev, axi_adc_child_remove, pdev);
+       if (ret)
+               return ret;
+
+       return 0;
+}
+
 static const struct iio_backend_ops adi_axi_adc_ops = {
        .enable = axi_adc_enable,
        .disable = axi_adc_disable,
@@ -417,6 +447,28 @@ static int adi_axi_adc_probe(struct platform_device *pdev)
                return dev_err_probe(&pdev->dev, ret,
                                     "failed to register iio backend\n");
 
+       device_for_each_child_node_scoped(&pdev->dev, child) {
+               int val;
+
+               if (!st->info->has_child_nodes)
+                       return dev_err_probe(&pdev->dev, -EINVAL,
+                                            "invalid fdt axi-dac compatible.");
+
+               /* Processing only reg 0 node */
+               ret = fwnode_property_read_u32(child, "reg", &val);
+               if (ret)
+                       return dev_err_probe(&pdev->dev, ret,
+                                            "invalid reg property.");
+               if (val != 0)
+                       return dev_err_probe(&pdev->dev, -EINVAL,
+                                            "invalid node address.");
+
+               ret = axi_adc_create_platform_device(st, child);
+               if (ret)
+                       return dev_err_probe(&pdev->dev, -EINVAL,
+                                            "cannot create device.");
+       }
+
        dev_info(&pdev->dev, "AXI ADC IP core (%d.%.2d.%c) probed\n",
                 ADI_AXI_PCORE_VER_MAJOR(ver),
                 ADI_AXI_PCORE_VER_MINOR(ver),
@@ -430,6 +482,19 @@ static const struct axi_adc_info adc_generic = {
        .backend_info = &adi_axi_adc_generic,
 };
 
+static const struct ad7606_platform_data ad7606_pdata = {
+       .bus_reg_read = ad7606_bus_reg_read,
+       .bus_reg_write = ad7606_bus_reg_write,
+};
+
+static const struct axi_adc_info adc_ad7606 = {
+       .version = ADI_AXI_PCORE_VER(10, 0, 'a'),
+       .backend_info = &adi_axi_adc_generic,
+       .pdata = &ad7606_pdata,
+       .pdata_sz = sizeof(ad7606_pdata),
+       .has_child_nodes = true,
+};
+
 /* Match table for of_platform binding */
 static const struct of_device_id adi_axi_adc_of_match[] = {
        { .compatible = "adi,axi-adc-10.0.a", .data = &adc_generic },