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#pragma once 14 15#include <platsupport/chardev.h> 16#include <utils/arith.h> 17 18struct dev_defn { 19 enum chardev_id id; 20 uintptr_t paddr; 21 int size; 22 const int *irqs; 23 int (*init_fn)(const struct dev_defn *defn, 24 const ps_io_ops_t *ops, 25 struct ps_chardevice *dev); 26}; 27 28static inline void *chardev_map( 29 const struct dev_defn *dev, 30 const ps_io_ops_t *ops) 31{ 32 return ps_io_map( 33 &ops->io_mapper, 34 dev->paddr, 35 dev->size, 36 0, // map uncached 37 PS_MEM_NORMAL); 38} 39 40int uart_init( 41 const struct dev_defn *defn, 42 const ps_io_ops_t *ops, 43 ps_chardevice_t *dev); 44 45int uart_static_init( 46 void *vaddr, 47 const ps_io_ops_t *ops, 48 ps_chardevice_t *dev); 49 50ssize_t uart_write( 51 ps_chardevice_t *dev, 52 const void *vdata, 53 size_t count, 54 chardev_callback_t rcb UNUSED, 55 void *token UNUSED); 56 57ssize_t uart_read( 58 ps_chardevice_t *dev, 59 void *vdata, 60 size_t count, 61 chardev_callback_t rcb UNUSED, 62 void *token UNUSED); 63 64int uart_getchar( 65 ps_chardevice_t *dev); 66 67int uart_putchar( 68 ps_chardevice_t *dev, 69 int c); 70 71