]> Joshua Wise's Git repositories - netwatch.git/blame - lib/serial.c
Add support for the power button SMI.
[netwatch.git] / lib / serial.c
CommitLineData
3c4e084d
JP
1/* serial.c
2 * Serial output routines.
3 * NetWatch system management mode administration console
4 *
5 * Copyright (c) 2008 Jacob Potter and Joshua Wise. All rights reserved.
6 * This program is free software; you can redistribute and/or modify it under
7 * the terms found in the file LICENSE in the root of this source tree.
8 *
9 */
10
e931b1fe
JW
11#include <minilib.h>
12#include <io.h>
13
14#define SER_BASE 0x3F8
15#define SER_THR 0x0
16#define SER_RBR 0x0
17#define SER_DLL 0x0
18#define SER_IER 0x1
19#define SER_DLM 0x1
20#define SER_IIR 0x2
21#define SER_FCR 0x2
22#define SER_LCR 0x3
23#define SER_LCR_DLAB 0x80
24#define SER_MCR 0x4
25#define SER_LSR 0x5
26#define SER_LSR_THR_EMPTY 0x20
27#define SER_MSR 0x6
28#define SER_SR 0x7
29
30#define SER_BAUD_BASE 115200
31#define SER_BAUD_REQ 115200
32
33void _outb(unsigned short port, unsigned char d)
34{
35 outb(SER_BASE + port, d);
36}
37
38unsigned char _inb(unsigned short port)
39{
40 return inb(SER_BASE + port);
41}
42
43void serial_init()
44{
45 unsigned short baud = SER_BAUD_REQ / SER_BAUD_BASE;
c07c6eba 46 _outb(SER_LCR, _inb(SER_LCR) | SER_LCR_DLAB);
e931b1fe
JW
47 _outb(SER_DLL, baud & 0xFF);
48 _outb(SER_DLM, baud >> 8);
c07c6eba 49 _outb(SER_LCR, _inb(SER_LCR) & ~SER_LCR_DLAB);
e931b1fe
JW
50 _outb(SER_IER, 0x0);
51 _outb(SER_FCR, 0x0); /* FIFOs off */
52 _outb(SER_LCR, 0x03); /* 8 data bits, one stop bit, no parity */
53}
54
55void serial_tx(unsigned char c)
56{
113df320
JW
57 int i = 100000;
58
59 while (!(_inb(SER_LSR) & SER_LSR_THR_EMPTY) && (i--))
e931b1fe
JW
60 ;
61 _outb(SER_THR, c);
62}
This page took 0.031398 seconds and 4 git commands to generate.