Skip to content

Commit 68183ce

Browse files
Kevin Wangcfriedt
authored andcommitted
drivers: spi: atcspi200: determining if spi is used as a flash controller
XIP may indicate that the program is executed either in local memory or flash. However, the SPI node is only used as a flash controller when the program is executed in flash. Therefore, optimize the related checks to ensure that when XIP is enabled but the program is executed in local memory, the SPI node can still be used. Signed-off-by: Kevin Wang <[email protected]>
1 parent f817f62 commit 68183ce

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

drivers/spi/spi_andes_atcspi200.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct spi_atcspi200_cfg {
5151
uint32_t base;
5252
uint32_t irq_num;
5353
uint32_t f_sys;
54-
bool xip;
54+
bool spi_cfg_rom;
5555
};
5656

5757
/* API Functions */
@@ -681,7 +681,7 @@ int spi_atcspi200_init(const struct device *dev)
681681
int err = 0;
682682

683683
/* we should not configure the device we are running on */
684-
if (cfg->xip) {
684+
if (cfg->spi_cfg_rom) {
685685
return -EINVAL;
686686
}
687687

@@ -769,7 +769,6 @@ static void spi_atcspi200_irq_handler(void *arg)
769769
spi_context_update_tx(ctx, dfs, 1);
770770

771771
data->tx_cnt--;
772-
773772
if (data->tx_cnt == 0) {
774773
/* Have already sent a chunk of data, so stop
775774
* sending data!
@@ -803,7 +802,6 @@ static void spi_atcspi200_irq_handler(void *arg)
803802
}
804803

805804
data->rx_cnt--;
806-
807805
if (data->rx_cnt == 0) {
808806
/* Have already sent a chunk of data, so stop
809807
* sending data!
@@ -914,11 +912,21 @@ static void spi_atcspi200_irq_handler(void *arg)
914912
#define SPI_BUSY_INIT .busy = false,
915913

916914
#if (CONFIG_XIP)
917-
#define SPI_ROM_CFG_XIP(node_id) DT_SAME_NODE(node_id, DT_BUS(DT_CHOSEN(zephyr_flash)))
915+
#define SPI_FLASH_BASE DT_REG_ADDR_BY_IDX(DT_PARENT(DT_CHOSEN(zephyr_flash)), 1)
916+
#define SPI_FLASH_SIZE DT_REG_SIZE_BY_IDX(DT_PARENT(DT_CHOSEN(zephyr_flash)), 1)
917+
#define SPI_FLASH_END (SPI_FLASH_BASE + SPI_FLASH_SIZE)
918+
919+
#if ((SPI_FLASH_BASE <= CONFIG_FLASH_BASE_ADDRESS) && \
920+
(CONFIG_FLASH_BASE_ADDRESS <= SPI_FLASH_END))
921+
#define SPI_CFG_ROM(node_id) DT_SAME_NODE(node_id, DT_BUS(DT_CHOSEN(zephyr_flash)))
918922
#else
919-
#define SPI_ROM_CFG_XIP(node_id) false
923+
#define SPI_CFG_ROM(node_id) false
920924
#endif
921925

926+
#else /* CONFIG_XIP */
927+
#define SPI_CFG_ROM(node_id) false
928+
#endif /* CONFIG_XIP */
929+
922930
#define SPI_INIT(n) \
923931
static struct spi_atcspi200_data spi_atcspi200_dev_data_##n = { \
924932
SPI_CONTEXT_INIT_LOCK(spi_atcspi200_dev_data_##n, ctx), \
@@ -934,10 +942,10 @@ static void spi_atcspi200_irq_handler(void *arg)
934942
.base = DT_INST_REG_ADDR(n), \
935943
.irq_num = DT_INST_IRQN(n), \
936944
.f_sys = DT_INST_PROP(n, clock_frequency), \
937-
.xip = SPI_ROM_CFG_XIP(DT_DRV_INST(n)), \
945+
.spi_cfg_rom = SPI_CFG_ROM(DT_DRV_INST(n)), \
938946
}; \
939947
\
940-
DEVICE_DT_INST_DEFINE(n, \
948+
SPI_DEVICE_DT_INST_DEFINE(n, \
941949
spi_atcspi200_init, \
942950
NULL, \
943951
&spi_atcspi200_dev_data_##n, \

0 commit comments

Comments
 (0)