c07fb1983b71f108ae156b733801f47bc4d4af52
[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.
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 };
275
276 static struct platform_device macallan_disp2_device = {
277         .name           = "tegradc",
278         .id             = 1,
279         .resource       = macallan_disp2_resources,
280         .num_resources  = ARRAY_SIZE(macallan_disp2_resources),
281         .dev = {
282                 .platform_data = &macallan_disp2_pdata,
283         },
284 };
285
286 static struct platform_device macallan_disp1_device = {
287         .name           = "tegradc",
288         .id             = 0,
289         .resource       = macallan_disp1_resources,
290         .num_resources  = ARRAY_SIZE(macallan_disp1_resources),
291         .dev = {
292                 .platform_data = &macallan_disp1_pdata,
293         },
294 };
295
296 static struct nvmap_platform_carveout macallan_carveouts[] = {
297         [0] = {
298                 .name           = "iram",
299                 .usage_mask     = NVMAP_HEAP_CARVEOUT_IRAM,
300                 .base           = TEGRA_IRAM_BASE + TEGRA_RESET_HANDLER_SIZE,
301                 .size           = TEGRA_IRAM_SIZE - TEGRA_RESET_HANDLER_SIZE,
302                 .buddy_size     = 0, /* no buddy allocation for IRAM */
303         },
304         [1] = {
305                 .name           = "generic-0",
306                 .usage_mask     = NVMAP_HEAP_CARVEOUT_GENERIC,
307                 .base           = 0, /* Filled in by macallan_panel_init() */
308                 .size           = 0, /* Filled in by macallan_panel_init() */
309                 .buddy_size     = SZ_32K,
310         },
311         [2] = {
312                 .name           = "vpr",
313                 .usage_mask     = NVMAP_HEAP_CARVEOUT_VPR,
314                 .base           = 0, /* Filled in by macallan_panel_init() */
315                 .size           = 0, /* Filled in by macallan_panel_init() */
316                 .buddy_size     = SZ_32K,
317         },
318 };
319
320 static struct nvmap_platform_data macallan_nvmap_data = {
321         .carveouts      = macallan_carveouts,
322         .nr_carveouts   = ARRAY_SIZE(macallan_carveouts),
323 };
324 static struct platform_device macallan_nvmap_device __initdata = {
325         .name   = "tegra-nvmap",
326         .id     = -1,
327         .dev    = {
328                 .platform_data = &macallan_nvmap_data,
329         },
330 };
331
332 static struct tegra_dc_sd_settings macallan_sd_settings = {
333         .enable = 1, /* enabled by default. */
334         .use_auto_pwm = false,
335         .hw_update_delay = 0,
336         .bin_width = -1,
337         .aggressiveness = 5,
338         .use_vid_luma = false,
339         .phase_in_adjustments = 0,
340         .k_limit_enable = true,
341         .k_limit = 200,
342         .sd_window_enable = false,
343         .soft_clipping_enable = true,
344         /* Low soft clipping threshold to compensate for aggressive k_limit */
345         .soft_clipping_threshold = 128,
346         .smooth_k_enable = false,
347         .smooth_k_incr = 64,
348         /* Default video coefficients */
349         .coeff = {5, 9, 2},
350         .fc = {0, 0},
351         /* Immediate backlight changes */
352         .blp = {1024, 255},
353         /* Gammas: R: 2.2 G: 2.2 B: 2.2 */
354         /* Default BL TF */
355         .bltf = {
356                         {
357                                 {57, 65, 73, 82},
358                                 {92, 103, 114, 125},
359                                 {138, 150, 164, 178},
360                                 {193, 208, 224, 241},
361                         },
362                 },
363         /* Default LUT */
364         .lut = {
365                         {
366                                 {255, 255, 255},
367                                 {199, 199, 199},
368                                 {153, 153, 153},
369                                 {116, 116, 116},
370                                 {85, 85, 85},
371                                 {59, 59, 59},
372                                 {36, 36, 36},
373                                 {17, 17, 17},
374                                 {0, 0, 0},
375                         },
376                 },
377         .sd_brightness = &sd_brightness,
378         .use_vpulse2 = true,
379 };
380
381 static void macallan_panel_select(void)
382 {
383         struct tegra_panel *panel = NULL;
384         struct board_info board;
385         u8 dsi_instance;
386
387         tegra_get_display_board_info(&board);
388
389         switch (board.board_id) {
390         default:
391                 panel = &dsi_p_wuxga_10_1;
392                 dsi_instance = DSI_INSTANCE_0;
393                 break;
394         }
395         if (panel) {
396                 if (panel->init_sd_settings)
397                         panel->init_sd_settings(&sd_settings);
398
399                 if (panel->init_dc_out) {
400                         panel->init_dc_out(&macallan_disp1_out);
401                         macallan_disp1_out.dsi->dsi_instance = dsi_instance;
402                         macallan_disp1_out.dsi->dsi_panel_rst_gpio =
403                                 DSI_PANEL_RST_GPIO;
404                         macallan_disp1_out.dsi->dsi_panel_bl_pwm_gpio =
405                                 DSI_PANEL_BL_PWM_GPIO;
406                 }
407
408                 if (panel->init_fb_data)
409                         panel->init_fb_data(&macallan_disp1_fb_data);
410
411                 if (panel->init_cmu_data)
412                         panel->init_cmu_data(&macallan_disp1_pdata);
413
414                 if (panel->set_disp_device)
415                         panel->set_disp_device(&macallan_disp1_device);
416
417                 tegra_dsi_resources_init(dsi_instance, macallan_disp1_resources,
418                                  ARRAY_SIZE(macallan_disp1_resources));
419
420                 if (panel->register_bl_dev)
421                         panel->register_bl_dev();
422
423                 if (panel->register_i2c_bridge)
424                         panel->register_i2c_bridge();
425         }
426
427 }
428 int __init macallan_panel_init(void)
429 {
430         int err = 0;
431         struct resource __maybe_unused *res;
432         struct platform_device *phost1x = NULL;
433
434         sd_settings = macallan_sd_settings;
435
436         macallan_panel_select();
437
438 #ifdef CONFIG_TEGRA_NVMAP
439         macallan_carveouts[1].base = tegra_carveout_start;
440         macallan_carveouts[1].size = tegra_carveout_size;
441         macallan_carveouts[2].base = tegra_vpr_start;
442         macallan_carveouts[2].size = tegra_vpr_size;
443
444         err = platform_device_register(&macallan_nvmap_device);
445         if (err) {
446                 pr_err("nvmap device registration failed\n");
447                 return err;
448         }
449 #endif
450
451         phost1x = macallan_host1x_init();
452         if (!phost1x) {
453                 pr_err("host1x devices registration failed\n");
454                 return -EINVAL;
455         }
456
457         res = platform_get_resource_byname(&macallan_disp1_device,
458                                          IORESOURCE_MEM, "fbmem");
459         res->start = tegra_fb_start;
460         res->end = tegra_fb_start + tegra_fb_size - 1;
461
462         /* Copy the bootloader fb to the fb. */
463         __tegra_move_framebuffer(&macallan_nvmap_device,
464                 tegra_fb_start, tegra_bootloader_fb_start,
465                         min(tegra_fb_size, tegra_bootloader_fb_size));
466
467         res = platform_get_resource_byname(&macallan_disp2_device,
468                 IORESOURCE_MEM, "fbmem");
469         res->start = tegra_fb2_start;
470         res->end = tegra_fb2_start + tegra_fb2_size - 1;
471
472         macallan_disp1_device.dev.parent = &phost1x->dev;
473         err = platform_device_register(&macallan_disp1_device);
474         if (err) {
475                 pr_err("disp1 device registration failed\n");
476                 return err;
477         }
478
479         macallan_disp2_device.dev.parent = &phost1x->dev;
480         err = platform_device_register(&macallan_disp2_device);
481         if (err) {
482                 pr_err("disp2 device registration failed\n");
483                 return err;
484         }
485
486 #ifdef CONFIG_TEGRA_NVAVP
487         nvavp_device.dev.parent = &phost1x->dev;
488         err = platform_device_register(&nvavp_device);
489         if (err) {
490                 pr_err("nvavp device registration failed\n");
491                 return err;
492         }
493 #endif
494         return err;
495 }
496 #else
497 int __init macallan_panel_init(void)
498 {
499         if (macallan_host1x_init())
500                 return 0;
501         else
502                 return -EINVAL;
503 }
504 #endif