Skip to content

Commit fe4e819

Browse files
ovpanaitgregkh
authored andcommitted
staging: axis-fifo: add debugfs interface for dumping fifo registers
For debugging purposes, add a simple, read-only debugfs interface to dump the following fifo registers: ISR - Interrupt Status Register IER - Interrupt Enable Register TDFV - Transmit Data FIFO Vacancy RDFO - Receive Data FIFO Occupancy $ cat /sys/kernel/debug/43c00000.axi_fifo_mm_s/regs isr: 0x00000000 ier: 0xfe000000 tdfv: 0x000001fc rdfo: 0x00000000 Signed-off-by: Ovidiu Panait <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent ff9ec95 commit fe4e819

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

drivers/staging/axis-fifo/axis-fifo.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <linux/uaccess.h>
3434
#include <linux/jiffies.h>
3535
#include <linux/miscdevice.h>
36+
#include <linux/debugfs.h>
3637

3738
/* ----------------------------
3839
* driver parameters
@@ -44,6 +45,8 @@
4445
#define READ_BUF_SIZE 128U /* read buffer length in words */
4546
#define WRITE_BUF_SIZE 128U /* write buffer length in words */
4647

48+
#define AXIS_FIFO_DEBUG_REG_NAME_MAX_LEN 4
49+
4750
/* ----------------------------
4851
* IP register offsets
4952
* ----------------------------
@@ -137,6 +140,13 @@ struct axis_fifo {
137140

138141
struct device *dt_device; /* device created from the device tree */
139142
struct miscdevice miscdev;
143+
144+
struct dentry *debugfs_dir;
145+
};
146+
147+
struct axis_fifo_debug_reg {
148+
const char * const name;
149+
unsigned int offset;
140150
};
141151

142152
/* ----------------------------
@@ -537,6 +547,37 @@ static const struct file_operations fops = {
537547
.write = axis_fifo_write
538548
};
539549

550+
static int axis_fifo_debugfs_regs_show(struct seq_file *m, void *p)
551+
{
552+
static const struct axis_fifo_debug_reg regs[] = {
553+
{"isr", XLLF_ISR_OFFSET},
554+
{"ier", XLLF_IER_OFFSET},
555+
{"tdfv", XLLF_TDFV_OFFSET},
556+
{"rdfo", XLLF_RDFO_OFFSET},
557+
{ /* Sentinel */ },
558+
};
559+
const struct axis_fifo_debug_reg *reg;
560+
struct axis_fifo *fifo = m->private;
561+
562+
for (reg = regs; reg->name; ++reg) {
563+
u32 val = ioread32(fifo->base_addr + reg->offset);
564+
565+
seq_printf(m, "%*s: 0x%08x\n", AXIS_FIFO_DEBUG_REG_NAME_MAX_LEN,
566+
reg->name, val);
567+
}
568+
569+
return 0;
570+
}
571+
DEFINE_SHOW_ATTRIBUTE(axis_fifo_debugfs_regs);
572+
573+
static void axis_fifo_debugfs_init(struct axis_fifo *fifo)
574+
{
575+
fifo->debugfs_dir = debugfs_create_dir(dev_name(fifo->dt_device), NULL);
576+
577+
debugfs_create_file("regs", 0444, fifo->debugfs_dir, fifo,
578+
&axis_fifo_debugfs_regs_fops);
579+
}
580+
540581
/* read named property from the device tree */
541582
static int get_dts_property(struct axis_fifo *fifo,
542583
char *name, unsigned int *var)
@@ -708,6 +749,8 @@ static int axis_fifo_probe(struct platform_device *pdev)
708749
if (rc < 0)
709750
goto err_initial;
710751

752+
axis_fifo_debugfs_init(fifo);
753+
711754
return 0;
712755

713756
err_initial:
@@ -720,6 +763,7 @@ static void axis_fifo_remove(struct platform_device *pdev)
720763
struct device *dev = &pdev->dev;
721764
struct axis_fifo *fifo = dev_get_drvdata(dev);
722765

766+
debugfs_remove(fifo->debugfs_dir);
723767
misc_deregister(&fifo->miscdev);
724768
dev_set_drvdata(dev, NULL);
725769
}

0 commit comments

Comments
 (0)