2019-08-26 19:19:30 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
/*
|
2020-12-07 18:32:18 +08:00
|
|
|
* Cadence USB3 and USBSSP DRD header file.
|
2019-08-26 19:19:30 +08:00
|
|
|
*
|
2020-12-07 18:32:18 +08:00
|
|
|
* Copyright (C) 2018-2020 Cadence.
|
2019-08-26 19:19:30 +08:00
|
|
|
*
|
|
|
|
* Author: Pawel Laszczak <pawell@cadence.com>
|
|
|
|
*/
|
|
|
|
#ifndef __LINUX_CDNS3_DRD
|
|
|
|
#define __LINUX_CDNS3_DRD
|
|
|
|
|
|
|
|
#include <linux/usb/otg.h>
|
|
|
|
#include "core.h"
|
|
|
|
|
2020-12-07 18:32:18 +08:00
|
|
|
/* DRD register interface for version v1 of cdns3 driver. */
|
2019-08-26 19:19:30 +08:00
|
|
|
struct cdns3_otg_regs {
|
|
|
|
__le32 did;
|
|
|
|
__le32 rid;
|
|
|
|
__le32 capabilities;
|
|
|
|
__le32 reserved1;
|
|
|
|
__le32 cmd;
|
|
|
|
__le32 sts;
|
|
|
|
__le32 state;
|
|
|
|
__le32 reserved2;
|
|
|
|
__le32 ien;
|
|
|
|
__le32 ivect;
|
|
|
|
__le32 refclk;
|
|
|
|
__le32 tmr;
|
|
|
|
__le32 reserved3[4];
|
|
|
|
__le32 simulate;
|
|
|
|
__le32 override;
|
|
|
|
__le32 susp_ctrl;
|
2020-09-15 19:45:43 +08:00
|
|
|
__le32 phyrst_cfg;
|
2019-08-26 19:19:30 +08:00
|
|
|
__le32 anasts;
|
|
|
|
__le32 adp_ramp_time;
|
|
|
|
__le32 ctrl1;
|
|
|
|
__le32 ctrl2;
|
|
|
|
};
|
|
|
|
|
2020-12-07 18:32:18 +08:00
|
|
|
/* DRD register interface for version v0 of cdns3 driver. */
|
2019-08-26 19:19:30 +08:00
|
|
|
struct cdns3_otg_legacy_regs {
|
|
|
|
__le32 cmd;
|
|
|
|
__le32 sts;
|
|
|
|
__le32 state;
|
|
|
|
__le32 refclk;
|
|
|
|
__le32 ien;
|
|
|
|
__le32 ivect;
|
|
|
|
__le32 reserved1[3];
|
|
|
|
__le32 tmr;
|
|
|
|
__le32 reserved2[2];
|
|
|
|
__le32 version;
|
|
|
|
__le32 capabilities;
|
|
|
|
__le32 reserved3[2];
|
|
|
|
__le32 simulate;
|
|
|
|
__le32 reserved4[5];
|
|
|
|
__le32 ctrl1;
|
|
|
|
};
|
|
|
|
|
2020-12-07 18:32:18 +08:00
|
|
|
/* DRD register interface for cdnsp driver */
|
|
|
|
struct cdnsp_otg_regs {
|
|
|
|
__le32 did;
|
|
|
|
__le32 rid;
|
|
|
|
__le32 cfgs1;
|
|
|
|
__le32 cfgs2;
|
|
|
|
__le32 cmd;
|
|
|
|
__le32 sts;
|
|
|
|
__le32 state;
|
|
|
|
__le32 ien;
|
|
|
|
__le32 ivect;
|
|
|
|
__le32 tmr;
|
|
|
|
__le32 simulate;
|
|
|
|
__le32 adpbc_sts;
|
|
|
|
__le32 adp_ramp_time;
|
|
|
|
__le32 adpbc_ctrl1;
|
|
|
|
__le32 adpbc_ctrl2;
|
|
|
|
__le32 override;
|
|
|
|
__le32 vbusvalid_dbnc_cfg;
|
|
|
|
__le32 sessvalid_dbnc_cfg;
|
|
|
|
__le32 susp_timing_ctrl;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define OTG_CDNSP_DID 0x0004034E
|
|
|
|
|
2019-08-26 19:19:30 +08:00
|
|
|
/*
|
2020-12-07 18:32:18 +08:00
|
|
|
* Common registers interface for both CDNS3 and CDNSP version of DRD.
|
2019-08-26 19:19:30 +08:00
|
|
|
*/
|
2020-12-07 18:32:21 +08:00
|
|
|
struct cdns_otg_common_regs {
|
2019-08-26 19:19:30 +08:00
|
|
|
__le32 cmd;
|
|
|
|
__le32 sts;
|
|
|
|
__le32 state;
|
2020-12-07 18:32:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Interrupt related registers. This registers are mapped in different
|
|
|
|
* location for CDNSP controller.
|
|
|
|
*/
|
2020-12-07 18:32:21 +08:00
|
|
|
struct cdns_otg_irq_regs {
|
2019-08-26 19:19:30 +08:00
|
|
|
__le32 ien;
|
|
|
|
__le32 ivect;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* CDNS_RID - bitmasks */
|
|
|
|
#define CDNS_RID(p) ((p) & GENMASK(15, 0))
|
|
|
|
|
|
|
|
/* CDNS_VID - bitmasks */
|
|
|
|
#define CDNS_DID(p) ((p) & GENMASK(31, 0))
|
|
|
|
|
|
|
|
/* OTGCMD - bitmasks */
|
|
|
|
/* "Request the bus for Device mode. */
|
|
|
|
#define OTGCMD_DEV_BUS_REQ BIT(0)
|
|
|
|
/* Request the bus for Host mode */
|
|
|
|
#define OTGCMD_HOST_BUS_REQ BIT(1)
|
|
|
|
/* Enable OTG mode. */
|
|
|
|
#define OTGCMD_OTG_EN BIT(2)
|
|
|
|
/* Disable OTG mode */
|
|
|
|
#define OTGCMD_OTG_DIS BIT(3)
|
|
|
|
/*"Configure OTG as A-Device. */
|
|
|
|
#define OTGCMD_A_DEV_EN BIT(4)
|
|
|
|
/*"Configure OTG as A-Device. */
|
|
|
|
#define OTGCMD_A_DEV_DIS BIT(5)
|
|
|
|
/* Drop the bus for Device mod e. */
|
|
|
|
#define OTGCMD_DEV_BUS_DROP BIT(8)
|
|
|
|
/* Drop the bus for Host mode*/
|
|
|
|
#define OTGCMD_HOST_BUS_DROP BIT(9)
|
2020-12-07 18:32:18 +08:00
|
|
|
/* Power Down USBSS-DEV - only for CDNS3.*/
|
2019-08-26 19:19:30 +08:00
|
|
|
#define OTGCMD_DEV_POWER_OFF BIT(11)
|
2020-12-07 18:32:18 +08:00
|
|
|
/* Power Down CDNSXHCI - only for CDNS3. */
|
2019-08-26 19:19:30 +08:00
|
|
|
#define OTGCMD_HOST_POWER_OFF BIT(12)
|
|
|
|
|
|
|
|
/* OTGIEN - bitmasks */
|
|
|
|
/* ID change interrupt enable */
|
|
|
|
#define OTGIEN_ID_CHANGE_INT BIT(0)
|
|
|
|
/* Vbusvalid fall detected interrupt enable.*/
|
|
|
|
#define OTGIEN_VBUSVALID_RISE_INT BIT(4)
|
|
|
|
/* Vbusvalid fall detected interrupt enable */
|
|
|
|
#define OTGIEN_VBUSVALID_FALL_INT BIT(5)
|
|
|
|
|
|
|
|
/* OTGSTS - bitmasks */
|
|
|
|
/*
|
|
|
|
* Current value of the ID pin. It is only valid when idpullup in
|
|
|
|
* OTGCTRL1_TYPE register is set to '1'.
|
|
|
|
*/
|
|
|
|
#define OTGSTS_ID_VALUE BIT(0)
|
|
|
|
/* Current value of the vbus_valid */
|
|
|
|
#define OTGSTS_VBUS_VALID BIT(1)
|
|
|
|
/* Current value of the b_sess_vld */
|
|
|
|
#define OTGSTS_SESSION_VALID BIT(2)
|
|
|
|
/*Device mode is active*/
|
|
|
|
#define OTGSTS_DEV_ACTIVE BIT(3)
|
|
|
|
/* Host mode is active. */
|
|
|
|
#define OTGSTS_HOST_ACTIVE BIT(4)
|
|
|
|
/* OTG Controller not ready. */
|
|
|
|
#define OTGSTS_OTG_NRDY_MASK BIT(11)
|
|
|
|
#define OTGSTS_OTG_NRDY(p) ((p) & OTGSTS_OTG_NRDY_MASK)
|
|
|
|
/*
|
2020-12-07 18:32:18 +08:00
|
|
|
* Value of the strap pins for:
|
|
|
|
* CDNS3:
|
2019-08-26 19:19:30 +08:00
|
|
|
* 000 - no default configuration
|
|
|
|
* 010 - Controller initiall configured as Host
|
|
|
|
* 100 - Controller initially configured as Device
|
2020-12-07 18:32:18 +08:00
|
|
|
* CDNSP:
|
|
|
|
* 000 - No default configuration.
|
|
|
|
* 010 - Controller initiall configured as Host.
|
|
|
|
* 100 - Controller initially configured as Device.
|
2019-08-26 19:19:30 +08:00
|
|
|
*/
|
|
|
|
#define OTGSTS_STRAP(p) (((p) & GENMASK(14, 12)) >> 12)
|
|
|
|
#define OTGSTS_STRAP_NO_DEFAULT_CFG 0x00
|
|
|
|
#define OTGSTS_STRAP_HOST_OTG 0x01
|
|
|
|
#define OTGSTS_STRAP_HOST 0x02
|
|
|
|
#define OTGSTS_STRAP_GADGET 0x04
|
2020-12-07 18:32:18 +08:00
|
|
|
#define OTGSTS_CDNSP_STRAP_HOST 0x01
|
|
|
|
#define OTGSTS_CDNSP_STRAP_GADGET 0x02
|
|
|
|
|
2019-08-26 19:19:30 +08:00
|
|
|
/* Host mode is turned on. */
|
2020-12-07 18:32:18 +08:00
|
|
|
#define OTGSTS_CDNS3_XHCI_READY BIT(26)
|
|
|
|
#define OTGSTS_CDNSP_XHCI_READY BIT(27)
|
|
|
|
|
2019-08-26 19:19:30 +08:00
|
|
|
/* "Device mode is turned on .*/
|
2020-12-07 18:32:18 +08:00
|
|
|
#define OTGSTS_CDNS3_DEV_READY BIT(27)
|
|
|
|
#define OTGSTS_CDNSP_DEV_READY BIT(26)
|
2019-08-26 19:19:30 +08:00
|
|
|
|
|
|
|
/* OTGSTATE- bitmasks */
|
|
|
|
#define OTGSTATE_DEV_STATE_MASK GENMASK(2, 0)
|
|
|
|
#define OTGSTATE_HOST_STATE_MASK GENMASK(5, 3)
|
|
|
|
#define OTGSTATE_HOST_STATE_IDLE 0x0
|
|
|
|
#define OTGSTATE_HOST_STATE_VBUS_FALL 0x7
|
|
|
|
#define OTGSTATE_HOST_STATE(p) (((p) & OTGSTATE_HOST_STATE_MASK) >> 3)
|
|
|
|
|
|
|
|
/* OTGREFCLK - bitmasks */
|
|
|
|
#define OTGREFCLK_STB_CLK_SWITCH_EN BIT(31)
|
|
|
|
|
|
|
|
/* OVERRIDE - bitmasks */
|
|
|
|
#define OVERRIDE_IDPULLUP BIT(0)
|
|
|
|
/* Only for CDNS3_CONTROLLER_V0 version */
|
|
|
|
#define OVERRIDE_IDPULLUP_V0 BIT(24)
|
2020-12-07 18:32:18 +08:00
|
|
|
/* Vbusvalid/Sesvalid override select. */
|
|
|
|
#define OVERRIDE_SESS_VLD_SEL BIT(10)
|
2019-08-26 19:19:30 +08:00
|
|
|
|
2020-09-15 19:45:43 +08:00
|
|
|
/* PHYRST_CFG - bitmasks */
|
|
|
|
#define PHYRST_CFG_PHYRST_A_ENABLE BIT(0)
|
|
|
|
|
2020-07-13 18:05:51 +08:00
|
|
|
#define CDNS3_ID_PERIPHERAL 1
|
|
|
|
#define CDNS3_ID_HOST 0
|
|
|
|
|
2020-12-07 18:32:21 +08:00
|
|
|
bool cdns_is_host(struct cdns *cdns);
|
|
|
|
bool cdns_is_device(struct cdns *cdns);
|
|
|
|
int cdns_get_id(struct cdns *cdns);
|
|
|
|
int cdns_get_vbus(struct cdns *cdns);
|
2020-12-07 18:32:24 +08:00
|
|
|
void cdns_clear_vbus(struct cdns *cdns);
|
|
|
|
void cdns_set_vbus(struct cdns *cdns);
|
2020-12-07 18:32:21 +08:00
|
|
|
int cdns_drd_init(struct cdns *cdns);
|
|
|
|
int cdns_drd_exit(struct cdns *cdns);
|
|
|
|
int cdns_drd_update_mode(struct cdns *cdns);
|
|
|
|
int cdns_drd_gadget_on(struct cdns *cdns);
|
|
|
|
void cdns_drd_gadget_off(struct cdns *cdns);
|
|
|
|
int cdns_drd_host_on(struct cdns *cdns);
|
|
|
|
void cdns_drd_host_off(struct cdns *cdns);
|
2021-02-19 06:51:08 +08:00
|
|
|
bool cdns_power_is_lost(struct cdns *cdns);
|
2019-08-26 19:19:30 +08:00
|
|
|
#endif /* __LINUX_CDNS3_DRD */
|