1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2016, The Linux Foundation. All rights reserved.
6 #include <linux/delay.h>
11 #define PHY_14NM_CKLN_IDX 4
13 static void dsi_14nm_dphy_set_timing(struct msm_dsi_phy
*phy
,
14 struct msm_dsi_dphy_timing
*timing
,
17 void __iomem
*base
= phy
->lane_base
;
18 bool clk_ln
= (lane_idx
== PHY_14NM_CKLN_IDX
);
19 u32 zero
= clk_ln
? timing
->clk_zero
: timing
->hs_zero
;
20 u32 prepare
= clk_ln
? timing
->clk_prepare
: timing
->hs_prepare
;
21 u32 trail
= clk_ln
? timing
->clk_trail
: timing
->hs_trail
;
22 u32 rqst
= clk_ln
? timing
->hs_rqst_ckln
: timing
->hs_rqst
;
23 u32 prep_dly
= clk_ln
? timing
->hs_prep_dly_ckln
: timing
->hs_prep_dly
;
24 u32 halfbyte_en
= clk_ln
? timing
->hs_halfbyte_en_ckln
:
25 timing
->hs_halfbyte_en
;
27 dsi_phy_write(base
+ REG_DSI_14nm_PHY_LN_TIMING_CTRL_4(lane_idx
),
28 DSI_14nm_PHY_LN_TIMING_CTRL_4_HS_EXIT(timing
->hs_exit
));
29 dsi_phy_write(base
+ REG_DSI_14nm_PHY_LN_TIMING_CTRL_5(lane_idx
),
30 DSI_14nm_PHY_LN_TIMING_CTRL_5_HS_ZERO(zero
));
31 dsi_phy_write(base
+ REG_DSI_14nm_PHY_LN_TIMING_CTRL_6(lane_idx
),
32 DSI_14nm_PHY_LN_TIMING_CTRL_6_HS_PREPARE(prepare
));
33 dsi_phy_write(base
+ REG_DSI_14nm_PHY_LN_TIMING_CTRL_7(lane_idx
),
34 DSI_14nm_PHY_LN_TIMING_CTRL_7_HS_TRAIL(trail
));
35 dsi_phy_write(base
+ REG_DSI_14nm_PHY_LN_TIMING_CTRL_8(lane_idx
),
36 DSI_14nm_PHY_LN_TIMING_CTRL_8_HS_RQST(rqst
));
37 dsi_phy_write(base
+ REG_DSI_14nm_PHY_LN_CFG0(lane_idx
),
38 DSI_14nm_PHY_LN_CFG0_PREPARE_DLY(prep_dly
));
39 dsi_phy_write(base
+ REG_DSI_14nm_PHY_LN_CFG1(lane_idx
),
40 halfbyte_en
? DSI_14nm_PHY_LN_CFG1_HALFBYTECLK_EN
: 0);
41 dsi_phy_write(base
+ REG_DSI_14nm_PHY_LN_TIMING_CTRL_9(lane_idx
),
42 DSI_14nm_PHY_LN_TIMING_CTRL_9_TA_GO(timing
->ta_go
) |
43 DSI_14nm_PHY_LN_TIMING_CTRL_9_TA_SURE(timing
->ta_sure
));
44 dsi_phy_write(base
+ REG_DSI_14nm_PHY_LN_TIMING_CTRL_10(lane_idx
),
45 DSI_14nm_PHY_LN_TIMING_CTRL_10_TA_GET(timing
->ta_get
));
46 dsi_phy_write(base
+ REG_DSI_14nm_PHY_LN_TIMING_CTRL_11(lane_idx
),
47 DSI_14nm_PHY_LN_TIMING_CTRL_11_TRIG3_CMD(0xa0));
50 static int dsi_14nm_phy_enable(struct msm_dsi_phy
*phy
, int src_pll_id
,
51 struct msm_dsi_phy_clk_request
*clk_req
)
53 struct msm_dsi_dphy_timing
*timing
= &phy
->timing
;
57 void __iomem
*base
= phy
->base
;
58 void __iomem
*lane_base
= phy
->lane_base
;
60 if (msm_dsi_dphy_timing_calc_v2(timing
, clk_req
)) {
61 DRM_DEV_ERROR(&phy
->pdev
->dev
,
62 "%s: D-PHY timing calculation failed\n", __func__
);
67 if (phy
->usecase
!= MSM_DSI_PHY_STANDALONE
)
68 data
|= DSI_14nm_PHY_CMN_LDO_CNTRL_VREG_CTRL(32);
69 dsi_phy_write(base
+ REG_DSI_14nm_PHY_CMN_LDO_CNTRL
, data
);
71 dsi_phy_write(base
+ REG_DSI_14nm_PHY_CMN_GLBL_TEST_CTRL
, 0x1);
73 /* 4 data lanes + 1 clk lane configuration */
74 for (i
= 0; i
< 5; i
++) {
75 dsi_phy_write(lane_base
+ REG_DSI_14nm_PHY_LN_VREG_CNTRL(i
),
78 dsi_phy_write(lane_base
+
79 REG_DSI_14nm_PHY_LN_STRENGTH_CTRL_0(i
), 0xff);
80 dsi_phy_write(lane_base
+
81 REG_DSI_14nm_PHY_LN_STRENGTH_CTRL_1(i
),
82 (i
== PHY_14NM_CKLN_IDX
) ? 0x00 : 0x06);
84 dsi_phy_write(lane_base
+ REG_DSI_14nm_PHY_LN_CFG3(i
),
85 (i
== PHY_14NM_CKLN_IDX
) ? 0x8f : 0x0f);
86 dsi_phy_write(lane_base
+ REG_DSI_14nm_PHY_LN_CFG2(i
), 0x10);
87 dsi_phy_write(lane_base
+ REG_DSI_14nm_PHY_LN_TEST_DATAPATH(i
),
89 dsi_phy_write(lane_base
+ REG_DSI_14nm_PHY_LN_TEST_STR(i
),
92 dsi_14nm_dphy_set_timing(phy
, timing
, i
);
95 /* Make sure PLL is not start */
96 dsi_phy_write(base
+ REG_DSI_14nm_PHY_CMN_PLL_CNTRL
, 0x00);
98 wmb(); /* make sure everything is written before reset and enable */
100 /* reset digital block */
101 dsi_phy_write(base
+ REG_DSI_14nm_PHY_CMN_CTRL_1
, 0x80);
102 wmb(); /* ensure reset is asserted */
104 dsi_phy_write(base
+ REG_DSI_14nm_PHY_CMN_CTRL_1
, 0x00);
106 msm_dsi_phy_set_src_pll(phy
, src_pll_id
,
107 REG_DSI_14nm_PHY_CMN_GLBL_TEST_CTRL
,
108 DSI_14nm_PHY_CMN_GLBL_TEST_CTRL_BITCLK_HS_SEL
);
110 ret
= msm_dsi_pll_set_usecase(phy
->pll
, phy
->usecase
);
112 DRM_DEV_ERROR(&phy
->pdev
->dev
, "%s: set pll usecase failed, %d\n",
117 /* Remove power down from PLL and all lanes */
118 dsi_phy_write(base
+ REG_DSI_14nm_PHY_CMN_CTRL_0
, 0xff);
123 static void dsi_14nm_phy_disable(struct msm_dsi_phy
*phy
)
125 dsi_phy_write(phy
->base
+ REG_DSI_14nm_PHY_CMN_GLBL_TEST_CTRL
, 0);
126 dsi_phy_write(phy
->base
+ REG_DSI_14nm_PHY_CMN_CTRL_0
, 0);
128 /* ensure that the phy is completely disabled */
132 static int dsi_14nm_phy_init(struct msm_dsi_phy
*phy
)
134 struct platform_device
*pdev
= phy
->pdev
;
136 phy
->lane_base
= msm_ioremap(pdev
, "dsi_phy_lane",
138 if (IS_ERR(phy
->lane_base
)) {
139 DRM_DEV_ERROR(&pdev
->dev
, "%s: failed to map phy lane base\n",
147 const struct msm_dsi_phy_cfg dsi_phy_14nm_cfgs
= {
148 .type
= MSM_DSI_PHY_14NM
,
149 .src_pll_truthtable
= { {false, false}, {true, false} },
157 .enable
= dsi_14nm_phy_enable
,
158 .disable
= dsi_14nm_phy_disable
,
159 .init
= dsi_14nm_phy_init
,
161 .io_start
= { 0x994400, 0x996400 },
165 const struct msm_dsi_phy_cfg dsi_phy_14nm_660_cfgs
= {
166 .type
= MSM_DSI_PHY_14NM
,
167 .src_pll_truthtable
= { {false, false}, {true, false} },
175 .enable
= dsi_14nm_phy_enable
,
176 .disable
= dsi_14nm_phy_disable
,
177 .init
= dsi_14nm_phy_init
,
179 .io_start
= { 0xc994400, 0xc996000 },