23 int serial_init(struct serial_if
*sif
)
25 uint16_t port
= sif
->port
;
26 uint8_t dll
, dlm
, lcr
;
29 outb(0x83, port
+ LCR
);
30 outb(0x01, port
+ DLL
);
31 outb(0x00, port
+ DLM
);
32 (void)inb(port
+ IER
); /* Synchronize */
33 dll
= inb(port
+ DLL
);
34 dlm
= inb(port
+ DLM
);
35 lcr
= inb(port
+ LCR
);
36 outb(0x03, port
+ LCR
);
37 (void)inb(port
+ IER
); /* Synchronize */
39 if (dll
!= 0x01 || dlm
!= 0x00 || lcr
!= 0x83)
40 return -1; /* This doesn't look like a serial port */
42 /* Disable interrupts */
45 /* Enable 16550A FIFOs if available */
46 outb(port
+ FCR
, 0x01); /* Enable FIFO */
47 (void)inb(port
+ IER
); /* Synchronize */
48 if (inb(port
+ IIR
) < 0xc0)
49 outb(port
+ FCR
, 0x00); /* Disable FIFOs if non-functional */
50 (void)inb(port
+ IER
); /* Synchronize */
55 void serial_write(struct serial_if
*sif
, const void *data
, size_t n
)
57 uint16_t port
= sif
->port
;
63 lsr
= inb(port
+ LSR
);
64 } while (!(lsr
& 0x20));
66 outb(*p
++, port
+ THR
);
70 void serial_read(struct serial_if
*sif
, void *data
, size_t n
)
72 uint16_t port
= sif
->port
;
78 lsr
= inb(port
+ LSR
);
79 } while (!(lsr
& 0x01));
81 *p
++ = inb(port
+ RBR
);