aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/touchscreen/grande_touchkey.c
blob: 5ba5595589a18bbe3dbb3328a9265efdcbea396f (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
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
/*
 * Driver for keys on GPIO lines capable of generating interrupts.
 *
 * Copyright 2005 Phil Blundell
 *
 * 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/init.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/sched.h>
#include <linux/pm.h>
#include <linux/sysctl.h>
#include <linux/proc_fs.h>
#include <linux/delay.h>
#include <linux/platform_device.h>
#include <linux/input.h>
#include <mach/regs-gpio.h>
#include <plat/gpio-cfg.h>
#include <asm/gpio.h>
#include <linux/miscdevice.h>
#include <asm/uaccess.h>
#include <linux/earlysuspend.h>
#include <asm/io.h>
#include <mach/gpio.h>
#include <mach/irqs.h>
#include <mach/gpio-midas.h>
#include <linux/regulator/consumer.h>
#include <linux/regulator/driver.h>
#include <linux/regulator/machine.h>

#ifdef CONFIG_CPU_FREQ
#include <mach/cpufreq.h>
#endif

/*
Melfas touchkey register
*/
#define KEYCODE_REG 0x00
#define FIRMWARE_VERSION 0x01
#define TOUCHKEY_MODULE_VERSION 0x03
#define TOUCHKEY_ADDRESS	0x20

#define UPDOWN_EVENT_BIT 0x08
#define KEYCODE_BIT 0x07
#define ESD_STATE_BIT 0x10
#define I2C_M_WR 0 /* for i2c */

//#define IRQ_TOUCH_INT (IRQ_EINT_GROUP22_BASE + 1)
#define DEVICE_NAME "melfas-touchkey"
#define INT_PEND_BASE	0xE0200A54

#define MCS5080_CHIP		0x03
#define MCS5080_last_ver	0x01  /*w999 v19*/

// if you want to see log, set this definition to NULL or KERN_WARNING
#define TCHKEY_KERN_DEBUG      KERN_DEBUG

#define _3_TOUCH_SDA_28V GPIO_3_TOUCH_SDA
#define _3_TOUCH_SCL_28V GPIO_3_TOUCH_SCL
#define _3_GPIO_TOUCH_EN	GPIO_3_TOUCH_EN
#define _3_GPIO_TOUCH_INT	GPIO_3_TOUCH_INT
#define IRQ_TOUCH_INT gpio_to_irq(GPIO_3_TOUCH_INT)



#define TOUCHKEY_KEYCODE_MENU 	KEY_MENU
#define TOUCHKEY_KEYCODE_HOME 	KEY_HOME
#define TOUCHKEY_KEYCODE_BACK 	KEY_BACK
#define TOUCHKEY_KEYCODE_SEARCH 	KEY_END
#define FLIP_CLOSE 0
#define FLIP_OPEN 1

static int touchkey_keycode[5] = {0,KEY_MENU , KEY_HOME, KEY_BACK, 0};
static unsigned int HWREV=7;
static u8 activation_onoff = 1;	// 0:deactivate   1:activate
static u8 is_suspending = 0;
static u8 user_press_on = 0;
static u8 touchkey_dead = 0;
static u8 menu_sensitivity = 0;
static u8 back_sensitivity = 0;
static u8 home_sensitivity = 0;

static int touchkey_enable = 0;

static u8 version_info[3];
static void	__iomem	*gpio_pend_mask_mem;
static int Flip_status=FLIP_OPEN;

struct i2c_touchkey_driver {
	struct i2c_client *client;
	struct input_dev *input_dev;
	struct work_struct work;
	struct early_suspend	early_suspend;
};
struct i2c_touchkey_driver *touchkey_driver = NULL;
struct workqueue_struct *touchkey_wq;
extern struct class *sec_class;
struct device *sec_touchkey;

static const struct i2c_device_id melfas_touchkey_id[] = {
	{"melfas-touchkey", 0},
	{}
};

MODULE_DEVICE_TABLE(i2c, melfas_touchkey_id);

extern void get_touchkey_data(u8 *data, u8 length);
static void init_hw(void);
static int touchkey_pmic_control(int onoff);
static int i2c_touchkey_probe(struct i2c_client *client, const struct i2c_device_id *id);
static void melfas_touchkey_switch_early_suspend(int FILP_STATE);
static void melfas_touchkey_switch_early_resume(int FILP_STATE);


struct i2c_driver touchkey_i2c_driver =
{
	.driver = {
		   .name = "melfas-touchkey",
	},
	.id_table = melfas_touchkey_id,
	.probe = i2c_touchkey_probe,
};


static int i2c_touchkey_read(u8 reg, u8 *val, unsigned int len)
{
	int	err;
	int	retry = 3;
	struct i2c_msg	msg[1];

	if((touchkey_driver == NULL)||touchkey_dead)
	{
		return -ENODEV;
	}

	while(retry--)
	{
		msg->addr	= touchkey_driver->client->addr;
		msg->flags = I2C_M_RD;
		msg->len   = len;
		msg->buf   = val;
		err = i2c_transfer(touchkey_driver->client->adapter, msg, 1);

		if (err >= 0)
		{
			return 0;
		}
		printk(KERN_ERR "%s %d i2c transfer error\n", __func__, __LINE__);/* add by inter.park */
		mdelay(10);
	}

	return err;

}

static int i2c_touchkey_write(u8 *val, unsigned int len)
{
	int err;
	struct i2c_msg msg[1];
	unsigned char data[2];

	if((touchkey_driver == NULL)||is_suspending||touchkey_dead)
	{
		return -ENODEV;
	}

	data[0] = *val;
	msg->addr = touchkey_driver->client->addr;
	msg->flags = I2C_M_WR;
	msg->len = len;
	msg->buf = data;

	err = i2c_transfer(touchkey_driver->client->adapter, msg, 1);

	if (err >= 0) return 0;

	printk(KERN_ERR "%s %d i2c transfer error\n", __func__, __LINE__);

	return err;
}

static unsigned int touch_state_val;
//extern unsigned int touch_state_val;
extern void TSP_forced_release(void);
void  touchkey_work_func(struct work_struct * p)
{
	u8 data[14];
	int keycode;
	int retry = 10;
	if (Flip_status == FLIP_CLOSE) {
		if (!gpio_get_value(_3_GPIO_TOUCH_INT) && !touchkey_dead) {
			i2c_touchkey_read(KEYCODE_REG, data, 14);

			keycode = touchkey_keycode[data[0] & KEYCODE_BIT];
		if(activation_onoff){
			if(data[0] & UPDOWN_EVENT_BIT) // key released
			{
				user_press_on = 0;
				input_report_key(touchkey_driver->input_dev, touchkey_keycode[data[0] &  KEYCODE_BIT], 0);
				input_sync(touchkey_driver->input_dev);
			}
			else // key pressed
			{
				if(touch_state_val == 1)
				{
					printk(TCHKEY_KERN_DEBUG "touchkey pressed but don't send event because touch is pressed. \n");
				}
				else
				{
					if(keycode == TOUCHKEY_KEYCODE_BACK)
					{
						user_press_on = 3;
						back_sensitivity = data[5];
					}
					else if(keycode == TOUCHKEY_KEYCODE_MENU)
					{
						user_press_on = 1;
						menu_sensitivity = data[3];
					}
					else if(keycode == TOUCHKEY_KEYCODE_HOME)
					{
						user_press_on = 2;
						home_sensitivity = data[4];
					}
					input_report_key(touchkey_driver->input_dev, keycode,1);
						input_sync(touchkey_driver->input_dev);
				}
			}
		}
	}
	else
		printk(KERN_ERR "touchkey interrupt line is high!\n");
	}

	else
	i2c_touchkey_read(KEYCODE_REG, data, 14);

	enable_irq(IRQ_TOUCH_INT);
	return ;
}

static irqreturn_t touchkey_interrupt(int irq, void *dummy)
{
	printk("TKEY interrupt call\n");
	disable_irq_nosync(IRQ_TOUCH_INT);
	queue_work(touchkey_wq, &touchkey_driver->work);
	
	return IRQ_HANDLED;
}

void samsung_switching_tkey(int flip)
{
	u8 data[6];
	int ret;

	if (touchkey_driver == NULL)
		return;

	printk(KERN_ERR "[TKEY] samsung_switching_tkey, Flip_status : %d, flip : %d \n", Flip_status, flip);
	
	if (Flip_status != flip)
	{
		Flip_status=flip;
		if (flip == FLIP_CLOSE) {
			touchkey_enable = 1;
			melfas_touchkey_switch_early_resume(flip);
			}
		else {
			touchkey_enable = 0;
			melfas_touchkey_switch_early_suspend(flip);
	}
	}

}
EXPORT_SYMBOL(samsung_switching_tkey);

static void melfas_touchkey_switch_early_suspend(int FILP_STATE){

	unsigned char data;
	
	if (touchkey_driver == NULL)
		return;

	data = 0x02;
	i2c_touchkey_write(&data, 1);	//Key LED force off

	printk(KERN_DEBUG "melfas_touchkey_switch_early_suspend, %d\n", FILP_STATE);
	if (touchkey_enable < 0) {
		printk("---%s---touchkey_enable: %d\n", __FUNCTION__,
			   touchkey_enable);
		return;
	}
	gpio_direction_output(_3_GPIO_TOUCH_EN, 0);
	gpio_direction_output(_3_TOUCH_SDA_28V, 0);
	gpio_direction_output(_3_TOUCH_SCL_28V, 0);
	if (system_rev >= 14)
		touchkey_pmic_control(0);

	disable_irq(IRQ_TOUCH_INT);

#ifdef USE_IRQ_FREE
	free_irq(IRQ_TOUCH_INT, NULL);
#endif

}

static void melfas_touchkey_switch_early_resume(int FILP_STATE){
	int err = 0;
	u8 data[14];
	int retry =5;
	u8 data1 = 0x01;
	if (touchkey_driver == NULL)
       return;

	if (Flip_status == FLIP_OPEN)
		return;

	printk(KERN_ERR "%d\n", FILP_STATE);

	i2c_touchkey_write(&data1, 1);
	
	init_hw();

#ifdef USE_IRQ_FREE
	msleep(50);


	printk("%s, %d\n",__func__, __LINE__);
	err = request_threaded_irq(IRQ_TOUCH_INT, NULL, touchkey_interrupt,
			IRQF_DISABLED | IRQF_TRIGGER_LOW | IRQF_ONESHOT, "touchkey_int", NULL);
	if (err) {
		printk(KERN_ERR "%s Can't allocate irq .. %d\n", __FUNCTION__, err);
	}
#endif

	//force raed (for INT high) before enable_irq
	while(!(gpio_get_value(GPIO_3_TOUCH_INT))){
		i2c_touchkey_read(KEYCODE_REG, data, 1);
		printk("%s : INT high force read , data = %d\n",__func__,data[0]);
		mdelay(5);
		if(retry<0) break;
		retry--;
	}

	enable_irq(IRQ_TOUCH_INT);
}

#ifdef CONFIG_HAS_EARLYSUSPEND
static void melfas_touchkey_early_suspend(struct early_suspend *h)
{
    pr_info("melfas_touchkey_early_suspend +++\n");
	touchkey_enable = 0;
	is_suspending = 1;
	if(user_press_on==1)
	{
		input_report_key(touchkey_driver->input_dev, TOUCHKEY_KEYCODE_MENU, 0);
//		printk(TCHKEY_KERN_DEBUG "%s release menu key\n",__func__);
	}
	else if(user_press_on==2)
	{
		input_report_key(touchkey_driver->input_dev, TOUCHKEY_KEYCODE_BACK, 0);
//		printk(TCHKEY_KERN_DEBUG "%s release back key\n",__func__);
	}
	user_press_on = 0;

	if(touchkey_dead)
	{
		printk(KERN_ERR "touchkey died after ESD");
		return;
	}

	disable_irq(IRQ_TOUCH_INT);
	gpio_direction_output(_3_GPIO_TOUCH_EN, 0);
	gpio_direction_output(_3_TOUCH_SDA_28V, 0);
	gpio_direction_output(_3_TOUCH_SCL_28V, 0);
	if (system_rev >= 14)
		touchkey_pmic_control(0);
    pr_info("melfas_touchkey_early_suspend ---\n");
}

static void melfas_touchkey_early_resume(struct early_suspend *h)
{
    pr_info("melfas_touchkey_early_resume +++\n");
	touchkey_enable = 1;
	if(touchkey_dead)
	{
		printk(KERN_ERR "touchkey died after ESD");
		return;
	}

	init_hw();
#if 0
	//clear interrupt
	if(readl(gpio_pend_mask_mem)&(0x1<<1))
		writel(readl(gpio_pend_mask_mem)|(0x1<<1), gpio_pend_mask_mem);
#endif
	enable_irq(IRQ_TOUCH_INT);
	is_suspending = 0;

    pr_info("melfas_touchkey_early_resume ---\n");
}
#endif	// End of CONFIG_HAS_EARLYSUSPEND

extern int mcsdl_download_binary_data(u8 chip_ver);
//extern int mcsdl_download_binary_file(unsigned char *pData, unsigned short nBinary_length);
static int i2c_touchkey_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
	struct device *dev = &client->dev;
	struct input_dev *input_dev;
	int err = 0;

	printk("melfas touchkey probe called!\n");
	touchkey_driver = kzalloc(sizeof(struct i2c_touchkey_driver), GFP_KERNEL);
	if (touchkey_driver == NULL)
	{
		dev_err(dev, "failed to create our state\n");
		return -ENOMEM;
	}

	touchkey_driver->client = client;

	touchkey_driver->client->irq = IRQ_TOUCH_INT;
	strlcpy(touchkey_driver->client->name, "melfas-touchkey", I2C_NAME_SIZE);

	input_dev = input_allocate_device();

	if (!input_dev)
		return -ENOMEM;

	touchkey_driver->input_dev = input_dev;

	input_dev->name = DEVICE_NAME;
	input_dev->phys = "melfas-touchkey/input0";
	input_dev->id.bustype = BUS_HOST;

	set_bit(EV_SYN, input_dev->evbit);
	set_bit(EV_LED, input_dev->evbit);
	set_bit(LED_MISC, input_dev->ledbit);
	set_bit(EV_KEY, input_dev->evbit);
	set_bit(touchkey_keycode[1], input_dev->keybit);
	set_bit(touchkey_keycode[2], input_dev->keybit);
	set_bit(touchkey_keycode[3], input_dev->keybit);
	set_bit(touchkey_keycode[4], input_dev->keybit);

	err = input_register_device(input_dev);
	if (err)
	{
		input_free_device(input_dev);
		return err;
	}

	gpio_pend_mask_mem = ioremap(INT_PEND_BASE, 0x10);
	touchkey_wq = create_singlethread_workqueue("melfas_touchkey_wq");
	if (!touchkey_wq)
		return -ENOMEM;

	INIT_WORK(&touchkey_driver->work, touchkey_work_func);

#ifdef CONFIG_HAS_EARLYSUSPEND
	touchkey_driver->early_suspend.suspend = melfas_touchkey_early_suspend;
	touchkey_driver->early_suspend.resume = melfas_touchkey_early_resume;
	register_early_suspend(&touchkey_driver->early_suspend);
#endif				/* CONFIG_HAS_EARLYSUSPEND */
	touchkey_enable = 1;
	if (request_irq(IRQ_TOUCH_INT, touchkey_interrupt, IRQF_DISABLED, DEVICE_NAME, touchkey_driver))
	{
		printk(KERN_ERR "%s Can't allocate irq ..\n", __FUNCTION__);
		return -EBUSY;
	}
	return 0;
}
static int touchkey_pmic_control(int onoff)
{
	struct regulator *regulator;
	regulator = regulator_get(NULL, "TOUCH_PULL_UP");

	if (onoff) {
		regulator_enable(regulator);
		printk(KERN_INFO "[touchkey]touchkey_pmic_control on\n");
		}
	else {
		regulator_disable(regulator);
		printk(KERN_INFO "[touchkey]touchkey_pmic_control off\n");
		}
	regulator_put(regulator);
	return 0;
}
static void init_hw(void)
{
	if (system_rev >= 14)
		touchkey_pmic_control(1);

	gpio_set_value(_3_GPIO_TOUCH_EN, 1);
	msleep(100);
	s3c_gpio_setpull(_3_GPIO_TOUCH_INT, S3C_GPIO_PULL_UP);
	irq_set_irq_type(IRQ_TOUCH_INT, IRQF_TRIGGER_FALLING);
	s3c_gpio_cfgpin(_3_GPIO_TOUCH_INT, S3C_GPIO_SFN(0xf));
}


