drd.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Cadence USB3 and USBSSP DRD header file.
  4. *
  5. * Copyright (C) 2018-2020 Cadence.
  6. *
  7. * Author: Pawel Laszczak <[email protected]>
  8. */
  9. #ifndef __LINUX_CDNS3_DRD
  10. #define __LINUX_CDNS3_DRD
  11. #include <linux/usb/otg.h>
  12. #include "core.h"
  13. /* DRD register interface for version v1 of cdns3 driver. */
  14. struct cdns3_otg_regs {
  15. __le32 did;
  16. __le32 rid;
  17. __le32 capabilities;
  18. __le32 reserved1;
  19. __le32 cmd;
  20. __le32 sts;
  21. __le32 state;
  22. __le32 reserved2;
  23. __le32 ien;
  24. __le32 ivect;
  25. __le32 refclk;
  26. __le32 tmr;
  27. __le32 reserved3[4];
  28. __le32 simulate;
  29. __le32 override;
  30. __le32 susp_ctrl;
  31. __le32 phyrst_cfg;
  32. __le32 anasts;
  33. __le32 adp_ramp_time;
  34. __le32 ctrl1;
  35. __le32 ctrl2;
  36. };
  37. /* DRD register interface for version v0 of cdns3 driver. */
  38. struct cdns3_otg_legacy_regs {
  39. __le32 cmd;
  40. __le32 sts;
  41. __le32 state;
  42. __le32 refclk;
  43. __le32 ien;
  44. __le32 ivect;
  45. __le32 reserved1[3];
  46. __le32 tmr;
  47. __le32 reserved2[2];
  48. __le32 version;
  49. __le32 capabilities;
  50. __le32 reserved3[2];
  51. __le32 simulate;
  52. __le32 reserved4[5];
  53. __le32 ctrl1;
  54. };
  55. /* DRD register interface for cdnsp driver */
  56. struct cdnsp_otg_regs {
  57. __le32 did;
  58. __le32 rid;
  59. __le32 cfgs1;
  60. __le32 cfgs2;
  61. __le32 cmd;
  62. __le32 sts;
  63. __le32 state;
  64. __le32 ien;
  65. __le32 ivect;
  66. __le32 tmr;
  67. __le32 simulate;
  68. __le32 adpbc_sts;
  69. __le32 adp_ramp_time;
  70. __le32 adpbc_ctrl1;
  71. __le32 adpbc_ctrl2;
  72. __le32 override;
  73. __le32 vbusvalid_dbnc_cfg;
  74. __le32 sessvalid_dbnc_cfg;
  75. __le32 susp_timing_ctrl;
  76. };
  77. #define OTG_CDNSP_DID 0x0004034E
  78. /*
  79. * Common registers interface for both CDNS3 and CDNSP version of DRD.
  80. */
  81. struct cdns_otg_common_regs {
  82. __le32 cmd;
  83. __le32 sts;
  84. __le32 state;
  85. };
  86. /*
  87. * Interrupt related registers. This registers are mapped in different
  88. * location for CDNSP controller.
  89. */
  90. struct cdns_otg_irq_regs {
  91. __le32 ien;
  92. __le32 ivect;
  93. };
  94. /* CDNS_RID - bitmasks */
  95. #define CDNS_RID(p) ((p) & GENMASK(15, 0))
  96. /* CDNS_VID - bitmasks */
  97. #define CDNS_DID(p) ((p) & GENMASK(31, 0))
  98. /* OTGCMD - bitmasks */
  99. /* "Request the bus for Device mode. */
  100. #define OTGCMD_DEV_BUS_REQ BIT(0)
  101. /* Request the bus for Host mode */
  102. #define OTGCMD_HOST_BUS_REQ BIT(1)
  103. /* Enable OTG mode. */
  104. #define OTGCMD_OTG_EN BIT(2)
  105. /* Disable OTG mode */
  106. #define OTGCMD_OTG_DIS BIT(3)
  107. /*"Configure OTG as A-Device. */
  108. #define OTGCMD_A_DEV_EN BIT(4)
  109. /*"Configure OTG as A-Device. */
  110. #define OTGCMD_A_DEV_DIS BIT(5)
  111. /* Drop the bus for Device mod e. */
  112. #define OTGCMD_DEV_BUS_DROP BIT(8)
  113. /* Drop the bus for Host mode*/
  114. #define OTGCMD_HOST_BUS_DROP BIT(9)
  115. /* Power Down USBSS-DEV - only for CDNS3.*/
  116. #define OTGCMD_DEV_POWER_OFF BIT(11)
  117. /* Power Down CDNSXHCI - only for CDNS3. */
  118. #define OTGCMD_HOST_POWER_OFF BIT(12)
  119. /* OTGIEN - bitmasks */
  120. /* ID change interrupt enable */
  121. #define OTGIEN_ID_CHANGE_INT BIT(0)
  122. /* Vbusvalid fall detected interrupt enable.*/
  123. #define OTGIEN_VBUSVALID_RISE_INT BIT(4)
  124. /* Vbusvalid fall detected interrupt enable */
  125. #define OTGIEN_VBUSVALID_FALL_INT BIT(5)
  126. /* OTGSTS - bitmasks */
  127. /*
  128. * Current value of the ID pin. It is only valid when idpullup in
  129. * OTGCTRL1_TYPE register is set to '1'.
  130. */
  131. #define OTGSTS_ID_VALUE BIT(0)
  132. /* Current value of the vbus_valid */
  133. #define OTGSTS_VBUS_VALID BIT(1)
  134. /* Current value of the b_sess_vld */
  135. #define OTGSTS_SESSION_VALID BIT(2)
  136. /*Device mode is active*/
  137. #define OTGSTS_DEV_ACTIVE BIT(3)
  138. /* Host mode is active. */
  139. #define OTGSTS_HOST_ACTIVE BIT(4)
  140. /* OTG Controller not ready. */
  141. #define OTGSTS_OTG_NRDY_MASK BIT(11)
  142. #define OTGSTS_OTG_NRDY(p) ((p) & OTGSTS_OTG_NRDY_MASK)
  143. /*
  144. * Value of the strap pins for:
  145. * CDNS3:
  146. * 000 - no default configuration
  147. * 010 - Controller initiall configured as Host
  148. * 100 - Controller initially configured as Device
  149. * CDNSP:
  150. * 000 - No default configuration.
  151. * 010 - Controller initiall configured as Host.
  152. * 100 - Controller initially configured as Device.
  153. */
  154. #define OTGSTS_STRAP(p) (((p) & GENMASK(14, 12)) >> 12)
  155. #define OTGSTS_STRAP_NO_DEFAULT_CFG 0x00
  156. #define OTGSTS_STRAP_HOST_OTG 0x01
  157. #define OTGSTS_STRAP_HOST 0x02
  158. #define OTGSTS_STRAP_GADGET 0x04
  159. #define OTGSTS_CDNSP_STRAP_HOST 0x01
  160. #define OTGSTS_CDNSP_STRAP_GADGET 0x02
  161. /* Host mode is turned on. */
  162. #define OTGSTS_CDNS3_XHCI_READY BIT(26)
  163. #define OTGSTS_CDNSP_XHCI_READY BIT(27)
  164. /* "Device mode is turned on .*/
  165. #define OTGSTS_CDNS3_DEV_READY BIT(27)
  166. #define OTGSTS_CDNSP_DEV_READY BIT(26)
  167. /* OTGSTATE- bitmasks */
  168. #define OTGSTATE_DEV_STATE_MASK GENMASK(2, 0)
  169. #define OTGSTATE_HOST_STATE_MASK GENMASK(5, 3)
  170. #define OTGSTATE_HOST_STATE_IDLE 0x0
  171. #define OTGSTATE_HOST_STATE_VBUS_FALL 0x7
  172. #define OTGSTATE_HOST_STATE(p) (((p) & OTGSTATE_HOST_STATE_MASK) >> 3)
  173. /* OTGREFCLK - bitmasks */
  174. #define OTGREFCLK_STB_CLK_SWITCH_EN BIT(31)
  175. /* OVERRIDE - bitmasks */
  176. #define OVERRIDE_IDPULLUP BIT(0)
  177. /* Only for CDNS3_CONTROLLER_V0 version */
  178. #define OVERRIDE_IDPULLUP_V0 BIT(24)
  179. /* Vbusvalid/Sesvalid override select. */
  180. #define OVERRIDE_SESS_VLD_SEL BIT(10)
  181. /* PHYRST_CFG - bitmasks */
  182. #define PHYRST_CFG_PHYRST_A_ENABLE BIT(0)
  183. #define CDNS3_ID_PERIPHERAL 1
  184. #define CDNS3_ID_HOST 0
  185. bool cdns_is_host(struct cdns *cdns);
  186. bool cdns_is_device(struct cdns *cdns);
  187. int cdns_get_id(struct cdns *cdns);
  188. int cdns_get_vbus(struct cdns *cdns);
  189. void cdns_clear_vbus(struct cdns *cdns);
  190. void cdns_set_vbus(struct cdns *cdns);
  191. int cdns_drd_init(struct cdns *cdns);
  192. int cdns_drd_exit(struct cdns *cdns);
  193. int cdns_drd_update_mode(struct cdns *cdns);
  194. int cdns_drd_gadget_on(struct cdns *cdns);
  195. void cdns_drd_gadget_off(struct cdns *cdns);
  196. int cdns_drd_host_on(struct cdns *cdns);
  197. void cdns_drd_host_off(struct cdns *cdns);
  198. bool cdns_power_is_lost(struct cdns *cdns);
  199. #endif /* __LINUX_CDNS3_DRD */