1/*
2 * Copyright 2017, Data61
3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4 * ABN 41 687 119 230.
5 *
6 * This software may be distributed and modified according to the terms of
7 * the BSD 2-Clause license. Note that NO WARRANTY is provided.
8 * See "LICENSE_BSD2.txt" for details.
9 *
10 * @TAG(DATA61_BSD)
11 */
12
13/*
14 * Contains definitions for all character devices on this
15 * platform
16 */
17
18#include "../../chardev.h"
19#include "../../common.h"
20
21#include "ega.h"
22#include "keyboard_chardev.h"
23#include <utils/arith.h>
24
25static const int com1_irqs[] = {SERIAL_CONSOLE_COM1_IRQ, -1};
26static const int com2_irqs[] = {SERIAL_CONSOLE_COM2_IRQ, -1};
27static const int com3_irqs[] = {SERIAL_CONSOLE_COM3_IRQ, -1};
28static const int com4_irqs[] = {SERIAL_CONSOLE_COM4_IRQ, -1};
29
30static const int ega_irqs[] = { -1};
31
32#define PC99_SERIAL_DEFN(devid) {          \
33    .id      = PC99_SERIAL_COM##devid,    \
34    .paddr   = SERIAL_CONSOLE_COM##devid##_PORT, \
35    .size    = 0,             \
36    .irqs    = com##devid##_irqs,  \
37    .init_fn = &uart_init           \
38}
39
40#define PC99_TEXT_EGA_DEFN() {      \
41        .id = PC99_TEXT_EGA,        \
42        .paddr = EGA_TEXT_FB_BASE,  \
43        .size = BIT(12),            \
44        .irqs = ega_irqs,           \
45        .init_fn = text_ega_init    \
46    }
47
48static const int keyboard_irqs[] = {KEYBOARD_PS2_IRQ, -1};
49
50#define PC99_KEYBOARD_DEFN() {        \
51    .id      = PC99_KEYBOARD_PS2,     \
52    .paddr   = 0,                     \
53    .size    = 0,                     \
54    .irqs    = keyboard_irqs,         \
55    .init_fn = &keyboard_cdev_init    \
56}
57
58static const struct dev_defn dev_defn[] = {
59    PC99_SERIAL_DEFN(1),
60    PC99_SERIAL_DEFN(2),
61    PC99_SERIAL_DEFN(3),
62    PC99_SERIAL_DEFN(4),
63    PC99_TEXT_EGA_DEFN(),
64    PC99_KEYBOARD_DEFN()
65};
66
67struct ps_chardevice*
68ps_cdev_init(enum chardev_id id, const ps_io_ops_t* io_ops, struct ps_chardevice* dev) {
69    unsigned int i;
70    for (i = 0; i < ARRAY_SIZE(dev_defn); i++) {
71        if (dev_defn[i].id == id) {
72            return (dev_defn[i].init_fn(dev_defn + i, io_ops, dev)) ? NULL : dev;
73        }
74    }
75    return NULL;
76}
77