Skip to content

Commit 997723b

Browse files
bbilascarlescufi
authored andcommitted
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 <[email protected]>
1 parent 81a3900 commit 997723b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

drivers/spi/spi_sifive.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,15 @@ void spi_sifive_xfer(const struct device *dev, const bool hw_cs_control)
153153

154154
int spi_sifive_init(const struct device *dev)
155155
{
156+
int err;
156157
/* Disable SPI Flash mode */
157158
sys_clear_bit(SPI_REG(dev, REG_FCTRL), SF_FCTRL_EN);
158159

160+
err = spi_context_cs_configure_all(&SPI_DATA(dev)->ctx);
161+
if (err < 0) {
162+
return err;
163+
}
164+
159165
/* Make sure the context is unlocked */
160166
spi_context_unlock_unconditionally(&SPI_DATA(dev)->ctx);
161167
return 0;
@@ -188,7 +194,6 @@ int spi_sifive_transceive(const struct device *dev,
188194
* If the user has requested manual GPIO control, ask the
189195
* context for control and disable HW control
190196
*/
191-
spi_context_cs_configure(&SPI_DATA(dev)->ctx);
192197
sys_write32(SF_CSMODE_OFF, SPI_REG(dev, REG_CSMODE));
193198
} else {
194199
/*
@@ -245,6 +250,7 @@ static struct spi_driver_api spi_sifive_api = {
245250
static struct spi_sifive_data spi_sifive_data_##n = { \
246251
SPI_CONTEXT_INIT_LOCK(spi_sifive_data_##n, ctx), \
247252
SPI_CONTEXT_INIT_SYNC(spi_sifive_data_##n, ctx), \
253+
SPI_CONTEXT_CS_GPIOS_INITIALIZE(DT_DRV_INST(n), ctx) \
248254
}; \
249255
static struct spi_sifive_cfg spi_sifive_cfg_##n = { \
250256
.base = DT_INST_REG_ADDR_BY_NAME(n, control), \

0 commit comments

Comments
 (0)