[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <a18f44bf-e590-0ebe-00c0-5658f3a51d86@lwfinger.net>
Date: Mon, 22 Nov 2021 12:38:41 -0600
From: Larry Finger <Larry.Finger@...inger.net>
To: Geert Uytterhoeven <geert+renesas@...der.be>,
Tony Lindgren <tony@...mide.com>,
Russell King <linux@...linux.org.uk>,
Rajendra Nayak <rnayak@...eaurora.org>,
Paul Walmsley <paul@...an.com>,
Michael Turquette <mturquette@...libre.com>,
Stephen Boyd <sboyd@...nel.org>,
Nicolas Ferre <nicolas.ferre@...rochip.com>,
Alexandre Belloni <alexandre.belloni@...tlin.com>,
Ludovic Desroches <ludovic.desroches@...rochip.com>,
Tero Kristo <kristo@...nel.org>,
Jonathan Cameron <jic23@...nel.org>,
Lars-Peter Clausen <lars@...afoo.de>,
Lorenzo Bianconi <lorenzo.bianconi83@...il.com>,
Benoit Parrot <bparrot@...com>,
Mauro Carvalho Chehab <mchehab@...nel.org>,
Adrian Hunter <adrian.hunter@...el.com>,
Andrew Jeffery <andrew@...id.au>,
Ulf Hansson <ulf.hansson@...aro.org>,
Joel Stanley <joel@....id.au>,
Ping-Ke Shih <pkshih@...ltek.com>,
Kalle Valo <kvalo@...eaurora.org>,
"David S . Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>,
Linus Walleij <linus.walleij@...aro.org>,
Liam Girdwood <lgirdwood@...il.com>,
Mark Brown <broonie@...nel.org>,
Magnus Damm <magnus.damm@...il.com>,
Eduardo Valentin <edubezval@...il.com>,
Keerthy <j-keerthy@...com>,
"Rafael J . Wysocki" <rafael@...nel.org>,
Daniel Lezcano <daniel.lezcano@...aro.org>,
Amit Kucheria <amitk@...nel.org>,
Zhang Rui <rui.zhang@...el.com>,
Jaroslav Kysela <perex@...ex.cz>, Takashi Iwai <tiwai@...e.com>
Cc: linux-arm-kernel@...ts.infradead.org, linux-omap@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-clk@...r.kernel.org,
linux-renesas-soc@...r.kernel.org, linux-iio@...r.kernel.org,
linux-media@...r.kernel.org, linux-mmc@...r.kernel.org,
linux-aspeed@...ts.ozlabs.org, openbmc@...ts.ozlabs.org,
linux-wireless@...r.kernel.org, netdev@...r.kernel.org,
linux-gpio@...r.kernel.org, linux-pm@...r.kernel.org,
alsa-devel@...a-project.org
Subject: Re: [PATCH/RFC 17/17] rtw89: Use bitfield helpers
On 11/22/21 09:54, Geert Uytterhoeven wrote:
> Use the field_{get,prep}() helpers, instead of open-coding the same
> operations.
>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@...der.be>
> ---
> 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(-)
Tested-by: Larry Finger <Larry,Finger@...inger.net>
Larry
>
> 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);
> }
>
>
Powered by blists - more mailing lists