OMAP: Serial: Define OMAP uart MDR1 reg and remove magic numbers
[linux-2.6.git] / drivers / staging / speakup / fakekey.c
blobadb93f21c0d6c844b345d6c8fb9cec77d26c8efe
1 /* fakekey.c
2 * Functions for simulating keypresses.
4 * Copyright (C) 2010 the Speakup Team
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include <linux/types.h>
21 #include <linux/slab.h>
22 #include <linux/preempt.h>
23 #include <linux/percpu.h>
24 #include <linux/input.h>
26 #include "speakup.h"
28 #define PRESSED 1
29 #define RELEASED 0
31 DEFINE_PER_CPU(bool, reporting_keystroke);
33 static struct input_dev *virt_keyboard;
35 int speakup_add_virtual_keyboard(void)
37 int err;
39 virt_keyboard = input_allocate_device();
41 if (!virt_keyboard)
42 return -ENOMEM;
44 virt_keyboard->name = "Speakup";
45 virt_keyboard->id.bustype = BUS_VIRTUAL;
46 virt_keyboard->phys = "speakup/input0";
47 virt_keyboard->dev.parent = NULL;
49 __set_bit(EV_KEY, virt_keyboard->evbit);
50 __set_bit(KEY_DOWN, virt_keyboard->keybit);
52 err = input_register_device(virt_keyboard);
53 if (err) {
54 input_free_device(virt_keyboard);
55 virt_keyboard = NULL;
58 return err;
61 void speakup_remove_virtual_keyboard(void)
63 if (virt_keyboard != NULL) {
64 input_unregister_device(virt_keyboard);
65 input_free_device(virt_keyboard);
66 virt_keyboard = NULL;
71 * Send a simulated down-arrow to the application.
73 void speakup_fake_down_arrow(void)
75 unsigned long flags;
77 /* disable keyboard interrupts */
78 local_irq_save(flags);
79 /* don't change CPU */
80 preempt_disable();
82 __get_cpu_var(reporting_keystroke) = true;
83 input_report_key(virt_keyboard, KEY_DOWN, PRESSED);
84 input_report_key(virt_keyboard, KEY_DOWN, RELEASED);
85 __get_cpu_var(reporting_keystroke) = false;
87 /* reenable preemption */
88 preempt_enable();
89 /* reenable keyboard interrupts */
90 local_irq_restore(flags);
94 * Are we handling a simulated keypress on the current CPU?
95 * Returns a boolean.
97 bool speakup_fake_key_pressed(void)
99 bool is_pressed;
101 is_pressed = get_cpu_var(reporting_keystroke);
102 put_cpu_var(reporting_keystroke);
104 return is_pressed;