aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/rc/rc-main.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/rc/rc-main.c')
-rw-r--r--drivers/media/rc/rc-main.c100
1 files changed, 51 insertions, 49 deletions
diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index 1db8d38fed7c..b67be33bd62f 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -68,6 +68,8 @@ static const struct {
68 .scancode_bits = 0x1fff, .repeat_period = 250 }, 68 .scancode_bits = 0x1fff, .repeat_period = 250 },
69 [RC_PROTO_XMP] = { .name = "xmp", .repeat_period = 250 }, 69 [RC_PROTO_XMP] = { .name = "xmp", .repeat_period = 250 },
70 [RC_PROTO_CEC] = { .name = "cec", .repeat_period = 550 }, 70 [RC_PROTO_CEC] = { .name = "cec", .repeat_period = 550 },
71 [RC_PROTO_IMON] = { .name = "imon",
72 .scancode_bits = 0x7fffffff, .repeat_period = 250 },
71}; 73};
72 74
73/* Used to keep track of known keymaps */ 75/* Used to keep track of known keymaps */
@@ -156,6 +158,7 @@ static struct rc_map_list empty_map = {
156 158
157/** 159/**
158 * ir_create_table() - initializes a scancode table 160 * ir_create_table() - initializes a scancode table
161 * @dev: the rc_dev device
159 * @rc_map: the rc_map to initialize 162 * @rc_map: the rc_map to initialize
160 * @name: name to assign to the table 163 * @name: name to assign to the table
161 * @rc_proto: ir type to assign to the new table 164 * @rc_proto: ir type to assign to the new table
@@ -166,7 +169,7 @@ static struct rc_map_list empty_map = {
166 * 169 *
167 * return: zero on success or a negative error code 170 * return: zero on success or a negative error code
168 */ 171 */
169static int ir_create_table(struct rc_map *rc_map, 172static int ir_create_table(struct rc_dev *dev, struct rc_map *rc_map,
170 const char *name, u64 rc_proto, size_t size) 173 const char *name, u64 rc_proto, size_t size)
171{ 174{
172 rc_map->name = kstrdup(name, GFP_KERNEL); 175 rc_map->name = kstrdup(name, GFP_KERNEL);
@@ -182,8 +185,8 @@ static int ir_create_table(struct rc_map *rc_map,
182 return -ENOMEM; 185 return -ENOMEM;
183 } 186 }
184 187
185 IR_dprintk(1, "Allocated space for %u keycode entries (%u bytes)\n", 188 dev_dbg(&dev->dev, "Allocated space for %u keycode entries (%u bytes)\n",
186 rc_map->size, rc_map->alloc); 189 rc_map->size, rc_map->alloc);
187 return 0; 190 return 0;
188} 191}
189 192
@@ -205,6 +208,7 @@ static void ir_free_table(struct rc_map *rc_map)
205 208
206/** 209/**
207 * ir_resize_table() - resizes a scancode table if necessary 210 * ir_resize_table() - resizes a scancode table if necessary
211 * @dev: the rc_dev device
208 * @rc_map: the rc_map to resize 212 * @rc_map: the rc_map to resize
209 * @gfp_flags: gfp flags to use when allocating memory 213 * @gfp_flags: gfp flags to use when allocating memory
210 * 214 *
@@ -213,7 +217,8 @@ static void ir_free_table(struct rc_map *rc_map)
213 * 217 *
214 * return: zero on success or a negative error code 218 * return: zero on success or a negative error code
215 */ 219 */
216static int ir_resize_table(struct rc_map *rc_map, gfp_t gfp_flags) 220static int ir_resize_table(struct rc_dev *dev, struct rc_map *rc_map,
221 gfp_t gfp_flags)
217{ 222{
218 unsigned int oldalloc = rc_map->alloc; 223 unsigned int oldalloc = rc_map->alloc;
219 unsigned int newalloc = oldalloc; 224 unsigned int newalloc = oldalloc;
@@ -226,23 +231,21 @@ static int ir_resize_table(struct rc_map *rc_map, gfp_t gfp_flags)
226 return -ENOMEM; 231 return -ENOMEM;
227 232
228 newalloc *= 2; 233 newalloc *= 2;
229 IR_dprintk(1, "Growing table to %u bytes\n", newalloc); 234 dev_dbg(&dev->dev, "Growing table to %u bytes\n", newalloc);
230 } 235 }
231 236
232 if ((rc_map->len * 3 < rc_map->size) && (oldalloc > IR_TAB_MIN_SIZE)) { 237 if ((rc_map->len * 3 < rc_map->size) && (oldalloc > IR_TAB_MIN_SIZE)) {
233 /* Less than 1/3 of entries in use -> shrink keytable */ 238 /* Less than 1/3 of entries in use -> shrink keytable */
234 newalloc /= 2; 239 newalloc /= 2;
235 IR_dprintk(1, "Shrinking table to %u bytes\n", newalloc); 240 dev_dbg(&dev->dev, "Shrinking table to %u bytes\n", newalloc);
236 } 241 }
237 242
238 if (newalloc == oldalloc) 243 if (newalloc == oldalloc)
239 return 0; 244 return 0;
240 245
241 newscan = kmalloc(newalloc, gfp_flags); 246 newscan = kmalloc(newalloc, gfp_flags);
242 if (!newscan) { 247 if (!newscan)
243 IR_dprintk(1, "Failed to kmalloc %u bytes\n", newalloc);
244 return -ENOMEM; 248 return -ENOMEM;
245 }
246 249
247 memcpy(newscan, rc_map->scan, rc_map->len * sizeof(struct rc_map_table)); 250 memcpy(newscan, rc_map->scan, rc_map->len * sizeof(struct rc_map_table));
248 rc_map->scan = newscan; 251 rc_map->scan = newscan;
@@ -275,16 +278,16 @@ static unsigned int ir_update_mapping(struct rc_dev *dev,
275 278
276 /* Did the user wish to remove the mapping? */ 279 /* Did the user wish to remove the mapping? */
277 if (new_keycode == KEY_RESERVED || new_keycode == KEY_UNKNOWN) { 280 if (new_keycode == KEY_RESERVED || new_keycode == KEY_UNKNOWN) {
278 IR_dprintk(1, "#%d: Deleting scan 0x%04x\n", 281 dev_dbg(&dev->dev, "#%d: Deleting scan 0x%04x\n",
279 index, rc_map->scan[index].scancode); 282 index, rc_map->scan[index].scancode);
280 rc_map->len--; 283 rc_map->len--;
281 memmove(&rc_map->scan[index], &rc_map->scan[index+ 1], 284 memmove(&rc_map->scan[index], &rc_map->scan[index+ 1],
282 (rc_map->len - index) * sizeof(struct rc_map_table)); 285 (rc_map->len - index) * sizeof(struct rc_map_table));
283 } else { 286 } else {
284 IR_dprintk(1, "#%d: %s scan 0x%04x with key 0x%04x\n", 287 dev_dbg(&dev->dev, "#%d: %s scan 0x%04x with key 0x%04x\n",
285 index, 288 index,
286 old_keycode == KEY_RESERVED ? "New" : "Replacing", 289 old_keycode == KEY_RESERVED ? "New" : "Replacing",
287 rc_map->scan[index].scancode, new_keycode); 290 rc_map->scan[index].scancode, new_keycode);
288 rc_map->scan[index].keycode = new_keycode; 291 rc_map->scan[index].keycode = new_keycode;
289 __set_bit(new_keycode, dev->input_dev->keybit); 292 __set_bit(new_keycode, dev->input_dev->keybit);
290 } 293 }
@@ -301,7 +304,7 @@ static unsigned int ir_update_mapping(struct rc_dev *dev,
301 } 304 }
302 305
303 /* Possibly shrink the keytable, failure is not a problem */ 306 /* Possibly shrink the keytable, failure is not a problem */
304 ir_resize_table(rc_map, GFP_ATOMIC); 307 ir_resize_table(dev, rc_map, GFP_ATOMIC);
305 } 308 }
306 309
307 return old_keycode; 310 return old_keycode;
@@ -352,7 +355,7 @@ static unsigned int ir_establish_scancode(struct rc_dev *dev,
352 355
353 /* No previous mapping found, we might need to grow the table */ 356 /* No previous mapping found, we might need to grow the table */
354 if (rc_map->size == rc_map->len) { 357 if (rc_map->size == rc_map->len) {
355 if (!resize || ir_resize_table(rc_map, GFP_ATOMIC)) 358 if (!resize || ir_resize_table(dev, rc_map, GFP_ATOMIC))
356 return -1U; 359 return -1U;
357 } 360 }
358 361
@@ -431,8 +434,8 @@ static int ir_setkeytable(struct rc_dev *dev,
431 unsigned int i, index; 434 unsigned int i, index;
432 int rc; 435 int rc;
433 436
434 rc = ir_create_table(rc_map, from->name, 437 rc = ir_create_table(dev, rc_map, from->name, from->rc_proto,
435 from->rc_proto, from->size); 438 from->size);
436 if (rc) 439 if (rc)
437 return rc; 440 return rc;
438 441
@@ -576,8 +579,8 @@ u32 rc_g_keycode_from_table(struct rc_dev *dev, u32 scancode)
576 spin_unlock_irqrestore(&rc_map->lock, flags); 579 spin_unlock_irqrestore(&rc_map->lock, flags);
577 580
578 if (keycode != KEY_RESERVED) 581 if (keycode != KEY_RESERVED)
579 IR_dprintk(1, "%s: scancode 0x%04x keycode 0x%02x\n", 582 dev_dbg(&dev->dev, "%s: scancode 0x%04x keycode 0x%02x\n",
580 dev->device_name, scancode, keycode); 583 dev->device_name, scancode, keycode);
581 584
582 return keycode; 585 return keycode;
583} 586}
@@ -596,7 +599,7 @@ static void ir_do_keyup(struct rc_dev *dev, bool sync)
596 if (!dev->keypressed) 599 if (!dev->keypressed)
597 return; 600 return;
598 601
599 IR_dprintk(1, "keyup key 0x%04x\n", dev->last_keycode); 602 dev_dbg(&dev->dev, "keyup key 0x%04x\n", dev->last_keycode);
600 del_timer(&dev->timer_repeat); 603 del_timer(&dev->timer_repeat);
601 input_report_key(dev->input_dev, dev->last_keycode, 0); 604 input_report_key(dev->input_dev, dev->last_keycode, 0);
602 led_trigger_event(led_feedback, LED_OFF); 605 led_trigger_event(led_feedback, LED_OFF);
@@ -751,8 +754,8 @@ static void ir_do_keydown(struct rc_dev *dev, enum rc_proto protocol,
751 /* Register a keypress */ 754 /* Register a keypress */
752 dev->keypressed = true; 755 dev->keypressed = true;
753 756
754 IR_dprintk(1, "%s: key down event, key 0x%04x, protocol 0x%04x, scancode 0x%08x\n", 757 dev_dbg(&dev->dev, "%s: key down event, key 0x%04x, protocol 0x%04x, scancode 0x%08x\n",
755 dev->device_name, keycode, protocol, scancode); 758 dev->device_name, keycode, protocol, scancode);
756 input_report_key(dev->input_dev, keycode, 1); 759 input_report_key(dev->input_dev, keycode, 1);
757 760
758 led_trigger_event(led_feedback, LED_FULL); 761 led_trigger_event(led_feedback, LED_FULL);
@@ -1003,6 +1006,7 @@ static const struct {
1003 RC_PROTO_BIT_MCIR2_MSE, "mce_kbd", "ir-mce_kbd-decoder" }, 1006 RC_PROTO_BIT_MCIR2_MSE, "mce_kbd", "ir-mce_kbd-decoder" },
1004 { RC_PROTO_BIT_XMP, "xmp", "ir-xmp-decoder" }, 1007 { RC_PROTO_BIT_XMP, "xmp", "ir-xmp-decoder" },
1005 { RC_PROTO_BIT_CEC, "cec", NULL }, 1008 { RC_PROTO_BIT_CEC, "cec", NULL },
1009 { RC_PROTO_BIT_IMON, "imon", "ir-imon-decoder" },
1006}; 1010};
1007 1011
1008/** 1012/**
@@ -1056,8 +1060,8 @@ static ssize_t show_protocols(struct device *device,
1056 1060
1057 mutex_unlock(&dev->lock); 1061 mutex_unlock(&dev->lock);
1058 1062
1059 IR_dprintk(1, "%s: allowed - 0x%llx, enabled - 0x%llx\n", 1063 dev_dbg(&dev->dev, "%s: allowed - 0x%llx, enabled - 0x%llx\n",
1060 __func__, (long long)allowed, (long long)enabled); 1064 __func__, (long long)allowed, (long long)enabled);
1061 1065
1062 for (i = 0; i < ARRAY_SIZE(proto_names); i++) { 1066 for (i = 0; i < ARRAY_SIZE(proto_names); i++) {
1063 if (allowed & enabled & proto_names[i].type) 1067 if (allowed & enabled & proto_names[i].type)
@@ -1083,6 +1087,7 @@ static ssize_t show_protocols(struct device *device,
1083 1087
1084/** 1088/**
1085 * parse_protocol_change() - parses a protocol change request 1089 * parse_protocol_change() - parses a protocol change request
1090 * @dev: rc_dev device
1086 * @protocols: pointer to the bitmask of current protocols 1091 * @protocols: pointer to the bitmask of current protocols
1087 * @buf: pointer to the buffer with a list of changes 1092 * @buf: pointer to the buffer with a list of changes
1088 * 1093 *
@@ -1092,7 +1097,8 @@ static ssize_t show_protocols(struct device *device,
1092 * Writing "none" will disable all protocols. 1097 * Writing "none" will disable all protocols.
1093 * Returns the number of changes performed or a negative error code. 1098 * Returns the number of changes performed or a negative error code.
1094 */ 1099 */
1095static int parse_protocol_change(u64 *protocols, const char *buf) 1100static int parse_protocol_change(struct rc_dev *dev, u64 *protocols,
1101 const char *buf)
1096{ 1102{
1097 const char *tmp; 1103 const char *tmp;
1098 unsigned count = 0; 1104 unsigned count = 0;
@@ -1128,7 +1134,8 @@ static int parse_protocol_change(u64 *protocols, const char *buf)
1128 if (!strcasecmp(tmp, "lirc")) 1134 if (!strcasecmp(tmp, "lirc"))
1129 mask = 0; 1135 mask = 0;
1130 else { 1136 else {
1131 IR_dprintk(1, "Unknown protocol: '%s'\n", tmp); 1137 dev_dbg(&dev->dev, "Unknown protocol: '%s'\n",
1138 tmp);
1132 return -EINVAL; 1139 return -EINVAL;
1133 } 1140 }
1134 } 1141 }
@@ -1144,7 +1151,7 @@ static int parse_protocol_change(u64 *protocols, const char *buf)
1144 } 1151 }
1145 1152
1146 if (!count) { 1153 if (!count) {
1147 IR_dprintk(1, "Protocol not specified\n"); 1154 dev_dbg(&dev->dev, "Protocol not specified\n");
1148 return -EINVAL; 1155 return -EINVAL;
1149 } 1156 }
1150 1157
@@ -1217,12 +1224,12 @@ static ssize_t store_protocols(struct device *device,
1217 u64 old_protocols, new_protocols; 1224 u64 old_protocols, new_protocols;
1218 ssize_t rc; 1225 ssize_t rc;
1219 1226
1220 IR_dprintk(1, "Normal protocol change requested\n"); 1227 dev_dbg(&dev->dev, "Normal protocol change requested\n");
1221 current_protocols = &dev->enabled_protocols; 1228 current_protocols = &dev->enabled_protocols;
1222 filter = &dev->scancode_filter; 1229 filter = &dev->scancode_filter;
1223 1230
1224 if (!dev->change_protocol) { 1231 if (!dev->change_protocol) {
1225 IR_dprintk(1, "Protocol switching not supported\n"); 1232 dev_dbg(&dev->dev, "Protocol switching not supported\n");
1226 return -EINVAL; 1233 return -EINVAL;
1227 } 1234 }
1228 1235
@@ -1230,14 +1237,14 @@ static ssize_t store_protocols(struct device *device,
1230 1237
1231 old_protocols = *current_protocols; 1238 old_protocols = *current_protocols;
1232 new_protocols = old_protocols; 1239 new_protocols = old_protocols;
1233 rc = parse_protocol_change(&new_protocols, buf); 1240 rc = parse_protocol_change(dev, &new_protocols, buf);
1234 if (rc < 0) 1241 if (rc < 0)
1235 goto out; 1242 goto out;
1236 1243
1237 rc = dev->change_protocol(dev, &new_protocols); 1244 rc = dev->change_protocol(dev, &new_protocols);
1238 if (rc < 0) { 1245 if (rc < 0) {
1239 IR_dprintk(1, "Error setting protocols to 0x%llx\n", 1246 dev_dbg(&dev->dev, "Error setting protocols to 0x%llx\n",
1240 (long long)new_protocols); 1247 (long long)new_protocols);
1241 goto out; 1248 goto out;
1242 } 1249 }
1243 1250
@@ -1246,8 +1253,8 @@ static ssize_t store_protocols(struct device *device,
1246 1253
1247 if (new_protocols != old_protocols) { 1254 if (new_protocols != old_protocols) {
1248 *current_protocols = new_protocols; 1255 *current_protocols = new_protocols;
1249 IR_dprintk(1, "Protocols changed to 0x%llx\n", 1256 dev_dbg(&dev->dev, "Protocols changed to 0x%llx\n",
1250 (long long)new_protocols); 1257 (long long)new_protocols);
1251 } 1258 }
1252 1259
1253 /* 1260 /*
@@ -1435,8 +1442,8 @@ static ssize_t show_wakeup_protocols(struct device *device,
1435 1442
1436 mutex_unlock(&dev->lock); 1443 mutex_unlock(&dev->lock);
1437 1444
1438 IR_dprintk(1, "%s: allowed - 0x%llx, enabled - %d\n", 1445 dev_dbg(&dev->dev, "%s: allowed - 0x%llx, enabled - %d\n",
1439 __func__, (long long)allowed, enabled); 1446 __func__, (long long)allowed, enabled);
1440 1447
1441 for (i = 0; i < ARRAY_SIZE(protocols); i++) { 1448 for (i = 0; i < ARRAY_SIZE(protocols); i++) {
1442 if (allowed & (1ULL << i)) { 1449 if (allowed & (1ULL << i)) {
@@ -1511,7 +1518,7 @@ static ssize_t store_wakeup_protocols(struct device *device,
1511 1518
1512 if (dev->wakeup_protocol != protocol) { 1519 if (dev->wakeup_protocol != protocol) {
1513 dev->wakeup_protocol = protocol; 1520 dev->wakeup_protocol = protocol;
1514 IR_dprintk(1, "Wakeup protocol changed to %d\n", protocol); 1521 dev_dbg(&dev->dev, "Wakeup protocol changed to %d\n", protocol);
1515 1522
1516 if (protocol == RC_PROTO_RC6_MCE) 1523 if (protocol == RC_PROTO_RC6_MCE)
1517 dev->scancode_wakeup_filter.data = 0x800f0000; 1524 dev->scancode_wakeup_filter.data = 0x800f0000;
@@ -1874,9 +1881,8 @@ int rc_register_device(struct rc_dev *dev)
1874 1881
1875 dev->registered = true; 1882 dev->registered = true;
1876 1883
1877 IR_dprintk(1, "Registered rc%u (driver: %s)\n", 1884 dev_dbg(&dev->dev, "Registered rc%u (driver: %s)\n", dev->minor,
1878 dev->minor, 1885 dev->driver_name ? dev->driver_name : "unknown");
1879 dev->driver_name ? dev->driver_name : "unknown");
1880 1886
1881 return 0; 1887 return 0;
1882 1888
@@ -1929,12 +1935,12 @@ void rc_unregister_device(struct rc_dev *dev)
1929 if (!dev) 1935 if (!dev)
1930 return; 1936 return;
1931 1937
1932 del_timer_sync(&dev->timer_keyup);
1933 del_timer_sync(&dev->timer_repeat);
1934
1935 if (dev->driver_type == RC_DRIVER_IR_RAW) 1938 if (dev->driver_type == RC_DRIVER_IR_RAW)
1936 ir_raw_event_unregister(dev); 1939 ir_raw_event_unregister(dev);
1937 1940
1941 del_timer_sync(&dev->timer_keyup);
1942 del_timer_sync(&dev->timer_repeat);
1943
1938 rc_free_rx_device(dev); 1944 rc_free_rx_device(dev);
1939 1945
1940 mutex_lock(&dev->lock); 1946 mutex_lock(&dev->lock);
@@ -1994,9 +2000,5 @@ static void __exit rc_core_exit(void)
1994subsys_initcall(rc_core_init); 2000subsys_initcall(rc_core_init);
1995module_exit(rc_core_exit); 2001module_exit(rc_core_exit);
1996 2002
1997int rc_core_debug; /* ir_debug level (0,1,2) */
1998EXPORT_SYMBOL_GPL(rc_core_debug);
1999module_param_named(debug, rc_core_debug, int, 0644);
2000
2001MODULE_AUTHOR("Mauro Carvalho Chehab"); 2003MODULE_AUTHOR("Mauro Carvalho Chehab");
2002MODULE_LICENSE("GPL v2"); 2004MODULE_LICENSE("GPL v2");