summaryrefstree
path: root/kernel/drivers/video/fbdev/exynos/panel/mdnie.h
blob: 1ccc179026a5ef3175503beb7ba03dfb3b11864e (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
496
497
498
499
500
501
502
503
504
/*
 * linux/drivers/video/fbdev/exynos/panel/mdnie.h
 *
 * Header file for Samsung Common LCD Driver.
 *
 * Copyright (c) 2016 Samsung Electronics
 * Gwanghui Lee <gwanghui.lee@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.
 */

#ifndef __MDNIE_H__
#define __MDNIE_H__

#include "panel.h"
#include "dpui.h"

typedef u8 mdnie_t;

#define MDNIE_SYSFS_PREFIX      "/sdcard/mdnie/"

#define IS_MDNIE_ENABLED(_mdnie_)	(!!(_mdnie_)->props.enable)
#define IS_DMB(idx)			(idx == DMB_NORMAL_MODE)
#define IS_SCENARIO(idx)		(idx < SCENARIO_MAX && !(idx > VIDEO_NORMAL_MODE && idx < CAMERA_MODE))
#define IS_ACCESSIBILITY(idx)		(idx && idx < ACCESSIBILITY_MAX)
#define IS_HBM(idx)			(idx && idx < HBM_MAX)
#define IS_HMD(idx)			(idx && idx < HMD_MDNIE_MAX)

#define SCENARIO_IS_VALID(idx)		(IS_DMB(idx) || IS_SCENARIO(idx))
#define IS_NIGHT_MODE_ON(idx)		(idx == NIGHT_MODE_ON)
#define IS_COLOR_LENS_ON(idx)		(idx == COLOR_LENS_ON)
#define IS_HDR(idx)			(idx >= HDR_ON && idx < HDR_MAX)
#define IS_LIGHT_NOTIFICATION(idx)			(idx >= LIGHT_NOTIFICATION_ON && idx < LIGHT_NOTIFICATION_MAX)

#define COLOR_OFFSET_FUNC(x, y, num, den, con)  \
	    (((s64)y * 1024LL) + ((((s64)x * 1024LL) * ((s64)num)) / ((s64)den)) + ((s64)con * 1024LL))
#define RECOGNIZE_REGION(compV, compH)	\
		((((compV) > 0) ? (0 + (((compH) > 0) ? 0 : 1)) : (2 + (((compH) < 0) ? 0 : 1))))

#define MAPTBL_IDX_SCENARIO(_idx_)	(MDNIE_SCENARIO_MAPTBL_START + (_idx_))
#define MAPTBL_IDX_ACCESSIBILITY(_idx_)	(MDNIE_ACCESSIBILITY_MAPTBL_START + (_idx_) - 1)

#define IS_BYPASS_MODE(_mdnie_)	(((_mdnie_)->props.bypass >= BYPASS_ON) && ((_mdnie_)->props.bypass < BYPASS_MAX))
#define IS_ACCESSIBILITY_MODE(_mdnie_)	(((_mdnie_)->props.accessibility > ACCESSIBILITY_OFF) && ((_mdnie_)->props.accessibility < ACCESSIBILITY_MAX))
#define IS_LIGHT_NOTIFICATION_MODE(_mdnie_)			(((_mdnie_)->props.light_notification >= LIGHT_NOTIFICATION_ON) && ((_mdnie_)->props.light_notification < LIGHT_NOTIFICATION_MAX))
#define IS_HDR_MODE(_mdnie_)			(((_mdnie_)->props.hdr >= HDR_ON) && ((_mdnie_)->props.hdr < HDR_MAX))
#define IS_HMD_MODE(_mdnie_)			(((_mdnie_)->props.hmd >= HMD_MDNIE_ON) && ((_mdnie_)->props.hmd < HMD_MDNIE_MAX))
#define IS_NIGHT_MODE(_mdnie_)			(((_mdnie_)->props.night >= NIGHT_MODE_ON) && ((_mdnie_)->props.night < NIGHT_MODE_MAX))
#define IS_COLOR_LENS_MODE(_mdnie_)		(((_mdnie_)->props.color_lens >= COLOR_LENS_ON) && ((_mdnie_)->props.color_lens < COLOR_LENS_MAX))
#define IS_HBM_MODE(_mdnie_)			(((_mdnie_)->props.hbm >= HBM_ON) && ((_mdnie_)->props.hbm < HBM_MAX))
#define IS_DMB_MODE(_mdnie_)			((_mdnie_)->props.scenario == DMB_NORMAL_MODE)
#define IS_SCENARIO_MODE(_mdnie_)		(((_mdnie_)->props.scenario >= UI_MODE && (_mdnie_)->props.scenario <= VIDEO_NORMAL_MODE) || \
		((_mdnie_)->props.scenario >= CAMERA_MODE && (_mdnie_)->props.scenario < SCENARIO_MAX))
