aboutsummaryrefslogtreecommitdiff
path: root/arch/arm/mach-ux500/board-mop500-mcde.c
blob: ef1a727416128827d5c2aa1bd7c1b0398283f03d (plain)
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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
/*
 * Copyright (C) ST-Ericsson AB 2010
 *
 * Author: Marcus Lorentzon <marcus.xm.lorentzon@stericsson.com>
 * for ST-Ericsson.
 *
 * License terms: GNU General Public License (GPL), version 2.
 */
#include <linux/platform_device.h>
#include <mach/tc35892.h>
#include <mach/ab8500_denc.h>
#include <video/av8100.h>
#include <video/mcde_display.h>
#include <video/mcde_display-generic_dsi.h>
#include <video/mcde_display-av8100.h>
#include <video/mcde_display-ab8500.h>
#include <video/mcde_fb.h>
#include <video/mcde_dss.h>

#define DSI_UNIT_INTERVAL_0	0x9
#define DSI_UNIT_INTERVAL_1	0x9
#define DSI_UNIT_INTERVAL_2	0x6

static bool rotate_main = true;
static bool display_initialized_during_boot;

static int __init startup_graphics_setup(char *str)
{
	if (!str)
		return 1;

	switch (*str) {
	case '0':
		pr_info("No Startup graphics support\n");
		display_initialized_during_boot = false;
		break;
	case '1':
		pr_info("Startup graphics supported\n");
		display_initialized_during_boot = true;
		break;
	default:
		display_initialized_during_boot = false;
		break;
	};

	return 1;
}
__setup("startup_graphics=", startup_graphics_setup);

#ifdef CONFIG_DISPLAY_GENERIC_DSI_PRIMARY
static struct mcde_port port0 = {
	.type = MCDE_PORTTYPE_DSI,
	.mode = MCDE_PORTMODE_CMD,
	.pixel_format = MCDE_PORTPIXFMT_DSI_24BPP,
	.ifc = 1,
	.link = 0,
	.sync_src = MCDE_SYNCSRC_BTA,
	.update_auto_trig = false,
	.phy = {
		.dsi = {
			.virt_id = 0,
			.num_data_lanes = 2,
			.ui = DSI_UNIT_INTERVAL_0,
		},
	},
};

struct mcde_display_generic_platform_data generic_display0_pdata = {
	.reset_gpio = EGPIO_PIN_15,
	.reset_delay = 1,
#ifdef CONFIG_REGULATOR
	.regulator_id = "v-display",
	.min_supply_voltage = 2500000, /* 2.5V */
	.max_supply_voltage = 2700000 /* 2.7V */
#endif
};

struct mcde_display_device generic_display0 = {
	.name = "mcde_disp_generic",
	.id = 0,
	.port = &port0,
	.chnl_id = MCDE_CHNL_A,
	.fifo = MCDE_FIFO_C0,
	.default_pixel_format = MCDE_OVLYPIXFMT_RGB565,
	.native_x_res = 864,
	.native_y_res = 480,
#ifdef CONFIG_DISPLAY_GENERIC_DSI_PRIMARY_VSYNC
	.synchronized_update = true,
#else
	.synchronized_update = false,
#endif
	/* TODO: Remove rotation buffers once ESRAM driver is completed */
	.rotbuf1 = U8500_ESRAM_BASE + 0x20000 * 4,
	.rotbuf2 = U8500_ESRAM_BASE + 0x20000 * 4 + 0x10000,
	.dev = {
		.platform_data = &generic_display0_pdata,
	},
};
#endif /* CONFIG_DISPLAY_GENERIC_DSI_PRIMARY */

#ifdef CONFIG_DISPLAY_GENERIC_DSI_SECONDARY
static struct mcde_port subdisplay_port = {
	.type = MCDE_PORTTYPE_DSI,
	.mode = MCDE_PORTMODE_CMD,
	.pixel_format = MCDE_PORTPIXFMT_DSI_24BPP,
	.ifc = 1,
	.link = 1,
	.sync_src = MCDE_SYNCSRC_BTA,
	.update_auto_trig = false,
	.phy = {
		.dsi = {
			.virt_id = 0,
			.num_data_lanes = 2,
			.ui = DSI_UNIT_INTERVAL_1,
		},
	},

};

