Changes in / [1b9c0e2:03eea27] in mainline
- Location:
- uspace
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/ohci/root_hub.c
r1b9c0e2 r03eea27 40 40 #include "root_hub.h" 41 41 #include "usb/classes/classes.h" 42 #include "usb/devdrv.h" 42 43 #include <usb/request.h> 43 44 #include <usb/classes/hub.h> … … 61 62 /// \TODO these values migt be different 62 63 .str_serial_number = 0, 63 .usb_spec_version = 0 ,64 .usb_spec_version = 0x110, 64 65 }; 65 66 … … 110 111 }; 111 112 112 /** Root hub initialization113 * @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 driver126 127 /* TODO: implement */128 return EOK;129 }130 /*----------------------------------------------------------------------------*/131 132 /**133 * create answer to port status_request134 *135 * Copy content of corresponding port status register to answer buffer.136 *137 * @param instance root hub instance138 * @param port port number, counted from 1139 * @param request structure containing both request and response information140 * @return error code141 */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_request154 *155 * Copy content of hub status register to answer buffer.156 *157 * @param instance root hub instance158 * @param request structure containing both request and response information159 * @return error code160 */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,17165 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 172 113 /** 173 114 * Create hub descriptor used in hub-driver <-> hub communication 174 * 115 * 175 116 * This means creating byt array from data in root hub registers. For more 176 117 * info see usb hub specification. … … 197 138 result[2] = instance->port_count; 198 139 uint32_t hub_desc_reg = instance->registers->rh_desc_a; 199 result[3] = 140 result[3] = 200 141 ((hub_desc_reg >> 8) %2) + 201 142 (((hub_desc_reg >> 9) %2) << 1) + … … 219 160 (*out_size) = size; 220 161 } 162 163 164 /** initialize hub descriptors 165 * 166 * Initialized are device and full configuration descriptor. These need to 167 * be initialized only once per hub. 168 * @instance root hub instance 169 */ 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 initialization 206 * @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 driver 220 221 /* TODO: implement */ 222 return EOK; 223 } 224 /*----------------------------------------------------------------------------*/ 225 226 /** 227 * create answer to port status_request 228 * 229 * Copy content of corresponding port status register to answer buffer. 230 * 231 * @param instance root hub instance 232 * @param port port number, counted from 1 233 * @param request structure containing both request and response information 234 * @return error code 235 */ 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_request 248 * 249 * Copy content of hub status register to answer buffer. 250 * 251 * @param instance root hub instance 252 * @param request structure containing both request and response information 253 * @return error code 254 */ 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,17 259 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 221 266 222 267 … … 284 329 } 285 330 } 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 331 310 332 /** 311 333 * create answer to a descriptor request … … 344 366 case USB_DESCTYPE_CONFIGURATION: { 345 367 usb_log_debug("USB_DESCTYPE_CONFIGURATION\n"); 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; 368 result_descriptor = instance->descriptors.configuration; 369 size = instance->descriptors.configuration_size; 352 370 break; 353 371 } … … 380 398 } 381 399 request->transfered_size = size; 382 memcpy(request->buffer,result_descriptor,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)); 383 403 if (del) 384 404 free(result_descriptor); -
uspace/drv/ohci/root_hub.h
r1b9c0e2 r03eea27 37 37 38 38 #include <usb/usb.h> 39 #include <usb/devdrv.h> 39 40 40 41 #include "ohci_regs.h" … … 53 54 /** hub port count */ 54 55 int port_count; 56 /** hubs descriptors */ 57 usb_device_descriptors_t descriptors; 55 58 } rh_t; 56 59 -
uspace/drv/usbhub/usbhub.c
r1b9c0e2 r03eea27 74 74 75 75 while(errorCode == EOK){ 76 async_usleep(1000 * 1000 * 10 );/// \TODO proper number once 76 77 errorCode = usb_hub_check_hub_changes(hub_info); 77 async_usleep(1000 * 1000 );/// \TODO proper number once78 78 } 79 79 usb_log_error("something in ctrl loop went wrong, errno %d\n",errorCode); -
uspace/lib/usb/src/devdrv.c
r1b9c0e2 r03eea27 251 251 &dev->descriptors.configuration_size); 252 252 if (rc != EOK) { 253 usb_log_error("Failed retrieving configuration descriptor: %s. \n",253 usb_log_error("Failed retrieving configuration descriptor: %s. %s\n", 254 254 dev->ddf_dev->name, str_error(rc)); 255 255 return rc; -
uspace/lib/usb/src/request.c
r1b9c0e2 r03eea27 529 529 return rc; 530 530 } 531 532 531 if (bare_config.descriptor_type != USB_DESCTYPE_CONFIGURATION) { 533 532 return ENOENT;
Note:
See TracChangeset
for help on using the changeset viewer.