Lines Matching refs:rc_map
106 struct rc_map *rc_map_get(const char *name) in rc_map_get()
214 static int ir_create_table(struct rc_dev *dev, struct rc_map *rc_map, in ir_create_table() argument
217 rc_map->name = kstrdup(name, GFP_KERNEL); in ir_create_table()
218 if (!rc_map->name) in ir_create_table()
220 rc_map->rc_proto = rc_proto; in ir_create_table()
221 rc_map->alloc = roundup_pow_of_two(size * sizeof(struct rc_map_table)); in ir_create_table()
222 rc_map->size = rc_map->alloc / sizeof(struct rc_map_table); in ir_create_table()
223 rc_map->scan = kmalloc(rc_map->alloc, GFP_KERNEL); in ir_create_table()
224 if (!rc_map->scan) { in ir_create_table()
225 kfree(rc_map->name); in ir_create_table()
226 rc_map->name = NULL; in ir_create_table()
231 rc_map->size, rc_map->alloc); in ir_create_table()
242 static void ir_free_table(struct rc_map *rc_map) in ir_free_table() argument
244 rc_map->size = 0; in ir_free_table()
245 kfree(rc_map->name); in ir_free_table()
246 rc_map->name = NULL; in ir_free_table()
247 kfree(rc_map->scan); in ir_free_table()
248 rc_map->scan = NULL; in ir_free_table()
262 static int ir_resize_table(struct rc_dev *dev, struct rc_map *rc_map, in ir_resize_table() argument
265 unsigned int oldalloc = rc_map->alloc; in ir_resize_table()
267 struct rc_map_table *oldscan = rc_map->scan; in ir_resize_table()
270 if (rc_map->size == rc_map->len) { in ir_resize_table()
272 if (rc_map->alloc >= IR_TAB_MAX_SIZE) in ir_resize_table()
279 if ((rc_map->len * 3 < rc_map->size) && (oldalloc > IR_TAB_MIN_SIZE)) { in ir_resize_table()
292 memcpy(newscan, rc_map->scan, rc_map->len * sizeof(struct rc_map_table)); in ir_resize_table()
293 rc_map->scan = newscan; in ir_resize_table()
294 rc_map->alloc = newalloc; in ir_resize_table()
295 rc_map->size = rc_map->alloc / sizeof(struct rc_map_table); in ir_resize_table()
314 struct rc_map *rc_map, in ir_update_mapping() argument
318 int old_keycode = rc_map->scan[index].keycode; in ir_update_mapping()
324 index, rc_map->scan[index].scancode); in ir_update_mapping()
325 rc_map->len--; in ir_update_mapping()
326 memmove(&rc_map->scan[index], &rc_map->scan[index+ 1], in ir_update_mapping()
327 (rc_map->len - index) * sizeof(struct rc_map_table)); in ir_update_mapping()
332 rc_map->scan[index].scancode, new_keycode); in ir_update_mapping()
333 rc_map->scan[index].keycode = new_keycode; in ir_update_mapping()
341 for (i = 0; i < rc_map->len; i++) { in ir_update_mapping()
342 if (rc_map->scan[i].keycode == old_keycode) { in ir_update_mapping()
349 ir_resize_table(dev, rc_map, GFP_ATOMIC); in ir_update_mapping()
371 struct rc_map *rc_map, in ir_establish_scancode() argument
388 for (i = 0; i < rc_map->len; i++) { in ir_establish_scancode()
389 if (rc_map->scan[i].scancode == scancode) in ir_establish_scancode()
393 if (rc_map->scan[i].scancode >= scancode) in ir_establish_scancode()
398 if (rc_map->size == rc_map->len) { in ir_establish_scancode()
399 if (!resize || ir_resize_table(dev, rc_map, GFP_ATOMIC)) in ir_establish_scancode()
404 if (i < rc_map->len) in ir_establish_scancode()
405 memmove(&rc_map->scan[i + 1], &rc_map->scan[i], in ir_establish_scancode()
406 (rc_map->len - i) * sizeof(struct rc_map_table)); in ir_establish_scancode()
407 rc_map->scan[i].scancode = scancode; in ir_establish_scancode()
408 rc_map->scan[i].keycode = KEY_RESERVED; in ir_establish_scancode()
409 rc_map->len++; in ir_establish_scancode()
429 struct rc_map *rc_map = &rdev->rc_map; in ir_setkeycode() local
435 spin_lock_irqsave(&rc_map->lock, flags); in ir_setkeycode()
439 if (index >= rc_map->len) { in ir_setkeycode()
448 index = ir_establish_scancode(rdev, rc_map, scancode, true); in ir_setkeycode()
449 if (index >= rc_map->len) { in ir_setkeycode()
455 *old_keycode = ir_update_mapping(rdev, rc_map, index, ke->keycode); in ir_setkeycode()
458 spin_unlock_irqrestore(&rc_map->lock, flags); in ir_setkeycode()
471 static int ir_setkeytable(struct rc_dev *dev, const struct rc_map *from) in ir_setkeytable()
473 struct rc_map *rc_map = &dev->rc_map; in ir_setkeytable() local
477 rc = ir_create_table(dev, rc_map, from->name, from->rc_proto, in ir_setkeytable()
483 index = ir_establish_scancode(dev, rc_map, in ir_setkeytable()
485 if (index >= rc_map->len) { in ir_setkeytable()
490 ir_update_mapping(dev, rc_map, index, in ir_setkeytable()
495 ir_free_table(rc_map); in ir_setkeytable()
522 static unsigned int ir_lookup_by_scancode(const struct rc_map *rc_map, in ir_lookup_by_scancode() argument
527 res = bsearch(&scancode, rc_map->scan, rc_map->len, in ir_lookup_by_scancode()
532 return res - rc_map->scan; in ir_lookup_by_scancode()
548 struct rc_map *rc_map = &rdev->rc_map; in ir_getkeycode() local
555 spin_lock_irqsave(&rc_map->lock, flags); in ir_getkeycode()
564 index = ir_lookup_by_scancode(rc_map, scancode); in ir_getkeycode()
567 if (index < rc_map->len) { in ir_getkeycode()
568 entry = &rc_map->scan[index]; in ir_getkeycode()
590 spin_unlock_irqrestore(&rc_map->lock, flags); in ir_getkeycode()
607 struct rc_map *rc_map = &dev->rc_map; in rc_g_keycode_from_table() local
612 spin_lock_irqsave(&rc_map->lock, flags); in rc_g_keycode_from_table()
614 index = ir_lookup_by_scancode(rc_map, scancode); in rc_g_keycode_from_table()
615 keycode = index < rc_map->len ? in rc_g_keycode_from_table()
616 rc_map->scan[index].keycode : KEY_RESERVED; in rc_g_keycode_from_table()
618 spin_unlock_irqrestore(&rc_map->lock, flags); in rc_g_keycode_from_table()
1625 if (ret == 0 && dev->rc_map.name) in rc_dev_uevent()
1626 ret = add_uevent_var(env, "NAME=%s", dev->rc_map.name); in rc_dev_uevent()
1722 spin_lock_init(&dev->rc_map.lock); in rc_allocate_device()
1786 struct rc_map *rc_map; in rc_prepare_rx_device() local
1792 rc_map = rc_map_get(dev->map_name); in rc_prepare_rx_device()
1793 if (!rc_map) in rc_prepare_rx_device()
1794 rc_map = rc_map_get(RC_MAP_EMPTY); in rc_prepare_rx_device()
1795 if (!rc_map || !rc_map->scan || rc_map->size == 0) in rc_prepare_rx_device()
1798 rc = ir_setkeytable(dev, rc_map); in rc_prepare_rx_device()
1802 rc_proto = BIT_ULL(rc_map->rc_proto); in rc_prepare_rx_device()
1842 ir_free_table(&dev->rc_map); in rc_prepare_rx_device()
1887 ir_free_table(&dev->rc_map); in rc_free_rx_device()
1979 ir_free_table(&dev->rc_map); in rc_register_device()