Changes in uspace/drv/uhci-hcd/uhci.c [b9d910f:1ae51ae] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/uhci-hcd/uhci.c
rb9d910f r1ae51ae 33 33 */ 34 34 #include <errno.h> 35 #include <str_error.h> 35 36 #include <adt/list.h> 37 #include <libarch/ddi.h> 36 38 37 39 #include <usb/debug.h> 38 40 #include <usb/usb.h> 41 #include <usb/ddfiface.h> 42 #include <usb_iface.h> 39 43 40 44 #include "uhci.h" 45 #include "iface.h" 46 41 47 static irq_cmd_t uhci_cmds[] = { 42 48 { 43 49 .cmd = CMD_PIO_READ_16, 44 .addr = (void*)0xc022,50 .addr = NULL, /* patched for every instance */ 45 51 .dstarg = 1 46 52 }, 47 53 { 48 54 .cmd = CMD_PIO_WRITE_16, 49 .addr = (void*)0xc022,55 .addr = NULL, /* pathed for every instance */ 50 56 .value = 0x1f 51 57 }, … … 53 59 .cmd = CMD_ACCEPT 54 60 } 61 }; 62 63 static int usb_iface_get_address(ddf_fun_t *fun, devman_handle_t handle, 64 usb_address_t *address) 65 { 66 assert(fun); 67 uhci_t *hc = fun_to_uhci(fun); 68 assert(hc); 69 70 usb_address_t addr = device_keeper_find(&hc->device_manager, 71 handle); 72 if (addr < 0) { 73 return addr; 74 } 75 76 if (address != NULL) { 77 *address = addr; 78 } 79 80 return EOK; 81 } 82 /*----------------------------------------------------------------------------*/ 83 static usb_iface_t hc_usb_iface = { 84 .get_hc_handle = usb_iface_get_hc_handle_hc_impl, 85 .get_address = usb_iface_get_address 86 }; 87 /*----------------------------------------------------------------------------*/ 88 static ddf_dev_ops_t uhci_ops = { 89 .interfaces[USB_DEV_IFACE] = &hc_usb_iface, 90 .interfaces[USBHC_DEV_IFACE] = &uhci_iface, 55 91 }; 56 92 … … 71 107 } else (void) 0 72 108 73 int uhci_init(uhci_t *instance, void *regs, size_t reg_size)109 int uhci_init(uhci_t *instance, ddf_dev_t *dev, void *regs, size_t reg_size) 74 110 { 75 111 assert(reg_size >= sizeof(regs_t)); 112 int ret; 113 114 /* 115 * Create UHCI function. 116 */ 117 instance->ddf_instance = ddf_fun_create(dev, fun_exposed, "uhci"); 118 if (instance->ddf_instance == NULL) { 119 usb_log_error("Failed to create UHCI device function.\n"); 120 return ENOMEM; 121 } 122 instance->ddf_instance->ops = &uhci_ops; 123 instance->ddf_instance->driver_data = instance; 124 125 ret = ddf_fun_bind(instance->ddf_instance); 126 CHECK_RET_RETURN(ret, "Failed to bind UHCI device function: %s.\n", 127 str_error(ret)); 76 128 77 129 /* allow access to hc control registers */ 78 130 regs_t *io; 79 intret = pio_enable(regs, reg_size, (void**)&io);131 ret = pio_enable(regs, reg_size, (void**)&io); 80 132 CHECK_RET_RETURN(ret, "Failed to gain access to registers at %p.\n", io); 81 133 instance->registers = io; … … 88 140 89 141 instance->cleaner = fibril_create(uhci_interrupt_emulator, instance); 90 //fibril_add_ready(instance->cleaner);142 fibril_add_ready(instance->cleaner); 91 143 92 144 instance->debug_checker = fibril_create(uhci_debug_checker, instance); … … 98 150 void uhci_init_hw(uhci_t *instance) 99 151 { 152 /* reset everything, who knows what touched it before us */ 153 pio_write_16(&instance->registers->usbcmd, UHCI_CMD_GLOBAL_RESET); 154 async_usleep(10000); /* 10ms according to USB spec */ 155 pio_write_16(&instance->registers->usbcmd, 0); 156 157 /* reset hc, all states and counters */ 158 pio_write_16(&instance->registers->usbcmd, UHCI_CMD_HCRESET); 159 while ((pio_read_16(&instance->registers->usbcmd) & UHCI_CMD_HCRESET) != 0) 160 { async_usleep(10); } 100 161 101 162 /* set framelist pointer */ … … 150 211 151 212 /* init address keeper(libusb) */ 152 usb_address_keeping_init(&instance->address_manager, USB11_ADDRESS_MAX);153 usb_log_debug("Initialized addressmanager.\n");213 device_keeper_init(&instance->device_manager); 214 usb_log_debug("Initialized device manager.\n"); 154 215 155 216 return EOK; … … 202 263 assert(instance); 203 264 assert(batch); 204 const int low_speed = (batch->speed == LOW_SPEED);265 const int low_speed = (batch->speed == USB_SPEED_LOW); 205 266 if (!allowed_usb_packet( 206 267 low_speed, batch->transfer_type, batch->max_packet_size)) { … … 223 284 { 224 285 assert(instance); 225 if ((status & (UHCI_STATUS_INTERRUPT | UHCI_STATUS_ERROR_INTERRUPT)) == 0)226 return;227 usb_log_debug("UHCI interrupt: %X.\n", status);228 transfer_list_ check(&instance->transfers_interrupt);229 transfer_list_ check(&instance->transfers_control_slow);230 transfer_list_ check(&instance->transfers_control_full);231 transfer_list_ check(&instance->transfers_bulk_full);286 // if ((status & (UHCI_STATUS_INTERRUPT | UHCI_STATUS_ERROR_INTERRUPT)) == 0) 287 // return; 288 // usb_log_debug2("UHCI interrupt: %X.\n", status); 289 transfer_list_remove_finished(&instance->transfers_interrupt); 290 transfer_list_remove_finished(&instance->transfers_control_slow); 291 transfer_list_remove_finished(&instance->transfers_control_full); 292 transfer_list_remove_finished(&instance->transfers_bulk_full); 232 293 } 233 294 /*----------------------------------------------------------------------------*/ … … 238 299 assert(instance); 239 300 240 while (1) {301 while (1) { 241 302 uint16_t status = pio_read_16(&instance->registers->usbsts); 303 if (status != 0) 304 usb_log_debug2("UHCI status: %x.\n", status); 305 status |= 1; 242 306 uhci_interrupt(instance, status); 243 async_usleep(UHCI_CLEANER_TIMEOUT); 307 pio_write_16(&instance->registers->usbsts, 0x1f); 308 async_usleep(UHCI_CLEANER_TIMEOUT * 5); 244 309 } 245 310 return EOK; … … 254 319 const uint16_t sts = pio_read_16(&instance->registers->usbsts); 255 320 const uint16_t intr = pio_read_16(&instance->registers->usbintr); 256 usb_log_debug("Command: %X Status: %X Interrupts: %x\n", 257 cmd, sts, intr); 258 259 uintptr_t frame_list = pio_read_32(&instance->registers->flbaseadd); 321 if (((cmd & UHCI_CMD_RUN_STOP) != 1) || (sts != 0)) { 322 usb_log_debug2("Command: %X Status: %X Intr: %x\n", 323 cmd, sts, intr); 324 } 325 326 uintptr_t frame_list = 327 pio_read_32(&instance->registers->flbaseadd) & ~0xfff; 260 328 if (frame_list != addr_to_phys(instance->frame_list)) { 261 329 usb_log_debug("Framelist address: %p vs. %p.\n",
Note:
See TracChangeset
for help on using the changeset viewer.