summaryrefstree
path: root/kernel/drivers/video/decon_display/s6e3ha0k_mipi_lcd.c
blob: ef57387dd5eb6ef31f3c29a39b81c29d048c93a9 (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
/* drivers/video/decon_display/s6e3ha0k_mipi_lcd.c
 *
 * Samsung SoC MIPI LCD driver.
 *
 * Copyright (c) 2014 Samsung Electronics
 *
 * Haowei Li, <haowei.li@samsung.com>
 *
 * 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/delay.h>
#include <linux/gpio.h>
#include <video/mipi_display.h>
#include <linux/platform_device.h>

#include "decon_mipi_dsi.h"
#include "s6e3ha0k_gamma.h"
#include "decon_display_driver.h"

#define GAMMA_PARAM_SIZE 26
#define MAX_BRIGHTNESS 255
#define MIN_BRIGHTNESS 0
#define DEFAULT_BRIGHTNESS 0

static struct mipi_dsim_device *dsim_base;
static struct backlight_device *bd;

static u8 SEQ_TEST_KEY_ON_F0[] = {0xF0, 0x5A, 0x5A};
static u8 SEQ_MIPI_SINGLE_DSI_SET1[] = {0xF2, 0x07, 0x00, 0x01, 0xA4, 0x03, 0x0d, 0xA0};
static u8 SEQ_MIPI_SINGLE_DSI_SET2[] = {0xF9, 0x29};
static u8 SEQ_TEST_KEY_ON_FC[] = {0xFC, 0x5A, 0x5A};
static u8 SEQ_REG_FF[] = {0xFF, 0x00, 0x00, 0x20, 0x00};
static u8 SEQ_TEST_KEY_OFF_FC[] = {0xFC, 0xA5, 0xA5};
//static u8 SEQ_SLEEP_OUT[] = {0x11};
static u8 SEQ_CAPS_ELVSS_SET[] = {0xB6,
	0x98, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x55, 0x54,
	0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x22, 0x22, 0x10};
//static u8 SEQ_TE_ON[] = {0x35};
static u8 SEQ_TOUCH_HSYNC_ON[] = {0xBD, 0x05};
static u8 SEQ_TOUCH_VSYNC_ON[] = {0xFF, 0x02};
static u8 SEQ_PENTILE_CONTROL[] = {0xC0, 0x74, 0x00, 0xD8, 0xD8};
static u8 SEQ_TEST_KEY_OFF_F0[] = {0xF0, 0xA5, 0xA5};
//static u8 SEQ_DISP_ON[] = {0x29};

static int s6e3ha0k_get_brightness(struct backlight_device *bd)
{
	return bd->props.brightness;
}

static int get_backlight_level(int brightness)
{
	int backlightlevel;

	switch (brightness) {
	case 0:
		backlightlevel = 0;
		break;
	case 1 ... 29:
		backlightlevel = 0;
		break;
	case 30 ... 34:
		backlightlevel = 1;
		break;
	case 35 ... 39:
		backlightlevel = 2;
		break;
	case 40 ... 44:
		backlightlevel = 3;
		break;
	case 45 ... 49:
		backlightlevel = 4;
		break;
	case 50 ... 54:
		backlightlevel = 5;
		break;
	case 55 ... 64:
		backlightlevel = 6;
		break;
	case 65 ... 74:
		backlightlevel = 7;
		break;
	case 75 ... 83:
		backlightlevel = 8;
		break;
	case 84 ... 93:
		backlightlevel = 9;
		break;
	case 94 ... 103:
		backlightlevel = 10;
		break;
	case 104 ... 113:
		backlightlevel = 11;
		break;
	case 114 ... 122:
		backlightlevel = 12;
		break;
	case 123 ... 132:
		backlightlevel = 13;
		break;
	case 133 ... 142:
		backlightlevel = 14;
		break;
	case 143 ... 152:
		backlightlevel = 15;
		break;
	case 153 ... 162:
		backlightlevel = 16;
		break;
	case 163 ... 171:
		backlightlevel = 17;
		break;
	case 172 ... 181:
		backlightlevel = 18;
		break;
	case 182 ... 191:
		backlightlevel = 19;
		break;
	case 192 ... 201:
		backlightlevel = 20;
		break;
	case 202 ... 210:
		backlightlevel = 21;
		break;
	case 211 ... 220:
		backlightlevel = 22;
		break;
	case 221 ... 230:
		backlightlevel = 23;
		break;
	case 231 ... 240:
		backlightlevel = 24;
		break;
	case 241 ... 250:
		backlightlevel = 25;
		break;
	case 251 ... 255:
		backlightlevel = 26;
		break;
	default:
		backlightlevel = 12;
		break;
	}

	return backlightlevel;
}

static int update_brightness(int brightness)
{
	int backlightlevel;

	backlightlevel = get_backlight_level(brightness);
	/* Need to implement
	if (s5p_mipi_dsi_wr_data(dsim_base, MIPI_DSI_DCS_LONG_WRITE,
			(unsigned int)gamma22_table[backlightlevel],
				GAMMA_PARAM_SIZE) == -1)
		printk(KERN_ERR "fail to write gamma value.\n");

	if (s5p_mipi_dsi_wr_data(dsim_base, MIPI_DSI_DCS_SHORT_WRITE_PARAM,
			(unsigned int)0xF7, (unsigned int)0x03) == -1)
		printk(KERN_ERR "fail to update gamma value.\n");
	*/
	return 0;
}

