Changeset d930980 in mainline
- Timestamp:
- 2013-07-07T12:11:35Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 30c1b75
- Parents:
- c53007f
- Location:
- uspace/drv/bus/usb
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/ehci/main.c
rc53007f rd930980 33 33 * Main routines of EHCI driver. 34 34 */ 35 35 36 #include <ddf/driver.h> 36 37 #include <ddf/interrupt.h> 37 38 #include <device/hw_res.h> 38 39 #include <errno.h> 40 #include <stdbool.h> 39 41 #include <str_error.h> 40 42 … … 70 72 static int ehci_dev_add(ddf_dev_t *device) 71 73 { 74 ddf_fun_t *hc_fun = NULL; 75 bool fun_bound = false; 76 72 77 assert(device); 73 #define CHECK_RET_RETURN(ret, message...) \74 if (ret != EOK) { \75 usb_log_error(message); \76 return ret; \77 }78 78 79 79 uintptr_t reg_base = 0; … … 81 81 int irq = 0; 82 82 83 int ret = get_my_registers(device, ®_base, ®_size, &irq); 84 CHECK_RET_RETURN(ret, 85 "Failed to get memory addresses for %" PRIun ": %s.\n", 86 ddf_dev_get_handle(device), str_error(ret)); 83 int rc = get_my_registers(device, ®_base, ®_size, &irq); 84 if (rc != EOK) { 85 usb_log_error("Failed to get memory addresses for %" PRIun 86 ": %s.\n", ddf_dev_get_handle(device), str_error(rc)); 87 goto error; 88 } 89 87 90 usb_log_info("Memory mapped regs at 0x%" PRIxn " (size %zu), IRQ %d.\n", 88 91 reg_base, reg_size, irq); 89 92 90 ret = disable_legacy(device, reg_base, reg_size); 91 CHECK_RET_RETURN(ret, 92 "Failed to disable legacy USB: %s.\n", str_error(ret)); 93 rc = disable_legacy(device, reg_base, reg_size); 94 if (rc != EOK) { 95 usb_log_error("Failed to disable legacy USB: %s.\n", 96 str_error(rc)); 97 goto error; 98 } 93 99 94 ddf_fun_t *hc_fun = ddf_fun_create(device, fun_exposed, "ehci_hc");100 hc_fun = ddf_fun_create(device, fun_exposed, "ehci_hc"); 95 101 if (hc_fun == NULL) { 96 102 usb_log_error("Failed to create EHCI function.\n"); 97 return ENOMEM; 103 rc = ENOMEM; 104 goto error; 98 105 } 106 99 107 hcd_t *ehci_hc = ddf_fun_data_alloc(hc_fun, sizeof(hcd_t)); 100 108 if (ehci_hc == NULL) { 101 109 usb_log_error("Failed to alloc generic HC driver.\n"); 102 return ENOMEM; 110 rc = ENOMEM; 111 goto error; 103 112 } 113 104 114 /* High Speed, no bandwidth */ 105 115 hcd_init(ehci_hc, USB_SPEED_HIGH, 0, NULL); 106 116 ddf_fun_set_ops(hc_fun, &hc_ops); 107 117 108 ret = ddf_fun_bind(hc_fun); 109 CHECK_RET_RETURN(ret, 110 "Failed to bind EHCI function: %s.\n", 111 str_error(ret)); 112 ret = ddf_fun_add_to_category(hc_fun, USB_HC_CATEGORY); 113 CHECK_RET_RETURN(ret, 114 "Failed to add EHCI to HC class: %s.\n", 115 str_error(ret)); 118 rc = ddf_fun_bind(hc_fun); 119 if (rc != EOK) { 120 usb_log_error("Failed to bind EHCI function: %s.\n", 121 str_error(rc)); 122 goto error; 123 } 124 125 fun_bound = true; 126 127 rc = ddf_fun_add_to_category(hc_fun, USB_HC_CATEGORY); 128 if (rc != EOK) { 129 usb_log_error("Failed to add EHCI to HC class: %s.\n", 130 str_error(rc)); 131 goto error; 132 } 116 133 117 134 usb_log_info("Controlling new EHCI device `%s' (handle %" PRIun ").\n", … … 119 136 120 137 return EOK; 121 #undef CHECK_RET_RETURN 138 error: 139 if (fun_bound) 140 ddf_fun_unbind(hc_fun); 141 if (hc_fun != NULL) 142 ddf_fun_destroy(hc_fun); 143 return rc; 122 144 } 123 145 -
uspace/drv/bus/usb/ehci/res.c
rc53007f rd930980 145 145 return ENOMEM; 146 146 147 #define CHECK_RET_HANGUP_RETURN(ret, message...) \148 if (ret != EOK) { \149 usb_log_error(message); \150 async_hangup(parent_sess); \151 return ret; \152 } else (void)0153 154 147 /* Read the first EEC. i.e. Legacy Support register */ 155 148 uint32_t usblegsup; 156 int r et= pci_config_space_read_32(parent_sess,149 int rc = pci_config_space_read_32(parent_sess, 157 150 eecp + USBLEGSUP_OFFSET, &usblegsup); 158 CHECK_RET_HANGUP_RETURN(ret, 159 "Failed to read USBLEGSUP: %s.\n", str_error(ret)); 151 if (rc != EOK) { 152 usb_log_error("Failed to read USBLEGSUP: %s.\n", 153 str_error(rc)); 154 goto error; 155 } 156 160 157 usb_log_debug("USBLEGSUP: %" PRIx32 ".\n", usblegsup); 161 158 … … 163 160 * byte. (OS Control semaphore)*/ 164 161 usb_log_debug("Requesting OS control.\n"); 165 r et= pci_config_space_write_8(parent_sess,162 rc = pci_config_space_write_8(parent_sess, 166 163 eecp + USBLEGSUP_OFFSET + 3, 1); 167 CHECK_RET_HANGUP_RETURN(ret, "Failed to request OS EHCI control: %s.\n", 168 str_error(ret)); 164 if (rc != EOK) { 165 usb_log_error("Failed to request OS EHCI control: %s.\n", 166 str_error(rc)); 167 goto error; 168 } 169 169 170 170 size_t wait = 0; 171 171 /* Wait for BIOS to release control. */ 172 r et= pci_config_space_read_32(172 rc = pci_config_space_read_32( 173 173 parent_sess, eecp + USBLEGSUP_OFFSET, &usblegsup); 174 if (rc != EOK) { 175 usb_log_error("Failed reading PCI config space: %s.\n", 176 str_error(rc)); 177 goto error; 178 } 179 174 180 while ((wait < DEFAULT_WAIT) && (usblegsup & USBLEGSUP_BIOS_CONTROL)) { 175 181 async_usleep(WAIT_STEP); 176 r et= pci_config_space_read_32(parent_sess,182 rc = pci_config_space_read_32(parent_sess, 177 183 eecp + USBLEGSUP_OFFSET, &usblegsup); 184 if (rc != EOK) { 185 usb_log_error("Failed reading PCI config space: %s.\n", 186 str_error(rc)); 187 goto error; 188 } 178 189 wait += WAIT_STEP; 179 190 } … … 188 199 usb_log_warning( "BIOS failed to release control after " 189 200 "%zu usecs, force it.\n", wait); 190 r et= pci_config_space_write_32(parent_sess,201 rc = pci_config_space_write_32(parent_sess, 191 202 eecp + USBLEGSUP_OFFSET, USBLEGSUP_OS_CONTROL); 192 CHECK_RET_HANGUP_RETURN(ret, "Failed to force OS control: " 193 "%s.\n", str_error(ret)); 203 if (rc != EOK) { 204 usb_log_error("Failed to force OS control: " 205 "%s.\n", str_error(rc)); 206 goto error; 207 } 208 194 209 /* 195 210 * Check capability type here, value of 01h identifies the capability … … 201 216 /* Read the second EEC Legacy Support and Control register */ 202 217 uint32_t usblegctlsts; 203 r et= pci_config_space_read_32(parent_sess,218 rc = pci_config_space_read_32(parent_sess, 204 219 eecp + USBLEGCTLSTS_OFFSET, &usblegctlsts); 205 CHECK_RET_HANGUP_RETURN(ret, "Failed to get USBLEGCTLSTS: %s.\n", 206 str_error(ret)); 220 if (rc != EOK) { 221 usb_log_error("Failed to get USBLEGCTLSTS: %s.\n", 222 str_error(rc)); 223 goto error; 224 } 225 207 226 usb_log_debug("USBLEGCTLSTS: %" PRIx32 ".\n", usblegctlsts); 208 227 /* … … 211 230 * interfering. NOTE: Three upper bits are WC 212 231 */ 213 r et= pci_config_space_write_32(parent_sess,232 rc = pci_config_space_write_32(parent_sess, 214 233 eecp + USBLEGCTLSTS_OFFSET, 0xe0000000); 215 CHECK_RET_HANGUP_RETURN(ret, "Failed(%d) zero USBLEGCTLSTS.\n", ret); 234 if (rc != EOK) { 235 usb_log_error("Failed(%d) zero USBLEGCTLSTS.\n", rc); 236 goto error; 237 } 238 216 239 udelay(10); 217 r et= pci_config_space_read_32(parent_sess,240 rc = pci_config_space_read_32(parent_sess, 218 241 eecp + USBLEGCTLSTS_OFFSET, &usblegctlsts); 219 CHECK_RET_HANGUP_RETURN(ret, "Failed to get USBLEGCTLSTS 2: %s.\n", 220 str_error(ret)); 242 if (rc != EOK) { 243 usb_log_error("Failed to get USBLEGCTLSTS 2: %s.\n", 244 str_error(rc)); 245 goto error; 246 } 247 221 248 usb_log_debug("Zeroed USBLEGCTLSTS: %" PRIx32 ".\n", 222 249 usblegctlsts); … … 224 251 225 252 /* Read again Legacy Support register */ 226 r et= pci_config_space_read_32(parent_sess,253 rc = pci_config_space_read_32(parent_sess, 227 254 eecp + USBLEGSUP_OFFSET, &usblegsup); 228 CHECK_RET_HANGUP_RETURN(ret, "Failed to read USBLEGSUP: %s.\n", 229 str_error(ret)); 255 if (rc != EOK) { 256 usb_log_error("Failed to read USBLEGSUP: %s.\n", 257 str_error(rc)); 258 goto error; 259 } 260 230 261 usb_log_debug("USBLEGSUP: %" PRIx32 ".\n", usblegsup); 231 262 async_hangup(parent_sess); 232 263 return EOK; 233 #undef CHECK_RET_HANGUP_RETURN 264 error: 265 async_hangup(parent_sess); 266 return rc; 234 267 } 235 268 … … 239 272 usb_log_debug("Disabling EHCI legacy support.\n"); 240 273 241 #define CHECK_RET_RETURN(ret, message...) \242 if (ret != EOK) { \243 usb_log_error(message); \244 return ret; \245 } else (void)0246 247 274 /* Map EHCI registers */ 248 275 void *regs = NULL; 249 int ret = pio_enable((void*)reg_base, reg_size, ®s); 250 CHECK_RET_RETURN(ret, "Failed to map registers %p: %s.\n", 251 (void *) reg_base, str_error(ret)); 276 int rc = pio_enable((void*)reg_base, reg_size, ®s); 277 if (rc != EOK) { 278 usb_log_error("Failed to map registers %p: %s.\n", 279 (void *) reg_base, str_error(rc)); 280 return rc; 281 } 252 282 253 283 usb_log_debug2("Registers mapped at: %p.\n", regs); … … 263 293 usb_log_debug("Value of EECP: %x.\n", eecp); 264 294 265 ret = disable_extended_caps(device, eecp); 266 CHECK_RET_RETURN(ret, "Failed to disable extended capabilities: %s.\n", 267 str_error(ret)); 268 269 #undef CHECK_RET_RETURN 295 rc = disable_extended_caps(device, eecp); 296 if (rc != EOK) { 297 usb_log_error("Failed to disable extended capabilities: %s.\n", 298 str_error(rc)); 299 return rc; 300 } 270 301 271 302 /* … … 306 337 usbcmd, *usbcmd, usbsts, *usbsts, usbint, *usbint, usbconf,*usbconf); 307 338 308 return r et;339 return rc; 309 340 } 310 341 -
uspace/drv/bus/usb/uhci/hc.c
rc53007f rd930980 430 430 431 431 return EOK; 432 #undef CHECK_RET_CLEAR_RETURN433 432 } 434 433
Note:
See TracChangeset
for help on using the changeset viewer.