aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/mouse/hil_ptr.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input/mouse/hil_ptr.c')
-rw-r--r--drivers/input/mouse/hil_ptr.c97
1 files changed, 50 insertions, 47 deletions
diff --git a/drivers/input/mouse/hil_ptr.c b/drivers/input/mouse/hil_ptr.c
index bfb174fe3230..449bf4dcbbcc 100644
--- a/drivers/input/mouse/hil_ptr.c
+++ b/drivers/input/mouse/hil_ptr.c
@@ -88,10 +88,12 @@ static void hil_ptr_process_record(struct hil_ptr *ptr)
88 idx = ptr->idx4/4; 88 idx = ptr->idx4/4;
89 p = data[idx - 1]; 89 p = data[idx - 1];
90 90
91 if ((p & ~HIL_CMDCT_POL) == 91 if ((p & ~HIL_CMDCT_POL) ==
92 (HIL_ERR_INT | HIL_PKT_CMD | HIL_CMD_POL)) goto report; 92 (HIL_ERR_INT | HIL_PKT_CMD | HIL_CMD_POL))
93 if ((p & ~HIL_CMDCT_RPL) == 93 goto report;
94 (HIL_ERR_INT | HIL_PKT_CMD | HIL_CMD_RPL)) goto report; 94 if ((p & ~HIL_CMDCT_RPL) ==
95 (HIL_ERR_INT | HIL_PKT_CMD | HIL_CMD_RPL))
96 goto report;
95 97
96 /* Not a poll response. See if we are loading config records. */ 98 /* Not a poll response. See if we are loading config records. */
97 switch (p & HIL_PKT_DATA_MASK) { 99 switch (p & HIL_PKT_DATA_MASK) {
@@ -101,27 +103,32 @@ static void hil_ptr_process_record(struct hil_ptr *ptr)
101 for (; i < HIL_PTR_MAX_LENGTH; i++) 103 for (; i < HIL_PTR_MAX_LENGTH; i++)
102 ptr->idd[i] = 0; 104 ptr->idd[i] = 0;
103 break; 105 break;
106
104 case HIL_CMD_RSC: 107 case HIL_CMD_RSC:
105 for (i = 0; i < idx; i++) 108 for (i = 0; i < idx; i++)
106 ptr->rsc[i] = ptr->data[i] & HIL_PKT_DATA_MASK; 109 ptr->rsc[i] = ptr->data[i] & HIL_PKT_DATA_MASK;
107 for (; i < HIL_PTR_MAX_LENGTH; i++) 110 for (; i < HIL_PTR_MAX_LENGTH; i++)
108 ptr->rsc[i] = 0; 111 ptr->rsc[i] = 0;
109 break; 112 break;
113
110 case HIL_CMD_EXD: 114 case HIL_CMD_EXD:
111 for (i = 0; i < idx; i++) 115 for (i = 0; i < idx; i++)
112 ptr->exd[i] = ptr->data[i] & HIL_PKT_DATA_MASK; 116 ptr->exd[i] = ptr->data[i] & HIL_PKT_DATA_MASK;
113 for (; i < HIL_PTR_MAX_LENGTH; i++) 117 for (; i < HIL_PTR_MAX_LENGTH; i++)
114 ptr->exd[i] = 0; 118 ptr->exd[i] = 0;
115 break; 119 break;
120
116 case HIL_CMD_RNM: 121 case HIL_CMD_RNM:
117 for (i = 0; i < idx; i++) 122 for (i = 0; i < idx; i++)
118 ptr->rnm[i] = ptr->data[i] & HIL_PKT_DATA_MASK; 123 ptr->rnm[i] = ptr->data[i] & HIL_PKT_DATA_MASK;
119 for (; i < HIL_PTR_MAX_LENGTH + 1; i++) 124 for (; i < HIL_PTR_MAX_LENGTH + 1; i++)
120 ptr->rnm[i] = '\0'; 125 ptr->rnm[i] = 0;
121 break; 126 break;
127
122 default: 128 default:
123 /* These occur when device isn't present */ 129 /* These occur when device isn't present */
124 if (p == (HIL_ERR_INT | HIL_PKT_CMD)) break; 130 if (p == (HIL_ERR_INT | HIL_PKT_CMD))
131 break;
125 /* Anything else we'd like to know about. */ 132 /* Anything else we'd like to know about. */
126 printk(KERN_WARNING PREFIX "Device sent unknown record %x\n", p); 133 printk(KERN_WARNING PREFIX "Device sent unknown record %x\n", p);
127 break; 134 break;
@@ -130,7 +137,8 @@ static void hil_ptr_process_record(struct hil_ptr *ptr)
130 137
131 report: 138 report:
132 if ((p & HIL_CMDCT_POL) != idx - 1) { 139 if ((p & HIL_CMDCT_POL) != idx - 1) {
133 printk(KERN_WARNING PREFIX "Malformed poll packet %x (idx = %i)\n", p, idx); 140 printk(KERN_WARNING PREFIX
141 "Malformed poll packet %x (idx = %i)\n", p, idx);
134 goto out; 142 goto out;
135 } 143 }
136 144
@@ -139,7 +147,7 @@ static void hil_ptr_process_record(struct hil_ptr *ptr)
139 laxis += i; 147 laxis += i;
140 148
141 ax16 = ptr->idd[1] & HIL_IDD_HEADER_16BIT; /* 8 or 16bit resolution */ 149 ax16 = ptr->idd[1] & HIL_IDD_HEADER_16BIT; /* 8 or 16bit resolution */
142 absdev = ptr->idd[1] & HIL_IDD_HEADER_ABS; 150 absdev = ptr->idd[1] & HIL_IDD_HEADER_ABS;
143 151
144 for (cnt = 1; i < laxis; i++) { 152 for (cnt = 1; i < laxis; i++) {
145 unsigned int lo,hi,val; 153 unsigned int lo,hi,val;
@@ -157,7 +165,8 @@ static void hil_ptr_process_record(struct hil_ptr *ptr)
157 input_report_abs(dev, ABS_X + i, val); 165 input_report_abs(dev, ABS_X + i, val);
158 } else { 166 } else {
159 val = (int) (((int8_t)lo) | ((int8_t)hi<<8)); 167 val = (int) (((int8_t)lo) | ((int8_t)hi<<8));
160 if (i%3) val *= -1; 168 if (i%3)
169 val *= -1;
161 input_report_rel(dev, REL_X + i, val); 170 input_report_rel(dev, REL_X + i, val);
162 } 171 }
163 } 172 }
@@ -168,10 +177,11 @@ static void hil_ptr_process_record(struct hil_ptr *ptr)
168 btn = ptr->data[cnt++]; 177 btn = ptr->data[cnt++];
169 up = btn & 1; 178 up = btn & 1;
170 btn &= 0xfe; 179 btn &= 0xfe;
171 if (btn == 0x8e) { 180 if (btn == 0x8e)
172 continue; /* TODO: proximity == touch? */ 181 continue; /* TODO: proximity == touch? */
173 } 182 else
174 else if ((btn > 0x8c) || (btn < 0x80)) continue; 183 if ((btn > 0x8c) || (btn < 0x80))
184 continue;
175 btn = (btn - 0x80) >> 1; 185 btn = (btn - 0x80) >> 1;
176 btn = ptr->btnmap[btn]; 186 btn = ptr->btnmap[btn];
177 input_report_key(dev, btn, !up); 187 input_report_key(dev, btn, !up);
@@ -182,14 +192,14 @@ static void hil_ptr_process_record(struct hil_ptr *ptr)
182 up(&ptr->sem); 192 up(&ptr->sem);
183} 193}
184 194
185static void hil_ptr_process_err(struct hil_ptr *ptr) { 195static void hil_ptr_process_err(struct hil_ptr *ptr)
196{
186 printk(KERN_WARNING PREFIX "errored HIL packet\n"); 197 printk(KERN_WARNING PREFIX "errored HIL packet\n");
187 ptr->idx4 = 0; 198 ptr->idx4 = 0;
188 up(&ptr->sem); 199 up(&ptr->sem);
189 return;
190} 200}
191 201
192static irqreturn_t hil_ptr_interrupt(struct serio *serio, 202static irqreturn_t hil_ptr_interrupt(struct serio *serio,
193 unsigned char data, unsigned int flags) 203 unsigned char data, unsigned int flags)
194{ 204{
195 struct hil_ptr *ptr; 205 struct hil_ptr *ptr;
@@ -197,29 +207,29 @@ static irqreturn_t hil_ptr_interrupt(struct serio *serio,
197 int idx; 207 int idx;
198 208
199 ptr = serio_get_drvdata(serio); 209 ptr = serio_get_drvdata(serio);
200 if (ptr == NULL) { 210 BUG_ON(ptr == NULL);
201 BUG();
202 return IRQ_HANDLED;
203 }
204 211
205 if (ptr->idx4 >= (HIL_PTR_MAX_LENGTH * sizeof(hil_packet))) { 212 if (ptr->idx4 >= (HIL_PTR_MAX_LENGTH * sizeof(hil_packet))) {
206 hil_ptr_process_err(ptr); 213 hil_ptr_process_err(ptr);
207 return IRQ_HANDLED; 214 return IRQ_HANDLED;
208 } 215 }
209 idx = ptr->idx4/4; 216 idx = ptr->idx4/4;
210 if (!(ptr->idx4 % 4)) ptr->data[idx] = 0; 217 if (!(ptr->idx4 % 4))
218 ptr->data[idx] = 0;
211 packet = ptr->data[idx]; 219 packet = ptr->data[idx];
212 packet |= ((hil_packet)data) << ((3 - (ptr->idx4 % 4)) * 8); 220 packet |= ((hil_packet)data) << ((3 - (ptr->idx4 % 4)) * 8);
213 ptr->data[idx] = packet; 221 ptr->data[idx] = packet;
214 222
215 /* Records of N 4-byte hil_packets must terminate with a command. */ 223 /* Records of N 4-byte hil_packets must terminate with a command. */
216 if ((++(ptr->idx4)) % 4) return IRQ_HANDLED; 224 if ((++(ptr->idx4)) % 4)
225 return IRQ_HANDLED;
217 if ((packet & 0xffff0000) != HIL_ERR_INT) { 226 if ((packet & 0xffff0000) != HIL_ERR_INT) {
218 hil_ptr_process_err(ptr); 227 hil_ptr_process_err(ptr);
219 return IRQ_HANDLED; 228 return IRQ_HANDLED;
220 } 229 }
221 if (packet & HIL_PKT_CMD) 230 if (packet & HIL_PKT_CMD)
222 hil_ptr_process_record(ptr); 231 hil_ptr_process_record(ptr);
232
223 return IRQ_HANDLED; 233 return IRQ_HANDLED;
224} 234}
225 235
@@ -228,10 +238,7 @@ static void hil_ptr_disconnect(struct serio *serio)
228 struct hil_ptr *ptr; 238 struct hil_ptr *ptr;
229 239
230 ptr = serio_get_drvdata(serio); 240 ptr = serio_get_drvdata(serio);
231 if (ptr == NULL) { 241 BUG_ON(ptr == NULL);
232 BUG();
233 return;
234 }
235 242
236 serio_close(serio); 243 serio_close(serio);
237 input_unregister_device(ptr->dev); 244 input_unregister_device(ptr->dev);
@@ -241,7 +248,7 @@ static void hil_ptr_disconnect(struct serio *serio)
241static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver) 248static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver)
242{ 249{
243 struct hil_ptr *ptr; 250 struct hil_ptr *ptr;
244 char *txt; 251 const char *txt;
245 unsigned int i, naxsets, btntype; 252 unsigned int i, naxsets, btntype;
246 uint8_t did, *idd; 253 uint8_t did, *idd;
247 254
@@ -252,42 +259,40 @@ static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver)
252 if (!ptr->dev) 259 if (!ptr->dev)
253 goto bail0; 260 goto bail0;
254 261
255 ptr->dev->private = ptr;
256
257 if (serio_open(serio, driver)) 262 if (serio_open(serio, driver))
258 goto bail1; 263 goto bail1;
259 264
260 serio_set_drvdata(serio, ptr); 265 serio_set_drvdata(serio, ptr);
261 ptr->serio = serio; 266 ptr->serio = serio;
262 267
263 init_MUTEX_LOCKED(&(ptr->sem)); 268 init_MUTEX_LOCKED(&ptr->sem);
264 269
265 /* Get device info. MLC driver supplies devid/status/etc. */ 270 /* Get device info. MLC driver supplies devid/status/etc. */
266 serio->write(serio, 0); 271 serio->write(serio, 0);
267 serio->write(serio, 0); 272 serio->write(serio, 0);
268 serio->write(serio, HIL_PKT_CMD >> 8); 273 serio->write(serio, HIL_PKT_CMD >> 8);
269 serio->write(serio, HIL_CMD_IDD); 274 serio->write(serio, HIL_CMD_IDD);
270 down(&(ptr->sem)); 275 down(&ptr->sem);
271 276
272 serio->write(serio, 0); 277 serio->write(serio, 0);
273 serio->write(serio, 0); 278 serio->write(serio, 0);
274 serio->write(serio, HIL_PKT_CMD >> 8); 279 serio->write(serio, HIL_PKT_CMD >> 8);
275 serio->write(serio, HIL_CMD_RSC); 280 serio->write(serio, HIL_CMD_RSC);
276 down(&(ptr->sem)); 281 down(&ptr->sem);
277 282
278 serio->write(serio, 0); 283 serio->write(serio, 0);
279 serio->write(serio, 0); 284 serio->write(serio, 0);
280 serio->write(serio, HIL_PKT_CMD >> 8); 285 serio->write(serio, HIL_PKT_CMD >> 8);
281 serio->write(serio, HIL_CMD_RNM); 286 serio->write(serio, HIL_CMD_RNM);
282 down(&(ptr->sem)); 287 down(&ptr->sem);
283 288
284 serio->write(serio, 0); 289 serio->write(serio, 0);
285 serio->write(serio, 0); 290 serio->write(serio, 0);
286 serio->write(serio, HIL_PKT_CMD >> 8); 291 serio->write(serio, HIL_PKT_CMD >> 8);
287 serio->write(serio, HIL_CMD_EXD); 292 serio->write(serio, HIL_CMD_EXD);
288 down(&(ptr->sem)); 293 down(&ptr->sem);
289 294
290 up(&(ptr->sem)); 295 up(&ptr->sem);
291 296
292 did = ptr->idd[0]; 297 did = ptr->idd[0];
293 idd = ptr->idd + 1; 298 idd = ptr->idd + 1;
@@ -301,12 +306,12 @@ static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver)
301 ptr->dev->evbit[0] = BIT(EV_ABS); 306 ptr->dev->evbit[0] = BIT(EV_ABS);
302 txt = "absolute"; 307 txt = "absolute";
303 } 308 }
304 if (!ptr->dev->evbit[0]) { 309 if (!ptr->dev->evbit[0])
305 goto bail2; 310 goto bail2;
306 }
307 311
308 ptr->nbtn = HIL_IDD_NUM_BUTTONS(idd); 312 ptr->nbtn = HIL_IDD_NUM_BUTTONS(idd);
309 if (ptr->nbtn) ptr->dev->evbit[0] |= BIT(EV_KEY); 313 if (ptr->nbtn)
314 ptr->dev->evbit[0] |= BIT(EV_KEY);
310 315
311 naxsets = HIL_IDD_NUM_AXSETS(*idd); 316 naxsets = HIL_IDD_NUM_AXSETS(*idd);
312 ptr->naxes = HIL_IDD_NUM_AXES_PER_SET(*idd); 317 ptr->naxes = HIL_IDD_NUM_AXES_PER_SET(*idd);
@@ -315,7 +320,7 @@ static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver)
315 did, txt); 320 did, txt);
316 printk(KERN_INFO PREFIX "HIL pointer has %i buttons and %i sets of %i axes\n", 321 printk(KERN_INFO PREFIX "HIL pointer has %i buttons and %i sets of %i axes\n",
317 ptr->nbtn, naxsets, ptr->naxes); 322 ptr->nbtn, naxsets, ptr->naxes);
318 323
319 btntype = BTN_MISC; 324 btntype = BTN_MISC;
320 if ((did & HIL_IDD_DID_ABS_TABLET_MASK) == HIL_IDD_DID_ABS_TABLET) 325 if ((did & HIL_IDD_DID_ABS_TABLET_MASK) == HIL_IDD_DID_ABS_TABLET)
321#ifdef TABLET_SIMULATES_MOUSE 326#ifdef TABLET_SIMULATES_MOUSE
@@ -325,7 +330,7 @@ static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver)
325#endif 330#endif
326 if ((did & HIL_IDD_DID_ABS_TSCREEN_MASK) == HIL_IDD_DID_ABS_TSCREEN) 331 if ((did & HIL_IDD_DID_ABS_TSCREEN_MASK) == HIL_IDD_DID_ABS_TSCREEN)
327 btntype = BTN_TOUCH; 332 btntype = BTN_TOUCH;
328 333
329 if ((did & HIL_IDD_DID_REL_MOUSE_MASK) == HIL_IDD_DID_REL_MOUSE) 334 if ((did & HIL_IDD_DID_REL_MOUSE_MASK) == HIL_IDD_DID_REL_MOUSE)
330 btntype = BTN_MOUSE; 335 btntype = BTN_MOUSE;
331 336
@@ -341,12 +346,10 @@ static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver)
341 } 346 }
342 347
343 if ((did & HIL_IDD_DID_TYPE_MASK) == HIL_IDD_DID_TYPE_REL) { 348 if ((did & HIL_IDD_DID_TYPE_MASK) == HIL_IDD_DID_TYPE_REL) {
344 for (i = 0; i < ptr->naxes; i++) { 349 for (i = 0; i < ptr->naxes; i++)
345 set_bit(REL_X + i, ptr->dev->relbit); 350 set_bit(REL_X + i, ptr->dev->relbit);
346 } 351 for (i = 3; (i < ptr->naxes + 3) && (naxsets > 1); i++)
347 for (i = 3; (i < ptr->naxes + 3) && (naxsets > 1); i++) {
348 set_bit(REL_X + i, ptr->dev->relbit); 352 set_bit(REL_X + i, ptr->dev->relbit);
349 }
350 } else { 353 } else {
351 for (i = 0; i < ptr->naxes; i++) { 354 for (i = 0; i < ptr->naxes; i++) {
352 set_bit(ABS_X + i, ptr->dev->absbit); 355 set_bit(ABS_X + i, ptr->dev->absbit);
@@ -375,7 +378,7 @@ static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver)
375 ptr->dev->id.vendor = PCI_VENDOR_ID_HP; 378 ptr->dev->id.vendor = PCI_VENDOR_ID_HP;
376 ptr->dev->id.product = 0x0001; /* TODO: get from ptr->rsc */ 379 ptr->dev->id.product = 0x0001; /* TODO: get from ptr->rsc */
377 ptr->dev->id.version = 0x0100; /* TODO: get from ptr->rsc */ 380 ptr->dev->id.version = 0x0100; /* TODO: get from ptr->rsc */
378 ptr->dev->cdev.dev = &serio->dev; 381 ptr->dev->dev.parent = &serio->dev;
379 382
380 input_register_device(ptr->dev); 383 input_register_device(ptr->dev);
381 printk(KERN_INFO "input: %s (%s), ID: %d\n", 384 printk(KERN_INFO "input: %s (%s), ID: %d\n",
@@ -419,11 +422,11 @@ static int __init hil_ptr_init(void)
419{ 422{
420 return serio_register_driver(&hil_ptr_serio_driver); 423 return serio_register_driver(&hil_ptr_serio_driver);
421} 424}
422 425
423static void __exit hil_ptr_exit(void) 426static void __exit hil_ptr_exit(void)
424{ 427{
425 serio_unregister_driver(&hil_ptr_serio_driver); 428 serio_unregister_driver(&hil_ptr_serio_driver);
426} 429}
427 430
428module_init(hil_ptr_init); 431module_init(hil_ptr_init);
429module_exit(hil_ptr_exit); 432module_exit(hil_ptr_exit);