]> nv-tegra.nvidia Code Review - linux-3.10.git/blob - arch/arm/mach-tegra/board-dalmore-panel.c
ARM: tegra: clock: Return minimum iso bandwidth
[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 static struct tegra_dc_out dalmore_disp2_out = {
227         .type           = TEGRA_DC_OUT_HDMI,
228         .flags          = TEGRA_DC_OUT_HOTPLUG_HIGH,
229         .parent_clk     = "pll_d2_out0",
230
231         .dcc_bus        = 3,
232         .hotplug_gpio   = dalmore_hdmi_hpd,
233
234         .max_pixclock   = KHZ2PICOS(297000),
235
236         .align          = TEGRA_DC_ALIGN_MSB,
237         .order          = TEGRA_DC_ORDER_RED_BLUE,
238
239         .enable         = dalmore_hdmi_enable,
240         .disable        = dalmore_hdmi_disable,
241         .postsuspend    = dalmore_hdmi_postsuspend,
242         .hotplug_init   = dalmore_hdmi_hotplug_init,
243 };
244
245 static struct tegra_fb_data dalmore_disp1_fb_data = {
246         .win            = 0,
247         .bits_per_pixel = 32,
248         .flags          = TEGRA_FB_FLIP_ON_PROBE,
249 };
250
251 static struct tegra_dc_platform_data dalmore_disp1_pdata = {
252         .flags          = TEGRA_DC_FLAG_ENABLED,
253         .default_out    = &dalmore_disp1_out,
254         .fb             = &dalmore_disp1_fb_data,
255         .emc_clk_rate   = 204000000,
256 #ifdef CONFIG_TEGRA_DC_CMU
257         .cmu_enable     = 1,
258 #endif
259 };
260
261 static struct tegra_fb_data dalmore_disp2_fb_data = {
262         .win            = 0,
263         .xres           = 1280,
264         .yres           = 720,
265         .bits_per_pixel = 32,
266         .flags          = TEGRA_FB_FLIP_ON_PROBE,
267 };
268
269 static struct tegra_dc_platform_data dalmore_disp2_pdata = {
270         .flags          = TEGRA_DC_FLAG_ENABLED,
271         .default_out    = &dalmore_disp2_out,
272         .fb             = &dalmore_disp2_fb_data,
273         .emc_clk_rate   = 300000000,
274 #ifdef CONFIG_TEGRA_DC_CMU
275         .cmu_enable     = 1,
276 #endif
277 };
278
279 static struct platform_device dalmore_disp2_device = {
280         .name           = "tegradc",
281         .id             = 1,
282         .resource       = dalmore_disp2_resources,
283         .num_resources  = ARRAY_SIZE(dalmore_disp2_resources),
284         .dev = {
285                 .platform_data = &dalmore_disp2_pdata,
286         },
287 };
288
289 static struct platform_device dalmore_disp1_device = {
290         .name           = "tegradc",
291         .id             = 0,
292         .resource       = dalmore_disp1_resources,
293         .num_resources  = ARRAY_SIZE(dalmore_disp1_resources),
294         .dev = {
295                 .platform_data = &dalmore_disp1_pdata,
296         },
297 };
298
299 static struct nvmap_platform_carveout dalmore_carveouts[] = {
300         [0] = {
301                 .name           = "iram",
302                 .usage_mask     = NVMAP_HEAP_CARVEOUT_IRAM,
303                 .base           = TEGRA_IRAM_BASE + TEGRA_RESET_HANDLER_SIZE,
304                 .size           = TEGRA_IRAM_SIZE - TEGRA_RESET_HANDLER_SIZE,
305                 .buddy_size     = 0, /* no buddy allocation for IRAM */
306         },
307         [1] = {
308                 .name           = "generic-0",
309                 .usage_mask     = NVMAP_HEAP_CARVEOUT_GENERIC,
310                 .base           = 0, /* Filled in by dalmore_panel_init() */
311                 .size           = 0, /* Filled in by dalmore_panel_init() */
312                 .buddy_size     = SZ_32K,
313         },
314         [2] = {
315                 .name           = "vpr",
316                 .usage_mask     = NVMAP_HEAP_CARVEOUT_VPR,
317                 .base           = 0, /* Filled in by dalmore_panel_init() */
318                 .size           = 0, /* Filled in by dalmore_panel_init() */
319                 .buddy_size     = SZ_32K,
320         },
321 };
322
323 static struct nvmap_platform_data dalmore_nvmap_data = {
324         .carveouts      = dalmore_carveouts,
325         .nr_carveouts   = ARRAY_SIZE(dalmore_carveouts),
326 };
327 static struct platform_device dalmore_nvmap_device = {
328         .name   = "tegra-nvmap",
329         .id     = -1,
330         .dev    = {
331                 .platform_data = &dalmore_nvmap_data,
332         },
333 };
334
335 static struct tegra_dc_sd_settings dalmore_sd_settings = {
336         .enable = 1, /* enabled by default. */
337         .use_auto_pwm = false,
338         .hw_update_delay = 0,
339         .bin_width = -1,
340         .aggressiveness = 5,
341         .use_vid_luma = false,
342         .phase_in_adjustments = 0,
343         .k_limit_enable = true,
344         .k_limit = 200,
345         .sd_window_enable = false,
346         .soft_clipping_enable = true,
347         /* Low soft clipping threshold to compensate for aggressive k_limit */
348         .soft_clipping_threshold = 128,
349         .smooth_k_enable = true,
350         .smooth_k_incr = 4,
351         /* Default video coefficients */
352         .coeff = {5, 9, 2},
353         .fc = {0, 0},
354         /* Immediate backlight changes */
355         .blp = {1024, 255},
356         /* Gammas: R: 2.2 G: 2.2 B: 2.2 */
357         /* Default BL TF */
358         .bltf = {
359                         {
360                                 {57, 65, 73, 82},
361                                 {92, 103, 114, 125},
362                                 {138, 150, 164, 178},
363                                 {193, 208, 224, 241},
364                         },
365                 },
366         /* Default LUT */
367         .lut = {
368                         {
369                                 {255, 255, 255},
370                                 {199, 199, 199},
371                                 {153, 153, 153},
372                                 {116, 116, 116},
373                                 {85, 85, 85},
374                                 {59, 59, 59},
375                                 {36, 36, 36},
376                                 {17, 17, 17},
377                                 {0, 0, 0},
378                         },
379                 },
380         .sd_brightness = &sd_brightness,
381         .use_vpulse2 = true,
382 };
383
384 static void dalmore_panel_select(void)
385 {
386         struct tegra_panel *panel = NULL;
387         struct board_info board;
388         u8 dsi_instance;
389
390         tegra_get_display_board_info(&board);
391
392         switch (board.board_id) {
393         case BOARD_E1639:
394                 panel = &dsi_s_wqxga_10_1;
395                 /* FIXME: panel used ganged mode,need to check if
396                  * the dsi_instance is useful in this case
397                  */
398                 dsi_instance = DSI_INSTANCE_0;
399                 break;
400         case BOARD_E1631:
401                 panel = &dsi_a_1080p_11_6;
402                 dsi_instance = DSI_INSTANCE_0;
403                 break;
404         case BOARD_E1627:
405         /* fall through */
406         default:
407                 panel = &dsi_p_wuxga_10_1;
408                 dsi_instance = DSI_INSTANCE_0;
409                 break;
410         }
411         if (panel) {
412                 if (panel->init_sd_settings)
413                         panel->init_sd_settings(&sd_settings);
414
415                 if (panel->init_dc_out) {
416                         panel->init_dc_out(&dalmore_disp1_out);
417                         dalmore_disp1_out.dsi->dsi_instance = dsi_instance;
418                         dalmore_disp1_out.dsi->dsi_panel_rst_gpio =
419                                 DSI_PANEL_RST_GPIO;
420                         dalmore_disp1_out.dsi->dsi_panel_bl_pwm_gpio =
421                                 DSI_PANEL_BL_PWM_GPIO;
422                 }
423
424                 if (panel->init_fb_data)
425                         panel->init_fb_data(&dalmore_disp1_fb_data);
426
427                 if (panel->init_cmu_data)
428                         panel->init_cmu_data(&dalmore_disp1_pdata);
429
430                 if (panel->set_disp_device)
431                         panel->set_disp_device(&dalmore_disp1_device);
432
433                 tegra_dsi_resources_init(dsi_instance, dalmore_disp1_resources,
434                         ARRAY_SIZE(dalmore_disp1_resources));
435
436                 if (panel->register_bl_dev)
437                         panel->register_bl_dev();
438
439                 if (panel->register_i2c_bridge)
440                         panel->register_i2c_bridge();
441         }
442
443 }
444 int __init dalmore_panel_init(void)
445 {
446         int err = 0;
447         struct resource __maybe_unused *res;
448         struct platform_device *phost1x = NULL;
449
450         sd_settings = dalmore_sd_settings;
451
452         dalmore_panel_select();
453
454 #ifdef CONFIG_TEGRA_NVMAP
455         dalmore_carveouts[1].base = tegra_carveout_start;
456         dalmore_carveouts[1].size = tegra_carveout_size;
457         dalmore_carveouts[2].base = tegra_vpr_start;
458         dalmore_carveouts[2].size = tegra_vpr_size;
459
460         err = platform_device_register(&dalmore_nvmap_device);
461         if (err) {
462                 pr_err("nvmap device registration failed\n");
463                 return err;
464         }
465 #endif
466
467         phost1x = dalmore_host1x_init();
468         if (!phost1x) {
469                 pr_err("host1x devices registration failed\n");
470                 return -EINVAL;
471         }
472
473         res = platform_get_resource_byname(&dalmore_disp1_device,
474                                          IORESOURCE_MEM, "fbmem");
475         res->start = tegra_fb_start;
476         res->end = tegra_fb_start + tegra_fb_size - 1;
477
478         /* Copy the bootloader fb to the fb. */
479         __tegra_move_framebuffer(&dalmore_nvmap_device,
480                 tegra_fb_start, tegra_bootloader_fb_start,
481                         min(tegra_fb_size, tegra_bootloader_fb_size));
482
483         res = platform_get_resource_byname(&dalmore_disp2_device,
484                                          IORESOURCE_MEM, "fbmem");
485
486         res->start = tegra_fb2_start;
487         res->end = tegra_fb2_start + tegra_fb2_size - 1;
488
489         dalmore_disp1_device.dev.parent = &phost1x->dev;
490         err = platform_device_register(&dalmore_disp1_device);
491         if (err) {
492                 pr_err("disp1 device registration failed\n");
493                 return err;
494         }
495
496         dalmore_disp2_device.dev.parent = &phost1x->dev;
497         err = platform_device_register(&dalmore_disp2_device);
498         if (err) {
499                 pr_err("disp2 device registration failed\n");
500                 return err;
501         }
502
503 #ifdef CONFIG_TEGRA_NVAVP
504         nvavp_device.dev.parent = &phost1x->dev;
505         err = platform_device_register(&nvavp_device);
506         if (err) {
507                 pr_err("nvavp device registration failed\n");
508                 return err;
509         }
510 #endif
511         return err;
512 }
513 #else
514 int __init dalmore_panel_init(void)
515 {
516         if (dalmore_host1x_init())
517                 return 0;
518         else
519                 return -EINVAL;
520 }
521 #endif