source: mainline/uspace/drv/bus/usb/usbmouse/init.c@ 763e0cd

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 763e0cd was 1dc4a5e, checked in by Jiri Svoboda <jiri@…>, 14 years ago

Renaming to reflect classes are gone.

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 * Copyright (c) 2011 Vojtech Horky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup drvusbmouse
30 * @{
31 */
32/**
33 * @file
34 * Initialization routines for USB mouse driver.
35 */
36
37#include "mouse.h"
38#include <usb/debug.h>
39#include <usb/classes/classes.h>
40#include <usb/hid/hid.h>
41#include <usb/dev/request.h>
42#include <usb/hid/request.h>
43#include <errno.h>
44
45/** Mouse polling endpoint description for boot protocol subclass. */
46usb_endpoint_description_t poll_endpoint_description = {
47 .transfer_type = USB_TRANSFER_INTERRUPT,
48 .direction = USB_DIRECTION_IN,
49 .interface_class = USB_CLASS_HID,
50 .interface_subclass = USB_HID_SUBCLASS_BOOT,
51 .interface_protocol = USB_HID_PROTOCOL_MOUSE,
52 .flags = 0
53};
54
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
81/** Device ops for USB mouse. */
82static ddf_dev_ops_t mouse_ops = {
83 .default_handler = default_connection_handler
84};
85
86/** Create USB mouse device.
87 *
88 * The mouse device is stored into <code>dev-&gt;driver_data</code>.
89 *
90 * @param dev Generic device.
91 * @return Error code.
92 */
93int usb_mouse_create(usb_device_t *dev)
94{
95 usb_mouse_t *mouse = malloc(sizeof(usb_mouse_t));
96 if (mouse == NULL)
97 return ENOMEM;
98
99 mouse->dev = dev;
100 mouse->console_sess = NULL;
101
102 int rc;
103
104 /* Create DDF function. */
105 mouse->mouse_fun = ddf_fun_create(dev->ddf_dev, fun_exposed, "mouse");
106 if (mouse->mouse_fun == NULL) {
107 rc = ENOMEM;
108 goto leave;
109 }
110
111 mouse->mouse_fun->ops = &mouse_ops;
112
113 rc = ddf_fun_bind(mouse->mouse_fun);
114 if (rc != EOK)
115 goto leave;
116
117 /* Add the function to mouse class. */
118 rc = ddf_fun_add_to_category(mouse->mouse_fun, "mouse");
119 if (rc != EOK)
120 goto leave;
121
122 /* Set the boot protocol. */
123 rc = usbhid_req_set_protocol(&dev->ctrl_pipe, dev->interface_no,
124 USB_HID_PROTOCOL_BOOT);
125 if (rc != EOK)
126 goto leave;
127
128 /* Everything allright. */
129 dev->driver_data = mouse;
130 mouse->mouse_fun->driver_data = mouse;
131
132 return EOK;
133
134leave:
135 free(mouse);
136 return rc;
137}
138
139/**
140 * @}
141 */
Note: See TracBrowser for help on using the repository browser.