Skip to content

Commit a6d8378

Browse files
Tomasz Bursztykanashif
authored andcommitted
drivers/flash: A support for SPI gpio-cs logic into w25qxxdv driver
Up to SPI API user code to handle providing the right SPI GPIO-CS parameters now. Signed-off-by: Tomasz Bursztyka <[email protected]>
1 parent 12f87f7 commit a6d8378

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

drivers/flash/Kconfig

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,30 @@ config SPI_FLASH_W25QXXDV_SPI_SLAVE
7979
This option sets the SPI slave number the SPI controller has to switch
8080
to when dealing with WinBond SPI flash chip.
8181

82+
config SPI_FLASH_W25QXXDV_GPIO_SPI_CS
83+
bool "Manage SPI CS through a GPIO pin"
84+
default n
85+
depends on SPI_FLASH_W25QXXDV
86+
help
87+
This option is useful if one needs to manage SPI CS through a GPIO
88+
pin to by-pass the SPI controller's CS logic.
89+
90+
config SPI_FLASH_W25QXXDV_GPIO_SPI_CS_DRV_NAME
91+
string "GPIO driver's name to use to drive SPI CS through"
92+
default ""
93+
depends on SPI_FLASH_W25QXXDV_GPIO_SPI_CS
94+
help
95+
This option is mandatory to set which GPIO controller to use in order
96+
to actually emulate the SPI CS.
97+
98+
config SPI_FLASH_W25QXXDV_GPIO_SPI_CS_PIN
99+
int "GPIO PIN to use to drive SPI CS through"
100+
default 0
101+
depends on SPI_FLASH_W25QXXDV_GPIO_SPI_CS
102+
help
103+
This option is mandatory to set which GPIO pin to use in order
104+
to actually emulate the SPI CS.
105+
82106
config SPI_FLASH_W25QXXDV_FLASH_SIZE
83107
int "Flash size in bytes"
84108
depends on SPI_FLASH_W25QXXDV

drivers/flash/spi_flash_w25qxxdv.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,19 @@ static int spi_flash_wb_configure(struct device *dev)
325325
data->spi_cfg.operation = SPI_WORD_SET(8);
326326
data->spi_cfg.slave = CONFIG_SPI_FLASH_W25QXXDV_SPI_SLAVE;
327327

328+
#if defined(CONFIG_SPI_FLASH_W25QXXDV_GPIO_SPI_CS)
329+
data->cs_ctrl.gpio_dev = device_get_binding(
330+
CONFIG_SPI_FLASH_W25QXXDV_GPIO_SPI_CS_DRV_NAME);
331+
if (!data->cs_ctrl.gpio_dev) {
332+
return -ENODEV;
333+
}
334+
335+
data->cs_ctrl.gpio_pin = CONFIG_SPI_FLASH_W25QXXDV_GPIO_SPI_CS_PIN;
336+
data->cs_ctrl.delay = 0;
337+
338+
data->spi_cfg.cs = &data->cs_ctrl;
339+
#endif /* CONFIG_SPI_FLASH_W25QXXDV_GPIO_SPI_CS */
340+
328341
return spi_flash_wb_id(dev);
329342
}
330343

@@ -336,7 +349,7 @@ static int spi_flash_init(struct device *dev)
336349
k_sem_init(&data->sem, 1, UINT_MAX);
337350

338351
ret = spi_flash_wb_configure(dev);
339-
if (ret) {
352+
if (!ret) {
340353
dev->driver_api = &spi_flash_api;
341354
}
342355

drivers/flash/spi_flash_w25qxxdv.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
struct spi_flash_data {
1818
struct device *spi;
19+
#if defined(CONFIG_SPI_FLASH_W25QXXDV_GPIO_SPI_CS)
20+
struct spi_cs_control cs_ctrl;
21+
#endif /* CONFIG_SPI_FLASH_W25QXXDV_GPIO_SPI_CS */
1922
struct spi_config spi_cfg;
2023
struct k_sem sem;
2124
};

0 commit comments

Comments
 (0)