drivers: spi_sifive: 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:
parent
81a3900b35
commit
997723b760
1 changed files with 7 additions and 1 deletions
|
@ -153,9 +153,15 @@ void spi_sifive_xfer(const struct device *dev, const bool hw_cs_control)
|
||||||
|
|
||||||
int spi_sifive_init(const struct device *dev)
|
int spi_sifive_init(const struct device *dev)
|
||||||
{
|
{
|
||||||
|
int err;
|
||||||
/* Disable SPI Flash mode */
|
/* Disable SPI Flash mode */
|
||||||
sys_clear_bit(SPI_REG(dev, REG_FCTRL), SF_FCTRL_EN);
|
sys_clear_bit(SPI_REG(dev, REG_FCTRL), SF_FCTRL_EN);
|
||||||
|
|
||||||
|
err = spi_context_cs_configure_all(&SPI_DATA(dev)->ctx);
|
||||||
|
if (err < 0) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
/* Make sure the context is unlocked */
|
/* Make sure the context is unlocked */
|
||||||
spi_context_unlock_unconditionally(&SPI_DATA(dev)->ctx);
|
spi_context_unlock_unconditionally(&SPI_DATA(dev)->ctx);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -188,7 +194,6 @@ int spi_sifive_transceive(const struct device *dev,
|
||||||
* If the user has requested manual GPIO control, ask the
|
* If the user has requested manual GPIO control, ask the
|
||||||
* context for control and disable HW control
|
* context for control and disable HW control
|
||||||
*/
|
*/
|
||||||
spi_context_cs_configure(&SPI_DATA(dev)->ctx);
|
|
||||||
sys_write32(SF_CSMODE_OFF, SPI_REG(dev, REG_CSMODE));
|
sys_write32(SF_CSMODE_OFF, SPI_REG(dev, REG_CSMODE));
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
|
@ -245,6 +250,7 @@ static struct spi_driver_api spi_sifive_api = {
|
||||||
static struct spi_sifive_data spi_sifive_data_##n = { \
|
static struct spi_sifive_data spi_sifive_data_##n = { \
|
||||||
SPI_CONTEXT_INIT_LOCK(spi_sifive_data_##n, ctx), \
|
SPI_CONTEXT_INIT_LOCK(spi_sifive_data_##n, ctx), \
|
||||||
SPI_CONTEXT_INIT_SYNC(spi_sifive_data_##n, ctx), \
|
SPI_CONTEXT_INIT_SYNC(spi_sifive_data_##n, ctx), \
|
||||||
|
SPI_CONTEXT_CS_GPIOS_INITIALIZE(DT_DRV_INST(n), ctx) \
|
||||||
}; \
|
}; \
|
||||||
static struct spi_sifive_cfg spi_sifive_cfg_##n = { \
|
static struct spi_sifive_cfg spi_sifive_cfg_##n = { \
|
||||||
.base = DT_INST_REG_ADDR_BY_NAME(n, control), \
|
.base = DT_INST_REG_ADDR_BY_NAME(n, control), \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue