Changes in kernel/genarch/src/drivers/ns16550/ns16550.c [24abb85d:448e093] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/genarch/src/drivers/ns16550/ns16550.c
r24abb85d r448e093 1 1 /* 2 2 * Copyright (c) 2009 Jakub Jermar 3 * Copyright (c) 2018 CZ.NIC, z.s.p.o. 3 4 * All rights reserved. 4 5 * … … 46 47 #define LSR_TH_READY 0x20 47 48 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 48 60 static irq_ownership_t ns16550_claim(irq_t *irq) 49 61 { 50 62 ns16550_instance_t *instance = irq->instance; 51 ns16550_t *dev = instance->ns16550; 52 53 if (pio_read_8(&dev->lsr) & LSR_DATA_READY) 63 64 if (ns16550_reg_read(instance, NS16550_REG_LSR) & LSR_DATA_READY) 54 65 return IRQ_ACCEPT; 55 66 else … … 60 71 { 61 72 ns16550_instance_t *instance = irq->instance; 62 ns16550_t *dev = instance->ns16550;63 73 64 if (pio_read_8(&dev->lsr) & LSR_DATA_READY) {65 uint8_t data = pio_read_8(&dev->rbr);74 while (ns16550_reg_read(instance, NS16550_REG_LSR) & LSR_DATA_READY) { 75 uint8_t data = ns16550_reg_read(instance, NS16550_REG_RBR); 66 76 indev_push_character(instance->input, data); 67 77 } … … 69 79 70 80 /**< Clear input buffer. */ 71 static void ns16550_clear_buffer(ns16550_ t *dev)81 static void ns16550_clear_buffer(ns16550_instance_t *instance) 72 82 { 73 while ( (pio_read_8(&dev->lsr) & LSR_DATA_READY))74 (void) pio_read_8(&dev->rbr);83 while (ns16550_reg_read(instance, NS16550_REG_LSR) & LSR_DATA_READY) 84 (void) ns16550_reg_read(instance, NS16550_REG_RBR); 75 85 } 76 86 77 static void ns16550_sendb(ns16550_ t *dev, uint8_t byte)87 static void ns16550_sendb(ns16550_instance_t *instance, uint8_t byte) 78 88 { 79 while (!( pio_read_8(&dev->lsr) & LSR_TH_READY))89 while (!(ns16550_reg_read(instance, NS16550_REG_LSR) & LSR_TH_READY)) 80 90 ; 81 pio_write_8(&dev->thr, byte);91 ns16550_reg_write(instance, NS16550_REG_THR, byte); 82 92 } 83 93 … … 88 98 if ((!instance->parea.mapped) || (console_override)) { 89 99 if (ascii_check(ch)) 90 ns16550_sendb(instance ->ns16550, (uint8_t) ch);100 ns16550_sendb(instance, (uint8_t) ch); 91 101 else 92 ns16550_sendb(instance ->ns16550, U_SPECIAL);102 ns16550_sendb(instance, U_SPECIAL); 93 103 } 94 104 } … … 101 111 /** Initialize ns16550. 102 112 * 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. 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. 110 123 * 111 124 * @return Keyboard instance or NULL on failure. 112 125 * 113 126 */ 114 ns16550_instance_t *ns16550_init( ns16550_t *dev, inr_t inr, cir_t cir,115 void *cir_arg, outdev_t **output)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) 116 129 { 117 130 ns16550_instance_t *instance … … 119 132 if (instance) { 120 133 instance->ns16550 = dev; 134 instance->reg_shift = reg_shift; 121 135 instance->input = NULL; 122 136 instance->output = NULL; … … 162 176 irq_register(&instance->irq); 163 177 164 ns16550_clear_buffer(instance ->ns16550);178 ns16550_clear_buffer(instance); 165 179 166 180 /* Enable interrupts */ 167 pio_write_8(&instance->ns16550->ier, IER_ERBFI);168 pio_write_8(&instance->ns16550->mcr, MCR_OUT2);181 ns16550_reg_write(instance, NS16550_REG_IER, IER_ERBFI); 182 ns16550_reg_write(instance, NS16550_REG_MCR, MCR_OUT2); 169 183 } 170 184
Note:
See TracChangeset
for help on using the changeset viewer.