phy-fsm-usb.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. enum otg_fsm_timer {
  33. /* Standard OTG timers */
  34. A_WAIT_VRISE,
  35. A_WAIT_VFALL,
  36. A_WAIT_BCON,
  37. A_AIDL_BDIS,
  38. B_ASE0_BRST,
  39. A_BIDL_ADIS,
  40. /* Auxiliary timers */
  41. B_SE0_SRP,
  42. B_SRP_FAIL,
  43. A_WAIT_ENUM,
  44. NUM_OTG_FSM_TIMERS,
  45. };
  46. /* OTG state machine according to the OTG spec */
  47. struct otg_fsm {
  48. /* Input */
  49. int id;
  50. int adp_change;
  51. int power_up;
  52. int test_device;
  53. int a_bus_drop;
  54. int a_bus_req;
  55. int a_srp_det;
  56. int a_vbus_vld;
  57. int b_conn;
  58. int a_bus_resume;
  59. int a_bus_suspend;
  60. int a_conn;
  61. int b_bus_req;
  62. int b_se0_srp;
  63. int b_ssend_srp;
  64. int b_sess_vld;
  65. /* Auxilary inputs */
  66. int a_sess_vld;
  67. int b_bus_resume;
  68. int b_bus_suspend;
  69. /* Output */
  70. int data_pulse;
  71. int drv_vbus;
  72. int loc_conn;
  73. int loc_sof;
  74. int adp_prb;
  75. int adp_sns;
  76. /* Internal variables */
  77. int a_set_b_hnp_en;
  78. int b_srp_done;
  79. int b_hnp_enable;
  80. int a_clr_err;
  81. /* Informative variables */
  82. int a_bus_drop_inf;
  83. int a_bus_req_inf;
  84. int a_clr_err_inf;
  85. int b_bus_req_inf;
  86. /* Auxilary informative variables */
  87. int a_suspend_req_inf;
  88. /* Timeout indicator for timers */
  89. int a_wait_vrise_tmout;
  90. int a_wait_vfall_tmout;
  91. int a_wait_bcon_tmout;
  92. int a_aidl_bdis_tmout;
  93. int b_ase0_brst_tmout;
  94. int a_bidl_adis_tmout;
  95. struct otg_fsm_ops *ops;
  96. struct usb_otg *otg;
  97. /* Current usb protocol used: 0:undefine; 1:host; 2:client */
  98. int protocol;
  99. spinlock_t lock;
  100. };
  101. struct otg_fsm_ops {
  102. void (*chrg_vbus)(struct otg_fsm *fsm, int on);
  103. void (*drv_vbus)(struct otg_fsm *fsm, int on);
  104. void (*loc_conn)(struct otg_fsm *fsm, int on);
  105. void (*loc_sof)(struct otg_fsm *fsm, int on);
  106. void (*start_pulse)(struct otg_fsm *fsm);
  107. void (*start_adp_prb)(struct otg_fsm *fsm);
  108. void (*start_adp_sns)(struct otg_fsm *fsm);
  109. void (*add_timer)(struct otg_fsm *fsm, enum otg_fsm_timer timer);
  110. void (*del_timer)(struct otg_fsm *fsm, enum otg_fsm_timer timer);
  111. int (*start_host)(struct otg_fsm *fsm, int on);
  112. int (*start_gadget)(struct otg_fsm *fsm, int on);
  113. };
  114. static inline int otg_chrg_vbus(struct otg_fsm *fsm, int on)
  115. {
  116. if (!fsm->ops->chrg_vbus)
  117. return -EOPNOTSUPP;
  118. fsm->ops->chrg_vbus(fsm, on);
  119. return 0;
  120. }
  121. static inline int otg_drv_vbus(struct otg_fsm *fsm, int on)
  122. {
  123. if (!fsm->ops->drv_vbus)
  124. return -EOPNOTSUPP;
  125. if (fsm->drv_vbus != on) {
  126. fsm->drv_vbus = on;
  127. fsm->ops->drv_vbus(fsm, on);
  128. }
  129. return 0;
  130. }
  131. static inline int otg_loc_conn(struct otg_fsm *fsm, int on)
  132. {
  133. if (!fsm->ops->loc_conn)
  134. return -EOPNOTSUPP;
  135. if (fsm->loc_conn != on) {
  136. fsm->loc_conn = on;
  137. fsm->ops->loc_conn(fsm, on);
  138. }
  139. return 0;
  140. }
  141. static inline int otg_loc_sof(struct otg_fsm *fsm, int on)
  142. {
  143. if (!fsm->ops->loc_sof)
  144. return -EOPNOTSUPP;
  145. if (fsm->loc_sof != on) {
  146. fsm->loc_sof = on;
  147. fsm->ops->loc_sof(fsm, on);
  148. }
  149. return 0;
  150. }
  151. static inline int otg_start_pulse(struct otg_fsm *fsm)
  152. {
  153. if (!fsm->ops->start_pulse)
  154. return -EOPNOTSUPP;
  155. if (!fsm->data_pulse) {
  156. fsm->data_pulse = 1;
  157. fsm->ops->start_pulse(fsm);
  158. }
  159. return 0;
  160. }
  161. static inline int otg_start_adp_prb(struct otg_fsm *fsm)
  162. {
  163. if (!fsm->ops->start_adp_prb)
  164. return -EOPNOTSUPP;
  165. if (!fsm->adp_prb) {
  166. fsm->adp_sns = 0;
  167. fsm->adp_prb = 1;
  168. fsm->ops->start_adp_prb(fsm);
  169. }
  170. return 0;
  171. }
  172. static inline int otg_start_adp_sns(struct otg_fsm *fsm)
  173. {
  174. if (!fsm->ops->start_adp_sns)
  175. return -EOPNOTSUPP;
  176. if (!fsm->adp_sns) {
  177. fsm->adp_sns = 1;
  178. fsm->ops->start_adp_sns(fsm);
  179. }
  180. return 0;
  181. }
  182. static inline int otg_add_timer(struct otg_fsm *fsm, enum otg_fsm_timer timer)
  183. {
  184. if (!fsm->ops->add_timer)
  185. return -EOPNOTSUPP;
  186. fsm->ops->add_timer(fsm, timer);
  187. return 0;
  188. }
  189. static inline int otg_del_timer(struct otg_fsm *fsm, enum otg_fsm_timer timer)
  190. {
  191. if (!fsm->ops->del_timer)
  192. return -EOPNOTSUPP;
  193. fsm->ops->del_timer(fsm, timer);
  194. return 0;
  195. }
  196. static inline int otg_start_host(struct otg_fsm *fsm, int on)
  197. {
  198. if (!fsm->ops->start_host)
  199. return -EOPNOTSUPP;
  200. return fsm->ops->start_host(fsm, on);
  201. }
  202. static inline int otg_start_gadget(struct otg_fsm *fsm, int on)
  203. {
  204. if (!fsm->ops->start_gadget)
  205. return -EOPNOTSUPP;
  206. return fsm->ops->start_gadget(fsm, on);
  207. }
  208. int otg_statemachine(struct otg_fsm *fsm);