From patchwork Mon Nov 22 15:54:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 12633683 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 alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (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 5C5EFC433EF for ; Tue, 23 Nov 2021 08:22:46 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 574D71678; Tue, 23 Nov 2021 09:21:54 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 574D71678 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1637655764; bh=uCJjVu9F+fHUSfn+6MrRuYhRGtKMYPrSQX0PYB661AM=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Ivjq+Rh8NJM0IwytFs/uRQ7PQVTdw8XbdhP7pbVlBqPkbeGIvalBcIvi9tNAhLV1X k30+VDGViN13xEJZeU9oYuf42JNzB2+97cXX8V8C7DJioSxADpbzKmHfxigBs5qqGA V+G40Sti/ym9Bsl70FS+gO+WpSDyXPmaMt5/jlj8= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id B66CFF804E4; Tue, 23 Nov 2021 09:21:08 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id D63DDF80154; Mon, 22 Nov 2021 16:55:17 +0100 (CET) Received: from michel.telenet-ops.be (michel.telenet-ops.be [IPv6:2a02:1800:110:4::f00:18]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id E0E9AF801F7 for ; Mon, 22 Nov 2021 16:55:07 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz E0E9AF801F7 Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed20:e4da:38c:79e9:48bf]) by michel.telenet-ops.be with bizsmtp id MTuK2600Z4yPVd606TuK7s; Mon, 22 Nov 2021 16:55:06 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1mpBe6-00EL3u-UU; Mon, 22 Nov 2021 16:54:18 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1mpBe5-00HH2O-V9; Mon, 22 Nov 2021 16:54:17 +0100 From: Geert Uytterhoeven To: Tony Lindgren , Russell King , Rajendra Nayak , Paul Walmsley , Michael Turquette , Stephen Boyd , Nicolas Ferre , Alexandre Belloni , Ludovic Desroches , Tero Kristo , Jonathan Cameron , Lars-Peter Clausen , Lorenzo Bianconi , Benoit Parrot , Mauro Carvalho Chehab , Adrian Hunter , Andrew Jeffery , Ulf Hansson , Joel Stanley , Ping-Ke Shih , Kalle Valo , "David S . Miller" , Jakub Kicinski , Linus Walleij , Liam Girdwood , Mark Brown , Magnus Damm , Eduardo Valentin , Keerthy , "Rafael J . Wysocki" , Daniel Lezcano , Amit Kucheria , Zhang Rui , Jaroslav Kysela , Takashi Iwai Subject: [PATCH/RFC 17/17] rtw89: Use bitfield helpers Date: Mon, 22 Nov 2021 16:54:10 +0100 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Mailman-Approved-At: Tue, 23 Nov 2021 09:20:57 +0100 Cc: alsa-devel@alsa-project.org, Geert Uytterhoeven , linux-aspeed@lists.ozlabs.org, linux-pm@vger.kernel.org, linux-iio@vger.kernel.org, linux-wireless@vger.kernel.org, openbmc@lists.ozlabs.org, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-gpio@vger.kernel.org, netdev@vger.kernel.org, linux-omap@vger.kernel.org, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" Use the field_{get,prep}() helpers, instead of open-coding the same operations. Signed-off-by: Geert Uytterhoeven Tested-by: Larry Finger --- Compile-tested only. Marked RFC, as this depends on [PATCH 01/17], but follows a different path to upstream. --- drivers/net/wireless/realtek/rtw89/core.h | 38 ++++------------------- 1 file changed, 6 insertions(+), 32 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h index c2885e4dd882f045..f9c0300ec373aaf2 100644 --- a/drivers/net/wireless/realtek/rtw89/core.h +++ b/drivers/net/wireless/realtek/rtw89/core.h @@ -2994,81 +2994,55 @@ rtw89_write32_clr(struct rtw89_dev *rtwdev, u32 addr, u32 bit) static inline u32 rtw89_read32_mask(struct rtw89_dev *rtwdev, u32 addr, u32 mask) { - u32 shift = __ffs(mask); - u32 orig; - u32 ret; - - orig = rtw89_read32(rtwdev, addr); - ret = (orig & mask) >> shift; - - return ret; + return field_get(mask, rtw89_read32(rtwdev, addr)); } static inline u16 rtw89_read16_mask(struct rtw89_dev *rtwdev, u32 addr, u32 mask) { - u32 shift = __ffs(mask); - u32 orig; - u32 ret; - - orig = rtw89_read16(rtwdev, addr); - ret = (orig & mask) >> shift; - - return ret; + return field_get(mask, rtw89_read16(rtwdev, addr)); } static inline u8 rtw89_read8_mask(struct rtw89_dev *rtwdev, u32 addr, u32 mask) { - u32 shift = __ffs(mask); - u32 orig; - u32 ret; - - orig = rtw89_read8(rtwdev, addr); - ret = (orig & mask) >> shift; - - return ret; + return field_get(mask, rtw89_read8(rtwdev, addr)); } static inline void rtw89_write32_mask(struct rtw89_dev *rtwdev, u32 addr, u32 mask, u32 data) { - u32 shift = __ffs(mask); u32 orig; u32 set; WARN(addr & 0x3, "should be 4-byte aligned, addr = 0x%08x\n", addr); orig = rtw89_read32(rtwdev, addr); - set = (orig & ~mask) | ((data << shift) & mask); + set = (orig & ~mask) | field_prep(mask, data); rtw89_write32(rtwdev, addr, set); } static inline void rtw89_write16_mask(struct rtw89_dev *rtwdev, u32 addr, u32 mask, u16 data) { - u32 shift; u16 orig, set; mask &= 0xffff; - shift = __ffs(mask); orig = rtw89_read16(rtwdev, addr); - set = (orig & ~mask) | ((data << shift) & mask); + set = (orig & ~mask) | field_prep(mask, data); rtw89_write16(rtwdev, addr, set); } static inline void rtw89_write8_mask(struct rtw89_dev *rtwdev, u32 addr, u32 mask, u8 data) { - u32 shift; u8 orig, set; mask &= 0xff; - shift = __ffs(mask); orig = rtw89_read8(rtwdev, addr); - set = (orig & ~mask) | ((data << shift) & mask); + set = (orig & ~mask) | field_prep(mask, data); rtw89_write8(rtwdev, addr, set); }