udc.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. #ifndef __DEV_UDC_H
  29. #define __DEV_UDC_H
  30. extern int txn_status;
  31. /* USB Device Controller Transfer Request */
  32. struct udc_request {
  33. void *buf;
  34. unsigned length;
  35. void (*complete)(struct udc_request *req, unsigned actual, int status);
  36. void *context;
  37. };
  38. /* endpoints are opaque handles specific to the particular device controller */
  39. struct udc_endpoint;
  40. struct udc_request *udc_request_alloc(void);
  41. void udc_request_free(struct udc_request *req);
  42. int udc_request_queue(struct udc_endpoint *ept, struct udc_request *req);
  43. int udc_request_cancel(struct udc_endpoint *ept, struct udc_request *req);
  44. #define UDC_TYPE_BULK_IN 1
  45. #define UDC_TYPE_BULK_OUT 2
  46. struct udc_endpoint *udc_endpoint_alloc(unsigned type, unsigned maxpkt);
  47. void udc_endpoint_free(struct udc_endpoint *ept);
  48. #define UDC_EVENT_ONLINE 1
  49. #define UDC_EVENT_OFFLINE 2
  50. struct udc_gadget {
  51. void (*notify)(struct udc_gadget *gadget, unsigned event);
  52. void *context;
  53. unsigned char ifc_class;
  54. unsigned char ifc_subclass;
  55. unsigned char ifc_protocol;
  56. unsigned char ifc_endpoints;
  57. const char *ifc_string;
  58. unsigned flags;
  59. struct udc_endpoint **ept;
  60. };
  61. struct udc_device {
  62. unsigned short vendor_id;
  63. unsigned short product_id;
  64. unsigned short version_id;
  65. const char *manufacturer;
  66. const char *product;
  67. const char *serialno;
  68. };
  69. int udc_init(struct udc_device *devinfo);
  70. int udc_register_gadget(struct udc_gadget *gadget);
  71. int udc_start(void);
  72. int udc_stop(void);
  73. /* these should probably go elsewhere */
  74. #define GET_STATUS 0
  75. #define CLEAR_FEATURE 1
  76. #define SET_FEATURE 3
  77. #define SET_ADDRESS 5
  78. #define GET_DESCRIPTOR 6
  79. #define SET_DESCRIPTOR 7
  80. #define GET_CONFIGURATION 8
  81. #define SET_CONFIGURATION 9
  82. #define GET_INTERFACE 10
  83. #define SET_INTERFACE 11
  84. #define SYNCH_FRAME 12
  85. #define SET_SEL 48
  86. #define TYPE_DEVICE 1
  87. #define TYPE_CONFIGURATION 2
  88. #define TYPE_STRING 3
  89. #define TYPE_INTERFACE 4
  90. #define TYPE_ENDPOINT 5
  91. #define TYPE_DEV_QUALIFIER 6
  92. #define TYPE_OTHER_SPEEDCONF 7
  93. #define TYPE_IFACE_POWER 8
  94. #define TYPE_OTG 9
  95. #define TYPE_DEBUG 10
  96. #define TYPE_IFACE_ASSOC 11
  97. #define TYPE_BOS 15
  98. #define TYPE_DEVICE_CAP 16
  99. #define TYPE_SS_EP_COMP 48
  100. #define DEVICE_READ 0x80
  101. #define DEVICE_WRITE 0x00
  102. #define INTERFACE_READ 0x81
  103. #define INTERFACE_WRITE 0x01
  104. #define ENDPOINT_READ 0x82
  105. #define ENDPOINT_WRITE 0x02
  106. #define TEST_SE0_NAK 0x0300
  107. #define TEST_PACKET 0x0400
  108. #define PORTSC_PTC (0xF << 16)
  109. #define PORTSC_PTC_SE0_NAK (0x03 << 16)
  110. #define PORTSC_PTC_TST_PKT (0x4 << 16)
  111. #define USB3_U1_ENABLE 48
  112. #define USB3_U2_ENABLE 49
  113. struct setup_packet {
  114. unsigned char type;
  115. unsigned char request;
  116. unsigned short value;
  117. unsigned short index;
  118. unsigned short length;
  119. } __attribute__ ((packed));
  120. #endif