otg_fsm.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* Copyright (C) 2007,2008 Freescale Semiconductor, Inc.
  2. *
  3. * This program is free software; you can redistribute it and/or modify it
  4. * under the terms of the GNU General Public License as published by the
  5. * Free Software Foundation; either version 2 of the License, or (at your
  6. * option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along
  14. * with this program; if not, write to the Free Software Foundation, Inc.,
  15. * 675 Mass Ave, Cambridge, MA 02139, USA.
  16. */
  17. #undef DEBUG
  18. #undef VERBOSE
  19. #ifdef DEBUG
  20. #define DBG(fmt, args...) printk(KERN_DEBUG "[%s] " fmt , \
  21. __func__, ## args)
  22. #else
  23. #define DBG(fmt, args...) do {} while (0)
  24. #endif
  25. #ifdef VERBOSE
  26. #define VDBG DBG
  27. #else
  28. #define VDBG(stuff...) do {} while (0)
  29. #endif
  30. #ifdef VERBOSE
  31. #define MPC_LOC printk("Current Location [%s]:[%d]\n", __FILE__, __LINE__)
  32. #else
  33. #define MPC_LOC do {} while (0)
  34. #endif
  35. #define PROTO_UNDEF (0)
  36. #define PROTO_HOST (1)
  37. #define PROTO_GADGET (2)
  38. /* OTG state machine according to the OTG spec */
  39. struct otg_fsm {
  40. /* Input */
  41. int a_bus_resume;
  42. int a_bus_suspend;
  43. int a_conn;
  44. int a_sess_vld;
  45. int a_srp_det;
  46. int a_vbus_vld;
  47. int b_bus_resume;
  48. int b_bus_suspend;
  49. int b_conn;
  50. int b_se0_srp;
  51. int b_sess_end;
  52. int b_sess_vld;
  53. int id;
  54. /* Internal variables */
  55. int a_set_b_hnp_en;
  56. int b_srp_done;
  57. int b_hnp_enable;
  58. /* Timeout indicator for timers */
  59. int a_wait_vrise_tmout;
  60. int a_wait_bcon_tmout;
  61. int a_aidl_bdis_tmout;
  62. int b_ase0_brst_tmout;
  63. /* Informative variables */
  64. int a_bus_drop;
  65. int a_bus_req;
  66. int a_clr_err;
  67. int a_suspend_req;
  68. int b_bus_req;
  69. /* Output */
  70. int drv_vbus;
  71. int loc_conn;
  72. int loc_sof;
  73. struct otg_fsm_ops *ops;
  74. struct usb_otg *otg;
  75. /* Current usb protocol used: 0:undefine; 1:host; 2:client */
  76. int protocol;
  77. spinlock_t lock;
  78. };
  79. struct otg_fsm_ops {
  80. void (*chrg_vbus)(int on);
  81. void (*drv_vbus)(int on);
  82. void (*loc_conn)(int on);
  83. void (*loc_sof)(int on);
  84. void (*start_pulse)(void);
  85. void (*add_timer)(void *timer);
  86. void (*del_timer)(void *timer);
  87. int (*start_host)(struct otg_fsm *fsm, int on);
  88. int (*start_gadget)(struct otg_fsm *fsm, int on);
  89. };
  90. static inline void otg_chrg_vbus(struct otg_fsm *fsm, int on)
  91. {
  92. fsm->ops->chrg_vbus(on);
  93. }
  94. static inline void otg_drv_vbus(struct otg_fsm *fsm, int on)
  95. {
  96. if (fsm->drv_vbus != on) {
  97. fsm->drv_vbus = on;
  98. fsm->ops->drv_vbus(on);
  99. }
  100. }
  101. static inline void otg_loc_conn(struct otg_fsm *fsm, int on)
  102. {
  103. if (fsm->loc_conn != on) {
  104. fsm->loc_conn = on;
  105. fsm->ops->loc_conn(on);
  106. }
  107. }
  108. static inline void otg_loc_sof(struct otg_fsm *fsm, int on)
  109. {
  110. if (fsm->loc_sof != on) {
  111. fsm->loc_sof = on;
  112. fsm->ops->loc_sof(on);
  113. }
  114. }
  115. static inline void otg_start_pulse(struct otg_fsm *fsm)
  116. {
  117. fsm->ops->start_pulse();
  118. }
  119. static inline void otg_add_timer(struct otg_fsm *fsm, void *timer)
  120. {
  121. fsm->ops->add_timer(timer);
  122. }
  123. static inline void otg_del_timer(struct otg_fsm *fsm, void *timer)
  124. {
  125. fsm->ops->del_timer(timer);
  126. }
  127. int otg_statemachine(struct otg_fsm *fsm);
  128. /* Defined by device specific driver, for different timer implementation */
  129. extern struct fsl_otg_timer *a_wait_vrise_tmr, *a_wait_bcon_tmr,
  130. *a_aidl_bdis_tmr, *b_ase0_brst_tmr, *b_se0_srp_tmr, *b_srp_fail_tmr,
  131. *a_wait_enum_tmr;