]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/usb/template/usb_template.h
Provide a public function to acquire a gpio pin by giving the property name
[FreeBSD/FreeBSD.git] / sys / dev / usb / template / usb_template.h
1 /* $FreeBSD$ */
2 /*-
3  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4  *
5  * Copyright (c) 2007 Hans Petter Selasky <hselasky@FreeBSD.org>
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29
30 /* USB templates are used to build up real USB descriptors */
31
32 #ifndef _USB_TEMPLATE_H_
33 #define _USB_TEMPLATE_H_
34
35 #ifndef USB_TEMPLATE_VENDOR
36 #define USB_TEMPLATE_VENDOR     0x0001
37 #endif
38
39 typedef const void *(usb_temp_get_string_desc_t)(uint16_t lang_id, uint8_t string_index);
40 typedef const void *(usb_temp_get_vendor_desc_t)(const struct usb_device_request *req, uint16_t *plen);
41
42 struct usb_temp_packet_size {
43         uint16_t mps[USB_SPEED_MAX];
44 };
45
46 struct usb_temp_interval {
47         uint8_t bInterval[USB_SPEED_MAX];
48 };
49
50 struct usb_temp_endpoint_desc {
51         const void **ppRawDesc;
52         const struct usb_temp_packet_size *pPacketSize;
53         const struct usb_temp_interval *pIntervals;
54         /*
55          * If (bEndpointAddress & UE_ADDR) is non-zero the endpoint number
56          * is pre-selected for this endpoint descriptor. Else an endpoint
57          * number is automatically chosen.
58          */
59         uint8_t bEndpointAddress;       /* UE_DIR_IN or UE_DIR_OUT */
60         uint8_t bmAttributes;
61 };
62
63 struct usb_temp_interface_desc {
64         const void **ppRawDesc;
65         const struct usb_temp_endpoint_desc **ppEndpoints;
66         uint8_t bInterfaceClass;
67         uint8_t bInterfaceSubClass;
68         uint8_t bInterfaceProtocol;
69         uint8_t iInterface;
70         uint8_t isAltInterface;
71 };
72
73 struct usb_temp_config_desc {
74         const struct usb_temp_interface_desc **ppIfaceDesc;
75         uint8_t bmAttributes;
76         uint8_t bMaxPower;
77         uint8_t iConfiguration;
78 };
79
80 struct usb_temp_device_desc {
81         usb_temp_get_string_desc_t *getStringDesc;
82         usb_temp_get_vendor_desc_t *getVendorDesc;
83         const struct usb_temp_config_desc **ppConfigDesc;
84         uint16_t idVendor;
85         uint16_t idProduct;
86         uint16_t bcdDevice;
87         uint8_t bDeviceClass;
88         uint8_t bDeviceSubClass;
89         uint8_t bDeviceProtocol;
90         uint8_t iManufacturer;
91         uint8_t iProduct;
92         uint8_t iSerialNumber;
93 };
94
95 struct usb_temp_data {
96         const struct usb_temp_device_desc *tdd;
97         struct usb_device_descriptor udd;       /* device descriptor */
98         struct usb_device_qualifier udq;        /* device qualifier */
99 };
100
101 /* prototypes */
102
103 extern struct usb_temp_device_desc usb_template_audio;
104 extern struct usb_temp_device_desc usb_template_cdce;
105 extern struct usb_temp_device_desc usb_template_kbd;
106 extern struct usb_temp_device_desc usb_template_modem;
107 extern struct usb_temp_device_desc usb_template_mouse;
108 extern struct usb_temp_device_desc usb_template_msc;
109 extern struct usb_temp_device_desc usb_template_mtp;
110 extern struct usb_temp_device_desc usb_template_phone;
111 extern struct usb_temp_device_desc usb_template_serialnet;
112 extern struct usb_temp_device_desc usb_template_midi;
113
114
115 void            usb_decode_str_desc(struct usb_string_descriptor *sd,
116                     char *buf, size_t buflen);
117 usb_error_t     usb_temp_setup(struct usb_device *,
118                     const struct usb_temp_device_desc *);
119 void            usb_temp_unsetup(struct usb_device *);
120 int             usb_temp_sysctl(SYSCTL_HANDLER_ARGS);
121
122 SYSCTL_DECL(_hw_usb_templates);
123
124 #endif                                  /* _USB_TEMPLATE_H_ */