Skip to content

Commit 550961d

Browse files
committed
[nrf fromlist] drivers: flash_mspi_nor: Get info from dts SFDP arrays
Get parameters for used flash commands and requirements for enabling Quad and Octal modes from dts uint8-arrays containing data read from SFDP tables for particular flash chips. Upstream PR #: 93093 Signed-off-by: Andrzej Głąbek <[email protected]>
1 parent d4dc95f commit 550961d

File tree

6 files changed

+434
-16
lines changed

6 files changed

+434
-16
lines changed

boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuapp.dts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,13 @@ slot3_partition: &cpurad_slot1_partition {
285285
30 b0 30 b0 f4 bd d5 5c 00 00 00 ff 10 10 00 20
286286
00 00 00 00 00 00 7c 23 48 00 00 00 00 00 88 88
287287
];
288+
sfdp-ff05 = [
289+
00 ee c0 69 72 72 71 71 00 d8 f7 f6 00 0a 00 00
290+
14 45 98 80
291+
];
292+
sfdp-ff84 = [
293+
43 06 0f 00 21 dc ff ff
294+
];
288295
size = <67108864>;
289296
has-dpd;
290297
t-enter-dpd = <10000>;

boards/nordic/nrf9280pdk/nrf9280pdk_nrf9280_cpuapp.dts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,13 @@ ipc0: &cpuapp_cpurad_ipc {
266266
30 b0 30 b0 f4 bd d5 5c 00 00 00 ff 10 10 00 20
267267
00 00 00 00 00 00 7c 23 48 00 00 00 00 00 88 88
268268
];
269+
sfdp-ff05 = [
270+
00 ee c0 69 72 72 71 71 00 d8 f7 f6 00 0a 00 00
271+
14 45 98 80
272+
];
273+
sfdp-ff84 = [
274+
43 06 0f 00 21 dc ff ff
275+
];
269276
size = <67108864>;
270277
has-dpd;
271278
t-enter-dpd = <10000>;

drivers/flash/flash_mspi_nor.c

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <zephyr/pm/device_runtime.h>
1313

1414
#include "flash_mspi_nor.h"
15+
#include "flash_mspi_nor_sfdp.h"
1516
#include "flash_mspi_nor_quirks.h"
1617

1718
LOG_MODULE_REGISTER(flash_mspi_nor, CONFIG_FLASH_LOG_LEVEL);
@@ -110,7 +111,9 @@ static inline uint32_t dev_flash_size(const struct device *dev)
110111

111112
static inline uint16_t dev_page_size(const struct device *dev)
112113
{
113-
return SPI_NOR_PAGE_SIZE;
114+
const struct flash_mspi_nor_config *dev_config = dev->config;
115+
116+
return dev_config->page_size;
114117
}
115118

116119
static int api_read(const struct device *dev, off_t addr, void *dest,
@@ -528,7 +531,7 @@ static int quad_enable_set(const struct device *dev, bool enable)
528531
return rc;
529532
}
530533

