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