mod.h 3.7 KB

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