2 * drivers/cbus/retu-pwrbutton.c
4 * Driver for sending retu power button event to input-layer
6 * Copyright (C) 2004 Nokia Corporation
8 * Written by Ari Saastamoinen <ari.saastamoinen@elektrobit.com>
10 * Contact Juha Yrjölä <juha.yrjola@nokia.com>
12 * This file is subject to the terms and conditions of the GNU General
13 * Public License. See the file "COPYING" in the main directory of this
14 * archive for more details.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <linux/module.h>
27 #include <linux/init.h>
28 #include <linux/kernel.h>
29 #include <linux/errno.h>
30 #include <linux/input.h>
31 #include <linux/timer.h>
32 #include <linux/jiffies.h>
33 #include <linux/bitops.h>
37 #define RETU_STATUS_PWRONX (1 << 5)
39 #define PWRBTN_DELAY 20
41 #define PWRBTN_PRESSED 1
43 static int pwrbtn_state
;
44 static struct input_dev
*pwrbtn_dev
;
45 static struct timer_list pwrbtn_timer
;
47 static void retubutton_timer_func(unsigned long arg
)
51 if (retu_read_reg(RETU_REG_STATUS
) & RETU_STATUS_PWRONX
)
54 state
= PWRBTN_PRESSED
;
56 if (pwrbtn_state
!= state
) {
57 input_report_key(pwrbtn_dev
, KEY_POWER
, state
);
63 * Interrupt function is called whenever power button key is pressed
66 static void retubutton_irq(unsigned long arg
)
68 retu_ack_irq(RETU_INT_PWR
);
69 mod_timer(&pwrbtn_timer
, jiffies
+ msecs_to_jiffies(PWRBTN_DELAY
));
74 * Allocates interrupt for power button and registers itself to input layer.
76 static int __init
retubutton_init(void)
80 printk(KERN_INFO
"Retu power button driver initialized\n");
83 init_timer(&pwrbtn_timer
);
84 pwrbtn_timer
.function
= retubutton_timer_func
;
86 if (retu_request_irq(irq
, &retubutton_irq
, 0, "PwrOnX") < 0) {
87 printk(KERN_ERR
"%s@%s: Cannot allocate irq\n",
88 __FUNCTION__
, __FILE__
);
92 pwrbtn_dev
= input_allocate_device();
96 pwrbtn_dev
->evbit
[0] = BIT_MASK(EV_KEY
);
97 pwrbtn_dev
->keybit
[BIT_WORD(KEY_POWER
)] = BIT_MASK(KEY_POWER
);
98 pwrbtn_dev
->name
= "retu-pwrbutton";
100 return input_register_device(pwrbtn_dev
);
104 * Cleanup function which is called when driver is unloaded
106 static void __exit
retubutton_exit(void)
108 retu_free_irq(RETU_INT_PWR
);
109 del_timer_sync(&pwrbtn_timer
);
110 input_unregister_device(pwrbtn_dev
);
113 module_init(retubutton_init
);
114 module_exit(retubutton_exit
);
116 MODULE_DESCRIPTION("Retu Power Button");
117 MODULE_LICENSE("GPL");
118 MODULE_AUTHOR("Ari Saastamoinen");