Skip to content

Commit 5455c55

Browse files
danieldegrassecarlescufi
authored andcommitted
drivers: memc_mcux_flexspi: enable configuring AHB RX buffer allocation
Allow configuration of AHB RX buffer allocation. This allows sections of the AHB RX buffer to be reserved for specific masters, which can enhance performance. Signed-off-by: Daniel DeGrasse <[email protected]>
1 parent 77c149b commit 5455c55

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

drivers/memc/memc_mcux_flexspi.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020 NXP
2+
* Copyright 2020-2023 NXP
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -29,6 +29,13 @@
2929

3030
LOG_MODULE_REGISTER(memc_flexspi, CONFIG_MEMC_LOG_LEVEL);
3131

32+
struct memc_flexspi_buf_cfg {
33+
uint16_t prefetch;
34+
uint16_t priority;
35+
uint16_t master_id;
36+
uint16_t buf_size;
37+
} __packed;
38+
3239
/* flexspi device data should be stored in RAM to avoid read-while-write hazards */
3340
struct memc_flexspi_data {
3441
FLEXSPI_Type *base;
@@ -45,6 +52,8 @@ struct memc_flexspi_data {
4552
const struct pinctrl_dev_config *pincfg;
4653
#endif
4754
size_t size[kFLEXSPI_PortCount];
55+
struct memc_flexspi_buf_cfg *buf_cfg;
56+
uint8_t buf_cfg_cnt;
4857
};
4958

5059
void memc_flexspi_wait_bus_idle(const struct device *dev)
@@ -170,6 +179,20 @@ static int memc_flexspi_init(const struct device *dev)
170179
flexspi_config.enableSckBDiffOpt = data->sck_differential_clock;
171180
flexspi_config.rxSampleClock = data->rx_sample_clock;
172181

182+
/* Configure AHB RX buffers, if any configuration settings are present */
183+
__ASSERT(data->buf_cfg_cnt < FSL_FEATURE_FLEXSPI_AHB_BUFFER_COUNT,
184+
"Maximum RX buffer configuration count exceeded");
185+
for (uint8_t i = 0; i < data->buf_cfg_cnt; i++) {
186+
/* Should AHB prefetch up to buffer size? */
187+
flexspi_config.ahbConfig.buffer[i].enablePrefetch = data->buf_cfg[i].prefetch;
188+
/* AHB access priority (used for suspending control of AHB prefetching )*/
189+
flexspi_config.ahbConfig.buffer[i].priority = data->buf_cfg[i].priority;
190+
/* AHB master index, SOC specific */
191+
flexspi_config.ahbConfig.buffer[i].masterIndex = data->buf_cfg[i].master_id;
192+
/* RX buffer allocation (total available buffer space is instance/SOC specific) */
193+
flexspi_config.ahbConfig.buffer[i].bufferSize = data->buf_cfg[i].buf_size;
194+
}
195+
173196
FLEXSPI_Init(data->base, &flexspi_config);
174197

175198
return 0;
@@ -226,6 +249,9 @@ static int memc_flexspi_pm_action(const struct device *dev, enum pm_device_actio
226249

227250
#define MEMC_FLEXSPI(n) \
228251
PINCTRL_DEFINE(n) \
252+
static uint16_t buf_cfg_##n[] = \
253+
DT_INST_PROP_OR(n, rx_buffer_config, {0}); \
254+
\
229255
static struct memc_flexspi_data \
230256
memc_flexspi_data_##n = { \
231257
.base = (FLEXSPI_Type *) DT_INST_REG_ADDR(n), \
@@ -238,6 +264,9 @@ static int memc_flexspi_pm_action(const struct device *dev, enum pm_device_actio
238264
.combination_mode = DT_INST_PROP(n, combination_mode), \
239265
.sck_differential_clock = DT_INST_PROP(n, sck_differential_clock), \
240266
.rx_sample_clock = DT_INST_PROP(n, rx_clock_source), \
267+
.buf_cfg = (struct memc_flexspi_buf_cfg *)buf_cfg_##n, \
268+
.buf_cfg_cnt = sizeof(buf_cfg_##n) / \
269+
sizeof(struct memc_flexspi_buf_cfg), \
241270
PINCTRL_INIT(n) \
242271
}; \
243272
\

dts/bindings/spi/nxp,imx-flexspi.yaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, NXP
1+
# Copyright 2018-2023, NXP
22
# SPDX-License-Identifier: Apache-2.0
33

44
description: NXP FlexSPI controller
@@ -61,6 +61,19 @@ properties:
6161
Source clock for flash read. See the RXCLKSRC field in register MCR0.
6262
The default corresponds to the reset value of the register field.
6363
64+
rx-buffer-config:
65+
type: array
66+
description: |
67+
Array of tuples to configure AHB RX buffers. Format is the following:
68+
<prefetch priority master_id buf_size>. Pass multiple tuples to configure
69+
multiple RX buffers (up to maximum supported by SOC).
70+
The tuple fields correspond to the following register bitfields:
71+
prefetch: AHBRXBUFxCRx[PREFETCH]
72+
priority: AHBRXBUFxCRx[PRIORITY]
73+
master_id: AHBRXBUFxCRx[MSTRID]
74+
buf_size: AHBRXBUFxCRx[BUFSZ]
75+
76+
6477
child-binding:
6578
description: NXP FlexSPI port
6679

0 commit comments

Comments
 (0)