Changeset 7aaed09 in mainline for uspace/drv/bus/usb/usbhid/main.c


Ignore:
Timestamp:
2011-12-18T14:02:30Z (12 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c868e2d
Parents:
3b71e84d (diff), 1761268 (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 mainline changes.

File:
1 edited

Legend:

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

    r3b71e84d r7aaed09  
    4949
    5050/**
    51  * Function for adding a new device of type USB/HID/keyboard.
     51 * Callback for passing a new device to the driver.
    5252 *
    53  * This functions initializes required structures from the device's descriptors
    54  * and starts new fibril for polling the keyboard for events and another one for
    55  * handling auto-repeat of keys.
     53 * @note Currently, only boot-protocol keyboards are supported by this driver.
    5654 *
    57  * During initialization, the keyboard is switched into boot protocol, the idle
    58  * rate is set to 0 (infinity), resulting in the keyboard only reporting event
    59  * when a key is pressed or released. Finally, the LED lights are turned on
    60  * according to the default setup of lock keys.
    61  *
    62  * @note By default, the keyboards is initialized with Num Lock turned on and
    63  *       other locks turned off.
    64  * @note Currently supports only boot-protocol keyboards.
    65  *
    66  * @param dev Device to add.
     55 * @param dev Structure representing the new device.
    6756 * @return Error code.
    6857 */
    69 static int usb_hid_try_add_device(usb_device_t *dev)
     58static int usb_hid_device_add(usb_device_t *dev)
    7059{
    71         assert(dev != NULL);
     60        usb_log_debug("%s\n", __FUNCTION__);
    7261
    73         /* Initialize device (get and process descriptors, get address, etc.) */
    74         usb_log_debug("Initializing USB/HID device...\n");
     62        if (dev == NULL) {
     63                usb_log_error("Wrong parameter given for add_device().\n");
     64                return EINVAL;
     65        }
    7566
     67        if (dev->interface_no < 0) {
     68                usb_log_error("Failed to add HID device: endpoints not found."
     69                    "\n");
     70                return ENOTSUP;
     71        }
    7672        usb_hid_dev_t *hid_dev =
    7773            usb_device_data_alloc(dev, sizeof(usb_hid_dev_t));
    7874        if (hid_dev == NULL) {
    79                 usb_log_error("Error while creating USB/HID device "
    80                     "structure.\n");
     75                usb_log_error("Failed to create USB/HID device structure.\n");
    8176                return ENOMEM;
    8277        }
    8378
    8479        int rc = usb_hid_init(hid_dev, dev);
    85 
    8680        if (rc != EOK) {
    8781                usb_log_error("Failed to initialize USB/HID device.\n");
     
    9286        usb_log_debug("USB/HID device structure initialized.\n");
    9387
    94         /*
    95          * 1) subdriver vytvori vlastnu ddf_fun, vlastne ddf_dev_ops, ktore da
    96          *    do nej.
    97          * 2) do tych ops do .interfaces[DEV_IFACE_USBHID (asi)] priradi
    98          *    vyplnenu strukturu usbhid_iface_t.
    99          * 3) klientska aplikacia - musi si rucne vytvorit telefon
    100          *    (devman_device_connect() - cesta k zariadeniu (/hw/pci0/...) az
    101          *    k tej fcii.
    102          *    pouzit usb/classes/hid/iface.h - prvy int je telefon
    103          */
    104 
    10588        /* Start automated polling function.
    10689         * This will create a separate fibril that will query the device
    107          * for the data continuously
    108          */
     90         * for the data continuously. */
    10991       rc = usb_device_auto_poll(dev,
    11092           /* Index of the polling pipe. */
     
    11395           usb_hid_polling_callback,
    11496           /* How much data to request. */
    115            dev->pipes[hid_dev->poll_pipe_index].pipe->max_packet_size,
     97           dev->pipes[hid_dev->poll_pipe_index].pipe.max_packet_size,
    11698           /* Callback when the polling ends. */
    11799           usb_hid_polling_ended_callback,
     
    126108        }
    127109        hid_dev->running = true;
    128 
    129         /*
    130          * Hurrah, device is initialized.
    131          */
    132         return EOK;
    133 }
    134 /*----------------------------------------------------------------------------*/
    135 /**
    136  * Callback for passing a new device to the driver.
    137  *
    138  * @note Currently, only boot-protocol keyboards are supported by this driver.
    139  *
    140  * @param dev Structure representing the new device.
    141  * @return Error code.
    142  */
    143 static int usb_hid_device_add(usb_device_t *dev)
    144 {
    145         usb_log_debug("usb_hid_device_add()\n");
    146 
    147         if (dev == NULL) {
    148                 usb_log_warning("Wrong parameter given for add_device().\n");
    149                 return EINVAL;
    150         }
    151 
    152         if (dev->interface_no < 0) {
    153                 usb_log_warning("Device is not a supported HID device.\n");
    154                 usb_log_error("Failed to add HID device: endpoints not found."
    155                     "\n");
    156                 return ENOTSUP;
    157         }
    158 
    159         int rc = usb_hid_try_add_device(dev);
    160 
    161         if (rc != EOK) {
    162                 usb_log_warning("Device is not a supported HID device.\n");
    163                 usb_log_error("Failed to add HID device: %s.\n",
    164                     str_error(rc));
    165                 return rc;
    166         }
    167110
    168111        usb_log_info("HID device `%s' ready to use.\n", dev->ddf_dev->name);
     
    179122static int usb_hid_device_rem(usb_device_t *dev)
    180123{
    181         return EOK;
     124        // TODO: Stop device polling
     125        // TODO: Call deinit (stops autorepeat too)
     126        return ENOTSUP;
    182127}
    183128/*----------------------------------------------------------------------------*/
     
    190135static int usb_hid_device_gone(usb_device_t *dev)
    191136{
     137        assert(dev);
     138        assert(dev->driver_data);
    192139        usb_hid_dev_t *hid_dev = dev->driver_data;
    193         unsigned tries = 10;
    194         while (hid_dev->running) {
     140        unsigned tries = 100;
     141        /* Wait for fail. */
     142        while (hid_dev->running && tries--) {
    195143                async_usleep(100000);
    196                 if (!tries--) {
    197                         usb_log_error("Can't remove hub, still running.\n");
    198                         return EBUSY;
    199                 }
     144        }
     145        if (hid_dev->running) {
     146                usb_log_error("Can't remove hid, still running.\n");
     147                return EBUSY;
    200148        }
    201149
    202         assert(!hid_dev->running);
    203150        usb_hid_deinit(hid_dev);
    204151        usb_log_debug2("%s destruction complete.\n", dev->ddf_dev->name);
Note: See TracChangeset for help on using the changeset viewer.