Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Jay Fang and committed by
Mark Brown
2b2142f2 6829222b

+50 -1
+50 -1
drivers/spi/spi-hisi-kunpeng.c
··· 9 9 10 10 #include <linux/acpi.h> 11 11 #include <linux/bitfield.h> 12 + #include <linux/debugfs.h> 12 13 #include <linux/delay.h> 13 14 #include <linux/err.h> 14 15 #include <linux/interrupt.h> ··· 127 126 void __iomem *regs; 128 127 int irq; 129 128 u32 fifo_len; /* depth of the FIFO buffer */ 129 + u16 bus_num; 130 130 131 131 /* Current message transfer state info */ 132 132 const void *tx; ··· 135 133 void *rx; 136 134 unsigned int rx_len; 137 135 u8 n_bytes; /* current is a 1/2/4 bytes op */ 136 + 137 + struct dentry *debugfs; 138 + struct debugfs_regset32 regset; 138 139 }; 140 + 141 + #define HISI_SPI_DBGFS_REG(_name, _off) \ 142 + { \ 143 + .name = _name, \ 144 + .offset = _off, \ 145 + } 146 + 147 + static const struct debugfs_reg32 hisi_spi_regs[] = { 148 + HISI_SPI_DBGFS_REG("CSCR", HISI_SPI_CSCR), 149 + HISI_SPI_DBGFS_REG("CR", HISI_SPI_CR), 150 + HISI_SPI_DBGFS_REG("ENR", HISI_SPI_ENR), 151 + HISI_SPI_DBGFS_REG("FIFOC", HISI_SPI_FIFOC), 152 + HISI_SPI_DBGFS_REG("IMR", HISI_SPI_IMR), 153 + HISI_SPI_DBGFS_REG("DIN", HISI_SPI_DIN), 154 + HISI_SPI_DBGFS_REG("DOUT", HISI_SPI_DOUT), 155 + HISI_SPI_DBGFS_REG("SR", HISI_SPI_SR), 156 + HISI_SPI_DBGFS_REG("RISR", HISI_SPI_RISR), 157 + HISI_SPI_DBGFS_REG("ISR", HISI_SPI_ISR), 158 + HISI_SPI_DBGFS_REG("ICR", HISI_SPI_ICR), 159 + HISI_SPI_DBGFS_REG("VERSION", HISI_SPI_VERSION), 160 + }; 161 + 162 + static int hisi_spi_debugfs_init(struct hisi_spi *hs) 163 + { 164 + char name[32]; 165 + 166 + snprintf(name, 32, "hisi_spi%d", hs->bus_num); 167 + hs->debugfs = debugfs_create_dir(name, NULL); 168 + if (!hs->debugfs) 169 + return -ENOMEM; 170 + 171 + hs->regset.regs = hisi_spi_regs; 172 + hs->regset.nregs = ARRAY_SIZE(hisi_spi_regs); 173 + hs->regset.base = hs->regs; 174 + debugfs_create_regset32("registers", 0400, hs->debugfs, &hs->regset); 175 + 176 + return 0; 177 + } 139 178 140 179 static u32 hisi_spi_busy(struct hisi_spi *hs) 141 180 { ··· 467 424 hs = spi_controller_get_devdata(master); 468 425 hs->dev = dev; 469 426 hs->irq = irq; 427 + hs->bus_num = pdev->id; 470 428 471 429 hs->regs = devm_platform_ioremap_resource(pdev, 0); 472 430 if (IS_ERR(hs->regs)) ··· 490 446 master->use_gpio_descriptors = true; 491 447 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LOOP; 492 448 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32); 493 - master->bus_num = pdev->id; 449 + master->bus_num = hs->bus_num; 494 450 master->setup = hisi_spi_setup; 495 451 master->cleanup = hisi_spi_cleanup; 496 452 master->transfer_one = hisi_spi_transfer_one; ··· 505 461 dev_err(dev, "failed to get IRQ=%d, ret=%d\n", hs->irq, ret); 506 462 return ret; 507 463 } 464 + 465 + if (hisi_spi_debugfs_init(hs)) 466 + dev_info(dev, "failed to create debugfs dir\n"); 508 467 509 468 ret = spi_register_controller(master); 510 469 if (ret) { ··· 525 478 static int hisi_spi_remove(struct platform_device *pdev) 526 479 { 527 480 struct spi_controller *master = platform_get_drvdata(pdev); 481 + struct hisi_spi *hs = spi_controller_get_devdata(master); 528 482 483 + debugfs_remove_recursive(hs->debugfs); 529 484 spi_unregister_controller(master); 530 485 531 486 return 0;