blob: 80a85bc46453803f92c62b9094cae4957ce702fc [file] [log] [blame]
Padmanabhan Komandurubd8268a2018-04-30 17:05:56 +05301/* Copyright (c) 2012-2015, 2018, The Linux Foundation. All rights reserved.
Shashank Mittal4bfb2e32012-04-16 10:56:27 -07002 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -080012 * * Neither the name of The Linux Foundation nor the names of its
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070013 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29#include <debug.h>
30#include <reg.h>
31#include <mipi_dsi.h>
Veera Sundaram Sankarandb0b2bf2014-12-16 18:09:27 -080032#include <mdp5.h>
33#include <platform/timer.h>
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070034#include <platform/iomap.h>
Prashant Nukala33715aa2015-06-15 21:32:43 +053035#include <target/display.h>
Veera Sundaram Sankarandb0b2bf2014-12-16 18:09:27 -080036#include <arch/defines.h>
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070037
Siddhartha Agrawal1b2ed842013-05-29 18:02:28 -070038#if (DISPLAY_TYPE_MDSS == 0)
39#define MIPI_DSI0_BASE MIPI_DSI_BASE
40#define MIPI_DSI1_BASE MIPI_DSI_BASE
41#endif
42
Dhaval Patelee8c9b32014-08-12 16:18:50 -070043#define MMSS_DSI_CLKOUT_TIMING_CTRL 0x0c4
44#define MMSS_DSI_PHY_TIMING_CTRL_0 0x0140
45#define MMSS_DSI_PHY_CTRL_0 0x0170
46#define MMSS_DSI_PHY_CTRL_1 0x0174
47#define MMSS_DSI_PHY_CTRL_2 0x0178
48#define MMSS_DSI_PHY_STRENGTH_CTRL_0 0x0184
49#define MMSS_DSI_PHY_STRENGTH_CTRL_1 0x0188
50#define MMSS_DSI_PHY_BIST_CTRL_0 0x01b4
51#define MMSS_DSI_PHY_GLBL_TEST_CTRL 0x01d4
Jeevan Shriram01379322015-01-07 17:41:26 -080052#define MDSS_DSI_DSIPHY_REGULATOR_CTRL_0 0x00
53#define MDSS_DSI_DSIPHY_REGULATOR_CTRL_1 0x04
54#define MDSS_DSI_DSIPHY_REGULATOR_CTRL_2 0x08
55#define MDSS_DSI_DSIPHY_REGULATOR_CTRL_3 0x0c
56#define MDSS_DSI_DSIPHY_REGULATOR_CTRL_4 0x10
57#define MDSS_DSI_DSIPHY_REGULATOR_CAL_PWR_CFG 0x18
Dhaval Patelee8c9b32014-08-12 16:18:50 -070058#define MMSS_DSI_PHY_LDO_CTRL 0x01dc
59
60#define TOTAL_TIMING_CTRL_CONFIG 12
61#define TOTAL_BIST_CTRL_CONFIG 6
62/* 4 data lanes and 1 clock lanes */
63#define TOTAL_LANE_COUNT 5
64#define CONFIG_REG_FOR_EACH_LANE 9
65
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -080066static void mipi_dsi_calibration(uint32_t ctl_base)
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070067{
68 uint32_t i = 0;
69 uint32_t term_cnt = 5000;
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -080070 int32_t cal_busy = readl(ctl_base + 0x550);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070071
72 /* DSI1_DSIPHY_REGULATOR_CAL_PWR_CFG */
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -080073 writel(0x01, ctl_base + 0x0518);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070074
75 /* DSI1_DSIPHY_CAL_SW_CFG2 */
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -080076 writel(0x0, ctl_base + 0x0534);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070077 /* DSI1_DSIPHY_CAL_HW_CFG1 */
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -080078 writel(0x5a, ctl_base + 0x053c);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070079 /* DSI1_DSIPHY_CAL_HW_CFG3 */
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -080080 writel(0x10, ctl_base + 0x0544);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070081 /* DSI1_DSIPHY_CAL_HW_CFG4 */
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -080082 writel(0x01, ctl_base + 0x0548);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070083 /* DSI1_DSIPHY_CAL_HW_CFG0 */
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -080084 writel(0x01, ctl_base + 0x0538);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070085
86 /* DSI1_DSIPHY_CAL_HW_TRIGGER */
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -080087 writel(0x01, ctl_base + 0x0528);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070088
89 /* DSI1_DSIPHY_CAL_HW_TRIGGER */
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -080090 writel(0x00, ctl_base + 0x0528);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070091
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -080092 cal_busy = readl(ctl_base + 0x550);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070093 while (cal_busy & 0x10) {
94 i++;
95 if (i > term_cnt) {
96 dprintf(CRITICAL, "DSI1 PHY REGULATOR NOT READY,"
97 "exceeded polling TIMEOUT!\n");
98 break;
99 }
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800100 cal_busy = readl(ctl_base + 0x550);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700101 }
102}
103
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800104#if (DISPLAY_TYPE_MDSS == 0)
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700105int mipi_dsi_phy_init(struct mipi_dsi_panel_config *pinfo)
106{
107 struct mipi_dsi_phy_ctrl *pd;
108 uint32_t i, off = 0;
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530109 int mdp_rev;
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700110
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530111 mdp_rev = mdp_get_revision();
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700112
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530113 if (MDP_REV_303 == mdp_rev || MDP_REV_41 == mdp_rev) {
114 writel(0x00000001, DSIPHY_SW_RESET);
115 writel(0x00000000, DSIPHY_SW_RESET);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700116
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530117 pd = (pinfo->dsi_phy_config);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700118
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530119 off = 0x02cc; /* regulator ctrl 0 */
120 for (i = 0; i < 4; i++) {
121 writel(pd->regulator[i], MIPI_DSI_BASE + off);
122 off += 4;
123 }
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700124
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530125 off = 0x0260; /* phy timig ctrl 0 */
126 for (i = 0; i < 11; i++) {
127 writel(pd->timing[i], MIPI_DSI_BASE + off);
128 off += 4;
129 }
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700130
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530131 /* T_CLK_POST, T_CLK_PRE for CLK lane P/N HS 200 mV timing
132 length should > data lane HS timing length */
133 writel(0xa1e, DSI_CLKOUT_TIMING_CTRL);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700134
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530135 off = 0x0290; /* ctrl 0 */
136 for (i = 0; i < 4; i++) {
137 writel(pd->ctrl[i], MIPI_DSI_BASE + off);
138 off += 4;
139 }
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700140
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530141 off = 0x02a0; /* strength 0 */
142 for (i = 0; i < 4; i++) {
143 writel(pd->strength[i], MIPI_DSI_BASE + off);
144 off += 4;
145 }
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700146
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530147 if (1 == pinfo->num_of_lanes)
148 pd->pll[10] |= 0x8;
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700149
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530150 off = 0x0204; /* pll ctrl 1, skip 0 */
151 for (i = 1; i < 21; i++) {
152 writel(pd->pll[i], MIPI_DSI_BASE + off);
153 off += 4;
154 }
155
156 /* pll ctrl 0 */
157 writel(pd->pll[0], MIPI_DSI_BASE + 0x200);
158 writel((pd->pll[0] | 0x01), MIPI_DSI_BASE + 0x200);
159 /* lane swp ctrol */
160 if (pinfo->lane_swap)
161 writel(pinfo->lane_swap, MIPI_DSI_BASE + 0xac);
162 } else {
163 writel(0x0001, MIPI_DSI_BASE + 0x128); /* start phy sw reset */
164 writel(0x0000, MIPI_DSI_BASE + 0x128); /* end phy w reset */
165 writel(0x0003, MIPI_DSI_BASE + 0x500); /* regulator_ctrl_0 */
166 writel(0x0001, MIPI_DSI_BASE + 0x504); /* regulator_ctrl_1 */
167 writel(0x0001, MIPI_DSI_BASE + 0x508); /* regulator_ctrl_2 */
168 writel(0x0000, MIPI_DSI_BASE + 0x50c); /* regulator_ctrl_3 */
169 writel(0x0100, MIPI_DSI_BASE + 0x510); /* regulator_ctrl_4 */
170
171 pd = (pinfo->dsi_phy_config);
172
173 off = 0x0480; /* strength 0 - 2 */
174 for (i = 0; i < 3; i++) {
175 writel(pd->strength[i], MIPI_DSI_BASE + off);
176 off += 4;
177 }
178
179 off = 0x0470; /* ctrl 0 - 3 */
180 for (i = 0; i < 4; i++) {
181 writel(pd->ctrl[i], MIPI_DSI_BASE + off);
182 off += 4;
183 }
184
185 off = 0x0500; /* regulator ctrl 0 - 4 */
186 for (i = 0; i < 5; i++) {
187 writel(pd->regulator[i], MIPI_DSI_BASE + off);
188 off += 4;
189 }
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800190 mipi_dsi_calibration(MIPI_DSI_BASE);
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530191
192 off = 0x0204; /* pll ctrl 1 - 19, skip 0 */
193 for (i = 1; i < 20; i++) {
194 writel(pd->pll[i], MIPI_DSI_BASE + off);
195 off += 4;
196 }
197
198 /* pll ctrl 0 */
199 writel(pd->pll[0], MIPI_DSI_BASE + 0x200);
200 writel((pd->pll[0] | 0x01), MIPI_DSI_BASE + 0x200);
201
202 /* Check that PHY is ready */
203 while (!(readl(DSIPHY_PLL_RDY) & 0x01))
204 udelay(1);
205
206 writel(0x202D, DSI_CLKOUT_TIMING_CTRL);
207
208 off = 0x0440; /* phy timing ctrl 0 - 11 */
209 for (i = 0; i < 12; i++) {
210 writel(pd->timing[i], MIPI_DSI_BASE + off);
211 off += 4;
212 }
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700213 }
214 return 0;
215}
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800216#endif
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800217
Siddhartha Agrawal1b2ed842013-05-29 18:02:28 -0700218void mdss_dsi_phy_sw_reset(uint32_t ctl_base)
Chandan Uddaraju932723b2013-02-21 18:36:20 -0800219{
220 /* start phy sw reset */
Siddhartha Agrawal1b2ed842013-05-29 18:02:28 -0700221 writel(0x0001, ctl_base + 0x012c);
Chandan Uddaraju932723b2013-02-21 18:36:20 -0800222 udelay(1000);
Dhaval Patel8b9a5822015-03-16 13:01:26 -0700223 dmb();
Chandan Uddaraju932723b2013-02-21 18:36:20 -0800224
225 /* end phy sw reset */
Siddhartha Agrawal1b2ed842013-05-29 18:02:28 -0700226 writel(0x0000, ctl_base + 0x012c);
Chandan Uddaraju932723b2013-02-21 18:36:20 -0800227 udelay(100);
Dhaval Patel8b9a5822015-03-16 13:01:26 -0700228 dmb();
Chandan Uddaraju932723b2013-02-21 18:36:20 -0800229}
230
Jeevan Shriram01379322015-01-07 17:41:26 -0800231static void mdss_dsi_20nm_phy_regulator_init(struct mdss_dsi_phy_ctrl *pd,
232 uint32_t phy_base, uint32_t reg_base)
Jeevan Shrirama0623d52014-12-14 14:25:48 -0800233{
234 /* DSI0 and DSI1 have a common regulator */
Jeevan Shrirama0623d52014-12-14 14:25:48 -0800235 if (pd->regulator_mode == DSI_PHY_REGULATOR_LDO_MODE) {
236 /* LDO ctrl */
Jeevan Shriram01379322015-01-07 17:41:26 -0800237 writel(0x1d, phy_base + MMSS_DSI_PHY_LDO_CTRL);
Jeevan Shrirama0623d52014-12-14 14:25:48 -0800238 } else {
239 /* Regulator ctrl 1 */
Jeevan Shriram01379322015-01-07 17:41:26 -0800240 writel(pd->regulator[1], reg_base + MDSS_DSI_DSIPHY_REGULATOR_CTRL_1);
Jeevan Shrirama0623d52014-12-14 14:25:48 -0800241 /* Regulator ctrl 2 */
Jeevan Shriram01379322015-01-07 17:41:26 -0800242 writel(pd->regulator[2], reg_base + MDSS_DSI_DSIPHY_REGULATOR_CTRL_2);
Jeevan Shrirama0623d52014-12-14 14:25:48 -0800243 /* Regulator ctrl 3 */
Jeevan Shriram01379322015-01-07 17:41:26 -0800244 writel(pd->regulator[3], reg_base + MDSS_DSI_DSIPHY_REGULATOR_CTRL_3);
Jeevan Shrirama0623d52014-12-14 14:25:48 -0800245 /* Regulator ctrl 4 */
Jeevan Shriram01379322015-01-07 17:41:26 -0800246 writel(pd->regulator[4], reg_base + MDSS_DSI_DSIPHY_REGULATOR_CTRL_4);
Jeevan Shrirama0623d52014-12-14 14:25:48 -0800247 /* Regulator ctrl - CAL_PWR_CFG */
Jeevan Shriram01379322015-01-07 17:41:26 -0800248 writel(pd->regulator[6], reg_base + MDSS_DSI_DSIPHY_REGULATOR_CAL_PWR_CFG);
Jeevan Shrirama0623d52014-12-14 14:25:48 -0800249 /* LDO ctrl */
Jeevan Shriram01379322015-01-07 17:41:26 -0800250 writel(0x00, phy_base + MMSS_DSI_PHY_LDO_CTRL);
Jeevan Shrirama0623d52014-12-14 14:25:48 -0800251 /* Regulator ctrl 0 */
Jeevan Shriram01379322015-01-07 17:41:26 -0800252 writel(pd->regulator[0], reg_base + MDSS_DSI_DSIPHY_REGULATOR_CTRL_0);
Jeevan Shrirama0623d52014-12-14 14:25:48 -0800253 dmb();
254 }
255}
256
Prashant Nukala33715aa2015-06-15 21:32:43 +0530257static void mdss_dsi_phy_regulator_init(struct mdss_dsi_phy_ctrl *pd, uint32_t ctl_base,
258 uint32_t phy_base, uint32_t reg_base)
Siddhartha Agrawal1b2ed842013-05-29 18:02:28 -0700259{
260 /* DSI0 and DSI1 have a common regulator */
Siddhartha Agrawal1b2ed842013-05-29 18:02:28 -0700261
Padmanabhan Komanduru2232c142014-10-29 00:06:24 +0530262 if (pd->regulator_mode == DSI_PHY_REGULATOR_LDO_MODE) {
263 /* Regulator ctrl 0 */
Prashant Nukala33715aa2015-06-15 21:32:43 +0530264 writel(0x00, reg_base + (4 * 0));
Padmanabhan Komanduru2232c142014-10-29 00:06:24 +0530265 /* Regulator ctrl - CAL_PWD_CFG */
Prashant Nukala33715aa2015-06-15 21:32:43 +0530266 writel(pd->regulator[6], reg_base + (4 * 6));
Padmanabhan Komanduru2232c142014-10-29 00:06:24 +0530267 /* Add h/w recommended delay */
268 udelay(1000);
269 /* Regulator ctrl - TEST */
Prashant Nukala33715aa2015-06-15 21:32:43 +0530270 writel(pd->regulator[5], reg_base + (4 * 5));
Padmanabhan Komanduru2232c142014-10-29 00:06:24 +0530271 /* Regulator ctrl 3 */
Prashant Nukala33715aa2015-06-15 21:32:43 +0530272 writel(pd->regulator[3], reg_base + (4 * 3));
Padmanabhan Komanduru2232c142014-10-29 00:06:24 +0530273 /* Regulator ctrl 2 */
Prashant Nukala33715aa2015-06-15 21:32:43 +0530274 writel(pd->regulator[2], reg_base + (4 * 2));
Padmanabhan Komanduru2232c142014-10-29 00:06:24 +0530275 /* Regulator ctrl 1 */
Prashant Nukala33715aa2015-06-15 21:32:43 +0530276 writel(pd->regulator[1], reg_base + (4 * 1));
Padmanabhan Komanduru2232c142014-10-29 00:06:24 +0530277 /* Regulator ctrl 4 */
Prashant Nukala33715aa2015-06-15 21:32:43 +0530278 writel(pd->regulator[4], reg_base + (4 * 4));
Padmanabhan Komanduru2232c142014-10-29 00:06:24 +0530279 /* LDO ctrl */
Prashant Nukala33715aa2015-06-15 21:32:43 +0530280 if ((readl(ctl_base) == DSI_HW_REV_103_1) ||
281 (readl(ctl_base) == DSI_HW_REV_104_2)) /* 8916/8939/8952/8956 */
Padmanabhan Komanduru2232c142014-10-29 00:06:24 +0530282 writel(0x05, phy_base + 0x01dc);
Padmanabhan Komanduru2232c142014-10-29 00:06:24 +0530283 else
284 writel(0x0d, phy_base + 0x01dc);
285 dmb();
286 } else {
287 /* Regulator ctrl 0 */
Prashant Nukala33715aa2015-06-15 21:32:43 +0530288 writel(0x00, reg_base + (4 * 0));
Padmanabhan Komanduru2232c142014-10-29 00:06:24 +0530289 /* Regulator ctrl - CAL_PWD_CFG */
Prashant Nukala33715aa2015-06-15 21:32:43 +0530290 writel(pd->regulator[6], reg_base + (4 * 6));
Padmanabhan Komanduru2232c142014-10-29 00:06:24 +0530291 /* Add h/w recommended delay */
292 udelay(1000);
293 /* Regulator ctrl 1 */
Prashant Nukala33715aa2015-06-15 21:32:43 +0530294 writel(pd->regulator[1], reg_base + (4 * 1));
Padmanabhan Komanduru2232c142014-10-29 00:06:24 +0530295 /* Regulator ctrl 2 */
Prashant Nukala33715aa2015-06-15 21:32:43 +0530296 writel(pd->regulator[2], reg_base + (4 * 2));
Padmanabhan Komanduru2232c142014-10-29 00:06:24 +0530297 /* Regulator ctrl 3 */
Prashant Nukala33715aa2015-06-15 21:32:43 +0530298 writel(pd->regulator[3], reg_base + (4 * 3));
Padmanabhan Komanduru2232c142014-10-29 00:06:24 +0530299 /* Regulator ctrl 4 */
Prashant Nukala33715aa2015-06-15 21:32:43 +0530300 writel(pd->regulator[4], reg_base + (4 * 4));
Padmanabhan Komanduru2232c142014-10-29 00:06:24 +0530301 /* LDO ctrl */
302 writel(0x00, phy_base + 0x01dc);
303 /* Regulator ctrl 0 */
Prashant Nukala33715aa2015-06-15 21:32:43 +0530304 writel(pd->regulator[0], reg_base + (4 * 0));
Padmanabhan Komanduru2232c142014-10-29 00:06:24 +0530305 dmb();
306 }
Siddhartha Agrawal1b2ed842013-05-29 18:02:28 -0700307}
308
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800309int mdss_dsi_v2_phy_init(struct mipi_panel_info *mipi, uint32_t ctl_base)
Terence Hampsonf49ff4e2013-06-18 15:11:31 -0400310{
311 struct mdss_dsi_phy_ctrl *pd;
312 uint32_t i, ln, off = 0, offset;
313
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800314 pd = mipi->mdss_dsi_phy_db;
Terence Hampsonf49ff4e2013-06-18 15:11:31 -0400315 /* DSI PHY configuration */
316 off = 0x480;
317 writel(pd->strength[0], ctl_base + off + (4 * 0));
318 writel(pd->strength[1], ctl_base + off + (4 * 2));
319
320 off = 0x470;
321 writel(0x10, ctl_base + off + (4 * 3));
322 writel(0x5F, ctl_base + off + (4 * 0));
323
324 off = 0x500;
Xiaoming Zhou7c9e1ee2013-07-18 10:51:41 -0400325 /* use LDO mode */
326 writel(0x25, ctl_base + 0x4B0);
Terence Hampsonf49ff4e2013-06-18 15:11:31 -0400327 for (i = 0; i < 5; i++)
328 writel(pd->regulator[i], ctl_base + off + (4 * i));
329
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800330 mipi_dsi_calibration(ctl_base);
Terence Hampsonf49ff4e2013-06-18 15:11:31 -0400331
332 /* 4 lanes + clk lane configuration */
333 /* lane config n * (0 - 4) & DataPath setup */
334 for (ln = 0; ln < 5; ln++) {
335 off = 0x0300 + (ln * 0x40);
336 for (i = 0; i < 9; i++) {
337 offset = i + (ln * 9);
338 writel(pd->laneCfg[offset], ctl_base + off);
339 dmb();
340 off += 4;
341 }
342 }
343
344 off = 0x440;
345 for (i = 0; i < 12; i++)
346 writel(pd->timing[i], ctl_base + off + (4 * i));
347
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800348 if (1 == mipi->num_of_lanes)
Terence Hampsonf49ff4e2013-06-18 15:11:31 -0400349 writel(0x8, ctl_base + 0x200 + (4 * 11));
350
351
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800352 if (mipi->lane_swap)
353 writel(mipi->lane_swap, ctl_base + 0x0ac);
Terence Hampsonf49ff4e2013-06-18 15:11:31 -0400354
355 /* T_CLK_POST, T_CLK_PRE for CLK lane P/N HS 200 mV timing
356 length should > data lane HS timing length */
357 writel(0x41b, ctl_base + 0x0c0);
358 return 0;
359}
360
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800361static int mdss_dsi_phy_28nm_init(struct mipi_panel_info *mipi,
Prashant Nukala33715aa2015-06-15 21:32:43 +0530362 uint32_t ctl_base, uint32_t phy_base, uint32_t reg_base)
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800363{
364 struct mdss_dsi_phy_ctrl *pd;
Prashant Nukala33715aa2015-06-15 21:32:43 +0530365 uint32_t i, off = 0, ln, offset, dsi0_phy_base;
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800366
Terence Hampsonf49ff4e2013-06-18 15:11:31 -0400367 if (mdp_get_revision() == MDP_REV_304)
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800368 return mdss_dsi_v2_phy_init(mipi, ctl_base);
Terence Hampsonf49ff4e2013-06-18 15:11:31 -0400369
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800370 pd = (mipi->mdss_dsi_phy_db);
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800371
Padmanabhan Komanduru0a749892015-06-15 15:38:59 +0530372 /* PHY_CTRL_0 */
373 writel(0x5b, phy_base + 0x0170);
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800374 /* Strength ctrl 0 */
Padmanabhan Komandurucdc651e2014-03-25 20:25:55 +0530375 writel(pd->strength[0], phy_base + 0x0184);
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800376
Prashant Nukala33715aa2015-06-15 21:32:43 +0530377 mdss_dsi_phy_regulator_init(pd, ctl_base, phy_base, reg_base);
Chandan Uddaraju932723b2013-02-21 18:36:20 -0800378
Padmanabhan Komandurucdc651e2014-03-25 20:25:55 +0530379 off = 0x0140; /* phy timing ctrl 0 - 11 */
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800380 for (i = 0; i < 12; i++) {
Padmanabhan Komandurucdc651e2014-03-25 20:25:55 +0530381 writel(pd->timing[i], phy_base + off);
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800382 dmb();
383 off += 4;
384 }
385
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800386 /* 4 lanes + clk lane configuration */
387 /* lane config n * (0 - 4) & DataPath setup */
388 for (ln = 0; ln < 5; ln++) {
Padmanabhan Komandurucdc651e2014-03-25 20:25:55 +0530389 off = (ln * 0x40);
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800390 for (i = 0; i < 9; i++) {
391 offset = i + (ln * 9);
Padmanabhan Komandurucdc651e2014-03-25 20:25:55 +0530392 writel(pd->laneCfg[offset], phy_base + off);
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800393 dmb();
394 off += 4;
395 }
396 }
397
Padmanabhan Komanduru0a749892015-06-15 15:38:59 +0530398 /* MMSS_DSI_0_PHY_DSIPHY_CTRL_4 */
399 writel(0x0a, phy_base + 0x0180);
400 dmb();
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800401
Siddhartha Agrawal1b2ed842013-05-29 18:02:28 -0700402 /* DSI_PHY_DSIPHY_GLBL_TEST_CTRL */
Sandeep Pandab066d7c2015-07-31 16:45:09 +0530403 if (mipi->dual_dsi) {
404 dsi0_phy_base = DSI0_PHY_BASE +
405 target_display_get_base_offset(DSI0_PHY_BASE);
406 if ((phy_base == dsi0_phy_base) ||
407 (readl(mipi->ctl_base) == DSI_HW_REV_103_1))
408 writel(0x01, phy_base + 0x01d4);
409 else
410 writel(0x00, phy_base + 0x01d4);
411 } else {
Padmanabhan Komandurucdc651e2014-03-25 20:25:55 +0530412 writel(0x01, phy_base + 0x01d4);
Sandeep Pandab066d7c2015-07-31 16:45:09 +0530413 }
414 dmb();
Siddhartha Agrawal1b2ed842013-05-29 18:02:28 -0700415
Padmanabhan Komanduru0a749892015-06-15 15:38:59 +0530416 /* MMSS_DSI_0_PHY_DSIPHY_CTRL_0 */
417 writel(0x5f, phy_base + 0x0170);
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800418 dmb();
419
Padmanabhan Komandurucdc651e2014-03-25 20:25:55 +0530420 off = 0x01b4; /* phy BIST ctrl 0 - 5 */
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800421 for (i = 0; i < 6; i++) {
Padmanabhan Komandurucdc651e2014-03-25 20:25:55 +0530422 writel(pd->bistCtrl[i], phy_base + off);
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800423 off += 4;
424 }
425 dmb();
426
427 /* DSI_0_CLKOUT_TIMING_CTRL */
Siddhartha Agrawal1b2ed842013-05-29 18:02:28 -0700428 writel(0x41b, ctl_base + 0x0c4);
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800429 dmb();
Veera Sundaram Sankarandb0b2bf2014-12-16 18:09:27 -0800430 return 0;
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800431
432}
Xiaoming Zhou03fd48b2014-07-31 15:24:41 -0400433
434void mdss_dsi_phy_contention_detection(
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800435 struct mipi_panel_info *mipi,
Xiaoming Zhou03fd48b2014-07-31 15:24:41 -0400436 uint32_t phy_base)
437{
438 struct mdss_dsi_phy_ctrl *pd;
439
Dhaval Patel8b9a5822015-03-16 13:01:26 -0700440 if ((mipi->mdss_dsi_phy_db->pll_type == DSI_PLL_TYPE_THULIUM) ||
Padmanabhan Komandurubd8268a2018-04-30 17:05:56 +0530441 (mipi->mdss_dsi_phy_db->pll_type == DSI_PLL_TYPE_12NM) ||
Dhaval Patel8b9a5822015-03-16 13:01:26 -0700442 (mdp_get_revision() == MDP_REV_304))
Xiaoming Zhou03fd48b2014-07-31 15:24:41 -0400443 return;
444
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800445 pd = (mipi->mdss_dsi_phy_db);
Aravind Venkateswaran51e57552014-12-09 13:23:19 -0800446 writel(pd->strength[1], phy_base + MMSS_DSI_PHY_STRENGTH_CTRL_1);
Xiaoming Zhou03fd48b2014-07-31 15:24:41 -0400447 dmb();
448}
449
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800450static int mdss_dsi_phy_20nm_init(struct mipi_panel_info *mipi,
Jeevan Shriram01379322015-01-07 17:41:26 -0800451 uint32_t ctl_base, uint32_t phy_base, uint32_t reg_base)
Dhaval Patelee8c9b32014-08-12 16:18:50 -0700452{
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800453 struct mdss_dsi_phy_ctrl *pd = mipi->mdss_dsi_phy_db;
Dhaval Patelee8c9b32014-08-12 16:18:50 -0700454 uint32_t i, off = 0, ln, offset;
455
Jeevan Shriram01379322015-01-07 17:41:26 -0800456 mdss_dsi_20nm_phy_regulator_init(pd, phy_base, reg_base);
Jeevan Shrirama0623d52014-12-14 14:25:48 -0800457
Dhaval Patelee8c9b32014-08-12 16:18:50 -0700458 /* Strength ctrl 0 */
459 writel(pd->strength[0], phy_base + MMSS_DSI_PHY_STRENGTH_CTRL_0);
460
Jeevan Shrirama0623d52014-12-14 14:25:48 -0800461 writel(0x00, phy_base + MMSS_DSI_PHY_GLBL_TEST_CTRL);
Dhaval Patelee8c9b32014-08-12 16:18:50 -0700462
Dhaval Patelee8c9b32014-08-12 16:18:50 -0700463 for (ln = 0; ln < TOTAL_LANE_COUNT; ln++) {
464 off = (ln * 0x40);
465 for (i = 0; i < CONFIG_REG_FOR_EACH_LANE; i++, off += 4) {
466 offset = i + (ln * CONFIG_REG_FOR_EACH_LANE);
467 writel(pd->laneCfg[offset], phy_base + off);
468 dmb();
469 }
470 }
471
Jeevan Shrirama0623d52014-12-14 14:25:48 -0800472 off = MMSS_DSI_PHY_TIMING_CTRL_0;
473 for (i = 0; i < TOTAL_TIMING_CTRL_CONFIG; i++, off += 4) {
474 writel(pd->timing[i], phy_base + off);
475 dmb();
Dhaval Patelee8c9b32014-08-12 16:18:50 -0700476 }
Dhaval Patelee8c9b32014-08-12 16:18:50 -0700477
Jeevan Shrirama0623d52014-12-14 14:25:48 -0800478 writel(0x00, phy_base + MMSS_DSI_PHY_CTRL_1);
479 dmb();
480 writel(0x7f, phy_base + MMSS_DSI_PHY_CTRL_0);
Dhaval Patelee8c9b32014-08-12 16:18:50 -0700481 dmb();
Veera Sundaram Sankarandb0b2bf2014-12-16 18:09:27 -0800482 return 0;
Dhaval Patelee8c9b32014-08-12 16:18:50 -0700483}
484
Jeevan Shriram01379322015-01-07 17:41:26 -0800485int mdss_dsi_phy_init(struct mipi_panel_info *mipi)
Dhaval Patelee8c9b32014-08-12 16:18:50 -0700486{
Dhaval Patel8b9a5822015-03-16 13:01:26 -0700487 int ret = 0;
Dhaval Patelee8c9b32014-08-12 16:18:50 -0700488
Dhaval Patel8b9a5822015-03-16 13:01:26 -0700489 /* 8994 and 8992 target */
490 switch (mipi->mdss_dsi_phy_db->pll_type) {
491 case DSI_PLL_TYPE_20NM:
Jeevan Shriram01379322015-01-07 17:41:26 -0800492 ret = mdss_dsi_phy_20nm_init(mipi, mipi->ctl_base,
493 mipi->phy_base, mipi->reg_base);
494 if (mipi->dual_dsi)
495 ret = mdss_dsi_phy_20nm_init(mipi, mipi->sctl_base,
496 mipi->sphy_base, mipi->reg_base);
Dhaval Patel8b9a5822015-03-16 13:01:26 -0700497 break;
498 case DSI_PLL_TYPE_THULIUM:
Padmanabhan Komandurubd8268a2018-04-30 17:05:56 +0530499 case DSI_PLL_TYPE_12NM:
Dhaval Patel8b9a5822015-03-16 13:01:26 -0700500 dprintf(SPEW, "phy is configured with PLL driver\n");
501 break;
502 case DSI_PLL_TYPE_28NM:
503 default:
Prashant Nukala33715aa2015-06-15 21:32:43 +0530504 ret = mdss_dsi_phy_28nm_init(mipi, mipi->ctl_base,
505 mipi->phy_base, mipi->reg_base);
Jeevan Shriram01379322015-01-07 17:41:26 -0800506 if (mipi->dual_dsi)
507 ret = mdss_dsi_phy_28nm_init(mipi, mipi->sctl_base,
Prashant Nukala33715aa2015-06-15 21:32:43 +0530508 mipi->sphy_base, mipi->reg_base);
Dhaval Patel8b9a5822015-03-16 13:01:26 -0700509 break;
Jeevan Shriram01379322015-01-07 17:41:26 -0800510 }
Dhaval Patelee8c9b32014-08-12 16:18:50 -0700511
512 return ret;
513}