blob: 2787960ae1d00fecea1b343c06de07ebd249e6c7 [file] [log] [blame]
Dhaval Patelbb408712014-03-18 11:45:53 -07001/* Copyright (c) 2012-2014, 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>
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070032#include <platform/iomap.h>
33
Siddhartha Agrawal1b2ed842013-05-29 18:02:28 -070034#if (DISPLAY_TYPE_MDSS == 0)
35#define MIPI_DSI0_BASE MIPI_DSI_BASE
36#define MIPI_DSI1_BASE MIPI_DSI_BASE
37#endif
38
Dhaval Patelee8c9b32014-08-12 16:18:50 -070039#define MMSS_DSI_CLKOUT_TIMING_CTRL 0x0c4
40#define MMSS_DSI_PHY_TIMING_CTRL_0 0x0140
41#define MMSS_DSI_PHY_CTRL_0 0x0170
42#define MMSS_DSI_PHY_CTRL_1 0x0174
43#define MMSS_DSI_PHY_CTRL_2 0x0178
44#define MMSS_DSI_PHY_STRENGTH_CTRL_0 0x0184
45#define MMSS_DSI_PHY_STRENGTH_CTRL_1 0x0188
46#define MMSS_DSI_PHY_BIST_CTRL_0 0x01b4
47#define MMSS_DSI_PHY_GLBL_TEST_CTRL 0x01d4
48#define MMSS_DSI_PHY_LDO_CTRL 0x01dc
49
50#define TOTAL_TIMING_CTRL_CONFIG 12
51#define TOTAL_BIST_CTRL_CONFIG 6
52/* 4 data lanes and 1 clock lanes */
53#define TOTAL_LANE_COUNT 5
54#define CONFIG_REG_FOR_EACH_LANE 9
55
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -080056static void mipi_dsi_calibration(uint32_t ctl_base)
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070057{
58 uint32_t i = 0;
59 uint32_t term_cnt = 5000;
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -080060 int32_t cal_busy = readl(ctl_base + 0x550);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070061
62 /* DSI1_DSIPHY_REGULATOR_CAL_PWR_CFG */
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -080063 writel(0x01, ctl_base + 0x0518);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070064
65 /* DSI1_DSIPHY_CAL_SW_CFG2 */
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -080066 writel(0x0, ctl_base + 0x0534);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070067 /* DSI1_DSIPHY_CAL_HW_CFG1 */
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -080068 writel(0x5a, ctl_base + 0x053c);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070069 /* DSI1_DSIPHY_CAL_HW_CFG3 */
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -080070 writel(0x10, ctl_base + 0x0544);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070071 /* DSI1_DSIPHY_CAL_HW_CFG4 */
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -080072 writel(0x01, ctl_base + 0x0548);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070073 /* DSI1_DSIPHY_CAL_HW_CFG0 */
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -080074 writel(0x01, ctl_base + 0x0538);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070075
76 /* DSI1_DSIPHY_CAL_HW_TRIGGER */
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -080077 writel(0x01, ctl_base + 0x0528);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070078
79 /* DSI1_DSIPHY_CAL_HW_TRIGGER */
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -080080 writel(0x00, ctl_base + 0x0528);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070081
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -080082 cal_busy = readl(ctl_base + 0x550);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070083 while (cal_busy & 0x10) {
84 i++;
85 if (i > term_cnt) {
86 dprintf(CRITICAL, "DSI1 PHY REGULATOR NOT READY,"
87 "exceeded polling TIMEOUT!\n");
88 break;
89 }
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -080090 cal_busy = readl(ctl_base + 0x550);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070091 }
92}
93
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -080094#if (DISPLAY_TYPE_MDSS == 0)
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070095int mipi_dsi_phy_init(struct mipi_dsi_panel_config *pinfo)
96{
97 struct mipi_dsi_phy_ctrl *pd;
98 uint32_t i, off = 0;
Channagoud Kadabi539ef722012-03-29 16:02:50 +053099 int mdp_rev;
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700100
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530101 mdp_rev = mdp_get_revision();
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700102
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530103 if (MDP_REV_303 == mdp_rev || MDP_REV_41 == mdp_rev) {
104 writel(0x00000001, DSIPHY_SW_RESET);
105 writel(0x00000000, DSIPHY_SW_RESET);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700106
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530107 pd = (pinfo->dsi_phy_config);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700108
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530109 off = 0x02cc; /* regulator ctrl 0 */
110 for (i = 0; i < 4; i++) {
111 writel(pd->regulator[i], MIPI_DSI_BASE + off);
112 off += 4;
113 }
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700114
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530115 off = 0x0260; /* phy timig ctrl 0 */
116 for (i = 0; i < 11; i++) {
117 writel(pd->timing[i], MIPI_DSI_BASE + off);
118 off += 4;
119 }
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700120
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530121 /* T_CLK_POST, T_CLK_PRE for CLK lane P/N HS 200 mV timing
122 length should > data lane HS timing length */
123 writel(0xa1e, DSI_CLKOUT_TIMING_CTRL);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700124
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530125 off = 0x0290; /* ctrl 0 */
126 for (i = 0; i < 4; i++) {
127 writel(pd->ctrl[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 off = 0x02a0; /* strength 0 */
132 for (i = 0; i < 4; i++) {
133 writel(pd->strength[i], MIPI_DSI_BASE + off);
134 off += 4;
135 }
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700136
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530137 if (1 == pinfo->num_of_lanes)
138 pd->pll[10] |= 0x8;
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700139
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530140 off = 0x0204; /* pll ctrl 1, skip 0 */
141 for (i = 1; i < 21; i++) {
142 writel(pd->pll[i], MIPI_DSI_BASE + off);
143 off += 4;
144 }
145
146 /* pll ctrl 0 */
147 writel(pd->pll[0], MIPI_DSI_BASE + 0x200);
148 writel((pd->pll[0] | 0x01), MIPI_DSI_BASE + 0x200);
149 /* lane swp ctrol */
150 if (pinfo->lane_swap)
151 writel(pinfo->lane_swap, MIPI_DSI_BASE + 0xac);
152 } else {
153 writel(0x0001, MIPI_DSI_BASE + 0x128); /* start phy sw reset */
154 writel(0x0000, MIPI_DSI_BASE + 0x128); /* end phy w reset */
155 writel(0x0003, MIPI_DSI_BASE + 0x500); /* regulator_ctrl_0 */
156 writel(0x0001, MIPI_DSI_BASE + 0x504); /* regulator_ctrl_1 */
157 writel(0x0001, MIPI_DSI_BASE + 0x508); /* regulator_ctrl_2 */
158 writel(0x0000, MIPI_DSI_BASE + 0x50c); /* regulator_ctrl_3 */
159 writel(0x0100, MIPI_DSI_BASE + 0x510); /* regulator_ctrl_4 */
160
161 pd = (pinfo->dsi_phy_config);
162
163 off = 0x0480; /* strength 0 - 2 */
164 for (i = 0; i < 3; i++) {
165 writel(pd->strength[i], MIPI_DSI_BASE + off);
166 off += 4;
167 }
168
169 off = 0x0470; /* ctrl 0 - 3 */
170 for (i = 0; i < 4; i++) {
171 writel(pd->ctrl[i], MIPI_DSI_BASE + off);
172 off += 4;
173 }
174
175 off = 0x0500; /* regulator ctrl 0 - 4 */
176 for (i = 0; i < 5; i++) {
177 writel(pd->regulator[i], MIPI_DSI_BASE + off);
178 off += 4;
179 }
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800180 mipi_dsi_calibration(MIPI_DSI_BASE);
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530181
182 off = 0x0204; /* pll ctrl 1 - 19, skip 0 */
183 for (i = 1; i < 20; i++) {
184 writel(pd->pll[i], MIPI_DSI_BASE + off);
185 off += 4;
186 }
187
188 /* pll ctrl 0 */
189 writel(pd->pll[0], MIPI_DSI_BASE + 0x200);
190 writel((pd->pll[0] | 0x01), MIPI_DSI_BASE + 0x200);
191
192 /* Check that PHY is ready */
193 while (!(readl(DSIPHY_PLL_RDY) & 0x01))
194 udelay(1);
195
196 writel(0x202D, DSI_CLKOUT_TIMING_CTRL);
197
198 off = 0x0440; /* phy timing ctrl 0 - 11 */
199 for (i = 0; i < 12; i++) {
200 writel(pd->timing[i], MIPI_DSI_BASE + off);
201 off += 4;
202 }
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700203 }
204 return 0;
205}
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800206#endif
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800207
Siddhartha Agrawal1b2ed842013-05-29 18:02:28 -0700208void mdss_dsi_phy_sw_reset(uint32_t ctl_base)
Chandan Uddaraju932723b2013-02-21 18:36:20 -0800209{
210 /* start phy sw reset */
Siddhartha Agrawal1b2ed842013-05-29 18:02:28 -0700211 writel(0x0001, ctl_base + 0x012c);
Chandan Uddaraju932723b2013-02-21 18:36:20 -0800212 udelay(1000);
213
214 /* end phy sw reset */
Siddhartha Agrawal1b2ed842013-05-29 18:02:28 -0700215 writel(0x0000, ctl_base + 0x012c);
Chandan Uddaraju932723b2013-02-21 18:36:20 -0800216 udelay(100);
217}
218
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800219static int mdss_dsi_phy_regulator_init(struct mdss_dsi_phy_ctrl *pd,
220 uint32_t phy_base)
Siddhartha Agrawal1b2ed842013-05-29 18:02:28 -0700221{
222 /* DSI0 and DSI1 have a common regulator */
Padmanabhan Komandurucdc651e2014-03-25 20:25:55 +0530223 uint32_t off = 0x0280; /* phy regulator ctrl settings */
Siddhartha Agrawal1b2ed842013-05-29 18:02:28 -0700224
Padmanabhan Komanduru2232c142014-10-29 00:06:24 +0530225 if (pd->regulator_mode == DSI_PHY_REGULATOR_LDO_MODE) {
226 /* Regulator ctrl 0 */
227 writel(0x00, DSI0_PHY_BASE + off + (4 * 0));
228 /* Regulator ctrl - CAL_PWD_CFG */
229 writel(pd->regulator[6], DSI0_PHY_BASE + off + (4 * 6));
230 /* Add h/w recommended delay */
231 udelay(1000);
232 /* Regulator ctrl - TEST */
233 writel(pd->regulator[5], DSI0_PHY_BASE + off + (4 * 5));
234 /* Regulator ctrl 3 */
235 writel(pd->regulator[3], DSI0_PHY_BASE + off + (4 * 3));
236 /* Regulator ctrl 2 */
237 writel(pd->regulator[2], DSI0_PHY_BASE + off + (4 * 2));
238 /* Regulator ctrl 1 */
239 writel(pd->regulator[1], DSI0_PHY_BASE + off + (4 * 1));
240 /* Regulator ctrl 4 */
241 writel(pd->regulator[4], DSI0_PHY_BASE + off + (4 * 4));
242 /* LDO ctrl */
243 if (readl(MIPI_DSI0_BASE) == DSI_HW_REV_103_1) /* 8916/8939 */
244 writel(0x05, phy_base + 0x01dc);
245 else if (readl(MIPI_DSI0_BASE) == DSI_HW_REV_103) /* 8994 */
246 writel(0x1d, phy_base + 0x01dc);
247 else
248 writel(0x0d, phy_base + 0x01dc);
249 dmb();
250 } else {
251 /* Regulator ctrl 0 */
252 writel(0x00, DSI0_PHY_BASE + off + (4 * 0));
253 /* Regulator ctrl - CAL_PWD_CFG */
254 writel(pd->regulator[6], DSI0_PHY_BASE + off + (4 * 6));
255 /* Add h/w recommended delay */
256 udelay(1000);
257 /* Regulator ctrl 1 */
258 writel(pd->regulator[1], DSI0_PHY_BASE + off + (4 * 1));
259 /* Regulator ctrl 2 */
260 writel(pd->regulator[2], DSI0_PHY_BASE + off + (4 * 2));
261 /* Regulator ctrl 3 */
262 writel(pd->regulator[3], DSI0_PHY_BASE + off + (4 * 3));
263 /* Regulator ctrl 4 */
264 writel(pd->regulator[4], DSI0_PHY_BASE + off + (4 * 4));
265 /* LDO ctrl */
266 writel(0x00, phy_base + 0x01dc);
267 /* Regulator ctrl 0 */
268 writel(pd->regulator[0], DSI0_PHY_BASE + off + (4 * 0));
269 dmb();
270 }
Siddhartha Agrawal1b2ed842013-05-29 18:02:28 -0700271}
272
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800273int mdss_dsi_v2_phy_init(struct mipi_panel_info *mipi, uint32_t ctl_base)
Terence Hampsonf49ff4e2013-06-18 15:11:31 -0400274{
275 struct mdss_dsi_phy_ctrl *pd;
276 uint32_t i, ln, off = 0, offset;
277
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800278 pd = mipi->mdss_dsi_phy_db;
Terence Hampsonf49ff4e2013-06-18 15:11:31 -0400279 /* DSI PHY configuration */
280 off = 0x480;
281 writel(pd->strength[0], ctl_base + off + (4 * 0));
282 writel(pd->strength[1], ctl_base + off + (4 * 2));
283
284 off = 0x470;
285 writel(0x10, ctl_base + off + (4 * 3));
286 writel(0x5F, ctl_base + off + (4 * 0));
287
288 off = 0x500;
Xiaoming Zhou7c9e1ee2013-07-18 10:51:41 -0400289 /* use LDO mode */
290 writel(0x25, ctl_base + 0x4B0);
Terence Hampsonf49ff4e2013-06-18 15:11:31 -0400291 for (i = 0; i < 5; i++)
292 writel(pd->regulator[i], ctl_base + off + (4 * i));
293
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800294 mipi_dsi_calibration(ctl_base);
Terence Hampsonf49ff4e2013-06-18 15:11:31 -0400295
296 /* 4 lanes + clk lane configuration */
297 /* lane config n * (0 - 4) & DataPath setup */
298 for (ln = 0; ln < 5; ln++) {
299 off = 0x0300 + (ln * 0x40);
300 for (i = 0; i < 9; i++) {
301 offset = i + (ln * 9);
302 writel(pd->laneCfg[offset], ctl_base + off);
303 dmb();
304 off += 4;
305 }
306 }
307
308 off = 0x440;
309 for (i = 0; i < 12; i++)
310 writel(pd->timing[i], ctl_base + off + (4 * i));
311
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800312 if (1 == mipi->num_of_lanes)
Terence Hampsonf49ff4e2013-06-18 15:11:31 -0400313 writel(0x8, ctl_base + 0x200 + (4 * 11));
314
315
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800316 if (mipi->lane_swap)
317 writel(mipi->lane_swap, ctl_base + 0x0ac);
Terence Hampsonf49ff4e2013-06-18 15:11:31 -0400318
319 /* T_CLK_POST, T_CLK_PRE for CLK lane P/N HS 200 mV timing
320 length should > data lane HS timing length */
321 writel(0x41b, ctl_base + 0x0c0);
322 return 0;
323}
324
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800325static int mdss_dsi_phy_28nm_init(struct mipi_panel_info *mipi,
Padmanabhan Komandurucdc651e2014-03-25 20:25:55 +0530326 uint32_t ctl_base, uint32_t phy_base)
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800327{
328 struct mdss_dsi_phy_ctrl *pd;
329 uint32_t i, off = 0, ln, offset;
330
Terence Hampsonf49ff4e2013-06-18 15:11:31 -0400331 if (mdp_get_revision() == MDP_REV_304)
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800332 return mdss_dsi_v2_phy_init(mipi, ctl_base);
Terence Hampsonf49ff4e2013-06-18 15:11:31 -0400333
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800334 pd = (mipi->mdss_dsi_phy_db);
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800335
336 /* Strength ctrl 0 */
Padmanabhan Komandurucdc651e2014-03-25 20:25:55 +0530337 writel(pd->strength[0], phy_base + 0x0184);
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800338
Padmanabhan Komanduru2232c142014-10-29 00:06:24 +0530339 mdss_dsi_phy_regulator_init(pd, phy_base);
Chandan Uddaraju932723b2013-02-21 18:36:20 -0800340
Padmanabhan Komandurucdc651e2014-03-25 20:25:55 +0530341 off = 0x0140; /* phy timing ctrl 0 - 11 */
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800342 for (i = 0; i < 12; i++) {
Padmanabhan Komandurucdc651e2014-03-25 20:25:55 +0530343 writel(pd->timing[i], phy_base + off);
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800344 dmb();
345 off += 4;
346 }
347
348 /* MMSS_DSI_0_PHY_DSIPHY_CTRL_1 */
Padmanabhan Komandurucdc651e2014-03-25 20:25:55 +0530349 writel(0x00, phy_base + 0x0174);
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800350 /* MMSS_DSI_0_PHY_DSIPHY_CTRL_0 */
Padmanabhan Komandurucdc651e2014-03-25 20:25:55 +0530351 writel(0x5f, phy_base + 0x0170);
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800352
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800353 dmb();
354 /* 4 lanes + clk lane configuration */
355 /* lane config n * (0 - 4) & DataPath setup */
356 for (ln = 0; ln < 5; ln++) {
Padmanabhan Komandurucdc651e2014-03-25 20:25:55 +0530357 off = (ln * 0x40);
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800358 for (i = 0; i < 9; i++) {
359 offset = i + (ln * 9);
Padmanabhan Komandurucdc651e2014-03-25 20:25:55 +0530360 writel(pd->laneCfg[offset], phy_base + off);
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800361 dmb();
362 off += 4;
363 }
364 }
365
366 /* MMSS_DSI_0_PHY_DSIPHY_CTRL_0 */
Padmanabhan Komandurucdc651e2014-03-25 20:25:55 +0530367 writel(0x5f, phy_base + 0x0170);
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800368
Siddhartha Agrawal1b2ed842013-05-29 18:02:28 -0700369 /* DSI_PHY_DSIPHY_GLBL_TEST_CTRL */
Vineet Bajaj2f08a362014-07-24 20:50:42 +0530370 if (phy_base == DSI0_PHY_BASE ||
371 (readl(MIPI_DSI0_BASE) == DSI_HW_REV_103_1))
Padmanabhan Komandurucdc651e2014-03-25 20:25:55 +0530372 writel(0x01, phy_base + 0x01d4);
Siddhartha Agrawal1b2ed842013-05-29 18:02:28 -0700373 else
Padmanabhan Komandurucdc651e2014-03-25 20:25:55 +0530374 writel(0x00, phy_base + 0x01d4);
Siddhartha Agrawal1b2ed842013-05-29 18:02:28 -0700375
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800376 dmb();
377
Padmanabhan Komandurucdc651e2014-03-25 20:25:55 +0530378 off = 0x01b4; /* phy BIST ctrl 0 - 5 */
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800379 for (i = 0; i < 6; i++) {
Padmanabhan Komandurucdc651e2014-03-25 20:25:55 +0530380 writel(pd->bistCtrl[i], phy_base + off);
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800381 off += 4;
382 }
383 dmb();
384
385 /* DSI_0_CLKOUT_TIMING_CTRL */
Siddhartha Agrawal1b2ed842013-05-29 18:02:28 -0700386 writel(0x41b, ctl_base + 0x0c4);
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800387 dmb();
388
389}
Xiaoming Zhou03fd48b2014-07-31 15:24:41 -0400390
391void mdss_dsi_phy_contention_detection(
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800392 struct mipi_panel_info *mipi,
Xiaoming Zhou03fd48b2014-07-31 15:24:41 -0400393 uint32_t phy_base)
394{
395 struct mdss_dsi_phy_ctrl *pd;
396
397 if (mdp_get_revision() == MDP_REV_304)
398 return;
399
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800400 pd = (mipi->mdss_dsi_phy_db);
Aravind Venkateswaran51e57552014-12-09 13:23:19 -0800401 writel(pd->strength[1], phy_base + MMSS_DSI_PHY_STRENGTH_CTRL_1);
Xiaoming Zhou03fd48b2014-07-31 15:24:41 -0400402 dmb();
403}
404
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800405static int mdss_dsi_phy_20nm_init(struct mipi_panel_info *mipi,
Dhaval Patelee8c9b32014-08-12 16:18:50 -0700406 uint32_t ctl_base, uint32_t phy_base)
407{
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800408 struct mdss_dsi_phy_ctrl *pd = mipi->mdss_dsi_phy_db;
Dhaval Patelee8c9b32014-08-12 16:18:50 -0700409 uint32_t i, off = 0, ln, offset;
410
411 /* Strength ctrl 0 */
412 writel(pd->strength[0], phy_base + MMSS_DSI_PHY_STRENGTH_CTRL_0);
413
Padmanabhan Komanduru2232c142014-10-29 00:06:24 +0530414 mdss_dsi_phy_regulator_init(pd, phy_base);
Dhaval Patelee8c9b32014-08-12 16:18:50 -0700415
416 off = MMSS_DSI_PHY_TIMING_CTRL_0;
417 for (i = 0; i < TOTAL_TIMING_CTRL_CONFIG; i++, off += 4) {
418 writel(pd->timing[i], phy_base + off);
419 dmb();
420 }
421
422 /* Currently the Phy settings for the DSI 0 is done in clk prepare*/
423 if (phy_base == DSI1_PHY_BASE) {
424 writel(0x00, phy_base + MMSS_DSI_PHY_CTRL_1);
425 writel(0x05, phy_base + MMSS_DSI_PHY_CTRL_0);
426 dmb();
427
428 writel(0x7f, phy_base + MMSS_DSI_PHY_CTRL_0);
429 dmb();
430
431 /* BITCLK_HS_SEL should be set to 0 for left */
432 writel(0x00, phy_base + MMSS_DSI_PHY_GLBL_TEST_CTRL);
433
434 writel(0x00, phy_base + MMSS_DSI_PHY_CTRL_2);
435 writel(0x02, phy_base + MMSS_DSI_PHY_CTRL_2);
436 writel(0x03, phy_base + MMSS_DSI_PHY_CTRL_2);
437 dmb();
438 }
439
Dhaval Patelee8c9b32014-08-12 16:18:50 -0700440 for (ln = 0; ln < TOTAL_LANE_COUNT; ln++) {
441 off = (ln * 0x40);
442 for (i = 0; i < CONFIG_REG_FOR_EACH_LANE; i++, off += 4) {
443 offset = i + (ln * CONFIG_REG_FOR_EACH_LANE);
444 writel(pd->laneCfg[offset], phy_base + off);
445 dmb();
446 }
447 }
448
449 dmb();
450
451 off = MMSS_DSI_PHY_BIST_CTRL_0;
452 for (i = 0; i < TOTAL_BIST_CTRL_CONFIG; i++, off +=4) {
453 writel(pd->bistCtrl[i], phy_base + off);
454 }
455 dmb();
456
457 writel(0x41b, ctl_base + MMSS_DSI_CLKOUT_TIMING_CTRL);
458 dmb();
459}
460
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800461int mdss_dsi_phy_init (struct mipi_panel_info *mipi,
Dhaval Patelee8c9b32014-08-12 16:18:50 -0700462 uint32_t ctl_base, uint32_t phy_base)
463{
464 int ret;
465
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800466 if (mipi->mdss_dsi_phy_db->is_pll_20nm)
467 ret = mdss_dsi_phy_20nm_init(mipi, ctl_base, phy_base);
Dhaval Patelee8c9b32014-08-12 16:18:50 -0700468 else
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800469 ret = mdss_dsi_phy_28nm_init(mipi, ctl_base, phy_base);
Dhaval Patelee8c9b32014-08-12 16:18:50 -0700470
471 return ret;
472}