drd.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Cadence USB3 DRD header file.
  4. *
  5. * Copyright (C) 2018-2019 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 <linux/phy/phy.h>
  13. #include "core.h"
  14. /* DRD register interface for version v1. */
  15. struct cdns3_otg_regs {
  16. __le32 did;
  17. __le32 rid;
  18. __le32 capabilities;
  19. __le32 reserved1;
  20. __le32 cmd;
  21. __le32 sts;
  22. __le32 state;
  23. __le32 reserved2;
  24. __le32 ien;
  25. __le32 ivect;
  26. __le32 refclk;
  27. __le32 tmr;
  28. __le32 reserved3[4];
  29. __le32 simulate;
  30. __le32 override;
  31. __le32 susp_ctrl;
  32. __le32 reserved4;
  33. __le32 anasts;
  34. __le32 adp_ramp_time;
  35. __le32 ctrl1;
  36. __le32 ctrl2;
  37. };
  38. /* DRD register interface for version v0. */
  39. struct cdns3_otg_legacy_regs {
  40. __le32 cmd;
  41. __le32 sts;
  42. __le32 state;
  43. __le32 refclk;
  44. __le32 ien;
  45. __le32 ivect;
  46. __le32 reserved1[3];
  47. __le32 tmr;
  48. __le32 reserved2[2];
  49. __le32 version;
  50. __le32 capabilities;
  51. __le32 reserved3[2];
  52. __le32 simulate;
  53. __le32 reserved4[5];
  54. __le32 ctrl1;
  55. };
  56. /*
  57. * Common registers interface for both version of DRD.
  58. */
  59. struct cdns3_otg_common_regs {
  60. __le32 cmd;
  61. __le32 sts;
  62. __le32 state;
  63. __le32 different1;
  64. __le32 ien;
  65. __le32 ivect;
  66. };
  67. /* CDNS_RID - bitmasks */
  68. #define CDNS_RID(p) ((p) & GENMASK(15, 0))
  69. /* CDNS_VID - bitmasks */
  70. #define CDNS_DID(p) ((p) & GENMASK(31, 0))
  71. /* OTGCMD - bitmasks */
  72. /* "Request the bus for Device mode. */
  73. #define OTGCMD_DEV_BUS_REQ BIT(0)
  74. /* Request the bus for Host mode */
  75. #define OTGCMD_HOST_BUS_REQ BIT(1)
  76. /* Enable OTG mode. */
  77. #define OTGCMD_OTG_EN BIT(2)
  78. /* Disable OTG mode */
  79. #define OTGCMD_OTG_DIS BIT(3)
  80. /*"Configure OTG as A-Device. */
  81. #define OTGCMD_A_DEV_EN BIT(4)
  82. /*"Configure OTG as A-Device. */
  83. #define OTGCMD_A_DEV_DIS BIT(5)
  84. /* Drop the bus for Device mod e. */
  85. #define OTGCMD_DEV_BUS_DROP BIT(8)
  86. /* Drop the bus for Host mode*/
  87. #define OTGCMD_HOST_BUS_DROP BIT(9)
  88. /* Power Down USBSS-DEV. */
  89. #define OTGCMD_DEV_POWER_OFF BIT(11)
  90. /* Power Down CDNSXHCI. */
  91. #define OTGCMD_HOST_POWER_OFF BIT(12)
  92. /* OTGIEN - bitmasks */
  93. /* ID change interrupt enable */
  94. #define OTGIEN_ID_CHANGE_INT BIT(0)
  95. /* Vbusvalid fall detected interrupt enable.*/
  96. #define OTGIEN_VBUSVALID_RISE_INT BIT(4)
  97. /* Vbusvalid fall detected interrupt enable */
  98. #define OTGIEN_VBUSVALID_FALL_INT BIT(5)
  99. /* OTGSTS - bitmasks */
  100. /*
  101. * Current value of the ID pin. It is only valid when idpullup in
  102. * OTGCTRL1_TYPE register is set to '1'.
  103. */
  104. #define OTGSTS_ID_VALUE BIT(0)
  105. /* Current value of the vbus_valid */
  106. #define OTGSTS_VBUS_VALID BIT(1)
  107. /* Current value of the b_sess_vld */
  108. #define OTGSTS_SESSION_VALID BIT(2)
  109. /*Device mode is active*/
  110. #define OTGSTS_DEV_ACTIVE BIT(3)
  111. /* Host mode is active. */
  112. #define OTGSTS_HOST_ACTIVE BIT(4)
  113. /* OTG Controller not ready. */
  114. #define OTGSTS_OTG_NRDY_MASK BIT(11)
  115. #define OTGSTS_OTG_NRDY(p) ((p) & OTGSTS_OTG_NRDY_MASK)
  116. /*
  117. * Value of the strap pins.
  118. * 000 - no default configuration
  119. * 010 - Controller initiall configured as Host
  120. * 100 - Controller initially configured as Device
  121. */
  122. #define OTGSTS_STRAP(p) (((p) & GENMASK(14, 12)) >> 12)
  123. #define OTGSTS_STRAP_NO_DEFAULT_CFG 0x00
  124. #define OTGSTS_STRAP_HOST_OTG 0x01
  125. #define OTGSTS_STRAP_HOST 0x02
  126. #define OTGSTS_STRAP_GADGET 0x04
  127. /* Host mode is turned on. */
  128. #define OTGSTS_XHCI_READY BIT(26)
  129. /* "Device mode is turned on .*/
  130. #define OTGSTS_DEV_READY BIT(27)
  131. /* OTGSTATE- bitmasks */
  132. #define OTGSTATE_DEV_STATE_MASK GENMASK(2, 0)
  133. #define OTGSTATE_HOST_STATE_MASK GENMASK(5, 3)
  134. #define OTGSTATE_HOST_STATE_IDLE 0x0
  135. #define OTGSTATE_HOST_STATE_VBUS_FALL 0x7
  136. #define OTGSTATE_HOST_STATE(p) (((p) & OTGSTATE_HOST_STATE_MASK) >> 3)
  137. /* OTGREFCLK - bitmasks */
  138. #define OTGREFCLK_STB_CLK_SWITCH_EN BIT(31)
  139. /* OVERRIDE - bitmasks */
  140. #define OVERRIDE_IDPULLUP BIT(0)
  141. /* Only for CDNS3_CONTROLLER_V0 version */
  142. #define OVERRIDE_IDPULLUP_V0 BIT(24)
  143. int cdns3_is_host(struct cdns3 *cdns);
  144. int cdns3_is_device(struct cdns3 *cdns);
  145. int cdns3_get_id(struct cdns3 *cdns);
  146. int cdns3_get_vbus(struct cdns3 *cdns);
  147. int cdns3_drd_init(struct cdns3 *cdns);
  148. int cdns3_drd_exit(struct cdns3 *cdns);
  149. int cdns3_drd_update_mode(struct cdns3 *cdns);
  150. int cdns3_drd_switch_gadget(struct cdns3 *cdns, int on);
  151. int cdns3_drd_switch_host(struct cdns3 *cdns, int on);
  152. int cdns3_set_mode(struct cdns3 *cdns, enum usb_dr_mode mode);
  153. #endif /* __LINUX_CDNS3_DRD */