Lines Matching +full:codec +full:- +full:1

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
10 * 1. Redistributions of source code must retain the above copyright
39 * HDA Codec defines
62 (1 << HDA_PARAM_SUPP_STREAM_FORMATS_PCM_SHIFT)
89 (1 << HDA_PARAM_AUDIO_WIDGET_CAP_CONN_LIST_SHIFT)
91 (1 << HDA_PARAM_AUDIO_WIDGET_CAP_FORMAT_OVR_SHIFT)
93 (1 << HDA_PARAM_AUDIO_WIDGET_CAP_AMP_OVR_SHIFT)
95 (1 << HDA_PARAM_AUDIO_WIDGET_CAP_OUT_AMP_SHIFT)
97 (1 << HDA_PARAM_AUDIO_WIDGET_CAP_IN_AMP_SHIFT)
99 (1 << HDA_PARAM_AUDIO_WIDGET_CAP_STEREO_SHIFT)
102 (1 << HDA_PARAM_PIN_CAP_OUTPUT_CAP_SHIFT)
104 (1 << HDA_PARAM_PIN_CAP_INPUT_CAP_SHIFT)
106 (1 << HDA_PARAM_PIN_CAP_PRESENCE_DETECT_CAP_SHIFT)
109 (1 << HDA_PARAM_OUTPUT_AMP_CAP_MUTE_CAP_SHIFT)
120 #define HDA_CODEC_PIN_SENSE_PRESENCE_PLUGGED (1 << 31)
122 (1 << HDA_CMD_GET_PIN_WIDGET_CTRL_OUT_ENABLE_SHIFT)
124 (1 << HDA_CMD_GET_PIN_WIDGET_CTRL_IN_ENABLE_SHIFT)
166 * HDA Codec data structures
203 * HDA Codec module function declarations
227 * HDA Codec global data
234 /* 1 Subnode, StartNid = 1 */ \
240 /* B8 - B32, 8.0 - 192.0kHz */ \
276 /* B16, 16.0 - 192.0kHz */ \
309 /* B16, 16.0 - 192.0kHz */ \
387 * HDA Codec module function definitions
399 return (-1); in hda_codec_init()
401 sc = calloc(1, sizeof(*sc)); in hda_codec_init()
403 return (-1); in hda_codec_init()
406 sc->get_parameters = hda_codec_duplex_parameters; in hda_codec_init()
409 sc->get_parameters = hda_codec_output_parameters; in hda_codec_init()
411 sc->get_parameters = hda_codec_input_parameters; in hda_codec_init()
413 sc->subsystem_id = HDA_CODEC_SUBSYSTEM_ID; in hda_codec_init()
414 sc->no_nodes = HDA_CODEC_NODES_COUNT; in hda_codec_init()
415 sc->conn_list = hda_codec_conn_list; in hda_codec_init()
416 sc->conf_default = hda_codec_conf_default; in hda_codec_init()
417 sc->pin_ctrl_default = hda_codec_pin_ctrl_default; in hda_codec_init()
418 sc->verb_handlers = hda_codec_verb_handlers; in hda_codec_init()
419 DPRINTF("HDA Codec nodes: %d", sc->no_nodes); in hda_codec_init()
425 st = &sc->streams[HDA_CODEC_STREAM_OUTPUT]; in hda_codec_init()
427 err = hda_audio_ctxt_init(&st->actx, "hda-audio-output", in hda_codec_init()
432 st->aud = audio_init(play, 1); in hda_codec_init()
433 if (!st->aud) { in hda_codec_init()
435 return (-1); in hda_codec_init()
443 st = &sc->streams[HDA_CODEC_STREAM_INPUT]; in hda_codec_init()
445 err = hda_audio_ctxt_init(&st->actx, "hda-audio-input", in hda_codec_init()
450 st->aud = audio_init(rec, 0); in hda_codec_init()
451 if (!st->aud) { in hda_codec_init()
453 return (-1); in hda_codec_init()
457 sc->hci = hci; in hda_codec_init()
458 hci->priv = sc; in hda_codec_init()
473 hops = hci->hops; in hda_codec_reset()
476 sc = (struct hda_codec_softc *)hci->priv; in hda_codec_reset()
480 st = &sc->streams[i]; in hda_codec_reset()
481 st->left_gain = HDA_CODEC_AMP_NUMSTEPS; in hda_codec_reset()
482 st->right_gain = HDA_CODEC_AMP_NUMSTEPS; in hda_codec_reset()
483 st->left_mute = HDA_CODEC_SET_AMP_GAIN_MUTE_MUTE; in hda_codec_reset()
484 st->right_mute = HDA_CODEC_SET_AMP_GAIN_MUTE_MUTE; in hda_codec_reset()
487 DPRINTF("cad: 0x%x", hci->cad); in hda_codec_reset()
489 if (!hops->signal) { in hda_codec_reset()
492 return (-1); in hda_codec_reset()
495 return (hops->signal(hci)); in hda_codec_reset()
526 hops = hci->hops; in hda_codec_command()
529 sc = (struct hda_codec_softc *)hci->priv; in hda_codec_command()
532 if (cad != hci->cad || nid >= sc->no_nodes) { in hda_codec_command()
534 return (-1); in hda_codec_command()
537 if (!hops->response) { in hda_codec_command()
540 return (-1); in hda_codec_command()
546 res = sc->get_parameters[nid][payload]; in hda_codec_command()
549 res = sc->conn_list[nid][0]; in hda_codec_command()
552 res = sc->pin_ctrl_default[nid]; in hda_codec_command()
558 res = sc->conf_default[nid]; in hda_codec_command()
561 res = sc->subsystem_id; in hda_codec_command()
564 assert(sc->verb_handlers); in hda_codec_command()
565 if (sc->verb_handlers[nid]) in hda_codec_command()
566 res = sc->verb_handlers[nid](sc, verb, payload); in hda_codec_command()
575 return (hops->response(hci, res, HDA_CODEC_RESPONSE_EX_SOL)); in hda_codec_command()
591 sc = (struct hda_codec_softc *)hci->priv; in hda_codec_notify()
595 st = &sc->streams[i]; in hda_codec_notify()
597 DPRINTF("run: %d, stream: 0x%x, st->stream: 0x%x dir: %d", in hda_codec_notify()
598 run, stream, st->stream, dir); in hda_codec_notify()
600 if (stream != st->stream) { in hda_codec_notify()
605 actx = &st->actx; in hda_codec_notify()
623 params->rate = (fmt & HDA_CODEC_FMT_BASE_MASK) ? 44100 : 48000; in hda_codec_parse_format()
627 params->rate *= 2; in hda_codec_parse_format()
630 params->rate *= 3; in hda_codec_parse_format()
633 params->rate *= 4; in hda_codec_parse_format()
638 params->rate /= (div + 1); in hda_codec_parse_format()
643 params->format = AFMT_U8; in hda_codec_parse_format()
646 params->format = AFMT_S16_LE; in hda_codec_parse_format()
649 params->format = AFMT_S24_LE; in hda_codec_parse_format()
652 params->format = AFMT_S32_LE; in hda_codec_parse_format()
657 return (-1); in hda_codec_parse_format()
661 params->channels = (fmt & HDA_CODEC_FMT_CHAN_MASK) + 1; in hda_codec_parse_format()
670 struct hda_codec_stream *st = &sc->streams[HDA_CODEC_STREAM_OUTPUT]; in hda_codec_audio_output_nid()
688 hci = sc->hci; in hda_codec_audio_output_do_transfer()
691 hops = hci->hops; in hda_codec_audio_output_do_transfer()
694 st = &sc->streams[HDA_CODEC_STREAM_OUTPUT]; in hda_codec_audio_output_do_transfer()
695 aud = st->aud; in hda_codec_audio_output_do_transfer()
697 err = hops->transfer(hci, st->stream, 1, st->buf, sizeof(st->buf)); in hda_codec_audio_output_do_transfer()
701 err = audio_playback(aud, st->buf, sizeof(st->buf)); in hda_codec_audio_output_do_transfer()
714 st = &sc->streams[HDA_CODEC_STREAM_OUTPUT]; in hda_codec_audio_output_do_setup()
715 aud = st->aud; in hda_codec_audio_output_do_setup()
717 err = hda_codec_parse_format(st->fmt, &params); in hda_codec_audio_output_do_setup()
719 return (-1); in hda_codec_audio_output_do_setup()
731 struct hda_codec_stream *st = &sc->streams[HDA_CODEC_STREAM_INPUT]; in hda_codec_audio_input_nid()
749 hci = sc->hci; in hda_codec_audio_input_do_transfer()
752 hops = hci->hops; in hda_codec_audio_input_do_transfer()
755 st = &sc->streams[HDA_CODEC_STREAM_INPUT]; in hda_codec_audio_input_do_transfer()
756 aud = st->aud; in hda_codec_audio_input_do_transfer()
758 err = audio_record(aud, st->buf, sizeof(st->buf)); in hda_codec_audio_input_do_transfer()
761 hops->transfer(hci, st->stream, 0, st->buf, sizeof(st->buf)); in hda_codec_audio_input_do_transfer()
773 st = &sc->streams[HDA_CODEC_STREAM_INPUT]; in hda_codec_audio_input_do_setup()
774 aud = st->aud; in hda_codec_audio_input_do_setup()
776 err = hda_codec_parse_format(st->fmt, &params); in hda_codec_audio_input_do_setup()
778 return (-1); in hda_codec_audio_input_do_setup()
794 DPRINTF("%s verb: 0x%x, payload, 0x%x", st->actx.name, verb, payload); in hda_codec_audio_inout_nid()
798 res = st->fmt; in hda_codec_audio_inout_nid()
801 st->fmt = payload; in hda_codec_audio_inout_nid()
805 res = st->left_gain | st->left_mute; in hda_codec_audio_inout_nid()
808 res = st->right_gain | st->right_mute; in hda_codec_audio_inout_nid()
817 st->left_mute = mute; in hda_codec_audio_inout_nid()
818 st->left_gain = gain; in hda_codec_audio_inout_nid()
824 st->right_mute = mute; in hda_codec_audio_inout_nid()
825 st->right_gain = gain; in hda_codec_audio_inout_nid()
831 res = (st->stream << 4) | st->channel; in hda_codec_audio_inout_nid()
834 st->channel = payload & 0x0f; in hda_codec_audio_inout_nid()
835 st->stream = (payload >> 4) & 0x0f; in hda_codec_audio_inout_nid()
836 DPRINTF("st->channel: 0x%x st->stream: 0x%x", in hda_codec_audio_inout_nid()
837 st->channel, st->stream); in hda_codec_audio_inout_nid()
838 if (!st->stream) in hda_codec_audio_inout_nid()
839 hda_audio_ctxt_stop(&st->actx); in hda_codec_audio_inout_nid()
867 DPRINTF("Start Thread: %s", actx->name); in hda_audio_ctxt_thr()
869 pthread_mutex_lock(&actx->mtx); in hda_audio_ctxt_thr()
870 while (1) { in hda_audio_ctxt_thr()
871 while (!actx->run) in hda_audio_ctxt_thr()
872 pthread_cond_wait(&actx->cond, &actx->mtx); in hda_audio_ctxt_thr()
874 actx->do_transfer(actx->priv); in hda_audio_ctxt_thr()
876 pthread_mutex_unlock(&actx->mtx); in hda_audio_ctxt_thr()
896 actx->run = 0; in hda_audio_ctxt_init()
897 actx->do_transfer = do_transfer; in hda_audio_ctxt_init()
898 actx->do_setup = do_setup; in hda_audio_ctxt_init()
899 actx->priv = priv; in hda_audio_ctxt_init()
900 if (strlen(tname) < sizeof(actx->name)) in hda_audio_ctxt_init()
901 memcpy(actx->name, tname, strlen(tname) + 1); in hda_audio_ctxt_init()
903 strcpy(actx->name, "unknown"); in hda_audio_ctxt_init()
905 err = pthread_mutex_init(&actx->mtx, NULL); in hda_audio_ctxt_init()
908 err = pthread_cond_init(&actx->cond, NULL); in hda_audio_ctxt_init()
911 err = pthread_create(&actx->tid, NULL, hda_audio_ctxt_thr, actx); in hda_audio_ctxt_init()
914 pthread_set_name_np(actx->tid, tname); in hda_audio_ctxt_init()
916 actx->started = 1; in hda_audio_ctxt_init()
927 assert(actx->started); in hda_audio_ctxt_start()
930 if (actx->run) in hda_audio_ctxt_start()
931 return (-1); in hda_audio_ctxt_start()
933 pthread_mutex_lock(&actx->mtx); in hda_audio_ctxt_start()
934 err = (* actx->do_setup)(actx->priv); in hda_audio_ctxt_start()
936 actx->run = 1; in hda_audio_ctxt_start()
937 pthread_cond_signal(&actx->cond); in hda_audio_ctxt_start()
939 pthread_mutex_unlock(&actx->mtx); in hda_audio_ctxt_start()
947 actx->run = 0; in hda_audio_ctxt_stop()