Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Cadence USB3 and USBSSP DRD header file.
0004  *
0005  * Copyright (C) 2018-2020 Cadence.
0006  *
0007  * Author: Pawel Laszczak <pawell@cadence.com>
0008  */
0009 #ifndef __LINUX_CDNS3_DRD
0010 #define __LINUX_CDNS3_DRD
0011 
0012 #include <linux/usb/otg.h>
0013 #include "core.h"
0014 
0015 /*  DRD register interface for version v1 of cdns3 driver. */
0016 struct cdns3_otg_regs {
0017     __le32 did;
0018     __le32 rid;
0019     __le32 capabilities;
0020     __le32 reserved1;
0021     __le32 cmd;
0022     __le32 sts;
0023     __le32 state;
0024     __le32 reserved2;
0025     __le32 ien;
0026     __le32 ivect;
0027     __le32 refclk;
0028     __le32 tmr;
0029     __le32 reserved3[4];
0030     __le32 simulate;
0031     __le32 override;
0032     __le32 susp_ctrl;
0033     __le32 phyrst_cfg;
0034     __le32 anasts;
0035     __le32 adp_ramp_time;
0036     __le32 ctrl1;
0037     __le32 ctrl2;
0038 };
0039 
0040 /*  DRD register interface for version v0 of cdns3 driver. */
0041 struct cdns3_otg_legacy_regs {
0042     __le32 cmd;
0043     __le32 sts;
0044     __le32 state;
0045     __le32 refclk;
0046     __le32 ien;
0047     __le32 ivect;
0048     __le32 reserved1[3];
0049     __le32 tmr;
0050     __le32 reserved2[2];
0051     __le32 version;
0052     __le32 capabilities;
0053     __le32 reserved3[2];
0054     __le32 simulate;
0055     __le32 reserved4[5];
0056     __le32 ctrl1;
0057 };
0058 
0059 /* DRD register interface for cdnsp driver */
0060 struct cdnsp_otg_regs {
0061     __le32 did;
0062     __le32 rid;
0063     __le32 cfgs1;
0064     __le32 cfgs2;
0065     __le32 cmd;
0066     __le32 sts;
0067     __le32 state;
0068     __le32 ien;
0069     __le32 ivect;
0070     __le32 tmr;
0071     __le32 simulate;
0072     __le32 adpbc_sts;
0073     __le32 adp_ramp_time;
0074     __le32 adpbc_ctrl1;
0075     __le32 adpbc_ctrl2;
0076     __le32 override;
0077     __le32 vbusvalid_dbnc_cfg;
0078     __le32 sessvalid_dbnc_cfg;
0079     __le32 susp_timing_ctrl;
0080 };
0081 
0082 #define OTG_CDNSP_DID   0x0004034E
0083 
0084 /*
0085  * Common registers interface for both CDNS3 and CDNSP version of DRD.
0086  */
0087 struct cdns_otg_common_regs {
0088     __le32 cmd;
0089     __le32 sts;
0090     __le32 state;
0091 };
0092 
0093 /*
0094  * Interrupt related registers. This registers are mapped in different
0095  * location for CDNSP controller.
0096  */
0097 struct cdns_otg_irq_regs {
0098     __le32 ien;
0099     __le32 ivect;
0100 };
0101 
0102 /* CDNS_RID - bitmasks */
0103 #define CDNS_RID(p)         ((p) & GENMASK(15, 0))
0104 
0105 /* CDNS_VID - bitmasks */
0106 #define CDNS_DID(p)         ((p) & GENMASK(31, 0))
0107 
0108 /* OTGCMD - bitmasks */
0109 /* "Request the bus for Device mode. */
0110 #define OTGCMD_DEV_BUS_REQ      BIT(0)
0111 /* Request the bus for Host mode */
0112 #define OTGCMD_HOST_BUS_REQ     BIT(1)
0113 /* Enable OTG mode. */
0114 #define OTGCMD_OTG_EN           BIT(2)
0115 /* Disable OTG mode */
0116 #define OTGCMD_OTG_DIS          BIT(3)
0117 /*"Configure OTG as A-Device. */
0118 #define OTGCMD_A_DEV_EN         BIT(4)
0119 /*"Configure OTG as A-Device. */
0120 #define OTGCMD_A_DEV_DIS        BIT(5)
0121 /* Drop the bus for Device mod  e. */
0122 #define OTGCMD_DEV_BUS_DROP     BIT(8)
0123 /* Drop the bus for Host mode*/
0124 #define OTGCMD_HOST_BUS_DROP        BIT(9)
0125 /* Power Down USBSS-DEV - only for CDNS3.*/
0126 #define OTGCMD_DEV_POWER_OFF        BIT(11)
0127 /* Power Down CDNSXHCI - only for CDNS3. */
0128 #define OTGCMD_HOST_POWER_OFF       BIT(12)
0129 
0130 /* OTGIEN - bitmasks */
0131 /* ID change interrupt enable */
0132 #define OTGIEN_ID_CHANGE_INT        BIT(0)
0133 /* Vbusvalid fall detected interrupt enable.*/
0134 #define OTGIEN_VBUSVALID_RISE_INT   BIT(4)
0135 /* Vbusvalid fall detected interrupt enable */
0136 #define OTGIEN_VBUSVALID_FALL_INT   BIT(5)
0137 
0138 /* OTGSTS - bitmasks */
0139 /*
0140  * Current value of the ID pin. It is only valid when idpullup in
0141  *  OTGCTRL1_TYPE register is set to '1'.
0142  */
0143 #define OTGSTS_ID_VALUE         BIT(0)
0144 /* Current value of the vbus_valid */
0145 #define OTGSTS_VBUS_VALID       BIT(1)
0146 /* Current value of the b_sess_vld */
0147 #define OTGSTS_SESSION_VALID        BIT(2)
0148 /*Device mode is active*/
0149 #define OTGSTS_DEV_ACTIVE       BIT(3)
0150 /* Host mode is active. */
0151 #define OTGSTS_HOST_ACTIVE      BIT(4)
0152 /* OTG Controller not ready. */
0153 #define OTGSTS_OTG_NRDY_MASK        BIT(11)
0154 #define OTGSTS_OTG_NRDY(p)      ((p) & OTGSTS_OTG_NRDY_MASK)
0155 /*
0156  * Value of the strap pins for:
0157  * CDNS3:
0158  * 000 - no default configuration
0159  * 010 - Controller initiall configured as Host
0160  * 100 - Controller initially configured as Device
0161  * CDNSP:
0162  * 000 - No default configuration.
0163  * 010 - Controller initiall configured as Host.
0164  * 100 - Controller initially configured as Device.
0165  */
0166 #define OTGSTS_STRAP(p)         (((p) & GENMASK(14, 12)) >> 12)
0167 #define OTGSTS_STRAP_NO_DEFAULT_CFG 0x00
0168 #define OTGSTS_STRAP_HOST_OTG       0x01
0169 #define OTGSTS_STRAP_HOST       0x02
0170 #define OTGSTS_STRAP_GADGET     0x04
0171 #define OTGSTS_CDNSP_STRAP_HOST     0x01
0172 #define OTGSTS_CDNSP_STRAP_GADGET   0x02
0173 
0174 /* Host mode is turned on. */
0175 #define OTGSTS_CDNS3_XHCI_READY     BIT(26)
0176 #define OTGSTS_CDNSP_XHCI_READY     BIT(27)
0177 
0178 /* "Device mode is turned on .*/
0179 #define OTGSTS_CDNS3_DEV_READY      BIT(27)
0180 #define OTGSTS_CDNSP_DEV_READY      BIT(26)
0181 
0182 /* OTGSTATE- bitmasks */
0183 #define OTGSTATE_DEV_STATE_MASK     GENMASK(2, 0)
0184 #define OTGSTATE_HOST_STATE_MASK    GENMASK(5, 3)
0185 #define OTGSTATE_HOST_STATE_IDLE    0x0
0186 #define OTGSTATE_HOST_STATE_VBUS_FALL   0x7
0187 #define OTGSTATE_HOST_STATE(p)      (((p) & OTGSTATE_HOST_STATE_MASK) >> 3)
0188 
0189 /* OTGREFCLK - bitmasks */
0190 #define OTGREFCLK_STB_CLK_SWITCH_EN BIT(31)
0191 
0192 /* OVERRIDE - bitmasks */
0193 #define OVERRIDE_IDPULLUP       BIT(0)
0194 /* Only for CDNS3_CONTROLLER_V0 version */
0195 #define OVERRIDE_IDPULLUP_V0        BIT(24)
0196 /* Vbusvalid/Sesvalid override select. */
0197 #define OVERRIDE_SESS_VLD_SEL       BIT(10)
0198 
0199 /* PHYRST_CFG - bitmasks */
0200 #define PHYRST_CFG_PHYRST_A_ENABLE     BIT(0)
0201 
0202 #define CDNS3_ID_PERIPHERAL     1
0203 #define CDNS3_ID_HOST           0
0204 
0205 bool cdns_is_host(struct cdns *cdns);
0206 bool cdns_is_device(struct cdns *cdns);
0207 int cdns_get_id(struct cdns *cdns);
0208 int cdns_get_vbus(struct cdns *cdns);
0209 void cdns_clear_vbus(struct cdns *cdns);
0210 void cdns_set_vbus(struct cdns *cdns);
0211 int cdns_drd_init(struct cdns *cdns);
0212 int cdns_drd_exit(struct cdns *cdns);
0213 int cdns_drd_update_mode(struct cdns *cdns);
0214 int cdns_drd_gadget_on(struct cdns *cdns);
0215 void cdns_drd_gadget_off(struct cdns *cdns);
0216 int cdns_drd_host_on(struct cdns *cdns);
0217 void cdns_drd_host_off(struct cdns *cdns);
0218 bool cdns_power_is_lost(struct cdns *cdns);
0219 #endif /* __LINUX_CDNS3_DRD */