Commit db7fa61a authored by Zong-Zhe Yang's avatar Zong-Zhe Yang Committed by Kalle Valo

rtw89: make rfk helpers common across chips

These rfk helpers are also useful for the chip which is under planning.
So, move them to common code to avoid duplicate stuff in the future.
Signed-off-by: default avatarZong-Zhe Yang <kevin_yang@realtek.com>
Signed-off-by: default avatarPing-Ke Shih <pkshih@realtek.com>
Signed-off-by: default avatarKalle Valo <kvalo@kernel.org>
Link: https://lore.kernel.org/r/20220211075953.40421-2-pkshih@realtek.com
parent ed26edf7
......@@ -3037,3 +3037,55 @@ void rtw89_phy_set_bss_color(struct rtw89_dev *rtwdev, struct ieee80211_vif *vif
rtw89_phy_write32_idx(rtwdev, R_BSS_CLR_MAP, B_BSS_CLR_MAP_STAID,
vif->bss_conf.aid, phy_idx);
}
static void
_rfk_write_rf(struct rtw89_dev *rtwdev, const struct rtw89_reg5_def *def)
{
rtw89_write_rf(rtwdev, def->path, def->addr, def->mask, def->data);
}
static void
_rfk_write32_mask(struct rtw89_dev *rtwdev, const struct rtw89_reg5_def *def)
{
rtw89_phy_write32_mask(rtwdev, def->addr, def->mask, def->data);
}
static void
_rfk_write32_set(struct rtw89_dev *rtwdev, const struct rtw89_reg5_def *def)
{
rtw89_phy_write32_set(rtwdev, def->addr, def->mask);
}
static void
_rfk_write32_clr(struct rtw89_dev *rtwdev, const struct rtw89_reg5_def *def)
{
rtw89_phy_write32_clr(rtwdev, def->addr, def->mask);
}
static void
_rfk_delay(struct rtw89_dev *rtwdev, const struct rtw89_reg5_def *def)
{
udelay(def->data);
}
static void
(*_rfk_handler[])(struct rtw89_dev *rtwdev, const struct rtw89_reg5_def *def) = {
[RTW89_RFK_F_WRF] = _rfk_write_rf,
[RTW89_RFK_F_WM] = _rfk_write32_mask,
[RTW89_RFK_F_WS] = _rfk_write32_set,
[RTW89_RFK_F_WC] = _rfk_write32_clr,
[RTW89_RFK_F_DELAY] = _rfk_delay,
};
static_assert(ARRAY_SIZE(_rfk_handler) == RTW89_RFK_F_NUM);
void
rtw89_rfk_parser(struct rtw89_dev *rtwdev, const struct rtw89_rfk_tbl *tbl)
{
const struct rtw89_reg5_def *p = tbl->defs;
const struct rtw89_reg5_def *end = tbl->defs + tbl->size;
for (; p < end; p++)
_rfk_handler[p->flag](rtwdev, p);
}
EXPORT_SYMBOL(rtw89_rfk_parser);
......@@ -328,6 +328,65 @@ static inline u32 rtw89_phy_read32_mask(struct rtw89_dev *rtwdev,
return rtw89_read32_mask(rtwdev, addr | RTW89_PHY_ADDR_OFFSET, mask);
}
enum rtw89_rfk_flag {
RTW89_RFK_F_WRF = 0,
RTW89_RFK_F_WM = 1,
RTW89_RFK_F_WS = 2,
RTW89_RFK_F_WC = 3,
RTW89_RFK_F_DELAY = 4,
RTW89_RFK_F_NUM,
};
struct rtw89_rfk_tbl {
const struct rtw89_reg5_def *defs;
u32 size;
};
#define DECLARE_RFK_TBL(_name) \
const struct rtw89_rfk_tbl _name ## _tbl = { \
.defs = _name, \
.size = ARRAY_SIZE(_name), \
}
#define DECL_RFK_WRF(_path, _addr, _mask, _data) \
{.flag = RTW89_RFK_F_WRF, \
.path = _path, \
.addr = _addr, \
.mask = _mask, \
.data = _data,}
#define DECL_RFK_WM(_addr, _mask, _data) \
{.flag = RTW89_RFK_F_WM, \
.addr = _addr, \
.mask = _mask, \
.data = _data,}
#define DECL_RFK_WS(_addr, _mask) \
{.flag = RTW89_RFK_F_WS, \
.addr = _addr, \
.mask = _mask,}
#define DECL_RFK_WC(_addr, _mask) \
{.flag = RTW89_RFK_F_WC, \
.addr = _addr, \
.mask = _mask,}
#define DECL_RFK_DELAY(_data) \
{.flag = RTW89_RFK_F_DELAY, \
.data = _data,}
void
rtw89_rfk_parser(struct rtw89_dev *rtwdev, const struct rtw89_rfk_tbl *tbl);
#define rtw89_rfk_parser_by_cond(dev, cond, tbl_t, tbl_f) \
do { \
typeof(dev) __dev = (dev); \
if (cond) \
rtw89_rfk_parser(__dev, (tbl_t)); \
else \
rtw89_rfk_parser(__dev, (tbl_f)); \
} while (0)
void rtw89_phy_write_reg3_tbl(struct rtw89_dev *rtwdev,
const struct rtw89_phy_reg3_tbl *tbl);
u8 rtw89_phy_get_txsc(struct rtw89_dev *rtwdev,
......
......@@ -12,66 +12,6 @@
#include "rtw8852a_rfk_table.h"
#include "rtw8852a_table.h"
static void
_rfk_write_rf(struct rtw89_dev *rtwdev, const struct rtw89_reg5_def *def)
{
rtw89_write_rf(rtwdev, def->path, def->addr, def->mask, def->data);
}
static void
_rfk_write32_mask(struct rtw89_dev *rtwdev, const struct rtw89_reg5_def *def)
{
rtw89_phy_write32_mask(rtwdev, def->addr, def->mask, def->data);
}
static void
_rfk_write32_set(struct rtw89_dev *rtwdev, const struct rtw89_reg5_def *def)
{
rtw89_phy_write32_set(rtwdev, def->addr, def->mask);
}
static void
_rfk_write32_clr(struct rtw89_dev *rtwdev, const struct rtw89_reg5_def *def)
{
rtw89_phy_write32_clr(rtwdev, def->addr, def->mask);
}
static void
_rfk_delay(struct rtw89_dev *rtwdev, const struct rtw89_reg5_def *def)
{
udelay(def->data);
}
static void
(*_rfk_handler[])(struct rtw89_dev *rtwdev, const struct rtw89_reg5_def *def) = {
[RTW89_RFK_F_WRF] = _rfk_write_rf,
[RTW89_RFK_F_WM] = _rfk_write32_mask,
[RTW89_RFK_F_WS] = _rfk_write32_set,
[RTW89_RFK_F_WC] = _rfk_write32_clr,
[RTW89_RFK_F_DELAY] = _rfk_delay,
};
static_assert(ARRAY_SIZE(_rfk_handler) == RTW89_RFK_F_NUM);
static void
rtw89_rfk_parser(struct rtw89_dev *rtwdev, const struct rtw89_rfk_tbl *tbl)
{
const struct rtw89_reg5_def *p = tbl->defs;
const struct rtw89_reg5_def *end = tbl->defs + tbl->size;
for (; p < end; p++)
_rfk_handler[p->flag](rtwdev, p);
}
#define rtw89_rfk_parser_by_cond(rtwdev, cond, tbl_t, tbl_f) \
do { \
typeof(rtwdev) _dev = (rtwdev); \
if (cond) \
rtw89_rfk_parser(_dev, (tbl_t)); \
else \
rtw89_rfk_parser(_dev, (tbl_f)); \
} while (0)
static u8 _kpath(struct rtw89_dev *rtwdev, enum rtw89_phy_idx phy_idx)
{
rtw89_debug(rtwdev, RTW89_DBG_RFK, "[RFK]dbcc_en: %x, PHY%d\n",
......
......@@ -5,54 +5,7 @@
#ifndef __RTW89_8852A_RFK_TABLE_H__
#define __RTW89_8852A_RFK_TABLE_H__
#include "core.h"
enum rtw89_rfk_flag {
RTW89_RFK_F_WRF = 0,
RTW89_RFK_F_WM = 1,
RTW89_RFK_F_WS = 2,
RTW89_RFK_F_WC = 3,
RTW89_RFK_F_DELAY = 4,
RTW89_RFK_F_NUM,
};
struct rtw89_rfk_tbl {
const struct rtw89_reg5_def *defs;
u32 size;
};
#define DECLARE_RFK_TBL(_name) \
const struct rtw89_rfk_tbl _name ## _tbl = { \
.defs = _name, \
.size = ARRAY_SIZE(_name), \
}
#define DECL_RFK_WRF(_path, _addr, _mask, _data) \
{.flag = RTW89_RFK_F_WRF, \
.path = _path, \
.addr = _addr, \
.mask = _mask, \
.data = _data,}
#define DECL_RFK_WM(_addr, _mask, _data) \
{.flag = RTW89_RFK_F_WM, \
.addr = _addr, \
.mask = _mask, \
.data = _data,}
#define DECL_RFK_WS(_addr, _mask) \
{.flag = RTW89_RFK_F_WS, \
.addr = _addr, \
.mask = _mask,}
#define DECL_RFK_WC(_addr, _mask) \
{.flag = RTW89_RFK_F_WC, \
.addr = _addr, \
.mask = _mask,}
#define DECL_RFK_DELAY(_data) \
{.flag = RTW89_RFK_F_DELAY, \
.data = _data,}
#include "phy.h"
extern const struct rtw89_rfk_tbl rtw8852a_tssi_sys_defs_tbl;
extern const struct rtw89_rfk_tbl rtw8852a_tssi_sys_defs_2g_tbl;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment