Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796551418; b=ndnE66aq7MdwLJomnlThysDARwOlqmIIiV/D0jg/aL//FsKWu+0qGoPlrkoCZROR9eIx uVccuUTJVmMWSzoLCtbkGvnfp4UdEyKgpNAhuNIc5LvLJehT2lOn7+I8feDBZNHOhL6Q1 JDLb6j5fxbhm1PUh17WIa3vG5OiAdfh/9gTmUdwvqG0o0shwH/TOectnu7L44daIsRG69 K6gkTgGJaG7JfAjsnFLhck/0Iy1KPltcfzb7OQ6iGxHf9OSxxpngNjvrVN7UAX1QBJQJU XnDnCCNyoysBJem6HmRcSMCCQQtIfL/G9hIr5nICNuj+zLvYO+OOPE7p8TZhKBe7SFA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796551418; 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=QRTmBfxv+5Wu8urD8JZDGZjk/Oc7StF8/aI4RZCdyQc=; b=IKpYtogTz0hO84f1J2IdUrjo5FPYg+ZAw8/TgkhlBaKJ+5brA+UrWeo0cJN6PKZyNBfo HLFW1Ayh5wzHplglHJWELgiRRWMDmHv7aRkFpTueRI/R5iGNDr6B1qG5GVXds1iwdiJXM Lr/Fa6QzC2YqDq66gFwIZLfmuPzbAi404Rf9OVIgbEjIs2uisQEm81FhN/UIctGVVdK8K dpVt7Znv9XcU7tvEqS2FnBR7laa+SdeQxdF36uQTXYr/a6KJe0v79hgSKV9y9n42k+q2l kDiULwGD0Il678Za0+Q4R/XEkuP6nGtryirRXh7Cszrs8iatqho6/Vi7pWAe9ec6R/w== 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=B8lm5VJM; arc=none smtp.remote-ip=209.85.167.42 Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (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 AB6C4606A32F for ; Sun, 6 Dec 2026 10:03:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AB6C4606A32F 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=B8lm5VJM Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-5be53e5fce1so2643497e87.1 for ; Sun, 06 Dec 2026 02:03:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796551416; x=1797156216; 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=QRTmBfxv+5Wu8urD8JZDGZjk/Oc7StF8/aI4RZCdyQc=; b=B8lm5VJMD7f/AA2qWdY4bMUvIg8RNLR7GuHTn1c15prMCBJVd00cNtZyh7HEB7QG4L tk4t6dghk7gDytiw6fQUxnrRbl8SvDvWzN1NHXLo0yJL159fUVfjzHeaqRfnDFYLpT/M x0Y02OqYKEHLUvb4TTOeJ2xutA4tH/6mS8nzn37FYcMv0NSc+PtJHUwL/Wn2wTMXDKn6 IKzP5daB44ZHVFrYaAAj3LfVfmgh1LnLFR77E1V3sHZCuysfsTgmq8ZKdE4ZaDOfCrXF 6Xoipnzy3H9HS+XsB73cfC/1JtLeWg+eLsp5OqwB0JplJaxhjz12UFawGGWYs8vSHqxZ 14jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796551416; x=1797156216; 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=QRTmBfxv+5Wu8urD8JZDGZjk/Oc7StF8/aI4RZCdyQc=; b=bClCFtoyl6cTgDwreP+TnMZ31uHw7/0ooDyG8lXcSeWHpyATmtPJIGV++eBOYLE/vA G8BG+kOBHktW0MRNmBJF+31wzlbVVJzmSAxYv0hHDXd3lsLlEJAAoieMrbO6VDwBubtO gMhSDCbsYJMttKuMYBl4MSzz5v9kwIWFCFMG5At6zMDYF2/r+UL3JfRplb2j+qdMEAx0 q5SvB6zsOnlMjEQ8VORNx/PdCQskORGLlIkhzQO2SZOgP5IhIov9IxCd6WGFrbBILxbp 0XqziOMEYAZb5fJZQYp02+LZXurCvCPVlOzMe+emc8N8qBLIXUaozJesapK2EI2bcwAu k15w== X-Forwarded-Encrypted: i=1; AL+hErGvK49D+QSRceCFv3I5QnI/WoFkjiDPg6DiSqP3PDXG7EbPBlQoXfy1JRFDdPvC2AAoLMaaLMDgCO8=@vger.kernel.org X-Gm-Message-State: AB4q+uFPFTughDeNt3gLCH3E3vI5BKFZ1HSiDqExGT3b+59lv/kipXDz eMqO7I87EHU/WiGQsWCAh/NDrvnZEU8jcTUiyICTZmoigxghtyHot1qz X-Gm-Gg: AZFdTZevxb79K8OmL3GwRqAeo/BG1XKyOAxRfZ2pgRwpGxBBl9xPmskyyLAPRYUOh3A SN4gJcRfcgKerksfAzaAwnck2Z0103OlyW4yHEmEjwcJapWZgiioNCfPLijtM9xI8H9JGbaGNzl mr1xMNwy9lwoHvqiHvwVw2oiCo6MeUNXcrjnnNnNet8Re7CGGzf58Ca0866uxlPhObwjqt/CD2w pY1Uaxb2fC1XbcIKaVYEQ7bnhwLKmrM+wNEcDBb+aM/bkjz41ZEtq195DA937BHHhKkP2C2+4Vn R3joliow6Xy5v1G+4x1X08m31b1Fh4jQQR3j1c910Y8YLxRls68FJPelqF9ToIPEGecfyelhYkc W6HfMtnEdh0dPZNNRZLFLimjcqYhKdFYh1LbjfVrR6US+FrGL49GvAg4QzuMvVgcEdwp3gpi/jL JeBPcUgSuyS0LiYsbYgr0EBBKzhitj/Z544b6526Ch6JTYBiH1Y5tzl2V53e9km6nv0Gwmhqs8h iXSPF6q5LoEC1PHcrlHFXpRx+ypnggJzrFFaZjTXQcah49hUN4dpehEaMcKRMsF2VEnf4eOUNvv dLS030cCws94qoqysjEbm8a+o6QiRIrr4jfXp5Qb3sVbbYK7k6Z6ZcXDjwkUu7sceRO0f5jUG0P 8GrG88ePljLTpzvIvYw== X-Received: by 2002:a05:6512:1095:b0:5c1:ace3:131a with SMTP id 2adb3069b0e04-5c3861efdffmr1496455e87.48.1796551415572; Sun, 06 Dec 2026 02:03:35 -0800 (PST) Received: from yantra.. (91-159-24-23.elisa-laajakaista.fi. [91.159.24.23]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5c3849a69fbsm2223243e87.10.2026.12.06.02.03.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Dec 2026 02:03:34 -0800 (PST) From: Rupesh Majhi To: Andy Shevchenko , Antoniu Miclaus , David Lechner , Eddie James , Jonathan Cameron , Jonathan Corbet , Lucas Stankus , Marcelo Schmitt , Michael Hennerich , =?UTF-8?q?Nuno=20S=C3=A1?= , Petre Rodan , Randy Dunlap , Shuah Khan Cc: linux@analog.com, linux-doc@vger.kernel.org, linux-iio@vger.kernel.org, Rupesh Majhi , crofts@kernel.org Subject: [PATCH v4 2/7] iio: core: add iio_access_debugfs_regmap_reg() Date: Sun, 6 Dec 2026 12:03:21 +0200 Message-ID: <20261206100326.45569-3-zoone.rupert@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261206100326.45569-1-zoone.rupert@gmail.com> References: <20261206100326.45569-1-zoone.rupert@gmail.com> X-Mailing-List: linux-doc@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 --- v4: - regmap lookup split from the declaration (Andy) - kernel-doc of iio_get_debugfs_dentry() left alone, patch 1 moves it - htmldocs: the helper is in driver-api/iio/core.html 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 | 29 +++++++++++++++++++++++++++++ include/linux/iio/iio.h | 4 ++++ 2 files changed, 33 insertions(+) diff --git a/drivers/iio/industrialio-debugfs.c b/drivers/iio/industrialio-debugfs.c index a331a7c6f8da..37101c8e7f8e 100644 --- a/drivers/iio/industrialio-debugfs.c +++ b/drivers/iio/industrialio-debugfs.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -48,6 +49,34 @@ 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; + + 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 5104392cce38..d82db4c768bc 100644 --- a/include/linux/iio/iio.h +++ b/include/linux/iio/iio.h @@ -1002,11 +1002,15 @@ struct iio_trigger *__devm_iio_trigger_alloc(struct device *parent, const char *fmt, ...); #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