Changeset 243cb86 in mainline for uspace/drv/usbhub/utils.c
- Timestamp:
- 2010-12-12T10:50:19Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8365533
- Parents:
- 101ef25c (diff), ebb98c5 (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 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhub/utils.c
r101ef25c r243cb86 33 33 * @brief Hub driver. 34 34 */ 35 #include < usb/hcdhubd.h>35 #include <driver.h> 36 36 #include <usb/devreq.h> 37 37 #include <usbhc_iface.h> 38 #include <usb/usbdrv.h> 38 39 #include <usb/descriptor.h> 39 40 #include <driver.h> … … 41 42 #include <errno.h> 42 43 #include <usb/classes/hub.h> 43 #include " hcdhubd_private.h"44 #include "usbhub.h" 44 45 45 46 static void check_hub_changes(void); … … 108 109 //********************************************* 109 110 110 static void set_hub_address(usb_hc_device_t *hc, usb_address_t address);111 112 111 usb_hcd_hub_info_t * usb_create_hub_info(device_t * device) { 113 112 usb_hcd_hub_info_t* result = (usb_hcd_hub_info_t*) malloc(sizeof (usb_hcd_hub_info_t)); 114 //get parent device115 /// @TODO this code is not correct116 device_t * my_hcd = device;117 while (my_hcd->parent)118 my_hcd = my_hcd->parent;119 //dev->120 printf("%s: owner hcd found: %s\n", hc_driver->name, my_hcd->name);121 //we add the hub into the first hc122 //link_t *link_hc = hc_list.next;123 //usb_hc_device_t *hc = list_get_instance(link_hc,124 // usb_hc_device_t, link);125 //must get generic device info126 127 113 128 114 return result; … … 135 121 */ 136 122 int usb_add_hub_device(device_t *dev) { 137 usb_hc_device_t *hc = list_get_instance(hc_list.next, usb_hc_device_t, link); 138 set_hub_address(hc, 5); 123 printf(NAME ": add_hub_device(handle=%d)\n", (int) dev->handle); 139 124 140 125 check_hub_changes(); … … 145 130 * connected devices. 146 131 */ 147 //insert hub into list148 //find owner hcd149 device_t * my_hcd = dev;150 while (my_hcd->parent)151 my_hcd = my_hcd->parent;152 //dev->153 printf("%s: owner hcd found: %s\n", hc_driver->name, my_hcd->name);154 my_hcd = dev;155 while (my_hcd->parent)156 my_hcd = my_hcd->parent;157 //dev->158 159 printf("%s: owner hcd found: %s\n", hc_driver->name, my_hcd->name);160 132 161 133 //create the hub structure 162 134 usb_hcd_hub_info_t * hub_info = usb_create_hub_info(dev); 163 164 165 //append into the list 166 //we add the hub into the first hc 167 list_append(&hub_info->link, &hc->hubs); 168 169 135 (void)hub_info; 170 136 171 137 return EOK; … … 173 139 } 174 140 175 /** Sample usage of usb_hc_async functions.176 * This function sets hub address using standard SET_ADDRESS request.177 *178 * @warning This function shall be removed once you are familiar with179 * the usb_hc_ API.180 *181 * @param hc Host controller the hub belongs to.182 * @param address New hub address.183 */184 static void set_hub_address(usb_hc_device_t *hc, usb_address_t address) {185 printf("%s: setting hub address to %d\n", hc->generic->name, address);186 usb_target_t target = {0, 0};187 usb_handle_t handle;188 int rc;189 190 usb_device_request_setup_packet_t setup_packet = {191 .request_type = 0,192 .request = USB_DEVREQ_SET_ADDRESS,193 .index = 0,194 .length = 0,195 };196 setup_packet.value = address;197 198 rc = usb_hc_async_control_write_setup(hc, target,199 &setup_packet, sizeof (setup_packet), &handle);200 if (rc != EOK) {201 return;202 }203 204 rc = usb_hc_async_wait_for(handle);205 if (rc != EOK) {206 return;207 }208 209 rc = usb_hc_async_control_write_status(hc, target, &handle);210 if (rc != EOK) {211 return;212 }213 214 rc = usb_hc_async_wait_for(handle);215 if (rc != EOK) {216 return;217 }218 219 printf("%s: hub address changed\n", hc->generic->name);220 }221 141 222 142 /** Check changes on all known hubs. … … 224 144 static void check_hub_changes(void) { 225 145 /* 226 * Iterate through all HCs.146 * Iterate through all hubs. 227 147 */ 228 link_t *link_hc; 229 for (link_hc = hc_list.next; 230 link_hc != &hc_list; 231 link_hc = link_hc->next) { 232 usb_hc_device_t *hc = list_get_instance(link_hc, 233 usb_hc_device_t, link); 234 /* 235 * Iterate through all their hubs. 236 */ 237 link_t *link_hub; 238 for (link_hub = hc->hubs.next; 239 link_hub != &hc->hubs; 240 link_hub = link_hub->next) { 241 usb_hcd_hub_info_t *hub = list_get_instance(link_hub, 242 usb_hcd_hub_info_t, link); 243 244 /* 245 * Check status change pipe of this hub. 246 */ 247 usb_target_t target = { 248 .address = hub->device->address, 249 .endpoint = 1 250 }; 251 252 // FIXME: count properly 253 size_t byte_length = (hub->port_count / 8) + 1; 254 255 void *change_bitmap = malloc(byte_length); 256 size_t actual_size; 257 usb_handle_t handle; 258 259 /* 260 * Send the request. 261 * FIXME: check returned value for possible errors 262 */ 263 usb_hc_async_interrupt_in(hc, target, 264 change_bitmap, byte_length, &actual_size, 265 &handle); 266 267 usb_hc_async_wait_for(handle); 268 269 /* 270 * TODO: handle the changes. 271 */ 148 for (; false; ) { 149 /* 150 * Check status change pipe of this hub. 151 */ 152 usb_target_t target = { 153 .address = 5, 154 .endpoint = 1 155 }; 156 157 size_t port_count = 7; 158 159 /* 160 * Connect to respective HC. 161 */ 162 int hc = usb_drv_hc_connect(NULL, 0); 163 if (hc < 0) { 164 continue; 272 165 } 166 167 // FIXME: count properly 168 size_t byte_length = (port_count / 8) + 1; 169 170 void *change_bitmap = malloc(byte_length); 171 size_t actual_size; 172 usb_handle_t handle; 173 174 /* 175 * Send the request. 176 * FIXME: check returned value for possible errors 177 */ 178 usb_drv_async_interrupt_in(hc, target, 179 change_bitmap, byte_length, &actual_size, 180 &handle); 181 182 usb_drv_async_wait_for(handle); 183 184 /* 185 * TODO: handle the changes. 186 */ 187 188 /* 189 * WARNING: sample code, will not work out of the box. 190 * And does not contain code for checking for errors. 191 */ 192 #if 0 193 /* 194 * Before opening the port, we must acquire the default 195 * address. 196 */ 197 usb_drv_reserve_default_address(hc); 198 199 usb_address_t new_device_address = usb_drv_request_address(hc); 200 201 // TODO: open the port 202 203 // TODO: send request for setting address to new_device_address 204 205 /* 206 * Once new address is set, we can release the default 207 * address. 208 */ 209 usb_drv_release_default_address(hc); 210 211 /* 212 * Obtain descriptors and create match ids for devman. 213 */ 214 215 // TODO: get device descriptors 216 217 // TODO: create match ids 218 219 // TODO: add child device 220 221 // child_device_register sets the device handle 222 // TODO: store it here 223 devman_handle_t new_device_handle = 0; 224 225 /* 226 * Inform the HC that the new device has devman handle 227 * assigned. 228 */ 229 usb_drv_bind_address(hc, new_device_address, new_device_handle); 230 231 /* 232 * That's all. 233 */ 234 #endif 235 236 237 /* 238 * Hang-up the HC-connected phone. 239 */ 240 ipc_hangup(hc); 273 241 } 274 242 }
Note:
See TracChangeset
for help on using the changeset viewer.