Skip to content

Commit 2048488

Browse files
committed
scripts: add Cadence QSPI-NOR registers
Adds register definitions for Cadence QSPI-NOR controllers.
1 parent 4e2d880 commit 2048488

File tree

2 files changed

+203
-0
lines changed

2 files changed

+203
-0
lines changed

generate_svd.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import inspect
1414
import pydevicetree
1515
from scripts.arm_pl022 import generate_registers_arm_pl022
16+
from scripts.cdns_qspi_nor import generate_registers_cdns_qspi
1617
from scripts.riscv_clint0_control import generate_registers_riscv_clint0
1718
from scripts.sifive_clic0_control import generate_registers_sifive_clic0
1819
from scripts.riscv_plic0_control import generate_registers_riscv_plic0
@@ -174,6 +175,8 @@ def generate_peripheral(dts, peripheral, comp, ext, reg, regmap_path):
174175

175176
if regmap_path.endswith("arm_pl022.py"):
176177
name = "spi{}".format(ext)
178+
elif regmap_path.endswith("cdns_qspi_nor.py"):
179+
name = "qspi".format(ext)
177180
elif regmap_path.endswith("riscv_clint0_control.py"):
178181
name = "clint"
179182
elif regmap_path.endswith("riscv_plic0_control.py"):
@@ -231,6 +234,8 @@ def generate_registers(dts, peripheral, regmap_path):
231234
"""Generate xml string for registers from regmap file or generator code"""
232235
if regmap_path.endswith("arm_pl022.py"):
233236
return generate_registers_arm_pl022(dts, peripheral)
237+
if regmap_path.endswith("cdns_qspi_nor.py"):
238+
return generate_registers_cdns_qspi(dts, peripheral)
234239
if regmap_path.endswith("riscv_clint0_control.py"):
235240
return generate_registers_riscv_clint0(dts)
236241
if regmap_path.endswith("sifive_clic0_control.py"):

