Skip to content

Commit 53921d2

Browse files
committed
eos-s3: iomux config: add default iomux config
Signed-off-by: Paweł Czarnecki <[email protected]>
1 parent 9e4ade2 commit 53921d2

File tree

1 file changed

+123
-38
lines changed

1 file changed

+123
-38
lines changed

quicklogic/pp3/utils/eos_s3_iomux_config.py

Lines changed: 123 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,57 @@
2222
"SDIOMUX": ["PB-SDIOMUX", ],
2323
}
2424

25-
# Default configuration of the IOMUX pad
26-
PAD_DEFAULT = {
25+
# Default configuration of the specific IOMUX pads
26+
PADS_1 = {
27+
2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 18, 21, 22, 23, 24, 25, 26, 27, 28, 29,
28+
30, 31, 32, 33, 35, 37, 40, 41, 42, 43
29+
}
30+
PAD_DEFAULTS_1 = {
31+
"func_sel": 0,
32+
"ctrl_sel": "A0",
33+
"mode": "output",
34+
"pull": "none",
35+
"drive": 4,
36+
"slew": "slow",
37+
"schmitt": 0
38+
}
39+
PADS_2 = {6, 14, 15, 17, 34, 36, 38, 39, 44, 45}
40+
PAD_DEFAULTS_2 = {
41+
"func_sel": 0,
42+
"ctrl_sel": "others",
43+
"mode": "output",
44+
"pull": "none",
45+
"drive": 4,
46+
"slew": "slow",
47+
"schmitt": 0
48+
}
49+
PADS_3 = {8, 9, 19, 20}
50+
PAD_DEFAULTS_3 = {
51+
"func_sel": 0,
52+
"ctrl_sel": "A0",
53+
"mode": "inout",
54+
"pull": "down",
55+
"drive": 4,
56+
"slew": "slow",
57+
"schmitt": 0
58+
}
59+
PADS_4 = {0, 1}
60+
PAD_DEFAULTS_4 = {
61+
"func_sel": 0,
62+
"ctrl_sel": "A0",
63+
"mode": "output",
64+
"pull": "up",
65+
"drive": 4,
66+
"slew": "slow",
67+
"schmitt": 0
68+
}
69+
PADS_5 = {16}
70+
PAD_DEFAULTS_5 = {
2771
"func_sel": 0,
28-
"ctrl_sel": 0,
29-
"mode": "none",
72+
"ctrl_sel": "A0",
73+
"mode": "inout",
3074
"pull": "none",
31-
"drive": 2,
75+
"drive": 4,
3276
"slew": "slow",
3377
"schmitt": 0
3478
}
@@ -53,9 +97,6 @@ def generate_iomux_register_content(config):
5397
pad = int(pad)
5498
reg = 0
5599

56-
# Patch default settings with settings read from the config file
57-
pad_cfg = dict(PAD_DEFAULT, **pad_cfg)
58-
59100
func_sel = pad_cfg["func_sel"]
60101
assert func_sel in [0, 1], func_sel
61102
reg |= func_sel
@@ -137,6 +178,49 @@ def generate_iomux_register_content(config):
137178
return iomux_regs
138179

139180

181+
def get_pad_no(pad_alias):
182+
pad = None
183+
184+
match = re.match(r"^IO_([0-9]+)$", pad_alias)
185+
if match is not None:
186+
pad = int(match.group(1))
187+
188+
# Pad not found or out of range
189+
if pad is None or pad < 0 or pad >= 46:
190+
return -1
191+
192+
return pad
193+
194+
195+
def prepare_default_config(pad_map):
196+
config = {"pads": {}}
197+
198+
# Populate IO config with default configuration for each pad
199+
for pin in pad_map.items():
200+
pad = get_pad_no(pin[1])
201+
if (pad == -1):
202+
continue
203+
204+
pad_config = None
205+
206+
if pad in PADS_1:
207+
pad_config = PAD_DEFAULTS_1
208+
elif pad in PADS_2:
209+
pad_config = PAD_DEFAULTS_2
210+
elif pad in PADS_3:
211+
pad_config = PAD_DEFAULTS_3
212+
elif pad in PADS_4:
213+
pad_config = PAD_DEFAULTS_4
214+
elif pad in PADS_5:
215+
pad_config = PAD_DEFAULTS_5
216+
else:
217+
raise ValueError("Unknown default IOMUX configuration")
218+
219+
config["pads"][str(pad)] = pad_config
220+
221+
return config
222+
223+
140224
# =============================================================================
141225

142226

@@ -189,6 +273,26 @@ def main():
189273

190274
args = parser.parse_args()
191275

276+
pad_map = {}
277+
pad_alias_map = {}
278+
279+
# Read pinmap
280+
for pin_map_entry in csv.DictReader(args.map):
281+
282+
if pin_map_entry['type'] not in IOB_TYPES:
283+
continue
284+
285+
name = pin_map_entry['name']
286+
alias = ""
287+
if 'alias' in pin_map_entry:
288+
alias = pin_map_entry['alias']
289+
pad_alias_map[alias] = name
290+
pad_map[name] = alias
291+
else:
292+
pad_map[name] = name
293+
294+
config = prepare_default_config(pad_map)
295+
192296
# Read the requested configurtion from a JSON file
193297
if args.json is not None:
194298

@@ -197,7 +301,11 @@ def main():
197301
exit(-1)
198302

199303
with open(args.json, "r") as fp:
200-
config = json.load(fp)
304+
json_config = json.load(fp)
305+
306+
# Overlay default config
307+
for design_pad, pad_config in json_config["pads"].items():
308+
config["pads"][str(design_pad)] = pad_config
201309

202310
# Generate the config according to the EBLIF netlist and PCF constraints.
203311
else:
@@ -206,23 +314,6 @@ def main():
206314
print("Use either '--json' or '--pcf' + '--eblif' options!")
207315
exit(-1)
208316

209-
pad_map = {}
210-
pad_alias_map = {}
211-
212-
for pin_map_entry in csv.DictReader(args.map):
213-
214-
if pin_map_entry['type'] not in IOB_TYPES:
215-
continue
216-
217-
name = pin_map_entry['name']
218-
alias = ""
219-
if 'alias' in pin_map_entry:
220-
alias = pin_map_entry['alias']
221-
pad_alias_map[alias] = name
222-
pad_map[name] = alias
223-
else:
224-
pad_map[name] = name
225-
226317
# Read and parse PCF
227318
with open(args.pcf, "r") as fp:
228319
pcf = list(parse_simple_pcf(fp))
@@ -231,9 +322,6 @@ def main():
231322
with open(args.eblif, "r") as fp:
232323
eblif = parse_blif(fp)
233324

234-
# Build the config
235-
config = {"pads": {}}
236-
237325
eblif_inputs = eblif["inputs"]["args"]
238326
eblif_outputs = eblif["outputs"]["args"]
239327

@@ -261,19 +349,14 @@ def main():
261349
if pad_name in pad_alias_map:
262350
pad_alias = pad_name
263351

264-
pad = None
265-
266-
match = re.match(r"^IO_([0-9]+)$", pad_alias)
267-
if match is not None:
268-
pad = int(match.group(1))
269-
270-
# Pad not found or out of range
271-
if pad is None or pad < 0 or pad >= 46:
352+
pad_no = get_pad_no(pad_alias)
353+
if (pad_no == -1):
272354
continue
273355

274356
# Detect inouts:
275357
is_inout_in = constraint.net + '_$inp' in eblif_inputs
276358
is_inout_out = constraint.net + '_$out' in eblif_outputs
359+
277360
if is_inout_in and is_inout_out:
278361
pad_config = {
279362
"ctrl_sel": "fabric",
@@ -296,7 +379,9 @@ def main():
296379
else:
297380
assert False, (constraint.net, constraint.pad)
298381

299-
config["pads"][str(pad)] = pad_config
382+
# Overlay default config
383+
config["pads"][str(pad_no)
384+
] = dict(config["pads"][str(pad_no)], **pad_config)
300385

301386
# Convert the config to IOMUX register content
302387
iomux_regs = generate_iomux_register_content(config)

0 commit comments

Comments
 (0)