blob: 7dc16c00af4cdf2f45e79709f0a45693de5483f2 [file] [log] [blame]
Brian Swetland9a2cd262009-01-19 19:40:47 -08001/*
2 * Copyright (c) 2009, Google Inc.
3 * All rights reserved.
Channagoud Kadabi5f8f1c42015-03-25 14:35:05 -07004 * Copyright (c) 2013-2015, 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;
vijay kumar9c9f1cf2014-01-15 16:05:28 +053039 void (*complete)();
Brian Swetland9a2cd262009-01-19 19:40:47 -080040 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
Channagoud Kadabi5f8f1c42015-03-25 14:35:05 -070053#define UDC_TYPE_INTR_IN 3
54#define UDC_TYPE_INTR_OUT 4
Brian Swetland9a2cd262009-01-19 19:40:47 -080055
56struct udc_endpoint *udc_endpoint_alloc(unsigned type, unsigned maxpkt);
57void udc_endpoint_free(struct udc_endpoint *ept);
58
59#define UDC_EVENT_ONLINE 1
60#define UDC_EVENT_OFFLINE 2
61
62struct udc_gadget {
63 void (*notify)(struct udc_gadget *gadget, unsigned event);
64 void *context;
65
66 unsigned char ifc_class;
67 unsigned char ifc_subclass;
68 unsigned char ifc_protocol;
69 unsigned char ifc_endpoints;
70 const char *ifc_string;
71 unsigned flags;
72
73 struct udc_endpoint **ept;
74};
75
76struct udc_device {
77 unsigned short vendor_id;
78 unsigned short product_id;
79 unsigned short version_id;
80
81 const char *manufacturer;
82 const char *product;
83 const char *serialno;
Channagoud Kadabi77b52272014-02-04 17:01:16 -080084 target_usb_iface_t *t_usb_if;
Brian Swetland9a2cd262009-01-19 19:40:47 -080085};
Amol Jadiaeae9f42013-07-23 14:38:35 -070086
Brian Swetland9a2cd262009-01-19 19:40:47 -080087int udc_init(struct udc_device *devinfo);
88int udc_register_gadget(struct udc_gadget *gadget);
89int udc_start(void);
90int udc_stop(void);
91
92/* these should probably go elsewhere */
93#define GET_STATUS 0
94#define CLEAR_FEATURE 1
95#define SET_FEATURE 3
96#define SET_ADDRESS 5
97#define GET_DESCRIPTOR 6
98#define SET_DESCRIPTOR 7
99#define GET_CONFIGURATION 8
100#define SET_CONFIGURATION 9
101#define GET_INTERFACE 10
102#define SET_INTERFACE 11
103#define SYNCH_FRAME 12
Amol Jadiaeae9f42013-07-23 14:38:35 -0700104#define SET_SEL 48
Channagoud Kadabi363e7402015-06-16 11:44:20 -0700105#define SET_ISOCH_DELAY 49
Brian Swetland9a2cd262009-01-19 19:40:47 -0800106
107#define TYPE_DEVICE 1
108#define TYPE_CONFIGURATION 2
109#define TYPE_STRING 3
110#define TYPE_INTERFACE 4
111#define TYPE_ENDPOINT 5
Channagoud Kadabi363e7402015-06-16 11:44:20 -0700112#define TYPE_DEVICE_QUALIFIER 6
113#define TYPE_OTHER_SPEED_CONFIG 7
Amol Jadiaeae9f42013-07-23 14:38:35 -0700114#define TYPE_BOS 15
115#define TYPE_DEVICE_CAP 16
116#define TYPE_SS_EP_COMP 48
Brian Swetland9a2cd262009-01-19 19:40:47 -0800117
118#define DEVICE_READ 0x80
119#define DEVICE_WRITE 0x00
120#define INTERFACE_READ 0x81
121#define INTERFACE_WRITE 0x01
122#define ENDPOINT_READ 0x82
123#define ENDPOINT_WRITE 0x02
Channagoud Kadabi363e7402015-06-16 11:44:20 -0700124#define TEST_MODE 0x02
Brian Swetland9a2cd262009-01-19 19:40:47 -0800125
Channagoud Kadabi363e7402015-06-16 11:44:20 -0700126#define TEST_J 0x0100
127#define TEST_K 0x0200
Shashank Mittal2523e0b2011-10-14 17:32:46 -0700128#define TEST_SE0_NAK 0x0300
Subbaraman Narayanamurthyd8b7afc2011-06-30 15:42:41 -0700129#define TEST_PACKET 0x0400
Channagoud Kadabi363e7402015-06-16 11:44:20 -0700130#define TEST_FORCE_ENABLE 0x0500
131
Subbaraman Narayanamurthyd8b7afc2011-06-30 15:42:41 -0700132#define PORTSC_PTC (0xF << 16)
Shashank Mittal2523e0b2011-10-14 17:32:46 -0700133#define PORTSC_PTC_SE0_NAK (0x03 << 16)
Subbaraman Narayanamurthyd8b7afc2011-06-30 15:42:41 -0700134#define PORTSC_PTC_TST_PKT (0x4 << 16)
135
Channagoud Kadabide1c1622014-01-13 11:39:06 -0800136#define USB_EP_NUM_MASK 0x0f
137#define USB_EP_DIR_MASK 0x80
138#define USB_EP_DIR_IN 0x80
139
Brian Swetland9a2cd262009-01-19 19:40:47 -0800140struct setup_packet {
141 unsigned char type;
142 unsigned char request;
143 unsigned short value;
144 unsigned short index;
145 unsigned short length;
146} __attribute__ ((packed));
147
148#endif