Changeset 4d0c40b in mainline
- Timestamp:
- 2011-03-22T22:30:55Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d8421c4
- Parents:
- 41ef5b9
- Location:
- uspace/drv
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/ohci/root_hub.c
r41ef5b9 r4d0c40b 39 39 40 40 #include "root_hub.h" 41 #include <usb/request.h> 42 #include <usb/classes/hub.h> 43 41 44 42 45 /** Root hub initialization … … 50 53 instance->device = dev; 51 54 55 52 56 usb_log_info("OHCI root hub with %d ports.\n", regs->rh_desc_a & 0xff); 53 57 58 //start generic usb hub driver 59 54 60 /* TODO: implement */ 55 61 return EOK; 56 62 } 57 63 /*----------------------------------------------------------------------------*/ 64 65 66 static int process_get_port_status_request(rh_t *instance, uint16_t port, 67 char * buffer){ 68 if(port<1 || port>instance->port_count) 69 return EINVAL; 70 uint32_t * uint32_buffer = (uint32_t*)buffer; 71 uint32_buffer[0] = instance->registers->rh_port_status[port -1]; 72 return EOK; 73 } 74 75 static int process_get_hub_status_request(rh_t *instance,char * buffer){ 76 uint32_t * uint32_buffer = (uint32_t*)buffer; 77 //bits, 0,1,16,17 78 uint32_t mask = 1 & (1<<1) & (1<<16) & (1<<17); 79 uint32_buffer[0] = mask & instance->registers->rh_status; 80 return EOK; 81 82 } 83 84 85 static int process_get_status_request(rh_t *instance,char * buffer, 86 size_t buffer_size, usb_device_request_setup_packet_t * request){ 87 88 usb_hub_bm_request_type_t request_type = request->request_type; 89 if(buffer_size!=4) return EINVAL; 90 if(request_type == USB_HUB_REQ_TYPE_GET_HUB_STATUS) 91 return process_get_hub_status_request(instance, buffer); 92 if(request_type == USB_HUB_REQ_TYPE_GET_PORT_STATUS) 93 return process_get_port_status_request(instance, request->index, 94 buffer); 95 return ENOTSUP; 96 } 97 98 static int process_get_descriptor_request(rh_t *instance, 99 usb_transfer_batch_t *request){ 100 /// \TODO 101 usb_device_request_setup_packet_t * setup_request = 102 (usb_device_request_setup_packet_t*)request->setup_buffer; 103 if(setup_request->value == USB_DESCTYPE_HUB){ 104 //create hub descriptor 105 }else if(setup_request->value == USB_DESCTYPE_HUB){ 106 //create std device descriptor 107 }else{ 108 return EINVAL; 109 } 110 return EOK; 111 } 112 113 static int process_get_configuration_request(rh_t *instance, char * buffer, 114 size_t buffer_size 115 ){ 116 //set and get configuration requests do not have any meaning, only dummy 117 //values are returned 118 if(buffer_size != 1) 119 return EINVAL; 120 buffer[0] = 1; 121 return EOK; 122 } 123 124 static int process_hub_feature_set_request(rh_t *instance, 125 uint16_t feature, bool enable){ 126 if(feature > USB_HUB_FEATURE_C_HUB_OVER_CURRENT) 127 return EINVAL; 128 instance->registers->rh_status = 129 enable ? 130 (instance->registers->rh_status | (1<<feature)) 131 : 132 (instance->registers->rh_status & (~(1<<feature))); 133 /// \TODO any error? 134 return EOK; 135 } 136 137 static int process_port_feature_set_request(rh_t *instance, 138 uint16_t feature, uint16_t port, bool enable){ 139 if(feature > USB_HUB_FEATURE_C_PORT_RESET) 140 return EINVAL; 141 if(port<1 || port>instance->port_count) 142 return EINVAL; 143 instance->registers->rh_port_status[port - 1] = 144 enable ? 145 (instance->registers->rh_port_status[port - 1] | (1<<feature)) 146 : 147 (instance->registers->rh_port_status[port - 1] & (~(1<<feature))); 148 /// \TODO any error? 149 return EOK; 150 151 } 152 153 static int process_request_with_output(rh_t *instance, 154 usb_transfer_batch_t *request){ 155 usb_device_request_setup_packet_t * setup_request = 156 (usb_device_request_setup_packet_t*)request->setup_buffer; 157 if(setup_request->request == USB_DEVREQ_GET_STATUS){ 158 return process_get_status_request(instance, request->buffer, 159 request->buffer_size, 160 setup_request); 161 } 162 if(setup_request->request == USB_DEVREQ_GET_DESCRIPTOR){ 163 return process_get_descriptor_request(instance, request); 164 } 165 if(setup_request->request == USB_DEVREQ_GET_CONFIGURATION){ 166 return process_get_configuration_request(instance, request->buffer, 167 request->buffer_size); 168 } 169 return ENOTSUP; 170 } 171 172 static int process_request_with_input(rh_t *instance, 173 usb_transfer_batch_t *request){ 174 usb_device_request_setup_packet_t * setup_request = 175 (usb_device_request_setup_packet_t*)request->setup_buffer; 176 if(setup_request->request == USB_DEVREQ_SET_DESCRIPTOR){ 177 return ENOTSUP; 178 } 179 if(setup_request->request == USB_DEVREQ_SET_CONFIGURATION){ 180 //set and get configuration requests do not have any meaning, 181 //only dummy values are returned 182 return EOK; 183 } 184 return ENOTSUP; 185 } 186 187 188 static int process_request_without_data(rh_t *instance, 189 usb_transfer_batch_t *request){ 190 usb_device_request_setup_packet_t * setup_request = 191 (usb_device_request_setup_packet_t*)request->setup_buffer; 192 if(setup_request->request_type == USB_HUB_REQ_TYPE_SET_HUB_FEATURE){ 193 return process_hub_feature_set_request(instance, setup_request->value, 194 setup_request->request == USB_DEVREQ_SET_FEATURE); 195 } 196 if(setup_request->request_type == USB_HUB_REQ_TYPE_SET_PORT_FEATURE){ 197 return process_port_feature_set_request(instance, setup_request->value, 198 setup_request->index, 199 setup_request->request == USB_DEVREQ_SET_FEATURE); 200 } 201 return ENOTSUP; 202 } 203 204 205 /** 206 * 207 * @param instance 208 * @param request 209 * @return 210 */ 58 211 int rh_request(rh_t *instance, usb_transfer_batch_t *request) 59 212 { 60 213 assert(instance); 61 214 assert(request); 62 /* TODO: implement */215 int opResult; 63 216 if (request->setup_buffer) { 64 217 usb_log_info("Root hub got SETUP packet: %s.\n", 65 218 usb_debug_str_buffer((const uint8_t *)request->setup_buffer, 8, 8)); 66 } 67 usb_log_error("Root hub request processing not implemented.\n"); 68 usb_transfer_batch_finish(request, ENOTSUP); 219 if(sizeof(usb_device_request_setup_packet_t)>request->setup_size){ 220 usb_log_error("setup packet too small\n"); 221 return EINVAL; 222 } 223 usb_device_request_setup_packet_t * setup_request = 224 (usb_device_request_setup_packet_t*)request->setup_buffer; 225 if( 226 setup_request->request == USB_DEVREQ_GET_STATUS 227 || setup_request->request == USB_DEVREQ_GET_DESCRIPTOR 228 || setup_request->request == USB_DEVREQ_GET_CONFIGURATION 229 ){ 230 usb_log_debug("processing request with output\n"); 231 opResult = process_request_with_output(instance,request); 232 }else if( 233 setup_request->request == USB_DEVREQ_CLEAR_FEATURE 234 || setup_request->request == USB_DEVREQ_SET_FEATURE 235 ){ 236 usb_log_debug("processing request without additional data\n"); 237 opResult = process_request_without_data(instance,request); 238 }else if(setup_request->request == USB_DEVREQ_SET_DESCRIPTOR 239 || setup_request->request == USB_DEVREQ_SET_CONFIGURATION 240 ){ 241 usb_log_debug("processing request with input\n"); 242 opResult = process_request_with_input(instance,request); 243 }else{ 244 usb_log_warning("received unsuported request: %d\n", 245 setup_request->request 246 ); 247 opResult = ENOTSUP; 248 } 249 }else{ 250 usb_log_error("root hub received empty transaction?"); 251 opResult = EINVAL; 252 } 253 usb_transfer_batch_finish(request, opResult); 69 254 return EOK; 70 255 } 71 256 /*----------------------------------------------------------------------------*/ 257 //is this status change? 72 258 void rh_interrupt(rh_t *instance) 73 259 { -
uspace/drv/ohci/root_hub.h
r41ef5b9 r4d0c40b 45 45 usb_address_t address; 46 46 ddf_dev_t *device; 47 int port_count; 47 48 } rh_t; 48 49 -
uspace/drv/usbhub/port_status.h
r41ef5b9 r4d0c40b 30 30 */ 31 31 32 #ifndef PORT_STATUS_H33 #define PORT_STATUS_H32 #ifndef HUB_PORT_STATUS_H 33 #define HUB_PORT_STATUS_H 34 34 35 35 #include <bool.h> … … 335 335 336 336 337 #endif /* PORT_STATUS_H */337 #endif /* HUB_PORT_STATUS_H */ 338 338 339 339 /** -
uspace/drv/usbhub/usbhub.c
r41ef5b9 r4d0c40b 162 162 std_descriptor->configuration_count); 163 163 if(std_descriptor->configuration_count<1){ 164 usb_log_error("THERE ARE NO CONFIGURATIONS AVAILABLE\n"); 165 //shouldn`t I return? 166 //definitely 164 usb_log_error("there are no configurations available\n"); 167 165 return EINVAL; 168 166 }
Note:
See TracChangeset
for help on using the changeset viewer.