From nobody Tue Feb 10 17:14:17 2026 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6F091BC062 for ; Wed, 29 Jan 2025 11:05:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738148716; cv=none; b=ZHr+IJ1LLmmcmPFJ8ayke0f7SY48y8Bt6uxKJzlWPQHUQ5DPkYnsnaXUPLl00QQCSy84rwBEUqfLvdoRf4eoyErY0nC6gCdkLcVS9sS6ltcJV4LmKWQA0o+LytMImo3gbV86uXBixjqtVOMQIl/dU4fCZeiced51M8tBOhfLVG8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738148716; c=relaxed/simple; bh=mPqWiYHTVbxQ1ZYyr5/FMNCEArrrEDwzZrloBMMEgyA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qnqTkQqi1oayCWoANWaqCsjOPoFIg2lHgVM0UsIF0Qw5hLnSezxitXMVVlhJahDoetVd+pKFli8w8DRsOM/638u/94YhE4rWzB7N8tyj/TRbRrAkvYvQId8Vi3XBaCGDztgezBVAYfesqUS2TbyJgO90IaihEQaoZOMI3aLAnZ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=hg8dbtUs; arc=none smtp.client-ip=209.85.221.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="hg8dbtUs" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-386329da1d9so3521942f8f.1 for ; Wed, 29 Jan 2025 03:05:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1738148713; x=1738753513; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=oB16y1gR9CriA2xIIhmFJG7RqN1ERbrsdfXmfj1Q/Eg=; b=hg8dbtUs3ej2s8+8uDCPZP696mOFtiureoxZPRDgnZFG+3poUzQF8iua9CSF8unCT1 hAREj16yyzC4B9Ox5DiC/1W6Ooh8vGxpMLmI/ko2BvkED6xuOW8cZMC/z68GXSg8UoI/ 8ckm6diKfkBe3CtnebTVNcsCG1XRnNFkB/Lc/V8WabSSdo0Z/rmZjdvOpqK+GFNt5DzQ kLhGAqT+c4/2yb1Fu++S0yRmi5m7ocwUPFfEP4r0ddtTWCQavwgewzhdqvJIj39WU+no 7oBN3DFGZdtnmL/GO/tTcU58bAZIZa0Toa7QqHVGwcExHsOwJE1oY9dvr6vnHpnHCgla yorA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738148713; x=1738753513; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oB16y1gR9CriA2xIIhmFJG7RqN1ERbrsdfXmfj1Q/Eg=; b=As5q42zJeOpL7c8g3vhYH9eIL8DuDeyOZ48zC5IrmCeMFN8pSb7qupTMotYxte0N4/ 2atJ0rFyhOJCSnMFri9AvtmQhDrXUXJvYgWO6bPkRrfIZJHPiIgIOCdHc/QuJkQrOOGK wnTdCy+uQLs76uJ7BgAKoM1i8cFVvaDxPfhCtbKygaQdJl5zkXO/lxJV+bCf9uk7PYLJ UGwE0drLjZlLzHhphz7eSu7knasVFxBJ+anQHiITfY7yVH7hsiHbL9RmkDRciKdSBt76 +Wa4A3g3k8zyKt3hZEoThBgeiMTCCh4CjN6p9DkvvuZsf3thhaENmlU+TEw/BhiS8CNW M8nQ== X-Forwarded-Encrypted: i=1; AJvYcCXQzA/GwPLvqP0UoSdHPVnQukPnf8KabsCAcwrIpz7D3tv3fF9z0CIrMJM3gmabq7L4x2z3BgmKPWwOrO4=@vger.kernel.org X-Gm-Message-State: AOJu0YzXQCv2joLrnDtcORteIs/oT/miiPwjDxXSPNjp7ZLpJBy8Tsp1 DN5IH5+V6KopLuPTkZfbsycsEH+pkiS9E05pfqOZSlp1tsBViQpmYMXnjTXTc9s= X-Gm-Gg: ASbGnct/gjoaj58dJYpqN3zV9Yf6hdFs/iSFfJ+C35IfEcsNBTv3zLJpQ3b4dZ3K757 KDEtMsVir5UlXFug09Ko3cnqkrJ5LLmxaHeTe3CMNQJvk3q1zcbJHWJhkJcnqAw9GrQjCiTvf9q +13q4tp6hARA9PbF3QVoe2PRu47ykx5Tgx2j5R8u7y0JfHUmRhNuPkg4kfOJ5CZEm4B6XCgPJEj J8xJl+OFxQ1RG5jXLtfxFZMzye1xgDMr7wr2Jh37y6Db9Q24zcSMmWluvFmesrHVv4HP8wh+Zg1 8d7j26XkBv3dz7OQBVbeXSKN7dPpX0fUPvkKyfnFkc32wyvjqpHoBmwLV+di+AhCdF3NmDY= X-Google-Smtp-Source: AGHT+IE2fvUTplc629GXhMiYkYYmY7/ekjLGkd6x/Utm4fEUGlUkylM4nyLFo8l3fkyBWJPLc/U7HQ== X-Received: by 2002:a05:6000:1a41:b0:38c:1281:260d with SMTP id ffacd0b85a97d-38c51b5ee9fmr1571798f8f.31.1738148712977; Wed, 29 Jan 2025 03:05:12 -0800 (PST) Received: from [127.0.1.1] (host-95-245-235-245.retail.telecomitalia.it. [95.245.235.245]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38c2a17d7a7sm17107364f8f.32.2025.01.29.03.05.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2025 03:05:11 -0800 (PST) From: Angelo Dureghello X-Google-Original-From: Angelo Dureghello Date: Wed, 29 Jan 2025 12:03:07 +0100 Subject: [PATCH v3 06/10] iio: adc: adi-axi-adc: add platform children support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250129-wip-bl-ad7606_add_backend_sw_mode-v3-6-c3aec77c0ab7@baylibre.com> References: <20250129-wip-bl-ad7606_add_backend_sw_mode-v3-0-c3aec77c0ab7@baylibre.com> In-Reply-To: <20250129-wip-bl-ad7606_add_backend_sw_mode-v3-0-c3aec77c0ab7@baylibre.com> To: Michael Hennerich , Lars-Peter Clausen , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Alexandru Ardelean , David Lechner Cc: Jonathan Cameron , linux-fbdev@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Guillaume Stols , Angelo Dureghello X-Mailer: b4 0.14.1 From: Guillaume Stols 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: Guillaume Stols Co-developed-by: Angelo Dureghello Signed-off-by: Angelo Dureghello --- drivers/iio/adc/ad7606_bus_iface.h | 16 ++++++++ drivers/iio/adc/adi-axi-adc.c | 84 ++++++++++++++++++++++++++++++++++= ---- 2 files changed, 91 insertions(+), 9 deletions(-) diff --git a/drivers/iio/adc/ad7606_bus_iface.h b/drivers/iio/adc/ad7606_bu= s_iface.h new file mode 100644 index 000000000000..d8d39822e2a9 --- /dev/null +++ b/drivers/iio/adc/ad7606_bus_iface.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (c) 2010-2024 Analog Devices Inc. + * Copyright (c) 2024 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__ */ diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c index c7357601f0f8..0923565cf5bb 100644 --- a/drivers/iio/adc/adi-axi-adc.c +++ b/drivers/iio/adc/adi-axi-adc.c @@ -80,7 +80,18 @@ ADI_AXI_REG_CHAN_CTRL_FMT_EN | \ ADI_AXI_REG_CHAN_CTRL_ENABLE) =20 +struct axi_adc_info { + unsigned int version; + const struct iio_backend_info *backend_info; + bool bus_controller; + const void *pdata; + unsigned int pdata_sz; +}; + struct adi_axi_adc_state { + /* Target ADC platform device */ + struct platform_device *adc_pdev; + const struct axi_adc_info *info; struct regmap *regmap; struct device *dev; /* lock to protect multiple accesses to the device registers */ @@ -325,6 +336,38 @@ static const struct regmap_config axi_adc_regmap_confi= g =3D { .reg_stride =3D 4, }; =20 +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 =3D { + .parent =3D st->dev, + .name =3D fwnode_get_name(child), + .id =3D PLATFORM_DEVID_AUTO, + .fwnode =3D child, + .data =3D st->info->pdata, + .size_data =3D st->info->pdata_sz, + }; + struct platform_device *pdev; + int ret; + + pdev =3D platform_device_register_full(&pi); + if (IS_ERR(pdev)) + return PTR_ERR(pdev); + + ret =3D devm_add_action_or_reset(st->dev, axi_adc_child_remove, pdev); + if (ret) + return ret; + + st->adc_pdev =3D pdev; + + return 0; +} + static const struct iio_backend_ops adi_axi_adc_ops =3D { .enable =3D axi_adc_enable, .disable =3D axi_adc_disable, @@ -348,7 +391,6 @@ static const struct iio_backend_info adi_axi_adc_generi= c =3D { =20 static int adi_axi_adc_probe(struct platform_device *pdev) { - const unsigned int *expected_ver; struct adi_axi_adc_state *st; void __iomem *base; unsigned int ver; @@ -370,8 +412,8 @@ static int adi_axi_adc_probe(struct platform_device *pd= ev) return dev_err_probe(&pdev->dev, PTR_ERR(st->regmap), "failed to init register map\n"); =20 - expected_ver =3D device_get_match_data(&pdev->dev); - if (!expected_ver) + st->info =3D device_get_match_data(&pdev->dev); + if (!st->info) return -ENODEV; =20 clk =3D devm_clk_get_enabled(&pdev->dev, NULL); @@ -391,12 +433,13 @@ static int adi_axi_adc_probe(struct platform_device *= pdev) if (ret) return ret; =20 - if (ADI_AXI_PCORE_VER_MAJOR(ver) !=3D ADI_AXI_PCORE_VER_MAJOR(*expected_v= er)) { + if (ADI_AXI_PCORE_VER_MAJOR(ver) !=3D + ADI_AXI_PCORE_VER_MAJOR(st->info->version)) { dev_err(&pdev->dev, "Major version mismatch. Expected %d.%.2d.%c, Reported %d.%.2d.%c\n", - ADI_AXI_PCORE_VER_MAJOR(*expected_ver), - ADI_AXI_PCORE_VER_MINOR(*expected_ver), - ADI_AXI_PCORE_VER_PATCH(*expected_ver), + ADI_AXI_PCORE_VER_MAJOR(st->info->version), + ADI_AXI_PCORE_VER_MINOR(st->info->version), + ADI_AXI_PCORE_VER_PATCH(st->info->version), ADI_AXI_PCORE_VER_MAJOR(ver), ADI_AXI_PCORE_VER_MINOR(ver), ADI_AXI_PCORE_VER_PATCH(ver)); @@ -408,6 +451,26 @@ static int adi_axi_adc_probe(struct platform_device *p= dev) return dev_err_probe(&pdev->dev, ret, "failed to register iio backend\n"); =20 + if (st->info->bus_controller) { + device_for_each_child_node_scoped(&pdev->dev, child) { + int val; + + /* Processing only reg 0 node */ + ret =3D fwnode_property_read_u32(child, "reg", &val); + if (ret || val !=3D 0) + continue; + + ret =3D fwnode_property_read_u32(child, "io-backends", + &val); + if (ret) + continue; + + ret =3D axi_adc_create_platform_device(st, child); + if (ret) + return ret; + } + } + 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), @@ -416,11 +479,14 @@ static int adi_axi_adc_probe(struct platform_device *= pdev) return 0; } =20 -static unsigned int adi_axi_adc_10_0_a_info =3D ADI_AXI_PCORE_VER(10, 0, '= a'); +static const struct axi_adc_info adc_generic =3D { + .version =3D ADI_AXI_PCORE_VER(10, 0, 'a'), + .backend_info =3D &adi_axi_adc_generic, +}; =20 /* Match table for of_platform binding */ static const struct of_device_id adi_axi_adc_of_match[] =3D { - { .compatible =3D "adi,axi-adc-10.0.a", .data =3D &adi_axi_adc_10_0_a_inf= o }, + { .compatible =3D "adi,axi-adc-10.0.a", .data =3D &adc_generic }, { /* end of list */ } }; MODULE_DEVICE_TABLE(of, adi_axi_adc_of_match); --=20 2.47.0