Software APIs
dt_api.c
Go to the documentation of this file.
1// Copyright lowRISC contributors (OpenTitan project).
2// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3// SPDX-License-Identifier: Apache-2.0
4//
5// Device table API auto-generated by `dtgen`
6
7
8/**
9 * @file
10 * @brief Device Tables (DT) API for top englishbreakfast
11 */
12
13#include "hw/top/dt/dt_api.h"
15#include <stdint.h>
16
17
18enum {
19 kTopEnglishbreakfastPlicIrqIdCount = kTopEnglishbreakfastPlicIrqIdLast + 1,
20};
21
22static const dt_instance_id_t instance_from_irq[kTopEnglishbreakfastPlicIrqIdCount] = {
111};
112
114 if (irq <= kTopEnglishbreakfastPlicIrqIdLast) {
115 return instance_from_irq[irq];
116 }
118}
119
120static const dt_device_type_t device_type[kDtInstanceIdCount] = {
140};
141
143 if (dev < kDtInstanceIdCount) {
144 return device_type[dev];
145 }
147}
148
149/**
150 * Pad description.
151 *
152 * A `dt_pad_t` represents a chip's physical pad.
153 */
154typedef struct dt_pad_desc {
155 dt_pad_type_t type; /**< Pad type */
156 /**
157 * For `kDtPadTypeMio` pads: MIO out number. This is the index of the MIO_OUTSEL register
158 * that controls this pad (or the output part of this pad).
159 *
160 * For `kDtPadTypeDio`: DIO pad number. This is the index of the various DIO_PAD_* registers
161 * that control this pad.
162 */
163 uint16_t mio_out_or_direct_pad;
164 /**
165 * For `kDtPadTypeMio` pads: MIO pad number. This is the value to put in the MIO_PERIPH_INSEL
166 * registers to connect a peripheral to this pad.
167 */
168 uint16_t insel;
170
171
172
173// Pad descriptions.
174static const dt_pad_desc_t dt_pad[kDtPadCount] = {
176 .type = kDtPadTypeMio,
177 .mio_out_or_direct_pad = 0,
179 },
181 .type = kDtPadTypeMio,
182 .mio_out_or_direct_pad = 0,
184 },
185 [kDtPadIoa0] = {
186 .type = kDtPadTypeMio,
187 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoa0,
189 },
190 [kDtPadIoa1] = {
191 .type = kDtPadTypeMio,
192 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoa1,
194 },
195 [kDtPadIoa2] = {
196 .type = kDtPadTypeMio,
197 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoa2,
199 },
200 [kDtPadIoa3] = {
201 .type = kDtPadTypeMio,
202 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoa3,
204 },
205 [kDtPadIoa4] = {
206 .type = kDtPadTypeMio,
207 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoa4,
209 },
210 [kDtPadIoa5] = {
211 .type = kDtPadTypeMio,
212 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoa5,
214 },
215 [kDtPadIoa6] = {
216 .type = kDtPadTypeMio,
217 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoa6,
219 },
220 [kDtPadIoa7] = {
221 .type = kDtPadTypeMio,
222 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoa7,
224 },
225 [kDtPadIoa8] = {
226 .type = kDtPadTypeMio,
227 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoa8,
229 },
230 [kDtPadIob0] = {
231 .type = kDtPadTypeMio,
232 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIob0,
234 },
235 [kDtPadIob1] = {
236 .type = kDtPadTypeMio,
237 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIob1,
239 },
240 [kDtPadIob2] = {
241 .type = kDtPadTypeMio,
242 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIob2,
244 },
245 [kDtPadIob3] = {
246 .type = kDtPadTypeMio,
247 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIob3,
249 },
250 [kDtPadIob4] = {
251 .type = kDtPadTypeMio,
252 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIob4,
254 },
255 [kDtPadIob5] = {
256 .type = kDtPadTypeMio,
257 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIob5,
259 },
260 [kDtPadIob6] = {
261 .type = kDtPadTypeMio,
262 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIob6,
264 },
265 [kDtPadIob7] = {
266 .type = kDtPadTypeMio,
267 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIob7,
269 },
270 [kDtPadIob8] = {
271 .type = kDtPadTypeMio,
272 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIob8,
274 },
275 [kDtPadIob9] = {
276 .type = kDtPadTypeMio,
277 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIob9,
279 },
280 [kDtPadIob10] = {
281 .type = kDtPadTypeMio,
282 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIob10,
284 },
285 [kDtPadIob11] = {
286 .type = kDtPadTypeMio,
287 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIob11,
289 },
290 [kDtPadIob12] = {
291 .type = kDtPadTypeMio,
292 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIob12,
294 },
295 [kDtPadIoc0] = {
296 .type = kDtPadTypeMio,
297 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoc0,
299 },
300 [kDtPadIoc1] = {
301 .type = kDtPadTypeMio,
302 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoc1,
304 },
305 [kDtPadIoc2] = {
306 .type = kDtPadTypeMio,
307 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoc2,
309 },
310 [kDtPadIoc3] = {
311 .type = kDtPadTypeMio,
312 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoc3,
314 },
315 [kDtPadIoc4] = {
316 .type = kDtPadTypeMio,
317 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoc4,
319 },
320 [kDtPadIoc5] = {
321 .type = kDtPadTypeMio,
322 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoc5,
324 },
325 [kDtPadIoc6] = {
326 .type = kDtPadTypeMio,
327 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoc6,
329 },
330 [kDtPadIoc7] = {
331 .type = kDtPadTypeMio,
332 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoc7,
334 },
335 [kDtPadIoc8] = {
336 .type = kDtPadTypeMio,
337 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoc8,
339 },
340 [kDtPadIoc9] = {
341 .type = kDtPadTypeMio,
342 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoc9,
344 },
345 [kDtPadIoc10] = {
346 .type = kDtPadTypeMio,
347 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoc10,
349 },
350 [kDtPadIoc11] = {
351 .type = kDtPadTypeMio,
352 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoc11,
354 },
355 [kDtPadIoc12] = {
356 .type = kDtPadTypeMio,
357 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoc12,
359 },
360 [kDtPadIor0] = {
361 .type = kDtPadTypeMio,
362 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIor0,
364 },
365 [kDtPadIor1] = {
366 .type = kDtPadTypeMio,
367 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIor1,
369 },
370 [kDtPadIor2] = {
371 .type = kDtPadTypeMio,
372 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIor2,
374 },
375 [kDtPadIor3] = {
376 .type = kDtPadTypeMio,
377 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIor3,
379 },
380 [kDtPadIor4] = {
381 .type = kDtPadTypeMio,
382 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIor4,
384 },
385 [kDtPadIor5] = {
386 .type = kDtPadTypeMio,
387 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIor5,
389 },
390 [kDtPadIor6] = {
391 .type = kDtPadTypeMio,
392 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIor6,
394 },
395 [kDtPadIor7] = {
396 .type = kDtPadTypeMio,
397 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIor7,
399 },
400 [kDtPadIor10] = {
401 .type = kDtPadTypeMio,
402 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIor10,
404 },
405 [kDtPadIor11] = {
406 .type = kDtPadTypeMio,
407 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIor11,
409 },
410 [kDtPadIor12] = {
411 .type = kDtPadTypeMio,
412 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIor12,
414 },
415 [kDtPadIor13] = {
416 .type = kDtPadTypeMio,
417 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIor13,
419 },
421 .type = kDtPadTypeDio,
422 .mio_out_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiHost0Sd0,
423 .insel = 0,
424 },
426 .type = kDtPadTypeDio,
427 .mio_out_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiHost0Sd1,
428 .insel = 0,
429 },
431 .type = kDtPadTypeDio,
432 .mio_out_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiHost0Sd2,
433 .insel = 0,
434 },
436 .type = kDtPadTypeDio,
437 .mio_out_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiHost0Sd3,
438 .insel = 0,
439 },
441 .type = kDtPadTypeDio,
442 .mio_out_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiDeviceSd0,
443 .insel = 0,
444 },
446 .type = kDtPadTypeDio,
447 .mio_out_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiDeviceSd1,
448 .insel = 0,
449 },
451 .type = kDtPadTypeDio,
452 .mio_out_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiDeviceSd2,
453 .insel = 0,
454 },
456 .type = kDtPadTypeDio,
457 .mio_out_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiDeviceSd3,
458 .insel = 0,
459 },
460 [kDtPadUsbdevUsbDp] = {
461 .type = kDtPadTypeDio,
462 .mio_out_or_direct_pad = kTopEnglishbreakfastDirectPadsUsbdevUsbDp,
463 .insel = 0,
464 },
465 [kDtPadUsbdevUsbDn] = {
466 .type = kDtPadTypeDio,
467 .mio_out_or_direct_pad = kTopEnglishbreakfastDirectPadsUsbdevUsbDn,
468 .insel = 0,
469 },
471 .type = kDtPadTypeDio,
472 .mio_out_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiDeviceSck,
473 .insel = 0,
474 },
476 .type = kDtPadTypeDio,
477 .mio_out_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiDeviceCsb,
478 .insel = 0,
479 },
481 .type = kDtPadTypeDio,
482 .mio_out_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiHost0Sck,
483 .insel = 0,
484 },
486 .type = kDtPadTypeDio,
487 .mio_out_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiHost0Csb,
488 .insel = 0,
489 },
490};
491
492
493
494#define TRY_GET_PAD(pad, default) ({ if ((pad) < (dt_pad_t)0 || (pad) >= kDtPadCount) return (default); &dt_pad[pad]; })
495
497 return TRY_GET_PAD(pad, kDtPadTypeUnspecified)->type;
498}
499
500dt_pinmux_mio_out_t dt_pad_mio_out(dt_pad_t pad) {
501 return (dt_pinmux_mio_out_t)TRY_GET_PAD(pad, 0)->mio_out_or_direct_pad;
502}
503
504dt_pinmux_muxed_pad_t dt_pad_mio_pad_index(dt_pad_t pad) {
505 // Same index as MIO_OUT.
506 return (dt_pinmux_muxed_pad_t)dt_pad_mio_out(pad);
507}
508
509dt_pinmux_insel_t dt_pad_mio_insel(dt_pad_t pad) {
510 return (dt_pinmux_insel_t)TRY_GET_PAD(pad, 0)->insel;
511}
512
513dt_pinmux_direct_pad_t dt_pad_dio_pad_index(dt_pad_t pad) {
514 return (dt_pinmux_direct_pad_t)TRY_GET_PAD(pad, 0)->mio_out_or_direct_pad;
515}
516
517/* Pin that is constantly tied to high-Z (input only) */
518const dt_periph_io_t kDtPeriphIoConstantHighZ = {
519 .__internal = {
520 .type = kDtPeriphIoTypeMio,
521 .periph_input_or_direct_pad = 0,
522 .outsel_or_dt_pad = kDtPinmuxOutselConstantHighZ,
523 }
524};
525
526/* Pin that is constantly tied to zero (input/output) */
527const dt_periph_io_t kDtPeriphIoConstantZero = {
528 .__internal = {
529 .type = kDtPeriphIoTypeMio,
530 .periph_input_or_direct_pad = 0,
531 .outsel_or_dt_pad = kDtPinmuxOutselConstantZero,
532 }
533};
534
535/* Pin that is constantly tied to one (input/output) */
536const dt_periph_io_t kDtPeriphIoConstantOne = {
537 .__internal = {
538 .type = kDtPeriphIoTypeMio,
539 .periph_input_or_direct_pad = 0,
540 .outsel_or_dt_pad = kDtPinmuxOutselConstantOne,
541 }
542};