gadget_chips.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /*
  2. * USB device controllers have lots of quirks. Use these macros in
  3. * gadget drivers or other code that needs to deal with them, and which
  4. * autoconfigures instead of using early binding to the hardware.
  5. *
  6. * This SHOULD eventually work like the ARM mach_is_*() stuff, driven by
  7. * some config file that gets updated as new hardware is supported.
  8. * (And avoiding all runtime comparisons in typical one-choice configs!)
  9. *
  10. * NOTE: some of these controller drivers may not be available yet.
  11. * Some are available on 2.4 kernels; several are available, but not
  12. * yet pushed in the 2.6 mainline tree.
  13. */
  14. #ifndef __GADGET_CHIPS_H
  15. #define __GADGET_CHIPS_H
  16. #ifdef CONFIG_USB_GADGET_NET2280
  17. #define gadget_is_net2280(g) !strcmp("net2280", (g)->name)
  18. #else
  19. #define gadget_is_net2280(g) 0
  20. #endif
  21. #ifdef CONFIG_USB_GADGET_AMD5536UDC
  22. #define gadget_is_amd5536udc(g) !strcmp("amd5536udc", (g)->name)
  23. #else
  24. #define gadget_is_amd5536udc(g) 0
  25. #endif
  26. #ifdef CONFIG_USB_GADGET_DUMMY_HCD
  27. #define gadget_is_dummy(g) !strcmp("dummy_udc", (g)->name)
  28. #else
  29. #define gadget_is_dummy(g) 0
  30. #endif
  31. #ifdef CONFIG_USB_GADGET_PXA25X
  32. #define gadget_is_pxa(g) !strcmp("pxa25x_udc", (g)->name)
  33. #else
  34. #define gadget_is_pxa(g) 0
  35. #endif
  36. #ifdef CONFIG_USB_GADGET_GOKU
  37. #define gadget_is_goku(g) !strcmp("goku_udc", (g)->name)
  38. #else
  39. #define gadget_is_goku(g) 0
  40. #endif
  41. #ifdef CONFIG_USB_GADGET_OMAP
  42. #define gadget_is_omap(g) !strcmp("omap_udc", (g)->name)
  43. #else
  44. #define gadget_is_omap(g) 0
  45. #endif
  46. /* various unstable versions available */
  47. #ifdef CONFIG_USB_GADGET_PXA27X
  48. #define gadget_is_pxa27x(g) !strcmp("pxa27x_udc", (g)->name)
  49. #else
  50. #define gadget_is_pxa27x(g) 0
  51. #endif
  52. #ifdef CONFIG_USB_GADGET_ATMEL_USBA
  53. #define gadget_is_atmel_usba(g) !strcmp("atmel_usba_udc", (g)->name)
  54. #else
  55. #define gadget_is_atmel_usba(g) 0
  56. #endif
  57. #ifdef CONFIG_USB_GADGET_S3C2410
  58. #define gadget_is_s3c2410(g) !strcmp("s3c2410_udc", (g)->name)
  59. #else
  60. #define gadget_is_s3c2410(g) 0
  61. #endif
  62. #ifdef CONFIG_USB_GADGET_AT91
  63. #define gadget_is_at91(g) !strcmp("at91_udc", (g)->name)
  64. #else
  65. #define gadget_is_at91(g) 0
  66. #endif
  67. #ifdef CONFIG_USB_GADGET_IMX
  68. #define gadget_is_imx(g) !strcmp("imx_udc", (g)->name)
  69. #else
  70. #define gadget_is_imx(g) 0
  71. #endif
  72. #ifdef CONFIG_USB_GADGET_FSL_USB2
  73. #define gadget_is_fsl_usb2(g) !strcmp("fsl-usb2-udc", (g)->name)
  74. #else
  75. #define gadget_is_fsl_usb2(g) 0
  76. #endif
  77. /* Mentor high speed "dual role" controller, in peripheral role */
  78. #ifdef CONFIG_USB_GADGET_MUSB_HDRC
  79. #define gadget_is_musbhdrc(g) !strcmp("musb-hdrc", (g)->name)
  80. #else
  81. #define gadget_is_musbhdrc(g) 0
  82. #endif
  83. #ifdef CONFIG_USB_GADGET_LANGWELL
  84. #define gadget_is_langwell(g) (!strcmp("langwell_udc", (g)->name))
  85. #else
  86. #define gadget_is_langwell(g) 0
  87. #endif
  88. #ifdef CONFIG_USB_GADGET_M66592
  89. #define gadget_is_m66592(g) !strcmp("m66592_udc", (g)->name)
  90. #else
  91. #define gadget_is_m66592(g) 0
  92. #endif
  93. /* Freescale CPM/QE UDC SUPPORT */
  94. #ifdef CONFIG_USB_GADGET_FSL_QE
  95. #define gadget_is_fsl_qe(g) !strcmp("fsl_qe_udc", (g)->name)
  96. #else
  97. #define gadget_is_fsl_qe(g) 0
  98. #endif
  99. #ifdef CONFIG_USB_GADGET_CI13XXX_PCI
  100. #define gadget_is_ci13xxx_pci(g) (!strcmp("ci13xxx_pci", (g)->name))
  101. #else
  102. #define gadget_is_ci13xxx_pci(g) 0
  103. #endif
  104. // CONFIG_USB_GADGET_SX2
  105. // CONFIG_USB_GADGET_AU1X00
  106. // ...
  107. #ifdef CONFIG_USB_GADGET_R8A66597
  108. #define gadget_is_r8a66597(g) !strcmp("r8a66597_udc", (g)->name)
  109. #else
  110. #define gadget_is_r8a66597(g) 0
  111. #endif
  112. #ifdef CONFIG_USB_S3C_HSOTG
  113. #define gadget_is_s3c_hsotg(g) (!strcmp("s3c-hsotg", (g)->name))
  114. #else
  115. #define gadget_is_s3c_hsotg(g) 0
  116. #endif
  117. #ifdef CONFIG_USB_S3C_HSUDC
  118. #define gadget_is_s3c_hsudc(g) (!strcmp("s3c-hsudc", (g)->name))
  119. #else
  120. #define gadget_is_s3c_hsudc(g) 0
  121. #endif
  122. #ifdef CONFIG_USB_GADGET_EG20T
  123. #define gadget_is_pch(g) (!strcmp("pch_udc", (g)->name))
  124. #else
  125. #define gadget_is_pch(g) 0
  126. #endif
  127. #ifdef CONFIG_USB_GADGET_CI13XXX_MSM
  128. #define gadget_is_ci13xxx_msm(g) (!strcmp("ci13xxx_msm", (g)->name))
  129. #else
  130. #define gadget_is_ci13xxx_msm(g) 0
  131. #endif
  132. #ifdef CONFIG_USB_GADGET_RENESAS_USBHS
  133. #define gadget_is_renesas_usbhs(g) (!strcmp("renesas_usbhs_udc", (g)->name))
  134. #else
  135. #define gadget_is_renesas_usbhs(g) 0
  136. #endif
  137. #ifdef CONFIG_USB_DWC_OTG_HCD
  138. #define gadget_is_dwc_otg(g) (!strcmp("dwc_otg_pcd", (g)->name))
  139. #else
  140. #define gadget_is_dwc_otg(g) 0
  141. #endif
  142. /**
  143. * usb_gadget_controller_number - support bcdDevice id convention
  144. * @gadget: the controller being driven
  145. *
  146. * Return a 2-digit BCD value associated with the peripheral controller,
  147. * suitable for use as part of a bcdDevice value, or a negative error code.
  148. *
  149. * NOTE: this convention is purely optional, and has no meaning in terms of
  150. * any USB specification. If you want to use a different convention in your
  151. * gadget driver firmware -- maybe a more formal revision ID -- feel free.
  152. *
  153. * Hosts see these bcdDevice numbers, and are allowed (but not encouraged!)
  154. * to change their behavior accordingly. For example it might help avoiding
  155. * some chip bug.
  156. */
  157. static inline int usb_gadget_controller_number(struct usb_gadget *gadget)
  158. {
  159. if (gadget_is_net2280(gadget))
  160. return 0x01;
  161. else if (gadget_is_dummy(gadget))
  162. return 0x02;
  163. else if (gadget_is_pxa(gadget))
  164. return 0x03;
  165. else if (gadget_is_goku(gadget))
  166. return 0x06;
  167. else if (gadget_is_omap(gadget))
  168. return 0x08;
  169. else if (gadget_is_pxa27x(gadget))
  170. return 0x11;
  171. else if (gadget_is_s3c2410(gadget))
  172. return 0x12;
  173. else if (gadget_is_at91(gadget))
  174. return 0x13;
  175. else if (gadget_is_imx(gadget))
  176. return 0x14;
  177. else if (gadget_is_musbhdrc(gadget))
  178. return 0x16;
  179. else if (gadget_is_atmel_usba(gadget))
  180. return 0x18;
  181. else if (gadget_is_fsl_usb2(gadget))
  182. return 0x19;
  183. else if (gadget_is_amd5536udc(gadget))
  184. return 0x20;
  185. else if (gadget_is_m66592(gadget))
  186. return 0x21;
  187. else if (gadget_is_fsl_qe(gadget))
  188. return 0x22;
  189. else if (gadget_is_ci13xxx_pci(gadget))
  190. return 0x23;
  191. else if (gadget_is_langwell(gadget))
  192. return 0x24;
  193. else if (gadget_is_r8a66597(gadget))
  194. return 0x25;
  195. else if (gadget_is_s3c_hsotg(gadget))
  196. return 0x26;
  197. else if (gadget_is_pch(gadget))
  198. return 0x27;
  199. else if (gadget_is_ci13xxx_msm(gadget))
  200. return 0x28;
  201. else if (gadget_is_renesas_usbhs(gadget))
  202. return 0x29;
  203. else if (gadget_is_s3c_hsudc(gadget))
  204. return 0x30;
  205. else if (gadget_is_dwc_otg(gadget))
  206. return 0x31;
  207. return -ENOENT;
  208. }
  209. /**
  210. * gadget_supports_altsettings - return true if altsettings work
  211. * @gadget: the gadget in question
  212. */
  213. static inline bool gadget_supports_altsettings(struct usb_gadget *gadget)
  214. {
  215. /* PXA 21x/25x/26x has no altsettings at all */
  216. if (gadget_is_pxa(gadget))
  217. return false;
  218. /* PXA 27x and 3xx have *broken* altsetting support */
  219. if (gadget_is_pxa27x(gadget))
  220. return false;
  221. /* Everything else is *presumably* fine ... */
  222. return true;
  223. }
  224. #endif /* __GADGET_CHIPS_H */