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 HCI_GPIO_OUT 0x70
52 #define HCI_ERR_EN_PA_LAYER 0x78
53 #define HCI_ERR_EN_DL_LAYER 0x7C
54 #define HCI_ERR_EN_N_LAYER 0x80
55 #define HCI_ERR_EN_T_LAYER 0x84
56 #define HCI_ERR_EN_DME_LAYER 0x88
57 #define HCI_V2P1_CTRL 0x8C
58 #define IA_TICK_SEL BIT(16)
59 #define HCI_CLKSTOP_CTRL 0xB0
60 #define REFCLKOUT_STOP BIT(4)
61 #define MPHY_APBCLK_STOP BIT(3)
62 #define REFCLK_STOP BIT(2)
63 #define UNIPRO_MCLK_STOP BIT(1)
64 #define UNIPRO_PCLK_STOP BIT(0)
65 #define CLK_STOP_MASK (REFCLKOUT_STOP | REFCLK_STOP |\
66 UNIPRO_MCLK_STOP | MPHY_APBCLK_STOP|\
68 /* HCI_MISC is also known as HCI_FORCE_HCS */
70 #define REFCLK_CTRL_EN BIT(7)
71 #define UNIPRO_PCLK_CTRL_EN BIT(6)
72 #define UNIPRO_MCLK_CTRL_EN BIT(5)
73 #define HCI_CORECLK_CTRL_EN BIT(4)
74 #define CLK_CTRL_EN_MASK (REFCLK_CTRL_EN |\
75 UNIPRO_PCLK_CTRL_EN |\
77 /* Device fatal error */
78 #define DFES_ERR_EN BIT(31)
79 #define DFES_DEF_L2_ERRS (UIC_DATA_LINK_LAYER_ERROR_RX_BUF_OF |\
80 UIC_DATA_LINK_LAYER_ERROR_PA_INIT)
81 #define DFES_DEF_L3_ERRS (UIC_NETWORK_UNSUPPORTED_HEADER_TYPE |\
82 UIC_NETWORK_BAD_DEVICEID_ENC |\
83 UIC_NETWORK_LHDR_TRAP_PACKET_DROPPING)
84 #define DFES_DEF_L4_ERRS (UIC_TRANSPORT_UNSUPPORTED_HEADER_TYPE |\
85 UIC_TRANSPORT_UNKNOWN_CPORTID |\
86 UIC_TRANSPORT_NO_CONNECTION_RX |\
89 /* FSYS UFS Shareability */
90 #define UFS_WR_SHARABLE BIT(2)
91 #define UFS_RD_SHARABLE BIT(1)
92 #define UFS_SHARABLE (UFS_WR_SHARABLE | UFS_RD_SHARABLE)
93 #define UFS_SHAREABILITY_OFFSET 0x710
95 /* Multi-host registers */
97 #define MHCTRL_EN_VH_MASK (0xE)
98 #define MHCTRL_EN_VH(vh) (vh << 1)
99 #define PH2VH_MBOX 0xD8
101 #define MH_MSG_MASK (0xFF)
103 #define MH_MSG(id, msg) ((id << 8) | (msg & 0xFF))
104 #define MH_MSG_PH_READY 0x1
105 #define MH_MSG_VH_READY 0x2
107 #define ALLOW_INQUIRY BIT(25)
108 #define ALLOW_MODE_SELECT BIT(24)
109 #define ALLOW_MODE_SENSE BIT(23)
110 #define ALLOW_PRE_FETCH GENMASK(22, 21)
111 #define ALLOW_READ_CMD_ALL GENMASK(20, 18) /* read_6/10/16 */
112 #define ALLOW_READ_BUFFER BIT(17)
113 #define ALLOW_READ_CAPACITY GENMASK(16, 15)
114 #define ALLOW_REPORT_LUNS BIT(14)
115 #define ALLOW_REQUEST_SENSE BIT(13)
116 #define ALLOW_SYNCHRONIZE_CACHE GENMASK(8, 7)
117 #define ALLOW_TEST_UNIT_READY BIT(6)
118 #define ALLOW_UNMAP BIT(5)
119 #define ALLOW_VERIFY BIT(4)
120 #define ALLOW_WRITE_CMD_ALL GENMASK(3, 1) /* write_6/10/16 */
122 #define ALLOW_TRANS_VH_DEFAULT (ALLOW_INQUIRY | ALLOW_MODE_SELECT | \
123 ALLOW_MODE_SENSE | ALLOW_PRE_FETCH | \
124 ALLOW_READ_CMD_ALL | ALLOW_READ_BUFFER | \
125 ALLOW_READ_CAPACITY | ALLOW_REPORT_LUNS | \
126 ALLOW_REQUEST_SENSE | ALLOW_SYNCHRONIZE_CACHE | \
127 ALLOW_TEST_UNIT_READY | ALLOW_UNMAP | \
128 ALLOW_VERIFY | ALLOW_WRITE_CMD_ALL)
130 #define HCI_MH_ALLOWABLE_TRAN_OF_VH 0x30C
131 #define HCI_MH_IID_IN_TASK_TAG 0X308
133 #define PH_READY_TIMEOUT_MS (5 * MSEC_PER_SEC)
136 UNIPRO_L1_5
= 0,/* PHY Adapter */
137 UNIPRO_L2
, /* Data Link */
138 UNIPRO_L3
, /* Network */
139 UNIPRO_L4
, /* Transport */
140 UNIPRO_DME
, /* DME */
146 #define UNIPRO_DME_POWERMODE_REQ_LOCALL2TIMER0 0x7888
147 #define UNIPRO_DME_POWERMODE_REQ_LOCALL2TIMER1 0x788c
148 #define UNIPRO_DME_POWERMODE_REQ_LOCALL2TIMER2 0x7890
149 #define UNIPRO_DME_POWERMODE_REQ_REMOTEL2TIMER0 0x78B8
150 #define UNIPRO_DME_POWERMODE_REQ_REMOTEL2TIMER1 0x78BC
151 #define UNIPRO_DME_POWERMODE_REQ_REMOTEL2TIMER2 0x78C0
154 * UFS Protector registers
156 #define UFSPRSECURITY 0x010
157 #define NSSMU BIT(14)
158 #define UFSPSBEGIN0 0x200
159 #define UFSPSEND0 0x204
160 #define UFSPSLUN0 0x208
161 #define UFSPSCTRL0 0x20C
163 #define CNTR_DIV_VAL 40
165 static void exynos_ufs_auto_ctrl_hcc(struct exynos_ufs
*ufs
, bool en
);
166 static void exynos_ufs_ctrl_clkstop(struct exynos_ufs
*ufs
, bool en
);
168 static inline void exynos_ufs_enable_auto_ctrl_hcc(struct exynos_ufs
*ufs
)
170 exynos_ufs_auto_ctrl_hcc(ufs
, true);
173 static inline void exynos_ufs_disable_auto_ctrl_hcc(struct exynos_ufs
*ufs
)
175 exynos_ufs_auto_ctrl_hcc(ufs
, false);
178 static inline void exynos_ufs_disable_auto_ctrl_hcc_save(
179 struct exynos_ufs
*ufs
, u32
*val
)
181 *val
= hci_readl(ufs
, HCI_MISC
);
182 exynos_ufs_auto_ctrl_hcc(ufs
, false);
185 static inline void exynos_ufs_auto_ctrl_hcc_restore(
186 struct exynos_ufs
*ufs
, u32
*val
)
188 hci_writel(ufs
, *val
, HCI_MISC
);
191 static inline void exynos_ufs_gate_clks(struct exynos_ufs
*ufs
)
193 exynos_ufs_ctrl_clkstop(ufs
, true);
196 static inline void exynos_ufs_ungate_clks(struct exynos_ufs
*ufs
)
198 exynos_ufs_ctrl_clkstop(ufs
, false);
201 static int exynos7_ufs_drv_init(struct device
*dev
, struct exynos_ufs
*ufs
)
206 static int exynosauto_ufs_drv_init(struct device
*dev
, struct exynos_ufs
*ufs
)
208 struct exynos_ufs_uic_attr
*attr
= ufs
->drv_data
->uic_attr
;
210 /* IO Coherency setting */
212 return regmap_update_bits(ufs
->sysreg
,
213 ufs
->shareability_reg_offset
,
214 UFS_SHARABLE
, UFS_SHARABLE
);
217 attr
->tx_dif_p_nsec
= 3200000;
222 static int exynosauto_ufs_post_hce_enable(struct exynos_ufs
*ufs
)
224 struct ufs_hba
*hba
= ufs
->hba
;
226 /* Enable Virtual Host #1 */
227 ufshcd_rmwl(hba
, MHCTRL_EN_VH_MASK
, MHCTRL_EN_VH(1), MHCTRL
);
228 /* Default VH Transfer permissions */
229 hci_writel(ufs
, ALLOW_TRANS_VH_DEFAULT
, HCI_MH_ALLOWABLE_TRAN_OF_VH
);
230 /* IID information is replaced in TASKTAG[7:5] instead of IID in UCD */
231 hci_writel(ufs
, 0x1, HCI_MH_IID_IN_TASK_TAG
);
236 static int exynosauto_ufs_pre_link(struct exynos_ufs
*ufs
)
238 struct ufs_hba
*hba
= ufs
->hba
;
240 u32 tx_line_reset_period
, rx_line_reset_period
;
242 rx_line_reset_period
= (RX_LINE_RESET_TIME
* ufs
->mclk_rate
) / NSEC_PER_MSEC
;
243 tx_line_reset_period
= (TX_LINE_RESET_TIME
* ufs
->mclk_rate
) / NSEC_PER_MSEC
;
245 ufshcd_dme_set(hba
, UIC_ARG_MIB(0x200), 0x40);
246 for_each_ufs_rx_lane(ufs
, i
) {
247 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_RX_CLK_PRD
, i
),
248 DIV_ROUND_UP(NSEC_PER_SEC
, ufs
->mclk_rate
));
249 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_RX_CLK_PRD_EN
, i
), 0x0);
251 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_RX_LINERESET_VALUE2
, i
),
252 (rx_line_reset_period
>> 16) & 0xFF);
253 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_RX_LINERESET_VALUE1
, i
),
254 (rx_line_reset_period
>> 8) & 0xFF);
255 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_RX_LINERESET_VALUE0
, i
),
256 (rx_line_reset_period
) & 0xFF);
258 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x2f, i
), 0x79);
259 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x84, i
), 0x1);
260 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x25, i
), 0xf6);
263 for_each_ufs_tx_lane(ufs
, i
) {
264 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_TX_CLK_PRD
, i
),
265 DIV_ROUND_UP(NSEC_PER_SEC
, ufs
->mclk_rate
));
266 /* Not to affect VND_TX_LINERESET_PVALUE to VND_TX_CLK_PRD */
267 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_TX_CLK_PRD_EN
, i
),
270 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_TX_LINERESET_PVALUE2
, i
),
271 (tx_line_reset_period
>> 16) & 0xFF);
272 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_TX_LINERESET_PVALUE1
, i
),
273 (tx_line_reset_period
>> 8) & 0xFF);
274 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_TX_LINERESET_PVALUE0
, i
),
275 (tx_line_reset_period
) & 0xFF);
277 /* TX PWM Gear Capability / PWM_G1_ONLY */
278 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x04, i
), 0x1);
281 ufshcd_dme_set(hba
, UIC_ARG_MIB(0x200), 0x0);
283 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_LOCAL_TX_LCC_ENABLE
), 0x0);
285 ufshcd_dme_set(hba
, UIC_ARG_MIB(0xa011), 0x8000);
290 static int exynosauto_ufs_pre_pwr_change(struct exynos_ufs
*ufs
,
291 struct ufs_pa_layer_attr
*pwr
)
293 struct ufs_hba
*hba
= ufs
->hba
;
295 /* PACP_PWR_req and delivered to the remote DME */
296 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_PWRMODEUSERDATA0
), 12000);
297 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_PWRMODEUSERDATA1
), 32000);
298 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_PWRMODEUSERDATA2
), 16000);
303 static int exynosauto_ufs_post_pwr_change(struct exynos_ufs
*ufs
,
304 struct ufs_pa_layer_attr
*pwr
)
306 struct ufs_hba
*hba
= ufs
->hba
;
309 enabled_vh
= ufshcd_readl(hba
, MHCTRL
) & MHCTRL_EN_VH_MASK
;
311 /* Send physical host ready message to virtual hosts */
312 ufshcd_writel(hba
, MH_MSG(enabled_vh
, MH_MSG_PH_READY
), PH2VH_MBOX
);
317 static int exynos7_ufs_pre_link(struct exynos_ufs
*ufs
)
319 struct exynos_ufs_uic_attr
*attr
= ufs
->drv_data
->uic_attr
;
320 u32 val
= attr
->pa_dbg_opt_suite1_val
;
321 struct ufs_hba
*hba
= ufs
->hba
;
324 exynos_ufs_enable_ov_tm(hba
);
325 for_each_ufs_tx_lane(ufs
, i
)
326 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x297, i
), 0x17);
327 for_each_ufs_rx_lane(ufs
, i
) {
328 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x362, i
), 0xff);
329 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x363, i
), 0x00);
331 exynos_ufs_disable_ov_tm(hba
);
333 for_each_ufs_tx_lane(ufs
, i
)
335 UIC_ARG_MIB_SEL(TX_HIBERN8_CONTROL
, i
), 0x0);
336 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_DBG_TXPHY_CFGUPDT
), 0x1);
338 ufshcd_dme_set(hba
, UIC_ARG_MIB(attr
->pa_dbg_opt_suite1_off
),
340 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_DBG_SKIP_RESET_PHY
), 0x1);
341 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_DBG_SKIP_LINE_RESET
), 0x1);
342 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_DBG_LINE_RESET_REQ
), 0x1);
344 ufshcd_dme_set(hba
, UIC_ARG_MIB(attr
->pa_dbg_opt_suite1_off
), val
);
349 static int exynos7_ufs_post_link(struct exynos_ufs
*ufs
)
351 struct ufs_hba
*hba
= ufs
->hba
;
354 exynos_ufs_enable_ov_tm(hba
);
355 for_each_ufs_tx_lane(ufs
, i
) {
356 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x28b, i
), 0x83);
357 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x29a, i
), 0x07);
358 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x277, i
),
359 TX_LINERESET_N(exynos_ufs_calc_time_cntr(ufs
, 200000)));
361 exynos_ufs_disable_ov_tm(hba
);
363 exynos_ufs_enable_dbg_mode(hba
);
364 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_SAVECONFIGTIME
), 0xbb8);
365 exynos_ufs_disable_dbg_mode(hba
);
370 static int exynos7_ufs_pre_pwr_change(struct exynos_ufs
*ufs
,
371 struct ufs_pa_layer_attr
*pwr
)
373 unipro_writel(ufs
, 0x22, UNIPRO_DBG_FORCE_DME_CTRL_STATE
);
378 static int exynos7_ufs_post_pwr_change(struct exynos_ufs
*ufs
,
379 struct ufs_pa_layer_attr
*pwr
)
381 struct ufs_hba
*hba
= ufs
->hba
;
382 int lanes
= max_t(u32
, pwr
->lane_rx
, pwr
->lane_tx
);
384 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_DBG_RXPHY_CFGUPDT
), 0x1);
387 exynos_ufs_enable_dbg_mode(hba
);
388 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_CONNECTEDTXDATALANES
), 0x1);
389 exynos_ufs_disable_dbg_mode(hba
);
396 * exynos_ufs_auto_ctrl_hcc - HCI core clock control by h/w
397 * Control should be disabled in the below cases
398 * - Before host controller S/W reset
399 * - Access to UFS protector's register
401 static void exynos_ufs_auto_ctrl_hcc(struct exynos_ufs
*ufs
, bool en
)
403 u32 misc
= hci_readl(ufs
, HCI_MISC
);
406 hci_writel(ufs
, misc
| HCI_CORECLK_CTRL_EN
, HCI_MISC
);
408 hci_writel(ufs
, misc
& ~HCI_CORECLK_CTRL_EN
, HCI_MISC
);
411 static void exynos_ufs_ctrl_clkstop(struct exynos_ufs
*ufs
, bool en
)
413 u32 ctrl
= hci_readl(ufs
, HCI_CLKSTOP_CTRL
);
414 u32 misc
= hci_readl(ufs
, HCI_MISC
);
417 hci_writel(ufs
, misc
| CLK_CTRL_EN_MASK
, HCI_MISC
);
418 hci_writel(ufs
, ctrl
| CLK_STOP_MASK
, HCI_CLKSTOP_CTRL
);
420 hci_writel(ufs
, ctrl
& ~CLK_STOP_MASK
, HCI_CLKSTOP_CTRL
);
421 hci_writel(ufs
, misc
& ~CLK_CTRL_EN_MASK
, HCI_MISC
);
425 static int exynos_ufs_get_clk_info(struct exynos_ufs
*ufs
)
427 struct ufs_hba
*hba
= ufs
->hba
;
428 struct list_head
*head
= &hba
->clk_list_head
;
429 struct ufs_clk_info
*clki
;
430 unsigned long pclk_rate
;
435 if (list_empty(head
))
438 list_for_each_entry(clki
, head
, list
) {
439 if (!IS_ERR(clki
->clk
)) {
440 if (!strcmp(clki
->name
, "core_clk"))
441 ufs
->clk_hci_core
= clki
->clk
;
442 else if (!strcmp(clki
->name
, "sclk_unipro_main"))
443 ufs
->clk_unipro_main
= clki
->clk
;
447 if (!ufs
->clk_hci_core
|| !ufs
->clk_unipro_main
) {
448 dev_err(hba
->dev
, "failed to get clk info\n");
453 ufs
->mclk_rate
= clk_get_rate(ufs
->clk_unipro_main
);
454 pclk_rate
= clk_get_rate(ufs
->clk_hci_core
);
455 f_min
= ufs
->pclk_avail_min
;
456 f_max
= ufs
->pclk_avail_max
;
458 if (ufs
->opts
& EXYNOS_UFS_OPT_HAS_APB_CLK_CTRL
) {
460 pclk_rate
/= (div
+ 1);
462 if (pclk_rate
<= f_max
)
465 } while (pclk_rate
>= f_min
);
468 if (unlikely(pclk_rate
< f_min
|| pclk_rate
> f_max
)) {
469 dev_err(hba
->dev
, "not available pclk range %lu\n", pclk_rate
);
474 ufs
->pclk_rate
= pclk_rate
;
481 static void exynos_ufs_set_unipro_pclk_div(struct exynos_ufs
*ufs
)
483 if (ufs
->opts
& EXYNOS_UFS_OPT_HAS_APB_CLK_CTRL
) {
486 val
= hci_readl(ufs
, HCI_UNIPRO_APB_CLK_CTRL
);
487 hci_writel(ufs
, UNIPRO_APB_CLK(val
, ufs
->pclk_div
),
488 HCI_UNIPRO_APB_CLK_CTRL
);
492 static void exynos_ufs_set_pwm_clk_div(struct exynos_ufs
*ufs
)
494 struct ufs_hba
*hba
= ufs
->hba
;
495 struct exynos_ufs_uic_attr
*attr
= ufs
->drv_data
->uic_attr
;
498 UIC_ARG_MIB(CMN_PWM_CLK_CTRL
), attr
->cmn_pwm_clk_ctrl
);
501 static void exynos_ufs_calc_pwm_clk_div(struct exynos_ufs
*ufs
)
503 struct ufs_hba
*hba
= ufs
->hba
;
504 struct exynos_ufs_uic_attr
*attr
= ufs
->drv_data
->uic_attr
;
505 const unsigned int div
= 30, mult
= 20;
506 const unsigned long pwm_min
= 3 * 1000 * 1000;
507 const unsigned long pwm_max
= 9 * 1000 * 1000;
508 const int divs
[] = {32, 16, 8, 4};
509 unsigned long clk
= 0, _clk
, clk_period
;
510 int i
= 0, clk_idx
= -1;
512 clk_period
= UNIPRO_PCLK_PERIOD(ufs
);
513 for (i
= 0; i
< ARRAY_SIZE(divs
); i
++) {
514 _clk
= NSEC_PER_SEC
* mult
/ (clk_period
* divs
[i
] * div
);
515 if (_clk
>= pwm_min
&& _clk
<= pwm_max
) {
524 ufshcd_dme_get(hba
, UIC_ARG_MIB(CMN_PWM_CLK_CTRL
), &clk_idx
);
526 "failed to decide pwm clock divider, will not change\n");
529 attr
->cmn_pwm_clk_ctrl
= clk_idx
& PWM_CLK_CTRL_MASK
;
532 long exynos_ufs_calc_time_cntr(struct exynos_ufs
*ufs
, long period
)
534 const int precise
= 10;
535 long pclk_rate
= ufs
->pclk_rate
;
536 long clk_period
, fraction
;
538 clk_period
= UNIPRO_PCLK_PERIOD(ufs
);
539 fraction
= ((NSEC_PER_SEC
% pclk_rate
) * precise
) / pclk_rate
;
541 return (period
* precise
) / ((clk_period
* precise
) + fraction
);
544 static void exynos_ufs_specify_phy_time_attr(struct exynos_ufs
*ufs
)
546 struct exynos_ufs_uic_attr
*attr
= ufs
->drv_data
->uic_attr
;
547 struct ufs_phy_time_cfg
*t_cfg
= &ufs
->t_cfg
;
549 t_cfg
->tx_linereset_p
=
550 exynos_ufs_calc_time_cntr(ufs
, attr
->tx_dif_p_nsec
);
551 t_cfg
->tx_linereset_n
=
552 exynos_ufs_calc_time_cntr(ufs
, attr
->tx_dif_n_nsec
);
553 t_cfg
->tx_high_z_cnt
=
554 exynos_ufs_calc_time_cntr(ufs
, attr
->tx_high_z_cnt_nsec
);
555 t_cfg
->tx_base_n_val
=
556 exynos_ufs_calc_time_cntr(ufs
, attr
->tx_base_unit_nsec
);
557 t_cfg
->tx_gran_n_val
=
558 exynos_ufs_calc_time_cntr(ufs
, attr
->tx_gran_unit_nsec
);
559 t_cfg
->tx_sleep_cnt
=
560 exynos_ufs_calc_time_cntr(ufs
, attr
->tx_sleep_cnt
);
562 t_cfg
->rx_linereset
=
563 exynos_ufs_calc_time_cntr(ufs
, attr
->rx_dif_p_nsec
);
564 t_cfg
->rx_hibern8_wait
=
565 exynos_ufs_calc_time_cntr(ufs
, attr
->rx_hibern8_wait_nsec
);
566 t_cfg
->rx_base_n_val
=
567 exynos_ufs_calc_time_cntr(ufs
, attr
->rx_base_unit_nsec
);
568 t_cfg
->rx_gran_n_val
=
569 exynos_ufs_calc_time_cntr(ufs
, attr
->rx_gran_unit_nsec
);
570 t_cfg
->rx_sleep_cnt
=
571 exynos_ufs_calc_time_cntr(ufs
, attr
->rx_sleep_cnt
);
572 t_cfg
->rx_stall_cnt
=
573 exynos_ufs_calc_time_cntr(ufs
, attr
->rx_stall_cnt
);
576 static void exynos_ufs_config_phy_time_attr(struct exynos_ufs
*ufs
)
578 struct ufs_hba
*hba
= ufs
->hba
;
579 struct ufs_phy_time_cfg
*t_cfg
= &ufs
->t_cfg
;
582 exynos_ufs_set_pwm_clk_div(ufs
);
584 exynos_ufs_enable_ov_tm(hba
);
586 for_each_ufs_rx_lane(ufs
, i
) {
587 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(RX_FILLER_ENABLE
, i
),
588 ufs
->drv_data
->uic_attr
->rx_filler_enable
);
589 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(RX_LINERESET_VAL
, i
),
590 RX_LINERESET(t_cfg
->rx_linereset
));
591 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(RX_BASE_NVAL_07_00
, i
),
592 RX_BASE_NVAL_L(t_cfg
->rx_base_n_val
));
593 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(RX_BASE_NVAL_15_08
, i
),
594 RX_BASE_NVAL_H(t_cfg
->rx_base_n_val
));
595 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(RX_GRAN_NVAL_07_00
, i
),
596 RX_GRAN_NVAL_L(t_cfg
->rx_gran_n_val
));
597 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(RX_GRAN_NVAL_10_08
, i
),
598 RX_GRAN_NVAL_H(t_cfg
->rx_gran_n_val
));
599 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(RX_OV_SLEEP_CNT_TIMER
, i
),
600 RX_OV_SLEEP_CNT(t_cfg
->rx_sleep_cnt
));
601 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(RX_OV_STALL_CNT_TIMER
, i
),
602 RX_OV_STALL_CNT(t_cfg
->rx_stall_cnt
));
605 for_each_ufs_tx_lane(ufs
, i
) {
606 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(TX_LINERESET_P_VAL
, i
),
607 TX_LINERESET_P(t_cfg
->tx_linereset_p
));
608 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(TX_HIGH_Z_CNT_07_00
, i
),
609 TX_HIGH_Z_CNT_L(t_cfg
->tx_high_z_cnt
));
610 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(TX_HIGH_Z_CNT_11_08
, i
),
611 TX_HIGH_Z_CNT_H(t_cfg
->tx_high_z_cnt
));
612 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(TX_BASE_NVAL_07_00
, i
),
613 TX_BASE_NVAL_L(t_cfg
->tx_base_n_val
));
614 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(TX_BASE_NVAL_15_08
, i
),
615 TX_BASE_NVAL_H(t_cfg
->tx_base_n_val
));
616 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(TX_GRAN_NVAL_07_00
, i
),
617 TX_GRAN_NVAL_L(t_cfg
->tx_gran_n_val
));
618 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(TX_GRAN_NVAL_10_08
, i
),
619 TX_GRAN_NVAL_H(t_cfg
->tx_gran_n_val
));
620 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(TX_OV_SLEEP_CNT_TIMER
, i
),
622 TX_OV_SLEEP_CNT(t_cfg
->tx_sleep_cnt
));
623 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(TX_MIN_ACTIVATETIME
, i
),
624 ufs
->drv_data
->uic_attr
->tx_min_activatetime
);
627 exynos_ufs_disable_ov_tm(hba
);
630 static void exynos_ufs_config_phy_cap_attr(struct exynos_ufs
*ufs
)
632 struct ufs_hba
*hba
= ufs
->hba
;
633 struct exynos_ufs_uic_attr
*attr
= ufs
->drv_data
->uic_attr
;
636 exynos_ufs_enable_ov_tm(hba
);
638 for_each_ufs_rx_lane(ufs
, i
) {
640 UIC_ARG_MIB_SEL(RX_HS_G1_SYNC_LENGTH_CAP
, i
),
641 attr
->rx_hs_g1_sync_len_cap
);
643 UIC_ARG_MIB_SEL(RX_HS_G2_SYNC_LENGTH_CAP
, i
),
644 attr
->rx_hs_g2_sync_len_cap
);
646 UIC_ARG_MIB_SEL(RX_HS_G3_SYNC_LENGTH_CAP
, i
),
647 attr
->rx_hs_g3_sync_len_cap
);
649 UIC_ARG_MIB_SEL(RX_HS_G1_PREP_LENGTH_CAP
, i
),
650 attr
->rx_hs_g1_prep_sync_len_cap
);
652 UIC_ARG_MIB_SEL(RX_HS_G2_PREP_LENGTH_CAP
, i
),
653 attr
->rx_hs_g2_prep_sync_len_cap
);
655 UIC_ARG_MIB_SEL(RX_HS_G3_PREP_LENGTH_CAP
, i
),
656 attr
->rx_hs_g3_prep_sync_len_cap
);
659 if (attr
->rx_adv_fine_gran_sup_en
== 0) {
660 for_each_ufs_rx_lane(ufs
, i
) {
662 UIC_ARG_MIB_SEL(RX_ADV_GRANULARITY_CAP
, i
), 0);
664 if (attr
->rx_min_actv_time_cap
)
667 RX_MIN_ACTIVATETIME_CAPABILITY
, i
),
668 attr
->rx_min_actv_time_cap
);
670 if (attr
->rx_hibern8_time_cap
)
672 UIC_ARG_MIB_SEL(RX_HIBERN8TIME_CAP
, i
),
673 attr
->rx_hibern8_time_cap
);
675 } else if (attr
->rx_adv_fine_gran_sup_en
== 1) {
676 for_each_ufs_rx_lane(ufs
, i
) {
677 if (attr
->rx_adv_fine_gran_step
)
679 UIC_ARG_MIB_SEL(RX_ADV_GRANULARITY_CAP
,
680 i
), RX_ADV_FINE_GRAN_STEP(
681 attr
->rx_adv_fine_gran_step
));
683 if (attr
->rx_adv_min_actv_time_cap
)
686 RX_ADV_MIN_ACTIVATETIME_CAP
, i
),
687 attr
->rx_adv_min_actv_time_cap
);
689 if (attr
->rx_adv_hibern8_time_cap
)
691 UIC_ARG_MIB_SEL(RX_ADV_HIBERN8TIME_CAP
,
693 attr
->rx_adv_hibern8_time_cap
);
697 exynos_ufs_disable_ov_tm(hba
);
700 static void exynos_ufs_establish_connt(struct exynos_ufs
*ufs
)
702 struct ufs_hba
*hba
= ufs
->hba
;
706 PEER_CPORT_ID
= 0x00,
707 TRAFFIC_CLASS
= 0x00,
710 /* allow cport attributes to be set */
711 ufshcd_dme_set(hba
, UIC_ARG_MIB(T_CONNECTIONSTATE
), CPORT_IDLE
);
713 /* local unipro attributes */
714 ufshcd_dme_set(hba
, UIC_ARG_MIB(N_DEVICEID
), DEV_ID
);
715 ufshcd_dme_set(hba
, UIC_ARG_MIB(N_DEVICEID_VALID
), true);
716 ufshcd_dme_set(hba
, UIC_ARG_MIB(T_PEERDEVICEID
), PEER_DEV_ID
);
717 ufshcd_dme_set(hba
, UIC_ARG_MIB(T_PEERCPORTID
), PEER_CPORT_ID
);
718 ufshcd_dme_set(hba
, UIC_ARG_MIB(T_CPORTFLAGS
), CPORT_DEF_FLAGS
);
719 ufshcd_dme_set(hba
, UIC_ARG_MIB(T_TRAFFICCLASS
), TRAFFIC_CLASS
);
720 ufshcd_dme_set(hba
, UIC_ARG_MIB(T_CONNECTIONSTATE
), CPORT_CONNECTED
);
723 static void exynos_ufs_config_smu(struct exynos_ufs
*ufs
)
727 exynos_ufs_disable_auto_ctrl_hcc_save(ufs
, &val
);
729 /* make encryption disabled by default */
730 reg
= ufsp_readl(ufs
, UFSPRSECURITY
);
731 ufsp_writel(ufs
, reg
| NSSMU
, UFSPRSECURITY
);
732 ufsp_writel(ufs
, 0x0, UFSPSBEGIN0
);
733 ufsp_writel(ufs
, 0xffffffff, UFSPSEND0
);
734 ufsp_writel(ufs
, 0xff, UFSPSLUN0
);
735 ufsp_writel(ufs
, 0xf1, UFSPSCTRL0
);
737 exynos_ufs_auto_ctrl_hcc_restore(ufs
, &val
);
740 static void exynos_ufs_config_sync_pattern_mask(struct exynos_ufs
*ufs
,
741 struct ufs_pa_layer_attr
*pwr
)
743 struct ufs_hba
*hba
= ufs
->hba
;
744 u8 g
= max_t(u32
, pwr
->gear_rx
, pwr
->gear_tx
);
747 SYNC_LEN_G1
= 80 * 1000, /* 80us */
748 SYNC_LEN_G2
= 40 * 1000, /* 44us */
749 SYNC_LEN_G3
= 20 * 1000, /* 20us */
754 sync_len
= SYNC_LEN_G1
;
756 sync_len
= SYNC_LEN_G2
;
758 sync_len
= SYNC_LEN_G3
;
762 mask
= exynos_ufs_calc_time_cntr(ufs
, sync_len
);
763 mask
= (mask
>> 8) & 0xff;
765 exynos_ufs_enable_ov_tm(hba
);
767 for_each_ufs_rx_lane(ufs
, i
)
769 UIC_ARG_MIB_SEL(RX_SYNC_MASK_LENGTH
, i
), mask
);
771 exynos_ufs_disable_ov_tm(hba
);
774 static int exynos_ufs_pre_pwr_mode(struct ufs_hba
*hba
,
775 struct ufs_pa_layer_attr
*dev_max_params
,
776 struct ufs_pa_layer_attr
*dev_req_params
)
778 struct exynos_ufs
*ufs
= ufshcd_get_variant(hba
);
779 struct phy
*generic_phy
= ufs
->phy
;
780 struct ufs_host_params host_params
;
783 if (!dev_req_params
) {
784 pr_err("%s: incoming dev_req_params is NULL\n", __func__
);
789 ufshcd_init_host_params(&host_params
);
791 ret
= ufshcd_negotiate_pwr_params(&host_params
, dev_max_params
, dev_req_params
);
793 pr_err("%s: failed to determine capabilities\n", __func__
);
797 if (ufs
->drv_data
->pre_pwr_change
)
798 ufs
->drv_data
->pre_pwr_change(ufs
, dev_req_params
);
800 if (ufshcd_is_hs_mode(dev_req_params
)) {
801 exynos_ufs_config_sync_pattern_mask(ufs
, dev_req_params
);
803 switch (dev_req_params
->hs_rate
) {
806 phy_calibrate(generic_phy
);
811 /* setting for three timeout values for traffic class #0 */
812 ufshcd_dme_set(hba
, UIC_ARG_MIB(DL_FC0PROTTIMEOUTVAL
), 8064);
813 ufshcd_dme_set(hba
, UIC_ARG_MIB(DL_TC0REPLAYTIMEOUTVAL
), 28224);
814 ufshcd_dme_set(hba
, UIC_ARG_MIB(DL_AFC0REQTIMEOUTVAL
), 20160);
821 #define PWR_MODE_STR_LEN 64
822 static int exynos_ufs_post_pwr_mode(struct ufs_hba
*hba
,
823 struct ufs_pa_layer_attr
*pwr_req
)
825 struct exynos_ufs
*ufs
= ufshcd_get_variant(hba
);
826 struct phy
*generic_phy
= ufs
->phy
;
827 int gear
= max_t(u32
, pwr_req
->gear_rx
, pwr_req
->gear_tx
);
828 int lanes
= max_t(u32
, pwr_req
->lane_rx
, pwr_req
->lane_tx
);
829 char pwr_str
[PWR_MODE_STR_LEN
] = "";
831 /* let default be PWM Gear 1, Lane 1 */
838 if (ufs
->drv_data
->post_pwr_change
)
839 ufs
->drv_data
->post_pwr_change(ufs
, pwr_req
);
841 if ((ufshcd_is_hs_mode(pwr_req
))) {
842 switch (pwr_req
->hs_rate
) {
845 phy_calibrate(generic_phy
);
849 snprintf(pwr_str
, PWR_MODE_STR_LEN
, "%s series_%s G_%d L_%d",
850 "FAST", pwr_req
->hs_rate
== PA_HS_MODE_A
? "A" : "B",
853 snprintf(pwr_str
, PWR_MODE_STR_LEN
, "%s G_%d L_%d",
854 "SLOW", gear
, lanes
);
857 dev_info(hba
->dev
, "Power mode changed to : %s\n", pwr_str
);
862 static void exynos_ufs_specify_nexus_t_xfer_req(struct ufs_hba
*hba
,
863 int tag
, bool is_scsi_cmd
)
865 struct exynos_ufs
*ufs
= ufshcd_get_variant(hba
);
868 type
= hci_readl(ufs
, HCI_UTRL_NEXUS_TYPE
);
871 hci_writel(ufs
, type
| (1 << tag
), HCI_UTRL_NEXUS_TYPE
);
873 hci_writel(ufs
, type
& ~(1 << tag
), HCI_UTRL_NEXUS_TYPE
);
876 static void exynos_ufs_specify_nexus_t_tm_req(struct ufs_hba
*hba
,
879 struct exynos_ufs
*ufs
= ufshcd_get_variant(hba
);
882 type
= hci_readl(ufs
, HCI_UTMRL_NEXUS_TYPE
);
887 hci_writel(ufs
, type
| (1 << tag
), HCI_UTMRL_NEXUS_TYPE
);
889 case UFS_ABORT_TASK_SET
:
890 case UFS_CLEAR_TASK_SET
:
891 case UFS_LOGICAL_RESET
:
892 case UFS_QUERY_TASK_SET
:
893 hci_writel(ufs
, type
& ~(1 << tag
), HCI_UTMRL_NEXUS_TYPE
);
898 static int exynos_ufs_phy_init(struct exynos_ufs
*ufs
)
900 struct ufs_hba
*hba
= ufs
->hba
;
901 struct phy
*generic_phy
= ufs
->phy
;
904 if (ufs
->avail_ln_rx
== 0 || ufs
->avail_ln_tx
== 0) {
905 ufshcd_dme_get(hba
, UIC_ARG_MIB(PA_AVAILRXDATALANES
),
907 ufshcd_dme_get(hba
, UIC_ARG_MIB(PA_AVAILTXDATALANES
),
909 WARN(ufs
->avail_ln_rx
!= ufs
->avail_ln_tx
,
910 "available data lane is not equal(rx:%d, tx:%d)\n",
911 ufs
->avail_ln_rx
, ufs
->avail_ln_tx
);
914 phy_set_bus_width(generic_phy
, ufs
->avail_ln_rx
);
915 ret
= phy_init(generic_phy
);
917 dev_err(hba
->dev
, "%s: phy init failed, ret = %d\n",
922 ret
= phy_power_on(generic_phy
);
929 phy_exit(generic_phy
);
934 static void exynos_ufs_config_unipro(struct exynos_ufs
*ufs
)
936 struct exynos_ufs_uic_attr
*attr
= ufs
->drv_data
->uic_attr
;
937 struct ufs_hba
*hba
= ufs
->hba
;
939 if (attr
->pa_dbg_clk_period_off
)
940 ufshcd_dme_set(hba
, UIC_ARG_MIB(attr
->pa_dbg_clk_period_off
),
941 DIV_ROUND_UP(NSEC_PER_SEC
, ufs
->mclk_rate
));
943 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_TXTRAILINGCLOCKS
),
944 ufs
->drv_data
->uic_attr
->tx_trailingclks
);
946 if (attr
->pa_dbg_opt_suite1_off
)
947 ufshcd_dme_set(hba
, UIC_ARG_MIB(attr
->pa_dbg_opt_suite1_off
),
948 attr
->pa_dbg_opt_suite1_val
);
950 if (attr
->pa_dbg_opt_suite2_off
)
951 ufshcd_dme_set(hba
, UIC_ARG_MIB(attr
->pa_dbg_opt_suite2_off
),
952 attr
->pa_dbg_opt_suite2_val
);
955 static void exynos_ufs_config_intr(struct exynos_ufs
*ufs
, u32 errs
, u8 index
)
959 hci_writel(ufs
, DFES_ERR_EN
| errs
, HCI_ERR_EN_PA_LAYER
);
962 hci_writel(ufs
, DFES_ERR_EN
| errs
, HCI_ERR_EN_DL_LAYER
);
965 hci_writel(ufs
, DFES_ERR_EN
| errs
, HCI_ERR_EN_N_LAYER
);
968 hci_writel(ufs
, DFES_ERR_EN
| errs
, HCI_ERR_EN_T_LAYER
);
971 hci_writel(ufs
, DFES_ERR_EN
| errs
, HCI_ERR_EN_DME_LAYER
);
976 static int exynos_ufs_setup_clocks(struct ufs_hba
*hba
, bool on
,
977 enum ufs_notify_change_status status
)
979 struct exynos_ufs
*ufs
= ufshcd_get_variant(hba
);
984 if (on
&& status
== PRE_CHANGE
) {
985 if (ufs
->opts
& EXYNOS_UFS_OPT_BROKEN_AUTO_CLK_CTRL
)
986 exynos_ufs_disable_auto_ctrl_hcc(ufs
);
987 exynos_ufs_ungate_clks(ufs
);
988 } else if (!on
&& status
== POST_CHANGE
) {
989 exynos_ufs_gate_clks(ufs
);
990 if (ufs
->opts
& EXYNOS_UFS_OPT_BROKEN_AUTO_CLK_CTRL
)
991 exynos_ufs_enable_auto_ctrl_hcc(ufs
);
997 static int exynos_ufs_pre_link(struct ufs_hba
*hba
)
999 struct exynos_ufs
*ufs
= ufshcd_get_variant(hba
);
1002 exynos_ufs_config_intr(ufs
, DFES_DEF_L2_ERRS
, UNIPRO_L2
);
1003 exynos_ufs_config_intr(ufs
, DFES_DEF_L3_ERRS
, UNIPRO_L3
);
1004 exynos_ufs_config_intr(ufs
, DFES_DEF_L4_ERRS
, UNIPRO_L4
);
1005 exynos_ufs_set_unipro_pclk_div(ufs
);
1008 exynos_ufs_config_unipro(ufs
);
1011 exynos_ufs_phy_init(ufs
);
1012 if (!(ufs
->opts
& EXYNOS_UFS_OPT_SKIP_CONFIG_PHY_ATTR
)) {
1013 exynos_ufs_config_phy_time_attr(ufs
);
1014 exynos_ufs_config_phy_cap_attr(ufs
);
1017 exynos_ufs_setup_clocks(hba
, true, PRE_CHANGE
);
1019 if (ufs
->drv_data
->pre_link
)
1020 ufs
->drv_data
->pre_link(ufs
);
1025 static void exynos_ufs_fit_aggr_timeout(struct exynos_ufs
*ufs
)
1029 /* Select function clock (mclk) for timer tick */
1030 if (ufs
->opts
& EXYNOS_UFS_OPT_TIMER_TICK_SELECT
) {
1031 val
= hci_readl(ufs
, HCI_V2P1_CTRL
);
1033 hci_writel(ufs
, val
, HCI_V2P1_CTRL
);
1036 val
= exynos_ufs_calc_time_cntr(ufs
, IATOVAL_NSEC
/ CNTR_DIV_VAL
);
1037 hci_writel(ufs
, val
& CNT_VAL_1US_MASK
, HCI_1US_TO_CNT_VAL
);
1040 static int exynos_ufs_post_link(struct ufs_hba
*hba
)
1042 struct exynos_ufs
*ufs
= ufshcd_get_variant(hba
);
1043 struct phy
*generic_phy
= ufs
->phy
;
1044 struct exynos_ufs_uic_attr
*attr
= ufs
->drv_data
->uic_attr
;
1046 exynos_ufs_establish_connt(ufs
);
1047 exynos_ufs_fit_aggr_timeout(ufs
);
1049 hci_writel(ufs
, 0xa, HCI_DATA_REORDER
);
1050 hci_writel(ufs
, ilog2(DATA_UNIT_SIZE
), HCI_TXPRDT_ENTRY_SIZE
);
1051 hci_writel(ufs
, ilog2(DATA_UNIT_SIZE
), HCI_RXPRDT_ENTRY_SIZE
);
1052 hci_writel(ufs
, (1 << hba
->nutrs
) - 1, HCI_UTRL_NEXUS_TYPE
);
1053 hci_writel(ufs
, (1 << hba
->nutmrs
) - 1, HCI_UTMRL_NEXUS_TYPE
);
1054 hci_writel(ufs
, 0xf, HCI_AXIDMA_RWDATA_BURST_LEN
);
1056 if (ufs
->opts
& EXYNOS_UFS_OPT_SKIP_CONNECTION_ESTAB
)
1058 UIC_ARG_MIB(T_DBG_SKIP_INIT_HIBERN8_EXIT
), true);
1060 if (attr
->pa_granularity
) {
1061 exynos_ufs_enable_dbg_mode(hba
);
1062 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_GRANULARITY
),
1063 attr
->pa_granularity
);
1064 exynos_ufs_disable_dbg_mode(hba
);
1066 if (attr
->pa_tactivate
)
1067 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_TACTIVATE
),
1068 attr
->pa_tactivate
);
1069 if (attr
->pa_hibern8time
&&
1070 !(ufs
->opts
& EXYNOS_UFS_OPT_USE_SW_HIBERN8_TIMER
))
1071 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_HIBERN8TIME
),
1072 attr
->pa_hibern8time
);
1075 if (ufs
->opts
& EXYNOS_UFS_OPT_USE_SW_HIBERN8_TIMER
) {
1076 if (!attr
->pa_granularity
)
1077 ufshcd_dme_get(hba
, UIC_ARG_MIB(PA_GRANULARITY
),
1078 &attr
->pa_granularity
);
1079 if (!attr
->pa_hibern8time
)
1080 ufshcd_dme_get(hba
, UIC_ARG_MIB(PA_HIBERN8TIME
),
1081 &attr
->pa_hibern8time
);
1083 * not wait for HIBERN8 time to exit hibernation
1085 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_HIBERN8TIME
), 0);
1087 if (attr
->pa_granularity
< 1 || attr
->pa_granularity
> 6) {
1088 /* Valid range for granularity: 1 ~ 6 */
1090 "%s: pa_granularity %d is invalid, assuming backwards compatibility\n",
1092 attr
->pa_granularity
);
1093 attr
->pa_granularity
= 6;
1097 phy_calibrate(generic_phy
);
1099 if (ufs
->drv_data
->post_link
)
1100 ufs
->drv_data
->post_link(ufs
);
1105 static int exynos_ufs_parse_dt(struct device
*dev
, struct exynos_ufs
*ufs
)
1107 struct device_node
*np
= dev
->of_node
;
1108 struct exynos_ufs_uic_attr
*attr
;
1111 ufs
->drv_data
= device_get_match_data(dev
);
1113 if (ufs
->drv_data
&& ufs
->drv_data
->uic_attr
) {
1114 attr
= ufs
->drv_data
->uic_attr
;
1116 dev_err(dev
, "failed to get uic attributes\n");
1121 ufs
->sysreg
= syscon_regmap_lookup_by_phandle(np
, "samsung,sysreg");
1122 if (IS_ERR(ufs
->sysreg
))
1125 if (of_property_read_u32_index(np
, "samsung,sysreg", 1,
1126 &ufs
->shareability_reg_offset
)) {
1127 dev_warn(dev
, "can't get an offset from sysreg. Set to default value\n");
1128 ufs
->shareability_reg_offset
= UFS_SHAREABILITY_OFFSET
;
1132 ufs
->pclk_avail_min
= PCLK_AVAIL_MIN
;
1133 ufs
->pclk_avail_max
= PCLK_AVAIL_MAX
;
1135 attr
->rx_adv_fine_gran_sup_en
= RX_ADV_FINE_GRAN_SUP_EN
;
1136 attr
->rx_adv_fine_gran_step
= RX_ADV_FINE_GRAN_STEP_VAL
;
1137 attr
->rx_adv_min_actv_time_cap
= RX_ADV_MIN_ACTV_TIME_CAP
;
1138 attr
->pa_granularity
= PA_GRANULARITY_VAL
;
1139 attr
->pa_tactivate
= PA_TACTIVATE_VAL
;
1140 attr
->pa_hibern8time
= PA_HIBERN8TIME_VAL
;
1146 static inline void exynos_ufs_priv_init(struct ufs_hba
*hba
,
1147 struct exynos_ufs
*ufs
)
1150 ufs
->opts
= ufs
->drv_data
->opts
;
1151 ufs
->rx_sel_idx
= PA_MAXDATALANES
;
1152 if (ufs
->opts
& EXYNOS_UFS_OPT_BROKEN_RX_SEL_IDX
)
1153 ufs
->rx_sel_idx
= 0;
1154 hba
->priv
= (void *)ufs
;
1155 hba
->quirks
= ufs
->drv_data
->quirks
;
1158 #ifdef CONFIG_SCSI_UFS_CRYPTO
1161 * Support for Flash Memory Protector (FMP), which is the inline encryption
1162 * hardware on Exynos and Exynos-based SoCs. The interface to this hardware is
1163 * not compatible with the standard UFS crypto. It requires that encryption be
1164 * configured in the PRDT using a nonstandard extension.
1167 enum fmp_crypto_algo_mode
{
1168 FMP_BYPASS_MODE
= 0,
1169 FMP_ALGO_MODE_AES_CBC
= 1,
1170 FMP_ALGO_MODE_AES_XTS
= 2,
1172 enum fmp_crypto_key_length
{
1173 FMP_KEYLEN_256BIT
= 1,
1177 * struct fmp_sg_entry - nonstandard format of PRDT entries when FMP is enabled
1179 * @base: The standard PRDT entry, but with nonstandard bitfields in the high
1180 * bits of the 'size' field, i.e. the last 32-bit word. When these
1181 * nonstandard bitfields are zero, the data segment won't be encrypted or
1182 * decrypted. Otherwise they specify the algorithm and key length with
1183 * which the data segment will be encrypted or decrypted.
1184 * @file_iv: The initialization vector (IV) with all bytes reversed
1185 * @file_enckey: The first half of the AES-XTS key with all bytes reserved
1186 * @file_twkey: The second half of the AES-XTS key with all bytes reserved
1190 struct fmp_sg_entry
{
1191 struct ufshcd_sg_entry base
;
1193 __be64 file_enckey
[4];
1194 __be64 file_twkey
[4];
1199 #define SMC_CMD_FMP_SECURITY \
1200 ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_64, \
1201 ARM_SMCCC_OWNER_SIP, 0x1810)
1202 #define SMC_CMD_SMU \
1203 ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_64, \
1204 ARM_SMCCC_OWNER_SIP, 0x1850)
1205 #define SMC_CMD_FMP_SMU_RESUME \
1206 ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_64, \
1207 ARM_SMCCC_OWNER_SIP, 0x1860)
1208 #define SMU_EMBEDDED 0
1210 #define CFG_DESCTYPE_3 3
1212 static void exynos_ufs_fmp_init(struct ufs_hba
*hba
, struct exynos_ufs
*ufs
)
1214 struct blk_crypto_profile
*profile
= &hba
->crypto_profile
;
1215 struct arm_smccc_res res
;
1219 * Check for the standard crypto support bit, since it's available even
1220 * though the rest of the interface to FMP is nonstandard.
1222 * This check should have the effect of preventing the driver from
1223 * trying to use FMP on old Exynos SoCs that don't have FMP.
1225 if (!(ufshcd_readl(hba
, REG_CONTROLLER_CAPABILITIES
) &
1226 MASK_CRYPTO_SUPPORT
))
1230 * The below sequence of SMC calls to enable FMP can be found in the
1231 * downstream driver source for gs101 and other Exynos-based SoCs. It
1232 * is the only way to enable FMP that works on SoCs such as gs101 that
1233 * don't make the FMP registers accessible to Linux. It probably works
1234 * on other Exynos-based SoCs too, and might even still be the only way
1235 * that works. But this hasn't been properly tested, and this code is
1236 * mutually exclusive with exynos_ufs_config_smu(). So for now only
1237 * enable FMP support on SoCs with EXYNOS_UFS_OPT_UFSPR_SECURE.
1239 if (!(ufs
->opts
& EXYNOS_UFS_OPT_UFSPR_SECURE
))
1243 * This call (which sets DESCTYPE to 0x3 in the FMPSECURITY0 register)
1244 * is needed to make the hardware use the larger PRDT entry size.
1246 BUILD_BUG_ON(sizeof(struct fmp_sg_entry
) != 128);
1247 arm_smccc_smc(SMC_CMD_FMP_SECURITY
, 0, SMU_EMBEDDED
, CFG_DESCTYPE_3
,
1251 "SMC_CMD_FMP_SECURITY failed on init: %ld. Disabling FMP support.\n",
1255 ufshcd_set_sg_entry_size(hba
, sizeof(struct fmp_sg_entry
));
1258 * This is needed to initialize FMP. Without it, errors occur when
1259 * inline encryption is used.
1261 arm_smccc_smc(SMC_CMD_SMU
, SMU_INIT
, SMU_EMBEDDED
, 0, 0, 0, 0, 0, &res
);
1264 "SMC_CMD_SMU(SMU_INIT) failed: %ld. Disabling FMP support.\n",
1269 /* Advertise crypto capabilities to the block layer. */
1270 err
= devm_blk_crypto_profile_init(hba
->dev
, profile
, 0);
1272 /* Only ENOMEM should be possible here. */
1273 dev_err(hba
->dev
, "Failed to initialize crypto profile: %d\n",
1277 profile
->max_dun_bytes_supported
= AES_BLOCK_SIZE
;
1278 profile
->dev
= hba
->dev
;
1279 profile
->modes_supported
[BLK_ENCRYPTION_MODE_AES_256_XTS
] =
1282 /* Advertise crypto support to ufshcd-core. */
1283 hba
->caps
|= UFSHCD_CAP_CRYPTO
;
1285 /* Advertise crypto quirks to ufshcd-core. */
1286 hba
->quirks
|= UFSHCD_QUIRK_CUSTOM_CRYPTO_PROFILE
|
1287 UFSHCD_QUIRK_BROKEN_CRYPTO_ENABLE
|
1288 UFSHCD_QUIRK_KEYS_IN_PRDT
;
1292 static void exynos_ufs_fmp_resume(struct ufs_hba
*hba
)
1294 struct arm_smccc_res res
;
1296 if (!(hba
->caps
& UFSHCD_CAP_CRYPTO
))
1299 arm_smccc_smc(SMC_CMD_FMP_SECURITY
, 0, SMU_EMBEDDED
, CFG_DESCTYPE_3
,
1303 "SMC_CMD_FMP_SECURITY failed on resume: %ld\n", res
.a0
);
1305 arm_smccc_smc(SMC_CMD_FMP_SMU_RESUME
, 0, SMU_EMBEDDED
, 0, 0, 0, 0, 0,
1309 "SMC_CMD_FMP_SMU_RESUME failed: %ld\n", res
.a0
);
1312 static inline __be64
fmp_key_word(const u8
*key
, int j
)
1314 return cpu_to_be64(get_unaligned_le64(
1315 key
+ AES_KEYSIZE_256
- (j
+ 1) * sizeof(u64
)));
1318 /* Fill the PRDT for a request according to the given encryption context. */
1319 static int exynos_ufs_fmp_fill_prdt(struct ufs_hba
*hba
,
1320 const struct bio_crypt_ctx
*crypt_ctx
,
1321 void *prdt
, unsigned int num_segments
)
1323 struct fmp_sg_entry
*fmp_prdt
= prdt
;
1324 const u8
*enckey
= crypt_ctx
->bc_key
->raw
;
1325 const u8
*twkey
= enckey
+ AES_KEYSIZE_256
;
1326 u64 dun_lo
= crypt_ctx
->bc_dun
[0];
1327 u64 dun_hi
= crypt_ctx
->bc_dun
[1];
1330 /* If FMP wasn't enabled, we shouldn't get any encrypted requests. */
1331 if (WARN_ON_ONCE(!(hba
->caps
& UFSHCD_CAP_CRYPTO
)))
1334 /* Configure FMP on each segment of the request. */
1335 for (i
= 0; i
< num_segments
; i
++) {
1336 struct fmp_sg_entry
*prd
= &fmp_prdt
[i
];
1339 /* Each segment must be exactly one data unit. */
1340 if (prd
->base
.size
!= cpu_to_le32(DATA_UNIT_SIZE
- 1)) {
1342 "data segment is misaligned for FMP\n");
1346 /* Set the algorithm and key length. */
1347 prd
->base
.size
|= cpu_to_le32((FMP_ALGO_MODE_AES_XTS
<< 28) |
1348 (FMP_KEYLEN_256BIT
<< 26));
1351 prd
->file_iv
[0] = cpu_to_be64(dun_hi
);
1352 prd
->file_iv
[1] = cpu_to_be64(dun_lo
);
1355 for (j
= 0; j
< AES_KEYSIZE_256
/ sizeof(u64
); j
++) {
1356 prd
->file_enckey
[j
] = fmp_key_word(enckey
, j
);
1357 prd
->file_twkey
[j
] = fmp_key_word(twkey
, j
);
1360 /* Increment the data unit number. */
1368 #else /* CONFIG_SCSI_UFS_CRYPTO */
1370 static void exynos_ufs_fmp_init(struct ufs_hba
*hba
, struct exynos_ufs
*ufs
)
1374 static void exynos_ufs_fmp_resume(struct ufs_hba
*hba
)
1378 #define exynos_ufs_fmp_fill_prdt NULL
1380 #endif /* !CONFIG_SCSI_UFS_CRYPTO */
1382 static int exynos_ufs_init(struct ufs_hba
*hba
)
1384 struct device
*dev
= hba
->dev
;
1385 struct platform_device
*pdev
= to_platform_device(dev
);
1386 struct exynos_ufs
*ufs
;
1389 ufs
= devm_kzalloc(dev
, sizeof(*ufs
), GFP_KERNEL
);
1393 /* exynos-specific hci */
1394 ufs
->reg_hci
= devm_platform_ioremap_resource_byname(pdev
, "vs_hci");
1395 if (IS_ERR(ufs
->reg_hci
)) {
1396 dev_err(dev
, "cannot ioremap for hci vendor register\n");
1397 return PTR_ERR(ufs
->reg_hci
);
1401 ufs
->reg_unipro
= devm_platform_ioremap_resource_byname(pdev
, "unipro");
1402 if (IS_ERR(ufs
->reg_unipro
)) {
1403 dev_err(dev
, "cannot ioremap for unipro register\n");
1404 return PTR_ERR(ufs
->reg_unipro
);
1408 ufs
->reg_ufsp
= devm_platform_ioremap_resource_byname(pdev
, "ufsp");
1409 if (IS_ERR(ufs
->reg_ufsp
)) {
1410 dev_err(dev
, "cannot ioremap for ufs protector register\n");
1411 return PTR_ERR(ufs
->reg_ufsp
);
1414 ret
= exynos_ufs_parse_dt(dev
, ufs
);
1416 dev_err(dev
, "failed to get dt info.\n");
1420 ufs
->phy
= devm_phy_get(dev
, "ufs-phy");
1421 if (IS_ERR(ufs
->phy
)) {
1422 ret
= PTR_ERR(ufs
->phy
);
1423 dev_err(dev
, "failed to get ufs-phy\n");
1427 exynos_ufs_priv_init(hba
, ufs
);
1429 exynos_ufs_fmp_init(hba
, ufs
);
1431 if (ufs
->drv_data
->drv_init
) {
1432 ret
= ufs
->drv_data
->drv_init(dev
, ufs
);
1434 dev_err(dev
, "failed to init drv-data\n");
1439 ret
= exynos_ufs_get_clk_info(ufs
);
1442 exynos_ufs_specify_phy_time_attr(ufs
);
1443 if (!(ufs
->opts
& EXYNOS_UFS_OPT_UFSPR_SECURE
))
1444 exynos_ufs_config_smu(ufs
);
1446 hba
->host
->dma_alignment
= DATA_UNIT_SIZE
- 1;
1454 static int exynos_ufs_host_reset(struct ufs_hba
*hba
)
1456 struct exynos_ufs
*ufs
= ufshcd_get_variant(hba
);
1457 unsigned long timeout
= jiffies
+ msecs_to_jiffies(1);
1461 exynos_ufs_disable_auto_ctrl_hcc_save(ufs
, &val
);
1463 hci_writel(ufs
, UFS_SW_RST_MASK
, HCI_SW_RST
);
1466 if (!(hci_readl(ufs
, HCI_SW_RST
) & UFS_SW_RST_MASK
))
1468 } while (time_before(jiffies
, timeout
));
1470 dev_err(hba
->dev
, "timeout host sw-reset\n");
1474 exynos_ufs_auto_ctrl_hcc_restore(ufs
, &val
);
1478 static void exynos_ufs_dev_hw_reset(struct ufs_hba
*hba
)
1480 struct exynos_ufs
*ufs
= ufshcd_get_variant(hba
);
1482 hci_writel(ufs
, 0 << 0, HCI_GPIO_OUT
);
1484 hci_writel(ufs
, 1 << 0, HCI_GPIO_OUT
);
1487 static void exynos_ufs_pre_hibern8(struct ufs_hba
*hba
, u8 enter
)
1489 struct exynos_ufs
*ufs
= ufshcd_get_variant(hba
);
1490 struct exynos_ufs_uic_attr
*attr
= ufs
->drv_data
->uic_attr
;
1493 if (ufs
->opts
& EXYNOS_UFS_OPT_BROKEN_AUTO_CLK_CTRL
)
1494 exynos_ufs_disable_auto_ctrl_hcc(ufs
);
1495 exynos_ufs_ungate_clks(ufs
);
1497 if (ufs
->opts
& EXYNOS_UFS_OPT_USE_SW_HIBERN8_TIMER
) {
1498 static const unsigned int granularity_tbl
[] = {
1499 1, 4, 8, 16, 32, 100
1501 int h8_time
= attr
->pa_hibern8time
*
1502 granularity_tbl
[attr
->pa_granularity
- 1];
1507 delta
= h8_time
- ktime_us_delta(ktime_get(),
1508 ufs
->entry_hibern8_t
);
1512 us
= min_t(s64
, delta
, USEC_PER_MSEC
);
1514 usleep_range(us
, us
+ 10);
1520 static void exynos_ufs_post_hibern8(struct ufs_hba
*hba
, u8 enter
)
1522 struct exynos_ufs
*ufs
= ufshcd_get_variant(hba
);
1528 if (ufshcd_is_hs_mode(&ufs
->dev_req_params
))
1529 pwrmode
= FAST_MODE
;
1531 pwrmode
= SLOW_MODE
;
1533 ufshcd_dme_get(hba
, UIC_ARG_MIB(PA_PWRMODE
), &cur_mode
);
1534 if (cur_mode
!= (pwrmode
<< 4 | pwrmode
)) {
1535 dev_warn(hba
->dev
, "%s: power mode change\n", __func__
);
1536 hba
->pwr_info
.pwr_rx
= (cur_mode
>> 4) & 0xf;
1537 hba
->pwr_info
.pwr_tx
= cur_mode
& 0xf;
1538 ufshcd_config_pwr_mode(hba
, &hba
->max_pwr_info
.info
);
1541 if (!(ufs
->opts
& EXYNOS_UFS_OPT_SKIP_CONNECTION_ESTAB
))
1542 exynos_ufs_establish_connt(ufs
);
1544 ufs
->entry_hibern8_t
= ktime_get();
1545 exynos_ufs_gate_clks(ufs
);
1546 if (ufs
->opts
& EXYNOS_UFS_OPT_BROKEN_AUTO_CLK_CTRL
)
1547 exynos_ufs_enable_auto_ctrl_hcc(ufs
);
1551 static int exynos_ufs_hce_enable_notify(struct ufs_hba
*hba
,
1552 enum ufs_notify_change_status status
)
1554 struct exynos_ufs
*ufs
= ufshcd_get_variant(hba
);
1560 * The maximum segment size must be set after scsi_host_alloc()
1561 * has been called and before LUN scanning starts
1562 * (ufshcd_async_scan()). Note: this callback may also be called
1563 * from other functions than ufshcd_init().
1565 hba
->host
->max_segment_size
= DATA_UNIT_SIZE
;
1567 if (ufs
->drv_data
->pre_hce_enable
) {
1568 ret
= ufs
->drv_data
->pre_hce_enable(ufs
);
1573 ret
= exynos_ufs_host_reset(hba
);
1576 exynos_ufs_dev_hw_reset(hba
);
1579 exynos_ufs_calc_pwm_clk_div(ufs
);
1580 if (!(ufs
->opts
& EXYNOS_UFS_OPT_BROKEN_AUTO_CLK_CTRL
))
1581 exynos_ufs_enable_auto_ctrl_hcc(ufs
);
1583 if (ufs
->drv_data
->post_hce_enable
)
1584 ret
= ufs
->drv_data
->post_hce_enable(ufs
);
1592 static int exynos_ufs_link_startup_notify(struct ufs_hba
*hba
,
1593 enum ufs_notify_change_status status
)
1599 ret
= exynos_ufs_pre_link(hba
);
1602 ret
= exynos_ufs_post_link(hba
);
1609 static int exynos_ufs_pwr_change_notify(struct ufs_hba
*hba
,
1610 enum ufs_notify_change_status status
,
1611 struct ufs_pa_layer_attr
*dev_max_params
,
1612 struct ufs_pa_layer_attr
*dev_req_params
)
1618 ret
= exynos_ufs_pre_pwr_mode(hba
, dev_max_params
,
1622 ret
= exynos_ufs_post_pwr_mode(hba
, dev_req_params
);
1629 static void exynos_ufs_hibern8_notify(struct ufs_hba
*hba
,
1630 enum uic_cmd_dme enter
,
1631 enum ufs_notify_change_status notify
)
1633 switch ((u8
)notify
) {
1635 exynos_ufs_pre_hibern8(hba
, enter
);
1638 exynos_ufs_post_hibern8(hba
, enter
);
1643 static int exynos_ufs_suspend(struct ufs_hba
*hba
, enum ufs_pm_op pm_op
,
1644 enum ufs_notify_change_status status
)
1646 struct exynos_ufs
*ufs
= ufshcd_get_variant(hba
);
1648 if (status
== PRE_CHANGE
)
1651 if (!ufshcd_is_link_active(hba
))
1652 phy_power_off(ufs
->phy
);
1657 static int exynos_ufs_resume(struct ufs_hba
*hba
, enum ufs_pm_op pm_op
)
1659 struct exynos_ufs
*ufs
= ufshcd_get_variant(hba
);
1661 if (!ufshcd_is_link_active(hba
))
1662 phy_power_on(ufs
->phy
);
1664 exynos_ufs_config_smu(ufs
);
1665 exynos_ufs_fmp_resume(hba
);
1669 static int exynosauto_ufs_vh_link_startup_notify(struct ufs_hba
*hba
,
1670 enum ufs_notify_change_status status
)
1672 if (status
== POST_CHANGE
) {
1673 ufshcd_set_link_active(hba
);
1674 ufshcd_set_ufs_dev_active(hba
);
1680 static int exynosauto_ufs_vh_wait_ph_ready(struct ufs_hba
*hba
)
1683 ktime_t start
, stop
;
1685 start
= ktime_get();
1686 stop
= ktime_add(start
, ms_to_ktime(PH_READY_TIMEOUT_MS
));
1689 mbox
= ufshcd_readl(hba
, PH2VH_MBOX
);
1690 /* TODO: Mailbox message protocols between the PH and VHs are
1691 * not implemented yet. This will be supported later
1693 if ((mbox
& MH_MSG_MASK
) == MH_MSG_PH_READY
)
1696 usleep_range(40, 50);
1697 } while (ktime_before(ktime_get(), stop
));
1702 static int exynosauto_ufs_vh_init(struct ufs_hba
*hba
)
1704 struct device
*dev
= hba
->dev
;
1705 struct platform_device
*pdev
= to_platform_device(dev
);
1706 struct exynos_ufs
*ufs
;
1709 ufs
= devm_kzalloc(dev
, sizeof(*ufs
), GFP_KERNEL
);
1713 /* exynos-specific hci */
1714 ufs
->reg_hci
= devm_platform_ioremap_resource_byname(pdev
, "vs_hci");
1715 if (IS_ERR(ufs
->reg_hci
)) {
1716 dev_err(dev
, "cannot ioremap for hci vendor register\n");
1717 return PTR_ERR(ufs
->reg_hci
);
1720 ret
= exynosauto_ufs_vh_wait_ph_ready(hba
);
1724 ufs
->drv_data
= device_get_match_data(dev
);
1728 exynos_ufs_priv_init(hba
, ufs
);
1733 static int fsd_ufs_pre_link(struct exynos_ufs
*ufs
)
1735 struct exynos_ufs_uic_attr
*attr
= ufs
->drv_data
->uic_attr
;
1736 struct ufs_hba
*hba
= ufs
->hba
;
1739 ufshcd_dme_set(hba
, UIC_ARG_MIB(attr
->pa_dbg_clk_period_off
),
1740 DIV_ROUND_UP(NSEC_PER_SEC
, ufs
->mclk_rate
));
1741 ufshcd_dme_set(hba
, UIC_ARG_MIB(0x201), 0x12);
1742 ufshcd_dme_set(hba
, UIC_ARG_MIB(0x200), 0x40);
1744 for_each_ufs_tx_lane(ufs
, i
) {
1745 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0xAA, i
),
1746 DIV_ROUND_UP(NSEC_PER_SEC
, ufs
->mclk_rate
));
1747 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x8F, i
), 0x3F);
1750 for_each_ufs_rx_lane(ufs
, i
) {
1751 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x12, i
),
1752 DIV_ROUND_UP(NSEC_PER_SEC
, ufs
->mclk_rate
));
1753 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x5C, i
), 0x38);
1754 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x0F, i
), 0x0);
1755 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x65, i
), 0x1);
1756 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x69, i
), 0x1);
1757 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x21, i
), 0x0);
1758 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x22, i
), 0x0);
1761 ufshcd_dme_set(hba
, UIC_ARG_MIB(0x200), 0x0);
1762 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_DBG_AUTOMODE_THLD
), 0x4E20);
1764 ufshcd_dme_set(hba
, UIC_ARG_MIB(attr
->pa_dbg_opt_suite1_off
),
1766 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_LOCAL_TX_LCC_ENABLE
), 0x0);
1768 exynos_ufs_establish_connt(ufs
);
1773 static int fsd_ufs_post_link(struct exynos_ufs
*ufs
)
1776 struct ufs_hba
*hba
= ufs
->hba
;
1777 u32 hw_cap_min_tactivate
;
1778 u32 peer_rx_min_actv_time_cap
;
1779 u32 max_rx_hibern8_time_cap
;
1781 ufshcd_dme_get(hba
, UIC_ARG_MIB_SEL(0x8F, 4),
1782 &hw_cap_min_tactivate
); /* HW Capability of MIN_TACTIVATE */
1783 ufshcd_dme_get(hba
, UIC_ARG_MIB(PA_TACTIVATE
),
1784 &peer_rx_min_actv_time_cap
); /* PA_TActivate */
1785 ufshcd_dme_get(hba
, UIC_ARG_MIB(PA_HIBERN8TIME
),
1786 &max_rx_hibern8_time_cap
); /* PA_Hibern8Time */
1788 if (peer_rx_min_actv_time_cap
>= hw_cap_min_tactivate
)
1789 ufshcd_dme_peer_set(hba
, UIC_ARG_MIB(PA_TACTIVATE
),
1790 peer_rx_min_actv_time_cap
+ 1);
1791 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_HIBERN8TIME
), max_rx_hibern8_time_cap
+ 1);
1793 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_DBG_MODE
), 0x01);
1794 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_SAVECONFIGTIME
), 0xFA);
1795 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_DBG_MODE
), 0x00);
1797 ufshcd_dme_set(hba
, UIC_ARG_MIB(0x200), 0x40);
1799 for_each_ufs_rx_lane(ufs
, i
) {
1800 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x35, i
), 0x05);
1801 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x73, i
), 0x01);
1802 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x41, i
), 0x02);
1803 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x42, i
), 0xAC);
1806 ufshcd_dme_set(hba
, UIC_ARG_MIB(0x200), 0x0);
1811 static int fsd_ufs_pre_pwr_change(struct exynos_ufs
*ufs
,
1812 struct ufs_pa_layer_attr
*pwr
)
1814 struct ufs_hba
*hba
= ufs
->hba
;
1816 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_TXTERMINATION
), 0x1);
1817 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_RXTERMINATION
), 0x1);
1818 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_PWRMODEUSERDATA0
), 12000);
1819 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_PWRMODEUSERDATA1
), 32000);
1820 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_PWRMODEUSERDATA2
), 16000);
1822 unipro_writel(ufs
, 12000, UNIPRO_DME_POWERMODE_REQ_REMOTEL2TIMER0
);
1823 unipro_writel(ufs
, 32000, UNIPRO_DME_POWERMODE_REQ_REMOTEL2TIMER1
);
1824 unipro_writel(ufs
, 16000, UNIPRO_DME_POWERMODE_REQ_REMOTEL2TIMER2
);
1829 static inline u32
get_mclk_period_unipro_18(struct exynos_ufs
*ufs
)
1831 return (16 * 1000 * 1000000UL / ufs
->mclk_rate
);
1834 static int gs101_ufs_pre_link(struct exynos_ufs
*ufs
)
1836 struct ufs_hba
*hba
= ufs
->hba
;
1838 u32 tx_line_reset_period
, rx_line_reset_period
;
1840 rx_line_reset_period
= (RX_LINE_RESET_TIME
* ufs
->mclk_rate
)
1842 tx_line_reset_period
= (TX_LINE_RESET_TIME
* ufs
->mclk_rate
)
1845 unipro_writel(ufs
, get_mclk_period_unipro_18(ufs
), COMP_CLK_PERIOD
);
1847 ufshcd_dme_set(hba
, UIC_ARG_MIB(0x200), 0x40);
1849 for_each_ufs_rx_lane(ufs
, i
) {
1850 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_RX_CLK_PRD
, i
),
1851 DIV_ROUND_UP(NSEC_PER_SEC
, ufs
->mclk_rate
));
1852 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_RX_CLK_PRD_EN
, i
), 0x0);
1853 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_RX_LINERESET_VALUE2
, i
),
1854 (rx_line_reset_period
>> 16) & 0xFF);
1855 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_RX_LINERESET_VALUE1
, i
),
1856 (rx_line_reset_period
>> 8) & 0xFF);
1857 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_RX_LINERESET_VALUE0
, i
),
1858 (rx_line_reset_period
) & 0xFF);
1859 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x2f, i
), 0x69);
1860 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x84, i
), 0x1);
1861 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x25, i
), 0xf6);
1864 for_each_ufs_tx_lane(ufs
, i
) {
1865 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_TX_CLK_PRD
, i
),
1866 DIV_ROUND_UP(NSEC_PER_SEC
, ufs
->mclk_rate
));
1867 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_TX_CLK_PRD_EN
, i
),
1869 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_TX_LINERESET_PVALUE2
, i
),
1870 (tx_line_reset_period
>> 16) & 0xFF);
1871 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_TX_LINERESET_PVALUE1
, i
),
1872 (tx_line_reset_period
>> 8) & 0xFF);
1873 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(VND_TX_LINERESET_PVALUE0
, i
),
1874 (tx_line_reset_period
) & 0xFF);
1875 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x04, i
), 1);
1876 ufshcd_dme_set(hba
, UIC_ARG_MIB_SEL(0x7F, i
), 0);
1879 ufshcd_dme_set(hba
, UIC_ARG_MIB(0x200), 0x0);
1880 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_LOCAL_TX_LCC_ENABLE
), 0x0);
1881 ufshcd_dme_set(hba
, UIC_ARG_MIB(N_DEVICEID
), 0x0);
1882 ufshcd_dme_set(hba
, UIC_ARG_MIB(N_DEVICEID_VALID
), 0x1);
1883 ufshcd_dme_set(hba
, UIC_ARG_MIB(T_PEERDEVICEID
), 0x1);
1884 ufshcd_dme_set(hba
, UIC_ARG_MIB(T_CONNECTIONSTATE
), CPORT_CONNECTED
);
1885 ufshcd_dme_set(hba
, UIC_ARG_MIB(0xA006), 0x8000);
1890 static int gs101_ufs_post_link(struct exynos_ufs
*ufs
)
1892 struct ufs_hba
*hba
= ufs
->hba
;
1894 exynos_ufs_enable_dbg_mode(hba
);
1895 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_SAVECONFIGTIME
), 0x3e8);
1896 exynos_ufs_disable_dbg_mode(hba
);
1901 static int gs101_ufs_pre_pwr_change(struct exynos_ufs
*ufs
,
1902 struct ufs_pa_layer_attr
*pwr
)
1904 struct ufs_hba
*hba
= ufs
->hba
;
1906 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_PWRMODEUSERDATA0
), 12000);
1907 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_PWRMODEUSERDATA1
), 32000);
1908 ufshcd_dme_set(hba
, UIC_ARG_MIB(PA_PWRMODEUSERDATA2
), 16000);
1909 unipro_writel(ufs
, 8064, UNIPRO_DME_POWERMODE_REQ_LOCALL2TIMER0
);
1910 unipro_writel(ufs
, 28224, UNIPRO_DME_POWERMODE_REQ_LOCALL2TIMER1
);
1911 unipro_writel(ufs
, 20160, UNIPRO_DME_POWERMODE_REQ_LOCALL2TIMER2
);
1912 unipro_writel(ufs
, 12000, UNIPRO_DME_POWERMODE_REQ_REMOTEL2TIMER0
);
1913 unipro_writel(ufs
, 32000, UNIPRO_DME_POWERMODE_REQ_REMOTEL2TIMER1
);
1914 unipro_writel(ufs
, 16000, UNIPRO_DME_POWERMODE_REQ_REMOTEL2TIMER2
);
1919 static const struct ufs_hba_variant_ops ufs_hba_exynos_ops
= {
1920 .name
= "exynos_ufs",
1921 .init
= exynos_ufs_init
,
1922 .hce_enable_notify
= exynos_ufs_hce_enable_notify
,
1923 .link_startup_notify
= exynos_ufs_link_startup_notify
,
1924 .pwr_change_notify
= exynos_ufs_pwr_change_notify
,
1925 .setup_clocks
= exynos_ufs_setup_clocks
,
1926 .setup_xfer_req
= exynos_ufs_specify_nexus_t_xfer_req
,
1927 .setup_task_mgmt
= exynos_ufs_specify_nexus_t_tm_req
,
1928 .hibern8_notify
= exynos_ufs_hibern8_notify
,
1929 .suspend
= exynos_ufs_suspend
,
1930 .resume
= exynos_ufs_resume
,
1931 .fill_crypto_prdt
= exynos_ufs_fmp_fill_prdt
,
1934 static struct ufs_hba_variant_ops ufs_hba_exynosauto_vh_ops
= {
1935 .name
= "exynosauto_ufs_vh",
1936 .init
= exynosauto_ufs_vh_init
,
1937 .link_startup_notify
= exynosauto_ufs_vh_link_startup_notify
,
1940 static int exynos_ufs_probe(struct platform_device
*pdev
)
1943 struct device
*dev
= &pdev
->dev
;
1944 const struct ufs_hba_variant_ops
*vops
= &ufs_hba_exynos_ops
;
1945 const struct exynos_ufs_drv_data
*drv_data
=
1946 device_get_match_data(dev
);
1948 if (drv_data
&& drv_data
->vops
)
1949 vops
= drv_data
->vops
;
1951 err
= ufshcd_pltfrm_init(pdev
, vops
);
1953 dev_err(dev
, "ufshcd_pltfrm_init() failed %d\n", err
);
1958 static void exynos_ufs_remove(struct platform_device
*pdev
)
1960 struct ufs_hba
*hba
= platform_get_drvdata(pdev
);
1961 struct exynos_ufs
*ufs
= ufshcd_get_variant(hba
);
1963 pm_runtime_get_sync(&(pdev
)->dev
);
1966 phy_power_off(ufs
->phy
);
1970 static struct exynos_ufs_uic_attr exynos7_uic_attr
= {
1971 .tx_trailingclks
= 0x10,
1972 .tx_dif_p_nsec
= 3000000, /* unit: ns */
1973 .tx_dif_n_nsec
= 1000000, /* unit: ns */
1974 .tx_high_z_cnt_nsec
= 20000, /* unit: ns */
1975 .tx_base_unit_nsec
= 100000, /* unit: ns */
1976 .tx_gran_unit_nsec
= 4000, /* unit: ns */
1977 .tx_sleep_cnt
= 1000, /* unit: ns */
1978 .tx_min_activatetime
= 0xa,
1979 .rx_filler_enable
= 0x2,
1980 .rx_dif_p_nsec
= 1000000, /* unit: ns */
1981 .rx_hibern8_wait_nsec
= 4000000, /* unit: ns */
1982 .rx_base_unit_nsec
= 100000, /* unit: ns */
1983 .rx_gran_unit_nsec
= 4000, /* unit: ns */
1984 .rx_sleep_cnt
= 1280, /* unit: ns */
1985 .rx_stall_cnt
= 320, /* unit: ns */
1986 .rx_hs_g1_sync_len_cap
= SYNC_LEN_COARSE(0xf),
1987 .rx_hs_g2_sync_len_cap
= SYNC_LEN_COARSE(0xf),
1988 .rx_hs_g3_sync_len_cap
= SYNC_LEN_COARSE(0xf),
1989 .rx_hs_g1_prep_sync_len_cap
= PREP_LEN(0xf),
1990 .rx_hs_g2_prep_sync_len_cap
= PREP_LEN(0xf),
1991 .rx_hs_g3_prep_sync_len_cap
= PREP_LEN(0xf),
1992 .pa_dbg_clk_period_off
= PA_DBG_CLK_PERIOD
,
1993 .pa_dbg_opt_suite1_val
= 0x30103,
1994 .pa_dbg_opt_suite1_off
= PA_DBG_OPTION_SUITE
,
1997 static const struct exynos_ufs_drv_data exynosauto_ufs_drvs
= {
1998 .uic_attr
= &exynos7_uic_attr
,
1999 .quirks
= UFSHCD_QUIRK_PRDT_BYTE_GRAN
|
2000 UFSHCI_QUIRK_SKIP_RESET_INTR_AGGR
|
2001 UFSHCD_QUIRK_BROKEN_OCS_FATAL_ERROR
|
2002 UFSHCD_QUIRK_SKIP_DEF_UNIPRO_TIMEOUT_SETTING
,
2003 .opts
= EXYNOS_UFS_OPT_BROKEN_AUTO_CLK_CTRL
|
2004 EXYNOS_UFS_OPT_SKIP_CONFIG_PHY_ATTR
|
2005 EXYNOS_UFS_OPT_BROKEN_RX_SEL_IDX
,
2006 .drv_init
= exynosauto_ufs_drv_init
,
2007 .post_hce_enable
= exynosauto_ufs_post_hce_enable
,
2008 .pre_link
= exynosauto_ufs_pre_link
,
2009 .pre_pwr_change
= exynosauto_ufs_pre_pwr_change
,
2010 .post_pwr_change
= exynosauto_ufs_post_pwr_change
,
2013 static const struct exynos_ufs_drv_data exynosauto_ufs_vh_drvs
= {
2014 .vops
= &ufs_hba_exynosauto_vh_ops
,
2015 .quirks
= UFSHCD_QUIRK_PRDT_BYTE_GRAN
|
2016 UFSHCI_QUIRK_SKIP_RESET_INTR_AGGR
|
2017 UFSHCD_QUIRK_BROKEN_OCS_FATAL_ERROR
|
2018 UFSHCI_QUIRK_BROKEN_HCE
|
2019 UFSHCD_QUIRK_BROKEN_UIC_CMD
|
2020 UFSHCD_QUIRK_SKIP_PH_CONFIGURATION
|
2021 UFSHCD_QUIRK_SKIP_DEF_UNIPRO_TIMEOUT_SETTING
,
2022 .opts
= EXYNOS_UFS_OPT_BROKEN_RX_SEL_IDX
,
2025 static const struct exynos_ufs_drv_data exynos_ufs_drvs
= {
2026 .uic_attr
= &exynos7_uic_attr
,
2027 .quirks
= UFSHCD_QUIRK_PRDT_BYTE_GRAN
|
2028 UFSHCI_QUIRK_BROKEN_REQ_LIST_CLR
|
2029 UFSHCI_QUIRK_BROKEN_HCE
|
2030 UFSHCI_QUIRK_SKIP_RESET_INTR_AGGR
|
2031 UFSHCD_QUIRK_BROKEN_OCS_FATAL_ERROR
|
2032 UFSHCI_QUIRK_SKIP_MANUAL_WB_FLUSH_CTRL
|
2033 UFSHCD_QUIRK_SKIP_DEF_UNIPRO_TIMEOUT_SETTING
,
2034 .opts
= EXYNOS_UFS_OPT_HAS_APB_CLK_CTRL
|
2035 EXYNOS_UFS_OPT_BROKEN_AUTO_CLK_CTRL
|
2036 EXYNOS_UFS_OPT_BROKEN_RX_SEL_IDX
|
2037 EXYNOS_UFS_OPT_SKIP_CONNECTION_ESTAB
|
2038 EXYNOS_UFS_OPT_USE_SW_HIBERN8_TIMER
,
2039 .drv_init
= exynos7_ufs_drv_init
,
2040 .pre_link
= exynos7_ufs_pre_link
,
2041 .post_link
= exynos7_ufs_post_link
,
2042 .pre_pwr_change
= exynos7_ufs_pre_pwr_change
,
2043 .post_pwr_change
= exynos7_ufs_post_pwr_change
,
2046 static struct exynos_ufs_uic_attr gs101_uic_attr
= {
2047 .tx_trailingclks
= 0xff,
2048 .tx_dif_p_nsec
= 3000000, /* unit: ns */
2049 .tx_dif_n_nsec
= 1000000, /* unit: ns */
2050 .tx_high_z_cnt_nsec
= 20000, /* unit: ns */
2051 .tx_base_unit_nsec
= 100000, /* unit: ns */
2052 .tx_gran_unit_nsec
= 4000, /* unit: ns */
2053 .tx_sleep_cnt
= 1000, /* unit: ns */
2054 .tx_min_activatetime
= 0xa,
2055 .rx_filler_enable
= 0x2,
2056 .rx_dif_p_nsec
= 1000000, /* unit: ns */
2057 .rx_hibern8_wait_nsec
= 4000000, /* unit: ns */
2058 .rx_base_unit_nsec
= 100000, /* unit: ns */
2059 .rx_gran_unit_nsec
= 4000, /* unit: ns */
2060 .rx_sleep_cnt
= 1280, /* unit: ns */
2061 .rx_stall_cnt
= 320, /* unit: ns */
2062 .rx_hs_g1_sync_len_cap
= SYNC_LEN_COARSE(0xf),
2063 .rx_hs_g2_sync_len_cap
= SYNC_LEN_COARSE(0xf),
2064 .rx_hs_g3_sync_len_cap
= SYNC_LEN_COARSE(0xf),
2065 .rx_hs_g1_prep_sync_len_cap
= PREP_LEN(0xf),
2066 .rx_hs_g2_prep_sync_len_cap
= PREP_LEN(0xf),
2067 .rx_hs_g3_prep_sync_len_cap
= PREP_LEN(0xf),
2068 .pa_dbg_opt_suite1_val
= 0x90913C1C,
2069 .pa_dbg_opt_suite1_off
= PA_GS101_DBG_OPTION_SUITE1
,
2070 .pa_dbg_opt_suite2_val
= 0xE01C115F,
2071 .pa_dbg_opt_suite2_off
= PA_GS101_DBG_OPTION_SUITE2
,
2074 static struct exynos_ufs_uic_attr fsd_uic_attr
= {
2075 .tx_trailingclks
= 0x10,
2076 .tx_dif_p_nsec
= 3000000, /* unit: ns */
2077 .tx_dif_n_nsec
= 1000000, /* unit: ns */
2078 .tx_high_z_cnt_nsec
= 20000, /* unit: ns */
2079 .tx_base_unit_nsec
= 100000, /* unit: ns */
2080 .tx_gran_unit_nsec
= 4000, /* unit: ns */
2081 .tx_sleep_cnt
= 1000, /* unit: ns */
2082 .tx_min_activatetime
= 0xa,
2083 .rx_filler_enable
= 0x2,
2084 .rx_dif_p_nsec
= 1000000, /* unit: ns */
2085 .rx_hibern8_wait_nsec
= 4000000, /* unit: ns */
2086 .rx_base_unit_nsec
= 100000, /* unit: ns */
2087 .rx_gran_unit_nsec
= 4000, /* unit: ns */
2088 .rx_sleep_cnt
= 1280, /* unit: ns */
2089 .rx_stall_cnt
= 320, /* unit: ns */
2090 .rx_hs_g1_sync_len_cap
= SYNC_LEN_COARSE(0xf),
2091 .rx_hs_g2_sync_len_cap
= SYNC_LEN_COARSE(0xf),
2092 .rx_hs_g3_sync_len_cap
= SYNC_LEN_COARSE(0xf),
2093 .rx_hs_g1_prep_sync_len_cap
= PREP_LEN(0xf),
2094 .rx_hs_g2_prep_sync_len_cap
= PREP_LEN(0xf),
2095 .rx_hs_g3_prep_sync_len_cap
= PREP_LEN(0xf),
2096 .pa_dbg_clk_period_off
= PA_DBG_CLK_PERIOD
,
2097 .pa_dbg_opt_suite1_val
= 0x2E820183,
2098 .pa_dbg_opt_suite1_off
= PA_DBG_OPTION_SUITE
,
2101 static const struct exynos_ufs_drv_data fsd_ufs_drvs
= {
2102 .uic_attr
= &fsd_uic_attr
,
2103 .quirks
= UFSHCD_QUIRK_PRDT_BYTE_GRAN
|
2104 UFSHCI_QUIRK_BROKEN_REQ_LIST_CLR
|
2105 UFSHCD_QUIRK_BROKEN_OCS_FATAL_ERROR
|
2106 UFSHCD_QUIRK_SKIP_DEF_UNIPRO_TIMEOUT_SETTING
|
2107 UFSHCI_QUIRK_SKIP_RESET_INTR_AGGR
,
2108 .opts
= EXYNOS_UFS_OPT_HAS_APB_CLK_CTRL
|
2109 EXYNOS_UFS_OPT_BROKEN_AUTO_CLK_CTRL
|
2110 EXYNOS_UFS_OPT_SKIP_CONFIG_PHY_ATTR
|
2111 EXYNOS_UFS_OPT_BROKEN_RX_SEL_IDX
,
2112 .pre_link
= fsd_ufs_pre_link
,
2113 .post_link
= fsd_ufs_post_link
,
2114 .pre_pwr_change
= fsd_ufs_pre_pwr_change
,
2117 static const struct exynos_ufs_drv_data gs101_ufs_drvs
= {
2118 .uic_attr
= &gs101_uic_attr
,
2119 .quirks
= UFSHCD_QUIRK_PRDT_BYTE_GRAN
|
2120 UFSHCI_QUIRK_SKIP_RESET_INTR_AGGR
|
2121 UFSHCI_QUIRK_BROKEN_REQ_LIST_CLR
|
2122 UFSHCD_QUIRK_BROKEN_OCS_FATAL_ERROR
|
2123 UFSHCI_QUIRK_SKIP_MANUAL_WB_FLUSH_CTRL
|
2124 UFSHCD_QUIRK_SKIP_DEF_UNIPRO_TIMEOUT_SETTING
,
2125 .opts
= EXYNOS_UFS_OPT_BROKEN_AUTO_CLK_CTRL
|
2126 EXYNOS_UFS_OPT_SKIP_CONFIG_PHY_ATTR
|
2127 EXYNOS_UFS_OPT_UFSPR_SECURE
|
2128 EXYNOS_UFS_OPT_TIMER_TICK_SELECT
,
2129 .drv_init
= exynosauto_ufs_drv_init
,
2130 .pre_link
= gs101_ufs_pre_link
,
2131 .post_link
= gs101_ufs_post_link
,
2132 .pre_pwr_change
= gs101_ufs_pre_pwr_change
,
2135 static const struct of_device_id exynos_ufs_of_match
[] = {
2136 { .compatible
= "google,gs101-ufs",
2137 .data
= &gs101_ufs_drvs
},
2138 { .compatible
= "samsung,exynos7-ufs",
2139 .data
= &exynos_ufs_drvs
},
2140 { .compatible
= "samsung,exynosautov9-ufs",
2141 .data
= &exynosauto_ufs_drvs
},
2142 { .compatible
= "samsung,exynosautov9-ufs-vh",
2143 .data
= &exynosauto_ufs_vh_drvs
},
2144 { .compatible
= "tesla,fsd-ufs",
2145 .data
= &fsd_ufs_drvs
},
2148 MODULE_DEVICE_TABLE(of
, exynos_ufs_of_match
);
2150 static const struct dev_pm_ops exynos_ufs_pm_ops
= {
2151 SET_SYSTEM_SLEEP_PM_OPS(ufshcd_system_suspend
, ufshcd_system_resume
)
2152 SET_RUNTIME_PM_OPS(ufshcd_runtime_suspend
, ufshcd_runtime_resume
, NULL
)
2153 .prepare
= ufshcd_suspend_prepare
,
2154 .complete
= ufshcd_resume_complete
,
2157 static struct platform_driver exynos_ufs_pltform
= {
2158 .probe
= exynos_ufs_probe
,
2159 .remove_new
= exynos_ufs_remove
,
2161 .name
= "exynos-ufshc",
2162 .pm
= &exynos_ufs_pm_ops
,
2163 .of_match_table
= exynos_ufs_of_match
,
2166 module_platform_driver(exynos_ufs_pltform
);
2168 MODULE_AUTHOR("Alim Akhtar <alim.akhtar@samsung.com>");
2169 MODULE_AUTHOR("Seungwon Jeon <essuuj@gmail.com>");
2170 MODULE_DESCRIPTION("Exynos UFS HCI Driver");
2171 MODULE_LICENSE("GPL v2");