summaryrefslogtreecommitdiff
path: root/drivers/video/mxc/mxcfb_epson_vga.c
blob: 18a343ef4276abace39394db4eb1d507bdb7c69b (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
/*
 * Copyright 2007-2010 Freescale Semiconductor, Inc. All Rights Reserved.
 */

/*
 * The code contained herein is licensed under the GNU General Public
 * License. You may obtain a copy of the GNU General Public License
 * Version 2 or later at the following locations:
 *
 * http://www.opensource.org/licenses/gpl-license.html
 * http://www.gnu.org/copyleft/gpl.html
 */

/*!
 * @defgroup Framebuffer Framebuffer Driver for SDC and ADC.
 */

/*!
 * @file mxcfb_epson_vga.c
 *
 * @brief MXC Frame buffer driver for SDC
 *
 * @ingroup Framebuffer
 */

/*!
 * Include files
 */
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/console.h>
#include <linux/delay.h>
#include <linux/errno.h>
#include <linux/fb.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/regulator/consumer.h>
#include <linux/spi/spi.h>
#include <linux/mxcfb.h>
#include <linux/ipu.h>
#include <asm/mach-types.h>
#include <mach/hardware.h>

static struct spi_device *lcd_spi;
static struct device *lcd_dev;

static void lcd_init(void);
static void lcd_poweron(void);
static void lcd_poweroff(void);

static void (*lcd_reset) (void);
static struct regulator *io_reg;
static struct regulator *core_reg;

static struct fb_videomode video_modes[] = {
	{
	 /* 480x640 @ 60 Hz */
	 "Epson-VGA", 60, 480, 640, 41701, 60, 41, 10, 5, 20, 10,
	 0,
	 FB_VMODE_NONINTERLACED,
	 0,},
};

static void lcd_init_fb(struct fb_info *info)
{
	struct fb_var_screeninfo var;

	memset(&var, 0, sizeof(var));

	fb_videomode_to_var(&var, &video_modes[0]);

	if (machine_is_mx31_3ds()) {
		var.upper_margin = 0;
		var.left_margin = 0;
	}

	var.activate = FB_ACTIVATE_ALL;
	var.yres_virtual = var.yres * 3;

	acquire_console_sem();
	info->flags |= FBINFO_MISC_USEREVENT;
	fb_set_var(info, &var);
	info->flags &= ~FBINFO_MISC_USEREVENT;
	release_console_sem();
}

static int lcd_fb_event(struct notifier_block *nb, unsigned long val, void *v)
{
	struct fb_event *event = v;

	if (strcmp(event->info->fix.id, "DISP3 BG")) {
		return 0;
	}

	switch (val) {
	case FB_EVENT_FB_REGISTERED:
		lcd_init_fb(event->info);
		lcd_poweron();
		break;
	case FB_EVENT_BLANK:
		if ((event->info->var.xres != 480) ||
		    (event->info->var.yres != 640)) {
			break;
		}
		if (*((int *)event->data) == FB_BLANK_UNBLANK) {
			lcd_poweron();
		} else {
			lcd_poweroff();
		}
		break;
	}
	return 0;
}

static struct notifier_block nb = {
	.notifier_call = lcd_fb_event,
};

/*!
 * This function is called whenever the SPI slave device is detected.
 *
 * @param	spi	the SPI slave device
 *
 * @return 	Returns 0 on SUCCESS and error on FAILURE.
 */
static int __devinit lcd_probe(struct device *dev)
{
	int i;
	struct mxc_lcd_platform_data *plat = dev->platform_data;

	lcd_dev = dev;

	if (plat) {
		io_reg = regulator_get(dev, plat->io_reg);
		if (!IS_ERR(io_reg)) {
			regulator_set_voltage(io_reg, 1800000, 1800000);
			regulator_enable(io_reg);
		}
		core_reg = regulator_get(dev, plat->core_reg);
		if (!IS_ERR(core_reg)) {
			regulator_set_voltage(core_reg, 2800000, 2800000);
			regulator_enable(core_reg);
		}

		lcd_reset = plat->reset;
		if (lcd_reset)
			lcd_reset();
	}

	lcd_init();

	for (i = 0; i < num_registered_fb; i++) {
		if (strcmp(registered_fb[i]->fix.id, "DISP3 BG") == 0) {
			lcd_init_fb(registered_fb[i]);
			fb_show_logo(registered_fb[i], 0);
			lcd_poweron();
		}
	}

	fb_register_client(&nb);

	return 0;
}

static int __devinit lcd_plat_probe(struct platform_device *pdev)
{
	ipu_adc_sig_cfg_t sig;
	ipu_channel_params_t param;

	memset(&sig, 0, sizeof(sig));
	sig.ifc_width = 9;
	sig.clk_pol = 1;
	ipu_init_async_panel(0, IPU_PANEL_SERIAL, 90, IPU_PIX_FMT_GENERIC, sig);

	memset(&param, 0, sizeof(param));
	ipu_init_channel(DIRECT_ASYNC1, &param);

	return lcd_probe(&pdev->dev);
}

static int __devinit lcd_spi_probe(struct spi_device *spi)
{
	lcd_spi = spi;

	spi->bits_per_word = 9;
	spi_setup(spi);

	return lcd_probe(&spi->dev);
}

static int __devexit lcd_remove(struct device *dev)
{
	fb_unregister_client(&nb);
	lcd_poweroff();
	regulator_put(io_reg);
	regulator_put(core_reg);

	return 0;
}

static int __devexit lcd_spi_remove(struct spi_device *spi)
{
	int ret = lcd_remove(&spi->dev);
	lcd_spi = NULL;
	return ret;
}

static int __devexit lcd_plat_remove(struct platform_device *pdev)
{
	return lcd_remove(&pdev->dev);
}

static int lcd_suspend(struct spi_device *spi, pm_message_t message)
{
	lcd_poweroff();
	return 0;
}

static int lcd_resume(struct spi_device *spi)
{
	if (lcd_reset)
		lcd_reset();

	lcd_init();
	lcd_poweron();
	return 0;
}

/*!
 * spi driver structure for LTV350QV
 */
static struct spi_driver lcd_spi_dev_driver = {

	.driver = {
		   .name = "lcd_spi",
		   .owner = THIS_MODULE,
		   },
	.probe = lcd_spi_probe,
	.remove = __devexit_p(lcd_spi_remove),
	.suspend = lcd_suspend,
	.resume = lcd_resume,
};

static struct platform_driver lcd_plat_driver = {
	.driver = {
		   .name = "lcd_spi",
		   .owner = THIS_MODULE,
		   },
	.probe = lcd_plat_probe,
	.remove = __devexit_p(lcd_plat_remove),
};

#define param(x) ((x) | 0x100)

/*
 * Send init commands to L4F00242T03
 *
 */
static void lcd_init(void)
{
	const u16 cmd[] = { 0x36, param(0), 0x3A, param(0x60) };

	dev_dbg(lcd_dev, "initializing LCD\n");
	if (lcd_spi) {
		spi_write(lcd_spi, (const u8 *)cmd, ARRAY_SIZE(cmd));
	} else {
		ipu_disp_direct_write(DIRECT_ASYNC1, 0x36, 0);
		ipu_disp_direct_write(DIRECT_ASYNC1, 0x100, 0);
		ipu_disp_direct_write(DIRECT_ASYNC1, 0x3A, 0);
		ipu_disp_direct_write(DIRECT_ASYNC1, 0x160, 0);
		msleep(1);
		ipu_uninit_channel(DIRECT_ASYNC1);
	}
}

static int lcd_on;
/*
 * Send Power On commands to L4F00242T03
 *
 */
static void lcd_poweron(void)
{
	const u16 slpout = 0x11;
	const u16 dison = 0x29;
	ipu_channel_params_t param;
	if (lcd_on)
		return;

	dev_dbg(lcd_dev, "turning on LCD\n");

	if (lcd_spi) {
		msleep(60);
		spi_write(lcd_spi, (const u8 *)&slpout, 1);
		msleep(60);
		spi_write(lcd_spi, (const u8 *)&dison, 1);
	} else {
		memset(&param, 0, sizeof(param));
		ipu_init_channel(DIRECT_ASYNC1, &param);
		ipu_disp_direct_write(DIRECT_ASYNC1, slpout, 0);
		msleep(60);
		ipu_disp_direct_write(DIRECT_ASYNC1, dison, 0);
		msleep(1);
		ipu_uninit_channel(DIRECT_ASYNC1);
	}
	lcd_on = 1;
}

/*
 * Send Power Off commands to L4F00242T03
 *
 */
static void lcd_poweroff(void)
{
	const u16 slpin = 0x10;
	const u16 disoff = 0x28;
	ipu_channel_params_t param;
	if (!lcd_on)
		return;

	dev_dbg(lcd_dev, "turning off LCD\n");

	if (lcd_spi) {
		msleep(60);
		spi_write(lcd_spi, (const u8 *)&disoff, 1);
		msleep(60);
		spi_write(lcd_spi, (const u8 *)&slpin, 1);
	} else {
		memset(&param, 0, sizeof(param));
		ipu_init_channel(DIRECT_ASYNC1, &param);
		ipu_disp_direct_write(DIRECT_ASYNC1, disoff, 0);
		msleep(60);
		ipu_disp_direct_write(DIRECT_ASYNC1, slpin, 0);
		msleep(1);
		ipu_uninit_channel(DIRECT_ASYNC1);
	}
	lcd_on = 0;
}

static int __init epson_lcd_init(void)
{
	int ret;

	ret = platform_driver_register(&lcd_plat_driver);
	if (ret)
		return ret;

	return spi_register_driver(&lcd_spi_dev_driver);

}

static void __exit epson_lcd_exit(void)
{
	spi_unregister_driver(&lcd_spi_dev_driver);
}

module_init(epson_lcd_init);
module_exit(epson_lcd_exit);

MODULE_AUTHOR("Freescale Semiconductor, Inc.");
MODULE_DESCRIPTION("Epson VGA LCD init driver");
MODULE_LICENSE("GPL");