Changeset b4b534ac in mainline for uspace/lib/usbdev/src/recognise.c
- Timestamp:
- 2016-07-22T08:24:47Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f76d2c2
- Parents:
- 5b18137 (diff), 8351f9a4 (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/lib/usbdev/src/recognise.c
r5b18137 rb4b534ac 34 34 */ 35 35 36 #include <sys/types.h>37 #include <fibril_synch.h>38 #include <usb/debug.h>39 #include <usb/dev/hub.h>40 36 #include <usb/dev/pipes.h> 41 37 #include <usb/dev/recognise.h> 42 #include <usb/ddfiface.h>43 38 #include <usb/dev/request.h> 44 39 #include <usb/classes/classes.h> 40 41 #include <assert.h> 42 #include <errno.h> 45 43 #include <stdio.h> 46 #include <errno.h> 47 #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_impl 52 }; 44 #include <sys/types.h> 53 45 54 46 /** Get integer part from BCD coded number. */ … … 242 234 (int) device_descriptor->product_id, 243 235 BCD_ARGS(device_descriptor->device_version)); 244 236 245 237 /* Next, without release number. */ 246 238 ADD_MATCHID_OR_RETURN(matches, 90, … … 248 240 (int) device_descriptor->vendor_id, 249 241 (int) device_descriptor->product_id); 250 } 251 252 /* 253 * If the device class points to interface we skip adding 254 * class directly but we add a multi interface device. 255 */ 256 if (device_descriptor->device_class != USB_CLASS_USE_INTERFACE) { 257 ADD_MATCHID_OR_RETURN(matches, 50, "usb&class=%s", 258 usb_str_class(device_descriptor->device_class)); 259 } else { 260 ADD_MATCHID_OR_RETURN(matches, 50, "usb&mid"); 261 } 262 242 } 243 244 /* Class match id */ 245 ADD_MATCHID_OR_RETURN(matches, 50, "usb&class=%s", 246 usb_str_class(device_descriptor->device_class)); 247 263 248 /* As a last resort, try fallback driver. */ 264 249 ADD_MATCHID_OR_RETURN(matches, 10, "usb&fallback"); … … 302 287 } 303 288 304 /** Probe for device kind and register it in devman.305 *306 * @param[in] ctrl_pipe Control pipe to the device.307 * @param[in] parent Parent device.308 * @param[in] dev_ops Child device ops. Default child_ops will be used if NULL.309 * @param[in] dev_data Arbitrary pointer to be stored in the child310 * as @c driver_data.311 * @param[out] child_fun Storage where pointer to allocated child function312 * will be written.313 * @return Error code.314 *315 */316 int usb_device_register_child_in_devman(usb_pipe_t *ctrl_pipe,317 ddf_dev_t *parent, ddf_fun_t *fun, ddf_dev_ops_t *dev_ops)318 {319 if (ctrl_pipe == NULL)320 return EINVAL;321 322 if (!dev_ops && ddf_fun_data_get(fun) != NULL) {323 usb_log_warning("Using standard fun ops with arbitrary "324 "driver data. This does not have to work.\n");325 }326 327 /** Index to append after device name for uniqueness. */328 static atomic_t device_name_index = {0};329 const size_t this_device_name_index =330 (size_t) atomic_preinc(&device_name_index);331 332 int rc;333 334 /*335 * TODO: Once the device driver framework support persistent336 * naming etc., something more descriptive could be created.337 */338 char child_name[12]; /* The format is: "usbAB_aXYZ", length 11 */339 rc = snprintf(child_name, sizeof(child_name),340 "usb%02zu_a%d", this_device_name_index, ctrl_pipe->wire->address);341 if (rc < 0) {342 goto failure;343 }344 345 rc = ddf_fun_set_name(fun, child_name);346 if (rc != EOK)347 goto failure;348 349 if (dev_ops != NULL)350 ddf_fun_set_ops(fun, dev_ops);351 else352 ddf_fun_set_ops(fun, &child_ops);353 354 /*355 * Store the attached device in fun356 * driver data if there is no other data357 */358 if (ddf_fun_data_get(fun) == NULL) {359 usb_hub_attached_device_t *new_device = ddf_fun_data_alloc(360 fun, sizeof(usb_hub_attached_device_t));361 if (!new_device) {362 rc = ENOMEM;363 goto failure;364 }365 366 new_device->address = ctrl_pipe->wire->address;367 new_device->fun = fun;368 }369 370 match_id_list_t match_ids;371 init_match_ids(&match_ids);372 rc = usb_device_create_match_ids(ctrl_pipe, &match_ids);373 if (rc != EOK)374 goto failure;375 376 list_foreach(match_ids.ids, link, match_id_t, match_id) {377 rc = ddf_fun_add_match_id(fun, match_id->id, match_id->score);378 if (rc != EOK) {379 clean_match_ids(&match_ids);380 goto failure;381 }382 }383 384 clean_match_ids(&match_ids);385 386 rc = ddf_fun_bind(fun);387 if (rc != EOK)388 goto failure;389 390 return EOK;391 392 failure:393 return rc;394 }395 396 289 /** 397 290 * @}
Note:
See TracChangeset
for help on using the changeset viewer.