20 int serial_init(struct serial_if
*sif
)
22 uint16_t port
= sif
->port
;
23 uint8_t dll
, dlm
, lcr
;
29 (void)inb(port
+IER
); /* Synchronize */
34 (void)inb(port
+IER
); /* Synchronize */
36 if (dll
!= 0x01 || dlm
!= 0x00 || lcr
!= 0x83)
37 return -1; /* This doesn't look like a serial port */
39 /* Disable interrupts */
42 /* Enable 16550A FIFOs if available */
43 outb(port
+FCR
, 0x01); /* Enable FIFO */
44 (void)inb(port
+IER
); /* Synchronize */
45 if (inb(port
+IIR
) < 0xc0)
46 outb(port
+FCR
, 0x00); /* Disable FIFOs if non-functional */
47 (void)inb(port
+IER
); /* Synchronize */
52 void serial_write(struct serial_if
*sif
, const void *data
, size_t n
)
54 uint16_t port
= sif
->port
;
61 } while (!(lsr
& 0x20));
67 void serial_read(struct serial_if
*sif
, void *data
, size_t n
)
69 uint16_t port
= sif
->port
;
76 } while (!(lsr
& 0x01));