1 // SPDX-License-Identifier: GPL-2.0-only
3 * UFS Host Controller driver for Exynos specific extensions
5 * Copyright (C) 2014-2015 Samsung Electronics Co., Ltd.
6 * Author: Seungwon Jeon <essuuj@gmail.com>
7 * Author: Alim Akhtar <alim.akhtar@samsung.com>
11 #include <linux/unaligned.h>
12 #include <crypto/aes.h>
13 #include <linux/arm-smccc.h>
14 #include <linux/clk.h>
15 #include <linux/delay.h>
16 #include <linux/module.h>
18 #include <linux/of_address.h>
19 #include <linux/mfd/syscon.h>
20 #include <linux/phy/phy.h>
21 #include <linux/platform_device.h>
22 #include <linux/regmap.h>
24 #include <ufs/ufshcd.h>
25 #include "ufshcd-pltfrm.h"
26 #include <ufs/ufshci.h>
27 #include <ufs/unipro.h>
29 #include "ufs-exynos.h"
31 #define DATA_UNIT_SIZE 4096
34 * Exynos's Vendor specific registers for UFSHCI
36 #define HCI_TXPRDT_ENTRY_SIZE 0x00
37 #define PRDT_PREFECT_EN BIT(31)
38 #define HCI_RXPRDT_ENTRY_SIZE 0x04
39 #define HCI_1US_TO_CNT_VAL 0x0C
40 #define CNT_VAL_1US_MASK 0x3FF
41 #define HCI_UTRL_NEXUS_TYPE 0x40
42 #define HCI_UTMRL_NEXUS_TYPE 0x44
43 #define HCI_SW_RST 0x50
44 #define UFS_LINK_SW_RST BIT(0)
45 #define UFS_UNIPRO_SW_RST BIT(1)
46 #define UFS_SW_RST_MASK (UFS_UNIPRO_SW_RST | UFS_LINK_SW_RST)
47 #define HCI_DATA_REORDER 0x60
48 #define HCI_UNIPRO_APB_CLK_CTRL 0x68
49 #define UNIPRO_APB_CLK(v, x) (((v) & ~0xF) | ((x) & 0xF))
50 #define HCI_AXIDMA_RWDATA_BURST_LEN 0x6C
51 #define WLU_EN BIT(31)
52 #define WLU_BURST_LEN(x) ((x) << 27 | ((x) & 0xF))
53 #define HCI_GPIO_OUT 0x70
54 #define HCI_ERR_EN_PA_LAYER 0x78
55 #define HCI_ERR_EN_DL_LAYER 0x7C
56 #define HCI_ERR_EN_N_LAYER 0x80
57 #define HCI_ERR_EN_T_LAYER 0x84
58 #define HCI_ERR_EN_DME_LAYER 0x88
59 #define HCI_V2P1_CTRL 0x8C
60 #define IA_TICK_SEL BIT(16)
61 #define HCI_CLKSTOP_CTRL 0xB0
62 #define REFCLKOUT_STOP BIT(4)
63 #define MPHY_APBCLK_STOP BIT(3)
64 #define REFCLK_STOP BIT(2)
65 #define UNIPRO_MCLK_STOP BIT(1)
66 #define UNIPRO_PCLK_STOP BIT(0)
67 #define CLK_STOP_MASK (REFCLKOUT_STOP | REFCLK_STOP |\
68 UNIPRO_MCLK_STOP | MPHY_APBCLK_STOP|\
70 /* HCI_MISC is also known as HCI_FORCE_HCS */
72 #define REFCLK_CTRL_EN BIT(7)
73 #define UNIPRO_PCLK_CTRL_EN BIT(6)
74 #define UNIPRO_MCLK_CTRL_EN BIT(5)
75 #define HCI_CORECLK_CTRL_EN BIT(4)
76 #define CLK_CTRL_EN_MASK (REFCLK_CTRL_EN |\
77 UNIPRO_PCLK_CTRL_EN |\
80 #define HCI_IOP_ACG_DISABLE 0x100
81 #define HCI_IOP_ACG_DISABLE_EN BIT(0)
83 /* Device fatal error */
84 #define DFES_ERR_EN BIT(31)
85 #define DFES_DEF_L2_ERRS (UIC_DATA_LINK_LAYER_ERROR_RX_BUF_OF |\
86 UIC_DATA_LINK_LAYER_ERROR_PA_INIT)
87 #define DFES_DEF_L3_ERRS (UIC_NETWORK_UNSUPPORTED_HEADER_TYPE |\
88 UIC_NETWORK_BAD_DEVICEID_ENC |\
89 UIC_NETWORK_LHDR_TRAP_PACKET_DROPPING)
90 #define DFES_DEF_L4_ERRS (UIC_TRANSPORT_UNSUPPORTED_HEADER_TYPE |\
91 UIC_TRANSPORT_UNKNOWN_CPORTID |\
92 UIC_TRANSPORT_NO_CONNECTION_RX |\
95 /* FSYS UFS Shareability */
96 #define UFS_WR_SHARABLE BIT(2)
97 #define UFS_RD_SHARABLE BIT(1)
98 #define UFS_SHARABLE (UFS_WR_SHARABLE | UFS_RD_SHARABLE)
99 #define UFS_SHAREABILITY_OFFSET 0x710
101 /* Multi-host registers */
103 #define MHCTRL_EN_VH_MASK (0xE)
104 #define MHCTRL_EN_VH(vh) (vh << 1)
105 #define PH2VH_MBOX 0xD8
107 #define MH_MSG_MASK (0xFF)
109 #define MH_MSG(id, msg) ((id << 8) | (msg & 0xFF))
110 #define MH_MSG_PH_READY 0x1
111 #define MH_MSG_VH_READY 0x2
113 #define ALLOW_INQUIRY BIT(25)
114 #define ALLOW_MODE_SELECT BIT(24)
115 #define ALLOW_MODE_SENSE BIT(23)
116 #define ALLOW_PRE_FETCH GENMASK(22, 21)
117 #define ALLOW_READ_CMD_ALL GENMASK(20, 18) /* read_6/10/16 */
118 #define ALLOW_READ_BUFFER BIT(17)
119 #define ALLOW_READ_CAPACITY GENMASK(16, 15)
120 #define ALLOW_REPORT_LUNS BIT(14)
121 #define ALLOW_REQUEST_SENSE BIT(13)
122 #define ALLOW_SYNCHRONIZE_CACHE GENMASK(8, 7)
123 #define ALLOW_TEST_UNIT_READY BIT(6)
124 #define ALLOW_UNMAP BIT(5)
125 #define ALLOW_VERIFY BIT(4)
126 #define ALLOW_WRITE_CMD_ALL GENMASK(3, 1) /* write_6/10/16 */
128 #define ALLOW_TRANS_VH_DEFAULT (ALLOW_INQUIRY | ALLOW_MODE_SELECT | \
129 ALLOW_MODE_SENSE | ALLOW_PRE_FETCH | \
130 ALLOW_READ_CMD_ALL | ALLOW_READ_BUFFER | \
131 ALLOW_READ_CAPACITY | ALLOW_REPORT_LUNS | \
132 ALLOW_REQUEST_SENSE | ALLOW_SYNCHRONIZE_CACHE | \
133 ALLOW_TEST_UNIT_READY | ALLOW_UNMAP | \
134 ALLOW_VERIFY | ALLOW_WRITE_CMD_ALL)
136 #define HCI_MH_ALLOWABLE_TRAN_OF_VH 0x30C
137 #define HCI_MH_IID_IN_TASK_TAG 0X308
139 #define PH_READY_TIMEOUT_MS (5 * MSEC_PER_SEC)
142 UNIPRO_L1_5
= 0,/* PHY Adapter */
143 UNIPRO_L2
, /* Data Link */
144 UNIPRO_L3
, /* Network */
145 UNIPRO_L4
, /* Transport */
146 UNIPRO_DME
, /* DME */
152 #define UNIPRO_DME_POWERMODE_REQ_LOCALL2TIMER0 0x7888
153 #define UNIPRO_DME_POWERMODE_REQ_LOCALL2TIMER1 0x788c
154 #define UNIPRO_DME_POWERMODE_REQ_LOCALL2TIMER2 0x7890
155 #define UNIPRO_DME_POWERMODE_REQ_REMOTEL2TIMER0 0x78B8
156 #define UNIPRO_DME_POWERMODE_REQ_REMOTEL2TIMER1 0x78BC
157 #define UNIPRO_DME_POWERMODE_REQ_REMOTEL2TIMER2 0x78C0
160 * UFS Protector registers
162 #define UFSPRSECURITY 0x010
163 #define NSSMU BIT(14)
164 #define UFSPSBEGIN0 0x200
165 #define UFSPSEND0 0x204
166 #define UFSPSLUN0 0x208
167 #define UFSPSCTRL0 0x20C
169 #define CNTR_DIV_VAL 40
171 static void exynos_ufs_auto_ctrl_hcc(struct exynos_ufs
*ufs
, bool en
);
172 static void exynos_ufs_ctrl_clkstop(struct exynos_ufs
*ufs
, bool en
);
174 static inline void exynos_ufs_enable_auto_ctrl_hcc(struct exynos_ufs
*ufs
)
176 exynos_ufs_auto_ctrl_hcc(ufs
, true);
179 static inline void exynos_ufs_disable_auto_ctrl_hcc(struct exynos_ufs
*ufs
)
181 exynos_ufs_auto_ctrl_hcc(ufs
, false);
184 static inline void exynos_ufs_disable_auto_ctrl_hcc_save(
185 struct exynos_ufs
*ufs
, u32
*val
)
187 *val
= hci_readl(ufs
, HCI_MISC
);
188 exynos_ufs_auto_ctrl_hcc(ufs
, false);
191 static inline void exynos_ufs_auto_ctrl_hcc_restore(
192 struct exynos_ufs
*ufs
, u32
*val
)
194 hci_writel(ufs
, *val
, HCI_MISC
);
197 static inline void exynos_ufs_gate_clks(struct exynos_ufs
*ufs
)
199 exynos_ufs_ctrl_clkstop(ufs
, true);
202 static inline void exynos_ufs_ungate_clks(struct exynos_ufs
*ufs
)
204 exynos_ufs_ctrl_clkstop(ufs
, false);
207 static int exynos_ufs_shareability(struct exynos_ufs
*ufs
)
209 /* IO Coherency setting */
211 return regmap_update_bits(ufs
->sysreg
,
212 ufs
->shareability_reg_offset
,
213 UFS_SHARABLE
, UFS_SHARABLE
);
219 static int gs101_ufs_drv_init(struct exynos_ufs
*ufs
)
221 struct ufs_hba
*hba
= ufs
->hba
;
224 /* Enable WriteBooster */
225 hba
->caps
|= UFSHCD_CAP_WB_EN
;
227 /* Enable clock gating and hibern8 */
228 hba
->caps
|= UFSHCD_CAP_CLK_GATING
| UFSHCD_CAP_HIBERN8_WITH_CLK_GATING
;
230 /* set ACG to be controlled by UFS_ACG_DISABLE */
231 reg
= hci_readl(ufs
, HCI_IOP_ACG_DISABLE
);
232 hci_writel(ufs
, reg
& (~HCI_IOP_ACG_DISABLE_EN
), HCI_IOP_ACG_DISABLE
);
234 return exynos_ufs_shareability(ufs
);
237 static int exynosauto_ufs_drv_init(struct exynos_ufs
*ufs
)
239 return exynos_ufs_shareability(ufs
);
242 static int exynosauto_ufs_post_hce_enable(struct exynos_ufs
*ufs
)
244 struct ufs_hba
*hba
= ufs
->hba
;
246 /* Enable Virtual Host #1 */
247 ufshcd_rmwl(hba
, MHCTRL_EN_VH_MASK
, MHCTRL_EN_VH(1), MHCTRL
);
248 /* Default VH Transfer permissions */
249 hci_writel(ufs
, ALLOW_TRANS_VH_DEFAULT
, HCI_MH_ALLOWABLE_TRAN_OF_VH
);
250 /* IID information is replaced in TASKTAG[7:5] instead of IID in UCD */
251 hci_writel(ufs
, 0x1, HCI_MH_IID_IN_TASK_TAG
);
256 static int exynosauto_ufs_pre_link(struct exynos_ufs
*ufs
)
258 struct ufs_hba
*hba
= ufs
->hba
;
260 u32 tx_line_reset_period
, rx_line_reset_period
;
262 rx_line_reset_period
= (RX_LINE_RESET_TIME
* ufs
->mclk_rate
) / NSEC_PER_MSEC
;
263 tx_line_reset_period
= (TX_LINE_RESET_TIME
* ufs
->mclk_rate
) / NSEC_PER_MSEC
;
265 ufshcd_dme_set(hba
, UIC_ARG_MIB(0x200), 0x40);
266 for_each_ufs_rx_lane(ufs
, i
) {
267 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_RX_CLK_PRD
, i
),
268 DIV_ROUND_UP(NSEC_PER_SEC
, ufs
->mclk_rate
));
269 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_RX_CLK_PRD_EN
, i
), 0x0);
271 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_RX_LINERESET_VALUE2
, i
),
272 (rx_line_reset_period
>> 16) & 0xFF);
273 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_RX_LINERESET_VALUE1
, i
),
274 (rx_line_reset_period
>> 8) & 0xFF);
275 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_RX_LINERESET_VALUE0
, i
),
276 (rx_line_reset_period
) & 0xFF);
278 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x2f, i
), 0x79);
279 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x84, i
), 0x1);
280 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x25, i
), 0xf6);
283 for_each_ufs_tx_lane(ufs
, i
) {
284 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_TX_CLK_PRD
, i
),
285 DIV_ROUND_UP(NSEC_PER_SEC
, ufs
->mclk_rate
));
286 /* Not to affect VND_TX_LINERESET_PVALUE to VND_TX_CLK_PRD */
287 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_TX_CLK_PRD_EN
, i
),
290 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_TX_LINERESET_PVALUE2
, i
),
291 (tx_line_reset_period
>> 16) & 0xFF);
292 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_TX_LINERESET_PVALUE1
, i
),
293 (tx_line_reset_period
>> 8) & 0xFF);
294 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_TX_LINERESET_PVALUE0
, i
),
295 (tx_line_reset_period
) & 0xFF);
297 /* TX PWM Gear Capability / PWM_G1_ONLY */
298 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x04, i
), 0x1);
301 ufshcd_dme_set(hba
, UIC_ARG_MIB(0x200), 0x0);
303 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_LOCAL_TX_LCC_ENABLE
), 0x0);
305 ufshcd_dme_set(hba
, UIC_ARG_MIB(0xa011), 0x8000);
310 static int exynosauto_ufs_pre_pwr_change(struct exynos_ufs
*ufs
,
311 struct ufs_pa_layer_attr
*pwr
)
313 struct ufs_hba
*hba
= ufs
->hba
;
315 /* PACP_PWR_req and delivered to the remote DME */
316 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_PWRMODEUSERDATA0
), 12000);
317 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_PWRMODEUSERDATA1
), 32000);
318 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_PWRMODEUSERDATA2
), 16000);
323 static int exynosauto_ufs_post_pwr_change(struct exynos_ufs
*ufs
,
324 struct ufs_pa_layer_attr
*pwr
)
326 struct ufs_hba
*hba
= ufs
->hba
;
329 enabled_vh
= ufshcd_readl(hba
, MHCTRL
) & MHCTRL_EN_VH_MASK
;
331 /* Send physical host ready message to virtual hosts */
332 ufshcd_writel(hba
, MH_MSG(enabled_vh
, MH_MSG_PH_READY
), PH2VH_MBOX
);
337 static int exynos7_ufs_pre_link(struct exynos_ufs
*ufs
)
339 struct exynos_ufs_uic_attr
*attr
= ufs
->drv_data
->uic_attr
;
340 u32 val
= attr
->pa_dbg_opt_suite1_val
;
341 struct ufs_hba
*hba
= ufs
->hba
;
344 exynos_ufs_enable_ov_tm(hba
);
345 for_each_ufs_tx_lane(ufs
, i
)
346 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x297, i
), 0x17);
347 for_each_ufs_rx_lane(ufs
, i
) {
348 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x362, i
), 0xff);
349 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x363, i
), 0x00);
351 exynos_ufs_disable_ov_tm(hba
);
353 for_each_ufs_tx_lane(ufs
, i
)
355 UIC_ARG_MIB_SEL(TX_HIBERN8_CONTROL
, i
), 0x0);
356 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_DBG_TXPHY_CFGUPDT
), 0x1);
358 ufshcd_dme_set(hba
, UIC_ARG_MIB(attr
->pa_dbg_opt_suite1_off
),
360 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_DBG_SKIP_RESET_PHY
), 0x1);
361 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_DBG_SKIP_LINE_RESET
), 0x1);
362 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_DBG_LINE_RESET_REQ
), 0x1);
364 ufshcd_dme_set(hba
, UIC_ARG_MIB(attr
->pa_dbg_opt_suite1_off
), val
);
369 static int exynos7_ufs_post_link(struct exynos_ufs
*ufs
)
371 struct ufs_hba
*hba
= ufs
->hba
;
374 exynos_ufs_enable_ov_tm(hba
);
375 for_each_ufs_tx_lane(ufs
, i
) {
376 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x28b, i
), 0x83);
377 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x29a, i
), 0x07);
378 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x277, i
),
379 TX_LINERESET_N(exynos_ufs_calc_time_cntr(ufs
, 200000)));
381 exynos_ufs_disable_ov_tm(hba
);
383 exynos_ufs_enable_dbg_mode(hba
);
384 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_SAVECONFIGTIME
), 0xbb8);
385 exynos_ufs_disable_dbg_mode(hba
);
390 static int exynos7_ufs_pre_pwr_change(struct exynos_ufs
*ufs
,
391 struct ufs_pa_layer_attr
*pwr
)
393 unipro_writel(ufs
, 0x22, UNIPRO_DBG_FORCE_DME_CTRL_STATE
);
398 static int exynos7_ufs_post_pwr_change(struct exynos_ufs
*ufs
,
399 struct ufs_pa_layer_attr
*pwr
)
401 struct ufs_hba
*hba
= ufs
->hba
;
402 int lanes
= max_t(u32
, pwr
->lane_rx
, pwr
->lane_tx
);
404 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_DBG_RXPHY_CFGUPDT
), 0x1);
407 exynos_ufs_enable_dbg_mode(hba
);
408 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_CONNECTEDTXDATALANES
), 0x1);
409 exynos_ufs_disable_dbg_mode(hba
);
416 * exynos_ufs_auto_ctrl_hcc - HCI core clock control by h/w
417 * Control should be disabled in the below cases
418 * - Before host controller S/W reset
419 * - Access to UFS protector's register
421 static void exynos_ufs_auto_ctrl_hcc(struct exynos_ufs
*ufs
, bool en
)
423 u32 misc
= hci_readl(ufs
, HCI_MISC
);
426 hci_writel(ufs
, misc
| HCI_CORECLK_CTRL_EN
, HCI_MISC
);
428 hci_writel(ufs
, misc
& ~HCI_CORECLK_CTRL_EN
, HCI_MISC
);
431 static void exynos_ufs_ctrl_clkstop(struct exynos_ufs
*ufs
, bool en
)
433 u32 ctrl
= hci_readl(ufs
, HCI_CLKSTOP_CTRL
);
434 u32 misc
= hci_readl(ufs
, HCI_MISC
);
437 hci_writel(ufs
, misc
| CLK_CTRL_EN_MASK
, HCI_MISC
);
438 hci_writel(ufs
, ctrl
| CLK_STOP_MASK
, HCI_CLKSTOP_CTRL
);
440 hci_writel(ufs
, ctrl
& ~CLK_STOP_MASK
, HCI_CLKSTOP_CTRL
);
441 hci_writel(ufs
, misc
& ~CLK_CTRL_EN_MASK
, HCI_MISC
);
445 static int exynos_ufs_get_clk_info(struct exynos_ufs
*ufs
)
447 struct ufs_hba
*hba
= ufs
->hba
;
448 struct list_head
*head
= &hba
->clk_list_head
;
449 struct ufs_clk_info
*clki
;
450 unsigned long pclk_rate
;
455 if (list_empty(head
))
458 list_for_each_entry(clki
, head
, list
) {
459 if (!IS_ERR(clki
->clk
)) {
460 if (!strcmp(clki
->name
, "core_clk"))
461 ufs
->clk_hci_core
= clki
->clk
;
462 else if (!strcmp(clki
->name
, "sclk_unipro_main"))
463 ufs
->clk_unipro_main
= clki
->clk
;
467 if (!ufs
->clk_hci_core
|| !ufs
->clk_unipro_main
) {
468 dev_err(hba
->dev
, "failed to get clk info\n");
473 ufs
->mclk_rate
= clk_get_rate(ufs
->clk_unipro_main
);
474 pclk_rate
= clk_get_rate(ufs
->clk_hci_core
);
475 f_min
= ufs
->pclk_avail_min
;
476 f_max
= ufs
->pclk_avail_max
;
478 if (ufs
->opts
& EXYNOS_UFS_OPT_HAS_APB_CLK_CTRL
) {
480 pclk_rate
/= (div
+ 1);
482 if (pclk_rate
<= f_max
)
485 } while (pclk_rate
>= f_min
);
488 if (unlikely(pclk_rate
< f_min
|| pclk_rate
> f_max
)) {
489 dev_err(hba
->dev
, "not available pclk range %lu\n", pclk_rate
);
494 ufs
->pclk_rate
= pclk_rate
;
501 static void exynos_ufs_set_unipro_pclk_div(struct exynos_ufs
*ufs
)
503 if (ufs
->opts
& EXYNOS_UFS_OPT_HAS_APB_CLK_CTRL
) {
506 val
= hci_readl(ufs
, HCI_UNIPRO_APB_CLK_CTRL
);
507 hci_writel(ufs
, UNIPRO_APB_CLK(val
, ufs
->pclk_div
),
508 HCI_UNIPRO_APB_CLK_CTRL
);
512 static void exynos_ufs_set_pwm_clk_div(struct exynos_ufs
*ufs
)
514 struct ufs_hba
*hba
= ufs
->hba
;
515 struct exynos_ufs_uic_attr
*attr
= ufs
->drv_data
->uic_attr
;
518 UIC_ARG_MIB(CMN_PWM_CLK_CTRL
), attr
->cmn_pwm_clk_ctrl
);
521 static void exynos_ufs_calc_pwm_clk_div(struct exynos_ufs
*ufs
)
523 struct ufs_hba
*hba
= ufs
->hba
;
524 struct exynos_ufs_uic_attr
*attr
= ufs
->drv_data
->uic_attr
;
525 const unsigned int div
= 30, mult
= 20;
526 const unsigned long pwm_min
= 3 * 1000 * 1000;
527 const unsigned long pwm_max
= 9 * 1000 * 1000;
528 const int divs
[] = {32, 16, 8, 4};
529 unsigned long clk
= 0, _clk
, clk_period
;
530 int i
= 0, clk_idx
= -1;
532 clk_period
= UNIPRO_PCLK_PERIOD(ufs
);
533 for (i
= 0; i
< ARRAY_SIZE(divs
); i
++) {
534 _clk
= NSEC_PER_SEC
* mult
/ (clk_period
* divs
[i
] * div
);
535 if (_clk
>= pwm_min
&& _clk
<= pwm_max
) {
544 ufshcd_dme_get(hba
, UIC_ARG_MIB(CMN_PWM_CLK_CTRL
), &clk_idx
);
546 "failed to decide pwm clock divider, will not change\n");
549 attr
->cmn_pwm_clk_ctrl
= clk_idx
& PWM_CLK_CTRL_MASK
;
552 long exynos_ufs_calc_time_cntr(struct exynos_ufs
*ufs
, long period
)
554 const int precise
= 10;
555 long pclk_rate
= ufs
->pclk_rate
;
556 long clk_period
, fraction
;
558 clk_period
= UNIPRO_PCLK_PERIOD(ufs
);
559 fraction
= ((NSEC_PER_SEC
% pclk_rate
) * precise
) / pclk_rate
;
561 return (period
* precise
) / ((clk_period
* precise
) + fraction
);
564 static void exynos_ufs_specify_phy_time_attr(struct exynos_ufs
*ufs
)
566 struct exynos_ufs_uic_attr
*attr
= ufs
->drv_data
->uic_attr
;
567 struct ufs_phy_time_cfg
*t_cfg
= &ufs
->t_cfg
;
569 if (ufs
->opts
& EXYNOS_UFS_OPT_SKIP_CONFIG_PHY_ATTR
)
572 t_cfg
->tx_linereset_p
=
573 exynos_ufs_calc_time_cntr(ufs
, attr
->tx_dif_p_nsec
);
574 t_cfg
->tx_linereset_n
=
575 exynos_ufs_calc_time_cntr(ufs
, attr
->tx_dif_n_nsec
);
576 t_cfg
->tx_high_z_cnt
=
577 exynos_ufs_calc_time_cntr(ufs
, attr
->tx_high_z_cnt_nsec
);
578 t_cfg
->tx_base_n_val
=
579 exynos_ufs_calc_time_cntr(ufs
, attr
->tx_base_unit_nsec
);
580 t_cfg
->tx_gran_n_val
=
581 exynos_ufs_calc_time_cntr(ufs
, attr
->tx_gran_unit_nsec
);
582 t_cfg
->tx_sleep_cnt
=
583 exynos_ufs_calc_time_cntr(ufs
, attr
->tx_sleep_cnt
);
585 t_cfg
->rx_linereset
=
586 exynos_ufs_calc_time_cntr(ufs
, attr
->rx_dif_p_nsec
);
587 t_cfg
->rx_hibern8_wait
=
588 exynos_ufs_calc_time_cntr(ufs
, attr
->rx_hibern8_wait_nsec
);
589 t_cfg
->rx_base_n_val
=
590 exynos_ufs_calc_time_cntr(ufs
, attr
->rx_base_unit_nsec
);
591 t_cfg
->rx_gran_n_val
=
592 exynos_ufs_calc_time_cntr(ufs
, attr
->rx_gran_unit_nsec
);
593 t_cfg
->rx_sleep_cnt
=
594 exynos_ufs_calc_time_cntr(ufs
, attr
->rx_sleep_cnt
);
595 t_cfg
->rx_stall_cnt
=
596 exynos_ufs_calc_time_cntr(ufs
, attr
->rx_stall_cnt
);
599 static void exynos_ufs_config_phy_time_attr(struct exynos_ufs
*ufs
)
601 struct ufs_hba
*hba
= ufs
->hba
;
602 struct ufs_phy_time_cfg
*t_cfg
= &ufs
->t_cfg
;
605 exynos_ufs_set_pwm_clk_div(ufs
);
607 exynos_ufs_enable_ov_tm(hba
);
609 for_each_ufs_rx_lane(ufs
, i
) {
610 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(RX_FILLER_ENABLE
, i
),
611 ufs
->drv_data
->uic_attr
->rx_filler_enable
);
612 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(RX_LINERESET_VAL
, i
),
613 RX_LINERESET(t_cfg
->rx_linereset
));
614 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(RX_BASE_NVAL_07_00
, i
),
615 RX_BASE_NVAL_L(t_cfg
->rx_base_n_val
));
616 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(RX_BASE_NVAL_15_08
, i
),
617 RX_BASE_NVAL_H(t_cfg
->rx_base_n_val
));
618 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(RX_GRAN_NVAL_07_00
, i
),
619 RX_GRAN_NVAL_L(t_cfg
->rx_gran_n_val
));
620 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(RX_GRAN_NVAL_10_08
, i
),
621 RX_GRAN_NVAL_H(t_cfg
->rx_gran_n_val
));
622 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(RX_OV_SLEEP_CNT_TIMER
, i
),
623 RX_OV_SLEEP_CNT(t_cfg
->rx_sleep_cnt
));
624 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(RX_OV_STALL_CNT_TIMER
, i
),
625 RX_OV_STALL_CNT(t_cfg
->rx_stall_cnt
));
628 for_each_ufs_tx_lane(ufs
, i
) {
629 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(TX_LINERESET_P_VAL
, i
),
630 TX_LINERESET_P(t_cfg
->tx_linereset_p
));
631 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(TX_HIGH_Z_CNT_07_00
, i
),
632 TX_HIGH_Z_CNT_L(t_cfg
->tx_high_z_cnt
));
633 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(TX_HIGH_Z_CNT_11_08
, i
),
634 TX_HIGH_Z_CNT_H(t_cfg
->tx_high_z_cnt
));
635 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(TX_BASE_NVAL_07_00
, i
),
636 TX_BASE_NVAL_L(t_cfg
->tx_base_n_val
));
637 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(TX_BASE_NVAL_15_08
, i
),
638 TX_BASE_NVAL_H(t_cfg
->tx_base_n_val
));
639 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(TX_GRAN_NVAL_07_00
, i
),
640 TX_GRAN_NVAL_L(t_cfg
->tx_gran_n_val
));
641 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(TX_GRAN_NVAL_10_08
, i
),
642 TX_GRAN_NVAL_H(t_cfg
->tx_gran_n_val
));
643 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(TX_OV_SLEEP_CNT_TIMER
, i
),
645 TX_OV_SLEEP_CNT(t_cfg
->tx_sleep_cnt
));
646 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(TX_MIN_ACTIVATETIME
, i
),
647 ufs
->drv_data
->uic_attr
->tx_min_activatetime
);
650 exynos_ufs_disable_ov_tm(hba
);
653 static void exynos_ufs_config_phy_cap_attr(struct exynos_ufs
*ufs
)
655 struct ufs_hba
*hba
= ufs
->hba
;
656 struct exynos_ufs_uic_attr
*attr
= ufs
->drv_data
->uic_attr
;
659 exynos_ufs_enable_ov_tm(hba
);
661 for_each_ufs_rx_lane(ufs
, i
) {
663 UIC_ARG_MIB_SEL(RX_HS_G1_SYNC_LENGTH_CAP
, i
),
664 attr
->rx_hs_g1_sync_len_cap
);
666 UIC_ARG_MIB_SEL(RX_HS_G2_SYNC_LENGTH_CAP
, i
),
667 attr
->rx_hs_g2_sync_len_cap
);
669 UIC_ARG_MIB_SEL(RX_HS_G3_SYNC_LENGTH_CAP
, i
),
670 attr
->rx_hs_g3_sync_len_cap
);
672 UIC_ARG_MIB_SEL(RX_HS_G1_PREP_LENGTH_CAP
, i
),
673 attr
->rx_hs_g1_prep_sync_len_cap
);
675 UIC_ARG_MIB_SEL(RX_HS_G2_PREP_LENGTH_CAP
, i
),
676 attr
->rx_hs_g2_prep_sync_len_cap
);
678 UIC_ARG_MIB_SEL(RX_HS_G3_PREP_LENGTH_CAP
, i
),
679 attr
->rx_hs_g3_prep_sync_len_cap
);
682 if (attr
->rx_adv_fine_gran_sup_en
== 0) {
683 for_each_ufs_rx_lane(ufs
, i
) {
685 UIC_ARG_MIB_SEL(RX_ADV_GRANULARITY_CAP
, i
), 0);
687 if (attr
->rx_min_actv_time_cap
)
690 RX_MIN_ACTIVATETIME_CAPABILITY
, i
),
691 attr
->rx_min_actv_time_cap
);
693 if (attr
->rx_hibern8_time_cap
)
695 UIC_ARG_MIB_SEL(RX_HIBERN8TIME_CAP
, i
),
696 attr
->rx_hibern8_time_cap
);
698 } else if (attr
->rx_adv_fine_gran_sup_en
== 1) {
699 for_each_ufs_rx_lane(ufs
, i
) {
700 if (attr
->rx_adv_fine_gran_step
)
702 UIC_ARG_MIB_SEL(RX_ADV_GRANULARITY_CAP
,
703 i
), RX_ADV_FINE_GRAN_STEP(
704 attr
->rx_adv_fine_gran_step
));
706 if (attr
->rx_adv_min_actv_time_cap
)
709 RX_ADV_MIN_ACTIVATETIME_CAP
, i
),
710 attr
->rx_adv_min_actv_time_cap
);
712 if (attr
->rx_adv_hibern8_time_cap
)
714 UIC_ARG_MIB_SEL(RX_ADV_HIBERN8TIME_CAP
,
716 attr
->rx_adv_hibern8_time_cap
);
720 exynos_ufs_disable_ov_tm(hba
);
723 static void exynos_ufs_establish_connt(struct exynos_ufs
*ufs
)
725 struct ufs_hba
*hba
= ufs
->hba
;
729 PEER_CPORT_ID
= 0x00,
730 TRAFFIC_CLASS
= 0x00,
733 /* allow cport attributes to be set */
734 ufshcd_dme_set(hba
, UIC_ARG_MIB(T_CONNECTIONSTATE
), CPORT_IDLE
);
736 /* local unipro attributes */
737 ufshcd_dme_set(hba
, UIC_ARG_MIB(N_DEVICEID
), DEV_ID
);
738 ufshcd_dme_set(hba
, UIC_ARG_MIB(N_DEVICEID_VALID
), true);
739 ufshcd_dme_set(hba
, UIC_ARG_MIB(T_PEERDEVICEID
), PEER_DEV_ID
);
740 ufshcd_dme_set(hba
, UIC_ARG_MIB(T_PEERCPORTID
), PEER_CPORT_ID
);
741 ufshcd_dme_set(hba
, UIC_ARG_MIB(T_CPORTFLAGS
), CPORT_DEF_FLAGS
);
742 ufshcd_dme_set(hba
, UIC_ARG_MIB(T_TRAFFICCLASS
), TRAFFIC_CLASS
);
743 ufshcd_dme_set(hba
, UIC_ARG_MIB(T_CONNECTIONSTATE
), CPORT_CONNECTED
);
746 static void exynos_ufs_config_smu(struct exynos_ufs
*ufs
)
750 if (ufs
->opts
& EXYNOS_UFS_OPT_UFSPR_SECURE
)
753 exynos_ufs_disable_auto_ctrl_hcc_save(ufs
, &val
);
755 /* make encryption disabled by default */
756 reg
= ufsp_readl(ufs
, UFSPRSECURITY
);
757 ufsp_writel(ufs
, reg
| NSSMU
, UFSPRSECURITY
);
758 ufsp_writel(ufs
, 0x0, UFSPSBEGIN0
);
759 ufsp_writel(ufs
, 0xffffffff, UFSPSEND0
);
760 ufsp_writel(ufs
, 0xff, UFSPSLUN0
);
761 ufsp_writel(ufs
, 0xf1, UFSPSCTRL0
);
763 exynos_ufs_auto_ctrl_hcc_restore(ufs
, &val
);
766 static void exynos_ufs_config_sync_pattern_mask(struct exynos_ufs
*ufs
,
767 struct ufs_pa_layer_attr
*pwr
)
769 struct ufs_hba
*hba
= ufs
->hba
;
770 u8 g
= max_t(u32
, pwr
->gear_rx
, pwr
->gear_tx
);
773 SYNC_LEN_G1
= 80 * 1000, /* 80us */
774 SYNC_LEN_G2
= 40 * 1000, /* 44us */
775 SYNC_LEN_G3
= 20 * 1000, /* 20us */
780 sync_len
= SYNC_LEN_G1
;
782 sync_len
= SYNC_LEN_G2
;
784 sync_len
= SYNC_LEN_G3
;
788 mask
= exynos_ufs_calc_time_cntr(ufs
, sync_len
);
789 mask
= (mask
>> 8) & 0xff;
791 exynos_ufs_enable_ov_tm(hba
);
793 for_each_ufs_rx_lane(ufs
, i
)
795 UIC_ARG_MIB_SEL(RX_SYNC_MASK_LENGTH
, i
), mask
);
797 exynos_ufs_disable_ov_tm(hba
);
800 #define UFS_HW_VER_MAJOR_MASK GENMASK(15, 8)
802 static u32
exynos_ufs_get_hs_gear(struct ufs_hba
*hba
)
806 major
= FIELD_GET(UFS_HW_VER_MAJOR_MASK
, hba
->ufs_version
);
811 /* Default is HS-G3 */
815 static int exynos_ufs_pre_pwr_mode(struct ufs_hba
*hba
,
816 struct ufs_pa_layer_attr
*dev_max_params
,
817 struct ufs_pa_layer_attr
*dev_req_params
)
819 struct exynos_ufs
*ufs
= ufshcd_get_variant(hba
);
820 struct phy
*generic_phy
= ufs
->phy
;
821 struct ufs_host_params host_params
;
824 if (!dev_req_params
) {
825 pr_err("%s: incoming dev_req_params is NULL\n", __func__
);
830 ufshcd_init_host_params(&host_params
);
832 /* This driver only support symmetric gear setting e.g. hs_tx_gear == hs_rx_gear */
833 host_params
.hs_tx_gear
= exynos_ufs_get_hs_gear(hba
);
834 host_params
.hs_rx_gear
= exynos_ufs_get_hs_gear(hba
);
836 ret
= ufshcd_negotiate_pwr_params(&host_params
, dev_max_params
, dev_req_params
);
838 pr_err("%s: failed to determine capabilities\n", __func__
);
842 if (ufs
->drv_data
->pre_pwr_change
)
843 ufs
->drv_data
->pre_pwr_change(ufs
, dev_req_params
);
845 if (ufshcd_is_hs_mode(dev_req_params
)) {
846 exynos_ufs_config_sync_pattern_mask(ufs
, dev_req_params
);
848 switch (dev_req_params
->hs_rate
) {
851 phy_calibrate(generic_phy
);
856 /* setting for three timeout values for traffic class #0 */
857 ufshcd_dme_set(hba
, UIC_ARG_MIB(DL_FC0PROTTIMEOUTVAL
), 8064);
858 ufshcd_dme_set(hba
, UIC_ARG_MIB(DL_TC0REPLAYTIMEOUTVAL
), 28224);
859 ufshcd_dme_set(hba
, UIC_ARG_MIB(DL_AFC0REQTIMEOUTVAL
), 20160);
866 #define PWR_MODE_STR_LEN 64
867 static int exynos_ufs_post_pwr_mode(struct ufs_hba
*hba
,
868 struct ufs_pa_layer_attr
*pwr_req
)
870 struct exynos_ufs
*ufs
= ufshcd_get_variant(hba
);
871 struct phy
*generic_phy
= ufs
->phy
;
872 int gear
= max_t(u32
, pwr_req
->gear_rx
, pwr_req
->gear_tx
);
873 int lanes
= max_t(u32
, pwr_req
->lane_rx
, pwr_req
->lane_tx
);
874 char pwr_str
[PWR_MODE_STR_LEN
] = "";
876 /* let default be PWM Gear 1, Lane 1 */
883 if (ufs
->drv_data
->post_pwr_change
)
884 ufs
->drv_data
->post_pwr_change(ufs
, pwr_req
);
886 if ((ufshcd_is_hs_mode(pwr_req
))) {
887 switch (pwr_req
->hs_rate
) {
890 phy_calibrate(generic_phy
);
894 snprintf(pwr_str
, PWR_MODE_STR_LEN
, "%s series_%s G_%d L_%d",
895 "FAST", pwr_req
->hs_rate
== PA_HS_MODE_A
? "A" : "B",
898 snprintf(pwr_str
, PWR_MODE_STR_LEN
, "%s G_%d L_%d",
899 "SLOW", gear
, lanes
);
902 dev_info(hba
->dev
, "Power mode changed to : %s\n", pwr_str
);
907 static void exynos_ufs_specify_nexus_t_xfer_req(struct ufs_hba
*hba
,
908 int tag
, bool is_scsi_cmd
)
910 struct exynos_ufs
*ufs
= ufshcd_get_variant(hba
);
913 type
= hci_readl(ufs
, HCI_UTRL_NEXUS_TYPE
);
916 hci_writel(ufs
, type
| (1 << tag
), HCI_UTRL_NEXUS_TYPE
);
918 hci_writel(ufs
, type
& ~(1 << tag
), HCI_UTRL_NEXUS_TYPE
);
921 static void exynos_ufs_specify_nexus_t_tm_req(struct ufs_hba
*hba
,
924 struct exynos_ufs
*ufs
= ufshcd_get_variant(hba
);
927 type
= hci_readl(ufs
, HCI_UTMRL_NEXUS_TYPE
);
932 hci_writel(ufs
, type
| (1 << tag
), HCI_UTMRL_NEXUS_TYPE
);
934 case UFS_ABORT_TASK_SET
:
935 case UFS_CLEAR_TASK_SET
:
936 case UFS_LOGICAL_RESET
:
937 case UFS_QUERY_TASK_SET
:
938 hci_writel(ufs
, type
& ~(1 << tag
), HCI_UTMRL_NEXUS_TYPE
);
943 static int exynos_ufs_phy_init(struct exynos_ufs
*ufs
)
945 struct ufs_hba
*hba
= ufs
->hba
;
946 struct phy
*generic_phy
= ufs
->phy
;
949 if (ufs
->avail_ln_rx
== 0 || ufs
->avail_ln_tx
== 0) {
950 ufshcd_dme_get(hba
, UIC_ARG_MIB(PA_AVAILRXDATALANES
),
952 ufshcd_dme_get(hba
, UIC_ARG_MIB(PA_AVAILTXDATALANES
),
954 WARN(ufs
->avail_ln_rx
!= ufs
->avail_ln_tx
,
955 "available data lane is not equal(rx:%d, tx:%d)\n",
956 ufs
->avail_ln_rx
, ufs
->avail_ln_tx
);
959 phy_set_bus_width(generic_phy
, ufs
->avail_ln_rx
);
960 ret
= phy_init(generic_phy
);
962 dev_err(hba
->dev
, "%s: phy init failed, ret = %d\n",
967 ret
= phy_power_on(generic_phy
);
974 phy_exit(generic_phy
);
979 static void exynos_ufs_config_unipro(struct exynos_ufs
*ufs
)
981 struct exynos_ufs_uic_attr
*attr
= ufs
->drv_data
->uic_attr
;
982 struct ufs_hba
*hba
= ufs
->hba
;
984 if (attr
->pa_dbg_clk_period_off
)
985 ufshcd_dme_set(hba
, UIC_ARG_MIB(attr
->pa_dbg_clk_period_off
),
986 DIV_ROUND_UP(NSEC_PER_SEC
, ufs
->mclk_rate
));
988 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_TXTRAILINGCLOCKS
),
989 ufs
->drv_data
->uic_attr
->tx_trailingclks
);
991 if (attr
->pa_dbg_opt_suite1_off
)
992 ufshcd_dme_set(hba
, UIC_ARG_MIB(attr
->pa_dbg_opt_suite1_off
),
993 attr
->pa_dbg_opt_suite1_val
);
995 if (attr
->pa_dbg_opt_suite2_off
)
996 ufshcd_dme_set(hba
, UIC_ARG_MIB(attr
->pa_dbg_opt_suite2_off
),
997 attr
->pa_dbg_opt_suite2_val
);
1000 static void exynos_ufs_config_intr(struct exynos_ufs
*ufs
, u32 errs
, u8 index
)
1004 hci_writel(ufs
, DFES_ERR_EN
| errs
, HCI_ERR_EN_PA_LAYER
);
1007 hci_writel(ufs
, DFES_ERR_EN
| errs
, HCI_ERR_EN_DL_LAYER
);
1010 hci_writel(ufs
, DFES_ERR_EN
| errs
, HCI_ERR_EN_N_LAYER
);
1013 hci_writel(ufs
, DFES_ERR_EN
| errs
, HCI_ERR_EN_T_LAYER
);
1016 hci_writel(ufs
, DFES_ERR_EN
| errs
, HCI_ERR_EN_DME_LAYER
);
1021 static int exynos_ufs_setup_clocks(struct ufs_hba
*hba
, bool on
,
1022 enum ufs_notify_change_status status
)
1024 struct exynos_ufs
*ufs
= ufshcd_get_variant(hba
);
1029 if (on
&& status
== PRE_CHANGE
) {
1030 if (ufs
->opts
& EXYNOS_UFS_OPT_BROKEN_AUTO_CLK_CTRL
)
1031 exynos_ufs_disable_auto_ctrl_hcc(ufs
);
1032 exynos_ufs_ungate_clks(ufs
);
1033 } else if (!on
&& status
== POST_CHANGE
) {
1034 exynos_ufs_gate_clks(ufs
);
1035 if (ufs
->opts
& EXYNOS_UFS_OPT_BROKEN_AUTO_CLK_CTRL
)
1036 exynos_ufs_enable_auto_ctrl_hcc(ufs
);
1042 static int exynos_ufs_pre_link(struct ufs_hba
*hba
)
1044 struct exynos_ufs
*ufs
= ufshcd_get_variant(hba
);
1047 exynos_ufs_config_intr(ufs
, DFES_DEF_L2_ERRS
, UNIPRO_L2
);
1048 exynos_ufs_config_intr(ufs
, DFES_DEF_L3_ERRS
, UNIPRO_L3
);
1049 exynos_ufs_config_intr(ufs
, DFES_DEF_L4_ERRS
, UNIPRO_L4
);
1050 exynos_ufs_set_unipro_pclk_div(ufs
);
1053 exynos_ufs_config_unipro(ufs
);
1056 exynos_ufs_phy_init(ufs
);
1057 if (!(ufs
->opts
& EXYNOS_UFS_OPT_SKIP_CONFIG_PHY_ATTR
)) {
1058 exynos_ufs_config_phy_time_attr(ufs
);
1059 exynos_ufs_config_phy_cap_attr(ufs
);
1062 exynos_ufs_setup_clocks(hba
, true, PRE_CHANGE
);
1064 if (ufs
->drv_data
->pre_link
)
1065 ufs
->drv_data
->pre_link(ufs
);
1070 static void exynos_ufs_fit_aggr_timeout(struct exynos_ufs
*ufs
)
1074 /* Select function clock (mclk) for timer tick */
1075 if (ufs
->opts
& EXYNOS_UFS_OPT_TIMER_TICK_SELECT
) {
1076 val
= hci_readl(ufs
, HCI_V2P1_CTRL
);
1078 hci_writel(ufs
, val
, HCI_V2P1_CTRL
);
1081 val
= exynos_ufs_calc_time_cntr(ufs
, IATOVAL_NSEC
/ CNTR_DIV_VAL
);
1082 hci_writel(ufs
, val
& CNT_VAL_1US_MASK
, HCI_1US_TO_CNT_VAL
);
1085 static int exynos_ufs_post_link(struct ufs_hba
*hba
)
1087 struct exynos_ufs
*ufs
= ufshcd_get_variant(hba
);
1088 struct phy
*generic_phy
= ufs
->phy
;
1089 struct exynos_ufs_uic_attr
*attr
= ufs
->drv_data
->uic_attr
;
1091 exynos_ufs_establish_connt(ufs
);
1092 exynos_ufs_fit_aggr_timeout(ufs
);
1094 hci_writel(ufs
, 0xa, HCI_DATA_REORDER
);
1095 hci_writel(ufs
, ilog2(DATA_UNIT_SIZE
), HCI_TXPRDT_ENTRY_SIZE
);
1096 hci_writel(ufs
, ilog2(DATA_UNIT_SIZE
), HCI_RXPRDT_ENTRY_SIZE
);
1097 hci_writel(ufs
, (1 << hba
->nutrs
) - 1, HCI_UTRL_NEXUS_TYPE
);
1098 hci_writel(ufs
, (1 << hba
->nutmrs
) - 1, HCI_UTMRL_NEXUS_TYPE
);
1099 hci_writel(ufs
, 0xf, HCI_AXIDMA_RWDATA_BURST_LEN
);
1101 if (ufs
->opts
& EXYNOS_UFS_OPT_SKIP_CONNECTION_ESTAB
)
1103 UIC_ARG_MIB(T_DBG_SKIP_INIT_HIBERN8_EXIT
), true);
1105 if (attr
->pa_granularity
) {
1106 exynos_ufs_enable_dbg_mode(hba
);
1107 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_GRANULARITY
),
1108 attr
->pa_granularity
);
1109 exynos_ufs_disable_dbg_mode(hba
);
1111 if (attr
->pa_tactivate
)
1112 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_TACTIVATE
),
1113 attr
->pa_tactivate
);
1114 if (attr
->pa_hibern8time
&&
1115 !(ufs
->opts
& EXYNOS_UFS_OPT_USE_SW_HIBERN8_TIMER
))
1116 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_HIBERN8TIME
),
1117 attr
->pa_hibern8time
);
1120 if (ufs
->opts
& EXYNOS_UFS_OPT_USE_SW_HIBERN8_TIMER
) {
1121 if (!attr
->pa_granularity
)
1122 ufshcd_dme_get(hba
, UIC_ARG_MIB(PA_GRANULARITY
),
1123 &attr
->pa_granularity
);
1124 if (!attr
->pa_hibern8time
)
1125 ufshcd_dme_get(hba
, UIC_ARG_MIB(PA_HIBERN8TIME
),
1126 &attr
->pa_hibern8time
);
1128 * not wait for HIBERN8 time to exit hibernation
1130 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_HIBERN8TIME
), 0);
1132 if (attr
->pa_granularity
< 1 || attr
->pa_granularity
> 6) {
1133 /* Valid range for granularity: 1 ~ 6 */
1135 "%s: pa_granularity %d is invalid, assuming backwards compatibility\n",
1137 attr
->pa_granularity
);
1138 attr
->pa_granularity
= 6;
1142 phy_calibrate(generic_phy
);
1144 if (ufs
->drv_data
->post_link
)
1145 ufs
->drv_data
->post_link(ufs
);
1150 static int exynos_ufs_parse_dt(struct device
*dev
, struct exynos_ufs
*ufs
)
1152 struct device_node
*np
= dev
->of_node
;
1153 struct exynos_ufs_uic_attr
*attr
;
1156 ufs
->drv_data
= device_get_match_data(dev
);
1158 if (ufs
->drv_data
&& ufs
->drv_data
->uic_attr
) {
1159 attr
= ufs
->drv_data
->uic_attr
;
1161 dev_err(dev
, "failed to get uic attributes\n");
1166 ufs
->sysreg
= syscon_regmap_lookup_by_phandle(np
, "samsung,sysreg");
1167 if (IS_ERR(ufs
->sysreg
))
1170 if (of_property_read_u32_index(np
, "samsung,sysreg", 1,
1171 &ufs
->shareability_reg_offset
)) {
1172 dev_warn(dev
, "can't get an offset from sysreg. Set to default value\n");
1173 ufs
->shareability_reg_offset
= UFS_SHAREABILITY_OFFSET
;
1177 ufs
->pclk_avail_min
= PCLK_AVAIL_MIN
;
1178 ufs
->pclk_avail_max
= PCLK_AVAIL_MAX
;
1180 attr
->rx_adv_fine_gran_sup_en
= RX_ADV_FINE_GRAN_SUP_EN
;
1181 attr
->rx_adv_fine_gran_step
= RX_ADV_FINE_GRAN_STEP_VAL
;
1182 attr
->rx_adv_min_actv_time_cap
= RX_ADV_MIN_ACTV_TIME_CAP
;
1183 attr
->pa_granularity
= PA_GRANULARITY_VAL
;
1184 attr
->pa_tactivate
= PA_TACTIVATE_VAL
;
1185 attr
->pa_hibern8time
= PA_HIBERN8TIME_VAL
;
1191 static inline void exynos_ufs_priv_init(struct ufs_hba
*hba
,
1192 struct exynos_ufs
*ufs
)
1195 ufs
->opts
= ufs
->drv_data
->opts
;
1196 ufs
->rx_sel_idx
= PA_MAXDATALANES
;
1197 if (ufs
->opts
& EXYNOS_UFS_OPT_BROKEN_RX_SEL_IDX
)
1198 ufs
->rx_sel_idx
= 0;
1199 hba
->priv
= (void *)ufs
;
1200 hba
->quirks
= ufs
->drv_data
->quirks
;
1203 #ifdef CONFIG_SCSI_UFS_CRYPTO
1206 * Support for Flash Memory Protector (FMP), which is the inline encryption
1207 * hardware on Exynos and Exynos-based SoCs. The interface to this hardware is
1208 * not compatible with the standard UFS crypto. It requires that encryption be
1209 * configured in the PRDT using a nonstandard extension.
1212 enum fmp_crypto_algo_mode
{
1213 FMP_BYPASS_MODE
= 0,
1214 FMP_ALGO_MODE_AES_CBC
= 1,
1215 FMP_ALGO_MODE_AES_XTS
= 2,
1217 enum fmp_crypto_key_length
{
1218 FMP_KEYLEN_256BIT
= 1,
1222 * struct fmp_sg_entry - nonstandard format of PRDT entries when FMP is enabled
1224 * @base: The standard PRDT entry, but with nonstandard bitfields in the high
1225 * bits of the 'size' field, i.e. the last 32-bit word. When these
1226 * nonstandard bitfields are zero, the data segment won't be encrypted or
1227 * decrypted. Otherwise they specify the algorithm and key length with
1228 * which the data segment will be encrypted or decrypted.
1229 * @file_iv: The initialization vector (IV) with all bytes reversed
1230 * @file_enckey: The first half of the AES-XTS key with all bytes reserved
1231 * @file_twkey: The second half of the AES-XTS key with all bytes reserved
1235 struct fmp_sg_entry
{
1236 struct ufshcd_sg_entry base
;
1238 __be64 file_enckey
[4];
1239 __be64 file_twkey
[4];
1244 #define SMC_CMD_FMP_SECURITY \
1245 ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_64, \
1246 ARM_SMCCC_OWNER_SIP, 0x1810)
1247 #define SMC_CMD_SMU \
1248 ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_64, \
1249 ARM_SMCCC_OWNER_SIP, 0x1850)
1250 #define SMC_CMD_FMP_SMU_RESUME \
1251 ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_64, \
1252 ARM_SMCCC_OWNER_SIP, 0x1860)
1253 #define SMU_EMBEDDED 0
1255 #define CFG_DESCTYPE_3 3
1257 static void exynos_ufs_fmp_init(struct ufs_hba
*hba
, struct exynos_ufs
*ufs
)
1259 struct blk_crypto_profile
*profile
= &hba
->crypto_profile
;
1260 struct arm_smccc_res res
;
1264 * Check for the standard crypto support bit, since it's available even
1265 * though the rest of the interface to FMP is nonstandard.
1267 * This check should have the effect of preventing the driver from
1268 * trying to use FMP on old Exynos SoCs that don't have FMP.
1270 if (!(ufshcd_readl(hba
, REG_CONTROLLER_CAPABILITIES
) &
1271 MASK_CRYPTO_SUPPORT
))
1275 * The below sequence of SMC calls to enable FMP can be found in the
1276 * downstream driver source for gs101 and other Exynos-based SoCs. It
1277 * is the only way to enable FMP that works on SoCs such as gs101 that
1278 * don't make the FMP registers accessible to Linux. It probably works
1279 * on other Exynos-based SoCs too, and might even still be the only way
1280 * that works. But this hasn't been properly tested, and this code is
1281 * mutually exclusive with exynos_ufs_config_smu(). So for now only
1282 * enable FMP support on SoCs with EXYNOS_UFS_OPT_UFSPR_SECURE.
1284 if (!(ufs
->opts
& EXYNOS_UFS_OPT_UFSPR_SECURE
))
1288 * This call (which sets DESCTYPE to 0x3 in the FMPSECURITY0 register)
1289 * is needed to make the hardware use the larger PRDT entry size.
1291 BUILD_BUG_ON(sizeof(struct fmp_sg_entry
) != 128);
1292 arm_smccc_smc(SMC_CMD_FMP_SECURITY
, 0, SMU_EMBEDDED
, CFG_DESCTYPE_3
,
1296 "SMC_CMD_FMP_SECURITY failed on init: %ld. Disabling FMP support.\n",
1300 ufshcd_set_sg_entry_size(hba
, sizeof(struct fmp_sg_entry
));
1303 * This is needed to initialize FMP. Without it, errors occur when
1304 * inline encryption is used.
1306 arm_smccc_smc(SMC_CMD_SMU
, SMU_INIT
, SMU_EMBEDDED
, 0, 0, 0, 0, 0, &res
);
1309 "SMC_CMD_SMU(SMU_INIT) failed: %ld. Disabling FMP support.\n",
1314 /* Advertise crypto capabilities to the block layer. */
1315 err
= devm_blk_crypto_profile_init(hba
->dev
, profile
, 0);
1317 /* Only ENOMEM should be possible here. */
1318 dev_err(hba
->dev
, "Failed to initialize crypto profile: %d\n",
1322 profile
->max_dun_bytes_supported
= AES_BLOCK_SIZE
;
1323 profile
->dev
= hba
->dev
;
1324 profile
->modes_supported
[BLK_ENCRYPTION_MODE_AES_256_XTS
] =
1327 /* Advertise crypto support to ufshcd-core. */
1328 hba
->caps
|= UFSHCD_CAP_CRYPTO
;
1330 /* Advertise crypto quirks to ufshcd-core. */
1331 hba
->quirks
|= UFSHCD_QUIRK_CUSTOM_CRYPTO_PROFILE
|
1332 UFSHCD_QUIRK_BROKEN_CRYPTO_ENABLE
|
1333 UFSHCD_QUIRK_KEYS_IN_PRDT
;
1337 static void exynos_ufs_fmp_resume(struct ufs_hba
*hba
)
1339 struct arm_smccc_res res
;
1341 if (!(hba
->caps
& UFSHCD_CAP_CRYPTO
))
1344 arm_smccc_smc(SMC_CMD_FMP_SECURITY
, 0, SMU_EMBEDDED
, CFG_DESCTYPE_3
,
1348 "SMC_CMD_FMP_SECURITY failed on resume: %ld\n", res
.a0
);
1350 arm_smccc_smc(SMC_CMD_FMP_SMU_RESUME
, 0, SMU_EMBEDDED
, 0, 0, 0, 0, 0,
1354 "SMC_CMD_FMP_SMU_RESUME failed: %ld\n", res
.a0
);
1357 static inline __be64
fmp_key_word(const u8
*key
, int j
)
1359 return cpu_to_be64(get_unaligned_le64(
1360 key
+ AES_KEYSIZE_256
- (j
+ 1) * sizeof(u64
)));
1363 /* Fill the PRDT for a request according to the given encryption context. */
1364 static int exynos_ufs_fmp_fill_prdt(struct ufs_hba
*hba
,
1365 const struct bio_crypt_ctx
*crypt_ctx
,
1366 void *prdt
, unsigned int num_segments
)
1368 struct fmp_sg_entry
*fmp_prdt
= prdt
;
1369 const u8
*enckey
= crypt_ctx
->bc_key
->raw
;
1370 const u8
*twkey
= enckey
+ AES_KEYSIZE_256
;
1371 u64 dun_lo
= crypt_ctx
->bc_dun
[0];
1372 u64 dun_hi
= crypt_ctx
->bc_dun
[1];
1375 /* If FMP wasn't enabled, we shouldn't get any encrypted requests. */
1376 if (WARN_ON_ONCE(!(hba
->caps
& UFSHCD_CAP_CRYPTO
)))
1379 /* Configure FMP on each segment of the request. */
1380 for (i
= 0; i
< num_segments
; i
++) {
1381 struct fmp_sg_entry
*prd
= &fmp_prdt
[i
];
1384 /* Each segment must be exactly one data unit. */
1385 if (prd
->base
.size
!= cpu_to_le32(DATA_UNIT_SIZE
- 1)) {
1387 "data segment is misaligned for FMP\n");
1391 /* Set the algorithm and key length. */
1392 prd
->base
.size
|= cpu_to_le32((FMP_ALGO_MODE_AES_XTS
<< 28) |
1393 (FMP_KEYLEN_256BIT
<< 26));
1396 prd
->file_iv
[0] = cpu_to_be64(dun_hi
);
1397 prd
->file_iv
[1] = cpu_to_be64(dun_lo
);
1400 for (j
= 0; j
< AES_KEYSIZE_256
/ sizeof(u64
); j
++) {
1401 prd
->file_enckey
[j
] = fmp_key_word(enckey
, j
);
1402 prd
->file_twkey
[j
] = fmp_key_word(twkey
, j
);
1405 /* Increment the data unit number. */
1413 #else /* CONFIG_SCSI_UFS_CRYPTO */
1415 static void exynos_ufs_fmp_init(struct ufs_hba
*hba
, struct exynos_ufs
*ufs
)
1419 static void exynos_ufs_fmp_resume(struct ufs_hba
*hba
)
1423 #define exynos_ufs_fmp_fill_prdt NULL
1425 #endif /* !CONFIG_SCSI_UFS_CRYPTO */
1427 static int exynos_ufs_init(struct ufs_hba
*hba
)
1429 struct device
*dev
= hba
->dev
;
1430 struct platform_device
*pdev
= to_platform_device(dev
);
1431 struct exynos_ufs
*ufs
;
1434 ufs
= devm_kzalloc(dev
, sizeof(*ufs
), GFP_KERNEL
);
1438 /* exynos-specific hci */
1439 ufs
->reg_hci
= devm_platform_ioremap_resource_byname(pdev
, "vs_hci");
1440 if (IS_ERR(ufs
->reg_hci
)) {
1441 dev_err(dev
, "cannot ioremap for hci vendor register\n");
1442 return PTR_ERR(ufs
->reg_hci
);
1446 ufs
->reg_unipro
= devm_platform_ioremap_resource_byname(pdev
, "unipro");
1447 if (IS_ERR(ufs
->reg_unipro
)) {
1448 dev_err(dev
, "cannot ioremap for unipro register\n");
1449 return PTR_ERR(ufs
->reg_unipro
);
1453 ufs
->reg_ufsp
= devm_platform_ioremap_resource_byname(pdev
, "ufsp");
1454 if (IS_ERR(ufs
->reg_ufsp
)) {
1455 dev_err(dev
, "cannot ioremap for ufs protector register\n");
1456 return PTR_ERR(ufs
->reg_ufsp
);
1459 ret
= exynos_ufs_parse_dt(dev
, ufs
);
1461 dev_err(dev
, "failed to get dt info.\n");
1465 ufs
->phy
= devm_phy_get(dev
, "ufs-phy");
1466 if (IS_ERR(ufs
->phy
)) {
1467 ret
= PTR_ERR(ufs
->phy
);
1468 dev_err(dev
, "failed to get ufs-phy\n");
1472 exynos_ufs_priv_init(hba
, ufs
);
1474 exynos_ufs_fmp_init(hba
, ufs
);
1476 if (ufs
->drv_data
->drv_init
) {
1477 ret
= ufs
->drv_data
->drv_init(ufs
);
1479 dev_err(dev
, "failed to init drv-data\n");
1484 ret
= exynos_ufs_get_clk_info(ufs
);
1487 exynos_ufs_specify_phy_time_attr(ufs
);
1489 exynos_ufs_config_smu(ufs
);
1491 hba
->host
->dma_alignment
= DATA_UNIT_SIZE
- 1;
1499 static int exynos_ufs_host_reset(struct ufs_hba
*hba
)
1501 struct exynos_ufs
*ufs
= ufshcd_get_variant(hba
);
1502 unsigned long timeout
= jiffies
+ msecs_to_jiffies(1);
1506 exynos_ufs_disable_auto_ctrl_hcc_save(ufs
, &val
);
1508 hci_writel(ufs
, UFS_SW_RST_MASK
, HCI_SW_RST
);
1511 if (!(hci_readl(ufs
, HCI_SW_RST
) & UFS_SW_RST_MASK
))
1513 } while (time_before(jiffies
, timeout
));
1515 dev_err(hba
->dev
, "timeout host sw-reset\n");
1519 exynos_ufs_auto_ctrl_hcc_restore(ufs
, &val
);
1523 static void exynos_ufs_dev_hw_reset(struct ufs_hba
*hba
)
1525 struct exynos_ufs
*ufs
= ufshcd_get_variant(hba
);
1527 hci_writel(ufs
, 0 << 0, HCI_GPIO_OUT
);
1529 hci_writel(ufs
, 1 << 0, HCI_GPIO_OUT
);
1532 static void exynos_ufs_pre_hibern8(struct ufs_hba
*hba
, enum uic_cmd_dme cmd
)
1534 struct exynos_ufs
*ufs
= ufshcd_get_variant(hba
);
1535 struct exynos_ufs_uic_attr
*attr
= ufs
->drv_data
->uic_attr
;
1537 if (cmd
== UIC_CMD_DME_HIBER_EXIT
) {
1538 if (ufs
->opts
& EXYNOS_UFS_OPT_BROKEN_AUTO_CLK_CTRL
)
1539 exynos_ufs_disable_auto_ctrl_hcc(ufs
);
1540 exynos_ufs_ungate_clks(ufs
);
1542 if (ufs
->opts
& EXYNOS_UFS_OPT_USE_SW_HIBERN8_TIMER
) {
1543 static const unsigned int granularity_tbl
[] = {
1544 1, 4, 8, 16, 32, 100
1546 int h8_time
= attr
->pa_hibern8time
*
1547 granularity_tbl
[attr
->pa_granularity
- 1];
1552 delta
= h8_time
- ktime_us_delta(ktime_get(),
1553 ufs
->entry_hibern8_t
);
1557 us
= min_t(s64
, delta
, USEC_PER_MSEC
);
1559 usleep_range(us
, us
+ 10);
1565 static void exynos_ufs_post_hibern8(struct ufs_hba
*hba
, enum uic_cmd_dme cmd
)
1567 struct exynos_ufs
*ufs
= ufshcd_get_variant(hba
);
1569 if (cmd
== UIC_CMD_DME_HIBER_ENTER
) {
1570 ufs
->entry_hibern8_t
= ktime_get();
1571 exynos_ufs_gate_clks(ufs
);
1572 if (ufs
->opts
& EXYNOS_UFS_OPT_BROKEN_AUTO_CLK_CTRL
)
1573 exynos_ufs_enable_auto_ctrl_hcc(ufs
);
1577 static int exynos_ufs_hce_enable_notify(struct ufs_hba
*hba
,
1578 enum ufs_notify_change_status status
)
1580 struct exynos_ufs
*ufs
= ufshcd_get_variant(hba
);
1586 * The maximum segment size must be set after scsi_host_alloc()
1587 * has been called and before LUN scanning starts
1588 * (ufshcd_async_scan()). Note: this callback may also be called
1589 * from other functions than ufshcd_init().
1591 hba
->host
->max_segment_size
= DATA_UNIT_SIZE
;
1593 if (ufs
->drv_data
->pre_hce_enable
) {
1594 ret
= ufs
->drv_data
->pre_hce_enable(ufs
);
1599 ret
= exynos_ufs_host_reset(hba
);
1602 exynos_ufs_dev_hw_reset(hba
);
1605 exynos_ufs_calc_pwm_clk_div(ufs
);
1606 if (!(ufs
->opts
& EXYNOS_UFS_OPT_BROKEN_AUTO_CLK_CTRL
))
1607 exynos_ufs_enable_auto_ctrl_hcc(ufs
);
1609 if (ufs
->drv_data
->post_hce_enable
)
1610 ret
= ufs
->drv_data
->post_hce_enable(ufs
);
1618 static int exynos_ufs_link_startup_notify(struct ufs_hba
*hba
,
1619 enum ufs_notify_change_status status
)
1625 ret
= exynos_ufs_pre_link(hba
);
1628 ret
= exynos_ufs_post_link(hba
);
1635 static int exynos_ufs_pwr_change_notify(struct ufs_hba
*hba
,
1636 enum ufs_notify_change_status status
,
1637 struct ufs_pa_layer_attr
*dev_max_params
,
1638 struct ufs_pa_layer_attr
*dev_req_params
)
1644 ret
= exynos_ufs_pre_pwr_mode(hba
, dev_max_params
,
1648 ret
= exynos_ufs_post_pwr_mode(hba
, dev_req_params
);
1655 static void exynos_ufs_hibern8_notify(struct ufs_hba
*hba
,
1656 enum uic_cmd_dme cmd
,
1657 enum ufs_notify_change_status notify
)
1659 switch ((u8
)notify
) {
1661 exynos_ufs_pre_hibern8(hba
, cmd
);
1664 exynos_ufs_post_hibern8(hba
, cmd
);
1669 static int exynos_ufs_suspend(struct ufs_hba
*hba
, enum ufs_pm_op pm_op
,
1670 enum ufs_notify_change_status status
)
1672 struct exynos_ufs
*ufs
= ufshcd_get_variant(hba
);
1674 if (status
== PRE_CHANGE
)
1677 if (!ufshcd_is_link_active(hba
))
1678 phy_power_off(ufs
->phy
);
1683 static int exynos_ufs_resume(struct ufs_hba
*hba
, enum ufs_pm_op pm_op
)
1685 struct exynos_ufs
*ufs
= ufshcd_get_variant(hba
);
1687 if (!ufshcd_is_link_active(hba
))
1688 phy_power_on(ufs
->phy
);
1690 exynos_ufs_config_smu(ufs
);
1691 exynos_ufs_fmp_resume(hba
);
1695 static int exynosauto_ufs_vh_link_startup_notify(struct ufs_hba
*hba
,
1696 enum ufs_notify_change_status status
)
1698 if (status
== POST_CHANGE
) {
1699 ufshcd_set_link_active(hba
);
1700 ufshcd_set_ufs_dev_active(hba
);
1706 static int exynosauto_ufs_vh_wait_ph_ready(struct ufs_hba
*hba
)
1709 ktime_t start
, stop
;
1711 start
= ktime_get();
1712 stop
= ktime_add(start
, ms_to_ktime(PH_READY_TIMEOUT_MS
));
1715 mbox
= ufshcd_readl(hba
, PH2VH_MBOX
);
1716 /* TODO: Mailbox message protocols between the PH and VHs are
1717 * not implemented yet. This will be supported later
1719 if ((mbox
& MH_MSG_MASK
) == MH_MSG_PH_READY
)
1722 usleep_range(40, 50);
1723 } while (ktime_before(ktime_get(), stop
));
1728 static int exynosauto_ufs_vh_init(struct ufs_hba
*hba
)
1730 struct device
*dev
= hba
->dev
;
1731 struct platform_device
*pdev
= to_platform_device(dev
);
1732 struct exynos_ufs
*ufs
;
1735 ufs
= devm_kzalloc(dev
, sizeof(*ufs
), GFP_KERNEL
);
1739 /* exynos-specific hci */
1740 ufs
->reg_hci
= devm_platform_ioremap_resource_byname(pdev
, "vs_hci");
1741 if (IS_ERR(ufs
->reg_hci
)) {
1742 dev_err(dev
, "cannot ioremap for hci vendor register\n");
1743 return PTR_ERR(ufs
->reg_hci
);
1746 ret
= exynosauto_ufs_vh_wait_ph_ready(hba
);
1750 ufs
->drv_data
= device_get_match_data(dev
);
1754 exynos_ufs_priv_init(hba
, ufs
);
1759 static int fsd_ufs_pre_link(struct exynos_ufs
*ufs
)
1761 struct exynos_ufs_uic_attr
*attr
= ufs
->drv_data
->uic_attr
;
1762 struct ufs_hba
*hba
= ufs
->hba
;
1765 ufshcd_dme_set(hba
, UIC_ARG_MIB(attr
->pa_dbg_clk_period_off
),
1766 DIV_ROUND_UP(NSEC_PER_SEC
, ufs
->mclk_rate
));
1767 ufshcd_dme_set(hba
, UIC_ARG_MIB(0x201), 0x12);
1768 ufshcd_dme_set(hba
, UIC_ARG_MIB(0x200), 0x40);
1770 for_each_ufs_tx_lane(ufs
, i
) {
1771 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0xAA, i
),
1772 DIV_ROUND_UP(NSEC_PER_SEC
, ufs
->mclk_rate
));
1773 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x8F, i
), 0x3F);
1776 for_each_ufs_rx_lane(ufs
, i
) {
1777 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x12, i
),
1778 DIV_ROUND_UP(NSEC_PER_SEC
, ufs
->mclk_rate
));
1779 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x5C, i
), 0x38);
1780 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x0F, i
), 0x0);
1781 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x65, i
), 0x1);
1782 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x69, i
), 0x1);
1783 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x21, i
), 0x0);
1784 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x22, i
), 0x0);
1787 ufshcd_dme_set(hba
, UIC_ARG_MIB(0x200), 0x0);
1788 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_DBG_AUTOMODE_THLD
), 0x4E20);
1790 ufshcd_dme_set(hba
, UIC_ARG_MIB(attr
->pa_dbg_opt_suite1_off
),
1792 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_LOCAL_TX_LCC_ENABLE
), 0x0);
1794 exynos_ufs_establish_connt(ufs
);
1799 static int fsd_ufs_post_link(struct exynos_ufs
*ufs
)
1802 struct ufs_hba
*hba
= ufs
->hba
;
1803 u32 hw_cap_min_tactivate
;
1804 u32 peer_rx_min_actv_time_cap
;
1805 u32 max_rx_hibern8_time_cap
;
1807 ufshcd_dme_get(hba
, UIC_ARG_MIB_SEL(0x8F, 4),
1808 &hw_cap_min_tactivate
); /* HW Capability of MIN_TACTIVATE */
1809 ufshcd_dme_get(hba
, UIC_ARG_MIB(PA_TACTIVATE
),
1810 &peer_rx_min_actv_time_cap
); /* PA_TActivate */
1811 ufshcd_dme_get(hba
, UIC_ARG_MIB(PA_HIBERN8TIME
),
1812 &max_rx_hibern8_time_cap
); /* PA_Hibern8Time */
1814 if (peer_rx_min_actv_time_cap
>= hw_cap_min_tactivate
)
1815 ufshcd_dme_peer_set(hba
, UIC_ARG_MIB(PA_TACTIVATE
),
1816 peer_rx_min_actv_time_cap
+ 1);
1817 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_HIBERN8TIME
), max_rx_hibern8_time_cap
+ 1);
1819 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_DBG_MODE
), 0x01);
1820 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_SAVECONFIGTIME
), 0xFA);
1821 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_DBG_MODE
), 0x00);
1823 ufshcd_dme_set(hba
, UIC_ARG_MIB(0x200), 0x40);
1825 for_each_ufs_rx_lane(ufs
, i
) {
1826 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x35, i
), 0x05);
1827 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x73, i
), 0x01);
1828 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x41, i
), 0x02);
1829 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x42, i
), 0xAC);
1832 ufshcd_dme_set(hba
, UIC_ARG_MIB(0x200), 0x0);
1837 static int fsd_ufs_pre_pwr_change(struct exynos_ufs
*ufs
,
1838 struct ufs_pa_layer_attr
*pwr
)
1840 struct ufs_hba
*hba
= ufs
->hba
;
1842 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_TXTERMINATION
), 0x1);
1843 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_RXTERMINATION
), 0x1);
1844 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_PWRMODEUSERDATA0
), 12000);
1845 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_PWRMODEUSERDATA1
), 32000);
1846 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_PWRMODEUSERDATA2
), 16000);
1848 unipro_writel(ufs
, 12000, UNIPRO_DME_POWERMODE_REQ_REMOTEL2TIMER0
);
1849 unipro_writel(ufs
, 32000, UNIPRO_DME_POWERMODE_REQ_REMOTEL2TIMER1
);
1850 unipro_writel(ufs
, 16000, UNIPRO_DME_POWERMODE_REQ_REMOTEL2TIMER2
);
1855 static inline u32
get_mclk_period_unipro_18(struct exynos_ufs
*ufs
)
1857 return (16 * 1000 * 1000000UL / ufs
->mclk_rate
);
1860 static int gs101_ufs_pre_link(struct exynos_ufs
*ufs
)
1862 struct ufs_hba
*hba
= ufs
->hba
;
1864 u32 tx_line_reset_period
, rx_line_reset_period
;
1866 rx_line_reset_period
= (RX_LINE_RESET_TIME
* ufs
->mclk_rate
)
1868 tx_line_reset_period
= (TX_LINE_RESET_TIME
* ufs
->mclk_rate
)
1871 unipro_writel(ufs
, get_mclk_period_unipro_18(ufs
), COMP_CLK_PERIOD
);
1873 ufshcd_dme_set(hba
, UIC_ARG_MIB(0x200), 0x40);
1875 for_each_ufs_rx_lane(ufs
, i
) {
1876 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_RX_CLK_PRD
, i
),
1877 DIV_ROUND_UP(NSEC_PER_SEC
, ufs
->mclk_rate
));
1878 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_RX_CLK_PRD_EN
, i
), 0x0);
1879 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_RX_LINERESET_VALUE2
, i
),
1880 (rx_line_reset_period
>> 16) & 0xFF);
1881 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_RX_LINERESET_VALUE1
, i
),
1882 (rx_line_reset_period
>> 8) & 0xFF);
1883 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_RX_LINERESET_VALUE0
, i
),
1884 (rx_line_reset_period
) & 0xFF);
1885 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x2f, i
), 0x69);
1886 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x84, i
), 0x1);
1887 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x25, i
), 0xf6);
1890 for_each_ufs_tx_lane(ufs
, i
) {
1891 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_TX_CLK_PRD
, i
),
1892 DIV_ROUND_UP(NSEC_PER_SEC
, ufs
->mclk_rate
));
1893 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_TX_CLK_PRD_EN
, i
),
1895 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_TX_LINERESET_PVALUE2
, i
),
1896 (tx_line_reset_period
>> 16) & 0xFF);
1897 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_TX_LINERESET_PVALUE1
, i
),
1898 (tx_line_reset_period
>> 8) & 0xFF);
1899 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_TX_LINERESET_PVALUE0
, i
),
1900 (tx_line_reset_period
) & 0xFF);
1901 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x04, i
), 1);
1902 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x7F, i
), 0);
1905 ufshcd_dme_set(hba
, UIC_ARG_MIB(0x200), 0x0);
1906 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_LOCAL_TX_LCC_ENABLE
), 0x0);
1907 ufshcd_dme_set(hba
, UIC_ARG_MIB(N_DEVICEID
), 0x0);
1908 ufshcd_dme_set(hba
, UIC_ARG_MIB(N_DEVICEID_VALID
), 0x1);
1909 ufshcd_dme_set(hba
, UIC_ARG_MIB(T_PEERDEVICEID
), 0x1);
1910 ufshcd_dme_set(hba
, UIC_ARG_MIB(T_CONNECTIONSTATE
), CPORT_CONNECTED
);
1911 ufshcd_dme_set(hba
, UIC_ARG_MIB(0xA006), 0x8000);
1916 static int gs101_ufs_post_link(struct exynos_ufs
*ufs
)
1918 struct ufs_hba
*hba
= ufs
->hba
;
1921 * Enable Write Line Unique. This field has to be 0x3
1922 * to support Write Line Unique transaction on gs101.
1924 hci_writel(ufs
, WLU_EN
| WLU_BURST_LEN(3), HCI_AXIDMA_RWDATA_BURST_LEN
);
1926 exynos_ufs_enable_dbg_mode(hba
);
1927 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_SAVECONFIGTIME
), 0x3e8);
1928 exynos_ufs_disable_dbg_mode(hba
);
1933 static int gs101_ufs_pre_pwr_change(struct exynos_ufs
*ufs
,
1934 struct ufs_pa_layer_attr
*pwr
)
1936 struct ufs_hba
*hba
= ufs
->hba
;
1938 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_PWRMODEUSERDATA0
), 12000);
1939 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_PWRMODEUSERDATA1
), 32000);
1940 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_PWRMODEUSERDATA2
), 16000);
1941 unipro_writel(ufs
, 8064, UNIPRO_DME_POWERMODE_REQ_LOCALL2TIMER0
);
1942 unipro_writel(ufs
, 28224, UNIPRO_DME_POWERMODE_REQ_LOCALL2TIMER1
);
1943 unipro_writel(ufs
, 20160, UNIPRO_DME_POWERMODE_REQ_LOCALL2TIMER2
);
1944 unipro_writel(ufs
, 12000, UNIPRO_DME_POWERMODE_REQ_REMOTEL2TIMER0
);
1945 unipro_writel(ufs
, 32000, UNIPRO_DME_POWERMODE_REQ_REMOTEL2TIMER1
);
1946 unipro_writel(ufs
, 16000, UNIPRO_DME_POWERMODE_REQ_REMOTEL2TIMER2
);
1951 static const struct ufs_hba_variant_ops ufs_hba_exynos_ops
= {
1952 .name
= "exynos_ufs",
1953 .init
= exynos_ufs_init
,
1954 .hce_enable_notify
= exynos_ufs_hce_enable_notify
,
1955 .link_startup_notify
= exynos_ufs_link_startup_notify
,
1956 .pwr_change_notify
= exynos_ufs_pwr_change_notify
,
1957 .setup_clocks
= exynos_ufs_setup_clocks
,
1958 .setup_xfer_req
= exynos_ufs_specify_nexus_t_xfer_req
,
1959 .setup_task_mgmt
= exynos_ufs_specify_nexus_t_tm_req
,
1960 .hibern8_notify
= exynos_ufs_hibern8_notify
,
1961 .suspend
= exynos_ufs_suspend
,
1962 .resume
= exynos_ufs_resume
,
1963 .fill_crypto_prdt
= exynos_ufs_fmp_fill_prdt
,
1966 static struct ufs_hba_variant_ops ufs_hba_exynosauto_vh_ops
= {
1967 .name
= "exynosauto_ufs_vh",
1968 .init
= exynosauto_ufs_vh_init
,
1969 .link_startup_notify
= exynosauto_ufs_vh_link_startup_notify
,
1972 static int exynos_ufs_probe(struct platform_device
*pdev
)
1975 struct device
*dev
= &pdev
->dev
;
1976 const struct ufs_hba_variant_ops
*vops
= &ufs_hba_exynos_ops
;
1977 const struct exynos_ufs_drv_data
*drv_data
=
1978 device_get_match_data(dev
);
1980 if (drv_data
&& drv_data
->vops
)
1981 vops
= drv_data
->vops
;
1983 err
= ufshcd_pltfrm_init(pdev
, vops
);
1985 dev_err(dev
, "ufshcd_pltfrm_init() failed %d\n", err
);
1990 static void exynos_ufs_remove(struct platform_device
*pdev
)
1992 struct ufs_hba
*hba
= platform_get_drvdata(pdev
);
1993 struct exynos_ufs
*ufs
= ufshcd_get_variant(hba
);
1995 pm_runtime_get_sync(&(pdev
)->dev
);
1998 phy_power_off(ufs
->phy
);
2002 static struct exynos_ufs_uic_attr exynos7_uic_attr
= {
2003 .tx_trailingclks
= 0x10,
2004 .tx_dif_p_nsec
= 3000000, /* unit: ns */
2005 .tx_dif_n_nsec
= 1000000, /* unit: ns */
2006 .tx_high_z_cnt_nsec
= 20000, /* unit: ns */
2007 .tx_base_unit_nsec
= 100000, /* unit: ns */
2008 .tx_gran_unit_nsec
= 4000, /* unit: ns */
2009 .tx_sleep_cnt
= 1000, /* unit: ns */
2010 .tx_min_activatetime
= 0xa,
2011 .rx_filler_enable
= 0x2,
2012 .rx_dif_p_nsec
= 1000000, /* unit: ns */
2013 .rx_hibern8_wait_nsec
= 4000000, /* unit: ns */
2014 .rx_base_unit_nsec
= 100000, /* unit: ns */
2015 .rx_gran_unit_nsec
= 4000, /* unit: ns */
2016 .rx_sleep_cnt
= 1280, /* unit: ns */
2017 .rx_stall_cnt
= 320, /* unit: ns */
2018 .rx_hs_g1_sync_len_cap
= SYNC_LEN_COARSE(0xf),
2019 .rx_hs_g2_sync_len_cap
= SYNC_LEN_COARSE(0xf),
2020 .rx_hs_g3_sync_len_cap
= SYNC_LEN_COARSE(0xf),
2021 .rx_hs_g1_prep_sync_len_cap
= PREP_LEN(0xf),
2022 .rx_hs_g2_prep_sync_len_cap
= PREP_LEN(0xf),
2023 .rx_hs_g3_prep_sync_len_cap
= PREP_LEN(0xf),
2024 .pa_dbg_clk_period_off
= PA_DBG_CLK_PERIOD
,
2025 .pa_dbg_opt_suite1_val
= 0x30103,
2026 .pa_dbg_opt_suite1_off
= PA_DBG_OPTION_SUITE
,
2029 static const struct exynos_ufs_drv_data exynosauto_ufs_drvs
= {
2030 .uic_attr
= &exynos7_uic_attr
,
2031 .quirks
= UFSHCD_QUIRK_PRDT_BYTE_GRAN
|
2032 UFSHCI_QUIRK_SKIP_RESET_INTR_AGGR
|
2033 UFSHCD_QUIRK_BROKEN_OCS_FATAL_ERROR
|
2034 UFSHCD_QUIRK_SKIP_DEF_UNIPRO_TIMEOUT_SETTING
,
2035 .opts
= EXYNOS_UFS_OPT_BROKEN_AUTO_CLK_CTRL
|
2036 EXYNOS_UFS_OPT_SKIP_CONFIG_PHY_ATTR
|
2037 EXYNOS_UFS_OPT_BROKEN_RX_SEL_IDX
,
2038 .drv_init
= exynosauto_ufs_drv_init
,
2039 .post_hce_enable
= exynosauto_ufs_post_hce_enable
,
2040 .pre_link
= exynosauto_ufs_pre_link
,
2041 .pre_pwr_change
= exynosauto_ufs_pre_pwr_change
,
2042 .post_pwr_change
= exynosauto_ufs_post_pwr_change
,
2045 static const struct exynos_ufs_drv_data exynosauto_ufs_vh_drvs
= {
2046 .vops
= &ufs_hba_exynosauto_vh_ops
,
2047 .quirks
= UFSHCD_QUIRK_PRDT_BYTE_GRAN
|
2048 UFSHCI_QUIRK_SKIP_RESET_INTR_AGGR
|
2049 UFSHCD_QUIRK_BROKEN_OCS_FATAL_ERROR
|
2050 UFSHCI_QUIRK_BROKEN_HCE
|
2051 UFSHCD_QUIRK_BROKEN_UIC_CMD
|
2052 UFSHCD_QUIRK_SKIP_PH_CONFIGURATION
|
2053 UFSHCD_QUIRK_SKIP_DEF_UNIPRO_TIMEOUT_SETTING
,
2054 .opts
= EXYNOS_UFS_OPT_BROKEN_RX_SEL_IDX
,
2057 static const struct exynos_ufs_drv_data exynos_ufs_drvs
= {
2058 .uic_attr
= &exynos7_uic_attr
,
2059 .quirks
= UFSHCD_QUIRK_PRDT_BYTE_GRAN
|
2060 UFSHCI_QUIRK_BROKEN_REQ_LIST_CLR
|
2061 UFSHCI_QUIRK_BROKEN_HCE
|
2062 UFSHCI_QUIRK_SKIP_RESET_INTR_AGGR
|
2063 UFSHCD_QUIRK_BROKEN_OCS_FATAL_ERROR
|
2064 UFSHCI_QUIRK_SKIP_MANUAL_WB_FLUSH_CTRL
|
2065 UFSHCD_QUIRK_SKIP_DEF_UNIPRO_TIMEOUT_SETTING
,
2066 .opts
= EXYNOS_UFS_OPT_HAS_APB_CLK_CTRL
|
2067 EXYNOS_UFS_OPT_BROKEN_AUTO_CLK_CTRL
|
2068 EXYNOS_UFS_OPT_BROKEN_RX_SEL_IDX
|
2069 EXYNOS_UFS_OPT_SKIP_CONNECTION_ESTAB
|
2070 EXYNOS_UFS_OPT_USE_SW_HIBERN8_TIMER
,
2071 .pre_link
= exynos7_ufs_pre_link
,
2072 .post_link
= exynos7_ufs_post_link
,
2073 .pre_pwr_change
= exynos7_ufs_pre_pwr_change
,
2074 .post_pwr_change
= exynos7_ufs_post_pwr_change
,
2077 static struct exynos_ufs_uic_attr gs101_uic_attr
= {
2078 .tx_trailingclks
= 0xff,
2079 .pa_dbg_opt_suite1_val
= 0x90913C1C,
2080 .pa_dbg_opt_suite1_off
= PA_GS101_DBG_OPTION_SUITE1
,
2081 .pa_dbg_opt_suite2_val
= 0xE01C115F,
2082 .pa_dbg_opt_suite2_off
= PA_GS101_DBG_OPTION_SUITE2
,
2085 static struct exynos_ufs_uic_attr fsd_uic_attr
= {
2086 .tx_trailingclks
= 0x10,
2087 .tx_dif_p_nsec
= 3000000, /* unit: ns */
2088 .tx_dif_n_nsec
= 1000000, /* unit: ns */
2089 .tx_high_z_cnt_nsec
= 20000, /* unit: ns */
2090 .tx_base_unit_nsec
= 100000, /* unit: ns */
2091 .tx_gran_unit_nsec
= 4000, /* unit: ns */
2092 .tx_sleep_cnt
= 1000, /* unit: ns */
2093 .tx_min_activatetime
= 0xa,
2094 .rx_filler_enable
= 0x2,
2095 .rx_dif_p_nsec
= 1000000, /* unit: ns */
2096 .rx_hibern8_wait_nsec
= 4000000, /* unit: ns */
2097 .rx_base_unit_nsec
= 100000, /* unit: ns */
2098 .rx_gran_unit_nsec
= 4000, /* unit: ns */
2099 .rx_sleep_cnt
= 1280, /* unit: ns */
2100 .rx_stall_cnt
= 320, /* unit: ns */
2101 .rx_hs_g1_sync_len_cap
= SYNC_LEN_COARSE(0xf),
2102 .rx_hs_g2_sync_len_cap
= SYNC_LEN_COARSE(0xf),
2103 .rx_hs_g3_sync_len_cap
= SYNC_LEN_COARSE(0xf),
2104 .rx_hs_g1_prep_sync_len_cap
= PREP_LEN(0xf),
2105 .rx_hs_g2_prep_sync_len_cap
= PREP_LEN(0xf),
2106 .rx_hs_g3_prep_sync_len_cap
= PREP_LEN(0xf),
2107 .pa_dbg_clk_period_off
= PA_DBG_CLK_PERIOD
,
2108 .pa_dbg_opt_suite1_val
= 0x2E820183,
2109 .pa_dbg_opt_suite1_off
= PA_DBG_OPTION_SUITE
,
2112 static const struct exynos_ufs_drv_data fsd_ufs_drvs
= {
2113 .uic_attr
= &fsd_uic_attr
,
2114 .quirks
= UFSHCD_QUIRK_PRDT_BYTE_GRAN
|
2115 UFSHCI_QUIRK_BROKEN_REQ_LIST_CLR
|
2116 UFSHCD_QUIRK_BROKEN_OCS_FATAL_ERROR
|
2117 UFSHCD_QUIRK_SKIP_DEF_UNIPRO_TIMEOUT_SETTING
|
2118 UFSHCI_QUIRK_SKIP_RESET_INTR_AGGR
,
2119 .opts
= EXYNOS_UFS_OPT_HAS_APB_CLK_CTRL
|
2120 EXYNOS_UFS_OPT_BROKEN_AUTO_CLK_CTRL
|
2121 EXYNOS_UFS_OPT_SKIP_CONFIG_PHY_ATTR
|
2122 EXYNOS_UFS_OPT_BROKEN_RX_SEL_IDX
,
2123 .pre_link
= fsd_ufs_pre_link
,
2124 .post_link
= fsd_ufs_post_link
,
2125 .pre_pwr_change
= fsd_ufs_pre_pwr_change
,
2128 static const struct exynos_ufs_drv_data gs101_ufs_drvs
= {
2129 .uic_attr
= &gs101_uic_attr
,
2130 .quirks
= UFSHCD_QUIRK_PRDT_BYTE_GRAN
|
2131 UFSHCI_QUIRK_SKIP_RESET_INTR_AGGR
|
2132 UFSHCI_QUIRK_BROKEN_REQ_LIST_CLR
|
2133 UFSHCD_QUIRK_BROKEN_OCS_FATAL_ERROR
|
2134 UFSHCI_QUIRK_SKIP_MANUAL_WB_FLUSH_CTRL
|
2135 UFSHCD_QUIRK_SKIP_DEF_UNIPRO_TIMEOUT_SETTING
,
2136 .opts
= EXYNOS_UFS_OPT_SKIP_CONFIG_PHY_ATTR
|
2137 EXYNOS_UFS_OPT_UFSPR_SECURE
|
2138 EXYNOS_UFS_OPT_TIMER_TICK_SELECT
,
2139 .drv_init
= gs101_ufs_drv_init
,
2140 .pre_link
= gs101_ufs_pre_link
,
2141 .post_link
= gs101_ufs_post_link
,
2142 .pre_pwr_change
= gs101_ufs_pre_pwr_change
,
2145 static const struct of_device_id exynos_ufs_of_match
[] = {
2146 { .compatible
= "google,gs101-ufs",
2147 .data
= &gs101_ufs_drvs
},
2148 { .compatible
= "samsung,exynos7-ufs",
2149 .data
= &exynos_ufs_drvs
},
2150 { .compatible
= "samsung,exynosautov9-ufs",
2151 .data
= &exynosauto_ufs_drvs
},
2152 { .compatible
= "samsung,exynosautov9-ufs-vh",
2153 .data
= &exynosauto_ufs_vh_drvs
},
2154 { .compatible
= "tesla,fsd-ufs",
2155 .data
= &fsd_ufs_drvs
},
2158 MODULE_DEVICE_TABLE(of
, exynos_ufs_of_match
);
2160 static const struct dev_pm_ops exynos_ufs_pm_ops
= {
2161 SET_SYSTEM_SLEEP_PM_OPS(ufshcd_system_suspend
, ufshcd_system_resume
)
2162 SET_RUNTIME_PM_OPS(ufshcd_runtime_suspend
, ufshcd_runtime_resume
, NULL
)
2163 .prepare
= ufshcd_suspend_prepare
,
2164 .complete
= ufshcd_resume_complete
,
2167 static struct platform_driver exynos_ufs_pltform
= {
2168 .probe
= exynos_ufs_probe
,
2169 .remove
= exynos_ufs_remove
,
2171 .name
= "exynos-ufshc",
2172 .pm
= &exynos_ufs_pm_ops
,
2173 .of_match_table
= exynos_ufs_of_match
,
2176 module_platform_driver(exynos_ufs_pltform
);
2178 MODULE_AUTHOR("Alim Akhtar <alim.akhtar@samsung.com>");
2179 MODULE_AUTHOR("Seungwon Jeon <essuuj@gmail.com>");
2180 MODULE_DESCRIPTION("Exynos UFS HCI Driver");
2181 MODULE_LICENSE("GPL v2");