diff options
author | Dmitry Torokhov <dtor_core@ameritech.net> | 2005-09-04 02:40:20 -0400 |
---|---|---|
committer | Dmitry Torokhov <dtor_core@ameritech.net> | 2005-09-04 02:40:20 -0400 |
commit | cfe9e88866fe892f4f71bf132c64ec8bd5256e5e (patch) | |
tree | c1da19c8a2b1f9f1a32597554660747fe0aa5132 /drivers/input/mouse/trackpoint.c | |
parent | 15c42e5a1f0bccb69508059b8ae0720840068b8e (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.c | 183 |
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 | ||
22 | PSMOUSE_DEFINE_ATTR(sensitivity); | ||
23 | PSMOUSE_DEFINE_ATTR(speed); | ||
24 | PSMOUSE_DEFINE_ATTR(inertia); | ||
25 | PSMOUSE_DEFINE_ATTR(reach); | ||
26 | PSMOUSE_DEFINE_ATTR(draghys); | ||
27 | PSMOUSE_DEFINE_ATTR(mindrag); | ||
28 | PSMOUSE_DEFINE_ATTR(thresh); | ||
29 | PSMOUSE_DEFINE_ATTR(upthresh); | ||
30 | PSMOUSE_DEFINE_ATTR(ztime); | ||
31 | PSMOUSE_DEFINE_ATTR(jenks); | ||
32 | PSMOUSE_DEFINE_ATTR(press_to_select); | ||
33 | PSMOUSE_DEFINE_ATTR(skipback); | ||
34 | PSMOUSE_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 | ||
111 | MAKE_ATTR_WRITE(sensitivity, TP_SENS); | ||
112 | MAKE_ATTR_READ(sensitivity); | ||
113 | |||
114 | MAKE_ATTR_WRITE(speed, TP_SPEED); | ||
115 | MAKE_ATTR_READ(speed); | ||
116 | 63 | ||
117 | MAKE_ATTR_WRITE(inertia, TP_INERTIA); | 64 | /* |
118 | MAKE_ATTR_READ(inertia); | 65 | * Trackpoint-specific attributes |
66 | */ | ||
67 | struct trackpoint_attr_data { | ||
68 | size_t field_offset; | ||
69 | unsigned char command; | ||
70 | unsigned char mask; | ||
71 | }; | ||
119 | 72 | ||
120 | MAKE_ATTR_WRITE(reach, TP_REACH); | 73 | static ssize_t trackpoint_show_int_attr(struct psmouse *psmouse, void *data, char *buf) |
121 | MAKE_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 | ||
123 | MAKE_ATTR_WRITE(draghys, TP_DRAGHYS); | 79 | return sprintf(buf, "%u\n", *field); |
124 | MAKE_ATTR_READ(draghys); | 80 | } |
125 | 81 | ||
126 | MAKE_ATTR_WRITE(mindrag, TP_MINDRAG); | 82 | static ssize_t trackpoint_set_int_attr(struct psmouse *psmouse, void *data, |
127 | MAKE_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 | ||
129 | MAKE_ATTR_WRITE(thresh, TP_THRESH); | 91 | value = simple_strtoul(buf, &rest, 10); |
130 | MAKE_ATTR_READ(thresh); | 92 | if (*rest || value > 255) |
93 | return -EINVAL; | ||
131 | 94 | ||
132 | MAKE_ATTR_WRITE(upthresh, TP_UP_THRESH); | 95 | *field = value; |
133 | MAKE_ATTR_READ(upthresh); | 96 | trackpoint_write(&psmouse->ps2dev, attr->command, value); |
134 | 97 | ||
135 | MAKE_ATTR_WRITE(ztime, TP_Z_TIME); | 98 | return count; |
136 | MAKE_ATTR_READ(ztime); | 99 | } |
137 | 100 | ||
138 | MAKE_ATTR_WRITE(jenks, TP_JENKS_CURV); | 101 | #define TRACKPOINT_INT_ATTR(_name, _command) \ |
139 | MAKE_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 | |||
110 | static 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 | ||
141 | MAKE_ATTR_TOGGLE(press_to_select, TP_TOGGLE_PTSON, TP_MASK_PTSON); | 128 | return count; |
142 | MAKE_ATTR_READ(press_to_select); | 129 | } |
143 | 130 | ||
144 | MAKE_ATTR_TOGGLE(skipback, TP_TOGGLE_SKIPBACK, TP_MASK_SKIPBACK); | ||
145 | MAKE_ATTR_READ(skipback); | ||
146 | 131 | ||
147 | MAKE_ATTR_TOGGLE(ext_dev, TP_TOGGLE_EXT_DEV, TP_MASK_EXT_DEV); | 132 | #define TRACKPOINT_BIT_ATTR(_name, _command, _mask) \ |
148 | MAKE_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 | |||
142 | TRACKPOINT_INT_ATTR(sensitivity, TP_SENS); | ||
143 | TRACKPOINT_INT_ATTR(speed, TP_SPEED); | ||
144 | TRACKPOINT_INT_ATTR(inertia, TP_INERTIA); | ||
145 | TRACKPOINT_INT_ATTR(reach, TP_REACH); | ||
146 | TRACKPOINT_INT_ATTR(draghys, TP_DRAGHYS); | ||
147 | TRACKPOINT_INT_ATTR(mindrag, TP_MINDRAG); | ||
148 | TRACKPOINT_INT_ATTR(thresh, TP_THRESH); | ||
149 | TRACKPOINT_INT_ATTR(upthresh, TP_UP_THRESH); | ||
150 | TRACKPOINT_INT_ATTR(ztime, TP_Z_TIME); | ||
151 | TRACKPOINT_INT_ATTR(jenks, TP_JENKS_CURV); | ||
152 | |||
153 | TRACKPOINT_BIT_ATTR(press_to_select, TP_TOGGLE_PTSON, TP_MASK_PTSON); | ||
154 | TRACKPOINT_BIT_ATTR(skipback, TP_TOGGLE_SKIPBACK, TP_MASK_SKIPBACK); | ||
155 | TRACKPOINT_BIT_ATTR(ext_dev, TP_TOGGLE_EXT_DEV, TP_MASK_EXT_DEV); | ||
149 | 156 | ||
150 | static struct attribute *trackpoint_attrs[] = { | 157 | static 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 | ||