source: mainline/uspace/lib/usbdev/include/usb/dev/driver.h@ c54b898

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since c54b898 was c54b898, checked in by Petr Manek <petr.manek@…>, 7 years ago

usbdev: refactoring

The device_rem driver callback was renamed to device_remove. Also,
a new device_removed callback was introduced. This callback will fire
after all device pipes (endpoints, internally) are unregistered from
the HC device after a call to device_remove. It is semantically
a better opportunity for the USB device driver to free resources and
join all fibrils, since endpoint unregistration will force abort all
active transfers, waking up their issuers.

  • Property mode set to 100644
File size: 3.5 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 libusbdev
30 * @{
31 */
32/** @file
33 * USB device driver framework.
34 */
35
36#ifndef LIBUSBDEV_DRIVER_H_
37#define LIBUSBDEV_DRIVER_H_
38
39#include <usb/dev/device.h>
40#include <usb/dev/pipes.h>
41
42/** USB driver ops. */
43typedef struct {
44 /** Callback when a new device was added to the system. */
45 int (*device_add)(usb_device_t *);
46 /** Callback when a device is about to be removed from the system. */
47 int (*device_remove)(usb_device_t *);
48 /** Callback when a device has just been removed from the system (optional). */
49 int (*device_removed)(usb_device_t *);
50 /** Callback when a device was removed from the system. */
51 int (*device_gone)(usb_device_t *);
52 /** Callback asking the driver to online a specific function. */
53 int (*function_online)(ddf_fun_t *);
54 /** Callback asking the driver to offline a specific function. */
55 int (*function_offline)(ddf_fun_t *);
56} usb_driver_ops_t;
57
58/** USB driver structure. */
59typedef struct {
60 /** Driver name.
61 * This name is copied to the generic driver name and must be exactly
62 * the same as the directory name where the driver executable resides.
63 */
64 const char *name;
65 /** Expected endpoints description.
66 * This description shall exclude default control endpoint (pipe zero)
67 * and must be NULL terminated.
68 * When only control endpoint is expected, you may set NULL directly
69 * without creating one item array containing NULL.
70 *
71 * When the driver expect single interrupt in endpoint,
72 * the initialization may look like this:
73\code
74static usb_endpoint_description_t poll_endpoint_description = {
75 .transfer_type = USB_TRANSFER_INTERRUPT,
76 .direction = USB_DIRECTION_IN,
77 .interface_class = USB_CLASS_HUB,
78 .interface_subclass = 0,
79 .interface_protocol = 0,
80 .flags = 0
81};
82
83static usb_endpoint_description_t *hub_endpoints[] = {
84 &poll_endpoint_description,
85 NULL
86};
87
88static usb_driver_t hub_driver = {
89 .endpoints = hub_endpoints,
90 ...
91};
92\endcode
93 */
94 const usb_endpoint_description_t **endpoints;
95 /** Driver ops. */
96 const usb_driver_ops_t *ops;
97} usb_driver_t;
98
99int usb_driver_main(const usb_driver_t *);
100
101#endif
102/**
103 * @}
104 */
Note: See TracBrowser for help on using the repository browser.