aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/hda/hda_codec.c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2008-12-25 05:40:28 -0500
committerTakashi Iwai <tiwai@suse.de>2008-12-25 05:40:28 -0500
commita65056205cdf7efb96fb2558e4f1ec6bae2582ed (patch)
tree22a5fa35464f26183e34aa4210fa6c145f24ddf3 /sound/pci/hda/hda_codec.c
parent313769d9edb1bbd59d2e94f5069950eecfe6fa44 (diff)
parent7645c4bfbb36f357f03815f5729c46ce8d89f008 (diff)
Merge branch 'topic/hda' into to-push
Diffstat (limited to 'sound/pci/hda/hda_codec.c')
-rw-r--r--sound/pci/hda/hda_codec.c781
1 files changed, 605 insertions, 176 deletions
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index eb9164176dab..e16cf63821ae 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -31,15 +31,6 @@
31#include <sound/initval.h> 31#include <sound/initval.h>
32#include "hda_local.h" 32#include "hda_local.h"
33#include <sound/hda_hwdep.h> 33#include <sound/hda_hwdep.h>
34#include "hda_patch.h" /* codec presets */
35
36#ifdef CONFIG_SND_HDA_POWER_SAVE
37/* define this option here to hide as static */
38static int power_save = CONFIG_SND_HDA_POWER_SAVE_DEFAULT;
39module_param(power_save, int, 0644);
40MODULE_PARM_DESC(power_save, "Automatic power-saving timeout "
41 "(in second, 0 = disable).");
42#endif
43 34
44/* 35/*
45 * vendor / preset table 36 * vendor / preset table
@@ -55,6 +46,7 @@ static struct hda_vendor_id hda_vendor_ids[] = {
55 { 0x1002, "ATI" }, 46 { 0x1002, "ATI" },
56 { 0x1057, "Motorola" }, 47 { 0x1057, "Motorola" },
57 { 0x1095, "Silicon Image" }, 48 { 0x1095, "Silicon Image" },
49 { 0x10de, "Nvidia" },
58 { 0x10ec, "Realtek" }, 50 { 0x10ec, "Realtek" },
59 { 0x1106, "VIA" }, 51 { 0x1106, "VIA" },
60 { 0x111d, "IDT" }, 52 { 0x111d, "IDT" },
@@ -66,40 +58,31 @@ static struct hda_vendor_id hda_vendor_ids[] = {
66 { 0x1854, "LG" }, 58 { 0x1854, "LG" },
67 { 0x1aec, "Wolfson Microelectronics" }, 59 { 0x1aec, "Wolfson Microelectronics" },
68 { 0x434d, "C-Media" }, 60 { 0x434d, "C-Media" },
61 { 0x8086, "Intel" },
69 { 0x8384, "SigmaTel" }, 62 { 0x8384, "SigmaTel" },
70 {} /* terminator */ 63 {} /* terminator */
71}; 64};
72 65
73static const struct hda_codec_preset *hda_preset_tables[] = { 66static DEFINE_MUTEX(preset_mutex);
74#ifdef CONFIG_SND_HDA_CODEC_REALTEK 67static LIST_HEAD(hda_preset_tables);
75 snd_hda_preset_realtek, 68
76#endif 69int snd_hda_add_codec_preset(struct hda_codec_preset_list *preset)
77#ifdef CONFIG_SND_HDA_CODEC_CMEDIA 70{
78 snd_hda_preset_cmedia, 71 mutex_lock(&preset_mutex);
79#endif 72 list_add_tail(&preset->list, &hda_preset_tables);
80#ifdef CONFIG_SND_HDA_CODEC_ANALOG 73 mutex_unlock(&preset_mutex);
81 snd_hda_preset_analog, 74 return 0;
82#endif 75}
83#ifdef CONFIG_SND_HDA_CODEC_SIGMATEL 76EXPORT_SYMBOL_HDA(snd_hda_add_codec_preset);
84 snd_hda_preset_sigmatel, 77
85#endif 78int snd_hda_delete_codec_preset(struct hda_codec_preset_list *preset)
86#ifdef CONFIG_SND_HDA_CODEC_SI3054 79{
87 snd_hda_preset_si3054, 80 mutex_lock(&preset_mutex);
88#endif 81 list_del(&preset->list);
89#ifdef CONFIG_SND_HDA_CODEC_ATIHDMI 82 mutex_unlock(&preset_mutex);
90 snd_hda_preset_atihdmi, 83 return 0;
91#endif 84}
92#ifdef CONFIG_SND_HDA_CODEC_CONEXANT 85EXPORT_SYMBOL_HDA(snd_hda_delete_codec_preset);
93 snd_hda_preset_conexant,
94#endif
95#ifdef CONFIG_SND_HDA_CODEC_VIA
96 snd_hda_preset_via,
97#endif
98#ifdef CONFIG_SND_HDA_CODEC_NVHDMI
99 snd_hda_preset_nvhdmi,
100#endif
101 NULL
102};
103 86
104#ifdef CONFIG_SND_HDA_POWER_SAVE 87#ifdef CONFIG_SND_HDA_POWER_SAVE
105static void hda_power_work(struct work_struct *work); 88static void hda_power_work(struct work_struct *work);
@@ -108,6 +91,72 @@ static void hda_keep_power_on(struct hda_codec *codec);
108static inline void hda_keep_power_on(struct hda_codec *codec) {} 91static inline void hda_keep_power_on(struct hda_codec *codec) {}
109#endif 92#endif
110 93
94const char *snd_hda_get_jack_location(u32 cfg)
95{
96 static char *bases[7] = {
97 "N/A", "Rear", "Front", "Left", "Right", "Top", "Bottom",
98 };
99 static unsigned char specials_idx[] = {
100 0x07, 0x08,
101 0x17, 0x18, 0x19,
102 0x37, 0x38
103 };
104 static char *specials[] = {
105 "Rear Panel", "Drive Bar",
106 "Riser", "HDMI", "ATAPI",
107 "Mobile-In", "Mobile-Out"
108 };
109 int i;
110 cfg = (cfg & AC_DEFCFG_LOCATION) >> AC_DEFCFG_LOCATION_SHIFT;
111 if ((cfg & 0x0f) < 7)
112 return bases[cfg & 0x0f];
113 for (i = 0; i < ARRAY_SIZE(specials_idx); i++) {
114 if (cfg == specials_idx[i])
115 return specials[i];
116 }
117 return "UNKNOWN";
118}
119EXPORT_SYMBOL_HDA(snd_hda_get_jack_location);
120
121const char *snd_hda_get_jack_connectivity(u32 cfg)
122{
123 static char *jack_locations[4] = { "Ext", "Int", "Sep", "Oth" };
124
125 return jack_locations[(cfg >> (AC_DEFCFG_LOCATION_SHIFT + 4)) & 3];
126}
127EXPORT_SYMBOL_HDA(snd_hda_get_jack_connectivity);
128
129const char *snd_hda_get_jack_type(u32 cfg)
130{
131 static char *jack_types[16] = {
132 "Line Out", "Speaker", "HP Out", "CD",
133 "SPDIF Out", "Digital Out", "Modem Line", "Modem Hand",
134 "Line In", "Aux", "Mic", "Telephony",
135 "SPDIF In", "Digitial In", "Reserved", "Other"
136 };
137
138 return jack_types[(cfg & AC_DEFCFG_DEVICE)
139 >> AC_DEFCFG_DEVICE_SHIFT];
140}
141EXPORT_SYMBOL_HDA(snd_hda_get_jack_type);
142
143/*
144 * Compose a 32bit command word to be sent to the HD-audio controller
145 */
146static inline unsigned int
147make_codec_cmd(struct hda_codec *codec, hda_nid_t nid, int direct,
148 unsigned int verb, unsigned int parm)
149{
150 u32 val;
151
152 val = (u32)(codec->addr & 0x0f) << 28;
153 val |= (u32)direct << 27;
154 val |= (u32)nid << 20;
155 val |= verb << 8;
156 val |= parm;
157 return val;
158}
159
111/** 160/**
112 * snd_hda_codec_read - send a command and get the response 161 * snd_hda_codec_read - send a command and get the response
113 * @codec: the HDA codec 162 * @codec: the HDA codec
@@ -124,17 +173,21 @@ unsigned int snd_hda_codec_read(struct hda_codec *codec, hda_nid_t nid,
124 int direct, 173 int direct,
125 unsigned int verb, unsigned int parm) 174 unsigned int verb, unsigned int parm)
126{ 175{
176 struct hda_bus *bus = codec->bus;
127 unsigned int res; 177 unsigned int res;
178
179 res = make_codec_cmd(codec, nid, direct, verb, parm);
128 snd_hda_power_up(codec); 180 snd_hda_power_up(codec);
129 mutex_lock(&codec->bus->cmd_mutex); 181 mutex_lock(&bus->cmd_mutex);
130 if (!codec->bus->ops.command(codec, nid, direct, verb, parm)) 182 if (!bus->ops.command(bus, res))
131 res = codec->bus->ops.get_response(codec); 183 res = bus->ops.get_response(bus);
132 else 184 else
133 res = (unsigned int)-1; 185 res = (unsigned int)-1;
134 mutex_unlock(&codec->bus->cmd_mutex); 186 mutex_unlock(&bus->cmd_mutex);
135 snd_hda_power_down(codec); 187 snd_hda_power_down(codec);
136 return res; 188 return res;
137} 189}
190EXPORT_SYMBOL_HDA(snd_hda_codec_read);
138 191
139/** 192/**
140 * snd_hda_codec_write - send a single command without waiting for response 193 * snd_hda_codec_write - send a single command without waiting for response
@@ -151,14 +204,19 @@ unsigned int snd_hda_codec_read(struct hda_codec *codec, hda_nid_t nid,
151int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int direct, 204int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int direct,
152 unsigned int verb, unsigned int parm) 205 unsigned int verb, unsigned int parm)
153{ 206{
207 struct hda_bus *bus = codec->bus;
208 unsigned int res;
154 int err; 209 int err;
210
211 res = make_codec_cmd(codec, nid, direct, verb, parm);
155 snd_hda_power_up(codec); 212 snd_hda_power_up(codec);
156 mutex_lock(&codec->bus->cmd_mutex); 213 mutex_lock(&bus->cmd_mutex);
157 err = codec->bus->ops.command(codec, nid, direct, verb, parm); 214 err = bus->ops.command(bus, res);
158 mutex_unlock(&codec->bus->cmd_mutex); 215 mutex_unlock(&bus->cmd_mutex);
159 snd_hda_power_down(codec); 216 snd_hda_power_down(codec);
160 return err; 217 return err;
161} 218}
219EXPORT_SYMBOL_HDA(snd_hda_codec_write);
162 220
163/** 221/**
164 * snd_hda_sequence_write - sequence writes 222 * snd_hda_sequence_write - sequence writes
@@ -173,6 +231,7 @@ void snd_hda_sequence_write(struct hda_codec *codec, const struct hda_verb *seq)
173 for (; seq->nid; seq++) 231 for (; seq->nid; seq++)
174 snd_hda_codec_write(codec, seq->nid, 0, seq->verb, seq->param); 232 snd_hda_codec_write(codec, seq->nid, 0, seq->verb, seq->param);
175} 233}
234EXPORT_SYMBOL_HDA(snd_hda_sequence_write);
176 235
177/** 236/**
178 * snd_hda_get_sub_nodes - get the range of sub nodes 237 * snd_hda_get_sub_nodes - get the range of sub nodes
@@ -194,6 +253,7 @@ int snd_hda_get_sub_nodes(struct hda_codec *codec, hda_nid_t nid,
194 *start_id = (parm >> 16) & 0x7fff; 253 *start_id = (parm >> 16) & 0x7fff;
195 return (int)(parm & 0x7fff); 254 return (int)(parm & 0x7fff);
196} 255}
256EXPORT_SYMBOL_HDA(snd_hda_get_sub_nodes);
197 257
198/** 258/**
199 * snd_hda_get_connections - get connection list 259 * snd_hda_get_connections - get connection list
@@ -282,6 +342,7 @@ int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
282 } 342 }
283 return conns; 343 return conns;
284} 344}
345EXPORT_SYMBOL_HDA(snd_hda_get_connections);
285 346
286 347
287/** 348/**
@@ -316,6 +377,7 @@ int snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex)
316 377
317 return 0; 378 return 0;
318} 379}
380EXPORT_SYMBOL_HDA(snd_hda_queue_unsol_event);
319 381
320/* 382/*
321 * process queued unsolicited events 383 * process queued unsolicited events
@@ -345,7 +407,7 @@ static void process_unsol_events(struct work_struct *work)
345/* 407/*
346 * initialize unsolicited queue 408 * initialize unsolicited queue
347 */ 409 */
348static int __devinit init_unsol_queue(struct hda_bus *bus) 410static int init_unsol_queue(struct hda_bus *bus)
349{ 411{
350 struct hda_bus_unsolicited *unsol; 412 struct hda_bus_unsolicited *unsol;
351 413
@@ -391,9 +453,24 @@ static int snd_hda_bus_free(struct hda_bus *bus)
391static int snd_hda_bus_dev_free(struct snd_device *device) 453static int snd_hda_bus_dev_free(struct snd_device *device)
392{ 454{
393 struct hda_bus *bus = device->device_data; 455 struct hda_bus *bus = device->device_data;
456 bus->shutdown = 1;
394 return snd_hda_bus_free(bus); 457 return snd_hda_bus_free(bus);
395} 458}
396 459
460#ifdef CONFIG_SND_HDA_HWDEP
461static int snd_hda_bus_dev_register(struct snd_device *device)
462{
463 struct hda_bus *bus = device->device_data;
464 struct hda_codec *codec;
465 list_for_each_entry(codec, &bus->codec_list, list) {
466 snd_hda_hwdep_add_sysfs(codec);
467 }
468 return 0;
469}
470#else
471#define snd_hda_bus_dev_register NULL
472#endif
473
397/** 474/**
398 * snd_hda_bus_new - create a HDA bus 475 * snd_hda_bus_new - create a HDA bus
399 * @card: the card entry 476 * @card: the card entry
@@ -402,13 +479,14 @@ static int snd_hda_bus_dev_free(struct snd_device *device)
402 * 479 *
403 * Returns 0 if successful, or a negative error code. 480 * Returns 0 if successful, or a negative error code.
404 */ 481 */
405int __devinit snd_hda_bus_new(struct snd_card *card, 482int /*__devinit*/ snd_hda_bus_new(struct snd_card *card,
406 const struct hda_bus_template *temp, 483 const struct hda_bus_template *temp,
407 struct hda_bus **busp) 484 struct hda_bus **busp)
408{ 485{
409 struct hda_bus *bus; 486 struct hda_bus *bus;
410 int err; 487 int err;
411 static struct snd_device_ops dev_ops = { 488 static struct snd_device_ops dev_ops = {
489 .dev_register = snd_hda_bus_dev_register,
412 .dev_free = snd_hda_bus_dev_free, 490 .dev_free = snd_hda_bus_dev_free,
413 }; 491 };
414 492
@@ -430,6 +508,7 @@ int __devinit snd_hda_bus_new(struct snd_card *card,
430 bus->private_data = temp->private_data; 508 bus->private_data = temp->private_data;
431 bus->pci = temp->pci; 509 bus->pci = temp->pci;
432 bus->modelname = temp->modelname; 510 bus->modelname = temp->modelname;
511 bus->power_save = temp->power_save;
433 bus->ops = temp->ops; 512 bus->ops = temp->ops;
434 513
435 mutex_init(&bus->cmd_mutex); 514 mutex_init(&bus->cmd_mutex);
@@ -444,27 +523,42 @@ int __devinit snd_hda_bus_new(struct snd_card *card,
444 *busp = bus; 523 *busp = bus;
445 return 0; 524 return 0;
446} 525}
526EXPORT_SYMBOL_HDA(snd_hda_bus_new);
447 527
448#ifdef CONFIG_SND_HDA_GENERIC 528#ifdef CONFIG_SND_HDA_GENERIC
449#define is_generic_config(codec) \ 529#define is_generic_config(codec) \
450 (codec->bus->modelname && !strcmp(codec->bus->modelname, "generic")) 530 (codec->modelname && !strcmp(codec->modelname, "generic"))
451#else 531#else
452#define is_generic_config(codec) 0 532#define is_generic_config(codec) 0
453#endif 533#endif
454 534
535#ifdef MODULE
536#define HDA_MODREQ_MAX_COUNT 2 /* two request_modules()'s */
537#else
538#define HDA_MODREQ_MAX_COUNT 0 /* all presets are statically linked */
539#endif
540
455/* 541/*
456 * find a matching codec preset 542 * find a matching codec preset
457 */ 543 */
458static const struct hda_codec_preset __devinit * 544static const struct hda_codec_preset *
459find_codec_preset(struct hda_codec *codec) 545find_codec_preset(struct hda_codec *codec)
460{ 546{
461 const struct hda_codec_preset **tbl, *preset; 547 struct hda_codec_preset_list *tbl;
548 const struct hda_codec_preset *preset;
549 int mod_requested = 0;
462 550
463 if (is_generic_config(codec)) 551 if (is_generic_config(codec))
464 return NULL; /* use the generic parser */ 552 return NULL; /* use the generic parser */
465 553
466 for (tbl = hda_preset_tables; *tbl; tbl++) { 554 again:
467 for (preset = *tbl; preset->id; preset++) { 555 mutex_lock(&preset_mutex);
556 list_for_each_entry(tbl, &hda_preset_tables, list) {
557 if (!try_module_get(tbl->owner)) {
558 snd_printk(KERN_ERR "hda_codec: cannot module_get\n");
559 continue;
560 }
561 for (preset = tbl->preset; preset->id; preset++) {
468 u32 mask = preset->mask; 562 u32 mask = preset->mask;
469 if (preset->afg && preset->afg != codec->afg) 563 if (preset->afg && preset->afg != codec->afg)
470 continue; 564 continue;
@@ -474,23 +568,40 @@ find_codec_preset(struct hda_codec *codec)
474 mask = ~0; 568 mask = ~0;
475 if (preset->id == (codec->vendor_id & mask) && 569 if (preset->id == (codec->vendor_id & mask) &&
476 (!preset->rev || 570 (!preset->rev ||
477 preset->rev == codec->revision_id)) 571 preset->rev == codec->revision_id)) {
572 mutex_unlock(&preset_mutex);
573 codec->owner = tbl->owner;
478 return preset; 574 return preset;
575 }
479 } 576 }
577 module_put(tbl->owner);
578 }
579 mutex_unlock(&preset_mutex);
580
581 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
582 char name[32];
583 if (!mod_requested)
584 snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
585 codec->vendor_id);
586 else
587 snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
588 (codec->vendor_id >> 16) & 0xffff);
589 request_module(name);
590 mod_requested++;
591 goto again;
480 } 592 }
481 return NULL; 593 return NULL;
482} 594}
483 595
484/* 596/*
485 * snd_hda_get_codec_name - store the codec name 597 * get_codec_name - store the codec name
486 */ 598 */
487void snd_hda_get_codec_name(struct hda_codec *codec, 599static int get_codec_name(struct hda_codec *codec)
488 char *name, int namelen)
489{ 600{
490 const struct hda_vendor_id *c; 601 const struct hda_vendor_id *c;
491 const char *vendor = NULL; 602 const char *vendor = NULL;
492 u16 vendor_id = codec->vendor_id >> 16; 603 u16 vendor_id = codec->vendor_id >> 16;
493 char tmp[16]; 604 char tmp[16], name[32];
494 605
495 for (c = hda_vendor_ids; c->id; c++) { 606 for (c = hda_vendor_ids; c->id; c++) {
496 if (c->id == vendor_id) { 607 if (c->id == vendor_id) {
@@ -503,16 +614,21 @@ void snd_hda_get_codec_name(struct hda_codec *codec,
503 vendor = tmp; 614 vendor = tmp;
504 } 615 }
505 if (codec->preset && codec->preset->name) 616 if (codec->preset && codec->preset->name)
506 snprintf(name, namelen, "%s %s", vendor, codec->preset->name); 617 snprintf(name, sizeof(name), "%s %s", vendor,
618 codec->preset->name);
507 else 619 else
508 snprintf(name, namelen, "%s ID %x", vendor, 620 snprintf(name, sizeof(name), "%s ID %x", vendor,
509 codec->vendor_id & 0xffff); 621 codec->vendor_id & 0xffff);
622 codec->name = kstrdup(name, GFP_KERNEL);
623 if (!codec->name)
624 return -ENOMEM;
625 return 0;
510} 626}
511 627
512/* 628/*
513 * look for an AFG and MFG nodes 629 * look for an AFG and MFG nodes
514 */ 630 */
515static void __devinit setup_fg_nodes(struct hda_codec *codec) 631static void /*__devinit*/ setup_fg_nodes(struct hda_codec *codec)
516{ 632{
517 int i, total_nodes; 633 int i, total_nodes;
518 hda_nid_t nid; 634 hda_nid_t nid;
@@ -571,11 +687,15 @@ static void snd_hda_codec_free(struct hda_codec *codec)
571 flush_scheduled_work(); 687 flush_scheduled_work();
572#endif 688#endif
573 list_del(&codec->list); 689 list_del(&codec->list);
690 snd_array_free(&codec->mixers);
574 codec->bus->caddr_tbl[codec->addr] = NULL; 691 codec->bus->caddr_tbl[codec->addr] = NULL;
575 if (codec->patch_ops.free) 692 if (codec->patch_ops.free)
576 codec->patch_ops.free(codec); 693 codec->patch_ops.free(codec);
694 module_put(codec->owner);
577 free_hda_cache(&codec->amp_cache); 695 free_hda_cache(&codec->amp_cache);
578 free_hda_cache(&codec->cmd_cache); 696 free_hda_cache(&codec->cmd_cache);
697 kfree(codec->name);
698 kfree(codec->modelname);
579 kfree(codec->wcaps); 699 kfree(codec->wcaps);
580 kfree(codec); 700 kfree(codec);
581} 701}
@@ -588,8 +708,8 @@ static void snd_hda_codec_free(struct hda_codec *codec)
588 * 708 *
589 * Returns 0 if successful, or a negative error code. 709 * Returns 0 if successful, or a negative error code.
590 */ 710 */
591int __devinit snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr, 711int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr,
592 struct hda_codec **codecp) 712 int do_init, struct hda_codec **codecp)
593{ 713{
594 struct hda_codec *codec; 714 struct hda_codec *codec;
595 char component[31]; 715 char component[31];
@@ -617,6 +737,14 @@ int __devinit snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr,
617 mutex_init(&codec->spdif_mutex); 737 mutex_init(&codec->spdif_mutex);
618 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info)); 738 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info));
619 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head)); 739 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head));
740 snd_array_init(&codec->mixers, sizeof(struct snd_kcontrol *), 32);
741 if (codec->bus->modelname) {
742 codec->modelname = kstrdup(codec->bus->modelname, GFP_KERNEL);
743 if (!codec->modelname) {
744 snd_hda_codec_free(codec);
745 return -ENODEV;
746 }
747 }
620 748
621#ifdef CONFIG_SND_HDA_POWER_SAVE 749#ifdef CONFIG_SND_HDA_POWER_SAVE
622 INIT_DELAYED_WORK(&codec->power_work, hda_power_work); 750 INIT_DELAYED_WORK(&codec->power_work, hda_power_work);
@@ -662,12 +790,44 @@ int __devinit snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr,
662 snd_hda_codec_read(codec, nid, 0, 790 snd_hda_codec_read(codec, nid, 0,
663 AC_VERB_GET_SUBSYSTEM_ID, 0); 791 AC_VERB_GET_SUBSYSTEM_ID, 0);
664 } 792 }
793 if (bus->modelname)
794 codec->modelname = kstrdup(bus->modelname, GFP_KERNEL);
795
796 if (do_init) {
797 err = snd_hda_codec_configure(codec);
798 if (err < 0) {
799 snd_hda_codec_free(codec);
800 return err;
801 }
802 }
803 snd_hda_codec_proc_new(codec);
804
805 snd_hda_create_hwdep(codec);
806
807 sprintf(component, "HDA:%08x,%08x,%08x", codec->vendor_id,
808 codec->subsystem_id, codec->revision_id);
809 snd_component_add(codec->bus->card, component);
810
811 if (codecp)
812 *codecp = codec;
813 return 0;
814}
815EXPORT_SYMBOL_HDA(snd_hda_codec_new);
816
817int snd_hda_codec_configure(struct hda_codec *codec)
818{
819 int err;
665 820
666 codec->preset = find_codec_preset(codec); 821 codec->preset = find_codec_preset(codec);
822 if (!codec->name) {
823 err = get_codec_name(codec);
824 if (err < 0)
825 return err;
826 }
667 /* audio codec should override the mixer name */ 827 /* audio codec should override the mixer name */
668 if (codec->afg || !*bus->card->mixername) 828 if (codec->afg || !*codec->bus->card->mixername)
669 snd_hda_get_codec_name(codec, bus->card->mixername, 829 strlcpy(codec->bus->card->mixername, codec->name,
670 sizeof(bus->card->mixername)); 830 sizeof(codec->bus->card->mixername));
671 831
672 if (is_generic_config(codec)) { 832 if (is_generic_config(codec)) {
673 err = snd_hda_parse_generic_codec(codec); 833 err = snd_hda_parse_generic_codec(codec);
@@ -684,25 +844,9 @@ int __devinit snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr,
684 printk(KERN_ERR "hda-codec: No codec parser is available\n"); 844 printk(KERN_ERR "hda-codec: No codec parser is available\n");
685 845
686 patched: 846 patched:
687 if (err < 0) { 847 if (!err && codec->patch_ops.unsol_event)
688 snd_hda_codec_free(codec); 848 err = init_unsol_queue(codec->bus);
689 return err; 849 return err;
690 }
691
692 if (codec->patch_ops.unsol_event)
693 init_unsol_queue(bus);
694
695 snd_hda_codec_proc_new(codec);
696#ifdef CONFIG_SND_HDA_HWDEP
697 snd_hda_create_hwdep(codec);
698#endif
699
700 sprintf(component, "HDA:%08x,%08x,%08x", codec->vendor_id, codec->subsystem_id, codec->revision_id);
701 snd_component_add(codec->bus->card, component);
702
703 if (codecp)
704 *codecp = codec;
705 return 0;
706} 850}
707 851
708/** 852/**
@@ -728,6 +872,7 @@ void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
728 msleep(1); 872 msleep(1);
729 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, format); 873 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, format);
730} 874}
875EXPORT_SYMBOL_HDA(snd_hda_codec_setup_stream);
731 876
732void snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid) 877void snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid)
733{ 878{
@@ -741,6 +886,7 @@ void snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid)
741 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, 0); 886 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, 0);
742#endif 887#endif
743} 888}
889EXPORT_SYMBOL_HDA(snd_hda_codec_cleanup_stream);
744 890
745/* 891/*
746 * amp access functions 892 * amp access functions
@@ -752,17 +898,17 @@ void snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid)
752#define INFO_AMP_VOL(ch) (1 << (1 + (ch))) 898#define INFO_AMP_VOL(ch) (1 << (1 + (ch)))
753 899
754/* initialize the hash table */ 900/* initialize the hash table */
755static void __devinit init_hda_cache(struct hda_cache_rec *cache, 901static void /*__devinit*/ init_hda_cache(struct hda_cache_rec *cache,
756 unsigned int record_size) 902 unsigned int record_size)
757{ 903{
758 memset(cache, 0, sizeof(*cache)); 904 memset(cache, 0, sizeof(*cache));
759 memset(cache->hash, 0xff, sizeof(cache->hash)); 905 memset(cache->hash, 0xff, sizeof(cache->hash));
760 cache->record_size = record_size; 906 snd_array_init(&cache->buf, record_size, 64);
761} 907}
762 908
763static void free_hda_cache(struct hda_cache_rec *cache) 909static void free_hda_cache(struct hda_cache_rec *cache)
764{ 910{
765 kfree(cache->buffer); 911 snd_array_free(&cache->buf);
766} 912}
767 913
768/* query the hash. allocate an entry if not found. */ 914/* query the hash. allocate an entry if not found. */
@@ -774,35 +920,17 @@ static struct hda_cache_head *get_alloc_hash(struct hda_cache_rec *cache,
774 struct hda_cache_head *info; 920 struct hda_cache_head *info;
775 921
776 while (cur != 0xffff) { 922 while (cur != 0xffff) {
777 info = (struct hda_cache_head *)(cache->buffer + 923 info = snd_array_elem(&cache->buf, cur);
778 cur * cache->record_size);
779 if (info->key == key) 924 if (info->key == key)
780 return info; 925 return info;
781 cur = info->next; 926 cur = info->next;
782 } 927 }
783 928
784 /* add a new hash entry */ 929 /* add a new hash entry */
785 if (cache->num_entries >= cache->size) { 930 info = snd_array_new(&cache->buf);
786 /* reallocate the array */ 931 if (!info)
787 unsigned int new_size = cache->size + 64; 932 return NULL;
788 void *new_buffer; 933 cur = snd_array_index(&cache->buf, info);
789 new_buffer = kcalloc(new_size, cache->record_size, GFP_KERNEL);
790 if (!new_buffer) {
791 snd_printk(KERN_ERR "hda_codec: "
792 "can't malloc amp_info\n");
793 return NULL;
794 }
795 if (cache->buffer) {
796 memcpy(new_buffer, cache->buffer,
797 cache->size * cache->record_size);
798 kfree(cache->buffer);
799 }
800 cache->size = new_size;
801 cache->buffer = new_buffer;
802 }
803 cur = cache->num_entries++;
804 info = (struct hda_cache_head *)(cache->buffer +
805 cur * cache->record_size);
806 info->key = key; 934 info->key = key;
807 info->val = 0; 935 info->val = 0;
808 info->next = cache->hash[idx]; 936 info->next = cache->hash[idx];
@@ -840,6 +968,7 @@ u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction)
840 } 968 }
841 return info->amp_caps; 969 return info->amp_caps;
842} 970}
971EXPORT_SYMBOL_HDA(query_amp_caps);
843 972
844int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, 973int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
845 unsigned int caps) 974 unsigned int caps)
@@ -853,6 +982,7 @@ int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
853 info->head.val |= INFO_AMP_CAPS; 982 info->head.val |= INFO_AMP_CAPS;
854 return 0; 983 return 0;
855} 984}
985EXPORT_SYMBOL_HDA(snd_hda_override_amp_caps);
856 986
857/* 987/*
858 * read the current volume to info 988 * read the current volume to info
@@ -906,6 +1036,7 @@ int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch,
906 return 0; 1036 return 0;
907 return get_vol_mute(codec, info, nid, ch, direction, index); 1037 return get_vol_mute(codec, info, nid, ch, direction, index);
908} 1038}
1039EXPORT_SYMBOL_HDA(snd_hda_codec_amp_read);
909 1040
910/* 1041/*
911 * update the AMP value, mask = bit mask to set, val = the value 1042 * update the AMP value, mask = bit mask to set, val = the value
@@ -925,6 +1056,7 @@ int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
925 put_vol_mute(codec, info, nid, ch, direction, idx, val); 1056 put_vol_mute(codec, info, nid, ch, direction, idx, val);
926 return 1; 1057 return 1;
927} 1058}
1059EXPORT_SYMBOL_HDA(snd_hda_codec_amp_update);
928 1060
929/* 1061/*
930 * update the AMP stereo with the same mask and value 1062 * update the AMP stereo with the same mask and value
@@ -938,15 +1070,16 @@ int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid,
938 idx, mask, val); 1070 idx, mask, val);
939 return ret; 1071 return ret;
940} 1072}
1073EXPORT_SYMBOL_HDA(snd_hda_codec_amp_stereo);
941 1074
942#ifdef SND_HDA_NEEDS_RESUME 1075#ifdef SND_HDA_NEEDS_RESUME
943/* resume the all amp commands from the cache */ 1076/* resume the all amp commands from the cache */
944void snd_hda_codec_resume_amp(struct hda_codec *codec) 1077void snd_hda_codec_resume_amp(struct hda_codec *codec)
945{ 1078{
946 struct hda_amp_info *buffer = codec->amp_cache.buffer; 1079 struct hda_amp_info *buffer = codec->amp_cache.buf.list;
947 int i; 1080 int i;
948 1081
949 for (i = 0; i < codec->amp_cache.size; i++, buffer++) { 1082 for (i = 0; i < codec->amp_cache.buf.used; i++, buffer++) {
950 u32 key = buffer->head.key; 1083 u32 key = buffer->head.key;
951 hda_nid_t nid; 1084 hda_nid_t nid;
952 unsigned int idx, dir, ch; 1085 unsigned int idx, dir, ch;
@@ -963,6 +1096,7 @@ void snd_hda_codec_resume_amp(struct hda_codec *codec)
963 } 1096 }
964 } 1097 }
965} 1098}
1099EXPORT_SYMBOL_HDA(snd_hda_codec_resume_amp);
966#endif /* SND_HDA_NEEDS_RESUME */ 1100#endif /* SND_HDA_NEEDS_RESUME */
967 1101
968/* volume */ 1102/* volume */
@@ -990,6 +1124,7 @@ int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol,
990 uinfo->value.integer.max = caps; 1124 uinfo->value.integer.max = caps;
991 return 0; 1125 return 0;
992} 1126}
1127EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_info);
993 1128
994int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol, 1129int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol,
995 struct snd_ctl_elem_value *ucontrol) 1130 struct snd_ctl_elem_value *ucontrol)
@@ -1009,6 +1144,7 @@ int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol,
1009 & HDA_AMP_VOLMASK; 1144 & HDA_AMP_VOLMASK;
1010 return 0; 1145 return 0;
1011} 1146}
1147EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_get);
1012 1148
1013int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol, 1149int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol,
1014 struct snd_ctl_elem_value *ucontrol) 1150 struct snd_ctl_elem_value *ucontrol)
@@ -1033,6 +1169,7 @@ int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol,
1033 snd_hda_power_down(codec); 1169 snd_hda_power_down(codec);
1034 return change; 1170 return change;
1035} 1171}
1172EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_put);
1036 1173
1037int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag, 1174int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1038 unsigned int size, unsigned int __user *_tlv) 1175 unsigned int size, unsigned int __user *_tlv)
@@ -1059,6 +1196,7 @@ int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1059 return -EFAULT; 1196 return -EFAULT;
1060 return 0; 1197 return 0;
1061} 1198}
1199EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_tlv);
1062 1200
1063/* 1201/*
1064 * set (static) TLV for virtual master volume; recalculated as max 0dB 1202 * set (static) TLV for virtual master volume; recalculated as max 0dB
@@ -1078,6 +1216,7 @@ void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir,
1078 tlv[2] = -nums * step; 1216 tlv[2] = -nums * step;
1079 tlv[3] = step; 1217 tlv[3] = step;
1080} 1218}
1219EXPORT_SYMBOL_HDA(snd_hda_set_vmaster_tlv);
1081 1220
1082/* find a mixer control element with the given name */ 1221/* find a mixer control element with the given name */
1083static struct snd_kcontrol * 1222static struct snd_kcontrol *
@@ -1097,6 +1236,69 @@ struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
1097{ 1236{
1098 return _snd_hda_find_mixer_ctl(codec, name, 0); 1237 return _snd_hda_find_mixer_ctl(codec, name, 0);
1099} 1238}
1239EXPORT_SYMBOL_HDA(snd_hda_find_mixer_ctl);
1240
1241/* Add a control element and assign to the codec */
1242int snd_hda_ctl_add(struct hda_codec *codec, struct snd_kcontrol *kctl)
1243{
1244 int err;
1245 struct snd_kcontrol **knewp;
1246
1247 err = snd_ctl_add(codec->bus->card, kctl);
1248 if (err < 0)
1249 return err;
1250 knewp = snd_array_new(&codec->mixers);
1251 if (!knewp)
1252 return -ENOMEM;
1253 *knewp = kctl;
1254 return 0;
1255}
1256EXPORT_SYMBOL_HDA(snd_hda_ctl_add);
1257
1258#ifdef CONFIG_SND_HDA_RECONFIG
1259/* Clear all controls assigned to the given codec */
1260void snd_hda_ctls_clear(struct hda_codec *codec)
1261{
1262 int i;
1263 struct snd_kcontrol **kctls = codec->mixers.list;
1264 for (i = 0; i < codec->mixers.used; i++)
1265 snd_ctl_remove(codec->bus->card, kctls[i]);
1266 snd_array_free(&codec->mixers);
1267}
1268
1269void snd_hda_codec_reset(struct hda_codec *codec)
1270{
1271 int i;
1272
1273#ifdef CONFIG_SND_HDA_POWER_SAVE
1274 cancel_delayed_work(&codec->power_work);
1275 flush_scheduled_work();
1276#endif
1277 snd_hda_ctls_clear(codec);
1278 /* relase PCMs */
1279 for (i = 0; i < codec->num_pcms; i++) {
1280 if (codec->pcm_info[i].pcm) {
1281 snd_device_free(codec->bus->card,
1282 codec->pcm_info[i].pcm);
1283 clear_bit(codec->pcm_info[i].device,
1284 codec->bus->pcm_dev_bits);
1285 }
1286 }
1287 if (codec->patch_ops.free)
1288 codec->patch_ops.free(codec);
1289 codec->proc_widget_hook = NULL;
1290 codec->spec = NULL;
1291 free_hda_cache(&codec->amp_cache);
1292 free_hda_cache(&codec->cmd_cache);
1293 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info));
1294 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head));
1295 codec->num_pcms = 0;
1296 codec->pcm_info = NULL;
1297 codec->preset = NULL;
1298 module_put(codec->owner);
1299 codec->owner = NULL;
1300}
1301#endif /* CONFIG_SND_HDA_RECONFIG */
1100 1302
1101/* create a virtual master control and add slaves */ 1303/* create a virtual master control and add slaves */
1102int snd_hda_add_vmaster(struct hda_codec *codec, char *name, 1304int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
@@ -1115,7 +1317,7 @@ int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1115 kctl = snd_ctl_make_virtual_master(name, tlv); 1317 kctl = snd_ctl_make_virtual_master(name, tlv);
1116 if (!kctl) 1318 if (!kctl)
1117 return -ENOMEM; 1319 return -ENOMEM;
1118 err = snd_ctl_add(codec->bus->card, kctl); 1320 err = snd_hda_ctl_add(codec, kctl);
1119 if (err < 0) 1321 if (err < 0)
1120 return err; 1322 return err;
1121 1323
@@ -1133,6 +1335,7 @@ int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1133 } 1335 }
1134 return 0; 1336 return 0;
1135} 1337}
1338EXPORT_SYMBOL_HDA(snd_hda_add_vmaster);
1136 1339
1137/* switch */ 1340/* switch */
1138int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol, 1341int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol,
@@ -1146,6 +1349,7 @@ int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol,
1146 uinfo->value.integer.max = 1; 1349 uinfo->value.integer.max = 1;
1147 return 0; 1350 return 0;
1148} 1351}
1352EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_info);
1149 1353
1150int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol, 1354int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol,
1151 struct snd_ctl_elem_value *ucontrol) 1355 struct snd_ctl_elem_value *ucontrol)
@@ -1165,6 +1369,7 @@ int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol,
1165 HDA_AMP_MUTE) ? 0 : 1; 1369 HDA_AMP_MUTE) ? 0 : 1;
1166 return 0; 1370 return 0;
1167} 1371}
1372EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_get);
1168 1373
1169int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol, 1374int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
1170 struct snd_ctl_elem_value *ucontrol) 1375 struct snd_ctl_elem_value *ucontrol)
@@ -1195,6 +1400,7 @@ int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
1195 snd_hda_power_down(codec); 1400 snd_hda_power_down(codec);
1196 return change; 1401 return change;
1197} 1402}
1403EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_put);
1198 1404
1199/* 1405/*
1200 * bound volume controls 1406 * bound volume controls
@@ -1220,6 +1426,7 @@ int snd_hda_mixer_bind_switch_get(struct snd_kcontrol *kcontrol,
1220 mutex_unlock(&codec->spdif_mutex); 1426 mutex_unlock(&codec->spdif_mutex);
1221 return err; 1427 return err;
1222} 1428}
1429EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_switch_get);
1223 1430
1224int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol, 1431int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol,
1225 struct snd_ctl_elem_value *ucontrol) 1432 struct snd_ctl_elem_value *ucontrol)
@@ -1243,6 +1450,7 @@ int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol,
1243 mutex_unlock(&codec->spdif_mutex); 1450 mutex_unlock(&codec->spdif_mutex);
1244 return err < 0 ? err : change; 1451 return err < 0 ? err : change;
1245} 1452}
1453EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_switch_put);
1246 1454
1247/* 1455/*
1248 * generic bound volume/swtich controls 1456 * generic bound volume/swtich controls
@@ -1262,6 +1470,7 @@ int snd_hda_mixer_bind_ctls_info(struct snd_kcontrol *kcontrol,
1262 mutex_unlock(&codec->spdif_mutex); 1470 mutex_unlock(&codec->spdif_mutex);
1263 return err; 1471 return err;
1264} 1472}
1473EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_info);
1265 1474
1266int snd_hda_mixer_bind_ctls_get(struct snd_kcontrol *kcontrol, 1475int snd_hda_mixer_bind_ctls_get(struct snd_kcontrol *kcontrol,
1267 struct snd_ctl_elem_value *ucontrol) 1476 struct snd_ctl_elem_value *ucontrol)
@@ -1278,6 +1487,7 @@ int snd_hda_mixer_bind_ctls_get(struct snd_kcontrol *kcontrol,
1278 mutex_unlock(&codec->spdif_mutex); 1487 mutex_unlock(&codec->spdif_mutex);
1279 return err; 1488 return err;
1280} 1489}
1490EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_get);
1281 1491
1282int snd_hda_mixer_bind_ctls_put(struct snd_kcontrol *kcontrol, 1492int snd_hda_mixer_bind_ctls_put(struct snd_kcontrol *kcontrol,
1283 struct snd_ctl_elem_value *ucontrol) 1493 struct snd_ctl_elem_value *ucontrol)
@@ -1300,6 +1510,7 @@ int snd_hda_mixer_bind_ctls_put(struct snd_kcontrol *kcontrol,
1300 mutex_unlock(&codec->spdif_mutex); 1510 mutex_unlock(&codec->spdif_mutex);
1301 return err < 0 ? err : change; 1511 return err < 0 ? err : change;
1302} 1512}
1513EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_put);
1303 1514
1304int snd_hda_mixer_bind_tlv(struct snd_kcontrol *kcontrol, int op_flag, 1515int snd_hda_mixer_bind_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1305 unsigned int size, unsigned int __user *tlv) 1516 unsigned int size, unsigned int __user *tlv)
@@ -1316,6 +1527,7 @@ int snd_hda_mixer_bind_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1316 mutex_unlock(&codec->spdif_mutex); 1527 mutex_unlock(&codec->spdif_mutex);
1317 return err; 1528 return err;
1318} 1529}
1530EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_tlv);
1319 1531
1320struct hda_ctl_ops snd_hda_bind_vol = { 1532struct hda_ctl_ops snd_hda_bind_vol = {
1321 .info = snd_hda_mixer_amp_volume_info, 1533 .info = snd_hda_mixer_amp_volume_info,
@@ -1323,6 +1535,7 @@ struct hda_ctl_ops snd_hda_bind_vol = {
1323 .put = snd_hda_mixer_amp_volume_put, 1535 .put = snd_hda_mixer_amp_volume_put,
1324 .tlv = snd_hda_mixer_amp_tlv 1536 .tlv = snd_hda_mixer_amp_tlv
1325}; 1537};
1538EXPORT_SYMBOL_HDA(snd_hda_bind_vol);
1326 1539
1327struct hda_ctl_ops snd_hda_bind_sw = { 1540struct hda_ctl_ops snd_hda_bind_sw = {
1328 .info = snd_hda_mixer_amp_switch_info, 1541 .info = snd_hda_mixer_amp_switch_info,
@@ -1330,6 +1543,7 @@ struct hda_ctl_ops snd_hda_bind_sw = {
1330 .put = snd_hda_mixer_amp_switch_put, 1543 .put = snd_hda_mixer_amp_switch_put,
1331 .tlv = snd_hda_mixer_amp_tlv 1544 .tlv = snd_hda_mixer_amp_tlv
1332}; 1545};
1546EXPORT_SYMBOL_HDA(snd_hda_bind_sw);
1333 1547
1334/* 1548/*
1335 * SPDIF out controls 1549 * SPDIF out controls
@@ -1577,9 +1791,11 @@ int snd_hda_create_spdif_out_ctls(struct hda_codec *codec, hda_nid_t nid)
1577 } 1791 }
1578 for (dig_mix = dig_mixes; dig_mix->name; dig_mix++) { 1792 for (dig_mix = dig_mixes; dig_mix->name; dig_mix++) {
1579 kctl = snd_ctl_new1(dig_mix, codec); 1793 kctl = snd_ctl_new1(dig_mix, codec);
1794 if (!kctl)
1795 return -ENOMEM;
1580 kctl->id.index = idx; 1796 kctl->id.index = idx;
1581 kctl->private_value = nid; 1797 kctl->private_value = nid;
1582 err = snd_ctl_add(codec->bus->card, kctl); 1798 err = snd_hda_ctl_add(codec, kctl);
1583 if (err < 0) 1799 if (err < 0)
1584 return err; 1800 return err;
1585 } 1801 }
@@ -1589,6 +1805,7 @@ int snd_hda_create_spdif_out_ctls(struct hda_codec *codec, hda_nid_t nid)
1589 codec->spdif_status = convert_to_spdif_status(codec->spdif_ctls); 1805 codec->spdif_status = convert_to_spdif_status(codec->spdif_ctls);
1590 return 0; 1806 return 0;
1591} 1807}
1808EXPORT_SYMBOL_HDA(snd_hda_create_spdif_out_ctls);
1592 1809
1593/* 1810/*
1594 * SPDIF sharing with analog output 1811 * SPDIF sharing with analog output
@@ -1623,9 +1840,10 @@ int snd_hda_create_spdif_share_sw(struct hda_codec *codec,
1623 if (!mout->dig_out_nid) 1840 if (!mout->dig_out_nid)
1624 return 0; 1841 return 0;
1625 /* ATTENTION: here mout is passed as private_data, instead of codec */ 1842 /* ATTENTION: here mout is passed as private_data, instead of codec */
1626 return snd_ctl_add(codec->bus->card, 1843 return snd_hda_ctl_add(codec,
1627 snd_ctl_new1(&spdif_share_sw, mout)); 1844 snd_ctl_new1(&spdif_share_sw, mout));
1628} 1845}
1846EXPORT_SYMBOL_HDA(snd_hda_create_spdif_share_sw);
1629 1847
1630/* 1848/*
1631 * SPDIF input 1849 * SPDIF input
@@ -1725,7 +1943,7 @@ int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid)
1725 for (dig_mix = dig_in_ctls; dig_mix->name; dig_mix++) { 1943 for (dig_mix = dig_in_ctls; dig_mix->name; dig_mix++) {
1726 kctl = snd_ctl_new1(dig_mix, codec); 1944 kctl = snd_ctl_new1(dig_mix, codec);
1727 kctl->private_value = nid; 1945 kctl->private_value = nid;
1728 err = snd_ctl_add(codec->bus->card, kctl); 1946 err = snd_hda_ctl_add(codec, kctl);
1729 if (err < 0) 1947 if (err < 0)
1730 return err; 1948 return err;
1731 } 1949 }
@@ -1735,6 +1953,7 @@ int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid)
1735 AC_DIG1_ENABLE; 1953 AC_DIG1_ENABLE;
1736 return 0; 1954 return 0;
1737} 1955}
1956EXPORT_SYMBOL_HDA(snd_hda_create_spdif_in_ctls);
1738 1957
1739#ifdef SND_HDA_NEEDS_RESUME 1958#ifdef SND_HDA_NEEDS_RESUME
1740/* 1959/*
@@ -1761,10 +1980,14 @@ int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid)
1761int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid, 1980int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid,
1762 int direct, unsigned int verb, unsigned int parm) 1981 int direct, unsigned int verb, unsigned int parm)
1763{ 1982{
1983 struct hda_bus *bus = codec->bus;
1984 unsigned int res;
1764 int err; 1985 int err;
1986
1987 res = make_codec_cmd(codec, nid, direct, verb, parm);
1765 snd_hda_power_up(codec); 1988 snd_hda_power_up(codec);
1766 mutex_lock(&codec->bus->cmd_mutex); 1989 mutex_lock(&bus->cmd_mutex);
1767 err = codec->bus->ops.command(codec, nid, direct, verb, parm); 1990 err = bus->ops.command(bus, res);
1768 if (!err) { 1991 if (!err) {
1769 struct hda_cache_head *c; 1992 struct hda_cache_head *c;
1770 u32 key = build_cmd_cache_key(nid, verb); 1993 u32 key = build_cmd_cache_key(nid, verb);
@@ -1772,18 +1995,19 @@ int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid,
1772 if (c) 1995 if (c)
1773 c->val = parm; 1996 c->val = parm;
1774 } 1997 }
1775 mutex_unlock(&codec->bus->cmd_mutex); 1998 mutex_unlock(&bus->cmd_mutex);
1776 snd_hda_power_down(codec); 1999 snd_hda_power_down(codec);
1777 return err; 2000 return err;
1778} 2001}
2002EXPORT_SYMBOL_HDA(snd_hda_codec_write_cache);
1779 2003
1780/* resume the all commands from the cache */ 2004/* resume the all commands from the cache */
1781void snd_hda_codec_resume_cache(struct hda_codec *codec) 2005void snd_hda_codec_resume_cache(struct hda_codec *codec)
1782{ 2006{
1783 struct hda_cache_head *buffer = codec->cmd_cache.buffer; 2007 struct hda_cache_head *buffer = codec->cmd_cache.buf.list;
1784 int i; 2008 int i;
1785 2009
1786 for (i = 0; i < codec->cmd_cache.size; i++, buffer++) { 2010 for (i = 0; i < codec->cmd_cache.buf.used; i++, buffer++) {
1787 u32 key = buffer->key; 2011 u32 key = buffer->key;
1788 if (!key) 2012 if (!key)
1789 continue; 2013 continue;
@@ -1791,6 +2015,7 @@ void snd_hda_codec_resume_cache(struct hda_codec *codec)
1791 get_cmd_cache_cmd(key), buffer->val); 2015 get_cmd_cache_cmd(key), buffer->val);
1792 } 2016 }
1793} 2017}
2018EXPORT_SYMBOL_HDA(snd_hda_codec_resume_cache);
1794 2019
1795/** 2020/**
1796 * snd_hda_sequence_write_cache - sequence writes with caching 2021 * snd_hda_sequence_write_cache - sequence writes with caching
@@ -1808,6 +2033,7 @@ void snd_hda_sequence_write_cache(struct hda_codec *codec,
1808 snd_hda_codec_write_cache(codec, seq->nid, 0, seq->verb, 2033 snd_hda_codec_write_cache(codec, seq->nid, 0, seq->verb,
1809 seq->param); 2034 seq->param);
1810} 2035}
2036EXPORT_SYMBOL_HDA(snd_hda_sequence_write_cache);
1811#endif /* SND_HDA_NEEDS_RESUME */ 2037#endif /* SND_HDA_NEEDS_RESUME */
1812 2038
1813/* 2039/*
@@ -1868,6 +2094,17 @@ static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
1868 } 2094 }
1869} 2095}
1870 2096
2097#ifdef CONFIG_SND_HDA_HWDEP
2098/* execute additional init verbs */
2099static void hda_exec_init_verbs(struct hda_codec *codec)
2100{
2101 if (codec->init_verbs.list)
2102 snd_hda_sequence_write(codec, codec->init_verbs.list);
2103}
2104#else
2105static inline void hda_exec_init_verbs(struct hda_codec *codec) {}
2106#endif
2107
1871#ifdef SND_HDA_NEEDS_RESUME 2108#ifdef SND_HDA_NEEDS_RESUME
1872/* 2109/*
1873 * call suspend and power-down; used both from PM and power-save 2110 * call suspend and power-down; used both from PM and power-save
@@ -1894,6 +2131,7 @@ static void hda_call_codec_resume(struct hda_codec *codec)
1894 hda_set_power_state(codec, 2131 hda_set_power_state(codec,
1895 codec->afg ? codec->afg : codec->mfg, 2132 codec->afg ? codec->afg : codec->mfg,
1896 AC_PWRST_D0); 2133 AC_PWRST_D0);
2134 hda_exec_init_verbs(codec);
1897 if (codec->patch_ops.resume) 2135 if (codec->patch_ops.resume)
1898 codec->patch_ops.resume(codec); 2136 codec->patch_ops.resume(codec);
1899 else { 2137 else {
@@ -1914,28 +2152,37 @@ static void hda_call_codec_resume(struct hda_codec *codec)
1914 * 2152 *
1915 * Returns 0 if successful, otherwise a negative error code. 2153 * Returns 0 if successful, otherwise a negative error code.
1916 */ 2154 */
1917int __devinit snd_hda_build_controls(struct hda_bus *bus) 2155int /*__devinit*/ snd_hda_build_controls(struct hda_bus *bus)
1918{ 2156{
1919 struct hda_codec *codec; 2157 struct hda_codec *codec;
1920 2158
1921 list_for_each_entry(codec, &bus->codec_list, list) { 2159 list_for_each_entry(codec, &bus->codec_list, list) {
1922 int err = 0; 2160 int err = snd_hda_codec_build_controls(codec);
1923 /* fake as if already powered-on */
1924 hda_keep_power_on(codec);
1925 /* then fire up */
1926 hda_set_power_state(codec,
1927 codec->afg ? codec->afg : codec->mfg,
1928 AC_PWRST_D0);
1929 /* continue to initialize... */
1930 if (codec->patch_ops.init)
1931 err = codec->patch_ops.init(codec);
1932 if (!err && codec->patch_ops.build_controls)
1933 err = codec->patch_ops.build_controls(codec);
1934 snd_hda_power_down(codec);
1935 if (err < 0) 2161 if (err < 0)
1936 return err; 2162 return err;
1937 } 2163 }
2164 return 0;
2165}
2166EXPORT_SYMBOL_HDA(snd_hda_build_controls);
1938 2167
2168int snd_hda_codec_build_controls(struct hda_codec *codec)
2169{
2170 int err = 0;
2171 /* fake as if already powered-on */
2172 hda_keep_power_on(codec);
2173 /* then fire up */
2174 hda_set_power_state(codec,
2175 codec->afg ? codec->afg : codec->mfg,
2176 AC_PWRST_D0);
2177 hda_exec_init_verbs(codec);
2178 /* continue to initialize... */
2179 if (codec->patch_ops.init)
2180 err = codec->patch_ops.init(codec);
2181 if (!err && codec->patch_ops.build_controls)
2182 err = codec->patch_ops.build_controls(codec);
2183 snd_hda_power_down(codec);
2184 if (err < 0)
2185 return err;
1939 return 0; 2186 return 0;
1940} 2187}
1941 2188
@@ -2028,6 +2275,7 @@ unsigned int snd_hda_calc_stream_format(unsigned int rate,
2028 2275
2029 return val; 2276 return val;
2030} 2277}
2278EXPORT_SYMBOL_HDA(snd_hda_calc_stream_format);
2031 2279
2032/** 2280/**
2033 * snd_hda_query_supported_pcm - query the supported PCM rates and formats 2281 * snd_hda_query_supported_pcm - query the supported PCM rates and formats
@@ -2042,7 +2290,7 @@ unsigned int snd_hda_calc_stream_format(unsigned int rate,
2042 * 2290 *
2043 * Returns 0 if successful, otherwise a negative error code. 2291 * Returns 0 if successful, otherwise a negative error code.
2044 */ 2292 */
2045int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid, 2293static int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid,
2046 u32 *ratesp, u64 *formatsp, unsigned int *bpsp) 2294 u32 *ratesp, u64 *formatsp, unsigned int *bpsp)
2047{ 2295{
2048 int i; 2296 int i;
@@ -2207,6 +2455,7 @@ int snd_hda_is_supported_format(struct hda_codec *codec, hda_nid_t nid,
2207 2455
2208 return 1; 2456 return 1;
2209} 2457}
2458EXPORT_SYMBOL_HDA(snd_hda_is_supported_format);
2210 2459
2211/* 2460/*
2212 * PCM stuff 2461 * PCM stuff
@@ -2236,8 +2485,8 @@ static int hda_pcm_default_cleanup(struct hda_pcm_stream *hinfo,
2236 return 0; 2485 return 0;
2237} 2486}
2238 2487
2239static int __devinit set_pcm_default_values(struct hda_codec *codec, 2488static int set_pcm_default_values(struct hda_codec *codec,
2240 struct hda_pcm_stream *info) 2489 struct hda_pcm_stream *info)
2241{ 2490{
2242 /* query support PCM information from the given NID */ 2491 /* query support PCM information from the given NID */
2243 if (info->nid && (!info->rates || !info->formats)) { 2492 if (info->nid && (!info->rates || !info->formats)) {
@@ -2263,6 +2512,110 @@ static int __devinit set_pcm_default_values(struct hda_codec *codec,
2263 return 0; 2512 return 0;
2264} 2513}
2265 2514
2515/*
2516 * get the empty PCM device number to assign
2517 */
2518static int get_empty_pcm_device(struct hda_bus *bus, int type)
2519{
2520 static const char *dev_name[HDA_PCM_NTYPES] = {
2521 "Audio", "SPDIF", "HDMI", "Modem"
2522 };
2523 /* starting device index for each PCM type */
2524 static int dev_idx[HDA_PCM_NTYPES] = {
2525 [HDA_PCM_TYPE_AUDIO] = 0,
2526 [HDA_PCM_TYPE_SPDIF] = 1,
2527 [HDA_PCM_TYPE_HDMI] = 3,
2528 [HDA_PCM_TYPE_MODEM] = 6
2529 };
2530 /* normal audio device indices; not linear to keep compatibility */
2531 static int audio_idx[4] = { 0, 2, 4, 5 };
2532 int i, dev;
2533
2534 switch (type) {
2535 case HDA_PCM_TYPE_AUDIO:
2536 for (i = 0; i < ARRAY_SIZE(audio_idx); i++) {
2537 dev = audio_idx[i];
2538 if (!test_bit(dev, bus->pcm_dev_bits))
2539 break;
2540 }
2541 if (i >= ARRAY_SIZE(audio_idx)) {
2542 snd_printk(KERN_WARNING "Too many audio devices\n");
2543 return -EAGAIN;
2544 }
2545 break;
2546 case HDA_PCM_TYPE_SPDIF:
2547 case HDA_PCM_TYPE_HDMI:
2548 case HDA_PCM_TYPE_MODEM:
2549 dev = dev_idx[type];
2550 if (test_bit(dev, bus->pcm_dev_bits)) {
2551 snd_printk(KERN_WARNING "%s already defined\n",
2552 dev_name[type]);
2553 return -EAGAIN;
2554 }
2555 break;
2556 default:
2557 snd_printk(KERN_WARNING "Invalid PCM type %d\n", type);
2558 return -EINVAL;
2559 }
2560 set_bit(dev, bus->pcm_dev_bits);
2561 return dev;
2562}
2563
2564/*
2565 * attach a new PCM stream
2566 */
2567static int snd_hda_attach_pcm(struct hda_codec *codec, struct hda_pcm *pcm)
2568{
2569 struct hda_bus *bus = codec->bus;
2570 struct hda_pcm_stream *info;
2571 int stream, err;
2572
2573 if (snd_BUG_ON(!pcm->name))
2574 return -EINVAL;
2575 for (stream = 0; stream < 2; stream++) {
2576 info = &pcm->stream[stream];
2577 if (info->substreams) {
2578 err = set_pcm_default_values(codec, info);
2579 if (err < 0)
2580 return err;
2581 }
2582 }
2583 return bus->ops.attach_pcm(bus, codec, pcm);
2584}
2585
2586/* assign all PCMs of the given codec */
2587int snd_hda_codec_build_pcms(struct hda_codec *codec)
2588{
2589 unsigned int pcm;
2590 int err;
2591
2592 if (!codec->num_pcms) {
2593 if (!codec->patch_ops.build_pcms)
2594 return 0;
2595 err = codec->patch_ops.build_pcms(codec);
2596 if (err < 0)
2597 return err;
2598 }
2599 for (pcm = 0; pcm < codec->num_pcms; pcm++) {
2600 struct hda_pcm *cpcm = &codec->pcm_info[pcm];
2601 int dev;
2602
2603 if (!cpcm->stream[0].substreams && !cpcm->stream[1].substreams)
2604 return 0; /* no substreams assigned */
2605
2606 if (!cpcm->pcm) {
2607 dev = get_empty_pcm_device(codec->bus, cpcm->pcm_type);
2608 if (dev < 0)
2609 return 0;
2610 cpcm->device = dev;
2611 err = snd_hda_attach_pcm(codec, cpcm);
2612 if (err < 0)
2613 return err;
2614 }
2615 }
2616 return 0;
2617}
2618
2266/** 2619/**
2267 * snd_hda_build_pcms - build PCM information 2620 * snd_hda_build_pcms - build PCM information
2268 * @bus: the BUS 2621 * @bus: the BUS
@@ -2294,27 +2647,13 @@ int __devinit snd_hda_build_pcms(struct hda_bus *bus)
2294 struct hda_codec *codec; 2647 struct hda_codec *codec;
2295 2648
2296 list_for_each_entry(codec, &bus->codec_list, list) { 2649 list_for_each_entry(codec, &bus->codec_list, list) {
2297 unsigned int pcm, s; 2650 int err = snd_hda_codec_build_pcms(codec);
2298 int err;
2299 if (!codec->patch_ops.build_pcms)
2300 continue;
2301 err = codec->patch_ops.build_pcms(codec);
2302 if (err < 0) 2651 if (err < 0)
2303 return err; 2652 return err;
2304 for (pcm = 0; pcm < codec->num_pcms; pcm++) {
2305 for (s = 0; s < 2; s++) {
2306 struct hda_pcm_stream *info;
2307 info = &codec->pcm_info[pcm].stream[s];
2308 if (!info->substreams)
2309 continue;
2310 err = set_pcm_default_values(codec, info);
2311 if (err < 0)
2312 return err;
2313 }
2314 }
2315 } 2653 }
2316 return 0; 2654 return 0;
2317} 2655}
2656EXPORT_SYMBOL_HDA(snd_hda_build_pcms);
2318 2657
2319/** 2658/**
2320 * snd_hda_check_board_config - compare the current codec with the config table 2659 * snd_hda_check_board_config - compare the current codec with the config table
@@ -2333,11 +2672,11 @@ int snd_hda_check_board_config(struct hda_codec *codec,
2333 int num_configs, const char **models, 2672 int num_configs, const char **models,
2334 const struct snd_pci_quirk *tbl) 2673 const struct snd_pci_quirk *tbl)
2335{ 2674{
2336 if (codec->bus->modelname && models) { 2675 if (codec->modelname && models) {
2337 int i; 2676 int i;
2338 for (i = 0; i < num_configs; i++) { 2677 for (i = 0; i < num_configs; i++) {
2339 if (models[i] && 2678 if (models[i] &&
2340 !strcmp(codec->bus->modelname, models[i])) { 2679 !strcmp(codec->modelname, models[i])) {
2341 snd_printd(KERN_INFO "hda_codec: model '%s' is " 2680 snd_printd(KERN_INFO "hda_codec: model '%s' is "
2342 "selected\n", models[i]); 2681 "selected\n", models[i]);
2343 return i; 2682 return i;
@@ -2370,6 +2709,7 @@ int snd_hda_check_board_config(struct hda_codec *codec,
2370 } 2709 }
2371 return -1; 2710 return -1;
2372} 2711}
2712EXPORT_SYMBOL_HDA(snd_hda_check_board_config);
2373 2713
2374/** 2714/**
2375 * snd_hda_add_new_ctls - create controls from the array 2715 * snd_hda_add_new_ctls - create controls from the array
@@ -2390,7 +2730,7 @@ int snd_hda_add_new_ctls(struct hda_codec *codec, struct snd_kcontrol_new *knew)
2390 kctl = snd_ctl_new1(knew, codec); 2730 kctl = snd_ctl_new1(knew, codec);
2391 if (!kctl) 2731 if (!kctl)
2392 return -ENOMEM; 2732 return -ENOMEM;
2393 err = snd_ctl_add(codec->bus->card, kctl); 2733 err = snd_hda_ctl_add(codec, kctl);
2394 if (err < 0) { 2734 if (err < 0) {
2395 if (!codec->addr) 2735 if (!codec->addr)
2396 return err; 2736 return err;
@@ -2398,13 +2738,14 @@ int snd_hda_add_new_ctls(struct hda_codec *codec, struct snd_kcontrol_new *knew)
2398 if (!kctl) 2738 if (!kctl)
2399 return -ENOMEM; 2739 return -ENOMEM;
2400 kctl->id.device = codec->addr; 2740 kctl->id.device = codec->addr;
2401 err = snd_ctl_add(codec->bus->card, kctl); 2741 err = snd_hda_ctl_add(codec, kctl);
2402 if (err < 0) 2742 if (err < 0)
2403 return err; 2743 return err;
2404 } 2744 }
2405 } 2745 }
2406 return 0; 2746 return 0;
2407} 2747}
2748EXPORT_SYMBOL_HDA(snd_hda_add_new_ctls);
2408 2749
2409#ifdef CONFIG_SND_HDA_POWER_SAVE 2750#ifdef CONFIG_SND_HDA_POWER_SAVE
2410static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg, 2751static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
@@ -2414,6 +2755,7 @@ static void hda_power_work(struct work_struct *work)
2414{ 2755{
2415 struct hda_codec *codec = 2756 struct hda_codec *codec =
2416 container_of(work, struct hda_codec, power_work.work); 2757 container_of(work, struct hda_codec, power_work.work);
2758 struct hda_bus *bus = codec->bus;
2417 2759
2418 if (!codec->power_on || codec->power_count) { 2760 if (!codec->power_on || codec->power_count) {
2419 codec->power_transition = 0; 2761 codec->power_transition = 0;
@@ -2421,8 +2763,8 @@ static void hda_power_work(struct work_struct *work)
2421 } 2763 }
2422 2764
2423 hda_call_codec_suspend(codec); 2765 hda_call_codec_suspend(codec);
2424 if (codec->bus->ops.pm_notify) 2766 if (bus->ops.pm_notify)
2425 codec->bus->ops.pm_notify(codec); 2767 bus->ops.pm_notify(bus);
2426} 2768}
2427 2769
2428static void hda_keep_power_on(struct hda_codec *codec) 2770static void hda_keep_power_on(struct hda_codec *codec)
@@ -2433,29 +2775,39 @@ static void hda_keep_power_on(struct hda_codec *codec)
2433 2775
2434void snd_hda_power_up(struct hda_codec *codec) 2776void snd_hda_power_up(struct hda_codec *codec)
2435{ 2777{
2778 struct hda_bus *bus = codec->bus;
2779
2436 codec->power_count++; 2780 codec->power_count++;
2437 if (codec->power_on || codec->power_transition) 2781 if (codec->power_on || codec->power_transition)
2438 return; 2782 return;
2439 2783
2440 codec->power_on = 1; 2784 codec->power_on = 1;
2441 if (codec->bus->ops.pm_notify) 2785 if (bus->ops.pm_notify)
2442 codec->bus->ops.pm_notify(codec); 2786 bus->ops.pm_notify(bus);
2443 hda_call_codec_resume(codec); 2787 hda_call_codec_resume(codec);
2444 cancel_delayed_work(&codec->power_work); 2788 cancel_delayed_work(&codec->power_work);
2445 codec->power_transition = 0; 2789 codec->power_transition = 0;
2446} 2790}
2791EXPORT_SYMBOL_HDA(snd_hda_power_up);
2792
2793#define power_save(codec) \
2794 ((codec)->bus->power_save ? *(codec)->bus->power_save : 0)
2795
2796#define power_save(codec) \
2797 ((codec)->bus->power_save ? *(codec)->bus->power_save : 0)
2447 2798
2448void snd_hda_power_down(struct hda_codec *codec) 2799void snd_hda_power_down(struct hda_codec *codec)
2449{ 2800{
2450 --codec->power_count; 2801 --codec->power_count;
2451 if (!codec->power_on || codec->power_count || codec->power_transition) 2802 if (!codec->power_on || codec->power_count || codec->power_transition)
2452 return; 2803 return;
2453 if (power_save) { 2804 if (power_save(codec)) {
2454 codec->power_transition = 1; /* avoid reentrance */ 2805 codec->power_transition = 1; /* avoid reentrance */
2455 schedule_delayed_work(&codec->power_work, 2806 schedule_delayed_work(&codec->power_work,
2456 msecs_to_jiffies(power_save * 1000)); 2807 msecs_to_jiffies(power_save(codec) * 1000));
2457 } 2808 }
2458} 2809}
2810EXPORT_SYMBOL_HDA(snd_hda_power_down);
2459 2811
2460int snd_hda_check_amp_list_power(struct hda_codec *codec, 2812int snd_hda_check_amp_list_power(struct hda_codec *codec,
2461 struct hda_loopback_check *check, 2813 struct hda_loopback_check *check,
@@ -2492,6 +2844,7 @@ int snd_hda_check_amp_list_power(struct hda_codec *codec,
2492 } 2844 }
2493 return 0; 2845 return 0;
2494} 2846}
2847EXPORT_SYMBOL_HDA(snd_hda_check_amp_list_power);
2495#endif 2848#endif
2496 2849
2497/* 2850/*
@@ -2511,6 +2864,7 @@ int snd_hda_ch_mode_info(struct hda_codec *codec,
2511 chmode[uinfo->value.enumerated.item].channels); 2864 chmode[uinfo->value.enumerated.item].channels);
2512 return 0; 2865 return 0;
2513} 2866}
2867EXPORT_SYMBOL_HDA(snd_hda_ch_mode_info);
2514 2868
2515int snd_hda_ch_mode_get(struct hda_codec *codec, 2869int snd_hda_ch_mode_get(struct hda_codec *codec,
2516 struct snd_ctl_elem_value *ucontrol, 2870 struct snd_ctl_elem_value *ucontrol,
@@ -2528,6 +2882,7 @@ int snd_hda_ch_mode_get(struct hda_codec *codec,
2528 } 2882 }
2529 return 0; 2883 return 0;
2530} 2884}
2885EXPORT_SYMBOL_HDA(snd_hda_ch_mode_get);
2531 2886
2532int snd_hda_ch_mode_put(struct hda_codec *codec, 2887int snd_hda_ch_mode_put(struct hda_codec *codec,
2533 struct snd_ctl_elem_value *ucontrol, 2888 struct snd_ctl_elem_value *ucontrol,
@@ -2548,6 +2903,7 @@ int snd_hda_ch_mode_put(struct hda_codec *codec,
2548 snd_hda_sequence_write_cache(codec, chmode[mode].sequence); 2903 snd_hda_sequence_write_cache(codec, chmode[mode].sequence);
2549 return 1; 2904 return 1;
2550} 2905}
2906EXPORT_SYMBOL_HDA(snd_hda_ch_mode_put);
2551 2907
2552/* 2908/*
2553 * input MUX helper 2909 * input MUX helper
@@ -2568,6 +2924,7 @@ int snd_hda_input_mux_info(const struct hda_input_mux *imux,
2568 strcpy(uinfo->value.enumerated.name, imux->items[index].label); 2924 strcpy(uinfo->value.enumerated.name, imux->items[index].label);
2569 return 0; 2925 return 0;
2570} 2926}
2927EXPORT_SYMBOL_HDA(snd_hda_input_mux_info);
2571 2928
2572int snd_hda_input_mux_put(struct hda_codec *codec, 2929int snd_hda_input_mux_put(struct hda_codec *codec,
2573 const struct hda_input_mux *imux, 2930 const struct hda_input_mux *imux,
@@ -2589,6 +2946,7 @@ int snd_hda_input_mux_put(struct hda_codec *codec,
2589 *cur_val = idx; 2946 *cur_val = idx;
2590 return 1; 2947 return 1;
2591} 2948}
2949EXPORT_SYMBOL_HDA(snd_hda_input_mux_put);
2592 2950
2593 2951
2594/* 2952/*
@@ -2641,6 +2999,7 @@ int snd_hda_multi_out_dig_open(struct hda_codec *codec,
2641 mutex_unlock(&codec->spdif_mutex); 2999 mutex_unlock(&codec->spdif_mutex);
2642 return 0; 3000 return 0;
2643} 3001}
3002EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_open);
2644 3003
2645int snd_hda_multi_out_dig_prepare(struct hda_codec *codec, 3004int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
2646 struct hda_multi_out *mout, 3005 struct hda_multi_out *mout,
@@ -2653,6 +3012,7 @@ int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
2653 mutex_unlock(&codec->spdif_mutex); 3012 mutex_unlock(&codec->spdif_mutex);
2654 return 0; 3013 return 0;
2655} 3014}
3015EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_prepare);
2656 3016
2657/* 3017/*
2658 * release the digital out 3018 * release the digital out
@@ -2665,6 +3025,7 @@ int snd_hda_multi_out_dig_close(struct hda_codec *codec,
2665 mutex_unlock(&codec->spdif_mutex); 3025 mutex_unlock(&codec->spdif_mutex);
2666 return 0; 3026 return 0;
2667} 3027}
3028EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_close);
2668 3029
2669/* 3030/*
2670 * set up more restrictions for analog out 3031 * set up more restrictions for analog out
@@ -2704,6 +3065,7 @@ int snd_hda_multi_out_analog_open(struct hda_codec *codec,
2704 return snd_pcm_hw_constraint_step(substream->runtime, 0, 3065 return snd_pcm_hw_constraint_step(substream->runtime, 0,
2705 SNDRV_PCM_HW_PARAM_CHANNELS, 2); 3066 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
2706} 3067}
3068EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_open);
2707 3069
2708/* 3070/*
2709 * set up the i/o for analog out 3071 * set up the i/o for analog out
@@ -2762,6 +3124,7 @@ int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
2762 } 3124 }
2763 return 0; 3125 return 0;
2764} 3126}
3127EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_prepare);
2765 3128
2766/* 3129/*
2767 * clean up the setting for analog out 3130 * clean up the setting for analog out
@@ -2788,6 +3151,7 @@ int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
2788 mutex_unlock(&codec->spdif_mutex); 3151 mutex_unlock(&codec->spdif_mutex);
2789 return 0; 3152 return 0;
2790} 3153}
3154EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_cleanup);
2791 3155
2792/* 3156/*
2793 * Helper for automatic pin configuration 3157 * Helper for automatic pin configuration
@@ -3073,11 +3437,13 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec,
3073 3437
3074 return 0; 3438 return 0;
3075} 3439}
3440EXPORT_SYMBOL_HDA(snd_hda_parse_pin_def_config);
3076 3441
3077/* labels for input pins */ 3442/* labels for input pins */
3078const char *auto_pin_cfg_labels[AUTO_PIN_LAST] = { 3443const char *auto_pin_cfg_labels[AUTO_PIN_LAST] = {
3079 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux" 3444 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux"
3080}; 3445};
3446EXPORT_SYMBOL_HDA(auto_pin_cfg_labels);
3081 3447
3082 3448
3083#ifdef CONFIG_PM 3449#ifdef CONFIG_PM
@@ -3105,11 +3471,11 @@ int snd_hda_suspend(struct hda_bus *bus, pm_message_t state)
3105 } 3471 }
3106 return 0; 3472 return 0;
3107} 3473}
3474EXPORT_SYMBOL_HDA(snd_hda_suspend);
3108 3475
3109/** 3476/**
3110 * snd_hda_resume - resume the codecs 3477 * snd_hda_resume - resume the codecs
3111 * @bus: the HDA bus 3478 * @bus: the HDA bus
3112 * @state: resume state
3113 * 3479 *
3114 * Returns 0 if successful. 3480 * Returns 0 if successful.
3115 * 3481 *
@@ -3126,16 +3492,79 @@ int snd_hda_resume(struct hda_bus *bus)
3126 } 3492 }
3127 return 0; 3493 return 0;
3128} 3494}
3129#ifdef CONFIG_SND_HDA_POWER_SAVE 3495EXPORT_SYMBOL_HDA(snd_hda_resume);
3130int snd_hda_codecs_inuse(struct hda_bus *bus) 3496#endif /* CONFIG_PM */
3131{
3132 struct hda_codec *codec;
3133 3497
3134 list_for_each_entry(codec, &bus->codec_list, list) { 3498/*
3135 if (snd_hda_codec_needs_resume(codec)) 3499 * generic arrays
3136 return 1; 3500 */
3501
3502/* get a new element from the given array
3503 * if it exceeds the pre-allocated array size, re-allocate the array
3504 */
3505void *snd_array_new(struct snd_array *array)
3506{
3507 if (array->used >= array->alloced) {
3508 int num = array->alloced + array->alloc_align;
3509 void *nlist;
3510 if (snd_BUG_ON(num >= 4096))
3511 return NULL;
3512 nlist = kcalloc(num + 1, array->elem_size, GFP_KERNEL);
3513 if (!nlist)
3514 return NULL;
3515 if (array->list) {
3516 memcpy(nlist, array->list,
3517 array->elem_size * array->alloced);
3518 kfree(array->list);
3519 }
3520 array->list = nlist;
3521 array->alloced = num;
3137 } 3522 }
3138 return 0; 3523 return snd_array_elem(array, array->used++);
3139} 3524}
3140#endif 3525EXPORT_SYMBOL_HDA(snd_array_new);
3141#endif 3526
3527/* free the given array elements */
3528void snd_array_free(struct snd_array *array)
3529{
3530 kfree(array->list);
3531 array->used = 0;
3532 array->alloced = 0;
3533 array->list = NULL;
3534}
3535EXPORT_SYMBOL_HDA(snd_array_free);
3536
3537/*
3538 * used by hda_proc.c and hda_eld.c
3539 */
3540void snd_print_pcm_rates(int pcm, char *buf, int buflen)
3541{
3542 static unsigned int rates[] = {
3543 8000, 11025, 16000, 22050, 32000, 44100, 48000, 88200,
3544 96000, 176400, 192000, 384000
3545 };
3546 int i, j;
3547
3548 for (i = 0, j = 0; i < ARRAY_SIZE(rates); i++)
3549 if (pcm & (1 << i))
3550 j += snprintf(buf + j, buflen - j, " %d", rates[i]);
3551
3552 buf[j] = '\0'; /* necessary when j == 0 */
3553}
3554EXPORT_SYMBOL_HDA(snd_print_pcm_rates);
3555
3556void snd_print_pcm_bits(int pcm, char *buf, int buflen)
3557{
3558 static unsigned int bits[] = { 8, 16, 20, 24, 32 };
3559 int i, j;
3560
3561 for (i = 0, j = 0; i < ARRAY_SIZE(bits); i++)
3562 if (pcm & (AC_SUPPCM_BITS_8 << i))
3563 j += snprintf(buf + j, buflen - j, " %d", bits[i]);
3564
3565 buf[j] = '\0'; /* necessary when j == 0 */
3566}
3567EXPORT_SYMBOL_HDA(snd_print_pcm_bits);
3568
3569MODULE_DESCRIPTION("HDA codec core");
3570MODULE_LICENSE("GPL");