ARM: tegra12: set CPU rate to 2.2GHz for sku 0x87
[linux-3.10.git] / arch / arm / mach-tegra / panel-a-1080p-14-0.c
1 /*
2  * arch/arm/mach-tegra/panel-a-1080p-14-0.c
3  *
4  * Copyright (c) 2013, 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 "board.h"
29 #include "board-panel.h"
30 #include "board-ardbeg.h"
31 #include "devices.h"
32 #include "gpio-names.h"
33 #include "tegra11_host1x_devices.h"
34
35 #define TEGRA_DSI_GANGED_MODE   0
36 #define DC_CTRL_MODE    TEGRA_DC_OUT_CONTINUOUS_MODE
37 #define DSI_PANEL_RESET         1
38
39 static bool reg_requested;
40 static bool gpio_requested;
41 static struct platform_device *disp_device;
42 static struct regulator *avdd_lcd_3v3;
43 static struct regulator *vdd_1v2_en;
44 static struct regulator *vdd_lcd_bl_en;
45 static struct regulator *dvdd_lcd_1v8;
46 static struct regulator *vdd_ds_1v8;
47 static struct regulator *vdd_lcd_bl;
48
49 static struct tegra_dc_sd_settings dsi_a_1080p_14_0_sd_settings = {
50         .enable = 1, /* enabled by default. */
51         .use_auto_pwm = false,
52         .hw_update_delay = 0,
53         .bin_width = -1,
54         .aggressiveness = 5,
55         .use_vid_luma = false,
56         .phase_in_adjustments = 0,
57         .k_limit_enable = true,
58         .k_limit = 200,
59         .sd_window_enable = false,
60         .soft_clipping_enable = true,
61         /* Low soft clipping threshold to compensate for aggressive k_limit */
62         .soft_clipping_threshold = 128,
63         .smooth_k_enable = false,
64         .smooth_k_incr = 64,
65         /* Default video coefficients */
66         .coeff = {5, 9, 2},
67         .fc = {0, 0},
68         /* Immediate backlight changes */
69         .blp = {1024, 255},
70         /* Gammas: R: 2.2 G: 2.2 B: 2.2 */
71         /* Default BL TF */
72         .bltf = {
73                         {
74                                 {57, 65, 73, 82},
75                                 {92, 103, 114, 125},
76                                 {138, 150, 164, 178},
77                                 {193, 208, 224, 241},
78                         },
79                 },
80         /* Default LUT */
81         .lut = {
82                         {
83                                 {255, 255, 255},
84                                 {199, 199, 199},
85                                 {153, 153, 153},
86                                 {116, 116, 116},
87                                 {85, 85, 85},
88                                 {59, 59, 59},
89                                 {36, 36, 36},
90                                 {17, 17, 17},
91                                 {0, 0, 0},
92                         },
93                 },
94         .sd_brightness = &sd_brightness,
95         .use_vpulse2 = true,
96 };
97
98 static tegra_dc_bl_output dsi_a_1080p_14_0_bl_output_measured = {
99         0, 0, 1, 2, 3, 4, 5, 6,
100         7, 8, 9, 9, 10, 11, 12, 13,
101         13, 14, 15, 16, 17, 17, 18, 19,
102         20, 21, 22, 22, 23, 24, 25, 26,
103         27, 27, 28, 29, 30, 31, 32, 32,
104         33, 34, 35, 36, 37, 37, 38, 39,
105         40, 41, 42, 42, 43, 44, 45, 46,
106         47, 48, 48, 49, 50, 51, 52, 53,
107         54, 55, 56, 57, 57, 58, 59, 60,
108         61, 62, 63, 64, 65, 66, 67, 68,
109         69, 70, 71, 71, 72, 73, 74, 75,
110         76, 77, 77, 78, 79, 80, 81, 82,
111         83, 84, 85, 87, 88, 89, 90, 91,
112         92, 93, 94, 95, 96, 97, 98, 99,
113         100, 101, 102, 103, 104, 105, 106, 107,
114         108, 109, 110, 111, 112, 113, 115, 116,
115         117, 118, 119, 120, 121, 122, 123, 124,
116         125, 126, 127, 128, 129, 130, 131, 132,
117         133, 134, 135, 136, 137, 138, 139, 141,
118         142, 143, 144, 146, 147, 148, 149, 151,
119         152, 153, 154, 155, 156, 157, 158, 158,
120         159, 160, 161, 162, 163, 165, 166, 167,
121         168, 169, 170, 171, 172, 173, 174, 176,
122         177, 178, 179, 180, 182, 183, 184, 185,
123         186, 187, 188, 189, 190, 191, 192, 194,
124         195, 196, 197, 198, 199, 200, 201, 202,
125         203, 204, 205, 206, 207, 208, 209, 210,
126         211, 212, 213, 214, 215, 216, 217, 219,
127         220, 221, 222, 224, 225, 226, 227, 229,
128         230, 231, 232, 233, 234, 235, 236, 238,
129         239, 240, 241, 242, 243, 244, 245, 246,
130         247, 248, 249, 250, 251, 252, 253, 255
131 };
132
133 static struct tegra_dsi_cmd dsi_a_1080p_14_0_init_cmd[] = {
134         /* no init command required */
135 };
136
137 static struct tegra_dsi_out dsi_a_1080p_14_0_pdata = {
138         .controller_vs = DSI_VS_1,
139         .dsi2edp_bridge_enable = true,
140         .n_data_lanes = 4,
141         .video_burst_mode = TEGRA_DSI_VIDEO_NONE_BURST_MODE_WITH_SYNC_END,
142
143         .pixel_format = TEGRA_DSI_PIXEL_FORMAT_24BIT_P,
144         .refresh_rate = 61,
145         .virtual_channel = TEGRA_DSI_VIRTUAL_CHANNEL_0,
146
147         .dsi_instance = DSI_INSTANCE_0,
148
149         .panel_reset = DSI_PANEL_RESET,
150         .power_saving_suspend = true,
151         .video_data_type = TEGRA_DSI_VIDEO_TYPE_VIDEO_MODE,
152         .video_clock_mode = TEGRA_DSI_VIDEO_CLOCK_TX_ONLY,
153         .dsi_init_cmd = dsi_a_1080p_14_0_init_cmd,
154         .n_init_cmd = ARRAY_SIZE(dsi_a_1080p_14_0_init_cmd),
155         .phy_timing = {
156                 .t_hsdexit_ns = 123,
157                 .t_hstrail_ns = 85,
158                 .t_datzero_ns = 170,
159                 .t_hsprepare_ns = 57,
160         },
161         .chip_id = 0x162,
162         .chip_rev = 1,
163 };
164
165 static int laguna_dsi_regulator_get(struct device *dev)
166 {
167         int err = 0;
168
169         if (reg_requested)
170                 return 0;
171
172         dvdd_lcd_1v8 = regulator_get(dev, "dvdd_lcd");
173                 if (IS_ERR(dvdd_lcd_1v8)) {
174                         pr_err("dvdd_lcd regulator get failed\n");
175                         err = PTR_ERR(dvdd_lcd_1v8);
176                         dvdd_lcd_1v8 = NULL;
177                         goto fail;
178         }
179
180         vdd_ds_1v8 = regulator_get(dev, "vdd_ds_1v8");
181         if (IS_ERR(vdd_ds_1v8)) {
182                 pr_err("vdd_ds_1v8 regulator get failed\n");
183                 err = PTR_ERR(vdd_ds_1v8);
184                 vdd_ds_1v8 = NULL;
185                 goto fail;
186         }
187
188         avdd_lcd_3v3 = regulator_get(dev, "avdd_lcd");
189         if (IS_ERR(avdd_lcd_3v3)) {
190                 pr_err("avdd_lcd regulator get failed\n");
191                 err = PTR_ERR(avdd_lcd_3v3);
192                 avdd_lcd_3v3 = NULL;
193                 goto fail;
194         }
195
196         vdd_1v2_en = regulator_get(dev, "vdd_1v2_en");
197         if (IS_ERR(vdd_1v2_en)) {
198                 pr_err("vdd_1v2_en regulator get failed\n");
199                 err = PTR_ERR(vdd_1v2_en);
200                 vdd_1v2_en = NULL;
201                 goto fail;
202         }
203
204
205         vdd_lcd_bl_en = regulator_get(dev, "vdd_lcd_bl_en");
206         if (IS_ERR(vdd_lcd_bl_en)) {
207                 pr_err("vdd_lcd_bl_en regulator get failed\n");
208                 err = PTR_ERR(vdd_lcd_bl_en);
209                 vdd_lcd_bl_en = NULL;
210                 goto fail;
211         }
212
213         vdd_lcd_bl = regulator_get(dev, "vdd_lcd_bl");
214         if (IS_ERR(vdd_lcd_bl)) {
215                 pr_err("vdd_lcd_bl regulator get failed\n");
216                 err = PTR_ERR(vdd_lcd_bl);
217                 vdd_lcd_bl = NULL;
218                 goto fail;
219         }
220
221         reg_requested = true;
222         return 0;
223 fail:
224         return err;
225 }
226
227 static int laguna_dsi_gpio_get(void)
228 {
229         int err = 0;
230
231         if (gpio_requested)
232                 return 0;
233
234         err = gpio_request(DSI_PANEL_RST_GPIO, "panel rst");
235         if (err < 0) {
236                 pr_err("panel reset gpio request failed\n");
237                 goto fail;
238         }
239         err = gpio_request(LCD_LR, "lcd_lr");
240         if (err < 0) {
241                 pr_err("panel reset gpio request failed\n");
242                 goto fail;
243         }
244
245         err = gpio_request(LCD_RST_L, "lcd_rst_l");
246         if (err < 0) {
247                 pr_err("panel reset gpio request failed\n");
248                 goto fail;
249         }
250
251         err = gpio_request(LCD_TE, "lcd_te");
252         if (err < 0) {
253                 pr_err("panel lcd te request failed\n");
254                 goto fail;
255         }
256
257         err = gpio_request(DSI_PANEL_BL_PWM_GPIO, "panel pwm");
258         if (err < 0) {
259                 pr_err("panel pwm gpio request failed\n");
260                 goto fail;
261         }
262
263         /* Free pwm GPIO */
264         gpio_free(DSI_PANEL_BL_PWM_GPIO);
265
266         err = gpio_request(lvds_en, "edp bridge 1v8 enable");
267         if (err < 0) {
268                 pr_err("edp bridge 1v8 enable gpio request failed\n");
269                 goto fail;
270         }
271
272         err = gpio_request(refclk_en, "edp bridge refclk enable");
273         if (err < 0) {
274                 pr_err("edp bridge refclk enable gpio request failed\n");
275                 goto fail;
276         }
277
278         gpio_requested = true;
279         return 0;
280 fail:
281         return err;
282 }
283
284 static int dsi_a_1080p_14_0_enable(struct device *dev)
285 {
286         int err = 0;
287         err = laguna_dsi_regulator_get(dev);
288         if (err < 0) {
289                 pr_err("dsi regulator get failed\n");
290                 goto fail;
291         }
292         err = laguna_dsi_gpio_get();
293         if (err < 0) {
294                 pr_err("dsi gpio request failed\n");
295                 goto fail;
296         }
297
298         if (dvdd_lcd_1v8) {
299                 err = regulator_enable(dvdd_lcd_1v8);
300                 if (err < 0) {
301                         pr_err("dvdd_lcd regulator enable failed\n");
302                         goto fail;
303                 }
304         }
305         if (avdd_lcd_3v3) {
306                 err = regulator_enable(avdd_lcd_3v3);
307                 if (err < 0) {
308                         pr_err("avdd_lcd regulator enable failed\n");
309                         goto fail;
310                 }
311         }
312
313         /* enable 1.8v */
314         if (vdd_ds_1v8) {
315                 err = regulator_enable(vdd_ds_1v8);
316                 if (err < 0) {
317                         pr_err("vdd_ds_1v8 regulator enable failed\n");
318                         goto fail;
319                 }
320         }
321
322         if (vdd_1v2_en) {
323                 err = regulator_enable(vdd_1v2_en);
324                 if (err < 0) {
325                         pr_err("vdd_1v2_en regulator enable failed\n");
326                         goto fail;
327                 }
328         }
329
330         if (vdd_lcd_bl_en) {
331                 err = regulator_enable(vdd_lcd_bl_en);
332                 if (err < 0) {
333                         pr_err("vdd_lcd_bl_en regulator enable failed\n");
334                         goto fail;
335                 }
336         }
337
338         if (vdd_lcd_bl) {
339                 err = regulator_enable(vdd_lcd_bl);
340                 if (err < 0) {
341                         pr_err("vdd_lcd_bl regulator enable failed\n");
342                         goto fail;
343                 }
344         }
345         gpio_direction_output(DSI_PANEL_RST_GPIO, 0);
346         usleep_range(10000, 12000);
347         gpio_direction_output(lvds_en, 1);
348         usleep_range(8000, 10000);
349         gpio_direction_output(refclk_en, 1);
350         usleep_range(5000, 8000);
351         gpio_direction_output(DSI_PANEL_RST_GPIO, 1);
352         return 0;
353 fail:
354         return err;
355
356 }
357
358 static int dsi_a_1080p_14_0_disable(void)
359 {
360         gpio_set_value(lvds_en, 0);
361         gpio_set_value(refclk_en, 0);
362
363         if (vdd_lcd_bl)
364                 regulator_disable(vdd_lcd_bl);
365
366         if (vdd_1v2_en)
367                 regulator_disable(vdd_1v2_en);
368
369         if (vdd_lcd_bl_en)
370                 regulator_disable(vdd_lcd_bl_en);
371
372         if (avdd_lcd_3v3)
373                 regulator_disable(avdd_lcd_3v3);
374
375         if (dvdd_lcd_1v8)
376                 regulator_disable(dvdd_lcd_1v8);
377
378         if (vdd_ds_1v8)
379                 regulator_disable(vdd_ds_1v8);
380         return 0;
381 }
382
383 static int dsi_a_1080p_14_0_postsuspend(void)
384 {
385         return 0;
386 }
387
388 static struct tegra_dc_mode dsi_a_1080p_14_0_modes[] = {
389         {
390                 .pclk = 137986200,
391                 .h_ref_to_sync = 11,
392                 .v_ref_to_sync = 1,
393                 .h_sync_width = 16,
394                 .v_sync_width = 14,
395                 .h_back_porch = 152,
396                 .v_back_porch = 19,
397                 .h_active = 1920,
398                 .v_active = 1080,
399                 .h_front_porch = 16,
400                 .v_front_porch = 3,
401         },
402 };
403
404 static int dsi_a_1080p_14_0_bl_notify(struct device *unused, int brightness)
405 {
406         atomic_t __maybe_unused sd_brightness = ATOMIC_INIT(255);
407         int cur_sd_brightness = atomic_read(&sd_brightness);
408
409         /* Apply any backlight response curve */
410         if (brightness > 255)
411                 pr_info("Error: Brightness > 255!\n");
412         else
413                 brightness = dsi_a_1080p_14_0_bl_output_measured[brightness];
414
415         /* SD brightness is a percentage */
416         brightness = (brightness * cur_sd_brightness) / 255;
417
418         return brightness;
419 }
420
421 static int dsi_a_1080p_14_0_check_fb(struct device *dev, struct fb_info *info)
422 {
423         return info->device == &disp_device->dev;
424 }
425
426 static struct platform_pwm_backlight_data dsi_a_1080p_14_0_bl_data = {
427         .pwm_id         = 1,
428         .max_brightness = 255,
429         .dft_brightness = 224,
430         .pwm_period_ns  = 1000000,
431         .pwm_gpio       = TEGRA_GPIO_INVALID,
432         .notify         = dsi_a_1080p_14_0_bl_notify,
433         /* Only toggle backlight on fb blank notifications for disp1 */
434         .check_fb       = dsi_a_1080p_14_0_check_fb,
435 };
436
437 static struct platform_device __maybe_unused
438                 dsi_a_1080p_14_0_bl_device = {
439         .name   = "pwm-backlight",
440         .id     = -1,
441         .dev    = {
442                 .platform_data = &dsi_a_1080p_14_0_bl_data,
443         },
444 };
445
446 static struct platform_device __maybe_unused
447                         *dsi_a_1080p_14_0_bl_devices[] __initdata = {
448         &tegra_pwfm_device,
449         &dsi_a_1080p_14_0_bl_device,
450 };
451
452 static int  __init dsi_a_1080p_14_0_register_bl_dev(void)
453 {
454         int err = 0;
455         err = platform_add_devices(dsi_a_1080p_14_0_bl_devices,
456                                 ARRAY_SIZE(dsi_a_1080p_14_0_bl_devices));
457         if (err) {
458                 pr_err("disp1 bl device registration failed");
459                 return err;
460         }
461         return err;
462 }
463
464 static void dsi_a_1080p_14_0_set_disp_device(
465         struct platform_device *laguna_display_device)
466 {
467         disp_device = laguna_display_device;
468 }
469
470 static void dsi_a_1080p_14_0_dc_out_init(struct tegra_dc_out *dc)
471 {
472         dc->dsi = &dsi_a_1080p_14_0_pdata;
473         dc->parent_clk = "pll_d_out0";
474         dc->modes = dsi_a_1080p_14_0_modes;
475         dc->n_modes = ARRAY_SIZE(dsi_a_1080p_14_0_modes);
476         dc->enable = dsi_a_1080p_14_0_enable;
477         dc->disable = dsi_a_1080p_14_0_disable;
478         dc->postsuspend = dsi_a_1080p_14_0_postsuspend,
479         dc->width = 256;
480         dc->height = 144;
481         dc->flags = DC_CTRL_MODE;
482 }
483
484 static void dsi_a_1080p_14_0_fb_data_init(struct tegra_fb_data *fb)
485 {
486         fb->xres = dsi_a_1080p_14_0_modes[0].h_active;
487         fb->yres = dsi_a_1080p_14_0_modes[0].v_active;
488 }
489
490 static void
491 dsi_a_1080p_14_0_sd_settings_init(struct tegra_dc_sd_settings *settings)
492 {
493         *settings = dsi_a_1080p_14_0_sd_settings;
494         settings->bl_device_name = "pwm-backlight";
495 }
496
497 static struct i2c_board_info laguna_sn65dsi86_dsi2edp_board_info __initdata = {
498                 I2C_BOARD_INFO("sn65dsi86_dsi2edp", 0x2d),
499 };
500
501 static int __init dsi_a_1080p_14_0_i2c_bridge_register(void)
502 {
503         int err = 0;
504         pr_info("dsi_a_1080p_14_0_i2c_bridge_register\n");
505         err = i2c_register_board_info(0,
506                         &laguna_sn65dsi86_dsi2edp_board_info, 1);
507         return err;
508 }
509 struct tegra_panel __initdata dsi_a_1080p_14_0 = {
510         .init_sd_settings = dsi_a_1080p_14_0_sd_settings_init,
511         .init_dc_out = dsi_a_1080p_14_0_dc_out_init,
512         .init_fb_data = dsi_a_1080p_14_0_fb_data_init,
513         .register_bl_dev = dsi_a_1080p_14_0_register_bl_dev,
514         .register_i2c_bridge = dsi_a_1080p_14_0_i2c_bridge_register,
515         .set_disp_device = dsi_a_1080p_14_0_set_disp_device,
516 };
517 EXPORT_SYMBOL(dsi_a_1080p_14_0);
518