Changes in / [03eea27:1b9c0e2] in mainline
- Location:
- uspace
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/ohci/root_hub.c
r03eea27 r1b9c0e2 40 40 #include "root_hub.h" 41 41 #include "usb/classes/classes.h" 42 #include "usb/devdrv.h"43 42 #include <usb/request.h> 44 43 #include <usb/classes/hub.h> … … 62 61 /// \TODO these values migt be different 63 62 .str_serial_number = 0, 64 .usb_spec_version = 0 x110,63 .usb_spec_version = 0, 65 64 }; 66 65 … … 111 110 }; 112 111 112 /** Root hub initialization 113 * @return Error code. 114 */ 115 int rh_init(rh_t *instance, ddf_dev_t *dev, ohci_regs_t *regs) 116 { 117 assert(instance); 118 instance->address = -1; 119 instance->registers = regs; 120 instance->device = dev; 121 122 123 usb_log_info("OHCI root hub with %d ports.\n", regs->rh_desc_a & 0xff); 124 125 //start generic usb hub driver 126 127 /* TODO: implement */ 128 return EOK; 129 } 130 /*----------------------------------------------------------------------------*/ 131 132 /** 133 * create answer to port status_request 134 * 135 * Copy content of corresponding port status register to answer buffer. 136 * 137 * @param instance root hub instance 138 * @param port port number, counted from 1 139 * @param request structure containing both request and response information 140 * @return error code 141 */ 142 static int process_get_port_status_request(rh_t *instance, uint16_t port, 143 usb_transfer_batch_t * request){ 144 if(port<1 || port>instance->port_count) 145 return EINVAL; 146 uint32_t * uint32_buffer = (uint32_t*)request->buffer; 147 request->transfered_size = 4; 148 uint32_buffer[0] = instance->registers->rh_port_status[port -1]; 149 return EOK; 150 } 151 152 /** 153 * create answer to port status_request 154 * 155 * Copy content of hub status register to answer buffer. 156 * 157 * @param instance root hub instance 158 * @param request structure containing both request and response information 159 * @return error code 160 */ 161 static int process_get_hub_status_request(rh_t *instance, 162 usb_transfer_batch_t * request){ 163 uint32_t * uint32_buffer = (uint32_t*)request->buffer; 164 //bits, 0,1,16,17 165 request->transfered_size = 4; 166 uint32_t mask = 1 & (1<<1) & (1<<16) & (1<<17); 167 uint32_buffer[0] = mask & instance->registers->rh_status; 168 return EOK; 169 170 } 171 113 172 /** 114 173 * Create hub descriptor used in hub-driver <-> hub communication 115 * 174 * 116 175 * This means creating byt array from data in root hub registers. For more 117 176 * info see usb hub specification. … … 138 197 result[2] = instance->port_count; 139 198 uint32_t hub_desc_reg = instance->registers->rh_desc_a; 140 result[3] = 199 result[3] = 141 200 ((hub_desc_reg >> 8) %2) + 142 201 (((hub_desc_reg >> 9) %2) << 1) + … … 160 219 (*out_size) = size; 161 220 } 162 163 164 /** initialize hub descriptors165 *166 * Initialized are device and full configuration descriptor. These need to167 * be initialized only once per hub.168 * @instance root hub instance169 */170 static void rh_init_descriptors(rh_t *instance){171 memcpy(&instance->descriptors.device, &ohci_rh_device_descriptor,172 sizeof(ohci_rh_device_descriptor)173 );174 usb_standard_configuration_descriptor_t descriptor;175 memcpy(&descriptor,&ohci_rh_conf_descriptor,176 sizeof(ohci_rh_conf_descriptor));177 uint8_t * hub_descriptor;178 size_t hub_desc_size;179 usb_create_serialized_hub_descriptor(instance, &hub_descriptor,180 &hub_desc_size);181 182 descriptor.total_length =183 sizeof(usb_standard_configuration_descriptor_t)+184 sizeof(usb_standard_endpoint_descriptor_t)+185 sizeof(usb_standard_interface_descriptor_t)+186 hub_desc_size;187 188 uint8_t * full_config_descriptor =189 (uint8_t*) malloc(descriptor.total_length);190 memcpy(full_config_descriptor, &descriptor, sizeof(descriptor));191 memcpy(full_config_descriptor + sizeof(descriptor),192 &ohci_rh_iface_descriptor, sizeof(ohci_rh_iface_descriptor));193 memcpy(full_config_descriptor + sizeof(descriptor) +194 sizeof(ohci_rh_iface_descriptor),195 &ohci_rh_ep_descriptor, sizeof(ohci_rh_ep_descriptor));196 memcpy(full_config_descriptor + sizeof(descriptor) +197 sizeof(ohci_rh_iface_descriptor) +198 sizeof(ohci_rh_ep_descriptor),199 hub_descriptor, hub_desc_size);200 201 instance->descriptors.configuration = full_config_descriptor;202 instance->descriptors.configuration_size = descriptor.total_length;203 }204 205 /** Root hub initialization206 * @return Error code.207 */208 int rh_init(rh_t *instance, ddf_dev_t *dev, ohci_regs_t *regs)209 {210 assert(instance);211 instance->address = -1;212 instance->registers = regs;213 instance->device = dev;214 rh_init_descriptors(instance);215 216 217 usb_log_info("OHCI root hub with %d ports.\n", regs->rh_desc_a & 0xff);218 219 //start generic usb hub driver220 221 /* TODO: implement */222 return EOK;223 }224 /*----------------------------------------------------------------------------*/225 226 /**227 * create answer to port status_request228 *229 * Copy content of corresponding port status register to answer buffer.230 *231 * @param instance root hub instance232 * @param port port number, counted from 1233 * @param request structure containing both request and response information234 * @return error code235 */236 static int process_get_port_status_request(rh_t *instance, uint16_t port,237 usb_transfer_batch_t * request){238 if(port<1 || port>instance->port_count)239 return EINVAL;240 uint32_t * uint32_buffer = (uint32_t*)request->buffer;241 request->transfered_size = 4;242 uint32_buffer[0] = instance->registers->rh_port_status[port -1];243 return EOK;244 }245 246 /**247 * create answer to port status_request248 *249 * Copy content of hub status register to answer buffer.250 *251 * @param instance root hub instance252 * @param request structure containing both request and response information253 * @return error code254 */255 static int process_get_hub_status_request(rh_t *instance,256 usb_transfer_batch_t * request){257 uint32_t * uint32_buffer = (uint32_t*)request->buffer;258 //bits, 0,1,16,17259 request->transfered_size = 4;260 uint32_t mask = 1 & (1<<1) & (1<<16) & (1<<17);261 uint32_buffer[0] = mask & instance->registers->rh_status;262 return EOK;263 264 }265 266 221 267 222 … … 329 284 } 330 285 } 331 286 287 /** 288 * create standart configuration descriptor for the root hub instance 289 * @param instance root hub instance 290 * @return newly allocated descriptor 291 */ 292 static usb_standard_configuration_descriptor_t * 293 usb_ohci_rh_create_standart_configuration_descriptor(rh_t *instance){ 294 usb_standard_configuration_descriptor_t * descriptor = 295 malloc(sizeof(usb_standard_configuration_descriptor_t)); 296 memcpy(descriptor, &ohci_rh_conf_descriptor, 297 sizeof(usb_standard_configuration_descriptor_t)); 298 /// \TODO should this include device descriptor? 299 const size_t hub_descriptor_size = 7 + 300 2* (instance->port_count / 8 + 301 ((instance->port_count % 8 > 0) ? 1 : 0)); 302 descriptor->total_length = 303 sizeof(usb_standard_configuration_descriptor_t)+ 304 sizeof(usb_standard_endpoint_descriptor_t)+ 305 sizeof(usb_standard_interface_descriptor_t)+ 306 hub_descriptor_size; 307 return descriptor; 308 } 309 332 310 /** 333 311 * create answer to a descriptor request … … 366 344 case USB_DESCTYPE_CONFIGURATION: { 367 345 usb_log_debug("USB_DESCTYPE_CONFIGURATION\n"); 368 result_descriptor = instance->descriptors.configuration; 369 size = instance->descriptors.configuration_size; 346 usb_standard_configuration_descriptor_t * descriptor = 347 usb_ohci_rh_create_standart_configuration_descriptor( 348 instance); 349 result_descriptor = descriptor; 350 size = sizeof(usb_standard_configuration_descriptor_t); 351 del = true; 370 352 break; 371 353 } … … 398 380 } 399 381 request->transfered_size = size; 400 memcpy(request->transport_buffer,result_descriptor,size); 401 usb_log_debug("sent desctiptor: %s\n", 402 usb_debug_str_buffer((uint8_t*)request->transport_buffer,size,size)); 382 memcpy(request->buffer,result_descriptor,size); 403 383 if (del) 404 384 free(result_descriptor); -
uspace/drv/ohci/root_hub.h
r03eea27 r1b9c0e2 37 37 38 38 #include <usb/usb.h> 39 #include <usb/devdrv.h>40 39 41 40 #include "ohci_regs.h" … … 54 53 /** hub port count */ 55 54 int port_count; 56 /** hubs descriptors */57 usb_device_descriptors_t descriptors;58 55 } rh_t; 59 56 -
uspace/drv/usbhub/usbhub.c
r03eea27 r1b9c0e2 74 74 75 75 while(errorCode == EOK){ 76 async_usleep(1000 * 1000 * 10 );/// \TODO proper number once77 76 errorCode = usb_hub_check_hub_changes(hub_info); 77 async_usleep(1000 * 1000 );/// \TODO proper number once 78 78 } 79 79 usb_log_error("something in ctrl loop went wrong, errno %d\n",errorCode); -
uspace/lib/usb/src/devdrv.c
r03eea27 r1b9c0e2 251 251 &dev->descriptors.configuration_size); 252 252 if (rc != EOK) { 253 usb_log_error("Failed retrieving configuration descriptor: %s. %s\n",253 usb_log_error("Failed retrieving configuration descriptor: %s.\n", 254 254 dev->ddf_dev->name, str_error(rc)); 255 255 return rc; -
uspace/lib/usb/src/request.c
r03eea27 r1b9c0e2 529 529 return rc; 530 530 } 531 531 532 if (bare_config.descriptor_type != USB_DESCTYPE_CONFIGURATION) { 532 533 return ENOENT;
Note:
See TracChangeset
for help on using the changeset viewer.