drivers: spi_sam0: initialize all cs gpios during init

In case when we have multiple devices connected to the
one SPI interface the initial state of CS gpios after
MCU reset is floating and it might be low that prevents us from
communicating between particular devices. Fix that by
initializing all provided cs gpios and setting them as inactive.

Signed-off-by: Bartosz Bilas <bartosz.bilas@hotmail.com>
This commit is contained in:
Bartosz Bilas 2021-10-07 17:08:55 +02:00 committed by Carles Cufí
commit 81a3900b35

View file

@ -135,7 +135,6 @@ static int spi_sam0_configure(const struct device *dev,
}
data->ctx.config = config;
spi_context_cs_configure(&data->ctx);
return 0;
}
@ -675,6 +674,7 @@ static int spi_sam0_release(const struct device *dev,
static int spi_sam0_init(const struct device *dev)
{
int err;
const struct spi_sam0_config *cfg = dev->config;
struct spi_sam0_data *data = dev->data;
SercomSpi *regs = cfg->regs;
@ -706,6 +706,11 @@ static int spi_sam0_init(const struct device *dev)
data->dev = dev;
#endif
err = spi_context_cs_configure_all(&data->ctx);
if (err < 0) {
return err;
}
spi_context_unlock_unconditionally(&data->ctx);
/* The device will be configured and enabled when transceive
@ -763,6 +768,7 @@ static const struct spi_sam0_config spi_sam0_config_##n = { \
static struct spi_sam0_data spi_sam0_dev_data_##n = { \
SPI_CONTEXT_INIT_LOCK(spi_sam0_dev_data_##n, ctx), \
SPI_CONTEXT_INIT_SYNC(spi_sam0_dev_data_##n, ctx), \
SPI_CONTEXT_CS_GPIOS_INITIALIZE(DT_DRV_INST(n), ctx) \
}; \
DEVICE_DT_INST_DEFINE(n, &spi_sam0_init, NULL, \
&spi_sam0_dev_data_##n, \