| 1 |
// SPDX-License-Identifier: GPL-2.0-or-later |
| 2 |
// |
| 3 |
// Realtek HD-audio codec support code |
| 4 |
// |
| 5 |
|
| 6 |
#ifndef __HDA_REALTEK_H |
| 7 |
#define __HDA_REALTEK_H |
| 8 |
|
| 9 |
#include <linux/acpi.h> |
| 10 |
#include <linux/cleanup.h> |
| 11 |
#include <linux/init.h> |
| 12 |
#include <linux/delay.h> |
| 13 |
#include <linux/slab.h> |
| 14 |
#include <linux/pci.h> |
| 15 |
#include <linux/dmi.h> |
| 16 |
#include <linux/module.h> |
| 17 |
#include <linux/i2c.h> |
| 18 |
#include <linux/input.h> |
| 19 |
#include <linux/leds.h> |
| 20 |
#include <linux/ctype.h> |
| 21 |
#include <linux/spi/spi.h> |
| 22 |
#include <sound/core.h> |
| 23 |
#include <sound/jack.h> |
| 24 |
#include <sound/hda_codec.h> |
| 25 |
#include "hda_local.h" |
| 26 |
#include "hda_auto_parser.h" |
| 27 |
#include "hda_beep.h" |
| 28 |
#include "hda_jack.h" |
| 29 |
#include "../generic.h" |
| 30 |
#include "../side-codecs/hda_component.h" |
| 31 |
|
| 32 |
/* extra amp-initialization sequence types */ |
| 33 |
enum { |
| 34 |
ALC_INIT_UNDEFINED, |
| 35 |
ALC_INIT_NONE, |
| 36 |
ALC_INIT_DEFAULT, |
| 37 |
}; |
| 38 |
|
| 39 |
enum { |
| 40 |
ALC_HEADSET_MODE_UNKNOWN, |
| 41 |
ALC_HEADSET_MODE_UNPLUGGED, |
| 42 |
ALC_HEADSET_MODE_HEADSET, |
| 43 |
ALC_HEADSET_MODE_MIC, |
| 44 |
ALC_HEADSET_MODE_HEADPHONE, |
| 45 |
}; |
| 46 |
|
| 47 |
enum { |
| 48 |
ALC_HEADSET_TYPE_UNKNOWN, |
| 49 |
ALC_HEADSET_TYPE_CTIA, |
| 50 |
ALC_HEADSET_TYPE_OMTP, |
| 51 |
}; |
| 52 |
|
| 53 |
enum { |
| 54 |
ALC_KEY_MICMUTE_INDEX, |
| 55 |
}; |
| 56 |
|
| 57 |
struct alc_customize_define { |
| 58 |
unsigned int sku_cfg; |
| 59 |
unsigned char port_connectivity; |
| 60 |
unsigned char check_sum; |
| 61 |
unsigned char customization; |
| 62 |
unsigned char external_amp; |
| 63 |
unsigned int enable_pcbeep:1; |
| 64 |
unsigned int platform_type:1; |
| 65 |
unsigned int swap:1; |
| 66 |
unsigned int override:1; |
| 67 |
unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */ |
| 68 |
}; |
| 69 |
|
| 70 |
struct alc_coef_led { |
| 71 |
unsigned int idx; |
| 72 |
unsigned int mask; |
| 73 |
unsigned int on; |
| 74 |
unsigned int off; |
| 75 |
}; |
| 76 |
|
| 77 |
struct alc_spec { |
| 78 |
struct hda_gen_spec gen; /* must be at head */ |
| 79 |
|
| 80 |
/* codec parameterization */ |
| 81 |
struct alc_customize_define cdefine; |
| 82 |
unsigned int parse_flags; /* flag for snd_hda_parse_pin_defcfg() */ |
| 83 |
|
| 84 |
/* GPIO bits */ |
| 85 |
unsigned int gpio_mask; |
| 86 |
unsigned int gpio_dir; |
| 87 |
unsigned int gpio_data; |
| 88 |
bool gpio_write_delay; /* add a delay before writing gpio_data */ |
| 89 |
|
| 90 |
/* mute LED for HP laptops, see vref_mute_led_set() */ |
| 91 |
int mute_led_polarity; |
| 92 |
int micmute_led_polarity; |
| 93 |
hda_nid_t mute_led_nid; |
| 94 |
hda_nid_t cap_mute_led_nid; |
| 95 |
|
| 96 |
unsigned int gpio_mute_led_mask; |
| 97 |
unsigned int gpio_mic_led_mask; |
| 98 |
struct alc_coef_led mute_led_coef; |
| 99 |
struct alc_coef_led mic_led_coef; |
| 100 |
struct mutex coef_mutex; |
| 101 |
|
| 102 |
hda_nid_t headset_mic_pin; |
| 103 |
hda_nid_t headphone_mic_pin; |
| 104 |
int current_headset_mode; |
| 105 |
int current_headset_type; |
| 106 |
|
| 107 |
/* hooks */ |
| 108 |
void (*init_hook)(struct hda_codec *codec); |
| 109 |
void (*power_hook)(struct hda_codec *codec); |
| 110 |
void (*shutup)(struct hda_codec *codec); |
| 111 |
|
| 112 |
int init_amp; |
| 113 |
int codec_variant; /* flag for other variants */ |
| 114 |
unsigned int has_alc5505_dsp:1; |
| 115 |
unsigned int no_depop_delay:1; |
| 116 |
unsigned int done_hp_init:1; |
| 117 |
unsigned int no_shutup_pins:1; |
| 118 |
unsigned int ultra_low_power:1; |
| 119 |
unsigned int has_hs_key:1; |
| 120 |
unsigned int no_internal_mic_pin:1; |
| 121 |
unsigned int en_3kpull_low:1; |
| 122 |
int num_speaker_amps; |
| 123 |
|
| 124 |
/* for PLL fix */ |
| 125 |
hda_nid_t pll_nid; |
| 126 |
unsigned int pll_coef_idx, pll_coef_bit; |
| 127 |
unsigned int coef0; |
| 128 |
struct input_dev *kb_dev; |
| 129 |
u8 alc_mute_keycode_map[1]; |
| 130 |
|
| 131 |
/* component binding */ |
| 132 |
struct hda_component_parent comps; |
| 133 |
}; |
| 134 |
|
| 135 |
int alc_read_coefex_idx(struct hda_codec *codec, hda_nid_t nid, |
| 136 |
unsigned int coef_idx); |
| 137 |
void alc_write_coefex_idx(struct hda_codec *codec, hda_nid_t nid, |
| 138 |
unsigned int coef_idx, unsigned int coef_val); |
| 139 |
void alc_update_coefex_idx(struct hda_codec *codec, hda_nid_t nid, |
| 140 |
unsigned int coef_idx, unsigned int mask, |
| 141 |
unsigned int bits_set); |
| 142 |
#define alc_read_coef_idx(codec, coef_idx) \ |
| 143 |
alc_read_coefex_idx(codec, 0x20, coef_idx) |
| 144 |
#define alc_write_coef_idx(codec, coef_idx, coef_val) \ |
| 145 |
alc_write_coefex_idx(codec, 0x20, coef_idx, coef_val) |
| 146 |
#define alc_update_coef_idx(codec, coef_idx, mask, bits_set) \ |
| 147 |
alc_update_coefex_idx(codec, 0x20, coef_idx, mask, bits_set) |
| 148 |
|
| 149 |
unsigned int alc_get_coef0(struct hda_codec *codec); |
| 150 |
|
| 151 |
/* coef writes/updates batch */ |
| 152 |
struct coef_fw { |
| 153 |
unsigned char nid; |
| 154 |
unsigned char idx; |
| 155 |
unsigned short mask; |
| 156 |
unsigned short val; |
| 157 |
}; |
| 158 |
|
| 159 |
#define UPDATE_COEFEX(_nid, _idx, _mask, _val) \ |
| 160 |
{ .nid = (_nid), .idx = (_idx), .mask = (_mask), .val = (_val) } |
| 161 |
#define WRITE_COEFEX(_nid, _idx, _val) UPDATE_COEFEX(_nid, _idx, -1, _val) |
| 162 |
#define WRITE_COEF(_idx, _val) WRITE_COEFEX(0x20, _idx, _val) |
| 163 |
#define UPDATE_COEF(_idx, _mask, _val) UPDATE_COEFEX(0x20, _idx, _mask, _val) |
| 164 |
|
| 165 |
void alc_process_coef_fw(struct hda_codec *codec, const struct coef_fw *fw); |
| 166 |
|
| 167 |
/* |
| 168 |
* GPIO helpers |
| 169 |
*/ |
| 170 |
void alc_setup_gpio(struct hda_codec *codec, unsigned int mask); |
| 171 |
void alc_write_gpio_data(struct hda_codec *codec); |
| 172 |
void alc_update_gpio_data(struct hda_codec *codec, unsigned int mask, |
| 173 |
bool on); |
| 174 |
void alc_write_gpio(struct hda_codec *codec); |
| 175 |
|
| 176 |
/* common GPIO fixups */ |
| 177 |
void alc_fixup_gpio(struct hda_codec *codec, int action, unsigned int mask); |
| 178 |
void alc_fixup_gpio1(struct hda_codec *codec, |
| 179 |
const struct hda_fixup *fix, int action); |
| 180 |
void alc_fixup_gpio2(struct hda_codec *codec, |
| 181 |
const struct hda_fixup *fix, int action); |
| 182 |
void alc_fixup_gpio3(struct hda_codec *codec, |
| 183 |
const struct hda_fixup *fix, int action); |
| 184 |
void alc_fixup_gpio4(struct hda_codec *codec, |
| 185 |
const struct hda_fixup *fix, int action); |
| 186 |
void alc_fixup_micmute_led(struct hda_codec *codec, |
| 187 |
const struct hda_fixup *fix, int action); |
| 188 |
|
| 189 |
/* |
| 190 |
* Common init code, callbacks and helpers |
| 191 |
*/ |
| 192 |
void alc_fix_pll(struct hda_codec *codec); |
| 193 |
void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid, |
| 194 |
unsigned int coef_idx, unsigned int coef_bit); |
| 195 |
void alc_fill_eapd_coef(struct hda_codec *codec); |
| 196 |
void alc_auto_setup_eapd(struct hda_codec *codec, bool on); |
| 197 |
|
| 198 |
int alc_find_ext_mic_pin(struct hda_codec *codec); |
| 199 |
void alc_headset_mic_no_shutup(struct hda_codec *codec); |
| 200 |
void alc_shutup_pins(struct hda_codec *codec); |
| 201 |
void alc_eapd_shutup(struct hda_codec *codec); |
| 202 |
void alc_auto_init_amp(struct hda_codec *codec, int type); |
| 203 |
hda_nid_t alc_get_hp_pin(struct alc_spec *spec); |
| 204 |
int alc_auto_parse_customize_define(struct hda_codec *codec); |
| 205 |
int alc_subsystem_id(struct hda_codec *codec, const hda_nid_t *ports); |
| 206 |
void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports); |
| 207 |
int alc_build_controls(struct hda_codec *codec); |
| 208 |
void alc_update_knob_master(struct hda_codec *codec, |
| 209 |
struct hda_jack_callback *jack); |
| 210 |
|
| 211 |
static inline void alc_pre_init(struct hda_codec *codec) |
| 212 |
{ |
| 213 |
alc_fill_eapd_coef(codec); |
| 214 |
} |
| 215 |
|
| 216 |
#define is_s3_resume(codec) \ |
| 217 |
((codec)->core.dev.power.power_state.event == PM_EVENT_RESUME) |
| 218 |
#define is_s4_resume(codec) \ |
| 219 |
((codec)->core.dev.power.power_state.event == PM_EVENT_RESTORE) |
| 220 |
#define is_s4_suspend(codec) \ |
| 221 |
((codec)->core.dev.power.power_state.event == PM_EVENT_FREEZE) |
| 222 |
|
| 223 |
int alc_init(struct hda_codec *codec); |
| 224 |
void alc_shutup(struct hda_codec *codec); |
| 225 |
void alc_power_eapd(struct hda_codec *codec); |
| 226 |
int alc_suspend(struct hda_codec *codec); |
| 227 |
int alc_resume(struct hda_codec *codec); |
| 228 |
|
| 229 |
int alc_parse_auto_config(struct hda_codec *codec, |
| 230 |
const hda_nid_t *ignore_nids, |
| 231 |
const hda_nid_t *ssid_nids); |
| 232 |
int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid); |
| 233 |
|
| 234 |
#define alc_codec_rename(codec, name) snd_hda_codec_set_name(codec, name) |
| 235 |
|
| 236 |
#ifdef CONFIG_SND_HDA_INPUT_BEEP |
| 237 |
int alc_set_beep_amp(struct alc_spec *spec, hda_nid_t nid, int idx, int dir); |
| 238 |
int alc_has_cdefine_beep(struct hda_codec *codec); |
| 239 |
#define set_beep_amp alc_set_beep_amp |
| 240 |
#define has_cdefine_beep alc_has_cdefine_beep |
| 241 |
#else |
| 242 |
#define set_beep_amp(spec, nid, idx, dir) 0 |
| 243 |
#define has_cdefine_beep(codec) 0 |
| 244 |
#endif |
| 245 |
|
| 246 |
static inline void rename_ctl(struct hda_codec *codec, const char *oldname, |
| 247 |
const char *newname) |
| 248 |
{ |
| 249 |
struct snd_kcontrol *kctl; |
| 250 |
|
| 251 |
kctl = snd_hda_find_mixer_ctl(codec, oldname); |
| 252 |
if (kctl) |
| 253 |
snd_ctl_rename(codec->card, kctl, newname); |
| 254 |
} |
| 255 |
|
| 256 |
/* Common fixups */ |
| 257 |
void alc_fixup_sku_ignore(struct hda_codec *codec, |
| 258 |
const struct hda_fixup *fix, int action); |
| 259 |
void alc_fixup_no_depop_delay(struct hda_codec *codec, |
| 260 |
const struct hda_fixup *fix, int action); |
| 261 |
void alc_fixup_inv_dmic(struct hda_codec *codec, |
| 262 |
const struct hda_fixup *fix, int action); |
| 263 |
void alc_fixup_dual_codecs(struct hda_codec *codec, |
| 264 |
const struct hda_fixup *fix, int action); |
| 265 |
void alc_fixup_bass_chmap(struct hda_codec *codec, |
| 266 |
const struct hda_fixup *fix, int action); |
| 267 |
void alc_fixup_headset_mode(struct hda_codec *codec, |
| 268 |
const struct hda_fixup *fix, int action); |
| 269 |
void alc_fixup_headset_mode_no_hp_mic(struct hda_codec *codec, |
| 270 |
const struct hda_fixup *fix, int action); |
| 271 |
void alc_fixup_headset_mic(struct hda_codec *codec, |
| 272 |
const struct hda_fixup *fix, int action); |
| 273 |
void alc_update_headset_jack_cb(struct hda_codec *codec, |
| 274 |
struct hda_jack_callback *jack); |
| 275 |
void alc_update_gpio_led(struct hda_codec *codec, unsigned int mask, |
| 276 |
int polarity, bool enabled); |
| 277 |
void alc_fixup_hp_gpio_led(struct hda_codec *codec, |
| 278 |
int action, |
| 279 |
unsigned int mute_mask, |
| 280 |
unsigned int micmute_mask); |
| 281 |
void alc_fixup_no_jack_detect(struct hda_codec *codec, |
| 282 |
const struct hda_fixup *fix, int action); |
| 283 |
void alc_fixup_disable_aamix(struct hda_codec *codec, |
| 284 |
const struct hda_fixup *fix, int action); |
| 285 |
void alc_fixup_auto_mute_via_amp(struct hda_codec *codec, |
| 286 |
const struct hda_fixup *fix, int action); |
| 287 |
|
| 288 |
/* device-specific, but used by multiple codec drivers */ |
| 289 |
void alc1220_fixup_gb_dual_codecs(struct hda_codec *codec, |
| 290 |
const struct hda_fixup *fix, |
| 291 |
int action); |
| 292 |
void alc233_alc662_fixup_lenovo_dual_codecs(struct hda_codec *codec, |
| 293 |
const struct hda_fixup *fix, |
| 294 |
int action); |
| 295 |
void alc_fixup_dell_xps13(struct hda_codec *codec, |
| 296 |
const struct hda_fixup *fix, int action); |
| 297 |
|
| 298 |
/* |
| 299 |
* COEF access helper functions |
| 300 |
*/ |
| 301 |
static inline void coef_mutex_lock(struct hda_codec *codec) |
| 302 |
{ |
| 303 |
struct alc_spec *spec = codec->spec; |
| 304 |
|
| 305 |
snd_hda_power_up_pm(codec); |
| 306 |
mutex_lock(&spec->coef_mutex); |
| 307 |
} |
| 308 |
|
| 309 |
static inline void coef_mutex_unlock(struct hda_codec *codec) |
| 310 |
{ |
| 311 |
struct alc_spec *spec = codec->spec; |
| 312 |
|
| 313 |
mutex_unlock(&spec->coef_mutex); |
| 314 |
snd_hda_power_down_pm(codec); |
| 315 |
} |
| 316 |
|
| 317 |
DEFINE_GUARD(coef_mutex, struct hda_codec *, coef_mutex_lock(_T), coef_mutex_unlock(_T)) |
| 318 |
|
| 319 |
#endif /* __HDA_REALTEK_H */ |