Skip to content

Commit a28f849

Browse files
committed
feature: scripts: add JH7110 DMC peripherals
Adds function to generate register arrays using the `dim` and `dimIncrement` register attributes. Adds scripts to generate JH7110 DDR memory controller CTRL and PHY peripheral registers.
1 parent 954ea4e commit a28f849

4 files changed

+70
-3
lines changed

generate_svd.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
from scripts.snps_designware_i2c import generate_registers_snps_designware_i2c
2121
from scripts.snps_dw_apb_uart import generate_registers_snps_dw_apb_uart
2222
from scripts.starfive_common import generate_interrupt
23+
from scripts.starfive_jh7110_dmc_ctrl import generate_registers_starfive_jh7110_dmc_ctrl
24+
from scripts.starfive_jh7110_dmc_phy import generate_registers_starfive_jh7110_dmc_phy
2325
from scripts.starfive_jh7110_pmu import generate_registers_starfive_jh7110_pmu
2426
from scripts.starfive_jh7110_stgcrg import generate_registers_starfive_jh7110_stgcrg
2527
from scripts.starfive_jh7110_syscrg import generate_registers_starfive_jh7110_syscrg
@@ -124,13 +126,13 @@ def generate_peripherals(dts):
124126

125127
if "clint" in comp and not os.path.exists(script_path):
126128
regmap_path = ""
127-
script_path = os.path.join(regmap_root, "scripts", "riscv_clint0_control.py")
129+
script_path = os.path.join(regmap_root, "scripts", "riscv_clint0_control.py")
128130
elif "plic" in comp and not os.path.exists(script_path):
129131
regmap_path = ""
130-
script_path = os.path.join(regmap_root, "scripts", "riscv_plic0_control.py")
132+
script_path = os.path.join(regmap_root, "scripts", "riscv_plic0_control.py")
131133
elif "clic" in comp and not os.path.exists(script_path):
132134
regmap_path = ""
133-
script_path = os.path.join(regmap_root, "scripts", "sifive_clic0_control.py")
135+
script_path = os.path.join(regmap_root, "scripts", "sifive_clic0_control.py")
134136

135137
if os.path.exists(regmap_path):
136138
ext = str(idx[comp])
@@ -211,6 +213,10 @@ def generate_peripheral(dts, peripheral, comp, ext, reg, regmap_path):
211213
name = "pwm"
212214
elif regmap_path.endswith("starfive_jh7110_trng.py"):
213215
name = "trng"
216+
elif regmap_path.endswith("starfive_jh7110_dmc_ctrl.py"):
217+
name = "dmc_ctrl"
218+
elif regmap_path.endswith("starfive_jh7110_dmc_phy.py"):
219+
name = "dmc_phy"
214220
else:
215221
name = "{}_{}".format(get_name_as_id(comp), ext)
216222

@@ -251,6 +257,10 @@ def generate_registers(dts, peripheral, regmap_path):
251257
return generate_registers_snps_designware_i2c(dts, peripheral)
252258
if regmap_path.endswith("snps_dw_apb_uart.py"):
253259
return generate_registers_snps_dw_apb_uart(dts, peripheral)
260+
if regmap_path.endswith("starfive_jh7110_dmc_ctrl.py"):
261+
return generate_registers_starfive_jh7110_dmc_ctrl(dts, peripheral)
262+
if regmap_path.endswith("starfive_jh7110_dmc_phy.py"):
263+
return generate_registers_starfive_jh7110_dmc_phy(dts, peripheral)
254264
if regmap_path.endswith("starfive_jh7110_pmu.py"):
255265
return generate_registers_starfive_jh7110_pmu(dts, peripheral)
256266
if regmap_path.endswith("starfive_jh7110_syscrg.py"):

scripts/starfive_common.py

+12
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,18 @@ def generate_register(name, desc, addr, field_name_desc_range_access, size=32, r
230230
</register>
231231
"""
232232

233+
def generate_register_arr(name, desc, addr, dim, dim_inc, reset_value=0):
234+
return """\
235+
<register>
236+
<dim>""" + str(dim) + """</dim>
237+
<dimIncrement>""" + "{:#x}".format(dim_inc) + """</dimIncrement>
238+
<name>""" + name + """[%s]</name>
239+
<description>""" + desc + """</description>
240+
<addressOffset>""" + "{:#x}".format(addr) + """</addressOffset>
241+
<resetValue>""" + str(reset_value) + """</resetValue>
242+
</register>
243+
"""
244+
233245
def generate_field(name, desc, bit_range, access):
234246
if len(desc) == 0:
235247
desc = name

scripts/starfive_jh7110_dmc_ctrl.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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 starfive JH7110 dmc ctrl
9+
"""
10+
11+
def generate_registers_starfive_jh7110_dmc_ctrl(dts, peripheral):
12+
"""Generate xml string for registers for starfive_dmc_ctrl peripheral"""
13+
txt = """\
14+
<registers>
15+
"""
16+
17+
txt += generate_register_arr("csr", "DDR Memory Control CSR register", 0x0, 1024, 0x20)
18+
txt += generate_register_arr("sec", "DDR Memory Control SEC register", 0x1000, 1024, 0x20)
19+
20+
return txt + """\
21+
</registers>
22+
"""

scripts/starfive_jh7110_dmc_phy.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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 starfive JH7110 dmc phy
9+
"""
10+
11+
def generate_registers_starfive_jh7110_dmc_phy(dts, peripheral):
12+
"""Generate xml string for registers for starfive_dmc_phy peripheral"""
13+
txt = """\
14+
<registers>
15+
"""
16+
17+
txt += generate_register_arr("csr", "DDR Memory Control PHY CSR", 0x0, 512, 0x20)
18+
txt += generate_register_arr("base", "DDR Memory Control PHY Base register", 0x800, 512, 0x20)
19+
txt += generate_register_arr("ac_base", "DDR Memory Control PHY AC Base register", 0x1000, 512, 0x20)
20+
21+
return txt + """\
22+
</registers>
23+
"""

0 commit comments

Comments
 (0)