Lines Matching refs:jack
179 struct cras_alsa_jack *jack = calloc(1, sizeof(*jack)); in cras_alloc_jack() local
180 if (jack == NULL) in cras_alloc_jack()
182 jack->is_gpio = is_gpio; in cras_alloc_jack()
183 return jack; in cras_alloc_jack()
186 static void cras_free_jack(struct cras_alsa_jack *jack, int rm_select_fd) in cras_free_jack() argument
188 if (!jack) in cras_free_jack()
191 free(jack->ucm_device); in cras_free_jack()
192 free((void *)jack->edid_file); in cras_free_jack()
193 if (jack->display_info_timer) in cras_free_jack()
195 jack->display_info_timer); in cras_free_jack()
197 if (jack->is_gpio) { in cras_free_jack()
198 free(jack->gpio.device_name); in cras_free_jack()
199 if (jack->gpio.fd >= 0) { in cras_free_jack()
201 cras_system_rm_select_fd(jack->gpio.fd); in cras_free_jack()
202 close(jack->gpio.fd); in cras_free_jack()
210 if (!jack->is_gpio && jack->elem) in cras_free_jack()
211 snd_hctl_elem_set_callback(jack->elem, NULL); in cras_free_jack()
213 free((void *)jack->override_type_name); in cras_free_jack()
214 free(jack); in cras_free_jack()
218 static int get_jack_current_state(struct cras_alsa_jack *jack) in get_jack_current_state() argument
222 if (jack->is_gpio) in get_jack_current_state()
223 return jack->gpio.current_state; in get_jack_current_state()
226 snd_hctl_elem_read(jack->elem, elem_value); in get_jack_current_state()
231 static int read_jack_edid(const struct cras_alsa_jack *jack, uint8_t *edid) in read_jack_edid() argument
235 fd = open(jack->edid_file, O_RDONLY); in read_jack_edid()
247 static int check_jack_edid(struct cras_alsa_jack *jack) in check_jack_edid() argument
251 if (read_jack_edid(jack, edid)) in check_jack_edid()
258 jack->gpio.current_state = 0; in check_jack_edid()
262 static int get_jack_edid_monitor_name(const struct cras_alsa_jack *jack, in get_jack_edid_monitor_name() argument
267 if (read_jack_edid(jack, edid)) in get_jack_edid_monitor_name()
276 static int check_jack_eld(struct cras_alsa_jack *jack) in check_jack_eld() argument
284 if (snd_hctl_elem_info(jack->eld_control, elem_info) != 0) in check_jack_eld()
301 static inline void jack_state_change_cb(struct cras_alsa_jack *jack, int retry) in jack_state_change_cb() argument
305 if (jack->display_info_timer) { in jack_state_change_cb()
306 cras_tm_cancel_timer(tm, jack->display_info_timer); in jack_state_change_cb()
307 jack->display_info_timer = NULL; in jack_state_change_cb()
310 jack->display_info_retries = in jack_state_change_cb()
311 jack->is_gpio ? DISPLAY_INFO_GPIO_MAX_RETRIES : in jack_state_change_cb()
315 if (!get_jack_current_state(jack)) in jack_state_change_cb()
322 if (jack->edid_file == NULL && jack->eld_control == NULL) in jack_state_change_cb()
324 if (jack->edid_file && (check_jack_edid(jack) == 0)) in jack_state_change_cb()
326 if (jack->eld_control && (check_jack_eld(jack) == 0)) in jack_state_change_cb()
329 if (--jack->display_info_retries == 0) { in jack_state_change_cb()
330 if (jack->is_gpio) in jack_state_change_cb()
331 jack->gpio.current_state = 0; in jack_state_change_cb()
332 if (jack->edid_file) in jack_state_change_cb()
334 jack->edid_file); in jack_state_change_cb()
338 jack->display_info_timer = cras_tm_create_timer( in jack_state_change_cb()
339 tm, DISPLAY_INFO_RETRY_DELAY_MS, display_info_delay_cb, jack); in jack_state_change_cb()
343 jack->jack_list->change_callback(jack, get_jack_current_state(jack), in jack_state_change_cb()
344 jack->jack_list->callback_data); in jack_state_change_cb()
351 static void gpio_switch_initial_state(struct cras_alsa_jack *jack) in gpio_switch_initial_state() argument
354 int r = sys_input_get_switch_state(jack->gpio.fd, in gpio_switch_initial_state()
355 jack->gpio.switch_event, &v); in gpio_switch_initial_state()
356 jack->gpio.current_state = r == 0 ? v : 0; in gpio_switch_initial_state()
357 jack_state_change_cb(jack, 1); in gpio_switch_initial_state()
371 struct cras_alsa_jack *jack = (struct cras_alsa_jack *)arg; in display_info_delay_cb() local
373 jack->display_info_timer = NULL; in display_info_delay_cb()
374 jack_state_change_cb(jack, 0); in display_info_delay_cb()
385 struct cras_alsa_jack *jack = arg; in gpio_switch_callback() local
390 r = gpio_switch_read(jack->gpio.fd, ev, in gpio_switch_callback()
396 if (is_audio_switch_event(&ev[i], jack->gpio.switch_event)) { in gpio_switch_callback()
397 jack->gpio.current_state = ev[i].value; in gpio_switch_callback()
399 jack_state_change_cb(jack, 1); in gpio_switch_callback()
409 gpio_jack_match_device(const struct cras_alsa_jack *jack, in gpio_jack_match_device() argument
417 if (!jack_list->ucm || !jack->ucm_device) in gpio_jack_match_device()
424 jack_list->ucm, jack->ucm_device, direction); in gpio_jack_match_device()
442 struct cras_alsa_jack *jack; in create_jack_for_gpio() local
451 jack = cras_alloc_jack(1); in create_jack_for_gpio()
452 if (jack == NULL) in create_jack_for_gpio()
455 jack->gpio.fd = gpio_switch_open(pathname); in create_jack_for_gpio()
456 if (jack->gpio.fd == -1) { in create_jack_for_gpio()
461 jack->gpio.switch_event = switch_event; in create_jack_for_gpio()
462 jack->jack_list = jack_list; in create_jack_for_gpio()
463 jack->gpio.device_name = strdup(dev_name); in create_jack_for_gpio()
464 if (!jack->gpio.device_name) { in create_jack_for_gpio()
469 if (!strstr(jack->gpio.device_name, card_name) || in create_jack_for_gpio()
470 (gpio_switch_eviocgbit(jack->gpio.fd, bits, sizeof(bits)) < 0) || in create_jack_for_gpio()
476 *out_jack = jack; in create_jack_for_gpio()
481 cras_free_jack(jack, 0); in create_jack_for_gpio()
489 struct cras_alsa_jack *jack, in cras_complete_gpio_jack() argument
495 if (jack->ucm_device) { in cras_complete_gpio_jack()
496 jack->edid_file = ucm_get_edid_file_for_dev(jack_list->ucm, in cras_complete_gpio_jack()
497 jack->ucm_device); in cras_complete_gpio_jack()
500 r = sys_input_get_switch_state(jack->gpio.fd, switch_event, in cras_complete_gpio_jack()
501 &jack->gpio.current_state); in cras_complete_gpio_jack()
503 cras_free_jack(jack, 0); in cras_complete_gpio_jack()
506 r = cras_system_add_select_fd(jack->gpio.fd, gpio_switch_callback, jack, in cras_complete_gpio_jack()
510 cras_free_jack(jack, 0); in cras_complete_gpio_jack()
514 DL_APPEND(jack_list->jacks, jack); in cras_complete_gpio_jack()
516 data->result_jack = jack; in cras_complete_gpio_jack()
533 struct cras_alsa_jack *jack; in open_and_monitor_gpio() local
539 &jack); in open_and_monitor_gpio()
544 jack->ucm_device = ucm_get_dev_for_jack( in open_and_monitor_gpio()
545 jack_list->ucm, jack->gpio.device_name, direction); in open_and_monitor_gpio()
547 if (!gpio_jack_match_device(jack, jack_list, direction)) { in open_and_monitor_gpio()
548 cras_free_jack(jack, 0); in open_and_monitor_gpio()
553 (strstr(jack->gpio.device_name, "Headphone") || in open_and_monitor_gpio()
554 strstr(jack->gpio.device_name, "Headset"))) in open_and_monitor_gpio()
555 jack->mixer_output = cras_alsa_mixer_get_output_matching_name( in open_and_monitor_gpio()
558 strstr(jack->gpio.device_name, "HDMI")) in open_and_monitor_gpio()
559 jack->mixer_output = cras_alsa_mixer_get_output_matching_name( in open_and_monitor_gpio()
562 if (jack->ucm_device && direction == CRAS_STREAM_INPUT) { in open_and_monitor_gpio()
564 control_name = ucm_get_cap_control(jack->jack_list->ucm, in open_and_monitor_gpio()
565 jack->ucm_device); in open_and_monitor_gpio()
567 jack->mixer_input = in open_and_monitor_gpio()
572 return cras_complete_gpio_jack(data, jack, switch_event); in open_and_monitor_gpio()
579 struct cras_alsa_jack *jack; in open_and_monitor_gpio_with_section() local
586 switch_event, &jack); in open_and_monitor_gpio_with_section()
590 jack->ucm_device = strdup(section->name); in open_and_monitor_gpio_with_section()
591 if (!jack->ucm_device) { in open_and_monitor_gpio_with_section()
592 cras_free_jack(jack, 0); in open_and_monitor_gpio_with_section()
597 jack->mixer_output = cras_alsa_mixer_get_control_for_section( in open_and_monitor_gpio_with_section()
600 jack->mixer_input = cras_alsa_mixer_get_control_for_section( in open_and_monitor_gpio_with_section()
603 return cras_complete_gpio_jack(data, jack, switch_event); in open_and_monitor_gpio_with_section()
807 struct cras_alsa_jack *jack; in hctl_jack_cb() local
809 jack = snd_hctl_elem_get_callback_private(elem); in hctl_jack_cb()
810 if (jack == NULL) { in hctl_jack_cb()
822 jack_state_change_cb(jack, 1); in hctl_jack_cb()
876 struct cras_alsa_jack *jack; in find_jack_controls() local
918 jack = cras_alloc_jack(0); in find_jack_controls()
919 if (jack == NULL) in find_jack_controls()
921 jack->elem = elem; in find_jack_controls()
922 jack->jack_list = jack_list; in find_jack_controls()
923 DL_APPEND(jack_list->jacks, jack); in find_jack_controls()
926 snd_hctl_elem_set_callback_private(elem, jack); in find_jack_controls()
929 jack->mixer_output = in find_jack_controls()
933 jack->ucm_device = ucm_get_dev_for_jack( in find_jack_controls()
936 if (jack->ucm_device && in find_jack_controls()
939 control_name = ucm_get_cap_control(jack->jack_list->ucm, in find_jack_controls()
940 jack->ucm_device); in find_jack_controls()
942 jack->mixer_input = in find_jack_controls()
947 if (jack->ucm_device) { in find_jack_controls()
948 jack->override_type_name = ucm_get_override_type_name( in find_jack_controls()
949 jack->jack_list->ucm, jack->ucm_device); in find_jack_controls()
954 DL_FOREACH (jack_list->jacks, jack) { in find_jack_controls()
955 if (jack->is_gpio || jack->eld_control) in find_jack_controls()
957 name = snd_hctl_elem_get_name(jack->elem); in find_jack_controls()
961 jack->eld_control = find_eld_control_by_dev_index( in find_jack_controls()
990 struct cras_alsa_jack *jack; in find_hctl_jack_for_section() local
1009 jack = cras_alloc_jack(0); in find_hctl_jack_for_section()
1010 if (jack == NULL) in find_hctl_jack_for_section()
1012 jack->elem = elem; in find_hctl_jack_for_section()
1013 jack->jack_list = jack_list; in find_hctl_jack_for_section()
1015 jack->ucm_device = strdup(section->name); in find_hctl_jack_for_section()
1016 if (!jack->ucm_device) { in find_hctl_jack_for_section()
1017 free(jack); in find_hctl_jack_for_section()
1021 jack->mixer_output = cras_alsa_mixer_get_control_for_section( in find_hctl_jack_for_section()
1024 jack->mixer_input = cras_alsa_mixer_get_control_for_section( in find_hctl_jack_for_section()
1028 snd_hctl_elem_set_callback_private(elem, jack); in find_hctl_jack_for_section()
1029 DL_APPEND(jack_list->jacks, jack); in find_hctl_jack_for_section()
1031 *result_jack = jack; in find_hctl_jack_for_section()
1033 if (!strcmp(jack->ucm_device, "HDMI") || in find_hctl_jack_for_section()
1034 !strcmp(jack->ucm_device, "DP")) in find_hctl_jack_for_section()
1038 jack->eld_control = find_eld_control_by_dev_index( in find_hctl_jack_for_section()
1113 struct cras_alsa_jack *jack; in cras_alsa_jack_list_destroy() local
1117 DL_FOREACH (jack_list->jacks, jack) { in cras_alsa_jack_list_destroy()
1118 DL_DELETE(jack_list->jacks, jack); in cras_alsa_jack_list_destroy()
1119 cras_free_jack(jack, 1); in cras_alsa_jack_list_destroy()
1126 struct cras_alsa_jack *jack; in cras_alsa_jack_list_has_hctl_jacks() local
1130 DL_FOREACH (jack_list->jacks, jack) { in cras_alsa_jack_list_has_hctl_jacks()
1131 if (!jack->is_gpio) in cras_alsa_jack_list_has_hctl_jacks()
1138 cras_alsa_jack_get_mixer_output(const struct cras_alsa_jack *jack) in cras_alsa_jack_get_mixer_output() argument
1140 if (jack == NULL) in cras_alsa_jack_get_mixer_output()
1142 return jack->mixer_output; in cras_alsa_jack_get_mixer_output()
1146 cras_alsa_jack_get_mixer_input(const struct cras_alsa_jack *jack) in cras_alsa_jack_get_mixer_input() argument
1148 return jack ? jack->mixer_input : NULL; in cras_alsa_jack_get_mixer_input()
1153 struct cras_alsa_jack *jack; in cras_alsa_jack_list_report() local
1158 DL_FOREACH (jack_list->jacks, jack) in cras_alsa_jack_list_report()
1159 if (jack->is_gpio) in cras_alsa_jack_list_report()
1160 gpio_switch_initial_state(jack); in cras_alsa_jack_list_report()
1162 hctl_jack_cb(jack->elem, 0); in cras_alsa_jack_list_report()
1165 const char *cras_alsa_jack_get_name(const struct cras_alsa_jack *jack) in cras_alsa_jack_get_name() argument
1167 if (jack == NULL) in cras_alsa_jack_get_name()
1169 if (jack->is_gpio) in cras_alsa_jack_get_name()
1170 return jack->gpio.device_name; in cras_alsa_jack_get_name()
1171 return snd_hctl_elem_get_name(jack->elem); in cras_alsa_jack_get_name()
1174 const char *cras_alsa_jack_get_ucm_device(const struct cras_alsa_jack *jack) in cras_alsa_jack_get_ucm_device() argument
1176 return jack->ucm_device; in cras_alsa_jack_get_ucm_device()
1179 void cras_alsa_jack_update_monitor_name(const struct cras_alsa_jack *jack, in cras_alsa_jack_update_monitor_name() argument
1188 if (!jack->eld_control) { in cras_alsa_jack_update_monitor_name()
1189 if (jack->edid_file) in cras_alsa_jack_update_monitor_name()
1190 get_jack_edid_monitor_name(jack, name_buf, buf_size); in cras_alsa_jack_update_monitor_name()
1195 if (snd_hctl_elem_info(jack->eld_control, elem_info) < 0) in cras_alsa_jack_update_monitor_name()
1203 if (snd_hctl_elem_read(jack->eld_control, elem_value) < 0) in cras_alsa_jack_update_monitor_name()
1223 buf = cras_alsa_jack_get_name(jack); in cras_alsa_jack_update_monitor_name()
1229 void cras_alsa_jack_update_node_type(const struct cras_alsa_jack *jack, in cras_alsa_jack_update_node_type() argument
1232 if (!jack->override_type_name) in cras_alsa_jack_update_node_type()
1234 if (!strcmp(jack->override_type_name, "Internal Speaker")) in cras_alsa_jack_update_node_type()
1239 void cras_alsa_jack_enable_ucm(const struct cras_alsa_jack *jack, int enable) in cras_alsa_jack_enable_ucm() argument
1241 if (jack && jack->ucm_device) in cras_alsa_jack_enable_ucm()
1242 ucm_set_enabled(jack->jack_list->ucm, jack->ucm_device, enable); in cras_alsa_jack_enable_ucm()