Lines Matching refs:hm

52 #define DPRINTFN(hm, n, fmt, ...) do {					\  argument
53 if ((hm)->debug_var != NULL && *(hm)->debug_var >= (n)) { \
54 device_printf((hm)->dev, "%s: " fmt, \
58 #define DPRINTF(hm, ...) DPRINTFN(hm, 1, __VA_ARGS__) argument
67 #define HIDMAP_WANT_MERGE_KEYS(hm) ((hm)->key_rel != NULL) argument
69 #define HIDMAP_FOREACH_ITEM(hm, mi, uoff) \ argument
72 (hm), &_map, &_item, &_uoff_priv, &(uoff))) != NULL;)
90 hidmap_get_next_map_item(struct hidmap *hm, u_int *map, u_int *item, in hidmap_get_next_map_item() argument
96 hm->map[*map], hm->nmap_items[*map], item, uoff)) { in hidmap_get_next_map_item()
100 if (*map >= hm->nmaps) in hidmap_get_next_map_item()
105 return (hm->map[*map] + *item); in hidmap_get_next_map_item()
109 _hidmap_set_debug_var(struct hidmap *hm, int *debug_var) in _hidmap_set_debug_var() argument
112 hm->debug_var = debug_var; in _hidmap_set_debug_var()
129 hidmap_support_key(struct hidmap *hm, uint16_t key) in hidmap_support_key() argument
131 if (hm->key_press == NULL) { in hidmap_support_key()
132 hm->key_press = malloc(howmany(KEY_CNT, 8), M_DEVBUF, in hidmap_support_key()
134 evdev_support_event(hm->evdev, EV_KEY); in hidmap_support_key()
135 hm->key_min = key; in hidmap_support_key()
136 hm->key_max = key; in hidmap_support_key()
138 hm->key_min = MIN(hm->key_min, key); in hidmap_support_key()
139 hm->key_max = MAX(hm->key_max, key); in hidmap_support_key()
140 if (isset(hm->key_press, key)) { in hidmap_support_key()
141 if (hm->key_rel == NULL) in hidmap_support_key()
142 hm->key_rel = malloc(howmany(KEY_CNT, 8), M_DEVBUF, in hidmap_support_key()
145 setbit(hm->key_press, key); in hidmap_support_key()
146 evdev_support_key(hm->evdev, key); in hidmap_support_key()
151 hidmap_push_key(struct hidmap *hm, uint16_t key, int32_t value) in hidmap_push_key() argument
153 if (HIDMAP_WANT_MERGE_KEYS(hm)) in hidmap_push_key()
154 setbit(value != 0 ? hm->key_press : hm->key_rel, key); in hidmap_push_key()
156 evdev_push_key(hm->evdev, key, value); in hidmap_push_key()
160 hidmap_sync_keys(struct hidmap *hm) in hidmap_sync_keys() argument
165 for (j = hm->key_min / 8; j <= hm->key_max / 8; j++) { in hidmap_sync_keys()
166 if (hm->key_press[j] != hm->key_rel[j]) { in hidmap_sync_keys()
168 press = isset(hm->key_press, i); in hidmap_sync_keys()
169 rel = isset(hm->key_rel, i); in hidmap_sync_keys()
171 evdev_push_key(hm->evdev, i, press); in hidmap_sync_keys()
175 bzero(hm->key_press, howmany(KEY_CNT, 8)); in hidmap_sync_keys()
176 bzero(hm->key_rel, howmany(KEY_CNT, 8)); in hidmap_sync_keys()
182 struct hidmap *hm = context; in hidmap_intr() local
191 DPRINTFN(hm, 6, "hm=%p len=%d\n", hm, len); in hidmap_intr()
192 DPRINTFN(hm, 6, "data = %*D\n", len, buf, " "); in hidmap_intr()
195 if (hm->hid_items[0].id) { in hidmap_intr()
201 hm->intr_buf = buf; in hidmap_intr()
202 hm->intr_len = len; in hidmap_intr()
204 for (hi = hm->hid_items; hi < hm->hid_items + hm->nhid_items; hi++) { in hidmap_intr()
207 DPRINTFN(hm, 6, "type=%d item=%*D\n", hi->type, in hidmap_intr()
209 if (hi->cb(hm, hi, (union hidmap_cb_ctx){.rid = id}) in hidmap_intr()
229 DPRINTFN(hm, 6, "type=%d data=%d item=%*D\n", hi->type, data, in hidmap_intr()
239 if (hi->cb(hm, hi, (union hidmap_cb_ctx){.data = data}) in hidmap_intr()
262 hidmap_push_key(hm, hi->code, data); in hidmap_intr()
264 evdev_push_event(hm->evdev, hi->evtype, in hidmap_intr()
284 DPRINTF(hm, "Can not map unknown HID " in hidmap_intr()
304 HIDMAP_FOREACH_ITEM(hm, mi, uoff) { in hidmap_intr()
313 DPRINTF(hm, "Can not map unknown HID " in hidmap_intr()
319 hidmap_push_key(hm, hi->last_key, 0); in hidmap_intr()
321 hidmap_push_key(hm, key, 1); in hidmap_intr()
332 if (HIDMAP_WANT_MERGE_KEYS(hm)) in hidmap_intr()
333 hidmap_sync_keys(hm); in hidmap_intr()
334 evdev_sync(hm->evdev); in hidmap_intr()
500 hidmap_add_map(struct hidmap *hm, const struct hidmap_item *map, in hidmap_add_map() argument
507 uint8_t tlc_index = hidbus_get_index(hm->dev); in hidmap_add_map()
510 for (i = 0; i < hm->nmaps; i++) in hidmap_add_map()
511 if (hm->map[i] == map) in hidmap_add_map()
514 error = hid_get_report_descr(hm->dev, &d_ptr, &d_len); in hidmap_add_map()
516 device_printf(hm->dev, "could not retrieve report descriptor " in hidmap_add_map()
521 hm->cb_state = HIDMAP_CB_IS_PROBING; in hidmap_add_map()
527 KASSERT(hm->nmaps < HIDMAP_MAX_MAPS, in hidmap_add_map()
529 hm->nhid_items += items; in hidmap_add_map()
530 hm->map[hm->nmaps] = map; in hidmap_add_map()
531 hm->nmap_items[hm->nmaps] = nitems_map; in hidmap_add_map()
532 hm->nmaps++; in hidmap_add_map()
538 hidmap_parse_hid_item(struct hidmap *hm, struct hid_item *hi, in hidmap_parse_hid_item() argument
547 HIDMAP_FOREACH_ITEM(hm, mi, uoff) { in hidmap_parse_hid_item()
556 if (mi->cb(hm, &hi_temp, in hidmap_parse_hid_item()
565 HIDMAP_FOREACH_ITEM(hm, mi, uoff) { in hidmap_parse_hid_item()
576 hidmap_support_key(hm, item->code); in hidmap_parse_hid_item()
579 evdev_support_event(hm->evdev, EV_REL); in hidmap_parse_hid_item()
580 evdev_support_rel(hm->evdev, in hidmap_parse_hid_item()
584 evdev_support_event(hm->evdev, EV_ABS); in hidmap_parse_hid_item()
585 evdev_support_abs(hm->evdev, in hidmap_parse_hid_item()
594 evdev_support_event(hm->evdev, EV_SW); in hidmap_parse_hid_item()
595 evdev_support_sw(hm->evdev, in hidmap_parse_hid_item()
608 HIDMAP_FOREACH_ITEM(hm, mi, uoff) { in hidmap_parse_hid_item()
610 hidmap_support_key(hm, mi->code + uoff); in hidmap_parse_hid_item()
623 HIDMAP_FOREACH_ITEM(hm, mi, uoff) { in hidmap_parse_hid_item()
625 hidmap_support_key(hm, mi->code + uoff); in hidmap_parse_hid_item()
648 DPRINTFN(hm, 6, "usage=%04x id=%d loc=%u/%u type=%d item=%*D\n", in hidmap_parse_hid_item()
656 hidmap_parse_hid_descr(struct hidmap *hm, uint8_t tlc_index) in hidmap_parse_hid_descr() argument
659 struct hidmap_hid_item *item = hm->hid_items; in hidmap_parse_hid_descr()
666 error = hid_get_report_descr(hm->dev, &d_ptr, &d_len); in hidmap_parse_hid_descr()
668 DPRINTF(hm, "could not retrieve report descriptor from " in hidmap_parse_hid_descr()
681 if (hidmap_parse_hid_item(hm, &hi, item)) in hidmap_parse_hid_descr()
683 KASSERT(item <= hm->hid_items + hm->nhid_items, in hidmap_parse_hid_descr()
689 for (i = 0; i < hm->nmaps; i++) { in hidmap_parse_hid_descr()
690 for (map = hm->map[i]; in hidmap_parse_hid_descr()
691 map < hm->map[i] + hm->nmap_items[i]; in hidmap_parse_hid_descr()
694 map->cb(hm, item, (union hidmap_cb_ctx){}) == 0) { in hidmap_parse_hid_descr()
706 if (hm->nhid_items != item - hm->hid_items) in hidmap_parse_hid_descr()
707 DPRINTF(hm, "Parsed HID item number mismatch: expected=%u " in hidmap_parse_hid_descr()
708 "result=%td\n", hm->nhid_items, item - hm->hid_items); in hidmap_parse_hid_descr()
709 hm->nhid_items = item - hm->hid_items; in hidmap_parse_hid_descr()
711 if (HIDMAP_WANT_MERGE_KEYS(hm)) in hidmap_parse_hid_descr()
712 bzero(hm->key_press, howmany(KEY_CNT, 8)); in hidmap_parse_hid_descr()
718 hidmap_probe(struct hidmap* hm, device_t dev, in hidmap_probe() argument
729 hidmap_set_dev(hm, dev); in hidmap_probe()
731 error = hidmap_add_map(hm, map, nitems_map, caps); in hidmap_probe()
741 hidmap_attach(struct hidmap* hm) in hidmap_attach() argument
743 const struct hid_device_info *hw = hid_get_device_info(hm->dev); in hidmap_attach()
750 if (hm->debug_var == NULL) { in hidmap_attach()
751 hm->debug_var = &hm->debug_level; in hidmap_attach()
753 device_get_name(hm->dev)); in hidmap_attach()
754 TUNABLE_INT_FETCH(tunable, &hm->debug_level); in hidmap_attach()
755 SYSCTL_ADD_INT(device_get_sysctl_ctx(hm->dev), in hidmap_attach()
756 SYSCTL_CHILDREN(device_get_sysctl_tree(hm->dev)), in hidmap_attach()
758 &hm->debug_level, 0, "Verbosity level"); in hidmap_attach()
762 DPRINTFN(hm, 11, "hm=%p\n", hm); in hidmap_attach()
764 hm->cb_state = HIDMAP_CB_IS_ATTACHING; in hidmap_attach()
766 hm->hid_items = malloc(hm->nhid_items * sizeof(struct hid_item), in hidmap_attach()
769 hidbus_set_intr(hm->dev, hidmap_intr, hm); in hidmap_attach()
770 hm->evdev_methods = (struct evdev_methods) { in hidmap_attach()
775 hm->evdev = evdev_alloc(); in hidmap_attach()
776 evdev_set_name(hm->evdev, device_get_desc(hm->dev)); in hidmap_attach()
777 evdev_set_phys(hm->evdev, device_get_nameunit(hm->dev)); in hidmap_attach()
778 evdev_set_id(hm->evdev, hw->idBus, hw->idVendor, hw->idProduct, in hidmap_attach()
780 evdev_set_serial(hm->evdev, hw->serial); in hidmap_attach()
781 evdev_set_flag(hm->evdev, EVDEV_FLAG_EXT_EPOCH); /* hidbus child */ in hidmap_attach()
782 evdev_support_event(hm->evdev, EV_SYN); in hidmap_attach()
783 error = hidmap_parse_hid_descr(hm, hidbus_get_index(hm->dev)); in hidmap_attach()
785 DPRINTF(hm, "error=%d\n", error); in hidmap_attach()
786 hidmap_detach(hm); in hidmap_attach()
790 evdev_set_methods(hm->evdev, hm->dev, &hm->evdev_methods); in hidmap_attach()
791 hm->cb_state = HIDMAP_CB_IS_RUNNING; in hidmap_attach()
793 error = evdev_register(hm->evdev); in hidmap_attach()
795 DPRINTF(hm, "error=%d\n", error); in hidmap_attach()
796 hidmap_detach(hm); in hidmap_attach()
804 hidmap_detach(struct hidmap* hm) in hidmap_detach() argument
808 DPRINTFN(hm, 11, "\n"); in hidmap_detach()
810 hm->cb_state = HIDMAP_CB_IS_DETACHING; in hidmap_detach()
812 evdev_free(hm->evdev); in hidmap_detach()
813 if (hm->hid_items != NULL) { in hidmap_detach()
814 for (hi = hm->hid_items; in hidmap_detach()
815 hi < hm->hid_items + hm->nhid_items; in hidmap_detach()
819 hi->cb(hm, hi, (union hidmap_cb_ctx){}); in hidmap_detach()
822 free(hm->hid_items, M_DEVBUF); in hidmap_detach()
825 free(hm->key_press, M_DEVBUF); in hidmap_detach()
826 free(hm->key_rel, M_DEVBUF); in hidmap_detach()