// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
/* Copyright(c) 2018-2019 Realtek Corporation
*/
#include <linux/debugfs.h>
#include <linux/seq_file.h>
#include "main.h"
#include "coex.h"
#include "sec.h"
#include "fw.h"
#include "debug.h"
#include "phy.h"
#ifdef CONFIG_RTW88_DEBUGFS
struct rtw_debugfs_priv {
struct rtw_dev *rtwdev;
int (*cb_read)(struct seq_file *m, void *v);
ssize_t (*cb_write)(struct file *filp, const char __user *buffer,
size_t count, loff_t *loff);
union {
u32 cb_data;
u8 *buf;
struct {
u32 page_offset;
u32 page_num;
} rsvd_page;
struct {
u8 rf_path;
u32 rf_addr;
u32 rf_mask;
};
struct {
u32 addr;
u32 len;
} read_reg;
};
};
static int rtw_debugfs_single_show(struct seq_file *m, void *v)
{
struct rtw_debugfs_priv *debugfs_priv = m->private;
return debugfs_priv->cb_read(m, v);
}
static ssize_t rtw_debugfs_common_write(struct file *filp,
const char __user *buffer,
size_t count, loff_t *loff)
{
struct rtw_debugfs_priv *debugfs_priv = filp->private_data;
return debugfs_priv->cb_write(filp, buffer, count, loff);
}
static ssize_t rtw_debugfs_single_write(struct file *filp,
const char __user *buffer,
size_t count, loff_t *loff)
{
struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
return debugfs_priv->cb_write(filp, buffer, count, loff);
}
static int rtw_debugfs_single_open_rw(struct inode *inode, struct file *filp)
{
return single_open(filp, rtw_debugfs_single_show, inode->i_private);
}
static int rtw_debugfs_close(struct inode *inode, struct file *filp)
{
return 0;
}
static const struct file_operations file_ops_single_r = {
.owner = THIS_MODULE,
.open = rtw_debugfs_single_open_rw,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
static const struct file_operations file_ops_single_rw = {
.owner = THIS_MODULE,
.open = rtw_debugfs_single_open_rw,
.release = single_release,
.read = seq_read,
.llseek = seq_lseek,
.write = rtw_debugfs_single_write,
};
static const struct file_operations file_ops_common_write = {
.owner = THIS_MODULE,
.write = rtw_debugfs_common_write,
.open = simple_open,
.release = rtw_debugfs_close,
};
static int rtw_debugfs_get_read_reg(struct seq_file *m, void *v)
{
struct rtw_debugfs_priv *debugfs_priv = m->private;
struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
u32 val, len, addr;
len = debugfs_priv->read_reg.len;
addr = debugfs_priv->read_reg.addr;
switch (len) {
case 1:
val = rtw_read8(rtwdev, addr);
seq_printf(m, "reg 0x%03x: 0x%02x\n", addr, val);
break;
case 2:
val = rtw_read16(rtwdev, addr);
seq_printf(m, "reg 0x%03x: 0x%04x\n", addr, val);
break;
case 4:
val = rtw_read32(rtwdev, addr);
seq_printf(m, "reg 0x%03x: 0x%08x\n", addr, val);
break;
}
return 0;
}
static int rtw_debugfs_get_rf_read(struct seq_file *m, void *v)
{
struct rtw_debugfs_priv *debugfs_priv = m->private;
s