mod.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. /* INTSTS0 :: DVST (DVSQ) */
  40. int (*irq_dev_state)(struct usbhs_priv *priv,
  41. struct usbhs_irq_state *irq_state);
  42. /* INTSTS0 :: CTRT (CTSQ) */
  43. int (*irq_ctrl_stage)(struct usbhs_priv *priv,
  44. struct usbhs_irq_state *irq_state);
  45. /* INTSTS0 :: BEMP */
  46. /* BEMPSTS */
  47. int (*irq_empty)(struct usbhs_priv *priv,
  48. struct usbhs_irq_state *irq_state);
  49. u16 irq_bempsts;
  50. /* INTSTS0 :: BRDY */
  51. /* BRDYSTS */
  52. int (*irq_ready)(struct usbhs_priv *priv,
  53. struct usbhs_irq_state *irq_state);
  54. u16 irq_brdysts;
  55. struct usbhs_priv *priv;
  56. };
  57. struct usbhs_mod_info {
  58. struct usbhs_mod *mod[USBHS_MAX];
  59. struct usbhs_mod *curt; /* current mod */
  60. /*
  61. * INTSTS0 :: VBINT
  62. *
  63. * This function will be used as autonomy mode
  64. * when platform cannot call notify_hotplug.
  65. *
  66. * This callback cannot be member of "struct usbhs_mod"
  67. * because it will be used even though
  68. * host/gadget has not been selected.
  69. */
  70. int (*irq_vbus)(struct usbhs_priv *priv,
  71. struct usbhs_irq_state *irq_state);
  72. };
  73. /*
  74. * for host/gadget module
  75. */
  76. struct usbhs_mod *usbhs_mod_get(struct usbhs_priv *priv, int id);
  77. struct usbhs_mod *usbhs_mod_get_current(struct usbhs_priv *priv);
  78. void usbhs_mod_register(struct usbhs_priv *priv, struct usbhs_mod *usb, int id);
  79. int usbhs_mod_is_host(struct usbhs_priv *priv);
  80. int usbhs_mod_change(struct usbhs_priv *priv, int id);
  81. int usbhs_mod_probe(struct usbhs_priv *priv);
  82. void usbhs_mod_remove(struct usbhs_priv *priv);
  83. void usbhs_mod_autonomy_mode(struct usbhs_priv *priv);
  84. /*
  85. * status functions
  86. */
  87. int usbhs_status_get_device_state(struct usbhs_irq_state *irq_state);
  88. int usbhs_status_get_ctrl_stage(struct usbhs_irq_state *irq_state);
  89. /*
  90. * callback functions
  91. */
  92. void usbhs_irq_callback_update(struct usbhs_priv *priv, struct usbhs_mod *mod);
  93. #define usbhs_mod_call(priv, func, param...) \
  94. ({ \
  95. struct usbhs_mod *mod; \
  96. mod = usbhs_mod_get_current(priv); \
  97. !mod ? -ENODEV : \
  98. !mod->func ? 0 : \
  99. mod->func(param); \
  100. })
  101. /*
  102. * gadget control
  103. */
  104. #ifdef CONFIG_USB_RENESAS_USBHS_UDC
  105. extern int __devinit usbhs_mod_gadget_probe(struct usbhs_priv *priv);
  106. extern void __devexit usbhs_mod_gadget_remove(struct usbhs_priv *priv);
  107. #else
  108. static inline int usbhs_mod_gadget_probe(struct usbhs_priv *priv)
  109. {
  110. return 0;
  111. }
  112. static inline void usbhs_mod_gadget_remove(struct usbhs_priv *priv)
  113. {
  114. }
  115. #endif
  116. #endif /* RENESAS_USB_MOD_H */