2 * Copyright (c) 2016, The Linux Foundation. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
17 #define PHY_14NM_CKLN_IDX 4
19 static void dsi_14nm_dphy_set_timing(struct msm_dsi_phy *phy,
20 struct msm_dsi_dphy_timing *timing,
23 void __iomem *base = phy->lane_base;
24 bool clk_ln = (lane_idx == PHY_14NM_CKLN_IDX);
25 u32 zero = clk_ln ? timing->clk_zero : timing->hs_zero;
26 u32 prepare = clk_ln ? timing->clk_prepare : timing->hs_prepare;
27 u32 trail = clk_ln ? timing->clk_trail : timing->hs_trail;
28 u32 rqst = clk_ln ? timing->hs_rqst_ckln : timing->hs_rqst;
29 u32 prep_dly = clk_ln ? timing->hs_prep_dly_ckln : timing->hs_prep_dly;
30 u32 halfbyte_en = clk_ln ? timing->hs_halfbyte_en_ckln :
31 timing->hs_halfbyte_en;
33 dsi_phy_write(base + REG_DSI_14nm_PHY_LN_TIMING_CTRL_4(lane_idx),
34 DSI_14nm_PHY_LN_TIMING_CTRL_4_HS_EXIT(timing->hs_exit));
35 dsi_phy_write(base + REG_DSI_14nm_PHY_LN_TIMING_CTRL_5(lane_idx),
36 DSI_14nm_PHY_LN_TIMING_CTRL_5_HS_ZERO(zero));
37 dsi_phy_write(base + REG_DSI_14nm_PHY_LN_TIMING_CTRL_6(lane_idx),
38 DSI_14nm_PHY_LN_TIMING_CTRL_6_HS_PREPARE(prepare));
39 dsi_phy_write(base + REG_DSI_14nm_PHY_LN_TIMING_CTRL_7(lane_idx),
40 DSI_14nm_PHY_LN_TIMING_CTRL_7_HS_TRAIL(trail));
41 dsi_phy_write(base + REG_DSI_14nm_PHY_LN_TIMING_CTRL_8(lane_idx),
42 DSI_14nm_PHY_LN_TIMING_CTRL_8_HS_RQST(rqst));
43 dsi_phy_write(base + REG_DSI_14nm_PHY_LN_CFG0(lane_idx),
44 DSI_14nm_PHY_LN_CFG0_PREPARE_DLY(prep_dly));
45 dsi_phy_write(base + REG_DSI_14nm_PHY_LN_CFG1(lane_idx),
46 halfbyte_en ? DSI_14nm_PHY_LN_CFG1_HALFBYTECLK_EN : 0);
47 dsi_phy_write(base + REG_DSI_14nm_PHY_LN_TIMING_CTRL_9(lane_idx),
48 DSI_14nm_PHY_LN_TIMING_CTRL_9_TA_GO(timing->ta_go) |
49 DSI_14nm_PHY_LN_TIMING_CTRL_9_TA_SURE(timing->ta_sure));
50 dsi_phy_write(base + REG_DSI_14nm_PHY_LN_TIMING_CTRL_10(lane_idx),
51 DSI_14nm_PHY_LN_TIMING_CTRL_10_TA_GET(timing->ta_get));
52 dsi_phy_write(base + REG_DSI_14nm_PHY_LN_TIMING_CTRL_11(lane_idx),
53 DSI_14nm_PHY_LN_TIMING_CTRL_11_TRIG3_CMD(0xa0));
56 static int dsi_14nm_phy_enable(struct msm_dsi_phy *phy, int src_pll_id,
57 struct msm_dsi_phy_clk_request *clk_req)
59 struct msm_dsi_dphy_timing *timing = &phy->timing;
63 void __iomem *base = phy->base;
64 void __iomem *lane_base = phy->lane_base;
66 if (msm_dsi_dphy_timing_calc_v2(timing, clk_req)) {
67 dev_err(&phy->pdev->dev,
68 "%s: D-PHY timing calculation failed\n", __func__);
73 if (phy->usecase != MSM_DSI_PHY_STANDALONE)
74 data |= DSI_14nm_PHY_CMN_LDO_CNTRL_VREG_CTRL(32);
75 dsi_phy_write(base + REG_DSI_14nm_PHY_CMN_LDO_CNTRL, data);
77 dsi_phy_write(base + REG_DSI_14nm_PHY_CMN_GLBL_TEST_CTRL, 0x1);
79 /* 4 data lanes + 1 clk lane configuration */
80 for (i = 0; i < 5; i++) {
81 dsi_phy_write(lane_base + REG_DSI_14nm_PHY_LN_VREG_CNTRL(i),
84 dsi_phy_write(lane_base +
85 REG_DSI_14nm_PHY_LN_STRENGTH_CTRL_0(i), 0xff);
86 dsi_phy_write(lane_base +
87 REG_DSI_14nm_PHY_LN_STRENGTH_CTRL_1(i),
88 (i == PHY_14NM_CKLN_IDX) ? 0x00 : 0x06);
90 dsi_phy_write(lane_base + REG_DSI_14nm_PHY_LN_CFG3(i),
91 (i == PHY_14NM_CKLN_IDX) ? 0x8f : 0x0f);
92 dsi_phy_write(lane_base + REG_DSI_14nm_PHY_LN_CFG2(i), 0x10);
93 dsi_phy_write(lane_base + REG_DSI_14nm_PHY_LN_TEST_DATAPATH(i),
95 dsi_phy_write(lane_base + REG_DSI_14nm_PHY_LN_TEST_STR(i),
98 dsi_14nm_dphy_set_timing(phy, timing, i);
101 /* Make sure PLL is not start */
102 dsi_phy_write(base + REG_DSI_14nm_PHY_CMN_PLL_CNTRL, 0x00);
104 wmb(); /* make sure everything is written before reset and enable */
106 /* reset digital block */
107 dsi_phy_write(base + REG_DSI_14nm_PHY_CMN_CTRL_1, 0x80);
108 wmb(); /* ensure reset is asserted */
110 dsi_phy_write(base + REG_DSI_14nm_PHY_CMN_CTRL_1, 0x00);
112 msm_dsi_phy_set_src_pll(phy, src_pll_id,
113 REG_DSI_14nm_PHY_CMN_GLBL_TEST_CTRL,
114 DSI_14nm_PHY_CMN_GLBL_TEST_CTRL_BITCLK_HS_SEL);
116 ret = msm_dsi_pll_set_usecase(phy->pll, phy->usecase);
118 dev_err(&phy->pdev->dev, "%s: set pll usecase failed, %d\n",
123 /* Remove power down from PLL and all lanes */
124 dsi_phy_write(base + REG_DSI_14nm_PHY_CMN_CTRL_0, 0xff);
129 static void dsi_14nm_phy_disable(struct msm_dsi_phy *phy)
131 dsi_phy_write(phy->base + REG_DSI_14nm_PHY_CMN_GLBL_TEST_CTRL, 0);
132 dsi_phy_write(phy->base + REG_DSI_14nm_PHY_CMN_CTRL_0, 0);
134 /* ensure that the phy is completely disabled */
138 static int dsi_14nm_phy_init(struct msm_dsi_phy *phy)
140 struct platform_device *pdev = phy->pdev;
142 phy->lane_base = msm_ioremap(pdev, "dsi_phy_lane",
144 if (IS_ERR(phy->lane_base)) {
145 dev_err(&pdev->dev, "%s: failed to map phy lane base\n",
153 const struct msm_dsi_phy_cfg dsi_phy_14nm_cfgs = {
154 .type = MSM_DSI_PHY_14NM,
155 .src_pll_truthtable = { {false, false}, {true, false} },
163 .enable = dsi_14nm_phy_enable,
164 .disable = dsi_14nm_phy_disable,
165 .init = dsi_14nm_phy_init,
167 .io_start = { 0x994400, 0x996400 },