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/generic/hiddev.c

    r1ccc32f r25696fea  
    5252        .direction = USB_DIRECTION_IN,
    5353        .interface_class = USB_CLASS_HID,
     54        .interface_subclass = -1,
     55        .interface_protocol = -1,
    5456        .flags = 0
    5557};
     
    9294        usb_log_debug2("Generic HID: Get event length (fun: %p, "
    9395            "fun->driver_data: %p.\n", fun, fun->driver_data);
    94        
     96
    9597        if (fun == NULL || fun->driver_data == NULL) {
    9698                return 0;
     
    98100
    99101        usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
    100        
     102
    101103        usb_log_debug2("hid_dev: %p, Max input report size (%zu).\n",
    102104            hid_dev, hid_dev->max_input_report_size);
    103        
     105
    104106        return hid_dev->max_input_report_size;
    105107}
     
    111113{
    112114        usb_log_debug2("Generic HID: Get event.\n");
    113        
     115
    114116        if (fun == NULL || fun->driver_data == NULL || buffer == NULL
    115117            || act_size == NULL || event_nr == NULL) {
     
    119121
    120122        usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
    121        
     123
    122124        if (hid_dev->input_report_size > size) {
    123125                usb_log_debug("input_report_size > size (%zu, %zu)\n",
     
    125127                return EINVAL;  // TODO: other error code
    126128        }
    127        
     129
    128130        /*! @todo This should probably be somehow atomic. */
    129131        memcpy(buffer, hid_dev->input_report,
     
    131133        *act_size = hid_dev->input_report_size;
    132134        *event_nr = usb_hid_report_number(hid_dev);
    133        
     135
    134136        usb_log_debug2("OK\n");
    135        
     137
    136138        return EOK;
    137139}
     
    142144{
    143145        usb_log_debug("Generic HID: Get report descriptor length.\n");
    144        
     146
    145147        if (fun == NULL || fun->driver_data == NULL) {
    146148                usb_log_debug("No function");
    147149                return EINVAL;
    148150        }
    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
    152154        usb_log_debug2("hid_dev->report_desc_size = %zu\n",
    153155            hid_dev->report_desc_size);
    154        
     156
    155157        return hid_dev->report_desc_size;
    156158}
     
    162164{
    163165        usb_log_debug2("Generic HID: Get report descriptor.\n");
    164        
     166
    165167        if (fun == NULL || fun->driver_data == NULL) {
    166168                usb_log_debug("No function");
    167169                return EINVAL;
    168170        }
    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
    172174        if (hid_dev->report_desc_size > size) {
    173175                return EINVAL;
    174176        }
    175        
     177
    176178        memcpy(desc, hid_dev->report_desc, hid_dev->report_desc_size);
    177179        *actual_size = hid_dev->report_desc_size;
    178        
     180
    179181        return EOK;
    180182}
     
    190192/*----------------------------------------------------------------------------*/
    191193
    192 static int usb_generic_hid_create_function(usb_hid_dev_t *hid_dev)
    193 {       
     194void 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
     211int usb_generic_hid_init(usb_hid_dev_t *hid_dev, void **data)
     212{
     213        if (hid_dev == NULL) {
     214                return EINVAL;
     215        }
     216
    194217        /* Create the exposed function. */
    195218        /** @todo Generate numbers for the devices? */
     
    201224                return ENOMEM;
    202225        }
    203        
     226
    204227        fun->ops = &usb_generic_hid_ops;
    205         fun->driver_data = hid_dev;
    206228
    207229        int rc = ddf_fun_bind(fun);
     
    212234                return rc;
    213235        }
    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
    215240        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;
    229244}
    230245
Note: See TracChangeset for help on using the changeset viewer.