5981c124ecea19c3de20e322bace90619d149e93
[linux-3.10.git] / arch / arm / mach-tegra / board-macallan-panel.c
1 /*
2  * arch/arm/mach-tegra/board-macallan-panel.c
3  *
4  * Copyright (c) 2013, NVIDIA Corporation. All rights reserved.
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
31 #include <mach/irqs.h>
32 #include <mach/dc.h>
33
34 #include "board.h"
35 #include "devices.h"
36 #include "gpio-names.h"
37 #include "board-panel.h"
38 #include "common.h"
39 #include "iomap.h"
40 #include "tegra11_host1x_devices.h"
41
42 #define DSI_PANEL_RST_GPIO      TEGRA_GPIO_PH5
43 #define DSI_PANEL_BL_PWM_GPIO   TEGRA_GPIO_PH1
44
45 struct platform_device * __init macallan_host1x_init(void)
46 {
47         struct platform_device *pdev = NULL;
48
49 #ifdef CONFIG_TEGRA_GRHOST
50         if (!of_have_populated_dt())
51                 pdev = tegra11_register_host1x_devices();
52         else
53                 pdev = to_platform_device(bus_find_device_by_name(
54                         &platform_bus_type, NULL, "host1x"));
55 #endif
56         return pdev;
57 }
58
59 #ifdef CONFIG_TEGRA_DC
60
61 /* HDMI Hotplug detection pin */
62 #define macallan_hdmi_hpd       TEGRA_GPIO_PN7
63
64 static struct regulator *macallan_hdmi_reg;
65 static struct regulator *macallan_hdmi_pll;
66 static struct regulator *macallan_hdmi_vddio;
67
68 static struct resource macallan_disp1_resources[] = {
69         {
70                 .name   = "irq",
71                 .start  = INT_DISPLAY_GENERAL,
72                 .end    = INT_DISPLAY_GENERAL,
73                 .flags  = IORESOURCE_IRQ,
74         },
75         {
76                 .name   = "regs",
77                 .start  = TEGRA_DISPLAY_BASE,
78                 .end    = TEGRA_DISPLAY_BASE + TEGRA_DISPLAY_SIZE - 1,
79                 .flags  = IORESOURCE_MEM,
80         },
81         {
82                 .name   = "fbmem",
83                 .start  = 0, /* Filled in by macallan_panel_init() */
84                 .end    = 0, /* Filled in by macallan_panel_init() */
85                 .flags  = IORESOURCE_MEM,
86         },
87         {
88                 .name   = "ganged_dsia_regs",
89                 .start  = 0, /* Filled in the panel file by init_resources() */
90                 .end    = 0, /* Filled in the panel file by init_resources() */
91                 .flags  = IORESOURCE_MEM,
92         },
93         {
94                 .name   = "ganged_dsib_regs",
95                 .start  = 0, /* Filled in the panel file by init_resources() */
96                 .end    = 0, /* Filled in the panel file by init_resources() */
97                 .flags  = IORESOURCE_MEM,
98         },
99         {
100                 .name   = "dsi_regs",
101                 .start  = 0, /* Filled in the panel file by init_resources() */
102                 .end    = 0, /* Filled in the panel file by init_resources() */
103                 .flags  = IORESOURCE_MEM,
104         },
105         {
106                 .name   = "mipi_cal",
107                 .start  = TEGRA_MIPI_CAL_BASE,
108                 .end    = TEGRA_MIPI_CAL_BASE + TEGRA_MIPI_CAL_SIZE - 1,
109                 .flags  = IORESOURCE_MEM,
110         },
111 };
112
113 static struct resource macallan_disp2_resources[] = {
114         {
115                 .name   = "irq",
116                 .start  = INT_DISPLAY_B_GENERAL,
117                 .end    = INT_DISPLAY_B_GENERAL,
118                 .flags  = IORESOURCE_IRQ,
119         },
120         {
121                 .name   = "regs",
122                 .start  = TEGRA_DISPLAY2_BASE,
123                 .end    = TEGRA_DISPLAY2_BASE + TEGRA_DISPLAY2_SIZE - 1,
124                 .flags  = IORESOURCE_MEM,
125         },
126         {
127                 .name   = "fbmem",
128                 .start  = 0, /* Filled in by macallan_panel_init() */
129                 .end    = 0, /* Filled in by macallan_panel_init() */
130                 .flags  = IORESOURCE_MEM,
131         },
132         {
133                 .name   = "hdmi_regs",
134                 .start  = TEGRA_HDMI_BASE,
135                 .end    = TEGRA_HDMI_BASE + TEGRA_HDMI_SIZE - 1,
136                 .flags  = IORESOURCE_MEM,
137         },
138 };
139
140
141 static struct tegra_dc_sd_settings sd_settings;
142
143 static struct tegra_dc_out macallan_disp1_out = {
144         .type           = TEGRA_DC_OUT_DSI,
145         .sd_settings    = &sd_settings,
146 };
147
148 static int macallan_hdmi_enable(struct device *dev)
149 {
150         int ret;
151         if (!macallan_hdmi_reg) {
152                 macallan_hdmi_reg = regulator_get(dev, "avdd_hdmi");
153                 if (IS_ERR_OR_NULL(macallan_hdmi_reg)) {
154                         pr_err("hdmi: couldn't get regulator avdd_hdmi\n");
155                         macallan_hdmi_reg = NULL;
156                         return PTR_ERR(macallan_hdmi_reg);
157                 }
158         }
159         ret = regulator_enable(macallan_hdmi_reg);
160         if (ret < 0) {
161                 pr_err("hdmi: couldn't enable regulator avdd_hdmi\n");
162                 return ret;
163         }
164         if (!macallan_hdmi_pll) {
165                 macallan_hdmi_pll = regulator_get(dev, "avdd_hdmi_pll");
166                 if (IS_ERR_OR_NULL(macallan_hdmi_pll)) {
167                         pr_err("hdmi: couldn't get regulator avdd_hdmi_pll\n");
168                         macallan_hdmi_pll = NULL;
169                         regulator_put(macallan_hdmi_reg);
170                         macallan_hdmi_reg = NULL;
171                         return PTR_ERR(macallan_hdmi_pll);
172                 }
173         }
174         ret = regulator_enable(macallan_hdmi_pll);
175         if (ret < 0) {
176                 pr_err("hdmi: couldn't enable regulator avdd_hdmi_pll\n");
177                 return ret;
178         }
179         return 0;
180 }
181
182 static int macallan_hdmi_disable(void)
183 {
184         if (macallan_hdmi_reg) {
185                 regulator_disable(macallan_hdmi_reg);
186                 regulator_put(macallan_hdmi_reg);
187                 macallan_hdmi_reg = NULL;
188         }
189
190         if (macallan_hdmi_pll) {
191                 regulator_disable(macallan_hdmi_pll);
192                 regulator_put(macallan_hdmi_pll);
193                 macallan_hdmi_pll = NULL;
194         }
195
196         return 0;
197 }
198
199 static int macallan_hdmi_postsuspend(void)
200 {
201         if (macallan_hdmi_vddio) {
202                 regulator_disable(macallan_hdmi_vddio);
203                 regulator_put(macallan_hdmi_vddio);
204                 macallan_hdmi_vddio = NULL;
205         }
206         return 0;
207 }
208
209 static int macallan_hdmi_hotplug_init(struct device *dev)
210 {
211         if (!macallan_hdmi_vddio) {
212                 macallan_hdmi_vddio = regulator_get(dev, "vdd_hdmi_5v0");
213                 if (WARN_ON(IS_ERR(macallan_hdmi_vddio))) {
214                         pr_err("%s: couldn't get regulator vdd_hdmi_5v0: %ld\n",
215                                 __func__, PTR_ERR(macallan_hdmi_vddio));
216                                 macallan_hdmi_vddio = NULL;
217                 } else {
218                         regulator_enable(macallan_hdmi_vddio);
219                         mdelay(5);
220                 }
221         }
222
223         return 0;
224 }
225
226 static struct tegra_dc_out macallan_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   = macallan_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         = macallan_hdmi_enable,
240         .disable        = macallan_hdmi_disable,
241         .postsuspend    = macallan_hdmi_postsuspend,
242         .hotplug_init   = macallan_hdmi_hotplug_init,
243 };
244
245 static struct tegra_fb_data macallan_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 macallan_disp1_pdata = {
252         .flags          = TEGRA_DC_FLAG_ENABLED,
253         .default_out    = &macallan_disp1_out,
254         .fb             = &macallan_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 macallan_disp2_fb_data = {
262         .win            = 0,
263         .xres           = 1024,
264         .yres           = 600,
265         .bits_per_pixel = 32,
266         .flags          = TEGRA_FB_FLIP_ON_PROBE,
267 };
268
269 static struct tegra_dc_platform_data macallan_disp2_pdata = {
270         .flags          = TEGRA_DC_FLAG_ENABLED,
271         .default_out    = &macallan_disp2_out,
272         .fb             = &macallan_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 macallan_disp2_device = {
280         .name           = "tegradc",
281         .id             = 1,
282         .resource       = macallan_disp2_resources,
283         .num_resources  = ARRAY_SIZE(macallan_disp2_resources),
284         .dev = {
285                 .platform_data = &macallan_disp2_pdata,
286         },
287 };
288
289 static struct platform_device macallan_disp1_device = {
290         .name           = "tegradc",
291         .id             = 0,
292         .resource       = macallan_disp1_resources,
293         .num_resources  = ARRAY_SIZE(macallan_disp1_resources),
294         .dev = {
295                 .platform_data = &macallan_disp1_pdata,
296         },
297 };
298
299 static struct nvmap_platform_carveout macallan_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 macallan_panel_init() */
311                 .size           = 0, /* Filled in by macallan_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 macallan_panel_init() */
318                 .size           = 0, /* Filled in by macallan_panel_init() */
319                 .buddy_size     = SZ_32K,
320         },
321 };
322
323 static struct nvmap_platform_data macallan_nvmap_data = {
324         .carveouts      = macallan_carveouts,
325         .nr_carveouts   = ARRAY_SIZE(macallan_carveouts),
326 };
327 static struct platform_device macallan_nvmap_device = {
328         .name   = "tegra-nvmap",
329         .id     = -1,
330         .dev    = {
331                 .platform_data = &macallan_nvmap_data,
332         },
333 };
334
335 static struct tegra_dc_sd_settings macallan_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 macallan_panel_select(void)
385 {
386         struct tegra_panel *panel = NULL;
387         struct board_info board;
388         u8 dsi_instance = DSI_INSTANCE_0;
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                 break;
396         default:
397                 panel = &dsi_p_wuxga_10_1;
398                 break;
399         }
400         if (panel) {
401                 if (panel->init_sd_settings)
402                         panel->init_sd_settings(&sd_settings);
403
404                 if (panel->init_dc_out) {
405                         panel->init_dc_out(&macallan_disp1_out);
406                         macallan_disp1_out.dsi->dsi_instance = dsi_instance;
407                         macallan_disp1_out.dsi->dsi_panel_rst_gpio =
408                                 DSI_PANEL_RST_GPIO;
409                         macallan_disp1_out.dsi->dsi_panel_bl_pwm_gpio =
410                                 DSI_PANEL_BL_PWM_GPIO;
411                 }
412
413                 if (panel->init_fb_data)
414                         panel->init_fb_data(&macallan_disp1_fb_data);
415
416                 if (panel->init_cmu_data)
417                         panel->init_cmu_data(&macallan_disp1_pdata);
418
419                 if (panel->set_disp_device)
420                         panel->set_disp_device(&macallan_disp1_device);
421
422                 tegra_dsi_resources_init(dsi_instance, macallan_disp1_resources,
423                                  ARRAY_SIZE(macallan_disp1_resources));
424
425                 if (panel->register_bl_dev)
426                         panel->register_bl_dev();
427
428                 if (panel->register_i2c_bridge)
429                         panel->register_i2c_bridge();
430         }
431
432 }
433 int __init macallan_panel_init(void)
434 {
435         int err = 0;
436         struct resource __maybe_unused *res;
437         struct platform_device *phost1x = NULL;
438
439         sd_settings = macallan_sd_settings;
440
441         macallan_panel_select();
442
443 #ifdef CONFIG_TEGRA_NVMAP
444         macallan_carveouts[1].base = tegra_carveout_start;
445         macallan_carveouts[1].size = tegra_carveout_size;
446         macallan_carveouts[2].base = tegra_vpr_start;
447         macallan_carveouts[2].size = tegra_vpr_size;
448
449         err = platform_device_register(&macallan_nvmap_device);
450         if (err) {
451                 pr_err("nvmap device registration failed\n");
452                 return err;
453         }
454 #endif
455
456         phost1x = macallan_host1x_init();
457         if (!phost1x) {
458                 pr_err("host1x devices registration failed\n");
459                 return -EINVAL;
460         }
461
462         res = platform_get_resource_byname(&macallan_disp1_device,
463                                          IORESOURCE_MEM, "fbmem");
464         res->start = tegra_fb_start;
465         res->end = tegra_fb_start + tegra_fb_size - 1;
466
467         /* Copy the bootloader fb to the fb. */
468         __tegra_move_framebuffer(&macallan_nvmap_device,
469                 tegra_fb_start, tegra_bootloader_fb_start,
470                         min(tegra_fb_size, tegra_bootloader_fb_size));
471
472         res = platform_get_resource_byname(&macallan_disp2_device,
473                 IORESOURCE_MEM, "fbmem");
474         res->start = tegra_fb2_start;
475         res->end = tegra_fb2_start + tegra_fb2_size - 1;
476
477         macallan_disp1_device.dev.parent = &phost1x->dev;
478         err = platform_device_register(&macallan_disp1_device);
479         if (err) {
480                 pr_err("disp1 device registration failed\n");
481                 return err;
482         }
483
484         macallan_disp2_device.dev.parent = &phost1x->dev;
485         err = platform_device_register(&macallan_disp2_device);
486         if (err) {
487                 pr_err("disp2 device registration failed\n");
488                 return err;
489         }
490
491 #ifdef CONFIG_TEGRA_NVAVP
492         nvavp_device.dev.parent = &phost1x->dev;
493         err = platform_device_register(&nvavp_device);
494         if (err) {
495                 pr_err("nvavp device registration failed\n");
496                 return err;
497         }
498 #endif
499         return err;
500 }
501 #else
502 int __init macallan_panel_init(void)
503 {
504         if (macallan_host1x_init())
505                 return 0;
506         else
507                 return -EINVAL;
508 }
509 #endif