Skip to content

Commit 022a540

Browse files
committed
dts: bindings: dma: gd32: split gd,gd32-dma-v1 for support F4xx feature
Split gd,gd32-dma-v1 from gd,gd32-dma to support F4xx specific features. Signed-off-by: TOKITA Hiroshi <[email protected]>
1 parent adfc2cc commit 022a540

File tree

4 files changed

+121
-19
lines changed

4 files changed

+121
-19
lines changed

drivers/dma/Kconfig.gd32

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
config DMA_GD32
55
bool "Gigadevice GD32 DMA driver"
66
default y
7-
depends on DT_HAS_GD_GD32_DMA_ENABLED
7+
depends on DT_HAS_GD_GD32_DMA_ENABLED || DT_HAS_GD_GD32_DMA_V1_ENABLED
88
select USE_GD32_DMA
99
help
1010
DMA driver for GigaDevice GD32 series MCUs.

drivers/dma/dma_gd32.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
#define DT_DRV_COMPAT gd_gd32_dma
8-
97
#include <zephyr/device.h>
108
#include <zephyr/drivers/clock_control.h>
119
#include <zephyr/drivers/clock_control/gd32.h>
@@ -16,7 +14,13 @@
1614
#include <gd32_dma.h>
1715
#include <zephyr/irq.h>
1816

19-
#ifdef CONFIG_SOC_SERIES_GD32F4XX
17+
#if DT_HAS_COMPAT_STATUS_OKAY(gd_gd32_dma_v1)
18+
#define DT_DRV_COMPAT gd_gd32_dma_v1
19+
#elif DT_HAS_COMPAT_STATUS_OKAY(gd_gd32_dma)
20+
#define DT_DRV_COMPAT gd_gd32_dma
21+
#endif
22+
23+
#if DT_HAS_COMPAT_STATUS_OKAY(gd_gd32_dma_v1)
2024
#define CHXCTL_PERIEN_OFFSET ((uint32_t)25U)
2125
#define GD32_DMA_CHXCTL_DIR BIT(6)
2226
#define GD32_DMA_CHXCTL_M2M BIT(7)
@@ -59,7 +63,7 @@ struct dma_gd32_config {
5963
uint32_t channels;
6064
uint16_t clkid;
6165
bool mem2mem;
62-
#ifdef CONFIG_SOC_SERIES_GD32F4XX
66+
#if DT_HAS_COMPAT_STATUS_OKAY(gd_gd32_dma_v1)
6367
struct reset_dt_spec reset;
6468
#endif
6569
void (*irq_configure)(void);
@@ -190,7 +194,7 @@ gd32_dma_periph_width_config(uint32_t reg, dma_channel_enum ch, uint32_t pwidth)
190194
GD32_DMA_CHCTL(reg, ch) = (ctl & (~DMA_CHXCTL_PWIDTH)) | pwidth;
191195
}
192196