static struct mcde_display_generic_platform_data generic_subdisplay_pdata = {
	.reset_gpio = EGPIO_PIN_14,
	.reset_delay = 1,
#ifdef CONFIG_REGULATOR
	.regulator_id = "v-display",
	.min_supply_voltage = 2500000, /* 2.5V */
	.max_supply_voltage = 2700000 /* 2.7V */
#endif
};

static struct mcde_display_device generic_subdisplay = {
	.name = "mcde_disp_generic_subdisplay",
	.id = 1,
	.port = &subdisplay_port,
	.chnl_id = MCDE_CHNL_C1,
	.fifo = MCDE_FIFO_C1,
	.default_pixel_format = MCDE_OVLYPIXFMT_RGB565,
	.native_x_res = 864,
	.native_y_res = 480,
#ifdef CONFIG_DISPLAY_GENERIC_DSI_SECONDARY_VSYNC
	.synchronized_update = true,
#else
	.synchronized_update = false,
#endif
	.dev = {
		.platform_data = &generic_subdisplay_pdata,
	},
};
#endif /* CONFIG_DISPLAY_GENERIC_DSI_SECONDARY */


#ifdef CONFIG_DISPLAY_AB8500_TERTIARY
static struct mcde_port port_tvout1 = {
	.type = MCDE_PORTTYPE_DPI,
	.pixel_format = MCDE_PORTPIXFMT_DPI_24BPP,
	.ifc = 0,
	.link = 1,
	.sync_src = MCDE_SYNCSRC_OFF,
	.update_auto_trig = true,
	.phy = {
		.dpi = {
			.num_data_lanes = 4, /* DDR mode */
		},
	},
};

static struct ab8500_display_platform_data ab8500_display_pdata = {
	/* REVIEW use "#ifdef CONFIG_REGULATOR" as with other displays */
	/* TODO use this ID as soon as we switch to newer kernel with support or
	 * ab8500 TVout regulator
	.regulator_id = "v-tvout",
	 */
	/* REVIEW change name: use transform instead of convert? */
	.rgb_2_yCbCr_convert = {
		.matrix = {
			{0x42, 0x81, 0x19},
			{0xffda, 0xffb6, 0x70},
			{0x70, 0xffa2, 0xffee},
		},
		.offset = {0x80, 0x10, 0x80},
	}
};

static int ab8500_platform_enable(struct mcde_display_device *ddev)
{
	int res = 0;
	/* probe checks for pdata */
	struct ab8500_display_platform_data *pdata = ddev->dev.platform_data;

	dev_info(&ddev->dev, "%s\n", __func__);
	res = stm_gpio_altfuncenable(GPIO_ALT_LCD_PANELB);
	if (res != 0)
		goto alt_func_failed;

	if (pdata->regulator) {
		res = regulator_enable(pdata->regulator);
	if (res != 0)
		goto regu_failed;
	}

	return res;

regu_failed:
	(void) stm_gpio_altfuncdisable(GPIO_ALT_LCD_PANELB);
alt_func_failed:
	dev_warn(&ddev->dev, "Failure during %s\n", __func__);
	return res;
}

static int ab8500_platform_disable(struct mcde_display_device *ddev)
{
	int res;
	/* probe checks for pdata */
	struct ab8500_display_platform_data *pdata = ddev->dev.platform_data;

	dev_info(&ddev->dev, "%s\n", __func__);

	res = stm_gpio_altfuncdisable(GPIO_ALT_LCD_PANELB);
	if (res != 0)
		goto alt_func_failed;

	if (pdata->regulator) {
		res = regulator_disable(pdata->regulator);
	if (res != 0)
		goto regu_failed;
	}

	return res;
regu_failed:
	(void) stm_gpio_altfuncenable(GPIO_ALT_LCD_PANELB);
alt_func_failed:
	dev_warn(&ddev->dev, "Failure during %s\n", __func__);
	return res;

}

