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