Skip to content

Commit d796c11

Browse files
sagevehenrikbrixandersen
authored andcommitted
stm32: ospi: make all clk, dqs, ncs pins configurable
The clk, dqs and ncs pins can be remapped between OSPI instances, but the driver doesn't support it, yet. Therefore replace hard coded numbers to device tree optional properties. Signed-off-by: Samuel Kleiser <s.kleiser@vega.com>
1 parent 530b593 commit d796c11

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed

drivers/flash/flash_stm32_ospi.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ LOG_MODULE_REGISTER(flash_stm32_ospi, CONFIG_FLASH_LOG_LEVEL);
3636
(_CONCAT(HAL_OSPIM_, DT_STRING_TOKEN(STM32_OSPI_NODE, prop))), \
3737
((default_value)))
3838

39+
#define DT_OSPI_PROP_OR(prop, default_value) \
40+
DT_PROP_OR(STM32_OSPI_NODE, prop, default_value)
41+
3942
/* Get the base address of the flash from the DTS node */
4043
#define STM32_OSPI_BASE_ADDRESS DT_INST_REG_ADDR(0)
4144

@@ -2094,17 +2097,17 @@ static int flash_stm32_ospi_init(const struct device *dev)
20942097
OSPIM_CfgTypeDef ospi_mgr_cfg = {0};
20952098

20962099
if (dev_data->hospi.Instance == OCTOSPI1) {
2097-
ospi_mgr_cfg.ClkPort = 1;
2098-
ospi_mgr_cfg.DQSPort = 1;
2099-
ospi_mgr_cfg.NCSPort = 1;
2100+
ospi_mgr_cfg.ClkPort = DT_OSPI_PROP_OR(clk_port, 1);
2101+
ospi_mgr_cfg.DQSPort = DT_OSPI_PROP_OR(dqs_port, 1);
2102+
ospi_mgr_cfg.NCSPort = DT_OSPI_PROP_OR(ncs_port, 1);
21002103
ospi_mgr_cfg.IOLowPort = DT_OSPI_IO_PORT_PROP_OR(io_low_port,
21012104
HAL_OSPIM_IOPORT_1_LOW);
21022105
ospi_mgr_cfg.IOHighPort = DT_OSPI_IO_PORT_PROP_OR(io_high_port,
21032106
HAL_OSPIM_IOPORT_1_HIGH);
21042107
} else if (dev_data->hospi.Instance == OCTOSPI2) {
2105-
ospi_mgr_cfg.ClkPort = 2;
2106-
ospi_mgr_cfg.DQSPort = 2;
2107-
ospi_mgr_cfg.NCSPort = 2;
2108+
ospi_mgr_cfg.ClkPort = DT_OSPI_PROP_OR(clk_port, 2);
2109+
ospi_mgr_cfg.DQSPort = DT_OSPI_PROP_OR(dqs_port, 2);
2110+
ospi_mgr_cfg.NCSPort = DT_OSPI_PROP_OR(ncs_port, 2);
21082111
ospi_mgr_cfg.IOLowPort = DT_OSPI_IO_PORT_PROP_OR(io_low_port,
21092112
HAL_OSPIM_IOPORT_2_LOW);
21102113
ospi_mgr_cfg.IOHighPort = DT_OSPI_IO_PORT_PROP_OR(io_high_port,

dts/bindings/ospi/st,stm32-ospi.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,48 @@ properties:
119119
Note: You might need to enable the OCTOSPI I/O manager clock to use the
120120
property. Please refer to Reference Manual.
121121
The clock can be enabled in the devicetree.
122+
123+
clk-port:
124+
type: int
125+
enum:
126+
- 1
127+
- 2
128+
description: |
129+
Specifies which port of the OCTOSPI IO Manager is used for the clk pin.
130+
131+
If absent, then n is used where `n` is the OSPI
132+
instance number.
133+
134+
Note: You might need to enable the OCTOSPI I/O manager clock to use the
135+
property. Please refer to Reference Manual.
136+
The clock can be enabled in the devicetree.
137+
138+
dqs-port:
139+
type: int
140+
enum:
141+
- 1
142+
- 2
143+
description: |
144+
Specifies which port of the OCTOSPI IO Manager is used for the dqs pin.
145+
146+
If absent, then n is used where `n` is the OSPI
147+
instance number.
148+
149+
Note: You might need to enable the OCTOSPI I/O manager clock to use the
150+
property. Please refer to Reference Manual.
151+
The clock can be enabled in the devicetree.
152+
153+
ncs-port:
154+
type: int
155+
enum:
156+
- 1
157+
- 2
158+
description: |
159+
Specifies which port of the OCTOSPI IO Manager is used for the ncs pin.
160+
161+
If absent, then n is used where `n` is the OSPI
162+
instance number.
163+
164+
Note: You might need to enable the OCTOSPI I/O manager clock to use the
165+
property. Please refer to Reference Manual.
166+
The clock can be enabled in the devicetree.

0 commit comments

Comments
 (0)