Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * Generic BIOS auto-parser helper functions for HD-audio
0004  *
0005  * Copyright (c) 2012 Takashi Iwai <tiwai@suse.de>
0006  */
0007 
0008 #ifndef __SOUND_HDA_GENERIC_H
0009 #define __SOUND_HDA_GENERIC_H
0010 
0011 #include <linux/leds.h>
0012 
0013 /* table entry for multi-io paths */
0014 struct hda_multi_io {
0015     hda_nid_t pin;      /* multi-io widget pin NID */
0016     hda_nid_t dac;      /* DAC to be connected */
0017     unsigned int ctl_in;    /* cached input-pin control value */
0018 };
0019 
0020 /* Widget connection path
0021  *
0022  * For output, stored in the order of DAC -> ... -> pin,
0023  * for input, pin -> ... -> ADC.
0024  *
0025  * idx[i] contains the source index number to select on of the widget path[i];
0026  * e.g. idx[1] is the index of the DAC (path[0]) selected by path[1] widget
0027  * multi[] indicates whether it's a selector widget with multi-connectors
0028  * (i.e. the connection selection is mandatory)
0029  * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
0030  */
0031 
0032 #define MAX_NID_PATH_DEPTH  10
0033 
0034 enum {
0035     NID_PATH_VOL_CTL,
0036     NID_PATH_MUTE_CTL,
0037     NID_PATH_BOOST_CTL,
0038     NID_PATH_NUM_CTLS
0039 };
0040 
0041 struct nid_path {
0042     int depth;
0043     hda_nid_t path[MAX_NID_PATH_DEPTH];
0044     unsigned char idx[MAX_NID_PATH_DEPTH];
0045     unsigned char multi[MAX_NID_PATH_DEPTH];
0046     unsigned int ctls[NID_PATH_NUM_CTLS]; /* NID_PATH_XXX_CTL */
0047     bool active:1;      /* activated by driver */
0048     bool pin_enabled:1; /* pins are enabled */
0049     bool pin_fixed:1;   /* path with fixed pin */
0050     bool stream_enabled:1;  /* stream is active */
0051 };
0052 
0053 /* mic/line-in auto switching entry */
0054 
0055 #define MAX_AUTO_MIC_PINS   3
0056 
0057 struct automic_entry {
0058     hda_nid_t pin;      /* pin */
0059     int idx;        /* imux index, -1 = invalid */
0060     unsigned int attr;  /* pin attribute (INPUT_PIN_ATTR_*) */
0061 };
0062 
0063 /* active stream id */
0064 enum { STREAM_MULTI_OUT, STREAM_INDEP_HP };
0065 
0066 /* PCM hook action */
0067 enum {
0068     HDA_GEN_PCM_ACT_OPEN,
0069     HDA_GEN_PCM_ACT_PREPARE,
0070     HDA_GEN_PCM_ACT_CLEANUP,
0071     HDA_GEN_PCM_ACT_CLOSE,
0072 };
0073 
0074 /* DAC assignment badness table */
0075 struct badness_table {
0076     int no_primary_dac; /* no primary DAC */
0077     int no_dac;     /* no secondary DACs */
0078     int shared_primary; /* primary DAC is shared with main output */
0079     int shared_surr;    /* secondary DAC shared with main or primary */
0080     int shared_clfe;    /* third DAC shared with main or primary */
0081     int shared_surr_main;   /* secondary DAC sahred with main/DAC0 */
0082 };
0083 
0084 extern const struct badness_table hda_main_out_badness;
0085 extern const struct badness_table hda_extra_out_badness;
0086 
0087 struct hda_gen_spec {
0088     char stream_name_analog[32];    /* analog PCM stream */
0089     const struct hda_pcm_stream *stream_analog_playback;
0090     const struct hda_pcm_stream *stream_analog_capture;
0091 
0092     char stream_name_alt_analog[32]; /* alternative analog PCM stream */
0093     const struct hda_pcm_stream *stream_analog_alt_playback;
0094     const struct hda_pcm_stream *stream_analog_alt_capture;
0095 
0096     char stream_name_digital[32];   /* digital PCM stream */
0097     const struct hda_pcm_stream *stream_digital_playback;
0098     const struct hda_pcm_stream *stream_digital_capture;
0099 
0100     /* PCM */
0101     unsigned int active_streams;
0102     struct mutex pcm_mutex;
0103 
0104     /* playback */
0105     struct hda_multi_out multiout;  /* playback set-up
0106                      * max_channels, dacs must be set
0107                      * dig_out_nid and hp_nid are optional
0108                      */
0109     hda_nid_t alt_dac_nid;
0110     hda_nid_t follower_dig_outs[3]; /* optional - for auto-parsing */
0111     int dig_out_type;
0112 
0113     /* capture */
0114     unsigned int num_adc_nids;
0115     hda_nid_t adc_nids[AUTO_CFG_MAX_INS];
0116     hda_nid_t dig_in_nid;       /* digital-in NID; optional */
0117     hda_nid_t mixer_nid;        /* analog-mixer NID */
0118     hda_nid_t mixer_merge_nid;  /* aamix merge-point NID (optional) */
0119     const char *input_labels[HDA_MAX_NUM_INPUTS];
0120     int input_label_idxs[HDA_MAX_NUM_INPUTS];
0121 
0122     /* capture setup for dynamic dual-adc switch */
0123     hda_nid_t cur_adc;
0124     unsigned int cur_adc_stream_tag;
0125     unsigned int cur_adc_format;
0126 
0127     /* capture source */
0128     struct hda_input_mux input_mux;
0129     unsigned int cur_mux[3];
0130 
0131     /* channel model */
0132     /* min_channel_count contains the minimum channel count for primary
0133      * outputs.  When multi_ios is set, the channels can be configured
0134      * between min_channel_count and (min_channel_count + multi_ios * 2).
0135      *
0136      * ext_channel_count contains the current channel count of the primary
0137      * out.  This varies in the range above.
0138      *
0139      * Meanwhile, const_channel_count is the channel count for all outputs
0140      * including headphone and speakers.  It's a constant value, and the
0141      * PCM is set up as max(ext_channel_count, const_channel_count).
0142      */
0143     int min_channel_count;      /* min. channel count for primary out */
0144     int ext_channel_count;      /* current channel count for primary */
0145     int const_channel_count;    /* channel count for all */
0146 
0147     /* PCM information */
0148     struct hda_pcm *pcm_rec[3]; /* used in build_pcms() */
0149 
0150     /* dynamic controls, init_verbs and input_mux */
0151     struct auto_pin_cfg autocfg;
0152     struct snd_array kctls;
0153     hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
0154     hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
0155     unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
0156     /* shared hp/mic */
0157     hda_nid_t shared_mic_vref_pin;
0158     hda_nid_t hp_mic_pin;
0159     int hp_mic_mux_idx;
0160 
0161     /* DAC/ADC lists */
0162     int num_all_dacs;
0163     hda_nid_t all_dacs[16];
0164     int num_all_adcs;
0165     hda_nid_t all_adcs[AUTO_CFG_MAX_INS];
0166 
0167     /* path list */
0168     struct snd_array paths;
0169 
0170     /* path indices */
0171     int out_paths[AUTO_CFG_MAX_OUTS];
0172     int hp_paths[AUTO_CFG_MAX_OUTS];
0173     int speaker_paths[AUTO_CFG_MAX_OUTS];
0174     int aamix_out_paths[3];
0175     int digout_paths[AUTO_CFG_MAX_OUTS];
0176     int input_paths[HDA_MAX_NUM_INPUTS][AUTO_CFG_MAX_INS];
0177     int loopback_paths[HDA_MAX_NUM_INPUTS];
0178     int loopback_merge_path;
0179     int digin_path;
0180 
0181     /* auto-mic stuff */
0182     int am_num_entries;
0183     struct automic_entry am_entry[MAX_AUTO_MIC_PINS];
0184 
0185     /* for pin sensing */
0186     /* current status; set in hda_generic.c */
0187     unsigned int hp_jack_present:1;
0188     unsigned int line_jack_present:1;
0189     unsigned int speaker_muted:1; /* current status of speaker mute */
0190     unsigned int line_out_muted:1; /* current status of LO mute */
0191 
0192     /* internal states of automute / autoswitch behavior */
0193     unsigned int auto_mic:1;
0194     unsigned int automute_speaker:1; /* automute speaker outputs */
0195     unsigned int automute_lo:1; /* automute LO outputs */
0196 
0197     /* capabilities detected by parser */
0198     unsigned int detect_hp:1;   /* Headphone detection enabled */
0199     unsigned int detect_lo:1;   /* Line-out detection enabled */
0200     unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
0201     unsigned int automute_lo_possible:1;      /* there are line outs and HP */
0202 
0203     /* additional parameters set by codec drivers */
0204     unsigned int master_mute:1; /* master mute over all */
0205     unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
0206     unsigned int line_in_auto_switch:1; /* allow line-in auto switch */
0207     unsigned int auto_mute_via_amp:1; /* auto-mute via amp instead of pinctl */
0208 
0209     /* parser behavior flags; set before snd_hda_gen_parse_auto_config() */
0210     unsigned int suppress_auto_mute:1; /* suppress input jack auto mute */
0211     unsigned int suppress_auto_mic:1; /* suppress input jack auto switch */
0212 
0213     /* other parse behavior flags */
0214     unsigned int need_dac_fix:1; /* need to limit DACs for multi channels */
0215     unsigned int hp_mic:1; /* Allow HP as a mic-in */
0216     unsigned int suppress_hp_mic_detect:1; /* Don't detect HP/mic */
0217     unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */
0218     unsigned int no_multi_io:1; /* Don't try multi I/O config */
0219     unsigned int multi_cap_vol:1; /* allow multiple capture xxx volumes */
0220     unsigned int inv_dmic_split:1; /* inverted dmic w/a for conexant */
0221     unsigned int own_eapd_ctl:1; /* set EAPD by own function */
0222     unsigned int keep_eapd_on:1; /* don't turn off EAPD automatically */
0223     unsigned int vmaster_mute_led:1; /* add SPK-LED flag to vmaster mute switch */
0224     unsigned int mic_mute_led:1; /* add MIC-LED flag to capture mute switch */
0225     unsigned int indep_hp:1; /* independent HP supported */
0226     unsigned int prefer_hp_amp:1; /* enable HP amp for speaker if any */
0227     unsigned int add_stereo_mix_input:2; /* add aamix as a capture src */
0228     unsigned int add_jack_modes:1; /* add i/o jack mode enum ctls */
0229     unsigned int power_down_unused:1; /* power down unused widgets */
0230     unsigned int dac_min_mute:1; /* minimal = mute for DACs */
0231     unsigned int suppress_vmaster:1; /* don't create vmaster kctls */
0232     unsigned int obey_preferred_dacs:1; /* obey preferred_dacs assignment */
0233 
0234     /* other internal flags */
0235     unsigned int no_analog:1; /* digital I/O only */
0236     unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
0237     unsigned int indep_hp_enabled:1; /* independent HP enabled */
0238     unsigned int have_aamix_ctl:1;
0239     unsigned int hp_mic_jack_modes:1;
0240     unsigned int skip_verbs:1; /* don't apply verbs at snd_hda_gen_init() */
0241 
0242     /* additional mute flags (only effective with auto_mute_via_amp=1) */
0243     u64 mute_bits;
0244 
0245     /* bitmask for skipping volume controls */
0246     u64 out_vol_mask;
0247 
0248     /* badness tables for output path evaluations */
0249     const struct badness_table *main_out_badness;
0250     const struct badness_table *extra_out_badness;
0251 
0252     /* preferred pin/DAC pairs; an array of paired NIDs */
0253     const hda_nid_t *preferred_dacs;
0254 
0255     /* loopback mixing mode */
0256     bool aamix_mode;
0257 
0258     /* digital beep */
0259     hda_nid_t beep_nid;
0260 
0261     /* for virtual master */
0262     hda_nid_t vmaster_nid;
0263     unsigned int vmaster_tlv[4];
0264     struct hda_vmaster_mute_hook vmaster_mute;
0265 
0266     struct hda_loopback_check loopback;
0267     struct snd_array loopback_list;
0268 
0269     /* multi-io */
0270     int multi_ios;
0271     struct hda_multi_io multi_io[4];
0272 
0273     /* hooks */
0274     void (*init_hook)(struct hda_codec *codec);
0275     void (*automute_hook)(struct hda_codec *codec);
0276     void (*cap_sync_hook)(struct hda_codec *codec,
0277                   struct snd_kcontrol *kcontrol,
0278                   struct snd_ctl_elem_value *ucontrol);
0279 
0280     /* PCM hooks */
0281     void (*pcm_playback_hook)(struct hda_pcm_stream *hinfo,
0282                   struct hda_codec *codec,
0283                   struct snd_pcm_substream *substream,
0284                   int action);
0285     void (*pcm_capture_hook)(struct hda_pcm_stream *hinfo,
0286                  struct hda_codec *codec,
0287                  struct snd_pcm_substream *substream,
0288                  int action);
0289 
0290     /* automute / autoswitch hooks */
0291     void (*hp_automute_hook)(struct hda_codec *codec,
0292                  struct hda_jack_callback *cb);
0293     void (*line_automute_hook)(struct hda_codec *codec,
0294                    struct hda_jack_callback *cb);
0295     void (*mic_autoswitch_hook)(struct hda_codec *codec,
0296                     struct hda_jack_callback *cb);
0297 
0298     /* leds */
0299     struct led_classdev *led_cdevs[NUM_AUDIO_LEDS];
0300 };
0301 
0302 /* values for add_stereo_mix_input flag */
0303 enum {
0304     HDA_HINT_STEREO_MIX_DISABLE,    /* No stereo mix input */
0305     HDA_HINT_STEREO_MIX_ENABLE, /* Add stereo mix input */
0306     HDA_HINT_STEREO_MIX_AUTO,   /* Add only if auto-mic is disabled */
0307 };
0308 
0309 int snd_hda_gen_spec_init(struct hda_gen_spec *spec);
0310 
0311 int snd_hda_gen_init(struct hda_codec *codec);
0312 void snd_hda_gen_free(struct hda_codec *codec);
0313 
0314 int snd_hda_get_path_idx(struct hda_codec *codec, struct nid_path *path);
0315 struct nid_path *snd_hda_get_path_from_idx(struct hda_codec *codec, int idx);
0316 struct nid_path *
0317 snd_hda_add_new_path(struct hda_codec *codec, hda_nid_t from_nid,
0318              hda_nid_t to_nid, int anchor_nid);
0319 void snd_hda_activate_path(struct hda_codec *codec, struct nid_path *path,
0320                bool enable, bool add_aamix);
0321 
0322 struct snd_kcontrol_new *
0323 snd_hda_gen_add_kctl(struct hda_gen_spec *spec, const char *name,
0324              const struct snd_kcontrol_new *temp);
0325 
0326 int snd_hda_gen_parse_auto_config(struct hda_codec *codec,
0327                   struct auto_pin_cfg *cfg);
0328 int snd_hda_gen_build_controls(struct hda_codec *codec);
0329 int snd_hda_gen_build_pcms(struct hda_codec *codec);
0330 
0331 /* standard jack event callbacks */
0332 void snd_hda_gen_hp_automute(struct hda_codec *codec,
0333                  struct hda_jack_callback *jack);
0334 void snd_hda_gen_line_automute(struct hda_codec *codec,
0335                    struct hda_jack_callback *jack);
0336 void snd_hda_gen_mic_autoswitch(struct hda_codec *codec,
0337                 struct hda_jack_callback *jack);
0338 void snd_hda_gen_update_outputs(struct hda_codec *codec);
0339 
0340 #ifdef CONFIG_PM
0341 int snd_hda_gen_check_power_status(struct hda_codec *codec, hda_nid_t nid);
0342 #endif
0343 unsigned int snd_hda_gen_path_power_filter(struct hda_codec *codec,
0344                        hda_nid_t nid,
0345                        unsigned int power_state);
0346 void snd_hda_gen_stream_pm(struct hda_codec *codec, hda_nid_t nid, bool on);
0347 int snd_hda_gen_fix_pin_power(struct hda_codec *codec, hda_nid_t pin);
0348 
0349 int snd_hda_gen_add_mute_led_cdev(struct hda_codec *codec,
0350                   int (*callback)(struct led_classdev *,
0351                           enum led_brightness));
0352 int snd_hda_gen_add_micmute_led_cdev(struct hda_codec *codec,
0353                      int (*callback)(struct led_classdev *,
0354                              enum led_brightness));
0355 
0356 #endif /* __SOUND_HDA_GENERIC_H */