193-
#ifdef CONFIG_SOC_SERIES_GD32F4XX
197+
#if DT_HAS_COMPAT_STATUS_OKAY(gd_gd32_dma_v1)
194198
static inline void
195199
gd32_dma_channel_subperipheral_select(uint32_t reg, dma_channel_enum ch,
196200
dma_subperipheral_enum sub_periph)
@@ -212,7 +216,7 @@ gd32_dma_periph_address_config(uint32_t reg, dma_channel_enum ch, uint32_t addr)
212216
static inline void
213217
gd32_dma_memory_address_config(uint32_t reg, dma_channel_enum ch, uint32_t addr)
214218
{
215-
#ifdef CONFIG_SOC_SERIES_GD32F4XX
219+
#if DT_HAS_COMPAT_STATUS_OKAY(gd_gd32_dma_v1)
216220
DMA_CHM0ADDR(reg, ch) = addr;
217221
#else
218222
GD32_DMA_CHMADDR(reg, ch) = addr;
@@ -234,7 +238,7 @@ gd32_dma_transfer_number_get(uint32_t reg, dma_channel_enum ch)
234238
static inline void
235239
gd32_dma_interrupt_flag_clear(uint32_t reg, dma_channel_enum ch, uint32_t flag)
236240
{
237-
#ifdef CONFIG_SOC_SERIES_GD32F4XX
241+
#if DT_HAS_COMPAT_STATUS_OKAY(gd_gd32_dma_v1)
238242
if (ch < DMA_CH4) {
239243
DMA_INTC0(reg) |= DMA_FLAG_ADD(flag, ch);
240244
} else {
@@ -248,7 +252,7 @@ gd32_dma_interrupt_flag_clear(uint32_t reg, dma_channel_enum ch, uint32_t flag)
248252
static inline void
249253
gd32_dma_flag_clear(uint32_t reg, dma_channel_enum ch, uint32_t flag)
250254
{
251-
#ifdef CONFIG_SOC_SERIES_GD32F4XX
255+
#if DT_HAS_COMPAT_STATUS_OKAY(gd_gd32_dma_v1)
252256
if (ch < DMA_CH4) {
253257
DMA_INTC0(reg) |= DMA_FLAG_ADD(flag, ch);
254258
} else {
@@ -262,7 +266,7 @@ gd32_dma_flag_clear(uint32_t reg, dma_channel_enum ch, uint32_t flag)
262266
static inline uint32_t
263267
gd32_dma_interrupt_flag_get(uint32_t reg, dma_channel_enum ch, uint32_t flag)
264268
{
265-
#ifdef CONFIG_SOC_SERIES_GD32F4XX
269+
#if DT_HAS_COMPAT_STATUS_OKAY(gd_gd32_dma_v1)
266270
if (ch < DMA_CH4) {
267271
return (DMA_INTF0(reg) & DMA_FLAG_ADD(flag, ch));
268272
} else {
@@ -280,7 +284,7 @@ static inline void gd32_dma_deinit(uint32_t reg, dma_channel_enum ch)
280284
GD32_DMA_CHCTL(reg, ch) = DMA_CHCTL_RESET_VALUE;
281285
GD32_DMA_CHCNT(reg, ch) = DMA_CHCNT_RESET_VALUE;
282286
GD32_DMA_CHPADDR(reg, ch) = DMA_CHPADDR_RESET_VALUE;
283-
#ifdef CONFIG_SOC_SERIES_GD32F4XX
287+
#if DT_HAS_COMPAT_STATUS_OKAY(gd_gd32_dma_v1)
284288
DMA_CHM0ADDR(reg, ch) = DMA_CHMADDR_RESET_VALUE;
285289
DMA_CHFCTL(reg, ch) = DMA_CHFCTL_RESET_VALUE;
286290
if (ch < DMA_CH4) {
@@ -409,7 +413,7 @@ static int dma_gd32_config(const struct device *dev, uint32_t channel,
409413
return -ENOTSUP;
410414
}
411415

412-
#ifdef CONFIG_SOC_SERIES_GD32F4XX
416+
#if DT_HAS_COMPAT_STATUS_OKAY(gd_gd32_dma_v1)
413417
if (dma_cfg->dma_slot > 0xF) {
414418
LOG_ERR("dma_slot must be <7 (%" PRIu32 ")",
415419
dma_cfg->dma_slot);
@@ -468,7 +472,7 @@ static int dma_gd32_config(const struct device *dev, uint32_t channel,
468472
gd32_dma_periph_width_config(cfg->reg, channel,
469473
dma_gd32_periph_width(periph_cfg->width));
470474
gd32_dma_circulation_disable(cfg->reg, channel);
471-
#ifdef CONFIG_SOC_SERIES_GD32F4XX
475+
#if DT_HAS_COMPAT_STATUS_OKAY(gd_gd32_dma_v1)
472476
if (dma_cfg->channel_direction != MEMORY_TO_MEMORY) {
473477
gd32_dma_channel_subperipheral_select(cfg->reg, channel,
474478
dma_cfg->dma_slot);
@@ -600,7 +604,7 @@ static int dma_gd32_init(const struct device *dev)
600604
(void)clock_control_on(GD32_CLOCK_CONTROLLER,
601605
(clock_control_subsys_t *)&cfg->clkid);
602606

603-
#ifdef CONFIG_SOC_SERIES_GD32F4XX
607+
#if DT_HAS_COMPAT_STATUS_OKAY(gd_gd32_dma_v1)
604608
(void)reset_line_toggle_dt(&cfg->reset);
605609
#endif
606610

@@ -674,7 +678,7 @@ static const struct dma_driver_api dma_gd32_driver_api = {
674678
.channels = DT_INST_PROP(inst, dma_channels), \
675679
.clkid = DT_INST_CLOCKS_CELL(inst, id), \
676680
.mem2mem = DT_INST_PROP(inst, gd_mem2mem), \
677-
IF_ENABLED(CONFIG_SOC_SERIES_GD32F4XX, \
681+
IF_ENABLED(DT_HAS_COMPAT_STATUS_OKAY(gd_gd32_dma_v1), \
678682
(.reset = RESET_DT_SPEC_INST_GET(inst),)) \
679683
.irq_configure = dma_gd32##inst##_irq_configure, \
680684
}; \

dts/arm/gigadevice/gd32f4xx/gd32f4xx.dtsi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -618,28 +618,28 @@
618618
};
619619

620620
dma0: dma@40026000 {
621-
compatible = "gd,gd32-dma";
621+
compatible = "gd,gd32-dma-v1";
622622
reg = <0x40026000 0x400>;
623623
interrupts = <11 0>, <12 0>, <13 0>, <14 0>,
624624
<15 0>, <16 0>, <17 0>, <47 0>;
625625
clocks = <&cctl GD32_CLOCK_DMA0>;
626626
resets = <&rctl GD32_RESET_DMA0>;
627627
dma-channels = <8>;
628628
gd,mem2mem;
629-
#dma-cells = <2>;
629+
#dma-cells = <4>;
630630
status = "disabled";
631631
};
632632

633633
dma1: dma@40026400 {
634-
compatible = "gd,gd32-dma";
634+
compatible = "gd,gd32-dma-v1";
635635
reg = <0x40026400 0x400>;
636636
interrupts = <56 0>, <57 0>, <58 0>, <59 0>,
637637
<60 0>, <68 0>, <69 0>, <70 0>;
638638
clocks = <&cctl GD32_CLOCK_DMA1>;
639639
resets = <&rctl GD32_RESET_DMA1>;
640640
dma-channels = <8>;
641641
gd,mem2mem;
642-
#dma-cells = <2>;
642+
#dma-cells = <4>;
643643
status = "disabled";
644644
};
645645
};
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Copyright (c) 2022, TOKITA Hiroshi <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: |
5+
GD32 DMA controller with FIFO
6+
7+
channel: Select channel for data transmitting
8+
9+
slot: Select peripheral to connect DMA
10+
11+
config: A 32bit mask specifying the DMA channel configuration
12+
- bit 6-7: Direction (see dma.h)
13+
- 0x0: MEMORY to MEMORY
14+
- 0x1: MEMORY to PERIPH
15+
- 0x2: PERIPH to MEMORY
16+
- 0x3: reserved for PERIPH to PERIPH
17+
18+
- bit 9: Peripheral address increase
19+
- 0x0: no address increment between transfers
20+
- 0x1: increment address between transfers
21+
22+
- bit 10: Memory address increase
23+
- 0x0: no address increase between transfers
24+
- 0x1: increase address between transfers
25+
26+
- bit 11-12: Peripheral data width
27+
- 0x0: 8 bits
28+
- 0x1: 16 bits
29+
- 0x2: 32 bits
30+
- 0x3: reserved
31+
32+
- bit 13-14: Memory data width
33+
- 0x0: 8 bits
34+
- 0x1: 16 bits
35+
- 0x2: 32 bits
36+
- 0x3: reserved
37+
38+
- bit 15: Peripheral Increment Offset Size
39+
- 0x0: offset size is linked to the peripheral bus width
40+
- 0x1: offset size is fixed to 4 (32-bit alignment)
41+
42+
- bit 16-17: Priority
43+
- 0x0: low
44+
- 0x1: medium
45+
- 0x2: high
46+
- 0x3: very high
47+
48+
fifo-threshold: A 32bit bitfield value specifying FIFO threshold
49+
- bit 0-1: Depth of DMA's FIFO used by burst-transfer.
50+
- 0x0: 1 word
51+
- 0x1: 2 word
52+
- 0x2: 3 word
53+
- 0x3: 4 word
54+
55+
56+
Example of devicetree configuration
57+
58+
&spi0 {
59+
status = "okay";
60+
pinctrl-0 = <&spi0_default>;
61+
pinctrl-names = "default";
62+
cs-gpios = <&gpioa 4 GPIO_ACTIVE_LOW>;
63+
64+
dmas = <&dma1 0 3 0 0>, <&dma1 5 3 GD32_DMA_PRIORITY_HIGH 0>
65+
dma-names = "rx", "tx";
66+
};
67+
68+
"spi0" uses dma1 for transmitting and receiving in the example.
69+
Each is named "rx" and "tx".
70+
The first cell assigns channel 0 to receive and channel 5 to transmit.
71+
The second cell is slot. Both channels select 3.
72+
What the slot number '3' means depends on the DMA controller and channel.
73+
See the Hardware manual.
74+
The config that places on the third can take various configs.
75+
But the setting used depends on each driver implementation.
76+
Set the priority for the transmitting channel as HIGH, LOW(the default) for receive channel.
77+
The fifo-threshold cell that places the fourth is configuring FIFO threshold.
78+
The behavior of burst transfer determines by data-width in the config cell,
79+
burst-length in the dma_config struct, and fifo-threshold.
80+
A single burst transfer transfers [ (4 * fifo-threshold) ] bytes using with DMA's FIFO.
81+
Where (data-width * burst-length) must be multiple numbers of burst transfer size.
82+
For example, In the case of data-width is 'byte' and burst-length is 8.
83+
If the fifo-threshold is a 2-word case, it runs one burst transfer to transfer 8 bytes.
84+
Or the fifo-threshold is a 4-word case, runs two times burst transfer to transferring 8 bytes each time.
85+
86+
compatible: "gd,gd32-dma-v1"
87+
88+
include: [ "reset-device.yaml", "gd,gd32-dma-base.yaml" ]
89+
90+
properties:
91+
"#dma-cells":
92+
const: 4
93+
94+
dma-cells:
95+
- channel
96+
- slot
97+
- config
98+
- fifo-threshold

0 commit comments

Comments
 (0)