531-
if (dev_config->dw15_qer == JESD216_DW15_QER_VAL_S1B6) {
534+
if (dev_data->switch_info.quad_enable_req == JESD216_DW15_QER_VAL_S1B6) {
532535
const struct flash_mspi_nor_cmd cmd_status = {
533536
.dir = MSPI_TX,
534537
.cmd = SPI_NOR_CMD_WRSR,
@@ -564,10 +567,11 @@ static int quad_enable_set(const struct device *dev, bool enable)
564567
static int default_io_mode(const struct device *dev)
565568
{
566569
const struct flash_mspi_nor_config *dev_config = dev->config;
570+
struct flash_mspi_nor_data *dev_data = dev->data;
567571
enum mspi_io_mode io_mode = dev_config->mspi_nor_cfg.io_mode;
568572
int rc = 0;
569573

570-
if (dev_config->dw15_qer != JESD216_DW15_QER_VAL_NONE) {
574+
if (dev_data->switch_info.quad_enable_req != JESD216_DW15_QER_VAL_NONE) {
571575
/* For Quad 1-1-4 and 1-4-4, entering or leaving mode is defined
572576
* in JEDEC216 BFP DW15 QER
573577
*/
@@ -651,7 +655,7 @@ static int flash_chip_init(const struct device *dev)
651655
/* Some chips reuse RESET pin for data in Quad modes:
652656
* force single line mode before resetting.
653657
*/
654-
if (dev_config->dw15_qer != JESD216_DW15_QER_VAL_NONE &&
658+
if (dev_data->switch_info.quad_enable_req != JESD216_DW15_QER_VAL_NONE &&
655659
(io_mode == MSPI_IO_MODE_SINGLE ||
656660
io_mode == MSPI_IO_MODE_QUAD_1_1_4 ||
657661
io_mode == MSPI_IO_MODE_QUAD_1_4_4)) {
@@ -743,6 +747,11 @@ static int drv_init(const struct device *dev)
743747
return -ENODEV;
744748
}
745749

750+
memcpy(dev_data->erase_types, dev_config->default_erase_types,
751+
sizeof(dev_data->erase_types));
752+
dev_data->cmd_info = dev_config->default_cmd_info;
753+
dev_data->switch_info = dev_config->default_switch_info;
754+
746755
rc = pm_device_runtime_get(dev_config->bus);
747756
if (rc < 0) {
748757
LOG_ERR("pm_device_runtime_get() failed: %d", rc);
@@ -793,7 +802,15 @@ static DEVICE_API(flash, drv_api) = {
793802
.dqs_enable = false, \
794803
}
795804

796-
#define FLASH_SIZE_INST(inst) (DT_INST_PROP(inst, size) / 8)
805+
#define FLASH_SIZE(inst) \
806+
(DT_INST_NODE_HAS_PROP(inst, size) \
807+
? DT_INST_PROP(inst, size) / 8 \
808+
: BFP_FLASH_DENSITY(SFDP_DW(inst, sfdp_bfp, 2)) / 8)
809+
810+
#define FLASH_PAGE_EXP(inst) SFDP_FIELD(inst, sfdp_bfp, 11, GENMASK(7, 4))
811+
#define FLASH_PAGE_SIZE(inst) \
812+
(FLASH_PAGE_EXP(inst) ? BIT(FLASH_PAGE_EXP(inst)) \
813+
: SPI_NOR_PAGE_SIZE)
797814

798815
/* Define copies of mspi_io_mode enum values, so they can be used inside
799816
* the COND_CODE_1 macros.
@@ -829,23 +846,17 @@ extern const struct flash_mspi_nor_cmds mspi_io_mode_not_supported;
829846

830847
#define FLASH_QUIRKS(inst) FLASH_MSPI_QUIRKS_GET(DT_DRV_INST(inst))
831848

832-
#define FLASH_DW15_QER_VAL(inst) _CONCAT(JESD216_DW15_QER_VAL_, \
833-
DT_INST_STRING_TOKEN(inst, quad_enable_requirements))
834-
#define FLASH_DW15_QER(inst) COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, quad_enable_requirements), \
835-
(FLASH_DW15_QER_VAL(inst)), (JESD216_DW15_QER_VAL_NONE))
836-
837-
838849
#if defined(CONFIG_FLASH_PAGE_LAYOUT)
839850
BUILD_ASSERT((CONFIG_FLASH_MSPI_NOR_LAYOUT_PAGE_SIZE % 4096) == 0,
840851
"MSPI_NOR_FLASH_LAYOUT_PAGE_SIZE must be multiple of 4096");
841852
#define FLASH_PAGE_LAYOUT_DEFINE(inst) \
842853
.layout = { \
843854
.pages_size = CONFIG_FLASH_MSPI_NOR_LAYOUT_PAGE_SIZE, \
844-
.pages_count = FLASH_SIZE_INST(inst) \
855+
.pages_count = FLASH_SIZE(inst) \
845856
/ CONFIG_FLASH_MSPI_NOR_LAYOUT_PAGE_SIZE, \
846857
},
847858
#define FLASH_PAGE_LAYOUT_CHECK(inst) \
848-
BUILD_ASSERT((FLASH_SIZE_INST(inst) % CONFIG_FLASH_MSPI_NOR_LAYOUT_PAGE_SIZE) == 0, \
859+
BUILD_ASSERT((FLASH_SIZE(inst) % CONFIG_FLASH_MSPI_NOR_LAYOUT_PAGE_SIZE) == 0, \
849860
"MSPI_NOR_FLASH_LAYOUT_PAGE_SIZE incompatible with flash size, instance " #inst);
850861
#else
851862
#define FLASH_PAGE_LAYOUT_DEFINE(inst)
@@ -867,11 +878,14 @@ BUILD_ASSERT((FLASH_SIZE_INST(inst) % CONFIG_FLASH_MSPI_NOR_LAYOUT_PAGE_SIZE) ==
867878
(DT_INST_ENUM_IDX(inst, mspi_io_mode) == \
868879
MSPI_IO_MODE_OCTAL), \
869880
"Only 1x, 1-4-4 and 8x I/O modes are supported for now"); \
881+
SFDP_BUILD_ASSERTS(inst); \
870882
PM_DEVICE_DT_INST_DEFINE(inst, dev_pm_action_cb); \
883+
DEFAULT_ERASE_TYPES_DEFINE(inst); \
871884
static struct flash_mspi_nor_data dev##inst##_data; \
872885
static const struct flash_mspi_nor_config dev##inst##_config = { \
873886
.bus = DEVICE_DT_GET(DT_INST_BUS(inst)), \
874-
.flash_size = FLASH_SIZE_INST(inst), \
887+
.flash_size = FLASH_SIZE(inst), \
888+
.page_size = FLASH_PAGE_SIZE(inst), \
875889
.mspi_id = MSPI_DEVICE_ID_DT_INST(inst), \
876890
.mspi_nor_cfg = MSPI_DEVICE_CONFIG_DT_INST(inst), \
877891
.mspi_nor_init_cfg = FLASH_INITIAL_CONFIG(inst), \
@@ -892,7 +906,9 @@ BUILD_ASSERT((FLASH_SIZE_INST(inst) % CONFIG_FLASH_MSPI_NOR_LAYOUT_PAGE_SIZE) ==
892906
.jedec_id = DT_INST_PROP(inst, jedec_id), \
893907
.jedec_cmds = FLASH_CMDS(inst), \
894908
.quirks = FLASH_QUIRKS(inst), \
895-
.dw15_qer = FLASH_DW15_QER(inst), \
909+
.default_erase_types = DEFAULT_ERASE_TYPES(inst), \
910+
.default_cmd_info = DEFAULT_CMD_INFO(inst), \
911+
.default_switch_info = DEFAULT_SWITCH_INFO(inst), \
896912
}; \
897913
FLASH_PAGE_LAYOUT_CHECK(inst) \
898914
DEVICE_DT_INST_DEFINE(inst, \

drivers/flash/flash_mspi_nor.h

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,49 @@ extern "C" {
2020
#define WITH_RESET_GPIO 1
2121
#endif
2222

23+
#define CMD_EXTENSION_NONE 0
24+
#define CMD_EXTENSION_SAME 1
25+
#define CMD_EXTENSION_INVERSE 2
26+
27+
#define ENTER_4BYTE_ADDR_NONE 0
28+
#define ENTER_4BYTE_ADDR_B7 1
29+
#define ENTER_4BYTE_ADDR_06_B7 2
30+
31+
struct flash_mspi_nor_cmd_info {
32+
uint8_t read_cmd;
33+
uint8_t read_mode_clocks : 3;
34+
uint8_t read_dummy_clocks : 5;
35+
uint8_t pp_cmd;
36+
bool uses_4byte_addr : 1;
37+
/* BFP, 18th DWORD, bits 30-29 */
38+
uint8_t cmd_extension : 2;
39+
/* xSPI Profile 1.0 (ID FF05), 1st DWORD: */
40+
/* - Read SFDP command address bytes: 4 (true) or 3 */
41+
bool sfdp_addr_4 : 1;
42+
/* - Read SDFP command dummy cycles: 20 (true) or 8 */
43+
bool sfdp_dummy_20 : 1;
44+
/* - Read Status Register command address bytes: 4 (true) or 0 */
45+
bool rdsr_addr_4 : 1;
46+
/* - Read Status Register command dummy cycles: 0, 4, or 8 */
47+
uint8_t rdsr_dummy : 4;
48+
/* - Read JEDEC ID command parameters; not sure where to get their
49+
* values from, but since for many flash chips they are the same
50+
* as for RDSR, those are taken as defaults, see DEFAULT_CMD_INFO()
51+
*/
52+
bool rdid_addr_4 : 1;
53+
uint8_t rdid_dummy : 4;
54+
};
55+
56+
struct flash_mspi_nor_switch_info {
57+
uint8_t quad_enable_req : 3;
58+
uint8_t octal_enable_req : 3;
59+
uint8_t enter_4byte_addr : 2;
60+
};
61+
2362
struct flash_mspi_nor_config {
2463
const struct device *bus;
2564
uint32_t flash_size;
65+
uint16_t page_size;
2666
struct mspi_dev_id mspi_id;
2767
struct mspi_dev_cfg mspi_nor_cfg;
2868
struct mspi_dev_cfg mspi_nor_init_cfg;
@@ -42,14 +82,19 @@ struct flash_mspi_nor_config {
4282
uint8_t jedec_id[SPI_NOR_MAX_ID_LEN];
4383
const struct flash_mspi_nor_cmds *jedec_cmds;
4484
struct flash_mspi_nor_quirks *quirks;
45-
uint8_t dw15_qer;
85+
const struct jesd216_erase_type *default_erase_types;
86+
struct flash_mspi_nor_cmd_info default_cmd_info;
87+
struct flash_mspi_nor_switch_info default_switch_info;
4688
};
4789

4890
struct flash_mspi_nor_data {
4991
struct k_sem acquired;
5092
struct mspi_xfer_packet packet;
5193
struct mspi_xfer xfer;
5294
struct mspi_dev_cfg *curr_cfg;
95+
struct jesd216_erase_type erase_types[JESD216_NUM_ERASE_TYPES];
96+
struct flash_mspi_nor_cmd_info cmd_info;
97+
struct flash_mspi_nor_switch_info switch_info;
5398
};
5499

55100
struct flash_mspi_nor_cmd {

0 commit comments

Comments
 (0)