This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit f641298d9e727fae417ca76490b3657248753d78 Author: Jukka Laitinen <[email protected]> AuthorDate: Wed Nov 19 11:35:06 2025 +0200 arch/imx9: Enable manual control for LPSPI PCS signals Add a function imx9_lpspi_select_cs to assert CS at the start of an SPI transfer and keep it asserted until called again to de-assert it. This can be called by board-provided imx9_lpspi_select, in case the CS needs to be controlled via the LPSPI block and not GPIO. The TCR register CONT (continue) bit is asserted to prevent CS toggling during the transfer, and the PCS bits are set to mark the correct CS Signed-off-by: Jukka Laitinen <[email protected]> --- arch/arm64/src/imx9/imx9_lpspi.c | 34 ++++++++++++++++++++++++++++++++++ arch/arm64/src/imx9/imx9_lpspi.h | 21 +++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/arch/arm64/src/imx9/imx9_lpspi.c b/arch/arm64/src/imx9/imx9_lpspi.c index b6caa7d4d11..5f665334d63 100644 --- a/arch/arm64/src/imx9/imx9_lpspi.c +++ b/arch/arm64/src/imx9/imx9_lpspi.c @@ -2094,4 +2094,38 @@ void imx9_lpspi_uninitialize(struct spi_dev_s *dev) } } +/**************************************************************************** + * Name: imx9_lpspi_select_cs + * + * Description: + * Assert or de-assert internal PCS0 or PCS1 line. Can be called by + * board-specific chip-select logic. Assertion of the CS is done at the + * start of the next transfer and de-assertion after this function is + * called again to de-assert the cs and the transfer has ended. + * + * Input Parameters: + * dev - Device-specific state data + * cs - Chip select 0 or 1 + * select - true: assert CS, false: de-assert CS + * + * Returned Value: + * None + * + ****************************************************************************/ + +void imx9_lpspi_select_cs(struct spi_dev_s *dev, int cs, bool select) +{ + struct imx9_lpspidev_s *priv = (struct imx9_lpspidev_s *)dev; + + if (select) + { + uint32_t pcs = (cs << LPSPI_TCR_PCS_SHIFT) & LPSPI_TCR_PCS_MASK; + imx9_lpspi_modifytcr(priv, LPSPI_TCR_PCS_MASK, pcs | LPSPI_TCR_CONT); + } + else + { + imx9_lpspi_modifytcr(priv, LPSPI_TCR_CONT, 0); + } +} + #endif /* CONFIG_IMX9_LPSPI */ diff --git a/arch/arm64/src/imx9/imx9_lpspi.h b/arch/arm64/src/imx9/imx9_lpspi.h index 0e39c31f696..280474712ef 100644 --- a/arch/arm64/src/imx9/imx9_lpspi.h +++ b/arch/arm64/src/imx9/imx9_lpspi.h @@ -148,6 +148,27 @@ int imx9_lpspi_register(struct spi_dev_s *dev, void *arg); #endif +/**************************************************************************** + * Name: imx9_lpspi_select_cs + * + * Description: + * Assert or de-assert internal PCS0 or PCS1 line. Can be called by + * board-specific chip-select logic. Assertion of the CS is done at the + * start of the next transfer and de-assertion after this function is + * called again to de-assert the cs and the transfer has ended. + * + * Input Parameters: + * dev - Device-specific state data + * cs - Chip select 0 or 1 + * select - true: assert CS, false: de-assert CS + * + * Returned Value: + * None + * + ****************************************************************************/ + +void imx9_lpspi_select_cs(struct spi_dev_s *dev, int cs, bool select); + #undef EXTERN #if defined(__cplusplus) }
