blob: 57b9ff1800715f22e967f8bdb152a97e9c7bb2a7 [file] [log] [blame]
Shashank Mittal4bfb2e32012-04-16 10:56:27 -07001/* Copyright (c) 2012, Code Aurora Forum. All rights reserved.
2 *
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.
12 * * Neither the name of Code Aurora Forum, Inc. nor the names of its
13 * 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>
32#include <mdp4.h>
33#include <platform/iomap.h>
34
35static void mipi_dsi_calibration(void)
36{
37 uint32_t i = 0;
38 uint32_t term_cnt = 5000;
39 int32_t cal_busy = readl(MIPI_DSI_BASE + 0x550);
40
41 /* DSI1_DSIPHY_REGULATOR_CAL_PWR_CFG */
42 writel(0x01, MIPI_DSI_BASE + 0x0518);
43
44 /* DSI1_DSIPHY_CAL_SW_CFG2 */
45 writel(0x0, MIPI_DSI_BASE + 0x0534);
46 /* DSI1_DSIPHY_CAL_HW_CFG1 */
47 writel(0x5a, MIPI_DSI_BASE + 0x053c);
48 /* DSI1_DSIPHY_CAL_HW_CFG3 */
49 writel(0x10, MIPI_DSI_BASE + 0x0544);
50 /* DSI1_DSIPHY_CAL_HW_CFG4 */
51 writel(0x01, MIPI_DSI_BASE + 0x0548);
52 /* DSI1_DSIPHY_CAL_HW_CFG0 */
53 writel(0x01, MIPI_DSI_BASE + 0x0538);
54
55 /* DSI1_DSIPHY_CAL_HW_TRIGGER */
56 writel(0x01, MIPI_DSI_BASE + 0x0528);
57
58 /* DSI1_DSIPHY_CAL_HW_TRIGGER */
59 writel(0x00, MIPI_DSI_BASE + 0x0528);
60
61 cal_busy = readl(MIPI_DSI_BASE + 0x550);
62 while (cal_busy & 0x10) {
63 i++;
64 if (i > term_cnt) {
65 dprintf(CRITICAL, "DSI1 PHY REGULATOR NOT READY,"
66 "exceeded polling TIMEOUT!\n");
67 break;
68 }
69 cal_busy = readl(MIPI_DSI_BASE + 0x550);
70 }
71}
72
73int mipi_dsi_phy_init(struct mipi_dsi_panel_config *pinfo)
74{
75 struct mipi_dsi_phy_ctrl *pd;
76 uint32_t i, off = 0;
77
78 writel(0x0001, MIPI_DSI_BASE + 0x128); /* start phy sw reset */
79 writel(0x0000, MIPI_DSI_BASE + 0x128); /* end phy w reset */
80 writel(0x0003, MIPI_DSI_BASE + 0x500); /* regulator_ctrl_0 */
81 writel(0x0001, MIPI_DSI_BASE + 0x504); /* regulator_ctrl_1 */
82 writel(0x0001, MIPI_DSI_BASE + 0x508); /* regulator_ctrl_2 */
83 writel(0x0000, MIPI_DSI_BASE + 0x50c); /* regulator_ctrl_3 */
84 writel(0x0100, MIPI_DSI_BASE + 0x510); /* regulator_ctrl_4 */
85
86 pd = (pinfo->dsi_phy_config);
87
88 off = 0x0480; /* strength 0 - 2 */
89 for (i = 0; i < 3; i++) {
90 writel(pd->strength[i], MIPI_DSI_BASE + off);
91 off += 4;
92 }
93
94 off = 0x0470; /* ctrl 0 - 3 */
95 for (i = 0; i < 4; i++) {
96 writel(pd->ctrl[i], MIPI_DSI_BASE + off);
97 off += 4;
98 }
99
100 off = 0x0500; /* regulator ctrl 0 - 4 */
101 for (i = 0; i < 5; i++) {
102 writel(pd->regulator[i], MIPI_DSI_BASE + off);
103 off += 4;
104 }
105 mipi_dsi_calibration();
106
107 off = 0x0204; /* pll ctrl 1 - 19, skip 0 */
108 for (i = 1; i < 20; i++) {
109 writel(pd->pll[i], MIPI_DSI_BASE + off);
110 off += 4;
111 }
112
113 /* pll ctrl 0 */
114 writel(pd->pll[0], MIPI_DSI_BASE + 0x200);
115 writel((pd->pll[0] | 0x01), MIPI_DSI_BASE + 0x200);
116
117 /* Check that PHY is ready */
118 while (!(readl(DSIPHY_PLL_RDY) & 0x01))
119 udelay(1);
120
121 writel(0x202D, DSI_CLKOUT_TIMING_CTRL);
122
123 off = 0x0440; /* phy timing ctrl 0 - 11 */
124 for (i = 0; i < 12; i++) {
125 writel(pd->timing[i], MIPI_DSI_BASE + off);
126 off += 4;
127 }
128 return 0;
129}