Lines Matching refs:jack
180 struct cras_alsa_jack *jack = calloc(1, sizeof(*jack)); in cras_alloc_jack() local
181 if (jack == NULL) in cras_alloc_jack()
183 jack->is_gpio = is_gpio; in cras_alloc_jack()
184 return jack; in cras_alloc_jack()
187 static void cras_free_jack(struct cras_alsa_jack *jack, in cras_free_jack() argument
190 if (!jack) in cras_free_jack()
193 free(jack->ucm_device); in cras_free_jack()
194 free((void *)jack->edid_file); in cras_free_jack()
195 if (jack->display_info_timer) in cras_free_jack()
197 jack->display_info_timer); in cras_free_jack()
199 if (jack->is_gpio) { in cras_free_jack()
200 free(jack->gpio.device_name); in cras_free_jack()
201 if (jack->gpio.fd >= 0) { in cras_free_jack()
203 cras_system_rm_select_fd(jack->gpio.fd); in cras_free_jack()
204 close(jack->gpio.fd); in cras_free_jack()
212 if (!jack->is_gpio && jack->elem) in cras_free_jack()
213 snd_hctl_elem_set_callback(jack->elem, NULL); in cras_free_jack()
215 free((void *)jack->override_type_name); in cras_free_jack()
216 free((void *)jack->dsp_name); in cras_free_jack()
217 free(jack); in cras_free_jack()
221 static int get_jack_current_state(struct cras_alsa_jack *jack) in get_jack_current_state() argument
225 if (jack->is_gpio) in get_jack_current_state()
226 return jack->gpio.current_state; in get_jack_current_state()
229 snd_hctl_elem_read(jack->elem, elem_value); in get_jack_current_state()
234 static int read_jack_edid(const struct cras_alsa_jack *jack, uint8_t *edid) in read_jack_edid() argument
238 fd = open(jack->edid_file, O_RDONLY); in read_jack_edid()
250 static int check_jack_edid(struct cras_alsa_jack *jack) in check_jack_edid() argument
254 if (read_jack_edid(jack, edid)) in check_jack_edid()
261 jack->gpio.current_state = 0; in check_jack_edid()
265 static int get_jack_edid_monitor_name(const struct cras_alsa_jack *jack, in get_jack_edid_monitor_name() argument
271 if (read_jack_edid(jack, edid)) in get_jack_edid_monitor_name()
280 static int check_jack_eld(struct cras_alsa_jack *jack) in check_jack_eld() argument
288 if (snd_hctl_elem_info(jack->eld_control, elem_info) != 0) in check_jack_eld()
305 static inline void jack_state_change_cb(struct cras_alsa_jack *jack, int retry) in jack_state_change_cb() argument
309 if (jack->display_info_timer) { in jack_state_change_cb()
310 cras_tm_cancel_timer(tm, jack->display_info_timer); in jack_state_change_cb()
311 jack->display_info_timer = NULL; in jack_state_change_cb()
314 jack->display_info_retries = in jack_state_change_cb()
315 jack->is_gpio ? DISPLAY_INFO_GPIO_MAX_RETRIES in jack_state_change_cb()
319 if (!get_jack_current_state(jack)) in jack_state_change_cb()
326 if (jack->edid_file == NULL && jack->eld_control == NULL) in jack_state_change_cb()
328 if (jack->edid_file && (check_jack_edid(jack) == 0)) in jack_state_change_cb()
330 if (jack->eld_control && (check_jack_eld(jack) == 0)) in jack_state_change_cb()
333 if (--jack->display_info_retries == 0) { in jack_state_change_cb()
334 if (jack->is_gpio) in jack_state_change_cb()
335 jack->gpio.current_state = 0; in jack_state_change_cb()
336 if (jack->edid_file) in jack_state_change_cb()
338 jack->edid_file); in jack_state_change_cb()
342 jack->display_info_timer = cras_tm_create_timer(tm, in jack_state_change_cb()
344 display_info_delay_cb, jack); in jack_state_change_cb()
348 jack->jack_list->change_callback(jack, in jack_state_change_cb()
349 get_jack_current_state(jack), in jack_state_change_cb()
350 jack->jack_list->callback_data); in jack_state_change_cb()
357 static void gpio_switch_initial_state(struct cras_alsa_jack *jack) in gpio_switch_initial_state() argument
360 int r = sys_input_get_switch_state(jack->gpio.fd, in gpio_switch_initial_state()
361 jack->gpio.switch_event, &v); in gpio_switch_initial_state()
362 jack->gpio.current_state = r == 0 ? v : 0; in gpio_switch_initial_state()
363 jack_state_change_cb(jack, 1); in gpio_switch_initial_state()
377 struct cras_alsa_jack *jack = (struct cras_alsa_jack *)arg; in display_info_delay_cb() local
379 jack->display_info_timer = NULL; in display_info_delay_cb()
380 jack_state_change_cb(jack, 0); in display_info_delay_cb()
391 struct cras_alsa_jack *jack = arg; in gpio_switch_callback() local
396 r = gpio_switch_read(jack->gpio.fd, ev, in gpio_switch_callback()
402 if (is_audio_switch_event(&ev[i], jack->gpio.switch_event)) { in gpio_switch_callback()
403 jack->gpio.current_state = ev[i].value; in gpio_switch_callback()
405 jack_state_change_cb(jack, 1); in gpio_switch_callback()
414 static unsigned int gpio_jack_match_device(const struct cras_alsa_jack *jack, in gpio_jack_match_device() argument
425 if (!jack_list->ucm || !jack->ucm_device) in gpio_jack_match_device()
430 jack_list->ucm, jack->ucm_device, direction); in gpio_jack_match_device()
458 struct cras_alsa_jack *jack; in create_jack_for_gpio() local
467 jack = cras_alloc_jack(1); in create_jack_for_gpio()
468 if (jack == NULL) in create_jack_for_gpio()
471 jack->gpio.fd = gpio_switch_open(pathname); in create_jack_for_gpio()
472 if (jack->gpio.fd == -1) { in create_jack_for_gpio()
477 jack->gpio.switch_event = switch_event; in create_jack_for_gpio()
478 jack->jack_list = jack_list; in create_jack_for_gpio()
479 jack->gpio.device_name = strdup(dev_name); in create_jack_for_gpio()
480 if (!jack->gpio.device_name) { in create_jack_for_gpio()
485 if (!strstr(jack->gpio.device_name, card_name) || in create_jack_for_gpio()
486 (gpio_switch_eviocgbit(jack->gpio.fd, bits, sizeof(bits)) < 0) || in create_jack_for_gpio()
492 *out_jack = jack; in create_jack_for_gpio()
497 cras_free_jack(jack, 0); in create_jack_for_gpio()
505 struct cras_alsa_jack *jack, in cras_complete_gpio_jack() argument
512 if (jack->ucm_device) { in cras_complete_gpio_jack()
513 jack->edid_file = ucm_get_edid_file_for_dev(jack_list->ucm, in cras_complete_gpio_jack()
514 jack->ucm_device); in cras_complete_gpio_jack()
515 jack->dsp_name = ucm_get_dsp_name( in cras_complete_gpio_jack()
516 jack->jack_list->ucm, jack->ucm_device, direction); in cras_complete_gpio_jack()
519 r = sys_input_get_switch_state(jack->gpio.fd, switch_event, in cras_complete_gpio_jack()
520 &jack->gpio.current_state); in cras_complete_gpio_jack()
522 cras_free_jack(jack, 0); in cras_complete_gpio_jack()
525 r = cras_system_add_select_fd(jack->gpio.fd, in cras_complete_gpio_jack()
526 gpio_switch_callback, jack); in cras_complete_gpio_jack()
529 cras_free_jack(jack, 0); in cras_complete_gpio_jack()
533 DL_APPEND(jack_list->jacks, jack); in cras_complete_gpio_jack()
535 data->result_jack = jack; in cras_complete_gpio_jack()
554 struct cras_alsa_jack *jack; in open_and_monitor_gpio() local
561 switch_event, &jack); in open_and_monitor_gpio()
566 jack->ucm_device = in open_and_monitor_gpio()
568 jack->gpio.device_name, in open_and_monitor_gpio()
571 if (!gpio_jack_match_device(jack, jack_list, card_name, direction)) { in open_and_monitor_gpio()
572 cras_free_jack(jack, 0); in open_and_monitor_gpio()
577 (strstr(jack->gpio.device_name, "Headphone") || in open_and_monitor_gpio()
578 strstr(jack->gpio.device_name, "Headset"))) in open_and_monitor_gpio()
579 jack->mixer_output = cras_alsa_mixer_get_output_matching_name( in open_and_monitor_gpio()
583 strstr(jack->gpio.device_name, "HDMI")) in open_and_monitor_gpio()
584 jack->mixer_output = cras_alsa_mixer_get_output_matching_name( in open_and_monitor_gpio()
588 if (jack->ucm_device && direction == CRAS_STREAM_INPUT) { in open_and_monitor_gpio()
590 control_name = ucm_get_cap_control(jack->jack_list->ucm, in open_and_monitor_gpio()
591 jack->ucm_device); in open_and_monitor_gpio()
593 jack->mixer_input = in open_and_monitor_gpio()
599 return cras_complete_gpio_jack(data, jack, switch_event); in open_and_monitor_gpio()
607 struct cras_alsa_jack *jack; in open_and_monitor_gpio_with_section() local
614 switch_event, &jack); in open_and_monitor_gpio_with_section()
618 jack->ucm_device = strdup(section->name); in open_and_monitor_gpio_with_section()
619 if (!jack->ucm_device) { in open_and_monitor_gpio_with_section()
620 cras_free_jack(jack, 0); in open_and_monitor_gpio_with_section()
625 jack->mixer_output = cras_alsa_mixer_get_control_for_section( in open_and_monitor_gpio_with_section()
628 jack->mixer_input = cras_alsa_mixer_get_control_for_section( in open_and_monitor_gpio_with_section()
631 return cras_complete_gpio_jack(data, jack, switch_event); in open_and_monitor_gpio_with_section()
808 struct cras_alsa_jack *jack; in hctl_jack_cb() local
810 jack = snd_hctl_elem_get_callback_private(elem); in hctl_jack_cb()
811 if (jack == NULL) { in hctl_jack_cb()
825 jack_state_change_cb(jack, 1); in hctl_jack_cb()
886 struct cras_alsa_jack *jack; in find_jack_controls() local
928 jack = cras_alloc_jack(0); in find_jack_controls()
929 if (jack == NULL) in find_jack_controls()
931 jack->elem = elem; in find_jack_controls()
932 jack->jack_list = jack_list; in find_jack_controls()
933 DL_APPEND(jack_list->jacks, jack); in find_jack_controls()
936 snd_hctl_elem_set_callback_private(elem, jack); in find_jack_controls()
939 jack->mixer_output = in find_jack_controls()
944 jack->ucm_device = in find_jack_controls()
948 if (jack->ucm_device && jack_list->direction == CRAS_STREAM_INPUT) { in find_jack_controls()
950 control_name = ucm_get_cap_control(jack->jack_list->ucm, in find_jack_controls()
951 jack->ucm_device); in find_jack_controls()
953 jack->mixer_input = in find_jack_controls()
959 if (jack->ucm_device) { in find_jack_controls()
960 jack->dsp_name = ucm_get_dsp_name( in find_jack_controls()
961 jack->jack_list->ucm, jack->ucm_device, in find_jack_controls()
963 jack->override_type_name = ucm_get_override_type_name( in find_jack_controls()
964 jack->jack_list->ucm, jack->ucm_device); in find_jack_controls()
969 DL_FOREACH(jack_list->jacks, jack) { in find_jack_controls()
970 if (jack->is_gpio || jack->eld_control) in find_jack_controls()
972 name = snd_hctl_elem_get_name(jack->elem); in find_jack_controls()
983 jack->eld_control = elem; in find_jack_controls()
1015 struct cras_alsa_jack *jack; in find_hctl_jack_for_section() local
1034 jack = cras_alloc_jack(0); in find_hctl_jack_for_section()
1035 if (jack == NULL) in find_hctl_jack_for_section()
1037 jack->elem = elem; in find_hctl_jack_for_section()
1038 jack->jack_list = jack_list; in find_hctl_jack_for_section()
1040 jack->ucm_device = strdup(section->name); in find_hctl_jack_for_section()
1041 if (!jack->ucm_device) { in find_hctl_jack_for_section()
1042 free(jack); in find_hctl_jack_for_section()
1046 jack->mixer_output = cras_alsa_mixer_get_control_for_section( in find_hctl_jack_for_section()
1049 jack->mixer_input = cras_alsa_mixer_get_control_for_section( in find_hctl_jack_for_section()
1052 jack->dsp_name = ucm_get_dsp_name( in find_hctl_jack_for_section()
1053 jack->jack_list->ucm, jack->ucm_device, in find_hctl_jack_for_section()
1057 snd_hctl_elem_set_callback_private(elem, jack); in find_hctl_jack_for_section()
1058 DL_APPEND(jack_list->jacks, jack); in find_hctl_jack_for_section()
1060 *result_jack = jack; in find_hctl_jack_for_section()
1062 if (!strcmp(jack->ucm_device, "HDMI") || in find_hctl_jack_for_section()
1063 !strcmp(jack->ucm_device, "DP")) in find_hctl_jack_for_section()
1070 jack->eld_control = elem; in find_hctl_jack_for_section()
1150 struct cras_alsa_jack *jack; in cras_alsa_jack_list_destroy() local
1154 DL_FOREACH(jack_list->jacks, jack) { in cras_alsa_jack_list_destroy()
1155 DL_DELETE(jack_list->jacks, jack); in cras_alsa_jack_list_destroy()
1156 cras_free_jack(jack, 1); in cras_alsa_jack_list_destroy()
1163 struct cras_alsa_jack *jack; in cras_alsa_jack_list_has_hctl_jacks() local
1167 DL_FOREACH(jack_list->jacks, jack) { in cras_alsa_jack_list_has_hctl_jacks()
1168 if (!jack->is_gpio) in cras_alsa_jack_list_has_hctl_jacks()
1175 const struct cras_alsa_jack *jack) in cras_alsa_jack_get_mixer_output() argument
1177 if (jack == NULL) in cras_alsa_jack_get_mixer_output()
1179 return jack->mixer_output; in cras_alsa_jack_get_mixer_output()
1183 const struct cras_alsa_jack *jack) in cras_alsa_jack_get_mixer_input() argument
1185 return jack ? jack->mixer_input : NULL; in cras_alsa_jack_get_mixer_input()
1190 struct cras_alsa_jack *jack; in cras_alsa_jack_list_report() local
1195 DL_FOREACH(jack_list->jacks, jack) in cras_alsa_jack_list_report()
1196 if (jack->is_gpio) in cras_alsa_jack_list_report()
1197 gpio_switch_initial_state(jack); in cras_alsa_jack_list_report()
1199 hctl_jack_cb(jack->elem, 0); in cras_alsa_jack_list_report()
1202 const char *cras_alsa_jack_get_name(const struct cras_alsa_jack *jack) in cras_alsa_jack_get_name() argument
1204 if (jack == NULL) in cras_alsa_jack_get_name()
1206 if (jack->is_gpio) in cras_alsa_jack_get_name()
1207 return jack->gpio.device_name; in cras_alsa_jack_get_name()
1208 return snd_hctl_elem_get_name(jack->elem); in cras_alsa_jack_get_name()
1211 const char *cras_alsa_jack_get_ucm_device(const struct cras_alsa_jack *jack) in cras_alsa_jack_get_ucm_device() argument
1213 return jack->ucm_device; in cras_alsa_jack_get_ucm_device()
1216 void cras_alsa_jack_update_monitor_name(const struct cras_alsa_jack *jack, in cras_alsa_jack_update_monitor_name() argument
1226 if (!jack->eld_control) { in cras_alsa_jack_update_monitor_name()
1227 if (jack->edid_file) in cras_alsa_jack_update_monitor_name()
1228 get_jack_edid_monitor_name(jack, name_buf, buf_size); in cras_alsa_jack_update_monitor_name()
1233 if (snd_hctl_elem_info(jack->eld_control, elem_info) < 0) in cras_alsa_jack_update_monitor_name()
1241 if (snd_hctl_elem_read(jack->eld_control, elem_value) < 0) in cras_alsa_jack_update_monitor_name()
1261 buf = cras_alsa_jack_get_name(jack); in cras_alsa_jack_update_monitor_name()
1267 void cras_alsa_jack_update_node_type(const struct cras_alsa_jack *jack, in cras_alsa_jack_update_node_type() argument
1270 if (!jack->override_type_name) in cras_alsa_jack_update_node_type()
1272 if (!strcmp(jack->override_type_name, "Internal Speaker")) in cras_alsa_jack_update_node_type()
1277 const char *cras_alsa_jack_get_dsp_name(const struct cras_alsa_jack *jack) in cras_alsa_jack_get_dsp_name() argument
1279 if (jack == NULL) in cras_alsa_jack_get_dsp_name()
1281 return jack->dsp_name; in cras_alsa_jack_get_dsp_name()
1284 void cras_alsa_jack_enable_ucm(const struct cras_alsa_jack *jack, int enable) in cras_alsa_jack_enable_ucm() argument
1286 if (jack && jack->ucm_device) in cras_alsa_jack_enable_ucm()
1287 ucm_set_enabled(jack->jack_list->ucm, jack->ucm_device, enable); in cras_alsa_jack_enable_ucm()