21
21
extern "C" {
22
22
#endif
23
23
24
+ #if defined(DT_DRV_COMPAT ) && !DT_ANY_INST_HAS_PROP_STATUS_OKAY (cs_gpios )
25
+ #define DT_SPI_CTX_HAS_NO_CS_GPIOS 1
26
+ #endif
27
+
24
28
enum spi_ctx_runtime_op_mode {
25
29
SPI_CTX_RUNTIME_OP_MODE_MASTER = BIT (0 ),
26
30
SPI_CTX_RUNTIME_OP_MODE_SLAVE = BIT (1 ),
@@ -31,8 +35,10 @@ struct spi_context {
31
35
#ifdef CONFIG_MULTITHREADING
32
36
const struct spi_config * owner ;
33
37
#endif
38
+ #ifndef DT_SPI_CTX_HAS_NO_CS_GPIOS
34
39
const struct gpio_dt_spec * cs_gpios ;
35
40
size_t num_cs_gpios ;
41
+ #endif /* !DT_SPI_CTX_HAS_NO_CS_GPIOS */
36
42
37
43
#ifdef CONFIG_MULTITHREADING
38
44
struct k_sem lock ;
@@ -71,6 +77,7 @@ struct spi_context {
71
77
#define SPI_CONTEXT_INIT_SYNC (_data , _ctx_name ) \
72
78
._ctx_name.sync = Z_SEM_INITIALIZER(_data._ctx_name.sync, 0, 1)
73
79
80
+ #ifndef DT_SPI_CTX_HAS_NO_CS_GPIOS
74
81
#define SPI_CONTEXT_CS_GPIO_SPEC_ELEM (_node_id , _prop , _idx ) \
75
82
GPIO_DT_SPEC_GET_BY_IDX(_node_id, _prop, _idx),
76
83
@@ -84,6 +91,9 @@ struct spi_context {
84
91
(SPI_CONTEXT_CS_GPIOS_FOREACH_ELEM(_node_id)), ({0})) \
85
92
}, \
86
93
._ctx_name.num_cs_gpios = DT_PROP_LEN_OR(_node_id, cs_gpios, 0),
94
+ #else /* DT_SPI_CTX_HAS_NO_CS_GPIOS */
95
+ #define SPI_CONTEXT_CS_GPIOS_INITIALIZE (...)
96
+ #endif /* DT_SPI_CTX_HAS_NO_CS_GPIOS */
87
97
88
98
/*
89
99
* Checks if a spi config is the same as the one stored in the spi_context
@@ -292,6 +302,13 @@ static inline void spi_context_complete(struct spi_context *ctx,
292
302
#endif /* CONFIG_SPI_ASYNC */
293
303
}
294
304
305
+ #ifdef DT_SPI_CTX_HAS_NO_CS_GPIOS
306
+ #define spi_context_cs_configure_all (...) 0
307
+ #define spi_context_cs_get_all (...) 0
308
+ #define spi_context_cs_put_all (...) 0
309
+ #define _spi_context_cs_control (...) (void) 0
310
+ #define spi_context_cs_control (...) (void) 0
311
+ #else /* DT_SPI_CTX_HAS_NO_CS_GPIOS */
295
312
/*
296
313
* This function initializes all the chip select GPIOs associated with a spi controller.
297
314
* The context first must be initialized using the SPI_CONTEXT_CS_GPIOS_INITIALIZE macro.
@@ -391,12 +408,13 @@ static inline void spi_context_cs_control(struct spi_context *ctx, bool on)
391
408
{
392
409
_spi_context_cs_control (ctx , on , false);
393
410
}
411
+ #endif /* DT_SPI_CTX_HAS_NO_CS_GPIOS */
394
412
395
413
/* Forcefully releases the spi context and removes the owner, allowing taking the lock
396
414
* with spi_context_lock without the previous owner releasing the lock.
397
415
* This is usually used to aid in implementation of the spi_release driver API.
398
416
*/
399
- static inline void spi_context_unlock_unconditionally (struct spi_context * ctx )
417
+ static inline void spi_context_unlock_unconditionally (struct spi_context * ctx __maybe_unused )
400
418
{
401
419
/* Forcing CS to go to inactive status */
402
420
_spi_context_cs_control (ctx , false, true);
0 commit comments