Skip to content

Commit 1a10ff4

Browse files
committed
drivers: flash_mspi_nor: Assign quirks based on flash DT node property
Introduce "chip-family" enum property in the "jedec,mspi-nor" binding as a way of specifying what special routines need to be use for a given flash chip. This has the advantage over an additional compatible string that users can see the possibilities in the binding documentation and do not need to look into the driver code to find out those. Also any typos in the enum value will be caught by the DT compiler, while for the compatible string such typos would cause it to be silently ignored. Signed-off-by: Andrzej Głąbek <[email protected]>
1 parent f23b1f5 commit 1a10ff4

File tree

5 files changed

+36
-23
lines changed

5 files changed

+36
-23
lines changed

boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuapp.dts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,10 @@ slot3_partition: &cpurad_slot1_partition {
269269
status = "disabled";
270270

271271
mx25uw63: mx25uw6345g@0 {
272-
compatible = "mxicy,mx25u", "jedec,mspi-nor";
272+
compatible = "jedec,mspi-nor";
273273
status = "disabled";
274274
reg = <0>;
275+
chip-family = "mxicy,mx25uw";
275276
jedec-id = [c2 84 37];
276277
sfdp-bfp = [e5 20 8a ff ff ff ff 03 00 ff 00 ff 00 ff 00 ff
277278
ee ff ff ff ff ff 00 ff ff ff 00 ff 0c 20 10 d8

boards/nordic/nrf9280pdk/nrf9280pdk_nrf9280_cpuapp.dts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,10 @@ ipc0: &cpuapp_cpurad_ipc {
248248
status = "okay";
249249

250250
mx25uw63: mx25uw6345g@0 {
251-
compatible = "mxicy,mx25u", "jedec,mspi-nor";
251+
compatible = "jedec,mspi-nor";
252252
status = "disabled";
253253
reg = <0>;
254+
chip-family = "mxicy,mx25uw";
254255
jedec-id = [c2 84 37];
255256
sfdp-bfp = [e5 20 8a ff ff ff ff 03 00 ff 00 ff 00 ff 00 ff
256257
ee ff ff ff ff ff 00 ff ff ff 00 ff 0c 20 10 d8

drivers/flash/flash_mspi_nor.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,8 +1257,6 @@ static DEVICE_API(flash, drv_api) = {
12571257
.dqs_enable = false, \
12581258
}
12591259

1260-
#define FLASH_QUIRKS(inst) FLASH_MSPI_QUIRKS_GET(DT_DRV_INST(inst))
1261-
12621260
#define IO_MODE_FLAGS(io_mode) \
12631261
.multi_io_cmd = (io_mode == MSPI_IO_MODE_DUAL || \
12641262
io_mode == MSPI_IO_MODE_QUAD || \

drivers/flash/flash_mspi_nor_quirks.h

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@ struct flash_mspi_nor_quirks {
2121
};
2222

2323
/* Extend this macro when adding new flash chip with quirks */
24-
#define FLASH_MSPI_QUIRKS_GET(node) \
25-
COND_CODE_1(DT_NODE_HAS_COMPAT_STATUS(node, mxicy_mx25r, okay), \
26-
(&flash_quirks_mxicy_mx25r), \
27-
(COND_CODE_1(DT_NODE_HAS_COMPAT_STATUS(node, mxicy_mx25u, okay), \
28-
(&flash_quirks_mxicy_mx25u), \
29-
(NULL))))
30-
31-
#if DT_HAS_COMPAT_STATUS_OKAY(mxicy_mx25r)
24+
#define FLASH_QUIRKS(inst) \
25+
DT_INST_ENUM_HAS_VALUE(inst, chip_family, mxicy_mx25r) ? \
26+
&flash_quirks_mxicy_mx25r : \
27+
DT_INST_ENUM_HAS_VALUE(inst, chip_family, mxicy_mx25um) || \
28+
DT_INST_ENUM_HAS_VALUE(inst, chip_family, mxicy_mx25uw) || \
29+
DT_INST_ENUM_HAS_VALUE(inst, chip_family, mxicy_mx66um) || \
30+
DT_INST_ENUM_HAS_VALUE(inst, chip_family, mxicy_mx66uw) ? \
31+
&flash_quirks_mxicy_mx25um : \
32+
NULL
33+
34+
/* ---- Macronix MX25R ---- */
3235

3336
#define MXICY_MX25R_LH_MASK BIT(1)
3437
#define MXICY_MX25R_QE_MASK BIT(6)
@@ -115,15 +118,13 @@ static inline int mxicy_mx25r_post_switch_mode(const struct device *dev)
115118
return 0;
116119
}
117120

118-
struct flash_mspi_nor_quirks flash_quirks_mxicy_mx25r = {
121+
__unused struct flash_mspi_nor_quirks flash_quirks_mxicy_mx25r = {
119122
.post_switch_mode = mxicy_mx25r_post_switch_mode,
120123
};
121124

122-
#endif /* DT_HAS_COMPAT_STATUS_OKAY(mxicy_mx25r) */
123-
124-
#if DT_HAS_COMPAT_STATUS_OKAY(mxicy_mx25u)
125+
/* ---- Macronix MX25UM, MX25UW, MX66UM, MX66UW ---- */
125126

126-
static inline int mxicy_mx25u_post_switch_mode(const struct device *dev)
127+
static inline int mxicy_mx25um_post_switch_mode(const struct device *dev)
127128
{
128129
const struct flash_mspi_nor_config *dev_config = dev->config;
129130
struct flash_mspi_nor_data *dev_data = dev->data;
@@ -162,7 +163,7 @@ static inline int mxicy_mx25u_post_switch_mode(const struct device *dev)
162163
return perform_xfer(dev, SPI_NOR_CMD_WR_CFGREG2, false);
163164
}
164165

165-
static int mxicy_mx25u_pre_init(const struct device *dev)
166+
static int mxicy_mx25um_pre_init(const struct device *dev)
166167
{
167168
const struct flash_mspi_nor_config *dev_config = dev->config;
168169
struct flash_mspi_nor_data *dev_data = dev->data;
@@ -204,11 +205,9 @@ static int mxicy_mx25u_pre_init(const struct device *dev)
204205
return 0;
205206
}
206207

207-
struct flash_mspi_nor_quirks flash_quirks_mxicy_mx25u = {
208-
.pre_init = mxicy_mx25u_pre_init,
209-
.post_switch_mode = mxicy_mx25u_post_switch_mode,
208+
__unused struct flash_mspi_nor_quirks flash_quirks_mxicy_mx25um = {
209+
.pre_init = mxicy_mx25um_pre_init,
210+
.post_switch_mode = mxicy_mx25um_post_switch_mode,
210211
};
211212

212-
#endif /* DT_HAS_COMPAT_STATUS_OKAY(mxicy_mx25u) */
213-
214213
#endif /*__FLASH_MSPI_NOR_QUIRKS_H__*/

dts/bindings/mtd/jedec,mspi-nor.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ include:
2121
- t-exit-dpd
2222

2323
properties:
24+
chip-family:
25+
type: string
26+
description: |
27+
Some flash chips need special handling in certain aspects, for example,
28+
to be configured properly at initialization. This property determines
29+
what specific routines need to be used for the flash chip. If not set,
30+
only generic handling is used.
31+
enum:
32+
- "mxicy,mx25r"
33+
- "mxicy,mx25um"
34+
- "mxicy,mx25uw"
35+
- "mxicy,mx66um"
36+
- "mxicy,mx66uw"
37+
2438
reset-gpios:
2539
type: phandle-array
2640
description: |

0 commit comments

Comments
 (0)