Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp3275127lfo; Mon, 23 May 2022 00:28:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyWep7hkLTUvbl4hlyiuu0Rr5yJPIxZJN56bsihQ2vUXxYTpEBaC9c9HMjxXa6PQHMsM6st X-Received: by 2002:a63:5044:0:b0:3db:a149:70ee with SMTP id q4-20020a635044000000b003dba14970eemr19229473pgl.490.1653290882821; Mon, 23 May 2022 00:28:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1653290882; cv=pass; d=google.com; s=arc-20160816; b=Pt13yqTs1NUwDaRLMkRlRzuzv2bENyWtSjpF6YaYZ5pb1m9tgVzfkX+FZ11glA1fBb 3ro0inVJ0hVdkXAA4B0DzbIgmFGxmlDbbtu0eIE/toFLat8vEOv9oRvIvpUPkHgLr+WP RU0V+t1X1FUXT2XCVakNbt5Xn3q/kne1bKPg38ONLxBBDgHx5PFQH2M0EVFPBT/mIxeM mvG1Ubr50WGZ3adYyDMhCcmMDu/z0NwK5K/mWZUnUbo2KuqQ+HO7L60hwRFaISUOv04c r5r31CzsVEKlQNeeKhktp08hfn3r8dOXP6EyHM7JDDhWPYVA3tTMqn7D9k1/9G5vBgW5 CDpQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:user-agent:importance :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:to:from:date:dkim-signature; bh=z6wL0P2oxKZ7jyZvUo3skmKeJ3yn8l7j8WvpmJJ9y2A=; b=YQsR5wm5EFljlrZu7c/BFZMKECt8Yy/mIqqkQOr1npI9zXVV0diBt/UKO2PgPsh0cy U7W8P+rAe9g1bzI7LgfupKZAnu1vqTkzXbGcd43kiu12q3qdOsWREWstgEJSd1tSC8zy e9jsUoZTyUzK6FaOOH2fUK7zVESm7wjexD7zuCE1wb5hiWQ2uuN8uS7YC231m274Vqm3 KQ9FoaW7PVTQ/C9S1RfGW+ga3zg2GWgpLSSrwIDUSzqUdJkpDMsBTZ/KIGk7vbqW3Qe3 RkPpDusBlGDCRswzfHEKhLidz/JW5yQL5BJmJOeXbXrUl6OaDDgSvHVvQ3O2wl7cmS2G 0nhA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@zohomail.com header.s=zm2022 header.b=B2GhqhSM; arc=pass (i=1 spf=pass spfdomain=zohomail.com dkim=pass dkdomain=zohomail.com dmarc=pass fromdomain=zohomail.com>); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=zohomail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id a63-20020a639042000000b003c6115ef99esi9156969pge.49.2022.05.23.00.28.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 00:28:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@zohomail.com header.s=zm2022 header.b=B2GhqhSM; arc=pass (i=1 spf=pass spfdomain=zohomail.com dkim=pass dkdomain=zohomail.com dmarc=pass fromdomain=zohomail.com>); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=zohomail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9F9DA658B; Sun, 22 May 2022 23:41:03 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234972AbiEUO1y (ORCPT + 99 others); Sat, 21 May 2022 10:27:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244440AbiEUO1v (ORCPT ); Sat, 21 May 2022 10:27:51 -0400 X-Greylist: delayed 70 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Sat, 21 May 2022 07:27:49 PDT Received: from sender4-pp-o94.zoho.com (sender4-pp-o94.zoho.com [136.143.188.94]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36BA13AA5E; Sat, 21 May 2022 07:27:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653143214; cv=none; d=zohomail.com; s=zohoarc; b=kE8zz6hAswUKjScOIdc/L6cdfge6ywC8/K021psACIT8bfnsWDNX12TOXGaF24o+fRy5mh3fFe1IqLjD5t24jEh3mpzrl9jLCFxxMRISAX7jJRCsGUw2Rh9n/1QA2q/iAIm14re9C7l4q1DdHSs9FU4LCdKEeeMVto0g2rdtVMc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653143214; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=z6wL0P2oxKZ7jyZvUo3skmKeJ3yn8l7j8WvpmJJ9y2A=; b=M8rCYV6GiB59j3m+BgOX1X4lnAKime4OmrWk8WgcgzE3L4n0EqlaYFmFFET02HOZ0RQGxPbehPi7/AfYDVuSaRn7FOMi/QEHvhMOei2frLkeCFXrk1s9hvwwrdxvWqZvLDbUePylsElF9rLtB67M9nSZ8FDIQIUeDthH5PXMSI8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=zohomail.com; spf=pass smtp.mailfrom=lchen.firstlove@zohomail.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1653143214; s=zm2022; d=zohomail.com; i=lchen.firstlove@zohomail.com; h=Date:Date:From:From:To:To:Message-ID:In-Reply-To:References:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Feedback-ID:Message-Id:Reply-To:Cc; bh=z6wL0P2oxKZ7jyZvUo3skmKeJ3yn8l7j8WvpmJJ9y2A=; b=B2GhqhSMa94on9wZCUJvL7RXvAzQ165f/25zNzDNlaJjcJ8bKuNXAIqT2P67Cm74 YzWHw3CGZs0WPXde/u8zheC4xHWyn0Aq4Qo4cSt3ztkMW1iOVoIAcFxOEFB8Aq7t8xs Ndgoy8YjgbvEcGwl13opJp6lcWYq83UbjRh2G1dw= Received: from mail.zoho.com by mx.zohomail.com with SMTP id 1653143213058600.2769632124064; Sat, 21 May 2022 07:26:53 -0700 (PDT) Received: from [45.12.140.94] by mail.zoho.com with HTTP;Sat, 21 May 2022 07:26:53 -0700 (PDT) Date: Sat, 21 May 2022 07:26:53 -0700 From: Li Chen To: "Mark Brown" , "linux-kernel" , "Greg Kroah-Hartman" , "Rafael J. Wysocki" , "linux-gpio" , "Linus Walleij" , "linux-arm-kernel" , "Patrice Chotard" , "linux-sunxi" , "Liam Girdwood" , "Jaroslav Kysela" , "Takashi Iwai" , "Chen-Yu Tsai" , "Jernej Skrabec" , "Samuel Holland" , "Philipp Zabel" Message-ID: <180e70393e7.bea7333745868.3931016213640307954@zohomail.com> In-Reply-To: <180e702a15f.e737e37e45859.3135149506136486394@zohomail.com> References: <180e702a15f.e737e37e45859.3135149506136486394@zohomail.com> Subject: [PATCH 1/4] regmap: provide regmap_field helpers for simple bit operations MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Importance: Medium User-Agent: Zoho Mail X-Mailer: Zoho Mail Feedback-ID: rr080112268bd82f7cfed3b19c5a185cb40000b440e50754e5654c60ed718200cd49c10dbbf299318737c7:zu08011227f8a703c654550416f81083160000e1fe84f8aac27165abd10358815b6ccdaee61e816e1c2fe8c1:rf0801122c62eaae334301465ae91f312300004b5111d98db5b56dfa50c31137c058746397e6037af2420ba3632588fae1:ZohoMail X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 From: Li Chen We have set/clear/test oerations for regmap, but not for regmap_field yet. So let's intoroduce regmap_field helpers too. In many instances regmap_field_update_bits() is used for simple bit setting and clearing. In these cases the last argument is redundant and we can hide it with a static inline function. This adds three new helpers for simple bit operations: set_bits, clear_bits and test_bits (the last one defined as a regular function). Signed-off-by: Li Chen --- drivers/base/regmap/regmap.c | 22 +++++++++++++++++++++ include/linux/regmap.h | 37 ++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 5e12f7cb5147..a37d6041b7bd 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -2208,6 +2208,28 @@ int regmap_field_update_bits_base(struct regmap_field *field, } EXPORT_SYMBOL_GPL(regmap_field_update_bits_base); +/** + * regmap_field_test_bits() - Check if all specified bits are set in a + * register field. + * + * @field: Register field to operate on + * @bits: Bits to test + * + * Returns -1 if the underlying regmap_field_read() fails, 0 if at least one of the + * tested bits is not set and 1 if all tested bits are set. + */ +int regmap_field_test_bits(struct regmap_field *field, unsigned int bits) +{ + unsigned int val, ret; + + ret = regmap_field_read(field, &val); + if (ret) + return ret; + + return (val & bits) == bits; +} +EXPORT_SYMBOL_GPL(regmap_field_test_bits); + /** * regmap_fields_update_bits_base() - Perform a read/modify/write cycle a * register field with port ID diff --git a/include/linux/regmap.h b/include/linux/regmap.h index de81a94d7b30..10b410734d9e 100644 --- a/include/linux/regmap.h +++ b/include/linux/regmap.h @@ -1324,6 +1324,22 @@ static inline int regmap_field_update_bits(struct regmap_field *field, NULL, false, false); } +static inline int regmap_field_set_bits(struct regmap_field *field, + unsigned int bits) +{ + return regmap_field_update_bits_base(field, bits, 0, NULL, false, + false); +} + +static inline int regmap_field_clear_bits(struct regmap_field *field, + unsigned int bits) +{ + return regmap_field_update_bits_base(field, bits, bits, NULL, false, + false); +} + +int regmap_field_test_bits(struct regmap_field *field, unsigned int bits); + static inline int regmap_field_force_update_bits(struct regmap_field *field, unsigned int mask, unsigned int val) @@ -1757,6 +1773,27 @@ regmap_field_force_update_bits(struct regmap_field *field, return -EINVAL; } +static inline int regmap_field_set_bits(struct regmap_field *field, + unsigned int bits) +{ + WARN_ONCE(1, "regmap API is disabled"); + return -EINVAL; +} + +static inline int regmap_field_clear_bits(struct regmap_field *field, + unsigned int bits) +{ + WARN_ONCE(1, "regmap API is disabled"); + return -EINVAL; +} + +static inline int regmap_field_test_bits(struct regmap_field *field, + unsigned int bits) +{ + WARN_ONCE(1, "regmap API is disabled"); + return -EINVAL; +} + static inline int regmap_fields_write(struct regmap_field *field, unsigned int id, unsigned int val) { -- 2.36.1