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