blob: aa1aadd0d08af5a4a1745916eca7b6fae02b2b2a [file] [log] [blame]
Brian Swetland9a2cd262009-01-19 19:40:47 -08001/*
2 * Copyright (c) 2009, Google Inc.
3 * All rights reserved.
Amol Jadiaeae9f42013-07-23 14:38:35 -07004 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
Brian Swetland9a2cd262009-01-19 19:40:47 -08005 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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
Amol Jadiaeae9f42013-07-23 14:38:35 -070013 * the documentation and/or other materials provided with the
Brian Swetland9a2cd262009-01-19 19:40:47 -080014 * distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
Amol Jadiaeae9f42013-07-23 14:38:35 -070023 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
Brian Swetland9a2cd262009-01-19 19:40:47 -080024 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#ifndef __DEV_UDC_H
31#define __DEV_UDC_H
32
33/* USB Device Controller Transfer Request */
34struct udc_request {
35 void *buf;
36 unsigned length;
vijay kumar35aebef2014-01-15 16:05:28 +053037 void (*complete)();
Brian Swetland9a2cd262009-01-19 19:40:47 -080038 void *context;
39};
40
41/* endpoints are opaque handles specific to the particular device controller */
42struct udc_endpoint;
43
44struct udc_request *udc_request_alloc(void);
45void udc_request_free(struct udc_request *req);
46int udc_request_queue(struct udc_endpoint *ept, struct udc_request *req);
47int udc_request_cancel(struct udc_endpoint *ept, struct udc_request *req);
48
49#define UDC_TYPE_BULK_IN 1
50#define UDC_TYPE_BULK_OUT 2
51
52struct udc_endpoint *udc_endpoint_alloc(unsigned type, unsigned maxpkt);
53void udc_endpoint_free(struct udc_endpoint *ept);
54
55#define UDC_EVENT_ONLINE 1
56#define UDC_EVENT_OFFLINE 2
57
58struct udc_gadget {
59 void (*notify)(struct udc_gadget *gadget, unsigned event);
60 void *context;
61
62 unsigned char ifc_class;
63 unsigned char ifc_subclass;
64 unsigned char ifc_protocol;
65 unsigned char ifc_endpoints;
66 const char *ifc_string;
67 unsigned flags;
68
69 struct udc_endpoint **ept;
70};
71
72struct udc_device {
73 unsigned short vendor_id;
74 unsigned short product_id;
75 unsigned short version_id;
76
77 const char *manufacturer;
78 const char *product;
79 const char *serialno;
80};
Amol Jadiaeae9f42013-07-23 14:38:35 -070081
Brian Swetland9a2cd262009-01-19 19:40:47 -080082int udc_init(struct udc_device *devinfo);
83int udc_register_gadget(struct udc_gadget *gadget);
84int udc_start(void);
85int udc_stop(void);
86
87/* these should probably go elsewhere */
88#define GET_STATUS 0
89#define CLEAR_FEATURE 1
90#define SET_FEATURE 3
91#define SET_ADDRESS 5
92#define GET_DESCRIPTOR 6
93#define SET_DESCRIPTOR 7
94#define GET_CONFIGURATION 8
95#define SET_CONFIGURATION 9
96#define GET_INTERFACE 10
97#define SET_INTERFACE 11
98#define SYNCH_FRAME 12
Amol Jadiaeae9f42013-07-23 14:38:35 -070099#define SET_SEL 48
Brian Swetland9a2cd262009-01-19 19:40:47 -0800100
101#define TYPE_DEVICE 1
102#define TYPE_CONFIGURATION 2
103#define TYPE_STRING 3
104#define TYPE_INTERFACE 4
105#define TYPE_ENDPOINT 5
Amol Jadiaeae9f42013-07-23 14:38:35 -0700106#define TYPE_BOS 15
107#define TYPE_DEVICE_CAP 16
108#define TYPE_SS_EP_COMP 48
Brian Swetland9a2cd262009-01-19 19:40:47 -0800109
110#define DEVICE_READ 0x80
111#define DEVICE_WRITE 0x00
112#define INTERFACE_READ 0x81
113#define INTERFACE_WRITE 0x01
114#define ENDPOINT_READ 0x82
115#define ENDPOINT_WRITE 0x02
116
Shashank Mittal2523e0b2011-10-14 17:32:46 -0700117#define TEST_SE0_NAK 0x0300
Subbaraman Narayanamurthyd8b7afc2011-06-30 15:42:41 -0700118#define TEST_PACKET 0x0400
119#define PORTSC_PTC (0xF << 16)
Shashank Mittal2523e0b2011-10-14 17:32:46 -0700120#define PORTSC_PTC_SE0_NAK (0x03 << 16)
Subbaraman Narayanamurthyd8b7afc2011-06-30 15:42:41 -0700121#define PORTSC_PTC_TST_PKT (0x4 << 16)
122
Brian Swetland9a2cd262009-01-19 19:40:47 -0800123struct setup_packet {
124 unsigned char type;
125 unsigned char request;
126 unsigned short value;
127 unsigned short index;
128 unsigned short length;
129} __attribute__ ((packed));
130
131#endif