471814efb79d8701838da353774d7ada38245fee
[linux-3.10.git] / arch / arm / mach-tegra / board-dalmore-panel.c
1 /*
2  * arch/arm/mach-tegra/board-dalmore-panel.c
3  *
4  * Copyright (c) 2011-2013, 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 #include <linux/pwm_backlight.h>
30 #include <linux/of.h>
31
32 #include <mach/irqs.h>
33 #include <mach/dc.h>
34
35 #include "board.h"
36 #include "devices.h"
37 #include "gpio-names.h"
38 #include "board-panel.h"
39 #include "common.h"
40 #include "iomap.h"
41 #include "tegra11_host1x_devices.h"
42
43 #define DSI_PANEL_RST_GPIO      TEGRA_GPIO_PH3
44 #define DSI_PANEL_BL_PWM_GPIO   TEGRA_GPIO_PH1
45
46 struct platform_device * __init dalmore_host1x_init(void)
47 {
48         struct platform_device *pdev = NULL;
49
50 #ifdef CONFIG_TEGRA_GRHOST
51         if (!of_have_populated_dt())
52                 pdev = tegra11_register_host1x_devices();
53         else
54                 pdev = to_platform_device(bus_find_device_by_name(
55                         &platform_bus_type, NULL, "host1x"));
56 #endif
57         return pdev;
58 }
59
60 #ifdef CONFIG_TEGRA_DC
61
62 /* HDMI Hotplug detection pin */
63 #define dalmore_hdmi_hpd        TEGRA_GPIO_PN7
64
65 static struct regulator *dalmore_hdmi_reg;
66 static struct regulator *dalmore_hdmi_pll;
67 static struct regulator *dalmore_hdmi_vddio;
68
69 static struct resource dalmore_disp1_resources[] = {
70         {
71                 .name   = "irq",
72                 .start  = INT_DISPLAY_GENERAL,
73                 .end    = INT_DISPLAY_GENERAL,
74                 .flags  = IORESOURCE_IRQ,
75         },
76         {
77                 .name   = "regs",
78                 .start  = TEGRA_DISPLAY_BASE,
79                 .end    = TEGRA_DISPLAY_BASE + TEGRA_DISPLAY_SIZE - 1,
80                 .flags  = IORESOURCE_MEM,
81         },
82         {
83                 .name   = "fbmem",
84                 .start  = 0, /* Filled in by dalmore_panel_init() */
85                 .end    = 0, /* Filled in by dalmore_panel_init() */
86                 .flags  = IORESOURCE_MEM,
87         },
88         {
89                 .name   = "ganged_dsia_regs",
90                 .start  = 0, /* Filled in the panel file by init_resources() */
91                 .end    = 0, /* Filled in the panel file by init_resources() */
92                 .flags  = IORESOURCE_MEM,
93         },
94         {
95                 .name   = "ganged_dsib_regs",
96                 .start  = 0, /* Filled in the panel file by init_resources() */
97                 .end    = 0, /* Filled in the panel file by init_resources() */
98                 .flags  = IORESOURCE_MEM,
99         },
100         {
101                 .name   = "dsi_regs",
102                 .start  = 0, /* Filled in the panel file by init_resources() */
103                 .end    = 0, /* Filled in the panel file by init_resources() */
104                 .flags  = IORESOURCE_MEM,
105         },
106         {
107                 .name   = "mipi_cal",
108                 .start  = TEGRA_MIPI_CAL_BASE,
109                 .end    = TEGRA_MIPI_CAL_BASE + TEGRA_MIPI_CAL_SIZE - 1,
110                 .flags  = IORESOURCE_MEM,
111         },
112 };
113
114 static struct resource dalmore_disp2_resources[] = {
115         {
116                 .name   = "irq",
117                 .start  = INT_DISPLAY_B_GENERAL,
118                 .end    = INT_DISPLAY_B_GENERAL,
119                 .flags  = IORESOURCE_IRQ,
120         },
121         {
122                 .name   = "regs",
123                 .start  = TEGRA_DISPLAY2_BASE,
124                 .end    = TEGRA_DISPLAY2_BASE + TEGRA_DISPLAY2_SIZE - 1,
125                 .flags  = IORESOURCE_MEM,
126         },
127         {
128                 .name   = "fbmem",
129                 .start  = 0, /* Filled in by dalmore_panel_init() */
130                 .end    = 0, /* Filled in by dalmore_panel_init() */
131                 .flags  = IORESOURCE_MEM,
132         },
133         {
134                 .name   = "hdmi_regs",
135                 .start  = TEGRA_HDMI_BASE,
136                 .end    = TEGRA_HDMI_BASE + TEGRA_HDMI_SIZE - 1,
137                 .flags  = IORESOURCE_MEM,
138         },
139 };
140
141
142 static struct tegra_dc_sd_settings sd_settings;
143
144 static struct tegra_dc_out dalmore_disp1_out = {
145         .type           = TEGRA_DC_OUT_DSI,
146         .sd_settings    = &sd_settings,
147 };
148
149 static int dalmore_hdmi_enable(struct device *dev)
150 {
151         int ret;
152         if (!dalmore_hdmi_reg) {
153                 dalmore_hdmi_reg = regulator_get(dev, "avdd_hdmi");
154                 if (IS_ERR_OR_NULL(dalmore_hdmi_reg)) {
155                         pr_err("hdmi: couldn't get regulator avdd_hdmi\n");
156                         dalmore_hdmi_reg = NULL;
157                         return PTR_ERR(dalmore_hdmi_reg);
158                 }
159         }
160         ret = regulator_enable(dalmore_hdmi_reg);
161         if (ret < 0) {
162                 pr_err("hdmi: couldn't enable regulator avdd_hdmi\n");
163                 return ret;
164         }
165         if (!dalmore_hdmi_pll) {
166                 dalmore_hdmi_pll = regulator_get(dev, "avdd_hdmi_pll");
167                 if (IS_ERR_OR_NULL(dalmore_hdmi_pll)) {
168                         pr_err("hdmi: couldn't get regulator avdd_hdmi_pll\n");
169                         dalmore_hdmi_pll = NULL;
170                         regulator_put(dalmore_hdmi_reg);
171                         dalmore_hdmi_reg = NULL;
172                         return PTR_ERR(dalmore_hdmi_pll);
173                 }
174         }
175         ret = regulator_enable(dalmore_hdmi_pll);
176         if (ret < 0) {
177                 pr_err("hdmi: couldn't enable regulator avdd_hdmi_pll\n");
178                 return ret;
179         }
180         return 0;
181 }
182
183 static int dalmore_hdmi_disable(void)
184 {
185         if (dalmore_hdmi_reg) {
186                 regulator_disable(dalmore_hdmi_reg);
187                 regulator_put(dalmore_hdmi_reg);
188                 dalmore_hdmi_reg = NULL;
189         }
190
191         if (dalmore_hdmi_pll) {
192                 regulator_disable(dalmore_hdmi_pll);
193                 regulator_put(dalmore_hdmi_pll);
194                 dalmore_hdmi_pll = NULL;
195         }
196
197         return 0;
198 }
199
200 static int dalmore_hdmi_postsuspend(void)
201 {
202         if (dalmore_hdmi_vddio) {
203                 regulator_disable(dalmore_hdmi_vddio);
204                 regulator_put(dalmore_hdmi_vddio);
205                 dalmore_hdmi_vddio = NULL;
206         }
207         return 0;
208 }
209
210 static int dalmore_hdmi_hotplug_init(struct device *dev)
211 {
212         if (!dalmore_hdmi_vddio) {
213                 dalmore_hdmi_vddio = regulator_get(dev, "vdd_hdmi_5v0");
214                 if (WARN_ON(IS_ERR(dalmore_hdmi_vddio))) {
215                         pr_err("%s: couldn't get regulator vdd_hdmi_5v0: %ld\n",
216                                 __func__, PTR_ERR(dalmore_hdmi_vddio));
217                                 dalmore_hdmi_vddio = NULL;
218                 } else {
219                         regulator_enable(dalmore_hdmi_vddio);
220                 }
221         }
222
223         return 0;
224 }
225
226 /* Electrical characteristics for HDMI, all modes must be declared here */
227 struct tmds_config dalmore_tmds_config[] = {
228         { /* 480p : 27 MHz and below */
229                 .pclk = 27000000,
230                 .pll0 = 0x01003010,
231                 .pll1 = 0x00301b00,
232                 .drive_current = 0x23232323,
233                 .pe_current = 0x00000000,
234                 .peak_current = 0x00000000,
235         },
236         { /* 720p : 74.25MHz modes */
237                 .pclk = 74250000,
238                 .pll0 = 0x01003110,
239                 .pll1 = 0x00301b00,
240                 .drive_current = 0x25252525,
241                 .pe_current = 0x00000000,
242                 .peak_current = 0x03030303,
243         },
244         { /* 1080p : 148.5MHz modes */
245                 .pclk = 148500000,
246                 .pll0 = 0x01003310,
247                 .pll1 = 0x00301b00,
248                 .drive_current = 0x27272727,
249                 .pe_current = 0x00000000,
250                 .peak_current = 0x03030303,
251         },
252         { /* 4K : 297MHz modes */
253                 .pclk = INT_MAX,
254                 .pll0 = 0x01003f10,
255                 .pll1 = 0x00300f00,
256                 .drive_current = 0x303f3f3f,
257                 .pe_current = 0x00000000,
258                 .peak_current = 0x040f0f0f,
259         },
260 };
261
262 struct tegra_hdmi_out dalmore_hdmi_out = {
263         .tmds_config = dalmore_tmds_config,
264         .n_tmds_config = ARRAY_SIZE(dalmore_tmds_config),
265 };
266
267 static struct tegra_dc_out dalmore_disp2_out = {
268         .type           = TEGRA_DC_OUT_HDMI,
269         .flags          = TEGRA_DC_OUT_HOTPLUG_HIGH,
270         .parent_clk     = "pll_d2_out0",
271
272         .dcc_bus        = 3,
273         .hotplug_gpio   = dalmore_hdmi_hpd,
274         .hdmi_out       = &dalmore_hdmi_out,
275
276         .max_pixclock   = KHZ2PICOS(297000),
277
278         .align          = TEGRA_DC_ALIGN_MSB,
279         .order          = TEGRA_DC_ORDER_RED_BLUE,
280
281         .enable         = dalmore_hdmi_enable,
282         .disable        = dalmore_hdmi_disable,
283         .postsuspend    = dalmore_hdmi_postsuspend,
284         .hotplug_init   = dalmore_hdmi_hotplug_init,
285 };
286
287 static struct tegra_fb_data dalmore_disp1_fb_data = {
288         .win            = 0,
289         .bits_per_pixel = 32,
290         .flags          = TEGRA_FB_FLIP_ON_PROBE,
291 };
292
293 static struct tegra_dc_platform_data dalmore_disp1_pdata = {
294         .flags          = TEGRA_DC_FLAG_ENABLED,
295         .default_out    = &dalmore_disp1_out,
296         .fb             = &dalmore_disp1_fb_data,
297         .emc_clk_rate   = 204000000,
298 #ifdef CONFIG_TEGRA_DC_CMU
299         .cmu_enable     = 1,
300 #endif
301 };
302
303 static struct tegra_fb_data dalmore_disp2_fb_data = {
304         .win            = 0,
305         .xres           = 1280,
306         .yres           = 720,
307         .bits_per_pixel = 32,
308         .flags          = TEGRA_FB_FLIP_ON_PROBE,
309 };
310
311 static struct tegra_dc_platform_data dalmore_disp2_pdata = {
312         .flags          = TEGRA_DC_FLAG_ENABLED,
313         .default_out    = &dalmore_disp2_out,
314         .fb             = &dalmore_disp2_fb_data,
315         .emc_clk_rate   = 300000000,
316 #ifdef CONFIG_TEGRA_DC_CMU
317         .cmu_enable     = 1,
318 #endif
319 };
320
321 static struct platform_device dalmore_disp2_device = {
322         .name           = "tegradc",
323         .id             = 1,
324         .resource       = dalmore_disp2_resources,
325         .num_resources  = ARRAY_SIZE(dalmore_disp2_resources),
326         .dev = {
327                 .platform_data = &dalmore_disp2_pdata,
328         },
329 };
330
331 static struct platform_device dalmore_disp1_device = {
332         .name           = "tegradc",
333         .id             = 0,
334         .resource       = dalmore_disp1_resources,
335         .num_resources  = ARRAY_SIZE(dalmore_disp1_resources),
336         .dev = {
337                 .platform_data = &dalmore_disp1_pdata,
338         },
339 };
340
341 static struct nvmap_platform_carveout dalmore_carveouts[] = {
342         [0] = {
343                 .name           = "iram",
344                 .usage_mask     = NVMAP_HEAP_CARVEOUT_IRAM,
345                 .base           = TEGRA_IRAM_BASE + TEGRA_RESET_HANDLER_SIZE,
346                 .size           = TEGRA_IRAM_SIZE - TEGRA_RESET_HANDLER_SIZE,
347                 .buddy_size     = 0, /* no buddy allocation for IRAM */
348         },
349         [1] = {
350                 .name           = "generic-0",
351                 .usage_mask     = NVMAP_HEAP_CARVEOUT_GENERIC,
352                 .base           = 0, /* Filled in by dalmore_panel_init() */
353                 .size           = 0, /* Filled in by dalmore_panel_init() */
354                 .buddy_size     = SZ_32K,
355         },
356         [2] = {
357                 .name           = "vpr",
358                 .usage_mask     = NVMAP_HEAP_CARVEOUT_VPR,
359                 .base           = 0, /* Filled in by dalmore_panel_init() */
360                 .size           = 0, /* Filled in by dalmore_panel_init() */
361                 .buddy_size     = SZ_32K,
362         },
363 };
364
365 static struct nvmap_platform_data dalmore_nvmap_data = {
366         .carveouts      = dalmore_carveouts,
367         .nr_carveouts   = ARRAY_SIZE(dalmore_carveouts),
368 };
369 static struct platform_device dalmore_nvmap_device = {
370         .name   = "tegra-nvmap",
371         .id     = -1,
372         .dev    = {
373                 .platform_data = &dalmore_nvmap_data,
374         },
375 };
376
377 static struct tegra_dc_sd_settings dalmore_sd_settings = {
378         .enable = 1, /* enabled by default. */
379         .use_auto_pwm = false,
380         .hw_update_delay = 0,
381         .bin_width = -1,
382         .aggressiveness = 5,
383         .use_vid_luma = false,
384         .phase_in_adjustments = 0,
385         .k_limit_enable = true,
386         .k_limit = 200,
387         .sd_window_enable = false,
388         .soft_clipping_enable = true,
389         /* Low soft clipping threshold to compensate for aggressive k_limit */
390         .soft_clipping_threshold = 128,
391         .smooth_k_enable = true,
392         .smooth_k_incr = 4,
393         /* Default video coefficients */
394         .coeff = {5, 9, 2},
395         .fc = {0, 0},
396         /* Immediate backlight changes */
397         .blp = {1024, 255},
398         /* Gammas: R: 2.2 G: 2.2 B: 2.2 */
399         /* Default BL TF */
400         .bltf = {
401                         {
402                                 {57, 65, 73, 82},
403                                 {92, 103, 114, 125},
404                                 {138, 150, 164, 178},
405                                 {193, 208, 224, 241},
406                         },
407                 },
408         /* Default LUT */
409         .lut = {
410                         {
411                                 {255, 255, 255},
412                                 {199, 199, 199},
413                                 {153, 153, 153},
414                                 {116, 116, 116},
415                                 {85, 85, 85},
416                                 {59, 59, 59},
417                                 {36, 36, 36},
418                                 {17, 17, 17},
419                                 {0, 0, 0},
420                         },
421                 },
422         .sd_brightness = &sd_brightness,
423         .use_vpulse2 = true,
424 };
425
426 static void dalmore_panel_select(void)
427 {
428         struct tegra_panel *panel = NULL;
429         struct board_info board;
430         u8 dsi_instance;
431
432         tegra_get_display_board_info(&board);
433
434         switch (board.board_id) {
435         case BOARD_E1639:
436                 panel = &dsi_s_wqxga_10_1;
437                 /* FIXME: panel used ganged mode,need to check if
438                  * the dsi_instance is useful in this case
439                  */
440                 dsi_instance = DSI_INSTANCE_0;
441                 break;
442         case BOARD_E1631:
443                 panel = &dsi_a_1080p_11_6;
444                 dsi_instance = DSI_INSTANCE_0;
445                 break;
446         case BOARD_E1627:
447         /* fall through */
448         default:
449                 panel = &dsi_p_wuxga_10_1;
450                 dsi_instance = DSI_INSTANCE_0;
451                 break;
452         }
453         if (panel) {
454                 if (panel->init_sd_settings)
455                         panel->init_sd_settings(&sd_settings);
456
457                 if (panel->init_dc_out) {
458                         panel->init_dc_out(&dalmore_disp1_out);
459                         dalmore_disp1_out.dsi->dsi_instance = dsi_instance;
460                         dalmore_disp1_out.dsi->dsi_panel_rst_gpio =
461                                 DSI_PANEL_RST_GPIO;
462                         dalmore_disp1_out.dsi->dsi_panel_bl_pwm_gpio =
463                                 DSI_PANEL_BL_PWM_GPIO;
464                 }
465
466                 if (panel->init_fb_data)
467                         panel->init_fb_data(&dalmore_disp1_fb_data);
468
469                 if (panel->init_cmu_data)
470                         panel->init_cmu_data(&dalmore_disp1_pdata);
471
472                 if (panel->set_disp_device)
473                         panel->set_disp_device(&dalmore_disp1_device);
474
475                 tegra_dsi_resources_init(dsi_instance, dalmore_disp1_resources,
476                         ARRAY_SIZE(dalmore_disp1_resources));
477
478                 if (panel->register_bl_dev)
479                         panel->register_bl_dev();
480
481                 if (panel->register_i2c_bridge)
482                         panel->register_i2c_bridge();
483         }
484
485 }
486 int __init dalmore_panel_init(void)
487 {
488         int err = 0;
489         struct resource __maybe_unused *res;
490         struct platform_device *phost1x = NULL;
491
492         sd_settings = dalmore_sd_settings;
493
494         dalmore_panel_select();
495
496 #ifdef CONFIG_TEGRA_NVMAP
497         dalmore_carveouts[1].base = tegra_carveout_start;
498         dalmore_carveouts[1].size = tegra_carveout_size;
499         dalmore_carveouts[2].base = tegra_vpr_start;
500         dalmore_carveouts[2].size = tegra_vpr_size;
501
502         err = platform_device_register(&dalmore_nvmap_device);
503         if (err) {
504                 pr_err("nvmap device registration failed\n");
505                 return err;
506         }
507 #endif
508
509         phost1x = dalmore_host1x_init();
510         if (!phost1x) {
511                 pr_err("host1x devices registration failed\n");
512                 return -EINVAL;
513         }
514
515         res = platform_get_resource_byname(&dalmore_disp1_device,
516                                          IORESOURCE_MEM, "fbmem");
517         res->start = tegra_fb_start;
518         res->end = tegra_fb_start + tegra_fb_size - 1;
519
520         /* Copy the bootloader fb to the fb. */
521         __tegra_move_framebuffer(&dalmore_nvmap_device,
522                 tegra_fb_start, tegra_bootloader_fb_start,
523                         min(tegra_fb_size, tegra_bootloader_fb_size));
524
525         res = platform_get_resource_byname(&dalmore_disp2_device,
526                                          IORESOURCE_MEM, "fbmem");
527
528         res->start = tegra_fb2_start;
529         res->end = tegra_fb2_start + tegra_fb2_size - 1;
530
531         dalmore_disp1_device.dev.parent = &phost1x->dev;
532         err = platform_device_register(&dalmore_disp1_device);
533         if (err) {
534                 pr_err("disp1 device registration failed\n");
535                 return err;
536         }
537
538         dalmore_disp2_device.dev.parent = &phost1x->dev;
539         err = platform_device_register(&dalmore_disp2_device);
540         if (err) {
541                 pr_err("disp2 device registration failed\n");
542                 return err;
543         }
544
545 #ifdef CONFIG_TEGRA_NVAVP
546         nvavp_device.dev.parent = &phost1x->dev;
547         err = platform_device_register(&nvavp_device);
548         if (err) {
549                 pr_err("nvavp device registration failed\n");
550                 return err;
551         }
552 #endif
553         return err;
554 }
555 #else
556 int __init dalmore_panel_init(void)
557 {
558         if (dalmore_host1x_init())
559                 return 0;
560         else
561                 return -EINVAL;
562 }
563 #endif