USB: ftdi_sio: fix status line change handling for TIOCMIWAIT and TIOCGICOUNT
[linux-flexiantxendom0.git] / ubuntu / omnibook / touchpad.c
1 /*
2  * touchpad.c -- enable/disable touchpad
3  * 
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2, or (at your option) any
7  * later version.
8  * 
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * Written by Soós Péter <sp@osb.hu>, 2002-2004
15  * Modified by Mathieu Bérard <mathieu.berard@crans.org>, 2006
16  */
17
18 #include "omnibook.h"
19 #include "hardware.h"
20
21 static int omnibook_touchpad_set(struct omnibook_operation *io_op, int status)
22 {
23         int retval = 0;
24
25         if(mutex_lock_interruptible(&io_op->backend->mutex))
26                 return -ERESTARTSYS;
27
28         if ((retval = __omnibook_toggle(io_op, !!status))) {
29                 printk(O_ERR "Failed touchpad %sable command.\n", status ? "en" : "dis");
30                 goto out;
31         }
32
33         io_op->backend->touchpad_state = !!status;
34
35         out:
36         mutex_unlock(&io_op->backend->mutex);
37         return retval;
38 }
39
40 /*
41  * Power management handlers: redisable touchpad on resume (if necessary)
42  */
43 static int omnibook_touchpad_resume(struct omnibook_operation *io_op)
44 {
45         int retval;
46         mutex_lock(&io_op->backend->mutex);
47         retval = __omnibook_toggle(io_op, !!io_op->backend->touchpad_state);
48         mutex_unlock(&io_op->backend->mutex);
49         return retval;
50 }
51
52 /*
53  * Hardware query is unsupported, so reading is unreliable.
54  */
55 static int omnibook_touchpad_read(char *buffer, struct omnibook_operation *io_op)
56 {
57         int len = 0;
58
59         if(mutex_lock_interruptible(&io_op->backend->mutex))
60                 return -ERESTARTSYS;
61
62         len +=
63             sprintf(buffer + len, "Last touchpad action was an %s command.\n",
64                     io_op->backend->touchpad_state ? "enable" : "disable");
65
66         mutex_unlock(&io_op->backend->mutex);
67         return len;
68 }
69
70 static int omnibook_touchpad_write(char *buffer, struct omnibook_operation *io_op)
71 {
72         int cmd;
73
74         if (*buffer == '0' || *buffer == '1') {
75                 cmd = *buffer - '0';
76                 if (!omnibook_touchpad_set(io_op, cmd)) {
77                         dprintk("%sabling touchpad.\n", cmd ? "En" : "Dis");
78                 }
79         } else {
80                 return -EINVAL;
81         }
82         return 0;
83 }
84
85
86 static int __init omnibook_touchpad_init(struct omnibook_operation *io_op)
87 {
88         mutex_lock(&io_op->backend->mutex);
89         /* Touchpad is assumed to be enabled by default */
90         io_op->backend->touchpad_state = 1;
91         mutex_unlock(&io_op->backend->mutex);
92         return 0;
93 }
94
95 /*
96  * Reenable touchpad upon exit
97  */
98 static void __exit omnibook_touchpad_cleanup(struct omnibook_operation *io_op)
99 {
100         omnibook_touchpad_set(io_op, 1);
101         printk(O_INFO "Enabling touchpad.\n");
102 }
103
104 static struct omnibook_tbl touchpad_table[] __initdata = {
105         {XE3GF | XE3GC | TSP10,
106          COMMAND(KBC, OMNIBOOK_KBC_CMD_TOUCHPAD_ENABLE, OMNIBOOK_KBC_CMD_TOUCHPAD_DISABLE)},
107         {TSM70, {CDI, 0, TSM70_FN_INDEX, 0, TSM70_TOUCHPAD_ON, TSM70_TOUCHPAD_OFF}},
108         {0,}
109 };
110
111 static struct omnibook_feature __declared_feature touchpad_driver = {
112         .name = "touchpad",
113         .enabled = 1,
114         .read = omnibook_touchpad_read,
115         .write = omnibook_touchpad_write,
116         .init = omnibook_touchpad_init,
117         .exit = omnibook_touchpad_cleanup,
118         .resume = omnibook_touchpad_resume,
119         .ectypes = XE3GF | XE3GC | TSP10 | TSM70,
120         .tbl = touchpad_table,
121 };
122
123 module_param_named(touchpad, touchpad_driver.enabled, int, S_IRUGO);
124 MODULE_PARM_DESC(touchpad, "Use 0 to disable, 1 to enable touchpad handling");
125
126 /* End of file */