Lines Matching refs:rc_map
106 struct rc_map *rc_map_get(const char *name) in rc_map_get()
177 static int ir_create_table(struct rc_map *rc_map, in ir_create_table() argument
180 rc_map->name = kstrdup(name, GFP_KERNEL); in ir_create_table()
181 if (!rc_map->name) in ir_create_table()
183 rc_map->rc_proto = rc_proto; in ir_create_table()
184 rc_map->alloc = roundup_pow_of_two(size * sizeof(struct rc_map_table)); in ir_create_table()
185 rc_map->size = rc_map->alloc / sizeof(struct rc_map_table); in ir_create_table()
186 rc_map->scan = kmalloc(rc_map->alloc, GFP_KERNEL); in ir_create_table()
187 if (!rc_map->scan) { in ir_create_table()
188 kfree(rc_map->name); in ir_create_table()
189 rc_map->name = NULL; in ir_create_table()
194 rc_map->size, rc_map->alloc); in ir_create_table()
205 static void ir_free_table(struct rc_map *rc_map) in ir_free_table() argument
207 rc_map->size = 0; in ir_free_table()
208 kfree(rc_map->name); in ir_free_table()
209 rc_map->name = NULL; in ir_free_table()
210 kfree(rc_map->scan); in ir_free_table()
211 rc_map->scan = NULL; in ir_free_table()
223 static int ir_resize_table(struct rc_map *rc_map, gfp_t gfp_flags) in ir_resize_table() argument
225 unsigned int oldalloc = rc_map->alloc; in ir_resize_table()
227 struct rc_map_table *oldscan = rc_map->scan; in ir_resize_table()
230 if (rc_map->size == rc_map->len) { in ir_resize_table()
232 if (rc_map->alloc >= IR_TAB_MAX_SIZE) in ir_resize_table()
239 if ((rc_map->len * 3 < rc_map->size) && (oldalloc > IR_TAB_MIN_SIZE)) { in ir_resize_table()
254 memcpy(newscan, rc_map->scan, rc_map->len * sizeof(struct rc_map_table)); in ir_resize_table()
255 rc_map->scan = newscan; in ir_resize_table()
256 rc_map->alloc = newalloc; in ir_resize_table()
257 rc_map->size = rc_map->alloc / sizeof(struct rc_map_table); in ir_resize_table()
274 struct rc_map *rc_map, in ir_update_mapping() argument
278 int old_keycode = rc_map->scan[index].keycode; in ir_update_mapping()
284 index, rc_map->scan[index].scancode); in ir_update_mapping()
285 rc_map->len--; in ir_update_mapping()
286 memmove(&rc_map->scan[index], &rc_map->scan[index+ 1], in ir_update_mapping()
287 (rc_map->len - index) * sizeof(struct rc_map_table)); in ir_update_mapping()
292 rc_map->scan[index].scancode, new_keycode); in ir_update_mapping()
293 rc_map->scan[index].keycode = new_keycode; in ir_update_mapping()
301 for (i = 0; i < rc_map->len; i++) { in ir_update_mapping()
302 if (rc_map->scan[i].keycode == old_keycode) { in ir_update_mapping()
309 ir_resize_table(rc_map, GFP_ATOMIC); in ir_update_mapping()
330 struct rc_map *rc_map, in ir_establish_scancode() argument
348 for (i = 0; i < rc_map->len; i++) { in ir_establish_scancode()
349 if (rc_map->scan[i].scancode == scancode) in ir_establish_scancode()
353 if (rc_map->scan[i].scancode >= scancode) in ir_establish_scancode()
358 if (rc_map->size == rc_map->len) { in ir_establish_scancode()
359 if (!resize || ir_resize_table(rc_map, GFP_ATOMIC)) in ir_establish_scancode()
364 if (i < rc_map->len) in ir_establish_scancode()
365 memmove(&rc_map->scan[i + 1], &rc_map->scan[i], in ir_establish_scancode()
366 (rc_map->len - i) * sizeof(struct rc_map_table)); in ir_establish_scancode()
367 rc_map->scan[i].scancode = scancode; in ir_establish_scancode()
368 rc_map->scan[i].keycode = KEY_RESERVED; in ir_establish_scancode()
369 rc_map->len++; in ir_establish_scancode()
388 struct rc_map *rc_map = &rdev->rc_map; in ir_setkeycode() local
394 spin_lock_irqsave(&rc_map->lock, flags); in ir_setkeycode()
398 if (index >= rc_map->len) { in ir_setkeycode()
407 index = ir_establish_scancode(rdev, rc_map, scancode, true); in ir_setkeycode()
408 if (index >= rc_map->len) { in ir_setkeycode()
414 *old_keycode = ir_update_mapping(rdev, rc_map, index, ke->keycode); in ir_setkeycode()
417 spin_unlock_irqrestore(&rc_map->lock, flags); in ir_setkeycode()
431 const struct rc_map *from) in ir_setkeytable()
433 struct rc_map *rc_map = &dev->rc_map; in ir_setkeytable() local
437 rc = ir_create_table(rc_map, from->name, in ir_setkeytable()
443 rc_map->size, rc_map->alloc); in ir_setkeytable()
446 index = ir_establish_scancode(dev, rc_map, in ir_setkeytable()
448 if (index >= rc_map->len) { in ir_setkeytable()
453 ir_update_mapping(dev, rc_map, index, in ir_setkeytable()
458 ir_free_table(rc_map); in ir_setkeytable()
472 static unsigned int ir_lookup_by_scancode(const struct rc_map *rc_map, in ir_lookup_by_scancode() argument
476 int end = rc_map->len - 1; in ir_lookup_by_scancode()
481 if (rc_map->scan[mid].scancode < scancode) in ir_lookup_by_scancode()
483 else if (rc_map->scan[mid].scancode > scancode) in ir_lookup_by_scancode()
505 struct rc_map *rc_map = &rdev->rc_map; in ir_getkeycode() local
512 spin_lock_irqsave(&rc_map->lock, flags); in ir_getkeycode()
521 index = ir_lookup_by_scancode(rc_map, scancode); in ir_getkeycode()
524 if (index < rc_map->len) { in ir_getkeycode()
525 entry = &rc_map->scan[index]; in ir_getkeycode()
548 spin_unlock_irqrestore(&rc_map->lock, flags); in ir_getkeycode()
564 struct rc_map *rc_map = &dev->rc_map; in rc_g_keycode_from_table() local
569 spin_lock_irqsave(&rc_map->lock, flags); in rc_g_keycode_from_table()
571 index = ir_lookup_by_scancode(rc_map, scancode); in rc_g_keycode_from_table()
572 keycode = index < rc_map->len ? in rc_g_keycode_from_table()
573 rc_map->scan[index].keycode : KEY_RESERVED; in rc_g_keycode_from_table()
575 spin_unlock_irqrestore(&rc_map->lock, flags); in rc_g_keycode_from_table()
1479 if (dev->rc_map.name) in rc_dev_uevent()
1480 ADD_HOTPLUG_VAR("NAME=%s", dev->rc_map.name); in rc_dev_uevent()
1559 spin_lock_init(&dev->rc_map.lock); in rc_allocate_device()
1623 struct rc_map *rc_map; in rc_prepare_rx_device() local
1629 rc_map = rc_map_get(dev->map_name); in rc_prepare_rx_device()
1630 if (!rc_map) in rc_prepare_rx_device()
1631 rc_map = rc_map_get(RC_MAP_EMPTY); in rc_prepare_rx_device()
1632 if (!rc_map || !rc_map->scan || rc_map->size == 0) in rc_prepare_rx_device()
1635 rc = ir_setkeytable(dev, rc_map); in rc_prepare_rx_device()
1639 rc_proto = BIT_ULL(rc_map->rc_proto); in rc_prepare_rx_device()
1668 ir_free_table(&dev->rc_map); in rc_prepare_rx_device()
1710 ir_free_table(&dev->rc_map); in rc_free_rx_device()
1786 ir_free_table(&dev->rc_map); in rc_register_device()