int touchkey_update_open (struct inode *inode, struct file *filp)
{
	return 0;
}

ssize_t touchkey_update_read(struct file *filp, char *buf, size_t count, loff_t *f_pos)
{
	return 0;
}

ssize_t touchkey_update_write (struct file *filp, const char *buf, size_t count, loff_t *f_pos)
{
	return count;
}

int touchkey_update_release (struct inode *inode, struct file *filp)
{
	return 0;
}

static ssize_t touchkey_activation_store(struct device *dev,
        struct device_attribute *attr, const char *buf, size_t size)
{
	printk(TCHKEY_KERN_DEBUG "called %s\n", __func__);
	sscanf(buf, "%hhu", &activation_onoff);
	printk(TCHKEY_KERN_DEBUG "deactivation test = %d\n", activation_onoff);
	return size;
}

static ssize_t touchkey_version_show(struct device *dev,
        struct device_attribute *attr, char *buf)
{
	printk(TCHKEY_KERN_DEBUG "called %s\n", __func__);
	return sprintf(buf,"%02x\n",version_info[1]);
}

static ssize_t touchkey_recommend_show(struct device *dev,
        struct device_attribute *attr, char *buf)
{
	u8 recommended_ver;
	printk(TCHKEY_KERN_DEBUG "called %s\n", __func__);
	if (version_info[2] == MCS5080_CHIP)
		recommended_ver = MCS5080_last_ver;
	else
		recommended_ver = version_info[1];

