Revert "Merge commit 'main-jb-2012.08.03-B4' into t114-0806"
[linux-2.6.git] / arch / arm / mach-tegra / board-aruba-panel.c
1 /*
2  * arch/arm/mach-tegra/board-aruba-panel.c
3  *
4  * Copyright (c) 2010-2012, NVIDIA Corporation.
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
21 #include <linux/delay.h>
22 #include <linux/gpio.h>
23 #include <linux/regulator/consumer.h>
24 #include <linux/resource.h>
25 #include <asm/mach-types.h>
26 #include <linux/platform_device.h>
27 #include <linux/pwm_backlight.h>
28 #include <linux/nvhost.h>
29 #include <linux/nvmap.h>
30 #include <mach/irqs.h>
31 #include <mach/iomap.h>
32 #include <mach/dc.h>
33 #include <mach/fb.h>
34
35 #include "board.h"
36 #include "devices.h"
37 #include "gpio-names.h"
38 #include "tegra2_host1x_devices.h"
39
40 #define aruba_lvds_shutdown     TEGRA_GPIO_PB2
41 #define aruba_bl_enb            TEGRA_GPIO_PW1
42
43 static int aruba_backlight_init(struct device *dev) {
44         int ret;
45
46         ret = gpio_request(aruba_bl_enb, "backlight_enb");
47         if (ret < 0)
48                 return ret;
49
50         ret = gpio_direction_output(aruba_bl_enb, 1);
51         if (ret < 0)
52                 gpio_free(aruba_bl_enb);
53         else
54                 tegra_gpio_enable(aruba_bl_enb);
55
56         return ret;
57 };
58
59 static void aruba_backlight_exit(struct device *dev) {
60         gpio_set_value(aruba_bl_enb, 0);
61         gpio_free(aruba_bl_enb);
62         tegra_gpio_disable(aruba_bl_enb);
63 }
64
65 static int aruba_backlight_notify(struct device *unused, int brightness)
66 {
67         gpio_set_value(aruba_bl_enb, !!brightness);
68         return brightness;
69 }
70
71 static struct platform_pwm_backlight_data aruba_backlight_data = {
72         .pwm_id         = 2,
73         .max_brightness = 255,
74         .dft_brightness = 224,
75         .pwm_period_ns  = 5000000,
76         .init           = aruba_backlight_init,
77         .exit           = aruba_backlight_exit,
78         .notify         = aruba_backlight_notify,
79 };
80
81 static struct platform_device aruba_backlight_device = {
82         .name   = "pwm-backlight",
83         .id     = -1,
84         .dev    = {
85                 .platform_data = &aruba_backlight_data,
86         },
87 };
88
89 #ifdef CONFIG_TEGRA_DC
90 static int aruba_panel_enable(void)
91 {
92         static struct regulator *reg = NULL;
93
94         if (reg == NULL) {
95                 reg = regulator_get(NULL, "avdd_lvds");
96                 if (WARN_ON(IS_ERR(reg)))
97                         pr_err("%s: couldn't get regulator avdd_lvds: %ld\n",
98                                __func__, PTR_ERR(reg));
99                 else
100                         regulator_enable(reg);
101         }
102
103         gpio_set_value(aruba_lvds_shutdown, 1);
104         return 0;
105 }
106
107 static int aruba_panel_disable(void)
108 {
109         gpio_set_value(aruba_lvds_shutdown, 0);
110         return 0;
111 }
112
113 static struct resource aruba_disp1_resources[] = {
114         {
115                 .name   = "irq",
116                 .start  = INT_DISPLAY_GENERAL,
117                 .end    = INT_DISPLAY_GENERAL,
118                 .flags  = IORESOURCE_IRQ,
119         },
120         {
121                 .name   = "regs",
122                 .start  = TEGRA_DISPLAY_BASE,
123                 .end    = TEGRA_DISPLAY_BASE + TEGRA_DISPLAY_SIZE-1,
124                 .flags  = IORESOURCE_MEM,
125         },
126         {
127                 .name   = "fbmem",
128                 .start  = 0,    /* Filled in by aruba_panel_init() */
129                 .end    = 0,    /* Filled in by aruba_panel_init() */
130                 .flags  = IORESOURCE_MEM,
131         },
132 };
133
134 static struct tegra_dc_mode aruba_panel_modes[] = {
135         {
136                 .pclk = 18000000,
137                 .h_ref_to_sync = 8,
138                 .v_ref_to_sync = 2,
139                 .h_sync_width = 4,
140                 .v_sync_width = 1,
141                 .h_back_porch = 20,
142                 .v_back_porch = 7,
143                 .h_active = 480,
144                 .v_active = 640,
145                 .h_front_porch = 8,
146                 .v_front_porch = 8,
147         },
148 };
149
150 static struct tegra_fb_data aruba_fb_data = {
151         .win            = 0,
152         .xres           = 480,
153         .yres           = 640,
154         .bits_per_pixel = 16,
155 };
156
157 static struct tegra_dc_out aruba_disp1_out = {
158         .type           = TEGRA_DC_OUT_RGB,
159
160         .align          = TEGRA_DC_ALIGN_MSB,
161         .order          = TEGRA_DC_ORDER_RED_BLUE,
162
163         .modes          = aruba_panel_modes,
164         .n_modes        = ARRAY_SIZE(aruba_panel_modes),
165
166         .enable         = aruba_panel_enable,
167         .disable        = aruba_panel_disable,
168 };
169
170 static struct tegra_dc_platform_data aruba_disp1_pdata = {
171         .flags          = TEGRA_DC_FLAG_ENABLED,
172         .default_out    = &aruba_disp1_out,
173         .fb             = &aruba_fb_data,
174 };
175
176 static struct nvhost_device aruba_disp1_device = {
177         .name           = "tegradc",
178         .id             = 0,
179         .resource       = aruba_disp1_resources,
180         .num_resources  = ARRAY_SIZE(aruba_disp1_resources),
181         .dev = {
182                 .platform_data = &aruba_disp1_pdata,
183         },
184 };
185 #endif
186
187 #if defined(CONFIG_TEGRA_NVMAP)
188 static struct nvmap_platform_carveout aruba_carveouts[] = {
189         [0] = NVMAP_HEAP_CARVEOUT_IRAM_INIT,
190         [1] = {
191                 .name           = "generic-0",
192                 .usage_mask     = NVMAP_HEAP_CARVEOUT_GENERIC,
193                 .base           = 0,    /* Filled in by aruba_panel_init() */
194                 .size           = 0,    /* Filled in by aruba_panel_init() */
195                 .buddy_size     = SZ_32K,
196         },
197 };
198
199 static struct nvmap_platform_data aruba_nvmap_data = {
200         .carveouts      = aruba_carveouts,
201         .nr_carveouts   = ARRAY_SIZE(aruba_carveouts),
202 };
203
204 static struct platform_device aruba_nvmap_device = {
205         .name   = "tegra-nvmap",
206         .id     = -1,
207         .dev    = {
208                 .platform_data = &aruba_nvmap_data,
209         },
210 };
211 #endif
212
213 static struct platform_device *aruba_gfx_devices[] __initdata = {
214 #if defined(CONFIG_TEGRA_NVMAP)
215         &aruba_nvmap_device,
216 #endif
217         &tegra_pwfm2_device,
218         &aruba_backlight_device,
219 };
220
221 int __init aruba_panel_init(void)
222 {
223         int err;
224         struct resource __maybe_unused *res;
225
226 #if defined(CONFIG_TEGRA_NVMAP)
227         aruba_carveouts[1].base = tegra_carveout_start;
228         aruba_carveouts[1].size = tegra_carveout_size;
229 #endif
230
231 #ifdef CONFIG_TEGRA_GRHOST
232         err = tegra2_register_host1x_devices();
233         if (err)
234                 return err;
235 #endif
236
237         err = platform_add_devices(aruba_gfx_devices,
238                                    ARRAY_SIZE(aruba_gfx_devices));
239
240 #if defined(CONFIG_TEGRA_GRHOST) && defined(CONFIG_TEGRA_DC)
241         res = nvhost_get_resource_byname(&aruba_disp1_device,
242                                          IORESOURCE_MEM, "fbmem");
243         res->start = tegra_fb_start;
244         res->end = tegra_fb_start + tegra_fb_size - 1;
245 #endif
246
247         /* Copy the bootloader fb to the fb. */
248         tegra_move_framebuffer(tegra_fb_start, tegra_bootloader_fb_start,
249                                 min(tegra_fb_size, tegra_bootloader_fb_size));
250
251 #if defined(CONFIG_TEGRA_GRHOST) && defined(CONFIG_TEGRA_DC)
252         if (!err)
253                 err = nvhost_device_register(&aruba_disp1_device);
254 #endif
255
256         return err;
257 }