Lines Matching +full:key +full:- +full:enable
1 // SPDX-License-Identifier: GPL-2.0-or-later
44 struct snd_jack *jack = device->device_data; in snd_jack_dev_disconnect()
49 guard(mutex)(&jack->input_dev_lock); in snd_jack_dev_disconnect()
50 if (!jack->input_dev) in snd_jack_dev_disconnect()
55 if (jack->registered) in snd_jack_dev_disconnect()
56 input_unregister_device(jack->input_dev); in snd_jack_dev_disconnect()
58 input_free_device(jack->input_dev); in snd_jack_dev_disconnect()
59 jack->input_dev = NULL; in snd_jack_dev_disconnect()
66 struct snd_jack *jack = device->device_data; in snd_jack_dev_free()
67 struct snd_card *card = device->card; in snd_jack_dev_free()
70 list_for_each_entry_safe(jack_kctl, tmp_jack_kctl, &jack->kctl_list, list) { in snd_jack_dev_free()
71 list_del_init(&jack_kctl->list); in snd_jack_dev_free()
72 snd_ctl_remove(card, jack_kctl->kctl); in snd_jack_dev_free()
75 if (jack->private_free) in snd_jack_dev_free()
76 jack->private_free(jack); in snd_jack_dev_free()
80 kfree(jack->id); in snd_jack_dev_free()
89 struct snd_jack *jack = device->device_data; in snd_jack_dev_register()
90 struct snd_card *card = device->card; in snd_jack_dev_register()
93 snprintf(jack->name, sizeof(jack->name), "%s %s", in snd_jack_dev_register()
94 card->shortname, jack->id); in snd_jack_dev_register()
96 guard(mutex)(&jack->input_dev_lock); in snd_jack_dev_register()
97 if (!jack->input_dev) in snd_jack_dev_register()
100 jack->input_dev->name = jack->name; in snd_jack_dev_register()
103 if (!jack->input_dev->dev.parent) in snd_jack_dev_register()
104 jack->input_dev->dev.parent = snd_card_get_device_link(card); in snd_jack_dev_register()
107 for (i = 0; i < ARRAY_SIZE(jack->key); i++) { in snd_jack_dev_register()
110 if (!(jack->type & testbit)) in snd_jack_dev_register()
113 if (!jack->key[i]) in snd_jack_dev_register()
114 jack->key[i] = BTN_0 + i; in snd_jack_dev_register()
116 input_set_capability(jack->input_dev, EV_KEY, jack->key[i]); in snd_jack_dev_register()
119 err = input_register_device(jack->input_dev); in snd_jack_dev_register()
121 jack->registered = 1; in snd_jack_dev_register()
137 jack = jack_kctl->jack; in snd_jack_inject_report()
139 if (jack_kctl->sw_inject_enable) in snd_jack_inject_report()
140 snd_kctl_jack_report(jack->card, jack_kctl->kctl, in snd_jack_inject_report()
141 status & jack_kctl->mask_bits); in snd_jack_inject_report()
144 if (!jack->input_dev) in snd_jack_inject_report()
147 for (i = 0; i < ARRAY_SIZE(jack->key); i++) { in snd_jack_inject_report()
148 int testbit = ((SND_JACK_BTN_0 >> i) & jack_kctl->mask_bits); in snd_jack_inject_report()
150 if (jack->type & testbit) in snd_jack_inject_report()
151 input_report_key(jack->input_dev, jack->key[i], in snd_jack_inject_report()
156 int testbit = ((1 << i) & jack_kctl->mask_bits); in snd_jack_inject_report()
158 if (jack->type & testbit) in snd_jack_inject_report()
159 input_report_switch(jack->input_dev, in snd_jack_inject_report()
164 input_sync(jack->input_dev); in snd_jack_inject_report()
171 struct snd_jack_kctl *jack_kctl = file->private_data; in sw_inject_enable_read()
175 len = scnprintf(buf, sizeof(buf), "%s: %s\t\t%s: %i\n", "Jack", jack_kctl->kctl->id.name, in sw_inject_enable_read()
176 "Inject Enabled", jack_kctl->sw_inject_enable); in sw_inject_enable_read()
185 struct snd_jack_kctl *jack_kctl = file->private_data; in sw_inject_enable_write()
187 unsigned long enable; in sw_inject_enable_write() local
190 ret = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, from, count); in sw_inject_enable_write()
191 err = kstrtoul(buf, 0, &enable); in sw_inject_enable_write()
195 if (jack_kctl->sw_inject_enable == (!!enable)) in sw_inject_enable_write()
198 jack_kctl->sw_inject_enable = !!enable; in sw_inject_enable_write()
200 if (!jack_kctl->sw_inject_enable) in sw_inject_enable_write()
201 snd_jack_report(jack_kctl->jack, jack_kctl->jack->hw_status_cache); in sw_inject_enable_write()
209 struct snd_jack_kctl *jack_kctl = file->private_data; in jackin_inject_write()
211 unsigned long enable; in jackin_inject_write() local
214 if (!jack_kctl->sw_inject_enable) in jackin_inject_write()
215 return -EINVAL; in jackin_inject_write()
217 ret = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, from, count); in jackin_inject_write()
218 err = kstrtoul(buf, 0, &enable); in jackin_inject_write()
222 snd_jack_inject_report(jack_kctl, !!enable ? jack_kctl->mask_bits : 0); in jackin_inject_write()
230 struct snd_jack_kctl *jack_kctl = file->private_data; in jack_kctl_id_read()
234 len = scnprintf(buf, sizeof(buf), "%s\n", jack_kctl->kctl->id.name); in jack_kctl_id_read()
268 struct snd_jack_kctl *jack_kctl = file->private_data; in jack_kctl_mask_bits_read()
272 len = parse_mask_bits(jack_kctl->mask_bits, buf, sizeof(buf)); in jack_kctl_mask_bits_read()
281 struct snd_jack_kctl *jack_kctl = file->private_data; in jack_kctl_status_read()
285 len = scnprintf(buf, sizeof(buf), "%s\n", jack_kctl->kctl->private_value ? in jack_kctl_status_read()
296 struct snd_jack_kctl *jack_kctl = file->private_data; in jack_type_read()
300 len = parse_mask_bits(jack_kctl->jack->type, buf, sizeof(buf)); in jack_type_read()
351 if (strstr(jack_kctl->kctl->id.name, "Phantom")) in snd_jack_debugfs_add_inject_node()
354 tname = kstrdup(jack_kctl->kctl->id.name, GFP_KERNEL); in snd_jack_debugfs_add_inject_node()
356 return -ENOMEM; in snd_jack_debugfs_add_inject_node()
363 jack_kctl->jack_debugfs_root = debugfs_create_dir(tname, jack->card->debugfs_root); in snd_jack_debugfs_add_inject_node()
366 debugfs_create_file("sw_inject_enable", 0644, jack_kctl->jack_debugfs_root, jack_kctl, in snd_jack_debugfs_add_inject_node()
369 debugfs_create_file("jackin_inject", 0200, jack_kctl->jack_debugfs_root, jack_kctl, in snd_jack_debugfs_add_inject_node()
372 debugfs_create_file("kctl_id", 0444, jack_kctl->jack_debugfs_root, jack_kctl, in snd_jack_debugfs_add_inject_node()
375 debugfs_create_file("mask_bits", 0444, jack_kctl->jack_debugfs_root, jack_kctl, in snd_jack_debugfs_add_inject_node()
378 debugfs_create_file("status", 0444, jack_kctl->jack_debugfs_root, jack_kctl, in snd_jack_debugfs_add_inject_node()
382 debugfs_create_file("type", 0444, jack_kctl->jack_debugfs_root, jack_kctl, in snd_jack_debugfs_add_inject_node()
392 list_for_each_entry(jack_kctl, &jack->kctl_list, list) { in snd_jack_remove_debugfs()
393 debugfs_remove(jack_kctl->jack_debugfs_root); in snd_jack_remove_debugfs()
394 jack_kctl->jack_debugfs_root = NULL; in snd_jack_remove_debugfs()
413 jack_kctl = kctl->private_data; in snd_jack_kctl_private_free()
415 list_del(&jack_kctl->list); in snd_jack_kctl_private_free()
422 jack_kctl->jack = jack; in snd_jack_kctl_add()
423 list_add_tail(&jack_kctl->list, &jack->kctl_list); in snd_jack_kctl_add()
446 jack_kctl->kctl = kctl; in snd_jack_kctl_new()
447 jack_kctl->mask_bits = mask; in snd_jack_kctl_new()
449 kctl->private_data = jack_kctl; in snd_jack_kctl_new()
450 kctl->private_free = snd_jack_kctl_private_free; in snd_jack_kctl_new()
459 * snd_jack_add_new_kctl - Create a new snd_jack_kctl and add it to jack
473 jack_kctl = snd_jack_kctl_new(jack->card, name, mask); in snd_jack_add_new_kctl()
475 return -ENOMEM; in snd_jack_add_new_kctl()
483 * snd_jack_new - Create a new jack
514 return -ENOMEM; in snd_jack_new()
519 return -ENOMEM; in snd_jack_new()
521 jack->id = kstrdup(id, GFP_KERNEL); in snd_jack_new()
522 if (jack->id == NULL) { in snd_jack_new()
524 return -ENOMEM; in snd_jack_new()
528 mutex_init(&jack->input_dev_lock); in snd_jack_new()
534 jack->input_dev = input_allocate_device(); in snd_jack_new()
535 if (jack->input_dev == NULL) { in snd_jack_new()
536 err = -ENOMEM; in snd_jack_new()
540 jack->input_dev->phys = "ALSA"; in snd_jack_new()
542 jack->type = type; in snd_jack_new()
546 input_set_capability(jack->input_dev, EV_SW, in snd_jack_new()
556 jack->card = card; in snd_jack_new()
557 INIT_LIST_HEAD(&jack->kctl_list); in snd_jack_new()
568 input_free_device(jack->input_dev); in snd_jack_new()
570 kfree(jack->id); in snd_jack_new()
578 * snd_jack_set_parent - Set the parent device for a jack
589 WARN_ON(jack->registered); in snd_jack_set_parent()
590 guard(mutex)(&jack->input_dev_lock); in snd_jack_set_parent()
591 if (jack->input_dev) in snd_jack_set_parent()
592 jack->input_dev->dev.parent = parent; in snd_jack_set_parent()
597 * snd_jack_set_key - Set a key mapping on a jack
600 * @type: Jack report type for this key
601 * @keytype: Input layer key type to be reported
603 * Map a SND_JACK_BTN_* button type to an input layer key, allowing
613 * access the input device directly - devices with complex input
624 int key = fls(SND_JACK_BTN_0) - fls(type); in snd_jack_set_key() local
626 WARN_ON(jack->registered); in snd_jack_set_key()
628 if (!keytype || key >= ARRAY_SIZE(jack->key)) in snd_jack_set_key()
629 return -EINVAL; in snd_jack_set_key()
631 jack->type |= type; in snd_jack_set_key()
632 jack->key[key] = keytype; in snd_jack_set_key()
639 * snd_jack_report - Report the current status of a jack
658 jack->hw_status_cache = status; in snd_jack_report()
660 list_for_each_entry(jack_kctl, &jack->kctl_list, list) in snd_jack_report()
661 if (jack_kctl->sw_inject_enable) in snd_jack_report()
662 mask_bits |= jack_kctl->mask_bits; in snd_jack_report()
664 snd_kctl_jack_report(jack->card, jack_kctl->kctl, in snd_jack_report()
665 status & jack_kctl->mask_bits); in snd_jack_report()
668 idev = input_get_device(jack->input_dev); in snd_jack_report()
672 for (i = 0; i < ARRAY_SIZE(jack->key); i++) { in snd_jack_report()
675 if (jack->type & testbit) in snd_jack_report()
676 input_report_key(idev, jack->key[i], in snd_jack_report()
683 if (jack->type & testbit) in snd_jack_report()