blob: f58b7b4ddc6928a2ff3ccb37d45bdc4e60d1ca41 [file] [log] [blame]
Brian Swetland9a2cd262009-01-19 19:40:47 -08001/*
2 * Copyright (c) 2009, Google Inc.
3 * All rights reserved.
Channagoud Kadabide1c1622014-01-13 11:39:06 -08004 * Copyright (c) 2013-2014, 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
Channagoud Kadabi77b52272014-02-04 17:01:16 -080033#include <target.h>
34
Brian Swetland9a2cd262009-01-19 19:40:47 -080035/* USB Device Controller Transfer Request */
36struct udc_request {
37 void *buf;
38 unsigned length;
39 void (*complete)(struct udc_request *req, unsigned actual, int status);
40 void *context;
41};
42
43/* endpoints are opaque handles specific to the particular device controller */
44struct udc_endpoint;
45
46struct udc_request *udc_request_alloc(void);
47void udc_request_free(struct udc_request *req);
48int udc_request_queue(struct udc_endpoint *ept, struct udc_request *req);
49int udc_request_cancel(struct udc_endpoint *ept, struct udc_request *req);
50
51#define UDC_TYPE_BULK_IN 1
52#define UDC_TYPE_BULK_OUT 2
53
54struct udc_endpoint *udc_endpoint_alloc(unsigned type, unsigned maxpkt);
55void udc_endpoint_free(struct udc_endpoint *ept);
56
57#define UDC_EVENT_ONLINE 1
58#define UDC_EVENT_OFFLINE 2
59
60struct udc_gadget {
61 void (*notify)(struct udc_gadget *gadget, unsigned event);
62 void *context;
63
64 unsigned char ifc_class;
65 unsigned char ifc_subclass;
66 unsigned char ifc_protocol;
67 unsigned char ifc_endpoints;
68 const char *ifc_string;
69 unsigned flags;
70
71 struct udc_endpoint **ept;
72};
73
74struct udc_device {
75 unsigned short vendor_id;
76 unsigned short product_id;
77 unsigned short version_id;
78
79 const char *manufacturer;
80 const char *product;
81 const char *serialno;
Channagoud Kadabi77b52272014-02-04 17:01:16 -080082 target_usb_iface_t *t_usb_if;
Brian Swetland9a2cd262009-01-19 19:40:47 -080083};
Amol Jadiaeae9f42013-07-23 14:38:35 -070084
Brian Swetland9a2cd262009-01-19 19:40:47 -080085int udc_init(struct udc_device *devinfo);
86int udc_register_gadget(struct udc_gadget *gadget);
87int udc_start(void);
88int udc_stop(void);
89
90/* these should probably go elsewhere */
91#define GET_STATUS 0
92#define CLEAR_FEATURE 1
93#define SET_FEATURE 3
94#define SET_ADDRESS 5
95#define GET_DESCRIPTOR 6
96#define SET_DESCRIPTOR 7
97#define GET_CONFIGURATION 8
98#define SET_CONFIGURATION 9
99#define GET_INTERFACE 10
100#define SET_INTERFACE 11
101#define SYNCH_FRAME 12
Amol Jadiaeae9f42013-07-23 14:38:35 -0700102#define SET_SEL 48
Brian Swetland9a2cd262009-01-19 19:40:47 -0800103
104#define TYPE_DEVICE 1
105#define TYPE_CONFIGURATION 2
106#define TYPE_STRING 3
107#define TYPE_INTERFACE 4
108#define TYPE_ENDPOINT 5
Amol Jadiaeae9f42013-07-23 14:38:35 -0700109#define TYPE_BOS 15
110#define TYPE_DEVICE_CAP 16
111#define TYPE_SS_EP_COMP 48
Brian Swetland9a2cd262009-01-19 19:40:47 -0800112
113#define DEVICE_READ 0x80
114#define DEVICE_WRITE 0x00
115#define INTERFACE_READ 0x81
116#define INTERFACE_WRITE 0x01
117#define ENDPOINT_READ 0x82
118#define ENDPOINT_WRITE 0x02
119
Shashank Mittal2523e0b2011-10-14 17:32:46 -0700120#define TEST_SE0_NAK 0x0300
Subbaraman Narayanamurthyd8b7afc2011-06-30 15:42:41 -0700121#define TEST_PACKET 0x0400
122#define PORTSC_PTC (0xF << 16)
Shashank Mittal2523e0b2011-10-14 17:32:46 -0700123#define PORTSC_PTC_SE0_NAK (0x03 << 16)
Subbaraman Narayanamurthyd8b7afc2011-06-30 15:42:41 -0700124#define PORTSC_PTC_TST_PKT (0x4 << 16)
125
Channagoud Kadabide1c1622014-01-13 11:39:06 -0800126#define USB_EP_NUM_MASK 0x0f
127#define USB_EP_DIR_MASK 0x80
128#define USB_EP_DIR_IN 0x80
129
Brian Swetland9a2cd262009-01-19 19:40:47 -0800130struct setup_packet {
131 unsigned char type;
132 unsigned char request;
133 unsigned short value;
134 unsigned short index;
135 unsigned short length;
136} __attribute__ ((packed));
137
138#endif