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

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

libusbdev: Use shared hc_connection for pipes.

  • Property mode set to 100644
File size: 6.2 KB
RevLine 
[6105fc0]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
[160b75e]29/** @addtogroup libusbdev
[6105fc0]30 * @{
31 */
32/** @file
33 * USB device driver framework.
34 */
[7d521e24]35#ifndef LIBUSBDEV_DRIVER_H_
36#define LIBUSBDEV_DRIVER_H_
[6105fc0]37
[7d521e24]38#include <usb/dev/pipes.h>
[6105fc0]39
[e484f3b]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. */
[7c95d6f5]45 const uint8_t *configuration;
[e484f3b]46 size_t configuration_size;
47} usb_device_descriptors_t;
48
[7526e3d9]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. */
[8a121b1]55 const usb_standard_interface_descriptor_t *interface;
[7526e3d9]56 /** Pointer to start of descriptor tree bound with this interface. */
[8a121b1]57 const uint8_t *nested_descriptors;
[7526e3d9]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
[69334af]72/** USB device structure. */
[6105fc0]73typedef struct {
[bd575647]74 usb_hc_connection_t hc_conn;
[7fc260ff]75 /** Connection backing the pipes.
76 * Typically, you will not need to use this attribute at all.
77 */
78 usb_device_connection_t wire;
[69334af]79 /** The default control pipe. */
[a372663]80 usb_pipe_t ctrl_pipe;
[69334af]81 /** Other endpoint pipes.
82 * This is an array of other endpoint pipes in the same order as
83 * in usb_driver_t.
84 */
[6105fc0]85 usb_endpoint_mapping_t *pipes;
[0b4e7ca]86 /** Number of other endpoint pipes. */
87 size_t pipes_count;
[d71691d]88 /** Current interface.
89 * Usually, drivers operate on single interface only.
90 * This item contains the value of the interface or -1 for any.
91 */
92 int interface_no;
[e484f3b]93
[904dcc6]94 /** Alternative interfaces. */
95 usb_alternate_interfaces_t alternate_interfaces;
[7526e3d9]96
[e484f3b]97 /** Some useful descriptors. */
98 usb_device_descriptors_t descriptors;
99
[7fc260ff]100 /** Generic DDF device backing this one. DO NOT TOUCH! */
[6105fc0]101 ddf_dev_t *ddf_dev;
[69334af]102 /** Custom driver data.
103 * Do not use the entry in generic device, that is already used
104 * by the framework.
105 */
[6105fc0]106 void *driver_data;
107} usb_device_t;
108
[69334af]109/** USB driver ops. */
[6105fc0]110typedef struct {
[1a4ea01d]111 /** Callback when a new device was added to the system. */
112 int (*device_add)(usb_device_t *);
[96646a6]113 /** Callback when a device is about to be removed from the system. */
114 int (*device_rem)(usb_device_t *);
115 /** Callback when a device was removed from the system. */
116 int (*device_gone)(usb_device_t *);
[6105fc0]117} usb_driver_ops_t;
118
[69334af]119/** USB driver structure. */
[6105fc0]120typedef struct {
[69334af]121 /** Driver name.
122 * This name is copied to the generic driver name and must be exactly
123 * the same as the directory name where the driver executable resides.
124 */
[6105fc0]125 const char *name;
[9bc276b]126 /** Expected endpoints description.
127 * This description shall exclude default control endpoint (pipe zero)
128 * and must be NULL terminated.
129 * When only control endpoint is expected, you may set NULL directly
130 * without creating one item array containing NULL.
[09daa8b]131 *
[9bc276b]132 * When the driver expect single interrupt in endpoint,
133 * the initialization may look like this:
134\code
135static usb_endpoint_description_t poll_endpoint_description = {
136 .transfer_type = USB_TRANSFER_INTERRUPT,
137 .direction = USB_DIRECTION_IN,
138 .interface_class = USB_CLASS_HUB,
139 .interface_subclass = 0,
140 .interface_protocol = 0,
141 .flags = 0
142};
143
144static usb_endpoint_description_t *hub_endpoints[] = {
145 &poll_endpoint_description,
146 NULL
147};
148
149static usb_driver_t hub_driver = {
150 .endpoints = hub_endpoints,
151 ...
152};
153\endcode
[09daa8b]154 */
[b803845]155 const usb_endpoint_description_t **endpoints;
[69334af]156 /** Driver ops. */
[49bd7ae2]157 const usb_driver_ops_t *ops;
[6105fc0]158} usb_driver_t;
159
[882580a]160int usb_driver_main(const usb_driver_t *);
[6105fc0]161
[7fc260ff]162int usb_device_init(usb_device_t *, ddf_dev_t *,
163 const usb_endpoint_description_t **, const char **);
164void usb_device_deinit(usb_device_t *);
165
[0b4e7ca]166int usb_device_select_interface(usb_device_t *, uint8_t,
[b803845]167 const usb_endpoint_description_t **);
[0b4e7ca]168
[c1b1944]169int usb_device_retrieve_descriptors(usb_pipe_t *, usb_device_descriptors_t *);
[7fc260ff]170void usb_device_release_descriptors(usb_device_descriptors_t *);
171
[8e5ce07]172int usb_device_create_pipes(const ddf_dev_t *, usb_device_connection_t *,
[b803845]173 const usb_endpoint_description_t **, const uint8_t *, size_t, int, int,
[c1b1944]174 usb_endpoint_mapping_t **, size_t *);
[8e5ce07]175int usb_device_destroy_pipes(const ddf_dev_t *, usb_endpoint_mapping_t *, size_t);
[96ec0a9]176
[065064e6]177void * usb_device_data_alloc(usb_device_t *, size_t);
[c1b1944]178
[7c95d6f5]179size_t usb_interface_count_alternates(const uint8_t *, size_t, uint8_t);
[904dcc6]180int usb_alternate_interfaces_init(usb_alternate_interfaces_t *,
181 const uint8_t *, size_t, int);
182void usb_alternate_interfaces_deinit(usb_alternate_interfaces_t *);
[6105fc0]183#endif
184/**
185 * @}
186 */
Note: See TracBrowser for help on using the repository browser.