Skip to content

Commit cf85c61

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 a14b71a commit cf85c61

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
@@ -2065,53 +2065,44 @@ static int flash_stm32_xspi_init(const struct device *dev)
20652065
return ret;
20662066
}
20672067

2068-
if (dev_cfg->pclk_len > 3) {
2069-
/* Max 3 domain clock are expected */
2070-
LOG_ERR("Could not select %d XSPI domain clock", dev_cfg->pclk_len);
2071-
return -EIO;
2072-
}
2073-
20742068
/* Clock configuration */
20752069
if (clock_control_on(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
2076-
(clock_control_subsys_t) &dev_cfg->pclken[0]) != 0) {
2070+
(clock_control_subsys_t) &dev_cfg->pclken) != 0) {
20772071
LOG_ERR("Could not enable XSPI clock");
20782072
return -EIO;
20792073
}
20802074
if (clock_control_get_rate(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
2081-
(clock_control_subsys_t) &dev_cfg->pclken[0],
2075+
(clock_control_subsys_t) &dev_cfg->pclken,
20822076
&ahb_clock_freq) < 0) {
20832077
LOG_ERR("Failed call clock_control_get_rate(pclken)");
20842078
return -EIO;
20852079
}
2086-
/* Alternate clock config for peripheral if any */
2087-
if (IS_ENABLED(STM32_XSPI_DOMAIN_CLOCK_SUPPORT) && (dev_cfg->pclk_len > 1)) {
2088-
if (clock_control_configure(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
2089-
(clock_control_subsys_t) &dev_cfg->pclken[1],
2090-
NULL) != 0) {
2091-
LOG_ERR("Could not select XSPI domain clock");
2092-
return -EIO;
2093-
}
2094-
/*
2095-
* Get the clock rate from this one (update ahb_clock_freq)
2096-
* TODO: retrieve index in the clocks property where clocks has "xspi-ker"
2097-
* Assuming index is 1
2098-
*/
2099-
if (clock_control_get_rate(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
2100-
(clock_control_subsys_t) &dev_cfg->pclken[1],
2101-
&ahb_clock_freq) < 0) {
2102-
LOG_ERR("Failed call clock_control_get_rate(pclken)");
2103-
return -EIO;
2104-
}
2080+
2081+
#if DT_CLOCKS_HAS_NAME(STM32_XSPI_NODE, xspi_ker)
2082+
/* Kernel clock config for peripheral if any */
2083+
if (clock_control_configure(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
2084+
(clock_control_subsys_t) &dev_cfg->pclken_ker,
2085+
NULL) != 0) {
2086+
LOG_ERR("Could not select XSPI domain clock");
2087+
return -EIO;
21052088
}
2089+
2090+
if (clock_control_get_rate(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
2091+
(clock_control_subsys_t) &dev_cfg->pclken_ker,
2092+
&ahb_clock_freq) < 0) {
2093+
LOG_ERR("Failed call clock_control_get_rate(pclken_ker)");
2094+
return -EIO;
2095+
}
2096+
#endif /* xspi_ker */
2097+
2098+
#if DT_CLOCKS_HAS_NAME(STM32_XSPI_NODE, xspi_mgr)
21062099
/* Clock domain corresponding to the IO-Mgr (XSPIM) */
2107-
if (IS_ENABLED(STM32_XSPI_DOMAIN_CLOCK_SUPPORT) && (dev_cfg->pclk_len > 2)) {
2108-
if (clock_control_on(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
2109-
(clock_control_subsys_t) &dev_cfg->pclken[2]) != 0) {
2110-
LOG_ERR("Could not enable XSPI Manager clock");
2111-
return -EIO;
2112-
}
2113-
/* Do NOT Get the clock rate from this one */
2100+
if (clock_control_on(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
2101+
(clock_control_subsys_t) &dev_cfg->pclken_mgr) != 0) {
2102+
LOG_ERR("Could not enable XSPI Manager clock");
2103+
return -EIO;
21142104
}
2105+
#endif /* xspi_mgr */
21152106

21162107
for (; prescaler <= STM32_XSPI_CLOCK_PRESCALER_MAX; prescaler++) {
21172108
uint32_t clk = STM32_XSPI_CLOCK_COMPUTE(ahb_clock_freq, prescaler);
@@ -2419,13 +2410,25 @@ static int flash_stm32_xspi_init(const struct device *dev)
24192410

24202411
static void flash_stm32_xspi_irq_config_func(const struct device *dev);
24212412

2422-
static const struct stm32_pclken pclken[] = STM32_DT_CLOCKS(STM32_XSPI_NODE);
2423-
24242413
PINCTRL_DT_DEFINE(STM32_XSPI_NODE);
24252414

24262415
static const struct flash_stm32_xspi_config flash_stm32_xspi_cfg = {
2427-
.pclken = pclken,
2428-
.pclk_len = DT_NUM_CLOCKS(STM32_XSPI_NODE),
2416+
.pclken = {
2417+
.bus = DT_CLOCKS_CELL_BY_NAME(STM32_XSPI_NODE, xspix, bus),
2418+
.enr = DT_CLOCKS_CELL_BY_NAME(STM32_XSPI_NODE, xspix, bits)
2419+
},
2420+
#if DT_CLOCKS_HAS_NAME(STM32_XSPI_NODE, xspi_ker)
2421+
.pclken_ker = {
2422+
.bus = DT_CLOCKS_CELL_BY_NAME(STM32_XSPI_NODE, xspi_ker, bus),
2423+
.enr = DT_CLOCKS_CELL_BY_NAME(STM32_XSPI_NODE, xspi_ker, bits)
2424+
},
2425+
#endif /* xspi_ker */
2426+
#if DT_CLOCKS_HAS_NAME(STM32_XSPI_NODE, xspi_mgr)
2427+
.pclken_mgr = {
2428+
.bus = DT_CLOCKS_CELL_BY_NAME(STM32_XSPI_NODE, xspi_mgr, bus),
2429+
.enr = DT_CLOCKS_CELL_BY_NAME(STM32_XSPI_NODE, xspi_mgr, bits)
2430+
},
2431+
#endif /* xspi_mgr */
24292432
.irq_config = flash_stm32_xspi_irq_config_func,
24302433
.flash_size = DT_INST_REG_ADDR_BY_IDX(0, 1),
24312434
.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)