bfefa25d7b302133e1cc1bef8ebf5faaecddc86d
[linux-2.6.git] / arch / arm / mach-tegra / board-dalmore-panel.c
1 /*
2  * arch/arm/mach-tegra/board-dalmore-panel.c
3  *
4  * Copyright (c) 2011-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 as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19  */
20 #include <linux/ioport.h>
21 #include <linux/fb.h>
22 #include <linux/nvmap.h>
23 #include <linux/nvhost.h>
24 #include <linux/init.h>
25 #include <linux/delay.h>
26 #include <linux/gpio.h>
27 #include <linux/tegra_pwm_bl.h>
28 #include <linux/regulator/consumer.h>
29
30 #include <mach/irqs.h>
31 #include <mach/iomap.h>
32 #include <mach/dc.h>
33
34 #include "board.h"
35 #include "devices.h"
36 #include "gpio-names.h"
37 #ifdef CONFIG_ARCH_TEGRA_3x_SOC
38 #include "tegra3_host1x_devices.h"
39 #else
40 #include "tegra11_host1x_devices.h"
41 #endif
42
43 #define TEGRA_PANEL_ENABLE      1
44
45 #if TEGRA_PANEL_ENABLE
46
47 #define TEGRA_DSI_GANGED_MODE   0
48 #define IS_EXTERNAL_PWM         1
49
50 /* PANEL_<diagonal length in inches>_<vendor name>_<resolution> */
51 #define PANEL_10_1_PANASONIC_1920_1200  1
52 #define PANEL_11_6_AUO_1920_1080        0
53 #define PANEL_10_1_SHARP_2560_1600      0
54
55 #define DSI_PANEL_RESET         1
56 #define DSI_PANEL_RST_GPIO      TEGRA_GPIO_PH3
57 #define DSI_PANEL_BL_EN_GPIO    TEGRA_GPIO_PH2
58
59 #define DC_CTRL_MODE    TEGRA_DC_OUT_CONTINUOUS_MODE
60
61 /* HDMI Hotplug detection pin */
62 #define dalmore_hdmi_hpd        TEGRA_GPIO_PN7
63
64 static atomic_t sd_brightness = ATOMIC_INIT(255);
65
66 static bool reg_requested;
67 static bool gpio_requested;
68
69 /* for PANEL_10_1_PANASONIC_1920_1200, PANEL_11_6_AUO_1920_1080
70  * and PANEL_10_1_SHARP_2560_1600
71  */
72 static struct regulator *avdd_lcd_3v3;
73 static struct regulator *vdd_lcd_bl_12v;
74
75 /* for PANEL_11_6_AUO_1920_1080 and PANEL_10_1_SHARP_2560_1600 */
76 static struct regulator *dvdd_lcd_1v8;
77
78 /* for PANEL_11_6_AUO_1920_1080 */
79 static struct regulator *vdd_ds_1v8;
80 #define en_vdd_bl       TEGRA_GPIO_PG0
81 #define lvds_en         TEGRA_GPIO_PG3
82
83 #ifdef CONFIG_TEGRA_DC
84 static struct regulator *dalmore_hdmi_reg;
85 static struct regulator *dalmore_hdmi_pll;
86 static struct regulator *dalmore_hdmi_vddio;
87 #endif
88
89 static struct resource dalmore_disp1_resources[] = {
90         {
91                 .name   = "irq",
92                 .start  = INT_DISPLAY_GENERAL,
93                 .end    = INT_DISPLAY_GENERAL,
94                 .flags  = IORESOURCE_IRQ,
95         },
96         {
97                 .name   = "regs",
98                 .start  = TEGRA_DISPLAY_BASE,
99                 .end    = TEGRA_DISPLAY_BASE + TEGRA_DISPLAY_SIZE - 1,
100                 .flags  = IORESOURCE_MEM,
101         },
102         {
103                 .name   = "fbmem",
104                 .start  = 0, /* Filled in by dalmore_panel_init() */
105                 .end    = 0, /* Filled in by dalmore_panel_init() */
106                 .flags  = IORESOURCE_MEM,
107         },
108 #if TEGRA_DSI_GANGED_MODE
109         {
110                 .name   = "ganged_dsia_regs",
111                 .start  = TEGRA_DSI_BASE,
112                 .end    = TEGRA_DSI_BASE + TEGRA_DSI_SIZE - 1,
113                 .flags  = IORESOURCE_MEM,
114         },
115         {
116                 .name   = "ganged_dsib_regs",
117                 .start  = TEGRA_DSIB_BASE,
118                 .end    = TEGRA_DSIB_BASE + TEGRA_DSIB_SIZE - 1,
119                 .flags  = IORESOURCE_MEM,
120         },
121 #else
122         {
123                 .name   = "dsi_regs",
124                 .start  = TEGRA_DSI_BASE,
125                 .end    = TEGRA_DSI_BASE + TEGRA_DSI_SIZE - 1,
126                 .flags  = IORESOURCE_MEM,
127         },
128 #endif
129 };
130
131 static struct resource dalmore_disp2_resources[] = {
132         {
133                 .name   = "irq",
134                 .start  = INT_DISPLAY_B_GENERAL,
135                 .end    = INT_DISPLAY_B_GENERAL,
136                 .flags  = IORESOURCE_IRQ,
137         },
138         {
139                 .name   = "regs",
140                 .start  = TEGRA_DISPLAY2_BASE,
141                 .end    = TEGRA_DISPLAY2_BASE + TEGRA_DISPLAY2_SIZE - 1,
142                 .flags  = IORESOURCE_MEM,
143         },
144         {
145                 .name   = "fbmem",
146                 .start  = 0, /* Filled in by dalmore_panel_init() */
147                 .end    = 0, /* Filled in by dalmore_panel_init() */
148                 .flags  = IORESOURCE_MEM,
149         },
150         {
151                 .name   = "hdmi_regs",
152                 .start  = TEGRA_HDMI_BASE,
153                 .end    = TEGRA_HDMI_BASE + TEGRA_HDMI_SIZE - 1,
154                 .flags  = IORESOURCE_MEM,
155         },
156 };
157
158 static struct tegra_dsi_cmd dsi_init_cmd[] = {
159 #if PANEL_10_1_PANASONIC_1920_1200
160         /* no init command required */
161 #endif
162 #if PANEL_11_6_AUO_1920_1080
163         /* no init command required */
164 #endif
165 #if PANEL_10_1_SHARP_2560_1600
166         /* TODO */
167 #endif
168 };
169
170 static struct tegra_dsi_out dalmore_dsi = {
171 #ifdef CONFIG_ARCH_TEGRA_3x_SOC
172         .n_data_lanes = 2,
173         .controller_vs = DSI_VS_0,
174 #else
175         .n_data_lanes = 4,
176         .controller_vs = DSI_VS_1,
177 #endif
178 #if PANEL_11_6_AUO_1920_1080
179         .dsi2edp_bridge_enable = true,
180 #endif
181         .pixel_format = TEGRA_DSI_PIXEL_FORMAT_24BIT_P,
182         .refresh_rate = 59,
183         .virtual_channel = TEGRA_DSI_VIRTUAL_CHANNEL_0,
184
185         .dsi_instance = DSI_INSTANCE_0,
186
187         .panel_reset = DSI_PANEL_RESET,
188         .power_saving_suspend = true,
189 #ifdef CONFIG_ARCH_TEGRA_3x_SOC
190         .video_data_type = TEGRA_DSI_VIDEO_TYPE_COMMAND_MODE,
191 #else
192         .video_data_type = TEGRA_DSI_VIDEO_TYPE_VIDEO_MODE,
193         .video_clock_mode = TEGRA_DSI_VIDEO_CLOCK_TX_ONLY,
194         .video_burst_mode = TEGRA_DSI_VIDEO_NONE_BURST_MODE_WITH_SYNC_END,
195 #endif
196         .dsi_init_cmd = dsi_init_cmd,
197         .n_init_cmd = ARRAY_SIZE(dsi_init_cmd),
198 };
199
200 static int dalmore_dsi_regulator_get(struct device *dev)
201 {
202         int err = 0;
203
204         if (reg_requested)
205                 return 0;
206
207 #if PANEL_11_6_AUO_1920_1080 || \
208         PANEL_10_1_SHARP_2560_1600
209         dvdd_lcd_1v8 = regulator_get(dev, "dvdd_lcd");
210         if (IS_ERR_OR_NULL(dvdd_lcd_1v8)) {
211                 pr_err("dvdd_lcd regulator get failed\n");
212                 err = PTR_ERR(dvdd_lcd_1v8);
213                 dvdd_lcd_1v8 = NULL;
214                 goto fail;
215         }
216 #endif
217 #if PANEL_11_6_AUO_1920_1080
218         vdd_ds_1v8 = regulator_get(dev, "vdd_ds_1v8");
219         if (IS_ERR_OR_NULL(vdd_ds_1v8)) {
220                 pr_err("vdd_ds_1v8 regulator get failed\n");
221                 err = PTR_ERR(vdd_ds_1v8);
222                 vdd_ds_1v8 = NULL;
223                 goto fail;
224         }
225 #endif
226 #if PANEL_10_1_PANASONIC_1920_1200 || \
227         PANEL_11_6_AUO_1920_1080 || \
228         PANEL_10_1_SHARP_2560_1600
229         avdd_lcd_3v3 = regulator_get(dev, "avdd_lcd");
230         if (IS_ERR_OR_NULL(avdd_lcd_3v3)) {
231                 pr_err("avdd_lcd regulator get failed\n");
232                 err = PTR_ERR(avdd_lcd_3v3);
233                 avdd_lcd_3v3 = NULL;
234                 goto fail;
235         }
236
237         vdd_lcd_bl_12v = regulator_get(dev, "vdd_lcd_bl");
238         if (IS_ERR_OR_NULL(vdd_lcd_bl_12v)) {
239                 pr_err("vdd_lcd_bl regulator get failed\n");
240                 err = PTR_ERR(vdd_lcd_bl_12v);
241                 vdd_lcd_bl_12v = NULL;
242                 goto fail;
243         }
244 #endif
245         reg_requested = true;
246         return 0;
247 fail:
248         return err;
249 }
250
251 static int dalmore_dsi_gpio_get(void)
252 {
253         int err = 0;
254
255         if (gpio_requested)
256                 return 0;
257
258         err = gpio_request(DSI_PANEL_RST_GPIO, "panel rst");
259         if (err < 0) {
260                 pr_err("panel reset gpio request failed\n");
261                 goto fail;
262         }
263
264         err = gpio_request(DSI_PANEL_BL_EN_GPIO, "panel backlight");
265         if (err < 0) {
266                 pr_err("panel backlight gpio request failed\n");
267                 goto fail;
268         }
269
270 #if PANEL_11_6_AUO_1920_1080
271         err = gpio_request(en_vdd_bl, "edp bridge 1v2 enable");
272         if (err < 0) {
273                 pr_err("edp bridge 1v2 enable gpio request failed\n");
274                 goto fail;
275         }
276
277         err = gpio_request(lvds_en, "edp bridge 1v8 enable");
278         if (err < 0) {
279                 pr_err("edp bridge 1v8 enable gpio request failed\n");
280                 goto fail;
281         }
282 #endif
283         gpio_requested = true;
284         return 0;
285 fail:
286         return err;
287 }
288
289 static int dalmore_dsi_panel_enable(struct device *dev)
290 {
291         int err = 0;
292
293         err = dalmore_dsi_regulator_get(dev);
294         if (err < 0) {
295                 pr_err("dsi regulator get failed\n");
296                 goto fail;
297         }
298         err = dalmore_dsi_gpio_get();
299         if (err < 0) {
300                 pr_err("dsi gpio request failed\n");
301                 goto fail;
302         }
303
304         if (vdd_ds_1v8) {
305                 err = regulator_enable(vdd_ds_1v8);
306                 if (err < 0) {
307                         pr_err("vdd_ds_1v8 regulator enable failed\n");
308                         goto fail;
309                 }
310         }
311
312         if (dvdd_lcd_1v8) {
313                 err = regulator_enable(dvdd_lcd_1v8);
314                 if (err < 0) {
315                         pr_err("dvdd_lcd regulator enable failed\n");
316                         goto fail;
317                 }
318         }
319
320         if (avdd_lcd_3v3) {
321                 err = regulator_enable(avdd_lcd_3v3);
322                 if (err < 0) {
323                         pr_err("avdd_lcd regulator enable failed\n");
324                         goto fail;
325                 }
326         }
327
328         if (vdd_lcd_bl_12v) {
329                 err = regulator_enable(vdd_lcd_bl_12v);
330                 if (err < 0) {
331                         pr_err("vdd_lcd_bl regulator enable failed\n");
332                         goto fail;
333                 }
334         }
335
336         msleep(100);
337 #if DSI_PANEL_RESET
338         gpio_direction_output(DSI_PANEL_RST_GPIO, 1);
339         usleep_range(1000, 5000);
340         gpio_set_value(DSI_PANEL_RST_GPIO, 0);
341         msleep(150);
342         gpio_set_value(DSI_PANEL_RST_GPIO, 1);
343         msleep(1500);
344 #endif
345
346         gpio_direction_output(DSI_PANEL_BL_EN_GPIO, 1);
347         gpio_direction_output(57, 1);
348
349 #if PANEL_11_6_AUO_1920_1080
350         gpio_direction_output(en_vdd_bl, 1);
351         msleep(100);
352         gpio_direction_output(lvds_en, 1);
353 #endif
354         return 0;
355 fail:
356         return err;
357 }
358
359 static int dalmore_dsi_panel_disable(void)
360 {
361         gpio_set_value(DSI_PANEL_BL_EN_GPIO, 0);
362
363 #if PANEL_11_6_AUO_1920_1080
364         gpio_set_value(lvds_en, 0);
365         msleep(100);
366         gpio_set_value(en_vdd_bl, 0);
367 #endif
368         if (vdd_lcd_bl_12v)
369                 regulator_disable(vdd_lcd_bl_12v);
370
371         if (avdd_lcd_3v3)
372                 regulator_disable(avdd_lcd_3v3);
373
374         if (dvdd_lcd_1v8)
375                 regulator_disable(dvdd_lcd_1v8);
376
377         if (vdd_ds_1v8)
378                 regulator_disable(vdd_ds_1v8);
379
380         return 0;
381 }
382
383 static int dalmore_dsi_panel_postsuspend(void)
384 {
385         return 0;
386 }
387
388 static struct tegra_dc_mode dalmore_dsi_modes[] = {
389 #if PANEL_10_1_PANASONIC_1920_1200
390         {
391                 .pclk = 10000000,
392                 .h_ref_to_sync = 4,
393                 .v_ref_to_sync = 1,
394                 .h_sync_width = 16,
395                 .v_sync_width = 2,
396                 .h_back_porch = 32,
397                 .v_back_porch = 16,
398                 .h_active = 1920,
399                 .v_active = 1200,
400                 .h_front_porch = 120,
401                 .v_front_porch = 17,
402         },
403 #endif
404 #if PANEL_11_6_AUO_1920_1080
405         {
406                 .pclk = 10000000,
407                 .h_ref_to_sync = 4,
408                 .v_ref_to_sync = 1,
409                 .h_sync_width = 28,
410                 .v_sync_width = 5,
411                 .h_back_porch = 148,
412                 .v_back_porch = 23,
413                 .h_active = 1920,
414                 .v_active = 1080,
415                 .h_front_porch = 66,
416                 .v_front_porch = 4,
417         },
418 #endif
419 #if PANEL_10_1_SHARP_2560_1600
420         {
421                 .pclk = 10000000,
422                 .h_ref_to_sync = 4,
423                 .v_ref_to_sync = 1,
424                 .h_sync_width = 16,
425                 .v_sync_width = 2,
426                 .h_back_porch = 16,
427                 .v_back_porch = 33,
428                 .h_active = 2560,
429                 .v_active = 1600,
430                 .h_front_porch = 128,
431                 .v_front_porch = 10,
432         },
433 #endif
434 };
435
436 static struct tegra_dc_out dalmore_disp1_out = {
437         .type           = TEGRA_DC_OUT_DSI,
438         .dsi            = &dalmore_dsi,
439
440         .flags          = DC_CTRL_MODE,
441
442         .modes          = dalmore_dsi_modes,
443         .n_modes        = ARRAY_SIZE(dalmore_dsi_modes),
444
445         .enable         = dalmore_dsi_panel_enable,
446         .disable        = dalmore_dsi_panel_disable,
447         .postsuspend    = dalmore_dsi_panel_postsuspend,
448
449 #if PANEL_10_1_PANASONIC_1920_1200
450         .width          = 217,
451         .height         = 135,
452 #endif
453 #if PANEL_11_6_AUO_1920_1080
454         .width          = 256,
455         .height         = 144,
456 #endif
457 #if PANEL_10_1_SHARP_2560_1600
458         .width          = 216,
459         .height         = 135,
460 #endif
461 };
462
463 static int dalmore_hdmi_enable(struct device *dev)
464 {
465         int ret;
466         if (!dalmore_hdmi_reg) {
467                         dalmore_hdmi_reg = regulator_get(dev, "avdd_hdmi");
468                         if (IS_ERR_OR_NULL(dalmore_hdmi_reg)) {
469                                 pr_err("hdmi: couldn't get regulator avdd_hdmi\n");
470                                 dalmore_hdmi_reg = NULL;
471                                 return PTR_ERR(dalmore_hdmi_reg);
472                         }
473         }
474         ret = regulator_enable(dalmore_hdmi_reg);
475         if (ret < 0) {
476                 pr_err("hdmi: couldn't enable regulator avdd_hdmi\n");
477                 return ret;
478         }
479         if (!dalmore_hdmi_pll) {
480                 dalmore_hdmi_pll = regulator_get(dev, "avdd_hdmi_pll");
481                 if (IS_ERR_OR_NULL(dalmore_hdmi_pll)) {
482                         pr_err("hdmi: couldn't get regulator avdd_hdmi_pll\n");
483                         dalmore_hdmi_pll = NULL;
484                         regulator_put(dalmore_hdmi_reg);
485                         dalmore_hdmi_reg = NULL;
486                         return PTR_ERR(dalmore_hdmi_pll);
487                 }
488         }
489         ret = regulator_enable(dalmore_hdmi_pll);
490         if (ret < 0) {
491                 pr_err("hdmi: couldn't enable regulator avdd_hdmi_pll\n");
492                 return ret;
493         }
494         return 0;
495 }
496
497 static int dalmore_hdmi_disable(void)
498 {
499         if (dalmore_hdmi_reg) {
500                 regulator_disable(dalmore_hdmi_reg);
501                 regulator_put(dalmore_hdmi_reg);
502                 dalmore_hdmi_reg = NULL;
503         }
504
505         if (dalmore_hdmi_pll) {
506                 regulator_disable(dalmore_hdmi_pll);
507                 regulator_put(dalmore_hdmi_pll);
508                 dalmore_hdmi_pll = NULL;
509         }
510
511         return 0;
512 }
513
514 static int dalmore_hdmi_postsuspend(void)
515 {
516         if (dalmore_hdmi_vddio) {
517                 regulator_disable(dalmore_hdmi_vddio);
518                 regulator_put(dalmore_hdmi_vddio);
519                 dalmore_hdmi_vddio = NULL;
520         }
521         return 0;
522 }
523
524 static int dalmore_hdmi_hotplug_init(struct device *dev)
525 {
526         if (!dalmore_hdmi_vddio) {
527                 dalmore_hdmi_vddio = regulator_get(dev, "vdd_hdmi_5v0");
528                 if (WARN_ON(IS_ERR(dalmore_hdmi_vddio))) {
529                         pr_err("%s: couldn't get regulator vdd_hdmi_5v0: %ld\n",
530                                 __func__, PTR_ERR(dalmore_hdmi_vddio));
531                                 dalmore_hdmi_vddio = NULL;
532                 } else {
533                         regulator_enable(dalmore_hdmi_vddio);
534                 }
535         }
536
537         return 0;
538 }
539
540 static struct tegra_dc_out dalmore_disp2_out = {
541         .type           = TEGRA_DC_OUT_HDMI,
542         .flags          = TEGRA_DC_OUT_HOTPLUG_HIGH,
543         .parent_clk     = "pll_d2_out0",
544
545         .dcc_bus        = 3,
546         .hotplug_gpio   = dalmore_hdmi_hpd,
547
548         .max_pixclock   = KHZ2PICOS(148500),
549
550         .align          = TEGRA_DC_ALIGN_MSB,
551         .order          = TEGRA_DC_ORDER_RED_BLUE,
552
553         .enable         = dalmore_hdmi_enable,
554         .disable        = dalmore_hdmi_disable,
555         .postsuspend    = dalmore_hdmi_postsuspend,
556         .hotplug_init   = dalmore_hdmi_hotplug_init,
557 };
558
559 static struct tegra_fb_data dalmore_disp1_fb_data = {
560         .win            = 0,
561         .bits_per_pixel = 32,
562         .flags          = TEGRA_FB_FLIP_ON_PROBE,
563 #if PANEL_10_1_PANASONIC_1920_1200
564         .xres           = 1920,
565         .yres           = 1200,
566 #endif
567 #if PANEL_11_6_AUO_1920_1080
568         .xres           = 1920,
569         .yres           = 1080,
570 #endif
571 #if PANEL_10_1_SHARP_2560_1600
572         .xres           = 2560,
573         .yres           = 1600,
574 #endif
575 };
576
577 static struct tegra_dc_platform_data dalmore_disp1_pdata = {
578         .flags          = TEGRA_DC_FLAG_ENABLED,
579         .default_out    = &dalmore_disp1_out,
580         .fb             = &dalmore_disp1_fb_data,
581         .emc_clk_rate   = 204000000,
582 };
583
584 static struct tegra_fb_data dalmore_disp2_fb_data = {
585         .win            = 0,
586         .xres           = 1024,
587         .yres           = 600,
588         .bits_per_pixel = 32,
589         .flags          = TEGRA_FB_FLIP_ON_PROBE,
590 };
591
592 static struct tegra_dc_platform_data dalmore_disp2_pdata = {
593         .flags          = TEGRA_DC_FLAG_ENABLED,
594         .default_out    = &dalmore_disp2_out,
595         .fb             = &dalmore_disp2_fb_data,
596         .emc_clk_rate   = 300000000,
597 };
598
599 static struct nvhost_device dalmore_disp2_device = {
600         .name           = "tegradc",
601         .id             = 1,
602         .resource       = dalmore_disp2_resources,
603         .num_resources  = ARRAY_SIZE(dalmore_disp2_resources),
604         .dev = {
605                 .platform_data = &dalmore_disp2_pdata,
606         },
607 };
608
609 static struct nvhost_device dalmore_disp1_device = {
610         .name           = "tegradc",
611         .id             = 0,
612         .resource       = dalmore_disp1_resources,
613         .num_resources  = ARRAY_SIZE(dalmore_disp1_resources),
614         .dev = {
615                 .platform_data = &dalmore_disp1_pdata,
616         },
617 };
618
619 static struct nvmap_platform_carveout dalmore_carveouts[] = {
620         [0] = {
621                 .name           = "iram",
622                 .usage_mask     = NVMAP_HEAP_CARVEOUT_IRAM,
623                 .base           = TEGRA_IRAM_BASE + TEGRA_RESET_HANDLER_SIZE,
624                 .size           = TEGRA_IRAM_SIZE - TEGRA_RESET_HANDLER_SIZE,
625                 .buddy_size     = 0, /* no buddy allocation for IRAM */
626         },
627         [1] = {
628                 .name           = "generic-0",
629                 .usage_mask     = NVMAP_HEAP_CARVEOUT_GENERIC,
630                 .base           = 0, /* Filled in by dalmore_panel_init() */
631                 .size           = 0, /* Filled in by dalmore_panel_init() */
632                 .buddy_size     = SZ_32K,
633         },
634         [2] = {
635                 .name           = "vpr",
636                 .usage_mask     = NVMAP_HEAP_CARVEOUT_VPR,
637                 .base           = 0, /* Filled in by dalmore_panel_init() */
638                 .size           = 0, /* Filled in by dalmore_panel_init() */
639                 .buddy_size     = SZ_32K,
640         },
641 };
642
643 static struct nvmap_platform_data dalmore_nvmap_data = {
644         .carveouts      = dalmore_carveouts,
645         .nr_carveouts   = ARRAY_SIZE(dalmore_carveouts),
646 };
647
648 static struct platform_device dalmore_nvmap_device __initdata = {
649         .name   = "tegra-nvmap",
650         .id     = -1,
651         .dev    = {
652                 .platform_data = &dalmore_nvmap_data,
653         },
654 };
655
656 static int dalmore_disp1_bl_notify(struct device *unused, int brightness)
657 {
658         int cur_sd_brightness = atomic_read(&sd_brightness);
659
660         /* SD brightness is a percentage */
661         brightness = (brightness * cur_sd_brightness) / 255;
662
663         /* Apply any backlight response curve */
664         if (brightness > 255)
665                 pr_info("Error: Brightness > 255!\n");
666         else
667                 /* TODO: backlight response LUT */
668                 brightness = brightness;
669
670         return brightness;
671 }
672
673 static int dalmore_disp1_check_fb(struct device *dev, struct fb_info *info)
674 {
675         return info->device == &dalmore_disp1_device.dev;
676 }
677
678 static struct platform_tegra_pwm_backlight_data dalmore_disp1_bl_data = {
679         .which_dc               = 0,
680         .which_pwm              = TEGRA_PWM_PM1,
681         .gpio_conf_to_sfio      = TEGRA_GPIO_PH1,
682         .max_brightness         = 255,
683         .dft_brightness         = 224,
684         .notify                 = dalmore_disp1_bl_notify,
685         .period                 = 0x3F,
686         .clk_div                = 0x3FF,
687         .clk_select             = 0,
688         /* Only toggle backlight on fb blank notifications for disp1 */
689         .check_fb               = dalmore_disp1_check_fb,
690 };
691
692 static struct platform_device __maybe_unused
693                 dalmore_disp1_bl_device __initdata = {
694         .name   = "tegra-pwm-bl",
695         .id     = -1,
696         .dev    = {
697                 .platform_data = &dalmore_disp1_bl_data,
698         },
699 };
700
701 #if PANEL_11_6_AUO_1920_1080
702 static struct i2c_board_info dalmore_tc358770_dsi2edp_board_info __initdata = {
703                 I2C_BOARD_INFO("tc358770_dsi2edp", 0x68),
704 };
705 #endif
706
707 int __init dalmore_panel_init(void)
708 {
709         int err = 0;
710         struct resource __maybe_unused *res;
711
712 #ifdef CONFIG_TEGRA_NVMAP
713         dalmore_carveouts[1].base = tegra_carveout_start;
714         dalmore_carveouts[1].size = tegra_carveout_size;
715         dalmore_carveouts[2].base = tegra_vpr_start;
716         dalmore_carveouts[2].size = tegra_vpr_size;
717
718         err = platform_device_register(&dalmore_nvmap_device);
719         if (err) {
720                 pr_err("nvmap device registration failed\n");
721                 return err;
722         }
723 #endif
724
725         gpio_request(dalmore_hdmi_hpd, "hdmi_hpd");
726         gpio_direction_input(dalmore_hdmi_hpd);
727
728 #ifdef CONFIG_TEGRA_GRHOST
729 #ifdef CONFIG_ARCH_TEGRA_3x_SOC
730         err = tegra3_register_host1x_devices();
731 #else
732         err = tegra11_register_host1x_devices();
733 #endif
734         if (err) {
735                 pr_err("host1x devices registration failed\n");
736                 return err;
737         }
738
739 #ifdef CONFIG_TEGRA_DC
740         res = nvhost_get_resource_byname(&dalmore_disp1_device,
741                                          IORESOURCE_MEM, "fbmem");
742         res->start = tegra_fb_start;
743         res->end = tegra_fb_start + tegra_fb_size - 1;
744
745         res = nvhost_get_resource_byname(&dalmore_disp2_device,
746                                          IORESOURCE_MEM, "fbmem");
747         res->start = tegra_fb2_start;
748         res->end = tegra_fb2_start + tegra_fb2_size - 1;
749
750         err = nvhost_device_register(&dalmore_disp1_device);
751         if (err) {
752                 pr_err("disp1 device registration failed\n");
753                 return err;
754         }
755
756         err = nvhost_device_register(&dalmore_disp2_device);
757         if (err) {
758                 pr_err("disp2 device registration failed\n");
759                 return err;
760         }
761
762 #if !IS_EXTERNAL_PWM
763         err = platform_device_register(&dalmore_disp1_bl_device);
764         if (err) {
765                 pr_err("disp1 bl device registration failed");
766                 return err;
767         }
768 #endif
769 #if PANEL_11_6_AUO_1920_1080
770         i2c_register_board_info(0, &dalmore_tc358770_dsi2edp_board_info, 1);
771 #endif
772 #endif
773
774 #ifdef CONFIG_TEGRA_NVAVP
775         err = nvhost_device_register(&nvavp_device);
776         if (err) {
777                 pr_err("nvavp device registration failed\n");
778                 return err;
779         }
780 #endif
781 #endif
782         return err;
783 }
784 #else
785 int __init dalmore_panel_init(void)
786 {
787         return -ENODEV;
788 }
789 #endif