aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
Diffstat (limited to 'sound')
-rw-r--r--sound/Kconfig2
-rw-r--r--sound/Makefile2
-rw-r--r--sound/aoa/soundbus/i2sbus/core.c2
-rw-r--r--sound/core/control.c329
-rw-r--r--sound/core/device.c47
-rw-r--r--sound/core/hwdep.c4
-rw-r--r--sound/core/init.c5
-rw-r--r--sound/core/oss/mixer_oss.c4
-rw-r--r--sound/core/oss/pcm_oss.c1
-rw-r--r--sound/core/pcm.c105
-rw-r--r--sound/core/pcm_compat.c28
-rw-r--r--sound/core/pcm_dmaengine.c4
-rw-r--r--sound/core/pcm_lib.c88
-rw-r--r--sound/core/pcm_native.c82
-rw-r--r--sound/core/rawmidi.c8
-rw-r--r--sound/core/seq/oss/seq_oss.c22
-rw-r--r--sound/core/seq/oss/seq_oss_init.c4
-rw-r--r--sound/core/seq/oss/seq_oss_midi.c5
-rw-r--r--sound/core/seq/oss/seq_oss_readq.c9
-rw-r--r--sound/core/seq/oss/seq_oss_synth.c12
-rw-r--r--sound/core/seq/oss/seq_oss_synth.h4
-rw-r--r--sound/core/seq/seq_clientmgr.c1
-rw-r--r--sound/core/seq/seq_device.c571
-rw-r--r--sound/core/seq/seq_dummy.c6
-rw-r--r--sound/core/seq/seq_fifo.c4
-rw-r--r--sound/core/seq/seq_memory.c8
-rw-r--r--sound/core/seq/seq_midi.c36
-rw-r--r--sound/core/seq/seq_ports.c4
-rw-r--r--sound/core/seq/seq_prioq.c4
-rw-r--r--sound/core/seq/seq_queue.c4
-rw-r--r--sound/core/seq/seq_timer.c4
-rw-r--r--sound/core/sound.c14
-rw-r--r--sound/core/timer.c4
-rw-r--r--sound/drivers/opl3/opl3_seq.c34
-rw-r--r--sound/drivers/opl4/opl4_seq.c33
-rw-r--r--sound/firewire/amdtp.c8
-rw-r--r--sound/firewire/bebob/bebob_maudio.c8
-rw-r--r--sound/firewire/fireworks/fireworks_transaction.c2
-rw-r--r--sound/hda/Kconfig3
-rw-r--r--sound/hda/Makefile7
-rw-r--r--sound/hda/array.c49
-rw-r--r--sound/hda/hda_bus_type.c42
-rw-r--r--sound/hda/hdac_bus.c186
-rw-r--r--sound/hda/hdac_device.c599
-rw-r--r--sound/hda/hdac_regmap.c472
-rw-r--r--sound/hda/hdac_sysfs.c406
-rw-r--r--sound/hda/local.h23
-rw-r--r--sound/hda/trace.c6
-rw-r--r--sound/hda/trace.h62
-rw-r--r--sound/i2c/other/ak4113.c4
-rw-r--r--sound/isa/sb/emu8000_synth.c35
-rw-r--r--sound/isa/wavefront/wavefront_fx.c6
-rw-r--r--sound/isa/wavefront/wavefront_synth.c26
-rw-r--r--sound/mips/au1x00.c12
-rw-r--r--sound/oss/dev_table.c6
-rw-r--r--sound/oss/opl3.c4
-rw-r--r--sound/oss/sb_ess.c19
-rw-r--r--sound/oss/sb_midi.c6
-rw-r--r--sound/oss/sequencer.c12
-rw-r--r--sound/oss/sys_timer.c35
-rw-r--r--sound/oss/v_midi.c4
-rw-r--r--sound/pci/ac97/ac97_codec.c4
-rw-r--r--sound/pci/ac97/ac97_patch.c27
-rw-r--r--sound/pci/ad1889.c2
-rw-r--r--sound/pci/asihpi/asihpi.c2
-rw-r--r--sound/pci/atiixp.c2
-rw-r--r--sound/pci/azt3328.c7
-rw-r--r--sound/pci/cmipci.c2
-rw-r--r--sound/pci/cs5535audio/cs5535audio.c2
-rw-r--r--sound/pci/echoaudio/echoaudio.c16
-rw-r--r--sound/pci/emu10k1/emu10k1_main.c25
-rw-r--r--sound/pci/emu10k1/emu10k1_synth.c35
-rw-r--r--sound/pci/emu10k1/emumixer.c118
-rw-r--r--sound/pci/emu10k1/emuproc.c12
-rw-r--r--sound/pci/hda/Kconfig1
-rw-r--r--sound/pci/hda/Makefile3
-rw-r--r--sound/pci/hda/hda_auto_parser.c33
-rw-r--r--sound/pci/hda/hda_beep.c37
-rw-r--r--sound/pci/hda/hda_beep.h1
-rw-r--r--sound/pci/hda/hda_bind.c273
-rw-r--r--sound/pci/hda/hda_codec.c2289
-rw-r--r--sound/pci/hda/hda_codec.h288
-rw-r--r--sound/pci/hda/hda_controller.c269
-rw-r--r--sound/pci/hda/hda_controller.h397
-rw-r--r--sound/pci/hda/hda_generic.c599
-rw-r--r--sound/pci/hda/hda_generic.h9
-rw-r--r--sound/pci/hda/hda_hwdep.c5
-rw-r--r--sound/pci/hda/hda_i915.c8
-rw-r--r--sound/pci/hda/hda_intel.c104
-rw-r--r--sound/pci/hda/hda_intel.h2
-rw-r--r--sound/pci/hda/hda_jack.c8
-rw-r--r--sound/pci/hda/hda_local.h123
-rw-r--r--sound/pci/hda/hda_priv.h406
-rw-r--r--sound/pci/hda/hda_proc.c80
-rw-r--r--sound/pci/hda/hda_sysfs.c62
-rw-r--r--sound/pci/hda/hda_tegra.c50
-rw-r--r--sound/pci/hda/hda_trace.h143
-rw-r--r--sound/pci/hda/local.h39
-rw-r--r--sound/pci/hda/patch_analog.c34
-rw-r--r--sound/pci/hda/patch_ca0110.c16
-rw-r--r--sound/pci/hda/patch_ca0132.c68
-rw-r--r--sound/pci/hda/patch_cirrus.c16
-rw-r--r--sound/pci/hda/patch_cmedia.c16
-rw-r--r--sound/pci/hda/patch_conexant.c41
-rw-r--r--sound/pci/hda/patch_hdmi.c99
-rw-r--r--sound/pci/hda/patch_realtek.c347
-rw-r--r--sound/pci/hda/patch_si3054.c37
-rw-r--r--sound/pci/hda/patch_sigmatel.c138
-rw-r--r--sound/pci/hda/patch_via.c778
-rw-r--r--sound/pci/hda/thinkpad_helper.c2
-rw-r--r--sound/pci/ice1712/wtm.c172
-rw-r--r--sound/pci/intel8x0.c6
-rw-r--r--sound/pci/rme9652/hdspm.c141
-rw-r--r--sound/pci/via82xx.c2
-rw-r--r--sound/ppc/pmac.c58
-rw-r--r--sound/soc/codecs/arizona.c7
-rw-r--r--sound/soc/codecs/pcm512x.c3
-rw-r--r--sound/soc/codecs/rt5645.c13
-rw-r--r--sound/soc/fsl/fsl_ssi.c2
-rw-r--r--sound/soc/intel/Makefile2
-rw-r--r--sound/soc/intel/baytrail/sst-baytrail-ipc.c1
-rw-r--r--sound/soc/intel/haswell/sst-haswell-ipc.c1
-rw-r--r--sound/soc/qcom/lpass-cpu.c2
-rw-r--r--sound/soc/sh/fsi.c18
-rw-r--r--sound/soc/soc-core.c4
-rw-r--r--sound/usb/format.c5
-rw-r--r--sound/usb/mixer_quirks.c1
-rw-r--r--sound/usb/quirks-table.h30
-rw-r--r--sound/usb/quirks.c50
129 files changed, 5636 insertions, 5493 deletions
diff --git a/sound/Kconfig b/sound/Kconfig
index c710ce2c5c37..5a240e050ae6 100644
--- a/sound/Kconfig
+++ b/sound/Kconfig
@@ -76,6 +76,8 @@ source "sound/isa/Kconfig"
76 76
77source "sound/pci/Kconfig" 77source "sound/pci/Kconfig"
78 78
79source "sound/hda/Kconfig"
80
79source "sound/ppc/Kconfig" 81source "sound/ppc/Kconfig"
80 82
81source "sound/aoa/Kconfig" 83source "sound/aoa/Kconfig"
diff --git a/sound/Makefile b/sound/Makefile
index ce9132b1c395..77320709fd26 100644
--- a/sound/Makefile
+++ b/sound/Makefile
@@ -6,7 +6,7 @@ obj-$(CONFIG_SOUND_PRIME) += sound_firmware.o
6obj-$(CONFIG_SOUND_PRIME) += oss/ 6obj-$(CONFIG_SOUND_PRIME) += oss/
7obj-$(CONFIG_DMASOUND) += oss/ 7obj-$(CONFIG_DMASOUND) += oss/
8obj-$(CONFIG_SND) += core/ i2c/ drivers/ isa/ pci/ ppc/ arm/ sh/ synth/ usb/ \ 8obj-$(CONFIG_SND) += core/ i2c/ drivers/ isa/ pci/ ppc/ arm/ sh/ synth/ usb/ \
9 firewire/ sparc/ spi/ parisc/ pcmcia/ mips/ soc/ atmel/ 9 firewire/ sparc/ spi/ parisc/ pcmcia/ mips/ soc/ atmel/ hda/
10obj-$(CONFIG_SND_AOA) += aoa/ 10obj-$(CONFIG_SND_AOA) += aoa/
11 11
12# This one must be compilable even if sound is configured out 12# This one must be compilable even if sound is configured out
diff --git a/sound/aoa/soundbus/i2sbus/core.c b/sound/aoa/soundbus/i2sbus/core.c
index b9737fae656a..1cbf210080a1 100644
--- a/sound/aoa/soundbus/i2sbus/core.c
+++ b/sound/aoa/soundbus/i2sbus/core.c
@@ -31,7 +31,7 @@ module_param(force, int, 0444);
31MODULE_PARM_DESC(force, "Force loading i2sbus even when" 31MODULE_PARM_DESC(force, "Force loading i2sbus even when"
32 " no layout-id property is present"); 32 " no layout-id property is present");
33 33
34static struct of_device_id i2sbus_match[] = { 34static const struct of_device_id i2sbus_match[] = {
35 { .name = "i2s" }, 35 { .name = "i2s" },
36 { } 36 { }
37}; 37};
diff --git a/sound/core/control.c b/sound/core/control.c
index eeb691d1911f..196a6fe100ca 100644
--- a/sound/core/control.c
+++ b/sound/core/control.c
@@ -192,36 +192,41 @@ void snd_ctl_notify(struct snd_card *card, unsigned int mask,
192EXPORT_SYMBOL(snd_ctl_notify); 192EXPORT_SYMBOL(snd_ctl_notify);
193 193
194/** 194/**
195 * snd_ctl_new - create a control instance from the template 195 * snd_ctl_new - create a new control instance with some elements
196 * @control: the control template 196 * @kctl: the pointer to store new control instance
197 * @access: the default control access 197 * @count: the number of elements in this control
198 * @access: the default access flags for elements in this control
199 * @file: given when locking these elements
198 * 200 *
199 * Allocates a new struct snd_kcontrol instance and copies the given template 201 * Allocates a memory object for a new control instance. The instance has
200 * to the new instance. It does not copy volatile data (access). 202 * elements as many as the given number (@count). Each element has given
203 * access permissions (@access). Each element is locked when @file is given.
201 * 204 *
202 * Return: The pointer of the new instance, or %NULL on failure. 205 * Return: 0 on success, error code on failure
203 */ 206 */
204static struct snd_kcontrol *snd_ctl_new(struct snd_kcontrol *control, 207static int snd_ctl_new(struct snd_kcontrol **kctl, unsigned int count,
205 unsigned int access) 208 unsigned int access, struct snd_ctl_file *file)
206{ 209{
207 struct snd_kcontrol *kctl; 210 unsigned int size;
208 unsigned int idx; 211 unsigned int idx;
209 212
210 if (snd_BUG_ON(!control || !control->count)) 213 if (count == 0 || count > MAX_CONTROL_COUNT)
211 return NULL; 214 return -EINVAL;
212 215
213 if (control->count > MAX_CONTROL_COUNT) 216 size = sizeof(struct snd_kcontrol);
214 return NULL; 217 size += sizeof(struct snd_kcontrol_volatile) * count;
215 218
216 kctl = kzalloc(sizeof(*kctl) + sizeof(struct snd_kcontrol_volatile) * control->count, GFP_KERNEL); 219 *kctl = kzalloc(size, GFP_KERNEL);
217 if (kctl == NULL) { 220 if (!*kctl)
218 pr_err("ALSA: Cannot allocate control instance\n"); 221 return -ENOMEM;
219 return NULL; 222
223 for (idx = 0; idx < count; idx++) {
224 (*kctl)->vd[idx].access = access;
225 (*kctl)->vd[idx].owner = file;
220 } 226 }
221 *kctl = *control; 227 (*kctl)->count = count;
222 for (idx = 0; idx < kctl->count; idx++) 228
223 kctl->vd[idx].access = access; 229 return 0;
224 return kctl;
225} 230}
226 231
227/** 232/**
@@ -238,37 +243,53 @@ static struct snd_kcontrol *snd_ctl_new(struct snd_kcontrol *control,
238struct snd_kcontrol *snd_ctl_new1(const struct snd_kcontrol_new *ncontrol, 243struct snd_kcontrol *snd_ctl_new1(const struct snd_kcontrol_new *ncontrol,
239 void *private_data) 244 void *private_data)
240{ 245{
241 struct snd_kcontrol kctl; 246 struct snd_kcontrol *kctl;
247 unsigned int count;
242 unsigned int access; 248 unsigned int access;
249 int err;
243 250
244 if (snd_BUG_ON(!ncontrol || !ncontrol->info)) 251 if (snd_BUG_ON(!ncontrol || !ncontrol->info))
245 return NULL; 252 return NULL;
246 memset(&kctl, 0, sizeof(kctl)); 253
247 kctl.id.iface = ncontrol->iface; 254 count = ncontrol->count;
248 kctl.id.device = ncontrol->device; 255 if (count == 0)
249 kctl.id.subdevice = ncontrol->subdevice; 256 count = 1;
257
258 access = ncontrol->access;
259 if (access == 0)
260 access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
261 access &= (SNDRV_CTL_ELEM_ACCESS_READWRITE |
262 SNDRV_CTL_ELEM_ACCESS_VOLATILE |
263 SNDRV_CTL_ELEM_ACCESS_INACTIVE |
264 SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE |
265 SNDRV_CTL_ELEM_ACCESS_TLV_COMMAND |
266 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK);
267
268 err = snd_ctl_new(&kctl, count, access, NULL);
269 if (err < 0)
270 return NULL;
271
272 /* The 'numid' member is decided when calling snd_ctl_add(). */
273 kctl->id.iface = ncontrol->iface;
274 kctl->id.device = ncontrol->device;
275 kctl->id.subdevice = ncontrol->subdevice;
250 if (ncontrol->name) { 276 if (ncontrol->name) {
251 strlcpy(kctl.id.name, ncontrol->name, sizeof(kctl.id.name)); 277 strlcpy(kctl->id.name, ncontrol->name, sizeof(kctl->id.name));
252 if (strcmp(ncontrol->name, kctl.id.name) != 0) 278 if (strcmp(ncontrol->name, kctl->id.name) != 0)
253 pr_warn("ALSA: Control name '%s' truncated to '%s'\n", 279 pr_warn("ALSA: Control name '%s' truncated to '%s'\n",
254 ncontrol->name, kctl.id.name); 280 ncontrol->name, kctl->id.name);
255 } 281 }
256 kctl.id.index = ncontrol->index; 282 kctl->id.index = ncontrol->index;
257 kctl.count = ncontrol->count ? ncontrol->count : 1; 283
258 access = ncontrol->access == 0 ? SNDRV_CTL_ELEM_ACCESS_READWRITE : 284 kctl->info = ncontrol->info;
259 (ncontrol->access & (SNDRV_CTL_ELEM_ACCESS_READWRITE| 285 kctl->get = ncontrol->get;
260 SNDRV_CTL_ELEM_ACCESS_VOLATILE| 286 kctl->put = ncontrol->put;
261 SNDRV_CTL_ELEM_ACCESS_INACTIVE| 287 kctl->tlv.p = ncontrol->tlv.p;
262 SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE| 288
263 SNDRV_CTL_ELEM_ACCESS_TLV_COMMAND| 289 kctl->private_value = ncontrol->private_value;
264 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK)); 290 kctl->private_data = private_data;
265 kctl.info = ncontrol->info; 291
266 kctl.get = ncontrol->get; 292 return kctl;
267 kctl.put = ncontrol->put;
268 kctl.tlv.p = ncontrol->tlv.p;
269 kctl.private_value = ncontrol->private_value;
270 kctl.private_data = private_data;
271 return snd_ctl_new(&kctl, access);
272} 293}
273EXPORT_SYMBOL(snd_ctl_new1); 294EXPORT_SYMBOL(snd_ctl_new1);
274 295
@@ -557,6 +578,7 @@ error:
557 * 578 *
558 * Finds the control instance with the given id, and activate or 579 * Finds the control instance with the given id, and activate or
559 * inactivate the control together with notification, if changed. 580 * inactivate the control together with notification, if changed.
581 * The given ID data is filled with full information.
560 * 582 *
561 * Return: 0 if unchanged, 1 if changed, or a negative error code on failure. 583 * Return: 0 if unchanged, 1 if changed, or a negative error code on failure.
562 */ 584 */
@@ -586,6 +608,7 @@ int snd_ctl_activate_id(struct snd_card *card, struct snd_ctl_elem_id *id,
586 goto unlock; 608 goto unlock;
587 vd->access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE; 609 vd->access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
588 } 610 }
611 snd_ctl_build_ioff(id, kctl, index_offset);
589 ret = 1; 612 ret = 1;
590 unlock: 613 unlock:
591 up_write(&card->controls_rwsem); 614 up_write(&card->controls_rwsem);
@@ -1006,7 +1029,7 @@ static int snd_ctl_elem_unlock(struct snd_ctl_file *file,
1006struct user_element { 1029struct user_element {
1007 struct snd_ctl_elem_info info; 1030 struct snd_ctl_elem_info info;
1008 struct snd_card *card; 1031 struct snd_card *card;
1009 void *elem_data; /* element data */ 1032 char *elem_data; /* element data */
1010 unsigned long elem_data_size; /* size of element data in bytes */ 1033 unsigned long elem_data_size; /* size of element data in bytes */
1011 void *tlv_data; /* TLV data */ 1034 void *tlv_data; /* TLV data */
1012 unsigned long tlv_data_size; /* TLV data size */ 1035 unsigned long tlv_data_size; /* TLV data size */
@@ -1017,8 +1040,12 @@ static int snd_ctl_elem_user_info(struct snd_kcontrol *kcontrol,
1017 struct snd_ctl_elem_info *uinfo) 1040 struct snd_ctl_elem_info *uinfo)
1018{ 1041{
1019 struct user_element *ue = kcontrol->private_data; 1042 struct user_element *ue = kcontrol->private_data;
1043 unsigned int offset;
1020 1044
1045 offset = snd_ctl_get_ioff(kcontrol, &uinfo->id);
1021 *uinfo = ue->info; 1046 *uinfo = ue->info;
1047 snd_ctl_build_ioff(&uinfo->id, kcontrol, offset);
1048
1022 return 0; 1049 return 0;
1023} 1050}
1024 1051
@@ -1028,10 +1055,13 @@ static int snd_ctl_elem_user_enum_info(struct snd_kcontrol *kcontrol,
1028 struct user_element *ue = kcontrol->private_data; 1055 struct user_element *ue = kcontrol->private_data;
1029 const char *names; 1056 const char *names;
1030 unsigned int item; 1057 unsigned int item;
1058 unsigned int offset;
1031 1059
1032 item = uinfo->value.enumerated.item; 1060 item = uinfo->value.enumerated.item;
1033 1061
1062 offset = snd_ctl_get_ioff(kcontrol, &uinfo->id);
1034 *uinfo = ue->info; 1063 *uinfo = ue->info;
1064 snd_ctl_build_ioff(&uinfo->id, kcontrol, offset);
1035 1065
1036 item = min(item, uinfo->value.enumerated.items - 1); 1066 item = min(item, uinfo->value.enumerated.items - 1);
1037 uinfo->value.enumerated.item = item; 1067 uinfo->value.enumerated.item = item;
@@ -1048,9 +1078,12 @@ static int snd_ctl_elem_user_get(struct snd_kcontrol *kcontrol,
1048 struct snd_ctl_elem_value *ucontrol) 1078 struct snd_ctl_elem_value *ucontrol)
1049{ 1079{
1050 struct user_element *ue = kcontrol->private_data; 1080 struct user_element *ue = kcontrol->private_data;
1081 unsigned int size = ue->elem_data_size;
1082 char *src = ue->elem_data +
1083 snd_ctl_get_ioff(kcontrol, &ucontrol->id) * size;
1051 1084
1052 mutex_lock(&ue->card->user_ctl_lock); 1085 mutex_lock(&ue->card->user_ctl_lock);
1053 memcpy(&ucontrol->value, ue->elem_data, ue->elem_data_size); 1086 memcpy(&ucontrol->value, src, size);
1054 mutex_unlock(&ue->card->user_ctl_lock); 1087 mutex_unlock(&ue->card->user_ctl_lock);
1055 return 0; 1088 return 0;
1056} 1089}
@@ -1060,11 +1093,14 @@ static int snd_ctl_elem_user_put(struct snd_kcontrol *kcontrol,
1060{ 1093{
1061 int change; 1094 int change;
1062 struct user_element *ue = kcontrol->private_data; 1095 struct user_element *ue = kcontrol->private_data;
1096 unsigned int size = ue->elem_data_size;
1097 char *dst = ue->elem_data +
1098 snd_ctl_get_ioff(kcontrol, &ucontrol->id) * size;
1063 1099
1064 mutex_lock(&ue->card->user_ctl_lock); 1100 mutex_lock(&ue->card->user_ctl_lock);
1065 change = memcmp(&ucontrol->value, ue->elem_data, ue->elem_data_size) != 0; 1101 change = memcmp(&ucontrol->value, dst, size) != 0;
1066 if (change) 1102 if (change)
1067 memcpy(ue->elem_data, &ucontrol->value, ue->elem_data_size); 1103 memcpy(dst, &ucontrol->value, size);
1068 mutex_unlock(&ue->card->user_ctl_lock); 1104 mutex_unlock(&ue->card->user_ctl_lock);
1069 return change; 1105 return change;
1070} 1106}
@@ -1078,7 +1114,7 @@ static int snd_ctl_elem_user_tlv(struct snd_kcontrol *kcontrol,
1078 int change = 0; 1114 int change = 0;
1079 void *new_data; 1115 void *new_data;
1080 1116
1081 if (op_flag > 0) { 1117 if (op_flag == SNDRV_CTL_TLV_OP_WRITE) {
1082 if (size > 1024 * 128) /* sane value */ 1118 if (size > 1024 * 128) /* sane value */
1083 return -EINVAL; 1119 return -EINVAL;
1084 1120
@@ -1161,84 +1197,103 @@ static void snd_ctl_elem_user_free(struct snd_kcontrol *kcontrol)
1161static int snd_ctl_elem_add(struct snd_ctl_file *file, 1197static int snd_ctl_elem_add(struct snd_ctl_file *file,
1162 struct snd_ctl_elem_info *info, int replace) 1198 struct snd_ctl_elem_info *info, int replace)
1163{ 1199{
1200 /* The capacity of struct snd_ctl_elem_value.value.*/
1201 static const unsigned int value_sizes[] = {
1202 [SNDRV_CTL_ELEM_TYPE_BOOLEAN] = sizeof(long),
1203 [SNDRV_CTL_ELEM_TYPE_INTEGER] = sizeof(long),
1204 [SNDRV_CTL_ELEM_TYPE_ENUMERATED] = sizeof(unsigned int),
1205 [SNDRV_CTL_ELEM_TYPE_BYTES] = sizeof(unsigned char),
1206 [SNDRV_CTL_ELEM_TYPE_IEC958] = sizeof(struct snd_aes_iec958),
1207 [SNDRV_CTL_ELEM_TYPE_INTEGER64] = sizeof(long long),
1208 };
1209 static const unsigned int max_value_counts[] = {
1210 [SNDRV_CTL_ELEM_TYPE_BOOLEAN] = 128,
1211 [SNDRV_CTL_ELEM_TYPE_INTEGER] = 128,
1212 [SNDRV_CTL_ELEM_TYPE_ENUMERATED] = 128,
1213 [SNDRV_CTL_ELEM_TYPE_BYTES] = 512,
1214 [SNDRV_CTL_ELEM_TYPE_IEC958] = 1,
1215 [SNDRV_CTL_ELEM_TYPE_INTEGER64] = 64,
1216 };
1164 struct snd_card *card = file->card; 1217 struct snd_card *card = file->card;
1165 struct snd_kcontrol kctl, *_kctl; 1218 struct snd_kcontrol *kctl;
1219 unsigned int count;
1166 unsigned int access; 1220 unsigned int access;
1167 long private_size; 1221 long private_size;
1168 struct user_element *ue; 1222 struct user_element *ue;
1169 int idx, err; 1223 unsigned int offset;
1224 int err;
1170 1225
1171 if (info->count < 1)
1172 return -EINVAL;
1173 if (!*info->id.name) 1226 if (!*info->id.name)
1174 return -EINVAL; 1227 return -EINVAL;
1175 if (strnlen(info->id.name, sizeof(info->id.name)) >= sizeof(info->id.name)) 1228 if (strnlen(info->id.name, sizeof(info->id.name)) >= sizeof(info->id.name))
1176 return -EINVAL; 1229 return -EINVAL;
1177 access = info->access == 0 ? SNDRV_CTL_ELEM_ACCESS_READWRITE :
1178 (info->access & (SNDRV_CTL_ELEM_ACCESS_READWRITE|
1179 SNDRV_CTL_ELEM_ACCESS_INACTIVE|
1180 SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE));
1181 info->id.numid = 0;
1182 memset(&kctl, 0, sizeof(kctl));
1183 1230
1231 /* Delete a control to replace them if needed. */
1184 if (replace) { 1232 if (replace) {
1233 info->id.numid = 0;
1185 err = snd_ctl_remove_user_ctl(file, &info->id); 1234 err = snd_ctl_remove_user_ctl(file, &info->id);
1186 if (err) 1235 if (err)
1187 return err; 1236 return err;
1188 } 1237 }
1189 1238
1190 if (card->user_ctl_count >= MAX_USER_CONTROLS) 1239 /*
1240 * The number of userspace controls are counted control by control,
1241 * not element by element.
1242 */
1243 if (card->user_ctl_count + 1 > MAX_USER_CONTROLS)
1191 return -ENOMEM; 1244 return -ENOMEM;
1192 1245
1193 memcpy(&kctl.id, &info->id, sizeof(info->id)); 1246 /* Check the number of elements for this userspace control. */
1194 kctl.count = info->owner ? info->owner : 1; 1247 count = info->owner;
1195 access |= SNDRV_CTL_ELEM_ACCESS_USER; 1248 if (count == 0)
1196 if (info->type == SNDRV_CTL_ELEM_TYPE_ENUMERATED) 1249 count = 1;
1197 kctl.info = snd_ctl_elem_user_enum_info; 1250
1198 else 1251 /* Arrange access permissions if needed. */
1199 kctl.info = snd_ctl_elem_user_info; 1252 access = info->access;
1200 if (access & SNDRV_CTL_ELEM_ACCESS_READ) 1253 if (access == 0)
1201 kctl.get = snd_ctl_elem_user_get; 1254 access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
1202 if (access & SNDRV_CTL_ELEM_ACCESS_WRITE) 1255 access &= (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1203 kctl.put = snd_ctl_elem_user_put; 1256 SNDRV_CTL_ELEM_ACCESS_INACTIVE |
1204 if (access & SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE) { 1257 SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE);
1205 kctl.tlv.c = snd_ctl_elem_user_tlv; 1258 if (access & SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE)
1206 access |= SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; 1259 access |= SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK;
1207 } 1260 access |= SNDRV_CTL_ELEM_ACCESS_USER;
1208 switch (info->type) { 1261
1209 case SNDRV_CTL_ELEM_TYPE_BOOLEAN: 1262 /*
1210 case SNDRV_CTL_ELEM_TYPE_INTEGER: 1263 * Check information and calculate the size of data specific to
1211 private_size = sizeof(long); 1264 * this userspace control.
1212 if (info->count > 128) 1265 */
1213 return -EINVAL; 1266 if (info->type < SNDRV_CTL_ELEM_TYPE_BOOLEAN ||
1214 break; 1267 info->type > SNDRV_CTL_ELEM_TYPE_INTEGER64)
1215 case SNDRV_CTL_ELEM_TYPE_INTEGER64:
1216 private_size = sizeof(long long);
1217 if (info->count > 64)
1218 return -EINVAL;
1219 break;
1220 case SNDRV_CTL_ELEM_TYPE_ENUMERATED:
1221 private_size = sizeof(unsigned int);
1222 if (info->count > 128 || info->value.enumerated.items == 0)
1223 return -EINVAL;
1224 break;
1225 case SNDRV_CTL_ELEM_TYPE_BYTES:
1226 private_size = sizeof(unsigned char);
1227 if (info->count > 512)
1228 return -EINVAL;
1229 break;
1230 case SNDRV_CTL_ELEM_TYPE_IEC958:
1231 private_size = sizeof(struct snd_aes_iec958);
1232 if (info->count != 1)
1233 return -EINVAL;
1234 break;
1235 default:
1236 return -EINVAL; 1268 return -EINVAL;
1237 } 1269 if (info->type == SNDRV_CTL_ELEM_TYPE_ENUMERATED &&
1238 private_size *= info->count; 1270 info->value.enumerated.items == 0)
1239 ue = kzalloc(sizeof(struct user_element) + private_size, GFP_KERNEL); 1271 return -EINVAL;
1240 if (ue == NULL) 1272 if (info->count < 1 ||
1273 info->count > max_value_counts[info->type])
1274 return -EINVAL;
1275 private_size = value_sizes[info->type] * info->count;
1276
1277 /*
1278 * Keep memory object for this userspace control. After passing this
1279 * code block, the instance should be freed by snd_ctl_free_one().
1280 *
1281 * Note that these elements in this control are locked.
1282 */
1283 err = snd_ctl_new(&kctl, count, access, file);
1284 if (err < 0)
1285 return err;
1286 memcpy(&kctl->id, &info->id, sizeof(kctl->id));
1287 kctl->private_data = kzalloc(sizeof(struct user_element) + private_size * count,
1288 GFP_KERNEL);
1289 if (kctl->private_data == NULL) {
1290 kfree(kctl);
1241 return -ENOMEM; 1291 return -ENOMEM;
1292 }
1293 kctl->private_free = snd_ctl_elem_user_free;
1294
1295 /* Set private data for this userspace control. */
1296 ue = (struct user_element *)kctl->private_data;
1242 ue->card = card; 1297 ue->card = card;
1243 ue->info = *info; 1298 ue->info = *info;
1244 ue->info.access = 0; 1299 ue->info.access = 0;
@@ -1247,23 +1302,36 @@ static int snd_ctl_elem_add(struct snd_ctl_file *file,
1247 if (ue->info.type == SNDRV_CTL_ELEM_TYPE_ENUMERATED) { 1302 if (ue->info.type == SNDRV_CTL_ELEM_TYPE_ENUMERATED) {
1248 err = snd_ctl_elem_init_enum_names(ue); 1303 err = snd_ctl_elem_init_enum_names(ue);
1249 if (err < 0) { 1304 if (err < 0) {
1250 kfree(ue); 1305 snd_ctl_free_one(kctl);
1251 return err; 1306 return err;
1252 } 1307 }
1253 } 1308 }
1254 kctl.private_free = snd_ctl_elem_user_free; 1309
1255 _kctl = snd_ctl_new(&kctl, access); 1310 /* Set callback functions. */
1256 if (_kctl == NULL) { 1311 if (info->type == SNDRV_CTL_ELEM_TYPE_ENUMERATED)
1257 kfree(ue->priv_data); 1312 kctl->info = snd_ctl_elem_user_enum_info;
1258 kfree(ue); 1313 else
1259 return -ENOMEM; 1314 kctl->info = snd_ctl_elem_user_info;
1260 } 1315 if (access & SNDRV_CTL_ELEM_ACCESS_READ)
1261 _kctl->private_data = ue; 1316 kctl->get = snd_ctl_elem_user_get;
1262 for (idx = 0; idx < _kctl->count; idx++) 1317 if (access & SNDRV_CTL_ELEM_ACCESS_WRITE)
1263 _kctl->vd[idx].owner = file; 1318 kctl->put = snd_ctl_elem_user_put;
1264 err = snd_ctl_add(card, _kctl); 1319 if (access & SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE)
1320 kctl->tlv.c = snd_ctl_elem_user_tlv;
1321
1322 /* This function manage to free the instance on failure. */
1323 err = snd_ctl_add(card, kctl);
1265 if (err < 0) 1324 if (err < 0)
1266 return err; 1325 return err;
1326 offset = snd_ctl_get_ioff(kctl, &info->id);
1327 snd_ctl_build_ioff(&info->id, kctl, offset);
1328 /*
1329 * Here we cannot fill any field for the number of elements added by
1330 * this operation because there're no specific fields. The usage of
1331 * 'owner' field for this purpose may cause any bugs to userspace
1332 * applications because the field originally means PID of a process
1333 * which locks the element.
1334 */
1267 1335
1268 down_write(&card->controls_rwsem); 1336 down_write(&card->controls_rwsem);
1269 card->user_ctl_count++; 1337 card->user_ctl_count++;
@@ -1276,9 +1344,19 @@ static int snd_ctl_elem_add_user(struct snd_ctl_file *file,
1276 struct snd_ctl_elem_info __user *_info, int replace) 1344 struct snd_ctl_elem_info __user *_info, int replace)
1277{ 1345{
1278 struct snd_ctl_elem_info info; 1346 struct snd_ctl_elem_info info;
1347 int err;
1348
1279 if (copy_from_user(&info, _info, sizeof(info))) 1349 if (copy_from_user(&info, _info, sizeof(info)))
1280 return -EFAULT; 1350 return -EFAULT;
1281 return snd_ctl_elem_add(file, &info, replace); 1351 err = snd_ctl_elem_add(file, &info, replace);
1352 if (err < 0)
1353 return err;
1354 if (copy_to_user(_info, &info, sizeof(info))) {
1355 snd_ctl_remove_user_ctl(file, &info.id);
1356 return -EFAULT;
1357 }
1358
1359 return 0;
1282} 1360}
1283 1361
1284static int snd_ctl_elem_remove(struct snd_ctl_file *file, 1362static int snd_ctl_elem_remove(struct snd_ctl_file *file,
@@ -1338,9 +1416,12 @@ static int snd_ctl_tlv_ioctl(struct snd_ctl_file *file,
1338 goto __kctl_end; 1416 goto __kctl_end;
1339 } 1417 }
1340 vd = &kctl->vd[tlv.numid - kctl->id.numid]; 1418 vd = &kctl->vd[tlv.numid - kctl->id.numid];
1341 if ((op_flag == 0 && (vd->access & SNDRV_CTL_ELEM_ACCESS_TLV_READ) == 0) || 1419 if ((op_flag == SNDRV_CTL_TLV_OP_READ &&
1342 (op_flag > 0 && (vd->access & SNDRV_CTL_ELEM_ACCESS_TLV_WRITE) == 0) || 1420 (vd->access & SNDRV_CTL_ELEM_ACCESS_TLV_READ) == 0) ||
1343 (op_flag < 0 && (vd->access & SNDRV_CTL_ELEM_ACCESS_TLV_COMMAND) == 0)) { 1421 (op_flag == SNDRV_CTL_TLV_OP_WRITE &&
1422 (vd->access & SNDRV_CTL_ELEM_ACCESS_TLV_WRITE) == 0) ||
1423 (op_flag == SNDRV_CTL_TLV_OP_CMD &&
1424 (vd->access & SNDRV_CTL_ELEM_ACCESS_TLV_COMMAND) == 0)) {
1344 err = -ENXIO; 1425 err = -ENXIO;
1345 goto __kctl_end; 1426 goto __kctl_end;
1346 } 1427 }
@@ -1357,7 +1438,7 @@ static int snd_ctl_tlv_ioctl(struct snd_ctl_file *file,
1357 return 0; 1438 return 0;
1358 } 1439 }
1359 } else { 1440 } else {
1360 if (op_flag) { 1441 if (op_flag != SNDRV_CTL_TLV_OP_READ) {
1361 err = -ENXIO; 1442 err = -ENXIO;
1362 goto __kctl_end; 1443 goto __kctl_end;
1363 } 1444 }
diff --git a/sound/core/device.c b/sound/core/device.c
index 41bec3075ae5..8918838b1999 100644
--- a/sound/core/device.c
+++ b/sound/core/device.c
@@ -50,10 +50,8 @@ int snd_device_new(struct snd_card *card, enum snd_device_type type,
50 if (snd_BUG_ON(!card || !device_data || !ops)) 50 if (snd_BUG_ON(!card || !device_data || !ops))
51 return -ENXIO; 51 return -ENXIO;
52 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 52 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
53 if (dev == NULL) { 53 if (!dev)
54 dev_err(card->dev, "Cannot allocate device, type=%d\n", type);
55 return -ENOMEM; 54 return -ENOMEM;
56 }
57 INIT_LIST_HEAD(&dev->list); 55 INIT_LIST_HEAD(&dev->list);
58 dev->card = card; 56 dev->card = card;
59 dev->type = type; 57 dev->type = type;
@@ -73,7 +71,7 @@ int snd_device_new(struct snd_card *card, enum snd_device_type type,
73} 71}
74EXPORT_SYMBOL(snd_device_new); 72EXPORT_SYMBOL(snd_device_new);
75 73
76static int __snd_device_disconnect(struct snd_device *dev) 74static void __snd_device_disconnect(struct snd_device *dev)
77{ 75{
78 if (dev->state == SNDRV_DEV_REGISTERED) { 76 if (dev->state == SNDRV_DEV_REGISTERED) {
79 if (dev->ops->dev_disconnect && 77 if (dev->ops->dev_disconnect &&
@@ -81,7 +79,6 @@ static int __snd_device_disconnect(struct snd_device *dev)
81 dev_err(dev->card->dev, "device disconnect failure\n"); 79 dev_err(dev->card->dev, "device disconnect failure\n");
82 dev->state = SNDRV_DEV_DISCONNECTED; 80 dev->state = SNDRV_DEV_DISCONNECTED;
83 } 81 }
84 return 0;
85} 82}
86 83
87static void __snd_device_free(struct snd_device *dev) 84static void __snd_device_free(struct snd_device *dev)
@@ -109,6 +106,34 @@ static struct snd_device *look_for_dev(struct snd_card *card, void *device_data)
109} 106}
110 107
111/** 108/**
109 * snd_device_disconnect - disconnect the device
110 * @card: the card instance
111 * @device_data: the data pointer to disconnect
112 *
113 * Turns the device into the disconnection state, invoking
114 * dev_disconnect callback, if the device was already registered.
115 *
116 * Usually called from snd_card_disconnect().
117 *
118 * Return: Zero if successful, or a negative error code on failure or if the
119 * device not found.
120 */
121void snd_device_disconnect(struct snd_card *card, void *device_data)
122{
123 struct snd_device *dev;
124
125 if (snd_BUG_ON(!card || !device_data))
126 return;
127 dev = look_for_dev(card, device_data);
128 if (dev)
129 __snd_device_disconnect(dev);
130 else
131 dev_dbg(card->dev, "device disconnect %p (from %pF), not found\n",
132 device_data, __builtin_return_address(0));
133}
134EXPORT_SYMBOL_GPL(snd_device_disconnect);
135
136/**
112 * snd_device_free - release the device from the card 137 * snd_device_free - release the device from the card
113 * @card: the card instance 138 * @card: the card instance
114 * @device_data: the data pointer to release 139 * @device_data: the data pointer to release
@@ -195,18 +220,14 @@ int snd_device_register_all(struct snd_card *card)
195 * disconnect all the devices on the card. 220 * disconnect all the devices on the card.
196 * called from init.c 221 * called from init.c
197 */ 222 */
198int snd_device_disconnect_all(struct snd_card *card) 223void snd_device_disconnect_all(struct snd_card *card)
199{ 224{
200 struct snd_device *dev; 225 struct snd_device *dev;
201 int err = 0;
202 226
203 if (snd_BUG_ON(!card)) 227 if (snd_BUG_ON(!card))
204 return -ENXIO; 228 return;
205 list_for_each_entry_reverse(dev, &card->devices, list) { 229 list_for_each_entry_reverse(dev, &card->devices, list)
206 if (__snd_device_disconnect(dev) < 0) 230 __snd_device_disconnect(dev);
207 err = -ENXIO;
208 }
209 return err;
210} 231}
211 232
212/* 233/*
diff --git a/sound/core/hwdep.c b/sound/core/hwdep.c
index 84244a5143cf..51692c8a39ea 100644
--- a/sound/core/hwdep.c
+++ b/sound/core/hwdep.c
@@ -378,10 +378,8 @@ int snd_hwdep_new(struct snd_card *card, char *id, int device,
378 if (rhwdep) 378 if (rhwdep)
379 *rhwdep = NULL; 379 *rhwdep = NULL;
380 hwdep = kzalloc(sizeof(*hwdep), GFP_KERNEL); 380 hwdep = kzalloc(sizeof(*hwdep), GFP_KERNEL);
381 if (hwdep == NULL) { 381 if (!hwdep)
382 dev_err(card->dev, "hwdep: cannot allocate\n");
383 return -ENOMEM; 382 return -ENOMEM;
384 }
385 383
386 init_waitqueue_head(&hwdep->open_wait); 384 init_waitqueue_head(&hwdep->open_wait);
387 mutex_init(&hwdep->open_mutex); 385 mutex_init(&hwdep->open_mutex);
diff --git a/sound/core/init.c b/sound/core/init.c
index 35419054821c..04734e047bfe 100644
--- a/sound/core/init.c
+++ b/sound/core/init.c
@@ -400,7 +400,6 @@ static const struct file_operations snd_shutdown_f_ops =
400int snd_card_disconnect(struct snd_card *card) 400int snd_card_disconnect(struct snd_card *card)
401{ 401{
402 struct snd_monitor_file *mfile; 402 struct snd_monitor_file *mfile;
403 int err;
404 403
405 if (!card) 404 if (!card)
406 return -EINVAL; 405 return -EINVAL;
@@ -445,9 +444,7 @@ int snd_card_disconnect(struct snd_card *card)
445#endif 444#endif
446 445
447 /* notify all devices that we are disconnected */ 446 /* notify all devices that we are disconnected */
448 err = snd_device_disconnect_all(card); 447 snd_device_disconnect_all(card);
449 if (err < 0)
450 dev_err(card->dev, "not all devices for card %i can be disconnected\n", card->number);
451 448
452 snd_info_card_disconnect(card); 449 snd_info_card_disconnect(card);
453 if (card->registered) { 450 if (card->registered) {
diff --git a/sound/core/oss/mixer_oss.c b/sound/core/oss/mixer_oss.c
index 5e6349f00ecd..056f8e274851 100644
--- a/sound/core/oss/mixer_oss.c
+++ b/sound/core/oss/mixer_oss.c
@@ -1212,10 +1212,8 @@ static void snd_mixer_oss_proc_write(struct snd_info_entry *entry,
1212 /* not changed */ 1212 /* not changed */
1213 goto __unlock; 1213 goto __unlock;
1214 tbl = kmalloc(sizeof(*tbl), GFP_KERNEL); 1214 tbl = kmalloc(sizeof(*tbl), GFP_KERNEL);
1215 if (! tbl) { 1215 if (!tbl)
1216 pr_err("ALSA: mixer_oss: no memory\n");
1217 goto __unlock; 1216 goto __unlock;
1218 }
1219 tbl->oss_id = ch; 1217 tbl->oss_id = ch;
1220 tbl->name = kstrdup(str, GFP_KERNEL); 1218 tbl->name = kstrdup(str, GFP_KERNEL);
1221 if (! tbl->name) { 1219 if (! tbl->name) {
diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
index 80423a4ccab6..58550cc93f28 100644
--- a/sound/core/oss/pcm_oss.c
+++ b/sound/core/oss/pcm_oss.c
@@ -854,7 +854,6 @@ static int snd_pcm_oss_change_params(struct snd_pcm_substream *substream)
854 params = kmalloc(sizeof(*params), GFP_KERNEL); 854 params = kmalloc(sizeof(*params), GFP_KERNEL);
855 sparams = kmalloc(sizeof(*sparams), GFP_KERNEL); 855 sparams = kmalloc(sizeof(*sparams), GFP_KERNEL);
856 if (!sw_params || !params || !sparams) { 856 if (!sw_params || !params || !sparams) {
857 pcm_dbg(substream->pcm, "No memory\n");
858 err = -ENOMEM; 857 err = -ENOMEM;
859 goto failure; 858 goto failure;
860 } 859 }
diff --git a/sound/core/pcm.c b/sound/core/pcm.c
index 0345e53a340c..b25bcf5b8644 100644
--- a/sound/core/pcm.c
+++ b/sound/core/pcm.c
@@ -49,8 +49,6 @@ static struct snd_pcm *snd_pcm_get(struct snd_card *card, int device)
49 struct snd_pcm *pcm; 49 struct snd_pcm *pcm;
50 50
51 list_for_each_entry(pcm, &snd_pcm_devices, list) { 51 list_for_each_entry(pcm, &snd_pcm_devices, list) {
52 if (pcm->internal)
53 continue;
54 if (pcm->card == card && pcm->device == device) 52 if (pcm->card == card && pcm->device == device)
55 return pcm; 53 return pcm;
56 } 54 }
@@ -62,8 +60,6 @@ static int snd_pcm_next(struct snd_card *card, int device)
62 struct snd_pcm *pcm; 60 struct snd_pcm *pcm;
63 61
64 list_for_each_entry(pcm, &snd_pcm_devices, list) { 62 list_for_each_entry(pcm, &snd_pcm_devices, list) {
65 if (pcm->internal)
66 continue;
67 if (pcm->card == card && pcm->device > device) 63 if (pcm->card == card && pcm->device > device)
68 return pcm->device; 64 return pcm->device;
69 else if (pcm->card->number > card->number) 65 else if (pcm->card->number > card->number)
@@ -76,6 +72,9 @@ static int snd_pcm_add(struct snd_pcm *newpcm)
76{ 72{
77 struct snd_pcm *pcm; 73 struct snd_pcm *pcm;
78 74
75 if (newpcm->internal)
76 return 0;
77
79 list_for_each_entry(pcm, &snd_pcm_devices, list) { 78 list_for_each_entry(pcm, &snd_pcm_devices, list) {
80 if (pcm->card == newpcm->card && pcm->device == newpcm->device) 79 if (pcm->card == newpcm->card && pcm->device == newpcm->device)
81 return -EBUSY; 80 return -EBUSY;
@@ -344,11 +343,8 @@ static void snd_pcm_proc_info_read(struct snd_pcm_substream *substream,
344 return; 343 return;
345 344
346 info = kmalloc(sizeof(*info), GFP_KERNEL); 345 info = kmalloc(sizeof(*info), GFP_KERNEL);
347 if (! info) { 346 if (!info)
348 pcm_dbg(substream->pcm,
349 "snd_pcm_proc_info_read: cannot malloc\n");
350 return; 347 return;
351 }
352 348
353 err = snd_pcm_info(substream, info); 349 err = snd_pcm_info(substream, info);
354 if (err < 0) { 350 if (err < 0) {
@@ -718,10 +714,8 @@ int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count)
718 prev = NULL; 714 prev = NULL;
719 for (idx = 0, prev = NULL; idx < substream_count; idx++) { 715 for (idx = 0, prev = NULL; idx < substream_count; idx++) {
720 substream = kzalloc(sizeof(*substream), GFP_KERNEL); 716 substream = kzalloc(sizeof(*substream), GFP_KERNEL);
721 if (substream == NULL) { 717 if (!substream)
722 pcm_err(pcm, "Cannot allocate PCM substream\n");
723 return -ENOMEM; 718 return -ENOMEM;
724 }
725 substream->pcm = pcm; 719 substream->pcm = pcm;
726 substream->pstr = pstr; 720 substream->pstr = pstr;
727 substream->number = idx; 721 substream->number = idx;
@@ -775,13 +769,14 @@ static int _snd_pcm_new(struct snd_card *card, const char *id, int device,
775 if (rpcm) 769 if (rpcm)
776 *rpcm = NULL; 770 *rpcm = NULL;
777 pcm = kzalloc(sizeof(*pcm), GFP_KERNEL); 771 pcm = kzalloc(sizeof(*pcm), GFP_KERNEL);
778 if (pcm == NULL) { 772 if (!pcm)
779 dev_err(card->dev, "Cannot allocate PCM\n");
780 return -ENOMEM; 773 return -ENOMEM;
781 }
782 pcm->card = card; 774 pcm->card = card;
783 pcm->device = device; 775 pcm->device = device;
784 pcm->internal = internal; 776 pcm->internal = internal;
777 mutex_init(&pcm->open_mutex);
778 init_waitqueue_head(&pcm->open_wait);
779 INIT_LIST_HEAD(&pcm->list);
785 if (id) 780 if (id)
786 strlcpy(pcm->id, id, sizeof(pcm->id)); 781 strlcpy(pcm->id, id, sizeof(pcm->id));
787 if ((err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_PLAYBACK, playback_count)) < 0) { 782 if ((err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_PLAYBACK, playback_count)) < 0) {
@@ -792,8 +787,6 @@ static int _snd_pcm_new(struct snd_card *card, const char *id, int device,
792 snd_pcm_free(pcm); 787 snd_pcm_free(pcm);
793 return err; 788 return err;
794 } 789 }
795 mutex_init(&pcm->open_mutex);
796 init_waitqueue_head(&pcm->open_wait);
797 if ((err = snd_device_new(card, SNDRV_DEV_PCM, pcm, &ops)) < 0) { 790 if ((err = snd_device_new(card, SNDRV_DEV_PCM, pcm, &ops)) < 0) {
798 snd_pcm_free(pcm); 791 snd_pcm_free(pcm);
799 return err; 792 return err;
@@ -888,8 +881,9 @@ static int snd_pcm_free(struct snd_pcm *pcm)
888 881
889 if (!pcm) 882 if (!pcm)
890 return 0; 883 return 0;
891 list_for_each_entry(notify, &snd_pcm_notify_list, list) { 884 if (!pcm->internal) {
892 notify->n_unregister(pcm); 885 list_for_each_entry(notify, &snd_pcm_notify_list, list)
886 notify->n_unregister(pcm);
893 } 887 }
894 if (pcm->private_free) 888 if (pcm->private_free)
895 pcm->private_free(pcm); 889 pcm->private_free(pcm);
@@ -919,6 +913,9 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,
919 913
920 if (snd_BUG_ON(!pcm || !rsubstream)) 914 if (snd_BUG_ON(!pcm || !rsubstream))
921 return -ENXIO; 915 return -ENXIO;
916 if (snd_BUG_ON(stream != SNDRV_PCM_STREAM_PLAYBACK &&
917 stream != SNDRV_PCM_STREAM_CAPTURE))
918 return -EINVAL;
922 *rsubstream = NULL; 919 *rsubstream = NULL;
923 pstr = &pcm->streams[stream]; 920 pstr = &pcm->streams[stream];
924 if (pstr->substream == NULL || pstr->substream_count == 0) 921 if (pstr->substream == NULL || pstr->substream_count == 0)
@@ -927,25 +924,14 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,
927 card = pcm->card; 924 card = pcm->card;
928 prefer_subdevice = snd_ctl_get_preferred_subdevice(card, SND_CTL_SUBDEV_PCM); 925 prefer_subdevice = snd_ctl_get_preferred_subdevice(card, SND_CTL_SUBDEV_PCM);
929 926
930 switch (stream) { 927 if (pcm->info_flags & SNDRV_PCM_INFO_HALF_DUPLEX) {
931 case SNDRV_PCM_STREAM_PLAYBACK: 928 int opposite = !stream;
932 if (pcm->info_flags & SNDRV_PCM_INFO_HALF_DUPLEX) { 929
933 for (substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream; substream; substream = substream->next) { 930 for (substream = pcm->streams[opposite].substream; substream;
934 if (SUBSTREAM_BUSY(substream)) 931 substream = substream->next) {
935 return -EAGAIN; 932 if (SUBSTREAM_BUSY(substream))
936 } 933 return -EAGAIN;
937 }
938 break;
939 case SNDRV_PCM_STREAM_CAPTURE:
940 if (pcm->info_flags & SNDRV_PCM_INFO_HALF_DUPLEX) {
941 for (substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; substream; substream = substream->next) {
942 if (SUBSTREAM_BUSY(substream))
943 return -EAGAIN;
944 }
945 } 934 }
946 break;
947 default:
948 return -EINVAL;
949 } 935 }
950 936
951 if (file->f_flags & O_APPEND) { 937 if (file->f_flags & O_APPEND) {
@@ -968,15 +954,12 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,
968 return 0; 954 return 0;
969 } 955 }
970 956
971 if (prefer_subdevice >= 0) { 957 for (substream = pstr->substream; substream; substream = substream->next) {
972 for (substream = pstr->substream; substream; substream = substream->next) 958 if (!SUBSTREAM_BUSY(substream) &&
973 if (!SUBSTREAM_BUSY(substream) && substream->number == prefer_subdevice) 959 (prefer_subdevice == -1 ||
974 goto __ok; 960 substream->number == prefer_subdevice))
975 }
976 for (substream = pstr->substream; substream; substream = substream->next)
977 if (!SUBSTREAM_BUSY(substream))
978 break; 961 break;
979 __ok: 962 }
980 if (substream == NULL) 963 if (substream == NULL)
981 return -EAGAIN; 964 return -EAGAIN;
982 965
@@ -1086,15 +1069,16 @@ static int snd_pcm_dev_register(struct snd_device *device)
1086 if (snd_BUG_ON(!device || !device->device_data)) 1069 if (snd_BUG_ON(!device || !device->device_data))
1087 return -ENXIO; 1070 return -ENXIO;
1088 pcm = device->device_data; 1071 pcm = device->device_data;
1072 if (pcm->internal)
1073 return 0;
1074
1089 mutex_lock(&register_mutex); 1075 mutex_lock(&register_mutex);
1090 err = snd_pcm_add(pcm); 1076 err = snd_pcm_add(pcm);
1091 if (err) { 1077 if (err)
1092 mutex_unlock(&register_mutex); 1078 goto unlock;
1093 return err;
1094 }
1095 for (cidx = 0; cidx < 2; cidx++) { 1079 for (cidx = 0; cidx < 2; cidx++) {
1096 int devtype = -1; 1080 int devtype = -1;
1097 if (pcm->streams[cidx].substream == NULL || pcm->internal) 1081 if (pcm->streams[cidx].substream == NULL)
1098 continue; 1082 continue;
1099 switch (cidx) { 1083 switch (cidx) {
1100 case SNDRV_PCM_STREAM_PLAYBACK: 1084 case SNDRV_PCM_STREAM_PLAYBACK:
@@ -1109,9 +1093,8 @@ static int snd_pcm_dev_register(struct snd_device *device)
1109 &snd_pcm_f_ops[cidx], pcm, 1093 &snd_pcm_f_ops[cidx], pcm,
1110 &pcm->streams[cidx].dev); 1094 &pcm->streams[cidx].dev);
1111 if (err < 0) { 1095 if (err < 0) {
1112 list_del(&pcm->list); 1096 list_del_init(&pcm->list);
1113 mutex_unlock(&register_mutex); 1097 goto unlock;
1114 return err;
1115 } 1098 }
1116 1099
1117 for (substream = pcm->streams[cidx].substream; substream; substream = substream->next) 1100 for (substream = pcm->streams[cidx].substream; substream; substream = substream->next)
@@ -1121,8 +1104,9 @@ static int snd_pcm_dev_register(struct snd_device *device)
1121 list_for_each_entry(notify, &snd_pcm_notify_list, list) 1104 list_for_each_entry(notify, &snd_pcm_notify_list, list)
1122 notify->n_register(pcm); 1105 notify->n_register(pcm);
1123 1106
1107 unlock:
1124 mutex_unlock(&register_mutex); 1108 mutex_unlock(&register_mutex);
1125 return 0; 1109 return err;
1126} 1110}
1127 1111
1128static int snd_pcm_dev_disconnect(struct snd_device *device) 1112static int snd_pcm_dev_disconnect(struct snd_device *device)
@@ -1133,13 +1117,10 @@ static int snd_pcm_dev_disconnect(struct snd_device *device)
1133 int cidx; 1117 int cidx;
1134 1118
1135 mutex_lock(&register_mutex); 1119 mutex_lock(&register_mutex);
1136 if (list_empty(&pcm->list))
1137 goto unlock;
1138
1139 mutex_lock(&pcm->open_mutex); 1120 mutex_lock(&pcm->open_mutex);
1140 wake_up(&pcm->open_wait); 1121 wake_up(&pcm->open_wait);
1141 list_del_init(&pcm->list); 1122 list_del_init(&pcm->list);
1142 for (cidx = 0; cidx < 2; cidx++) 1123 for (cidx = 0; cidx < 2; cidx++) {
1143 for (substream = pcm->streams[cidx].substream; substream; substream = substream->next) { 1124 for (substream = pcm->streams[cidx].substream; substream; substream = substream->next) {
1144 snd_pcm_stream_lock_irq(substream); 1125 snd_pcm_stream_lock_irq(substream);
1145 if (substream->runtime) { 1126 if (substream->runtime) {
@@ -1149,18 +1130,20 @@ static int snd_pcm_dev_disconnect(struct snd_device *device)
1149 } 1130 }
1150 snd_pcm_stream_unlock_irq(substream); 1131 snd_pcm_stream_unlock_irq(substream);
1151 } 1132 }
1152 list_for_each_entry(notify, &snd_pcm_notify_list, list) { 1133 }
1153 notify->n_disconnect(pcm); 1134 if (!pcm->internal) {
1135 list_for_each_entry(notify, &snd_pcm_notify_list, list)
1136 notify->n_disconnect(pcm);
1154 } 1137 }
1155 for (cidx = 0; cidx < 2; cidx++) { 1138 for (cidx = 0; cidx < 2; cidx++) {
1156 snd_unregister_device(&pcm->streams[cidx].dev); 1139 if (!pcm->internal)
1140 snd_unregister_device(&pcm->streams[cidx].dev);
1157 if (pcm->streams[cidx].chmap_kctl) { 1141 if (pcm->streams[cidx].chmap_kctl) {
1158 snd_ctl_remove(pcm->card, pcm->streams[cidx].chmap_kctl); 1142 snd_ctl_remove(pcm->card, pcm->streams[cidx].chmap_kctl);
1159 pcm->streams[cidx].chmap_kctl = NULL; 1143 pcm->streams[cidx].chmap_kctl = NULL;
1160 } 1144 }
1161 } 1145 }
1162 mutex_unlock(&pcm->open_mutex); 1146 mutex_unlock(&pcm->open_mutex);
1163 unlock:
1164 mutex_unlock(&register_mutex); 1147 mutex_unlock(&register_mutex);
1165 return 0; 1148 return 0;
1166} 1149}
diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
index 2d957ba63557..b48b434444ed 100644
--- a/sound/core/pcm_compat.c
+++ b/sound/core/pcm_compat.c
@@ -194,18 +194,30 @@ struct snd_pcm_status32 {
194 u32 avail_max; 194 u32 avail_max;
195 u32 overrange; 195 u32 overrange;
196 s32 suspended_state; 196 s32 suspended_state;
197 u32 reserved_alignment; 197 u32 audio_tstamp_data;
198 struct compat_timespec audio_tstamp; 198 struct compat_timespec audio_tstamp;
199 unsigned char reserved[56-sizeof(struct compat_timespec)]; 199 struct compat_timespec driver_tstamp;
200 u32 audio_tstamp_accuracy;
201 unsigned char reserved[52-2*sizeof(struct compat_timespec)];
200} __attribute__((packed)); 202} __attribute__((packed));
201 203
202 204
203static int snd_pcm_status_user_compat(struct snd_pcm_substream *substream, 205static int snd_pcm_status_user_compat(struct snd_pcm_substream *substream,
204 struct snd_pcm_status32 __user *src) 206 struct snd_pcm_status32 __user *src,
207 bool ext)
205{ 208{
206 struct snd_pcm_status status; 209 struct snd_pcm_status status;
207 int err; 210 int err;
208 211
212 memset(&status, 0, sizeof(status));
213 /*
214 * with extension, parameters are read/write,
215 * get audio_tstamp_data from user,
216 * ignore rest of status structure
217 */
218 if (ext && get_user(status.audio_tstamp_data,
219 (u32 __user *)(&src->audio_tstamp_data)))
220 return -EFAULT;
209 err = snd_pcm_status(substream, &status); 221 err = snd_pcm_status(substream, &status);
210 if (err < 0) 222 if (err < 0)
211 return err; 223 return err;
@@ -222,7 +234,10 @@ static int snd_pcm_status_user_compat(struct snd_pcm_substream *substream,
222 put_user(status.avail_max, &src->avail_max) || 234 put_user(status.avail_max, &src->avail_max) ||
223 put_user(status.overrange, &src->overrange) || 235 put_user(status.overrange, &src->overrange) ||
224 put_user(status.suspended_state, &src->suspended_state) || 236 put_user(status.suspended_state, &src->suspended_state) ||
225 compat_put_timespec(&status.audio_tstamp, &src->audio_tstamp)) 237 put_user(status.audio_tstamp_data, &src->audio_tstamp_data) ||
238 compat_put_timespec(&status.audio_tstamp, &src->audio_tstamp) ||
239 compat_put_timespec(&status.driver_tstamp, &src->driver_tstamp) ||
240 put_user(status.audio_tstamp_accuracy, &src->audio_tstamp_accuracy))
226 return -EFAULT; 241 return -EFAULT;
227 242
228 return err; 243 return err;
@@ -457,6 +472,7 @@ enum {
457 SNDRV_PCM_IOCTL_HW_PARAMS32 = _IOWR('A', 0x11, struct snd_pcm_hw_params32), 472 SNDRV_PCM_IOCTL_HW_PARAMS32 = _IOWR('A', 0x11, struct snd_pcm_hw_params32),
458 SNDRV_PCM_IOCTL_SW_PARAMS32 = _IOWR('A', 0x13, struct snd_pcm_sw_params32), 473 SNDRV_PCM_IOCTL_SW_PARAMS32 = _IOWR('A', 0x13, struct snd_pcm_sw_params32),
459 SNDRV_PCM_IOCTL_STATUS32 = _IOR('A', 0x20, struct snd_pcm_status32), 474 SNDRV_PCM_IOCTL_STATUS32 = _IOR('A', 0x20, struct snd_pcm_status32),
475 SNDRV_PCM_IOCTL_STATUS_EXT32 = _IOWR('A', 0x24, struct snd_pcm_status32),
460 SNDRV_PCM_IOCTL_DELAY32 = _IOR('A', 0x21, s32), 476 SNDRV_PCM_IOCTL_DELAY32 = _IOR('A', 0x21, s32),
461 SNDRV_PCM_IOCTL_CHANNEL_INFO32 = _IOR('A', 0x32, struct snd_pcm_channel_info32), 477 SNDRV_PCM_IOCTL_CHANNEL_INFO32 = _IOR('A', 0x32, struct snd_pcm_channel_info32),
462 SNDRV_PCM_IOCTL_REWIND32 = _IOW('A', 0x46, u32), 478 SNDRV_PCM_IOCTL_REWIND32 = _IOW('A', 0x46, u32),
@@ -517,7 +533,9 @@ static long snd_pcm_ioctl_compat(struct file *file, unsigned int cmd, unsigned l
517 case SNDRV_PCM_IOCTL_SW_PARAMS32: 533 case SNDRV_PCM_IOCTL_SW_PARAMS32:
518 return snd_pcm_ioctl_sw_params_compat(substream, argp); 534 return snd_pcm_ioctl_sw_params_compat(substream, argp);
519 case SNDRV_PCM_IOCTL_STATUS32: 535 case SNDRV_PCM_IOCTL_STATUS32:
520 return snd_pcm_status_user_compat(substream, argp); 536 return snd_pcm_status_user_compat(substream, argp, false);
537 case SNDRV_PCM_IOCTL_STATUS_EXT32:
538 return snd_pcm_status_user_compat(substream, argp, true);
521 case SNDRV_PCM_IOCTL_SYNC_PTR32: 539 case SNDRV_PCM_IOCTL_SYNC_PTR32:
522 return snd_pcm_ioctl_sync_ptr_compat(substream, argp); 540 return snd_pcm_ioctl_sync_ptr_compat(substream, argp);
523 case SNDRV_PCM_IOCTL_CHANNEL_INFO32: 541 case SNDRV_PCM_IOCTL_CHANNEL_INFO32:
diff --git a/sound/core/pcm_dmaengine.c b/sound/core/pcm_dmaengine.c
index 6542c4083594..fba365a78390 100644
--- a/sound/core/pcm_dmaengine.c
+++ b/sound/core/pcm_dmaengine.c
@@ -289,7 +289,7 @@ EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_request_channel);
289 * 289 *
290 * The function should usually be called from the pcm open callback. Note that 290 * The function should usually be called from the pcm open callback. Note that
291 * this function will use private_data field of the substream's runtime. So it 291 * this function will use private_data field of the substream's runtime. So it
292 * is not availabe to your pcm driver implementation. 292 * is not available to your pcm driver implementation.
293 */ 293 */
294int snd_dmaengine_pcm_open(struct snd_pcm_substream *substream, 294int snd_dmaengine_pcm_open(struct snd_pcm_substream *substream,
295 struct dma_chan *chan) 295 struct dma_chan *chan)
@@ -328,7 +328,7 @@ EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_open);
328 * This function will request a DMA channel using the passed filter function and 328 * This function will request a DMA channel using the passed filter function and
329 * data. The function should usually be called from the pcm open callback. Note 329 * data. The function should usually be called from the pcm open callback. Note
330 * that this function will use private_data field of the substream's runtime. So 330 * that this function will use private_data field of the substream's runtime. So
331 * it is not availabe to your pcm driver implementation. 331 * it is not available to your pcm driver implementation.
332 */ 332 */
333int snd_dmaengine_pcm_open_request_chan(struct snd_pcm_substream *substream, 333int snd_dmaengine_pcm_open_request_chan(struct snd_pcm_substream *substream,
334 dma_filter_fn filter_fn, void *filter_data) 334 dma_filter_fn filter_fn, void *filter_data)
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index ffd656012ab8..ac6b33f3779c 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -232,6 +232,49 @@ int snd_pcm_update_state(struct snd_pcm_substream *substream,
232 return 0; 232 return 0;
233} 233}
234 234
235static void update_audio_tstamp(struct snd_pcm_substream *substream,
236 struct timespec *curr_tstamp,
237 struct timespec *audio_tstamp)
238{
239 struct snd_pcm_runtime *runtime = substream->runtime;
240 u64 audio_frames, audio_nsecs;
241 struct timespec driver_tstamp;
242
243 if (runtime->tstamp_mode != SNDRV_PCM_TSTAMP_ENABLE)
244 return;
245
246 if (!(substream->ops->get_time_info) ||
247 (runtime->audio_tstamp_report.actual_type ==
248 SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT)) {
249
250 /*
251 * provide audio timestamp derived from pointer position
252 * add delay only if requested
253 */
254
255 audio_frames = runtime->hw_ptr_wrap + runtime->status->hw_ptr;
256
257 if (runtime->audio_tstamp_config.report_delay) {
258 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
259 audio_frames -= runtime->delay;
260 else
261 audio_frames += runtime->delay;
262 }
263 audio_nsecs = div_u64(audio_frames * 1000000000LL,
264 runtime->rate);
265 *audio_tstamp = ns_to_timespec(audio_nsecs);
266 }
267 runtime->status->audio_tstamp = *audio_tstamp;
268 runtime->status->tstamp = *curr_tstamp;
269
270 /*
271 * re-take a driver timestamp to let apps detect if the reference tstamp
272 * read by low-level hardware was provided with a delay
273 */
274 snd_pcm_gettime(substream->runtime, (struct timespec *)&driver_tstamp);
275 runtime->driver_tstamp = driver_tstamp;
276}
277
235static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream, 278static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream,
236 unsigned int in_interrupt) 279 unsigned int in_interrupt)
237{ 280{
@@ -256,11 +299,18 @@ static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream,
256 pos = substream->ops->pointer(substream); 299 pos = substream->ops->pointer(substream);
257 curr_jiffies = jiffies; 300 curr_jiffies = jiffies;
258 if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) { 301 if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) {
259 snd_pcm_gettime(runtime, (struct timespec *)&curr_tstamp); 302 if ((substream->ops->get_time_info) &&
260 303 (runtime->audio_tstamp_config.type_requested != SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT)) {
261 if ((runtime->hw.info & SNDRV_PCM_INFO_HAS_WALL_CLOCK) && 304 substream->ops->get_time_info(substream, &curr_tstamp,
262 (substream->ops->wall_clock)) 305 &audio_tstamp,
263 substream->ops->wall_clock(substream, &audio_tstamp); 306 &runtime->audio_tstamp_config,
307 &runtime->audio_tstamp_report);
308
309 /* re-test in case tstamp type is not supported in hardware and was demoted to DEFAULT */
310 if (runtime->audio_tstamp_report.actual_type == SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT)
311 snd_pcm_gettime(runtime, (struct timespec *)&curr_tstamp);
312 } else
313 snd_pcm_gettime(runtime, (struct timespec *)&curr_tstamp);
264 } 314 }
265 315
266 if (pos == SNDRV_PCM_POS_XRUN) { 316 if (pos == SNDRV_PCM_POS_XRUN) {
@@ -403,8 +453,10 @@ static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream,
403 } 453 }
404 454
405 no_delta_check: 455 no_delta_check:
406 if (runtime->status->hw_ptr == new_hw_ptr) 456 if (runtime->status->hw_ptr == new_hw_ptr) {
457 update_audio_tstamp(substream, &curr_tstamp, &audio_tstamp);
407 return 0; 458 return 0;
459 }
408 460
409 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && 461 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
410 runtime->silence_size > 0) 462 runtime->silence_size > 0)
@@ -426,30 +478,8 @@ static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream,
426 snd_BUG_ON(crossed_boundary != 1); 478 snd_BUG_ON(crossed_boundary != 1);
427 runtime->hw_ptr_wrap += runtime->boundary; 479 runtime->hw_ptr_wrap += runtime->boundary;
428 } 480 }
429 if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) {
430 runtime->status->tstamp = curr_tstamp;
431 481
432 if (!(runtime->hw.info & SNDRV_PCM_INFO_HAS_WALL_CLOCK)) { 482 update_audio_tstamp(substream, &curr_tstamp, &audio_tstamp);
433 /*
434 * no wall clock available, provide audio timestamp
435 * derived from pointer position+delay
436 */
437 u64 audio_frames, audio_nsecs;
438
439 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
440 audio_frames = runtime->hw_ptr_wrap
441 + runtime->status->hw_ptr
442 - runtime->delay;
443 else
444 audio_frames = runtime->hw_ptr_wrap
445 + runtime->status->hw_ptr
446 + runtime->delay;
447 audio_nsecs = div_u64(audio_frames * 1000000000LL,
448 runtime->rate);
449 audio_tstamp = ns_to_timespec(audio_nsecs);
450 }
451 runtime->status->audio_tstamp = audio_tstamp;
452 }
453 483
454 return snd_pcm_update_state(substream, runtime); 484 return snd_pcm_update_state(substream, runtime);
455} 485}
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 279e24f61305..d126c03361ae 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -25,7 +25,6 @@
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/time.h> 26#include <linux/time.h>
27#include <linux/pm_qos.h> 27#include <linux/pm_qos.h>
28#include <linux/aio.h>
29#include <linux/io.h> 28#include <linux/io.h>
30#include <linux/dma-mapping.h> 29#include <linux/dma-mapping.h>
31#include <sound/core.h> 30#include <sound/core.h>
@@ -35,6 +34,7 @@
35#include <sound/pcm_params.h> 34#include <sound/pcm_params.h>
36#include <sound/timer.h> 35#include <sound/timer.h>
37#include <sound/minors.h> 36#include <sound/minors.h>
37#include <linux/uio.h>
38 38
39/* 39/*
40 * Compatibility 40 * Compatibility
@@ -707,6 +707,23 @@ int snd_pcm_status(struct snd_pcm_substream *substream,
707 struct snd_pcm_runtime *runtime = substream->runtime; 707 struct snd_pcm_runtime *runtime = substream->runtime;
708 708
709 snd_pcm_stream_lock_irq(substream); 709 snd_pcm_stream_lock_irq(substream);
710
711 snd_pcm_unpack_audio_tstamp_config(status->audio_tstamp_data,
712 &runtime->audio_tstamp_config);
713
714 /* backwards compatible behavior */
715 if (runtime->audio_tstamp_config.type_requested ==
716 SNDRV_PCM_AUDIO_TSTAMP_TYPE_COMPAT) {
717 if (runtime->hw.info & SNDRV_PCM_INFO_HAS_WALL_CLOCK)
718 runtime->audio_tstamp_config.type_requested =
719 SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK;
720 else
721 runtime->audio_tstamp_config.type_requested =
722 SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT;
723 runtime->audio_tstamp_report.valid = 0;
724 } else
725 runtime->audio_tstamp_report.valid = 1;
726
710 status->state = runtime->status->state; 727 status->state = runtime->status->state;
711 status->suspended_state = runtime->status->suspended_state; 728 status->suspended_state = runtime->status->suspended_state;
712 if (status->state == SNDRV_PCM_STATE_OPEN) 729 if (status->state == SNDRV_PCM_STATE_OPEN)
@@ -716,8 +733,15 @@ int snd_pcm_status(struct snd_pcm_substream *substream,
716 snd_pcm_update_hw_ptr(substream); 733 snd_pcm_update_hw_ptr(substream);
717 if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) { 734 if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) {
718 status->tstamp = runtime->status->tstamp; 735 status->tstamp = runtime->status->tstamp;
736 status->driver_tstamp = runtime->driver_tstamp;
719 status->audio_tstamp = 737 status->audio_tstamp =
720 runtime->status->audio_tstamp; 738 runtime->status->audio_tstamp;
739 if (runtime->audio_tstamp_report.valid == 1)
740 /* backwards compatibility, no report provided in COMPAT mode */
741 snd_pcm_pack_audio_tstamp_report(&status->audio_tstamp_data,
742 &status->audio_tstamp_accuracy,
743 &runtime->audio_tstamp_report);
744
721 goto _tstamp_end; 745 goto _tstamp_end;
722 } 746 }
723 } else { 747 } else {
@@ -753,12 +777,21 @@ int snd_pcm_status(struct snd_pcm_substream *substream,
753} 777}
754 778
755static int snd_pcm_status_user(struct snd_pcm_substream *substream, 779static int snd_pcm_status_user(struct snd_pcm_substream *substream,
756 struct snd_pcm_status __user * _status) 780 struct snd_pcm_status __user * _status,
781 bool ext)
757{ 782{
758 struct snd_pcm_status status; 783 struct snd_pcm_status status;
759 int res; 784 int res;
760 785
761 memset(&status, 0, sizeof(status)); 786 memset(&status, 0, sizeof(status));
787 /*
788 * with extension, parameters are read/write,
789 * get audio_tstamp_data from user,
790 * ignore rest of status structure
791 */
792 if (ext && get_user(status.audio_tstamp_data,
793 (u32 __user *)(&_status->audio_tstamp_data)))
794 return -EFAULT;
762 res = snd_pcm_status(substream, &status); 795 res = snd_pcm_status(substream, &status);
763 if (res < 0) 796 if (res < 0)
764 return res; 797 return res;
@@ -2725,7 +2758,9 @@ static int snd_pcm_common_ioctl1(struct file *file,
2725 case SNDRV_PCM_IOCTL_SW_PARAMS: 2758 case SNDRV_PCM_IOCTL_SW_PARAMS:
2726 return snd_pcm_sw_params_user(substream, arg); 2759 return snd_pcm_sw_params_user(substream, arg);
2727 case SNDRV_PCM_IOCTL_STATUS: 2760 case SNDRV_PCM_IOCTL_STATUS:
2728 return snd_pcm_status_user(substream, arg); 2761 return snd_pcm_status_user(substream, arg, false);
2762 case SNDRV_PCM_IOCTL_STATUS_EXT:
2763 return snd_pcm_status_user(substream, arg, true);
2729 case SNDRV_PCM_IOCTL_CHANNEL_INFO: 2764 case SNDRV_PCM_IOCTL_CHANNEL_INFO:
2730 return snd_pcm_channel_info_user(substream, arg); 2765 return snd_pcm_channel_info_user(substream, arg);
2731 case SNDRV_PCM_IOCTL_PREPARE: 2766 case SNDRV_PCM_IOCTL_PREPARE:
@@ -3033,9 +3068,7 @@ static ssize_t snd_pcm_write(struct file *file, const char __user *buf,
3033 return result; 3068 return result;
3034} 3069}
3035 3070
3036static ssize_t snd_pcm_aio_read(struct kiocb *iocb, const struct iovec *iov, 3071static ssize_t snd_pcm_readv(struct kiocb *iocb, struct iov_iter *to)
3037 unsigned long nr_segs, loff_t pos)
3038
3039{ 3072{
3040 struct snd_pcm_file *pcm_file; 3073 struct snd_pcm_file *pcm_file;
3041 struct snd_pcm_substream *substream; 3074 struct snd_pcm_substream *substream;
@@ -3052,16 +3085,18 @@ static ssize_t snd_pcm_aio_read(struct kiocb *iocb, const struct iovec *iov,
3052 runtime = substream->runtime; 3085 runtime = substream->runtime;
3053 if (runtime->status->state == SNDRV_PCM_STATE_OPEN) 3086 if (runtime->status->state == SNDRV_PCM_STATE_OPEN)
3054 return -EBADFD; 3087 return -EBADFD;
3055 if (nr_segs > 1024 || nr_segs != runtime->channels) 3088 if (!iter_is_iovec(to))
3089 return -EINVAL;
3090 if (to->nr_segs > 1024 || to->nr_segs != runtime->channels)
3056 return -EINVAL; 3091 return -EINVAL;
3057 if (!frame_aligned(runtime, iov->iov_len)) 3092 if (!frame_aligned(runtime, to->iov->iov_len))
3058 return -EINVAL; 3093 return -EINVAL;
3059 frames = bytes_to_samples(runtime, iov->iov_len); 3094 frames = bytes_to_samples(runtime, to->iov->iov_len);
3060 bufs = kmalloc(sizeof(void *) * nr_segs, GFP_KERNEL); 3095 bufs = kmalloc(sizeof(void *) * to->nr_segs, GFP_KERNEL);
3061 if (bufs == NULL) 3096 if (bufs == NULL)
3062 return -ENOMEM; 3097 return -ENOMEM;
3063 for (i = 0; i < nr_segs; ++i) 3098 for (i = 0; i < to->nr_segs; ++i)
3064 bufs[i] = iov[i].iov_base; 3099 bufs[i] = to->iov[i].iov_base;
3065 result = snd_pcm_lib_readv(substream, bufs, frames); 3100 result = snd_pcm_lib_readv(substream, bufs, frames);
3066 if (result > 0) 3101 if (result > 0)
3067 result = frames_to_bytes(runtime, result); 3102 result = frames_to_bytes(runtime, result);
@@ -3069,8 +3104,7 @@ static ssize_t snd_pcm_aio_read(struct kiocb *iocb, const struct iovec *iov,
3069 return result; 3104 return result;
3070} 3105}
3071 3106
3072static ssize_t snd_pcm_aio_write(struct kiocb *iocb, const struct iovec *iov, 3107static ssize_t snd_pcm_writev(struct kiocb *iocb, struct iov_iter *from)
3073 unsigned long nr_segs, loff_t pos)
3074{ 3108{
3075 struct snd_pcm_file *pcm_file; 3109 struct snd_pcm_file *pcm_file;
3076 struct snd_pcm_substream *substream; 3110 struct snd_pcm_substream *substream;
@@ -3087,15 +3121,17 @@ static ssize_t snd_pcm_aio_write(struct kiocb *iocb, const struct iovec *iov,
3087 runtime = substream->runtime; 3121 runtime = substream->runtime;
3088 if (runtime->status->state == SNDRV_PCM_STATE_OPEN) 3122 if (runtime->status->state == SNDRV_PCM_STATE_OPEN)
3089 return -EBADFD; 3123 return -EBADFD;
3090 if (nr_segs > 128 || nr_segs != runtime->channels || 3124 if (!iter_is_iovec(from))
3091 !frame_aligned(runtime, iov->iov_len)) 3125 return -EINVAL;
3126 if (from->nr_segs > 128 || from->nr_segs != runtime->channels ||
3127 !frame_aligned(runtime, from->iov->iov_len))
3092 return -EINVAL; 3128 return -EINVAL;
3093 frames = bytes_to_samples(runtime, iov->iov_len); 3129 frames = bytes_to_samples(runtime, from->iov->iov_len);
3094 bufs = kmalloc(sizeof(void *) * nr_segs, GFP_KERNEL); 3130 bufs = kmalloc(sizeof(void *) * from->nr_segs, GFP_KERNEL);
3095 if (bufs == NULL) 3131 if (bufs == NULL)
3096 return -ENOMEM; 3132 return -ENOMEM;
3097 for (i = 0; i < nr_segs; ++i) 3133 for (i = 0; i < from->nr_segs; ++i)
3098 bufs[i] = iov[i].iov_base; 3134 bufs[i] = from->iov[i].iov_base;
3099 result = snd_pcm_lib_writev(substream, bufs, frames); 3135 result = snd_pcm_lib_writev(substream, bufs, frames);
3100 if (result > 0) 3136 if (result > 0)
3101 result = frames_to_bytes(runtime, result); 3137 result = frames_to_bytes(runtime, result);
@@ -3633,7 +3669,7 @@ const struct file_operations snd_pcm_f_ops[2] = {
3633 { 3669 {
3634 .owner = THIS_MODULE, 3670 .owner = THIS_MODULE,
3635 .write = snd_pcm_write, 3671 .write = snd_pcm_write,
3636 .aio_write = snd_pcm_aio_write, 3672 .write_iter = snd_pcm_writev,
3637 .open = snd_pcm_playback_open, 3673 .open = snd_pcm_playback_open,
3638 .release = snd_pcm_release, 3674 .release = snd_pcm_release,
3639 .llseek = no_llseek, 3675 .llseek = no_llseek,
@@ -3647,7 +3683,7 @@ const struct file_operations snd_pcm_f_ops[2] = {
3647 { 3683 {
3648 .owner = THIS_MODULE, 3684 .owner = THIS_MODULE,
3649 .read = snd_pcm_read, 3685 .read = snd_pcm_read,
3650 .aio_read = snd_pcm_aio_read, 3686 .read_iter = snd_pcm_readv,
3651 .open = snd_pcm_capture_open, 3687 .open = snd_pcm_capture_open,
3652 .release = snd_pcm_release, 3688 .release = snd_pcm_release,
3653 .llseek = no_llseek, 3689 .llseek = no_llseek,
diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c
index b5a748596fc4..a7759846fbaa 100644
--- a/sound/core/rawmidi.c
+++ b/sound/core/rawmidi.c
@@ -1429,10 +1429,8 @@ static int snd_rawmidi_alloc_substreams(struct snd_rawmidi *rmidi,
1429 1429
1430 for (idx = 0; idx < count; idx++) { 1430 for (idx = 0; idx < count; idx++) {
1431 substream = kzalloc(sizeof(*substream), GFP_KERNEL); 1431 substream = kzalloc(sizeof(*substream), GFP_KERNEL);
1432 if (substream == NULL) { 1432 if (!substream)
1433 rmidi_err(rmidi, "rawmidi: cannot allocate substream\n");
1434 return -ENOMEM; 1433 return -ENOMEM;
1435 }
1436 substream->stream = direction; 1434 substream->stream = direction;
1437 substream->number = idx; 1435 substream->number = idx;
1438 substream->rmidi = rmidi; 1436 substream->rmidi = rmidi;
@@ -1479,10 +1477,8 @@ int snd_rawmidi_new(struct snd_card *card, char *id, int device,
1479 if (rrawmidi) 1477 if (rrawmidi)
1480 *rrawmidi = NULL; 1478 *rrawmidi = NULL;
1481 rmidi = kzalloc(sizeof(*rmidi), GFP_KERNEL); 1479 rmidi = kzalloc(sizeof(*rmidi), GFP_KERNEL);
1482 if (rmidi == NULL) { 1480 if (!rmidi)
1483 dev_err(card->dev, "rawmidi: cannot allocate\n");
1484 return -ENOMEM; 1481 return -ENOMEM;
1485 }
1486 rmidi->card = card; 1482 rmidi->card = card;
1487 rmidi->device = device; 1483 rmidi->device = device;
1488 mutex_init(&rmidi->open_mutex); 1484 mutex_init(&rmidi->open_mutex);
diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
index 16d42679e43f..72873a46afeb 100644
--- a/sound/core/seq/oss/seq_oss.c
+++ b/sound/core/seq/oss/seq_oss.c
@@ -65,15 +65,20 @@ static unsigned int odev_poll(struct file *file, poll_table * wait);
65 * module interface 65 * module interface
66 */ 66 */
67 67
68static struct snd_seq_driver seq_oss_synth_driver = {
69 .driver = {
70 .name = KBUILD_MODNAME,
71 .probe = snd_seq_oss_synth_probe,
72 .remove = snd_seq_oss_synth_remove,
73 },
74 .id = SNDRV_SEQ_DEV_ID_OSS,
75 .argsize = sizeof(struct snd_seq_oss_reg),
76};
77
68static int __init alsa_seq_oss_init(void) 78static int __init alsa_seq_oss_init(void)
69{ 79{
70 int rc; 80 int rc;
71 static struct snd_seq_dev_ops ops = {
72 snd_seq_oss_synth_register,
73 snd_seq_oss_synth_unregister,
74 };
75 81
76 snd_seq_autoload_lock();
77 if ((rc = register_device()) < 0) 82 if ((rc = register_device()) < 0)
78 goto error; 83 goto error;
79 if ((rc = register_proc()) < 0) { 84 if ((rc = register_proc()) < 0) {
@@ -86,8 +91,8 @@ static int __init alsa_seq_oss_init(void)
86 goto error; 91 goto error;
87 } 92 }
88 93
89 if ((rc = snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OSS, &ops, 94 rc = snd_seq_driver_register(&seq_oss_synth_driver);
90 sizeof(struct snd_seq_oss_reg))) < 0) { 95 if (rc < 0) {
91 snd_seq_oss_delete_client(); 96 snd_seq_oss_delete_client();
92 unregister_proc(); 97 unregister_proc();
93 unregister_device(); 98 unregister_device();
@@ -98,13 +103,12 @@ static int __init alsa_seq_oss_init(void)
98 snd_seq_oss_synth_init(); 103 snd_seq_oss_synth_init();
99 104
100 error: 105 error:
101 snd_seq_autoload_unlock();
102 return rc; 106 return rc;
103} 107}
104 108
105static void __exit alsa_seq_oss_exit(void) 109static void __exit alsa_seq_oss_exit(void)
106{ 110{
107 snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_OSS); 111 snd_seq_driver_unregister(&seq_oss_synth_driver);
108 snd_seq_oss_delete_client(); 112 snd_seq_oss_delete_client();
109 unregister_proc(); 113 unregister_proc();
110 unregister_device(); 114 unregister_device();
diff --git a/sound/core/seq/oss/seq_oss_init.c b/sound/core/seq/oss/seq_oss_init.c
index b0e32e161dd1..2de3feff70d0 100644
--- a/sound/core/seq/oss/seq_oss_init.c
+++ b/sound/core/seq/oss/seq_oss_init.c
@@ -188,10 +188,8 @@ snd_seq_oss_open(struct file *file, int level)
188 struct seq_oss_devinfo *dp; 188 struct seq_oss_devinfo *dp;
189 189
190 dp = kzalloc(sizeof(*dp), GFP_KERNEL); 190 dp = kzalloc(sizeof(*dp), GFP_KERNEL);
191 if (!dp) { 191 if (!dp)
192 pr_err("ALSA: seq_oss: can't malloc device info\n");
193 return -ENOMEM; 192 return -ENOMEM;
194 }
195 193
196 dp->cseq = system_client; 194 dp->cseq = system_client;
197 dp->port = -1; 195 dp->port = -1;
diff --git a/sound/core/seq/oss/seq_oss_midi.c b/sound/core/seq/oss/seq_oss_midi.c
index e79cc44b1394..96e8395ae586 100644
--- a/sound/core/seq/oss/seq_oss_midi.c
+++ b/sound/core/seq/oss/seq_oss_midi.c
@@ -173,10 +173,9 @@ snd_seq_oss_midi_check_new_port(struct snd_seq_port_info *pinfo)
173 /* 173 /*
174 * allocate midi info record 174 * allocate midi info record
175 */ 175 */
176 if ((mdev = kzalloc(sizeof(*mdev), GFP_KERNEL)) == NULL) { 176 mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
177 pr_err("ALSA: seq_oss: can't malloc midi info\n"); 177 if (!mdev)
178 return -ENOMEM; 178 return -ENOMEM;
179 }
180 179
181 /* copy the port information */ 180 /* copy the port information */
182 mdev->client = pinfo->addr.client; 181 mdev->client = pinfo->addr.client;
diff --git a/sound/core/seq/oss/seq_oss_readq.c b/sound/core/seq/oss/seq_oss_readq.c
index 654d17a5023c..c080c73cea04 100644
--- a/sound/core/seq/oss/seq_oss_readq.c
+++ b/sound/core/seq/oss/seq_oss_readq.c
@@ -47,13 +47,12 @@ snd_seq_oss_readq_new(struct seq_oss_devinfo *dp, int maxlen)
47{ 47{
48 struct seq_oss_readq *q; 48 struct seq_oss_readq *q;
49 49
50 if ((q = kzalloc(sizeof(*q), GFP_KERNEL)) == NULL) { 50 q = kzalloc(sizeof(*q), GFP_KERNEL);
51 pr_err("ALSA: seq_oss: can't malloc read queue\n"); 51 if (!q)
52 return NULL; 52 return NULL;
53 }
54 53
55 if ((q->q = kcalloc(maxlen, sizeof(union evrec), GFP_KERNEL)) == NULL) { 54 q->q = kcalloc(maxlen, sizeof(union evrec), GFP_KERNEL);
56 pr_err("ALSA: seq_oss: can't malloc read queue buffer\n"); 55 if (!q->q) {
57 kfree(q); 56 kfree(q);
58 return NULL; 57 return NULL;
59 } 58 }
diff --git a/sound/core/seq/oss/seq_oss_synth.c b/sound/core/seq/oss/seq_oss_synth.c
index 701feb71b700..48e4fe1b68ab 100644
--- a/sound/core/seq/oss/seq_oss_synth.c
+++ b/sound/core/seq/oss/seq_oss_synth.c
@@ -98,17 +98,17 @@ snd_seq_oss_synth_init(void)
98 * registration of the synth device 98 * registration of the synth device
99 */ 99 */
100int 100int
101snd_seq_oss_synth_register(struct snd_seq_device *dev) 101snd_seq_oss_synth_probe(struct device *_dev)
102{ 102{
103 struct snd_seq_device *dev = to_seq_dev(_dev);
103 int i; 104 int i;
104 struct seq_oss_synth *rec; 105 struct seq_oss_synth *rec;
105 struct snd_seq_oss_reg *reg = SNDRV_SEQ_DEVICE_ARGPTR(dev); 106 struct snd_seq_oss_reg *reg = SNDRV_SEQ_DEVICE_ARGPTR(dev);
106 unsigned long flags; 107 unsigned long flags;
107 108
108 if ((rec = kzalloc(sizeof(*rec), GFP_KERNEL)) == NULL) { 109 rec = kzalloc(sizeof(*rec), GFP_KERNEL);
109 pr_err("ALSA: seq_oss: can't malloc synth info\n"); 110 if (!rec)
110 return -ENOMEM; 111 return -ENOMEM;
111 }
112 rec->seq_device = -1; 112 rec->seq_device = -1;
113 rec->synth_type = reg->type; 113 rec->synth_type = reg->type;
114 rec->synth_subtype = reg->subtype; 114 rec->synth_subtype = reg->subtype;
@@ -149,8 +149,9 @@ snd_seq_oss_synth_register(struct snd_seq_device *dev)
149 149
150 150
151int 151int
152snd_seq_oss_synth_unregister(struct snd_seq_device *dev) 152snd_seq_oss_synth_remove(struct device *_dev)
153{ 153{
154 struct snd_seq_device *dev = to_seq_dev(_dev);
154 int index; 155 int index;
155 struct seq_oss_synth *rec = dev->driver_data; 156 struct seq_oss_synth *rec = dev->driver_data;
156 unsigned long flags; 157 unsigned long flags;
@@ -247,7 +248,6 @@ snd_seq_oss_synth_setup(struct seq_oss_devinfo *dp)
247 if (info->nr_voices > 0) { 248 if (info->nr_voices > 0) {
248 info->ch = kcalloc(info->nr_voices, sizeof(struct seq_oss_chinfo), GFP_KERNEL); 249 info->ch = kcalloc(info->nr_voices, sizeof(struct seq_oss_chinfo), GFP_KERNEL);
249 if (!info->ch) { 250 if (!info->ch) {
250 pr_err("ALSA: seq_oss: Cannot malloc voices\n");
251 rec->oper.close(&info->arg); 251 rec->oper.close(&info->arg);
252 module_put(rec->oper.owner); 252 module_put(rec->oper.owner);
253 snd_use_lock_free(&rec->use_lock); 253 snd_use_lock_free(&rec->use_lock);
diff --git a/sound/core/seq/oss/seq_oss_synth.h b/sound/core/seq/oss/seq_oss_synth.h
index dbdfcbb80eaa..74ac55f166b6 100644
--- a/sound/core/seq/oss/seq_oss_synth.h
+++ b/sound/core/seq/oss/seq_oss_synth.h
@@ -28,8 +28,8 @@
28#include <sound/seq_device.h> 28#include <sound/seq_device.h>
29 29
30void snd_seq_oss_synth_init(void); 30void snd_seq_oss_synth_init(void);
31int snd_seq_oss_synth_register(struct snd_seq_device *dev); 31int snd_seq_oss_synth_probe(struct device *dev);
32int snd_seq_oss_synth_unregister(struct snd_seq_device *dev); 32int snd_seq_oss_synth_remove(struct device *dev);
33void snd_seq_oss_synth_setup(struct seq_oss_devinfo *dp); 33void snd_seq_oss_synth_setup(struct seq_oss_devinfo *dp);
34void snd_seq_oss_synth_setup_midi(struct seq_oss_devinfo *dp); 34void snd_seq_oss_synth_setup_midi(struct seq_oss_devinfo *dp);
35void snd_seq_oss_synth_cleanup(struct seq_oss_devinfo *dp); 35void snd_seq_oss_synth_cleanup(struct seq_oss_devinfo *dp);
diff --git a/sound/core/seq/seq_clientmgr.c b/sound/core/seq/seq_clientmgr.c
index 48287651ac77..edbdab85fc02 100644
--- a/sound/core/seq/seq_clientmgr.c
+++ b/sound/core/seq/seq_clientmgr.c
@@ -1879,6 +1879,7 @@ static int snd_seq_ioctl_get_client_pool(struct snd_seq_client *client,
1879 if (cptr == NULL) 1879 if (cptr == NULL)
1880 return -ENOENT; 1880 return -ENOENT;
1881 memset(&info, 0, sizeof(info)); 1881 memset(&info, 0, sizeof(info));
1882 info.client = cptr->number;
1882 info.output_pool = cptr->pool->size; 1883 info.output_pool = cptr->pool->size;
1883 info.output_room = cptr->pool->room; 1884 info.output_room = cptr->pool->room;
1884 info.output_free = info.output_pool; 1885 info.output_free = info.output_pool;
diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
index 0631bdadd12b..d99f99d61983 100644
--- a/sound/core/seq/seq_device.c
+++ b/sound/core/seq/seq_device.c
@@ -36,6 +36,7 @@
36 * 36 *
37 */ 37 */
38 38
39#include <linux/device.h>
39#include <linux/init.h> 40#include <linux/init.h>
40#include <linux/module.h> 41#include <linux/module.h>
41#include <sound/core.h> 42#include <sound/core.h>
@@ -51,140 +52,78 @@ MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
51MODULE_DESCRIPTION("ALSA sequencer device management"); 52MODULE_DESCRIPTION("ALSA sequencer device management");
52MODULE_LICENSE("GPL"); 53MODULE_LICENSE("GPL");
53 54
54/* driver state */ 55/*
55#define DRIVER_EMPTY 0 56 * bus definition
56#define DRIVER_LOADED (1<<0) 57 */
57#define DRIVER_REQUESTED (1<<1) 58static int snd_seq_bus_match(struct device *dev, struct device_driver *drv)
58#define DRIVER_LOCKED (1<<2) 59{
59#define DRIVER_REQUESTING (1<<3) 60 struct snd_seq_device *sdev = to_seq_dev(dev);
60 61 struct snd_seq_driver *sdrv = to_seq_drv(drv);
61struct ops_list {
62 char id[ID_LEN]; /* driver id */
63 int driver; /* driver state */
64 int used; /* reference counter */
65 int argsize; /* argument size */
66
67 /* operators */
68 struct snd_seq_dev_ops ops;
69
70 /* registered devices */
71 struct list_head dev_list; /* list of devices */
72 int num_devices; /* number of associated devices */
73 int num_init_devices; /* number of initialized devices */
74 struct mutex reg_mutex;
75
76 struct list_head list; /* next driver */
77};
78 62
63 return strcmp(sdrv->id, sdev->id) == 0 &&
64 sdrv->argsize == sdev->argsize;
65}
79 66
80static LIST_HEAD(opslist); 67static struct bus_type snd_seq_bus_type = {
81static int num_ops; 68 .name = "snd_seq",
82static DEFINE_MUTEX(ops_mutex); 69 .match = snd_seq_bus_match,
83#ifdef CONFIG_PROC_FS 70};
84static struct snd_info_entry *info_entry;
85#endif
86 71
87/* 72/*
88 * prototypes 73 * proc interface -- just for compatibility
89 */ 74 */
90static int snd_seq_device_free(struct snd_seq_device *dev); 75#ifdef CONFIG_PROC_FS
91static int snd_seq_device_dev_free(struct snd_device *device); 76static struct snd_info_entry *info_entry;
92static int snd_seq_device_dev_register(struct snd_device *device);
93static int snd_seq_device_dev_disconnect(struct snd_device *device);
94
95static int init_device(struct snd_seq_device *dev, struct ops_list *ops);
96static int free_device(struct snd_seq_device *dev, struct ops_list *ops);
97static struct ops_list *find_driver(char *id, int create_if_empty);
98static struct ops_list *create_driver(char *id);
99static void unlock_driver(struct ops_list *ops);
100static void remove_drivers(void);
101 77
102/* 78static int print_dev_info(struct device *dev, void *data)
103 * show all drivers and their status 79{
104 */ 80 struct snd_seq_device *sdev = to_seq_dev(dev);
81 struct snd_info_buffer *buffer = data;
82
83 snd_iprintf(buffer, "snd-%s,%s,%d\n", sdev->id,
84 dev->driver ? "loaded" : "empty",
85 dev->driver ? 1 : 0);
86 return 0;
87}
105 88
106#ifdef CONFIG_PROC_FS
107static void snd_seq_device_info(struct snd_info_entry *entry, 89static void snd_seq_device_info(struct snd_info_entry *entry,
108 struct snd_info_buffer *buffer) 90 struct snd_info_buffer *buffer)
109{ 91{
110 struct ops_list *ops; 92 bus_for_each_dev(&snd_seq_bus_type, NULL, buffer, print_dev_info);
111
112 mutex_lock(&ops_mutex);
113 list_for_each_entry(ops, &opslist, list) {
114 snd_iprintf(buffer, "snd-%s%s%s%s,%d\n",
115 ops->id,
116 ops->driver & DRIVER_LOADED ? ",loaded" : (ops->driver == DRIVER_EMPTY ? ",empty" : ""),
117 ops->driver & DRIVER_REQUESTED ? ",requested" : "",
118 ops->driver & DRIVER_LOCKED ? ",locked" : "",
119 ops->num_devices);
120 }
121 mutex_unlock(&ops_mutex);
122} 93}
123#endif 94#endif
124 95
125/* 96/*
126 * load all registered drivers (called from seq_clientmgr.c) 97 * load all registered drivers (called from seq_clientmgr.c)
127 */ 98 */
128 99
129#ifdef CONFIG_MODULES 100#ifdef CONFIG_MODULES
130/* avoid auto-loading during module_init() */ 101/* flag to block auto-loading */
131static atomic_t snd_seq_in_init = ATOMIC_INIT(1); /* blocked as default */ 102static atomic_t snd_seq_in_init = ATOMIC_INIT(1); /* blocked as default */
132void snd_seq_autoload_lock(void)
133{
134 atomic_inc(&snd_seq_in_init);
135}
136 103
137void snd_seq_autoload_unlock(void) 104static int request_seq_drv(struct device *dev, void *data)
138{ 105{
139 atomic_dec(&snd_seq_in_init); 106 struct snd_seq_device *sdev = to_seq_dev(dev);
107
108 if (!dev->driver)
109 request_module("snd-%s", sdev->id);
110 return 0;
140} 111}
141 112
142static void autoload_drivers(void) 113static void autoload_drivers(struct work_struct *work)
143{ 114{
144 /* avoid reentrance */ 115 /* avoid reentrance */
145 if (atomic_inc_return(&snd_seq_in_init) == 1) { 116 if (atomic_inc_return(&snd_seq_in_init) == 1)
146 struct ops_list *ops; 117 bus_for_each_dev(&snd_seq_bus_type, NULL, NULL,
147 118 request_seq_drv);
148 mutex_lock(&ops_mutex);
149 list_for_each_entry(ops, &opslist, list) {
150 if ((ops->driver & DRIVER_REQUESTING) &&
151 !(ops->driver & DRIVER_REQUESTED)) {
152 ops->used++;
153 mutex_unlock(&ops_mutex);
154 ops->driver |= DRIVER_REQUESTED;
155 request_module("snd-%s", ops->id);
156 mutex_lock(&ops_mutex);
157 ops->used--;
158 }
159 }
160 mutex_unlock(&ops_mutex);
161 }
162 atomic_dec(&snd_seq_in_init); 119 atomic_dec(&snd_seq_in_init);
163} 120}
164 121
165static void call_autoload(struct work_struct *work) 122static DECLARE_WORK(autoload_work, autoload_drivers);
166{
167 autoload_drivers();
168}
169
170static DECLARE_WORK(autoload_work, call_autoload);
171
172static void try_autoload(struct ops_list *ops)
173{
174 if (!ops->driver) {
175 ops->driver |= DRIVER_REQUESTING;
176 schedule_work(&autoload_work);
177 }
178}
179 123
180static void queue_autoload_drivers(void) 124static void queue_autoload_drivers(void)
181{ 125{
182 struct ops_list *ops; 126 schedule_work(&autoload_work);
183
184 mutex_lock(&ops_mutex);
185 list_for_each_entry(ops, &opslist, list)
186 try_autoload(ops);
187 mutex_unlock(&ops_mutex);
188} 127}
189 128
190void snd_seq_autoload_init(void) 129void snd_seq_autoload_init(void)
@@ -195,384 +134,143 @@ void snd_seq_autoload_init(void)
195 queue_autoload_drivers(); 134 queue_autoload_drivers();
196#endif 135#endif
197} 136}
198#else 137EXPORT_SYMBOL(snd_seq_autoload_init);
199#define try_autoload(ops) /* NOP */
200#endif
201 138
202void snd_seq_device_load_drivers(void) 139void snd_seq_autoload_exit(void)
203{ 140{
204#ifdef CONFIG_MODULES 141 atomic_inc(&snd_seq_in_init);
205 queue_autoload_drivers();
206 flush_work(&autoload_work);
207#endif
208} 142}
143EXPORT_SYMBOL(snd_seq_autoload_exit);
209 144
210/* 145void snd_seq_device_load_drivers(void)
211 * register a sequencer device
212 * card = card info
213 * device = device number (if any)
214 * id = id of driver
215 * result = return pointer (NULL allowed if unnecessary)
216 */
217int snd_seq_device_new(struct snd_card *card, int device, char *id, int argsize,
218 struct snd_seq_device **result)
219{ 146{
220 struct snd_seq_device *dev; 147 queue_autoload_drivers();
221 struct ops_list *ops; 148 flush_work(&autoload_work);
222 int err;
223 static struct snd_device_ops dops = {
224 .dev_free = snd_seq_device_dev_free,
225 .dev_register = snd_seq_device_dev_register,
226 .dev_disconnect = snd_seq_device_dev_disconnect,
227 };
228
229 if (result)
230 *result = NULL;
231
232 if (snd_BUG_ON(!id))
233 return -EINVAL;
234
235 ops = find_driver(id, 1);
236 if (ops == NULL)
237 return -ENOMEM;
238
239 dev = kzalloc(sizeof(*dev)*2 + argsize, GFP_KERNEL);
240 if (dev == NULL) {
241 unlock_driver(ops);
242 return -ENOMEM;
243 }
244
245 /* set up device info */
246 dev->card = card;
247 dev->device = device;
248 strlcpy(dev->id, id, sizeof(dev->id));
249 dev->argsize = argsize;
250 dev->status = SNDRV_SEQ_DEVICE_FREE;
251
252 /* add this device to the list */
253 mutex_lock(&ops->reg_mutex);
254 list_add_tail(&dev->list, &ops->dev_list);
255 ops->num_devices++;
256 mutex_unlock(&ops->reg_mutex);
257
258 if ((err = snd_device_new(card, SNDRV_DEV_SEQUENCER, dev, &dops)) < 0) {
259 snd_seq_device_free(dev);
260 return err;
261 }
262
263 try_autoload(ops);
264 unlock_driver(ops);
265
266 if (result)
267 *result = dev;
268
269 return 0;
270} 149}
150EXPORT_SYMBOL(snd_seq_device_load_drivers);
151#else
152#define queue_autoload_drivers() /* NOP */
153#endif
271 154
272/* 155/*
273 * free the existing device 156 * device management
274 */ 157 */
275static int snd_seq_device_free(struct snd_seq_device *dev)
276{
277 struct ops_list *ops;
278
279 if (snd_BUG_ON(!dev))
280 return -EINVAL;
281
282 ops = find_driver(dev->id, 0);
283 if (ops == NULL)
284 return -ENXIO;
285
286 /* remove the device from the list */
287 mutex_lock(&ops->reg_mutex);
288 list_del(&dev->list);
289 ops->num_devices--;
290 mutex_unlock(&ops->reg_mutex);
291
292 free_device(dev, ops);
293 if (dev->private_free)
294 dev->private_free(dev);
295 kfree(dev);
296
297 unlock_driver(ops);
298
299 return 0;
300}
301
302static int snd_seq_device_dev_free(struct snd_device *device) 158static int snd_seq_device_dev_free(struct snd_device *device)
303{ 159{
304 struct snd_seq_device *dev = device->device_data; 160 struct snd_seq_device *dev = device->device_data;
305 return snd_seq_device_free(dev); 161
162 put_device(&dev->dev);
163 return 0;
306} 164}
307 165
308/*
309 * register the device
310 */
311static int snd_seq_device_dev_register(struct snd_device *device) 166static int snd_seq_device_dev_register(struct snd_device *device)
312{ 167{
313 struct snd_seq_device *dev = device->device_data; 168 struct snd_seq_device *dev = device->device_data;
314 struct ops_list *ops; 169 int err;
315
316 ops = find_driver(dev->id, 0);
317 if (ops == NULL)
318 return -ENOENT;
319
320 /* initialize this device if the corresponding driver was
321 * already loaded
322 */
323 if (ops->driver & DRIVER_LOADED)
324 init_device(dev, ops);
325 170
326 unlock_driver(ops); 171 err = device_add(&dev->dev);
172 if (err < 0)
173 return err;
174 if (!dev->dev.driver)
175 queue_autoload_drivers();
327 return 0; 176 return 0;
328} 177}
329 178
330/*
331 * disconnect the device
332 */
333static int snd_seq_device_dev_disconnect(struct snd_device *device) 179static int snd_seq_device_dev_disconnect(struct snd_device *device)
334{ 180{
335 struct snd_seq_device *dev = device->device_data; 181 struct snd_seq_device *dev = device->device_data;
336 struct ops_list *ops;
337
338 ops = find_driver(dev->id, 0);
339 if (ops == NULL)
340 return -ENOENT;
341
342 free_device(dev, ops);
343 182
344 unlock_driver(ops); 183 device_del(&dev->dev);
345 return 0; 184 return 0;
346} 185}
347 186
348/* 187static void snd_seq_dev_release(struct device *dev)
349 * register device driver
350 * id = driver id
351 * entry = driver operators - duplicated to each instance
352 */
353int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
354 int argsize)
355{ 188{
356 struct ops_list *ops; 189 struct snd_seq_device *sdev = to_seq_dev(dev);
357 struct snd_seq_device *dev;
358 190
359 if (id == NULL || entry == NULL || 191 if (sdev->private_free)
360 entry->init_device == NULL || entry->free_device == NULL) 192 sdev->private_free(sdev);
361 return -EINVAL; 193 kfree(sdev);
362
363 ops = find_driver(id, 1);
364 if (ops == NULL)
365 return -ENOMEM;
366 if (ops->driver & DRIVER_LOADED) {
367 pr_warn("ALSA: seq: driver_register: driver '%s' already exists\n", id);
368 unlock_driver(ops);
369 return -EBUSY;
370 }
371
372 mutex_lock(&ops->reg_mutex);
373 /* copy driver operators */
374 ops->ops = *entry;
375 ops->driver |= DRIVER_LOADED;
376 ops->argsize = argsize;
377
378 /* initialize existing devices if necessary */
379 list_for_each_entry(dev, &ops->dev_list, list) {
380 init_device(dev, ops);
381 }
382 mutex_unlock(&ops->reg_mutex);
383
384 unlock_driver(ops);
385
386 return 0;
387} 194}
388 195
389
390/*
391 * create driver record
392 */
393static struct ops_list * create_driver(char *id)
394{
395 struct ops_list *ops;
396
397 ops = kzalloc(sizeof(*ops), GFP_KERNEL);
398 if (ops == NULL)
399 return ops;
400
401 /* set up driver entry */
402 strlcpy(ops->id, id, sizeof(ops->id));
403 mutex_init(&ops->reg_mutex);
404 /*
405 * The ->reg_mutex locking rules are per-driver, so we create
406 * separate per-driver lock classes:
407 */
408 lockdep_set_class(&ops->reg_mutex, (struct lock_class_key *)id);
409
410 ops->driver = DRIVER_EMPTY;
411 INIT_LIST_HEAD(&ops->dev_list);
412 /* lock this instance */
413 ops->used = 1;
414
415 /* register driver entry */
416 mutex_lock(&ops_mutex);
417 list_add_tail(&ops->list, &opslist);
418 num_ops++;
419 mutex_unlock(&ops_mutex);
420
421 return ops;
422}
423
424
425/* 196/*
426 * unregister the specified driver 197 * register a sequencer device
198 * card = card info
199 * device = device number (if any)
200 * id = id of driver
201 * result = return pointer (NULL allowed if unnecessary)
427 */ 202 */
428int snd_seq_device_unregister_driver(char *id) 203int snd_seq_device_new(struct snd_card *card, int device, const char *id,
204 int argsize, struct snd_seq_device **result)
429{ 205{
430 struct ops_list *ops;
431 struct snd_seq_device *dev; 206 struct snd_seq_device *dev;
207 int err;
208 static struct snd_device_ops dops = {
209 .dev_free = snd_seq_device_dev_free,
210 .dev_register = snd_seq_device_dev_register,
211 .dev_disconnect = snd_seq_device_dev_disconnect,
212 };
432 213
433 ops = find_driver(id, 0); 214 if (result)
434 if (ops == NULL) 215 *result = NULL;
435 return -ENXIO;
436 if (! (ops->driver & DRIVER_LOADED) ||
437 (ops->driver & DRIVER_LOCKED)) {
438 pr_err("ALSA: seq: driver_unregister: cannot unload driver '%s': status=%x\n",
439 id, ops->driver);
440 unlock_driver(ops);
441 return -EBUSY;
442 }
443
444 /* close and release all devices associated with this driver */
445 mutex_lock(&ops->reg_mutex);
446 ops->driver |= DRIVER_LOCKED; /* do not remove this driver recursively */
447 list_for_each_entry(dev, &ops->dev_list, list) {
448 free_device(dev, ops);
449 }
450
451 ops->driver = 0;
452 if (ops->num_init_devices > 0)
453 pr_err("ALSA: seq: free_driver: init_devices > 0!! (%d)\n",
454 ops->num_init_devices);
455 mutex_unlock(&ops->reg_mutex);
456
457 unlock_driver(ops);
458 216
459 /* remove empty driver entries */ 217 if (snd_BUG_ON(!id))
460 remove_drivers(); 218 return -EINVAL;
461 219
462 return 0; 220 dev = kzalloc(sizeof(*dev) + argsize, GFP_KERNEL);
463} 221 if (!dev)
222 return -ENOMEM;
464 223
224 /* set up device info */
225 dev->card = card;
226 dev->device = device;
227 dev->id = id;
228 dev->argsize = argsize;
465 229
466/* 230 device_initialize(&dev->dev);
467 * remove empty driver entries 231 dev->dev.parent = &card->card_dev;
468 */ 232 dev->dev.bus = &snd_seq_bus_type;
469static void remove_drivers(void) 233 dev->dev.release = snd_seq_dev_release;
470{ 234 dev_set_name(&dev->dev, "%s-%d-%d", dev->id, card->number, device);
471 struct list_head *head;
472
473 mutex_lock(&ops_mutex);
474 head = opslist.next;
475 while (head != &opslist) {
476 struct ops_list *ops = list_entry(head, struct ops_list, list);
477 if (! (ops->driver & DRIVER_LOADED) &&
478 ops->used == 0 && ops->num_devices == 0) {
479 head = head->next;
480 list_del(&ops->list);
481 kfree(ops);
482 num_ops--;
483 } else
484 head = head->next;
485 }
486 mutex_unlock(&ops_mutex);
487}
488 235
489/* 236 /* add this device to the list */
490 * initialize the device - call init_device operator 237 err = snd_device_new(card, SNDRV_DEV_SEQUENCER, dev, &dops);
491 */ 238 if (err < 0) {
492static int init_device(struct snd_seq_device *dev, struct ops_list *ops) 239 put_device(&dev->dev);
493{ 240 return err;
494 if (! (ops->driver & DRIVER_LOADED))
495 return 0; /* driver is not loaded yet */
496 if (dev->status != SNDRV_SEQ_DEVICE_FREE)
497 return 0; /* already initialized */
498 if (ops->argsize != dev->argsize) {
499 pr_err("ALSA: seq: incompatible device '%s' for plug-in '%s' (%d %d)\n",
500 dev->name, ops->id, ops->argsize, dev->argsize);
501 return -EINVAL;
502 }
503 if (ops->ops.init_device(dev) >= 0) {
504 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
505 ops->num_init_devices++;
506 } else {
507 pr_err("ALSA: seq: init_device failed: %s: %s\n",
508 dev->name, dev->id);
509 } 241 }
242
243 if (result)
244 *result = dev;
510 245
511 return 0; 246 return 0;
512} 247}
248EXPORT_SYMBOL(snd_seq_device_new);
513 249
514/* 250/*
515 * release the device - call free_device operator 251 * driver registration
516 */ 252 */
517static int free_device(struct snd_seq_device *dev, struct ops_list *ops) 253int __snd_seq_driver_register(struct snd_seq_driver *drv, struct module *mod)
518{ 254{
519 int result; 255 if (WARN_ON(!drv->driver.name || !drv->id))
520
521 if (! (ops->driver & DRIVER_LOADED))
522 return 0; /* driver is not loaded yet */
523 if (dev->status != SNDRV_SEQ_DEVICE_REGISTERED)
524 return 0; /* not registered */
525 if (ops->argsize != dev->argsize) {
526 pr_err("ALSA: seq: incompatible device '%s' for plug-in '%s' (%d %d)\n",
527 dev->name, ops->id, ops->argsize, dev->argsize);
528 return -EINVAL; 256 return -EINVAL;
529 } 257 drv->driver.bus = &snd_seq_bus_type;
530 if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) { 258 drv->driver.owner = mod;
531 dev->status = SNDRV_SEQ_DEVICE_FREE; 259 return driver_register(&drv->driver);
532 dev->driver_data = NULL;
533 ops->num_init_devices--;
534 } else {
535 pr_err("ALSA: seq: free_device failed: %s: %s\n",
536 dev->name, dev->id);
537 }
538
539 return 0;
540} 260}
261EXPORT_SYMBOL_GPL(__snd_seq_driver_register);
541 262
542/* 263void snd_seq_driver_unregister(struct snd_seq_driver *drv)
543 * find the matching driver with given id
544 */
545static struct ops_list * find_driver(char *id, int create_if_empty)
546{ 264{
547 struct ops_list *ops; 265 driver_unregister(&drv->driver);
548
549 mutex_lock(&ops_mutex);
550 list_for_each_entry(ops, &opslist, list) {
551 if (strcmp(ops->id, id) == 0) {
552 ops->used++;
553 mutex_unlock(&ops_mutex);
554 return ops;
555 }
556 }
557 mutex_unlock(&ops_mutex);
558 if (create_if_empty)
559 return create_driver(id);
560 return NULL;
561} 266}
562 267EXPORT_SYMBOL_GPL(snd_seq_driver_unregister);
563static void unlock_driver(struct ops_list *ops)
564{
565 mutex_lock(&ops_mutex);
566 ops->used--;
567 mutex_unlock(&ops_mutex);
568}
569
570 268
571/* 269/*
572 * module part 270 * module part
573 */ 271 */
574 272
575static int __init alsa_seq_device_init(void) 273static int __init seq_dev_proc_init(void)
576{ 274{
577#ifdef CONFIG_PROC_FS 275#ifdef CONFIG_PROC_FS
578 info_entry = snd_info_create_module_entry(THIS_MODULE, "drivers", 276 info_entry = snd_info_create_module_entry(THIS_MODULE, "drivers",
@@ -589,28 +287,29 @@ static int __init alsa_seq_device_init(void)
589 return 0; 287 return 0;
590} 288}
591 289
290static int __init alsa_seq_device_init(void)
291{
292 int err;
293
294 err = bus_register(&snd_seq_bus_type);
295 if (err < 0)
296 return err;
297 err = seq_dev_proc_init();
298 if (err < 0)
299 bus_unregister(&snd_seq_bus_type);
300 return err;
301}
302
592static void __exit alsa_seq_device_exit(void) 303static void __exit alsa_seq_device_exit(void)
593{ 304{
594#ifdef CONFIG_MODULES 305#ifdef CONFIG_MODULES
595 cancel_work_sync(&autoload_work); 306 cancel_work_sync(&autoload_work);
596#endif 307#endif
597 remove_drivers();
598#ifdef CONFIG_PROC_FS 308#ifdef CONFIG_PROC_FS
599 snd_info_free_entry(info_entry); 309 snd_info_free_entry(info_entry);
600#endif 310#endif
601 if (num_ops) 311 bus_unregister(&snd_seq_bus_type);
602 pr_err("ALSA: seq: drivers not released (%d)\n", num_ops);
603} 312}
604 313
605module_init(alsa_seq_device_init) 314subsys_initcall(alsa_seq_device_init)
606module_exit(alsa_seq_device_exit) 315module_exit(alsa_seq_device_exit)
607
608EXPORT_SYMBOL(snd_seq_device_load_drivers);
609EXPORT_SYMBOL(snd_seq_device_new);
610EXPORT_SYMBOL(snd_seq_device_register_driver);
611EXPORT_SYMBOL(snd_seq_device_unregister_driver);
612#ifdef CONFIG_MODULES
613EXPORT_SYMBOL(snd_seq_autoload_init);
614EXPORT_SYMBOL(snd_seq_autoload_lock);
615EXPORT_SYMBOL(snd_seq_autoload_unlock);
616#endif
diff --git a/sound/core/seq/seq_dummy.c b/sound/core/seq/seq_dummy.c
index 5d905d90d504..d3a2ec4f0561 100644
--- a/sound/core/seq/seq_dummy.c
+++ b/sound/core/seq/seq_dummy.c
@@ -214,11 +214,7 @@ delete_client(void)
214 214
215static int __init alsa_seq_dummy_init(void) 215static int __init alsa_seq_dummy_init(void)
216{ 216{
217 int err; 217 return register_client();
218 snd_seq_autoload_lock();
219 err = register_client();
220 snd_seq_autoload_unlock();
221 return err;
222} 218}
223 219
224static void __exit alsa_seq_dummy_exit(void) 220static void __exit alsa_seq_dummy_exit(void)
diff --git a/sound/core/seq/seq_fifo.c b/sound/core/seq/seq_fifo.c
index 53a403e17c5b..1d5acbe0c08b 100644
--- a/sound/core/seq/seq_fifo.c
+++ b/sound/core/seq/seq_fifo.c
@@ -33,10 +33,8 @@ struct snd_seq_fifo *snd_seq_fifo_new(int poolsize)
33 struct snd_seq_fifo *f; 33 struct snd_seq_fifo *f;
34 34
35 f = kzalloc(sizeof(*f), GFP_KERNEL); 35 f = kzalloc(sizeof(*f), GFP_KERNEL);
36 if (f == NULL) { 36 if (!f)
37 pr_debug("ALSA: seq: malloc failed for snd_seq_fifo_new() \n");
38 return NULL; 37 return NULL;
39 }
40 38
41 f->pool = snd_seq_pool_new(poolsize); 39 f->pool = snd_seq_pool_new(poolsize);
42 if (f->pool == NULL) { 40 if (f->pool == NULL) {
diff --git a/sound/core/seq/seq_memory.c b/sound/core/seq/seq_memory.c
index ba8e4a64e13e..801076687bb1 100644
--- a/sound/core/seq/seq_memory.c
+++ b/sound/core/seq/seq_memory.c
@@ -387,10 +387,8 @@ int snd_seq_pool_init(struct snd_seq_pool *pool)
387 return 0; 387 return 0;
388 388
389 pool->ptr = vmalloc(sizeof(struct snd_seq_event_cell) * pool->size); 389 pool->ptr = vmalloc(sizeof(struct snd_seq_event_cell) * pool->size);
390 if (pool->ptr == NULL) { 390 if (!pool->ptr)
391 pr_debug("ALSA: seq: malloc for sequencer events failed\n");
392 return -ENOMEM; 391 return -ENOMEM;
393 }
394 392
395 /* add new cells to the free cell list */ 393 /* add new cells to the free cell list */
396 spin_lock_irqsave(&pool->lock, flags); 394 spin_lock_irqsave(&pool->lock, flags);
@@ -463,10 +461,8 @@ struct snd_seq_pool *snd_seq_pool_new(int poolsize)
463 461
464 /* create pool block */ 462 /* create pool block */
465 pool = kzalloc(sizeof(*pool), GFP_KERNEL); 463 pool = kzalloc(sizeof(*pool), GFP_KERNEL);
466 if (pool == NULL) { 464 if (!pool)
467 pr_debug("ALSA: seq: malloc failed for pool\n");
468 return NULL; 465 return NULL;
469 }
470 spin_lock_init(&pool->lock); 466 spin_lock_init(&pool->lock);
471 pool->ptr = NULL; 467 pool->ptr = NULL;
472 pool->free = NULL; 468 pool->free = NULL;
diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
index 68fec776da26..5dd0ee258359 100644
--- a/sound/core/seq/seq_midi.c
+++ b/sound/core/seq/seq_midi.c
@@ -273,8 +273,9 @@ static void snd_seq_midisynth_delete(struct seq_midisynth *msynth)
273 273
274/* register new midi synth port */ 274/* register new midi synth port */
275static int 275static int
276snd_seq_midisynth_register_port(struct snd_seq_device *dev) 276snd_seq_midisynth_probe(struct device *_dev)
277{ 277{
278 struct snd_seq_device *dev = to_seq_dev(_dev);
278 struct seq_midisynth_client *client; 279 struct seq_midisynth_client *client;
279 struct seq_midisynth *msynth, *ms; 280 struct seq_midisynth *msynth, *ms;
280 struct snd_seq_port_info *port; 281 struct snd_seq_port_info *port;
@@ -427,8 +428,9 @@ snd_seq_midisynth_register_port(struct snd_seq_device *dev)
427 428
428/* release midi synth port */ 429/* release midi synth port */
429static int 430static int
430snd_seq_midisynth_unregister_port(struct snd_seq_device *dev) 431snd_seq_midisynth_remove(struct device *_dev)
431{ 432{
433 struct snd_seq_device *dev = to_seq_dev(_dev);
432 struct seq_midisynth_client *client; 434 struct seq_midisynth_client *client;
433 struct seq_midisynth *msynth; 435 struct seq_midisynth *msynth;
434 struct snd_card *card = dev->card; 436 struct snd_card *card = dev->card;
@@ -457,24 +459,14 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
457 return 0; 459 return 0;
458} 460}
459 461
462static struct snd_seq_driver seq_midisynth_driver = {
463 .driver = {
464 .name = KBUILD_MODNAME,
465 .probe = snd_seq_midisynth_probe,
466 .remove = snd_seq_midisynth_remove,
467 },
468 .id = SNDRV_SEQ_DEV_ID_MIDISYNTH,
469 .argsize = 0,
470};
460 471
461static int __init alsa_seq_midi_init(void) 472module_snd_seq_driver(seq_midisynth_driver);
462{
463 static struct snd_seq_dev_ops ops = {
464 snd_seq_midisynth_register_port,
465 snd_seq_midisynth_unregister_port,
466 };
467 memset(&synths, 0, sizeof(synths));
468 snd_seq_autoload_lock();
469 snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_MIDISYNTH, &ops, 0);
470 snd_seq_autoload_unlock();
471 return 0;
472}
473
474static void __exit alsa_seq_midi_exit(void)
475{
476 snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_MIDISYNTH);
477}
478
479module_init(alsa_seq_midi_init)
480module_exit(alsa_seq_midi_exit)
diff --git a/sound/core/seq/seq_ports.c b/sound/core/seq/seq_ports.c
index 46ff593f618d..55170a20ae72 100644
--- a/sound/core/seq/seq_ports.c
+++ b/sound/core/seq/seq_ports.c
@@ -141,10 +141,8 @@ struct snd_seq_client_port *snd_seq_create_port(struct snd_seq_client *client,
141 141
142 /* create a new port */ 142 /* create a new port */
143 new_port = kzalloc(sizeof(*new_port), GFP_KERNEL); 143 new_port = kzalloc(sizeof(*new_port), GFP_KERNEL);
144 if (! new_port) { 144 if (!new_port)
145 pr_debug("ALSA: seq: malloc failed for registering client port\n");
146 return NULL; /* failure, out of memory */ 145 return NULL; /* failure, out of memory */
147 }
148 /* init port data */ 146 /* init port data */
149 new_port->addr.client = client->number; 147 new_port->addr.client = client->number;
150 new_port->addr.port = -1; 148 new_port->addr.port = -1;
diff --git a/sound/core/seq/seq_prioq.c b/sound/core/seq/seq_prioq.c
index 021b02bc9330..bc1c8488fc2a 100644
--- a/sound/core/seq/seq_prioq.c
+++ b/sound/core/seq/seq_prioq.c
@@ -59,10 +59,8 @@ struct snd_seq_prioq *snd_seq_prioq_new(void)
59 struct snd_seq_prioq *f; 59 struct snd_seq_prioq *f;
60 60
61 f = kzalloc(sizeof(*f), GFP_KERNEL); 61 f = kzalloc(sizeof(*f), GFP_KERNEL);
62 if (f == NULL) { 62 if (!f)
63 pr_debug("ALSA: seq: malloc failed for snd_seq_prioq_new()\n");
64 return NULL; 63 return NULL;
65 }
66 64
67 spin_lock_init(&f->lock); 65 spin_lock_init(&f->lock);
68 f->head = NULL; 66 f->head = NULL;
diff --git a/sound/core/seq/seq_queue.c b/sound/core/seq/seq_queue.c
index aad4878cee55..a0cda38205b9 100644
--- a/sound/core/seq/seq_queue.c
+++ b/sound/core/seq/seq_queue.c
@@ -111,10 +111,8 @@ static struct snd_seq_queue *queue_new(int owner, int locked)
111 struct snd_seq_queue *q; 111 struct snd_seq_queue *q;
112 112
113 q = kzalloc(sizeof(*q), GFP_KERNEL); 113 q = kzalloc(sizeof(*q), GFP_KERNEL);
114 if (q == NULL) { 114 if (!q)
115 pr_debug("ALSA: seq: malloc failed for snd_seq_queue_new()\n");
116 return NULL; 115 return NULL;
117 }
118 116
119 spin_lock_init(&q->owner_lock); 117 spin_lock_init(&q->owner_lock);
120 spin_lock_init(&q->check_lock); 118 spin_lock_init(&q->check_lock);
diff --git a/sound/core/seq/seq_timer.c b/sound/core/seq/seq_timer.c
index e73605393eee..186f1611103c 100644
--- a/sound/core/seq/seq_timer.c
+++ b/sound/core/seq/seq_timer.c
@@ -56,10 +56,8 @@ struct snd_seq_timer *snd_seq_timer_new(void)
56 struct snd_seq_timer *tmr; 56 struct snd_seq_timer *tmr;
57 57
58 tmr = kzalloc(sizeof(*tmr), GFP_KERNEL); 58 tmr = kzalloc(sizeof(*tmr), GFP_KERNEL);
59 if (tmr == NULL) { 59 if (!tmr)
60 pr_debug("ALSA: seq: malloc failed for snd_seq_timer_new() \n");
61 return NULL; 60 return NULL;
62 }
63 spin_lock_init(&tmr->lock); 61 spin_lock_init(&tmr->lock);
64 62
65 /* reset setup to defaults */ 63 /* reset setup to defaults */
diff --git a/sound/core/sound.c b/sound/core/sound.c
index 185cec01ee25..5fc93d00572a 100644
--- a/sound/core/sound.c
+++ b/sound/core/sound.c
@@ -186,7 +186,7 @@ static const struct file_operations snd_fops =
186}; 186};
187 187
188#ifdef CONFIG_SND_DYNAMIC_MINORS 188#ifdef CONFIG_SND_DYNAMIC_MINORS
189static int snd_find_free_minor(int type) 189static int snd_find_free_minor(int type, struct snd_card *card, int dev)
190{ 190{
191 int minor; 191 int minor;
192 192
@@ -209,7 +209,7 @@ static int snd_find_free_minor(int type)
209 return -EBUSY; 209 return -EBUSY;
210} 210}
211#else 211#else
212static int snd_kernel_minor(int type, struct snd_card *card, int dev) 212static int snd_find_free_minor(int type, struct snd_card *card, int dev)
213{ 213{
214 int minor; 214 int minor;
215 215
@@ -237,6 +237,8 @@ static int snd_kernel_minor(int type, struct snd_card *card, int dev)
237 } 237 }
238 if (snd_BUG_ON(minor < 0 || minor >= SNDRV_OS_MINORS)) 238 if (snd_BUG_ON(minor < 0 || minor >= SNDRV_OS_MINORS))
239 return -EINVAL; 239 return -EINVAL;
240 if (snd_minors[minor])
241 return -EBUSY;
240 return minor; 242 return minor;
241} 243}
242#endif 244#endif
@@ -276,13 +278,7 @@ int snd_register_device(int type, struct snd_card *card, int dev,
276 preg->private_data = private_data; 278 preg->private_data = private_data;
277 preg->card_ptr = card; 279 preg->card_ptr = card;
278 mutex_lock(&sound_mutex); 280 mutex_lock(&sound_mutex);
279#ifdef CONFIG_SND_DYNAMIC_MINORS 281 minor = snd_find_free_minor(type, card, dev);
280 minor = snd_find_free_minor(type);
281#else
282 minor = snd_kernel_minor(type, card, dev);
283 if (minor >= 0 && snd_minors[minor])
284 minor = -EBUSY;
285#endif
286 if (minor < 0) { 282 if (minor < 0) {
287 err = minor; 283 err = minor;
288 goto error; 284 goto error;
diff --git a/sound/core/timer.c b/sound/core/timer.c
index 490b489d713d..a9a1a047c521 100644
--- a/sound/core/timer.c
+++ b/sound/core/timer.c
@@ -774,10 +774,8 @@ int snd_timer_new(struct snd_card *card, char *id, struct snd_timer_id *tid,
774 if (rtimer) 774 if (rtimer)
775 *rtimer = NULL; 775 *rtimer = NULL;
776 timer = kzalloc(sizeof(*timer), GFP_KERNEL); 776 timer = kzalloc(sizeof(*timer), GFP_KERNEL);
777 if (timer == NULL) { 777 if (!timer)
778 pr_err("ALSA: timer: cannot allocate\n");
779 return -ENOMEM; 778 return -ENOMEM;
780 }
781 timer->tmr_class = tid->dev_class; 779 timer->tmr_class = tid->dev_class;
782 timer->card = card; 780 timer->card = card;
783 timer->tmr_device = tid->device; 781 timer->tmr_device = tid->device;
diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
index a9f618e06a22..fdae5d7f421f 100644
--- a/sound/drivers/opl3/opl3_seq.c
+++ b/sound/drivers/opl3/opl3_seq.c
@@ -216,8 +216,9 @@ static int snd_opl3_synth_create_port(struct snd_opl3 * opl3)
216 216
217/* ------------------------------ */ 217/* ------------------------------ */
218 218
219static int snd_opl3_seq_new_device(struct snd_seq_device *dev) 219static int snd_opl3_seq_probe(struct device *_dev)
220{ 220{
221 struct snd_seq_device *dev = to_seq_dev(_dev);
221 struct snd_opl3 *opl3; 222 struct snd_opl3 *opl3;
222 int client, err; 223 int client, err;
223 char name[32]; 224 char name[32];
@@ -257,8 +258,9 @@ static int snd_opl3_seq_new_device(struct snd_seq_device *dev)
257 return 0; 258 return 0;
258} 259}
259 260
260static int snd_opl3_seq_delete_device(struct snd_seq_device *dev) 261static int snd_opl3_seq_remove(struct device *_dev)
261{ 262{
263 struct snd_seq_device *dev = to_seq_dev(_dev);
262 struct snd_opl3 *opl3; 264 struct snd_opl3 *opl3;
263 265
264 opl3 = *(struct snd_opl3 **)SNDRV_SEQ_DEVICE_ARGPTR(dev); 266 opl3 = *(struct snd_opl3 **)SNDRV_SEQ_DEVICE_ARGPTR(dev);
@@ -275,22 +277,14 @@ static int snd_opl3_seq_delete_device(struct snd_seq_device *dev)
275 return 0; 277 return 0;
276} 278}
277 279
278static int __init alsa_opl3_seq_init(void) 280static struct snd_seq_driver opl3_seq_driver = {
279{ 281 .driver = {
280 static struct snd_seq_dev_ops ops = 282 .name = KBUILD_MODNAME,
281 { 283 .probe = snd_opl3_seq_probe,
282 snd_opl3_seq_new_device, 284 .remove = snd_opl3_seq_remove,
283 snd_opl3_seq_delete_device 285 },
284 }; 286 .id = SNDRV_SEQ_DEV_ID_OPL3,
285 287 .argsize = sizeof(struct snd_opl3 *),
286 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL3, &ops, 288};
287 sizeof(struct snd_opl3 *));
288}
289
290static void __exit alsa_opl3_seq_exit(void)
291{
292 snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_OPL3);
293}
294 289
295module_init(alsa_opl3_seq_init) 290module_snd_seq_driver(opl3_seq_driver);
296module_exit(alsa_opl3_seq_exit)
diff --git a/sound/drivers/opl4/opl4_seq.c b/sound/drivers/opl4/opl4_seq.c
index 99197699c55a..03d6202f4829 100644
--- a/sound/drivers/opl4/opl4_seq.c
+++ b/sound/drivers/opl4/opl4_seq.c
@@ -124,8 +124,9 @@ static void snd_opl4_seq_free_port(void *private_data)
124 snd_midi_channel_free_set(opl4->chset); 124 snd_midi_channel_free_set(opl4->chset);
125} 125}
126 126
127static int snd_opl4_seq_new_device(struct snd_seq_device *dev) 127static int snd_opl4_seq_probe(struct device *_dev)
128{ 128{
129 struct snd_seq_device *dev = to_seq_dev(_dev);
129 struct snd_opl4 *opl4; 130 struct snd_opl4 *opl4;
130 int client; 131 int client;
131 struct snd_seq_port_callback pcallbacks; 132 struct snd_seq_port_callback pcallbacks;
@@ -180,8 +181,9 @@ static int snd_opl4_seq_new_device(struct snd_seq_device *dev)
180 return 0; 181 return 0;
181} 182}
182 183
183static int snd_opl4_seq_delete_device(struct snd_seq_device *dev) 184static int snd_opl4_seq_remove(struct device *_dev)
184{ 185{
186 struct snd_seq_device *dev = to_seq_dev(_dev);
185 struct snd_opl4 *opl4; 187 struct snd_opl4 *opl4;
186 188
187 opl4 = *(struct snd_opl4 **)SNDRV_SEQ_DEVICE_ARGPTR(dev); 189 opl4 = *(struct snd_opl4 **)SNDRV_SEQ_DEVICE_ARGPTR(dev);
@@ -195,21 +197,14 @@ static int snd_opl4_seq_delete_device(struct snd_seq_device *dev)
195 return 0; 197 return 0;
196} 198}
197 199
198static int __init alsa_opl4_synth_init(void) 200static struct snd_seq_driver opl4_seq_driver = {
199{ 201 .driver = {
200 static struct snd_seq_dev_ops ops = { 202 .name = KBUILD_MODNAME,
201 snd_opl4_seq_new_device, 203 .probe = snd_opl4_seq_probe,
202 snd_opl4_seq_delete_device 204 .remove = snd_opl4_seq_remove,
203 }; 205 },
204 206 .id = SNDRV_SEQ_DEV_ID_OPL4,
205 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL4, &ops, 207 .argsize = sizeof(struct snd_opl4 *),
206 sizeof(struct snd_opl4 *)); 208};
207}
208
209static void __exit alsa_opl4_synth_exit(void)
210{
211 snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_OPL4);
212}
213 209
214module_init(alsa_opl4_synth_init) 210module_snd_seq_driver(opl4_seq_driver);
215module_exit(alsa_opl4_synth_exit)
diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
index 5cc356db5351..e061355f535f 100644
--- a/sound/firewire/amdtp.c
+++ b/sound/firewire/amdtp.c
@@ -166,10 +166,10 @@ int amdtp_stream_add_pcm_hw_constraints(struct amdtp_stream *s,
166 * One AMDTP packet can include some frames. In blocking mode, the 166 * One AMDTP packet can include some frames. In blocking mode, the
167 * number equals to SYT_INTERVAL. So the number is 8, 16 or 32, 167 * number equals to SYT_INTERVAL. So the number is 8, 16 or 32,
168 * depending on its sampling rate. For accurate period interrupt, it's 168 * depending on its sampling rate. For accurate period interrupt, it's
169 * preferrable to aligh period/buffer sizes to current SYT_INTERVAL. 169 * preferrable to align period/buffer sizes to current SYT_INTERVAL.
170 * 170 *
171 * TODO: These constraints can be improved with propper rules. 171 * TODO: These constraints can be improved with proper rules.
172 * Currently apply LCM of SYT_INTEVALs. 172 * Currently apply LCM of SYT_INTERVALs.
173 */ 173 */
174 err = snd_pcm_hw_constraint_step(runtime, 0, 174 err = snd_pcm_hw_constraint_step(runtime, 0,
175 SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 32); 175 SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 32);
@@ -270,7 +270,7 @@ static void amdtp_read_s32(struct amdtp_stream *s,
270 * @s: the AMDTP stream to configure 270 * @s: the AMDTP stream to configure
271 * @format: the format of the ALSA PCM device 271 * @format: the format of the ALSA PCM device
272 * 272 *
273 * The sample format must be set after the other paramters (rate/PCM channels/ 273 * The sample format must be set after the other parameters (rate/PCM channels/
274 * MIDI) and before the stream is started, and must not be changed while the 274 * MIDI) and before the stream is started, and must not be changed while the
275 * stream is running. 275 * stream is running.
276 */ 276 */
diff --git a/sound/firewire/bebob/bebob_maudio.c b/sound/firewire/bebob/bebob_maudio.c
index a422aaa3bb0c..9ee25a63f684 100644
--- a/sound/firewire/bebob/bebob_maudio.c
+++ b/sound/firewire/bebob/bebob_maudio.c
@@ -96,10 +96,10 @@ int snd_bebob_maudio_load_firmware(struct fw_unit *unit)
96 struct fw_device *device = fw_parent_device(unit); 96 struct fw_device *device = fw_parent_device(unit);
97 int err, rcode; 97 int err, rcode;
98 u64 date; 98 u64 date;
99 __be32 cues[3] = { 99 __le32 cues[3] = {
100 MAUDIO_BOOTLOADER_CUE1, 100 cpu_to_le32(MAUDIO_BOOTLOADER_CUE1),
101 MAUDIO_BOOTLOADER_CUE2, 101 cpu_to_le32(MAUDIO_BOOTLOADER_CUE2),
102 MAUDIO_BOOTLOADER_CUE3 102 cpu_to_le32(MAUDIO_BOOTLOADER_CUE3)
103 }; 103 };
104 104
105 /* check date of software used to build */ 105 /* check date of software used to build */
diff --git a/sound/firewire/fireworks/fireworks_transaction.c b/sound/firewire/fireworks/fireworks_transaction.c
index 2a85e4209f0b..f550808d1784 100644
--- a/sound/firewire/fireworks/fireworks_transaction.c
+++ b/sound/firewire/fireworks/fireworks_transaction.c
@@ -13,7 +13,7 @@
13 * 13 *
14 * Transaction substance: 14 * Transaction substance:
15 * At first, 6 data exist. Following to the data, parameters for each command 15 * At first, 6 data exist. Following to the data, parameters for each command
16 * exist. All of the parameters are 32 bit alighed to big endian. 16 * exist. All of the parameters are 32 bit aligned to big endian.
17 * data[0]: Length of transaction substance 17 * data[0]: Length of transaction substance
18 * data[1]: Transaction version 18 * data[1]: Transaction version
19 * data[2]: Sequence number. This is incremented by the device 19 * data[2]: Sequence number. This is incremented by the device
diff --git a/sound/hda/Kconfig b/sound/hda/Kconfig
new file mode 100644
index 000000000000..001c6588a5ff
--- /dev/null
+++ b/sound/hda/Kconfig
@@ -0,0 +1,3 @@
1config SND_HDA_CORE
2 tristate
3 select REGMAP
diff --git a/sound/hda/Makefile b/sound/hda/Makefile
new file mode 100644
index 000000000000..7a359f5b7e25
--- /dev/null
+++ b/sound/hda/Makefile
@@ -0,0 +1,7 @@
1snd-hda-core-objs := hda_bus_type.o hdac_bus.o hdac_device.o hdac_sysfs.o \
2 hdac_regmap.o array.o
3
4snd-hda-core-objs += trace.o
5CFLAGS_trace.o := -I$(src)
6
7obj-$(CONFIG_SND_HDA_CORE) += snd-hda-core.o
diff --git a/sound/hda/array.c b/sound/hda/array.c
new file mode 100644
index 000000000000..516795baa7db
--- /dev/null
+++ b/sound/hda/array.c
@@ -0,0 +1,49 @@
1/*
2 * generic arrays
3 */
4
5#include <linux/slab.h>
6#include <sound/core.h>
7#include <sound/hdaudio.h>
8
9/**
10 * snd_array_new - get a new element from the given array
11 * @array: the array object
12 *
13 * Get a new element from the given array. If it exceeds the
14 * pre-allocated array size, re-allocate the array.
15 *
16 * Returns NULL if allocation failed.
17 */
18void *snd_array_new(struct snd_array *array)
19{
20 if (snd_BUG_ON(!array->elem_size))
21 return NULL;
22 if (array->used >= array->alloced) {
23 int num = array->alloced + array->alloc_align;
24 int size = (num + 1) * array->elem_size;
25 void *nlist;
26 if (snd_BUG_ON(num >= 4096))
27 return NULL;
28 nlist = krealloc(array->list, size, GFP_KERNEL | __GFP_ZERO);
29 if (!nlist)
30 return NULL;
31 array->list = nlist;
32 array->alloced = num;
33 }
34 return snd_array_elem(array, array->used++);
35}
36EXPORT_SYMBOL_GPL(snd_array_new);
37
38/**
39 * snd_array_free - free the given array elements
40 * @array: the array object
41 */
42void snd_array_free(struct snd_array *array)
43{
44 kfree(array->list);
45 array->used = 0;
46 array->alloced = 0;
47 array->list = NULL;
48}
49EXPORT_SYMBOL_GPL(snd_array_free);
diff --git a/sound/hda/hda_bus_type.c b/sound/hda/hda_bus_type.c
new file mode 100644
index 000000000000..519914a12e8a
--- /dev/null
+++ b/sound/hda/hda_bus_type.c
@@ -0,0 +1,42 @@
1/*
2 * HD-audio bus
3 */
4#include <linux/init.h>
5#include <linux/device.h>
6#include <linux/module.h>
7#include <linux/export.h>
8#include <sound/hdaudio.h>
9
10MODULE_DESCRIPTION("HD-audio bus");
11MODULE_LICENSE("GPL");
12
13static int hda_bus_match(struct device *dev, struct device_driver *drv)
14{
15 struct hdac_device *hdev = dev_to_hdac_dev(dev);
16 struct hdac_driver *hdrv = drv_to_hdac_driver(drv);
17
18 if (hdev->type != hdrv->type)
19 return 0;
20 if (hdrv->match)
21 return hdrv->match(hdev, hdrv);
22 return 1;
23}
24
25struct bus_type snd_hda_bus_type = {
26 .name = "hdaudio",
27 .match = hda_bus_match,
28};
29EXPORT_SYMBOL_GPL(snd_hda_bus_type);
30
31static int __init hda_bus_init(void)
32{
33 return bus_register(&snd_hda_bus_type);
34}
35
36static void __exit hda_bus_exit(void)
37{
38 bus_unregister(&snd_hda_bus_type);
39}
40
41subsys_initcall(hda_bus_init);
42module_exit(hda_bus_exit);
diff --git a/sound/hda/hdac_bus.c b/sound/hda/hdac_bus.c
new file mode 100644
index 000000000000..8e262da74f6a
--- /dev/null
+++ b/sound/hda/hdac_bus.c
@@ -0,0 +1,186 @@
1/*
2 * HD-audio core bus driver
3 */
4
5#include <linux/init.h>
6#include <linux/device.h>
7#include <linux/module.h>
8#include <linux/export.h>
9#include <sound/hdaudio.h>
10#include "trace.h"
11
12static void process_unsol_events(struct work_struct *work);
13
14/**
15 * snd_hdac_bus_init - initialize a HD-audio bas bus
16 * @bus: the pointer to bus object
17 *
18 * Returns 0 if successful, or a negative error code.
19 */
20int snd_hdac_bus_init(struct hdac_bus *bus, struct device *dev,
21 const struct hdac_bus_ops *ops)
22{
23 memset(bus, 0, sizeof(*bus));
24 bus->dev = dev;
25 bus->ops = ops;
26 INIT_LIST_HEAD(&bus->codec_list);
27 INIT_WORK(&bus->unsol_work, process_unsol_events);
28 mutex_init(&bus->cmd_mutex);
29 return 0;
30}
31EXPORT_SYMBOL_GPL(snd_hdac_bus_init);
32
33/**
34 * snd_hdac_bus_exit - clean up a HD-audio bas bus
35 * @bus: the pointer to bus object
36 */
37void snd_hdac_bus_exit(struct hdac_bus *bus)
38{
39 WARN_ON(!list_empty(&bus->codec_list));
40 cancel_work_sync(&bus->unsol_work);
41}
42EXPORT_SYMBOL_GPL(snd_hdac_bus_exit);
43
44/**
45 * snd_hdac_bus_exec_verb - execute a HD-audio verb on the given bus
46 * @bus: bus object
47 * @cmd: HD-audio encoded verb
48 * @res: pointer to store the response, NULL if performing asynchronously
49 *
50 * Returns 0 if successful, or a negative error code.
51 */
52int snd_hdac_bus_exec_verb(struct hdac_bus *bus, unsigned int addr,
53 unsigned int cmd, unsigned int *res)
54{
55 int err;
56
57 mutex_lock(&bus->cmd_mutex);
58 err = snd_hdac_bus_exec_verb_unlocked(bus, addr, cmd, res);
59 mutex_unlock(&bus->cmd_mutex);
60 return err;
61}
62EXPORT_SYMBOL_GPL(snd_hdac_bus_exec_verb);
63
64/**
65 * snd_hdac_bus_exec_verb_unlocked - unlocked version
66 * @bus: bus object
67 * @cmd: HD-audio encoded verb
68 * @res: pointer to store the response, NULL if performing asynchronously
69 *
70 * Returns 0 if successful, or a negative error code.
71 */
72int snd_hdac_bus_exec_verb_unlocked(struct hdac_bus *bus, unsigned int addr,
73 unsigned int cmd, unsigned int *res)
74{
75 unsigned int tmp;
76 int err;
77
78 if (cmd == ~0)
79 return -EINVAL;
80
81 if (res)
82 *res = -1;
83 else if (bus->sync_write)
84 res = &tmp;
85 for (;;) {
86 trace_hda_send_cmd(bus, cmd);
87 err = bus->ops->command(bus, cmd);
88 if (err != -EAGAIN)
89 break;
90 /* process pending verbs */
91 err = bus->ops->get_response(bus, addr, &tmp);
92 if (err)
93 break;
94 }
95 if (!err && res) {
96 err = bus->ops->get_response(bus, addr, res);
97 trace_hda_get_response(bus, addr, *res);
98 }
99 return err;
100}
101EXPORT_SYMBOL_GPL(snd_hdac_bus_exec_verb_unlocked);
102
103/**
104 * snd_hdac_bus_queue_event - add an unsolicited event to queue
105 * @bus: the BUS
106 * @res: unsolicited event (lower 32bit of RIRB entry)
107 * @res_ex: codec addr and flags (upper 32bit or RIRB entry)
108 *
109 * Adds the given event to the queue. The events are processed in
110 * the workqueue asynchronously. Call this function in the interrupt
111 * hanlder when RIRB receives an unsolicited event.
112 */
113void snd_hdac_bus_queue_event(struct hdac_bus *bus, u32 res, u32 res_ex)
114{
115 unsigned int wp;
116
117 if (!bus)
118 return;
119
120 trace_hda_unsol_event(bus, res, res_ex);
121 wp = (bus->unsol_wp + 1) % HDA_UNSOL_QUEUE_SIZE;
122 bus->unsol_wp = wp;
123
124 wp <<= 1;
125 bus->unsol_queue[wp] = res;
126 bus->unsol_queue[wp + 1] = res_ex;
127
128 schedule_work(&bus->unsol_work);
129}
130EXPORT_SYMBOL_GPL(snd_hdac_bus_queue_event);
131
132/*
133 * process queued unsolicited events
134 */
135static void process_unsol_events(struct work_struct *work)
136{
137 struct hdac_bus *bus = container_of(work, struct hdac_bus, unsol_work);
138 struct hdac_device *codec;
139 struct hdac_driver *drv;
140 unsigned int rp, caddr, res;
141
142 while (bus->unsol_rp != bus->unsol_wp) {
143 rp = (bus->unsol_rp + 1) % HDA_UNSOL_QUEUE_SIZE;
144 bus->unsol_rp = rp;
145 rp <<= 1;
146 res = bus->unsol_queue[rp];
147 caddr = bus->unsol_queue[rp + 1];
148 if (!(caddr & (1 << 4))) /* no unsolicited event? */
149 continue;
150 codec = bus->caddr_tbl[caddr & 0x0f];
151 if (!codec || !codec->dev.driver)
152 continue;
153 drv = drv_to_hdac_driver(codec->dev.driver);
154 if (drv->unsol_event)
155 drv->unsol_event(codec, res);
156 }
157}
158
159int snd_hdac_bus_add_device(struct hdac_bus *bus, struct hdac_device *codec)
160{
161 if (bus->caddr_tbl[codec->addr]) {
162 dev_err(bus->dev, "address 0x%x is already occupied\n",
163 codec->addr);
164 return -EBUSY;
165 }
166
167 list_add_tail(&codec->list, &bus->codec_list);
168 bus->caddr_tbl[codec->addr] = codec;
169 set_bit(codec->addr, &bus->codec_powered);
170 bus->num_codecs++;
171 return 0;
172}
173EXPORT_SYMBOL_GPL(snd_hdac_bus_add_device);
174
175void snd_hdac_bus_remove_device(struct hdac_bus *bus,
176 struct hdac_device *codec)
177{
178 WARN_ON(bus != codec->bus);
179 if (list_empty(&codec->list))
180 return;
181 list_del_init(&codec->list);
182 bus->caddr_tbl[codec->addr] = NULL;
183 clear_bit(codec->addr, &bus->codec_powered);
184 bus->num_codecs--;
185}
186EXPORT_SYMBOL_GPL(snd_hdac_bus_remove_device);
diff --git a/sound/hda/hdac_device.c b/sound/hda/hdac_device.c
new file mode 100644
index 000000000000..f75bf5622687
--- /dev/null
+++ b/sound/hda/hdac_device.c
@@ -0,0 +1,599 @@
1/*
2 * HD-audio codec core device
3 */
4
5#include <linux/init.h>
6#include <linux/device.h>
7#include <linux/slab.h>
8#include <linux/module.h>
9#include <linux/export.h>
10#include <linux/pm_runtime.h>
11#include <sound/hdaudio.h>
12#include <sound/hda_regmap.h>
13#include "local.h"
14
15static void setup_fg_nodes(struct hdac_device *codec);
16static int get_codec_vendor_name(struct hdac_device *codec);
17
18static void default_release(struct device *dev)
19{
20 snd_hdac_device_exit(container_of(dev, struct hdac_device, dev));
21}
22
23/**
24 * snd_hdac_device_init - initialize the HD-audio codec base device
25 * @codec: device to initialize
26 * @bus: but to attach
27 * @name: device name string
28 * @addr: codec address
29 *
30 * Returns zero for success or a negative error code.
31 *
32 * This function increments the runtime PM counter and marks it active.
33 * The caller needs to turn it off appropriately later.
34 *
35 * The caller needs to set the device's release op properly by itself.
36 */
37int snd_hdac_device_init(struct hdac_device *codec, struct hdac_bus *bus,
38 const char *name, unsigned int addr)
39{
40 struct device *dev;
41 hda_nid_t fg;
42 int err;
43
44 dev = &codec->dev;
45 device_initialize(dev);
46 dev->parent = bus->dev;
47 dev->bus = &snd_hda_bus_type;
48 dev->release = default_release;
49 dev->groups = hdac_dev_attr_groups;
50 dev_set_name(dev, "%s", name);
51 device_enable_async_suspend(dev);
52
53 codec->bus = bus;
54 codec->addr = addr;
55 codec->type = HDA_DEV_CORE;
56 pm_runtime_set_active(&codec->dev);
57 pm_runtime_get_noresume(&codec->dev);
58 atomic_set(&codec->in_pm, 0);
59
60 err = snd_hdac_bus_add_device(bus, codec);
61 if (err < 0)
62 goto error;
63
64 /* fill parameters */
65 codec->vendor_id = snd_hdac_read_parm(codec, AC_NODE_ROOT,
66 AC_PAR_VENDOR_ID);
67 if (codec->vendor_id == -1) {
68 /* read again, hopefully the access method was corrected
69 * in the last read...
70 */
71 codec->vendor_id = snd_hdac_read_parm(codec, AC_NODE_ROOT,
72 AC_PAR_VENDOR_ID);
73 }
74
75 codec->subsystem_id = snd_hdac_read_parm(codec, AC_NODE_ROOT,
76 AC_PAR_SUBSYSTEM_ID);
77 codec->revision_id = snd_hdac_read_parm(codec, AC_NODE_ROOT,
78 AC_PAR_REV_ID);
79
80 setup_fg_nodes(codec);
81 if (!codec->afg && !codec->mfg) {
82 dev_err(dev, "no AFG or MFG node found\n");
83 err = -ENODEV;
84 goto error;
85 }
86
87 fg = codec->afg ? codec->afg : codec->mfg;
88
89 err = snd_hdac_refresh_widgets(codec);
90 if (err < 0)
91 goto error;
92
93 codec->power_caps = snd_hdac_read_parm(codec, fg, AC_PAR_POWER_STATE);
94 /* reread ssid if not set by parameter */
95 if (codec->subsystem_id == -1 || codec->subsystem_id == 0)
96 snd_hdac_read(codec, fg, AC_VERB_GET_SUBSYSTEM_ID, 0,
97 &codec->subsystem_id);
98
99 err = get_codec_vendor_name(codec);
100 if (err < 0)
101 goto error;
102
103 codec->chip_name = kasprintf(GFP_KERNEL, "ID %x",
104 codec->vendor_id & 0xffff);
105 if (!codec->chip_name) {
106 err = -ENOMEM;
107 goto error;
108 }
109
110 return 0;
111
112 error:
113 put_device(&codec->dev);
114 return err;
115}
116EXPORT_SYMBOL_GPL(snd_hdac_device_init);
117
118/**
119 * snd_hdac_device_exit - clean up the HD-audio codec base device
120 * @codec: device to clean up
121 */
122void snd_hdac_device_exit(struct hdac_device *codec)
123{
124 pm_runtime_put_noidle(&codec->dev);
125 snd_hdac_bus_remove_device(codec->bus, codec);
126 kfree(codec->vendor_name);
127 kfree(codec->chip_name);
128}
129EXPORT_SYMBOL_GPL(snd_hdac_device_exit);
130
131/**
132 * snd_hdac_device_register - register the hd-audio codec base device
133 * codec: the device to register
134 */
135int snd_hdac_device_register(struct hdac_device *codec)
136{
137 int err;
138
139 err = device_add(&codec->dev);
140 if (err < 0)
141 return err;
142 err = hda_widget_sysfs_init(codec);
143 if (err < 0) {
144 device_del(&codec->dev);
145 return err;
146 }
147
148 return 0;
149}
150EXPORT_SYMBOL_GPL(snd_hdac_device_register);
151
152/**
153 * snd_hdac_device_unregister - unregister the hd-audio codec base device
154 * codec: the device to unregister
155 */
156void snd_hdac_device_unregister(struct hdac_device *codec)
157{
158 if (device_is_registered(&codec->dev)) {
159 hda_widget_sysfs_exit(codec);
160 device_del(&codec->dev);
161 }
162}
163EXPORT_SYMBOL_GPL(snd_hdac_device_unregister);
164
165/**
166 * snd_hdac_make_cmd - compose a 32bit command word to be sent to the
167 * HD-audio controller
168 * @codec: the codec object
169 * @nid: NID to encode
170 * @verb: verb to encode
171 * @parm: parameter to encode
172 *
173 * Return an encoded command verb or -1 for error.
174 */
175unsigned int snd_hdac_make_cmd(struct hdac_device *codec, hda_nid_t nid,
176 unsigned int verb, unsigned int parm)
177{
178 u32 val, addr;
179
180 addr = codec->addr;
181 if ((addr & ~0xf) || (nid & ~0x7f) ||
182 (verb & ~0xfff) || (parm & ~0xffff)) {
183 dev_err(&codec->dev, "out of range cmd %x:%x:%x:%x\n",
184 addr, nid, verb, parm);
185 return -1;
186 }
187
188 val = addr << 28;
189 val |= (u32)nid << 20;
190 val |= verb << 8;
191 val |= parm;
192 return val;
193}
194EXPORT_SYMBOL_GPL(snd_hdac_make_cmd);
195
196/**
197 * snd_hdac_exec_verb - execute an encoded verb
198 * @codec: the codec object
199 * @cmd: encoded verb to execute
200 * @flags: optional flags, pass zero for default
201 * @res: the pointer to store the result, NULL if running async
202 *
203 * Returns zero if successful, or a negative error code.
204 *
205 * This calls the exec_verb op when set in hdac_codec. If not,
206 * call the default snd_hdac_bus_exec_verb().
207 */
208int snd_hdac_exec_verb(struct hdac_device *codec, unsigned int cmd,
209 unsigned int flags, unsigned int *res)
210{
211 if (codec->exec_verb)
212 return codec->exec_verb(codec, cmd, flags, res);
213 return snd_hdac_bus_exec_verb(codec->bus, codec->addr, cmd, res);
214}
215EXPORT_SYMBOL_GPL(snd_hdac_exec_verb);
216
217
218/**
219 * snd_hdac_read - execute a verb
220 * @codec: the codec object
221 * @nid: NID to execute a verb
222 * @verb: verb to execute
223 * @parm: parameter for a verb
224 * @res: the pointer to store the result, NULL if running async
225 *
226 * Returns zero if successful, or a negative error code.
227 */
228int snd_hdac_read(struct hdac_device *codec, hda_nid_t nid,
229 unsigned int verb, unsigned int parm, unsigned int *res)
230{
231 unsigned int cmd = snd_hdac_make_cmd(codec, nid, verb, parm);
232
233 return snd_hdac_exec_verb(codec, cmd, 0, res);
234}
235EXPORT_SYMBOL_GPL(snd_hdac_read);
236
237/**
238 * _snd_hdac_read_parm - read a parmeter
239 *
240 * This function returns zero or an error unlike snd_hdac_read_parm().
241 */
242int _snd_hdac_read_parm(struct hdac_device *codec, hda_nid_t nid, int parm,
243 unsigned int *res)
244{
245 unsigned int cmd;
246
247 cmd = snd_hdac_regmap_encode_verb(nid, AC_VERB_PARAMETERS) | parm;
248 return snd_hdac_regmap_read_raw(codec, cmd, res);
249}
250EXPORT_SYMBOL_GPL(_snd_hdac_read_parm);
251
252/**
253 * snd_hdac_read_parm_uncached - read a codec parameter without caching
254 * @codec: the codec object
255 * @nid: NID to read a parameter
256 * @parm: parameter to read
257 *
258 * Returns -1 for error. If you need to distinguish the error more
259 * strictly, use snd_hdac_read() directly.
260 */
261int snd_hdac_read_parm_uncached(struct hdac_device *codec, hda_nid_t nid,
262 int parm)
263{
264 int val;
265
266 if (codec->regmap)
267 regcache_cache_bypass(codec->regmap, true);
268 val = snd_hdac_read_parm(codec, nid, parm);
269 if (codec->regmap)
270 regcache_cache_bypass(codec->regmap, false);
271 return val;
272}
273EXPORT_SYMBOL_GPL(snd_hdac_read_parm_uncached);
274
275/**
276 * snd_hdac_override_parm - override read-only parameters
277 * @codec: the codec object
278 * @nid: NID for the parameter
279 * @parm: the parameter to change
280 * @val: the parameter value to overwrite
281 */
282int snd_hdac_override_parm(struct hdac_device *codec, hda_nid_t nid,
283 unsigned int parm, unsigned int val)
284{
285 unsigned int verb = (AC_VERB_PARAMETERS << 8) | (nid << 20) | parm;
286 int err;
287
288 if (!codec->regmap)
289 return -EINVAL;
290
291 codec->caps_overwriting = true;
292 err = snd_hdac_regmap_write_raw(codec, verb, val);
293 codec->caps_overwriting = false;
294 return err;
295}
296EXPORT_SYMBOL_GPL(snd_hdac_override_parm);
297
298/**
299 * snd_hdac_get_sub_nodes - get start NID and number of subtree nodes
300 * @codec: the codec object
301 * @nid: NID to inspect
302 * @start_id: the pointer to store the starting NID
303 *
304 * Returns the number of subtree nodes or zero if not found.
305 * This function reads parameters always without caching.
306 */
307int snd_hdac_get_sub_nodes(struct hdac_device *codec, hda_nid_t nid,
308 hda_nid_t *start_id)
309{
310 unsigned int parm;
311
312 parm = snd_hdac_read_parm_uncached(codec, nid, AC_PAR_NODE_COUNT);
313 if (parm == -1) {
314 *start_id = 0;
315 return 0;
316 }
317 *start_id = (parm >> 16) & 0x7fff;
318 return (int)(parm & 0x7fff);
319}
320EXPORT_SYMBOL_GPL(snd_hdac_get_sub_nodes);
321
322/*
323 * look for an AFG and MFG nodes
324 */
325static void setup_fg_nodes(struct hdac_device *codec)
326{
327 int i, total_nodes, function_id;
328 hda_nid_t nid;
329
330 total_nodes = snd_hdac_get_sub_nodes(codec, AC_NODE_ROOT, &nid);
331 for (i = 0; i < total_nodes; i++, nid++) {
332 function_id = snd_hdac_read_parm(codec, nid,
333 AC_PAR_FUNCTION_TYPE);
334 switch (function_id & 0xff) {
335 case AC_GRP_AUDIO_FUNCTION:
336 codec->afg = nid;
337 codec->afg_function_id = function_id & 0xff;
338 codec->afg_unsol = (function_id >> 8) & 1;
339 break;
340 case AC_GRP_MODEM_FUNCTION:
341 codec->mfg = nid;
342 codec->mfg_function_id = function_id & 0xff;
343 codec->mfg_unsol = (function_id >> 8) & 1;
344 break;
345 default:
346 break;
347 }
348 }
349}
350
351/**
352 * snd_hdac_refresh_widgets - Reset the widget start/end nodes
353 * @codec: the codec object
354 */
355int snd_hdac_refresh_widgets(struct hdac_device *codec)
356{
357 hda_nid_t start_nid;
358 int nums;
359
360 nums = snd_hdac_get_sub_nodes(codec, codec->afg, &start_nid);
361 if (!start_nid || nums <= 0 || nums >= 0xff) {
362 dev_err(&codec->dev, "cannot read sub nodes for FG 0x%02x\n",
363 codec->afg);
364 return -EINVAL;
365 }
366
367 codec->num_nodes = nums;
368 codec->start_nid = start_nid;
369 codec->end_nid = start_nid + nums;
370 return 0;
371}
372EXPORT_SYMBOL_GPL(snd_hdac_refresh_widgets);
373
374/* return CONNLIST_LEN parameter of the given widget */
375static unsigned int get_num_conns(struct hdac_device *codec, hda_nid_t nid)
376{
377 unsigned int wcaps = get_wcaps(codec, nid);
378 unsigned int parm;
379
380 if (!(wcaps & AC_WCAP_CONN_LIST) &&
381 get_wcaps_type(wcaps) != AC_WID_VOL_KNB)
382 return 0;
383
384 parm = snd_hdac_read_parm(codec, nid, AC_PAR_CONNLIST_LEN);
385 if (parm == -1)
386 parm = 0;
387 return parm;
388}
389
390/**
391 * snd_hdac_get_connections - get a widget connection list
392 * @codec: the codec object
393 * @nid: NID
394 * @conn_list: the array to store the results, can be NULL
395 * @max_conns: the max size of the given array
396 *
397 * Returns the number of connected widgets, zero for no connection, or a
398 * negative error code. When the number of elements don't fit with the
399 * given array size, it returns -ENOSPC.
400 *
401 * When @conn_list is NULL, it just checks the number of connections.
402 */
403int snd_hdac_get_connections(struct hdac_device *codec, hda_nid_t nid,
404 hda_nid_t *conn_list, int max_conns)
405{
406 unsigned int parm;
407 int i, conn_len, conns, err;
408 unsigned int shift, num_elems, mask;
409 hda_nid_t prev_nid;
410 int null_count = 0;
411
412 parm = get_num_conns(codec, nid);
413 if (!parm)
414 return 0;
415
416 if (parm & AC_CLIST_LONG) {
417 /* long form */
418 shift = 16;
419 num_elems = 2;
420 } else {
421 /* short form */
422 shift = 8;
423 num_elems = 4;
424 }
425 conn_len = parm & AC_CLIST_LENGTH;
426 mask = (1 << (shift-1)) - 1;
427
428 if (!conn_len)
429 return 0; /* no connection */
430
431 if (conn_len == 1) {
432 /* single connection */
433 err = snd_hdac_read(codec, nid, AC_VERB_GET_CONNECT_LIST, 0,
434 &parm);
435 if (err < 0)
436 return err;
437 if (conn_list)
438 conn_list[0] = parm & mask;
439 return 1;
440 }
441
442 /* multi connection */
443 conns = 0;
444 prev_nid = 0;
445 for (i = 0; i < conn_len; i++) {
446 int range_val;
447 hda_nid_t val, n;
448
449 if (i % num_elems == 0) {
450 err = snd_hdac_read(codec, nid,
451 AC_VERB_GET_CONNECT_LIST, i,
452 &parm);
453 if (err < 0)
454 return -EIO;
455 }
456 range_val = !!(parm & (1 << (shift-1))); /* ranges */
457 val = parm & mask;
458 if (val == 0 && null_count++) { /* no second chance */
459 dev_dbg(&codec->dev,
460 "invalid CONNECT_LIST verb %x[%i]:%x\n",
461 nid, i, parm);
462 return 0;
463 }
464 parm >>= shift;
465 if (range_val) {
466 /* ranges between the previous and this one */
467 if (!prev_nid || prev_nid >= val) {
468 dev_warn(&codec->dev,
469 "invalid dep_range_val %x:%x\n",
470 prev_nid, val);
471 continue;
472 }
473 for (n = prev_nid + 1; n <= val; n++) {
474 if (conn_list) {
475 if (conns >= max_conns)
476 return -ENOSPC;
477 conn_list[conns] = n;
478 }
479 conns++;
480 }
481 } else {
482 if (conn_list) {
483 if (conns >= max_conns)
484 return -ENOSPC;
485 conn_list[conns] = val;
486 }
487 conns++;
488 }
489 prev_nid = val;
490 }
491 return conns;
492}
493EXPORT_SYMBOL_GPL(snd_hdac_get_connections);
494
495#ifdef CONFIG_PM
496/**
497 * snd_hdac_power_up - power up the codec
498 * @codec: the codec object
499 *
500 * This function calls the runtime PM helper to power up the given codec.
501 * Unlike snd_hdac_power_up_pm(), you should call this only for the code
502 * path that isn't included in PM path. Otherwise it gets stuck.
503 */
504void snd_hdac_power_up(struct hdac_device *codec)
505{
506 pm_runtime_get_sync(&codec->dev);
507}
508EXPORT_SYMBOL_GPL(snd_hdac_power_up);
509
510/**
511 * snd_hdac_power_down - power down the codec
512 * @codec: the codec object
513 */
514void snd_hdac_power_down(struct hdac_device *codec)
515{
516 struct device *dev = &codec->dev;
517
518 pm_runtime_mark_last_busy(dev);
519 pm_runtime_put_autosuspend(dev);
520}
521EXPORT_SYMBOL_GPL(snd_hdac_power_down);
522
523/**
524 * snd_hdac_power_up_pm - power up the codec
525 * @codec: the codec object
526 *
527 * This function can be called in a recursive code path like init code
528 * which may be called by PM suspend/resume again. OTOH, if a power-up
529 * call must wake up the sleeper (e.g. in a kctl callback), use
530 * snd_hdac_power_up() instead.
531 */
532void snd_hdac_power_up_pm(struct hdac_device *codec)
533{
534 if (!atomic_inc_not_zero(&codec->in_pm))
535 snd_hdac_power_up(codec);
536}
537EXPORT_SYMBOL_GPL(snd_hdac_power_up_pm);
538
539/**
540 * snd_hdac_power_down_pm - power down the codec
541 * @codec: the codec object
542 *
543 * Like snd_hdac_power_up_pm(), this function is used in a recursive
544 * code path like init code which may be called by PM suspend/resume again.
545 */
546void snd_hdac_power_down_pm(struct hdac_device *codec)
547{
548 if (atomic_dec_if_positive(&codec->in_pm) < 0)
549 snd_hdac_power_down(codec);
550}
551EXPORT_SYMBOL_GPL(snd_hdac_power_down_pm);
552#endif
553
554/* codec vendor labels */
555struct hda_vendor_id {
556 unsigned int id;
557 const char *name;
558};
559
560static struct hda_vendor_id hda_vendor_ids[] = {
561 { 0x1002, "ATI" },
562 { 0x1013, "Cirrus Logic" },
563 { 0x1057, "Motorola" },
564 { 0x1095, "Silicon Image" },
565 { 0x10de, "Nvidia" },
566 { 0x10ec, "Realtek" },
567 { 0x1102, "Creative" },
568 { 0x1106, "VIA" },
569 { 0x111d, "IDT" },
570 { 0x11c1, "LSI" },
571 { 0x11d4, "Analog Devices" },
572 { 0x13f6, "C-Media" },
573 { 0x14f1, "Conexant" },
574 { 0x17e8, "Chrontel" },
575 { 0x1854, "LG" },
576 { 0x1aec, "Wolfson Microelectronics" },
577 { 0x1af4, "QEMU" },
578 { 0x434d, "C-Media" },
579 { 0x8086, "Intel" },
580 { 0x8384, "SigmaTel" },
581 {} /* terminator */
582};
583
584/* store the codec vendor name */
585static int get_codec_vendor_name(struct hdac_device *codec)
586{
587 const struct hda_vendor_id *c;
588 u16 vendor_id = codec->vendor_id >> 16;
589
590 for (c = hda_vendor_ids; c->id; c++) {
591 if (c->id == vendor_id) {
592 codec->vendor_name = kstrdup(c->name, GFP_KERNEL);
593 return codec->vendor_name ? 0 : -ENOMEM;
594 }
595 }
596
597 codec->vendor_name = kasprintf(GFP_KERNEL, "Generic %04x", vendor_id);
598 return codec->vendor_name ? 0 : -ENOMEM;
599}
diff --git a/sound/hda/hdac_regmap.c b/sound/hda/hdac_regmap.c
new file mode 100644
index 000000000000..7371e0c3926f
--- /dev/null
+++ b/sound/hda/hdac_regmap.c
@@ -0,0 +1,472 @@
1/*
2 * Regmap support for HD-audio verbs
3 *
4 * A virtual register is translated to one or more hda verbs for write,
5 * vice versa for read.
6 *
7 * A few limitations:
8 * - Provided for not all verbs but only subset standard non-volatile verbs.
9 * - For reading, only AC_VERB_GET_* variants can be used.
10 * - For writing, mapped to the *corresponding* AC_VERB_SET_* variants,
11 * so can't handle asymmetric verbs for read and write
12 */
13
14#include <linux/slab.h>
15#include <linux/device.h>
16#include <linux/regmap.h>
17#include <linux/export.h>
18#include <linux/pm.h>
19#include <linux/pm_runtime.h>
20#include <sound/core.h>
21#include <sound/hdaudio.h>
22#include <sound/hda_regmap.h>
23
24#ifdef CONFIG_PM
25#define codec_is_running(codec) \
26 (atomic_read(&(codec)->in_pm) || \
27 !pm_runtime_suspended(&(codec)->dev))
28#else
29#define codec_is_running(codec) true
30#endif
31
32#define get_verb(reg) (((reg) >> 8) & 0xfff)
33
34static bool hda_volatile_reg(struct device *dev, unsigned int reg)
35{
36 struct hdac_device *codec = dev_to_hdac_dev(dev);
37 unsigned int verb = get_verb(reg);
38
39 switch (verb) {
40 case AC_VERB_GET_PROC_COEF:
41 return !codec->cache_coef;
42 case AC_VERB_GET_COEF_INDEX:
43 case AC_VERB_GET_PROC_STATE:
44 case AC_VERB_GET_POWER_STATE:
45 case AC_VERB_GET_PIN_SENSE:
46 case AC_VERB_GET_HDMI_DIP_SIZE:
47 case AC_VERB_GET_HDMI_ELDD:
48 case AC_VERB_GET_HDMI_DIP_INDEX:
49 case AC_VERB_GET_HDMI_DIP_DATA:
50 case AC_VERB_GET_HDMI_DIP_XMIT:
51 case AC_VERB_GET_HDMI_CP_CTRL:
52 case AC_VERB_GET_HDMI_CHAN_SLOT:
53 case AC_VERB_GET_DEVICE_SEL:
54 case AC_VERB_GET_DEVICE_LIST: /* read-only volatile */
55 return true;
56 }
57
58 return false;
59}
60
61static bool hda_writeable_reg(struct device *dev, unsigned int reg)
62{
63 struct hdac_device *codec = dev_to_hdac_dev(dev);
64 unsigned int verb = get_verb(reg);
65 int i;
66
67 for (i = 0; i < codec->vendor_verbs.used; i++) {
68 unsigned int *v = snd_array_elem(&codec->vendor_verbs, i);
69 if (verb == *v)
70 return true;
71 }
72
73 if (codec->caps_overwriting)
74 return true;
75
76 switch (verb & 0xf00) {
77 case AC_VERB_GET_STREAM_FORMAT:
78 case AC_VERB_GET_AMP_GAIN_MUTE:
79 return true;
80 case AC_VERB_GET_PROC_COEF:
81 return codec->cache_coef;
82 case 0xf00:
83 break;
84 default:
85 return false;
86 }
87
88 switch (verb) {
89 case AC_VERB_GET_CONNECT_SEL:
90 case AC_VERB_GET_SDI_SELECT:
91 case AC_VERB_GET_PIN_WIDGET_CONTROL:
92 case AC_VERB_GET_UNSOLICITED_RESPONSE: /* only as SET_UNSOLICITED_ENABLE */
93 case AC_VERB_GET_BEEP_CONTROL:
94 case AC_VERB_GET_EAPD_BTLENABLE:
95 case AC_VERB_GET_DIGI_CONVERT_1:
96 case AC_VERB_GET_DIGI_CONVERT_2: /* only for beep control */
97 case AC_VERB_GET_VOLUME_KNOB_CONTROL:
98 case AC_VERB_GET_GPIO_MASK:
99 case AC_VERB_GET_GPIO_DIRECTION:
100 case AC_VERB_GET_GPIO_DATA: /* not for volatile read */
101 case AC_VERB_GET_GPIO_WAKE_MASK:
102 case AC_VERB_GET_GPIO_UNSOLICITED_RSP_MASK:
103 case AC_VERB_GET_GPIO_STICKY_MASK:
104 return true;
105 }
106
107 return false;
108}
109
110static bool hda_readable_reg(struct device *dev, unsigned int reg)
111{
112 struct hdac_device *codec = dev_to_hdac_dev(dev);
113 unsigned int verb = get_verb(reg);
114
115 if (codec->caps_overwriting)
116 return true;
117
118 switch (verb) {
119 case AC_VERB_PARAMETERS:
120 case AC_VERB_GET_CONNECT_LIST:
121 case AC_VERB_GET_SUBSYSTEM_ID:
122 return true;
123 /* below are basically writable, but disabled for reducing unnecessary
124 * writes at sync
125 */
126 case AC_VERB_GET_CONFIG_DEFAULT: /* usually just read */
127 case AC_VERB_GET_CONV: /* managed in PCM code */
128 case AC_VERB_GET_CVT_CHAN_COUNT: /* managed in HDMI CA code */
129 return true;
130 }
131
132 return hda_writeable_reg(dev, reg);
133}
134
135/*
136 * Stereo amp pseudo register:
137 * for making easier to handle the stereo volume control, we provide a
138 * fake register to deal both left and right channels by a single
139 * (pseudo) register access. A verb consisting of SET_AMP_GAIN with
140 * *both* SET_LEFT and SET_RIGHT bits takes a 16bit value, the lower 8bit
141 * for the left and the upper 8bit for the right channel.
142 */
143static bool is_stereo_amp_verb(unsigned int reg)
144{
145 if (((reg >> 8) & 0x700) != AC_VERB_SET_AMP_GAIN_MUTE)
146 return false;
147 return (reg & (AC_AMP_SET_LEFT | AC_AMP_SET_RIGHT)) ==
148 (AC_AMP_SET_LEFT | AC_AMP_SET_RIGHT);
149}
150
151/* read a pseudo stereo amp register (16bit left+right) */
152static int hda_reg_read_stereo_amp(struct hdac_device *codec,
153 unsigned int reg, unsigned int *val)
154{
155 unsigned int left, right;
156 int err;
157
158 reg &= ~(AC_AMP_SET_LEFT | AC_AMP_SET_RIGHT);
159 err = snd_hdac_exec_verb(codec, reg | AC_AMP_GET_LEFT, 0, &left);
160 if (err < 0)
161 return err;
162 err = snd_hdac_exec_verb(codec, reg | AC_AMP_GET_RIGHT, 0, &right);
163 if (err < 0)
164 return err;
165 *val = left | (right << 8);
166 return 0;
167}
168
169/* write a pseudo stereo amp register (16bit left+right) */
170static int hda_reg_write_stereo_amp(struct hdac_device *codec,
171 unsigned int reg, unsigned int val)
172{
173 int err;
174 unsigned int verb, left, right;
175
176 verb = AC_VERB_SET_AMP_GAIN_MUTE << 8;
177 if (reg & AC_AMP_GET_OUTPUT)
178 verb |= AC_AMP_SET_OUTPUT;
179 else
180 verb |= AC_AMP_SET_INPUT | ((reg & 0xf) << 8);
181 reg = (reg & ~0xfffff) | verb;
182
183 left = val & 0xff;
184 right = (val >> 8) & 0xff;
185 if (left == right) {
186 reg |= AC_AMP_SET_LEFT | AC_AMP_SET_RIGHT;
187 return snd_hdac_exec_verb(codec, reg | left, 0, NULL);
188 }
189
190 err = snd_hdac_exec_verb(codec, reg | AC_AMP_SET_LEFT | left, 0, NULL);
191 if (err < 0)
192 return err;
193 err = snd_hdac_exec_verb(codec, reg | AC_AMP_SET_RIGHT | right, 0, NULL);
194 if (err < 0)
195 return err;
196 return 0;
197}
198
199/* read a pseudo coef register (16bit) */
200static int hda_reg_read_coef(struct hdac_device *codec, unsigned int reg,
201 unsigned int *val)
202{
203 unsigned int verb;
204 int err;
205
206 if (!codec->cache_coef)
207 return -EINVAL;
208 /* LSB 8bit = coef index */
209 verb = (reg & ~0xfff00) | (AC_VERB_SET_COEF_INDEX << 8);
210 err = snd_hdac_exec_verb(codec, verb, 0, NULL);
211 if (err < 0)
212 return err;
213 verb = (reg & ~0xfffff) | (AC_VERB_GET_COEF_INDEX << 8);
214 return snd_hdac_exec_verb(codec, verb, 0, val);
215}
216
217/* write a pseudo coef register (16bit) */
218static int hda_reg_write_coef(struct hdac_device *codec, unsigned int reg,
219 unsigned int val)
220{
221 unsigned int verb;
222 int err;
223
224 if (!codec->cache_coef)
225 return -EINVAL;
226 /* LSB 8bit = coef index */
227 verb = (reg & ~0xfff00) | (AC_VERB_SET_COEF_INDEX << 8);
228 err = snd_hdac_exec_verb(codec, verb, 0, NULL);
229 if (err < 0)
230 return err;
231 verb = (reg & ~0xfffff) | (AC_VERB_GET_COEF_INDEX << 8) |
232 (val & 0xffff);
233 return snd_hdac_exec_verb(codec, verb, 0, NULL);
234}
235
236static int hda_reg_read(void *context, unsigned int reg, unsigned int *val)
237{
238 struct hdac_device *codec = context;
239 int verb = get_verb(reg);
240 int err;
241
242 if (!codec_is_running(codec) && verb != AC_VERB_GET_POWER_STATE)
243 return -EAGAIN;
244 reg |= (codec->addr << 28);
245 if (is_stereo_amp_verb(reg))
246 return hda_reg_read_stereo_amp(codec, reg, val);
247 if (verb == AC_VERB_GET_PROC_COEF)
248 return hda_reg_read_coef(codec, reg, val);
249 err = snd_hdac_exec_verb(codec, reg, 0, val);
250 if (err < 0)
251 return err;
252 /* special handling for asymmetric reads */
253 if (verb == AC_VERB_GET_POWER_STATE) {
254 if (*val & AC_PWRST_ERROR)
255 *val = -1;
256 else /* take only the actual state */
257 *val = (*val >> 4) & 0x0f;
258 }
259 return 0;
260}
261
262static int hda_reg_write(void *context, unsigned int reg, unsigned int val)
263{
264 struct hdac_device *codec = context;
265 unsigned int verb;
266 int i, bytes, err;
267
268 reg &= ~0x00080000U; /* drop GET bit */
269 reg |= (codec->addr << 28);
270 verb = get_verb(reg);
271
272 if (!codec_is_running(codec) && verb != AC_VERB_SET_POWER_STATE)
273 return codec->lazy_cache ? 0 : -EAGAIN;
274
275 if (is_stereo_amp_verb(reg))
276 return hda_reg_write_stereo_amp(codec, reg, val);
277
278 if (verb == AC_VERB_SET_PROC_COEF)
279 return hda_reg_write_coef(codec, reg, val);
280
281 switch (verb & 0xf00) {
282 case AC_VERB_SET_AMP_GAIN_MUTE:
283 verb = AC_VERB_SET_AMP_GAIN_MUTE;
284 if (reg & AC_AMP_GET_LEFT)
285 verb |= AC_AMP_SET_LEFT >> 8;
286 else
287 verb |= AC_AMP_SET_RIGHT >> 8;
288 if (reg & AC_AMP_GET_OUTPUT) {
289 verb |= AC_AMP_SET_OUTPUT >> 8;
290 } else {
291 verb |= AC_AMP_SET_INPUT >> 8;
292 verb |= reg & 0xf;
293 }
294 break;
295 }
296
297 switch (verb) {
298 case AC_VERB_SET_DIGI_CONVERT_1:
299 bytes = 2;
300 break;
301 case AC_VERB_SET_CONFIG_DEFAULT_BYTES_0:
302 bytes = 4;
303 break;
304 default:
305 bytes = 1;
306 break;
307 }
308
309 for (i = 0; i < bytes; i++) {
310 reg &= ~0xfffff;
311 reg |= (verb + i) << 8 | ((val >> (8 * i)) & 0xff);
312 err = snd_hdac_exec_verb(codec, reg, 0, NULL);
313 if (err < 0)
314 return err;
315 }
316
317 return 0;
318}
319
320static const struct regmap_config hda_regmap_cfg = {
321 .name = "hdaudio",
322 .reg_bits = 32,
323 .val_bits = 32,
324 .max_register = 0xfffffff,
325 .writeable_reg = hda_writeable_reg,
326 .readable_reg = hda_readable_reg,
327 .volatile_reg = hda_volatile_reg,
328 .cache_type = REGCACHE_RBTREE,
329 .reg_read = hda_reg_read,
330 .reg_write = hda_reg_write,
331 .use_single_rw = true,
332};
333
334int snd_hdac_regmap_init(struct hdac_device *codec)
335{
336 struct regmap *regmap;
337
338 regmap = regmap_init(&codec->dev, NULL, codec, &hda_regmap_cfg);
339 if (IS_ERR(regmap))
340 return PTR_ERR(regmap);
341 codec->regmap = regmap;
342 snd_array_init(&codec->vendor_verbs, sizeof(unsigned int), 8);
343 return 0;
344}
345EXPORT_SYMBOL_GPL(snd_hdac_regmap_init);
346
347void snd_hdac_regmap_exit(struct hdac_device *codec)
348{
349 if (codec->regmap) {
350 regmap_exit(codec->regmap);
351 codec->regmap = NULL;
352 snd_array_free(&codec->vendor_verbs);
353 }
354}
355EXPORT_SYMBOL_GPL(snd_hdac_regmap_exit);
356
357/**
358 * snd_hdac_regmap_add_vendor_verb - add a vendor-specific verb to regmap
359 * @codec: the codec object
360 * @verb: verb to allow accessing via regmap
361 *
362 * Returns zero for success or a negative error code.
363 */
364int snd_hdac_regmap_add_vendor_verb(struct hdac_device *codec,
365 unsigned int verb)
366{
367 unsigned int *p = snd_array_new(&codec->vendor_verbs);
368
369 if (!p)
370 return -ENOMEM;
371 *p = verb | 0x800; /* set GET bit */
372 return 0;
373}
374EXPORT_SYMBOL_GPL(snd_hdac_regmap_add_vendor_verb);
375
376/*
377 * helper functions
378 */
379
380/* write a pseudo-register value (w/o power sequence) */
381static int reg_raw_write(struct hdac_device *codec, unsigned int reg,
382 unsigned int val)
383{
384 if (!codec->regmap)
385 return hda_reg_write(codec, reg, val);
386 else
387 return regmap_write(codec->regmap, reg, val);
388}
389
390/**
391 * snd_hdac_regmap_write_raw - write a pseudo register with power mgmt
392 * @codec: the codec object
393 * @reg: pseudo register
394 * @val: value to write
395 *
396 * Returns zero if successful or a negative error code.
397 */
398int snd_hdac_regmap_write_raw(struct hdac_device *codec, unsigned int reg,
399 unsigned int val)
400{
401 int err;
402
403 err = reg_raw_write(codec, reg, val);
404 if (err == -EAGAIN) {
405 snd_hdac_power_up_pm(codec);
406 err = reg_raw_write(codec, reg, val);
407 snd_hdac_power_down_pm(codec);
408 }
409 return err;
410}
411EXPORT_SYMBOL_GPL(snd_hdac_regmap_write_raw);
412
413static int reg_raw_read(struct hdac_device *codec, unsigned int reg,
414 unsigned int *val)
415{
416 if (!codec->regmap)
417 return hda_reg_read(codec, reg, val);
418 else
419 return regmap_read(codec->regmap, reg, val);
420}
421
422/**
423 * snd_hdac_regmap_read_raw - read a pseudo register with power mgmt
424 * @codec: the codec object
425 * @reg: pseudo register
426 * @val: pointer to store the read value
427 *
428 * Returns zero if successful or a negative error code.
429 */
430int snd_hdac_regmap_read_raw(struct hdac_device *codec, unsigned int reg,
431 unsigned int *val)
432{
433 int err;
434
435 err = reg_raw_read(codec, reg, val);
436 if (err == -EAGAIN) {
437 snd_hdac_power_up_pm(codec);
438 err = reg_raw_read(codec, reg, val);
439 snd_hdac_power_down_pm(codec);
440 }
441 return err;
442}
443EXPORT_SYMBOL_GPL(snd_hdac_regmap_read_raw);
444
445/**
446 * snd_hdac_regmap_update_raw - update a pseudo register with power mgmt
447 * @codec: the codec object
448 * @reg: pseudo register
449 * @mask: bit mask to udpate
450 * @val: value to update
451 *
452 * Returns zero if successful or a negative error code.
453 */
454int snd_hdac_regmap_update_raw(struct hdac_device *codec, unsigned int reg,
455 unsigned int mask, unsigned int val)
456{
457 unsigned int orig;
458 int err;
459
460 val &= mask;
461 err = snd_hdac_regmap_read_raw(codec, reg, &orig);
462 if (err < 0)
463 return err;
464 val |= orig & ~mask;
465 if (val == orig)
466 return 0;
467 err = snd_hdac_regmap_write_raw(codec, reg, val);
468 if (err < 0)
469 return err;
470 return 1;
471}
472EXPORT_SYMBOL_GPL(snd_hdac_regmap_update_raw);
diff --git a/sound/hda/hdac_sysfs.c b/sound/hda/hdac_sysfs.c
new file mode 100644
index 000000000000..0a6ce3b84cc4
--- /dev/null
+++ b/sound/hda/hdac_sysfs.c
@@ -0,0 +1,406 @@
1/*
2 * sysfs support for HD-audio core device
3 */
4
5#include <linux/slab.h>
6#include <linux/sysfs.h>
7#include <linux/device.h>
8#include <sound/core.h>
9#include <sound/hdaudio.h>
10#include "local.h"
11
12struct hdac_widget_tree {
13 struct kobject *root;
14 struct kobject *afg;
15 struct kobject **nodes;
16};
17
18#define CODEC_ATTR(type) \
19static ssize_t type##_show(struct device *dev, \
20 struct device_attribute *attr, \
21 char *buf) \
22{ \
23 struct hdac_device *codec = dev_to_hdac_dev(dev); \
24 return sprintf(buf, "0x%x\n", codec->type); \
25} \
26static DEVICE_ATTR_RO(type)
27
28#define CODEC_ATTR_STR(type) \
29static ssize_t type##_show(struct device *dev, \
30 struct device_attribute *attr, \
31 char *buf) \
32{ \
33 struct hdac_device *codec = dev_to_hdac_dev(dev); \
34 return sprintf(buf, "%s\n", \
35 codec->type ? codec->type : ""); \
36} \
37static DEVICE_ATTR_RO(type)
38
39CODEC_ATTR(type);
40CODEC_ATTR(vendor_id);
41CODEC_ATTR(subsystem_id);
42CODEC_ATTR(revision_id);
43CODEC_ATTR(afg);
44CODEC_ATTR(mfg);
45CODEC_ATTR_STR(vendor_name);
46CODEC_ATTR_STR(chip_name);
47
48static struct attribute *hdac_dev_attrs[] = {
49 &dev_attr_type.attr,
50 &dev_attr_vendor_id.attr,
51 &dev_attr_subsystem_id.attr,
52 &dev_attr_revision_id.attr,
53 &dev_attr_afg.attr,
54 &dev_attr_mfg.attr,
55 &dev_attr_vendor_name.attr,
56 &dev_attr_chip_name.attr,
57 NULL
58};
59
60static struct attribute_group hdac_dev_attr_group = {
61 .attrs = hdac_dev_attrs,
62};
63
64const struct attribute_group *hdac_dev_attr_groups[] = {
65 &hdac_dev_attr_group,
66 NULL
67};
68
69/*
70 * Widget tree sysfs
71 *
72 * This is a tree showing the attributes of each widget. It appears like
73 * /sys/bus/hdaudioC0D0/widgets/04/caps
74 */
75
76struct widget_attribute;
77
78struct widget_attribute {
79 struct attribute attr;
80 ssize_t (*show)(struct hdac_device *codec, hda_nid_t nid,
81 struct widget_attribute *attr, char *buf);
82 ssize_t (*store)(struct hdac_device *codec, hda_nid_t nid,
83 struct widget_attribute *attr,
84 const char *buf, size_t count);
85};
86
87static int get_codec_nid(struct kobject *kobj, struct hdac_device **codecp)
88{
89 struct device *dev = kobj_to_dev(kobj->parent->parent);
90 int nid;
91 ssize_t ret;
92
93 ret = kstrtoint(kobj->name, 16, &nid);
94 if (ret < 0)
95 return ret;
96 *codecp = dev_to_hdac_dev(dev);
97 return nid;
98}
99
100static ssize_t widget_attr_show(struct kobject *kobj, struct attribute *attr,
101 char *buf)
102{
103 struct widget_attribute *wid_attr =
104 container_of(attr, struct widget_attribute, attr);
105 struct hdac_device *codec;
106 int nid;
107
108 if (!wid_attr->show)
109 return -EIO;
110 nid = get_codec_nid(kobj, &codec);
111 if (nid < 0)
112 return nid;
113 return wid_attr->show(codec, nid, wid_attr, buf);
114}
115
116static ssize_t widget_attr_store(struct kobject *kobj, struct attribute *attr,
117 const char *buf, size_t count)
118{
119 struct widget_attribute *wid_attr =
120 container_of(attr, struct widget_attribute, attr);
121 struct hdac_device *codec;
122 int nid;
123
124 if (!wid_attr->store)
125 return -EIO;
126 nid = get_codec_nid(kobj, &codec);
127 if (nid < 0)
128 return nid;
129 return wid_attr->store(codec, nid, wid_attr, buf, count);
130}
131
132static const struct sysfs_ops widget_sysfs_ops = {
133 .show = widget_attr_show,
134 .store = widget_attr_store,
135};
136
137static void widget_release(struct kobject *kobj)
138{
139 kfree(kobj);
140}
141
142static struct kobj_type widget_ktype = {
143 .release = widget_release,
144 .sysfs_ops = &widget_sysfs_ops,
145};
146
147#define WIDGET_ATTR_RO(_name) \
148 struct widget_attribute wid_attr_##_name = __ATTR_RO(_name)
149#define WIDGET_ATTR_RW(_name) \
150 struct widget_attribute wid_attr_##_name = __ATTR_RW(_name)
151
152static ssize_t caps_show(struct hdac_device *codec, hda_nid_t nid,
153 struct widget_attribute *attr, char *buf)
154{
155 return sprintf(buf, "0x%08x\n", get_wcaps(codec, nid));
156}
157
158static ssize_t pin_caps_show(struct hdac_device *codec, hda_nid_t nid,
159 struct widget_attribute *attr, char *buf)
160{
161 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
162 return 0;
163 return sprintf(buf, "0x%08x\n",
164 snd_hdac_read_parm(codec, nid, AC_PAR_PIN_CAP));
165}
166
167static ssize_t pin_cfg_show(struct hdac_device *codec, hda_nid_t nid,
168 struct widget_attribute *attr, char *buf)
169{
170 unsigned int val;
171
172 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
173 return 0;
174 if (snd_hdac_read(codec, nid, AC_VERB_GET_CONFIG_DEFAULT, 0, &val))
175 return 0;
176 return sprintf(buf, "0x%08x\n", val);
177}
178
179static bool has_pcm_cap(struct hdac_device *codec, hda_nid_t nid)
180{
181 if (nid == codec->afg || nid == codec->mfg)
182 return true;
183 switch (get_wcaps_type(get_wcaps(codec, nid))) {
184 case AC_WID_AUD_OUT:
185 case AC_WID_AUD_IN:
186 return true;
187 default:
188 return false;
189 }
190}
191
192static ssize_t pcm_caps_show(struct hdac_device *codec, hda_nid_t nid,
193 struct widget_attribute *attr, char *buf)
194{
195 if (!has_pcm_cap(codec, nid))
196 return 0;
197 return sprintf(buf, "0x%08x\n",
198 snd_hdac_read_parm(codec, nid, AC_PAR_PCM));
199}
200
201static ssize_t pcm_formats_show(struct hdac_device *codec, hda_nid_t nid,
202 struct widget_attribute *attr, char *buf)
203{
204 if (!has_pcm_cap(codec, nid))
205 return 0;
206 return sprintf(buf, "0x%08x\n",
207 snd_hdac_read_parm(codec, nid, AC_PAR_STREAM));
208}
209
210static ssize_t amp_in_caps_show(struct hdac_device *codec, hda_nid_t nid,
211 struct widget_attribute *attr, char *buf)
212{
213 if (nid != codec->afg && !(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
214 return 0;
215 return sprintf(buf, "0x%08x\n",
216 snd_hdac_read_parm(codec, nid, AC_PAR_AMP_IN_CAP));
217}
218
219static ssize_t amp_out_caps_show(struct hdac_device *codec, hda_nid_t nid,
220 struct widget_attribute *attr, char *buf)
221{
222 if (nid != codec->afg && !(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
223 return 0;
224 return sprintf(buf, "0x%08x\n",
225 snd_hdac_read_parm(codec, nid, AC_PAR_AMP_OUT_CAP));
226}
227
228static ssize_t power_caps_show(struct hdac_device *codec, hda_nid_t nid,
229 struct widget_attribute *attr, char *buf)
230{
231 if (nid != codec->afg && !(get_wcaps(codec, nid) & AC_WCAP_POWER))
232 return 0;
233 return sprintf(buf, "0x%08x\n",
234 snd_hdac_read_parm(codec, nid, AC_PAR_POWER_STATE));
235}
236
237static ssize_t gpio_caps_show(struct hdac_device *codec, hda_nid_t nid,
238 struct widget_attribute *attr, char *buf)
239{
240 return sprintf(buf, "0x%08x\n",
241 snd_hdac_read_parm(codec, nid, AC_PAR_GPIO_CAP));
242}
243
244static ssize_t connections_show(struct hdac_device *codec, hda_nid_t nid,
245 struct widget_attribute *attr, char *buf)
246{
247 hda_nid_t list[32];
248 int i, nconns;
249 ssize_t ret = 0;
250
251 nconns = snd_hdac_get_connections(codec, nid, list, ARRAY_SIZE(list));
252 if (nconns <= 0)
253 return nconns;
254 for (i = 0; i < nconns; i++)
255 ret += sprintf(buf + ret, "%s0x%02x", i ? " " : "", list[i]);
256 ret += sprintf(buf + ret, "\n");
257 return ret;
258}
259
260static WIDGET_ATTR_RO(caps);
261static WIDGET_ATTR_RO(pin_caps);
262static WIDGET_ATTR_RO(pin_cfg);
263static WIDGET_ATTR_RO(pcm_caps);
264static WIDGET_ATTR_RO(pcm_formats);
265static WIDGET_ATTR_RO(amp_in_caps);
266static WIDGET_ATTR_RO(amp_out_caps);
267static WIDGET_ATTR_RO(power_caps);
268static WIDGET_ATTR_RO(gpio_caps);
269static WIDGET_ATTR_RO(connections);
270
271static struct attribute *widget_node_attrs[] = {
272 &wid_attr_caps.attr,
273 &wid_attr_pin_caps.attr,
274 &wid_attr_pin_cfg.attr,
275 &wid_attr_pcm_caps.attr,
276 &wid_attr_pcm_formats.attr,
277 &wid_attr_amp_in_caps.attr,
278 &wid_attr_amp_out_caps.attr,
279 &wid_attr_power_caps.attr,
280 &wid_attr_connections.attr,
281 NULL,
282};
283
284static struct attribute *widget_afg_attrs[] = {
285 &wid_attr_pcm_caps.attr,
286 &wid_attr_pcm_formats.attr,
287 &wid_attr_amp_in_caps.attr,
288 &wid_attr_amp_out_caps.attr,
289 &wid_attr_power_caps.attr,
290 &wid_attr_gpio_caps.attr,
291 NULL,
292};
293
294static const struct attribute_group widget_node_group = {
295 .attrs = widget_node_attrs,
296};
297
298static const struct attribute_group widget_afg_group = {
299 .attrs = widget_afg_attrs,
300};
301
302static void free_widget_node(struct kobject *kobj,
303 const struct attribute_group *group)
304{
305 if (kobj) {
306 sysfs_remove_group(kobj, group);
307 kobject_put(kobj);
308 }
309}
310
311static void widget_tree_free(struct hdac_device *codec)
312{
313 struct hdac_widget_tree *tree = codec->widgets;
314 struct kobject **p;
315
316 if (!tree)
317 return;
318 free_widget_node(tree->afg, &widget_afg_group);
319 if (tree->nodes) {
320 for (p = tree->nodes; *p; p++)
321 free_widget_node(*p, &widget_node_group);
322 kfree(tree->nodes);
323 }
324 if (tree->root)
325 kobject_put(tree->root);
326 kfree(tree);
327 codec->widgets = NULL;
328}
329
330static int add_widget_node(struct kobject *parent, hda_nid_t nid,
331 const struct attribute_group *group,
332 struct kobject **res)
333{
334 struct kobject *kobj = kzalloc(sizeof(*kobj), GFP_KERNEL);
335 int err;
336
337 if (!kobj)
338 return -ENOMEM;
339 kobject_init(kobj, &widget_ktype);
340 err = kobject_add(kobj, parent, "%02x", nid);
341 if (err < 0)
342 return err;
343 err = sysfs_create_group(kobj, group);
344 if (err < 0) {
345 kobject_put(kobj);
346 return err;
347 }
348
349 *res = kobj;
350 return 0;
351}
352
353static int widget_tree_create(struct hdac_device *codec)
354{
355 struct hdac_widget_tree *tree;
356 int i, err;
357 hda_nid_t nid;
358
359 tree = codec->widgets = kzalloc(sizeof(*tree), GFP_KERNEL);
360 if (!tree)
361 return -ENOMEM;
362
363 tree->root = kobject_create_and_add("widgets", &codec->dev.kobj);
364 if (!tree->root)
365 return -ENOMEM;
366
367 tree->nodes = kcalloc(codec->num_nodes + 1, sizeof(*tree->nodes),
368 GFP_KERNEL);
369 if (!tree->nodes)
370 return -ENOMEM;
371
372 for (i = 0, nid = codec->start_nid; i < codec->num_nodes; i++, nid++) {
373 err = add_widget_node(tree->root, nid, &widget_node_group,
374 &tree->nodes[i]);
375 if (err < 0)
376 return err;
377 }
378
379 if (codec->afg) {
380 err = add_widget_node(tree->root, codec->afg,
381 &widget_afg_group, &tree->afg);
382 if (err < 0)
383 return err;
384 }
385
386 kobject_uevent(tree->root, KOBJ_CHANGE);
387 return 0;
388}
389
390int hda_widget_sysfs_init(struct hdac_device *codec)
391{
392 int err;
393
394 err = widget_tree_create(codec);
395 if (err < 0) {
396 widget_tree_free(codec);
397 return err;
398 }
399
400 return 0;
401}
402
403void hda_widget_sysfs_exit(struct hdac_device *codec)
404{
405 widget_tree_free(codec);
406}
diff --git a/sound/hda/local.h b/sound/hda/local.h
new file mode 100644
index 000000000000..d692f417ddc0
--- /dev/null
+++ b/sound/hda/local.h
@@ -0,0 +1,23 @@
1/*
2 * Local helper macros and functions for HD-audio core drivers
3 */
4
5#ifndef __HDAC_LOCAL_H
6#define __HDAC_LOCAL_H
7
8#define get_wcaps(codec, nid) \
9 snd_hdac_read_parm(codec, nid, AC_PAR_AUDIO_WIDGET_CAP)
10
11/* get the widget type from widget capability bits */
12static inline int get_wcaps_type(unsigned int wcaps)
13{
14 if (!wcaps)
15 return -1; /* invalid type */
16 return (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
17}
18
19extern const struct attribute_group *hdac_dev_attr_groups[];
20int hda_widget_sysfs_init(struct hdac_device *codec);
21void hda_widget_sysfs_exit(struct hdac_device *codec);
22
23#endif /* __HDAC_LOCAL_H */
diff --git a/sound/hda/trace.c b/sound/hda/trace.c
new file mode 100644
index 000000000000..ca2d6bd94518
--- /dev/null
+++ b/sound/hda/trace.c
@@ -0,0 +1,6 @@
1/*
2 * tracepoint definitions for HD-audio core drivers
3 */
4
5#define CREATE_TRACE_POINTS
6#include "trace.h"
diff --git a/sound/hda/trace.h b/sound/hda/trace.h
new file mode 100644
index 000000000000..33a7eb5573d4
--- /dev/null
+++ b/sound/hda/trace.h
@@ -0,0 +1,62 @@
1#undef TRACE_SYSTEM
2#define TRACE_SYSTEM hda
3
4#if !defined(__HDAC_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
5#define __HDAC_TRACE_H
6
7#include <linux/tracepoint.h>
8#include <linux/device.h>
9#include <sound/hdaudio.h>
10
11#ifndef HDAC_MSG_MAX
12#define HDAC_MSG_MAX 500
13#endif
14
15struct hdac_bus;
16struct hdac_codec;
17
18TRACE_EVENT(hda_send_cmd,
19 TP_PROTO(struct hdac_bus *bus, unsigned int cmd),
20 TP_ARGS(bus, cmd),
21 TP_STRUCT__entry(__dynamic_array(char, msg, HDAC_MSG_MAX)),
22 TP_fast_assign(
23 snprintf(__get_str(msg), HDAC_MSG_MAX,
24 "[%s:%d] val=0x%08x",
25 dev_name((bus)->dev), (cmd) >> 28, cmd);
26 ),
27 TP_printk("%s", __get_str(msg))
28);
29
30TRACE_EVENT(hda_get_response,
31 TP_PROTO(struct hdac_bus *bus, unsigned int addr, unsigned int res),
32 TP_ARGS(bus, addr, res),
33 TP_STRUCT__entry(__dynamic_array(char, msg, HDAC_MSG_MAX)),
34 TP_fast_assign(
35 snprintf(__get_str(msg), HDAC_MSG_MAX,
36 "[%s:%d] val=0x%08x",
37 dev_name((bus)->dev), addr, res);
38 ),
39 TP_printk("%s", __get_str(msg))
40);
41
42TRACE_EVENT(hda_unsol_event,
43 TP_PROTO(struct hdac_bus *bus, u32 res, u32 res_ex),
44 TP_ARGS(bus, res, res_ex),
45 TP_STRUCT__entry(__dynamic_array(char, msg, HDAC_MSG_MAX)),
46 TP_fast_assign(
47 snprintf(__get_str(msg), HDAC_MSG_MAX,
48 "[%s:%d] res=0x%08x, res_ex=0x%08x",
49 dev_name((bus)->dev), res_ex & 0x0f, res, res_ex);
50 ),
51 TP_printk("%s", __get_str(msg))
52);
53#endif /* __HDAC_TRACE_H */
54
55/* This part must be outside protection */
56#undef TRACE_INCLUDE_PATH
57#define TRACE_INCLUDE_PATH .
58
59#undef TRACE_INCLUDE_FILE
60#define TRACE_INCLUDE_FILE trace
61
62#include <trace/define_trace.h>
diff --git a/sound/i2c/other/ak4113.c b/sound/i2c/other/ak4113.c
index 88844881cbff..2183e9ebaa6d 100644
--- a/sound/i2c/other/ak4113.c
+++ b/sound/i2c/other/ak4113.c
@@ -73,7 +73,7 @@ int snd_ak4113_create(struct snd_card *card, ak4113_read_t *read,
73 void *private_data, struct ak4113 **r_ak4113) 73 void *private_data, struct ak4113 **r_ak4113)
74{ 74{
75 struct ak4113 *chip; 75 struct ak4113 *chip;
76 int err = 0; 76 int err;
77 unsigned char reg; 77 unsigned char reg;
78 static struct snd_device_ops ops = { 78 static struct snd_device_ops ops = {
79 .dev_free = snd_ak4113_dev_free, 79 .dev_free = snd_ak4113_dev_free,
@@ -109,7 +109,7 @@ int snd_ak4113_create(struct snd_card *card, ak4113_read_t *read,
109 109
110__fail: 110__fail:
111 snd_ak4113_free(chip); 111 snd_ak4113_free(chip);
112 return err < 0 ? err : -EIO; 112 return err;
113} 113}
114EXPORT_SYMBOL_GPL(snd_ak4113_create); 114EXPORT_SYMBOL_GPL(snd_ak4113_create);
115 115
diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
index 72332dfada9a..4aa719cad331 100644
--- a/sound/isa/sb/emu8000_synth.c
+++ b/sound/isa/sb/emu8000_synth.c
@@ -34,8 +34,9 @@ MODULE_LICENSE("GPL");
34/* 34/*
35 * create a new hardware dependent device for Emu8000 35 * create a new hardware dependent device for Emu8000
36 */ 36 */
37static int snd_emu8000_new_device(struct snd_seq_device *dev) 37static int snd_emu8000_probe(struct device *_dev)
38{ 38{
39 struct snd_seq_device *dev = to_seq_dev(_dev);
39 struct snd_emu8000 *hw; 40 struct snd_emu8000 *hw;
40 struct snd_emux *emu; 41 struct snd_emux *emu;
41 42
@@ -93,8 +94,9 @@ static int snd_emu8000_new_device(struct snd_seq_device *dev)
93/* 94/*
94 * free all resources 95 * free all resources
95 */ 96 */
96static int snd_emu8000_delete_device(struct snd_seq_device *dev) 97static int snd_emu8000_remove(struct device *_dev)
97{ 98{
99 struct snd_seq_device *dev = to_seq_dev(_dev);
98 struct snd_emu8000 *hw; 100 struct snd_emu8000 *hw;
99 101
100 if (dev->driver_data == NULL) 102 if (dev->driver_data == NULL)
@@ -114,21 +116,14 @@ static int snd_emu8000_delete_device(struct snd_seq_device *dev)
114 * INIT part 116 * INIT part
115 */ 117 */
116 118
117static int __init alsa_emu8000_init(void) 119static struct snd_seq_driver emu8000_driver = {
118{ 120 .driver = {
119 121 .name = KBUILD_MODNAME,
120 static struct snd_seq_dev_ops ops = { 122 .probe = snd_emu8000_probe,
121 snd_emu8000_new_device, 123 .remove = snd_emu8000_remove,
122 snd_emu8000_delete_device, 124 },
123 }; 125 .id = SNDRV_SEQ_DEV_ID_EMU8000,
124 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops, 126 .argsize = sizeof(struct snd_emu8000 *),
125 sizeof(struct snd_emu8000*)); 127};
126} 128
127 129module_snd_seq_driver(emu8000_driver);
128static void __exit alsa_emu8000_exit(void)
129{
130 snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_EMU8000);
131}
132
133module_init(alsa_emu8000_init)
134module_exit(alsa_emu8000_exit)
diff --git a/sound/isa/wavefront/wavefront_fx.c b/sound/isa/wavefront/wavefront_fx.c
index b5a19708473a..0608a5a4289d 100644
--- a/sound/isa/wavefront/wavefront_fx.c
+++ b/sound/isa/wavefront/wavefront_fx.c
@@ -79,13 +79,13 @@ wavefront_fx_memset (snd_wavefront_t *dev,
79 if (page < 0 || page > 7) { 79 if (page < 0 || page > 7) {
80 snd_printk ("FX memset: " 80 snd_printk ("FX memset: "
81 "page must be >= 0 and <= 7\n"); 81 "page must be >= 0 and <= 7\n");
82 return -(EINVAL); 82 return -EINVAL;
83 } 83 }
84 84
85 if (addr < 0 || addr > 0x7f) { 85 if (addr < 0 || addr > 0x7f) {
86 snd_printk ("FX memset: " 86 snd_printk ("FX memset: "
87 "addr must be >= 0 and <= 7f\n"); 87 "addr must be >= 0 and <= 7f\n");
88 return -(EINVAL); 88 return -EINVAL;
89 } 89 }
90 90
91 if (cnt == 1) { 91 if (cnt == 1) {
@@ -118,7 +118,7 @@ wavefront_fx_memset (snd_wavefront_t *dev,
118 snd_printk ("FX memset " 118 snd_printk ("FX memset "
119 "(0x%x, 0x%x, 0x%lx, %d) incomplete\n", 119 "(0x%x, 0x%x, 0x%lx, %d) incomplete\n",
120 page, addr, (unsigned long) data, cnt); 120 page, addr, (unsigned long) data, cnt);
121 return -(EIO); 121 return -EIO;
122 } 122 }
123 } 123 }
124 124
diff --git a/sound/isa/wavefront/wavefront_synth.c b/sound/isa/wavefront/wavefront_synth.c
index 33f5ec14fcfa..69f76ff5693d 100644
--- a/sound/isa/wavefront/wavefront_synth.c
+++ b/sound/isa/wavefront/wavefront_synth.c
@@ -793,7 +793,7 @@ wavefront_send_patch (snd_wavefront_t *dev, wavefront_patch_info *header)
793 793
794 if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_PATCH, NULL, buf)) { 794 if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_PATCH, NULL, buf)) {
795 snd_printk ("download patch failed\n"); 795 snd_printk ("download patch failed\n");
796 return -(EIO); 796 return -EIO;
797 } 797 }
798 798
799 return (0); 799 return (0);
@@ -831,7 +831,7 @@ wavefront_send_program (snd_wavefront_t *dev, wavefront_patch_info *header)
831 831
832 if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_PROGRAM, NULL, buf)) { 832 if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_PROGRAM, NULL, buf)) {
833 snd_printk ("download patch failed\n"); 833 snd_printk ("download patch failed\n");
834 return -(EIO); 834 return -EIO;
835 } 835 }
836 836
837 return (0); 837 return (0);
@@ -952,7 +952,7 @@ wavefront_send_sample (snd_wavefront_t *dev,
952 if (skip > 0 && header->hdr.s.SampleResolution != LINEAR_16BIT) { 952 if (skip > 0 && header->hdr.s.SampleResolution != LINEAR_16BIT) {
953 snd_printk ("channel selection only " 953 snd_printk ("channel selection only "
954 "possible on 16-bit samples"); 954 "possible on 16-bit samples");
955 return -(EINVAL); 955 return -EINVAL;
956 } 956 }
957 957
958 switch (skip) { 958 switch (skip) {
@@ -1049,7 +1049,7 @@ wavefront_send_sample (snd_wavefront_t *dev,
1049 NULL, sample_hdr)) { 1049 NULL, sample_hdr)) {
1050 snd_printk ("sample %sdownload refused.\n", 1050 snd_printk ("sample %sdownload refused.\n",
1051 header->size ? "" : "header "); 1051 header->size ? "" : "header ");
1052 return -(EIO); 1052 return -EIO;
1053 } 1053 }
1054 1054
1055 if (header->size == 0) { 1055 if (header->size == 0) {
@@ -1075,7 +1075,7 @@ wavefront_send_sample (snd_wavefront_t *dev,
1075 if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_BLOCK, NULL, NULL)) { 1075 if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_BLOCK, NULL, NULL)) {
1076 snd_printk ("download block " 1076 snd_printk ("download block "
1077 "request refused.\n"); 1077 "request refused.\n");
1078 return -(EIO); 1078 return -EIO;
1079 } 1079 }
1080 1080
1081 for (i = 0; i < blocksize; i++) { 1081 for (i = 0; i < blocksize; i++) {
@@ -1135,12 +1135,12 @@ wavefront_send_sample (snd_wavefront_t *dev,
1135 if (dma_ack == -1) { 1135 if (dma_ack == -1) {
1136 snd_printk ("upload sample " 1136 snd_printk ("upload sample "
1137 "DMA ack timeout\n"); 1137 "DMA ack timeout\n");
1138 return -(EIO); 1138 return -EIO;
1139 } else { 1139 } else {
1140 snd_printk ("upload sample " 1140 snd_printk ("upload sample "
1141 "DMA ack error 0x%x\n", 1141 "DMA ack error 0x%x\n",
1142 dma_ack); 1142 dma_ack);
1143 return -(EIO); 1143 return -EIO;
1144 } 1144 }
1145 } 1145 }
1146 } 1146 }
@@ -1181,7 +1181,7 @@ wavefront_send_alias (snd_wavefront_t *dev, wavefront_patch_info *header)
1181 1181
1182 if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_SAMPLE_ALIAS, NULL, alias_hdr)) { 1182 if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_SAMPLE_ALIAS, NULL, alias_hdr)) {
1183 snd_printk ("download alias failed.\n"); 1183 snd_printk ("download alias failed.\n");
1184 return -(EIO); 1184 return -EIO;
1185 } 1185 }
1186 1186
1187 dev->sample_status[header->number] = (WF_SLOT_FILLED|WF_ST_ALIAS); 1187 dev->sample_status[header->number] = (WF_SLOT_FILLED|WF_ST_ALIAS);
@@ -1232,7 +1232,7 @@ wavefront_send_multisample (snd_wavefront_t *dev, wavefront_patch_info *header)
1232 msample_hdr)) { 1232 msample_hdr)) {
1233 snd_printk ("download of multisample failed.\n"); 1233 snd_printk ("download of multisample failed.\n");
1234 kfree(msample_hdr); 1234 kfree(msample_hdr);
1235 return -(EIO); 1235 return -EIO;
1236 } 1236 }
1237 1237
1238 dev->sample_status[header->number] = (WF_SLOT_FILLED|WF_ST_MULTISAMPLE); 1238 dev->sample_status[header->number] = (WF_SLOT_FILLED|WF_ST_MULTISAMPLE);
@@ -1254,7 +1254,7 @@ wavefront_fetch_multisample (snd_wavefront_t *dev,
1254 1254
1255 if (snd_wavefront_cmd (dev, WFC_UPLOAD_MULTISAMPLE, log_ns, number)) { 1255 if (snd_wavefront_cmd (dev, WFC_UPLOAD_MULTISAMPLE, log_ns, number)) {
1256 snd_printk ("upload multisample failed.\n"); 1256 snd_printk ("upload multisample failed.\n");
1257 return -(EIO); 1257 return -EIO;
1258 } 1258 }
1259 1259
1260 DPRINT (WF_DEBUG_DATA, "msample %d has %d samples\n", 1260 DPRINT (WF_DEBUG_DATA, "msample %d has %d samples\n",
@@ -1273,14 +1273,14 @@ wavefront_fetch_multisample (snd_wavefront_t *dev,
1273 if ((val = wavefront_read (dev)) == -1) { 1273 if ((val = wavefront_read (dev)) == -1) {
1274 snd_printk ("upload multisample failed " 1274 snd_printk ("upload multisample failed "
1275 "during sample loop.\n"); 1275 "during sample loop.\n");
1276 return -(EIO); 1276 return -EIO;
1277 } 1277 }
1278 d[0] = val; 1278 d[0] = val;
1279 1279
1280 if ((val = wavefront_read (dev)) == -1) { 1280 if ((val = wavefront_read (dev)) == -1) {
1281 snd_printk ("upload multisample failed " 1281 snd_printk ("upload multisample failed "
1282 "during sample loop.\n"); 1282 "during sample loop.\n");
1283 return -(EIO); 1283 return -EIO;
1284 } 1284 }
1285 d[1] = val; 1285 d[1] = val;
1286 1286
@@ -1315,7 +1315,7 @@ wavefront_send_drum (snd_wavefront_t *dev, wavefront_patch_info *header)
1315 1315
1316 if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_EDRUM_PROGRAM, NULL, drumbuf)) { 1316 if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_EDRUM_PROGRAM, NULL, drumbuf)) {
1317 snd_printk ("download drum failed.\n"); 1317 snd_printk ("download drum failed.\n");
1318 return -(EIO); 1318 return -EIO;
1319 } 1319 }
1320 1320
1321 return (0); 1321 return (0);
diff --git a/sound/mips/au1x00.c b/sound/mips/au1x00.c
index fbcaa5434fd8..1e30e8475431 100644
--- a/sound/mips/au1x00.c
+++ b/sound/mips/au1x00.c
@@ -633,19 +633,25 @@ static int au1000_ac97_probe(struct platform_device *pdev)
633 633
634 au1000->stream[PLAYBACK] = kmalloc(sizeof(struct audio_stream), 634 au1000->stream[PLAYBACK] = kmalloc(sizeof(struct audio_stream),
635 GFP_KERNEL); 635 GFP_KERNEL);
636 if (!au1000->stream[PLAYBACK]) 636 if (!au1000->stream[PLAYBACK]) {
637 err = -ENOMEM;
637 goto out; 638 goto out;
639 }
638 au1000->stream[PLAYBACK]->dma = -1; 640 au1000->stream[PLAYBACK]->dma = -1;
639 641
640 au1000->stream[CAPTURE] = kmalloc(sizeof(struct audio_stream), 642 au1000->stream[CAPTURE] = kmalloc(sizeof(struct audio_stream),
641 GFP_KERNEL); 643 GFP_KERNEL);
642 if (!au1000->stream[CAPTURE]) 644 if (!au1000->stream[CAPTURE]) {
645 err = -ENOMEM;
643 goto out; 646 goto out;
647 }
644 au1000->stream[CAPTURE]->dma = -1; 648 au1000->stream[CAPTURE]->dma = -1;
645 649
646 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 650 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
647 if (!r) 651 if (!r) {
652 err = -ENODEV;
648 goto out; 653 goto out;
654 }
649 655
650 err = -EBUSY; 656 err = -EBUSY;
651 au1000->ac97_res_port = request_mem_region(r->start, resource_size(r), 657 au1000->ac97_res_port = request_mem_region(r->start, resource_size(r),
diff --git a/sound/oss/dev_table.c b/sound/oss/dev_table.c
index d8cf3e58dc76..6dad51596b70 100644
--- a/sound/oss/dev_table.c
+++ b/sound/oss/dev_table.c
@@ -58,13 +58,13 @@ int sound_install_audiodrv(int vers, char *name, struct audio_driver *driver,
58 58
59 if (vers != AUDIO_DRIVER_VERSION || driver_size > sizeof(struct audio_driver)) { 59 if (vers != AUDIO_DRIVER_VERSION || driver_size > sizeof(struct audio_driver)) {
60 printk(KERN_ERR "Sound: Incompatible audio driver for %s\n", name); 60 printk(KERN_ERR "Sound: Incompatible audio driver for %s\n", name);
61 return -(EINVAL); 61 return -EINVAL;
62 } 62 }
63 num = sound_alloc_audiodev(); 63 num = sound_alloc_audiodev();
64 64
65 if (num == -1) { 65 if (num == -1) {
66 printk(KERN_ERR "sound: Too many audio drivers\n"); 66 printk(KERN_ERR "sound: Too many audio drivers\n");
67 return -(EBUSY); 67 return -EBUSY;
68 } 68 }
69 d = (struct audio_driver *) (sound_mem_blocks[sound_nblocks] = vmalloc(sizeof(struct audio_driver))); 69 d = (struct audio_driver *) (sound_mem_blocks[sound_nblocks] = vmalloc(sizeof(struct audio_driver)));
70 sound_nblocks++; 70 sound_nblocks++;
@@ -79,7 +79,7 @@ int sound_install_audiodrv(int vers, char *name, struct audio_driver *driver,
79 if (d == NULL || op == NULL) { 79 if (d == NULL || op == NULL) {
80 printk(KERN_ERR "Sound: Can't allocate driver for (%s)\n", name); 80 printk(KERN_ERR "Sound: Can't allocate driver for (%s)\n", name);
81 sound_unload_audiodev(num); 81 sound_unload_audiodev(num);
82 return -(ENOMEM); 82 return -ENOMEM;
83 } 83 }
84 init_waitqueue_head(&op->in_sleeper); 84 init_waitqueue_head(&op->in_sleeper);
85 init_waitqueue_head(&op->out_sleeper); 85 init_waitqueue_head(&op->out_sleeper);
diff --git a/sound/oss/opl3.c b/sound/oss/opl3.c
index 607cee4d545e..b6d19adf8f41 100644
--- a/sound/oss/opl3.c
+++ b/sound/oss/opl3.c
@@ -666,7 +666,7 @@ static int opl3_start_note (int dev, int voice, int note, int volume)
666 opl3_command(map->ioaddr, FNUM_LOW + map->voice_num, data); 666 opl3_command(map->ioaddr, FNUM_LOW + map->voice_num, data);
667 667
668 data = 0x20 | ((block & 0x7) << 2) | ((fnum >> 8) & 0x3); 668 data = 0x20 | ((block & 0x7) << 2) | ((fnum >> 8) & 0x3);
669 devc->voc[voice].keyon_byte = data; 669 devc->voc[voice].keyon_byte = data;
670 opl3_command(map->ioaddr, KEYON_BLOCK + map->voice_num, data); 670 opl3_command(map->ioaddr, KEYON_BLOCK + map->voice_num, data);
671 if (voice_mode == 4) 671 if (voice_mode == 4)
672 opl3_command(map->ioaddr, KEYON_BLOCK + map->voice_num + 3, data); 672 opl3_command(map->ioaddr, KEYON_BLOCK + map->voice_num + 3, data);
@@ -717,7 +717,7 @@ static void freq_to_fnum (int freq, int *block, int *fnum)
717 717
718static void opl3_command (int io_addr, unsigned int addr, unsigned int val) 718static void opl3_command (int io_addr, unsigned int addr, unsigned int val)
719{ 719{
720 int i; 720 int i;
721 721
722 /* 722 /*
723 * The original 2-OP synth requires a quite long delay after writing to a 723 * The original 2-OP synth requires a quite long delay after writing to a
diff --git a/sound/oss/sb_ess.c b/sound/oss/sb_ess.c
index b47a69026f1b..57f7d25a2cd3 100644
--- a/sound/oss/sb_ess.c
+++ b/sound/oss/sb_ess.c
@@ -604,7 +604,7 @@ static void ess_audio_output_block_audio2
604 ess_chgmixer (devc, 0x78, 0x03, 0x03); /* Go */ 604 ess_chgmixer (devc, 0x78, 0x03, 0x03); /* Go */
605 605
606 devc->irq_mode_16 = IMODE_OUTPUT; 606 devc->irq_mode_16 = IMODE_OUTPUT;
607 devc->intr_active_16 = 1; 607 devc->intr_active_16 = 1;
608} 608}
609 609
610static void ess_audio_output_block 610static void ess_audio_output_block
@@ -1183,17 +1183,12 @@ FKS_test (devc);
1183 chip = "ES1688"; 1183 chip = "ES1688";
1184 } 1184 }
1185 1185
1186 printk ( KERN_INFO "ESS chip %s %s%s\n" 1186 printk(KERN_INFO "ESS chip %s %s%s\n", chip,
1187 , chip 1187 (devc->sbmo.esstype == ESSTYPE_DETECT ||
1188 , ( devc->sbmo.esstype == ESSTYPE_DETECT || devc->sbmo.esstype == ESSTYPE_LIKE20 1188 devc->sbmo.esstype == ESSTYPE_LIKE20) ?
1189 ? "detected" 1189 "detected" : "specified",
1190 : "specified" 1190 devc->sbmo.esstype == ESSTYPE_LIKE20 ?
1191 ) 1191 " (kernel 2.0 compatible)" : "");
1192 , ( devc->sbmo.esstype == ESSTYPE_LIKE20
1193 ? " (kernel 2.0 compatible)"
1194 : ""
1195 )
1196 );
1197 1192
1198 sprintf(name,"ESS %s AudioDrive (rev %d)", chip, ess_minor & 0x0f); 1193 sprintf(name,"ESS %s AudioDrive (rev %d)", chip, ess_minor & 0x0f);
1199 } else { 1194 } else {
diff --git a/sound/oss/sb_midi.c b/sound/oss/sb_midi.c
index f139028e85c0..551ee7557b4e 100644
--- a/sound/oss/sb_midi.c
+++ b/sound/oss/sb_midi.c
@@ -179,14 +179,14 @@ void sb_dsp_midi_init(sb_devc * devc, struct module *owner)
179 { 179 {
180 printk(KERN_WARNING "Sound Blaster: failed to allocate MIDI memory.\n"); 180 printk(KERN_WARNING "Sound Blaster: failed to allocate MIDI memory.\n");
181 sound_unload_mididev(dev); 181 sound_unload_mididev(dev);
182 return; 182 return;
183 } 183 }
184 memcpy((char *) midi_devs[dev], (char *) &sb_midi_operations, 184 memcpy((char *) midi_devs[dev], (char *) &sb_midi_operations,
185 sizeof(struct midi_operations)); 185 sizeof(struct midi_operations));
186 186
187 if (owner) 187 if (owner)
188 midi_devs[dev]->owner = owner; 188 midi_devs[dev]->owner = owner;
189 189
190 midi_devs[dev]->devc = devc; 190 midi_devs[dev]->devc = devc;
191 191
192 192
diff --git a/sound/oss/sequencer.c b/sound/oss/sequencer.c
index c0eea1dfe90f..f19da4b47c1d 100644
--- a/sound/oss/sequencer.c
+++ b/sound/oss/sequencer.c
@@ -681,13 +681,8 @@ static int seq_timing_event(unsigned char *event_rec)
681 break; 681 break;
682 682
683 case TMR_ECHO: 683 case TMR_ECHO:
684 if (seq_mode == SEQ_2) 684 parm = (parm << 8 | SEQ_ECHO);
685 seq_copy_to_input(event_rec, 8); 685 seq_copy_to_input((unsigned char *) &parm, 4);
686 else
687 {
688 parm = (parm << 8 | SEQ_ECHO);
689 seq_copy_to_input((unsigned char *) &parm, 4);
690 }
691 break; 686 break;
692 687
693 default:; 688 default:;
@@ -1324,7 +1319,6 @@ int sequencer_ioctl(int dev, struct file *file, unsigned int cmd, void __user *a
1324 int mode = translate_mode(file); 1319 int mode = translate_mode(file);
1325 struct synth_info inf; 1320 struct synth_info inf;
1326 struct seq_event_rec event_rec; 1321 struct seq_event_rec event_rec;
1327 unsigned long flags;
1328 int __user *p = arg; 1322 int __user *p = arg;
1329 1323
1330 orig_dev = dev = dev >> 4; 1324 orig_dev = dev = dev >> 4;
@@ -1479,9 +1473,7 @@ int sequencer_ioctl(int dev, struct file *file, unsigned int cmd, void __user *a
1479 case SNDCTL_SEQ_OUTOFBAND: 1473 case SNDCTL_SEQ_OUTOFBAND:
1480 if (copy_from_user(&event_rec, arg, sizeof(event_rec))) 1474 if (copy_from_user(&event_rec, arg, sizeof(event_rec)))
1481 return -EFAULT; 1475 return -EFAULT;
1482 spin_lock_irqsave(&lock,flags);
1483 play_event(event_rec.arr); 1476 play_event(event_rec.arr);
1484 spin_unlock_irqrestore(&lock,flags);
1485 return 0; 1477 return 0;
1486 1478
1487 case SNDCTL_MIDI_INFO: 1479 case SNDCTL_MIDI_INFO:
diff --git a/sound/oss/sys_timer.c b/sound/oss/sys_timer.c
index 9f039831114c..2226dda0eff0 100644
--- a/sound/oss/sys_timer.c
+++ b/sound/oss/sys_timer.c
@@ -50,29 +50,24 @@ tmr2ticks(int tmr_value)
50static void 50static void
51poll_def_tmr(unsigned long dummy) 51poll_def_tmr(unsigned long dummy)
52{ 52{
53 if (!opened)
54 return;
55 def_tmr.expires = (1) + jiffies;
56 add_timer(&def_tmr);
53 57
54 if (opened) 58 if (!tmr_running)
55 { 59 return;
56 60
57 { 61 spin_lock(&lock);
58 def_tmr.expires = (1) + jiffies; 62 tmr_ctr++;
59 add_timer(&def_tmr); 63 curr_ticks = ticks_offs + tmr2ticks(tmr_ctr);
60 }
61 64
62 if (tmr_running) 65 if (curr_ticks >= next_event_time) {
63 { 66 next_event_time = (unsigned long) -1;
64 spin_lock(&lock); 67 sequencer_timer(0);
65 tmr_ctr++; 68 }
66 curr_ticks = ticks_offs + tmr2ticks(tmr_ctr); 69
67 70 spin_unlock(&lock);
68 if (curr_ticks >= next_event_time)
69 {
70 next_event_time = (unsigned long) -1;
71 sequencer_timer(0);
72 }
73 spin_unlock(&lock);
74 }
75 }
76} 71}
77 72
78static void 73static void
diff --git a/sound/oss/v_midi.c b/sound/oss/v_midi.c
index f0b4151d9b17..fc0ba276cc8f 100644
--- a/sound/oss/v_midi.c
+++ b/sound/oss/v_midi.c
@@ -49,13 +49,13 @@ static int v_midi_open (int dev, int mode,
49 unsigned long flags; 49 unsigned long flags;
50 50
51 if (devc == NULL) 51 if (devc == NULL)
52 return -(ENXIO); 52 return -ENXIO;
53 53
54 spin_lock_irqsave(&devc->lock,flags); 54 spin_lock_irqsave(&devc->lock,flags);
55 if (devc->opened) 55 if (devc->opened)
56 { 56 {
57 spin_unlock_irqrestore(&devc->lock,flags); 57 spin_unlock_irqrestore(&devc->lock,flags);
58 return -(EBUSY); 58 return -EBUSY;
59 } 59 }
60 devc->opened = 1; 60 devc->opened = 1;
61 spin_unlock_irqrestore(&devc->lock,flags); 61 spin_unlock_irqrestore(&devc->lock,flags);
diff --git a/sound/pci/ac97/ac97_codec.c b/sound/pci/ac97/ac97_codec.c
index 5ee2f17c287c..82259ca61e64 100644
--- a/sound/pci/ac97/ac97_codec.c
+++ b/sound/pci/ac97/ac97_codec.c
@@ -177,6 +177,7 @@ static const struct ac97_codec_id snd_ac97_codec_ids[] = {
177{ 0x54524123, 0xffffffff, "TR28602", NULL, NULL }, // only guess --jk [TR28023 = eMicro EM28023 (new CT1297)] 177{ 0x54524123, 0xffffffff, "TR28602", NULL, NULL }, // only guess --jk [TR28023 = eMicro EM28023 (new CT1297)]
178{ 0x54584e03, 0xffffffff, "TLV320AIC27", NULL, NULL }, 178{ 0x54584e03, 0xffffffff, "TLV320AIC27", NULL, NULL },
179{ 0x54584e20, 0xffffffff, "TLC320AD9xC", NULL, NULL }, 179{ 0x54584e20, 0xffffffff, "TLC320AD9xC", NULL, NULL },
180{ 0x56494120, 0xfffffff0, "VIA1613", patch_vt1613, NULL },
180{ 0x56494161, 0xffffffff, "VIA1612A", NULL, NULL }, // modified ICE1232 with S/PDIF 181{ 0x56494161, 0xffffffff, "VIA1612A", NULL, NULL }, // modified ICE1232 with S/PDIF
181{ 0x56494170, 0xffffffff, "VIA1617A", patch_vt1617a, NULL }, // modified VT1616 with S/PDIF 182{ 0x56494170, 0xffffffff, "VIA1617A", patch_vt1617a, NULL }, // modified VT1616 with S/PDIF
182{ 0x56494182, 0xffffffff, "VIA1618", patch_vt1618, NULL }, 183{ 0x56494182, 0xffffffff, "VIA1618", patch_vt1618, NULL },
@@ -2901,7 +2902,8 @@ static int apply_quirk_str(struct snd_ac97 *ac97, const char *typestr)
2901 * Return: Zero if successful, or a negative error code on failure. 2902 * Return: Zero if successful, or a negative error code on failure.
2902 */ 2903 */
2903 2904
2904int snd_ac97_tune_hardware(struct snd_ac97 *ac97, struct ac97_quirk *quirk, const char *override) 2905int snd_ac97_tune_hardware(struct snd_ac97 *ac97,
2906 const struct ac97_quirk *quirk, const char *override)
2905{ 2907{
2906 int result; 2908 int result;
2907 2909
diff --git a/sound/pci/ac97/ac97_patch.c b/sound/pci/ac97/ac97_patch.c
index ceaac1c41906..f4234edb878c 100644
--- a/sound/pci/ac97/ac97_patch.c
+++ b/sound/pci/ac97/ac97_patch.c
@@ -3352,6 +3352,33 @@ static int patch_cm9780(struct snd_ac97 *ac97)
3352} 3352}
3353 3353
3354/* 3354/*
3355 * VIA VT1613 codec
3356 */
3357static const struct snd_kcontrol_new snd_ac97_controls_vt1613[] = {
3358AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0),
3359};
3360
3361static int patch_vt1613_specific(struct snd_ac97 *ac97)
3362{
3363 return patch_build_controls(ac97, &snd_ac97_controls_vt1613[0],
3364 ARRAY_SIZE(snd_ac97_controls_vt1613));
3365};
3366
3367static const struct snd_ac97_build_ops patch_vt1613_ops = {
3368 .build_specific = patch_vt1613_specific
3369};
3370
3371static int patch_vt1613(struct snd_ac97 *ac97)
3372{
3373 ac97->build_ops = &patch_vt1613_ops;
3374
3375 ac97->flags |= AC97_HAS_NO_VIDEO;
3376 ac97->caps |= AC97_BC_HEADPHONE;
3377
3378 return 0;
3379}
3380
3381/*
3355 * VIA VT1616 codec 3382 * VIA VT1616 codec
3356 */ 3383 */
3357static const struct snd_kcontrol_new snd_ac97_controls_vt1616[] = { 3384static const struct snd_kcontrol_new snd_ac97_controls_vt1616[] = {
diff --git a/sound/pci/ad1889.c b/sound/pci/ad1889.c
index 850a8c984c25..66ddd981d1d5 100644
--- a/sound/pci/ad1889.c
+++ b/sound/pci/ad1889.c
@@ -747,7 +747,7 @@ snd_ad1889_proc_init(struct snd_ad1889 *chip)
747 snd_info_set_text_ops(entry, chip, snd_ad1889_proc_read); 747 snd_info_set_text_ops(entry, chip, snd_ad1889_proc_read);
748} 748}
749 749
750static struct ac97_quirk ac97_quirks[] = { 750static const struct ac97_quirk ac97_quirks[] = {
751 { 751 {
752 .subvendor = 0x11d4, /* AD */ 752 .subvendor = 0x11d4, /* AD */
753 .subdevice = 0x1889, /* AD1889 */ 753 .subdevice = 0x1889, /* AD1889 */
diff --git a/sound/pci/asihpi/asihpi.c b/sound/pci/asihpi/asihpi.c
index e5cd7be85355..1039eccbb895 100644
--- a/sound/pci/asihpi/asihpi.c
+++ b/sound/pci/asihpi/asihpi.c
@@ -2376,7 +2376,7 @@ static int snd_asihpi_cmode_add(struct snd_card_asihpi *asihpi,
2376/*------------------------------------------------------------ 2376/*------------------------------------------------------------
2377 Sampleclock source controls 2377 Sampleclock source controls
2378 ------------------------------------------------------------*/ 2378 ------------------------------------------------------------*/
2379static const char const *sampleclock_sources[] = { 2379static const char * const sampleclock_sources[] = {
2380 "N/A", "Local PLL", "Digital Sync", "Word External", "Word Header", 2380 "N/A", "Local PLL", "Digital Sync", "Word External", "Word Header",
2381 "SMPTE", "Digital1", "Auto", "Network", "Invalid", 2381 "SMPTE", "Digital1", "Auto", "Network", "Invalid",
2382 "Prev Module", "BLU-Link", 2382 "Prev Module", "BLU-Link",
diff --git a/sound/pci/atiixp.c b/sound/pci/atiixp.c
index d5f15c9bbeda..42a20c806b39 100644
--- a/sound/pci/atiixp.c
+++ b/sound/pci/atiixp.c
@@ -1390,7 +1390,7 @@ static irqreturn_t snd_atiixp_interrupt(int irq, void *dev_id)
1390 * ac97 mixer section 1390 * ac97 mixer section
1391 */ 1391 */
1392 1392
1393static struct ac97_quirk ac97_quirks[] = { 1393static const struct ac97_quirk ac97_quirks[] = {
1394 { 1394 {
1395 .subvendor = 0x103c, 1395 .subvendor = 0x103c,
1396 .subdevice = 0x006b, 1396 .subdevice = 0x006b,
diff --git a/sound/pci/azt3328.c b/sound/pci/azt3328.c
index a40a2b4c8fd7..33b2a0af1b59 100644
--- a/sound/pci/azt3328.c
+++ b/sound/pci/azt3328.c
@@ -1385,8 +1385,8 @@ snd_azf3328_ctrl_codec_activity(struct snd_azf3328 *chip,
1385 .running) 1385 .running)
1386 && (!chip->codecs[peer_codecs[codec_type].other2] 1386 && (!chip->codecs[peer_codecs[codec_type].other2]
1387 .running)); 1387 .running));
1388 } 1388 }
1389 if (call_function) 1389 if (call_function)
1390 snd_azf3328_ctrl_enable_codecs(chip, enable); 1390 snd_azf3328_ctrl_enable_codecs(chip, enable);
1391 1391
1392 /* ...and adjust clock, too 1392 /* ...and adjust clock, too
@@ -2126,7 +2126,8 @@ static struct snd_pcm_ops snd_azf3328_i2s_out_ops = {
2126static int 2126static int
2127snd_azf3328_pcm(struct snd_azf3328 *chip) 2127snd_azf3328_pcm(struct snd_azf3328 *chip)
2128{ 2128{
2129enum { AZF_PCMDEV_STD, AZF_PCMDEV_I2S_OUT, NUM_AZF_PCMDEVS }; /* pcm devices */ 2129 /* pcm devices */
2130 enum { AZF_PCMDEV_STD, AZF_PCMDEV_I2S_OUT, NUM_AZF_PCMDEVS };
2130 2131
2131 struct snd_pcm *pcm; 2132 struct snd_pcm *pcm;
2132 int err; 2133 int err;
diff --git a/sound/pci/cmipci.c b/sound/pci/cmipci.c
index 1d0f2cad2f5a..6cf464d9043d 100644
--- a/sound/pci/cmipci.c
+++ b/sound/pci/cmipci.c
@@ -2062,7 +2062,7 @@ static int snd_cmipci_get_volume(struct snd_kcontrol *kcontrol,
2062 val = (snd_cmipci_mixer_read(cm, reg.right_reg) >> reg.right_shift) & reg.mask; 2062 val = (snd_cmipci_mixer_read(cm, reg.right_reg) >> reg.right_shift) & reg.mask;
2063 if (reg.invert) 2063 if (reg.invert)
2064 val = reg.mask - val; 2064 val = reg.mask - val;
2065 ucontrol->value.integer.value[1] = val; 2065 ucontrol->value.integer.value[1] = val;
2066 } 2066 }
2067 spin_unlock_irq(&cm->reg_lock); 2067 spin_unlock_irq(&cm->reg_lock);
2068 return 0; 2068 return 0;
diff --git a/sound/pci/cs5535audio/cs5535audio.c b/sound/pci/cs5535audio/cs5535audio.c
index 802c33f1cc59..963b912550d4 100644
--- a/sound/pci/cs5535audio/cs5535audio.c
+++ b/sound/pci/cs5535audio/cs5535audio.c
@@ -43,7 +43,7 @@ static char *ac97_quirk;
43module_param(ac97_quirk, charp, 0444); 43module_param(ac97_quirk, charp, 0444);
44MODULE_PARM_DESC(ac97_quirk, "AC'97 board specific workarounds."); 44MODULE_PARM_DESC(ac97_quirk, "AC'97 board specific workarounds.");
45 45
46static struct ac97_quirk ac97_quirks[] = { 46static const struct ac97_quirk ac97_quirks[] = {
47#if 0 /* Not yet confirmed if all 5536 boards are HP only */ 47#if 0 /* Not yet confirmed if all 5536 boards are HP only */
48 { 48 {
49 .subvendor = PCI_VENDOR_ID_AMD, 49 .subvendor = PCI_VENDOR_ID_AMD,
diff --git a/sound/pci/echoaudio/echoaudio.c b/sound/pci/echoaudio/echoaudio.c
index a962de03ebb6..862db9a0b041 100644
--- a/sound/pci/echoaudio/echoaudio.c
+++ b/sound/pci/echoaudio/echoaudio.c
@@ -1283,12 +1283,14 @@ static int snd_echo_mixer_info(struct snd_kcontrol *kcontrol,
1283static int snd_echo_mixer_get(struct snd_kcontrol *kcontrol, 1283static int snd_echo_mixer_get(struct snd_kcontrol *kcontrol,
1284 struct snd_ctl_elem_value *ucontrol) 1284 struct snd_ctl_elem_value *ucontrol)
1285{ 1285{
1286 struct echoaudio *chip; 1286 struct echoaudio *chip = snd_kcontrol_chip(kcontrol);
1287 unsigned int out = ucontrol->id.index / num_busses_in(chip);
1288 unsigned int in = ucontrol->id.index % num_busses_in(chip);
1287 1289
1288 chip = snd_kcontrol_chip(kcontrol); 1290 if (out >= ECHO_MAXAUDIOOUTPUTS || in >= ECHO_MAXAUDIOINPUTS)
1289 ucontrol->value.integer.value[0] = 1291 return -EINVAL;
1290 chip->monitor_gain[ucontrol->id.index / num_busses_in(chip)] 1292
1291 [ucontrol->id.index % num_busses_in(chip)]; 1293 ucontrol->value.integer.value[0] = chip->monitor_gain[out][in];
1292 return 0; 1294 return 0;
1293} 1295}
1294 1296
@@ -1297,12 +1299,14 @@ static int snd_echo_mixer_put(struct snd_kcontrol *kcontrol,
1297{ 1299{
1298 struct echoaudio *chip; 1300 struct echoaudio *chip;
1299 int changed, gain; 1301 int changed, gain;
1300 short out, in; 1302 unsigned int out, in;
1301 1303
1302 changed = 0; 1304 changed = 0;
1303 chip = snd_kcontrol_chip(kcontrol); 1305 chip = snd_kcontrol_chip(kcontrol);
1304 out = ucontrol->id.index / num_busses_in(chip); 1306 out = ucontrol->id.index / num_busses_in(chip);
1305 in = ucontrol->id.index % num_busses_in(chip); 1307 in = ucontrol->id.index % num_busses_in(chip);
1308 if (out >= ECHO_MAXAUDIOOUTPUTS || in >= ECHO_MAXAUDIOINPUTS)
1309 return -EINVAL;
1306 gain = ucontrol->value.integer.value[0]; 1310 gain = ucontrol->value.integer.value[0];
1307 if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT) 1311 if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT)
1308 return -EINVAL; 1312 return -EINVAL;
diff --git a/sound/pci/emu10k1/emu10k1_main.c b/sound/pci/emu10k1/emu10k1_main.c
index b4458a630a7c..54079f5d5673 100644
--- a/sound/pci/emu10k1/emu10k1_main.c
+++ b/sound/pci/emu10k1/emu10k1_main.c
@@ -707,6 +707,7 @@ static int emu1010_firmware_thread(void *data)
707{ 707{
708 struct snd_emu10k1 *emu = data; 708 struct snd_emu10k1 *emu = data;
709 u32 tmp, tmp2, reg; 709 u32 tmp, tmp2, reg;
710 u32 last_reg = 0;
710 int err; 711 int err;
711 712
712 for (;;) { 713 for (;;) {
@@ -782,7 +783,15 @@ static int emu1010_firmware_thread(void *data)
782 msleep(10); 783 msleep(10);
783 /* Unmute all. Default is muted after a firmware load */ 784 /* Unmute all. Default is muted after a firmware load */
784 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE); 785 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE);
786 } else if (!reg && last_reg) {
787 /* Audio Dock removed */
788 dev_info(emu->card->dev,
789 "emu1010: Audio Dock detached\n");
790 /* Unmute all */
791 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE);
785 } 792 }
793
794 last_reg = reg;
786 } 795 }
787 dev_info(emu->card->dev, "emu1010: firmware thread stopping\n"); 796 dev_info(emu->card->dev, "emu1010: firmware thread stopping\n");
788 return 0; 797 return 0;
@@ -1325,6 +1334,22 @@ static int snd_emu10k1_dev_free(struct snd_device *device)
1325} 1334}
1326 1335
1327static struct snd_emu_chip_details emu_chip_details[] = { 1336static struct snd_emu_chip_details emu_chip_details[] = {
1337 /* Audigy 5/Rx SB1550 */
1338 /* Tested by michael@gernoth.net 28 Mar 2015 */
1339 /* DSP: CA10300-IAT LF
1340 * DAC: Cirrus Logic CS4382-KQZ
1341 * ADC: Philips 1361T
1342 * AC97: Sigmatel STAC9750
1343 * CA0151: None
1344 */
1345 {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x10241102,
1346 .driver = "Audigy2", .name = "SB Audigy 5/Rx [SB1550]",
1347 .id = "Audigy2",
1348 .emu10k2_chip = 1,
1349 .ca0108_chip = 1,
1350 .spk71 = 1,
1351 .adc_1361t = 1, /* 24 bit capture instead of 16bit */
1352 .ac97_chip = 1},
1328 /* Audigy4 (Not PRO) SB0610 */ 1353 /* Audigy4 (Not PRO) SB0610 */
1329 /* Tested by James@superbug.co.uk 4th April 2006 */ 1354 /* Tested by James@superbug.co.uk 4th April 2006 */
1330 /* A_IOCFG bits 1355 /* A_IOCFG bits
diff --git a/sound/pci/emu10k1/emu10k1_synth.c b/sound/pci/emu10k1/emu10k1_synth.c
index 4c41c903a840..5457d5613f6b 100644
--- a/sound/pci/emu10k1/emu10k1_synth.c
+++ b/sound/pci/emu10k1/emu10k1_synth.c
@@ -29,8 +29,9 @@ MODULE_LICENSE("GPL");
29/* 29/*
30 * create a new hardware dependent device for Emu10k1 30 * create a new hardware dependent device for Emu10k1
31 */ 31 */
32static int snd_emu10k1_synth_new_device(struct snd_seq_device *dev) 32static int snd_emu10k1_synth_probe(struct device *_dev)
33{ 33{
34 struct snd_seq_device *dev = to_seq_dev(_dev);
34 struct snd_emux *emux; 35 struct snd_emux *emux;
35 struct snd_emu10k1 *hw; 36 struct snd_emu10k1 *hw;
36 struct snd_emu10k1_synth_arg *arg; 37 struct snd_emu10k1_synth_arg *arg;
@@ -79,8 +80,9 @@ static int snd_emu10k1_synth_new_device(struct snd_seq_device *dev)
79 return 0; 80 return 0;
80} 81}
81 82
82static int snd_emu10k1_synth_delete_device(struct snd_seq_device *dev) 83static int snd_emu10k1_synth_remove(struct device *_dev)
83{ 84{
85 struct snd_seq_device *dev = to_seq_dev(_dev);
84 struct snd_emux *emux; 86 struct snd_emux *emux;
85 struct snd_emu10k1 *hw; 87 struct snd_emu10k1 *hw;
86 unsigned long flags; 88 unsigned long flags;
@@ -104,21 +106,14 @@ static int snd_emu10k1_synth_delete_device(struct snd_seq_device *dev)
104 * INIT part 106 * INIT part
105 */ 107 */
106 108
107static int __init alsa_emu10k1_synth_init(void) 109static struct snd_seq_driver emu10k1_synth_driver = {
108{ 110 .driver = {
109 111 .name = KBUILD_MODNAME,
110 static struct snd_seq_dev_ops ops = { 112 .probe = snd_emu10k1_synth_probe,
111 snd_emu10k1_synth_new_device, 113 .remove = snd_emu10k1_synth_remove,
112 snd_emu10k1_synth_delete_device, 114 },
113 }; 115 .id = SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH,
114 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops, 116 .argsize = sizeof(struct snd_emu10k1_synth_arg),
115 sizeof(struct snd_emu10k1_synth_arg)); 117};
116} 118
117 119module_snd_seq_driver(emu10k1_synth_driver);
118static void __exit alsa_emu10k1_synth_exit(void)
119{
120 snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH);
121}
122
123module_init(alsa_emu10k1_synth_init)
124module_exit(alsa_emu10k1_synth_exit)
diff --git a/sound/pci/emu10k1/emumixer.c b/sound/pci/emu10k1/emumixer.c
index 1de33025669a..55e57166256e 100644
--- a/sound/pci/emu10k1/emumixer.c
+++ b/sound/pci/emu10k1/emumixer.c
@@ -806,6 +806,108 @@ static struct snd_kcontrol_new snd_emu1010_internal_clock =
806 .put = snd_emu1010_internal_clock_put 806 .put = snd_emu1010_internal_clock_put
807}; 807};
808 808
809static int snd_emu1010_optical_out_info(struct snd_kcontrol *kcontrol,
810 struct snd_ctl_elem_info *uinfo)
811{
812 static const char * const texts[2] = {
813 "SPDIF", "ADAT"
814 };
815
816 return snd_ctl_enum_info(uinfo, 1, 2, texts);
817}
818
819static int snd_emu1010_optical_out_get(struct snd_kcontrol *kcontrol,
820 struct snd_ctl_elem_value *ucontrol)
821{
822 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
823
824 ucontrol->value.enumerated.item[0] = emu->emu1010.optical_out;
825 return 0;
826}
827
828static int snd_emu1010_optical_out_put(struct snd_kcontrol *kcontrol,
829 struct snd_ctl_elem_value *ucontrol)
830{
831 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
832 unsigned int val;
833 u32 tmp;
834 int change = 0;
835
836 val = ucontrol->value.enumerated.item[0];
837 /* Limit: uinfo->value.enumerated.items = 2; */
838 if (val >= 2)
839 return -EINVAL;
840 change = (emu->emu1010.optical_out != val);
841 if (change) {
842 emu->emu1010.optical_out = val;
843 tmp = (emu->emu1010.optical_in ? EMU_HANA_OPTICAL_IN_ADAT : 0) |
844 (emu->emu1010.optical_out ? EMU_HANA_OPTICAL_OUT_ADAT : 0);
845 snd_emu1010_fpga_write(emu, EMU_HANA_OPTICAL_TYPE, tmp);
846 }
847 return change;
848}
849
850static struct snd_kcontrol_new snd_emu1010_optical_out = {
851 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
852 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
853 .name = "Optical Output Mode",
854 .count = 1,
855 .info = snd_emu1010_optical_out_info,
856 .get = snd_emu1010_optical_out_get,
857 .put = snd_emu1010_optical_out_put
858};
859
860static int snd_emu1010_optical_in_info(struct snd_kcontrol *kcontrol,
861 struct snd_ctl_elem_info *uinfo)
862{
863 static const char * const texts[2] = {
864 "SPDIF", "ADAT"
865 };
866
867 return snd_ctl_enum_info(uinfo, 1, 2, texts);
868}
869
870static int snd_emu1010_optical_in_get(struct snd_kcontrol *kcontrol,
871 struct snd_ctl_elem_value *ucontrol)
872{
873 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
874
875 ucontrol->value.enumerated.item[0] = emu->emu1010.optical_in;
876 return 0;
877}
878
879static int snd_emu1010_optical_in_put(struct snd_kcontrol *kcontrol,
880 struct snd_ctl_elem_value *ucontrol)
881{
882 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
883 unsigned int val;
884 u32 tmp;
885 int change = 0;
886
887 val = ucontrol->value.enumerated.item[0];
888 /* Limit: uinfo->value.enumerated.items = 2; */
889 if (val >= 2)
890 return -EINVAL;
891 change = (emu->emu1010.optical_in != val);
892 if (change) {
893 emu->emu1010.optical_in = val;
894 tmp = (emu->emu1010.optical_in ? EMU_HANA_OPTICAL_IN_ADAT : 0) |
895 (emu->emu1010.optical_out ? EMU_HANA_OPTICAL_OUT_ADAT : 0);
896 snd_emu1010_fpga_write(emu, EMU_HANA_OPTICAL_TYPE, tmp);
897 }
898 return change;
899}
900
901static struct snd_kcontrol_new snd_emu1010_optical_in = {
902 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
903 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
904 .name = "Optical Input Mode",
905 .count = 1,
906 .info = snd_emu1010_optical_in_info,
907 .get = snd_emu1010_optical_in_get,
908 .put = snd_emu1010_optical_in_put
909};
910
809static int snd_audigy_i2c_capture_source_info(struct snd_kcontrol *kcontrol, 911static int snd_audigy_i2c_capture_source_info(struct snd_kcontrol *kcontrol,
810 struct snd_ctl_elem_info *uinfo) 912 struct snd_ctl_elem_info *uinfo)
811{ 913{
@@ -2051,6 +2153,14 @@ int snd_emu10k1_mixer(struct snd_emu10k1 *emu,
2051 snd_ctl_new1(&snd_emu1010_internal_clock, emu)); 2153 snd_ctl_new1(&snd_emu1010_internal_clock, emu));
2052 if (err < 0) 2154 if (err < 0)
2053 return err; 2155 return err;
2156 err = snd_ctl_add(card,
2157 snd_ctl_new1(&snd_emu1010_optical_out, emu));
2158 if (err < 0)
2159 return err;
2160 err = snd_ctl_add(card,
2161 snd_ctl_new1(&snd_emu1010_optical_in, emu));
2162 if (err < 0)
2163 return err;
2054 2164
2055 } else if (emu->card_capabilities->emu_model) { 2165 } else if (emu->card_capabilities->emu_model) {
2056 /* all other e-mu cards for now */ 2166 /* all other e-mu cards for now */
@@ -2086,6 +2196,14 @@ int snd_emu10k1_mixer(struct snd_emu10k1 *emu,
2086 snd_ctl_new1(&snd_emu1010_internal_clock, emu)); 2196 snd_ctl_new1(&snd_emu1010_internal_clock, emu));
2087 if (err < 0) 2197 if (err < 0)
2088 return err; 2198 return err;
2199 err = snd_ctl_add(card,
2200 snd_ctl_new1(&snd_emu1010_optical_out, emu));
2201 if (err < 0)
2202 return err;
2203 err = snd_ctl_add(card,
2204 snd_ctl_new1(&snd_emu1010_optical_in, emu));
2205 if (err < 0)
2206 return err;
2089 } 2207 }
2090 2208
2091 if ( emu->card_capabilities->i2c_adc) { 2209 if ( emu->card_capabilities->i2c_adc) {
diff --git a/sound/pci/emu10k1/emuproc.c b/sound/pci/emu10k1/emuproc.c
index 2ca9f2e93139..53745f4c2bf5 100644
--- a/sound/pci/emu10k1/emuproc.c
+++ b/sound/pci/emu10k1/emuproc.c
@@ -241,31 +241,22 @@ static void snd_emu10k1_proc_spdif_read(struct snd_info_entry *entry,
241 struct snd_emu10k1 *emu = entry->private_data; 241 struct snd_emu10k1 *emu = entry->private_data;
242 u32 value; 242 u32 value;
243 u32 value2; 243 u32 value2;
244 unsigned long flags;
245 u32 rate; 244 u32 rate;
246 245
247 if (emu->card_capabilities->emu_model) { 246 if (emu->card_capabilities->emu_model) {
248 spin_lock_irqsave(&emu->emu_lock, flags);
249 snd_emu1010_fpga_read(emu, 0x38, &value); 247 snd_emu1010_fpga_read(emu, 0x38, &value);
250 spin_unlock_irqrestore(&emu->emu_lock, flags);
251 if ((value & 0x1) == 0) { 248 if ((value & 0x1) == 0) {
252 spin_lock_irqsave(&emu->emu_lock, flags);
253 snd_emu1010_fpga_read(emu, 0x2a, &value); 249 snd_emu1010_fpga_read(emu, 0x2a, &value);
254 snd_emu1010_fpga_read(emu, 0x2b, &value2); 250 snd_emu1010_fpga_read(emu, 0x2b, &value2);
255 spin_unlock_irqrestore(&emu->emu_lock, flags);
256 rate = 0x1770000 / (((value << 5) | value2)+1); 251 rate = 0x1770000 / (((value << 5) | value2)+1);
257 snd_iprintf(buffer, "ADAT Locked : %u\n", rate); 252 snd_iprintf(buffer, "ADAT Locked : %u\n", rate);
258 } else { 253 } else {
259 snd_iprintf(buffer, "ADAT Unlocked\n"); 254 snd_iprintf(buffer, "ADAT Unlocked\n");
260 } 255 }
261 spin_lock_irqsave(&emu->emu_lock, flags);
262 snd_emu1010_fpga_read(emu, 0x20, &value); 256 snd_emu1010_fpga_read(emu, 0x20, &value);
263 spin_unlock_irqrestore(&emu->emu_lock, flags);
264 if ((value & 0x4) == 0) { 257 if ((value & 0x4) == 0) {
265 spin_lock_irqsave(&emu->emu_lock, flags);
266 snd_emu1010_fpga_read(emu, 0x28, &value); 258 snd_emu1010_fpga_read(emu, 0x28, &value);
267 snd_emu1010_fpga_read(emu, 0x29, &value2); 259 snd_emu1010_fpga_read(emu, 0x29, &value2);
268 spin_unlock_irqrestore(&emu->emu_lock, flags);
269 rate = 0x1770000 / (((value << 5) | value2)+1); 260 rate = 0x1770000 / (((value << 5) | value2)+1);
270 snd_iprintf(buffer, "SPDIF Locked : %d\n", rate); 261 snd_iprintf(buffer, "SPDIF Locked : %d\n", rate);
271 } else { 262 } else {
@@ -410,14 +401,11 @@ static void snd_emu_proc_emu1010_reg_read(struct snd_info_entry *entry,
410{ 401{
411 struct snd_emu10k1 *emu = entry->private_data; 402 struct snd_emu10k1 *emu = entry->private_data;
412 u32 value; 403 u32 value;
413 unsigned long flags;
414 int i; 404 int i;
415 snd_iprintf(buffer, "EMU1010 Registers:\n\n"); 405 snd_iprintf(buffer, "EMU1010 Registers:\n\n");
416 406
417 for(i = 0; i < 0x40; i+=1) { 407 for(i = 0; i < 0x40; i+=1) {
418 spin_lock_irqsave(&emu->emu_lock, flags);
419 snd_emu1010_fpga_read(emu, i, &value); 408 snd_emu1010_fpga_read(emu, i, &value);
420 spin_unlock_irqrestore(&emu->emu_lock, flags);
421 snd_iprintf(buffer, "%02X: %08X, %02X\n", i, value, (value >> 8) & 0x7f); 409 snd_iprintf(buffer, "%02X: %08X, %02X\n", i, value, (value >> 8) & 0x7f);
422 } 410 }
423} 411}
diff --git a/sound/pci/hda/Kconfig b/sound/pci/hda/Kconfig
index 7f0f2c5a4e97..a5ed1c181784 100644
--- a/sound/pci/hda/Kconfig
+++ b/sound/pci/hda/Kconfig
@@ -5,6 +5,7 @@ config SND_HDA
5 select SND_PCM 5 select SND_PCM
6 select SND_VMASTER 6 select SND_VMASTER
7 select SND_KCTL_JACK 7 select SND_KCTL_JACK
8 select SND_HDA_CORE
8 9
9config SND_HDA_INTEL 10config SND_HDA_INTEL
10 tristate "HD Audio PCI" 11 tristate "HD Audio PCI"
diff --git a/sound/pci/hda/Makefile b/sound/pci/hda/Makefile
index 194f30935e77..af78fb33a4fd 100644
--- a/sound/pci/hda/Makefile
+++ b/sound/pci/hda/Makefile
@@ -4,13 +4,12 @@ snd-hda-tegra-objs := hda_tegra.o
4# for haswell power well 4# for haswell power well
5snd-hda-intel-$(CONFIG_SND_HDA_I915) += hda_i915.o 5snd-hda-intel-$(CONFIG_SND_HDA_I915) += hda_i915.o
6 6
7snd-hda-codec-y := hda_codec.o hda_jack.o hda_auto_parser.o hda_sysfs.o 7snd-hda-codec-y := hda_bind.o hda_codec.o hda_jack.o hda_auto_parser.o hda_sysfs.o
8snd-hda-codec-$(CONFIG_PROC_FS) += hda_proc.o 8snd-hda-codec-$(CONFIG_PROC_FS) += hda_proc.o
9snd-hda-codec-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o 9snd-hda-codec-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o
10snd-hda-codec-$(CONFIG_SND_HDA_INPUT_BEEP) += hda_beep.o 10snd-hda-codec-$(CONFIG_SND_HDA_INPUT_BEEP) += hda_beep.o
11 11
12# for trace-points 12# for trace-points
13CFLAGS_hda_codec.o := -I$(src)
14CFLAGS_hda_controller.o := -I$(src) 13CFLAGS_hda_controller.o := -I$(src)
15 14
16snd-hda-codec-generic-objs := hda_generic.o 15snd-hda-codec-generic-objs := hda_generic.o
diff --git a/sound/pci/hda/hda_auto_parser.c b/sound/pci/hda/hda_auto_parser.c
index 3f8706bb3d16..03b7399bb7f0 100644
--- a/sound/pci/hda/hda_auto_parser.c
+++ b/sound/pci/hda/hda_auto_parser.c
@@ -172,7 +172,7 @@ int snd_hda_parse_pin_defcfg(struct hda_codec *codec,
172 const hda_nid_t *ignore_nids, 172 const hda_nid_t *ignore_nids,
173 unsigned int cond_flags) 173 unsigned int cond_flags)
174{ 174{
175 hda_nid_t nid, end_nid; 175 hda_nid_t nid;
176 short seq, assoc_line_out; 176 short seq, assoc_line_out;
177 struct auto_out_pin line_out[ARRAY_SIZE(cfg->line_out_pins)]; 177 struct auto_out_pin line_out[ARRAY_SIZE(cfg->line_out_pins)];
178 struct auto_out_pin speaker_out[ARRAY_SIZE(cfg->speaker_pins)]; 178 struct auto_out_pin speaker_out[ARRAY_SIZE(cfg->speaker_pins)];
@@ -189,8 +189,7 @@ int snd_hda_parse_pin_defcfg(struct hda_codec *codec,
189 memset(hp_out, 0, sizeof(hp_out)); 189 memset(hp_out, 0, sizeof(hp_out));
190 assoc_line_out = 0; 190 assoc_line_out = 0;
191 191
192 end_nid = codec->start_nid + codec->num_nodes; 192 for_each_hda_codec_node(nid, codec) {
193 for (nid = codec->start_nid; nid < end_nid; nid++) {
194 unsigned int wid_caps = get_wcaps(codec, nid); 193 unsigned int wid_caps = get_wcaps(codec, nid);
195 unsigned int wid_type = get_wcaps_type(wid_caps); 194 unsigned int wid_type = get_wcaps_type(wid_caps);
196 unsigned int def_conf; 195 unsigned int def_conf;
@@ -410,7 +409,7 @@ int snd_hda_parse_pin_defcfg(struct hda_codec *codec,
410 * debug prints of the parsed results 409 * debug prints of the parsed results
411 */ 410 */
412 codec_info(codec, "autoconfig for %s: line_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x) type:%s\n", 411 codec_info(codec, "autoconfig for %s: line_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x) type:%s\n",
413 codec->chip_name, cfg->line_outs, cfg->line_out_pins[0], 412 codec->core.chip_name, cfg->line_outs, cfg->line_out_pins[0],
414 cfg->line_out_pins[1], cfg->line_out_pins[2], 413 cfg->line_out_pins[1], cfg->line_out_pins[2],
415 cfg->line_out_pins[3], cfg->line_out_pins[4], 414 cfg->line_out_pins[3], cfg->line_out_pins[4],
416 cfg->line_out_type == AUTO_PIN_HP_OUT ? "hp" : 415 cfg->line_out_type == AUTO_PIN_HP_OUT ? "hp" :
@@ -836,33 +835,33 @@ static void apply_fixup(struct hda_codec *codec, int id, int action, int depth)
836 if (action != HDA_FIXUP_ACT_PRE_PROBE || !fix->v.pins) 835 if (action != HDA_FIXUP_ACT_PRE_PROBE || !fix->v.pins)
837 break; 836 break;
838 codec_dbg(codec, "%s: Apply pincfg for %s\n", 837 codec_dbg(codec, "%s: Apply pincfg for %s\n",
839 codec->chip_name, modelname); 838 codec->core.chip_name, modelname);
840 snd_hda_apply_pincfgs(codec, fix->v.pins); 839 snd_hda_apply_pincfgs(codec, fix->v.pins);
841 break; 840 break;
842 case HDA_FIXUP_VERBS: 841 case HDA_FIXUP_VERBS:
843 if (action != HDA_FIXUP_ACT_PROBE || !fix->v.verbs) 842 if (action != HDA_FIXUP_ACT_PROBE || !fix->v.verbs)
844 break; 843 break;
845 codec_dbg(codec, "%s: Apply fix-verbs for %s\n", 844 codec_dbg(codec, "%s: Apply fix-verbs for %s\n",
846 codec->chip_name, modelname); 845 codec->core.chip_name, modelname);
847 snd_hda_add_verbs(codec, fix->v.verbs); 846 snd_hda_add_verbs(codec, fix->v.verbs);
848 break; 847 break;
849 case HDA_FIXUP_FUNC: 848 case HDA_FIXUP_FUNC:
850 if (!fix->v.func) 849 if (!fix->v.func)
851 break; 850 break;
852 codec_dbg(codec, "%s: Apply fix-func for %s\n", 851 codec_dbg(codec, "%s: Apply fix-func for %s\n",
853 codec->chip_name, modelname); 852 codec->core.chip_name, modelname);
854 fix->v.func(codec, fix, action); 853 fix->v.func(codec, fix, action);
855 break; 854 break;
856 case HDA_FIXUP_PINCTLS: 855 case HDA_FIXUP_PINCTLS:
857 if (action != HDA_FIXUP_ACT_PROBE || !fix->v.pins) 856 if (action != HDA_FIXUP_ACT_PROBE || !fix->v.pins)
858 break; 857 break;
859 codec_dbg(codec, "%s: Apply pinctl for %s\n", 858 codec_dbg(codec, "%s: Apply pinctl for %s\n",
860 codec->chip_name, modelname); 859 codec->core.chip_name, modelname);
861 set_pin_targets(codec, fix->v.pins); 860 set_pin_targets(codec, fix->v.pins);
862 break; 861 break;
863 default: 862 default:
864 codec_err(codec, "%s: Invalid fixup type %d\n", 863 codec_err(codec, "%s: Invalid fixup type %d\n",
865 codec->chip_name, fix->type); 864 codec->core.chip_name, fix->type);
866 break; 865 break;
867 } 866 }
868 if (!fix->chained || fix->chained_before) 867 if (!fix->chained || fix->chained_before)
@@ -912,16 +911,16 @@ void snd_hda_pick_pin_fixup(struct hda_codec *codec,
912 return; 911 return;
913 912
914 for (pq = pin_quirk; pq->subvendor; pq++) { 913 for (pq = pin_quirk; pq->subvendor; pq++) {
915 if ((codec->subsystem_id & 0xffff0000) != (pq->subvendor << 16)) 914 if ((codec->core.subsystem_id & 0xffff0000) != (pq->subvendor << 16))
916 continue; 915 continue;
917 if (codec->vendor_id != pq->codec) 916 if (codec->core.vendor_id != pq->codec)
918 continue; 917 continue;
919 if (pin_config_match(codec, pq->pins)) { 918 if (pin_config_match(codec, pq->pins)) {
920 codec->fixup_id = pq->value; 919 codec->fixup_id = pq->value;
921#ifdef CONFIG_SND_DEBUG_VERBOSE 920#ifdef CONFIG_SND_DEBUG_VERBOSE
922 codec->fixup_name = pq->name; 921 codec->fixup_name = pq->name;
923 codec_dbg(codec, "%s: picked fixup %s (pin match)\n", 922 codec_dbg(codec, "%s: picked fixup %s (pin match)\n",
924 codec->chip_name, codec->fixup_name); 923 codec->core.chip_name, codec->fixup_name);
925#endif 924#endif
926 codec->fixup_list = fixlist; 925 codec->fixup_list = fixlist;
927 return; 926 return;
@@ -963,7 +962,7 @@ void snd_hda_pick_fixup(struct hda_codec *codec,
963 codec->fixup_name = NULL; 962 codec->fixup_name = NULL;
964 codec->fixup_id = HDA_FIXUP_ID_NO_FIXUP; 963 codec->fixup_id = HDA_FIXUP_ID_NO_FIXUP;
965 codec_dbg(codec, "%s: picked no fixup (nofixup specified)\n", 964 codec_dbg(codec, "%s: picked no fixup (nofixup specified)\n",
966 codec->chip_name); 965 codec->core.chip_name);
967 return; 966 return;
968 } 967 }
969 968
@@ -974,7 +973,7 @@ void snd_hda_pick_fixup(struct hda_codec *codec,
974 codec->fixup_name = models->name; 973 codec->fixup_name = models->name;
975 codec->fixup_list = fixlist; 974 codec->fixup_list = fixlist;
976 codec_dbg(codec, "%s: picked fixup %s (model specified)\n", 975 codec_dbg(codec, "%s: picked fixup %s (model specified)\n",
977 codec->chip_name, codec->fixup_name); 976 codec->core.chip_name, codec->fixup_name);
978 return; 977 return;
979 } 978 }
980 models++; 979 models++;
@@ -987,7 +986,7 @@ void snd_hda_pick_fixup(struct hda_codec *codec,
987#ifdef CONFIG_SND_DEBUG_VERBOSE 986#ifdef CONFIG_SND_DEBUG_VERBOSE
988 name = q->name; 987 name = q->name;
989 codec_dbg(codec, "%s: picked fixup %s (PCI SSID%s)\n", 988 codec_dbg(codec, "%s: picked fixup %s (PCI SSID%s)\n",
990 codec->chip_name, name, q->subdevice_mask ? "" : " - vendor generic"); 989 codec->core.chip_name, name, q->subdevice_mask ? "" : " - vendor generic");
991#endif 990#endif
992 } 991 }
993 } 992 }
@@ -996,12 +995,12 @@ void snd_hda_pick_fixup(struct hda_codec *codec,
996 unsigned int vendorid = 995 unsigned int vendorid =
997 q->subdevice | (q->subvendor << 16); 996 q->subdevice | (q->subvendor << 16);
998 unsigned int mask = 0xffff0000 | q->subdevice_mask; 997 unsigned int mask = 0xffff0000 | q->subdevice_mask;
999 if ((codec->subsystem_id & mask) == (vendorid & mask)) { 998 if ((codec->core.subsystem_id & mask) == (vendorid & mask)) {
1000 id = q->value; 999 id = q->value;
1001#ifdef CONFIG_SND_DEBUG_VERBOSE 1000#ifdef CONFIG_SND_DEBUG_VERBOSE
1002 name = q->name; 1001 name = q->name;
1003 codec_dbg(codec, "%s: picked fixup %s (codec SSID)\n", 1002 codec_dbg(codec, "%s: picked fixup %s (codec SSID)\n",
1004 codec->chip_name, name); 1003 codec->core.chip_name, name);
1005#endif 1004#endif
1006 break; 1005 break;
1007 } 1006 }
diff --git a/sound/pci/hda/hda_beep.c b/sound/pci/hda/hda_beep.c
index 1e7de08e77cb..3364dc0fdeab 100644
--- a/sound/pci/hda/hda_beep.c
+++ b/sound/pci/hda/hda_beep.c
@@ -33,30 +33,36 @@ enum {
33 DIGBEEP_HZ_MAX = 12000000, /* 12 KHz */ 33 DIGBEEP_HZ_MAX = 12000000, /* 12 KHz */
34}; 34};
35 35
36static void snd_hda_generate_beep(struct work_struct *work) 36/* generate or stop tone */
37static void generate_tone(struct hda_beep *beep, int tone)
37{ 38{
38 struct hda_beep *beep =
39 container_of(work, struct hda_beep, beep_work);
40 struct hda_codec *codec = beep->codec; 39 struct hda_codec *codec = beep->codec;
41 int tone;
42 40
43 if (!beep->enabled)
44 return;
45
46 tone = beep->tone;
47 if (tone && !beep->playing) { 41 if (tone && !beep->playing) {
48 snd_hda_power_up(codec); 42 snd_hda_power_up(codec);
43 if (beep->power_hook)
44 beep->power_hook(beep, true);
49 beep->playing = 1; 45 beep->playing = 1;
50 } 46 }
51 /* generate tone */
52 snd_hda_codec_write(codec, beep->nid, 0, 47 snd_hda_codec_write(codec, beep->nid, 0,
53 AC_VERB_SET_BEEP_CONTROL, tone); 48 AC_VERB_SET_BEEP_CONTROL, tone);
54 if (!tone && beep->playing) { 49 if (!tone && beep->playing) {
55 beep->playing = 0; 50 beep->playing = 0;
51 if (beep->power_hook)
52 beep->power_hook(beep, false);
56 snd_hda_power_down(codec); 53 snd_hda_power_down(codec);
57 } 54 }
58} 55}
59 56
57static void snd_hda_generate_beep(struct work_struct *work)
58{
59 struct hda_beep *beep =
60 container_of(work, struct hda_beep, beep_work);
61
62 if (beep->enabled)
63 generate_tone(beep, beep->tone);
64}
65
60/* (non-standard) Linear beep tone calculation for IDT/STAC codecs 66/* (non-standard) Linear beep tone calculation for IDT/STAC codecs
61 * 67 *
62 * The tone frequency of beep generator on IDT/STAC codecs is 68 * The tone frequency of beep generator on IDT/STAC codecs is
@@ -130,10 +136,7 @@ static void turn_off_beep(struct hda_beep *beep)
130 cancel_work_sync(&beep->beep_work); 136 cancel_work_sync(&beep->beep_work);
131 if (beep->playing) { 137 if (beep->playing) {
132 /* turn off beep */ 138 /* turn off beep */
133 snd_hda_codec_write(beep->codec, beep->nid, 0, 139 generate_tone(beep, 0);
134 AC_VERB_SET_BEEP_CONTROL, 0);
135 beep->playing = 0;
136 snd_hda_power_down(beep->codec);
137 } 140 }
138} 141}
139 142
@@ -160,15 +163,15 @@ static int snd_hda_do_attach(struct hda_beep *beep)
160 input_dev->name = "HDA Digital PCBeep"; 163 input_dev->name = "HDA Digital PCBeep";
161 input_dev->phys = beep->phys; 164 input_dev->phys = beep->phys;
162 input_dev->id.bustype = BUS_PCI; 165 input_dev->id.bustype = BUS_PCI;
166 input_dev->dev.parent = &codec->card->card_dev;
163 167
164 input_dev->id.vendor = codec->vendor_id >> 16; 168 input_dev->id.vendor = codec->core.vendor_id >> 16;
165 input_dev->id.product = codec->vendor_id & 0xffff; 169 input_dev->id.product = codec->core.vendor_id & 0xffff;
166 input_dev->id.version = 0x01; 170 input_dev->id.version = 0x01;
167 171
168 input_dev->evbit[0] = BIT_MASK(EV_SND); 172 input_dev->evbit[0] = BIT_MASK(EV_SND);
169 input_dev->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE); 173 input_dev->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE);
170 input_dev->event = snd_hda_beep_event; 174 input_dev->event = snd_hda_beep_event;
171 input_dev->dev.parent = &codec->dev;
172 input_set_drvdata(input_dev, beep); 175 input_set_drvdata(input_dev, beep);
173 176
174 beep->dev = input_dev; 177 beep->dev = input_dev;
@@ -224,7 +227,7 @@ int snd_hda_attach_beep_device(struct hda_codec *codec, int nid)
224 if (beep == NULL) 227 if (beep == NULL)
225 return -ENOMEM; 228 return -ENOMEM;
226 snprintf(beep->phys, sizeof(beep->phys), 229 snprintf(beep->phys, sizeof(beep->phys),
227 "card%d/codec#%d/beep0", codec->bus->card->number, codec->addr); 230 "card%d/codec#%d/beep0", codec->card->number, codec->addr);
228 /* enable linear scale */ 231 /* enable linear scale */
229 snd_hda_codec_write_cache(codec, nid, 0, 232 snd_hda_codec_write_cache(codec, nid, 0,
230 AC_VERB_SET_DIGI_CONVERT_2, 0x01); 233 AC_VERB_SET_DIGI_CONVERT_2, 0x01);
diff --git a/sound/pci/hda/hda_beep.h b/sound/pci/hda/hda_beep.h
index a63b5e077332..46524ff7e79e 100644
--- a/sound/pci/hda/hda_beep.h
+++ b/sound/pci/hda/hda_beep.h
@@ -40,6 +40,7 @@ struct hda_beep {
40 unsigned int playing:1; 40 unsigned int playing:1;
41 struct work_struct beep_work; /* scheduled task for beep event */ 41 struct work_struct beep_work; /* scheduled task for beep event */
42 struct mutex mutex; 42 struct mutex mutex;
43 void (*power_hook)(struct hda_beep *beep, bool on);
43}; 44};
44 45
45#ifdef CONFIG_SND_HDA_INPUT_BEEP 46#ifdef CONFIG_SND_HDA_INPUT_BEEP
diff --git a/sound/pci/hda/hda_bind.c b/sound/pci/hda/hda_bind.c
new file mode 100644
index 000000000000..00aa31c5f08e
--- /dev/null
+++ b/sound/pci/hda/hda_bind.c
@@ -0,0 +1,273 @@
1/*
2 * HD-audio codec driver binding
3 * Copyright (c) Takashi Iwai <tiwai@suse.de>
4 */
5
6#include <linux/init.h>
7#include <linux/slab.h>
8#include <linux/mutex.h>
9#include <linux/module.h>
10#include <linux/export.h>
11#include <linux/pm.h>
12#include <linux/pm_runtime.h>
13#include <sound/core.h>
14#include "hda_codec.h"
15#include "hda_local.h"
16
17/*
18 * find a matching codec preset
19 */
20static int hda_codec_match(struct hdac_device *dev, struct hdac_driver *drv)
21{
22 struct hda_codec *codec = container_of(dev, struct hda_codec, core);
23 struct hda_codec_driver *driver =
24 container_of(drv, struct hda_codec_driver, core);
25 const struct hda_codec_preset *preset;
26 /* check probe_id instead of vendor_id if set */
27 u32 id = codec->probe_id ? codec->probe_id : codec->core.vendor_id;
28
29 for (preset = driver->preset; preset->id; preset++) {
30 u32 mask = preset->mask;
31
32 if (preset->afg && preset->afg != codec->core.afg)
33 continue;
34 if (preset->mfg && preset->mfg != codec->core.mfg)
35 continue;
36 if (!mask)
37 mask = ~0;
38 if (preset->id == (id & mask) &&
39 (!preset->rev || preset->rev == codec->core.revision_id)) {
40 codec->preset = preset;
41 return 1;
42 }
43 }
44 return 0;
45}
46
47/* process an unsolicited event */
48static void hda_codec_unsol_event(struct hdac_device *dev, unsigned int ev)
49{
50 struct hda_codec *codec = container_of(dev, struct hda_codec, core);
51
52 if (codec->patch_ops.unsol_event)
53 codec->patch_ops.unsol_event(codec, ev);
54}
55
56/* reset the codec name from the preset */
57static int codec_refresh_name(struct hda_codec *codec, const char *name)
58{
59 if (name) {
60 kfree(codec->core.chip_name);
61 codec->core.chip_name = kstrdup(name, GFP_KERNEL);
62 }
63 return codec->core.chip_name ? 0 : -ENOMEM;
64}
65
66static int hda_codec_driver_probe(struct device *dev)
67{
68 struct hda_codec *codec = dev_to_hda_codec(dev);
69 struct module *owner = dev->driver->owner;
70 int err;
71
72 if (WARN_ON(!codec->preset))
73 return -EINVAL;
74
75 err = codec_refresh_name(codec, codec->preset->name);
76 if (err < 0)
77 goto error;
78 err = snd_hdac_regmap_init(&codec->core);
79 if (err < 0)
80 goto error;
81
82 if (!try_module_get(owner)) {
83 err = -EINVAL;
84 goto error;
85 }
86
87 err = codec->preset->patch(codec);
88 if (err < 0)
89 goto error_module;
90
91 err = snd_hda_codec_build_pcms(codec);
92 if (err < 0)
93 goto error_module;
94 err = snd_hda_codec_build_controls(codec);
95 if (err < 0)
96 goto error_module;
97 if (codec->card->registered) {
98 err = snd_card_register(codec->card);
99 if (err < 0)
100 goto error_module;
101 snd_hda_codec_register(codec);
102 }
103
104 codec->core.lazy_cache = true;
105 return 0;
106
107 error_module:
108 module_put(owner);
109
110 error:
111 snd_hda_codec_cleanup_for_unbind(codec);
112 return err;
113}
114
115static int hda_codec_driver_remove(struct device *dev)
116{
117 struct hda_codec *codec = dev_to_hda_codec(dev);
118
119 if (codec->patch_ops.free)
120 codec->patch_ops.free(codec);
121 snd_hda_codec_cleanup_for_unbind(codec);
122 module_put(dev->driver->owner);
123 return 0;
124}
125
126static void hda_codec_driver_shutdown(struct device *dev)
127{
128 struct hda_codec *codec = dev_to_hda_codec(dev);
129
130 if (!pm_runtime_suspended(dev) && codec->patch_ops.reboot_notify)
131 codec->patch_ops.reboot_notify(codec);
132}
133
134int __hda_codec_driver_register(struct hda_codec_driver *drv, const char *name,
135 struct module *owner)
136{
137 drv->core.driver.name = name;
138 drv->core.driver.owner = owner;
139 drv->core.driver.bus = &snd_hda_bus_type;
140 drv->core.driver.probe = hda_codec_driver_probe;
141 drv->core.driver.remove = hda_codec_driver_remove;
142 drv->core.driver.shutdown = hda_codec_driver_shutdown;
143 drv->core.driver.pm = &hda_codec_driver_pm;
144 drv->core.type = HDA_DEV_LEGACY;
145 drv->core.match = hda_codec_match;
146 drv->core.unsol_event = hda_codec_unsol_event;
147 return driver_register(&drv->core.driver);
148}
149EXPORT_SYMBOL_GPL(__hda_codec_driver_register);
150
151void hda_codec_driver_unregister(struct hda_codec_driver *drv)
152{
153 driver_unregister(&drv->core.driver);
154}
155EXPORT_SYMBOL_GPL(hda_codec_driver_unregister);
156
157static inline bool codec_probed(struct hda_codec *codec)
158{
159 return device_attach(hda_codec_dev(codec)) > 0 && codec->preset;
160}
161
162/* try to auto-load and bind the codec module */
163static void codec_bind_module(struct hda_codec *codec)
164{
165#ifdef MODULE
166 request_module("snd-hda-codec-id:%08x", codec->core.vendor_id);
167 if (codec_probed(codec))
168 return;
169 request_module("snd-hda-codec-id:%04x*",
170 (codec->core.vendor_id >> 16) & 0xffff);
171 if (codec_probed(codec))
172 return;
173#endif
174}
175
176#if IS_ENABLED(CONFIG_SND_HDA_CODEC_HDMI)
177/* if all audio out widgets are digital, let's assume the codec as a HDMI/DP */
178static bool is_likely_hdmi_codec(struct hda_codec *codec)
179{
180 hda_nid_t nid;
181
182 for_each_hda_codec_node(nid, codec) {
183 unsigned int wcaps = get_wcaps(codec, nid);
184 switch (get_wcaps_type(wcaps)) {
185 case AC_WID_AUD_IN:
186 return false; /* HDMI parser supports only HDMI out */
187 case AC_WID_AUD_OUT:
188 if (!(wcaps & AC_WCAP_DIGITAL))
189 return false;
190 break;
191 }
192 }
193 return true;
194}
195#else
196/* no HDMI codec parser support */
197#define is_likely_hdmi_codec(codec) false
198#endif /* CONFIG_SND_HDA_CODEC_HDMI */
199
200static int codec_bind_generic(struct hda_codec *codec)
201{
202 if (codec->probe_id)
203 return -ENODEV;
204
205 if (is_likely_hdmi_codec(codec)) {
206 codec->probe_id = HDA_CODEC_ID_GENERIC_HDMI;
207#if IS_MODULE(CONFIG_SND_HDA_CODEC_HDMI)
208 request_module("snd-hda-codec-hdmi");
209#endif
210 if (codec_probed(codec))
211 return 0;
212 }
213
214 codec->probe_id = HDA_CODEC_ID_GENERIC;
215#if IS_MODULE(CONFIG_SND_HDA_GENERIC)
216 request_module("snd-hda-codec-generic");
217#endif
218 if (codec_probed(codec))
219 return 0;
220 return -ENODEV;
221}
222
223#if IS_ENABLED(CONFIG_SND_HDA_GENERIC)
224#define is_generic_config(codec) \
225 (codec->modelname && !strcmp(codec->modelname, "generic"))
226#else
227#define is_generic_config(codec) 0
228#endif
229
230/**
231 * snd_hda_codec_configure - (Re-)configure the HD-audio codec
232 * @codec: the HDA codec
233 *
234 * Start parsing of the given codec tree and (re-)initialize the whole
235 * patch instance.
236 *
237 * Returns 0 if successful or a negative error code.
238 */
239int snd_hda_codec_configure(struct hda_codec *codec)
240{
241 int err;
242
243 if (is_generic_config(codec))
244 codec->probe_id = HDA_CODEC_ID_GENERIC;
245 else
246 codec->probe_id = 0;
247
248 err = snd_hdac_device_register(&codec->core);
249 if (err < 0)
250 return err;
251
252 if (!codec->preset)
253 codec_bind_module(codec);
254 if (!codec->preset) {
255 err = codec_bind_generic(codec);
256 if (err < 0) {
257 codec_err(codec, "Unable to bind the codec\n");
258 goto error;
259 }
260 }
261
262 /* audio codec should override the mixer name */
263 if (codec->core.afg || !*codec->card->mixername)
264 snprintf(codec->card->mixername,
265 sizeof(codec->card->mixername), "%s %s",
266 codec->core.vendor_name, codec->core.chip_name);
267 return 0;
268
269 error:
270 snd_hdac_device_unregister(&codec->core);
271 return err;
272}
273EXPORT_SYMBOL_GPL(snd_hda_codec_configure);
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 2fe86d2e1b09..873ed1bce12b 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -26,6 +26,8 @@
26#include <linux/mutex.h> 26#include <linux/mutex.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/async.h> 28#include <linux/async.h>
29#include <linux/pm.h>
30#include <linux/pm_runtime.h>
29#include <sound/core.h> 31#include <sound/core.h>
30#include "hda_codec.h" 32#include "hda_codec.h"
31#include <sound/asoundef.h> 33#include <sound/asoundef.h>
@@ -37,97 +39,20 @@
37#include "hda_jack.h" 39#include "hda_jack.h"
38#include <sound/hda_hwdep.h> 40#include <sound/hda_hwdep.h>
39 41
40#define CREATE_TRACE_POINTS
41#include "hda_trace.h"
42
43/*
44 * vendor / preset table
45 */
46
47struct hda_vendor_id {
48 unsigned int id;
49 const char *name;
50};
51
52/* codec vendor labels */
53static struct hda_vendor_id hda_vendor_ids[] = {
54 { 0x1002, "ATI" },
55 { 0x1013, "Cirrus Logic" },
56 { 0x1057, "Motorola" },
57 { 0x1095, "Silicon Image" },
58 { 0x10de, "Nvidia" },
59 { 0x10ec, "Realtek" },
60 { 0x1102, "Creative" },
61 { 0x1106, "VIA" },
62 { 0x111d, "IDT" },
63 { 0x11c1, "LSI" },
64 { 0x11d4, "Analog Devices" },
65 { 0x13f6, "C-Media" },
66 { 0x14f1, "Conexant" },
67 { 0x17e8, "Chrontel" },
68 { 0x1854, "LG" },
69 { 0x1aec, "Wolfson Microelectronics" },
70 { 0x1af4, "QEMU" },
71 { 0x434d, "C-Media" },
72 { 0x8086, "Intel" },
73 { 0x8384, "SigmaTel" },
74 {} /* terminator */
75};
76
77static DEFINE_MUTEX(preset_mutex);
78static LIST_HEAD(hda_preset_tables);
79
80/**
81 * snd_hda_add_codec_preset - Add a codec preset to the chain
82 * @preset: codec preset table to add
83 */
84int snd_hda_add_codec_preset(struct hda_codec_preset_list *preset)
85{
86 mutex_lock(&preset_mutex);
87 list_add_tail(&preset->list, &hda_preset_tables);
88 mutex_unlock(&preset_mutex);
89 return 0;
90}
91EXPORT_SYMBOL_GPL(snd_hda_add_codec_preset);
92
93/**
94 * snd_hda_delete_codec_preset - Delete a codec preset from the chain
95 * @preset: codec preset table to delete
96 */
97int snd_hda_delete_codec_preset(struct hda_codec_preset_list *preset)
98{
99 mutex_lock(&preset_mutex);
100 list_del(&preset->list);
101 mutex_unlock(&preset_mutex);
102 return 0;
103}
104EXPORT_SYMBOL_GPL(snd_hda_delete_codec_preset);
105
106#ifdef CONFIG_PM 42#ifdef CONFIG_PM
107#define codec_in_pm(codec) ((codec)->in_pm) 43#define codec_in_pm(codec) atomic_read(&(codec)->core.in_pm)
108static void hda_power_work(struct work_struct *work); 44#define hda_codec_is_power_on(codec) \
109static void hda_keep_power_on(struct hda_codec *codec); 45 (!pm_runtime_suspended(hda_codec_dev(codec)))
110#define hda_codec_is_power_on(codec) ((codec)->power_on)
111
112static void hda_call_pm_notify(struct hda_codec *codec, bool power_up)
113{
114 struct hda_bus *bus = codec->bus;
115
116 if ((power_up && codec->pm_up_notified) ||
117 (!power_up && !codec->pm_up_notified))
118 return;
119 if (bus->ops.pm_notify)
120 bus->ops.pm_notify(bus, power_up);
121 codec->pm_up_notified = power_up;
122}
123
124#else 46#else
125#define codec_in_pm(codec) 0 47#define codec_in_pm(codec) 0
126static inline void hda_keep_power_on(struct hda_codec *codec) {}
127#define hda_codec_is_power_on(codec) 1 48#define hda_codec_is_power_on(codec) 1
128#define hda_call_pm_notify(codec, state) {}
129#endif 49#endif
130 50
51#define codec_has_epss(codec) \
52 ((codec)->core.power_caps & AC_PWRST_EPSS)
53#define codec_has_clkstop(codec) \
54 ((codec)->core.power_caps & AC_PWRST_CLKSTOP)
55
131/** 56/**
132 * snd_hda_get_jack_location - Give a location string of the jack 57 * snd_hda_get_jack_location - Give a location string of the jack
133 * @cfg: pin default config value 58 * @cfg: pin default config value
@@ -199,67 +124,32 @@ const char *snd_hda_get_jack_type(u32 cfg)
199EXPORT_SYMBOL_GPL(snd_hda_get_jack_type); 124EXPORT_SYMBOL_GPL(snd_hda_get_jack_type);
200 125
201/* 126/*
202 * Compose a 32bit command word to be sent to the HD-audio controller 127 * Send and receive a verb - passed to exec_verb override for hdac_device
203 */
204static inline unsigned int
205make_codec_cmd(struct hda_codec *codec, hda_nid_t nid, int flags,
206 unsigned int verb, unsigned int parm)
207{
208 u32 val;
209
210 if ((codec->addr & ~0xf) || (nid & ~0x7f) ||
211 (verb & ~0xfff) || (parm & ~0xffff)) {
212 codec_err(codec, "hda-codec: out of range cmd %x:%x:%x:%x\n",
213 codec->addr, nid, verb, parm);
214 return ~0;
215 }
216
217 val = (u32)codec->addr << 28;
218 val |= (u32)nid << 20;
219 val |= verb << 8;
220 val |= parm;
221 return val;
222}
223
224/*
225 * Send and receive a verb
226 */ 128 */
227static int codec_exec_verb(struct hda_codec *codec, unsigned int cmd, 129static int codec_exec_verb(struct hdac_device *dev, unsigned int cmd,
228 int flags, unsigned int *res) 130 unsigned int flags, unsigned int *res)
229{ 131{
132 struct hda_codec *codec = container_of(dev, struct hda_codec, core);
230 struct hda_bus *bus = codec->bus; 133 struct hda_bus *bus = codec->bus;
231 int err; 134 int err;
232 135
233 if (cmd == ~0) 136 if (cmd == ~0)
234 return -1; 137 return -1;
235 138
236 if (res)
237 *res = -1;
238 again: 139 again:
239 snd_hda_power_up(codec); 140 snd_hda_power_up_pm(codec);
240 mutex_lock(&bus->cmd_mutex); 141 mutex_lock(&bus->core.cmd_mutex);
241 if (flags & HDA_RW_NO_RESPONSE_FALLBACK) 142 if (flags & HDA_RW_NO_RESPONSE_FALLBACK)
242 bus->no_response_fallback = 1; 143 bus->no_response_fallback = 1;
243 for (;;) { 144 err = snd_hdac_bus_exec_verb_unlocked(&bus->core, codec->core.addr,
244 trace_hda_send_cmd(codec, cmd); 145 cmd, res);
245 err = bus->ops.command(bus, cmd);
246 if (err != -EAGAIN)
247 break;
248 /* process pending verbs */
249 bus->ops.get_response(bus, codec->addr);
250 }
251 if (!err && res) {
252 *res = bus->ops.get_response(bus, codec->addr);
253 trace_hda_get_response(codec, *res);
254 }
255 bus->no_response_fallback = 0; 146 bus->no_response_fallback = 0;
256 mutex_unlock(&bus->cmd_mutex); 147 mutex_unlock(&bus->core.cmd_mutex);
257 snd_hda_power_down(codec); 148 snd_hda_power_down_pm(codec);
258 if (!codec_in_pm(codec) && res && *res == -1 && bus->rirb_error) { 149 if (!codec_in_pm(codec) && res && err < 0 && bus->rirb_error) {
259 if (bus->response_reset) { 150 if (bus->response_reset) {
260 codec_dbg(codec, 151 codec_dbg(codec,
261 "resetting BUS due to fatal communication error\n"); 152 "resetting BUS due to fatal communication error\n");
262 trace_hda_bus_reset(bus);
263 bus->ops.bus_reset(bus); 153 bus->ops.bus_reset(bus);
264 } 154 }
265 goto again; 155 goto again;
@@ -286,9 +176,9 @@ unsigned int snd_hda_codec_read(struct hda_codec *codec, hda_nid_t nid,
286 int flags, 176 int flags,
287 unsigned int verb, unsigned int parm) 177 unsigned int verb, unsigned int parm)
288{ 178{
289 unsigned cmd = make_codec_cmd(codec, nid, flags, verb, parm); 179 unsigned int cmd = snd_hdac_make_cmd(&codec->core, nid, verb, parm);
290 unsigned int res; 180 unsigned int res;
291 if (codec_exec_verb(codec, cmd, flags, &res)) 181 if (snd_hdac_exec_verb(&codec->core, cmd, flags, &res))
292 return -1; 182 return -1;
293 return res; 183 return res;
294} 184}
@@ -309,10 +199,8 @@ EXPORT_SYMBOL_GPL(snd_hda_codec_read);
309int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int flags, 199int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int flags,
310 unsigned int verb, unsigned int parm) 200 unsigned int verb, unsigned int parm)
311{ 201{
312 unsigned int cmd = make_codec_cmd(codec, nid, flags, verb, parm); 202 unsigned int cmd = snd_hdac_make_cmd(&codec->core, nid, verb, parm);
313 unsigned int res; 203 return snd_hdac_exec_verb(&codec->core, cmd, flags, NULL);
314 return codec_exec_verb(codec, cmd, flags,
315 codec->bus->sync_write ? &res : NULL);
316} 204}
317EXPORT_SYMBOL_GPL(snd_hda_codec_write); 205EXPORT_SYMBOL_GPL(snd_hda_codec_write);
318 206
@@ -331,30 +219,6 @@ void snd_hda_sequence_write(struct hda_codec *codec, const struct hda_verb *seq)
331} 219}
332EXPORT_SYMBOL_GPL(snd_hda_sequence_write); 220EXPORT_SYMBOL_GPL(snd_hda_sequence_write);
333 221
334/**
335 * snd_hda_get_sub_nodes - get the range of sub nodes
336 * @codec: the HDA codec
337 * @nid: NID to parse
338 * @start_id: the pointer to store the start NID
339 *
340 * Parse the NID and store the start NID of its sub-nodes.
341 * Returns the number of sub-nodes.
342 */
343int snd_hda_get_sub_nodes(struct hda_codec *codec, hda_nid_t nid,
344 hda_nid_t *start_id)
345{
346 unsigned int parm;
347
348 parm = snd_hda_param_read(codec, nid, AC_PAR_NODE_COUNT);
349 if (parm == -1) {
350 *start_id = 0;
351 return 0;
352 }
353 *start_id = (parm >> 16) & 0x7fff;
354 return (int)(parm & 0x7fff);
355}
356EXPORT_SYMBOL_GPL(snd_hda_get_sub_nodes);
357
358/* connection list element */ 222/* connection list element */
359struct hda_conn_list { 223struct hda_conn_list {
360 struct list_head list; 224 struct list_head list;
@@ -495,128 +359,6 @@ int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
495} 359}
496EXPORT_SYMBOL_GPL(snd_hda_get_connections); 360EXPORT_SYMBOL_GPL(snd_hda_get_connections);
497 361
498/* return CONNLIST_LEN parameter of the given widget */
499static unsigned int get_num_conns(struct hda_codec *codec, hda_nid_t nid)
500{
501 unsigned int wcaps = get_wcaps(codec, nid);
502 unsigned int parm;
503
504 if (!(wcaps & AC_WCAP_CONN_LIST) &&
505 get_wcaps_type(wcaps) != AC_WID_VOL_KNB)
506 return 0;
507
508 parm = snd_hda_param_read(codec, nid, AC_PAR_CONNLIST_LEN);
509 if (parm == -1)
510 parm = 0;
511 return parm;
512}
513
514int snd_hda_get_num_raw_conns(struct hda_codec *codec, hda_nid_t nid)
515{
516 return snd_hda_get_raw_connections(codec, nid, NULL, 0);
517}
518
519/**
520 * snd_hda_get_raw_connections - copy connection list without cache
521 * @codec: the HDA codec
522 * @nid: NID to parse
523 * @conn_list: connection list array
524 * @max_conns: max. number of connections to store
525 *
526 * Like snd_hda_get_connections(), copy the connection list but without
527 * checking through the connection-list cache.
528 * Currently called only from hda_proc.c, so not exported.
529 */
530int snd_hda_get_raw_connections(struct hda_codec *codec, hda_nid_t nid,
531 hda_nid_t *conn_list, int max_conns)
532{
533 unsigned int parm;
534 int i, conn_len, conns;
535 unsigned int shift, num_elems, mask;
536 hda_nid_t prev_nid;
537 int null_count = 0;
538
539 parm = get_num_conns(codec, nid);
540 if (!parm)
541 return 0;
542
543 if (parm & AC_CLIST_LONG) {
544 /* long form */
545 shift = 16;
546 num_elems = 2;
547 } else {
548 /* short form */
549 shift = 8;
550 num_elems = 4;
551 }
552 conn_len = parm & AC_CLIST_LENGTH;
553 mask = (1 << (shift-1)) - 1;
554
555 if (!conn_len)
556 return 0; /* no connection */
557
558 if (conn_len == 1) {
559 /* single connection */
560 parm = snd_hda_codec_read(codec, nid, 0,
561 AC_VERB_GET_CONNECT_LIST, 0);
562 if (parm == -1 && codec->bus->rirb_error)
563 return -EIO;
564 if (conn_list)
565 conn_list[0] = parm & mask;
566 return 1;
567 }
568
569 /* multi connection */
570 conns = 0;
571 prev_nid = 0;
572 for (i = 0; i < conn_len; i++) {
573 int range_val;
574 hda_nid_t val, n;
575
576 if (i % num_elems == 0) {
577 parm = snd_hda_codec_read(codec, nid, 0,
578 AC_VERB_GET_CONNECT_LIST, i);
579 if (parm == -1 && codec->bus->rirb_error)
580 return -EIO;
581 }
582 range_val = !!(parm & (1 << (shift-1))); /* ranges */
583 val = parm & mask;
584 if (val == 0 && null_count++) { /* no second chance */
585 codec_dbg(codec,
586 "invalid CONNECT_LIST verb %x[%i]:%x\n",
587 nid, i, parm);
588 return 0;
589 }
590 parm >>= shift;
591 if (range_val) {
592 /* ranges between the previous and this one */
593 if (!prev_nid || prev_nid >= val) {
594 codec_warn(codec,
595 "invalid dep_range_val %x:%x\n",
596 prev_nid, val);
597 continue;
598 }
599 for (n = prev_nid + 1; n <= val; n++) {
600 if (conn_list) {
601 if (conns >= max_conns)
602 return -ENOSPC;
603 conn_list[conns] = n;
604 }
605 conns++;
606 }
607 } else {
608 if (conn_list) {
609 if (conns >= max_conns)
610 return -ENOSPC;
611 conn_list[conns] = val;
612 }
613 conns++;
614 }
615 prev_nid = val;
616 }
617 return conns;
618}
619
620/** 362/**
621 * snd_hda_override_conn_list - add/modify the connection-list to cache 363 * snd_hda_override_conn_list - add/modify the connection-list to cache
622 * @codec: the HDA codec 364 * @codec: the HDA codec
@@ -741,90 +483,6 @@ int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid,
741 return devices; 483 return devices;
742} 484}
743 485
744/**
745 * snd_hda_queue_unsol_event - add an unsolicited event to queue
746 * @bus: the BUS
747 * @res: unsolicited event (lower 32bit of RIRB entry)
748 * @res_ex: codec addr and flags (upper 32bit or RIRB entry)
749 *
750 * Adds the given event to the queue. The events are processed in
751 * the workqueue asynchronously. Call this function in the interrupt
752 * hanlder when RIRB receives an unsolicited event.
753 *
754 * Returns 0 if successful, or a negative error code.
755 */
756int snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex)
757{
758 struct hda_bus_unsolicited *unsol;
759 unsigned int wp;
760
761 if (!bus || !bus->workq)
762 return 0;
763
764 trace_hda_unsol_event(bus, res, res_ex);
765 unsol = bus->unsol;
766 if (!unsol)
767 return 0;
768
769 wp = (unsol->wp + 1) % HDA_UNSOL_QUEUE_SIZE;
770 unsol->wp = wp;
771
772 wp <<= 1;
773 unsol->queue[wp] = res;
774 unsol->queue[wp + 1] = res_ex;
775
776 queue_work(bus->workq, &unsol->work);
777
778 return 0;
779}
780EXPORT_SYMBOL_GPL(snd_hda_queue_unsol_event);
781
782/*
783 * process queued unsolicited events
784 */
785static void process_unsol_events(struct work_struct *work)
786{
787 struct hda_bus_unsolicited *unsol =
788 container_of(work, struct hda_bus_unsolicited, work);
789 struct hda_bus *bus = unsol->bus;
790 struct hda_codec *codec;
791 unsigned int rp, caddr, res;
792
793 while (unsol->rp != unsol->wp) {
794 rp = (unsol->rp + 1) % HDA_UNSOL_QUEUE_SIZE;
795 unsol->rp = rp;
796 rp <<= 1;
797 res = unsol->queue[rp];
798 caddr = unsol->queue[rp + 1];
799 if (!(caddr & (1 << 4))) /* no unsolicited event? */
800 continue;
801 codec = bus->caddr_tbl[caddr & 0x0f];
802 if (codec && codec->patch_ops.unsol_event)
803 codec->patch_ops.unsol_event(codec, res);
804 }
805}
806
807/*
808 * initialize unsolicited queue
809 */
810static int init_unsol_queue(struct hda_bus *bus)
811{
812 struct hda_bus_unsolicited *unsol;
813
814 if (bus->unsol) /* already initialized */
815 return 0;
816
817 unsol = kzalloc(sizeof(*unsol), GFP_KERNEL);
818 if (!unsol) {
819 dev_err(bus->card->dev, "can't allocate unsolicited queue\n");
820 return -ENOMEM;
821 }
822 INIT_WORK(&unsol->work, process_unsol_events);
823 unsol->bus = bus;
824 bus->unsol = unsol;
825 return 0;
826}
827
828/* 486/*
829 * destructor 487 * destructor
830 */ 488 */
@@ -832,16 +490,9 @@ static void snd_hda_bus_free(struct hda_bus *bus)
832{ 490{
833 if (!bus) 491 if (!bus)
834 return; 492 return;
835
836 WARN_ON(!list_empty(&bus->codec_list));
837 if (bus->workq)
838 flush_workqueue(bus->workq);
839 kfree(bus->unsol);
840 if (bus->ops.private_free) 493 if (bus->ops.private_free)
841 bus->ops.private_free(bus); 494 bus->ops.private_free(bus);
842 if (bus->workq) 495 snd_hdac_bus_exit(&bus->core);
843 destroy_workqueue(bus->workq);
844
845 kfree(bus); 496 kfree(bus);
846} 497}
847 498
@@ -858,17 +509,35 @@ static int snd_hda_bus_dev_disconnect(struct snd_device *device)
858 return 0; 509 return 0;
859} 510}
860 511
512/* hdac_bus_ops translations */
513static int _hda_bus_command(struct hdac_bus *_bus, unsigned int cmd)
514{
515 struct hda_bus *bus = container_of(_bus, struct hda_bus, core);
516 return bus->ops.command(bus, cmd);
517}
518
519static int _hda_bus_get_response(struct hdac_bus *_bus, unsigned int addr,
520 unsigned int *res)
521{
522 struct hda_bus *bus = container_of(_bus, struct hda_bus, core);
523 *res = bus->ops.get_response(bus, addr);
524 return bus->rirb_error ? -EIO : 0;
525}
526
527static const struct hdac_bus_ops bus_ops = {
528 .command = _hda_bus_command,
529 .get_response = _hda_bus_get_response,
530};
531
861/** 532/**
862 * snd_hda_bus_new - create a HDA bus 533 * snd_hda_bus_new - create a HDA bus
863 * @card: the card entry 534 * @card: the card entry
864 * @temp: the template for hda_bus information
865 * @busp: the pointer to store the created bus instance 535 * @busp: the pointer to store the created bus instance
866 * 536 *
867 * Returns 0 if successful, or a negative error code. 537 * Returns 0 if successful, or a negative error code.
868 */ 538 */
869int snd_hda_bus_new(struct snd_card *card, 539int snd_hda_bus_new(struct snd_card *card,
870 const struct hda_bus_template *temp, 540 struct hda_bus **busp)
871 struct hda_bus **busp)
872{ 541{
873 struct hda_bus *bus; 542 struct hda_bus *bus;
874 int err; 543 int err;
@@ -877,40 +546,21 @@ int snd_hda_bus_new(struct snd_card *card,
877 .dev_free = snd_hda_bus_dev_free, 546 .dev_free = snd_hda_bus_dev_free,
878 }; 547 };
879 548
880 if (snd_BUG_ON(!temp))
881 return -EINVAL;
882 if (snd_BUG_ON(!temp->ops.command || !temp->ops.get_response))
883 return -EINVAL;
884
885 if (busp) 549 if (busp)
886 *busp = NULL; 550 *busp = NULL;
887 551
888 bus = kzalloc(sizeof(*bus), GFP_KERNEL); 552 bus = kzalloc(sizeof(*bus), GFP_KERNEL);
889 if (bus == NULL) { 553 if (!bus)
890 dev_err(card->dev, "can't allocate struct hda_bus\n");
891 return -ENOMEM; 554 return -ENOMEM;
555
556 err = snd_hdac_bus_init(&bus->core, card->dev, &bus_ops);
557 if (err < 0) {
558 kfree(bus);
559 return err;
892 } 560 }
893 561
894 bus->card = card; 562 bus->card = card;
895 bus->private_data = temp->private_data;
896 bus->pci = temp->pci;
897 bus->modelname = temp->modelname;
898 bus->power_save = temp->power_save;
899 bus->ops = temp->ops;
900
901 mutex_init(&bus->cmd_mutex);
902 mutex_init(&bus->prepare_mutex); 563 mutex_init(&bus->prepare_mutex);
903 INIT_LIST_HEAD(&bus->codec_list);
904
905 snprintf(bus->workq_name, sizeof(bus->workq_name),
906 "hd-audio%d", card->number);
907 bus->workq = create_singlethread_workqueue(bus->workq_name);
908 if (!bus->workq) {
909 dev_err(card->dev, "cannot create workqueue %s\n",
910 bus->workq_name);
911 kfree(bus);
912 return -ENOMEM;
913 }
914 564
915 err = snd_device_new(card, SNDRV_DEV_BUS, bus, &dev_ops); 565 err = snd_device_new(card, SNDRV_DEV_BUS, bus, &dev_ops);
916 if (err < 0) { 566 if (err < 0) {
@@ -923,140 +573,6 @@ int snd_hda_bus_new(struct snd_card *card,
923} 573}
924EXPORT_SYMBOL_GPL(snd_hda_bus_new); 574EXPORT_SYMBOL_GPL(snd_hda_bus_new);
925 575
926#if IS_ENABLED(CONFIG_SND_HDA_GENERIC)
927#define is_generic_config(codec) \
928 (codec->modelname && !strcmp(codec->modelname, "generic"))
929#else
930#define is_generic_config(codec) 0
931#endif
932
933#ifdef MODULE
934#define HDA_MODREQ_MAX_COUNT 2 /* two request_modules()'s */
935#else
936#define HDA_MODREQ_MAX_COUNT 0 /* all presets are statically linked */
937#endif
938
939/*
940 * find a matching codec preset
941 */
942static const struct hda_codec_preset *
943find_codec_preset(struct hda_codec *codec)
944{
945 struct hda_codec_preset_list *tbl;
946 const struct hda_codec_preset *preset;
947 unsigned int mod_requested = 0;
948
949 again:
950 mutex_lock(&preset_mutex);
951 list_for_each_entry(tbl, &hda_preset_tables, list) {
952 if (!try_module_get(tbl->owner)) {
953 codec_err(codec, "cannot module_get\n");
954 continue;
955 }
956 for (preset = tbl->preset; preset->id; preset++) {
957 u32 mask = preset->mask;
958 if (preset->afg && preset->afg != codec->afg)
959 continue;
960 if (preset->mfg && preset->mfg != codec->mfg)
961 continue;
962 if (!mask)
963 mask = ~0;
964 if (preset->id == (codec->vendor_id & mask) &&
965 (!preset->rev ||
966 preset->rev == codec->revision_id)) {
967 mutex_unlock(&preset_mutex);
968 codec->owner = tbl->owner;
969 return preset;
970 }
971 }
972 module_put(tbl->owner);
973 }
974 mutex_unlock(&preset_mutex);
975
976 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
977 if (!mod_requested)
978 request_module("snd-hda-codec-id:%08x",
979 codec->vendor_id);
980 else
981 request_module("snd-hda-codec-id:%04x*",
982 (codec->vendor_id >> 16) & 0xffff);
983 mod_requested++;
984 goto again;
985 }
986 return NULL;
987}
988
989/*
990 * get_codec_name - store the codec name
991 */
992static int get_codec_name(struct hda_codec *codec)
993{
994 const struct hda_vendor_id *c;
995 const char *vendor = NULL;
996 u16 vendor_id = codec->vendor_id >> 16;
997 char tmp[16];
998
999 if (codec->vendor_name)
1000 goto get_chip_name;
1001
1002 for (c = hda_vendor_ids; c->id; c++) {
1003 if (c->id == vendor_id) {
1004 vendor = c->name;
1005 break;
1006 }
1007 }
1008 if (!vendor) {
1009 sprintf(tmp, "Generic %04x", vendor_id);
1010 vendor = tmp;
1011 }
1012 codec->vendor_name = kstrdup(vendor, GFP_KERNEL);
1013 if (!codec->vendor_name)
1014 return -ENOMEM;
1015
1016 get_chip_name:
1017 if (codec->chip_name)
1018 return 0;
1019
1020 if (codec->preset && codec->preset->name)
1021 codec->chip_name = kstrdup(codec->preset->name, GFP_KERNEL);
1022 else {
1023 sprintf(tmp, "ID %x", codec->vendor_id & 0xffff);
1024 codec->chip_name = kstrdup(tmp, GFP_KERNEL);
1025 }
1026 if (!codec->chip_name)
1027 return -ENOMEM;
1028 return 0;
1029}
1030
1031/*
1032 * look for an AFG and MFG nodes
1033 */
1034static void setup_fg_nodes(struct hda_codec *codec)
1035{
1036 int i, total_nodes, function_id;
1037 hda_nid_t nid;
1038
1039 total_nodes = snd_hda_get_sub_nodes(codec, AC_NODE_ROOT, &nid);
1040 for (i = 0; i < total_nodes; i++, nid++) {
1041 function_id = snd_hda_param_read(codec, nid,
1042 AC_PAR_FUNCTION_TYPE);
1043 switch (function_id & 0xff) {
1044 case AC_GRP_AUDIO_FUNCTION:
1045 codec->afg = nid;
1046 codec->afg_function_id = function_id & 0xff;
1047 codec->afg_unsol = (function_id >> 8) & 1;
1048 break;
1049 case AC_GRP_MODEM_FUNCTION:
1050 codec->mfg = nid;
1051 codec->mfg_function_id = function_id & 0xff;
1052 codec->mfg_unsol = (function_id >> 8) & 1;
1053 break;
1054 default:
1055 break;
1056 }
1057 }
1058}
1059
1060/* 576/*
1061 * read widget caps for each widget and store in cache 577 * read widget caps for each widget and store in cache
1062 */ 578 */
@@ -1065,25 +581,22 @@ static int read_widget_caps(struct hda_codec *codec, hda_nid_t fg_node)
1065 int i; 581 int i;
1066 hda_nid_t nid; 582 hda_nid_t nid;
1067 583
1068 codec->num_nodes = snd_hda_get_sub_nodes(codec, fg_node, 584 codec->wcaps = kmalloc(codec->core.num_nodes * 4, GFP_KERNEL);
1069 &codec->start_nid);
1070 codec->wcaps = kmalloc(codec->num_nodes * 4, GFP_KERNEL);
1071 if (!codec->wcaps) 585 if (!codec->wcaps)
1072 return -ENOMEM; 586 return -ENOMEM;
1073 nid = codec->start_nid; 587 nid = codec->core.start_nid;
1074 for (i = 0; i < codec->num_nodes; i++, nid++) 588 for (i = 0; i < codec->core.num_nodes; i++, nid++)
1075 codec->wcaps[i] = snd_hda_param_read(codec, nid, 589 codec->wcaps[i] = snd_hdac_read_parm_uncached(&codec->core,
1076 AC_PAR_AUDIO_WIDGET_CAP); 590 nid, AC_PAR_AUDIO_WIDGET_CAP);
1077 return 0; 591 return 0;
1078} 592}
1079 593
1080/* read all pin default configurations and save codec->init_pins */ 594/* read all pin default configurations and save codec->init_pins */
1081static int read_pin_defaults(struct hda_codec *codec) 595static int read_pin_defaults(struct hda_codec *codec)
1082{ 596{
1083 int i; 597 hda_nid_t nid;
1084 hda_nid_t nid = codec->start_nid;
1085 598
1086 for (i = 0; i < codec->num_nodes; i++, nid++) { 599 for_each_hda_codec_node(nid, codec) {
1087 struct hda_pincfg *pin; 600 struct hda_pincfg *pin;
1088 unsigned int wcaps = get_wcaps(codec, nid); 601 unsigned int wcaps = get_wcaps(codec, nid);
1089 unsigned int wid_type = get_wcaps_type(wcaps); 602 unsigned int wid_type = get_wcaps_type(wcaps);
@@ -1290,14 +803,10 @@ static void hda_jackpoll_work(struct work_struct *work)
1290 if (!codec->jackpoll_interval) 803 if (!codec->jackpoll_interval)
1291 return; 804 return;
1292 805
1293 queue_delayed_work(codec->bus->workq, &codec->jackpoll_work, 806 schedule_delayed_work(&codec->jackpoll_work,
1294 codec->jackpoll_interval); 807 codec->jackpoll_interval);
1295} 808}
1296 809
1297static void init_hda_cache(struct hda_cache_rec *cache,
1298 unsigned int record_size);
1299static void free_hda_cache(struct hda_cache_rec *cache);
1300
1301/* release all pincfg lists */ 810/* release all pincfg lists */
1302static void free_init_pincfgs(struct hda_codec *codec) 811static void free_init_pincfgs(struct hda_codec *codec)
1303{ 812{
@@ -1339,70 +848,117 @@ get_hda_cvt_setup(struct hda_codec *codec, hda_nid_t nid)
1339} 848}
1340 849
1341/* 850/*
1342 * Dynamic symbol binding for the codec parsers 851 * PCM device
1343 */ 852 */
853static void release_pcm(struct kref *kref)
854{
855 struct hda_pcm *pcm = container_of(kref, struct hda_pcm, kref);
856
857 if (pcm->pcm)
858 snd_device_free(pcm->codec->card, pcm->pcm);
859 clear_bit(pcm->device, pcm->codec->bus->pcm_dev_bits);
860 kfree(pcm->name);
861 kfree(pcm);
862}
1344 863
1345#define load_parser(codec, sym) \ 864void snd_hda_codec_pcm_put(struct hda_pcm *pcm)
1346 ((codec)->parser = (int (*)(struct hda_codec *))symbol_request(sym)) 865{
866 kref_put(&pcm->kref, release_pcm);
867}
868EXPORT_SYMBOL_GPL(snd_hda_codec_pcm_put);
1347 869
1348static void unload_parser(struct hda_codec *codec) 870struct hda_pcm *snd_hda_codec_pcm_new(struct hda_codec *codec,
871 const char *fmt, ...)
1349{ 872{
1350 if (codec->parser) 873 struct hda_pcm *pcm;
1351 symbol_put_addr(codec->parser); 874 va_list args;
1352 codec->parser = NULL; 875
876 va_start(args, fmt);
877 pcm = kzalloc(sizeof(*pcm), GFP_KERNEL);
878 if (!pcm)
879 return NULL;
880
881 pcm->codec = codec;
882 kref_init(&pcm->kref);
883 pcm->name = kvasprintf(GFP_KERNEL, fmt, args);
884 if (!pcm->name) {
885 kfree(pcm);
886 return NULL;
887 }
888
889 list_add_tail(&pcm->list, &codec->pcm_list_head);
890 return pcm;
1353} 891}
892EXPORT_SYMBOL_GPL(snd_hda_codec_pcm_new);
1354 893
1355/* 894/*
1356 * codec destructor 895 * codec destructor
1357 */ 896 */
1358static void snd_hda_codec_free(struct hda_codec *codec) 897static void codec_release_pcms(struct hda_codec *codec)
1359{ 898{
1360 if (!codec) 899 struct hda_pcm *pcm, *n;
1361 return; 900
901 list_for_each_entry_safe(pcm, n, &codec->pcm_list_head, list) {
902 list_del_init(&pcm->list);
903 if (pcm->pcm)
904 snd_device_disconnect(codec->card, pcm->pcm);
905 snd_hda_codec_pcm_put(pcm);
906 }
907}
908
909void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec)
910{
911 if (codec->registered) {
912 /* pm_runtime_put() is called in snd_hdac_device_exit() */
913 pm_runtime_get_noresume(hda_codec_dev(codec));
914 pm_runtime_disable(hda_codec_dev(codec));
915 codec->registered = 0;
916 }
917
1362 cancel_delayed_work_sync(&codec->jackpoll_work); 918 cancel_delayed_work_sync(&codec->jackpoll_work);
919 if (!codec->in_freeing)
920 snd_hda_ctls_clear(codec);
921 codec_release_pcms(codec);
922 snd_hda_detach_beep_device(codec);
923 memset(&codec->patch_ops, 0, sizeof(codec->patch_ops));
1363 snd_hda_jack_tbl_clear(codec); 924 snd_hda_jack_tbl_clear(codec);
1364 free_init_pincfgs(codec); 925 codec->proc_widget_hook = NULL;
1365#ifdef CONFIG_PM 926 codec->spec = NULL;
1366 cancel_delayed_work(&codec->power_work); 927
1367 flush_workqueue(codec->bus->workq); 928 /* free only driver_pins so that init_pins + user_pins are restored */
1368#endif 929 snd_array_free(&codec->driver_pins);
1369 list_del(&codec->list);
1370 snd_array_free(&codec->mixers);
1371 snd_array_free(&codec->nids);
1372 snd_array_free(&codec->cvt_setups); 930 snd_array_free(&codec->cvt_setups);
1373 snd_array_free(&codec->spdif_out); 931 snd_array_free(&codec->spdif_out);
932 snd_array_free(&codec->verbs);
933 codec->preset = NULL;
934 codec->slave_dig_outs = NULL;
935 codec->spdif_status_reset = 0;
936 snd_array_free(&codec->mixers);
937 snd_array_free(&codec->nids);
1374 remove_conn_list(codec); 938 remove_conn_list(codec);
1375 codec->bus->caddr_tbl[codec->addr] = NULL; 939 snd_hdac_regmap_exit(&codec->core);
1376 if (codec->patch_ops.free)
1377 codec->patch_ops.free(codec);
1378 hda_call_pm_notify(codec, false); /* cancel leftover refcounts */
1379 snd_hda_sysfs_clear(codec);
1380 unload_parser(codec);
1381 module_put(codec->owner);
1382 free_hda_cache(&codec->amp_cache);
1383 free_hda_cache(&codec->cmd_cache);
1384 kfree(codec->vendor_name);
1385 kfree(codec->chip_name);
1386 kfree(codec->modelname);
1387 kfree(codec->wcaps);
1388 codec->bus->num_codecs--;
1389 put_device(&codec->dev);
1390} 940}
1391 941
1392static bool snd_hda_codec_get_supported_ps(struct hda_codec *codec,
1393 hda_nid_t fg, unsigned int power_state);
1394
1395static unsigned int hda_set_power_state(struct hda_codec *codec, 942static unsigned int hda_set_power_state(struct hda_codec *codec,
1396 unsigned int power_state); 943 unsigned int power_state);
1397 944
1398static int snd_hda_codec_dev_register(struct snd_device *device) 945/* also called from hda_bind.c */
946void snd_hda_codec_register(struct hda_codec *codec)
1399{ 947{
1400 struct hda_codec *codec = device->device_data; 948 if (codec->registered)
1401 int err = device_add(&codec->dev); 949 return;
950 if (device_is_registered(hda_codec_dev(codec))) {
951 snd_hda_register_beep_device(codec);
952 pm_runtime_enable(hda_codec_dev(codec));
953 /* it was powered up in snd_hda_codec_new(), now all done */
954 snd_hda_power_down(codec);
955 codec->registered = 1;
956 }
957}
1402 958
1403 if (err < 0) 959static int snd_hda_codec_dev_register(struct snd_device *device)
1404 return err; 960{
1405 snd_hda_register_beep_device(codec); 961 snd_hda_codec_register(device->device_data);
1406 return 0; 962 return 0;
1407} 963}
1408 964
@@ -1411,20 +967,29 @@ static int snd_hda_codec_dev_disconnect(struct snd_device *device)
1411 struct hda_codec *codec = device->device_data; 967 struct hda_codec *codec = device->device_data;
1412 968
1413 snd_hda_detach_beep_device(codec); 969 snd_hda_detach_beep_device(codec);
1414 device_del(&codec->dev);
1415 return 0; 970 return 0;
1416} 971}
1417 972
1418static int snd_hda_codec_dev_free(struct snd_device *device) 973static int snd_hda_codec_dev_free(struct snd_device *device)
1419{ 974{
1420 snd_hda_codec_free(device->device_data); 975 struct hda_codec *codec = device->device_data;
976
977 codec->in_freeing = 1;
978 snd_hdac_device_unregister(&codec->core);
979 put_device(hda_codec_dev(codec));
1421 return 0; 980 return 0;
1422} 981}
1423 982
1424/* just free the container */
1425static void snd_hda_codec_dev_release(struct device *dev) 983static void snd_hda_codec_dev_release(struct device *dev)
1426{ 984{
1427 kfree(container_of(dev, struct hda_codec, dev)); 985 struct hda_codec *codec = dev_to_hda_codec(dev);
986
987 free_init_pincfgs(codec);
988 snd_hdac_device_exit(&codec->core);
989 snd_hda_sysfs_clear(codec);
990 kfree(codec->modelname);
991 kfree(codec->wcaps);
992 kfree(codec);
1428} 993}
1429 994
1430/** 995/**
@@ -1435,9 +1000,8 @@ static void snd_hda_codec_dev_release(struct device *dev)
1435 * 1000 *
1436 * Returns 0 if successful, or a negative error code. 1001 * Returns 0 if successful, or a negative error code.
1437 */ 1002 */
1438int snd_hda_codec_new(struct hda_bus *bus, 1003int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card,
1439 unsigned int codec_addr, 1004 unsigned int codec_addr, struct hda_codec **codecp)
1440 struct hda_codec **codecp)
1441{ 1005{
1442 struct hda_codec *codec; 1006 struct hda_codec *codec;
1443 char component[31]; 1007 char component[31];
@@ -1454,35 +1018,27 @@ int snd_hda_codec_new(struct hda_bus *bus,
1454 if (snd_BUG_ON(codec_addr > HDA_MAX_CODEC_ADDRESS)) 1018 if (snd_BUG_ON(codec_addr > HDA_MAX_CODEC_ADDRESS))
1455 return -EINVAL; 1019 return -EINVAL;
1456 1020
1457 if (bus->caddr_tbl[codec_addr]) {
1458 dev_err(bus->card->dev,
1459 "address 0x%x is already occupied\n",
1460 codec_addr);
1461 return -EBUSY;
1462 }
1463
1464 codec = kzalloc(sizeof(*codec), GFP_KERNEL); 1021 codec = kzalloc(sizeof(*codec), GFP_KERNEL);
1465 if (codec == NULL) { 1022 if (!codec)
1466 dev_err(bus->card->dev, "can't allocate struct hda_codec\n");
1467 return -ENOMEM; 1023 return -ENOMEM;
1024
1025 sprintf(component, "hdaudioC%dD%d", card->number, codec_addr);
1026 err = snd_hdac_device_init(&codec->core, &bus->core, component,
1027 codec_addr);
1028 if (err < 0) {
1029 kfree(codec);
1030 return err;
1468 } 1031 }
1469 1032
1470 device_initialize(&codec->dev); 1033 codec->core.dev.release = snd_hda_codec_dev_release;
1471 codec->dev.parent = &bus->card->card_dev; 1034 codec->core.type = HDA_DEV_LEGACY;
1472 codec->dev.class = sound_class; 1035 codec->core.exec_verb = codec_exec_verb;
1473 codec->dev.release = snd_hda_codec_dev_release;
1474 codec->dev.groups = snd_hda_dev_attr_groups;
1475 dev_set_name(&codec->dev, "hdaudioC%dD%d", bus->card->number,
1476 codec_addr);
1477 dev_set_drvdata(&codec->dev, codec); /* for sysfs */
1478 1036
1479 codec->bus = bus; 1037 codec->bus = bus;
1038 codec->card = card;
1480 codec->addr = codec_addr; 1039 codec->addr = codec_addr;
1481 mutex_init(&codec->spdif_mutex); 1040 mutex_init(&codec->spdif_mutex);
1482 mutex_init(&codec->control_mutex); 1041 mutex_init(&codec->control_mutex);
1483 mutex_init(&codec->hash_mutex);
1484 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info));
1485 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head));
1486 snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 32); 1042 snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 32);
1487 snd_array_init(&codec->nids, sizeof(struct hda_nid_item), 32); 1043 snd_array_init(&codec->nids, sizeof(struct hda_nid_item), 32);
1488 snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16); 1044 snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16);
@@ -1492,19 +1048,14 @@ int snd_hda_codec_new(struct hda_bus *bus,
1492 snd_array_init(&codec->jacktbl, sizeof(struct hda_jack_tbl), 16); 1048 snd_array_init(&codec->jacktbl, sizeof(struct hda_jack_tbl), 16);
1493 snd_array_init(&codec->verbs, sizeof(struct hda_verb *), 8); 1049 snd_array_init(&codec->verbs, sizeof(struct hda_verb *), 8);
1494 INIT_LIST_HEAD(&codec->conn_list); 1050 INIT_LIST_HEAD(&codec->conn_list);
1051 INIT_LIST_HEAD(&codec->pcm_list_head);
1495 1052
1496 INIT_DELAYED_WORK(&codec->jackpoll_work, hda_jackpoll_work); 1053 INIT_DELAYED_WORK(&codec->jackpoll_work, hda_jackpoll_work);
1497 codec->depop_delay = -1; 1054 codec->depop_delay = -1;
1498 codec->fixup_id = HDA_FIXUP_ID_NOT_SET; 1055 codec->fixup_id = HDA_FIXUP_ID_NOT_SET;
1499 1056
1500#ifdef CONFIG_PM 1057#ifdef CONFIG_PM
1501 spin_lock_init(&codec->power_lock); 1058 codec->power_jiffies = jiffies;
1502 INIT_DELAYED_WORK(&codec->power_work, hda_power_work);
1503 /* snd_hda_codec_new() marks the codec as power-up, and leave it as is.
1504 * the caller has to power down appropriatley after initialization
1505 * phase.
1506 */
1507 hda_keep_power_on(codec);
1508#endif 1059#endif
1509 1060
1510 snd_hda_sysfs_init(codec); 1061 snd_hda_sysfs_init(codec);
@@ -1517,59 +1068,14 @@ int snd_hda_codec_new(struct hda_bus *bus,
1517 } 1068 }
1518 } 1069 }
1519 1070
1520 list_add_tail(&codec->list, &bus->codec_list); 1071 fg = codec->core.afg ? codec->core.afg : codec->core.mfg;
1521 bus->num_codecs++;
1522
1523 bus->caddr_tbl[codec_addr] = codec;
1524
1525 codec->vendor_id = snd_hda_param_read(codec, AC_NODE_ROOT,
1526 AC_PAR_VENDOR_ID);
1527 if (codec->vendor_id == -1)
1528 /* read again, hopefully the access method was corrected
1529 * in the last read...
1530 */
1531 codec->vendor_id = snd_hda_param_read(codec, AC_NODE_ROOT,
1532 AC_PAR_VENDOR_ID);
1533 codec->subsystem_id = snd_hda_param_read(codec, AC_NODE_ROOT,
1534 AC_PAR_SUBSYSTEM_ID);
1535 codec->revision_id = snd_hda_param_read(codec, AC_NODE_ROOT,
1536 AC_PAR_REV_ID);
1537
1538 setup_fg_nodes(codec);
1539 if (!codec->afg && !codec->mfg) {
1540 dev_err(bus->card->dev, "no AFG or MFG node found\n");
1541 err = -ENODEV;
1542 goto error;
1543 }
1544
1545 fg = codec->afg ? codec->afg : codec->mfg;
1546 err = read_widget_caps(codec, fg); 1072 err = read_widget_caps(codec, fg);
1547 if (err < 0) { 1073 if (err < 0)
1548 dev_err(bus->card->dev, "cannot malloc\n");
1549 goto error; 1074 goto error;
1550 }
1551 err = read_pin_defaults(codec); 1075 err = read_pin_defaults(codec);
1552 if (err < 0) 1076 if (err < 0)
1553 goto error; 1077 goto error;
1554 1078
1555 if (!codec->subsystem_id) {
1556 codec->subsystem_id =
1557 snd_hda_codec_read(codec, fg, 0,
1558 AC_VERB_GET_SUBSYSTEM_ID, 0);
1559 }
1560
1561#ifdef CONFIG_PM
1562 codec->d3_stop_clk = snd_hda_codec_get_supported_ps(codec, fg,
1563 AC_PWRST_CLKSTOP);
1564#endif
1565 codec->epss = snd_hda_codec_get_supported_ps(codec, fg,
1566 AC_PWRST_EPSS);
1567#ifdef CONFIG_PM
1568 if (!codec->d3_stop_clk || !codec->epss)
1569 bus->power_keep_link_on = 1;
1570#endif
1571
1572
1573 /* power-up all before initialization */ 1079 /* power-up all before initialization */
1574 hda_set_power_state(codec, AC_PWRST_D0); 1080 hda_set_power_state(codec, AC_PWRST_D0);
1575 1081
@@ -1577,11 +1083,11 @@ int snd_hda_codec_new(struct hda_bus *bus,
1577 1083
1578 snd_hda_create_hwdep(codec); 1084 snd_hda_create_hwdep(codec);
1579 1085
1580 sprintf(component, "HDA:%08x,%08x,%08x", codec->vendor_id, 1086 sprintf(component, "HDA:%08x,%08x,%08x", codec->core.vendor_id,
1581 codec->subsystem_id, codec->revision_id); 1087 codec->core.subsystem_id, codec->core.revision_id);
1582 snd_component_add(codec->bus->card, component); 1088 snd_component_add(card, component);
1583 1089
1584 err = snd_device_new(bus->card, SNDRV_DEV_CODEC, codec, &dev_ops); 1090 err = snd_device_new(card, SNDRV_DEV_CODEC, codec, &dev_ops);
1585 if (err < 0) 1091 if (err < 0)
1586 goto error; 1092 goto error;
1587 1093
@@ -1590,7 +1096,7 @@ int snd_hda_codec_new(struct hda_bus *bus,
1590 return 0; 1096 return 0;
1591 1097
1592 error: 1098 error:
1593 snd_hda_codec_free(codec); 1099 put_device(hda_codec_dev(codec));
1594 return err; 1100 return err;
1595} 1101}
1596EXPORT_SYMBOL_GPL(snd_hda_codec_new); 1102EXPORT_SYMBOL_GPL(snd_hda_codec_new);
@@ -1607,16 +1113,18 @@ int snd_hda_codec_update_widgets(struct hda_codec *codec)
1607 hda_nid_t fg; 1113 hda_nid_t fg;
1608 int err; 1114 int err;
1609 1115
1116 err = snd_hdac_refresh_widgets(&codec->core);
1117 if (err < 0)
1118 return err;
1119
1610 /* Assume the function group node does not change, 1120 /* Assume the function group node does not change,
1611 * only the widget nodes may change. 1121 * only the widget nodes may change.
1612 */ 1122 */
1613 kfree(codec->wcaps); 1123 kfree(codec->wcaps);
1614 fg = codec->afg ? codec->afg : codec->mfg; 1124 fg = codec->core.afg ? codec->core.afg : codec->core.mfg;
1615 err = read_widget_caps(codec, fg); 1125 err = read_widget_caps(codec, fg);
1616 if (err < 0) { 1126 if (err < 0)
1617 codec_err(codec, "cannot malloc\n");
1618 return err; 1127 return err;
1619 }
1620 1128
1621 snd_array_free(&codec->init_pins); 1129 snd_array_free(&codec->init_pins);
1622 err = read_pin_defaults(codec); 1130 err = read_pin_defaults(codec);
@@ -1625,98 +1133,6 @@ int snd_hda_codec_update_widgets(struct hda_codec *codec)
1625} 1133}
1626EXPORT_SYMBOL_GPL(snd_hda_codec_update_widgets); 1134EXPORT_SYMBOL_GPL(snd_hda_codec_update_widgets);
1627 1135
1628
1629#if IS_ENABLED(CONFIG_SND_HDA_CODEC_HDMI)
1630/* if all audio out widgets are digital, let's assume the codec as a HDMI/DP */
1631static bool is_likely_hdmi_codec(struct hda_codec *codec)
1632{
1633 hda_nid_t nid = codec->start_nid;
1634 int i;
1635
1636 for (i = 0; i < codec->num_nodes; i++, nid++) {
1637 unsigned int wcaps = get_wcaps(codec, nid);
1638 switch (get_wcaps_type(wcaps)) {
1639 case AC_WID_AUD_IN:
1640 return false; /* HDMI parser supports only HDMI out */
1641 case AC_WID_AUD_OUT:
1642 if (!(wcaps & AC_WCAP_DIGITAL))
1643 return false;
1644 break;
1645 }
1646 }
1647 return true;
1648}
1649#else
1650/* no HDMI codec parser support */
1651#define is_likely_hdmi_codec(codec) false
1652#endif /* CONFIG_SND_HDA_CODEC_HDMI */
1653
1654/**
1655 * snd_hda_codec_configure - (Re-)configure the HD-audio codec
1656 * @codec: the HDA codec
1657 *
1658 * Start parsing of the given codec tree and (re-)initialize the whole
1659 * patch instance.
1660 *
1661 * Returns 0 if successful or a negative error code.
1662 */
1663int snd_hda_codec_configure(struct hda_codec *codec)
1664{
1665 int (*patch)(struct hda_codec *) = NULL;
1666 int err;
1667
1668 codec->preset = find_codec_preset(codec);
1669 if (!codec->vendor_name || !codec->chip_name) {
1670 err = get_codec_name(codec);
1671 if (err < 0)
1672 return err;
1673 }
1674
1675 if (!is_generic_config(codec) && codec->preset)
1676 patch = codec->preset->patch;
1677 if (!patch) {
1678 unload_parser(codec); /* to be sure */
1679 if (is_likely_hdmi_codec(codec)) {
1680#if IS_MODULE(CONFIG_SND_HDA_CODEC_HDMI)
1681 patch = load_parser(codec, snd_hda_parse_hdmi_codec);
1682#elif IS_BUILTIN(CONFIG_SND_HDA_CODEC_HDMI)
1683 patch = snd_hda_parse_hdmi_codec;
1684#endif
1685 }
1686 if (!patch) {
1687#if IS_MODULE(CONFIG_SND_HDA_GENERIC)
1688 patch = load_parser(codec, snd_hda_parse_generic_codec);
1689#elif IS_BUILTIN(CONFIG_SND_HDA_GENERIC)
1690 patch = snd_hda_parse_generic_codec;
1691#endif
1692 }
1693 if (!patch) {
1694 codec_err(codec, "No codec parser is available\n");
1695 return -ENODEV;
1696 }
1697 }
1698
1699 err = patch(codec);
1700 if (err < 0) {
1701 unload_parser(codec);
1702 return err;
1703 }
1704
1705 if (codec->patch_ops.unsol_event) {
1706 err = init_unsol_queue(codec->bus);
1707 if (err < 0)
1708 return err;
1709 }
1710
1711 /* audio codec should override the mixer name */
1712 if (codec->afg || !*codec->bus->card->mixername)
1713 snprintf(codec->bus->card->mixername,
1714 sizeof(codec->bus->card->mixername),
1715 "%s %s", codec->vendor_name, codec->chip_name);
1716 return 0;
1717}
1718EXPORT_SYMBOL_GPL(snd_hda_codec_configure);
1719
1720/* update the stream-id if changed */ 1136/* update the stream-id if changed */
1721static void update_pcm_stream_id(struct hda_codec *codec, 1137static void update_pcm_stream_id(struct hda_codec *codec,
1722 struct hda_cvt_setup *p, hda_nid_t nid, 1138 struct hda_cvt_setup *p, hda_nid_t nid,
@@ -1782,6 +1198,8 @@ void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
1782 if (!p) 1198 if (!p)
1783 return; 1199 return;
1784 1200
1201 if (codec->patch_ops.stream_pm)
1202 codec->patch_ops.stream_pm(codec, nid, true);
1785 if (codec->pcm_format_first) 1203 if (codec->pcm_format_first)
1786 update_pcm_format(codec, p, nid, format); 1204 update_pcm_format(codec, p, nid, format);
1787 update_pcm_stream_id(codec, p, nid, stream_tag, channel_id); 1205 update_pcm_stream_id(codec, p, nid, stream_tag, channel_id);
@@ -1793,7 +1211,7 @@ void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
1793 1211
1794 /* make other inactive cvts with the same stream-tag dirty */ 1212 /* make other inactive cvts with the same stream-tag dirty */
1795 type = get_wcaps_type(get_wcaps(codec, nid)); 1213 type = get_wcaps_type(get_wcaps(codec, nid));
1796 list_for_each_entry(c, &codec->bus->codec_list, list) { 1214 list_for_each_codec(c, codec->bus) {
1797 for (i = 0; i < c->cvt_setups.used; i++) { 1215 for (i = 0; i < c->cvt_setups.used; i++) {
1798 p = snd_array_elem(&c->cvt_setups, i); 1216 p = snd_array_elem(&c->cvt_setups, i);
1799 if (!p->active && p->stream_tag == stream_tag && 1217 if (!p->active && p->stream_tag == stream_tag &&
@@ -1850,6 +1268,8 @@ static void really_cleanup_stream(struct hda_codec *codec,
1850); 1268);
1851 memset(q, 0, sizeof(*q)); 1269 memset(q, 0, sizeof(*q));
1852 q->nid = nid; 1270 q->nid = nid;
1271 if (codec->patch_ops.stream_pm)
1272 codec->patch_ops.stream_pm(codec, nid, false);
1853} 1273}
1854 1274
1855/* clean up the all conflicting obsolete streams */ 1275/* clean up the all conflicting obsolete streams */
@@ -1858,7 +1278,7 @@ static void purify_inactive_streams(struct hda_codec *codec)
1858 struct hda_codec *c; 1278 struct hda_codec *c;
1859 int i; 1279 int i;
1860 1280
1861 list_for_each_entry(c, &codec->bus->codec_list, list) { 1281 list_for_each_codec(c, codec->bus) {
1862 for (i = 0; i < c->cvt_setups.used; i++) { 1282 for (i = 0; i < c->cvt_setups.used; i++) {
1863 struct hda_cvt_setup *p; 1283 struct hda_cvt_setup *p;
1864 p = snd_array_elem(&c->cvt_setups, i); 1284 p = snd_array_elem(&c->cvt_setups, i);
@@ -1886,127 +1306,6 @@ static void hda_cleanup_all_streams(struct hda_codec *codec)
1886 * amp access functions 1306 * amp access functions
1887 */ 1307 */
1888 1308
1889/* FIXME: more better hash key? */
1890#define HDA_HASH_KEY(nid, dir, idx) (u32)((nid) + ((idx) << 16) + ((dir) << 24))
1891#define HDA_HASH_PINCAP_KEY(nid) (u32)((nid) + (0x02 << 24))
1892#define HDA_HASH_PARPCM_KEY(nid) (u32)((nid) + (0x03 << 24))
1893#define HDA_HASH_PARSTR_KEY(nid) (u32)((nid) + (0x04 << 24))
1894#define INFO_AMP_CAPS (1<<0)
1895#define INFO_AMP_VOL(ch) (1 << (1 + (ch)))
1896
1897/* initialize the hash table */
1898static void init_hda_cache(struct hda_cache_rec *cache,
1899 unsigned int record_size)
1900{
1901 memset(cache, 0, sizeof(*cache));
1902 memset(cache->hash, 0xff, sizeof(cache->hash));
1903 snd_array_init(&cache->buf, record_size, 64);
1904}
1905
1906static void free_hda_cache(struct hda_cache_rec *cache)
1907{
1908 snd_array_free(&cache->buf);
1909}
1910
1911/* query the hash. allocate an entry if not found. */
1912static struct hda_cache_head *get_hash(struct hda_cache_rec *cache, u32 key)
1913{
1914 u16 idx = key % (u16)ARRAY_SIZE(cache->hash);
1915 u16 cur = cache->hash[idx];
1916 struct hda_cache_head *info;
1917
1918 while (cur != 0xffff) {
1919 info = snd_array_elem(&cache->buf, cur);
1920 if (info->key == key)
1921 return info;
1922 cur = info->next;
1923 }
1924 return NULL;
1925}
1926
1927/* query the hash. allocate an entry if not found. */
1928static struct hda_cache_head *get_alloc_hash(struct hda_cache_rec *cache,
1929 u32 key)
1930{
1931 struct hda_cache_head *info = get_hash(cache, key);
1932 if (!info) {
1933 u16 idx, cur;
1934 /* add a new hash entry */
1935 info = snd_array_new(&cache->buf);
1936 if (!info)
1937 return NULL;
1938 cur = snd_array_index(&cache->buf, info);
1939 info->key = key;
1940 info->val = 0;
1941 info->dirty = 0;
1942 idx = key % (u16)ARRAY_SIZE(cache->hash);
1943 info->next = cache->hash[idx];
1944 cache->hash[idx] = cur;
1945 }
1946 return info;
1947}
1948
1949/* query and allocate an amp hash entry */
1950static inline struct hda_amp_info *
1951get_alloc_amp_hash(struct hda_codec *codec, u32 key)
1952{
1953 return (struct hda_amp_info *)get_alloc_hash(&codec->amp_cache, key);
1954}
1955
1956/* overwrite the value with the key in the caps hash */
1957static int write_caps_hash(struct hda_codec *codec, u32 key, unsigned int val)
1958{
1959 struct hda_amp_info *info;
1960
1961 mutex_lock(&codec->hash_mutex);
1962 info = get_alloc_amp_hash(codec, key);
1963 if (!info) {
1964 mutex_unlock(&codec->hash_mutex);
1965 return -EINVAL;
1966 }
1967 info->amp_caps = val;
1968 info->head.val |= INFO_AMP_CAPS;
1969 mutex_unlock(&codec->hash_mutex);
1970 return 0;
1971}
1972
1973/* query the value from the caps hash; if not found, fetch the current
1974 * value from the given function and store in the hash
1975 */
1976static unsigned int
1977query_caps_hash(struct hda_codec *codec, hda_nid_t nid, int dir, u32 key,
1978 unsigned int (*func)(struct hda_codec *, hda_nid_t, int))
1979{
1980 struct hda_amp_info *info;
1981 unsigned int val;
1982
1983 mutex_lock(&codec->hash_mutex);
1984 info = get_alloc_amp_hash(codec, key);
1985 if (!info) {
1986 mutex_unlock(&codec->hash_mutex);
1987 return 0;
1988 }
1989 if (!(info->head.val & INFO_AMP_CAPS)) {
1990 mutex_unlock(&codec->hash_mutex); /* for reentrance */
1991 val = func(codec, nid, dir);
1992 write_caps_hash(codec, key, val);
1993 } else {
1994 val = info->amp_caps;
1995 mutex_unlock(&codec->hash_mutex);
1996 }
1997 return val;
1998}
1999
2000static unsigned int read_amp_cap(struct hda_codec *codec, hda_nid_t nid,
2001 int direction)
2002{
2003 if (!(get_wcaps(codec, nid) & AC_WCAP_AMP_OVRD))
2004 nid = codec->afg;
2005 return snd_hda_param_read(codec, nid,
2006 direction == HDA_OUTPUT ?
2007 AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP);
2008}
2009
2010/** 1309/**
2011 * query_amp_caps - query AMP capabilities 1310 * query_amp_caps - query AMP capabilities
2012 * @codec: the HD-auio codec 1311 * @codec: the HD-auio codec
@@ -2021,9 +1320,11 @@ static unsigned int read_amp_cap(struct hda_codec *codec, hda_nid_t nid,
2021 */ 1320 */
2022u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction) 1321u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction)
2023{ 1322{
2024 return query_caps_hash(codec, nid, direction, 1323 if (!(get_wcaps(codec, nid) & AC_WCAP_AMP_OVRD))
2025 HDA_HASH_KEY(nid, direction, 0), 1324 nid = codec->core.afg;
2026 read_amp_cap); 1325 return snd_hda_param_read(codec, nid,
1326 direction == HDA_OUTPUT ?
1327 AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP);
2027} 1328}
2028EXPORT_SYMBOL_GPL(query_amp_caps); 1329EXPORT_SYMBOL_GPL(query_amp_caps);
2029 1330
@@ -2064,183 +1365,14 @@ EXPORT_SYMBOL_GPL(snd_hda_check_amp_caps);
2064int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, 1365int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
2065 unsigned int caps) 1366 unsigned int caps)
2066{ 1367{
2067 return write_caps_hash(codec, HDA_HASH_KEY(nid, dir, 0), caps); 1368 unsigned int parm;
2068}
2069EXPORT_SYMBOL_GPL(snd_hda_override_amp_caps);
2070
2071static unsigned int read_pin_cap(struct hda_codec *codec, hda_nid_t nid,
2072 int dir)
2073{
2074 return snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
2075}
2076
2077/**
2078 * snd_hda_query_pin_caps - Query PIN capabilities
2079 * @codec: the HD-auio codec
2080 * @nid: the NID to query
2081 *
2082 * Query PIN capabilities for the given widget.
2083 * Returns the obtained capability bits.
2084 *
2085 * When cap bits have been already read, this doesn't read again but
2086 * returns the cached value.
2087 */
2088u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid)
2089{
2090 return query_caps_hash(codec, nid, 0, HDA_HASH_PINCAP_KEY(nid),
2091 read_pin_cap);
2092}
2093EXPORT_SYMBOL_GPL(snd_hda_query_pin_caps);
2094
2095/**
2096 * snd_hda_override_pin_caps - Override the pin capabilities
2097 * @codec: the CODEC
2098 * @nid: the NID to override
2099 * @caps: the capability bits to set
2100 *
2101 * Override the cached PIN capabilitiy bits value by the given one.
2102 *
2103 * Returns zero if successful or a negative error code.
2104 */
2105int snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid,
2106 unsigned int caps)
2107{
2108 return write_caps_hash(codec, HDA_HASH_PINCAP_KEY(nid), caps);
2109}
2110EXPORT_SYMBOL_GPL(snd_hda_override_pin_caps);
2111
2112/* read or sync the hash value with the current value;
2113 * call within hash_mutex
2114 */
2115static struct hda_amp_info *
2116update_amp_hash(struct hda_codec *codec, hda_nid_t nid, int ch,
2117 int direction, int index, bool init_only)
2118{
2119 struct hda_amp_info *info;
2120 unsigned int parm, val = 0;
2121 bool val_read = false;
2122
2123 retry:
2124 info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, index));
2125 if (!info)
2126 return NULL;
2127 if (!(info->head.val & INFO_AMP_VOL(ch))) {
2128 if (!val_read) {
2129 mutex_unlock(&codec->hash_mutex);
2130 parm = ch ? AC_AMP_GET_RIGHT : AC_AMP_GET_LEFT;
2131 parm |= direction == HDA_OUTPUT ?
2132 AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT;
2133 parm |= index;
2134 val = snd_hda_codec_read(codec, nid, 0,
2135 AC_VERB_GET_AMP_GAIN_MUTE, parm);
2136 val &= 0xff;
2137 val_read = true;
2138 mutex_lock(&codec->hash_mutex);
2139 goto retry;
2140 }
2141 info->vol[ch] = val;
2142 info->head.val |= INFO_AMP_VOL(ch);
2143 } else if (init_only)
2144 return NULL;
2145 return info;
2146}
2147
2148/*
2149 * write the current volume in info to the h/w
2150 */
2151static void put_vol_mute(struct hda_codec *codec, unsigned int amp_caps,
2152 hda_nid_t nid, int ch, int direction, int index,
2153 int val)
2154{
2155 u32 parm;
2156
2157 parm = ch ? AC_AMP_SET_RIGHT : AC_AMP_SET_LEFT;
2158 parm |= direction == HDA_OUTPUT ? AC_AMP_SET_OUTPUT : AC_AMP_SET_INPUT;
2159 parm |= index << AC_AMP_SET_INDEX_SHIFT;
2160 if ((val & HDA_AMP_MUTE) && !(amp_caps & AC_AMPCAP_MUTE) &&
2161 (amp_caps & AC_AMPCAP_MIN_MUTE))
2162 ; /* set the zero value as a fake mute */
2163 else
2164 parm |= val;
2165 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, parm);
2166}
2167
2168/**
2169 * snd_hda_codec_amp_read - Read AMP value
2170 * @codec: HD-audio codec
2171 * @nid: NID to read the AMP value
2172 * @ch: channel (left=0 or right=1)
2173 * @direction: #HDA_INPUT or #HDA_OUTPUT
2174 * @index: the index value (only for input direction)
2175 *
2176 * Read AMP value. The volume is between 0 to 0x7f, 0x80 = mute bit.
2177 */
2178int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch,
2179 int direction, int index)
2180{
2181 struct hda_amp_info *info;
2182 unsigned int val = 0;
2183
2184 mutex_lock(&codec->hash_mutex);
2185 info = update_amp_hash(codec, nid, ch, direction, index, false);
2186 if (info)
2187 val = info->vol[ch];
2188 mutex_unlock(&codec->hash_mutex);
2189 return val;
2190}
2191EXPORT_SYMBOL_GPL(snd_hda_codec_amp_read);
2192
2193static int codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
2194 int direction, int idx, int mask, int val,
2195 bool init_only)
2196{
2197 struct hda_amp_info *info;
2198 unsigned int caps;
2199 unsigned int cache_only;
2200
2201 if (snd_BUG_ON(mask & ~0xff))
2202 mask &= 0xff;
2203 val &= mask;
2204
2205 mutex_lock(&codec->hash_mutex);
2206 info = update_amp_hash(codec, nid, ch, direction, idx, init_only);
2207 if (!info) {
2208 mutex_unlock(&codec->hash_mutex);
2209 return 0;
2210 }
2211 val |= info->vol[ch] & ~mask;
2212 if (info->vol[ch] == val) {
2213 mutex_unlock(&codec->hash_mutex);
2214 return 0;
2215 }
2216 info->vol[ch] = val;
2217 cache_only = info->head.dirty = codec->cached_write;
2218 caps = info->amp_caps;
2219 mutex_unlock(&codec->hash_mutex);
2220 if (!cache_only)
2221 put_vol_mute(codec, caps, nid, ch, direction, idx, val);
2222 return 1;
2223}
2224 1369
2225/** 1370 snd_hda_override_wcaps(codec, nid,
2226 * snd_hda_codec_amp_update - update the AMP value 1371 get_wcaps(codec, nid) | AC_WCAP_AMP_OVRD);
2227 * @codec: HD-audio codec 1372 parm = dir == HDA_OUTPUT ? AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP;
2228 * @nid: NID to read the AMP value 1373 return snd_hdac_override_parm(&codec->core, nid, parm, caps);
2229 * @ch: channel (left=0 or right=1)
2230 * @direction: #HDA_INPUT or #HDA_OUTPUT
2231 * @idx: the index value (only for input direction)
2232 * @mask: bit mask to set
2233 * @val: the bits value to set
2234 *
2235 * Update the AMP value with a bit mask.
2236 * Returns 0 if the value is unchanged, 1 if changed.
2237 */
2238int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
2239 int direction, int idx, int mask, int val)
2240{
2241 return codec_amp_update(codec, nid, ch, direction, idx, mask, val, false);
2242} 1374}
2243EXPORT_SYMBOL_GPL(snd_hda_codec_amp_update); 1375EXPORT_SYMBOL_GPL(snd_hda_override_amp_caps);
2244 1376
2245/** 1377/**
2246 * snd_hda_codec_amp_stereo - update the AMP stereo values 1378 * snd_hda_codec_amp_stereo - update the AMP stereo values
@@ -2285,7 +1417,16 @@ EXPORT_SYMBOL_GPL(snd_hda_codec_amp_stereo);
2285int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch, 1417int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch,
2286 int dir, int idx, int mask, int val) 1418 int dir, int idx, int mask, int val)
2287{ 1419{
2288 return codec_amp_update(codec, nid, ch, dir, idx, mask, val, true); 1420 int orig;
1421
1422 if (!codec->core.regmap)
1423 return -EINVAL;
1424 regcache_cache_only(codec->core.regmap, true);
1425 orig = snd_hda_codec_amp_read(codec, nid, ch, dir, idx);
1426 regcache_cache_only(codec->core.regmap, false);
1427 if (orig >= 0)
1428 return 0;
1429 return snd_hda_codec_amp_update(codec, nid, ch, dir, idx, mask, val);
2289} 1430}
2290EXPORT_SYMBOL_GPL(snd_hda_codec_amp_init); 1431EXPORT_SYMBOL_GPL(snd_hda_codec_amp_init);
2291 1432
@@ -2314,49 +1455,6 @@ int snd_hda_codec_amp_init_stereo(struct hda_codec *codec, hda_nid_t nid,
2314} 1455}
2315EXPORT_SYMBOL_GPL(snd_hda_codec_amp_init_stereo); 1456EXPORT_SYMBOL_GPL(snd_hda_codec_amp_init_stereo);
2316 1457
2317/**
2318 * snd_hda_codec_resume_amp - Resume all AMP commands from the cache
2319 * @codec: HD-audio codec
2320 *
2321 * Resume the all amp commands from the cache.
2322 */
2323void snd_hda_codec_resume_amp(struct hda_codec *codec)
2324{
2325 int i;
2326
2327 mutex_lock(&codec->hash_mutex);
2328 codec->cached_write = 0;
2329 for (i = 0; i < codec->amp_cache.buf.used; i++) {
2330 struct hda_amp_info *buffer;
2331 u32 key;
2332 hda_nid_t nid;
2333 unsigned int idx, dir, ch;
2334 struct hda_amp_info info;
2335
2336 buffer = snd_array_elem(&codec->amp_cache.buf, i);
2337 if (!buffer->head.dirty)
2338 continue;
2339 buffer->head.dirty = 0;
2340 info = *buffer;
2341 key = info.head.key;
2342 if (!key)
2343 continue;
2344 nid = key & 0xff;
2345 idx = (key >> 16) & 0xff;
2346 dir = (key >> 24) & 0xff;
2347 for (ch = 0; ch < 2; ch++) {
2348 if (!(info.head.val & INFO_AMP_VOL(ch)))
2349 continue;
2350 mutex_unlock(&codec->hash_mutex);
2351 put_vol_mute(codec, info.amp_caps, nid, ch, dir, idx,
2352 info.vol[ch]);
2353 mutex_lock(&codec->hash_mutex);
2354 }
2355 }
2356 mutex_unlock(&codec->hash_mutex);
2357}
2358EXPORT_SYMBOL_GPL(snd_hda_codec_resume_amp);
2359
2360static u32 get_amp_max_value(struct hda_codec *codec, hda_nid_t nid, int dir, 1458static u32 get_amp_max_value(struct hda_codec *codec, hda_nid_t nid, int dir,
2361 unsigned int ofs) 1459 unsigned int ofs)
2362{ 1460{
@@ -2478,14 +1576,12 @@ int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol,
2478 long *valp = ucontrol->value.integer.value; 1576 long *valp = ucontrol->value.integer.value;
2479 int change = 0; 1577 int change = 0;
2480 1578
2481 snd_hda_power_up(codec);
2482 if (chs & 1) { 1579 if (chs & 1) {
2483 change = update_amp_value(codec, nid, 0, dir, idx, ofs, *valp); 1580 change = update_amp_value(codec, nid, 0, dir, idx, ofs, *valp);
2484 valp++; 1581 valp++;
2485 } 1582 }
2486 if (chs & 2) 1583 if (chs & 2)
2487 change |= update_amp_value(codec, nid, 1, dir, idx, ofs, *valp); 1584 change |= update_amp_value(codec, nid, 1, dir, idx, ofs, *valp);
2488 snd_hda_power_down(codec);
2489 return change; 1585 return change;
2490} 1586}
2491EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_volume_put); 1587EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_volume_put);
@@ -2572,7 +1668,7 @@ find_mixer_ctl(struct hda_codec *codec, const char *name, int dev, int idx)
2572 if (snd_BUG_ON(strlen(name) >= sizeof(id.name))) 1668 if (snd_BUG_ON(strlen(name) >= sizeof(id.name)))
2573 return NULL; 1669 return NULL;
2574 strcpy(id.name, name); 1670 strcpy(id.name, name);
2575 return snd_ctl_find_id(codec->bus->card, &id); 1671 return snd_ctl_find_id(codec->card, &id);
2576} 1672}
2577 1673
2578/** 1674/**
@@ -2636,7 +1732,7 @@ int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid,
2636 nid = kctl->id.subdevice & 0xffff; 1732 nid = kctl->id.subdevice & 0xffff;
2637 if (kctl->id.subdevice & (HDA_SUBDEV_NID_FLAG|HDA_SUBDEV_AMP_FLAG)) 1733 if (kctl->id.subdevice & (HDA_SUBDEV_NID_FLAG|HDA_SUBDEV_AMP_FLAG))
2638 kctl->id.subdevice = 0; 1734 kctl->id.subdevice = 0;
2639 err = snd_ctl_add(codec->bus->card, kctl); 1735 err = snd_ctl_add(codec->card, kctl);
2640 if (err < 0) 1736 if (err < 0)
2641 return err; 1737 return err;
2642 item = snd_array_new(&codec->mixers); 1738 item = snd_array_new(&codec->mixers);
@@ -2689,7 +1785,7 @@ void snd_hda_ctls_clear(struct hda_codec *codec)
2689 int i; 1785 int i;
2690 struct hda_nid_item *items = codec->mixers.list; 1786 struct hda_nid_item *items = codec->mixers.list;
2691 for (i = 0; i < codec->mixers.used; i++) 1787 for (i = 0; i < codec->mixers.used; i++)
2692 snd_ctl_remove(codec->bus->card, items[i].kctl); 1788 snd_ctl_remove(codec->card, items[i].kctl);
2693 snd_array_free(&codec->mixers); 1789 snd_array_free(&codec->mixers);
2694 snd_array_free(&codec->nids); 1790 snd_array_free(&codec->nids);
2695} 1791}
@@ -2712,10 +1808,9 @@ int snd_hda_lock_devices(struct hda_bus *bus)
2712 if (!list_empty(&card->ctl_files)) 1808 if (!list_empty(&card->ctl_files))
2713 goto err_clear; 1809 goto err_clear;
2714 1810
2715 list_for_each_entry(codec, &bus->codec_list, list) { 1811 list_for_each_codec(codec, bus) {
2716 int pcm; 1812 struct hda_pcm *cpcm;
2717 for (pcm = 0; pcm < codec->num_pcms; pcm++) { 1813 list_for_each_entry(cpcm, &codec->pcm_list_head, list) {
2718 struct hda_pcm *cpcm = &codec->pcm_info[pcm];
2719 if (!cpcm->pcm) 1814 if (!cpcm->pcm)
2720 continue; 1815 continue;
2721 if (cpcm->pcm->streams[0].substream_opened || 1816 if (cpcm->pcm->streams[0].substream_opened ||
@@ -2742,7 +1837,6 @@ void snd_hda_unlock_devices(struct hda_bus *bus)
2742{ 1837{
2743 struct snd_card *card = bus->card; 1838 struct snd_card *card = bus->card;
2744 1839
2745 card = bus->card;
2746 spin_lock(&card->files_lock); 1840 spin_lock(&card->files_lock);
2747 card->shutdown = 0; 1841 card->shutdown = 0;
2748 spin_unlock(&card->files_lock); 1842 spin_unlock(&card->files_lock);
@@ -2762,51 +1856,12 @@ EXPORT_SYMBOL_GPL(snd_hda_unlock_devices);
2762int snd_hda_codec_reset(struct hda_codec *codec) 1856int snd_hda_codec_reset(struct hda_codec *codec)
2763{ 1857{
2764 struct hda_bus *bus = codec->bus; 1858 struct hda_bus *bus = codec->bus;
2765 struct snd_card *card = bus->card;
2766 int i;
2767 1859
2768 if (snd_hda_lock_devices(bus) < 0) 1860 if (snd_hda_lock_devices(bus) < 0)
2769 return -EBUSY; 1861 return -EBUSY;
2770 1862
2771 /* OK, let it free */ 1863 /* OK, let it free */
2772 cancel_delayed_work_sync(&codec->jackpoll_work); 1864 snd_hdac_device_unregister(&codec->core);
2773#ifdef CONFIG_PM
2774 cancel_delayed_work_sync(&codec->power_work);
2775 flush_workqueue(bus->workq);
2776#endif
2777 snd_hda_ctls_clear(codec);
2778 /* release PCMs */
2779 for (i = 0; i < codec->num_pcms; i++) {
2780 if (codec->pcm_info[i].pcm) {
2781 snd_device_free(card, codec->pcm_info[i].pcm);
2782 clear_bit(codec->pcm_info[i].device,
2783 bus->pcm_dev_bits);
2784 }
2785 }
2786 snd_hda_detach_beep_device(codec);
2787 if (codec->patch_ops.free)
2788 codec->patch_ops.free(codec);
2789 memset(&codec->patch_ops, 0, sizeof(codec->patch_ops));
2790 snd_hda_jack_tbl_clear(codec);
2791 codec->proc_widget_hook = NULL;
2792 codec->spec = NULL;
2793 free_hda_cache(&codec->amp_cache);
2794 free_hda_cache(&codec->cmd_cache);
2795 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info));
2796 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head));
2797 /* free only driver_pins so that init_pins + user_pins are restored */
2798 snd_array_free(&codec->driver_pins);
2799 snd_array_free(&codec->cvt_setups);
2800 snd_array_free(&codec->spdif_out);
2801 snd_array_free(&codec->verbs);
2802 codec->num_pcms = 0;
2803 codec->pcm_info = NULL;
2804 codec->preset = NULL;
2805 codec->slave_dig_outs = NULL;
2806 codec->spdif_status_reset = 0;
2807 unload_parser(codec);
2808 module_put(codec->owner);
2809 codec->owner = NULL;
2810 1865
2811 /* allow device access again */ 1866 /* allow device access again */
2812 snd_hda_unlock_devices(bus); 1867 snd_hda_unlock_devices(bus);
@@ -3153,7 +2208,6 @@ int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
3153 long *valp = ucontrol->value.integer.value; 2208 long *valp = ucontrol->value.integer.value;
3154 int change = 0; 2209 int change = 0;
3155 2210
3156 snd_hda_power_up(codec);
3157 if (chs & 1) { 2211 if (chs & 1) {
3158 change = snd_hda_codec_amp_update(codec, nid, 0, dir, idx, 2212 change = snd_hda_codec_amp_update(codec, nid, 0, dir, idx,
3159 HDA_AMP_MUTE, 2213 HDA_AMP_MUTE,
@@ -3165,7 +2219,6 @@ int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
3165 HDA_AMP_MUTE, 2219 HDA_AMP_MUTE,
3166 *valp ? 0 : HDA_AMP_MUTE); 2220 *valp ? 0 : HDA_AMP_MUTE);
3167 hda_call_check_power_status(codec, nid); 2221 hda_call_check_power_status(codec, nid);
3168 snd_hda_power_down(codec);
3169 return change; 2222 return change;
3170} 2223}
3171EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_switch_put); 2224EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_switch_put);
@@ -3466,25 +2519,35 @@ static unsigned int convert_to_spdif_status(unsigned short val)
3466 2519
3467/* set digital convert verbs both for the given NID and its slaves */ 2520/* set digital convert verbs both for the given NID and its slaves */
3468static void set_dig_out(struct hda_codec *codec, hda_nid_t nid, 2521static void set_dig_out(struct hda_codec *codec, hda_nid_t nid,
3469 int verb, int val) 2522 int mask, int val)
3470{ 2523{
3471 const hda_nid_t *d; 2524 const hda_nid_t *d;
3472 2525
3473 snd_hda_codec_write_cache(codec, nid, 0, verb, val); 2526 snd_hdac_regmap_update(&codec->core, nid, AC_VERB_SET_DIGI_CONVERT_1,
2527 mask, val);
3474 d = codec->slave_dig_outs; 2528 d = codec->slave_dig_outs;
3475 if (!d) 2529 if (!d)
3476 return; 2530 return;
3477 for (; *d; d++) 2531 for (; *d; d++)
3478 snd_hda_codec_write_cache(codec, *d, 0, verb, val); 2532 snd_hdac_regmap_update(&codec->core, *d,
2533 AC_VERB_SET_DIGI_CONVERT_1, mask, val);
3479} 2534}
3480 2535
3481static inline void set_dig_out_convert(struct hda_codec *codec, hda_nid_t nid, 2536static inline void set_dig_out_convert(struct hda_codec *codec, hda_nid_t nid,
3482 int dig1, int dig2) 2537 int dig1, int dig2)
3483{ 2538{
3484 if (dig1 != -1) 2539 unsigned int mask = 0;
3485 set_dig_out(codec, nid, AC_VERB_SET_DIGI_CONVERT_1, dig1); 2540 unsigned int val = 0;
3486 if (dig2 != -1) 2541
3487 set_dig_out(codec, nid, AC_VERB_SET_DIGI_CONVERT_2, dig2); 2542 if (dig1 != -1) {
2543 mask |= 0xff;
2544 val = dig1;
2545 }
2546 if (dig2 != -1) {
2547 mask |= 0xff00;
2548 val |= dig2 << 8;
2549 }
2550 set_dig_out(codec, nid, mask, val);
3488} 2551}
3489 2552
3490static int snd_hda_spdif_default_put(struct snd_kcontrol *kcontrol, 2553static int snd_hda_spdif_default_put(struct snd_kcontrol *kcontrol,
@@ -3617,6 +2680,7 @@ int snd_hda_create_dig_out_ctls(struct hda_codec *codec,
3617 struct snd_kcontrol *kctl; 2680 struct snd_kcontrol *kctl;
3618 struct snd_kcontrol_new *dig_mix; 2681 struct snd_kcontrol_new *dig_mix;
3619 int idx = 0; 2682 int idx = 0;
2683 int val = 0;
3620 const int spdif_index = 16; 2684 const int spdif_index = 16;
3621 struct hda_spdif_out *spdif; 2685 struct hda_spdif_out *spdif;
3622 struct hda_bus *bus = codec->bus; 2686 struct hda_bus *bus = codec->bus;
@@ -3657,8 +2721,9 @@ int snd_hda_create_dig_out_ctls(struct hda_codec *codec,
3657 return err; 2721 return err;
3658 } 2722 }
3659 spdif->nid = cvt_nid; 2723 spdif->nid = cvt_nid;
3660 spdif->ctls = snd_hda_codec_read(codec, cvt_nid, 0, 2724 snd_hdac_regmap_read(&codec->core, cvt_nid,
3661 AC_VERB_GET_DIGI_CONVERT_1, 0); 2725 AC_VERB_GET_DIGI_CONVERT_1, &val);
2726 spdif->ctls = val;
3662 spdif->status = convert_to_spdif_status(spdif->ctls); 2727 spdif->status = convert_to_spdif_status(spdif->ctls);
3663 return 0; 2728 return 0;
3664} 2729}
@@ -3802,8 +2867,8 @@ static int snd_hda_spdif_in_switch_put(struct snd_kcontrol *kcontrol,
3802 change = codec->spdif_in_enable != val; 2867 change = codec->spdif_in_enable != val;
3803 if (change) { 2868 if (change) {
3804 codec->spdif_in_enable = val; 2869 codec->spdif_in_enable = val;
3805 snd_hda_codec_write_cache(codec, nid, 0, 2870 snd_hdac_regmap_write(&codec->core, nid,
3806 AC_VERB_SET_DIGI_CONVERT_1, val); 2871 AC_VERB_SET_DIGI_CONVERT_1, val);
3807 } 2872 }
3808 mutex_unlock(&codec->spdif_mutex); 2873 mutex_unlock(&codec->spdif_mutex);
3809 return change; 2874 return change;
@@ -3814,10 +2879,11 @@ static int snd_hda_spdif_in_status_get(struct snd_kcontrol *kcontrol,
3814{ 2879{
3815 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2880 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3816 hda_nid_t nid = kcontrol->private_value; 2881 hda_nid_t nid = kcontrol->private_value;
3817 unsigned short val; 2882 unsigned int val;
3818 unsigned int sbits; 2883 unsigned int sbits;
3819 2884
3820 val = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_DIGI_CONVERT_1, 0); 2885 snd_hdac_regmap_read(&codec->core, nid,
2886 AC_VERB_GET_DIGI_CONVERT_1, &val);
3821 sbits = convert_to_spdif_status(val); 2887 sbits = convert_to_spdif_status(val);
3822 ucontrol->value.iec958.status[0] = sbits; 2888 ucontrol->value.iec958.status[0] = sbits;
3823 ucontrol->value.iec958.status[1] = sbits >> 8; 2889 ucontrol->value.iec958.status[1] = sbits >> 8;
@@ -3883,153 +2949,6 @@ int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid)
3883} 2949}
3884EXPORT_SYMBOL_GPL(snd_hda_create_spdif_in_ctls); 2950EXPORT_SYMBOL_GPL(snd_hda_create_spdif_in_ctls);
3885 2951
3886/*
3887 * command cache
3888 */
3889
3890/* build a 31bit cache key with the widget id and the command parameter */
3891#define build_cmd_cache_key(nid, verb) ((verb << 8) | nid)
3892#define get_cmd_cache_nid(key) ((key) & 0xff)
3893#define get_cmd_cache_cmd(key) (((key) >> 8) & 0xffff)
3894
3895/**
3896 * snd_hda_codec_write_cache - send a single command with caching
3897 * @codec: the HDA codec
3898 * @nid: NID to send the command
3899 * @flags: optional bit flags
3900 * @verb: the verb to send
3901 * @parm: the parameter for the verb
3902 *
3903 * Send a single command without waiting for response.
3904 *
3905 * Returns 0 if successful, or a negative error code.
3906 */
3907int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid,
3908 int flags, unsigned int verb, unsigned int parm)
3909{
3910 int err;
3911 struct hda_cache_head *c;
3912 u32 key;
3913 unsigned int cache_only;
3914
3915 cache_only = codec->cached_write;
3916 if (!cache_only) {
3917 err = snd_hda_codec_write(codec, nid, flags, verb, parm);
3918 if (err < 0)
3919 return err;
3920 }
3921
3922 /* parm may contain the verb stuff for get/set amp */
3923 verb = verb | (parm >> 8);
3924 parm &= 0xff;
3925 key = build_cmd_cache_key(nid, verb);
3926 mutex_lock(&codec->bus->cmd_mutex);
3927 c = get_alloc_hash(&codec->cmd_cache, key);
3928 if (c) {
3929 c->val = parm;
3930 c->dirty = cache_only;
3931 }
3932 mutex_unlock(&codec->bus->cmd_mutex);
3933 return 0;
3934}
3935EXPORT_SYMBOL_GPL(snd_hda_codec_write_cache);
3936
3937/**
3938 * snd_hda_codec_update_cache - check cache and write the cmd only when needed
3939 * @codec: the HDA codec
3940 * @nid: NID to send the command
3941 * @flags: optional bit flags
3942 * @verb: the verb to send
3943 * @parm: the parameter for the verb
3944 *
3945 * This function works like snd_hda_codec_write_cache(), but it doesn't send
3946 * command if the parameter is already identical with the cached value.
3947 * If not, it sends the command and refreshes the cache.
3948 *
3949 * Returns 0 if successful, or a negative error code.
3950 */
3951int snd_hda_codec_update_cache(struct hda_codec *codec, hda_nid_t nid,
3952 int flags, unsigned int verb, unsigned int parm)
3953{
3954 struct hda_cache_head *c;
3955 u32 key;
3956
3957 /* parm may contain the verb stuff for get/set amp */
3958 verb = verb | (parm >> 8);
3959 parm &= 0xff;
3960 key = build_cmd_cache_key(nid, verb);
3961 mutex_lock(&codec->bus->cmd_mutex);
3962 c = get_hash(&codec->cmd_cache, key);
3963 if (c && c->val == parm) {
3964 mutex_unlock(&codec->bus->cmd_mutex);
3965 return 0;
3966 }
3967 mutex_unlock(&codec->bus->cmd_mutex);
3968 return snd_hda_codec_write_cache(codec, nid, flags, verb, parm);
3969}
3970EXPORT_SYMBOL_GPL(snd_hda_codec_update_cache);
3971
3972/**
3973 * snd_hda_codec_resume_cache - Resume the all commands from the cache
3974 * @codec: HD-audio codec
3975 *
3976 * Execute all verbs recorded in the command caches to resume.
3977 */
3978void snd_hda_codec_resume_cache(struct hda_codec *codec)
3979{
3980 int i;
3981
3982 mutex_lock(&codec->hash_mutex);
3983 codec->cached_write = 0;
3984 for (i = 0; i < codec->cmd_cache.buf.used; i++) {
3985 struct hda_cache_head *buffer;
3986 u32 key;
3987
3988 buffer = snd_array_elem(&codec->cmd_cache.buf, i);
3989 key = buffer->key;
3990 if (!key)
3991 continue;
3992 if (!buffer->dirty)
3993 continue;
3994 buffer->dirty = 0;
3995 mutex_unlock(&codec->hash_mutex);
3996 snd_hda_codec_write(codec, get_cmd_cache_nid(key), 0,
3997 get_cmd_cache_cmd(key), buffer->val);
3998 mutex_lock(&codec->hash_mutex);
3999 }
4000 mutex_unlock(&codec->hash_mutex);
4001}
4002EXPORT_SYMBOL_GPL(snd_hda_codec_resume_cache);
4003
4004/**
4005 * snd_hda_sequence_write_cache - sequence writes with caching
4006 * @codec: the HDA codec
4007 * @seq: VERB array to send
4008 *
4009 * Send the commands sequentially from the given array.
4010 * Thte commands are recorded on cache for power-save and resume.
4011 * The array must be terminated with NID=0.
4012 */
4013void snd_hda_sequence_write_cache(struct hda_codec *codec,
4014 const struct hda_verb *seq)
4015{
4016 for (; seq->nid; seq++)
4017 snd_hda_codec_write_cache(codec, seq->nid, 0, seq->verb,
4018 seq->param);
4019}
4020EXPORT_SYMBOL_GPL(snd_hda_sequence_write_cache);
4021
4022/**
4023 * snd_hda_codec_flush_cache - Execute all pending (cached) amps / verbs
4024 * @codec: HD-audio codec
4025 */
4026void snd_hda_codec_flush_cache(struct hda_codec *codec)
4027{
4028 snd_hda_codec_resume_amp(codec);
4029 snd_hda_codec_resume_cache(codec);
4030}
4031EXPORT_SYMBOL_GPL(snd_hda_codec_flush_cache);
4032
4033/** 2952/**
4034 * snd_hda_codec_set_power_to_all - Set the power state to all widgets 2953 * snd_hda_codec_set_power_to_all - Set the power state to all widgets
4035 * @codec: the HDA codec 2954 * @codec: the HDA codec
@@ -4043,10 +2962,9 @@ EXPORT_SYMBOL_GPL(snd_hda_codec_flush_cache);
4043void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg, 2962void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg,
4044 unsigned int power_state) 2963 unsigned int power_state)
4045{ 2964{
4046 hda_nid_t nid = codec->start_nid; 2965 hda_nid_t nid;
4047 int i;
4048 2966
4049 for (i = 0; i < codec->num_nodes; i++, nid++) { 2967 for_each_hda_codec_node(nid, codec) {
4050 unsigned int wcaps = get_wcaps(codec, nid); 2968 unsigned int wcaps = get_wcaps(codec, nid);
4051 unsigned int state = power_state; 2969 unsigned int state = power_state;
4052 if (!(wcaps & AC_WCAP_POWER)) 2970 if (!(wcaps & AC_WCAP_POWER))
@@ -4063,22 +2981,6 @@ void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg,
4063EXPORT_SYMBOL_GPL(snd_hda_codec_set_power_to_all); 2981EXPORT_SYMBOL_GPL(snd_hda_codec_set_power_to_all);
4064 2982
4065/* 2983/*
4066 * supported power states check
4067 */
4068static bool snd_hda_codec_get_supported_ps(struct hda_codec *codec, hda_nid_t fg,
4069 unsigned int power_state)
4070{
4071 int sup = snd_hda_param_read(codec, fg, AC_PAR_POWER_STATE);
4072
4073 if (sup == -1)
4074 return false;
4075 if (sup & power_state)
4076 return true;
4077 else
4078 return false;
4079}
4080
4081/*
4082 * wait until the state is reached, returns the current state 2984 * wait until the state is reached, returns the current state
4083 */ 2985 */
4084static unsigned int hda_sync_power_state(struct hda_codec *codec, 2986static unsigned int hda_sync_power_state(struct hda_codec *codec,
@@ -4117,7 +3019,7 @@ unsigned int snd_hda_codec_eapd_power_filter(struct hda_codec *codec,
4117 hda_nid_t nid, 3019 hda_nid_t nid,
4118 unsigned int power_state) 3020 unsigned int power_state)
4119{ 3021{
4120 if (nid == codec->afg || nid == codec->mfg) 3022 if (nid == codec->core.afg || nid == codec->core.mfg)
4121 return power_state; 3023 return power_state;
4122 if (power_state == AC_PWRST_D3 && 3024 if (power_state == AC_PWRST_D3 &&
4123 get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_PIN && 3025 get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_PIN &&
@@ -4137,7 +3039,7 @@ EXPORT_SYMBOL_GPL(snd_hda_codec_eapd_power_filter);
4137static unsigned int hda_set_power_state(struct hda_codec *codec, 3039static unsigned int hda_set_power_state(struct hda_codec *codec,
4138 unsigned int power_state) 3040 unsigned int power_state)
4139{ 3041{
4140 hda_nid_t fg = codec->afg ? codec->afg : codec->mfg; 3042 hda_nid_t fg = codec->core.afg ? codec->core.afg : codec->core.mfg;
4141 int count; 3043 int count;
4142 unsigned int state; 3044 unsigned int state;
4143 int flags = 0; 3045 int flags = 0;
@@ -4145,7 +3047,7 @@ static unsigned int hda_set_power_state(struct hda_codec *codec,
4145 /* this delay seems necessary to avoid click noise at power-down */ 3047 /* this delay seems necessary to avoid click noise at power-down */
4146 if (power_state == AC_PWRST_D3) { 3048 if (power_state == AC_PWRST_D3) {
4147 if (codec->depop_delay < 0) 3049 if (codec->depop_delay < 0)
4148 msleep(codec->epss ? 10 : 100); 3050 msleep(codec_has_epss(codec) ? 10 : 100);
4149 else if (codec->depop_delay > 0) 3051 else if (codec->depop_delay > 0)
4150 msleep(codec->depop_delay); 3052 msleep(codec->depop_delay);
4151 flags = HDA_RW_NO_RESPONSE_FALLBACK; 3053 flags = HDA_RW_NO_RESPONSE_FALLBACK;
@@ -4179,14 +3081,13 @@ static unsigned int hda_set_power_state(struct hda_codec *codec,
4179 */ 3081 */
4180static void sync_power_up_states(struct hda_codec *codec) 3082static void sync_power_up_states(struct hda_codec *codec)
4181{ 3083{
4182 hda_nid_t nid = codec->start_nid; 3084 hda_nid_t nid;
4183 int i;
4184 3085
4185 /* don't care if no filter is used */ 3086 /* don't care if no filter is used */
4186 if (!codec->power_filter) 3087 if (!codec->power_filter)
4187 return; 3088 return;
4188 3089
4189 for (i = 0; i < codec->num_nodes; i++, nid++) { 3090 for_each_hda_codec_node(nid, codec) {
4190 unsigned int wcaps = get_wcaps(codec, nid); 3091 unsigned int wcaps = get_wcaps(codec, nid);
4191 unsigned int target; 3092 unsigned int target;
4192 if (!(wcaps & AC_WCAP_POWER)) 3093 if (!(wcaps & AC_WCAP_POWER))
@@ -4212,63 +3113,54 @@ static inline void hda_exec_init_verbs(struct hda_codec *codec) {}
4212#endif 3113#endif
4213 3114
4214#ifdef CONFIG_PM 3115#ifdef CONFIG_PM
3116/* update the power on/off account with the current jiffies */
3117static void update_power_acct(struct hda_codec *codec, bool on)
3118{
3119 unsigned long delta = jiffies - codec->power_jiffies;
3120
3121 if (on)
3122 codec->power_on_acct += delta;
3123 else
3124 codec->power_off_acct += delta;
3125 codec->power_jiffies += delta;
3126}
3127
3128void snd_hda_update_power_acct(struct hda_codec *codec)
3129{
3130 update_power_acct(codec, hda_codec_is_power_on(codec));
3131}
3132
4215/* 3133/*
4216 * call suspend and power-down; used both from PM and power-save 3134 * call suspend and power-down; used both from PM and power-save
4217 * this function returns the power state in the end 3135 * this function returns the power state in the end
4218 */ 3136 */
4219static unsigned int hda_call_codec_suspend(struct hda_codec *codec, bool in_wq) 3137static unsigned int hda_call_codec_suspend(struct hda_codec *codec)
4220{ 3138{
4221 unsigned int state; 3139 unsigned int state;
4222 3140
4223 codec->in_pm = 1; 3141 atomic_inc(&codec->core.in_pm);
4224 3142
4225 if (codec->patch_ops.suspend) 3143 if (codec->patch_ops.suspend)
4226 codec->patch_ops.suspend(codec); 3144 codec->patch_ops.suspend(codec);
4227 hda_cleanup_all_streams(codec); 3145 hda_cleanup_all_streams(codec);
4228 state = hda_set_power_state(codec, AC_PWRST_D3); 3146 state = hda_set_power_state(codec, AC_PWRST_D3);
4229 /* Cancel delayed work if we aren't currently running from it. */ 3147 update_power_acct(codec, true);
4230 if (!in_wq) 3148 atomic_dec(&codec->core.in_pm);
4231 cancel_delayed_work_sync(&codec->power_work);
4232 spin_lock(&codec->power_lock);
4233 snd_hda_update_power_acct(codec);
4234 trace_hda_power_down(codec);
4235 codec->power_on = 0;
4236 codec->power_transition = 0;
4237 codec->power_jiffies = jiffies;
4238 spin_unlock(&codec->power_lock);
4239 codec->in_pm = 0;
4240 return state; 3149 return state;
4241} 3150}
4242 3151
4243/* mark all entries of cmd and amp caches dirty */
4244static void hda_mark_cmd_cache_dirty(struct hda_codec *codec)
4245{
4246 int i;
4247 for (i = 0; i < codec->cmd_cache.buf.used; i++) {
4248 struct hda_cache_head *cmd;
4249 cmd = snd_array_elem(&codec->cmd_cache.buf, i);
4250 cmd->dirty = 1;
4251 }
4252 for (i = 0; i < codec->amp_cache.buf.used; i++) {
4253 struct hda_amp_info *amp;
4254 amp = snd_array_elem(&codec->amp_cache.buf, i);
4255 amp->head.dirty = 1;
4256 }
4257}
4258
4259/* 3152/*
4260 * kick up codec; used both from PM and power-save 3153 * kick up codec; used both from PM and power-save
4261 */ 3154 */
4262static void hda_call_codec_resume(struct hda_codec *codec) 3155static void hda_call_codec_resume(struct hda_codec *codec)
4263{ 3156{
4264 codec->in_pm = 1; 3157 atomic_inc(&codec->core.in_pm);
4265 3158
4266 hda_mark_cmd_cache_dirty(codec); 3159 if (codec->core.regmap)
3160 regcache_mark_dirty(codec->core.regmap);
3161
3162 codec->power_jiffies = jiffies;
4267 3163
4268 /* set as if powered on for avoiding re-entering the resume
4269 * in the resume / power-save sequence
4270 */
4271 hda_keep_power_on(codec);
4272 hda_set_power_state(codec, AC_PWRST_D0); 3164 hda_set_power_state(codec, AC_PWRST_D0);
4273 restore_shutup_pins(codec); 3165 restore_shutup_pins(codec);
4274 hda_exec_init_verbs(codec); 3166 hda_exec_init_verbs(codec);
@@ -4278,72 +3170,71 @@ static void hda_call_codec_resume(struct hda_codec *codec)
4278 else { 3170 else {
4279 if (codec->patch_ops.init) 3171 if (codec->patch_ops.init)
4280 codec->patch_ops.init(codec); 3172 codec->patch_ops.init(codec);
4281 snd_hda_codec_resume_amp(codec); 3173 if (codec->core.regmap)
4282 snd_hda_codec_resume_cache(codec); 3174 regcache_sync(codec->core.regmap);
4283 } 3175 }
4284 3176
4285 if (codec->jackpoll_interval) 3177 if (codec->jackpoll_interval)
4286 hda_jackpoll_work(&codec->jackpoll_work.work); 3178 hda_jackpoll_work(&codec->jackpoll_work.work);
4287 else 3179 else
4288 snd_hda_jack_report_sync(codec); 3180 snd_hda_jack_report_sync(codec);
4289 3181 atomic_dec(&codec->core.in_pm);
4290 codec->in_pm = 0;
4291 snd_hda_power_down(codec); /* flag down before returning */
4292} 3182}
4293#endif /* CONFIG_PM */
4294 3183
3184static int hda_codec_runtime_suspend(struct device *dev)
3185{
3186 struct hda_codec *codec = dev_to_hda_codec(dev);
3187 struct hda_pcm *pcm;
3188 unsigned int state;
4295 3189
4296/** 3190 cancel_delayed_work_sync(&codec->jackpoll_work);
4297 * snd_hda_build_controls - build mixer controls 3191 list_for_each_entry(pcm, &codec->pcm_list_head, list)
4298 * @bus: the BUS 3192 snd_pcm_suspend_all(pcm->pcm);
4299 * 3193 state = hda_call_codec_suspend(codec);
4300 * Creates mixer controls for each codec included in the bus. 3194 if (codec_has_clkstop(codec) && codec_has_epss(codec) &&
4301 * 3195 (state & AC_PWRST_CLK_STOP_OK))
4302 * Returns 0 if successful, otherwise a negative error code. 3196 snd_hdac_codec_link_down(&codec->core);
4303 */ 3197 return 0;
4304int snd_hda_build_controls(struct hda_bus *bus) 3198}
3199
3200static int hda_codec_runtime_resume(struct device *dev)
4305{ 3201{
4306 struct hda_codec *codec; 3202 struct hda_codec *codec = dev_to_hda_codec(dev);
4307 3203
4308 list_for_each_entry(codec, &bus->codec_list, list) { 3204 snd_hdac_codec_link_up(&codec->core);
4309 int err = snd_hda_codec_build_controls(codec); 3205 hda_call_codec_resume(codec);
4310 if (err < 0) { 3206 pm_runtime_mark_last_busy(dev);
4311 codec_err(codec,
4312 "cannot build controls for #%d (error %d)\n",
4313 codec->addr, err);
4314 err = snd_hda_codec_reset(codec);
4315 if (err < 0) {
4316 codec_err(codec,
4317 "cannot revert codec\n");
4318 return err;
4319 }
4320 }
4321 }
4322 return 0; 3207 return 0;
4323} 3208}
4324EXPORT_SYMBOL_GPL(snd_hda_build_controls); 3209#endif /* CONFIG_PM */
3210
3211/* referred in hda_bind.c */
3212const struct dev_pm_ops hda_codec_driver_pm = {
3213 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
3214 pm_runtime_force_resume)
3215 SET_RUNTIME_PM_OPS(hda_codec_runtime_suspend, hda_codec_runtime_resume,
3216 NULL)
3217};
4325 3218
4326/* 3219/*
4327 * add standard channel maps if not specified 3220 * add standard channel maps if not specified
4328 */ 3221 */
4329static int add_std_chmaps(struct hda_codec *codec) 3222static int add_std_chmaps(struct hda_codec *codec)
4330{ 3223{
4331 int i, str, err; 3224 struct hda_pcm *pcm;
3225 int str, err;
4332 3226
4333 for (i = 0; i < codec->num_pcms; i++) { 3227 list_for_each_entry(pcm, &codec->pcm_list_head, list) {
4334 for (str = 0; str < 2; str++) { 3228 for (str = 0; str < 2; str++) {
4335 struct snd_pcm *pcm = codec->pcm_info[i].pcm; 3229 struct hda_pcm_stream *hinfo = &pcm->stream[str];
4336 struct hda_pcm_stream *hinfo =
4337 &codec->pcm_info[i].stream[str];
4338 struct snd_pcm_chmap *chmap; 3230 struct snd_pcm_chmap *chmap;
4339 const struct snd_pcm_chmap_elem *elem; 3231 const struct snd_pcm_chmap_elem *elem;
4340 3232
4341 if (codec->pcm_info[i].own_chmap) 3233 if (!pcm || pcm->own_chmap ||
4342 continue; 3234 !hinfo->substreams)
4343 if (!pcm || !hinfo->substreams)
4344 continue; 3235 continue;
4345 elem = hinfo->chmap ? hinfo->chmap : snd_pcm_std_chmaps; 3236 elem = hinfo->chmap ? hinfo->chmap : snd_pcm_std_chmaps;
4346 err = snd_pcm_add_chmap_ctls(pcm, str, elem, 3237 err = snd_pcm_add_chmap_ctls(pcm->pcm, str, elem,
4347 hinfo->channels_max, 3238 hinfo->channels_max,
4348 0, &chmap); 3239 0, &chmap);
4349 if (err < 0) 3240 if (err < 0)
@@ -4499,43 +3390,29 @@ unsigned int snd_hda_calc_stream_format(struct hda_codec *codec,
4499} 3390}
4500EXPORT_SYMBOL_GPL(snd_hda_calc_stream_format); 3391EXPORT_SYMBOL_GPL(snd_hda_calc_stream_format);
4501 3392
4502static unsigned int get_pcm_param(struct hda_codec *codec, hda_nid_t nid, 3393static unsigned int query_pcm_param(struct hda_codec *codec, hda_nid_t nid)
4503 int dir)
4504{ 3394{
4505 unsigned int val = 0; 3395 unsigned int val = 0;
4506 if (nid != codec->afg && 3396 if (nid != codec->core.afg &&
4507 (get_wcaps(codec, nid) & AC_WCAP_FORMAT_OVRD)) 3397 (get_wcaps(codec, nid) & AC_WCAP_FORMAT_OVRD))
4508 val = snd_hda_param_read(codec, nid, AC_PAR_PCM); 3398 val = snd_hda_param_read(codec, nid, AC_PAR_PCM);
4509 if (!val || val == -1) 3399 if (!val || val == -1)
4510 val = snd_hda_param_read(codec, codec->afg, AC_PAR_PCM); 3400 val = snd_hda_param_read(codec, codec->core.afg, AC_PAR_PCM);
4511 if (!val || val == -1) 3401 if (!val || val == -1)
4512 return 0; 3402 return 0;
4513 return val; 3403 return val;
4514} 3404}
4515 3405
4516static unsigned int query_pcm_param(struct hda_codec *codec, hda_nid_t nid) 3406static unsigned int query_stream_param(struct hda_codec *codec, hda_nid_t nid)
4517{
4518 return query_caps_hash(codec, nid, 0, HDA_HASH_PARPCM_KEY(nid),
4519 get_pcm_param);
4520}
4521
4522static unsigned int get_stream_param(struct hda_codec *codec, hda_nid_t nid,
4523 int dir)
4524{ 3407{
4525 unsigned int streams = snd_hda_param_read(codec, nid, AC_PAR_STREAM); 3408 unsigned int streams = snd_hda_param_read(codec, nid, AC_PAR_STREAM);
4526 if (!streams || streams == -1) 3409 if (!streams || streams == -1)
4527 streams = snd_hda_param_read(codec, codec->afg, AC_PAR_STREAM); 3410 streams = snd_hda_param_read(codec, codec->core.afg, AC_PAR_STREAM);
4528 if (!streams || streams == -1) 3411 if (!streams || streams == -1)
4529 return 0; 3412 return 0;
4530 return streams; 3413 return streams;
4531} 3414}
4532 3415
4533static unsigned int query_stream_param(struct hda_codec *codec, hda_nid_t nid)
4534{
4535 return query_caps_hash(codec, nid, 0, HDA_HASH_PARSTR_KEY(nid),
4536 get_stream_param);
4537}
4538
4539/** 3416/**
4540 * snd_hda_query_supported_pcm - query the supported PCM rates and formats 3417 * snd_hda_query_supported_pcm - query the supported PCM rates and formats
4541 * @codec: the HDA codec 3418 * @codec: the HDA codec
@@ -4792,7 +3669,11 @@ int snd_hda_codec_prepare(struct hda_codec *codec,
4792{ 3669{
4793 int ret; 3670 int ret;
4794 mutex_lock(&codec->bus->prepare_mutex); 3671 mutex_lock(&codec->bus->prepare_mutex);
4795 ret = hinfo->ops.prepare(hinfo, codec, stream, format, substream); 3672 if (hinfo->ops.prepare)
3673 ret = hinfo->ops.prepare(hinfo, codec, stream, format,
3674 substream);
3675 else
3676 ret = -ENODEV;
4796 if (ret >= 0) 3677 if (ret >= 0)
4797 purify_inactive_streams(codec); 3678 purify_inactive_streams(codec);
4798 mutex_unlock(&codec->bus->prepare_mutex); 3679 mutex_unlock(&codec->bus->prepare_mutex);
@@ -4813,7 +3694,8 @@ void snd_hda_codec_cleanup(struct hda_codec *codec,
4813 struct snd_pcm_substream *substream) 3694 struct snd_pcm_substream *substream)
4814{ 3695{
4815 mutex_lock(&codec->bus->prepare_mutex); 3696 mutex_lock(&codec->bus->prepare_mutex);
4816 hinfo->ops.cleanup(hinfo, codec, substream); 3697 if (hinfo->ops.cleanup)
3698 hinfo->ops.cleanup(hinfo, codec, substream);
4817 mutex_unlock(&codec->bus->prepare_mutex); 3699 mutex_unlock(&codec->bus->prepare_mutex);
4818} 3700}
4819EXPORT_SYMBOL_GPL(snd_hda_codec_cleanup); 3701EXPORT_SYMBOL_GPL(snd_hda_codec_cleanup);
@@ -4871,112 +3753,84 @@ static int get_empty_pcm_device(struct hda_bus *bus, unsigned int type)
4871 return -EAGAIN; 3753 return -EAGAIN;
4872} 3754}
4873 3755
4874/* 3756/* call build_pcms ops of the given codec and set up the default parameters */
4875 * attach a new PCM stream 3757int snd_hda_codec_parse_pcms(struct hda_codec *codec)
4876 */
4877static int snd_hda_attach_pcm(struct hda_codec *codec, struct hda_pcm *pcm)
4878{ 3758{
4879 struct hda_bus *bus = codec->bus; 3759 struct hda_pcm *cpcm;
4880 struct hda_pcm_stream *info; 3760 int err;
4881 int stream, err;
4882 3761
4883 if (snd_BUG_ON(!pcm->name)) 3762 if (!list_empty(&codec->pcm_list_head))
4884 return -EINVAL; 3763 return 0; /* already parsed */
4885 for (stream = 0; stream < 2; stream++) { 3764
4886 info = &pcm->stream[stream]; 3765 if (!codec->patch_ops.build_pcms)
4887 if (info->substreams) { 3766 return 0;
3767
3768 err = codec->patch_ops.build_pcms(codec);
3769 if (err < 0) {
3770 codec_err(codec, "cannot build PCMs for #%d (error %d)\n",
3771 codec->core.addr, err);
3772 return err;
3773 }
3774
3775 list_for_each_entry(cpcm, &codec->pcm_list_head, list) {
3776 int stream;
3777
3778 for (stream = 0; stream < 2; stream++) {
3779 struct hda_pcm_stream *info = &cpcm->stream[stream];
3780
3781 if (!info->substreams)
3782 continue;
4888 err = set_pcm_default_values(codec, info); 3783 err = set_pcm_default_values(codec, info);
4889 if (err < 0) 3784 if (err < 0) {
3785 codec_warn(codec,
3786 "fail to setup default for PCM %s\n",
3787 cpcm->name);
4890 return err; 3788 return err;
3789 }
4891 } 3790 }
4892 } 3791 }
4893 return bus->ops.attach_pcm(bus, codec, pcm); 3792
3793 return 0;
4894} 3794}
4895 3795
4896/* assign all PCMs of the given codec */ 3796/* assign all PCMs of the given codec */
4897int snd_hda_codec_build_pcms(struct hda_codec *codec) 3797int snd_hda_codec_build_pcms(struct hda_codec *codec)
4898{ 3798{
4899 unsigned int pcm; 3799 struct hda_bus *bus = codec->bus;
4900 int err; 3800 struct hda_pcm *cpcm;
3801 int dev, err;
4901 3802
4902 if (!codec->num_pcms) { 3803 if (snd_BUG_ON(!bus->ops.attach_pcm))
4903 if (!codec->patch_ops.build_pcms) 3804 return -EINVAL;
4904 return 0; 3805
4905 err = codec->patch_ops.build_pcms(codec); 3806 err = snd_hda_codec_parse_pcms(codec);
4906 if (err < 0) { 3807 if (err < 0) {
4907 codec_err(codec, 3808 snd_hda_codec_reset(codec);
4908 "cannot build PCMs for #%d (error %d)\n", 3809 return err;
4909 codec->addr, err);
4910 err = snd_hda_codec_reset(codec);
4911 if (err < 0) {
4912 codec_err(codec,
4913 "cannot revert codec\n");
4914 return err;
4915 }
4916 }
4917 } 3810 }
4918 for (pcm = 0; pcm < codec->num_pcms; pcm++) {
4919 struct hda_pcm *cpcm = &codec->pcm_info[pcm];
4920 int dev;
4921 3811
3812 /* attach a new PCM streams */
3813 list_for_each_entry(cpcm, &codec->pcm_list_head, list) {
3814 if (cpcm->pcm)
3815 continue; /* already attached */
4922 if (!cpcm->stream[0].substreams && !cpcm->stream[1].substreams) 3816 if (!cpcm->stream[0].substreams && !cpcm->stream[1].substreams)
4923 continue; /* no substreams assigned */ 3817 continue; /* no substreams assigned */
4924 3818
4925 if (!cpcm->pcm) { 3819 dev = get_empty_pcm_device(bus, cpcm->pcm_type);
4926 dev = get_empty_pcm_device(codec->bus, cpcm->pcm_type); 3820 if (dev < 0)
4927 if (dev < 0) 3821 continue; /* no fatal error */
4928 continue; /* no fatal error */ 3822 cpcm->device = dev;
4929 cpcm->device = dev; 3823 err = bus->ops.attach_pcm(bus, codec, cpcm);
4930 err = snd_hda_attach_pcm(codec, cpcm); 3824 if (err < 0) {
4931 if (err < 0) { 3825 codec_err(codec,
4932 codec_err(codec, 3826 "cannot attach PCM stream %d for codec #%d\n",
4933 "cannot attach PCM stream %d for codec #%d\n", 3827 dev, codec->core.addr);
4934 dev, codec->addr); 3828 continue; /* no fatal error */
4935 continue; /* no fatal error */
4936 }
4937 } 3829 }
4938 } 3830 }
4939 return 0;
4940}
4941 3831
4942/**
4943 * snd_hda_build_pcms - build PCM information
4944 * @bus: the BUS
4945 *
4946 * Create PCM information for each codec included in the bus.
4947 *
4948 * The build_pcms codec patch is requested to set up codec->num_pcms and
4949 * codec->pcm_info properly. The array is referred by the top-level driver
4950 * to create its PCM instances.
4951 * The allocated codec->pcm_info should be released in codec->patch_ops.free
4952 * callback.
4953 *
4954 * At least, substreams, channels_min and channels_max must be filled for
4955 * each stream. substreams = 0 indicates that the stream doesn't exist.
4956 * When rates and/or formats are zero, the supported values are queried
4957 * from the given nid. The nid is used also by the default ops.prepare
4958 * and ops.cleanup callbacks.
4959 *
4960 * The driver needs to call ops.open in its open callback. Similarly,
4961 * ops.close is supposed to be called in the close callback.
4962 * ops.prepare should be called in the prepare or hw_params callback
4963 * with the proper parameters for set up.
4964 * ops.cleanup should be called in hw_free for clean up of streams.
4965 *
4966 * This function returns 0 if successful, or a negative error code.
4967 */
4968int snd_hda_build_pcms(struct hda_bus *bus)
4969{
4970 struct hda_codec *codec;
4971
4972 list_for_each_entry(codec, &bus->codec_list, list) {
4973 int err = snd_hda_codec_build_pcms(codec);
4974 if (err < 0)
4975 return err;
4976 }
4977 return 0; 3832 return 0;
4978} 3833}
4979EXPORT_SYMBOL_GPL(snd_hda_build_pcms);
4980 3834
4981/** 3835/**
4982 * snd_hda_add_new_ctls - create controls from the array 3836 * snd_hda_add_new_ctls - create controls from the array
@@ -5013,8 +3867,8 @@ int snd_hda_add_new_ctls(struct hda_codec *codec,
5013 * the codec addr; if it still fails (or it's the 3867 * the codec addr; if it still fails (or it's the
5014 * primary codec), then try another control index 3868 * primary codec), then try another control index
5015 */ 3869 */
5016 if (!addr && codec->addr) 3870 if (!addr && codec->core.addr)
5017 addr = codec->addr; 3871 addr = codec->core.addr;
5018 else if (!idx && !knew->index) { 3872 else if (!idx && !knew->index) {
5019 idx = find_empty_mixer_ctl_idx(codec, 3873 idx = find_empty_mixer_ctl_idx(codec,
5020 knew->name, 0); 3874 knew->name, 0);
@@ -5029,127 +3883,37 @@ int snd_hda_add_new_ctls(struct hda_codec *codec,
5029EXPORT_SYMBOL_GPL(snd_hda_add_new_ctls); 3883EXPORT_SYMBOL_GPL(snd_hda_add_new_ctls);
5030 3884
5031#ifdef CONFIG_PM 3885#ifdef CONFIG_PM
5032static void hda_power_work(struct work_struct *work) 3886static void codec_set_power_save(struct hda_codec *codec, int delay)
5033{
5034 struct hda_codec *codec =
5035 container_of(work, struct hda_codec, power_work.work);
5036 struct hda_bus *bus = codec->bus;
5037 unsigned int state;
5038
5039 spin_lock(&codec->power_lock);
5040 if (codec->power_transition > 0) { /* during power-up sequence? */
5041 spin_unlock(&codec->power_lock);
5042 return;
5043 }
5044 if (!codec->power_on || codec->power_count) {
5045 codec->power_transition = 0;
5046 spin_unlock(&codec->power_lock);
5047 return;
5048 }
5049 spin_unlock(&codec->power_lock);
5050
5051 state = hda_call_codec_suspend(codec, true);
5052 if (!bus->power_keep_link_on && (state & AC_PWRST_CLK_STOP_OK))
5053 hda_call_pm_notify(codec, false);
5054}
5055
5056static void hda_keep_power_on(struct hda_codec *codec)
5057{
5058 spin_lock(&codec->power_lock);
5059 codec->power_count++;
5060 codec->power_on = 1;
5061 codec->power_jiffies = jiffies;
5062 spin_unlock(&codec->power_lock);
5063 hda_call_pm_notify(codec, true);
5064}
5065
5066/* update the power on/off account with the current jiffies */
5067void snd_hda_update_power_acct(struct hda_codec *codec)
5068{
5069 unsigned long delta = jiffies - codec->power_jiffies;
5070 if (codec->power_on)
5071 codec->power_on_acct += delta;
5072 else
5073 codec->power_off_acct += delta;
5074 codec->power_jiffies += delta;
5075}
5076
5077/* Transition to powered up, if wait_power_down then wait for a pending
5078 * transition to D3 to complete. A pending D3 transition is indicated
5079 * with power_transition == -1. */
5080/* call this with codec->power_lock held! */
5081static void __snd_hda_power_up(struct hda_codec *codec, bool wait_power_down)
5082{
5083 /* Return if power_on or transitioning to power_on, unless currently
5084 * powering down. */
5085 if ((codec->power_on || codec->power_transition > 0) &&
5086 !(wait_power_down && codec->power_transition < 0))
5087 return;
5088 spin_unlock(&codec->power_lock);
5089
5090 cancel_delayed_work_sync(&codec->power_work);
5091
5092 spin_lock(&codec->power_lock);
5093 /* If the power down delayed work was cancelled above before starting,
5094 * then there is no need to go through power up here.
5095 */
5096 if (codec->power_on) {
5097 if (codec->power_transition < 0)
5098 codec->power_transition = 0;
5099 return;
5100 }
5101
5102 trace_hda_power_up(codec);
5103 snd_hda_update_power_acct(codec);
5104 codec->power_on = 1;
5105 codec->power_jiffies = jiffies;
5106 codec->power_transition = 1; /* avoid reentrance */
5107 spin_unlock(&codec->power_lock);
5108
5109 hda_call_codec_resume(codec);
5110
5111 spin_lock(&codec->power_lock);
5112 codec->power_transition = 0;
5113}
5114
5115#define power_save(codec) \
5116 ((codec)->bus->power_save ? *(codec)->bus->power_save : 0)
5117
5118/* Transition to powered down */
5119static void __snd_hda_power_down(struct hda_codec *codec)
5120{ 3887{
5121 if (!codec->power_on || codec->power_count || codec->power_transition) 3888 struct device *dev = hda_codec_dev(codec);
5122 return;
5123 3889
5124 if (power_save(codec)) { 3890 if (delay > 0) {
5125 codec->power_transition = -1; /* avoid reentrance */ 3891 pm_runtime_set_autosuspend_delay(dev, delay);
5126 queue_delayed_work(codec->bus->workq, &codec->power_work, 3892 pm_runtime_use_autosuspend(dev);
5127 msecs_to_jiffies(power_save(codec) * 1000)); 3893 pm_runtime_allow(dev);
3894 if (!pm_runtime_suspended(dev))
3895 pm_runtime_mark_last_busy(dev);
3896 } else {
3897 pm_runtime_dont_use_autosuspend(dev);
3898 pm_runtime_forbid(dev);
5128 } 3899 }
5129} 3900}
5130 3901
5131/** 3902/**
5132 * snd_hda_power_save - Power-up/down/sync the codec 3903 * snd_hda_set_power_save - reprogram autosuspend for the given delay
5133 * @codec: HD-audio codec 3904 * @bus: HD-audio bus
5134 * @delta: the counter delta to change 3905 * @delay: autosuspend delay in msec, 0 = off
5135 * @d3wait: sync for D3 transition complete
5136 * 3906 *
5137 * Change the power-up counter via @delta, and power up or down the hardware 3907 * Synchronize the runtime PM autosuspend state from the power_save option.
5138 * appropriately. For the power-down, queue to the delayed action.
5139 * Passing zero to @delta means to synchronize the power state.
5140 */ 3908 */
5141void snd_hda_power_save(struct hda_codec *codec, int delta, bool d3wait) 3909void snd_hda_set_power_save(struct hda_bus *bus, int delay)
5142{ 3910{
5143 spin_lock(&codec->power_lock); 3911 struct hda_codec *c;
5144 codec->power_count += delta; 3912
5145 trace_hda_power_count(codec); 3913 list_for_each_codec(c, bus)
5146 if (delta > 0) 3914 codec_set_power_save(c, delay);
5147 __snd_hda_power_up(codec, d3wait);
5148 else
5149 __snd_hda_power_down(codec);
5150 spin_unlock(&codec->power_lock);
5151} 3915}
5152EXPORT_SYMBOL_GPL(snd_hda_power_save); 3916EXPORT_SYMBOL_GPL(snd_hda_set_power_save);
5153 3917
5154/** 3918/**
5155 * snd_hda_check_amp_list_power - Check the amp list and update the power 3919 * snd_hda_check_amp_list_power - Check the amp list and update the power
@@ -5187,7 +3951,7 @@ int snd_hda_check_amp_list_power(struct hda_codec *codec,
5187 if (!(v & HDA_AMP_MUTE) && v > 0) { 3951 if (!(v & HDA_AMP_MUTE) && v > 0) {
5188 if (!check->power_on) { 3952 if (!check->power_on) {
5189 check->power_on = 1; 3953 check->power_on = 1;
5190 snd_hda_power_up(codec); 3954 snd_hda_power_up_pm(codec);
5191 } 3955 }
5192 return 1; 3956 return 1;
5193 } 3957 }
@@ -5195,7 +3959,7 @@ int snd_hda_check_amp_list_power(struct hda_codec *codec,
5195 } 3959 }
5196 if (check->power_on) { 3960 if (check->power_on) {
5197 check->power_on = 0; 3961 check->power_on = 0;
5198 snd_hda_power_down(codec); 3962 snd_hda_power_down_pm(codec);
5199 } 3963 }
5200 return 0; 3964 return 0;
5201} 3965}
@@ -5203,88 +3967,6 @@ EXPORT_SYMBOL_GPL(snd_hda_check_amp_list_power);
5203#endif 3967#endif
5204 3968
5205/* 3969/*
5206 * Channel mode helper
5207 */
5208
5209/**
5210 * snd_hda_ch_mode_info - Info callback helper for the channel mode enum
5211 * @codec: the HDA codec
5212 * @uinfo: pointer to get/store the data
5213 * @chmode: channel mode array
5214 * @num_chmodes: channel mode array size
5215 */
5216int snd_hda_ch_mode_info(struct hda_codec *codec,
5217 struct snd_ctl_elem_info *uinfo,
5218 const struct hda_channel_mode *chmode,
5219 int num_chmodes)
5220{
5221 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
5222 uinfo->count = 1;
5223 uinfo->value.enumerated.items = num_chmodes;
5224 if (uinfo->value.enumerated.item >= num_chmodes)
5225 uinfo->value.enumerated.item = num_chmodes - 1;
5226 sprintf(uinfo->value.enumerated.name, "%dch",
5227 chmode[uinfo->value.enumerated.item].channels);
5228 return 0;
5229}
5230EXPORT_SYMBOL_GPL(snd_hda_ch_mode_info);
5231
5232/**
5233 * snd_hda_ch_mode_get - Get callback helper for the channel mode enum
5234 * @codec: the HDA codec
5235 * @ucontrol: pointer to get/store the data
5236 * @chmode: channel mode array
5237 * @num_chmodes: channel mode array size
5238 * @max_channels: max number of channels
5239 */
5240int snd_hda_ch_mode_get(struct hda_codec *codec,
5241 struct snd_ctl_elem_value *ucontrol,
5242 const struct hda_channel_mode *chmode,
5243 int num_chmodes,
5244 int max_channels)
5245{
5246 int i;
5247
5248 for (i = 0; i < num_chmodes; i++) {
5249 if (max_channels == chmode[i].channels) {
5250 ucontrol->value.enumerated.item[0] = i;
5251 break;
5252 }
5253 }
5254 return 0;
5255}
5256EXPORT_SYMBOL_GPL(snd_hda_ch_mode_get);
5257
5258/**
5259 * snd_hda_ch_mode_put - Put callback helper for the channel mode enum
5260 * @codec: the HDA codec
5261 * @ucontrol: pointer to get/store the data
5262 * @chmode: channel mode array
5263 * @num_chmodes: channel mode array size
5264 * @max_channelsp: pointer to store the max channels
5265 */
5266int snd_hda_ch_mode_put(struct hda_codec *codec,
5267 struct snd_ctl_elem_value *ucontrol,
5268 const struct hda_channel_mode *chmode,
5269 int num_chmodes,
5270 int *max_channelsp)
5271{
5272 unsigned int mode;
5273
5274 mode = ucontrol->value.enumerated.item[0];
5275 if (mode >= num_chmodes)
5276 return -EINVAL;
5277 if (*max_channelsp == chmode[mode].channels)
5278 return 0;
5279 /* change the current channel setting */
5280 *max_channelsp = chmode[mode].channels;
5281 if (chmode[mode].sequence)
5282 snd_hda_sequence_write_cache(codec, chmode[mode].sequence);
5283 return 1;
5284}
5285EXPORT_SYMBOL_GPL(snd_hda_ch_mode_put);
5286
5287/*
5288 * input MUX helper 3970 * input MUX helper
5289 */ 3971 */
5290 3972
@@ -5418,24 +4100,6 @@ static void cleanup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid)
5418} 4100}
5419 4101
5420/** 4102/**
5421 * snd_hda_bus_reboot_notify - call the reboot notifier of each codec
5422 * @bus: HD-audio bus
5423 */
5424void snd_hda_bus_reboot_notify(struct hda_bus *bus)
5425{
5426 struct hda_codec *codec;
5427
5428 if (!bus)
5429 return;
5430 list_for_each_entry(codec, &bus->codec_list, list) {
5431 if (hda_codec_is_power_on(codec) &&
5432 codec->patch_ops.reboot_notify)
5433 codec->patch_ops.reboot_notify(codec);
5434 }
5435}
5436EXPORT_SYMBOL_GPL(snd_hda_bus_reboot_notify);
5437
5438/**
5439 * snd_hda_multi_out_dig_open - open the digital out in the exclusive mode 4103 * snd_hda_multi_out_dig_open - open the digital out in the exclusive mode
5440 * @codec: the HDA codec 4104 * @codec: the HDA codec
5441 * @mout: hda_multi_out object 4105 * @mout: hda_multi_out object
@@ -5825,123 +4489,26 @@ int snd_hda_add_imux_item(struct hda_codec *codec,
5825} 4489}
5826EXPORT_SYMBOL_GPL(snd_hda_add_imux_item); 4490EXPORT_SYMBOL_GPL(snd_hda_add_imux_item);
5827 4491
5828
5829#ifdef CONFIG_PM
5830/*
5831 * power management
5832 */
5833
5834
5835static void hda_async_suspend(void *data, async_cookie_t cookie)
5836{
5837 hda_call_codec_suspend(data, false);
5838}
5839
5840static void hda_async_resume(void *data, async_cookie_t cookie)
5841{
5842 hda_call_codec_resume(data);
5843}
5844
5845/** 4492/**
5846 * snd_hda_suspend - suspend the codecs 4493 * snd_hda_bus_reset - Reset the bus
5847 * @bus: the HDA bus 4494 * @bus: HD-audio bus
5848 *
5849 * Returns 0 if successful.
5850 */ 4495 */
5851int snd_hda_suspend(struct hda_bus *bus) 4496void snd_hda_bus_reset(struct hda_bus *bus)
5852{ 4497{
5853 struct hda_codec *codec; 4498 struct hda_codec *codec;
5854 ASYNC_DOMAIN_EXCLUSIVE(domain);
5855 4499
5856 list_for_each_entry(codec, &bus->codec_list, list) { 4500 list_for_each_codec(codec, bus) {
4501 /* FIXME: maybe a better way needed for forced reset */
5857 cancel_delayed_work_sync(&codec->jackpoll_work); 4502 cancel_delayed_work_sync(&codec->jackpoll_work);
4503#ifdef CONFIG_PM
5858 if (hda_codec_is_power_on(codec)) { 4504 if (hda_codec_is_power_on(codec)) {
5859 if (bus->num_codecs > 1) 4505 hda_call_codec_suspend(codec);
5860 async_schedule_domain(hda_async_suspend, codec,
5861 &domain);
5862 else
5863 hda_call_codec_suspend(codec, false);
5864 }
5865 }
5866
5867 if (bus->num_codecs > 1)
5868 async_synchronize_full_domain(&domain);
5869
5870 return 0;
5871}
5872EXPORT_SYMBOL_GPL(snd_hda_suspend);
5873
5874/**
5875 * snd_hda_resume - resume the codecs
5876 * @bus: the HDA bus
5877 *
5878 * Returns 0 if successful.
5879 */
5880int snd_hda_resume(struct hda_bus *bus)
5881{
5882 struct hda_codec *codec;
5883 ASYNC_DOMAIN_EXCLUSIVE(domain);
5884
5885 list_for_each_entry(codec, &bus->codec_list, list) {
5886 if (bus->num_codecs > 1)
5887 async_schedule_domain(hda_async_resume, codec, &domain);
5888 else
5889 hda_call_codec_resume(codec); 4506 hda_call_codec_resume(codec);
4507 }
4508#endif
5890 } 4509 }
5891
5892 if (bus->num_codecs > 1)
5893 async_synchronize_full_domain(&domain);
5894
5895 return 0;
5896}
5897EXPORT_SYMBOL_GPL(snd_hda_resume);
5898#endif /* CONFIG_PM */
5899
5900/*
5901 * generic arrays
5902 */
5903
5904/**
5905 * snd_array_new - get a new element from the given array
5906 * @array: the array object
5907 *
5908 * Get a new element from the given array. If it exceeds the
5909 * pre-allocated array size, re-allocate the array.
5910 *
5911 * Returns NULL if allocation failed.
5912 */
5913void *snd_array_new(struct snd_array *array)
5914{
5915 if (snd_BUG_ON(!array->elem_size))
5916 return NULL;
5917 if (array->used >= array->alloced) {
5918 int num = array->alloced + array->alloc_align;
5919 int size = (num + 1) * array->elem_size;
5920 void *nlist;
5921 if (snd_BUG_ON(num >= 4096))
5922 return NULL;
5923 nlist = krealloc(array->list, size, GFP_KERNEL | __GFP_ZERO);
5924 if (!nlist)
5925 return NULL;
5926 array->list = nlist;
5927 array->alloced = num;
5928 }
5929 return snd_array_elem(array, array->used++);
5930}
5931EXPORT_SYMBOL_GPL(snd_array_new);
5932
5933/**
5934 * snd_array_free - free the given array elements
5935 * @array: the array object
5936 */
5937void snd_array_free(struct snd_array *array)
5938{
5939 kfree(array->list);
5940 array->used = 0;
5941 array->alloced = 0;
5942 array->list = NULL;
5943} 4510}
5944EXPORT_SYMBOL_GPL(snd_array_free); 4511EXPORT_SYMBOL_GPL(snd_hda_bus_reset);
5945 4512
5946/** 4513/**
5947 * snd_print_pcm_bits - Print the supported PCM fmt bits to the string buffer 4514 * snd_print_pcm_bits - Print the supported PCM fmt bits to the string buffer
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
index 9c8820f21f94..9075ac28dc4b 100644
--- a/sound/pci/hda/hda_codec.h
+++ b/sound/pci/hda/hda_codec.h
@@ -21,41 +21,14 @@
21#ifndef __SOUND_HDA_CODEC_H 21#ifndef __SOUND_HDA_CODEC_H
22#define __SOUND_HDA_CODEC_H 22#define __SOUND_HDA_CODEC_H
23 23
24#include <linux/kref.h>
24#include <sound/info.h> 25#include <sound/info.h>
25#include <sound/control.h> 26#include <sound/control.h>
26#include <sound/pcm.h> 27#include <sound/pcm.h>
27#include <sound/hwdep.h> 28#include <sound/hwdep.h>
29#include <sound/hdaudio.h>
28#include <sound/hda_verbs.h> 30#include <sound/hda_verbs.h>
29 31#include <sound/hda_regmap.h>
30/*
31 * generic arrays
32 */
33struct snd_array {
34 unsigned int used;
35 unsigned int alloced;
36 unsigned int elem_size;
37 unsigned int alloc_align;
38 void *list;
39};
40
41void *snd_array_new(struct snd_array *array);
42void snd_array_free(struct snd_array *array);
43static inline void snd_array_init(struct snd_array *array, unsigned int size,
44 unsigned int align)
45{
46 array->elem_size = size;
47 array->alloc_align = align;
48}
49
50static inline void *snd_array_elem(struct snd_array *array, unsigned int idx)
51{
52 return array->list + idx * array->elem_size;
53}
54
55static inline unsigned int snd_array_index(struct snd_array *array, void *ptr)
56{
57 return (unsigned long)(ptr - array->list) / array->elem_size;
58}
59 32
60/* 33/*
61 * Structures 34 * Structures
@@ -66,10 +39,6 @@ struct hda_beep;
66struct hda_codec; 39struct hda_codec;
67struct hda_pcm; 40struct hda_pcm;
68struct hda_pcm_stream; 41struct hda_pcm_stream;
69struct hda_bus_unsolicited;
70
71/* NID type */
72typedef u16 hda_nid_t;
73 42
74/* bus operators */ 43/* bus operators */
75struct hda_bus_ops { 44struct hda_bus_ops {
@@ -84,10 +53,6 @@ struct hda_bus_ops {
84 struct hda_pcm *pcm); 53 struct hda_pcm *pcm);
85 /* reset bus for retry verb */ 54 /* reset bus for retry verb */
86 void (*bus_reset)(struct hda_bus *bus); 55 void (*bus_reset)(struct hda_bus *bus);
87#ifdef CONFIG_PM
88 /* notify power-up/down from codec to controller */
89 void (*pm_notify)(struct hda_bus *bus, bool power_up);
90#endif
91#ifdef CONFIG_SND_HDA_DSP_LOADER 56#ifdef CONFIG_SND_HDA_DSP_LOADER
92 /* prepare DSP transfer */ 57 /* prepare DSP transfer */
93 int (*load_dsp_prepare)(struct hda_bus *bus, unsigned int format, 58 int (*load_dsp_prepare)(struct hda_bus *bus, unsigned int format,
@@ -101,15 +66,6 @@ struct hda_bus_ops {
101#endif 66#endif
102}; 67};
103 68
104/* template to pass to the bus constructor */
105struct hda_bus_template {
106 void *private_data;
107 struct pci_dev *pci;
108 const char *modelname;
109 int *power_save;
110 struct hda_bus_ops ops;
111};
112
113/* 69/*
114 * codec bus 70 * codec bus
115 * 71 *
@@ -117,42 +73,28 @@ struct hda_bus_template {
117 * A hda_bus contains several codecs in the list codec_list. 73 * A hda_bus contains several codecs in the list codec_list.
118 */ 74 */
119struct hda_bus { 75struct hda_bus {
76 struct hdac_bus core;
77
120 struct snd_card *card; 78 struct snd_card *card;
121 79
122 /* copied from template */
123 void *private_data; 80 void *private_data;
124 struct pci_dev *pci; 81 struct pci_dev *pci;
125 const char *modelname; 82 const char *modelname;
126 int *power_save;
127 struct hda_bus_ops ops; 83 struct hda_bus_ops ops;
128 84
129 /* codec linked list */
130 struct list_head codec_list;
131 unsigned int num_codecs;
132 /* link caddr -> codec */
133 struct hda_codec *caddr_tbl[HDA_MAX_CODEC_ADDRESS + 1];
134
135 struct mutex cmd_mutex;
136 struct mutex prepare_mutex; 85 struct mutex prepare_mutex;
137 86
138 /* unsolicited event queue */
139 struct hda_bus_unsolicited *unsol;
140 char workq_name[16];
141 struct workqueue_struct *workq; /* common workqueue for codecs */
142
143 /* assigned PCMs */ 87 /* assigned PCMs */
144 DECLARE_BITMAP(pcm_dev_bits, SNDRV_PCM_DEVICES); 88 DECLARE_BITMAP(pcm_dev_bits, SNDRV_PCM_DEVICES);
145 89
146 /* misc op flags */ 90 /* misc op flags */
147 unsigned int needs_damn_long_delay :1; 91 unsigned int needs_damn_long_delay :1;
148 unsigned int allow_bus_reset:1; /* allow bus reset at fatal error */ 92 unsigned int allow_bus_reset:1; /* allow bus reset at fatal error */
149 unsigned int sync_write:1; /* sync after verb write */
150 /* status for codec/controller */ 93 /* status for codec/controller */
151 unsigned int shutdown :1; /* being unloaded */ 94 unsigned int shutdown :1; /* being unloaded */
152 unsigned int rirb_error:1; /* error in codec communication */ 95 unsigned int rirb_error:1; /* error in codec communication */
153 unsigned int response_reset:1; /* controller was reset */ 96 unsigned int response_reset:1; /* controller was reset */
154 unsigned int in_reset:1; /* during reset operation */ 97 unsigned int in_reset:1; /* during reset operation */
155 unsigned int power_keep_link_on:1; /* don't power off HDA link */
156 unsigned int no_response_fallback:1; /* don't fallback at RIRB error */ 98 unsigned int no_response_fallback:1; /* don't fallback at RIRB error */
157 99
158 int primary_dig_out_type; /* primary digital out PCM type */ 100 int primary_dig_out_type; /* primary digital out PCM type */
@@ -175,15 +117,22 @@ struct hda_codec_preset {
175 int (*patch)(struct hda_codec *codec); 117 int (*patch)(struct hda_codec *codec);
176}; 118};
177 119
178struct hda_codec_preset_list { 120#define HDA_CODEC_ID_GENERIC_HDMI 0x00000101
121#define HDA_CODEC_ID_GENERIC 0x00000201
122
123struct hda_codec_driver {
124 struct hdac_driver core;
179 const struct hda_codec_preset *preset; 125 const struct hda_codec_preset *preset;
180 struct module *owner;
181 struct list_head list;
182}; 126};
183 127
184/* initial hook */ 128int __hda_codec_driver_register(struct hda_codec_driver *drv, const char *name,
185int snd_hda_add_codec_preset(struct hda_codec_preset_list *preset); 129 struct module *owner);
186int snd_hda_delete_codec_preset(struct hda_codec_preset_list *preset); 130#define hda_codec_driver_register(drv) \
131 __hda_codec_driver_register(drv, KBUILD_MODNAME, THIS_MODULE)
132void hda_codec_driver_unregister(struct hda_codec_driver *drv);
133#define module_hda_codec_driver(drv) \
134 module_driver(drv, hda_codec_driver_register, \
135 hda_codec_driver_unregister)
187 136
188/* ops set by the preset patch */ 137/* ops set by the preset patch */
189struct hda_codec_ops { 138struct hda_codec_ops {
@@ -200,25 +149,7 @@ struct hda_codec_ops {
200 int (*check_power_status)(struct hda_codec *codec, hda_nid_t nid); 149 int (*check_power_status)(struct hda_codec *codec, hda_nid_t nid);
201#endif 150#endif
202 void (*reboot_notify)(struct hda_codec *codec); 151 void (*reboot_notify)(struct hda_codec *codec);
203}; 152 void (*stream_pm)(struct hda_codec *codec, hda_nid_t nid, bool on);
204
205/* record for amp information cache */
206struct hda_cache_head {
207 u32 key:31; /* hash key */
208 u32 dirty:1;
209 u16 val; /* assigned value */
210 u16 next;
211};
212
213struct hda_amp_info {
214 struct hda_cache_head head;
215 u32 amp_caps; /* amp capabilities */
216 u16 vol[2]; /* current volume & mute */
217};
218
219struct hda_cache_rec {
220 u16 hash[64]; /* hash table for index */
221 struct snd_array buf; /* record entries */
222}; 153};
223 154
224/* PCM callbacks */ 155/* PCM callbacks */
@@ -267,41 +198,29 @@ struct hda_pcm {
267 int device; /* device number to assign */ 198 int device; /* device number to assign */
268 struct snd_pcm *pcm; /* assigned PCM instance */ 199 struct snd_pcm *pcm; /* assigned PCM instance */
269 bool own_chmap; /* codec driver provides own channel maps */ 200 bool own_chmap; /* codec driver provides own channel maps */
201 /* private: */
202 struct hda_codec *codec;
203 struct kref kref;
204 struct list_head list;
270}; 205};
271 206
272/* codec information */ 207/* codec information */
273struct hda_codec { 208struct hda_codec {
274 struct device dev; 209 struct hdac_device core;
275 struct hda_bus *bus; 210 struct hda_bus *bus;
211 struct snd_card *card;
276 unsigned int addr; /* codec addr*/ 212 unsigned int addr; /* codec addr*/
277 struct list_head list; /* list point */ 213 u32 probe_id; /* overridden id for probing */
278
279 hda_nid_t afg; /* AFG node id */
280 hda_nid_t mfg; /* MFG node id */
281
282 /* ids */
283 u8 afg_function_id;
284 u8 mfg_function_id;
285 u8 afg_unsol;
286 u8 mfg_unsol;
287 u32 vendor_id;
288 u32 subsystem_id;
289 u32 revision_id;
290 214
291 /* detected preset */ 215 /* detected preset */
292 const struct hda_codec_preset *preset; 216 const struct hda_codec_preset *preset;
293 struct module *owner;
294 int (*parser)(struct hda_codec *codec);
295 const char *vendor_name; /* codec vendor name */
296 const char *chip_name; /* codec chip name */
297 const char *modelname; /* model name for preset */ 217 const char *modelname; /* model name for preset */
298 218
299 /* set by patch */ 219 /* set by patch */
300 struct hda_codec_ops patch_ops; 220 struct hda_codec_ops patch_ops;
301 221
302 /* PCM to create, set by patch_ops.build_pcms callback */ 222 /* PCM to create, set by patch_ops.build_pcms callback */
303 unsigned int num_pcms; 223 struct list_head pcm_list_head;
304 struct hda_pcm *pcm_info;
305 224
306 /* codec specific info */ 225 /* codec specific info */
307 void *spec; 226 void *spec;
@@ -311,21 +230,15 @@ struct hda_codec {
311 unsigned int beep_mode; 230 unsigned int beep_mode;
312 231
313 /* widget capabilities cache */ 232 /* widget capabilities cache */
314 unsigned int num_nodes;
315 hda_nid_t start_nid;
316 u32 *wcaps; 233 u32 *wcaps;
317 234
318 struct snd_array mixers; /* list of assigned mixer elements */ 235 struct snd_array mixers; /* list of assigned mixer elements */
319 struct snd_array nids; /* list of mapped mixer elements */ 236 struct snd_array nids; /* list of mapped mixer elements */
320 237
321 struct hda_cache_rec amp_cache; /* cache for amp access */
322 struct hda_cache_rec cmd_cache; /* cache for other commands */
323
324 struct list_head conn_list; /* linked-list of connection-list */ 238 struct list_head conn_list; /* linked-list of connection-list */
325 239
326 struct mutex spdif_mutex; 240 struct mutex spdif_mutex;
327 struct mutex control_mutex; 241 struct mutex control_mutex;
328 struct mutex hash_mutex;
329 struct snd_array spdif_out; 242 struct snd_array spdif_out;
330 unsigned int spdif_in_enable; /* SPDIF input enable? */ 243 unsigned int spdif_in_enable; /* SPDIF input enable? */
331 const hda_nid_t *slave_dig_outs; /* optional digital out slave widgets */ 244 const hda_nid_t *slave_dig_outs; /* optional digital out slave widgets */
@@ -345,6 +258,8 @@ struct hda_codec {
345#endif 258#endif
346 259
347 /* misc flags */ 260 /* misc flags */
261 unsigned int in_freeing:1; /* being released */
262 unsigned int registered:1; /* codec was registered */
348 unsigned int spdif_status_reset :1; /* needs to toggle SPDIF for each 263 unsigned int spdif_status_reset :1; /* needs to toggle SPDIF for each
349 * status change 264 * status change
350 * (e.g. Realtek codecs) 265 * (e.g. Realtek codecs)
@@ -362,22 +277,14 @@ struct hda_codec {
362 unsigned int inv_eapd:1; /* broken h/w: inverted EAPD control */ 277 unsigned int inv_eapd:1; /* broken h/w: inverted EAPD control */
363 unsigned int inv_jack_detect:1; /* broken h/w: inverted detection bit */ 278 unsigned int inv_jack_detect:1; /* broken h/w: inverted detection bit */
364 unsigned int pcm_format_first:1; /* PCM format must be set first */ 279 unsigned int pcm_format_first:1; /* PCM format must be set first */
365 unsigned int epss:1; /* supporting EPSS? */
366 unsigned int cached_write:1; /* write only to caches */ 280 unsigned int cached_write:1; /* write only to caches */
367 unsigned int dp_mst:1; /* support DP1.2 Multi-stream transport */ 281 unsigned int dp_mst:1; /* support DP1.2 Multi-stream transport */
368 unsigned int dump_coef:1; /* dump processing coefs in codec proc file */ 282 unsigned int dump_coef:1; /* dump processing coefs in codec proc file */
283 unsigned int power_save_node:1; /* advanced PM for each widget */
369#ifdef CONFIG_PM 284#ifdef CONFIG_PM
370 unsigned int power_on :1; /* current (global) power-state */
371 unsigned int d3_stop_clk:1; /* support D3 operation without BCLK */
372 unsigned int pm_up_notified:1; /* PM notified to controller */
373 unsigned int in_pm:1; /* suspend/resume being performed */
374 int power_transition; /* power-state in transition */
375 int power_count; /* current (global) power refcount */
376 struct delayed_work power_work; /* delayed task for powerdown */
377 unsigned long power_on_acct; 285 unsigned long power_on_acct;
378 unsigned long power_off_acct; 286 unsigned long power_off_acct;
379 unsigned long power_jiffies; 287 unsigned long power_jiffies;
380 spinlock_t power_lock;
381#endif 288#endif
382 289
383 /* filter the requested power state per nid */ 290 /* filter the requested power state per nid */
@@ -409,10 +316,11 @@ struct hda_codec {
409 struct snd_array verbs; 316 struct snd_array verbs;
410}; 317};
411 318
412/* direction */ 319#define dev_to_hda_codec(_dev) container_of(_dev, struct hda_codec, core.dev)
413enum { 320#define hda_codec_dev(_dev) (&(_dev)->core.dev)
414 HDA_INPUT, HDA_OUTPUT 321
415}; 322#define list_for_each_codec(c, bus) \
323 list_for_each_entry(c, &(bus)->core.codec_list, core.list)
416 324
417/* snd_hda_codec_read/write optional flags */ 325/* snd_hda_codec_read/write optional flags */
418#define HDA_RW_NO_RESPONSE_FALLBACK (1 << 0) 326#define HDA_RW_NO_RESPONSE_FALLBACK (1 << 0)
@@ -420,10 +328,9 @@ enum {
420/* 328/*
421 * constructors 329 * constructors
422 */ 330 */
423int snd_hda_bus_new(struct snd_card *card, const struct hda_bus_template *temp, 331int snd_hda_bus_new(struct snd_card *card, struct hda_bus **busp);
424 struct hda_bus **busp); 332int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card,
425int snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr, 333 unsigned int codec_addr, struct hda_codec **codecp);
426 struct hda_codec **codecp);
427int snd_hda_codec_configure(struct hda_codec *codec); 334int snd_hda_codec_configure(struct hda_codec *codec);
428int snd_hda_codec_update_widgets(struct hda_codec *codec); 335int snd_hda_codec_update_widgets(struct hda_codec *codec);
429 336
@@ -436,9 +343,9 @@ unsigned int snd_hda_codec_read(struct hda_codec *codec, hda_nid_t nid,
436int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int flags, 343int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int flags,
437 unsigned int verb, unsigned int parm); 344 unsigned int verb, unsigned int parm);
438#define snd_hda_param_read(codec, nid, param) \ 345#define snd_hda_param_read(codec, nid, param) \
439 snd_hda_codec_read(codec, nid, 0, AC_VERB_PARAMETERS, param) 346 snd_hdac_read_parm(&(codec)->core, nid, param)
440int snd_hda_get_sub_nodes(struct hda_codec *codec, hda_nid_t nid, 347#define snd_hda_get_sub_nodes(codec, nid, start_nid) \
441 hda_nid_t *start_id); 348 snd_hdac_get_sub_nodes(&(codec)->core, nid, start_nid)
442int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid, 349int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
443 hda_nid_t *conn_list, int max_conns); 350 hda_nid_t *conn_list, int max_conns);
444static inline int 351static inline int
@@ -446,9 +353,12 @@ snd_hda_get_num_conns(struct hda_codec *codec, hda_nid_t nid)
446{ 353{
447 return snd_hda_get_connections(codec, nid, NULL, 0); 354 return snd_hda_get_connections(codec, nid, NULL, 0);
448} 355}
449int snd_hda_get_num_raw_conns(struct hda_codec *codec, hda_nid_t nid); 356
450int snd_hda_get_raw_connections(struct hda_codec *codec, hda_nid_t nid, 357#define snd_hda_get_raw_connections(codec, nid, list, max_conns) \
451 hda_nid_t *conn_list, int max_conns); 358 snd_hdac_get_connections(&(codec)->core, nid, list, max_conns)
359#define snd_hda_get_num_raw_conns(codec, nid) \
360 snd_hdac_get_connections(&(codec)->core, nid, NULL, 0);
361
452int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid, 362int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid,
453 const hda_nid_t **listp); 363 const hda_nid_t **listp);
454int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int nums, 364int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int nums,
@@ -470,18 +380,22 @@ void snd_hda_sequence_write(struct hda_codec *codec,
470 const struct hda_verb *seq); 380 const struct hda_verb *seq);
471 381
472/* unsolicited event */ 382/* unsolicited event */
473int snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex); 383static inline void
384snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex)
385{
386 snd_hdac_bus_queue_event(&bus->core, res, res_ex);
387}
474 388
475/* cached write */ 389/* cached write */
476int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid, 390static inline int
477 int flags, unsigned int verb, unsigned int parm); 391snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid,
478void snd_hda_sequence_write_cache(struct hda_codec *codec, 392 int flags, unsigned int verb, unsigned int parm)
479 const struct hda_verb *seq); 393{
480int snd_hda_codec_update_cache(struct hda_codec *codec, hda_nid_t nid, 394 return snd_hdac_regmap_write(&codec->core, nid, verb, parm);
481 int flags, unsigned int verb, unsigned int parm); 395}
482void snd_hda_codec_resume_cache(struct hda_codec *codec); 396
483/* both for cmd & amp caches */ 397#define snd_hda_codec_update_cache(codec, nid, flags, verb, parm) \
484void snd_hda_codec_flush_cache(struct hda_codec *codec); 398 snd_hda_codec_write_cache(codec, nid, flags, verb, parm)
485 399
486/* the struct for codec->pin_configs */ 400/* the struct for codec->pin_configs */
487struct hda_pincfg { 401struct hda_pincfg {
@@ -512,15 +426,24 @@ void snd_hda_spdif_ctls_assign(struct hda_codec *codec, int idx, hda_nid_t nid);
512/* 426/*
513 * Mixer 427 * Mixer
514 */ 428 */
515int snd_hda_build_controls(struct hda_bus *bus);
516int snd_hda_codec_build_controls(struct hda_codec *codec); 429int snd_hda_codec_build_controls(struct hda_codec *codec);
517 430
518/* 431/*
519 * PCM 432 * PCM
520 */ 433 */
521int snd_hda_build_pcms(struct hda_bus *bus); 434int snd_hda_codec_parse_pcms(struct hda_codec *codec);
522int snd_hda_codec_build_pcms(struct hda_codec *codec); 435int snd_hda_codec_build_pcms(struct hda_codec *codec);
523 436
437__printf(2, 3)
438struct hda_pcm *snd_hda_codec_pcm_new(struct hda_codec *codec,
439 const char *fmt, ...);
440
441static inline void snd_hda_codec_pcm_get(struct hda_pcm *pcm)
442{
443 kref_get(&pcm->kref);
444}
445void snd_hda_codec_pcm_put(struct hda_pcm *pcm);
446
524int snd_hda_codec_prepare(struct hda_codec *codec, 447int snd_hda_codec_prepare(struct hda_codec *codec,
525 struct hda_pcm_stream *hinfo, 448 struct hda_pcm_stream *hinfo,
526 unsigned int stream, 449 unsigned int stream,
@@ -552,20 +475,17 @@ extern const struct snd_pcm_chmap_elem snd_pcm_2_1_chmaps[];
552 * Misc 475 * Misc
553 */ 476 */
554void snd_hda_get_codec_name(struct hda_codec *codec, char *name, int namelen); 477void snd_hda_get_codec_name(struct hda_codec *codec, char *name, int namelen);
555void snd_hda_bus_reboot_notify(struct hda_bus *bus);
556void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg, 478void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg,
557 unsigned int power_state); 479 unsigned int power_state);
558 480
559int snd_hda_lock_devices(struct hda_bus *bus); 481int snd_hda_lock_devices(struct hda_bus *bus);
560void snd_hda_unlock_devices(struct hda_bus *bus); 482void snd_hda_unlock_devices(struct hda_bus *bus);
483void snd_hda_bus_reset(struct hda_bus *bus);
561 484
562/* 485/*
563 * power management 486 * power management
564 */ 487 */
565#ifdef CONFIG_PM 488extern const struct dev_pm_ops hda_codec_driver_pm;
566int snd_hda_suspend(struct hda_bus *bus);
567int snd_hda_resume(struct hda_bus *bus);
568#endif
569 489
570static inline 490static inline
571int hda_call_check_power_status(struct hda_codec *codec, hda_nid_t nid) 491int hda_call_check_power_status(struct hda_codec *codec, hda_nid_t nid)
@@ -587,65 +507,17 @@ const char *snd_hda_get_jack_location(u32 cfg);
587/* 507/*
588 * power saving 508 * power saving
589 */ 509 */
510#define snd_hda_power_up(codec) snd_hdac_power_up(&(codec)->core)
511#define snd_hda_power_up_pm(codec) snd_hdac_power_up_pm(&(codec)->core)
512#define snd_hda_power_down(codec) snd_hdac_power_down(&(codec)->core)
513#define snd_hda_power_down_pm(codec) snd_hdac_power_down_pm(&(codec)->core)
590#ifdef CONFIG_PM 514#ifdef CONFIG_PM
591void snd_hda_power_save(struct hda_codec *codec, int delta, bool d3wait); 515void snd_hda_set_power_save(struct hda_bus *bus, int delay);
592void snd_hda_update_power_acct(struct hda_codec *codec); 516void snd_hda_update_power_acct(struct hda_codec *codec);
593#else 517#else
594static inline void snd_hda_power_save(struct hda_codec *codec, int delta, 518static inline void snd_hda_set_power_save(struct hda_bus *bus, int delay) {}
595 bool d3wait) {}
596#endif 519#endif
597 520
598/**
599 * snd_hda_power_up - Power-up the codec
600 * @codec: HD-audio codec
601 *
602 * Increment the power-up counter and power up the hardware really when
603 * not turned on yet.
604 */
605static inline void snd_hda_power_up(struct hda_codec *codec)
606{
607 snd_hda_power_save(codec, 1, false);
608}
609
610/**
611 * snd_hda_power_up_d3wait - Power-up the codec after waiting for any pending
612 * D3 transition to complete. This differs from snd_hda_power_up() when
613 * power_transition == -1. snd_hda_power_up sees this case as a nop,
614 * snd_hda_power_up_d3wait waits for the D3 transition to complete then powers
615 * back up.
616 * @codec: HD-audio codec
617 *
618 * Cancel any power down operation hapenning on the work queue, then power up.
619 */
620static inline void snd_hda_power_up_d3wait(struct hda_codec *codec)
621{
622 snd_hda_power_save(codec, 1, true);
623}
624
625/**
626 * snd_hda_power_down - Power-down the codec
627 * @codec: HD-audio codec
628 *
629 * Decrement the power-up counter and schedules the power-off work if
630 * the counter rearches to zero.
631 */
632static inline void snd_hda_power_down(struct hda_codec *codec)
633{
634 snd_hda_power_save(codec, -1, false);
635}
636
637/**
638 * snd_hda_power_sync - Synchronize the power-save status
639 * @codec: HD-audio codec
640 *
641 * Synchronize the actual power state with the power account;
642 * called when power_save parameter is changed
643 */
644static inline void snd_hda_power_sync(struct hda_codec *codec)
645{
646 snd_hda_power_save(codec, 0, false);
647}
648
649#ifdef CONFIG_SND_HDA_PATCH_LOADER 521#ifdef CONFIG_SND_HDA_PATCH_LOADER
650/* 522/*
651 * patch firmware 523 * patch firmware
diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c
index 17c2637d842c..26ce990592a0 100644
--- a/sound/pci/hda/hda_controller.c
+++ b/sound/pci/hda/hda_controller.c
@@ -27,10 +27,8 @@
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/pm_runtime.h> 28#include <linux/pm_runtime.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/reboot.h>
31#include <sound/core.h> 30#include <sound/core.h>
32#include <sound/initval.h> 31#include <sound/initval.h>
33#include "hda_priv.h"
34#include "hda_controller.h" 32#include "hda_controller.h"
35 33
36#define CREATE_TRACE_POINTS 34#define CREATE_TRACE_POINTS
@@ -259,11 +257,18 @@ static void azx_timecounter_init(struct snd_pcm_substream *substream,
259 tc->cycle_last = last; 257 tc->cycle_last = last;
260} 258}
261 259
260static inline struct hda_pcm_stream *
261to_hda_pcm_stream(struct snd_pcm_substream *substream)
262{
263 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
264 return &apcm->info->stream[substream->stream];
265}
266
262static u64 azx_adjust_codec_delay(struct snd_pcm_substream *substream, 267static u64 azx_adjust_codec_delay(struct snd_pcm_substream *substream,
263 u64 nsec) 268 u64 nsec)
264{ 269{
265 struct azx_pcm *apcm = snd_pcm_substream_chip(substream); 270 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
266 struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream]; 271 struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream);
267 u64 codec_frames, codec_nsecs; 272 u64 codec_frames, codec_nsecs;
268 273
269 if (!hinfo->ops.get_delay) 274 if (!hinfo->ops.get_delay)
@@ -399,7 +404,7 @@ static int azx_setup_periods(struct azx *chip,
399static int azx_pcm_close(struct snd_pcm_substream *substream) 404static int azx_pcm_close(struct snd_pcm_substream *substream)
400{ 405{
401 struct azx_pcm *apcm = snd_pcm_substream_chip(substream); 406 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
402 struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream]; 407 struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream);
403 struct azx *chip = apcm->chip; 408 struct azx *chip = apcm->chip;
404 struct azx_dev *azx_dev = get_azx_dev(substream); 409 struct azx_dev *azx_dev = get_azx_dev(substream);
405 unsigned long flags; 410 unsigned long flags;
@@ -410,9 +415,11 @@ static int azx_pcm_close(struct snd_pcm_substream *substream)
410 azx_dev->running = 0; 415 azx_dev->running = 0;
411 spin_unlock_irqrestore(&chip->reg_lock, flags); 416 spin_unlock_irqrestore(&chip->reg_lock, flags);
412 azx_release_device(azx_dev); 417 azx_release_device(azx_dev);
413 hinfo->ops.close(hinfo, apcm->codec, substream); 418 if (hinfo->ops.close)
419 hinfo->ops.close(hinfo, apcm->codec, substream);
414 snd_hda_power_down(apcm->codec); 420 snd_hda_power_down(apcm->codec);
415 mutex_unlock(&chip->open_mutex); 421 mutex_unlock(&chip->open_mutex);
422 snd_hda_codec_pcm_put(apcm->info);
416 return 0; 423 return 0;
417} 424}
418 425
@@ -441,7 +448,7 @@ static int azx_pcm_hw_free(struct snd_pcm_substream *substream)
441 struct azx_pcm *apcm = snd_pcm_substream_chip(substream); 448 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
442 struct azx_dev *azx_dev = get_azx_dev(substream); 449 struct azx_dev *azx_dev = get_azx_dev(substream);
443 struct azx *chip = apcm->chip; 450 struct azx *chip = apcm->chip;
444 struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream]; 451 struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream);
445 int err; 452 int err;
446 453
447 /* reset BDL address */ 454 /* reset BDL address */
@@ -468,7 +475,7 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream)
468 struct azx_pcm *apcm = snd_pcm_substream_chip(substream); 475 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
469 struct azx *chip = apcm->chip; 476 struct azx *chip = apcm->chip;
470 struct azx_dev *azx_dev = get_azx_dev(substream); 477 struct azx_dev *azx_dev = get_azx_dev(substream);
471 struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream]; 478 struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream);
472 struct snd_pcm_runtime *runtime = substream->runtime; 479 struct snd_pcm_runtime *runtime = substream->runtime;
473 unsigned int bufsize, period_bytes, format_val, stream_tag; 480 unsigned int bufsize, period_bytes, format_val, stream_tag;
474 int err; 481 int err;
@@ -708,7 +715,7 @@ unsigned int azx_get_position(struct azx *chip,
708 715
709 if (substream->runtime) { 716 if (substream->runtime) {
710 struct azx_pcm *apcm = snd_pcm_substream_chip(substream); 717 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
711 struct hda_pcm_stream *hinfo = apcm->hinfo[stream]; 718 struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream);
712 719
713 if (chip->get_delay[stream]) 720 if (chip->get_delay[stream])
714 delay += chip->get_delay[stream](chip, azx_dev, pos); 721 delay += chip->get_delay[stream](chip, azx_dev, pos);
@@ -732,17 +739,32 @@ static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream)
732 azx_get_position(chip, azx_dev)); 739 azx_get_position(chip, azx_dev));
733} 740}
734 741
735static int azx_get_wallclock_tstamp(struct snd_pcm_substream *substream, 742static int azx_get_time_info(struct snd_pcm_substream *substream,
736 struct timespec *ts) 743 struct timespec *system_ts, struct timespec *audio_ts,
744 struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
745 struct snd_pcm_audio_tstamp_report *audio_tstamp_report)
737{ 746{
738 struct azx_dev *azx_dev = get_azx_dev(substream); 747 struct azx_dev *azx_dev = get_azx_dev(substream);
739 u64 nsec; 748 u64 nsec;
740 749
741 nsec = timecounter_read(&azx_dev->azx_tc); 750 if ((substream->runtime->hw.info & SNDRV_PCM_INFO_HAS_LINK_ATIME) &&
742 nsec = div_u64(nsec, 3); /* can be optimized */ 751 (audio_tstamp_config->type_requested == SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK)) {
743 nsec = azx_adjust_codec_delay(substream, nsec); 752
753 snd_pcm_gettime(substream->runtime, system_ts);
744 754
745 *ts = ns_to_timespec(nsec); 755 nsec = timecounter_read(&azx_dev->azx_tc);
756 nsec = div_u64(nsec, 3); /* can be optimized */
757 if (audio_tstamp_config->report_delay)
758 nsec = azx_adjust_codec_delay(substream, nsec);
759
760 *audio_ts = ns_to_timespec(nsec);
761
762 audio_tstamp_report->actual_type = SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK;
763 audio_tstamp_report->accuracy_report = 1; /* rest of structure is valid */
764 audio_tstamp_report->accuracy = 42; /* 24 MHz WallClock == 42ns resolution */
765
766 } else
767 audio_tstamp_report->actual_type = SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT;
746 768
747 return 0; 769 return 0;
748} 770}
@@ -756,7 +778,8 @@ static struct snd_pcm_hardware azx_pcm_hw = {
756 /* SNDRV_PCM_INFO_RESUME |*/ 778 /* SNDRV_PCM_INFO_RESUME |*/
757 SNDRV_PCM_INFO_PAUSE | 779 SNDRV_PCM_INFO_PAUSE |
758 SNDRV_PCM_INFO_SYNC_START | 780 SNDRV_PCM_INFO_SYNC_START |
759 SNDRV_PCM_INFO_HAS_WALL_CLOCK | 781 SNDRV_PCM_INFO_HAS_WALL_CLOCK | /* legacy */
782 SNDRV_PCM_INFO_HAS_LINK_ATIME |
760 SNDRV_PCM_INFO_NO_PERIOD_WAKEUP), 783 SNDRV_PCM_INFO_NO_PERIOD_WAKEUP),
761 .formats = SNDRV_PCM_FMTBIT_S16_LE, 784 .formats = SNDRV_PCM_FMTBIT_S16_LE,
762 .rates = SNDRV_PCM_RATE_48000, 785 .rates = SNDRV_PCM_RATE_48000,
@@ -775,7 +798,7 @@ static struct snd_pcm_hardware azx_pcm_hw = {
775static int azx_pcm_open(struct snd_pcm_substream *substream) 798static int azx_pcm_open(struct snd_pcm_substream *substream)
776{ 799{
777 struct azx_pcm *apcm = snd_pcm_substream_chip(substream); 800 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
778 struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream]; 801 struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream);
779 struct azx *chip = apcm->chip; 802 struct azx *chip = apcm->chip;
780 struct azx_dev *azx_dev; 803 struct azx_dev *azx_dev;
781 struct snd_pcm_runtime *runtime = substream->runtime; 804 struct snd_pcm_runtime *runtime = substream->runtime;
@@ -783,11 +806,12 @@ static int azx_pcm_open(struct snd_pcm_substream *substream)
783 int err; 806 int err;
784 int buff_step; 807 int buff_step;
785 808
809 snd_hda_codec_pcm_get(apcm->info);
786 mutex_lock(&chip->open_mutex); 810 mutex_lock(&chip->open_mutex);
787 azx_dev = azx_assign_device(chip, substream); 811 azx_dev = azx_assign_device(chip, substream);
788 if (azx_dev == NULL) { 812 if (azx_dev == NULL) {
789 mutex_unlock(&chip->open_mutex); 813 err = -EBUSY;
790 return -EBUSY; 814 goto unlock;
791 } 815 }
792 runtime->hw = azx_pcm_hw; 816 runtime->hw = azx_pcm_hw;
793 runtime->hw.channels_min = hinfo->channels_min; 817 runtime->hw.channels_min = hinfo->channels_min;
@@ -821,13 +845,14 @@ static int azx_pcm_open(struct snd_pcm_substream *substream)
821 buff_step); 845 buff_step);
822 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 846 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
823 buff_step); 847 buff_step);
824 snd_hda_power_up_d3wait(apcm->codec); 848 snd_hda_power_up(apcm->codec);
825 err = hinfo->ops.open(hinfo, apcm->codec, substream); 849 if (hinfo->ops.open)
850 err = hinfo->ops.open(hinfo, apcm->codec, substream);
851 else
852 err = -ENODEV;
826 if (err < 0) { 853 if (err < 0) {
827 azx_release_device(azx_dev); 854 azx_release_device(azx_dev);
828 snd_hda_power_down(apcm->codec); 855 goto powerdown;
829 mutex_unlock(&chip->open_mutex);
830 return err;
831 } 856 }
832 snd_pcm_limit_hw_rates(runtime); 857 snd_pcm_limit_hw_rates(runtime);
833 /* sanity check */ 858 /* sanity check */
@@ -836,16 +861,18 @@ static int azx_pcm_open(struct snd_pcm_substream *substream)
836 snd_BUG_ON(!runtime->hw.formats) || 861 snd_BUG_ON(!runtime->hw.formats) ||
837 snd_BUG_ON(!runtime->hw.rates)) { 862 snd_BUG_ON(!runtime->hw.rates)) {
838 azx_release_device(azx_dev); 863 azx_release_device(azx_dev);
839 hinfo->ops.close(hinfo, apcm->codec, substream); 864 if (hinfo->ops.close)
840 snd_hda_power_down(apcm->codec); 865 hinfo->ops.close(hinfo, apcm->codec, substream);
841 mutex_unlock(&chip->open_mutex); 866 err = -EINVAL;
842 return -EINVAL; 867 goto powerdown;
843 } 868 }
844 869
845 /* disable WALLCLOCK timestamps for capture streams 870 /* disable LINK_ATIME timestamps for capture streams
846 until we figure out how to handle digital inputs */ 871 until we figure out how to handle digital inputs */
847 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) 872 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
848 runtime->hw.info &= ~SNDRV_PCM_INFO_HAS_WALL_CLOCK; 873 runtime->hw.info &= ~SNDRV_PCM_INFO_HAS_WALL_CLOCK; /* legacy */
874 runtime->hw.info &= ~SNDRV_PCM_INFO_HAS_LINK_ATIME;
875 }
849 876
850 spin_lock_irqsave(&chip->reg_lock, flags); 877 spin_lock_irqsave(&chip->reg_lock, flags);
851 azx_dev->substream = substream; 878 azx_dev->substream = substream;
@@ -856,6 +883,13 @@ static int azx_pcm_open(struct snd_pcm_substream *substream)
856 snd_pcm_set_sync(substream); 883 snd_pcm_set_sync(substream);
857 mutex_unlock(&chip->open_mutex); 884 mutex_unlock(&chip->open_mutex);
858 return 0; 885 return 0;
886
887 powerdown:
888 snd_hda_power_down(apcm->codec);
889 unlock:
890 mutex_unlock(&chip->open_mutex);
891 snd_hda_codec_pcm_put(apcm->info);
892 return err;
859} 893}
860 894
861static int azx_pcm_mmap(struct snd_pcm_substream *substream, 895static int azx_pcm_mmap(struct snd_pcm_substream *substream,
@@ -877,7 +911,7 @@ static struct snd_pcm_ops azx_pcm_ops = {
877 .prepare = azx_pcm_prepare, 911 .prepare = azx_pcm_prepare,
878 .trigger = azx_pcm_trigger, 912 .trigger = azx_pcm_trigger,
879 .pointer = azx_pcm_pointer, 913 .pointer = azx_pcm_pointer,
880 .wall_clock = azx_get_wallclock_tstamp, 914 .get_time_info = azx_get_time_info,
881 .mmap = azx_pcm_mmap, 915 .mmap = azx_pcm_mmap,
882 .page = snd_pcm_sgbuf_ops_page, 916 .page = snd_pcm_sgbuf_ops_page,
883}; 917};
@@ -887,6 +921,7 @@ static void azx_pcm_free(struct snd_pcm *pcm)
887 struct azx_pcm *apcm = pcm->private_data; 921 struct azx_pcm *apcm = pcm->private_data;
888 if (apcm) { 922 if (apcm) {
889 list_del(&apcm->list); 923 list_del(&apcm->list);
924 apcm->info->pcm = NULL;
890 kfree(apcm); 925 kfree(apcm);
891 } 926 }
892} 927}
@@ -923,6 +958,7 @@ static int azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec,
923 apcm->chip = chip; 958 apcm->chip = chip;
924 apcm->pcm = pcm; 959 apcm->pcm = pcm;
925 apcm->codec = codec; 960 apcm->codec = codec;
961 apcm->info = cpcm;
926 pcm->private_data = apcm; 962 pcm->private_data = apcm;
927 pcm->private_free = azx_pcm_free; 963 pcm->private_free = azx_pcm_free;
928 if (cpcm->pcm_type == HDA_PCM_TYPE_MODEM) 964 if (cpcm->pcm_type == HDA_PCM_TYPE_MODEM)
@@ -930,7 +966,6 @@ static int azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec,
930 list_add_tail(&apcm->list, &chip->pcm_list); 966 list_add_tail(&apcm->list, &chip->pcm_list);
931 cpcm->pcm = pcm; 967 cpcm->pcm = pcm;
932 for (s = 0; s < 2; s++) { 968 for (s = 0; s < 2; s++) {
933 apcm->hinfo[s] = &cpcm->stream[s];
934 if (cpcm->stream[s].substreams) 969 if (cpcm->stream[s].substreams)
935 snd_pcm_set_ops(pcm, s, &azx_pcm_ops); 970 snd_pcm_set_ops(pcm, s, &azx_pcm_ops);
936 } 971 }
@@ -941,9 +976,6 @@ static int azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec,
941 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, 976 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
942 chip->card->dev, 977 chip->card->dev,
943 size, MAX_PREALLOC_SIZE); 978 size, MAX_PREALLOC_SIZE);
944 /* link to codec */
945 for (s = 0; s < 2; s++)
946 pcm->streams[s].dev.parent = &codec->dev;
947 return 0; 979 return 0;
948} 980}
949 981
@@ -952,14 +984,9 @@ static int azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec,
952 */ 984 */
953static int azx_alloc_cmd_io(struct azx *chip) 985static int azx_alloc_cmd_io(struct azx *chip)
954{ 986{
955 int err;
956
957 /* single page (at least 4096 bytes) must suffice for both ringbuffes */ 987 /* single page (at least 4096 bytes) must suffice for both ringbuffes */
958 err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV, 988 return chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV,
959 PAGE_SIZE, &chip->rb); 989 PAGE_SIZE, &chip->rb);
960 if (err < 0)
961 dev_err(chip->card->dev, "cannot allocate CORB/RIRB\n");
962 return err;
963} 990}
964 991
965static void azx_init_cmd_io(struct azx *chip) 992static void azx_init_cmd_io(struct azx *chip)
@@ -1445,7 +1472,6 @@ static void azx_load_dsp_cleanup(struct hda_bus *bus,
1445int azx_alloc_stream_pages(struct azx *chip) 1472int azx_alloc_stream_pages(struct azx *chip)
1446{ 1473{
1447 int i, err; 1474 int i, err;
1448 struct snd_card *card = chip->card;
1449 1475
1450 for (i = 0; i < chip->num_streams; i++) { 1476 for (i = 0; i < chip->num_streams; i++) {
1451 dsp_lock_init(&chip->azx_dev[i]); 1477 dsp_lock_init(&chip->azx_dev[i]);
@@ -1453,18 +1479,14 @@ int azx_alloc_stream_pages(struct azx *chip)
1453 err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV, 1479 err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV,
1454 BDL_SIZE, 1480 BDL_SIZE,
1455 &chip->azx_dev[i].bdl); 1481 &chip->azx_dev[i].bdl);
1456 if (err < 0) { 1482 if (err < 0)
1457 dev_err(card->dev, "cannot allocate BDL\n");
1458 return -ENOMEM; 1483 return -ENOMEM;
1459 }
1460 } 1484 }
1461 /* allocate memory for the position buffer */ 1485 /* allocate memory for the position buffer */
1462 err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV, 1486 err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV,
1463 chip->num_streams * 8, &chip->posbuf); 1487 chip->num_streams * 8, &chip->posbuf);
1464 if (err < 0) { 1488 if (err < 0)
1465 dev_err(card->dev, "cannot allocate posbuf\n");
1466 return -ENOMEM; 1489 return -ENOMEM;
1467 }
1468 1490
1469 /* allocate CORB/RIRB */ 1491 /* allocate CORB/RIRB */
1470 err = azx_alloc_cmd_io(chip); 1492 err = azx_alloc_cmd_io(chip);
@@ -1676,7 +1698,7 @@ irqreturn_t azx_interrupt(int irq, void *dev_id)
1676 int i; 1698 int i;
1677 1699
1678#ifdef CONFIG_PM 1700#ifdef CONFIG_PM
1679 if (chip->driver_caps & AZX_DCAPS_PM_RUNTIME) 1701 if (azx_has_pm_runtime(chip))
1680 if (!pm_runtime_active(chip->card->dev)) 1702 if (!pm_runtime_active(chip->card->dev))
1681 return IRQ_NONE; 1703 return IRQ_NONE;
1682#endif 1704#endif
@@ -1742,12 +1764,12 @@ static int probe_codec(struct azx *chip, int addr)
1742 (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID; 1764 (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID;
1743 unsigned int res; 1765 unsigned int res;
1744 1766
1745 mutex_lock(&chip->bus->cmd_mutex); 1767 mutex_lock(&chip->bus->core.cmd_mutex);
1746 chip->probing = 1; 1768 chip->probing = 1;
1747 azx_send_cmd(chip->bus, cmd); 1769 azx_send_cmd(chip->bus, cmd);
1748 res = azx_get_response(chip->bus, addr); 1770 res = azx_get_response(chip->bus, addr);
1749 chip->probing = 0; 1771 chip->probing = 0;
1750 mutex_unlock(&chip->bus->cmd_mutex); 1772 mutex_unlock(&chip->bus->core.cmd_mutex);
1751 if (res == -1) 1773 if (res == -1)
1752 return -EIO; 1774 return -EIO;
1753 dev_dbg(chip->card->dev, "codec #%d probed OK\n", addr); 1775 dev_dbg(chip->card->dev, "codec #%d probed OK\n", addr);
@@ -1761,34 +1783,11 @@ static void azx_bus_reset(struct hda_bus *bus)
1761 bus->in_reset = 1; 1783 bus->in_reset = 1;
1762 azx_stop_chip(chip); 1784 azx_stop_chip(chip);
1763 azx_init_chip(chip, true); 1785 azx_init_chip(chip, true);
1764#ifdef CONFIG_PM 1786 if (chip->initialized)
1765 if (chip->initialized) { 1787 snd_hda_bus_reset(chip->bus);
1766 struct azx_pcm *p;
1767 list_for_each_entry(p, &chip->pcm_list, list)
1768 snd_pcm_suspend_all(p->pcm);
1769 snd_hda_suspend(chip->bus);
1770 snd_hda_resume(chip->bus);
1771 }
1772#endif
1773 bus->in_reset = 0; 1788 bus->in_reset = 0;
1774} 1789}
1775 1790
1776#ifdef CONFIG_PM
1777/* power-up/down the controller */
1778static void azx_power_notify(struct hda_bus *bus, bool power_up)
1779{
1780 struct azx *chip = bus->private_data;
1781
1782 if (!(chip->driver_caps & AZX_DCAPS_PM_RUNTIME))
1783 return;
1784
1785 if (power_up)
1786 pm_runtime_get_sync(chip->card->dev);
1787 else
1788 pm_runtime_put_sync(chip->card->dev);
1789}
1790#endif
1791
1792static int get_jackpoll_interval(struct azx *chip) 1791static int get_jackpoll_interval(struct azx *chip)
1793{ 1792{
1794 int i; 1793 int i;
@@ -1810,41 +1809,59 @@ static int get_jackpoll_interval(struct azx *chip)
1810 return j; 1809 return j;
1811} 1810}
1812 1811
1813/* Codec initialization */ 1812static struct hda_bus_ops bus_ops = {
1814int azx_codec_create(struct azx *chip, const char *model, 1813 .command = azx_send_cmd,
1815 unsigned int max_slots, 1814 .get_response = azx_get_response,
1816 int *power_save_to) 1815 .attach_pcm = azx_attach_pcm_stream,
1817{ 1816 .bus_reset = azx_bus_reset,
1818 struct hda_bus_template bus_temp;
1819 int c, codecs, err;
1820
1821 memset(&bus_temp, 0, sizeof(bus_temp));
1822 bus_temp.private_data = chip;
1823 bus_temp.modelname = model;
1824 bus_temp.pci = chip->pci;
1825 bus_temp.ops.command = azx_send_cmd;
1826 bus_temp.ops.get_response = azx_get_response;
1827 bus_temp.ops.attach_pcm = azx_attach_pcm_stream;
1828 bus_temp.ops.bus_reset = azx_bus_reset;
1829#ifdef CONFIG_PM
1830 bus_temp.power_save = power_save_to;
1831 bus_temp.ops.pm_notify = azx_power_notify;
1832#endif
1833#ifdef CONFIG_SND_HDA_DSP_LOADER 1817#ifdef CONFIG_SND_HDA_DSP_LOADER
1834 bus_temp.ops.load_dsp_prepare = azx_load_dsp_prepare; 1818 .load_dsp_prepare = azx_load_dsp_prepare,
1835 bus_temp.ops.load_dsp_trigger = azx_load_dsp_trigger; 1819 .load_dsp_trigger = azx_load_dsp_trigger,
1836 bus_temp.ops.load_dsp_cleanup = azx_load_dsp_cleanup; 1820 .load_dsp_cleanup = azx_load_dsp_cleanup,
1837#endif 1821#endif
1822};
1823
1824/* HD-audio bus initialization */
1825int azx_bus_create(struct azx *chip, const char *model)
1826{
1827 struct hda_bus *bus;
1828 int err;
1838 1829
1839 err = snd_hda_bus_new(chip->card, &bus_temp, &chip->bus); 1830 err = snd_hda_bus_new(chip->card, &bus);
1840 if (err < 0) 1831 if (err < 0)
1841 return err; 1832 return err;
1842 1833
1834 chip->bus = bus;
1835 bus->private_data = chip;
1836 bus->pci = chip->pci;
1837 bus->modelname = model;
1838 bus->ops = bus_ops;
1839
1843 if (chip->driver_caps & AZX_DCAPS_RIRB_DELAY) { 1840 if (chip->driver_caps & AZX_DCAPS_RIRB_DELAY) {
1844 dev_dbg(chip->card->dev, "Enable delay in RIRB handling\n"); 1841 dev_dbg(chip->card->dev, "Enable delay in RIRB handling\n");
1845 chip->bus->needs_damn_long_delay = 1; 1842 bus->needs_damn_long_delay = 1;
1843 }
1844
1845 /* AMD chipsets often cause the communication stalls upon certain
1846 * sequence like the pin-detection. It seems that forcing the synced
1847 * access works around the stall. Grrr...
1848 */
1849 if (chip->driver_caps & AZX_DCAPS_SYNC_WRITE) {
1850 dev_dbg(chip->card->dev, "Enable sync_write for stable communication\n");
1851 bus->core.sync_write = 1;
1852 bus->allow_bus_reset = 1;
1846 } 1853 }
1847 1854
1855 return 0;
1856}
1857EXPORT_SYMBOL_GPL(azx_bus_create);
1858
1859/* Probe codecs */
1860int azx_probe_codecs(struct azx *chip, unsigned int max_slots)
1861{
1862 struct hda_bus *bus = chip->bus;
1863 int c, codecs, err;
1864
1848 codecs = 0; 1865 codecs = 0;
1849 if (!max_slots) 1866 if (!max_slots)
1850 max_slots = AZX_DEFAULT_CODECS; 1867 max_slots = AZX_DEFAULT_CODECS;
@@ -1872,21 +1889,11 @@ int azx_codec_create(struct azx *chip, const char *model,
1872 } 1889 }
1873 } 1890 }
1874 1891
1875 /* AMD chipsets often cause the communication stalls upon certain
1876 * sequence like the pin-detection. It seems that forcing the synced
1877 * access works around the stall. Grrr...
1878 */
1879 if (chip->driver_caps & AZX_DCAPS_SYNC_WRITE) {
1880 dev_dbg(chip->card->dev, "Enable sync_write for stable communication\n");
1881 chip->bus->sync_write = 1;
1882 chip->bus->allow_bus_reset = 1;
1883 }
1884
1885 /* Then create codec instances */ 1892 /* Then create codec instances */
1886 for (c = 0; c < max_slots; c++) { 1893 for (c = 0; c < max_slots; c++) {
1887 if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) { 1894 if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) {
1888 struct hda_codec *codec; 1895 struct hda_codec *codec;
1889 err = snd_hda_codec_new(chip->bus, c, &codec); 1896 err = snd_hda_codec_new(bus, bus->card, c, &codec);
1890 if (err < 0) 1897 if (err < 0)
1891 continue; 1898 continue;
1892 codec->jackpoll_interval = get_jackpoll_interval(chip); 1899 codec->jackpoll_interval = get_jackpoll_interval(chip);
@@ -1900,26 +1907,19 @@ int azx_codec_create(struct azx *chip, const char *model,
1900 } 1907 }
1901 return 0; 1908 return 0;
1902} 1909}
1903EXPORT_SYMBOL_GPL(azx_codec_create); 1910EXPORT_SYMBOL_GPL(azx_probe_codecs);
1904 1911
1905/* configure each codec instance */ 1912/* configure each codec instance */
1906int azx_codec_configure(struct azx *chip) 1913int azx_codec_configure(struct azx *chip)
1907{ 1914{
1908 struct hda_codec *codec; 1915 struct hda_codec *codec;
1909 list_for_each_entry(codec, &chip->bus->codec_list, list) { 1916 list_for_each_codec(codec, chip->bus) {
1910 snd_hda_codec_configure(codec); 1917 snd_hda_codec_configure(codec);
1911 } 1918 }
1912 return 0; 1919 return 0;
1913} 1920}
1914EXPORT_SYMBOL_GPL(azx_codec_configure); 1921EXPORT_SYMBOL_GPL(azx_codec_configure);
1915 1922
1916/* mixer creation - all stuff is implemented in hda module */
1917int azx_mixer_create(struct azx *chip)
1918{
1919 return snd_hda_build_controls(chip->bus);
1920}
1921EXPORT_SYMBOL_GPL(azx_mixer_create);
1922
1923 1923
1924static bool is_input_stream(struct azx *chip, unsigned char index) 1924static bool is_input_stream(struct azx *chip, unsigned char index)
1925{ 1925{
@@ -1966,30 +1966,5 @@ int azx_init_stream(struct azx *chip)
1966} 1966}
1967EXPORT_SYMBOL_GPL(azx_init_stream); 1967EXPORT_SYMBOL_GPL(azx_init_stream);
1968 1968
1969/*
1970 * reboot notifier for hang-up problem at power-down
1971 */
1972static int azx_halt(struct notifier_block *nb, unsigned long event, void *buf)
1973{
1974 struct azx *chip = container_of(nb, struct azx, reboot_notifier);
1975 snd_hda_bus_reboot_notify(chip->bus);
1976 azx_stop_chip(chip);
1977 return NOTIFY_OK;
1978}
1979
1980void azx_notifier_register(struct azx *chip)
1981{
1982 chip->reboot_notifier.notifier_call = azx_halt;
1983 register_reboot_notifier(&chip->reboot_notifier);
1984}
1985EXPORT_SYMBOL_GPL(azx_notifier_register);
1986
1987void azx_notifier_unregister(struct azx *chip)
1988{
1989 if (chip->reboot_notifier.notifier_call)
1990 unregister_reboot_notifier(&chip->reboot_notifier);
1991}
1992EXPORT_SYMBOL_GPL(azx_notifier_unregister);
1993
1994MODULE_LICENSE("GPL"); 1969MODULE_LICENSE("GPL");
1995MODULE_DESCRIPTION("Common HDA driver functions"); 1970MODULE_DESCRIPTION("Common HDA driver functions");
diff --git a/sound/pci/hda/hda_controller.h b/sound/pci/hda/hda_controller.h
index c90d10fd4d8f..0efdb094d21c 100644
--- a/sound/pci/hda/hda_controller.h
+++ b/sound/pci/hda/hda_controller.h
@@ -15,10 +15,396 @@
15#ifndef __SOUND_HDA_CONTROLLER_H 15#ifndef __SOUND_HDA_CONTROLLER_H
16#define __SOUND_HDA_CONTROLLER_H 16#define __SOUND_HDA_CONTROLLER_H
17 17
18#include <linux/timecounter.h>
19#include <linux/interrupt.h>
18#include <sound/core.h> 20#include <sound/core.h>
21#include <sound/pcm.h>
19#include <sound/initval.h> 22#include <sound/initval.h>
20#include "hda_codec.h" 23#include "hda_codec.h"
21#include "hda_priv.h" 24
25/*
26 * registers
27 */
28#define AZX_REG_GCAP 0x00
29#define AZX_GCAP_64OK (1 << 0) /* 64bit address support */
30#define AZX_GCAP_NSDO (3 << 1) /* # of serial data out signals */
31#define AZX_GCAP_BSS (31 << 3) /* # of bidirectional streams */
32#define AZX_GCAP_ISS (15 << 8) /* # of input streams */
33#define AZX_GCAP_OSS (15 << 12) /* # of output streams */
34#define AZX_REG_VMIN 0x02
35#define AZX_REG_VMAJ 0x03
36#define AZX_REG_OUTPAY 0x04
37#define AZX_REG_INPAY 0x06
38#define AZX_REG_GCTL 0x08
39#define AZX_GCTL_RESET (1 << 0) /* controller reset */
40#define AZX_GCTL_FCNTRL (1 << 1) /* flush control */
41#define AZX_GCTL_UNSOL (1 << 8) /* accept unsol. response enable */
42#define AZX_REG_WAKEEN 0x0c
43#define AZX_REG_STATESTS 0x0e
44#define AZX_REG_GSTS 0x10
45#define AZX_GSTS_FSTS (1 << 1) /* flush status */
46#define AZX_REG_INTCTL 0x20
47#define AZX_REG_INTSTS 0x24
48#define AZX_REG_WALLCLK 0x30 /* 24Mhz source */
49#define AZX_REG_OLD_SSYNC 0x34 /* SSYNC for old ICH */
50#define AZX_REG_SSYNC 0x38
51#define AZX_REG_CORBLBASE 0x40
52#define AZX_REG_CORBUBASE 0x44
53#define AZX_REG_CORBWP 0x48
54#define AZX_REG_CORBRP 0x4a
55#define AZX_CORBRP_RST (1 << 15) /* read pointer reset */
56#define AZX_REG_CORBCTL 0x4c
57#define AZX_CORBCTL_RUN (1 << 1) /* enable DMA */
58#define AZX_CORBCTL_CMEIE (1 << 0) /* enable memory error irq */
59#define AZX_REG_CORBSTS 0x4d
60#define AZX_CORBSTS_CMEI (1 << 0) /* memory error indication */
61#define AZX_REG_CORBSIZE 0x4e
62
63#define AZX_REG_RIRBLBASE 0x50
64#define AZX_REG_RIRBUBASE 0x54
65#define AZX_REG_RIRBWP 0x58
66#define AZX_RIRBWP_RST (1 << 15) /* write pointer reset */
67#define AZX_REG_RINTCNT 0x5a
68#define AZX_REG_RIRBCTL 0x5c
69#define AZX_RBCTL_IRQ_EN (1 << 0) /* enable IRQ */
70#define AZX_RBCTL_DMA_EN (1 << 1) /* enable DMA */
71#define AZX_RBCTL_OVERRUN_EN (1 << 2) /* enable overrun irq */
72#define AZX_REG_RIRBSTS 0x5d
73#define AZX_RBSTS_IRQ (1 << 0) /* response irq */
74#define AZX_RBSTS_OVERRUN (1 << 2) /* overrun irq */
75#define AZX_REG_RIRBSIZE 0x5e
76
77#define AZX_REG_IC 0x60
78#define AZX_REG_IR 0x64
79#define AZX_REG_IRS 0x68
80#define AZX_IRS_VALID (1<<1)
81#define AZX_IRS_BUSY (1<<0)
82
83#define AZX_REG_DPLBASE 0x70
84#define AZX_REG_DPUBASE 0x74
85#define AZX_DPLBASE_ENABLE 0x1 /* Enable position buffer */
86
87/* SD offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */
88enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
89
90/* stream register offsets from stream base */
91#define AZX_REG_SD_CTL 0x00
92#define AZX_REG_SD_STS 0x03
93#define AZX_REG_SD_LPIB 0x04
94#define AZX_REG_SD_CBL 0x08
95#define AZX_REG_SD_LVI 0x0c
96#define AZX_REG_SD_FIFOW 0x0e
97#define AZX_REG_SD_FIFOSIZE 0x10
98#define AZX_REG_SD_FORMAT 0x12
99#define AZX_REG_SD_BDLPL 0x18
100#define AZX_REG_SD_BDLPU 0x1c
101
102/* PCI space */
103#define AZX_PCIREG_TCSEL 0x44
104
105/*
106 * other constants
107 */
108
109/* max number of fragments - we may use more if allocating more pages for BDL */
110#define BDL_SIZE 4096
111#define AZX_MAX_BDL_ENTRIES (BDL_SIZE / 16)
112#define AZX_MAX_FRAG 32
113/* max buffer size - no h/w limit, you can increase as you like */
114#define AZX_MAX_BUF_SIZE (1024*1024*1024)
115
116/* RIRB int mask: overrun[2], response[0] */
117#define RIRB_INT_RESPONSE 0x01
118#define RIRB_INT_OVERRUN 0x04
119#define RIRB_INT_MASK 0x05
120
121/* STATESTS int mask: S3,SD2,SD1,SD0 */
122#define AZX_MAX_CODECS 8
123#define AZX_DEFAULT_CODECS 4
124#define STATESTS_INT_MASK ((1 << AZX_MAX_CODECS) - 1)
125
126/* SD_CTL bits */
127#define SD_CTL_STREAM_RESET 0x01 /* stream reset bit */
128#define SD_CTL_DMA_START 0x02 /* stream DMA start bit */
129#define SD_CTL_STRIPE (3 << 16) /* stripe control */
130#define SD_CTL_TRAFFIC_PRIO (1 << 18) /* traffic priority */
131#define SD_CTL_DIR (1 << 19) /* bi-directional stream */
132#define SD_CTL_STREAM_TAG_MASK (0xf << 20)
133#define SD_CTL_STREAM_TAG_SHIFT 20
134
135/* SD_CTL and SD_STS */
136#define SD_INT_DESC_ERR 0x10 /* descriptor error interrupt */
137#define SD_INT_FIFO_ERR 0x08 /* FIFO error interrupt */
138#define SD_INT_COMPLETE 0x04 /* completion interrupt */
139#define SD_INT_MASK (SD_INT_DESC_ERR|SD_INT_FIFO_ERR|\
140 SD_INT_COMPLETE)
141
142/* SD_STS */
143#define SD_STS_FIFO_READY 0x20 /* FIFO ready */
144
145/* INTCTL and INTSTS */
146#define AZX_INT_ALL_STREAM 0xff /* all stream interrupts */
147#define AZX_INT_CTRL_EN 0x40000000 /* controller interrupt enable bit */
148#define AZX_INT_GLOBAL_EN 0x80000000 /* global interrupt enable bit */
149
150/* below are so far hardcoded - should read registers in future */
151#define AZX_MAX_CORB_ENTRIES 256
152#define AZX_MAX_RIRB_ENTRIES 256
153
154/* driver quirks (capabilities) */
155/* bits 0-7 are used for indicating driver type */
156#define AZX_DCAPS_NO_TCSEL (1 << 8) /* No Intel TCSEL bit */
157#define AZX_DCAPS_NO_MSI (1 << 9) /* No MSI support */
158#define AZX_DCAPS_SNOOP_MASK (3 << 10) /* snoop type mask */
159#define AZX_DCAPS_SNOOP_OFF (1 << 12) /* snoop default off */
160#define AZX_DCAPS_RIRB_DELAY (1 << 13) /* Long delay in read loop */
161#define AZX_DCAPS_RIRB_PRE_DELAY (1 << 14) /* Put a delay before read */
162#define AZX_DCAPS_CTX_WORKAROUND (1 << 15) /* X-Fi workaround */
163#define AZX_DCAPS_POSFIX_LPIB (1 << 16) /* Use LPIB as default */
164#define AZX_DCAPS_POSFIX_VIA (1 << 17) /* Use VIACOMBO as default */
165#define AZX_DCAPS_NO_64BIT (1 << 18) /* No 64bit address */
166#define AZX_DCAPS_SYNC_WRITE (1 << 19) /* sync each cmd write */
167#define AZX_DCAPS_OLD_SSYNC (1 << 20) /* Old SSYNC reg for ICH */
168#define AZX_DCAPS_NO_ALIGN_BUFSIZE (1 << 21) /* no buffer size alignment */
169/* 22 unused */
170#define AZX_DCAPS_4K_BDLE_BOUNDARY (1 << 23) /* BDLE in 4k boundary */
171#define AZX_DCAPS_REVERSE_ASSIGN (1 << 24) /* Assign devices in reverse order */
172#define AZX_DCAPS_COUNT_LPIB_DELAY (1 << 25) /* Take LPIB as delay */
173#define AZX_DCAPS_PM_RUNTIME (1 << 26) /* runtime PM support */
174#define AZX_DCAPS_I915_POWERWELL (1 << 27) /* HSW i915 powerwell support */
175#define AZX_DCAPS_CORBRP_SELF_CLEAR (1 << 28) /* CORBRP clears itself after reset */
176#define AZX_DCAPS_NO_MSI64 (1 << 29) /* Stick to 32-bit MSIs */
177#define AZX_DCAPS_SEPARATE_STREAM_TAG (1 << 30) /* capture and playback use separate stream tag */
178
179enum {
180 AZX_SNOOP_TYPE_NONE,
181 AZX_SNOOP_TYPE_SCH,
182 AZX_SNOOP_TYPE_ATI,
183 AZX_SNOOP_TYPE_NVIDIA,
184};
185
186/* HD Audio class code */
187#define PCI_CLASS_MULTIMEDIA_HD_AUDIO 0x0403
188
189struct azx_dev {
190 struct snd_dma_buffer bdl; /* BDL buffer */
191 u32 *posbuf; /* position buffer pointer */
192
193 unsigned int bufsize; /* size of the play buffer in bytes */
194 unsigned int period_bytes; /* size of the period in bytes */
195 unsigned int frags; /* number for period in the play buffer */
196 unsigned int fifo_size; /* FIFO size */
197 unsigned long start_wallclk; /* start + minimum wallclk */
198 unsigned long period_wallclk; /* wallclk for period */
199
200 void __iomem *sd_addr; /* stream descriptor pointer */
201
202 u32 sd_int_sta_mask; /* stream int status mask */
203
204 /* pcm support */
205 struct snd_pcm_substream *substream; /* assigned substream,
206 * set in PCM open
207 */
208 unsigned int format_val; /* format value to be set in the
209 * controller and the codec
210 */
211 unsigned char stream_tag; /* assigned stream */
212 unsigned char index; /* stream index */
213 int assigned_key; /* last device# key assigned to */
214
215 unsigned int opened:1;
216 unsigned int running:1;
217 unsigned int irq_pending:1;
218 unsigned int prepared:1;
219 unsigned int locked:1;
220 /*
221 * For VIA:
222 * A flag to ensure DMA position is 0
223 * when link position is not greater than FIFO size
224 */
225 unsigned int insufficient:1;
226 unsigned int wc_marked:1;
227 unsigned int no_period_wakeup:1;
228
229 struct timecounter azx_tc;
230 struct cyclecounter azx_cc;
231
232 int delay_negative_threshold;
233
234#ifdef CONFIG_SND_HDA_DSP_LOADER
235 /* Allows dsp load to have sole access to the playback stream. */
236 struct mutex dsp_mutex;
237#endif
238};
239
240/* CORB/RIRB */
241struct azx_rb {
242 u32 *buf; /* CORB/RIRB buffer
243 * Each CORB entry is 4byte, RIRB is 8byte
244 */
245 dma_addr_t addr; /* physical address of CORB/RIRB buffer */
246 /* for RIRB */
247 unsigned short rp, wp; /* read/write pointers */
248 int cmds[AZX_MAX_CODECS]; /* number of pending requests */
249 u32 res[AZX_MAX_CODECS]; /* last read value */
250};
251
252struct azx;
253
254/* Functions to read/write to hda registers. */
255struct hda_controller_ops {
256 /* Register Access */
257 void (*reg_writel)(u32 value, u32 __iomem *addr);
258 u32 (*reg_readl)(u32 __iomem *addr);
259 void (*reg_writew)(u16 value, u16 __iomem *addr);
260 u16 (*reg_readw)(u16 __iomem *addr);
261 void (*reg_writeb)(u8 value, u8 __iomem *addr);
262 u8 (*reg_readb)(u8 __iomem *addr);
263 /* Disable msi if supported, PCI only */
264 int (*disable_msi_reset_irq)(struct azx *);
265 /* Allocation ops */
266 int (*dma_alloc_pages)(struct azx *chip,
267 int type,
268 size_t size,
269 struct snd_dma_buffer *buf);
270 void (*dma_free_pages)(struct azx *chip, struct snd_dma_buffer *buf);
271 int (*substream_alloc_pages)(struct azx *chip,
272 struct snd_pcm_substream *substream,
273 size_t size);
274 int (*substream_free_pages)(struct azx *chip,
275 struct snd_pcm_substream *substream);
276 void (*pcm_mmap_prepare)(struct snd_pcm_substream *substream,
277 struct vm_area_struct *area);
278 /* Check if current position is acceptable */
279 int (*position_check)(struct azx *chip, struct azx_dev *azx_dev);
280};
281
282struct azx_pcm {
283 struct azx *chip;
284 struct snd_pcm *pcm;
285 struct hda_codec *codec;
286 struct hda_pcm *info;
287 struct list_head list;
288};
289
290typedef unsigned int (*azx_get_pos_callback_t)(struct azx *, struct azx_dev *);
291typedef int (*azx_get_delay_callback_t)(struct azx *, struct azx_dev *, unsigned int pos);
292
293struct azx {
294 struct snd_card *card;
295 struct pci_dev *pci;
296 int dev_index;
297
298 /* chip type specific */
299 int driver_type;
300 unsigned int driver_caps;
301 int playback_streams;
302 int playback_index_offset;
303 int capture_streams;
304 int capture_index_offset;
305 int num_streams;
306 const int *jackpoll_ms; /* per-card jack poll interval */
307
308 /* Register interaction. */
309 const struct hda_controller_ops *ops;
310
311 /* position adjustment callbacks */
312 azx_get_pos_callback_t get_position[2];
313 azx_get_delay_callback_t get_delay[2];
314
315 /* pci resources */
316 unsigned long addr;
317 void __iomem *remap_addr;
318 int irq;
319
320 /* locks */
321 spinlock_t reg_lock;
322 struct mutex open_mutex; /* Prevents concurrent open/close operations */
323
324 /* streams (x num_streams) */
325 struct azx_dev *azx_dev;
326
327 /* PCM */
328 struct list_head pcm_list; /* azx_pcm list */
329
330 /* HD codec */
331 unsigned short codec_mask;
332 int codec_probe_mask; /* copied from probe_mask option */
333 struct hda_bus *bus;
334 unsigned int beep_mode;
335
336 /* CORB/RIRB */
337 struct azx_rb corb;
338 struct azx_rb rirb;
339
340 /* CORB/RIRB and position buffers */
341 struct snd_dma_buffer rb;
342 struct snd_dma_buffer posbuf;
343
344#ifdef CONFIG_SND_HDA_PATCH_LOADER
345 const struct firmware *fw;
346#endif
347
348 /* flags */
349 const int *bdl_pos_adj;
350 int poll_count;
351 unsigned int running:1;
352 unsigned int initialized:1;
353 unsigned int single_cmd:1;
354 unsigned int polling_mode:1;
355 unsigned int msi:1;
356 unsigned int probing:1; /* codec probing phase */
357 unsigned int snoop:1;
358 unsigned int align_buffer_size:1;
359 unsigned int region_requested:1;
360 unsigned int disabled:1; /* disabled by VGA-switcher */
361
362 /* for debugging */
363 unsigned int last_cmd[AZX_MAX_CODECS];
364
365#ifdef CONFIG_SND_HDA_DSP_LOADER
366 struct azx_dev saved_azx_dev;
367#endif
368};
369
370#ifdef CONFIG_X86
371#define azx_snoop(chip) ((chip)->snoop)
372#else
373#define azx_snoop(chip) true
374#endif
375
376/*
377 * macros for easy use
378 */
379
380#define azx_writel(chip, reg, value) \
381 ((chip)->ops->reg_writel(value, (chip)->remap_addr + AZX_REG_##reg))
382#define azx_readl(chip, reg) \
383 ((chip)->ops->reg_readl((chip)->remap_addr + AZX_REG_##reg))
384#define azx_writew(chip, reg, value) \
385 ((chip)->ops->reg_writew(value, (chip)->remap_addr + AZX_REG_##reg))
386#define azx_readw(chip, reg) \
387 ((chip)->ops->reg_readw((chip)->remap_addr + AZX_REG_##reg))
388#define azx_writeb(chip, reg, value) \
389 ((chip)->ops->reg_writeb(value, (chip)->remap_addr + AZX_REG_##reg))
390#define azx_readb(chip, reg) \
391 ((chip)->ops->reg_readb((chip)->remap_addr + AZX_REG_##reg))
392
393#define azx_sd_writel(chip, dev, reg, value) \
394 ((chip)->ops->reg_writel(value, (dev)->sd_addr + AZX_REG_##reg))
395#define azx_sd_readl(chip, dev, reg) \
396 ((chip)->ops->reg_readl((dev)->sd_addr + AZX_REG_##reg))
397#define azx_sd_writew(chip, dev, reg, value) \
398 ((chip)->ops->reg_writew(value, (dev)->sd_addr + AZX_REG_##reg))
399#define azx_sd_readw(chip, dev, reg) \
400 ((chip)->ops->reg_readw((dev)->sd_addr + AZX_REG_##reg))
401#define azx_sd_writeb(chip, dev, reg, value) \
402 ((chip)->ops->reg_writeb(value, (dev)->sd_addr + AZX_REG_##reg))
403#define azx_sd_readb(chip, dev, reg) \
404 ((chip)->ops->reg_readb((dev)->sd_addr + AZX_REG_##reg))
405
406#define azx_has_pm_runtime(chip) \
407 ((chip)->driver_caps & AZX_DCAPS_PM_RUNTIME)
22 408
23/* PCM setup */ 409/* PCM setup */
24static inline struct azx_dev *get_azx_dev(struct snd_pcm_substream *substream) 410static inline struct azx_dev *get_azx_dev(struct snd_pcm_substream *substream)
@@ -43,14 +429,9 @@ void azx_enter_link_reset(struct azx *chip);
43irqreturn_t azx_interrupt(int irq, void *dev_id); 429irqreturn_t azx_interrupt(int irq, void *dev_id);
44 430
45/* Codec interface */ 431/* Codec interface */
46int azx_codec_create(struct azx *chip, const char *model, 432int azx_bus_create(struct azx *chip, const char *model);
47 unsigned int max_slots, 433int azx_probe_codecs(struct azx *chip, unsigned int max_slots);
48 int *power_save_to);
49int azx_codec_configure(struct azx *chip); 434int azx_codec_configure(struct azx *chip);
50int azx_mixer_create(struct azx *chip);
51int azx_init_stream(struct azx *chip); 435int azx_init_stream(struct azx *chip);
52 436
53void azx_notifier_register(struct azx *chip);
54void azx_notifier_unregister(struct azx *chip);
55
56#endif /* __SOUND_HDA_CONTROLLER_H */ 437#endif /* __SOUND_HDA_CONTROLLER_H */
diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c
index 8ec5289f8e05..3d2597b7037b 100644
--- a/sound/pci/hda/hda_generic.c
+++ b/sound/pci/hda/hda_generic.c
@@ -140,6 +140,9 @@ static void parse_user_hints(struct hda_codec *codec)
140 val = snd_hda_get_bool_hint(codec, "single_adc_amp"); 140 val = snd_hda_get_bool_hint(codec, "single_adc_amp");
141 if (val >= 0) 141 if (val >= 0)
142 codec->single_adc_amp = !!val; 142 codec->single_adc_amp = !!val;
143 val = snd_hda_get_bool_hint(codec, "power_save_node");
144 if (val >= 0)
145 codec->power_save_node = !!val;
143 146
144 val = snd_hda_get_bool_hint(codec, "auto_mute"); 147 val = snd_hda_get_bool_hint(codec, "auto_mute");
145 if (val >= 0) 148 if (val >= 0)
@@ -648,12 +651,24 @@ static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid,
648 unsigned int dir, unsigned int idx) 651 unsigned int dir, unsigned int idx)
649{ 652{
650 struct hda_gen_spec *spec = codec->spec; 653 struct hda_gen_spec *spec = codec->spec;
654 int type = get_wcaps_type(get_wcaps(codec, nid));
651 int i, n; 655 int i, n;
652 656
657 if (nid == codec->core.afg)
658 return true;
659
653 for (n = 0; n < spec->paths.used; n++) { 660 for (n = 0; n < spec->paths.used; n++) {
654 struct nid_path *path = snd_array_elem(&spec->paths, n); 661 struct nid_path *path = snd_array_elem(&spec->paths, n);
655 if (!path->active) 662 if (!path->active)
656 continue; 663 continue;
664 if (codec->power_save_node) {
665 if (!path->stream_enabled)
666 continue;
667 /* ignore unplugged paths except for DAC/ADC */
668 if (!(path->pin_enabled || path->pin_fixed) &&
669 type != AC_WID_AUD_OUT && type != AC_WID_AUD_IN)
670 continue;
671 }
657 for (i = 0; i < path->depth; i++) { 672 for (i = 0; i < path->depth; i++) {
658 if (path->path[i] == nid) { 673 if (path->path[i] == nid) {
659 if (dir == HDA_OUTPUT || path->idx[i] == idx) 674 if (dir == HDA_OUTPUT || path->idx[i] == idx)
@@ -807,6 +822,44 @@ static void activate_amp_in(struct hda_codec *codec, struct nid_path *path,
807 } 822 }
808} 823}
809 824
825/* sync power of each widget in the the given path */
826static hda_nid_t path_power_update(struct hda_codec *codec,
827 struct nid_path *path,
828 bool allow_powerdown)
829{
830 hda_nid_t nid, changed = 0;
831 int i, state;
832
833 for (i = 0; i < path->depth; i++) {
834 nid = path->path[i];
835 if (!(get_wcaps(codec, nid) & AC_WCAP_POWER))
836 continue;
837 if (nid == codec->core.afg)
838 continue;
839 if (!allow_powerdown || is_active_nid_for_any(codec, nid))
840 state = AC_PWRST_D0;
841 else
842 state = AC_PWRST_D3;
843 if (!snd_hda_check_power_state(codec, nid, state)) {
844 snd_hda_codec_write(codec, nid, 0,
845 AC_VERB_SET_POWER_STATE, state);
846 changed = nid;
847 if (state == AC_PWRST_D0)
848 snd_hdac_regmap_sync_node(&codec->core, nid);
849 }
850 }
851 return changed;
852}
853
854/* do sync with the last power state change */
855static void sync_power_state_change(struct hda_codec *codec, hda_nid_t nid)
856{
857 if (nid) {
858 msleep(10);
859 snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_POWER_STATE, 0);
860 }
861}
862
810/** 863/**
811 * snd_hda_activate_path - activate or deactivate the given path 864 * snd_hda_activate_path - activate or deactivate the given path
812 * @codec: the HDA codec 865 * @codec: the HDA codec
@@ -825,15 +878,13 @@ void snd_hda_activate_path(struct hda_codec *codec, struct nid_path *path,
825 if (!enable) 878 if (!enable)
826 path->active = false; 879 path->active = false;
827 880
881 /* make sure the widget is powered up */
882 if (enable && (spec->power_down_unused || codec->power_save_node))
883 path_power_update(codec, path, codec->power_save_node);
884
828 for (i = path->depth - 1; i >= 0; i--) { 885 for (i = path->depth - 1; i >= 0; i--) {
829 hda_nid_t nid = path->path[i]; 886 hda_nid_t nid = path->path[i];
830 if (enable && spec->power_down_unused) { 887
831 /* make sure the widget is powered up */
832 if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D0))
833 snd_hda_codec_write(codec, nid, 0,
834 AC_VERB_SET_POWER_STATE,
835 AC_PWRST_D0);
836 }
837 if (enable && path->multi[i]) 888 if (enable && path->multi[i])
838 snd_hda_codec_update_cache(codec, nid, 0, 889 snd_hda_codec_update_cache(codec, nid, 0,
839 AC_VERB_SET_CONNECT_SEL, 890 AC_VERB_SET_CONNECT_SEL,
@@ -853,28 +904,10 @@ EXPORT_SYMBOL_GPL(snd_hda_activate_path);
853static void path_power_down_sync(struct hda_codec *codec, struct nid_path *path) 904static void path_power_down_sync(struct hda_codec *codec, struct nid_path *path)
854{ 905{
855 struct hda_gen_spec *spec = codec->spec; 906 struct hda_gen_spec *spec = codec->spec;
856 bool changed = false;
857 int i;
858 907
859 if (!spec->power_down_unused || path->active) 908 if (!(spec->power_down_unused || codec->power_save_node) || path->active)
860 return; 909 return;
861 910 sync_power_state_change(codec, path_power_update(codec, path, true));
862 for (i = 0; i < path->depth; i++) {
863 hda_nid_t nid = path->path[i];
864 if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D3) &&
865 !is_active_nid_for_any(codec, nid)) {
866 snd_hda_codec_write(codec, nid, 0,
867 AC_VERB_SET_POWER_STATE,
868 AC_PWRST_D3);
869 changed = true;
870 }
871 }
872
873 if (changed) {
874 msleep(10);
875 snd_hda_codec_read(codec, path->path[0], 0,
876 AC_VERB_GET_POWER_STATE, 0);
877 }
878} 911}
879 912
880/* turn on/off EAPD on the given pin */ 913/* turn on/off EAPD on the given pin */
@@ -1574,6 +1607,7 @@ static int check_aamix_out_path(struct hda_codec *codec, int path_idx)
1574 return 0; 1607 return 0;
1575 /* print_nid_path(codec, "output-aamix", path); */ 1608 /* print_nid_path(codec, "output-aamix", path); */
1576 path->active = false; /* unused as default */ 1609 path->active = false; /* unused as default */
1610 path->pin_fixed = true; /* static route */
1577 return snd_hda_get_path_idx(codec, path); 1611 return snd_hda_get_path_idx(codec, path);
1578} 1612}
1579 1613
@@ -1863,12 +1897,11 @@ static void debug_show_configs(struct hda_codec *codec,
1863static void fill_all_dac_nids(struct hda_codec *codec) 1897static void fill_all_dac_nids(struct hda_codec *codec)
1864{ 1898{
1865 struct hda_gen_spec *spec = codec->spec; 1899 struct hda_gen_spec *spec = codec->spec;
1866 int i; 1900 hda_nid_t nid;
1867 hda_nid_t nid = codec->start_nid;
1868 1901
1869 spec->num_all_dacs = 0; 1902 spec->num_all_dacs = 0;
1870 memset(spec->all_dacs, 0, sizeof(spec->all_dacs)); 1903 memset(spec->all_dacs, 0, sizeof(spec->all_dacs));
1871 for (i = 0; i < codec->num_nodes; i++, nid++) { 1904 for_each_hda_codec_node(nid, codec) {
1872 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT) 1905 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
1873 continue; 1906 continue;
1874 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) { 1907 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
@@ -2998,6 +3031,7 @@ static int new_analog_input(struct hda_codec *codec, int input_idx,
2998 } 3031 }
2999 3032
3000 path->active = true; 3033 path->active = true;
3034 path->stream_enabled = true; /* no DAC/ADC involved */
3001 err = add_loopback_list(spec, mix_nid, idx); 3035 err = add_loopback_list(spec, mix_nid, idx);
3002 if (err < 0) 3036 if (err < 0)
3003 return err; 3037 return err;
@@ -3009,6 +3043,8 @@ static int new_analog_input(struct hda_codec *codec, int input_idx,
3009 if (path) { 3043 if (path) {
3010 print_nid_path(codec, "loopback-merge", path); 3044 print_nid_path(codec, "loopback-merge", path);
3011 path->active = true; 3045 path->active = true;
3046 path->pin_fixed = true; /* static route */
3047 path->stream_enabled = true; /* no DAC/ADC involved */
3012 spec->loopback_merge_path = 3048 spec->loopback_merge_path =
3013 snd_hda_get_path_idx(codec, path); 3049 snd_hda_get_path_idx(codec, path);
3014 } 3050 }
@@ -3030,10 +3066,9 @@ static int fill_adc_nids(struct hda_codec *codec)
3030 hda_nid_t nid; 3066 hda_nid_t nid;
3031 hda_nid_t *adc_nids = spec->adc_nids; 3067 hda_nid_t *adc_nids = spec->adc_nids;
3032 int max_nums = ARRAY_SIZE(spec->adc_nids); 3068 int max_nums = ARRAY_SIZE(spec->adc_nids);
3033 int i, nums = 0; 3069 int nums = 0;
3034 3070
3035 nid = codec->start_nid; 3071 for_each_hda_codec_node(nid, codec) {
3036 for (i = 0; i < codec->num_nodes; i++, nid++) {
3037 unsigned int caps = get_wcaps(codec, nid); 3072 unsigned int caps = get_wcaps(codec, nid);
3038 int type = get_wcaps_type(caps); 3073 int type = get_wcaps_type(caps);
3039 3074
@@ -3346,11 +3381,6 @@ static int cap_put_caller(struct snd_kcontrol *kcontrol,
3346 imux = &spec->input_mux; 3381 imux = &spec->input_mux;
3347 adc_idx = kcontrol->id.index; 3382 adc_idx = kcontrol->id.index;
3348 mutex_lock(&codec->control_mutex); 3383 mutex_lock(&codec->control_mutex);
3349 /* we use the cache-only update at first since multiple input paths
3350 * may shared the same amp; by updating only caches, the redundant
3351 * writes to hardware can be reduced.
3352 */
3353 codec->cached_write = 1;
3354 for (i = 0; i < imux->num_items; i++) { 3384 for (i = 0; i < imux->num_items; i++) {
3355 path = get_input_path(codec, adc_idx, i); 3385 path = get_input_path(codec, adc_idx, i);
3356 if (!path || !path->ctls[type]) 3386 if (!path || !path->ctls[type])
@@ -3358,12 +3388,9 @@ static int cap_put_caller(struct snd_kcontrol *kcontrol,
3358 kcontrol->private_value = path->ctls[type]; 3388 kcontrol->private_value = path->ctls[type];
3359 err = func(kcontrol, ucontrol); 3389 err = func(kcontrol, ucontrol);
3360 if (err < 0) 3390 if (err < 0)
3361 goto error; 3391 break;
3362 } 3392 }
3363 error:
3364 codec->cached_write = 0;
3365 mutex_unlock(&codec->control_mutex); 3393 mutex_unlock(&codec->control_mutex);
3366 snd_hda_codec_flush_cache(codec); /* flush the updates */
3367 if (err >= 0 && spec->cap_sync_hook) 3394 if (err >= 0 && spec->cap_sync_hook)
3368 spec->cap_sync_hook(codec, kcontrol, ucontrol); 3395 spec->cap_sync_hook(codec, kcontrol, ucontrol);
3369 return err; 3396 return err;
@@ -3810,6 +3837,7 @@ static void parse_digital(struct hda_codec *codec)
3810 continue; 3837 continue;
3811 print_nid_path(codec, "digout", path); 3838 print_nid_path(codec, "digout", path);
3812 path->active = true; 3839 path->active = true;
3840 path->pin_fixed = true; /* no jack detection */
3813 spec->digout_paths[i] = snd_hda_get_path_idx(codec, path); 3841 spec->digout_paths[i] = snd_hda_get_path_idx(codec, path);
3814 set_pin_target(codec, pin, PIN_OUT, false); 3842 set_pin_target(codec, pin, PIN_OUT, false);
3815 if (!nums) { 3843 if (!nums) {
@@ -3826,8 +3854,7 @@ static void parse_digital(struct hda_codec *codec)
3826 3854
3827 if (spec->autocfg.dig_in_pin) { 3855 if (spec->autocfg.dig_in_pin) {
3828 pin = spec->autocfg.dig_in_pin; 3856 pin = spec->autocfg.dig_in_pin;
3829 dig_nid = codec->start_nid; 3857 for_each_hda_codec_node(dig_nid, codec) {
3830 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
3831 unsigned int wcaps = get_wcaps(codec, dig_nid); 3858 unsigned int wcaps = get_wcaps(codec, dig_nid);
3832 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN) 3859 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
3833 continue; 3860 continue;
@@ -3837,6 +3864,7 @@ static void parse_digital(struct hda_codec *codec)
3837 if (path) { 3864 if (path) {
3838 print_nid_path(codec, "digin", path); 3865 print_nid_path(codec, "digin", path);
3839 path->active = true; 3866 path->active = true;
3867 path->pin_fixed = true; /* no jack */
3840 spec->dig_in_nid = dig_nid; 3868 spec->dig_in_nid = dig_nid;
3841 spec->digin_path = snd_hda_get_path_idx(codec, path); 3869 spec->digin_path = snd_hda_get_path_idx(codec, path);
3842 set_pin_target(codec, pin, PIN_IN, false); 3870 set_pin_target(codec, pin, PIN_IN, false);
@@ -3896,6 +3924,238 @@ static int mux_select(struct hda_codec *codec, unsigned int adc_idx,
3896 return 1; 3924 return 1;
3897} 3925}
3898 3926
3927/* power up/down widgets in the all paths that match with the given NID
3928 * as terminals (either start- or endpoint)
3929 *
3930 * returns the last changed NID, or zero if unchanged.
3931 */
3932static hda_nid_t set_path_power(struct hda_codec *codec, hda_nid_t nid,
3933 int pin_state, int stream_state)
3934{
3935 struct hda_gen_spec *spec = codec->spec;
3936 hda_nid_t last, changed = 0;
3937 struct nid_path *path;
3938 int n;
3939
3940 for (n = 0; n < spec->paths.used; n++) {
3941 path = snd_array_elem(&spec->paths, n);
3942 if (path->path[0] == nid ||
3943 path->path[path->depth - 1] == nid) {
3944 bool pin_old = path->pin_enabled;
3945 bool stream_old = path->stream_enabled;
3946
3947 if (pin_state >= 0)
3948 path->pin_enabled = pin_state;
3949 if (stream_state >= 0)
3950 path->stream_enabled = stream_state;
3951 if ((!path->pin_fixed && path->pin_enabled != pin_old)
3952 || path->stream_enabled != stream_old) {
3953 last = path_power_update(codec, path, true);
3954 if (last)
3955 changed = last;
3956 }
3957 }
3958 }
3959 return changed;
3960}
3961
3962/* check the jack status for power control */
3963static bool detect_pin_state(struct hda_codec *codec, hda_nid_t pin)
3964{
3965 if (!is_jack_detectable(codec, pin))
3966 return true;
3967 return snd_hda_jack_detect_state(codec, pin) != HDA_JACK_NOT_PRESENT;
3968}
3969
3970/* power up/down the paths of the given pin according to the jack state;
3971 * power = 0/1 : only power up/down if it matches with the jack state,
3972 * < 0 : force power up/down to follow the jack sate
3973 *
3974 * returns the last changed NID, or zero if unchanged.
3975 */
3976static hda_nid_t set_pin_power_jack(struct hda_codec *codec, hda_nid_t pin,
3977 int power)
3978{
3979 bool on;
3980
3981 if (!codec->power_save_node)
3982 return 0;
3983
3984 on = detect_pin_state(codec, pin);
3985
3986 if (power >= 0 && on != power)
3987 return 0;
3988 return set_path_power(codec, pin, on, -1);
3989}
3990
3991static void pin_power_callback(struct hda_codec *codec,
3992 struct hda_jack_callback *jack,
3993 bool on)
3994{
3995 if (jack && jack->tbl->nid)
3996 sync_power_state_change(codec,
3997 set_pin_power_jack(codec, jack->tbl->nid, on));
3998}
3999
4000/* callback only doing power up -- called at first */
4001static void pin_power_up_callback(struct hda_codec *codec,
4002 struct hda_jack_callback *jack)
4003{
4004 pin_power_callback(codec, jack, true);
4005}
4006
4007/* callback only doing power down -- called at last */
4008static void pin_power_down_callback(struct hda_codec *codec,
4009 struct hda_jack_callback *jack)
4010{
4011 pin_power_callback(codec, jack, false);
4012}
4013
4014/* set up the power up/down callbacks */
4015static void add_pin_power_ctls(struct hda_codec *codec, int num_pins,
4016 const hda_nid_t *pins, bool on)
4017{
4018 int i;
4019 hda_jack_callback_fn cb =
4020 on ? pin_power_up_callback : pin_power_down_callback;
4021
4022 for (i = 0; i < num_pins && pins[i]; i++) {
4023 if (is_jack_detectable(codec, pins[i]))
4024 snd_hda_jack_detect_enable_callback(codec, pins[i], cb);
4025 else
4026 set_path_power(codec, pins[i], true, -1);
4027 }
4028}
4029
4030/* enabled power callback to each available I/O pin with jack detections;
4031 * the digital I/O pins are excluded because of the unreliable detectsion
4032 */
4033static void add_all_pin_power_ctls(struct hda_codec *codec, bool on)
4034{
4035 struct hda_gen_spec *spec = codec->spec;
4036 struct auto_pin_cfg *cfg = &spec->autocfg;
4037 int i;
4038
4039 if (!codec->power_save_node)
4040 return;
4041 add_pin_power_ctls(codec, cfg->line_outs, cfg->line_out_pins, on);
4042 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
4043 add_pin_power_ctls(codec, cfg->hp_outs, cfg->hp_pins, on);
4044 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
4045 add_pin_power_ctls(codec, cfg->speaker_outs, cfg->speaker_pins, on);
4046 for (i = 0; i < cfg->num_inputs; i++)
4047 add_pin_power_ctls(codec, 1, &cfg->inputs[i].pin, on);
4048}
4049
4050/* sync path power up/down with the jack states of given pins */
4051static void sync_pin_power_ctls(struct hda_codec *codec, int num_pins,
4052 const hda_nid_t *pins)
4053{
4054 int i;
4055
4056 for (i = 0; i < num_pins && pins[i]; i++)
4057 if (is_jack_detectable(codec, pins[i]))
4058 set_pin_power_jack(codec, pins[i], -1);
4059}
4060
4061/* sync path power up/down with pins; called at init and resume */
4062static void sync_all_pin_power_ctls(struct hda_codec *codec)
4063{
4064 struct hda_gen_spec *spec = codec->spec;
4065 struct auto_pin_cfg *cfg = &spec->autocfg;
4066 int i;
4067
4068 if (!codec->power_save_node)
4069 return;
4070 sync_pin_power_ctls(codec, cfg->line_outs, cfg->line_out_pins);
4071 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
4072 sync_pin_power_ctls(codec, cfg->hp_outs, cfg->hp_pins);
4073 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
4074 sync_pin_power_ctls(codec, cfg->speaker_outs, cfg->speaker_pins);
4075 for (i = 0; i < cfg->num_inputs; i++)
4076 sync_pin_power_ctls(codec, 1, &cfg->inputs[i].pin);
4077}
4078
4079/* add fake paths if not present yet */
4080static int add_fake_paths(struct hda_codec *codec, hda_nid_t nid,
4081 int num_pins, const hda_nid_t *pins)
4082{
4083 struct hda_gen_spec *spec = codec->spec;
4084 struct nid_path *path;
4085 int i;
4086
4087 for (i = 0; i < num_pins; i++) {
4088 if (!pins[i])
4089 break;
4090 if (get_nid_path(codec, nid, pins[i], 0))
4091 continue;
4092 path = snd_array_new(&spec->paths);
4093 if (!path)
4094 return -ENOMEM;
4095 memset(path, 0, sizeof(*path));
4096 path->depth = 2;
4097 path->path[0] = nid;
4098 path->path[1] = pins[i];
4099 path->active = true;
4100 }
4101 return 0;
4102}
4103
4104/* create fake paths to all outputs from beep */
4105static int add_fake_beep_paths(struct hda_codec *codec)
4106{
4107 struct hda_gen_spec *spec = codec->spec;
4108 struct auto_pin_cfg *cfg = &spec->autocfg;
4109 hda_nid_t nid = spec->beep_nid;
4110 int err;
4111
4112 if (!codec->power_save_node || !nid)
4113 return 0;
4114 err = add_fake_paths(codec, nid, cfg->line_outs, cfg->line_out_pins);
4115 if (err < 0)
4116 return err;
4117 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
4118 err = add_fake_paths(codec, nid, cfg->hp_outs, cfg->hp_pins);
4119 if (err < 0)
4120 return err;
4121 }
4122 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
4123 err = add_fake_paths(codec, nid, cfg->speaker_outs,
4124 cfg->speaker_pins);
4125 if (err < 0)
4126 return err;
4127 }
4128 return 0;
4129}
4130
4131/* power up/down beep widget and its output paths */
4132static void beep_power_hook(struct hda_beep *beep, bool on)
4133{
4134 set_path_power(beep->codec, beep->nid, -1, on);
4135}
4136
4137/**
4138 * snd_hda_gen_fix_pin_power - Fix the power of the given pin widget to D0
4139 * @codec: the HDA codec
4140 * @pin: NID of pin to fix
4141 */
4142int snd_hda_gen_fix_pin_power(struct hda_codec *codec, hda_nid_t pin)
4143{
4144 struct hda_gen_spec *spec = codec->spec;
4145 struct nid_path *path;
4146
4147 path = snd_array_new(&spec->paths);
4148 if (!path)
4149 return -ENOMEM;
4150 memset(path, 0, sizeof(*path));
4151 path->depth = 1;
4152 path->path[0] = pin;
4153 path->active = true;
4154 path->pin_fixed = true;
4155 path->stream_enabled = true;
4156 return 0;
4157}
4158EXPORT_SYMBOL_GPL(snd_hda_gen_fix_pin_power);
3899 4159
3900/* 4160/*
3901 * Jack detections for HP auto-mute and mic-switch 4161 * Jack detections for HP auto-mute and mic-switch
@@ -3933,6 +4193,10 @@ static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
3933 if (!nid) 4193 if (!nid)
3934 break; 4194 break;
3935 4195
4196 oldval = snd_hda_codec_get_pin_target(codec, nid);
4197 if (oldval & PIN_IN)
4198 continue; /* no mute for inputs */
4199
3936 if (spec->auto_mute_via_amp) { 4200 if (spec->auto_mute_via_amp) {
3937 struct nid_path *path; 4201 struct nid_path *path;
3938 hda_nid_t mute_nid; 4202 hda_nid_t mute_nid;
@@ -3947,29 +4211,32 @@ static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
3947 spec->mute_bits |= (1ULL << mute_nid); 4211 spec->mute_bits |= (1ULL << mute_nid);
3948 else 4212 else
3949 spec->mute_bits &= ~(1ULL << mute_nid); 4213 spec->mute_bits &= ~(1ULL << mute_nid);
3950 set_pin_eapd(codec, nid, !mute);
3951 continue; 4214 continue;
4215 } else {
4216 /* don't reset VREF value in case it's controlling
4217 * the amp (see alc861_fixup_asus_amp_vref_0f())
4218 */
4219 if (spec->keep_vref_in_automute)
4220 val = oldval & ~PIN_HP;
4221 else
4222 val = 0;
4223 if (!mute)
4224 val |= oldval;
4225 /* here we call update_pin_ctl() so that the pinctl is
4226 * changed without changing the pinctl target value;
4227 * the original target value will be still referred at
4228 * the init / resume again
4229 */
4230 update_pin_ctl(codec, nid, val);
3952 } 4231 }
3953 4232
3954 oldval = snd_hda_codec_get_pin_target(codec, nid);
3955 if (oldval & PIN_IN)
3956 continue; /* no mute for inputs */
3957 /* don't reset VREF value in case it's controlling
3958 * the amp (see alc861_fixup_asus_amp_vref_0f())
3959 */
3960 if (spec->keep_vref_in_automute)
3961 val = oldval & ~PIN_HP;
3962 else
3963 val = 0;
3964 if (!mute)
3965 val |= oldval;
3966 /* here we call update_pin_ctl() so that the pinctl is changed
3967 * without changing the pinctl target value;
3968 * the original target value will be still referred at the
3969 * init / resume again
3970 */
3971 update_pin_ctl(codec, nid, val);
3972 set_pin_eapd(codec, nid, !mute); 4233 set_pin_eapd(codec, nid, !mute);
4234 if (codec->power_save_node) {
4235 bool on = !mute;
4236 if (on)
4237 on = detect_pin_state(codec, nid);
4238 set_path_power(codec, nid, on, -1);
4239 }
3973 } 4240 }
3974} 4241}
3975 4242
@@ -4436,7 +4703,11 @@ unsigned int snd_hda_gen_path_power_filter(struct hda_codec *codec,
4436 hda_nid_t nid, 4703 hda_nid_t nid,
4437 unsigned int power_state) 4704 unsigned int power_state)
4438{ 4705{
4439 if (power_state != AC_PWRST_D0 || nid == codec->afg) 4706 struct hda_gen_spec *spec = codec->spec;
4707
4708 if (!spec->power_down_unused && !codec->power_save_node)
4709 return power_state;
4710 if (power_state != AC_PWRST_D0 || nid == codec->core.afg)
4440 return power_state; 4711 return power_state;
4441 if (get_wcaps_type(get_wcaps(codec, nid)) >= AC_WID_POWER) 4712 if (get_wcaps_type(get_wcaps(codec, nid)) >= AC_WID_POWER)
4442 return power_state; 4713 return power_state;
@@ -4466,6 +4737,21 @@ static void mute_all_mixer_nid(struct hda_codec *codec, hda_nid_t mix)
4466} 4737}
4467 4738
4468/** 4739/**
4740 * snd_hda_gen_stream_pm - Stream power management callback
4741 * @codec: the HDA codec
4742 * @nid: audio widget
4743 * @on: power on/off flag
4744 *
4745 * Set this in patch_ops.stream_pm. Only valid with power_save_node flag.
4746 */
4747void snd_hda_gen_stream_pm(struct hda_codec *codec, hda_nid_t nid, bool on)
4748{
4749 if (codec->power_save_node)
4750 set_path_power(codec, nid, -1, on);
4751}
4752EXPORT_SYMBOL_GPL(snd_hda_gen_stream_pm);
4753
4754/**
4469 * snd_hda_gen_parse_auto_config - Parse the given BIOS configuration and 4755 * snd_hda_gen_parse_auto_config - Parse the given BIOS configuration and
4470 * set up the hda_gen_spec 4756 * set up the hda_gen_spec
4471 * @codec: the HDA codec 4757 * @codec: the HDA codec
@@ -4549,6 +4835,9 @@ int snd_hda_gen_parse_auto_config(struct hda_codec *codec,
4549 if (err < 0) 4835 if (err < 0)
4550 return err; 4836 return err;
4551 4837
4838 /* add power-down pin callbacks at first */
4839 add_all_pin_power_ctls(codec, false);
4840
4552 spec->const_channel_count = spec->ext_channel_count; 4841 spec->const_channel_count = spec->ext_channel_count;
4553 /* check the multiple speaker and headphone pins */ 4842 /* check the multiple speaker and headphone pins */
4554 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) 4843 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
@@ -4618,6 +4907,9 @@ int snd_hda_gen_parse_auto_config(struct hda_codec *codec,
4618 } 4907 }
4619 } 4908 }
4620 4909
4910 /* add power-up pin callbacks at last */
4911 add_all_pin_power_ctls(codec, true);
4912
4621 /* mute all aamix input initially */ 4913 /* mute all aamix input initially */
4622 if (spec->mixer_nid) 4914 if (spec->mixer_nid)
4623 mute_all_mixer_nid(codec, spec->mixer_nid); 4915 mute_all_mixer_nid(codec, spec->mixer_nid);
@@ -4625,13 +4917,20 @@ int snd_hda_gen_parse_auto_config(struct hda_codec *codec,
4625 dig_only: 4917 dig_only:
4626 parse_digital(codec); 4918 parse_digital(codec);
4627 4919
4628 if (spec->power_down_unused) 4920 if (spec->power_down_unused || codec->power_save_node)
4629 codec->power_filter = snd_hda_gen_path_power_filter; 4921 if (!codec->power_filter)
4922 codec->power_filter = snd_hda_gen_path_power_filter;
4630 4923
4631 if (!spec->no_analog && spec->beep_nid) { 4924 if (!spec->no_analog && spec->beep_nid) {
4632 err = snd_hda_attach_beep_device(codec, spec->beep_nid); 4925 err = snd_hda_attach_beep_device(codec, spec->beep_nid);
4633 if (err < 0) 4926 if (err < 0)
4634 return err; 4927 return err;
4928 if (codec->beep && codec->power_save_node) {
4929 err = add_fake_beep_paths(codec);
4930 if (err < 0)
4931 return err;
4932 codec->beep->power_hook = beep_power_hook;
4933 }
4635 } 4934 }
4636 4935
4637 return 1; 4936 return 1;
@@ -4675,7 +4974,7 @@ int snd_hda_gen_build_controls(struct hda_codec *codec)
4675 err = snd_hda_create_dig_out_ctls(codec, 4974 err = snd_hda_create_dig_out_ctls(codec,
4676 spec->multiout.dig_out_nid, 4975 spec->multiout.dig_out_nid,
4677 spec->multiout.dig_out_nid, 4976 spec->multiout.dig_out_nid,
4678 spec->pcm_rec[1].pcm_type); 4977 spec->pcm_rec[1]->pcm_type);
4679 if (err < 0) 4978 if (err < 0)
4680 return err; 4979 return err;
4681 if (!spec->no_analog) { 4980 if (!spec->no_analog) {
@@ -5137,6 +5436,33 @@ static void fill_pcm_stream_name(char *str, size_t len, const char *sfx,
5137 strlcat(str, sfx, len); 5436 strlcat(str, sfx, len);
5138} 5437}
5139 5438
5439/* copy PCM stream info from @default_str, and override non-NULL entries
5440 * from @spec_str and @nid
5441 */
5442static void setup_pcm_stream(struct hda_pcm_stream *str,
5443 const struct hda_pcm_stream *default_str,
5444 const struct hda_pcm_stream *spec_str,
5445 hda_nid_t nid)
5446{
5447 *str = *default_str;
5448 if (nid)
5449 str->nid = nid;
5450 if (spec_str) {
5451 if (spec_str->substreams)
5452 str->substreams = spec_str->substreams;
5453 if (spec_str->channels_min)
5454 str->channels_min = spec_str->channels_min;
5455 if (spec_str->channels_max)
5456 str->channels_max = spec_str->channels_max;
5457 if (spec_str->rates)
5458 str->rates = spec_str->rates;
5459 if (spec_str->formats)
5460 str->formats = spec_str->formats;
5461 if (spec_str->maxbps)
5462 str->maxbps = spec_str->maxbps;
5463 }
5464}
5465
5140/** 5466/**
5141 * snd_hda_gen_build_pcms - build PCM streams based on the parsed results 5467 * snd_hda_gen_build_pcms - build PCM streams based on the parsed results
5142 * @codec: the HDA codec 5468 * @codec: the HDA codec
@@ -5146,27 +5472,25 @@ static void fill_pcm_stream_name(char *str, size_t len, const char *sfx,
5146int snd_hda_gen_build_pcms(struct hda_codec *codec) 5472int snd_hda_gen_build_pcms(struct hda_codec *codec)
5147{ 5473{
5148 struct hda_gen_spec *spec = codec->spec; 5474 struct hda_gen_spec *spec = codec->spec;
5149 struct hda_pcm *info = spec->pcm_rec; 5475 struct hda_pcm *info;
5150 const struct hda_pcm_stream *p;
5151 bool have_multi_adcs; 5476 bool have_multi_adcs;
5152 5477
5153 codec->num_pcms = 1;
5154 codec->pcm_info = info;
5155
5156 if (spec->no_analog) 5478 if (spec->no_analog)
5157 goto skip_analog; 5479 goto skip_analog;
5158 5480
5159 fill_pcm_stream_name(spec->stream_name_analog, 5481 fill_pcm_stream_name(spec->stream_name_analog,
5160 sizeof(spec->stream_name_analog), 5482 sizeof(spec->stream_name_analog),
5161 " Analog", codec->chip_name); 5483 " Analog", codec->core.chip_name);
5162 info->name = spec->stream_name_analog; 5484 info = snd_hda_codec_pcm_new(codec, "%s", spec->stream_name_analog);
5485 if (!info)
5486 return -ENOMEM;
5487 spec->pcm_rec[0] = info;
5163 5488
5164 if (spec->multiout.num_dacs > 0) { 5489 if (spec->multiout.num_dacs > 0) {
5165 p = spec->stream_analog_playback; 5490 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK],
5166 if (!p) 5491 &pcm_analog_playback,
5167 p = &pcm_analog_playback; 5492 spec->stream_analog_playback,
5168 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; 5493 spec->multiout.dac_nids[0]);
5169 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
5170 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 5494 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
5171 spec->multiout.max_channels; 5495 spec->multiout.max_channels;
5172 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT && 5496 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
@@ -5175,15 +5499,11 @@ int snd_hda_gen_build_pcms(struct hda_codec *codec)
5175 snd_pcm_2_1_chmaps; 5499 snd_pcm_2_1_chmaps;
5176 } 5500 }
5177 if (spec->num_adc_nids) { 5501 if (spec->num_adc_nids) {
5178 p = spec->stream_analog_capture; 5502 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE],
5179 if (!p) { 5503 (spec->dyn_adc_switch ?
5180 if (spec->dyn_adc_switch) 5504 &dyn_adc_pcm_analog_capture : &pcm_analog_capture),
5181 p = &dyn_adc_pcm_analog_capture; 5505 spec->stream_analog_capture,
5182 else 5506 spec->adc_nids[0]);
5183 p = &pcm_analog_capture;
5184 }
5185 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
5186 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
5187 } 5507 }
5188 5508
5189 skip_analog: 5509 skip_analog:
@@ -5191,29 +5511,27 @@ int snd_hda_gen_build_pcms(struct hda_codec *codec)
5191 if (spec->multiout.dig_out_nid || spec->dig_in_nid) { 5511 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
5192 fill_pcm_stream_name(spec->stream_name_digital, 5512 fill_pcm_stream_name(spec->stream_name_digital,
5193 sizeof(spec->stream_name_digital), 5513 sizeof(spec->stream_name_digital),
5194 " Digital", codec->chip_name); 5514 " Digital", codec->core.chip_name);
5195 codec->num_pcms = 2; 5515 info = snd_hda_codec_pcm_new(codec, "%s",
5516 spec->stream_name_digital);
5517 if (!info)
5518 return -ENOMEM;
5196 codec->slave_dig_outs = spec->multiout.slave_dig_outs; 5519 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
5197 info = spec->pcm_rec + 1; 5520 spec->pcm_rec[1] = info;
5198 info->name = spec->stream_name_digital;
5199 if (spec->dig_out_type) 5521 if (spec->dig_out_type)
5200 info->pcm_type = spec->dig_out_type; 5522 info->pcm_type = spec->dig_out_type;
5201 else 5523 else
5202 info->pcm_type = HDA_PCM_TYPE_SPDIF; 5524 info->pcm_type = HDA_PCM_TYPE_SPDIF;
5203 if (spec->multiout.dig_out_nid) { 5525 if (spec->multiout.dig_out_nid)
5204 p = spec->stream_digital_playback; 5526 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK],
5205 if (!p) 5527 &pcm_digital_playback,
5206 p = &pcm_digital_playback; 5528 spec->stream_digital_playback,
5207 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; 5529 spec->multiout.dig_out_nid);
5208 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; 5530 if (spec->dig_in_nid)
5209 } 5531 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE],
5210 if (spec->dig_in_nid) { 5532 &pcm_digital_capture,
5211 p = spec->stream_digital_capture; 5533 spec->stream_digital_capture,
5212 if (!p) 5534 spec->dig_in_nid);
5213 p = &pcm_digital_capture;
5214 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
5215 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
5216 }
5217 } 5535 }
5218 5536
5219 if (spec->no_analog) 5537 if (spec->no_analog)
@@ -5228,35 +5546,30 @@ int snd_hda_gen_build_pcms(struct hda_codec *codec)
5228 if (spec->alt_dac_nid || have_multi_adcs) { 5546 if (spec->alt_dac_nid || have_multi_adcs) {
5229 fill_pcm_stream_name(spec->stream_name_alt_analog, 5547 fill_pcm_stream_name(spec->stream_name_alt_analog,
5230 sizeof(spec->stream_name_alt_analog), 5548 sizeof(spec->stream_name_alt_analog),
5231 " Alt Analog", codec->chip_name); 5549 " Alt Analog", codec->core.chip_name);
5232 codec->num_pcms = 3; 5550 info = snd_hda_codec_pcm_new(codec, "%s",
5233 info = spec->pcm_rec + 2; 5551 spec->stream_name_alt_analog);
5234 info->name = spec->stream_name_alt_analog; 5552 if (!info)
5235 if (spec->alt_dac_nid) { 5553 return -ENOMEM;
5236 p = spec->stream_analog_alt_playback; 5554 spec->pcm_rec[2] = info;
5237 if (!p) 5555 if (spec->alt_dac_nid)
5238 p = &pcm_analog_alt_playback; 5556 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK],
5239 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; 5557 &pcm_analog_alt_playback,
5240 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 5558 spec->stream_analog_alt_playback,
5241 spec->alt_dac_nid; 5559 spec->alt_dac_nid);
5242 } else { 5560 else
5243 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = 5561 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK],
5244 pcm_null_stream; 5562 &pcm_null_stream, NULL, 0);
5245 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
5246 }
5247 if (have_multi_adcs) { 5563 if (have_multi_adcs) {
5248 p = spec->stream_analog_alt_capture; 5564 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE],
5249 if (!p) 5565 &pcm_analog_alt_capture,
5250 p = &pcm_analog_alt_capture; 5566 spec->stream_analog_alt_capture,
5251 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; 5567 spec->adc_nids[1]);
5252 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
5253 spec->adc_nids[1];
5254 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 5568 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
5255 spec->num_adc_nids - 1; 5569 spec->num_adc_nids - 1;
5256 } else { 5570 } else {
5257 info->stream[SNDRV_PCM_STREAM_CAPTURE] = 5571 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE],
5258 pcm_null_stream; 5572 &pcm_null_stream, NULL, 0);
5259 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
5260 } 5573 }
5261 } 5574 }
5262 5575
@@ -5452,8 +5765,6 @@ int snd_hda_gen_init(struct hda_codec *codec)
5452 5765
5453 snd_hda_apply_verbs(codec); 5766 snd_hda_apply_verbs(codec);
5454 5767
5455 codec->cached_write = 1;
5456
5457 init_multi_out(codec); 5768 init_multi_out(codec);
5458 init_extra_out(codec); 5769 init_extra_out(codec);
5459 init_multi_io(codec); 5770 init_multi_io(codec);
@@ -5464,10 +5775,12 @@ int snd_hda_gen_init(struct hda_codec *codec)
5464 5775
5465 clear_unsol_on_unused_pins(codec); 5776 clear_unsol_on_unused_pins(codec);
5466 5777
5778 sync_all_pin_power_ctls(codec);
5779
5467 /* call init functions of standard auto-mute helpers */ 5780 /* call init functions of standard auto-mute helpers */
5468 update_automute_all(codec); 5781 update_automute_all(codec);
5469 5782
5470 snd_hda_codec_flush_cache(codec); 5783 regcache_sync(codec->core.regmap);
5471 5784
5472 if (spec->vmaster_mute.sw_kctl && spec->vmaster_mute.hook) 5785 if (spec->vmaster_mute.sw_kctl && spec->vmaster_mute.hook)
5473 snd_hda_sync_vmaster_hook(&spec->vmaster_mute); 5786 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
@@ -5524,13 +5837,11 @@ static const struct hda_codec_ops generic_patch_ops = {
5524#endif 5837#endif
5525}; 5838};
5526 5839
5527/** 5840/*
5528 * snd_hda_parse_generic_codec - Generic codec parser 5841 * snd_hda_parse_generic_codec - Generic codec parser
5529 * @codec: the HDA codec 5842 * @codec: the HDA codec
5530 *
5531 * This should be called from the HDA codec core.
5532 */ 5843 */
5533int snd_hda_parse_generic_codec(struct hda_codec *codec) 5844static int snd_hda_parse_generic_codec(struct hda_codec *codec)
5534{ 5845{
5535 struct hda_gen_spec *spec; 5846 struct hda_gen_spec *spec;
5536 int err; 5847 int err;
@@ -5556,7 +5867,17 @@ error:
5556 snd_hda_gen_free(codec); 5867 snd_hda_gen_free(codec);
5557 return err; 5868 return err;
5558} 5869}
5559EXPORT_SYMBOL_GPL(snd_hda_parse_generic_codec); 5870
5871static const struct hda_codec_preset snd_hda_preset_generic[] = {
5872 { .id = HDA_CODEC_ID_GENERIC, .patch = snd_hda_parse_generic_codec },
5873 {} /* terminator */
5874};
5875
5876static struct hda_codec_driver generic_driver = {
5877 .preset = snd_hda_preset_generic,
5878};
5879
5880module_hda_codec_driver(generic_driver);
5560 5881
5561MODULE_LICENSE("GPL"); 5882MODULE_LICENSE("GPL");
5562MODULE_DESCRIPTION("Generic HD-audio codec parser"); 5883MODULE_DESCRIPTION("Generic HD-audio codec parser");
diff --git a/sound/pci/hda/hda_generic.h b/sound/pci/hda/hda_generic.h
index 3d852660443a..56e4139b9032 100644
--- a/sound/pci/hda/hda_generic.h
+++ b/sound/pci/hda/hda_generic.h
@@ -46,7 +46,10 @@ struct nid_path {
46 unsigned char idx[MAX_NID_PATH_DEPTH]; 46 unsigned char idx[MAX_NID_PATH_DEPTH];
47 unsigned char multi[MAX_NID_PATH_DEPTH]; 47 unsigned char multi[MAX_NID_PATH_DEPTH];
48 unsigned int ctls[NID_PATH_NUM_CTLS]; /* NID_PATH_XXX_CTL */ 48 unsigned int ctls[NID_PATH_NUM_CTLS]; /* NID_PATH_XXX_CTL */
49 bool active; 49 bool active:1; /* activated by driver */
50 bool pin_enabled:1; /* pins are enabled */
51 bool pin_fixed:1; /* path with fixed pin */
52 bool stream_enabled:1; /* stream is active */
50}; 53};
51 54
52/* mic/line-in auto switching entry */ 55/* mic/line-in auto switching entry */
@@ -144,7 +147,7 @@ struct hda_gen_spec {
144 int const_channel_count; /* channel count for all */ 147 int const_channel_count; /* channel count for all */
145 148
146 /* PCM information */ 149 /* PCM information */
147 struct hda_pcm pcm_rec[3]; /* used in build_pcms() */ 150 struct hda_pcm *pcm_rec[3]; /* used in build_pcms() */
148 151
149 /* dynamic controls, init_verbs and input_mux */ 152 /* dynamic controls, init_verbs and input_mux */
150 struct auto_pin_cfg autocfg; 153 struct auto_pin_cfg autocfg;
@@ -340,5 +343,7 @@ int snd_hda_gen_check_power_status(struct hda_codec *codec, hda_nid_t nid);
340unsigned int snd_hda_gen_path_power_filter(struct hda_codec *codec, 343unsigned int snd_hda_gen_path_power_filter(struct hda_codec *codec,
341 hda_nid_t nid, 344 hda_nid_t nid,
342 unsigned int power_state); 345 unsigned int power_state);
346void snd_hda_gen_stream_pm(struct hda_codec *codec, hda_nid_t nid, bool on);
347int snd_hda_gen_fix_pin_power(struct hda_codec *codec, hda_nid_t pin);
343 348
344#endif /* __SOUND_HDA_GENERIC_H */ 349#endif /* __SOUND_HDA_GENERIC_H */
diff --git a/sound/pci/hda/hda_hwdep.c b/sound/pci/hda/hda_hwdep.c
index 11b5a42b4ec8..57df06e76968 100644
--- a/sound/pci/hda/hda_hwdep.c
+++ b/sound/pci/hda/hda_hwdep.c
@@ -101,7 +101,7 @@ int snd_hda_create_hwdep(struct hda_codec *codec)
101 int err; 101 int err;
102 102
103 sprintf(hwname, "HDA Codec %d", codec->addr); 103 sprintf(hwname, "HDA Codec %d", codec->addr);
104 err = snd_hwdep_new(codec->bus->card, hwname, codec->addr, &hwdep); 104 err = snd_hwdep_new(codec->card, hwname, codec->addr, &hwdep);
105 if (err < 0) 105 if (err < 0)
106 return err; 106 return err;
107 codec->hwdep = hwdep; 107 codec->hwdep = hwdep;
@@ -116,9 +116,6 @@ int snd_hda_create_hwdep(struct hda_codec *codec)
116 hwdep->ops.ioctl_compat = hda_hwdep_ioctl_compat; 116 hwdep->ops.ioctl_compat = hda_hwdep_ioctl_compat;
117#endif 117#endif
118 118
119 /* link to codec */
120 hwdep->dev.parent = &codec->dev;
121
122 /* for sysfs */ 119 /* for sysfs */
123 hwdep->dev.groups = snd_hda_dev_attr_groups; 120 hwdep->dev.groups = snd_hda_dev_attr_groups;
124 dev_set_drvdata(&hwdep->dev, codec); 121 dev_set_drvdata(&hwdep->dev, codec);
diff --git a/sound/pci/hda/hda_i915.c b/sound/pci/hda/hda_i915.c
index 714894527e06..3052a2b095f7 100644
--- a/sound/pci/hda/hda_i915.c
+++ b/sound/pci/hda/hda_i915.c
@@ -22,7 +22,7 @@
22#include <linux/component.h> 22#include <linux/component.h>
23#include <drm/i915_component.h> 23#include <drm/i915_component.h>
24#include <sound/core.h> 24#include <sound/core.h>
25#include "hda_priv.h" 25#include "hda_controller.h"
26#include "hda_intel.h" 26#include "hda_intel.h"
27 27
28/* Intel HSW/BDW display HDA controller Extended Mode registers. 28/* Intel HSW/BDW display HDA controller Extended Mode registers.
@@ -55,6 +55,12 @@ void haswell_set_bclk(struct hda_intel *hda)
55 int cdclk_freq; 55 int cdclk_freq;
56 unsigned int bclk_m, bclk_n; 56 unsigned int bclk_m, bclk_n;
57 struct i915_audio_component *acomp = &hda->audio_component; 57 struct i915_audio_component *acomp = &hda->audio_component;
58 struct pci_dev *pci = hda->chip.pci;
59
60 /* Only Haswell/Broadwell need set BCLK */
61 if (pci->device != 0x0a0c && pci->device != 0x0c0c
62 && pci->device != 0x0d0c && pci->device != 0x160c)
63 return;
58 64
59 if (!acomp->ops) 65 if (!acomp->ops)
60 return; 66 return;
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index a8a1e14272a1..34040d26c94f 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -62,7 +62,6 @@
62#include <linux/firmware.h> 62#include <linux/firmware.h>
63#include "hda_codec.h" 63#include "hda_codec.h"
64#include "hda_controller.h" 64#include "hda_controller.h"
65#include "hda_priv.h"
66#include "hda_intel.h" 65#include "hda_intel.h"
67 66
68/* position fix mode */ 67/* position fix mode */
@@ -174,7 +173,6 @@ static struct kernel_param_ops param_ops_xint = {
174#define param_check_xint param_check_int 173#define param_check_xint param_check_int
175 174
176static int power_save = CONFIG_SND_HDA_POWER_SAVE_DEFAULT; 175static int power_save = CONFIG_SND_HDA_POWER_SAVE_DEFAULT;
177static int *power_save_addr = &power_save;
178module_param(power_save, xint, 0644); 176module_param(power_save, xint, 0644);
179MODULE_PARM_DESC(power_save, "Automatic power-saving timeout " 177MODULE_PARM_DESC(power_save, "Automatic power-saving timeout "
180 "(in second, 0 = disable)."); 178 "(in second, 0 = disable).");
@@ -187,7 +185,7 @@ static bool power_save_controller = 1;
187module_param(power_save_controller, bool, 0644); 185module_param(power_save_controller, bool, 0644);
188MODULE_PARM_DESC(power_save_controller, "Reset controller in power save mode."); 186MODULE_PARM_DESC(power_save_controller, "Reset controller in power save mode.");
189#else 187#else
190static int *power_save_addr; 188#define power_save 0
191#endif /* CONFIG_PM */ 189#endif /* CONFIG_PM */
192 190
193static int align_buffer_size = -1; 191static int align_buffer_size = -1;
@@ -299,8 +297,15 @@ enum {
299 AZX_DCAPS_PM_RUNTIME | AZX_DCAPS_I915_POWERWELL |\ 297 AZX_DCAPS_PM_RUNTIME | AZX_DCAPS_I915_POWERWELL |\
300 AZX_DCAPS_SNOOP_TYPE(SCH)) 298 AZX_DCAPS_SNOOP_TYPE(SCH))
301 299
300#define AZX_DCAPS_INTEL_BAYTRAIL \
301 (AZX_DCAPS_INTEL_PCH_NOPM | AZX_DCAPS_I915_POWERWELL)
302
303#define AZX_DCAPS_INTEL_BRASWELL \
304 (AZX_DCAPS_INTEL_PCH | AZX_DCAPS_I915_POWERWELL)
305
302#define AZX_DCAPS_INTEL_SKYLAKE \ 306#define AZX_DCAPS_INTEL_SKYLAKE \
303 (AZX_DCAPS_INTEL_PCH | AZX_DCAPS_SEPARATE_STREAM_TAG) 307 (AZX_DCAPS_INTEL_PCH | AZX_DCAPS_SEPARATE_STREAM_TAG |\
308 AZX_DCAPS_I915_POWERWELL)
304 309
305/* quirks for ATI SB / AMD Hudson */ 310/* quirks for ATI SB / AMD Hudson */
306#define AZX_DCAPS_PRESET_ATI_SB \ 311#define AZX_DCAPS_PRESET_ATI_SB \
@@ -530,10 +535,10 @@ static int azx_position_check(struct azx *chip, struct azx_dev *azx_dev)
530 if (ok == 1) { 535 if (ok == 1) {
531 azx_dev->irq_pending = 0; 536 azx_dev->irq_pending = 0;
532 return ok; 537 return ok;
533 } else if (ok == 0 && chip->bus && chip->bus->workq) { 538 } else if (ok == 0) {
534 /* bogus IRQ, process it later */ 539 /* bogus IRQ, process it later */
535 azx_dev->irq_pending = 1; 540 azx_dev->irq_pending = 1;
536 queue_work(chip->bus->workq, &hda->irq_pending_work); 541 schedule_work(&hda->irq_pending_work);
537 } 542 }
538 return 0; 543 return 0;
539} 544}
@@ -741,7 +746,6 @@ static int param_set_xint(const char *val, const struct kernel_param *kp)
741{ 746{
742 struct hda_intel *hda; 747 struct hda_intel *hda;
743 struct azx *chip; 748 struct azx *chip;
744 struct hda_codec *c;
745 int prev = power_save; 749 int prev = power_save;
746 int ret = param_set_int(val, kp); 750 int ret = param_set_int(val, kp);
747 751
@@ -753,8 +757,7 @@ static int param_set_xint(const char *val, const struct kernel_param *kp)
753 chip = &hda->chip; 757 chip = &hda->chip;
754 if (!chip->bus || chip->disabled) 758 if (!chip->bus || chip->disabled)
755 continue; 759 continue;
756 list_for_each_entry(c, &chip->bus->codec_list, list) 760 snd_hda_set_power_save(chip->bus, power_save * 1000);
757 snd_hda_power_sync(c);
758 } 761 }
759 mutex_unlock(&card_list_lock); 762 mutex_unlock(&card_list_lock);
760 return 0; 763 return 0;
@@ -773,7 +776,6 @@ static int azx_suspend(struct device *dev)
773 struct snd_card *card = dev_get_drvdata(dev); 776 struct snd_card *card = dev_get_drvdata(dev);
774 struct azx *chip; 777 struct azx *chip;
775 struct hda_intel *hda; 778 struct hda_intel *hda;
776 struct azx_pcm *p;
777 779
778 if (!card) 780 if (!card)
779 return 0; 781 return 0;
@@ -785,10 +787,6 @@ static int azx_suspend(struct device *dev)
785 787
786 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 788 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
787 azx_clear_irq_pending(chip); 789 azx_clear_irq_pending(chip);
788 list_for_each_entry(p, &chip->pcm_list, list)
789 snd_pcm_suspend_all(p->pcm);
790 if (chip->initialized)
791 snd_hda_suspend(chip->bus);
792 azx_stop_chip(chip); 790 azx_stop_chip(chip);
793 azx_enter_link_reset(chip); 791 azx_enter_link_reset(chip);
794 if (chip->irq >= 0) { 792 if (chip->irq >= 0) {
@@ -831,7 +829,6 @@ static int azx_resume(struct device *dev)
831 829
832 azx_init_chip(chip, true); 830 azx_init_chip(chip, true);
833 831
834 snd_hda_resume(chip->bus);
835 snd_power_change_state(card, SNDRV_CTL_POWER_D0); 832 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
836 return 0; 833 return 0;
837} 834}
@@ -852,7 +849,7 @@ static int azx_runtime_suspend(struct device *dev)
852 if (chip->disabled || hda->init_failed) 849 if (chip->disabled || hda->init_failed)
853 return 0; 850 return 0;
854 851
855 if (!(chip->driver_caps & AZX_DCAPS_PM_RUNTIME)) 852 if (!azx_has_pm_runtime(chip))
856 return 0; 853 return 0;
857 854
858 /* enable controller wake up event */ 855 /* enable controller wake up event */
@@ -885,7 +882,7 @@ static int azx_runtime_resume(struct device *dev)
885 if (chip->disabled || hda->init_failed) 882 if (chip->disabled || hda->init_failed)
886 return 0; 883 return 0;
887 884
888 if (!(chip->driver_caps & AZX_DCAPS_PM_RUNTIME)) 885 if (!azx_has_pm_runtime(chip))
889 return 0; 886 return 0;
890 887
891 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) { 888 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
@@ -901,10 +898,10 @@ static int azx_runtime_resume(struct device *dev)
901 898
902 bus = chip->bus; 899 bus = chip->bus;
903 if (status && bus) { 900 if (status && bus) {
904 list_for_each_entry(codec, &bus->codec_list, list) 901 list_for_each_codec(codec, bus)
905 if (status & (1 << codec->addr)) 902 if (status & (1 << codec->addr))
906 queue_delayed_work(codec->bus->workq, 903 schedule_delayed_work(&codec->jackpoll_work,
907 &codec->jackpoll_work, codec->jackpoll_interval); 904 codec->jackpoll_interval);
908 } 905 }
909 906
910 /* disable controller Wake Up event*/ 907 /* disable controller Wake Up event*/
@@ -928,8 +925,8 @@ static int azx_runtime_idle(struct device *dev)
928 if (chip->disabled || hda->init_failed) 925 if (chip->disabled || hda->init_failed)
929 return 0; 926 return 0;
930 927
931 if (!power_save_controller || 928 if (!power_save_controller || !azx_has_pm_runtime(chip) ||
932 !(chip->driver_caps & AZX_DCAPS_PM_RUNTIME)) 929 chip->bus->core.codec_powered)
933 return -EBUSY; 930 return -EBUSY;
934 931
935 return 0; 932 return 0;
@@ -1071,14 +1068,11 @@ static int azx_free(struct azx *chip)
1071 struct hda_intel *hda = container_of(chip, struct hda_intel, chip); 1068 struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
1072 int i; 1069 int i;
1073 1070
1074 if ((chip->driver_caps & AZX_DCAPS_PM_RUNTIME) 1071 if (azx_has_pm_runtime(chip) && chip->running)
1075 && chip->running)
1076 pm_runtime_get_noresume(&pci->dev); 1072 pm_runtime_get_noresume(&pci->dev);
1077 1073
1078 azx_del_card_list(chip); 1074 azx_del_card_list(chip);
1079 1075
1080 azx_notifier_unregister(chip);
1081
1082 hda->init_failed = 1; /* to be sure */ 1076 hda->init_failed = 1; /* to be sure */
1083 complete_all(&hda->probe_wait); 1077 complete_all(&hda->probe_wait);
1084 1078
@@ -1394,7 +1388,6 @@ static int azx_create(struct snd_card *card, struct pci_dev *pci,
1394 1388
1395 hda = kzalloc(sizeof(*hda), GFP_KERNEL); 1389 hda = kzalloc(sizeof(*hda), GFP_KERNEL);
1396 if (!hda) { 1390 if (!hda) {
1397 dev_err(card->dev, "Cannot allocate hda\n");
1398 pci_disable_device(pci); 1391 pci_disable_device(pci);
1399 return -ENOMEM; 1392 return -ENOMEM;
1400 } 1393 }
@@ -1575,10 +1568,8 @@ static int azx_first_init(struct azx *chip)
1575 chip->num_streams = chip->playback_streams + chip->capture_streams; 1568 chip->num_streams = chip->playback_streams + chip->capture_streams;
1576 chip->azx_dev = kcalloc(chip->num_streams, sizeof(*chip->azx_dev), 1569 chip->azx_dev = kcalloc(chip->num_streams, sizeof(*chip->azx_dev),
1577 GFP_KERNEL); 1570 GFP_KERNEL);
1578 if (!chip->azx_dev) { 1571 if (!chip->azx_dev)
1579 dev_err(card->dev, "cannot malloc azx_dev\n");
1580 return -ENOMEM; 1572 return -ENOMEM;
1581 }
1582 1573
1583 err = azx_alloc_stream_pages(chip); 1574 err = azx_alloc_stream_pages(chip);
1584 if (err < 0) 1575 if (err < 0)
@@ -1615,19 +1606,6 @@ static int azx_first_init(struct azx *chip)
1615 return 0; 1606 return 0;
1616} 1607}
1617 1608
1618static void power_down_all_codecs(struct azx *chip)
1619{
1620#ifdef CONFIG_PM
1621 /* The codecs were powered up in snd_hda_codec_new().
1622 * Now all initialization done, so turn them down if possible
1623 */
1624 struct hda_codec *codec;
1625 list_for_each_entry(codec, &chip->bus->codec_list, list) {
1626 snd_hda_power_down(codec);
1627 }
1628#endif
1629}
1630
1631#ifdef CONFIG_SND_HDA_PATCH_LOADER 1609#ifdef CONFIG_SND_HDA_PATCH_LOADER
1632/* callback from request_firmware_nowait() */ 1610/* callback from request_firmware_nowait() */
1633static void azx_firmware_cb(const struct firmware *fw, void *context) 1611static void azx_firmware_cb(const struct firmware *fw, void *context)
@@ -1896,12 +1874,14 @@ static int azx_probe_continue(struct azx *chip)
1896#endif 1874#endif
1897 1875
1898 /* create codec instances */ 1876 /* create codec instances */
1899 err = azx_codec_create(chip, model[dev], 1877 err = azx_bus_create(chip, model[dev]);
1900 azx_max_codecs[chip->driver_type], 1878 if (err < 0)
1901 power_save_addr); 1879 goto out_free;
1902 1880
1881 err = azx_probe_codecs(chip, azx_max_codecs[chip->driver_type]);
1903 if (err < 0) 1882 if (err < 0)
1904 goto out_free; 1883 goto out_free;
1884
1905#ifdef CONFIG_SND_HDA_PATCH_LOADER 1885#ifdef CONFIG_SND_HDA_PATCH_LOADER
1906 if (chip->fw) { 1886 if (chip->fw) {
1907 err = snd_hda_load_patch(chip->bus, chip->fw->size, 1887 err = snd_hda_load_patch(chip->bus, chip->fw->size,
@@ -1920,25 +1900,14 @@ static int azx_probe_continue(struct azx *chip)
1920 goto out_free; 1900 goto out_free;
1921 } 1901 }
1922 1902
1923 /* create PCM streams */
1924 err = snd_hda_build_pcms(chip->bus);
1925 if (err < 0)
1926 goto out_free;
1927
1928 /* create mixer controls */
1929 err = azx_mixer_create(chip);
1930 if (err < 0)
1931 goto out_free;
1932
1933 err = snd_card_register(chip->card); 1903 err = snd_card_register(chip->card);
1934 if (err < 0) 1904 if (err < 0)
1935 goto out_free; 1905 goto out_free;
1936 1906
1937 chip->running = 1; 1907 chip->running = 1;
1938 power_down_all_codecs(chip);
1939 azx_notifier_register(chip);
1940 azx_add_card_list(chip); 1908 azx_add_card_list(chip);
1941 if ((chip->driver_caps & AZX_DCAPS_PM_RUNTIME) || hda->use_vga_switcheroo) 1909 snd_hda_set_power_save(chip->bus, power_save * 1000);
1910 if (azx_has_pm_runtime(chip) || hda->use_vga_switcheroo)
1942 pm_runtime_put_noidle(&pci->dev); 1911 pm_runtime_put_noidle(&pci->dev);
1943 1912
1944out_free: 1913out_free:
@@ -1956,6 +1925,18 @@ static void azx_remove(struct pci_dev *pci)
1956 snd_card_free(card); 1925 snd_card_free(card);
1957} 1926}
1958 1927
1928static void azx_shutdown(struct pci_dev *pci)
1929{
1930 struct snd_card *card = pci_get_drvdata(pci);
1931 struct azx *chip;
1932
1933 if (!card)
1934 return;
1935 chip = card->private_data;
1936 if (chip && chip->running)
1937 azx_stop_chip(chip);
1938}
1939
1959/* PCI IDs */ 1940/* PCI IDs */
1960static const struct pci_device_id azx_ids[] = { 1941static const struct pci_device_id azx_ids[] = {
1961 /* CPT */ 1942 /* CPT */
@@ -2014,10 +1995,10 @@ static const struct pci_device_id azx_ids[] = {
2014 .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_NOPM }, 1995 .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_NOPM },
2015 /* BayTrail */ 1996 /* BayTrail */
2016 { PCI_DEVICE(0x8086, 0x0f04), 1997 { PCI_DEVICE(0x8086, 0x0f04),
2017 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH_NOPM }, 1998 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_BAYTRAIL },
2018 /* Braswell */ 1999 /* Braswell */
2019 { PCI_DEVICE(0x8086, 0x2284), 2000 { PCI_DEVICE(0x8086, 0x2284),
2020 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH }, 2001 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_BRASWELL },
2021 /* ICH6 */ 2002 /* ICH6 */
2022 { PCI_DEVICE(0x8086, 0x2668), 2003 { PCI_DEVICE(0x8086, 0x2668),
2023 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH }, 2004 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH },
@@ -2178,6 +2159,7 @@ static struct pci_driver azx_driver = {
2178 .id_table = azx_ids, 2159 .id_table = azx_ids,
2179 .probe = azx_probe, 2160 .probe = azx_probe,
2180 .remove = azx_remove, 2161 .remove = azx_remove,
2162 .shutdown = azx_shutdown,
2181 .driver = { 2163 .driver = {
2182 .pm = AZX_PM_OPS, 2164 .pm = AZX_PM_OPS,
2183 }, 2165 },
diff --git a/sound/pci/hda/hda_intel.h b/sound/pci/hda/hda_intel.h
index 348611835476..d5231f7216a7 100644
--- a/sound/pci/hda/hda_intel.h
+++ b/sound/pci/hda/hda_intel.h
@@ -17,7 +17,7 @@
17#define __SOUND_HDA_INTEL_H 17#define __SOUND_HDA_INTEL_H
18 18
19#include <drm/i915_component.h> 19#include <drm/i915_component.h>
20#include "hda_priv.h" 20#include "hda_controller.h"
21 21
22struct hda_intel { 22struct hda_intel {
23 struct azx chip; 23 struct azx chip;
diff --git a/sound/pci/hda/hda_jack.c b/sound/pci/hda/hda_jack.c
index e664307617bd..d7cfe7b8c32b 100644
--- a/sound/pci/hda/hda_jack.c
+++ b/sound/pci/hda/hda_jack.c
@@ -135,7 +135,7 @@ void snd_hda_jack_tbl_clear(struct hda_codec *codec)
135#ifdef CONFIG_SND_HDA_INPUT_JACK 135#ifdef CONFIG_SND_HDA_INPUT_JACK
136 /* free jack instances manually when clearing/reconfiguring */ 136 /* free jack instances manually when clearing/reconfiguring */
137 if (!codec->bus->shutdown && jack->jack) 137 if (!codec->bus->shutdown && jack->jack)
138 snd_device_free(codec->bus->card, jack->jack); 138 snd_device_free(codec->card, jack->jack);
139#endif 139#endif
140 for (cb = jack->callback; cb; cb = next) { 140 for (cb = jack->callback; cb; cb = next) {
141 next = cb->next; 141 next = cb->next;
@@ -340,7 +340,7 @@ void snd_hda_jack_report_sync(struct hda_codec *codec)
340 if (!jack->kctl || jack->block_report) 340 if (!jack->kctl || jack->block_report)
341 continue; 341 continue;
342 state = get_jack_plug_state(jack->pin_sense); 342 state = get_jack_plug_state(jack->pin_sense);
343 snd_kctl_jack_report(codec->bus->card, jack->kctl, state); 343 snd_kctl_jack_report(codec->card, jack->kctl, state);
344#ifdef CONFIG_SND_HDA_INPUT_JACK 344#ifdef CONFIG_SND_HDA_INPUT_JACK
345 if (jack->jack) 345 if (jack->jack)
346 snd_jack_report(jack->jack, 346 snd_jack_report(jack->jack,
@@ -412,11 +412,11 @@ static int __snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid,
412 jack->phantom_jack = !!phantom_jack; 412 jack->phantom_jack = !!phantom_jack;
413 413
414 state = snd_hda_jack_detect(codec, nid); 414 state = snd_hda_jack_detect(codec, nid);
415 snd_kctl_jack_report(codec->bus->card, kctl, state); 415 snd_kctl_jack_report(codec->card, kctl, state);
416#ifdef CONFIG_SND_HDA_INPUT_JACK 416#ifdef CONFIG_SND_HDA_INPUT_JACK
417 if (!phantom_jack) { 417 if (!phantom_jack) {
418 jack->type = get_input_jack_type(codec, nid); 418 jack->type = get_input_jack_type(codec, nid);
419 err = snd_jack_new(codec->bus->card, name, jack->type, 419 err = snd_jack_new(codec->card, name, jack->type,
420 &jack->jack); 420 &jack->jack);
421 if (err < 0) 421 if (err < 0)
422 return err; 422 return err;
diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h
index 62658f2f8c9f..3b567f42296b 100644
--- a/sound/pci/hda/hda_local.h
+++ b/sound/pci/hda/hda_local.h
@@ -127,18 +127,16 @@ int snd_hda_mixer_amp_switch_put_beep(struct snd_kcontrol *kcontrol,
127 struct snd_ctl_elem_value *ucontrol); 127 struct snd_ctl_elem_value *ucontrol);
128#endif 128#endif
129/* lowlevel accessor with caching; use carefully */ 129/* lowlevel accessor with caching; use carefully */
130int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch, 130#define snd_hda_codec_amp_read(codec, nid, ch, dir, idx) \
131 int direction, int index); 131 snd_hdac_regmap_get_amp(&(codec)->core, nid, ch, dir, idx)
132int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch, 132#define snd_hda_codec_amp_update(codec, nid, ch, dir, idx, mask, val) \
133 int direction, int idx, int mask, int val); 133 snd_hdac_regmap_update_amp(&(codec)->core, nid, ch, dir, idx, mask, val)
134int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid, 134int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid,
135 int dir, int idx, int mask, int val); 135 int dir, int idx, int mask, int val);
136int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch, 136int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch,
137 int direction, int idx, int mask, int val); 137 int direction, int idx, int mask, int val);
138int snd_hda_codec_amp_init_stereo(struct hda_codec *codec, hda_nid_t nid, 138int snd_hda_codec_amp_init_stereo(struct hda_codec *codec, hda_nid_t nid,
139 int dir, int idx, int mask, int val); 139 int dir, int idx, int mask, int val);
140void snd_hda_codec_resume_amp(struct hda_codec *codec);
141
142void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir, 140void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir,
143 unsigned int *tlv); 141 unsigned int *tlv);
144struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec, 142struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
@@ -150,6 +148,8 @@ int __snd_hda_add_vmaster(struct hda_codec *codec, char *name,
150#define snd_hda_add_vmaster(codec, name, tlv, slaves, suffix) \ 148#define snd_hda_add_vmaster(codec, name, tlv, slaves, suffix) \
151 __snd_hda_add_vmaster(codec, name, tlv, slaves, suffix, true, NULL) 149 __snd_hda_add_vmaster(codec, name, tlv, slaves, suffix, true, NULL)
152int snd_hda_codec_reset(struct hda_codec *codec); 150int snd_hda_codec_reset(struct hda_codec *codec);
151void snd_hda_codec_register(struct hda_codec *codec);
152void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec);
153 153
154enum { 154enum {
155 HDA_VMUTE_OFF, 155 HDA_VMUTE_OFF,
@@ -273,29 +273,6 @@ int snd_hda_add_imux_item(struct hda_codec *codec,
273 int index, int *type_index_ret); 273 int index, int *type_index_ret);
274 274
275/* 275/*
276 * Channel mode helper
277 */
278struct hda_channel_mode {
279 int channels;
280 const struct hda_verb *sequence;
281};
282
283int snd_hda_ch_mode_info(struct hda_codec *codec,
284 struct snd_ctl_elem_info *uinfo,
285 const struct hda_channel_mode *chmode,
286 int num_chmodes);
287int snd_hda_ch_mode_get(struct hda_codec *codec,
288 struct snd_ctl_elem_value *ucontrol,
289 const struct hda_channel_mode *chmode,
290 int num_chmodes,
291 int max_channels);
292int snd_hda_ch_mode_put(struct hda_codec *codec,
293 struct snd_ctl_elem_value *ucontrol,
294 const struct hda_channel_mode *chmode,
295 int num_chmodes,
296 int *max_channelsp);
297
298/*
299 * Multi-channel / digital-out PCM helper 276 * Multi-channel / digital-out PCM helper
300 */ 277 */
301 278
@@ -351,12 +328,6 @@ int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
351 struct hda_multi_out *mout); 328 struct hda_multi_out *mout);
352 329
353/* 330/*
354 * generic codec parser
355 */
356int snd_hda_parse_generic_codec(struct hda_codec *codec);
357int snd_hda_parse_hdmi_codec(struct hda_codec *codec);
358
359/*
360 * generic proc interface 331 * generic proc interface
361 */ 332 */
362#ifdef CONFIG_PROC_FS 333#ifdef CONFIG_PROC_FS
@@ -466,23 +437,6 @@ void snd_hda_pick_pin_fixup(struct hda_codec *codec,
466 const struct snd_hda_pin_quirk *pin_quirk, 437 const struct snd_hda_pin_quirk *pin_quirk,
467 const struct hda_fixup *fixlist); 438 const struct hda_fixup *fixlist);
468 439
469
470/*
471 * unsolicited event handler
472 */
473
474#define HDA_UNSOL_QUEUE_SIZE 64
475
476struct hda_bus_unsolicited {
477 /* ring buffer */
478 u32 queue[HDA_UNSOL_QUEUE_SIZE * 2];
479 unsigned int rp, wp;
480
481 /* workqueue */
482 struct work_struct work;
483 struct hda_bus *bus;
484};
485
486/* helper macros to retrieve pin default-config values */ 440/* helper macros to retrieve pin default-config values */
487#define get_defcfg_connect(cfg) \ 441#define get_defcfg_connect(cfg) \
488 ((cfg & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT) 442 ((cfg & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT)
@@ -560,15 +514,18 @@ int snd_hda_codec_get_pin_target(struct hda_codec *codec, hda_nid_t nid);
560int snd_hda_codec_set_pin_target(struct hda_codec *codec, hda_nid_t nid, 514int snd_hda_codec_set_pin_target(struct hda_codec *codec, hda_nid_t nid,
561 unsigned int val); 515 unsigned int val);
562 516
517#define for_each_hda_codec_node(nid, codec) \
518 for ((nid) = (codec)->core.start_nid; (nid) < (codec)->core.end_nid; (nid)++)
519
563/* 520/*
564 * get widget capabilities 521 * get widget capabilities
565 */ 522 */
566static inline u32 get_wcaps(struct hda_codec *codec, hda_nid_t nid) 523static inline u32 get_wcaps(struct hda_codec *codec, hda_nid_t nid)
567{ 524{
568 if (nid < codec->start_nid || 525 if (nid < codec->core.start_nid ||
569 nid >= codec->start_nid + codec->num_nodes) 526 nid >= codec->core.start_nid + codec->core.num_nodes)
570 return 0; 527 return 0;
571 return codec->wcaps[nid - codec->start_nid]; 528 return codec->wcaps[nid - codec->core.start_nid];
572} 529}
573 530
574/* get the widget type from widget capability bits */ 531/* get the widget type from widget capability bits */
@@ -592,17 +549,49 @@ static inline unsigned int get_wcaps_channels(u32 wcaps)
592static inline void snd_hda_override_wcaps(struct hda_codec *codec, 549static inline void snd_hda_override_wcaps(struct hda_codec *codec,
593 hda_nid_t nid, u32 val) 550 hda_nid_t nid, u32 val)
594{ 551{
595 if (nid >= codec->start_nid && 552 if (nid >= codec->core.start_nid &&
596 nid < codec->start_nid + codec->num_nodes) 553 nid < codec->core.start_nid + codec->core.num_nodes)
597 codec->wcaps[nid - codec->start_nid] = val; 554 codec->wcaps[nid - codec->core.start_nid] = val;
598} 555}
599 556
600u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction); 557u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction);
601int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, 558int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
602 unsigned int caps); 559 unsigned int caps);
603u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid); 560/**
604int snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid, 561 * snd_hda_query_pin_caps - Query PIN capabilities
605 unsigned int caps); 562 * @codec: the HD-auio codec
563 * @nid: the NID to query
564 *
565 * Query PIN capabilities for the given widget.
566 * Returns the obtained capability bits.
567 *
568 * When cap bits have been already read, this doesn't read again but
569 * returns the cached value.
570 */
571static inline u32
572snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid)
573{
574 return snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
575
576}
577
578/**
579 * snd_hda_override_pin_caps - Override the pin capabilities
580 * @codec: the CODEC
581 * @nid: the NID to override
582 * @caps: the capability bits to set
583 *
584 * Override the cached PIN capabilitiy bits value by the given one.
585 *
586 * Returns zero if successful or a negative error code.
587 */
588static inline int
589snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid,
590 unsigned int caps)
591{
592 return snd_hdac_override_parm(&codec->core, nid, AC_PAR_PIN_CAP, caps);
593}
594
606bool snd_hda_check_amp_caps(struct hda_codec *codec, hda_nid_t nid, 595bool snd_hda_check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
607 int dir, unsigned int bits); 596 int dir, unsigned int bits);
608 597
@@ -800,9 +789,13 @@ void snd_print_channel_allocation(int spk_alloc, char *buf, int buflen);
800 789
801/* 790/*
802 */ 791 */
803#define codec_err(codec, fmt, args...) dev_err(&(codec)->dev, fmt, ##args) 792#define codec_err(codec, fmt, args...) \
804#define codec_warn(codec, fmt, args...) dev_warn(&(codec)->dev, fmt, ##args) 793 dev_err(hda_codec_dev(codec), fmt, ##args)
805#define codec_info(codec, fmt, args...) dev_info(&(codec)->dev, fmt, ##args) 794#define codec_warn(codec, fmt, args...) \
806#define codec_dbg(codec, fmt, args...) dev_dbg(&(codec)->dev, fmt, ##args) 795 dev_warn(hda_codec_dev(codec), fmt, ##args)
796#define codec_info(codec, fmt, args...) \
797 dev_info(hda_codec_dev(codec), fmt, ##args)
798#define codec_dbg(codec, fmt, args...) \
799 dev_dbg(hda_codec_dev(codec), fmt, ##args)
807 800
808#endif /* __SOUND_HDA_LOCAL_H */ 801#endif /* __SOUND_HDA_LOCAL_H */
diff --git a/sound/pci/hda/hda_priv.h b/sound/pci/hda/hda_priv.h
deleted file mode 100644
index daf458299753..000000000000
--- a/sound/pci/hda/hda_priv.h
+++ /dev/null
@@ -1,406 +0,0 @@
1/*
2 * Common defines for the alsa driver code base for HD Audio.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation; either version 2 of the License, or (at your option)
7 * any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef __SOUND_HDA_PRIV_H
16#define __SOUND_HDA_PRIV_H
17
18#include <linux/timecounter.h>
19#include <sound/core.h>
20#include <sound/pcm.h>
21
22/*
23 * registers
24 */
25#define AZX_REG_GCAP 0x00
26#define AZX_GCAP_64OK (1 << 0) /* 64bit address support */
27#define AZX_GCAP_NSDO (3 << 1) /* # of serial data out signals */
28#define AZX_GCAP_BSS (31 << 3) /* # of bidirectional streams */
29#define AZX_GCAP_ISS (15 << 8) /* # of input streams */
30#define AZX_GCAP_OSS (15 << 12) /* # of output streams */
31#define AZX_REG_VMIN 0x02
32#define AZX_REG_VMAJ 0x03
33#define AZX_REG_OUTPAY 0x04
34#define AZX_REG_INPAY 0x06
35#define AZX_REG_GCTL 0x08
36#define AZX_GCTL_RESET (1 << 0) /* controller reset */
37#define AZX_GCTL_FCNTRL (1 << 1) /* flush control */
38#define AZX_GCTL_UNSOL (1 << 8) /* accept unsol. response enable */
39#define AZX_REG_WAKEEN 0x0c
40#define AZX_REG_STATESTS 0x0e
41#define AZX_REG_GSTS 0x10
42#define AZX_GSTS_FSTS (1 << 1) /* flush status */
43#define AZX_REG_INTCTL 0x20
44#define AZX_REG_INTSTS 0x24
45#define AZX_REG_WALLCLK 0x30 /* 24Mhz source */
46#define AZX_REG_OLD_SSYNC 0x34 /* SSYNC for old ICH */
47#define AZX_REG_SSYNC 0x38
48#define AZX_REG_CORBLBASE 0x40
49#define AZX_REG_CORBUBASE 0x44
50#define AZX_REG_CORBWP 0x48
51#define AZX_REG_CORBRP 0x4a
52#define AZX_CORBRP_RST (1 << 15) /* read pointer reset */
53#define AZX_REG_CORBCTL 0x4c
54#define AZX_CORBCTL_RUN (1 << 1) /* enable DMA */
55#define AZX_CORBCTL_CMEIE (1 << 0) /* enable memory error irq */
56#define AZX_REG_CORBSTS 0x4d
57#define AZX_CORBSTS_CMEI (1 << 0) /* memory error indication */
58#define AZX_REG_CORBSIZE 0x4e
59
60#define AZX_REG_RIRBLBASE 0x50
61#define AZX_REG_RIRBUBASE 0x54
62#define AZX_REG_RIRBWP 0x58
63#define AZX_RIRBWP_RST (1 << 15) /* write pointer reset */
64#define AZX_REG_RINTCNT 0x5a
65#define AZX_REG_RIRBCTL 0x5c
66#define AZX_RBCTL_IRQ_EN (1 << 0) /* enable IRQ */
67#define AZX_RBCTL_DMA_EN (1 << 1) /* enable DMA */
68#define AZX_RBCTL_OVERRUN_EN (1 << 2) /* enable overrun irq */
69#define AZX_REG_RIRBSTS 0x5d
70#define AZX_RBSTS_IRQ (1 << 0) /* response irq */
71#define AZX_RBSTS_OVERRUN (1 << 2) /* overrun irq */
72#define AZX_REG_RIRBSIZE 0x5e
73
74#define AZX_REG_IC 0x60
75#define AZX_REG_IR 0x64
76#define AZX_REG_IRS 0x68
77#define AZX_IRS_VALID (1<<1)
78#define AZX_IRS_BUSY (1<<0)
79
80#define AZX_REG_DPLBASE 0x70
81#define AZX_REG_DPUBASE 0x74
82#define AZX_DPLBASE_ENABLE 0x1 /* Enable position buffer */
83
84/* SD offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */
85enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
86
87/* stream register offsets from stream base */
88#define AZX_REG_SD_CTL 0x00
89#define AZX_REG_SD_STS 0x03
90#define AZX_REG_SD_LPIB 0x04
91#define AZX_REG_SD_CBL 0x08
92#define AZX_REG_SD_LVI 0x0c
93#define AZX_REG_SD_FIFOW 0x0e
94#define AZX_REG_SD_FIFOSIZE 0x10
95#define AZX_REG_SD_FORMAT 0x12
96#define AZX_REG_SD_BDLPL 0x18
97#define AZX_REG_SD_BDLPU 0x1c
98
99/* PCI space */
100#define AZX_PCIREG_TCSEL 0x44
101
102/*
103 * other constants
104 */
105
106/* max number of fragments - we may use more if allocating more pages for BDL */
107#define BDL_SIZE 4096
108#define AZX_MAX_BDL_ENTRIES (BDL_SIZE / 16)
109#define AZX_MAX_FRAG 32
110/* max buffer size - no h/w limit, you can increase as you like */
111#define AZX_MAX_BUF_SIZE (1024*1024*1024)
112
113/* RIRB int mask: overrun[2], response[0] */
114#define RIRB_INT_RESPONSE 0x01
115#define RIRB_INT_OVERRUN 0x04
116#define RIRB_INT_MASK 0x05
117
118/* STATESTS int mask: S3,SD2,SD1,SD0 */
119#define AZX_MAX_CODECS 8
120#define AZX_DEFAULT_CODECS 4
121#define STATESTS_INT_MASK ((1 << AZX_MAX_CODECS) - 1)
122
123/* SD_CTL bits */
124#define SD_CTL_STREAM_RESET 0x01 /* stream reset bit */
125#define SD_CTL_DMA_START 0x02 /* stream DMA start bit */
126#define SD_CTL_STRIPE (3 << 16) /* stripe control */
127#define SD_CTL_TRAFFIC_PRIO (1 << 18) /* traffic priority */
128#define SD_CTL_DIR (1 << 19) /* bi-directional stream */
129#define SD_CTL_STREAM_TAG_MASK (0xf << 20)
130#define SD_CTL_STREAM_TAG_SHIFT 20
131
132/* SD_CTL and SD_STS */
133#define SD_INT_DESC_ERR 0x10 /* descriptor error interrupt */
134#define SD_INT_FIFO_ERR 0x08 /* FIFO error interrupt */
135#define SD_INT_COMPLETE 0x04 /* completion interrupt */
136#define SD_INT_MASK (SD_INT_DESC_ERR|SD_INT_FIFO_ERR|\
137 SD_INT_COMPLETE)
138
139/* SD_STS */
140#define SD_STS_FIFO_READY 0x20 /* FIFO ready */
141
142/* INTCTL and INTSTS */
143#define AZX_INT_ALL_STREAM 0xff /* all stream interrupts */
144#define AZX_INT_CTRL_EN 0x40000000 /* controller interrupt enable bit */
145#define AZX_INT_GLOBAL_EN 0x80000000 /* global interrupt enable bit */
146
147/* below are so far hardcoded - should read registers in future */
148#define AZX_MAX_CORB_ENTRIES 256
149#define AZX_MAX_RIRB_ENTRIES 256
150
151/* driver quirks (capabilities) */
152/* bits 0-7 are used for indicating driver type */
153#define AZX_DCAPS_NO_TCSEL (1 << 8) /* No Intel TCSEL bit */
154#define AZX_DCAPS_NO_MSI (1 << 9) /* No MSI support */
155#define AZX_DCAPS_SNOOP_MASK (3 << 10) /* snoop type mask */
156#define AZX_DCAPS_SNOOP_OFF (1 << 12) /* snoop default off */
157#define AZX_DCAPS_RIRB_DELAY (1 << 13) /* Long delay in read loop */
158#define AZX_DCAPS_RIRB_PRE_DELAY (1 << 14) /* Put a delay before read */
159#define AZX_DCAPS_CTX_WORKAROUND (1 << 15) /* X-Fi workaround */
160#define AZX_DCAPS_POSFIX_LPIB (1 << 16) /* Use LPIB as default */
161#define AZX_DCAPS_POSFIX_VIA (1 << 17) /* Use VIACOMBO as default */
162#define AZX_DCAPS_NO_64BIT (1 << 18) /* No 64bit address */
163#define AZX_DCAPS_SYNC_WRITE (1 << 19) /* sync each cmd write */
164#define AZX_DCAPS_OLD_SSYNC (1 << 20) /* Old SSYNC reg for ICH */
165#define AZX_DCAPS_NO_ALIGN_BUFSIZE (1 << 21) /* no buffer size alignment */
166/* 22 unused */
167#define AZX_DCAPS_4K_BDLE_BOUNDARY (1 << 23) /* BDLE in 4k boundary */
168#define AZX_DCAPS_REVERSE_ASSIGN (1 << 24) /* Assign devices in reverse order */
169#define AZX_DCAPS_COUNT_LPIB_DELAY (1 << 25) /* Take LPIB as delay */
170#define AZX_DCAPS_PM_RUNTIME (1 << 26) /* runtime PM support */
171#define AZX_DCAPS_I915_POWERWELL (1 << 27) /* HSW i915 powerwell support */
172#define AZX_DCAPS_CORBRP_SELF_CLEAR (1 << 28) /* CORBRP clears itself after reset */
173#define AZX_DCAPS_NO_MSI64 (1 << 29) /* Stick to 32-bit MSIs */
174#define AZX_DCAPS_SEPARATE_STREAM_TAG (1 << 30) /* capture and playback use separate stream tag */
175
176enum {
177 AZX_SNOOP_TYPE_NONE ,
178 AZX_SNOOP_TYPE_SCH,
179 AZX_SNOOP_TYPE_ATI,
180 AZX_SNOOP_TYPE_NVIDIA,
181};
182
183/* HD Audio class code */
184#define PCI_CLASS_MULTIMEDIA_HD_AUDIO 0x0403
185
186struct azx_dev {
187 struct snd_dma_buffer bdl; /* BDL buffer */
188 u32 *posbuf; /* position buffer pointer */
189
190 unsigned int bufsize; /* size of the play buffer in bytes */
191 unsigned int period_bytes; /* size of the period in bytes */
192 unsigned int frags; /* number for period in the play buffer */
193 unsigned int fifo_size; /* FIFO size */
194 unsigned long start_wallclk; /* start + minimum wallclk */
195 unsigned long period_wallclk; /* wallclk for period */
196
197 void __iomem *sd_addr; /* stream descriptor pointer */
198
199 u32 sd_int_sta_mask; /* stream int status mask */
200
201 /* pcm support */
202 struct snd_pcm_substream *substream; /* assigned substream,
203 * set in PCM open
204 */
205 unsigned int format_val; /* format value to be set in the
206 * controller and the codec
207 */
208 unsigned char stream_tag; /* assigned stream */
209 unsigned char index; /* stream index */
210 int assigned_key; /* last device# key assigned to */
211
212 unsigned int opened:1;
213 unsigned int running:1;
214 unsigned int irq_pending:1;
215 unsigned int prepared:1;
216 unsigned int locked:1;
217 /*
218 * For VIA:
219 * A flag to ensure DMA position is 0
220 * when link position is not greater than FIFO size
221 */
222 unsigned int insufficient:1;
223 unsigned int wc_marked:1;
224 unsigned int no_period_wakeup:1;
225
226 struct timecounter azx_tc;
227 struct cyclecounter azx_cc;
228
229 int delay_negative_threshold;
230
231#ifdef CONFIG_SND_HDA_DSP_LOADER
232 /* Allows dsp load to have sole access to the playback stream. */
233 struct mutex dsp_mutex;
234#endif
235};
236
237/* CORB/RIRB */
238struct azx_rb {
239 u32 *buf; /* CORB/RIRB buffer
240 * Each CORB entry is 4byte, RIRB is 8byte
241 */
242 dma_addr_t addr; /* physical address of CORB/RIRB buffer */
243 /* for RIRB */
244 unsigned short rp, wp; /* read/write pointers */
245 int cmds[AZX_MAX_CODECS]; /* number of pending requests */
246 u32 res[AZX_MAX_CODECS]; /* last read value */
247};
248
249struct azx;
250
251/* Functions to read/write to hda registers. */
252struct hda_controller_ops {
253 /* Register Access */
254 void (*reg_writel)(u32 value, u32 __iomem *addr);
255 u32 (*reg_readl)(u32 __iomem *addr);
256 void (*reg_writew)(u16 value, u16 __iomem *addr);
257 u16 (*reg_readw)(u16 __iomem *addr);
258 void (*reg_writeb)(u8 value, u8 __iomem *addr);
259 u8 (*reg_readb)(u8 __iomem *addr);
260 /* Disable msi if supported, PCI only */
261 int (*disable_msi_reset_irq)(struct azx *);
262 /* Allocation ops */
263 int (*dma_alloc_pages)(struct azx *chip,
264 int type,
265 size_t size,
266 struct snd_dma_buffer *buf);
267 void (*dma_free_pages)(struct azx *chip, struct snd_dma_buffer *buf);
268 int (*substream_alloc_pages)(struct azx *chip,
269 struct snd_pcm_substream *substream,
270 size_t size);
271 int (*substream_free_pages)(struct azx *chip,
272 struct snd_pcm_substream *substream);
273 void (*pcm_mmap_prepare)(struct snd_pcm_substream *substream,
274 struct vm_area_struct *area);
275 /* Check if current position is acceptable */
276 int (*position_check)(struct azx *chip, struct azx_dev *azx_dev);
277};
278
279struct azx_pcm {
280 struct azx *chip;
281 struct snd_pcm *pcm;
282 struct hda_codec *codec;
283 struct hda_pcm_stream *hinfo[2];
284 struct list_head list;
285};
286
287typedef unsigned int (*azx_get_pos_callback_t)(struct azx *, struct azx_dev *);
288typedef int (*azx_get_delay_callback_t)(struct azx *, struct azx_dev *, unsigned int pos);
289
290struct azx {
291 struct snd_card *card;
292 struct pci_dev *pci;
293 int dev_index;
294
295 /* chip type specific */
296 int driver_type;
297 unsigned int driver_caps;
298 int playback_streams;
299 int playback_index_offset;
300 int capture_streams;
301 int capture_index_offset;
302 int num_streams;
303 const int *jackpoll_ms; /* per-card jack poll interval */
304
305 /* Register interaction. */
306 const struct hda_controller_ops *ops;
307
308 /* position adjustment callbacks */
309 azx_get_pos_callback_t get_position[2];
310 azx_get_delay_callback_t get_delay[2];
311
312 /* pci resources */
313 unsigned long addr;
314 void __iomem *remap_addr;
315 int irq;
316
317 /* locks */
318 spinlock_t reg_lock;
319 struct mutex open_mutex; /* Prevents concurrent open/close operations */
320
321 /* streams (x num_streams) */
322 struct azx_dev *azx_dev;
323
324 /* PCM */
325 struct list_head pcm_list; /* azx_pcm list */
326
327 /* HD codec */
328 unsigned short codec_mask;
329 int codec_probe_mask; /* copied from probe_mask option */
330 struct hda_bus *bus;
331 unsigned int beep_mode;
332
333 /* CORB/RIRB */
334 struct azx_rb corb;
335 struct azx_rb rirb;
336
337 /* CORB/RIRB and position buffers */
338 struct snd_dma_buffer rb;
339 struct snd_dma_buffer posbuf;
340
341#ifdef CONFIG_SND_HDA_PATCH_LOADER
342 const struct firmware *fw;
343#endif
344
345 /* flags */
346 const int *bdl_pos_adj;
347 int poll_count;
348 unsigned int running:1;
349 unsigned int initialized:1;
350 unsigned int single_cmd:1;
351 unsigned int polling_mode:1;
352 unsigned int msi:1;
353 unsigned int probing:1; /* codec probing phase */
354 unsigned int snoop:1;
355 unsigned int align_buffer_size:1;
356 unsigned int region_requested:1;
357 unsigned int disabled:1; /* disabled by VGA-switcher */
358
359 /* for debugging */
360 unsigned int last_cmd[AZX_MAX_CODECS];
361
362 /* reboot notifier (for mysterious hangup problem at power-down) */
363 struct notifier_block reboot_notifier;
364
365#ifdef CONFIG_SND_HDA_DSP_LOADER
366 struct azx_dev saved_azx_dev;
367#endif
368};
369
370#ifdef CONFIG_X86
371#define azx_snoop(chip) ((chip)->snoop)
372#else
373#define azx_snoop(chip) true
374#endif
375
376/*
377 * macros for easy use
378 */
379
380#define azx_writel(chip, reg, value) \
381 ((chip)->ops->reg_writel(value, (chip)->remap_addr + AZX_REG_##reg))
382#define azx_readl(chip, reg) \
383 ((chip)->ops->reg_readl((chip)->remap_addr + AZX_REG_##reg))
384#define azx_writew(chip, reg, value) \
385 ((chip)->ops->reg_writew(value, (chip)->remap_addr + AZX_REG_##reg))
386#define azx_readw(chip, reg) \
387 ((chip)->ops->reg_readw((chip)->remap_addr + AZX_REG_##reg))
388#define azx_writeb(chip, reg, value) \
389 ((chip)->ops->reg_writeb(value, (chip)->remap_addr + AZX_REG_##reg))
390#define azx_readb(chip, reg) \
391 ((chip)->ops->reg_readb((chip)->remap_addr + AZX_REG_##reg))
392
393#define azx_sd_writel(chip, dev, reg, value) \
394 ((chip)->ops->reg_writel(value, (dev)->sd_addr + AZX_REG_##reg))
395#define azx_sd_readl(chip, dev, reg) \
396 ((chip)->ops->reg_readl((dev)->sd_addr + AZX_REG_##reg))
397#define azx_sd_writew(chip, dev, reg, value) \
398 ((chip)->ops->reg_writew(value, (dev)->sd_addr + AZX_REG_##reg))
399#define azx_sd_readw(chip, dev, reg) \
400 ((chip)->ops->reg_readw((dev)->sd_addr + AZX_REG_##reg))
401#define azx_sd_writeb(chip, dev, reg, value) \
402 ((chip)->ops->reg_writeb(value, (dev)->sd_addr + AZX_REG_##reg))
403#define azx_sd_readb(chip, dev, reg) \
404 ((chip)->ops->reg_readb((dev)->sd_addr + AZX_REG_##reg))
405
406#endif /* __SOUND_HDA_PRIV_H */
diff --git a/sound/pci/hda/hda_proc.c b/sound/pci/hda/hda_proc.c
index 05e19f78b4cb..baaf7ed06875 100644
--- a/sound/pci/hda/hda_proc.c
+++ b/sound/pci/hda/hda_proc.c
@@ -32,6 +32,10 @@ static int dump_coef = -1;
32module_param(dump_coef, int, 0644); 32module_param(dump_coef, int, 0644);
33MODULE_PARM_DESC(dump_coef, "Dump processing coefficients in codec proc file (-1=auto, 0=disable, 1=enable)"); 33MODULE_PARM_DESC(dump_coef, "Dump processing coefficients in codec proc file (-1=auto, 0=disable, 1=enable)");
34 34
35/* always use noncached version */
36#define param_read(codec, nid, parm) \
37 snd_hdac_read_parm_uncached(&(codec)->core, nid, parm)
38
35static char *bits_names(unsigned int bits, char *names[], int size) 39static char *bits_names(unsigned int bits, char *names[], int size)
36{ 40{
37 int i, n; 41 int i, n;
@@ -99,10 +103,10 @@ static void print_nid_array(struct snd_info_buffer *buffer,
99static void print_nid_pcms(struct snd_info_buffer *buffer, 103static void print_nid_pcms(struct snd_info_buffer *buffer,
100 struct hda_codec *codec, hda_nid_t nid) 104 struct hda_codec *codec, hda_nid_t nid)
101{ 105{
102 int pcm, type; 106 int type;
103 struct hda_pcm *cpcm; 107 struct hda_pcm *cpcm;
104 for (pcm = 0; pcm < codec->num_pcms; pcm++) { 108
105 cpcm = &codec->pcm_info[pcm]; 109 list_for_each_entry(cpcm, &codec->pcm_list_head, list) {
106 for (type = 0; type < 2; type++) { 110 for (type = 0; type < 2; type++) {
107 if (cpcm->stream[type].nid != nid || cpcm->pcm == NULL) 111 if (cpcm->stream[type].nid != nid || cpcm->pcm == NULL)
108 continue; 112 continue;
@@ -119,9 +123,8 @@ static void print_amp_caps(struct snd_info_buffer *buffer,
119 struct hda_codec *codec, hda_nid_t nid, int dir) 123 struct hda_codec *codec, hda_nid_t nid, int dir)
120{ 124{
121 unsigned int caps; 125 unsigned int caps;
122 caps = snd_hda_param_read(codec, nid, 126 caps = param_read(codec, nid, dir == HDA_OUTPUT ?
123 dir == HDA_OUTPUT ? 127 AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP);
124 AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP);
125 if (caps == -1 || caps == 0) { 128 if (caps == -1 || caps == 0) {
126 snd_iprintf(buffer, "N/A\n"); 129 snd_iprintf(buffer, "N/A\n");
127 return; 130 return;
@@ -225,8 +228,8 @@ static void print_pcm_formats(struct snd_info_buffer *buffer,
225static void print_pcm_caps(struct snd_info_buffer *buffer, 228static void print_pcm_caps(struct snd_info_buffer *buffer,
226 struct hda_codec *codec, hda_nid_t nid) 229 struct hda_codec *codec, hda_nid_t nid)
227{ 230{
228 unsigned int pcm = snd_hda_param_read(codec, nid, AC_PAR_PCM); 231 unsigned int pcm = param_read(codec, nid, AC_PAR_PCM);
229 unsigned int stream = snd_hda_param_read(codec, nid, AC_PAR_STREAM); 232 unsigned int stream = param_read(codec, nid, AC_PAR_STREAM);
230 if (pcm == -1 || stream == -1) { 233 if (pcm == -1 || stream == -1) {
231 snd_iprintf(buffer, "N/A\n"); 234 snd_iprintf(buffer, "N/A\n");
232 return; 235 return;
@@ -273,7 +276,7 @@ static void print_pin_caps(struct snd_info_buffer *buffer,
273 static char *jack_conns[4] = { "Jack", "N/A", "Fixed", "Both" }; 276 static char *jack_conns[4] = { "Jack", "N/A", "Fixed", "Both" };
274 unsigned int caps, val; 277 unsigned int caps, val;
275 278
276 caps = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP); 279 caps = param_read(codec, nid, AC_PAR_PIN_CAP);
277 snd_iprintf(buffer, " Pincap 0x%08x:", caps); 280 snd_iprintf(buffer, " Pincap 0x%08x:", caps);
278 if (caps & AC_PINCAP_IN) 281 if (caps & AC_PINCAP_IN)
279 snd_iprintf(buffer, " IN"); 282 snd_iprintf(buffer, " IN");
@@ -289,7 +292,7 @@ static void print_pin_caps(struct snd_info_buffer *buffer,
289 snd_iprintf(buffer, " Balanced"); 292 snd_iprintf(buffer, " Balanced");
290 if (caps & AC_PINCAP_HDMI) { 293 if (caps & AC_PINCAP_HDMI) {
291 /* Realtek uses this bit as a different meaning */ 294 /* Realtek uses this bit as a different meaning */
292 if ((codec->vendor_id >> 16) == 0x10ec) 295 if ((codec->core.vendor_id >> 16) == 0x10ec)
293 snd_iprintf(buffer, " R/L"); 296 snd_iprintf(buffer, " R/L");
294 else { 297 else {
295 if (caps & AC_PINCAP_HBR) 298 if (caps & AC_PINCAP_HBR)
@@ -401,8 +404,7 @@ static void print_pin_ctls(struct snd_info_buffer *buffer,
401static void print_vol_knob(struct snd_info_buffer *buffer, 404static void print_vol_knob(struct snd_info_buffer *buffer,
402 struct hda_codec *codec, hda_nid_t nid) 405 struct hda_codec *codec, hda_nid_t nid)
403{ 406{
404 unsigned int cap = snd_hda_param_read(codec, nid, 407 unsigned int cap = param_read(codec, nid, AC_PAR_VOL_KNB_CAP);
405 AC_PAR_VOL_KNB_CAP);
406 snd_iprintf(buffer, " Volume-Knob: delta=%d, steps=%d, ", 408 snd_iprintf(buffer, " Volume-Knob: delta=%d, steps=%d, ",
407 (cap >> 7) & 1, cap & 0x7f); 409 (cap >> 7) & 1, cap & 0x7f);
408 cap = snd_hda_codec_read(codec, nid, 0, 410 cap = snd_hda_codec_read(codec, nid, 0,
@@ -487,7 +489,7 @@ static void print_power_state(struct snd_info_buffer *buffer,
487 [ilog2(AC_PWRST_EPSS)] = "EPSS", 489 [ilog2(AC_PWRST_EPSS)] = "EPSS",
488 }; 490 };
489 491
490 int sup = snd_hda_param_read(codec, nid, AC_PAR_POWER_STATE); 492 int sup = param_read(codec, nid, AC_PAR_POWER_STATE);
491 int pwr = snd_hda_codec_read(codec, nid, 0, 493 int pwr = snd_hda_codec_read(codec, nid, 0,
492 AC_VERB_GET_POWER_STATE, 0); 494 AC_VERB_GET_POWER_STATE, 0);
493 if (sup != -1) 495 if (sup != -1)
@@ -531,8 +533,7 @@ static void print_proc_caps(struct snd_info_buffer *buffer,
531 struct hda_codec *codec, hda_nid_t nid) 533 struct hda_codec *codec, hda_nid_t nid)
532{ 534{
533 unsigned int i, ncoeff, oldindex; 535 unsigned int i, ncoeff, oldindex;
534 unsigned int proc_caps = snd_hda_param_read(codec, nid, 536 unsigned int proc_caps = param_read(codec, nid, AC_PAR_PROC_CAP);
535 AC_PAR_PROC_CAP);
536 ncoeff = (proc_caps & AC_PCAP_NUM_COEF) >> AC_PCAP_NUM_COEF_SHIFT; 537 ncoeff = (proc_caps & AC_PCAP_NUM_COEF) >> AC_PCAP_NUM_COEF_SHIFT;
537 snd_iprintf(buffer, " Processing caps: benign=%d, ncoeff=%d\n", 538 snd_iprintf(buffer, " Processing caps: benign=%d, ncoeff=%d\n",
538 proc_caps & AC_PCAP_BENIGN, ncoeff); 539 proc_caps & AC_PCAP_BENIGN, ncoeff);
@@ -581,8 +582,8 @@ static void print_conn_list(struct snd_info_buffer *buffer,
581 582
582 /* Get Cache connections info */ 583 /* Get Cache connections info */
583 cache_len = snd_hda_get_conn_list(codec, nid, &list); 584 cache_len = snd_hda_get_conn_list(codec, nid, &list);
584 if (cache_len != conn_len 585 if (cache_len >= 0 && (cache_len != conn_len ||
585 || memcmp(list, conn, conn_len)) { 586 memcmp(list, conn, conn_len) != 0)) {
586 snd_iprintf(buffer, " In-driver Connection: %d\n", cache_len); 587 snd_iprintf(buffer, " In-driver Connection: %d\n", cache_len);
587 if (cache_len > 0) { 588 if (cache_len > 0) {
588 snd_iprintf(buffer, " "); 589 snd_iprintf(buffer, " ");
@@ -597,7 +598,7 @@ static void print_gpio(struct snd_info_buffer *buffer,
597 struct hda_codec *codec, hda_nid_t nid) 598 struct hda_codec *codec, hda_nid_t nid)
598{ 599{
599 unsigned int gpio = 600 unsigned int gpio =
600 snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP); 601 param_read(codec, codec->core.afg, AC_PAR_GPIO_CAP);
601 unsigned int enable, direction, wake, unsol, sticky, data; 602 unsigned int enable, direction, wake, unsol, sticky, data;
602 int i, max; 603 int i, max;
603 snd_iprintf(buffer, "GPIO: io=%d, o=%d, i=%d, " 604 snd_iprintf(buffer, "GPIO: io=%d, o=%d, i=%d, "
@@ -667,13 +668,9 @@ static void print_device_list(struct snd_info_buffer *buffer,
667 } 668 }
668} 669}
669 670
670static void print_codec_info(struct snd_info_entry *entry, 671static void print_codec_core_info(struct hdac_device *codec,
671 struct snd_info_buffer *buffer) 672 struct snd_info_buffer *buffer)
672{ 673{
673 struct hda_codec *codec = entry->private_data;
674 hda_nid_t nid;
675 int i, nodes;
676
677 snd_iprintf(buffer, "Codec: "); 674 snd_iprintf(buffer, "Codec: ");
678 if (codec->vendor_name && codec->chip_name) 675 if (codec->vendor_name && codec->chip_name)
679 snd_iprintf(buffer, "%s %s\n", 676 snd_iprintf(buffer, "%s %s\n",
@@ -695,34 +692,43 @@ static void print_codec_info(struct snd_info_entry *entry,
695 snd_iprintf(buffer, "Modem Function Group: 0x%x\n", codec->mfg); 692 snd_iprintf(buffer, "Modem Function Group: 0x%x\n", codec->mfg);
696 else 693 else
697 snd_iprintf(buffer, "No Modem Function Group found\n"); 694 snd_iprintf(buffer, "No Modem Function Group found\n");
695}
696
697static void print_codec_info(struct snd_info_entry *entry,
698 struct snd_info_buffer *buffer)
699{
700 struct hda_codec *codec = entry->private_data;
701 hda_nid_t nid, fg;
702 int i, nodes;
698 703
699 if (! codec->afg) 704 print_codec_core_info(&codec->core, buffer);
705 fg = codec->core.afg;
706 if (!fg)
700 return; 707 return;
701 snd_hda_power_up(codec); 708 snd_hda_power_up(codec);
702 snd_iprintf(buffer, "Default PCM:\n"); 709 snd_iprintf(buffer, "Default PCM:\n");
703 print_pcm_caps(buffer, codec, codec->afg); 710 print_pcm_caps(buffer, codec, fg);
704 snd_iprintf(buffer, "Default Amp-In caps: "); 711 snd_iprintf(buffer, "Default Amp-In caps: ");
705 print_amp_caps(buffer, codec, codec->afg, HDA_INPUT); 712 print_amp_caps(buffer, codec, fg, HDA_INPUT);
706 snd_iprintf(buffer, "Default Amp-Out caps: "); 713 snd_iprintf(buffer, "Default Amp-Out caps: ");
707 print_amp_caps(buffer, codec, codec->afg, HDA_OUTPUT); 714 print_amp_caps(buffer, codec, fg, HDA_OUTPUT);
708 snd_iprintf(buffer, "State of AFG node 0x%02x:\n", codec->afg); 715 snd_iprintf(buffer, "State of AFG node 0x%02x:\n", fg);
709 print_power_state(buffer, codec, codec->afg); 716 print_power_state(buffer, codec, fg);
710 717
711 nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid); 718 nodes = snd_hda_get_sub_nodes(codec, fg, &nid);
712 if (! nid || nodes < 0) { 719 if (! nid || nodes < 0) {
713 snd_iprintf(buffer, "Invalid AFG subtree\n"); 720 snd_iprintf(buffer, "Invalid AFG subtree\n");
714 snd_hda_power_down(codec); 721 snd_hda_power_down(codec);
715 return; 722 return;
716 } 723 }
717 724
718 print_gpio(buffer, codec, codec->afg); 725 print_gpio(buffer, codec, fg);
719 if (codec->proc_widget_hook) 726 if (codec->proc_widget_hook)
720 codec->proc_widget_hook(buffer, codec, codec->afg); 727 codec->proc_widget_hook(buffer, codec, fg);
721 728
722 for (i = 0; i < nodes; i++, nid++) { 729 for (i = 0; i < nodes; i++, nid++) {
723 unsigned int wid_caps = 730 unsigned int wid_caps =
724 snd_hda_param_read(codec, nid, 731 param_read(codec, nid, AC_PAR_AUDIO_WIDGET_CAP);
725 AC_PAR_AUDIO_WIDGET_CAP);
726 unsigned int wid_type = get_wcaps_type(wid_caps); 732 unsigned int wid_type = get_wcaps_type(wid_caps);
727 hda_nid_t *conn = NULL; 733 hda_nid_t *conn = NULL;
728 int conn_len = 0; 734 int conn_len = 0;
@@ -860,8 +866,8 @@ int snd_hda_codec_proc_new(struct hda_codec *codec)
860 struct snd_info_entry *entry; 866 struct snd_info_entry *entry;
861 int err; 867 int err;
862 868
863 snprintf(name, sizeof(name), "codec#%d", codec->addr); 869 snprintf(name, sizeof(name), "codec#%d", codec->core.addr);
864 err = snd_card_proc_new(codec->bus->card, name, &entry); 870 err = snd_card_proc_new(codec->card, name, &entry);
865 if (err < 0) 871 if (err < 0)
866 return err; 872 return err;
867 873
diff --git a/sound/pci/hda/hda_sysfs.c b/sound/pci/hda/hda_sysfs.c
index ccc962a1699f..a6e3d9b511ab 100644
--- a/sound/pci/hda/hda_sysfs.c
+++ b/sound/pci/hda/hda_sysfs.c
@@ -48,33 +48,33 @@ static DEVICE_ATTR_RO(power_on_acct);
48static DEVICE_ATTR_RO(power_off_acct); 48static DEVICE_ATTR_RO(power_off_acct);
49#endif /* CONFIG_PM */ 49#endif /* CONFIG_PM */
50 50
51#define CODEC_INFO_SHOW(type) \ 51#define CODEC_INFO_SHOW(type, field) \
52static ssize_t type##_show(struct device *dev, \ 52static ssize_t type##_show(struct device *dev, \
53 struct device_attribute *attr, \ 53 struct device_attribute *attr, \
54 char *buf) \ 54 char *buf) \
55{ \ 55{ \
56 struct hda_codec *codec = dev_get_drvdata(dev); \ 56 struct hda_codec *codec = dev_get_drvdata(dev); \
57 return sprintf(buf, "0x%x\n", codec->type); \ 57 return sprintf(buf, "0x%x\n", codec->field); \
58} 58}
59 59
60#define CODEC_INFO_STR_SHOW(type) \ 60#define CODEC_INFO_STR_SHOW(type, field) \
61static ssize_t type##_show(struct device *dev, \ 61static ssize_t type##_show(struct device *dev, \
62 struct device_attribute *attr, \ 62 struct device_attribute *attr, \
63 char *buf) \ 63 char *buf) \
64{ \ 64{ \
65 struct hda_codec *codec = dev_get_drvdata(dev); \ 65 struct hda_codec *codec = dev_get_drvdata(dev); \
66 return sprintf(buf, "%s\n", \ 66 return sprintf(buf, "%s\n", \
67 codec->type ? codec->type : ""); \ 67 codec->field ? codec->field : ""); \
68} 68}
69 69
70CODEC_INFO_SHOW(vendor_id); 70CODEC_INFO_SHOW(vendor_id, core.vendor_id);
71CODEC_INFO_SHOW(subsystem_id); 71CODEC_INFO_SHOW(subsystem_id, core.subsystem_id);
72CODEC_INFO_SHOW(revision_id); 72CODEC_INFO_SHOW(revision_id, core.revision_id);
73CODEC_INFO_SHOW(afg); 73CODEC_INFO_SHOW(afg, core.afg);
74CODEC_INFO_SHOW(mfg); 74CODEC_INFO_SHOW(mfg, core.mfg);
75CODEC_INFO_STR_SHOW(vendor_name); 75CODEC_INFO_STR_SHOW(vendor_name, core.vendor_name);
76CODEC_INFO_STR_SHOW(chip_name); 76CODEC_INFO_STR_SHOW(chip_name, core.chip_name);
77CODEC_INFO_STR_SHOW(modelname); 77CODEC_INFO_STR_SHOW(modelname, modelname);
78 78
79static ssize_t pin_configs_show(struct hda_codec *codec, 79static ssize_t pin_configs_show(struct hda_codec *codec,
80 struct snd_array *list, 80 struct snd_array *list,
@@ -149,7 +149,7 @@ static int reconfig_codec(struct hda_codec *codec)
149 err = snd_hda_codec_build_controls(codec); 149 err = snd_hda_codec_build_controls(codec);
150 if (err < 0) 150 if (err < 0)
151 goto error; 151 goto error;
152 err = snd_card_register(codec->bus->card); 152 err = snd_card_register(codec->card);
153 error: 153 error:
154 snd_hda_power_down(codec); 154 snd_hda_power_down(codec);
155 return err; 155 return err;
@@ -170,7 +170,7 @@ static char *kstrndup_noeol(const char *src, size_t len)
170 return s; 170 return s;
171} 171}
172 172
173#define CODEC_INFO_STORE(type) \ 173#define CODEC_INFO_STORE(type, field) \
174static ssize_t type##_store(struct device *dev, \ 174static ssize_t type##_store(struct device *dev, \
175 struct device_attribute *attr, \ 175 struct device_attribute *attr, \
176 const char *buf, size_t count) \ 176 const char *buf, size_t count) \
@@ -180,11 +180,11 @@ static ssize_t type##_store(struct device *dev, \
180 int err = kstrtoul(buf, 0, &val); \ 180 int err = kstrtoul(buf, 0, &val); \
181 if (err < 0) \ 181 if (err < 0) \
182 return err; \ 182 return err; \
183 codec->type = val; \ 183 codec->field = val; \
184 return count; \ 184 return count; \
185} 185}
186 186
187#define CODEC_INFO_STR_STORE(type) \ 187#define CODEC_INFO_STR_STORE(type, field) \
188static ssize_t type##_store(struct device *dev, \ 188static ssize_t type##_store(struct device *dev, \
189 struct device_attribute *attr, \ 189 struct device_attribute *attr, \
190 const char *buf, size_t count) \ 190 const char *buf, size_t count) \
@@ -193,17 +193,17 @@ static ssize_t type##_store(struct device *dev, \
193 char *s = kstrndup_noeol(buf, 64); \ 193 char *s = kstrndup_noeol(buf, 64); \
194 if (!s) \ 194 if (!s) \
195 return -ENOMEM; \ 195 return -ENOMEM; \
196 kfree(codec->type); \ 196 kfree(codec->field); \
197 codec->type = s; \ 197 codec->field = s; \
198 return count; \ 198 return count; \
199} 199}
200 200
201CODEC_INFO_STORE(vendor_id); 201CODEC_INFO_STORE(vendor_id, core.vendor_id);
202CODEC_INFO_STORE(subsystem_id); 202CODEC_INFO_STORE(subsystem_id, core.subsystem_id);
203CODEC_INFO_STORE(revision_id); 203CODEC_INFO_STORE(revision_id, core.revision_id);
204CODEC_INFO_STR_STORE(vendor_name); 204CODEC_INFO_STR_STORE(vendor_name, core.vendor_name);
205CODEC_INFO_STR_STORE(chip_name); 205CODEC_INFO_STR_STORE(chip_name, core.chip_name);
206CODEC_INFO_STR_STORE(modelname); 206CODEC_INFO_STR_STORE(modelname, modelname);
207 207
208#define CODEC_ACTION_STORE(type) \ 208#define CODEC_ACTION_STORE(type) \
209static ssize_t type##_store(struct device *dev, \ 209static ssize_t type##_store(struct device *dev, \
@@ -552,10 +552,10 @@ static void parse_codec_mode(char *buf, struct hda_bus *bus,
552 552
553 *codecp = NULL; 553 *codecp = NULL;
554 if (sscanf(buf, "%i %i %i", &vendorid, &subid, &caddr) == 3) { 554 if (sscanf(buf, "%i %i %i", &vendorid, &subid, &caddr) == 3) {
555 list_for_each_entry(codec, &bus->codec_list, list) { 555 list_for_each_codec(codec, bus) {
556 if ((vendorid <= 0 || codec->vendor_id == vendorid) && 556 if ((vendorid <= 0 || codec->core.vendor_id == vendorid) &&
557 (subid <= 0 || codec->subsystem_id == subid) && 557 (subid <= 0 || codec->core.subsystem_id == subid) &&
558 codec->addr == caddr) { 558 codec->core.addr == caddr) {
559 *codecp = codec; 559 *codecp = codec;
560 break; 560 break;
561 } 561 }
@@ -595,8 +595,8 @@ static void parse_model_mode(char *buf, struct hda_bus *bus,
595static void parse_chip_name_mode(char *buf, struct hda_bus *bus, 595static void parse_chip_name_mode(char *buf, struct hda_bus *bus,
596 struct hda_codec **codecp) 596 struct hda_codec **codecp)
597{ 597{
598 kfree((*codecp)->chip_name); 598 kfree((*codecp)->core.chip_name);
599 (*codecp)->chip_name = kstrdup(buf, GFP_KERNEL); 599 (*codecp)->core.chip_name = kstrdup(buf, GFP_KERNEL);
600} 600}
601 601
602#define DEFINE_PARSE_ID_MODE(name) \ 602#define DEFINE_PARSE_ID_MODE(name) \
@@ -605,7 +605,7 @@ static void parse_##name##_mode(char *buf, struct hda_bus *bus, \
605{ \ 605{ \
606 unsigned long val; \ 606 unsigned long val; \
607 if (!kstrtoul(buf, 0, &val)) \ 607 if (!kstrtoul(buf, 0, &val)) \
608 (*codecp)->name = val; \ 608 (*codecp)->core.name = val; \
609} 609}
610 610
611DEFINE_PARSE_ID_MODE(vendor_id); 611DEFINE_PARSE_ID_MODE(vendor_id);
diff --git a/sound/pci/hda/hda_tegra.c b/sound/pci/hda/hda_tegra.c
index 375e94f4cf52..2e4fd5c56d3b 100644
--- a/sound/pci/hda/hda_tegra.c
+++ b/sound/pci/hda/hda_tegra.c
@@ -37,7 +37,6 @@
37 37
38#include "hda_codec.h" 38#include "hda_codec.h"
39#include "hda_controller.h" 39#include "hda_controller.h"
40#include "hda_priv.h"
41 40
42/* Defines for Nvidia Tegra HDA support */ 41/* Defines for Nvidia Tegra HDA support */
43#define HDA_BAR0 0x8000 42#define HDA_BAR0 0x8000
@@ -82,7 +81,7 @@ module_param(power_save, bint, 0644);
82MODULE_PARM_DESC(power_save, 81MODULE_PARM_DESC(power_save,
83 "Automatic power-saving timeout (in seconds, 0 = disable)."); 82 "Automatic power-saving timeout (in seconds, 0 = disable).");
84#else 83#else
85static int power_save = 0; 84#define power_save 0
86#endif 85#endif
87 86
88/* 87/*
@@ -250,14 +249,9 @@ static int hda_tegra_suspend(struct device *dev)
250{ 249{
251 struct snd_card *card = dev_get_drvdata(dev); 250 struct snd_card *card = dev_get_drvdata(dev);
252 struct azx *chip = card->private_data; 251 struct azx *chip = card->private_data;
253 struct azx_pcm *p;
254 struct hda_tegra *hda = container_of(chip, struct hda_tegra, chip); 252 struct hda_tegra *hda = container_of(chip, struct hda_tegra, chip);
255 253
256 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 254 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
257 list_for_each_entry(p, &chip->pcm_list, list)
258 snd_pcm_suspend_all(p->pcm);
259 if (chip->initialized)
260 snd_hda_suspend(chip->bus);
261 255
262 azx_stop_chip(chip); 256 azx_stop_chip(chip);
263 azx_enter_link_reset(chip); 257 azx_enter_link_reset(chip);
@@ -278,7 +272,6 @@ static int hda_tegra_resume(struct device *dev)
278 272
279 azx_init_chip(chip, 1); 273 azx_init_chip(chip, 1);
280 274
281 snd_hda_resume(chip->bus);
282 snd_power_change_state(card, SNDRV_CTL_POWER_D0); 275 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
283 276
284 return 0; 277 return 0;
@@ -297,8 +290,6 @@ static int hda_tegra_dev_free(struct snd_device *device)
297 int i; 290 int i;
298 struct azx *chip = device->device_data; 291 struct azx *chip = device->device_data;
299 292
300 azx_notifier_unregister(chip);
301
302 if (chip->initialized) { 293 if (chip->initialized) {
303 for (i = 0; i < chip->num_streams; i++) 294 for (i = 0; i < chip->num_streams; i++)
304 azx_stream_stop(chip, &chip->azx_dev[i]); 295 azx_stream_stop(chip, &chip->azx_dev[i]);
@@ -344,17 +335,6 @@ static int hda_tegra_init_chip(struct azx *chip, struct platform_device *pdev)
344 return 0; 335 return 0;
345} 336}
346 337
347/*
348 * The codecs were powered up in snd_hda_codec_new().
349 * Now all initialization done, so turn them down if possible
350 */
351static void power_down_all_codecs(struct azx *chip)
352{
353 struct hda_codec *codec;
354 list_for_each_entry(codec, &chip->bus->codec_list, list)
355 snd_hda_power_down(codec);
356}
357
358static int hda_tegra_first_init(struct azx *chip, struct platform_device *pdev) 338static int hda_tegra_first_init(struct azx *chip, struct platform_device *pdev)
359{ 339{
360 struct snd_card *card = chip->card; 340 struct snd_card *card = chip->card;
@@ -503,21 +483,15 @@ static int hda_tegra_probe(struct platform_device *pdev)
503 goto out_free; 483 goto out_free;
504 484
505 /* create codec instances */ 485 /* create codec instances */
506 err = azx_codec_create(chip, NULL, 0, &power_save); 486 err = azx_bus_create(chip, NULL);
507 if (err < 0) 487 if (err < 0)
508 goto out_free; 488 goto out_free;
509 489
510 err = azx_codec_configure(chip); 490 err = azx_probe_codecs(chip, 0);
511 if (err < 0) 491 if (err < 0)
512 goto out_free; 492 goto out_free;
513 493
514 /* create PCM streams */ 494 err = azx_codec_configure(chip);
515 err = snd_hda_build_pcms(chip->bus);
516 if (err < 0)
517 goto out_free;
518
519 /* create mixer controls */
520 err = azx_mixer_create(chip);
521 if (err < 0) 495 if (err < 0)
522 goto out_free; 496 goto out_free;
523 497
@@ -526,8 +500,7 @@ static int hda_tegra_probe(struct platform_device *pdev)
526 goto out_free; 500 goto out_free;
527 501
528 chip->running = 1; 502 chip->running = 1;
529 power_down_all_codecs(chip); 503 snd_hda_set_power_save(chip->bus, power_save * 1000);
530 azx_notifier_register(chip);
531 504
532 return 0; 505 return 0;
533 506
@@ -541,6 +514,18 @@ static int hda_tegra_remove(struct platform_device *pdev)
541 return snd_card_free(dev_get_drvdata(&pdev->dev)); 514 return snd_card_free(dev_get_drvdata(&pdev->dev));
542} 515}
543 516
517static void hda_tegra_shutdown(struct platform_device *pdev)
518{
519 struct snd_card *card = dev_get_drvdata(&pdev->dev);
520 struct azx *chip;
521
522 if (!card)
523 return;
524 chip = card->private_data;
525 if (chip && chip->running)
526 azx_stop_chip(chip);
527}
528
544static struct platform_driver tegra_platform_hda = { 529static struct platform_driver tegra_platform_hda = {
545 .driver = { 530 .driver = {
546 .name = "tegra-hda", 531 .name = "tegra-hda",
@@ -549,6 +534,7 @@ static struct platform_driver tegra_platform_hda = {
549 }, 534 },
550 .probe = hda_tegra_probe, 535 .probe = hda_tegra_probe,
551 .remove = hda_tegra_remove, 536 .remove = hda_tegra_remove,
537 .shutdown = hda_tegra_shutdown,
552}; 538};
553module_platform_driver(tegra_platform_hda); 539module_platform_driver(tegra_platform_hda);
554 540
diff --git a/sound/pci/hda/hda_trace.h b/sound/pci/hda/hda_trace.h
deleted file mode 100644
index 3a1c63161eb1..000000000000
--- a/sound/pci/hda/hda_trace.h
+++ /dev/null
@@ -1,143 +0,0 @@
1#undef TRACE_SYSTEM
2#define TRACE_SYSTEM hda
3#define TRACE_INCLUDE_FILE hda_trace
4
5#if !defined(_TRACE_HDA_H) || defined(TRACE_HEADER_MULTI_READ)
6#define _TRACE_HDA_H
7
8#include <linux/tracepoint.h>
9
10struct hda_bus;
11struct hda_codec;
12
13DECLARE_EVENT_CLASS(hda_cmd,
14
15 TP_PROTO(struct hda_codec *codec, unsigned int val),
16
17 TP_ARGS(codec, val),
18
19 TP_STRUCT__entry(
20 __field( unsigned int, card )
21 __field( unsigned int, addr )
22 __field( unsigned int, val )
23 ),
24
25 TP_fast_assign(
26 __entry->card = (codec)->bus->card->number;
27 __entry->addr = (codec)->addr;
28 __entry->val = (val);
29 ),
30
31 TP_printk("[%d:%d] val=%x", __entry->card, __entry->addr, __entry->val)
32);
33
34DEFINE_EVENT(hda_cmd, hda_send_cmd,
35 TP_PROTO(struct hda_codec *codec, unsigned int val),
36 TP_ARGS(codec, val)
37);
38
39DEFINE_EVENT(hda_cmd, hda_get_response,
40 TP_PROTO(struct hda_codec *codec, unsigned int val),
41 TP_ARGS(codec, val)
42);
43
44TRACE_EVENT(hda_bus_reset,
45
46 TP_PROTO(struct hda_bus *bus),
47
48 TP_ARGS(bus),
49
50 TP_STRUCT__entry(
51 __field( unsigned int, card )
52 ),
53
54 TP_fast_assign(
55 __entry->card = (bus)->card->number;
56 ),
57
58 TP_printk("[%d]", __entry->card)
59);
60
61#ifdef CONFIG_PM
62DECLARE_EVENT_CLASS(hda_power,
63
64 TP_PROTO(struct hda_codec *codec),
65
66 TP_ARGS(codec),
67
68 TP_STRUCT__entry(
69 __field( unsigned int, card )
70 __field( unsigned int, addr )
71 ),
72
73 TP_fast_assign(
74 __entry->card = (codec)->bus->card->number;
75 __entry->addr = (codec)->addr;
76 ),
77
78 TP_printk("[%d:%d]", __entry->card, __entry->addr)
79);
80
81DEFINE_EVENT(hda_power, hda_power_down,
82 TP_PROTO(struct hda_codec *codec),
83 TP_ARGS(codec)
84);
85
86DEFINE_EVENT(hda_power, hda_power_up,
87 TP_PROTO(struct hda_codec *codec),
88 TP_ARGS(codec)
89);
90
91TRACE_EVENT(hda_power_count,
92 TP_PROTO(struct hda_codec *codec),
93 TP_ARGS(codec),
94 TP_STRUCT__entry(
95 __field( unsigned int, card )
96 __field( unsigned int, addr )
97 __field( int, power_count )
98 __field( int, power_on )
99 __field( int, power_transition )
100 ),
101
102 TP_fast_assign(
103 __entry->card = (codec)->bus->card->number;
104 __entry->addr = (codec)->addr;
105 __entry->power_count = (codec)->power_count;
106 __entry->power_on = (codec)->power_on;
107 __entry->power_transition = (codec)->power_transition;
108 ),
109
110 TP_printk("[%d:%d] power_count=%d, power_on=%d, power_transition=%d",
111 __entry->card, __entry->addr, __entry->power_count,
112 __entry->power_on, __entry->power_transition)
113);
114#endif /* CONFIG_PM */
115
116TRACE_EVENT(hda_unsol_event,
117
118 TP_PROTO(struct hda_bus *bus, u32 res, u32 res_ex),
119
120 TP_ARGS(bus, res, res_ex),
121
122 TP_STRUCT__entry(
123 __field( unsigned int, card )
124 __field( u32, res )
125 __field( u32, res_ex )
126 ),
127
128 TP_fast_assign(
129 __entry->card = (bus)->card->number;
130 __entry->res = res;
131 __entry->res_ex = res_ex;
132 ),
133
134 TP_printk("[%d] res=%x, res_ex=%x", __entry->card,
135 __entry->res, __entry->res_ex)
136);
137
138#endif /* _TRACE_HDA_H */
139
140/* This part must be outside protection */
141#undef TRACE_INCLUDE_PATH
142#define TRACE_INCLUDE_PATH .
143#include <trace/define_trace.h>
diff --git a/sound/pci/hda/local.h b/sound/pci/hda/local.h
new file mode 100644
index 000000000000..28cb7f98982e
--- /dev/null
+++ b/sound/pci/hda/local.h
@@ -0,0 +1,39 @@
1/*
2 */
3
4#ifndef __HDAC_LOCAL_H
5#define __HDAC_LOCAL_H
6
7int hdac_read_parm(struct hdac_device *codec, hda_nid_t nid, int parm);
8
9#define get_wcaps(codec, nid) \
10 hdac_read_parm(codec, nid, AC_PAR_AUDIO_WIDGET_CAP)
11/* get the widget type from widget capability bits */
12static inline int get_wcaps_type(unsigned int wcaps)
13{
14 if (!wcaps)
15 return -1; /* invalid type */
16 return (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
17}
18
19#define get_pin_caps(codec, nid) \
20 hdac_read_parm(codec, nid, AC_PAR_PIN_CAP)
21
22static inline
23unsigned int get_pin_cfg(struct hdac_device *codec, hda_nid_t nid)
24{
25 unsigned int val;
26
27 if (snd_hdac_read(codec, nid, AC_VERB_GET_CONFIG_DEFAULT, 0, &val))
28 return -1;
29 return val;
30}
31
32#define get_amp_caps(codec, nid, dir) \
33 hdac_read_parm(codec, nid, (dir) == HDA_OUTPUT ? \
34 AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP)
35
36#define get_power_caps(codec, nid) \
37 hdac_read_parm(codec, nid, AC_PAR_POWER_STATE)
38
39#endif /* __HDAC_LOCAL_H */
diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c
index d285904cdb64..231f89029779 100644
--- a/sound/pci/hda/patch_analog.c
+++ b/sound/pci/hda/patch_analog.c
@@ -99,7 +99,7 @@ static void ad198x_power_eapd_write(struct hda_codec *codec, hda_nid_t front,
99static void ad198x_power_eapd(struct hda_codec *codec) 99static void ad198x_power_eapd(struct hda_codec *codec)
100{ 100{
101 /* We currently only handle front, HP */ 101 /* We currently only handle front, HP */
102 switch (codec->vendor_id) { 102 switch (codec->core.vendor_id) {
103 case 0x11d41882: 103 case 0x11d41882:
104 case 0x11d4882a: 104 case 0x11d4882a:
105 case 0x11d41884: 105 case 0x11d41884:
@@ -777,7 +777,6 @@ static int ad1988_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
777 return 0; 777 return 0;
778 778
779 mutex_lock(&codec->control_mutex); 779 mutex_lock(&codec->control_mutex);
780 codec->cached_write = 1;
781 path = snd_hda_get_path_from_idx(codec, 780 path = snd_hda_get_path_from_idx(codec,
782 spec->smux_paths[spec->cur_smux]); 781 spec->smux_paths[spec->cur_smux]);
783 if (path) 782 if (path)
@@ -786,9 +785,7 @@ static int ad1988_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
786 if (path) 785 if (path)
787 snd_hda_activate_path(codec, path, true, true); 786 snd_hda_activate_path(codec, path, true, true);
788 spec->cur_smux = val; 787 spec->cur_smux = val;
789 codec->cached_write = 0;
790 mutex_unlock(&codec->control_mutex); 788 mutex_unlock(&codec->control_mutex);
791 snd_hda_codec_flush_cache(codec); /* flush the updates */
792 return 1; 789 return 1;
793} 790}
794 791
@@ -1004,18 +1001,17 @@ static void ad1884_fixup_hp_eapd(struct hda_codec *codec,
1004 const struct hda_fixup *fix, int action) 1001 const struct hda_fixup *fix, int action)
1005{ 1002{
1006 struct ad198x_spec *spec = codec->spec; 1003 struct ad198x_spec *spec = codec->spec;
1007 static const struct hda_verb gpio_init_verbs[] = {
1008 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
1009 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
1010 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
1011 {},
1012 };
1013 1004
1014 switch (action) { 1005 switch (action) {
1015 case HDA_FIXUP_ACT_PRE_PROBE: 1006 case HDA_FIXUP_ACT_PRE_PROBE:
1016 spec->gen.vmaster_mute.hook = ad1884_vmaster_hp_gpio_hook; 1007 spec->gen.vmaster_mute.hook = ad1884_vmaster_hp_gpio_hook;
1017 spec->gen.own_eapd_ctl = 1; 1008 spec->gen.own_eapd_ctl = 1;
1018 snd_hda_sequence_write_cache(codec, gpio_init_verbs); 1009 snd_hda_codec_write_cache(codec, 0x01, 0,
1010 AC_VERB_SET_GPIO_MASK, 0x02);
1011 snd_hda_codec_write_cache(codec, 0x01, 0,
1012 AC_VERB_SET_GPIO_DIRECTION, 0x02);
1013 snd_hda_codec_write_cache(codec, 0x01, 0,
1014 AC_VERB_SET_GPIO_DATA, 0x02);
1019 break; 1015 break;
1020 case HDA_FIXUP_ACT_PROBE: 1016 case HDA_FIXUP_ACT_PROBE:
1021 if (spec->gen.autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT) 1017 if (spec->gen.autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
@@ -1194,20 +1190,8 @@ MODULE_ALIAS("snd-hda-codec-id:11d4*");
1194MODULE_LICENSE("GPL"); 1190MODULE_LICENSE("GPL");
1195MODULE_DESCRIPTION("Analog Devices HD-audio codec"); 1191MODULE_DESCRIPTION("Analog Devices HD-audio codec");
1196 1192
1197static struct hda_codec_preset_list analog_list = { 1193static struct hda_codec_driver analog_driver = {
1198 .preset = snd_hda_preset_analog, 1194 .preset = snd_hda_preset_analog,
1199 .owner = THIS_MODULE,
1200}; 1195};
1201 1196
1202static int __init patch_analog_init(void) 1197module_hda_codec_driver(analog_driver);
1203{
1204 return snd_hda_add_codec_preset(&analog_list);
1205}
1206
1207static void __exit patch_analog_exit(void)
1208{
1209 snd_hda_delete_codec_preset(&analog_list);
1210}
1211
1212module_init(patch_analog_init)
1213module_exit(patch_analog_exit)
diff --git a/sound/pci/hda/patch_ca0110.c b/sound/pci/hda/patch_ca0110.c
index 5e65999e0d8e..447302695195 100644
--- a/sound/pci/hda/patch_ca0110.c
+++ b/sound/pci/hda/patch_ca0110.c
@@ -98,20 +98,8 @@ MODULE_ALIAS("snd-hda-codec-id:1102000d");
98MODULE_LICENSE("GPL"); 98MODULE_LICENSE("GPL");
99MODULE_DESCRIPTION("Creative CA0110-IBG HD-audio codec"); 99MODULE_DESCRIPTION("Creative CA0110-IBG HD-audio codec");
100 100
101static struct hda_codec_preset_list ca0110_list = { 101static struct hda_codec_driver ca0110_driver = {
102 .preset = snd_hda_preset_ca0110, 102 .preset = snd_hda_preset_ca0110,
103 .owner = THIS_MODULE,
104}; 103};
105 104
106static int __init patch_ca0110_init(void) 105module_hda_codec_driver(ca0110_driver);
107{
108 return snd_hda_add_codec_preset(&ca0110_list);
109}
110
111static void __exit patch_ca0110_exit(void)
112{
113 snd_hda_delete_codec_preset(&ca0110_list);
114}
115
116module_init(patch_ca0110_init)
117module_exit(patch_ca0110_exit)
diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c
index e0383eea9880..4a4e7b282e4f 100644
--- a/sound/pci/hda/patch_ca0132.c
+++ b/sound/pci/hda/patch_ca0132.c
@@ -719,7 +719,6 @@ struct ca0132_spec {
719 unsigned int num_inputs; 719 unsigned int num_inputs;
720 hda_nid_t shared_mic_nid; 720 hda_nid_t shared_mic_nid;
721 hda_nid_t shared_out_nid; 721 hda_nid_t shared_out_nid;
722 struct hda_pcm pcm_rec[5]; /* PCM information */
723 722
724 /* chip access */ 723 /* chip access */
725 struct mutex chipio_mutex; /* chip access mutex */ 724 struct mutex chipio_mutex; /* chip access mutex */
@@ -3132,7 +3131,7 @@ static int ca0132_select_out(struct hda_codec *codec)
3132 3131
3133 codec_dbg(codec, "ca0132_select_out\n"); 3132 codec_dbg(codec, "ca0132_select_out\n");
3134 3133
3135 snd_hda_power_up(codec); 3134 snd_hda_power_up_pm(codec);
3136 3135
3137 auto_jack = spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID]; 3136 auto_jack = spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID];
3138 3137
@@ -3216,7 +3215,7 @@ static int ca0132_select_out(struct hda_codec *codec)
3216 } 3215 }
3217 3216
3218exit: 3217exit:
3219 snd_hda_power_down(codec); 3218 snd_hda_power_down_pm(codec);
3220 3219
3221 return err < 0 ? err : 0; 3220 return err < 0 ? err : 0;
3222} 3221}
@@ -3294,7 +3293,7 @@ static int ca0132_select_mic(struct hda_codec *codec)
3294 3293
3295 codec_dbg(codec, "ca0132_select_mic\n"); 3294 codec_dbg(codec, "ca0132_select_mic\n");
3296 3295
3297 snd_hda_power_up(codec); 3296 snd_hda_power_up_pm(codec);
3298 3297
3299 auto_jack = spec->vnode_lswitch[VNID_AMIC1_ASEL - VNODE_START_NID]; 3298 auto_jack = spec->vnode_lswitch[VNID_AMIC1_ASEL - VNODE_START_NID];
3300 3299
@@ -3327,7 +3326,7 @@ static int ca0132_select_mic(struct hda_codec *codec)
3327 ca0132_effects_set(codec, VOICE_FOCUS, 0); 3326 ca0132_effects_set(codec, VOICE_FOCUS, 0);
3328 } 3327 }
3329 3328
3330 snd_hda_power_down(codec); 3329 snd_hda_power_down_pm(codec);
3331 3330
3332 return 0; 3331 return 0;
3333} 3332}
@@ -4036,12 +4035,11 @@ static struct hda_pcm_stream ca0132_pcm_digital_capture = {
4036static int ca0132_build_pcms(struct hda_codec *codec) 4035static int ca0132_build_pcms(struct hda_codec *codec)
4037{ 4036{
4038 struct ca0132_spec *spec = codec->spec; 4037 struct ca0132_spec *spec = codec->spec;
4039 struct hda_pcm *info = spec->pcm_rec; 4038 struct hda_pcm *info;
4040
4041 codec->pcm_info = info;
4042 codec->num_pcms = 0;
4043 4039
4044 info->name = "CA0132 Analog"; 4040 info = snd_hda_codec_pcm_new(codec, "CA0132 Analog");
4041 if (!info)
4042 return -ENOMEM;
4045 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ca0132_pcm_analog_playback; 4043 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ca0132_pcm_analog_playback;
4046 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dacs[0]; 4044 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dacs[0];
4047 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 4045 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
@@ -4049,27 +4047,27 @@ static int ca0132_build_pcms(struct hda_codec *codec)
4049 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture; 4047 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture;
4050 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1; 4048 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
4051 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[0]; 4049 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[0];
4052 codec->num_pcms++;
4053 4050
4054 info++; 4051 info = snd_hda_codec_pcm_new(codec, "CA0132 Analog Mic-In2");
4055 info->name = "CA0132 Analog Mic-In2"; 4052 if (!info)
4053 return -ENOMEM;
4056 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture; 4054 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture;
4057 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1; 4055 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
4058 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[1]; 4056 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[1];
4059 codec->num_pcms++;
4060 4057
4061 info++; 4058 info = snd_hda_codec_pcm_new(codec, "CA0132 What U Hear");
4062 info->name = "CA0132 What U Hear"; 4059 if (!info)
4060 return -ENOMEM;
4063 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture; 4061 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture;
4064 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1; 4062 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
4065 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[2]; 4063 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[2];
4066 codec->num_pcms++;
4067 4064
4068 if (!spec->dig_out && !spec->dig_in) 4065 if (!spec->dig_out && !spec->dig_in)
4069 return 0; 4066 return 0;
4070 4067
4071 info++; 4068 info = snd_hda_codec_pcm_new(codec, "CA0132 Digital");
4072 info->name = "CA0132 Digital"; 4069 if (!info)
4070 return -ENOMEM;
4073 info->pcm_type = HDA_PCM_TYPE_SPDIF; 4071 info->pcm_type = HDA_PCM_TYPE_SPDIF;
4074 if (spec->dig_out) { 4072 if (spec->dig_out) {
4075 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = 4073 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
@@ -4081,7 +4079,6 @@ static int ca0132_build_pcms(struct hda_codec *codec)
4081 ca0132_pcm_digital_capture; 4079 ca0132_pcm_digital_capture;
4082 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in; 4080 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in;
4083 } 4081 }
4084 codec->num_pcms++;
4085 4082
4086 return 0; 4083 return 0;
4087} 4084}
@@ -4246,13 +4243,9 @@ static void ca0132_refresh_widget_caps(struct hda_codec *codec)
4246{ 4243{
4247 struct ca0132_spec *spec = codec->spec; 4244 struct ca0132_spec *spec = codec->spec;
4248 int i; 4245 int i;
4249 hda_nid_t nid;
4250 4246
4251 codec_dbg(codec, "ca0132_refresh_widget_caps.\n"); 4247 codec_dbg(codec, "ca0132_refresh_widget_caps.\n");
4252 nid = codec->start_nid; 4248 snd_hda_codec_update_widgets(codec);
4253 for (i = 0; i < codec->num_nodes; i++, nid++)
4254 codec->wcaps[i] = snd_hda_param_read(codec, nid,
4255 AC_PAR_AUDIO_WIDGET_CAP);
4256 4249
4257 for (i = 0; i < spec->multiout.num_dacs; i++) 4250 for (i = 0; i < spec->multiout.num_dacs; i++)
4258 refresh_amp_caps(codec, spec->dacs[i], HDA_OUTPUT); 4251 refresh_amp_caps(codec, spec->dacs[i], HDA_OUTPUT);
@@ -4352,7 +4345,7 @@ static bool ca0132_download_dsp_images(struct hda_codec *codec)
4352 const struct dsp_image_seg *dsp_os_image; 4345 const struct dsp_image_seg *dsp_os_image;
4353 const struct firmware *fw_entry; 4346 const struct firmware *fw_entry;
4354 4347
4355 if (request_firmware(&fw_entry, EFX_FILE, codec->bus->card->dev) != 0) 4348 if (request_firmware(&fw_entry, EFX_FILE, codec->card->dev) != 0)
4356 return false; 4349 return false;
4357 4350
4358 dsp_os_image = (struct dsp_image_seg *)(fw_entry->data); 4351 dsp_os_image = (struct dsp_image_seg *)(fw_entry->data);
@@ -4413,8 +4406,7 @@ static void hp_callback(struct hda_codec *codec, struct hda_jack_callback *cb)
4413 * state machine run. 4406 * state machine run.
4414 */ 4407 */
4415 cancel_delayed_work_sync(&spec->unsol_hp_work); 4408 cancel_delayed_work_sync(&spec->unsol_hp_work);
4416 queue_delayed_work(codec->bus->workq, &spec->unsol_hp_work, 4409 schedule_delayed_work(&spec->unsol_hp_work, msecs_to_jiffies(500));
4417 msecs_to_jiffies(500));
4418 cb->tbl->block_report = 1; 4410 cb->tbl->block_report = 1;
4419} 4411}
4420 4412
@@ -4554,7 +4546,7 @@ static int ca0132_init(struct hda_codec *codec)
4554 spec->dsp_state = DSP_DOWNLOAD_INIT; 4546 spec->dsp_state = DSP_DOWNLOAD_INIT;
4555 spec->curr_chip_addx = INVALID_CHIP_ADDRESS; 4547 spec->curr_chip_addx = INVALID_CHIP_ADDRESS;
4556 4548
4557 snd_hda_power_up(codec); 4549 snd_hda_power_up_pm(codec);
4558 4550
4559 ca0132_init_unsol(codec); 4551 ca0132_init_unsol(codec);
4560 4552
@@ -4585,7 +4577,7 @@ static int ca0132_init(struct hda_codec *codec)
4585 4577
4586 snd_hda_jack_report_sync(codec); 4578 snd_hda_jack_report_sync(codec);
4587 4579
4588 snd_hda_power_down(codec); 4580 snd_hda_power_down_pm(codec);
4589 4581
4590 return 0; 4582 return 0;
4591} 4583}
@@ -4702,20 +4694,8 @@ MODULE_ALIAS("snd-hda-codec-id:11020011");
4702MODULE_LICENSE("GPL"); 4694MODULE_LICENSE("GPL");
4703MODULE_DESCRIPTION("Creative Sound Core3D codec"); 4695MODULE_DESCRIPTION("Creative Sound Core3D codec");
4704 4696
4705static struct hda_codec_preset_list ca0132_list = { 4697static struct hda_codec_driver ca0132_driver = {
4706 .preset = snd_hda_preset_ca0132, 4698 .preset = snd_hda_preset_ca0132,
4707 .owner = THIS_MODULE,
4708}; 4699};
4709 4700
4710static int __init patch_ca0132_init(void) 4701module_hda_codec_driver(ca0132_driver);
4711{
4712 return snd_hda_add_codec_preset(&ca0132_list);
4713}
4714
4715static void __exit patch_ca0132_exit(void)
4716{
4717 snd_hda_delete_codec_preset(&ca0132_list);
4718}
4719
4720module_init(patch_ca0132_init)
4721module_exit(patch_ca0132_exit)
diff --git a/sound/pci/hda/patch_cirrus.c b/sound/pci/hda/patch_cirrus.c
index dd2b3d92071f..50e9dd675579 100644
--- a/sound/pci/hda/patch_cirrus.c
+++ b/sound/pci/hda/patch_cirrus.c
@@ -1221,20 +1221,8 @@ MODULE_ALIAS("snd-hda-codec-id:10134213");
1221MODULE_LICENSE("GPL"); 1221MODULE_LICENSE("GPL");
1222MODULE_DESCRIPTION("Cirrus Logic HD-audio codec"); 1222MODULE_DESCRIPTION("Cirrus Logic HD-audio codec");
1223 1223
1224static struct hda_codec_preset_list cirrus_list = { 1224static struct hda_codec_driver cirrus_driver = {
1225 .preset = snd_hda_preset_cirrus, 1225 .preset = snd_hda_preset_cirrus,
1226 .owner = THIS_MODULE,
1227}; 1226};
1228 1227
1229static int __init patch_cirrus_init(void) 1228module_hda_codec_driver(cirrus_driver);
1230{
1231 return snd_hda_add_codec_preset(&cirrus_list);
1232}
1233
1234static void __exit patch_cirrus_exit(void)
1235{
1236 snd_hda_delete_codec_preset(&cirrus_list);
1237}
1238
1239module_init(patch_cirrus_init)
1240module_exit(patch_cirrus_exit)
diff --git a/sound/pci/hda/patch_cmedia.c b/sound/pci/hda/patch_cmedia.c
index c895a8f21192..617d9012e78a 100644
--- a/sound/pci/hda/patch_cmedia.c
+++ b/sound/pci/hda/patch_cmedia.c
@@ -137,20 +137,8 @@ MODULE_ALIAS("snd-hda-codec-id:434d4980");
137MODULE_LICENSE("GPL"); 137MODULE_LICENSE("GPL");
138MODULE_DESCRIPTION("C-Media HD-audio codec"); 138MODULE_DESCRIPTION("C-Media HD-audio codec");
139 139
140static struct hda_codec_preset_list cmedia_list = { 140static struct hda_codec_driver cmedia_driver = {
141 .preset = snd_hda_preset_cmedia, 141 .preset = snd_hda_preset_cmedia,
142 .owner = THIS_MODULE,
143}; 142};
144 143
145static int __init patch_cmedia_init(void) 144module_hda_codec_driver(cmedia_driver);
146{
147 return snd_hda_add_codec_preset(&cmedia_list);
148}
149
150static void __exit patch_cmedia_exit(void)
151{
152 snd_hda_delete_codec_preset(&cmedia_list);
153}
154
155module_init(patch_cmedia_init)
156module_exit(patch_cmedia_exit)
diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c
index da67ea8645a6..f8f0dfbef149 100644
--- a/sound/pci/hda/patch_conexant.c
+++ b/sound/pci/hda/patch_conexant.c
@@ -103,10 +103,9 @@ static int add_beep_ctls(struct hda_codec *codec)
103static void cx_auto_parse_beep(struct hda_codec *codec) 103static void cx_auto_parse_beep(struct hda_codec *codec)
104{ 104{
105 struct conexant_spec *spec = codec->spec; 105 struct conexant_spec *spec = codec->spec;
106 hda_nid_t nid, end_nid; 106 hda_nid_t nid;
107 107
108 end_nid = codec->start_nid + codec->num_nodes; 108 for_each_hda_codec_node(nid, codec)
109 for (nid = codec->start_nid; nid < end_nid; nid++)
110 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) { 109 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
111 set_beep_amp(spec, nid, 0, HDA_OUTPUT); 110 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
112 break; 111 break;
@@ -120,10 +119,9 @@ static void cx_auto_parse_beep(struct hda_codec *codec)
120static void cx_auto_parse_eapd(struct hda_codec *codec) 119static void cx_auto_parse_eapd(struct hda_codec *codec)
121{ 120{
122 struct conexant_spec *spec = codec->spec; 121 struct conexant_spec *spec = codec->spec;
123 hda_nid_t nid, end_nid; 122 hda_nid_t nid;
124 123
125 end_nid = codec->start_nid + codec->num_nodes; 124 for_each_hda_codec_node(nid, codec) {
126 for (nid = codec->start_nid; nid < end_nid; nid++) {
127 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) 125 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
128 continue; 126 continue;
129 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) 127 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
@@ -304,6 +302,7 @@ static void cxt_fixup_headphone_mic(struct hda_codec *codec,
304 switch (action) { 302 switch (action) {
305 case HDA_FIXUP_ACT_PRE_PROBE: 303 case HDA_FIXUP_ACT_PRE_PROBE:
306 spec->parse_flags |= HDA_PINCFG_HEADPHONE_MIC; 304 spec->parse_flags |= HDA_PINCFG_HEADPHONE_MIC;
305 snd_hdac_regmap_add_vendor_verb(&codec->core, 0x410);
307 break; 306 break;
308 case HDA_FIXUP_ACT_PROBE: 307 case HDA_FIXUP_ACT_PROBE:
309 spec->gen.cap_sync_hook = cxt_update_headset_mode_hook; 308 spec->gen.cap_sync_hook = cxt_update_headset_mode_hook;
@@ -411,15 +410,11 @@ static void olpc_xo_automic(struct hda_codec *codec,
411 struct hda_jack_callback *jack) 410 struct hda_jack_callback *jack)
412{ 411{
413 struct conexant_spec *spec = codec->spec; 412 struct conexant_spec *spec = codec->spec;
414 int saved_cached_write = codec->cached_write;
415 413
416 codec->cached_write = 1;
417 /* in DC mode, we don't handle automic */ 414 /* in DC mode, we don't handle automic */
418 if (!spec->dc_enable) 415 if (!spec->dc_enable)
419 snd_hda_gen_mic_autoswitch(codec, jack); 416 snd_hda_gen_mic_autoswitch(codec, jack);
420 olpc_xo_update_mic_pins(codec); 417 olpc_xo_update_mic_pins(codec);
421 snd_hda_codec_flush_cache(codec);
422 codec->cached_write = saved_cached_write;
423 if (spec->dc_enable) 418 if (spec->dc_enable)
424 olpc_xo_update_mic_boost(codec); 419 olpc_xo_update_mic_boost(codec);
425} 420}
@@ -848,7 +843,7 @@ static int patch_conexant_auto(struct hda_codec *codec)
848 struct conexant_spec *spec; 843 struct conexant_spec *spec;
849 int err; 844 int err;
850 845
851 codec_info(codec, "%s: BIOS auto-probing.\n", codec->chip_name); 846 codec_info(codec, "%s: BIOS auto-probing.\n", codec->core.chip_name);
852 847
853 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 848 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
854 if (!spec) 849 if (!spec)
@@ -862,7 +857,7 @@ static int patch_conexant_auto(struct hda_codec *codec)
862 if (spec->dynamic_eapd) 857 if (spec->dynamic_eapd)
863 spec->gen.vmaster_mute.hook = cx_auto_vmaster_hook; 858 spec->gen.vmaster_mute.hook = cx_auto_vmaster_hook;
864 859
865 switch (codec->vendor_id) { 860 switch (codec->core.vendor_id) {
866 case 0x14f15045: 861 case 0x14f15045:
867 codec->single_adc_amp = 1; 862 codec->single_adc_amp = 1;
868 spec->gen.mixer_nid = 0x17; 863 spec->gen.mixer_nid = 0x17;
@@ -896,7 +891,7 @@ static int patch_conexant_auto(struct hda_codec *codec)
896 * others may use EAPD really as an amp switch, so it might be 891 * others may use EAPD really as an amp switch, so it might be
897 * not good to expose it blindly. 892 * not good to expose it blindly.
898 */ 893 */
899 switch (codec->subsystem_id >> 16) { 894 switch (codec->core.subsystem_id >> 16) {
900 case 0x103c: 895 case 0x103c:
901 spec->gen.vmaster_mute_enum = 1; 896 spec->gen.vmaster_mute_enum = 1;
902 break; 897 break;
@@ -919,10 +914,10 @@ static int patch_conexant_auto(struct hda_codec *codec)
919 * which falls into the single-cmd mode. 914 * which falls into the single-cmd mode.
920 * Better to make reset, then. 915 * Better to make reset, then.
921 */ 916 */
922 if (!codec->bus->sync_write) { 917 if (!codec->bus->core.sync_write) {
923 codec_info(codec, 918 codec_info(codec,
924 "Enable sync_write for stable communication\n"); 919 "Enable sync_write for stable communication\n");
925 codec->bus->sync_write = 1; 920 codec->bus->core.sync_write = 1;
926 codec->bus->allow_bus_reset = 1; 921 codec->bus->allow_bus_reset = 1;
927 } 922 }
928 923
@@ -1018,20 +1013,8 @@ MODULE_ALIAS("snd-hda-codec-id:14f151d7");
1018MODULE_LICENSE("GPL"); 1013MODULE_LICENSE("GPL");
1019MODULE_DESCRIPTION("Conexant HD-audio codec"); 1014MODULE_DESCRIPTION("Conexant HD-audio codec");
1020 1015
1021static struct hda_codec_preset_list conexant_list = { 1016static struct hda_codec_driver conexant_driver = {
1022 .preset = snd_hda_preset_conexant, 1017 .preset = snd_hda_preset_conexant,
1023 .owner = THIS_MODULE,
1024}; 1018};
1025 1019
1026static int __init patch_conexant_init(void) 1020module_hda_codec_driver(conexant_driver);
1027{
1028 return snd_hda_add_codec_preset(&conexant_list);
1029}
1030
1031static void __exit patch_conexant_exit(void)
1032{
1033 snd_hda_delete_codec_preset(&conexant_list);
1034}
1035
1036module_init(patch_conexant_init)
1037module_exit(patch_conexant_exit)
diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
index b422e406a9cb..5f44f60a6389 100644
--- a/sound/pci/hda/patch_hdmi.c
+++ b/sound/pci/hda/patch_hdmi.c
@@ -45,14 +45,14 @@ static bool static_hdmi_pcm;
45module_param(static_hdmi_pcm, bool, 0644); 45module_param(static_hdmi_pcm, bool, 0644);
46MODULE_PARM_DESC(static_hdmi_pcm, "Don't restrict PCM parameters per ELD info"); 46MODULE_PARM_DESC(static_hdmi_pcm, "Don't restrict PCM parameters per ELD info");
47 47
48#define is_haswell(codec) ((codec)->vendor_id == 0x80862807) 48#define is_haswell(codec) ((codec)->core.vendor_id == 0x80862807)
49#define is_broadwell(codec) ((codec)->vendor_id == 0x80862808) 49#define is_broadwell(codec) ((codec)->core.vendor_id == 0x80862808)
50#define is_skylake(codec) ((codec)->vendor_id == 0x80862809) 50#define is_skylake(codec) ((codec)->core.vendor_id == 0x80862809)
51#define is_haswell_plus(codec) (is_haswell(codec) || is_broadwell(codec) \ 51#define is_haswell_plus(codec) (is_haswell(codec) || is_broadwell(codec) \
52 || is_skylake(codec)) 52 || is_skylake(codec))
53 53
54#define is_valleyview(codec) ((codec)->vendor_id == 0x80862882) 54#define is_valleyview(codec) ((codec)->core.vendor_id == 0x80862882)
55#define is_cherryview(codec) ((codec)->vendor_id == 0x80862883) 55#define is_cherryview(codec) ((codec)->core.vendor_id == 0x80862883)
56#define is_valleyview_plus(codec) (is_valleyview(codec) || is_cherryview(codec)) 56#define is_valleyview_plus(codec) (is_valleyview(codec) || is_cherryview(codec))
57 57
58struct hdmi_spec_per_cvt { 58struct hdmi_spec_per_cvt {
@@ -86,7 +86,6 @@ struct hdmi_spec_per_pin {
86 bool non_pcm; 86 bool non_pcm;
87 bool chmap_set; /* channel-map override by ALSA API? */ 87 bool chmap_set; /* channel-map override by ALSA API? */
88 unsigned char chmap[8]; /* ALSA API channel-map */ 88 unsigned char chmap[8]; /* ALSA API channel-map */
89 char pcm_name[8]; /* filled in build_pcm callbacks */
90#ifdef CONFIG_PROC_FS 89#ifdef CONFIG_PROC_FS
91 struct snd_info_entry *proc_entry; 90 struct snd_info_entry *proc_entry;
92#endif 91#endif
@@ -132,7 +131,7 @@ struct hdmi_spec {
132 131
133 int num_pins; 132 int num_pins;
134 struct snd_array pins; /* struct hdmi_spec_per_pin */ 133 struct snd_array pins; /* struct hdmi_spec_per_pin */
135 struct snd_array pcm_rec; /* struct hda_pcm */ 134 struct hda_pcm *pcm_rec[16];
136 unsigned int channels_max; /* max over all cvts */ 135 unsigned int channels_max; /* max over all cvts */
137 136
138 struct hdmi_eld temp_eld; 137 struct hdmi_eld temp_eld;
@@ -355,8 +354,7 @@ static struct cea_channel_speaker_allocation channel_allocations[] = {
355 ((struct hdmi_spec_per_pin *)snd_array_elem(&spec->pins, idx)) 354 ((struct hdmi_spec_per_pin *)snd_array_elem(&spec->pins, idx))
356#define get_cvt(spec, idx) \ 355#define get_cvt(spec, idx) \
357 ((struct hdmi_spec_per_cvt *)snd_array_elem(&spec->cvts, idx)) 356 ((struct hdmi_spec_per_cvt *)snd_array_elem(&spec->cvts, idx))
358#define get_pcm_rec(spec, idx) \ 357#define get_pcm_rec(spec, idx) ((spec)->pcm_rec[idx])
359 ((struct hda_pcm *)snd_array_elem(&spec->pcm_rec, idx))
360 358
361static int pin_nid_to_pin_index(struct hda_codec *codec, hda_nid_t pin_nid) 359static int pin_nid_to_pin_index(struct hda_codec *codec, hda_nid_t pin_nid)
362{ 360{
@@ -579,7 +577,7 @@ static int eld_proc_new(struct hdmi_spec_per_pin *per_pin, int index)
579 int err; 577 int err;
580 578
581 snprintf(name, sizeof(name), "eld#%d.%d", codec->addr, index); 579 snprintf(name, sizeof(name), "eld#%d.%d", codec->addr, index);
582 err = snd_card_proc_new(codec->bus->card, name, &entry); 580 err = snd_card_proc_new(codec->card, name, &entry);
583 if (err < 0) 581 if (err < 0)
584 return err; 582 return err;
585 583
@@ -594,7 +592,7 @@ static int eld_proc_new(struct hdmi_spec_per_pin *per_pin, int index)
594static void eld_proc_free(struct hdmi_spec_per_pin *per_pin) 592static void eld_proc_free(struct hdmi_spec_per_pin *per_pin)
595{ 593{
596 if (!per_pin->codec->bus->shutdown && per_pin->proc_entry) { 594 if (!per_pin->codec->bus->shutdown && per_pin->proc_entry) {
597 snd_device_free(per_pin->codec->bus->card, per_pin->proc_entry); 595 snd_device_free(per_pin->codec->card, per_pin->proc_entry);
598 per_pin->proc_entry = NULL; 596 per_pin->proc_entry = NULL;
599 } 597 }
600} 598}
@@ -1393,13 +1391,12 @@ static void intel_not_share_assigned_cvt(struct hda_codec *codec,
1393 hda_nid_t pin_nid, int mux_idx) 1391 hda_nid_t pin_nid, int mux_idx)
1394{ 1392{
1395 struct hdmi_spec *spec = codec->spec; 1393 struct hdmi_spec *spec = codec->spec;
1396 hda_nid_t nid, end_nid; 1394 hda_nid_t nid;
1397 int cvt_idx, curr; 1395 int cvt_idx, curr;
1398 struct hdmi_spec_per_cvt *per_cvt; 1396 struct hdmi_spec_per_cvt *per_cvt;
1399 1397
1400 /* configure all pins, including "no physical connection" ones */ 1398 /* configure all pins, including "no physical connection" ones */
1401 end_nid = codec->start_nid + codec->num_nodes; 1399 for_each_hda_codec_node(nid, codec) {
1402 for (nid = codec->start_nid; nid < end_nid; nid++) {
1403 unsigned int wid_caps = get_wcaps(codec, nid); 1400 unsigned int wid_caps = get_wcaps(codec, nid);
1404 unsigned int wid_type = get_wcaps_type(wid_caps); 1401 unsigned int wid_type = get_wcaps_type(wid_caps);
1405 1402
@@ -1548,7 +1545,7 @@ static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
1548 bool eld_changed = false; 1545 bool eld_changed = false;
1549 bool ret; 1546 bool ret;
1550 1547
1551 snd_hda_power_up(codec); 1548 snd_hda_power_up_pm(codec);
1552 present = snd_hda_pin_sense(codec, pin_nid); 1549 present = snd_hda_pin_sense(codec, pin_nid);
1553 1550
1554 mutex_lock(&per_pin->lock); 1551 mutex_lock(&per_pin->lock);
@@ -1578,9 +1575,8 @@ static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
1578 update_eld = true; 1575 update_eld = true;
1579 } 1576 }
1580 else if (repoll) { 1577 else if (repoll) {
1581 queue_delayed_work(codec->bus->workq, 1578 schedule_delayed_work(&per_pin->work,
1582 &per_pin->work, 1579 msecs_to_jiffies(300));
1583 msecs_to_jiffies(300));
1584 goto unlock; 1580 goto unlock;
1585 } 1581 }
1586 } 1582 }
@@ -1624,7 +1620,7 @@ static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
1624 } 1620 }
1625 1621
1626 if (eld_changed) 1622 if (eld_changed)
1627 snd_ctl_notify(codec->bus->card, 1623 snd_ctl_notify(codec->card,
1628 SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO, 1624 SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO,
1629 &per_pin->eld_ctl->id); 1625 &per_pin->eld_ctl->id);
1630 unlock: 1626 unlock:
@@ -1635,7 +1631,7 @@ static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
1635 jack->block_report = !ret; 1631 jack->block_report = !ret;
1636 1632
1637 mutex_unlock(&per_pin->lock); 1633 mutex_unlock(&per_pin->lock);
1638 snd_hda_power_down(codec); 1634 snd_hda_power_down_pm(codec);
1639 return ret; 1635 return ret;
1640} 1636}
1641 1637
@@ -1731,7 +1727,7 @@ static int hdmi_parse_codec(struct hda_codec *codec)
1731 hda_nid_t nid; 1727 hda_nid_t nid;
1732 int i, nodes; 1728 int i, nodes;
1733 1729
1734 nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid); 1730 nodes = snd_hda_get_sub_nodes(codec, codec->core.afg, &nid);
1735 if (!nid || nodes < 0) { 1731 if (!nid || nodes < 0) {
1736 codec_warn(codec, "HDMI: failed to get afg sub nodes\n"); 1732 codec_warn(codec, "HDMI: failed to get afg sub nodes\n");
1737 return -EINVAL; 1733 return -EINVAL;
@@ -2056,11 +2052,10 @@ static int generic_hdmi_build_pcms(struct hda_codec *codec)
2056 struct hdmi_spec_per_pin *per_pin; 2052 struct hdmi_spec_per_pin *per_pin;
2057 2053
2058 per_pin = get_pin(spec, pin_idx); 2054 per_pin = get_pin(spec, pin_idx);
2059 sprintf(per_pin->pcm_name, "HDMI %d", pin_idx); 2055 info = snd_hda_codec_pcm_new(codec, "HDMI %d", pin_idx);
2060 info = snd_array_new(&spec->pcm_rec);
2061 if (!info) 2056 if (!info)
2062 return -ENOMEM; 2057 return -ENOMEM;
2063 info->name = per_pin->pcm_name; 2058 spec->pcm_rec[pin_idx] = info;
2064 info->pcm_type = HDA_PCM_TYPE_HDMI; 2059 info->pcm_type = HDA_PCM_TYPE_HDMI;
2065 info->own_chmap = true; 2060 info->own_chmap = true;
2066 2061
@@ -2070,9 +2065,6 @@ static int generic_hdmi_build_pcms(struct hda_codec *codec)
2070 /* other pstr fields are set in open */ 2065 /* other pstr fields are set in open */
2071 } 2066 }
2072 2067
2073 codec->num_pcms = spec->num_pins;
2074 codec->pcm_info = spec->pcm_rec.list;
2075
2076 return 0; 2068 return 0;
2077} 2069}
2078 2070
@@ -2125,13 +2117,15 @@ static int generic_hdmi_build_controls(struct hda_codec *codec)
2125 2117
2126 /* add channel maps */ 2118 /* add channel maps */
2127 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { 2119 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2120 struct hda_pcm *pcm;
2128 struct snd_pcm_chmap *chmap; 2121 struct snd_pcm_chmap *chmap;
2129 struct snd_kcontrol *kctl; 2122 struct snd_kcontrol *kctl;
2130 int i; 2123 int i;
2131 2124
2132 if (!codec->pcm_info[pin_idx].pcm) 2125 pcm = spec->pcm_rec[pin_idx];
2126 if (!pcm || !pcm->pcm)
2133 break; 2127 break;
2134 err = snd_pcm_add_chmap_ctls(codec->pcm_info[pin_idx].pcm, 2128 err = snd_pcm_add_chmap_ctls(pcm->pcm,
2135 SNDRV_PCM_STREAM_PLAYBACK, 2129 SNDRV_PCM_STREAM_PLAYBACK,
2136 NULL, 0, pin_idx, &chmap); 2130 NULL, 0, pin_idx, &chmap);
2137 if (err < 0) 2131 if (err < 0)
@@ -2186,14 +2180,12 @@ static void hdmi_array_init(struct hdmi_spec *spec, int nums)
2186{ 2180{
2187 snd_array_init(&spec->pins, sizeof(struct hdmi_spec_per_pin), nums); 2181 snd_array_init(&spec->pins, sizeof(struct hdmi_spec_per_pin), nums);
2188 snd_array_init(&spec->cvts, sizeof(struct hdmi_spec_per_cvt), nums); 2182 snd_array_init(&spec->cvts, sizeof(struct hdmi_spec_per_cvt), nums);
2189 snd_array_init(&spec->pcm_rec, sizeof(struct hda_pcm), nums);
2190} 2183}
2191 2184
2192static void hdmi_array_free(struct hdmi_spec *spec) 2185static void hdmi_array_free(struct hdmi_spec *spec)
2193{ 2186{
2194 snd_array_free(&spec->pins); 2187 snd_array_free(&spec->pins);
2195 snd_array_free(&spec->cvts); 2188 snd_array_free(&spec->cvts);
2196 snd_array_free(&spec->pcm_rec);
2197} 2189}
2198 2190
2199static void generic_hdmi_free(struct hda_codec *codec) 2191static void generic_hdmi_free(struct hda_codec *codec)
@@ -2204,11 +2196,10 @@ static void generic_hdmi_free(struct hda_codec *codec)
2204 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { 2196 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2205 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); 2197 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2206 2198
2207 cancel_delayed_work(&per_pin->work); 2199 cancel_delayed_work_sync(&per_pin->work);
2208 eld_proc_free(per_pin); 2200 eld_proc_free(per_pin);
2209 } 2201 }
2210 2202
2211 flush_workqueue(codec->bus->workq);
2212 hdmi_array_free(spec); 2203 hdmi_array_free(spec);
2213 kfree(spec); 2204 kfree(spec);
2214} 2205}
@@ -2220,8 +2211,7 @@ static int generic_hdmi_resume(struct hda_codec *codec)
2220 int pin_idx; 2211 int pin_idx;
2221 2212
2222 codec->patch_ops.init(codec); 2213 codec->patch_ops.init(codec);
2223 snd_hda_codec_resume_amp(codec); 2214 regcache_sync(codec->core.regmap);
2224 snd_hda_codec_resume_cache(codec);
2225 2215
2226 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { 2216 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2227 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); 2217 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
@@ -2308,6 +2298,7 @@ static void intel_haswell_fixup_enable_dp12(struct hda_codec *codec)
2308 2298
2309 /* enable DP1.2 mode */ 2299 /* enable DP1.2 mode */
2310 vendor_param |= INTEL_EN_DP12; 2300 vendor_param |= INTEL_EN_DP12;
2301 snd_hdac_regmap_add_vendor_verb(&codec->core, INTEL_SET_VENDOR_VERB);
2311 snd_hda_codec_write_cache(codec, INTEL_VENDOR_NID, 0, 2302 snd_hda_codec_write_cache(codec, INTEL_VENDOR_NID, 0,
2312 INTEL_SET_VENDOR_VERB, vendor_param); 2303 INTEL_SET_VENDOR_VERB, vendor_param);
2313} 2304}
@@ -2381,11 +2372,10 @@ static int simple_playback_build_pcms(struct hda_codec *codec)
2381 chans = get_wcaps(codec, per_cvt->cvt_nid); 2372 chans = get_wcaps(codec, per_cvt->cvt_nid);
2382 chans = get_wcaps_channels(chans); 2373 chans = get_wcaps_channels(chans);
2383 2374
2384 info = snd_array_new(&spec->pcm_rec); 2375 info = snd_hda_codec_pcm_new(codec, "HDMI 0");
2385 if (!info) 2376 if (!info)
2386 return -ENOMEM; 2377 return -ENOMEM;
2387 info->name = get_pin(spec, 0)->pcm_name; 2378 spec->pcm_rec[0] = info;
2388 sprintf(info->name, "HDMI 0");
2389 info->pcm_type = HDA_PCM_TYPE_HDMI; 2379 info->pcm_type = HDA_PCM_TYPE_HDMI;
2390 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK]; 2380 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
2391 *pstr = spec->pcm_playback; 2381 *pstr = spec->pcm_playback;
@@ -2393,9 +2383,6 @@ static int simple_playback_build_pcms(struct hda_codec *codec)
2393 if (pstr->channels_max <= 2 && chans && chans <= 16) 2383 if (pstr->channels_max <= 2 && chans && chans <= 16)
2394 pstr->channels_max = chans; 2384 pstr->channels_max = chans;
2395 2385
2396 codec->num_pcms = 1;
2397 codec->pcm_info = info;
2398
2399 return 0; 2386 return 0;
2400} 2387}
2401 2388
@@ -2940,7 +2927,8 @@ static int patch_nvhdmi(struct hda_codec *codec)
2940 */ 2927 */
2941 2928
2942#define is_amdhdmi_rev3_or_later(codec) \ 2929#define is_amdhdmi_rev3_or_later(codec) \
2943 ((codec)->vendor_id == 0x1002aa01 && ((codec)->revision_id & 0xff00) >= 0x0300) 2930 ((codec)->core.vendor_id == 0x1002aa01 && \
2931 ((codec)->core.revision_id & 0xff00) >= 0x0300)
2944#define has_amd_full_remap_support(codec) is_amdhdmi_rev3_or_later(codec) 2932#define has_amd_full_remap_support(codec) is_amdhdmi_rev3_or_later(codec)
2945 2933
2946/* ATI/AMD specific HDA pin verbs, see the AMD HDA Verbs specification */ 2934/* ATI/AMD specific HDA pin verbs, see the AMD HDA Verbs specification */
@@ -3301,15 +3289,6 @@ static int patch_via_hdmi(struct hda_codec *codec)
3301} 3289}
3302 3290
3303/* 3291/*
3304 * called from hda_codec.c for generic HDMI support
3305 */
3306int snd_hda_parse_hdmi_codec(struct hda_codec *codec)
3307{
3308 return patch_generic_hdmi(codec);
3309}
3310EXPORT_SYMBOL_GPL(snd_hda_parse_hdmi_codec);
3311
3312/*
3313 * patch entries 3292 * patch entries
3314 */ 3293 */
3315static const struct hda_codec_preset snd_hda_preset_hdmi[] = { 3294static const struct hda_codec_preset snd_hda_preset_hdmi[] = {
@@ -3373,6 +3352,8 @@ static const struct hda_codec_preset snd_hda_preset_hdmi[] = {
3373{ .id = 0x80862882, .name = "Valleyview2 HDMI", .patch = patch_generic_hdmi }, 3352{ .id = 0x80862882, .name = "Valleyview2 HDMI", .patch = patch_generic_hdmi },
3374{ .id = 0x80862883, .name = "Braswell HDMI", .patch = patch_generic_hdmi }, 3353{ .id = 0x80862883, .name = "Braswell HDMI", .patch = patch_generic_hdmi },
3375{ .id = 0x808629fb, .name = "Crestline HDMI", .patch = patch_generic_hdmi }, 3354{ .id = 0x808629fb, .name = "Crestline HDMI", .patch = patch_generic_hdmi },
3355/* special ID for generic HDMI */
3356{ .id = HDA_CODEC_ID_GENERIC_HDMI, .patch = patch_generic_hdmi },
3376{} /* terminator */ 3357{} /* terminator */
3377}; 3358};
3378 3359
@@ -3442,20 +3423,8 @@ MODULE_ALIAS("snd-hda-codec-intelhdmi");
3442MODULE_ALIAS("snd-hda-codec-nvhdmi"); 3423MODULE_ALIAS("snd-hda-codec-nvhdmi");
3443MODULE_ALIAS("snd-hda-codec-atihdmi"); 3424MODULE_ALIAS("snd-hda-codec-atihdmi");
3444 3425
3445static struct hda_codec_preset_list intel_list = { 3426static struct hda_codec_driver hdmi_driver = {
3446 .preset = snd_hda_preset_hdmi, 3427 .preset = snd_hda_preset_hdmi,
3447 .owner = THIS_MODULE,
3448}; 3428};
3449 3429
3450static int __init patch_hdmi_init(void) 3430module_hda_codec_driver(hdmi_driver);
3451{
3452 return snd_hda_add_codec_preset(&intel_list);
3453}
3454
3455static void __exit patch_hdmi_exit(void)
3456{
3457 snd_hda_delete_codec_preset(&intel_list);
3458}
3459
3460module_init(patch_hdmi_init)
3461module_exit(patch_hdmi_exit)
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 74382137b9f5..06199e4e930f 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -299,7 +299,7 @@ static void alc_fill_eapd_coef(struct hda_codec *codec)
299 299
300 coef = alc_get_coef0(codec); 300 coef = alc_get_coef0(codec);
301 301
302 switch (codec->vendor_id) { 302 switch (codec->core.vendor_id) {
303 case 0x10ec0262: 303 case 0x10ec0262:
304 alc_update_coef_idx(codec, 0x7, 0, 1<<5); 304 alc_update_coef_idx(codec, 0x7, 0, 1<<5);
305 break; 305 break;
@@ -432,7 +432,7 @@ static void alc_auto_init_amp(struct hda_codec *codec, int type)
432 snd_hda_sequence_write(codec, alc_gpio3_init_verbs); 432 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
433 break; 433 break;
434 case ALC_INIT_DEFAULT: 434 case ALC_INIT_DEFAULT:
435 switch (codec->vendor_id) { 435 switch (codec->core.vendor_id) {
436 case 0x10ec0260: 436 case 0x10ec0260:
437 alc_update_coefex_idx(codec, 0x1a, 7, 0, 0x2010); 437 alc_update_coefex_idx(codec, 0x1a, 7, 0, 0x2010);
438 break; 438 break;
@@ -498,18 +498,18 @@ static int alc_auto_parse_customize_define(struct hda_codec *codec)
498 498
499 if (!codec->bus->pci) 499 if (!codec->bus->pci)
500 return -1; 500 return -1;
501 ass = codec->subsystem_id & 0xffff; 501 ass = codec->core.subsystem_id & 0xffff;
502 if (ass != codec->bus->pci->subsystem_device && (ass & 1)) 502 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
503 goto do_sku; 503 goto do_sku;
504 504
505 nid = 0x1d; 505 nid = 0x1d;
506 if (codec->vendor_id == 0x10ec0260) 506 if (codec->core.vendor_id == 0x10ec0260)
507 nid = 0x17; 507 nid = 0x17;
508 ass = snd_hda_codec_get_pincfg(codec, nid); 508 ass = snd_hda_codec_get_pincfg(codec, nid);
509 509
510 if (!(ass & 1)) { 510 if (!(ass & 1)) {
511 codec_info(codec, "%s: SKU not ready 0x%08x\n", 511 codec_info(codec, "%s: SKU not ready 0x%08x\n",
512 codec->chip_name, ass); 512 codec->core.chip_name, ass);
513 return -1; 513 return -1;
514 } 514 }
515 515
@@ -585,7 +585,7 @@ static int alc_subsystem_id(struct hda_codec *codec, const hda_nid_t *ports)
585 goto do_sku; 585 goto do_sku;
586 } 586 }
587 587
588 ass = codec->subsystem_id & 0xffff; 588 ass = codec->core.subsystem_id & 0xffff;
589 if (codec->bus->pci && 589 if (codec->bus->pci &&
590 ass != codec->bus->pci->subsystem_device && (ass & 1)) 590 ass != codec->bus->pci->subsystem_device && (ass & 1))
591 goto do_sku; 591 goto do_sku;
@@ -600,7 +600,7 @@ static int alc_subsystem_id(struct hda_codec *codec, const hda_nid_t *ports)
600 * 0 : override 600 * 0 : override
601 */ 601 */
602 nid = 0x1d; 602 nid = 0x1d;
603 if (codec->vendor_id == 0x10ec0260) 603 if (codec->core.vendor_id == 0x10ec0260)
604 nid = 0x17; 604 nid = 0x17;
605 ass = snd_hda_codec_get_pincfg(codec, nid); 605 ass = snd_hda_codec_get_pincfg(codec, nid);
606 codec_dbg(codec, 606 codec_dbg(codec,
@@ -621,7 +621,7 @@ static int alc_subsystem_id(struct hda_codec *codec, const hda_nid_t *ports)
621 return 0; 621 return 0;
622do_sku: 622do_sku:
623 codec_dbg(codec, "realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n", 623 codec_dbg(codec, "realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
624 ass & 0xffff, codec->vendor_id); 624 ass & 0xffff, codec->core.vendor_id);
625 /* 625 /*
626 * 0 : override 626 * 0 : override
627 * 1 : Swap Jack 627 * 1 : Swap Jack
@@ -799,8 +799,7 @@ static int alc_resume(struct hda_codec *codec)
799 if (!spec->no_depop_delay) 799 if (!spec->no_depop_delay)
800 msleep(150); /* to avoid pop noise */ 800 msleep(150); /* to avoid pop noise */
801 codec->patch_ops.init(codec); 801 codec->patch_ops.init(codec);
802 snd_hda_codec_resume_amp(codec); 802 regcache_sync(codec->core.regmap);
803 snd_hda_codec_resume_cache(codec);
804 hda_call_check_power_status(codec, 0x01); 803 hda_call_check_power_status(codec, 0x01);
805 return 0; 804 return 0;
806} 805}
@@ -826,9 +825,9 @@ static const struct hda_codec_ops alc_patch_ops = {
826/* replace the codec chip_name with the given string */ 825/* replace the codec chip_name with the given string */
827static int alc_codec_rename(struct hda_codec *codec, const char *name) 826static int alc_codec_rename(struct hda_codec *codec, const char *name)
828{ 827{
829 kfree(codec->chip_name); 828 kfree(codec->core.chip_name);
830 codec->chip_name = kstrdup(name, GFP_KERNEL); 829 codec->core.chip_name = kstrdup(name, GFP_KERNEL);
831 if (!codec->chip_name) { 830 if (!codec->core.chip_name) {
832 alc_free(codec); 831 alc_free(codec);
833 return -ENOMEM; 832 return -ENOMEM;
834 } 833 }
@@ -904,7 +903,7 @@ static int alc_codec_rename_from_preset(struct hda_codec *codec)
904 const struct alc_codec_rename_pci_table *q; 903 const struct alc_codec_rename_pci_table *q;
905 904
906 for (p = rename_tbl; p->vendor_id; p++) { 905 for (p = rename_tbl; p->vendor_id; p++) {
907 if (p->vendor_id != codec->vendor_id) 906 if (p->vendor_id != codec->core.vendor_id)
908 continue; 907 continue;
909 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits) 908 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
910 return alc_codec_rename(codec, p->name); 909 return alc_codec_rename(codec, p->name);
@@ -913,7 +912,7 @@ static int alc_codec_rename_from_preset(struct hda_codec *codec)
913 if (!codec->bus->pci) 912 if (!codec->bus->pci)
914 return 0; 913 return 0;
915 for (q = rename_pci_tbl; q->codec_vendor_id; q++) { 914 for (q = rename_pci_tbl; q->codec_vendor_id; q++) {
916 if (q->codec_vendor_id != codec->vendor_id) 915 if (q->codec_vendor_id != codec->core.vendor_id)
917 continue; 916 continue;
918 if (q->pci_subvendor != codec->bus->pci->subsystem_vendor) 917 if (q->pci_subvendor != codec->bus->pci->subsystem_vendor)
919 continue; 918 continue;
@@ -1785,7 +1784,7 @@ static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
1785{ 1784{
1786 unsigned int gpiostate, gpiomask, gpiodir; 1785 unsigned int gpiostate, gpiomask, gpiodir;
1787 1786
1788 gpiostate = snd_hda_codec_read(codec, codec->afg, 0, 1787 gpiostate = snd_hda_codec_read(codec, codec->core.afg, 0,
1789 AC_VERB_GET_GPIO_DATA, 0); 1788 AC_VERB_GET_GPIO_DATA, 0);
1790 1789
1791 if (!muted) 1790 if (!muted)
@@ -1793,23 +1792,23 @@ static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
1793 else 1792 else
1794 gpiostate &= ~(1 << pin); 1793 gpiostate &= ~(1 << pin);
1795 1794
1796 gpiomask = snd_hda_codec_read(codec, codec->afg, 0, 1795 gpiomask = snd_hda_codec_read(codec, codec->core.afg, 0,
1797 AC_VERB_GET_GPIO_MASK, 0); 1796 AC_VERB_GET_GPIO_MASK, 0);
1798 gpiomask |= (1 << pin); 1797 gpiomask |= (1 << pin);
1799 1798
1800 gpiodir = snd_hda_codec_read(codec, codec->afg, 0, 1799 gpiodir = snd_hda_codec_read(codec, codec->core.afg, 0,
1801 AC_VERB_GET_GPIO_DIRECTION, 0); 1800 AC_VERB_GET_GPIO_DIRECTION, 0);
1802 gpiodir |= (1 << pin); 1801 gpiodir |= (1 << pin);
1803 1802
1804 1803
1805 snd_hda_codec_write(codec, codec->afg, 0, 1804 snd_hda_codec_write(codec, codec->core.afg, 0,
1806 AC_VERB_SET_GPIO_MASK, gpiomask); 1805 AC_VERB_SET_GPIO_MASK, gpiomask);
1807 snd_hda_codec_write(codec, codec->afg, 0, 1806 snd_hda_codec_write(codec, codec->core.afg, 0,
1808 AC_VERB_SET_GPIO_DIRECTION, gpiodir); 1807 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
1809 1808
1810 msleep(1); 1809 msleep(1);
1811 1810
1812 snd_hda_codec_write(codec, codec->afg, 0, 1811 snd_hda_codec_write(codec, codec->core.afg, 0,
1813 AC_VERB_SET_GPIO_DATA, gpiostate); 1812 AC_VERB_SET_GPIO_DATA, gpiostate);
1814} 1813}
1815 1814
@@ -2269,7 +2268,7 @@ static int patch_alc882(struct hda_codec *codec)
2269 2268
2270 spec = codec->spec; 2269 spec = codec->spec;
2271 2270
2272 switch (codec->vendor_id) { 2271 switch (codec->core.vendor_id) {
2273 case 0x10ec0882: 2272 case 0x10ec0882:
2274 case 0x10ec0885: 2273 case 0x10ec0885:
2275 case 0x10ec0900: 2274 case 0x10ec0900:
@@ -2602,53 +2601,12 @@ static int patch_alc268(struct hda_codec *codec)
2602 * ALC269 2601 * ALC269
2603 */ 2602 */
2604 2603
2605static int playback_pcm_open(struct hda_pcm_stream *hinfo,
2606 struct hda_codec *codec,
2607 struct snd_pcm_substream *substream)
2608{
2609 struct hda_gen_spec *spec = codec->spec;
2610 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2611 hinfo);
2612}
2613
2614static int playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2615 struct hda_codec *codec,
2616 unsigned int stream_tag,
2617 unsigned int format,
2618 struct snd_pcm_substream *substream)
2619{
2620 struct hda_gen_spec *spec = codec->spec;
2621 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2622 stream_tag, format, substream);
2623}
2624
2625static int playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2626 struct hda_codec *codec,
2627 struct snd_pcm_substream *substream)
2628{
2629 struct hda_gen_spec *spec = codec->spec;
2630 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2631}
2632
2633static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = { 2604static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
2634 .substreams = 1,
2635 .channels_min = 2,
2636 .channels_max = 8,
2637 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */ 2605 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
2638 /* NID is set in alc_build_pcms */
2639 .ops = {
2640 .open = playback_pcm_open,
2641 .prepare = playback_pcm_prepare,
2642 .cleanup = playback_pcm_cleanup
2643 },
2644}; 2606};
2645 2607
2646static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = { 2608static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
2647 .substreams = 1,
2648 .channels_min = 2,
2649 .channels_max = 2,
2650 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */ 2609 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
2651 /* NID is set in alc_build_pcms */
2652}; 2610};
2653 2611
2654/* different alc269-variants */ 2612/* different alc269-variants */
@@ -2912,6 +2870,8 @@ static void alc283_init(struct hda_codec *codec)
2912 2870
2913 if (!hp_pin) 2871 if (!hp_pin)
2914 return; 2872 return;
2873
2874 msleep(30);
2915 hp_pin_sense = snd_hda_jack_detect(codec, hp_pin); 2875 hp_pin_sense = snd_hda_jack_detect(codec, hp_pin);
2916 2876
2917 /* Index 0x43 Direct Drive HP AMP LPM Control 1 */ 2877 /* Index 0x43 Direct Drive HP AMP LPM Control 1 */
@@ -3099,8 +3059,7 @@ static int alc269_resume(struct hda_codec *codec)
3099 msleep(200); 3059 msleep(200);
3100 } 3060 }
3101 3061
3102 snd_hda_codec_resume_amp(codec); 3062 regcache_sync(codec->core.regmap);
3103 snd_hda_codec_resume_cache(codec);
3104 hda_call_check_power_status(codec, 0x01); 3063 hda_call_check_power_status(codec, 0x01);
3105 3064
3106 /* on some machine, the BIOS will clear the codec gpio data when enter 3065 /* on some machine, the BIOS will clear the codec gpio data when enter
@@ -3108,7 +3067,7 @@ static int alc269_resume(struct hda_codec *codec)
3108 * in the driver. 3067 * in the driver.
3109 */ 3068 */
3110 if (spec->gpio_led) 3069 if (spec->gpio_led)
3111 snd_hda_codec_write(codec, codec->afg, 0, AC_VERB_SET_GPIO_DATA, 3070 snd_hda_codec_write(codec, codec->core.afg, 0, AC_VERB_SET_GPIO_DATA,
3112 spec->gpio_led); 3071 spec->gpio_led);
3113 3072
3114 if (spec->has_alc5505_dsp) 3073 if (spec->has_alc5505_dsp)
@@ -3153,8 +3112,8 @@ static void alc271_fixup_dmic(struct hda_codec *codec,
3153 }; 3112 };
3154 unsigned int cfg; 3113 unsigned int cfg;
3155 3114
3156 if (strcmp(codec->chip_name, "ALC271X") && 3115 if (strcmp(codec->core.chip_name, "ALC271X") &&
3157 strcmp(codec->chip_name, "ALC269VB")) 3116 strcmp(codec->core.chip_name, "ALC269VB"))
3158 return; 3117 return;
3159 cfg = snd_hda_codec_get_pincfg(codec, 0x12); 3118 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
3160 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED) 3119 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
@@ -3264,7 +3223,7 @@ static unsigned int led_power_filter(struct hda_codec *codec,
3264 snd_hda_set_pin_ctl(codec, nid, 3223 snd_hda_set_pin_ctl(codec, nid,
3265 snd_hda_codec_get_pin_target(codec, nid)); 3224 snd_hda_codec_get_pin_target(codec, nid));
3266 3225
3267 return AC_PWRST_D0; 3226 return snd_hda_gen_path_power_filter(codec, nid, power_state);
3268} 3227}
3269 3228
3270static void alc269_fixup_hp_mute_led(struct hda_codec *codec, 3229static void alc269_fixup_hp_mute_led(struct hda_codec *codec,
@@ -3520,9 +3479,9 @@ static void alc280_fixup_hp_gpio2_mic_hotkey(struct hda_codec *codec,
3520 } 3479 }
3521 3480
3522 snd_hda_add_verbs(codec, gpio_init); 3481 snd_hda_add_verbs(codec, gpio_init);
3523 snd_hda_codec_write_cache(codec, codec->afg, 0, 3482 snd_hda_codec_write_cache(codec, codec->core.afg, 0,
3524 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x04); 3483 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x04);
3525 snd_hda_jack_detect_enable_callback(codec, codec->afg, 3484 snd_hda_jack_detect_enable_callback(codec, codec->core.afg,
3526 gpio2_mic_hotkey_event); 3485 gpio2_mic_hotkey_event);
3527 3486
3528 spec->gen.vmaster_mute.hook = alc_fixup_gpio_mute_hook; 3487 spec->gen.vmaster_mute.hook = alc_fixup_gpio_mute_hook;
@@ -3583,6 +3542,14 @@ static void alc_headset_mode_unplugged(struct hda_codec *codec)
3583 WRITE_COEF(0x32, 0x42a3), 3542 WRITE_COEF(0x32, 0x42a3),
3584 {} 3543 {}
3585 }; 3544 };
3545 static struct coef_fw coef0288[] = {
3546 UPDATE_COEF(0x4f, 0xfcc0, 0xc400),
3547 UPDATE_COEF(0x50, 0x2000, 0x2000),
3548 UPDATE_COEF(0x56, 0x0006, 0x0006),
3549 UPDATE_COEF(0x66, 0x0008, 0),
3550 UPDATE_COEF(0x67, 0x2000, 0),
3551 {}
3552 };
3586 static struct coef_fw coef0292[] = { 3553 static struct coef_fw coef0292[] = {
3587 WRITE_COEF(0x76, 0x000e), 3554 WRITE_COEF(0x76, 0x000e),
3588 WRITE_COEF(0x6c, 0x2400), 3555 WRITE_COEF(0x6c, 0x2400),
@@ -3605,14 +3572,19 @@ static void alc_headset_mode_unplugged(struct hda_codec *codec)
3605 {} 3572 {}
3606 }; 3573 };
3607 3574
3608 switch (codec->vendor_id) { 3575 switch (codec->core.vendor_id) {
3609 case 0x10ec0255: 3576 case 0x10ec0255:
3577 case 0x10ec0256:
3610 alc_process_coef_fw(codec, coef0255); 3578 alc_process_coef_fw(codec, coef0255);
3611 break; 3579 break;
3612 case 0x10ec0233: 3580 case 0x10ec0233:
3613 case 0x10ec0283: 3581 case 0x10ec0283:
3614 alc_process_coef_fw(codec, coef0233); 3582 alc_process_coef_fw(codec, coef0233);
3615 break; 3583 break;
3584 case 0x10ec0286:
3585 case 0x10ec0288:
3586 alc_process_coef_fw(codec, coef0288);
3587 break;
3616 case 0x10ec0292: 3588 case 0x10ec0292:
3617 alc_process_coef_fw(codec, coef0292); 3589 alc_process_coef_fw(codec, coef0292);
3618 break; 3590 break;
@@ -3642,6 +3614,14 @@ static void alc_headset_mode_mic_in(struct hda_codec *codec, hda_nid_t hp_pin,
3642 WRITE_COEF(0x26, 0x008c), 3614 WRITE_COEF(0x26, 0x008c),
3643 {} 3615 {}
3644 }; 3616 };
3617 static struct coef_fw coef0288[] = {
3618 UPDATE_COEF(0x50, 0x2000, 0),
3619 UPDATE_COEF(0x56, 0x0006, 0),
3620 UPDATE_COEF(0x4f, 0xfcc0, 0xc400),
3621 UPDATE_COEF(0x66, 0x0008, 0x0008),
3622 UPDATE_COEF(0x67, 0x2000, 0x2000),
3623 {}
3624 };
3645 static struct coef_fw coef0292[] = { 3625 static struct coef_fw coef0292[] = {
3646 WRITE_COEF(0x19, 0xa208), 3626 WRITE_COEF(0x19, 0xa208),
3647 WRITE_COEF(0x2e, 0xacf0), 3627 WRITE_COEF(0x2e, 0xacf0),
@@ -3660,8 +3640,9 @@ static void alc_headset_mode_mic_in(struct hda_codec *codec, hda_nid_t hp_pin,
3660 {} 3640 {}
3661 }; 3641 };
3662 3642
3663 switch (codec->vendor_id) { 3643 switch (codec->core.vendor_id) {
3664 case 0x10ec0255: 3644 case 0x10ec0255:
3645 case 0x10ec0256:
3665 alc_write_coef_idx(codec, 0x45, 0xc489); 3646 alc_write_coef_idx(codec, 0x45, 0xc489);
3666 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0); 3647 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
3667 alc_process_coef_fw(codec, coef0255); 3648 alc_process_coef_fw(codec, coef0255);
@@ -3674,6 +3655,13 @@ static void alc_headset_mode_mic_in(struct hda_codec *codec, hda_nid_t hp_pin,
3674 alc_process_coef_fw(codec, coef0233); 3655 alc_process_coef_fw(codec, coef0233);
3675 snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50); 3656 snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50);
3676 break; 3657 break;
3658 case 0x10ec0286:
3659 case 0x10ec0288:
3660 alc_update_coef_idx(codec, 0x4f, 0x000c, 0);
3661 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
3662 alc_process_coef_fw(codec, coef0288);
3663 snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50);
3664 break;
3677 case 0x10ec0292: 3665 case 0x10ec0292:
3678 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0); 3666 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
3679 alc_process_coef_fw(codec, coef0292); 3667 alc_process_coef_fw(codec, coef0292);
@@ -3709,6 +3697,14 @@ static void alc_headset_mode_default(struct hda_codec *codec)
3709 WRITE_COEF(0x32, 0x4ea3), 3697 WRITE_COEF(0x32, 0x4ea3),
3710 {} 3698 {}
3711 }; 3699 };
3700 static struct coef_fw coef0288[] = {
3701 UPDATE_COEF(0x4f, 0xfcc0, 0xc400), /* Set to TRS type */
3702 UPDATE_COEF(0x50, 0x2000, 0x2000),
3703 UPDATE_COEF(0x56, 0x0006, 0x0006),
3704 UPDATE_COEF(0x66, 0x0008, 0),
3705 UPDATE_COEF(0x67, 0x2000, 0),
3706 {}
3707 };
3712 static struct coef_fw coef0292[] = { 3708 static struct coef_fw coef0292[] = {
3713 WRITE_COEF(0x76, 0x000e), 3709 WRITE_COEF(0x76, 0x000e),
3714 WRITE_COEF(0x6c, 0x2400), 3710 WRITE_COEF(0x6c, 0x2400),
@@ -3729,14 +3725,20 @@ static void alc_headset_mode_default(struct hda_codec *codec)
3729 {} 3725 {}
3730 }; 3726 };
3731 3727
3732 switch (codec->vendor_id) { 3728 switch (codec->core.vendor_id) {
3733 case 0x10ec0255: 3729 case 0x10ec0255:
3730 case 0x10ec0256:
3734 alc_process_coef_fw(codec, coef0255); 3731 alc_process_coef_fw(codec, coef0255);
3735 break; 3732 break;
3736 case 0x10ec0233: 3733 case 0x10ec0233:
3737 case 0x10ec0283: 3734 case 0x10ec0283:
3738 alc_process_coef_fw(codec, coef0233); 3735 alc_process_coef_fw(codec, coef0233);
3739 break; 3736 break;
3737 case 0x10ec0286:
3738 case 0x10ec0288:
3739 alc_process_coef_fw(codec, coef0288);
3740 break;
3741 break;
3740 case 0x10ec0292: 3742 case 0x10ec0292:
3741 alc_process_coef_fw(codec, coef0292); 3743 alc_process_coef_fw(codec, coef0292);
3742 break; 3744 break;
@@ -3765,6 +3767,13 @@ static void alc_headset_mode_ctia(struct hda_codec *codec)
3765 WRITE_COEF(0x32, 0x4ea3), 3767 WRITE_COEF(0x32, 0x4ea3),
3766 {} 3768 {}
3767 }; 3769 };
3770 static struct coef_fw coef0288[] = {
3771 UPDATE_COEF(0x50, 0x2000, 0x2000),
3772 UPDATE_COEF(0x56, 0x0006, 0x0006),
3773 UPDATE_COEF(0x66, 0x0008, 0),
3774 UPDATE_COEF(0x67, 0x2000, 0),
3775 {}
3776 };
3768 static struct coef_fw coef0292[] = { 3777 static struct coef_fw coef0292[] = {
3769 WRITE_COEF(0x6b, 0xd429), 3778 WRITE_COEF(0x6b, 0xd429),
3770 WRITE_COEF(0x76, 0x0008), 3779 WRITE_COEF(0x76, 0x0008),
@@ -3783,14 +3792,21 @@ static void alc_headset_mode_ctia(struct hda_codec *codec)
3783 {} 3792 {}
3784 }; 3793 };
3785 3794
3786 switch (codec->vendor_id) { 3795 switch (codec->core.vendor_id) {
3787 case 0x10ec0255: 3796 case 0x10ec0255:
3797 case 0x10ec0256:
3788 alc_process_coef_fw(codec, coef0255); 3798 alc_process_coef_fw(codec, coef0255);
3789 break; 3799 break;
3790 case 0x10ec0233: 3800 case 0x10ec0233:
3791 case 0x10ec0283: 3801 case 0x10ec0283:
3792 alc_process_coef_fw(codec, coef0233); 3802 alc_process_coef_fw(codec, coef0233);
3793 break; 3803 break;
3804 case 0x10ec0286:
3805 case 0x10ec0288:
3806 alc_update_coef_idx(codec, 0x4f, 0xfcc0, 0xd400);
3807 msleep(300);
3808 alc_process_coef_fw(codec, coef0288);
3809 break;
3794 case 0x10ec0292: 3810 case 0x10ec0292:
3795 alc_process_coef_fw(codec, coef0292); 3811 alc_process_coef_fw(codec, coef0292);
3796 break; 3812 break;
@@ -3819,6 +3835,13 @@ static void alc_headset_mode_omtp(struct hda_codec *codec)
3819 WRITE_COEF(0x32, 0x4ea3), 3835 WRITE_COEF(0x32, 0x4ea3),
3820 {} 3836 {}
3821 }; 3837 };
3838 static struct coef_fw coef0288[] = {
3839 UPDATE_COEF(0x50, 0x2000, 0x2000),
3840 UPDATE_COEF(0x56, 0x0006, 0x0006),
3841 UPDATE_COEF(0x66, 0x0008, 0),
3842 UPDATE_COEF(0x67, 0x2000, 0),
3843 {}
3844 };
3822 static struct coef_fw coef0292[] = { 3845 static struct coef_fw coef0292[] = {
3823 WRITE_COEF(0x6b, 0xe429), 3846 WRITE_COEF(0x6b, 0xe429),
3824 WRITE_COEF(0x76, 0x0008), 3847 WRITE_COEF(0x76, 0x0008),
@@ -3837,14 +3860,21 @@ static void alc_headset_mode_omtp(struct hda_codec *codec)
3837 {} 3860 {}
3838 }; 3861 };
3839 3862
3840 switch (codec->vendor_id) { 3863 switch (codec->core.vendor_id) {
3841 case 0x10ec0255: 3864 case 0x10ec0255:
3865 case 0x10ec0256:
3842 alc_process_coef_fw(codec, coef0255); 3866 alc_process_coef_fw(codec, coef0255);
3843 break; 3867 break;
3844 case 0x10ec0233: 3868 case 0x10ec0233:
3845 case 0x10ec0283: 3869 case 0x10ec0283:
3846 alc_process_coef_fw(codec, coef0233); 3870 alc_process_coef_fw(codec, coef0233);
3847 break; 3871 break;
3872 case 0x10ec0286:
3873 case 0x10ec0288:
3874 alc_update_coef_idx(codec, 0x4f, 0xfcc0, 0xe400);
3875 msleep(300);
3876 alc_process_coef_fw(codec, coef0288);
3877 break;
3848 case 0x10ec0292: 3878 case 0x10ec0292:
3849 alc_process_coef_fw(codec, coef0292); 3879 alc_process_coef_fw(codec, coef0292);
3850 break; 3880 break;
@@ -3869,6 +3899,10 @@ static void alc_determine_headset_type(struct hda_codec *codec)
3869 conteol) */ 3899 conteol) */
3870 {} 3900 {}
3871 }; 3901 };
3902 static struct coef_fw coef0288[] = {
3903 UPDATE_COEF(0x4f, 0xfcc0, 0xd400), /* Check Type */
3904 {}
3905 };
3872 static struct coef_fw coef0293[] = { 3906 static struct coef_fw coef0293[] = {
3873 UPDATE_COEF(0x4a, 0x000f, 0x0008), /* Combo Jack auto detect */ 3907 UPDATE_COEF(0x4a, 0x000f, 0x0008), /* Combo Jack auto detect */
3874 WRITE_COEF(0x45, 0xD429), /* Set to ctia type */ 3908 WRITE_COEF(0x45, 0xD429), /* Set to ctia type */
@@ -3882,8 +3916,9 @@ static void alc_determine_headset_type(struct hda_codec *codec)
3882 {} 3916 {}
3883 }; 3917 };
3884 3918
3885 switch (codec->vendor_id) { 3919 switch (codec->core.vendor_id) {
3886 case 0x10ec0255: 3920 case 0x10ec0255:
3921 case 0x10ec0256:
3887 alc_process_coef_fw(codec, coef0255); 3922 alc_process_coef_fw(codec, coef0255);
3888 msleep(300); 3923 msleep(300);
3889 val = alc_read_coef_idx(codec, 0x46); 3924 val = alc_read_coef_idx(codec, 0x46);
@@ -3896,6 +3931,13 @@ static void alc_determine_headset_type(struct hda_codec *codec)
3896 val = alc_read_coef_idx(codec, 0x46); 3931 val = alc_read_coef_idx(codec, 0x46);
3897 is_ctia = (val & 0x0070) == 0x0070; 3932 is_ctia = (val & 0x0070) == 0x0070;
3898 break; 3933 break;
3934 case 0x10ec0286:
3935 case 0x10ec0288:
3936 alc_process_coef_fw(codec, coef0288);
3937 msleep(350);
3938 val = alc_read_coef_idx(codec, 0x50);
3939 is_ctia = (val & 0x0070) == 0x0070;
3940 break;
3899 case 0x10ec0292: 3941 case 0x10ec0292:
3900 alc_write_coef_idx(codec, 0x6b, 0xd429); 3942 alc_write_coef_idx(codec, 0x6b, 0xd429);
3901 msleep(300); 3943 msleep(300);
@@ -4079,6 +4121,29 @@ static void alc_fixup_headset_mode_alc255_no_hp_mic(struct hda_codec *codec,
4079 alc_fixup_headset_mode(codec, fix, action); 4121 alc_fixup_headset_mode(codec, fix, action);
4080} 4122}
4081 4123
4124static void alc288_update_headset_jack_cb(struct hda_codec *codec,
4125 struct hda_jack_callback *jack)
4126{
4127 struct alc_spec *spec = codec->spec;
4128 int present;
4129
4130 alc_update_headset_jack_cb(codec, jack);
4131 /* Headset Mic enable or disable, only for Dell Dino */
4132 present = spec->gen.hp_jack_present ? 0x40 : 0;
4133 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4134 present);
4135}
4136
4137static void alc_fixup_headset_mode_dell_alc288(struct hda_codec *codec,
4138 const struct hda_fixup *fix, int action)
4139{
4140 alc_fixup_headset_mode(codec, fix, action);
4141 if (action == HDA_FIXUP_ACT_PROBE) {
4142 struct alc_spec *spec = codec->spec;
4143 spec->gen.hp_automute_hook = alc288_update_headset_jack_cb;
4144 }
4145}
4146
4082static void alc_fixup_auto_mute_via_amp(struct hda_codec *codec, 4147static void alc_fixup_auto_mute_via_amp(struct hda_codec *codec,
4083 const struct hda_fixup *fix, int action) 4148 const struct hda_fixup *fix, int action)
4084{ 4149{
@@ -4111,17 +4176,15 @@ static void alc_fixup_disable_aamix(struct hda_codec *codec,
4111 } 4176 }
4112} 4177}
4113 4178
4114static unsigned int alc_power_filter_xps13(struct hda_codec *codec, 4179static void alc_shutup_dell_xps13(struct hda_codec *codec)
4115 hda_nid_t nid,
4116 unsigned int power_state)
4117{ 4180{
4118 struct alc_spec *spec = codec->spec; 4181 struct alc_spec *spec = codec->spec;
4182 int hp_pin = spec->gen.autocfg.hp_pins[0];
4119 4183
4120 /* Avoid pop noises when headphones are plugged in */ 4184 /* Prevent pop noises when headphones are plugged in */
4121 if (spec->gen.hp_jack_present) 4185 snd_hda_codec_write(codec, hp_pin, 0,
4122 if (nid == codec->afg || nid == 0x02 || nid == 0x15) 4186 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
4123 return AC_PWRST_D0; 4187 msleep(20);
4124 return power_state;
4125} 4188}
4126 4189
4127static void alc_fixup_dell_xps13(struct hda_codec *codec, 4190static void alc_fixup_dell_xps13(struct hda_codec *codec,
@@ -4132,8 +4195,7 @@ static void alc_fixup_dell_xps13(struct hda_codec *codec,
4132 struct hda_input_mux *imux = &spec->gen.input_mux; 4195 struct hda_input_mux *imux = &spec->gen.input_mux;
4133 int i; 4196 int i;
4134 4197
4135 spec->shutup = alc_no_shutup; 4198 spec->shutup = alc_shutup_dell_xps13;
4136 codec->power_filter = alc_power_filter_xps13;
4137 4199
4138 /* Make the internal mic the default input source. */ 4200 /* Make the internal mic the default input source. */
4139 for (i = 0; i < imux->num_items; i++) { 4201 for (i = 0; i < imux->num_items; i++) {
@@ -4364,6 +4426,7 @@ enum {
4364 ALC269_FIXUP_QUANTA_MUTE, 4426 ALC269_FIXUP_QUANTA_MUTE,
4365 ALC269_FIXUP_LIFEBOOK, 4427 ALC269_FIXUP_LIFEBOOK,
4366 ALC269_FIXUP_LIFEBOOK_EXTMIC, 4428 ALC269_FIXUP_LIFEBOOK_EXTMIC,
4429 ALC269_FIXUP_LIFEBOOK_HP_PIN,
4367 ALC269_FIXUP_AMIC, 4430 ALC269_FIXUP_AMIC,
4368 ALC269_FIXUP_DMIC, 4431 ALC269_FIXUP_DMIC,
4369 ALC269VB_FIXUP_AMIC, 4432 ALC269VB_FIXUP_AMIC,
@@ -4418,6 +4481,9 @@ enum {
4418 ALC286_FIXUP_HP_GPIO_LED, 4481 ALC286_FIXUP_HP_GPIO_LED,
4419 ALC280_FIXUP_HP_GPIO2_MIC_HOTKEY, 4482 ALC280_FIXUP_HP_GPIO2_MIC_HOTKEY,
4420 ALC280_FIXUP_HP_DOCK_PINS, 4483 ALC280_FIXUP_HP_DOCK_PINS,
4484 ALC288_FIXUP_DELL_HEADSET_MODE,
4485 ALC288_FIXUP_DELL1_MIC_NO_PRESENCE,
4486 ALC288_FIXUP_DELL_XPS_13_GPIO6,
4421}; 4487};
4422 4488
4423static const struct hda_fixup alc269_fixups[] = { 4489static const struct hda_fixup alc269_fixups[] = {
@@ -4517,6 +4583,13 @@ static const struct hda_fixup alc269_fixups[] = {
4517 { } 4583 { }
4518 }, 4584 },
4519 }, 4585 },
4586 [ALC269_FIXUP_LIFEBOOK_HP_PIN] = {
4587 .type = HDA_FIXUP_PINS,
4588 .v.pins = (const struct hda_pintbl[]) {
4589 { 0x21, 0x0221102f }, /* HP out */
4590 { }
4591 },
4592 },
4520 [ALC269_FIXUP_AMIC] = { 4593 [ALC269_FIXUP_AMIC] = {
4521 .type = HDA_FIXUP_PINS, 4594 .type = HDA_FIXUP_PINS,
4522 .v.pins = (const struct hda_pintbl[]) { 4595 .v.pins = (const struct hda_pintbl[]) {
@@ -4906,6 +4979,33 @@ static const struct hda_fixup alc269_fixups[] = {
4906 .chained = true, 4979 .chained = true,
4907 .chain_id = ALC280_FIXUP_HP_GPIO4 4980 .chain_id = ALC280_FIXUP_HP_GPIO4
4908 }, 4981 },
4982 [ALC288_FIXUP_DELL_HEADSET_MODE] = {
4983 .type = HDA_FIXUP_FUNC,
4984 .v.func = alc_fixup_headset_mode_dell_alc288,
4985 .chained = true,
4986 .chain_id = ALC255_FIXUP_DELL_WMI_MIC_MUTE_LED
4987 },
4988 [ALC288_FIXUP_DELL1_MIC_NO_PRESENCE] = {
4989 .type = HDA_FIXUP_PINS,
4990 .v.pins = (const struct hda_pintbl[]) {
4991 { 0x18, 0x01a1913c }, /* use as headset mic, without its own jack detect */
4992 { 0x1a, 0x01a1913d }, /* use as headphone mic, without its own jack detect */
4993 { }
4994 },
4995 .chained = true,
4996 .chain_id = ALC288_FIXUP_DELL_HEADSET_MODE
4997 },
4998 [ALC288_FIXUP_DELL_XPS_13_GPIO6] = {
4999 .type = HDA_FIXUP_VERBS,
5000 .v.verbs = (const struct hda_verb[]) {
5001 {0x01, AC_VERB_SET_GPIO_MASK, 0x40},
5002 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x40},
5003 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5004 { }
5005 },
5006 .chained = true,
5007 .chain_id = ALC288_FIXUP_DELL1_MIC_NO_PRESENCE
5008 },
4909}; 5009};
4910 5010
4911static const struct snd_pci_quirk alc269_fixup_tbl[] = { 5011static const struct snd_pci_quirk alc269_fixup_tbl[] = {
@@ -5010,6 +5110,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
5010 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ), 5110 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5011 SND_PCI_QUIRK(0x104d, 0x9099, "Sony VAIO S13", ALC275_FIXUP_SONY_DISABLE_AAMIX), 5111 SND_PCI_QUIRK(0x104d, 0x9099, "Sony VAIO S13", ALC275_FIXUP_SONY_DISABLE_AAMIX),
5012 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK), 5112 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
5113 SND_PCI_QUIRK(0x10cf, 0x15dc, "Lifebook T731", ALC269_FIXUP_LIFEBOOK_HP_PIN),
5013 SND_PCI_QUIRK(0x10cf, 0x1845, "Lifebook U904", ALC269_FIXUP_LIFEBOOK_EXTMIC), 5114 SND_PCI_QUIRK(0x10cf, 0x1845, "Lifebook U904", ALC269_FIXUP_LIFEBOOK_EXTMIC),
5014 SND_PCI_QUIRK(0x144d, 0xc109, "Samsung Ativ book 9 (NP900X3G)", ALC269_FIXUP_INV_DMIC), 5115 SND_PCI_QUIRK(0x144d, 0xc109, "Samsung Ativ book 9 (NP900X3G)", ALC269_FIXUP_INV_DMIC),
5015 SND_PCI_QUIRK(0x1458, 0xfa53, "Gigabyte BXBT-2807", ALC283_FIXUP_BXBT2807_MIC), 5116 SND_PCI_QUIRK(0x1458, 0xfa53, "Gigabyte BXBT-2807", ALC283_FIXUP_BXBT2807_MIC),
@@ -5030,12 +5131,14 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
5030 SND_PCI_QUIRK(0x17aa, 0x2212, "Thinkpad T440", ALC292_FIXUP_TPT440_DOCK), 5131 SND_PCI_QUIRK(0x17aa, 0x2212, "Thinkpad T440", ALC292_FIXUP_TPT440_DOCK),
5031 SND_PCI_QUIRK(0x17aa, 0x2214, "Thinkpad X240", ALC292_FIXUP_TPT440_DOCK), 5132 SND_PCI_QUIRK(0x17aa, 0x2214, "Thinkpad X240", ALC292_FIXUP_TPT440_DOCK),
5032 SND_PCI_QUIRK(0x17aa, 0x2215, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST), 5133 SND_PCI_QUIRK(0x17aa, 0x2215, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
5134 SND_PCI_QUIRK(0x17aa, 0x2226, "ThinkPad X250", ALC292_FIXUP_TPT440_DOCK),
5033 SND_PCI_QUIRK(0x17aa, 0x3977, "IdeaPad S210", ALC283_FIXUP_INT_MIC), 5135 SND_PCI_QUIRK(0x17aa, 0x3977, "IdeaPad S210", ALC283_FIXUP_INT_MIC),
5034 SND_PCI_QUIRK(0x17aa, 0x3978, "IdeaPad Y410P", ALC269_FIXUP_NO_SHUTUP), 5136 SND_PCI_QUIRK(0x17aa, 0x3978, "IdeaPad Y410P", ALC269_FIXUP_NO_SHUTUP),
5035 SND_PCI_QUIRK(0x17aa, 0x5013, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST), 5137 SND_PCI_QUIRK(0x17aa, 0x5013, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
5036 SND_PCI_QUIRK(0x17aa, 0x501a, "Thinkpad", ALC283_FIXUP_INT_MIC), 5138 SND_PCI_QUIRK(0x17aa, 0x501a, "Thinkpad", ALC283_FIXUP_INT_MIC),
5037 SND_PCI_QUIRK(0x17aa, 0x501e, "Thinkpad L440", ALC292_FIXUP_TPT440_DOCK), 5139 SND_PCI_QUIRK(0x17aa, 0x501e, "Thinkpad L440", ALC292_FIXUP_TPT440_DOCK),
5038 SND_PCI_QUIRK(0x17aa, 0x5026, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST), 5140 SND_PCI_QUIRK(0x17aa, 0x5026, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
5141 SND_PCI_QUIRK(0x17aa, 0x5034, "Thinkpad T450", ALC292_FIXUP_TPT440_DOCK),
5039 SND_PCI_QUIRK(0x17aa, 0x5036, "Thinkpad T450s", ALC292_FIXUP_TPT440_DOCK), 5142 SND_PCI_QUIRK(0x17aa, 0x5036, "Thinkpad T450s", ALC292_FIXUP_TPT440_DOCK),
5040 SND_PCI_QUIRK(0x17aa, 0x5109, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST), 5143 SND_PCI_QUIRK(0x17aa, 0x5109, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
5041 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K), 5144 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
@@ -5125,6 +5228,16 @@ static const struct hda_model_fixup alc269_fixup_models[] = {
5125 {0x1b, 0x411111f0}, \ 5228 {0x1b, 0x411111f0}, \
5126 {0x1e, 0x411111f0} 5229 {0x1e, 0x411111f0}
5127 5230
5231#define ALC256_STANDARD_PINS \
5232 {0x12, 0x90a60140}, \
5233 {0x14, 0x90170110}, \
5234 {0x19, 0x411111f0}, \
5235 {0x1a, 0x411111f0}, \
5236 {0x1b, 0x411111f0}, \
5237 {0x1d, 0x40700001}, \
5238 {0x1e, 0x411111f0}, \
5239 {0x21, 0x02211020}
5240
5128#define ALC282_STANDARD_PINS \ 5241#define ALC282_STANDARD_PINS \
5129 {0x14, 0x90170110}, \ 5242 {0x14, 0x90170110}, \
5130 {0x18, 0x411111f0}, \ 5243 {0x18, 0x411111f0}, \
@@ -5132,6 +5245,13 @@ static const struct hda_model_fixup alc269_fixup_models[] = {
5132 {0x1b, 0x411111f0}, \ 5245 {0x1b, 0x411111f0}, \
5133 {0x1e, 0x411111f0} 5246 {0x1e, 0x411111f0}
5134 5247
5248#define ALC288_STANDARD_PINS \
5249 {0x17, 0x411111f0}, \
5250 {0x18, 0x411111f0}, \
5251 {0x19, 0x411111f0}, \
5252 {0x1a, 0x411111f0}, \
5253 {0x1e, 0x411111f0}
5254
5135#define ALC290_STANDARD_PINS \ 5255#define ALC290_STANDARD_PINS \
5136 {0x12, 0x99a30130}, \ 5256 {0x12, 0x99a30130}, \
5137 {0x13, 0x40000000}, \ 5257 {0x13, 0x40000000}, \
@@ -5217,6 +5337,12 @@ static const struct snd_hda_pin_quirk alc269_pin_fixup_tbl[] = {
5217 {0x17, 0x40000000}, 5337 {0x17, 0x40000000},
5218 {0x1d, 0x40700001}, 5338 {0x1d, 0x40700001},
5219 {0x21, 0x02211050}), 5339 {0x21, 0x02211050}),
5340 SND_HDA_PIN_QUIRK(0x10ec0256, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
5341 ALC256_STANDARD_PINS,
5342 {0x13, 0x40000000}),
5343 SND_HDA_PIN_QUIRK(0x10ec0256, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
5344 ALC256_STANDARD_PINS,
5345 {0x13, 0x411111f0}),
5220 SND_HDA_PIN_QUIRK(0x10ec0280, 0x103c, "HP", ALC280_FIXUP_HP_GPIO4, 5346 SND_HDA_PIN_QUIRK(0x10ec0280, 0x103c, "HP", ALC280_FIXUP_HP_GPIO4,
5221 {0x12, 0x90a60130}, 5347 {0x12, 0x90a60130},
5222 {0x13, 0x40000000}, 5348 {0x13, 0x40000000},
@@ -5317,6 +5443,13 @@ static const struct snd_hda_pin_quirk alc269_pin_fixup_tbl[] = {
5317 {0x19, 0x03a11020}, 5443 {0x19, 0x03a11020},
5318 {0x1d, 0x40e00001}, 5444 {0x1d, 0x40e00001},
5319 {0x21, 0x0321101f}), 5445 {0x21, 0x0321101f}),
5446 SND_HDA_PIN_QUIRK(0x10ec0288, 0x1028, "Dell", ALC288_FIXUP_DELL_XPS_13_GPIO6,
5447 ALC288_STANDARD_PINS,
5448 {0x12, 0x90a60120},
5449 {0x13, 0x40000000},
5450 {0x14, 0x90170110},
5451 {0x1d, 0x4076832d},
5452 {0x21, 0x0321101f}),
5320 SND_HDA_PIN_QUIRK(0x10ec0290, 0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1, 5453 SND_HDA_PIN_QUIRK(0x10ec0290, 0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1,
5321 ALC290_STANDARD_PINS, 5454 ALC290_STANDARD_PINS,
5322 {0x14, 0x411111f0}, 5455 {0x14, 0x411111f0},
@@ -5457,6 +5590,7 @@ static int patch_alc269(struct hda_codec *codec)
5457 5590
5458 spec = codec->spec; 5591 spec = codec->spec;
5459 spec->gen.shared_mic_vref_pin = 0x18; 5592 spec->gen.shared_mic_vref_pin = 0x18;
5593 codec->power_save_node = 1;
5460 5594
5461 snd_hda_pick_fixup(codec, alc269_fixup_models, 5595 snd_hda_pick_fixup(codec, alc269_fixup_models,
5462 alc269_fixup_tbl, alc269_fixups); 5596 alc269_fixup_tbl, alc269_fixups);
@@ -5470,7 +5604,7 @@ static int patch_alc269(struct hda_codec *codec)
5470 if (has_cdefine_beep(codec)) 5604 if (has_cdefine_beep(codec))
5471 spec->gen.beep_nid = 0x01; 5605 spec->gen.beep_nid = 0x01;
5472 5606
5473 switch (codec->vendor_id) { 5607 switch (codec->core.vendor_id) {
5474 case 0x10ec0269: 5608 case 0x10ec0269:
5475 spec->codec_variant = ALC269_TYPE_ALC269VA; 5609 spec->codec_variant = ALC269_TYPE_ALC269VA;
5476 switch (alc_get_coef0(codec) & 0x00f0) { 5610 switch (alc_get_coef0(codec) & 0x00f0) {
@@ -5536,6 +5670,8 @@ static int patch_alc269(struct hda_codec *codec)
5536 break; 5670 break;
5537 case 0x10ec0256: 5671 case 0x10ec0256:
5538 spec->codec_variant = ALC269_TYPE_ALC256; 5672 spec->codec_variant = ALC269_TYPE_ALC256;
5673 spec->gen.mixer_nid = 0; /* ALC256 does not have any loopback mixer path */
5674 alc_update_coef_idx(codec, 0x36, 1 << 13, 1 << 5); /* Switch pcbeep path to Line in path*/
5539 break; 5675 break;
5540 } 5676 }
5541 5677
@@ -5549,10 +5685,11 @@ static int patch_alc269(struct hda_codec *codec)
5549 if (err < 0) 5685 if (err < 0)
5550 goto error; 5686 goto error;
5551 5687
5552 if (!spec->gen.no_analog && spec->gen.beep_nid) 5688 if (!spec->gen.no_analog && spec->gen.beep_nid && spec->gen.mixer_nid)
5553 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT); 5689 set_beep_amp(spec, spec->gen.mixer_nid, 0x04, HDA_INPUT);
5554 5690
5555 codec->patch_ops = alc_patch_ops; 5691 codec->patch_ops = alc_patch_ops;
5692 codec->patch_ops.stream_pm = snd_hda_gen_stream_pm;
5556#ifdef CONFIG_PM 5693#ifdef CONFIG_PM
5557 codec->patch_ops.suspend = alc269_suspend; 5694 codec->patch_ops.suspend = alc269_suspend;
5558 codec->patch_ops.resume = alc269_resume; 5695 codec->patch_ops.resume = alc269_resume;
@@ -5814,9 +5951,9 @@ static int alc662_parse_auto_config(struct hda_codec *codec)
5814 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 }; 5951 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5815 const hda_nid_t *ssids; 5952 const hda_nid_t *ssids;
5816 5953
5817 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 || 5954 if (codec->core.vendor_id == 0x10ec0272 || codec->core.vendor_id == 0x10ec0663 ||
5818 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670 || 5955 codec->core.vendor_id == 0x10ec0665 || codec->core.vendor_id == 0x10ec0670 ||
5819 codec->vendor_id == 0x10ec0671) 5956 codec->core.vendor_id == 0x10ec0671)
5820 ssids = alc663_ssids; 5957 ssids = alc663_ssids;
5821 else 5958 else
5822 ssids = alc662_ssids; 5959 ssids = alc662_ssids;
@@ -5851,7 +5988,7 @@ static void alc_fixup_bass_chmap(struct hda_codec *codec,
5851{ 5988{
5852 if (action == HDA_FIXUP_ACT_BUILD) { 5989 if (action == HDA_FIXUP_ACT_BUILD) {
5853 struct alc_spec *spec = codec->spec; 5990 struct alc_spec *spec = codec->spec;
5854 spec->gen.pcm_rec[0].stream[0].chmap = asus_pcm_2_1_chmaps; 5991 spec->gen.pcm_rec[0]->stream[0].chmap = asus_pcm_2_1_chmaps;
5855 } 5992 }
5856} 5993}
5857 5994
@@ -5861,7 +5998,7 @@ static unsigned int gpio_led_power_filter(struct hda_codec *codec,
5861 unsigned int power_state) 5998 unsigned int power_state)
5862{ 5999{
5863 struct alc_spec *spec = codec->spec; 6000 struct alc_spec *spec = codec->spec;
5864 if (nid == codec->afg && power_state == AC_PWRST_D3 && spec->gpio_led) 6001 if (nid == codec->core.afg && power_state == AC_PWRST_D3 && spec->gpio_led)
5865 return AC_PWRST_D0; 6002 return AC_PWRST_D0;
5866 return power_state; 6003 return power_state;
5867} 6004}
@@ -6359,7 +6496,7 @@ static int patch_alc662(struct hda_codec *codec)
6359 6496
6360 alc_fix_pll_init(codec, 0x20, 0x04, 15); 6497 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6361 6498
6362 switch (codec->vendor_id) { 6499 switch (codec->core.vendor_id) {
6363 case 0x10ec0668: 6500 case 0x10ec0668:
6364 spec->init_hook = alc668_restore_default_value; 6501 spec->init_hook = alc668_restore_default_value;
6365 break; 6502 break;
@@ -6389,7 +6526,7 @@ static int patch_alc662(struct hda_codec *codec)
6389 goto error; 6526 goto error;
6390 6527
6391 if (!spec->gen.no_analog && spec->gen.beep_nid) { 6528 if (!spec->gen.no_analog && spec->gen.beep_nid) {
6392 switch (codec->vendor_id) { 6529 switch (codec->core.vendor_id) {
6393 case 0x10ec0662: 6530 case 0x10ec0662:
6394 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); 6531 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6395 break; 6532 break;
@@ -6522,20 +6659,8 @@ MODULE_ALIAS("snd-hda-codec-id:10ec*");
6522MODULE_LICENSE("GPL"); 6659MODULE_LICENSE("GPL");
6523MODULE_DESCRIPTION("Realtek HD-audio codec"); 6660MODULE_DESCRIPTION("Realtek HD-audio codec");
6524 6661
6525static struct hda_codec_preset_list realtek_list = { 6662static struct hda_codec_driver realtek_driver = {
6526 .preset = snd_hda_preset_realtek, 6663 .preset = snd_hda_preset_realtek,
6527 .owner = THIS_MODULE,
6528}; 6664};
6529 6665
6530static int __init patch_realtek_init(void) 6666module_hda_codec_driver(realtek_driver);
6531{
6532 return snd_hda_add_codec_preset(&realtek_list);
6533}
6534
6535static void __exit patch_realtek_exit(void)
6536{
6537 snd_hda_delete_codec_preset(&realtek_list);
6538}
6539
6540module_init(patch_realtek_init)
6541module_exit(patch_realtek_exit)
diff --git a/sound/pci/hda/patch_si3054.c b/sound/pci/hda/patch_si3054.c
index 3208ad69583e..5104bebb2286 100644
--- a/sound/pci/hda/patch_si3054.c
+++ b/sound/pci/hda/patch_si3054.c
@@ -83,7 +83,6 @@
83 83
84struct si3054_spec { 84struct si3054_spec {
85 unsigned international; 85 unsigned international;
86 struct hda_pcm pcm;
87}; 86};
88 87
89 88
@@ -199,15 +198,15 @@ static const struct hda_pcm_stream si3054_pcm = {
199 198
200static int si3054_build_pcms(struct hda_codec *codec) 199static int si3054_build_pcms(struct hda_codec *codec)
201{ 200{
202 struct si3054_spec *spec = codec->spec; 201 struct hda_pcm *info;
203 struct hda_pcm *info = &spec->pcm; 202
204 codec->num_pcms = 1; 203 info = snd_hda_codec_pcm_new(codec, "Si3054 Modem");
205 codec->pcm_info = info; 204 if (!info)
206 info->name = "Si3054 Modem"; 205 return -ENOMEM;
207 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = si3054_pcm; 206 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = si3054_pcm;
208 info->stream[SNDRV_PCM_STREAM_CAPTURE] = si3054_pcm; 207 info->stream[SNDRV_PCM_STREAM_CAPTURE] = si3054_pcm;
209 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = codec->mfg; 208 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = codec->core.mfg;
210 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = codec->mfg; 209 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = codec->core.mfg;
211 info->pcm_type = HDA_PCM_TYPE_MODEM; 210 info->pcm_type = HDA_PCM_TYPE_MODEM;
212 return 0; 211 return 0;
213} 212}
@@ -223,8 +222,12 @@ static int si3054_init(struct hda_codec *codec)
223 unsigned wait_count; 222 unsigned wait_count;
224 u16 val; 223 u16 val;
225 224
225 if (snd_hdac_regmap_add_vendor_verb(&codec->core,
226 SI3054_VERB_WRITE_NODE))
227 return -ENOMEM;
228
226 snd_hda_codec_write(codec, AC_NODE_ROOT, 0, AC_VERB_SET_CODEC_RESET, 0); 229 snd_hda_codec_write(codec, AC_NODE_ROOT, 0, AC_VERB_SET_CODEC_RESET, 0);
227 snd_hda_codec_write(codec, codec->mfg, 0, AC_VERB_SET_STREAM_FORMAT, 0); 230 snd_hda_codec_write(codec, codec->core.mfg, 0, AC_VERB_SET_STREAM_FORMAT, 0);
228 SET_REG(codec, SI3054_LINE_RATE, 9600); 231 SET_REG(codec, SI3054_LINE_RATE, 9600);
229 SET_REG(codec, SI3054_LINE_LEVEL, SI3054_DTAG_MASK|SI3054_ATAG_MASK); 232 SET_REG(codec, SI3054_LINE_LEVEL, SI3054_DTAG_MASK|SI3054_ATAG_MASK);
230 SET_REG(codec, SI3054_EXTENDED_MID, 0); 233 SET_REG(codec, SI3054_EXTENDED_MID, 0);
@@ -319,20 +322,8 @@ MODULE_ALIAS("snd-hda-codec-id:18540018");
319MODULE_LICENSE("GPL"); 322MODULE_LICENSE("GPL");
320MODULE_DESCRIPTION("Si3054 HD-audio modem codec"); 323MODULE_DESCRIPTION("Si3054 HD-audio modem codec");
321 324
322static struct hda_codec_preset_list si3054_list = { 325static struct hda_codec_driver si3054_driver = {
323 .preset = snd_hda_preset_si3054, 326 .preset = snd_hda_preset_si3054,
324 .owner = THIS_MODULE,
325}; 327};
326 328
327static int __init patch_si3054_init(void) 329module_hda_codec_driver(si3054_driver);
328{
329 return snd_hda_add_codec_preset(&si3054_list);
330}
331
332static void __exit patch_si3054_exit(void)
333{
334 snd_hda_delete_codec_preset(&si3054_list);
335}
336
337module_init(patch_si3054_init)
338module_exit(patch_si3054_exit)
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index 87eff3173ce9..43c99ce4a520 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -299,32 +299,33 @@ static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
299 unsigned int dir_mask, unsigned int data) 299 unsigned int dir_mask, unsigned int data)
300{ 300{
301 unsigned int gpiostate, gpiomask, gpiodir; 301 unsigned int gpiostate, gpiomask, gpiodir;
302 hda_nid_t fg = codec->core.afg;
302 303
303 codec_dbg(codec, "%s msk %x dir %x gpio %x\n", __func__, mask, dir_mask, data); 304 codec_dbg(codec, "%s msk %x dir %x gpio %x\n", __func__, mask, dir_mask, data);
304 305
305 gpiostate = snd_hda_codec_read(codec, codec->afg, 0, 306 gpiostate = snd_hda_codec_read(codec, fg, 0,
306 AC_VERB_GET_GPIO_DATA, 0); 307 AC_VERB_GET_GPIO_DATA, 0);
307 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask); 308 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
308 309
309 gpiomask = snd_hda_codec_read(codec, codec->afg, 0, 310 gpiomask = snd_hda_codec_read(codec, fg, 0,
310 AC_VERB_GET_GPIO_MASK, 0); 311 AC_VERB_GET_GPIO_MASK, 0);
311 gpiomask |= mask; 312 gpiomask |= mask;
312 313
313 gpiodir = snd_hda_codec_read(codec, codec->afg, 0, 314 gpiodir = snd_hda_codec_read(codec, fg, 0,
314 AC_VERB_GET_GPIO_DIRECTION, 0); 315 AC_VERB_GET_GPIO_DIRECTION, 0);
315 gpiodir |= dir_mask; 316 gpiodir |= dir_mask;
316 317
317 /* Configure GPIOx as CMOS */ 318 /* Configure GPIOx as CMOS */
318 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0); 319 snd_hda_codec_write(codec, fg, 0, 0x7e7, 0);
319 320
320 snd_hda_codec_write(codec, codec->afg, 0, 321 snd_hda_codec_write(codec, fg, 0,
321 AC_VERB_SET_GPIO_MASK, gpiomask); 322 AC_VERB_SET_GPIO_MASK, gpiomask);
322 snd_hda_codec_read(codec, codec->afg, 0, 323 snd_hda_codec_read(codec, fg, 0,
323 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */ 324 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
324 325
325 msleep(1); 326 msleep(1);
326 327
327 snd_hda_codec_read(codec, codec->afg, 0, 328 snd_hda_codec_read(codec, fg, 0,
328 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */ 329 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
329} 330}
330 331
@@ -387,7 +388,7 @@ static unsigned int stac_vref_led_power_filter(struct hda_codec *codec,
387 hda_nid_t nid, 388 hda_nid_t nid,
388 unsigned int power_state) 389 unsigned int power_state)
389{ 390{
390 if (nid == codec->afg && power_state == AC_PWRST_D3) 391 if (nid == codec->core.afg && power_state == AC_PWRST_D3)
391 return AC_PWRST_D1; 392 return AC_PWRST_D1;
392 return snd_hda_gen_path_power_filter(codec, nid, power_state); 393 return snd_hda_gen_path_power_filter(codec, nid, power_state);
393} 394}
@@ -432,7 +433,7 @@ static void stac_update_outputs(struct hda_codec *codec)
432 433
433 if (spec->gpio_mute) 434 if (spec->gpio_mute)
434 spec->gen.master_mute = 435 spec->gen.master_mute =
435 !(snd_hda_codec_read(codec, codec->afg, 0, 436 !(snd_hda_codec_read(codec, codec->core.afg, 0,
436 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute); 437 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
437 438
438 snd_hda_gen_update_outputs(codec); 439 snd_hda_gen_update_outputs(codec);
@@ -476,7 +477,7 @@ static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
476 if (val != spec->power_map_bits) { 477 if (val != spec->power_map_bits) {
477 spec->power_map_bits = val; 478 spec->power_map_bits = val;
478 if (do_write) 479 if (do_write)
479 snd_hda_codec_write(codec, codec->afg, 0, 480 snd_hda_codec_write(codec, codec->core.afg, 0,
480 AC_VERB_IDT_SET_POWER_MAP, val); 481 AC_VERB_IDT_SET_POWER_MAP, val);
481 } 482 }
482} 483}
@@ -508,7 +509,8 @@ static void jack_update_power(struct hda_codec *codec,
508 false); 509 false);
509 } 510 }
510 511
511 snd_hda_codec_write(codec, codec->afg, 0, AC_VERB_IDT_SET_POWER_MAP, 512 snd_hda_codec_write(codec, codec->core.afg, 0,
513 AC_VERB_IDT_SET_POWER_MAP,
512 spec->power_map_bits); 514 spec->power_map_bits);
513} 515}
514 516
@@ -517,10 +519,10 @@ static void stac_vref_event(struct hda_codec *codec,
517{ 519{
518 unsigned int data; 520 unsigned int data;
519 521
520 data = snd_hda_codec_read(codec, codec->afg, 0, 522 data = snd_hda_codec_read(codec, codec->core.afg, 0,
521 AC_VERB_GET_GPIO_DATA, 0); 523 AC_VERB_GET_GPIO_DATA, 0);
522 /* toggle VREF state based on GPIOx status */ 524 /* toggle VREF state based on GPIOx status */
523 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0, 525 snd_hda_codec_write(codec, codec->core.afg, 0, 0x7e0,
524 !!(data & (1 << event->private_data))); 526 !!(data & (1 << event->private_data)));
525} 527}
526 528
@@ -622,7 +624,7 @@ static int stac_aloopback_put(struct snd_kcontrol *kcontrol,
622 /* Only return the bits defined by the shift value of the 624 /* Only return the bits defined by the shift value of the
623 * first two bytes of the mask 625 * first two bytes of the mask
624 */ 626 */
625 dac_mode = snd_hda_codec_read(codec, codec->afg, 0, 627 dac_mode = snd_hda_codec_read(codec, codec->core.afg, 0,
626 kcontrol->private_value & 0xFFFF, 0x0); 628 kcontrol->private_value & 0xFFFF, 0x0);
627 dac_mode >>= spec->aloopback_shift; 629 dac_mode >>= spec->aloopback_shift;
628 630
@@ -634,7 +636,7 @@ static int stac_aloopback_put(struct snd_kcontrol *kcontrol,
634 dac_mode &= ~idx_val; 636 dac_mode &= ~idx_val;
635 } 637 }
636 638
637 snd_hda_codec_write_cache(codec, codec->afg, 0, 639 snd_hda_codec_write_cache(codec, codec->core.afg, 0,
638 kcontrol->private_value >> 16, dac_mode); 640 kcontrol->private_value >> 16, dac_mode);
639 641
640 return 1; 642 return 1;
@@ -658,11 +660,11 @@ static int stac_aloopback_put(struct snd_kcontrol *kcontrol,
658/* check whether it's a HP laptop with a docking port */ 660/* check whether it's a HP laptop with a docking port */
659static bool hp_bnb2011_with_dock(struct hda_codec *codec) 661static bool hp_bnb2011_with_dock(struct hda_codec *codec)
660{ 662{
661 if (codec->vendor_id != 0x111d7605 && 663 if (codec->core.vendor_id != 0x111d7605 &&
662 codec->vendor_id != 0x111d76d1) 664 codec->core.vendor_id != 0x111d76d1)
663 return false; 665 return false;
664 666
665 switch (codec->subsystem_id) { 667 switch (codec->core.subsystem_id) {
666 case 0x103c1618: 668 case 0x103c1618:
667 case 0x103c1619: 669 case 0x103c1619:
668 case 0x103c161a: 670 case 0x103c161a:
@@ -733,7 +735,7 @@ static void set_hp_led_gpio(struct hda_codec *codec)
733 if (spec->gpio_led) 735 if (spec->gpio_led)
734 return; 736 return;
735 737
736 gpio = snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP); 738 gpio = snd_hda_param_read(codec, codec->core.afg, AC_PAR_GPIO_CAP);
737 gpio &= AC_GPIO_IO_COUNT; 739 gpio &= AC_GPIO_IO_COUNT;
738 if (gpio > 3) 740 if (gpio > 3)
739 spec->gpio_led = 0x08; /* GPIO 3 */ 741 spec->gpio_led = 0x08; /* GPIO 3 */
@@ -777,7 +779,7 @@ static int find_mute_led_cfg(struct hda_codec *codec, int default_polarity)
777 &spec->gpio_led_polarity, 779 &spec->gpio_led_polarity,
778 &spec->gpio_led) == 2) { 780 &spec->gpio_led) == 2) {
779 unsigned int max_gpio; 781 unsigned int max_gpio;
780 max_gpio = snd_hda_param_read(codec, codec->afg, 782 max_gpio = snd_hda_param_read(codec, codec->core.afg,
781 AC_PAR_GPIO_CAP); 783 AC_PAR_GPIO_CAP);
782 max_gpio &= AC_GPIO_IO_COUNT; 784 max_gpio &= AC_GPIO_IO_COUNT;
783 if (spec->gpio_led < max_gpio) 785 if (spec->gpio_led < max_gpio)
@@ -807,7 +809,7 @@ static int find_mute_led_cfg(struct hda_codec *codec, int default_polarity)
807 * we statically set the GPIO - if not a B-series system 809 * we statically set the GPIO - if not a B-series system
808 * and default polarity is provided 810 * and default polarity is provided
809 */ 811 */
810 if (!hp_blike_system(codec->subsystem_id) && 812 if (!hp_blike_system(codec->core.subsystem_id) &&
811 (default_polarity == 0 || default_polarity == 1)) { 813 (default_polarity == 0 || default_polarity == 1)) {
812 set_hp_led_gpio(codec); 814 set_hp_led_gpio(codec);
813 spec->gpio_led_polarity = default_polarity; 815 spec->gpio_led_polarity = default_polarity;
@@ -1048,12 +1050,9 @@ static const struct hda_verb stac92hd71bxx_core_init[] = {
1048 {} 1050 {}
1049}; 1051};
1050 1052
1051static const struct hda_verb stac92hd71bxx_unmute_core_init[] = { 1053static const hda_nid_t stac92hd71bxx_unmute_nids[] = {
1052 /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */ 1054 /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
1053 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 1055 0x0f, 0x0a, 0x0d, 0
1054 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1055 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1056 {}
1057}; 1056};
1058 1057
1059static const struct hda_verb stac925x_core_init[] = { 1058static const struct hda_verb stac925x_core_init[] = {
@@ -2132,8 +2131,10 @@ static void stac92hd83xxx_fixup_hp_mic_led(struct hda_codec *codec,
2132 2131
2133 if (action == HDA_FIXUP_ACT_PRE_PROBE) { 2132 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
2134 spec->mic_mute_led_gpio = 0x08; /* GPIO3 */ 2133 spec->mic_mute_led_gpio = 0x08; /* GPIO3 */
2134#ifdef CONFIG_PM
2135 /* resetting controller clears GPIO, so we need to keep on */ 2135 /* resetting controller clears GPIO, so we need to keep on */
2136 codec->bus->power_keep_link_on = 1; 2136 codec->core.power_caps &= ~AC_PWRST_CLKSTOP;
2137#endif
2137 } 2138 }
2138} 2139}
2139 2140
@@ -3029,9 +3030,9 @@ static void stac92hd71bxx_fixup_hp_m4(struct hda_codec *codec,
3029 return; 3030 return;
3030 3031
3031 /* Enable VREF power saving on GPIO1 detect */ 3032 /* Enable VREF power saving on GPIO1 detect */
3032 snd_hda_codec_write_cache(codec, codec->afg, 0, 3033 snd_hda_codec_write_cache(codec, codec->core.afg, 0,
3033 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02); 3034 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
3034 jack = snd_hda_jack_detect_enable_callback(codec, codec->afg, 3035 jack = snd_hda_jack_detect_enable_callback(codec, codec->core.afg,
3035 stac_vref_event); 3036 stac_vref_event);
3036 if (!IS_ERR(jack)) 3037 if (!IS_ERR(jack))
3037 jack->private_data = 0x02; 3038 jack->private_data = 0x02;
@@ -3091,7 +3092,7 @@ static void stac92hd71bxx_fixup_hp(struct hda_codec *codec,
3091 if (action != HDA_FIXUP_ACT_PRE_PROBE) 3092 if (action != HDA_FIXUP_ACT_PRE_PROBE)
3092 return; 3093 return;
3093 3094
3094 if (hp_blike_system(codec->subsystem_id)) { 3095 if (hp_blike_system(codec->core.subsystem_id)) {
3095 unsigned int pin_cfg = snd_hda_codec_get_pincfg(codec, 0x0f); 3096 unsigned int pin_cfg = snd_hda_codec_get_pincfg(codec, 0x0f);
3096 if (get_defcfg_device(pin_cfg) == AC_JACK_LINE_OUT || 3097 if (get_defcfg_device(pin_cfg) == AC_JACK_LINE_OUT ||
3097 get_defcfg_device(pin_cfg) == AC_JACK_SPEAKER || 3098 get_defcfg_device(pin_cfg) == AC_JACK_SPEAKER ||
@@ -3790,7 +3791,7 @@ static void stac927x_fixup_dell_dmic(struct hda_codec *codec,
3790 if (action != HDA_FIXUP_ACT_PRE_PROBE) 3791 if (action != HDA_FIXUP_ACT_PRE_PROBE)
3791 return; 3792 return;
3792 3793
3793 if (codec->subsystem_id != 0x1028022f) { 3794 if (codec->core.subsystem_id != 0x1028022f) {
3794 /* GPIO2 High = Enable EAPD */ 3795 /* GPIO2 High = Enable EAPD */
3795 spec->eapd_mask = spec->gpio_mask = 0x04; 3796 spec->eapd_mask = spec->gpio_mask = 0x04;
3796 spec->gpio_dir = spec->gpio_data = 0x04; 3797 spec->gpio_dir = spec->gpio_data = 0x04;
@@ -4051,9 +4052,9 @@ static void stac9205_fixup_dell_m43(struct hda_codec *codec,
4051 snd_hda_apply_pincfgs(codec, dell_9205_m43_pin_configs); 4052 snd_hda_apply_pincfgs(codec, dell_9205_m43_pin_configs);
4052 4053
4053 /* Enable unsol response for GPIO4/Dock HP connection */ 4054 /* Enable unsol response for GPIO4/Dock HP connection */
4054 snd_hda_codec_write_cache(codec, codec->afg, 0, 4055 snd_hda_codec_write_cache(codec, codec->core.afg, 0,
4055 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10); 4056 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
4056 jack = snd_hda_jack_detect_enable_callback(codec, codec->afg, 4057 jack = snd_hda_jack_detect_enable_callback(codec, codec->core.afg,
4057 stac_vref_event); 4058 stac_vref_event);
4058 if (!IS_ERR(jack)) 4059 if (!IS_ERR(jack))
4059 jack->private_data = 0x01; 4060 jack->private_data = 0x01;
@@ -4223,6 +4224,12 @@ static int stac_parse_auto_config(struct hda_codec *codec)
4223 if (err < 0) 4224 if (err < 0)
4224 return err; 4225 return err;
4225 4226
4227 if (spec->vref_mute_led_nid) {
4228 err = snd_hda_gen_fix_pin_power(codec, spec->vref_mute_led_nid);
4229 if (err < 0)
4230 return err;
4231 }
4232
4226 /* setup analog beep controls */ 4233 /* setup analog beep controls */
4227 if (spec->anabeep_nid > 0) { 4234 if (spec->anabeep_nid > 0) {
4228 err = stac_auto_create_beep_ctls(codec, 4235 err = stac_auto_create_beep_ctls(codec,
@@ -4259,6 +4266,10 @@ static int stac_parse_auto_config(struct hda_codec *codec)
4259 4266
4260 if (spec->aloopback_ctl && 4267 if (spec->aloopback_ctl &&
4261 snd_hda_get_bool_hint(codec, "loopback") == 1) { 4268 snd_hda_get_bool_hint(codec, "loopback") == 1) {
4269 unsigned int wr_verb =
4270 spec->aloopback_ctl->private_value >> 16;
4271 if (snd_hdac_regmap_add_vendor_verb(&codec->core, wr_verb))
4272 return -ENOMEM;
4262 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, spec->aloopback_ctl)) 4273 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, spec->aloopback_ctl))
4263 return -ENOMEM; 4274 return -ENOMEM;
4264 } 4275 }
@@ -4294,7 +4305,7 @@ static int stac_init(struct hda_codec *codec)
4294 4305
4295 /* sync the power-map */ 4306 /* sync the power-map */
4296 if (spec->num_pwrs) 4307 if (spec->num_pwrs)
4297 snd_hda_codec_write(codec, codec->afg, 0, 4308 snd_hda_codec_write(codec, codec->core.afg, 0,
4298 AC_VERB_IDT_SET_POWER_MAP, 4309 AC_VERB_IDT_SET_POWER_MAP,
4299 spec->power_map_bits); 4310 spec->power_map_bits);
4300 4311
@@ -4330,7 +4341,7 @@ static void stac_shutup(struct hda_codec *codec)
4330static void stac92hd_proc_hook(struct snd_info_buffer *buffer, 4341static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4331 struct hda_codec *codec, hda_nid_t nid) 4342 struct hda_codec *codec, hda_nid_t nid)
4332{ 4343{
4333 if (nid == codec->afg) 4344 if (nid == codec->core.afg)
4334 snd_iprintf(buffer, "Power-Map: 0x%02x\n", 4345 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4335 snd_hda_codec_read(codec, nid, 0, 4346 snd_hda_codec_read(codec, nid, 0,
4336 AC_VERB_IDT_GET_POWER_MAP, 0)); 4347 AC_VERB_IDT_GET_POWER_MAP, 0));
@@ -4341,7 +4352,7 @@ static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4341 unsigned int verb) 4352 unsigned int verb)
4342{ 4353{
4343 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n", 4354 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4344 snd_hda_codec_read(codec, codec->afg, 0, verb, 0)); 4355 snd_hda_codec_read(codec, codec->core.afg, 0, verb, 0));
4345} 4356}
4346 4357
4347/* stac92hd71bxx, stac92hd73xx */ 4358/* stac92hd71bxx, stac92hd73xx */
@@ -4349,21 +4360,21 @@ static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4349 struct hda_codec *codec, hda_nid_t nid) 4360 struct hda_codec *codec, hda_nid_t nid)
4350{ 4361{
4351 stac92hd_proc_hook(buffer, codec, nid); 4362 stac92hd_proc_hook(buffer, codec, nid);
4352 if (nid == codec->afg) 4363 if (nid == codec->core.afg)
4353 analog_loop_proc_hook(buffer, codec, 0xfa0); 4364 analog_loop_proc_hook(buffer, codec, 0xfa0);
4354} 4365}
4355 4366
4356static void stac9205_proc_hook(struct snd_info_buffer *buffer, 4367static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4357 struct hda_codec *codec, hda_nid_t nid) 4368 struct hda_codec *codec, hda_nid_t nid)
4358{ 4369{
4359 if (nid == codec->afg) 4370 if (nid == codec->core.afg)
4360 analog_loop_proc_hook(buffer, codec, 0xfe0); 4371 analog_loop_proc_hook(buffer, codec, 0xfe0);
4361} 4372}
4362 4373
4363static void stac927x_proc_hook(struct snd_info_buffer *buffer, 4374static void stac927x_proc_hook(struct snd_info_buffer *buffer,
4364 struct hda_codec *codec, hda_nid_t nid) 4375 struct hda_codec *codec, hda_nid_t nid)
4365{ 4376{
4366 if (nid == codec->afg) 4377 if (nid == codec->core.afg)
4367 analog_loop_proc_hook(buffer, codec, 0xfeb); 4378 analog_loop_proc_hook(buffer, codec, 0xfeb);
4368} 4379}
4369#else 4380#else
@@ -4392,6 +4403,7 @@ static const struct hda_codec_ops stac_patch_ops = {
4392#ifdef CONFIG_PM 4403#ifdef CONFIG_PM
4393 .suspend = stac_suspend, 4404 .suspend = stac_suspend,
4394#endif 4405#endif
4406 .stream_pm = snd_hda_gen_stream_pm,
4395 .reboot_notify = stac_shutup, 4407 .reboot_notify = stac_shutup,
4396}; 4408};
4397 4409
@@ -4485,6 +4497,7 @@ static int patch_stac92hd73xx(struct hda_codec *codec)
4485 return err; 4497 return err;
4486 4498
4487 spec = codec->spec; 4499 spec = codec->spec;
4500 codec->power_save_node = 1;
4488 spec->linear_tone_beep = 0; 4501 spec->linear_tone_beep = 0;
4489 spec->gen.mixer_nid = 0x1d; 4502 spec->gen.mixer_nid = 0x1d;
4490 spec->have_spdif_mux = 1; 4503 spec->have_spdif_mux = 1;
@@ -4587,9 +4600,11 @@ static int patch_stac92hd83xxx(struct hda_codec *codec)
4587 if (err < 0) 4600 if (err < 0)
4588 return err; 4601 return err;
4589 4602
4590 codec->epss = 0; /* longer delay needed for D3 */ 4603 /* longer delay needed for D3 */
4604 codec->core.power_caps &= ~AC_PWRST_EPSS;
4591 4605
4592 spec = codec->spec; 4606 spec = codec->spec;
4607 codec->power_save_node = 1;
4593 spec->linear_tone_beep = 0; 4608 spec->linear_tone_beep = 0;
4594 spec->gen.own_eapd_ctl = 1; 4609 spec->gen.own_eapd_ctl = 1;
4595 spec->gen.power_down_unused = 1; 4610 spec->gen.power_down_unused = 1;
@@ -4636,9 +4651,11 @@ static int patch_stac92hd95(struct hda_codec *codec)
4636 if (err < 0) 4651 if (err < 0)
4637 return err; 4652 return err;
4638 4653
4639 codec->epss = 0; /* longer delay needed for D3 */ 4654 /* longer delay needed for D3 */
4655 codec->core.power_caps &= ~AC_PWRST_EPSS;
4640 4656
4641 spec = codec->spec; 4657 spec = codec->spec;
4658 codec->power_save_node = 1;
4642 spec->linear_tone_beep = 0; 4659 spec->linear_tone_beep = 0;
4643 spec->gen.own_eapd_ctl = 1; 4660 spec->gen.own_eapd_ctl = 1;
4644 spec->gen.power_down_unused = 1; 4661 spec->gen.power_down_unused = 1;
@@ -4672,7 +4689,7 @@ static int patch_stac92hd95(struct hda_codec *codec)
4672static int patch_stac92hd71bxx(struct hda_codec *codec) 4689static int patch_stac92hd71bxx(struct hda_codec *codec)
4673{ 4690{
4674 struct sigmatel_spec *spec; 4691 struct sigmatel_spec *spec;
4675 const struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init; 4692 const hda_nid_t *unmute_nids = stac92hd71bxx_unmute_nids;
4676 int err; 4693 int err;
4677 4694
4678 err = alloc_stac_spec(codec); 4695 err = alloc_stac_spec(codec);
@@ -4680,6 +4697,7 @@ static int patch_stac92hd71bxx(struct hda_codec *codec)
4680 return err; 4697 return err;
4681 4698
4682 spec = codec->spec; 4699 spec = codec->spec;
4700 codec->power_save_node = 1;
4683 spec->linear_tone_beep = 0; 4701 spec->linear_tone_beep = 0;
4684 spec->gen.own_eapd_ctl = 1; 4702 spec->gen.own_eapd_ctl = 1;
4685 spec->gen.power_down_unused = 1; 4703 spec->gen.power_down_unused = 1;
@@ -4693,23 +4711,23 @@ static int patch_stac92hd71bxx(struct hda_codec *codec)
4693 spec->gpio_dir = 0x01; 4711 spec->gpio_dir = 0x01;
4694 spec->gpio_data = 0x01; 4712 spec->gpio_data = 0x01;
4695 4713
4696 switch (codec->vendor_id) { 4714 switch (codec->core.vendor_id) {
4697 case 0x111d76b6: /* 4 Port without Analog Mixer */ 4715 case 0x111d76b6: /* 4 Port without Analog Mixer */
4698 case 0x111d76b7: 4716 case 0x111d76b7:
4699 unmute_init++; 4717 unmute_nids++;
4700 break; 4718 break;
4701 case 0x111d7608: /* 5 Port with Analog Mixer */ 4719 case 0x111d7608: /* 5 Port with Analog Mixer */
4702 if ((codec->revision_id & 0xf) == 0 || 4720 if ((codec->core.revision_id & 0xf) == 0 ||
4703 (codec->revision_id & 0xf) == 1) 4721 (codec->core.revision_id & 0xf) == 1)
4704 spec->stream_delay = 40; /* 40 milliseconds */ 4722 spec->stream_delay = 40; /* 40 milliseconds */
4705 4723
4706 /* disable VSW */ 4724 /* disable VSW */
4707 unmute_init++; 4725 unmute_nids++;
4708 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0); 4726 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
4709 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3); 4727 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
4710 break; 4728 break;
4711 case 0x111d7603: /* 6 Port with Analog Mixer */ 4729 case 0x111d7603: /* 6 Port with Analog Mixer */
4712 if ((codec->revision_id & 0xf) == 1) 4730 if ((codec->core.revision_id & 0xf) == 1)
4713 spec->stream_delay = 40; /* 40 milliseconds */ 4731 spec->stream_delay = 40; /* 40 milliseconds */
4714 4732
4715 break; 4733 break;
@@ -4718,8 +4736,12 @@ static int patch_stac92hd71bxx(struct hda_codec *codec)
4718 if (get_wcaps_type(get_wcaps(codec, 0x28)) == AC_WID_VOL_KNB) 4736 if (get_wcaps_type(get_wcaps(codec, 0x28)) == AC_WID_VOL_KNB)
4719 snd_hda_add_verbs(codec, stac92hd71bxx_core_init); 4737 snd_hda_add_verbs(codec, stac92hd71bxx_core_init);
4720 4738
4721 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP) 4739 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP) {
4722 snd_hda_sequence_write_cache(codec, unmute_init); 4740 const hda_nid_t *p;
4741 for (p = unmute_nids; *p; p++)
4742 snd_hda_codec_amp_init_stereo(codec, *p, HDA_INPUT, 0,
4743 0xff, 0x00);
4744 }
4723 4745
4724 spec->aloopback_ctl = &stac92hd71bxx_loopback; 4746 spec->aloopback_ctl = &stac92hd71bxx_loopback;
4725 spec->aloopback_mask = 0x50; 4747 spec->aloopback_mask = 0x50;
@@ -5091,20 +5113,8 @@ MODULE_ALIAS("snd-hda-codec-id:111d*");
5091MODULE_LICENSE("GPL"); 5113MODULE_LICENSE("GPL");
5092MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec"); 5114MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
5093 5115
5094static struct hda_codec_preset_list sigmatel_list = { 5116static struct hda_codec_driver sigmatel_driver = {
5095 .preset = snd_hda_preset_sigmatel, 5117 .preset = snd_hda_preset_sigmatel,
5096 .owner = THIS_MODULE,
5097}; 5118};
5098 5119
5099static int __init patch_sigmatel_init(void) 5120module_hda_codec_driver(sigmatel_driver);
5100{
5101 return snd_hda_add_codec_preset(&sigmatel_list);
5102}
5103
5104static void __exit patch_sigmatel_exit(void)
5105{
5106 snd_hda_delete_codec_preset(&sigmatel_list);
5107}
5108
5109module_init(patch_sigmatel_init)
5110module_exit(patch_sigmatel_exit)
diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
index 3de6d3d779c9..31a95cca015d 100644
--- a/sound/pci/hda/patch_via.c
+++ b/sound/pci/hda/patch_via.c
@@ -99,7 +99,6 @@ struct via_spec {
99 99
100 /* HP mode source */ 100 /* HP mode source */
101 unsigned int dmic_enabled; 101 unsigned int dmic_enabled;
102 unsigned int no_pin_power_ctl;
103 enum VIA_HDA_CODEC codec_type; 102 enum VIA_HDA_CODEC codec_type;
104 103
105 /* analog low-power control */ 104 /* analog low-power control */
@@ -109,8 +108,7 @@ struct via_spec {
109 int hp_work_active; 108 int hp_work_active;
110 int vt1708_jack_detect; 109 int vt1708_jack_detect;
111 110
112 void (*set_widgets_power_state)(struct hda_codec *codec); 111 unsigned int beep_amp;
113 unsigned int dac_stream_tag[4];
114}; 112};
115 113
116static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec); 114static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
@@ -133,17 +131,18 @@ static struct via_spec *via_new_spec(struct hda_codec *codec)
133 /* VT1708BCE & VT1708S are almost same */ 131 /* VT1708BCE & VT1708S are almost same */
134 if (spec->codec_type == VT1708BCE) 132 if (spec->codec_type == VT1708BCE)
135 spec->codec_type = VT1708S; 133 spec->codec_type = VT1708S;
136 spec->no_pin_power_ctl = 1;
137 spec->gen.indep_hp = 1; 134 spec->gen.indep_hp = 1;
138 spec->gen.keep_eapd_on = 1; 135 spec->gen.keep_eapd_on = 1;
139 spec->gen.pcm_playback_hook = via_playback_pcm_hook; 136 spec->gen.pcm_playback_hook = via_playback_pcm_hook;
140 spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO; 137 spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO;
138 codec->power_save_node = 1;
139 spec->gen.power_down_unused = 1;
141 return spec; 140 return spec;
142} 141}
143 142
144static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec) 143static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
145{ 144{
146 u32 vendor_id = codec->vendor_id; 145 u32 vendor_id = codec->core.vendor_id;
147 u16 ven_id = vendor_id >> 16; 146 u16 ven_id = vendor_id >> 16;
148 u16 dev_id = vendor_id & 0xffff; 147 u16 dev_id = vendor_id & 0xffff;
149 enum VIA_HDA_CODEC codec_type; 148 enum VIA_HDA_CODEC codec_type;
@@ -222,98 +221,13 @@ static void vt1708_update_hp_work(struct hda_codec *codec)
222 if (!spec->hp_work_active) { 221 if (!spec->hp_work_active) {
223 codec->jackpoll_interval = msecs_to_jiffies(100); 222 codec->jackpoll_interval = msecs_to_jiffies(100);
224 snd_hda_codec_write(codec, 0x1, 0, 0xf81, 0); 223 snd_hda_codec_write(codec, 0x1, 0, 0xf81, 0);
225 queue_delayed_work(codec->bus->workq, 224 schedule_delayed_work(&codec->jackpoll_work, 0);
226 &codec->jackpoll_work, 0);
227 spec->hp_work_active = true; 225 spec->hp_work_active = true;
228 } 226 }
229 } else if (!hp_detect_with_aa(codec)) 227 } else if (!hp_detect_with_aa(codec))
230 vt1708_stop_hp_work(codec); 228 vt1708_stop_hp_work(codec);
231} 229}
232 230
233static void set_widgets_power_state(struct hda_codec *codec)
234{
235#if 0 /* FIXME: the assumed connections don't match always with the
236 * actual routes by the generic parser, so better to disable
237 * the control for safety.
238 */
239 struct via_spec *spec = codec->spec;
240 if (spec->set_widgets_power_state)
241 spec->set_widgets_power_state(codec);
242#endif
243}
244
245static void update_power_state(struct hda_codec *codec, hda_nid_t nid,
246 unsigned int parm)
247{
248 if (snd_hda_check_power_state(codec, nid, parm))
249 return;
250 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
251}
252
253static void update_conv_power_state(struct hda_codec *codec, hda_nid_t nid,
254 unsigned int parm, unsigned int index)
255{
256 struct via_spec *spec = codec->spec;
257 unsigned int format;
258
259 if (snd_hda_check_power_state(codec, nid, parm))
260 return;
261 format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
262 if (format && (spec->dac_stream_tag[index] != format))
263 spec->dac_stream_tag[index] = format;
264
265 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
266 if (parm == AC_PWRST_D0) {
267 format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
268 if (!format && (spec->dac_stream_tag[index] != format))
269 snd_hda_codec_write(codec, nid, 0,
270 AC_VERB_SET_CHANNEL_STREAMID,
271 spec->dac_stream_tag[index]);
272 }
273}
274
275static bool smart51_enabled(struct hda_codec *codec)
276{
277 struct via_spec *spec = codec->spec;
278 return spec->gen.ext_channel_count > 2;
279}
280
281static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
282{
283 struct via_spec *spec = codec->spec;
284 int i;
285
286 for (i = 0; i < spec->gen.multi_ios; i++)
287 if (spec->gen.multi_io[i].pin == pin)
288 return true;
289 return false;
290}
291
292static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
293 unsigned int *affected_parm)
294{
295 unsigned parm;
296 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
297 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
298 >> AC_DEFCFG_MISC_SHIFT
299 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
300 struct via_spec *spec = codec->spec;
301 unsigned present = 0;
302
303 no_presence |= spec->no_pin_power_ctl;
304 if (!no_presence)
305 present = snd_hda_jack_detect(codec, nid);
306 if ((smart51_enabled(codec) && is_smart51_pins(codec, nid))
307 || ((no_presence || present)
308 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
309 *affected_parm = AC_PWRST_D0; /* if it's connected */
310 parm = AC_PWRST_D0;
311 } else
312 parm = AC_PWRST_D3;
313
314 update_power_state(codec, nid, parm);
315}
316
317static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol, 231static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
318 struct snd_ctl_elem_info *uinfo) 232 struct snd_ctl_elem_info *uinfo)
319{ 233{
@@ -324,8 +238,7 @@ static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
324 struct snd_ctl_elem_value *ucontrol) 238 struct snd_ctl_elem_value *ucontrol)
325{ 239{
326 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 240 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
327 struct via_spec *spec = codec->spec; 241 ucontrol->value.enumerated.item[0] = codec->power_save_node;
328 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
329 return 0; 242 return 0;
330} 243}
331 244
@@ -334,12 +247,12 @@ static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
334{ 247{
335 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 248 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
336 struct via_spec *spec = codec->spec; 249 struct via_spec *spec = codec->spec;
337 unsigned int val = !ucontrol->value.enumerated.item[0]; 250 bool val = !!ucontrol->value.enumerated.item[0];
338 251
339 if (val == spec->no_pin_power_ctl) 252 if (val == codec->power_save_node)
340 return 0; 253 return 0;
341 spec->no_pin_power_ctl = val; 254 codec->power_save_node = val;
342 set_widgets_power_state(codec); 255 spec->gen.power_down_unused = val;
343 analog_low_current_mode(codec); 256 analog_low_current_mode(codec);
344 return 1; 257 return 1;
345} 258}
@@ -355,6 +268,59 @@ static const struct snd_kcontrol_new via_pin_power_ctl_enum[] = {
355 {} /* terminator */ 268 {} /* terminator */
356}; 269};
357 270
271#ifdef CONFIG_SND_HDA_INPUT_BEEP
272static inline void set_beep_amp(struct via_spec *spec, hda_nid_t nid,
273 int idx, int dir)
274{
275 spec->gen.beep_nid = nid;
276 spec->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir);
277}
278
279/* additional beep mixers; the actual parameters are overwritten at build */
280static const struct snd_kcontrol_new cxt_beep_mixer[] = {
281 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
282 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
283 { } /* end */
284};
285
286/* create beep controls if needed */
287static int add_beep_ctls(struct hda_codec *codec)
288{
289 struct via_spec *spec = codec->spec;
290 int err;
291
292 if (spec->beep_amp) {
293 const struct snd_kcontrol_new *knew;
294 for (knew = cxt_beep_mixer; knew->name; knew++) {
295 struct snd_kcontrol *kctl;
296 kctl = snd_ctl_new1(knew, codec);
297 if (!kctl)
298 return -ENOMEM;
299 kctl->private_value = spec->beep_amp;
300 err = snd_hda_ctl_add(codec, 0, kctl);
301 if (err < 0)
302 return err;
303 }
304 }
305 return 0;
306}
307
308static void auto_parse_beep(struct hda_codec *codec)
309{
310 struct via_spec *spec = codec->spec;
311 hda_nid_t nid;
312
313 for_each_hda_codec_node(nid, codec)
314 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
315 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
316 break;
317 }
318}
319#else
320#define set_beep_amp(spec, nid, idx, dir) /* NOP */
321#define add_beep_ctls(codec) 0
322#define auto_parse_beep(codec)
323#endif
358 324
359/* check AA path's mute status */ 325/* check AA path's mute status */
360static bool is_aa_path_mute(struct hda_codec *codec) 326static bool is_aa_path_mute(struct hda_codec *codec)
@@ -384,7 +350,7 @@ static void __analog_low_current_mode(struct hda_codec *codec, bool force)
384 bool enable; 350 bool enable;
385 unsigned int verb, parm; 351 unsigned int verb, parm;
386 352
387 if (spec->no_pin_power_ctl) 353 if (!codec->power_save_node)
388 enable = false; 354 enable = false;
389 else 355 else
390 enable = is_aa_path_mute(codec) && !spec->gen.active_streams; 356 enable = is_aa_path_mute(codec) && !spec->gen.active_streams;
@@ -424,7 +390,7 @@ static void __analog_low_current_mode(struct hda_codec *codec, bool force)
424 return; /* other codecs are not supported */ 390 return; /* other codecs are not supported */
425 } 391 }
426 /* send verb */ 392 /* send verb */
427 snd_hda_codec_write(codec, codec->afg, 0, verb, parm); 393 snd_hda_codec_write(codec, codec->core.afg, 0, verb, parm);
428} 394}
429 395
430static void analog_low_current_mode(struct hda_codec *codec) 396static void analog_low_current_mode(struct hda_codec *codec)
@@ -441,8 +407,11 @@ static int via_build_controls(struct hda_codec *codec)
441 if (err < 0) 407 if (err < 0)
442 return err; 408 return err;
443 409
444 if (spec->set_widgets_power_state) 410 err = add_beep_ctls(codec);
445 spec->mixers[spec->num_mixers++] = via_pin_power_ctl_enum; 411 if (err < 0)
412 return err;
413
414 spec->mixers[spec->num_mixers++] = via_pin_power_ctl_enum;
446 415
447 for (i = 0; i < spec->num_mixers; i++) { 416 for (i = 0; i < spec->num_mixers; i++) {
448 err = snd_hda_add_new_ctls(codec, spec->mixers[i]); 417 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
@@ -486,7 +455,6 @@ static int via_suspend(struct hda_codec *codec)
486static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid) 455static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
487{ 456{
488 struct via_spec *spec = codec->spec; 457 struct via_spec *spec = codec->spec;
489 set_widgets_power_state(codec);
490 analog_low_current_mode(codec); 458 analog_low_current_mode(codec);
491 vt1708_update_hp_work(codec); 459 vt1708_update_hp_work(codec);
492 return snd_hda_check_amp_list_power(codec, &spec->gen.loopback, nid); 460 return snd_hda_check_amp_list_power(codec, &spec->gen.loopback, nid);
@@ -504,6 +472,7 @@ static const struct hda_codec_ops via_patch_ops = {
504 .init = via_init, 472 .init = via_init,
505 .free = via_free, 473 .free = via_free,
506 .unsol_event = snd_hda_jack_unsol_event, 474 .unsol_event = snd_hda_jack_unsol_event,
475 .stream_pm = snd_hda_gen_stream_pm,
507#ifdef CONFIG_PM 476#ifdef CONFIG_PM
508 .suspend = via_suspend, 477 .suspend = via_suspend,
509 .check_power_status = via_check_power_status, 478 .check_power_status = via_check_power_status,
@@ -574,34 +543,6 @@ static const struct snd_kcontrol_new vt1708_jack_detect_ctl[] = {
574 {} /* terminator */ 543 {} /* terminator */
575}; 544};
576 545
577static void via_jack_powerstate_event(struct hda_codec *codec,
578 struct hda_jack_callback *tbl)
579{
580 set_widgets_power_state(codec);
581}
582
583static void via_set_jack_unsol_events(struct hda_codec *codec)
584{
585 struct via_spec *spec = codec->spec;
586 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
587 hda_nid_t pin;
588 int i;
589
590 for (i = 0; i < cfg->line_outs; i++) {
591 pin = cfg->line_out_pins[i];
592 if (pin && is_jack_detectable(codec, pin))
593 snd_hda_jack_detect_enable_callback(codec, pin,
594 via_jack_powerstate_event);
595 }
596
597 for (i = 0; i < cfg->num_inputs; i++) {
598 pin = cfg->line_out_pins[i];
599 if (pin && is_jack_detectable(codec, pin))
600 snd_hda_jack_detect_enable_callback(codec, pin,
601 via_jack_powerstate_event);
602 }
603}
604
605static const struct badness_table via_main_out_badness = { 546static const struct badness_table via_main_out_badness = {
606 .no_primary_dac = 0x10000, 547 .no_primary_dac = 0x10000,
607 .no_dac = 0x4000, 548 .no_dac = 0x4000,
@@ -631,11 +572,15 @@ static int via_parse_auto_config(struct hda_codec *codec)
631 if (err < 0) 572 if (err < 0)
632 return err; 573 return err;
633 574
575 auto_parse_beep(codec);
576
634 err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg); 577 err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
635 if (err < 0) 578 if (err < 0)
636 return err; 579 return err;
637 580
638 via_set_jack_unsol_events(codec); 581 /* disable widget PM at start for compatibility */
582 codec->power_save_node = 0;
583 spec->gen.power_down_unused = 0;
639 return 0; 584 return 0;
640} 585}
641 586
@@ -648,7 +593,6 @@ static int via_init(struct hda_codec *codec)
648 snd_hda_sequence_write(codec, spec->init_verbs[i]); 593 snd_hda_sequence_write(codec, spec->init_verbs[i]);
649 594
650 /* init power states */ 595 /* init power states */
651 set_widgets_power_state(codec);
652 __analog_low_current_mode(codec, true); 596 __analog_low_current_mode(codec, true);
653 597
654 snd_hda_gen_init(codec); 598 snd_hda_gen_init(codec);
@@ -676,15 +620,17 @@ static int vt1708_build_pcms(struct hda_codec *codec)
676 int i, err; 620 int i, err;
677 621
678 err = snd_hda_gen_build_pcms(codec); 622 err = snd_hda_gen_build_pcms(codec);
679 if (err < 0 || codec->vendor_id != 0x11061708) 623 if (err < 0 || codec->core.vendor_id != 0x11061708)
680 return err; 624 return err;
681 625
682 /* We got noisy outputs on the right channel on VT1708 when 626 /* We got noisy outputs on the right channel on VT1708 when
683 * 24bit samples are used. Until any workaround is found, 627 * 24bit samples are used. Until any workaround is found,
684 * disable the 24bit format, so far. 628 * disable the 24bit format, so far.
685 */ 629 */
686 for (i = 0; i < codec->num_pcms; i++) { 630 for (i = 0; i < ARRAY_SIZE(spec->gen.pcm_rec); i++) {
687 struct hda_pcm *info = &spec->gen.pcm_rec[i]; 631 struct hda_pcm *info = spec->gen.pcm_rec[i];
632 if (!info)
633 continue;
688 if (!info->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams || 634 if (!info->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams ||
689 info->pcm_type != HDA_PCM_TYPE_AUDIO) 635 info->pcm_type != HDA_PCM_TYPE_AUDIO)
690 continue; 636 continue;
@@ -766,78 +712,6 @@ static int patch_vt1709(struct hda_codec *codec)
766 return 0; 712 return 0;
767} 713}
768 714
769static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
770{
771 struct via_spec *spec = codec->spec;
772 int imux_is_smixer;
773 unsigned int parm;
774 int is_8ch = 0;
775 if ((spec->codec_type != VT1708B_4CH) &&
776 (codec->vendor_id != 0x11064397))
777 is_8ch = 1;
778
779 /* SW0 (17h) = stereo mixer */
780 imux_is_smixer =
781 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
782 == ((spec->codec_type == VT1708S) ? 5 : 0));
783 /* inputs */
784 /* PW 1/2/5 (1ah/1bh/1eh) */
785 parm = AC_PWRST_D3;
786 set_pin_power_state(codec, 0x1a, &parm);
787 set_pin_power_state(codec, 0x1b, &parm);
788 set_pin_power_state(codec, 0x1e, &parm);
789 if (imux_is_smixer)
790 parm = AC_PWRST_D0;
791 /* SW0 (17h), AIW 0/1 (13h/14h) */
792 update_power_state(codec, 0x17, parm);
793 update_power_state(codec, 0x13, parm);
794 update_power_state(codec, 0x14, parm);
795
796 /* outputs */
797 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
798 parm = AC_PWRST_D3;
799 set_pin_power_state(codec, 0x19, &parm);
800 if (smart51_enabled(codec))
801 set_pin_power_state(codec, 0x1b, &parm);
802 update_power_state(codec, 0x18, parm);
803 update_power_state(codec, 0x11, parm);
804
805 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
806 if (is_8ch) {
807 parm = AC_PWRST_D3;
808 set_pin_power_state(codec, 0x22, &parm);
809 if (smart51_enabled(codec))
810 set_pin_power_state(codec, 0x1a, &parm);
811 update_power_state(codec, 0x26, parm);
812 update_power_state(codec, 0x24, parm);
813 } else if (codec->vendor_id == 0x11064397) {
814 /* PW7(23h), SW2(27h), AOW2(25h) */
815 parm = AC_PWRST_D3;
816 set_pin_power_state(codec, 0x23, &parm);
817 if (smart51_enabled(codec))
818 set_pin_power_state(codec, 0x1a, &parm);
819 update_power_state(codec, 0x27, parm);
820 update_power_state(codec, 0x25, parm);
821 }
822
823 /* PW 3/4/7 (1ch/1dh/23h) */
824 parm = AC_PWRST_D3;
825 /* force to D0 for internal Speaker */
826 set_pin_power_state(codec, 0x1c, &parm);
827 set_pin_power_state(codec, 0x1d, &parm);
828 if (is_8ch)
829 set_pin_power_state(codec, 0x23, &parm);
830
831 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
832 update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
833 update_power_state(codec, 0x10, parm);
834 if (is_8ch) {
835 update_power_state(codec, 0x25, parm);
836 update_power_state(codec, 0x27, parm);
837 } else if (codec->vendor_id == 0x11064397 && spec->gen.indep_hp_enabled)
838 update_power_state(codec, 0x25, parm);
839}
840
841static int patch_vt1708S(struct hda_codec *codec); 715static int patch_vt1708S(struct hda_codec *codec);
842static int patch_vt1708B(struct hda_codec *codec) 716static int patch_vt1708B(struct hda_codec *codec)
843{ 717{
@@ -862,9 +736,6 @@ static int patch_vt1708B(struct hda_codec *codec)
862 } 736 }
863 737
864 codec->patch_ops = via_patch_ops; 738 codec->patch_ops = via_patch_ops;
865
866 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
867
868 return 0; 739 return 0;
869} 740}
870 741
@@ -905,19 +776,19 @@ static int patch_vt1708S(struct hda_codec *codec)
905 776
906 /* correct names for VT1708BCE */ 777 /* correct names for VT1708BCE */
907 if (get_codec_type(codec) == VT1708BCE) { 778 if (get_codec_type(codec) == VT1708BCE) {
908 kfree(codec->chip_name); 779 kfree(codec->core.chip_name);
909 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL); 780 codec->core.chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
910 snprintf(codec->bus->card->mixername, 781 snprintf(codec->card->mixername,
911 sizeof(codec->bus->card->mixername), 782 sizeof(codec->card->mixername),
912 "%s %s", codec->vendor_name, codec->chip_name); 783 "%s %s", codec->core.vendor_name, codec->core.chip_name);
913 } 784 }
914 /* correct names for VT1705 */ 785 /* correct names for VT1705 */
915 if (codec->vendor_id == 0x11064397) { 786 if (codec->core.vendor_id == 0x11064397) {
916 kfree(codec->chip_name); 787 kfree(codec->core.chip_name);
917 codec->chip_name = kstrdup("VT1705", GFP_KERNEL); 788 codec->core.chip_name = kstrdup("VT1705", GFP_KERNEL);
918 snprintf(codec->bus->card->mixername, 789 snprintf(codec->card->mixername,
919 sizeof(codec->bus->card->mixername), 790 sizeof(codec->card->mixername),
920 "%s %s", codec->vendor_name, codec->chip_name); 791 "%s %s", codec->core.vendor_name, codec->core.chip_name);
921 } 792 }
922 793
923 /* automatic parse from the BIOS config */ 794 /* automatic parse from the BIOS config */
@@ -930,8 +801,6 @@ static int patch_vt1708S(struct hda_codec *codec)
930 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs; 801 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
931 802
932 codec->patch_ops = via_patch_ops; 803 codec->patch_ops = via_patch_ops;
933
934 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
935 return 0; 804 return 0;
936} 805}
937 806
@@ -945,36 +814,6 @@ static const struct hda_verb vt1702_init_verbs[] = {
945 { } 814 { }
946}; 815};
947 816
948static void set_widgets_power_state_vt1702(struct hda_codec *codec)
949{
950 int imux_is_smixer =
951 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
952 unsigned int parm;
953 /* inputs */
954 /* PW 1/2/5 (14h/15h/18h) */
955 parm = AC_PWRST_D3;
956 set_pin_power_state(codec, 0x14, &parm);
957 set_pin_power_state(codec, 0x15, &parm);
958 set_pin_power_state(codec, 0x18, &parm);
959 if (imux_is_smixer)
960 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
961 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
962 update_power_state(codec, 0x13, parm);
963 update_power_state(codec, 0x12, parm);
964 update_power_state(codec, 0x1f, parm);
965 update_power_state(codec, 0x20, parm);
966
967 /* outputs */
968 /* PW 3/4 (16h/17h) */
969 parm = AC_PWRST_D3;
970 set_pin_power_state(codec, 0x17, &parm);
971 set_pin_power_state(codec, 0x16, &parm);
972 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
973 update_power_state(codec, 0x1a, imux_is_smixer ? AC_PWRST_D0 : parm);
974 update_power_state(codec, 0x10, parm);
975 update_power_state(codec, 0x1d, parm);
976}
977
978static int patch_vt1702(struct hda_codec *codec) 817static int patch_vt1702(struct hda_codec *codec)
979{ 818{
980 struct via_spec *spec; 819 struct via_spec *spec;
@@ -1004,8 +843,6 @@ static int patch_vt1702(struct hda_codec *codec)
1004 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs; 843 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
1005 844
1006 codec->patch_ops = via_patch_ops; 845 codec->patch_ops = via_patch_ops;
1007
1008 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
1009 return 0; 846 return 0;
1010} 847}
1011 848
@@ -1020,71 +857,6 @@ static const struct hda_verb vt1718S_init_verbs[] = {
1020 { } 857 { }
1021}; 858};
1022 859
1023static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
1024{
1025 struct via_spec *spec = codec->spec;
1026 int imux_is_smixer;
1027 unsigned int parm, parm2;
1028 /* MUX6 (1eh) = stereo mixer */
1029 imux_is_smixer =
1030 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
1031 /* inputs */
1032 /* PW 5/6/7 (29h/2ah/2bh) */
1033 parm = AC_PWRST_D3;
1034 set_pin_power_state(codec, 0x29, &parm);
1035 set_pin_power_state(codec, 0x2a, &parm);
1036 set_pin_power_state(codec, 0x2b, &parm);
1037 if (imux_is_smixer)
1038 parm = AC_PWRST_D0;
1039 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
1040 update_power_state(codec, 0x1e, parm);
1041 update_power_state(codec, 0x1f, parm);
1042 update_power_state(codec, 0x10, parm);
1043 update_power_state(codec, 0x11, parm);
1044
1045 /* outputs */
1046 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
1047 parm = AC_PWRST_D3;
1048 set_pin_power_state(codec, 0x27, &parm);
1049 update_power_state(codec, 0x1a, parm);
1050 parm2 = parm; /* for pin 0x0b */
1051
1052 /* PW2 (26h), AOW2 (ah) */
1053 parm = AC_PWRST_D3;
1054 set_pin_power_state(codec, 0x26, &parm);
1055 if (smart51_enabled(codec))
1056 set_pin_power_state(codec, 0x2b, &parm);
1057 update_power_state(codec, 0xa, parm);
1058
1059 /* PW0 (24h), AOW0 (8h) */
1060 parm = AC_PWRST_D3;
1061 set_pin_power_state(codec, 0x24, &parm);
1062 if (!spec->gen.indep_hp_enabled) /* check for redirected HP */
1063 set_pin_power_state(codec, 0x28, &parm);
1064 update_power_state(codec, 0x8, parm);
1065 if (!spec->gen.indep_hp_enabled && parm2 != AC_PWRST_D3)
1066 parm = parm2;
1067 update_power_state(codec, 0xb, parm);
1068 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
1069 update_power_state(codec, 0x21, imux_is_smixer ? AC_PWRST_D0 : parm);
1070
1071 /* PW1 (25h), AOW1 (9h) */
1072 parm = AC_PWRST_D3;
1073 set_pin_power_state(codec, 0x25, &parm);
1074 if (smart51_enabled(codec))
1075 set_pin_power_state(codec, 0x2a, &parm);
1076 update_power_state(codec, 0x9, parm);
1077
1078 if (spec->gen.indep_hp_enabled) {
1079 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
1080 parm = AC_PWRST_D3;
1081 set_pin_power_state(codec, 0x28, &parm);
1082 update_power_state(codec, 0x1b, parm);
1083 update_power_state(codec, 0x34, parm);
1084 update_power_state(codec, 0xc, parm);
1085 }
1086}
1087
1088/* Add a connection to the primary DAC from AA-mixer for some codecs 860/* Add a connection to the primary DAC from AA-mixer for some codecs
1089 * This isn't listed from the raw info, but the chip has a secret connection. 861 * This isn't listed from the raw info, but the chip has a secret connection.
1090 */ 862 */
@@ -1105,8 +877,7 @@ static int add_secret_dac_path(struct hda_codec *codec)
1105 } 877 }
1106 878
1107 /* find the primary DAC and add to the connection list */ 879 /* find the primary DAC and add to the connection list */
1108 nid = codec->start_nid; 880 for_each_hda_codec_node(nid, codec) {
1109 for (i = 0; i < codec->num_nodes; i++, nid++) {
1110 unsigned int caps = get_wcaps(codec, nid); 881 unsigned int caps = get_wcaps(codec, nid);
1111 if (get_wcaps_type(caps) == AC_WID_AUD_OUT && 882 if (get_wcaps_type(caps) == AC_WID_AUD_OUT &&
1112 !(caps & AC_WCAP_DIGITAL)) { 883 !(caps & AC_WCAP_DIGITAL)) {
@@ -1145,9 +916,6 @@ static int patch_vt1718S(struct hda_codec *codec)
1145 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs; 916 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
1146 917
1147 codec->patch_ops = via_patch_ops; 918 codec->patch_ops = via_patch_ops;
1148
1149 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
1150
1151 return 0; 919 return 0;
1152} 920}
1153 921
@@ -1187,7 +955,6 @@ static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
1187 snd_hda_codec_write(codec, 0x26, 0, 955 snd_hda_codec_write(codec, 0x26, 0,
1188 AC_VERB_SET_CONNECT_SEL, index); 956 AC_VERB_SET_CONNECT_SEL, index);
1189 spec->dmic_enabled = index; 957 spec->dmic_enabled = index;
1190 set_widgets_power_state(codec);
1191 return 1; 958 return 1;
1192} 959}
1193 960
@@ -1222,95 +989,6 @@ static const struct hda_verb vt1716S_init_verbs[] = {
1222 { } 989 { }
1223}; 990};
1224 991
1225static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
1226{
1227 struct via_spec *spec = codec->spec;
1228 int imux_is_smixer;
1229 unsigned int parm;
1230 unsigned int mono_out, present;
1231 /* SW0 (17h) = stereo mixer */
1232 imux_is_smixer =
1233 (snd_hda_codec_read(codec, 0x17, 0,
1234 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
1235 /* inputs */
1236 /* PW 1/2/5 (1ah/1bh/1eh) */
1237 parm = AC_PWRST_D3;
1238 set_pin_power_state(codec, 0x1a, &parm);
1239 set_pin_power_state(codec, 0x1b, &parm);
1240 set_pin_power_state(codec, 0x1e, &parm);
1241 if (imux_is_smixer)
1242 parm = AC_PWRST_D0;
1243 /* SW0 (17h), AIW0(13h) */
1244 update_power_state(codec, 0x17, parm);
1245 update_power_state(codec, 0x13, parm);
1246
1247 parm = AC_PWRST_D3;
1248 set_pin_power_state(codec, 0x1e, &parm);
1249 /* PW11 (22h) */
1250 if (spec->dmic_enabled)
1251 set_pin_power_state(codec, 0x22, &parm);
1252 else
1253 update_power_state(codec, 0x22, AC_PWRST_D3);
1254
1255 /* SW2(26h), AIW1(14h) */
1256 update_power_state(codec, 0x26, parm);
1257 update_power_state(codec, 0x14, parm);
1258
1259 /* outputs */
1260 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
1261 parm = AC_PWRST_D3;
1262 set_pin_power_state(codec, 0x19, &parm);
1263 /* Smart 5.1 PW2(1bh) */
1264 if (smart51_enabled(codec))
1265 set_pin_power_state(codec, 0x1b, &parm);
1266 update_power_state(codec, 0x18, parm);
1267 update_power_state(codec, 0x11, parm);
1268
1269 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
1270 parm = AC_PWRST_D3;
1271 set_pin_power_state(codec, 0x23, &parm);
1272 /* Smart 5.1 PW1(1ah) */
1273 if (smart51_enabled(codec))
1274 set_pin_power_state(codec, 0x1a, &parm);
1275 update_power_state(codec, 0x27, parm);
1276
1277 /* Smart 5.1 PW5(1eh) */
1278 if (smart51_enabled(codec))
1279 set_pin_power_state(codec, 0x1e, &parm);
1280 update_power_state(codec, 0x25, parm);
1281
1282 /* Mono out */
1283 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
1284 present = snd_hda_jack_detect(codec, 0x1c);
1285
1286 if (present)
1287 mono_out = 0;
1288 else {
1289 present = snd_hda_jack_detect(codec, 0x1d);
1290 if (!spec->gen.indep_hp_enabled && present)
1291 mono_out = 0;
1292 else
1293 mono_out = 1;
1294 }
1295 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
1296 update_power_state(codec, 0x28, parm);
1297 update_power_state(codec, 0x29, parm);
1298 update_power_state(codec, 0x2a, parm);
1299
1300 /* PW 3/4 (1ch/1dh) */
1301 parm = AC_PWRST_D3;
1302 set_pin_power_state(codec, 0x1c, &parm);
1303 set_pin_power_state(codec, 0x1d, &parm);
1304 /* HP Independent Mode, power on AOW3 */
1305 if (spec->gen.indep_hp_enabled)
1306 update_power_state(codec, 0x25, parm);
1307
1308 /* force to D0 for internal Speaker */
1309 /* MW0 (16h), AOW0 (10h) */
1310 update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
1311 update_power_state(codec, 0x10, mono_out ? AC_PWRST_D0 : parm);
1312}
1313
1314static int patch_vt1716S(struct hda_codec *codec) 992static int patch_vt1716S(struct hda_codec *codec)
1315{ 993{
1316 struct via_spec *spec; 994 struct via_spec *spec;
@@ -1338,8 +1016,6 @@ static int patch_vt1716S(struct hda_codec *codec)
1338 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer; 1016 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
1339 1017
1340 codec->patch_ops = via_patch_ops; 1018 codec->patch_ops = via_patch_ops;
1341
1342 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
1343 return 0; 1019 return 0;
1344} 1020}
1345 1021
@@ -1365,98 +1041,6 @@ static const struct hda_verb vt1802_init_verbs[] = {
1365 { } 1041 { }
1366}; 1042};
1367 1043
1368static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
1369{
1370 struct via_spec *spec = codec->spec;
1371 int imux_is_smixer;
1372 unsigned int parm;
1373 unsigned int present;
1374 /* MUX9 (1eh) = stereo mixer */
1375 imux_is_smixer =
1376 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
1377 /* inputs */
1378 /* PW 5/6/7 (29h/2ah/2bh) */
1379 parm = AC_PWRST_D3;
1380 set_pin_power_state(codec, 0x29, &parm);
1381 set_pin_power_state(codec, 0x2a, &parm);
1382 set_pin_power_state(codec, 0x2b, &parm);
1383 parm = AC_PWRST_D0;
1384 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
1385 update_power_state(codec, 0x1e, parm);
1386 update_power_state(codec, 0x1f, parm);
1387 update_power_state(codec, 0x10, parm);
1388 update_power_state(codec, 0x11, parm);
1389
1390 /* outputs */
1391 /* AOW0 (8h)*/
1392 update_power_state(codec, 0x8, parm);
1393
1394 if (spec->codec_type == VT1802) {
1395 /* PW4 (28h), MW4 (18h), MUX4(38h) */
1396 parm = AC_PWRST_D3;
1397 set_pin_power_state(codec, 0x28, &parm);
1398 update_power_state(codec, 0x18, parm);
1399 update_power_state(codec, 0x38, parm);
1400 } else {
1401 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
1402 parm = AC_PWRST_D3;
1403 set_pin_power_state(codec, 0x26, &parm);
1404 update_power_state(codec, 0x1c, parm);
1405 update_power_state(codec, 0x37, parm);
1406 }
1407
1408 if (spec->codec_type == VT1802) {
1409 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
1410 parm = AC_PWRST_D3;
1411 set_pin_power_state(codec, 0x25, &parm);
1412 update_power_state(codec, 0x15, parm);
1413 update_power_state(codec, 0x35, parm);
1414 } else {
1415 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
1416 parm = AC_PWRST_D3;
1417 set_pin_power_state(codec, 0x25, &parm);
1418 update_power_state(codec, 0x19, parm);
1419 update_power_state(codec, 0x35, parm);
1420 }
1421
1422 if (spec->gen.indep_hp_enabled)
1423 update_power_state(codec, 0x9, AC_PWRST_D0);
1424
1425 /* Class-D */
1426 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
1427 present = snd_hda_jack_detect(codec, 0x25);
1428
1429 parm = AC_PWRST_D3;
1430 set_pin_power_state(codec, 0x24, &parm);
1431 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
1432 if (spec->codec_type == VT1802)
1433 update_power_state(codec, 0x14, parm);
1434 else
1435 update_power_state(codec, 0x18, parm);
1436 update_power_state(codec, 0x34, parm);
1437
1438 /* Mono Out */
1439 present = snd_hda_jack_detect(codec, 0x26);
1440
1441 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
1442 if (spec->codec_type == VT1802) {
1443 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
1444 update_power_state(codec, 0x33, parm);
1445 update_power_state(codec, 0x1c, parm);
1446 update_power_state(codec, 0x3c, parm);
1447 } else {
1448 /* PW15 (31h), MW8(17h), MUX8(3bh) */
1449 update_power_state(codec, 0x31, parm);
1450 update_power_state(codec, 0x17, parm);
1451 update_power_state(codec, 0x3b, parm);
1452 }
1453 /* MW9 (21h) */
1454 if (imux_is_smixer || !is_aa_path_mute(codec))
1455 update_power_state(codec, 0x21, AC_PWRST_D0);
1456 else
1457 update_power_state(codec, 0x21, AC_PWRST_D3);
1458}
1459
1460/* 1044/*
1461 * pin fix-up 1045 * pin fix-up
1462 */ 1046 */
@@ -1540,8 +1124,6 @@ static int patch_vt2002P(struct hda_codec *codec)
1540 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs; 1124 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
1541 1125
1542 codec->patch_ops = via_patch_ops; 1126 codec->patch_ops = via_patch_ops;
1543
1544 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
1545 return 0; 1127 return 0;
1546} 1128}
1547 1129
@@ -1555,81 +1137,6 @@ static const struct hda_verb vt1812_init_verbs[] = {
1555 { } 1137 { }
1556}; 1138};
1557 1139
1558static void set_widgets_power_state_vt1812(struct hda_codec *codec)
1559{
1560 struct via_spec *spec = codec->spec;
1561 unsigned int parm;
1562 unsigned int present;
1563 /* inputs */
1564 /* PW 5/6/7 (29h/2ah/2bh) */
1565 parm = AC_PWRST_D3;
1566 set_pin_power_state(codec, 0x29, &parm);
1567 set_pin_power_state(codec, 0x2a, &parm);
1568 set_pin_power_state(codec, 0x2b, &parm);
1569 parm = AC_PWRST_D0;
1570 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
1571 update_power_state(codec, 0x1e, parm);
1572 update_power_state(codec, 0x1f, parm);
1573 update_power_state(codec, 0x10, parm);
1574 update_power_state(codec, 0x11, parm);
1575
1576 /* outputs */
1577 /* AOW0 (8h)*/
1578 update_power_state(codec, 0x8, AC_PWRST_D0);
1579
1580 /* PW4 (28h), MW4 (18h), MUX4(38h) */
1581 parm = AC_PWRST_D3;
1582 set_pin_power_state(codec, 0x28, &parm);
1583 update_power_state(codec, 0x18, parm);
1584 update_power_state(codec, 0x38, parm);
1585
1586 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
1587 parm = AC_PWRST_D3;
1588 set_pin_power_state(codec, 0x25, &parm);
1589 update_power_state(codec, 0x15, parm);
1590 update_power_state(codec, 0x35, parm);
1591 if (spec->gen.indep_hp_enabled)
1592 update_power_state(codec, 0x9, AC_PWRST_D0);
1593
1594 /* Internal Speaker */
1595 /* PW0 (24h), MW0(14h), MUX0(34h) */
1596 present = snd_hda_jack_detect(codec, 0x25);
1597
1598 parm = AC_PWRST_D3;
1599 set_pin_power_state(codec, 0x24, &parm);
1600 if (present) {
1601 update_power_state(codec, 0x14, AC_PWRST_D3);
1602 update_power_state(codec, 0x34, AC_PWRST_D3);
1603 } else {
1604 update_power_state(codec, 0x14, AC_PWRST_D0);
1605 update_power_state(codec, 0x34, AC_PWRST_D0);
1606 }
1607
1608
1609 /* Mono Out */
1610 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
1611 present = snd_hda_jack_detect(codec, 0x28);
1612
1613 parm = AC_PWRST_D3;
1614 set_pin_power_state(codec, 0x31, &parm);
1615 if (present) {
1616 update_power_state(codec, 0x1c, AC_PWRST_D3);
1617 update_power_state(codec, 0x3c, AC_PWRST_D3);
1618 update_power_state(codec, 0x3e, AC_PWRST_D3);
1619 } else {
1620 update_power_state(codec, 0x1c, AC_PWRST_D0);
1621 update_power_state(codec, 0x3c, AC_PWRST_D0);
1622 update_power_state(codec, 0x3e, AC_PWRST_D0);
1623 }
1624
1625 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
1626 parm = AC_PWRST_D3;
1627 set_pin_power_state(codec, 0x33, &parm);
1628 update_power_state(codec, 0x1d, parm);
1629 update_power_state(codec, 0x3d, parm);
1630
1631}
1632
1633/* patch for vt1812 */ 1140/* patch for vt1812 */
1634static int patch_vt1812(struct hda_codec *codec) 1141static int patch_vt1812(struct hda_codec *codec)
1635{ 1142{
@@ -1656,8 +1163,6 @@ static int patch_vt1812(struct hda_codec *codec)
1656 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs; 1163 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
1657 1164
1658 codec->patch_ops = via_patch_ops; 1165 codec->patch_ops = via_patch_ops;
1659
1660 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
1661 return 0; 1166 return 0;
1662} 1167}
1663 1168
@@ -1673,84 +1178,6 @@ static const struct hda_verb vt3476_init_verbs[] = {
1673 { } 1178 { }
1674}; 1179};
1675 1180
1676static void set_widgets_power_state_vt3476(struct hda_codec *codec)
1677{
1678 struct via_spec *spec = codec->spec;
1679 int imux_is_smixer;
1680 unsigned int parm, parm2;
1681 /* MUX10 (1eh) = stereo mixer */
1682 imux_is_smixer =
1683 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 4;
1684 /* inputs */
1685 /* PW 5/6/7 (29h/2ah/2bh) */
1686 parm = AC_PWRST_D3;
1687 set_pin_power_state(codec, 0x29, &parm);
1688 set_pin_power_state(codec, 0x2a, &parm);
1689 set_pin_power_state(codec, 0x2b, &parm);
1690 if (imux_is_smixer)
1691 parm = AC_PWRST_D0;
1692 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
1693 update_power_state(codec, 0x1e, parm);
1694 update_power_state(codec, 0x1f, parm);
1695 update_power_state(codec, 0x10, parm);
1696 update_power_state(codec, 0x11, parm);
1697
1698 /* outputs */
1699 /* PW3 (27h), MW3(37h), AOW3 (bh) */
1700 if (spec->codec_type == VT1705CF) {
1701 parm = AC_PWRST_D3;
1702 update_power_state(codec, 0x27, parm);
1703 update_power_state(codec, 0x37, parm);
1704 } else {
1705 parm = AC_PWRST_D3;
1706 set_pin_power_state(codec, 0x27, &parm);
1707 update_power_state(codec, 0x37, parm);
1708 }
1709
1710 /* PW2 (26h), MW2(36h), AOW2 (ah) */
1711 parm = AC_PWRST_D3;
1712 set_pin_power_state(codec, 0x26, &parm);
1713 update_power_state(codec, 0x36, parm);
1714 if (smart51_enabled(codec)) {
1715 /* PW7(2bh), MW7(3bh), MUX7(1Bh) */
1716 set_pin_power_state(codec, 0x2b, &parm);
1717 update_power_state(codec, 0x3b, parm);
1718 update_power_state(codec, 0x1b, parm);
1719 }
1720 update_conv_power_state(codec, 0xa, parm, 2);
1721
1722 /* PW1 (25h), MW1(35h), AOW1 (9h) */
1723 parm = AC_PWRST_D3;
1724 set_pin_power_state(codec, 0x25, &parm);
1725 update_power_state(codec, 0x35, parm);
1726 if (smart51_enabled(codec)) {
1727 /* PW6(2ah), MW6(3ah), MUX6(1ah) */
1728 set_pin_power_state(codec, 0x2a, &parm);
1729 update_power_state(codec, 0x3a, parm);
1730 update_power_state(codec, 0x1a, parm);
1731 }
1732 update_conv_power_state(codec, 0x9, parm, 1);
1733
1734 /* PW4 (28h), MW4 (38h), MUX4(18h), AOW3(bh)/AOW0(8h) */
1735 parm = AC_PWRST_D3;
1736 set_pin_power_state(codec, 0x28, &parm);
1737 update_power_state(codec, 0x38, parm);
1738 update_power_state(codec, 0x18, parm);
1739 if (spec->gen.indep_hp_enabled)
1740 update_conv_power_state(codec, 0xb, parm, 3);
1741 parm2 = parm; /* for pin 0x0b */
1742
1743 /* PW0 (24h), MW0(34h), MW9(3fh), AOW0 (8h) */
1744 parm = AC_PWRST_D3;
1745 set_pin_power_state(codec, 0x24, &parm);
1746 update_power_state(codec, 0x34, parm);
1747 if (!spec->gen.indep_hp_enabled && parm2 != AC_PWRST_D3)
1748 parm = parm2;
1749 update_conv_power_state(codec, 0x8, parm, 0);
1750 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
1751 update_power_state(codec, 0x3f, imux_is_smixer ? AC_PWRST_D0 : parm);
1752}
1753
1754static int patch_vt3476(struct hda_codec *codec) 1181static int patch_vt3476(struct hda_codec *codec)
1755{ 1182{
1756 struct via_spec *spec; 1183 struct via_spec *spec;
@@ -1774,9 +1201,6 @@ static int patch_vt3476(struct hda_codec *codec)
1774 spec->init_verbs[spec->num_iverbs++] = vt3476_init_verbs; 1201 spec->init_verbs[spec->num_iverbs++] = vt3476_init_verbs;
1775 1202
1776 codec->patch_ops = via_patch_ops; 1203 codec->patch_ops = via_patch_ops;
1777
1778 spec->set_widgets_power_state = set_widgets_power_state_vt3476;
1779
1780 return 0; 1204 return 0;
1781} 1205}
1782 1206
@@ -1884,23 +1308,11 @@ static const struct hda_codec_preset snd_hda_preset_via[] = {
1884 1308
1885MODULE_ALIAS("snd-hda-codec-id:1106*"); 1309MODULE_ALIAS("snd-hda-codec-id:1106*");
1886 1310
1887static struct hda_codec_preset_list via_list = { 1311static struct hda_codec_driver via_driver = {
1888 .preset = snd_hda_preset_via, 1312 .preset = snd_hda_preset_via,
1889 .owner = THIS_MODULE,
1890}; 1313};
1891 1314
1892MODULE_LICENSE("GPL"); 1315MODULE_LICENSE("GPL");
1893MODULE_DESCRIPTION("VIA HD-audio codec"); 1316MODULE_DESCRIPTION("VIA HD-audio codec");
1894 1317
1895static int __init patch_via_init(void) 1318module_hda_codec_driver(via_driver);
1896{
1897 return snd_hda_add_codec_preset(&via_list);
1898}
1899
1900static void __exit patch_via_exit(void)
1901{
1902 snd_hda_delete_codec_preset(&via_list);
1903}
1904
1905module_init(patch_via_init)
1906module_exit(patch_via_exit)
diff --git a/sound/pci/hda/thinkpad_helper.c b/sound/pci/hda/thinkpad_helper.c
index 6ba0b5517c40..0a4ad5feb82e 100644
--- a/sound/pci/hda/thinkpad_helper.c
+++ b/sound/pci/hda/thinkpad_helper.c
@@ -21,7 +21,7 @@ static acpi_status acpi_check_cb(acpi_handle handle, u32 lvl, void *context,
21static bool is_thinkpad(struct hda_codec *codec) 21static bool is_thinkpad(struct hda_codec *codec)
22{ 22{
23 bool found = false; 23 bool found = false;
24 if (codec->subsystem_id >> 16 != 0x17aa) 24 if (codec->core.subsystem_id >> 16 != 0x17aa)
25 return false; 25 return false;
26 if (ACPI_SUCCESS(acpi_get_devices("LEN0068", acpi_check_cb, &found, NULL)) && found) 26 if (ACPI_SUCCESS(acpi_get_devices("LEN0068", acpi_check_cb, &found, NULL)) && found)
27 return true; 27 return true;
diff --git a/sound/pci/ice1712/wtm.c b/sound/pci/ice1712/wtm.c
index bcf30a387b87..9906119e0954 100644
--- a/sound/pci/ice1712/wtm.c
+++ b/sound/pci/ice1712/wtm.c
@@ -29,12 +29,19 @@
29#include <linux/interrupt.h> 29#include <linux/interrupt.h>
30#include <linux/init.h> 30#include <linux/init.h>
31#include <sound/core.h> 31#include <sound/core.h>
32#include <sound/tlv.h>
33#include <linux/slab.h>
32 34
33#include "ice1712.h" 35#include "ice1712.h"
34#include "envy24ht.h" 36#include "envy24ht.h"
35#include "wtm.h" 37#include "wtm.h"
36#include "stac946x.h" 38#include "stac946x.h"
37 39
40struct wtm_spec {
41 /* rate change needs atomic mute/unmute of all dacs*/
42 struct mutex mute_mutex;
43};
44
38 45
39/* 46/*
40 * 2*ADC 6*DAC no1 ringbuffer r/w on i2c bus 47 * 2*ADC 6*DAC no1 ringbuffer r/w on i2c bus
@@ -68,15 +75,65 @@ static inline unsigned char stac9460_2_get(struct snd_ice1712 *ice, int reg)
68/* 75/*
69 * DAC mute control 76 * DAC mute control
70 */ 77 */
78static void stac9460_dac_mute_all(struct snd_ice1712 *ice, unsigned char mute,
79 unsigned short int *change_mask)
80{
81 unsigned char new, old;
82 int id, idx, change;
83
84 /*stac9460 1*/
85 for (id = 0; id < 7; id++) {
86 if (*change_mask & (0x01 << id)) {
87 if (id == 0)
88 idx = STAC946X_MASTER_VOLUME;
89 else
90 idx = STAC946X_LF_VOLUME - 1 + id;
91 old = stac9460_get(ice, idx);
92 new = (~mute << 7 & 0x80) | (old & ~0x80);
93 change = (new != old);
94 if (change) {
95 stac9460_put(ice, idx, new);
96 *change_mask = *change_mask | (0x01 << id);
97 } else {
98 *change_mask = *change_mask & ~(0x01 << id);
99 }
100 }
101 }
102
103 /*stac9460 2*/
104 for (id = 0; id < 3; id++) {
105 if (*change_mask & (0x01 << (id + 7))) {
106 if (id == 0)
107 idx = STAC946X_MASTER_VOLUME;
108 else
109 idx = STAC946X_LF_VOLUME - 1 + id;
110 old = stac9460_2_get(ice, idx);
111 new = (~mute << 7 & 0x80) | (old & ~0x80);
112 change = (new != old);
113 if (change) {
114 stac9460_2_put(ice, idx, new);
115 *change_mask = *change_mask | (0x01 << id);
116 } else {
117 *change_mask = *change_mask & ~(0x01 << id);
118 }
119 }
120 }
121}
122
123
124
71#define stac9460_dac_mute_info snd_ctl_boolean_mono_info 125#define stac9460_dac_mute_info snd_ctl_boolean_mono_info
72 126
73static int stac9460_dac_mute_get(struct snd_kcontrol *kcontrol, 127static int stac9460_dac_mute_get(struct snd_kcontrol *kcontrol,
74 struct snd_ctl_elem_value *ucontrol) 128 struct snd_ctl_elem_value *ucontrol)
75{ 129{
76 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 130 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
131 struct wtm_spec *spec = ice->spec;
77 unsigned char val; 132 unsigned char val;
78 int idx, id; 133 int idx, id;
79 134
135 mutex_lock(&spec->mute_mutex);
136
80 if (kcontrol->private_value) { 137 if (kcontrol->private_value) {
81 idx = STAC946X_MASTER_VOLUME; 138 idx = STAC946X_MASTER_VOLUME;
82 id = 0; 139 id = 0;
@@ -89,6 +146,8 @@ static int stac9460_dac_mute_get(struct snd_kcontrol *kcontrol,
89 else 146 else
90 val = stac9460_2_get(ice, idx - 6); 147 val = stac9460_2_get(ice, idx - 6);
91 ucontrol->value.integer.value[0] = (~val >> 7) & 0x1; 148 ucontrol->value.integer.value[0] = (~val >> 7) & 0x1;
149
150 mutex_unlock(&spec->mute_mutex);
92 return 0; 151 return 0;
93} 152}
94 153
@@ -338,8 +397,14 @@ static int stac9460_adc_vol_put(struct snd_kcontrol *kcontrol,
338/* 397/*
339 * MIC / LINE switch fonction 398 * MIC / LINE switch fonction
340 */ 399 */
400static int stac9460_mic_sw_info(struct snd_kcontrol *kcontrol,
401 struct snd_ctl_elem_info *uinfo)
402{
403 static const char * const texts[2] = { "Line In", "Mic" };
404
405 return snd_ctl_enum_info(uinfo, 1, 2, texts);
406}
341 407
342#define stac9460_mic_sw_info snd_ctl_boolean_mono_info
343 408
344static int stac9460_mic_sw_get(struct snd_kcontrol *kcontrol, 409static int stac9460_mic_sw_get(struct snd_kcontrol *kcontrol,
345 struct snd_ctl_elem_value *ucontrol) 410 struct snd_ctl_elem_value *ucontrol)
@@ -353,7 +418,7 @@ static int stac9460_mic_sw_get(struct snd_kcontrol *kcontrol,
353 val = stac9460_get(ice, STAC946X_GENERAL_PURPOSE); 418 val = stac9460_get(ice, STAC946X_GENERAL_PURPOSE);
354 else 419 else
355 val = stac9460_2_get(ice, STAC946X_GENERAL_PURPOSE); 420 val = stac9460_2_get(ice, STAC946X_GENERAL_PURPOSE);
356 ucontrol->value.integer.value[0] = ~val>>7 & 0x1; 421 ucontrol->value.enumerated.item[0] = (val >> 7) & 0x1;
357 return 0; 422 return 0;
358} 423}
359 424
@@ -369,7 +434,7 @@ static int stac9460_mic_sw_put(struct snd_kcontrol *kcontrol,
369 old = stac9460_get(ice, STAC946X_GENERAL_PURPOSE); 434 old = stac9460_get(ice, STAC946X_GENERAL_PURPOSE);
370 else 435 else
371 old = stac9460_2_get(ice, STAC946X_GENERAL_PURPOSE); 436 old = stac9460_2_get(ice, STAC946X_GENERAL_PURPOSE);
372 new = (~ucontrol->value.integer.value[0] << 7 & 0x80) | (old & ~0x80); 437 new = (ucontrol->value.enumerated.item[0] << 7 & 0x80) | (old & ~0x80);
373 change = (new != old); 438 change = (new != old);
374 if (change) { 439 if (change) {
375 if (id == 0) 440 if (id == 0)
@@ -380,17 +445,63 @@ static int stac9460_mic_sw_put(struct snd_kcontrol *kcontrol,
380 return change; 445 return change;
381} 446}
382 447
448
449/*
450 * Handler for setting correct codec rate - called when rate change is detected
451 */
452static void stac9460_set_rate_val(struct snd_ice1712 *ice, unsigned int rate)
453{
454 unsigned char old, new;
455 unsigned short int changed;
456 struct wtm_spec *spec = ice->spec;
457
458 if (rate == 0) /* no hint - S/PDIF input is master, simply return */
459 return;
460 else if (rate <= 48000)
461 new = 0x08; /* 256x, base rate mode */
462 else if (rate <= 96000)
463 new = 0x11; /* 256x, mid rate mode */
464 else
465 new = 0x12; /* 128x, high rate mode */
466
467 old = stac9460_get(ice, STAC946X_MASTER_CLOCKING);
468 if (old == new)
469 return;
470 /* change detected, setting master clock, muting first */
471 /* due to possible conflicts with mute controls - mutexing */
472 mutex_lock(&spec->mute_mutex);
473 /* we have to remember current mute status for each DAC */
474 changed = 0xFFFF;
475 stac9460_dac_mute_all(ice, 0, &changed);
476 /*printk(KERN_DEBUG "Rate change: %d, new MC: 0x%02x\n", rate, new);*/
477 stac9460_put(ice, STAC946X_MASTER_CLOCKING, new);
478 stac9460_2_put(ice, STAC946X_MASTER_CLOCKING, new);
479 udelay(10);
480 /* unmuting - only originally unmuted dacs -
481 * i.e. those changed when muting */
482 stac9460_dac_mute_all(ice, 1, &changed);
483 mutex_unlock(&spec->mute_mutex);
484}
485
486
487/*Limits value in dB for fader*/
488static const DECLARE_TLV_DB_SCALE(db_scale_dac, -19125, 75, 0);
489static const DECLARE_TLV_DB_SCALE(db_scale_adc, 0, 150, 0);
490
383/* 491/*
384 * Control tabs 492 * Control tabs
385 */ 493 */
386static struct snd_kcontrol_new stac9640_controls[] = { 494static struct snd_kcontrol_new stac9640_controls[] = {
387 { 495 {
388 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 496 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
497 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
498 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
389 .name = "Master Playback Switch", 499 .name = "Master Playback Switch",
390 .info = stac9460_dac_mute_info, 500 .info = stac9460_dac_mute_info,
391 .get = stac9460_dac_mute_get, 501 .get = stac9460_dac_mute_get,
392 .put = stac9460_dac_mute_put, 502 .put = stac9460_dac_mute_put,
393 .private_value = 1 503 .private_value = 1,
504 .tlv = { .p = db_scale_dac }
394 }, 505 },
395 { 506 {
396 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 507 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
@@ -402,7 +513,7 @@ static struct snd_kcontrol_new stac9640_controls[] = {
402 }, 513 },
403 { 514 {
404 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 515 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
405 .name = "MIC/Line switch", 516 .name = "MIC/Line Input Enum",
406 .count = 2, 517 .count = 2,
407 .info = stac9460_mic_sw_info, 518 .info = stac9460_mic_sw_info,
408 .get = stac9460_mic_sw_get, 519 .get = stac9460_mic_sw_get,
@@ -419,11 +530,15 @@ static struct snd_kcontrol_new stac9640_controls[] = {
419 }, 530 },
420 { 531 {
421 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 532 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
533 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
534 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
535
422 .name = "DAC Volume", 536 .name = "DAC Volume",
423 .count = 8, 537 .count = 8,
424 .info = stac9460_dac_vol_info, 538 .info = stac9460_dac_vol_info,
425 .get = stac9460_dac_vol_get, 539 .get = stac9460_dac_vol_get,
426 .put = stac9460_dac_vol_put, 540 .put = stac9460_dac_vol_put,
541 .tlv = { .p = db_scale_dac }
427 }, 542 },
428 { 543 {
429 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 544 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
@@ -435,12 +550,15 @@ static struct snd_kcontrol_new stac9640_controls[] = {
435 }, 550 },
436 { 551 {
437 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 552 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
553 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
554 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
555
438 .name = "ADC Volume", 556 .name = "ADC Volume",
439 .count = 2, 557 .count = 2,
440 .info = stac9460_adc_vol_info, 558 .info = stac9460_adc_vol_info,
441 .get = stac9460_adc_vol_get, 559 .get = stac9460_adc_vol_get,
442 .put = stac9460_adc_vol_put, 560 .put = stac9460_adc_vol_put,
443 561 .tlv = { .p = db_scale_adc }
444 } 562 }
445}; 563};
446 564
@@ -463,41 +581,53 @@ static int wtm_add_controls(struct snd_ice1712 *ice)
463 581
464static int wtm_init(struct snd_ice1712 *ice) 582static int wtm_init(struct snd_ice1712 *ice)
465{ 583{
466 static unsigned short stac_inits_prodigy[] = { 584 static unsigned short stac_inits_wtm[] = {
467 STAC946X_RESET, 0, 585 STAC946X_RESET, 0,
586 STAC946X_MASTER_CLOCKING, 0x11,
468 (unsigned short)-1 587 (unsigned short)-1
469 }; 588 };
470 unsigned short *p; 589 unsigned short *p;
590 struct wtm_spec *spec;
471 591
472 /*WTM 192M*/ 592 /*WTM 192M*/
473 ice->num_total_dacs = 8; 593 ice->num_total_dacs = 8;
474 ice->num_total_adcs = 4; 594 ice->num_total_adcs = 4;
475 ice->force_rdma1 = 1; 595 ice->force_rdma1 = 1;
476 596
597 /*init mutex for dac mute conflict*/
598 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
599 if (!spec)
600 return -ENOMEM;
601 ice->spec = spec;
602 mutex_init(&spec->mute_mutex);
603
604
477 /*initialize codec*/ 605 /*initialize codec*/
478 p = stac_inits_prodigy; 606 p = stac_inits_wtm;
479 for (; *p != (unsigned short)-1; p += 2) { 607 for (; *p != (unsigned short)-1; p += 2) {
480 stac9460_put(ice, p[0], p[1]); 608 stac9460_put(ice, p[0], p[1]);
481 stac9460_2_put(ice, p[0], p[1]); 609 stac9460_2_put(ice, p[0], p[1]);
482 } 610 }
611 ice->gpio.set_pro_rate = stac9460_set_rate_val;
483 return 0; 612 return 0;
484} 613}
485 614
486 615
487static unsigned char wtm_eeprom[] = { 616static unsigned char wtm_eeprom[] = {
488 0x47, /*SYSCONF: clock 192KHz, 4ADC, 8DAC */ 617 [ICE_EEP2_SYSCONF] = 0x67, /*SYSCONF: clock 192KHz, mpu401,
489 0x80, /* ACLINK : I2S */ 618 4ADC, 8DAC */
490 0xf8, /* I2S: vol; 96k, 24bit, 192k */ 619 [ICE_EEP2_ACLINK] = 0x80, /* ACLINK : I2S */
491 0xc1 /*SPDIF: out-en, spidf ext out*/, 620 [ICE_EEP2_I2S] = 0xf8, /* I2S: vol; 96k, 24bit, 192k */
492 0x9f, /* GPIO_DIR */ 621 [ICE_EEP2_SPDIF] = 0xc1, /*SPDIF: out-en, spidf ext out*/
493 0xff, /* GPIO_DIR1 */ 622 [ICE_EEP2_GPIO_DIR] = 0x9f,
494 0x7f, /* GPIO_DIR2 */ 623 [ICE_EEP2_GPIO_DIR1] = 0xff,
495 0x9f, /* GPIO_MASK */ 624 [ICE_EEP2_GPIO_DIR2] = 0x7f,
496 0xff, /* GPIO_MASK1 */ 625 [ICE_EEP2_GPIO_MASK] = 0x9f,
497 0x7f, /* GPIO_MASK2 */ 626 [ICE_EEP2_GPIO_MASK1] = 0xff,
498 0x16, /* GPIO_STATE */ 627 [ICE_EEP2_GPIO_MASK2] = 0x7f,
499 0x80, /* GPIO_STATE1 */ 628 [ICE_EEP2_GPIO_STATE] = 0x16,
500 0x00, /* GPIO_STATE2 */ 629 [ICE_EEP2_GPIO_STATE1] = 0x80,
630 [ICE_EEP2_GPIO_STATE2] = 0x00,
501}; 631};
502 632
503 633
diff --git a/sound/pci/intel8x0.c b/sound/pci/intel8x0.c
index 2c5484eeb963..b120925223ae 100644
--- a/sound/pci/intel8x0.c
+++ b/sound/pci/intel8x0.c
@@ -1795,7 +1795,7 @@ static struct ac97_pcm ac97_pcm_defs[] = {
1795 }, 1795 },
1796}; 1796};
1797 1797
1798static struct ac97_quirk ac97_quirks[] = { 1798static const struct ac97_quirk ac97_quirks[] = {
1799 { 1799 {
1800 .subvendor = 0x0e11, 1800 .subvendor = 0x0e11,
1801 .subdevice = 0x000e, 1801 .subdevice = 0x000e,
@@ -3101,13 +3101,13 @@ static int snd_intel8x0_create(struct snd_card *card,
3101 chip->bmaddr = pci_iomap(pci, 3, 0); 3101 chip->bmaddr = pci_iomap(pci, 3, 0);
3102 else 3102 else
3103 chip->bmaddr = pci_iomap(pci, 1, 0); 3103 chip->bmaddr = pci_iomap(pci, 1, 0);
3104
3105 port_inited:
3104 if (!chip->bmaddr) { 3106 if (!chip->bmaddr) {
3105 dev_err(card->dev, "Controller space ioremap problem\n"); 3107 dev_err(card->dev, "Controller space ioremap problem\n");
3106 snd_intel8x0_free(chip); 3108 snd_intel8x0_free(chip);
3107 return -EIO; 3109 return -EIO;
3108 } 3110 }
3109
3110 port_inited:
3111 chip->bdbars_count = bdbars[device_type]; 3111 chip->bdbars_count = bdbars[device_type];
3112 3112
3113 /* initialize offsets */ 3113 /* initialize offsets */
diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c
index ca67f896d117..cb666c73712d 100644
--- a/sound/pci/rme9652/hdspm.c
+++ b/sound/pci/rme9652/hdspm.c
@@ -6043,23 +6043,30 @@ hdspm_hw_constraints_aes32_sample_rates = {
6043 .mask = 0 6043 .mask = 0
6044}; 6044};
6045 6045
6046static int snd_hdspm_playback_open(struct snd_pcm_substream *substream) 6046static int snd_hdspm_open(struct snd_pcm_substream *substream)
6047{ 6047{
6048 struct hdspm *hdspm = snd_pcm_substream_chip(substream); 6048 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
6049 struct snd_pcm_runtime *runtime = substream->runtime; 6049 struct snd_pcm_runtime *runtime = substream->runtime;
6050 bool playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
6050 6051
6051 spin_lock_irq(&hdspm->lock); 6052 spin_lock_irq(&hdspm->lock);
6052
6053 snd_pcm_set_sync(substream); 6053 snd_pcm_set_sync(substream);
6054 runtime->hw = (playback) ? snd_hdspm_playback_subinfo :
6055 snd_hdspm_capture_subinfo;
6054 6056
6057 if (playback) {
6058 if (hdspm->capture_substream == NULL)
6059 hdspm_stop_audio(hdspm);
6055 6060
6056 runtime->hw = snd_hdspm_playback_subinfo; 6061 hdspm->playback_pid = current->pid;
6057 6062 hdspm->playback_substream = substream;
6058 if (hdspm->capture_substream == NULL) 6063 } else {
6059 hdspm_stop_audio(hdspm); 6064 if (hdspm->playback_substream == NULL)
6065 hdspm_stop_audio(hdspm);
6060 6066
6061 hdspm->playback_pid = current->pid; 6067 hdspm->capture_pid = current->pid;
6062 hdspm->playback_substream = substream; 6068 hdspm->capture_substream = substream;
6069 }
6063 6070
6064 spin_unlock_irq(&hdspm->lock); 6071 spin_unlock_irq(&hdspm->lock);
6065 6072
@@ -6094,108 +6101,42 @@ static int snd_hdspm_playback_open(struct snd_pcm_substream *substream)
6094 &hdspm_hw_constraints_aes32_sample_rates); 6101 &hdspm_hw_constraints_aes32_sample_rates);
6095 } else { 6102 } else {
6096 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 6103 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
6097 snd_hdspm_hw_rule_rate_out_channels, hdspm, 6104 (playback ?
6105 snd_hdspm_hw_rule_rate_out_channels :
6106 snd_hdspm_hw_rule_rate_in_channels), hdspm,
6098 SNDRV_PCM_HW_PARAM_CHANNELS, -1); 6107 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
6099 } 6108 }
6100 6109
6101 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 6110 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
6102 snd_hdspm_hw_rule_out_channels, hdspm, 6111 (playback ? snd_hdspm_hw_rule_out_channels :
6112 snd_hdspm_hw_rule_in_channels), hdspm,
6103 SNDRV_PCM_HW_PARAM_CHANNELS, -1); 6113 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
6104 6114
6105 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 6115 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
6106 snd_hdspm_hw_rule_out_channels_rate, hdspm, 6116 (playback ? snd_hdspm_hw_rule_out_channels_rate :
6117 snd_hdspm_hw_rule_in_channels_rate), hdspm,
6107 SNDRV_PCM_HW_PARAM_RATE, -1); 6118 SNDRV_PCM_HW_PARAM_RATE, -1);
6108 6119
6109 return 0; 6120 return 0;
6110} 6121}
6111 6122
6112static int snd_hdspm_playback_release(struct snd_pcm_substream *substream) 6123static int snd_hdspm_release(struct snd_pcm_substream *substream)
6113{ 6124{
6114 struct hdspm *hdspm = snd_pcm_substream_chip(substream); 6125 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
6126 bool playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
6115 6127
6116 spin_lock_irq(&hdspm->lock); 6128 spin_lock_irq(&hdspm->lock);
6117 6129
6118 hdspm->playback_pid = -1; 6130 if (playback) {
6119 hdspm->playback_substream = NULL; 6131 hdspm->playback_pid = -1;
6120 6132 hdspm->playback_substream = NULL;
6121 spin_unlock_irq(&hdspm->lock);
6122
6123 return 0;
6124}
6125
6126
6127static int snd_hdspm_capture_open(struct snd_pcm_substream *substream)
6128{
6129 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
6130 struct snd_pcm_runtime *runtime = substream->runtime;
6131
6132 spin_lock_irq(&hdspm->lock);
6133 snd_pcm_set_sync(substream);
6134 runtime->hw = snd_hdspm_capture_subinfo;
6135
6136 if (hdspm->playback_substream == NULL)
6137 hdspm_stop_audio(hdspm);
6138
6139 hdspm->capture_pid = current->pid;
6140 hdspm->capture_substream = substream;
6141
6142 spin_unlock_irq(&hdspm->lock);
6143
6144 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
6145 snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
6146
6147 switch (hdspm->io_type) {
6148 case AIO:
6149 case RayDAT:
6150 snd_pcm_hw_constraint_minmax(runtime,
6151 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
6152 32, 4096);
6153 snd_pcm_hw_constraint_minmax(runtime,
6154 SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
6155 16384, 16384);
6156 break;
6157
6158 default:
6159 snd_pcm_hw_constraint_minmax(runtime,
6160 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
6161 64, 8192);
6162 snd_pcm_hw_constraint_minmax(runtime,
6163 SNDRV_PCM_HW_PARAM_PERIODS,
6164 2, 2);
6165 break;
6166 }
6167
6168 if (AES32 == hdspm->io_type) {
6169 runtime->hw.rates |= SNDRV_PCM_RATE_KNOT;
6170 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
6171 &hdspm_hw_constraints_aes32_sample_rates);
6172 } else { 6133 } else {
6173 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 6134 hdspm->capture_pid = -1;
6174 snd_hdspm_hw_rule_rate_in_channels, hdspm, 6135 hdspm->capture_substream = NULL;
6175 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
6176 } 6136 }
6177 6137
6178 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
6179 snd_hdspm_hw_rule_in_channels, hdspm,
6180 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
6181
6182 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
6183 snd_hdspm_hw_rule_in_channels_rate, hdspm,
6184 SNDRV_PCM_HW_PARAM_RATE, -1);
6185
6186 return 0;
6187}
6188
6189static int snd_hdspm_capture_release(struct snd_pcm_substream *substream)
6190{
6191 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
6192
6193 spin_lock_irq(&hdspm->lock);
6194
6195 hdspm->capture_pid = -1;
6196 hdspm->capture_substream = NULL;
6197
6198 spin_unlock_irq(&hdspm->lock); 6138 spin_unlock_irq(&hdspm->lock);
6139
6199 return 0; 6140 return 0;
6200} 6141}
6201 6142
@@ -6413,21 +6354,9 @@ static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
6413 return 0; 6354 return 0;
6414} 6355}
6415 6356
6416static struct snd_pcm_ops snd_hdspm_playback_ops = { 6357static struct snd_pcm_ops snd_hdspm_ops = {
6417 .open = snd_hdspm_playback_open, 6358 .open = snd_hdspm_open,
6418 .close = snd_hdspm_playback_release, 6359 .close = snd_hdspm_release,
6419 .ioctl = snd_hdspm_ioctl,
6420 .hw_params = snd_hdspm_hw_params,
6421 .hw_free = snd_hdspm_hw_free,
6422 .prepare = snd_hdspm_prepare,
6423 .trigger = snd_hdspm_trigger,
6424 .pointer = snd_hdspm_hw_pointer,
6425 .page = snd_pcm_sgbuf_ops_page,
6426};
6427
6428static struct snd_pcm_ops snd_hdspm_capture_ops = {
6429 .open = snd_hdspm_capture_open,
6430 .close = snd_hdspm_capture_release,
6431 .ioctl = snd_hdspm_ioctl, 6360 .ioctl = snd_hdspm_ioctl,
6432 .hw_params = snd_hdspm_hw_params, 6361 .hw_params = snd_hdspm_hw_params,
6433 .hw_free = snd_hdspm_hw_free, 6362 .hw_free = snd_hdspm_hw_free,
@@ -6521,9 +6450,9 @@ static int snd_hdspm_create_pcm(struct snd_card *card,
6521 strcpy(pcm->name, hdspm->card_name); 6450 strcpy(pcm->name, hdspm->card_name);
6522 6451
6523 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, 6452 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
6524 &snd_hdspm_playback_ops); 6453 &snd_hdspm_ops);
6525 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, 6454 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
6526 &snd_hdspm_capture_ops); 6455 &snd_hdspm_ops);
6527 6456
6528 pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX; 6457 pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX;
6529 6458
diff --git a/sound/pci/via82xx.c b/sound/pci/via82xx.c
index 8622283e89f3..3dd038bdb204 100644
--- a/sound/pci/via82xx.c
+++ b/sound/pci/via82xx.c
@@ -1812,7 +1812,7 @@ static void snd_via82xx_mixer_free_ac97(struct snd_ac97 *ac97)
1812 chip->ac97 = NULL; 1812 chip->ac97 = NULL;
1813} 1813}
1814 1814
1815static struct ac97_quirk ac97_quirks[] = { 1815static const struct ac97_quirk ac97_quirks[] = {
1816 { 1816 {
1817 .subvendor = 0x1106, 1817 .subvendor = 0x1106,
1818 .subdevice = 0x4161, 1818 .subdevice = 0x4161,
diff --git a/sound/ppc/pmac.c b/sound/ppc/pmac.c
index 13146d701413..0095a80a997f 100644
--- a/sound/ppc/pmac.c
+++ b/sound/ppc/pmac.c
@@ -240,7 +240,7 @@ static int snd_pmac_pcm_prepare(struct snd_pmac *chip, struct pmac_stream *rec,
240 */ 240 */
241 spin_lock_irq(&chip->reg_lock); 241 spin_lock_irq(&chip->reg_lock);
242 snd_pmac_dma_stop(rec); 242 snd_pmac_dma_stop(rec);
243 st_le16(&chip->extra_dma.cmds->command, DBDMA_STOP); 243 chip->extra_dma.cmds->command = cpu_to_le16(DBDMA_STOP);
244 snd_pmac_dma_set_command(rec, &chip->extra_dma); 244 snd_pmac_dma_set_command(rec, &chip->extra_dma);
245 snd_pmac_dma_run(rec, RUN); 245 snd_pmac_dma_run(rec, RUN);
246 spin_unlock_irq(&chip->reg_lock); 246 spin_unlock_irq(&chip->reg_lock);
@@ -251,15 +251,15 @@ static int snd_pmac_pcm_prepare(struct snd_pmac *chip, struct pmac_stream *rec,
251 */ 251 */
252 offset = runtime->dma_addr; 252 offset = runtime->dma_addr;
253 for (i = 0, cp = rec->cmd.cmds; i < rec->nperiods; i++, cp++) { 253 for (i = 0, cp = rec->cmd.cmds; i < rec->nperiods; i++, cp++) {
254 st_le32(&cp->phy_addr, offset); 254 cp->phy_addr = cpu_to_le32(offset);
255 st_le16(&cp->req_count, rec->period_size); 255 cp->req_count = cpu_to_le16(rec->period_size);
256 /*st_le16(&cp->res_count, 0);*/ 256 /*cp->res_count = cpu_to_le16(0);*/
257 st_le16(&cp->xfer_status, 0); 257 cp->xfer_status = cpu_to_le16(0);
258 offset += rec->period_size; 258 offset += rec->period_size;
259 } 259 }
260 /* make loop */ 260 /* make loop */
261 st_le16(&cp->command, DBDMA_NOP + BR_ALWAYS); 261 cp->command = cpu_to_le16(DBDMA_NOP + BR_ALWAYS);
262 st_le32(&cp->cmd_dep, rec->cmd.addr); 262 cp->cmd_dep = cpu_to_le32(rec->cmd.addr);
263 263
264 snd_pmac_dma_stop(rec); 264 snd_pmac_dma_stop(rec);
265 snd_pmac_dma_set_command(rec, &rec->cmd); 265 snd_pmac_dma_set_command(rec, &rec->cmd);
@@ -328,7 +328,7 @@ static snd_pcm_uframes_t snd_pmac_pcm_pointer(struct snd_pmac *chip,
328#if 1 /* hmm.. how can we get the current dma pointer?? */ 328#if 1 /* hmm.. how can we get the current dma pointer?? */
329 int stat; 329 int stat;
330 volatile struct dbdma_cmd __iomem *cp = &rec->cmd.cmds[rec->cur_period]; 330 volatile struct dbdma_cmd __iomem *cp = &rec->cmd.cmds[rec->cur_period];
331 stat = ld_le16(&cp->xfer_status); 331 stat = le16_to_cpu(cp->xfer_status);
332 if (stat & (ACTIVE|DEAD)) { 332 if (stat & (ACTIVE|DEAD)) {
333 count = in_le16(&cp->res_count); 333 count = in_le16(&cp->res_count);
334 if (count) 334 if (count)
@@ -427,26 +427,26 @@ static inline void snd_pmac_pcm_dead_xfer(struct pmac_stream *rec,
427 memcpy((void *)emergency_dbdma.cmds, (void *)cp, 427 memcpy((void *)emergency_dbdma.cmds, (void *)cp,
428 sizeof(struct dbdma_cmd)); 428 sizeof(struct dbdma_cmd));
429 emergency_in_use = 1; 429 emergency_in_use = 1;
430 st_le16(&cp->xfer_status, 0); 430 cp->xfer_status = cpu_to_le16(0);
431 st_le16(&cp->req_count, rec->period_size); 431 cp->req_count = cpu_to_le16(rec->period_size);
432 cp = emergency_dbdma.cmds; 432 cp = emergency_dbdma.cmds;
433 } 433 }
434 434
435 /* now bump the values to reflect the amount 435 /* now bump the values to reflect the amount
436 we haven't yet shifted */ 436 we haven't yet shifted */
437 req = ld_le16(&cp->req_count); 437 req = le16_to_cpu(cp->req_count);
438 res = ld_le16(&cp->res_count); 438 res = le16_to_cpu(cp->res_count);
439 phy = ld_le32(&cp->phy_addr); 439 phy = le32_to_cpu(cp->phy_addr);
440 phy += (req - res); 440 phy += (req - res);
441 st_le16(&cp->req_count, res); 441 cp->req_count = cpu_to_le16(res);
442 st_le16(&cp->res_count, 0); 442 cp->res_count = cpu_to_le16(0);
443 st_le16(&cp->xfer_status, 0); 443 cp->xfer_status = cpu_to_le16(0);
444 st_le32(&cp->phy_addr, phy); 444 cp->phy_addr = cpu_to_le32(phy);
445 445
446 st_le32(&cp->cmd_dep, rec->cmd.addr 446 cp->cmd_dep = cpu_to_le32(rec->cmd.addr
447 + sizeof(struct dbdma_cmd)*((rec->cur_period+1)%rec->nperiods)); 447 + sizeof(struct dbdma_cmd)*((rec->cur_period+1)%rec->nperiods));
448 448
449 st_le16(&cp->command, OUTPUT_MORE | BR_ALWAYS | INTR_ALWAYS); 449 cp->command = cpu_to_le16(OUTPUT_MORE | BR_ALWAYS | INTR_ALWAYS);
450 450
451 /* point at our patched up command block */ 451 /* point at our patched up command block */
452 out_le32(&rec->dma->cmdptr, emergency_dbdma.addr); 452 out_le32(&rec->dma->cmdptr, emergency_dbdma.addr);
@@ -475,7 +475,7 @@ static void snd_pmac_pcm_update(struct snd_pmac *chip, struct pmac_stream *rec)
475 else 475 else
476 cp = &rec->cmd.cmds[rec->cur_period]; 476 cp = &rec->cmd.cmds[rec->cur_period];
477 477
478 stat = ld_le16(&cp->xfer_status); 478 stat = le16_to_cpu(cp->xfer_status);
479 479
480 if (stat & DEAD) { 480 if (stat & DEAD) {
481 snd_pmac_pcm_dead_xfer(rec, cp); 481 snd_pmac_pcm_dead_xfer(rec, cp);
@@ -489,9 +489,9 @@ static void snd_pmac_pcm_update(struct snd_pmac *chip, struct pmac_stream *rec)
489 break; 489 break;
490 490
491 /*printk(KERN_DEBUG "update frag %d\n", rec->cur_period);*/ 491 /*printk(KERN_DEBUG "update frag %d\n", rec->cur_period);*/
492 st_le16(&cp->xfer_status, 0); 492 cp->xfer_status = cpu_to_le16(0);
493 st_le16(&cp->req_count, rec->period_size); 493 cp->req_count = cpu_to_le16(rec->period_size);
494 /*st_le16(&cp->res_count, 0);*/ 494 /*cp->res_count = cpu_to_le16(0);*/
495 rec->cur_period++; 495 rec->cur_period++;
496 if (rec->cur_period >= rec->nperiods) { 496 if (rec->cur_period >= rec->nperiods) {
497 rec->cur_period = 0; 497 rec->cur_period = 0;
@@ -760,11 +760,11 @@ void snd_pmac_beep_dma_start(struct snd_pmac *chip, int bytes, unsigned long add
760 struct pmac_stream *rec = &chip->playback; 760 struct pmac_stream *rec = &chip->playback;
761 761
762 snd_pmac_dma_stop(rec); 762 snd_pmac_dma_stop(rec);
763 st_le16(&chip->extra_dma.cmds->req_count, bytes); 763 chip->extra_dma.cmds->req_count = cpu_to_le16(bytes);
764 st_le16(&chip->extra_dma.cmds->xfer_status, 0); 764 chip->extra_dma.cmds->xfer_status = cpu_to_le16(0);
765 st_le32(&chip->extra_dma.cmds->cmd_dep, chip->extra_dma.addr); 765 chip->extra_dma.cmds->cmd_dep = cpu_to_le32(chip->extra_dma.addr);
766 st_le32(&chip->extra_dma.cmds->phy_addr, addr); 766 chip->extra_dma.cmds->phy_addr = cpu_to_le32(addr);
767 st_le16(&chip->extra_dma.cmds->command, OUTPUT_MORE + BR_ALWAYS); 767 chip->extra_dma.cmds->command = cpu_to_le16(OUTPUT_MORE + BR_ALWAYS);
768 out_le32(&chip->awacs->control, 768 out_le32(&chip->awacs->control,
769 (in_le32(&chip->awacs->control) & ~0x1f00) 769 (in_le32(&chip->awacs->control) & ~0x1f00)
770 | (speed << 8)); 770 | (speed << 8));
@@ -776,7 +776,7 @@ void snd_pmac_beep_dma_start(struct snd_pmac *chip, int bytes, unsigned long add
776void snd_pmac_beep_dma_stop(struct snd_pmac *chip) 776void snd_pmac_beep_dma_stop(struct snd_pmac *chip)
777{ 777{
778 snd_pmac_dma_stop(&chip->playback); 778 snd_pmac_dma_stop(&chip->playback);
779 st_le16(&chip->extra_dma.cmds->command, DBDMA_STOP); 779 chip->extra_dma.cmds->command = cpu_to_le16(DBDMA_STOP);
780 snd_pmac_pcm_set_format(chip); /* reset format */ 780 snd_pmac_pcm_set_format(chip); /* reset format */
781} 781}
782 782
diff --git a/sound/soc/codecs/arizona.c b/sound/soc/codecs/arizona.c
index 9015b44a9e11..eff4b4d512b7 100644
--- a/sound/soc/codecs/arizona.c
+++ b/sound/soc/codecs/arizona.c
@@ -19,7 +19,6 @@
19#include <sound/tlv.h> 19#include <sound/tlv.h>
20 20
21#include <linux/mfd/arizona/core.h> 21#include <linux/mfd/arizona/core.h>
22#include <linux/mfd/arizona/gpio.h>
23#include <linux/mfd/arizona/registers.h> 22#include <linux/mfd/arizona/registers.h>
24 23
25#include "arizona.h" 24#include "arizona.h"
@@ -281,6 +280,7 @@ int arizona_init_gpio(struct snd_soc_codec *codec)
281 280
282 switch (arizona->type) { 281 switch (arizona->type) {
283 case WM5110: 282 case WM5110:
283 case WM8280:
284 snd_soc_dapm_disable_pin(&codec->dapm, "DRC2 Signal Activity"); 284 snd_soc_dapm_disable_pin(&codec->dapm, "DRC2 Signal Activity");
285 break; 285 break;
286 default: 286 default:
@@ -840,8 +840,8 @@ int arizona_hp_ev(struct snd_soc_dapm_widget *w,
840 priv->arizona->hp_ena &= ~mask; 840 priv->arizona->hp_ena &= ~mask;
841 priv->arizona->hp_ena |= val; 841 priv->arizona->hp_ena |= val;
842 842
843 /* Force off if HPDET magic is active */ 843 /* Force off if HPDET clamp is active */
844 if (priv->arizona->hpdet_magic) 844 if (priv->arizona->hpdet_clamp)
845 val = 0; 845 val = 0;
846 846
847 regmap_update_bits_async(arizona->regmap, ARIZONA_OUTPUT_ENABLES_1, 847 regmap_update_bits_async(arizona->regmap, ARIZONA_OUTPUT_ENABLES_1,
@@ -1729,6 +1729,7 @@ static int arizona_calc_fratio(struct arizona_fll *fll,
1729 1729
1730 switch (fll->arizona->type) { 1730 switch (fll->arizona->type) {
1731 case WM5110: 1731 case WM5110:
1732 case WM8280:
1732 if (fll->arizona->rev < 3 || sync) 1733 if (fll->arizona->rev < 3 || sync)
1733 return init_ratio; 1734 return init_ratio;
1734 break; 1735 break;
diff --git a/sound/soc/codecs/pcm512x.c b/sound/soc/codecs/pcm512x.c
index 5a30fdd0da00..e12764d15431 100644
--- a/sound/soc/codecs/pcm512x.c
+++ b/sound/soc/codecs/pcm512x.c
@@ -18,6 +18,7 @@
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/clk.h> 20#include <linux/clk.h>
21#include <linux/kernel.h>
21#include <linux/pm_runtime.h> 22#include <linux/pm_runtime.h>
22#include <linux/regmap.h> 23#include <linux/regmap.h>
23#include <linux/regulator/consumer.h> 24#include <linux/regulator/consumer.h>
@@ -31,8 +32,6 @@
31 32
32#define DIV_ROUND_DOWN_ULL(ll, d) \ 33#define DIV_ROUND_DOWN_ULL(ll, d) \
33 ({ unsigned long long _tmp = (ll); do_div(_tmp, d); _tmp; }) 34 ({ unsigned long long _tmp = (ll); do_div(_tmp, d); _tmp; })
34#define DIV_ROUND_CLOSEST_ULL(ll, d) \
35 ({ unsigned long long _tmp = (ll)+(d)/2; do_div(_tmp, d); _tmp; })
36 35
37#define PCM512x_NUM_SUPPLIES 3 36#define PCM512x_NUM_SUPPLIES 3
38static const char * const pcm512x_supply_names[PCM512x_NUM_SUPPLIES] = { 37static const char * const pcm512x_supply_names[PCM512x_NUM_SUPPLIES] = {
diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c
index 69528ae5410c..be4d741c45ba 100644
--- a/sound/soc/codecs/rt5645.c
+++ b/sound/soc/codecs/rt5645.c
@@ -18,6 +18,7 @@
18#include <linux/platform_device.h> 18#include <linux/platform_device.h>
19#include <linux/spi/spi.h> 19#include <linux/spi/spi.h>
20#include <linux/gpio.h> 20#include <linux/gpio.h>
21#include <linux/acpi.h>
21#include <sound/core.h> 22#include <sound/core.h>
22#include <sound/pcm.h> 23#include <sound/pcm.h>
23#include <sound/pcm_params.h> 24#include <sound/pcm_params.h>
@@ -2656,6 +2657,15 @@ static const struct i2c_device_id rt5645_i2c_id[] = {
2656}; 2657};
2657MODULE_DEVICE_TABLE(i2c, rt5645_i2c_id); 2658MODULE_DEVICE_TABLE(i2c, rt5645_i2c_id);
2658 2659
2660#ifdef CONFIG_ACPI
2661static struct acpi_device_id rt5645_acpi_match[] = {
2662 { "10EC5645", 0 },
2663 { "10EC5650", 0 },
2664 {},
2665};
2666MODULE_DEVICE_TABLE(acpi, rt5645_acpi_match);
2667#endif
2668
2659static int rt5645_i2c_probe(struct i2c_client *i2c, 2669static int rt5645_i2c_probe(struct i2c_client *i2c,
2660 const struct i2c_device_id *id) 2670 const struct i2c_device_id *id)
2661{ 2671{
@@ -2770,7 +2780,7 @@ static int rt5645_i2c_probe(struct i2c_client *i2c,
2770 2780
2771 case RT5645_DMIC_DATA_GPIO12: 2781 case RT5645_DMIC_DATA_GPIO12:
2772 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1, 2782 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1,
2773 RT5645_DMIC_1_DP_MASK, RT5645_DMIC_2_DP_GPIO12); 2783 RT5645_DMIC_2_DP_MASK, RT5645_DMIC_2_DP_GPIO12);
2774 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, 2784 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1,
2775 RT5645_GP12_PIN_MASK, 2785 RT5645_GP12_PIN_MASK,
2776 RT5645_GP12_PIN_DMIC2_SDA); 2786 RT5645_GP12_PIN_DMIC2_SDA);
@@ -2872,6 +2882,7 @@ static struct i2c_driver rt5645_i2c_driver = {
2872 .driver = { 2882 .driver = {
2873 .name = "rt5645", 2883 .name = "rt5645",
2874 .owner = THIS_MODULE, 2884 .owner = THIS_MODULE,
2885 .acpi_match_table = ACPI_PTR(rt5645_acpi_match),
2875 }, 2886 },
2876 .probe = rt5645_i2c_probe, 2887 .probe = rt5645_i2c_probe,
2877 .remove = rt5645_i2c_remove, 2888 .remove = rt5645_i2c_remove,
diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
index e8bb8eef1d16..0d48804218b1 100644
--- a/sound/soc/fsl/fsl_ssi.c
+++ b/sound/soc/fsl/fsl_ssi.c
@@ -1357,7 +1357,7 @@ static int fsl_ssi_probe(struct platform_device *pdev)
1357 } 1357 }
1358 1358
1359 ssi_private->irq = platform_get_irq(pdev, 0); 1359 ssi_private->irq = platform_get_irq(pdev, 0);
1360 if (!ssi_private->irq) { 1360 if (ssi_private->irq < 0) {
1361 dev_err(&pdev->dev, "no irq for node %s\n", pdev->name); 1361 dev_err(&pdev->dev, "no irq for node %s\n", pdev->name);
1362 return ssi_private->irq; 1362 return ssi_private->irq;
1363 } 1363 }
diff --git a/sound/soc/intel/Makefile b/sound/soc/intel/Makefile
index cd9aee9871a3..3853ec2ddbc7 100644
--- a/sound/soc/intel/Makefile
+++ b/sound/soc/intel/Makefile
@@ -4,7 +4,7 @@ obj-$(CONFIG_SND_SOC_INTEL_SST) += common/
4# Platform Support 4# Platform Support
5obj-$(CONFIG_SND_SOC_INTEL_HASWELL) += haswell/ 5obj-$(CONFIG_SND_SOC_INTEL_HASWELL) += haswell/
6obj-$(CONFIG_SND_SOC_INTEL_BAYTRAIL) += baytrail/ 6obj-$(CONFIG_SND_SOC_INTEL_BAYTRAIL) += baytrail/
7obj-$(CONFIG_SND_SOC_INTEL_BAYTRAIL) += atom/ 7obj-$(CONFIG_SND_SST_MFLD_PLATFORM) += atom/
8 8
9# Machine support 9# Machine support
10obj-$(CONFIG_SND_SOC_INTEL_SST) += boards/ 10obj-$(CONFIG_SND_SOC_INTEL_SST) += boards/
diff --git a/sound/soc/intel/baytrail/sst-baytrail-ipc.c b/sound/soc/intel/baytrail/sst-baytrail-ipc.c
index 1efb33b36303..a839dbfa5218 100644
--- a/sound/soc/intel/baytrail/sst-baytrail-ipc.c
+++ b/sound/soc/intel/baytrail/sst-baytrail-ipc.c
@@ -759,7 +759,6 @@ fw_err:
759dsp_new_err: 759dsp_new_err:
760 sst_ipc_fini(ipc); 760 sst_ipc_fini(ipc);
761ipc_init_err: 761ipc_init_err:
762 kfree(byt);
763 762
764 return err; 763 return err;
765} 764}
diff --git a/sound/soc/intel/haswell/sst-haswell-ipc.c b/sound/soc/intel/haswell/sst-haswell-ipc.c
index 344a1e9bbce5..324eceb07b25 100644
--- a/sound/soc/intel/haswell/sst-haswell-ipc.c
+++ b/sound/soc/intel/haswell/sst-haswell-ipc.c
@@ -2201,7 +2201,6 @@ dma_err:
2201dsp_new_err: 2201dsp_new_err:
2202 sst_ipc_fini(ipc); 2202 sst_ipc_fini(ipc);
2203ipc_init_err: 2203ipc_init_err:
2204 kfree(hsw);
2205 return ret; 2204 return ret;
2206} 2205}
2207EXPORT_SYMBOL_GPL(sst_hsw_dsp_init); 2206EXPORT_SYMBOL_GPL(sst_hsw_dsp_init);
diff --git a/sound/soc/qcom/lpass-cpu.c b/sound/soc/qcom/lpass-cpu.c
index 6698d058de29..dc790abaa331 100644
--- a/sound/soc/qcom/lpass-cpu.c
+++ b/sound/soc/qcom/lpass-cpu.c
@@ -194,7 +194,7 @@ static int lpass_cpu_daiops_trigger(struct snd_pcm_substream *substream,
194 int cmd, struct snd_soc_dai *dai) 194 int cmd, struct snd_soc_dai *dai)
195{ 195{
196 struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai); 196 struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai);
197 int ret; 197 int ret = -EINVAL;
198 198
199 switch (cmd) { 199 switch (cmd) {
200 case SNDRV_PCM_TRIGGER_START: 200 case SNDRV_PCM_TRIGGER_START:
diff --git a/sound/soc/sh/fsi.c b/sound/soc/sh/fsi.c
index 0c2af21b0b82..142c066eaee2 100644
--- a/sound/soc/sh/fsi.c
+++ b/sound/soc/sh/fsi.c
@@ -250,6 +250,7 @@ struct fsi_clk {
250 250
251struct fsi_priv { 251struct fsi_priv {
252 void __iomem *base; 252 void __iomem *base;
253 phys_addr_t phys;
253 struct fsi_master *master; 254 struct fsi_master *master;
254 255
255 struct fsi_stream playback; 256 struct fsi_stream playback;
@@ -1371,13 +1372,18 @@ static int fsi_dma_probe(struct fsi_priv *fsi, struct fsi_stream *io, struct dev
1371 shdma_chan_filter, (void *)io->dma_id, 1372 shdma_chan_filter, (void *)io->dma_id,
1372 dev, is_play ? "tx" : "rx"); 1373 dev, is_play ? "tx" : "rx");
1373 if (io->chan) { 1374 if (io->chan) {
1374 struct dma_slave_config cfg; 1375 struct dma_slave_config cfg = {};
1375 int ret; 1376 int ret;
1376 1377
1377 cfg.slave_id = io->dma_id; 1378 if (is_play) {
1378 cfg.dst_addr = 0; /* use default addr */ 1379 cfg.dst_addr = fsi->phys + REG_DODT;
1379 cfg.src_addr = 0; /* use default addr */ 1380 cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
1380 cfg.direction = is_play ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM; 1381 cfg.direction = DMA_MEM_TO_DEV;
1382 } else {
1383 cfg.src_addr = fsi->phys + REG_DIDT;
1384 cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
1385 cfg.direction = DMA_DEV_TO_MEM;
1386 }
1381 1387
1382 ret = dmaengine_slave_config(io->chan, &cfg); 1388 ret = dmaengine_slave_config(io->chan, &cfg);
1383 if (ret < 0) { 1389 if (ret < 0) {
@@ -1974,6 +1980,7 @@ static int fsi_probe(struct platform_device *pdev)
1974 /* FSI A setting */ 1980 /* FSI A setting */
1975 fsi = &master->fsia; 1981 fsi = &master->fsia;
1976 fsi->base = master->base; 1982 fsi->base = master->base;
1983 fsi->phys = res->start;
1977 fsi->master = master; 1984 fsi->master = master;
1978 fsi_port_info_init(fsi, &info.port_a); 1985 fsi_port_info_init(fsi, &info.port_a);
1979 fsi_handler_init(fsi, &info.port_a); 1986 fsi_handler_init(fsi, &info.port_a);
@@ -1986,6 +1993,7 @@ static int fsi_probe(struct platform_device *pdev)
1986 /* FSI B setting */ 1993 /* FSI B setting */
1987 fsi = &master->fsib; 1994 fsi = &master->fsib;
1988 fsi->base = master->base + 0x40; 1995 fsi->base = master->base + 0x40;
1996 fsi->phys = res->start + 0x40;
1989 fsi->master = master; 1997 fsi->master = master;
1990 fsi_port_info_init(fsi, &info.port_b); 1998 fsi_port_info_init(fsi, &info.port_b);
1991 fsi_handler_init(fsi, &info.port_b); 1999 fsi_handler_init(fsi, &info.port_b);
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 12b7ff2426da..23732523f87c 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -2792,7 +2792,7 @@ int snd_soc_register_component(struct device *dev,
2792 2792
2793 ret = snd_soc_register_dais(cmpnt, dai_drv, num_dai, true); 2793 ret = snd_soc_register_dais(cmpnt, dai_drv, num_dai, true);
2794 if (ret < 0) { 2794 if (ret < 0) {
2795 dev_err(dev, "ASoC: Failed to regster DAIs: %d\n", ret); 2795 dev_err(dev, "ASoC: Failed to register DAIs: %d\n", ret);
2796 goto err_cleanup; 2796 goto err_cleanup;
2797 } 2797 }
2798 2798
@@ -3113,7 +3113,7 @@ int snd_soc_register_codec(struct device *dev,
3113 3113
3114 ret = snd_soc_register_dais(&codec->component, dai_drv, num_dai, false); 3114 ret = snd_soc_register_dais(&codec->component, dai_drv, num_dai, false);
3115 if (ret < 0) { 3115 if (ret < 0) {
3116 dev_err(dev, "ASoC: Failed to regster DAIs: %d\n", ret); 3116 dev_err(dev, "ASoC: Failed to register DAIs: %d\n", ret);
3117 goto err_cleanup; 3117 goto err_cleanup;
3118 } 3118 }
3119 3119
diff --git a/sound/usb/format.c b/sound/usb/format.c
index 8bcc87cf5667..789d19ec035d 100644
--- a/sound/usb/format.c
+++ b/sound/usb/format.c
@@ -79,7 +79,10 @@ static u64 parse_audio_format_i_type(struct snd_usb_audio *chip,
79 format = 1 << UAC_FORMAT_TYPE_I_PCM; 79 format = 1 << UAC_FORMAT_TYPE_I_PCM;
80 } 80 }
81 if (format & (1 << UAC_FORMAT_TYPE_I_PCM)) { 81 if (format & (1 << UAC_FORMAT_TYPE_I_PCM)) {
82 if (chip->usb_id == USB_ID(0x0582, 0x0016) /* Edirol SD-90 */ && 82 if (((chip->usb_id == USB_ID(0x0582, 0x0016)) ||
83 /* Edirol SD-90 */
84 (chip->usb_id == USB_ID(0x0582, 0x000c))) &&
85 /* Roland SC-D70 */
83 sample_width == 24 && sample_bytes == 2) 86 sample_width == 24 && sample_bytes == 2)
84 sample_bytes = 3; 87 sample_bytes = 3;
85 else if (sample_width > sample_bytes * 8) { 88 else if (sample_width > sample_bytes * 8) {
diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c
index dc9df007d3e3..337c317ead6f 100644
--- a/sound/usb/mixer_quirks.c
+++ b/sound/usb/mixer_quirks.c
@@ -192,6 +192,7 @@ static const struct rc_config {
192 { USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */ 192 { USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */
193 { USB_ID(0x041e, 0x3042), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 */ 193 { USB_ID(0x041e, 0x3042), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 */
194 { USB_ID(0x041e, 0x30df), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */ 194 { USB_ID(0x041e, 0x30df), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
195 { USB_ID(0x041e, 0x3237), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */
195 { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */ 196 { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */
196}; 197};
197 198
diff --git a/sound/usb/quirks-table.h b/sound/usb/quirks-table.h
index 07f984d5f516..2f6d3e9a1bcd 100644
--- a/sound/usb/quirks-table.h
+++ b/sound/usb/quirks-table.h
@@ -816,37 +816,11 @@ YAMAHA_DEVICE(0x7010, "UB99"),
816 .data = (const struct snd_usb_audio_quirk[]) { 816 .data = (const struct snd_usb_audio_quirk[]) {
817 { 817 {
818 .ifnum = 0, 818 .ifnum = 0,
819 .type = QUIRK_AUDIO_FIXED_ENDPOINT, 819 .type = QUIRK_AUDIO_STANDARD_INTERFACE
820 .data = & (const struct audioformat) {
821 .formats = SNDRV_PCM_FMTBIT_S24_3LE,
822 .channels = 2,
823 .iface = 0,
824 .altsetting = 1,
825 .altset_idx = 1,
826 .attributes = 0,
827 .endpoint = 0x01,
828 .ep_attr = 0x01,
829 .rates = SNDRV_PCM_RATE_CONTINUOUS,
830 .rate_min = 44100,
831 .rate_max = 44100,
832 }
833 }, 820 },
834 { 821 {
835 .ifnum = 1, 822 .ifnum = 1,
836 .type = QUIRK_AUDIO_FIXED_ENDPOINT, 823 .type = QUIRK_AUDIO_STANDARD_INTERFACE
837 .data = & (const struct audioformat) {
838 .formats = SNDRV_PCM_FMTBIT_S24_3LE,
839 .channels = 2,
840 .iface = 1,
841 .altsetting = 1,
842 .altset_idx = 1,
843 .attributes = 0,
844 .endpoint = 0x81,
845 .ep_attr = 0x01,
846 .rates = SNDRV_PCM_RATE_CONTINUOUS,
847 .rate_min = 44100,
848 .rate_max = 44100,
849 }
850 }, 824 },
851 { 825 {
852 .ifnum = 2, 826 .ifnum = 2,
diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c
index 753a47de8459..7c5a70139278 100644
--- a/sound/usb/quirks.c
+++ b/sound/usb/quirks.c
@@ -1113,24 +1113,37 @@ void snd_usb_set_format_quirk(struct snd_usb_substream *subs,
1113 1113
1114bool snd_usb_get_sample_rate_quirk(struct snd_usb_audio *chip) 1114bool snd_usb_get_sample_rate_quirk(struct snd_usb_audio *chip)
1115{ 1115{
1116 /* MS Lifecam HD-5000 doesn't support reading the sample rate. */ 1116 /* devices which do not support reading the sample rate. */
1117 return chip->usb_id == USB_ID(0x045E, 0x076D); 1117 switch (chip->usb_id) {
1118 case USB_ID(0x045E, 0x075D): /* MS Lifecam Cinema */
1119 case USB_ID(0x045E, 0x076D): /* MS Lifecam HD-5000 */
1120 case USB_ID(0x04D8, 0xFEEA): /* Benchmark DAC1 Pre */
1121 return true;
1122 }
1123 return false;
1118} 1124}
1119 1125
1120/* Marantz/Denon USB DACs need a vendor cmd to switch 1126/* Marantz/Denon USB DACs need a vendor cmd to switch
1121 * between PCM and native DSD mode 1127 * between PCM and native DSD mode
1122 */ 1128 */
1129static bool is_marantz_denon_dac(unsigned int id)
1130{
1131 switch (id) {
1132 case USB_ID(0x154e, 0x1003): /* Denon DA-300USB */
1133 case USB_ID(0x154e, 0x3005): /* Marantz HD-DAC1 */
1134 case USB_ID(0x154e, 0x3006): /* Marantz SA-14S1 */
1135 return true;
1136 }
1137 return false;
1138}
1139
1123int snd_usb_select_mode_quirk(struct snd_usb_substream *subs, 1140int snd_usb_select_mode_quirk(struct snd_usb_substream *subs,
1124 struct audioformat *fmt) 1141 struct audioformat *fmt)
1125{ 1142{
1126 struct usb_device *dev = subs->dev; 1143 struct usb_device *dev = subs->dev;
1127 int err; 1144 int err;
1128 1145
1129 switch (subs->stream->chip->usb_id) { 1146 if (is_marantz_denon_dac(subs->stream->chip->usb_id)) {
1130 case USB_ID(0x154e, 0x1003): /* Denon DA-300USB */
1131 case USB_ID(0x154e, 0x3005): /* Marantz HD-DAC1 */
1132 case USB_ID(0x154e, 0x3006): /* Marantz SA-14S1 */
1133
1134 /* First switch to alt set 0, otherwise the mode switch cmd 1147 /* First switch to alt set 0, otherwise the mode switch cmd
1135 * will not be accepted by the DAC 1148 * will not be accepted by the DAC
1136 */ 1149 */
@@ -1203,17 +1216,10 @@ void snd_usb_ctl_msg_quirk(struct usb_device *dev, unsigned int pipe,
1203 /* Marantz/Denon devices with USB DAC functionality need a delay 1216 /* Marantz/Denon devices with USB DAC functionality need a delay
1204 * after each class compliant request 1217 * after each class compliant request
1205 */ 1218 */
1206 if ((le16_to_cpu(dev->descriptor.idVendor) == 0x154e) && 1219 if (is_marantz_denon_dac(USB_ID(le16_to_cpu(dev->descriptor.idVendor),
1207 (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS) { 1220 le16_to_cpu(dev->descriptor.idProduct)))
1208 1221 && (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
1209 switch (le16_to_cpu(dev->descriptor.idProduct)) { 1222 mdelay(20);
1210 case 0x1003: /* Denon DA300-USB */
1211 case 0x3005: /* Marantz HD-DAC1 */
1212 case 0x3006: /* Marantz SA-14S1 */
1213 mdelay(20);
1214 break;
1215 }
1216 }
1217 1223
1218 /* Zoom R16/24 needs a tiny delay here, otherwise requests like 1224 /* Zoom R16/24 needs a tiny delay here, otherwise requests like
1219 * get/set frequency return as failed despite actually succeeding. 1225 * get/set frequency return as failed despite actually succeeding.
@@ -1268,15 +1274,9 @@ u64 snd_usb_interface_dsd_format_quirks(struct snd_usb_audio *chip,
1268 } 1274 }
1269 1275
1270 /* Denon/Marantz devices with USB DAC functionality */ 1276 /* Denon/Marantz devices with USB DAC functionality */
1271 switch (chip->usb_id) { 1277 if (is_marantz_denon_dac(chip->usb_id)) {
1272 case USB_ID(0x154e, 0x1003): /* Denon DA300-USB */
1273 case USB_ID(0x154e, 0x3005): /* Marantz HD-DAC1 */
1274 case USB_ID(0x154e, 0x3006): /* Marantz SA-14S1 */
1275 if (fp->altsetting == 2) 1278 if (fp->altsetting == 2)
1276 return SNDRV_PCM_FMTBIT_DSD_U32_BE; 1279 return SNDRV_PCM_FMTBIT_DSD_U32_BE;
1277 break;
1278 default:
1279 break;
1280 } 1280 }
1281 1281
1282 return 0; 1282 return 0;