Brian Swetland | 9a2cd26 | 2009-01-19 19:40:47 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2009, Google Inc. |
| 3 | * All rights reserved. |
Amol Jadi | aeae9f4 | 2013-07-23 14:38:35 -0700 | [diff] [blame] | 4 | * Copyright (c) 2013, The Linux Foundation. All rights reserved. |
Brian Swetland | 9a2cd26 | 2009-01-19 19:40:47 -0800 | [diff] [blame] | 5 | * |
| 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 Jadi | aeae9f4 | 2013-07-23 14:38:35 -0700 | [diff] [blame] | 13 | * the documentation and/or other materials provided with the |
Brian Swetland | 9a2cd26 | 2009-01-19 19:40:47 -0800 | [diff] [blame] | 14 | * 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 Jadi | aeae9f4 | 2013-07-23 14:38:35 -0700 | [diff] [blame] | 23 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
Brian Swetland | 9a2cd26 | 2009-01-19 19:40:47 -0800 | [diff] [blame] | 24 | * 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 */ |
| 34 | struct udc_request { |
| 35 | void *buf; |
| 36 | unsigned length; |
vijay kumar | 35aebef | 2014-01-15 16:05:28 +0530 | [diff] [blame] | 37 | void (*complete)(); |
Brian Swetland | 9a2cd26 | 2009-01-19 19:40:47 -0800 | [diff] [blame] | 38 | void *context; |
| 39 | }; |
| 40 | |
| 41 | /* endpoints are opaque handles specific to the particular device controller */ |
| 42 | struct udc_endpoint; |
| 43 | |
| 44 | struct udc_request *udc_request_alloc(void); |
| 45 | void udc_request_free(struct udc_request *req); |
| 46 | int udc_request_queue(struct udc_endpoint *ept, struct udc_request *req); |
| 47 | int 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 | |
| 52 | struct udc_endpoint *udc_endpoint_alloc(unsigned type, unsigned maxpkt); |
| 53 | void udc_endpoint_free(struct udc_endpoint *ept); |
| 54 | |
| 55 | #define UDC_EVENT_ONLINE 1 |
| 56 | #define UDC_EVENT_OFFLINE 2 |
| 57 | |
| 58 | struct 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 | |
| 72 | struct 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 Jadi | aeae9f4 | 2013-07-23 14:38:35 -0700 | [diff] [blame] | 81 | |
Brian Swetland | 9a2cd26 | 2009-01-19 19:40:47 -0800 | [diff] [blame] | 82 | int udc_init(struct udc_device *devinfo); |
| 83 | int udc_register_gadget(struct udc_gadget *gadget); |
| 84 | int udc_start(void); |
| 85 | int 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 Jadi | aeae9f4 | 2013-07-23 14:38:35 -0700 | [diff] [blame] | 99 | #define SET_SEL 48 |
Brian Swetland | 9a2cd26 | 2009-01-19 19:40:47 -0800 | [diff] [blame] | 100 | |
| 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 Jadi | aeae9f4 | 2013-07-23 14:38:35 -0700 | [diff] [blame] | 106 | #define TYPE_BOS 15 |
| 107 | #define TYPE_DEVICE_CAP 16 |
| 108 | #define TYPE_SS_EP_COMP 48 |
Brian Swetland | 9a2cd26 | 2009-01-19 19:40:47 -0800 | [diff] [blame] | 109 | |
| 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 Mittal | 2523e0b | 2011-10-14 17:32:46 -0700 | [diff] [blame] | 117 | #define TEST_SE0_NAK 0x0300 |
Subbaraman Narayanamurthy | d8b7afc | 2011-06-30 15:42:41 -0700 | [diff] [blame] | 118 | #define TEST_PACKET 0x0400 |
| 119 | #define PORTSC_PTC (0xF << 16) |
Shashank Mittal | 2523e0b | 2011-10-14 17:32:46 -0700 | [diff] [blame] | 120 | #define PORTSC_PTC_SE0_NAK (0x03 << 16) |
Subbaraman Narayanamurthy | d8b7afc | 2011-06-30 15:42:41 -0700 | [diff] [blame] | 121 | #define PORTSC_PTC_TST_PKT (0x4 << 16) |
| 122 | |
Brian Swetland | 9a2cd26 | 2009-01-19 19:40:47 -0800 | [diff] [blame] | 123 | struct 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 |