Mauro Carvalho Chehab | 2083528 | 2017-12-01 08:47:08 -0500 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | // rc-main.c - Remote Controller core module |
| 3 | // |
| 4 | // Copyright (C) 2009-2010 by Mauro Carvalho Chehab |
Mauro Carvalho Chehab | ef53a11 | 2009-11-27 22:01:23 -0300 | [diff] [blame] | 5 | |
Mauro Carvalho Chehab | d3d9682 | 2016-10-20 15:04:39 -0200 | [diff] [blame] | 6 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 7 | |
Mauro Carvalho Chehab | 6bda964 | 2010-11-17 13:28:38 -0300 | [diff] [blame] | 8 | #include <media/rc-core.h> |
Thomas Meyer | 8ca01d4 | 2017-09-08 13:33:36 -0300 | [diff] [blame] | 9 | #include <linux/bsearch.h> |
Mauro Carvalho Chehab | 631493e | 2010-11-09 23:44:27 -0300 | [diff] [blame] | 10 | #include <linux/spinlock.h> |
| 11 | #include <linux/delay.h> |
Mauro Carvalho Chehab | 882ead3 | 2009-12-29 10:37:38 -0300 | [diff] [blame] | 12 | #include <linux/input.h> |
Sean Young | 153a60b | 2013-07-30 19:00:01 -0300 | [diff] [blame] | 13 | #include <linux/leds.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 14 | #include <linux/slab.h> |
David Härdeman | fcb1309 | 2015-05-19 19:03:17 -0300 | [diff] [blame] | 15 | #include <linux/idr.h> |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 16 | #include <linux/device.h> |
Paul Gortmaker | 7a707b8 | 2011-07-03 14:03:12 -0400 | [diff] [blame] | 17 | #include <linux/module.h> |
Mauro Carvalho Chehab | f62de67 | 2010-11-09 23:09:57 -0300 | [diff] [blame] | 18 | #include "rc-core-priv.h" |
Mauro Carvalho Chehab | ef53a11 | 2009-11-27 22:01:23 -0300 | [diff] [blame] | 19 | |
David Härdeman | b3074c0 | 2010-04-02 15:58:28 -0300 | [diff] [blame] | 20 | /* Sizes are in bytes, 256 bytes allows for 32 entries on x64 */ |
| 21 | #define IR_TAB_MIN_SIZE 256 |
| 22 | #define IR_TAB_MAX_SIZE 8192 |
Mauro Carvalho Chehab | f6fc504 | 2009-11-29 11:08:02 -0300 | [diff] [blame] | 23 | |
Sean Young | d57ea87 | 2017-08-09 13:19:16 -0400 | [diff] [blame] | 24 | static const struct { |
| 25 | const char *name; |
| 26 | unsigned int repeat_period; |
| 27 | unsigned int scancode_bits; |
| 28 | } protocols[] = { |
Sean Young | 2849225 | 2018-03-24 08:02:48 -0400 | [diff] [blame] | 29 | [RC_PROTO_UNKNOWN] = { .name = "unknown", .repeat_period = 125 }, |
| 30 | [RC_PROTO_OTHER] = { .name = "other", .repeat_period = 125 }, |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 31 | [RC_PROTO_RC5] = { .name = "rc-5", |
Sean Young | 2849225 | 2018-03-24 08:02:48 -0400 | [diff] [blame] | 32 | .scancode_bits = 0x1f7f, .repeat_period = 114 }, |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 33 | [RC_PROTO_RC5X_20] = { .name = "rc-5x-20", |
Sean Young | 2849225 | 2018-03-24 08:02:48 -0400 | [diff] [blame] | 34 | .scancode_bits = 0x1f7f3f, .repeat_period = 114 }, |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 35 | [RC_PROTO_RC5_SZ] = { .name = "rc-5-sz", |
Sean Young | 2849225 | 2018-03-24 08:02:48 -0400 | [diff] [blame] | 36 | .scancode_bits = 0x2fff, .repeat_period = 114 }, |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 37 | [RC_PROTO_JVC] = { .name = "jvc", |
Sean Young | 2849225 | 2018-03-24 08:02:48 -0400 | [diff] [blame] | 38 | .scancode_bits = 0xffff, .repeat_period = 125 }, |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 39 | [RC_PROTO_SONY12] = { .name = "sony-12", |
Sean Young | 2849225 | 2018-03-24 08:02:48 -0400 | [diff] [blame] | 40 | .scancode_bits = 0x1f007f, .repeat_period = 100 }, |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 41 | [RC_PROTO_SONY15] = { .name = "sony-15", |
Sean Young | 2849225 | 2018-03-24 08:02:48 -0400 | [diff] [blame] | 42 | .scancode_bits = 0xff007f, .repeat_period = 100 }, |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 43 | [RC_PROTO_SONY20] = { .name = "sony-20", |
Sean Young | 2849225 | 2018-03-24 08:02:48 -0400 | [diff] [blame] | 44 | .scancode_bits = 0x1fff7f, .repeat_period = 100 }, |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 45 | [RC_PROTO_NEC] = { .name = "nec", |
Sean Young | 2849225 | 2018-03-24 08:02:48 -0400 | [diff] [blame] | 46 | .scancode_bits = 0xffff, .repeat_period = 110 }, |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 47 | [RC_PROTO_NECX] = { .name = "nec-x", |
Sean Young | 2849225 | 2018-03-24 08:02:48 -0400 | [diff] [blame] | 48 | .scancode_bits = 0xffffff, .repeat_period = 110 }, |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 49 | [RC_PROTO_NEC32] = { .name = "nec-32", |
Sean Young | 2849225 | 2018-03-24 08:02:48 -0400 | [diff] [blame] | 50 | .scancode_bits = 0xffffffff, .repeat_period = 110 }, |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 51 | [RC_PROTO_SANYO] = { .name = "sanyo", |
Sean Young | 2849225 | 2018-03-24 08:02:48 -0400 | [diff] [blame] | 52 | .scancode_bits = 0x1fffff, .repeat_period = 125 }, |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 53 | [RC_PROTO_MCIR2_KBD] = { .name = "mcir2-kbd", |
Sean Young | 5393276 | 2018-04-07 17:41:17 -0400 | [diff] [blame] | 54 | .scancode_bits = 0xffffff, .repeat_period = 100 }, |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 55 | [RC_PROTO_MCIR2_MSE] = { .name = "mcir2-mse", |
Sean Young | 2849225 | 2018-03-24 08:02:48 -0400 | [diff] [blame] | 56 | .scancode_bits = 0x1fffff, .repeat_period = 100 }, |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 57 | [RC_PROTO_RC6_0] = { .name = "rc-6-0", |
Sean Young | 2849225 | 2018-03-24 08:02:48 -0400 | [diff] [blame] | 58 | .scancode_bits = 0xffff, .repeat_period = 114 }, |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 59 | [RC_PROTO_RC6_6A_20] = { .name = "rc-6-6a-20", |
Sean Young | 2849225 | 2018-03-24 08:02:48 -0400 | [diff] [blame] | 60 | .scancode_bits = 0xfffff, .repeat_period = 114 }, |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 61 | [RC_PROTO_RC6_6A_24] = { .name = "rc-6-6a-24", |
Sean Young | 2849225 | 2018-03-24 08:02:48 -0400 | [diff] [blame] | 62 | .scancode_bits = 0xffffff, .repeat_period = 114 }, |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 63 | [RC_PROTO_RC6_6A_32] = { .name = "rc-6-6a-32", |
Sean Young | 2849225 | 2018-03-24 08:02:48 -0400 | [diff] [blame] | 64 | .scancode_bits = 0xffffffff, .repeat_period = 114 }, |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 65 | [RC_PROTO_RC6_MCE] = { .name = "rc-6-mce", |
Sean Young | 2849225 | 2018-03-24 08:02:48 -0400 | [diff] [blame] | 66 | .scancode_bits = 0xffff7fff, .repeat_period = 114 }, |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 67 | [RC_PROTO_SHARP] = { .name = "sharp", |
Sean Young | 2849225 | 2018-03-24 08:02:48 -0400 | [diff] [blame] | 68 | .scancode_bits = 0x1fff, .repeat_period = 125 }, |
| 69 | [RC_PROTO_XMP] = { .name = "xmp", .repeat_period = 125 }, |
| 70 | [RC_PROTO_CEC] = { .name = "cec", .repeat_period = 0 }, |
Sean Young | 447dcc0c | 2017-12-03 11:06:54 -0500 | [diff] [blame] | 71 | [RC_PROTO_IMON] = { .name = "imon", |
Sean Young | 2849225 | 2018-03-24 08:02:48 -0400 | [diff] [blame] | 72 | .scancode_bits = 0x7fffffff, .repeat_period = 114 }, |
Patrick Lerda | 721074b | 2019-01-17 03:50:13 -0500 | [diff] [blame] | 73 | [RC_PROTO_RCMM12] = { .name = "rc-mm-12", |
| 74 | .scancode_bits = 0x00000fff, .repeat_period = 114 }, |
| 75 | [RC_PROTO_RCMM24] = { .name = "rc-mm-24", |
| 76 | .scancode_bits = 0x00ffffff, .repeat_period = 114 }, |
| 77 | [RC_PROTO_RCMM32] = { .name = "rc-mm-32", |
| 78 | .scancode_bits = 0xffffffff, .repeat_period = 114 }, |
Matthias Reichl | 1728769 | 2019-03-24 05:43:51 -0400 | [diff] [blame] | 79 | [RC_PROTO_XBOX_DVD] = { .name = "xbox-dvd", .repeat_period = 64 }, |
Sean Young | d57ea87 | 2017-08-09 13:19:16 -0400 | [diff] [blame] | 80 | }; |
David Härdeman | a374fef | 2010-04-02 15:58:29 -0300 | [diff] [blame] | 81 | |
David Härdeman | 4c7b355 | 2010-11-10 11:04:19 -0300 | [diff] [blame] | 82 | /* Used to keep track of known keymaps */ |
Mauro Carvalho Chehab | 631493e | 2010-11-09 23:44:27 -0300 | [diff] [blame] | 83 | static LIST_HEAD(rc_map_list); |
| 84 | static DEFINE_SPINLOCK(rc_map_lock); |
Sean Young | 153a60b | 2013-07-30 19:00:01 -0300 | [diff] [blame] | 85 | static struct led_trigger *led_feedback; |
Mauro Carvalho Chehab | 631493e | 2010-11-09 23:44:27 -0300 | [diff] [blame] | 86 | |
David Härdeman | fcb1309 | 2015-05-19 19:03:17 -0300 | [diff] [blame] | 87 | /* Used to keep track of rc devices */ |
| 88 | static DEFINE_IDA(rc_ida); |
| 89 | |
Mauro Carvalho Chehab | d100e65 | 2010-11-17 15:56:53 -0300 | [diff] [blame] | 90 | static struct rc_map_list *seek_rc_map(const char *name) |
Mauro Carvalho Chehab | 631493e | 2010-11-09 23:44:27 -0300 | [diff] [blame] | 91 | { |
Mauro Carvalho Chehab | d100e65 | 2010-11-17 15:56:53 -0300 | [diff] [blame] | 92 | struct rc_map_list *map = NULL; |
Mauro Carvalho Chehab | 631493e | 2010-11-09 23:44:27 -0300 | [diff] [blame] | 93 | |
| 94 | spin_lock(&rc_map_lock); |
| 95 | list_for_each_entry(map, &rc_map_list, list) { |
| 96 | if (!strcmp(name, map->map.name)) { |
| 97 | spin_unlock(&rc_map_lock); |
| 98 | return map; |
| 99 | } |
| 100 | } |
| 101 | spin_unlock(&rc_map_lock); |
| 102 | |
| 103 | return NULL; |
| 104 | } |
| 105 | |
Mauro Carvalho Chehab | d100e65 | 2010-11-17 15:56:53 -0300 | [diff] [blame] | 106 | struct rc_map *rc_map_get(const char *name) |
Mauro Carvalho Chehab | 631493e | 2010-11-09 23:44:27 -0300 | [diff] [blame] | 107 | { |
| 108 | |
Mauro Carvalho Chehab | d100e65 | 2010-11-17 15:56:53 -0300 | [diff] [blame] | 109 | struct rc_map_list *map; |
Mauro Carvalho Chehab | 631493e | 2010-11-09 23:44:27 -0300 | [diff] [blame] | 110 | |
| 111 | map = seek_rc_map(name); |
Russell King | 2ff56fa | 2015-10-15 13:15:24 -0300 | [diff] [blame] | 112 | #ifdef CONFIG_MODULES |
Mauro Carvalho Chehab | 631493e | 2010-11-09 23:44:27 -0300 | [diff] [blame] | 113 | if (!map) { |
Kees Cook | 8ea5488 | 2014-03-11 17:25:53 -0300 | [diff] [blame] | 114 | int rc = request_module("%s", name); |
Mauro Carvalho Chehab | 631493e | 2010-11-09 23:44:27 -0300 | [diff] [blame] | 115 | if (rc < 0) { |
Mauro Carvalho Chehab | d3d9682 | 2016-10-20 15:04:39 -0200 | [diff] [blame] | 116 | pr_err("Couldn't load IR keymap %s\n", name); |
Mauro Carvalho Chehab | 631493e | 2010-11-09 23:44:27 -0300 | [diff] [blame] | 117 | return NULL; |
| 118 | } |
| 119 | msleep(20); /* Give some time for IR to register */ |
| 120 | |
| 121 | map = seek_rc_map(name); |
| 122 | } |
| 123 | #endif |
| 124 | if (!map) { |
Mauro Carvalho Chehab | d3d9682 | 2016-10-20 15:04:39 -0200 | [diff] [blame] | 125 | pr_err("IR keymap %s not found\n", name); |
Mauro Carvalho Chehab | 631493e | 2010-11-09 23:44:27 -0300 | [diff] [blame] | 126 | return NULL; |
| 127 | } |
| 128 | |
| 129 | printk(KERN_INFO "Registered IR keymap %s\n", map->map.name); |
| 130 | |
| 131 | return &map->map; |
| 132 | } |
Mauro Carvalho Chehab | d100e65 | 2010-11-17 15:56:53 -0300 | [diff] [blame] | 133 | EXPORT_SYMBOL_GPL(rc_map_get); |
Mauro Carvalho Chehab | 631493e | 2010-11-09 23:44:27 -0300 | [diff] [blame] | 134 | |
Mauro Carvalho Chehab | d100e65 | 2010-11-17 15:56:53 -0300 | [diff] [blame] | 135 | int rc_map_register(struct rc_map_list *map) |
Mauro Carvalho Chehab | 631493e | 2010-11-09 23:44:27 -0300 | [diff] [blame] | 136 | { |
| 137 | spin_lock(&rc_map_lock); |
| 138 | list_add_tail(&map->list, &rc_map_list); |
| 139 | spin_unlock(&rc_map_lock); |
| 140 | return 0; |
| 141 | } |
Mauro Carvalho Chehab | d100e65 | 2010-11-17 15:56:53 -0300 | [diff] [blame] | 142 | EXPORT_SYMBOL_GPL(rc_map_register); |
Mauro Carvalho Chehab | 631493e | 2010-11-09 23:44:27 -0300 | [diff] [blame] | 143 | |
Mauro Carvalho Chehab | d100e65 | 2010-11-17 15:56:53 -0300 | [diff] [blame] | 144 | void rc_map_unregister(struct rc_map_list *map) |
Mauro Carvalho Chehab | 631493e | 2010-11-09 23:44:27 -0300 | [diff] [blame] | 145 | { |
| 146 | spin_lock(&rc_map_lock); |
| 147 | list_del(&map->list); |
| 148 | spin_unlock(&rc_map_lock); |
| 149 | } |
Mauro Carvalho Chehab | d100e65 | 2010-11-17 15:56:53 -0300 | [diff] [blame] | 150 | EXPORT_SYMBOL_GPL(rc_map_unregister); |
Mauro Carvalho Chehab | 631493e | 2010-11-09 23:44:27 -0300 | [diff] [blame] | 151 | |
| 152 | |
Mauro Carvalho Chehab | 2f4f58d | 2010-11-17 15:46:09 -0300 | [diff] [blame] | 153 | static struct rc_map_table empty[] = { |
Mauro Carvalho Chehab | 631493e | 2010-11-09 23:44:27 -0300 | [diff] [blame] | 154 | { 0x2a, KEY_COFFEE }, |
| 155 | }; |
| 156 | |
Mauro Carvalho Chehab | d100e65 | 2010-11-17 15:56:53 -0300 | [diff] [blame] | 157 | static struct rc_map_list empty_map = { |
Mauro Carvalho Chehab | 631493e | 2010-11-09 23:44:27 -0300 | [diff] [blame] | 158 | .map = { |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 159 | .scan = empty, |
| 160 | .size = ARRAY_SIZE(empty), |
| 161 | .rc_proto = RC_PROTO_UNKNOWN, /* Legacy IR type */ |
| 162 | .name = RC_MAP_EMPTY, |
Mauro Carvalho Chehab | 631493e | 2010-11-09 23:44:27 -0300 | [diff] [blame] | 163 | } |
| 164 | }; |
| 165 | |
Mauro Carvalho Chehab | f6fc504 | 2009-11-29 11:08:02 -0300 | [diff] [blame] | 166 | /** |
Sean Young | e6c6d7d | 2020-01-17 17:46:36 +0100 | [diff] [blame] | 167 | * scancode_to_u64() - converts scancode in &struct input_keymap_entry |
| 168 | * @ke: keymap entry containing scancode to be converted. |
| 169 | * @scancode: pointer to the location where converted scancode should |
| 170 | * be stored. |
| 171 | * |
| 172 | * This function is a version of input_scancode_to_scalar specialized for |
| 173 | * rc-core. |
| 174 | */ |
| 175 | static int scancode_to_u64(const struct input_keymap_entry *ke, u64 *scancode) |
| 176 | { |
| 177 | switch (ke->len) { |
| 178 | case 1: |
| 179 | *scancode = *((u8 *)ke->scancode); |
| 180 | break; |
| 181 | |
| 182 | case 2: |
| 183 | *scancode = *((u16 *)ke->scancode); |
| 184 | break; |
| 185 | |
| 186 | case 4: |
| 187 | *scancode = *((u32 *)ke->scancode); |
| 188 | break; |
| 189 | |
| 190 | case 8: |
| 191 | *scancode = *((u64 *)ke->scancode); |
| 192 | break; |
| 193 | |
| 194 | default: |
| 195 | return -EINVAL; |
| 196 | } |
| 197 | |
| 198 | return 0; |
| 199 | } |
| 200 | |
| 201 | /** |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 202 | * ir_create_table() - initializes a scancode table |
Sean Young | 1f17f68 | 2018-02-12 07:27:50 -0500 | [diff] [blame] | 203 | * @dev: the rc_dev device |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 204 | * @rc_map: the rc_map to initialize |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 205 | * @name: name to assign to the table |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 206 | * @rc_proto: ir type to assign to the new table |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 207 | * @size: initial size of the table |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 208 | * |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 209 | * This routine will initialize the rc_map and will allocate |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 210 | * memory to hold at least the specified number of elements. |
Mauro Carvalho Chehab | f67f366 | 2017-11-27 08:35:13 -0500 | [diff] [blame] | 211 | * |
| 212 | * return: zero on success or a negative error code |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 213 | */ |
Sean Young | 1f17f68 | 2018-02-12 07:27:50 -0500 | [diff] [blame] | 214 | static int ir_create_table(struct rc_dev *dev, struct rc_map *rc_map, |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 215 | const char *name, u64 rc_proto, size_t size) |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 216 | { |
Hans Verkuil | d54fc3b | 2016-06-26 07:44:56 -0300 | [diff] [blame] | 217 | rc_map->name = kstrdup(name, GFP_KERNEL); |
| 218 | if (!rc_map->name) |
| 219 | return -ENOMEM; |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 220 | rc_map->rc_proto = rc_proto; |
Mauro Carvalho Chehab | 2f4f58d | 2010-11-17 15:46:09 -0300 | [diff] [blame] | 221 | rc_map->alloc = roundup_pow_of_two(size * sizeof(struct rc_map_table)); |
| 222 | rc_map->size = rc_map->alloc / sizeof(struct rc_map_table); |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 223 | rc_map->scan = kmalloc(rc_map->alloc, GFP_KERNEL); |
Hans Verkuil | d54fc3b | 2016-06-26 07:44:56 -0300 | [diff] [blame] | 224 | if (!rc_map->scan) { |
| 225 | kfree(rc_map->name); |
| 226 | rc_map->name = NULL; |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 227 | return -ENOMEM; |
Hans Verkuil | d54fc3b | 2016-06-26 07:44:56 -0300 | [diff] [blame] | 228 | } |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 229 | |
Sean Young | 1f17f68 | 2018-02-12 07:27:50 -0500 | [diff] [blame] | 230 | dev_dbg(&dev->dev, "Allocated space for %u keycode entries (%u bytes)\n", |
| 231 | rc_map->size, rc_map->alloc); |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | /** |
| 236 | * ir_free_table() - frees memory allocated by a scancode table |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 237 | * @rc_map: the table whose mappings need to be freed |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 238 | * |
| 239 | * This routine will free memory alloctaed for key mappings used by given |
| 240 | * scancode table. |
| 241 | */ |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 242 | static void ir_free_table(struct rc_map *rc_map) |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 243 | { |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 244 | rc_map->size = 0; |
Hans Verkuil | d54fc3b | 2016-06-26 07:44:56 -0300 | [diff] [blame] | 245 | kfree(rc_map->name); |
Max Kellermann | c183d35 | 2016-08-09 18:32:06 -0300 | [diff] [blame] | 246 | rc_map->name = NULL; |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 247 | kfree(rc_map->scan); |
| 248 | rc_map->scan = NULL; |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | /** |
David Härdeman | b3074c0 | 2010-04-02 15:58:28 -0300 | [diff] [blame] | 252 | * ir_resize_table() - resizes a scancode table if necessary |
Sean Young | 1f17f68 | 2018-02-12 07:27:50 -0500 | [diff] [blame] | 253 | * @dev: the rc_dev device |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 254 | * @rc_map: the rc_map to resize |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 255 | * @gfp_flags: gfp flags to use when allocating memory |
Mauro Carvalho Chehab | 7fee03e | 2009-12-02 15:56:47 -0300 | [diff] [blame] | 256 | * |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 257 | * This routine will shrink the rc_map if it has lots of |
David Härdeman | b3074c0 | 2010-04-02 15:58:28 -0300 | [diff] [blame] | 258 | * unused entries and grow it if it is full. |
Mauro Carvalho Chehab | f67f366 | 2017-11-27 08:35:13 -0500 | [diff] [blame] | 259 | * |
| 260 | * return: zero on success or a negative error code |
Mauro Carvalho Chehab | 7fee03e | 2009-12-02 15:56:47 -0300 | [diff] [blame] | 261 | */ |
Sean Young | 1f17f68 | 2018-02-12 07:27:50 -0500 | [diff] [blame] | 262 | static int ir_resize_table(struct rc_dev *dev, struct rc_map *rc_map, |
| 263 | gfp_t gfp_flags) |
David Härdeman | b3074c0 | 2010-04-02 15:58:28 -0300 | [diff] [blame] | 264 | { |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 265 | unsigned int oldalloc = rc_map->alloc; |
David Härdeman | b3074c0 | 2010-04-02 15:58:28 -0300 | [diff] [blame] | 266 | unsigned int newalloc = oldalloc; |
Mauro Carvalho Chehab | 2f4f58d | 2010-11-17 15:46:09 -0300 | [diff] [blame] | 267 | struct rc_map_table *oldscan = rc_map->scan; |
| 268 | struct rc_map_table *newscan; |
David Härdeman | b3074c0 | 2010-04-02 15:58:28 -0300 | [diff] [blame] | 269 | |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 270 | if (rc_map->size == rc_map->len) { |
David Härdeman | b3074c0 | 2010-04-02 15:58:28 -0300 | [diff] [blame] | 271 | /* All entries in use -> grow keytable */ |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 272 | if (rc_map->alloc >= IR_TAB_MAX_SIZE) |
David Härdeman | b3074c0 | 2010-04-02 15:58:28 -0300 | [diff] [blame] | 273 | return -ENOMEM; |
| 274 | |
| 275 | newalloc *= 2; |
Sean Young | 1f17f68 | 2018-02-12 07:27:50 -0500 | [diff] [blame] | 276 | dev_dbg(&dev->dev, "Growing table to %u bytes\n", newalloc); |
David Härdeman | b3074c0 | 2010-04-02 15:58:28 -0300 | [diff] [blame] | 277 | } |
| 278 | |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 279 | if ((rc_map->len * 3 < rc_map->size) && (oldalloc > IR_TAB_MIN_SIZE)) { |
David Härdeman | b3074c0 | 2010-04-02 15:58:28 -0300 | [diff] [blame] | 280 | /* Less than 1/3 of entries in use -> shrink keytable */ |
| 281 | newalloc /= 2; |
Sean Young | 1f17f68 | 2018-02-12 07:27:50 -0500 | [diff] [blame] | 282 | dev_dbg(&dev->dev, "Shrinking table to %u bytes\n", newalloc); |
David Härdeman | b3074c0 | 2010-04-02 15:58:28 -0300 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | if (newalloc == oldalloc) |
| 286 | return 0; |
| 287 | |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 288 | newscan = kmalloc(newalloc, gfp_flags); |
Sean Young | 1f17f68 | 2018-02-12 07:27:50 -0500 | [diff] [blame] | 289 | if (!newscan) |
David Härdeman | b3074c0 | 2010-04-02 15:58:28 -0300 | [diff] [blame] | 290 | return -ENOMEM; |
David Härdeman | b3074c0 | 2010-04-02 15:58:28 -0300 | [diff] [blame] | 291 | |
Mauro Carvalho Chehab | 2f4f58d | 2010-11-17 15:46:09 -0300 | [diff] [blame] | 292 | memcpy(newscan, rc_map->scan, rc_map->len * sizeof(struct rc_map_table)); |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 293 | rc_map->scan = newscan; |
| 294 | rc_map->alloc = newalloc; |
Mauro Carvalho Chehab | 2f4f58d | 2010-11-17 15:46:09 -0300 | [diff] [blame] | 295 | rc_map->size = rc_map->alloc / sizeof(struct rc_map_table); |
David Härdeman | b3074c0 | 2010-04-02 15:58:28 -0300 | [diff] [blame] | 296 | kfree(oldscan); |
| 297 | return 0; |
| 298 | } |
| 299 | |
| 300 | /** |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 301 | * ir_update_mapping() - set a keycode in the scancode->keycode table |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 302 | * @dev: the struct rc_dev device descriptor |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 303 | * @rc_map: scancode table to be adjusted |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 304 | * @index: index of the mapping that needs to be updated |
Mauro Carvalho Chehab | f67f366 | 2017-11-27 08:35:13 -0500 | [diff] [blame] | 305 | * @new_keycode: the desired keycode |
David Härdeman | b3074c0 | 2010-04-02 15:58:28 -0300 | [diff] [blame] | 306 | * |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 307 | * This routine is used to update scancode->keycode mapping at given |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 308 | * position. |
Mauro Carvalho Chehab | f67f366 | 2017-11-27 08:35:13 -0500 | [diff] [blame] | 309 | * |
| 310 | * return: previous keycode assigned to the mapping |
| 311 | * |
David Härdeman | b3074c0 | 2010-04-02 15:58:28 -0300 | [diff] [blame] | 312 | */ |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 313 | static unsigned int ir_update_mapping(struct rc_dev *dev, |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 314 | struct rc_map *rc_map, |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 315 | unsigned int index, |
| 316 | unsigned int new_keycode) |
| 317 | { |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 318 | int old_keycode = rc_map->scan[index].keycode; |
Sean Young | 05f0eda | 2019-02-22 04:08:05 -0500 | [diff] [blame] | 319 | int i; |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 320 | |
| 321 | /* Did the user wish to remove the mapping? */ |
| 322 | if (new_keycode == KEY_RESERVED || new_keycode == KEY_UNKNOWN) { |
Sean Young | e6c6d7d | 2020-01-17 17:46:36 +0100 | [diff] [blame] | 323 | dev_dbg(&dev->dev, "#%d: Deleting scan 0x%04llx\n", |
Sean Young | 1f17f68 | 2018-02-12 07:27:50 -0500 | [diff] [blame] | 324 | index, rc_map->scan[index].scancode); |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 325 | rc_map->len--; |
| 326 | memmove(&rc_map->scan[index], &rc_map->scan[index+ 1], |
Mauro Carvalho Chehab | 2f4f58d | 2010-11-17 15:46:09 -0300 | [diff] [blame] | 327 | (rc_map->len - index) * sizeof(struct rc_map_table)); |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 328 | } else { |
Sean Young | e6c6d7d | 2020-01-17 17:46:36 +0100 | [diff] [blame] | 329 | dev_dbg(&dev->dev, "#%d: %s scan 0x%04llx with key 0x%04x\n", |
Sean Young | 1f17f68 | 2018-02-12 07:27:50 -0500 | [diff] [blame] | 330 | index, |
| 331 | old_keycode == KEY_RESERVED ? "New" : "Replacing", |
| 332 | rc_map->scan[index].scancode, new_keycode); |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 333 | rc_map->scan[index].keycode = new_keycode; |
Sean Young | 05f0eda | 2019-02-22 04:08:05 -0500 | [diff] [blame] | 334 | __set_bit(new_keycode, dev->input_dev->keybit); |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | if (old_keycode != KEY_RESERVED) { |
Sean Young | 05f0eda | 2019-02-22 04:08:05 -0500 | [diff] [blame] | 338 | /* A previous mapping was updated... */ |
| 339 | __clear_bit(old_keycode, dev->input_dev->keybit); |
| 340 | /* ... but another scancode might use the same keycode */ |
| 341 | for (i = 0; i < rc_map->len; i++) { |
| 342 | if (rc_map->scan[i].keycode == old_keycode) { |
| 343 | __set_bit(old_keycode, dev->input_dev->keybit); |
| 344 | break; |
| 345 | } |
| 346 | } |
| 347 | |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 348 | /* Possibly shrink the keytable, failure is not a problem */ |
Sean Young | 1f17f68 | 2018-02-12 07:27:50 -0500 | [diff] [blame] | 349 | ir_resize_table(dev, rc_map, GFP_ATOMIC); |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | return old_keycode; |
| 353 | } |
| 354 | |
| 355 | /** |
David Härdeman | 4c7b355 | 2010-11-10 11:04:19 -0300 | [diff] [blame] | 356 | * ir_establish_scancode() - set a keycode in the scancode->keycode table |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 357 | * @dev: the struct rc_dev device descriptor |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 358 | * @rc_map: scancode table to be searched |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 359 | * @scancode: the desired scancode |
| 360 | * @resize: controls whether we allowed to resize the table to |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 361 | * accommodate not yet present scancodes |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 362 | * |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 363 | * This routine is used to locate given scancode in rc_map. |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 364 | * If scancode is not yet present the routine will allocate a new slot |
| 365 | * for it. |
Mauro Carvalho Chehab | f67f366 | 2017-11-27 08:35:13 -0500 | [diff] [blame] | 366 | * |
| 367 | * return: index of the mapping containing scancode in question |
| 368 | * or -1U in case of failure. |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 369 | */ |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 370 | static unsigned int ir_establish_scancode(struct rc_dev *dev, |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 371 | struct rc_map *rc_map, |
Sean Young | e6c6d7d | 2020-01-17 17:46:36 +0100 | [diff] [blame] | 372 | u64 scancode, bool resize) |
David Härdeman | b3074c0 | 2010-04-02 15:58:28 -0300 | [diff] [blame] | 373 | { |
| 374 | unsigned int i; |
Mauro Carvalho Chehab | 9dfe4e8 | 2010-04-04 14:06:55 -0300 | [diff] [blame] | 375 | |
| 376 | /* |
| 377 | * Unfortunately, some hardware-based IR decoders don't provide |
| 378 | * all bits for the complete IR code. In general, they provide only |
| 379 | * the command part of the IR code. Yet, as it is possible to replace |
| 380 | * the provided IR with another one, it is needed to allow loading |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 381 | * IR tables from other remotes. So, we support specifying a mask to |
| 382 | * indicate the valid bits of the scancodes. |
Mauro Carvalho Chehab | 9dfe4e8 | 2010-04-04 14:06:55 -0300 | [diff] [blame] | 383 | */ |
David Härdeman | 9d2f1d3 | 2014-04-03 20:32:26 -0300 | [diff] [blame] | 384 | if (dev->scancode_mask) |
| 385 | scancode &= dev->scancode_mask; |
David Härdeman | b3074c0 | 2010-04-02 15:58:28 -0300 | [diff] [blame] | 386 | |
| 387 | /* First check if we already have a mapping for this ir command */ |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 388 | for (i = 0; i < rc_map->len; i++) { |
| 389 | if (rc_map->scan[i].scancode == scancode) |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 390 | return i; |
| 391 | |
David Härdeman | b3074c0 | 2010-04-02 15:58:28 -0300 | [diff] [blame] | 392 | /* Keytable is sorted from lowest to highest scancode */ |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 393 | if (rc_map->scan[i].scancode >= scancode) |
David Härdeman | b3074c0 | 2010-04-02 15:58:28 -0300 | [diff] [blame] | 394 | break; |
David Härdeman | b3074c0 | 2010-04-02 15:58:28 -0300 | [diff] [blame] | 395 | } |
| 396 | |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 397 | /* No previous mapping found, we might need to grow the table */ |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 398 | if (rc_map->size == rc_map->len) { |
Sean Young | 1f17f68 | 2018-02-12 07:27:50 -0500 | [diff] [blame] | 399 | if (!resize || ir_resize_table(dev, rc_map, GFP_ATOMIC)) |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 400 | return -1U; |
| 401 | } |
David Härdeman | b3074c0 | 2010-04-02 15:58:28 -0300 | [diff] [blame] | 402 | |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 403 | /* i is the proper index to insert our new keycode */ |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 404 | if (i < rc_map->len) |
| 405 | memmove(&rc_map->scan[i + 1], &rc_map->scan[i], |
Mauro Carvalho Chehab | 2f4f58d | 2010-11-17 15:46:09 -0300 | [diff] [blame] | 406 | (rc_map->len - i) * sizeof(struct rc_map_table)); |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 407 | rc_map->scan[i].scancode = scancode; |
| 408 | rc_map->scan[i].keycode = KEY_RESERVED; |
| 409 | rc_map->len++; |
David Härdeman | b3074c0 | 2010-04-02 15:58:28 -0300 | [diff] [blame] | 410 | |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 411 | return i; |
David Härdeman | b3074c0 | 2010-04-02 15:58:28 -0300 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | /** |
| 415 | * ir_setkeycode() - set a keycode in the scancode->keycode table |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 416 | * @idev: the struct input_dev device descriptor |
Mauro Carvalho Chehab | f67f366 | 2017-11-27 08:35:13 -0500 | [diff] [blame] | 417 | * @ke: Input keymap entry |
| 418 | * @old_keycode: result |
David Härdeman | b3074c0 | 2010-04-02 15:58:28 -0300 | [diff] [blame] | 419 | * |
| 420 | * This routine is used to handle evdev EVIOCSKEY ioctl. |
Mauro Carvalho Chehab | f67f366 | 2017-11-27 08:35:13 -0500 | [diff] [blame] | 421 | * |
| 422 | * return: -EINVAL if the keycode could not be inserted, otherwise zero. |
David Härdeman | b3074c0 | 2010-04-02 15:58:28 -0300 | [diff] [blame] | 423 | */ |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 424 | static int ir_setkeycode(struct input_dev *idev, |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 425 | const struct input_keymap_entry *ke, |
| 426 | unsigned int *old_keycode) |
Mauro Carvalho Chehab | 7fee03e | 2009-12-02 15:56:47 -0300 | [diff] [blame] | 427 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 428 | struct rc_dev *rdev = input_get_drvdata(idev); |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 429 | struct rc_map *rc_map = &rdev->rc_map; |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 430 | unsigned int index; |
Sean Young | e6c6d7d | 2020-01-17 17:46:36 +0100 | [diff] [blame] | 431 | u64 scancode; |
Mauro Carvalho Chehab | dea8a39 | 2010-11-29 07:46:13 -0300 | [diff] [blame] | 432 | int retval = 0; |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 433 | unsigned long flags; |
Mauro Carvalho Chehab | 7fee03e | 2009-12-02 15:56:47 -0300 | [diff] [blame] | 434 | |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 435 | spin_lock_irqsave(&rc_map->lock, flags); |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 436 | |
| 437 | if (ke->flags & INPUT_KEYMAP_BY_INDEX) { |
| 438 | index = ke->index; |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 439 | if (index >= rc_map->len) { |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 440 | retval = -EINVAL; |
| 441 | goto out; |
| 442 | } |
| 443 | } else { |
Sean Young | e6c6d7d | 2020-01-17 17:46:36 +0100 | [diff] [blame] | 444 | retval = scancode_to_u64(ke, &scancode); |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 445 | if (retval) |
| 446 | goto out; |
| 447 | |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 448 | index = ir_establish_scancode(rdev, rc_map, scancode, true); |
| 449 | if (index >= rc_map->len) { |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 450 | retval = -ENOMEM; |
| 451 | goto out; |
| 452 | } |
| 453 | } |
| 454 | |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 455 | *old_keycode = ir_update_mapping(rdev, rc_map, index, ke->keycode); |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 456 | |
| 457 | out: |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 458 | spin_unlock_irqrestore(&rc_map->lock, flags); |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 459 | return retval; |
Mauro Carvalho Chehab | 7fee03e | 2009-12-02 15:56:47 -0300 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | /** |
David Härdeman | b3074c0 | 2010-04-02 15:58:28 -0300 | [diff] [blame] | 463 | * ir_setkeytable() - sets several entries in the scancode->keycode table |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 464 | * @dev: the struct rc_dev device descriptor |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 465 | * @from: the struct rc_map to copy entries from |
Mauro Carvalho Chehab | f6fc504 | 2009-11-29 11:08:02 -0300 | [diff] [blame] | 466 | * |
David Härdeman | b3074c0 | 2010-04-02 15:58:28 -0300 | [diff] [blame] | 467 | * This routine is used to handle table initialization. |
Mauro Carvalho Chehab | f67f366 | 2017-11-27 08:35:13 -0500 | [diff] [blame] | 468 | * |
| 469 | * return: -ENOMEM if all keycodes could not be inserted, otherwise zero. |
Mauro Carvalho Chehab | f6fc504 | 2009-11-29 11:08:02 -0300 | [diff] [blame] | 470 | */ |
Sean Young | e6c6d7d | 2020-01-17 17:46:36 +0100 | [diff] [blame] | 471 | static int ir_setkeytable(struct rc_dev *dev, const struct rc_map *from) |
Mauro Carvalho Chehab | f6fc504 | 2009-11-29 11:08:02 -0300 | [diff] [blame] | 472 | { |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 473 | struct rc_map *rc_map = &dev->rc_map; |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 474 | unsigned int i, index; |
| 475 | int rc; |
Mauro Carvalho Chehab | f6fc504 | 2009-11-29 11:08:02 -0300 | [diff] [blame] | 476 | |
Sean Young | 1f17f68 | 2018-02-12 07:27:50 -0500 | [diff] [blame] | 477 | rc = ir_create_table(dev, rc_map, from->name, from->rc_proto, |
| 478 | from->size); |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 479 | if (rc) |
| 480 | return rc; |
| 481 | |
David Härdeman | b3074c0 | 2010-04-02 15:58:28 -0300 | [diff] [blame] | 482 | for (i = 0; i < from->size; i++) { |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 483 | index = ir_establish_scancode(dev, rc_map, |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 484 | from->scan[i].scancode, false); |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 485 | if (index >= rc_map->len) { |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 486 | rc = -ENOMEM; |
David Härdeman | b3074c0 | 2010-04-02 15:58:28 -0300 | [diff] [blame] | 487 | break; |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 488 | } |
| 489 | |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 490 | ir_update_mapping(dev, rc_map, index, |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 491 | from->scan[i].keycode); |
Mauro Carvalho Chehab | f6fc504 | 2009-11-29 11:08:02 -0300 | [diff] [blame] | 492 | } |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 493 | |
| 494 | if (rc) |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 495 | ir_free_table(rc_map); |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 496 | |
David Härdeman | b3074c0 | 2010-04-02 15:58:28 -0300 | [diff] [blame] | 497 | return rc; |
Mauro Carvalho Chehab | f6fc504 | 2009-11-29 11:08:02 -0300 | [diff] [blame] | 498 | } |
| 499 | |
Thomas Meyer | 8ca01d4 | 2017-09-08 13:33:36 -0300 | [diff] [blame] | 500 | static int rc_map_cmp(const void *key, const void *elt) |
| 501 | { |
Sean Young | e6c6d7d | 2020-01-17 17:46:36 +0100 | [diff] [blame] | 502 | const u64 *scancode = key; |
Thomas Meyer | 8ca01d4 | 2017-09-08 13:33:36 -0300 | [diff] [blame] | 503 | const struct rc_map_table *e = elt; |
| 504 | |
| 505 | if (*scancode < e->scancode) |
| 506 | return -1; |
| 507 | else if (*scancode > e->scancode) |
| 508 | return 1; |
| 509 | return 0; |
| 510 | } |
| 511 | |
Mauro Carvalho Chehab | ef53a11 | 2009-11-27 22:01:23 -0300 | [diff] [blame] | 512 | /** |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 513 | * ir_lookup_by_scancode() - locate mapping by scancode |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 514 | * @rc_map: the struct rc_map to search |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 515 | * @scancode: scancode to look for in the table |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 516 | * |
| 517 | * This routine performs binary search in RC keykeymap table for |
| 518 | * given scancode. |
Mauro Carvalho Chehab | f67f366 | 2017-11-27 08:35:13 -0500 | [diff] [blame] | 519 | * |
| 520 | * return: index in the table, -1U if not found |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 521 | */ |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 522 | static unsigned int ir_lookup_by_scancode(const struct rc_map *rc_map, |
Sean Young | e6c6d7d | 2020-01-17 17:46:36 +0100 | [diff] [blame] | 523 | u64 scancode) |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 524 | { |
Thomas Meyer | 8ca01d4 | 2017-09-08 13:33:36 -0300 | [diff] [blame] | 525 | struct rc_map_table *res; |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 526 | |
Thomas Meyer | 8ca01d4 | 2017-09-08 13:33:36 -0300 | [diff] [blame] | 527 | res = bsearch(&scancode, rc_map->scan, rc_map->len, |
| 528 | sizeof(struct rc_map_table), rc_map_cmp); |
| 529 | if (!res) |
| 530 | return -1U; |
| 531 | else |
| 532 | return res - rc_map->scan; |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | /** |
David Härdeman | b3074c0 | 2010-04-02 15:58:28 -0300 | [diff] [blame] | 536 | * ir_getkeycode() - get a keycode from the scancode->keycode table |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 537 | * @idev: the struct input_dev device descriptor |
Mauro Carvalho Chehab | f67f366 | 2017-11-27 08:35:13 -0500 | [diff] [blame] | 538 | * @ke: Input keymap entry |
Mauro Carvalho Chehab | ef53a11 | 2009-11-27 22:01:23 -0300 | [diff] [blame] | 539 | * |
| 540 | * This routine is used to handle evdev EVIOCGKEY ioctl. |
Mauro Carvalho Chehab | f67f366 | 2017-11-27 08:35:13 -0500 | [diff] [blame] | 541 | * |
| 542 | * return: always returns zero. |
Mauro Carvalho Chehab | ef53a11 | 2009-11-27 22:01:23 -0300 | [diff] [blame] | 543 | */ |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 544 | static int ir_getkeycode(struct input_dev *idev, |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 545 | struct input_keymap_entry *ke) |
Mauro Carvalho Chehab | ef53a11 | 2009-11-27 22:01:23 -0300 | [diff] [blame] | 546 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 547 | struct rc_dev *rdev = input_get_drvdata(idev); |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 548 | struct rc_map *rc_map = &rdev->rc_map; |
Mauro Carvalho Chehab | 2f4f58d | 2010-11-17 15:46:09 -0300 | [diff] [blame] | 549 | struct rc_map_table *entry; |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 550 | unsigned long flags; |
| 551 | unsigned int index; |
Sean Young | e6c6d7d | 2020-01-17 17:46:36 +0100 | [diff] [blame] | 552 | u64 scancode; |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 553 | int retval; |
Mauro Carvalho Chehab | ef53a11 | 2009-11-27 22:01:23 -0300 | [diff] [blame] | 554 | |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 555 | spin_lock_irqsave(&rc_map->lock, flags); |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 556 | |
| 557 | if (ke->flags & INPUT_KEYMAP_BY_INDEX) { |
| 558 | index = ke->index; |
| 559 | } else { |
Sean Young | e6c6d7d | 2020-01-17 17:46:36 +0100 | [diff] [blame] | 560 | retval = scancode_to_u64(ke, &scancode); |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 561 | if (retval) |
| 562 | goto out; |
| 563 | |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 564 | index = ir_lookup_by_scancode(rc_map, scancode); |
Mauro Carvalho Chehab | e97f467 | 2009-12-04 17:17:47 -0300 | [diff] [blame] | 565 | } |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 566 | |
Dmitry Torokhov | 54e74b8 | 2011-01-28 23:33:29 -0800 | [diff] [blame] | 567 | if (index < rc_map->len) { |
| 568 | entry = &rc_map->scan[index]; |
| 569 | |
| 570 | ke->index = index; |
| 571 | ke->keycode = entry->keycode; |
| 572 | ke->len = sizeof(entry->scancode); |
| 573 | memcpy(ke->scancode, &entry->scancode, sizeof(entry->scancode)); |
Dmitry Torokhov | 54e74b8 | 2011-01-28 23:33:29 -0800 | [diff] [blame] | 574 | } else if (!(ke->flags & INPUT_KEYMAP_BY_INDEX)) { |
| 575 | /* |
| 576 | * We do not really know the valid range of scancodes |
| 577 | * so let's respond with KEY_RESERVED to anything we |
| 578 | * do not have mapping for [yet]. |
| 579 | */ |
| 580 | ke->index = index; |
| 581 | ke->keycode = KEY_RESERVED; |
| 582 | } else { |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 583 | retval = -EINVAL; |
| 584 | goto out; |
| 585 | } |
| 586 | |
Dmitry Torokhov | 47c5ba5 | 2010-10-31 15:18:42 -0700 | [diff] [blame] | 587 | retval = 0; |
| 588 | |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 589 | out: |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 590 | spin_unlock_irqrestore(&rc_map->lock, flags); |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 591 | return retval; |
Mauro Carvalho Chehab | ef53a11 | 2009-11-27 22:01:23 -0300 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | /** |
Mauro Carvalho Chehab | ca86674 | 2010-11-17 13:53:11 -0300 | [diff] [blame] | 595 | * rc_g_keycode_from_table() - gets the keycode that corresponds to a scancode |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 596 | * @dev: the struct rc_dev descriptor of the device |
| 597 | * @scancode: the scancode to look for |
Mauro Carvalho Chehab | ef53a11 | 2009-11-27 22:01:23 -0300 | [diff] [blame] | 598 | * |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 599 | * This routine is used by drivers which need to convert a scancode to a |
| 600 | * keycode. Normally it should not be used since drivers should have no |
| 601 | * interest in keycodes. |
Mauro Carvalho Chehab | f67f366 | 2017-11-27 08:35:13 -0500 | [diff] [blame] | 602 | * |
| 603 | * return: the corresponding keycode, or KEY_RESERVED |
Mauro Carvalho Chehab | ef53a11 | 2009-11-27 22:01:23 -0300 | [diff] [blame] | 604 | */ |
Sean Young | e6c6d7d | 2020-01-17 17:46:36 +0100 | [diff] [blame] | 605 | u32 rc_g_keycode_from_table(struct rc_dev *dev, u64 scancode) |
Mauro Carvalho Chehab | ef53a11 | 2009-11-27 22:01:23 -0300 | [diff] [blame] | 606 | { |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 607 | struct rc_map *rc_map = &dev->rc_map; |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 608 | unsigned int keycode; |
| 609 | unsigned int index; |
| 610 | unsigned long flags; |
Mauro Carvalho Chehab | ef53a11 | 2009-11-27 22:01:23 -0300 | [diff] [blame] | 611 | |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 612 | spin_lock_irqsave(&rc_map->lock, flags); |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 613 | |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 614 | index = ir_lookup_by_scancode(rc_map, scancode); |
| 615 | keycode = index < rc_map->len ? |
| 616 | rc_map->scan[index].keycode : KEY_RESERVED; |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 617 | |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 618 | spin_unlock_irqrestore(&rc_map->lock, flags); |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 619 | |
Mauro Carvalho Chehab | 3543894 | 2010-04-03 16:53:16 -0300 | [diff] [blame] | 620 | if (keycode != KEY_RESERVED) |
Sean Young | e6c6d7d | 2020-01-17 17:46:36 +0100 | [diff] [blame] | 621 | dev_dbg(&dev->dev, "%s: scancode 0x%04llx keycode 0x%02x\n", |
Sean Young | 1f17f68 | 2018-02-12 07:27:50 -0500 | [diff] [blame] | 622 | dev->device_name, scancode, keycode); |
Dmitry Torokhov | 9f47009 | 2010-09-09 21:59:11 -0700 | [diff] [blame] | 623 | |
David Härdeman | b3074c0 | 2010-04-02 15:58:28 -0300 | [diff] [blame] | 624 | return keycode; |
Mauro Carvalho Chehab | ef53a11 | 2009-11-27 22:01:23 -0300 | [diff] [blame] | 625 | } |
Mauro Carvalho Chehab | ca86674 | 2010-11-17 13:53:11 -0300 | [diff] [blame] | 626 | EXPORT_SYMBOL_GPL(rc_g_keycode_from_table); |
Mauro Carvalho Chehab | ef53a11 | 2009-11-27 22:01:23 -0300 | [diff] [blame] | 627 | |
| 628 | /** |
David Härdeman | 62c6503 | 2010-10-29 16:08:07 -0300 | [diff] [blame] | 629 | * ir_do_keyup() - internal function to signal the release of a keypress |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 630 | * @dev: the struct rc_dev descriptor of the device |
Jarod Wilson | 98c32bc | 2011-06-23 10:40:55 -0300 | [diff] [blame] | 631 | * @sync: whether or not to call input_sync |
Mauro Carvalho Chehab | 6660de5 | 2010-03-21 12:15:16 -0300 | [diff] [blame] | 632 | * |
David Härdeman | 62c6503 | 2010-10-29 16:08:07 -0300 | [diff] [blame] | 633 | * This function is used internally to release a keypress, it must be |
| 634 | * called with keylock held. |
Mauro Carvalho Chehab | 6660de5 | 2010-03-21 12:15:16 -0300 | [diff] [blame] | 635 | */ |
Jarod Wilson | 98c32bc | 2011-06-23 10:40:55 -0300 | [diff] [blame] | 636 | static void ir_do_keyup(struct rc_dev *dev, bool sync) |
Mauro Carvalho Chehab | 6660de5 | 2010-03-21 12:15:16 -0300 | [diff] [blame] | 637 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 638 | if (!dev->keypressed) |
Mauro Carvalho Chehab | 6660de5 | 2010-03-21 12:15:16 -0300 | [diff] [blame] | 639 | return; |
| 640 | |
Sean Young | 1f17f68 | 2018-02-12 07:27:50 -0500 | [diff] [blame] | 641 | dev_dbg(&dev->dev, "keyup key 0x%04x\n", dev->last_keycode); |
Sean Young | fb7ccc6 | 2017-12-03 08:55:24 -0500 | [diff] [blame] | 642 | del_timer(&dev->timer_repeat); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 643 | input_report_key(dev->input_dev, dev->last_keycode, 0); |
Sean Young | 153a60b | 2013-07-30 19:00:01 -0300 | [diff] [blame] | 644 | led_trigger_event(led_feedback, LED_OFF); |
Jarod Wilson | 98c32bc | 2011-06-23 10:40:55 -0300 | [diff] [blame] | 645 | if (sync) |
| 646 | input_sync(dev->input_dev); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 647 | dev->keypressed = false; |
Mauro Carvalho Chehab | 6660de5 | 2010-03-21 12:15:16 -0300 | [diff] [blame] | 648 | } |
David Härdeman | 62c6503 | 2010-10-29 16:08:07 -0300 | [diff] [blame] | 649 | |
| 650 | /** |
Mauro Carvalho Chehab | ca86674 | 2010-11-17 13:53:11 -0300 | [diff] [blame] | 651 | * rc_keyup() - signals the release of a keypress |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 652 | * @dev: the struct rc_dev descriptor of the device |
David Härdeman | 62c6503 | 2010-10-29 16:08:07 -0300 | [diff] [blame] | 653 | * |
| 654 | * This routine is used to signal that a key has been released on the |
| 655 | * remote control. |
| 656 | */ |
Mauro Carvalho Chehab | ca86674 | 2010-11-17 13:53:11 -0300 | [diff] [blame] | 657 | void rc_keyup(struct rc_dev *dev) |
David Härdeman | 62c6503 | 2010-10-29 16:08:07 -0300 | [diff] [blame] | 658 | { |
| 659 | unsigned long flags; |
David Härdeman | 62c6503 | 2010-10-29 16:08:07 -0300 | [diff] [blame] | 660 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 661 | spin_lock_irqsave(&dev->keylock, flags); |
Jarod Wilson | 98c32bc | 2011-06-23 10:40:55 -0300 | [diff] [blame] | 662 | ir_do_keyup(dev, true); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 663 | spin_unlock_irqrestore(&dev->keylock, flags); |
David Härdeman | 62c6503 | 2010-10-29 16:08:07 -0300 | [diff] [blame] | 664 | } |
Mauro Carvalho Chehab | ca86674 | 2010-11-17 13:53:11 -0300 | [diff] [blame] | 665 | EXPORT_SYMBOL_GPL(rc_keyup); |
David Härdeman | a374fef | 2010-04-02 15:58:29 -0300 | [diff] [blame] | 666 | |
| 667 | /** |
| 668 | * ir_timer_keyup() - generates a keyup event after a timeout |
Mauro Carvalho Chehab | f67f366 | 2017-11-27 08:35:13 -0500 | [diff] [blame] | 669 | * |
| 670 | * @t: a pointer to the struct timer_list |
David Härdeman | a374fef | 2010-04-02 15:58:29 -0300 | [diff] [blame] | 671 | * |
| 672 | * This routine will generate a keyup event some time after a keydown event |
| 673 | * is generated when no further activity has been detected. |
| 674 | */ |
Kees Cook | b17ec78 | 2017-10-24 11:23:14 -0400 | [diff] [blame] | 675 | static void ir_timer_keyup(struct timer_list *t) |
David Härdeman | a374fef | 2010-04-02 15:58:29 -0300 | [diff] [blame] | 676 | { |
Kees Cook | b17ec78 | 2017-10-24 11:23:14 -0400 | [diff] [blame] | 677 | struct rc_dev *dev = from_timer(dev, t, timer_keyup); |
David Härdeman | a374fef | 2010-04-02 15:58:29 -0300 | [diff] [blame] | 678 | unsigned long flags; |
| 679 | |
| 680 | /* |
| 681 | * ir->keyup_jiffies is used to prevent a race condition if a |
| 682 | * hardware interrupt occurs at this point and the keyup timer |
| 683 | * event is moved further into the future as a result. |
| 684 | * |
| 685 | * The timer will then be reactivated and this function called |
| 686 | * again in the future. We need to exit gracefully in that case |
| 687 | * to allow the input subsystem to do its auto-repeat magic or |
| 688 | * a keyup event might follow immediately after the keydown. |
| 689 | */ |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 690 | spin_lock_irqsave(&dev->keylock, flags); |
| 691 | if (time_is_before_eq_jiffies(dev->keyup_jiffies)) |
Jarod Wilson | 98c32bc | 2011-06-23 10:40:55 -0300 | [diff] [blame] | 692 | ir_do_keyup(dev, true); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 693 | spin_unlock_irqrestore(&dev->keylock, flags); |
David Härdeman | a374fef | 2010-04-02 15:58:29 -0300 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | /** |
Sean Young | 57c642c | 2017-11-23 17:37:10 -0500 | [diff] [blame] | 697 | * ir_timer_repeat() - generates a repeat event after a timeout |
| 698 | * |
| 699 | * @t: a pointer to the struct timer_list |
| 700 | * |
| 701 | * This routine will generate a soft repeat event every REP_PERIOD |
| 702 | * milliseconds. |
| 703 | */ |
| 704 | static void ir_timer_repeat(struct timer_list *t) |
| 705 | { |
| 706 | struct rc_dev *dev = from_timer(dev, t, timer_repeat); |
| 707 | struct input_dev *input = dev->input_dev; |
| 708 | unsigned long flags; |
| 709 | |
| 710 | spin_lock_irqsave(&dev->keylock, flags); |
| 711 | if (dev->keypressed) { |
| 712 | input_event(input, EV_KEY, dev->last_keycode, 2); |
| 713 | input_sync(input); |
| 714 | if (input->rep[REP_PERIOD]) |
| 715 | mod_timer(&dev->timer_repeat, jiffies + |
| 716 | msecs_to_jiffies(input->rep[REP_PERIOD])); |
| 717 | } |
| 718 | spin_unlock_irqrestore(&dev->keylock, flags); |
| 719 | } |
| 720 | |
Sean Young | f5dbee6 | 2018-07-28 05:11:15 -0400 | [diff] [blame] | 721 | static unsigned int repeat_period(int protocol) |
| 722 | { |
| 723 | if (protocol >= ARRAY_SIZE(protocols)) |
| 724 | return 100; |
| 725 | |
| 726 | return protocols[protocol].repeat_period; |
| 727 | } |
| 728 | |
Sean Young | 57c642c | 2017-11-23 17:37:10 -0500 | [diff] [blame] | 729 | /** |
Mauro Carvalho Chehab | ca86674 | 2010-11-17 13:53:11 -0300 | [diff] [blame] | 730 | * rc_repeat() - signals that a key is still pressed |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 731 | * @dev: the struct rc_dev descriptor of the device |
David Härdeman | a374fef | 2010-04-02 15:58:29 -0300 | [diff] [blame] | 732 | * |
| 733 | * This routine is used by IR decoders when a repeat message which does |
| 734 | * not include the necessary bits to reproduce the scancode has been |
| 735 | * received. |
| 736 | */ |
Mauro Carvalho Chehab | ca86674 | 2010-11-17 13:53:11 -0300 | [diff] [blame] | 737 | void rc_repeat(struct rc_dev *dev) |
David Härdeman | a374fef | 2010-04-02 15:58:29 -0300 | [diff] [blame] | 738 | { |
| 739 | unsigned long flags; |
Matthias Reichl | 06b8315 | 2021-01-05 10:30:23 +0100 | [diff] [blame] | 740 | unsigned int timeout = usecs_to_jiffies(dev->timeout) + |
Sean Young | f5dbee6 | 2018-07-28 05:11:15 -0400 | [diff] [blame] | 741 | msecs_to_jiffies(repeat_period(dev->last_protocol)); |
Sean Young | b66218f | 2017-09-30 07:13:37 -0400 | [diff] [blame] | 742 | struct lirc_scancode sc = { |
| 743 | .scancode = dev->last_scancode, .rc_proto = dev->last_protocol, |
| 744 | .keycode = dev->keypressed ? dev->last_keycode : KEY_RESERVED, |
| 745 | .flags = LIRC_SCANCODE_FLAG_REPEAT | |
| 746 | (dev->last_toggle ? LIRC_SCANCODE_FLAG_TOGGLE : 0) |
| 747 | }; |
| 748 | |
Sean Young | e5bb9d3 | 2018-10-22 05:01:50 -0400 | [diff] [blame] | 749 | if (dev->allowed_protocols != RC_PROTO_BIT_CEC) |
Sean Young | 75992a4 | 2020-08-24 21:10:45 +0200 | [diff] [blame] | 750 | lirc_scancode_event(dev, &sc); |
David Härdeman | a374fef | 2010-04-02 15:58:29 -0300 | [diff] [blame] | 751 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 752 | spin_lock_irqsave(&dev->keylock, flags); |
David Härdeman | a374fef | 2010-04-02 15:58:29 -0300 | [diff] [blame] | 753 | |
Sean Young | e6c6d7d | 2020-01-17 17:46:36 +0100 | [diff] [blame] | 754 | if (dev->last_scancode <= U32_MAX) { |
| 755 | input_event(dev->input_dev, EV_MSC, MSC_SCAN, |
| 756 | dev->last_scancode); |
| 757 | input_sync(dev->input_dev); |
| 758 | } |
David Härdeman | 265a298 | 2017-06-22 15:23:54 -0400 | [diff] [blame] | 759 | |
Sean Young | b66218f | 2017-09-30 07:13:37 -0400 | [diff] [blame] | 760 | if (dev->keypressed) { |
Sean Young | 2849225 | 2018-03-24 08:02:48 -0400 | [diff] [blame] | 761 | dev->keyup_jiffies = jiffies + timeout; |
Sean Young | b66218f | 2017-09-30 07:13:37 -0400 | [diff] [blame] | 762 | mod_timer(&dev->timer_keyup, dev->keyup_jiffies); |
| 763 | } |
David Härdeman | a374fef | 2010-04-02 15:58:29 -0300 | [diff] [blame] | 764 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 765 | spin_unlock_irqrestore(&dev->keylock, flags); |
David Härdeman | a374fef | 2010-04-02 15:58:29 -0300 | [diff] [blame] | 766 | } |
Mauro Carvalho Chehab | ca86674 | 2010-11-17 13:53:11 -0300 | [diff] [blame] | 767 | EXPORT_SYMBOL_GPL(rc_repeat); |
Mauro Carvalho Chehab | 6660de5 | 2010-03-21 12:15:16 -0300 | [diff] [blame] | 768 | |
| 769 | /** |
David Härdeman | 62c6503 | 2010-10-29 16:08:07 -0300 | [diff] [blame] | 770 | * ir_do_keydown() - internal function to process a keypress |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 771 | * @dev: the struct rc_dev descriptor of the device |
David Härdeman | 120703f | 2014-04-03 20:31:30 -0300 | [diff] [blame] | 772 | * @protocol: the protocol of the keypress |
David Härdeman | 62c6503 | 2010-10-29 16:08:07 -0300 | [diff] [blame] | 773 | * @scancode: the scancode of the keypress |
| 774 | * @keycode: the keycode of the keypress |
| 775 | * @toggle: the toggle value of the keypress |
| 776 | * |
| 777 | * This function is used internally to register a keypress, it must be |
| 778 | * called with keylock held. |
| 779 | */ |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 780 | static void ir_do_keydown(struct rc_dev *dev, enum rc_proto protocol, |
Sean Young | e6c6d7d | 2020-01-17 17:46:36 +0100 | [diff] [blame] | 781 | u64 scancode, u32 keycode, u8 toggle) |
David Härdeman | 62c6503 | 2010-10-29 16:08:07 -0300 | [diff] [blame] | 782 | { |
David Härdeman | 99b0f3c | 2014-04-04 19:06:06 -0300 | [diff] [blame] | 783 | bool new_event = (!dev->keypressed || |
David Härdeman | 120703f | 2014-04-03 20:31:30 -0300 | [diff] [blame] | 784 | dev->last_protocol != protocol || |
David Härdeman | 99b0f3c | 2014-04-04 19:06:06 -0300 | [diff] [blame] | 785 | dev->last_scancode != scancode || |
David Härdeman | 120703f | 2014-04-03 20:31:30 -0300 | [diff] [blame] | 786 | dev->last_toggle != toggle); |
Sean Young | de142c3 | 2017-02-25 06:51:32 -0500 | [diff] [blame] | 787 | struct lirc_scancode sc = { |
| 788 | .scancode = scancode, .rc_proto = protocol, |
| 789 | .flags = toggle ? LIRC_SCANCODE_FLAG_TOGGLE : 0, |
| 790 | .keycode = keycode |
| 791 | }; |
| 792 | |
Sean Young | e5bb9d3 | 2018-10-22 05:01:50 -0400 | [diff] [blame] | 793 | if (dev->allowed_protocols != RC_PROTO_BIT_CEC) |
Sean Young | 75992a4 | 2020-08-24 21:10:45 +0200 | [diff] [blame] | 794 | lirc_scancode_event(dev, &sc); |
Jarod Wilson | 98c32bc | 2011-06-23 10:40:55 -0300 | [diff] [blame] | 795 | |
| 796 | if (new_event && dev->keypressed) |
| 797 | ir_do_keyup(dev, false); |
| 798 | |
Sean Young | e6c6d7d | 2020-01-17 17:46:36 +0100 | [diff] [blame] | 799 | if (scancode <= U32_MAX) |
| 800 | input_event(dev->input_dev, EV_MSC, MSC_SCAN, scancode); |
David Härdeman | 62c6503 | 2010-10-29 16:08:07 -0300 | [diff] [blame] | 801 | |
Sean Young | b66218f | 2017-09-30 07:13:37 -0400 | [diff] [blame] | 802 | dev->last_protocol = protocol; |
| 803 | dev->last_scancode = scancode; |
| 804 | dev->last_toggle = toggle; |
| 805 | dev->last_keycode = keycode; |
| 806 | |
Jarod Wilson | 98c32bc | 2011-06-23 10:40:55 -0300 | [diff] [blame] | 807 | if (new_event && keycode != KEY_RESERVED) { |
| 808 | /* Register a keypress */ |
| 809 | dev->keypressed = true; |
David Härdeman | 62c6503 | 2010-10-29 16:08:07 -0300 | [diff] [blame] | 810 | |
Sean Young | e6c6d7d | 2020-01-17 17:46:36 +0100 | [diff] [blame] | 811 | dev_dbg(&dev->dev, "%s: key down event, key 0x%04x, protocol 0x%04x, scancode 0x%08llx\n", |
Sean Young | 1f17f68 | 2018-02-12 07:27:50 -0500 | [diff] [blame] | 812 | dev->device_name, keycode, protocol, scancode); |
Jarod Wilson | 98c32bc | 2011-06-23 10:40:55 -0300 | [diff] [blame] | 813 | input_report_key(dev->input_dev, keycode, 1); |
James Hogan | 70a2f91 | 2014-01-16 19:56:22 -0300 | [diff] [blame] | 814 | |
| 815 | led_trigger_event(led_feedback, LED_FULL); |
Jarod Wilson | 98c32bc | 2011-06-23 10:40:55 -0300 | [diff] [blame] | 816 | } |
David Härdeman | 62c6503 | 2010-10-29 16:08:07 -0300 | [diff] [blame] | 817 | |
Sean Young | 57c642c | 2017-11-23 17:37:10 -0500 | [diff] [blame] | 818 | /* |
| 819 | * For CEC, start sending repeat messages as soon as the first |
| 820 | * repeated message is sent, as long as REP_DELAY = 0 and REP_PERIOD |
| 821 | * is non-zero. Otherwise, the input layer will generate repeat |
| 822 | * messages. |
| 823 | */ |
| 824 | if (!new_event && keycode != KEY_RESERVED && |
| 825 | dev->allowed_protocols == RC_PROTO_BIT_CEC && |
| 826 | !timer_pending(&dev->timer_repeat) && |
| 827 | dev->input_dev->rep[REP_PERIOD] && |
| 828 | !dev->input_dev->rep[REP_DELAY]) { |
| 829 | input_event(dev->input_dev, EV_KEY, keycode, 2); |
| 830 | mod_timer(&dev->timer_repeat, jiffies + |
| 831 | msecs_to_jiffies(dev->input_dev->rep[REP_PERIOD])); |
| 832 | } |
| 833 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 834 | input_sync(dev->input_dev); |
David Härdeman | 62c6503 | 2010-10-29 16:08:07 -0300 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | /** |
Mauro Carvalho Chehab | ca86674 | 2010-11-17 13:53:11 -0300 | [diff] [blame] | 838 | * rc_keydown() - generates input event for a key press |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 839 | * @dev: the struct rc_dev descriptor of the device |
David Härdeman | 120703f | 2014-04-03 20:31:30 -0300 | [diff] [blame] | 840 | * @protocol: the protocol for the keypress |
| 841 | * @scancode: the scancode for the keypress |
David Härdeman | a374fef | 2010-04-02 15:58:29 -0300 | [diff] [blame] | 842 | * @toggle: the toggle value (protocol dependent, if the protocol doesn't |
| 843 | * support toggle values, this should be set to zero) |
Mauro Carvalho Chehab | 6660de5 | 2010-03-21 12:15:16 -0300 | [diff] [blame] | 844 | * |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 845 | * This routine is used to signal that a key has been pressed on the |
| 846 | * remote control. |
Mauro Carvalho Chehab | 6660de5 | 2010-03-21 12:15:16 -0300 | [diff] [blame] | 847 | */ |
Sean Young | e6c6d7d | 2020-01-17 17:46:36 +0100 | [diff] [blame] | 848 | void rc_keydown(struct rc_dev *dev, enum rc_proto protocol, u64 scancode, |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 849 | u8 toggle) |
Mauro Carvalho Chehab | 6660de5 | 2010-03-21 12:15:16 -0300 | [diff] [blame] | 850 | { |
David Härdeman | a374fef | 2010-04-02 15:58:29 -0300 | [diff] [blame] | 851 | unsigned long flags; |
Mauro Carvalho Chehab | ca86674 | 2010-11-17 13:53:11 -0300 | [diff] [blame] | 852 | u32 keycode = rc_g_keycode_from_table(dev, scancode); |
Mauro Carvalho Chehab | 6660de5 | 2010-03-21 12:15:16 -0300 | [diff] [blame] | 853 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 854 | spin_lock_irqsave(&dev->keylock, flags); |
David Härdeman | 120703f | 2014-04-03 20:31:30 -0300 | [diff] [blame] | 855 | ir_do_keydown(dev, protocol, scancode, keycode, toggle); |
Mauro Carvalho Chehab | 6660de5 | 2010-03-21 12:15:16 -0300 | [diff] [blame] | 856 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 857 | if (dev->keypressed) { |
Matthias Reichl | 06b8315 | 2021-01-05 10:30:23 +0100 | [diff] [blame] | 858 | dev->keyup_jiffies = jiffies + usecs_to_jiffies(dev->timeout) + |
Sean Young | f5dbee6 | 2018-07-28 05:11:15 -0400 | [diff] [blame] | 859 | msecs_to_jiffies(repeat_period(protocol)); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 860 | mod_timer(&dev->timer_keyup, dev->keyup_jiffies); |
David Härdeman | 62c6503 | 2010-10-29 16:08:07 -0300 | [diff] [blame] | 861 | } |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 862 | spin_unlock_irqrestore(&dev->keylock, flags); |
Mauro Carvalho Chehab | 6660de5 | 2010-03-21 12:15:16 -0300 | [diff] [blame] | 863 | } |
Mauro Carvalho Chehab | ca86674 | 2010-11-17 13:53:11 -0300 | [diff] [blame] | 864 | EXPORT_SYMBOL_GPL(rc_keydown); |
Mauro Carvalho Chehab | 6660de5 | 2010-03-21 12:15:16 -0300 | [diff] [blame] | 865 | |
David Härdeman | 62c6503 | 2010-10-29 16:08:07 -0300 | [diff] [blame] | 866 | /** |
Mauro Carvalho Chehab | ca86674 | 2010-11-17 13:53:11 -0300 | [diff] [blame] | 867 | * rc_keydown_notimeout() - generates input event for a key press without |
David Härdeman | 62c6503 | 2010-10-29 16:08:07 -0300 | [diff] [blame] | 868 | * an automatic keyup event at a later time |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 869 | * @dev: the struct rc_dev descriptor of the device |
David Härdeman | 120703f | 2014-04-03 20:31:30 -0300 | [diff] [blame] | 870 | * @protocol: the protocol for the keypress |
| 871 | * @scancode: the scancode for the keypress |
David Härdeman | 62c6503 | 2010-10-29 16:08:07 -0300 | [diff] [blame] | 872 | * @toggle: the toggle value (protocol dependent, if the protocol doesn't |
| 873 | * support toggle values, this should be set to zero) |
| 874 | * |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 875 | * This routine is used to signal that a key has been pressed on the |
Mauro Carvalho Chehab | ca86674 | 2010-11-17 13:53:11 -0300 | [diff] [blame] | 876 | * remote control. The driver must manually call rc_keyup() at a later stage. |
David Härdeman | 62c6503 | 2010-10-29 16:08:07 -0300 | [diff] [blame] | 877 | */ |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 878 | void rc_keydown_notimeout(struct rc_dev *dev, enum rc_proto protocol, |
Sean Young | e6c6d7d | 2020-01-17 17:46:36 +0100 | [diff] [blame] | 879 | u64 scancode, u8 toggle) |
David Härdeman | 62c6503 | 2010-10-29 16:08:07 -0300 | [diff] [blame] | 880 | { |
| 881 | unsigned long flags; |
Mauro Carvalho Chehab | ca86674 | 2010-11-17 13:53:11 -0300 | [diff] [blame] | 882 | u32 keycode = rc_g_keycode_from_table(dev, scancode); |
David Härdeman | 62c6503 | 2010-10-29 16:08:07 -0300 | [diff] [blame] | 883 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 884 | spin_lock_irqsave(&dev->keylock, flags); |
David Härdeman | 120703f | 2014-04-03 20:31:30 -0300 | [diff] [blame] | 885 | ir_do_keydown(dev, protocol, scancode, keycode, toggle); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 886 | spin_unlock_irqrestore(&dev->keylock, flags); |
David Härdeman | 62c6503 | 2010-10-29 16:08:07 -0300 | [diff] [blame] | 887 | } |
Mauro Carvalho Chehab | ca86674 | 2010-11-17 13:53:11 -0300 | [diff] [blame] | 888 | EXPORT_SYMBOL_GPL(rc_keydown_notimeout); |
David Härdeman | 62c6503 | 2010-10-29 16:08:07 -0300 | [diff] [blame] | 889 | |
Sean Young | b590c0b | 2016-12-05 19:24:59 -0200 | [diff] [blame] | 890 | /** |
Sean Young | 6b514c4 | 2017-10-09 16:32:41 -0400 | [diff] [blame] | 891 | * rc_validate_scancode() - checks that a scancode is valid for a protocol. |
| 892 | * For nec, it should do the opposite of ir_nec_bytes_to_scancode() |
Sean Young | 49a4b36 | 2017-09-27 16:00:49 -0400 | [diff] [blame] | 893 | * @proto: protocol |
| 894 | * @scancode: scancode |
| 895 | */ |
| 896 | bool rc_validate_scancode(enum rc_proto proto, u32 scancode) |
| 897 | { |
| 898 | switch (proto) { |
Sean Young | 6b514c4 | 2017-10-09 16:32:41 -0400 | [diff] [blame] | 899 | /* |
| 900 | * NECX has a 16-bit address; if the lower 8 bits match the upper |
| 901 | * 8 bits inverted, then the address would match regular nec. |
| 902 | */ |
Sean Young | 49a4b36 | 2017-09-27 16:00:49 -0400 | [diff] [blame] | 903 | case RC_PROTO_NECX: |
| 904 | if ((((scancode >> 16) ^ ~(scancode >> 8)) & 0xff) == 0) |
| 905 | return false; |
| 906 | break; |
Sean Young | 6b514c4 | 2017-10-09 16:32:41 -0400 | [diff] [blame] | 907 | /* |
| 908 | * NEC32 has a 16 bit address and 16 bit command. If the lower 8 bits |
| 909 | * of the command match the upper 8 bits inverted, then it would |
| 910 | * be either NEC or NECX. |
| 911 | */ |
Sean Young | 49a4b36 | 2017-09-27 16:00:49 -0400 | [diff] [blame] | 912 | case RC_PROTO_NEC32: |
Sean Young | 6b514c4 | 2017-10-09 16:32:41 -0400 | [diff] [blame] | 913 | if ((((scancode >> 8) ^ ~scancode) & 0xff) == 0) |
Sean Young | 49a4b36 | 2017-09-27 16:00:49 -0400 | [diff] [blame] | 914 | return false; |
| 915 | break; |
Sean Young | 6b514c4 | 2017-10-09 16:32:41 -0400 | [diff] [blame] | 916 | /* |
| 917 | * If the customer code (top 32-bit) is 0x800f, it is MCE else it |
| 918 | * is regular mode-6a 32 bit |
| 919 | */ |
Sean Young | 49a4b36 | 2017-09-27 16:00:49 -0400 | [diff] [blame] | 920 | case RC_PROTO_RC6_MCE: |
| 921 | if ((scancode & 0xffff0000) != 0x800f0000) |
| 922 | return false; |
| 923 | break; |
| 924 | case RC_PROTO_RC6_6A_32: |
| 925 | if ((scancode & 0xffff0000) == 0x800f0000) |
| 926 | return false; |
| 927 | break; |
| 928 | default: |
| 929 | break; |
| 930 | } |
| 931 | |
| 932 | return true; |
| 933 | } |
| 934 | |
| 935 | /** |
Sean Young | b590c0b | 2016-12-05 19:24:59 -0200 | [diff] [blame] | 936 | * rc_validate_filter() - checks that the scancode and mask are valid and |
| 937 | * provides sensible defaults |
James Hogan | f423ccc | 2015-03-31 14:48:10 -0300 | [diff] [blame] | 938 | * @dev: the struct rc_dev descriptor of the device |
Sean Young | b590c0b | 2016-12-05 19:24:59 -0200 | [diff] [blame] | 939 | * @filter: the scancode and mask |
Mauro Carvalho Chehab | f67f366 | 2017-11-27 08:35:13 -0500 | [diff] [blame] | 940 | * |
| 941 | * return: 0 or -EINVAL if the filter is not valid |
Sean Young | b590c0b | 2016-12-05 19:24:59 -0200 | [diff] [blame] | 942 | */ |
James Hogan | f423ccc | 2015-03-31 14:48:10 -0300 | [diff] [blame] | 943 | static int rc_validate_filter(struct rc_dev *dev, |
Sean Young | b590c0b | 2016-12-05 19:24:59 -0200 | [diff] [blame] | 944 | struct rc_scancode_filter *filter) |
| 945 | { |
Sean Young | d57ea87 | 2017-08-09 13:19:16 -0400 | [diff] [blame] | 946 | u32 mask, s = filter->data; |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 947 | enum rc_proto protocol = dev->wakeup_protocol; |
Sean Young | b590c0b | 2016-12-05 19:24:59 -0200 | [diff] [blame] | 948 | |
Sean Young | d57ea87 | 2017-08-09 13:19:16 -0400 | [diff] [blame] | 949 | if (protocol >= ARRAY_SIZE(protocols)) |
Sean Young | 2168b41 | 2017-08-07 09:21:29 -0400 | [diff] [blame] | 950 | return -EINVAL; |
| 951 | |
Sean Young | d57ea87 | 2017-08-09 13:19:16 -0400 | [diff] [blame] | 952 | mask = protocols[protocol].scancode_bits; |
| 953 | |
Sean Young | 49a4b36 | 2017-09-27 16:00:49 -0400 | [diff] [blame] | 954 | if (!rc_validate_scancode(protocol, s)) |
| 955 | return -EINVAL; |
Sean Young | b590c0b | 2016-12-05 19:24:59 -0200 | [diff] [blame] | 956 | |
Sean Young | d57ea87 | 2017-08-09 13:19:16 -0400 | [diff] [blame] | 957 | filter->data &= mask; |
| 958 | filter->mask &= mask; |
Sean Young | b590c0b | 2016-12-05 19:24:59 -0200 | [diff] [blame] | 959 | |
James Hogan | f423ccc | 2015-03-31 14:48:10 -0300 | [diff] [blame] | 960 | /* |
| 961 | * If we have to raw encode the IR for wakeup, we cannot have a mask |
| 962 | */ |
Sean Young | d57ea87 | 2017-08-09 13:19:16 -0400 | [diff] [blame] | 963 | if (dev->encode_wakeup && filter->mask != 0 && filter->mask != mask) |
James Hogan | f423ccc | 2015-03-31 14:48:10 -0300 | [diff] [blame] | 964 | return -EINVAL; |
| 965 | |
Sean Young | b590c0b | 2016-12-05 19:24:59 -0200 | [diff] [blame] | 966 | return 0; |
| 967 | } |
| 968 | |
Srinivas Kandagatla | 8b2ff32 | 2013-07-22 04:22:57 -0300 | [diff] [blame] | 969 | int rc_open(struct rc_dev *rdev) |
| 970 | { |
| 971 | int rval = 0; |
| 972 | |
| 973 | if (!rdev) |
| 974 | return -EINVAL; |
| 975 | |
| 976 | mutex_lock(&rdev->lock); |
Mauro Carvalho Chehab | c73bbaa | 2016-02-11 10:33:31 -0200 | [diff] [blame] | 977 | |
Sean Young | cb84343 | 2017-09-23 17:44:03 -0400 | [diff] [blame] | 978 | if (!rdev->registered) { |
| 979 | rval = -ENODEV; |
| 980 | } else { |
| 981 | if (!rdev->users++ && rdev->open) |
| 982 | rval = rdev->open(rdev); |
Srinivas Kandagatla | 8b2ff32 | 2013-07-22 04:22:57 -0300 | [diff] [blame] | 983 | |
Sean Young | cb84343 | 2017-09-23 17:44:03 -0400 | [diff] [blame] | 984 | if (rval) |
| 985 | rdev->users--; |
| 986 | } |
Srinivas Kandagatla | 8b2ff32 | 2013-07-22 04:22:57 -0300 | [diff] [blame] | 987 | |
| 988 | mutex_unlock(&rdev->lock); |
| 989 | |
| 990 | return rval; |
| 991 | } |
Srinivas Kandagatla | 8b2ff32 | 2013-07-22 04:22:57 -0300 | [diff] [blame] | 992 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 993 | static int ir_open(struct input_dev *idev) |
Mauro Carvalho Chehab | 716aab4 | 2010-03-31 14:40:35 -0300 | [diff] [blame] | 994 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 995 | struct rc_dev *rdev = input_get_drvdata(idev); |
Mauro Carvalho Chehab | 716aab4 | 2010-03-31 14:40:35 -0300 | [diff] [blame] | 996 | |
Srinivas Kandagatla | 8b2ff32 | 2013-07-22 04:22:57 -0300 | [diff] [blame] | 997 | return rc_open(rdev); |
Mauro Carvalho Chehab | 716aab4 | 2010-03-31 14:40:35 -0300 | [diff] [blame] | 998 | } |
| 999 | |
Srinivas Kandagatla | 8b2ff32 | 2013-07-22 04:22:57 -0300 | [diff] [blame] | 1000 | void rc_close(struct rc_dev *rdev) |
| 1001 | { |
| 1002 | if (rdev) { |
| 1003 | mutex_lock(&rdev->lock); |
| 1004 | |
Sean Young | cb84343 | 2017-09-23 17:44:03 -0400 | [diff] [blame] | 1005 | if (!--rdev->users && rdev->close && rdev->registered) |
Srinivas Kandagatla | 8b2ff32 | 2013-07-22 04:22:57 -0300 | [diff] [blame] | 1006 | rdev->close(rdev); |
| 1007 | |
| 1008 | mutex_unlock(&rdev->lock); |
| 1009 | } |
| 1010 | } |
Srinivas Kandagatla | 8b2ff32 | 2013-07-22 04:22:57 -0300 | [diff] [blame] | 1011 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1012 | static void ir_close(struct input_dev *idev) |
Mauro Carvalho Chehab | 716aab4 | 2010-03-31 14:40:35 -0300 | [diff] [blame] | 1013 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1014 | struct rc_dev *rdev = input_get_drvdata(idev); |
Srinivas Kandagatla | 8b2ff32 | 2013-07-22 04:22:57 -0300 | [diff] [blame] | 1015 | rc_close(rdev); |
Mauro Carvalho Chehab | 716aab4 | 2010-03-31 14:40:35 -0300 | [diff] [blame] | 1016 | } |
Mauro Carvalho Chehab | 6660de5 | 2010-03-21 12:15:16 -0300 | [diff] [blame] | 1017 | |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1018 | /* class for /sys/class/rc */ |
David Härdeman | 40fc532 | 2013-03-06 16:52:10 -0300 | [diff] [blame] | 1019 | static char *rc_devnode(struct device *dev, umode_t *mode) |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1020 | { |
| 1021 | return kasprintf(GFP_KERNEL, "rc/%s", dev_name(dev)); |
| 1022 | } |
| 1023 | |
David Härdeman | 40fc532 | 2013-03-06 16:52:10 -0300 | [diff] [blame] | 1024 | static struct class rc_class = { |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1025 | .name = "rc", |
David Härdeman | 40fc532 | 2013-03-06 16:52:10 -0300 | [diff] [blame] | 1026 | .devnode = rc_devnode, |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1027 | }; |
| 1028 | |
David Härdeman | c003ab1 | 2012-10-11 19:11:54 -0300 | [diff] [blame] | 1029 | /* |
| 1030 | * These are the protocol textual descriptions that are |
| 1031 | * used by the sysfs protocols file. Note that the order |
| 1032 | * of the entries is relevant. |
| 1033 | */ |
Heiner Kallweit | 53df877 | 2015-11-16 17:52:17 -0200 | [diff] [blame] | 1034 | static const struct { |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1035 | u64 type; |
Heiner Kallweit | 53df877 | 2015-11-16 17:52:17 -0200 | [diff] [blame] | 1036 | const char *name; |
Heiner Kallweit | 9f0bf36 | 2015-11-16 17:52:08 -0200 | [diff] [blame] | 1037 | const char *module_name; |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1038 | } proto_names[] = { |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 1039 | { RC_PROTO_BIT_NONE, "none", NULL }, |
| 1040 | { RC_PROTO_BIT_OTHER, "other", NULL }, |
| 1041 | { RC_PROTO_BIT_UNKNOWN, "unknown", NULL }, |
| 1042 | { RC_PROTO_BIT_RC5 | |
| 1043 | RC_PROTO_BIT_RC5X_20, "rc-5", "ir-rc5-decoder" }, |
| 1044 | { RC_PROTO_BIT_NEC | |
| 1045 | RC_PROTO_BIT_NECX | |
| 1046 | RC_PROTO_BIT_NEC32, "nec", "ir-nec-decoder" }, |
| 1047 | { RC_PROTO_BIT_RC6_0 | |
| 1048 | RC_PROTO_BIT_RC6_6A_20 | |
| 1049 | RC_PROTO_BIT_RC6_6A_24 | |
| 1050 | RC_PROTO_BIT_RC6_6A_32 | |
| 1051 | RC_PROTO_BIT_RC6_MCE, "rc-6", "ir-rc6-decoder" }, |
| 1052 | { RC_PROTO_BIT_JVC, "jvc", "ir-jvc-decoder" }, |
| 1053 | { RC_PROTO_BIT_SONY12 | |
| 1054 | RC_PROTO_BIT_SONY15 | |
| 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" }, |
| 1059 | { RC_PROTO_BIT_MCIR2_KBD | |
| 1060 | RC_PROTO_BIT_MCIR2_MSE, "mce_kbd", "ir-mce_kbd-decoder" }, |
| 1061 | { RC_PROTO_BIT_XMP, "xmp", "ir-xmp-decoder" }, |
| 1062 | { RC_PROTO_BIT_CEC, "cec", NULL }, |
Sean Young | 447dcc0c | 2017-12-03 11:06:54 -0500 | [diff] [blame] | 1063 | { RC_PROTO_BIT_IMON, "imon", "ir-imon-decoder" }, |
Patrick Lerda | 721074b | 2019-01-17 03:50:13 -0500 | [diff] [blame] | 1064 | { RC_PROTO_BIT_RCMM12 | |
| 1065 | RC_PROTO_BIT_RCMM24 | |
| 1066 | RC_PROTO_BIT_RCMM32, "rc-mm", "ir-rcmm-decoder" }, |
Matthias Reichl | 1728769 | 2019-03-24 05:43:51 -0400 | [diff] [blame] | 1067 | { RC_PROTO_BIT_XBOX_DVD, "xbox-dvd", NULL }, |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1068 | }; |
| 1069 | |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1070 | /** |
James Hogan | ab88c66 | 2014-02-28 20:17:05 -0300 | [diff] [blame] | 1071 | * struct rc_filter_attribute - Device attribute relating to a filter type. |
| 1072 | * @attr: Device attribute. |
| 1073 | * @type: Filter type. |
| 1074 | * @mask: false for filter value, true for filter mask. |
| 1075 | */ |
| 1076 | struct rc_filter_attribute { |
| 1077 | struct device_attribute attr; |
| 1078 | enum rc_filter_type type; |
| 1079 | bool mask; |
| 1080 | }; |
| 1081 | #define to_rc_filter_attr(a) container_of(a, struct rc_filter_attribute, attr) |
| 1082 | |
James Hogan | ab88c66 | 2014-02-28 20:17:05 -0300 | [diff] [blame] | 1083 | #define RC_FILTER_ATTR(_name, _mode, _show, _store, _type, _mask) \ |
| 1084 | struct rc_filter_attribute dev_attr_##_name = { \ |
| 1085 | .attr = __ATTR(_name, _mode, _show, _store), \ |
| 1086 | .type = (_type), \ |
| 1087 | .mask = (_mask), \ |
| 1088 | } |
| 1089 | |
| 1090 | /** |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1091 | * show_protocols() - shows the current IR protocol(s) |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1092 | * @device: the device descriptor |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1093 | * @mattr: the device attribute struct |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1094 | * @buf: a pointer to the output buffer |
| 1095 | * |
| 1096 | * This routine is a callback routine for input read the IR protocol type(s). |
Mauro Carvalho Chehab | 04ad301 | 2019-02-18 14:29:01 -0500 | [diff] [blame] | 1097 | * it is triggered by reading /sys/class/rc/rc?/protocols. |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1098 | * It returns the protocol names of supported protocols. |
| 1099 | * Enabled protocols are printed in brackets. |
Jarod Wilson | 08aeb7c | 2011-05-11 15:14:31 -0300 | [diff] [blame] | 1100 | * |
David Härdeman | 18726a3 | 2017-04-27 17:34:08 -0300 | [diff] [blame] | 1101 | * dev->lock is taken to guard against races between |
| 1102 | * store_protocols and show_protocols. |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1103 | */ |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1104 | static ssize_t show_protocols(struct device *device, |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1105 | struct device_attribute *mattr, char *buf) |
| 1106 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1107 | struct rc_dev *dev = to_rc_dev(device); |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1108 | u64 allowed, enabled; |
| 1109 | char *tmp = buf; |
| 1110 | int i; |
| 1111 | |
Jarod Wilson | 08aeb7c | 2011-05-11 15:14:31 -0300 | [diff] [blame] | 1112 | mutex_lock(&dev->lock); |
| 1113 | |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1114 | enabled = dev->enabled_protocols; |
| 1115 | allowed = dev->allowed_protocols; |
| 1116 | if (dev->raw && !allowed) |
| 1117 | allowed = ir_raw_get_allowed_protocols(); |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1118 | |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1119 | mutex_unlock(&dev->lock); |
| 1120 | |
Sean Young | 1f17f68 | 2018-02-12 07:27:50 -0500 | [diff] [blame] | 1121 | dev_dbg(&dev->dev, "%s: allowed - 0x%llx, enabled - 0x%llx\n", |
| 1122 | __func__, (long long)allowed, (long long)enabled); |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1123 | |
| 1124 | for (i = 0; i < ARRAY_SIZE(proto_names); i++) { |
| 1125 | if (allowed & enabled & proto_names[i].type) |
| 1126 | tmp += sprintf(tmp, "[%s] ", proto_names[i].name); |
| 1127 | else if (allowed & proto_names[i].type) |
| 1128 | tmp += sprintf(tmp, "%s ", proto_names[i].name); |
David Härdeman | c003ab1 | 2012-10-11 19:11:54 -0300 | [diff] [blame] | 1129 | |
| 1130 | if (allowed & proto_names[i].type) |
| 1131 | allowed &= ~proto_names[i].type; |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1132 | } |
| 1133 | |
Sean Young | a60d64b | 2017-09-23 10:41:13 -0400 | [diff] [blame] | 1134 | #ifdef CONFIG_LIRC |
| 1135 | if (dev->driver_type == RC_DRIVER_IR_RAW) |
David Härdeman | 275ddb4 | 2015-05-19 19:03:22 -0300 | [diff] [blame] | 1136 | tmp += sprintf(tmp, "[lirc] "); |
Sean Young | a60d64b | 2017-09-23 10:41:13 -0400 | [diff] [blame] | 1137 | #endif |
David Härdeman | 275ddb4 | 2015-05-19 19:03:22 -0300 | [diff] [blame] | 1138 | |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1139 | if (tmp != buf) |
| 1140 | tmp--; |
| 1141 | *tmp = '\n'; |
Jarod Wilson | 08aeb7c | 2011-05-11 15:14:31 -0300 | [diff] [blame] | 1142 | |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1143 | return tmp + 1 - buf; |
| 1144 | } |
| 1145 | |
| 1146 | /** |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1147 | * parse_protocol_change() - parses a protocol change request |
Sean Young | 1f17f68 | 2018-02-12 07:27:50 -0500 | [diff] [blame] | 1148 | * @dev: rc_dev device |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1149 | * @protocols: pointer to the bitmask of current protocols |
| 1150 | * @buf: pointer to the buffer with a list of changes |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1151 | * |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1152 | * Writing "+proto" will add a protocol to the protocol mask. |
| 1153 | * Writing "-proto" will remove a protocol from protocol mask. |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1154 | * Writing "proto" will enable only "proto". |
| 1155 | * Writing "none" will disable all protocols. |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1156 | * Returns the number of changes performed or a negative error code. |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1157 | */ |
Sean Young | 1f17f68 | 2018-02-12 07:27:50 -0500 | [diff] [blame] | 1158 | static int parse_protocol_change(struct rc_dev *dev, u64 *protocols, |
| 1159 | const char *buf) |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1160 | { |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1161 | const char *tmp; |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1162 | unsigned count = 0; |
| 1163 | bool enable, disable; |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1164 | u64 mask; |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1165 | int i; |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1166 | |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1167 | while ((tmp = strsep((char **)&buf, " \n")) != NULL) { |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1168 | if (!*tmp) |
| 1169 | break; |
| 1170 | |
| 1171 | if (*tmp == '+') { |
| 1172 | enable = true; |
| 1173 | disable = false; |
| 1174 | tmp++; |
| 1175 | } else if (*tmp == '-') { |
| 1176 | enable = false; |
| 1177 | disable = true; |
| 1178 | tmp++; |
| 1179 | } else { |
| 1180 | enable = false; |
| 1181 | disable = false; |
| 1182 | } |
| 1183 | |
David Härdeman | c003ab1 | 2012-10-11 19:11:54 -0300 | [diff] [blame] | 1184 | for (i = 0; i < ARRAY_SIZE(proto_names); i++) { |
| 1185 | if (!strcasecmp(tmp, proto_names[i].name)) { |
| 1186 | mask = proto_names[i].type; |
| 1187 | break; |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1188 | } |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1189 | } |
| 1190 | |
David Härdeman | c003ab1 | 2012-10-11 19:11:54 -0300 | [diff] [blame] | 1191 | if (i == ARRAY_SIZE(proto_names)) { |
David Härdeman | 275ddb4 | 2015-05-19 19:03:22 -0300 | [diff] [blame] | 1192 | if (!strcasecmp(tmp, "lirc")) |
| 1193 | mask = 0; |
| 1194 | else { |
Sean Young | 1f17f68 | 2018-02-12 07:27:50 -0500 | [diff] [blame] | 1195 | dev_dbg(&dev->dev, "Unknown protocol: '%s'\n", |
| 1196 | tmp); |
David Härdeman | 275ddb4 | 2015-05-19 19:03:22 -0300 | [diff] [blame] | 1197 | return -EINVAL; |
| 1198 | } |
David Härdeman | c003ab1 | 2012-10-11 19:11:54 -0300 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | count++; |
| 1202 | |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1203 | if (enable) |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1204 | *protocols |= mask; |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1205 | else if (disable) |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1206 | *protocols &= ~mask; |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1207 | else |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1208 | *protocols = mask; |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | if (!count) { |
Sean Young | 1f17f68 | 2018-02-12 07:27:50 -0500 | [diff] [blame] | 1212 | dev_dbg(&dev->dev, "Protocol not specified\n"); |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1213 | return -EINVAL; |
| 1214 | } |
| 1215 | |
| 1216 | return count; |
| 1217 | } |
| 1218 | |
Sean Young | 0d39ab0 | 2017-02-25 06:51:31 -0500 | [diff] [blame] | 1219 | void ir_raw_load_modules(u64 *protocols) |
Heiner Kallweit | 9f0bf36 | 2015-11-16 17:52:08 -0200 | [diff] [blame] | 1220 | { |
| 1221 | u64 available; |
| 1222 | int i, ret; |
| 1223 | |
| 1224 | for (i = 0; i < ARRAY_SIZE(proto_names); i++) { |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 1225 | if (proto_names[i].type == RC_PROTO_BIT_NONE || |
| 1226 | proto_names[i].type & (RC_PROTO_BIT_OTHER | |
| 1227 | RC_PROTO_BIT_UNKNOWN)) |
Heiner Kallweit | 9f0bf36 | 2015-11-16 17:52:08 -0200 | [diff] [blame] | 1228 | continue; |
| 1229 | |
| 1230 | available = ir_raw_get_allowed_protocols(); |
| 1231 | if (!(*protocols & proto_names[i].type & ~available)) |
| 1232 | continue; |
| 1233 | |
| 1234 | if (!proto_names[i].module_name) { |
| 1235 | pr_err("Can't enable IR protocol %s\n", |
| 1236 | proto_names[i].name); |
| 1237 | *protocols &= ~proto_names[i].type; |
| 1238 | continue; |
| 1239 | } |
| 1240 | |
| 1241 | ret = request_module("%s", proto_names[i].module_name); |
| 1242 | if (ret < 0) { |
| 1243 | pr_err("Couldn't load IR protocol module %s\n", |
| 1244 | proto_names[i].module_name); |
| 1245 | *protocols &= ~proto_names[i].type; |
| 1246 | continue; |
| 1247 | } |
| 1248 | msleep(20); |
| 1249 | available = ir_raw_get_allowed_protocols(); |
| 1250 | if (!(*protocols & proto_names[i].type & ~available)) |
| 1251 | continue; |
| 1252 | |
Sean Young | 8caebcd | 2017-01-19 19:33:49 -0200 | [diff] [blame] | 1253 | pr_err("Loaded IR protocol module %s, but protocol %s still not available\n", |
Heiner Kallweit | 9f0bf36 | 2015-11-16 17:52:08 -0200 | [diff] [blame] | 1254 | proto_names[i].module_name, |
| 1255 | proto_names[i].name); |
| 1256 | *protocols &= ~proto_names[i].type; |
| 1257 | } |
| 1258 | } |
| 1259 | |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1260 | /** |
| 1261 | * store_protocols() - changes the current/wakeup IR protocol(s) |
| 1262 | * @device: the device descriptor |
| 1263 | * @mattr: the device attribute struct |
| 1264 | * @buf: a pointer to the input buffer |
| 1265 | * @len: length of the input buffer |
| 1266 | * |
| 1267 | * This routine is for changing the IR protocol type. |
Mauro Carvalho Chehab | 04ad301 | 2019-02-18 14:29:01 -0500 | [diff] [blame] | 1268 | * It is triggered by writing to /sys/class/rc/rc?/[wakeup_]protocols. |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1269 | * See parse_protocol_change() for the valid commands. |
| 1270 | * Returns @len on success or a negative error code. |
| 1271 | * |
David Härdeman | 18726a3 | 2017-04-27 17:34:08 -0300 | [diff] [blame] | 1272 | * dev->lock is taken to guard against races between |
| 1273 | * store_protocols and show_protocols. |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1274 | */ |
| 1275 | static ssize_t store_protocols(struct device *device, |
| 1276 | struct device_attribute *mattr, |
| 1277 | const char *buf, size_t len) |
| 1278 | { |
| 1279 | struct rc_dev *dev = to_rc_dev(device); |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1280 | u64 *current_protocols; |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1281 | struct rc_scancode_filter *filter; |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1282 | u64 old_protocols, new_protocols; |
| 1283 | ssize_t rc; |
| 1284 | |
Sean Young | 1f17f68 | 2018-02-12 07:27:50 -0500 | [diff] [blame] | 1285 | dev_dbg(&dev->dev, "Normal protocol change requested\n"); |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1286 | current_protocols = &dev->enabled_protocols; |
| 1287 | filter = &dev->scancode_filter; |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1288 | |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1289 | if (!dev->change_protocol) { |
Sean Young | 1f17f68 | 2018-02-12 07:27:50 -0500 | [diff] [blame] | 1290 | dev_dbg(&dev->dev, "Protocol switching not supported\n"); |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1291 | return -EINVAL; |
| 1292 | } |
| 1293 | |
| 1294 | mutex_lock(&dev->lock); |
Sean Young | a2e2d73 | 2020-08-08 13:38:02 +0200 | [diff] [blame] | 1295 | if (!dev->registered) { |
| 1296 | mutex_unlock(&dev->lock); |
| 1297 | return -ENODEV; |
| 1298 | } |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1299 | |
| 1300 | old_protocols = *current_protocols; |
| 1301 | new_protocols = old_protocols; |
Sean Young | 1f17f68 | 2018-02-12 07:27:50 -0500 | [diff] [blame] | 1302 | rc = parse_protocol_change(dev, &new_protocols, buf); |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1303 | if (rc < 0) |
| 1304 | goto out; |
| 1305 | |
Sean Young | a86d6df | 2018-03-23 16:47:37 -0400 | [diff] [blame] | 1306 | if (dev->driver_type == RC_DRIVER_IR_RAW) |
| 1307 | ir_raw_load_modules(&new_protocols); |
| 1308 | |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1309 | rc = dev->change_protocol(dev, &new_protocols); |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1310 | if (rc < 0) { |
Sean Young | 1f17f68 | 2018-02-12 07:27:50 -0500 | [diff] [blame] | 1311 | dev_dbg(&dev->dev, "Error setting protocols to 0x%llx\n", |
| 1312 | (long long)new_protocols); |
Jarod Wilson | 08aeb7c | 2011-05-11 15:14:31 -0300 | [diff] [blame] | 1313 | goto out; |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1314 | } |
| 1315 | |
James Hogan | 983c5bd | 2014-12-08 13:17:07 -0300 | [diff] [blame] | 1316 | if (new_protocols != old_protocols) { |
| 1317 | *current_protocols = new_protocols; |
Sean Young | 1f17f68 | 2018-02-12 07:27:50 -0500 | [diff] [blame] | 1318 | dev_dbg(&dev->dev, "Protocols changed to 0x%llx\n", |
| 1319 | (long long)new_protocols); |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1320 | } |
| 1321 | |
James Hogan | 6bea25a | 2014-02-28 20:17:06 -0300 | [diff] [blame] | 1322 | /* |
James Hogan | 983c5bd | 2014-12-08 13:17:07 -0300 | [diff] [blame] | 1323 | * If a protocol change was attempted the filter may need updating, even |
| 1324 | * if the actual protocol mask hasn't changed (since the driver may have |
| 1325 | * cleared the filter). |
James Hogan | 6bea25a | 2014-02-28 20:17:06 -0300 | [diff] [blame] | 1326 | * Try setting the same filter with the new protocol (if any). |
| 1327 | * Fall back to clearing the filter. |
| 1328 | */ |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1329 | if (dev->s_filter && filter->mask) { |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1330 | if (new_protocols) |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1331 | rc = dev->s_filter(dev, filter); |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1332 | else |
| 1333 | rc = -1; |
David Härdeman | 23c843b | 2014-04-04 19:06:01 -0300 | [diff] [blame] | 1334 | |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1335 | if (rc < 0) { |
| 1336 | filter->data = 0; |
| 1337 | filter->mask = 0; |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1338 | dev->s_filter(dev, filter); |
James Hogan | 6bea25a | 2014-02-28 20:17:06 -0300 | [diff] [blame] | 1339 | } |
James Hogan | 6bea25a | 2014-02-28 20:17:06 -0300 | [diff] [blame] | 1340 | } |
| 1341 | |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1342 | rc = len; |
Jarod Wilson | 08aeb7c | 2011-05-11 15:14:31 -0300 | [diff] [blame] | 1343 | |
| 1344 | out: |
| 1345 | mutex_unlock(&dev->lock); |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1346 | return rc; |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1347 | } |
| 1348 | |
James Hogan | 00942d1 | 2014-01-17 10:58:49 -0300 | [diff] [blame] | 1349 | /** |
James Hogan | 00942d1 | 2014-01-17 10:58:49 -0300 | [diff] [blame] | 1350 | * show_filter() - shows the current scancode filter value or mask |
| 1351 | * @device: the device descriptor |
| 1352 | * @attr: the device attribute struct |
| 1353 | * @buf: a pointer to the output buffer |
| 1354 | * |
| 1355 | * This routine is a callback routine to read a scancode filter value or mask. |
Mauro Carvalho Chehab | 04ad301 | 2019-02-18 14:29:01 -0500 | [diff] [blame] | 1356 | * It is triggered by reading /sys/class/rc/rc?/[wakeup_]filter[_mask]. |
James Hogan | 00942d1 | 2014-01-17 10:58:49 -0300 | [diff] [blame] | 1357 | * It prints the current scancode filter value or mask of the appropriate filter |
| 1358 | * type in hexadecimal into @buf and returns the size of the buffer. |
| 1359 | * |
| 1360 | * Bits of the filter value corresponding to set bits in the filter mask are |
| 1361 | * compared against input scancodes and non-matching scancodes are discarded. |
| 1362 | * |
David Härdeman | 18726a3 | 2017-04-27 17:34:08 -0300 | [diff] [blame] | 1363 | * dev->lock is taken to guard against races between |
James Hogan | 00942d1 | 2014-01-17 10:58:49 -0300 | [diff] [blame] | 1364 | * store_filter and show_filter. |
| 1365 | */ |
| 1366 | static ssize_t show_filter(struct device *device, |
| 1367 | struct device_attribute *attr, |
| 1368 | char *buf) |
| 1369 | { |
| 1370 | struct rc_dev *dev = to_rc_dev(device); |
| 1371 | struct rc_filter_attribute *fattr = to_rc_filter_attr(attr); |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1372 | struct rc_scancode_filter *filter; |
James Hogan | 00942d1 | 2014-01-17 10:58:49 -0300 | [diff] [blame] | 1373 | u32 val; |
| 1374 | |
Mauro Carvalho Chehab | c73bbaa | 2016-02-11 10:33:31 -0200 | [diff] [blame] | 1375 | mutex_lock(&dev->lock); |
Mauro Carvalho Chehab | c73bbaa | 2016-02-11 10:33:31 -0200 | [diff] [blame] | 1376 | |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1377 | if (fattr->type == RC_FILTER_NORMAL) |
David Härdeman | c5540fb | 2014-04-03 20:32:21 -0300 | [diff] [blame] | 1378 | filter = &dev->scancode_filter; |
James Hogan | 00942d1 | 2014-01-17 10:58:49 -0300 | [diff] [blame] | 1379 | else |
David Härdeman | c5540fb | 2014-04-03 20:32:21 -0300 | [diff] [blame] | 1380 | filter = &dev->scancode_wakeup_filter; |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1381 | |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1382 | if (fattr->mask) |
| 1383 | val = filter->mask; |
| 1384 | else |
| 1385 | val = filter->data; |
James Hogan | 00942d1 | 2014-01-17 10:58:49 -0300 | [diff] [blame] | 1386 | mutex_unlock(&dev->lock); |
| 1387 | |
| 1388 | return sprintf(buf, "%#x\n", val); |
| 1389 | } |
| 1390 | |
| 1391 | /** |
| 1392 | * store_filter() - changes the scancode filter value |
| 1393 | * @device: the device descriptor |
| 1394 | * @attr: the device attribute struct |
| 1395 | * @buf: a pointer to the input buffer |
| 1396 | * @len: length of the input buffer |
| 1397 | * |
| 1398 | * This routine is for changing a scancode filter value or mask. |
Mauro Carvalho Chehab | 04ad301 | 2019-02-18 14:29:01 -0500 | [diff] [blame] | 1399 | * It is triggered by writing to /sys/class/rc/rc?/[wakeup_]filter[_mask]. |
James Hogan | 00942d1 | 2014-01-17 10:58:49 -0300 | [diff] [blame] | 1400 | * Returns -EINVAL if an invalid filter value for the current protocol was |
| 1401 | * specified or if scancode filtering is not supported by the driver, otherwise |
| 1402 | * returns @len. |
| 1403 | * |
| 1404 | * Bits of the filter value corresponding to set bits in the filter mask are |
| 1405 | * compared against input scancodes and non-matching scancodes are discarded. |
| 1406 | * |
David Härdeman | 18726a3 | 2017-04-27 17:34:08 -0300 | [diff] [blame] | 1407 | * dev->lock is taken to guard against races between |
James Hogan | 00942d1 | 2014-01-17 10:58:49 -0300 | [diff] [blame] | 1408 | * store_filter and show_filter. |
| 1409 | */ |
| 1410 | static ssize_t store_filter(struct device *device, |
| 1411 | struct device_attribute *attr, |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1412 | const char *buf, size_t len) |
James Hogan | 00942d1 | 2014-01-17 10:58:49 -0300 | [diff] [blame] | 1413 | { |
| 1414 | struct rc_dev *dev = to_rc_dev(device); |
| 1415 | struct rc_filter_attribute *fattr = to_rc_filter_attr(attr); |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1416 | struct rc_scancode_filter new_filter, *filter; |
James Hogan | 00942d1 | 2014-01-17 10:58:49 -0300 | [diff] [blame] | 1417 | int ret; |
| 1418 | unsigned long val; |
David Härdeman | 23c843b | 2014-04-04 19:06:01 -0300 | [diff] [blame] | 1419 | int (*set_filter)(struct rc_dev *dev, struct rc_scancode_filter *filter); |
James Hogan | 00942d1 | 2014-01-17 10:58:49 -0300 | [diff] [blame] | 1420 | |
James Hogan | 00942d1 | 2014-01-17 10:58:49 -0300 | [diff] [blame] | 1421 | ret = kstrtoul(buf, 0, &val); |
| 1422 | if (ret < 0) |
| 1423 | return ret; |
| 1424 | |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1425 | if (fattr->type == RC_FILTER_NORMAL) { |
| 1426 | set_filter = dev->s_filter; |
David Härdeman | c5540fb | 2014-04-03 20:32:21 -0300 | [diff] [blame] | 1427 | filter = &dev->scancode_filter; |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1428 | } else { |
| 1429 | set_filter = dev->s_wakeup_filter; |
David Härdeman | c5540fb | 2014-04-03 20:32:21 -0300 | [diff] [blame] | 1430 | filter = &dev->scancode_wakeup_filter; |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1431 | } |
| 1432 | |
David Härdeman | 99b0f3c | 2014-04-04 19:06:06 -0300 | [diff] [blame] | 1433 | if (!set_filter) |
| 1434 | return -EINVAL; |
James Hogan | 00942d1 | 2014-01-17 10:58:49 -0300 | [diff] [blame] | 1435 | |
| 1436 | mutex_lock(&dev->lock); |
Sean Young | a2e2d73 | 2020-08-08 13:38:02 +0200 | [diff] [blame] | 1437 | if (!dev->registered) { |
| 1438 | mutex_unlock(&dev->lock); |
| 1439 | return -ENODEV; |
| 1440 | } |
James Hogan | 00942d1 | 2014-01-17 10:58:49 -0300 | [diff] [blame] | 1441 | |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1442 | new_filter = *filter; |
James Hogan | 00942d1 | 2014-01-17 10:58:49 -0300 | [diff] [blame] | 1443 | if (fattr->mask) |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1444 | new_filter.mask = val; |
James Hogan | 00942d1 | 2014-01-17 10:58:49 -0300 | [diff] [blame] | 1445 | else |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1446 | new_filter.data = val; |
David Härdeman | 23c843b | 2014-04-04 19:06:01 -0300 | [diff] [blame] | 1447 | |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1448 | if (fattr->type == RC_FILTER_WAKEUP) { |
Sean Young | b590c0b | 2016-12-05 19:24:59 -0200 | [diff] [blame] | 1449 | /* |
| 1450 | * Refuse to set a filter unless a protocol is enabled |
| 1451 | * and the filter is valid for that protocol |
| 1452 | */ |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 1453 | if (dev->wakeup_protocol != RC_PROTO_UNKNOWN) |
James Hogan | f423ccc | 2015-03-31 14:48:10 -0300 | [diff] [blame] | 1454 | ret = rc_validate_filter(dev, &new_filter); |
Sean Young | b590c0b | 2016-12-05 19:24:59 -0200 | [diff] [blame] | 1455 | else |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1456 | ret = -EINVAL; |
Sean Young | b590c0b | 2016-12-05 19:24:59 -0200 | [diff] [blame] | 1457 | |
| 1458 | if (ret != 0) |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1459 | goto unlock; |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1460 | } |
| 1461 | |
| 1462 | if (fattr->type == RC_FILTER_NORMAL && !dev->enabled_protocols && |
| 1463 | val) { |
James Hogan | 6bea25a | 2014-02-28 20:17:06 -0300 | [diff] [blame] | 1464 | /* refuse to set a filter unless a protocol is enabled */ |
| 1465 | ret = -EINVAL; |
| 1466 | goto unlock; |
| 1467 | } |
David Härdeman | 23c843b | 2014-04-04 19:06:01 -0300 | [diff] [blame] | 1468 | |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1469 | ret = set_filter(dev, &new_filter); |
David Härdeman | 99b0f3c | 2014-04-04 19:06:06 -0300 | [diff] [blame] | 1470 | if (ret < 0) |
| 1471 | goto unlock; |
James Hogan | 00942d1 | 2014-01-17 10:58:49 -0300 | [diff] [blame] | 1472 | |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1473 | *filter = new_filter; |
James Hogan | 00942d1 | 2014-01-17 10:58:49 -0300 | [diff] [blame] | 1474 | |
| 1475 | unlock: |
| 1476 | mutex_unlock(&dev->lock); |
David Härdeman | da6e162 | 2014-04-03 20:32:16 -0300 | [diff] [blame] | 1477 | return (ret < 0) ? ret : len; |
James Hogan | 00942d1 | 2014-01-17 10:58:49 -0300 | [diff] [blame] | 1478 | } |
| 1479 | |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1480 | /** |
| 1481 | * show_wakeup_protocols() - shows the wakeup IR protocol |
| 1482 | * @device: the device descriptor |
| 1483 | * @mattr: the device attribute struct |
| 1484 | * @buf: a pointer to the output buffer |
| 1485 | * |
| 1486 | * This routine is a callback routine for input read the IR protocol type(s). |
Mauro Carvalho Chehab | 04ad301 | 2019-02-18 14:29:01 -0500 | [diff] [blame] | 1487 | * it is triggered by reading /sys/class/rc/rc?/wakeup_protocols. |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1488 | * It returns the protocol names of supported protocols. |
| 1489 | * The enabled protocols are printed in brackets. |
| 1490 | * |
David Härdeman | 18726a3 | 2017-04-27 17:34:08 -0300 | [diff] [blame] | 1491 | * dev->lock is taken to guard against races between |
| 1492 | * store_wakeup_protocols and show_wakeup_protocols. |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1493 | */ |
| 1494 | static ssize_t show_wakeup_protocols(struct device *device, |
| 1495 | struct device_attribute *mattr, |
| 1496 | char *buf) |
| 1497 | { |
| 1498 | struct rc_dev *dev = to_rc_dev(device); |
| 1499 | u64 allowed; |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 1500 | enum rc_proto enabled; |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1501 | char *tmp = buf; |
| 1502 | int i; |
| 1503 | |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1504 | mutex_lock(&dev->lock); |
| 1505 | |
| 1506 | allowed = dev->allowed_wakeup_protocols; |
| 1507 | enabled = dev->wakeup_protocol; |
| 1508 | |
| 1509 | mutex_unlock(&dev->lock); |
| 1510 | |
Sean Young | 1f17f68 | 2018-02-12 07:27:50 -0500 | [diff] [blame] | 1511 | dev_dbg(&dev->dev, "%s: allowed - 0x%llx, enabled - %d\n", |
| 1512 | __func__, (long long)allowed, enabled); |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1513 | |
Sean Young | d57ea87 | 2017-08-09 13:19:16 -0400 | [diff] [blame] | 1514 | for (i = 0; i < ARRAY_SIZE(protocols); i++) { |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1515 | if (allowed & (1ULL << i)) { |
| 1516 | if (i == enabled) |
Sean Young | d57ea87 | 2017-08-09 13:19:16 -0400 | [diff] [blame] | 1517 | tmp += sprintf(tmp, "[%s] ", protocols[i].name); |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1518 | else |
Sean Young | d57ea87 | 2017-08-09 13:19:16 -0400 | [diff] [blame] | 1519 | tmp += sprintf(tmp, "%s ", protocols[i].name); |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1520 | } |
| 1521 | } |
| 1522 | |
| 1523 | if (tmp != buf) |
| 1524 | tmp--; |
| 1525 | *tmp = '\n'; |
| 1526 | |
| 1527 | return tmp + 1 - buf; |
| 1528 | } |
| 1529 | |
| 1530 | /** |
| 1531 | * store_wakeup_protocols() - changes the wakeup IR protocol(s) |
| 1532 | * @device: the device descriptor |
| 1533 | * @mattr: the device attribute struct |
| 1534 | * @buf: a pointer to the input buffer |
| 1535 | * @len: length of the input buffer |
| 1536 | * |
| 1537 | * This routine is for changing the IR protocol type. |
Mauro Carvalho Chehab | 04ad301 | 2019-02-18 14:29:01 -0500 | [diff] [blame] | 1538 | * It is triggered by writing to /sys/class/rc/rc?/wakeup_protocols. |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1539 | * Returns @len on success or a negative error code. |
| 1540 | * |
David Härdeman | 18726a3 | 2017-04-27 17:34:08 -0300 | [diff] [blame] | 1541 | * dev->lock is taken to guard against races between |
| 1542 | * store_wakeup_protocols and show_wakeup_protocols. |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1543 | */ |
| 1544 | static ssize_t store_wakeup_protocols(struct device *device, |
| 1545 | struct device_attribute *mattr, |
| 1546 | const char *buf, size_t len) |
| 1547 | { |
| 1548 | struct rc_dev *dev = to_rc_dev(device); |
Mauro Carvalho Chehab | 3d35153 | 2019-05-23 05:27:30 -0400 | [diff] [blame] | 1549 | enum rc_proto protocol = RC_PROTO_UNKNOWN; |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1550 | ssize_t rc; |
| 1551 | u64 allowed; |
| 1552 | int i; |
| 1553 | |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1554 | mutex_lock(&dev->lock); |
Sean Young | a2e2d73 | 2020-08-08 13:38:02 +0200 | [diff] [blame] | 1555 | if (!dev->registered) { |
| 1556 | mutex_unlock(&dev->lock); |
| 1557 | return -ENODEV; |
| 1558 | } |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1559 | |
| 1560 | allowed = dev->allowed_wakeup_protocols; |
| 1561 | |
Mauro Carvalho Chehab | 3d35153 | 2019-05-23 05:27:30 -0400 | [diff] [blame] | 1562 | if (!sysfs_streq(buf, "none")) { |
Sean Young | d57ea87 | 2017-08-09 13:19:16 -0400 | [diff] [blame] | 1563 | for (i = 0; i < ARRAY_SIZE(protocols); i++) { |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1564 | if ((allowed & (1ULL << i)) && |
Sean Young | d57ea87 | 2017-08-09 13:19:16 -0400 | [diff] [blame] | 1565 | sysfs_streq(buf, protocols[i].name)) { |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1566 | protocol = i; |
| 1567 | break; |
| 1568 | } |
| 1569 | } |
| 1570 | |
Sean Young | d57ea87 | 2017-08-09 13:19:16 -0400 | [diff] [blame] | 1571 | if (i == ARRAY_SIZE(protocols)) { |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1572 | rc = -EINVAL; |
| 1573 | goto out; |
| 1574 | } |
James Hogan | f423ccc | 2015-03-31 14:48:10 -0300 | [diff] [blame] | 1575 | |
| 1576 | if (dev->encode_wakeup) { |
| 1577 | u64 mask = 1ULL << protocol; |
| 1578 | |
| 1579 | ir_raw_load_modules(&mask); |
| 1580 | if (!mask) { |
| 1581 | rc = -EINVAL; |
| 1582 | goto out; |
| 1583 | } |
| 1584 | } |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1585 | } |
| 1586 | |
| 1587 | if (dev->wakeup_protocol != protocol) { |
| 1588 | dev->wakeup_protocol = protocol; |
Sean Young | 1f17f68 | 2018-02-12 07:27:50 -0500 | [diff] [blame] | 1589 | dev_dbg(&dev->dev, "Wakeup protocol changed to %d\n", protocol); |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1590 | |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 1591 | if (protocol == RC_PROTO_RC6_MCE) |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1592 | dev->scancode_wakeup_filter.data = 0x800f0000; |
| 1593 | else |
| 1594 | dev->scancode_wakeup_filter.data = 0; |
| 1595 | dev->scancode_wakeup_filter.mask = 0; |
| 1596 | |
| 1597 | rc = dev->s_wakeup_filter(dev, &dev->scancode_wakeup_filter); |
| 1598 | if (rc == 0) |
| 1599 | rc = len; |
| 1600 | } else { |
| 1601 | rc = len; |
| 1602 | } |
| 1603 | |
| 1604 | out: |
| 1605 | mutex_unlock(&dev->lock); |
| 1606 | return rc; |
| 1607 | } |
| 1608 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1609 | static void rc_dev_release(struct device *device) |
| 1610 | { |
Max Kellermann | 47cae1e | 2016-03-21 08:33:05 -0300 | [diff] [blame] | 1611 | struct rc_dev *dev = to_rc_dev(device); |
| 1612 | |
| 1613 | kfree(dev); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1614 | } |
| 1615 | |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1616 | static int rc_dev_uevent(struct device *device, struct kobj_uevent_env *env) |
| 1617 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1618 | struct rc_dev *dev = to_rc_dev(device); |
Sean Young | 4f0835d | 2020-08-08 13:19:12 +0200 | [diff] [blame] | 1619 | int ret = 0; |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1620 | |
Sean Young | 4f0835d | 2020-08-08 13:19:12 +0200 | [diff] [blame] | 1621 | mutex_lock(&dev->lock); |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1622 | |
Sean Young | 4f0835d | 2020-08-08 13:19:12 +0200 | [diff] [blame] | 1623 | if (!dev->registered) |
| 1624 | ret = -ENODEV; |
| 1625 | if (ret == 0 && dev->rc_map.name) |
| 1626 | ret = add_uevent_var(env, "NAME=%s", dev->rc_map.name); |
| 1627 | if (ret == 0 && dev->driver_name) |
| 1628 | ret = add_uevent_var(env, "DRV_NAME=%s", dev->driver_name); |
| 1629 | if (ret == 0 && dev->device_name) |
| 1630 | ret = add_uevent_var(env, "DEV_NAME=%s", dev->device_name); |
| 1631 | |
| 1632 | mutex_unlock(&dev->lock); |
| 1633 | |
| 1634 | return ret; |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1635 | } |
| 1636 | |
| 1637 | /* |
| 1638 | * Static device attribute struct with the sysfs attributes for IR's |
| 1639 | */ |
Sean Young | 6d75db3 | 2017-09-01 11:30:50 -0300 | [diff] [blame] | 1640 | static struct device_attribute dev_attr_ro_protocols = |
| 1641 | __ATTR(protocols, 0444, show_protocols, NULL); |
| 1642 | static struct device_attribute dev_attr_rw_protocols = |
| 1643 | __ATTR(protocols, 0644, show_protocols, store_protocols); |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1644 | static DEVICE_ATTR(wakeup_protocols, 0644, show_wakeup_protocols, |
| 1645 | store_wakeup_protocols); |
James Hogan | 00942d1 | 2014-01-17 10:58:49 -0300 | [diff] [blame] | 1646 | static RC_FILTER_ATTR(filter, S_IRUGO|S_IWUSR, |
| 1647 | show_filter, store_filter, RC_FILTER_NORMAL, false); |
| 1648 | static RC_FILTER_ATTR(filter_mask, S_IRUGO|S_IWUSR, |
| 1649 | show_filter, store_filter, RC_FILTER_NORMAL, true); |
| 1650 | static RC_FILTER_ATTR(wakeup_filter, S_IRUGO|S_IWUSR, |
| 1651 | show_filter, store_filter, RC_FILTER_WAKEUP, false); |
| 1652 | static RC_FILTER_ATTR(wakeup_filter_mask, S_IRUGO|S_IWUSR, |
| 1653 | show_filter, store_filter, RC_FILTER_WAKEUP, true); |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1654 | |
Sean Young | 6d75db3 | 2017-09-01 11:30:50 -0300 | [diff] [blame] | 1655 | static struct attribute *rc_dev_rw_protocol_attrs[] = { |
| 1656 | &dev_attr_rw_protocols.attr, |
David Härdeman | 99b0f3c | 2014-04-04 19:06:06 -0300 | [diff] [blame] | 1657 | NULL, |
| 1658 | }; |
| 1659 | |
Sean Young | 6d75db3 | 2017-09-01 11:30:50 -0300 | [diff] [blame] | 1660 | static const struct attribute_group rc_dev_rw_protocol_attr_grp = { |
| 1661 | .attrs = rc_dev_rw_protocol_attrs, |
| 1662 | }; |
| 1663 | |
| 1664 | static struct attribute *rc_dev_ro_protocol_attrs[] = { |
| 1665 | &dev_attr_ro_protocols.attr, |
| 1666 | NULL, |
| 1667 | }; |
| 1668 | |
| 1669 | static const struct attribute_group rc_dev_ro_protocol_attr_grp = { |
| 1670 | .attrs = rc_dev_ro_protocol_attrs, |
David Härdeman | 99b0f3c | 2014-04-04 19:06:06 -0300 | [diff] [blame] | 1671 | }; |
| 1672 | |
David Härdeman | 99b0f3c | 2014-04-04 19:06:06 -0300 | [diff] [blame] | 1673 | static struct attribute *rc_dev_filter_attrs[] = { |
James Hogan | 00942d1 | 2014-01-17 10:58:49 -0300 | [diff] [blame] | 1674 | &dev_attr_filter.attr.attr, |
| 1675 | &dev_attr_filter_mask.attr.attr, |
David Härdeman | 99b0f3c | 2014-04-04 19:06:06 -0300 | [diff] [blame] | 1676 | NULL, |
| 1677 | }; |
| 1678 | |
Arvind Yadav | db68102 | 2017-07-07 04:23:54 -0400 | [diff] [blame] | 1679 | static const struct attribute_group rc_dev_filter_attr_grp = { |
David Härdeman | 99b0f3c | 2014-04-04 19:06:06 -0300 | [diff] [blame] | 1680 | .attrs = rc_dev_filter_attrs, |
| 1681 | }; |
| 1682 | |
| 1683 | static struct attribute *rc_dev_wakeup_filter_attrs[] = { |
James Hogan | 00942d1 | 2014-01-17 10:58:49 -0300 | [diff] [blame] | 1684 | &dev_attr_wakeup_filter.attr.attr, |
| 1685 | &dev_attr_wakeup_filter_mask.attr.attr, |
Sean Young | 0751d33 | 2016-12-05 17:08:35 -0200 | [diff] [blame] | 1686 | &dev_attr_wakeup_protocols.attr, |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1687 | NULL, |
| 1688 | }; |
| 1689 | |
Arvind Yadav | db68102 | 2017-07-07 04:23:54 -0400 | [diff] [blame] | 1690 | static const struct attribute_group rc_dev_wakeup_filter_attr_grp = { |
David Härdeman | 99b0f3c | 2014-04-04 19:06:06 -0300 | [diff] [blame] | 1691 | .attrs = rc_dev_wakeup_filter_attrs, |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1692 | }; |
| 1693 | |
Bhumika Goyal | f03f02f | 2017-08-19 05:22:15 -0300 | [diff] [blame] | 1694 | static const struct device_type rc_dev_type = { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1695 | .release = rc_dev_release, |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1696 | .uevent = rc_dev_uevent, |
| 1697 | }; |
| 1698 | |
Andi Shyti | 0f7499f | 2016-12-16 06:50:58 -0200 | [diff] [blame] | 1699 | struct rc_dev *rc_allocate_device(enum rc_driver_type type) |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1700 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1701 | struct rc_dev *dev; |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1702 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1703 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
| 1704 | if (!dev) |
| 1705 | return NULL; |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1706 | |
Andi Shyti | d34aee1 | 2016-12-16 04:12:15 -0200 | [diff] [blame] | 1707 | if (type != RC_DRIVER_IR_RAW_TX) { |
| 1708 | dev->input_dev = input_allocate_device(); |
| 1709 | if (!dev->input_dev) { |
| 1710 | kfree(dev); |
| 1711 | return NULL; |
| 1712 | } |
| 1713 | |
| 1714 | dev->input_dev->getkeycode = ir_getkeycode; |
| 1715 | dev->input_dev->setkeycode = ir_setkeycode; |
| 1716 | input_set_drvdata(dev->input_dev, dev); |
| 1717 | |
Sean Young | 2849225 | 2018-03-24 08:02:48 -0400 | [diff] [blame] | 1718 | dev->timeout = IR_DEFAULT_TIMEOUT; |
Kees Cook | b17ec78 | 2017-10-24 11:23:14 -0400 | [diff] [blame] | 1719 | timer_setup(&dev->timer_keyup, ir_timer_keyup, 0); |
Sean Young | 57c642c | 2017-11-23 17:37:10 -0500 | [diff] [blame] | 1720 | timer_setup(&dev->timer_repeat, ir_timer_repeat, 0); |
Andi Shyti | d34aee1 | 2016-12-16 04:12:15 -0200 | [diff] [blame] | 1721 | |
| 1722 | spin_lock_init(&dev->rc_map.lock); |
| 1723 | spin_lock_init(&dev->keylock); |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1724 | } |
Jarod Wilson | 08aeb7c | 2011-05-11 15:14:31 -0300 | [diff] [blame] | 1725 | mutex_init(&dev->lock); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1726 | |
| 1727 | dev->dev.type = &rc_dev_type; |
David Härdeman | 40fc532 | 2013-03-06 16:52:10 -0300 | [diff] [blame] | 1728 | dev->dev.class = &rc_class; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1729 | device_initialize(&dev->dev); |
| 1730 | |
Andi Shyti | 0f7499f | 2016-12-16 06:50:58 -0200 | [diff] [blame] | 1731 | dev->driver_type = type; |
| 1732 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1733 | __module_get(THIS_MODULE); |
| 1734 | return dev; |
| 1735 | } |
| 1736 | EXPORT_SYMBOL_GPL(rc_allocate_device); |
| 1737 | |
| 1738 | void rc_free_device(struct rc_dev *dev) |
| 1739 | { |
Mauro Carvalho Chehab | b05681b | 2011-07-29 02:23:20 -0300 | [diff] [blame] | 1740 | if (!dev) |
| 1741 | return; |
| 1742 | |
Markus Elfring | 3dd94f0 | 2014-11-20 09:01:32 -0300 | [diff] [blame] | 1743 | input_free_device(dev->input_dev); |
Mauro Carvalho Chehab | b05681b | 2011-07-29 02:23:20 -0300 | [diff] [blame] | 1744 | |
| 1745 | put_device(&dev->dev); |
| 1746 | |
Max Kellermann | 47cae1e | 2016-03-21 08:33:05 -0300 | [diff] [blame] | 1747 | /* kfree(dev) will be called by the callback function |
| 1748 | rc_dev_release() */ |
| 1749 | |
Mauro Carvalho Chehab | b05681b | 2011-07-29 02:23:20 -0300 | [diff] [blame] | 1750 | module_put(THIS_MODULE); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1751 | } |
| 1752 | EXPORT_SYMBOL_GPL(rc_free_device); |
| 1753 | |
Heiner Kallweit | ddbf7d5 | 2016-09-30 17:42:07 -0300 | [diff] [blame] | 1754 | static void devm_rc_alloc_release(struct device *dev, void *res) |
| 1755 | { |
| 1756 | rc_free_device(*(struct rc_dev **)res); |
| 1757 | } |
| 1758 | |
Andi Shyti | 0f7499f | 2016-12-16 06:50:58 -0200 | [diff] [blame] | 1759 | struct rc_dev *devm_rc_allocate_device(struct device *dev, |
| 1760 | enum rc_driver_type type) |
Heiner Kallweit | ddbf7d5 | 2016-09-30 17:42:07 -0300 | [diff] [blame] | 1761 | { |
| 1762 | struct rc_dev **dr, *rc; |
| 1763 | |
| 1764 | dr = devres_alloc(devm_rc_alloc_release, sizeof(*dr), GFP_KERNEL); |
| 1765 | if (!dr) |
| 1766 | return NULL; |
| 1767 | |
Andi Shyti | 0f7499f | 2016-12-16 06:50:58 -0200 | [diff] [blame] | 1768 | rc = rc_allocate_device(type); |
Heiner Kallweit | ddbf7d5 | 2016-09-30 17:42:07 -0300 | [diff] [blame] | 1769 | if (!rc) { |
| 1770 | devres_free(dr); |
| 1771 | return NULL; |
| 1772 | } |
| 1773 | |
| 1774 | rc->dev.parent = dev; |
| 1775 | rc->managed_alloc = true; |
| 1776 | *dr = rc; |
| 1777 | devres_add(dev, dr); |
| 1778 | |
| 1779 | return rc; |
| 1780 | } |
| 1781 | EXPORT_SYMBOL_GPL(devm_rc_allocate_device); |
| 1782 | |
David Härdeman | f56928a | 2017-05-03 07:04:00 -0300 | [diff] [blame] | 1783 | static int rc_prepare_rx_device(struct rc_dev *dev) |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1784 | { |
David Härdeman | fcb1309 | 2015-05-19 19:03:17 -0300 | [diff] [blame] | 1785 | int rc; |
Andi Shyti | 7ff2c2b | 2016-12-16 04:12:14 -0200 | [diff] [blame] | 1786 | struct rc_map *rc_map; |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 1787 | u64 rc_proto; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1788 | |
Andi Shyti | 7ff2c2b | 2016-12-16 04:12:14 -0200 | [diff] [blame] | 1789 | if (!dev->map_name) |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1790 | return -EINVAL; |
| 1791 | |
Mauro Carvalho Chehab | d100e65 | 2010-11-17 15:56:53 -0300 | [diff] [blame] | 1792 | rc_map = rc_map_get(dev->map_name); |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 1793 | if (!rc_map) |
Mauro Carvalho Chehab | d100e65 | 2010-11-17 15:56:53 -0300 | [diff] [blame] | 1794 | rc_map = rc_map_get(RC_MAP_EMPTY); |
Mauro Carvalho Chehab | b088ba6 | 2010-11-17 14:28:27 -0300 | [diff] [blame] | 1795 | if (!rc_map || !rc_map->scan || rc_map->size == 0) |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1796 | return -EINVAL; |
| 1797 | |
Andi Shyti | 7ff2c2b | 2016-12-16 04:12:14 -0200 | [diff] [blame] | 1798 | rc = ir_setkeytable(dev, rc_map); |
| 1799 | if (rc) |
| 1800 | return rc; |
| 1801 | |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 1802 | rc_proto = BIT_ULL(rc_map->rc_proto); |
Andi Shyti | 7ff2c2b | 2016-12-16 04:12:14 -0200 | [diff] [blame] | 1803 | |
Sean Young | 831c4c8 | 2017-09-01 09:55:59 -0300 | [diff] [blame] | 1804 | if (dev->driver_type == RC_DRIVER_SCANCODE && !dev->change_protocol) |
| 1805 | dev->enabled_protocols = dev->allowed_protocols; |
| 1806 | |
Sean Young | a86d6df | 2018-03-23 16:47:37 -0400 | [diff] [blame] | 1807 | if (dev->driver_type == RC_DRIVER_IR_RAW) |
| 1808 | ir_raw_load_modules(&rc_proto); |
| 1809 | |
Sean Young | 4138086 | 2017-02-22 18:48:01 -0300 | [diff] [blame] | 1810 | if (dev->change_protocol) { |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 1811 | rc = dev->change_protocol(dev, &rc_proto); |
Andi Shyti | 7ff2c2b | 2016-12-16 04:12:14 -0200 | [diff] [blame] | 1812 | if (rc < 0) |
| 1813 | goto out_table; |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 1814 | dev->enabled_protocols = rc_proto; |
Andi Shyti | 7ff2c2b | 2016-12-16 04:12:14 -0200 | [diff] [blame] | 1815 | } |
| 1816 | |
Sean Young | 0ac5a60 | 2018-09-16 07:35:58 -0400 | [diff] [blame] | 1817 | /* Keyboard events */ |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1818 | set_bit(EV_KEY, dev->input_dev->evbit); |
| 1819 | set_bit(EV_REP, dev->input_dev->evbit); |
| 1820 | set_bit(EV_MSC, dev->input_dev->evbit); |
| 1821 | set_bit(MSC_SCAN, dev->input_dev->mscbit); |
Sean Young | fec225a | 2018-09-18 04:50:20 -0400 | [diff] [blame] | 1822 | |
Sean Young | 0ac5a60 | 2018-09-16 07:35:58 -0400 | [diff] [blame] | 1823 | /* Pointer/mouse events */ |
Sean Young | ce81964 | 2019-09-28 17:46:14 -0300 | [diff] [blame] | 1824 | set_bit(INPUT_PROP_POINTING_STICK, dev->input_dev->propbit); |
Sean Young | 0ac5a60 | 2018-09-16 07:35:58 -0400 | [diff] [blame] | 1825 | set_bit(EV_REL, dev->input_dev->evbit); |
| 1826 | set_bit(REL_X, dev->input_dev->relbit); |
| 1827 | set_bit(REL_Y, dev->input_dev->relbit); |
| 1828 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1829 | if (dev->open) |
| 1830 | dev->input_dev->open = ir_open; |
| 1831 | if (dev->close) |
| 1832 | dev->input_dev->close = ir_close; |
| 1833 | |
David Härdeman | b2aceb7 | 2017-04-27 17:33:58 -0300 | [diff] [blame] | 1834 | dev->input_dev->dev.parent = &dev->dev; |
| 1835 | memcpy(&dev->input_dev->id, &dev->input_id, sizeof(dev->input_id)); |
| 1836 | dev->input_dev->phys = dev->input_phys; |
Sean Young | 518f4b2 | 2017-07-01 12:13:19 -0400 | [diff] [blame] | 1837 | dev->input_dev->name = dev->device_name; |
David Härdeman | b2aceb7 | 2017-04-27 17:33:58 -0300 | [diff] [blame] | 1838 | |
David Härdeman | f56928a | 2017-05-03 07:04:00 -0300 | [diff] [blame] | 1839 | return 0; |
| 1840 | |
| 1841 | out_table: |
| 1842 | ir_free_table(&dev->rc_map); |
| 1843 | |
| 1844 | return rc; |
| 1845 | } |
| 1846 | |
| 1847 | static int rc_setup_rx_device(struct rc_dev *dev) |
| 1848 | { |
| 1849 | int rc; |
| 1850 | |
David Härdeman | b2aceb7 | 2017-04-27 17:33:58 -0300 | [diff] [blame] | 1851 | /* rc_open will be called here */ |
| 1852 | rc = input_register_device(dev->input_dev); |
| 1853 | if (rc) |
David Härdeman | f56928a | 2017-05-03 07:04:00 -0300 | [diff] [blame] | 1854 | return rc; |
David Härdeman | b2aceb7 | 2017-04-27 17:33:58 -0300 | [diff] [blame] | 1855 | |
Andi Shyti | 7ff2c2b | 2016-12-16 04:12:14 -0200 | [diff] [blame] | 1856 | /* |
| 1857 | * Default delay of 250ms is too short for some protocols, especially |
| 1858 | * since the timeout is currently set to 250ms. Increase it to 500ms, |
| 1859 | * to avoid wrong repetition of the keycodes. Note that this must be |
| 1860 | * set after the call to input_register_device(). |
| 1861 | */ |
Sean Young | 57c642c | 2017-11-23 17:37:10 -0500 | [diff] [blame] | 1862 | if (dev->allowed_protocols == RC_PROTO_BIT_CEC) |
| 1863 | dev->input_dev->rep[REP_DELAY] = 0; |
| 1864 | else |
| 1865 | dev->input_dev->rep[REP_DELAY] = 500; |
Andi Shyti | 7ff2c2b | 2016-12-16 04:12:14 -0200 | [diff] [blame] | 1866 | |
| 1867 | /* |
| 1868 | * As a repeat event on protocols like RC-5 and NEC take as long as |
| 1869 | * 110/114ms, using 33ms as a repeat period is not the right thing |
| 1870 | * to do. |
| 1871 | */ |
| 1872 | dev->input_dev->rep[REP_PERIOD] = 125; |
| 1873 | |
Andi Shyti | 7ff2c2b | 2016-12-16 04:12:14 -0200 | [diff] [blame] | 1874 | return 0; |
Andi Shyti | 7ff2c2b | 2016-12-16 04:12:14 -0200 | [diff] [blame] | 1875 | } |
| 1876 | |
| 1877 | static void rc_free_rx_device(struct rc_dev *dev) |
| 1878 | { |
David Härdeman | f56928a | 2017-05-03 07:04:00 -0300 | [diff] [blame] | 1879 | if (!dev) |
Andi Shyti | 7ff2c2b | 2016-12-16 04:12:14 -0200 | [diff] [blame] | 1880 | return; |
| 1881 | |
David Härdeman | f56928a | 2017-05-03 07:04:00 -0300 | [diff] [blame] | 1882 | if (dev->input_dev) { |
| 1883 | input_unregister_device(dev->input_dev); |
| 1884 | dev->input_dev = NULL; |
| 1885 | } |
Andi Shyti | 7ff2c2b | 2016-12-16 04:12:14 -0200 | [diff] [blame] | 1886 | |
David Härdeman | f56928a | 2017-05-03 07:04:00 -0300 | [diff] [blame] | 1887 | ir_free_table(&dev->rc_map); |
Andi Shyti | 7ff2c2b | 2016-12-16 04:12:14 -0200 | [diff] [blame] | 1888 | } |
| 1889 | |
| 1890 | int rc_register_device(struct rc_dev *dev) |
| 1891 | { |
Andi Shyti | 7ff2c2b | 2016-12-16 04:12:14 -0200 | [diff] [blame] | 1892 | const char *path; |
| 1893 | int attr = 0; |
| 1894 | int minor; |
| 1895 | int rc; |
| 1896 | |
| 1897 | if (!dev) |
| 1898 | return -EINVAL; |
| 1899 | |
David Härdeman | fcb1309 | 2015-05-19 19:03:17 -0300 | [diff] [blame] | 1900 | minor = ida_simple_get(&rc_ida, 0, RC_DEV_MAX, GFP_KERNEL); |
| 1901 | if (minor < 0) |
| 1902 | return minor; |
| 1903 | |
| 1904 | dev->minor = minor; |
| 1905 | dev_set_name(&dev->dev, "rc%u", dev->minor); |
| 1906 | dev_set_drvdata(&dev->dev, dev); |
Mauro Carvalho Chehab | 587d1b0 | 2014-01-14 16:27:55 -0300 | [diff] [blame] | 1907 | |
David Härdeman | 99b0f3c | 2014-04-04 19:06:06 -0300 | [diff] [blame] | 1908 | dev->dev.groups = dev->sysfs_groups; |
Sean Young | 6d75db3 | 2017-09-01 11:30:50 -0300 | [diff] [blame] | 1909 | if (dev->driver_type == RC_DRIVER_SCANCODE && !dev->change_protocol) |
| 1910 | dev->sysfs_groups[attr++] = &rc_dev_ro_protocol_attr_grp; |
| 1911 | else if (dev->driver_type != RC_DRIVER_IR_RAW_TX) |
| 1912 | dev->sysfs_groups[attr++] = &rc_dev_rw_protocol_attr_grp; |
David Härdeman | 99b0f3c | 2014-04-04 19:06:06 -0300 | [diff] [blame] | 1913 | if (dev->s_filter) |
David Härdeman | 120703f | 2014-04-03 20:31:30 -0300 | [diff] [blame] | 1914 | dev->sysfs_groups[attr++] = &rc_dev_filter_attr_grp; |
David Härdeman | 99b0f3c | 2014-04-04 19:06:06 -0300 | [diff] [blame] | 1915 | if (dev->s_wakeup_filter) |
| 1916 | dev->sysfs_groups[attr++] = &rc_dev_wakeup_filter_attr_grp; |
David Härdeman | 99b0f3c | 2014-04-04 19:06:06 -0300 | [diff] [blame] | 1917 | dev->sysfs_groups[attr++] = NULL; |
| 1918 | |
Sean Young | a60d64b | 2017-09-23 10:41:13 -0400 | [diff] [blame] | 1919 | if (dev->driver_type == RC_DRIVER_IR_RAW) { |
David Härdeman | f56928a | 2017-05-03 07:04:00 -0300 | [diff] [blame] | 1920 | rc = ir_raw_event_prepare(dev); |
| 1921 | if (rc < 0) |
| 1922 | goto out_minor; |
| 1923 | } |
| 1924 | |
| 1925 | if (dev->driver_type != RC_DRIVER_IR_RAW_TX) { |
| 1926 | rc = rc_prepare_rx_device(dev); |
| 1927 | if (rc) |
| 1928 | goto out_raw; |
| 1929 | } |
| 1930 | |
Sean Young | 896111d | 2020-12-20 13:29:54 +0100 | [diff] [blame] | 1931 | dev->registered = true; |
| 1932 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1933 | rc = device_add(&dev->dev); |
| 1934 | if (rc) |
David Härdeman | f56928a | 2017-05-03 07:04:00 -0300 | [diff] [blame] | 1935 | goto out_rx_free; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1936 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1937 | path = kobject_get_path(&dev->dev.kobj, GFP_KERNEL); |
Heiner Kallweit | 4dc0e90 | 2015-10-29 19:39:06 -0200 | [diff] [blame] | 1938 | dev_info(&dev->dev, "%s as %s\n", |
Sean Young | 518f4b2 | 2017-07-01 12:13:19 -0400 | [diff] [blame] | 1939 | dev->device_name ?: "Unspecified device", path ?: "N/A"); |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1940 | kfree(path); |
| 1941 | |
Sean Young | 080d89f | 2019-11-21 11:10:47 +0100 | [diff] [blame] | 1942 | /* |
| 1943 | * once the the input device is registered in rc_setup_rx_device, |
| 1944 | * userspace can open the input device and rc_open() will be called |
| 1945 | * as a result. This results in driver code being allowed to submit |
| 1946 | * keycodes with rc_keydown, so lirc must be registered first. |
| 1947 | */ |
Sean Young | 62d6f199 | 2017-09-24 12:43:24 -0400 | [diff] [blame] | 1948 | if (dev->allowed_protocols != RC_PROTO_BIT_CEC) { |
Sean Young | 75992a4 | 2020-08-24 21:10:45 +0200 | [diff] [blame] | 1949 | rc = lirc_register(dev); |
David Härdeman | f56928a | 2017-05-03 07:04:00 -0300 | [diff] [blame] | 1950 | if (rc < 0) |
Sean Young | 080d89f | 2019-11-21 11:10:47 +0100 | [diff] [blame] | 1951 | goto out_dev; |
| 1952 | } |
| 1953 | |
| 1954 | if (dev->driver_type != RC_DRIVER_IR_RAW_TX) { |
| 1955 | rc = rc_setup_rx_device(dev); |
| 1956 | if (rc) |
| 1957 | goto out_lirc; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1958 | } |
| 1959 | |
Sean Young | a60d64b | 2017-09-23 10:41:13 -0400 | [diff] [blame] | 1960 | if (dev->driver_type == RC_DRIVER_IR_RAW) { |
| 1961 | rc = ir_raw_event_register(dev); |
| 1962 | if (rc < 0) |
Sean Young | 080d89f | 2019-11-21 11:10:47 +0100 | [diff] [blame] | 1963 | goto out_rx; |
Sean Young | a60d64b | 2017-09-23 10:41:13 -0400 | [diff] [blame] | 1964 | } |
| 1965 | |
Sean Young | 1f17f68 | 2018-02-12 07:27:50 -0500 | [diff] [blame] | 1966 | dev_dbg(&dev->dev, "Registered rc%u (driver: %s)\n", dev->minor, |
| 1967 | dev->driver_name ? dev->driver_name : "unknown"); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1968 | |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1969 | return 0; |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 1970 | |
Sean Young | 080d89f | 2019-11-21 11:10:47 +0100 | [diff] [blame] | 1971 | out_rx: |
| 1972 | rc_free_rx_device(dev); |
Sean Young | a60d64b | 2017-09-23 10:41:13 -0400 | [diff] [blame] | 1973 | out_lirc: |
Sean Young | 62d6f199 | 2017-09-24 12:43:24 -0400 | [diff] [blame] | 1974 | if (dev->allowed_protocols != RC_PROTO_BIT_CEC) |
Sean Young | 75992a4 | 2020-08-24 21:10:45 +0200 | [diff] [blame] | 1975 | lirc_unregister(dev); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1976 | out_dev: |
| 1977 | device_del(&dev->dev); |
David Härdeman | f56928a | 2017-05-03 07:04:00 -0300 | [diff] [blame] | 1978 | out_rx_free: |
| 1979 | ir_free_table(&dev->rc_map); |
| 1980 | out_raw: |
| 1981 | ir_raw_event_free(dev); |
| 1982 | out_minor: |
David Härdeman | fcb1309 | 2015-05-19 19:03:17 -0300 | [diff] [blame] | 1983 | ida_simple_remove(&rc_ida, minor); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1984 | return rc; |
| 1985 | } |
| 1986 | EXPORT_SYMBOL_GPL(rc_register_device); |
| 1987 | |
Heiner Kallweit | ddbf7d5 | 2016-09-30 17:42:07 -0300 | [diff] [blame] | 1988 | static void devm_rc_release(struct device *dev, void *res) |
| 1989 | { |
| 1990 | rc_unregister_device(*(struct rc_dev **)res); |
| 1991 | } |
| 1992 | |
| 1993 | int devm_rc_register_device(struct device *parent, struct rc_dev *dev) |
| 1994 | { |
| 1995 | struct rc_dev **dr; |
| 1996 | int ret; |
| 1997 | |
| 1998 | dr = devres_alloc(devm_rc_release, sizeof(*dr), GFP_KERNEL); |
| 1999 | if (!dr) |
| 2000 | return -ENOMEM; |
| 2001 | |
| 2002 | ret = rc_register_device(dev); |
| 2003 | if (ret) { |
| 2004 | devres_free(dr); |
| 2005 | return ret; |
| 2006 | } |
| 2007 | |
| 2008 | *dr = dev; |
| 2009 | devres_add(parent, dr); |
| 2010 | |
| 2011 | return 0; |
| 2012 | } |
| 2013 | EXPORT_SYMBOL_GPL(devm_rc_register_device); |
| 2014 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 2015 | void rc_unregister_device(struct rc_dev *dev) |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 2016 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 2017 | if (!dev) |
| 2018 | return; |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 2019 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 2020 | if (dev->driver_type == RC_DRIVER_IR_RAW) |
| 2021 | ir_raw_event_unregister(dev); |
| 2022 | |
Sean Young | 8d40688 | 2018-03-06 08:57:57 -0500 | [diff] [blame] | 2023 | del_timer_sync(&dev->timer_keyup); |
| 2024 | del_timer_sync(&dev->timer_repeat); |
| 2025 | |
Sean Young | 7790e81 | 2017-09-26 07:31:29 -0400 | [diff] [blame] | 2026 | mutex_lock(&dev->lock); |
Sean Young | 8e782fc | 2018-11-04 05:12:09 -0500 | [diff] [blame] | 2027 | if (dev->users && dev->close) |
| 2028 | dev->close(dev); |
Sean Young | 7790e81 | 2017-09-26 07:31:29 -0400 | [diff] [blame] | 2029 | dev->registered = false; |
| 2030 | mutex_unlock(&dev->lock); |
| 2031 | |
Sean Young | 4f0835d | 2020-08-08 13:19:12 +0200 | [diff] [blame] | 2032 | rc_free_rx_device(dev); |
| 2033 | |
Sean Young | 7790e81 | 2017-09-26 07:31:29 -0400 | [diff] [blame] | 2034 | /* |
| 2035 | * lirc device should be freed with dev->registered = false, so |
| 2036 | * that userspace polling will get notified. |
| 2037 | */ |
Sean Young | 62d6f199 | 2017-09-24 12:43:24 -0400 | [diff] [blame] | 2038 | if (dev->allowed_protocols != RC_PROTO_BIT_CEC) |
Sean Young | 75992a4 | 2020-08-24 21:10:45 +0200 | [diff] [blame] | 2039 | lirc_unregister(dev); |
Sean Young | a60d64b | 2017-09-23 10:41:13 -0400 | [diff] [blame] | 2040 | |
Mauro Carvalho Chehab | b05681b | 2011-07-29 02:23:20 -0300 | [diff] [blame] | 2041 | device_del(&dev->dev); |
| 2042 | |
David Härdeman | fcb1309 | 2015-05-19 19:03:17 -0300 | [diff] [blame] | 2043 | ida_simple_remove(&rc_ida, dev->minor); |
| 2044 | |
Heiner Kallweit | ddbf7d5 | 2016-09-30 17:42:07 -0300 | [diff] [blame] | 2045 | if (!dev->managed_alloc) |
| 2046 | rc_free_device(dev); |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 2047 | } |
Mauro Carvalho Chehab | b05681b | 2011-07-29 02:23:20 -0300 | [diff] [blame] | 2048 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 2049 | EXPORT_SYMBOL_GPL(rc_unregister_device); |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 2050 | |
| 2051 | /* |
| 2052 | * Init/exit code for the module. Basically, creates/removes /sys/class/rc |
| 2053 | */ |
| 2054 | |
Mauro Carvalho Chehab | 6bda964 | 2010-11-17 13:28:38 -0300 | [diff] [blame] | 2055 | static int __init rc_core_init(void) |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 2056 | { |
David Härdeman | 40fc532 | 2013-03-06 16:52:10 -0300 | [diff] [blame] | 2057 | int rc = class_register(&rc_class); |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 2058 | if (rc) { |
Mauro Carvalho Chehab | d3d9682 | 2016-10-20 15:04:39 -0200 | [diff] [blame] | 2059 | pr_err("rc_core: unable to register rc class\n"); |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 2060 | return rc; |
| 2061 | } |
| 2062 | |
Sean Young | a60d64b | 2017-09-23 10:41:13 -0400 | [diff] [blame] | 2063 | rc = lirc_dev_init(); |
| 2064 | if (rc) { |
| 2065 | pr_err("rc_core: unable to init lirc\n"); |
| 2066 | class_unregister(&rc_class); |
Evgeny Novikov | 3b4cfc6 | 2020-06-18 15:15:38 +0200 | [diff] [blame] | 2067 | return rc; |
Sean Young | a60d64b | 2017-09-23 10:41:13 -0400 | [diff] [blame] | 2068 | } |
| 2069 | |
Sean Young | 153a60b | 2013-07-30 19:00:01 -0300 | [diff] [blame] | 2070 | led_trigger_register_simple("rc-feedback", &led_feedback); |
Mauro Carvalho Chehab | d100e65 | 2010-11-17 15:56:53 -0300 | [diff] [blame] | 2071 | rc_map_register(&empty_map); |
Hans Verkuil | f09f9f9 | 2021-02-26 11:37:47 +0100 | [diff] [blame] | 2072 | #ifdef CONFIG_MEDIA_CEC_RC |
| 2073 | rc_map_register(&cec_map); |
| 2074 | #endif |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 2075 | |
| 2076 | return 0; |
| 2077 | } |
| 2078 | |
Mauro Carvalho Chehab | 6bda964 | 2010-11-17 13:28:38 -0300 | [diff] [blame] | 2079 | static void __exit rc_core_exit(void) |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 2080 | { |
Sean Young | a60d64b | 2017-09-23 10:41:13 -0400 | [diff] [blame] | 2081 | lirc_dev_exit(); |
David Härdeman | 40fc532 | 2013-03-06 16:52:10 -0300 | [diff] [blame] | 2082 | class_unregister(&rc_class); |
Sean Young | 153a60b | 2013-07-30 19:00:01 -0300 | [diff] [blame] | 2083 | led_trigger_unregister_simple(led_feedback); |
Hans Verkuil | f09f9f9 | 2021-02-26 11:37:47 +0100 | [diff] [blame] | 2084 | #ifdef CONFIG_MEDIA_CEC_RC |
| 2085 | rc_map_unregister(&cec_map); |
| 2086 | #endif |
Mauro Carvalho Chehab | d100e65 | 2010-11-17 15:56:53 -0300 | [diff] [blame] | 2087 | rc_map_unregister(&empty_map); |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 2088 | } |
| 2089 | |
David Härdeman | e76d4ce | 2013-03-06 16:52:15 -0300 | [diff] [blame] | 2090 | subsys_initcall(rc_core_init); |
Mauro Carvalho Chehab | 6bda964 | 2010-11-17 13:28:38 -0300 | [diff] [blame] | 2091 | module_exit(rc_core_exit); |
Mauro Carvalho Chehab | bc2a6c5 | 2010-11-09 23:18:24 -0300 | [diff] [blame] | 2092 | |
Mauro Carvalho Chehab | 37e59f8 | 2014-02-07 08:03:07 -0200 | [diff] [blame] | 2093 | MODULE_AUTHOR("Mauro Carvalho Chehab"); |
Mauro Carvalho Chehab | 2083528 | 2017-12-01 08:47:08 -0500 | [diff] [blame] | 2094 | MODULE_LICENSE("GPL v2"); |