mod.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // SPDX-License-Identifier: GPL-1.0+
  2. /*
  3. * Renesas USB driver
  4. *
  5. * Copyright (C) 2011 Renesas Solutions Corp.
  6. * Copyright (C) 2019 Renesas Electronics Corporation
  7. * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  8. */
  9. #ifndef RENESAS_USB_MOD_H
  10. #define RENESAS_USB_MOD_H
  11. #include <linux/spinlock.h>
  12. #include <linux/usb/renesas_usbhs.h>
  13. #include "common.h"
  14. /*
  15. * struct
  16. */
  17. struct usbhs_irq_state {
  18. u16 intsts0;
  19. u16 intsts1;
  20. u16 brdysts;
  21. u16 nrdysts;
  22. u16 bempsts;
  23. };
  24. struct usbhs_mod {
  25. char *name;
  26. /*
  27. * entry point from common.c
  28. */
  29. int (*start)(struct usbhs_priv *priv);
  30. int (*stop)(struct usbhs_priv *priv);
  31. /*
  32. * INTSTS0
  33. */
  34. /* DVST (DVSQ) */
  35. int (*irq_dev_state)(struct usbhs_priv *priv,
  36. struct usbhs_irq_state *irq_state);
  37. /* CTRT (CTSQ) */
  38. int (*irq_ctrl_stage)(struct usbhs_priv *priv,
  39. struct usbhs_irq_state *irq_state);
  40. /* BEMP / BEMPSTS */
  41. int (*irq_empty)(struct usbhs_priv *priv,
  42. struct usbhs_irq_state *irq_state);
  43. u16 irq_bempsts;
  44. /* BRDY / BRDYSTS */
  45. int (*irq_ready)(struct usbhs_priv *priv,
  46. struct usbhs_irq_state *irq_state);
  47. u16 irq_brdysts;
  48. /*
  49. * INTSTS1
  50. */
  51. /* ATTCHE */
  52. int (*irq_attch)(struct usbhs_priv *priv,
  53. struct usbhs_irq_state *irq_state);
  54. /* DTCHE */
  55. int (*irq_dtch)(struct usbhs_priv *priv,
  56. struct usbhs_irq_state *irq_state);
  57. /* SIGN */
  58. int (*irq_sign)(struct usbhs_priv *priv,
  59. struct usbhs_irq_state *irq_state);
  60. /* SACK */
  61. int (*irq_sack)(struct usbhs_priv *priv,
  62. struct usbhs_irq_state *irq_state);
  63. struct usbhs_priv *priv;
  64. };
  65. struct usbhs_mod_info {
  66. struct usbhs_mod *mod[USBHS_MAX];
  67. struct usbhs_mod *curt; /* current mod */
  68. /*
  69. * INTSTS0 :: VBINT
  70. *
  71. * This function will be used as autonomy mode (runtime_pwctrl == 0)
  72. * when the platform doesn't have own get_vbus function.
  73. *
  74. * This callback cannot be member of "struct usbhs_mod" because it
  75. * will be used even though host/gadget has not been selected.
  76. */
  77. int (*irq_vbus)(struct usbhs_priv *priv,
  78. struct usbhs_irq_state *irq_state);
  79. /*
  80. * This function will be used on any gadget mode. To simplify the code,
  81. * this member is in here.
  82. */
  83. int (*get_vbus)(struct platform_device *pdev);
  84. };
  85. /*
  86. * for host/gadget module
  87. */
  88. struct usbhs_mod *usbhs_mod_get(struct usbhs_priv *priv, int id);
  89. struct usbhs_mod *usbhs_mod_get_current(struct usbhs_priv *priv);
  90. void usbhs_mod_register(struct usbhs_priv *priv, struct usbhs_mod *usb, int id);
  91. int usbhs_mod_is_host(struct usbhs_priv *priv);
  92. int usbhs_mod_change(struct usbhs_priv *priv, int id);
  93. int usbhs_mod_probe(struct usbhs_priv *priv);
  94. void usbhs_mod_remove(struct usbhs_priv *priv);
  95. void usbhs_mod_autonomy_mode(struct usbhs_priv *priv);
  96. void usbhs_mod_non_autonomy_mode(struct usbhs_priv *priv);
  97. /*
  98. * status functions
  99. */
  100. int usbhs_status_get_device_state(struct usbhs_irq_state *irq_state);
  101. int usbhs_status_get_ctrl_stage(struct usbhs_irq_state *irq_state);
  102. /*
  103. * callback functions
  104. */
  105. void usbhs_irq_callback_update(struct usbhs_priv *priv, struct usbhs_mod *mod);
  106. #define usbhs_mod_call(priv, func, param...) \
  107. ({ \
  108. struct usbhs_mod *mod; \
  109. mod = usbhs_mod_get_current(priv); \
  110. !mod ? -ENODEV : \
  111. !mod->func ? 0 : \
  112. mod->func(param); \
  113. })
  114. #define usbhs_priv_to_modinfo(priv) (&priv->mod_info)
  115. #define usbhs_mod_info_call(priv, func, param...) \
  116. ({ \
  117. struct usbhs_mod_info *info; \
  118. info = usbhs_priv_to_modinfo(priv); \
  119. !info->func ? 0 : \
  120. info->func(param); \
  121. })
  122. /*
  123. * host / gadget control
  124. */
  125. #if defined(CONFIG_USB_RENESAS_USBHS_HCD) || \
  126. defined(CONFIG_USB_RENESAS_USBHS_HCD_MODULE)
  127. extern int usbhs_mod_host_probe(struct usbhs_priv *priv);
  128. extern int usbhs_mod_host_remove(struct usbhs_priv *priv);
  129. #else
  130. static inline int usbhs_mod_host_probe(struct usbhs_priv *priv)
  131. {
  132. return 0;
  133. }
  134. static inline void usbhs_mod_host_remove(struct usbhs_priv *priv)
  135. {
  136. }
  137. #endif
  138. #if defined(CONFIG_USB_RENESAS_USBHS_UDC) || \
  139. defined(CONFIG_USB_RENESAS_USBHS_UDC_MODULE)
  140. extern int usbhs_mod_gadget_probe(struct usbhs_priv *priv);
  141. extern void usbhs_mod_gadget_remove(struct usbhs_priv *priv);
  142. #else
  143. static inline int usbhs_mod_gadget_probe(struct usbhs_priv *priv)
  144. {
  145. return 0;
  146. }
  147. static inline void usbhs_mod_gadget_remove(struct usbhs_priv *priv)
  148. {
  149. }
  150. #endif
  151. #endif /* RENESAS_USB_MOD_H */