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