blob: fbc112de532e2209a786b2c98e603ab02dad94f1 [file] [log] [blame]
Brian Swetland9a2cd262009-01-19 19:40:47 -08001/*
2 * Copyright (c) 2009, Google Inc.
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 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#ifndef __DEV_UDC_H
30#define __DEV_UDC_H
31
32/* USB Device Controller Transfer Request */
33struct udc_request {
34 void *buf;
35 unsigned length;
36 void (*complete)(struct udc_request *req, unsigned actual, int status);
37 void *context;
38};
39
40/* endpoints are opaque handles specific to the particular device controller */
41struct udc_endpoint;
42
43struct udc_request *udc_request_alloc(void);
44void udc_request_free(struct udc_request *req);
45int udc_request_queue(struct udc_endpoint *ept, struct udc_request *req);
46int udc_request_cancel(struct udc_endpoint *ept, struct udc_request *req);
47
48#define UDC_TYPE_BULK_IN 1
49#define UDC_TYPE_BULK_OUT 2
50
51struct udc_endpoint *udc_endpoint_alloc(unsigned type, unsigned maxpkt);
52void udc_endpoint_free(struct udc_endpoint *ept);
53
54#define UDC_EVENT_ONLINE 1
55#define UDC_EVENT_OFFLINE 2
56
57struct udc_gadget {
58 void (*notify)(struct udc_gadget *gadget, unsigned event);
59 void *context;
60
61 unsigned char ifc_class;
62 unsigned char ifc_subclass;
63 unsigned char ifc_protocol;
64 unsigned char ifc_endpoints;
65 const char *ifc_string;
66 unsigned flags;
67
68 struct udc_endpoint **ept;
69};
70
71struct udc_device {
72 unsigned short vendor_id;
73 unsigned short product_id;
74 unsigned short version_id;
75
76 const char *manufacturer;
77 const char *product;
78 const char *serialno;
79};
80
81int udc_init(struct udc_device *devinfo);
82int udc_register_gadget(struct udc_gadget *gadget);
83int udc_start(void);
84int udc_stop(void);
85
86/* these should probably go elsewhere */
87#define GET_STATUS 0
88#define CLEAR_FEATURE 1
89#define SET_FEATURE 3
90#define SET_ADDRESS 5
91#define GET_DESCRIPTOR 6
92#define SET_DESCRIPTOR 7
93#define GET_CONFIGURATION 8
94#define SET_CONFIGURATION 9
95#define GET_INTERFACE 10
96#define SET_INTERFACE 11
97#define SYNCH_FRAME 12
98
99#define TYPE_DEVICE 1
100#define TYPE_CONFIGURATION 2
101#define TYPE_STRING 3
102#define TYPE_INTERFACE 4
103#define TYPE_ENDPOINT 5
104
105#define DEVICE_READ 0x80
106#define DEVICE_WRITE 0x00
107#define INTERFACE_READ 0x81
108#define INTERFACE_WRITE 0x01
109#define ENDPOINT_READ 0x82
110#define ENDPOINT_WRITE 0x02
111
Subbaraman Narayanamurthyd8b7afc2011-06-30 15:42:41 -0700112#define TEST_PACKET 0x0400
113#define PORTSC_PTC (0xF << 16)
114#define PORTSC_PTC_TST_PKT (0x4 << 16)
115
Brian Swetland9a2cd262009-01-19 19:40:47 -0800116struct setup_packet {
117 unsigned char type;
118 unsigned char request;
119 unsigned short value;
120 unsigned short index;
121 unsigned short length;
122} __attribute__ ((packed));
123
124#endif