@@ -69,29 +69,14 @@ int spi_mcux_release(const struct device *dev, const struct spi_config *spi_cfg)
69
69
return 0 ;
70
70
}
71
71
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 )
73
73
{
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 );
78
74
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 ;
91
76
92
77
if (spi_cfg -> operation & SPI_HALF_DUPLEX ) {
93
78
/* 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" );
95
80
return - ENOTSUP ;
96
81
}
97
82
@@ -103,22 +88,49 @@ int spi_mcux_configure(const struct device *dev, const struct spi_config *spi_cf
103
88
* Minimum hardware word size is 2. Since this driver is intended to work
104
89
* for 32 bit platforms, and 64 bits is max size, then only 33 and 1 are invalid.
105
90
*/
106
- LOG_ERR ("Word size %d not allowed" , word_size );
91
+ LOG_WRN ("Word size %d not allowed" , word_size );
107
92
return - EINVAL ;
108
93
}
109
94
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 );
113
97
return - EINVAL ;
114
98
}
115
99
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
+
116
128
ret = clock_control_get_rate (config -> clock_dev , config -> clock_subsys , & clock_freq );
117
129
if (ret ) {
118
130
return ret ;
119
131
}
120
132
121
- if (configured ) {
133
+ if (already_configured ) {
122
134
/* Setting the baud rate in LPSPI_MasterInit requires module to be disabled. Only
123
135
* disable if already configured, otherwise the clock is not enabled and the
124
136
* CR register cannot be written.
0 commit comments