ARM: tegra: loki: set init panel mode flag
[linux-3.10.git] / arch / arm / mach-tegra / board-loki-panel.c
1 /*
2  * arch/arm/mach-tegra/board-loki-panel.c
3  *
4  * Copyright (c) 2011-2013, NVIDIA Corporation. All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19  */
20 #include <linux/ioport.h>
21 #include <linux/fb.h>
22 #include <linux/nvmap.h>
23 #include <linux/nvhost.h>
24 #include <linux/init.h>
25 #include <linux/delay.h>
26 #include <linux/gpio.h>
27 #include <linux/tegra_pwm_bl.h>
28 #include <linux/regulator/consumer.h>
29 #include <linux/pwm_backlight.h>
30 #include <linux/of.h>
31
32 #include <mach/irqs.h>
33 #include <mach/dc.h>
34 #include <mach/pinmux.h>
35 #include <mach/pinmux-t12.h>
36 #include <asm/mach-types.h>
37
38 #include "board.h"
39 #include "devices.h"
40 #include "gpio-names.h"
41 #include "iomap.h"
42 #include "tegra12_host1x_devices.h"
43
44 struct platform_device * __init loki_host1x_init(void)
45 {
46         struct platform_device *pdev = NULL;
47
48         pdev = tegra12_register_host1x_devices();
49
50         if (!pdev) {
51                 pr_err("host1x devices registration failed\n");
52                 return NULL;
53         }
54         return pdev;
55 }
56
57 #ifdef CONFIG_TEGRA_DC
58
59 #define IS_EXTERNAL_PWM         1
60
61 #define DSI_PANEL_RESET         1
62
63 #define DSI_PANEL_RST_GPIO      TEGRA_GPIO_PH3
64 #define DSI_PANEL_BL_PWM        TEGRA_GPIO_PH1
65
66 #define DSI_PANEL_CE            0
67
68 #define DC_CTRL_MODE    TEGRA_DC_OUT_CONTINUOUS_MODE
69
70 /* HDMI Hotplug detection pin */
71 #define loki_hdmi_hpd   TEGRA_GPIO_PN7
72
73 static atomic_t sd_brightness = ATOMIC_INIT(255);
74
75 static bool reg_requested;
76 static bool gpio_requested;
77
78 static struct regulator *vdd_lcd_s_1v8;
79 static struct regulator *vdd_lcd_bl;
80 static struct regulator *vdd_lcd_bl_en;
81 static struct regulator *avdd_lcd_3v0_2v8;
82
83 static struct regulator *loki_hdmi_reg;
84 static struct regulator *loki_hdmi_pll;
85 static struct regulator *loki_hdmi_vddio;
86
87 #ifdef CONFIG_TEGRA_DC_CMU
88 static struct tegra_dc_cmu loki_cmu = {
89         /* lut1 maps sRGB to linear space. */
90         {
91                 0,    1,    2,    4,    5,    6,    7,    9,
92                 10,   11,   12,   14,   15,   16,   18,   20,
93                 21,   23,   25,   27,   29,   31,   33,   35,
94                 37,   40,   42,   45,   48,   50,   53,   56,
95                 59,   62,   66,   69,   72,   76,   79,   83,
96                 87,   91,   95,   99,   103,  107,  112,  116,
97                 121,  126,  131,  136,  141,  146,  151,  156,
98                 162,  168,  173,  179,  185,  191,  197,  204,
99                 210,  216,  223,  230,  237,  244,  251,  258,
100                 265,  273,  280,  288,  296,  304,  312,  320,
101                 329,  337,  346,  354,  363,  372,  381,  390,
102                 400,  409,  419,  428,  438,  448,  458,  469,
103                 479,  490,  500,  511,  522,  533,  544,  555,
104                 567,  578,  590,  602,  614,  626,  639,  651,
105                 664,  676,  689,  702,  715,  728,  742,  755,
106                 769,  783,  797,  811,  825,  840,  854,  869,
107                 884,  899,  914,  929,  945,  960,  976,  992,
108                 1008, 1024, 1041, 1057, 1074, 1091, 1108, 1125,
109                 1142, 1159, 1177, 1195, 1213, 1231, 1249, 1267,
110                 1286, 1304, 1323, 1342, 1361, 1381, 1400, 1420,
111                 1440, 1459, 1480, 1500, 1520, 1541, 1562, 1582,
112                 1603, 1625, 1646, 1668, 1689, 1711, 1733, 1755,
113                 1778, 1800, 1823, 1846, 1869, 1892, 1916, 1939,
114                 1963, 1987, 2011, 2035, 2059, 2084, 2109, 2133,
115                 2159, 2184, 2209, 2235, 2260, 2286, 2312, 2339,
116                 2365, 2392, 2419, 2446, 2473, 2500, 2527, 2555,
117                 2583, 2611, 2639, 2668, 2696, 2725, 2754, 2783,
118                 2812, 2841, 2871, 2901, 2931, 2961, 2991, 3022,
119                 3052, 3083, 3114, 3146, 3177, 3209, 3240, 3272,
120                 3304, 3337, 3369, 3402, 3435, 3468, 3501, 3535,
121                 3568, 3602, 3636, 3670, 3705, 3739, 3774, 3809,
122                 3844, 3879, 3915, 3950, 3986, 4022, 4059, 4095,
123         },
124         /* csc */
125         {
126                 0x100, 0x0,   0x0,
127                 0x0,   0x100, 0x0,
128                 0x0,   0x0,   0x100,
129         },
130         /* lut2 maps linear space to sRGB*/
131         {
132                 0, 0, 1, 2, 3, 3, 4, 5,
133                 6, 6, 7, 8, 8, 9, 10, 10,
134                 11, 12, 12, 13, 13, 14, 14, 15,
135                 16, 16, 17, 17, 18, 18, 19, 19,
136                 19, 20, 20, 21, 21, 22, 22, 22,
137                 23, 23, 24, 24, 24, 25, 25, 25,
138                 26, 26, 27, 27, 27, 28, 28, 28,
139                 28, 29, 29, 29, 30, 30, 30, 31,
140                 31, 31, 31, 32, 32, 32, 33, 33,
141                 33, 33, 34, 34, 34, 35, 35, 35,
142                 35, 36, 36, 36, 36, 37, 37, 37,
143                 38, 38, 38, 38, 39, 39, 39, 39,
144                 40, 40, 40, 40, 40, 41, 41, 41,
145                 41, 42, 42, 42, 42, 43, 43, 43,
146                 43, 43, 44, 44, 44, 44, 45, 45,
147                 45, 45, 45, 46, 46, 46, 46, 46,
148                 47, 47, 47, 47, 47, 48, 48, 48,
149                 48, 48, 49, 49, 49, 49, 49, 49,
150                 50, 50, 50, 50, 50, 50, 51, 51,
151                 51, 51, 51, 51, 52, 52, 52, 52,
152                 52, 52, 53, 53, 53, 53, 53, 53,
153                 54, 54, 54, 54, 54, 54, 54, 55,
154                 55, 55, 55, 55, 55, 55, 55, 56,
155                 56, 56, 56, 56, 56, 56, 57, 57,
156                 57, 57, 57, 57, 57, 57, 58, 58,
157                 58, 58, 58, 58, 58, 58, 58, 59,
158                 59, 59, 59, 59, 59, 59, 59, 59,
159                 60, 60, 60, 60, 60, 60, 60, 60,
160                 60, 61, 61, 61, 61, 61, 61, 61,
161                 61, 61, 61, 62, 62, 62, 62, 62,
162                 62, 62, 62, 62, 62, 63, 63, 63,
163                 63, 63, 63, 63, 63, 63, 63, 63,
164                 64, 64, 64, 64, 64, 64, 64, 64,
165                 64, 64, 64, 65, 65, 65, 65, 65,
166                 65, 65, 65, 65, 65, 65, 66, 66,
167                 66, 66, 66, 66, 66, 66, 66, 66,
168                 66, 66, 67, 67, 67, 67, 67, 67,
169                 67, 67, 67, 67, 67, 67, 68, 68,
170                 68, 68, 68, 68, 68, 68, 68, 68,
171                 68, 68, 69, 69, 69, 69, 69, 69,
172                 69, 69, 69, 69, 69, 69, 70, 70,
173                 70, 70, 70, 70, 70, 70, 70, 70,
174                 70, 70, 70, 71, 71, 71, 71, 71,
175                 71, 71, 71, 71, 71, 71, 71, 71,
176                 72, 72, 72, 72, 72, 72, 72, 72,
177                 72, 72, 72, 72, 72, 73, 73, 73,
178                 73, 73, 73, 73, 73, 73, 73, 73,
179                 73, 73, 73, 74, 74, 74, 74, 74,
180                 74, 74, 74, 74, 74, 74, 74, 74,
181                 75, 75, 75, 75, 75, 75, 75, 75,
182                 75, 75, 75, 75, 75, 75, 76, 76,
183                 76, 76, 76, 76, 76, 76, 76, 76,
184                 76, 76, 76, 76, 77, 77, 77, 77,
185                 77, 77, 77, 77, 77, 77, 77, 77,
186                 77, 77, 78, 78, 78, 78, 78, 78,
187                 78, 78, 78, 78, 78, 78, 78, 78,
188                 79, 79, 79, 79, 79, 79, 79, 79,
189                 79, 79, 79, 79, 79, 79, 80, 80,
190                 80, 80, 80, 80, 80, 80, 80, 80,
191                 80, 80, 80, 80, 81, 81, 81, 81,
192                 81, 81, 81, 81, 81, 81, 81, 81,
193                 81, 81, 82, 82, 82, 82, 82, 82,
194                 82, 82, 82, 82, 82, 82, 82, 82,
195                 83, 83, 83, 83, 83, 83, 83, 83,
196                 84, 84, 85, 85, 86, 86, 87, 88,
197                 88, 89, 89, 90, 90, 91, 92, 92,
198                 93, 93, 94, 94, 95, 95, 96, 96,
199                 97, 97, 98, 98, 99, 99, 100, 100,
200                 101, 101, 102, 102, 103, 103, 104, 104,
201                 105, 105, 106, 106, 107, 107, 107, 108,
202                 108, 109, 109, 110, 110, 111, 111, 111,
203                 112, 112, 113, 113, 114, 114, 114, 115,
204                 115, 116, 116, 117, 117, 117, 118, 118,
205                 119, 119, 119, 120, 120, 121, 121, 121,
206                 122, 122, 123, 123, 123, 124, 124, 125,
207                 125, 126, 126, 126, 127, 127, 128, 128,
208                 128, 129, 129, 129, 130, 130, 131, 131,
209                 131, 132, 132, 133, 133, 133, 134, 134,
210                 135, 135, 135, 136, 136, 137, 137, 137,
211                 138, 138, 138, 139, 139, 140, 140, 140,
212                 141, 141, 142, 142, 142, 143, 143, 143,
213                 144, 144, 145, 145, 145, 146, 146, 146,
214                 147, 147, 147, 148, 148, 149, 149, 149,
215                 150, 150, 150, 151, 151, 151, 152, 152,
216                 153, 153, 153, 154, 154, 154, 155, 155,
217                 156, 156, 156, 157, 157, 157, 158, 158,
218                 159, 159, 159, 160, 160, 160, 161, 161,
219                 162, 162, 162, 163, 163, 164, 164, 164,
220                 165, 165, 166, 166, 166, 167, 167, 168,
221                 168, 168, 169, 169, 170, 170, 170, 171,
222                 171, 172, 172, 172, 173, 173, 173, 174,
223                 174, 175, 175, 175, 176, 176, 176, 177,
224                 177, 177, 178, 178, 178, 179, 179, 179,
225                 180, 180, 180, 180, 181, 181, 181, 182,
226                 182, 182, 182, 183, 183, 183, 184, 184,
227                 184, 184, 185, 185, 185, 185, 186, 186,
228                 186, 186, 187, 187, 187, 187, 188, 188,
229                 188, 188, 189, 189, 189, 190, 190, 190,
230                 190, 191, 191, 191, 191, 192, 192, 192,
231                 193, 193, 193, 193, 194, 194, 194, 195,
232                 195, 195, 195, 196, 196, 196, 197, 197,
233                 197, 198, 198, 198, 198, 199, 199, 199,
234                 200, 200, 200, 201, 201, 201, 202, 202,
235                 202, 203, 203, 204, 204, 204, 205, 205,
236                 205, 206, 206, 206, 207, 207, 208, 208,
237                 208, 209, 209, 209, 210, 210, 211, 211,
238                 211, 212, 212, 213, 213, 213, 214, 214,
239                 215, 215, 215, 216, 216, 217, 217, 217,
240                 218, 218, 218, 219, 219, 220, 220, 220,
241                 221, 221, 221, 222, 222, 222, 223, 223,
242                 223, 224, 224, 224, 225, 225, 225, 225,
243                 226, 226, 226, 226, 227, 227, 227, 227,
244                 228, 228, 228, 228, 229, 229, 229, 229,
245                 229, 230, 230, 230, 230, 231, 231, 231,
246                 231, 232, 232, 232, 233, 233, 233, 233,
247                 234, 234, 234, 235, 235, 235, 236, 236,
248                 236, 237, 237, 238, 238, 239, 239, 239,
249                 240, 240, 241, 241, 242, 242, 243, 244,
250                 244, 245, 245, 246, 247, 247, 248, 249,
251                 250, 250, 251, 252, 253, 254, 254, 255,
252         },
253 };
254 #endif
255
256 static struct resource loki_disp1_resources[] = {
257         {
258                 .name   = "irq",
259                 .start  = INT_DISPLAY_GENERAL,
260                 .end    = INT_DISPLAY_GENERAL,
261                 .flags  = IORESOURCE_IRQ,
262         },
263         {
264                 .name   = "regs",
265                 .start  = TEGRA_DISPLAY_BASE,
266                 .end    = TEGRA_DISPLAY_BASE + TEGRA_DISPLAY_SIZE - 1,
267                 .flags  = IORESOURCE_MEM,
268         },
269         {
270                 .name   = "fbmem",
271                 .start  = 0, /* Filled in by loki_panel_init() */
272                 .end    = 0, /* Filled in by loki_panel_init() */
273                 .flags  = IORESOURCE_MEM,
274         },
275         {
276                 .name   = "dsi_regs",
277                 .start  = TEGRA_DSI_BASE,
278                 .end    = TEGRA_DSI_BASE + TEGRA_DSI_SIZE - 1,
279                 .flags  = IORESOURCE_MEM,
280         },
281         {
282                 .name   = "mipi_cal",
283                 .start  = TEGRA_MIPI_CAL_BASE,
284                 .end    = TEGRA_MIPI_CAL_BASE + TEGRA_MIPI_CAL_SIZE - 1,
285                 .flags  = IORESOURCE_MEM,
286         },
287 };
288
289 static struct resource loki_disp2_resources[] = {
290         {
291                 .name   = "irq",
292                 .start  = INT_DISPLAY_B_GENERAL,
293                 .end    = INT_DISPLAY_B_GENERAL,
294                 .flags  = IORESOURCE_IRQ,
295         },
296         {
297                 .name   = "regs",
298                 .start  = TEGRA_DISPLAY2_BASE,
299                 .end    = TEGRA_DISPLAY2_BASE + TEGRA_DISPLAY2_SIZE - 1,
300                 .flags  = IORESOURCE_MEM,
301         },
302         {
303                 .name   = "fbmem",
304                 .start  = 0, /* Filled in by loki_panel_init() */
305                 .end    = 0, /* Filled in by loki_panel_init() */
306                 .flags  = IORESOURCE_MEM,
307         },
308         {
309                 .name   = "hdmi_regs",
310                 .start  = TEGRA_HDMI_BASE,
311                 .end    = TEGRA_HDMI_BASE + TEGRA_HDMI_SIZE - 1,
312                 .flags  = IORESOURCE_MEM,
313         },
314 };
315
316 static u8 panel_dsi_config[] = {0xe0, 0x43, 0x0, 0x80, 0x0, 0x0};
317 static u8 panel_disp_ctrl1[] = {0xb5, 0x34, 0x20, 0x40, 0x0, 0x20};
318 static u8 panel_disp_ctrl2[] = {0xb6, 0x04, 0x74, 0x0f, 0x16, 0x13};
319 static u8 panel_internal_clk[] = {0xc0, 0x01, 0x08};
320 static u8 panel_pwr_ctrl3[] = {
321         0xc3, 0x0, 0x09, 0x10, 0x02, 0x0, 0x66, 0x00, 0x13, 0x0};
322 static u8 panel_pwr_ctrl4[] = {0xc4, 0x23, 0x24, 0x12, 0x12, 0x60};
323 static u8 panel_positive_gamma_red[] = {
324         0xd0, 0x21, 0x25, 0x67, 0x36, 0x0a, 0x06, 0x61, 0x23, 0x03};
325 static u8 panel_negetive_gamma_red[] = {
326         0xd1, 0x31, 0x25, 0x66, 0x36, 0x05, 0x06, 0x61, 0x23, 0x03};
327 static u8 panel_positive_gamma_green[] = {
328         0xd2, 0x41, 0x26, 0x56, 0x36, 0x0a, 0x06, 0x61, 0x23, 0x03};
329 static u8 panel_negetive_gamma_green[] = {
330         0xd3, 0x51, 0x26, 0x55, 0x36, 0x05, 0x06, 0x61, 0x23, 0x03};
331 static u8 panel_positive_gamma_blue[] = {
332         0xd4, 0x41, 0x26, 0x56, 0x36, 0x0a, 0x06, 0x61, 0x23, 0x03};
333 static u8 panel_negetive_gamma_blue[] = {
334         0xd5, 0x51, 0x26, 0x55, 0x36, 0x05, 0x06, 0x61, 0x23, 0x03};
335
336 #if DSI_PANEL_CE
337 static u8 panel_ce2[] = {0x71, 0x0, 0x0, 0x01, 0x01};
338 static u8 panel_ce3[] = {0x72, 0x01, 0x0e};
339 static u8 panel_ce4[] = {0x73, 0x34, 0x52, 0x0};
340 static u8 panel_ce5[] = {0x74, 0x05, 0x0, 0x06};
341 static u8 panel_ce6[] = {0x75, 0x03, 0x0, 0x07};
342 static u8 panel_ce7[] = {0x76, 0x07, 0x0, 0x06};
343 static u8 panel_ce8[] = {0x77, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f};
344 static u8 panel_ce9[] = {0x78, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40};
345 static u8 panel_ce10[] = {
346         0x79, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40};
347 static u8 panel_ce11[] = {0x7a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
348 static u8 panel_ce12[] = {0x7b, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
349 static u8 panel_ce13[] = {0x7c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
350 #endif
351
352 static struct tegra_dsi_cmd dsi_init_cmd[] = {
353         DSI_DLY_MS(20),
354         DSI_GPIO_SET(DSI_PANEL_RST_GPIO, 1),
355
356         DSI_CMD_LONG(DSI_GENERIC_LONG_WRITE, panel_dsi_config),
357
358         DSI_CMD_LONG(DSI_GENERIC_LONG_WRITE, panel_disp_ctrl1),
359         DSI_CMD_LONG(DSI_GENERIC_LONG_WRITE, panel_disp_ctrl2),
360
361         DSI_CMD_LONG(DSI_GENERIC_LONG_WRITE, panel_internal_clk),
362
363         /*  panel power control 1 */
364         DSI_CMD_SHORT(DSI_GENERIC_SHORT_WRITE_2_PARAMS, 0xc1, 0x0),
365         DSI_CMD_LONG(DSI_GENERIC_LONG_WRITE, panel_pwr_ctrl3),
366         DSI_CMD_LONG(DSI_GENERIC_LONG_WRITE, panel_pwr_ctrl4),
367
368         DSI_CMD_LONG(DSI_GENERIC_LONG_WRITE, panel_positive_gamma_red),
369         DSI_CMD_LONG(DSI_GENERIC_LONG_WRITE, panel_negetive_gamma_red),
370         DSI_CMD_LONG(DSI_GENERIC_LONG_WRITE, panel_positive_gamma_green),
371         DSI_CMD_LONG(DSI_GENERIC_LONG_WRITE, panel_negetive_gamma_green),
372         DSI_CMD_LONG(DSI_GENERIC_LONG_WRITE, panel_positive_gamma_blue),
373         DSI_CMD_LONG(DSI_GENERIC_LONG_WRITE, panel_negetive_gamma_blue),
374
375         DSI_CMD_SHORT(DSI_DCS_WRITE_1_PARAM, DSI_DCS_SET_ADDR_MODE, 0x0B),
376
377         /* panel OTP 2 */
378         DSI_CMD_SHORT(DSI_GENERIC_SHORT_WRITE_2_PARAMS, 0xf9, 0x0),
379
380 #if DSI_PANEL_CE
381         /* panel CE 1 */
382         DSI_CMD_SHORT(DSI_GENERIC_SHORT_WRITE_2_PARAMS, 0x70, 0x0),
383         DSI_CMD_LONG(DSI_GENERIC_LONG_WRITE, panel_ce2),
384         DSI_CMD_LONG(DSI_GENERIC_LONG_WRITE, panel_ce3),
385         DSI_CMD_LONG(DSI_GENERIC_LONG_WRITE, panel_ce4),
386         DSI_CMD_LONG(DSI_GENERIC_LONG_WRITE, panel_ce5),
387         DSI_CMD_LONG(DSI_GENERIC_LONG_WRITE, panel_ce6),
388         DSI_CMD_LONG(DSI_GENERIC_LONG_WRITE, panel_ce7),
389         DSI_CMD_LONG(DSI_GENERIC_LONG_WRITE, panel_ce8),
390         DSI_CMD_LONG(DSI_GENERIC_LONG_WRITE, panel_ce9),
391         DSI_CMD_LONG(DSI_GENERIC_LONG_WRITE, panel_ce10),
392         DSI_CMD_LONG(DSI_GENERIC_LONG_WRITE, panel_ce11),
393         DSI_CMD_LONG(DSI_GENERIC_LONG_WRITE, panel_ce12),
394         DSI_CMD_LONG(DSI_GENERIC_LONG_WRITE, panel_ce13),
395 #endif
396         /* panel power control 2 */
397         DSI_CMD_SHORT(DSI_GENERIC_SHORT_WRITE_2_PARAMS, 0xc2, 0x02),
398         DSI_DLY_MS(20),
399
400         /* panel power control 2 */
401         DSI_CMD_SHORT(DSI_GENERIC_SHORT_WRITE_2_PARAMS, 0xc2, 0x06),
402         DSI_DLY_MS(20),
403
404         /* panel power control 2 */
405         DSI_CMD_SHORT(DSI_GENERIC_SHORT_WRITE_2_PARAMS, 0xc2, 0x4e),
406         DSI_DLY_MS(100),
407
408         DSI_CMD_SHORT(DSI_DCS_WRITE_0_PARAM, DSI_DCS_EXIT_SLEEP_MODE, 0x0),
409         DSI_DLY_MS(140),
410
411         /* panel OTP 2 */
412         DSI_CMD_SHORT(DSI_GENERIC_SHORT_WRITE_2_PARAMS, 0xf9, 0x80),
413         DSI_DLY_MS(20),
414
415         DSI_CMD_SHORT(DSI_DCS_WRITE_0_PARAM, DSI_DCS_SET_DISPLAY_ON, 0x0),
416 };
417
418 static u8 panel_suspend_pwr_ctrl4[] = {0xc4, 0x0, 0x0, 0x0, 0x0, 0x0};
419
420 static struct tegra_dsi_cmd dsi_suspend_cmd[] = {
421         DSI_DLY_MS(40),
422
423         DSI_CMD_SHORT(DSI_DCS_WRITE_0_PARAM, DSI_DCS_SET_DISPLAY_OFF, 0x0),
424         DSI_DLY_MS(20),
425
426         DSI_CMD_SHORT(DSI_DCS_WRITE_0_PARAM, DSI_DCS_ENTER_SLEEP_MODE, 0x0),
427
428         /* panel power control 2 */
429         DSI_CMD_SHORT(DSI_GENERIC_SHORT_WRITE_2_PARAMS, 0xc2, 0x0),
430
431         /* panel power control 4 */
432         DSI_CMD_LONG(DSI_GENERIC_LONG_WRITE, panel_suspend_pwr_ctrl4),
433
434         /* panel power control 1 */
435         DSI_CMD_SHORT(DSI_GENERIC_SHORT_WRITE_2_PARAMS, 0xc1, 0x2),
436         DSI_DLY_MS(20),
437
438         /* panel power control 1 */
439         DSI_CMD_SHORT(DSI_GENERIC_SHORT_WRITE_2_PARAMS, 0xc1, 0x3),
440         DSI_DLY_MS(20),
441 };
442
443 static struct tegra_dsi_out loki_dsi = {
444         .n_data_lanes = 4,
445         .controller_vs = DSI_VS_1,
446         .pixel_format = TEGRA_DSI_PIXEL_FORMAT_24BIT_P,
447         .refresh_rate = 60,
448         .virtual_channel = TEGRA_DSI_VIRTUAL_CHANNEL_0,
449
450         .dsi_instance = DSI_INSTANCE_0,
451
452         .panel_reset = DSI_PANEL_RESET,
453         .power_saving_suspend = true,
454         .video_data_type = TEGRA_DSI_VIDEO_TYPE_VIDEO_MODE,
455         .video_clock_mode = TEGRA_DSI_VIDEO_CLOCK_CONTINUOUS,
456         .video_burst_mode = TEGRA_DSI_VIDEO_NONE_BURST_MODE_WITH_SYNC_END,
457         .dsi_init_cmd = dsi_init_cmd,
458         .n_init_cmd = ARRAY_SIZE(dsi_init_cmd),
459         .dsi_suspend_cmd = dsi_suspend_cmd,
460         .n_suspend_cmd = ARRAY_SIZE(dsi_suspend_cmd),
461 };
462
463 static int loki_dsi_regulator_get(struct device *dev)
464 {
465         int err = 0;
466
467         if (reg_requested)
468                 return 0;
469
470         avdd_lcd_3v0_2v8 = regulator_get(dev, "avdd_lcd");
471         if (IS_ERR_OR_NULL(avdd_lcd_3v0_2v8)) {
472                 pr_err("avdd_lcd regulator get failed\n");
473                 err = PTR_ERR(avdd_lcd_3v0_2v8);
474                 avdd_lcd_3v0_2v8 = NULL;
475                 goto fail;
476         }
477         vdd_lcd_s_1v8 = regulator_get(dev, "dvdd_lcd");
478         if (IS_ERR_OR_NULL(vdd_lcd_s_1v8)) {
479                 pr_err("vdd_lcd_1v8_s regulator get failed\n");
480                 err = PTR_ERR(vdd_lcd_s_1v8);
481                 vdd_lcd_s_1v8 = NULL;
482                 goto fail;
483         }
484
485         if (machine_is_dalmore()) {
486                 vdd_lcd_bl = regulator_get(dev, "vdd_lcd_bl");
487                 if (IS_ERR_OR_NULL(vdd_lcd_bl)) {
488                         pr_err("vdd_lcd_bl regulator get failed\n");
489                         err = PTR_ERR(vdd_lcd_bl);
490                         vdd_lcd_bl = NULL;
491                         goto fail;
492                 }
493         }
494
495         vdd_lcd_bl_en = regulator_get(dev, "vdd_lcd_bl_en");
496         if (IS_ERR_OR_NULL(vdd_lcd_bl_en)) {
497                 pr_err("vdd_lcd_bl_en regulator get failed\n");
498                 err = PTR_ERR(vdd_lcd_bl_en);
499                 vdd_lcd_bl_en = NULL;
500                 goto fail;
501         }
502         reg_requested = true;
503         return 0;
504 fail:
505         return err;
506 }
507
508 static int loki_dsi_gpio_get(void)
509 {
510         int err = 0;
511
512         if (gpio_requested)
513                 return 0;
514
515         err = gpio_request(DSI_PANEL_RST_GPIO, "panel rst");
516         if (err < 0) {
517                 pr_err("panel reset gpio request failed\n");
518                 goto fail;
519         }
520
521         gpio_requested = true;
522         return 0;
523 fail:
524         return err;
525 }
526
527 static struct tegra_dc_out loki_disp1_out;
528
529 static int loki_dsi_panel_enable(struct device *dev)
530 {
531         int err = 0;
532
533         err = loki_dsi_regulator_get(dev);
534         if (err < 0) {
535                 pr_err("dsi regulator get failed\n");
536                 goto fail;
537         }
538         err = loki_dsi_gpio_get();
539         if (err < 0) {
540                 pr_err("dsi gpio request failed\n");
541                 goto fail;
542         }
543
544         /* Skip panel programming if in initialized mode */
545         if (!(loki_disp1_out.flags & TEGRA_DC_OUT_INITIALIZED_MODE)) {
546                 loki_dsi.dsi_init_cmd = dsi_init_cmd;
547                 gpio_set_value(DSI_PANEL_RST_GPIO, 0);
548         } else {
549                 loki_dsi.dsi_init_cmd = dsi_init_cmd + 2;
550         }
551
552         if (vdd_lcd_s_1v8) {
553                 err = regulator_enable(vdd_lcd_s_1v8);
554                 if (err < 0) {
555                         pr_err("vdd_lcd_1v8_s regulator enable failed\n");
556                         goto fail;
557                 }
558         }
559         usleep_range(3000, 5000);
560
561         if (avdd_lcd_3v0_2v8) {
562                 err = regulator_enable(avdd_lcd_3v0_2v8);
563                 if (err < 0) {
564                         pr_err("avdd_lcd_3v0_2v8 regulator enable failed\n");
565                         goto fail;
566                 }
567                 regulator_set_voltage(avdd_lcd_3v0_2v8, 2800000, 2800000);
568         }
569         usleep_range(3000, 5000);
570
571         if (vdd_lcd_bl) {
572                 err = regulator_enable(vdd_lcd_bl);
573                 if (err < 0) {
574                         pr_err("vdd_lcd_bl regulator enable failed\n");
575                         goto fail;
576                 }
577         }
578
579         if (vdd_lcd_bl_en) {
580                 err = regulator_enable(vdd_lcd_bl_en);
581                 if (err < 0) {
582                         pr_err("vdd_lcd_bl_en regulator enable failed\n");
583                         goto fail;
584                 }
585         }
586
587         return 0;
588 fail:
589         return err;
590 }
591
592 static int loki_dsi_panel_disable(void)
593 {
594         if (vdd_lcd_bl)
595                 regulator_disable(vdd_lcd_bl);
596
597         if (vdd_lcd_bl_en)
598                 regulator_disable(vdd_lcd_bl_en);
599
600         gpio_set_value(DSI_PANEL_RST_GPIO, 0);
601         mdelay(20);
602
603         if (vdd_lcd_s_1v8)
604                 regulator_disable(vdd_lcd_s_1v8);
605
606         if (avdd_lcd_3v0_2v8)
607                 regulator_disable(avdd_lcd_3v0_2v8);
608
609         return 0;
610 }
611
612 static int loki_dsi_panel_postsuspend(void)
613 {
614         /* TODO */
615         return 0;
616 }
617
618 static struct tegra_dc_mode loki_dsi_modes[] = {
619         {
620                 .pclk = 66700000,
621                 .h_ref_to_sync = 4,
622                 .v_ref_to_sync = 1,
623                 .h_sync_width = 4,
624                 .v_sync_width = 4,
625                 .h_back_porch = 112,
626                 .v_back_porch = 12,
627                 .h_active = 720,
628                 .v_active = 1280,
629                 .h_front_porch = 12,
630                 .v_front_porch = 8,
631         },
632 };
633
634 static struct tegra_dc_sd_settings sd_settings;
635
636 static struct tegra_dc_out loki_disp1_out = {
637         .type           = TEGRA_DC_OUT_DSI,
638         .dsi            = &loki_dsi,
639
640         .flags          = DC_CTRL_MODE,
641         .sd_settings    = &sd_settings,
642
643         .modes          = loki_dsi_modes,
644         .n_modes        = ARRAY_SIZE(loki_dsi_modes),
645
646         .enable         = loki_dsi_panel_enable,
647         .disable        = loki_dsi_panel_disable,
648         .postsuspend    = loki_dsi_panel_postsuspend,
649         .width          = 62,
650         .height         = 110,
651 };
652
653 static int loki_hdmi_enable(struct device *dev)
654 {
655         int ret;
656         if (!loki_hdmi_reg) {
657                 loki_hdmi_reg = regulator_get(dev, "avdd_hdmi");
658                 if (IS_ERR_OR_NULL(loki_hdmi_reg)) {
659                         pr_err("hdmi: couldn't get regulator avdd_hdmi\n");
660                         loki_hdmi_reg = NULL;
661                         return PTR_ERR(loki_hdmi_reg);
662                 }
663         }
664         ret = regulator_enable(loki_hdmi_reg);
665         if (ret < 0) {
666                 pr_err("hdmi: couldn't enable regulator avdd_hdmi\n");
667                 return ret;
668         }
669         if (!loki_hdmi_pll) {
670                 loki_hdmi_pll = regulator_get(dev, "avdd_hdmi_pll");
671                 if (IS_ERR_OR_NULL(loki_hdmi_pll)) {
672                         pr_err("hdmi: couldn't get regulator avdd_hdmi_pll\n");
673                         loki_hdmi_pll = NULL;
674                         regulator_put(loki_hdmi_reg);
675                         loki_hdmi_reg = NULL;
676                         return PTR_ERR(loki_hdmi_pll);
677                 }
678         }
679         ret = regulator_enable(loki_hdmi_pll);
680         if (ret < 0) {
681                 pr_err("hdmi: couldn't enable regulator avdd_hdmi_pll\n");
682                 return ret;
683         }
684         return 0;
685 }
686
687 static int loki_hdmi_disable(void)
688 {
689         if (loki_hdmi_reg) {
690                 regulator_disable(loki_hdmi_reg);
691                 regulator_put(loki_hdmi_reg);
692                 loki_hdmi_reg = NULL;
693         }
694
695         if (loki_hdmi_pll) {
696                 regulator_disable(loki_hdmi_pll);
697                 regulator_put(loki_hdmi_pll);
698                 loki_hdmi_pll = NULL;
699         }
700
701         return 0;
702 }
703
704 static int loki_hdmi_postsuspend(void)
705 {
706         if (loki_hdmi_vddio) {
707                 regulator_disable(loki_hdmi_vddio);
708                 regulator_put(loki_hdmi_vddio);
709                 loki_hdmi_vddio = NULL;
710         }
711         return 0;
712 }
713
714 static int loki_hdmi_hotplug_init(struct device *dev)
715 {
716         if (!loki_hdmi_vddio) {
717                 loki_hdmi_vddio = regulator_get(dev, "vdd_hdmi_5v0");
718                 if (WARN_ON(IS_ERR(loki_hdmi_vddio))) {
719                         pr_err("%s: couldn't get regulator vdd_hdmi_5v0: %ld\n",
720                                         __func__, PTR_ERR(loki_hdmi_vddio));
721                         loki_hdmi_vddio = NULL;
722                 } else
723                         regulator_enable(loki_hdmi_vddio);
724         }
725         return 0;
726 }
727
728 static void loki_hdmi_hotplug_report(bool state)
729 {
730         if (state) {
731                 tegra_pinmux_set_pullupdown(TEGRA_PINGROUP_DDC_SDA,
732                                                 TEGRA_PUPD_PULL_DOWN);
733                 tegra_pinmux_set_pullupdown(TEGRA_PINGROUP_DDC_SCL,
734                                                 TEGRA_PUPD_PULL_DOWN);
735         } else {
736                 tegra_pinmux_set_pullupdown(TEGRA_PINGROUP_DDC_SDA,
737                                                 TEGRA_PUPD_NORMAL);
738                 tegra_pinmux_set_pullupdown(TEGRA_PINGROUP_DDC_SCL,
739                                                 TEGRA_PUPD_NORMAL);
740         }
741 }
742
743 static struct tegra_dc_out loki_disp2_out = {
744         .type           = TEGRA_DC_OUT_HDMI,
745         .flags          = TEGRA_DC_OUT_HOTPLUG_HIGH,
746         .parent_clk     = "pll_d2_out0",
747
748         .dcc_bus        = 3,
749         .hotplug_gpio   = loki_hdmi_hpd,
750
751         .max_pixclock   = KHZ2PICOS(297000),
752
753         .align          = TEGRA_DC_ALIGN_MSB,
754         .order          = TEGRA_DC_ORDER_RED_BLUE,
755
756         .enable         = loki_hdmi_enable,
757         .disable        = loki_hdmi_disable,
758         .postsuspend    = loki_hdmi_postsuspend,
759         .hotplug_init   = loki_hdmi_hotplug_init,
760         .hotplug_report = loki_hdmi_hotplug_report,
761 };
762
763 static struct tegra_fb_data loki_disp1_fb_data = {
764         .win            = 0,
765         .bits_per_pixel = 32,
766         .flags          = TEGRA_FB_FLIP_ON_PROBE,
767         .xres           = 720,
768         .yres           = 1280,
769 };
770
771 static struct tegra_dc_platform_data loki_disp1_pdata = {
772         .flags          = TEGRA_DC_FLAG_ENABLED,
773         .default_out    = &loki_disp1_out,
774         .fb             = &loki_disp1_fb_data,
775         .emc_clk_rate   = 204000000,
776 #ifdef CONFIG_TEGRA_DC_CMU
777         .cmu_enable     = 1,
778         .cmu            = &loki_cmu,
779 #endif
780 };
781
782 static struct tegra_fb_data loki_disp2_fb_data = {
783         .win            = 0,
784         .xres           = 1024,
785         .yres           = 600,
786         .bits_per_pixel = 32,
787         .flags          = TEGRA_FB_FLIP_ON_PROBE,
788 };
789
790 static struct tegra_dc_platform_data loki_disp2_pdata = {
791         .flags          = TEGRA_DC_FLAG_ENABLED,
792         .default_out    = &loki_disp2_out,
793         .fb             = &loki_disp2_fb_data,
794         .emc_clk_rate   = 300000000,
795 #ifdef CONFIG_TEGRA_DC_CMU
796         .cmu_enable     = 1,
797 #endif
798 };
799
800 static struct platform_device loki_disp2_device = {
801         .name           = "tegradc",
802         .id             = 1,
803         .resource       = loki_disp2_resources,
804         .num_resources  = ARRAY_SIZE(loki_disp2_resources),
805         .dev = {
806                 .platform_data = &loki_disp2_pdata,
807         },
808 };
809
810 static struct platform_device loki_disp1_device = {
811         .name           = "tegradc",
812         .id             = 0,
813         .resource       = loki_disp1_resources,
814         .num_resources  = ARRAY_SIZE(loki_disp1_resources),
815         .dev = {
816                 .platform_data = &loki_disp1_pdata,
817         },
818 };
819
820 static struct nvmap_platform_carveout loki_carveouts[] = {
821         [0] = {
822                 .name           = "iram",
823                 .usage_mask     = NVMAP_HEAP_CARVEOUT_IRAM,
824                 .base           = TEGRA_IRAM_BASE + TEGRA_RESET_HANDLER_SIZE,
825                 .size           = TEGRA_IRAM_SIZE - TEGRA_RESET_HANDLER_SIZE,
826                 .buddy_size     = 0, /* no buddy allocation for IRAM */
827         },
828         [1] = {
829                 .name           = "generic-0",
830                 .usage_mask     = NVMAP_HEAP_CARVEOUT_GENERIC,
831                 .base           = 0, /* Filled in by loki_panel_init() */
832                 .size           = 0, /* Filled in by loki_panel_init() */
833                 .buddy_size     = SZ_32K,
834         },
835         [2] = {
836                 .name           = "vpr",
837                 .usage_mask     = NVMAP_HEAP_CARVEOUT_VPR,
838                 .base           = 0, /* Filled in by loki_panel_init() */
839                 .size           = 0, /* Filled in by loki_panel_init() */
840                 .buddy_size     = SZ_32K,
841         },
842 };
843
844 static struct nvmap_platform_data loki_nvmap_data = {
845         .carveouts      = loki_carveouts,
846         .nr_carveouts   = ARRAY_SIZE(loki_carveouts),
847 };
848
849 static struct platform_device loki_nvmap_device = {
850         .name   = "tegra-nvmap",
851         .id     = -1,
852         .dev    = {
853                 .platform_data = &loki_nvmap_data,
854         },
855 };
856
857 static int loki_disp1_bl_notify(struct device *unused, int brightness)
858 {
859         int cur_sd_brightness = atomic_read(&sd_brightness);
860
861         /* SD brightness is a percentage */
862         brightness = (brightness * cur_sd_brightness) / 255;
863
864         /* Apply any backlight response curve */
865         if (brightness > 255)
866                 pr_info("Error: Brightness > 255!\n");
867
868         return brightness;
869 }
870
871 static int loki_disp1_check_fb(struct device *dev, struct fb_info *info)
872 {
873         return info->device == &loki_disp1_device.dev;
874 }
875
876 static struct platform_pwm_backlight_data loki_disp1_bl_data = {
877         .pwm_id         = 1,
878         .max_brightness = 255,
879         .dft_brightness = 77,
880         .pwm_period_ns  = 40000,
881         .pwm_gpio       = DSI_PANEL_BL_PWM,
882         .notify         = loki_disp1_bl_notify,
883         /* Only toggle backlight on fb blank notifications for disp1 */
884         .check_fb       = loki_disp1_check_fb,
885 };
886
887 static struct platform_device __maybe_unused
888                 loki_disp1_bl_device = {
889         .name   = "pwm-backlight",
890         .id     = -1,
891         .dev    = {
892                 .platform_data = &loki_disp1_bl_data,
893         },
894 };
895
896 static struct tegra_dc_sd_settings loki_sd_settings = {
897         .enable = 0, /* disabled by default. */
898         .use_auto_pwm = false,
899         .hw_update_delay = 0,
900         .bin_width = -1,
901         .aggressiveness = 1,
902         .use_vid_luma = false,
903         .phase_in_adjustments = 0,
904         .k_limit_enable = true,
905         .k_limit = 180,
906         .sd_window_enable = false,
907         .soft_clipping_enable = true,
908         /* Low soft clipping threshold to compensate for aggressive k_limit */
909         .soft_clipping_threshold = 128,
910         .smooth_k_enable = true,
911         .smooth_k_incr = 128,
912         /* Default video coefficients */
913         .coeff = {5, 9, 2},
914         .fc = {0, 0},
915         /* Immediate backlight changes */
916         .blp = {1024, 255},
917         /* Gammas: R: 2.2 G: 2.2 B: 2.2 */
918         /* Default BL TF */
919         .bltf = {
920                         {
921                                 {57, 65, 73, 82},
922                                 {92, 103, 114, 125},
923                                 {138, 150, 164, 178},
924                                 {193, 208, 224, 241},
925                         },
926                 },
927         /* Default LUT */
928         .lut = {
929                         {
930                                 {255, 255, 255},
931                                 {199, 199, 199},
932                                 {153, 153, 153},
933                                 {116, 116, 116},
934                                 {85, 85, 85},
935                                 {59, 59, 59},
936                                 {36, 36, 36},
937                                 {17, 17, 17},
938                                 {0, 0, 0},
939                         },
940                 },
941         .sd_brightness = &sd_brightness,
942         .bl_device_name = "pwm-backlight",
943 };
944
945 static struct platform_device __maybe_unused
946                         *loki_bl_device[] __initdata = {
947         &tegra_pwfm_device,
948         &loki_disp1_bl_device,
949 };
950
951 int __init loki_panel_init(int board_id)
952 {
953         int err = 0;
954         struct resource __maybe_unused *res;
955         struct platform_device *phost1x = NULL;
956
957         sd_settings = loki_sd_settings;
958
959 #ifdef CONFIG_TEGRA_NVMAP
960         loki_carveouts[1].base = tegra_carveout_start;
961         loki_carveouts[1].size = tegra_carveout_size;
962         loki_carveouts[2].base = tegra_vpr_start;
963         loki_carveouts[2].size = tegra_vpr_size;
964
965         err = platform_device_register(&loki_nvmap_device);
966         if (err) {
967                 pr_err("nvmap device registration failed\n");
968                 return err;
969         }
970 #endif
971
972         phost1x = loki_host1x_init();
973         if (!phost1x) {
974                 pr_err("host1x devices registration failed\n");
975                 return -EINVAL;
976         }
977
978         res = platform_get_resource_byname(&loki_disp1_device,
979                                          IORESOURCE_MEM, "fbmem");
980         res->start = tegra_fb_start;
981         res->end = tegra_fb_start + tegra_fb_size - 1;
982
983         /* Copy the bootloader fb to the fb. */
984         __tegra_move_framebuffer(&loki_nvmap_device,
985                 tegra_fb_start, tegra_bootloader_fb_start,
986                         min(tegra_fb_size, tegra_bootloader_fb_size));
987
988         res = platform_get_resource_byname(&loki_disp2_device,
989                                          IORESOURCE_MEM, "fbmem");
990         res->start = tegra_fb2_start;
991         res->end = tegra_fb2_start + tegra_fb2_size - 1;
992
993         /*
994          * only loki supports initialized mode.
995          */
996         loki_disp1_out.flags |= TEGRA_DC_OUT_INITIALIZED_MODE;
997
998         loki_disp1_device.dev.parent = &phost1x->dev;
999         err = platform_device_register(&loki_disp1_device);
1000         if (err) {
1001                 pr_err("disp1 device registration failed\n");
1002                 return err;
1003         }
1004
1005         loki_disp2_device.dev.parent = &phost1x->dev;
1006         err = platform_device_register(&loki_disp2_device);
1007         if (err) {
1008                 pr_err("disp2 device registration failed\n");
1009                 return err;
1010         }
1011
1012 #if IS_EXTERNAL_PWM
1013         err = platform_add_devices(loki_bl_device,
1014                                 ARRAY_SIZE(loki_bl_device));
1015         if (err) {
1016                 pr_err("disp1 bl device registration failed");
1017                 return err;
1018         }
1019 #endif
1020
1021 #ifdef CONFIG_TEGRA_NVAVP
1022         nvavp_device.dev.parent = &phost1x->dev;
1023         err = platform_device_register(&nvavp_device);
1024         if (err) {
1025                 pr_err("nvavp device registration failed\n");
1026                 return err;
1027         }
1028 #endif
1029         return err;
1030 }
1031 #else
1032 int __init loki_panel_init(void)
1033 {
1034         if (loki_host1x_init())
1035                 return 0;
1036         else
1037                 return -EINVAL;
1038 }
1039 #endif