aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/hda/hda_codec.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/pci/hda/hda_codec.c')
-rw-r--r--sound/pci/hda/hda_codec.c466
1 files changed, 276 insertions, 190 deletions
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index fe4acfa9e4e6..2fdd1652bad3 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -71,12 +71,13 @@ static struct hda_vendor_id hda_vendor_ids[] = {
71 * 71 *
72 * Returns the obtained response value, or -1 for an error. 72 * Returns the obtained response value, or -1 for an error.
73 */ 73 */
74unsigned int snd_hda_codec_read(struct hda_codec *codec, hda_nid_t nid, int direct, 74unsigned int snd_hda_codec_read(struct hda_codec *codec, hda_nid_t nid,
75 int direct,
75 unsigned int verb, unsigned int parm) 76 unsigned int verb, unsigned int parm)
76{ 77{
77 unsigned int res; 78 unsigned int res;
78 mutex_lock(&codec->bus->cmd_mutex); 79 mutex_lock(&codec->bus->cmd_mutex);
79 if (! codec->bus->ops.command(codec, nid, direct, verb, parm)) 80 if (!codec->bus->ops.command(codec, nid, direct, verb, parm))
80 res = codec->bus->ops.get_response(codec); 81 res = codec->bus->ops.get_response(codec);
81 else 82 else
82 res = (unsigned int)-1; 83 res = (unsigned int)-1;
@@ -129,7 +130,8 @@ void snd_hda_sequence_write(struct hda_codec *codec, const struct hda_verb *seq)
129 * Parse the NID and store the start NID of its sub-nodes. 130 * Parse the NID and store the start NID of its sub-nodes.
130 * Returns the number of sub-nodes. 131 * Returns the number of sub-nodes.
131 */ 132 */
132int snd_hda_get_sub_nodes(struct hda_codec *codec, hda_nid_t nid, hda_nid_t *start_id) 133int snd_hda_get_sub_nodes(struct hda_codec *codec, hda_nid_t nid,
134 hda_nid_t *start_id)
133{ 135{
134 unsigned int parm; 136 unsigned int parm;
135 137
@@ -173,12 +175,13 @@ int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
173 conn_len = parm & AC_CLIST_LENGTH; 175 conn_len = parm & AC_CLIST_LENGTH;
174 mask = (1 << (shift-1)) - 1; 176 mask = (1 << (shift-1)) - 1;
175 177
176 if (! conn_len) 178 if (!conn_len)
177 return 0; /* no connection */ 179 return 0; /* no connection */
178 180
179 if (conn_len == 1) { 181 if (conn_len == 1) {
180 /* single connection */ 182 /* single connection */
181 parm = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_LIST, 0); 183 parm = snd_hda_codec_read(codec, nid, 0,
184 AC_VERB_GET_CONNECT_LIST, 0);
182 conn_list[0] = parm & mask; 185 conn_list[0] = parm & mask;
183 return 1; 186 return 1;
184 } 187 }
@@ -193,18 +196,21 @@ int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
193 if (i % num_elems == 0) 196 if (i % num_elems == 0)
194 parm = snd_hda_codec_read(codec, nid, 0, 197 parm = snd_hda_codec_read(codec, nid, 0,
195 AC_VERB_GET_CONNECT_LIST, i); 198 AC_VERB_GET_CONNECT_LIST, i);
196 range_val = !! (parm & (1 << (shift-1))); /* ranges */ 199 range_val = !!(parm & (1 << (shift-1))); /* ranges */
197 val = parm & mask; 200 val = parm & mask;
198 parm >>= shift; 201 parm >>= shift;
199 if (range_val) { 202 if (range_val) {
200 /* ranges between the previous and this one */ 203 /* ranges between the previous and this one */
201 if (! prev_nid || prev_nid >= val) { 204 if (!prev_nid || prev_nid >= val) {
202 snd_printk(KERN_WARNING "hda_codec: invalid dep_range_val %x:%x\n", prev_nid, val); 205 snd_printk(KERN_WARNING "hda_codec: "
206 "invalid dep_range_val %x:%x\n",
207 prev_nid, val);
203 continue; 208 continue;
204 } 209 }
205 for (n = prev_nid + 1; n <= val; n++) { 210 for (n = prev_nid + 1; n <= val; n++) {
206 if (conns >= max_conns) { 211 if (conns >= max_conns) {
207 snd_printk(KERN_ERR "Too many connections\n"); 212 snd_printk(KERN_ERR
213 "Too many connections\n");
208 return -EINVAL; 214 return -EINVAL;
209 } 215 }
210 conn_list[conns++] = n; 216 conn_list[conns++] = n;
@@ -239,7 +245,8 @@ int snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex)
239 struct hda_bus_unsolicited *unsol; 245 struct hda_bus_unsolicited *unsol;
240 unsigned int wp; 246 unsigned int wp;
241 247
242 if ((unsol = bus->unsol) == NULL) 248 unsol = bus->unsol;
249 if (!unsol)
243 return 0; 250 return 0;
244 251
245 wp = (unsol->wp + 1) % HDA_UNSOL_QUEUE_SIZE; 252 wp = (unsol->wp + 1) % HDA_UNSOL_QUEUE_SIZE;
@@ -271,7 +278,7 @@ static void process_unsol_events(struct work_struct *work)
271 rp <<= 1; 278 rp <<= 1;
272 res = unsol->queue[rp]; 279 res = unsol->queue[rp];
273 caddr = unsol->queue[rp + 1]; 280 caddr = unsol->queue[rp + 1];
274 if (! (caddr & (1 << 4))) /* no unsolicited event? */ 281 if (!(caddr & (1 << 4))) /* no unsolicited event? */
275 continue; 282 continue;
276 codec = bus->caddr_tbl[caddr & 0x0f]; 283 codec = bus->caddr_tbl[caddr & 0x0f];
277 if (codec && codec->patch_ops.unsol_event) 284 if (codec && codec->patch_ops.unsol_event)
@@ -290,8 +297,9 @@ static int __devinit init_unsol_queue(struct hda_bus *bus)
290 return 0; 297 return 0;
291 298
292 unsol = kzalloc(sizeof(*unsol), GFP_KERNEL); 299 unsol = kzalloc(sizeof(*unsol), GFP_KERNEL);
293 if (! unsol) { 300 if (!unsol) {
294 snd_printk(KERN_ERR "hda_codec: can't allocate unsolicited queue\n"); 301 snd_printk(KERN_ERR "hda_codec: "
302 "can't allocate unsolicited queue\n");
295 return -ENOMEM; 303 return -ENOMEM;
296 } 304 }
297 INIT_WORK(&unsol->work, process_unsol_events); 305 INIT_WORK(&unsol->work, process_unsol_events);
@@ -307,16 +315,15 @@ static void snd_hda_codec_free(struct hda_codec *codec);
307 315
308static int snd_hda_bus_free(struct hda_bus *bus) 316static int snd_hda_bus_free(struct hda_bus *bus)
309{ 317{
310 struct list_head *p, *n; 318 struct hda_codec *codec, *n;
311 319
312 if (! bus) 320 if (!bus)
313 return 0; 321 return 0;
314 if (bus->unsol) { 322 if (bus->unsol) {
315 flush_scheduled_work(); 323 flush_scheduled_work();
316 kfree(bus->unsol); 324 kfree(bus->unsol);
317 } 325 }
318 list_for_each_safe(p, n, &bus->codec_list) { 326 list_for_each_entry_safe(codec, n, &bus->codec_list, list) {
319 struct hda_codec *codec = list_entry(p, struct hda_codec, list);
320 snd_hda_codec_free(codec); 327 snd_hda_codec_free(codec);
321 } 328 }
322 if (bus->ops.private_free) 329 if (bus->ops.private_free)
@@ -370,7 +377,8 @@ int __devinit snd_hda_bus_new(struct snd_card *card,
370 mutex_init(&bus->cmd_mutex); 377 mutex_init(&bus->cmd_mutex);
371 INIT_LIST_HEAD(&bus->codec_list); 378 INIT_LIST_HEAD(&bus->codec_list);
372 379
373 if ((err = snd_device_new(card, SNDRV_DEV_BUS, bus, &dev_ops)) < 0) { 380 err = snd_device_new(card, SNDRV_DEV_BUS, bus, &dev_ops);
381 if (err < 0) {
374 snd_hda_bus_free(bus); 382 snd_hda_bus_free(bus);
375 return err; 383 return err;
376 } 384 }
@@ -393,10 +401,10 @@ find_codec_preset(struct hda_codec *codec)
393 for (tbl = hda_preset_tables; *tbl; tbl++) { 401 for (tbl = hda_preset_tables; *tbl; tbl++) {
394 for (preset = *tbl; preset->id; preset++) { 402 for (preset = *tbl; preset->id; preset++) {
395 u32 mask = preset->mask; 403 u32 mask = preset->mask;
396 if (! mask) 404 if (!mask)
397 mask = ~0; 405 mask = ~0;
398 if (preset->id == (codec->vendor_id & mask) && 406 if (preset->id == (codec->vendor_id & mask) &&
399 (! preset->rev || 407 (!preset->rev ||
400 preset->rev == codec->revision_id)) 408 preset->rev == codec->revision_id))
401 return preset; 409 return preset;
402 } 410 }
@@ -421,14 +429,15 @@ void snd_hda_get_codec_name(struct hda_codec *codec,
421 break; 429 break;
422 } 430 }
423 } 431 }
424 if (! vendor) { 432 if (!vendor) {
425 sprintf(tmp, "Generic %04x", vendor_id); 433 sprintf(tmp, "Generic %04x", vendor_id);
426 vendor = tmp; 434 vendor = tmp;
427 } 435 }
428 if (codec->preset && codec->preset->name) 436 if (codec->preset && codec->preset->name)
429 snprintf(name, namelen, "%s %s", vendor, codec->preset->name); 437 snprintf(name, namelen, "%s %s", vendor, codec->preset->name);
430 else 438 else
431 snprintf(name, namelen, "%s ID %x", vendor, codec->vendor_id & 0xffff); 439 snprintf(name, namelen, "%s ID %x", vendor,
440 codec->vendor_id & 0xffff);
432} 441}
433 442
434/* 443/*
@@ -441,7 +450,9 @@ static void __devinit setup_fg_nodes(struct hda_codec *codec)
441 450
442 total_nodes = snd_hda_get_sub_nodes(codec, AC_NODE_ROOT, &nid); 451 total_nodes = snd_hda_get_sub_nodes(codec, AC_NODE_ROOT, &nid);
443 for (i = 0; i < total_nodes; i++, nid++) { 452 for (i = 0; i < total_nodes; i++, nid++) {
444 switch((snd_hda_param_read(codec, nid, AC_PAR_FUNCTION_TYPE) & 0xff)) { 453 unsigned int func;
454 func = snd_hda_param_read(codec, nid, AC_PAR_FUNCTION_TYPE);
455 switch (func & 0xff) {
445 case AC_GRP_AUDIO_FUNCTION: 456 case AC_GRP_AUDIO_FUNCTION:
446 codec->afg = nid; 457 codec->afg = nid;
447 break; 458 break;
@@ -465,7 +476,7 @@ static int read_widget_caps(struct hda_codec *codec, hda_nid_t fg_node)
465 codec->num_nodes = snd_hda_get_sub_nodes(codec, fg_node, 476 codec->num_nodes = snd_hda_get_sub_nodes(codec, fg_node,
466 &codec->start_nid); 477 &codec->start_nid);
467 codec->wcaps = kmalloc(codec->num_nodes * 4, GFP_KERNEL); 478 codec->wcaps = kmalloc(codec->num_nodes * 4, GFP_KERNEL);
468 if (! codec->wcaps) 479 if (!codec->wcaps)
469 return -ENOMEM; 480 return -ENOMEM;
470 nid = codec->start_nid; 481 nid = codec->start_nid;
471 for (i = 0; i < codec->num_nodes; i++, nid++) 482 for (i = 0; i < codec->num_nodes; i++, nid++)
@@ -480,7 +491,7 @@ static int read_widget_caps(struct hda_codec *codec, hda_nid_t fg_node)
480 */ 491 */
481static void snd_hda_codec_free(struct hda_codec *codec) 492static void snd_hda_codec_free(struct hda_codec *codec)
482{ 493{
483 if (! codec) 494 if (!codec)
484 return; 495 return;
485 list_del(&codec->list); 496 list_del(&codec->list);
486 codec->bus->caddr_tbl[codec->addr] = NULL; 497 codec->bus->caddr_tbl[codec->addr] = NULL;
@@ -512,7 +523,8 @@ int __devinit snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr,
512 snd_assert(codec_addr <= HDA_MAX_CODEC_ADDRESS, return -EINVAL); 523 snd_assert(codec_addr <= HDA_MAX_CODEC_ADDRESS, return -EINVAL);
513 524
514 if (bus->caddr_tbl[codec_addr]) { 525 if (bus->caddr_tbl[codec_addr]) {
515 snd_printk(KERN_ERR "hda_codec: address 0x%x is already occupied\n", codec_addr); 526 snd_printk(KERN_ERR "hda_codec: "
527 "address 0x%x is already occupied\n", codec_addr);
516 return -EBUSY; 528 return -EBUSY;
517 } 529 }
518 530
@@ -530,18 +542,21 @@ int __devinit snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr,
530 list_add_tail(&codec->list, &bus->codec_list); 542 list_add_tail(&codec->list, &bus->codec_list);
531 bus->caddr_tbl[codec_addr] = codec; 543 bus->caddr_tbl[codec_addr] = codec;
532 544
533 codec->vendor_id = snd_hda_param_read(codec, AC_NODE_ROOT, AC_PAR_VENDOR_ID); 545 codec->vendor_id = snd_hda_param_read(codec, AC_NODE_ROOT,
546 AC_PAR_VENDOR_ID);
534 if (codec->vendor_id == -1) 547 if (codec->vendor_id == -1)
535 /* read again, hopefully the access method was corrected 548 /* read again, hopefully the access method was corrected
536 * in the last read... 549 * in the last read...
537 */ 550 */
538 codec->vendor_id = snd_hda_param_read(codec, AC_NODE_ROOT, 551 codec->vendor_id = snd_hda_param_read(codec, AC_NODE_ROOT,
539 AC_PAR_VENDOR_ID); 552 AC_PAR_VENDOR_ID);
540 codec->subsystem_id = snd_hda_param_read(codec, AC_NODE_ROOT, AC_PAR_SUBSYSTEM_ID); 553 codec->subsystem_id = snd_hda_param_read(codec, AC_NODE_ROOT,
541 codec->revision_id = snd_hda_param_read(codec, AC_NODE_ROOT, AC_PAR_REV_ID); 554 AC_PAR_SUBSYSTEM_ID);
555 codec->revision_id = snd_hda_param_read(codec, AC_NODE_ROOT,
556 AC_PAR_REV_ID);
542 557
543 setup_fg_nodes(codec); 558 setup_fg_nodes(codec);
544 if (! codec->afg && ! codec->mfg) { 559 if (!codec->afg && !codec->mfg) {
545 snd_printdd("hda_codec: no AFG or MFG node found\n"); 560 snd_printdd("hda_codec: no AFG or MFG node found\n");
546 snd_hda_codec_free(codec); 561 snd_hda_codec_free(codec);
547 return -ENODEV; 562 return -ENODEV;
@@ -553,15 +568,15 @@ int __devinit snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr,
553 return -ENOMEM; 568 return -ENOMEM;
554 } 569 }
555 570
556 if (! codec->subsystem_id) { 571 if (!codec->subsystem_id) {
557 hda_nid_t nid = codec->afg ? codec->afg : codec->mfg; 572 hda_nid_t nid = codec->afg ? codec->afg : codec->mfg;
558 codec->subsystem_id = snd_hda_codec_read(codec, nid, 0, 573 codec->subsystem_id =
559 AC_VERB_GET_SUBSYSTEM_ID, 574 snd_hda_codec_read(codec, nid, 0,
560 0); 575 AC_VERB_GET_SUBSYSTEM_ID, 0);
561 } 576 }
562 577
563 codec->preset = find_codec_preset(codec); 578 codec->preset = find_codec_preset(codec);
564 if (! *bus->card->mixername) 579 if (!*bus->card->mixername)
565 snd_hda_get_codec_name(codec, bus->card->mixername, 580 snd_hda_get_codec_name(codec, bus->card->mixername,
566 sizeof(bus->card->mixername)); 581 sizeof(bus->card->mixername));
567 582
@@ -595,13 +610,15 @@ int __devinit snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr,
595 * @channel_id: channel id to pass, zero based. 610 * @channel_id: channel id to pass, zero based.
596 * @format: stream format. 611 * @format: stream format.
597 */ 612 */
598void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid, u32 stream_tag, 613void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
614 u32 stream_tag,
599 int channel_id, int format) 615 int channel_id, int format)
600{ 616{
601 if (! nid) 617 if (!nid)
602 return; 618 return;
603 619
604 snd_printdd("hda_codec_setup_stream: NID=0x%x, stream=0x%x, channel=%d, format=0x%x\n", 620 snd_printdd("hda_codec_setup_stream: "
621 "NID=0x%x, stream=0x%x, channel=%d, format=0x%x\n",
605 nid, stream_tag, channel_id, format); 622 nid, stream_tag, channel_id, format);
606 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID, 623 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID,
607 (stream_tag << 4) | channel_id); 624 (stream_tag << 4) | channel_id);
@@ -645,15 +662,18 @@ static struct hda_amp_info *get_alloc_amp_hash(struct hda_codec *codec, u32 key)
645 if (codec->num_amp_entries >= codec->amp_info_size) { 662 if (codec->num_amp_entries >= codec->amp_info_size) {
646 /* reallocate the array */ 663 /* reallocate the array */
647 int new_size = codec->amp_info_size + 64; 664 int new_size = codec->amp_info_size + 64;
648 struct hda_amp_info *new_info = kcalloc(new_size, sizeof(struct hda_amp_info), 665 struct hda_amp_info *new_info;
649 GFP_KERNEL); 666 new_info = kcalloc(new_size, sizeof(struct hda_amp_info),
650 if (! new_info) { 667 GFP_KERNEL);
651 snd_printk(KERN_ERR "hda_codec: can't malloc amp_info\n"); 668 if (!new_info) {
669 snd_printk(KERN_ERR "hda_codec: "
670 "can't malloc amp_info\n");
652 return NULL; 671 return NULL;
653 } 672 }
654 if (codec->amp_info) { 673 if (codec->amp_info) {
655 memcpy(new_info, codec->amp_info, 674 memcpy(new_info, codec->amp_info,
656 codec->amp_info_size * sizeof(struct hda_amp_info)); 675 codec->amp_info_size *
676 sizeof(struct hda_amp_info));
657 kfree(codec->amp_info); 677 kfree(codec->amp_info);
658 } 678 }
659 codec->amp_info_size = new_size; 679 codec->amp_info_size = new_size;
@@ -674,15 +694,18 @@ static struct hda_amp_info *get_alloc_amp_hash(struct hda_codec *codec, u32 key)
674 */ 694 */
675static u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction) 695static u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction)
676{ 696{
677 struct hda_amp_info *info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, 0)); 697 struct hda_amp_info *info;
678 698
679 if (! info) 699 info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, 0));
700 if (!info)
680 return 0; 701 return 0;
681 if (! (info->status & INFO_AMP_CAPS)) { 702 if (!(info->status & INFO_AMP_CAPS)) {
682 if (! (get_wcaps(codec, nid) & AC_WCAP_AMP_OVRD)) 703 if (!(get_wcaps(codec, nid) & AC_WCAP_AMP_OVRD))
683 nid = codec->afg; 704 nid = codec->afg;
684 info->amp_caps = snd_hda_param_read(codec, nid, direction == HDA_OUTPUT ? 705 info->amp_caps = snd_hda_param_read(codec, nid,
685 AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP); 706 direction == HDA_OUTPUT ?
707 AC_PAR_AMP_OUT_CAP :
708 AC_PAR_AMP_IN_CAP);
686 info->status |= INFO_AMP_CAPS; 709 info->status |= INFO_AMP_CAPS;
687 } 710 }
688 return info->amp_caps; 711 return info->amp_caps;
@@ -692,8 +715,9 @@ static u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction)
692 * read the current volume to info 715 * read the current volume to info
693 * if the cache exists, read the cache value. 716 * if the cache exists, read the cache value.
694 */ 717 */
695static unsigned int get_vol_mute(struct hda_codec *codec, struct hda_amp_info *info, 718static unsigned int get_vol_mute(struct hda_codec *codec,
696 hda_nid_t nid, int ch, int direction, int index) 719 struct hda_amp_info *info, hda_nid_t nid,
720 int ch, int direction, int index)
697{ 721{
698 u32 val, parm; 722 u32 val, parm;
699 723
@@ -703,7 +727,8 @@ static unsigned int get_vol_mute(struct hda_codec *codec, struct hda_amp_info *i
703 parm = ch ? AC_AMP_GET_RIGHT : AC_AMP_GET_LEFT; 727 parm = ch ? AC_AMP_GET_RIGHT : AC_AMP_GET_LEFT;
704 parm |= direction == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT; 728 parm |= direction == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT;
705 parm |= index; 729 parm |= index;
706 val = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_AMP_GAIN_MUTE, parm); 730 val = snd_hda_codec_read(codec, nid, 0,
731 AC_VERB_GET_AMP_GAIN_MUTE, parm);
707 info->vol[ch] = val & 0xff; 732 info->vol[ch] = val & 0xff;
708 info->status |= INFO_AMP_VOL(ch); 733 info->status |= INFO_AMP_VOL(ch);
709 return info->vol[ch]; 734 return info->vol[ch];
@@ -713,7 +738,8 @@ static unsigned int get_vol_mute(struct hda_codec *codec, struct hda_amp_info *i
713 * write the current volume in info to the h/w and update the cache 738 * write the current volume in info to the h/w and update the cache
714 */ 739 */
715static void put_vol_mute(struct hda_codec *codec, struct hda_amp_info *info, 740static void put_vol_mute(struct hda_codec *codec, struct hda_amp_info *info,
716 hda_nid_t nid, int ch, int direction, int index, int val) 741 hda_nid_t nid, int ch, int direction, int index,
742 int val)
717{ 743{
718 u32 parm; 744 u32 parm;
719 745
@@ -731,8 +757,9 @@ static void put_vol_mute(struct hda_codec *codec, struct hda_amp_info *info,
731int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch, 757int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch,
732 int direction, int index) 758 int direction, int index)
733{ 759{
734 struct hda_amp_info *info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, index)); 760 struct hda_amp_info *info;
735 if (! info) 761 info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, index));
762 if (!info)
736 return 0; 763 return 0;
737 return get_vol_mute(codec, info, nid, ch, direction, index); 764 return get_vol_mute(codec, info, nid, ch, direction, index);
738} 765}
@@ -743,13 +770,14 @@ int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch,
743int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch, 770int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
744 int direction, int idx, int mask, int val) 771 int direction, int idx, int mask, int val)
745{ 772{
746 struct hda_amp_info *info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, idx)); 773 struct hda_amp_info *info;
747 774
748 if (! info) 775 info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, idx));
776 if (!info)
749 return 0; 777 return 0;
750 val &= mask; 778 val &= mask;
751 val |= get_vol_mute(codec, info, nid, ch, direction, idx) & ~mask; 779 val |= get_vol_mute(codec, info, nid, ch, direction, idx) & ~mask;
752 if (info->vol[ch] == val && ! codec->in_resume) 780 if (info->vol[ch] == val && !codec->in_resume)
753 return 0; 781 return 0;
754 put_vol_mute(codec, info, nid, ch, direction, idx, val); 782 put_vol_mute(codec, info, nid, ch, direction, idx, val);
755 return 1; 783 return 1;
@@ -766,7 +794,8 @@ int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
766#define get_amp_index(kc) (((kc)->private_value >> 19) & 0xf) 794#define get_amp_index(kc) (((kc)->private_value >> 19) & 0xf)
767 795
768/* volume */ 796/* volume */
769int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 797int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol,
798 struct snd_ctl_elem_info *uinfo)
770{ 799{
771 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 800 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
772 u16 nid = get_amp_nid(kcontrol); 801 u16 nid = get_amp_nid(kcontrol);
@@ -775,9 +804,11 @@ int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_
775 u32 caps; 804 u32 caps;
776 805
777 caps = query_amp_caps(codec, nid, dir); 806 caps = query_amp_caps(codec, nid, dir);
778 caps = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT; /* num steps */ 807 /* num steps */
779 if (! caps) { 808 caps = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
780 printk(KERN_WARNING "hda_codec: num_steps = 0 for NID=0x%x\n", nid); 809 if (!caps) {
810 printk(KERN_WARNING "hda_codec: "
811 "num_steps = 0 for NID=0x%x\n", nid);
781 return -EINVAL; 812 return -EINVAL;
782 } 813 }
783 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 814 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
@@ -787,7 +818,8 @@ int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_
787 return 0; 818 return 0;
788} 819}
789 820
790int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 821int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol,
822 struct snd_ctl_elem_value *ucontrol)
791{ 823{
792 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 824 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
793 hda_nid_t nid = get_amp_nid(kcontrol); 825 hda_nid_t nid = get_amp_nid(kcontrol);
@@ -803,7 +835,8 @@ int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_e
803 return 0; 835 return 0;
804} 836}
805 837
806int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 838int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol,
839 struct snd_ctl_elem_value *ucontrol)
807{ 840{
808 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 841 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
809 hda_nid_t nid = get_amp_nid(kcontrol); 842 hda_nid_t nid = get_amp_nid(kcontrol);
@@ -835,7 +868,8 @@ int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag,
835 if (size < 4 * sizeof(unsigned int)) 868 if (size < 4 * sizeof(unsigned int))
836 return -ENOMEM; 869 return -ENOMEM;
837 caps = query_amp_caps(codec, nid, dir); 870 caps = query_amp_caps(codec, nid, dir);
838 val2 = (((caps & AC_AMPCAP_STEP_SIZE) >> AC_AMPCAP_STEP_SIZE_SHIFT) + 1) * 25; 871 val2 = (caps & AC_AMPCAP_STEP_SIZE) >> AC_AMPCAP_STEP_SIZE_SHIFT;
872 val2 = (val2 + 1) * 25;
839 val1 = -((caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT); 873 val1 = -((caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT);
840 val1 = ((int)val1) * ((int)val2); 874 val1 = ((int)val1) * ((int)val2);
841 if (put_user(SNDRV_CTL_TLVT_DB_SCALE, _tlv)) 875 if (put_user(SNDRV_CTL_TLVT_DB_SCALE, _tlv))
@@ -850,7 +884,8 @@ int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag,
850} 884}
851 885
852/* switch */ 886/* switch */
853int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 887int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol,
888 struct snd_ctl_elem_info *uinfo)
854{ 889{
855 int chs = get_amp_channels(kcontrol); 890 int chs = get_amp_channels(kcontrol);
856 891
@@ -861,7 +896,8 @@ int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_
861 return 0; 896 return 0;
862} 897}
863 898
864int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 899int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol,
900 struct snd_ctl_elem_value *ucontrol)
865{ 901{
866 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 902 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
867 hda_nid_t nid = get_amp_nid(kcontrol); 903 hda_nid_t nid = get_amp_nid(kcontrol);
@@ -871,13 +907,16 @@ int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_e
871 long *valp = ucontrol->value.integer.value; 907 long *valp = ucontrol->value.integer.value;
872 908
873 if (chs & 1) 909 if (chs & 1)
874 *valp++ = (snd_hda_codec_amp_read(codec, nid, 0, dir, idx) & 0x80) ? 0 : 1; 910 *valp++ = (snd_hda_codec_amp_read(codec, nid, 0, dir, idx) &
911 0x80) ? 0 : 1;
875 if (chs & 2) 912 if (chs & 2)
876 *valp = (snd_hda_codec_amp_read(codec, nid, 1, dir, idx) & 0x80) ? 0 : 1; 913 *valp = (snd_hda_codec_amp_read(codec, nid, 1, dir, idx) &
914 0x80) ? 0 : 1;
877 return 0; 915 return 0;
878} 916}
879 917
880int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 918int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
919 struct snd_ctl_elem_value *ucontrol)
881{ 920{
882 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 921 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
883 hda_nid_t nid = get_amp_nid(kcontrol); 922 hda_nid_t nid = get_amp_nid(kcontrol);
@@ -908,7 +947,8 @@ int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e
908#define AMP_VAL_IDX_SHIFT 19 947#define AMP_VAL_IDX_SHIFT 19
909#define AMP_VAL_IDX_MASK (0x0f<<19) 948#define AMP_VAL_IDX_MASK (0x0f<<19)
910 949
911int snd_hda_mixer_bind_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 950int snd_hda_mixer_bind_switch_get(struct snd_kcontrol *kcontrol,
951 struct snd_ctl_elem_value *ucontrol)
912{ 952{
913 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 953 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
914 unsigned long pval; 954 unsigned long pval;
@@ -923,7 +963,8 @@ int snd_hda_mixer_bind_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_
923 return err; 963 return err;
924} 964}
925 965
926int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 966int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol,
967 struct snd_ctl_elem_value *ucontrol)
927{ 968{
928 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 969 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
929 unsigned long pval; 970 unsigned long pval;
@@ -933,7 +974,8 @@ int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_
933 pval = kcontrol->private_value; 974 pval = kcontrol->private_value;
934 indices = (pval & AMP_VAL_IDX_MASK) >> AMP_VAL_IDX_SHIFT; 975 indices = (pval & AMP_VAL_IDX_MASK) >> AMP_VAL_IDX_SHIFT;
935 for (i = 0; i < indices; i++) { 976 for (i = 0; i < indices; i++) {
936 kcontrol->private_value = (pval & ~AMP_VAL_IDX_MASK) | (i << AMP_VAL_IDX_SHIFT); 977 kcontrol->private_value = (pval & ~AMP_VAL_IDX_MASK) |
978 (i << AMP_VAL_IDX_SHIFT);
937 err = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol); 979 err = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
938 if (err < 0) 980 if (err < 0)
939 break; 981 break;
@@ -948,14 +990,16 @@ int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_
948 * SPDIF out controls 990 * SPDIF out controls
949 */ 991 */
950 992
951static int snd_hda_spdif_mask_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 993static int snd_hda_spdif_mask_info(struct snd_kcontrol *kcontrol,
994 struct snd_ctl_elem_info *uinfo)
952{ 995{
953 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; 996 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
954 uinfo->count = 1; 997 uinfo->count = 1;
955 return 0; 998 return 0;
956} 999}
957 1000
958static int snd_hda_spdif_cmask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1001static int snd_hda_spdif_cmask_get(struct snd_kcontrol *kcontrol,
1002 struct snd_ctl_elem_value *ucontrol)
959{ 1003{
960 ucontrol->value.iec958.status[0] = IEC958_AES0_PROFESSIONAL | 1004 ucontrol->value.iec958.status[0] = IEC958_AES0_PROFESSIONAL |
961 IEC958_AES0_NONAUDIO | 1005 IEC958_AES0_NONAUDIO |
@@ -966,7 +1010,8 @@ static int snd_hda_spdif_cmask_get(struct snd_kcontrol *kcontrol, struct snd_ctl
966 return 0; 1010 return 0;
967} 1011}
968 1012
969static int snd_hda_spdif_pmask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1013static int snd_hda_spdif_pmask_get(struct snd_kcontrol *kcontrol,
1014 struct snd_ctl_elem_value *ucontrol)
970{ 1015{
971 ucontrol->value.iec958.status[0] = IEC958_AES0_PROFESSIONAL | 1016 ucontrol->value.iec958.status[0] = IEC958_AES0_PROFESSIONAL |
972 IEC958_AES0_NONAUDIO | 1017 IEC958_AES0_NONAUDIO |
@@ -974,7 +1019,8 @@ static int snd_hda_spdif_pmask_get(struct snd_kcontrol *kcontrol, struct snd_ctl
974 return 0; 1019 return 0;
975} 1020}
976 1021
977static int snd_hda_spdif_default_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1022static int snd_hda_spdif_default_get(struct snd_kcontrol *kcontrol,
1023 struct snd_ctl_elem_value *ucontrol)
978{ 1024{
979 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1025 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
980 1026
@@ -994,19 +1040,21 @@ static unsigned short convert_from_spdif_status(unsigned int sbits)
994 unsigned short val = 0; 1040 unsigned short val = 0;
995 1041
996 if (sbits & IEC958_AES0_PROFESSIONAL) 1042 if (sbits & IEC958_AES0_PROFESSIONAL)
997 val |= 1 << 6; 1043 val |= AC_DIG1_PROFESSIONAL;
998 if (sbits & IEC958_AES0_NONAUDIO) 1044 if (sbits & IEC958_AES0_NONAUDIO)
999 val |= 1 << 5; 1045 val |= AC_DIG1_NONAUDIO;
1000 if (sbits & IEC958_AES0_PROFESSIONAL) { 1046 if (sbits & IEC958_AES0_PROFESSIONAL) {
1001 if ((sbits & IEC958_AES0_PRO_EMPHASIS) == IEC958_AES0_PRO_EMPHASIS_5015) 1047 if ((sbits & IEC958_AES0_PRO_EMPHASIS) ==
1002 val |= 1 << 3; 1048 IEC958_AES0_PRO_EMPHASIS_5015)
1049 val |= AC_DIG1_EMPHASIS;
1003 } else { 1050 } else {
1004 if ((sbits & IEC958_AES0_CON_EMPHASIS) == IEC958_AES0_CON_EMPHASIS_5015) 1051 if ((sbits & IEC958_AES0_CON_EMPHASIS) ==
1005 val |= 1 << 3; 1052 IEC958_AES0_CON_EMPHASIS_5015)
1006 if (! (sbits & IEC958_AES0_CON_NOT_COPYRIGHT)) 1053 val |= AC_DIG1_EMPHASIS;
1007 val |= 1 << 4; 1054 if (!(sbits & IEC958_AES0_CON_NOT_COPYRIGHT))
1055 val |= AC_DIG1_COPYRIGHT;
1008 if (sbits & (IEC958_AES1_CON_ORIGINAL << 8)) 1056 if (sbits & (IEC958_AES1_CON_ORIGINAL << 8))
1009 val |= 1 << 7; 1057 val |= AC_DIG1_LEVEL;
1010 val |= sbits & (IEC958_AES1_CON_CATEGORY << 8); 1058 val |= sbits & (IEC958_AES1_CON_CATEGORY << 8);
1011 } 1059 }
1012 return val; 1060 return val;
@@ -1018,26 +1066,27 @@ static unsigned int convert_to_spdif_status(unsigned short val)
1018{ 1066{
1019 unsigned int sbits = 0; 1067 unsigned int sbits = 0;
1020 1068
1021 if (val & (1 << 5)) 1069 if (val & AC_DIG1_NONAUDIO)
1022 sbits |= IEC958_AES0_NONAUDIO; 1070 sbits |= IEC958_AES0_NONAUDIO;
1023 if (val & (1 << 6)) 1071 if (val & AC_DIG1_PROFESSIONAL)
1024 sbits |= IEC958_AES0_PROFESSIONAL; 1072 sbits |= IEC958_AES0_PROFESSIONAL;
1025 if (sbits & IEC958_AES0_PROFESSIONAL) { 1073 if (sbits & IEC958_AES0_PROFESSIONAL) {
1026 if (sbits & (1 << 3)) 1074 if (sbits & AC_DIG1_EMPHASIS)
1027 sbits |= IEC958_AES0_PRO_EMPHASIS_5015; 1075 sbits |= IEC958_AES0_PRO_EMPHASIS_5015;
1028 } else { 1076 } else {
1029 if (val & (1 << 3)) 1077 if (val & AC_DIG1_EMPHASIS)
1030 sbits |= IEC958_AES0_CON_EMPHASIS_5015; 1078 sbits |= IEC958_AES0_CON_EMPHASIS_5015;
1031 if (! (val & (1 << 4))) 1079 if (!(val & AC_DIG1_COPYRIGHT))
1032 sbits |= IEC958_AES0_CON_NOT_COPYRIGHT; 1080 sbits |= IEC958_AES0_CON_NOT_COPYRIGHT;
1033 if (val & (1 << 7)) 1081 if (val & AC_DIG1_LEVEL)
1034 sbits |= (IEC958_AES1_CON_ORIGINAL << 8); 1082 sbits |= (IEC958_AES1_CON_ORIGINAL << 8);
1035 sbits |= val & (0x7f << 8); 1083 sbits |= val & (0x7f << 8);
1036 } 1084 }
1037 return sbits; 1085 return sbits;
1038} 1086}
1039 1087
1040static int snd_hda_spdif_default_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1088static int snd_hda_spdif_default_put(struct snd_kcontrol *kcontrol,
1089 struct snd_ctl_elem_value *ucontrol)
1041{ 1090{
1042 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1091 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1043 hda_nid_t nid = kcontrol->private_value; 1092 hda_nid_t nid = kcontrol->private_value;
@@ -1055,15 +1104,18 @@ static int snd_hda_spdif_default_put(struct snd_kcontrol *kcontrol, struct snd_c
1055 codec->spdif_ctls = val; 1104 codec->spdif_ctls = val;
1056 1105
1057 if (change || codec->in_resume) { 1106 if (change || codec->in_resume) {
1058 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1, val & 0xff); 1107 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
1059 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_2, val >> 8); 1108 val & 0xff);
1109 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_2,
1110 val >> 8);
1060 } 1111 }
1061 1112
1062 mutex_unlock(&codec->spdif_mutex); 1113 mutex_unlock(&codec->spdif_mutex);
1063 return change; 1114 return change;
1064} 1115}
1065 1116
1066static int snd_hda_spdif_out_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1117static int snd_hda_spdif_out_switch_info(struct snd_kcontrol *kcontrol,
1118 struct snd_ctl_elem_info *uinfo)
1067{ 1119{
1068 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 1120 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1069 uinfo->count = 1; 1121 uinfo->count = 1;
@@ -1072,15 +1124,17 @@ static int snd_hda_spdif_out_switch_info(struct snd_kcontrol *kcontrol, struct s
1072 return 0; 1124 return 0;
1073} 1125}
1074 1126
1075static int snd_hda_spdif_out_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1127static int snd_hda_spdif_out_switch_get(struct snd_kcontrol *kcontrol,
1128 struct snd_ctl_elem_value *ucontrol)
1076{ 1129{
1077 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1130 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1078 1131
1079 ucontrol->value.integer.value[0] = codec->spdif_ctls & 1; 1132 ucontrol->value.integer.value[0] = codec->spdif_ctls & AC_DIG1_ENABLE;
1080 return 0; 1133 return 0;
1081} 1134}
1082 1135
1083static int snd_hda_spdif_out_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1136static int snd_hda_spdif_out_switch_put(struct snd_kcontrol *kcontrol,
1137 struct snd_ctl_elem_value *ucontrol)
1084{ 1138{
1085 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1139 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1086 hda_nid_t nid = kcontrol->private_value; 1140 hda_nid_t nid = kcontrol->private_value;
@@ -1088,20 +1142,21 @@ static int snd_hda_spdif_out_switch_put(struct snd_kcontrol *kcontrol, struct sn
1088 int change; 1142 int change;
1089 1143
1090 mutex_lock(&codec->spdif_mutex); 1144 mutex_lock(&codec->spdif_mutex);
1091 val = codec->spdif_ctls & ~1; 1145 val = codec->spdif_ctls & ~AC_DIG1_ENABLE;
1092 if (ucontrol->value.integer.value[0]) 1146 if (ucontrol->value.integer.value[0])
1093 val |= 1; 1147 val |= AC_DIG1_ENABLE;
1094 change = codec->spdif_ctls != val; 1148 change = codec->spdif_ctls != val;
1095 if (change || codec->in_resume) { 1149 if (change || codec->in_resume) {
1096 codec->spdif_ctls = val; 1150 codec->spdif_ctls = val;
1097 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1, 1151 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
1098 val & 0xff); 1152 val & 0xff);
1099 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) 1153 /* unmute amp switch (if any) */
1154 if ((get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) &&
1155 (val & AC_DIG1_ENABLE))
1100 snd_hda_codec_write(codec, nid, 0, 1156 snd_hda_codec_write(codec, nid, 0,
1101 AC_VERB_SET_AMP_GAIN_MUTE, 1157 AC_VERB_SET_AMP_GAIN_MUTE,
1102 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | 1158 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT |
1103 AC_AMP_SET_OUTPUT | 1159 AC_AMP_SET_OUTPUT);
1104 ((val & 1) ? 0 : 0x80));
1105 } 1160 }
1106 mutex_unlock(&codec->spdif_mutex); 1161 mutex_unlock(&codec->spdif_mutex);
1107 return change; 1162 return change;
@@ -1159,10 +1214,12 @@ int __devinit snd_hda_create_spdif_out_ctls(struct hda_codec *codec,
1159 for (dig_mix = dig_mixes; dig_mix->name; dig_mix++) { 1214 for (dig_mix = dig_mixes; dig_mix->name; dig_mix++) {
1160 kctl = snd_ctl_new1(dig_mix, codec); 1215 kctl = snd_ctl_new1(dig_mix, codec);
1161 kctl->private_value = nid; 1216 kctl->private_value = nid;
1162 if ((err = snd_ctl_add(codec->bus->card, kctl)) < 0) 1217 err = snd_ctl_add(codec->bus->card, kctl);
1218 if (err < 0)
1163 return err; 1219 return err;
1164 } 1220 }
1165 codec->spdif_ctls = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_DIGI_CONVERT, 0); 1221 codec->spdif_ctls =
1222 snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_DIGI_CONVERT, 0);
1166 codec->spdif_status = convert_to_spdif_status(codec->spdif_ctls); 1223 codec->spdif_status = convert_to_spdif_status(codec->spdif_ctls);
1167 return 0; 1224 return 0;
1168} 1225}
@@ -1173,7 +1230,8 @@ int __devinit snd_hda_create_spdif_out_ctls(struct hda_codec *codec,
1173 1230
1174#define snd_hda_spdif_in_switch_info snd_hda_spdif_out_switch_info 1231#define snd_hda_spdif_in_switch_info snd_hda_spdif_out_switch_info
1175 1232
1176static int snd_hda_spdif_in_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1233static int snd_hda_spdif_in_switch_get(struct snd_kcontrol *kcontrol,
1234 struct snd_ctl_elem_value *ucontrol)
1177{ 1235{
1178 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1236 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1179 1237
@@ -1181,7 +1239,8 @@ static int snd_hda_spdif_in_switch_get(struct snd_kcontrol *kcontrol, struct snd
1181 return 0; 1239 return 0;
1182} 1240}
1183 1241
1184static int snd_hda_spdif_in_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1242static int snd_hda_spdif_in_switch_put(struct snd_kcontrol *kcontrol,
1243 struct snd_ctl_elem_value *ucontrol)
1185{ 1244{
1186 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1245 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1187 hda_nid_t nid = kcontrol->private_value; 1246 hda_nid_t nid = kcontrol->private_value;
@@ -1192,13 +1251,15 @@ static int snd_hda_spdif_in_switch_put(struct snd_kcontrol *kcontrol, struct snd
1192 change = codec->spdif_in_enable != val; 1251 change = codec->spdif_in_enable != val;
1193 if (change || codec->in_resume) { 1252 if (change || codec->in_resume) {
1194 codec->spdif_in_enable = val; 1253 codec->spdif_in_enable = val;
1195 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1, val); 1254 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
1255 val);
1196 } 1256 }
1197 mutex_unlock(&codec->spdif_mutex); 1257 mutex_unlock(&codec->spdif_mutex);
1198 return change; 1258 return change;
1199} 1259}
1200 1260
1201static int snd_hda_spdif_in_status_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1261static int snd_hda_spdif_in_status_get(struct snd_kcontrol *kcontrol,
1262 struct snd_ctl_elem_value *ucontrol)
1202{ 1263{
1203 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1264 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1204 hda_nid_t nid = kcontrol->private_value; 1265 hda_nid_t nid = kcontrol->private_value;
@@ -1252,10 +1313,13 @@ int __devinit snd_hda_create_spdif_in_ctls(struct hda_codec *codec,
1252 for (dig_mix = dig_in_ctls; dig_mix->name; dig_mix++) { 1313 for (dig_mix = dig_in_ctls; dig_mix->name; dig_mix++) {
1253 kctl = snd_ctl_new1(dig_mix, codec); 1314 kctl = snd_ctl_new1(dig_mix, codec);
1254 kctl->private_value = nid; 1315 kctl->private_value = nid;
1255 if ((err = snd_ctl_add(codec->bus->card, kctl)) < 0) 1316 err = snd_ctl_add(codec->bus->card, kctl);
1317 if (err < 0)
1256 return err; 1318 return err;
1257 } 1319 }
1258 codec->spdif_in_enable = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_DIGI_CONVERT, 0) & 1; 1320 codec->spdif_in_enable =
1321 snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_DIGI_CONVERT, 0) &
1322 AC_DIG1_ENABLE;
1259 return 0; 1323 return 0;
1260} 1324}
1261 1325
@@ -1295,13 +1359,12 @@ static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
1295 */ 1359 */
1296int __devinit snd_hda_build_controls(struct hda_bus *bus) 1360int __devinit snd_hda_build_controls(struct hda_bus *bus)
1297{ 1361{
1298 struct list_head *p; 1362 struct hda_codec *codec;
1299 1363
1300 /* build controls */ 1364 /* build controls */
1301 list_for_each(p, &bus->codec_list) { 1365 list_for_each_entry(codec, &bus->codec_list, list) {
1302 struct hda_codec *codec = list_entry(p, struct hda_codec, list);
1303 int err; 1366 int err;
1304 if (! codec->patch_ops.build_controls) 1367 if (!codec->patch_ops.build_controls)
1305 continue; 1368 continue;
1306 err = codec->patch_ops.build_controls(codec); 1369 err = codec->patch_ops.build_controls(codec);
1307 if (err < 0) 1370 if (err < 0)
@@ -1309,13 +1372,12 @@ int __devinit snd_hda_build_controls(struct hda_bus *bus)
1309 } 1372 }
1310 1373
1311 /* initialize */ 1374 /* initialize */
1312 list_for_each(p, &bus->codec_list) { 1375 list_for_each_entry(codec, &bus->codec_list, list) {
1313 struct hda_codec *codec = list_entry(p, struct hda_codec, list);
1314 int err; 1376 int err;
1315 hda_set_power_state(codec, 1377 hda_set_power_state(codec,
1316 codec->afg ? codec->afg : codec->mfg, 1378 codec->afg ? codec->afg : codec->mfg,
1317 AC_PWRST_D0); 1379 AC_PWRST_D0);
1318 if (! codec->patch_ops.init) 1380 if (!codec->patch_ops.init)
1319 continue; 1381 continue;
1320 err = codec->patch_ops.init(codec); 1382 err = codec->patch_ops.init(codec);
1321 if (err < 0) 1383 if (err < 0)
@@ -1381,7 +1443,7 @@ unsigned int snd_hda_calc_stream_format(unsigned int rate,
1381 val = rate_bits[i].hda_fmt; 1443 val = rate_bits[i].hda_fmt;
1382 break; 1444 break;
1383 } 1445 }
1384 if (! rate_bits[i].hz) { 1446 if (!rate_bits[i].hz) {
1385 snd_printdd("invalid rate %d\n", rate); 1447 snd_printdd("invalid rate %d\n", rate);
1386 return 0; 1448 return 0;
1387 } 1449 }
@@ -1406,7 +1468,8 @@ unsigned int snd_hda_calc_stream_format(unsigned int rate,
1406 val |= 0x20; 1468 val |= 0x20;
1407 break; 1469 break;
1408 default: 1470 default:
1409 snd_printdd("invalid format width %d\n", snd_pcm_format_width(format)); 1471 snd_printdd("invalid format width %d\n",
1472 snd_pcm_format_width(format));
1410 return 0; 1473 return 0;
1411 } 1474 }
1412 1475
@@ -1439,7 +1502,7 @@ int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid,
1439 if (val == -1) 1502 if (val == -1)
1440 return -EIO; 1503 return -EIO;
1441 } 1504 }
1442 if (! val) 1505 if (!val)
1443 val = snd_hda_param_read(codec, codec->afg, AC_PAR_PCM); 1506 val = snd_hda_param_read(codec, codec->afg, AC_PAR_PCM);
1444 1507
1445 if (ratesp) { 1508 if (ratesp) {
@@ -1460,8 +1523,9 @@ int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid,
1460 streams = snd_hda_param_read(codec, nid, AC_PAR_STREAM); 1523 streams = snd_hda_param_read(codec, nid, AC_PAR_STREAM);
1461 if (streams == -1) 1524 if (streams == -1)
1462 return -EIO; 1525 return -EIO;
1463 if (! streams) { 1526 if (!streams) {
1464 streams = snd_hda_param_read(codec, codec->afg, AC_PAR_STREAM); 1527 streams = snd_hda_param_read(codec, codec->afg,
1528 AC_PAR_STREAM);
1465 if (streams == -1) 1529 if (streams == -1)
1466 return -EIO; 1530 return -EIO;
1467 } 1531 }
@@ -1485,7 +1549,8 @@ int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid,
1485 bps = 24; 1549 bps = 24;
1486 else if (val & AC_SUPPCM_BITS_20) 1550 else if (val & AC_SUPPCM_BITS_20)
1487 bps = 20; 1551 bps = 20;
1488 } else if (val & (AC_SUPPCM_BITS_20|AC_SUPPCM_BITS_24|AC_SUPPCM_BITS_32)) { 1552 } else if (val & (AC_SUPPCM_BITS_20|AC_SUPPCM_BITS_24|
1553 AC_SUPPCM_BITS_32)) {
1489 formats |= SNDRV_PCM_FMTBIT_S32_LE; 1554 formats |= SNDRV_PCM_FMTBIT_S32_LE;
1490 if (val & AC_SUPPCM_BITS_32) 1555 if (val & AC_SUPPCM_BITS_32)
1491 bps = 32; 1556 bps = 32;
@@ -1495,10 +1560,12 @@ int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid,
1495 bps = 20; 1560 bps = 20;
1496 } 1561 }
1497 } 1562 }
1498 else if (streams == AC_SUPFMT_FLOAT32) { /* should be exclusive */ 1563 else if (streams == AC_SUPFMT_FLOAT32) {
1564 /* should be exclusive */
1499 formats |= SNDRV_PCM_FMTBIT_FLOAT_LE; 1565 formats |= SNDRV_PCM_FMTBIT_FLOAT_LE;
1500 bps = 32; 1566 bps = 32;
1501 } else if (streams == AC_SUPFMT_AC3) { /* should be exclusive */ 1567 } else if (streams == AC_SUPFMT_AC3) {
1568 /* should be exclusive */
1502 /* temporary hack: we have still no proper support 1569 /* temporary hack: we have still no proper support
1503 * for the direct AC3 stream... 1570 * for the direct AC3 stream...
1504 */ 1571 */
@@ -1515,7 +1582,8 @@ int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid,
1515} 1582}
1516 1583
1517/** 1584/**
1518 * snd_hda_is_supported_format - check whether the given node supports the format val 1585 * snd_hda_is_supported_format - check whether the given node supports
1586 * the format val
1519 * 1587 *
1520 * Returns 1 if supported, 0 if not. 1588 * Returns 1 if supported, 0 if not.
1521 */ 1589 */
@@ -1531,7 +1599,7 @@ int snd_hda_is_supported_format(struct hda_codec *codec, hda_nid_t nid,
1531 if (val == -1) 1599 if (val == -1)
1532 return 0; 1600 return 0;
1533 } 1601 }
1534 if (! val) { 1602 if (!val) {
1535 val = snd_hda_param_read(codec, codec->afg, AC_PAR_PCM); 1603 val = snd_hda_param_read(codec, codec->afg, AC_PAR_PCM);
1536 if (val == -1) 1604 if (val == -1)
1537 return 0; 1605 return 0;
@@ -1550,31 +1618,31 @@ int snd_hda_is_supported_format(struct hda_codec *codec, hda_nid_t nid,
1550 stream = snd_hda_param_read(codec, nid, AC_PAR_STREAM); 1618 stream = snd_hda_param_read(codec, nid, AC_PAR_STREAM);
1551 if (stream == -1) 1619 if (stream == -1)
1552 return 0; 1620 return 0;
1553 if (! stream && nid != codec->afg) 1621 if (!stream && nid != codec->afg)
1554 stream = snd_hda_param_read(codec, codec->afg, AC_PAR_STREAM); 1622 stream = snd_hda_param_read(codec, codec->afg, AC_PAR_STREAM);
1555 if (! stream || stream == -1) 1623 if (!stream || stream == -1)
1556 return 0; 1624 return 0;
1557 1625
1558 if (stream & AC_SUPFMT_PCM) { 1626 if (stream & AC_SUPFMT_PCM) {
1559 switch (format & 0xf0) { 1627 switch (format & 0xf0) {
1560 case 0x00: 1628 case 0x00:
1561 if (! (val & AC_SUPPCM_BITS_8)) 1629 if (!(val & AC_SUPPCM_BITS_8))
1562 return 0; 1630 return 0;
1563 break; 1631 break;
1564 case 0x10: 1632 case 0x10:
1565 if (! (val & AC_SUPPCM_BITS_16)) 1633 if (!(val & AC_SUPPCM_BITS_16))
1566 return 0; 1634 return 0;
1567 break; 1635 break;
1568 case 0x20: 1636 case 0x20:
1569 if (! (val & AC_SUPPCM_BITS_20)) 1637 if (!(val & AC_SUPPCM_BITS_20))
1570 return 0; 1638 return 0;
1571 break; 1639 break;
1572 case 0x30: 1640 case 0x30:
1573 if (! (val & AC_SUPPCM_BITS_24)) 1641 if (!(val & AC_SUPPCM_BITS_24))
1574 return 0; 1642 return 0;
1575 break; 1643 break;
1576 case 0x40: 1644 case 0x40:
1577 if (! (val & AC_SUPPCM_BITS_32)) 1645 if (!(val & AC_SUPPCM_BITS_32))
1578 return 0; 1646 return 0;
1579 break; 1647 break;
1580 default: 1648 default:
@@ -1615,15 +1683,15 @@ static int hda_pcm_default_cleanup(struct hda_pcm_stream *hinfo,
1615 return 0; 1683 return 0;
1616} 1684}
1617 1685
1618static int set_pcm_default_values(struct hda_codec *codec, struct hda_pcm_stream *info) 1686static int __devinit set_pcm_default_values(struct hda_codec *codec,
1687 struct hda_pcm_stream *info)
1619{ 1688{
1620 if (info->nid) { 1689 /* query support PCM information from the given NID */
1621 /* query support PCM information from the given NID */ 1690 if (info->nid && (!info->rates || !info->formats)) {
1622 if (! info->rates || ! info->formats) 1691 snd_hda_query_supported_pcm(codec, info->nid,
1623 snd_hda_query_supported_pcm(codec, info->nid, 1692 info->rates ? NULL : &info->rates,
1624 info->rates ? NULL : &info->rates, 1693 info->formats ? NULL : &info->formats,
1625 info->formats ? NULL : &info->formats, 1694 info->maxbps ? NULL : &info->maxbps);
1626 info->maxbps ? NULL : &info->maxbps);
1627 } 1695 }
1628 if (info->ops.open == NULL) 1696 if (info->ops.open == NULL)
1629 info->ops.open = hda_pcm_default_open_close; 1697 info->ops.open = hda_pcm_default_open_close;
@@ -1668,13 +1736,12 @@ static int set_pcm_default_values(struct hda_codec *codec, struct hda_pcm_stream
1668 */ 1736 */
1669int __devinit snd_hda_build_pcms(struct hda_bus *bus) 1737int __devinit snd_hda_build_pcms(struct hda_bus *bus)
1670{ 1738{
1671 struct list_head *p; 1739 struct hda_codec *codec;
1672 1740
1673 list_for_each(p, &bus->codec_list) { 1741 list_for_each_entry(codec, &bus->codec_list, list) {
1674 struct hda_codec *codec = list_entry(p, struct hda_codec, list);
1675 unsigned int pcm, s; 1742 unsigned int pcm, s;
1676 int err; 1743 int err;
1677 if (! codec->patch_ops.build_pcms) 1744 if (!codec->patch_ops.build_pcms)
1678 continue; 1745 continue;
1679 err = codec->patch_ops.build_pcms(codec); 1746 err = codec->patch_ops.build_pcms(codec);
1680 if (err < 0) 1747 if (err < 0)
@@ -1683,7 +1750,7 @@ int __devinit snd_hda_build_pcms(struct hda_bus *bus)
1683 for (s = 0; s < 2; s++) { 1750 for (s = 0; s < 2; s++) {
1684 struct hda_pcm_stream *info; 1751 struct hda_pcm_stream *info;
1685 info = &codec->pcm_info[pcm].stream[s]; 1752 info = &codec->pcm_info[pcm].stream[s];
1686 if (! info->substreams) 1753 if (!info->substreams)
1687 continue; 1754 continue;
1688 err = set_pcm_default_values(codec, info); 1755 err = set_pcm_default_values(codec, info);
1689 if (err < 0) 1756 if (err < 0)
@@ -1767,17 +1834,18 @@ int __devinit snd_hda_add_new_ctls(struct hda_codec *codec,
1767 for (; knew->name; knew++) { 1834 for (; knew->name; knew++) {
1768 struct snd_kcontrol *kctl; 1835 struct snd_kcontrol *kctl;
1769 kctl = snd_ctl_new1(knew, codec); 1836 kctl = snd_ctl_new1(knew, codec);
1770 if (! kctl) 1837 if (!kctl)
1771 return -ENOMEM; 1838 return -ENOMEM;
1772 err = snd_ctl_add(codec->bus->card, kctl); 1839 err = snd_ctl_add(codec->bus->card, kctl);
1773 if (err < 0) { 1840 if (err < 0) {
1774 if (! codec->addr) 1841 if (!codec->addr)
1775 return err; 1842 return err;
1776 kctl = snd_ctl_new1(knew, codec); 1843 kctl = snd_ctl_new1(knew, codec);
1777 if (! kctl) 1844 if (!kctl)
1778 return -ENOMEM; 1845 return -ENOMEM;
1779 kctl->id.device = codec->addr; 1846 kctl->id.device = codec->addr;
1780 if ((err = snd_ctl_add(codec->bus->card, kctl)) < 0) 1847 err = snd_ctl_add(codec->bus->card, kctl);
1848 if (err < 0)
1781 return err; 1849 return err;
1782 } 1850 }
1783 } 1851 }
@@ -1788,8 +1856,10 @@ int __devinit snd_hda_add_new_ctls(struct hda_codec *codec,
1788/* 1856/*
1789 * Channel mode helper 1857 * Channel mode helper
1790 */ 1858 */
1791int snd_hda_ch_mode_info(struct hda_codec *codec, struct snd_ctl_elem_info *uinfo, 1859int snd_hda_ch_mode_info(struct hda_codec *codec,
1792 const struct hda_channel_mode *chmode, int num_chmodes) 1860 struct snd_ctl_elem_info *uinfo,
1861 const struct hda_channel_mode *chmode,
1862 int num_chmodes)
1793{ 1863{
1794 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1864 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1795 uinfo->count = 1; 1865 uinfo->count = 1;
@@ -1801,8 +1871,10 @@ int snd_hda_ch_mode_info(struct hda_codec *codec, struct snd_ctl_elem_info *uinf
1801 return 0; 1871 return 0;
1802} 1872}
1803 1873
1804int snd_hda_ch_mode_get(struct hda_codec *codec, struct snd_ctl_elem_value *ucontrol, 1874int snd_hda_ch_mode_get(struct hda_codec *codec,
1805 const struct hda_channel_mode *chmode, int num_chmodes, 1875 struct snd_ctl_elem_value *ucontrol,
1876 const struct hda_channel_mode *chmode,
1877 int num_chmodes,
1806 int max_channels) 1878 int max_channels)
1807{ 1879{
1808 int i; 1880 int i;
@@ -1816,15 +1888,17 @@ int snd_hda_ch_mode_get(struct hda_codec *codec, struct snd_ctl_elem_value *ucon
1816 return 0; 1888 return 0;
1817} 1889}
1818 1890
1819int snd_hda_ch_mode_put(struct hda_codec *codec, struct snd_ctl_elem_value *ucontrol, 1891int snd_hda_ch_mode_put(struct hda_codec *codec,
1820 const struct hda_channel_mode *chmode, int num_chmodes, 1892 struct snd_ctl_elem_value *ucontrol,
1893 const struct hda_channel_mode *chmode,
1894 int num_chmodes,
1821 int *max_channelsp) 1895 int *max_channelsp)
1822{ 1896{
1823 unsigned int mode; 1897 unsigned int mode;
1824 1898
1825 mode = ucontrol->value.enumerated.item[0]; 1899 mode = ucontrol->value.enumerated.item[0];
1826 snd_assert(mode < num_chmodes, return -EINVAL); 1900 snd_assert(mode < num_chmodes, return -EINVAL);
1827 if (*max_channelsp == chmode[mode].channels && ! codec->in_resume) 1901 if (*max_channelsp == chmode[mode].channels && !codec->in_resume)
1828 return 0; 1902 return 0;
1829 /* change the current channel setting */ 1903 /* change the current channel setting */
1830 *max_channelsp = chmode[mode].channels; 1904 *max_channelsp = chmode[mode].channels;
@@ -1836,7 +1910,8 @@ int snd_hda_ch_mode_put(struct hda_codec *codec, struct snd_ctl_elem_value *ucon
1836/* 1910/*
1837 * input MUX helper 1911 * input MUX helper
1838 */ 1912 */
1839int snd_hda_input_mux_info(const struct hda_input_mux *imux, struct snd_ctl_elem_info *uinfo) 1913int snd_hda_input_mux_info(const struct hda_input_mux *imux,
1914 struct snd_ctl_elem_info *uinfo)
1840{ 1915{
1841 unsigned int index; 1916 unsigned int index;
1842 1917
@@ -1850,8 +1925,10 @@ int snd_hda_input_mux_info(const struct hda_input_mux *imux, struct snd_ctl_elem
1850 return 0; 1925 return 0;
1851} 1926}
1852 1927
1853int snd_hda_input_mux_put(struct hda_codec *codec, const struct hda_input_mux *imux, 1928int snd_hda_input_mux_put(struct hda_codec *codec,
1854 struct snd_ctl_elem_value *ucontrol, hda_nid_t nid, 1929 const struct hda_input_mux *imux,
1930 struct snd_ctl_elem_value *ucontrol,
1931 hda_nid_t nid,
1855 unsigned int *cur_val) 1932 unsigned int *cur_val)
1856{ 1933{
1857 unsigned int idx; 1934 unsigned int idx;
@@ -1859,7 +1936,7 @@ int snd_hda_input_mux_put(struct hda_codec *codec, const struct hda_input_mux *i
1859 idx = ucontrol->value.enumerated.item[0]; 1936 idx = ucontrol->value.enumerated.item[0];
1860 if (idx >= imux->num_items) 1937 if (idx >= imux->num_items)
1861 idx = imux->num_items - 1; 1938 idx = imux->num_items - 1;
1862 if (*cur_val == idx && ! codec->in_resume) 1939 if (*cur_val == idx && !codec->in_resume)
1863 return 0; 1940 return 0;
1864 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, 1941 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL,
1865 imux->items[idx].index); 1942 imux->items[idx].index);
@@ -1890,7 +1967,8 @@ static void setup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid,
1890/* 1967/*
1891 * open the digital out in the exclusive mode 1968 * open the digital out in the exclusive mode
1892 */ 1969 */
1893int snd_hda_multi_out_dig_open(struct hda_codec *codec, struct hda_multi_out *mout) 1970int snd_hda_multi_out_dig_open(struct hda_codec *codec,
1971 struct hda_multi_out *mout)
1894{ 1972{
1895 mutex_lock(&codec->spdif_mutex); 1973 mutex_lock(&codec->spdif_mutex);
1896 if (mout->dig_out_used == HDA_DIG_ANALOG_DUP) 1974 if (mout->dig_out_used == HDA_DIG_ANALOG_DUP)
@@ -1916,7 +1994,8 @@ int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
1916/* 1994/*
1917 * release the digital out 1995 * release the digital out
1918 */ 1996 */
1919int snd_hda_multi_out_dig_close(struct hda_codec *codec, struct hda_multi_out *mout) 1997int snd_hda_multi_out_dig_close(struct hda_codec *codec,
1998 struct hda_multi_out *mout)
1920{ 1999{
1921 mutex_lock(&codec->spdif_mutex); 2000 mutex_lock(&codec->spdif_mutex);
1922 mout->dig_out_used = 0; 2001 mout->dig_out_used = 0;
@@ -1927,7 +2006,8 @@ int snd_hda_multi_out_dig_close(struct hda_codec *codec, struct hda_multi_out *m
1927/* 2006/*
1928 * set up more restrictions for analog out 2007 * set up more restrictions for analog out
1929 */ 2008 */
1930int snd_hda_multi_out_analog_open(struct hda_codec *codec, struct hda_multi_out *mout, 2009int snd_hda_multi_out_analog_open(struct hda_codec *codec,
2010 struct hda_multi_out *mout,
1931 struct snd_pcm_substream *substream) 2011 struct snd_pcm_substream *substream)
1932{ 2012{
1933 substream->runtime->hw.channels_max = mout->max_channels; 2013 substream->runtime->hw.channels_max = mout->max_channels;
@@ -1939,7 +2019,8 @@ int snd_hda_multi_out_analog_open(struct hda_codec *codec, struct hda_multi_out
1939 * set up the i/o for analog out 2019 * set up the i/o for analog out
1940 * when the digital out is available, copy the front out to digital out, too. 2020 * when the digital out is available, copy the front out to digital out, too.
1941 */ 2021 */
1942int snd_hda_multi_out_analog_prepare(struct hda_codec *codec, struct hda_multi_out *mout, 2022int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
2023 struct hda_multi_out *mout,
1943 unsigned int stream_tag, 2024 unsigned int stream_tag,
1944 unsigned int format, 2025 unsigned int format,
1945 struct snd_pcm_substream *substream) 2026 struct snd_pcm_substream *substream)
@@ -1951,23 +2032,27 @@ int snd_hda_multi_out_analog_prepare(struct hda_codec *codec, struct hda_multi_o
1951 mutex_lock(&codec->spdif_mutex); 2032 mutex_lock(&codec->spdif_mutex);
1952 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) { 2033 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
1953 if (chs == 2 && 2034 if (chs == 2 &&
1954 snd_hda_is_supported_format(codec, mout->dig_out_nid, format) && 2035 snd_hda_is_supported_format(codec, mout->dig_out_nid,
1955 ! (codec->spdif_status & IEC958_AES0_NONAUDIO)) { 2036 format) &&
2037 !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
1956 mout->dig_out_used = HDA_DIG_ANALOG_DUP; 2038 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
1957 setup_dig_out_stream(codec, mout->dig_out_nid, 2039 setup_dig_out_stream(codec, mout->dig_out_nid,
1958 stream_tag, format); 2040 stream_tag, format);
1959 } else { 2041 } else {
1960 mout->dig_out_used = 0; 2042 mout->dig_out_used = 0;
1961 snd_hda_codec_setup_stream(codec, mout->dig_out_nid, 0, 0, 0); 2043 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
2044 0, 0, 0);
1962 } 2045 }
1963 } 2046 }
1964 mutex_unlock(&codec->spdif_mutex); 2047 mutex_unlock(&codec->spdif_mutex);
1965 2048
1966 /* front */ 2049 /* front */
1967 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag, 0, format); 2050 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
2051 0, format);
1968 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]) 2052 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT])
1969 /* headphone out will just decode front left/right (stereo) */ 2053 /* headphone out will just decode front left/right (stereo) */
1970 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag, 0, format); 2054 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
2055 0, format);
1971 /* extra outputs copied from front */ 2056 /* extra outputs copied from front */
1972 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++) 2057 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1973 if (mout->extra_out_nid[i]) 2058 if (mout->extra_out_nid[i])
@@ -1978,11 +2063,11 @@ int snd_hda_multi_out_analog_prepare(struct hda_codec *codec, struct hda_multi_o
1978 /* surrounds */ 2063 /* surrounds */
1979 for (i = 1; i < mout->num_dacs; i++) { 2064 for (i = 1; i < mout->num_dacs; i++) {
1980 if (chs >= (i + 1) * 2) /* independent out */ 2065 if (chs >= (i + 1) * 2) /* independent out */
1981 snd_hda_codec_setup_stream(codec, nids[i], stream_tag, i * 2, 2066 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1982 format); 2067 i * 2, format);
1983 else /* copy front */ 2068 else /* copy front */
1984 snd_hda_codec_setup_stream(codec, nids[i], stream_tag, 0, 2069 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1985 format); 2070 0, format);
1986 } 2071 }
1987 return 0; 2072 return 0;
1988} 2073}
@@ -1990,7 +2075,8 @@ int snd_hda_multi_out_analog_prepare(struct hda_codec *codec, struct hda_multi_o
1990/* 2075/*
1991 * clean up the setting for analog out 2076 * clean up the setting for analog out
1992 */ 2077 */
1993int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec, struct hda_multi_out *mout) 2078int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
2079 struct hda_multi_out *mout)
1994{ 2080{
1995 hda_nid_t *nids = mout->dac_nids; 2081 hda_nid_t *nids = mout->dac_nids;
1996 int i; 2082 int i;
@@ -2058,7 +2144,8 @@ int __devinit snd_hda_parse_pin_def_config(struct hda_codec *codec,
2058 nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid_start); 2144 nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid_start);
2059 for (nid = nid_start; nid < nodes + nid_start; nid++) { 2145 for (nid = nid_start; nid < nodes + nid_start; nid++) {
2060 unsigned int wid_caps = get_wcaps(codec, nid); 2146 unsigned int wid_caps = get_wcaps(codec, nid);
2061 unsigned int wid_type = (wid_caps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; 2147 unsigned int wid_type =
2148 (wid_caps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
2062 unsigned int def_conf; 2149 unsigned int def_conf;
2063 short assoc, loc; 2150 short assoc, loc;
2064 2151
@@ -2069,7 +2156,8 @@ int __devinit snd_hda_parse_pin_def_config(struct hda_codec *codec,
2069 if (ignore_nids && is_in_nid_list(nid, ignore_nids)) 2156 if (ignore_nids && is_in_nid_list(nid, ignore_nids))
2070 continue; 2157 continue;
2071 2158
2072 def_conf = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONFIG_DEFAULT, 0); 2159 def_conf = snd_hda_codec_read(codec, nid, 0,
2160 AC_VERB_GET_CONFIG_DEFAULT, 0);
2073 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE) 2161 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
2074 continue; 2162 continue;
2075 loc = get_defcfg_location(def_conf); 2163 loc = get_defcfg_location(def_conf);
@@ -2077,9 +2165,9 @@ int __devinit snd_hda_parse_pin_def_config(struct hda_codec *codec,
2077 case AC_JACK_LINE_OUT: 2165 case AC_JACK_LINE_OUT:
2078 seq = get_defcfg_sequence(def_conf); 2166 seq = get_defcfg_sequence(def_conf);
2079 assoc = get_defcfg_association(def_conf); 2167 assoc = get_defcfg_association(def_conf);
2080 if (! assoc) 2168 if (!assoc)
2081 continue; 2169 continue;
2082 if (! assoc_line_out) 2170 if (!assoc_line_out)
2083 assoc_line_out = assoc; 2171 assoc_line_out = assoc;
2084 else if (assoc_line_out != assoc) 2172 else if (assoc_line_out != assoc)
2085 continue; 2173 continue;
@@ -2198,7 +2286,7 @@ int __devinit snd_hda_parse_pin_def_config(struct hda_codec *codec,
2198 * FIX-UP: if no line-outs are detected, try to use speaker or HP pin 2286 * FIX-UP: if no line-outs are detected, try to use speaker or HP pin
2199 * as a primary output 2287 * as a primary output
2200 */ 2288 */
2201 if (! cfg->line_outs) { 2289 if (!cfg->line_outs) {
2202 if (cfg->speaker_outs) { 2290 if (cfg->speaker_outs) {
2203 cfg->line_outs = cfg->speaker_outs; 2291 cfg->line_outs = cfg->speaker_outs;
2204 memcpy(cfg->line_out_pins, cfg->speaker_pins, 2292 memcpy(cfg->line_out_pins, cfg->speaker_pins,
@@ -2237,11 +2325,10 @@ const char *auto_pin_cfg_labels[AUTO_PIN_LAST] = {
2237 */ 2325 */
2238int snd_hda_suspend(struct hda_bus *bus, pm_message_t state) 2326int snd_hda_suspend(struct hda_bus *bus, pm_message_t state)
2239{ 2327{
2240 struct list_head *p; 2328 struct hda_codec *codec;
2241 2329
2242 /* FIXME: should handle power widget capabilities */ 2330 /* FIXME: should handle power widget capabilities */
2243 list_for_each(p, &bus->codec_list) { 2331 list_for_each_entry(codec, &bus->codec_list, list) {
2244 struct hda_codec *codec = list_entry(p, struct hda_codec, list);
2245 if (codec->patch_ops.suspend) 2332 if (codec->patch_ops.suspend)
2246 codec->patch_ops.suspend(codec, state); 2333 codec->patch_ops.suspend(codec, state);
2247 hda_set_power_state(codec, 2334 hda_set_power_state(codec,
@@ -2260,10 +2347,9 @@ int snd_hda_suspend(struct hda_bus *bus, pm_message_t state)
2260 */ 2347 */
2261int snd_hda_resume(struct hda_bus *bus) 2348int snd_hda_resume(struct hda_bus *bus)
2262{ 2349{
2263 struct list_head *p; 2350 struct hda_codec *codec;
2264 2351
2265 list_for_each(p, &bus->codec_list) { 2352 list_for_each_entry(codec, &bus->codec_list, list) {
2266 struct hda_codec *codec = list_entry(p, struct hda_codec, list);
2267 hda_set_power_state(codec, 2353 hda_set_power_state(codec,
2268 codec->afg ? codec->afg : codec->mfg, 2354 codec->afg ? codec->afg : codec->mfg,
2269 AC_PWRST_D0); 2355 AC_PWRST_D0);
@@ -2287,7 +2373,7 @@ int snd_hda_resume_ctls(struct hda_codec *codec, struct snd_kcontrol_new *knew)
2287 struct snd_ctl_elem_value *val; 2373 struct snd_ctl_elem_value *val;
2288 2374
2289 val = kmalloc(sizeof(*val), GFP_KERNEL); 2375 val = kmalloc(sizeof(*val), GFP_KERNEL);
2290 if (! val) 2376 if (!val)
2291 return -ENOMEM; 2377 return -ENOMEM;
2292 codec->in_resume = 1; 2378 codec->in_resume = 1;
2293 for (; knew->name; knew++) { 2379 for (; knew->name; knew++) {