Changes in uspace/drv/bus/usb/usbhid/main.c [5f6e25e:065064e6] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhid/main.c
r5f6e25e r065064e6 76 76 { 77 77 assert(dev != NULL); 78 79 /* 80 * Initialize device (get and process descriptors, get address, etc.) 81 */ 78 79 /* Initialize device (get and process descriptors, get address, etc.) */ 82 80 usb_log_debug("Initializing USB/HID device...\n"); 83 84 usb_hid_dev_t *hid_dev = usb_hid_new(); 81 82 usb_hid_dev_t *hid_dev = 83 usb_device_data_alloc(dev, sizeof(usb_hid_dev_t)); 85 84 if (hid_dev == NULL) { 86 85 usb_log_error("Error while creating USB/HID device " … … 88 87 return ENOMEM; 89 88 } 90 89 91 90 int rc = usb_hid_init(hid_dev, dev); 92 91 93 92 if (rc != EOK) { 94 93 usb_log_error("Failed to initialize USB/HID device.\n"); 95 94 usb_hid_destroy(hid_dev); 96 95 return rc; 97 } 98 96 } 97 99 98 usb_log_debug("USB/HID device structure initialized.\n"); 100 99 101 100 /* 102 101 * 1) subdriver vytvori vlastnu ddf_fun, vlastne ddf_dev_ops, ktore da … … 109 108 * pouzit usb/classes/hid/iface.h - prvy int je telefon 110 109 */ 111 110 112 111 /* Start automated polling function. 113 112 * This will create a separate fibril that will query the device … … 125 124 /* Custom argument. */ 126 125 hid_dev); 127 128 126 129 127 if (rc != EOK) { 130 128 usb_log_error("Failed to start polling fibril for `%s'.\n", 131 129 dev->ddf_dev->name); 130 usb_hid_destroy(hid_dev); 132 131 return rc; 133 132 } 133 hid_dev->running = true; 134 dev->driver_data = hid_dev; 134 135 135 136 /* … … 150 151 * @retval EREFUSED if the device is not supported. 151 152 */ 152 static int usb_hid_ add_device(usb_device_t *dev)153 { 154 usb_log_debug("usb_hid_ add_device()\n");155 153 static int usb_hid_device_add(usb_device_t *dev) 154 { 155 usb_log_debug("usb_hid_device_add()\n"); 156 156 157 if (dev == NULL) { 157 158 usb_log_warning("Wrong parameter given for add_device().\n"); 158 159 return EINVAL; 159 160 } 160 161 161 162 if (dev->interface_no < 0) { 162 163 usb_log_warning("Device is not a supported HID device.\n"); … … 165 166 return ENOTSUP; 166 167 } 167 168 168 169 int rc = usb_hid_try_add_device(dev); 169 170 170 171 if (rc != EOK) { 171 172 usb_log_warning("Device is not a supported HID device.\n"); … … 174 175 return rc; 175 176 } 176 177 177 178 usb_log_info("HID device `%s' ready to use.\n", dev->ddf_dev->name); 178 179 … … 182 183 /*----------------------------------------------------------------------------*/ 183 184 184 /* Currently, the framework supports only device adding. Once the framework 185 * supports unplug, more callbacks will be added. */ 185 /** 186 * Callback for removing a device from the driver. 187 * 188 * @param dev Structure representing the device. 189 * 190 * @retval EOK if successful. 191 * @retval EREFUSED if the device is not supported. 192 */ 193 static int usb_hid_device_gone(usb_device_t *dev) 194 { 195 usb_hid_dev_t *hid_dev = dev->driver_data; 196 unsigned tries = 10; 197 while (hid_dev->running) { 198 async_usleep(100000); 199 if (!tries--) { 200 usb_log_error("Can't remove hub, still running.\n"); 201 return EINPROGRESS; 202 } 203 } 204 205 assert(!hid_dev->running); 206 usb_hid_destroy(hid_dev); 207 usb_log_debug2("%s destruction complete.\n", dev->ddf_dev->name); 208 return EOK; 209 } 210 211 /** USB generic driver callbacks */ 186 212 static usb_driver_ops_t usb_hid_driver_ops = { 187 .add_device = usb_hid_add_device, 213 .device_add = usb_hid_device_add, 214 .device_gone = usb_hid_device_gone, 188 215 }; 189 216 190 217 191 /* The driver itself. */218 /** The driver itself. */ 192 219 static usb_driver_t usb_hid_driver = { 193 220 .name = NAME,
Note:
See TracChangeset
for help on using the changeset viewer.