	return sprintf(buf,"%02x\n",recommended_ver);
}

static ssize_t touchkey_firmup_show(struct device *dev,
        struct device_attribute *attr, char *buf)
{
	printk(TCHKEY_KERN_DEBUG "Touchkey firm-up start!\n");

	if (version_info[2] == MCS5080_CHIP)
		mcsdl_download_binary_data(MCS5080_CHIP);
	else
		printk(KERN_ERR "Touchkey IC module is old, can't update!");

	get_touchkey_data(version_info, 3);
	printk(TCHKEY_KERN_DEBUG "Updated F/W version: 0x%x, Module version:0x%x\n", version_info[1], version_info[2]);
	return sprintf(buf,"%02x\n",version_info[1]);
}

static ssize_t touchkey_init_show(struct device *dev,
        struct device_attribute *attr, char *buf)
{
	printk(TCHKEY_KERN_DEBUG "called %s \n", __func__);
	return sprintf(buf, "%d\n",touchkey_dead);
}

static ssize_t touchkey_menu_show(struct device *dev,
        struct device_attribute *attr, char *buf)
{
	printk(TCHKEY_KERN_DEBUG "called %s \n", __func__);
	return sprintf(buf, "%d\n",menu_sensitivity);
}
static ssize_t touchkey_home_show(struct device *dev,
        struct device_attribute *attr, char *buf)
{
	printk(TCHKEY_KERN_DEBUG "called %s \n", __func__);
	return sprintf(buf, "%d\n",home_sensitivity);
}

