2 * SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2018, The Linux Foundation
6 #include <linux/iopoll.h>
11 static int dsi_phy_hw_v4_0_is_pll_on(struct msm_dsi_phy *phy)
13 void __iomem *base = phy->base;
16 data = dsi_phy_read(base + REG_DSI_7nm_PHY_CMN_PLL_CNTRL);
17 mb(); /* make sure read happened */
19 return (data & BIT(0));
22 static void dsi_phy_hw_v4_0_config_lpcdrx(struct msm_dsi_phy *phy, bool enable)
24 void __iomem *lane_base = phy->lane_base;
25 int phy_lane_0 = 0; /* TODO: Support all lane swap configs */
28 * LPRX and CDRX need to enabled only for physical data lane
29 * corresponding to the logical data lane 0
32 dsi_phy_write(lane_base +
33 REG_DSI_7nm_PHY_LN_LPRX_CTRL(phy_lane_0), 0x3);
35 dsi_phy_write(lane_base +
36 REG_DSI_7nm_PHY_LN_LPRX_CTRL(phy_lane_0), 0);
39 static void dsi_phy_hw_v4_0_lane_settings(struct msm_dsi_phy *phy)
42 const u8 tx_dctrl_0[] = { 0x00, 0x00, 0x00, 0x04, 0x01 };
43 const u8 tx_dctrl_1[] = { 0x40, 0x40, 0x40, 0x46, 0x41 };
44 const u8 *tx_dctrl = tx_dctrl_0;
45 void __iomem *lane_base = phy->lane_base;
47 if (phy->cfg->type == MSM_DSI_PHY_7NM_V4_1)
48 tx_dctrl = tx_dctrl_1;
50 /* Strength ctrl settings */
51 for (i = 0; i < 5; i++) {
53 * Disable LPRX and CDRX for all lanes. And later on, it will
54 * be only enabled for the physical data lane corresponding
55 * to the logical data lane 0
57 dsi_phy_write(lane_base + REG_DSI_7nm_PHY_LN_LPRX_CTRL(i), 0);
58 dsi_phy_write(lane_base + REG_DSI_7nm_PHY_LN_PIN_SWAP(i), 0x0);
61 dsi_phy_hw_v4_0_config_lpcdrx(phy, true);
64 for (i = 0; i < 5; i++) {
65 dsi_phy_write(lane_base + REG_DSI_7nm_PHY_LN_CFG0(i), 0x0);
66 dsi_phy_write(lane_base + REG_DSI_7nm_PHY_LN_CFG1(i), 0x0);
67 dsi_phy_write(lane_base + REG_DSI_7nm_PHY_LN_CFG2(i), i == 4 ? 0x8a : 0xa);
68 dsi_phy_write(lane_base + REG_DSI_7nm_PHY_LN_TX_DCTRL(i), tx_dctrl[i]);
72 static int dsi_7nm_phy_enable(struct msm_dsi_phy *phy, int src_pll_id,
73 struct msm_dsi_phy_clk_request *clk_req)
77 u32 const delay_us = 5;
78 u32 const timeout_us = 1000;
79 struct msm_dsi_dphy_timing *timing = &phy->timing;
80 void __iomem *base = phy->base;
81 bool less_than_1500_mhz;
82 u32 vreg_ctrl_0, glbl_str_swi_cal_sel_ctrl, glbl_hstx_str_ctrl_0;
83 u32 glbl_rescode_top_ctrl, glbl_rescode_bot_ctrl;
88 if (msm_dsi_dphy_timing_calc_v4(timing, clk_req)) {
89 DRM_DEV_ERROR(&phy->pdev->dev,
90 "%s: D-PHY timing calculation failed\n", __func__);
94 if (dsi_phy_hw_v4_0_is_pll_on(phy))
95 pr_warn("PLL turned on before configuring PHY\n");
97 /* wait for REFGEN READY */
98 ret = readl_poll_timeout_atomic(base + REG_DSI_7nm_PHY_CMN_PHY_STATUS,
99 status, (status & BIT(0)),
100 delay_us, timeout_us);
102 pr_err("Ref gen not ready. Aborting\n");
106 /* TODO: CPHY enable path (this is for DPHY only) */
108 /* Alter PHY configurations if data rate less than 1.5GHZ*/
109 less_than_1500_mhz = (clk_req->bitclk_rate <= 1500000000);
111 if (phy->cfg->type == MSM_DSI_PHY_7NM_V4_1) {
112 vreg_ctrl_0 = less_than_1500_mhz ? 0x53 : 0x52;
113 glbl_rescode_top_ctrl = less_than_1500_mhz ? 0x3d : 0x00;
114 glbl_rescode_bot_ctrl = less_than_1500_mhz ? 0x39 : 0x3c;
115 glbl_str_swi_cal_sel_ctrl = 0x00;
116 glbl_hstx_str_ctrl_0 = 0x88;
118 vreg_ctrl_0 = less_than_1500_mhz ? 0x5B : 0x59;
119 glbl_str_swi_cal_sel_ctrl = less_than_1500_mhz ? 0x03 : 0x00;
120 glbl_hstx_str_ctrl_0 = less_than_1500_mhz ? 0x66 : 0x88;
121 glbl_rescode_top_ctrl = 0x03;
122 glbl_rescode_bot_ctrl = 0x3c;
125 /* de-assert digital and pll power down */
126 data = BIT(6) | BIT(5);
127 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_CTRL_0, data);
129 /* Assert PLL core reset */
130 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_PLL_CNTRL, 0x00);
132 /* turn off resync FIFO */
133 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_RBUF_CTRL, 0x00);
135 /* program CMN_CTRL_4 for minor_ver 2 chipsets*/
136 data = dsi_phy_read(base + REG_DSI_7nm_PHY_CMN_REVISION_ID0);
137 data = data & (0xf0);
139 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_CTRL_4, 0x04);
141 /* Configure PHY lane swap (TODO: we need to calculate this) */
142 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_LANE_CFG0, 0x21);
143 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_LANE_CFG1, 0x84);
146 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_VREG_CTRL_0, vreg_ctrl_0);
147 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_VREG_CTRL_1, 0x5c);
148 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_CTRL_3, 0x00);
149 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_GLBL_STR_SWI_CAL_SEL_CTRL,
150 glbl_str_swi_cal_sel_ctrl);
151 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_GLBL_HSTX_STR_CTRL_0,
152 glbl_hstx_str_ctrl_0);
153 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_GLBL_PEMPH_CTRL_0, 0x00);
154 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_GLBL_RESCODE_OFFSET_TOP_CTRL,
155 glbl_rescode_top_ctrl);
156 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_GLBL_RESCODE_OFFSET_BOT_CTRL,
157 glbl_rescode_bot_ctrl);
158 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_GLBL_LPTX_STR_CTRL, 0x55);
160 /* Remove power down from all blocks */
161 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_CTRL_0, 0x7f);
163 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_LANE_CTRL0, 0x1f);
165 /* Select full-rate mode */
166 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_CTRL_2, 0x40);
168 ret = msm_dsi_pll_set_usecase(phy->pll, phy->usecase);
170 DRM_DEV_ERROR(&phy->pdev->dev, "%s: set pll usecase failed, %d\n",
175 /* DSI PHY timings */
176 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_TIMING_CTRL_0, 0x00);
177 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_TIMING_CTRL_1, timing->clk_zero);
178 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_TIMING_CTRL_2, timing->clk_prepare);
179 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_TIMING_CTRL_3, timing->clk_trail);
180 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_TIMING_CTRL_4, timing->hs_exit);
181 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_TIMING_CTRL_5, timing->hs_zero);
182 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_TIMING_CTRL_6, timing->hs_prepare);
183 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_TIMING_CTRL_7, timing->hs_trail);
184 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_TIMING_CTRL_8, timing->hs_rqst);
185 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_TIMING_CTRL_9, 0x02);
186 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_TIMING_CTRL_10, 0x04);
187 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_TIMING_CTRL_11, 0x00);
188 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_TIMING_CTRL_12,
189 timing->shared_timings.clk_pre);
190 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_TIMING_CTRL_13,
191 timing->shared_timings.clk_post);
193 /* DSI lane settings */
194 dsi_phy_hw_v4_0_lane_settings(phy);
196 DBG("DSI%d PHY enabled", phy->id);
201 static void dsi_7nm_phy_disable(struct msm_dsi_phy *phy)
203 void __iomem *base = phy->base;
208 if (dsi_phy_hw_v4_0_is_pll_on(phy))
209 pr_warn("Turning OFF PHY while PLL is on\n");
211 dsi_phy_hw_v4_0_config_lpcdrx(phy, false);
212 data = dsi_phy_read(base + REG_DSI_7nm_PHY_CMN_CTRL_0);
214 /* disable all lanes */
216 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_CTRL_0, data);
217 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_LANE_CTRL0, 0);
219 /* Turn off all PHY blocks */
220 dsi_phy_write(base + REG_DSI_7nm_PHY_CMN_CTRL_0, 0x00);
221 /* make sure phy is turned off */
224 DBG("DSI%d PHY disabled", phy->id);
227 static int dsi_7nm_phy_init(struct msm_dsi_phy *phy)
229 struct platform_device *pdev = phy->pdev;
231 phy->lane_base = msm_ioremap(pdev, "dsi_phy_lane",
233 if (IS_ERR(phy->lane_base)) {
234 DRM_DEV_ERROR(&pdev->dev, "%s: failed to map phy lane base\n",
242 const struct msm_dsi_phy_cfg dsi_phy_7nm_cfgs = {
243 .type = MSM_DSI_PHY_7NM_V4_1,
244 .src_pll_truthtable = { {false, false}, {true, false} },
252 .enable = dsi_7nm_phy_enable,
253 .disable = dsi_7nm_phy_disable,
254 .init = dsi_7nm_phy_init,
256 .io_start = { 0xae94400, 0xae96400 },
260 const struct msm_dsi_phy_cfg dsi_phy_7nm_8150_cfgs = {
261 .type = MSM_DSI_PHY_7NM,
262 .src_pll_truthtable = { {false, false}, {true, false} },
270 .enable = dsi_7nm_phy_enable,
271 .disable = dsi_7nm_phy_disable,
272 .init = dsi_7nm_phy_init,
274 .io_start = { 0xae94400, 0xae96400 },