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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since bdb23c63 was bdb23c63, checked in by Jan Vesely <jano.vesely@…>, 14 years ago

libusbdev: Remove unused mutex.

  • Property mode set to 100644
File size: 6.2 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#ifndef LIBUSBDEV_DRIVER_H_
36#define LIBUSBDEV_DRIVER_H_
37
38#include <usb/dev/pipes.h>
39
40/** Descriptors for USB device. */
41typedef struct {
42 /** Standard device descriptor. */
43 usb_standard_device_descriptor_t device;
44 /** Full configuration descriptor of current configuration. */
45 const uint8_t *configuration;
46 size_t configuration_size;
47} usb_device_descriptors_t;
48
49/** Wrapper for data related to alternate interface setting.
50 * The pointers will typically point inside configuration descriptor and
51 * thus you shall not deallocate them.
52 */
53typedef struct {
54 /** Interface descriptor. */
55 const usb_standard_interface_descriptor_t *interface;
56 /** Pointer to start of descriptor tree bound with this interface. */
57 const uint8_t *nested_descriptors;
58 /** Size of data pointed by nested_descriptors in bytes. */
59 size_t nested_descriptors_size;
60} usb_alternate_interface_descriptors_t;
61
62/** Alternate interface settings. */
63typedef struct {
64 /** Array of alternate interfaces descriptions. */
65 usb_alternate_interface_descriptors_t *alternatives;
66 /** Size of @c alternatives array. */
67 size_t alternative_count;
68 /** Index of currently selected one. */
69 size_t current;
70} usb_alternate_interfaces_t;
71
72/** USB device structure. */
73typedef struct {
74 /** Connection to USB hc, used by wire and arbitrary requests. */
75 usb_hc_connection_t hc_conn;
76 /** Connection backing the pipes.
77 * Typically, you will not need to use this attribute at all.
78 */
79 usb_device_connection_t wire;
80 /** The default control pipe. */
81 usb_pipe_t ctrl_pipe;
82 /** Other endpoint pipes.
83 * This is an array of other endpoint pipes in the same order as
84 * in usb_driver_t.
85 */
86 usb_endpoint_mapping_t *pipes;
87 /** Number of other endpoint pipes. */
88 size_t pipes_count;
89 /** Current interface.
90 * Usually, drivers operate on single interface only.
91 * This item contains the value of the interface or -1 for any.
92 */
93 int interface_no;
94
95 /** Alternative interfaces. */
96 usb_alternate_interfaces_t alternate_interfaces;
97
98 /** Some useful descriptors. */
99 usb_device_descriptors_t descriptors;
100
101 /** Generic DDF device backing this one. DO NOT TOUCH! */
102 ddf_dev_t *ddf_dev;
103 /** Custom driver data.
104 * Do not use the entry in generic device, that is already used
105 * by the framework.
106 */
107 void *driver_data;
108} usb_device_t;
109
110/** USB driver ops. */
111typedef struct {
112 /** Callback when a new device was added to the system. */
113 int (*device_add)(usb_device_t *);
114 /** Callback when a device is about to be removed from the system. */
115 int (*device_rem)(usb_device_t *);
116 /** Callback when a device was removed from the system. */
117 int (*device_gone)(usb_device_t *);
118} usb_driver_ops_t;
119
120/** USB driver structure. */
121typedef struct {
122 /** Driver name.
123 * This name is copied to the generic driver name and must be exactly
124 * the same as the directory name where the driver executable resides.
125 */
126 const char *name;
127 /** Expected endpoints description.
128 * This description shall exclude default control endpoint (pipe zero)
129 * and must be NULL terminated.
130 * When only control endpoint is expected, you may set NULL directly
131 * without creating one item array containing NULL.
132 *
133 * When the driver expect single interrupt in endpoint,
134 * the initialization may look like this:
135\code
136static usb_endpoint_description_t poll_endpoint_description = {
137 .transfer_type = USB_TRANSFER_INTERRUPT,
138 .direction = USB_DIRECTION_IN,
139 .interface_class = USB_CLASS_HUB,
140 .interface_subclass = 0,
141 .interface_protocol = 0,
142 .flags = 0
143};
144
145static usb_endpoint_description_t *hub_endpoints[] = {
146 &poll_endpoint_description,
147 NULL
148};
149
150static usb_driver_t hub_driver = {
151 .endpoints = hub_endpoints,
152 ...
153};
154\endcode
155 */
156 const usb_endpoint_description_t **endpoints;
157 /** Driver ops. */
158 const usb_driver_ops_t *ops;
159} usb_driver_t;
160
161int usb_driver_main(const usb_driver_t *);
162
163int usb_device_init(usb_device_t *, ddf_dev_t *,
164 const usb_endpoint_description_t **, const char **);
165void usb_device_deinit(usb_device_t *);
166
167int usb_device_select_interface(usb_device_t *, uint8_t,
168 const usb_endpoint_description_t **);
169
170int usb_device_retrieve_descriptors(usb_pipe_t *, usb_device_descriptors_t *);
171void usb_device_release_descriptors(usb_device_descriptors_t *);
172
173int usb_device_create_pipes(const ddf_dev_t *, usb_device_connection_t *,
174 const usb_endpoint_description_t **, const uint8_t *, size_t, int, int,
175 usb_endpoint_mapping_t **, size_t *);
176int usb_device_destroy_pipes(const ddf_dev_t *, usb_endpoint_mapping_t *, size_t);
177
178void * usb_device_data_alloc(usb_device_t *, size_t);
179
180size_t usb_interface_count_alternates(const uint8_t *, size_t, uint8_t);
181int usb_alternate_interfaces_init(usb_alternate_interfaces_t *,
182 const uint8_t *, size_t, int);
183void usb_alternate_interfaces_deinit(usb_alternate_interfaces_t *);
184#endif
185/**
186 * @}
187 */
Note: See TracBrowser for help on using the repository browser.