aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/video/backlight/s6e63m0_mipi_lcd.c
blob: f0b2d00a88167e92858ccea5cbeaafe9c2f90c17 (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
/* linux/drivers/video/backlight/s6e63m0_mipi_lcd.c
 *
 *
 * Copyright (c) 2011 Samsung Electronics
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 *
*/

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/mutex.h>
#include <linux/wait.h>
#include <linux/ctype.h>
#include <linux/io.h>
#include <linux/delay.h>
#include <linux/irq.h>
#include <linux/interrupt.h>
#include <linux/gpio.h>
#include <linux/workqueue.h>
#include <linux/backlight.h>
#include <linux/lcd.h>

#include <video/mipi_display.h>

#include <plat/gpio-cfg.h>
#include <plat/regs-dsim.h>

#include <plat/dsim.h>
#include <plat/mipi_dsi.h>

void init_lcd(struct mipi_dsim_device *dsim)
{
	unsigned char buf1[4] = {0xf2, 0x02, 0x03, 0x1b};
	unsigned char buf2[15] = {0xf8, 0x01, 0x27, 0x27, 0x07, 0x07, 0x54,
							0x9f, 0x63, 0x86, 0x1a,
							0x33, 0x0d, 0x00, 0x00};
	unsigned char buf3[4] = {0xf6, 0x00, 0x8c, 0x07};

	/* password */
	unsigned char rf[3] = {0x00, 0x5a, 0x5a};

	rf[0] = 0xf0;
	s5p_mipi_dsi_wr_data(dsim, MIPI_DSI_DCS_LONG_WRITE,
		(unsigned int) rf, 3);

	rf[0] = 0xf1;
	s5p_mipi_dsi_wr_data(dsim, MIPI_DSI_DCS_LONG_WRITE,
		(unsigned int) rf, 3);

	rf[0] = 0xfc;
	s5p_mipi_dsi_wr_data(dsim, MIPI_DSI_DCS_LONG_WRITE,
		(unsigned int) rf, 3);

	/* HZ (0x16 = 60Hz) */
	s5p_mipi_dsi_wr_data(dsim, MIPI_DSI_DCS_SHORT_WRITE_PARAM,
		0xfd, 0x14);

	s5p_mipi_dsi_wr_data(dsim,
		MIPI_DSI_DCS_SHORT_WRITE_PARAM, 0xb0, 0x09);
	s5p_mipi_dsi_wr_data(dsim,
		MIPI_DSI_DCS_SHORT_WRITE_PARAM, 0xd5, 0x64);
	s5p_mipi_dsi_wr_data(dsim,
		MIPI_DSI_DCS_SHORT_WRITE_PARAM, 0xb0, 0x09);

	/* nonBurstSyncPulse */
	if (dsim->pd->dsim_config->e_burst_mode == DSIM_NON_BURST_SYNC_PULSE)
		s5p_mipi_dsi_wr_data(dsim,
			MIPI_DSI_DCS_SHORT_WRITE_PARAM, 0xd5, 0x84);
	else
		s5p_mipi_dsi_wr_data(dsim,
			MIPI_DSI_DCS_SHORT_WRITE_PARAM, 0xd5, 0xc4);

	s5p_mipi_dsi_wr_data(dsim,
		MIPI_DSI_DCS_LONG_WRITE, (unsigned int) buf1, sizeof(buf1));
	s5p_mipi_dsi_wr_data(dsim,
		MIPI_DSI_DCS_LONG_WRITE, (unsigned int) buf2, sizeof(buf2));
	s5p_mipi_dsi_wr_data(dsim,
		MIPI_DSI_DCS_LONG_WRITE, (unsigned int) buf3, sizeof(buf3));

	s5p_mipi_dsi_wr_data(dsim,
		MIPI_DSI_DCS_SHORT_WRITE_PARAM, 0xfa, 0x01);
	/* Exit sleep */
	s5p_mipi_dsi_wr_data(dsim, MIPI_DSI_DCS_SHORT_WRITE,
		0x11, 0);
	mdelay(600);
	/* Set Display ON */
	s5p_mipi_dsi_wr_data(dsim, MIPI_DSI_DCS_SHORT_WRITE,
		0x29, 0);
}

void s6e63m0_mipi_lcd_off(struct mipi_dsim_device *dsim)
{
	/* softreset */
	s5p_mipi_dsi_wr_data(dsim, MIPI_DSI_DCS_SHORT_WRITE,
		0x1, 0);
	/* Enter sleep */
	s5p_mipi_dsi_wr_data(dsim, MIPI_DSI_DCS_SHORT_WRITE,
		0x10, 0);
	mdelay(60);

	/* Set Display off */
	s5p_mipi_dsi_wr_data(dsim, MIPI_DSI_DCS_SHORT_WRITE,
		0x28, 0);
}

static int s6e63m0_mipi_lcd_bl_update_status(struct backlight_device *bd)
{
	return 0;
}

static const struct backlight_ops s6e63m0_mipi_lcd_bl_ops = {
	.update_status = s6e63m0_mipi_lcd_bl_update_status,
};

static int s6e63m0_mipi_lcd_probe(struct mipi_dsim_device *dsim)
{
	struct mipi_dsim_device *dsim_drv;
	struct backlight_device *bd = NULL;
	struct backlight_properties props;

	dsim_drv = kzalloc(sizeof(struct mipi_dsim_device), GFP_KERNEL);
	if (!dsim_drv)
		return -ENOMEM;

	dsim_drv = (struct mipi_dsim_device *) dsim;

	props.max_brightness = 1;
	props.type = BACKLIGHT_PLATFORM;

	bd = backlight_device_register("pwm-backlight",
		dsim_drv->dev, dsim_drv, &s6e63m0_mipi_lcd_bl_ops, &props);

	return 0;
}

static int s6e63m0_mipi_lcd_suspend(struct mipi_dsim_device *dsim)
{
	s6e63m0_mipi_lcd_off(dsim);
	return 0;
}

static int s6e63m0_mipi_lcd_displayon(struct mipi_dsim_device *dsim)
{
	init_lcd(dsim);

	return 0;
}

static int s6e63m0_mipi_lcd_resume(struct mipi_dsim_device *dsim)
{
	init_lcd(dsim);
	return 0;
}

struct mipi_dsim_lcd_driver s6e63m0_mipi_lcd_driver = {
	.probe = s6e63m0_mipi_lcd_probe,
	.suspend =  s6e63m0_mipi_lcd_suspend,
	.displayon = s6e63m0_mipi_lcd_displayon,
	.resume = s6e63m0_mipi_lcd_resume,
};