Skip to content

Commit 5c62097

Browse files
TomChang19kartben
authored andcommitted
drivers: flash: npcx: add setting of low flash device
This commit adds functions to select the low flash device and set the size of the low flash device. Signed-off-by: Tom Chang <[email protected]>
1 parent 54a714a commit 5c62097

File tree

5 files changed

+77
-0
lines changed

5 files changed

+77
-0
lines changed

drivers/flash/Kconfig.npcx_fiu

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,12 @@ config FLASH_NPCX_FIU_SUPP_DRA_2_DEV
6565
Selected if NPCX series supports two external SPI devices in Direct
6666
Read Access (DRA) on QSPI bus.
6767

68+
DT_NPCX_FIU_LOW_DEV_SWAP := $(dt_nodelabel_bool_prop,qspi_fiu1,flash-dev-inv)
69+
config FLASH_NPCX_FIU_SUPP_LOW_DEV_SWAP
70+
bool "Inverse the access of the two external flashes"
71+
default y if SOC_SERIES_NPCX4 && FLASH_NPCX_FIU_SUPP_DRA_2_DEV && \
72+
"$(DT_NPCX_FIU_LOW_DEV_SWAP)"
73+
help
74+
Select if it needs to swap the access of the two external flashes.
75+
6876
endif #FLASH_NPCX_FIU_QSPI

drivers/flash/flash_npcx_fiu_nor.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,9 +587,23 @@ static int flash_npcx_nor_init(const struct device *dev)
587587
}
588588
}
589589

590+
if (config->qspi_cfg.is_logical_low_dev && IS_ENABLED(CONFIG_FLASH_NPCX_FIU_DRA_V2)) {
591+
qspi_npcx_fiu_set_spi_size(config->qspi_bus, &config->qspi_cfg);
592+
}
593+
590594
return 0;
591595
}
592596

