Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1119631rwd; Tue, 13 Jun 2023 05:16:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7mooV4cUTo29bZBSVwZVlVrHCtdNlC3r9/wG2pegC2V2nUN1gAZOmLXE8QTvi62cgRGezV X-Received: by 2002:a05:6a20:840d:b0:11a:f632:78fb with SMTP id c13-20020a056a20840d00b0011af63278fbmr6698820pzd.19.1686658619004; Tue, 13 Jun 2023 05:16:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686658618; cv=none; d=google.com; s=arc-20160816; b=Qo6Vt4cd9pha2v/YsiJX0C8Z+7jEosh669dXOE6XtEugJzfHNJ7B5QGG3HniVcT5LZ MY04ja7JtqsQHC2k6jYRI4rWCNGBx3ISNkublEZzU8+4L0mBXLuq0JS4ZHH5OjhIzbge SYmfUT++6kLxqO/Fr+6x2gRAq2YBrvCNyZN4CNiqiJZg+adLuKkXwjLhK2ol1b8VMymS 7TCUn6bOnGodhSED6Z6L21k8YYdEayca77svk162rbLhkOdvvw2uIoMdkzUITIFz3Bsm HEf1yU0ZsDEGDpIKz7hqe6eC2UWXDQbKvEgTTE/+Vv8ggWTjekwax5MEFagkphlh2YCa i3FQ== 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=0M3Bw0Wvlmg09M9Otqtr7gQiKvBD/9rNZgj0Z8luQVA=; b=Up8IvWB6xsfHHLVw6kmBXgksBSgJxnOEzLn8HGbQzchGRDTyVJZi/JTO3tVyRwe6CB gCVFAS1Engc273cqzXk+BPRLlC3Oj7jEUhWQjCz3PZDB6kRyCQf8WEWtEiVNtQ7MlYbj kTuO8Fb6DeHngC+7XMyJbwrCRmuispEoNUAr1BUoPSv9MqxOWTq5dtd2NLpn/knog5l0 qUkGw126RrmcJuZikhMMd4QlVuBi8WUQBaQb4XJKiITYjxZLA3RhwWTKUfmKgVmX9+YR Vif0Yv5aZDackiYk2CebKjHxzgnHhGeBS1dZXYT3SpHohW5n7wQ7udertO2HzSuBrS+i 3VFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=B1pggX0K; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i20-20020aa796f4000000b00647514cfd36si7363899pfq.242.2023.06.13.05.16.46; Tue, 13 Jun 2023 05:16:58 -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=B1pggX0K; 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 S242265AbjFMMDb (ORCPT + 99 others); Tue, 13 Jun 2023 08:03:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235323AbjFMMD3 (ORCPT ); Tue, 13 Jun 2023 08:03:29 -0400 Received: from smtp1.axis.com (smtp1.axis.com [195.60.68.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C59D91AC for ; Tue, 13 Jun 2023 05:03:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1686657808; x=1718193808; h=from:to:cc:subject:date:message-id:mime-version; bh=0M3Bw0Wvlmg09M9Otqtr7gQiKvBD/9rNZgj0Z8luQVA=; b=B1pggX0KfEPzMjBeAa5P3gRPVvmWxjYmsFxCvdyOTDRL6aavEywxlkr+ I/X9LWD/1pziIF5jNnH6EUCkIIrID0DJemAt+rT3iI48cDsn0LTOnK+u3 03CqcIY2jSOjEbrJI6tU1Af+5/ae3rxYTA9cgcbyokBn1BjNKbVVSPnIv dVMWl/wu5y//pMsddgMILytIWxsZRbkrQk12nOix8E/Ia8XZDpYC17ope Y7GbiOd7GXkPtTUVgXa0UJeisXMMQUCHBXcVgUJo27nvxqtKR6rHxUp4/ zFHkEiTzmzfRKJCKmStD0e4mAXcFSh1FOJApfj5TWXx90F76nXgx9WSOC A==; User-agent: a.out From: Waqar Hameed To: Mark Brown , Greg Kroah-Hartman , "Rafael J. Wysocki" CC: , Subject: [PATCH v2] regmap: Add debugfs file for forcing field writes Date: Tue, 13 Jun 2023 13:42:27 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain 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,URIBL_BLOCKED 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 `_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 to enable this. Since this feature could interfere with driver operation, guard it with a macro. Signed-off-by: Waqar Hameed --- Changes in v2: * Add macro to guard the debugfs entry. * Fix `Signed-off-by` in commit message to match actual email address. * Link to v1: https://lore.kernel.org/all/pndttvcu3ut.fsf@axis.com/ drivers/base/regmap/internal.h | 3 +++ drivers/base/regmap/regmap-debugfs.c | 11 +++++++++++ drivers/base/regmap/regmap.c | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) 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..f36027591e1a 100644 --- a/drivers/base/regmap/regmap-debugfs.c +++ b/drivers/base/regmap/regmap-debugfs.c @@ -636,6 +636,17 @@ void regmap_debugfs_init(struct regmap *map) ®map_cache_bypass_fops); } + /* + * This could interfere with driver operation. Therefore, don't provide + * any real compile time configuration option for this feature. One will + * have to modify the source code directly in order to use it. + */ +#undef REGMAP_ALLOW_FORCE_WRITE_FIELD_DEBUGFS +#ifdef REGMAP_ALLOW_FORCE_WRITE_FIELD_DEBUGFS + debugfs_create_bool("force_write_field", 0600, map->debugfs, + &map->force_write_field); +#endif + 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; base-commit: 858fd168a95c5b9669aac8db6c14a9aeab446375 -- 2.30.2