#define IS_LDU_MODE(_mdnie_)			(((_mdnie_)->props.ldu > LDU_MODE_OFF) && ((_mdnie_)->props.ldu < MAX_LDU_MODE))

#define MAX_MDNIE_SCR_LEN	(24)
#define MAX_COLOR (3)

#define GET_MSB_8BIT(x)		((x >> 8) & (BIT(8) - 1))
#define GET_LSB_8BIT(x)		((x >> 0) & (BIT(8) - 1))

#define MIN_WRGB_OFS	(-40)
#define MAX_WRGB_OFS	(0)
#define IS_VALID_WRGB_OFS(_ofs_)	(((int)(_ofs_) <= MAX_WRGB_OFS) && ((int)(_ofs_) >= (MIN_WRGB_OFS)))

#define MIN_WCRD_X	(2930)
#define MAX_WCRD_X	(3060)
#define MIN_WCRD_Y	(3050)
#define MAX_WCRD_Y	(3260)

enum {
	MDNIE_OFF_MODE,
	MDNIE_BYPASS_MODE,
	MDNIE_ACCESSIBILITY_MODE,
	MDNIE_LIGHT_NOTIFICATION_MODE,
	MDNIE_COLOR_LENS_MODE,
	MDNIE_HDR_MODE,
	MDNIE_HMD_MODE,
	MDNIE_NIGHT_MODE,
	MDNIE_HBM_MODE,
	MDNIE_DMB_MODE,
	MDNIE_SCENARIO_MODE,
	MAX_MDNIE_MODE,
};

enum SCENARIO_MODE {
	DYNAMIC,
	STANDARD,
	NATURAL,
	MOVIE,
	AUTO,
	MODE_MAX
};

enum SCENARIO {
	UI_MODE,
	VIDEO_NORMAL_MODE,
	CAMERA_MODE = 4,
	NAVI_MODE,
	GALLERY_MODE,
	VT_MODE,
	BROWSER_MODE,
	EBOOK_MODE,
	EMAIL_MODE,
	GAME_LOW_MODE,
	GAME_MID_MODE,
	GAME_HIGH_MODE,
	VIDEO_ENHANCER,
	VIDEO_ENHANCER_THIRD,
	HMD_8_MODE,
	HMD_16_MODE,
	SCENARIO_MAX,
	DMB_NORMAL_MODE = 20,
	DMB_MODE_MAX
};

enum BYPASS {
	BYPASS_OFF = 0,
	BYPASS_ON,
	BYPASS_MAX
};

enum ACCESSIBILITY {
	ACCESSIBILITY_OFF,
	NEGATIVE,
	COLOR_BLIND,
	SCREEN_CURTAIN,
	GRAYSCALE,
	GRAYSCALE_NEGATIVE,
	COLOR_BLIND_HBM,
	ACCESSIBILITY_MAX
};

enum HBM {
	HBM_OFF,
	HBM_ON,
	HBM_MAX
};

enum HMD_MODE {
	HMD_MDNIE_OFF,
	HMD_MDNIE_ON,
	HMD_3000K = HMD_MDNIE_ON,
	HMD_4000K,
	HMD_5000K,
	HMD_6500K,
	HMD_7500K,
	HMD_MDNIE_MAX
};

enum NIGHT_MODE {
	NIGHT_MODE_OFF,
	NIGHT_MODE_ON,
	NIGHT_MODE_MAX
};

