Brian Swetland | 9a2cd26 | 2009-01-19 19:40:47 -0800 | [diff] [blame] | 1 | /* |
| 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 */ |
| 33 | struct 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 */ |
| 41 | struct udc_endpoint; |
| 42 | |
| 43 | struct udc_request *udc_request_alloc(void); |
| 44 | void udc_request_free(struct udc_request *req); |
| 45 | int udc_request_queue(struct udc_endpoint *ept, struct udc_request *req); |
| 46 | int 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 | |
| 51 | struct udc_endpoint *udc_endpoint_alloc(unsigned type, unsigned maxpkt); |
| 52 | void udc_endpoint_free(struct udc_endpoint *ept); |
| 53 | |
| 54 | #define UDC_EVENT_ONLINE 1 |
| 55 | #define UDC_EVENT_OFFLINE 2 |
| 56 | |
| 57 | struct 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 | |
| 71 | struct 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 | |
| 81 | int udc_init(struct udc_device *devinfo); |
| 82 | int udc_register_gadget(struct udc_gadget *gadget); |
| 83 | int udc_start(void); |
| 84 | int 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 | |
Shashank Mittal | 2523e0b | 2011-10-14 17:32:46 -0700 | [diff] [blame] | 112 | #define TEST_SE0_NAK 0x0300 |
Subbaraman Narayanamurthy | d8b7afc | 2011-06-30 15:42:41 -0700 | [diff] [blame] | 113 | #define TEST_PACKET 0x0400 |
| 114 | #define PORTSC_PTC (0xF << 16) |
Shashank Mittal | 2523e0b | 2011-10-14 17:32:46 -0700 | [diff] [blame] | 115 | #define PORTSC_PTC_SE0_NAK (0x03 << 16) |
Subbaraman Narayanamurthy | d8b7afc | 2011-06-30 15:42:41 -0700 | [diff] [blame] | 116 | #define PORTSC_PTC_TST_PKT (0x4 << 16) |
| 117 | |
Brian Swetland | 9a2cd26 | 2009-01-19 19:40:47 -0800 | [diff] [blame] | 118 | struct setup_packet { |
| 119 | unsigned char type; |
| 120 | unsigned char request; |
| 121 | unsigned short value; |
| 122 | unsigned short index; |
| 123 | unsigned short length; |
| 124 | } __attribute__ ((packed)); |
| 125 | |
| 126 | #endif |