Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796407873; b=FROg90mAUi/Hggkra5iXASrv7sT8hLoloF27yoJRiIcMJfue+eMNW2GB/g47c/y6LE8Q 5I94XeUOOSbrsp9a5jEDlIpWiM3560TiirywL+FfUF1f445brSIvsYYUlhNGVFz0mJfL4 DSOVpQo9XM/25eHWPf0Du6QXiBW4yQ2Pc6sZ3fWk8JoGiWtmW9msjPrwEBOy4wkuZL60p rBfE47MP5NyYGcmQJAfzHuOULQIzQZcai8akAcvvvxs2GdBv7KG93uED0I2oyF9gfwwdT qx2O/YyoMMQxbHecA1nfBU5Pui5nV34QdOhiqTGNMneIGE9Di7UlReU+Xe/cFPW09QA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796407873; 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=fOAyB3L5W5gVrTRKUt5D0+4PsswnZ3A7QGHXcMrtyW0=; b=UylC34/Ox0FhNSnOiEzfAAobDDnov0a7IPGjy2vG1x7R0kSCA+j29Eubf3ppZUs0mdNy GqrolXATRBjlIbYKPkvZHH63gb+KOYndUf7HXRjBMP38C9agzvHMUKdPVQ7FMZ2li1apf ZYkHMBGZtmqFRJovFwPadXsw12knwu1VMKBjndCA5vih1mITNM/1OXx6++t7+CClNV63U YK73xJB0RUXMaWqjIW6n+zwTT1T1wUdCxzS5J7tWGMiNaKGsNLsnZo3H2FHIZOq6WQi6T vE3MQk/pIOQs0AWAyJY/hwRsOTKMKU6i9qNrot7wrveudMtRl8Mz8/Oeg0mLvoEcMIQ== 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=rtRnanyt; arc=none smtp.remote-ip=209.85.167.43 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (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 32382606A322 for ; Fri, 4 Dec 2026 18:11:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 32382606A322 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=rtRnanyt Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-5c14f7768acso741442e87.3 for ; Fri, 04 Dec 2026 10:11:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796407871; x=1797012671; 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=fOAyB3L5W5gVrTRKUt5D0+4PsswnZ3A7QGHXcMrtyW0=; b=rtRnanytTahySZv310Z9pjuBAJZKOFq9YjeEd/YWQeMF4hV/Bl7yPC7xlgA/XlJuBN klcqBtC3jRkMwIiQm4aWngjZoSt5PUhvevehJbReaXLRREcZBApQtosxAf8WAV5l1Kom hm6vjUrHZD1DmAvEXd4rMsMQ4GZ5VfWI7fTq2tU4Ar2m6qLIFK2SSW1Y/7IPLRO3Q+qa br9tkwVEQZ6bvgRJfOEJbclX3pLYI1H2X1QYFNCeEF5LY9G6DJC1LCYBOKJKFR1IX9F1 s/JrUdKx+ajsVOfE3CDcqDqgzm12ZVdY8VY9AvO3CpiXFzDaib/TnZr3WNDv3cgjGids qhAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796407871; x=1797012671; 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=fOAyB3L5W5gVrTRKUt5D0+4PsswnZ3A7QGHXcMrtyW0=; b=0LMimBJfDUhMPIgbY8j4Gd8t2DlqDm5bIYgnhalq2bAeCvYfb0w5OPH4Ch5WwHM7el dMobsH09/8W6P9SQasbOKz6sQz7Ke1huSjJqH2Q2W4CUoKJlawyzCcPkMwlV4lra0uAg JvXgtollqE6fHAtzy3/1i5b96zMntQxtTezlLMruCgkfi8fzgJ74JnOIEHVkG1YQlkvJ Pzjx9Af7jYyufwGLHcclXwVVClv084sjWDbM5fcsp2Ak3g97ec5ANm3HalYkYtwGQgw6 nLVMxIg/nIorPCfb2Y0B8v7rIDZKtSNozlKGWU27RrqQxjFDf4QjSfIlsZ4qQORn4dGz ZMZw== X-Forwarded-Encrypted: i=1; AL+hErEpDuvm9KjWu7ycopfWSljKXFZrjGouUv2XUUI3eoHeJByyRVAoAx2zXb0BPa0TIOBUiNlbE0rOFTQ=@vger.kernel.org X-Gm-Message-State: APuU4Z+DO1afenNl6YVgm1vVqlPCyg9LRVp5BTDh4pTVYjpNlNb2pprb F9+tAvh2ZtDIE8O8UyNO8miiGYrYEYLnQPuYELN3exuyH9kpNUMm7Op7 X-Gm-Gg: AZFdTZc1d+C8A2t9lXZuGmU4UHeSm1o9EtHUSdmbIUVfzqpOCiCMM6LGEE0+t4Y3Lwk jGsSjk+whqpk7cmv7gYcM0Qc2+gvglf+4DnN3Ct3Vmc2T3jzcWxwsFxusPMHSuvxWaMD2yN3KFS TYzJ0HWtlEYCydr/ui442BlCmAxDjM7x3GqXIAj0cOHFQJb5H+yl/lguxayH/tJSkpecrZIV0ls h0jqG+XuZWWipw04e6VLQUwqBJferMc3hb+8LVCjSMU9E63e8e1CihUmeQ3N5anUyo8dDiLdWS3 BvplI179QBBUqt3+Dqt2799cgsihn3A8cJbLf2DsDkXprD2B6Hx2EzdeK87cYZIMBNoQ840KGkC njVUHSidlCP4J5Dx8FyuejQ4IWkOnxnbcNl3uKc20AONUEslNlfhSXGJuRDZKUot5z13xbPKfkC GYSapoJYUmY8qBL4+V/hLMV9IMw12oL0nKnGRGZlaNNozisXIhIf1Dcp2tqw619m/QRH4FKqCv4 XCHKqhdZkqy+lwHjJQW0abHhIN7BHG6Vzs/jciTAsYkL50vaqxafJqyXLfvZYs889n0F/obmhjX EcB9RhwdqYdZLviWgfdWzhki3z7oqGIBci1Tz7GudA2IqrkwcUgWCRtQLinVsRhZHoFxIzypWCC bNZz3ORttGFEF8gQi9A== X-Received: by 2002:a05:6512:1282:b0:5c1:c192:8f2 with SMTP id 2adb3069b0e04-5c385f41eb0mr781959e87.3.1796407870974; Fri, 04 Dec 2026 10:11:10 -0800 (PST) Received: from yantra.. (91-159-24-23.elisa-laajakaista.fi. [91.159.24.23]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5c384aa37a3sm790311e87.67.2026.12.04.10.11.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 10:11:09 -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 v3 1/6] iio: core: add iio_access_debugfs_regmap_reg() Date: Fri, 4 Dec 2026 20:11:00 +0200 Message-ID: <20261204181105.150419-2-zoone.rupert@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261204181105.150419-1-zoone.rupert@gmail.com> References: <20261204181105.150419-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 --- v3: - rename to iio_access_debugfs_regmap_reg() (Andy) - kernel-doc of iio_get_debugfs_dentry() moves inside the #if, so the new prototype can share the block; kernel-doc output is unchanged (Andy) - callback written as .debugfs_reg_access() (Andy) 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 | 7 ++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/drivers/iio/industrialio-debugfs.c b/drivers/iio/industrialio-debugfs.c index a8a3c7a3e85d..7b22308ed1a9 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_access_debugfs_regmap_reg() - 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_access_debugfs_regmap_reg(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_access_debugfs_regmap_reg); + 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..ca44394ab115 100644 --- a/include/linux/iio/iio.h +++ b/include/linux/iio/iio.h @@ -1000,17 +1000,22 @@ __printf(3, 4) struct iio_trigger *__devm_iio_trigger_alloc(struct device *parent, struct module *this_mod, const char *fmt, ...); +#if defined(CONFIG_DEBUG_FS) /** * iio_get_debugfs_dentry() - helper function to get the debugfs_dentry * @indio_dev: IIO device structure for device **/ -#if defined(CONFIG_DEBUG_FS) struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev); + +int iio_access_debugfs_regmap_reg(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_access_debugfs_regmap_reg NULL #endif /** -- 2.43.0