2
0
mirror of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git synced 2025-09-04 20:19:47 +08:00

iio: adc: adi-axi-adc: add platform children support

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>
This commit is contained in:
Angelo Dureghello 2025-02-10 17:10:55 +01:00 committed by Jonathan Cameron
parent c4330d0817
commit a4ab57debd
2 changed files with 81 additions and 0 deletions

View File

@ -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__ */

View 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 },