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 <jukka.laitinen@tii.ae>
This commit is contained in:
Jukka Laitinen
2025-11-19 11:35:06 +02:00
committed by Alan C. Assis
parent fbd27c045b
commit f641298d9e
2 changed files with 55 additions and 0 deletions

View File

@@ -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 */

View File

@@ -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)
}