Changeset 25696fea in mainline for uspace/drv/bus/usb/usbhid/main.c


Ignore:
Timestamp:
2011-10-15T20:05:00Z (13 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
22ceff3a
Parents:
1ccc32f (diff), 721d4b6e (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.
Message:

Merge with mainline

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbhid/main.c

    r1ccc32f r25696fea  
    7676{
    7777        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.) */
    8280        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));
    8584        if (hid_dev == NULL) {
    8685                usb_log_error("Error while creating USB/HID device "
     
    8887                return ENOMEM;
    8988        }
    90        
     89
    9190        int rc = usb_hid_init(hid_dev, dev);
    92        
     91
    9392        if (rc != EOK) {
    9493                usb_log_error("Failed to initialize USB/HID device.\n");
    9594                usb_hid_destroy(hid_dev);
    9695                return rc;
    97         }       
    98        
     96        }
     97
    9998        usb_log_debug("USB/HID device structure initialized.\n");
    100        
     99
    101100        /*
    102101         * 1) subdriver vytvori vlastnu ddf_fun, vlastne ddf_dev_ops, ktore da
     
    109108         *    pouzit usb/classes/hid/iface.h - prvy int je telefon
    110109         */
    111        
     110
    112111        /* Start automated polling function.
    113112         * This will create a separate fibril that will query the device
     
    125124           /* Custom argument. */
    126125           hid_dev);
    127        
    128        
     126
    129127        if (rc != EOK) {
    130128                usb_log_error("Failed to start polling fibril for `%s'.\n",
    131129                    dev->ddf_dev->name);
     130                usb_hid_destroy(hid_dev);
    132131                return rc;
    133132        }
     133        hid_dev->running = true;
     134        dev->driver_data = hid_dev;
    134135
    135136        /*
     
    150151 * @retval EREFUSED if the device is not supported.
    151152 */
    152 static int usb_hid_add_device(usb_device_t *dev)
    153 {
    154         usb_log_debug("usb_hid_add_device()\n");
    155        
     153static int usb_hid_device_add(usb_device_t *dev)
     154{
     155        usb_log_debug("usb_hid_device_add()\n");
     156
    156157        if (dev == NULL) {
    157158                usb_log_warning("Wrong parameter given for add_device().\n");
    158159                return EINVAL;
    159160        }
    160        
     161
    161162        if (dev->interface_no < 0) {
    162163                usb_log_warning("Device is not a supported HID device.\n");
     
    165166                return ENOTSUP;
    166167        }
    167        
     168
    168169        int rc = usb_hid_try_add_device(dev);
    169        
     170
    170171        if (rc != EOK) {
    171172                usb_log_warning("Device is not a supported HID device.\n");
     
    174175                return rc;
    175176        }
    176        
     177
    177178        usb_log_info("HID device `%s' ready to use.\n", dev->ddf_dev->name);
    178179
     
    182183/*----------------------------------------------------------------------------*/
    183184
    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 */
     193static 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 */
    186212static 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,
    188215};
    189216
    190217
    191 /* The driver itself. */
     218/** The driver itself. */
    192219static usb_driver_t usb_hid_driver = {
    193220        .name = NAME,
Note: See TracChangeset for help on using the changeset viewer.