Changeset 9c7ed9c in mainline
- Timestamp:
- 2012-12-16T21:42:20Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 21be46a
- Parents:
- 5994cc3
- Location:
- uspace/lib/usbhost
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/include/usb/host/hcd.h
r5994cc3 r9c7ed9c 38 38 39 39 #include <assert.h> 40 #include <adt/list.h> 40 41 #include <usbhc_iface.h> 41 42 … … 56 57 /** Endpoint manager. */ 57 58 usb_endpoint_manager_t ep_manager; 59 /** Added devices */ 60 list_t devices; 58 61 59 62 /** Device specific driver data. */ … … 80 83 usb_device_manager_init(&hcd->dev_manager, max_speed); 81 84 usb_endpoint_manager_init(&hcd->ep_manager, bandwidth, bw_count); 85 list_initialize(&hcd->devices); 86 82 87 hcd->private_data = NULL; 83 88 hcd->schedule = NULL; … … 110 115 } 111 116 117 118 int hcd_add_device(hcd_t *instance, ddf_dev_t *parent, 119 usb_address_t address, usb_speed_t speed, const char *name, 120 const match_id_list_t *mids); 121 112 122 int hcd_setup_device(ddf_dev_t *device); 113 123 int hcd_setup_hub(hcd_t *instance, usb_address_t *address, ddf_dev_t *dev); -
uspace/lib/usbhost/src/hcd.c
r5994cc3 r9c7ed9c 43 43 typedef struct hc_dev { 44 44 ddf_fun_t *hc_fun; 45 ddf_fun_t *rh_fun;46 45 } hc_dev_t; 47 46 … … 62 61 63 62 typedef struct usb_dev { 63 link_t link; 64 ddf_fun_t *fun; 64 65 usb_address_t address; 65 66 usb_speed_t speed; … … 106 107 }; 107 108 /** Standard USB RH options (RH interface) */ 108 static ddf_dev_ops_t rh_ops = {109 static ddf_dev_ops_t usb_ops = { 109 110 .interfaces[USB_DEV_IFACE] = &usb_iface, 110 111 }; … … 115 116 }; 116 117 118 int hcd_add_device(hcd_t *instance, ddf_dev_t *parent, 119 usb_address_t address, usb_speed_t speed, const char *name, 120 const match_id_list_t *mids) 121 { 122 assert(instance); 123 assert(parent); 124 hc_dev_t *hc_dev = ddf_dev_data_get(parent); 125 devman_handle_t hc_handle = ddf_fun_get_handle(hc_dev->hc_fun); 126 127 //TODO more checks 128 ddf_fun_t *fun = ddf_fun_create(parent, fun_inner, name); 129 if (!fun) 130 return ENOMEM; 131 usb_dev_t *info = ddf_fun_data_alloc(fun, sizeof(usb_dev_t)); 132 if (!info) { 133 ddf_fun_destroy(fun); 134 return ENOMEM; 135 } 136 info->address = address; 137 info->speed = speed; 138 info->handle = hc_handle; 139 info->fun = fun; 140 link_initialize(&info->link); 141 142 ddf_fun_set_ops(fun, &usb_ops); 143 list_foreach(mids->ids, iter) { 144 match_id_t *mid = list_get_instance(iter, match_id_t, link); 145 ddf_fun_add_match_id(fun, mid->id, mid->score); 146 } 147 148 int ret = ddf_fun_bind(fun); 149 if (ret != EOK) { 150 ddf_fun_destroy(fun); 151 return ret; 152 } 153 154 ret = usb_device_manager_bind_address(&instance->dev_manager, 155 address, ddf_fun_get_handle(fun)); 156 if (ret != EOK) 157 usb_log_warning("Failed to bind root hub address: %s.\n", 158 str_error(ret)); 159 160 list_append(&info->link, &instance->devices); 161 return EOK; 162 } 163 117 164 /** Announce root hub to the DDF 118 165 * … … 126 173 assert(address); 127 174 assert(device); 128 129 hc_dev_t *hc_dev = ddf_dev_data_get(device);130 hc_dev->rh_fun = ddf_fun_create(device, fun_inner, "rh");131 if (!hc_dev->rh_fun)132 return ENOMEM;133 usb_dev_t *rh = ddf_fun_data_alloc(hc_dev->rh_fun, sizeof(usb_dev_t));134 if (!rh) {135 ddf_fun_destroy(hc_dev->rh_fun);136 return ENOMEM;137 }138 139 175 140 176 int ret = usb_device_manager_request_address(&instance->dev_manager, … … 143 179 usb_log_error("Failed to get root hub address: %s\n", 144 180 str_error(ret)); 145 ddf_fun_destroy(hc_dev->rh_fun);146 181 return ret; 147 182 } 148 149 rh->address = *address;150 rh->speed = USB_SPEED_FULL;151 rh->handle = ddf_fun_get_handle(hc_dev->hc_fun);152 153 ddf_fun_set_ops(hc_dev->rh_fun, &rh_ops);154 183 155 184 #define CHECK_RET_UNREG_RETURN(ret, message...) \ … … 161 190 usb_device_manager_release_address( \ 162 191 &instance->dev_manager, *address); \ 163 ddf_fun_destroy(hc_dev->rh_fun); \164 192 return ret; \ 165 193 } else (void)0 … … 170 198 0, NULL, NULL); 171 199 CHECK_RET_UNREG_RETURN(ret, 172 "Failed to register root hub control endpoint: %s.\n", 173 str_error(ret)); 174 175 ret = ddf_fun_add_match_id(hc_dev->rh_fun, "usb&class=hub", 100); 200 "Failed to add root hub control endpoint: %s.\n", str_error(ret)); 201 202 match_id_t mid = { .id = "usb&class=hub", .score = 100 }; 203 link_initialize(&mid.link); 204 match_id_list_t mid_list; 205 init_match_ids(&mid_list); 206 add_match_id(&mid_list, &mid); 207 208 ret = hcd_add_device( 209 instance, device, *address, USB_SPEED_FULL, "rh", &mid_list); 176 210 CHECK_RET_UNREG_RETURN(ret, 177 "Failed to add root hub match-id: %s.\n", str_error(ret)); 178 179 ret = ddf_fun_bind(hc_dev->rh_fun); 180 CHECK_RET_UNREG_RETURN(ret, 181 "Failed to bind root hub function: %s.\n", str_error(ret)); 182 183 ret = usb_device_manager_bind_address(&instance->dev_manager, 184 *address, ddf_fun_get_handle(hc_dev->rh_fun)); 185 if (ret != EOK) 186 usb_log_warning("Failed to bind root hub address: %s.\n", 187 str_error(ret)); 188 211 "Failed to add hcd device: %s.\n", str_error(ret)); 189 212 190 213 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.