xref: /openbmc/linux/sound/pci/hda/hda_local.h (revision e9edcee061a80181f0d6e7cada07e1898c14718e)
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))
301da177e4SLinus Torvalds #define HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \
311da177e4SLinus Torvalds 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx,  \
321da177e4SLinus Torvalds 	  .info = snd_hda_mixer_amp_volume_info, \
331da177e4SLinus Torvalds 	  .get = snd_hda_mixer_amp_volume_get, \
341da177e4SLinus Torvalds 	  .put = snd_hda_mixer_amp_volume_put, \
351da177e4SLinus Torvalds 	  .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, direction) }
361da177e4SLinus Torvalds #define HDA_CODEC_VOLUME_IDX(xname, xcidx, nid, xindex, direction) \
371da177e4SLinus Torvalds 	HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, 3, xindex, direction)
381da177e4SLinus Torvalds #define HDA_CODEC_VOLUME_MONO(xname, nid, channel, xindex, direction) \
391da177e4SLinus Torvalds 	HDA_CODEC_VOLUME_MONO_IDX(xname, 0, nid, channel, xindex, direction)
401da177e4SLinus Torvalds #define HDA_CODEC_VOLUME(xname, nid, xindex, direction) \
411da177e4SLinus Torvalds 	HDA_CODEC_VOLUME_MONO(xname, nid, 3, xindex, direction)
421da177e4SLinus Torvalds #define HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \
431da177e4SLinus Torvalds 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \
441da177e4SLinus Torvalds 	  .info = snd_hda_mixer_amp_switch_info, \
451da177e4SLinus Torvalds 	  .get = snd_hda_mixer_amp_switch_get, \
461da177e4SLinus Torvalds 	  .put = snd_hda_mixer_amp_switch_put, \
471da177e4SLinus Torvalds 	  .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, direction) }
481da177e4SLinus Torvalds #define HDA_CODEC_MUTE_IDX(xname, xcidx, nid, xindex, direction) \
491da177e4SLinus Torvalds 	HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, 3, xindex, direction)
501da177e4SLinus Torvalds #define HDA_CODEC_MUTE_MONO(xname, nid, channel, xindex, direction) \
511da177e4SLinus Torvalds 	HDA_CODEC_MUTE_MONO_IDX(xname, 0, nid, channel, xindex, direction)
521da177e4SLinus Torvalds #define HDA_CODEC_MUTE(xname, nid, xindex, direction) \
531da177e4SLinus Torvalds 	HDA_CODEC_MUTE_MONO(xname, nid, 3, xindex, direction)
541da177e4SLinus Torvalds 
551da177e4SLinus Torvalds int snd_hda_mixer_amp_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo);
561da177e4SLinus Torvalds int snd_hda_mixer_amp_volume_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol);
571da177e4SLinus Torvalds int snd_hda_mixer_amp_volume_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol);
581da177e4SLinus Torvalds int snd_hda_mixer_amp_switch_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo);
591da177e4SLinus Torvalds int snd_hda_mixer_amp_switch_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol);
601da177e4SLinus Torvalds int snd_hda_mixer_amp_switch_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol);
611da177e4SLinus Torvalds 
621da177e4SLinus Torvalds int snd_hda_create_spdif_out_ctls(struct hda_codec *codec, hda_nid_t nid);
631da177e4SLinus Torvalds int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid);
641da177e4SLinus Torvalds 
651da177e4SLinus Torvalds /*
661da177e4SLinus Torvalds  * input MUX helper
671da177e4SLinus Torvalds  */
681da177e4SLinus Torvalds #define HDA_MAX_NUM_INPUTS	8
691da177e4SLinus Torvalds struct hda_input_mux_item {
701da177e4SLinus Torvalds 	const char *label;
711da177e4SLinus Torvalds 	unsigned int index;
721da177e4SLinus Torvalds };
731da177e4SLinus Torvalds struct hda_input_mux {
741da177e4SLinus Torvalds 	unsigned int num_items;
751da177e4SLinus Torvalds 	struct hda_input_mux_item items[HDA_MAX_NUM_INPUTS];
761da177e4SLinus Torvalds };
771da177e4SLinus Torvalds 
781da177e4SLinus Torvalds int snd_hda_input_mux_info(const struct hda_input_mux *imux, snd_ctl_elem_info_t *uinfo);
791da177e4SLinus Torvalds int snd_hda_input_mux_put(struct hda_codec *codec, const struct hda_input_mux *imux,
801da177e4SLinus Torvalds 			  snd_ctl_elem_value_t *ucontrol, hda_nid_t nid,
811da177e4SLinus Torvalds 			  unsigned int *cur_val);
821da177e4SLinus Torvalds 
831da177e4SLinus Torvalds /*
841da177e4SLinus Torvalds  * Multi-channel / digital-out PCM helper
851da177e4SLinus Torvalds  */
861da177e4SLinus Torvalds 
871da177e4SLinus Torvalds enum { HDA_FRONT, HDA_REAR, HDA_CLFE, HDA_SIDE }; /* index for dac_nidx */
881da177e4SLinus Torvalds enum { HDA_DIG_NONE, HDA_DIG_EXCLUSIVE, HDA_DIG_ANALOG_DUP }; /* dig_out_used */
891da177e4SLinus Torvalds 
901da177e4SLinus Torvalds struct hda_multi_out {
911da177e4SLinus Torvalds 	int num_dacs;		/* # of DACs, must be more than 1 */
921da177e4SLinus Torvalds 	hda_nid_t *dac_nids;	/* DAC list */
931da177e4SLinus Torvalds 	hda_nid_t hp_nid;	/* optional DAC for HP, 0 when not exists */
941da177e4SLinus Torvalds 	hda_nid_t dig_out_nid;	/* digital out audio widget */
951da177e4SLinus Torvalds 	int max_channels;	/* currently supported analog channels */
961da177e4SLinus Torvalds 	int dig_out_used;	/* current usage of digital out (HDA_DIG_XXX) */
971da177e4SLinus Torvalds };
981da177e4SLinus Torvalds 
991da177e4SLinus Torvalds int snd_hda_multi_out_dig_open(struct hda_codec *codec, struct hda_multi_out *mout);
1001da177e4SLinus Torvalds int snd_hda_multi_out_dig_close(struct hda_codec *codec, struct hda_multi_out *mout);
1011da177e4SLinus Torvalds int snd_hda_multi_out_analog_open(struct hda_codec *codec, struct hda_multi_out *mout,
1021da177e4SLinus Torvalds 				  snd_pcm_substream_t *substream);
1031da177e4SLinus Torvalds int snd_hda_multi_out_analog_prepare(struct hda_codec *codec, struct hda_multi_out *mout,
1041da177e4SLinus Torvalds 				     unsigned int stream_tag,
1051da177e4SLinus Torvalds 				     unsigned int format,
1061da177e4SLinus Torvalds 				     snd_pcm_substream_t *substream);
1071da177e4SLinus Torvalds int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec, struct hda_multi_out *mout);
1081da177e4SLinus Torvalds 
1091da177e4SLinus Torvalds /*
1101da177e4SLinus Torvalds  * generic codec parser
1111da177e4SLinus Torvalds  */
1121da177e4SLinus Torvalds int snd_hda_parse_generic_codec(struct hda_codec *codec);
1131da177e4SLinus Torvalds 
1141da177e4SLinus Torvalds /*
1151da177e4SLinus Torvalds  * generic proc interface
1161da177e4SLinus Torvalds  */
1171da177e4SLinus Torvalds #ifdef CONFIG_PROC_FS
1181da177e4SLinus Torvalds int snd_hda_codec_proc_new(struct hda_codec *codec);
1191da177e4SLinus Torvalds #else
1201da177e4SLinus Torvalds static inline int snd_hda_codec_proc_new(struct hda_codec *codec) { return 0; }
1211da177e4SLinus Torvalds #endif
1221da177e4SLinus Torvalds 
1231da177e4SLinus Torvalds /*
1241da177e4SLinus Torvalds  * Misc
1251da177e4SLinus Torvalds  */
1261da177e4SLinus Torvalds struct hda_board_config {
1271da177e4SLinus Torvalds 	const char *modelname;
1281da177e4SLinus Torvalds 	int config;
1297291548dSTakashi Iwai 	unsigned short pci_subvendor;
1307291548dSTakashi Iwai 	unsigned short pci_subdevice;
1311da177e4SLinus Torvalds };
1321da177e4SLinus Torvalds 
133*e9edcee0STakashi Iwai int snd_hda_check_board_config(struct hda_codec *codec, const struct hda_board_config *tbl);
1341da177e4SLinus Torvalds int snd_hda_add_new_ctls(struct hda_codec *codec, snd_kcontrol_new_t *knew);
1351da177e4SLinus Torvalds 
1361da177e4SLinus Torvalds /*
1371da177e4SLinus Torvalds  * power management
1381da177e4SLinus Torvalds  */
1391da177e4SLinus Torvalds #ifdef CONFIG_PM
1401da177e4SLinus Torvalds int snd_hda_resume_ctls(struct hda_codec *codec, snd_kcontrol_new_t *knew);
1411da177e4SLinus Torvalds int snd_hda_resume_spdif_out(struct hda_codec *codec);
1421da177e4SLinus Torvalds int snd_hda_resume_spdif_in(struct hda_codec *codec);
1431da177e4SLinus Torvalds #endif
1441da177e4SLinus Torvalds 
1451da177e4SLinus Torvalds /*
1461da177e4SLinus Torvalds  * unsolicited event handler
1471da177e4SLinus Torvalds  */
1481da177e4SLinus Torvalds 
1491da177e4SLinus Torvalds #define HDA_UNSOL_QUEUE_SIZE	64
1501da177e4SLinus Torvalds 
1511da177e4SLinus Torvalds struct hda_bus_unsolicited {
1521da177e4SLinus Torvalds 	/* ring buffer */
1531da177e4SLinus Torvalds 	u32 queue[HDA_UNSOL_QUEUE_SIZE * 2];
1541da177e4SLinus Torvalds 	unsigned int rp, wp;
1551da177e4SLinus Torvalds 
1561da177e4SLinus Torvalds 	/* workqueue */
1571da177e4SLinus Torvalds 	struct workqueue_struct *workq;
1581da177e4SLinus Torvalds 	struct work_struct work;
1591da177e4SLinus Torvalds };
1601da177e4SLinus Torvalds 
161*e9edcee0STakashi Iwai /*
162*e9edcee0STakashi Iwai  * Helper for automatic ping configuration
163*e9edcee0STakashi Iwai  */
164*e9edcee0STakashi Iwai 
165*e9edcee0STakashi Iwai enum {
166*e9edcee0STakashi Iwai 	AUTO_PIN_MIC,
167*e9edcee0STakashi Iwai 	AUTO_PIN_FRONT_MIC,
168*e9edcee0STakashi Iwai 	AUTO_PIN_LINE,
169*e9edcee0STakashi Iwai 	AUTO_PIN_FRONT_LINE,
170*e9edcee0STakashi Iwai 	AUTO_PIN_CD,
171*e9edcee0STakashi Iwai 	AUTO_PIN_AUX,
172*e9edcee0STakashi Iwai 	AUTO_PIN_LAST
173*e9edcee0STakashi Iwai };
174*e9edcee0STakashi Iwai 
175*e9edcee0STakashi Iwai struct auto_pin_cfg {
176*e9edcee0STakashi Iwai 	int line_outs;
177*e9edcee0STakashi Iwai 	hda_nid_t line_out_pins[4]; /* sorted in the order of Front/Surr/CLFE/Side */
178*e9edcee0STakashi Iwai 	hda_nid_t hp_pin;
179*e9edcee0STakashi Iwai 	hda_nid_t input_pins[AUTO_PIN_LAST];
180*e9edcee0STakashi Iwai 	hda_nid_t dig_out_pin;
181*e9edcee0STakashi Iwai 	hda_nid_t dig_in_pin;
182*e9edcee0STakashi Iwai };
183*e9edcee0STakashi Iwai 
184*e9edcee0STakashi Iwai #define get_defcfg_connect(cfg) ((cfg & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT)
185*e9edcee0STakashi Iwai #define get_defcfg_association(cfg) ((cfg & AC_DEFCFG_DEF_ASSOC) >> AC_DEFCFG_ASSOC_SHIFT)
186*e9edcee0STakashi Iwai #define get_defcfg_location(cfg) ((cfg & AC_DEFCFG_LOCATION) >> AC_DEFCFG_LOCATION_SHIFT)
187*e9edcee0STakashi Iwai #define get_defcfg_sequence(cfg) (cfg & AC_DEFCFG_SEQUENCE)
188*e9edcee0STakashi Iwai #define get_defcfg_device(cfg) ((cfg & AC_DEFCFG_DEVICE) >> AC_DEFCFG_DEVICE_SHIFT)
189*e9edcee0STakashi Iwai 
190*e9edcee0STakashi Iwai int snd_hda_parse_pin_def_config(struct hda_codec *codec, struct auto_pin_cfg *cfg);
191*e9edcee0STakashi Iwai 
1921da177e4SLinus Torvalds #endif /* __SOUND_HDA_LOCAL_H */
193