mod.h 3.4 KB

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