aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/mouse/trackpoint.c
diff options
context:
space:
mode:
authorDmitry Torokhov <dtor_core@ameritech.net>2005-09-04 02:40:20 -0400
committerDmitry Torokhov <dtor_core@ameritech.net>2005-09-04 02:40:20 -0400
commitcfe9e88866fe892f4f71bf132c64ec8bd5256e5e (patch)
treec1da19c8a2b1f9f1a32597554660747fe0aa5132 /drivers/input/mouse/trackpoint.c
parent15c42e5a1f0bccb69508059b8ae0720840068b8e (diff)
Input: rework psmouse attributes to reduce module size
Rearrange attribute code to use generic show and set handlers instead of replicating them for every attribute; switch to using attribute_group instead of creating all attributes manually. All this saves about 4K. Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input/mouse/trackpoint.c')
-rw-r--r--drivers/input/mouse/trackpoint.c183
1 files changed, 95 insertions, 88 deletions
diff --git a/drivers/input/mouse/trackpoint.c b/drivers/input/mouse/trackpoint.c
index aee3b24a9102..b4898d8a68e2 100644
--- a/drivers/input/mouse/trackpoint.c
+++ b/drivers/input/mouse/trackpoint.c
@@ -19,54 +19,6 @@
19#include "psmouse.h" 19#include "psmouse.h"
20#include "trackpoint.h" 20#include "trackpoint.h"
21 21
22PSMOUSE_DEFINE_ATTR(sensitivity);
23PSMOUSE_DEFINE_ATTR(speed);
24PSMOUSE_DEFINE_ATTR(inertia);
25PSMOUSE_DEFINE_ATTR(reach);
26PSMOUSE_DEFINE_ATTR(draghys);
27PSMOUSE_DEFINE_ATTR(mindrag);
28PSMOUSE_DEFINE_ATTR(thresh);
29PSMOUSE_DEFINE_ATTR(upthresh);
30PSMOUSE_DEFINE_ATTR(ztime);
31PSMOUSE_DEFINE_ATTR(jenks);
32PSMOUSE_DEFINE_ATTR(press_to_select);
33PSMOUSE_DEFINE_ATTR(skipback);
34PSMOUSE_DEFINE_ATTR(ext_dev);
35
36#define MAKE_ATTR_READ(_item) \
37 static ssize_t psmouse_attr_show_##_item(struct psmouse *psmouse, char *buf) \
38 { \
39 struct trackpoint_data *tp = psmouse->private; \
40 return sprintf(buf, "%lu\n", (unsigned long)tp->_item); \
41 }
42
43#define MAKE_ATTR_WRITE(_item, command) \
44 static ssize_t psmouse_attr_set_##_item(struct psmouse *psmouse, const char *buf, size_t count) \
45 { \
46 char *rest; \
47 unsigned long value; \
48 struct trackpoint_data *tp = psmouse->private; \
49 value = simple_strtoul(buf, &rest, 10); \
50 if (*rest) \
51 return -EINVAL; \
52 tp->_item = value; \
53 trackpoint_write(&psmouse->ps2dev, command, tp->_item); \
54 return count; \
55 }
56
57#define MAKE_ATTR_TOGGLE(_item, command, mask) \
58 static ssize_t psmouse_attr_set_##_item(struct psmouse *psmouse, const char *buf, size_t count) \
59 { \
60 unsigned char toggle; \
61 struct trackpoint_data *tp = psmouse->private; \
62 toggle = (buf[0] == '1') ? 1 : 0; \
63 if (toggle != tp->_item) { \
64 tp->_item = toggle; \
65 trackpoint_toggle_bit(&psmouse->ps2dev, command, mask); \
66 } \
67 return count; \
68 }
69
70/* 22/*
71 * Device IO: read, write and toggle bit 23 * Device IO: read, write and toggle bit
72 */ 24 */
@@ -108,59 +60,114 @@ static int trackpoint_toggle_bit(struct ps2dev *ps2dev, unsigned char loc, unsig
108 return 0; 60 return 0;
109} 61}
110 62
111MAKE_ATTR_WRITE(sensitivity, TP_SENS);
112MAKE_ATTR_READ(sensitivity);
113
114MAKE_ATTR_WRITE(speed, TP_SPEED);
115MAKE_ATTR_READ(speed);
116 63
117MAKE_ATTR_WRITE(inertia, TP_INERTIA); 64/*
118MAKE_ATTR_READ(inertia); 65 * Trackpoint-specific attributes
66 */
67struct trackpoint_attr_data {
68 size_t field_offset;
69 unsigned char command;
70 unsigned char mask;
71};
119 72
120MAKE_ATTR_WRITE(reach, TP_REACH); 73static ssize_t trackpoint_show_int_attr(struct psmouse *psmouse, void *data, char *buf)
121MAKE_ATTR_READ(reach); 74{
75 struct trackpoint_data *tp = psmouse->private;
76 struct trackpoint_attr_data *attr = data;
77 unsigned char *field = (unsigned char *)((char *)tp + attr->field_offset);
122 78
123MAKE_ATTR_WRITE(draghys, TP_DRAGHYS); 79 return sprintf(buf, "%u\n", *field);
124MAKE_ATTR_READ(draghys); 80}
125 81
126MAKE_ATTR_WRITE(mindrag, TP_MINDRAG); 82static ssize_t trackpoint_set_int_attr(struct psmouse *psmouse, void *data,
127MAKE_ATTR_READ(mindrag); 83 const char *buf, size_t count)
84{
85 struct trackpoint_data *tp = psmouse->private;
86 struct trackpoint_attr_data *attr = data;
87 unsigned char *field = (unsigned char *)((char *)tp + attr->field_offset);
88 unsigned long value;
89 char *rest;
128 90
129MAKE_ATTR_WRITE(thresh, TP_THRESH); 91 value = simple_strtoul(buf, &rest, 10);
130MAKE_ATTR_READ(thresh); 92 if (*rest || value > 255)
93 return -EINVAL;
131 94
132MAKE_ATTR_WRITE(upthresh, TP_UP_THRESH); 95 *field = value;
133MAKE_ATTR_READ(upthresh); 96 trackpoint_write(&psmouse->ps2dev, attr->command, value);
134 97
135MAKE_ATTR_WRITE(ztime, TP_Z_TIME); 98 return count;
136MAKE_ATTR_READ(ztime); 99}
137 100
138MAKE_ATTR_WRITE(jenks, TP_JENKS_CURV); 101#define TRACKPOINT_INT_ATTR(_name, _command) \
139MAKE_ATTR_READ(jenks); 102 static struct trackpoint_attr_data trackpoint_attr_##_name = { \
103 .field_offset = offsetof(struct trackpoint_data, _name), \
104 .command = _command, \
105 }; \
106 PSMOUSE_DEFINE_ATTR(_name, S_IWUSR | S_IRUGO, \
107 &trackpoint_attr_##_name, \
108 trackpoint_show_int_attr, trackpoint_set_int_attr)
109
110static ssize_t trackpoint_set_bit_attr(struct psmouse *psmouse, void *data,
111 const char *buf, size_t count)
112{
113 struct trackpoint_data *tp = psmouse->private;
114 struct trackpoint_attr_data *attr = data;
115 unsigned char *field = (unsigned char *)((char *)tp + attr->field_offset);
116 unsigned long value;
117 char *rest;
118
119 value = simple_strtoul(buf, &rest, 10);
120 if (*rest || value > 1)
121 return -EINVAL;
122
123 if (*field != value) {
124 *field = value;
125 trackpoint_toggle_bit(&psmouse->ps2dev, attr->command, attr->mask);
126 }
140 127
141MAKE_ATTR_TOGGLE(press_to_select, TP_TOGGLE_PTSON, TP_MASK_PTSON); 128 return count;
142MAKE_ATTR_READ(press_to_select); 129}
143 130
144MAKE_ATTR_TOGGLE(skipback, TP_TOGGLE_SKIPBACK, TP_MASK_SKIPBACK);
145MAKE_ATTR_READ(skipback);
146 131
147MAKE_ATTR_TOGGLE(ext_dev, TP_TOGGLE_EXT_DEV, TP_MASK_EXT_DEV); 132#define TRACKPOINT_BIT_ATTR(_name, _command, _mask) \
148MAKE_ATTR_READ(ext_dev); 133 static struct trackpoint_attr_data trackpoint_attr_##_name = { \
134 .field_offset = offsetof(struct trackpoint_data, _name), \
135 .command = _command, \
136 .mask = _mask, \
137 }; \
138 PSMOUSE_DEFINE_ATTR(_name, S_IWUSR | S_IRUGO, \
139 &trackpoint_attr_##_name, \
140 trackpoint_show_int_attr, trackpoint_set_bit_attr)
141
142TRACKPOINT_INT_ATTR(sensitivity, TP_SENS);
143TRACKPOINT_INT_ATTR(speed, TP_SPEED);
144TRACKPOINT_INT_ATTR(inertia, TP_INERTIA);
145TRACKPOINT_INT_ATTR(reach, TP_REACH);
146TRACKPOINT_INT_ATTR(draghys, TP_DRAGHYS);
147TRACKPOINT_INT_ATTR(mindrag, TP_MINDRAG);
148TRACKPOINT_INT_ATTR(thresh, TP_THRESH);
149TRACKPOINT_INT_ATTR(upthresh, TP_UP_THRESH);
150TRACKPOINT_INT_ATTR(ztime, TP_Z_TIME);
151TRACKPOINT_INT_ATTR(jenks, TP_JENKS_CURV);
152
153TRACKPOINT_BIT_ATTR(press_to_select, TP_TOGGLE_PTSON, TP_MASK_PTSON);
154TRACKPOINT_BIT_ATTR(skipback, TP_TOGGLE_SKIPBACK, TP_MASK_SKIPBACK);
155TRACKPOINT_BIT_ATTR(ext_dev, TP_TOGGLE_EXT_DEV, TP_MASK_EXT_DEV);
149 156
150static struct attribute *trackpoint_attrs[] = { 157static struct attribute *trackpoint_attrs[] = {
151 &psmouse_attr_sensitivity.attr, 158 &psmouse_attr_sensitivity.dattr.attr,
152 &psmouse_attr_speed.attr, 159 &psmouse_attr_speed.dattr.attr,
153 &psmouse_attr_inertia.attr, 160 &psmouse_attr_inertia.dattr.attr,
154 &psmouse_attr_reach.attr, 161 &psmouse_attr_reach.dattr.attr,
155 &psmouse_attr_draghys.attr, 162 &psmouse_attr_draghys.dattr.attr,
156 &psmouse_attr_mindrag.attr, 163 &psmouse_attr_mindrag.dattr.attr,
157 &psmouse_attr_thresh.attr, 164 &psmouse_attr_thresh.dattr.attr,
158 &psmouse_attr_upthresh.attr, 165 &psmouse_attr_upthresh.dattr.attr,
159 &psmouse_attr_ztime.attr, 166 &psmouse_attr_ztime.dattr.attr,
160 &psmouse_attr_jenks.attr, 167 &psmouse_attr_jenks.dattr.attr,
161 &psmouse_attr_press_to_select.attr, 168 &psmouse_attr_press_to_select.dattr.attr,
162 &psmouse_attr_skipback.attr, 169 &psmouse_attr_skipback.dattr.attr,
163 &psmouse_attr_ext_dev.attr, 170 &psmouse_attr_ext_dev.dattr.attr,
164 NULL 171 NULL
165}; 172};
166 173