Changeset 8c877b2 in mainline for uspace/drv/uhci-hcd/main.c
- Timestamp:
- 2011-03-04T13:05:35Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d49728c
- Parents:
- dff940f8 (diff), 9a422574 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/uhci-hcd/main.c
rdff940f8 r8c877b2 34 34 #include <ddf/driver.h> 35 35 #include <ddf/interrupt.h> 36 #include <device/hw_res.h> 37 #include <errno.h> 38 #include <str_error.h> 39 36 40 #include <usb_iface.h> 37 41 #include <usb/ddfiface.h> 38 #include <device/hw_res.h>39 40 #include <errno.h>41 42 42 #include <usb/debug.h> 43 43 … … 50 50 51 51 static int uhci_add_device(ddf_dev_t *device); 52 53 52 /*----------------------------------------------------------------------------*/ 54 53 static driver_ops_t uhci_driver_ops = { … … 70 69 } 71 70 /*----------------------------------------------------------------------------*/ 72 #define CHECK_RET_RETURN(ret, message...) \ 71 static int uhci_add_device(ddf_dev_t *device) 72 { 73 assert(device); 74 uhci_t *hcd = NULL; 75 #define CHECK_RET_FREE_HC_RETURN(ret, message...) \ 73 76 if (ret != EOK) { \ 74 77 usb_log_error(message); \ 78 if (hcd != NULL) \ 79 free(hcd); \ 75 80 return ret; \ 76 81 } 77 82 78 static int uhci_add_device(ddf_dev_t *device)79 {80 assert(device);81 82 83 usb_log_info("uhci_add_device() called\n"); 83 84 84 85 uintptr_t io_reg_base; 86 size_t io_reg_size; 87 int irq; 85 uintptr_t io_reg_base = 0; 86 size_t io_reg_size = 0; 87 int irq = 0; 88 88 89 89 int ret = 90 90 pci_get_my_registers(device, &io_reg_base, &io_reg_size, &irq); 91 92 CHECK_RET_RETURN(ret, 91 CHECK_RET_FREE_HC_RETURN(ret, 93 92 "Failed(%d) to get I/O addresses:.\n", ret, device->handle); 94 93 usb_log_info("I/O regs at 0x%X (size %zu), IRQ %d.\n", 95 94 io_reg_base, io_reg_size, irq); 96 95 96 ret = pci_disable_legacy(device); 97 CHECK_RET_FREE_HC_RETURN(ret, 98 "Failed(%d) disable legacy USB: %s.\n", ret, str_error(ret)); 99 100 #if 0 97 101 ret = pci_enable_interrupts(device); 98 CHECK_RET_RETURN(ret, "Failed(%d) to get enable interrupts:\n", ret); 102 if (ret != EOK) { 103 usb_log_warning( 104 "Failed(%d) to enable interrupts, fall back to polling.\n", 105 ret); 106 } 107 #endif 99 108 100 uhci_t *uhci_hc = malloc(sizeof(uhci_t)); 101 ret = (uhci_hc != NULL) ? EOK : ENOMEM; 102 CHECK_RET_RETURN(ret, "Failed to allocate memory for uhci hcd driver.\n"); 109 hcd = malloc(sizeof(uhci_t)); 110 ret = (hcd != NULL) ? EOK : ENOMEM; 111 CHECK_RET_FREE_HC_RETURN(ret, 112 "Failed(%d) to allocate memory for uhci hcd.\n", ret); 103 113 104 ret = uhci_init(uhci_hc, device, (void*)io_reg_base, io_reg_size); 105 if (ret != EOK) { 106 usb_log_error("Failed to init uhci-hcd.\n"); 107 free(uhci_hc); 108 return ret; 109 } 114 ret = uhci_init(hcd, device, (void*)io_reg_base, io_reg_size); 115 CHECK_RET_FREE_HC_RETURN(ret, "Failed(%d) to init uhci-hcd.\n", 116 ret); 117 #undef CHECK_RET_FREE_HC_RETURN 110 118 111 119 /* 112 * We might free uhci_hc, but that does not matter since no one120 * We might free hcd, but that does not matter since no one 113 121 * else would access driver_data anyway. 114 122 */ 115 device->driver_data = uhci_hc;123 device->driver_data = hcd; 116 124 125 ddf_fun_t *rh = NULL; 126 #define CHECK_RET_FINI_FREE_RETURN(ret, message...) \ 127 if (ret != EOK) { \ 128 usb_log_error(message); \ 129 if (hcd != NULL) {\ 130 uhci_fini(hcd); \ 131 free(hcd); \ 132 } \ 133 if (rh != NULL) \ 134 free(rh); \ 135 return ret; \ 136 } 137 138 /* It does no harm if we register this on polling */ 117 139 ret = register_interrupt_handler(device, irq, irq_handler, 118 &uhci_hc->interrupt_code); 119 if (ret != EOK) { 120 usb_log_error("Failed to register interrupt handler.\n"); 121 uhci_fini(uhci_hc); 122 free(uhci_hc); 123 return ret; 124 } 140 &hcd->interrupt_code); 141 CHECK_RET_FINI_FREE_RETURN(ret, 142 "Failed(%d) to register interrupt handler.\n", ret); 125 143 126 ddf_fun_t *rh;127 144 ret = setup_root_hub(&rh, device); 128 if (ret != EOK) { 129 usb_log_error("Failed to setup uhci root hub.\n"); 130 uhci_fini(uhci_hc); 131 free(uhci_hc); 132 return ret; 133 } 134 rh->driver_data = uhci_hc->ddf_instance; 145 CHECK_RET_FINI_FREE_RETURN(ret, 146 "Failed(%d) to setup UHCI root hub.\n", ret); 147 rh->driver_data = hcd->ddf_instance; 135 148 136 149 ret = ddf_fun_bind(rh); 137 if (ret != EOK) { 138 usb_log_error("Failed to register root hub.\n"); 139 uhci_fini(uhci_hc); 140 free(uhci_hc); 141 free(rh); 142 return ret; 143 } 150 CHECK_RET_FINI_FREE_RETURN(ret, 151 "Failed(%d) to register UHCI root hub.\n", ret); 144 152 145 153 return EOK; 154 #undef CHECK_RET_FINI_FREE_RETURN 146 155 } 147 156 /*----------------------------------------------------------------------------*/ … … 149 158 { 150 159 sleep(3); 151 usb_log_enable(USB_LOG_LEVEL_ INFO, NAME);160 usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME); 152 161 153 162 return ddf_driver_main(&uhci_driver);
Note:
See TracChangeset
for help on using the changeset viewer.