2019-03-16 08:04:47 +03:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 MediaTek Inc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _UFS_MEDIATEK_H
|
|
|
|
#define _UFS_MEDIATEK_H
|
|
|
|
|
2019-12-30 08:32:26 +03:00
|
|
|
#include <linux/bitops.h>
|
2022-06-23 06:50:51 +03:00
|
|
|
#include <linux/pm_qos.h>
|
2019-12-30 08:32:26 +03:00
|
|
|
#include <linux/soc/mediatek/mtk_sip_svc.h>
|
|
|
|
|
2019-12-30 08:32:27 +03:00
|
|
|
/*
|
|
|
|
* Vendor specific UFSHCI Registers
|
|
|
|
*/
|
2022-06-23 06:50:47 +03:00
|
|
|
#define REG_UFS_XOUFS_CTRL 0x140
|
2019-12-30 08:32:27 +03:00
|
|
|
#define REG_UFS_REFCLK_CTRL 0x144
|
2020-01-17 06:51:06 +03:00
|
|
|
#define REG_UFS_EXTREG 0x2100
|
|
|
|
#define REG_UFS_MPHYCTRL 0x2200
|
2021-09-06 11:53:07 +03:00
|
|
|
#define REG_UFS_MTK_IP_VER 0x2240
|
2020-01-17 06:51:06 +03:00
|
|
|
#define REG_UFS_REJECT_MON 0x22AC
|
|
|
|
#define REG_UFS_DEBUG_SEL 0x22C0
|
|
|
|
#define REG_UFS_PROBE 0x22C8
|
2021-09-06 11:53:07 +03:00
|
|
|
#define REG_UFS_DEBUG_SEL_B0 0x22D0
|
|
|
|
#define REG_UFS_DEBUG_SEL_B1 0x22D4
|
|
|
|
#define REG_UFS_DEBUG_SEL_B2 0x22D8
|
|
|
|
#define REG_UFS_DEBUG_SEL_B3 0x22DC
|
2019-12-30 08:32:27 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Ref-clk control
|
|
|
|
*
|
|
|
|
* Values for register REG_UFS_REFCLK_CTRL
|
|
|
|
*/
|
|
|
|
#define REFCLK_RELEASE 0x0
|
|
|
|
#define REFCLK_REQUEST BIT(0)
|
|
|
|
#define REFCLK_ACK BIT(1)
|
|
|
|
|
2020-06-01 13:46:42 +03:00
|
|
|
#define REFCLK_REQ_TIMEOUT_US 3000
|
2021-10-16 03:58:00 +03:00
|
|
|
#define REFCLK_DEFAULT_WAIT_US 32
|
2019-12-30 08:32:27 +03:00
|
|
|
|
2019-03-16 08:04:47 +03:00
|
|
|
/*
|
|
|
|
* Other attributes
|
|
|
|
*/
|
|
|
|
#define VS_DEBUGCLOCKENABLE 0xD0A1
|
|
|
|
#define VS_SAVEPOWERCONTROL 0xD0A6
|
|
|
|
#define VS_UNIPROPOWERDOWNCONTROL 0xD0A8
|
|
|
|
|
2020-01-29 13:52:51 +03:00
|
|
|
/*
|
|
|
|
* Vendor specific link state
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
VS_LINK_DISABLED = 0,
|
|
|
|
VS_LINK_DOWN = 1,
|
|
|
|
VS_LINK_UP = 2,
|
|
|
|
VS_LINK_HIBERN8 = 3,
|
|
|
|
VS_LINK_LOST = 4,
|
|
|
|
VS_LINK_CFG = 5,
|
|
|
|
};
|
|
|
|
|
2021-10-06 08:47:05 +03:00
|
|
|
/*
|
|
|
|
* Vendor specific host controller state
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
VS_HCE_RESET = 0,
|
|
|
|
VS_HCE_BASE = 1,
|
|
|
|
VS_HCE_OOCPR_WAIT = 2,
|
|
|
|
VS_HCE_DME_RESET = 3,
|
|
|
|
VS_HCE_MIDDLE = 4,
|
|
|
|
VS_HCE_DME_ENABLE = 5,
|
|
|
|
VS_HCE_DEFAULTS = 6,
|
|
|
|
VS_HIB_IDLEEN = 7,
|
|
|
|
VS_HIB_ENTER = 8,
|
|
|
|
VS_HIB_ENTER_CONF = 9,
|
|
|
|
VS_HIB_MIDDLE = 10,
|
|
|
|
VS_HIB_WAITTIMER = 11,
|
|
|
|
VS_HIB_EXIT_CONF = 12,
|
|
|
|
VS_HIB_EXIT = 13,
|
|
|
|
};
|
|
|
|
|
2019-12-30 08:32:26 +03:00
|
|
|
/*
|
|
|
|
* SiP commands
|
|
|
|
*/
|
2019-12-30 08:32:27 +03:00
|
|
|
#define MTK_SIP_UFS_CONTROL MTK_SIP_SMC_CMD(0x276)
|
2020-10-29 14:57:46 +03:00
|
|
|
#define UFS_MTK_SIP_VA09_PWR_CTRL BIT(0)
|
2019-12-30 08:32:27 +03:00
|
|
|
#define UFS_MTK_SIP_DEVICE_RESET BIT(1)
|
2020-07-12 03:32:26 +03:00
|
|
|
#define UFS_MTK_SIP_CRYPTO_CTRL BIT(2)
|
2019-12-30 08:32:27 +03:00
|
|
|
#define UFS_MTK_SIP_REF_CLK_NOTIFICATION BIT(3)
|
2022-06-23 06:50:50 +03:00
|
|
|
#define UFS_MTK_SIP_HOST_PWR_CTRL BIT(5)
|
2022-06-16 08:37:24 +03:00
|
|
|
#define UFS_MTK_SIP_GET_VCC_NUM BIT(6)
|
2022-06-16 08:37:22 +03:00
|
|
|
#define UFS_MTK_SIP_DEVICE_PWR_CTRL BIT(7)
|
2019-12-30 08:32:26 +03:00
|
|
|
|
2019-03-16 08:04:47 +03:00
|
|
|
/*
|
|
|
|
* VS_DEBUGCLOCKENABLE
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
TX_SYMBOL_CLK_REQ_FORCE = 5,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* VS_SAVEPOWERCONTROL
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
RX_SYMBOL_CLK_GATE_EN = 0,
|
|
|
|
SYS_CLK_GATE_EN = 2,
|
|
|
|
TX_CLK_GATE_EN = 3,
|
|
|
|
};
|
|
|
|
|
2020-09-14 08:00:51 +03:00
|
|
|
/*
|
|
|
|
* Host capability
|
|
|
|
*/
|
|
|
|
enum ufs_mtk_host_caps {
|
|
|
|
UFS_MTK_CAP_BOOST_CRYPT_ENGINE = 1 << 0,
|
2020-10-29 14:57:46 +03:00
|
|
|
UFS_MTK_CAP_VA09_PWR_CTRL = 1 << 1,
|
2020-10-29 14:57:48 +03:00
|
|
|
UFS_MTK_CAP_DISABLE_AH8 = 1 << 2,
|
2020-12-07 08:49:55 +03:00
|
|
|
UFS_MTK_CAP_BROKEN_VCC = 1 << 3,
|
2022-06-16 08:37:17 +03:00
|
|
|
UFS_MTK_CAP_PMC_VIA_FASTAUTO = 1 << 6,
|
2020-09-14 08:00:51 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ufs_mtk_crypt_cfg {
|
|
|
|
struct regulator *reg_vcore;
|
|
|
|
struct clk *clk_crypt_perf;
|
|
|
|
struct clk *clk_crypt_mux;
|
|
|
|
struct clk *clk_crypt_lp;
|
|
|
|
int vcore_volt;
|
|
|
|
};
|
|
|
|
|
2022-08-03 02:54:37 +03:00
|
|
|
struct ufs_mtk_clk {
|
|
|
|
struct ufs_clk_info *ufs_sel_clki; /* Mux */
|
|
|
|
struct ufs_clk_info *ufs_sel_max_clki; /* Max src */
|
|
|
|
struct ufs_clk_info *ufs_sel_min_clki; /* Min src */
|
|
|
|
};
|
|
|
|
|
2020-10-29 14:57:50 +03:00
|
|
|
struct ufs_mtk_hw_ver {
|
|
|
|
u8 step;
|
|
|
|
u8 minor;
|
|
|
|
u8 major;
|
|
|
|
};
|
|
|
|
|
2019-03-16 08:04:47 +03:00
|
|
|
struct ufs_mtk_host {
|
|
|
|
struct phy *mphy;
|
2022-06-23 06:50:51 +03:00
|
|
|
struct pm_qos_request pm_qos_req;
|
2020-10-29 14:57:46 +03:00
|
|
|
struct regulator *reg_va09;
|
2020-09-08 09:45:07 +03:00
|
|
|
struct reset_control *hci_reset;
|
|
|
|
struct reset_control *unipro_reset;
|
|
|
|
struct reset_control *crypto_reset;
|
2020-10-29 14:57:47 +03:00
|
|
|
struct ufs_hba *hba;
|
|
|
|
struct ufs_mtk_crypt_cfg *crypt;
|
2022-08-03 02:54:37 +03:00
|
|
|
struct ufs_mtk_clk mclk;
|
2020-10-29 14:57:50 +03:00
|
|
|
struct ufs_mtk_hw_ver hw_ver;
|
2020-10-29 14:57:47 +03:00
|
|
|
enum ufs_mtk_host_caps caps;
|
2020-06-01 13:46:45 +03:00
|
|
|
bool mphy_powered_on;
|
2022-06-23 06:50:51 +03:00
|
|
|
bool pm_qos_init;
|
2020-03-18 13:40:16 +03:00
|
|
|
bool unipro_lpm;
|
2019-12-30 08:32:27 +03:00
|
|
|
bool ref_clk_enabled;
|
2020-02-20 16:48:48 +03:00
|
|
|
u16 ref_clk_ungating_wait_us;
|
|
|
|
u16 ref_clk_gating_wait_us;
|
2021-09-06 11:53:07 +03:00
|
|
|
u32 ip_ver;
|
2019-03-16 08:04:47 +03:00
|
|
|
};
|
|
|
|
|
2022-06-16 08:37:24 +03:00
|
|
|
/*
|
|
|
|
* Multi-VCC by Numbering
|
|
|
|
*/
|
|
|
|
enum ufs_mtk_vcc_num {
|
|
|
|
UFS_VCC_NONE = 0,
|
|
|
|
UFS_VCC_1,
|
|
|
|
UFS_VCC_2,
|
|
|
|
UFS_VCC_MAX
|
|
|
|
};
|
|
|
|
|
2022-06-23 06:50:50 +03:00
|
|
|
/*
|
|
|
|
* Host Power Control options
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
HOST_PWR_HCI = 0,
|
|
|
|
HOST_PWR_MPHY
|
|
|
|
};
|
|
|
|
|
2022-06-16 08:37:21 +03:00
|
|
|
/*
|
|
|
|
* SMC call wrapper function
|
|
|
|
*/
|
|
|
|
struct ufs_mtk_smc_arg {
|
|
|
|
unsigned long cmd;
|
|
|
|
struct arm_smccc_res *res;
|
|
|
|
unsigned long v1;
|
|
|
|
unsigned long v2;
|
|
|
|
unsigned long v3;
|
|
|
|
unsigned long v4;
|
|
|
|
unsigned long v5;
|
|
|
|
unsigned long v6;
|
|
|
|
unsigned long v7;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void _ufs_mtk_smc(struct ufs_mtk_smc_arg s)
|
|
|
|
{
|
|
|
|
arm_smccc_smc(MTK_SIP_UFS_CONTROL,
|
|
|
|
s.cmd, s.v1, s.v2, s.v3, s.v4, s.v5, s.v6, s.res);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ufs_mtk_smc(...) \
|
|
|
|
_ufs_mtk_smc((struct ufs_mtk_smc_arg) {__VA_ARGS__})
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SMC call interface
|
|
|
|
*/
|
|
|
|
#define ufs_mtk_va09_pwr_ctrl(res, on) \
|
|
|
|
ufs_mtk_smc(UFS_MTK_SIP_VA09_PWR_CTRL, &(res), on)
|
|
|
|
|
|
|
|
#define ufs_mtk_crypto_ctrl(res, enable) \
|
|
|
|
ufs_mtk_smc(UFS_MTK_SIP_CRYPTO_CTRL, &(res), enable)
|
|
|
|
|
2022-06-23 06:50:48 +03:00
|
|
|
#define ufs_mtk_ref_clk_notify(on, stage, res) \
|
|
|
|
ufs_mtk_smc(UFS_MTK_SIP_REF_CLK_NOTIFICATION, &(res), on, stage)
|
2022-06-16 08:37:21 +03:00
|
|
|
|
|
|
|
#define ufs_mtk_device_reset_ctrl(high, res) \
|
|
|
|
ufs_mtk_smc(UFS_MTK_SIP_DEVICE_RESET, &(res), high)
|
|
|
|
|
2022-06-23 06:50:50 +03:00
|
|
|
#define ufs_mtk_host_pwr_ctrl(opt, on, res) \
|
|
|
|
ufs_mtk_smc(UFS_MTK_SIP_HOST_PWR_CTRL, &(res), opt, on)
|
|
|
|
|
2022-06-16 08:37:24 +03:00
|
|
|
#define ufs_mtk_get_vcc_num(res) \
|
|
|
|
ufs_mtk_smc(UFS_MTK_SIP_GET_VCC_NUM, &(res))
|
|
|
|
|
2022-06-16 08:37:22 +03:00
|
|
|
#define ufs_mtk_device_pwr_ctrl(on, ufs_ver, res) \
|
|
|
|
ufs_mtk_smc(UFS_MTK_SIP_DEVICE_PWR_CTRL, &(res), on, ufs_ver)
|
|
|
|
|
2019-03-16 08:04:47 +03:00
|
|
|
#endif /* !_UFS_MEDIATEK_H */
|