Skip to content

Commit 9ba4902

Browse files
committed
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 1fa0296 commit 9ba4902

File tree

3 files changed

+49
-40
lines changed

3 files changed

+49
-40
lines changed

drivers/flash/flash_stm32_xspi.c

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,53 +2055,44 @@ static int flash_stm32_xspi_init(const struct device *dev)
20552055
return ret;
20562056
}
20572057

2058-
if (dev_cfg->pclk_len > 3) {
2059-
/* Max 3 domain clock are expected */
2060-
LOG_ERR("Could not select %d XSPI domain clock", dev_cfg->pclk_len);
2061-
return -EIO;
2062-
}
2063-
20642058
/* Clock configuration */
20652059
if (clock_control_on(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
2066-
(clock_control_subsys_t) &dev_cfg->pclken[0]) != 0) {
2060+
(clock_control_subsys_t) &dev_cfg->pclken) != 0) {
20672061
LOG_ERR("Could not enable XSPI clock");
20682062
return -EIO;
20692063
}
20702064
if (clock_control_get_rate(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
2071-
(clock_control_subsys_t) &dev_cfg->pclken[0],
2065+
(clock_control_subsys_t) &dev_cfg->pclken,
20722066
&ahb_clock_freq) < 0) {
20732067
LOG_ERR("Failed call clock_control_get_rate(pclken)");
20742068
return -EIO;
20752069
}
2076-
/* Alternate clock config for peripheral if any */
2077-
if (IS_ENABLED(STM32_XSPI_DOMAIN_CLOCK_SUPPORT) && (dev_cfg->pclk_len > 1)) {
2078-
if (clock_control_configure(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
2079-
(clock_control_subsys_t) &dev_cfg->pclken[1],
2080-
NULL) != 0) {
2081-
LOG_ERR("Could not select XSPI domain clock");
2082-
return -EIO;
2083-
}
2084-
/*
2085-
* Get the clock rate from this one (update ahb_clock_freq)
2086-
* TODO: retrieve index in the clocks property where clocks has "xspi-ker"
2087-
* Assuming index is 1
2088-
*/
2089-
if (clock_control_get_rate(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
2090-
(clock_control_subsys_t) &dev_cfg->pclken[1],
2091-
&ahb_clock_freq) < 0) {
2092-
LOG_ERR("Failed call clock_control_get_rate(pclken)");
2093-
return -EIO;
2094-
}
2070+
2071+
#if DT_CLOCKS_HAS_NAME(STM32_XSPI_NODE, xspi_ker)
2072+
/* Kernel clock config for peripheral if any */
2073+
if (clock_control_configure(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
2074+
(clock_control_subsys_t) &dev_cfg->pclken_ker,
2075+
NULL) != 0) {
2076+
LOG_ERR("Could not select XSPI domain clock");
2077+
return -EIO;
20952078
}
2079+
2080+
if (clock_control_get_rate(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
2081+
(clock_control_subsys_t) &dev_cfg->pclken_ker,
2082+
&ahb_clock_freq) < 0) {
2083+
LOG_ERR("Failed call clock_control_get_rate(pclken_ker)");
2084+
return -EIO;
2085+
}
2086+
#endif /* xspi_ker */
2087+
2088+
#if DT_CLOCKS_HAS_NAME(STM32_XSPI_NODE, xspi_mgr)
20962089
/* Clock domain corresponding to the IO-Mgr (XSPIM) */
2097-
if (IS_ENABLED(STM32_XSPI_DOMAIN_CLOCK_SUPPORT) && (dev_cfg->pclk_len > 2)) {
2098-
if (clock_control_on(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
2099-
(clock_control_subsys_t) &dev_cfg->pclken[2]) != 0) {
2100-
LOG_ERR("Could not enable XSPI Manager clock");
2101-
return -EIO;
2102-
}
2103-
/* Do NOT Get the clock rate from this one */
2090+
if (clock_control_on(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
2091+
(clock_control_subsys_t) &dev_cfg->pclken_mgr) != 0) {
2092+
LOG_ERR("Could not enable XSPI Manager clock");
2093+
return -EIO;
21042094
}
2095+
#endif /* xspi_mgr */
21052096

21062097
for (; prescaler <= STM32_XSPI_CLOCK_PRESCALER_MAX; prescaler++) {
21072098
uint32_t clk = STM32_XSPI_CLOCK_COMPUTE(ahb_clock_freq, prescaler);
@@ -2405,13 +2396,25 @@ static int flash_stm32_xspi_init(const struct device *dev)
24052396

24062397
static void flash_stm32_xspi_irq_config_func(const struct device *dev);
24072398

2408-
static const struct stm32_pclken pclken[] = STM32_DT_CLOCKS(STM32_XSPI_NODE);
2409-
24102399
PINCTRL_DT_DEFINE(STM32_XSPI_NODE);
24112400

24122401
static const struct flash_stm32_xspi_config flash_stm32_xspi_cfg = {
2413-
.pclken = pclken,
2414-
.pclk_len = DT_NUM_CLOCKS(STM32_XSPI_NODE),
2402+
.pclken = {
2403+
.bus = DT_CLOCKS_CELL_BY_NAME(STM32_XSPI_NODE, xspix, bus),
2404+
.enr = DT_CLOCKS_CELL_BY_NAME(STM32_XSPI_NODE, xspix, bits)
2405+
},
2406+
#if DT_CLOCKS_HAS_NAME(STM32_XSPI_NODE, xspi_ker)
2407+
.pclken_ker = {
2408+
.bus = DT_CLOCKS_CELL_BY_NAME(STM32_XSPI_NODE, xspi_ker, bus),
2409+
.enr = DT_CLOCKS_CELL_BY_NAME(STM32_XSPI_NODE, xspi_ker, bits)
2410+
},
2411+
#endif /* xspi_ker */
2412+
#if DT_CLOCKS_HAS_NAME(STM32_XSPI_NODE, xspi_mgr)
2413+
.pclken_mgr = {
2414+
.bus = DT_CLOCKS_CELL_BY_NAME(STM32_XSPI_NODE, xspi_mgr, bus),
2415+
.enr = DT_CLOCKS_CELL_BY_NAME(STM32_XSPI_NODE, xspi_mgr, bits)
2416+
},
2417+
#endif /* xspi_mgr */
24152418
.irq_config = flash_stm32_xspi_irq_config_func,
24162419
.flash_size = DT_INST_PROP(0, size) / 8, /* In Bytes */
24172420
.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;

include/zephyr/dt-bindings/clock/stm32h7rs_clock.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838

3939
/** Clock muxes */
4040
#define STM32_SRC_CKPER (STM32_SRC_PLL3_S + 1)
41+
#define STM32_SRC_HCLK1 (STM32_SRC_CKPER + 1)
42+
#define STM32_SRC_HCLK2 (STM32_SRC_HCLK1 + 1)
43+
#define STM32_SRC_HCLK3 (STM32_SRC_HCLK2 + 1)
44+
#define STM32_SRC_HCLK4 (STM32_SRC_HCLK3 + 1)
45+
#define STM32_SRC_HCLK5 (STM32_SRC_HCLK4 + 1)
4146
/** Others: Not yet supported */
4247

4348
/** Bus clocks */

0 commit comments

Comments
 (0)