11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Universal Interface for Intel High Definition Audio Codec 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Local helper functions 51da177e4SLinus Torvalds * 61da177e4SLinus Torvalds * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de> 71da177e4SLinus Torvalds * 81da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify it 91da177e4SLinus Torvalds * under the terms of the GNU General Public License as published by the Free 101da177e4SLinus Torvalds * Software Foundation; either version 2 of the License, or (at your option) 111da177e4SLinus Torvalds * any later version. 121da177e4SLinus Torvalds * 131da177e4SLinus Torvalds * This program is distributed in the hope that it will be useful, but WITHOUT 141da177e4SLinus Torvalds * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 151da177e4SLinus Torvalds * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 161da177e4SLinus Torvalds * more details. 171da177e4SLinus Torvalds * 181da177e4SLinus Torvalds * You should have received a copy of the GNU General Public License along with 191da177e4SLinus Torvalds * this program; if not, write to the Free Software Foundation, Inc., 59 201da177e4SLinus Torvalds * Temple Place - Suite 330, Boston, MA 02111-1307, USA. 211da177e4SLinus Torvalds */ 221da177e4SLinus Torvalds 231da177e4SLinus Torvalds #ifndef __SOUND_HDA_LOCAL_H 241da177e4SLinus Torvalds #define __SOUND_HDA_LOCAL_H 251da177e4SLinus Torvalds 261da177e4SLinus Torvalds /* 271da177e4SLinus Torvalds * for mixer controls 281da177e4SLinus Torvalds */ 291da177e4SLinus Torvalds #define HDA_COMPOSE_AMP_VAL(nid,chs,idx,dir) ((nid) | ((chs)<<16) | ((dir)<<18) | ((idx)<<19)) 30985be54bSTakashi Iwai /* mono volume with index (index=0,1,...) (channel=1,2) */ 311da177e4SLinus Torvalds #define HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \ 321da177e4SLinus Torvalds { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \ 331da177e4SLinus Torvalds .info = snd_hda_mixer_amp_volume_info, \ 341da177e4SLinus Torvalds .get = snd_hda_mixer_amp_volume_get, \ 351da177e4SLinus Torvalds .put = snd_hda_mixer_amp_volume_put, \ 361da177e4SLinus Torvalds .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, direction) } 37985be54bSTakashi Iwai /* stereo volume with index */ 381da177e4SLinus Torvalds #define HDA_CODEC_VOLUME_IDX(xname, xcidx, nid, xindex, direction) \ 391da177e4SLinus Torvalds HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, 3, xindex, direction) 40985be54bSTakashi Iwai /* mono volume */ 411da177e4SLinus Torvalds #define HDA_CODEC_VOLUME_MONO(xname, nid, channel, xindex, direction) \ 421da177e4SLinus Torvalds HDA_CODEC_VOLUME_MONO_IDX(xname, 0, nid, channel, xindex, direction) 43985be54bSTakashi Iwai /* stereo volume */ 441da177e4SLinus Torvalds #define HDA_CODEC_VOLUME(xname, nid, xindex, direction) \ 451da177e4SLinus Torvalds HDA_CODEC_VOLUME_MONO(xname, nid, 3, xindex, direction) 46985be54bSTakashi Iwai /* mono mute switch with index (index=0,1,...) (channel=1,2) */ 471da177e4SLinus Torvalds #define HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \ 481da177e4SLinus Torvalds { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \ 491da177e4SLinus Torvalds .info = snd_hda_mixer_amp_switch_info, \ 501da177e4SLinus Torvalds .get = snd_hda_mixer_amp_switch_get, \ 511da177e4SLinus Torvalds .put = snd_hda_mixer_amp_switch_put, \ 521da177e4SLinus Torvalds .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, direction) } 53985be54bSTakashi Iwai /* stereo mute switch with index */ 541da177e4SLinus Torvalds #define HDA_CODEC_MUTE_IDX(xname, xcidx, nid, xindex, direction) \ 551da177e4SLinus Torvalds HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, 3, xindex, direction) 56985be54bSTakashi Iwai /* mono mute switch */ 571da177e4SLinus Torvalds #define HDA_CODEC_MUTE_MONO(xname, nid, channel, xindex, direction) \ 581da177e4SLinus Torvalds HDA_CODEC_MUTE_MONO_IDX(xname, 0, nid, channel, xindex, direction) 59985be54bSTakashi Iwai /* stereo mute switch */ 601da177e4SLinus Torvalds #define HDA_CODEC_MUTE(xname, nid, xindex, direction) \ 611da177e4SLinus Torvalds HDA_CODEC_MUTE_MONO(xname, nid, 3, xindex, direction) 621da177e4SLinus Torvalds 63c8b6bf9bSTakashi Iwai int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo); 64c8b6bf9bSTakashi Iwai int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol); 65c8b6bf9bSTakashi Iwai int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol); 66c8b6bf9bSTakashi Iwai int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo); 67c8b6bf9bSTakashi Iwai int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol); 68c8b6bf9bSTakashi Iwai int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol); 69834be88dSTakashi Iwai /* lowlevel accessor with caching; use carefully */ 70834be88dSTakashi Iwai int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch, 71834be88dSTakashi Iwai int direction, int index); 72834be88dSTakashi Iwai int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch, 73834be88dSTakashi Iwai int direction, int idx, int mask, int val); 741da177e4SLinus Torvalds 75985be54bSTakashi Iwai /* mono switch binding multiple inputs */ 76985be54bSTakashi Iwai #define HDA_BIND_MUTE_MONO(xname, nid, channel, indices, direction) \ 77985be54bSTakashi Iwai { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 78985be54bSTakashi Iwai .info = snd_hda_mixer_amp_switch_info, \ 79985be54bSTakashi Iwai .get = snd_hda_mixer_bind_switch_get, \ 80985be54bSTakashi Iwai .put = snd_hda_mixer_bind_switch_put, \ 81985be54bSTakashi Iwai .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, indices, direction) } 82985be54bSTakashi Iwai 83985be54bSTakashi Iwai /* stereo switch binding multiple inputs */ 84985be54bSTakashi Iwai #define HDA_BIND_MUTE(xname,nid,indices,dir) HDA_BIND_MUTE_MONO(xname,nid,3,indices,dir) 85985be54bSTakashi Iwai 86c8b6bf9bSTakashi Iwai int snd_hda_mixer_bind_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol); 87c8b6bf9bSTakashi Iwai int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol); 88985be54bSTakashi Iwai 891da177e4SLinus Torvalds int snd_hda_create_spdif_out_ctls(struct hda_codec *codec, hda_nid_t nid); 901da177e4SLinus Torvalds int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid); 911da177e4SLinus Torvalds 921da177e4SLinus Torvalds /* 931da177e4SLinus Torvalds * input MUX helper 941da177e4SLinus Torvalds */ 9554d17403STakashi Iwai #define HDA_MAX_NUM_INPUTS 16 961da177e4SLinus Torvalds struct hda_input_mux_item { 971da177e4SLinus Torvalds const char *label; 981da177e4SLinus Torvalds unsigned int index; 991da177e4SLinus Torvalds }; 1001da177e4SLinus Torvalds struct hda_input_mux { 1011da177e4SLinus Torvalds unsigned int num_items; 1021da177e4SLinus Torvalds struct hda_input_mux_item items[HDA_MAX_NUM_INPUTS]; 1031da177e4SLinus Torvalds }; 1041da177e4SLinus Torvalds 105c8b6bf9bSTakashi Iwai int snd_hda_input_mux_info(const struct hda_input_mux *imux, struct snd_ctl_elem_info *uinfo); 1061da177e4SLinus Torvalds int snd_hda_input_mux_put(struct hda_codec *codec, const struct hda_input_mux *imux, 107c8b6bf9bSTakashi Iwai struct snd_ctl_elem_value *ucontrol, hda_nid_t nid, 1081da177e4SLinus Torvalds unsigned int *cur_val); 1091da177e4SLinus Torvalds 110d2a6d7dcSTakashi Iwai /* 111d2a6d7dcSTakashi Iwai * Channel mode helper 112d2a6d7dcSTakashi Iwai */ 113d2a6d7dcSTakashi Iwai struct hda_channel_mode { 114d2a6d7dcSTakashi Iwai int channels; 115d2a6d7dcSTakashi Iwai const struct hda_verb *sequence; 116d2a6d7dcSTakashi Iwai }; 117d2a6d7dcSTakashi Iwai 118c8b6bf9bSTakashi Iwai int snd_hda_ch_mode_info(struct hda_codec *codec, struct snd_ctl_elem_info *uinfo, 119d2a6d7dcSTakashi Iwai const struct hda_channel_mode *chmode, int num_chmodes); 120c8b6bf9bSTakashi Iwai int snd_hda_ch_mode_get(struct hda_codec *codec, struct snd_ctl_elem_value *ucontrol, 121d2a6d7dcSTakashi Iwai const struct hda_channel_mode *chmode, int num_chmodes, 122d2a6d7dcSTakashi Iwai int max_channels); 123c8b6bf9bSTakashi Iwai int snd_hda_ch_mode_put(struct hda_codec *codec, struct snd_ctl_elem_value *ucontrol, 124d2a6d7dcSTakashi Iwai const struct hda_channel_mode *chmode, int num_chmodes, 125d2a6d7dcSTakashi Iwai int *max_channelsp); 126d2a6d7dcSTakashi Iwai 1271da177e4SLinus Torvalds /* 1281da177e4SLinus Torvalds * Multi-channel / digital-out PCM helper 1291da177e4SLinus Torvalds */ 1301da177e4SLinus Torvalds 1311da177e4SLinus Torvalds enum { HDA_FRONT, HDA_REAR, HDA_CLFE, HDA_SIDE }; /* index for dac_nidx */ 1321da177e4SLinus Torvalds enum { HDA_DIG_NONE, HDA_DIG_EXCLUSIVE, HDA_DIG_ANALOG_DUP }; /* dig_out_used */ 1331da177e4SLinus Torvalds 1341da177e4SLinus Torvalds struct hda_multi_out { 1351da177e4SLinus Torvalds int num_dacs; /* # of DACs, must be more than 1 */ 1361da177e4SLinus Torvalds hda_nid_t *dac_nids; /* DAC list */ 1371da177e4SLinus Torvalds hda_nid_t hp_nid; /* optional DAC for HP, 0 when not exists */ 138*82bc955fSTakashi Iwai hda_nid_t extra_out_nid[3]; /* optional DACs, 0 when not exists */ 1391da177e4SLinus Torvalds hda_nid_t dig_out_nid; /* digital out audio widget */ 1401da177e4SLinus Torvalds int max_channels; /* currently supported analog channels */ 1411da177e4SLinus Torvalds int dig_out_used; /* current usage of digital out (HDA_DIG_XXX) */ 1421da177e4SLinus Torvalds }; 1431da177e4SLinus Torvalds 1441da177e4SLinus Torvalds int snd_hda_multi_out_dig_open(struct hda_codec *codec, struct hda_multi_out *mout); 1451da177e4SLinus Torvalds int snd_hda_multi_out_dig_close(struct hda_codec *codec, struct hda_multi_out *mout); 1461da177e4SLinus Torvalds int snd_hda_multi_out_analog_open(struct hda_codec *codec, struct hda_multi_out *mout, 147c8b6bf9bSTakashi Iwai struct snd_pcm_substream *substream); 1481da177e4SLinus Torvalds int snd_hda_multi_out_analog_prepare(struct hda_codec *codec, struct hda_multi_out *mout, 1491da177e4SLinus Torvalds unsigned int stream_tag, 1501da177e4SLinus Torvalds unsigned int format, 151c8b6bf9bSTakashi Iwai struct snd_pcm_substream *substream); 1521da177e4SLinus Torvalds int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec, struct hda_multi_out *mout); 1531da177e4SLinus Torvalds 1541da177e4SLinus Torvalds /* 1551da177e4SLinus Torvalds * generic codec parser 1561da177e4SLinus Torvalds */ 1571da177e4SLinus Torvalds int snd_hda_parse_generic_codec(struct hda_codec *codec); 1581da177e4SLinus Torvalds 1591da177e4SLinus Torvalds /* 1601da177e4SLinus Torvalds * generic proc interface 1611da177e4SLinus Torvalds */ 1621da177e4SLinus Torvalds #ifdef CONFIG_PROC_FS 1631da177e4SLinus Torvalds int snd_hda_codec_proc_new(struct hda_codec *codec); 1641da177e4SLinus Torvalds #else 1651da177e4SLinus Torvalds static inline int snd_hda_codec_proc_new(struct hda_codec *codec) { return 0; } 1661da177e4SLinus Torvalds #endif 1671da177e4SLinus Torvalds 1681da177e4SLinus Torvalds /* 1691da177e4SLinus Torvalds * Misc 1701da177e4SLinus Torvalds */ 1711da177e4SLinus Torvalds struct hda_board_config { 1721da177e4SLinus Torvalds const char *modelname; 1731da177e4SLinus Torvalds int config; 1747291548dSTakashi Iwai unsigned short pci_subvendor; 1757291548dSTakashi Iwai unsigned short pci_subdevice; 1761da177e4SLinus Torvalds }; 1771da177e4SLinus Torvalds 178e9edcee0STakashi Iwai int snd_hda_check_board_config(struct hda_codec *codec, const struct hda_board_config *tbl); 179c8b6bf9bSTakashi Iwai int snd_hda_add_new_ctls(struct hda_codec *codec, struct snd_kcontrol_new *knew); 1801da177e4SLinus Torvalds 1811da177e4SLinus Torvalds /* 1821da177e4SLinus Torvalds * power management 1831da177e4SLinus Torvalds */ 1841da177e4SLinus Torvalds #ifdef CONFIG_PM 185c8b6bf9bSTakashi Iwai int snd_hda_resume_ctls(struct hda_codec *codec, struct snd_kcontrol_new *knew); 1861da177e4SLinus Torvalds int snd_hda_resume_spdif_out(struct hda_codec *codec); 1871da177e4SLinus Torvalds int snd_hda_resume_spdif_in(struct hda_codec *codec); 1881da177e4SLinus Torvalds #endif 1891da177e4SLinus Torvalds 1901da177e4SLinus Torvalds /* 1911da177e4SLinus Torvalds * unsolicited event handler 1921da177e4SLinus Torvalds */ 1931da177e4SLinus Torvalds 1941da177e4SLinus Torvalds #define HDA_UNSOL_QUEUE_SIZE 64 1951da177e4SLinus Torvalds 1961da177e4SLinus Torvalds struct hda_bus_unsolicited { 1971da177e4SLinus Torvalds /* ring buffer */ 1981da177e4SLinus Torvalds u32 queue[HDA_UNSOL_QUEUE_SIZE * 2]; 1991da177e4SLinus Torvalds unsigned int rp, wp; 2001da177e4SLinus Torvalds 2011da177e4SLinus Torvalds /* workqueue */ 2021da177e4SLinus Torvalds struct workqueue_struct *workq; 2031da177e4SLinus Torvalds struct work_struct work; 2041da177e4SLinus Torvalds }; 2051da177e4SLinus Torvalds 206e9edcee0STakashi Iwai /* 207e9edcee0STakashi Iwai * Helper for automatic ping configuration 208e9edcee0STakashi Iwai */ 209e9edcee0STakashi Iwai 210e9edcee0STakashi Iwai enum { 211e9edcee0STakashi Iwai AUTO_PIN_MIC, 212e9edcee0STakashi Iwai AUTO_PIN_FRONT_MIC, 213e9edcee0STakashi Iwai AUTO_PIN_LINE, 214e9edcee0STakashi Iwai AUTO_PIN_FRONT_LINE, 215e9edcee0STakashi Iwai AUTO_PIN_CD, 216e9edcee0STakashi Iwai AUTO_PIN_AUX, 217e9edcee0STakashi Iwai AUTO_PIN_LAST 218e9edcee0STakashi Iwai }; 219e9edcee0STakashi Iwai 2204a471b7dSTakashi Iwai extern const char *auto_pin_cfg_labels[AUTO_PIN_LAST]; 2214a471b7dSTakashi Iwai 222e9edcee0STakashi Iwai struct auto_pin_cfg { 223e9edcee0STakashi Iwai int line_outs; 224df694daaSKailang Yang hda_nid_t line_out_pins[5]; /* sorted in the order of Front/Surr/CLFE/Side */ 225*82bc955fSTakashi Iwai int speaker_outs; 226*82bc955fSTakashi Iwai hda_nid_t speaker_pins[5]; 227e9edcee0STakashi Iwai hda_nid_t hp_pin; 228e9edcee0STakashi Iwai hda_nid_t input_pins[AUTO_PIN_LAST]; 229e9edcee0STakashi Iwai hda_nid_t dig_out_pin; 230e9edcee0STakashi Iwai hda_nid_t dig_in_pin; 231e9edcee0STakashi Iwai }; 232e9edcee0STakashi Iwai 233e9edcee0STakashi Iwai #define get_defcfg_connect(cfg) ((cfg & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT) 234e9edcee0STakashi Iwai #define get_defcfg_association(cfg) ((cfg & AC_DEFCFG_DEF_ASSOC) >> AC_DEFCFG_ASSOC_SHIFT) 235e9edcee0STakashi Iwai #define get_defcfg_location(cfg) ((cfg & AC_DEFCFG_LOCATION) >> AC_DEFCFG_LOCATION_SHIFT) 236e9edcee0STakashi Iwai #define get_defcfg_sequence(cfg) (cfg & AC_DEFCFG_SEQUENCE) 237e9edcee0STakashi Iwai #define get_defcfg_device(cfg) ((cfg & AC_DEFCFG_DEVICE) >> AC_DEFCFG_DEVICE_SHIFT) 238e9edcee0STakashi Iwai 239df694daaSKailang Yang int snd_hda_parse_pin_def_config(struct hda_codec *codec, struct auto_pin_cfg *cfg, 240df694daaSKailang Yang hda_nid_t *ignore_nids); 241e9edcee0STakashi Iwai 2428d88bc3dSTakashi Iwai /* amp values */ 2438d88bc3dSTakashi Iwai #define AMP_IN_MUTE(idx) (0x7080 | ((idx)<<8)) 2448d88bc3dSTakashi Iwai #define AMP_IN_UNMUTE(idx) (0x7000 | ((idx)<<8)) 2458d88bc3dSTakashi Iwai #define AMP_OUT_MUTE 0xb080 2468d88bc3dSTakashi Iwai #define AMP_OUT_UNMUTE 0xb000 2478d88bc3dSTakashi Iwai #define AMP_OUT_ZERO 0xb000 2488d88bc3dSTakashi Iwai /* pinctl values */ 2498d88bc3dSTakashi Iwai #define PIN_IN 0x20 2508d88bc3dSTakashi Iwai #define PIN_VREF80 0x24 2518d88bc3dSTakashi Iwai #define PIN_VREF50 0x21 2528d88bc3dSTakashi Iwai #define PIN_OUT 0x40 2538d88bc3dSTakashi Iwai #define PIN_HP 0xc0 2548d88bc3dSTakashi Iwai #define PIN_HP_AMP 0x80 2558d88bc3dSTakashi Iwai 25654d17403STakashi Iwai /* 25754d17403STakashi Iwai * get widget capabilities 25854d17403STakashi Iwai */ 25954d17403STakashi Iwai static inline u32 get_wcaps(struct hda_codec *codec, hda_nid_t nid) 26054d17403STakashi Iwai { 26154d17403STakashi Iwai if (nid < codec->start_nid || 26254d17403STakashi Iwai nid >= codec->start_nid + codec->num_nodes) 26354d17403STakashi Iwai return snd_hda_param_read(codec, nid, AC_PAR_AUDIO_WIDGET_CAP); 26454d17403STakashi Iwai return codec->wcaps[nid - codec->start_nid]; 26554d17403STakashi Iwai } 26654d17403STakashi Iwai 26754d17403STakashi Iwai 2681da177e4SLinus Torvalds #endif /* __SOUND_HDA_LOCAL_H */ 269