Changeset ef4e8eb in mainline for uspace/lib/usbdev/src/recognise.c
- Timestamp:
- 2013-01-15T20:39:09Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ef40434
- Parents:
- 918e1e84
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbdev/src/recognise.c
r918e1e84 ref4e8eb 37 37 #include <fibril_synch.h> 38 38 #include <usb/debug.h> 39 #include <usb/dev/hub.h>40 39 #include <usb/dev/pipes.h> 41 40 #include <usb/dev/recognise.h> … … 46 45 #include <errno.h> 47 46 #include <assert.h> 48 49 /** DDF operations of child devices. */50 static ddf_dev_ops_t child_ops = {51 .interfaces[USB_DEV_IFACE] = &usb_iface_hub_child_impl52 };53 47 54 48 /** Get integer part from BCD coded number. */ … … 295 289 } 296 290 297 /** Probe for device kind and register it in devman.298 *299 * @param[in] ctrl_pipe Control pipe to the device.300 * @param[in] parent Parent device.301 * @param[in] dev_ops Child device ops. Default child_ops will be used if NULL.302 * @param[in] dev_data Arbitrary pointer to be stored in the child303 * as @c driver_data.304 * @param[out] child_fun Storage where pointer to allocated child function305 * will be written.306 * @return Error code.307 *308 */309 int usb_device_register_child_in_devman(usb_pipe_t *ctrl_pipe,310 ddf_dev_t *parent, ddf_fun_t **child_fun)311 {312 if (child_fun == NULL || ctrl_pipe == NULL)313 return EINVAL;314 315 /** Index to append after device name for uniqueness. */316 static atomic_t device_name_index = {0};317 const size_t this_device_name_index =318 (size_t) atomic_preinc(&device_name_index);319 320 ddf_fun_t *child = NULL;321 int rc;322 323 /*324 * TODO: Once the device driver framework support persistent325 * naming etc., something more descriptive could be created.326 */327 char child_name[12]; /* The format is: "usbAB_aXYZ", length 11 */328 rc = snprintf(child_name, sizeof(child_name),329 "usb%02zu_a%d", this_device_name_index, ctrl_pipe->wire->address);330 if (rc < 0) {331 goto failure;332 }333 334 child = ddf_fun_create(parent, fun_inner, child_name);335 if (child == NULL) {336 rc = ENOMEM;337 goto failure;338 }339 340 ddf_fun_set_ops(child, &child_ops);341 /*342 * Store the attached device in fun343 * driver data if there is no other data344 */345 usb_hub_attached_device_t *new_device = ddf_fun_data_alloc(346 child, sizeof(usb_hub_attached_device_t));347 if (!new_device) {348 rc = ENOMEM;349 goto failure;350 }351 352 new_device->address = ctrl_pipe->wire->address;353 new_device->fun = child;354 355 match_id_list_t match_ids;356 init_match_ids(&match_ids);357 rc = usb_device_create_match_ids(ctrl_pipe, &match_ids);358 if (rc != EOK)359 goto failure;360 361 list_foreach(match_ids.ids, id_link) {362 match_id_t *match_id = list_get_instance(id_link, match_id_t, link);363 rc = ddf_fun_add_match_id(child, match_id->id, match_id->score);364 if (rc != EOK) {365 clean_match_ids(&match_ids);366 goto failure;367 }368 }369 370 clean_match_ids(&match_ids);371 372 rc = ddf_fun_bind(child);373 if (rc != EOK)374 goto failure;375 376 *child_fun = child;377 return EOK;378 379 failure:380 if (child != NULL) {381 /* This takes care of match_id deallocation as well. */382 ddf_fun_destroy(child);383 }384 385 return rc;386 }387 388 291 /** 389 292 * @}
Note:
See TracChangeset
for help on using the changeset viewer.