gadget_chips.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. /* from Montavista kernel (?) */
  120. #ifdef CONFIG_USB_GADGET_MPC8272
  121. #define gadget_is_mpc8272(g) !strcmp("mpc8272_udc", (g)->name)
  122. #else
  123. #define gadget_is_mpc8272(g) 0
  124. #endif
  125. #ifdef CONFIG_USB_GADGET_M66592
  126. #define gadget_is_m66592(g) !strcmp("m66592_udc", (g)->name)
  127. #else
  128. #define gadget_is_m66592(g) 0
  129. #endif
  130. /* Freescale CPM/QE UDC SUPPORT */
  131. #ifdef CONFIG_USB_GADGET_FSL_QE
  132. #define gadget_is_fsl_qe(g) !strcmp("fsl_qe_udc", (g)->name)
  133. #else
  134. #define gadget_is_fsl_qe(g) 0
  135. #endif
  136. #ifdef CONFIG_USB_GADGET_CI13XXX
  137. #define gadget_is_ci13xxx(g) (!strcmp("ci13xxx_udc", (g)->name))
  138. #else
  139. #define gadget_is_ci13xxx(g) 0
  140. #endif
  141. // CONFIG_USB_GADGET_SX2
  142. // CONFIG_USB_GADGET_AU1X00
  143. // ...
  144. /**
  145. * usb_gadget_controller_number - support bcdDevice id convention
  146. * @gadget: the controller being driven
  147. *
  148. * Return a 2-digit BCD value associated with the peripheral controller,
  149. * suitable for use as part of a bcdDevice value, or a negative error code.
  150. *
  151. * NOTE: this convention is purely optional, and has no meaning in terms of
  152. * any USB specification. If you want to use a different convention in your
  153. * gadget driver firmware -- maybe a more formal revision ID -- feel free.
  154. *
  155. * Hosts see these bcdDevice numbers, and are allowed (but not encouraged!)
  156. * to change their behavior accordingly. For example it might help avoiding
  157. * some chip bug.
  158. */
  159. static inline int usb_gadget_controller_number(struct usb_gadget *gadget)
  160. {
  161. if (gadget_is_net2280(gadget))
  162. return 0x01;
  163. else if (gadget_is_dummy(gadget))
  164. return 0x02;
  165. else if (gadget_is_pxa(gadget))
  166. return 0x03;
  167. else if (gadget_is_sh(gadget))
  168. return 0x04;
  169. else if (gadget_is_sa1100(gadget))
  170. return 0x05;
  171. else if (gadget_is_goku(gadget))
  172. return 0x06;
  173. else if (gadget_is_mq11xx(gadget))
  174. return 0x07;
  175. else if (gadget_is_omap(gadget))
  176. return 0x08;
  177. else if (gadget_is_lh7a40x(gadget))
  178. return 0x09;
  179. else if (gadget_is_n9604(gadget))
  180. return 0x10;
  181. else if (gadget_is_pxa27x(gadget))
  182. return 0x11;
  183. else if (gadget_is_s3c2410(gadget))
  184. return 0x12;
  185. else if (gadget_is_at91(gadget))
  186. return 0x13;
  187. else if (gadget_is_imx(gadget))
  188. return 0x14;
  189. else if (gadget_is_musbhsfc(gadget))
  190. return 0x15;
  191. else if (gadget_is_musbhdrc(gadget))
  192. return 0x16;
  193. else if (gadget_is_mpc8272(gadget))
  194. return 0x17;
  195. else if (gadget_is_atmel_usba(gadget))
  196. return 0x18;
  197. else if (gadget_is_fsl_usb2(gadget))
  198. return 0x19;
  199. else if (gadget_is_amd5536udc(gadget))
  200. return 0x20;
  201. else if (gadget_is_m66592(gadget))
  202. return 0x21;
  203. else if (gadget_is_fsl_qe(gadget))
  204. return 0x22;
  205. else if (gadget_is_ci13xxx(gadget))
  206. return 0x23;
  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. /* SH3 hardware just doesn't do altsettings */
  222. if (gadget_is_sh(gadget))
  223. return false;
  224. /* Everything else is *presumably* fine ... */
  225. return true;
  226. }
  227. #endif /* __GADGET_CHIPS_H */