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