From patchwork Mon Jun 12 14:53:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Waqar Hameed X-Patchwork-Id: 106668 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2664874vqr; Mon, 12 Jun 2023 08:23:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7vOxINWdakF0VsLCg5c2OdL0ikQtdeaLcHXODgQUImlodyo/oHWw83UJ+zrgbFSCBzCAmw X-Received: by 2002:a17:907:8694:b0:977:d468:827 with SMTP id qa20-20020a170907869400b00977d4680827mr10350823ejc.17.1686583382301; Mon, 12 Jun 2023 08:23:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686583382; cv=none; d=google.com; s=arc-20160816; b=srB2WzQEN2Uo3RCX/f61AO9q7kVE7DgI80b0dbP/Wh92QdsCorWvXgusCLztS59DBX eew+ZdRGENcPbd6zckkcB9JESreGHR/RNWSgyTD1WVPTFjPPpXg/hKrA3ZDtMhKi8+iz +IaumXqR/z8ubSiPvykBslOiO/J+sHkn0vIoMpsT4iIz48DNCVzYXxfOeowjQP+6EhAO NEUBaN0BPA/Su0k8ySdrUbZo7KNxglvhjwWYOFK6yHvhxWCwot9ukZ6hqE/V5pyChDKB gymNasdsfa1WmoB0HW7IcN2IQgFnH6jePmpkB1fPddN2XWb7slXed4b6xnK17ta+BPzl ahgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from :user-agent:dkim-signature; bh=b0xZhbVJ2iDdtRWYPfdkFa5rLtdBa+vfP9oTAzuy6e4=; b=sqV9Dxp+7Mg3uOy8BnTXaExsBcwyJ0qypf8hkfp6eEvewbSqlzkn19vkjHWBSiPuNx aDMKF5liW+ZVpekssibTOHbI5nTzf/OuBzyYfBl3hu6K2Bnfm4SAbwTctAnIL2Zl9i7c oEWdmrPu1rTN91RJ/1kIy4qCwB815EasgXGVN+GglSw5xiCUho2SdUTHdZiqmA3ezLeZ +9Eab+k9TbwIwGy01Rf0YxtV1xJzYVLmwUfVph6jNa8j8Ug9ALFv4SNSJOiZ4MSTvWra Nlp+f3pL1LYg/qJHMAhW5WujYweZ4RaH1Rq8IHQsOn7gZYZxLrGPCOuww8tn0IRq2OCN J8qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=P2WbVqd9; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kq15-20020a170906abcf00b0097839dc85dfsi5449318ejb.317.2023.06.12.08.22.37; Mon, 12 Jun 2023 08:23:02 -0700 (PDT) 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 (test mode) header.i=@axis.com header.s=axis-central1 header.b=P2WbVqd9; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238169AbjFLO4A (ORCPT + 99 others); Mon, 12 Jun 2023 10:56:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232090AbjFLOz6 (ORCPT ); Mon, 12 Jun 2023 10:55:58 -0400 Received: from smtp2.axis.com (smtp2.axis.com [195.60.68.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18759C5 for ; Mon, 12 Jun 2023 07:55:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1686581758; x=1718117758; h=from:to:cc:subject:date:message-id:mime-version; bh=b0xZhbVJ2iDdtRWYPfdkFa5rLtdBa+vfP9oTAzuy6e4=; b=P2WbVqd9KKCgC5jBn9eQ8tBvK3HcYsw02czxeykj84roLiEBFuESA0+H Gv3YhNvblsChW08mrhoy9kSV9peeCdTTodtKBOMYKkZMqz5OxCaNofqN4 0Ve8krnmqLtIRk+K6qsUqen9tgXFkibu8ofCfqOkrCDP8hE40dhBoDz66 JG6cB7nXDFWadxuJ3JwV18Fn7/RNr3vgol1qsu+qFlsSv4eFTXLq9e48r 5EMRj2V+htM5/hHhK8Q65aZ1f6NaD0X/O55XzM78oDXXpEF59CAdOZvlf UV/qH6JNEsnr+wrj14e8JxE9kcGFMxnAZkiOdE4ALrpOPTqgmsFmp6Cfn Q==; User-agent: a.out From: Waqar Hameed To: Mark Brown , Greg Kroah-Hartman , "Rafael J. Wysocki" CC: , Subject: [PATCH] regmap: Add debugfs file for forcing field writes Date: Mon, 12 Jun 2023 16:53:35 +0200 Message-ID: MIME-Version: 1.0 X-Originating-IP: [10.0.5.60] X-ClientProxiedBy: se-mail02w.axis.com (10.20.40.8) To se-mail01w.axis.com (10.20.40.7) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1768510856431141189?= X-GMAIL-MSGID: =?utf-8?q?1768510856431141189?= `_regmap_update_bits` checks if the current register value differs from the new value, and only writes to the register if they differ. When testing hardware drivers, it might be desirable to always force a register write, for example when writing to a `regmap_field`. This enables and simplifies testing and verification of the hardware interaction. For example, when using a hardware mock/simulation model, one can then more easily verify that the driver makes the correct expected register writes during certain events. Add a bool variable `force_write_field` and a corresponding debugfs entry. Signed-off-by: Waqar Hameed --- drivers/base/regmap/internal.h | 3 +++ drivers/base/regmap/regmap-debugfs.c | 3 +++ drivers/base/regmap/regmap.c | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) base-commit: 858fd168a95c5b9669aac8db6c14a9aeab446375 diff --git a/drivers/base/regmap/internal.h b/drivers/base/regmap/internal.h index 9bd0dfd1e259..6472b3222b82 100644 --- a/drivers/base/regmap/internal.h +++ b/drivers/base/regmap/internal.h @@ -125,6 +125,9 @@ struct regmap { int reg_stride; int reg_stride_order; + /* If set, will always write field to HW. */ + bool force_write_field; + /* regcache specific members */ const struct regcache_ops *cache_ops; enum regcache_type cache_type; diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c index c491fabe3617..ed677eb10063 100644 --- a/drivers/base/regmap/regmap-debugfs.c +++ b/drivers/base/regmap/regmap-debugfs.c @@ -636,6 +636,9 @@ void regmap_debugfs_init(struct regmap *map) ®map_cache_bypass_fops); } + debugfs_create_bool("force_write_field", 0600, map->debugfs, + &map->force_write_field); + next = rb_first(&map->range_tree); while (next) { range_node = rb_entry(next, struct regmap_range_node, node); diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index fa2d3fba6ac9..89b701ceb43f 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -3273,7 +3273,7 @@ static int _regmap_update_bits(struct regmap *map, unsigned int reg, tmp = orig & ~mask; tmp |= val & mask; - if (force_write || (tmp != orig)) { + if (force_write || (tmp != orig) || map->force_write_field) { ret = _regmap_write(map, reg, tmp); if (ret == 0 && change) *change = true;