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 169C736D for ; Mon, 23 May 2022 03:28:52 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; t=1653276420; cv=none; d=zohomail.com; s=zohoarc; b=dPUbWOjXkY4D1ACcVOHZ3MXtDhRJQmFAk5i1zb33Z1Mtq9UG5t1wItiavahgnaHxk8Kjr/ayMGFxLTomCkL/dxYc6hww5mr1eKPtMKtrSel7ZHBxWPwZk3wzxnCLhqx/8Aes5iWyNyCYukZqAAN5gc+jnB28ah2oGipAFI/Gp0Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653276420; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=653U0KohN+HP/o+oh32zgz9fQdD+H+WyjAKskd6wRQM=; b=UA2+PdDFUw9MHs7m4H0OZFs3/7ZT0vSTkO7mQTSVhJ+KfUhx+DMDsYOztADOAHAMiX/j1FsV74wRpVzVUoyU3C6WAAXJY/tga8YsWNPaSmmKVYVJXeNOpF+Y+kaWf5IAaMFSIzLQrGuWLU9cK9svmfVBOiSkkU7UMun9uTifz4U= 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=1653276420; 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=653U0KohN+HP/o+oh32zgz9fQdD+H+WyjAKskd6wRQM=; b=BGPgHSw9zhcJWAmXA3KKfh4gS93r9n6Vm3FTOKWL501vLONPa0Uj1GLl55j8hd8E 226GnsAdqmzLFxaBue8POaXaYzhh5mCH80c8ixkmDrpzcmUxd6jkW8MjnUeGyxpHcZ9 03jPQ3Qor/JBMT05ykrx9ab9lSIcJlJrAY1RoqWM= Received: from mail.zoho.com by mx.zohomail.com with SMTP id 1653276418781727.4269279984867; Sun, 22 May 2022 20:26:58 -0700 (PDT) Received: from [45.12.140.94] by mail.zoho.com with HTTP;Sun, 22 May 2022 20:26:58 -0700 (PDT) Date: Sun, 22 May 2022 20:26:58 -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: <180eef422c3.deae9cd960729.8518395646822099769@zohomail.com> In-Reply-To: <180eef39205.122d47c8260721.2430302798386025245@zohomail.com> References: <180e702a15f.e737e37e45859.3135149506136486394@zohomail.com> <180eef39205.122d47c8260721.2430302798386025245@zohomail.com> Subject: [PATCH v3 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: rr08011226ed2a55e7bd2433a4b81fe4b800005e0616bf7185857e4bd1cb23448e26bba9ab7506f720ece0:zu08011227425c9f2bd7997548a7395e4d0000f6efb52c28c80fdb48cce01e25d481c1bbff148752a6239083:rf0801122c3b2638554a7123d4cc66b00400001ada923ad19f8b2f9de5f5d128cb0de0e42e65a3f81cd01f2a58986b9f47: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..5f317403c520 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, bits, 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, 0, 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 4D17DC433F5 for ; Mon, 23 May 2022 09:23:43 +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=BvWrvOWi8HNZfbTkMh2AtvVNZqjpL8hm/oT5ZuJiCDo=; b=043FH3b4Tgv8fbtGkEQATIDx7H BMr4qu5ONWSndNSeD9HuAjhw5N3XId4hXTMl7sJEPggl+Mw/Z/zGbfOjeX1SC0bdNDDTJcsg2MvcH 4j3nPZwT01o7DDtR7AVtNnA8cU0xTJTRUQQZO4bOUpIYIaTGhv/KaAgX9asEfCyaPqQsOVz6PeuOg 1E0u4iEM7xP9wJZXvxe+2MhU6979lYzlnudemYyG3wf+jyLpDFB3UuB0FBgg54le86TWSnJh6MN9A bGrtTIDUaVwf8mPUc2hqJ4p6QeYelYHnrO6EYWyuROY7IllWrPgAbbUd0c6A3Vrb33IWvJdXoK2mW TOQcY/ZA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nt4GS-002nnY-6u; Mon, 23 May 2022 09:22:12 +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 1nt2rY-002A7b-41 for linux-arm-kernel@bombadil.infradead.org; Mon, 23 May 2022 07:52:25 +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=653U0KohN+HP/o+oh32zgz9fQdD+H+WyjAKskd6wRQM=; b=EvubCxchz9M5788PTtlI5PToAB oz+YxmwlBvSIm+NFeKVKzcoYOpbEMzrl6N5N57Oq17CeL0ZeYtD7Eg3W40R/HuGdDaxYcfWRpevAv CapHZ7Jq8hpFN/sikjkgDRUjz3pcs8p5rn8c70+8ph1Un73CnHd94R0kWVfbLIDKuBygJ6kVMhvmb 2i/mYppAydjl7FFc3RpBFtAY6Xuum8vCOcQphF/JI02b4QkcHKGioIYghgNHyJEox89N+iqQlc9rQ HIjiqklvT/HjaGpAnfIB0pZCiHvah/8H0oJP7kfx6M2XPpbQ7cK170W7sk/HuRAEQ53kcjgCLpd8c uswjI6Zw==; 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 1nsykQ-000nFo-6V for linux-arm-kernel@lists.infradead.org; Mon, 23 May 2022 03:28:50 +0000 ARC-Seal: i=1; a=rsa-sha256; t=1653276420; cv=none; d=zohomail.com; s=zohoarc; b=dPUbWOjXkY4D1ACcVOHZ3MXtDhRJQmFAk5i1zb33Z1Mtq9UG5t1wItiavahgnaHxk8Kjr/ayMGFxLTomCkL/dxYc6hww5mr1eKPtMKtrSel7ZHBxWPwZk3wzxnCLhqx/8Aes5iWyNyCYukZqAAN5gc+jnB28ah2oGipAFI/Gp0Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653276420; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=653U0KohN+HP/o+oh32zgz9fQdD+H+WyjAKskd6wRQM=; b=UA2+PdDFUw9MHs7m4H0OZFs3/7ZT0vSTkO7mQTSVhJ+KfUhx+DMDsYOztADOAHAMiX/j1FsV74wRpVzVUoyU3C6WAAXJY/tga8YsWNPaSmmKVYVJXeNOpF+Y+kaWf5IAaMFSIzLQrGuWLU9cK9svmfVBOiSkkU7UMun9uTifz4U= 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=1653276420; 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=653U0KohN+HP/o+oh32zgz9fQdD+H+WyjAKskd6wRQM=; b=BGPgHSw9zhcJWAmXA3KKfh4gS93r9n6Vm3FTOKWL501vLONPa0Uj1GLl55j8hd8E 226GnsAdqmzLFxaBue8POaXaYzhh5mCH80c8ixkmDrpzcmUxd6jkW8MjnUeGyxpHcZ9 03jPQ3Qor/JBMT05ykrx9ab9lSIcJlJrAY1RoqWM= Received: from mail.zoho.com by mx.zohomail.com with SMTP id 1653276418781727.4269279984867; Sun, 22 May 2022 20:26:58 -0700 (PDT) Received: from [45.12.140.94] by mail.zoho.com with HTTP;Sun, 22 May 2022 20:26:58 -0700 (PDT) Date: Sun, 22 May 2022 20:26:58 -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: <180eef422c3.deae9cd960729.8518395646822099769@zohomail.com> In-Reply-To: <180eef39205.122d47c8260721.2430302798386025245@zohomail.com> References: <180e702a15f.e737e37e45859.3135149506136486394@zohomail.com> <180eef39205.122d47c8260721.2430302798386025245@zohomail.com> Subject: [PATCH v3 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: rr08011226ed2a55e7bd2433a4b81fe4b800005e0616bf7185857e4bd1cb23448e26bba9ab7506f720ece0:zu08011227425c9f2bd7997548a7395e4d0000f6efb52c28c80fdb48cce01e25d481c1bbff148752a6239083:rf0801122c3b2638554a7123d4cc66b00400001ada923ad19f8b2f9de5f5d128cb0de0e42e65a3f81cd01f2a58986b9f47:ZohoMail X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220523_042849_029390_1B8FF7AB X-CRM114-Status: GOOD ( 15.01 ) 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..5f317403c520 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, bits, 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, 0, 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