enum NIGHT_LEVEL {
	NIGHT_LEVEL_6500K,
	NIGHT_LEVEL_6100K,
	NIGHT_LEVEL_5700K,
	NIGHT_LEVEL_5300K,
	NIGHT_LEVEL_4900K,
	NIGHT_LEVEL_4500K,
	NIGHT_LEVEL_4100K,
	NIGHT_LEVEL_3700K,
	NIGHT_LEVEL_3300K,
	NIGHT_LEVEL_2900K,
	NIGHT_LEVEL_2500K,
	NIGHT_LEVEL_7000K,
	MAX_NIGHT_LEVEL,
};

enum COLOR_LENS {
	COLOR_LENS_OFF,
	COLOR_LENS_ON,
	COLOR_LENS_MAX
};

enum COLOR_LENS_COLOR {
	COLOR_LENS_COLOR_BLUE,
	COLOR_LENS_COLOR_AZURE,
	COLOR_LENS_COLOR_CYAN,
	COLOR_LENS_COLOR_SPRING_GREEN,
	COLOR_LENS_COLOR_GREEN,
	COLOR_LENS_COLOR_CHARTREUSE_GREEN,
	COLOR_LENS_COLOR_YELLOW,
	COLOR_LENS_COLOR_ORANGE,
	COLOR_LENS_COLOR_RED,
	COLOR_LENS_COLOR_ROSE,
	COLOR_LENS_COLOR_MAGENTA,
	COLOR_LENS_COLOR_VIOLET,
	COLOR_LENS_COLOR_MAX
};

enum COLOR_LENS_LEVEL {
	COLOR_LENS_LEVEL_20P,
	COLOR_LENS_LEVEL_25P,
	COLOR_LENS_LEVEL_30P,
	COLOR_LENS_LEVEL_35P,
	COLOR_LENS_LEVEL_40P,
	COLOR_LENS_LEVEL_45P,
	COLOR_LENS_LEVEL_50P,
	COLOR_LENS_LEVEL_55P,
	COLOR_LENS_LEVEL_60P,
	COLOR_LENS_LEVEL_MAX,
};

enum HDR {
	HDR_OFF,
	HDR_ON,
	HDR_1 = HDR_ON,
	HDR_2,
	HDR_3,
	HDR_4,
	HDR_5,
	HDR_MAX
};

enum LIGHT_NOTIFICATION {
	LIGHT_NOTIFICATION_OFF = 0,
	LIGHT_NOTIFICATION_ON,
	LIGHT_NOTIFICATION_MAX
};

enum {
	CCRD_PT_NONE,
	CCRD_PT_1,
	CCRD_PT_2,
	CCRD_PT_3,
	CCRD_PT_4,
	CCRD_PT_5,
	CCRD_PT_6,
	CCRD_PT_7,
	CCRD_PT_8,
	CCRD_PT_9,
	MAX_CCRD_PT,
};

enum LDU_MODE {
	LDU_MODE_OFF,
	LDU_MODE_1,
	LDU_MODE_2,
	LDU_MODE_3,
	LDU_MODE_4,
	LDU_MODE_5,
	MAX_LDU_MODE,
};

enum SCR_WHITE_MODE {
	SCR_WHITE_MODE_NONE,
	SCR_WHITE_MODE_COLOR_COORDINATE,
	SCR_WHITE_MODE_ADJUST_LDU,
	SCR_WHITE_MODE_SENSOR_RGB,
	MAX_SCR_WHITE_MODE,
};

enum TRANS_MODE {
	TRANS_OFF,
	TRANS_ON,
	MAX_TRANS_MODE,
};

