1/*
2 * Copyright 2020, DornerWorks
3 *
4 * This software may be distributed and modified according to the terms of
5 * the BSD 2-Clause license. Note that NO WARRANTY is provided.
6 * See "LICENSE_BSD2.txt" for details.
7 *
8 * @TAG(DORNERWORKS_BSD)
9 */
10
11/**
12 * Contains the definition for all character devices on this platform.
13 * Currently this is just a simple patch.
14 */
15
16#include "../../chardev.h"
17#include "../../common.h"
18#include <utils/util.h>
19
20
21static const int uart0_irqs[] = {UART0_IRQ, -1};
22static const int uart1_irqs[] = {UART1_IRQ, -1};
23static const int uart2_irqs[] = {UART2_IRQ, -1};
24static const int uart3_irqs[] = {UART3_IRQ, -1};
25
26#define UART_DEFN(devid) {          \
27    .id      = UART##devid,    \
28    .paddr   = UART##devid##_PADDR, \
29    .size    = BIT(12),             \
30    .irqs    = uart##devid##_irqs,  \
31    .init_fn = &uart_init           \
32}
33
34const struct dev_defn dev_defn[] = {
35    UART_DEFN(0),
36    UART_DEFN(1),
37    UART_DEFN(2),
38    UART_DEFN(3)
39};
40
41
42struct ps_chardevice *
43ps_cdev_init(enum chardev_id id, const ps_io_ops_t *o, struct ps_chardevice *d)
44{
45    unsigned int i;
46    for (i = 0; i < ARRAY_SIZE(dev_defn); i++) {
47        if (dev_defn[i].id == id) {
48            return (dev_defn[i].init_fn(dev_defn + i, o, d)) ? NULL : d;
49        }
50    }
51    return NULL;
52}
53