1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) 2019 MediaTek Inc.
6 #ifndef _UFS_MEDIATEK_H
7 #define _UFS_MEDIATEK_H
9 #include <linux/bitops.h>
12 * MCQ define and struct
14 #define UFSHCD_MAX_Q_NR 8
15 #define MTK_MCQ_INVALID_IRQ 0xFFFF
17 /* REG_UFS_MMIO_OPT_CTRL_0 160h */
19 #define PFM_IMPV BIT(1)
20 #define MCQ_MULTI_INTR_EN BIT(2)
21 #define MCQ_CMB_INTR_EN BIT(3)
22 #define MCQ_AH8 BIT(4)
24 #define MCQ_INTR_EN_MSK (MCQ_MULTI_INTR_EN | MCQ_CMB_INTR_EN)
27 * Vendor specific UFSHCI Registers
29 #define REG_UFS_XOUFS_CTRL 0x140
30 #define REG_UFS_REFCLK_CTRL 0x144
31 #define REG_UFS_MMIO_OPT_CTRL_0 0x160
32 #define REG_UFS_EXTREG 0x2100
33 #define REG_UFS_MPHYCTRL 0x2200
34 #define REG_UFS_MTK_IP_VER 0x2240
35 #define REG_UFS_REJECT_MON 0x22AC
36 #define REG_UFS_DEBUG_SEL 0x22C0
37 #define REG_UFS_PROBE 0x22C8
38 #define REG_UFS_DEBUG_SEL_B0 0x22D0
39 #define REG_UFS_DEBUG_SEL_B1 0x22D4
40 #define REG_UFS_DEBUG_SEL_B2 0x22D8
41 #define REG_UFS_DEBUG_SEL_B3 0x22DC
43 #define REG_UFS_MTK_SQD 0x2800
44 #define REG_UFS_MTK_SQIS 0x2814
45 #define REG_UFS_MTK_CQD 0x281C
46 #define REG_UFS_MTK_CQIS 0x2824
48 #define REG_UFS_MCQ_STRIDE 0x30
53 * Values for register REG_UFS_REFCLK_CTRL
55 #define REFCLK_RELEASE 0x0
56 #define REFCLK_REQUEST BIT(0)
57 #define REFCLK_ACK BIT(1)
59 #define REFCLK_REQ_TIMEOUT_US 3000
60 #define REFCLK_DEFAULT_WAIT_US 32
65 #define VS_DEBUGCLOCKENABLE 0xD0A1
66 #define VS_SAVEPOWERCONTROL 0xD0A6
67 #define VS_UNIPROPOWERDOWNCONTROL 0xD0A8
70 * Vendor specific link state
82 * Vendor specific host controller state
87 VS_HCE_OOCPR_WAIT
= 2,
90 VS_HCE_DME_ENABLE
= 5,
94 VS_HIB_ENTER_CONF
= 9,
96 VS_HIB_WAITTIMER
= 11,
97 VS_HIB_EXIT_CONF
= 12,
102 * VS_DEBUGCLOCKENABLE
105 TX_SYMBOL_CLK_REQ_FORCE
= 5,
109 * VS_SAVEPOWERCONTROL
112 RX_SYMBOL_CLK_GATE_EN
= 0,
120 enum ufs_mtk_host_caps
{
121 UFS_MTK_CAP_BOOST_CRYPT_ENGINE
= 1 << 0,
122 UFS_MTK_CAP_VA09_PWR_CTRL
= 1 << 1,
123 UFS_MTK_CAP_DISABLE_AH8
= 1 << 2,
124 UFS_MTK_CAP_BROKEN_VCC
= 1 << 3,
127 * Override UFS_MTK_CAP_BROKEN_VCC's behavior to
128 * allow vccqx upstream to enter LPM
130 UFS_MTK_CAP_ALLOW_VCCQX_LPM
= 1 << 5,
131 UFS_MTK_CAP_PMC_VIA_FASTAUTO
= 1 << 6,
132 UFS_MTK_CAP_TX_SKEW_FIX
= 1 << 7,
133 UFS_MTK_CAP_DISABLE_MCQ
= 1 << 8,
134 /* Control MTCMOS with RTFF */
135 UFS_MTK_CAP_RTFF_MTCMOS
= 1 << 9,
138 struct ufs_mtk_crypt_cfg
{
139 struct regulator
*reg_vcore
;
140 struct clk
*clk_crypt_perf
;
141 struct clk
*clk_crypt_mux
;
142 struct clk
*clk_crypt_lp
;
147 struct ufs_clk_info
*ufs_sel_clki
; /* Mux */
148 struct ufs_clk_info
*ufs_sel_max_clki
; /* Max src */
149 struct ufs_clk_info
*ufs_sel_min_clki
; /* Min src */
152 struct ufs_mtk_hw_ver
{
158 struct ufs_mtk_mcq_intr_info
{
164 struct ufs_mtk_host
{
166 struct regulator
*reg_va09
;
167 struct reset_control
*hci_reset
;
168 struct reset_control
*unipro_reset
;
169 struct reset_control
*crypto_reset
;
170 struct reset_control
*mphy_reset
;
172 struct ufs_mtk_crypt_cfg
*crypt
;
173 struct ufs_mtk_clk mclk
;
174 struct ufs_mtk_hw_ver hw_ver
;
175 enum ufs_mtk_host_caps caps
;
176 bool mphy_powered_on
;
178 bool ref_clk_enabled
;
179 u16 ref_clk_ungating_wait_us
;
180 u16 ref_clk_gating_wait_us
;
184 bool is_mcq_intr_enabled
;
186 struct ufs_mtk_mcq_intr_info mcq_intr_info
[UFSHCD_MAX_Q_NR
];
189 /* MTK delay of autosuspend: 500 ms */
190 #define MTK_RPM_AUTOSUSPEND_DELAY_MS 500
192 /* MTK RTT support number */
193 #define MTK_MAX_NUM_RTT 2
195 #endif /* !_UFS_MEDIATEK_H */