drivers/spi: Adapt Kconfig and generic context to enable slave support

Adding Kconfig options to set supported modes by the controller
(master, slave or both)

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
Tomasz Bursztyka 2017-06-28 12:35:07 +02:00 committed by Carles Cufí
commit 29a68cd7a5
2 changed files with 89 additions and 2 deletions

View file

@ -31,6 +31,13 @@ config SPI_ASYNC
help
This option enables the asynchronous API calls.
config SPI_SLAVE
bool "Enable Slave support [EXPERIMENTAL]"
default n
help
Enables Driver SPI slave operations. Slave support depends
on the driver and the hardware it runs on.
config SPI_INIT_PRIORITY
int "Init priority"
default 70
@ -75,6 +82,17 @@ config SPI_0_NAME
depends on !HAS_DTS_SPI
default "SPI_0"
config SPI_0_OP_MODES
int "Port 0 supported operation modes (master/slave/both)"
default 1
range 1 3
help
This sets the supported operation modes at runtime, by the SPI
port 0, where:
1 is MASTER mode only (default)
2 is SLAVE mode only
3 is both modes are available.
config SPI_0_IRQ_PRI
int "Port 0 interrupt priority"
@ -111,6 +129,17 @@ config SPI_1_NAME
depends on !HAS_DTS_SPI
default "SPI_1"
config SPI_1_OP_MODES
int "Port 1 supported operation modes (master/slave/both)"
default 1
range 1 3
help
This sets the supported operation modes at runtime, by the SPI
port 1, where:
1 is MASTER mode only (default)
2 is SLAVE mode only
3 is both modes are available.
config SPI_1_IRQ_PRI
int "Port 0 interrupt priority"
depends on !HAS_DTS_SPI
@ -148,6 +177,17 @@ config SPI_2_NAME
depends on !HAS_DTS_SPI
default "SPI_2"
config SPI_2_OP_MODES
int "Port 2 supported operation modes (master/slave/both)"
default 1
range 1 3
help
This sets the supported operation modes at runtime, by the SPI
port 2, where:
1 is MASTER mode only (default)
2 is SLAVE mode only
3 is both modes are available.
config SPI_2_IRQ_PRI
int "Port 2 interrupt priority"
depends on !HAS_DTS_SPI
@ -185,6 +225,17 @@ config SPI_3_NAME
depends on !HAS_DTS_SPI
default "SPI_3"
config SPI_3_OP_MODES
int "Port 3 supported operation modes (master/slave/both)"
default 1
range 1 3
help
This sets the supported operation modes at runtime, by the SPI
port 3, where:
1 is MASTER mode only (default)
2 is SLAVE mode only
3 is both modes are available.
config SPI_3_IRQ_PRI
int "Port 3 interrupt priority"
depends on !HAS_DTS_SPI
@ -202,6 +253,18 @@ config SPI_4_NAME
depends on SPI_4
default "SPI_4"
config SPI_4_OP_MODES
int "Port 4 supported operation modes (master/slave/both)"
depends on SPI_4
default 1
range 1 3
help
This sets the supported operation modes at runtime, by the SPI
port 4, where:
1 is MASTER mode only (default)
2 is SLAVE mode only
3 is both modes are available.
config SPI_5
bool "SPI port 5"
default n
@ -213,6 +276,18 @@ config SPI_5_NAME
depends on SPI_5
default "SPI_5"
config SPI_5_OP_MODES
int "Port 5 supported operation modes (master/slave/both)"
depends on SPI_5
default 1
range 1 3
help
This sets the supported operation modes at runtime, by the SPI
port 5, where:
1 is MASTER mode only (default)
2 is SLAVE mode only
3 is both modes are available.
if SPI_LEGACY_API
config SPI_INTEL

View file

@ -19,6 +19,11 @@
extern "C" {
#endif
enum spi_ctx_runtime_op_mode {
SPI_CTX_RUNTIME_OP_MODE_MASTER = BIT(0),
SPI_CTX_RUNTIME_OP_MODE_SLAVE = BIT(1),
};
struct spi_context {
const struct spi_config *config;
@ -53,6 +58,11 @@ static inline bool spi_context_configured(struct spi_context *ctx,
return !!(ctx->config == config);
}
static inline bool spi_context_is_slave(struct spi_context *ctx)
{
return (ctx->config->operation & SPI_OP_MODE_SLAVE);
}
static inline void spi_context_lock(struct spi_context *ctx,
bool asynchronous,
struct k_poll_signal *signal)
@ -67,7 +77,8 @@ static inline void spi_context_lock(struct spi_context *ctx,
static inline void spi_context_release(struct spi_context *ctx, int status)
{
if (!status && (ctx->config->operation & SPI_LOCK_ON)) {
if (!status &&
(ctx->config->operation & (SPI_LOCK_ON | SPI_OP_MODE_SLAVE))) {
return;
}
@ -113,7 +124,8 @@ static inline void spi_context_complete(struct spi_context *ctx, int status)
k_poll_signal(ctx->signal, status);
}
if (!(ctx->config->operation & SPI_LOCK_ON)) {
if (!(ctx->config->operation & (SPI_LOCK_ON |
SPI_OP_MODE_SLAVE))) {
k_sem_give(&ctx->lock);
}
}