ARM: tegra12: set CPU rate to 2.2GHz for sku 0x87
[linux-3.10.git] / arch / arm / mach-tegra / board-pismo-panel.c
1 /*
2  * arch/arm/mach-tegra/board-pismo-panel.c
3  *
4  * Copyright (c) 2011-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 #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 pismo_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 /* HDMI Hotplug detection pin */
61 #define pismo_hdmi_hpd  TEGRA_GPIO_PN7
62
63 static struct regulator *pismo_hdmi_reg;
64 static struct regulator *pismo_hdmi_pll;
65 static struct regulator *pismo_hdmi_vddio;
66
67 static struct resource pismo_disp1_resources[] = {
68         {
69                 .name   = "irq",
70                 .start  = INT_DISPLAY_GENERAL,
71                 .end    = INT_DISPLAY_GENERAL,
72                 .flags  = IORESOURCE_IRQ,
73         },
74         {
75                 .name   = "regs",
76                 .start  = TEGRA_DISPLAY_BASE,
77                 .end    = TEGRA_DISPLAY_BASE + TEGRA_DISPLAY_SIZE - 1,
78                 .flags  = IORESOURCE_MEM,
79         },
80         {
81                 .name   = "fbmem",
82                 .start  = 0, /* Filled in by pismo_panel_init() */
83                 .end    = 0, /* Filled in by pismo_panel_init() */
84                 .flags  = IORESOURCE_MEM,
85         },
86         {
87                 .name   = "ganged_dsia_regs",
88                 .start  = 0, /* Filled in the panel file by init_resources() */
89                 .end    = 0, /* Filled in the panel file by init_resources() */
90                 .flags  = IORESOURCE_MEM,
91         },
92         {
93                 .name   = "ganged_dsib_regs",
94                 .start  = 0, /* Filled in the panel file by init_resources() */
95                 .end    = 0, /* Filled in the panel file by init_resources() */
96                 .flags  = IORESOURCE_MEM,
97         },
98         {
99                 .name   = "dsi_regs",
100                 .start  = 0, /* Filled in the panel file by init_resources() */
101                 .end    = 0, /* Filled in the panel file by init_resources() */
102                 .flags  = IORESOURCE_MEM,
103         },
104         {
105                 .name   = "mipi_cal",
106                 .start  = TEGRA_MIPI_CAL_BASE,
107                 .end    = TEGRA_MIPI_CAL_BASE + TEGRA_MIPI_CAL_SIZE - 1,
108                 .flags  = IORESOURCE_MEM,
109         },
110 };
111
112 static struct resource pismo_disp2_resources[] = {
113         {
114                 .name   = "irq",
115                 .start  = INT_DISPLAY_B_GENERAL,
116                 .end    = INT_DISPLAY_B_GENERAL,
117                 .flags  = IORESOURCE_IRQ,
118         },
119         {
120                 .name   = "regs",
121                 .start  = TEGRA_DISPLAY2_BASE,
122                 .end    = TEGRA_DISPLAY2_BASE + TEGRA_DISPLAY2_SIZE - 1,
123                 .flags  = IORESOURCE_MEM,
124         },
125         {
126                 .name   = "fbmem",
127                 .start  = 0, /* Filled in by pismo_panel_init() */
128                 .end    = 0, /* Filled in by pismo_panel_init() */
129                 .flags  = IORESOURCE_MEM,
130         },
131         {
132                 .name   = "hdmi_regs",
133                 .start  = TEGRA_HDMI_BASE,
134                 .end    = TEGRA_HDMI_BASE + TEGRA_HDMI_SIZE - 1,
135                 .flags  = IORESOURCE_MEM,
136         },
137 };
138
139
140 static struct tegra_dc_sd_settings sd_settings;
141
142 static struct tegra_dc_out pismo_disp1_out = {
143         .type           = TEGRA_DC_OUT_DSI,
144         .sd_settings    = &sd_settings,
145 };
146
147 static int pismo_hdmi_enable(struct device *dev)
148 {
149         int ret;
150         if (!pismo_hdmi_reg) {
151                 pismo_hdmi_reg = regulator_get(dev, "avdd_hdmi");
152                 if (IS_ERR(pismo_hdmi_reg)) {
153                         pr_err("hdmi: couldn't get regulator avdd_hdmi\n");
154                         pismo_hdmi_reg = NULL;
155                         return PTR_ERR(pismo_hdmi_reg);
156                 }
157         }
158         ret = regulator_enable(pismo_hdmi_reg);
159         if (ret < 0) {
160                 pr_err("hdmi: couldn't enable regulator avdd_hdmi\n");
161                 return ret;
162         }
163         if (!pismo_hdmi_pll) {
164                 pismo_hdmi_pll = regulator_get(dev, "avdd_hdmi_pll");
165                 if (IS_ERR(pismo_hdmi_pll)) {
166                         pr_err("hdmi: couldn't get regulator avdd_hdmi_pll\n");
167                         pismo_hdmi_pll = NULL;
168                         regulator_put(pismo_hdmi_reg);
169                         pismo_hdmi_reg = NULL;
170                         return PTR_ERR(pismo_hdmi_pll);
171                 }
172         }
173         ret = regulator_enable(pismo_hdmi_pll);
174         if (ret < 0) {
175                 pr_err("hdmi: couldn't enable regulator avdd_hdmi_pll\n");
176                 return ret;
177         }
178         return 0;
179 }
180
181 static int pismo_hdmi_disable(void)
182 {
183         if (pismo_hdmi_reg) {
184                 regulator_disable(pismo_hdmi_reg);
185                 regulator_put(pismo_hdmi_reg);
186                 pismo_hdmi_reg = NULL;
187         }
188
189         if (pismo_hdmi_pll) {
190                 regulator_disable(pismo_hdmi_pll);
191                 regulator_put(pismo_hdmi_pll);
192                 pismo_hdmi_pll = NULL;
193         }
194
195         return 0;
196 }
197
198 static int pismo_hdmi_postsuspend(void)
199 {
200         if (pismo_hdmi_vddio) {
201                 regulator_disable(pismo_hdmi_vddio);
202                 regulator_put(pismo_hdmi_vddio);
203                 pismo_hdmi_vddio = NULL;
204         }
205         return 0;
206 }
207
208 static int pismo_hdmi_hotplug_init(struct device *dev)
209 {
210         if (!pismo_hdmi_vddio) {
211                 pismo_hdmi_vddio = regulator_get(dev, "vdd_hdmi_5v0");
212                 if (WARN_ON(IS_ERR(pismo_hdmi_vddio))) {
213                         pr_err("%s: couldn't get regulator vdd_hdmi_5v0: %ld\n",
214                                 __func__, PTR_ERR(pismo_hdmi_vddio));
215                                 pismo_hdmi_vddio = NULL;
216                 } else {
217                         regulator_enable(pismo_hdmi_vddio);
218                 }
219         }
220
221         return 0;
222 }
223
224 static struct tegra_dc_out pismo_disp2_out = {
225         .type           = TEGRA_DC_OUT_HDMI,
226         .flags          = TEGRA_DC_OUT_HOTPLUG_HIGH,
227         .parent_clk     = "pll_d2_out0",
228
229         .dcc_bus        = 3,
230         .hotplug_gpio   = pismo_hdmi_hpd,
231
232         .max_pixclock   = KHZ2PICOS(148500),
233
234         .align          = TEGRA_DC_ALIGN_MSB,
235         .order          = TEGRA_DC_ORDER_RED_BLUE,
236
237         .enable         = pismo_hdmi_enable,
238         .disable        = pismo_hdmi_disable,
239         .postsuspend    = pismo_hdmi_postsuspend,
240         .hotplug_init   = pismo_hdmi_hotplug_init,
241 };
242
243 static struct tegra_fb_data pismo_disp1_fb_data = {
244         .win            = 0,
245         .bits_per_pixel = 32,
246         .flags          = TEGRA_FB_FLIP_ON_PROBE,
247 };
248
249 static struct tegra_dc_platform_data pismo_disp1_pdata = {
250         .flags          = TEGRA_DC_FLAG_ENABLED,
251         .default_out    = &pismo_disp1_out,
252         .fb             = &pismo_disp1_fb_data,
253         .emc_clk_rate   = 204000000,
254 #ifdef CONFIG_TEGRA_DC_CMU
255         .cmu_enable     = 1,
256 #endif
257 };
258
259 static struct tegra_fb_data pismo_disp2_fb_data = {
260         .win            = 0,
261         .xres           = 1280,
262         .yres           = 720,
263         .bits_per_pixel = 32,
264         .flags          = TEGRA_FB_FLIP_ON_PROBE,
265 };
266
267 static struct tegra_dc_platform_data pismo_disp2_pdata = {
268         .flags          = TEGRA_DC_FLAG_ENABLED,
269         .default_out    = &pismo_disp2_out,
270         .fb             = &pismo_disp2_fb_data,
271         .emc_clk_rate   = 300000000,
272 #ifdef CONFIG_TEGRA_DC_CMU
273         .cmu_enable     = 1,
274 #endif
275 };
276
277 static struct platform_device pismo_disp2_device = {
278         .name           = "tegradc",
279         .id             = 1,
280         .resource       = pismo_disp2_resources,
281         .num_resources  = ARRAY_SIZE(pismo_disp2_resources),
282         .dev = {
283                 .platform_data = &pismo_disp2_pdata,
284         },
285 };
286
287 static struct platform_device pismo_disp1_device = {
288         .name           = "tegradc",
289         .id             = 0,
290         .resource       = pismo_disp1_resources,
291         .num_resources  = ARRAY_SIZE(pismo_disp1_resources),
292         .dev = {
293                 .platform_data = &pismo_disp1_pdata,
294         },
295 };
296
297 static struct nvmap_platform_carveout pismo_carveouts[] = {
298         [0] = {
299                 .name           = "iram",
300                 .usage_mask     = NVMAP_HEAP_CARVEOUT_IRAM,
301                 .base           = TEGRA_IRAM_BASE + TEGRA_RESET_HANDLER_SIZE,
302                 .size           = TEGRA_IRAM_SIZE - TEGRA_RESET_HANDLER_SIZE,
303                 .buddy_size     = 0, /* no buddy allocation for IRAM */
304         },
305         [1] = {
306                 .name           = "generic-0",
307                 .usage_mask     = NVMAP_HEAP_CARVEOUT_GENERIC,
308                 .base           = 0, /* Filled in by pismo_panel_init() */
309                 .size           = 0, /* Filled in by pismo_panel_init() */
310                 .buddy_size     = SZ_32K,
311         },
312         [2] = {
313                 .name           = "vpr",
314                 .usage_mask     = NVMAP_HEAP_CARVEOUT_VPR,
315                 .base           = 0, /* Filled in by pismo_panel_init() */
316                 .size           = 0, /* Filled in by pismo_panel_init() */
317                 .buddy_size     = SZ_32K,
318         },
319 };
320
321 static struct nvmap_platform_data pismo_nvmap_data = {
322         .carveouts      = pismo_carveouts,
323         .nr_carveouts   = ARRAY_SIZE(pismo_carveouts),
324 };
325 static struct platform_device pismo_nvmap_device = {
326         .name   = "tegra-nvmap",
327         .id     = -1,
328         .dev    = {
329                 .platform_data = &pismo_nvmap_data,
330         },
331 };
332
333 static void pismo_panel_select(void)
334 {
335         struct tegra_panel *panel = NULL;
336
337         panel = &dsi_a_1080p_11_6;
338         if (panel) {
339                 if (panel->init_sd_settings)
340                         panel->init_sd_settings(&sd_settings);
341
342                 if (panel->init_dc_out) {
343                         panel->init_dc_out(&pismo_disp1_out);
344                         pismo_disp1_out.dsi->dsi_instance = DSI_INSTANCE_0;
345                         pismo_disp1_out.dsi->dsi_panel_rst_gpio =
346                                 DSI_PANEL_RST_GPIO;
347                         pismo_disp1_out.dsi->dsi_panel_bl_pwm_gpio =
348                                 DSI_PANEL_BL_PWM_GPIO;
349                 }
350
351                 if (panel->init_fb_data)
352                         panel->init_fb_data(&pismo_disp1_fb_data);
353
354                 if (panel->init_cmu_data)
355                         panel->init_cmu_data(&pismo_disp1_pdata);
356
357                 if (panel->set_disp_device)
358                         panel->set_disp_device(&pismo_disp1_device);
359
360                 tegra_dsi_resources_init(pismo_disp1_out.dsi->dsi_instance,
361                         pismo_disp1_resources,
362                         ARRAY_SIZE(pismo_disp1_resources));
363
364                 if (panel->register_bl_dev)
365                         panel->register_bl_dev();
366
367                 if (panel->register_i2c_bridge)
368                         panel->register_i2c_bridge();
369         }
370
371 }
372 int __init pismo_panel_init(void)
373 {
374         int err = 0;
375         struct resource __maybe_unused *res;
376         struct platform_device *phost1x = NULL;
377
378         pismo_panel_select();
379
380 #ifdef CONFIG_TEGRA_NVMAP
381         pismo_carveouts[1].base = tegra_carveout_start;
382         pismo_carveouts[1].size = tegra_carveout_size;
383         pismo_carveouts[2].base = tegra_vpr_start;
384         pismo_carveouts[2].size = tegra_vpr_size;
385
386         err = platform_device_register(&pismo_nvmap_device);
387         if (err) {
388                 pr_err("nvmap device registration failed\n");
389                 return err;
390         }
391 #endif
392
393         phost1x = pismo_host1x_init();
394         if (!phost1x) {
395                 pr_err("host1x devices registration failed\n");
396                 return -EINVAL;
397         }
398
399         res = platform_get_resource_byname(&pismo_disp1_device,
400                                          IORESOURCE_MEM, "fbmem");
401         res->start = tegra_fb_start;
402         res->end = tegra_fb_start + tegra_fb_size - 1;
403
404         /* Copy the bootloader fb to the fb. */
405         __tegra_move_framebuffer(&pismo_nvmap_device,
406                 tegra_fb_start, tegra_bootloader_fb_start,
407                         min(tegra_fb_size, tegra_bootloader_fb_size));
408
409         pismo_disp1_device.dev.parent = &phost1x->dev;
410         err = platform_device_register(&pismo_disp1_device);
411         if (err) {
412                 pr_err("disp1 device registration failed\n");
413                 return err;
414         }
415
416         err = tegra_init_hdmi(&pismo_disp2_device, phost1x);
417         if (err)
418                 return err;
419
420 #ifdef CONFIG_TEGRA_NVAVP
421         nvavp_device.dev.parent = &phost1x->dev;
422         err = platform_device_register(&nvavp_device);
423         if (err) {
424                 pr_err("nvavp device registration failed\n");
425                 return err;
426         }
427 #endif
428         return err;
429 }