]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/9/bcm/uartmini.c
merge
[plan9front.git] / sys / src / 9 / bcm / uartmini.c
index aa9b87f1348c37a9b024ba7532da859a1b4836c3..9236d2ae97b5dc9bd40e9d183691190d26adc881 100644 (file)
 #include "fns.h"
 #include "io.h"
 
-#define GPIOREGS       (VIRTIO+0x200000)
 #define AUXREGS                (VIRTIO+0x215000)
 #define        OkLed           16
 #define        TxPin           14
 #define        RxPin           15
 
-/* GPIO regs */
-enum {
-       Fsel0   = 0x00>>2,
-               FuncMask= 0x7,
-               Input   = 0x0,
-               Output  = 0x1,
-               Alt0    = 0x4,
-               Alt1    = 0x5,
-               Alt2    = 0x6,
-               Alt3    = 0x7,
-               Alt4    = 0x3,
-               Alt5    = 0x2,
-       Set0    = 0x1c>>2,
-       Clr0    = 0x28>>2,
-       Lev0    = 0x34>>2,
-       PUD     = 0x94>>2,
-               Off     = 0x0,
-               Pulldown= 0x1,
-               Pullup  = 0x2,
-       PUDclk0 = 0x98>>2,
-       PUDclk1 = 0x9c>>2,
-};
-
 /* AUX regs */
 enum {
        Irq     = 0x00>>2,
@@ -71,58 +47,13 @@ extern PhysUart miniphysuart;
 
 static Uart miniuart = {
        .regs   = (u32int*)AUXREGS,
-       .name   = "uart0",
+       .name   = "uart1",
        .freq   = 250000000,
+       .baud   = 115200,
        .phys   = &miniphysuart,
 };
 
-void
-gpiosel(uint pin, int func)
-{      
-       u32int *gp, *fsel;
-       int off;
-
-       gp = (u32int*)GPIOREGS;
-       fsel = &gp[Fsel0 + pin/10];
-       off = (pin % 10) * 3;
-       *fsel = (*fsel & ~(FuncMask << off)) | func << off;
-}
-
-void
-gpiopulloff(uint pin)
-{
-       u32int *gp, *reg;
-       u32int mask;
-
-       gp = (u32int*)GPIOREGS;
-       reg = &gp[PUDclk0 + pin/32];
-       mask = 1 << (pin % 32);
-       gp[PUD] = Off;
-       microdelay(1);
-       *reg = mask;
-       microdelay(1);
-       *reg = 0;
-}
-
-void
-gpioout(uint pin, int set)
-{
-       u32int *gp;
-       int v;
-
-       gp = (u32int*)GPIOREGS;
-       v = set? Set0: Clr0;
-       gp[v + pin/32] = 1 << (pin % 32);
-}
-
-int
-gpioin(uint pin)
-{
-       u32int *gp;
-
-       gp = (u32int*)GPIOREGS;
-       return (gp[Lev0 + pin/32] & (1 << (pin % 32))) != 0;
-}
+static int baud(Uart*, int);
 
 static void
 interrupt(Ureg*, void *arg)
@@ -162,14 +93,14 @@ enable(Uart *uart, int ie)
        gpiosel(TxPin, Alt5);
        gpiosel(RxPin, Alt5);
        gpiopulloff(TxPin);
-       gpiopulloff(RxPin);
+       gpiopullup(RxPin);
        ap[Enables] |= UartEn;
        ap[MuIir] = 6;
        ap[MuLcr] = Bits8;
        ap[MuCntl] = TxEn|RxEn;
-       ap[MuBaud] = 250000000 / (115200 * 8) - 1;
+       baud(uart, uart->baud);
        if(ie){
-               intrenable(IRQaux, interrupt, uart, 0, "uart");
+               intrenable(IRQaux, interrupt, uart, 0, uart->name);
                ap[MuIer] = RxIen|TxIen;
        }else
                ap[MuIer] = 0;
@@ -328,7 +259,7 @@ donothing(Uart*, int)
 {
 }
 
-void
+static void
 putc(Uart*, int c)
 {
        u32int *ap;
@@ -341,7 +272,7 @@ putc(Uart*, int c)
                ;
 }
 
-int
+static int
 getc(Uart*)
 {
        u32int *ap;
@@ -352,38 +283,8 @@ getc(Uart*)
        return ap[MuIo] & 0xFF;
 }
 
-void
-uartconsinit(void)
-{
-       Uart *uart;
-       int n;
-       char *p, *cmd;
-
-       if((p = getconf("console")) == nil)
-               return;
-       n = strtoul(p, &cmd, 0);
-       if(p == cmd)
-               return;
-       switch(n){
-       default:
-               return;
-       case 0:
-               uart = &miniuart;
-               break;
-       }
-
-       if(!uart->enabled)
-               (*uart->phys->enable)(uart, 0);
-       uartctl(uart, "b9600 l8 pn s1");
-       if(*cmd != '\0')
-               uartctl(uart, cmd);
-
-       consuart = uart;
-       uart->console = 1;
-}
-
 PhysUart miniphysuart = {
-       .name           = "miniuart",
+       .name           = "mini",
        .pnp            = pnp,
        .enable         = enable,
        .disable        = disable,
@@ -401,13 +302,3 @@ PhysUart miniphysuart = {
        .getc           = getc,
        .putc           = putc,
 };
-
-void
-okay(int on)
-{
-       static int first;
-
-       if(!first++)
-               gpiosel(OkLed, Output);
-       gpioout(OkLed, !on);
-}