597+
#define NPCX_FLASH_IS_LOGICAL_LOW_DEV(n) \
598+
(DT_PROP(DT_PARENT(DT_DRV_INST(n)), en_direct_access_2dev) && \
599+
(DT_PROP(DT_PARENT(DT_DRV_INST(n)), flash_dev_inv) == \
600+
((DT_INST_PROP(n, qspi_flags) & NPCX_QSPI_SEC_FLASH_SL) == \
601+
NPCX_QSPI_SEC_FLASH_SL)))
602+
603+
#define NPCX_FLASH_SPI_ALLOCATE_SIZE(n) \
604+
COND_CODE_1(DT_INST_NODE_HAS_PROP(n, spi_dev_size), \
605+
(DT_INST_STRING_TOKEN(n, spi_dev_size)), (0xFF))
606+
593607
#define NPCX_FLASH_NOR_INIT(n) \
594608
BUILD_ASSERT(DT_INST_QUAD_EN_PROP_OR(n) == JESD216_DW15_QER_NONE || \
595609
DT_INST_STRING_TOKEN(n, rd_mode) == NPCX_RD_MODE_FAST_DUAL, \
@@ -606,6 +620,8 @@ static const struct flash_npcx_nor_config flash_npcx_nor_config_##n = { \
606620
.enter_4ba = DT_INST_PROP_OR(n, enter_4byte_addr, 0), \
607621
.qer_type = DT_INST_QUAD_EN_PROP_OR(n), \
608622
.rd_mode = DT_INST_STRING_TOKEN(n, rd_mode), \
623+
.is_logical_low_dev = NPCX_FLASH_IS_LOGICAL_LOW_DEV(n), \
624+
.spi_dev_sz = NPCX_FLASH_SPI_ALLOCATE_SIZE(n), \
609625
}, \
610626
IF_ENABLED(CONFIG_FLASH_PAGE_LAYOUT, ( \
611627
.layout = { \

drivers/flash/flash_npcx_fiu_qspi.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct npcx_qspi_fiu_config {
3030
struct npcx_clk_cfg clk_cfg;
3131
/* Enable 2 external SPI devices for direct read on QSPI bus */
3232
bool en_direct_access_2dev;
33+
bool base_flash_inv;
3334
};
3435

3536
/* Device data */
@@ -244,6 +245,25 @@ void qspi_npcx_fiu_mutex_unlock(const struct device *dev)
244245
k_sem_give(&data->lock_sem);
245246
}
246247

248+
#if defined(CONFIG_FLASH_NPCX_FIU_DRA_V2)
249+
void qspi_npcx_fiu_set_spi_size(const struct device *dev, const struct npcx_qspi_cfg *cfg)
250+
{
251+
struct fiu_reg *const inst = HAL_INSTANCE(dev);
252+
uint8_t flags = cfg->flags;
253+
254+
if (cfg->spi_dev_sz <= NPCX_SPI_DEV_SIZE_128M) {
255+
if ((flags & NPCX_QSPI_SEC_FLASH_SL) == 0) {
256+
SET_FIELD(inst->BURST_CFG, NPCX_BURST_CFG_SPI_DEV_SEL, NPCX_SPI_F_CS0);
257+
} else {
258+
SET_FIELD(inst->BURST_CFG, NPCX_BURST_CFG_SPI_DEV_SEL, NPCX_SPI_F_CS1);
259+
}
260+
inst->SPI_DEV_SIZE = BIT(cfg->spi_dev_sz);
261+
} else {
262+
LOG_ERR("Invalid setting of low device size");
263+
}
264+
}
265+
#endif
266+
247267
static int qspi_npcx_fiu_init(const struct device *dev)
248268
{
249269
const struct npcx_qspi_fiu_config *const config = dev->config;
@@ -273,6 +293,11 @@ static int qspi_npcx_fiu_init(const struct device *dev)
273293
struct fiu_reg *const inst = HAL_INSTANCE(dev);
274294

275295
inst->FIU_EXT_CFG |= BIT(NPCX_FIU_EXT_CFG_SPI1_2DEV);
296+
#if defined(CONFIG_FLASH_NPCX_FIU_SUPP_LOW_DEV_SWAP)
297+
if (config->base_flash_inv) {
298+
inst->FIU_EXT_CFG |= BIT(NPCX_FIU_EXT_CFG_LOW_DEV_NUM);
299+
}
300+
#endif
276301
#endif
277302
}
278303

@@ -284,6 +309,7 @@ static const struct npcx_qspi_fiu_config npcx_qspi_fiu_config_##n = { \
284309
.base = DT_INST_REG_ADDR(n), \
285310
.clk_cfg = NPCX_DT_CLK_CFG_ITEM(n), \
286311
.en_direct_access_2dev = DT_INST_PROP(n, en_direct_access_2dev), \
312+
.base_flash_inv = DT_INST_PROP(n, flash_dev_inv), \
287313
}; \
288314
static struct npcx_qspi_fiu_data npcx_qspi_fiu_data_##n; \
289315
DEVICE_DT_INST_DEFINE(n, qspi_npcx_fiu_init, NULL, \

drivers/flash/flash_npcx_fiu_qspi.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ extern "C" {
2525
#define NPCX_DEV_NUM_ADDR_3BYTE 3
2626
#define NPCX_DEV_NUM_ADDR_4BYTE 4
2727

28+
#define NPCX_SPI_F_CS0 0
29+
#define NPCX_SPI_F_CS1 1
30+
31+
enum NPCX_SPI_DEV_SIZE {
32+
NPCX_SPI_DEV_SIZE_1M,
33+
NPCX_SPI_DEV_SIZE_2M,
34+
NPCX_SPI_DEV_SIZE_4M,
35+
NPCX_SPI_DEV_SIZE_8M,
36+
NPCX_SPI_DEV_SIZE_16M,
37+
NPCX_SPI_DEV_SIZE_32M,
38+
NPCX_SPI_DEV_SIZE_64M,
39+
NPCX_SPI_DEV_SIZE_128M,
40+
};
41+
2842
/* UMA operation configuration for a SPI device */
2943
struct npcx_uma_cfg {
3044
uint8_t opcode;
@@ -48,6 +62,8 @@ struct npcx_qspi_cfg {
4862
uint8_t enter_4ba;
4963
/* SPI read access type of Direct Read Access mode */
5064
uint8_t rd_mode;
65+
bool is_logical_low_dev;
66+
uint8_t spi_dev_sz;
5167
/* Configurations for the Quad-SPI peripherals */
5268
int flags;
5369
};
@@ -81,6 +97,16 @@ void qspi_npcx_fiu_mutex_lock_configure(const struct device *dev,
8197
*/
8298
void qspi_npcx_fiu_mutex_unlock(const struct device *dev);
8399

100+
#if defined(CONFIG_FLASH_NPCX_FIU_DRA_V2)
101+
/**
102+
* @brief Set the size of the address space allocated for SPI device.
103+
*
104+
* @param dev Pointer to the device structure for qspi bus controller instance.
105+
* @param cfg Pointer to the configuration for the device on qspi bus.
106+
*/
107+
void qspi_npcx_fiu_set_spi_size(const struct device *dev, const struct npcx_qspi_cfg *cfg);
108+
#endif
109+
84110
#ifdef __cplusplus
85111
}
86112
#endif

soc/nuvoton/npcx/npcx4/soc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
/* NPCX4 FIU register fields */
4040
#define NPCX_FIU_EXT_CFG_SPI1_2DEV 6
41+
#define NPCX_FIU_EXT_CFG_LOW_DEV_NUM 7
4142

4243
/* NPCX4 supported group mask of DEVALT_LK */
4344
#define NPCX_DEVALT_LK_GROUP_MASK \

0 commit comments

Comments
 (0)