Lines Matching +full:long +full:- +full:press +full:- +full:ms

1 // SPDX-License-Identifier: GPL-2.0
2 // rc-main.c - Remote Controller core module
4 // Copyright (C) 2009-2010 by Mauro Carvalho Chehab
8 #include <media/rc-core.h>
18 #include "rc-core-priv.h"
31 [RC_PROTO_RC5] = { .name = "rc-5",
33 [RC_PROTO_RC5X_20] = { .name = "rc-5x-20",
35 [RC_PROTO_RC5_SZ] = { .name = "rc-5-sz",
39 [RC_PROTO_SONY12] = { .name = "sony-12",
41 [RC_PROTO_SONY15] = { .name = "sony-15",
43 [RC_PROTO_SONY20] = { .name = "sony-20",
47 [RC_PROTO_NECX] = { .name = "nec-x",
49 [RC_PROTO_NEC32] = { .name = "nec-32",
53 [RC_PROTO_MCIR2_KBD] = { .name = "mcir2-kbd",
55 [RC_PROTO_MCIR2_MSE] = { .name = "mcir2-mse",
57 [RC_PROTO_RC6_0] = { .name = "rc-6-0",
59 [RC_PROTO_RC6_6A_20] = { .name = "rc-6-6a-20",
61 [RC_PROTO_RC6_6A_24] = { .name = "rc-6-6a-24",
63 [RC_PROTO_RC6_6A_32] = { .name = "rc-6-6a-32",
65 [RC_PROTO_RC6_MCE] = { .name = "rc-6-mce",
73 [RC_PROTO_RCMM12] = { .name = "rc-mm-12",
75 [RC_PROTO_RCMM24] = { .name = "rc-mm-24",
77 [RC_PROTO_RCMM32] = { .name = "rc-mm-32",
79 [RC_PROTO_XBOX_DVD] = { .name = "xbox-dvd", .repeat_period = 64 },
96 if (!strcmp(name, map->map.name)) { in seek_rc_map()
129 printk(KERN_INFO "Registered IR keymap %s\n", map->map.name); in rc_map_get()
131 return &map->map; in rc_map_get()
138 list_add_tail(&map->list, &rc_map_list); in rc_map_register()
147 list_del(&map->list); in rc_map_unregister()
167 * scancode_to_u64() - converts scancode in &struct input_keymap_entry
173 * rc-core.
177 switch (ke->len) { in scancode_to_u64()
179 *scancode = *((u8 *)ke->scancode); in scancode_to_u64()
183 *scancode = *((u16 *)ke->scancode); in scancode_to_u64()
187 *scancode = *((u32 *)ke->scancode); in scancode_to_u64()
191 *scancode = *((u64 *)ke->scancode); in scancode_to_u64()
195 return -EINVAL; in scancode_to_u64()
202 * ir_create_table() - initializes a scancode table
217 rc_map->name = kstrdup(name, GFP_KERNEL); in ir_create_table()
218 if (!rc_map->name) in ir_create_table()
219 return -ENOMEM; in ir_create_table()
220 rc_map->rc_proto = rc_proto; in ir_create_table()
221 rc_map->alloc = roundup_pow_of_two(size * sizeof(struct rc_map_table)); in ir_create_table()
222 rc_map->size = rc_map->alloc / sizeof(struct rc_map_table); in ir_create_table()
223 rc_map->scan = kmalloc(rc_map->alloc, GFP_KERNEL); in ir_create_table()
224 if (!rc_map->scan) { in ir_create_table()
225 kfree(rc_map->name); in ir_create_table()
226 rc_map->name = NULL; in ir_create_table()
227 return -ENOMEM; in ir_create_table()
230 dev_dbg(&dev->dev, "Allocated space for %u keycode entries (%u bytes)\n", in ir_create_table()
231 rc_map->size, rc_map->alloc); in ir_create_table()
236 * ir_free_table() - frees memory allocated by a scancode table
244 rc_map->size = 0; in ir_free_table()
245 kfree(rc_map->name); in ir_free_table()
246 rc_map->name = NULL; in ir_free_table()
247 kfree(rc_map->scan); in ir_free_table()
248 rc_map->scan = NULL; in ir_free_table()
252 * ir_resize_table() - resizes a scancode table if necessary
265 unsigned int oldalloc = rc_map->alloc; in ir_resize_table()
267 struct rc_map_table *oldscan = rc_map->scan; in ir_resize_table()
270 if (rc_map->size == rc_map->len) { in ir_resize_table()
271 /* All entries in use -> grow keytable */ in ir_resize_table()
272 if (rc_map->alloc >= IR_TAB_MAX_SIZE) in ir_resize_table()
273 return -ENOMEM; in ir_resize_table()
276 dev_dbg(&dev->dev, "Growing table to %u bytes\n", newalloc); in ir_resize_table()
279 if ((rc_map->len * 3 < rc_map->size) && (oldalloc > IR_TAB_MIN_SIZE)) { in ir_resize_table()
280 /* Less than 1/3 of entries in use -> shrink keytable */ in ir_resize_table()
282 dev_dbg(&dev->dev, "Shrinking table to %u bytes\n", newalloc); in ir_resize_table()
290 return -ENOMEM; in ir_resize_table()
292 memcpy(newscan, rc_map->scan, rc_map->len * sizeof(struct rc_map_table)); in ir_resize_table()
293 rc_map->scan = newscan; in ir_resize_table()
294 rc_map->alloc = newalloc; in ir_resize_table()
295 rc_map->size = rc_map->alloc / sizeof(struct rc_map_table); in ir_resize_table()
301 * ir_update_mapping() - set a keycode in the scancode->keycode table
307 * This routine is used to update scancode->keycode mapping at given
318 int old_keycode = rc_map->scan[index].keycode; in ir_update_mapping()
323 dev_dbg(&dev->dev, "#%d: Deleting scan 0x%04llx\n", in ir_update_mapping()
324 index, rc_map->scan[index].scancode); in ir_update_mapping()
325 rc_map->len--; in ir_update_mapping()
326 memmove(&rc_map->scan[index], &rc_map->scan[index+ 1], in ir_update_mapping()
327 (rc_map->len - index) * sizeof(struct rc_map_table)); in ir_update_mapping()
329 dev_dbg(&dev->dev, "#%d: %s scan 0x%04llx with key 0x%04x\n", in ir_update_mapping()
332 rc_map->scan[index].scancode, new_keycode); in ir_update_mapping()
333 rc_map->scan[index].keycode = new_keycode; in ir_update_mapping()
334 __set_bit(new_keycode, dev->input_dev->keybit); in ir_update_mapping()
339 __clear_bit(old_keycode, dev->input_dev->keybit); in ir_update_mapping()
341 for (i = 0; i < rc_map->len; i++) { in ir_update_mapping()
342 if (rc_map->scan[i].keycode == old_keycode) { in ir_update_mapping()
343 __set_bit(old_keycode, dev->input_dev->keybit); in ir_update_mapping()
356 * ir_establish_scancode() - set a keycode in the scancode->keycode table
368 * or -1U in case of failure.
377 * Unfortunately, some hardware-based IR decoders don't provide in ir_establish_scancode()
384 if (dev->scancode_mask) in ir_establish_scancode()
385 scancode &= dev->scancode_mask; in ir_establish_scancode()
388 for (i = 0; i < rc_map->len; i++) { in ir_establish_scancode()
389 if (rc_map->scan[i].scancode == scancode) in ir_establish_scancode()
393 if (rc_map->scan[i].scancode >= scancode) in ir_establish_scancode()
398 if (rc_map->size == rc_map->len) { in ir_establish_scancode()
400 return -1U; in ir_establish_scancode()
404 if (i < rc_map->len) in ir_establish_scancode()
405 memmove(&rc_map->scan[i + 1], &rc_map->scan[i], in ir_establish_scancode()
406 (rc_map->len - i) * sizeof(struct rc_map_table)); in ir_establish_scancode()
407 rc_map->scan[i].scancode = scancode; in ir_establish_scancode()
408 rc_map->scan[i].keycode = KEY_RESERVED; in ir_establish_scancode()
409 rc_map->len++; in ir_establish_scancode()
415 * ir_setkeycode() - set a keycode in the scancode->keycode table
422 * return: -EINVAL if the keycode could not be inserted, otherwise zero.
429 struct rc_map *rc_map = &rdev->rc_map; in ir_setkeycode()
433 unsigned long flags; in ir_setkeycode()
435 spin_lock_irqsave(&rc_map->lock, flags); in ir_setkeycode()
437 if (ke->flags & INPUT_KEYMAP_BY_INDEX) { in ir_setkeycode()
438 index = ke->index; in ir_setkeycode()
439 if (index >= rc_map->len) { in ir_setkeycode()
440 retval = -EINVAL; in ir_setkeycode()
449 if (index >= rc_map->len) { in ir_setkeycode()
450 retval = -ENOMEM; in ir_setkeycode()
455 *old_keycode = ir_update_mapping(rdev, rc_map, index, ke->keycode); in ir_setkeycode()
458 spin_unlock_irqrestore(&rc_map->lock, flags); in ir_setkeycode()
463 * ir_setkeytable() - sets several entries in the scancode->keycode table
469 * return: -ENOMEM if all keycodes could not be inserted, otherwise zero.
473 struct rc_map *rc_map = &dev->rc_map; in ir_setkeytable()
477 rc = ir_create_table(dev, rc_map, from->name, from->rc_proto, in ir_setkeytable()
478 from->size); in ir_setkeytable()
482 for (i = 0; i < from->size; i++) { in ir_setkeytable()
484 from->scan[i].scancode, false); in ir_setkeytable()
485 if (index >= rc_map->len) { in ir_setkeytable()
486 rc = -ENOMEM; in ir_setkeytable()
491 from->scan[i].keycode); in ir_setkeytable()
505 if (*scancode < e->scancode) in rc_map_cmp()
506 return -1; in rc_map_cmp()
507 else if (*scancode > e->scancode) in rc_map_cmp()
513 * ir_lookup_by_scancode() - locate mapping by scancode
520 * return: index in the table, -1U if not found
527 res = bsearch(&scancode, rc_map->scan, rc_map->len, in ir_lookup_by_scancode()
530 return -1U; in ir_lookup_by_scancode()
532 return res - rc_map->scan; in ir_lookup_by_scancode()
536 * ir_getkeycode() - get a keycode from the scancode->keycode table
548 struct rc_map *rc_map = &rdev->rc_map; in ir_getkeycode()
550 unsigned long flags; in ir_getkeycode()
555 spin_lock_irqsave(&rc_map->lock, flags); in ir_getkeycode()
557 if (ke->flags & INPUT_KEYMAP_BY_INDEX) { in ir_getkeycode()
558 index = ke->index; in ir_getkeycode()
567 if (index < rc_map->len) { in ir_getkeycode()
568 entry = &rc_map->scan[index]; in ir_getkeycode()
570 ke->index = index; in ir_getkeycode()
571 ke->keycode = entry->keycode; in ir_getkeycode()
572 ke->len = sizeof(entry->scancode); in ir_getkeycode()
573 memcpy(ke->scancode, &entry->scancode, sizeof(entry->scancode)); in ir_getkeycode()
574 } else if (!(ke->flags & INPUT_KEYMAP_BY_INDEX)) { in ir_getkeycode()
580 ke->index = index; in ir_getkeycode()
581 ke->keycode = KEY_RESERVED; in ir_getkeycode()
583 retval = -EINVAL; in ir_getkeycode()
590 spin_unlock_irqrestore(&rc_map->lock, flags); in ir_getkeycode()
595 * rc_g_keycode_from_table() - gets the keycode that corresponds to a scancode
607 struct rc_map *rc_map = &dev->rc_map; in rc_g_keycode_from_table()
610 unsigned long flags; in rc_g_keycode_from_table()
612 spin_lock_irqsave(&rc_map->lock, flags); in rc_g_keycode_from_table()
615 keycode = index < rc_map->len ? in rc_g_keycode_from_table()
616 rc_map->scan[index].keycode : KEY_RESERVED; in rc_g_keycode_from_table()
618 spin_unlock_irqrestore(&rc_map->lock, flags); in rc_g_keycode_from_table()
621 dev_dbg(&dev->dev, "%s: scancode 0x%04llx keycode 0x%02x\n", in rc_g_keycode_from_table()
622 dev->device_name, scancode, keycode); in rc_g_keycode_from_table()
629 * ir_do_keyup() - internal function to signal the release of a keypress
638 if (!dev->keypressed) in ir_do_keyup()
641 dev_dbg(&dev->dev, "keyup key 0x%04x\n", dev->last_keycode); in ir_do_keyup()
642 del_timer(&dev->timer_repeat); in ir_do_keyup()
643 input_report_key(dev->input_dev, dev->last_keycode, 0); in ir_do_keyup()
646 input_sync(dev->input_dev); in ir_do_keyup()
647 dev->keypressed = false; in ir_do_keyup()
651 * rc_keyup() - signals the release of a keypress
659 unsigned long flags; in rc_keyup()
661 spin_lock_irqsave(&dev->keylock, flags); in rc_keyup()
663 spin_unlock_irqrestore(&dev->keylock, flags); in rc_keyup()
668 * ir_timer_keyup() - generates a keyup event after a timeout
678 unsigned long flags; in ir_timer_keyup()
681 * ir->keyup_jiffies is used to prevent a race condition if a in ir_timer_keyup()
687 * to allow the input subsystem to do its auto-repeat magic or in ir_timer_keyup()
690 spin_lock_irqsave(&dev->keylock, flags); in ir_timer_keyup()
691 if (time_is_before_eq_jiffies(dev->keyup_jiffies)) in ir_timer_keyup()
693 spin_unlock_irqrestore(&dev->keylock, flags); in ir_timer_keyup()
697 * ir_timer_repeat() - generates a repeat event after a timeout
707 struct input_dev *input = dev->input_dev; in ir_timer_repeat()
708 unsigned long flags; in ir_timer_repeat()
710 spin_lock_irqsave(&dev->keylock, flags); in ir_timer_repeat()
711 if (dev->keypressed) { in ir_timer_repeat()
712 input_event(input, EV_KEY, dev->last_keycode, 2); in ir_timer_repeat()
714 if (input->rep[REP_PERIOD]) in ir_timer_repeat()
715 mod_timer(&dev->timer_repeat, jiffies + in ir_timer_repeat()
716 msecs_to_jiffies(input->rep[REP_PERIOD])); in ir_timer_repeat()
718 spin_unlock_irqrestore(&dev->keylock, flags); in ir_timer_repeat()
730 * rc_repeat() - signals that a key is still pressed
739 unsigned long flags; in rc_repeat()
740 unsigned int timeout = usecs_to_jiffies(dev->timeout) + in rc_repeat()
741 msecs_to_jiffies(repeat_period(dev->last_protocol)); in rc_repeat()
743 .scancode = dev->last_scancode, .rc_proto = dev->last_protocol, in rc_repeat()
744 .keycode = dev->keypressed ? dev->last_keycode : KEY_RESERVED, in rc_repeat()
746 (dev->last_toggle ? LIRC_SCANCODE_FLAG_TOGGLE : 0) in rc_repeat()
749 if (dev->allowed_protocols != RC_PROTO_BIT_CEC) in rc_repeat()
752 spin_lock_irqsave(&dev->keylock, flags); in rc_repeat()
754 if (dev->last_scancode <= U32_MAX) { in rc_repeat()
755 input_event(dev->input_dev, EV_MSC, MSC_SCAN, in rc_repeat()
756 dev->last_scancode); in rc_repeat()
757 input_sync(dev->input_dev); in rc_repeat()
760 if (dev->keypressed) { in rc_repeat()
761 dev->keyup_jiffies = jiffies + timeout; in rc_repeat()
762 mod_timer(&dev->timer_keyup, dev->keyup_jiffies); in rc_repeat()
765 spin_unlock_irqrestore(&dev->keylock, flags); in rc_repeat()
770 * ir_do_keydown() - internal function to process a keypress
783 bool new_event = (!dev->keypressed || in ir_do_keydown()
784 dev->last_protocol != protocol || in ir_do_keydown()
785 dev->last_scancode != scancode || in ir_do_keydown()
786 dev->last_toggle != toggle); in ir_do_keydown()
794 if (dev->allowed_protocols != RC_PROTO_BIT_CEC) in ir_do_keydown()
797 if (new_event && dev->keypressed) in ir_do_keydown()
801 input_event(dev->input_dev, EV_MSC, MSC_SCAN, scancode); in ir_do_keydown()
803 dev->last_protocol = protocol; in ir_do_keydown()
804 dev->last_scancode = scancode; in ir_do_keydown()
805 dev->last_toggle = toggle; in ir_do_keydown()
806 dev->last_keycode = keycode; in ir_do_keydown()
810 dev->keypressed = true; in ir_do_keydown()
812 dev_dbg(&dev->dev, "%s: key down event, key 0x%04x, protocol 0x%04x, scancode 0x%08llx\n", in ir_do_keydown()
813 dev->device_name, keycode, protocol, scancode); in ir_do_keydown()
814 input_report_key(dev->input_dev, keycode, 1); in ir_do_keydown()
821 * repeated message is sent, as long as REP_DELAY = 0 and REP_PERIOD in ir_do_keydown()
822 * is non-zero. Otherwise, the input layer will generate repeat in ir_do_keydown()
826 dev->allowed_protocols == RC_PROTO_BIT_CEC && in ir_do_keydown()
827 !timer_pending(&dev->timer_repeat) && in ir_do_keydown()
828 dev->input_dev->rep[REP_PERIOD] && in ir_do_keydown()
829 !dev->input_dev->rep[REP_DELAY]) { in ir_do_keydown()
830 input_event(dev->input_dev, EV_KEY, keycode, 2); in ir_do_keydown()
831 mod_timer(&dev->timer_repeat, jiffies + in ir_do_keydown()
832 msecs_to_jiffies(dev->input_dev->rep[REP_PERIOD])); in ir_do_keydown()
835 input_sync(dev->input_dev); in ir_do_keydown()
839 * rc_keydown() - generates input event for a key press
852 unsigned long flags; in rc_keydown()
855 spin_lock_irqsave(&dev->keylock, flags); in rc_keydown()
858 if (dev->keypressed) { in rc_keydown()
859 dev->keyup_jiffies = jiffies + usecs_to_jiffies(dev->timeout) + in rc_keydown()
861 mod_timer(&dev->timer_keyup, dev->keyup_jiffies); in rc_keydown()
863 spin_unlock_irqrestore(&dev->keylock, flags); in rc_keydown()
868 * rc_keydown_notimeout() - generates input event for a key press without
882 unsigned long flags; in rc_keydown_notimeout()
885 spin_lock_irqsave(&dev->keylock, flags); in rc_keydown_notimeout()
887 spin_unlock_irqrestore(&dev->keylock, flags); in rc_keydown_notimeout()
892 * rc_validate_scancode() - checks that a scancode is valid for a protocol.
901 * NECX has a 16-bit address; if the lower 8 bits match the upper in rc_validate_scancode()
918 * If the customer code (top 32-bit) is 0x800f, it is MCE else it in rc_validate_scancode()
919 * is regular mode-6a 32 bit in rc_validate_scancode()
937 * rc_validate_filter() - checks that the scancode and mask are valid and
942 * return: 0 or -EINVAL if the filter is not valid
947 u32 mask, s = filter->data; in rc_validate_filter()
948 enum rc_proto protocol = dev->wakeup_protocol; in rc_validate_filter()
951 return -EINVAL; in rc_validate_filter()
956 return -EINVAL; in rc_validate_filter()
958 filter->data &= mask; in rc_validate_filter()
959 filter->mask &= mask; in rc_validate_filter()
964 if (dev->encode_wakeup && filter->mask != 0 && filter->mask != mask) in rc_validate_filter()
965 return -EINVAL; in rc_validate_filter()
975 return -EINVAL; in rc_open()
977 mutex_lock(&rdev->lock); in rc_open()
979 if (!rdev->registered) { in rc_open()
980 rval = -ENODEV; in rc_open()
982 if (!rdev->users++ && rdev->open) in rc_open()
983 rval = rdev->open(rdev); in rc_open()
986 rdev->users--; in rc_open()
989 mutex_unlock(&rdev->lock); in rc_open()
1004 mutex_lock(&rdev->lock); in rc_close()
1006 if (!--rdev->users && rdev->close && rdev->registered) in rc_close()
1007 rdev->close(rdev); in rc_close()
1009 mutex_unlock(&rdev->lock); in rc_close()
1044 RC_PROTO_BIT_RC5X_20, "rc-5", "ir-rc5-decoder" },
1047 RC_PROTO_BIT_NEC32, "nec", "ir-nec-decoder" },
1052 RC_PROTO_BIT_RC6_MCE, "rc-6", "ir-rc6-decoder" },
1053 { RC_PROTO_BIT_JVC, "jvc", "ir-jvc-decoder" },
1056 RC_PROTO_BIT_SONY20, "sony", "ir-sony-decoder" },
1057 { RC_PROTO_BIT_RC5_SZ, "rc-5-sz", "ir-rc5-decoder" },
1058 { RC_PROTO_BIT_SANYO, "sanyo", "ir-sanyo-decoder" },
1059 { RC_PROTO_BIT_SHARP, "sharp", "ir-sharp-decoder" },
1061 RC_PROTO_BIT_MCIR2_MSE, "mce_kbd", "ir-mce_kbd-decoder" },
1062 { RC_PROTO_BIT_XMP, "xmp", "ir-xmp-decoder" },
1064 { RC_PROTO_BIT_IMON, "imon", "ir-imon-decoder" },
1067 RC_PROTO_BIT_RCMM32, "rc-mm", "ir-rcmm-decoder" },
1068 { RC_PROTO_BIT_XBOX_DVD, "xbox-dvd", NULL },
1072 * struct rc_filter_attribute - Device attribute relating to a filter type.
1092 * show_protocols() - shows the current IR protocol(s)
1102 * dev->lock is taken to guard against races between
1113 mutex_lock(&dev->lock); in show_protocols()
1115 enabled = dev->enabled_protocols; in show_protocols()
1116 allowed = dev->allowed_protocols; in show_protocols()
1117 if (dev->raw && !allowed) in show_protocols()
1120 mutex_unlock(&dev->lock); in show_protocols()
1122 dev_dbg(&dev->dev, "%s: allowed - 0x%llx, enabled - 0x%llx\n", in show_protocols()
1123 __func__, (long long)allowed, (long long)enabled); in show_protocols()
1136 if (dev->driver_type == RC_DRIVER_IR_RAW) in show_protocols()
1141 tmp--; in show_protocols()
1144 return tmp + 1 - buf; in show_protocols()
1148 * parse_protocol_change() - parses a protocol change request
1154 * Writing "-proto" will remove a protocol from protocol mask.
1176 } else if (*tmp == '-') { in parse_protocol_change()
1196 dev_dbg(&dev->dev, "Unknown protocol: '%s'\n", in parse_protocol_change()
1198 return -EINVAL; in parse_protocol_change()
1213 dev_dbg(&dev->dev, "Protocol not specified\n"); in parse_protocol_change()
1214 return -EINVAL; in parse_protocol_change()
1262 * store_protocols() - changes the current/wakeup IR protocol(s)
1273 * dev->lock is taken to guard against races between
1286 dev_dbg(&dev->dev, "Normal protocol change requested\n"); in store_protocols()
1287 current_protocols = &dev->enabled_protocols; in store_protocols()
1288 filter = &dev->scancode_filter; in store_protocols()
1290 if (!dev->change_protocol) { in store_protocols()
1291 dev_dbg(&dev->dev, "Protocol switching not supported\n"); in store_protocols()
1292 return -EINVAL; in store_protocols()
1295 mutex_lock(&dev->lock); in store_protocols()
1296 if (!dev->registered) { in store_protocols()
1297 mutex_unlock(&dev->lock); in store_protocols()
1298 return -ENODEV; in store_protocols()
1307 if (dev->driver_type == RC_DRIVER_IR_RAW) in store_protocols()
1310 rc = dev->change_protocol(dev, &new_protocols); in store_protocols()
1312 dev_dbg(&dev->dev, "Error setting protocols to 0x%llx\n", in store_protocols()
1313 (long long)new_protocols); in store_protocols()
1319 dev_dbg(&dev->dev, "Protocols changed to 0x%llx\n", in store_protocols()
1320 (long long)new_protocols); in store_protocols()
1330 if (dev->s_filter && filter->mask) { in store_protocols()
1332 rc = dev->s_filter(dev, filter); in store_protocols()
1334 rc = -1; in store_protocols()
1337 filter->data = 0; in store_protocols()
1338 filter->mask = 0; in store_protocols()
1339 dev->s_filter(dev, filter); in store_protocols()
1346 mutex_unlock(&dev->lock); in store_protocols()
1351 * show_filter() - shows the current scancode filter value or mask
1362 * compared against input scancodes and non-matching scancodes are discarded.
1364 * dev->lock is taken to guard against races between
1376 mutex_lock(&dev->lock); in show_filter()
1378 if (fattr->type == RC_FILTER_NORMAL) in show_filter()
1379 filter = &dev->scancode_filter; in show_filter()
1381 filter = &dev->scancode_wakeup_filter; in show_filter()
1383 if (fattr->mask) in show_filter()
1384 val = filter->mask; in show_filter()
1386 val = filter->data; in show_filter()
1387 mutex_unlock(&dev->lock); in show_filter()
1393 * store_filter() - changes the scancode filter value
1401 * Returns -EINVAL if an invalid filter value for the current protocol was
1406 * compared against input scancodes and non-matching scancodes are discarded.
1408 * dev->lock is taken to guard against races between
1419 unsigned long val; in store_filter()
1426 if (fattr->type == RC_FILTER_NORMAL) { in store_filter()
1427 set_filter = dev->s_filter; in store_filter()
1428 filter = &dev->scancode_filter; in store_filter()
1430 set_filter = dev->s_wakeup_filter; in store_filter()
1431 filter = &dev->scancode_wakeup_filter; in store_filter()
1435 return -EINVAL; in store_filter()
1437 mutex_lock(&dev->lock); in store_filter()
1438 if (!dev->registered) { in store_filter()
1439 mutex_unlock(&dev->lock); in store_filter()
1440 return -ENODEV; in store_filter()
1444 if (fattr->mask) in store_filter()
1449 if (fattr->type == RC_FILTER_WAKEUP) { in store_filter()
1454 if (dev->wakeup_protocol != RC_PROTO_UNKNOWN) in store_filter()
1457 ret = -EINVAL; in store_filter()
1463 if (fattr->type == RC_FILTER_NORMAL && !dev->enabled_protocols && in store_filter()
1466 ret = -EINVAL; in store_filter()
1477 mutex_unlock(&dev->lock); in store_filter()
1482 * show_wakeup_protocols() - shows the wakeup IR protocol
1492 * dev->lock is taken to guard against races between
1505 mutex_lock(&dev->lock); in show_wakeup_protocols()
1507 allowed = dev->allowed_wakeup_protocols; in show_wakeup_protocols()
1508 enabled = dev->wakeup_protocol; in show_wakeup_protocols()
1510 mutex_unlock(&dev->lock); in show_wakeup_protocols()
1512 dev_dbg(&dev->dev, "%s: allowed - 0x%llx, enabled - %d\n", in show_wakeup_protocols()
1513 __func__, (long long)allowed, enabled); in show_wakeup_protocols()
1525 tmp--; in show_wakeup_protocols()
1528 return tmp + 1 - buf; in show_wakeup_protocols()
1532 * store_wakeup_protocols() - changes the wakeup IR protocol(s)
1542 * dev->lock is taken to guard against races between
1555 mutex_lock(&dev->lock); in store_wakeup_protocols()
1556 if (!dev->registered) { in store_wakeup_protocols()
1557 mutex_unlock(&dev->lock); in store_wakeup_protocols()
1558 return -ENODEV; in store_wakeup_protocols()
1561 allowed = dev->allowed_wakeup_protocols; in store_wakeup_protocols()
1573 rc = -EINVAL; in store_wakeup_protocols()
1577 if (dev->encode_wakeup) { in store_wakeup_protocols()
1582 rc = -EINVAL; in store_wakeup_protocols()
1588 if (dev->wakeup_protocol != protocol) { in store_wakeup_protocols()
1589 dev->wakeup_protocol = protocol; in store_wakeup_protocols()
1590 dev_dbg(&dev->dev, "Wakeup protocol changed to %d\n", protocol); in store_wakeup_protocols()
1593 dev->scancode_wakeup_filter.data = 0x800f0000; in store_wakeup_protocols()
1595 dev->scancode_wakeup_filter.data = 0; in store_wakeup_protocols()
1596 dev->scancode_wakeup_filter.mask = 0; in store_wakeup_protocols()
1598 rc = dev->s_wakeup_filter(dev, &dev->scancode_wakeup_filter); in store_wakeup_protocols()
1606 mutex_unlock(&dev->lock); in store_wakeup_protocols()
1622 mutex_lock(&dev->lock); in rc_dev_uevent()
1624 if (!dev->registered) in rc_dev_uevent()
1625 ret = -ENODEV; in rc_dev_uevent()
1626 if (ret == 0 && dev->rc_map.name) in rc_dev_uevent()
1627 ret = add_uevent_var(env, "NAME=%s", dev->rc_map.name); in rc_dev_uevent()
1628 if (ret == 0 && dev->driver_name) in rc_dev_uevent()
1629 ret = add_uevent_var(env, "DRV_NAME=%s", dev->driver_name); in rc_dev_uevent()
1630 if (ret == 0 && dev->device_name) in rc_dev_uevent()
1631 ret = add_uevent_var(env, "DEV_NAME=%s", dev->device_name); in rc_dev_uevent()
1633 mutex_unlock(&dev->lock); in rc_dev_uevent()
1709 dev->input_dev = input_allocate_device(); in rc_allocate_device()
1710 if (!dev->input_dev) { in rc_allocate_device()
1715 dev->input_dev->getkeycode = ir_getkeycode; in rc_allocate_device()
1716 dev->input_dev->setkeycode = ir_setkeycode; in rc_allocate_device()
1717 input_set_drvdata(dev->input_dev, dev); in rc_allocate_device()
1719 dev->timeout = IR_DEFAULT_TIMEOUT; in rc_allocate_device()
1720 timer_setup(&dev->timer_keyup, ir_timer_keyup, 0); in rc_allocate_device()
1721 timer_setup(&dev->timer_repeat, ir_timer_repeat, 0); in rc_allocate_device()
1723 spin_lock_init(&dev->rc_map.lock); in rc_allocate_device()
1724 spin_lock_init(&dev->keylock); in rc_allocate_device()
1726 mutex_init(&dev->lock); in rc_allocate_device()
1728 dev->dev.type = &rc_dev_type; in rc_allocate_device()
1729 dev->dev.class = &rc_class; in rc_allocate_device()
1730 device_initialize(&dev->dev); in rc_allocate_device()
1732 dev->driver_type = type; in rc_allocate_device()
1744 input_free_device(dev->input_dev); in rc_free_device()
1746 put_device(&dev->dev); in rc_free_device()
1775 rc->dev.parent = dev; in devm_rc_allocate_device()
1776 rc->managed_alloc = true; in devm_rc_allocate_device()
1790 if (!dev->map_name) in rc_prepare_rx_device()
1791 return -EINVAL; in rc_prepare_rx_device()
1793 rc_map = rc_map_get(dev->map_name); in rc_prepare_rx_device()
1796 if (!rc_map || !rc_map->scan || rc_map->size == 0) in rc_prepare_rx_device()
1797 return -EINVAL; in rc_prepare_rx_device()
1803 rc_proto = BIT_ULL(rc_map->rc_proto); in rc_prepare_rx_device()
1805 if (dev->driver_type == RC_DRIVER_SCANCODE && !dev->change_protocol) in rc_prepare_rx_device()
1806 dev->enabled_protocols = dev->allowed_protocols; in rc_prepare_rx_device()
1808 if (dev->driver_type == RC_DRIVER_IR_RAW) in rc_prepare_rx_device()
1811 if (dev->change_protocol) { in rc_prepare_rx_device()
1812 rc = dev->change_protocol(dev, &rc_proto); in rc_prepare_rx_device()
1815 dev->enabled_protocols = rc_proto; in rc_prepare_rx_device()
1819 set_bit(EV_KEY, dev->input_dev->evbit); in rc_prepare_rx_device()
1820 set_bit(EV_REP, dev->input_dev->evbit); in rc_prepare_rx_device()
1821 set_bit(EV_MSC, dev->input_dev->evbit); in rc_prepare_rx_device()
1822 set_bit(MSC_SCAN, dev->input_dev->mscbit); in rc_prepare_rx_device()
1825 set_bit(INPUT_PROP_POINTING_STICK, dev->input_dev->propbit); in rc_prepare_rx_device()
1826 set_bit(EV_REL, dev->input_dev->evbit); in rc_prepare_rx_device()
1827 set_bit(REL_X, dev->input_dev->relbit); in rc_prepare_rx_device()
1828 set_bit(REL_Y, dev->input_dev->relbit); in rc_prepare_rx_device()
1830 if (dev->open) in rc_prepare_rx_device()
1831 dev->input_dev->open = ir_open; in rc_prepare_rx_device()
1832 if (dev->close) in rc_prepare_rx_device()
1833 dev->input_dev->close = ir_close; in rc_prepare_rx_device()
1835 dev->input_dev->dev.parent = &dev->dev; in rc_prepare_rx_device()
1836 memcpy(&dev->input_dev->id, &dev->input_id, sizeof(dev->input_id)); in rc_prepare_rx_device()
1837 dev->input_dev->phys = dev->input_phys; in rc_prepare_rx_device()
1838 dev->input_dev->name = dev->device_name; in rc_prepare_rx_device()
1843 ir_free_table(&dev->rc_map); in rc_prepare_rx_device()
1853 rc = input_register_device(dev->input_dev); in rc_setup_rx_device()
1858 * Default delay of 250ms is too short for some protocols, especially in rc_setup_rx_device()
1859 * since the timeout is currently set to 250ms. Increase it to 500ms, in rc_setup_rx_device()
1863 if (dev->allowed_protocols == RC_PROTO_BIT_CEC) in rc_setup_rx_device()
1864 dev->input_dev->rep[REP_DELAY] = 0; in rc_setup_rx_device()
1866 dev->input_dev->rep[REP_DELAY] = 500; in rc_setup_rx_device()
1869 * As a repeat event on protocols like RC-5 and NEC take as long as in rc_setup_rx_device()
1870 * 110/114ms, using 33ms as a repeat period is not the right thing in rc_setup_rx_device()
1873 dev->input_dev->rep[REP_PERIOD] = 125; in rc_setup_rx_device()
1883 if (dev->input_dev) { in rc_free_rx_device()
1884 input_unregister_device(dev->input_dev); in rc_free_rx_device()
1885 dev->input_dev = NULL; in rc_free_rx_device()
1888 ir_free_table(&dev->rc_map); in rc_free_rx_device()
1899 return -EINVAL; in rc_register_device()
1901 minor = ida_alloc_max(&rc_ida, RC_DEV_MAX - 1, GFP_KERNEL); in rc_register_device()
1905 dev->minor = minor; in rc_register_device()
1906 dev_set_name(&dev->dev, "rc%u", dev->minor); in rc_register_device()
1907 dev_set_drvdata(&dev->dev, dev); in rc_register_device()
1909 dev->dev.groups = dev->sysfs_groups; in rc_register_device()
1910 if (dev->driver_type == RC_DRIVER_SCANCODE && !dev->change_protocol) in rc_register_device()
1911 dev->sysfs_groups[attr++] = &rc_dev_ro_protocol_attr_grp; in rc_register_device()
1912 else if (dev->driver_type != RC_DRIVER_IR_RAW_TX) in rc_register_device()
1913 dev->sysfs_groups[attr++] = &rc_dev_rw_protocol_attr_grp; in rc_register_device()
1914 if (dev->s_filter) in rc_register_device()
1915 dev->sysfs_groups[attr++] = &rc_dev_filter_attr_grp; in rc_register_device()
1916 if (dev->s_wakeup_filter) in rc_register_device()
1917 dev->sysfs_groups[attr++] = &rc_dev_wakeup_filter_attr_grp; in rc_register_device()
1918 dev->sysfs_groups[attr++] = NULL; in rc_register_device()
1920 if (dev->driver_type == RC_DRIVER_IR_RAW) { in rc_register_device()
1926 if (dev->driver_type != RC_DRIVER_IR_RAW_TX) { in rc_register_device()
1932 dev->registered = true; in rc_register_device()
1934 rc = device_add(&dev->dev); in rc_register_device()
1938 path = kobject_get_path(&dev->dev.kobj, GFP_KERNEL); in rc_register_device()
1939 dev_info(&dev->dev, "%s as %s\n", in rc_register_device()
1940 dev->device_name ?: "Unspecified device", path ?: "N/A"); in rc_register_device()
1949 if (dev->allowed_protocols != RC_PROTO_BIT_CEC) { in rc_register_device()
1955 if (dev->driver_type != RC_DRIVER_IR_RAW_TX) { in rc_register_device()
1961 if (dev->driver_type == RC_DRIVER_IR_RAW) { in rc_register_device()
1967 dev_dbg(&dev->dev, "Registered rc%u (driver: %s)\n", dev->minor, in rc_register_device()
1968 dev->driver_name ? dev->driver_name : "unknown"); in rc_register_device()
1975 if (dev->allowed_protocols != RC_PROTO_BIT_CEC) in rc_register_device()
1978 device_del(&dev->dev); in rc_register_device()
1980 ir_free_table(&dev->rc_map); in rc_register_device()
2001 return -ENOMEM; in devm_rc_register_device()
2021 if (dev->driver_type == RC_DRIVER_IR_RAW) in rc_unregister_device()
2024 del_timer_sync(&dev->timer_keyup); in rc_unregister_device()
2025 del_timer_sync(&dev->timer_repeat); in rc_unregister_device()
2027 mutex_lock(&dev->lock); in rc_unregister_device()
2028 if (dev->users && dev->close) in rc_unregister_device()
2029 dev->close(dev); in rc_unregister_device()
2030 dev->registered = false; in rc_unregister_device()
2031 mutex_unlock(&dev->lock); in rc_unregister_device()
2036 * lirc device should be freed with dev->registered = false, so in rc_unregister_device()
2039 if (dev->allowed_protocols != RC_PROTO_BIT_CEC) in rc_unregister_device()
2042 device_del(&dev->dev); in rc_unregister_device()
2044 ida_free(&rc_ida, dev->minor); in rc_unregister_device()
2046 if (!dev->managed_alloc) in rc_unregister_device()
2071 led_trigger_register_simple("rc-feedback", &led_feedback); in rc_core_init()