25 #include <linux/slab.h>
26 #include <linux/pci.h>
28 #include <linux/module.h>
40 #define CREATE_TRACE_POINTS
55 { 0x1013,
"Cirrus Logic" },
56 { 0x1057,
"Motorola" },
57 { 0x1095,
"Silicon Image" },
59 { 0x10ec,
"Realtek" },
60 { 0x1102,
"Creative" },
64 { 0x11d4,
"Analog Devices" },
65 { 0x13f6,
"C-Media" },
66 { 0x14f1,
"Conexant" },
67 { 0x17e8,
"Chrontel" },
69 { 0x1aec,
"Wolfson Microelectronics" },
70 { 0x434d,
"C-Media" },
72 { 0x8384,
"SigmaTel" },
98 #define codec_in_pm(codec) ((codec)->in_pm)
101 #define hda_codec_is_power_on(codec) ((codec)->power_on)
104 if (bus->
ops.pm_notify)
105 bus->
ops.pm_notify(bus, power_up);
108 #define codec_in_pm(codec) 0
110 #define hda_codec_is_power_on(codec) 1
111 #define hda_call_pm_notify(bus, state) {}
123 static char *bases[7] = {
124 "N/A",
"Rear",
"Front",
"Left",
"Right",
"Top",
"Bottom",
126 static unsigned char specials_idx[] = {
131 static char *specials[] = {
132 "Rear Panel",
"Drive Bar",
133 "Riser",
"HDMI",
"ATAPI",
134 "Mobile-In",
"Mobile-Out"
138 if ((cfg & 0x0f) < 7)
139 return bases[cfg & 0x0f];
140 for (i = 0; i <
ARRAY_SIZE(specials_idx); i++) {
141 if (cfg == specials_idx[i])
157 static char *jack_locations[4] = {
"Ext",
"Int",
"Sep",
"Oth" };
172 static char *jack_types[16] = {
173 "Line Out",
"Speaker",
"HP Out",
"CD",
174 "SPDIF Out",
"Digital Out",
"Modem Line",
"Modem Hand",
175 "Line In",
"Aux",
"Mic",
"Telephony",
176 "SPDIF In",
"Digitial In",
"Reserved",
"Other"
187 static inline unsigned int
189 unsigned int verb,
unsigned int parm)
193 if ((codec->
addr & ~0xf) || (direct & ~1) || (nid & ~0x7f) ||
194 (verb & ~0xfff) || (parm & ~0xffff)) {
196 codec->
addr, direct, nid, verb, parm);
201 val |= (
u32)direct << 27;
202 val |= (
u32)nid << 20;
211 static int codec_exec_verb(
struct hda_codec *codec,
unsigned int cmd,
223 snd_hda_power_up(codec);
225 trace_hda_send_cmd(codec, cmd);
226 err = bus->
ops.command(bus, cmd);
228 *res = bus->
ops.get_response(bus, codec->
addr);
229 trace_hda_get_response(codec, *res);
232 snd_hda_power_down(codec);
236 "fatal communication error\n");
237 trace_hda_bus_reset(bus);
238 bus->
ops.bus_reset(bus);
262 unsigned int verb,
unsigned int parm)
264 unsigned cmd = make_codec_cmd(codec, nid, direct, verb, parm);
266 if (codec_exec_verb(codec, cmd, &res))
285 unsigned int verb,
unsigned int parm)
287 unsigned int cmd = make_codec_cmd(codec, nid, direct, verb, parm);
289 return codec_exec_verb(codec, cmd,
290 codec->
bus->sync_write ? &res :
NULL);
304 for (; seq->
nid; seq++)
326 *start_id = (parm >> 16) & 0x7fff;
327 return (
int)(parm & 0x7fff);
335 for (i = 0; i < array->
used; ) {
381 p = lookup_conn_list(array, nid);
384 if (conn_list && len > max_conns) {
386 "Too many connections %d for NID 0x%x\n",
391 if (conn_list && len)
400 len = read_and_add_raw_conns(codec, nid);
423 int i, conn_len, conns;
431 wcaps = get_wcaps(codec, nid);
447 mask = (1 << (shift-1)) - 1;
456 if (parm == -1 && codec->
bus->rirb_error)
458 conn_list[0] = parm &
mask;
465 for (i = 0; i < conn_len; i++) {
469 if (i % num_elems == 0) {
472 if (parm == -1 && codec->
bus->rirb_error)
475 range_val = !!(parm & (1 << (shift-1)));
479 "invalid CONNECT_LIST verb %x[%i]:%x\n",
486 if (!prev_nid || prev_nid >= val) {
488 "invalid dep_range_val %x:%x\n",
492 for (n = prev_nid + 1; n <=
val; n++) {
493 if (conns >= max_conns) {
495 "Too many connections %d for NID 0x%x\n",
499 conn_list[conns++] =
n;
502 if (conns >= max_conns) {
504 "Too many connections %d for NID 0x%x\n",
508 conn_list[conns++] =
val;
544 p = lookup_conn_list(array, nid);
548 old_used = array->
used;
549 if (!add_conn_list(array, nid) || !add_conn_list(array, len))
551 for (i = 0; i < len; i++)
552 if (!add_conn_list(array, list[i]))
558 array->
used = old_used;
582 for (i = 0; i < nums; i++)
588 snd_printd(
"hda_codec: too deep connection for 0x%x\n", nid);
592 for (i = 0; i < nums; i++) {
593 unsigned int type = get_wcaps_type(get_wcaps(codec, conn[i]));
620 trace_hda_unsol_event(bus, res, res_ex);
630 unsol->
queue[wp + 1] = res_ex;
647 unsigned int rp, caddr,
res;
649 while (unsol->
rp != unsol->
wp) {
654 caddr = unsol->
queue[rp + 1];
655 if (!(caddr & (1 << 4)))
658 if (codec && codec->
patch_ops.unsol_event)
659 codec->
patch_ops.unsol_event(codec, res);
666 static int init_unsol_queue(
struct hda_bus *bus)
676 "can't allocate unsolicited queue\n");
688 static void snd_hda_codec_free(
struct hda_codec *codec);
690 static int snd_hda_bus_free(
struct hda_bus *bus)
701 snd_hda_codec_free(codec);
703 if (bus->
ops.private_free)
704 bus->
ops.private_free(bus);
715 return snd_hda_bus_free(bus);
718 #ifdef CONFIG_SND_HDA_HWDEP
724 snd_hda_hwdep_add_sysfs(codec);
725 snd_hda_hwdep_add_power_sysfs(codec);
730 #define snd_hda_bus_dev_register NULL
749 .dev_free = snd_hda_bus_dev_free,
778 "hd-audio%d", card->
number);
789 snd_hda_bus_free(bus);
798 #ifdef CONFIG_SND_HDA_GENERIC
799 #define is_generic_config(codec) \
800 (codec->modelname && !strcmp(codec->modelname, "generic"))
802 #define is_generic_config(codec) 0
806 #define HDA_MODREQ_MAX_COUNT 2
808 #define HDA_MODREQ_MAX_COUNT 0
815 find_codec_preset(
struct hda_codec *codec)
819 unsigned int mod_requested = 0;
827 if (!try_module_get(tbl->
owner)) {
831 for (preset = tbl->
preset; preset->
id; preset++) {
833 if (preset->
afg && preset->
afg != codec->
afg)
835 if (preset->
mfg && preset->
mfg != codec->
mfg)
847 module_put(tbl->
owner);
854 snprintf(name,
sizeof(name),
"snd-hda-codec-id:%08x",
857 snprintf(name,
sizeof(name),
"snd-hda-codec-id:%04x*",
859 request_module(name);
869 static int get_codec_name(
struct hda_codec *codec)
879 for (c = hda_vendor_ids; c->
id; c++) {
880 if (c->
id == vendor_id) {
886 sprintf(tmp,
"Generic %04x", vendor_id);
911 static void setup_fg_nodes(
struct hda_codec *codec)
913 int i, total_nodes, function_id;
917 for (i = 0; i < total_nodes; i++, nid++) {
920 switch (function_id & 0xff) {
924 codec->
afg_unsol = (function_id >> 8) & 1;
929 codec->
mfg_unsol = (function_id >> 8) & 1;
951 for (i = 0; i < codec->
num_nodes; i++, nid++)
958 static int read_pin_defaults(
struct hda_codec *codec)
963 for (i = 0; i < codec->
num_nodes; i++, nid++) {
965 unsigned int wcaps = get_wcaps(codec, nid);
966 unsigned int wid_type = get_wcaps_type(wcaps);
988 for (i = 0; i < array->
used; i++) {
989 struct hda_pincfg *pin = snd_array_elem(array, i);
1001 for (i = 0; i < 4; i++) {
1016 unsigned int oldcfg;
1018 if (get_wcaps_type(get_wcaps(codec, nid)) !=
AC_WID_PIN)
1022 pin = look_up_pincfg(codec, list, nid);
1036 set_pincfg(codec, nid, cfg);
1070 #ifdef CONFIG_SND_HDA_HWDEP
1071 pin = look_up_pincfg(codec, &codec->user_pins, nid);
1075 pin = look_up_pincfg(codec, &codec->
driver_pins, nid);
1078 pin = look_up_pincfg(codec, &codec->
init_pins, nid);
1086 static void restore_pincfgs(
struct hda_codec *codec)
1089 for (i = 0; i < codec->
init_pins.used; i++) {
1091 set_pincfg(codec, pin->
nid,
1109 if (codec->
bus->shutdown)
1111 for (i = 0; i < codec->
init_pins.used; i++) {
1123 static void restore_shutup_pins(
struct hda_codec *codec)
1128 if (codec->
bus->shutdown)
1130 for (i = 0; i < codec->
init_pins.used; i++) {
1141 unsigned int record_size);
1145 static void restore_init_pincfgs(
struct hda_codec *codec)
1151 #ifdef CONFIG_SND_HDA_HWDEP
1154 restore_pincfgs(codec);
1177 for (i = 0; i < codec->
cvt_setups.used; i++) {
1191 static void snd_hda_codec_free(
struct hda_codec *codec)
1196 restore_init_pincfgs(codec);
1211 if (!codec->pm_down_notified)
1214 module_put(codec->
owner);
1224 static bool snd_hda_codec_get_supported_ps(
struct hda_codec *codec,
1227 static unsigned int hda_set_power_state(
struct hda_codec *codec,
1239 unsigned int codec_addr,
1254 "address 0x%x is already occupied\n", codec_addr);
1259 if (codec ==
NULL) {
1265 codec->
addr = codec_addr;
1286 hda_keep_power_on(codec);
1290 if (codec->
bus->modelname) {
1293 snd_hda_codec_free(codec);
1314 setup_fg_nodes(codec);
1315 if (!codec->
afg && !codec->
mfg) {
1316 snd_printdd(
"hda_codec: no AFG or MFG node found\n");
1321 fg = codec->
afg ? codec->
afg : codec->
mfg;
1322 err = read_widget_caps(codec, fg);
1327 err = read_pin_defaults(codec);
1338 codec->d3_stop_clk = snd_hda_codec_get_supported_ps(codec, fg,
1340 if (!codec->d3_stop_clk)
1343 codec->
epss = snd_hda_codec_get_supported_ps(codec, fg,
1362 snd_hda_codec_free(codec);
1380 codec->
preset = find_codec_preset(codec);
1382 err = get_codec_name(codec);
1392 err = codec->
preset->patch(codec);
1402 if (!err && codec->
patch_ops.unsol_event)
1403 err = init_unsol_queue(codec->
bus);
1405 if (!err && (codec->
afg || !*codec->
bus->card->mixername))
1407 sizeof(codec->
bus->card->mixername),
1414 static void update_pcm_stream_id(
struct hda_codec *codec,
1416 u32 stream_tag,
int channel_id)
1418 unsigned int oldval, newval;
1422 newval = (stream_tag << 4) | channel_id;
1423 if (oldval != newval)
1436 unsigned int oldval;
1441 if (oldval != format) {
1461 int channel_id,
int format)
1472 "NID=0x%x, stream=0x%x, channel=%d, format=0x%x\n",
1473 nid, stream_tag, channel_id, format);
1474 p = get_hda_cvt_setup(codec, nid);
1479 update_pcm_format(codec, p, nid, format);
1480 update_pcm_stream_id(codec, p, nid, stream_tag, channel_id);
1482 update_pcm_format(codec, p, nid, format);
1488 type = get_wcaps_type(get_wcaps(codec, nid));
1493 get_wcaps_type(get_wcaps(c, p->
nid)) == type)
1500 static void really_cleanup_stream(
struct hda_codec *codec,
1520 snd_printdd(
"hda_codec_cleanup_stream: NID=0x%x\n", nid);
1521 p = get_hda_cvt_setup(codec, nid);
1528 really_cleanup_stream(codec, p);
1535 static void really_cleanup_stream(
struct hda_codec *codec,
1544 memset(q, 0,
sizeof(*q));
1549 static void purify_inactive_streams(
struct hda_codec *codec)
1559 really_cleanup_stream(c, p);
1566 static void hda_cleanup_all_streams(
struct hda_codec *codec)
1570 for (i = 0; i < codec->
cvt_setups.used; i++) {
1573 really_cleanup_stream(codec, p);
1583 #define HDA_HASH_KEY(nid, dir, idx) (u32)((nid) + ((idx) << 16) + ((dir) << 24))
1584 #define HDA_HASH_PINCAP_KEY(nid) (u32)((nid) + (0x02 << 24))
1585 #define HDA_HASH_PARPCM_KEY(nid) (u32)((nid) + (0x03 << 24))
1586 #define HDA_HASH_PARSTR_KEY(nid) (u32)((nid) + (0x04 << 24))
1587 #define INFO_AMP_CAPS (1<<0)
1588 #define INFO_AMP_VOL(ch) (1 << (1 + (ch)))
1592 unsigned int record_size)
1594 memset(cache, 0,
sizeof(*cache));
1596 snd_array_init(&cache->
buf, record_size, 64);
1611 while (cur != 0xffff) {
1612 info = snd_array_elem(&cache->
buf, cur);
1613 if (info->
key == key)
1631 cur = snd_array_index(&cache->
buf, info);
1649 static int write_caps_hash(
struct hda_codec *codec,
u32 key,
unsigned int val)
1654 info = get_alloc_amp_hash(codec, key);
1676 info = get_alloc_amp_hash(codec, key);
1683 val =
func(codec, nid, dir);
1684 write_caps_hash(codec, key, val);
1716 return query_caps_hash(codec, nid, direction,
1738 return write_caps_hash(codec,
HDA_HASH_KEY(nid, dir, 0), caps);
1788 int direction,
int index)
1791 unsigned int parm, val = 0;
1792 bool val_read =
false;
1795 info = get_alloc_amp_hash(codec,
HDA_HASH_KEY(nid, direction, index));
1822 hda_nid_t nid,
int ch,
int direction,
int index,
1849 int direction,
int index)
1852 unsigned int val = 0;
1855 info = update_amp_hash(codec, nid, ch, direction, index);
1857 val = info->
vol[ch];
1877 int direction,
int idx,
int mask,
int val)
1886 info = update_amp_hash(codec, nid, ch, direction, idx);
1891 val |= info->
vol[ch] & ~mask;
1892 if (info->
vol[ch] == val) {
1898 put_vol_mute(codec, info, nid, ch, direction, idx, val);
1916 int direction,
int idx,
int mask,
int val)
1922 for (ch = 0; ch < 2; ch++)
1936 void snd_hda_codec_resume_amp(
struct hda_codec *codec)
1941 for (i = 0; i < codec->
amp_cache.buf.used; i++, buffer++) {
1944 unsigned int idx, dir, ch;
1948 idx = (key >> 16) & 0xff;
1949 dir = (key >> 24) & 0xff;
1950 for (ch = 0; ch < 2; ch++) {
1953 put_vol_mute(codec, buffer, nid, ch, dir, idx,
1988 uinfo->
count = chs == 3 ? 2 : 1;
1990 uinfo->
value.
integer.max = get_amp_max_value(codec, nid, dir, ofs);
1993 "num_steps = 0 for NID=0x%x (ctl = %s)\n", nid,
2002 static inline unsigned int
2004 int ch,
int dir,
int idx,
unsigned int ofs)
2018 int ch,
int dir,
int idx,
unsigned int ofs,
2021 unsigned int maxval;
2026 maxval = get_amp_max_value(codec, nid, dir, 0);
2048 long *valp = ucontrol->
value.integer.value;
2051 *valp++ = read_amp_value(codec, nid, 0, dir, idx, ofs);
2053 *valp = read_amp_value(codec, nid, 1, dir, idx, ofs);
2073 long *valp = ucontrol->
value.integer.value;
2076 snd_hda_power_up(codec);
2078 change = update_amp_value(codec, nid, 0, dir, idx, ofs, *valp);
2082 change |= update_amp_value(codec, nid, 1, dir, idx, ofs, *valp);
2083 snd_hda_power_down(codec);
2095 unsigned int size,
unsigned int __user *_tlv)
2104 if (size < 4 *
sizeof(
unsigned int))
2108 val2 = (val2 + 1) * 25;
2111 val1 = ((
int)val1) * ((
int)val2);
2116 if (
put_user(2 *
sizeof(
unsigned int), _tlv + 1))
2146 step = (step + 1) * 25;
2148 tlv[1] = 2 *
sizeof(
unsigned int);
2149 tlv[2] = -nums *
step;
2156 _snd_hda_find_mixer_ctl(
struct hda_codec *codec,
2157 const char *
name,
int idx)
2160 memset(&
id, 0,
sizeof(
id));
2179 return _snd_hda_find_mixer_ctl(codec, name, 0);
2183 static int find_empty_mixer_ctl_idx(
struct hda_codec *codec,
const char *name)
2186 for (idx = 0; idx < 16; idx++) {
2187 if (!_snd_hda_find_mixer_ctl(codec, name, idx))
2216 unsigned short flags = 0;
2225 nid = kctl->
id.subdevice & 0xffff;
2227 kctl->
id.subdevice = 0;
2266 printk(
KERN_ERR "hda-codec: no NID for mapping control %s:%d:%d\n",
2267 kctl->
id.name, kctl->
id.index, index);
2280 for (i = 0; i < codec->
mixers.used; i++)
2303 for (pcm = 0; pcm < codec->
num_pcms; pcm++) {
2307 if (cpcm->
pcm->streams[0].substream_opened ||
2308 cpcm->
pcm->streams[1].substream_opened)
2357 codec->power_on = 0;
2358 codec->power_transition = 0;
2359 codec->power_jiffies =
jiffies;
2364 for (i = 0; i < codec->
num_pcms; i++) {
2383 restore_pincfgs(codec);
2391 module_put(codec->
owner);
2402 static int map_slaves(
struct hda_codec *codec,
const char *
const *slaves,
2406 const char *
const *
s;
2409 items = codec->
mixers.list;
2410 for (i = 0; i < codec->
mixers.used; i++) {
2412 if (!sctl || !sctl->
id.name ||
2415 for (s = slaves; *
s; s++) {
2416 char tmpname[
sizeof(sctl->
id.name)];
2417 const char *name = *
s;
2419 snprintf(tmpname,
sizeof(tmpname),
"%s %s",
2423 if (!
strcmp(sctl->
id.name, name)) {
2424 err =
func(data, sctl);
2440 static int get_kctl_0dB_offset(
struct snd_kcontrol *kctl)
2450 if (!kctl->
tlv.
c(kctl, 0,
sizeof(_tlv), _tlv))
2456 val = -tlv[2] / tlv[3];
2461 static int put_kctl_with_value(
struct snd_kcontrol *kctl,
int val)
2464 ucontrol = kzalloc(
sizeof(*ucontrol),
GFP_KERNEL);
2467 ucontrol->
value.integer.value[0] =
val;
2468 ucontrol->
value.integer.value[1] =
val;
2469 kctl->
put(kctl, ucontrol);
2477 int offset = get_kctl_0dB_offset(slave);
2479 put_kctl_with_value(slave, offset);
2484 static int init_slave_unmute(
void *data,
struct snd_kcontrol *slave)
2486 return put_kctl_with_value(slave, 1);
2509 unsigned int *tlv,
const char *
const *slaves,
2510 const char *suffix,
bool init_slave_vol,
2519 err = map_slaves(codec, slaves, suffix, check_slave_present,
NULL);
2531 err = map_slaves(codec, slaves, suffix,
2537 put_kctl_with_value(kctl, 0);
2539 map_slaves(codec, slaves, suffix,
2540 tlv ? init_slave_0dB : init_slave_unmute, kctl);
2551 static int vmaster_mute_mode_info(
struct snd_kcontrol *kcontrol,
2554 static const char *
const texts[] = {
2555 "Off",
"On",
"Follow Master"
2569 static int vmaster_mute_mode_get(
struct snd_kcontrol *kcontrol,
2577 static int vmaster_mute_mode_put(
struct snd_kcontrol *kcontrol,
2581 unsigned int old_mode = hook->
mute_mode;
2594 .name =
"Mute-LED Mode",
2595 .info = vmaster_mute_mode_info,
2596 .get = vmaster_mute_mode_get,
2597 .put = vmaster_mute_mode_put,
2607 bool expose_enum_ctl)
2616 if (!expose_enum_ctl)
2657 uinfo->
count = chs == 3 ? 2 : 1;
2678 long *valp = ucontrol->
value.integer.value;
2704 long *valp = ucontrol->
value.integer.value;
2707 snd_hda_power_up(codec);
2711 *valp ? 0 : HDA_AMP_MUTE);
2717 *valp ? 0 : HDA_AMP_MUTE);
2718 hda_call_check_power_status(codec, nid);
2719 snd_hda_power_down(codec);
2730 #define AMP_VAL_IDX_SHIFT 19
2731 #define AMP_VAL_IDX_MASK (0x0f<<19)
2767 int i, indices, err = 0, change = 0;
2772 for (i = 0; i < indices; i++) {
2782 return err < 0 ? err : change;
2802 err = c->
ops->info(kcontrol, uinfo);
2825 err = c->
ops->get(kcontrol, ucontrol);
2843 unsigned long *vals;
2844 int err = 0, change = 0;
2850 err = c->
ops->put(kcontrol, ucontrol);
2857 return err < 0 ? err : change;
2868 unsigned int size,
unsigned int __user *tlv)
2877 err = c->
ops->tlv(kcontrol, op_flag, size, tlv);
2904 static int snd_hda_spdif_mask_info(
struct snd_kcontrol *kcontrol,
2912 static int snd_hda_spdif_cmask_get(
struct snd_kcontrol *kcontrol,
2924 static int snd_hda_spdif_pmask_get(
struct snd_kcontrol *kcontrol,
2933 static int snd_hda_spdif_default_get(
struct snd_kcontrol *kcontrol,
2941 spdif = snd_array_elem(&codec->
spdif_out, idx);
2942 ucontrol->
value.iec958.status[0] = spdif->
status & 0xff;
2943 ucontrol->
value.iec958.status[1] = (spdif->
status >> 8) & 0xff;
2944 ucontrol->
value.iec958.status[2] = (spdif->
status >> 16) & 0xff;
2945 ucontrol->
value.iec958.status[3] = (spdif->
status >> 24) & 0xff;
2954 static unsigned short convert_from_spdif_status(
unsigned int sbits)
2956 unsigned short val = 0;
2962 if (sbits & IEC958_AES0_PROFESSIONAL) {
2981 static unsigned int convert_to_spdif_status(
unsigned short val)
2983 unsigned int sbits = 0;
2989 if (sbits & IEC958_AES0_PROFESSIONAL) {
2999 sbits |= val & (0x7f << 8);
3027 static int snd_hda_spdif_default_put(
struct snd_kcontrol *kcontrol,
3038 spdif = snd_array_elem(&codec->
spdif_out, idx);
3040 spdif->
status = ucontrol->
value.iec958.status[0] |
3041 ((
unsigned int)ucontrol->
value.iec958.status[1] << 8) |
3042 ((
unsigned int)ucontrol->
value.iec958.status[2] << 16) |
3043 ((
unsigned int)ucontrol->
value.iec958.status[3] << 24);
3044 val = convert_from_spdif_status(spdif->
status);
3045 val |= spdif->
ctls & 1;
3048 if (change && nid != (
u16)-1)
3049 set_dig_out_convert(codec, nid, val & 0xff, (val >> 8) & 0xff);
3054 #define snd_hda_spdif_out_switch_info snd_ctl_boolean_mono_info
3056 static int snd_hda_spdif_out_switch_get(
struct snd_kcontrol *kcontrol,
3064 spdif = snd_array_elem(&codec->
spdif_out, idx);
3073 set_dig_out_convert(codec, nid, dig1, dig2);
3081 static int snd_hda_spdif_out_switch_put(
struct snd_kcontrol *kcontrol,
3092 spdif = snd_array_elem(&codec->
spdif_out, idx);
3095 if (ucontrol->
value.integer.value[0])
3099 if (change && nid != (
u16)-1)
3100 set_spdif_ctls(codec, nid, val & 0xff, -1);
3110 .info = snd_hda_spdif_mask_info,
3111 .get = snd_hda_spdif_cmask_get,
3117 .info = snd_hda_spdif_mask_info,
3118 .get = snd_hda_spdif_pmask_get,
3123 .info = snd_hda_spdif_mask_info,
3124 .get = snd_hda_spdif_default_get,
3125 .put = snd_hda_spdif_default_put,
3131 .get = snd_hda_spdif_out_switch_get,
3132 .put = snd_hda_spdif_out_switch_put,
3157 idx = find_empty_mixer_ctl_idx(codec,
"IEC958 Playback Switch");
3163 for (dig_mix = dig_mixes; dig_mix->
name; dig_mix++) {
3167 kctl->
id.index =
idx;
3173 spdif->
nid = cvt_nid;
3176 spdif->
status = convert_to_spdif_status(spdif->
ctls);
3188 for (i = 0; i < codec->
spdif_out.used; i++) {
3191 if (spdif->
nid == nid)
3203 spdif = snd_array_elem(&codec->
spdif_out, idx);
3215 spdif = snd_array_elem(&codec->
spdif_out, idx);
3216 if (spdif->
nid != nid) {
3219 set_spdif_ctls(codec, nid, val & 0xff, (val >> 8) & 0xff);
3228 static int spdif_share_sw_get(
struct snd_kcontrol *kcontrol,
3236 static int spdif_share_sw_put(
struct snd_kcontrol *kcontrol,
3246 .name =
"IEC958 Default PCM Playback Switch",
3248 .get = spdif_share_sw_get,
3249 .put = spdif_share_sw_put,
3272 #define snd_hda_spdif_in_switch_info snd_hda_spdif_out_switch_info
3274 static int snd_hda_spdif_in_switch_get(
struct snd_kcontrol *kcontrol,
3283 static int snd_hda_spdif_in_switch_put(
struct snd_kcontrol *kcontrol,
3288 unsigned int val = !!ucontrol->
value.integer.value[0];
3302 static int snd_hda_spdif_in_status_get(
struct snd_kcontrol *kcontrol,
3311 sbits = convert_to_spdif_status(val);
3312 ucontrol->
value.iec958.status[0] = sbits;
3313 ucontrol->
value.iec958.status[1] = sbits >> 8;
3314 ucontrol->
value.iec958.status[2] = sbits >> 16;
3315 ucontrol->
value.iec958.status[3] = sbits >> 24;
3324 .get = snd_hda_spdif_in_switch_get,
3325 .put = snd_hda_spdif_in_switch_put,
3331 .info = snd_hda_spdif_mask_info,
3332 .get = snd_hda_spdif_in_status_get,
3354 idx = find_empty_mixer_ctl_idx(codec,
"IEC958 Capture Switch");
3359 for (dig_mix = dig_in_ctls; dig_mix->
name; dig_mix++) {
3382 #define build_cmd_cache_key(nid, verb) ((verb << 8) | nid)
3383 #define get_cmd_cache_nid(key) ((key) & 0xff)
3384 #define get_cmd_cache_cmd(key) (((key) >> 8) & 0xffff)
3399 int direct,
unsigned int verb,
unsigned int parm)
3408 verb = verb | (parm >> 8);
3410 key = build_cmd_cache_key(nid, verb);
3412 c = get_alloc_hash(&codec->
cmd_cache, key);
3435 int direct,
unsigned int verb,
unsigned int parm)
3441 verb = verb | (parm >> 8);
3443 key = build_cmd_cache_key(nid, verb);
3446 if (c && c->
val == parm) {
3461 void snd_hda_codec_resume_cache(
struct hda_codec *codec)
3466 for (i = 0; i < codec->
cmd_cache.buf.used; i++, buffer++) {
3471 get_cmd_cache_cmd(key), buffer->
val);
3488 for (; seq->
nid; seq++)
3497 bool eapd_workaround)
3502 for (i = 0; i < codec->
num_nodes; i++, nid++) {
3503 unsigned int wcaps = get_wcaps(codec, nid);
3509 if (eapd_workaround && power_state ==
AC_PWRST_D3 &&
3533 if (sup & power_state)
3542 static unsigned int hda_sync_power_state(
struct hda_codec *codec,
3544 unsigned int power_state)
3547 unsigned int state, actual_state;
3554 actual_state = (state >> 4) & 0x0f;
3555 if (actual_state == power_state)
3568 static unsigned int hda_set_power_state(
struct hda_codec *codec,
3569 unsigned int power_state)
3582 for (count = 0; count < 10; count++) {
3584 codec->
patch_ops.set_power_state(codec, fg,
3593 state = hda_sync_power_state(codec, fg, power_state);
3594 if (!(state & AC_PWRST_ERROR))
3601 #ifdef CONFIG_SND_HDA_HWDEP
3603 static void hda_exec_init_verbs(
struct hda_codec *codec)
3605 if (codec->init_verbs.
list)
3609 static inline void hda_exec_init_verbs(
struct hda_codec *codec) {}
3617 static unsigned int hda_call_codec_suspend(
struct hda_codec *codec,
bool in_wq)
3625 hda_cleanup_all_streams(codec);
3630 spin_lock(&codec->power_lock);
3631 snd_hda_update_power_acct(codec);
3632 trace_hda_power_down(codec);
3633 codec->power_on = 0;
3634 codec->power_transition = 0;
3635 codec->power_jiffies =
jiffies;
3636 spin_unlock(&codec->power_lock);
3644 static void hda_call_codec_resume(
struct hda_codec *codec)
3651 hda_keep_power_on(codec);
3653 restore_pincfgs(codec);
3654 restore_shutup_pins(codec);
3655 hda_exec_init_verbs(codec);
3662 snd_hda_codec_resume_amp(codec);
3663 snd_hda_codec_resume_cache(codec);
3668 snd_hda_power_down(codec);
3689 "for #%d (error %d)\n", codec->
addr, err);
3693 "hda_codec: cannot revert codec\n");
3705 static int add_std_chmaps(
struct hda_codec *codec)
3709 for (i = 0; i < codec->
num_pcms; i++) {
3710 for (str = 0; str < 2; str++) {
3735 hda_exec_init_verbs(codec);
3739 if (!err && codec->
patch_ops.build_controls)
3740 err = codec->
patch_ops.build_controls(codec);
3745 err = add_std_chmaps(codec);
3763 #define HDA_RATE(base, mult, div) \
3764 (AC_FMT_BASE_##base##K | (((mult) - 1) << AC_FMT_MULT_SHIFT) | \
3765 (((div) - 1) << AC_FMT_DIV_SHIFT))
3782 #define AC_PAR_PCM_RATE_BITS 11
3804 unsigned int format,
3805 unsigned int maxbps,
3806 unsigned short spdif_ctls)
3809 unsigned int val = 0;
3811 for (i = 0; rate_bits[
i].
hz; i++)
3812 if (rate_bits[i].
hz == rate) {
3816 if (!rate_bits[i].
hz) {
3821 if (channels == 0 || channels > 8) {
3825 val |= channels - 1;
3839 else if (maxbps >= 24)
3850 if (spdif_ctls & AC_DIG1_NONAUDIO)
3860 unsigned int val = 0;
3861 if (nid != codec->
afg &&
3864 if (!val || val == -1)
3866 if (!val || val == -1)
3881 if (!streams || streams == -1)
3883 if (!streams || streams == -1)
3908 u32 *ratesp,
u64 *formatsp,
unsigned int *bpsp)
3910 unsigned int i,
val, wcaps;
3912 wcaps = get_wcaps(codec, nid);
3913 val = query_pcm_param(codec, nid);
3923 "(nid=0x%x, val=0x%x, ovrd=%i)\n",
3925 (wcaps & AC_WCAP_FORMAT_OVRD) ? 1 : 0);
3931 if (formatsp || bpsp) {
3935 streams = query_stream_param(codec, nid);
3986 "(nid=0x%x, val=0x%x, ovrd=%i, "
3989 (wcaps & AC_WCAP_FORMAT_OVRD) ? 1 : 0,
3994 *formatsp = formats;
4014 unsigned int format)
4019 val = query_pcm_param(codec, nid);
4023 rate = format & 0xff00;
4030 if (i >= AC_PAR_PCM_RATE_BITS)
4033 stream = query_stream_param(codec, nid);
4038 switch (format & 0xf0) {
4073 static int hda_pcm_default_open_close(
struct hda_pcm_stream *hinfo,
4082 unsigned int stream_tag,
4083 unsigned int format,
4098 static int set_pcm_default_values(
struct hda_codec *codec,
4113 info->
ops.open = hda_pcm_default_open_close;
4115 info->
ops.close = hda_pcm_default_open_close;
4116 if (info->
ops.prepare ==
NULL) {
4119 info->
ops.prepare = hda_pcm_default_prepare;
4121 if (info->
ops.cleanup ==
NULL) {
4124 info->
ops.cleanup = hda_pcm_default_cleanup;
4134 unsigned int stream,
4135 unsigned int format,
4140 ret = hinfo->
ops.prepare(hinfo, codec, stream, format, substream);
4142 purify_inactive_streams(codec);
4153 hinfo->
ops.cleanup(hinfo, codec, substream);
4160 "Audio",
"SPDIF",
"HDMI",
"Modem"
4168 static int get_empty_pcm_device(
struct hda_bus *bus,
int type)
4184 for (i = 0; audio_idx[
type][
i] >= 0 ; i++)
4186 return audio_idx[
type][
i];
4189 for (i = 10; i < 32; i++) {
4195 snd_hda_pcm_type_name[type]);
4202 static int snd_hda_attach_pcm(
struct hda_codec *codec,
struct hda_pcm *pcm)
4210 for (stream = 0; stream < 2; stream++) {
4211 info = &pcm->
stream[stream];
4213 err = set_pcm_default_values(codec, info);
4218 return bus->
ops.attach_pcm(bus, codec, pcm);
4230 err = codec->
patch_ops.build_pcms(codec);
4233 "for #%d (error %d)\n", codec->
addr, err);
4237 "hda_codec: cannot revert codec\n");
4242 for (pcm = 0; pcm < codec->
num_pcms; pcm++) {
4246 if (!cpcm->
stream[0].substreams && !cpcm->
stream[1].substreams)
4250 dev = get_empty_pcm_device(codec->
bus, cpcm->
pcm_type);
4254 err = snd_hda_attach_pcm(codec, cpcm);
4257 "PCM stream %d for codec #%d\n",
4319 int num_configs,
const char *
const *models,
4320 const struct snd_pci_quirk *tbl)
4324 for (i = 0; i < num_configs; i++) {
4328 "selected\n", models[i]);
4334 if (!codec->
bus->pci || !tbl)
4337 tbl = snd_pci_quirk_lookup(codec->
bus->pci, tbl);
4340 if (tbl->value >= 0 && tbl->value < num_configs) {
4341 #ifdef CONFIG_SND_DEBUG_VERBOSE
4345 model = models[tbl->value];
4347 sprintf(tmp,
"#%d", tbl->value);
4351 "for config %x:%x (%s)\n",
4352 model, tbl->subvendor, tbl->subdevice,
4353 (tbl->name ? tbl->name :
"Unknown device"));
4383 int num_configs,
const char *
const *models,
4384 const struct snd_pci_quirk *tbl)
4386 const struct snd_pci_quirk *
q;
4389 for (q = tbl; q->subvendor; q++) {
4390 unsigned int mask = 0xffff0000 | q->subdevice_mask;
4391 unsigned int id = (q->subdevice | (q->subvendor << 16)) &
mask;
4401 if (tbl->value >= 0 && tbl->value < num_configs) {
4402 #ifdef CONFIG_SND_DEBUG_VERBOSE
4406 model = models[tbl->value];
4408 sprintf(tmp,
"#%d", tbl->value);
4412 "for config %x:%x (%s)\n",
4413 model, tbl->subvendor, tbl->subdevice,
4414 (tbl->name ? tbl->name :
"Unknown device"));
4437 for (; knew->
name; knew++) {
4439 int addr = 0, idx = 0;
4440 if (knew->
iface == -1)
4449 kctl->
id.index =
idx;
4457 if (!addr && codec->
addr)
4459 else if (!idx && !knew->
index) {
4460 idx = find_empty_mixer_ctl_idx(codec,
4473 static void hda_power_work(
struct work_struct *work)
4480 spin_lock(&codec->power_lock);
4481 if (codec->power_transition > 0) {
4482 spin_unlock(&codec->power_lock);
4485 if (!codec->power_on || codec->power_count) {
4486 codec->power_transition = 0;
4487 spin_unlock(&codec->power_lock);
4490 spin_unlock(&codec->power_lock);
4492 state = hda_call_codec_suspend(codec,
true);
4493 codec->pm_down_notified = 0;
4495 codec->pm_down_notified = 1;
4500 static void hda_keep_power_on(
struct hda_codec *codec)
4502 spin_lock(&codec->power_lock);
4503 codec->power_count++;
4504 codec->power_on = 1;
4505 codec->power_jiffies =
jiffies;
4506 spin_unlock(&codec->power_lock);
4510 void snd_hda_update_power_acct(
struct hda_codec *codec)
4513 if (codec->power_on)
4514 codec->power_on_acct +=
delta;
4516 codec->power_off_acct +=
delta;
4517 codec->power_jiffies +=
delta;
4524 static void __snd_hda_power_up(
struct hda_codec *codec,
bool wait_power_down)
4530 if ((codec->power_on || codec->power_transition > 0) &&
4531 !(wait_power_down && codec->power_transition < 0))
4533 spin_unlock(&codec->power_lock);
4537 spin_lock(&codec->power_lock);
4541 if (codec->power_on) {
4542 if (codec->power_transition < 0)
4543 codec->power_transition = 0;
4547 trace_hda_power_up(codec);
4548 snd_hda_update_power_acct(codec);
4549 codec->power_on = 1;
4550 codec->power_jiffies =
jiffies;
4551 codec->power_transition = 1;
4552 spin_unlock(&codec->power_lock);
4554 if (codec->pm_down_notified) {
4555 codec->pm_down_notified = 0;
4559 hda_call_codec_resume(codec);
4561 spin_lock(&codec->power_lock);
4562 codec->power_transition = 0;
4565 #define power_save(codec) \
4566 ((codec)->bus->power_save ? *(codec)->bus->power_save : 0)
4569 static void __snd_hda_power_down(
struct hda_codec *codec)
4571 if (!codec->power_on || codec->power_count || codec->power_transition)
4575 codec->power_transition = -1;
4590 void snd_hda_power_save(
struct hda_codec *codec,
int delta,
bool d3wait)
4592 spin_lock(&codec->power_lock);
4593 codec->power_count +=
delta;
4594 trace_hda_power_count(codec);
4596 __snd_hda_power_up(codec, d3wait);
4598 __snd_hda_power_down(codec);
4599 spin_unlock(&codec->power_lock);
4633 for (ch = 0; ch < 2; ch++) {
4636 if (!(v & HDA_AMP_MUTE) && v > 0) {
4639 snd_hda_power_up(codec);
4647 snd_hda_power_down(codec);
4688 for (i = 0; i < num_chmodes; i++) {
4689 if (max_channels == chmode[i].
channels) {
4690 ucontrol->
value.enumerated.item[0] =
i;
4709 mode = ucontrol->
value.enumerated.item[0];
4710 if (mode >= num_chmodes)
4712 if (*max_channelsp == chmode[mode].
channels)
4754 unsigned int *cur_val)
4760 idx = ucontrol->
value.enumerated.item[0];
4763 if (*cur_val == idx)
4766 imux->
items[idx].index);
4779 unsigned int stream_tag,
unsigned int format)
4785 set_dig_out_convert(codec, nid,
4797 set_dig_out_convert(codec, nid,
4798 spdif->
ctls & 0xff, -1);
4850 unsigned int stream_tag,
4851 unsigned int format,
4855 setup_dig_out_stream(codec, mout->
dig_out_nid, stream_tag, format);
4945 unsigned int stream_tag,
4946 unsigned int format,
4950 int chs = substream->
runtime->channels;
4961 !(spdif->
status & IEC958_AES0_NONAUDIO)) {
4964 stream_tag, format);
4985 stream_tag, 0, format);
4990 stream_tag, 0, format);
4993 for (i = 1; i < mout->
num_dacs; i++) {
4994 if (chs >= (i + 1) * 2)
5014 for (i = 0; i < mout->
num_dacs; i++)
5044 unsigned int pincap;
5045 unsigned int oldval;
5064 unsigned int val,
bool cached)
5073 val &= ~AC_PINCTL_HP_EN;
5097 int index,
int *type_idx)
5099 int i, label_idx = 0;
5109 *type_idx = label_idx;
5113 "%s %d", label, label_idx);
5135 int snd_hda_suspend(
struct hda_bus *bus)
5141 hda_call_codec_suspend(codec,
false);
5153 int snd_hda_resume(
struct hda_bus *bus)
5158 hda_call_codec_resume(codec);
5196 return snd_array_elem(array, array->
used++);
5223 static unsigned int bits[] = { 8, 16, 20, 24, 32 };
5226 for (i = 0, j = 0; i <
ARRAY_SIZE(bits); i++)
5228 j +=
snprintf(buf + j, buflen - j,
" %d", bits[i]);