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