Changeset 4317827 in mainline for uspace/drv/usbhub/utils.c
- Timestamp:
- 2010-12-04T14:00:41Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 36c410e
- Parents:
- 62c9661
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhub/utils.c
r62c9661 r4317827 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 static void set_hub_address(device_t *dev, usb_address_t address); 111 112 112 113 usb_hcd_hub_info_t * usb_create_hub_info(device_t * device) { 113 114 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 115 128 116 return result; … … 135 123 */ 136 124 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);125 printf(NAME ": add_hub_device(handle=%d)\n", (int) dev->handle); 126 set_hub_address(dev, 5); 139 127 140 128 check_hub_changes(); … … 145 133 * connected devices. 146 134 */ 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 135 161 136 //create the hub structure 162 137 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 138 (void)hub_info; 170 139 171 140 return EOK; … … 182 151 * @param address New hub address. 183 152 */ 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);153 static void set_hub_address(device_t *dev, usb_address_t address) { 154 printf(NAME ": setting hub address to %d\n", address); 186 155 usb_target_t target = {0, 0}; 187 156 usb_handle_t handle; … … 196 165 setup_packet.value = address; 197 166 198 rc = usb_hc_async_control_write_setup(hc, target, 167 int hc = usb_drv_hc_connect(dev, 0); 168 169 rc = usb_drv_async_control_write_setup(hc, target, 199 170 &setup_packet, sizeof (setup_packet), &handle); 200 171 if (rc != EOK) { … … 202 173 } 203 174 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);175 rc = usb_drv_async_wait_for(handle); 176 if (rc != EOK) { 177 return; 178 } 179 180 rc = usb_drv_async_control_write_status(hc, target, &handle); 181 if (rc != EOK) { 182 return; 183 } 184 185 rc = usb_drv_async_wait_for(handle); 186 if (rc != EOK) { 187 return; 188 } 189 190 printf(NAME ": hub address changed\n"); 220 191 } 221 192 … … 224 195 static void check_hub_changes(void) { 225 196 /* 226 * Iterate through all HCs.197 * Iterate through all hubs. 227 198 */ 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 */ 199 for (; false; ) { 200 /* 201 * Check status change pipe of this hub. 202 */ 203 usb_target_t target = { 204 .address = 5, 205 .endpoint = 1 206 }; 207 208 size_t port_count = 7; 209 210 /* 211 * Connect to respective HC. 212 */ 213 int hc = usb_drv_hc_connect(NULL, 0); 214 if (hc < 0) { 215 continue; 272 216 } 217 218 // FIXME: count properly 219 size_t byte_length = (port_count / 8) + 1; 220 221 void *change_bitmap = malloc(byte_length); 222 size_t actual_size; 223 usb_handle_t handle; 224 225 /* 226 * Send the request. 227 * FIXME: check returned value for possible errors 228 */ 229 usb_drv_async_interrupt_in(hc, target, 230 change_bitmap, byte_length, &actual_size, 231 &handle); 232 233 usb_drv_async_wait_for(handle); 234 235 /* 236 * TODO: handle the changes. 237 */ 238 239 240 /* 241 * Hang-up the HC-connected phone. 242 */ 243 ipc_hangup(hc); 273 244 } 274 245 }
Note:
See TracChangeset
for help on using the changeset viewer.