drd.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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 <pawell@cadence.com>
  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. /* CDNSP driver supports 0x000403xx Cadence USB controller family. */
  78. #define OTG_CDNSP_CHECK_DID(did) (((did) & GENMASK(31, 8)) == 0x00040300)
  79. /* CDNS3 driver supports 0x000402xx Cadence USB controller family. */
  80. #define OTG_CDNS3_CHECK_DID(did) (((did) & GENMASK(31, 8)) == 0x00040200)
  81. /*
  82. * Common registers interface for both CDNS3 and CDNSP version of DRD.
  83. */
  84. struct cdns_otg_common_regs {
  85. __le32 cmd;
  86. __le32 sts;
  87. __le32 state;
  88. };
  89. /*
  90. * Interrupt related registers. This registers are mapped in different
  91. * location for CDNSP controller.
  92. */
  93. struct cdns_otg_irq_regs {
  94. __le32 ien;
  95. __le32 ivect;
  96. };
  97. /* CDNS_RID - bitmasks */
  98. #define CDNS_RID(p) ((p) & GENMASK(15, 0))
  99. /* CDNS_VID - bitmasks */
  100. #define CDNS_DID(p) ((p) & GENMASK(31, 0))
  101. /* OTGCMD - bitmasks */
  102. /* "Request the bus for Device mode. */
  103. #define OTGCMD_DEV_BUS_REQ BIT(0)
  104. /* Request the bus for Host mode */
  105. #define OTGCMD_HOST_BUS_REQ BIT(1)
  106. /* Enable OTG mode. */
  107. #define OTGCMD_OTG_EN BIT(2)
  108. /* Disable OTG mode */
  109. #define OTGCMD_OTG_DIS BIT(3)
  110. /*"Configure OTG as A-Device. */
  111. #define OTGCMD_A_DEV_EN BIT(4)
  112. /*"Configure OTG as A-Device. */
  113. #define OTGCMD_A_DEV_DIS BIT(5)
  114. /* Drop the bus for Device mod e. */
  115. #define OTGCMD_DEV_BUS_DROP BIT(8)
  116. /* Drop the bus for Host mode*/
  117. #define OTGCMD_HOST_BUS_DROP BIT(9)
  118. /* Power Down USBSS-DEV - only for CDNS3.*/
  119. #define OTGCMD_DEV_POWER_OFF BIT(11)
  120. /* Power Down CDNSXHCI - only for CDNS3. */
  121. #define OTGCMD_HOST_POWER_OFF BIT(12)
  122. /* OTGIEN - bitmasks */
  123. /* ID change interrupt enable */
  124. #define OTGIEN_ID_CHANGE_INT BIT(0)
  125. /* Vbusvalid fall detected interrupt enable.*/
  126. #define OTGIEN_VBUSVALID_RISE_INT BIT(4)
  127. /* Vbusvalid fall detected interrupt enable */
  128. #define OTGIEN_VBUSVALID_FALL_INT BIT(5)
  129. /* OTGSTS - bitmasks */
  130. /*
  131. * Current value of the ID pin. It is only valid when idpullup in
  132. * OTGCTRL1_TYPE register is set to '1'.
  133. */
  134. #define OTGSTS_ID_VALUE BIT(0)
  135. /* Current value of the vbus_valid */
  136. #define OTGSTS_VBUS_VALID BIT(1)
  137. /* Current value of the b_sess_vld */
  138. #define OTGSTS_SESSION_VALID BIT(2)
  139. /*Device mode is active*/
  140. #define OTGSTS_DEV_ACTIVE BIT(3)
  141. /* Host mode is active. */
  142. #define OTGSTS_HOST_ACTIVE BIT(4)
  143. /* OTG Controller not ready. */
  144. #define OTGSTS_OTG_NRDY_MASK BIT(11)
  145. #define OTGSTS_OTG_NRDY(p) ((p) & OTGSTS_OTG_NRDY_MASK)
  146. /*
  147. * Value of the strap pins for:
  148. * CDNS3:
  149. * 000 - no default configuration
  150. * 010 - Controller initiall configured as Host
  151. * 100 - Controller initially configured as Device
  152. * CDNSP:
  153. * 000 - No default configuration.
  154. * 010 - Controller initiall configured as Host.
  155. * 100 - Controller initially configured as Device.
  156. */
  157. #define OTGSTS_STRAP(p) (((p) & GENMASK(14, 12)) >> 12)
  158. #define OTGSTS_STRAP_NO_DEFAULT_CFG 0x00
  159. #define OTGSTS_STRAP_HOST_OTG 0x01
  160. #define OTGSTS_STRAP_HOST 0x02
  161. #define OTGSTS_STRAP_GADGET 0x04
  162. #define OTGSTS_CDNSP_STRAP_HOST 0x01
  163. #define OTGSTS_CDNSP_STRAP_GADGET 0x02
  164. /* Host mode is turned on. */
  165. #define OTGSTS_CDNS3_XHCI_READY BIT(26)
  166. #define OTGSTS_CDNSP_XHCI_READY BIT(27)
  167. /* "Device mode is turned on .*/
  168. #define OTGSTS_CDNS3_DEV_READY BIT(27)
  169. #define OTGSTS_CDNSP_DEV_READY BIT(26)
  170. /* OTGSTATE- bitmasks */
  171. #define OTGSTATE_DEV_STATE_MASK GENMASK(2, 0)
  172. #define OTGSTATE_HOST_STATE_MASK GENMASK(5, 3)
  173. #define OTGSTATE_HOST_STATE_IDLE 0x0
  174. #define OTGSTATE_HOST_STATE_VBUS_FALL 0x7
  175. #define OTGSTATE_HOST_STATE(p) (((p) & OTGSTATE_HOST_STATE_MASK) >> 3)
  176. /* OTGREFCLK - bitmasks */
  177. #define OTGREFCLK_STB_CLK_SWITCH_EN BIT(31)
  178. /* SUPS_CTRL - bitmasks */
  179. #define SUSP_CTRL_SUSPEND_RESIDENCY_ENABLE BIT(17)
  180. /* OVERRIDE - bitmasks */
  181. #define OVERRIDE_IDPULLUP BIT(0)
  182. /* Only for CDNS3_CONTROLLER_V0 version */
  183. #define OVERRIDE_IDPULLUP_V0 BIT(24)
  184. /* Vbusvalid/Sesvalid override select. */
  185. #define OVERRIDE_SESS_VLD_SEL BIT(10)
  186. /* PHYRST_CFG - bitmasks */
  187. #define PHYRST_CFG_PHYRST_A_ENABLE BIT(0)
  188. #define CDNS3_ID_PERIPHERAL 1
  189. #define CDNS3_ID_HOST 0
  190. bool cdns_is_host(struct cdns *cdns);
  191. bool cdns_is_device(struct cdns *cdns);
  192. int cdns_get_id(struct cdns *cdns);
  193. int cdns_get_vbus(struct cdns *cdns);
  194. void cdns_clear_vbus(struct cdns *cdns);
  195. void cdns_set_vbus(struct cdns *cdns);
  196. int cdns_drd_init(struct cdns *cdns);
  197. int cdns_drd_exit(struct cdns *cdns);
  198. int cdns_drd_update_mode(struct cdns *cdns);
  199. int cdns_drd_gadget_on(struct cdns *cdns);
  200. void cdns_drd_gadget_off(struct cdns *cdns);
  201. int cdns_drd_host_on(struct cdns *cdns);
  202. void cdns_drd_host_off(struct cdns *cdns);
  203. bool cdns_power_is_lost(struct cdns *cdns);
  204. #endif /* __LINUX_CDNS3_DRD */