blob: de957ae60f367fa81e2fe02346f98627dea47c48 [file] [log] [blame]
Bhupesh Sharma90b214e2024-09-10 11:50:13 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
3 */
4
5#ifndef UFS_QCOM_H_
6#define UFS_QCOM_H_
7
8#include <reset.h>
9#include <linux/bitfield.h>
10
11#define MPHY_TX_FSM_STATE 0x41
12#define TX_FSM_HIBERN8 0x1
13#define DEFAULT_CLK_RATE_HZ 1000000
14
15#define UFS_HW_VER_MAJOR_MASK GENMASK(31, 28)
16#define UFS_HW_VER_MINOR_MASK GENMASK(27, 16)
17#define UFS_HW_VER_STEP_MASK GENMASK(15, 0)
18
19/* QCOM UFS host controller vendor specific registers */
20enum {
21 REG_UFS_SYS1CLK_1US = 0xC0,
22 REG_UFS_TX_SYMBOL_CLK_NS_US = 0xC4,
23 REG_UFS_LOCAL_PORT_ID_REG = 0xC8,
24 REG_UFS_PA_ERR_CODE = 0xCC,
25 /* On older UFS revisions, this register is called "RETRY_TIMER_REG" */
26 REG_UFS_PARAM0 = 0xD0,
27 /* On older UFS revisions, this register is called "REG_UFS_PA_LINK_STARTUP_TIMER" */
28 REG_UFS_CFG0 = 0xD8,
29 REG_UFS_CFG1 = 0xDC,
30 REG_UFS_CFG2 = 0xE0,
31 REG_UFS_HW_VERSION = 0xE4,
32
33 UFS_TEST_BUS = 0xE8,
34 UFS_TEST_BUS_CTRL_0 = 0xEC,
35 UFS_TEST_BUS_CTRL_1 = 0xF0,
36 UFS_TEST_BUS_CTRL_2 = 0xF4,
37 UFS_UNIPRO_CFG = 0xF8,
38
39 /*
40 * QCOM UFS host controller vendor specific registers
41 * added in HW Version 3.0.0
42 */
43 UFS_AH8_CFG = 0xFC,
44
45 REG_UFS_CFG3 = 0x271C,
46};
47
48/* bit definitions for REG_UFS_CFG0 register */
49#define QUNIPRO_G4_SEL BIT(5)
50
51/* bit definitions for REG_UFS_CFG1 register */
52#define QUNIPRO_SEL BIT(0)
53#define UFS_PHY_SOFT_RESET BIT(1)
54#define UTP_DBG_RAMS_EN BIT(17)
55#define TEST_BUS_EN BIT(18)
56#define TEST_BUS_SEL GENMASK(22, 19)
57#define UFS_REG_TEST_BUS_EN BIT(30)
58
59#define UFS_PHY_RESET_ENABLE 1
60#define UFS_PHY_RESET_DISABLE 0
61
62/* bit definitions for REG_UFS_CFG2 register */
63#define UAWM_HW_CGC_EN BIT(0)
64#define UARM_HW_CGC_EN BIT(1)
65#define TXUC_HW_CGC_EN BIT(2)
66#define RXUC_HW_CGC_EN BIT(3)
67#define DFC_HW_CGC_EN BIT(4)
68#define TRLUT_HW_CGC_EN BIT(5)
69#define TMRLUT_HW_CGC_EN BIT(6)
70#define OCSC_HW_CGC_EN BIT(7)
71
72/* bit definitions for REG_UFS_PARAM0 */
73#define MAX_HS_GEAR_MASK GENMASK(6, 4)
74#define UFS_QCOM_MAX_GEAR(x) FIELD_GET(MAX_HS_GEAR_MASK, (x))
75
76/* bit definition for UFS_UFS_TEST_BUS_CTRL_n */
77#define TEST_BUS_SUB_SEL_MASK GENMASK(4, 0) /* All XXX_SEL fields are 5 bits wide */
78
79#define REG_UFS_CFG2_CGC_EN_ALL (UAWM_HW_CGC_EN | UARM_HW_CGC_EN |\
80 TXUC_HW_CGC_EN | RXUC_HW_CGC_EN |\
81 DFC_HW_CGC_EN | TRLUT_HW_CGC_EN |\
82 TMRLUT_HW_CGC_EN | OCSC_HW_CGC_EN)
83
84/* bit offset */
85#define OFFSET_CLK_NS_REG 0xa
86
87/* bit masks */
88#define MASK_TX_SYMBOL_CLK_1US_REG GENMASK(9, 0)
89#define MASK_CLK_NS_REG GENMASK(23, 10)
90
91/* QUniPro Vendor specific attributes */
92#define PA_VS_CONFIG_REG1 0x9000
93#define DME_VS_CORE_CLK_CTRL 0xD002
94/* bit and mask definitions for DME_VS_CORE_CLK_CTRL attribute */
95#define CLK_1US_CYCLES_MASK_V4 GENMASK(27, 16)
96#define CLK_1US_CYCLES_MASK GENMASK(7, 0)
97#define DME_VS_CORE_CLK_CTRL_CORE_CLK_DIV_EN_BIT BIT(8)
98#define PA_VS_CORE_CLK_40NS_CYCLES 0x9007
99#define PA_VS_CORE_CLK_40NS_CYCLES_MASK GENMASK(6, 0)
100
101/* QCOM UFS host controller core clk frequencies */
102#define UNIPRO_CORE_CLK_FREQ_37_5_MHZ 38
103#define UNIPRO_CORE_CLK_FREQ_75_MHZ 75
104#define UNIPRO_CORE_CLK_FREQ_100_MHZ 100
105#define UNIPRO_CORE_CLK_FREQ_150_MHZ 150
106#define UNIPRO_CORE_CLK_FREQ_300_MHZ 300
107#define UNIPRO_CORE_CLK_FREQ_201_5_MHZ 202
108#define UNIPRO_CORE_CLK_FREQ_403_MHZ 403
109
110static inline void
111ufs_qcom_get_controller_revision(struct ufs_hba *hba,
112 u8 *major, u16 *minor, u16 *step)
113{
114 u32 ver = ufshcd_readl(hba, REG_UFS_HW_VERSION);
115
116 *major = FIELD_GET(UFS_HW_VER_MAJOR_MASK, ver);
117 *minor = FIELD_GET(UFS_HW_VER_MINOR_MASK, ver);
118 *step = FIELD_GET(UFS_HW_VER_STEP_MASK, ver);
119};
120
121/* Host controller hardware version: major.minor.step */
122struct ufs_hw_version {
123 u16 step;
124 u16 minor;
125 u8 major;
126};
127
128struct gpio_desc;
129
130struct ufs_qcom_priv {
131 struct phy *generic_phy;
132 struct ufs_hba *hba;
133
134 struct clk_bulk clks;
135 bool is_clks_enabled;
136
137 struct ufs_hw_version hw_ver;
138
139 /* Reset control of HCI */
140 struct reset_ctl core_reset;
141
142 struct gpio_desc reset;
143
144 bool is_dev_ref_clk_enabled;
145};
146
147#endif /* UFS_QCOM_H_ */