Lines Matching refs:softc

106 #define OHCI_WRITECSR(softc,x,y) \
107 *((volatile uint32_t *) ((softc)->ohci_regs + ((x)/sizeof(uint32_t)))) = (y)
108 #define OHCI_READCSR(softc,x) \
109 *((volatile uint32_t *) ((softc)->ohci_regs + ((x)/sizeof(uint32_t))))
135 #define OHCI_WRITECSR(softc,x,y) \
136 phys_write32(((softc)->ohci_regs + (x)),(y))
137 #define OHCI_READCSR(softc,x) \
138 phys_read32(((softc)->ohci_regs + (x)))
186 #define ohci_td_from_transfer(softc,transfer) \
187 ((softc)->ohci_hwtdpool + ((transfer) - (softc)->ohci_transfer_pool))
189 #define ohci_transfer_from_td(softc,td) \
190 ((softc)->ohci_transfer_pool + ((td) - (softc)->ohci_hwtdpool))
192 #define ohci_ed_from_endpoint(softc,endpoint) \
193 ((softc)->ohci_hwedpool + ((endpoint) - (softc)->ohci_endpoint_pool))
195 #define ohci_endpoint_from_ed(softc,ed) \
196 ((softc)->ohci_endpoint_pool + ((ed) - (softc)->ohci_hwedpool))
203 static void ohci_roothub_statchg(ohci_softc_t *softc);
218 void ohci_dumpdoneq(ohci_softc_t *softc);
256 void ohci_dumptd(ohci_softc_t *softc,ohci_td_t *td)
277 void ohci_dumptdchain(ohci_softc_t *softc,ohci_td_t *td)
290 transfer = ohci_transfer_from_td(softc,td);
299 void ohci_dumped(ohci_softc_t *softc,ohci_ed_t *ed)
321 ohci_dumptdchain(softc,OHCI_PTOV(BSWAP32(ed->ed_headp) & M_OHCI_ED_PTRMASK));
324 void ohci_dumpedchain(ohci_softc_t *softc,ohci_ed_t *ed)
329 ohci_dumped(softc,ed);
337 void ohci_dumpdoneq(ohci_softc_t *softc)
339 uint32_t donehead = softc->ohci_hcca->hcca_donehead;
347 printf("Done Queue:\n"); ohci_dumptdchain(softc,td);
352 static void eptstats(ohci_softc_t *softc)
358 e = softc->ohci_endpoint_freelist;
367 * _ohci_allocept(softc)
374 * softc - our OHCI controller
380 static ohci_endpoint_t *_ohci_allocept(ohci_softc_t *softc)
387 printf("AllocEpt: ");eptstats(softc);
391 e = softc->ohci_endpoint_freelist;
398 softc->ohci_endpoint_freelist = e->ep_next;
400 ed = ohci_ed_from_endpoint(softc,e);
415 * _ohci_allocxfer(softc)
421 * softc - our OHCI controller
427 static ohci_transfer_t *_ohci_allocxfer(ohci_softc_t *softc)
436 t = softc->ohci_transfer_freelist;
442 t = softc->ohci_transfer_freelist;
449 softc->ohci_transfer_freelist = t->t_next;
451 td = ohci_td_from_transfer(softc,t);
466 * _ohci_freeept(softc,e)
471 * softc - our OHCI controller
478 static void _ohci_freeept(ohci_softc_t *softc,ohci_endpoint_t *e)
486 ee = softc->ohci_endpoint_freelist;
492 e->ep_next = softc->ohci_endpoint_freelist;
493 softc->ohci_endpoint_freelist = e;
498 * _ohci_freexfer(softc,t)
503 * softc - our OHCI controller
510 static void _ohci_freexfer(ohci_softc_t *softc,ohci_transfer_t *t)
512 t->t_next = softc->ohci_transfer_freelist;
513 softc->ohci_transfer_freelist = t;
551 * _ohci_initpools(softc)
558 * softc - our OHCI controller
565 static int _ohci_initpools(ohci_softc_t *softc)
580 softc->ohci_transfer_pool = KMALLOC(OHCI_TDPOOL_SIZE*sizeof(ohci_transfer_t),CACHE_ALIGN);
581 softc->ohci_hwtdpool = _ohci_dma_alloc(OHCI_TDPOOL_SIZE*sizeof(ohci_td_t),OHCI_TD_ALIGN);
583 if (!softc->ohci_transfer_pool || !softc->ohci_hwtdpool) {
589 softc->ohci_hwtdpool = (void *) UNCADDR(PHYSADDR((uint32_t)(softc->ohci_hwtdpool)));
592 softc->ohci_transfer_freelist = NULL;
595 _ohci_freexfer(softc,softc->ohci_transfer_pool+idx);
602 softc->ohci_endpoint_pool = KMALLOC(OHCI_EDPOOL_SIZE*sizeof(ohci_endpoint_t),CACHE_ALIGN);
604 softc->ohci_hwedpool = _ohci_dma_alloc(OHCI_EDPOOL_SIZE*sizeof(ohci_ed_t),OHCI_ED_ALIGN);
606 if (!softc->ohci_endpoint_pool || !softc->ohci_hwedpool) {
612 softc->ohci_hwedpool = (void *) UNCADDR(PHYSADDR((uint32_t)(softc->ohci_hwedpool)));
615 softc->ohci_endpoint_freelist = NULL;
618 _ohci_freeept(softc,softc->ohci_endpoint_pool+idx);
625 softc->ohci_hcca = _ohci_dma_alloc(sizeof(ohci_hcca_t),OHCI_HCCA_ALIGN);
627 if (!softc->ohci_hcca) {
633 softc->ohci_hcca = (void *) UNCADDR(PHYSADDR((uint32_t)(softc->ohci_hcca)));
636 memset(softc->ohci_hcca,0,sizeof(ohci_hcca_t));
659 ohci_softc_t *softc = (ohci_softc_t *) bus->ub_hwsoftc;
668 OHCI_WRITECSR(softc,R_OHCI_CONTROL,V_OHCI_CONTROL_HCFS(K_OHCI_HCFS_RESET));
676 frameint = G_OHCI_FMINTERVAL_FI(OHCI_READCSR(softc,R_OHCI_FMINTERVAL));
683 OHCI_WRITECSR(softc,R_OHCI_CMDSTATUS,M_OHCI_CMDSTATUS_HCR);
685 if (!(OHCI_READCSR(softc,R_OHCI_CMDSTATUS) & M_OHCI_CMDSTATUS_HCR)) break;
688 if (OHCI_READCSR(softc,R_OHCI_CMDSTATUS) & M_OHCI_CMDSTATUS_HCR) {
700 OHCI_WRITECSR(softc,R_OHCI_HCCA,OHCI_VTOP(softc->ohci_hcca));
701 OHCI_WRITECSR(softc,R_OHCI_CONTROLHEADED,softc->ohci_ctl_list->ep_phys);
702 OHCI_WRITECSR(softc,R_OHCI_BULKHEADED,softc->ohci_bulk_list->ep_phys);
708 OHCI_WRITECSR(softc,R_OHCI_INTDISABLE,M_OHCI_INT_ALL);
714 reg = OHCI_READCSR(softc,R_OHCI_CONTROL);
721 OHCI_WRITECSR(softc,R_OHCI_CONTROL,reg);
727 reg = OHCI_READCSR(softc,R_OHCI_FMINTERVAL);
732 OHCI_WRITECSR(softc,R_OHCI_FMINTERVAL,reg);
735 OHCI_WRITECSR(softc,R_OHCI_PERIODICSTART,reg);
737 usb_delay_ms(softc->ohci_bus,10);
743 reg = OHCI_READCSR(softc,R_OHCI_RHDSCRA);
744 softc->ohci_ndp = G_OHCI_RHDSCRA_NDP(reg);
750 OHCI_WRITECSR(softc,R_OHCI_RHSTATUS,M_OHCI_RHSTATUS_LPSC);
751 usb_delay_ms(softc->ohci_bus,10);
758 * _ohci_setupepts(softc)
767 * softc - our OHCI controller
774 static int _ohci_setupepts(ohci_softc_t *softc)
795 softc->ohci_isoc_list = _ohci_allocept(softc);
796 softc->ohci_ctl_list = _ohci_allocept(softc);
797 softc->ohci_bulk_list = _ohci_allocept(softc);
815 e = _ohci_allocept(softc); /* allocated with sKip bit set */
816 softc->ohci_edtable[idx] = e;
817 child = (idx == 0) ? softc->ohci_isoc_list : softc->ohci_edtable[(idx-1)/2];
818 ed = ohci_ed_from_endpoint(softc,e);
829 child = softc->ohci_edtable[OHCI_INTTREE_SIZE-OHCI_INTTABLE_SIZE+idx];
830 softc->ohci_inttable[ohci_revbits[idx]] = child;
831 softc->ohci_hcca->hcca_inttable[ohci_revbits[idx]] = BSWAP32(child->ep_phys);
855 ohci_softc_t *softc = (ohci_softc_t *) bus->ub_hwsoftc;
857 OHCI_WRITECSR(softc,R_OHCI_CONTROL,V_OHCI_CONTROL_HCFS(K_OHCI_HCFS_RESET));
862 * _ohci_queueept(softc,queue,e)
876 static void _ohci_queueept(ohci_softc_t *softc,ohci_endpoint_t *queue,ohci_endpoint_t *newept)
881 qed = ohci_ed_from_endpoint(softc,queue);
882 newed = ohci_ed_from_endpoint(softc,newept);
891 if (ohcidebug > 1) ohci_dumped(softc,newed);
911 static void _ohci_deqept(ohci_softc_t *softc,ohci_endpoint_t *queue,ohci_endpoint_t *e)
936 cured = ohci_ed_from_endpoint(softc,cur);
937 ed = ohci_ed_from_endpoint(softc,e);
944 * ohci_intr_procdoneq(softc)
951 * softc - our OHCI controller
957 static void ohci_intr_procdoneq(ohci_softc_t *softc, uint32_t donehead)
972 transfer = ohci_transfer_from_td(softc,td);
988 ed = ohci_ed_from_endpoint(softc,ept);
990 // ohci_dumped(softc,ed);
1001 ohci_dumptd(softc,td);
1053 _ohci_freexfer(softc,transfer);
1060 transfer = ohci_transfer_from_td(softc,td);
1080 ohci_softc_t *softc = (ohci_softc_t *) bus->ub_hwsoftc;
1088 reg = OHCI_READCSR(softc,R_OHCI_INTSTATUS);
1102 donehead = softc->ohci_hcca->hcca_donehead;
1109 OHCI_WRITECSR(softc,R_OHCI_INTSTATUS,reg);
1118 ohci_intr_procdoneq(softc, donehead);
1142 if ((reg & ~softc->ohci_intdisable) & M_OHCI_INT_RHSC) {
1147 reg = OHCI_READCSR(softc,R_OHCI_RHSTATUS);
1149 reg = OHCI_READCSR(softc,R_OHCI_RHPORTSTATUS(1));
1151 reg = OHCI_READCSR(softc,R_OHCI_RHPORTSTATUS(2));
1155 ohci_roothub_statchg(softc);
1202 ohci_softc_t *softc;
1205 softc = KMALLOC(sizeof(ohci_softc_t),0);
1206 if (!softc) return NULL;
1211 memset(softc,0,sizeof(ohci_softc_t));
1214 bus->ub_hwsoftc = (usb_hc_t *) softc;
1217 q_init(&(softc->ohci_rh_intrq));
1220 softc->ohci_regs = addr;
1222 softc->ohci_regs = (volatile uint32_t *) addr;
1225 softc->ohci_rh_newaddr = -1;
1226 softc->ohci_bus = bus;
1228 if ((res = _ohci_initpools(softc)) != 0) goto error;
1229 if ((res = _ohci_setupepts(softc)) != 0) goto error;
1231 OHCI_WRITECSR(softc,R_OHCI_CONTROL,V_OHCI_CONTROL_HCFS(K_OHCI_HCFS_RESET));
1236 KFREE(softc);
1272 ohci_softc_t *softc = (ohci_softc_t *) bus->ub_hwsoftc;
1274 ept = _ohci_allocept(softc);
1275 ed = ohci_ed_from_endpoint(softc,ept);
1277 tailtransfer = _ohci_allocxfer(softc);
1278 tailtd = ohci_td_from_transfer(softc,tailtransfer);
1337 _ohci_queueept(softc,softc->ohci_ctl_list,ept);
1340 _ohci_queueept(softc,softc->ohci_bulk_list,ept);
1344 _ohci_queueept(softc,softc->ohci_inttable[0],ept);
1373 ohci_softc_t *softc = (ohci_softc_t *) bus->ub_hwsoftc;
1374 ohci_ed_t *ed = ohci_ed_from_endpoint(softc,ept);
1402 ohci_softc_t *softc = (ohci_softc_t *) bus->ub_hwsoftc;
1404 ohci_ed_t *ed = ohci_ed_from_endpoint(softc,ept);
1431 ohci_softc_t *softc = (ohci_softc_t *) bus->ub_hwsoftc;
1433 ohci_ed_t *ed = ohci_ed_from_endpoint(softc,ept);
1439 OHCI_WRITECSR(softc,R_OHCI_CMDSTATUS,M_OHCI_CMDSTATUS_CLF);
1461 ohci_softc_t *softc = (ohci_softc_t *) bus->ub_hwsoftc;
1463 ohci_ed_t *ed = ohci_ed_from_endpoint(softc,ept);
1471 queue = softc->ohci_ctl_list;
1474 queue = softc->ohci_bulk_list;
1477 queue = softc->ohci_inttable[0];
1492 framenum = OHCI_READCSR(softc,R_OHCI_FMNUMBER) & 0xFFFF;
1493 while ((OHCI_READCSR(softc,R_OHCI_FMNUMBER) & 0xFFFF) == framenum) ; /* NULL LOOP */
1495 framenum = OHCI_READCSR(softc,R_OHCI_FMNUMBER) & 0xFFFF;
1496 while ((OHCI_READCSR(softc,R_OHCI_FMNUMBER) & 0xFFFF) == framenum) ; /* NULL LOOP */
1502 _ohci_deqept(softc,queue,ept);
1513 transfer = ohci_transfer_from_td(softc,td);
1532 _ohci_freexfer(softc,transfer);
1540 _ohci_freexfer(softc,ohci_transfer_from_td(softc,td));
1546 _ohci_freeept(softc,ept);
1569 ohci_softc_t *softc = (ohci_softc_t *) bus->ub_hwsoftc;
1571 ohci_ed_t *ed = ohci_ed_from_endpoint(softc,ept);
1588 if (ur->ur_dev->ud_address == softc->ohci_rh_addr) {
1651 // ohci_dumped(softc,ed);
1656 curtransfer = ohci_transfer_from_td(softc,curtd);
1659 newtailtransfer = _ohci_allocxfer(softc);
1660 newtailtd = ohci_td_from_transfer(softc,newtailtransfer);
1669 if (ohcidebug > 1) { printf("QueueTD: "); ohci_dumptd(softc,curtd); }
1679 newtailtransfer = _ohci_allocxfer(softc);
1680 newtailtd = ohci_td_from_transfer(softc,newtailtransfer);
1689 if (ohcidebug > 1) { printf("QueueTD: "); ohci_dumptd(softc,curtd); }
1692 curtransfer = ohci_transfer_from_td(softc,curtd);
1714 OHCI_WRITECSR(softc,R_OHCI_CMDSTATUS,M_OHCI_CMDSTATUS_BLF);
1718 OHCI_WRITECSR(softc,R_OHCI_CMDSTATUS,M_OHCI_CMDSTATUS_CLF);
1842 * ohci_roothub_req(softc,req)
1849 * softc - our OHCI controller
1857 static int ohci_roothub_req(ohci_softc_t *softc,usb_device_request_t *req)
1870 ptr = softc->ohci_rh_buf;
1890 status = OHCI_READCSR(softc,(R_OHCI_RHPORTSTATUS(wIndex)));
1917 printf("RHClearFeature(%d): ",wValue); ohci_dumpportstat(wIndex,OHCI_READCSR(softc,statport));
1924 OHCI_WRITECSR(softc,statport,M_OHCI_RHPORTSTAT_CCS);
1927 OHCI_WRITECSR(softc,statport,M_OHCI_RHPORTSTAT_POCI);
1934 OHCI_WRITECSR(softc,statport,M_OHCI_RHPORTSTAT_LSDA);
1939 OHCI_WRITECSR(softc,statport,M_OHCI_RHPORTSTAT_CSC);
1942 OHCI_WRITECSR(softc,statport,M_OHCI_RHPORTSTAT_PESC);
1945 OHCI_WRITECSR(softc,statport,M_OHCI_RHPORTSTAT_PSSC);
1948 OHCI_WRITECSR(softc,statport,M_OHCI_RHPORTSTAT_OCIC);
1951 OHCI_WRITECSR(softc,statport,M_OHCI_RHPORTSTAT_PRSC);
1964 status = OHCI_READCSR(softc,statport);
1966 softc->ohci_intdisable &= ~M_OHCI_INT_RHSC;
1987 OHCI_WRITECSR(softc,statport,M_OHCI_RHPORTSTAT_PES);
1990 OHCI_WRITECSR(softc,statport,M_OHCI_RHPORTSTAT_PSS);
1995 OHCI_WRITECSR(softc,statport,M_OHCI_RHPORTSTAT_PRS);
1997 usb_delay_ms(softc->ohci_bus,100);
1998 if (!(OHCI_READCSR(softc,statport) & M_OHCI_RHPORTSTAT_PRS)) break;
2002 OHCI_WRITECSR(softc,statport,M_OHCI_RHPORTSTAT_PPS);
2022 softc->ohci_rh_newaddr = wValue;
2060 hdsc.bNumberOfPorts = softc->ohci_ndp;
2061 status = OHCI_READCSR(softc,R_OHCI_RHDSCRA);
2070 status = OHCI_READCSR(softc,R_OHCI_RHDSCRB);
2081 *ptr++ = softc->ohci_rh_conf;
2085 softc->ohci_rh_conf = wValue;
2101 softc->ohci_rh_ptr = softc->ohci_rh_buf;
2102 softc->ohci_rh_len = ptr - softc->ohci_rh_buf;
2108 * ohci_roothub_statchg(softc)
2117 * softc - our OHCI controller
2123 static void ohci_roothub_statchg(ohci_softc_t *softc)
2131 for (idx = 1; idx <= softc->ohci_ndp; idx++) {
2132 status = OHCI_READCSR(softc,R_OHCI_RHPORTSTATUS(idx));
2140 softc->ohci_intdisable |= M_OHCI_INT_RHSC;
2142 ur = (usbreq_t *) q_deqnext(&(softc->ohci_rh_intrq));
2154 * ohci_roothub_xfer(softc,req)
2165 * softc - our OHCI controller structure
2175 ohci_softc_t *softc = (ohci_softc_t *) bus->ub_hwsoftc;
2200 res = ohci_roothub_req(softc,req);
2217 if (softc->ohci_rh_newaddr != -1) {
2218 softc->ohci_rh_addr = softc->ohci_rh_newaddr;
2219 softc->ohci_rh_newaddr = -1;
2242 amtcopy = softc->ohci_rh_len;
2245 memcpy(ur->ur_buffer,softc->ohci_rh_ptr,amtcopy);
2247 softc->ohci_rh_ptr += amtcopy;
2248 softc->ohci_rh_len -= amtcopy;
2267 q_enqueue(&(softc->ohci_rh_intrq),(queue_t *) ur);