@@ -44,29 +44,14 @@ int spi_mcux_release(const struct device *dev, const struct spi_config *spi_cfg)
44
44
return 0 ;
45
45
}
46
46
47
- int spi_mcux_configure ( const struct device * dev , const struct spi_config * spi_cfg )
47
+ static inline int lpspi_validate_xfer_args ( const struct spi_config * spi_cfg )
48
48
{
49
- const struct spi_mcux_config * config = dev -> config ;
50
- struct spi_mcux_data * data = dev -> data ;
51
- struct spi_context * ctx = & data -> ctx ;
52
- LPSPI_Type * base = (LPSPI_Type * )DEVICE_MMIO_NAMED_GET (dev , reg_base );
53
49
uint32_t word_size = SPI_WORD_SIZE_GET (spi_cfg -> operation );
54
- bool configured = ctx -> config != NULL ;
55
- lpspi_master_config_t master_config ;
56
- uint32_t clock_freq ;
57
- int ret ;
58
-
59
- /* fast path to avoid reconfigure */
60
- /* TODO: S32K3 errata ERR050456 requiring module reset before every transfer,
61
- * investigate alternative workaround so we don't have this latency for S32.
62
- */
63
- if (spi_context_configured (ctx , spi_cfg ) && !IS_ENABLED (CONFIG_SOC_FAMILY_NXP_S32 )) {
64
- return 0 ;
65
- }
50
+ uint32_t pcs = spi_cfg -> slave ;
66
51
67
52
if (spi_cfg -> operation & SPI_HALF_DUPLEX ) {
68
53
/* the IP DOES support half duplex, need to implement driver support */
69
- LOG_ERR ("Half-duplex not supported" );
54
+ LOG_WRN ("Half-duplex not supported" );
70
55
return - ENOTSUP ;
71
56
}
72
57
@@ -78,22 +63,49 @@ int spi_mcux_configure(const struct device *dev, const struct spi_config *spi_cf
78
63
* Minimum hardware word size is 2. Since this driver is intended to work
79
64
* for 32 bit platforms, and 64 bits is max size, then only 33 and 1 are invalid.
80
65
*/
81
- LOG_ERR ("Word size %d not allowed" , word_size );
66
+ LOG_WRN ("Word size %d not allowed" , word_size );
82
67
return - EINVAL ;
83
68
}
84
69
85
- if (spi_cfg -> slave > (LPSPI_CHIP_SELECT_COUNT - 1 )) {
86
- LOG_ERR ("Peripheral %d select exceeds max %d" , spi_cfg -> slave ,
87
- LPSPI_CHIP_SELECT_COUNT - 1 );
70
+ if (pcs > LPSPI_CHIP_SELECT_COUNT - 1 ) {
71
+ LOG_WRN ("Peripheral %d select exceeds max %d" , pcs , LPSPI_CHIP_SELECT_COUNT - 1 );
88
72
return - EINVAL ;
89
73
}
90
74
75
+ return 0 ;
76
+ }
77
+
78
+ int spi_mcux_configure (const struct device * dev , const struct spi_config * spi_cfg )
79
+ {
80
+ const struct spi_mcux_config * config = dev -> config ;
81
+ struct spi_mcux_data * data = dev -> data ;
82
+ struct spi_context * ctx = & data -> ctx ;
83
+ bool already_configured = spi_context_configured (ctx , spi_cfg );
84
+ LPSPI_Type * base = (LPSPI_Type * )DEVICE_MMIO_NAMED_GET (dev , reg_base );
85
+ uint32_t word_size = SPI_WORD_SIZE_GET (spi_cfg -> operation );
86
+ lpspi_master_config_t master_config ;
87
+ uint32_t clock_freq ;
88
+ int ret ;
89
+
90
+ /* fast path to avoid reconfigure */
91
+ /* TODO: S32K3 errata ERR050456 requiring module reset before every transfer,
92
+ * investigate alternative workaround so we don't have this latency for S32.
93
+ */
94
+ if (already_configured && !IS_ENABLED (CONFIG_SOC_FAMILY_NXP_S32 )) {
95
+ return 0 ;
96
+ }
97
+
98
+ ret = lpspi_validate_xfer_args (spi_cfg );
99
+ if (ret ) {
100
+ return ret ;
101
+ }
102
+
91
103
ret = clock_control_get_rate (config -> clock_dev , config -> clock_subsys , & clock_freq );
92
104
if (ret ) {
93
105
return ret ;
94
106
}
95
107
96
- if (configured ) {
108
+ if (already_configured ) {
97
109
/* Setting the baud rate in LPSPI_MasterInit requires module to be disabled. Only
98
110
* disable if already configured, otherwise the clock is not enabled and the
99
111
* CR register cannot be written.
0 commit comments