s3c_udc.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * drivers/usb/gadget/s3c_udc.h
  3. * Samsung S3C on-chip full/high speed USB device controllers
  4. * Copyright (C) 2005 for Samsung Electronics
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. #ifndef __S3C_USB_GADGET
  22. #define __S3C_USB_GADGET
  23. #include <asm/errno.h>
  24. #include <linux/usb/ch9.h>
  25. #include <usbdescriptors.h>
  26. #include <linux/usb/gadget.h>
  27. #include <linux/list.h>
  28. #include <usb/lin_gadget_compat.h>
  29. #define PHY0_SLEEP (1 << 5)
  30. /*-------------------------------------------------------------------------*/
  31. /* DMA bounce buffer size, 16K is enough even for mass storage */
  32. #define DMA_BUFFER_SIZE (4096*4)
  33. #define EP0_FIFO_SIZE 64
  34. #define EP_FIFO_SIZE 512
  35. #define EP_FIFO_SIZE2 1024
  36. /* ep0-control, ep1in-bulk, ep2out-bulk, ep3in-int */
  37. #define S3C_MAX_ENDPOINTS 4
  38. #define S3C_MAX_HW_ENDPOINTS 16
  39. #define WAIT_FOR_SETUP 0
  40. #define DATA_STATE_XMIT 1
  41. #define DATA_STATE_NEED_ZLP 2
  42. #define WAIT_FOR_OUT_STATUS 3
  43. #define DATA_STATE_RECV 4
  44. #define WAIT_FOR_COMPLETE 5
  45. #define WAIT_FOR_OUT_COMPLETE 6
  46. #define WAIT_FOR_IN_COMPLETE 7
  47. #define WAIT_FOR_NULL_COMPLETE 8
  48. #define TEST_J_SEL 0x1
  49. #define TEST_K_SEL 0x2
  50. #define TEST_SE0_NAK_SEL 0x3
  51. #define TEST_PACKET_SEL 0x4
  52. #define TEST_FORCE_ENABLE_SEL 0x5
  53. /* ************************************************************************* */
  54. /* IO
  55. */
  56. enum ep_type {
  57. ep_control, ep_bulk_in, ep_bulk_out, ep_interrupt
  58. };
  59. struct s3c_ep {
  60. struct usb_ep ep;
  61. struct s3c_udc *dev;
  62. const struct usb_endpoint_descriptor *desc;
  63. struct list_head queue;
  64. unsigned long pio_irqs;
  65. int len;
  66. void *dma_buf;
  67. u8 stopped;
  68. u8 bEndpointAddress;
  69. u8 bmAttributes;
  70. enum ep_type ep_type;
  71. int fifo_num;
  72. };
  73. struct s3c_request {
  74. struct usb_request req;
  75. struct list_head queue;
  76. };
  77. struct s3c_udc {
  78. struct usb_gadget gadget;
  79. struct usb_gadget_driver *driver;
  80. struct s3c_plat_otg_data *pdata;
  81. void *dma_buf[S3C_MAX_ENDPOINTS+1];
  82. dma_addr_t dma_addr[S3C_MAX_ENDPOINTS+1];
  83. int ep0state;
  84. struct s3c_ep ep[S3C_MAX_ENDPOINTS];
  85. unsigned char usb_address;
  86. unsigned req_pending:1, req_std:1;
  87. };
  88. extern struct s3c_udc *the_controller;
  89. #define ep_is_in(EP) (((EP)->bEndpointAddress&USB_DIR_IN) == USB_DIR_IN)
  90. #define ep_index(EP) ((EP)->bEndpointAddress&0xF)
  91. #define ep_maxpacket(EP) ((EP)->ep.maxpacket)
  92. /*-------------------------------------------------------------------------*/
  93. /* #define DEBUG_UDC */
  94. #ifdef DEBUG_UDC
  95. #define DBG(stuff...) printf("udc: " stuff)
  96. #else
  97. #define DBG(stuff...) do {} while (0)
  98. #endif
  99. #ifdef DEBUG_S3C_UDC_SETUP
  100. #define DEBUG_SETUP(fmt, args...) printk(fmt, ##args)
  101. #else
  102. #define DEBUG_SETUP(fmt, args...) do {} while (0)
  103. #endif
  104. #ifdef DEBUG_S3C_UDC_EP0
  105. #define DEBUG_EP0(fmt, args...) printk(fmt, ##args)
  106. #else
  107. #define DEBUG_EP0(fmt, args...) do {} while (0)
  108. #endif
  109. #ifdef DEBUG_S3C_UDC_ISR
  110. #define DEBUG_ISR 1
  111. #else
  112. #define DEBUG_ISR 0
  113. #endif
  114. #ifdef DEBUG_S3C_UDC_OUT_EP
  115. #define DEBUG_OUT_EP(fmt, args...) printk(fmt, ##args)
  116. #else
  117. #define DEBUG_OUT_EP(fmt, args...) do {} while (0)
  118. #endif
  119. #ifdef DEBUG_S3C_UDC_IN_EP
  120. #define DEBUG_IN_EP 1
  121. #else
  122. #define DEBUG_IN_EP 0
  123. #endif
  124. #if defined(DEBUG_S3C_UDC_SETUP) || defined(DEBUG_S3C_UDC_EP0) || \
  125. defined(DEBUG_S3C_UDC_ISR) || defined(DEBUG_S3C_UDC_OUT_EP) || \
  126. defined(DEBUG_S3C_UDC_IN_EP) || defined(DEBUG_S3C_UDC)
  127. #define DEBUG
  128. #endif
  129. #define ERR(stuff...) printf("ERR udc: " stuff)
  130. #define WARN(stuff...) printf("WARNING udc: " stuff)
  131. #define INFO(stuff...) printf("INFO udc: " stuff)
  132. extern void otg_phy_init(struct s3c_udc *dev);
  133. extern void otg_phy_off(struct s3c_udc *dev);
  134. extern void s3c_udc_ep_set_stall(struct s3c_ep *ep);
  135. extern int s3c_udc_probe(struct s3c_plat_otg_data *pdata);
  136. struct s3c_plat_otg_data {
  137. int (*phy_control)(int on);
  138. unsigned int regs_phy;
  139. unsigned int regs_otg;
  140. unsigned int usb_phy_ctrl;
  141. unsigned int usb_flags;
  142. };
  143. #endif