arm: tegra: loki: put DSIC/D to DPD for all panels
[linux-3.10.git] / arch / arm / mach-tegra / board-loki-panel.c
1 /*
2  * arch/arm/mach-tegra/board-loki-panel.c
3  *
4  * Copyright (c) 2011-2014, 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 #include <mach/pinmux-t12.h>
34 #include <mach/io_dpd.h>
35
36 #include "board.h"
37 #include "devices.h"
38 #include "gpio-names.h"
39 #include "iomap.h"
40 #include "tegra12_host1x_devices.h"
41 #include "board-panel.h"
42 #include "common.h"
43 #include "tegra-board-id.h"
44
45 struct platform_device * __init loki_host1x_init(void)
46 {
47         struct platform_device *pdev = NULL;
48
49 #ifdef CONFIG_TEGRA_GRHOST
50         if (!of_have_populated_dt())
51                 pdev = tegra12_register_host1x_devices();
52         else
53                 pdev = to_platform_device(bus_find_device_by_name(
54                         &platform_bus_type, NULL, "host1x"));
55
56         if (!pdev) {
57                 pr_err("host1x devices registration failed\n");
58                 return NULL;
59         }
60 #endif
61         return pdev;
62 }
63
64 #ifdef CONFIG_TEGRA_DC
65
66 #define DSI_PANEL_RST_GPIO      TEGRA_GPIO_PH3
67 #define DSI_PANEL_BL_PWM_GPIO   TEGRA_GPIO_PH1
68
69 /* HDMI Hotplug detection pin */
70 #define loki_hdmi_hpd   TEGRA_GPIO_PN7
71
72 static struct regulator *loki_hdmi_reg;
73 static struct regulator *loki_hdmi_pll;
74 static struct regulator *loki_hdmi_vddio;
75
76 static struct resource loki_disp1_resources[] = {
77         {
78                 .name   = "irq",
79                 .start  = INT_DISPLAY_GENERAL,
80                 .end    = INT_DISPLAY_GENERAL,
81                 .flags  = IORESOURCE_IRQ,
82         },
83         {
84                 .name   = "regs",
85                 .start  = TEGRA_DISPLAY_BASE,
86                 .end    = TEGRA_DISPLAY_BASE + TEGRA_DISPLAY_SIZE - 1,
87                 .flags  = IORESOURCE_MEM,
88         },
89         {
90                 .name   = "fbmem",
91                 .start  = 0, /* Filled in by loki_panel_init() */
92                 .end    = 0, /* Filled in by loki_panel_init() */
93                 .flags  = IORESOURCE_MEM,
94         },
95         {
96                 .name   = "dsi_regs",
97                 .start  = TEGRA_DSI_BASE,
98                 .end    = TEGRA_DSI_BASE + TEGRA_DSI_SIZE - 1,
99                 .flags  = IORESOURCE_MEM,
100         },
101         {
102                 .name   = "mipi_cal",
103                 .start  = TEGRA_MIPI_CAL_BASE,
104                 .end    = TEGRA_MIPI_CAL_BASE + TEGRA_MIPI_CAL_SIZE - 1,
105                 .flags  = IORESOURCE_MEM,
106         },
107 };
108
109 static struct resource loki_disp2_resources[] = {
110         {
111                 .name   = "irq",
112                 .start  = INT_DISPLAY_B_GENERAL,
113                 .end    = INT_DISPLAY_B_GENERAL,
114                 .flags  = IORESOURCE_IRQ,
115         },
116         {
117                 .name   = "regs",
118                 .start  = TEGRA_DISPLAY2_BASE,
119                 .end    = TEGRA_DISPLAY2_BASE + TEGRA_DISPLAY2_SIZE - 1,
120                 .flags  = IORESOURCE_MEM,
121         },
122         {
123                 .name   = "fbmem",
124                 .start  = 0, /* Filled in by loki_panel_init() */
125                 .end    = 0, /* Filled in by loki_panel_init() */
126                 .flags  = IORESOURCE_MEM,
127         },
128         {
129                 .name   = "hdmi_regs",
130                 .start  = TEGRA_HDMI_BASE,
131                 .end    = TEGRA_HDMI_BASE + TEGRA_HDMI_SIZE - 1,
132                 .flags  = IORESOURCE_MEM,
133         },
134 };
135
136 static struct tegra_dc_sd_settings sd_settings;
137
138 static struct tegra_dc_out loki_disp1_out = {
139         .type           = TEGRA_DC_OUT_DSI,
140         .sd_settings    = &sd_settings,
141 };
142
143 static int loki_hdmi_enable(struct device *dev)
144 {
145         int ret;
146         if (!loki_hdmi_reg) {
147                 loki_hdmi_reg = regulator_get(dev, "avdd_hdmi");
148                 if (IS_ERR(loki_hdmi_reg)) {
149                         pr_err("hdmi: couldn't get regulator avdd_hdmi\n");
150                         loki_hdmi_reg = NULL;
151                         return PTR_ERR(loki_hdmi_reg);
152                 }
153         }
154         ret = regulator_enable(loki_hdmi_reg);
155         if (ret < 0) {
156                 pr_err("hdmi: couldn't enable regulator avdd_hdmi\n");
157                 return ret;
158         }
159         if (!loki_hdmi_pll) {
160                 loki_hdmi_pll = regulator_get(dev, "avdd_hdmi_pll");
161                 if (IS_ERR(loki_hdmi_pll)) {
162                         pr_err("hdmi: couldn't get regulator avdd_hdmi_pll\n");
163                         loki_hdmi_pll = NULL;
164                         regulator_put(loki_hdmi_reg);
165                         loki_hdmi_reg = NULL;
166                         return PTR_ERR(loki_hdmi_pll);
167                 }
168         }
169         ret = regulator_enable(loki_hdmi_pll);
170         if (ret < 0) {
171                 pr_err("hdmi: couldn't enable regulator avdd_hdmi_pll\n");
172                 return ret;
173         }
174         return 0;
175 }
176
177 static int loki_hdmi_disable(void)
178 {
179         if (loki_hdmi_reg) {
180                 regulator_disable(loki_hdmi_reg);
181                 regulator_put(loki_hdmi_reg);
182                 loki_hdmi_reg = NULL;
183         }
184
185         if (loki_hdmi_pll) {
186                 regulator_disable(loki_hdmi_pll);
187                 regulator_put(loki_hdmi_pll);
188                 loki_hdmi_pll = NULL;
189         }
190
191         return 0;
192 }
193
194 static int loki_hdmi_postsuspend(void)
195 {
196         if (loki_hdmi_vddio) {
197                 regulator_disable(loki_hdmi_vddio);
198                 regulator_put(loki_hdmi_vddio);
199                 loki_hdmi_vddio = NULL;
200         }
201         return 0;
202 }
203
204 static int loki_hdmi_hotplug_init(struct device *dev)
205 {
206         if (!loki_hdmi_vddio) {
207                 loki_hdmi_vddio = regulator_get(dev, "vdd_hdmi_5v0");
208                 if (WARN_ON(IS_ERR(loki_hdmi_vddio))) {
209                         pr_err("%s: couldn't get regulator vdd_hdmi_5v0: %ld\n",
210                                         __func__, PTR_ERR(loki_hdmi_vddio));
211                         loki_hdmi_vddio = NULL;
212                 } else
213                         return regulator_enable(loki_hdmi_vddio);
214         }
215         return 0;
216 }
217
218 /* Table of electrical characteristics for Roth HDMI.
219  * All modes must be declared here
220  */
221 struct tmds_config loki_tmds_config[] = {
222         { /* 720p / 74.25MHz modes */
223                 .pclk = 74250000,
224                 .pll0 = 0x01003f10,
225                 .pll1 = 0x10300b00,
226                 .pe_current = 0x00000000,
227                 .drive_current = 0x32323232,
228                 .peak_current = 0x05050505,
229         },
230         { /* 1080p / 148.5MHz modes */
231                 .pclk = 148500000,
232                 .pll0 = 0x01003f10,
233                 .pll1 = 0x10300b00,
234                 .pe_current = 0x00000000,
235                 .drive_current = 0x32323232,
236                 .peak_current = 0x05050505,
237         },
238         { /* 297MHz modes */
239                 .pclk = INT_MAX,
240                 .pll0 = 0x01003f10,
241                 .pll1 = 0x13300b00,
242                 .pe_current = 0x00000000,
243                 .drive_current = 0x36363636,
244                 .peak_current = 0x07070707,
245         },
246 };
247
248 struct tegra_hdmi_out loki_hdmi_out = {
249         .tmds_config = loki_tmds_config,
250         .n_tmds_config = 3,
251 };
252
253 static void loki_hdmi_hotplug_report(bool state)
254 {
255         if (state) {
256                 tegra_pinmux_set_pullupdown(TEGRA_PINGROUP_DDC_SDA,
257                                                 TEGRA_PUPD_PULL_DOWN);
258                 tegra_pinmux_set_pullupdown(TEGRA_PINGROUP_DDC_SCL,
259                                                 TEGRA_PUPD_PULL_DOWN);
260         } else {
261                 tegra_pinmux_set_pullupdown(TEGRA_PINGROUP_DDC_SDA,
262                                                 TEGRA_PUPD_NORMAL);
263                 tegra_pinmux_set_pullupdown(TEGRA_PINGROUP_DDC_SCL,
264                                                 TEGRA_PUPD_NORMAL);
265         }
266 }
267
268 static struct tegra_dc_out loki_disp2_out = {
269         .type           = TEGRA_DC_OUT_HDMI,
270         .flags          = TEGRA_DC_OUT_HOTPLUG_HIGH,
271         .parent_clk     = "pll_d2",
272
273         .dcc_bus        = 3,
274         .hotplug_gpio   = loki_hdmi_hpd,
275
276         .max_pixclock   = KHZ2PICOS(297000),
277
278         .align          = TEGRA_DC_ALIGN_MSB,
279         .order          = TEGRA_DC_ORDER_RED_BLUE,
280
281         .enable         = loki_hdmi_enable,
282         .disable        = loki_hdmi_disable,
283         .postsuspend    = loki_hdmi_postsuspend,
284         .hotplug_init   = loki_hdmi_hotplug_init,
285         .hotplug_report = loki_hdmi_hotplug_report,
286 };
287
288 static struct tegra_fb_data loki_disp1_fb_data = {
289         .win            = 0,
290         .bits_per_pixel = 32,
291 };
292
293 static struct tegra_dc_platform_data loki_disp1_pdata = {
294         .flags          = TEGRA_DC_FLAG_ENABLED,
295         .default_out    = &loki_disp1_out,
296         .fb             = &loki_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 loki_disp2_fb_data = {
304         .win            = 0,
305         .xres           = 1024,
306         .yres           = 600,
307         .bits_per_pixel = 32,
308 };
309
310 static struct tegra_dc_platform_data loki_disp2_pdata = {
311         .flags          = TEGRA_DC_FLAG_ENABLED,
312         .default_out    = &loki_disp2_out,
313         .fb             = &loki_disp2_fb_data,
314         .emc_clk_rate   = 300000000,
315 #ifdef CONFIG_TEGRA_DC_CMU
316         .cmu_enable     = 1,
317 #endif
318 };
319
320 static struct platform_device loki_disp2_device = {
321         .name           = "tegradc",
322         .id             = 1,
323         .resource       = loki_disp2_resources,
324         .num_resources  = ARRAY_SIZE(loki_disp2_resources),
325         .dev = {
326                 .platform_data = &loki_disp2_pdata,
327         },
328 };
329
330 static struct platform_device loki_disp1_device = {
331         .name           = "tegradc",
332         .id             = 0,
333         .resource       = loki_disp1_resources,
334         .num_resources  = ARRAY_SIZE(loki_disp1_resources),
335         .dev = {
336                 .platform_data = &loki_disp1_pdata,
337         },
338 };
339
340 static struct nvmap_platform_carveout loki_carveouts[] = {
341         [0] = {
342                 .name           = "iram",
343                 .usage_mask     = NVMAP_HEAP_CARVEOUT_IRAM,
344                 .base           = TEGRA_IRAM_BASE + TEGRA_RESET_HANDLER_SIZE,
345                 .size           = TEGRA_IRAM_SIZE - TEGRA_RESET_HANDLER_SIZE,
346         },
347         [1] = {
348                 .name           = "generic-0",
349                 .usage_mask     = NVMAP_HEAP_CARVEOUT_GENERIC,
350                 .base           = 0, /* Filled in by loki_panel_init() */
351                 .size           = 0, /* Filled in by loki_panel_init() */
352         },
353         [2] = {
354                 .name           = "vpr",
355                 .usage_mask     = NVMAP_HEAP_CARVEOUT_VPR,
356                 .base           = 0, /* Filled in by loki_panel_init() */
357                 .size           = 0, /* Filled in by loki_panel_init() */
358         },
359 };
360
361 static struct nvmap_platform_data loki_nvmap_data = {
362         .carveouts      = loki_carveouts,
363         .nr_carveouts   = ARRAY_SIZE(loki_carveouts),
364 };
365
366 static struct platform_device loki_nvmap_device = {
367         .name   = "tegra-nvmap",
368         .id     = -1,
369         .dev    = {
370                 .platform_data = &loki_nvmap_data,
371         },
372 };
373 static struct tegra_io_dpd dsic_io = {
374         .name                   = "DSIC",
375         .io_dpd_reg_index       = 1,
376         .io_dpd_bit             = 8,
377 };
378 static struct tegra_io_dpd dsid_io = {
379         .name                   = "DSID",
380         .io_dpd_reg_index       = 1,
381         .io_dpd_bit             = 9,
382 };
383 static struct tegra_dc_mode hdmi_panel_modes[] = {
384         {
385                 .pclk = 148500000,
386                 .h_ref_to_sync = 1,
387                 .v_ref_to_sync = 1,
388                 .h_sync_width = 44,
389                 .v_sync_width = 5,
390                 .h_back_porch = 148,
391                 .v_back_porch = 36,
392                 .h_active = 1920,
393                 .v_active = 1080,
394                 .h_front_porch = 88,
395                 .v_front_porch = 4,
396         },
397 };
398
399 static void loki_panel_select(void)
400 {
401         struct tegra_panel *panel;
402         struct board_info board;
403         u8 dsi_instance = DSI_INSTANCE_0;
404
405         tegra_get_display_board_info(&board);
406
407         switch (board.fab) {
408         case 0x2:
409                 panel = &dsi_j_720p_5;
410                 break;
411         case 0x1:
412                 panel = &dsi_j_1440_810_5_8;
413                 break;
414         case 0x0:
415         default:
416                 panel = &dsi_l_720p_5_loki;
417                 break;
418         }
419
420         tegra_io_dpd_enable(&dsic_io);
421         tegra_io_dpd_enable(&dsid_io);
422
423         if (panel) {
424                 if (panel->init_sd_settings)
425                         panel->init_sd_settings(&sd_settings);
426
427                 if (panel->init_dc_out) {
428                         panel->init_dc_out(&loki_disp1_out);
429                         loki_disp1_out.dsi->dsi_instance = dsi_instance;
430                         loki_disp1_out.dsi->dsi_panel_rst_gpio =
431                                 DSI_PANEL_RST_GPIO;
432                         loki_disp1_out.dsi->dsi_panel_bl_pwm_gpio =
433                                 DSI_PANEL_BL_PWM_GPIO;
434                         tegra_dsi_update_init_cmd_gpio_rst(&loki_disp1_out);
435                 }
436
437                 if (panel->init_fb_data)
438                         panel->init_fb_data(&loki_disp1_fb_data);
439
440                 if (panel->init_cmu_data)
441                         panel->init_cmu_data(&loki_disp1_pdata);
442
443                 if (panel->set_disp_device)
444                         panel->set_disp_device(&loki_disp1_device);
445
446                 if (panel->register_bl_dev)
447                         panel->register_bl_dev();
448         }
449 }
450
451 int __init loki_panel_init(int board_id)
452 {
453         int err = 0;
454         struct resource __maybe_unused *res;
455         struct platform_device *phost1x = NULL;
456         struct board_info bi;
457
458         tegra_get_board_info(&bi);
459         if ((bi.sku == BOARD_SKU_FOSTER) && (bi.board_id == BOARD_P2530)) {
460                 res = platform_get_resource_byname(&loki_disp2_device,
461                                          IORESOURCE_IRQ, "irq");
462                 res->start = INT_DISPLAY_GENERAL;
463                 res->end = INT_DISPLAY_GENERAL;
464                 res = platform_get_resource_byname(&loki_disp2_device,
465                                          IORESOURCE_MEM, "regs");
466                 res->start = TEGRA_DISPLAY_BASE;
467                 res->end = TEGRA_DISPLAY_BASE + TEGRA_DISPLAY_SIZE - 1;
468                 loki_disp2_fb_data.xres = 1920;
469                 loki_disp2_fb_data.yres = 1080;
470                 loki_disp2_device.id = 0;
471
472                 loki_disp2_out.modes = hdmi_panel_modes;
473                 loki_disp2_out.n_modes = ARRAY_SIZE(hdmi_panel_modes);
474         } else
475                 loki_panel_select();
476
477 #ifdef CONFIG_TEGRA_NVMAP
478         loki_carveouts[1].base = tegra_carveout_start;
479         loki_carveouts[1].size = tegra_carveout_size;
480         loki_carveouts[2].base = tegra_vpr_start;
481         loki_carveouts[2].size = tegra_vpr_size;
482 #ifdef CONFIG_NVMAP_USE_CMA_FOR_CARVEOUT
483         loki_carveouts[1].cma_dev = &tegra_generic_cma_dev;
484         loki_carveouts[1].resize = false;
485         loki_carveouts[2].cma_dev = &tegra_vpr_cma_dev;
486         loki_carveouts[2].resize = true;
487         loki_carveouts[2].cma_chunk_size = SZ_32M;
488 #endif
489
490         err = platform_device_register(&loki_nvmap_device);
491         if (err) {
492                 pr_err("nvmap device registration failed\n");
493                 return err;
494         }
495 #endif
496
497         phost1x = loki_host1x_init();
498         if (!phost1x) {
499                 pr_err("host1x devices registration failed\n");
500                 return -EINVAL;
501         }
502
503         res = platform_get_resource_byname(&loki_disp1_device,
504                                          IORESOURCE_MEM, "fbmem");
505         res->start = tegra_fb_start;
506         res->end = tegra_fb_start + tegra_fb_size - 1;
507
508         /* Copy the bootloader fb to the fb. */
509         __tegra_move_framebuffer(&loki_nvmap_device,
510                 tegra_fb_start, tegra_bootloader_fb_start,
511                         min(tegra_fb_size, tegra_bootloader_fb_size));
512
513         if (tegra_bootloader_fb2_size)
514                 __tegra_move_framebuffer(&loki_nvmap_device,
515                         tegra_fb2_start, tegra_bootloader_fb2_start,
516                         min(tegra_fb2_size, tegra_bootloader_fb2_size));
517         else
518                 __tegra_clear_framebuffer(&loki_nvmap_device,
519                                 tegra_fb2_start, tegra_fb2_size);
520
521         res = platform_get_resource_byname(&loki_disp2_device,
522                                          IORESOURCE_MEM, "fbmem");
523         res->start = tegra_fb2_start;
524         res->end = tegra_fb2_start + tegra_fb2_size - 1;
525
526         loki_disp1_device.dev.parent = &phost1x->dev;
527
528         if ((bi.sku != BOARD_SKU_FOSTER) || (bi.board_id != BOARD_P2530)) {
529                 err = platform_device_register(&loki_disp1_device);
530                 if (err) {
531                         pr_err("disp1 device registration failed\n");
532                         return err;
533                 }
534         }
535
536         loki_disp2_device.dev.parent = &phost1x->dev;
537         loki_disp2_out.hdmi_out = &loki_hdmi_out;
538         err = platform_device_register(&loki_disp2_device);
539         if (err) {
540                 pr_err("disp2 device registration failed\n");
541                 return err;
542         }
543
544 #ifdef CONFIG_TEGRA_NVAVP
545         nvavp_device.dev.parent = &phost1x->dev;
546         err = platform_device_register(&nvavp_device);
547         if (err) {
548                 pr_err("nvavp device registration failed\n");
549                 return err;
550         }
551 #endif
552         return err;
553 }
554 #else
555 int __init loki_panel_init(void)
556 {
557         if (loki_host1x_init())
558                 return 0;
559         else
560                 return -EINVAL;
561 }
562 #endif