Changeset 54b141a in mainline for uspace/drv/usbhub/utils.c
- Timestamp:
- 2010-12-04T17:01:24Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e28d228
- Parents:
- 2cb6571 (diff), ad104e0 (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
r2cb6571 r54b141a 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 device_t * my_hcd = device;116 while (my_hcd->parent)117 my_hcd = my_hcd->parent;118 //dev->119 printf("[hcdhubd]%s: owner hcd found: %s\n", hc_driver->name, my_hcd->name);120 //we add the hub into the first hc121 //link_t *link_hc = hc_list.next;122 //usb_hc_device_t *hc = list_get_instance(link_hc,123 // usb_hc_device_t, link);124 //must get generic device info125 126 113 127 114 return result; … … 134 121 */ 135 122 int usb_add_hub_device(device_t *dev) { 136 //usb_hc_device_t *hc = list_get_instance(hc_list.next, usb_hc_device_t, link); 137 assert(dev->parent); 138 usb_hc_device_t *hc = (usb_hc_device_t*)dev->parent->driver_data; 139 usb_address_t addr =usb_use_free_address(hc); 140 if(addr<0){ 141 printf("[hcdhubd] ERROR: cannot find an address \n"); 142 } 143 set_hub_address(hc, addr); 123 printf(NAME ": add_hub_device(handle=%d)\n", (int) dev->handle); 144 124 145 125 check_hub_changes(); … … 150 130 * connected devices. 151 131 */ 152 //insert hub into list153 //find owner hcd154 device_t * my_hcd = dev;155 while (my_hcd->parent)156 my_hcd = my_hcd->parent;157 //dev->158 printf("[hcdhubd]%s: owner hcd found: %s\n", hc_driver->name, my_hcd->name);159 my_hcd = dev;160 while (my_hcd->parent)161 my_hcd = my_hcd->parent;162 //dev->163 164 printf("[hcdhubd]%s: owner hcd found: %s\n", hc_driver->name, my_hcd->name);165 132 166 133 //create the hub structure 167 134 usb_hcd_hub_info_t * hub_info = usb_create_hub_info(dev); 168 169 170 //append into the list 171 //we add the hub into the first hc 172 list_append(&hub_info->link, &hc->hubs); 173 174 135 (void)hub_info; 175 136 176 137 return EOK; … … 178 139 } 179 140 180 /** Sample usage of usb_hc_async functions.181 * This function sets hub address using standard SET_ADDRESS request.182 *183 * @warning This function shall be removed once you are familiar with184 * the usb_hc_ API.185 *186 * @param hc Host controller the hub belongs to.187 * @param address New hub address.188 */189 static void set_hub_address(usb_hc_device_t *hc, usb_address_t address) {190 printf("[hcdhubd]%s: setting hub address to %d\n", hc->generic->name, address);191 usb_target_t target = {0, 0};192 usb_handle_t handle;193 int rc;194 195 usb_device_request_setup_packet_t setup_packet = {196 .request_type = 0,197 .request = USB_DEVREQ_SET_ADDRESS,198 .index = 0,199 .length = 0,200 };201 setup_packet.value = address;202 203 rc = usb_hc_async_control_write_setup(hc, target,204 &setup_packet, sizeof (setup_packet), &handle);205 if (rc != EOK) {206 return;207 }208 209 rc = usb_hc_async_wait_for(handle);210 if (rc != EOK) {211 return;212 }213 214 rc = usb_hc_async_control_write_status(hc, target, &handle);215 if (rc != EOK) {216 return;217 }218 219 rc = usb_hc_async_wait_for(handle);220 if (rc != EOK) {221 return;222 }223 224 printf("[hcdhubd]%s: hub address changed successfully to %d\n",225 hc->generic->name, address);226 }227 141 228 142 /** Check changes on all known hubs. … … 230 144 static void check_hub_changes(void) { 231 145 /* 232 * Iterate through all HCs.146 * Iterate through all hubs. 233 147 */ 234 link_t *link_hc; 235 for (link_hc = hc_list.next; 236 link_hc != &hc_list; 237 link_hc = link_hc->next) { 238 usb_hc_device_t *hc = list_get_instance(link_hc, 239 usb_hc_device_t, link); 148 for (; false; ) { 240 149 /* 241 * Iterate through all their hubs.150 * Check status change pipe of this hub. 242 151 */ 243 link_t *link_hub; 244 for (link_hub = hc->hubs.next; 245 link_hub != &hc->hubs; 246 link_hub = link_hub->next) { 247 usb_hcd_hub_info_t *hub = list_get_instance(link_hub, 248 usb_hcd_hub_info_t, link); 152 usb_target_t target = { 153 .address = 5, 154 .endpoint = 1 155 }; 249 156 250 /* 251 * Check status change pipe of this hub. 252 */ 253 usb_target_t target = { 254 .address = hub->device->address, 255 .endpoint = 1 256 }; 157 size_t port_count = 7; 257 158 258 // FIXME: count properly 259 size_t byte_length = (hub->port_count / 8) + 1; 159 /* 160 * Connect to respective HC. 161 */ 162 int hc = usb_drv_hc_connect(NULL, 0); 163 if (hc < 0) { 164 continue; 165 } 260 166 261 void *change_bitmap = malloc(byte_length); 262 size_t actual_size; 263 usb_handle_t handle; 167 // FIXME: count properly 168 size_t byte_length = (port_count / 8) + 1; 264 169 265 /* 266 * Send the request. 267 * FIXME: check returned value for possible errors 268 */ 269 usb_hc_async_interrupt_in(hc, target, 270 change_bitmap, byte_length, &actual_size, 271 &handle); 170 void *change_bitmap = malloc(byte_length); 171 size_t actual_size; 172 usb_handle_t handle; 272 173 273 usb_hc_async_wait_for(handle); 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); 274 181 275 /* 276 * TODO: handle the changes. 277 */ 278 } 182 usb_drv_async_wait_for(handle); 183 184 /* 185 * TODO: handle the changes. 186 */ 187 188 189 /* 190 * Hang-up the HC-connected phone. 191 */ 192 ipc_hangup(hc); 279 193 } 280 194 }
Note:
See TracChangeset
for help on using the changeset viewer.