Skip to content

Commit

Permalink
drivers: mspi: add checking device frequency
Browse files Browse the repository at this point in the history
Add checking if desired transmission frequency is possible to
set.

Signed-off-by: Magdalena Pastula <[email protected]>
  • Loading branch information
magp-nordic committed Feb 25, 2025
1 parent 19aeee1 commit 75b88e8
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions drivers/mspi/mspi_nrfe.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ LOG_MODULE_REGISTER(mspi_nrfe, CONFIG_MSPI_LOG_LEVEL);

#define SDP_MPSI_PINCTRL_DEV_CONFIG_INIT(node_id) \
{ \
.reg = PINCTRL_REG_NONE, \
.states = Z_PINCTRL_STATES_NAME(node_id), \
.reg = PINCTRL_REG_NONE, \
.states = Z_PINCTRL_STATES_NAME(node_id), \
.state_cnt = ARRAY_SIZE(Z_PINCTRL_STATES_NAME(node_id)), \
}

Expand Down Expand Up @@ -60,8 +60,8 @@ static atomic_t ipc_atomic_sem = ATOMIC_INIT(0);
.duplex = DT_PROP_OR(MSPI_NRFE_NODE, duplex, MSPI_FULL_DUPLEX), \
.dqs_support = DT_PROP_OR(MSPI_NRFE_NODE, dqs_support, false), \
.num_periph = DT_CHILD_NUM(MSPI_NRFE_NODE), \
.max_freq = DT_PROP(MSPI_NRFE_NODE, clock_frequency), \
.re_init = true, \
.max_freq = DT_PROP(MSPI_NRFE_NODE, clock_frequency), \
.re_init = true, \
.sw_multi_periph = false, \
}

Expand Down Expand Up @@ -408,6 +408,18 @@ static int api_dev_config(const struct device *dev, const struct mspi_dev_id *de
drv_cfg->mspicfg.max_freq);
return -EINVAL;
}

if (cfg->freq < drv_cfg->mspicfg.max_freq / UINT16_MAX) {
LOG_ERR("Invalid frequency: %u. MIN: %u", cfg->freq,
drv_cfg->mspicfg.max_freq / UINT16_MAX);
return -EINVAL;
}
if (SystemCoreClock % (cfg->freq * 2) != 0) {
LOG_ERR("Invalid frequency: %u. Only divisors of (CPU_FREQ / 2) are "
"allowed.",
cfg->freq);
return -EINVAL;
}
}

if (param_mask & MSPI_DEVICE_CONFIG_IO_MODE) {
Expand Down

0 comments on commit 75b88e8

Please sign in to comment.