From patchwork Wed Jan 11 07:21:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Chen X-Patchwork-Id: 41782 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3176099wrt; Tue, 10 Jan 2023 23:27:48 -0800 (PST) X-Google-Smtp-Source: AMrXdXvkiNYVkY/KWJQuup56L4wb5JBIhhD6g9W5j5E09ektjyRiyMwnmAMY/7E+kdresOHVIWrE X-Received: by 2002:a17:903:2686:b0:193:362d:f41f with SMTP id jf6-20020a170903268600b00193362df41fmr1091176plb.60.1673422068456; Tue, 10 Jan 2023 23:27:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1673422068; cv=pass; d=google.com; s=arc-20160816; b=Ztc/1OjSQDuWF0uXyfnsT/YZb6Scpvt0e8pFWjtsOSxuY04AXamzUeIi3AeOD5VhtA 9WorjmN0Fus7NPfPbRwa0hXwbZkYlDPsrqxV6TYpSjf5FV78Uksgy4LV14cgKXlTZLq/ j4VMyy9VEg+P1QXrhQyQubuxqgNntEw3LPmkLql5vyVB9U33VhtFvf7k+GTE9aUtADVU WG93f/so1KMnozEU4+Wb5/Q87tfpwgYWnULduBtQI3HYmBQhoW4RrYGlUYVb+Qh7vUaf W45t8eHt9uHqfjqt9wKJO5QKWWVPLv3UhTLo+iGqurEYQ/Hw2UpWQWeCTqnpwNOMYwNv k4WQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=l3IhQjA23IOVq/9VuPj6c/xH2k/jNURCOgUNUZ43pkU=; b=kDtNnVZUbut2HHV4aUymh1X5ZuJcqwMXXxBGatT7qdVxGo9oUvoMgwhanCNmS1w0Zg c9TD4Sw+tiFo2lo9+/7YwEchrJ01QHFihRSs870bVNonRw+srCM+eA+ftPLue/3tgJtb DlnaWd3+HevTalFxjPqOh8FI5DvtDeMEDBie1IKuAuTMY8YWDiEmgOn8OCJQQ9lgFiBr gEYDMQsv0bCy7r5CzWLXb3v2LxSwBVYj+gppYR2LOD3ULPX9ZaXnwmUmqtc0zNhjj5ZA bt8jBng5TiAwdhIFOhfVJSMwXzZfp2cRyx8k5Iq20W0A67wf0LcLN1Wn3U4T9E+ozm8k 3QOQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.beauty header.s=zmail header.b=j2yOJh1N; arc=pass (i=1 spf=pass spfdomain=linux.beauty dkim=pass dkdomain=linux.beauty dmarc=pass fromdomain=linux.beauty>); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j7-20020a170903024700b001927aa58c73si14422304plh.203.2023.01.10.23.27.36; Tue, 10 Jan 2023 23:27:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.beauty header.s=zmail header.b=j2yOJh1N; arc=pass (i=1 spf=pass spfdomain=linux.beauty dkim=pass dkdomain=linux.beauty dmarc=pass fromdomain=linux.beauty>); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231717AbjAKHWv (ORCPT + 99 others); Wed, 11 Jan 2023 02:22:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229931AbjAKHWs (ORCPT ); Wed, 11 Jan 2023 02:22:48 -0500 Received: from sender4-op-o14.zoho.com (sender4-op-o14.zoho.com [136.143.188.14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08B0B63C4 for ; Tue, 10 Jan 2023 23:22:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673421760; cv=none; d=zohomail.com; s=zohoarc; b=mspABjZ/6BnU7Re05YT75tkDPGR7PdpYWJRIpIQ/ZrbkiQJ2iH+FUtrg2sQjfzrEyORD+hYD7DHa6deLAbAw1r5uLDoq15lr4nf6BV/a6bfdP9R1x0R/yUDiZ7Djyx5MK7llMYMPQ3zhBDsEUU1I9uuUiFHrxUv7k5fjUebBcVA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673421760; h=Content-Transfer-Encoding:Cc:Date:From:MIME-Version:Message-ID:Subject:To; bh=l3IhQjA23IOVq/9VuPj6c/xH2k/jNURCOgUNUZ43pkU=; b=VnxgWrsYRs5ogv4gVy5PEM++QUz6vTvSTmLgnp7iJHMKovZ0XS0AI9NafkPX/cc7kEj6OKPvPiqlTdCHBJ9agXgbMlFLOvEbm4UQXgRk70pfDIrP09cYxj0BKKcqvI1Iz/sPE49TTqiqneUprLtvvs1SuXS5yZqFMK6T5T9KVP4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=linux.beauty; spf=pass smtp.mailfrom=me@linux.beauty; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1673421760; s=zmail; d=linux.beauty; i=me@linux.beauty; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=l3IhQjA23IOVq/9VuPj6c/xH2k/jNURCOgUNUZ43pkU=; b=j2yOJh1NtPzxRB0Vh9VZrvAy3C5SYAnCtVI6SgMRQtGD+NYuPrkAQUxTjjOw9syP d39iB/utz9zD7M7L4fWx+Fp4icmpQczLzCPIdXE4wnpBJEHCMyQByT/vAwCzG5v5Z7T Zsw1Skl9pvQ1QFnW0RWPo7PO86IiAuGWX//f19sw= Received: from shbuild9.ambarella.net (116.246.37.178 [116.246.37.178]) by mx.zohomail.com with SMTPS id 16734217593541004.5197615793295; Tue, 10 Jan 2023 23:22:39 -0800 (PST) From: Li Chen To: Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: Li Chen , linux-kernel@vger.kernel.org Subject: [PATCH v2] debugfs: allow to use regmap for print regs Date: Wed, 11 Jan 2023 15:21:29 +0800 Message-Id: <20230111072130.3885460-1-me@linux.beauty> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-ZohoMailClient: External X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754710218830283498?= X-GMAIL-MSGID: =?utf-8?q?1754710218830283498?= From: Li Chen Currently, debugfs_regset32 only contains void __iomem *base, and it is not friendly to regmap user. Let's add regmap to debugfs_regset32, and add debugfs_print_regmap_reg32 to allow debugfs_regset32_show handle regmap. Signed-off-by: Li Chen --- Changelog: v1 -> v2: Suggested by Greg, provide a new function for regmap instead of trying to overload old function. --- fs/debugfs/file.c | 46 ++++++++++++++++++++++++++++++++++++++++- include/linux/debugfs.h | 10 +++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c index b54f470e0d03..f204b27f757f 100644 --- a/fs/debugfs/file.c +++ b/fs/debugfs/file.c @@ -1137,14 +1137,58 @@ void debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs, } EXPORT_SYMBOL_GPL(debugfs_print_regs32); +/** + * debugfs_print_regmap_regs32 - use seq_print to describe a set of registers + * @s: the seq_file structure being used to generate output + * @regs: an array if struct debugfs_reg32 structures + * @nregs: the length of the above array + * @regmap: regmap to be used in reading the registers + * @prefix: a string to be prefixed to every output line + * + * This function outputs a text block describing the current values of + * some 32-bit hardware registers. It is meant to be used within debugfs + * files based on seq_file that need to show registers, intermixed with other + * information. The prefix argument may be used to specify a leading string, + * because some peripherals have several blocks of identical registers, + * for example configuration of dma channels + */ +void debugfs_print_regmap_regs32(struct seq_file *s, const struct debugfs_reg32 *regs, + int nregs, struct regmap *regmap, char *prefix) +{ + int i; + u32 val; + + for (i = 0; i < nregs; i++, regs++) { + if (prefix) + seq_printf(s, "%s", prefix); + regmap_read(regmap, regs->offset, &val); + seq_printf(s, "%s = 0x%08x\n", regs->name, val); + if (seq_has_overflowed(s)) + break; + } +} +EXPORT_SYMBOL_GPL(debugfs_print_regmap_regs32); + static int debugfs_regset32_show(struct seq_file *s, void *data) { struct debugfs_regset32 *regset = s->private; + void __iomem *base = regset->base; + struct regmap *regmap = regset->regmap; + + if ((regmap && base) || (!regmap && !base)) { + seq_puts( + s, + "You should provide one and only one between base and regmap!\n"); + return -EINVAL; + } if (regset->dev) pm_runtime_get_sync(regset->dev); - debugfs_print_regs32(s, regset->regs, regset->nregs, regset->base, ""); + if (base) + debugfs_print_regs32(s, regset->regs, regset->nregs, base, ""); + if (regmap) + debugfs_print_regmap_regs32(s, regset->regs, regset->nregs, regmap, ""); if (regset->dev) pm_runtime_put(regset->dev); diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h index ea2d919fd9c7..04bc2bb70b79 100644 --- a/include/linux/debugfs.h +++ b/include/linux/debugfs.h @@ -17,6 +17,7 @@ #include #include +#include struct device; struct file_operations; @@ -35,6 +36,7 @@ struct debugfs_regset32 { const struct debugfs_reg32 *regs; int nregs; void __iomem *base; + struct regmap *regmap; struct device *dev; /* Optional device for Runtime PM */ }; @@ -152,6 +154,9 @@ void debugfs_create_regset32(const char *name, umode_t mode, void debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs, int nregs, void __iomem *base, char *prefix); +void debugfs_print_regmap_regs32(struct seq_file *s, const struct debugfs_reg32 *regs, + int nregs, struct regmap *regmap, char *prefix); + void debugfs_create_u32_array(const char *name, umode_t mode, struct dentry *parent, struct debugfs_u32_array *array); @@ -338,6 +343,11 @@ static inline void debugfs_print_regs32(struct seq_file *s, const struct debugfs { } +static inline void debugfs_print_regmap_regs32(struct seq_file *s, + const struct debugfs_reg32 *regs, + int nregs, struct regmap *regmap, + char *prefix); + static inline bool debugfs_initialized(void) { return false;