gadget_chips.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. /* SH3 UDC -- not yet ported 2.4 --> 2.6 */
  42. #ifdef CONFIG_USB_GADGET_SUPERH
  43. #define gadget_is_sh(g) !strcmp("sh_udc", (g)->name)
  44. #else
  45. #define gadget_is_sh(g) 0
  46. #endif
  47. /* not yet stable on 2.6 (would help "original Zaurus") */
  48. #ifdef CONFIG_USB_GADGET_SA1100
  49. #define gadget_is_sa1100(g) !strcmp("sa1100_udc", (g)->name)
  50. #else
  51. #define gadget_is_sa1100(g) 0
  52. #endif
  53. #ifdef CONFIG_USB_GADGET_LH7A40X
  54. #define gadget_is_lh7a40x(g) !strcmp("lh7a40x_udc", (g)->name)
  55. #else
  56. #define gadget_is_lh7a40x(g) 0
  57. #endif
  58. /* handhelds.org tree (?) */
  59. #ifdef CONFIG_USB_GADGET_MQ11XX
  60. #define gadget_is_mq11xx(g) !strcmp("mq11xx_udc", (g)->name)
  61. #else
  62. #define gadget_is_mq11xx(g) 0
  63. #endif
  64. #ifdef CONFIG_USB_GADGET_OMAP
  65. #define gadget_is_omap(g) !strcmp("omap_udc", (g)->name)
  66. #else
  67. #define gadget_is_omap(g) 0
  68. #endif
  69. /* not yet ported 2.4 --> 2.6 */
  70. #ifdef CONFIG_USB_GADGET_N9604
  71. #define gadget_is_n9604(g) !strcmp("n9604_udc", (g)->name)
  72. #else
  73. #define gadget_is_n9604(g) 0
  74. #endif
  75. /* various unstable versions available */
  76. #ifdef CONFIG_USB_GADGET_PXA27X
  77. #define gadget_is_pxa27x(g) !strcmp("pxa27x_udc", (g)->name)
  78. #else
  79. #define gadget_is_pxa27x(g) 0
  80. #endif
  81. #ifdef CONFIG_USB_GADGET_ATMEL_USBA
  82. #define gadget_is_atmel_usba(g) !strcmp("atmel_usba_udc", (g)->name)
  83. #else
  84. #define gadget_is_atmel_usba(g) 0
  85. #endif
  86. #ifdef CONFIG_USB_GADGET_S3C2410
  87. #define gadget_is_s3c2410(g) !strcmp("s3c2410_udc", (g)->name)
  88. #else
  89. #define gadget_is_s3c2410(g) 0
  90. #endif
  91. #ifdef CONFIG_USB_GADGET_AT91
  92. #define gadget_is_at91(g) !strcmp("at91_udc", (g)->name)
  93. #else
  94. #define gadget_is_at91(g) 0
  95. #endif
  96. #ifdef CONFIG_USB_GADGET_IMX
  97. #define gadget_is_imx(g) !strcmp("imx_udc", (g)->name)
  98. #else
  99. #define gadget_is_imx(g) 0
  100. #endif
  101. #ifdef CONFIG_USB_GADGET_FSL_USB2
  102. #define gadget_is_fsl_usb2(g) !strcmp("fsl-usb2-udc", (g)->name)
  103. #else
  104. #define gadget_is_fsl_usb2(g) 0
  105. #endif
  106. /* Mentor high speed function controller */
  107. /* from Montavista kernel (?) */
  108. #ifdef CONFIG_USB_GADGET_MUSBHSFC
  109. #define gadget_is_musbhsfc(g) !strcmp("musbhsfc_udc", (g)->name)
  110. #else
  111. #define gadget_is_musbhsfc(g) 0
  112. #endif
  113. /* Mentor high speed "dual role" controller, in peripheral role */
  114. #ifdef CONFIG_USB_GADGET_MUSB_HDRC
  115. #define gadget_is_musbhdrc(g) !strcmp("musb_hdrc", (g)->name)
  116. #else
  117. #define gadget_is_musbhdrc(g) 0
  118. #endif
  119. #ifdef CONFIG_USB_GADGET_LANGWELL
  120. #define gadget_is_langwell(g) (!strcmp("langwell_udc", (g)->name))
  121. #else
  122. #define gadget_is_langwell(g) 0
  123. #endif
  124. /* from Montavista kernel (?) */
  125. #ifdef CONFIG_USB_GADGET_MPC8272
  126. #define gadget_is_mpc8272(g) !strcmp("mpc8272_udc", (g)->name)
  127. #else
  128. #define gadget_is_mpc8272(g) 0
  129. #endif
  130. #ifdef CONFIG_USB_GADGET_M66592
  131. #define gadget_is_m66592(g) !strcmp("m66592_udc", (g)->name)
  132. #else
  133. #define gadget_is_m66592(g) 0
  134. #endif
  135. /* Freescale CPM/QE UDC SUPPORT */
  136. #ifdef CONFIG_USB_GADGET_FSL_QE
  137. #define gadget_is_fsl_qe(g) !strcmp("fsl_qe_udc", (g)->name)
  138. #else
  139. #define gadget_is_fsl_qe(g) 0
  140. #endif
  141. #ifdef CONFIG_USB_GADGET_CI13XXX
  142. #define gadget_is_ci13xxx(g) (!strcmp("ci13xxx_udc", (g)->name))
  143. #else
  144. #define gadget_is_ci13xxx(g) 0
  145. #endif
  146. // CONFIG_USB_GADGET_SX2
  147. // CONFIG_USB_GADGET_AU1X00
  148. // ...
  149. /**
  150. * usb_gadget_controller_number - support bcdDevice id convention
  151. * @gadget: the controller being driven
  152. *
  153. * Return a 2-digit BCD value associated with the peripheral controller,
  154. * suitable for use as part of a bcdDevice value, or a negative error code.
  155. *
  156. * NOTE: this convention is purely optional, and has no meaning in terms of
  157. * any USB specification. If you want to use a different convention in your
  158. * gadget driver firmware -- maybe a more formal revision ID -- feel free.
  159. *
  160. * Hosts see these bcdDevice numbers, and are allowed (but not encouraged!)
  161. * to change their behavior accordingly. For example it might help avoiding
  162. * some chip bug.
  163. */
  164. static inline int usb_gadget_controller_number(struct usb_gadget *gadget)
  165. {
  166. if (gadget_is_net2280(gadget))
  167. return 0x01;
  168. else if (gadget_is_dummy(gadget))
  169. return 0x02;
  170. else if (gadget_is_pxa(gadget))
  171. return 0x03;
  172. else if (gadget_is_sh(gadget))
  173. return 0x04;
  174. else if (gadget_is_sa1100(gadget))
  175. return 0x05;
  176. else if (gadget_is_goku(gadget))
  177. return 0x06;
  178. else if (gadget_is_mq11xx(gadget))
  179. return 0x07;
  180. else if (gadget_is_omap(gadget))
  181. return 0x08;
  182. else if (gadget_is_lh7a40x(gadget))
  183. return 0x09;
  184. else if (gadget_is_n9604(gadget))
  185. return 0x10;
  186. else if (gadget_is_pxa27x(gadget))
  187. return 0x11;
  188. else if (gadget_is_s3c2410(gadget))
  189. return 0x12;
  190. else if (gadget_is_at91(gadget))
  191. return 0x13;
  192. else if (gadget_is_imx(gadget))
  193. return 0x14;
  194. else if (gadget_is_musbhsfc(gadget))
  195. return 0x15;
  196. else if (gadget_is_musbhdrc(gadget))
  197. return 0x16;
  198. else if (gadget_is_mpc8272(gadget))
  199. return 0x17;
  200. else if (gadget_is_atmel_usba(gadget))
  201. return 0x18;
  202. else if (gadget_is_fsl_usb2(gadget))
  203. return 0x19;
  204. else if (gadget_is_amd5536udc(gadget))
  205. return 0x20;
  206. else if (gadget_is_m66592(gadget))
  207. return 0x21;
  208. else if (gadget_is_fsl_qe(gadget))
  209. return 0x22;
  210. else if (gadget_is_ci13xxx(gadget))
  211. return 0x23;
  212. else if (gadget_is_langwell(gadget))
  213. return 0x24;
  214. return -ENOENT;
  215. }
  216. /**
  217. * gadget_supports_altsettings - return true if altsettings work
  218. * @gadget: the gadget in question
  219. */
  220. static inline bool gadget_supports_altsettings(struct usb_gadget *gadget)
  221. {
  222. /* PXA 21x/25x/26x has no altsettings at all */
  223. if (gadget_is_pxa(gadget))
  224. return false;
  225. /* PXA 27x and 3xx have *broken* altsetting support */
  226. if (gadget_is_pxa27x(gadget))
  227. return false;
  228. /* SH3 hardware just doesn't do altsettings */
  229. if (gadget_is_sh(gadget))
  230. return false;
  231. /* Everything else is *presumably* fine ... */
  232. return true;
  233. }
  234. #endif /* __GADGET_CHIPS_H */