Skip to content

Commit e164be7

Browse files
fancerbroonie
authored andcommitted
spi: dw: Add a number of native CS auto-detection
Aside with the FIFO depth and DFS field size it's possible to auto-detect a number of native chip-select synthesized in the DW APB/AHB SSI IP-core. It can be done just by writing ones to the SER register. The number of writable flags in the register is limited by the SSI_NUM_SLAVES IP-core synthesize parameter. All the upper flags are read-only and wired to zero. Based on that let's add the number of native CS auto-detection procedure so the low-level platform drivers wouldn't need to manually set it up unless it's required to set a constraint due to platform-specific reasons (for instance, due to a hardware bug). Signed-off-by: Serge Semin <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 11ae2e6 commit e164be7

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

drivers/spi/spi-dw-core.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,20 @@ static void dw_spi_hw_init(struct device *dev, struct dw_spi *dws)
834834
DW_SPI_GET_BYTE(dws->ver, 1));
835835
}
836836

837+
/*
838+
* Try to detect the number of native chip-selects if the platform
839+
* driver didn't set it up. There can be up to 16 lines configured.
840+
*/
841+
if (!dws->num_cs) {
842+
u32 ser;
843+
844+
dw_writel(dws, DW_SPI_SER, 0xffff);
845+
ser = dw_readl(dws, DW_SPI_SER);
846+
dw_writel(dws, DW_SPI_SER, 0);
847+
848+
dws->num_cs = hweight16(ser);
849+
}
850+
837851
/*
838852
* Try to detect the FIFO depth if not set by interface driver,
839853
* the depth could be from 2 to 256 from HW spec

0 commit comments

Comments
 (0)