summaryrefslogtreecommitdiff
path: root/drivers/input/keyboard/mxc_pwrkey.c
blob: 9621f1e3d78f5989a0dd926a9064f19abd2fed6c (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
/*
 * Copyright (C) 2010 Freescale Semiconductor, Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 *
 */

#include <linux/module.h>
#include <linux/sched.h>
#include <linux/mm.h>
#include <linux/init.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#include <linux/kd.h>
#include <linux/fs.h>
#include <linux/ioctl.h>
#include <linux/input.h>
#include <linux/irq.h>
#include <linux/interrupt.h>
#include <linux/platform_device.h>
#include <linux/pmic_external.h>
#include "../arch/arm/mach-mx5/mx51_pins.h"
#define KEYCODE_ONOFF            KEY_F4

#if 1
#define pk_printf printk
#else
#define pk_printf(...)
#endif

/*! Input device structure. */
struct input_dev *mxcpwrkey_dev = NULL;
static bool key_press=false;
static void power_key_event_handler(void)
{
	if (!key_press) {
		key_press = true;
		input_report_key(mxcpwrkey_dev, KEYCODE_ONOFF,  1);
		pk_printf("%s_KeyUP\n",__func__);
	}else {
		if (key_press){
			key_press = false;
			input_report_key(mxcpwrkey_dev, KEYCODE_ONOFF,  0);
			pk_printf("%s_KeyDown\n",__func__);
		}
	}
	
}
static int mxcpwrkey_probe(struct platform_device *pdev)
{
	int retval,err;
	pmic_event_callback_t power_key_event;

	printk("I.MX5 powerkey probe\n");
/*
	init_completion(&pk_cmd_done);
	pwrkey_task = kthread_run(powerkey_thread, pdev, "powerkey");
	if (IS_ERR(pwrkey_task)) {
		err = PTR_ERR(pwrkey_task);
		printk(KERN_ERR "powerkey: Failed to start powerkey_thread, err: %d\n", err);
		goto err1;
	}
*/
	mxcpwrkey_dev = input_allocate_device();
	if (!mxcpwrkey_dev) {
		printk(KERN_ERR
		       "mxcpwrkey_dev: not enough memory for input device\n");
		retval = -ENOMEM;
		goto err1;
	}
    
	mxcpwrkey_dev->name = "mxc_power_key";
	mxcpwrkey_dev->phys = "mxcpwrkey/input0";;
	mxcpwrkey_dev->id.bustype = BUS_HOST ;
	mxcpwrkey_dev->evbit[0] = BIT_MASK(EV_KEY) ;
    
	
	power_key_event.param = NULL;
	power_key_event.func = (void *)power_key_event_handler;
	pmic_event_subscribe(EVENT_PWRONI, power_key_event);

	input_set_capability(mxcpwrkey_dev, EV_KEY, KEYCODE_ONOFF);
	
	retval = input_register_device(mxcpwrkey_dev);
	if (retval < 0) {
		printk(KERN_ERR
		       "mxcpwrkey_dev: failed to register input device\n");
		goto err2;
	}
	return 0;
	
      err2:
	input_free_device(mxcpwrkey_dev);
      err1:
	return retval;
}
static int mxcpwrkey_remove(struct platform_device *pdev)
{
	return 0;
} 
static int mxc_pwrkey_suspend(struct platform_device *pdev, pm_message_t state)
{
	return 0;
}
static int mxc_pwrkey_resume(struct platform_device *pdev)
{
	return 0;
}
static struct platform_driver mxcpwrkey_driver = {
	.driver = {
		.name = "mxcpwrkey",
	},
	.probe = mxcpwrkey_probe,
	.remove = mxcpwrkey_remove,
	.suspend = mxc_pwrkey_suspend,
	.resume = mxc_pwrkey_resume,
};
static int __init mxcpwrkey_init(void)
{
	platform_driver_register(&mxcpwrkey_driver);
	return 0;
}

static void __exit mxcpwrkey_exit(void)
{
	platform_driver_unregister(&mxcpwrkey_driver);
}
module_init(mxcpwrkey_init);
module_exit(mxcpwrkey_exit);


MODULE_AUTHOR("eben");
MODULE_DESCRIPTION("MXC power key  Driver");
MODULE_LICENSE("GPL");