@@ -69,29 +69,14 @@ int spi_mcux_release(const struct device *dev, const struct spi_config *spi_cfg)
6969 return 0 ;
7070}
7171
72- int spi_mcux_configure ( const struct device * dev , const struct spi_config * spi_cfg )
72+ static inline int lpspi_validate_xfer_args ( const struct spi_config * spi_cfg )
7373{
74- const struct spi_mcux_config * config = dev -> config ;
75- struct spi_mcux_data * data = dev -> data ;
76- struct spi_context * ctx = & data -> ctx ;
77- LPSPI_Type * base = (LPSPI_Type * )DEVICE_MMIO_NAMED_GET (dev , reg_base );
7874 uint32_t word_size = SPI_WORD_SIZE_GET (spi_cfg -> operation );
79- bool configured = ctx -> config != NULL ;
80- lpspi_master_config_t master_config ;
81- uint32_t clock_freq ;
82- int ret ;
83-
84- /* fast path to avoid reconfigure */
85- /* TODO: S32K3 errata ERR050456 requiring module reset before every transfer,
86- * investigate alternative workaround so we don't have this latency for S32.
87- */
88- if (spi_context_configured (ctx , spi_cfg ) && !IS_ENABLED (CONFIG_SOC_FAMILY_NXP_S32 )) {
89- return 0 ;
90- }
75+ uint32_t pcs = spi_cfg -> slave ;
9176
9277 if (spi_cfg -> operation & SPI_HALF_DUPLEX ) {
9378 /* the IP DOES support half duplex, need to implement driver support */
94- LOG_ERR ("Half-duplex not supported" );
79+ LOG_WRN ("Half-duplex not supported" );
9580 return - ENOTSUP ;
9681 }
9782
@@ -103,22 +88,49 @@ int spi_mcux_configure(const struct device *dev, const struct spi_config *spi_cf
10388 * Minimum hardware word size is 2. Since this driver is intended to work
10489 * for 32 bit platforms, and 64 bits is max size, then only 33 and 1 are invalid.
10590 */
106- LOG_ERR ("Word size %d not allowed" , word_size );
91+ LOG_WRN ("Word size %d not allowed" , word_size );
10792 return - EINVAL ;
10893 }
10994
110- if (spi_cfg -> slave > (LPSPI_CHIP_SELECT_COUNT - 1 )) {
111- LOG_ERR ("Peripheral %d select exceeds max %d" , spi_cfg -> slave ,
112- LPSPI_CHIP_SELECT_COUNT - 1 );
95+ if (pcs > LPSPI_CHIP_SELECT_COUNT - 1 ) {
96+ LOG_WRN ("Peripheral %d select exceeds max %d" , pcs , LPSPI_CHIP_SELECT_COUNT - 1 );
11397 return - EINVAL ;
11498 }
11599
100+ return 0 ;
101+ }
102+
103+ int spi_mcux_configure (const struct device * dev , const struct spi_config * spi_cfg )
104+ {
105+ const struct spi_mcux_config * config = dev -> config ;
106+ struct spi_mcux_data * data = dev -> data ;
107+ struct spi_context * ctx = & data -> ctx ;
108+ bool already_configured = spi_context_configured (ctx , spi_cfg );
109+ LPSPI_Type * base = (LPSPI_Type * )DEVICE_MMIO_NAMED_GET (dev , reg_base );
110+ uint32_t word_size = SPI_WORD_SIZE_GET (spi_cfg -> operation );
111+ lpspi_master_config_t master_config ;
112+ uint32_t clock_freq ;
113+ int ret ;
114+
115+ /* fast path to avoid reconfigure */
116+ /* TODO: S32K3 errata ERR050456 requiring module reset before every transfer,
117+ * investigate alternative workaround so we don't have this latency for S32.
118+ */
119+ if (already_configured && !IS_ENABLED (CONFIG_SOC_FAMILY_NXP_S32 )) {
120+ return 0 ;
121+ }
122+
123+ ret = lpspi_validate_xfer_args (spi_cfg );
124+ if (ret ) {
125+ return ret ;
126+ }
127+
116128 ret = clock_control_get_rate (config -> clock_dev , config -> clock_subsys , & clock_freq );
117129 if (ret ) {
118130 return ret ;
119131 }
120132
121- if (configured ) {
133+ if (already_configured ) {
122134 /* Setting the baud rate in LPSPI_MasterInit requires module to be disabled. Only
123135 * disable if already configured, otherwise the clock is not enabled and the
124136 * CR register cannot be written.
0 commit comments