ARM: tegra12: set CPU rate to 2.2GHz for sku 0x87
[linux-3.10.git] / arch / arm / mach-tegra / panel-j-720p-4-7.c
1 /*
2  * arch/arm/mach-tegra/panel-j-720p-4-7.c
3  *
4  * Copyright (c) 2012-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 <linux/export.h>
29
30 #include "gpio-names.h"
31 #include "board-panel.h"
32 #include "devices.h"
33
34 #define DSI_PANEL_RESET         0
35
36 #define DC_CTRL_MODE            (TEGRA_DC_OUT_ONE_SHOT_MODE | \
37                          TEGRA_DC_OUT_ONE_SHOT_LP_MODE)
38
39 static struct regulator *vdd_lcd_s_1v8;
40 static struct regulator *vdd_sys_bl_3v7;
41 static struct regulator *avdd_lcd_3v0_2v8;
42
43
44 static bool dsi_j_720p_4_7_reg_requested;
45 static bool dsi_j_720p_4_7_gpio_requested;
46 static bool is_bl_powered;
47 static struct platform_device *disp_device;
48
49 static struct tegra_dc_sd_settings dsi_j_720p_4_7_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 = 180,
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 = true,
64         .smooth_k_incr = 4,
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_j_720p_4_7_bl_response_curve = {
99         0, 1, 2, 3, 4, 5, 6, 7,
100         8, 9, 10, 11, 12, 13, 14, 15,
101         16, 18, 19, 20, 21, 22, 23, 25,
102         26, 27, 28, 30, 31, 32, 33, 35,
103         36, 38, 39, 41, 42, 43, 45, 46,
104         48, 49, 51, 52, 54, 55, 57, 58,
105         60, 61, 63, 64, 66, 67, 68, 70,
106         71, 72, 74, 75, 77, 78, 79, 80,
107         81, 82, 83, 85, 86, 87, 88, 89,
108         90, 90, 91, 92, 93, 93, 94, 95,
109         96, 96, 96, 97, 97, 97, 97, 98,
110         98, 98, 98, 99, 100, 101, 101, 102,
111         103, 104, 104, 105, 106, 107, 108, 109,
112         110, 112, 113, 114, 115, 116, 117, 119,
113         120, 121, 122, 123, 125, 126, 127, 128,
114         129, 131, 132, 133, 134, 135, 136, 137,
115         138, 140, 141, 142, 142, 143, 144, 145,
116         146, 147, 148, 149, 149, 150, 151, 152,
117         153, 154, 154, 155, 156, 157, 158, 159,
118         160, 162, 163, 164, 165, 167, 168, 169,
119         170, 171, 172, 173, 173, 174, 175, 176,
120         176, 177, 178, 179, 179, 180, 181, 182,
121         182, 183, 184, 184, 185, 186, 186, 187,
122         188, 188, 189, 189, 190, 190, 191, 192,
123         193, 194, 195, 195, 196, 197, 198, 199,
124         200, 201, 202, 203, 203, 204, 205, 206,
125         207, 208, 209, 210, 211, 212, 213, 213,
126         214, 215, 216, 217, 218, 219, 220, 221,
127         222, 224, 225, 226, 227, 228, 229, 230,
128         231, 232, 233, 234, 235, 236, 237, 238,
129         239, 240, 241, 242, 243, 244, 246, 247,
130         248, 249, 250, 251, 252, 253, 254, 255
131 };
132
133 static int __maybe_unused dsi_j_720p_4_7_bl_notify(struct device *unused,
134                                                         int brightness)
135 {
136         int cur_sd_brightness = atomic_read(&sd_brightness);
137
138         /* SD brightness is a percentage */
139         brightness = (brightness * cur_sd_brightness) / 255;
140
141         /* Apply any backlight response curve */
142         if (brightness > 255)
143                 pr_info("Error: Brightness > 255!\n");
144         else
145                 brightness = dsi_j_720p_4_7_bl_response_curve[brightness];
146
147         return brightness;
148 }
149
150 static int __maybe_unused dsi_j_720p_4_7_check_fb(struct device *dev,
151                                              struct fb_info *info)
152 {
153         return info->device == &disp_device->dev;
154 }
155
156 /*
157         JDI uses Platform blacklight device
158 */
159
160 static struct platform_pwm_backlight_data dsi_j_720p_4_7_bl_data = {
161 #ifdef CONFIG_ARCH_TEGRA_11x_SOC
162         .pwm_id         = 1,
163 #else
164         .pwm_id         = 0,
165 #endif
166         .max_brightness = 255,
167         .dft_brightness = 77,
168         .pwm_period_ns  = 40000,
169         .pwm_gpio       = TEGRA_GPIO_INVALID,
170         .notify         = dsi_j_720p_4_7_bl_notify,
171         .check_fb       = dsi_j_720p_4_7_check_fb,
172 };
173
174 static struct platform_device dsi_j_720p_4_7_bl_device = {
175         .name   = "pwm-backlight",
176         .id     = -1,
177         .dev    = {
178                 .platform_data = &dsi_j_720p_4_7_bl_data,
179         },
180 };
181
182 static struct tegra_dsi_out dsi_j_720p_4_7_pdata;
183
184 static int dsi_j_720p_4_7_register_bl_dev(void)
185 {
186         int err = 0;
187         err = platform_device_register(&tegra_pwfm_device);
188         if (err) {
189                 pr_err("disp1 pwm device registration failed");
190                 return err;
191         }
192
193         err = platform_device_register(&dsi_j_720p_4_7_bl_device);
194         if (err) {
195                 pr_err("disp1 bl device registration failed");
196                 return err;
197         }
198
199         err = gpio_request(dsi_j_720p_4_7_pdata.dsi_panel_bl_pwm_gpio,
200                 "panel pwm");
201         if (err < 0) {
202                 pr_err("panel backlight pwm gpio request failed\n");
203                 return err;
204         }
205         gpio_free(dsi_j_720p_4_7_pdata.dsi_panel_bl_pwm_gpio);
206         return err;
207 }
208 struct tegra_dc_mode dsi_j_720p_4_7_modes[] = {
209         {
210                 .pclk = 62625000,
211                 .h_ref_to_sync = 2,
212                 .v_ref_to_sync = 1,
213                 .h_sync_width = 2,
214                 .v_sync_width = 2,
215                 .h_back_porch = 84,
216                 .v_back_porch = 2,
217                 .h_active = 720,
218                 .v_active = 1280,
219                 .h_front_porch = 4,
220                 .v_front_porch = 4,
221         },
222 };
223 static int dsi_j_720p_4_7_reg_get(void)
224 {
225         int err = 0;
226
227         if (dsi_j_720p_4_7_reg_requested)
228                 return 0;
229
230         avdd_lcd_3v0_2v8 = regulator_get(NULL, "avdd_lcd");
231         if (IS_ERR(avdd_lcd_3v0_2v8)) {
232                 pr_err("avdd_lcd regulator get failed\n");
233                 err = PTR_ERR(avdd_lcd_3v0_2v8);
234                 avdd_lcd_3v0_2v8 = NULL;
235                 goto fail;
236         }
237
238         vdd_lcd_s_1v8 = regulator_get(NULL, "vdd_lcd_1v8_s");
239         if (IS_ERR(vdd_lcd_s_1v8)) {
240                 pr_err("vdd_lcd_1v8_s regulator get failed\n");
241                 err = PTR_ERR(vdd_lcd_s_1v8);
242                 vdd_lcd_s_1v8 = NULL;
243                 goto fail;
244         }
245
246         vdd_sys_bl_3v7 = regulator_get(NULL, "vdd_sys_bl");
247         if (IS_ERR(vdd_sys_bl_3v7)) {
248                 pr_err("vdd_sys_bl regulator get failed\n");
249                 err = PTR_ERR(vdd_sys_bl_3v7);
250                 vdd_sys_bl_3v7 = NULL;
251                 goto fail;
252         }
253
254         dsi_j_720p_4_7_reg_requested = true;
255         return 0;
256 fail:
257         return err;
258 }
259
260 static int dsi_j_720p_4_7_gpio_get(void)
261 {
262         int err = 0;
263
264         if (dsi_j_720p_4_7_gpio_requested)
265                 return 0;
266
267         err = gpio_request(dsi_j_720p_4_7_pdata.dsi_panel_rst_gpio,
268                 "panel rst");
269         if (err < 0) {
270                 pr_err("panel reset gpio request failed\n");
271                 goto fail;
272         }
273
274         err = gpio_request(dsi_j_720p_4_7_pdata.dsi_panel_bl_en_gpio,
275                 "panel backlight");
276         if (err < 0) {
277                 pr_err("panel backlight gpio request failed\n");
278                 goto fail;
279         }
280
281
282
283         dsi_j_720p_4_7_gpio_requested = true;
284         return 0;
285 fail:
286         return err;
287 }
288
289 static int dsi_j_720p_4_7_enable(struct device *dev)
290 {
291         int err = 0;
292
293         err = dsi_j_720p_4_7_reg_get();
294         if (err < 0) {
295                 pr_err("dsi regulator get failed\n");
296                 goto fail;
297         }
298
299         err = dsi_j_720p_4_7_gpio_get();
300         if (err < 0) {
301                 pr_err("dsi gpio request failed\n");
302                 goto fail;
303         }
304         gpio_direction_output(dsi_j_720p_4_7_pdata.dsi_panel_rst_gpio, 0);
305
306         if (avdd_lcd_3v0_2v8) {
307                 err = regulator_enable(avdd_lcd_3v0_2v8);
308                 if (err < 0) {
309                         pr_err("avdd_lcd regulator enable failed\n");
310                         goto fail;
311                 }
312                 regulator_set_voltage(avdd_lcd_3v0_2v8, 3000000, 3000000);
313         }
314
315         usleep_range(3000, 5000);
316
317         if (vdd_lcd_s_1v8) {
318                 err = regulator_enable(vdd_lcd_s_1v8);
319                 if (err < 0) {
320                         pr_err("vdd_lcd_1v8_s regulator enable failed\n");
321                         goto fail;
322                 }
323         }
324         usleep_range(3000, 5000);
325
326         if (vdd_sys_bl_3v7) {
327                 err = regulator_enable(vdd_sys_bl_3v7);
328                 if (err < 0) {
329                         pr_err("vdd_sys_bl regulator enable failed\n");
330                         goto fail;
331                 }
332         }
333         usleep_range(3000, 5000);
334
335 #if DSI_PANEL_RESET
336         gpio_set_value(dsi_j_720p_4_7_pdata.dsi_panel_rst_gpio, 1);
337         usleep_range(1000, 5000);
338         gpio_set_value(dsi_j_720p_4_7_pdata.dsi_panel_rst_gpio, 0);
339         usleep_range(1000, 5000);
340         gpio_set_value(dsi_j_720p_4_7_pdata.dsi_panel_rst_gpio, 1);
341         msleep(20);
342 #endif
343
344         gpio_direction_output(dsi_j_720p_4_7_pdata.dsi_panel_bl_en_gpio, 1);
345         is_bl_powered = true;
346         return 0;
347 fail:
348         return err;
349 }
350
351 static struct tegra_dsi_cmd dsi_j_720p_4_7_init_cmd[] = {
352         DSI_CMD_SHORT(DSI_DCS_WRITE_1_PARAM, 0xFF, 0xEE),
353         DSI_CMD_SHORT(DSI_DCS_WRITE_1_PARAM, 0x26, 0x08),
354         DSI_DLY_MS(10),
355         DSI_CMD_SHORT(DSI_DCS_WRITE_1_PARAM, 0x26, 0x00),
356         DSI_CMD_SHORT(DSI_DCS_WRITE_1_PARAM, 0xFF, 0x00),
357         DSI_DLY_MS(15),
358         DSI_GPIO_SET(0, 1), /* use dummy gpio */
359         DSI_DLY_MS(10),
360         DSI_GPIO_SET(0, 0), /* use dummy gpio */
361         DSI_DLY_MS(20),
362         DSI_GPIO_SET(0, 1), /* use dummy gpio */
363         DSI_DLY_MS(100),
364         DSI_CMD_SHORT(DSI_DCS_WRITE_1_PARAM, 0xBA, 0x02),
365         DSI_DLY_MS(5),
366         DSI_CMD_SHORT(DSI_DCS_WRITE_1_PARAM, 0xC2, 0x08),
367         DSI_DLY_MS(5),
368         DSI_CMD_SHORT(DSI_DCS_WRITE_1_PARAM, 0xFF, 0x04),
369         DSI_DLY_MS(5),
370         DSI_CMD_SHORT(DSI_DCS_WRITE_1_PARAM, 0x09, 0x00),
371         DSI_DLY_MS(5),
372         DSI_CMD_SHORT(DSI_DCS_WRITE_1_PARAM, 0x0A, 0x00),
373         DSI_DLY_MS(5),
374         DSI_CMD_SHORT(DSI_DCS_WRITE_1_PARAM, 0xFB, 0x01),
375         DSI_DLY_MS(5),
376         DSI_CMD_SHORT(DSI_DCS_WRITE_1_PARAM, 0xFF, 0xEE),
377         DSI_DLY_MS(5),
378         DSI_CMD_SHORT(DSI_DCS_WRITE_1_PARAM, 0x12, 0x53),
379         DSI_DLY_MS(5),
380         DSI_CMD_SHORT(DSI_DCS_WRITE_1_PARAM, 0x13, 0x05),
381         DSI_DLY_MS(5),
382         DSI_CMD_SHORT(DSI_DCS_WRITE_1_PARAM, 0x6A, 0x60),
383         DSI_DLY_MS(5),
384         DSI_CMD_SHORT(DSI_DCS_WRITE_1_PARAM, 0xFB, 0x01),
385         DSI_DLY_MS(5),
386         DSI_CMD_SHORT(DSI_DCS_WRITE_1_PARAM, 0xFF, 0x00),
387         DSI_DLY_MS(5),
388         DSI_CMD_SHORT(DSI_DCS_WRITE_1_PARAM, 0x3A, 0x77),
389         DSI_DLY_MS(5),
390         DSI_CMD_SHORT(DSI_DCS_WRITE_0_PARAM, DSI_DCS_EXIT_SLEEP_MODE, 0x00),
391         DSI_DLY_MS(100),
392 #if (DC_CTRL_MODE & TEGRA_DC_OUT_ONE_SHOT_MODE)
393         DSI_CMD_SHORT(DSI_DCS_WRITE_1_PARAM, DSI_DCS_SET_TEARING_EFFECT_ON, 0),
394 #endif
395         DSI_CMD_SHORT(DSI_DCS_WRITE_0_PARAM, DSI_DCS_SET_DISPLAY_ON, 0x00),
396         DSI_DLY_MS(150),
397 };
398
399 static struct tegra_dsi_out dsi_j_720p_4_7_pdata = {
400         .n_data_lanes = 3,
401
402         .rated_refresh_rate = 60,
403         .refresh_rate = 60,
404         .suspend_aggr = DSI_HOST_SUSPEND_LV2,
405         .video_data_type = TEGRA_DSI_VIDEO_TYPE_COMMAND_MODE,
406         .video_clock_mode = TEGRA_DSI_VIDEO_CLOCK_TX_ONLY,
407         .controller_vs = DSI_VS_1,
408         .pixel_format = TEGRA_DSI_PIXEL_FORMAT_24BIT_P,
409         .virtual_channel = TEGRA_DSI_VIRTUAL_CHANNEL_0,
410
411         .panel_reset = DSI_PANEL_RESET,
412         .power_saving_suspend = true,
413         .dsi_init_cmd = dsi_j_720p_4_7_init_cmd,
414         .n_init_cmd = ARRAY_SIZE(dsi_j_720p_4_7_init_cmd),
415 };
416
417 static int dsi_j_720p_4_7_disable(void)
418 {
419         gpio_set_value(dsi_j_720p_4_7_pdata.dsi_panel_bl_en_gpio, 0);
420         is_bl_powered = false;
421         if (vdd_sys_bl_3v7)
422                 regulator_disable(vdd_sys_bl_3v7);
423
424         if (vdd_lcd_s_1v8)
425                 regulator_disable(vdd_lcd_s_1v8);
426
427         if (avdd_lcd_3v0_2v8)
428                 regulator_disable(avdd_lcd_3v0_2v8);
429
430         return 0;
431 }
432
433 static void dsi_j_720p_4_7_set_disp_device(
434         struct platform_device *pluto_display_device)
435 {
436         disp_device = pluto_display_device;
437 }
438
439 static void dsi_j_720p_4_7_dc_out_init(struct tegra_dc_out *dc)
440 {
441         dc->dsi = &dsi_j_720p_4_7_pdata;
442         dc->parent_clk = "pll_d_out0";
443         dc->modes = dsi_j_720p_4_7_modes;
444         dc->n_modes = ARRAY_SIZE(dsi_j_720p_4_7_modes);
445         dc->enable = dsi_j_720p_4_7_enable;
446         dc->disable = dsi_j_720p_4_7_disable;
447         dc->width = 58;
448         dc->height = 103;
449         dc->flags = DC_CTRL_MODE;
450 }
451 static void dsi_j_720p_4_7_fb_data_init(struct tegra_fb_data *fb)
452 {
453         fb->xres = dsi_j_720p_4_7_modes[0].h_active;
454         fb->yres = dsi_j_720p_4_7_modes[0].v_active;
455 }
456
457 static void dsi_j_720p_4_7_sd_settings_init
458 (struct tegra_dc_sd_settings *settings)
459 {
460         *settings = dsi_j_720p_4_7_sd_settings;
461         settings->bl_device_name = "pwm-backlight";
462 }
463
464
465 struct tegra_panel __initdata dsi_j_720p_4_7 = {
466         .init_sd_settings = dsi_j_720p_4_7_sd_settings_init,
467         .init_dc_out = dsi_j_720p_4_7_dc_out_init,
468         .init_fb_data = dsi_j_720p_4_7_fb_data_init,
469         .set_disp_device = dsi_j_720p_4_7_set_disp_device,
470         .register_bl_dev = dsi_j_720p_4_7_register_bl_dev,
471 };
472 EXPORT_SYMBOL(dsi_j_720p_4_7);