Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/genarch/src/drivers/ns16550/ns16550.c

    r448e093 r24abb85d  
    11/*
    22 * Copyright (c) 2009 Jakub Jermar
    3  * Copyright (c) 2018 CZ.NIC, z.s.p.o.
    43 * All rights reserved.
    54 *
     
    4746#define LSR_TH_READY    0x20
    4847
    49 static uint8_t ns16550_reg_read(ns16550_instance_t *inst, ns16550_reg_t reg)
    50 {
    51         return pio_read_8(&inst->ns16550[reg << inst->reg_shift]);
    52 }
    53 
    54 static void ns16550_reg_write(ns16550_instance_t *inst, ns16550_reg_t reg,
    55     uint8_t val)
    56 {
    57         pio_write_8(&inst->ns16550[reg << inst->reg_shift], val);
    58 }
    59 
    6048static irq_ownership_t ns16550_claim(irq_t *irq)
    6149{
    6250        ns16550_instance_t *instance = irq->instance;
    63 
    64         if (ns16550_reg_read(instance, NS16550_REG_LSR) & LSR_DATA_READY)
     51        ns16550_t *dev = instance->ns16550;
     52       
     53        if (pio_read_8(&dev->lsr) & LSR_DATA_READY)
    6554                return IRQ_ACCEPT;
    6655        else
     
    7160{
    7261        ns16550_instance_t *instance = irq->instance;
     62        ns16550_t *dev = instance->ns16550;
    7363       
    74         while (ns16550_reg_read(instance, NS16550_REG_LSR) & LSR_DATA_READY) {
    75                 uint8_t data = ns16550_reg_read(instance, NS16550_REG_RBR);
     64        if (pio_read_8(&dev->lsr) & LSR_DATA_READY) {
     65                uint8_t data = pio_read_8(&dev->rbr);
    7666                indev_push_character(instance->input, data);
    7767        }
     
    7969
    8070/**< Clear input buffer. */
    81 static void ns16550_clear_buffer(ns16550_instance_t *instance)
     71static void ns16550_clear_buffer(ns16550_t *dev)
    8272{
    83         while (ns16550_reg_read(instance, NS16550_REG_LSR) & LSR_DATA_READY)
    84                 (void) ns16550_reg_read(instance, NS16550_REG_RBR);
     73        while ((pio_read_8(&dev->lsr) & LSR_DATA_READY))
     74                (void) pio_read_8(&dev->rbr);
    8575}
    8676
    87 static void ns16550_sendb(ns16550_instance_t *instance, uint8_t byte)
     77static void ns16550_sendb(ns16550_t *dev, uint8_t byte)
    8878{
    89         while (!(ns16550_reg_read(instance, NS16550_REG_LSR) & LSR_TH_READY))
     79        while (!(pio_read_8(&dev->lsr) & LSR_TH_READY))
    9080                ;
    91         ns16550_reg_write(instance, NS16550_REG_THR, byte);
     81        pio_write_8(&dev->thr, byte);
    9282}
    9383
     
    9888        if ((!instance->parea.mapped) || (console_override)) {
    9989                if (ascii_check(ch))
    100                         ns16550_sendb(instance, (uint8_t) ch);
     90                        ns16550_sendb(instance->ns16550, (uint8_t) ch);
    10191                else
    102                         ns16550_sendb(instance, U_SPECIAL);
     92                        ns16550_sendb(instance->ns16550, U_SPECIAL);
    10393        }
    10494}
     
    111101/** Initialize ns16550.
    112102 *
    113  * @param dev        Address of the beginning of the device in I/O space.
    114  * @param reg_shift  Spacing between individual register addresses, in log2.
    115  *                   The individual register location is calculated as
    116  *                   `base + (register offset << reg_shift)`.
    117  * @param inr        Interrupt number.
    118  * @param cir        Clear interrupt function.
    119  * @param cir_arg    First argument to cir.
    120  * @param output     Where to store pointer to the output device
    121  *                   or NULL if the caller is not interested in
    122  *                   writing to the serial port.
     103 * @param dev      Addrress of the beginning of the device in I/O space.
     104 * @param inr      Interrupt number.
     105 * @param cir      Clear interrupt function.
     106 * @param cir_arg  First argument to cir.
     107 * @param output   Where to store pointer to the output device
     108 *                 or NULL if the caller is not interested in
     109 *                 writing to the serial port.
    123110 *
    124111 * @return Keyboard instance or NULL on failure.
    125112 *
    126113 */
    127 ns16550_instance_t *ns16550_init(ioport8_t *dev, unsigned reg_shift, inr_t inr,
    128     cir_t cir, void *cir_arg, outdev_t **output)
     114ns16550_instance_t *ns16550_init(ns16550_t *dev, inr_t inr, cir_t cir,
     115    void *cir_arg, outdev_t **output)
    129116{
    130117        ns16550_instance_t *instance
     
    132119        if (instance) {
    133120                instance->ns16550 = dev;
    134                 instance->reg_shift = reg_shift;
    135121                instance->input = NULL;
    136122                instance->output = NULL;
     
    176162        irq_register(&instance->irq);
    177163       
    178         ns16550_clear_buffer(instance);
     164        ns16550_clear_buffer(instance->ns16550);
    179165       
    180166        /* Enable interrupts */
    181         ns16550_reg_write(instance, NS16550_REG_IER, IER_ERBFI);
    182         ns16550_reg_write(instance, NS16550_REG_MCR, MCR_OUT2);
     167        pio_write_8(&instance->ns16550->ier, IER_ERBFI);
     168        pio_write_8(&instance->ns16550->mcr, MCR_OUT2);
    183169}
    184170
Note: See TracChangeset for help on using the changeset viewer.