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