mod.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * Renesas USB driver
  3. *
  4. * Copyright (C) 2011 Renesas Solutions Corp.
  5. * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software
  14. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  15. *
  16. */
  17. #ifndef RENESAS_USB_MOD_H
  18. #define RENESAS_USB_MOD_H
  19. #include <linux/spinlock.h>
  20. #include <linux/usb/renesas_usbhs.h>
  21. #include "common.h"
  22. /*
  23. * struct
  24. */
  25. struct usbhs_irq_state {
  26. u16 intsts0;
  27. u16 intsts1;
  28. u16 brdysts;
  29. u16 nrdysts;
  30. u16 bempsts;
  31. };
  32. struct usbhs_mod {
  33. char *name;
  34. /*
  35. * entry point from common.c
  36. */
  37. int (*start)(struct usbhs_priv *priv);
  38. int (*stop)(struct usbhs_priv *priv);
  39. /*
  40. * INTSTS0
  41. */
  42. /* DVST (DVSQ) */
  43. int (*irq_dev_state)(struct usbhs_priv *priv,
  44. struct usbhs_irq_state *irq_state);
  45. /* CTRT (CTSQ) */
  46. int (*irq_ctrl_stage)(struct usbhs_priv *priv,
  47. struct usbhs_irq_state *irq_state);
  48. /* BEMP / BEMPSTS */
  49. int (*irq_empty)(struct usbhs_priv *priv,
  50. struct usbhs_irq_state *irq_state);
  51. u16 irq_bempsts;
  52. /* BRDY / BRDYSTS */
  53. int (*irq_ready)(struct usbhs_priv *priv,
  54. struct usbhs_irq_state *irq_state);
  55. u16 irq_brdysts;
  56. /*
  57. * INTSTS1
  58. */
  59. /* ATTCHE */
  60. int (*irq_attch)(struct usbhs_priv *priv,
  61. struct usbhs_irq_state *irq_state);
  62. /* DTCHE */
  63. int (*irq_dtch)(struct usbhs_priv *priv,
  64. struct usbhs_irq_state *irq_state);
  65. /* SIGN */
  66. int (*irq_sign)(struct usbhs_priv *priv,
  67. struct usbhs_irq_state *irq_state);
  68. /* SACK */
  69. int (*irq_sack)(struct usbhs_priv *priv,
  70. struct usbhs_irq_state *irq_state);
  71. struct usbhs_priv *priv;
  72. };
  73. struct usbhs_mod_info {
  74. struct usbhs_mod *mod[USBHS_MAX];
  75. struct usbhs_mod *curt; /* current mod */
  76. /*
  77. * INTSTS0 :: VBINT
  78. *
  79. * This function will be used as autonomy mode
  80. * when platform cannot call notify_hotplug.
  81. *
  82. * This callback cannot be member of "struct usbhs_mod"
  83. * because it will be used even though
  84. * host/gadget has not been selected.
  85. */
  86. int (*irq_vbus)(struct usbhs_priv *priv,
  87. struct usbhs_irq_state *irq_state);
  88. };
  89. /*
  90. * for host/gadget module
  91. */
  92. struct usbhs_mod *usbhs_mod_get(struct usbhs_priv *priv, int id);
  93. struct usbhs_mod *usbhs_mod_get_current(struct usbhs_priv *priv);
  94. void usbhs_mod_register(struct usbhs_priv *priv, struct usbhs_mod *usb, int id);
  95. int usbhs_mod_is_host(struct usbhs_priv *priv);
  96. int usbhs_mod_change(struct usbhs_priv *priv, int id);
  97. int usbhs_mod_probe(struct usbhs_priv *priv);
  98. void usbhs_mod_remove(struct usbhs_priv *priv);
  99. void usbhs_mod_autonomy_mode(struct usbhs_priv *priv);
  100. /*
  101. * status functions
  102. */
  103. int usbhs_status_get_device_state(struct usbhs_irq_state *irq_state);
  104. int usbhs_status_get_ctrl_stage(struct usbhs_irq_state *irq_state);
  105. /*
  106. * callback functions
  107. */
  108. void usbhs_irq_callback_update(struct usbhs_priv *priv, struct usbhs_mod *mod);
  109. #define usbhs_mod_call(priv, func, param...) \
  110. ({ \
  111. struct usbhs_mod *mod; \
  112. mod = usbhs_mod_get_current(priv); \
  113. !mod ? -ENODEV : \
  114. !mod->func ? 0 : \
  115. mod->func(param); \
  116. })
  117. /*
  118. * host / gadget control
  119. */
  120. #if defined(CONFIG_USB_RENESAS_USBHS_HCD) || \
  121. defined(CONFIG_USB_RENESAS_USBHS_HCD_MODULE)
  122. extern int usbhs_mod_host_probe(struct usbhs_priv *priv);
  123. extern int usbhs_mod_host_remove(struct usbhs_priv *priv);
  124. #else
  125. static inline int usbhs_mod_host_probe(struct usbhs_priv *priv)
  126. {
  127. return 0;
  128. }
  129. static inline void usbhs_mod_host_remove(struct usbhs_priv *priv)
  130. {
  131. }
  132. #endif
  133. #if defined(CONFIG_USB_RENESAS_USBHS_UDC) || \
  134. defined(CONFIG_USB_RENESAS_USBHS_UDC_MODULE)
  135. extern int usbhs_mod_gadget_probe(struct usbhs_priv *priv);
  136. extern void usbhs_mod_gadget_remove(struct usbhs_priv *priv);
  137. #else
  138. static inline int usbhs_mod_gadget_probe(struct usbhs_priv *priv)
  139. {
  140. return 0;
  141. }
  142. static inline void usbhs_mod_gadget_remove(struct usbhs_priv *priv)
  143. {
  144. }
  145. #endif
  146. #endif /* RENESAS_USB_MOD_H */