summaryrefstree
path: root/kernel/drivers/video/exynos/decon/decon_mdnie.c
blob: f7cc7859372512013045625c7dce457df1645827 (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
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
/* linux/drivers/video/mdnie.c
 *
 * Register interface file for Samsung mDNIe driver
 *
*/

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/mutex.h>
#include <linux/mm.h>
#include <linux/device.h>
#include <linux/backlight.h>
#include <linux/platform_device.h>
#include <linux/delay.h>
#include <linux/lcd.h>
#include <linux/fb.h>
#include <linux/pm_runtime.h>

#include "./panels/mdnie.h"
#include "mdnie_reg.h"

#if defined(CONFIG_PANEL_S6E3HA2_DYNAMIC) || defined(CONFIG_PANEL_S6E3HF2_DYNAMIC) || defined(CONFIG_PANEL_S6E3HA3_DYNAMIC)
#include "decon-mdnie_table_zero.h"
#endif
#if defined(CONFIG_TDMB)
#include "decon-mdnie_table_dmb.h"
#endif

#define MDNIE_SYSFS_PREFIX		"/sdcard/mdnie/"
#define PANEL_COORDINATE_PATH	"/sys/class/lcd/panel/color_coordinate"

#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 >= 6)
#if defined(CONFIG_LCD_HMT)
#define IS_HMT(idx)			(idx >= HMT_MDNIE_ON && idx < HMT_MDNIE_MAX)
#endif

#define SCENARIO_IS_VALID(idx)	(IS_DMB(idx) || IS_SCENARIO(idx))

/* Split 16 bit as 8bit x 2 */
#define GET_MSB_8BIT(x)		((x >> 8) & (BIT(8) - 1))
#define GET_LSB_8BIT(x)		((x >> 0) & (BIT(8) - 1))


static int mdnie_write_table(struct mdnie_info *mdnie, struct mdnie_table *table)
{

	if (IS_ERR_OR_NULL(table->tune[0].sequence)) {
		dev_err(mdnie->dev, "mdnie sequence %s is null, %lx\n",
				table->name, (unsigned long)table->tune[0].sequence);
		return -EPERM;
	}

	mutex_lock(&mdnie->dev_lock);
	mdnie->lpd_store_data = table->tune[0].sequence;
	mdnie->need_update = 1;
	mutex_unlock(&mdnie->dev_lock);
	return 0;
}

static struct mdnie_table *mdnie_find_table(struct mdnie_info *mdnie)
{
	struct mdnie_table *table = NULL;

	mutex_lock(&mdnie->lock);

	if (IS_ACCESSIBILITY(mdnie->accessibility)) {
		table = &accessibility_table[mdnie->accessibility];
		goto exit;
#if defined(CONFIG_LCD_HMT)
	} else if (IS_HMT(mdnie->hmt_mode)) {
		table = &hmt_table[mdnie->hmt_mode];
		goto exit;
#endif
	} else if (IS_HBM(mdnie->hbm)) {
		if((mdnie->scenario == BROWSER_MODE) || (mdnie->scenario == EBOOK_MODE))
			table = &hbm_table[HBM_ON_TEXT];
		else
			table = &hbm_table[HBM_ON];
		goto exit;
#if defined(CONFIG_TDMB)
	} else if (IS_DMB(mdnie->scenario)) {
		table = &dmb_table[mdnie->mode];
		goto exit;
#endif
	} else if (IS_SCENARIO(mdnie->scenario)) {
		table = &tuning_table[mdnie->scenario][mdnie->mode];
		dev_info(mdnie->dev, "%s: scenario = %d mode = %d, %s\n", __func__, mdnie->scenario, mdnie->mode, table->name);
		goto exit;
	}

exit:
	mutex_unlock(&mdnie->lock);

	return table;
}

static void mdnie_update_sequence(struct mdnie_info *mdnie, struct mdnie_table *table)
{
	mdnie_write_table(mdnie, table);
}

static void mdnie_update(struct mdnie_info *mdnie)
{
	struct mdnie_table *table = NULL;

	/*if (!mdnie->enable) {
		dev_err(mdnie->dev, "mdnie state is off\n");
		return;
	}*/

	table = mdnie_find_table(mdnie);
	if (!IS_ERR_OR_NULL(table) && !IS_ERR_OR_NULL(table->name)) {
		unsigned int s[3], i = 0;
		mdnie_t *wbuf=NULL;

		mdnie_update_sequence(mdnie, table);
		dev_info(mdnie->dev, "%s\n", table->name);

		mutex_lock(&mdnie->lock);

                s[0]=s[1]=s[2]=0;
                wbuf = table->tune[MDNIE_CMD1].sequence;
                while (wbuf[i] != END_SEQ) {
                    if(wbuf[i]>=MDNIE_WHITE_R && wbuf[i]<=MDNIE_WHITE_B) {
                            unsigned int k = wbuf[i]-MDNIE_WHITE_R;
                            u16 val = ((0xFF00 & wbuf[i+1]) >> 8);
                            val &= 0x00FF;
                            s[k]=val;
                    }
                    i += 2;
                }
		mdnie->white_r = s[0];
		mdnie->white_g = s[1];
		mdnie->white_b = s[2];

		mutex_unlock(&mdnie->lock);
	}
	return;
}

void mdnie_restore_data(struct mdnie_info *mdnie)
{
	int i = 0;
	const unsigned short *wbuf = NULL;
	wbuf = mdnie->lpd_store_data;

	if(mdnie->need_update || !mdnie->enable) {
		if(!IS_ERR_OR_NULL(wbuf)) {
			while (wbuf[i] != END_SEQ) {
				mdnie_write(wbuf[i]*4, wbuf[i+1]);
				i += 2;
			}
			mdnie->need_update = 0;
		} else {
			dev_info(mdnie->dev, "%s tuning buffer is null\n", __func__);
		}
	}
	return;
}

void decon_mdnie_start(struct mdnie_info *mdnie, u32 w, u32 h)
{
	if(IS_ERR_OR_NULL(mdnie))
		return;
   
	mutex_lock(&mdnie->lock);
	mdnie_reg_start(w, h);
	mdnie_restore_data(mdnie);
	mdnie->enable = 1;
	mutex_unlock(&mdnie->lock);
}

void decon_mdnie_stop(struct mdnie_info *mdnie)
{
	if(IS_ERR_OR_NULL(mdnie))
		return;

	mutex_lock(&mdnie->lock);
        mdnie_reg_stop();
	mdnie->enable = 0;
	mutex_unlock(&mdnie->lock);
}

void decon_mdnie_frame_update(struct mdnie_info *mdnie, u32 xres, u32 yres)
{
	if(IS_ERR_OR_NULL(mdnie))
		return;

	mutex_lock(&mdnie->lock);
	if(mdnie->enable) {
		mdnie_restore_data(mdnie);
		mdnie_reg_frame_update(xres, yres);
		/*dev_info(mdnie->dev, "%s: xres=%d, yres=%d\n", __func__, xres, yres);*/
	}
	mutex_unlock(&mdnie->lock);
}

u32 decon_mdnie_input_read(void)
{
	return mdnie_reg_read_input_data();
}

static void update_color_position(struct mdnie_info *mdnie, unsigned int idx)
{
	u8 mode, scenario;

	dev_info(mdnie->dev, "%s: idx=%d\n", __func__, idx);

	mutex_lock(&mdnie->lock);

	for (mode = 0; mode < MODE_MAX; mode++) {
		for (scenario = 0; scenario <= EMAIL_MODE; scenario++) {
			unsigned int i = 0;
			mdnie_t *wbuf=NULL;
			wbuf = tuning_table[scenario][mode].tune[MDNIE_CMD1].sequence;
			if (IS_ERR_OR_NULL(wbuf))
				continue;
                        if (scenario != EBOOK_MODE){
                            while (wbuf[i] != END_SEQ) {
                                if(wbuf[i]>=MDNIE_WHITE_R && wbuf[i]<=MDNIE_WHITE_B) {
                                    unsigned int k = wbuf[i]-MDNIE_WHITE_R;
                                    u16 val = (0x00FF & wbuf[i+1]);
                                    val |= ((0x00FF & coordinate_data[mode][idx][k]) << 8);
                                    /*dev_info(mdnie->dev, "%02x : %04x->%04x\n", wbuf[i], wbuf[i+1], val);*/
                                    wbuf[i+1] = val;
                                }
                                i += 2;
                            }
                        }
		}
	}

	mutex_unlock(&mdnie->lock);
}

static int mdnie_calibration(int *r)
{
	int ret = 0;

	if (r[1] > 0) {
		if (r[3] > 0)
			ret = 3;
		else
			ret = (r[4] < 0) ? 1 : 2;
	} else {
		if (r[2] < 0) {
			if (r[3] > 0)
				ret = 9;
			else
				ret = (r[4] < 0) ? 7 : 8;
		} else {
			if (r[3] > 0)
				ret = 6;
			else
				ret = (r[4] < 0) ? 4 : 5;
		}
	}

	pr_info("%d, %d, %d, %d, tune%d\n", r[1], r[2], r[3], r[4], ret);

	return ret;
}

static int get_panel_coordinate(struct mdnie_info *mdnie, int *result)
{
	int ret = 0;

	unsigned short x, y;

	x = mdnie->coordinate[0];
	y = mdnie->coordinate[1];


	result[1] = COLOR_OFFSET_F1(x, y);
	result[2] = COLOR_OFFSET_F2(x, y);
	result[3] = COLOR_OFFSET_F3(x, y);
	result[4] = COLOR_OFFSET_F4(x, y);

	ret = mdnie_calibration(result);
	dev_info(mdnie->dev, "%s: %d, %d, idx=%d\n", __func__, x, y, ret);

//skip_color_correction:
	mdnie->color_correction = 1;

	return ret;
}

static ssize_t mode_show(struct device *dev,
		struct device_attribute *attr, char *buf)
{
	struct mdnie_info *mdnie = dev_get_drvdata(dev);

	return sprintf(buf, "%d\n", mdnie->mode);
}

static ssize_t mode_store(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t count)
{
	struct mdnie_info *mdnie = dev_get_drvdata(dev);
	unsigned int value = 0;
	int ret;
	int result[5] = {0,};

	ret = kstrtouint(buf, 0, &value);
	if (ret < 0)
		return ret;

	dev_info(dev, "%s: value=%d\n", __func__, value);

	if (value >= MODE_MAX) {
		value = STANDARD;
		return -EINVAL;
	}

	mutex_lock(&mdnie->lock);
	mdnie->mode = value;
	mutex_unlock(&mdnie->lock);

	if (!mdnie->color_correction) {
		ret = get_panel_coordinate(mdnie, result);
		if (ret > 0)
			update_color_position(mdnie, ret);
	}

	mdnie_update(mdnie);

	return count;
}


static ssize_t scenario_show(struct device *dev,
		struct device_attribute *attr, char *buf)
{
	struct mdnie_info *mdnie = dev_get_drvdata(dev);

	return sprintf(buf, "%d\n", mdnie->scenario);
}

static ssize_t scenario_store(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t count)
{
	struct mdnie_info *mdnie = dev_get_drvdata(dev);
	unsigned int value;
	int ret;

	ret = kstrtouint(buf, 0, &value);
	if (ret < 0)
		return ret;

	dev_info(dev, "%s: value=%d\n", __func__, value);

	if (!SCENARIO_IS_VALID(value))
		value = UI_MODE;

	mutex_lock(&mdnie->lock);
	mdnie->scenario = value;
	mutex_unlock(&mdnie->lock);

	mdnie_update(mdnie);

	return count;
}

static ssize_t accessibility_show(struct device *dev,
		struct device_attribute *attr, char *buf)
{
	struct mdnie_info *mdnie = dev_get_drvdata(dev);

	return sprintf(buf, "%d\n", mdnie->accessibility);
}

static ssize_t accessibility_store(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t count)
{
	struct mdnie_info *mdnie = dev_get_drvdata(dev);
        unsigned int value, s[9], i = 0;
	int ret;

	ret = sscanf(buf, "%d %x %x %x %x %x %x %x %x %x",
		&value, &s[0], &s[1], &s[2], &s[3],
		&s[4], &s[5], &s[6], &s[7], &s[8]);

	dev_info(dev, "%s: value=%d\n", __func__, value);

	if (ret < 0){
		return ret;
	}
	else {
		if (value >= ACCESSIBILITY_MAX)
			value = ACCESSIBILITY_OFF;

		mutex_lock(&mdnie->lock);

		mdnie->accessibility = value;
		if (value == COLOR_BLIND) {
                        mdnie_t *wbuf=NULL;
			if (ret != 10) {
				mutex_unlock(&mdnie->lock);
				return -EINVAL;
			}
			wbuf = accessibility_table[COLOR_BLIND].tune[MDNIE_CMD1].sequence;
                        while (wbuf[i] != END_SEQ) {
                            if(wbuf[i]>=MDNIE_RED_R && wbuf[i]<=MDNIE_BLUE_B) {
                                unsigned int k = wbuf[i]-MDNIE_RED_R;
                                dev_info(mdnie->dev, "%02x : %04x->%04x\n", wbuf[i], wbuf[i+1], s[k]);
                                wbuf[i+1] = (u16)s[k];
                            }
                            i += 2;
                        }
			dev_info(dev, "%s: %s\n", __func__, buf);
		}

		mutex_unlock(&mdnie->lock);

		mdnie_update(mdnie);
	}

	return count;
}

static ssize_t color_correct_show(struct device *dev,
		struct device_attribute *attr, char *buf)
{
	struct mdnie_info *mdnie = dev_get_drvdata(dev);
	char *pos = buf;
	int i, idx, result[5] = {0,};

	if (!mdnie->color_correction)
		return -EINVAL;

	idx = get_panel_coordinate(mdnie, result);

	for (i = 1; i < (int) ARRAY_SIZE(result); i++)
		pos += sprintf(pos, "f%d: %d, ", i, result[i]);
	pos += sprintf(pos, "tune%d\n", idx);

	return pos - buf;
}

static ssize_t bypass_show(struct device *dev,
		struct device_attribute *attr, char *buf)
{
	struct mdnie_info *mdnie = dev_get_drvdata(dev);

	return sprintf(buf, "%d\n", mdnie->bypass);
}

static ssize_t bypass_store(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t count)
{
	struct mdnie_info *mdnie = dev_get_drvdata(dev);
	struct mdnie_table *table = NULL;
	unsigned int value;
	int ret;

	ret = kstrtouint(buf, 0, &value);

	dev_info(dev, "%s :: value=%d\n", __func__, value);

	if (ret < 0)
		return ret;
	else {
		if (value >= BYPASS_MAX)
			value = BYPASS_OFF;

		value = (value) ? BYPASS_ON : BYPASS_OFF;

		mutex_lock(&mdnie->lock);
		mdnie->bypass = value;
		mutex_unlock(&mdnie->lock);

		table = &bypass_table[value];
		if (!IS_ERR_OR_NULL(table)) {
			mdnie_update_sequence(mdnie, table);
			dev_info(mdnie->dev, "%s\n", table->name);
		}
	}

	return count;
}

static ssize_t sensorRGB_show(struct device *dev,
		struct device_attribute *attr, char *buf)
{
	struct mdnie_info *mdnie = dev_get_drvdata(dev);
	return sprintf(buf, "%d %d %d\n", mdnie->white_r,
		mdnie->white_g, mdnie->white_b);
}

static ssize_t sensorRGB_store(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t count)
{
	struct mdnie_info *mdnie = dev_get_drvdata(dev);
	unsigned int s[3];
	int ret;

	ret = sscanf(buf, "%d %d %d"
		, &s[0], &s[1], &s[2]);
	if (ret < 0)
		return ret;

        dev_info(mdnie->dev, "%d, %d, %d, accessibility=%d, mode=%d, senario=%d\n",
		s[0], s[1], s[2], mdnie->accessibility, mdnie->mode, mdnie->scenario);

	if ((mdnie->accessibility == ACCESSIBILITY_OFF)
		&& (mdnie->mode == AUTO)
		&& ((mdnie->scenario == BROWSER_MODE) || (mdnie->scenario == EBOOK_MODE))) {

		mdnie_t *wbuf=NULL;
		struct mdnie_table *table = NULL;
		unsigned int i = 0;

		table = mdnie_find_table(mdnie);
		memcpy(&(mdnie->table_buffer),
			table, sizeof(struct mdnie_table));
		memcpy(mdnie->sequence_buffer,
			table->tune[MDNIE_CMD1].sequence,
			sizeof(mdnie_t)*(table->tune[MDNIE_CMD1].size));
		mdnie->table_buffer.tune[MDNIE_CMD1].sequence
			= mdnie->sequence_buffer;

                mutex_lock(&mdnie->lock);

		wbuf = mdnie->table_buffer.tune[MDNIE_CMD1].sequence;

                while (wbuf[i] != END_SEQ) {
                    if(wbuf[i]>=MDNIE_WHITE_R && wbuf[i]<=MDNIE_WHITE_B) {
                            unsigned int k = wbuf[i]-MDNIE_WHITE_R;
                            u16 val = (0x00FF & wbuf[i+1]);
                            val |= ((0x00FF & s[k]) << 8);
                            dev_info(mdnie->dev, "%02x : %04x->%04x\n", wbuf[i], wbuf[i+1], val);
                            wbuf[i+1] = val;
                    }
                    i += 2;
                }
		mdnie->white_r = s[0];
		mdnie->white_g = s[1];
		mdnie->white_b = s[2];

		mutex_unlock(&mdnie->lock);

		mdnie_update_sequence(mdnie, &(mdnie->table_buffer));
	}

	return count;
}

#if defined(CONFIG_LCD_HMT)
static ssize_t hmtColorTemp_show(struct device *dev,
		struct device_attribute *attr, char *buf)
{
	struct mdnie_info *mdnie = dev_get_drvdata(dev);

	return sprintf(buf, "hmt_mode: %d\n", mdnie->hmt_mode);
}

static ssize_t hmtColorTemp_store(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t count)
{
	struct mdnie_info *mdnie = dev_get_drvdata(dev);
	unsigned int value;
	int ret;

	ret = kstrtouint(buf, 0, &value);
	if (ret < 0)
		return ret;


	if (value != mdnie->hmt_mode && value < HMT_MDNIE_MAX) {
		mutex_lock(&mdnie->lock);
		mdnie->hmt_mode = value;
		mutex_unlock(&mdnie->lock);
		mdnie_update(mdnie);
	}

	return count;
}
#endif

static struct device_attribute mdnie_attributes[] = {
	__ATTR(mode, 0664, mode_show, mode_store),
	__ATTR(scenario, 0664, scenario_show, scenario_store),
	__ATTR(accessibility, 0664, accessibility_show, accessibility_store),
	__ATTR(color_correct, 0444, color_correct_show, NULL),
	__ATTR(bypass, 0664, bypass_show, bypass_store),
//	__ATTR(mdnie, 0444, mdnie_show, NULL),
	__ATTR(sensorRGB, 0664, sensorRGB_show, sensorRGB_store),
#if defined(CONFIG_LCD_HMT)
	__ATTR(hmt_color_temperature, 0664, hmtColorTemp_show, hmtColorTemp_store),
#endif
	__ATTR_NULL,
};

static int fb_notifier_callback(struct notifier_block *self,
				 unsigned long event, void *data)
{
	struct mdnie_info *mdnie;
	struct fb_event *evdata = data;
	int fb_blank;

	switch (event) {
	case FB_EVENT_BLANK:
		break;
	default:
		return 0;
	}

	mdnie = container_of(self, struct mdnie_info, fb_notif);

	fb_blank = *(int *)evdata->data;

	dev_info(mdnie->dev, "%s: %d\n", __func__, fb_blank);

	if (evdata->info->node != 0)
		return 0;

        if (fb_blank == FB_BLANK_UNBLANK) {
		/*mutex_lock(&mdnie->lock);
		mdnie->enable = 1;
		mutex_unlock(&mdnie->lock);

		mdnie_update(mdnie);*/
	} else if (fb_blank == FB_BLANK_POWERDOWN) {
		/*mutex_lock(&mdnie->lock);
		mdnie->enable = 0;
		mutex_unlock(&mdnie->lock);*/
	}

	return 0;
}

static int mdnie_register_fb(struct mdnie_info *mdnie)
{
	memset(&mdnie->fb_notif, 0, sizeof(mdnie->fb_notif));
	mdnie->fb_notif.notifier_call = fb_notifier_callback;
	return fb_register_client(&mdnie->fb_notif);
}

struct mdnie_info* decon_mdnie_register(void)
{
	int ret = 0;
	struct mdnie_info *mdnie;
	static struct class *mdnie_class;

	pr_info("%s\n", __func__);

	mdnie_class = class_create(THIS_MODULE, "mdnie");
	if (IS_ERR_OR_NULL(mdnie_class)) {
		pr_err("failed to create mdnie class\n");
		ret = -EINVAL;
		goto error0;
	}

	mdnie_class->dev_attrs = mdnie_attributes;

	mdnie = kzalloc(sizeof(struct mdnie_info), GFP_KERNEL);
	if (!mdnie) {
		pr_err("failed to allocate mdnie\n");
		ret = -ENOMEM;
		goto error1;
	}

	mdnie->dev = device_create(mdnie_class, NULL, 0, &mdnie, "mdnie");
	if (IS_ERR_OR_NULL(mdnie->dev)) {
		pr_err("failed to create mdnie device\n");
		ret = -EINVAL;
		goto error2;
	}

	mdnie->scenario = UI_MODE;
	mdnie->mode = STANDARD;
	mdnie->enable = 0;
	mdnie->tuning = 0;
	mdnie->accessibility = ACCESSIBILITY_OFF;
	mdnie->bypass = BYPASS_OFF;
	mdnie->coordinate[0] = 0;
	mdnie->coordinate[1] = 0;

	mutex_init(&mdnie->lock);
	mutex_init(&mdnie->dev_lock);

	dev_set_drvdata(mdnie->dev, mdnie);

	mdnie_register_fb(mdnie);

	mdnie->enable = 0;
	mdnie_update(mdnie);

	dev_info(mdnie->dev, "registered successfully\n");

	return mdnie;

error2:
	kfree(mdnie);
error1:
	class_destroy(mdnie_class);
error0:
	return 0;
}