Skip to content

Commit 4be35f7

Browse files
committed
8070: add 16x50 serial driver
1 parent 25864a4 commit 4be35f7

File tree

1 file changed

+65
-5
lines changed
  • Kernel/platform/platform-rcbus-8070

1 file changed

+65
-5
lines changed

Kernel/platform/platform-rcbus-8070/devtty.c

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/*
2+
* TODO: support multiple 16x50 ports
3+
*/
14
#include <kernel.h>
25
#include <kdata.h>
36
#include <printf.h>
@@ -44,10 +47,58 @@ void tty_putc(uint8_t minor, unsigned char c)
4447
*uart = c;
4548
}
4649

50+
/*
51+
* 16x50 conversion betwen a Bxxxx speed rate (see tty.h) and the values
52+
* to stuff into the chip.
53+
*/
54+
static uint16_t clocks[] = {
55+
12, /* Not a real rate */
56+
2304,
57+
1536,
58+
1047,
59+
857,
60+
768,
61+
384,
62+
192,
63+
96,
64+
48,
65+
24,
66+
12,
67+
6,
68+
3,
69+
2,
70+
1
71+
};
72+
73+
4774
void tty_setup(uint8_t minor, uint8_t flag)
4875
{
49-
/* As we don't have a separate clock for serial and the
50-
divider is very limited we are stuck at 115200 8N1 */
76+
uint8_t d;
77+
uint16_t w;
78+
struct termios *t = &ttydata[1].termios;
79+
80+
d = 0x80; /* DLAB (so we can write the speed) */
81+
d |= (t->c_cflag & CSIZE) >> 4;
82+
if(t->c_cflag & CSTOPB)
83+
d |= 0x04;
84+
if (t->c_cflag & PARENB)
85+
d |= 0x08;
86+
if (!(t->c_cflag & PARODD))
87+
d |= 0x10;
88+
uart[3] = d; /* LCR */
89+
w = clocks[t->c_cflag & CBAUD];
90+
*uart = w; /* Set the DL */
91+
uart[1] = w >> 8;
92+
if (w >> 8) /* Low speeds interrupt every byte for latency */
93+
uart[2] = 0;
94+
else /* High speeds set our interrupt quite early
95+
as our latency is poor, turn on 64 byte if
96+
we have a 16C750 */
97+
uart[2] = 0x51;
98+
uart[3] = d & 0x7F;
99+
/* FIXME: CTS/RTS support */
100+
uart[4] = 0x03; /* DTR RTS */
101+
uart[1] = 0x0D; /* We don't use tx ints */
51102
}
52103

53104
void tty_sleeping(uint8_t minor)
@@ -57,7 +108,7 @@ void tty_sleeping(uint8_t minor)
57108
/* No carrier signal */
58109
int tty_carrier(uint8_t minor)
59110
{
60-
return 1;
111+
return uart[6] & 0x80;
61112
}
62113

63114
/* No flow control */
@@ -67,6 +118,15 @@ void tty_data_consumed(uint8_t minor)
67118

68119
void tty_poll(void)
69120
{
70-
/* TODO if (cpuio[0x11] & 0x80)
71-
tty_inproc(1, cpuio[0x12]); */
121+
uint8_t msr;
122+
if (uart[5] & 0x01)
123+
tty_inproc(1, *uart);
124+
msr = uart[6];
125+
if (msr & 0x08) {
126+
if (msr & 0x80)
127+
tty_carrier_raise(1);
128+
else
129+
tty_carrier_drop(1);
130+
}
131+
/* TOOD: CTS/RTS etc */
72132
}

0 commit comments

Comments
 (0)