intel_mid_otg.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * Intel MID (Langwell/Penwell) USB OTG Transceiver driver
  3. * Copyright (C) 2008 - 2010, Intel Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  17. *
  18. */
  19. #ifndef __INTEL_MID_OTG_H
  20. #define __INTEL_MID_OTG_H
  21. #include <linux/pm.h>
  22. #include <linux/usb/otg.h>
  23. #include <linux/notifier.h>
  24. struct intel_mid_otg_xceiv;
  25. /* This is a common data structure for Intel MID platform to
  26. * save values of the OTG state machine */
  27. struct otg_hsm {
  28. /* Input */
  29. int a_bus_resume;
  30. int a_bus_suspend;
  31. int a_conn;
  32. int a_sess_vld;
  33. int a_srp_det;
  34. int a_vbus_vld;
  35. int b_bus_resume;
  36. int b_bus_suspend;
  37. int b_conn;
  38. int b_se0_srp;
  39. int b_ssend_srp;
  40. int b_sess_end;
  41. int b_sess_vld;
  42. int id;
  43. /* id values */
  44. #define ID_B 0x05
  45. #define ID_A 0x04
  46. #define ID_ACA_C 0x03
  47. #define ID_ACA_B 0x02
  48. #define ID_ACA_A 0x01
  49. int power_up;
  50. int adp_change;
  51. int test_device;
  52. /* Internal variables */
  53. int a_set_b_hnp_en;
  54. int b_srp_done;
  55. int b_hnp_enable;
  56. int hnp_poll_enable;
  57. /* Timeout indicator for timers */
  58. int a_wait_vrise_tmout;
  59. int a_wait_bcon_tmout;
  60. int a_aidl_bdis_tmout;
  61. int a_bidl_adis_tmout;
  62. int a_bidl_adis_tmr;
  63. int a_wait_vfall_tmout;
  64. int b_ase0_brst_tmout;
  65. int b_bus_suspend_tmout;
  66. int b_srp_init_tmout;
  67. int b_srp_fail_tmout;
  68. int b_srp_fail_tmr;
  69. int b_adp_sense_tmout;
  70. /* Informative variables */
  71. int a_bus_drop;
  72. int a_bus_req;
  73. int a_clr_err;
  74. int b_bus_req;
  75. int a_suspend_req;
  76. int b_bus_suspend_vld;
  77. /* Output */
  78. int drv_vbus;
  79. int loc_conn;
  80. int loc_sof;
  81. /* Others */
  82. int vbus_srp_up;
  83. };
  84. /* must provide ULPI access function to read/write registers implemented in
  85. * ULPI address space */
  86. struct iotg_ulpi_access_ops {
  87. int (*read)(struct intel_mid_otg_xceiv *iotg, u8 reg, u8 *val);
  88. int (*write)(struct intel_mid_otg_xceiv *iotg, u8 reg, u8 val);
  89. };
  90. #define OTG_A_DEVICE 0x0
  91. #define OTG_B_DEVICE 0x1
  92. /*
  93. * the Intel MID (Langwell/Penwell) otg transceiver driver needs to interact
  94. * with device and host drivers to implement the USB OTG related feature. More
  95. * function members are added based on usb_phy data structure for this
  96. * purpose.
  97. */
  98. struct intel_mid_otg_xceiv {
  99. struct usb_phy otg;
  100. struct otg_hsm hsm;
  101. /* base address */
  102. void __iomem *base;
  103. /* ops to access ulpi */
  104. struct iotg_ulpi_access_ops ulpi_ops;
  105. /* atomic notifier for interrupt context */
  106. struct atomic_notifier_head iotg_notifier;
  107. /* start/stop USB Host function */
  108. int (*start_host)(struct intel_mid_otg_xceiv *iotg);
  109. int (*stop_host)(struct intel_mid_otg_xceiv *iotg);
  110. /* start/stop USB Peripheral function */
  111. int (*start_peripheral)(struct intel_mid_otg_xceiv *iotg);
  112. int (*stop_peripheral)(struct intel_mid_otg_xceiv *iotg);
  113. /* start/stop ADP sense/probe function */
  114. int (*set_adp_probe)(struct intel_mid_otg_xceiv *iotg,
  115. bool enabled, int dev);
  116. int (*set_adp_sense)(struct intel_mid_otg_xceiv *iotg,
  117. bool enabled);
  118. #ifdef CONFIG_PM
  119. /* suspend/resume USB host function */
  120. int (*suspend_host)(struct intel_mid_otg_xceiv *iotg,
  121. pm_message_t message);
  122. int (*resume_host)(struct intel_mid_otg_xceiv *iotg);
  123. int (*suspend_peripheral)(struct intel_mid_otg_xceiv *iotg,
  124. pm_message_t message);
  125. int (*resume_peripheral)(struct intel_mid_otg_xceiv *iotg);
  126. #endif
  127. };
  128. static inline
  129. struct intel_mid_otg_xceiv *otg_to_mid_xceiv(struct usb_phy *otg)
  130. {
  131. return container_of(otg, struct intel_mid_otg_xceiv, otg);
  132. }
  133. #define MID_OTG_NOTIFY_CONNECT 0x0001
  134. #define MID_OTG_NOTIFY_DISCONN 0x0002
  135. #define MID_OTG_NOTIFY_HSUSPEND 0x0003
  136. #define MID_OTG_NOTIFY_HRESUME 0x0004
  137. #define MID_OTG_NOTIFY_CSUSPEND 0x0005
  138. #define MID_OTG_NOTIFY_CRESUME 0x0006
  139. #define MID_OTG_NOTIFY_HOSTADD 0x0007
  140. #define MID_OTG_NOTIFY_HOSTREMOVE 0x0008
  141. #define MID_OTG_NOTIFY_CLIENTADD 0x0009
  142. #define MID_OTG_NOTIFY_CLIENTREMOVE 0x000a
  143. static inline int
  144. intel_mid_otg_register_notifier(struct intel_mid_otg_xceiv *iotg,
  145. struct notifier_block *nb)
  146. {
  147. return atomic_notifier_chain_register(&iotg->iotg_notifier, nb);
  148. }
  149. static inline void
  150. intel_mid_otg_unregister_notifier(struct intel_mid_otg_xceiv *iotg,
  151. struct notifier_block *nb)
  152. {
  153. atomic_notifier_chain_unregister(&iotg->iotg_notifier, nb);
  154. }
  155. #endif /* __INTEL_MID_OTG_H */