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
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
@@ -300,8 +310,9 @@ static inline void spi_context_complete(struct spi_context *ctx,
300
310
* Note: If a controller has native CS control in SPI hardware, they should also be initialized
301
311
* during device init by the driver with hardware-specific code.
302
312
*/
303
- static inline int spi_context_cs_configure_all (struct spi_context * ctx )
313
+ static inline int spi_context_cs_configure_all (struct spi_context * ctx __maybe_unused )
304
314
{
315
+ #ifndef DT_SPI_CTX_HAS_NO_CS_GPIOS
305
316
int ret ;
306
317
const struct gpio_dt_spec * cs_gpio ;
307
318
@@ -317,13 +328,16 @@ static inline int spi_context_cs_configure_all(struct spi_context *ctx)
317
328
return ret ;
318
329
}
319
330
}
331
+ #endif /* !DT_SPI_CTX_HAS_NO_CS_GPIOS */
320
332
321
333
return 0 ;
322
334
}
323
335
324
336
/* Helper function to power manage the GPIO CS pins, not meant to be used directly by drivers */
325
- static inline int _spi_context_cs_pm_all (struct spi_context * ctx , bool get )
337
+ static inline int _spi_context_cs_pm_all (struct spi_context * ctx __maybe_unused ,
338
+ bool get __maybe_unused )
326
339
{
340
+ #ifndef DT_SPI_CTX_HAS_NO_CS_GPIOS
327
341
const struct gpio_dt_spec * cs_gpio ;
328
342
int ret ;
329
343
@@ -338,6 +352,7 @@ static inline int _spi_context_cs_pm_all(struct spi_context *ctx, bool get)
338
352
return ret ;
339
353
}
340
354
}
355
+ #endif /* !DT_SPI_CTX_HAS_NO_CS_GPIOS */
341
356
342
357
return 0 ;
343
358
}
@@ -361,9 +376,10 @@ static inline int spi_context_cs_put_all(struct spi_context *ctx)
361
376
}
362
377
363
378
/* Helper function to control the GPIO CS, not meant to be used directly by drivers */
364
- static inline void _spi_context_cs_control (struct spi_context * ctx ,
365
- bool on , bool force_off )
379
+ static inline void _spi_context_cs_control (struct spi_context * ctx __maybe_unused ,
380
+ bool on __maybe_unused , bool force_off __maybe_unused )
366
381
{
382
+ #ifndef DT_SPI_CTX_HAS_NO_CS_GPIOS
367
383
if (ctx -> config && spi_cs_is_gpio (ctx -> config )) {
368
384
if (on ) {
369
385
gpio_pin_set_dt (& ctx -> config -> cs .gpio , 1 );
@@ -378,6 +394,7 @@ static inline void _spi_context_cs_control(struct spi_context *ctx,
378
394
gpio_pin_set_dt (& ctx -> config -> cs .gpio , 0 );
379
395
}
380
396
}
397
+ #endif /* !DT_SPI_CTX_HAS_NO_CS_GPIOS */
381
398
}
382
399
383
400
/* This function should be called by drivers to control the chip select line in master mode
0 commit comments