Software APIs
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 darjeeling
11 */
12
13#include "hw/top/dt/api.h"
15#include <stdint.h>
16
17
18enum {
19 kTopDarjeelingPlicIrqIdCount = kTopDarjeelingPlicIrqIdLast + 1,
20};
21
22static const dt_instance_id_t instance_from_irq[kTopDarjeelingPlicIrqIdCount] = {
155};
156
158 if (irq <= kTopDarjeelingPlicIrqIdLast) {
159 return instance_from_irq[irq];
160 }
162}
163
164
165enum {
166 kTopDarjeelingAlertIdCount = kTopDarjeelingAlertIdLast + 1,
167};
168
169static const dt_instance_id_t instance_from_alert[kTopDarjeelingAlertIdCount] = {
247};
248
250 if (alert <= kTopDarjeelingAlertIdLast) {
251 return instance_from_alert[alert];
252 }
254}
255
305};
306
308 if ((int)dev < kDtInstanceIdCount) {
309 return device_type[dev];
310 }
312}
313
314/**
315 * Pad description.
316 *
317 * A `dt_pad_t` represents a chip's physical pad.
318 */
319typedef struct dt_pad_desc {
320 dt_pad_type_t type; /**< Pad type */
321 /**
322 * For `kDtPadTypeMio` pads: MIO out number. This is the index of the MIO_OUTSEL register
323 * that controls this pad (or the output part of this pad).
324 *
325 * For `kDtPadTypeDio`: DIO pad number. This is the index of the various DIO_PAD_* registers
326 * that control this pad.
327 */
328 uint16_t mio_out_or_direct_pad;
329 /**
330 * For `kDtPadTypeMio` pads: MIO pad number. This is the value to put in the MIO_PERIPH_INSEL
331 * registers to connect a peripheral to this pad.
332 */
333 uint16_t insel;
335
336
337
338// Pad descriptions.
339static const dt_pad_desc_t dt_pad[kDtPadCount] = {
341 .type = kDtPadTypeMio,
342 .mio_out_or_direct_pad = 0,
344 },
346 .type = kDtPadTypeMio,
347 .mio_out_or_direct_pad = 0,
349 },
350 [kDtPadMio0] = {
351 .type = kDtPadTypeMio,
352 .mio_out_or_direct_pad = kTopDarjeelingPinmuxMioOutMio0,
354 },
355 [kDtPadMio1] = {
356 .type = kDtPadTypeMio,
357 .mio_out_or_direct_pad = kTopDarjeelingPinmuxMioOutMio1,
359 },
360 [kDtPadMio2] = {
361 .type = kDtPadTypeMio,
362 .mio_out_or_direct_pad = kTopDarjeelingPinmuxMioOutMio2,
364 },
365 [kDtPadMio3] = {
366 .type = kDtPadTypeMio,
367 .mio_out_or_direct_pad = kTopDarjeelingPinmuxMioOutMio3,
369 },
370 [kDtPadMio4] = {
371 .type = kDtPadTypeMio,
372 .mio_out_or_direct_pad = kTopDarjeelingPinmuxMioOutMio4,
374 },
375 [kDtPadMio5] = {
376 .type = kDtPadTypeMio,
377 .mio_out_or_direct_pad = kTopDarjeelingPinmuxMioOutMio5,
379 },
380 [kDtPadMio6] = {
381 .type = kDtPadTypeMio,
382 .mio_out_or_direct_pad = kTopDarjeelingPinmuxMioOutMio6,
384 },
385 [kDtPadMio7] = {
386 .type = kDtPadTypeMio,
387 .mio_out_or_direct_pad = kTopDarjeelingPinmuxMioOutMio7,
389 },
390 [kDtPadMio8] = {
391 .type = kDtPadTypeMio,
392 .mio_out_or_direct_pad = kTopDarjeelingPinmuxMioOutMio8,
394 },
395 [kDtPadMio9] = {
396 .type = kDtPadTypeMio,
397 .mio_out_or_direct_pad = kTopDarjeelingPinmuxMioOutMio9,
399 },
400 [kDtPadMio10] = {
401 .type = kDtPadTypeMio,
402 .mio_out_or_direct_pad = kTopDarjeelingPinmuxMioOutMio10,
404 },
405 [kDtPadMio11] = {
406 .type = kDtPadTypeMio,
407 .mio_out_or_direct_pad = kTopDarjeelingPinmuxMioOutMio11,
409 },
411 .type = kDtPadTypeDio,
412 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSpiHost0Sd0,
413 .insel = 0,
414 },
416 .type = kDtPadTypeDio,
417 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSpiHost0Sd1,
418 .insel = 0,
419 },
421 .type = kDtPadTypeDio,
422 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSpiHost0Sd2,
423 .insel = 0,
424 },
426 .type = kDtPadTypeDio,
427 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSpiHost0Sd3,
428 .insel = 0,
429 },
431 .type = kDtPadTypeDio,
432 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSpiDeviceSd0,
433 .insel = 0,
434 },
436 .type = kDtPadTypeDio,
437 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSpiDeviceSd1,
438 .insel = 0,
439 },
441 .type = kDtPadTypeDio,
442 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSpiDeviceSd2,
443 .insel = 0,
444 },
446 .type = kDtPadTypeDio,
447 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSpiDeviceSd3,
448 .insel = 0,
449 },
450 [kDtPadI2c0Scl] = {
451 .type = kDtPadTypeDio,
452 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsI2c0Scl,
453 .insel = 0,
454 },
455 [kDtPadI2c0Sda] = {
456 .type = kDtPadTypeDio,
457 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsI2c0Sda,
458 .insel = 0,
459 },
460 [kDtPadGpio0Gpio0] = {
461 .type = kDtPadTypeDio,
462 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsGpio0Gpio0,
463 .insel = 0,
464 },
465 [kDtPadGpio0Gpio1] = {
466 .type = kDtPadTypeDio,
467 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsGpio0Gpio1,
468 .insel = 0,
469 },
470 [kDtPadGpio0Gpio2] = {
471 .type = kDtPadTypeDio,
472 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsGpio0Gpio2,
473 .insel = 0,
474 },
475 [kDtPadGpio0Gpio3] = {
476 .type = kDtPadTypeDio,
477 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsGpio0Gpio3,
478 .insel = 0,
479 },
480 [kDtPadGpio0Gpio4] = {
481 .type = kDtPadTypeDio,
482 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsGpio0Gpio4,
483 .insel = 0,
484 },
485 [kDtPadGpio0Gpio5] = {
486 .type = kDtPadTypeDio,
487 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsGpio0Gpio5,
488 .insel = 0,
489 },
490 [kDtPadGpio0Gpio6] = {
491 .type = kDtPadTypeDio,
492 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsGpio0Gpio6,
493 .insel = 0,
494 },
495 [kDtPadGpio0Gpio7] = {
496 .type = kDtPadTypeDio,
497 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsGpio0Gpio7,
498 .insel = 0,
499 },
500 [kDtPadGpio0Gpio8] = {
501 .type = kDtPadTypeDio,
502 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsGpio0Gpio8,
503 .insel = 0,
504 },
505 [kDtPadGpio0Gpio9] = {
506 .type = kDtPadTypeDio,
507 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsGpio0Gpio9,
508 .insel = 0,
509 },
511 .type = kDtPadTypeDio,
512 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsGpio0Gpio10,
513 .insel = 0,
514 },
516 .type = kDtPadTypeDio,
517 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsGpio0Gpio11,
518 .insel = 0,
519 },
521 .type = kDtPadTypeDio,
522 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsGpio0Gpio12,
523 .insel = 0,
524 },
526 .type = kDtPadTypeDio,
527 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsGpio0Gpio13,
528 .insel = 0,
529 },
531 .type = kDtPadTypeDio,
532 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsGpio0Gpio14,
533 .insel = 0,
534 },
536 .type = kDtPadTypeDio,
537 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsGpio0Gpio15,
538 .insel = 0,
539 },
541 .type = kDtPadTypeDio,
542 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsGpio0Gpio16,
543 .insel = 0,
544 },
546 .type = kDtPadTypeDio,
547 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsGpio0Gpio17,
548 .insel = 0,
549 },
551 .type = kDtPadTypeDio,
552 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsGpio0Gpio18,
553 .insel = 0,
554 },
556 .type = kDtPadTypeDio,
557 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsGpio0Gpio19,
558 .insel = 0,
559 },
561 .type = kDtPadTypeDio,
562 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsGpio0Gpio20,
563 .insel = 0,
564 },
566 .type = kDtPadTypeDio,
567 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsGpio0Gpio21,
568 .insel = 0,
569 },
571 .type = kDtPadTypeDio,
572 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsGpio0Gpio22,
573 .insel = 0,
574 },
576 .type = kDtPadTypeDio,
577 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsGpio0Gpio23,
578 .insel = 0,
579 },
581 .type = kDtPadTypeDio,
582 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsGpio0Gpio24,
583 .insel = 0,
584 },
586 .type = kDtPadTypeDio,
587 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsGpio0Gpio25,
588 .insel = 0,
589 },
591 .type = kDtPadTypeDio,
592 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsGpio0Gpio26,
593 .insel = 0,
594 },
596 .type = kDtPadTypeDio,
597 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsGpio0Gpio27,
598 .insel = 0,
599 },
601 .type = kDtPadTypeDio,
602 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsGpio0Gpio28,
603 .insel = 0,
604 },
606 .type = kDtPadTypeDio,
607 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsGpio0Gpio29,
608 .insel = 0,
609 },
611 .type = kDtPadTypeDio,
612 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsGpio0Gpio30,
613 .insel = 0,
614 },
616 .type = kDtPadTypeDio,
617 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsGpio0Gpio31,
618 .insel = 0,
619 },
621 .type = kDtPadTypeDio,
622 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSpiDeviceSck,
623 .insel = 0,
624 },
626 .type = kDtPadTypeDio,
627 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSpiDeviceCsb,
628 .insel = 0,
629 },
631 .type = kDtPadTypeDio,
632 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSpiDeviceTpmCsb,
633 .insel = 0,
634 },
635 [kDtPadUart0Rx] = {
636 .type = kDtPadTypeDio,
637 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsUart0Rx,
638 .insel = 0,
639 },
641 .type = kDtPadTypeDio,
642 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSocProxySocGpi0,
643 .insel = 0,
644 },
646 .type = kDtPadTypeDio,
647 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSocProxySocGpi1,
648 .insel = 0,
649 },
651 .type = kDtPadTypeDio,
652 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSocProxySocGpi2,
653 .insel = 0,
654 },
656 .type = kDtPadTypeDio,
657 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSocProxySocGpi3,
658 .insel = 0,
659 },
661 .type = kDtPadTypeDio,
662 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSocProxySocGpi4,
663 .insel = 0,
664 },
666 .type = kDtPadTypeDio,
667 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSocProxySocGpi5,
668 .insel = 0,
669 },
671 .type = kDtPadTypeDio,
672 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSocProxySocGpi6,
673 .insel = 0,
674 },
676 .type = kDtPadTypeDio,
677 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSocProxySocGpi7,
678 .insel = 0,
679 },
681 .type = kDtPadTypeDio,
682 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSocProxySocGpi8,
683 .insel = 0,
684 },
686 .type = kDtPadTypeDio,
687 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSocProxySocGpi9,
688 .insel = 0,
689 },
691 .type = kDtPadTypeDio,
692 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSocProxySocGpi10,
693 .insel = 0,
694 },
696 .type = kDtPadTypeDio,
697 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSocProxySocGpi11,
698 .insel = 0,
699 },
701 .type = kDtPadTypeDio,
702 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSpiHost0Sck,
703 .insel = 0,
704 },
706 .type = kDtPadTypeDio,
707 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSpiHost0Csb,
708 .insel = 0,
709 },
710 [kDtPadUart0Tx] = {
711 .type = kDtPadTypeDio,
712 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsUart0Tx,
713 .insel = 0,
714 },
716 .type = kDtPadTypeDio,
717 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSocProxySocGpo0,
718 .insel = 0,
719 },
721 .type = kDtPadTypeDio,
722 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSocProxySocGpo1,
723 .insel = 0,
724 },
726 .type = kDtPadTypeDio,
727 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSocProxySocGpo2,
728 .insel = 0,
729 },
731 .type = kDtPadTypeDio,
732 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSocProxySocGpo3,
733 .insel = 0,
734 },
736 .type = kDtPadTypeDio,
737 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSocProxySocGpo4,
738 .insel = 0,
739 },
741 .type = kDtPadTypeDio,
742 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSocProxySocGpo5,
743 .insel = 0,
744 },
746 .type = kDtPadTypeDio,
747 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSocProxySocGpo6,
748 .insel = 0,
749 },
751 .type = kDtPadTypeDio,
752 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSocProxySocGpo7,
753 .insel = 0,
754 },
756 .type = kDtPadTypeDio,
757 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSocProxySocGpo8,
758 .insel = 0,
759 },
761 .type = kDtPadTypeDio,
762 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSocProxySocGpo9,
763 .insel = 0,
764 },
766 .type = kDtPadTypeDio,
767 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSocProxySocGpo10,
768 .insel = 0,
769 },
771 .type = kDtPadTypeDio,
772 .mio_out_or_direct_pad = kTopDarjeelingDirectPadsSocProxySocGpo11,
773 .insel = 0,
774 },
775};
776
777
778
779#define TRY_GET_PAD(pad, default) ({ if ((pad) < (dt_pad_t)0 || (int)(pad) >= kDtPadCount) return (default); &dt_pad[pad]; })
780
782 return TRY_GET_PAD(pad, kDtPadTypeUnspecified)->type;
783}
784
785dt_pinmux_mio_out_t dt_pad_mio_out(dt_pad_t pad) {
786 return (dt_pinmux_mio_out_t)TRY_GET_PAD(pad, 0)->mio_out_or_direct_pad;
787}
788
789dt_pinmux_muxed_pad_t dt_pad_mio_pad_index(dt_pad_t pad) {
790 // Same index as MIO_OUT.
791 return (dt_pinmux_muxed_pad_t)dt_pad_mio_out(pad);
792}
793
794dt_pinmux_insel_t dt_pad_mio_insel(dt_pad_t pad) {
795 return (dt_pinmux_insel_t)TRY_GET_PAD(pad, 0)->insel;
796}
797
798dt_pinmux_direct_pad_t dt_pad_dio_pad_index(dt_pad_t pad) {
799 return (dt_pinmux_direct_pad_t)TRY_GET_PAD(pad, 0)->mio_out_or_direct_pad;
800}
801
802/* Pin that is constantly tied to high-Z (input only) */
803const dt_periph_io_t kDtPeriphIoConstantHighZ = {
804 .__internal = {
805 .type = kDtPeriphIoTypeMio,
806 .periph_input_or_direct_pad = 0,
807 .outsel_or_dt_pad = kDtPinmuxOutselConstantHighZ,
808 }
809};
810
811/* Pin that is constantly tied to zero (input/output) */
812const dt_periph_io_t kDtPeriphIoConstantZero = {
813 .__internal = {
814 .type = kDtPeriphIoTypeMio,
815 .periph_input_or_direct_pad = 0,
816 .outsel_or_dt_pad = kDtPinmuxOutselConstantZero,
817 }
818};
819
820/* Pin that is constantly tied to one (input/output) */
821const dt_periph_io_t kDtPeriphIoConstantOne = {
822 .__internal = {
823 .type = kDtPeriphIoTypeMio,
824 .periph_input_or_direct_pad = 0,
825 .outsel_or_dt_pad = kDtPinmuxOutselConstantOne,
826 }
827};