enum MDNIE_MAPTBL {
	/* SCENARIO */
	MDNIE_SCENARIO_MAPTBL_START,
	MDNIE_UI_MAPTBL = MDNIE_SCENARIO_MAPTBL_START,
	MDNIE_VIDEO_MAPTBL,
	MDNIE_CAMERA_MAPTBL = 4,
	MDNIE_NAVI_MAPTBL,
	MDNIE_GALLERY_MAPTBL,
	MDNIE_VT_MAPTBL,
	MDNIE_BROWSER_MAPTBL,
	MDNIE_EBOOK_MAPTBL,
	MDNIE_EMAIL_MAPTBL,
	MDNIE_GAME_LOW_MAPTBL,
	MDNIE_GAME_MID_MAPTBL,
	MDNIE_GAME_HIGH_MAPTBL,
	MDNIE_VIDEO_ENHANCER_MAPTBL,
	MDNIE_VIDEO_ENHANCER_THIRD_MAPTBL,
	MDNIE_HMD_8_MAPTBL,
	MDNIE_HMD_16_MAPTBL,
#if defined(CONFIG_TDMB)
	MDNIE_DMB_MAPTBL,
	MDNIE_SCENARIO_MAPTBL_END = MDNIE_DMB_MAPTBL,
#else
	MDNIE_SCENARIO_MAPTBL_END = MDNIE_HMD_16_MAPTBL,
#endif
	/* ACCESSIBILITY */
	MDNIE_ACCESSIBILITY_MAPTBL_START,
	MDNIE_NEGATIVE_MAPTBL = MDNIE_ACCESSIBILITY_MAPTBL_START,
	MDNIE_COLOR_BLIND_MAPTBL,
	MDNIE_SCREEN_CURTAIN_MAPTBL,
	MDNIE_GRAYSCALE_MAPTBL,
	MDNIE_GRAYSCALE_NEGATIVE_MAPTBL,
	MDNIE_COLOR_BLIND_HBM_MAPTBL,
	MDNIE_ACCESSIBILITY_MAPTBL_END = MDNIE_COLOR_BLIND_HBM_MAPTBL,
	/* BYPASS */
	MDNIE_BYPASS_MAPTBL,
	/* HBM */
	MDNIE_HBM_MAPTBL,
	/* HMD */
	MDNIE_HMD_MAPTBL,
	/* HDR */
	MDNIE_HDR_MAPTBL,
	/* NIGHT */
	MDNIE_NIGHT_MAPTBL,
	/* LIGHT_NOTIFICATION */
	MDNIE_LIGHT_NOTIFICATION_MAPTBL,
	/* COLOR LENS */
	MDNIE_COLOR_LENS_MAPTBL,
	MAX_MDNIE_MAPTBL,
};

enum MDNIE_SEQ {
	MDNIE_SET_SEQ,
	/* if necessary, add new seq */
	MAX_MDNIE_SEQ,
};

enum {
	MDNIE_SCR_WHITE_NONE_MAPTBL,
	MDNIE_COLOR_COORDINATE_MAPTBL,
	MDNIE_ADJUST_LDU_MAPTBL,
	MDNIE_SENSOR_RGB_MAPTBL,
	MAX_SCR_WHITE_MAPTBL,
};

enum {
	MDNIE_ETC_NONE_MAPTBL,
	MDNIE_ETC_TRANS_MAPTBL,
	MDNIE_ETC_NIGHT_MAPTBL,
	MDNIE_ETC_COLOR_LENS_MAPTBL,
	MAX_MDNIE_ETC_MAPTBL,
};

enum {
	WCRD_TYPE_ADAPTIVE,
	WCRD_TYPE_D65,
	MAX_WCRD_TYPE,
};

enum {
	H_LINE,
	V_LINE,
	MAX_CAL_LINE,
};

enum {
	RGB_00,
	RGB_01,
	RGB_10,
	RGB_11,
	MAX_RGB_PT,
};

enum {
	QUAD_1,
	QUAD_2,
	QUAD_3,
	QUAD_4,
	MAX_QUAD,
};

struct cal_center {
	int x;
	int y;
	int thres;
};

struct cal_line {
	int num;
	int den;
	int con;
};

struct cal_coef {
	int a, b, c, d;
	int e, f, g, h;
};

struct mdnie_tune {
	struct seqinfo *seqtbl;
	u32 nr_seqtbl;
	struct maptbl *maptbl;
	u32 nr_maptbl;
	struct maptbl *scr_white_maptbl;
	u32 nr_scr_white_maptbl;
	struct maptbl *etc_maptbl;
	u32 nr_etc_maptbl;
	struct cal_center center;
	struct cal_line line[MAX_CAL_LINE];
	struct cal_coef coef[MAX_QUAD];
	u32 cal_x_center;
	u32 cal_y_center;
	u32 cal_boundary_center;
	u8 vtx[MAX_WCRD_TYPE][MAX_CCRD_PT][MAX_COLOR];
	u32 num_ldu_mode;
	u32 num_night_level;
	u32 num_color_lens_color;
	u32 num_color_lens_level;
};

