Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbmouse/init.c

    rb59ec8c r4a4c8bcf  
    3434 * Initialization routines for USB mouse driver.
    3535 */
     36
    3637#include "mouse.h"
    3738#include <usb/debug.h>
     
    5253};
    5354
    54 static void default_connection_handler(ddf_fun_t *, ipc_callid_t, ipc_call_t *);
     55/** Default handler for IPC methods not handled by DDF.
     56 *
     57 * @param fun     Device function handling the call.
     58 * @param icallid Call ID.
     59 * @param icall   Call data.
     60 *
     61 */
     62static void default_connection_handler(ddf_fun_t *fun, ipc_callid_t icallid,
     63    ipc_call_t *icall)
     64{
     65        usb_mouse_t *mouse = (usb_mouse_t *) fun->driver_data;
     66        assert(mouse != NULL);
     67       
     68        async_sess_t *callback =
     69            async_callback_receive_start(EXCHANGE_SERIALIZE, icall);
     70       
     71        if (callback) {
     72                if (mouse->console_sess == NULL) {
     73                        mouse->console_sess = callback;
     74                        async_answer_0(icallid, EOK);
     75                } else
     76                        async_answer_0(icallid, ELIMIT);
     77        } else
     78                async_answer_0(icallid, EINVAL);
     79}
     80
    5581/** Device ops for USB mouse. */
    5682static ddf_dev_ops_t mouse_ops = {
    5783        .default_handler = default_connection_handler
    5884};
    59 
    60 /** Default handler for IPC methods not handled by DDF.
    61  *
    62  * @param fun Device function handling the call.
    63  * @param icallid Call id.
    64  * @param icall Call data.
    65  */
    66 void default_connection_handler(ddf_fun_t *fun,
    67     ipc_callid_t icallid, ipc_call_t *icall)
    68 {
    69         sysarg_t method = IPC_GET_IMETHOD(*icall);
    70 
    71         usb_mouse_t *mouse = (usb_mouse_t *) fun->driver_data;
    72         assert(mouse != NULL);
    73 
    74         if (method == IPC_M_CONNECT_TO_ME) {
    75                 int callback = IPC_GET_ARG5(*icall);
    76 
    77                 if (mouse->console_phone != -1) {
    78                         async_answer_0(icallid, ELIMIT);
    79                         return;
    80                 }
    81 
    82                 mouse->console_phone = callback;
    83                 async_answer_0(icallid, EOK);
    84                 return;
    85         }
    86 
    87         async_answer_0(icallid, EINVAL);
    88 }
    8985
    9086/** Create USB mouse device.
     
    9894{
    9995        usb_mouse_t *mouse = malloc(sizeof(usb_mouse_t));
    100         if (mouse == NULL) {
     96        if (mouse == NULL)
    10197                return ENOMEM;
    102         }
     98       
    10399        mouse->dev = dev;
    104         mouse->console_phone = -1;
    105 
     100        mouse->console_sess = NULL;
     101       
    106102        int rc;
    107 
     103       
    108104        /* Create DDF function. */
    109105        mouse->mouse_fun = ddf_fun_create(dev->ddf_dev, fun_exposed, "mouse");
     
    112108                goto leave;
    113109        }
    114 
     110       
    115111        mouse->mouse_fun->ops = &mouse_ops;
    116 
     112       
    117113        rc = ddf_fun_bind(mouse->mouse_fun);
    118         if (rc != EOK) {
     114        if (rc != EOK)
    119115                goto leave;
    120         }
    121 
     116       
    122117        /* Add the function to mouse class. */
    123118        rc = ddf_fun_add_to_class(mouse->mouse_fun, "mouse");
    124         if (rc != EOK) {
     119        if (rc != EOK)
    125120                goto leave;
    126         }
    127121       
    128122        /* Set the boot protocol. */
    129123        rc = usbhid_req_set_protocol(&dev->ctrl_pipe, dev->interface_no,
    130124            USB_HID_PROTOCOL_BOOT);
    131         if (rc != EOK) {
     125        if (rc != EOK)
    132126                goto leave;
    133         }
    134127       
    135         /* Everything all right. */
     128        /* Everything allright. */
    136129        dev->driver_data = mouse;
    137130        mouse->mouse_fun->driver_data = mouse;
    138 
     131       
    139132        return EOK;
    140 
     133       
    141134leave:
    142135        free(mouse);
    143 
    144136        return rc;
    145137}
Note: See TracChangeset for help on using the changeset viewer.