2 # see https://bugs.libre-soc.org/show_bug.cgi?id=304
4 from spec
.base
import PinSpec
5 from parse
import Parse
8 from pprint
import pprint
9 from spec
.ifaceprint
import display
, display_fns
, check_functions
10 from spec
.ifaceprint
import display_fixed
11 from collections
import OrderedDict
14 pinbanks
= OrderedDict((
42 'PWM': 'PWM (pulse-width modulation)',
43 'MSPI0': 'SPI Master 1 (general)',
44 'MSPI1': 'SPI Master 2 (SDCard)',
45 'UART0': 'UART (TX/RX) 1',
46 'SYS': 'System Control',
48 'EINT': 'External Interrupt',
51 'MTWI': 'I2C Master 1',
56 #'LPC1': 'Low Pincount Interface 1',
57 #'LPC2': 'Low Pincount Interface 2',
60 ps
= PinSpec(pinbanks
, fixedpins
, function_names
)
62 ps
.vss("E", ('N', 0), 0, 0, 1)
63 ps
.vdd("E", ('N', 1), 0, 0, 1)
64 ps
.sdram1("", ('N', 2), 0, 0, 30)
65 ps
.vss("I", ('N', 30), 0, 0, 1)
66 ps
.vdd("I", ('N', 31), 0, 0, 1)
68 ps
.vss("E", ('E', 0), 0, 1, 1)
69 ps
.vdd("E", ('E', 1), 0, 1, 1)
70 ps
.sdram2("", ('E', 2), 0, 0, 12)
71 ps
.vss("I", ('E', 14), 0, 1, 1)
72 ps
.vdd("I", ('E', 15), 0, 1, 1)
73 ps
.gpio("", ('E', 16), 0, 8, 8)
74 ps
.jtag("", ('E', 25), 0, 0, 4)
76 ps
.vss("I", ('S', 0), 0, 2, 1)
77 ps
.vdd("I", ('S', 1), 0, 2, 1)
78 ps
.mi2c("", ('S', 2), 0, 0, 2)
79 ps
.mspi("0", ('S', 8), 0)
80 ps
.uart("0", ('S', 13), 0)
81 ps
.gpio("", ('S', 15), 0, 0, 8)
82 ps
.sys("", ('S', 23), 0, 0, 7)
83 ps
.vss("I", ('S', 30), 0, 3, 1)
84 ps
.vdd("I", ('S', 31), 0, 3, 1)
86 ps
.vss("E", ('W', 0), 0, 2, 1)
87 ps
.vdd("E", ('W', 1), 0, 2, 1)
88 ps
.pwm("", ('W', 2), 0, 0, 2)
89 ps
.eint("", ('W', 4), 0, 0, 3)
90 ps
.mspi("1", ('W', 7), 0)
91 ps
.sdmmc("0", ('W', 11), 0)
92 ps
.vss("I", ('W', 30), 0, 4, 1)
93 ps
.vdd("I", ('W', 31), 0, 4, 1)
94 #ps.mspi("0", ('W', 8), 0)
95 #ps.mspi("1", ('W', 8), 0)
97 #ps.mquadspi("1", ('S', 0), 0)
99 print "ps clocks", ps
.clocks
101 # Scenarios below can be spec'd out as either "find first interface"
102 # by name/number e.g. SPI1, or as "find in bank/mux" which must be
103 # spec'd as "BM:Name" where B is bank (A-F), M is Mux (0-3)
104 # EINT and PWM are grouped together, specially, but may still be spec'd
105 # using "BM:Name". Pins are removed in-order as listed from
106 # lists (interfaces, EINTs, PWMs) from available pins.
108 ls180
= ['SD0', 'UART0', 'GPIOS', 'GPIOE', 'JTAG', 'PWM', 'EINT',
110 'MTWI', 'MSPI0', 'MSPI1', 'SDR']
112 ls180_pwm
= []#['B0:PWM_0']
114 'SD0': 'user-facing: internal (on Card), multiplexed with JTAG\n'
115 'and UART2, for debug purposes',
124 'B1:LCD/22': '18-bit RGB/TTL LCD',
125 'ULPI0/8': 'user-facing: internal (on Card), USB-OTG ULPI PHY',
126 'ULPI1': 'dual USB2 Host ULPI PHY'
129 ps
.add_scenario("Libre-SOC 180nm", ls180
, ls180_eint
, ls180_pwm
,
135 # map pins to litex name conventions, primarily for use in coriolis2
136 # yes this is a mess. it'll do the job though. improvements later
137 def pinparse(psp
, pinspec
):
138 p
= Parse(pinspec
, verify
=False)
142 print p
.muxed_cells_bank
148 pads
= {'N': pn
, 'S': ps
, 'E': pe
, 'W': pw
}
156 for (padnum
, name
, x
), bank
in zip(p
.muxed_cells
, p
.muxed_cells_bank
):
158 domain
= None # TODO, get this from the PinSpec. sigh
160 start
= p
.bankstart
[bank
]
161 banknum
= padnum
- start
162 print "bank", bank
, banknum
, "padname", name
, padnum
, x
166 if name
.startswith('vss'):
167 name
= 'p_%sck_' % name
[:-2] + name
[-1]
169 elif name
.startswith('vdd'):
174 name
= 'p_%sck_' % name
[:-2] + name
[-1]
176 elif name
.startswith('sys'):
178 if name
== 'sys_clk':
180 elif name
== 'sys_rst':
181 #name = 'p_sys_rst_1'
182 pad
= [name
, name
, name
]
183 padbank
[banknum
] = name
184 print "sys_rst add", bank
, banknum
, name
186 elif name
== 'sys_pllclk':
188 elif name
== 'sys_pllock':
190 pad
= ['p_' + name
, name
, name
]
191 elif name
== 'sys_pllout':
192 name
= 'sys_pll_48_o'
193 pad
= ['p_' + name
, name
, name
]
194 elif name
.startswith('sys_csel'):
196 name2
= 'sys_clksel_i(%s)' % i
197 name
= 'p_sys_clksel_' + i
198 pad
= [name
, name2
, name2
]
200 # iopads.append([pname, name, name])
201 print "sys pad", name
203 elif name
.startswith('mspi0') or name
.startswith('mspi1'):
208 elif suffix
== 'nss':
210 if name
.startswith('mspi1'):
211 prefix
= 'spimaster_'
213 prefix
= 'spisdcard_'
214 name
= prefix
+ suffix
215 pad
= ['p_' + name
, name
, name
]
217 elif name
.startswith('sd0'):
219 if name
.startswith('sd0_d'):
221 name
= 'sdcard_data' + i
222 name2
= 'sdcard_data_%%s(%s)' % i
223 pad
= ['p_' + name
, name
, name2
% 'o', name2
% 'i',
225 elif name
.startswith('sd0_cmd'):
227 name2
= 'sdcard_cmd_%s'
228 pad
= ['p_'+name
, name
, name2
% 'o', name2
% 'i', name2
% 'oe']
230 name
= 'sdcard_' + name
[4:]
231 pad
= ['p_' + name
, name
, name
]
233 elif name
.startswith('sdr'):
235 if name
== 'sdr_clk':
237 pad
= ['p_' + name
, name
, name
]
238 elif name
.startswith('sdr_ad'):
240 name
= 'sdram_a_' + i
241 name2
= 'sdram_a(%s)' % i
242 pad
= ['p_' + name
, name2
, name2
]
243 elif name
.startswith('sdr_ba'):
245 name
= 'sdram_ba_' + i
246 name2
= 'sdram_ba(%s)' % i
247 pad
= ['p_' + name
, name2
, name2
]
248 elif name
.startswith('sdr_dqm'):
250 name
= 'sdram_dm_' + i
251 name2
= 'sdram_dm(%s)' % i
252 pad
= ['p_' + name
, name2
, name2
]
253 elif name
.startswith('sdr_d'):
255 name
= 'sdram_dq_' + i
256 name2
= 'sdram_dq_%%s(%s)' % i
257 pad
= ['p_'+name
, name
, name2
% 'o', name2
% 'i', 'sdram_dq_oe']
258 elif name
== 'sdr_csn0':
260 pad
= ['p_' + name
, name
, name
]
261 elif name
[-1] == 'n':
262 name
= 'sdram_' + name
[4:-1] + '_n'
263 pad
= ['p_' + name
, name
, name
]
265 name
= 'sdram_' + name
[4:]
266 pad
= ['p_' + name
, name
, name
]
268 elif name
.startswith('uart'):
270 name
= 'uart_' + name
[6:]
271 pad
= ['p_' + name
, name
, name
]
273 elif name
.startswith('gpio'):
277 name2
= 'gpio_%%s(%s)' % i
278 pad
= ['p_' + name
, name
, name2
% 'o', name2
% 'i', name2
% 'oe']
279 print ("GPIO pad", name
, pad
)
281 elif name
.startswith('mtwi'):
283 name
= 'i2c' + name
[4:]
284 if name
.startswith('i2c_sda'):
286 pad
= ['p_'+name
, name
, name2
% 'o', name2
% 'i', name2
% 'oe']
287 print ("I2C pad", name
, pad
)
289 pad
= ['p_' + name
, name
, name
]
291 elif name
.startswith('twi'):
293 name
= 'i2c' + name
[3:]
295 pad
= ['p_'+name
, name
, name2
% 'o', name2
% 'i', name2
% 'oe']
296 print ("I2C pad", name
, pad
)
298 elif name
.startswith('eint'):
302 name2
= 'eint(%s)' % i
303 pad
= ['p_' + name
, name2
, name2
]
305 elif name
.startswith('pwm'):
309 name2
= 'pwm(%s)' % i
310 pad
= ['p_' + name
, name2
, name2
]
312 pad
= ['p_' + name
, name
, name
]
313 print ("GPIO pad", name
, pad
)
316 if name
and name
.startswith('jtag'):
319 if name
and not name
.startswith('p_'):
322 padbank
[banknum
] = name
324 if domain
is not None:
325 if domain
not in domains
:
327 domains
[domain
].append(name
)
329 if domain
in psp
.clocks
and orig_name
.startswith(dl
):
330 clk
= psp
.clocks
[domain
]
331 if clk
.lower() in orig_name
: # TODO, might over-match
332 clocks
[domain
] = name
334 pinmap
[orig_name
] = name
337 if domain
and pad
is not None:
338 # append direction from spec/domain. damn awkward processing
340 fn
, name
= orig_name
.split("_")
347 for k
in psp
.byspec
.keys():
348 if k
.startswith(domain
):
350 print "spec found", domain
, spec
351 assert spec
is not None
354 if pname
.lower().startswith(name
):
356 print "found spec", found
357 assert found
is not None
358 # whewwww. add the direction onto the pad spec list
359 pad
.append(found
[-1])
364 for pl
in [pe
, pw
, pn
, ps
]:
365 for i
in range(len(pl
)):
367 pl
[i
] = 'nc_%d' % nc_idx
383 print "chip domains (excluding sys-default)"
385 print "chip clocks (excluding sys-default)"
395 'pads.instances' : iopads
,
396 'pins.specs' : psp
.byspec
,
398 'chip.domains' : domains
,
399 'chip.clocks' : clocks
,
400 'chip.n_intpower': n_intpower
,
401 'chip.n_extpower': n_extpower
,
404 chip
= json
.dumps(chip
)
405 with
open("ls180/litex_pinpads.json", "w") as f
: