Software APIs
dt_usbdev.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 * @file
9 * @brief Device Tables (DT) for IP usbdev and top englishbreakfast.
10 */
11
12#include "dt/dt_usbdev.h"
13
14
15
16/**
17 * Description of instances.
18 */
19typedef struct dt_desc_usbdev {
20 dt_instance_id_t inst_id; /**< Instance ID */
21 uint32_t base_addr[kDtUsbdevRegBlockCount]; /**< Base address of each register block */
22 /**
23 * PLIC ID of the first IRQ of this instance
24 *
25 * This can be `kDtPlicIrqIdNone` if the block is not connected to the PLIC.
26 */
28 dt_clock_t clock[kDtUsbdevClockCount]; /**< Clock signal connected to each clock port */
29 dt_reset_t reset[kDtUsbdevResetCount]; /**< Reset signal connected to each reset port */
30 dt_periph_io_t periph_io[kDtUsbdevPeriphIoCount]; /**< Description of each peripheral I/O */
32
33
34
35
36static const dt_desc_usbdev_t usbdev_desc[kDtUsbdevCount] = {
37 [kDtUsbdev] = {
38 .inst_id = kDtInstanceIdUsbdev,
39 .base_addr = {
40 [kDtUsbdevRegBlockCore] = 0x40320000,
41 },
43 .clock = {
46 },
47 .reset = {
50 },
51 .periph_io = {
52 [kDtUsbdevPeriphIoSense] = {
53 .__internal = {
54 .type = kDtPeriphIoTypeMio,
55 .dir = kDtPeriphIoDirIn,
56 .periph_input_or_direct_pad = kTopEnglishbreakfastPinmuxPeripheralInUsbdevSense,
57 .outsel_or_dt_pad = 0,
58 },
59 },
60 [kDtUsbdevPeriphIoUsbDp] = {
61 .__internal = {
64 .periph_input_or_direct_pad = 0,
65 .outsel_or_dt_pad = 0,
66 },
67 },
68 [kDtUsbdevPeriphIoUsbDn] = {
69 .__internal = {
72 .periph_input_or_direct_pad = 0,
73 .outsel_or_dt_pad = 0,
74 },
75 },
76 },
77 },
78};
79
80/**
81 * Return a pointer to the `dt_usbdev_desc_t` structure of the requested
82 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
83 * the function) with the provided default value.
84 */
85#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_usbdev_t)0 || (dt) >= kDtUsbdevCount) return (default); &usbdev_desc[dt]; })
86
88 if (inst_id >= kDtInstanceIdUsbdev && inst_id <= kDtInstanceIdUsbdev) {
89 return (dt_usbdev_t)(inst_id - kDtInstanceIdUsbdev);
90 }
91 return (dt_usbdev_t)0;
92}
93
98
100 dt_usbdev_t dt,
101 dt_usbdev_reg_block_t reg_block) {
102 // Return a recognizable address in case of wrong argument.
103 return TRY_GET_DT(dt, 0xdeadbeef)->base_addr[reg_block];
104}
105
107 dt_usbdev_t dt,
108 dt_usbdev_irq_t irq) {
109 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, kDtPlicIrqIdNone)->first_irq;
110 if (first_irq == kDtPlicIrqIdNone) {
111 return kDtPlicIrqIdNone;
112 }
113 return (dt_plic_irq_id_t)((uint32_t)first_irq + (uint32_t)irq);
114}
115
117 dt_usbdev_t dt,
118 dt_plic_irq_id_t irq) {
119 dt_usbdev_irq_t count = kDtUsbdevIrqCount;
120 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, count)->first_irq;
121 if (first_irq == kDtPlicIrqIdNone) {
122 return count;
123 }
124 if (irq < first_irq || irq >= first_irq + (dt_plic_irq_id_t)count) {
125 return count;
126 }
127 return (dt_usbdev_irq_t)(irq - first_irq);
128}
129
130
131
133 dt_usbdev_t dt,
135 // Return a harmless value in case of wrong argument.
136 return TRY_GET_DT(dt, kDtPeriphIoConstantHighZ)->periph_io[sig];
137}
138
140 dt_usbdev_t dt,
141 dt_usbdev_clock_t clk) {
142 // Return the first clock in case of invalid argument.
143 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
144}
145
147 dt_usbdev_t dt,
148 dt_usbdev_reset_t rst) {
149 const dt_usbdev_reset_t count = kDtUsbdevResetCount;
150 if (rst >= count) {
151 return kDtResetUnknown;
152 }
153 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
154}
155
156