Skip to content

Commit 2604951

Browse files
gautierg-stfabiobaltieri
authored andcommitted
drivers: flash: Use dts to configure STM32 OSPI manager clock
Instead of calling __HAL_RCC_OSPIM_CLK_ENABLE() to enable the OSPI manager clock, we now use a new clock binding in the dts. In order to avoid confusion between the different clocks, the driver is modified to select the clock based on their names instead of indexes. Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
1 parent 59d6b94 commit 2604951

File tree

1 file changed

+47
-30
lines changed

1 file changed

+47
-30
lines changed

drivers/flash/flash_stm32_ospi.c

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,17 @@ struct stream {
8080

8181
typedef void (*irq_config_func_t)(const struct device *dev);
8282

83+
#define STM32_OSPI_NODE DT_INST_PARENT(0)
84+
8385
struct flash_stm32_ospi_config {
8486
OCTOSPI_TypeDef *regs;
85-
const struct stm32_pclken *pclken; /* clock subsystem */
86-
size_t pclk_len; /* number of clock subsystems */
87+
const struct stm32_pclken pclken; /* clock subsystem */
88+
#if DT_CLOCKS_HAS_NAME(STM32_OSPI_NODE, ospi_ker)
89+
const struct stm32_pclken pclken_ker; /* clock subsystem */
90+
#endif
91+
#if DT_CLOCKS_HAS_NAME(STM32_OSPI_NODE, ospi_mgr)
92+
const struct stm32_pclken pclken_mgr; /* clock subsystem */
93+
#endif
8794
irq_config_func_t irq_config;
8895
size_t flash_size;
8996
uint32_t max_frequency;
@@ -1720,32 +1727,39 @@ static int flash_stm32_ospi_init(const struct device *dev)
17201727

17211728
/* Clock configuration */
17221729
if (clock_control_on(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
1723-
(clock_control_subsys_t) &dev_cfg->pclken[0]) != 0) {
1730+
(clock_control_subsys_t) &dev_cfg->pclken) != 0) {
17241731
LOG_ERR("Could not enable OSPI clock");
17251732
return -EIO;
17261733
}
17271734
/* Alternate clock config for peripheral if any */
1728-
if (dev_cfg->pclk_len > 1) {
1729-
if (clock_control_configure(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
1730-
(clock_control_subsys_t) &dev_cfg->pclken[1],
1731-
NULL) != 0) {
1732-
LOG_ERR("Could not select OSPI domain clock pclk[1]");
1733-
return -EIO;
1734-
}
1735-
if (clock_control_get_rate(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
1736-
(clock_control_subsys_t) &dev_cfg->pclken[1],
1737-
&ahb_clock_freq) < 0) {
1738-
LOG_ERR("Failed call clock_control_get_rate(pclk[1])");
1739-
return -EIO;
1740-
}
1741-
} else {
1742-
if (clock_control_get_rate(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
1743-
(clock_control_subsys_t) &dev_cfg->pclken[0],
1744-
&ahb_clock_freq) < 0) {
1745-
LOG_ERR("Failed call clock_control_get_rate(pclk[0])");
1746-
return -EIO;
1747-
}
1735+
#if DT_CLOCKS_HAS_NAME(STM32_OSPI_NODE, ospi_ker)
1736+
if (clock_control_configure(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
1737+
(clock_control_subsys_t) &dev_cfg->pclken_ker,
1738+
NULL) != 0) {
1739+
LOG_ERR("Could not select OSPI domain clock");
1740+
return -EIO;
1741+
}
1742+
if (clock_control_get_rate(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
1743+
(clock_control_subsys_t) &dev_cfg->pclken_ker,
1744+
&ahb_clock_freq) < 0) {
1745+
LOG_ERR("Failed call clock_control_get_rate(pclken_ker)");
1746+
return -EIO;
17481747
}
1748+
#else
1749+
if (clock_control_get_rate(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
1750+
(clock_control_subsys_t) &dev_cfg->pclken,
1751+
&ahb_clock_freq) < 0) {
1752+
LOG_ERR("Failed call clock_control_get_rate(pclken)");
1753+
return -EIO;
1754+
}
1755+
#endif
1756+
#if DT_CLOCKS_HAS_NAME(STM32_OSPI_NODE, ospi_mgr)
1757+
if (clock_control_on(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
1758+
(clock_control_subsys_t) &dev_cfg->pclken_mgr) != 0) {
1759+
LOG_ERR("Could not enable OSPI Manager clock");
1760+
return -EIO;
1761+
}
1762+
#endif
17491763

17501764
for (; prescaler <= STM32_OSPI_CLOCK_PRESCALER_MAX; prescaler++) {
17511765
uint32_t clk = ahb_clock_freq / (prescaler + 1);
@@ -1787,7 +1801,6 @@ static int flash_stm32_ospi_init(const struct device *dev)
17871801
/* OCTOSPI I/O manager init Function */
17881802
OSPIM_CfgTypeDef ospi_mgr_cfg = {0};
17891803

1790-
__HAL_RCC_OSPIM_CLK_ENABLE();
17911804
if (dev_data->hospi.Instance == OCTOSPI1) {
17921805
ospi_mgr_cfg.ClkPort = 1;
17931806
ospi_mgr_cfg.DQSPort = 1;
@@ -1962,16 +1975,20 @@ static int flash_stm32_ospi_init(const struct device *dev)
19621975

19631976
static void flash_stm32_ospi_irq_config_func(const struct device *dev);
19641977

1965-
#define STM32_OSPI_NODE DT_INST_PARENT(0)
1966-
19671978
PINCTRL_DT_DEFINE(STM32_OSPI_NODE);
19681979

1969-
static const struct stm32_pclken pclken_id[] = STM32_DT_CLOCKS(STM32_OSPI_NODE);
1970-
19711980
static const struct flash_stm32_ospi_config flash_stm32_ospi_cfg = {
19721981
.regs = (OCTOSPI_TypeDef *)DT_REG_ADDR(STM32_OSPI_NODE),
1973-
.pclken = pclken_id,
1974-
.pclk_len = DT_NUM_CLOCKS(STM32_OSPI_NODE),
1982+
.pclken = {.bus = DT_CLOCKS_CELL_BY_NAME(STM32_OSPI_NODE, ospix, bus),
1983+
.enr = DT_CLOCKS_CELL_BY_NAME(STM32_OSPI_NODE, ospix, bits)},
1984+
#if DT_CLOCKS_HAS_NAME(STM32_OSPI_NODE, ospi_ker)
1985+
.pclken_ker = {.bus = DT_CLOCKS_CELL_BY_NAME(STM32_OSPI_NODE, ospi_ker, bus),
1986+
.enr = DT_CLOCKS_CELL_BY_NAME(STM32_OSPI_NODE, ospi_ker, bits)},
1987+
#endif
1988+
#if DT_CLOCKS_HAS_NAME(STM32_OSPI_NODE, ospi_mgr)
1989+
.pclken_mgr = {.bus = DT_CLOCKS_CELL_BY_NAME(STM32_OSPI_NODE, ospi_mgr, bus),
1990+
.enr = DT_CLOCKS_CELL_BY_NAME(STM32_OSPI_NODE, ospi_mgr, bits)},
1991+
#endif
19751992
.irq_config = flash_stm32_ospi_irq_config_func,
19761993
.flash_size = DT_INST_PROP(0, size) / 8U,
19771994
.max_frequency = DT_INST_PROP(0, ospi_max_frequency),

0 commit comments

Comments
 (0)