Lines Matching full:this

8  * This code is derived from software contributed to The NetBSD Foundation
15 * notice, this list of conditions and the following disclaimer.
17 * notice, this list of conditions and the following disclaimer in the
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
642 * this function is called if the device could not be supported,
643 * in which case az->detached == 1. check if this function has
1444 azalia_resume_codec(codec_t *this)
1450 err = azalia_comresp(this, this->audiofunc, CORB_SET_POWER_STATE,
1458 if (this->qrks & AZ_QRK_DOLBY_ATMOS)
1459 azalia_codec_init_dolby_atmos(this);
1461 FOR_EACH_WIDGET(this, i) {
1462 w = &this->w[i];
1464 azalia_comresp(this, w->nid, CORB_SET_POWER_STATE,
1469 azalia_widget_init_pin(w, this);
1470 if (this->qrks & AZ_QRK_WID_MASK)
1471 azalia_codec_widget_quirks(this, w->nid);
1474 if (this->qrks & AZ_QRK_GPIO_MASK) {
1475 err = azalia_codec_gpio_quirks(this);
1493 /* is this necessary? */
1519 azalia_codec_init(codec_t *this)
1525 addr = this->address;
1527 err = azalia_comresp(this, CORB_NID_ROOT, CORB_GET_PARAMETER,
1531 err = azalia_comresp(this, CORB_NID_ROOT, CORB_GET_PARAMETER,
1535 this->vid = id;
1536 this->subid = this->az->subid;
1537 azalia_codec_init_vtbl(this);
1539 XNAME(this->az), addr, this->vid, this->subid,
1545 err = azalia_comresp(this, CORB_NID_ROOT, CORB_GET_PARAMETER,
1549 this->nfunctions = COP_NSUBNODES(result);
1552 XNAME(this->az), addr));
1558 XNAME(this->az), n, this->nfunctions));
1559 this->audiofunc = -1;
1560 for (i = 0; i < this->nfunctions; i++) {
1561 err = azalia_comresp(this, n + i, CORB_GET_PARAMETER,
1567 this->audiofunc = n + i;
1571 if (this->audiofunc < 0) {
1573 XNAME(this->az), addr));
1578 azalia_comresp(this, this->audiofunc, CORB_SET_POWER_STATE,
1583 err = azalia_comresp(this, this->audiofunc, CORB_GET_PARAMETER,
1589 this->wstart = COP_START_NID(result);
1590 if (this->wstart < 2) {
1591 printf("%s: invalid node structure\n", XNAME(this->az));
1594 this->wend = this->wstart + COP_NSUBNODES(result);
1595 this->w = mallocarray(this->wend, sizeof(widget_t), M_DEVBUF,
1597 if (this->w == NULL) {
1598 printf("%s: out of memory\n", XNAME(this->az));
1602 if (this->qrks & AZ_QRK_DOLBY_ATMOS)
1603 azalia_codec_init_dolby_atmos(this);
1606 azalia_comresp(this, this->audiofunc, CORB_GET_PARAMETER,
1608 this->w[this->audiofunc].d.audio.encodings = result;
1609 azalia_comresp(this, this->audiofunc, CORB_GET_PARAMETER,
1611 this->w[this->audiofunc].d.audio.bits_rates = result;
1612 azalia_comresp(this, this->audiofunc, CORB_GET_PARAMETER,
1614 this->w[this->audiofunc].inamp_cap = result;
1615 azalia_comresp(this, this->audiofunc, CORB_GET_PARAMETER,
1617 this->w[this->audiofunc].outamp_cap = result;
1619 azalia_codec_print_audiofunc(this);
1621 strlcpy(this->w[CORB_NID_ROOT].name, "root",
1622 sizeof(this->w[CORB_NID_ROOT].name));
1623 strlcpy(this->w[this->audiofunc].name, "hdaudio",
1624 sizeof(this->w[this->audiofunc].name));
1625 this->w[this->audiofunc].enable = 1;
1627 FOR_EACH_WIDGET(this, i) {
1628 w = &this->w[i];
1629 err = azalia_widget_init(w, this, i);
1632 err = azalia_widget_init_connection(w, this);
1636 azalia_widget_print_widget(w, this);
1638 if (this->qrks & AZ_QRK_WID_MASK) {
1639 azalia_codec_widget_quirks(this, i);
1643 this->na_dacs = this->na_dacs_d = 0;
1644 this->na_adcs = this->na_adcs_d = 0;
1645 this->speaker = this->speaker2 = this->spkr_dac =
1646 this->fhp = this->fhp_dac =
1647 this->mic = this->mic_adc = -1;
1648 this->nsense_pins = 0;
1649 this->nout_jacks = 0;
1651 FOR_EACH_WIDGET(this, i) {
1652 w = &this->w[i];
1661 if (!azalia_widget_check_conn(this, i, 0))
1667 if (this->na_dacs < HDA_MAX_CHANNELS)
1668 this->a_dacs[this->na_dacs++] = i;
1670 if (this->na_dacs_d < HDA_MAX_CHANNELS)
1671 this->a_dacs_d[this->na_dacs_d++] = i;
1677 if (this->na_adcs < HDA_MAX_CHANNELS)
1678 this->a_adcs[this->na_adcs++] = i;
1680 if (this->na_adcs_d < HDA_MAX_CHANNELS)
1681 this->a_adcs_d[this->na_adcs_d++] = i;
1690 if (this->speaker == -1) {
1691 this->speaker = i;
1693 this->w[this->speaker].d.pin.association ||
1695 this->w[this->speaker].d.pin.association &&
1697 this->w[this->speaker].d.pin.sequence)) {
1698 this->speaker2 = this->speaker;
1699 this->speaker = i;
1701 this->speaker2 = i;
1703 if (this->speaker == i)
1704 this->spkr_dac =
1705 azalia_codec_find_defdac(this, i, 0);
1708 this->mic = i;
1709 this->mic_adc =
1710 azalia_codec_find_defadc(this, i, 0);
1716 this->nout_jacks++;
1720 this->fhp = i;
1721 this->fhp_dac =
1722 azalia_codec_find_defdac(this, i, 0);
1724 if (this->nsense_pins >= HDA_MAX_SENSE_PINS ||
1728 err = azalia_comresp(this, i,
1733 this->sense_pins[this->nsense_pins++] = i;
1746 this->codec_type = AZ_CODEC_TYPE_ANALOG;
1747 if ((this->na_dacs == 0) && (this->na_adcs == 0)) {
1748 this->codec_type = AZ_CODEC_TYPE_DIGITAL;
1750 this->codec_type = AZ_CODEC_TYPE_HDMI;
1754 if (this->mic != -1 && this->mic_adc == -1) {
1755 if (azalia_codec_select_micadc(this)) {
1760 err = azalia_codec_sort_pins(this);
1764 err = azalia_codec_find_inputmixer(this);
1772 if (this->na_dacs >= 3 && this->nopins >= 3) {
1773 err = azalia_codec_select_dacs(this);
1778 err = azalia_codec_select_spkrdac(this);
1782 err = azalia_init_dacgroup(this);
1786 azalia_codec_print_groups(this);
1788 err = azalia_widget_label_widgets(this);
1792 err = azalia_codec_construct_format(this, 0, 0);
1796 err = azalia_codec_init_volgroups(this);
1800 if (this->qrks & AZ_QRK_GPIO_MASK) {
1801 err = azalia_codec_gpio_quirks(this);
1806 err = azalia_mixer_init(this);
1814 azalia_codec_find_inputmixer(codec_t *this)
1819 this->input_mixer = -1;
1821 FOR_EACH_WIDGET(this, i) {
1822 w = &this->w[i];
1827 for (j = 0; j < this->nipins; j++) {
1828 if (azalia_codec_fnode(this, this->ipins[j].nid,
1832 if (j == this->nipins)
1836 for (j = 0; j < this->nopins; j++) {
1837 if (azalia_codec_fnode(this, w->nid,
1838 this->opins[j].nid, 0) != -1)
1841 if (j == this->nopins)
1845 for (j = 0; j < this->na_adcs; j++) {
1846 if (azalia_codec_fnode(this, w->nid,
1847 this->a_adcs[j], 0) != -1)
1850 if (j == this->na_adcs)
1853 this->input_mixer = i;
1860 azalia_codec_select_micadc(codec_t *this)
1865 for (i = 0; i < this->na_adcs; i++) {
1866 if (azalia_codec_fnode(this, this->mic,
1867 this->a_adcs[i], 0) >= 0)
1870 if (i >= this->na_adcs)
1872 conv = this->a_adcs[i];
1874 w = &this->w[conv];
1877 if (!azalia_widget_enabled(this, w->connections[i]))
1879 if (azalia_codec_fnode(this, this->mic,
1886 err = azalia_comresp(this, w->nid,
1891 if (w->connections[i] == this->mic) {
1892 this->mic_adc = conv;
1895 w = &this->w[w->connections[i]];
1901 azalia_codec_sort_pins(codec_t *this)
1913 FOR_EACH_WIDGET(this, i) {
1914 w = &this->w[i];
1919 if (this->na_dacs >= 3 && this->nout_jacks < 3)
1929 conv = azalia_codec_find_defdac(this, w->nid, 0);
1933 if (w->nid == this->speaker ||
1934 w->nid == this->speaker2)
1943 if (w->nid == this->mic)
1961 conv = azalia_codec_find_defdac(this, w->nid, 0);
1978 conv = azalia_codec_find_defadc(this, w->nid, 0);
1987 if (w->nid == this->speaker ||
1988 w->nid == this->speaker2)
2006 conv = azalia_codec_find_defadc(this, w->nid, 0);
2022 this->opins = mallocarray(nopins, sizeof(struct io_pin), M_DEVBUF,
2024 if (this->opins == NULL)
2026 this->nopins = 0;
2028 for (j = 0; j < this->nopins; j++)
2029 if (this->opins[j].prio > opins[i].prio)
2031 for (k = this->nopins; k > j; k--)
2032 this->opins[k] = this->opins[k - 1];
2034 this->opins[j] = opins[i];
2035 this->nopins++;
2036 if (this->nopins == nopins)
2040 this->opins_d = mallocarray(nopins_d, sizeof(struct io_pin), M_DEVBUF,
2042 if (this->opins_d == NULL)
2044 this->nopins_d = 0;
2046 for (j = 0; j < this->nopins_d; j++)
2047 if (this->opins_d[j].prio > opins_d[i].prio)
2049 for (k = this->nopins_d; k > j; k--)
2050 this->opins_d[k] = this->opins_d[k - 1];
2052 this->opins_d[j] = opins_d[i];
2053 this->nopins_d++;
2054 if (this->nopins_d == nopins_d)
2058 this->ipins = mallocarray(nipins, sizeof(struct io_pin), M_DEVBUF,
2060 if (this->ipins == NULL)
2062 this->nipins = 0;
2064 for (j = 0; j < this->nipins; j++)
2065 if (this->ipins[j].prio > ipins[i].prio)
2067 for (k = this->nipins; k > j; k--)
2068 this->ipins[k] = this->ipins[k - 1];
2070 this->ipins[j] = ipins[i];
2071 this->nipins++;
2072 if (this->nipins == nipins)
2076 this->ipins_d = mallocarray(nipins_d, sizeof(struct io_pin), M_DEVBUF,
2078 if (this->ipins_d == NULL)
2080 this->nipins_d = 0;
2082 for (j = 0; j < this->nipins_d; j++)
2083 if (this->ipins_d[j].prio > ipins_d[i].prio)
2085 for (k = this->nipins_d; k > j; k--)
2086 this->ipins_d[k] = this->ipins_d[k - 1];
2088 this->ipins_d[j] = ipins_d[i];
2089 this->nipins_d++;
2090 if (this->nipins_d == nipins_d)
2096 for (i = 0; i < this->nopins; i++)
2097 printf(" 0x%2.2x->0x%2.2x", this->opins[i].nid,
2098 this->opins[i].conv);
2101 for (i = 0; i < this->nopins_d; i++)
2102 printf(" 0x%2.2x->0x%2.2x", this->opins_d[i].nid,
2103 this->opins_d[i].conv);
2106 for (i = 0; i < this->nipins; i++)
2107 printf(" 0x%2.2x->0x%2.2x", this->ipins[i].nid,
2108 this->ipins[i].conv);
2111 for (i = 0; i < this->nipins_d; i++)
2112 printf(" 0x%2.2x->0x%2.2x", this->ipins_d[i].nid,
2113 this->ipins_d[i].conv);
2122 azalia_codec_select_dacs(codec_t *this)
2129 convs = mallocarray(this->na_dacs, sizeof(nid_t), M_DEVBUF,
2136 for (i = 0; i < this->nopins; i++) {
2137 w = &this->w[this->opins[i].nid];
2139 conv = this->opins[i].conv;
2146 if (w->nid == this->fhp)
2147 this->fhp_dac = conv;
2148 if (nconv >= this->na_dacs) {
2155 if (!azalia_widget_enabled(this,
2158 conv = azalia_codec_find_defdac(this,
2170 err = azalia_comresp(this, w->nid,
2175 this->opins[i].conv = conv;
2176 if (w->nid == this->fhp)
2177 this->fhp_dac = conv;
2179 if (nconv >= this->na_dacs)
2185 free(convs, M_DEVBUF, this->na_dacs * sizeof(nid_t));
2194 azalia_codec_select_spkrdac(codec_t *this)
2202 for (i = 0; i < this->nopins; i++) {
2203 conv = this->opins[i].conv;
2209 if (conv == this->spkr_dac)
2212 if (nconv == this->na_dacs)
2219 w = &this->w[this->speaker];
2221 conv = azalia_codec_find_defdac(this,
2235 if (this->spkr_dac == this->opins[0].conv) {
2240 w = &this->w[this->opins[0].nid];
2242 conv = azalia_codec_find_defdac(this,
2244 if (conv != this->opins[0].conv) {
2252 err = azalia_comresp(this, w->nid,
2257 if (w->nid == this->speaker)
2258 this->spkr_dac = conv;
2260 this->opins[0].conv = conv;
2265 if (this->speaker2 != -1) {
2267 w = &this->w[this->speaker2];
2269 conv = azalia_codec_find_defdac(this,
2271 if (this->qrks & AZ_QRK_ROUTE_SPKR2_DAC) {
2272 if (conv != this->spkr_dac) {
2276 } else if (conv == this->spkr_dac) {
2282 err = azalia_comresp(this, w->nid,
2294 azalia_codec_find_defdac(codec_t *this, int index, int depth)
2299 w = &this->w[index];
2319 if (!azalia_widget_enabled(this, index))
2321 ret = azalia_codec_find_defdac(this, index,
2337 if (VALID_WIDGET_NID(index, this)) {
2338 ret = azalia_codec_find_defdac(this,
2350 azalia_codec_find_defadc_sub(codec_t *this, nid_t node, int index, int depth)
2355 w = &this->w[index];
2373 if (!azalia_widget_enabled(this, w->connections[i]))
2375 ret = azalia_codec_find_defadc_sub(this, node,
2391 if (VALID_WIDGET_NID(index, this)) {
2392 ret = azalia_codec_find_defadc_sub(this,
2403 azalia_codec_find_defadc(codec_t *this, int index, int depth)
2408 for (i = 0; i < this->na_adcs; i++) {
2409 j = azalia_codec_find_defadc_sub(this, index,
2410 this->a_adcs[i], 0);
2412 conv = this->a_adcs[i];
2420 azalia_codec_init_volgroups(codec_t *this)
2427 this->playvols.mask = 0;
2428 FOR_EACH_WIDGET(this, i) {
2429 w = &this->w[i];
2439 this->playvols.mask |= (1 << j);
2440 this->playvols.slaves[j++] = w->nid;
2444 this->playvols.nslaves = j;
2446 this->playvols.cur = 0;
2447 for (i = 0; i < this->playvols.nslaves; i++) {
2448 w = &this->w[this->playvols.slaves[i]];
2449 if (w->nid == this->input_mixer ||
2450 w->parent == this->input_mixer ||
2461 dac = azalia_codec_find_defdac(this, w->nid, j);
2464 if (dac != this->dacs.groups[this->dacs.cur].conv[0] &&
2465 dac != this->spkr_dac && dac != this->fhp_dac)
2472 err = azalia_comresp(this, w->nid,
2475 this->playvols.cur |= (1 << i);
2477 this->playvols.cur |= (1 << i);
2480 if (this->playvols.cur == 0) {
2481 for (i = 0; i < this->playvols.nslaves; i++) {
2482 w = &this->w[this->playvols.slaves[i]];
2487 dac = azalia_codec_find_defdac(this, w->nid, j);
2490 if (dac != this->dacs.groups[this->dacs.cur].conv[0] &&
2491 dac != this->spkr_dac && dac != this->fhp_dac)
2496 err = azalia_comresp(this, w->nid,
2499 this->playvols.cur |= (1 << i);
2501 this->playvols.cur |= (1 << i);
2506 this->playvols.master = this->audiofunc;
2507 if (this->playvols.nslaves > 0) {
2508 FOR_EACH_WIDGET(this, i) {
2509 w = &this->w[i];
2514 this->playvols.master = w->nid;
2520 this->recvols.mask = 0;
2521 FOR_EACH_WIDGET(this, i) {
2522 w = &this->w[i];
2544 this->recvols.mask |= (1 << j);
2545 this->recvols.slaves[j++] = w->nid;
2549 this->recvols.nslaves = j;
2551 this->recvols.cur = 0;
2552 for (i = 0; i < this->recvols.nslaves; i++) {
2553 w = &this->w[this->recvols.slaves[i]];
2563 err = azalia_comresp(this, w->nid,
2566 this->recvols.cur |= (1 << i);
2568 this->recvols.cur |= (1 << i);
2571 if (this->recvols.cur == 0) {
2572 for (i = 0; i < this->recvols.nslaves; i++) {
2573 w = &this->w[this->recvols.slaves[i]];
2582 err = azalia_comresp(this, w->nid,
2585 this->recvols.cur |= (1 << i);
2587 this->recvols.cur |= (1 << i);
2592 this->recvols.master = this->audiofunc;
2598 azalia_codec_delete(codec_t *this)
2600 azalia_mixer_delete(this);
2602 if (this->formats != NULL) {
2603 free(this->formats, M_DEVBUF,
2604 this->nformats * sizeof(struct audio_format));
2605 this->formats = NULL;
2607 this->nformats = 0;
2609 if (this->opins != NULL) {
2610 free(this->opins, M_DEVBUF,
2611 this->nopins * sizeof(struct io_pin));
2612 this->opins = NULL;
2614 this->nopins = 0;
2616 if (this->opins_d != NULL) {
2617 free(this->opins_d, M_DEVBUF,
2618 this->nopins_d * sizeof(struct io_pin));
2619 this->opins_d = NULL;
2621 this->nopins_d = 0;
2623 if (this->ipins != NULL) {
2624 free(this->ipins, M_DEVBUF,
2625 this->nipins * sizeof(struct io_pin));
2626 this->ipins = NULL;
2628 this->nipins = 0;
2630 if (this->ipins_d != NULL) {
2631 free(this->ipins_d, M_DEVBUF,
2632 this->nipins_d * sizeof(struct io_pin));
2633 this->ipins_d = NULL;
2635 this->nipins_d = 0;
2637 if (this->w != NULL) {
2638 free(this->w, M_DEVBUF,
2639 this->wend * sizeof(widget_t));
2640 this->w = NULL;
2647 azalia_codec_construct_format(codec_t *this, int newdac, int newadc)
2657 if (this->dacs.ngroups > 0 && newdac < this->dacs.ngroups &&
2659 this->dacs.cur = newdac;
2660 group = &this->dacs.groups[this->dacs.cur];
2661 bits_rates = this->w[group->conv[0]].d.audio.bits_rates;
2672 !(this->w[group->conv[0]].widgetcap & COP_AWCAP_DIGITAL))
2676 XNAME(this->az), bits_rates);
2682 if (this->adcs.ngroups > 0 && newadc < this->adcs.ngroups &&
2684 this->adcs.cur = newadc;
2685 group = &this->adcs.groups[this->adcs.cur];
2686 bits_rates = this->w[group->conv[0]].d.audio.bits_rates;
2697 !(this->w[group->conv[0]].widgetcap & COP_AWCAP_DIGITAL))
2701 XNAME(this->az), bits_rates);
2708 DPRINTF(("%s: no converter groups\n", XNAME(this->az)));
2712 if (this->formats != NULL)
2713 free(this->formats, M_DEVBUF, 0);
2714 this->nformats = 0;
2715 this->formats = mallocarray(variation, sizeof(struct audio_format),
2717 if (this->formats == NULL) {
2719 XNAME(this->az), __func__);
2724 if (this->dacs.ngroups > 0) {
2725 group = &this->dacs.groups[this->dacs.cur];
2729 if (this->w[group->conv[0]].widgetcap &
2734 chan += WIDGET_CHANNELS(&this->w[nid]);
2735 bits_rates &= this->w[nid].d.audio.bits_rates;
2737 azalia_codec_add_bits(this, chan, bits_rates,
2743 if (this->adcs.ngroups > 0) {
2744 group = &this->adcs.groups[this->adcs.cur];
2748 if (this->w[group->conv[0]].widgetcap &
2753 chan += WIDGET_CHANNELS(&this->w[nid]);
2754 bits_rates &= this->w[nid].d.audio.bits_rates;
2756 azalia_codec_add_bits(this, chan, bits_rates,
2765 azalia_codec_add_bits(codec_t *this, int chan, uint32_t bits_rates, int mode)
2768 azalia_codec_add_format(this, chan, 8, bits_rates, mode);
2770 azalia_codec_add_format(this, chan, 16, bits_rates, mode);
2772 azalia_codec_add_format(this, chan, 20, bits_rates, mode);
2774 azalia_codec_add_format(this, chan, 24, bits_rates, mode);
2776 azalia_codec_add_format(this, chan, 32, bits_rates, mode);
2780 azalia_codec_add_format(codec_t *this, int chan, int prec, uint32_t rates,
2785 f = &this->formats[this->nformats++];
2820 azalia_codec_connect_stream(stream_t *this)
2822 const codec_t *codec = &this->az->codecs[this->az->codecno];
2829 nchan = (this->fmt & HDA_SD_FMT_CHAN) + 1;
2831 if (this->dir == AUMODE_RECORD)
2841 stream_chan = (this->number << 4);
2854 w->nid, stream_chan & ~(this->number << 4)));
2858 this->fmt, NULL);
2861 __func__, w->nid, this->fmt, err));
2896 azalia_codec_disconnect_stream(stream_t *this)
2898 const codec_t *codec = &this->az->codecs[this->az->codecno];
2904 if (this->dir == AUMODE_RECORD)
2929 azalia_widget_init(widget_t *this, const codec_t *codec, nid_t nid)
2938 this->nid = nid;
2939 this->widgetcap = result;
2940 this->type = COP_AWCAP_TYPE(result);
2941 if (this->widgetcap & COP_AWCAP_POWER) {
2947 this->enable = 1;
2948 this->mixer_class = -1;
2949 this->parent = codec->audiofunc;
2951 switch (this->type) {
2955 azalia_widget_init_audio(this, codec);
2958 azalia_widget_init_pin(this, codec);
2961 err = azalia_comresp(codec, this->nid, CORB_GET_PARAMETER,
2965 this->d.volume.cap = result;
2970 this->enable = 0;
2979 if (this->widgetcap & COP_AWCAP_INAMP) {
2980 if (this->widgetcap & COP_AWCAP_AMPOV)
2982 COP_INPUT_AMPCAP, &this->inamp_cap);
2984 this->inamp_cap = codec->w[codec->audiofunc].inamp_cap;
2985 this->inamp_cap &= ~(0x7f << 24);
2987 if (this->widgetcap & COP_AWCAP_OUTAMP) {
2988 if (this->widgetcap & COP_AWCAP_AMPOV)
2990 COP_OUTPUT_AMPCAP, &this->outamp_cap);
2992 this->outamp_cap = codec->w[codec->audiofunc].outamp_cap;
2993 this->outamp_cap &= ~(0x7f << 24);
2999 azalia_widget_sole_conn(codec_t *this, nid_t nid)
3004 for (i = 0; i < this->adcs.ngroups; i++) {
3005 for (j = 0; j < this->adcs.groups[i].nconv; j++) {
3006 target = this->adcs.groups[i].conv[j];
3007 if (this->w[target].nconnections == 1 &&
3008 this->w[target].connections[0] == nid) {
3014 for (i = 0; i < this->dacs.ngroups; i++) {
3015 for (j = 0; j < this->dacs.groups[i].nconv; j++) {
3016 target = this->dacs.groups[i].conv[j];
3017 if (this->w[target].nconnections == 1 &&
3018 this->w[target].connections[0] == nid) {
3025 FOR_EACH_WIDGET(this, i) {
3026 if (this->w[i].type != COP_AWTYPE_PIN_COMPLEX)
3028 if (this->w[i].nconnections == 1 &&
3029 this->w[i].connections[0] == nid) {
3036 for (j = 0; j < this->w[i].nconnections; j++) {
3037 if (!this->w[this->w[i].connections[j]].enable)
3040 if (this->w[i].connections[j] == nid)
3194 * no input or no output capabilities. This widget
3215 /* As part of a disabled widget, this widget
3237 azalia_widget_init_audio(widget_t *this, const codec_t *codec)
3243 if (this->widgetcap & COP_AWCAP_FORMATOV) {
3244 err = azalia_comresp(codec, this->nid, CORB_GET_PARAMETER,
3248 this->d.audio.encodings = result;
3250 * This must not occur usually... */
3251 this->d.audio.encodings =
3253 this->d.audio.bits_rates =
3258 XNAME(codec->az), this->name, result);
3261 err = azalia_comresp(codec, this->nid,
3265 this->d.audio.bits_rates = result;
3268 this->d.audio.encodings =
3270 this->d.audio.bits_rates =
3277 azalia_widget_init_pin(widget_t *this, const codec_t *codec)
3282 err = azalia_comresp(codec, this->nid, CORB_GET_CONFIGURATION_DEFAULT,
3286 this->d.pin.config = result;
3287 this->d.pin.sequence = CORB_CD_SEQUENCE(result);
3288 this->d.pin.association = CORB_CD_ASSOCIATION(result);
3289 this->d.pin.color = CORB_CD_COLOR(result);
3290 this->d.pin.device = CORB_CD_DEVICE(result);
3292 err = azalia_comresp(codec, this->nid, CORB_GET_PARAMETER,
3296 this->d.pin.cap = result;
3299 switch (this->d.pin.device) {
3309 if (dir == CORB_PWC_INPUT && !(this->d.pin.cap & COP_PINCAP_INPUT))
3311 if (dir == CORB_PWC_OUTPUT && !(this->d.pin.cap & COP_PINCAP_OUTPUT))
3314 if (dir == CORB_PWC_INPUT && this->d.pin.device == CORB_CD_MICIN) {
3315 if (COP_PINCAP_VREF(this->d.pin.cap) & (1 << CORB_PWC_VREF_80))
3317 else if (COP_PINCAP_VREF(this->d.pin.cap) &
3325 azalia_comresp(codec, this->nid, CORB_SET_PIN_WIDGET_CONTROL,
3328 if (this->d.pin.cap & COP_PINCAP_EAPD) {
3329 err = azalia_comresp(codec, this->nid,
3335 err = azalia_comresp(codec, this->nid,
3342 if (CORB_CD_PORT(this->d.pin.config) == CORB_CD_NONE)
3343 this->enable = 0;
3349 azalia_widget_init_connection(widget_t *this, const codec_t *codec)
3356 this->selected = -1;
3357 if ((this->widgetcap & COP_AWCAP_CONNLIST) == 0)
3360 err = azalia_comresp(codec, this->nid, CORB_GET_PARAMETER,
3381 err = azalia_comresp(codec, this->nid,
3387 /* If high bit is set, this is the end of a continuous
3399 this->connections = mallocarray(nconn, sizeof(nid_t), M_DEVBUF, M_NOWAIT);
3400 if (this->connections == NULL) {
3405 err = azalia_comresp(codec, this->nid,
3411 /* If high bit is set, this is the end of a continuous
3416 this->connections[i++] = last + j;
3418 this->connections[i++] = conn;
3423 this->nconnections = nconn;
3426 err = azalia_comresp(codec, this->nid,
3430 this->selected = CORB_CSC_INDEX(result);
3503 azalia_codec_print_audiofunc(const codec_t *this)
3507 azalia_widget_print_audio(&this->w[this->audiofunc], "\t");
3509 result = this->w[this->audiofunc].inamp_cap;
3513 result = this->w[this->audiofunc].outamp_cap;
3517 azalia_comresp(this, this->audiofunc, CORB_GET_PARAMETER,
3526 azalia_codec_print_groups(const codec_t *this)
3530 for (i = 0; i < this->dacs.ngroups; i++) {
3531 printf("%s: dacgroup[%d]:", XNAME(this->az), i);
3532 for (n = 0; n < this->dacs.groups[i].nconv; n++) {
3533 printf(" %2.2x", this->dacs.groups[i].conv[n]);
3537 for (i = 0; i < this->adcs.ngroups; i++) {
3538 printf("%s: adcgroup[%d]:", XNAME(this->az), i);
3539 for (n = 0; n < this->adcs.groups[i].nconv; n++) {
3540 printf(" %2.2x", this->adcs.groups[i].conv[n]);
3547 azalia_widget_print_audio(const widget_t *this, const char *lead)
3549 printf("%sencodings=%b\n", lead, this->d.audio.encodings,
3551 printf("%sPCM formats=%b\n", lead, this->d.audio.bits_rates,
3599 azalia_widget_print_pin(const widget_t *this)
3601 printf("\tcap=%b\n", this->d.pin.cap, PINCAP_BITS);
3602 printf("\t[%2.2d/%2.2d] ", CORB_CD_ASSOCIATION(this->d.pin.config),
3603 CORB_CD_SEQUENCE(this->d.pin.config));
3604 printf("color=%s ", pin_colors[CORB_CD_COLOR(this->d.pin.config)]);
3605 printf("device=%s ", pin_devices[CORB_CD_DEVICE(this->d.pin.config)]);
3606 printf("conn=%s ", pin_conn[CORB_CD_PORT(this->d.pin.config)]);
3607 printf("conntype=%s\n", pin_conntype[CORB_CD_CONNECTION(this->d.pin.config)]);
3608 printf("\tlocation=%s ", pin_geo[CORB_CD_LOC_GEO(this->d.pin.config)]);
3609 printf("chassis=%s ", pin_chass[CORB_CD_LOC_CHASS(this->d.pin.config)]);
3611 if (CORB_CD_LOC_GEO(this->d.pin.config) == CORB_CD_LOC_SPEC0) {
3612 if (CORB_CD_LOC_CHASS(this->d.pin.config) == CORB_CD_EXTERNAL)
3614 else if (CORB_CD_LOC_CHASS(this->d.pin.config) == CORB_CD_INTERNAL)
3616 else if (CORB_CD_LOC_CHASS(this->d.pin.config) == CORB_CD_LOC_OTHER)
3618 } else if (CORB_CD_LOC_GEO(this->d.pin.config) == CORB_CD_LOC_SPEC1) {
3619 if (CORB_CD_LOC_CHASS(this->d.pin.config) == CORB_CD_EXTERNAL)
3621 else if (CORB_CD_LOC_CHASS(this->d.pin.config) == CORB_CD_INTERNAL)
3623 else if (CORB_CD_LOC_CHASS(this->d.pin.config) == CORB_CD_LOC_OTHER)
3625 } else if (CORB_CD_LOC_GEO(this->d.pin.config) == CORB_CD_LOC_SPEC2) {
3626 if (CORB_CD_LOC_CHASS(this->d.pin.config) == CORB_CD_INTERNAL)
3636 azalia_codec_print_audiofunc(const codec_t *this) {}
3639 azalia_codec_print_groups(const codec_t *this) {}
3642 azalia_widget_print_audio(const widget_t *this, const char *lead) {}
3648 azalia_widget_print_pin(const widget_t *this) {}
3657 azalia_stream_init(stream_t *this, azalia_t *az, int regindex, int strnum,
3662 this->az = az;
3663 this->regbase = HDA_SD_BASE + regindex * HDA_SD_SIZE;
3664 this->intr_bit = 1 << regindex;
3665 this->number = strnum;
3666 this->dir = dir;
3670 128, &this->bdlist);
3679 azalia_stream_reset(stream_t *this)
3686 ctl = STR_READ_2(this, CTL);
3688 STR_WRITE_2(this, CTL, ctl);
3692 ctl = STR_READ_2(this, CTL);
3693 STR_WRITE_2(this, CTL, ctl | HDA_SD_CTL_SRST);
3696 ctl = STR_READ_2(this, CTL);
3701 DPRINTF(("%s: stream reset failure 1\n", XNAME(this->az)));
3706 STR_WRITE_2(this, CTL, ctl & ~HDA_SD_CTL_SRST);
3709 ctl = STR_READ_2(this, CTL);
3714 DPRINTF(("%s: stream reset failure 2\n", XNAME(this->az)));
3718 sts = STR_READ_1(this, STS);
3720 STR_WRITE_1(this, STS, sts);
3726 azalia_stream_start(stream_t *this)
3733 err = azalia_stream_reset(this);
3739 STR_WRITE_4(this, BDPL, 0);
3740 STR_WRITE_4(this, BDPU, 0);
3743 dmaaddr = AZALIA_DMA_DMAADDR(&this->buffer);
3744 dmaend = dmaaddr + this->bufsize;
3745 bdlist = (bdlist_entry_t*)this->bdlist.addr;
3749 bdlist[index].length = htole32(this->blk);
3751 dmaaddr += this->blk;
3759 __func__, this->bufsize, this->fmt, index));
3761 dmaaddr = AZALIA_DMA_DMAADDR(&this->bdlist);
3762 STR_WRITE_4(this, BDPL, dmaaddr);
3763 STR_WRITE_4(this, BDPU, PTR_UPPER32(dmaaddr));
3764 STR_WRITE_2(this, LVI, (index - 1) & HDA_SD_LVI_LVI);
3765 ctl2 = STR_READ_1(this, CTL2);
3766 STR_WRITE_1(this, CTL2,
3767 (ctl2 & ~HDA_SD_CTL2_STRM) | (this->number << HDA_SD_CTL2_STRM_SHIFT));
3768 STR_WRITE_4(this, CBL, this->bufsize);
3769 STR_WRITE_2(this, FMT, this->fmt);
3771 err = azalia_codec_connect_stream(this);
3775 this->az->intctl |= this->intr_bit;
3776 AZ_WRITE_4(this->az, INTCTL, this->az->intctl);
3778 STR_WRITE_1(this, CTL, STR_READ_1(this, CTL) |
3785 azalia_stream_halt(stream_t *this)
3789 ctl = STR_READ_2(this, CTL);
3791 STR_WRITE_2(this, CTL, ctl);
3792 this->az->intctl &= ~this->intr_bit;
3793 AZ_WRITE_4(this->az, INTCTL, this->az->intctl);
3794 azalia_codec_disconnect_stream(this);
3802 azalia_stream_intr(stream_t *this)
3807 sts = STR_READ_1(this, STS);
3808 STR_WRITE_1(this, STS, sts |
3812 DPRINTF(("%s: stream %d: sts=%b\n", XNAME(this->az),
3813 this->number, sts, HDA_SD_STS_BITS));
3816 lpib = STR_READ_4(this, LPIB);
3817 fifos = STR_READ_2(this, FIFOS);
3821 if (this->dir == AUMODE_PLAY)
3823 if (hwpos >= this->bufsize)
3824 hwpos -= this->bufsize;
3827 this->number, this->swpos, hwpos, lpib, fifos));
3829 while (hwpos - this->swpos >= this->blk) {
3830 this->intr(this->intr_arg);
3831 this->swpos += this->blk;
3832 if (this->swpos == this->bufsize)
3833 this->swpos = 0;
3838 __func__, this->number, this->swpos, cnt));
4188 DPRINTFN(1, ("%s: this=%p start=%p end=%p blk=%d {enc=%u %uch %ubit %luHz}\n",