static ssize_t touchkey_back_show(struct device *dev,
        struct device_attribute *attr, char *buf)
{
	printk(TCHKEY_KERN_DEBUG "called %s \n", __func__);
	return sprintf(buf, "%d\n",back_sensitivity);
}

static ssize_t touch_led_control(struct device *dev, struct device_attribute *attr, const char *buf, size_t size)
{
	u8 data;
	if (!touchkey_enable)
		return -1;

	sscanf(buf, "%hhu", &data);
	i2c_touchkey_write(&data, 1);	// LED on(data=1) or off(data=2)
	return size;
}

static ssize_t touchkey_enable_disable(struct device *dev, struct device_attribute *attr, const char *buf, size_t size)
{
	// this function is called when platform shutdown thread begins
	printk(TCHKEY_KERN_DEBUG "called %s %c \n",__func__, *buf);
	if(*buf == '0')
	{
		is_suspending = 1;
	    disable_irq(IRQ_TOUCH_INT);
	    gpio_direction_output(_3_GPIO_TOUCH_EN, 0);
	}
	else
	{
	    printk(KERN_ERR "%s: unknown command %c \n",__func__, *buf);
	}

        return size;
}

static DEVICE_ATTR(touchkey_activation, 0664, NULL, touchkey_activation_store);
static DEVICE_ATTR(touchkey_firm_version_panel, S_IRUGO, touchkey_version_show, NULL);
static DEVICE_ATTR(touchkey_firm_version_phone, S_IRUGO, touchkey_recommend_show, NULL);
static DEVICE_ATTR(recommended_version, S_IRUGO, touchkey_recommend_show, NULL);
static DEVICE_ATTR(touchkey_firm_update, S_IRUGO, touchkey_firmup_show, NULL);
static DEVICE_ATTR(touchkey_init, S_IRUGO, touchkey_init_show, NULL);
static DEVICE_ATTR(touchkey_menu, S_IRUGO, touchkey_menu_show, NULL);
static DEVICE_ATTR(touchkey_back, S_IRUGO, touchkey_back_show, NULL);
static DEVICE_ATTR(touchkey_home, S_IRUGO, touchkey_home_show, NULL);
static DEVICE_ATTR(brightness, 0664, NULL, touch_led_control);
static DEVICE_ATTR(enable_disable, 0664, NULL, touchkey_enable_disable);

