1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
|
/*
* arch/arm/mach-tegra/board-ventana-panel.c
*
* Copyright (c) 2010, NVIDIA Corporation.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <linux/delay.h>
#include <linux/gpio.h>
#include <linux/regulator/consumer.h>
#include <linux/resource.h>
#include <asm/mach-types.h>
#include <linux/platform_device.h>
#include <linux/earlysuspend.h>
#include <linux/pwm_backlight.h>
#include <mach/nvhost.h>
#include <mach/nvmap.h>
#include <mach/irqs.h>
#include <mach/iomap.h>
#include <mach/dc.h>
#include <mach/fb.h>
#include "devices.h"
#include "gpio-names.h"
#include "board.h"
#define ventana_pnl_pwr_enb TEGRA_GPIO_PC6
#define ventana_bl_enb TEGRA_GPIO_PD4
#define ventana_lvds_shutdown TEGRA_GPIO_PB2
#define ventana_hdmi_hpd TEGRA_GPIO_PN7
#define ventana_hdmi_enb TEGRA_GPIO_PV5
static struct regulator *ventana_hdmi_reg = NULL;
static struct regulator *ventana_hdmi_pll = NULL;
static int ventana_backlight_init(struct device *dev) {
int ret;
ret = gpio_request(ventana_bl_enb, "backlight_enb");
if (ret < 0)
return ret;
ret = gpio_direction_output(ventana_bl_enb, 1);
if (ret < 0)
gpio_free(ventana_bl_enb);
else
tegra_gpio_enable(ventana_bl_enb);
return ret;
};
static void ventana_backlight_exit(struct device *dev) {
gpio_set_value(ventana_bl_enb, 0);
gpio_free(ventana_bl_enb);
tegra_gpio_disable(ventana_bl_enb);
}
static int ventana_backlight_notify(struct device *unused, int brightness)
{
gpio_set_value(ventana_bl_enb, !!brightness);
return brightness;
}
static struct platform_pwm_backlight_data ventana_backlight_data = {
.pwm_id = 2,
.max_brightness = 255,
.dft_brightness = 224,
.pwm_period_ns = 5000000,
.init = ventana_backlight_init,
.exit = ventana_backlight_exit,
.notify = ventana_backlight_notify,
};
static struct platform_device ventana_backlight_device = {
.name = "pwm-backlight",
.id = -1,
.dev = {
.platform_data = &ventana_backlight_data,
},
};
static int ventana_panel_enable(void)
{
gpio_set_value(ventana_pnl_pwr_enb, 1);
gpio_set_value(ventana_lvds_shutdown, 1);
return 0;
}
static int ventana_panel_disable(void)
{
gpio_set_value(ventana_lvds_shutdown, 0);
gpio_set_value(ventana_pnl_pwr_enb, 0);
return 0;
}
static int ventana_hdmi_enable(void)
{
if (!ventana_hdmi_reg) {
ventana_hdmi_reg = regulator_get(NULL, "avdd_hdmi"); /* LD07 */
if (IS_ERR_OR_NULL(ventana_hdmi_reg)) {
pr_err("hdmi: couldn't get regulator avdd_hdmi\n");
ventana_hdmi_reg = NULL;
return PTR_ERR(ventana_hdmi_reg);
}
}
regulator_enable(ventana_hdmi_reg);
if (!ventana_hdmi_pll) {
ventana_hdmi_pll = regulator_get(NULL, "avdd_hdmi_pll"); /* LD08 */
if (IS_ERR_OR_NULL(ventana_hdmi_pll)) {
pr_err("hdmi: couldn't get regulator avdd_hdmi_pll\n");
ventana_hdmi_pll = NULL;
regulator_disable(ventana_hdmi_reg);
ventana_hdmi_reg = NULL;
return PTR_ERR(ventana_hdmi_pll);
}
}
regulator_enable(ventana_hdmi_pll);
return 0;
}
static int ventana_hdmi_disable(void)
{
regulator_disable(ventana_hdmi_reg);
regulator_disable(ventana_hdmi_pll);
return 0;
}
static struct resource ventana_disp1_resources[] = {
{
.name = "irq",
.start = INT_DISPLAY_GENERAL,
.end = INT_DISPLAY_GENERAL,
.flags = IORESOURCE_IRQ,
},
{
.name = "regs",
.start = TEGRA_DISPLAY_BASE,
.end = TEGRA_DISPLAY_BASE + TEGRA_DISPLAY_SIZE-1,
.flags = IORESOURCE_MEM,
},
{
.name = "fbmem",
.flags = IORESOURCE_MEM,
},
};
static struct resource ventana_disp2_resources[] = {
{
.name = "irq",
.start = INT_DISPLAY_B_GENERAL,
.end = INT_DISPLAY_B_GENERAL,
.flags = IORESOURCE_IRQ,
},
{
.name = "regs",
.start = TEGRA_DISPLAY2_BASE,
.end = TEGRA_DISPLAY2_BASE + TEGRA_DISPLAY2_SIZE - 1,
.flags = IORESOURCE_MEM,
},
{
.name = "fbmem",
.flags = IORESOURCE_MEM,
},
{
.name = "hdmi_regs",
.start = TEGRA_HDMI_BASE,
.end = TEGRA_HDMI_BASE + TEGRA_HDMI_SIZE - 1,
.flags = IORESOURCE_MEM,
},
};
static struct tegra_dc_mode ventana_panel_modes[] = {
{
.pclk = 62200000,
.h_ref_to_sync = 11,
.v_ref_to_sync = 1,
.h_sync_width = 58,
.v_sync_width = 4,
.h_back_porch = 58,
.v_back_porch = 4,
.h_active = 1366,
.v_active = 768,
.h_front_porch = 58,
.v_front_porch = 4,
},
};
static struct tegra_fb_data ventana_fb_data = {
.win = 0,
.xres = 1366,
.yres = 768,
.bits_per_pixel = 32,
};
static struct tegra_fb_data ventana_hdmi_fb_data = {
.win = 0,
.xres = 1366,
.yres = 768,
.bits_per_pixel = 32,
};
static struct tegra_dc_out ventana_disp1_out = {
.type = TEGRA_DC_OUT_RGB,
.align = TEGRA_DC_ALIGN_MSB,
.order = TEGRA_DC_ORDER_RED_BLUE,
.modes = ventana_panel_modes,
.n_modes = ARRAY_SIZE(ventana_panel_modes),
.enable = ventana_panel_enable,
.disable = ventana_panel_disable,
};
static struct tegra_dc_out ventana_disp2_out = {
.type = TEGRA_DC_OUT_HDMI,
.flags = TEGRA_DC_OUT_HOTPLUG_HIGH,
.dcc_bus = 1,
.hotplug_gpio = ventana_hdmi_hpd,
.align = TEGRA_DC_ALIGN_MSB,
.order = TEGRA_DC_ORDER_RED_BLUE,
.enable = ventana_hdmi_enable,
.disable = ventana_hdmi_disable,
};
static struct tegra_dc_platform_data ventana_disp1_pdata = {
.flags = TEGRA_DC_FLAG_ENABLED,
.default_out = &ventana_disp1_out,
.fb = &ventana_fb_data,
};
static struct tegra_dc_platform_data ventana_disp2_pdata = {
.flags = 0,
.default_out = &ventana_disp2_out,
.fb = &ventana_hdmi_fb_data,
};
static struct nvhost_device ventana_disp1_device = {
.name = "tegradc",
.id = 0,
.resource = ventana_disp1_resources,
.num_resources = ARRAY_SIZE(ventana_disp1_resources),
.dev = {
.platform_data = &ventana_disp1_pdata,
},
};
static struct nvhost_device ventana_disp2_device = {
.name = "tegradc",
.id = 1,
.resource = ventana_disp2_resources,
.num_resources = ARRAY_SIZE(ventana_disp2_resources),
.dev = {
.platform_data = &ventana_disp2_pdata,
},
};
static struct nvmap_platform_carveout ventana_carveouts[] = {
[0] = {
.name = "iram",
.usage_mask = NVMAP_HEAP_CARVEOUT_IRAM,
.base = TEGRA_IRAM_BASE,
.size = TEGRA_IRAM_SIZE,
.buddy_size = 0, /* no buddy allocation for IRAM */
},
[1] = {
.name = "generic-0",
.usage_mask = NVMAP_HEAP_CARVEOUT_GENERIC,
.buddy_size = SZ_32K,
},
};
static struct nvmap_platform_data ventana_nvmap_data = {
.carveouts = ventana_carveouts,
.nr_carveouts = ARRAY_SIZE(ventana_carveouts),
};
static struct platform_device ventana_nvmap_device = {
.name = "tegra-nvmap",
.id = -1,
.dev = {
.platform_data = &ventana_nvmap_data,
},
};
static struct platform_device *ventana_gfx_devices[] __initdata = {
&ventana_nvmap_device,
&tegra_grhost_device,
&tegra_pwfm2_device,
&ventana_backlight_device,
};
#ifdef CONFIG_HAS_EARLYSUSPEND
/* put early_suspend/late_resume handlers here for the display in order
* to keep the code out of the display driver, keeping it closer to upstream
*/
struct early_suspend ventana_panel_early_suspender;
static void ventana_panel_early_suspend(struct early_suspend *h)
{
if (num_registered_fb > 0)
fb_blank(registered_fb[0], FB_BLANK_POWERDOWN);
}
static void ventana_panel_late_resume(struct early_suspend *h)
{
if (num_registered_fb > 0)
fb_blank(registered_fb[0], FB_BLANK_UNBLANK);
}
#endif
int __init ventana_panel_init(void)
{
int err;
struct resource *res;
gpio_request(ventana_pnl_pwr_enb, "pnl_pwr_enb");
gpio_direction_output(ventana_pnl_pwr_enb, 1);
tegra_gpio_enable(ventana_pnl_pwr_enb);
gpio_request(ventana_lvds_shutdown, "lvds_shdn");
gpio_direction_output(ventana_lvds_shutdown, 1);
tegra_gpio_enable(ventana_lvds_shutdown);
tegra_gpio_enable(ventana_hdmi_enb);
gpio_request(ventana_hdmi_enb, "hdmi_5v_en");
gpio_direction_output(ventana_hdmi_enb, 1);
tegra_gpio_enable(ventana_hdmi_hpd);
gpio_request(ventana_hdmi_hpd, "hdmi_hpd");
gpio_direction_input(ventana_hdmi_hpd);
#ifdef CONFIG_HAS_EARLYSUSPEND
ventana_panel_early_suspender.suspend = ventana_panel_early_suspend;
ventana_panel_early_suspender.resume = ventana_panel_late_resume;
ventana_panel_early_suspender.level = EARLY_SUSPEND_LEVEL_DISABLE_FB;
register_early_suspend(&ventana_panel_early_suspender);
#endif
ventana_carveouts[1].base = tegra_carveout_start;
ventana_carveouts[1].size = tegra_carveout_size;
err = platform_add_devices(ventana_gfx_devices,
ARRAY_SIZE(ventana_gfx_devices));
res = nvhost_get_resource_byname(&ventana_disp1_device,
IORESOURCE_MEM, "fbmem");
res->start = tegra_fb_start;
res->end = tegra_fb_start + tegra_fb_size - 1;
res = nvhost_get_resource_byname(&ventana_disp2_device,
IORESOURCE_MEM, "fbmem");
res->start = tegra_fb2_start;
res->end = tegra_fb2_start + tegra_fb2_size - 1;
if (!err)
err = nvhost_device_register(&ventana_disp1_device);
if (!err)
err = nvhost_device_register(&ventana_disp2_device);
return err;
}
|