ARM: tegra12: set CPU rate to 2.2GHz for sku 0x87
[linux-3.10.git] / arch / arm / mach-tegra / panel-a-edp-1080p-14-0.c
1 /*
2  * arch/arm/mach-tegra/panel-a-1080p-11-6.c
3  *
4  * Copyright (c) 2012-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 "board.h"
29 #include "board-panel.h"
30 #include "devices.h"
31 #include "gpio-names.h"
32 #include "tegra12_host1x_devices.h"
33
34 #define DC_CTRL_MODE    TEGRA_DC_OUT_CONTINUOUS_MODE
35
36 #define EDP_PANEL_BL_PWM        TEGRA_GPIO_PH1
37
38 static bool reg_requested;
39 static bool gpio_requested;
40 static struct platform_device *disp_device;
41
42 static struct regulator *vdd_lcd_bl;
43 static struct regulator *vdd_lcd_bl_en;
44 static struct regulator *avdd_lcd;
45 static struct regulator *vdd_ds_1v8;
46 static struct regulator *avdd_3v3_dp;
47
48 static struct tegra_dc_sd_settings edp_a_1080p_14_0_sd_settings = {
49         .enable = 1, /* enabled by default. */
50         .use_auto_pwm = false,
51         .hw_update_delay = 0,
52         .bin_width = -1,
53         .aggressiveness = 5,
54         .use_vid_luma = false,
55         .phase_in_adjustments = 0,
56         .k_limit_enable = true,
57         .k_limit = 200,
58         .sd_window_enable = false,
59         .soft_clipping_enable = true,
60         /* Low soft clipping threshold to compensate for aggressive k_limit */
61         .soft_clipping_threshold = 128,
62         .smooth_k_enable = false,
63         .smooth_k_incr = 64,
64         /* Default video coefficients */
65         .coeff = {5, 9, 2},
66         .fc = {0, 0},
67         /* Immediate backlight changes */
68         .blp = {1024, 255},
69         /* Gammas: R: 2.2 G: 2.2 B: 2.2 */
70         /* Default BL TF */
71         .bltf = {
72                         {
73                                 {57, 65, 73, 82},
74                                 {92, 103, 114, 125},
75                                 {138, 150, 164, 178},
76                                 {193, 208, 224, 241},
77                         },
78                 },
79         /* Default LUT */
80         .lut = {
81                         {
82                                 {255, 255, 255},
83                                 {199, 199, 199},
84                                 {153, 153, 153},
85                                 {116, 116, 116},
86                                 {85, 85, 85},
87                                 {59, 59, 59},
88                                 {36, 36, 36},
89                                 {17, 17, 17},
90                                 {0, 0, 0},
91                         },
92                 },
93         .sd_brightness = &sd_brightness,
94         .use_vpulse2 = true,
95 };
96
97 static tegra_dc_bl_output edp_a_1080p_14_0_bl_output_measured = {
98         0, 0, 1, 2, 3, 4, 5, 6,
99         7, 8, 9, 9, 10, 11, 12, 13,
100         13, 14, 15, 16, 17, 17, 18, 19,
101         20, 21, 22, 22, 23, 24, 25, 26,
102         27, 27, 28, 29, 30, 31, 32, 32,
103         33, 34, 35, 36, 37, 37, 38, 39,
104         40, 41, 42, 42, 43, 44, 45, 46,
105         47, 48, 48, 49, 50, 51, 52, 53,
106         54, 55, 56, 57, 57, 58, 59, 60,
107         61, 62, 63, 64, 65, 66, 67, 68,
108         69, 70, 71, 71, 72, 73, 74, 75,
109         76, 77, 77, 78, 79, 80, 81, 82,
110         83, 84, 85, 87, 88, 89, 90, 91,
111         92, 93, 94, 95, 96, 97, 98, 99,
112         100, 101, 102, 103, 104, 105, 106, 107,
113         108, 109, 110, 111, 112, 113, 115, 116,
114         117, 118, 119, 120, 121, 122, 123, 124,
115         125, 126, 127, 128, 129, 130, 131, 132,
116         133, 134, 135, 136, 137, 138, 139, 141,
117         142, 143, 144, 146, 147, 148, 149, 151,
118         152, 153, 154, 155, 156, 157, 158, 158,
119         159, 160, 161, 162, 163, 165, 166, 167,
120         168, 169, 170, 171, 172, 173, 174, 176,
121         177, 178, 179, 180, 182, 183, 184, 185,
122         186, 187, 188, 189, 190, 191, 192, 194,
123         195, 196, 197, 198, 199, 200, 201, 202,
124         203, 204, 205, 206, 207, 208, 209, 210,
125         211, 212, 213, 214, 215, 216, 217, 219,
126         220, 221, 222, 224, 225, 226, 227, 229,
127         230, 231, 232, 233, 234, 235, 236, 238,
128         239, 240, 241, 242, 243, 244, 245, 246,
129         247, 248, 249, 250, 251, 252, 253, 255
130 };
131
132 static int laguna_edp_regulator_get(struct device *dev)
133 {
134         int err = 0;
135
136         if (reg_requested)
137                 return 0;
138
139         vdd_ds_1v8 = regulator_get(dev, "vdd_ds_1v8");
140         if (IS_ERR(vdd_ds_1v8)) {
141                 pr_err("vdd_ds_1v8 regulator get failed\n");
142                 err = PTR_ERR(vdd_ds_1v8);
143                 vdd_ds_1v8 = NULL;
144                 goto fail;
145         }
146
147         vdd_lcd_bl = regulator_get(dev, "vdd_lcd_bl");
148         if (IS_ERR(vdd_lcd_bl)) {
149                 pr_err("vdd_lcd_bl regulator get failed\n");
150                 err = PTR_ERR(vdd_lcd_bl);
151                 vdd_lcd_bl = NULL;
152                 goto fail;
153         }
154
155         vdd_lcd_bl_en = regulator_get(dev, "vdd_lcd_bl_en");
156         if (IS_ERR(vdd_lcd_bl_en)) {
157                 pr_err("vdd_lcd_bl_en regulator get failed\n");
158                 err = PTR_ERR(vdd_lcd_bl_en);
159                 vdd_lcd_bl_en = NULL;
160                 goto fail;
161         }
162
163         avdd_lcd = regulator_get(dev, "avdd_lcd");
164         if (IS_ERR(avdd_lcd)) {
165                 pr_err("avdd_lcd regulator get failed\n");
166                 err = PTR_ERR(avdd_lcd);
167                 avdd_lcd = NULL;
168                 goto fail;
169         }
170
171         reg_requested = true;
172         return 0;
173 fail:
174         return err;
175 }
176
177 static int ardbeg_edp_regulator_get(struct device *dev)
178 {
179         int err = 0;
180
181         if (reg_requested)
182                 return 0;
183
184         vdd_ds_1v8 = regulator_get(dev, "vdd_lcd_1v8_s");
185         if (IS_ERR_OR_NULL(vdd_ds_1v8)) {
186                 pr_err("vdd_ds_1v8 regulator get failed\n");
187                 err = PTR_ERR(vdd_ds_1v8);
188                 vdd_ds_1v8 = NULL;
189                 goto fail;
190         }
191
192         vdd_lcd_bl_en = regulator_get(dev, "vdd_lcd_bl_en");
193         if (IS_ERR_OR_NULL(vdd_lcd_bl_en)) {
194                 pr_err("vdd_lcd_bl_en regulator get failed\n");
195                 err = PTR_ERR(vdd_lcd_bl_en);
196                 vdd_lcd_bl_en = NULL;
197                 goto fail;
198         }
199
200         avdd_lcd = regulator_get(dev, "avdd_lcd");
201         if (IS_ERR_OR_NULL(avdd_lcd)) {
202                 pr_err("avdd_lcd regulator get failed\n");
203                 err = PTR_ERR(avdd_lcd);
204                 avdd_lcd = NULL;
205                 goto fail;
206         }
207
208         avdd_3v3_dp = regulator_get(dev, "avdd_3v3_dp");
209         if (IS_ERR_OR_NULL(avdd_3v3_dp)) {
210                 pr_err("avdd_3v3_dp regulator get failed\n");
211                 err = PTR_ERR(avdd_3v3_dp);
212                 avdd_3v3_dp = NULL;
213                 goto fail;
214         }
215
216         reg_requested = true;
217         return 0;
218 fail:
219         return err;
220 }
221
222 static int laguna_edp_gpio_get(void)
223 {
224         int err = 0;
225
226         if (gpio_requested)
227                 return 0;
228
229         err = gpio_request(EDP_PANEL_BL_PWM, "panel pwm");
230         if (err < 0) {
231                 pr_err("panel pwm gpio request failed\n");
232                 goto fail;
233         }
234         gpio_free(EDP_PANEL_BL_PWM);
235
236         gpio_requested = true;
237         return 0;
238 fail:
239         return err;
240 }
241
242 static int edp_a_1080p_14_0_enable(struct device *dev)
243 {
244         int err = 0;
245
246         if (of_machine_is_compatible("nvidia,ardbeg"))
247                 err = ardbeg_edp_regulator_get(dev);
248         else
249                 err = laguna_edp_regulator_get(dev);
250         if (err < 0) {
251                 pr_err("edp regulator get failed\n");
252                 goto fail;
253         }
254
255         err = laguna_edp_gpio_get();
256         if (err < 0) {
257                 pr_err("edp gpio request failed\n");
258                 goto fail;
259         }
260
261         if (vdd_lcd_bl) {
262                 err = regulator_enable(vdd_lcd_bl);
263                 if (err < 0) {
264                         pr_err("vdd_lcd_bl regulator enable failed\n");
265                         goto fail;
266                 }
267         }
268
269         if (avdd_3v3_dp) {
270                 err = regulator_enable(avdd_3v3_dp);
271                 if (err < 0) {
272                         pr_err("avdd_3v3_dp regulator enable failed\n");
273                         goto fail;
274                 }
275         }
276
277         msleep(20);
278
279         if (vdd_ds_1v8) {
280                 err = regulator_enable(vdd_ds_1v8);
281                 if (err < 0) {
282                         pr_err("vdd_ds_1v8 regulator enable failed\n");
283                         goto fail;
284                 }
285         }
286
287         if (avdd_lcd) {
288                 err = regulator_enable(avdd_lcd);
289                 if (err < 0) {
290                         pr_err("avdd_lcd regulator enable failed\n");
291                         goto fail;
292                 }
293         }
294
295         msleep(10);
296
297         if (vdd_lcd_bl_en) {
298                 err = regulator_enable(vdd_lcd_bl_en);
299                 if (err < 0) {
300                         pr_err("vdd_lcd_bl_en regulator enable failed\n");
301                         goto fail;
302                 }
303         }
304         msleep(180);
305
306         return 0;
307 fail:
308         return err;
309 }
310
311 static int edp_a_1080p_14_0_disable(void)
312 {
313         if (vdd_lcd_bl_en)
314                 regulator_disable(vdd_lcd_bl_en);
315
316         msleep(10);
317
318         if (avdd_lcd)
319                 regulator_disable(avdd_lcd);
320
321         if (vdd_ds_1v8)
322                 regulator_disable(vdd_ds_1v8);
323
324         msleep(10);
325
326         if (vdd_lcd_bl)
327                 regulator_disable(vdd_lcd_bl);
328
329         if (avdd_3v3_dp)
330                 regulator_disable(avdd_3v3_dp);
331
332         msleep(500);
333
334         return 0;
335 }
336
337 static int edp_a_1080p_14_0_postsuspend(void)
338 {
339         return 0;
340 }
341
342 static struct tegra_dc_out_pin edp_out_pins[] = {
343         {
344                 .name   = TEGRA_DC_OUT_PIN_H_SYNC,
345                 .pol    = TEGRA_DC_OUT_PIN_POL_LOW,
346         },
347         {
348                 .name   = TEGRA_DC_OUT_PIN_V_SYNC,
349                 .pol    = TEGRA_DC_OUT_PIN_POL_LOW,
350         },
351         {
352                 .name   = TEGRA_DC_OUT_PIN_PIXEL_CLOCK,
353                 .pol    = TEGRA_DC_OUT_PIN_POL_LOW,
354         },
355         {
356                 .name   = TEGRA_DC_OUT_PIN_DATA_ENABLE,
357                 .pol    = TEGRA_DC_OUT_PIN_POL_HIGH,
358         },
359 };
360
361 static int edp_a_1080p_14_0_bl_notify(struct device *unused, int brightness)
362 {
363         int cur_sd_brightness = atomic_read(&sd_brightness);
364
365         /* SD brightness is a percentage */
366         brightness = (brightness * cur_sd_brightness) / 255;
367
368         /* Apply any backlight response curve */
369         if (brightness > 255)
370                 pr_info("Error: Brightness > 255!\n");
371         else
372                 brightness = edp_a_1080p_14_0_bl_output_measured[brightness];
373
374         return brightness;
375 }
376
377 static int edp_a_1080p_14_0_check_fb(struct device *dev, struct fb_info *info)
378 {
379         return info->device == &disp_device->dev;
380 }
381
382 static struct platform_pwm_backlight_data edp_a_1080p_14_0_bl_data = {
383         .pwm_id         = 1,
384         .max_brightness = 255,
385         .dft_brightness = 224,
386         .pwm_period_ns  = 1000000,
387         .pwm_gpio       = TEGRA_GPIO_INVALID,
388         .notify         = edp_a_1080p_14_0_bl_notify,
389         /* Only toggle backlight on fb blank notifications for disp1 */
390         .check_fb       = edp_a_1080p_14_0_check_fb,
391 };
392
393 static struct platform_device __maybe_unused
394                 edp_a_1080p_14_0_bl_device = {
395         .name   = "pwm-backlight",
396         .id     = -1,
397         .dev    = {
398                 .platform_data = &edp_a_1080p_14_0_bl_data,
399         },
400 };
401
402 static struct platform_device __maybe_unused
403                         *edp_a_1080p_14_0_bl_devices[] __initdata = {
404         &tegra_pwfm_device,
405         &edp_a_1080p_14_0_bl_device,
406 };
407
408 static int  __init edp_a_1080p_14_0_register_bl_dev(void)
409 {
410         int err = 0;
411         err = platform_add_devices(edp_a_1080p_14_0_bl_devices,
412                                 ARRAY_SIZE(edp_a_1080p_14_0_bl_devices));
413         if (err) {
414                 pr_err("disp1 bl device registration failed");
415                 return err;
416         }
417         return err;
418 }
419
420 static void edp_a_1080p_14_0_set_disp_device(
421         struct platform_device *laguna_display_device)
422 {
423         disp_device = laguna_display_device;
424 }
425
426 static void edp_a_1080p_14_0_dc_out_init(struct tegra_dc_out *dc)
427 {
428         dc->align = TEGRA_DC_ALIGN_MSB,
429         dc->order = TEGRA_DC_ORDER_RED_BLUE,
430         dc->flags = DC_CTRL_MODE;
431         dc->out_pins = edp_out_pins,
432         dc->n_out_pins = ARRAY_SIZE(edp_out_pins),
433         dc->depth = 18,
434         dc->parent_clk = "pll_d_out0";
435         dc->enable = edp_a_1080p_14_0_enable;
436         dc->disable = edp_a_1080p_14_0_disable;
437         dc->postsuspend = edp_a_1080p_14_0_postsuspend,
438         dc->hotplug_gpio = TEGRA_GPIO_PFF0;
439 }
440
441 static void
442 edp_a_1080p_14_0_sd_settings_init(struct tegra_dc_sd_settings *settings)
443 {
444         *settings = edp_a_1080p_14_0_sd_settings;
445         settings->bl_device_name = "pwm-backlight";
446 }
447
448 struct tegra_panel __initdata edp_a_1080p_14_0 = {
449         .init_sd_settings = edp_a_1080p_14_0_sd_settings_init,
450         .init_dc_out = edp_a_1080p_14_0_dc_out_init,
451         .register_bl_dev = edp_a_1080p_14_0_register_bl_dev,
452         .set_disp_device = edp_a_1080p_14_0_set_disp_device,
453 };
454 EXPORT_SYMBOL(edp_a_1080p_14_0);
455