• Home
  • Raw
  • Download

Lines Matching +full:rc +full:- +full:map +full:- +full:name

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"
25 const char *name; member
29 [RC_PROTO_UNKNOWN] = { .name = "unknown", .repeat_period = 125 },
30 [RC_PROTO_OTHER] = { .name = "other", .repeat_period = 125 },
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",
37 [RC_PROTO_JVC] = { .name = "jvc",
39 [RC_PROTO_SONY12] = { .name = "sony-12",
41 [RC_PROTO_SONY15] = { .name = "sony-15",
43 [RC_PROTO_SONY20] = { .name = "sony-20",
45 [RC_PROTO_NEC] = { .name = "nec",
47 [RC_PROTO_NECX] = { .name = "nec-x",
49 [RC_PROTO_NEC32] = { .name = "nec-32",
51 [RC_PROTO_SANYO] = { .name = "sanyo",
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",
67 [RC_PROTO_SHARP] = { .name = "sharp",
69 [RC_PROTO_XMP] = { .name = "xmp", .repeat_period = 125 },
70 [RC_PROTO_CEC] = { .name = "cec", .repeat_period = 0 },
71 [RC_PROTO_IMON] = { .name = "imon",
80 /* Used to keep track of rc devices */
83 static struct rc_map_list *seek_rc_map(const char *name) in seek_rc_map() argument
85 struct rc_map_list *map = NULL; in seek_rc_map() local
88 list_for_each_entry(map, &rc_map_list, list) { in seek_rc_map()
89 if (!strcmp(name, map->map.name)) { in seek_rc_map()
91 return map; in seek_rc_map()
99 struct rc_map *rc_map_get(const char *name) in rc_map_get() argument
102 struct rc_map_list *map; in rc_map_get() local
104 map = seek_rc_map(name); in rc_map_get()
106 if (!map) { in rc_map_get()
107 int rc = request_module("%s", name); in rc_map_get() local
108 if (rc < 0) { in rc_map_get()
109 pr_err("Couldn't load IR keymap %s\n", name); in rc_map_get()
114 map = seek_rc_map(name); in rc_map_get()
117 if (!map) { in rc_map_get()
118 pr_err("IR keymap %s not found\n", name); in rc_map_get()
122 printk(KERN_INFO "Registered IR keymap %s\n", map->map.name); in rc_map_get()
124 return &map->map; in rc_map_get()
128 int rc_map_register(struct rc_map_list *map) in rc_map_register() argument
131 list_add_tail(&map->list, &rc_map_list); in rc_map_register()
137 void rc_map_unregister(struct rc_map_list *map) in rc_map_unregister() argument
140 list_del(&map->list); in rc_map_unregister()
151 .map = {
155 .name = RC_MAP_EMPTY,
160 * ir_create_table() - initializes a scancode table
163 * @name: name to assign to the table
173 const char *name, u64 rc_proto, size_t size) in ir_create_table() argument
175 rc_map->name = kstrdup(name, GFP_KERNEL); in ir_create_table()
176 if (!rc_map->name) in ir_create_table()
177 return -ENOMEM; in ir_create_table()
178 rc_map->rc_proto = rc_proto; in ir_create_table()
179 rc_map->alloc = roundup_pow_of_two(size * sizeof(struct rc_map_table)); in ir_create_table()
180 rc_map->size = rc_map->alloc / sizeof(struct rc_map_table); in ir_create_table()
181 rc_map->scan = kmalloc(rc_map->alloc, GFP_KERNEL); in ir_create_table()
182 if (!rc_map->scan) { in ir_create_table()
183 kfree(rc_map->name); in ir_create_table()
184 rc_map->name = NULL; in ir_create_table()
185 return -ENOMEM; in ir_create_table()
188 dev_dbg(&dev->dev, "Allocated space for %u keycode entries (%u bytes)\n", in ir_create_table()
189 rc_map->size, rc_map->alloc); in ir_create_table()
194 * ir_free_table() - frees memory allocated by a scancode table
202 rc_map->size = 0; in ir_free_table()
203 kfree(rc_map->name); in ir_free_table()
204 rc_map->name = NULL; in ir_free_table()
205 kfree(rc_map->scan); in ir_free_table()
206 rc_map->scan = NULL; in ir_free_table()
210 * ir_resize_table() - resizes a scancode table if necessary
223 unsigned int oldalloc = rc_map->alloc; in ir_resize_table()
225 struct rc_map_table *oldscan = rc_map->scan; in ir_resize_table()
228 if (rc_map->size == rc_map->len) { in ir_resize_table()
229 /* All entries in use -> grow keytable */ in ir_resize_table()
230 if (rc_map->alloc >= IR_TAB_MAX_SIZE) in ir_resize_table()
231 return -ENOMEM; in ir_resize_table()
234 dev_dbg(&dev->dev, "Growing table to %u bytes\n", newalloc); in ir_resize_table()
237 if ((rc_map->len * 3 < rc_map->size) && (oldalloc > IR_TAB_MIN_SIZE)) { in ir_resize_table()
238 /* Less than 1/3 of entries in use -> shrink keytable */ in ir_resize_table()
240 dev_dbg(&dev->dev, "Shrinking table to %u bytes\n", newalloc); in ir_resize_table()
248 return -ENOMEM; in ir_resize_table()
250 memcpy(newscan, rc_map->scan, rc_map->len * sizeof(struct rc_map_table)); in ir_resize_table()
251 rc_map->scan = newscan; in ir_resize_table()
252 rc_map->alloc = newalloc; in ir_resize_table()
253 rc_map->size = rc_map->alloc / sizeof(struct rc_map_table); in ir_resize_table()
259 * ir_update_mapping() - set a keycode in the scancode->keycode table
265 * This routine is used to update scancode->keycode mapping at given
276 int old_keycode = rc_map->scan[index].keycode; in ir_update_mapping()
281 dev_dbg(&dev->dev, "#%d: Deleting scan 0x%04x\n", in ir_update_mapping()
282 index, rc_map->scan[index].scancode); in ir_update_mapping()
283 rc_map->len--; in ir_update_mapping()
284 memmove(&rc_map->scan[index], &rc_map->scan[index+ 1], in ir_update_mapping()
285 (rc_map->len - index) * sizeof(struct rc_map_table)); in ir_update_mapping()
287 dev_dbg(&dev->dev, "#%d: %s scan 0x%04x with key 0x%04x\n", in ir_update_mapping()
290 rc_map->scan[index].scancode, new_keycode); in ir_update_mapping()
291 rc_map->scan[index].keycode = new_keycode; in ir_update_mapping()
292 __set_bit(new_keycode, dev->input_dev->keybit); in ir_update_mapping()
297 __clear_bit(old_keycode, dev->input_dev->keybit); in ir_update_mapping()
299 for (i = 0; i < rc_map->len; i++) { in ir_update_mapping()
300 if (rc_map->scan[i].keycode == old_keycode) { in ir_update_mapping()
301 __set_bit(old_keycode, dev->input_dev->keybit); in ir_update_mapping()
314 * ir_establish_scancode() - set a keycode in the scancode->keycode table
326 * or -1U in case of failure.
336 * Unfortunately, some hardware-based IR decoders don't provide in ir_establish_scancode()
343 if (dev->scancode_mask) in ir_establish_scancode()
344 scancode &= dev->scancode_mask; in ir_establish_scancode()
347 for (i = 0; i < rc_map->len; i++) { in ir_establish_scancode()
348 if (rc_map->scan[i].scancode == scancode) in ir_establish_scancode()
352 if (rc_map->scan[i].scancode >= scancode) in ir_establish_scancode()
357 if (rc_map->size == rc_map->len) { in ir_establish_scancode()
359 return -1U; in ir_establish_scancode()
363 if (i < rc_map->len) in ir_establish_scancode()
364 memmove(&rc_map->scan[i + 1], &rc_map->scan[i], in ir_establish_scancode()
365 (rc_map->len - i) * sizeof(struct rc_map_table)); in ir_establish_scancode()
366 rc_map->scan[i].scancode = scancode; in ir_establish_scancode()
367 rc_map->scan[i].keycode = KEY_RESERVED; in ir_establish_scancode()
368 rc_map->len++; in ir_establish_scancode()
374 * ir_setkeycode() - set a keycode in the scancode->keycode table
381 * return: -EINVAL if the keycode could not be inserted, otherwise zero.
388 struct rc_map *rc_map = &rdev->rc_map; in ir_setkeycode()
394 spin_lock_irqsave(&rc_map->lock, flags); in ir_setkeycode()
396 if (ke->flags & INPUT_KEYMAP_BY_INDEX) { in ir_setkeycode()
397 index = ke->index; in ir_setkeycode()
398 if (index >= rc_map->len) { in ir_setkeycode()
399 retval = -EINVAL; in ir_setkeycode()
408 if (index >= rc_map->len) { in ir_setkeycode()
409 retval = -ENOMEM; in ir_setkeycode()
414 *old_keycode = ir_update_mapping(rdev, rc_map, index, ke->keycode); in ir_setkeycode()
417 spin_unlock_irqrestore(&rc_map->lock, flags); in ir_setkeycode()
422 * ir_setkeytable() - sets several entries in the scancode->keycode table
428 * return: -ENOMEM if all keycodes could not be inserted, otherwise zero.
433 struct rc_map *rc_map = &dev->rc_map; in ir_setkeytable()
435 int rc; in ir_setkeytable() local
437 rc = ir_create_table(dev, rc_map, from->name, from->rc_proto, in ir_setkeytable()
438 from->size); in ir_setkeytable()
439 if (rc) in ir_setkeytable()
440 return rc; in ir_setkeytable()
442 for (i = 0; i < from->size; i++) { in ir_setkeytable()
444 from->scan[i].scancode, false); in ir_setkeytable()
445 if (index >= rc_map->len) { in ir_setkeytable()
446 rc = -ENOMEM; in ir_setkeytable()
451 from->scan[i].keycode); in ir_setkeytable()
454 if (rc) in ir_setkeytable()
457 return rc; in ir_setkeytable()
465 if (*scancode < e->scancode) in rc_map_cmp()
466 return -1; in rc_map_cmp()
467 else if (*scancode > e->scancode) in rc_map_cmp()
473 * ir_lookup_by_scancode() - locate mapping by scancode
477 * This routine performs binary search in RC keykeymap table for
480 * return: index in the table, -1U if not found
487 res = bsearch(&scancode, rc_map->scan, rc_map->len, in ir_lookup_by_scancode()
490 return -1U; in ir_lookup_by_scancode()
492 return res - rc_map->scan; in ir_lookup_by_scancode()
496 * ir_getkeycode() - get a keycode from the scancode->keycode table
508 struct rc_map *rc_map = &rdev->rc_map; in ir_getkeycode()
515 spin_lock_irqsave(&rc_map->lock, flags); in ir_getkeycode()
517 if (ke->flags & INPUT_KEYMAP_BY_INDEX) { in ir_getkeycode()
518 index = ke->index; in ir_getkeycode()
527 if (index < rc_map->len) { in ir_getkeycode()
528 entry = &rc_map->scan[index]; in ir_getkeycode()
530 ke->index = index; in ir_getkeycode()
531 ke->keycode = entry->keycode; in ir_getkeycode()
532 ke->len = sizeof(entry->scancode); in ir_getkeycode()
533 memcpy(ke->scancode, &entry->scancode, sizeof(entry->scancode)); in ir_getkeycode()
535 } else if (!(ke->flags & INPUT_KEYMAP_BY_INDEX)) { in ir_getkeycode()
541 ke->index = index; in ir_getkeycode()
542 ke->keycode = KEY_RESERVED; in ir_getkeycode()
544 retval = -EINVAL; in ir_getkeycode()
551 spin_unlock_irqrestore(&rc_map->lock, flags); in ir_getkeycode()
556 * rc_g_keycode_from_table() - gets the keycode that corresponds to a scancode
568 struct rc_map *rc_map = &dev->rc_map; in rc_g_keycode_from_table()
573 spin_lock_irqsave(&rc_map->lock, flags); in rc_g_keycode_from_table()
576 keycode = index < rc_map->len ? in rc_g_keycode_from_table()
577 rc_map->scan[index].keycode : KEY_RESERVED; in rc_g_keycode_from_table()
579 spin_unlock_irqrestore(&rc_map->lock, flags); in rc_g_keycode_from_table()
582 dev_dbg(&dev->dev, "%s: scancode 0x%04x keycode 0x%02x\n", in rc_g_keycode_from_table()
583 dev->device_name, scancode, keycode); in rc_g_keycode_from_table()
590 * ir_do_keyup() - internal function to signal the release of a keypress
599 if (!dev->keypressed) in ir_do_keyup()
602 dev_dbg(&dev->dev, "keyup key 0x%04x\n", dev->last_keycode); in ir_do_keyup()
603 del_timer(&dev->timer_repeat); in ir_do_keyup()
604 input_report_key(dev->input_dev, dev->last_keycode, 0); in ir_do_keyup()
607 input_sync(dev->input_dev); in ir_do_keyup()
608 dev->keypressed = false; in ir_do_keyup()
612 * rc_keyup() - signals the release of a keypress
622 spin_lock_irqsave(&dev->keylock, flags); in rc_keyup()
624 spin_unlock_irqrestore(&dev->keylock, flags); in rc_keyup()
629 * ir_timer_keyup() - generates a keyup event after a timeout
642 * ir->keyup_jiffies is used to prevent a race condition if a in ir_timer_keyup()
648 * to allow the input subsystem to do its auto-repeat magic or in ir_timer_keyup()
651 spin_lock_irqsave(&dev->keylock, flags); in ir_timer_keyup()
652 if (time_is_before_eq_jiffies(dev->keyup_jiffies)) in ir_timer_keyup()
654 spin_unlock_irqrestore(&dev->keylock, flags); in ir_timer_keyup()
658 * ir_timer_repeat() - generates a repeat event after a timeout
668 struct input_dev *input = dev->input_dev; in ir_timer_repeat()
671 spin_lock_irqsave(&dev->keylock, flags); in ir_timer_repeat()
672 if (dev->keypressed) { in ir_timer_repeat()
673 input_event(input, EV_KEY, dev->last_keycode, 2); in ir_timer_repeat()
675 if (input->rep[REP_PERIOD]) in ir_timer_repeat()
676 mod_timer(&dev->timer_repeat, jiffies + in ir_timer_repeat()
677 msecs_to_jiffies(input->rep[REP_PERIOD])); in ir_timer_repeat()
679 spin_unlock_irqrestore(&dev->keylock, flags); in ir_timer_repeat()
691 * rc_repeat() - signals that a key is still pressed
701 unsigned int timeout = nsecs_to_jiffies(dev->timeout) + in rc_repeat()
702 msecs_to_jiffies(repeat_period(dev->last_protocol)); in rc_repeat()
704 .scancode = dev->last_scancode, .rc_proto = dev->last_protocol, in rc_repeat()
705 .keycode = dev->keypressed ? dev->last_keycode : KEY_RESERVED, in rc_repeat()
707 (dev->last_toggle ? LIRC_SCANCODE_FLAG_TOGGLE : 0) in rc_repeat()
710 if (dev->allowed_protocols != RC_PROTO_BIT_CEC) in rc_repeat()
713 spin_lock_irqsave(&dev->keylock, flags); in rc_repeat()
715 input_event(dev->input_dev, EV_MSC, MSC_SCAN, dev->last_scancode); in rc_repeat()
716 input_sync(dev->input_dev); in rc_repeat()
718 if (dev->keypressed) { in rc_repeat()
719 dev->keyup_jiffies = jiffies + timeout; in rc_repeat()
720 mod_timer(&dev->timer_keyup, dev->keyup_jiffies); in rc_repeat()
723 spin_unlock_irqrestore(&dev->keylock, flags); in rc_repeat()
728 * ir_do_keydown() - internal function to process a keypress
741 bool new_event = (!dev->keypressed || in ir_do_keydown()
742 dev->last_protocol != protocol || in ir_do_keydown()
743 dev->last_scancode != scancode || in ir_do_keydown()
744 dev->last_toggle != toggle); in ir_do_keydown()
751 if (dev->allowed_protocols != RC_PROTO_BIT_CEC) in ir_do_keydown()
754 if (new_event && dev->keypressed) in ir_do_keydown()
757 input_event(dev->input_dev, EV_MSC, MSC_SCAN, scancode); in ir_do_keydown()
759 dev->last_protocol = protocol; in ir_do_keydown()
760 dev->last_scancode = scancode; in ir_do_keydown()
761 dev->last_toggle = toggle; in ir_do_keydown()
762 dev->last_keycode = keycode; in ir_do_keydown()
766 dev->keypressed = true; in ir_do_keydown()
768 dev_dbg(&dev->dev, "%s: key down event, key 0x%04x, protocol 0x%04x, scancode 0x%08x\n", in ir_do_keydown()
769 dev->device_name, keycode, protocol, scancode); in ir_do_keydown()
770 input_report_key(dev->input_dev, keycode, 1); in ir_do_keydown()
778 * is non-zero. Otherwise, the input layer will generate repeat in ir_do_keydown()
782 dev->allowed_protocols == RC_PROTO_BIT_CEC && in ir_do_keydown()
783 !timer_pending(&dev->timer_repeat) && in ir_do_keydown()
784 dev->input_dev->rep[REP_PERIOD] && in ir_do_keydown()
785 !dev->input_dev->rep[REP_DELAY]) { in ir_do_keydown()
786 input_event(dev->input_dev, EV_KEY, keycode, 2); in ir_do_keydown()
787 mod_timer(&dev->timer_repeat, jiffies + in ir_do_keydown()
788 msecs_to_jiffies(dev->input_dev->rep[REP_PERIOD])); in ir_do_keydown()
791 input_sync(dev->input_dev); in ir_do_keydown()
795 * rc_keydown() - generates input event for a key press
811 spin_lock_irqsave(&dev->keylock, flags); in rc_keydown()
814 if (dev->keypressed) { in rc_keydown()
815 dev->keyup_jiffies = jiffies + nsecs_to_jiffies(dev->timeout) + in rc_keydown()
817 mod_timer(&dev->timer_keyup, dev->keyup_jiffies); in rc_keydown()
819 spin_unlock_irqrestore(&dev->keylock, flags); in rc_keydown()
824 * rc_keydown_notimeout() - generates input event for a key press without
841 spin_lock_irqsave(&dev->keylock, flags); in rc_keydown_notimeout()
843 spin_unlock_irqrestore(&dev->keylock, flags); in rc_keydown_notimeout()
848 * rc_validate_scancode() - checks that a scancode is valid for a protocol.
857 * NECX has a 16-bit address; if the lower 8 bits match the upper in rc_validate_scancode()
874 * If the customer code (top 32-bit) is 0x800f, it is MCE else it in rc_validate_scancode()
875 * is regular mode-6a 32 bit in rc_validate_scancode()
893 * rc_validate_filter() - checks that the scancode and mask are valid and
898 * return: 0 or -EINVAL if the filter is not valid
903 u32 mask, s = filter->data; in rc_validate_filter()
904 enum rc_proto protocol = dev->wakeup_protocol; in rc_validate_filter()
907 return -EINVAL; in rc_validate_filter()
912 return -EINVAL; in rc_validate_filter()
914 filter->data &= mask; in rc_validate_filter()
915 filter->mask &= mask; in rc_validate_filter()
920 if (dev->encode_wakeup && filter->mask != 0 && filter->mask != mask) in rc_validate_filter()
921 return -EINVAL; in rc_validate_filter()
931 return -EINVAL; in rc_open()
933 mutex_lock(&rdev->lock); in rc_open()
935 if (!rdev->registered) { in rc_open()
936 rval = -ENODEV; in rc_open()
938 if (!rdev->users++ && rdev->open) in rc_open()
939 rval = rdev->open(rdev); in rc_open()
942 rdev->users--; in rc_open()
945 mutex_unlock(&rdev->lock); in rc_open()
960 mutex_lock(&rdev->lock); in rc_close()
962 if (!--rdev->users && rdev->close && rdev->registered) in rc_close()
963 rdev->close(rdev); in rc_close()
965 mutex_unlock(&rdev->lock); in rc_close()
975 /* class for /sys/class/rc */
978 return kasprintf(GFP_KERNEL, "rc/%s", dev_name(dev)); in rc_devnode()
982 .name = "rc",
993 const char *name; member
1000 RC_PROTO_BIT_RC5X_20, "rc-5", "ir-rc5-decoder" },
1003 RC_PROTO_BIT_NEC32, "nec", "ir-nec-decoder" },
1008 RC_PROTO_BIT_RC6_MCE, "rc-6", "ir-rc6-decoder" },
1009 { RC_PROTO_BIT_JVC, "jvc", "ir-jvc-decoder" },
1012 RC_PROTO_BIT_SONY20, "sony", "ir-sony-decoder" },
1013 { RC_PROTO_BIT_RC5_SZ, "rc-5-sz", "ir-rc5-decoder" },
1014 { RC_PROTO_BIT_SANYO, "sanyo", "ir-sanyo-decoder" },
1015 { RC_PROTO_BIT_SHARP, "sharp", "ir-sharp-decoder" },
1017 RC_PROTO_BIT_MCIR2_MSE, "mce_kbd", "ir-mce_kbd-decoder" },
1018 { RC_PROTO_BIT_XMP, "xmp", "ir-xmp-decoder" },
1020 { RC_PROTO_BIT_IMON, "imon", "ir-imon-decoder" },
1024 * struct rc_filter_attribute - Device attribute relating to a filter type.
1044 * show_protocols() - shows the current IR protocol(s)
1050 * it is trigged by reading /sys/class/rc/rc?/protocols.
1054 * dev->lock is taken to guard against races between
1065 mutex_lock(&dev->lock); in show_protocols()
1067 enabled = dev->enabled_protocols; in show_protocols()
1068 allowed = dev->allowed_protocols; in show_protocols()
1069 if (dev->raw && !allowed) in show_protocols()
1072 mutex_unlock(&dev->lock); in show_protocols()
1074 dev_dbg(&dev->dev, "%s: allowed - 0x%llx, enabled - 0x%llx\n", in show_protocols()
1079 tmp += sprintf(tmp, "[%s] ", proto_names[i].name); in show_protocols()
1081 tmp += sprintf(tmp, "%s ", proto_names[i].name); in show_protocols()
1088 if (dev->driver_type == RC_DRIVER_IR_RAW) in show_protocols()
1093 tmp--; in show_protocols()
1096 return tmp + 1 - buf; in show_protocols()
1100 * parse_protocol_change() - parses a protocol change request
1106 * Writing "-proto" will remove a protocol from protocol mask.
1128 } else if (*tmp == '-') { in parse_protocol_change()
1138 if (!strcasecmp(tmp, proto_names[i].name)) { in parse_protocol_change()
1148 dev_dbg(&dev->dev, "Unknown protocol: '%s'\n", in parse_protocol_change()
1150 return -EINVAL; in parse_protocol_change()
1165 dev_dbg(&dev->dev, "Protocol not specified\n"); in parse_protocol_change()
1166 return -EINVAL; in parse_protocol_change()
1189 proto_names[i].name); in ir_raw_load_modules()
1208 proto_names[i].name); in ir_raw_load_modules()
1214 * store_protocols() - changes the current/wakeup IR protocol(s)
1221 * It is trigged by writing to /sys/class/rc/rc?/[wakeup_]protocols.
1225 * dev->lock is taken to guard against races between
1236 ssize_t rc; in store_protocols() local
1238 dev_dbg(&dev->dev, "Normal protocol change requested\n"); in store_protocols()
1239 current_protocols = &dev->enabled_protocols; in store_protocols()
1240 filter = &dev->scancode_filter; in store_protocols()
1242 if (!dev->change_protocol) { in store_protocols()
1243 dev_dbg(&dev->dev, "Protocol switching not supported\n"); in store_protocols()
1244 return -EINVAL; in store_protocols()
1247 mutex_lock(&dev->lock); in store_protocols()
1248 if (!dev->registered) { in store_protocols()
1249 mutex_unlock(&dev->lock); in store_protocols()
1250 return -ENODEV; in store_protocols()
1255 rc = parse_protocol_change(dev, &new_protocols, buf); in store_protocols()
1256 if (rc < 0) in store_protocols()
1259 if (dev->driver_type == RC_DRIVER_IR_RAW) in store_protocols()
1262 rc = dev->change_protocol(dev, &new_protocols); in store_protocols()
1263 if (rc < 0) { in store_protocols()
1264 dev_dbg(&dev->dev, "Error setting protocols to 0x%llx\n", in store_protocols()
1271 dev_dbg(&dev->dev, "Protocols changed to 0x%llx\n", in store_protocols()
1282 if (dev->s_filter && filter->mask) { in store_protocols()
1284 rc = dev->s_filter(dev, filter); in store_protocols()
1286 rc = -1; in store_protocols()
1288 if (rc < 0) { in store_protocols()
1289 filter->data = 0; in store_protocols()
1290 filter->mask = 0; in store_protocols()
1291 dev->s_filter(dev, filter); in store_protocols()
1295 rc = len; in store_protocols()
1298 mutex_unlock(&dev->lock); in store_protocols()
1299 return rc; in store_protocols()
1303 * show_filter() - shows the current scancode filter value or mask
1309 * It is trigged by reading /sys/class/rc/rc?/[wakeup_]filter[_mask].
1314 * compared against input scancodes and non-matching scancodes are discarded.
1316 * dev->lock is taken to guard against races between
1328 mutex_lock(&dev->lock); in show_filter()
1330 if (fattr->type == RC_FILTER_NORMAL) in show_filter()
1331 filter = &dev->scancode_filter; in show_filter()
1333 filter = &dev->scancode_wakeup_filter; in show_filter()
1335 if (fattr->mask) in show_filter()
1336 val = filter->mask; in show_filter()
1338 val = filter->data; in show_filter()
1339 mutex_unlock(&dev->lock); in show_filter()
1345 * store_filter() - changes the scancode filter value
1352 * It is trigged by writing to /sys/class/rc/rc?/[wakeup_]filter[_mask].
1353 * Returns -EINVAL if an invalid filter value for the current protocol was
1358 * compared against input scancodes and non-matching scancodes are discarded.
1360 * dev->lock is taken to guard against races between
1378 if (fattr->type == RC_FILTER_NORMAL) { in store_filter()
1379 set_filter = dev->s_filter; in store_filter()
1380 filter = &dev->scancode_filter; in store_filter()
1382 set_filter = dev->s_wakeup_filter; in store_filter()
1383 filter = &dev->scancode_wakeup_filter; in store_filter()
1387 return -EINVAL; in store_filter()
1389 mutex_lock(&dev->lock); in store_filter()
1390 if (!dev->registered) { in store_filter()
1391 mutex_unlock(&dev->lock); in store_filter()
1392 return -ENODEV; in store_filter()
1396 if (fattr->mask) in store_filter()
1401 if (fattr->type == RC_FILTER_WAKEUP) { in store_filter()
1406 if (dev->wakeup_protocol != RC_PROTO_UNKNOWN) in store_filter()
1409 ret = -EINVAL; in store_filter()
1415 if (fattr->type == RC_FILTER_NORMAL && !dev->enabled_protocols && in store_filter()
1418 ret = -EINVAL; in store_filter()
1429 mutex_unlock(&dev->lock); in store_filter()
1434 * show_wakeup_protocols() - shows the wakeup IR protocol
1440 * it is trigged by reading /sys/class/rc/rc?/wakeup_protocols.
1444 * dev->lock is taken to guard against races between
1457 mutex_lock(&dev->lock); in show_wakeup_protocols()
1459 allowed = dev->allowed_wakeup_protocols; in show_wakeup_protocols()
1460 enabled = dev->wakeup_protocol; in show_wakeup_protocols()
1462 mutex_unlock(&dev->lock); in show_wakeup_protocols()
1464 dev_dbg(&dev->dev, "%s: allowed - 0x%llx, enabled - %d\n", in show_wakeup_protocols()
1470 tmp += sprintf(tmp, "[%s] ", protocols[i].name); in show_wakeup_protocols()
1472 tmp += sprintf(tmp, "%s ", protocols[i].name); in show_wakeup_protocols()
1477 tmp--; in show_wakeup_protocols()
1480 return tmp + 1 - buf; in show_wakeup_protocols()
1484 * store_wakeup_protocols() - changes the wakeup IR protocol(s)
1491 * It is trigged by writing to /sys/class/rc/rc?/wakeup_protocols.
1494 * dev->lock is taken to guard against races between
1503 ssize_t rc; in store_wakeup_protocols() local
1507 mutex_lock(&dev->lock); in store_wakeup_protocols()
1508 if (!dev->registered) { in store_wakeup_protocols()
1509 mutex_unlock(&dev->lock); in store_wakeup_protocols()
1510 return -ENODEV; in store_wakeup_protocols()
1513 allowed = dev->allowed_wakeup_protocols; in store_wakeup_protocols()
1520 sysfs_streq(buf, protocols[i].name)) { in store_wakeup_protocols()
1527 rc = -EINVAL; in store_wakeup_protocols()
1531 if (dev->encode_wakeup) { in store_wakeup_protocols()
1536 rc = -EINVAL; in store_wakeup_protocols()
1542 if (dev->wakeup_protocol != protocol) { in store_wakeup_protocols()
1543 dev->wakeup_protocol = protocol; in store_wakeup_protocols()
1544 dev_dbg(&dev->dev, "Wakeup protocol changed to %d\n", protocol); in store_wakeup_protocols()
1547 dev->scancode_wakeup_filter.data = 0x800f0000; in store_wakeup_protocols()
1549 dev->scancode_wakeup_filter.data = 0; in store_wakeup_protocols()
1550 dev->scancode_wakeup_filter.mask = 0; in store_wakeup_protocols()
1552 rc = dev->s_wakeup_filter(dev, &dev->scancode_wakeup_filter); in store_wakeup_protocols()
1553 if (rc == 0) in store_wakeup_protocols()
1554 rc = len; in store_wakeup_protocols()
1556 rc = len; in store_wakeup_protocols()
1560 mutex_unlock(&dev->lock); in store_wakeup_protocols()
1561 return rc; in store_wakeup_protocols()
1576 mutex_lock(&dev->lock); in rc_dev_uevent()
1578 if (!dev->registered) in rc_dev_uevent()
1579 ret = -ENODEV; in rc_dev_uevent()
1580 if (ret == 0 && dev->rc_map.name) in rc_dev_uevent()
1581 ret = add_uevent_var(env, "NAME=%s", dev->rc_map.name); in rc_dev_uevent()
1582 if (ret == 0 && dev->driver_name) in rc_dev_uevent()
1583 ret = add_uevent_var(env, "DRV_NAME=%s", dev->driver_name); in rc_dev_uevent()
1584 if (ret == 0 && dev->device_name) in rc_dev_uevent()
1585 ret = add_uevent_var(env, "DEV_NAME=%s", dev->device_name); in rc_dev_uevent()
1587 mutex_unlock(&dev->lock); in rc_dev_uevent()
1663 dev->input_dev = input_allocate_device(); in rc_allocate_device()
1664 if (!dev->input_dev) { in rc_allocate_device()
1669 dev->input_dev->getkeycode = ir_getkeycode; in rc_allocate_device()
1670 dev->input_dev->setkeycode = ir_setkeycode; in rc_allocate_device()
1671 input_set_drvdata(dev->input_dev, dev); in rc_allocate_device()
1673 dev->timeout = IR_DEFAULT_TIMEOUT; in rc_allocate_device()
1674 timer_setup(&dev->timer_keyup, ir_timer_keyup, 0); in rc_allocate_device()
1675 timer_setup(&dev->timer_repeat, ir_timer_repeat, 0); in rc_allocate_device()
1677 spin_lock_init(&dev->rc_map.lock); in rc_allocate_device()
1678 spin_lock_init(&dev->keylock); in rc_allocate_device()
1680 mutex_init(&dev->lock); in rc_allocate_device()
1682 dev->dev.type = &rc_dev_type; in rc_allocate_device()
1683 dev->dev.class = &rc_class; in rc_allocate_device()
1684 device_initialize(&dev->dev); in rc_allocate_device()
1686 dev->driver_type = type; in rc_allocate_device()
1698 input_free_device(dev->input_dev); in rc_free_device()
1700 put_device(&dev->dev); in rc_free_device()
1717 struct rc_dev **dr, *rc; in devm_rc_allocate_device() local
1723 rc = rc_allocate_device(type); in devm_rc_allocate_device()
1724 if (!rc) { in devm_rc_allocate_device()
1729 rc->dev.parent = dev; in devm_rc_allocate_device()
1730 rc->managed_alloc = true; in devm_rc_allocate_device()
1731 *dr = rc; in devm_rc_allocate_device()
1734 return rc; in devm_rc_allocate_device()
1740 int rc; in rc_prepare_rx_device() local
1744 if (!dev->map_name) in rc_prepare_rx_device()
1745 return -EINVAL; in rc_prepare_rx_device()
1747 rc_map = rc_map_get(dev->map_name); in rc_prepare_rx_device()
1750 if (!rc_map || !rc_map->scan || rc_map->size == 0) in rc_prepare_rx_device()
1751 return -EINVAL; in rc_prepare_rx_device()
1753 rc = ir_setkeytable(dev, rc_map); in rc_prepare_rx_device()
1754 if (rc) in rc_prepare_rx_device()
1755 return rc; in rc_prepare_rx_device()
1757 rc_proto = BIT_ULL(rc_map->rc_proto); in rc_prepare_rx_device()
1759 if (dev->driver_type == RC_DRIVER_SCANCODE && !dev->change_protocol) in rc_prepare_rx_device()
1760 dev->enabled_protocols = dev->allowed_protocols; in rc_prepare_rx_device()
1762 if (dev->driver_type == RC_DRIVER_IR_RAW) in rc_prepare_rx_device()
1765 if (dev->change_protocol) { in rc_prepare_rx_device()
1766 rc = dev->change_protocol(dev, &rc_proto); in rc_prepare_rx_device()
1767 if (rc < 0) in rc_prepare_rx_device()
1769 dev->enabled_protocols = rc_proto; in rc_prepare_rx_device()
1772 set_bit(EV_KEY, dev->input_dev->evbit); in rc_prepare_rx_device()
1773 set_bit(EV_REP, dev->input_dev->evbit); in rc_prepare_rx_device()
1774 set_bit(EV_MSC, dev->input_dev->evbit); in rc_prepare_rx_device()
1775 set_bit(MSC_SCAN, dev->input_dev->mscbit); in rc_prepare_rx_device()
1776 if (dev->open) in rc_prepare_rx_device()
1777 dev->input_dev->open = ir_open; in rc_prepare_rx_device()
1778 if (dev->close) in rc_prepare_rx_device()
1779 dev->input_dev->close = ir_close; in rc_prepare_rx_device()
1781 dev->input_dev->dev.parent = &dev->dev; in rc_prepare_rx_device()
1782 memcpy(&dev->input_dev->id, &dev->input_id, sizeof(dev->input_id)); in rc_prepare_rx_device()
1783 dev->input_dev->phys = dev->input_phys; in rc_prepare_rx_device()
1784 dev->input_dev->name = dev->device_name; in rc_prepare_rx_device()
1789 ir_free_table(&dev->rc_map); in rc_prepare_rx_device()
1791 return rc; in rc_prepare_rx_device()
1796 int rc; in rc_setup_rx_device() local
1799 rc = input_register_device(dev->input_dev); in rc_setup_rx_device()
1800 if (rc) in rc_setup_rx_device()
1801 return rc; in rc_setup_rx_device()
1809 if (dev->allowed_protocols == RC_PROTO_BIT_CEC) in rc_setup_rx_device()
1810 dev->input_dev->rep[REP_DELAY] = 0; in rc_setup_rx_device()
1812 dev->input_dev->rep[REP_DELAY] = 500; in rc_setup_rx_device()
1815 * As a repeat event on protocols like RC-5 and NEC take as long as in rc_setup_rx_device()
1819 dev->input_dev->rep[REP_PERIOD] = 125; in rc_setup_rx_device()
1829 if (dev->input_dev) { in rc_free_rx_device()
1830 input_unregister_device(dev->input_dev); in rc_free_rx_device()
1831 dev->input_dev = NULL; in rc_free_rx_device()
1834 ir_free_table(&dev->rc_map); in rc_free_rx_device()
1842 int rc; in rc_register_device() local
1845 return -EINVAL; in rc_register_device()
1851 dev->minor = minor; in rc_register_device()
1852 dev_set_name(&dev->dev, "rc%u", dev->minor); in rc_register_device()
1853 dev_set_drvdata(&dev->dev, dev); in rc_register_device()
1855 dev->dev.groups = dev->sysfs_groups; in rc_register_device()
1856 if (dev->driver_type == RC_DRIVER_SCANCODE && !dev->change_protocol) in rc_register_device()
1857 dev->sysfs_groups[attr++] = &rc_dev_ro_protocol_attr_grp; in rc_register_device()
1858 else if (dev->driver_type != RC_DRIVER_IR_RAW_TX) in rc_register_device()
1859 dev->sysfs_groups[attr++] = &rc_dev_rw_protocol_attr_grp; in rc_register_device()
1860 if (dev->s_filter) in rc_register_device()
1861 dev->sysfs_groups[attr++] = &rc_dev_filter_attr_grp; in rc_register_device()
1862 if (dev->s_wakeup_filter) in rc_register_device()
1863 dev->sysfs_groups[attr++] = &rc_dev_wakeup_filter_attr_grp; in rc_register_device()
1864 dev->sysfs_groups[attr++] = NULL; in rc_register_device()
1866 if (dev->driver_type == RC_DRIVER_IR_RAW) { in rc_register_device()
1867 rc = ir_raw_event_prepare(dev); in rc_register_device()
1868 if (rc < 0) in rc_register_device()
1872 if (dev->driver_type != RC_DRIVER_IR_RAW_TX) { in rc_register_device()
1873 rc = rc_prepare_rx_device(dev); in rc_register_device()
1874 if (rc) in rc_register_device()
1878 rc = device_add(&dev->dev); in rc_register_device()
1879 if (rc) in rc_register_device()
1882 path = kobject_get_path(&dev->dev.kobj, GFP_KERNEL); in rc_register_device()
1883 dev_info(&dev->dev, "%s as %s\n", in rc_register_device()
1884 dev->device_name ?: "Unspecified device", path ?: "N/A"); in rc_register_device()
1887 dev->registered = true; in rc_register_device()
1895 if (dev->allowed_protocols != RC_PROTO_BIT_CEC) { in rc_register_device()
1896 rc = ir_lirc_register(dev); in rc_register_device()
1897 if (rc < 0) in rc_register_device()
1901 if (dev->driver_type != RC_DRIVER_IR_RAW_TX) { in rc_register_device()
1902 rc = rc_setup_rx_device(dev); in rc_register_device()
1903 if (rc) in rc_register_device()
1907 if (dev->driver_type == RC_DRIVER_IR_RAW) { in rc_register_device()
1908 rc = ir_raw_event_register(dev); in rc_register_device()
1909 if (rc < 0) in rc_register_device()
1913 dev_dbg(&dev->dev, "Registered rc%u (driver: %s)\n", dev->minor, in rc_register_device()
1914 dev->driver_name ? dev->driver_name : "unknown"); in rc_register_device()
1921 if (dev->allowed_protocols != RC_PROTO_BIT_CEC) in rc_register_device()
1924 device_del(&dev->dev); in rc_register_device()
1926 ir_free_table(&dev->rc_map); in rc_register_device()
1931 return rc; in rc_register_device()
1947 return -ENOMEM; in devm_rc_register_device()
1967 if (dev->driver_type == RC_DRIVER_IR_RAW) in rc_unregister_device()
1970 del_timer_sync(&dev->timer_keyup); in rc_unregister_device()
1971 del_timer_sync(&dev->timer_repeat); in rc_unregister_device()
1973 mutex_lock(&dev->lock); in rc_unregister_device()
1974 if (dev->users && dev->close) in rc_unregister_device()
1975 dev->close(dev); in rc_unregister_device()
1976 dev->registered = false; in rc_unregister_device()
1977 mutex_unlock(&dev->lock); in rc_unregister_device()
1982 * lirc device should be freed with dev->registered = false, so in rc_unregister_device()
1985 if (dev->allowed_protocols != RC_PROTO_BIT_CEC) in rc_unregister_device()
1988 device_del(&dev->dev); in rc_unregister_device()
1990 ida_simple_remove(&rc_ida, dev->minor); in rc_unregister_device()
1992 if (!dev->managed_alloc) in rc_unregister_device()
1999 * Init/exit code for the module. Basically, creates/removes /sys/class/rc
2004 int rc = class_register(&rc_class); in rc_core_init() local
2005 if (rc) { in rc_core_init()
2006 pr_err("rc_core: unable to register rc class\n"); in rc_core_init()
2007 return rc; in rc_core_init()
2010 rc = lirc_dev_init(); in rc_core_init()
2011 if (rc) { in rc_core_init()
2017 led_trigger_register_simple("rc-feedback", &led_feedback); in rc_core_init()