scripts/cdns_qspi_nor.py

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
#!/usr/bin/env python3
2+
# Copyleft (c) 2023 cmsis-svd-generator developers
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
from scripts.starfive_common import *
6+
7+
"""
8+
This program generates CMSIS SVD xml for cadence QSPI
9+
"""
10+
11+
def generate_registers_cdns_qspi(dts, peripheral):
12+
"""Generate xml string for registers for cadence_qspi peripheral"""
13+
txt = """\
14+
<registers>
15+
"""
16+
txt += generate_register("config", "Cadence QSPI Configuration", 0x00, [
17+
("enable", "Enable the QSPI controller", "[0:0]", "read-write"),
18+
("enb_dir_acc_ctrl", "Enable direct access controller", "[7:7]", "read-write"),
19+
("decode", "Enable the QSPI decoder", "[9:9]", "read-write"),
20+
("chipselect", "Chip select - CS0: 0b1110, CS1: 0b1101, CS2: 0b1011, CS3: 0b0111", "[13:10]", "read-write"),
21+
("dma", "Enable Direct Memory Access", "[15:15]", "read-write"),
22+
("baud", "Set the QSPI BAUD rate divisor", "[22:19]", "read-write"),
23+
("dtr_proto", "Enable DTR Protocol", "[24:24]", "read-write"),
24+
("dual_opcode", "Enable Dual Opcode Mode", "[30:30]", "read-write"),
25+
("idle", "Set Idle", "[31:31]", "read-write"),
26+
])
27+
28+
txt += generate_register("rd_instr", "Cadence QSPI Read Instruction", 0x04, [
29+
("opcode", "Instruction Opcode", "[7:0]", "read-write"),
30+
("type_instr", "Type of Instruction", "[9:8]", "read-write"),
31+
("type_addr", "Type of Address", "[13:12]", "read-write"),
32+
("type_data", "", "[17:16]", "read-write"),
33+
("mode_en", "Mode ", "[20:20]", "read-write"),
34+
("dummy", "Send dummy signal to stall the device", "[28:24]", "read-write"),
35+
])
36+
37+
txt += generate_register("wr_instr", "Cadence QSPI Write Instruction", 0x08, [
38+
("opcode", "Instruction Opcode", "[7:0]", "read-write"),
39+
("type_addr", "Type of Address", "[13:12]", "read-write"),
40+
("type_data", "", "[17:16]", "read-write"),
41+
])
42+
43+
txt += generate_register("delay", "Cadence QSPI Delay", 0x0c, [
44+
("tslch", "TSLCH Delay Value", "[7:0]", "read-write"),
45+
("tchsh", "TCHSH Delay Value", "[15:8]", "read-write"),
46+
("tsd2d", "TSD2D Delay Value", "[23:16]", "read-write"),
47+
("tshsl", "TSHSL Delay Value", "[31:24]", "read-write"),
48+
])
49+
50+
txt += generate_register("read_capture", "Cadence QSPI Read Capture", 0x10, [
51+
("bypass", "Bypass the Read Capture", "[0:0]", "read-write"),
52+
("delay", "Read Capture Delay Value", "[4:1]", "read-write"),
53+
])
54+
55+
txt += generate_register("size", "Cadence QSPI Size Configuration", 0x14, [
56+
("address", "Address Size in Bytes", "[3:0]", "read-write"),
57+
("page", "Page Size in Bytes", "[15:4]", "read-write"),
58+
("block", "Block Size in Bytes", "[21:16]", "read-write"),
59+
])
60+
61+
txt += generate_register("sram_partition", "Cadence QSPI SRAM Partition Size", 0x18, [
62+
("size", "Partition size in bytes", "[31:0]", "read-write"),
63+
])
64+
65+
txt += generate_register("indirect_trigger", "Cadence QSPI Indirect Trigger Address", 0x1c, [
66+
("address", "", "[31:0]", "read-write"),
67+
])
68+
69+
txt += generate_register("dma", "Cadence QSPI Direct Memory Access", 0x20, [
70+
("single", "", "[7:0]", "read-write"),
71+
("burst", "", "[15:8]", "read-write"),
72+
])
73+
74+
txt += generate_register("remap", "Cadence QSPI Remap Address", 0x24, [
75+
("address", "", "[31:0]", "read-write"),
76+
])
77+
78+
txt += generate_register("mode_bit", "Cadence QSPI Mode Bit(s)", 0x28, [
79+
("mode", "", "[31:0]", "read-write"),
80+
])
81+
82+
txt += generate_register("sdram_level", "Cadence QSPI SDRAM Level", 0x2c, [
83+
("rd", "SDRAM Read Level", "[15:0]", "read-only"),
84+
("wr", "SDRAM Write Level", "[31:16]", "read-only"),
85+
])
86+
87+
txt += generate_register("wr_completion_ctrl", "Cadence QSPI Write Completion Control", 0x38, [
88+
# FIXME: fill out the remaining control fields. This is the only field in the Linux driver.
89+
("disable_auto_poll", "SPI NAND flashes require the address of the status register to be passed in the Read SR command. Also, some SPI NOR flashes like the Cypress Semper flash expect a 4-byte dummy address in the Read SR command in DTR mode. But this controller does not support address phase in the Read SR command when doing auto-HW polling. So, disable write completion polling on the controller's side. spi-nand and spi-nor will take care of polling the status register.", "[14:14]", "read-write"),
90+
])
91+
92+
txt += generate_register("irq_status", "Cadence QSPI IRQ Status", 0x40, [
93+
("mode_err", "Mode error interrupt", "[0:0]", "read-write"),
94+
("underflow", "Buffer underflow interrupt", "[1:1]", "read-write"),
95+
("ind_comp", "Indirect computation interrupt", "[2:2]", "read-write"),
96+
("ind_rd_reject", "Indirect read rejection interrupt", "[3:3]", "read-write"),
97+
("wr_protected_err", "Write protected error interrupt", "[4:4]", "read-write"),
98+
("illegal_ahb_err", "Illegal AHB clock error interrupt", "[5:5]", "read-write"),
99+
("watermark", "Watermark interrupt", "[6:6]", "read-write"),
100+
("ind_sram_full", "Indirect SRAM full interrupt", "[12:12]", "read-write"),
101+
# Reset value: (0b1_1111_1111_1111)
102+
], 32, 0x1ffff)
103+
104+
txt += generate_register("irq_mask", "Cadence QSPI IRQ Mask", 0x44, [
105+
("mode_err", "Mode error interrupt", "[0:0]", "read-write"),
106+
("underflow", "Buffer underflow interrupt", "[1:1]", "read-write"),
107+
("ind_comp", "Indirect computation interrupt", "[2:2]", "read-write"),
108+
("ind_rd_reject", "Indirect read rejection interrupt", "[3:3]", "read-write"),
109+
("wr_protected_err", "Write protected error interrupt", "[4:4]", "read-write"),
110+
("illegal_ahb_err", "Illegal AHB clock error interrupt", "[5:5]", "read-write"),
111+
("watermark", "Watermark interrupt", "[6:6]", "read-write"),
112+
("ind_sram_full", "Indirect SRAM full interrupt", "[12:12]", "read-write"),
113+
# Reset value: (IND_COMP | WATERMARK | UNDERFLOW)
114+
], 32, 0x46)
115+
116+
txt += generate_register("indirect_rd", "Cadence QSPI Indirect Read", 0x60, [
117+
("start", "Start indirect read", "[0:0]", "read-write"),
118+
("cancel", "Cancel indirect read", "[1:1]", "read-write"),
119+
("done", "Indirect read done", "[5:5]", "read-write"),
120+
])
121+
122+
txt += generate_register("indirect_rd_watermark", "Cadence QSPI Indirect Read Watermark", 0x64, [
123+
("watermark", "", "[31:0]", "read-write"),
124+
])
125+
126+
txt += generate_register("indirect_rd_start_addr", "Cadence QSPI Indirect Read Start Address", 0x68, [
127+
("address", "", "[31:0]", "read-write"),
128+
])
129+
130+
txt += generate_register("indirect_rd_bytes", "Cadence QSPI Indirect Read Bytes", 0x6c, [
131+
("bytes", "", "[31:0]", "read-write"),
132+
])
133+
134+
txt += generate_register("indirect_wr", "Cadence QSPI Indirect Write", 0x70, [
135+
("start", "Start indirect write", "[0:0]", "read-write"),
136+
("cancel", "Cancel indirect write", "[1:1]", "read-write"),
137+
("done", "Indirect write done", "[5:5]", "read-write"),
138+
])
139+
140+
txt += generate_register("indirect_wr_watermark", "Cadence QSPI Indirect Write Watermark", 0x74, [
141+
("watermark", "", "[31:0]", "read-write"),
142+
])
143+
144+
txt += generate_register("indirect_wr_start_addr", "Cadence QSPI Indirect Write Start Address", 0x78, [
145+
("address", "", "[31:0]", "read-write"),
146+
])
147+
148+
txt += generate_register("indirect_wr_bytes", "Cadence QSPI Indirect Write Bytes", 0x7c, [
149+
("bytes", "", "[31:0]", "read-write"),
150+
])
151+
152+
txt += generate_register("cmd_ctrl", "Cadence QSPI Command Control", 0x90, [
153+
("execute", "Execute-in-Place (XIP)", "[0:0]", "read-write"),
154+
("in_progress", "Command in progress", "[1:1]", "read-write"),
155+
("dummy", "Dummy command", "[11:7]", "read-write"),
156+
("wr_bytes", "Write bytes", "[14:12]", "read-write"),
157+
("wr_en", "Write enable", "[15:15]", "read-write"),
158+
("add_bytes", "Add command bytes", "[17:16]", "read-write"),
159+
("addr_en", "Address enable", "[19:19]", "read-write"),
160+
("rd_bytes", "Read bytes", "[22:20]", "read-write"),
161+
("rd_en", "Read enable", "[23:23]", "read-write"),
162+
("opcode", "Command opcode", "[31:24]", "read-write"),
163+
])
164+
165+
txt += generate_register("cmd_address", "Cadence QSPI Command Address", 0x94, [
166+
("address", "", "[31:0]", "read-write"),
167+
])
168+
169+
txt += generate_register("cmd_read_at_lower", "Cadence QSPI Command Read at Lower", 0xa0, [
170+
("read_at_lower", "", "[31:0]", "read-write"),
171+
])
172+
173+
txt += generate_register("cmd_read_at_upper", "Cadence QSPI Command Read at Upper", 0xa4, [
174+
("read_at_upper", "", "[31:0]", "read-write"),
175+
])
176+
177+
txt += generate_register("cmd_write_at_lower", "Cadence QSPI Command Write at Lower", 0xa8, [
178+
("write_at_lower", "", "[31:0]", "read-write"),
179+
])
180+
181+
txt += generate_register("cmd_write_at_upper", "Cadence QSPI Command Write at Upper", 0xac, [
182+
("write_at_upper", "", "[31:0]", "read-write"),
183+
])
184+
185+
txt += generate_register("polling_status", "Cadence QSPI Polling Status", 0xb0, [
186+
("status", "", "[15:0]", "read-write"),
187+
("dummy", "", "[20:16]", "read-write"),
188+
])
189+
190+
txt += generate_register("ext_lower", "Cadence QSPI Extension Lower", 0xe0, [
191+
("stig", "", "[15:0]", "read-write"),
192+
("write", "", "[23:16]", "read-write"),
193+
("read", "", "[31:24]", "read-write"),
194+
])
195+
196+
return txt + """\
197+
</registers>
198+
"""

0 commit comments

Comments
 (0)