static int s6e3ha0k_set_brightness(struct backlight_device *bd)
{
	int brightness = bd->props.brightness;

	if (brightness < MIN_BRIGHTNESS || brightness > MAX_BRIGHTNESS) {
		printk(KERN_ALERT "Brightness should be in the range of 0 ~ 255\n");
		return -EINVAL;
	}

	update_brightness(brightness);

	return 0;
}

static const struct backlight_ops s6e3ha0k_backlight_ops = {
	.get_brightness = s6e3ha0k_get_brightness,
	.update_status = s6e3ha0k_set_brightness,
};

static int s6e3ha0k_probe(struct mipi_dsim_device *dsim)
{
	dsim_base = dsim;

	bd = backlight_device_register("pwm-backlight.0", NULL,
		NULL, &s6e3ha0k_backlight_ops, NULL);
	if (IS_ERR(bd))
		printk(KERN_ALERT "failed to register backlight device!\n");

	bd->props.max_brightness = MAX_BRIGHTNESS;
	bd->props.brightness = DEFAULT_BRIGHTNESS;

	return 0;
}

int init_lcd(struct mipi_dsim_device *dsim)
{
	if (s5p_mipi_dsi_wr_data(dsim_base, MIPI_DSI_DCS_LONG_WRITE,
			(unsigned int)SEQ_TEST_KEY_ON_F0,
				ARRAY_SIZE(SEQ_TEST_KEY_ON_F0)) == -1)
		printk(KERN_ERR "fail to write F0 init command.\n");
	msleep(50);

	if (s5p_mipi_dsi_wr_data(dsim_base, MIPI_DSI_DCS_LONG_WRITE,
			(unsigned int)SEQ_MIPI_SINGLE_DSI_SET1,
				ARRAY_SIZE(SEQ_MIPI_SINGLE_DSI_SET1)) == -1)
		printk(KERN_ERR "fail to write DSI_SET1 command.\n");
	msleep(50);

	if (s5p_mipi_dsi_wr_data(dsim_base, MIPI_DSI_DCS_SHORT_WRITE_PARAM,
			(unsigned int)SEQ_MIPI_SINGLE_DSI_SET2[0],
			(unsigned int)SEQ_MIPI_SINGLE_DSI_SET2[1]) == -1)
		printk(KERN_ERR "fail to write DSI_SET2 command.\n");
	msleep(50);

	if (s5p_mipi_dsi_wr_data(dsim_base, MIPI_DSI_DCS_LONG_WRITE,
			(unsigned int)SEQ_TEST_KEY_ON_FC,
				ARRAY_SIZE(SEQ_TEST_KEY_ON_FC)) == -1)
		printk(KERN_ERR "fail to write FC init command.\n");
	msleep(50);

	if (s5p_mipi_dsi_wr_data(dsim_base, MIPI_DSI_DCS_LONG_WRITE,
			(unsigned int)SEQ_REG_FF,
				ARRAY_SIZE(SEQ_REG_FF)) == -1)
		printk(KERN_ERR "fail to write SEQ_REG_FF command.\n");
	msleep(50);

	if (s5p_mipi_dsi_wr_data(dsim_base, MIPI_DSI_DCS_LONG_WRITE,
			(unsigned int)SEQ_TEST_KEY_OFF_FC,
				ARRAY_SIZE(SEQ_TEST_KEY_OFF_FC)) == -1)
		printk(KERN_ERR "fail to write FC OFF command.\n");
	msleep(50);

	if (s5p_mipi_dsi_wr_data(dsim_base, MIPI_DSI_DCS_SHORT_WRITE,
			0x11, 0x0) == -1)
		printk(KERN_ERR "fail to write Exit_sleep init command.\n");

	msleep(100);

	if (s5p_mipi_dsi_wr_data(dsim_base, MIPI_DSI_DCS_LONG_WRITE,
			(unsigned int)SEQ_CAPS_ELVSS_SET,
				ARRAY_SIZE(SEQ_CAPS_ELVSS_SET)) == -1)
		printk(KERN_ERR "fail to write SEQ_CAPS_ELVSS_SET command.\n");
	msleep(50);

	if (s5p_mipi_dsi_wr_data(dsim_base, MIPI_DSI_DCS_LONG_WRITE,
			(unsigned int)SEQ_TEST_KEY_OFF_F0,
				ARRAY_SIZE(SEQ_TEST_KEY_OFF_F0)) == -1)
		printk(KERN_ERR "fail to write KEY_OFF_F0 command.\n");
	msleep(50);

	if (s5p_mipi_dsi_wr_data(dsim_base, MIPI_DSI_DCS_SHORT_WRITE_PARAM,
			0x35, 0x0) == -1)
		printk(KERN_ERR "fail to write TE_on init command.\n");
	msleep(50);
	if (s5p_mipi_dsi_wr_data(dsim_base, MIPI_DSI_DCS_LONG_WRITE,
			(unsigned int)SEQ_TEST_KEY_ON_F0,
				ARRAY_SIZE(SEQ_TEST_KEY_ON_F0)) == -1)
		printk(KERN_ERR "fail to write KEY_OFF_F0 command.\n");
	msleep(50);

	if (s5p_mipi_dsi_wr_data(dsim_base, MIPI_DSI_DCS_LONG_WRITE,
			(unsigned int)SEQ_TEST_KEY_ON_FC,
				ARRAY_SIZE(SEQ_TEST_KEY_ON_FC)) == -1)
		printk(KERN_ERR "fail to write FC init command.\n");
	msleep(50);

	if (s5p_mipi_dsi_wr_data(dsim_base, MIPI_DSI_DCS_SHORT_WRITE_PARAM,
			(unsigned int)SEQ_TOUCH_HSYNC_ON[0],
			(unsigned int)SEQ_TOUCH_HSYNC_ON[1]) == -1)
		printk(KERN_ERR "fail to write SEQ_TOUCH_HSYNC_ON command.\n");
	msleep(50);

	if (s5p_mipi_dsi_wr_data(dsim_base, MIPI_DSI_DCS_SHORT_WRITE_PARAM,
			(unsigned int)SEQ_TOUCH_VSYNC_ON[0],
			(unsigned int)SEQ_TOUCH_VSYNC_ON[1]) == -1)
		printk(KERN_ERR "fail to write SEQ_TOUCH_VSYNC_ON command.\n");
	msleep(50);

	if (s5p_mipi_dsi_wr_data(dsim_base, MIPI_DSI_DCS_LONG_WRITE,
			(unsigned int)SEQ_TEST_KEY_OFF_FC,
				ARRAY_SIZE(SEQ_TEST_KEY_OFF_FC)) == -1)
		printk(KERN_ERR "fail to write KEY_OFF_FC command.\n");
	msleep(50);

	if (s5p_mipi_dsi_wr_data(dsim_base, MIPI_DSI_DCS_LONG_WRITE,
			(unsigned int)SEQ_PENTILE_CONTROL,
				ARRAY_SIZE(SEQ_PENTILE_CONTROL)) == -1)
		printk(KERN_ERR "fail to write SEQ_PENTILE_CONTROL command.\n");
	msleep(50);

	if (s5p_mipi_dsi_wr_data(dsim_base, MIPI_DSI_DCS_LONG_WRITE,
			(unsigned int)SEQ_TEST_KEY_OFF_F0,
				ARRAY_SIZE(SEQ_TEST_KEY_OFF_F0)) == -1)
		printk(KERN_ERR "fail to write KEY_OFF_F0 command.\n");
	msleep(50);

	if (s5p_mipi_dsi_wr_data(dsim_base, MIPI_DSI_DCS_SHORT_WRITE,
			0x29, 0x0) == -1)
		printk(KERN_ERR "fail to write Disp_on init command.\n");

	return 0;
}

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

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

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

struct mipi_dsim_lcd_driver s6e3ha0k_mipi_lcd_driver = {
	.probe		= s6e3ha0k_probe,
	.displayon	= s6e3ha0k_displayon,
	.suspend	= s6e3ha0k_suspend,
	.resume		= s6e3ha0k_resume,
};