Skip to content

Commit 939bfd5

Browse files
drivers: flash: flash_mspi_nor: support custom read frequency
Many flash chips support a higher read frequency than other operations. Support specifying a custom read frequency to take advantage of the performance improvements available with this approach. Signed-off-by: Daniel DeGrasse <[email protected]>
1 parent 91b9c3a commit 939bfd5

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

drivers/flash/flash_mspi_nor.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,20 @@ static int api_read(const struct device *dev, off_t addr, void *dest,
354354
return rc;
355355
}
356356

357+
if (dev_config->read_freq != 0) {
358+
/* Set custom read frequency */
359+
struct mspi_dev_cfg read_freq_cfg = {
360+
.freq = dev_config->read_freq,
361+
};
362+
363+
rc = mspi_dev_config(dev_config->bus, &dev_config->mspi_id,
364+
MSPI_DEVICE_CONFIG_FREQUENCY, &read_freq_cfg);
365+
if (rc < 0) {
366+
LOG_ERR("Could not set read frequency: %d", rc);
367+
goto release_and_exit;
368+
}
369+
}
370+
357371
while (size > 0) {
358372
uint32_t to_read;
359373

@@ -375,6 +389,17 @@ static int api_read(const struct device *dev, off_t addr, void *dest,
375389
size -= to_read;
376390
}
377391

392+
release_and_exit:
393+
if (rc == 0 && dev_config->read_freq != 0) {
394+
/* Restore normal frequency */
395+
rc = mspi_dev_config(dev_config->bus, &dev_config->mspi_id,
396+
MSPI_DEVICE_CONFIG_FREQUENCY,
397+
&dev_config->mspi_nor_cfg);
398+
if (rc < 0) {
399+
LOG_ERR("Could not restore normal frequency: %d", rc);
400+
}
401+
}
402+
378403
release(dev);
379404

380405
if (rc < 0) {
@@ -1342,6 +1367,7 @@ BUILD_ASSERT((FLASH_SIZE(inst) % CONFIG_FLASH_MSPI_NOR_LAYOUT_PAGE_SIZE) == 0, \
13421367
.reset_recovery_us = DT_INST_PROP_OR(inst, t_reset_recovery, 0) \
13431368
/ 1000, \
13441369
.transfer_timeout = DT_INST_PROP(inst, transfer_timeout), \
1370+
.read_freq = DT_INST_PROP_OR(inst, read_frequency, 0), \
13451371
FLASH_PAGE_LAYOUT_DEFINE(inst) \
13461372
.jedec_id = DT_INST_PROP_OR(inst, jedec_id, {0}), \
13471373
.quirks = FLASH_QUIRKS(inst), \

drivers/flash/flash_mspi_nor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ struct flash_mspi_nor_config {
8888
#endif
8989
uint32_t reset_recovery_us;
9090
uint32_t transfer_timeout;
91+
uint32_t read_freq;
9192
#if defined(CONFIG_FLASH_PAGE_LAYOUT)
9293
struct flash_pages_layout layout;
9394
#endif

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,9 @@ properties:
6060
description: |
6161
When set, the flash driver performs software reset of the flash chip
6262
at initialization.
63+
64+
read-frequency:
65+
type: int
66+
description: |
67+
Frequency, in Hz, to be used for read operations. If not specified,
68+
the driver uses the same frequency as for other operations.

0 commit comments

Comments
 (0)