Ignore:
File:
1 edited

Legend:

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

    r4a4c8bcf rb59ec8c  
    3434 * Initialization routines for USB mouse driver.
    3535 */
    36 
    3736#include "mouse.h"
    3837#include <usb/debug.h>
     
    5352};
    5453
    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  */
    62 static 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 
     54static void default_connection_handler(ddf_fun_t *, ipc_callid_t, ipc_call_t *);
    8155/** Device ops for USB mouse. */
    8256static ddf_dev_ops_t mouse_ops = {
    8357        .default_handler = default_connection_handler
    8458};
     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 */
     66void 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}
    8589
    8690/** Create USB mouse device.
     
    9498{
    9599        usb_mouse_t *mouse = malloc(sizeof(usb_mouse_t));
    96         if (mouse == NULL)
     100        if (mouse == NULL) {
    97101                return ENOMEM;
    98        
     102        }
    99103        mouse->dev = dev;
    100         mouse->console_sess = NULL;
    101        
     104        mouse->console_phone = -1;
     105
    102106        int rc;
    103        
     107
    104108        /* Create DDF function. */
    105109        mouse->mouse_fun = ddf_fun_create(dev->ddf_dev, fun_exposed, "mouse");
     
    108112                goto leave;
    109113        }
    110        
     114
    111115        mouse->mouse_fun->ops = &mouse_ops;
    112        
     116
    113117        rc = ddf_fun_bind(mouse->mouse_fun);
    114         if (rc != EOK)
     118        if (rc != EOK) {
    115119                goto leave;
    116        
     120        }
     121
    117122        /* Add the function to mouse class. */
    118123        rc = ddf_fun_add_to_class(mouse->mouse_fun, "mouse");
    119         if (rc != EOK)
     124        if (rc != EOK) {
    120125                goto leave;
     126        }
    121127       
    122128        /* Set the boot protocol. */
    123129        rc = usbhid_req_set_protocol(&dev->ctrl_pipe, dev->interface_no,
    124130            USB_HID_PROTOCOL_BOOT);
    125         if (rc != EOK)
     131        if (rc != EOK) {
    126132                goto leave;
     133        }
    127134       
    128         /* Everything allright. */
     135        /* Everything all right. */
    129136        dev->driver_data = mouse;
    130137        mouse->mouse_fun->driver_data = mouse;
    131        
     138
    132139        return EOK;
    133        
     140
    134141leave:
    135142        free(mouse);
     143
    136144        return rc;
    137145}
Note: See TracChangeset for help on using the changeset viewer.