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+
138181static 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)
478525static 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