@@ -520,7 +520,7 @@ static int quad_enable_set(const struct device *dev, bool enable)
520520 struct flash_mspi_nor_data * dev_data = dev -> data ;
521521 int rc ;
522522
523- flash_mspi_command_set (dev , & commands [ MSPI_IO_MODE_SINGLE ] .write_en );
523+ flash_mspi_command_set (dev , & commands_single .write_en );
524524 rc = mspi_transceive (dev_config -> bus , & dev_config -> mspi_id ,
525525 & dev_data -> xfer );
526526 if (rc < 0 ) {
@@ -672,7 +672,7 @@ static int flash_chip_init(const struct device *dev)
672672 }
673673#endif
674674
675- flash_mspi_command_set (dev , & commands [ MSPI_IO_MODE_SINGLE ] .id );
675+ flash_mspi_command_set (dev , & commands_single .id );
676676 dev_data -> packet .data_buf = id ;
677677 dev_data -> packet .num_bytes = sizeof (id );
678678
@@ -787,7 +787,39 @@ static DEVICE_API(flash, drv_api) = {
787787}
788788
789789#define FLASH_SIZE_INST (inst ) (DT_INST_PROP(inst, size) / 8)
790- #define FLASH_CMDS (inst ) &commands[DT_INST_ENUM_IDX(inst, mspi_io_mode)]
790+
791+ /* Define copies of mspi_io_mode enum values, so they can be used inside
792+ * the COND_CODE_1 macros.
793+ */
794+ #define _MSPI_IO_MODE_SINGLE 0
795+ #define _MSPI_IO_MODE_QUAD_1_4_4 6
796+ #define _MSPI_IO_MODE_OCTAL 7
797+ BUILD_ASSERT (_MSPI_IO_MODE_SINGLE == MSPI_IO_MODE_SINGLE ,
798+ "Please align _MSPI_IO_MODE_SINGLE macro value" );
799+ BUILD_ASSERT (_MSPI_IO_MODE_QUAD_1_4_4 == MSPI_IO_MODE_QUAD_1_4_4 ,
800+ "Please align _MSPI_IO_MODE_QUAD_1_4_4 macro value" );
801+ BUILD_ASSERT (_MSPI_IO_MODE_OCTAL == MSPI_IO_MODE_OCTAL ,
802+ "Please align _MSPI_IO_MODE_OCTAL macro value" );
803+
804+ /* Define a non-existing extern symbol to get an understandable compile-time error
805+ * if the IO mode is not suported by the driver.
806+ */
807+ extern const struct flash_mspi_nor_cmds mspi_io_mode_not_supported ;
808+
809+ #define FLASH_CMDS (inst ) COND_CODE_1( \
810+ IS_EQ(DT_INST_ENUM_IDX(inst, mspi_io_mode), _MSPI_IO_MODE_SINGLE), \
811+ (&commands_single), \
812+ (COND_CODE_1( \
813+ IS_EQ(DT_INST_ENUM_IDX(inst, mspi_io_mode), _MSPI_IO_MODE_QUAD_1_4_4), \
814+ (&commands_quad_1_4_4), \
815+ (COND_CODE_1( \
816+ IS_EQ(DT_INST_ENUM_IDX(inst, mspi_io_mode), _MSPI_IO_MODE_OCTAL), \
817+ (&commands_octal), \
818+ (&mspi_io_mode_not_supported) \
819+ )) \
820+ )) \
821+ )
822+
791823#define FLASH_QUIRKS (inst ) FLASH_MSPI_QUIRKS_GET(DT_DRV_INST(inst))
792824
793825#define FLASH_DW15_QER_VAL (inst ) _CONCAT(JESD216_DW15_QER_VAL_, \
0 commit comments