Changes in uspace/drv/uhci-hcd/uhci.c [1ae51ae:b9d910f] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/uhci-hcd/uhci.c
r1ae51ae rb9d910f 33 33 */ 34 34 #include <errno.h> 35 #include <str_error.h>36 35 #include <adt/list.h> 37 #include <libarch/ddi.h>38 36 39 37 #include <usb/debug.h> 40 38 #include <usb/usb.h> 41 #include <usb/ddfiface.h>42 #include <usb_iface.h>43 39 44 40 #include "uhci.h" 45 #include "iface.h"46 47 41 static irq_cmd_t uhci_cmds[] = { 48 42 { 49 43 .cmd = CMD_PIO_READ_16, 50 .addr = NULL, /* patched for every instance */44 .addr = (void*)0xc022, 51 45 .dstarg = 1 52 46 }, 53 47 { 54 48 .cmd = CMD_PIO_WRITE_16, 55 .addr = NULL, /* pathed for every instance */49 .addr = (void*)0xc022, 56 50 .value = 0x1f 57 51 }, … … 59 53 .cmd = CMD_ACCEPT 60 54 } 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_address86 };87 /*----------------------------------------------------------------------------*/88 static ddf_dev_ops_t uhci_ops = {89 .interfaces[USB_DEV_IFACE] = &hc_usb_iface,90 .interfaces[USBHC_DEV_IFACE] = &uhci_iface,91 55 }; 92 56 … … 107 71 } else (void) 0 108 72 109 int uhci_init(uhci_t *instance, ddf_dev_t *dev,void *regs, size_t reg_size)73 int uhci_init(uhci_t *instance, void *regs, size_t reg_size) 110 74 { 111 75 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));128 76 129 77 /* allow access to hc control registers */ 130 78 regs_t *io; 131 ret = pio_enable(regs, reg_size, (void**)&io);79 int ret = pio_enable(regs, reg_size, (void**)&io); 132 80 CHECK_RET_RETURN(ret, "Failed to gain access to registers at %p.\n", io); 133 81 instance->registers = io; … … 140 88 141 89 instance->cleaner = fibril_create(uhci_interrupt_emulator, instance); 142 fibril_add_ready(instance->cleaner);90 // fibril_add_ready(instance->cleaner); 143 91 144 92 instance->debug_checker = fibril_create(uhci_debug_checker, instance); … … 150 98 void uhci_init_hw(uhci_t *instance) 151 99 { 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); }161 100 162 101 /* set framelist pointer */ … … 211 150 212 151 /* init address keeper(libusb) */ 213 device_keeper_init(&instance->device_manager);214 usb_log_debug("Initialized devicemanager.\n");152 usb_address_keeping_init(&instance->address_manager, USB11_ADDRESS_MAX); 153 usb_log_debug("Initialized address manager.\n"); 215 154 216 155 return EOK; … … 263 202 assert(instance); 264 203 assert(batch); 265 const int low_speed = (batch->speed == USB_SPEED_LOW);204 const int low_speed = (batch->speed == LOW_SPEED); 266 205 if (!allowed_usb_packet( 267 206 low_speed, batch->transfer_type, batch->max_packet_size)) { … … 284 223 { 285 224 assert(instance); 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);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); 293 232 } 294 233 /*----------------------------------------------------------------------------*/ … … 299 238 assert(instance); 300 239 301 while 240 while(1) { 302 241 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;306 242 uhci_interrupt(instance, status); 307 pio_write_16(&instance->registers->usbsts, 0x1f); 308 async_usleep(UHCI_CLEANER_TIMEOUT * 5); 243 async_usleep(UHCI_CLEANER_TIMEOUT); 309 244 } 310 245 return EOK; … … 319 254 const uint16_t sts = pio_read_16(&instance->registers->usbsts); 320 255 const uint16_t intr = pio_read_16(&instance->registers->usbintr); 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; 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); 328 260 if (frame_list != addr_to_phys(instance->frame_list)) { 329 261 usb_log_debug("Framelist address: %p vs. %p.\n",
Note:
See TracChangeset
for help on using the changeset viewer.