Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795891231; b=qEyQDS6qHOhoiI0JQMvLJhM/YHRqawco37/NHH0sUMIUCa2+k2uuMgAEEvCyyCvAg0Gc EWMV2qAt+lkhIs0Fb/iTlZ88YarRfymEAdKseEDfqGTJvRO2jmN6hwj0YjaYHGX6a4eeU qa33V2uqcEDvmcB4wGh7PkFaTYDuViAQ8Wmn716LdIf0UlDshIfp2gOPMbH50zyJ/htQd FLMf6AeKFJc4St9mxSjXukPdoOXE6K/Pa4xzRNb2ElyqNFaUCubpYcn5Z7LpZvbfHRVBL gxcDVRmDvXKVivuYV6g2qiyFnorlHyf8eN3Tv57f72uxeVqdI0YRNtN71b2ZhhedgKA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795891231; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=ye9FnjLJ74KosMwWKEMI8v5HeWPK6pILN0B/93HKiVU=; b=cJB6vuPTw72xR2L57nF/b6+rbm7z/gFaq7awFTI4SE3cLWwWO5QCnpfgdMrLcEbCQRu8 u0ynPWOpn5F6hDXQ+c72IMPUUZhNQwf3Wc80dQH2UDGmkUFSfYyyq78uLLpwa4BGhxM23 1/zT7ip5b79/Rk7mP+nglFxlokEhlQ57YmMOOeNgngKcQJ6Dvg8MNekii/pK5ttAymZhd YrGrk6qX/94GNiJmhXjz/ZuqoEY9cOpUFFNRCr5xXOCnJw3BkZDud60i3sGz5eXfJjcVT +j84Mg34twjiEoHiYhTPqq4/Sv1nTELYifWo/kfYbQG1UXQeDCUAZJWB1iAYjmSfe9Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=JOGgzlyW; arc=none smtp.remote-ip=209.85.167.46 Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70DC0606A325 for ; Sat, 28 Nov 2026 18:40:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 70DC0606A325 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=JOGgzlyW Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-5c158c4c15fso10713502e87.1 for ; Sat, 28 Nov 2026 10:40:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795891230; x=1796496030; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=ye9FnjLJ74KosMwWKEMI8v5HeWPK6pILN0B/93HKiVU=; b=JOGgzlyWSIicH+xrjaslIXQRh0Zg9GKRYEclshpvh0Y3/Uayf2OA9ypkMRu0vO9qdu ZGhTLCVoekhOyCCvHwaNWKY+K35xe9KOFb3Hu9DfXYz+W7faWBFXOhbRhbCNcYvmaHJM KtBei3WglDDfHDpnCOWo9mjGZdg3IPoV+GBkXwytKSPCLbEy+L9hMYey8cwuYpNLLKzt ZSSv6ep8hXlCVzEeTsfbFp/ndj9w9I10RrndX4xz8cZ0HWJlmPPSpMaZGUJEikQVXqTV Lwmlzjnfr1HG+yHdiH16TPrE4StVFyB0D5HR2X6vZXqKTQIw2EHJLDfPVrSKR75su6VU 58fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795891230; x=1796496030; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ye9FnjLJ74KosMwWKEMI8v5HeWPK6pILN0B/93HKiVU=; b=RLv6mJ93xJLI0On9ynuJCtYxw3tLEC/pSdDB2pXrN13Yf+gjYg3ashDQL8wYrhVZ3S SM2gbHYc19Us8XeYxCXrMz2dOmNO/+MoXKg9DipiQJRV6yqQ+pO4Yd6t8Ok/8Low8Z8A y14aG6Z8vmHmH0VqwUg8n1cZz8Z43qAsUjdmlxkYBxsExtkcTNv1R05+IBOqogFkU3Pm XH6NBdgZ8Tup2Mv9q2kQI7eIZ05VEMretMC0ZZiQ3NS1pc7a0PsLwbFvu59qtn5GYvw7 fID8LP0cxMJ+BCIGpDQETTs70dyfKQ0LZ+DVXmY88ossZ8DhDipf+1RR4Irr85SY7zHq PDWA== X-Forwarded-Encrypted: i=1; AL+hErGcPgpg2etfwV4OsQuCaVrpfRymnHE91l+FrQlIgvJfOF/AMXXJvMMAM7F+dYAZ2DtrKwFK7Uaqmqc=@vger.kernel.org X-Gm-Message-State: APuU4Z9UK+asfeCzZm+rRGzDZjue1UUnchrVJuyyAEePL1qnyFmiKxS6 CRVWbW06F8niQLQ2+d8QZgQp7Flnhj7HoBEmdAKQckOJ4Rjp09Lhoy21 X-Gm-Gg: AZFdTZfq74qG+3yYWNaRpJb7+JULT+FE6fbK7KKPGLRIsMN2tylq2x8PrA6c3z9D6+F 2qyxQq7+xJKANKEQ5QXmrPddBUL4N70mGTFZ1wEso4BspUoKQA3nMePJcmgzjoo2qOuzX4Q+g9e oJmHHXpQBg+fx1PcTtI8LN5dVPXPEYVXTUbgPBkTqTC0qotyp1gqFYA+ZBVgF21cU4Jis7JUc9L EzAhPeDQKVYuhxgtvHqvli4QDX8VkeTMzuPaHDg1BggfrMWxLHzEbSGHbmyeMjQVi4b4l+TLYX5 YrdUnTYlHDNhfFZgQom9s2+dDwPL4DDERTJnBuxdFZ3lq10/yPOQMkAk8jQu94/01iqUzA2c8Rb PQe+iD0ZFOlQV7DFm/ARd2tus3v6Ej2vYs/m1zSPmubz+1Fa52R5YvciDlRfgC98fpOumdV9FAT xkHe2gRkkoXTGquG4OnFTW+2ikcE1tmB0aTl65kMD9mnjFzdlSKpRkDOV1KV+RW9sJrV6TB1CtL mQRmvkpp0fczLRjDBUuD/Jy4lo+XbVJHrCGBHIAQznYEh9/rOXolMNjimLICBfcwhVKErRPtXPN JNyR/RolQfwVcC/YxWPBui/QZ98XnAA6YXcOXnjDd9MfroeAaujXBriGf7/PKcahbD8ZMtzIYe4 QaeL8WPR5PoTj6WF2jZl1CApiMzqQgANh95IWhw== X-Received: by 2002:a05:6512:3052:b0:5c1:5b06:27c0 with SMTP id 2adb3069b0e04-5c1bc6f69dcmr6962154e87.3.1795891229436; Sat, 28 Nov 2026 10:40:29 -0800 (PST) Received: from yantra.. (nekmmqv0jakeqhog8zq-1.v6.elisa-laajakaista.fi. [2001:99a:d7d:c300:c335:912f:e4f2:ad86]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5c1bcff8bc8sm7007006e87.20.2026.11.28.10.40.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Nov 2026 10:40:29 -0800 (PST) From: Rupesh Majhi To: Andy Shevchenko , Antoniu Miclaus , David Lechner , Eddie James , Jonathan Cameron , Lucas Stankus , Marcelo Schmitt , Michael Hennerich , =?UTF-8?q?Nuno=20S=C3=A1?= , Petre Rodan Cc: linux@analog.com, linux-iio@vger.kernel.org, Rupesh Majhi , crofts@kernel.org Subject: [PATCH v2 1/6] iio: core: add iio_debugfs_reg_access_regmap() Date: Sat, 28 Nov 2026 20:40:20 +0200 Message-ID: <20261128184025.87548-2-zoone.rupert@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261128184025.87548-1-zoone.rupert@gmail.com> References: <20261128184025.87548-1-zoone.rupert@gmail.com> X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit More than 25 drivers implement debugfs_reg_access with only a regmap_read() or regmap_write() on the regmap of the parent device. Add a helper that looks that regmap up with dev_get_regmap(), so these drivers can drop their own copy. Without CONFIG_DEBUG_FS the helper is defined as NULL, like adis_debugfs_reg_access, so drivers can use it without ifdefs. Reviewed-by: Nuno Sá Signed-off-by: Rupesh Majhi --- v2: - move the helper to industrialio-debugfs.c (Andy) - NULL without CONFIG_DEBUG_FS, that file is not built then - Nuno's tag kept, given "With Andy split" Cc: crofts@kernel.org drivers/iio/industrialio-debugfs.c | 28 ++++++++++++++++++++++++++++ include/linux/iio/iio.h | 4 ++++ 2 files changed, 32 insertions(+) diff --git a/drivers/iio/industrialio-debugfs.c b/drivers/iio/industrialio-debugfs.c index a8a3c7a3e85d..22a96f286f4b 100644 --- a/drivers/iio/industrialio-debugfs.c +++ b/drivers/iio/industrialio-debugfs.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -43,6 +44,33 @@ void __exit iio_debugfs_remove(void) debugfs_remove(iio_debugfs_dentry); } +/** + * iio_debugfs_reg_access_regmap() - debugfs register access through regmap + * @indio_dev: IIO device + * @reg: register address + * @writeval: value to write when @readval is NULL + * @readval: where to store the value read, or NULL for a write + * + * For &iio_info.debugfs_reg_access when the parent device has one regmap. + * + * Returns: 0 on success, -ENODEV if the parent has no regmap, or the error + * from regmap. + */ +int iio_debugfs_reg_access_regmap(struct iio_dev *indio_dev, unsigned int reg, + unsigned int writeval, unsigned int *readval) +{ + struct regmap *map = dev_get_regmap(indio_dev->dev.parent, NULL); + + if (!map) + return -ENODEV; + + if (readval) + return regmap_read(map, reg, readval); + + return regmap_write(map, reg, writeval); +} +EXPORT_SYMBOL_GPL(iio_debugfs_reg_access_regmap); + static ssize_t iio_debugfs_read_reg(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h index 8b3fd7673293..8ecf8ee879cf 100644 --- a/include/linux/iio/iio.h +++ b/include/linux/iio/iio.h @@ -1006,11 +1006,15 @@ struct iio_trigger *__devm_iio_trigger_alloc(struct device *parent, **/ #if defined(CONFIG_DEBUG_FS) struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev); +int iio_debugfs_reg_access_regmap(struct iio_dev *indio_dev, unsigned int reg, + unsigned int writeval, unsigned int *readval); #else static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev) { return NULL; } + +#define iio_debugfs_reg_access_regmap NULL #endif /** -- 2.43.0