arm: tegra: move sd_settings to the panel board file
[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(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(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 void macallan_panel_select(void)
339 {
340         struct tegra_panel *panel = NULL;
341         struct board_info board;
342         u8 dsi_instance = DSI_INSTANCE_0;
343
344         tegra_get_display_board_info(&board);
345
346         switch (board.board_id) {
347         case BOARD_E1639:
348                 panel = &dsi_s_wqxga_10_1;
349                 break;
350         default:
351                 panel = &dsi_p_wuxga_10_1;
352                 break;
353         }
354         if (panel) {
355                 if (panel->init_sd_settings)
356                         panel->init_sd_settings(&sd_settings);
357
358                 if (panel->init_dc_out) {
359                         panel->init_dc_out(&macallan_disp1_out);
360                         macallan_disp1_out.dsi->dsi_instance = dsi_instance;
361                         macallan_disp1_out.dsi->dsi_panel_rst_gpio =
362                                 DSI_PANEL_RST_GPIO;
363                         macallan_disp1_out.dsi->dsi_panel_bl_pwm_gpio =
364                                 DSI_PANEL_BL_PWM_GPIO;
365                 }
366
367                 if (panel->init_fb_data)
368                         panel->init_fb_data(&macallan_disp1_fb_data);
369
370                 if (panel->init_cmu_data)
371                         panel->init_cmu_data(&macallan_disp1_pdata);
372
373                 if (panel->set_disp_device)
374                         panel->set_disp_device(&macallan_disp1_device);
375
376                 tegra_dsi_resources_init(dsi_instance, macallan_disp1_resources,
377                                  ARRAY_SIZE(macallan_disp1_resources));
378
379                 if (panel->register_bl_dev)
380                         panel->register_bl_dev();
381
382                 if (panel->register_i2c_bridge)
383                         panel->register_i2c_bridge();
384         }
385
386 }
387 int __init macallan_panel_init(void)
388 {
389         int err = 0;
390         struct resource __maybe_unused *res;
391         struct platform_device *phost1x = NULL;
392
393         macallan_panel_select();
394
395 #ifdef CONFIG_TEGRA_NVMAP
396         macallan_carveouts[1].base = tegra_carveout_start;
397         macallan_carveouts[1].size = tegra_carveout_size;
398         macallan_carveouts[2].base = tegra_vpr_start;
399         macallan_carveouts[2].size = tegra_vpr_size;
400
401         err = platform_device_register(&macallan_nvmap_device);
402         if (err) {
403                 pr_err("nvmap device registration failed\n");
404                 return err;
405         }
406 #endif
407
408         phost1x = macallan_host1x_init();
409         if (!phost1x) {
410                 pr_err("host1x devices registration failed\n");
411                 return -EINVAL;
412         }
413
414         res = platform_get_resource_byname(&macallan_disp1_device,
415                                          IORESOURCE_MEM, "fbmem");
416         res->start = tegra_fb_start;
417         res->end = tegra_fb_start + tegra_fb_size - 1;
418
419         /* Copy the bootloader fb to the fb. */
420         __tegra_move_framebuffer(&macallan_nvmap_device,
421                 tegra_fb_start, tegra_bootloader_fb_start,
422                         min(tegra_fb_size, tegra_bootloader_fb_size));
423
424         macallan_disp1_device.dev.parent = &phost1x->dev;
425         err = platform_device_register(&macallan_disp1_device);
426         if (err) {
427                 pr_err("disp1 device registration failed\n");
428                 return err;
429         }
430
431         err = tegra_init_hdmi(&macallan_disp2_device, phost1x);
432         if (err)
433                 return err;
434
435 #ifdef CONFIG_TEGRA_NVAVP
436         nvavp_device.dev.parent = &phost1x->dev;
437         err = platform_device_register(&nvavp_device);
438         if (err) {
439                 pr_err("nvavp device registration failed\n");
440                 return err;
441         }
442 #endif
443         return err;
444 }
445 #else
446 int __init macallan_panel_init(void)
447 {
448         if (macallan_host1x_init())
449                 return 0;
450         else
451                 return -EINVAL;
452 }
453 #endif