ARM: tegra: fix regulator_get() return value check
[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 struct tegra_dc_sd_settings pismo_sd_settings = {
334         .enable = 1, /* enabled by default. */
335         .use_auto_pwm = false,
336         .hw_update_delay = 0,
337         .bin_width = -1,
338         .aggressiveness = 5,
339         .use_vid_luma = false,
340         .phase_in_adjustments = 0,
341         .k_limit_enable = true,
342         .k_limit = 200,
343         .sd_window_enable = false,
344         .soft_clipping_enable = true,
345         /* Low soft clipping threshold to compensate for aggressive k_limit */
346         .soft_clipping_threshold = 128,
347         .smooth_k_enable = false,
348         .smooth_k_incr = 64,
349         /* Default video coefficients */
350         .coeff = {5, 9, 2},
351         .fc = {0, 0},
352         /* Immediate backlight changes */
353         .blp = {1024, 255},
354         /* Gammas: R: 2.2 G: 2.2 B: 2.2 */
355         /* Default BL TF */
356         .bltf = {
357                         {
358                                 {57, 65, 73, 82},
359                                 {92, 103, 114, 125},
360                                 {138, 150, 164, 178},
361                                 {193, 208, 224, 241},
362                         },
363                 },
364         /* Default LUT */
365         .lut = {
366                         {
367                                 {255, 255, 255},
368                                 {199, 199, 199},
369                                 {153, 153, 153},
370                                 {116, 116, 116},
371                                 {85, 85, 85},
372                                 {59, 59, 59},
373                                 {36, 36, 36},
374                                 {17, 17, 17},
375                                 {0, 0, 0},
376                         },
377                 },
378         .sd_brightness = &sd_brightness,
379         .use_vpulse2 = true,
380 };
381
382 static void pismo_panel_select(void)
383 {
384         struct tegra_panel *panel = NULL;
385
386         panel = &dsi_a_1080p_11_6;
387         if (panel) {
388                 if (panel->init_sd_settings)
389                         panel->init_sd_settings(&pismo_sd_settings);
390
391                 if (panel->init_dc_out) {
392                         panel->init_dc_out(&pismo_disp1_out);
393                         pismo_disp1_out.dsi->dsi_instance = DSI_INSTANCE_0;
394                         pismo_disp1_out.dsi->dsi_panel_rst_gpio =
395                                 DSI_PANEL_RST_GPIO;
396                         pismo_disp1_out.dsi->dsi_panel_bl_pwm_gpio =
397                                 DSI_PANEL_BL_PWM_GPIO;
398                 }
399
400                 if (panel->init_fb_data)
401                         panel->init_fb_data(&pismo_disp1_fb_data);
402
403                 if (panel->init_cmu_data)
404                         panel->init_cmu_data(&pismo_disp1_pdata);
405
406                 if (panel->set_disp_device)
407                         panel->set_disp_device(&pismo_disp1_device);
408
409                 tegra_dsi_resources_init(pismo_disp1_out.dsi->dsi_instance,
410                         pismo_disp1_resources,
411                         ARRAY_SIZE(pismo_disp1_resources));
412
413                 if (panel->register_bl_dev)
414                         panel->register_bl_dev();
415
416                 if (panel->register_i2c_bridge)
417                         panel->register_i2c_bridge();
418         }
419
420 }
421 int __init pismo_panel_init(void)
422 {
423         int err = 0;
424         struct resource __maybe_unused *res;
425         struct platform_device *phost1x = NULL;
426
427         sd_settings = pismo_sd_settings;
428
429         pismo_panel_select();
430
431 #ifdef CONFIG_TEGRA_NVMAP
432         pismo_carveouts[1].base = tegra_carveout_start;
433         pismo_carveouts[1].size = tegra_carveout_size;
434         pismo_carveouts[2].base = tegra_vpr_start;
435         pismo_carveouts[2].size = tegra_vpr_size;
436
437         err = platform_device_register(&pismo_nvmap_device);
438         if (err) {
439                 pr_err("nvmap device registration failed\n");
440                 return err;
441         }
442 #endif
443
444         phost1x = pismo_host1x_init();
445         if (!phost1x) {
446                 pr_err("host1x devices registration failed\n");
447                 return -EINVAL;
448         }
449
450         res = platform_get_resource_byname(&pismo_disp1_device,
451                                          IORESOURCE_MEM, "fbmem");
452         res->start = tegra_fb_start;
453         res->end = tegra_fb_start + tegra_fb_size - 1;
454
455         /* Copy the bootloader fb to the fb. */
456         __tegra_move_framebuffer(&pismo_nvmap_device,
457                 tegra_fb_start, tegra_bootloader_fb_start,
458                         min(tegra_fb_size, tegra_bootloader_fb_size));
459
460         pismo_disp1_device.dev.parent = &phost1x->dev;
461         err = platform_device_register(&pismo_disp1_device);
462         if (err) {
463                 pr_err("disp1 device registration failed\n");
464                 return err;
465         }
466
467         err = tegra_init_hdmi(&pismo_disp2_device, phost1x);
468         if (err)
469                 return err;
470
471 #ifdef CONFIG_TEGRA_NVAVP
472         nvavp_device.dev.parent = &phost1x->dev;
473         err = platform_device_register(&nvavp_device);
474         if (err) {
475                 pr_err("nvavp device registration failed\n");
476                 return err;
477         }
478 #endif
479         return err;
480 }