From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from sender4-pp-o94.zoho.com (sender4-pp-o94.zoho.com [136.143.188.94]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B595A36E for ; Mon, 23 May 2022 02:24:38 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; t=1653272623; cv=none; d=zohomail.com; s=zohoarc; b=Mhs37bNwflasXqUL/nuCgrq5OrJP5e0xOyLOB5ZqNPBJm0BXmZtmekIUzvzC3tWtpxhyNrYY2jRuboKEL58lod/B2rdbJ8FMj0exaZb4rde420WhSFTSsrQLduHEeG4ASDc5mlpaQ829IzO4XtOB3RUqF75auzNngQYMCAIh6z8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653272623; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=xmuC7wjrBYjPhnZdcSYX8RdIkUmIzgF9HaqzQxuyqjU=; b=UxugHEDpEi0QorwwNIc9ACNyxb+X7cnCWzAZ0wiLIpw+fBZvL2gVix+F24VCIoymaW4LBebUKIMhU/CEmvQ+L59DcWB00kewgS+BDjsPeAy0juqRwNCp9hkb9gVxfGuf3XZitTwV/PXort+Bz096b/5bWUSsStQFO0OhF5sbE1A= 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=1653272623; 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=xmuC7wjrBYjPhnZdcSYX8RdIkUmIzgF9HaqzQxuyqjU=; b=XLc1kFNl0NGz9rmVlY9a/eJWxrkgKjYfa9GLc5mpCq/gKyxhikIEtaGXYl8cj7es vtvRcf07IguP7Easi7THjk9ibrcp6r8NmofXji6ZikyKNqzHNXJViw2tR3S7DV3ZPTd ncBmnDvUxX4htci1SQ0JZClcSKdCdc+0XgxqkIJ4= Received: from mail.zoho.com by mx.zohomail.com with SMTP id 1653272623146927.7887030557581; Sun, 22 May 2022 19:23:43 -0700 (PDT) Received: from [45.12.140.94] by mail.zoho.com with HTTP;Sun, 22 May 2022 19:23:43 -0700 (PDT) Date: Sun, 22 May 2022 19:23:43 -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: <180eeba3811.f7218bc260169.7323954027713751119@zohomail.com> In-Reply-To: <180eeb93909.12110e2de60158.391061173597432851@zohomail.com> References: <180e702a15f.e737e37e45859.3135149506136486394@zohomail.com> <180eeb93909.12110e2de60158.391061173597432851@zohomail.com> Subject: [PATCH v2 1/4] regmap: provide regmap_field helpers for simple bit operations Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: 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: rr08011226f0c67c19081218c48c19e9650000330f85c9f9faa1b17b873eb77d42e145bde705c4f5f23435:zu08011227410f90132b5cfda0a647cf1b00006eb8554ca4528fc4bafd598538b251c6156d01c7934d640b80:rf0801122c4ee423217b2876e675ede8960000f2ed2563a4e18840ab19ea1cd4b11ba37511798467510fcee42cf27538a9:ZohoMail From: Li Chen We have set/clear/test operations for regmap, but not for regmap_field yet. So let's introduce 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 569E6C433F5 for ; Mon, 23 May 2022 08:20:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Subject:References: In-Reply-To:Message-ID:To:From:Date:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=IG212aEis698hUgH1NqRVP5BA6rhfh1yB7bqpJTBw/g=; b=m6yVsR/fepKDetnotCMQJQbz4c 1HXLyHJ5WvQAmHFQl8PFjRu2RjkkDiGn2gFFqj2leiczl3QRlAMvvSa/Sy62PaYodUwV22e5jZDrx R3v3HYVVRegj8X8IBDYdrbQMqnnNXvT6vfajjH4O/IZSkooKJeiQbSBBEXGM9ZdCq3ZHZFLM9VYg1 sl0cwvza0J/Iok8wgoU9eeJOl2IO4oq8b4W/DPss0biu+cPN9Gn21zQwNPr18CFHbkQuVdpCIQwDO tuzNlfLtrIrOfwFj9ZzCj3Fw6/MwMnTYH7PTNK75lrUHkuoQfR8g9Q7rSRG9TUzgj7URWUg32JBPy bCH17nFg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nt3Gi-002NBK-9y; Mon, 23 May 2022 08:18:24 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nt2si-002CKb-Ij for linux-arm-kernel@bombadil.infradead.org; Mon, 23 May 2022 07:53:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:Content-Type :MIME-Version:Subject:References:In-Reply-To:Message-ID:To:From:Date:Sender: Reply-To:Cc:Content-ID:Content-Description; bh=xmuC7wjrBYjPhnZdcSYX8RdIkUmIzgF9HaqzQxuyqjU=; b=C/aSocvGYCMFlzocChDDg8hGAC ceWXX4k4kWZEtLyYEDwPc1yyKq4iL1tuFVbTp6+yI+CNdBA6doYud4MGpsdsh0a/ChanGyBT4bo0B ntm3sWvIaygK203aUko6NQnA1BC+QvBWJNKJtwA8TU/EqkMknKwwpDOv3rOJdfzRUKHNWkyLut/Co WU556kBNO75U6mL0uZmaPvYaTfdH4swwCTbDzJ8X/vfw9Bze5jb5xGq8LngvklSDcBV89PmVMoxyQ hz/E4NQwYt8ewCURc+VI+yAkULdDV2cjDOOfucSmR/wLA4Mg3O29vNvhHqyEU7tdGmm98UTIcw04F b40oGdHg==; Received: from sender4-pp-o94.zoho.com ([136.143.188.94]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nsxkJ-000lLA-4o for linux-arm-kernel@lists.infradead.org; Mon, 23 May 2022 02:24:37 +0000 ARC-Seal: i=1; a=rsa-sha256; t=1653272623; cv=none; d=zohomail.com; s=zohoarc; b=Mhs37bNwflasXqUL/nuCgrq5OrJP5e0xOyLOB5ZqNPBJm0BXmZtmekIUzvzC3tWtpxhyNrYY2jRuboKEL58lod/B2rdbJ8FMj0exaZb4rde420WhSFTSsrQLduHEeG4ASDc5mlpaQ829IzO4XtOB3RUqF75auzNngQYMCAIh6z8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653272623; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=xmuC7wjrBYjPhnZdcSYX8RdIkUmIzgF9HaqzQxuyqjU=; b=UxugHEDpEi0QorwwNIc9ACNyxb+X7cnCWzAZ0wiLIpw+fBZvL2gVix+F24VCIoymaW4LBebUKIMhU/CEmvQ+L59DcWB00kewgS+BDjsPeAy0juqRwNCp9hkb9gVxfGuf3XZitTwV/PXort+Bz096b/5bWUSsStQFO0OhF5sbE1A= 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=1653272623; 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=xmuC7wjrBYjPhnZdcSYX8RdIkUmIzgF9HaqzQxuyqjU=; b=XLc1kFNl0NGz9rmVlY9a/eJWxrkgKjYfa9GLc5mpCq/gKyxhikIEtaGXYl8cj7es vtvRcf07IguP7Easi7THjk9ibrcp6r8NmofXji6ZikyKNqzHNXJViw2tR3S7DV3ZPTd ncBmnDvUxX4htci1SQ0JZClcSKdCdc+0XgxqkIJ4= Received: from mail.zoho.com by mx.zohomail.com with SMTP id 1653272623146927.7887030557581; Sun, 22 May 2022 19:23:43 -0700 (PDT) Received: from [45.12.140.94] by mail.zoho.com with HTTP;Sun, 22 May 2022 19:23:43 -0700 (PDT) Date: Sun, 22 May 2022 19:23:43 -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: <180eeba3811.f7218bc260169.7323954027713751119@zohomail.com> In-Reply-To: <180eeb93909.12110e2de60158.391061173597432851@zohomail.com> References: <180e702a15f.e737e37e45859.3135149506136486394@zohomail.com> <180eeb93909.12110e2de60158.391061173597432851@zohomail.com> Subject: [PATCH v2 1/4] regmap: provide regmap_field helpers for simple bit operations MIME-Version: 1.0 Importance: Medium User-Agent: Zoho Mail X-Mailer: Zoho Mail Feedback-ID: rr08011226f0c67c19081218c48c19e9650000330f85c9f9faa1b17b873eb77d42e145bde705c4f5f23435:zu08011227410f90132b5cfda0a647cf1b00006eb8554ca4528fc4bafd598538b251c6156d01c7934d640b80:rf0801122c4ee423217b2876e675ede8960000f2ed2563a4e18840ab19ea1cd4b11ba37511798467510fcee42cf27538a9:ZohoMail X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220523_032436_028456_68C5F87A X-CRM114-Status: GOOD ( 14.90 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Li Chen We have set/clear/test operations for regmap, but not for regmap_field yet. So let's introduce 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel