3 """ define functions here, with their pin names and the pin type.
5 each function returns a pair of lists
6 (or objects with a __getitem__ function)
8 the first list (or object) contains pin name plus type specifications.
12 * "-" for an input pin,
13 * "+" for an output pin,
14 * "*" for an in/out pin
16 each function is then added to the pinspec tuple, below, as a ("NAME",
19 different functions may be added multiple times under the same NAME,
20 so that complex (or large) functions can be split into one or more
21 groups (and placed on different pinbanks).
23 eint, pwm and gpio are slightly odd in that instead of a fixed list
24 an object is returned with a __getitem__ function that accepts a
25 slice object. in this way the actual generation of the pin name
26 is delayed until it is known precisely how many pins are to be
27 generated, and that's not known immediately (or it would be if
28 every single one of the functions below had a start and end parameter
29 added). see spec.interfaces.PinGen class slice on pingroup
31 the second list is the names of pins that are part of an inout bus.
32 this list of pins (a ganged group) will need to be changed under
33 the control of the function, as a group. for example: sdmmc's
34 D0-D3 pins are in-out, they all change from input to output at
35 the same time under the control of the function, therefore there's
36 no point having multiple in-out switch/control wires, as the
37 sdmmc is never going to do anything other than switch this entire
38 bank all at once. so in this particular example, sdmmc returns:
40 (['CMD+', 'CLK+', 'D0*', 'D1*', 'D2*', 'D3*'] # pin names
41 ['D0*', 'D1*', 'D2*', 'D3*']) # ganged bus names
45 3rd item in list gives the name of the clock.
49 def i2s(suffix
, bank
):
50 return (['MCK+', 'BCK+', 'LRCK+', 'DI-', 'DO+'],
54 # XXX TODO: correct these. this is a stub for now
55 # https://bugs.libre-soc.org/show_bug.cgi?id=303
56 def lpc(suffix
, bank
, pincount
=4):
57 lpcpins
= ['CMD*', 'CLK+']
59 for i
in range(pincount
):
63 return (lpcpins
, inout
, 'CLK')
66 def emmc(suffix
, bank
, pincount
=8):
67 emmcpins
= ['CMD*', 'CLK+']
69 for i
in range(pincount
):
71 emmcpins
.append(pname
)
73 return (emmcpins
, inout
, 'CLK')
76 def sdmmc(suffix
, bank
):
77 return emmc(suffix
, bank
, pincount
=4)
80 def nspi(suffix
, bank
, iosize
, masteronly
=True):
82 qpins
= ['CK+', 'NSS+']
84 qpins
= ['CK*', 'NSS*']
87 qpins
+= ['MOSI+', 'MISO-']
89 for i
in range(iosize
):
93 return (qpins
, inout
, 'CK')
96 def mspi(suffix
, bank
):
97 return nspi(suffix
, bank
, 2, masteronly
=True)
100 def mquadspi(suffix
, bank
):
101 return nspi(suffix
, bank
, 4, masteronly
=True)
104 def spi(suffix
, bank
):
105 return nspi(suffix
, bank
, 2)
108 def quadspi(suffix
, bank
):
109 return nspi(suffix
, bank
, 4)
112 def i2c(suffix
, bank
):
113 """bi-directional (reversible, master-slave) I2C
115 return (['SDA*', 'SCL*'], [], 'SCL')
118 def mi2c(suffix
, bank
):
119 """master-only I2C (clock is output only)
121 return (['SDA*', 'SCL+'], [], 'SCL')
124 def jtag(suffix
, bank
):
125 return (['TMS-', 'TDI-', 'TDO+', 'TCK+'], [], 'TCK')
128 def uart(suffix
, bank
):
129 return (['TX+', 'RX-'], [], None)
132 def ulpi(suffix
, bank
):
133 ulpipins
= ['CK+', 'DIR+', 'STP+', 'NXT+']
135 ulpipins
.append('D%d*' % i
)
136 return (ulpipins
, [], 'CK')
139 def uartfull(suffix
, bank
):
140 return (['TX+', 'RX-', 'CTS-', 'RTS+'], [], None)
143 def rgbttl(suffix
, bank
):
144 ttlpins
= ['CK+', 'DE+', 'HS+', 'VS+']
146 ttlpins
.append("OUT%d+" % i
)
147 return (ttlpins
, [], 'CK')
150 def rgmii(suffix
, bank
):
153 buspins
.append("ERXD%d-" % i
)
155 buspins
.append("ETXD%d+" % i
)
156 buspins
+= ['ERXCK-', 'ERXERR-', 'ERXDV-',
158 'ETXEN+', 'ETXCK+', 'ECRS-',
160 return (buspins
, [], ['ERXCK', 'ETXCK'])
163 def flexbus1(suffix
, bank
):
168 buspins
.append(pname
)
171 buspins
.append("CS%d+" % i
)
172 buspins
+= ['ALE+', 'OE+', 'RW+', 'TA-',
173 # 'TS+', commented out for now, mirrors ALE, for mux'd mode
177 buspins
.append("BWE%d+" % i
)
178 for i
in range(2, 6):
179 buspins
.append("CS%d+" % i
)
180 return (buspins
, inout
, None)
183 def flexbus2(suffix
, bank
):
185 for i
in range(8, 32):
186 buspins
.append("AD%d*" % i
)
187 return (buspins
, buspins
, None)
190 def sdram1(suffix
, bank
, n_adr
=10):
195 buspins
.append(pname
)
198 buspins
.append(pname
)
201 buspins
.append("BA%d+" % i
)
202 for i
in range(n_adr
):
203 buspins
.append("AD%d+" % i
)
204 buspins
+= ['CLK+', 'CKE+', 'RASn+', 'CASn+', 'WEn+',
206 return (buspins
, inout
, 'CLK')
209 def sdram2(suffix
, bank
):
212 for i
in range(10, 13):
213 buspins
.append("AD%d+" % i
)
214 for i
in range(1, 2):
216 buspins
.append(pname
)
217 for i
in range(8, 16):
219 buspins
.append(pname
)
221 return (buspins
, inout
, None)
224 def sdram3(suffix
, bank
):
227 for i
in range(1, 6):
228 buspins
.append("CSn%d+" % i
)
229 for i
in range(13, 14):
230 buspins
.append("AD%d+" % i
)
231 for i
in range(1, 4):
233 for i
in range(8, 32):
235 buspins
.append(pname
)
237 return (buspins
, inout
, None)
240 def mcu8080(suffix
, bank
):
245 buspins
.append(pname
)
248 buspins
.append("AD%d+" % (i
+ 8))
250 buspins
.append("CS%d+" % i
)
252 buspins
.append("NRB%d+" % i
)
253 buspins
+= ['CD+', 'RD+', 'WR+', 'CLE+', 'ALE+',
255 return (buspins
, inout
, None)
258 class RangePin(object):
259 def __init__(self
, suffix
, prefix
=None):
261 self
.prefix
= prefix
or ''
263 def __getitem__(self
, s
):
265 for idx
in range(s
.start
or 0, s
.stop
or -1, s
.step
or 1):
266 res
.append("%s%d%s" % (self
.prefix
, idx
, self
.suffix
))
270 def eint(suffix
, bank
):
271 return (RangePin("-"), [], None)
274 def pwm(suffix
, bank
):
275 return (RangePin("+"), [], None)
278 def gpio(suffix
, bank
):
279 return (("GPIO%s" % bank
, RangePin(prefix
=bank
, suffix
="*")), [], None)
281 def vss(suffix
, bank
):
282 return (RangePin("-"), [], None)
284 def vdd(suffix
, bank
):
285 return (RangePin("-"), [], None)
287 def sys(suffix
, bank
):
288 return (['RST-', # reset line
289 'PLLCLK-', # incoming clock (to PLL)
290 'PLLSELA0-', 'PLLSELA1-', # PLL divider-selector
291 'PLLTESTOUT+', # divided-output (for testing)
292 'PLLVCOUT+', # PLL VCO analog out (for testing)
295 # list functions by name here
297 pinspec
= (('IIS', i2s
),