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 "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] = {
175 [kDtPadIoa0] = {
176 .type = kDtPadTypeMio,
177 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoa0,
179 },
180 [kDtPadIoa1] = {
181 .type = kDtPadTypeMio,
182 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoa1,
184 },
185 [kDtPadIoa2] = {
186 .type = kDtPadTypeMio,
187 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoa2,
189 },
190 [kDtPadIoa3] = {
191 .type = kDtPadTypeMio,
192 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoa3,
194 },
195 [kDtPadIoa4] = {
196 .type = kDtPadTypeMio,
197 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoa4,
199 },
200 [kDtPadIoa5] = {
201 .type = kDtPadTypeMio,
202 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoa5,
204 },
205 [kDtPadIoa6] = {
206 .type = kDtPadTypeMio,
207 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoa6,
209 },
210 [kDtPadIoa7] = {
211 .type = kDtPadTypeMio,
212 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoa7,
214 },
215 [kDtPadIoa8] = {
216 .type = kDtPadTypeMio,
217 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoa8,
219 },
220 [kDtPadIob0] = {
221 .type = kDtPadTypeMio,
222 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIob0,
224 },
225 [kDtPadIob1] = {
226 .type = kDtPadTypeMio,
227 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIob1,
229 },
230 [kDtPadIob2] = {
231 .type = kDtPadTypeMio,
232 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIob2,
234 },
235 [kDtPadIob3] = {
236 .type = kDtPadTypeMio,
237 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIob3,
239 },
240 [kDtPadIob4] = {
241 .type = kDtPadTypeMio,
242 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIob4,
244 },
245 [kDtPadIob5] = {
246 .type = kDtPadTypeMio,
247 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIob5,
249 },
250 [kDtPadIob6] = {
251 .type = kDtPadTypeMio,
252 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIob6,
254 },
255 [kDtPadIob7] = {
256 .type = kDtPadTypeMio,
257 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIob7,
259 },
260 [kDtPadIob8] = {
261 .type = kDtPadTypeMio,
262 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIob8,
264 },
265 [kDtPadIob9] = {
266 .type = kDtPadTypeMio,
267 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIob9,
269 },
270 [kDtPadIob10] = {
271 .type = kDtPadTypeMio,
272 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIob10,
274 },
275 [kDtPadIob11] = {
276 .type = kDtPadTypeMio,
277 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIob11,
279 },
280 [kDtPadIob12] = {
281 .type = kDtPadTypeMio,
282 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIob12,
284 },
285 [kDtPadIoc0] = {
286 .type = kDtPadTypeMio,
287 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoc0,
289 },
290 [kDtPadIoc1] = {
291 .type = kDtPadTypeMio,
292 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoc1,
294 },
295 [kDtPadIoc2] = {
296 .type = kDtPadTypeMio,
297 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoc2,
299 },
300 [kDtPadIoc3] = {
301 .type = kDtPadTypeMio,
302 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoc3,
304 },
305 [kDtPadIoc4] = {
306 .type = kDtPadTypeMio,
307 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoc4,
309 },
310 [kDtPadIoc5] = {
311 .type = kDtPadTypeMio,
312 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoc5,
314 },
315 [kDtPadIoc6] = {
316 .type = kDtPadTypeMio,
317 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoc6,
319 },
320 [kDtPadIoc7] = {
321 .type = kDtPadTypeMio,
322 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoc7,
324 },
325 [kDtPadIoc8] = {
326 .type = kDtPadTypeMio,
327 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoc8,
329 },
330 [kDtPadIoc9] = {
331 .type = kDtPadTypeMio,
332 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoc9,
334 },
335 [kDtPadIoc10] = {
336 .type = kDtPadTypeMio,
337 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoc10,
339 },
340 [kDtPadIoc11] = {
341 .type = kDtPadTypeMio,
342 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoc11,
344 },
345 [kDtPadIoc12] = {
346 .type = kDtPadTypeMio,
347 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIoc12,
349 },
350 [kDtPadIor0] = {
351 .type = kDtPadTypeMio,
352 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIor0,
354 },
355 [kDtPadIor1] = {
356 .type = kDtPadTypeMio,
357 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIor1,
359 },
360 [kDtPadIor2] = {
361 .type = kDtPadTypeMio,
362 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIor2,
364 },
365 [kDtPadIor3] = {
366 .type = kDtPadTypeMio,
367 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIor3,
369 },
370 [kDtPadIor4] = {
371 .type = kDtPadTypeMio,
372 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIor4,
374 },
375 [kDtPadIor5] = {
376 .type = kDtPadTypeMio,
377 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIor5,
379 },
380 [kDtPadIor6] = {
381 .type = kDtPadTypeMio,
382 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIor6,
384 },
385 [kDtPadIor7] = {
386 .type = kDtPadTypeMio,
387 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIor7,
389 },
390 [kDtPadIor10] = {
391 .type = kDtPadTypeMio,
392 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIor10,
394 },
395 [kDtPadIor11] = {
396 .type = kDtPadTypeMio,
397 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIor11,
399 },
400 [kDtPadIor12] = {
401 .type = kDtPadTypeMio,
402 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIor12,
404 },
405 [kDtPadIor13] = {
406 .type = kDtPadTypeMio,
407 .mio_out_or_direct_pad = kTopEnglishbreakfastPinmuxMioOutIor13,
409 },
411 .type = kDtPadTypeDio,
412 .mio_out_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiHost0Sd0,
413 .insel = 0,
414 },
416 .type = kDtPadTypeDio,
417 .mio_out_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiHost0Sd1,
418 .insel = 0,
419 },
421 .type = kDtPadTypeDio,
422 .mio_out_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiHost0Sd2,
423 .insel = 0,
424 },
426 .type = kDtPadTypeDio,
427 .mio_out_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiHost0Sd3,
428 .insel = 0,
429 },
431 .type = kDtPadTypeDio,
432 .mio_out_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiDeviceSd0,
433 .insel = 0,
434 },
436 .type = kDtPadTypeDio,
437 .mio_out_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiDeviceSd1,
438 .insel = 0,
439 },
441 .type = kDtPadTypeDio,
442 .mio_out_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiDeviceSd2,
443 .insel = 0,
444 },
446 .type = kDtPadTypeDio,
447 .mio_out_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiDeviceSd3,
448 .insel = 0,
449 },
450 [kDtPadUsbdevUsbDp] = {
451 .type = kDtPadTypeDio,
452 .mio_out_or_direct_pad = kTopEnglishbreakfastDirectPadsUsbdevUsbDp,
453 .insel = 0,
454 },
455 [kDtPadUsbdevUsbDn] = {
456 .type = kDtPadTypeDio,
457 .mio_out_or_direct_pad = kTopEnglishbreakfastDirectPadsUsbdevUsbDn,
458 .insel = 0,
459 },
461 .type = kDtPadTypeDio,
462 .mio_out_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiDeviceSck,
463 .insel = 0,
464 },
466 .type = kDtPadTypeDio,
467 .mio_out_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiDeviceCsb,
468 .insel = 0,
469 },
471 .type = kDtPadTypeDio,
472 .mio_out_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiHost0Sck,
473 .insel = 0,
474 },
476 .type = kDtPadTypeDio,
477 .mio_out_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiHost0Csb,
478 .insel = 0,
479 },
480};
481
482
483
484#define TRY_GET_PAD(pad, default) ({ if ((pad) < (dt_pad_t)0 || (pad) >= kDtPadCount) return (default); &dt_pad[pad]; })
485
487 return TRY_GET_PAD(pad, kDtPadTypeUnspecified)->type;
488}
489
490dt_pinmux_mio_out_t dt_pad_mio_out(dt_pad_t pad) {
491 return (dt_pinmux_mio_out_t)TRY_GET_PAD(pad, 0)->mio_out_or_direct_pad;
492}
493
494dt_pinmux_muxed_pad_t dt_pad_mio_pad_index(dt_pad_t pad) {
495 // Same index as MIO_OUT.
496 return (dt_pinmux_muxed_pad_t)dt_pad_mio_out(pad);
497}
498
499dt_pinmux_insel_t dt_pad_mio_insel(dt_pad_t pad) {
500 return (dt_pinmux_insel_t)TRY_GET_PAD(pad, 0)->insel;
501}
502
503dt_pinmux_direct_pad_t dt_pad_dio_pad_index(dt_pad_t pad) {
504 return (dt_pinmux_direct_pad_t)TRY_GET_PAD(pad, 0)->mio_out_or_direct_pad;
505}
506
507/* Pin that is constantly tied to high-Z (input only) */
508const dt_periph_io_t kDtPeriphIoConstantHighZ = {
509 .__internal = {
510 .type = kDtPeriphIoTypeMio,
511 .periph_input_or_direct_pad = 0,
512 .outsel_or_dt_pad = kDtPinmuxOutselConstantHighZ,
513 }
514};
515
516/* Pin that is constantly tied to zero (input/output) */
517const dt_periph_io_t kDtPeriphIoConstantZero = {
518 .__internal = {
519 .type = kDtPeriphIoTypeMio,
520 .periph_input_or_direct_pad = 0,
521 .outsel_or_dt_pad = kDtPinmuxOutselConstantZero,
522 }
523};
524
525/* Pin that is constantly tied to one (input/output) */
526const dt_periph_io_t kDtPeriphIoConstantOne = {
527 .__internal = {
528 .type = kDtPeriphIoTypeMio,
529 .periph_input_or_direct_pad = 0,
530 .outsel_or_dt_pad = kDtPinmuxOutselConstantOne,
531 }
532};