Skip to content

Commit 2b2142f

Browse files
Jay Fangbroonie
authored andcommitted
spi: hisi-kunpeng: Add debugfs support
This patch uses debugfs_regset32 interface to create the registers dump file. Use it instead of creating a generic debugfs file with manually written read callback function. With these entries, users can check all the SPI controller registers during run time. Signed-off-by: Jay Fang <f.fangjian@huawei.com> Link: https://lore.kernel.org/r/1622789718-13977-1-git-send-email-f.fangjian@huawei.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 6829222 commit 2b2142f

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

drivers/spi/spi-hisi-kunpeng.c

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <linux/acpi.h>
1111
#include <linux/bitfield.h>
12+
#include <linux/debugfs.h>
1213
#include <linux/delay.h>
1314
#include <linux/err.h>
1415
#include <linux/interrupt.h>
@@ -126,15 +127,57 @@ struct hisi_spi {
126127
void __iomem *regs;
127128
int irq;
128129
u32 fifo_len; /* depth of the FIFO buffer */
130+
u16 bus_num;
129131

130132
/* Current message transfer state info */
131133
const void *tx;
132134
unsigned int tx_len;
133135
void *rx;
134136
unsigned int rx_len;
135137
u8 n_bytes; /* current is a 1/2/4 bytes op */
138+
139+
struct dentry *debugfs;
140+
struct debugfs_regset32 regset;
141+
};
142+
143+
#define HISI_SPI_DBGFS_REG(_name, _off) \
144+
{ \
145+
.name = _name, \
146+
.offset = _off, \
147+
}
148+
149+
static const struct debugfs_reg32 hisi_spi_regs[] = {
150+
HISI_SPI_DBGFS_REG("CSCR", HISI_SPI_CSCR),
151+
HISI_SPI_DBGFS_REG("CR", HISI_SPI_CR),
152+
HISI_SPI_DBGFS_REG("ENR", HISI_SPI_ENR),
153+
HISI_SPI_DBGFS_REG("FIFOC", HISI_SPI_FIFOC),
154+
HISI_SPI_DBGFS_REG("IMR", HISI_SPI_IMR),
155+
HISI_SPI_DBGFS_REG("DIN", HISI_SPI_DIN),
156+
HISI_SPI_DBGFS_REG("DOUT", HISI_SPI_DOUT),
157+
HISI_SPI_DBGFS_REG("SR", HISI_SPI_SR),
158+
HISI_SPI_DBGFS_REG("RISR", HISI_SPI_RISR),
159+
HISI_SPI_DBGFS_REG("ISR", HISI_SPI_ISR),
160+
HISI_SPI_DBGFS_REG("ICR", HISI_SPI_ICR),
161+
HISI_SPI_DBGFS_REG("VERSION", HISI_SPI_VERSION),
136162
};
137163

164+
static int hisi_spi_debugfs_init(struct hisi_spi *hs)
165+
{
166+
char name[32];
167+
168+
snprintf(name, 32, "hisi_spi%d", hs->bus_num);
169+
hs->debugfs = debugfs_create_dir(name, NULL);
170+
if (!hs->debugfs)
171+
return -ENOMEM;
172+
173+
hs->regset.regs = hisi_spi_regs;
174+
hs->regset.nregs = ARRAY_SIZE(hisi_spi_regs);
175+
hs->regset.base = hs->regs;
176+
debugfs_create_regset32("registers", 0400, hs->debugfs, &hs->regset);
177+
178+
return 0;
179+
}
180+
138181
static u32 hisi_spi_busy(struct hisi_spi *hs)
139182
{
140183
return readl(hs->regs + HISI_SPI_SR) & SR_BUSY;
@@ -424,6 +467,7 @@ static int hisi_spi_probe(struct platform_device *pdev)
424467
hs = spi_controller_get_devdata(master);
425468
hs->dev = dev;
426469
hs->irq = irq;
470+
hs->bus_num = pdev->id;
427471

428472
hs->regs = devm_platform_ioremap_resource(pdev, 0);
429473
if (IS_ERR(hs->regs))
@@ -446,7 +490,7 @@ static int hisi_spi_probe(struct platform_device *pdev)
446490
master->use_gpio_descriptors = true;
447491
master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LOOP;
448492
master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32);
449-
master->bus_num = pdev->id;
493+
master->bus_num = hs->bus_num;
450494
master->setup = hisi_spi_setup;
451495
master->cleanup = hisi_spi_cleanup;
452496
master->transfer_one = hisi_spi_transfer_one;
@@ -462,6 +506,9 @@ static int hisi_spi_probe(struct platform_device *pdev)
462506
return ret;
463507
}
464508

509+
if (hisi_spi_debugfs_init(hs))
510+
dev_info(dev, "failed to create debugfs dir\n");
511+
465512
ret = spi_register_controller(master);
466513
if (ret) {
467514
dev_err(dev, "failed to register spi master, ret=%d\n", ret);
@@ -478,7 +525,9 @@ static int hisi_spi_probe(struct platform_device *pdev)
478525
static int hisi_spi_remove(struct platform_device *pdev)
479526
{
480527
struct spi_controller *master = platform_get_drvdata(pdev);
528+
struct hisi_spi *hs = spi_controller_get_devdata(master);
481529

530+
debugfs_remove_recursive(hs->debugfs);
482531
spi_unregister_controller(master);
483532

484533
return 0;

0 commit comments

Comments
 (0)