wifi: rtl8xxxu: Add rtl8xxxu_write{8,16,32}_{set,clear}

Also add rtl8xxxu_write32_mask, rtl8xxxu_write_rfreg_mask.

These helper functions make it easier to modify only parts of a register
by eliminating the call to the register reading function and the bit
manipulations.

Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
Reviewed-by: Ping-Ke Shih <pkshih@realtek.com>
Signed-off-by: Kalle Valo <kvalo@kernel.org>
Link: https://lore.kernel.org/r/9430b841-1048-b27c-14ec-fca447dc32af@gmail.com
This commit is contained in:
Bitterblue Smith 2023-04-17 20:07:09 +03:00 committed by Kalle Valo
parent af8678e6c5
commit cd85c8b059
2 changed files with 91 additions and 0 deletions

View File

@ -1953,10 +1953,22 @@ u32 rtl8xxxu_read32(struct rtl8xxxu_priv *priv, u16 addr);
int rtl8xxxu_write8(struct rtl8xxxu_priv *priv, u16 addr, u8 val);
int rtl8xxxu_write16(struct rtl8xxxu_priv *priv, u16 addr, u16 val);
int rtl8xxxu_write32(struct rtl8xxxu_priv *priv, u16 addr, u32 val);
int rtl8xxxu_write8_set(struct rtl8xxxu_priv *priv, u16 addr, u8 bits);
int rtl8xxxu_write8_clear(struct rtl8xxxu_priv *priv, u16 addr, u8 bits);
int rtl8xxxu_write16_set(struct rtl8xxxu_priv *priv, u16 addr, u16 bits);
int rtl8xxxu_write16_clear(struct rtl8xxxu_priv *priv, u16 addr, u16 bits);
int rtl8xxxu_write32_set(struct rtl8xxxu_priv *priv, u16 addr, u32 bits);
int rtl8xxxu_write32_clear(struct rtl8xxxu_priv *priv, u16 addr, u32 bits);
int rtl8xxxu_write32_mask(struct rtl8xxxu_priv *priv, u16 addr,
u32 mask, u32 val);
u32 rtl8xxxu_read_rfreg(struct rtl8xxxu_priv *priv,
enum rtl8xxxu_rfpath path, u8 reg);
int rtl8xxxu_write_rfreg(struct rtl8xxxu_priv *priv,
enum rtl8xxxu_rfpath path, u8 reg, u32 data);
int rtl8xxxu_write_rfreg_mask(struct rtl8xxxu_priv *priv,
enum rtl8xxxu_rfpath path, u8 reg,
u32 mask, u32 val);
void rtl8xxxu_save_regs(struct rtl8xxxu_priv *priv, const u32 *regs,
u32 *backup, int count);
void rtl8xxxu_restore_regs(struct rtl8xxxu_priv *priv, const u32 *regs,

View File

@ -786,6 +786,85 @@ int rtl8xxxu_write32(struct rtl8xxxu_priv *priv, u16 addr, u32 val)
return ret;
}
int rtl8xxxu_write8_set(struct rtl8xxxu_priv *priv, u16 addr, u8 bits)
{
u8 val8;
val8 = rtl8xxxu_read8(priv, addr);
val8 |= bits;
return rtl8xxxu_write8(priv, addr, val8);
}
int rtl8xxxu_write8_clear(struct rtl8xxxu_priv *priv, u16 addr, u8 bits)
{
u8 val8;
val8 = rtl8xxxu_read8(priv, addr);
val8 &= ~bits;
return rtl8xxxu_write8(priv, addr, val8);
}
int rtl8xxxu_write16_set(struct rtl8xxxu_priv *priv, u16 addr, u16 bits)
{
u16 val16;
val16 = rtl8xxxu_read16(priv, addr);
val16 |= bits;
return rtl8xxxu_write16(priv, addr, val16);
}
int rtl8xxxu_write16_clear(struct rtl8xxxu_priv *priv, u16 addr, u16 bits)
{
u16 val16;
val16 = rtl8xxxu_read16(priv, addr);
val16 &= ~bits;
return rtl8xxxu_write16(priv, addr, val16);
}
int rtl8xxxu_write32_set(struct rtl8xxxu_priv *priv, u16 addr, u32 bits)
{
u32 val32;
val32 = rtl8xxxu_read32(priv, addr);
val32 |= bits;
return rtl8xxxu_write32(priv, addr, val32);
}
int rtl8xxxu_write32_clear(struct rtl8xxxu_priv *priv, u16 addr, u32 bits)
{
u32 val32;
val32 = rtl8xxxu_read32(priv, addr);
val32 &= ~bits;
return rtl8xxxu_write32(priv, addr, val32);
}
int rtl8xxxu_write32_mask(struct rtl8xxxu_priv *priv, u16 addr,
u32 mask, u32 val)
{
u32 orig, new, shift;
shift = __ffs(mask);
orig = rtl8xxxu_read32(priv, addr);
new = (orig & ~mask) | ((val << shift) & mask);
return rtl8xxxu_write32(priv, addr, new);
}
int rtl8xxxu_write_rfreg_mask(struct rtl8xxxu_priv *priv,
enum rtl8xxxu_rfpath path, u8 reg,
u32 mask, u32 val)
{
u32 orig, new, shift;
shift = __ffs(mask);
orig = rtl8xxxu_read_rfreg(priv, path, reg);
new = (orig & ~mask) | ((val << shift) & mask);
return rtl8xxxu_write_rfreg(priv, path, reg, new);
}
static int
rtl8xxxu_writeN(struct rtl8xxxu_priv *priv, u16 addr, u8 *buf, u16 len)
{