2 * bcm2835 mini uart (UART1)
6 #include "../port/lib.h"
7 #include "../port/error.h"
13 #define AUXREGS (VIRTIO+0x215000)
46 extern PhysUart miniphysuart;
48 static Uart miniuart = {
49 .regs = (u32int*)AUXREGS,
53 .phys = &miniphysuart,
56 static int baud(Uart*, int);
59 interrupt(Ureg*, void *arg)
65 ap = (u32int*)uart->regs;
68 if(0 && (ap[Irq] & UartIrq) == 0)
72 if(ap[MuLsr] & RxRdy){
74 uartrecv(uart, ap[MuIo] & 0xFF);
75 }while(ap[MuLsr] & RxRdy);
87 enable(Uart *uart, int ie)
91 ap = (u32int*)uart->regs;
97 ap[Enables] |= UartEn;
100 ap[MuCntl] = TxEn|RxEn;
101 baud(uart, uart->baud);
103 intrenable(IRQaux, interrupt, uart, 0, "uart");
104 ap[MuIer] = RxIen|TxIen;
114 ap = (u32int*)uart->regs;
124 ap = (u32int*)uart->regs;
128 while(ap[MuLsr] & TxRdy){
129 if(uart->op >= uart->oe && uartstageoutput(uart) == 0)
131 ap[MuIo] = *(uart->op++);
133 if(ap[MuLsr] & TxDone)
142 dobreak(Uart *uart, int ms)
148 baud(Uart *uart, int n)
152 ap = (u32int*)uart->regs;
153 if(uart->freq == 0 || n <= 0)
155 ap[MuBaud] = (uart->freq + 4*n - 1) / (8 * n) - 1;
161 bits(Uart *uart, int n)
166 ap = (u32int*)uart->regs;
177 ap[MuLcr] = (ap[MuLcr] & ~Bitsmask) | set;
183 stop(Uart *uart, int n)
192 parity(Uart *uart, int n)
201 * cts/rts flow control
202 * need to bring signals to gpio pins before enabling this
206 modemctl(Uart *uart, int on)
210 ap = (u32int*)uart->regs;
212 ap[MuCntl] |= CtsFlow;
214 ap[MuCntl] &= ~CtsFlow;
219 rts(Uart *uart, int on)
223 ap = (u32int*)uart->regs;
231 status(Uart *uart, void *buf, long n, long offset)
240 "dev(%d) type(%d) framing(%d) overruns(%d) "
241 "berr(%d) serr(%d)\n",
251 n = readstr(offset, buf, n, p);
258 donothing(Uart*, int)
267 ap = (u32int*)AUXREGS;
268 while((ap[MuLsr] & TxRdy) == 0)
271 while((ap[MuLsr] & TxRdy) == 0)
280 ap = (u32int*)AUXREGS;
281 while((ap[MuLsr] & RxRdy) == 0)
283 return ap[MuIo] & 0xFF;
293 if((p = getconf("console")) == nil)
295 n = strtoul(p, &cmd, 0);
307 (*uart->phys->enable)(uart, 0);
308 uartctl(uart, "l8 pn s1");
316 PhysUart miniphysuart = {
327 .modemctl = donothing,