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",
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 },
87 /* Used to keep track of rc devices */
90 static struct rc_map_list *seek_rc_map(const char *name) in seek_rc_map() argument
92 struct rc_map_list *map = NULL; in seek_rc_map() local
95 list_for_each_entry(map, &rc_map_list, list) { in seek_rc_map()
96 if (!strcmp(name, map->map.name)) { in seek_rc_map()
98 return map; in seek_rc_map()
106 struct rc_map *rc_map_get(const char *name) in rc_map_get() argument
109 struct rc_map_list *map; in rc_map_get() local
111 map = seek_rc_map(name); in rc_map_get()
113 if (!map) { in rc_map_get()
114 int rc = request_module("%s", name); in rc_map_get() local
115 if (rc < 0) { in rc_map_get()
116 pr_err("Couldn't load IR keymap %s\n", name); in rc_map_get()
121 map = seek_rc_map(name); in rc_map_get()
124 if (!map) { in rc_map_get()
125 pr_err("IR keymap %s not found\n", name); in rc_map_get()
129 printk(KERN_INFO "Registered IR keymap %s\n", map->map.name); in rc_map_get()
131 return &map->map; in rc_map_get()
135 int rc_map_register(struct rc_map_list *map) in rc_map_register() argument
138 list_add_tail(&map->list, &rc_map_list); in rc_map_register()
144 void rc_map_unregister(struct rc_map_list *map) in rc_map_unregister() argument
147 list_del(&map->list); in rc_map_unregister()
158 .map = {
162 .name = RC_MAP_EMPTY,
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
205 * @name: name to assign to the table
215 const char *name, u64 rc_proto, size_t size) in ir_create_table() argument
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()
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()
475 int rc; in ir_setkeytable() local
477 rc = ir_create_table(dev, rc_map, from->name, from->rc_proto, in ir_setkeytable()
478 from->size); in ir_setkeytable()
479 if (rc) in ir_setkeytable()
480 return rc; 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()
494 if (rc) in ir_setkeytable()
497 return rc; 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
517 * This routine performs binary search in RC keykeymap table for
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()
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()
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
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
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()
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
740 unsigned int timeout = nsecs_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()
793 if (dev->allowed_protocols != RC_PROTO_BIT_CEC) in ir_do_keydown()
796 if (new_event && dev->keypressed) in ir_do_keydown()
800 input_event(dev->input_dev, EV_MSC, MSC_SCAN, scancode); in ir_do_keydown()
802 dev->last_protocol = protocol; in ir_do_keydown()
803 dev->last_scancode = scancode; in ir_do_keydown()
804 dev->last_toggle = toggle; in ir_do_keydown()
805 dev->last_keycode = keycode; in ir_do_keydown()
809 dev->keypressed = true; in ir_do_keydown()
811 dev_dbg(&dev->dev, "%s: key down event, key 0x%04x, protocol 0x%04x, scancode 0x%08llx\n", in ir_do_keydown()
812 dev->device_name, keycode, protocol, scancode); in ir_do_keydown()
813 input_report_key(dev->input_dev, keycode, 1); in ir_do_keydown()
821 * is non-zero. Otherwise, the input layer will generate repeat in ir_do_keydown()
825 dev->allowed_protocols == RC_PROTO_BIT_CEC && in ir_do_keydown()
826 !timer_pending(&dev->timer_repeat) && in ir_do_keydown()
827 dev->input_dev->rep[REP_PERIOD] && in ir_do_keydown()
828 !dev->input_dev->rep[REP_DELAY]) { in ir_do_keydown()
829 input_event(dev->input_dev, EV_KEY, keycode, 2); in ir_do_keydown()
830 mod_timer(&dev->timer_repeat, jiffies + in ir_do_keydown()
831 msecs_to_jiffies(dev->input_dev->rep[REP_PERIOD])); in ir_do_keydown()
834 input_sync(dev->input_dev); in ir_do_keydown()
838 * rc_keydown() - generates input event for a key press
854 spin_lock_irqsave(&dev->keylock, flags); in rc_keydown()
857 if (dev->keypressed) { in rc_keydown()
858 dev->keyup_jiffies = jiffies + nsecs_to_jiffies(dev->timeout) + in rc_keydown()
860 mod_timer(&dev->timer_keyup, dev->keyup_jiffies); in rc_keydown()
862 spin_unlock_irqrestore(&dev->keylock, flags); in rc_keydown()
867 * rc_keydown_notimeout() - generates input event for a key press without
884 spin_lock_irqsave(&dev->keylock, flags); in rc_keydown_notimeout()
886 spin_unlock_irqrestore(&dev->keylock, flags); in rc_keydown_notimeout()
891 * rc_validate_scancode() - checks that a scancode is valid for a protocol.
900 * NECX has a 16-bit address; if the lower 8 bits match the upper in rc_validate_scancode()
917 * If the customer code (top 32-bit) is 0x800f, it is MCE else it in rc_validate_scancode()
918 * is regular mode-6a 32 bit in rc_validate_scancode()
936 * rc_validate_filter() - checks that the scancode and mask are valid and
941 * return: 0 or -EINVAL if the filter is not valid
946 u32 mask, s = filter->data; in rc_validate_filter()
947 enum rc_proto protocol = dev->wakeup_protocol; in rc_validate_filter()
950 return -EINVAL; in rc_validate_filter()
955 return -EINVAL; in rc_validate_filter()
957 filter->data &= mask; in rc_validate_filter()
958 filter->mask &= mask; in rc_validate_filter()
963 if (dev->encode_wakeup && filter->mask != 0 && filter->mask != mask) in rc_validate_filter()
964 return -EINVAL; in rc_validate_filter()
974 return -EINVAL; in rc_open()
976 mutex_lock(&rdev->lock); in rc_open()
978 if (!rdev->registered) { in rc_open()
979 rval = -ENODEV; in rc_open()
981 if (!rdev->users++ && rdev->open) in rc_open()
982 rval = rdev->open(rdev); in rc_open()
985 rdev->users--; in rc_open()
988 mutex_unlock(&rdev->lock); in rc_open()
1003 mutex_lock(&rdev->lock); in rc_close()
1005 if (!--rdev->users && rdev->close && rdev->registered) in rc_close()
1006 rdev->close(rdev); in rc_close()
1008 mutex_unlock(&rdev->lock); in rc_close()
1018 /* class for /sys/class/rc */
1021 return kasprintf(GFP_KERNEL, "rc/%s", dev_name(dev)); in rc_devnode()
1025 .name = "rc",
1036 const char *name; member
1043 RC_PROTO_BIT_RC5X_20, "rc-5", "ir-rc5-decoder" },
1046 RC_PROTO_BIT_NEC32, "nec", "ir-nec-decoder" },
1051 RC_PROTO_BIT_RC6_MCE, "rc-6", "ir-rc6-decoder" },
1052 { RC_PROTO_BIT_JVC, "jvc", "ir-jvc-decoder" },
1055 RC_PROTO_BIT_SONY20, "sony", "ir-sony-decoder" },
1056 { RC_PROTO_BIT_RC5_SZ, "rc-5-sz", "ir-rc5-decoder" },
1057 { RC_PROTO_BIT_SANYO, "sanyo", "ir-sanyo-decoder" },
1058 { RC_PROTO_BIT_SHARP, "sharp", "ir-sharp-decoder" },
1060 RC_PROTO_BIT_MCIR2_MSE, "mce_kbd", "ir-mce_kbd-decoder" },
1061 { RC_PROTO_BIT_XMP, "xmp", "ir-xmp-decoder" },
1063 { RC_PROTO_BIT_IMON, "imon", "ir-imon-decoder" },
1066 RC_PROTO_BIT_RCMM32, "rc-mm", "ir-rcmm-decoder" },
1067 { RC_PROTO_BIT_XBOX_DVD, "xbox-dvd", NULL },
1071 * struct rc_filter_attribute - Device attribute relating to a filter type.
1091 * show_protocols() - shows the current IR protocol(s)
1097 * it is triggered by reading /sys/class/rc/rc?/protocols.
1101 * dev->lock is taken to guard against races between
1112 mutex_lock(&dev->lock); in show_protocols()
1114 enabled = dev->enabled_protocols; in show_protocols()
1115 allowed = dev->allowed_protocols; in show_protocols()
1116 if (dev->raw && !allowed) in show_protocols()
1119 mutex_unlock(&dev->lock); in show_protocols()
1121 dev_dbg(&dev->dev, "%s: allowed - 0x%llx, enabled - 0x%llx\n", in show_protocols()
1126 tmp += sprintf(tmp, "[%s] ", proto_names[i].name); in show_protocols()
1128 tmp += sprintf(tmp, "%s ", proto_names[i].name); in show_protocols()
1135 if (dev->driver_type == RC_DRIVER_IR_RAW) in show_protocols()
1140 tmp--; in show_protocols()
1143 return tmp + 1 - buf; in show_protocols()
1147 * parse_protocol_change() - parses a protocol change request
1153 * Writing "-proto" will remove a protocol from protocol mask.
1175 } else if (*tmp == '-') { in parse_protocol_change()
1185 if (!strcasecmp(tmp, proto_names[i].name)) { in parse_protocol_change()
1195 dev_dbg(&dev->dev, "Unknown protocol: '%s'\n", in parse_protocol_change()
1197 return -EINVAL; in parse_protocol_change()
1212 dev_dbg(&dev->dev, "Protocol not specified\n"); in parse_protocol_change()
1213 return -EINVAL; in parse_protocol_change()
1236 proto_names[i].name); in ir_raw_load_modules()
1255 proto_names[i].name); in ir_raw_load_modules()
1261 * store_protocols() - changes the current/wakeup IR protocol(s)
1268 * It is triggered by writing to /sys/class/rc/rc?/[wakeup_]protocols.
1272 * dev->lock is taken to guard against races between
1283 ssize_t rc; in store_protocols() local
1285 dev_dbg(&dev->dev, "Normal protocol change requested\n"); in store_protocols()
1286 current_protocols = &dev->enabled_protocols; in store_protocols()
1287 filter = &dev->scancode_filter; in store_protocols()
1289 if (!dev->change_protocol) { in store_protocols()
1290 dev_dbg(&dev->dev, "Protocol switching not supported\n"); in store_protocols()
1291 return -EINVAL; in store_protocols()
1294 mutex_lock(&dev->lock); in store_protocols()
1295 if (!dev->registered) { in store_protocols()
1296 mutex_unlock(&dev->lock); in store_protocols()
1297 return -ENODEV; in store_protocols()
1302 rc = parse_protocol_change(dev, &new_protocols, buf); in store_protocols()
1303 if (rc < 0) in store_protocols()
1306 if (dev->driver_type == RC_DRIVER_IR_RAW) in store_protocols()
1309 rc = dev->change_protocol(dev, &new_protocols); in store_protocols()
1310 if (rc < 0) { in store_protocols()
1311 dev_dbg(&dev->dev, "Error setting protocols to 0x%llx\n", in store_protocols()
1318 dev_dbg(&dev->dev, "Protocols changed to 0x%llx\n", in store_protocols()
1329 if (dev->s_filter && filter->mask) { in store_protocols()
1331 rc = dev->s_filter(dev, filter); in store_protocols()
1333 rc = -1; in store_protocols()
1335 if (rc < 0) { in store_protocols()
1336 filter->data = 0; in store_protocols()
1337 filter->mask = 0; in store_protocols()
1338 dev->s_filter(dev, filter); in store_protocols()
1342 rc = len; in store_protocols()
1345 mutex_unlock(&dev->lock); in store_protocols()
1346 return rc; in store_protocols()
1350 * show_filter() - shows the current scancode filter value or mask
1356 * It is triggered by reading /sys/class/rc/rc?/[wakeup_]filter[_mask].
1361 * compared against input scancodes and non-matching scancodes are discarded.
1363 * dev->lock is taken to guard against races between
1375 mutex_lock(&dev->lock); in show_filter()
1377 if (fattr->type == RC_FILTER_NORMAL) in show_filter()
1378 filter = &dev->scancode_filter; in show_filter()
1380 filter = &dev->scancode_wakeup_filter; in show_filter()
1382 if (fattr->mask) in show_filter()
1383 val = filter->mask; in show_filter()
1385 val = filter->data; in show_filter()
1386 mutex_unlock(&dev->lock); in show_filter()
1392 * store_filter() - changes the scancode filter value
1399 * It is triggered by writing to /sys/class/rc/rc?/[wakeup_]filter[_mask].
1400 * Returns -EINVAL if an invalid filter value for the current protocol was
1405 * compared against input scancodes and non-matching scancodes are discarded.
1407 * dev->lock is taken to guard against races between
1425 if (fattr->type == RC_FILTER_NORMAL) { in store_filter()
1426 set_filter = dev->s_filter; in store_filter()
1427 filter = &dev->scancode_filter; in store_filter()
1429 set_filter = dev->s_wakeup_filter; in store_filter()
1430 filter = &dev->scancode_wakeup_filter; in store_filter()
1434 return -EINVAL; in store_filter()
1436 mutex_lock(&dev->lock); in store_filter()
1437 if (!dev->registered) { in store_filter()
1438 mutex_unlock(&dev->lock); in store_filter()
1439 return -ENODEV; in store_filter()
1443 if (fattr->mask) in store_filter()
1448 if (fattr->type == RC_FILTER_WAKEUP) { in store_filter()
1453 if (dev->wakeup_protocol != RC_PROTO_UNKNOWN) in store_filter()
1456 ret = -EINVAL; in store_filter()
1462 if (fattr->type == RC_FILTER_NORMAL && !dev->enabled_protocols && in store_filter()
1465 ret = -EINVAL; in store_filter()
1476 mutex_unlock(&dev->lock); in store_filter()
1481 * show_wakeup_protocols() - shows the wakeup IR protocol
1487 * it is triggered by reading /sys/class/rc/rc?/wakeup_protocols.
1491 * dev->lock is taken to guard against races between
1504 mutex_lock(&dev->lock); in show_wakeup_protocols()
1506 allowed = dev->allowed_wakeup_protocols; in show_wakeup_protocols()
1507 enabled = dev->wakeup_protocol; in show_wakeup_protocols()
1509 mutex_unlock(&dev->lock); in show_wakeup_protocols()
1511 dev_dbg(&dev->dev, "%s: allowed - 0x%llx, enabled - %d\n", in show_wakeup_protocols()
1517 tmp += sprintf(tmp, "[%s] ", protocols[i].name); in show_wakeup_protocols()
1519 tmp += sprintf(tmp, "%s ", protocols[i].name); in show_wakeup_protocols()
1524 tmp--; in show_wakeup_protocols()
1527 return tmp + 1 - buf; in show_wakeup_protocols()
1531 * store_wakeup_protocols() - changes the wakeup IR protocol(s)
1538 * It is triggered by writing to /sys/class/rc/rc?/wakeup_protocols.
1541 * dev->lock is taken to guard against races between
1550 ssize_t rc; in store_wakeup_protocols() local
1554 mutex_lock(&dev->lock); in store_wakeup_protocols()
1555 if (!dev->registered) { in store_wakeup_protocols()
1556 mutex_unlock(&dev->lock); in store_wakeup_protocols()
1557 return -ENODEV; in store_wakeup_protocols()
1560 allowed = dev->allowed_wakeup_protocols; in store_wakeup_protocols()
1565 sysfs_streq(buf, protocols[i].name)) { in store_wakeup_protocols()
1572 rc = -EINVAL; in store_wakeup_protocols()
1576 if (dev->encode_wakeup) { in store_wakeup_protocols()
1581 rc = -EINVAL; in store_wakeup_protocols()
1587 if (dev->wakeup_protocol != protocol) { in store_wakeup_protocols()
1588 dev->wakeup_protocol = protocol; in store_wakeup_protocols()
1589 dev_dbg(&dev->dev, "Wakeup protocol changed to %d\n", protocol); in store_wakeup_protocols()
1592 dev->scancode_wakeup_filter.data = 0x800f0000; in store_wakeup_protocols()
1594 dev->scancode_wakeup_filter.data = 0; in store_wakeup_protocols()
1595 dev->scancode_wakeup_filter.mask = 0; in store_wakeup_protocols()
1597 rc = dev->s_wakeup_filter(dev, &dev->scancode_wakeup_filter); in store_wakeup_protocols()
1598 if (rc == 0) in store_wakeup_protocols()
1599 rc = len; in store_wakeup_protocols()
1601 rc = len; in store_wakeup_protocols()
1605 mutex_unlock(&dev->lock); in store_wakeup_protocols()
1606 return rc; in store_wakeup_protocols()
1621 mutex_lock(&dev->lock); in rc_dev_uevent()
1623 if (!dev->registered) in rc_dev_uevent()
1624 ret = -ENODEV; in rc_dev_uevent()
1625 if (ret == 0 && dev->rc_map.name) in rc_dev_uevent()
1626 ret = add_uevent_var(env, "NAME=%s", dev->rc_map.name); in rc_dev_uevent()
1627 if (ret == 0 && dev->driver_name) in rc_dev_uevent()
1628 ret = add_uevent_var(env, "DRV_NAME=%s", dev->driver_name); in rc_dev_uevent()
1629 if (ret == 0 && dev->device_name) in rc_dev_uevent()
1630 ret = add_uevent_var(env, "DEV_NAME=%s", dev->device_name); in rc_dev_uevent()
1632 mutex_unlock(&dev->lock); in rc_dev_uevent()
1708 dev->input_dev = input_allocate_device(); in rc_allocate_device()
1709 if (!dev->input_dev) { in rc_allocate_device()
1714 dev->input_dev->getkeycode = ir_getkeycode; in rc_allocate_device()
1715 dev->input_dev->setkeycode = ir_setkeycode; in rc_allocate_device()
1716 input_set_drvdata(dev->input_dev, dev); in rc_allocate_device()
1718 dev->timeout = IR_DEFAULT_TIMEOUT; in rc_allocate_device()
1719 timer_setup(&dev->timer_keyup, ir_timer_keyup, 0); in rc_allocate_device()
1720 timer_setup(&dev->timer_repeat, ir_timer_repeat, 0); in rc_allocate_device()
1722 spin_lock_init(&dev->rc_map.lock); in rc_allocate_device()
1723 spin_lock_init(&dev->keylock); in rc_allocate_device()
1725 mutex_init(&dev->lock); in rc_allocate_device()
1727 dev->dev.type = &rc_dev_type; in rc_allocate_device()
1728 dev->dev.class = &rc_class; in rc_allocate_device()
1729 device_initialize(&dev->dev); in rc_allocate_device()
1731 dev->driver_type = type; in rc_allocate_device()
1743 input_free_device(dev->input_dev); in rc_free_device()
1745 put_device(&dev->dev); in rc_free_device()
1762 struct rc_dev **dr, *rc; in devm_rc_allocate_device() local
1768 rc = rc_allocate_device(type); in devm_rc_allocate_device()
1769 if (!rc) { in devm_rc_allocate_device()
1774 rc->dev.parent = dev; in devm_rc_allocate_device()
1775 rc->managed_alloc = true; in devm_rc_allocate_device()
1776 *dr = rc; in devm_rc_allocate_device()
1779 return rc; in devm_rc_allocate_device()
1785 int rc; in rc_prepare_rx_device() local
1789 if (!dev->map_name) in rc_prepare_rx_device()
1790 return -EINVAL; in rc_prepare_rx_device()
1792 rc_map = rc_map_get(dev->map_name); in rc_prepare_rx_device()
1795 if (!rc_map || !rc_map->scan || rc_map->size == 0) in rc_prepare_rx_device()
1796 return -EINVAL; in rc_prepare_rx_device()
1798 rc = ir_setkeytable(dev, rc_map); in rc_prepare_rx_device()
1799 if (rc) in rc_prepare_rx_device()
1800 return rc; in rc_prepare_rx_device()
1802 rc_proto = BIT_ULL(rc_map->rc_proto); in rc_prepare_rx_device()
1804 if (dev->driver_type == RC_DRIVER_SCANCODE && !dev->change_protocol) in rc_prepare_rx_device()
1805 dev->enabled_protocols = dev->allowed_protocols; in rc_prepare_rx_device()
1807 if (dev->driver_type == RC_DRIVER_IR_RAW) in rc_prepare_rx_device()
1810 if (dev->change_protocol) { in rc_prepare_rx_device()
1811 rc = dev->change_protocol(dev, &rc_proto); in rc_prepare_rx_device()
1812 if (rc < 0) in rc_prepare_rx_device()
1814 dev->enabled_protocols = rc_proto; in rc_prepare_rx_device()
1818 set_bit(EV_KEY, dev->input_dev->evbit); in rc_prepare_rx_device()
1819 set_bit(EV_REP, dev->input_dev->evbit); in rc_prepare_rx_device()
1820 set_bit(EV_MSC, dev->input_dev->evbit); in rc_prepare_rx_device()
1821 set_bit(MSC_SCAN, dev->input_dev->mscbit); in rc_prepare_rx_device()
1824 set_bit(INPUT_PROP_POINTING_STICK, dev->input_dev->propbit); in rc_prepare_rx_device()
1825 set_bit(EV_REL, dev->input_dev->evbit); in rc_prepare_rx_device()
1826 set_bit(REL_X, dev->input_dev->relbit); in rc_prepare_rx_device()
1827 set_bit(REL_Y, dev->input_dev->relbit); in rc_prepare_rx_device()
1829 if (dev->open) in rc_prepare_rx_device()
1830 dev->input_dev->open = ir_open; in rc_prepare_rx_device()
1831 if (dev->close) in rc_prepare_rx_device()
1832 dev->input_dev->close = ir_close; in rc_prepare_rx_device()
1834 dev->input_dev->dev.parent = &dev->dev; in rc_prepare_rx_device()
1835 memcpy(&dev->input_dev->id, &dev->input_id, sizeof(dev->input_id)); in rc_prepare_rx_device()
1836 dev->input_dev->phys = dev->input_phys; in rc_prepare_rx_device()
1837 dev->input_dev->name = dev->device_name; in rc_prepare_rx_device()
1842 ir_free_table(&dev->rc_map); in rc_prepare_rx_device()
1844 return rc; in rc_prepare_rx_device()
1849 int rc; in rc_setup_rx_device() local
1852 rc = input_register_device(dev->input_dev); in rc_setup_rx_device()
1853 if (rc) in rc_setup_rx_device()
1854 return rc; in rc_setup_rx_device()
1862 if (dev->allowed_protocols == RC_PROTO_BIT_CEC) in rc_setup_rx_device()
1863 dev->input_dev->rep[REP_DELAY] = 0; in rc_setup_rx_device()
1865 dev->input_dev->rep[REP_DELAY] = 500; in rc_setup_rx_device()
1868 * As a repeat event on protocols like RC-5 and NEC take as long as in rc_setup_rx_device()
1872 dev->input_dev->rep[REP_PERIOD] = 125; in rc_setup_rx_device()
1882 if (dev->input_dev) { in rc_free_rx_device()
1883 input_unregister_device(dev->input_dev); in rc_free_rx_device()
1884 dev->input_dev = NULL; in rc_free_rx_device()
1887 ir_free_table(&dev->rc_map); in rc_free_rx_device()
1895 int rc; in rc_register_device() local
1898 return -EINVAL; in rc_register_device()
1904 dev->minor = minor; in rc_register_device()
1905 dev_set_name(&dev->dev, "rc%u", dev->minor); in rc_register_device()
1906 dev_set_drvdata(&dev->dev, dev); in rc_register_device()
1908 dev->dev.groups = dev->sysfs_groups; in rc_register_device()
1909 if (dev->driver_type == RC_DRIVER_SCANCODE && !dev->change_protocol) in rc_register_device()
1910 dev->sysfs_groups[attr++] = &rc_dev_ro_protocol_attr_grp; in rc_register_device()
1911 else if (dev->driver_type != RC_DRIVER_IR_RAW_TX) in rc_register_device()
1912 dev->sysfs_groups[attr++] = &rc_dev_rw_protocol_attr_grp; in rc_register_device()
1913 if (dev->s_filter) in rc_register_device()
1914 dev->sysfs_groups[attr++] = &rc_dev_filter_attr_grp; in rc_register_device()
1915 if (dev->s_wakeup_filter) in rc_register_device()
1916 dev->sysfs_groups[attr++] = &rc_dev_wakeup_filter_attr_grp; in rc_register_device()
1917 dev->sysfs_groups[attr++] = NULL; in rc_register_device()
1919 if (dev->driver_type == RC_DRIVER_IR_RAW) { in rc_register_device()
1920 rc = ir_raw_event_prepare(dev); in rc_register_device()
1921 if (rc < 0) in rc_register_device()
1925 if (dev->driver_type != RC_DRIVER_IR_RAW_TX) { in rc_register_device()
1926 rc = rc_prepare_rx_device(dev); in rc_register_device()
1927 if (rc) in rc_register_device()
1931 rc = device_add(&dev->dev); in rc_register_device()
1932 if (rc) in rc_register_device()
1935 path = kobject_get_path(&dev->dev.kobj, GFP_KERNEL); in rc_register_device()
1936 dev_info(&dev->dev, "%s as %s\n", in rc_register_device()
1937 dev->device_name ?: "Unspecified device", path ?: "N/A"); in rc_register_device()
1940 dev->registered = true; in rc_register_device()
1948 if (dev->allowed_protocols != RC_PROTO_BIT_CEC) { in rc_register_device()
1949 rc = lirc_register(dev); in rc_register_device()
1950 if (rc < 0) in rc_register_device()
1954 if (dev->driver_type != RC_DRIVER_IR_RAW_TX) { in rc_register_device()
1955 rc = rc_setup_rx_device(dev); in rc_register_device()
1956 if (rc) in rc_register_device()
1960 if (dev->driver_type == RC_DRIVER_IR_RAW) { in rc_register_device()
1961 rc = ir_raw_event_register(dev); in rc_register_device()
1962 if (rc < 0) in rc_register_device()
1966 dev_dbg(&dev->dev, "Registered rc%u (driver: %s)\n", dev->minor, in rc_register_device()
1967 dev->driver_name ? dev->driver_name : "unknown"); in rc_register_device()
1974 if (dev->allowed_protocols != RC_PROTO_BIT_CEC) in rc_register_device()
1977 device_del(&dev->dev); in rc_register_device()
1979 ir_free_table(&dev->rc_map); in rc_register_device()
1984 return rc; in rc_register_device()
2000 return -ENOMEM; in devm_rc_register_device()
2020 if (dev->driver_type == RC_DRIVER_IR_RAW) in rc_unregister_device()
2023 del_timer_sync(&dev->timer_keyup); in rc_unregister_device()
2024 del_timer_sync(&dev->timer_repeat); in rc_unregister_device()
2026 mutex_lock(&dev->lock); in rc_unregister_device()
2027 if (dev->users && dev->close) in rc_unregister_device()
2028 dev->close(dev); in rc_unregister_device()
2029 dev->registered = false; in rc_unregister_device()
2030 mutex_unlock(&dev->lock); in rc_unregister_device()
2035 * lirc device should be freed with dev->registered = false, so in rc_unregister_device()
2038 if (dev->allowed_protocols != RC_PROTO_BIT_CEC) in rc_unregister_device()
2041 device_del(&dev->dev); in rc_unregister_device()
2043 ida_simple_remove(&rc_ida, dev->minor); in rc_unregister_device()
2045 if (!dev->managed_alloc) in rc_unregister_device()
2052 * Init/exit code for the module. Basically, creates/removes /sys/class/rc
2057 int rc = class_register(&rc_class); in rc_core_init() local
2058 if (rc) { in rc_core_init()
2059 pr_err("rc_core: unable to register rc class\n"); in rc_core_init()
2060 return rc; in rc_core_init()
2063 rc = lirc_dev_init(); in rc_core_init()
2064 if (rc) { in rc_core_init()
2067 return rc; in rc_core_init()
2070 led_trigger_register_simple("rc-feedback", &led_feedback); in rc_core_init()