Skip to content

Commit 8cb8017

Browse files
FRASTMkartben
authored andcommitted
drivers: flash: stm32 xspi driver supports clock domain config
Add the clock domain configuration for the xspi nodes Where the DTS defines main clock and peripheral clock sel plus a XSPIM clock Signed-off-by: Francois Ramu <[email protected]>
1 parent ad0466f commit 8cb8017

File tree

2 files changed

+45
-41
lines changed

2 files changed

+45
-41
lines changed

drivers/flash/flash_stm32_xspi.c

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,7 +2050,7 @@ static int flash_stm32_xspi_init(const struct device *dev)
20502050
* If clock is off, then MemoryMapped is off too and we do init
20512051
*/
20522052
if (clock_control_get_status(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
2053-
(clock_control_subsys_t) &dev_cfg->pclken[0])
2053+
(clock_control_subsys_t) &dev_cfg->pclken)
20542054
== CLOCK_CONTROL_STATUS_ON) {
20552055
if (stm32_xspi_is_memorymap(dev)) {
20562056
LOG_ERR("NOR init'd in MemMapped mode");
@@ -2076,53 +2076,44 @@ static int flash_stm32_xspi_init(const struct device *dev)
20762076
return ret;
20772077
}
20782078

2079-
if (dev_cfg->pclk_len > 3) {
2080-
/* Max 3 domain clock are expected */
2081-
LOG_ERR("Could not select %d XSPI domain clock", dev_cfg->pclk_len);
2082-
return -EIO;
2083-
}
2084-
20852079
/* Clock configuration */
20862080
if (clock_control_on(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
2087-
(clock_control_subsys_t) &dev_cfg->pclken[0]) != 0) {
2081+
(clock_control_subsys_t) &dev_cfg->pclken) != 0) {
20882082
LOG_ERR("Could not enable XSPI clock");
20892083
return -EIO;
20902084
}
20912085
if (clock_control_get_rate(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
2092-
(clock_control_subsys_t) &dev_cfg->pclken[0],
2086+
(clock_control_subsys_t) &dev_cfg->pclken,
20932087
&ahb_clock_freq) < 0) {
20942088
LOG_ERR("Failed call clock_control_get_rate(pclken)");
20952089
return -EIO;
20962090
}
2097-
/* Alternate clock config for peripheral if any */
2098-
if (IS_ENABLED(STM32_XSPI_DOMAIN_CLOCK_SUPPORT) && (dev_cfg->pclk_len > 1)) {
2099-
if (clock_control_configure(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
2100-
(clock_control_subsys_t) &dev_cfg->pclken[1],
2101-
NULL) != 0) {
2102-
LOG_ERR("Could not select XSPI domain clock");
2103-
return -EIO;
2104-
}
2105-
/*
2106-
* Get the clock rate from this one (update ahb_clock_freq)
2107-
* TODO: retrieve index in the clocks property where clocks has "xspi-ker"
2108-
* Assuming index is 1
2109-
*/
2110-
if (clock_control_get_rate(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
2111-
(clock_control_subsys_t) &dev_cfg->pclken[1],
2112-
&ahb_clock_freq) < 0) {
2113-
LOG_ERR("Failed call clock_control_get_rate(pclken)");
2114-
return -EIO;
2115-
}
2091+
2092+
#if DT_CLOCKS_HAS_NAME(STM32_XSPI_NODE, xspi_ker)
2093+
/* Kernel clock config for peripheral if any */
2094+
if (clock_control_configure(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
2095+
(clock_control_subsys_t) &dev_cfg->pclken_ker,
2096+
NULL) != 0) {
2097+
LOG_ERR("Could not select XSPI domain clock");
2098+
return -EIO;
21162099
}
2100+
2101+
if (clock_control_get_rate(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
2102+
(clock_control_subsys_t) &dev_cfg->pclken_ker,
2103+
&ahb_clock_freq) < 0) {
2104+
LOG_ERR("Failed call clock_control_get_rate(pclken_ker)");
2105+
return -EIO;
2106+
}
2107+
#endif /* xspi_ker */
2108+
2109+
#if DT_CLOCKS_HAS_NAME(STM32_XSPI_NODE, xspi_mgr)
21172110
/* Clock domain corresponding to the IO-Mgr (XSPIM) */
2118-
if (IS_ENABLED(STM32_XSPI_DOMAIN_CLOCK_SUPPORT) && (dev_cfg->pclk_len > 2)) {
2119-
if (clock_control_on(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
2120-
(clock_control_subsys_t) &dev_cfg->pclken[2]) != 0) {
2121-
LOG_ERR("Could not enable XSPI Manager clock");
2122-
return -EIO;
2123-
}
2124-
/* Do NOT Get the clock rate from this one */
2111+
if (clock_control_on(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
2112+
(clock_control_subsys_t) &dev_cfg->pclken_mgr) != 0) {
2113+
LOG_ERR("Could not enable XSPI Manager clock");
2114+
return -EIO;
21252115
}
2116+
#endif /* xspi_mgr */
21262117

21272118
for (; prescaler <= STM32_XSPI_CLOCK_PRESCALER_MAX; prescaler++) {
21282119
uint32_t clk = STM32_XSPI_CLOCK_COMPUTE(ahb_clock_freq, prescaler);
@@ -2429,13 +2420,25 @@ static int flash_stm32_xspi_init(const struct device *dev)
24292420

24302421
static void flash_stm32_xspi_irq_config_func(const struct device *dev);
24312422

2432-
static const struct stm32_pclken pclken[] = STM32_DT_CLOCKS(STM32_XSPI_NODE);
2433-
24342423
PINCTRL_DT_DEFINE(STM32_XSPI_NODE);
24352424

24362425
static const struct flash_stm32_xspi_config flash_stm32_xspi_cfg = {
2437-
.pclken = pclken,
2438-
.pclk_len = DT_NUM_CLOCKS(STM32_XSPI_NODE),
2426+
.pclken = {
2427+
.bus = DT_CLOCKS_CELL_BY_NAME(STM32_XSPI_NODE, xspix, bus),
2428+
.enr = DT_CLOCKS_CELL_BY_NAME(STM32_XSPI_NODE, xspix, bits)
2429+
},
2430+
#if DT_CLOCKS_HAS_NAME(STM32_XSPI_NODE, xspi_ker)
2431+
.pclken_ker = {
2432+
.bus = DT_CLOCKS_CELL_BY_NAME(STM32_XSPI_NODE, xspi_ker, bus),
2433+
.enr = DT_CLOCKS_CELL_BY_NAME(STM32_XSPI_NODE, xspi_ker, bits)
2434+
},
2435+
#endif /* xspi_ker */
2436+
#if DT_CLOCKS_HAS_NAME(STM32_XSPI_NODE, xspi_mgr)
2437+
.pclken_mgr = {
2438+
.bus = DT_CLOCKS_CELL_BY_NAME(STM32_XSPI_NODE, xspi_mgr, bus),
2439+
.enr = DT_CLOCKS_CELL_BY_NAME(STM32_XSPI_NODE, xspi_mgr, bits)
2440+
},
2441+
#endif /* xspi_mgr */
24392442
.irq_config = flash_stm32_xspi_irq_config_func,
24402443
.flash_size = DT_INST_PROP(0, size) / 8, /* In Bytes */
24412444
.max_frequency = DT_INST_PROP(0, ospi_max_frequency),

drivers/flash/flash_stm32_xspi.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ struct stream {
6767
typedef void (*irq_config_func_t)(const struct device *dev);
6868

6969
struct flash_stm32_xspi_config {
70-
const struct stm32_pclken *pclken;
71-
size_t pclk_len;
70+
const struct stm32_pclken pclken;
71+
const struct stm32_pclken pclken_ker;
72+
const struct stm32_pclken pclken_mgr;
7273
irq_config_func_t irq_config;
7374
size_t flash_size;
7475
uint32_t max_frequency;

0 commit comments

Comments
 (0)