struct mdnie_properties {
	u32 enable;
	enum SCENARIO scenario;
	enum SCENARIO_MODE mode;
	enum BYPASS bypass;
	enum HBM hbm;
	enum HMD_MODE hmd;
	enum NIGHT_MODE night;
	enum NIGHT_LEVEL night_level;
	enum COLOR_LENS color_lens;
	enum COLOR_LENS_COLOR color_lens_color;
	enum COLOR_LENS_LEVEL color_lens_level;
	enum HDR hdr;
	enum LIGHT_NOTIFICATION light_notification;
	enum ACCESSIBILITY accessibility;
	enum LDU_MODE ldu;
	enum SCR_WHITE_MODE scr_white_mode;
	enum TRANS_MODE trans_mode;

	/* for color adjustment */
	u8 scr[MAX_MDNIE_SCR_LEN];
	u32 sz_scr;

	int wcrd_x, wcrd_y;

	/* default whiteRGB : color coordinated wrgb */
	u8 coord_wrgb[MAX_WCRD_TYPE][MAX_COLOR];
	/* sensor whiteRGB */
	u8 ssr_wrgb[MAX_COLOR];
	/* current whiteRGB */
	u8 cur_wrgb[MAX_COLOR];
	/* default whiteRGB : color coordinated wrgb */
	u8 def_wrgb[MAX_COLOR];
	s8 def_wrgb_ofs[MAX_COLOR];

	u32 num_ldu_mode;
	u32 num_night_level;
	u32 num_color_lens_color;
	u32 num_color_lens_level;
	struct cal_line line[MAX_CAL_LINE];
	struct cal_coef coef[MAX_QUAD];
	u32 cal_x_center;
	u32 cal_y_center;
	u32 cal_boundary_center;
	u8 vtx[MAX_WCRD_TYPE][MAX_CCRD_PT][MAX_COLOR];

	/* support */
	unsigned support_ldu:1;
	unsigned support_trans:1;

	/* dirty flag */
	unsigned tuning:1;				/* tuning file loaded */
	unsigned update_color_adj:1;	/* color adjustement updated */
	unsigned update_scenario:1;		/* scenario updated */
	unsigned update_color_coord:1;	/* color coordinate updated */
	unsigned update_ldu:1;			/* adjust ldu updated */
	unsigned update_sensorRGB:1;	/* sensorRGB scr white updated */

	/* mdnie tuning */
#ifdef CONFIG_EXYNOS_DECON_LCD_TUNING
	char tfilepath[128];			/* tuning file path */
#endif
};

struct mdnie_info {
	struct device *dev;
	struct class *class;
	struct mutex lock;
	struct mdnie_properties props;
	struct notifier_block fb_notif;
#ifdef CONFIG_DISPLAY_USE_INFO
	struct notifier_block dpui_notif;
#endif
	struct maptbl *maptbl;
	u32 nr_maptbl;
	struct maptbl *scr_white_maptbl;
	u32 nr_scr_white_maptbl;
	struct maptbl *etc_maptbl;
	u32 nr_etc_maptbl;
	struct seqinfo *seqtbl;
	u32 nr_seqtbl;
	u32 nr_reg;
};

#ifdef CONFIG_EXYNOS_DECON_MDNIE_LITE
extern int mdnie_probe(struct panel_device *panel, struct mdnie_tune *mdnie_tune);
extern int mdnie_enable(struct mdnie_info *mdnie);
extern int mdnie_disable(struct mdnie_info *mdnie);
extern int mdnie_update(struct mdnie_info *mdnie);
#else
static inline int mdnie_probe(struct panel_device *panel, struct mdnie_tune *mdnie_tune) { return 0; }
static inline int mdnie_enable(struct mdnie_info *mdnie) { return 0; }
static inline int mdnie_disable(struct mdnie_info *mdnie) { return 0; }
static inline int mdnie_update(struct mdnie_info *mdnie) { return 0; }
#endif
extern struct maptbl *mdnie_find_maptbl(struct mdnie_info *);
extern struct maptbl *mdnie_find_etc_maptbl(struct mdnie_info *, int);
extern int mdnie_get_maptbl_index(struct mdnie_info *);
extern ssize_t attr_store_for_each(struct class *, const char *, const char *, size_t);
#endif /* __MDNIE_H__ */