2 #include "../port/lib.h"
7 #include "../port/error.h"
8 #include "../port/usb.h"
18 static Ctlr ctlrs[3] = {
38 opio->cmd |= Chcreset;
39 for(i = 0; i < 100; i++){
40 if((opio->cmd & Chcreset) == 0)
45 print("ehci %#p controller reset timed out\n", ctlr->base);
47 switch(opio->cmd & Cflsmask){
58 panic("ehci: unknown fls %ld", opio->cmd & Cflsmask);
60 dprint("ehci: %d frames\n", ctlr->nframes);
64 /* descriptors need to be allocated in uncached memory */
66 tdalloc(ulong size, int, ulong)
74 return mallocalign(ROUND(len, BLOCKALIGN), BLOCKALIGN, 0, 0);
82 static int (*ehciportstatus)(Hci*,int);
85 portstatus(Hci *hp, int port)
93 r = (*ehciportstatus)(hp, port);
95 sts = opio->portsc[port-1];
96 r &= ~(HPhigh|HPslow);
108 static Lock resetlck;
112 for(ctlr = ctlrs; ctlr->base != 0; ctlr++)
113 if(!ctlr->active && (hp->port == 0 || hp->port == ctlr->base)){
120 hp->port = ctlr->base;
124 ctlr->r = vmap(ctlr->base, 0x1F0);
125 ctlr->opio = (Eopio *) ((uchar *) ctlr->r + 0x140);
126 ctlr->capio = (void *) ctlr->base;
129 ctlr->tdalloc = tdalloc;
130 ctlr->dmaalloc = dmaalloc;
131 ctlr->dmafree = dmafree;
134 ctlr->r[USBMODE] |= USBHOST;
135 ctlr->r[ULPI] = 1<<30 | 1<<29 | 0x0B << 16 | 3<<5;
139 /* hook portstatus */
140 ehciportstatus = hp->portstatus;
141 hp->portstatus = portstatus;
143 if(hp->interrupt != nil)
144 intrenable(hp->irq, hp->interrupt, hp, LEVEL, hp->type);
152 addhcitype("ehci", reset);