]> rtime.felk.cvut.cz Git - sojka/nv-tegra/linux-3.10.git/blob - arch/arm/mach-tegra/panel-a-1200-1920-8-0.c
Revert "Revert "dc: tegra: disable prism at low brightness""
[sojka/nv-tegra/linux-3.10.git] / arch / arm / mach-tegra / panel-a-1200-1920-8-0.c
1 /*
2  * arch/arm/mach-tegra/panel-a-1200-1920-8-0.c
3  *
4  * Copyright (c) 2013-2014, NVIDIA CORPORATION.  All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms and conditions of the GNU General Public License,
8  * version 2, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #include <mach/dc.h>
20 #include <linux/delay.h>
21 #include <linux/gpio.h>
22 #include <linux/tegra_pwm_bl.h>
23 #include <linux/regulator/consumer.h>
24 #include <linux/pwm_backlight.h>
25 #include <linux/max8831_backlight.h>
26 #include <linux/leds.h>
27 #include <linux/ioport.h>
28 #include <linux/mfd/palmas.h>
29 #include <generated/mach-types.h>
30 #include <video/mipi_display.h>
31 #include "board.h"
32 #include "board-panel.h"
33 #include "devices.h"
34 #include "gpio-names.h"
35 #include "tegra11_host1x_devices.h"
36
37 #define TEGRA_DSI_GANGED_MODE   0
38
39 #define DSI_PANEL_RESET         1
40
41 #define DC_CTRL_MODE    (TEGRA_DC_OUT_CONTINUOUS_MODE  |\
42                         TEGRA_DC_OUT_INITIALIZED_MODE)
43
44 #define PRISM_THRESHOLD         50
45 #define HYST_VAL                25
46
47 static bool reg_requested;
48 static bool gpio_requested;
49 static struct platform_device *disp_device;
50 static struct regulator *avdd_lcd_3v3;
51 static struct regulator *vdd_lcd_bl_en;
52 static struct regulator *dvdd_lcd_1v8;
53 static struct device *dc_dev;
54
55 static struct tegra_dc_sd_settings dsi_a_1200_1920_8_0_sd_settings = {
56         .enable = 0, /* disabled by default. */
57         .enable_int = 0, /* disabled by default. */
58         .use_auto_pwm = false,
59         .hw_update_delay = 0,
60         .bin_width = -1,
61         .aggressiveness = 3,
62         .use_vid_luma = false,
63         .phase_in_adjustments = 0,
64         .k_limit_enable = true,
65         .k_limit = 220,
66         .sd_window_enable = false,
67         .soft_clipping_enable = true,
68         /* Low soft clipping threshold to compensate for aggressive k_limit */
69         .soft_clipping_threshold = 128,
70         .smooth_k_enable = true,
71         .smooth_k_incr = 4,
72         /* Default video coefficients */
73         .coeff = {5, 9, 2},
74         .fc = {0, 0},
75         /* Immediate backlight changes */
76         .blp = {1024, 255},
77         /* Gammas: R: 2.2 G: 2.2 B: 2.2 */
78         /* Default BL TF */
79         .bltf = {
80                         {
81                                 {57, 65, 73, 82},
82                                 {92, 103, 114, 125},
83                                 {138, 150, 164, 178},
84                                 {193, 208, 224, 241},
85                         },
86                 },
87         /* Default LUT */
88         .lut = {
89                         {
90                                 {255, 255, 255},
91                                 {199, 199, 199},
92                                 {153, 153, 153},
93                                 {116, 116, 116},
94                                 {85, 85, 85},
95                                 {59, 59, 59},
96                                 {36, 36, 36},
97                                 {17, 17, 17},
98                                 {0, 0, 0},
99                         },
100                 },
101         .sd_brightness = &sd_brightness,
102         .use_vpulse2 = true,
103 };
104
105 static tegra_dc_bl_output dsi_a_1200_1920_8_0_bl_output_measured = {
106         0, 1, 2, 4, 5, 6, 7, 8,
107         10, 11, 12, 13, 14, 14, 15, 16,
108         17, 18, 18, 19, 20, 21, 22, 23,
109         24, 25, 26, 27, 28, 29, 30, 31,
110         32, 33, 34, 35, 36, 37, 38, 39,
111         40, 41, 42, 43, 44, 45, 46, 47,
112         48, 49, 50, 51, 52, 53, 54, 55,
113         55, 56, 57, 58, 59, 60, 61, 62,
114         63, 64, 65, 66, 67, 68, 69, 70,
115         71, 72, 73, 74, 75, 76, 77, 78,
116         79, 80, 81, 82, 83, 84, 85, 86,
117         87, 88, 89, 90, 91, 92, 93, 94,
118         95, 96, 97, 98, 99, 100, 101, 102,
119         103, 104, 105, 106, 107, 108, 109, 110,
120         111, 112, 113, 114, 115, 116, 117, 118,
121         119, 120, 121, 122, 123, 124, 125, 126,
122         127, 128, 129, 130, 131, 132, 133, 134,
123         135, 136, 137, 138, 139, 140, 141, 142,
124         143, 144, 145, 146, 147, 148, 149, 150,
125         151, 152, 153, 154, 155, 156, 157, 158,
126         159, 160, 161, 162, 163, 164, 165, 166,
127         167, 168, 169, 170, 171, 172, 173, 174,
128         175, 176, 177, 178, 179, 180, 181, 182,
129         183, 184, 185, 186, 187, 188, 189, 190,
130         191, 192, 193, 194, 195, 196, 197, 198,
131         199, 200, 201, 202, 203, 204, 205, 206,
132         207, 208, 209, 210, 211, 212, 213, 214,
133         215, 216, 217, 218, 219, 220, 221, 222,
134         223, 224, 225, 226, 227, 228, 229, 230,
135         231, 232, 233, 234, 235, 236, 237, 238,
136         239, 240, 241, 242, 243, 244, 245, 246,
137         247, 248, 249, 250, 251, 253, 254, 255,
138 };
139
140 static u8 dsi_a_1200_1920_8_0_bl_nonlinear[256] = {
141         0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6,
142         7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12,
143         12, 13, 14, 14, 15, 15, 16, 16, 17, 17,
144         18, 18, 19, 20, 20, 21, 21, 22, 22, 23,
145         23, 24, 24, 25, 25, 26, 27, 27, 28, 28,
146         29, 29, 30, 30, 31, 31, 32, 33, 33, 34,
147         34, 35, 35, 36, 36, 37, 37, 38, 38, 39,
148         40, 40, 41, 41, 42, 42, 43, 43, 44, 44,
149         45, 46, 46, 47, 47, 48, 48, 49, 49, 50,
150         50, 51, 52, 52, 53, 53, 54, 54, 55, 55,
151         56, 56, 57, 57, 58, 59, 59, 60, 60, 61,
152         61, 62, 62, 63, 63, 64, 65, 65, 66, 66,
153         67, 67, 68, 68, 69, 69, 70, 70, 71, 72,
154         72, 73, 73, 74, 74, 75, 75, 76, 76, 77,
155         78, 78, 79, 79, 80, 80, 81, 81, 82, 82,
156         83, 83, 84, 85, 85, 86, 86, 87, 87, 88,
157         88, 89, 89, 90, 92, 94, 96, 97, 99, 101,
158         103, 105, 107, 109, 110, 112, 114, 116, 118,
159         120, 122, 123, 125, 127, 129, 131, 133, 134,
160         136, 138, 140, 142, 144, 146, 147, 149, 151,
161         153, 155, 157, 159, 160, 162, 164, 166, 168,
162         170, 172, 173, 175, 177, 179, 181, 183, 185,
163         186, 188, 190, 192, 194, 196, 198, 199, 201,
164         203, 205, 207, 209, 211, 212, 214, 216, 218,
165         220, 222, 223, 225, 227, 229, 231, 233, 235,
166         236, 238, 240, 242, 244, 246, 248, 249, 251,
167         253, 255
168 };
169
170 static struct tegra_dsi_cmd dsi_a_1200_1920_8_0_init_cmd[] = {
171     /* no init command required */
172 };
173
174
175 static struct tegra_dsi_out dsi_a_1200_1920_8_0_pdata = {
176         .controller_vs = DSI_VS_1,
177         .n_data_lanes = 4,
178         .video_burst_mode = TEGRA_DSI_VIDEO_NONE_BURST_MODE,
179
180         .pixel_format = TEGRA_DSI_PIXEL_FORMAT_24BIT_P,
181         .refresh_rate = 60,
182         .virtual_channel = TEGRA_DSI_VIRTUAL_CHANNEL_0,
183
184         .panel_reset = DSI_PANEL_RESET,
185         .power_saving_suspend = true,
186         .video_data_type = TEGRA_DSI_VIDEO_TYPE_VIDEO_MODE,
187         .video_clock_mode = TEGRA_DSI_VIDEO_CLOCK_TX_ONLY,
188         .dsi_init_cmd = dsi_a_1200_1920_8_0_init_cmd,
189         .n_init_cmd = ARRAY_SIZE(dsi_a_1200_1920_8_0_init_cmd),
190         .boardinfo = {BOARD_P1761, 0, 0, 1},
191         .ulpm_not_supported = true,
192 };
193
194 static int dsi_a_1200_1920_8_0_regulator_get(struct device *dev)
195 {
196         int err = 0;
197
198         if (reg_requested)
199                 return 0;
200
201         avdd_lcd_3v3 = regulator_get(dev, "avdd_lcd");
202         if (IS_ERR_OR_NULL(avdd_lcd_3v3)) {
203                 pr_err("avdd_lcd regulator get failed\n");
204                 err = PTR_ERR(avdd_lcd_3v3);
205                 avdd_lcd_3v3 = NULL;
206                 goto fail;
207         }
208
209         dvdd_lcd_1v8 = regulator_get(dev, "dvdd_lcd");
210         if (IS_ERR_OR_NULL(dvdd_lcd_1v8)) {
211                 pr_err("dvdd_lcd_1v8 regulator get failed\n");
212                 err = PTR_ERR(dvdd_lcd_1v8);
213                 dvdd_lcd_1v8 = NULL;
214                 goto fail;
215         }
216
217         vdd_lcd_bl_en = regulator_get(dev, "vdd_lcd_bl_en");
218         if (IS_ERR_OR_NULL(vdd_lcd_bl_en)) {
219                 pr_err("vdd_lcd_bl_en regulator get failed\n");
220                 err = PTR_ERR(vdd_lcd_bl_en);
221                 vdd_lcd_bl_en = NULL;
222                 goto fail;
223         }
224
225         reg_requested = true;
226         return 0;
227 fail:
228         return err;
229 }
230
231 static int dsi_a_1200_1920_8_0_gpio_get(void)
232 {
233         int err = 0;
234
235         if (gpio_requested)
236                 return 0;
237
238         err = gpio_request(dsi_a_1200_1920_8_0_pdata.dsi_panel_rst_gpio,
239                 "panel rst");
240         if (err < 0) {
241                 pr_err("panel reset gpio request failed\n");
242                 goto fail;
243         }
244
245         /* free pwm GPIO */
246         err = gpio_request(dsi_a_1200_1920_8_0_pdata.dsi_panel_bl_pwm_gpio,
247                 "panel pwm");
248         if (err < 0) {
249                 pr_err("panel pwm gpio request failed\n");
250                 goto fail;
251         }
252
253         gpio_free(dsi_a_1200_1920_8_0_pdata.dsi_panel_bl_pwm_gpio);
254         gpio_requested = true;
255         return 0;
256 fail:
257         return err;
258 }
259
260 static int dsi_a_1200_1920_8_0_enable(struct device *dev)
261 {
262         int err = 0;
263         struct tegra_dc_out *disp_out =
264                         ((struct tegra_dc_platform_data *)
265                         (disp_device->dev.platform_data))->default_out;
266
267         err = dsi_a_1200_1920_8_0_regulator_get(dev);
268         if (err < 0) {
269                 pr_err("dsi regulator get failed\n");
270                 goto fail;
271         }
272
273         err = dsi_a_1200_1920_8_0_gpio_get();
274         if (err < 0) {
275                 pr_err("dsi gpio request failed\n");
276                 goto fail;
277         }
278
279         if (avdd_lcd_3v3) {
280                 err = regulator_enable(avdd_lcd_3v3);
281                 if (err < 0) {
282                         pr_err("avdd_lcd regulator enable failed\n");
283                         goto fail;
284                 }
285         }
286
287         if (dvdd_lcd_1v8) {
288                 err = regulator_enable(dvdd_lcd_1v8);
289                 if (err < 0) {
290                         pr_err("dvdd_lcd regulator enable failed\n");
291                         goto fail;
292                 }
293         }
294
295         if (vdd_lcd_bl_en) {
296                 err = regulator_enable(vdd_lcd_bl_en);
297                 if (err < 0) {
298                         pr_err("vdd_lcd_bl_en regulator enable failed\n");
299                         goto fail;
300                 }
301         }
302
303         msleep(100);
304 #if DSI_PANEL_RESET
305         if (!(disp_out->flags & TEGRA_DC_OUT_INITIALIZED_MODE)) {
306                 gpio_direction_output(
307                         dsi_a_1200_1920_8_0_pdata.dsi_panel_rst_gpio, 1);
308                 usleep_range(1000, 5000);
309                 gpio_set_value(
310                         dsi_a_1200_1920_8_0_pdata.dsi_panel_rst_gpio, 0);
311                 msleep(150);
312                 gpio_set_value(
313                         dsi_a_1200_1920_8_0_pdata.dsi_panel_rst_gpio, 1);
314                 msleep(20);
315         }
316 #endif
317         dc_dev = dev;
318         return 0;
319 fail:
320         return err;
321 }
322
323 static int dsi_a_1200_1920_8_0_disable(void)
324 {
325         if (gpio_is_valid(dsi_a_1200_1920_8_0_pdata.dsi_panel_rst_gpio)) {
326                 /* Wait for 50ms before triggering panel reset */
327                 msleep(50);
328                 gpio_set_value(dsi_a_1200_1920_8_0_pdata.dsi_panel_rst_gpio, 0);
329         }
330
331         msleep(120);
332
333         if (vdd_lcd_bl_en)
334                 regulator_disable(vdd_lcd_bl_en);
335
336         if (avdd_lcd_3v3)
337                 regulator_disable(avdd_lcd_3v3);
338
339         if (dvdd_lcd_1v8)
340                 regulator_disable(dvdd_lcd_1v8);
341
342         dc_dev = NULL;
343         return 0;
344 }
345
346 static int dsi_a_1200_1920_8_0_postsuspend(void)
347 {
348         return 0;
349 }
350
351 static struct tegra_dc_mode dsi_a_1200_1920_8_0_modes[] = {
352         {
353                 .pclk = 155774400,
354                 .h_ref_to_sync = 4,
355                 .v_ref_to_sync = 1,
356                 .h_sync_width = 10,
357                 .v_sync_width = 2,
358                 .h_back_porch = 54,
359                 .v_back_porch = 30,
360                 .h_active = 1200,
361                 .v_active = 1920,
362                 .h_front_porch = 64,
363                 .v_front_porch = 3,
364         },
365 };
366
367 #ifdef CONFIG_TEGRA_DC_CMU
368 static struct tegra_dc_cmu dsi_a_1200_1920_8_0_cmu = {
369         /* lut1 maps sRGB to linear space. */
370         {
371                 0,  1,  2,  4,  5,  6,  7,  9,
372                 10,  11,  12,  14,  15,  16,  18,  19,
373                 21,  23,  25,  27,  29,  31,  33,  35,
374                 37,  40,  42,  45,  47,  50,  53,  56,
375                 59,  62,  65,  69,  72,  75,  79,  83,
376                 87,  90,  94,  99,  103,  107,  111,  116,
377                 121,  125,  130,  135,  140,  145,  151,  156,
378                 161,  167,  173,  178,  184,  190,  197,  203,
379                 209,  216,  222,  229,  236,  243,  250,  257,
380                 264,  272,  279,  287,  295,  303,  311,  319,
381                 327,  336,  344,  353,  362,  371,  380,  389,
382                 398,  408,  417,  427,  437,  447,  457,  467,
383                 477,  488,  498,  509,  520,  531,  542,  553,
384                 565,  576,  588,  600,  612,  624,  636,  649,
385                 661,  674,  687,  699,  713,  726,  739,  753,
386                 766,  780,  794,  808,  822,  837,  851,  866,
387                 881,  896,  911,  926,  941,  957,  973,  989,
388                 1005,  1021,  1037,  1053,  1070,  1087,  1104,  1121,
389                 1138,  1155,  1173,  1190,  1208,  1226,  1244,  1263,
390                 1281,  1300,  1318,  1337,  1356,  1376,  1395,  1415,
391                 1434,  1454,  1474,  1494,  1515,  1535,  1556,  1577,
392                 1598,  1619,  1640,  1662,  1683,  1705,  1727,  1749,
393                 1771,  1794,  1816,  1839,  1862,  1885,  1909,  1932,
394                 1956,  1979,  2003,  2027,  2052,  2076,  2101,  2126,
395                 2151,  2176,  2201,  2227,  2252,  2278,  2304,  2330,
396                 2357,  2383,  2410,  2437,  2464,  2491,  2518,  2546,
397                 2573,  2601,  2629,  2658,  2686,  2715,  2744,  2773,
398                 2802,  2831,  2860,  2890,  2920,  2950,  2980,  3011,
399                 3041,  3072,  3103,  3134,  3165,  3197,  3228,  3260,
400                 3292,  3325,  3357,  3390,  3422,  3455,  3488,  3522,
401                 3555,  3589,  3623,  3657,  3691,  3725,  3760,  3795,
402                 3830,  3865,  3900,  3936,  3972,  4008,  4044,  4080,
403         },
404         /* csc */
405         {
406                 0x0FD, 0x3F1, 0x010,
407                 0x3F5, 0x104, 0x3E4,
408                 0x3FC, 0x004, 0x0E4,
409         },
410         /* lut2 maps linear space to sRGB */
411         {
412                 0,  2,  3,  5,  6,  8,  9,  11,
413                 12,  14,  15,  16,  17,  17,  17,  18,
414                 18,  19,  19,  20,  20,  20,  21,  21,
415                 22,  22,  22,  23,  23,  24,  24,  25,
416                 25,  25,  26,  26,  27,  27,  28,  28,
417                 28,  29,  29,  30,  30,  30,  31,  31,
418                 32,  32,  32,  33,  33,  33,  33,  33,
419                 34,  34,  34,  34,  35,  35,  35,  35,
420                 35,  36,  36,  36,  36,  37,  37,  37,
421                 37,  37,  38,  38,  38,  38,  39,  39,
422                 39,  39,  39,  40,  40,  40,  40,  41,
423                 41,  41,  41,  41,  42,  42,  42,  42,
424                 43,  43,  43,  43,  44,  44,  44,  44,
425                 44,  45,  45,  45,  45,  46,  46,  46,
426                 46,  46,  47,  47,  47,  47,  48,  48,
427                 48,  48,  48,  48,  49,  49,  49,  49,
428                 49,  49,  50,  50,  50,  50,  50,  50,
429                 50,  51,  51,  51,  51,  51,  51,  51,
430                 52,  52,  52,  52,  52,  52,  53,  53,
431                 53,  53,  53,  53,  53,  54,  54,  54,
432                 54,  54,  54,  55,  55,  55,  55,  55,
433                 55,  55,  56,  56,  56,  56,  56,  56,
434                 57,  57,  57,  57,  57,  57,  57,  58,
435                 58,  58,  58,  58,  58,  59,  59,  59,
436                 59,  59,  59,  59,  60,  60,  60,  60,
437                 60,  60,  60,  61,  61,  61,  61,  61,
438                 61,  62,  62,  62,  62,  62,  62,  62,
439                 63,  63,  63,  63,  63,  63,  64,  64,
440                 64,  64,  64,  64,  64,  64,  65,  65,
441                 65,  65,  65,  65,  65,  65,  66,  66,
442                 66,  66,  66,  66,  66,  66,  67,  67,
443                 67,  67,  67,  67,  67,  67,  67,  68,
444                 68,  68,  68,  68,  68,  68,  68,  69,
445                 69,  69,  69,  69,  69,  69,  69,  70,
446                 70,  70,  70,  70,  70,  70,  70,  70,
447                 71,  71,  71,  71,  71,  71,  71,  71,
448                 72,  72,  72,  72,  72,  72,  72,  72,
449                 73,  73,  73,  73,  73,  73,  73,  73,
450                 73,  74,  74,  74,  74,  74,  74,  74,
451                 74,  75,  75,  75,  75,  75,  75,  75,
452                 75,  76,  76,  76,  76,  76,  76,  76,
453                 76,  76,  77,  77,  77,  77,  77,  77,
454                 77,  77,  78,  78,  78,  78,  78,  78,
455                 78,  78,  79,  79,  79,  79,  79,  79,
456                 79,  79,  80,  80,  80,  80,  80,  80,
457                 80,  80,  80,  80,  81,  81,  81,  81,
458                 81,  81,  81,  81,  81,  81,  81,  81,
459                 82,  82,  82,  82,  82,  82,  82,  82,
460                 82,  82,  82,  83,  83,  83,  83,  83,
461                 83,  83,  83,  83,  83,  83,  84,  84,
462                 84,  84,  84,  84,  84,  84,  84,  84,
463                 84,  84,  85,  85,  85,  85,  85,  85,
464                 85,  85,  85,  85,  85,  86,  86,  86,
465                 86,  86,  86,  86,  86,  86,  86,  86,
466                 87,  87,  87,  87,  87,  87,  87,  87,
467                 87,  87,  87,  87,  88,  88,  88,  88,
468                 88,  88,  88,  88,  88,  88,  88,  89,
469                 89,  89,  89,  89,  89,  89,  89,  89,
470                 89,  89,  89,  90,  90,  90,  90,  90,
471                 90,  90,  90,  90,  90,  90,  91,  91,
472                 91,  91,  91,  91,  91,  91,  91,  91,
473                 91,  92,  92,  92,  92,  92,  92,  92,
474                 92,  92,  92,  92,  92,  93,  93,  93,
475                 93,  93,  93,  93,  93,  93,  93,  93,
476                 94,  95,  95,  96,  97,  97,  98,  99,
477                 99,  100,  100,  101,  102,  102,  103,  104,
478                 104,  105,  105,  106,  107,  107,  108,  109,
479                 109,  110,  111,  111,  112,  112,  113,  113,
480                 114,  115,  115,  116,  116,  117,  117,  118,
481                 118,  119,  119,  120,  120,  121,  122,  122,
482                 123,  123,  124,  124,  125,  125,  126,  126,
483                 127,  127,  128,  128,  129,  129,  130,  130,
484                 131,  131,  132,  132,  132,  133,  133,  134,
485                 134,  135,  135,  136,  136,  136,  137,  137,
486                 138,  138,  139,  139,  140,  140,  140,  141,
487                 141,  142,  142,  143,  143,  144,  144,  144,
488                 145,  145,  146,  146,  147,  147,  148,  148,
489                 148,  149,  149,  150,  150,  151,  151,  151,
490                 152,  152,  153,  153,  154,  154,  155,  155,
491                 155,  156,  156,  157,  157,  158,  158,  158,
492                 159,  159,  160,  160,  161,  161,  161,  162,
493                 162,  162,  163,  163,  163,  164,  164,  164,
494                 165,  165,  165,  166,  166,  166,  167,  167,
495                 168,  168,  168,  169,  169,  169,  170,  170,
496                 170,  171,  171,  171,  172,  172,  172,  173,
497                 173,  173,  174,  174,  175,  175,  175,  176,
498                 176,  176,  177,  177,  177,  178,  178,  178,
499                 179,  179,  180,  180,  180,  181,  181,  181,
500                 182,  182,  182,  183,  183,  184,  184,  184,
501                 185,  185,  185,  186,  186,  186,  187,  187,
502                 188,  188,  188,  189,  189,  189,  190,  190,
503                 191,  191,  191,  192,  192,  192,  193,  193,
504                 193,  194,  194,  194,  194,  195,  195,  195,
505                 196,  196,  196,  197,  197,  197,  198,  198,
506                 198,  199,  199,  199,  199,  200,  200,  200,
507                 201,  201,  201,  202,  202,  202,  203,  203,
508                 203,  204,  204,  204,  204,  205,  205,  205,
509                 206,  206,  206,  207,  207,  207,  208,  208,
510                 208,  208,  209,  209,  209,  210,  210,  210,
511                 210,  211,  211,  211,  212,  212,  212,  212,
512                 213,  213,  213,  213,  214,  214,  214,  215,
513                 215,  215,  215,  216,  216,  216,  216,  217,
514                 217,  217,  218,  218,  218,  218,  219,  219,
515                 219,  220,  220,  220,  220,  221,  221,  221,
516                 221,  222,  222,  222,  223,  223,  223,  223,
517                 224,  224,  224,  224,  225,  225,  225,  226,
518                 226,  226,  226,  227,  227,  227,  227,  228,
519                 228,  228,  228,  229,  229,  229,  229,  230,
520                 230,  230,  231,  231,  231,  231,  232,  232,
521                 232,  232,  233,  233,  233,  233,  234,  234,
522                 234,  234,  235,  235,  235,  236,  236,  236,
523                 236,  237,  237,  237,  237,  238,  238,  238,
524                 238,  239,  239,  239,  239,  240,  240,  240,
525                 241,  241,  241,  241,  242,  242,  242,  242,
526                 243,  243,  243,  243,  244,  244,  244,  245,
527                 245,  245,  245,  246,  246,  246,  246,  247,
528                 247,  247,  248,  248,  248,  248,  249,  249,
529                 249,  249,  250,  250,  250,  251,  251,  251,
530                 251,  252,  252,  252,  252,  253,  253,  253,
531                 253,  254,  254,  254,  255,  255,  255,  255,
532         },
533 };
534 #endif
535
536 static int dsi_a_1200_1920_8_0_bl_notify(struct device *unused, int brightness)
537 {
538         int cur_sd_brightness;
539
540         /* apply the non-linear curve adjustment */
541         brightness = dsi_a_1200_1920_8_0_bl_nonlinear[brightness];
542         if (dc_dev) {
543                 if (brightness <= PRISM_THRESHOLD)
544                         nvsd_enbl_dsbl_prism(dc_dev, false);
545                 else if (brightness > PRISM_THRESHOLD + HYST_VAL)
546                         nvsd_enbl_dsbl_prism(dc_dev, true);
547         }
548         cur_sd_brightness = atomic_read(&sd_brightness);
549         /* SD brightness is a percentage */
550         brightness = (brightness * cur_sd_brightness) / 255;
551
552         /* Apply any backlight response curve */
553         if (brightness > 255)
554                 pr_info("Error: Brightness > 255!\n");
555         else
556                 brightness = dsi_a_1200_1920_8_0_bl_output_measured[brightness];
557
558         return brightness;
559 }
560
561 static int dsi_a_1200_1920_8_0_check_fb(struct device *dev,
562         struct fb_info *info)
563 {
564         return info->device == &disp_device->dev;
565 }
566
567 static struct platform_pwm_backlight_data dsi_a_1200_1920_8_0_bl_data = {
568         .pwm_id         = 1,
569         .max_brightness = 255,
570         .dft_brightness = 191,
571         .pwm_period_ns  = 40161,
572         .pwm_gpio       = TEGRA_GPIO_INVALID,
573         .notify         = dsi_a_1200_1920_8_0_bl_notify,
574         /* Only toggle backlight on fb blank notifications for disp1 */
575         .check_fb       = dsi_a_1200_1920_8_0_check_fb,
576 };
577
578 static struct platform_device __maybe_unused
579                 dsi_a_1200_1920_8_0_bl_device = {
580         .name   = "pwm-backlight",
581         .id     = -1,
582         .dev    = {
583                 .platform_data = &dsi_a_1200_1920_8_0_bl_data,
584         },
585 };
586
587 static struct platform_device __maybe_unused
588                         *dsi_a_1200_1920_8_0_bl_devices[] __initdata = {
589         &dsi_a_1200_1920_8_0_bl_device,
590 };
591
592 static int  __init dsi_a_1200_1920_8_0_register_bl_dev(void)
593 {
594         int err = 0;
595
596         if (tegra_get_touch_vendor_id() == MAXIM_TOUCH) {
597                 struct platform_pwm_backlight_data *pfm_dat;
598                 pfm_dat = dsi_a_1200_1920_8_0_bl_devices[0]->dev.platform_data;
599                 /* override backlight pwm frequency to 1KHz */
600                 pfm_dat->pwm_period_ns = 1000000;
601         }
602         err = platform_add_devices(dsi_a_1200_1920_8_0_bl_devices,
603                                 ARRAY_SIZE(dsi_a_1200_1920_8_0_bl_devices));
604         if (err) {
605                 pr_err("disp1 bl device registration failed");
606                 return err;
607         }
608         return err;
609 }
610
611 static void dsi_a_1200_1920_8_0_set_disp_device(
612         struct platform_device *display_device)
613 {
614         disp_device = display_device;
615 }
616
617 static void dsi_a_1200_1920_8_0_dc_out_init(struct tegra_dc_out *dc)
618 {
619         dc->dsi = &dsi_a_1200_1920_8_0_pdata;
620         dc->parent_clk = "pll_d_out0";
621         dc->modes = dsi_a_1200_1920_8_0_modes;
622         dc->n_modes = ARRAY_SIZE(dsi_a_1200_1920_8_0_modes);
623         dc->enable = dsi_a_1200_1920_8_0_enable;
624         dc->disable = dsi_a_1200_1920_8_0_disable;
625         dc->postsuspend = dsi_a_1200_1920_8_0_postsuspend,
626         dc->width = 107;
627         dc->height = 172;
628         dc->flags = DC_CTRL_MODE;
629 }
630
631 static void dsi_a_1200_1920_8_0_fb_data_init(struct tegra_fb_data *fb)
632 {
633         fb->xres = dsi_a_1200_1920_8_0_modes[0].h_active;
634         fb->yres = dsi_a_1200_1920_8_0_modes[0].v_active;
635 }
636
637 static void
638 dsi_a_1200_1920_8_0_sd_settings_init(struct tegra_dc_sd_settings *settings)
639 {
640         *settings = dsi_a_1200_1920_8_0_sd_settings;
641         settings->bl_device_name = "pwm-backlight";
642 }
643
644 static void dsi_a_1200_1920_8_0_cmu_init(struct tegra_dc_platform_data *pdata)
645 {
646         pdata->cmu = &dsi_a_1200_1920_8_0_cmu;
647 }
648
649 struct tegra_panel __initdata dsi_a_1200_1920_8_0 = {
650         .init_sd_settings = dsi_a_1200_1920_8_0_sd_settings_init,
651         .init_dc_out = dsi_a_1200_1920_8_0_dc_out_init,
652         .init_fb_data = dsi_a_1200_1920_8_0_fb_data_init,
653         .register_bl_dev = dsi_a_1200_1920_8_0_register_bl_dev,
654         .init_cmu_data = dsi_a_1200_1920_8_0_cmu_init,
655         .set_disp_device = dsi_a_1200_1920_8_0_set_disp_device,
656 };
657 EXPORT_SYMBOL(dsi_a_1200_1920_8_0);
658