static struct mcde_display_device tvout_ab8500_display = {
	.name = "mcde_tv_ab8500",
	.id = 2,
	.port = &port_tvout1,
	.chnl_id = MCDE_CHNL_B,
	.fifo = MCDE_FIFO_B,
	.default_pixel_format = MCDE_OVLYPIXFMT_RGB565,
	.native_x_res = 720,
	.native_y_res = 576,
	.synchronized_update = true,
	.dev = {
		.platform_data = &ab8500_display_pdata,
	},

	/*
	* We might need to describe the std here:
	* - there are different PAL / NTSC formats (do they require MCDE
	*   settings?)
	*/
	.platform_enable = ab8500_platform_enable,
	.platform_disable = ab8500_platform_disable,
};

static struct ab8500_denc_platform_data ab8500_denc_pdata = {
	.ddr_enable = true,
	.ddr_little_endian = false,
};

static struct platform_device ab8500_denc = {
	.name = "ab8500_denc",
	.id = -1,
	.dev = {
		.platform_data = &ab8500_denc_pdata,
	},
};
#endif /* CONFIG_DISPLAY_AB8500_TERTIARY */

#ifdef CONFIG_DISPLAY_AV8100_TERTIARY
static struct mcde_port port2 = {
	.type = MCDE_PORTTYPE_DSI,
	.mode = MCDE_PORTMODE_CMD,
	.pixel_format = MCDE_PORTPIXFMT_DSI_24BPP,
	.ifc = 1,
	.link = 2,
#ifdef AV8100_HW_TE_I2SDAT3
	.sync_src = MCDE_SYNCSRC_TE1,
#else
	.sync_src = MCDE_SYNCSRC_TE0,
#endif /* AV8100_HW_TE_I2SDAT3 */
	.update_auto_trig = true,
	.phy = {
		.dsi = {
			.virt_id = 0,
			.num_data_lanes = 2,
			.ui = DSI_UNIT_INTERVAL_2,
		},
	},
};

struct mcde_display_hdmi_platform_data av8100_hdmi_pdata = {
	.reset_gpio = 0,
	.reset_delay = 1,
	.regulator_id = NULL, /* TODO: "display_main" */
	.ddb_id = 1,
	.rgb_2_yCbCr_convert = {
		.matrix = {
			{0x42, 0x81, 0x19},
			{0xffda, 0xffb6, 0x70},
			{0x70, 0xffa2, 0xffee},
		},
		.offset = {0x80, 0x10, 0x80},
	}
};

static int av8100_platform_enable(struct mcde_display_device *dev)
{
	int ret = 0;
	struct mcde_display_hdmi_platform_data *pdata =
		dev->dev.platform_data;

	ret = stm_gpio_altfuncenable(GPIO_ALT_LCD_PANELA);
	if (ret != 0)
		goto alt_func_failed;

	if (pdata->reset_gpio)
		gpio_set_value(pdata->reset_gpio, pdata->reset_high);
	if (pdata->regulator)
		ret = regulator_enable(pdata->regulator);
alt_func_failed:
	return ret;
}

static int av8100_platform_disable(struct mcde_display_device *dev)
{
	int ret = 0;
	struct mcde_display_hdmi_platform_data *pdata =
		dev->dev.platform_data;

	ret = stm_gpio_altfuncdisable(GPIO_ALT_LCD_PANELA);
	if (ret != 0)
		goto alt_func_failed;
	if (pdata->reset_gpio)
		gpio_set_value(pdata->reset_gpio, !pdata->reset_high);
	if (pdata->regulator)
		ret = regulator_disable(pdata->regulator);
alt_func_failed:
	return ret;
}

static struct mcde_display_device av8100_hdmi = {
	.name = "av8100_hdmi",
	.id = 2,
	.port = &port2,
	.chnl_id = MCDE_CHNL_B,
	.fifo = MCDE_FIFO_B,
	.default_pixel_format = MCDE_OVLYPIXFMT_RGB565,
#ifdef CONFIG_AV8100_SDTV
	.native_x_res = 720,
	.native_y_res = 576,
#else
	.native_x_res = 1280,
	.native_y_res = 720,
#endif
	.synchronized_update = true,
	.dev = {
		.platform_data = &av8100_hdmi_pdata,
	},
	.platform_enable = av8100_platform_enable,
	.platform_disable = av8100_platform_disable,
};
#endif /* CONFIG_DISPLAY_AV8100_TERTIARY */

