phy-fsm-usb.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 VERBOSE
  18. #ifdef VERBOSE
  19. #define VDBG(fmt, args...) pr_debug("[%s] " fmt , \
  20. __func__, ## args)
  21. #else
  22. #define VDBG(stuff...) do {} while (0)
  23. #endif
  24. #ifdef VERBOSE
  25. #define MPC_LOC printk("Current Location [%s]:[%d]\n", __FILE__, __LINE__)
  26. #else
  27. #define MPC_LOC do {} while (0)
  28. #endif
  29. #define PROTO_UNDEF (0)
  30. #define PROTO_HOST (1)
  31. #define PROTO_GADGET (2)
  32. /* OTG state machine according to the OTG spec */
  33. struct otg_fsm {
  34. /* Input */
  35. int a_bus_resume;
  36. int a_bus_suspend;
  37. int a_conn;
  38. int a_sess_vld;
  39. int a_srp_det;
  40. int a_vbus_vld;
  41. int b_bus_resume;
  42. int b_bus_suspend;
  43. int b_conn;
  44. int b_se0_srp;
  45. int b_sess_end;
  46. int b_sess_vld;
  47. int id;
  48. /* Internal variables */
  49. int a_set_b_hnp_en;
  50. int b_srp_done;
  51. int b_hnp_enable;
  52. /* Timeout indicator for timers */
  53. int a_wait_vrise_tmout;
  54. int a_wait_bcon_tmout;
  55. int a_aidl_bdis_tmout;
  56. int b_ase0_brst_tmout;
  57. /* Informative variables */
  58. int a_bus_drop;
  59. int a_bus_req;
  60. int a_clr_err;
  61. int a_suspend_req;
  62. int b_bus_req;
  63. /* Output */
  64. int drv_vbus;
  65. int loc_conn;
  66. int loc_sof;
  67. struct otg_fsm_ops *ops;
  68. struct usb_otg *otg;
  69. /* Current usb protocol used: 0:undefine; 1:host; 2:client */
  70. int protocol;
  71. spinlock_t lock;
  72. };
  73. struct otg_fsm_ops {
  74. void (*chrg_vbus)(int on);
  75. void (*drv_vbus)(int on);
  76. void (*loc_conn)(int on);
  77. void (*loc_sof)(int on);
  78. void (*start_pulse)(void);
  79. void (*add_timer)(void *timer);
  80. void (*del_timer)(void *timer);
  81. int (*start_host)(struct otg_fsm *fsm, int on);
  82. int (*start_gadget)(struct otg_fsm *fsm, int on);
  83. };
  84. static inline void otg_chrg_vbus(struct otg_fsm *fsm, int on)
  85. {
  86. fsm->ops->chrg_vbus(on);
  87. }
  88. static inline void otg_drv_vbus(struct otg_fsm *fsm, int on)
  89. {
  90. if (fsm->drv_vbus != on) {
  91. fsm->drv_vbus = on;
  92. fsm->ops->drv_vbus(on);
  93. }
  94. }
  95. static inline void otg_loc_conn(struct otg_fsm *fsm, int on)
  96. {
  97. if (fsm->loc_conn != on) {
  98. fsm->loc_conn = on;
  99. fsm->ops->loc_conn(on);
  100. }
  101. }
  102. static inline void otg_loc_sof(struct otg_fsm *fsm, int on)
  103. {
  104. if (fsm->loc_sof != on) {
  105. fsm->loc_sof = on;
  106. fsm->ops->loc_sof(on);
  107. }
  108. }
  109. static inline void otg_start_pulse(struct otg_fsm *fsm)
  110. {
  111. fsm->ops->start_pulse();
  112. }
  113. static inline void otg_add_timer(struct otg_fsm *fsm, void *timer)
  114. {
  115. fsm->ops->add_timer(timer);
  116. }
  117. static inline void otg_del_timer(struct otg_fsm *fsm, void *timer)
  118. {
  119. fsm->ops->del_timer(timer);
  120. }
  121. int otg_statemachine(struct otg_fsm *fsm);
  122. /* Defined by device specific driver, for different timer implementation */
  123. extern struct fsl_otg_timer *a_wait_vrise_tmr, *a_wait_bcon_tmr,
  124. *a_aidl_bdis_tmr, *b_ase0_brst_tmr, *b_se0_srp_tmr, *b_srp_fail_tmr,
  125. *a_wait_enum_tmr;