Changeset b995183 in mainline
- Timestamp:
- 2013-01-06T16:19:33Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e938fa6
- Parents:
- be554d9
- Location:
- uspace/lib/usbhost
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/include/usb/host/ddf_helpers.h
rbe554d9 rb995183 46 46 usb_speed_t max_speed, size_t bw, bw_count_func_t bw_count); 47 47 int hcd_ddf_setup_root_hub(ddf_dev_t *dev, usb_speed_t speed); 48 int hcd_ddf_new_device(ddf_dev_t *device); 48 int hcd_ddf_new_device(ddf_dev_t *device, usb_address_t *address); 49 int hcd_ddf_remove_device(ddf_dev_t *device, usb_address_t address); 49 50 50 51 hcd_t *dev_to_hcd(ddf_dev_t *dev); -
uspace/lib/usbhost/src/ddf_helpers.c
rbe554d9 rb995183 51 51 ddf_fun_t *hc_fun; 52 52 list_t devices; 53 fibril_mutex_t guard; 53 54 } hc_dev_t; 54 55 … … 73 74 usb_address_t address; 74 75 usb_speed_t speed; 75 devman_handle_t h andle;76 devman_handle_t hc_handle; 76 77 } usb_dev_t; 77 78 … … 82 83 * @return Error code. 83 84 */ 84 static int rh_get_my_address(ddf_fun_t *fun, usb_address_t *address)85 static int get_my_address(ddf_fun_t *fun, usb_address_t *address) 85 86 { 86 87 assert(fun); … … 98 99 * @return Error code. 99 100 */ 100 static int rh_get_hc_handle(ddf_fun_t *fun, devman_handle_t *handle)101 static int get_hc_handle(ddf_fun_t *fun, devman_handle_t *handle) 101 102 { 102 103 assert(fun); … … 104 105 if (handle != NULL) { 105 106 usb_dev_t *usb_dev = ddf_fun_data_get(fun); 106 *handle = usb_dev->h andle;107 *handle = usb_dev->hc_handle; 107 108 } 108 109 return EOK; … … 111 112 /** Root hub USB interface */ 112 113 static usb_iface_t usb_iface = { 113 .get_hc_handle = rh_get_hc_handle,114 .get_my_address = rh_get_my_address,114 .get_hc_handle = get_hc_handle, 115 .get_my_address = get_my_address, 115 116 }; 116 117 /** Standard USB RH options (RH interface) */ … … 146 147 }; 147 148 148 static const usb_device_request_setup_packet_t set_address = {149 .request_type = SETUP_REQUEST_TYPE_DEVICE_TO_HOST150 | (USB_REQUEST_TYPE_STANDARD << 5)151 | USB_REQUEST_RECIPIENT_DEVICE,152 .request = USB_DEVREQ_GET_DESCRIPTOR,153 .value = uint16_host2usb(USB_DESCTYPE_DEVICE << 8),154 .index = uint16_host2usb(0),155 .length = uint16_host2usb(CTRL_PIPE_MIN_PACKET_SIZE),156 };157 158 149 int hcd_ddf_add_usb_device(ddf_dev_t *parent, 159 150 usb_address_t address, usb_speed_t speed, const char *name, … … 182 173 info->address = address; 183 174 info->speed = speed; 184 info->h andle = hc_handle;175 info->hc_handle = hc_handle; 185 176 info->fun = fun; 186 177 link_initialize(&info->link); … … 207 198 return EOK; 208 199 } 209 210 200 211 201 #define ADD_MATCHID_OR_RETURN(list, sc, str, ...) \ … … 227 217 add_match_id(list, mid); \ 228 218 } while (0) 229 219 230 220 231 221 /* This is a copy of lib/usbdev/src/recognise.c */ … … 259 249 } 260 250 261 int hcd_ddf_ new_device(ddf_dev_t *device)251 int hcd_ddf_remove_device(ddf_dev_t *device, usb_address_t id) 262 252 { 263 253 assert(device); … … 265 255 hcd_t *hcd = dev_to_hcd(device); 266 256 assert(hcd); 267 257 258 hc_dev_t *hc_dev = dev_to_hc_dev(device); 259 assert(hc_dev); 260 261 fibril_mutex_lock(&hc_dev->guard); 262 263 usb_dev_t *victim = NULL; 264 265 list_foreach(hc_dev->devices, it) { 266 victim = list_get_instance(it, usb_dev_t, link); 267 if (victim->address == id) 268 break; 269 } 270 if (victim && victim->address == id) { 271 list_remove(&victim->link); 272 fibril_mutex_unlock(&hc_dev->guard); 273 ddf_fun_unbind(victim->fun); 274 ddf_fun_destroy(victim->fun); 275 return EOK; 276 } 277 return ENOENT; 278 } 279 280 int hcd_ddf_new_device(ddf_dev_t *device, usb_address_t *id) 281 { 282 assert(device); 283 284 hcd_t *hcd = dev_to_hcd(device); 285 assert(hcd); 286 268 287 usb_speed_t speed = USB_SPEED_MAX; 269 288 … … 329 348 SET_ADDRESS(target.address); 330 349 331 // TODO CALLBACKS332 350 got = hcd_send_batch_sync(hcd, default_target, USB_DIRECTION_OUT, 333 351 NULL, 0, *(uint64_t *)&set_address, "set address"); … … 345 363 GET_DEVICE_DESC(sizeof(desc)); 346 364 347 // TODO CALLBACKS348 365 got = hcd_send_batch_sync(hcd, target, USB_DIRECTION_IN, 349 366 &desc, sizeof(desc), *(uint64_t *)&get_device_desc, … … 354 371 return got < 0 ? got : EOVERFLOW; 355 372 } 356 373 357 374 /* Create match ids from the device descriptor */ 358 375 match_id_list_t mids; … … 365 382 return ret; 366 383 } 367 368 369 370 /* Register device */ 384 385 /* Register device */ 371 386 ret = hcd_ddf_add_usb_device(device, address, speed, NULL, &mids); 372 387 clean_match_ids(&mids); … … 376 391 return ret; 377 392 } 393 if (ret == EOK && id) 394 *id = target.address; 378 395 379 396 return ret; … … 393 410 394 411 hcd_reserve_default_address(hcd, speed); 395 const int ret = hcd_ddf_new_device(device );412 const int ret = hcd_ddf_new_device(device, NULL); 396 413 hcd_release_default_address(hcd); 397 414 return ret; … … 416 433 } 417 434 list_initialize(&instance->devices); 435 fibril_mutex_initialize(&instance->guard); 418 436 419 437 #define CHECK_RET_DEST_FREE_RETURN(ret, message...) \
Note:
See TracChangeset
for help on using the changeset viewer.