diff options
Diffstat (limited to 'drivers/media/rc/rc-main.c')
-rw-r--r-- | drivers/media/rc/rc-main.c | 612 |
1 files changed, 274 insertions, 338 deletions
diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c index 67a6bd5d949..5b67eea96eb 100644 --- a/drivers/media/rc/rc-main.c +++ b/drivers/media/rc/rc-main.c | |||
@@ -20,11 +20,6 @@ | |||
20 | #include <linux/device.h> | 20 | #include <linux/device.h> |
21 | #include "rc-core-priv.h" | 21 | #include "rc-core-priv.h" |
22 | 22 | ||
23 | #define IRRCV_NUM_DEVICES 256 | ||
24 | |||
25 | /* bit array to represent IR sysfs device number */ | ||
26 | static unsigned long ir_core_dev_number; | ||
27 | |||
28 | /* Sizes are in bytes, 256 bytes allows for 32 entries on x64 */ | 23 | /* Sizes are in bytes, 256 bytes allows for 32 entries on x64 */ |
29 | #define IR_TAB_MIN_SIZE 256 | 24 | #define IR_TAB_MIN_SIZE 256 |
30 | #define IR_TAB_MAX_SIZE 8192 | 25 | #define IR_TAB_MAX_SIZE 8192 |
@@ -36,12 +31,6 @@ static unsigned long ir_core_dev_number; | |||
36 | static LIST_HEAD(rc_map_list); | 31 | static LIST_HEAD(rc_map_list); |
37 | static DEFINE_SPINLOCK(rc_map_lock); | 32 | static DEFINE_SPINLOCK(rc_map_lock); |
38 | 33 | ||
39 | /* Forward declarations */ | ||
40 | static int ir_register_class(struct input_dev *input_dev); | ||
41 | static void ir_unregister_class(struct input_dev *input_dev); | ||
42 | static int ir_register_input(struct input_dev *input_dev); | ||
43 | |||
44 | |||
45 | static struct rc_keymap *seek_rc_map(const char *name) | 34 | static struct rc_keymap *seek_rc_map(const char *name) |
46 | { | 35 | { |
47 | struct rc_keymap *map = NULL; | 36 | struct rc_keymap *map = NULL; |
@@ -127,7 +116,7 @@ static struct rc_keymap empty_map = { | |||
127 | * @return: zero on success or a negative error code | 116 | * @return: zero on success or a negative error code |
128 | * | 117 | * |
129 | * This routine will initialize the ir_scancode_table and will allocate | 118 | * This routine will initialize the ir_scancode_table and will allocate |
130 | * memory to hold at least the specified number elements. | 119 | * memory to hold at least the specified number of elements. |
131 | */ | 120 | */ |
132 | static int ir_create_table(struct ir_scancode_table *rc_tab, | 121 | static int ir_create_table(struct ir_scancode_table *rc_tab, |
133 | const char *name, u64 ir_type, size_t size) | 122 | const char *name, u64 ir_type, size_t size) |
@@ -209,16 +198,16 @@ static int ir_resize_table(struct ir_scancode_table *rc_tab, gfp_t gfp_flags) | |||
209 | 198 | ||
210 | /** | 199 | /** |
211 | * ir_update_mapping() - set a keycode in the scancode->keycode table | 200 | * ir_update_mapping() - set a keycode in the scancode->keycode table |
212 | * @dev: the struct input_dev device descriptor | 201 | * @dev: the struct rc_dev device descriptor |
213 | * @rc_tab: scancode table to be adjusted | 202 | * @rc_tab: scancode table to be adjusted |
214 | * @index: index of the mapping that needs to be updated | 203 | * @index: index of the mapping that needs to be updated |
215 | * @keycode: the desired keycode | 204 | * @keycode: the desired keycode |
216 | * @return: previous keycode assigned to the mapping | 205 | * @return: previous keycode assigned to the mapping |
217 | * | 206 | * |
218 | * This routine is used to update scancode->keycopde mapping at given | 207 | * This routine is used to update scancode->keycode mapping at given |
219 | * position. | 208 | * position. |
220 | */ | 209 | */ |
221 | static unsigned int ir_update_mapping(struct input_dev *dev, | 210 | static unsigned int ir_update_mapping(struct rc_dev *dev, |
222 | struct ir_scancode_table *rc_tab, | 211 | struct ir_scancode_table *rc_tab, |
223 | unsigned int index, | 212 | unsigned int index, |
224 | unsigned int new_keycode) | 213 | unsigned int new_keycode) |
@@ -239,16 +228,16 @@ static unsigned int ir_update_mapping(struct input_dev *dev, | |||
239 | old_keycode == KEY_RESERVED ? "New" : "Replacing", | 228 | old_keycode == KEY_RESERVED ? "New" : "Replacing", |
240 | rc_tab->scan[index].scancode, new_keycode); | 229 | rc_tab->scan[index].scancode, new_keycode); |
241 | rc_tab->scan[index].keycode = new_keycode; | 230 | rc_tab->scan[index].keycode = new_keycode; |
242 | __set_bit(new_keycode, dev->keybit); | 231 | __set_bit(new_keycode, dev->input_dev->keybit); |
243 | } | 232 | } |
244 | 233 | ||
245 | if (old_keycode != KEY_RESERVED) { | 234 | if (old_keycode != KEY_RESERVED) { |
246 | /* A previous mapping was updated... */ | 235 | /* A previous mapping was updated... */ |
247 | __clear_bit(old_keycode, dev->keybit); | 236 | __clear_bit(old_keycode, dev->input_dev->keybit); |
248 | /* ... but another scancode might use the same keycode */ | 237 | /* ... but another scancode might use the same keycode */ |
249 | for (i = 0; i < rc_tab->len; i++) { | 238 | for (i = 0; i < rc_tab->len; i++) { |
250 | if (rc_tab->scan[i].keycode == old_keycode) { | 239 | if (rc_tab->scan[i].keycode == old_keycode) { |
251 | __set_bit(old_keycode, dev->keybit); | 240 | __set_bit(old_keycode, dev->input_dev->keybit); |
252 | break; | 241 | break; |
253 | } | 242 | } |
254 | } | 243 | } |
@@ -262,7 +251,7 @@ static unsigned int ir_update_mapping(struct input_dev *dev, | |||
262 | 251 | ||
263 | /** | 252 | /** |
264 | * ir_establish_scancode() - set a keycode in the scancode->keycode table | 253 | * ir_establish_scancode() - set a keycode in the scancode->keycode table |
265 | * @ir_dev: the struct ir_input_dev device descriptor | 254 | * @dev: the struct rc_dev device descriptor |
266 | * @rc_tab: scancode table to be searched | 255 | * @rc_tab: scancode table to be searched |
267 | * @scancode: the desired scancode | 256 | * @scancode: the desired scancode |
268 | * @resize: controls whether we allowed to resize the table to | 257 | * @resize: controls whether we allowed to resize the table to |
@@ -274,7 +263,7 @@ static unsigned int ir_update_mapping(struct input_dev *dev, | |||
274 | * If scancode is not yet present the routine will allocate a new slot | 263 | * If scancode is not yet present the routine will allocate a new slot |
275 | * for it. | 264 | * for it. |
276 | */ | 265 | */ |
277 | static unsigned int ir_establish_scancode(struct ir_input_dev *ir_dev, | 266 | static unsigned int ir_establish_scancode(struct rc_dev *dev, |
278 | struct ir_scancode_table *rc_tab, | 267 | struct ir_scancode_table *rc_tab, |
279 | unsigned int scancode, | 268 | unsigned int scancode, |
280 | bool resize) | 269 | bool resize) |
@@ -286,10 +275,11 @@ static unsigned int ir_establish_scancode(struct ir_input_dev *ir_dev, | |||
286 | * all bits for the complete IR code. In general, they provide only | 275 | * all bits for the complete IR code. In general, they provide only |
287 | * the command part of the IR code. Yet, as it is possible to replace | 276 | * the command part of the IR code. Yet, as it is possible to replace |
288 | * the provided IR with another one, it is needed to allow loading | 277 | * the provided IR with another one, it is needed to allow loading |
289 | * IR tables from other remotes. So, | 278 | * IR tables from other remotes. So, we support specifying a mask to |
279 | * indicate the valid bits of the scancodes. | ||
290 | */ | 280 | */ |
291 | if (ir_dev->props && ir_dev->props->scanmask) | 281 | if (dev->scanmask) |
292 | scancode &= ir_dev->props->scanmask; | 282 | scancode &= dev->scanmask; |
293 | 283 | ||
294 | /* First check if we already have a mapping for this ir command */ | 284 | /* First check if we already have a mapping for this ir command */ |
295 | for (i = 0; i < rc_tab->len; i++) { | 285 | for (i = 0; i < rc_tab->len; i++) { |
@@ -320,19 +310,19 @@ static unsigned int ir_establish_scancode(struct ir_input_dev *ir_dev, | |||
320 | 310 | ||
321 | /** | 311 | /** |
322 | * ir_setkeycode() - set a keycode in the scancode->keycode table | 312 | * ir_setkeycode() - set a keycode in the scancode->keycode table |
323 | * @dev: the struct input_dev device descriptor | 313 | * @idev: the struct input_dev device descriptor |
324 | * @scancode: the desired scancode | 314 | * @scancode: the desired scancode |
325 | * @keycode: result | 315 | * @keycode: result |
326 | * @return: -EINVAL if the keycode could not be inserted, otherwise zero. | 316 | * @return: -EINVAL if the keycode could not be inserted, otherwise zero. |
327 | * | 317 | * |
328 | * This routine is used to handle evdev EVIOCSKEY ioctl. | 318 | * This routine is used to handle evdev EVIOCSKEY ioctl. |
329 | */ | 319 | */ |
330 | static int ir_setkeycode(struct input_dev *dev, | 320 | static int ir_setkeycode(struct input_dev *idev, |
331 | const struct input_keymap_entry *ke, | 321 | const struct input_keymap_entry *ke, |
332 | unsigned int *old_keycode) | 322 | unsigned int *old_keycode) |
333 | { | 323 | { |
334 | struct ir_input_dev *ir_dev = input_get_drvdata(dev); | 324 | struct rc_dev *rdev = input_get_drvdata(idev); |
335 | struct ir_scancode_table *rc_tab = &ir_dev->rc_tab; | 325 | struct ir_scancode_table *rc_tab = &rdev->rc_tab; |
336 | unsigned int index; | 326 | unsigned int index; |
337 | unsigned int scancode; | 327 | unsigned int scancode; |
338 | int retval; | 328 | int retval; |
@@ -351,14 +341,14 @@ static int ir_setkeycode(struct input_dev *dev, | |||
351 | if (retval) | 341 | if (retval) |
352 | goto out; | 342 | goto out; |
353 | 343 | ||
354 | index = ir_establish_scancode(ir_dev, rc_tab, scancode, true); | 344 | index = ir_establish_scancode(rdev, rc_tab, scancode, true); |
355 | if (index >= rc_tab->len) { | 345 | if (index >= rc_tab->len) { |
356 | retval = -ENOMEM; | 346 | retval = -ENOMEM; |
357 | goto out; | 347 | goto out; |
358 | } | 348 | } |
359 | } | 349 | } |
360 | 350 | ||
361 | *old_keycode = ir_update_mapping(dev, rc_tab, index, ke->keycode); | 351 | *old_keycode = ir_update_mapping(rdev, rc_tab, index, ke->keycode); |
362 | 352 | ||
363 | out: | 353 | out: |
364 | spin_unlock_irqrestore(&rc_tab->lock, flags); | 354 | spin_unlock_irqrestore(&rc_tab->lock, flags); |
@@ -367,22 +357,22 @@ out: | |||
367 | 357 | ||
368 | /** | 358 | /** |
369 | * ir_setkeytable() - sets several entries in the scancode->keycode table | 359 | * ir_setkeytable() - sets several entries in the scancode->keycode table |
370 | * @dev: the struct input_dev device descriptor | 360 | * @dev: the struct rc_dev device descriptor |
371 | * @to: the struct ir_scancode_table to copy entries to | 361 | * @to: the struct ir_scancode_table to copy entries to |
372 | * @from: the struct ir_scancode_table to copy entries from | 362 | * @from: the struct ir_scancode_table to copy entries from |
373 | * @return: -ENOMEM if all keycodes could not be inserted, otherwise zero. | 363 | * @return: -ENOMEM if all keycodes could not be inserted, otherwise zero. |
374 | * | 364 | * |
375 | * This routine is used to handle table initialization. | 365 | * This routine is used to handle table initialization. |
376 | */ | 366 | */ |
377 | static int ir_setkeytable(struct ir_input_dev *ir_dev, | 367 | static int ir_setkeytable(struct rc_dev *dev, |
378 | const struct ir_scancode_table *from) | 368 | const struct ir_scancode_table *from) |
379 | { | 369 | { |
380 | struct ir_scancode_table *rc_tab = &ir_dev->rc_tab; | 370 | struct ir_scancode_table *rc_tab = &dev->rc_tab; |
381 | unsigned int i, index; | 371 | unsigned int i, index; |
382 | int rc; | 372 | int rc; |
383 | 373 | ||
384 | rc = ir_create_table(&ir_dev->rc_tab, | 374 | rc = ir_create_table(rc_tab, from->name, |
385 | from->name, from->ir_type, from->size); | 375 | from->ir_type, from->size); |
386 | if (rc) | 376 | if (rc) |
387 | return rc; | 377 | return rc; |
388 | 378 | ||
@@ -390,14 +380,14 @@ static int ir_setkeytable(struct ir_input_dev *ir_dev, | |||
390 | rc_tab->size, rc_tab->alloc); | 380 | rc_tab->size, rc_tab->alloc); |
391 | 381 | ||
392 | for (i = 0; i < from->size; i++) { | 382 | for (i = 0; i < from->size; i++) { |
393 | index = ir_establish_scancode(ir_dev, rc_tab, | 383 | index = ir_establish_scancode(dev, rc_tab, |
394 | from->scan[i].scancode, false); | 384 | from->scan[i].scancode, false); |
395 | if (index >= rc_tab->len) { | 385 | if (index >= rc_tab->len) { |
396 | rc = -ENOMEM; | 386 | rc = -ENOMEM; |
397 | break; | 387 | break; |
398 | } | 388 | } |
399 | 389 | ||
400 | ir_update_mapping(ir_dev->input_dev, rc_tab, index, | 390 | ir_update_mapping(dev, rc_tab, index, |
401 | from->scan[i].keycode); | 391 | from->scan[i].keycode); |
402 | } | 392 | } |
403 | 393 | ||
@@ -409,7 +399,7 @@ static int ir_setkeytable(struct ir_input_dev *ir_dev, | |||
409 | 399 | ||
410 | /** | 400 | /** |
411 | * ir_lookup_by_scancode() - locate mapping by scancode | 401 | * ir_lookup_by_scancode() - locate mapping by scancode |
412 | * @rc_tab: the &struct ir_scancode_table to search | 402 | * @rc_tab: the struct ir_scancode_table to search |
413 | * @scancode: scancode to look for in the table | 403 | * @scancode: scancode to look for in the table |
414 | * @return: index in the table, -1U if not found | 404 | * @return: index in the table, -1U if not found |
415 | * | 405 | * |
@@ -438,18 +428,18 @@ static unsigned int ir_lookup_by_scancode(const struct ir_scancode_table *rc_tab | |||
438 | 428 | ||
439 | /** | 429 | /** |
440 | * ir_getkeycode() - get a keycode from the scancode->keycode table | 430 | * ir_getkeycode() - get a keycode from the scancode->keycode table |
441 | * @dev: the struct input_dev device descriptor | 431 | * @idev: the struct input_dev device descriptor |
442 | * @scancode: the desired scancode | 432 | * @scancode: the desired scancode |
443 | * @keycode: used to return the keycode, if found, or KEY_RESERVED | 433 | * @keycode: used to return the keycode, if found, or KEY_RESERVED |
444 | * @return: always returns zero. | 434 | * @return: always returns zero. |
445 | * | 435 | * |
446 | * This routine is used to handle evdev EVIOCGKEY ioctl. | 436 | * This routine is used to handle evdev EVIOCGKEY ioctl. |
447 | */ | 437 | */ |
448 | static int ir_getkeycode(struct input_dev *dev, | 438 | static int ir_getkeycode(struct input_dev *idev, |
449 | struct input_keymap_entry *ke) | 439 | struct input_keymap_entry *ke) |
450 | { | 440 | { |
451 | struct ir_input_dev *ir_dev = input_get_drvdata(dev); | 441 | struct rc_dev *rdev = input_get_drvdata(idev); |
452 | struct ir_scancode_table *rc_tab = &ir_dev->rc_tab; | 442 | struct ir_scancode_table *rc_tab = &rdev->rc_tab; |
453 | struct ir_scancode *entry; | 443 | struct ir_scancode *entry; |
454 | unsigned long flags; | 444 | unsigned long flags; |
455 | unsigned int index; | 445 | unsigned int index; |
@@ -492,18 +482,17 @@ out: | |||
492 | 482 | ||
493 | /** | 483 | /** |
494 | * ir_g_keycode_from_table() - gets the keycode that corresponds to a scancode | 484 | * ir_g_keycode_from_table() - gets the keycode that corresponds to a scancode |
495 | * @input_dev: the struct input_dev descriptor of the device | 485 | * @dev: the struct rc_dev descriptor of the device |
496 | * @scancode: the scancode that we're seeking | 486 | * @scancode: the scancode to look for |
487 | * @return: the corresponding keycode, or KEY_RESERVED | ||
497 | * | 488 | * |
498 | * This routine is used by the input routines when a key is pressed at the | 489 | * This routine is used by drivers which need to convert a scancode to a |
499 | * IR. The scancode is received and needs to be converted into a keycode. | 490 | * keycode. Normally it should not be used since drivers should have no |
500 | * If the key is not found, it returns KEY_RESERVED. Otherwise, returns the | 491 | * interest in keycodes. |
501 | * corresponding keycode from the table. | ||
502 | */ | 492 | */ |
503 | u32 ir_g_keycode_from_table(struct input_dev *dev, u32 scancode) | 493 | u32 ir_g_keycode_from_table(struct rc_dev *dev, u32 scancode) |
504 | { | 494 | { |
505 | struct ir_input_dev *ir_dev = input_get_drvdata(dev); | 495 | struct ir_scancode_table *rc_tab = &dev->rc_tab; |
506 | struct ir_scancode_table *rc_tab = &ir_dev->rc_tab; | ||
507 | unsigned int keycode; | 496 | unsigned int keycode; |
508 | unsigned int index; | 497 | unsigned int index; |
509 | unsigned long flags; | 498 | unsigned long flags; |
@@ -518,7 +507,7 @@ u32 ir_g_keycode_from_table(struct input_dev *dev, u32 scancode) | |||
518 | 507 | ||
519 | if (keycode != KEY_RESERVED) | 508 | if (keycode != KEY_RESERVED) |
520 | IR_dprintk(1, "%s: scancode 0x%04x keycode 0x%02x\n", | 509 | IR_dprintk(1, "%s: scancode 0x%04x keycode 0x%02x\n", |
521 | dev->name, scancode, keycode); | 510 | dev->input_name, scancode, keycode); |
522 | 511 | ||
523 | return keycode; | 512 | return keycode; |
524 | } | 513 | } |
@@ -526,50 +515,49 @@ EXPORT_SYMBOL_GPL(ir_g_keycode_from_table); | |||
526 | 515 | ||
527 | /** | 516 | /** |
528 | * ir_do_keyup() - internal function to signal the release of a keypress | 517 | * ir_do_keyup() - internal function to signal the release of a keypress |
529 | * @ir: the struct ir_input_dev descriptor of the device | 518 | * @dev: the struct rc_dev descriptor of the device |
530 | * | 519 | * |
531 | * This function is used internally to release a keypress, it must be | 520 | * This function is used internally to release a keypress, it must be |
532 | * called with keylock held. | 521 | * called with keylock held. |
533 | */ | 522 | */ |
534 | static void ir_do_keyup(struct ir_input_dev *ir) | 523 | static void ir_do_keyup(struct rc_dev *dev) |
535 | { | 524 | { |
536 | if (!ir->keypressed) | 525 | if (!dev->keypressed) |
537 | return; | 526 | return; |
538 | 527 | ||
539 | IR_dprintk(1, "keyup key 0x%04x\n", ir->last_keycode); | 528 | IR_dprintk(1, "keyup key 0x%04x\n", dev->last_keycode); |
540 | input_report_key(ir->input_dev, ir->last_keycode, 0); | 529 | input_report_key(dev->input_dev, dev->last_keycode, 0); |
541 | input_sync(ir->input_dev); | 530 | input_sync(dev->input_dev); |
542 | ir->keypressed = false; | 531 | dev->keypressed = false; |
543 | } | 532 | } |
544 | 533 | ||
545 | /** | 534 | /** |
546 | * ir_keyup() - generates input event to signal the release of a keypress | 535 | * ir_keyup() - signals the release of a keypress |
547 | * @dev: the struct input_dev descriptor of the device | 536 | * @dev: the struct rc_dev descriptor of the device |
548 | * | 537 | * |
549 | * This routine is used to signal that a key has been released on the | 538 | * This routine is used to signal that a key has been released on the |
550 | * remote control. | 539 | * remote control. |
551 | */ | 540 | */ |
552 | void ir_keyup(struct input_dev *dev) | 541 | void ir_keyup(struct rc_dev *dev) |
553 | { | 542 | { |
554 | unsigned long flags; | 543 | unsigned long flags; |
555 | struct ir_input_dev *ir = input_get_drvdata(dev); | ||
556 | 544 | ||
557 | spin_lock_irqsave(&ir->keylock, flags); | 545 | spin_lock_irqsave(&dev->keylock, flags); |
558 | ir_do_keyup(ir); | 546 | ir_do_keyup(dev); |
559 | spin_unlock_irqrestore(&ir->keylock, flags); | 547 | spin_unlock_irqrestore(&dev->keylock, flags); |
560 | } | 548 | } |
561 | EXPORT_SYMBOL_GPL(ir_keyup); | 549 | EXPORT_SYMBOL_GPL(ir_keyup); |
562 | 550 | ||
563 | /** | 551 | /** |
564 | * ir_timer_keyup() - generates a keyup event after a timeout | 552 | * ir_timer_keyup() - generates a keyup event after a timeout |
565 | * @cookie: a pointer to struct ir_input_dev passed to setup_timer() | 553 | * @cookie: a pointer to the struct rc_dev for the device |
566 | * | 554 | * |
567 | * This routine will generate a keyup event some time after a keydown event | 555 | * This routine will generate a keyup event some time after a keydown event |
568 | * is generated when no further activity has been detected. | 556 | * is generated when no further activity has been detected. |
569 | */ | 557 | */ |
570 | static void ir_timer_keyup(unsigned long cookie) | 558 | static void ir_timer_keyup(unsigned long cookie) |
571 | { | 559 | { |
572 | struct ir_input_dev *ir = (struct ir_input_dev *)cookie; | 560 | struct rc_dev *dev = (struct rc_dev *)cookie; |
573 | unsigned long flags; | 561 | unsigned long flags; |
574 | 562 | ||
575 | /* | 563 | /* |
@@ -582,43 +570,42 @@ static void ir_timer_keyup(unsigned long cookie) | |||
582 | * to allow the input subsystem to do its auto-repeat magic or | 570 | * to allow the input subsystem to do its auto-repeat magic or |
583 | * a keyup event might follow immediately after the keydown. | 571 | * a keyup event might follow immediately after the keydown. |
584 | */ | 572 | */ |
585 | spin_lock_irqsave(&ir->keylock, flags); | 573 | spin_lock_irqsave(&dev->keylock, flags); |
586 | if (time_is_before_eq_jiffies(ir->keyup_jiffies)) | 574 | if (time_is_before_eq_jiffies(dev->keyup_jiffies)) |
587 | ir_do_keyup(ir); | 575 | ir_do_keyup(dev); |
588 | spin_unlock_irqrestore(&ir->keylock, flags); | 576 | spin_unlock_irqrestore(&dev->keylock, flags); |
589 | } | 577 | } |
590 | 578 | ||
591 | /** | 579 | /** |
592 | * ir_repeat() - notifies the IR core that a key is still pressed | 580 | * ir_repeat() - signals that a key is still pressed |
593 | * @dev: the struct input_dev descriptor of the device | 581 | * @dev: the struct rc_dev descriptor of the device |
594 | * | 582 | * |
595 | * This routine is used by IR decoders when a repeat message which does | 583 | * This routine is used by IR decoders when a repeat message which does |
596 | * not include the necessary bits to reproduce the scancode has been | 584 | * not include the necessary bits to reproduce the scancode has been |
597 | * received. | 585 | * received. |
598 | */ | 586 | */ |
599 | void ir_repeat(struct input_dev *dev) | 587 | void ir_repeat(struct rc_dev *dev) |
600 | { | 588 | { |
601 | unsigned long flags; | 589 | unsigned long flags; |
602 | struct ir_input_dev *ir = input_get_drvdata(dev); | ||
603 | 590 | ||
604 | spin_lock_irqsave(&ir->keylock, flags); | 591 | spin_lock_irqsave(&dev->keylock, flags); |
605 | 592 | ||
606 | input_event(dev, EV_MSC, MSC_SCAN, ir->last_scancode); | 593 | input_event(dev->input_dev, EV_MSC, MSC_SCAN, dev->last_scancode); |
607 | 594 | ||
608 | if (!ir->keypressed) | 595 | if (!dev->keypressed) |
609 | goto out; | 596 | goto out; |
610 | 597 | ||
611 | ir->keyup_jiffies = jiffies + msecs_to_jiffies(IR_KEYPRESS_TIMEOUT); | 598 | dev->keyup_jiffies = jiffies + msecs_to_jiffies(IR_KEYPRESS_TIMEOUT); |
612 | mod_timer(&ir->timer_keyup, ir->keyup_jiffies); | 599 | mod_timer(&dev->timer_keyup, dev->keyup_jiffies); |
613 | 600 | ||
614 | out: | 601 | out: |
615 | spin_unlock_irqrestore(&ir->keylock, flags); | 602 | spin_unlock_irqrestore(&dev->keylock, flags); |
616 | } | 603 | } |
617 | EXPORT_SYMBOL_GPL(ir_repeat); | 604 | EXPORT_SYMBOL_GPL(ir_repeat); |
618 | 605 | ||
619 | /** | 606 | /** |
620 | * ir_do_keydown() - internal function to process a keypress | 607 | * ir_do_keydown() - internal function to process a keypress |
621 | * @dev: the struct input_dev descriptor of the device | 608 | * @dev: the struct rc_dev descriptor of the device |
622 | * @scancode: the scancode of the keypress | 609 | * @scancode: the scancode of the keypress |
623 | * @keycode: the keycode of the keypress | 610 | * @keycode: the keycode of the keypress |
624 | * @toggle: the toggle value of the keypress | 611 | * @toggle: the toggle value of the keypress |
@@ -626,231 +613,96 @@ EXPORT_SYMBOL_GPL(ir_repeat); | |||
626 | * This function is used internally to register a keypress, it must be | 613 | * This function is used internally to register a keypress, it must be |
627 | * called with keylock held. | 614 | * called with keylock held. |
628 | */ | 615 | */ |
629 | static void ir_do_keydown(struct input_dev *dev, int scancode, | 616 | static void ir_do_keydown(struct rc_dev *dev, int scancode, |
630 | u32 keycode, u8 toggle) | 617 | u32 keycode, u8 toggle) |
631 | { | 618 | { |
632 | struct ir_input_dev *ir = input_get_drvdata(dev); | 619 | input_event(dev->input_dev, EV_MSC, MSC_SCAN, scancode); |
633 | |||
634 | input_event(dev, EV_MSC, MSC_SCAN, scancode); | ||
635 | 620 | ||
636 | /* Repeat event? */ | 621 | /* Repeat event? */ |
637 | if (ir->keypressed && | 622 | if (dev->keypressed && |
638 | ir->last_scancode == scancode && | 623 | dev->last_scancode == scancode && |
639 | ir->last_toggle == toggle) | 624 | dev->last_toggle == toggle) |
640 | return; | 625 | return; |
641 | 626 | ||
642 | /* Release old keypress */ | 627 | /* Release old keypress */ |
643 | ir_do_keyup(ir); | 628 | ir_do_keyup(dev); |
644 | 629 | ||
645 | ir->last_scancode = scancode; | 630 | dev->last_scancode = scancode; |
646 | ir->last_toggle = toggle; | 631 | dev->last_toggle = toggle; |
647 | ir->last_keycode = keycode; | 632 | dev->last_keycode = keycode; |
648 | 633 | ||
649 | if (keycode == KEY_RESERVED) | 634 | if (keycode == KEY_RESERVED) |
650 | return; | 635 | return; |
651 | 636 | ||
652 | /* Register a keypress */ | 637 | /* Register a keypress */ |
653 | ir->keypressed = true; | 638 | dev->keypressed = true; |
654 | IR_dprintk(1, "%s: key down event, key 0x%04x, scancode 0x%04x\n", | 639 | IR_dprintk(1, "%s: key down event, key 0x%04x, scancode 0x%04x\n", |
655 | dev->name, keycode, scancode); | 640 | dev->input_name, keycode, scancode); |
656 | input_report_key(dev, ir->last_keycode, 1); | 641 | input_report_key(dev->input_dev, dev->last_keycode, 1); |
657 | input_sync(dev); | 642 | input_sync(dev->input_dev); |
658 | } | 643 | } |
659 | 644 | ||
660 | /** | 645 | /** |
661 | * ir_keydown() - generates input event for a key press | 646 | * ir_keydown() - generates input event for a key press |
662 | * @dev: the struct input_dev descriptor of the device | 647 | * @dev: the struct rc_dev descriptor of the device |
663 | * @scancode: the scancode that we're seeking | 648 | * @scancode: the scancode that we're seeking |
664 | * @toggle: the toggle value (protocol dependent, if the protocol doesn't | 649 | * @toggle: the toggle value (protocol dependent, if the protocol doesn't |
665 | * support toggle values, this should be set to zero) | 650 | * support toggle values, this should be set to zero) |
666 | * | 651 | * |
667 | * This routine is used by the input routines when a key is pressed at the | 652 | * This routine is used to signal that a key has been pressed on the |
668 | * IR. It gets the keycode for a scancode and reports an input event via | 653 | * remote control. |
669 | * input_report_key(). | ||
670 | */ | 654 | */ |
671 | void ir_keydown(struct input_dev *dev, int scancode, u8 toggle) | 655 | void ir_keydown(struct rc_dev *dev, int scancode, u8 toggle) |
672 | { | 656 | { |
673 | unsigned long flags; | 657 | unsigned long flags; |
674 | struct ir_input_dev *ir = input_get_drvdata(dev); | ||
675 | u32 keycode = ir_g_keycode_from_table(dev, scancode); | 658 | u32 keycode = ir_g_keycode_from_table(dev, scancode); |
676 | 659 | ||
677 | spin_lock_irqsave(&ir->keylock, flags); | 660 | spin_lock_irqsave(&dev->keylock, flags); |
678 | ir_do_keydown(dev, scancode, keycode, toggle); | 661 | ir_do_keydown(dev, scancode, keycode, toggle); |
679 | 662 | ||
680 | if (ir->keypressed) { | 663 | if (dev->keypressed) { |
681 | ir->keyup_jiffies = jiffies + msecs_to_jiffies(IR_KEYPRESS_TIMEOUT); | 664 | dev->keyup_jiffies = jiffies + msecs_to_jiffies(IR_KEYPRESS_TIMEOUT); |
682 | mod_timer(&ir->timer_keyup, ir->keyup_jiffies); | 665 | mod_timer(&dev->timer_keyup, dev->keyup_jiffies); |
683 | } | 666 | } |
684 | spin_unlock_irqrestore(&ir->keylock, flags); | 667 | spin_unlock_irqrestore(&dev->keylock, flags); |
685 | } | 668 | } |
686 | EXPORT_SYMBOL_GPL(ir_keydown); | 669 | EXPORT_SYMBOL_GPL(ir_keydown); |
687 | 670 | ||
688 | /** | 671 | /** |
689 | * ir_keydown_notimeout() - generates input event for a key press without | 672 | * ir_keydown_notimeout() - generates input event for a key press without |
690 | * an automatic keyup event at a later time | 673 | * an automatic keyup event at a later time |
691 | * @dev: the struct input_dev descriptor of the device | 674 | * @dev: the struct rc_dev descriptor of the device |
692 | * @scancode: the scancode that we're seeking | 675 | * @scancode: the scancode that we're seeking |
693 | * @toggle: the toggle value (protocol dependent, if the protocol doesn't | 676 | * @toggle: the toggle value (protocol dependent, if the protocol doesn't |
694 | * support toggle values, this should be set to zero) | 677 | * support toggle values, this should be set to zero) |
695 | * | 678 | * |
696 | * This routine is used by the input routines when a key is pressed at the | 679 | * This routine is used to signal that a key has been pressed on the |
697 | * IR. It gets the keycode for a scancode and reports an input event via | 680 | * remote control. The driver must manually call ir_keyup() at a later stage. |
698 | * input_report_key(). The driver must manually call ir_keyup() at a later | ||
699 | * stage. | ||
700 | */ | 681 | */ |
701 | void ir_keydown_notimeout(struct input_dev *dev, int scancode, u8 toggle) | 682 | void ir_keydown_notimeout(struct rc_dev *dev, int scancode, u8 toggle) |
702 | { | 683 | { |
703 | unsigned long flags; | 684 | unsigned long flags; |
704 | struct ir_input_dev *ir = input_get_drvdata(dev); | ||
705 | u32 keycode = ir_g_keycode_from_table(dev, scancode); | 685 | u32 keycode = ir_g_keycode_from_table(dev, scancode); |
706 | 686 | ||
707 | spin_lock_irqsave(&ir->keylock, flags); | 687 | spin_lock_irqsave(&dev->keylock, flags); |
708 | ir_do_keydown(dev, scancode, keycode, toggle); | 688 | ir_do_keydown(dev, scancode, keycode, toggle); |
709 | spin_unlock_irqrestore(&ir->keylock, flags); | 689 | spin_unlock_irqrestore(&dev->keylock, flags); |
710 | } | 690 | } |
711 | EXPORT_SYMBOL_GPL(ir_keydown_notimeout); | 691 | EXPORT_SYMBOL_GPL(ir_keydown_notimeout); |
712 | 692 | ||
713 | static int ir_open(struct input_dev *input_dev) | 693 | static int ir_open(struct input_dev *idev) |
714 | { | ||
715 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); | ||
716 | |||
717 | return ir_dev->props->open(ir_dev->props->priv); | ||
718 | } | ||
719 | |||
720 | static void ir_close(struct input_dev *input_dev) | ||
721 | { | ||
722 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); | ||
723 | |||
724 | ir_dev->props->close(ir_dev->props->priv); | ||
725 | } | ||
726 | |||
727 | /** | ||
728 | * __ir_input_register() - sets the IR keycode table and add the handlers | ||
729 | * for keymap table get/set | ||
730 | * @input_dev: the struct input_dev descriptor of the device | ||
731 | * @rc_tab: the struct ir_scancode_table table of scancode/keymap | ||
732 | * | ||
733 | * This routine is used to initialize the input infrastructure | ||
734 | * to work with an IR. | ||
735 | * It will register the input/evdev interface for the device and | ||
736 | * register the syfs code for IR class | ||
737 | */ | ||
738 | int __ir_input_register(struct input_dev *input_dev, | ||
739 | const struct ir_scancode_table *rc_tab, | ||
740 | struct ir_dev_props *props, | ||
741 | const char *driver_name) | ||
742 | { | 694 | { |
743 | struct ir_input_dev *ir_dev; | 695 | struct rc_dev *rdev = input_get_drvdata(idev); |
744 | int rc; | ||
745 | |||
746 | if (rc_tab->scan == NULL || !rc_tab->size) | ||
747 | return -EINVAL; | ||
748 | |||
749 | ir_dev = kzalloc(sizeof(*ir_dev), GFP_KERNEL); | ||
750 | if (!ir_dev) | ||
751 | return -ENOMEM; | ||
752 | |||
753 | ir_dev->driver_name = kasprintf(GFP_KERNEL, "%s", driver_name); | ||
754 | if (!ir_dev->driver_name) { | ||
755 | rc = -ENOMEM; | ||
756 | goto out_dev; | ||
757 | } | ||
758 | |||
759 | input_dev->getkeycode_new = ir_getkeycode; | ||
760 | input_dev->setkeycode_new = ir_setkeycode; | ||
761 | input_set_drvdata(input_dev, ir_dev); | ||
762 | ir_dev->input_dev = input_dev; | ||
763 | |||
764 | spin_lock_init(&ir_dev->rc_tab.lock); | ||
765 | spin_lock_init(&ir_dev->keylock); | ||
766 | setup_timer(&ir_dev->timer_keyup, ir_timer_keyup, (unsigned long)ir_dev); | ||
767 | |||
768 | if (props) { | ||
769 | ir_dev->props = props; | ||
770 | if (props->open) | ||
771 | input_dev->open = ir_open; | ||
772 | if (props->close) | ||
773 | input_dev->close = ir_close; | ||
774 | } | ||
775 | |||
776 | set_bit(EV_KEY, input_dev->evbit); | ||
777 | set_bit(EV_REP, input_dev->evbit); | ||
778 | set_bit(EV_MSC, input_dev->evbit); | ||
779 | set_bit(MSC_SCAN, input_dev->mscbit); | ||
780 | |||
781 | rc = ir_setkeytable(ir_dev, rc_tab); | ||
782 | if (rc) | ||
783 | goto out_name; | ||
784 | 696 | ||
785 | rc = ir_register_class(input_dev); | 697 | return rdev->open(rdev); |
786 | if (rc < 0) | ||
787 | goto out_table; | ||
788 | |||
789 | if (ir_dev->props) | ||
790 | if (ir_dev->props->driver_type == RC_DRIVER_IR_RAW) { | ||
791 | rc = ir_raw_event_register(input_dev); | ||
792 | if (rc < 0) | ||
793 | goto out_event; | ||
794 | } | ||
795 | |||
796 | rc = ir_register_input(input_dev); | ||
797 | if (rc < 0) | ||
798 | goto out_event; | ||
799 | |||
800 | IR_dprintk(1, "Registered input device on %s for %s remote%s.\n", | ||
801 | driver_name, rc_tab->name, | ||
802 | (ir_dev->props && ir_dev->props->driver_type == RC_DRIVER_IR_RAW) ? | ||
803 | " in raw mode" : ""); | ||
804 | |||
805 | /* | ||
806 | * Default delay of 250ms is too short for some protocols, expecially | ||
807 | * since the timeout is currently set to 250ms. Increase it to 500ms, | ||
808 | * to avoid wrong repetition of the keycodes. | ||
809 | */ | ||
810 | input_dev->rep[REP_DELAY] = 500; | ||
811 | |||
812 | return 0; | ||
813 | |||
814 | out_event: | ||
815 | ir_unregister_class(input_dev); | ||
816 | out_table: | ||
817 | ir_free_table(&ir_dev->rc_tab); | ||
818 | out_name: | ||
819 | kfree(ir_dev->driver_name); | ||
820 | out_dev: | ||
821 | kfree(ir_dev); | ||
822 | return rc; | ||
823 | } | 698 | } |
824 | EXPORT_SYMBOL_GPL(__ir_input_register); | ||
825 | |||
826 | /** | ||
827 | * ir_input_unregister() - unregisters IR and frees resources | ||
828 | * @input_dev: the struct input_dev descriptor of the device | ||
829 | 699 | ||
830 | * This routine is used to free memory and de-register interfaces. | 700 | static void ir_close(struct input_dev *idev) |
831 | */ | ||
832 | void ir_input_unregister(struct input_dev *input_dev) | ||
833 | { | 701 | { |
834 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); | 702 | struct rc_dev *rdev = input_get_drvdata(idev); |
835 | |||
836 | if (!ir_dev) | ||
837 | return; | ||
838 | |||
839 | IR_dprintk(1, "Freed keycode table\n"); | ||
840 | 703 | ||
841 | del_timer_sync(&ir_dev->timer_keyup); | 704 | rdev->close(rdev); |
842 | if (ir_dev->props) | ||
843 | if (ir_dev->props->driver_type == RC_DRIVER_IR_RAW) | ||
844 | ir_raw_event_unregister(input_dev); | ||
845 | |||
846 | ir_free_table(&ir_dev->rc_tab); | ||
847 | |||
848 | ir_unregister_class(input_dev); | ||
849 | |||
850 | kfree(ir_dev->driver_name); | ||
851 | kfree(ir_dev); | ||
852 | } | 705 | } |
853 | EXPORT_SYMBOL_GPL(ir_input_unregister); | ||
854 | 706 | ||
855 | /* class for /sys/class/rc */ | 707 | /* class for /sys/class/rc */ |
856 | static char *ir_devnode(struct device *dev, mode_t *mode) | 708 | static char *ir_devnode(struct device *dev, mode_t *mode) |
@@ -881,7 +733,7 @@ static struct { | |||
881 | 733 | ||
882 | /** | 734 | /** |
883 | * show_protocols() - shows the current IR protocol(s) | 735 | * show_protocols() - shows the current IR protocol(s) |
884 | * @d: the device descriptor | 736 | * @device: the device descriptor |
885 | * @mattr: the device attribute struct (unused) | 737 | * @mattr: the device attribute struct (unused) |
886 | * @buf: a pointer to the output buffer | 738 | * @buf: a pointer to the output buffer |
887 | * | 739 | * |
@@ -890,26 +742,25 @@ static struct { | |||
890 | * It returns the protocol names of supported protocols. | 742 | * It returns the protocol names of supported protocols. |
891 | * Enabled protocols are printed in brackets. | 743 | * Enabled protocols are printed in brackets. |
892 | */ | 744 | */ |
893 | static ssize_t show_protocols(struct device *d, | 745 | static ssize_t show_protocols(struct device *device, |
894 | struct device_attribute *mattr, char *buf) | 746 | struct device_attribute *mattr, char *buf) |
895 | { | 747 | { |
896 | struct ir_input_dev *ir_dev = dev_get_drvdata(d); | 748 | struct rc_dev *dev = to_rc_dev(device); |
897 | u64 allowed, enabled; | 749 | u64 allowed, enabled; |
898 | char *tmp = buf; | 750 | char *tmp = buf; |
899 | int i; | 751 | int i; |
900 | 752 | ||
901 | /* Device is being removed */ | 753 | /* Device is being removed */ |
902 | if (!ir_dev) | 754 | if (!dev) |
903 | return -EINVAL; | 755 | return -EINVAL; |
904 | 756 | ||
905 | if (ir_dev->props && ir_dev->props->driver_type == RC_DRIVER_SCANCODE) { | 757 | if (dev->driver_type == RC_DRIVER_SCANCODE) { |
906 | enabled = ir_dev->rc_tab.ir_type; | 758 | enabled = dev->rc_tab.ir_type; |
907 | allowed = ir_dev->props->allowed_protos; | 759 | allowed = dev->allowed_protos; |
908 | } else if (ir_dev->raw) { | 760 | } else { |
909 | enabled = ir_dev->raw->enabled_protocols; | 761 | enabled = dev->raw->enabled_protocols; |
910 | allowed = ir_raw_get_allowed_protocols(); | 762 | allowed = ir_raw_get_allowed_protocols(); |
911 | } else | 763 | } |
912 | return sprintf(tmp, "[builtin]\n"); | ||
913 | 764 | ||
914 | IR_dprintk(1, "allowed - 0x%llx, enabled - 0x%llx\n", | 765 | IR_dprintk(1, "allowed - 0x%llx, enabled - 0x%llx\n", |
915 | (long long)allowed, | 766 | (long long)allowed, |
@@ -930,12 +781,12 @@ static ssize_t show_protocols(struct device *d, | |||
930 | 781 | ||
931 | /** | 782 | /** |
932 | * store_protocols() - changes the current IR protocol(s) | 783 | * store_protocols() - changes the current IR protocol(s) |
933 | * @d: the device descriptor | 784 | * @device: the device descriptor |
934 | * @mattr: the device attribute struct (unused) | 785 | * @mattr: the device attribute struct (unused) |
935 | * @buf: a pointer to the input buffer | 786 | * @buf: a pointer to the input buffer |
936 | * @len: length of the input buffer | 787 | * @len: length of the input buffer |
937 | * | 788 | * |
938 | * This routine is a callback routine for changing the IR protocol type. | 789 | * This routine is for changing the IR protocol type. |
939 | * It is trigged by writing to /sys/class/rc/rc?/protocols. | 790 | * It is trigged by writing to /sys/class/rc/rc?/protocols. |
940 | * Writing "+proto" will add a protocol to the list of enabled protocols. | 791 | * Writing "+proto" will add a protocol to the list of enabled protocols. |
941 | * Writing "-proto" will remove a protocol from the list of enabled protocols. | 792 | * Writing "-proto" will remove a protocol from the list of enabled protocols. |
@@ -944,12 +795,12 @@ static ssize_t show_protocols(struct device *d, | |||
944 | * Returns -EINVAL if an invalid protocol combination or unknown protocol name | 795 | * Returns -EINVAL if an invalid protocol combination or unknown protocol name |
945 | * is used, otherwise @len. | 796 | * is used, otherwise @len. |
946 | */ | 797 | */ |
947 | static ssize_t store_protocols(struct device *d, | 798 | static ssize_t store_protocols(struct device *device, |
948 | struct device_attribute *mattr, | 799 | struct device_attribute *mattr, |
949 | const char *data, | 800 | const char *data, |
950 | size_t len) | 801 | size_t len) |
951 | { | 802 | { |
952 | struct ir_input_dev *ir_dev = dev_get_drvdata(d); | 803 | struct rc_dev *dev = to_rc_dev(device); |
953 | bool enable, disable; | 804 | bool enable, disable; |
954 | const char *tmp; | 805 | const char *tmp; |
955 | u64 type; | 806 | u64 type; |
@@ -958,13 +809,13 @@ static ssize_t store_protocols(struct device *d, | |||
958 | unsigned long flags; | 809 | unsigned long flags; |
959 | 810 | ||
960 | /* Device is being removed */ | 811 | /* Device is being removed */ |
961 | if (!ir_dev) | 812 | if (!dev) |
962 | return -EINVAL; | 813 | return -EINVAL; |
963 | 814 | ||
964 | if (ir_dev->props && ir_dev->props->driver_type == RC_DRIVER_SCANCODE) | 815 | if (dev->driver_type == RC_DRIVER_SCANCODE) |
965 | type = ir_dev->rc_tab.ir_type; | 816 | type = dev->rc_tab.ir_type; |
966 | else if (ir_dev->raw) | 817 | else if (dev->raw) |
967 | type = ir_dev->raw->enabled_protocols; | 818 | type = dev->raw->enabled_protocols; |
968 | else { | 819 | else { |
969 | IR_dprintk(1, "Protocol switching not supported\n"); | 820 | IR_dprintk(1, "Protocol switching not supported\n"); |
970 | return -EINVAL; | 821 | return -EINVAL; |
@@ -1019,9 +870,8 @@ static ssize_t store_protocols(struct device *d, | |||
1019 | return -EINVAL; | 870 | return -EINVAL; |
1020 | } | 871 | } |
1021 | 872 | ||
1022 | if (ir_dev->props && ir_dev->props->change_protocol) { | 873 | if (dev->change_protocol) { |
1023 | rc = ir_dev->props->change_protocol(ir_dev->props->priv, | 874 | rc = dev->change_protocol(dev, type); |
1024 | type); | ||
1025 | if (rc < 0) { | 875 | if (rc < 0) { |
1026 | IR_dprintk(1, "Error setting protocols to 0x%llx\n", | 876 | IR_dprintk(1, "Error setting protocols to 0x%llx\n", |
1027 | (long long)type); | 877 | (long long)type); |
@@ -1029,12 +879,12 @@ static ssize_t store_protocols(struct device *d, | |||
1029 | } | 879 | } |
1030 | } | 880 | } |
1031 | 881 | ||
1032 | if (ir_dev->props && ir_dev->props->driver_type == RC_DRIVER_SCANCODE) { | 882 | if (dev->driver_type == RC_DRIVER_SCANCODE) { |
1033 | spin_lock_irqsave(&ir_dev->rc_tab.lock, flags); | 883 | spin_lock_irqsave(&dev->rc_tab.lock, flags); |
1034 | ir_dev->rc_tab.ir_type = type; | 884 | dev->rc_tab.ir_type = type; |
1035 | spin_unlock_irqrestore(&ir_dev->rc_tab.lock, flags); | 885 | spin_unlock_irqrestore(&dev->rc_tab.lock, flags); |
1036 | } else { | 886 | } else { |
1037 | ir_dev->raw->enabled_protocols = type; | 887 | dev->raw->enabled_protocols = type; |
1038 | } | 888 | } |
1039 | 889 | ||
1040 | IR_dprintk(1, "Current protocol(s): 0x%llx\n", | 890 | IR_dprintk(1, "Current protocol(s): 0x%llx\n", |
@@ -1043,6 +893,14 @@ static ssize_t store_protocols(struct device *d, | |||
1043 | return len; | 893 | return len; |
1044 | } | 894 | } |
1045 | 895 | ||
896 | static void rc_dev_release(struct device *device) | ||
897 | { | ||
898 | struct rc_dev *dev = to_rc_dev(device); | ||
899 | |||
900 | kfree(dev); | ||
901 | module_put(THIS_MODULE); | ||
902 | } | ||
903 | |||
1046 | #define ADD_HOTPLUG_VAR(fmt, val...) \ | 904 | #define ADD_HOTPLUG_VAR(fmt, val...) \ |
1047 | do { \ | 905 | do { \ |
1048 | int err = add_uevent_var(env, fmt, val); \ | 906 | int err = add_uevent_var(env, fmt, val); \ |
@@ -1052,12 +910,12 @@ static ssize_t store_protocols(struct device *d, | |||
1052 | 910 | ||
1053 | static int rc_dev_uevent(struct device *device, struct kobj_uevent_env *env) | 911 | static int rc_dev_uevent(struct device *device, struct kobj_uevent_env *env) |
1054 | { | 912 | { |
1055 | struct ir_input_dev *ir_dev = dev_get_drvdata(device); | 913 | struct rc_dev *dev = to_rc_dev(device); |
1056 | 914 | ||
1057 | if (ir_dev->rc_tab.name) | 915 | if (dev->rc_tab.name) |
1058 | ADD_HOTPLUG_VAR("NAME=%s", ir_dev->rc_tab.name); | 916 | ADD_HOTPLUG_VAR("NAME=%s", dev->rc_tab.name); |
1059 | if (ir_dev->driver_name) | 917 | if (dev->driver_name) |
1060 | ADD_HOTPLUG_VAR("DRV_NAME=%s", ir_dev->driver_name); | 918 | ADD_HOTPLUG_VAR("DRV_NAME=%s", dev->driver_name); |
1061 | 919 | ||
1062 | return 0; | 920 | return 0; |
1063 | } | 921 | } |
@@ -1084,84 +942,162 @@ static const struct attribute_group *rc_dev_attr_groups[] = { | |||
1084 | 942 | ||
1085 | static struct device_type rc_dev_type = { | 943 | static struct device_type rc_dev_type = { |
1086 | .groups = rc_dev_attr_groups, | 944 | .groups = rc_dev_attr_groups, |
945 | .release = rc_dev_release, | ||
1087 | .uevent = rc_dev_uevent, | 946 | .uevent = rc_dev_uevent, |
1088 | }; | 947 | }; |
1089 | 948 | ||
1090 | /** | 949 | struct rc_dev *rc_allocate_device(void) |
1091 | * ir_register_class() - creates the sysfs for /sys/class/rc/rc? | ||
1092 | * @input_dev: the struct input_dev descriptor of the device | ||
1093 | * | ||
1094 | * This routine is used to register the syfs code for IR class | ||
1095 | */ | ||
1096 | static int ir_register_class(struct input_dev *input_dev) | ||
1097 | { | 950 | { |
1098 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); | 951 | struct rc_dev *dev; |
1099 | int devno = find_first_zero_bit(&ir_core_dev_number, | ||
1100 | IRRCV_NUM_DEVICES); | ||
1101 | |||
1102 | if (unlikely(devno < 0)) | ||
1103 | return devno; | ||
1104 | |||
1105 | ir_dev->dev.type = &rc_dev_type; | ||
1106 | ir_dev->devno = devno; | ||
1107 | |||
1108 | ir_dev->dev.class = &ir_input_class; | ||
1109 | ir_dev->dev.parent = input_dev->dev.parent; | ||
1110 | input_dev->dev.parent = &ir_dev->dev; | ||
1111 | dev_set_name(&ir_dev->dev, "rc%d", devno); | ||
1112 | dev_set_drvdata(&ir_dev->dev, ir_dev); | ||
1113 | return device_register(&ir_dev->dev); | ||
1114 | }; | ||
1115 | 952 | ||
1116 | /** | 953 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
1117 | * ir_register_input - registers ir input device with input subsystem | 954 | if (!dev) |
1118 | * @input_dev: the struct input_dev descriptor of the device | 955 | return NULL; |
1119 | */ | 956 | |
957 | dev->input_dev = input_allocate_device(); | ||
958 | if (!dev->input_dev) { | ||
959 | kfree(dev); | ||
960 | return NULL; | ||
961 | } | ||
962 | |||
963 | dev->input_dev->getkeycode_new = ir_getkeycode; | ||
964 | dev->input_dev->setkeycode_new = ir_setkeycode; | ||
965 | input_set_drvdata(dev->input_dev, dev); | ||
966 | |||
967 | spin_lock_init(&dev->rc_tab.lock); | ||
968 | spin_lock_init(&dev->keylock); | ||
969 | setup_timer(&dev->timer_keyup, ir_timer_keyup, (unsigned long)dev); | ||
1120 | 970 | ||
1121 | static int ir_register_input(struct input_dev *input_dev) | 971 | dev->dev.type = &rc_dev_type; |
972 | dev->dev.class = &ir_input_class; | ||
973 | device_initialize(&dev->dev); | ||
974 | |||
975 | __module_get(THIS_MODULE); | ||
976 | return dev; | ||
977 | } | ||
978 | EXPORT_SYMBOL_GPL(rc_allocate_device); | ||
979 | |||
980 | void rc_free_device(struct rc_dev *dev) | ||
1122 | { | 981 | { |
1123 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); | 982 | if (dev) { |
1124 | int rc; | 983 | input_free_device(dev->input_dev); |
984 | put_device(&dev->dev); | ||
985 | } | ||
986 | } | ||
987 | EXPORT_SYMBOL_GPL(rc_free_device); | ||
988 | |||
989 | int rc_register_device(struct rc_dev *dev) | ||
990 | { | ||
991 | static atomic_t devno = ATOMIC_INIT(0); | ||
992 | struct ir_scancode_table *rc_tab; | ||
1125 | const char *path; | 993 | const char *path; |
994 | int rc; | ||
1126 | 995 | ||
996 | if (!dev || !dev->map_name) | ||
997 | return -EINVAL; | ||
1127 | 998 | ||
1128 | rc = input_register_device(input_dev); | 999 | rc_tab = get_rc_map(dev->map_name); |
1129 | if (rc < 0) { | 1000 | if (!rc_tab) |
1130 | device_del(&ir_dev->dev); | 1001 | rc_tab = get_rc_map(RC_MAP_EMPTY); |
1002 | if (!rc_tab || !rc_tab->scan || rc_tab->size == 0) | ||
1003 | return -EINVAL; | ||
1004 | |||
1005 | set_bit(EV_KEY, dev->input_dev->evbit); | ||
1006 | set_bit(EV_REP, dev->input_dev->evbit); | ||
1007 | set_bit(EV_MSC, dev->input_dev->evbit); | ||
1008 | set_bit(MSC_SCAN, dev->input_dev->mscbit); | ||
1009 | if (dev->open) | ||
1010 | dev->input_dev->open = ir_open; | ||
1011 | if (dev->close) | ||
1012 | dev->input_dev->close = ir_close; | ||
1013 | |||
1014 | dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1); | ||
1015 | dev_set_name(&dev->dev, "rc%ld", dev->devno); | ||
1016 | dev_set_drvdata(&dev->dev, dev); | ||
1017 | rc = device_add(&dev->dev); | ||
1018 | if (rc) | ||
1131 | return rc; | 1019 | return rc; |
1132 | } | ||
1133 | 1020 | ||
1134 | __module_get(THIS_MODULE); | 1021 | rc = ir_setkeytable(dev, rc_tab); |
1022 | if (rc) | ||
1023 | goto out_dev; | ||
1024 | |||
1025 | dev->input_dev->dev.parent = &dev->dev; | ||
1026 | memcpy(&dev->input_dev->id, &dev->input_id, sizeof(dev->input_id)); | ||
1027 | dev->input_dev->phys = dev->input_phys; | ||
1028 | dev->input_dev->name = dev->input_name; | ||
1029 | rc = input_register_device(dev->input_dev); | ||
1030 | if (rc) | ||
1031 | goto out_table; | ||
1135 | 1032 | ||
1136 | path = kobject_get_path(&ir_dev->dev.kobj, GFP_KERNEL); | 1033 | /* |
1034 | * Default delay of 250ms is too short for some protocols, expecially | ||
1035 | * since the timeout is currently set to 250ms. Increase it to 500ms, | ||
1036 | * to avoid wrong repetition of the keycodes. Note that this must be | ||
1037 | * set after the call to input_register_device(). | ||
1038 | */ | ||
1039 | dev->input_dev->rep[REP_DELAY] = 500; | ||
1040 | |||
1041 | path = kobject_get_path(&dev->dev.kobj, GFP_KERNEL); | ||
1137 | printk(KERN_INFO "%s: %s as %s\n", | 1042 | printk(KERN_INFO "%s: %s as %s\n", |
1138 | dev_name(&ir_dev->dev), | 1043 | dev_name(&dev->dev), |
1139 | input_dev->name ? input_dev->name : "Unspecified device", | 1044 | dev->input_name ? dev->input_name : "Unspecified device", |
1140 | path ? path : "N/A"); | 1045 | path ? path : "N/A"); |
1141 | kfree(path); | 1046 | kfree(path); |
1142 | 1047 | ||
1143 | set_bit(ir_dev->devno, &ir_core_dev_number); | 1048 | if (dev->driver_type == RC_DRIVER_IR_RAW) { |
1049 | rc = ir_raw_event_register(dev); | ||
1050 | if (rc < 0) | ||
1051 | goto out_input; | ||
1052 | } | ||
1053 | |||
1054 | if (dev->change_protocol) { | ||
1055 | rc = dev->change_protocol(dev, rc_tab->ir_type); | ||
1056 | if (rc < 0) | ||
1057 | goto out_raw; | ||
1058 | } | ||
1059 | |||
1060 | IR_dprintk(1, "Registered rc%ld (driver: %s, remote: %s, mode %s)\n", | ||
1061 | dev->devno, | ||
1062 | dev->driver_name ? dev->driver_name : "unknown", | ||
1063 | rc_tab->name ? rc_tab->name : "unknown", | ||
1064 | dev->driver_type == RC_DRIVER_IR_RAW ? "raw" : "cooked"); | ||
1065 | |||
1144 | return 0; | 1066 | return 0; |
1067 | |||
1068 | out_raw: | ||
1069 | if (dev->driver_type == RC_DRIVER_IR_RAW) | ||
1070 | ir_raw_event_unregister(dev); | ||
1071 | out_input: | ||
1072 | input_unregister_device(dev->input_dev); | ||
1073 | dev->input_dev = NULL; | ||
1074 | out_table: | ||
1075 | ir_free_table(&dev->rc_tab); | ||
1076 | out_dev: | ||
1077 | device_del(&dev->dev); | ||
1078 | return rc; | ||
1145 | } | 1079 | } |
1080 | EXPORT_SYMBOL_GPL(rc_register_device); | ||
1146 | 1081 | ||
1147 | /** | 1082 | void rc_unregister_device(struct rc_dev *dev) |
1148 | * ir_unregister_class() - removes the sysfs for sysfs for | ||
1149 | * /sys/class/rc/rc? | ||
1150 | * @input_dev: the struct input_dev descriptor of the device | ||
1151 | * | ||
1152 | * This routine is used to unregister the syfs code for IR class | ||
1153 | */ | ||
1154 | static void ir_unregister_class(struct input_dev *input_dev) | ||
1155 | { | 1083 | { |
1156 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); | 1084 | if (!dev) |
1085 | return; | ||
1157 | 1086 | ||
1158 | input_set_drvdata(input_dev, NULL); | 1087 | del_timer_sync(&dev->timer_keyup); |
1159 | clear_bit(ir_dev->devno, &ir_core_dev_number); | ||
1160 | input_unregister_device(input_dev); | ||
1161 | device_del(&ir_dev->dev); | ||
1162 | 1088 | ||
1163 | module_put(THIS_MODULE); | 1089 | if (dev->driver_type == RC_DRIVER_IR_RAW) |
1090 | ir_raw_event_unregister(dev); | ||
1091 | |||
1092 | input_unregister_device(dev->input_dev); | ||
1093 | dev->input_dev = NULL; | ||
1094 | |||
1095 | ir_free_table(&dev->rc_tab); | ||
1096 | IR_dprintk(1, "Freed keycode table\n"); | ||
1097 | |||
1098 | device_unregister(&dev->dev); | ||
1164 | } | 1099 | } |
1100 | EXPORT_SYMBOL_GPL(rc_unregister_device); | ||
1165 | 1101 | ||
1166 | /* | 1102 | /* |
1167 | * Init/exit code for the module. Basically, creates/removes /sys/class/rc | 1103 | * Init/exit code for the module. Basically, creates/removes /sys/class/rc |