static struct attribute *touchkey_attributes[] = {
	&dev_attr_touchkey_activation.attr,
	&dev_attr_touchkey_firm_version_panel.attr,
	&dev_attr_touchkey_firm_version_phone.attr,
	&dev_attr_recommended_version.attr,
	&dev_attr_touchkey_firm_update.attr,
	&dev_attr_touchkey_init.attr,
	&dev_attr_touchkey_menu.attr,
	&dev_attr_touchkey_back.attr,
	&dev_attr_touchkey_home.attr,
	&dev_attr_brightness.attr,
	&dev_attr_enable_disable.attr,
	NULL,
};


static int __init touchkey_init(void)
{

	int ret = 0;

	u8 updated = 0;
	if ((ret = gpio_request(_3_GPIO_TOUCH_EN, "_3_GPIO_TOUCH_EN")))
		printk(KERN_ERR "Failed to request gpio %s:%d\n", __func__, __LINE__);

	sec_touchkey=device_create(sec_class, NULL, 0, NULL, "sec_touchkey");

	if (device_create_file(sec_touchkey, &dev_attr_touchkey_activation) < 0)
		pr_err("Failed to create device file(%s)!\n", dev_attr_touchkey_activation.attr.name);

	if (device_create_file(sec_touchkey, &dev_attr_touchkey_firm_version_panel) < 0)
		pr_err("Failed to create device file(%s)!\n", dev_attr_touchkey_firm_version_panel.attr.name);

	if (device_create_file(sec_touchkey, &dev_attr_touchkey_firm_version_phone) < 0)
		pr_err("Failed to create device file(%s)!\n", dev_attr_touchkey_firm_version_phone.attr.name);

	if (device_create_file(sec_touchkey, &dev_attr_recommended_version) < 0)
		pr_err("Failed to create device file(%s)!\n", dev_attr_recommended_version.attr.name);

	if (device_create_file(sec_touchkey, &dev_attr_touchkey_firm_update) < 0)
		pr_err("Failed to create device file(%s)!\n", dev_attr_touchkey_firm_update.attr.name);

	if (device_create_file(sec_touchkey, &dev_attr_touchkey_init) < 0)
		pr_err("Failed to create device file(%s)!\n", dev_attr_touchkey_init.attr.name);

	if (device_create_file(sec_touchkey, &dev_attr_touchkey_menu) < 0)
		pr_err("Failed to create device file(%s)!\n", dev_attr_touchkey_menu.attr.name);

	if (device_create_file(sec_touchkey, &dev_attr_touchkey_back) < 0)
		pr_err("Failed to create device file(%s)!\n", dev_attr_touchkey_back.attr.name);

	if (device_create_file(sec_touchkey, &dev_attr_touchkey_home) < 0)
		pr_err("Failed to create device file(%s)!\n", dev_attr_touchkey_home.attr.name);

	if (device_create_file(sec_touchkey, &dev_attr_brightness) < 0)
		pr_err("Failed to create device file(%s)!\n", dev_attr_brightness.attr.name);

	if (device_create_file(sec_touchkey, &dev_attr_enable_disable) < 0)
		pr_err("Failed to create device file(%s)!\n", dev_attr_enable_disable.attr.name);

	init_hw();

	get_touchkey_data(version_info, 3);
	printk(TCHKEY_KERN_DEBUG "%s F/W version: 0x%x, Module version:0x%x\n",__FUNCTION__, version_info[1], version_info[2]);

//-------------------   Auto Firmware Update Routine Start   -------------------//
		if (version_info[1] == 0xff) {
			mcsdl_download_binary_data(MCS5080_CHIP);
			updated = 1;
		}
		else
		{
			if (version_info[2] == MCS5080_CHIP)
			{
				if (version_info[1] != MCS5080_last_ver)
				{
					mcsdl_download_binary_data(MCS5080_CHIP);
					updated = 1;
				} else
					printk(KERN_ERR"Touchkey IC module is old, can't update!");
			}
			if (updated)
			{
				get_touchkey_data(version_info, 3);
				printk(TCHKEY_KERN_DEBUG "Updated F/W version: 0x%x, Module version:0x%x\n", version_info[1], version_info[2]);
			}
		}
//-------------------   Auto Firmware Update Routine End   -------------------//

	ret = i2c_add_driver(&touchkey_i2c_driver);

	if(ret||(touchkey_driver==NULL))
	{
		touchkey_dead = 1;
		printk("ret = %d, touch_driver= %p:", ret, touchkey_driver);
		printk(KERN_ERR
		       "melfas touch keypad registration failed, module not inserted.ret= %d\n",
		       ret);
	}

	return ret;
}

static void __exit touchkey_exit(void)
{
	i2c_del_driver(&touchkey_i2c_driver);
//	misc_deregister(&touchkey_update_device);
	if (touchkey_wq)
		destroy_workqueue(touchkey_wq);
	gpio_free(_3_GPIO_TOUCH_INT);
}

module_init(touchkey_init);
module_exit(touchkey_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("@@@");
MODULE_DESCRIPTION("melfas touch keypad");