static struct fb_info *fbs[3] = { NULL, NULL, NULL };
static struct mcde_display_device *displays[3] = { NULL, NULL, NULL };

static int display_registered_callback(struct notifier_block *nb,
	unsigned long event, void *dev)
{
	struct mcde_display_device *ddev = dev;
	u16 width, height;
	bool rotate;

	if (event != MCDE_DSS_EVENT_DISPLAY_REGISTERED)
		return 0;

	if (ddev->id < 0 || ddev->id >= ARRAY_SIZE(fbs))
		return 0;

	mcde_dss_get_native_resolution(ddev, &width, &height);

	rotate = (ddev->id == 0 && rotate_main);
	if (rotate) {
		u16 tmp = height;
		height = width;
		width = tmp;
	}

	/* Create frame buffer */
	fbs[ddev->id] = mcde_fb_create(ddev,
		width, height,
		width, height * 2,
		ddev->default_pixel_format,
		rotate ? FB_ROTATE_CW : FB_ROTATE_UR);
	if (IS_ERR(fbs[ddev->id]))
		pr_warning("Failed to create fb for display %s\n", ddev->name);
	else
		pr_info("Framebuffer created (%s)\n", ddev->name);

	return 0;
}

static struct notifier_block display_nb = {
	.notifier_call = display_registered_callback,
};

static int framebuffer_registered_callback(struct notifier_block *nb,
	unsigned long event, void *data)
{
	int ret = 0;
	struct fb_event *event_data = data;
	struct fb_info *info;
	struct fb_var_screeninfo var;
	struct fb_fix_screeninfo fix;

	if (event == FB_EVENT_FB_REGISTERED &&
		!display_initialized_during_boot) {
		if (event_data) {
			u8 *addr;
			info = event_data->info;
			if (!lock_fb_info(info))
				return -ENODEV;
			var = info->var;
			fix = info->fix;
			addr = ioremap(fix.smem_start,
					var.yres_virtual * fix.line_length);
			memset(addr, 0x00,
					var.yres_virtual * fix.line_length);
			var.yoffset = var.yoffset ? 0 : var.yres;
			if (info->fbops->fb_pan_display)
				ret = info->fbops->fb_pan_display(&var, info);
			unlock_fb_info(info);
		}
	}
	return ret;
}

static struct notifier_block framebuffer_nb = {
	.notifier_call = framebuffer_registered_callback,
};

int __init init_display_devices(void)
{
	int ret;

	ret = fb_register_client(&framebuffer_nb);
	if (ret)
		pr_warning("Failed to register framebuffer notifier\n");

	ret = mcde_dss_register_notifier(&display_nb);
	if (ret)
		pr_warning("Failed to register dss notifier\n");

#ifdef CONFIG_DISPLAY_GENERIC_DSI_PRIMARY
	if (display_initialized_during_boot)
		generic_display0.power_mode = MCDE_DISPLAY_PM_STANDBY;
	ret = mcde_display_device_register(&generic_display0);
	if (ret)
		pr_warning("Failed to register generic display device 0\n");
	displays[0] = &generic_display0;
#endif

#ifdef CONFIG_DISPLAY_GENERIC_DSI_SECONDARY
	ret = mcde_display_device_register(&generic_subdisplay);
	if (ret)
		pr_warning("Failed to register generic sub display device\n");
	displays[1] = &generic_subdisplay;
#endif

#ifdef CONFIG_DISPLAY_AV8100_TERTIARY
	ret = mcde_display_device_register(&av8100_hdmi);
	if (ret)
		pr_warning("Failed to register av8100_hdmi\n");
	displays[2] = &av8100_hdmi;
#endif
#ifdef CONFIG_DISPLAY_AB8500_TERTIARY
	ret = platform_device_register(&ab8500_denc);
	if (ret)
		pr_warning("Failed to register ab8500_denc device\n");
	else {
		ret = mcde_display_device_register(&tvout_ab8500_display);
		if (ret)
			pr_warning("Failed to register ab8500 tvout device\n");
		displays[2] = &tvout_ab8500_display;
	}
#endif

	return ret;
}

module_init(init_display_devices);