Changeset 20a3465 in mainline for uspace/drv/bus/usb/usbhid/generic/hiddev.c
- Timestamp:
- 2011-10-30T19:50:54Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3ce78580, 48902fa
- Parents:
- 4c3ad56 (diff), 45bf63c (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 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhid/generic/hiddev.c
r4c3ad56 r20a3465 48 48 /*----------------------------------------------------------------------------*/ 49 49 50 usb_endpoint_description_t usb_hid_generic_poll_endpoint_description = {50 const usb_endpoint_description_t usb_hid_generic_poll_endpoint_description = { 51 51 .transfer_type = USB_TRANSFER_INTERRUPT, 52 52 .direction = USB_DIRECTION_IN, 53 53 .interface_class = USB_CLASS_HID, 54 .interface_subclass = -1, 55 .interface_protocol = -1, 54 56 .flags = 0 55 57 }; … … 92 94 usb_log_debug2("Generic HID: Get event length (fun: %p, " 93 95 "fun->driver_data: %p.\n", fun, fun->driver_data); 94 96 95 97 if (fun == NULL || fun->driver_data == NULL) { 96 98 return 0; … … 98 100 99 101 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 100 102 101 103 usb_log_debug2("hid_dev: %p, Max input report size (%zu).\n", 102 104 hid_dev, hid_dev->max_input_report_size); 103 105 104 106 return hid_dev->max_input_report_size; 105 107 } … … 111 113 { 112 114 usb_log_debug2("Generic HID: Get event.\n"); 113 115 114 116 if (fun == NULL || fun->driver_data == NULL || buffer == NULL 115 117 || act_size == NULL || event_nr == NULL) { … … 119 121 120 122 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 121 123 122 124 if (hid_dev->input_report_size > size) { 123 125 usb_log_debug("input_report_size > size (%zu, %zu)\n", … … 125 127 return EINVAL; // TODO: other error code 126 128 } 127 129 128 130 /*! @todo This should probably be somehow atomic. */ 129 131 memcpy(buffer, hid_dev->input_report, … … 131 133 *act_size = hid_dev->input_report_size; 132 134 *event_nr = usb_hid_report_number(hid_dev); 133 135 134 136 usb_log_debug2("OK\n"); 135 137 136 138 return EOK; 137 139 } … … 142 144 { 143 145 usb_log_debug("Generic HID: Get report descriptor length.\n"); 144 146 145 147 if (fun == NULL || fun->driver_data == NULL) { 146 148 usb_log_debug("No function"); 147 149 return EINVAL; 148 150 } 149 150 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 151 151 152 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 153 152 154 usb_log_debug2("hid_dev->report_desc_size = %zu\n", 153 155 hid_dev->report_desc_size); 154 156 155 157 return hid_dev->report_desc_size; 156 158 } … … 162 164 { 163 165 usb_log_debug2("Generic HID: Get report descriptor.\n"); 164 166 165 167 if (fun == NULL || fun->driver_data == NULL) { 166 168 usb_log_debug("No function"); 167 169 return EINVAL; 168 170 } 169 170 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 171 171 172 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 173 172 174 if (hid_dev->report_desc_size > size) { 173 175 return EINVAL; 174 176 } 175 177 176 178 memcpy(desc, hid_dev->report_desc, hid_dev->report_desc_size); 177 179 *actual_size = hid_dev->report_desc_size; 178 180 179 181 return EOK; 180 182 } … … 190 192 /*----------------------------------------------------------------------------*/ 191 193 192 static int usb_generic_hid_create_function(usb_hid_dev_t *hid_dev) 193 { 194 void usb_generic_hid_deinit(usb_hid_dev_t *hid_dev, void *data) 195 { 196 ddf_fun_t *fun = data; 197 const int ret = ddf_fun_unbind(fun); 198 if (ret != EOK) { 199 usb_log_error("Failed to unbind generic hid fun.\n"); 200 return; 201 } 202 usb_log_debug2("%s unbound.\n", fun->name); 203 /* We did not allocate this, so leave this alone 204 * the device would take care of it */ 205 fun->driver_data = NULL; 206 ddf_fun_destroy(fun); 207 } 208 209 /*----------------------------------------------------------------------------*/ 210 211 int usb_generic_hid_init(usb_hid_dev_t *hid_dev, void **data) 212 { 213 if (hid_dev == NULL) { 214 return EINVAL; 215 } 216 194 217 /* Create the exposed function. */ 195 218 /** @todo Generate numbers for the devices? */ … … 201 224 return ENOMEM; 202 225 } 203 226 204 227 fun->ops = &usb_generic_hid_ops; 205 fun->driver_data = hid_dev;206 228 207 229 int rc = ddf_fun_bind(fun); … … 212 234 return rc; 213 235 } 214 236 /* This is nasty both device and this function have the same 237 * driver data, thus destruction would lead to double free */ 238 fun->driver_data = hid_dev; 239 215 240 usb_log_debug("HID function created. Handle: %" PRIun "\n", fun->handle); 216 217 return EOK; 218 } 219 220 /*----------------------------------------------------------------------------*/ 221 222 int usb_generic_hid_init(usb_hid_dev_t *hid_dev, void **data) 223 { 224 if (hid_dev == NULL) { 225 return EINVAL; 226 } 227 228 return usb_generic_hid_create_function(hid_dev); 241 *data = fun; 242 243 return EOK; 229 244 } 230 245
Note:
See TracChangeset
for help on using the changeset viewer.