Skip to content

Commit ba7d34d

Browse files
committed
drivers: flash_mspi_nor: Implement flash_ex_op for cmd read/write
Implement the flash extended operation to allow other flash-part specific drivers to be composed using this driver. Signed-off-by: Utsav Munendra <[email protected]>
1 parent 09ca52f commit ba7d34d

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

drivers/flash/Kconfig.mspi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ menuconfig FLASH_MSPI_NOR
4444
depends on DT_HAS_JEDEC_MSPI_NOR_ENABLED
4545
select FLASH_MSPI
4646
select FLASH_HAS_EXPLICIT_ERASE
47+
select FLASH_HAS_EX_OP
4748
select FLASH_JESD216
4849
select GPIO if $(dt_compat_any_has_prop,$(DT_COMPAT_JEDEC_MSPI_NOR),reset-gpios) \
4950
|| $(dt_compat_any_has_prop,$(DT_COMPAT_JEDEC_MSPI_NOR),supply-gpios)

drivers/flash/flash_mspi_nor.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,65 @@ static int api_read_jedec_id(const struct device *dev, uint8_t *id)
644644
}
645645
#endif /* CONFIG_FLASH_JESD216_API */
646646

647+
#if defined(CONFIG_FLASH_EX_OP_ENABLED)
648+
static int ex_op_cmd_read(const struct device *dev,
649+
const struct flash_ex_op_cmd_read_in *in,
650+
struct flash_ex_op_cmd_read_out *out)
651+
{
652+
struct flash_mspi_nor_data *dev_data = dev->data;
653+
654+
int rc = acquire(dev);
655+
if (rc < 0) {
656+
return rc;
657+
}
658+
659+
set_up_xfer(dev, MSPI_RX);
660+
dev_data->packet.data_buf = in->read_buffer;
661+
dev_data->packet.num_bytes = in->buffer_len;
662+
rc = perform_xfer(dev, in->cmd);
663+
out->read_len = (rc < 0) ? 0 : in->buffer_len;
664+
665+
release(dev);
666+
667+
return rc;
668+
}
669+
670+
static int ex_op_cmd_write(const struct device *dev,
671+
const struct flash_ex_op_cmd_write_in *in,
672+
struct flash_ex_op_cmd_write_out *out)
673+
{
674+
struct flash_mspi_nor_data *dev_data = dev->data;
675+
676+
int rc = acquire(dev);
677+
if (rc < 0) {
678+
return rc;
679+
}
680+
681+
set_up_xfer(dev, MSPI_TX);
682+
dev_data->packet.data_buf = in->write_buffer;
683+
dev_data->packet.num_bytes = in->buffer_len;
684+
rc = perform_xfer(dev, in->cmd);
685+
out->write_len = (rc < 0) ? 0 : in->buffer_len;
686+
687+
release(dev);
688+
689+
return rc;
690+
}
691+
692+
static int api_ex_op(const struct device *dev,
693+
uint16_t code, const uintptr_t in, void *out)
694+
{
695+
switch (code) {
696+
case FLASH_EX_OP_CMD_READ:
697+
return ex_op_cmd_read(dev, (const struct flash_ex_op_cmd_read_in *)in, out);
698+
case FLASH_EX_OP_CMD_WRITE:
699+
return ex_op_cmd_write(dev, (const struct flash_ex_op_cmd_write_in *)in, out);
700+
default:
701+
return -ENOTSUP;
702+
};
703+
}
704+
#endif /* CONFIG_FLASH_EX_OP_ENABLED */
705+
647706
static int dev_pm_action_cb(const struct device *dev,
648707
enum pm_device_action action)
649708
{
@@ -1259,6 +1318,9 @@ static DEVICE_API(flash, drv_api) = {
12591318
.sfdp_read = api_sfdp_read,
12601319
.read_jedec_id = api_read_jedec_id,
12611320
#endif
1321+
#if defined(CONFIG_FLASH_EX_OP_ENABLED)
1322+
.ex_op = api_ex_op,
1323+
#endif
12621324
};
12631325

12641326
#define FLASH_INITIAL_CONFIG(inst) \

0 commit comments

Comments
 (0)