dfa21445e38adcf8680d7082f0125922bdb5270a
[linux-2.6.git] / arch / arm / mach-tegra / board-kai-panel.c
1 /*
2  * arch/arm/mach-tegra/board-kai-panel.c
3  *
4  * Copyright (c) 2012, NVIDIA Corporation.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that 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 along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18  */
19
20 #include <linux/delay.h>
21 #include <linux/gpio.h>
22 #include <linux/regulator/consumer.h>
23 #include <linux/resource.h>
24 #include <asm/mach-types.h>
25 #include <linux/platform_device.h>
26 #ifdef CONFIG_HAS_EARLYSUSPEND
27 #include <linux/earlysuspend.h>
28 #endif
29 #include <linux/pwm_backlight.h>
30 #include <asm/atomic.h>
31 #include <linux/nvhost.h>
32 #include <linux/nvmap.h>
33 #include <mach/irqs.h>
34 #include <mach/iomap.h>
35 #include <mach/dc.h>
36 #include <mach/fb.h>
37 #include <mach/gpio-tegra.h>
38
39 #include "board.h"
40 #include "board-kai.h"
41 #include "devices.h"
42 #include "gpio-names.h"
43
44 /* kai default display board pins */
45 #define kai_lvds_avdd_en                TEGRA_GPIO_PH6
46 #define kai_lvds_stdby                  TEGRA_GPIO_PG5
47 #define kai_lvds_rst                    TEGRA_GPIO_PG7
48 #define kai_lvds_shutdown               TEGRA_GPIO_PN6
49 #define kai_lvds_rs                     TEGRA_GPIO_PV6
50 #define kai_lvds_lr                     TEGRA_GPIO_PG1
51
52 /* kai A00 display board pins */
53 #define kai_lvds_rs_a00         TEGRA_GPIO_PH1
54
55 /* common pins( backlight ) for all display boards */
56 #define kai_bl_enb                      TEGRA_GPIO_PH3
57 #define kai_bl_pwm                      TEGRA_GPIO_PH0
58 #define kai_hdmi_hpd                    TEGRA_GPIO_PN7
59
60 #ifdef CONFIG_TEGRA_DC
61 static struct regulator *kai_hdmi_reg;
62 static struct regulator *kai_hdmi_pll;
63 static struct regulator *kai_hdmi_vddio;
64 #endif
65
66 static atomic_t sd_brightness = ATOMIC_INIT(255);
67
68 static struct regulator *kai_lvds_reg;
69 static struct regulator *kai_lvds_vdd_panel;
70
71 static tegra_dc_bl_output kai_bl_output_measured = {
72         0, 1, 2, 3, 4, 5, 6, 7,
73         7, 8, 9, 10, 11, 12, 13, 14,
74         15, 16, 17, 18, 19, 20, 20, 21,
75         22, 23, 24, 25, 26, 27, 28, 29,
76         30, 31, 32, 32, 34, 34, 36, 36,
77         38, 39, 40, 40, 41, 42, 42, 43,
78         44, 44, 45, 46, 46, 47, 48, 48,
79         49, 50, 50, 51, 52, 53, 54, 54,
80         55, 56, 57, 58, 58, 59, 60, 61,
81         62, 63, 64, 65, 66, 67, 68, 69,
82         70, 71, 72, 72, 73, 74, 75, 76,
83         76, 77, 78, 79, 80, 81, 82, 83,
84         85, 86, 87, 89, 90, 91, 92, 92,
85         93, 94, 95, 96, 96, 97, 98, 99,
86         100, 100, 101, 102, 103, 104, 104, 105,
87         106, 107, 108, 108, 109, 110, 112, 114,
88         116, 118, 120, 121, 122, 123, 124, 125,
89         126, 127, 128, 129, 130, 131, 132, 133,
90         134, 135, 136, 137, 138, 139, 140, 141,
91         142, 143, 144, 145, 146, 147, 148, 149,
92         150, 151, 151, 152, 153, 153, 154, 155,
93         155, 156, 157, 157, 158, 159, 159, 160,
94         162, 164, 166, 168, 170, 172, 174, 176,
95         178, 180, 181, 181, 182, 183, 183, 184,
96         185, 185, 186, 187, 187, 188, 189, 189,
97         190, 191, 192, 193, 194, 195, 196, 197,
98         198, 199, 200, 201, 201, 202, 203, 203,
99         204, 205, 205, 206, 207, 207, 208, 209,
100         209, 210, 211, 211, 212, 212, 213, 213,
101         214, 215, 215, 216, 216, 217, 217, 218,
102         219, 219, 220, 222, 226, 230, 232, 234,
103         236, 238, 240, 244, 248, 251, 253, 255
104 };
105
106 static p_tegra_dc_bl_output bl_output;
107
108 static int kai_backlight_init(struct device *dev)
109 {
110         int ret;
111
112         bl_output = kai_bl_output_measured;
113
114         if (WARN_ON(ARRAY_SIZE(kai_bl_output_measured) != 256))
115                 pr_err("bl_output array does not have 256 elements\n");
116
117         ret = gpio_request(kai_bl_enb, "backlight_enb");
118         if (ret < 0)
119                 return ret;
120
121         ret = gpio_direction_output(kai_bl_enb, 1);
122         if (ret < 0)
123                 gpio_free(kai_bl_enb);
124
125         return ret;
126 };
127
128 static void kai_backlight_exit(struct device *dev)
129 {
130         /* int ret; */
131         /*ret = gpio_request(kai_bl_enb, "backlight_enb");*/
132         gpio_set_value(kai_bl_enb, 0);
133         gpio_free(kai_bl_enb);
134         return;
135 }
136
137 static int kai_backlight_notify(struct device *unused, int brightness)
138 {
139         int cur_sd_brightness = atomic_read(&sd_brightness);
140
141         /* Set the backlight GPIO pin mode to 'backlight_enable' */
142         gpio_set_value(kai_bl_enb, !!brightness);
143
144         /* SD brightness is a percentage, 8-bit value. */
145         brightness = (brightness * cur_sd_brightness) / 255;
146
147         /* Apply any backlight response curve */
148         if (brightness > 255)
149                 pr_info("Error: Brightness > 255!\n");
150         else
151                 brightness = bl_output[brightness];
152
153         return brightness;
154 }
155
156 static int kai_disp1_check_fb(struct device *dev, struct fb_info *info);
157
158 static struct platform_pwm_backlight_data kai_backlight_data = {
159         .pwm_id         = 0,
160         .max_brightness = 255,
161         .dft_brightness = 224,
162         .pwm_period_ns  = 100000,
163         .init           = kai_backlight_init,
164         .exit           = kai_backlight_exit,
165         .notify         = kai_backlight_notify,
166         /* Only toggle backlight on fb blank notifications for disp1 */
167         .check_fb       = kai_disp1_check_fb,
168 };
169
170 static struct platform_device kai_backlight_device = {
171         .name   = "pwm-backlight",
172         .id     = -1,
173         .dev    = {
174                 .platform_data = &kai_backlight_data,
175         },
176 };
177
178 static int kai_panel_enable(void)
179 {
180         if (kai_lvds_reg == NULL) {
181                 kai_lvds_reg = regulator_get(NULL, "vdd_lvds");
182                 if (WARN_ON(IS_ERR(kai_lvds_reg)))
183                         pr_err("%s: couldn't get regulator vdd_lvds: %ld\n",
184                                __func__, PTR_ERR(kai_lvds_reg));
185                 else
186                         regulator_enable(kai_lvds_reg);
187         }
188
189         if (kai_lvds_vdd_panel == NULL) {
190                 kai_lvds_vdd_panel = regulator_get(NULL, "vdd_lcd_panel");
191                 if (WARN_ON(IS_ERR(kai_lvds_vdd_panel)))
192                         pr_err("%s: couldn't get regulator vdd_lcd_panel: %ld\n",
193                                __func__, PTR_ERR(kai_lvds_vdd_panel));
194                 else
195                         regulator_enable(kai_lvds_vdd_panel);
196         }
197
198         mdelay(5);
199
200         gpio_set_value(kai_lvds_avdd_en, 1);
201         mdelay(5);
202
203         gpio_set_value(kai_lvds_stdby, 1);
204         gpio_set_value(kai_lvds_rst, 1);
205         gpio_set_value(kai_lvds_shutdown, 1);
206         gpio_set_value(kai_lvds_lr, 1);
207
208         mdelay(10);
209
210         return 0;
211 }
212
213 static int kai_panel_disable(void)
214 {
215         gpio_set_value(kai_lvds_lr, 0);
216         gpio_set_value(kai_lvds_shutdown, 0);
217         gpio_set_value(kai_lvds_rst, 0);
218         gpio_set_value(kai_lvds_stdby, 0);
219         mdelay(5);
220
221         gpio_set_value(kai_lvds_avdd_en, 0);
222         mdelay(5);
223
224         regulator_disable(kai_lvds_reg);
225         regulator_put(kai_lvds_reg);
226         kai_lvds_reg = NULL;
227
228         regulator_disable(kai_lvds_vdd_panel);
229         regulator_put(kai_lvds_vdd_panel);
230         kai_lvds_vdd_panel = NULL;
231
232         return 0;
233 }
234
235 #ifdef CONFIG_TEGRA_DC
236 static int kai_hdmi_vddio_enable(void)
237 {
238         int ret;
239         if (!kai_hdmi_vddio) {
240                 kai_hdmi_vddio = regulator_get(NULL, "vdd_hdmi_con");
241                 if (IS_ERR_OR_NULL(kai_hdmi_vddio)) {
242                         ret = PTR_ERR(kai_hdmi_vddio);
243                         pr_err("hdmi: couldn't get regulator vdd_hdmi_con\n");
244                         kai_hdmi_vddio = NULL;
245                         return ret;
246                 }
247         }
248         ret = regulator_enable(kai_hdmi_vddio);
249         if (ret < 0) {
250                 pr_err("hdmi: couldn't enable regulator vdd_hdmi_con\n");
251                 regulator_put(kai_hdmi_vddio);
252                 kai_hdmi_vddio = NULL;
253                 return ret;
254         }
255         return ret;
256 }
257
258 static int kai_hdmi_vddio_disable(void)
259 {
260         if (kai_hdmi_vddio) {
261                 regulator_disable(kai_hdmi_vddio);
262                 regulator_put(kai_hdmi_vddio);
263                 kai_hdmi_vddio = NULL;
264         }
265         return 0;
266 }
267
268 static int kai_hdmi_enable(void)
269 {
270         int ret;
271         if (!kai_hdmi_reg) {
272                 kai_hdmi_reg = regulator_get(NULL, "avdd_hdmi");
273                 if (IS_ERR_OR_NULL(kai_hdmi_reg)) {
274                         pr_err("hdmi: couldn't get regulator avdd_hdmi\n");
275                         kai_hdmi_reg = NULL;
276                         return PTR_ERR(kai_hdmi_reg);
277                 }
278         }
279         ret = regulator_enable(kai_hdmi_reg);
280         if (ret < 0) {
281                 pr_err("hdmi: couldn't enable regulator avdd_hdmi\n");
282                 return ret;
283         }
284         if (!kai_hdmi_pll) {
285                 kai_hdmi_pll = regulator_get(NULL, "avdd_hdmi_pll");
286                 if (IS_ERR_OR_NULL(kai_hdmi_pll)) {
287                         pr_err("hdmi: couldn't get regulator avdd_hdmi_pll\n");
288                         kai_hdmi_pll = NULL;
289                         regulator_put(kai_hdmi_reg);
290                         kai_hdmi_reg = NULL;
291                         return PTR_ERR(kai_hdmi_pll);
292                 }
293         }
294         ret = regulator_enable(kai_hdmi_pll);
295         if (ret < 0) {
296                 pr_err("hdmi: couldn't enable regulator avdd_hdmi_pll\n");
297                 return ret;
298         }
299         return 0;
300 }
301
302 static int kai_hdmi_disable(void)
303 {
304         regulator_disable(kai_hdmi_reg);
305         regulator_put(kai_hdmi_reg);
306         kai_hdmi_reg = NULL;
307
308         regulator_disable(kai_hdmi_pll);
309         regulator_put(kai_hdmi_pll);
310         kai_hdmi_pll = NULL;
311         return 0;
312 }
313
314 static struct resource kai_disp1_resources[] = {
315         {
316                 .name   = "irq",
317                 .start  = INT_DISPLAY_GENERAL,
318                 .end    = INT_DISPLAY_GENERAL,
319                 .flags  = IORESOURCE_IRQ,
320         },
321         {
322                 .name   = "regs",
323                 .start  = TEGRA_DISPLAY_BASE,
324                 .end    = TEGRA_DISPLAY_BASE + TEGRA_DISPLAY_SIZE-1,
325                 .flags  = IORESOURCE_MEM,
326         },
327         {
328                 .name   = "fbmem",
329                 .start  = 0,    /* Filled in by kai_panel_init() */
330                 .end    = 0,    /* Filled in by kai_panel_init() */
331                 .flags  = IORESOURCE_MEM,
332         },
333 };
334
335 static struct resource kai_disp2_resources[] = {
336         {
337                 .name   = "irq",
338                 .start  = INT_DISPLAY_B_GENERAL,
339                 .end    = INT_DISPLAY_B_GENERAL,
340                 .flags  = IORESOURCE_IRQ,
341         },
342         {
343                 .name   = "regs",
344                 .start  = TEGRA_DISPLAY2_BASE,
345                 .end    = TEGRA_DISPLAY2_BASE + TEGRA_DISPLAY2_SIZE - 1,
346                 .flags  = IORESOURCE_MEM,
347         },
348         {
349                 .name   = "fbmem",
350                 .flags  = IORESOURCE_MEM,
351                 .start  = 0,
352                 .end    = 0,
353         },
354         {
355                 .name   = "hdmi_regs",
356                 .start  = TEGRA_HDMI_BASE,
357                 .end    = TEGRA_HDMI_BASE + TEGRA_HDMI_SIZE - 1,
358                 .flags  = IORESOURCE_MEM,
359         },
360 };
361 #endif
362
363 static struct tegra_dc_mode kai_panel_modes[] = {
364         {
365                 /* 1024x600@60Hz */
366                 .pclk = 51206000,
367                 .h_ref_to_sync = 11,
368                 .v_ref_to_sync = 1,
369                 .h_sync_width = 10,
370                 .v_sync_width = 5,
371                 .h_back_porch = 10,
372                 .v_back_porch = 15,
373                 .h_active = 1024,
374                 .v_active = 600,
375                 .h_front_porch = 300,
376                 .v_front_porch = 15,
377         },
378 };
379
380 static struct tegra_dc_sd_settings kai_sd_settings = {
381         .enable = 1, /* enabled by default. */
382         .use_auto_pwm = false,
383         .hw_update_delay = 0,
384         .bin_width = -1,
385         .aggressiveness = 1,
386         .phase_in_adjustments = true,
387         .use_vid_luma = false,
388         /* Default video coefficients */
389         .coeff = {5, 9, 2},
390         .fc = {0, 0},
391         /* Immediate backlight changes */
392         .blp = {1024, 255},
393         /* Gammas: R: 2.2 G: 2.2 B: 2.2 */
394         /* Default BL TF */
395         .bltf = {
396                         {
397                                 {57, 65, 74, 83},
398                                 {93, 103, 114, 126},
399                                 {138, 151, 165, 179},
400                                 {194, 209, 225, 242},
401                         },
402                         {
403                                 {58, 66, 75, 84},
404                                 {94, 105, 116, 127},
405                                 {140, 153, 166, 181},
406                                 {196, 211, 227, 244},
407                         },
408                         {
409                                 {60, 68, 77, 87},
410                                 {97, 107, 119, 130},
411                                 {143, 156, 170, 184},
412                                 {199, 215, 231, 248},
413                         },
414                         {
415                                 {64, 73, 82, 91},
416                                 {102, 113, 124, 137},
417                                 {149, 163, 177, 192},
418                                 {207, 223, 240, 255},
419                         },
420                 },
421         /* Default LUT */
422         .lut = {
423                         {
424                                 {250, 250, 250},
425                                 {194, 194, 194},
426                                 {149, 149, 149},
427                                 {113, 113, 113},
428                                 {82, 82, 82},
429                                 {56, 56, 56},
430                                 {34, 34, 34},
431                                 {15, 15, 15},
432                                 {0, 0, 0},
433                         },
434                         {
435                                 {246, 246, 246},
436                                 {191, 191, 191},
437                                 {147, 147, 147},
438                                 {111, 111, 111},
439                                 {80, 80, 80},
440                                 {55, 55, 55},
441                                 {33, 33, 33},
442                                 {14, 14, 14},
443                                 {0, 0, 0},
444                         },
445                         {
446                                 {239, 239, 239},
447                                 {185, 185, 185},
448                                 {142, 142, 142},
449                                 {107, 107, 107},
450                                 {77, 77, 77},
451                                 {52, 52, 52},
452                                 {30, 30, 30},
453                                 {12, 12, 12},
454                                 {0, 0, 0},
455                         },
456                         {
457                                 {224, 224, 224},
458                                 {173, 173, 173},
459                                 {133, 133, 133},
460                                 {99, 99, 99},
461                                 {70, 70, 70},
462                                 {46, 46, 46},
463                                 {25, 25, 25},
464                                 {7, 7, 7},
465                                 {0, 0, 0},
466                         },
467                 },
468         .sd_brightness = &sd_brightness,
469         .bl_device = &kai_backlight_device,
470 };
471
472 #ifdef CONFIG_TEGRA_DC
473 static struct tegra_fb_data kai_fb_data = {
474         .win            = 0,
475         .xres           = 1024,
476         .yres           = 600,
477         .bits_per_pixel = 32,
478         .flags          = TEGRA_FB_FLIP_ON_PROBE,
479 };
480
481 static struct tegra_fb_data kai_hdmi_fb_data = {
482         .win            = 0,
483         .xres           = 1024,
484         .yres           = 600,
485         .bits_per_pixel = 32,
486         .flags          = TEGRA_FB_FLIP_ON_PROBE,
487 };
488
489 static struct tegra_dc_out kai_disp2_out = {
490         .type           = TEGRA_DC_OUT_HDMI,
491         .flags          = TEGRA_DC_OUT_HOTPLUG_HIGH,
492
493         .dcc_bus        = 3,
494         .hotplug_gpio   = kai_hdmi_hpd,
495
496         .max_pixclock   = KHZ2PICOS(148500),
497
498         .align          = TEGRA_DC_ALIGN_MSB,
499         .order          = TEGRA_DC_ORDER_RED_BLUE,
500
501         .enable         = kai_hdmi_enable,
502         .disable        = kai_hdmi_disable,
503
504         .postsuspend    = kai_hdmi_vddio_disable,
505         .hotplug_init   = kai_hdmi_vddio_enable,
506 };
507
508 static struct tegra_dc_platform_data kai_disp2_pdata = {
509         .flags          = 0,
510         .default_out    = &kai_disp2_out,
511         .fb             = &kai_hdmi_fb_data,
512         .emc_clk_rate   = 300000000,
513 };
514 #endif
515
516 static struct tegra_dc_out kai_disp1_out = {
517         .align          = TEGRA_DC_ALIGN_MSB,
518         .order          = TEGRA_DC_ORDER_RED_BLUE,
519         .sd_settings    = &kai_sd_settings,
520         .parent_clk     = "pll_p",
521         .parent_clk_backup = "pll_d2_out0",
522
523         .type           = TEGRA_DC_OUT_RGB,
524         .depth          = 18,
525         .dither         = TEGRA_DC_ORDERED_DITHER,
526
527         .modes          = kai_panel_modes,
528         .n_modes        = ARRAY_SIZE(kai_panel_modes),
529
530         .enable         = kai_panel_enable,
531         .disable        = kai_panel_disable,
532 };
533
534 #ifdef CONFIG_TEGRA_DC
535 static struct tegra_dc_platform_data kai_disp1_pdata = {
536         .flags          = TEGRA_DC_FLAG_ENABLED,
537         .default_out    = &kai_disp1_out,
538         .emc_clk_rate   = 300000000,
539         .fb             = &kai_fb_data,
540 };
541
542 static struct nvhost_device kai_disp1_device = {
543         .name           = "tegradc",
544         .id             = 0,
545         .resource       = kai_disp1_resources,
546         .num_resources  = ARRAY_SIZE(kai_disp1_resources),
547         .dev = {
548                 .platform_data = &kai_disp1_pdata,
549         },
550 };
551
552 static int kai_disp1_check_fb(struct device *dev, struct fb_info *info)
553 {
554         return info->device == &kai_disp1_device.dev;
555 }
556
557 static struct nvhost_device kai_disp2_device = {
558         .name           = "tegradc",
559         .id             = 1,
560         .resource       = kai_disp2_resources,
561         .num_resources  = ARRAY_SIZE(kai_disp2_resources),
562         .dev = {
563                 .platform_data = &kai_disp2_pdata,
564         },
565 };
566 #else
567 static int kai_disp1_check_fb(struct device *dev, struct fb_info *info)
568 {
569         return 0;
570 }
571 #endif
572
573 #if defined(CONFIG_TEGRA_NVMAP)
574 static struct nvmap_platform_carveout kai_carveouts[] = {
575         [0] = NVMAP_HEAP_CARVEOUT_IRAM_INIT,
576         [1] = {
577                 .name           = "generic-0",
578                 .usage_mask     = NVMAP_HEAP_CARVEOUT_GENERIC,
579                 .base           = 0,    /* Filled in by kai_panel_init() */
580                 .size           = 0,    /* Filled in by kai_panel_init() */
581                 .buddy_size     = SZ_32K,
582         },
583 };
584
585 static struct nvmap_platform_data kai_nvmap_data = {
586         .carveouts      = kai_carveouts,
587         .nr_carveouts   = ARRAY_SIZE(kai_carveouts),
588 };
589
590 static struct platform_device kai_nvmap_device = {
591         .name   = "tegra-nvmap",
592         .id     = -1,
593         .dev    = {
594                 .platform_data = &kai_nvmap_data,
595         },
596 };
597 #endif
598
599 static struct platform_device *kai_gfx_devices[] __initdata = {
600 #if defined(CONFIG_TEGRA_NVMAP)
601         &kai_nvmap_device,
602 #endif
603         &tegra_pwfm0_device,
604         &kai_backlight_device,
605 };
606
607
608 #ifdef CONFIG_HAS_EARLYSUSPEND
609 /* put early_suspend/late_resume handlers here for the display in order
610  * to keep the code out of the display driver, keeping it closer to upstream
611  */
612 struct early_suspend kai_panel_early_suspender;
613
614 static void kai_panel_early_suspend(struct early_suspend *h)
615 {
616         /* power down LCD, add use a black screen for HDMI */
617         if (num_registered_fb > 0)
618                 fb_blank(registered_fb[0], FB_BLANK_POWERDOWN);
619         if (num_registered_fb > 1)
620                 fb_blank(registered_fb[1], FB_BLANK_NORMAL);
621 #ifdef CONFIG_TEGRA_CONVSERVATIVE_GOV_ON_EARLYSUPSEND
622         cpufreq_store_default_gov();
623         if (cpufreq_change_gov(cpufreq_conservative_gov))
624                 pr_err("Early_suspend: Error changing governor to %s\n",
625                                 cpufreq_conservative_gov);
626 #endif
627 }
628
629 static void kai_panel_late_resume(struct early_suspend *h)
630 {
631         unsigned i;
632 #ifdef CONFIG_TEGRA_CONVSERVATIVE_GOV_ON_EARLYSUPSEND
633         if (cpufreq_restore_default_gov())
634                 pr_err("Early_suspend: Unable to restore governor\n");
635 #endif
636         for (i = 0; i < num_registered_fb; i++)
637                 fb_blank(registered_fb[i], FB_BLANK_UNBLANK);
638 }
639 #endif
640
641 int __init kai_panel_init(void)
642 {
643         int err;
644         struct resource __maybe_unused *res;
645         struct board_info board_info;
646
647         tegra_get_board_info(&board_info);
648
649 #if defined(CONFIG_TEGRA_NVMAP)
650         kai_carveouts[1].base = tegra_carveout_start;
651         kai_carveouts[1].size = tegra_carveout_size;
652 #endif
653         gpio_request(kai_lvds_avdd_en, "lvds_avdd_en");
654         gpio_direction_output(kai_lvds_avdd_en, 1);
655
656         gpio_request(kai_lvds_stdby, "lvds_stdby");
657         gpio_direction_output(kai_lvds_stdby, 1);
658
659         gpio_request(kai_lvds_rst, "lvds_rst");
660         gpio_direction_output(kai_lvds_rst, 1);
661
662         if (board_info.fab == BOARD_FAB_A00) {
663                 gpio_request(kai_lvds_rs_a00, "lvds_rs");
664                 gpio_direction_output(kai_lvds_rs_a00, 0);
665         } else {
666                 gpio_request(kai_lvds_rs, "lvds_rs");
667                 gpio_direction_output(kai_lvds_rs, 0);
668         }
669
670         gpio_request(kai_lvds_lr, "lvds_lr");
671         gpio_direction_output(kai_lvds_lr, 1);
672
673         gpio_request(kai_lvds_shutdown, "lvds_shutdown");
674         gpio_direction_output(kai_lvds_shutdown, 1);
675
676         gpio_request(kai_hdmi_hpd, "hdmi_hpd");
677         gpio_direction_input(kai_hdmi_hpd);
678
679 #ifdef CONFIG_HAS_EARLYSUSPEND
680         kai_panel_early_suspender.suspend = kai_panel_early_suspend;
681         kai_panel_early_suspender.resume = kai_panel_late_resume;
682         kai_panel_early_suspender.level = EARLY_SUSPEND_LEVEL_DISABLE_FB;
683         register_early_suspend(&kai_panel_early_suspender);
684 #endif
685
686 #ifdef CONFIG_TEGRA_GRHOST
687         err = nvhost_device_register(&tegra_grhost_device);
688         if (err)
689                 return err;
690 #endif
691
692         err = platform_add_devices(kai_gfx_devices,
693                                 ARRAY_SIZE(kai_gfx_devices));
694
695 #if defined(CONFIG_TEGRA_GRHOST) && defined(CONFIG_TEGRA_DC)
696         res = nvhost_get_resource_byname(&kai_disp1_device,
697                                          IORESOURCE_MEM, "fbmem");
698         res->start = tegra_fb_start;
699         res->end = tegra_fb_start + tegra_fb_size - 1;
700 #endif
701
702         /* Copy the bootloader fb to the fb. */
703         tegra_move_framebuffer(tegra_fb_start, tegra_bootloader_fb_start,
704                                 min(tegra_fb_size, tegra_bootloader_fb_size));
705
706 #if defined(CONFIG_TEGRA_GRHOST) && defined(CONFIG_TEGRA_DC)
707         if (!err)
708                 err = nvhost_device_register(&kai_disp1_device);
709
710         res = nvhost_get_resource_byname(&kai_disp2_device,
711                                          IORESOURCE_MEM, "fbmem");
712         res->start = tegra_fb2_start;
713         res->end = tegra_fb2_start + tegra_fb2_size - 1;
714         if (!err)
715                 err = nvhost_device_register(&kai_disp2_device);
716 #endif
717
718 #if defined(CONFIG_TEGRA_GRHOST) && defined(CONFIG_TEGRA_NVAVP)
719         if (!err)
720                 err = nvhost_device_register(&nvavp_device);
721 #endif
722         return err;
723 }