From 056622053b8ae02978678ac1321b5bd956e7c812 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 12 Feb 2015 13:43:22 +0100 Subject: ALSA: seq: Define driver object in each driver This patch moves the driver object initialization and allocation to each driver's module init/exit code like other normal drivers. The snd_seq_driver struct is now published in seq_device.h, and each driver is responsible to define it with proper driver attributes (name, probe and remove) with snd_seq_driver specific attributes as id and argsize fields. The helper functions snd_seq_driver_register(), snd_seq_driver_unregister() and module_snd_seq_driver() are used for simplifying codes. Signed-off-by: Takashi Iwai --- sound/pci/emu10k1/emu10k1_synth.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) (limited to 'sound/pci') 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"); /* * create a new hardware dependent device for Emu10k1 */ -static int snd_emu10k1_synth_new_device(struct snd_seq_device *dev) +static int snd_emu10k1_synth_probe(struct device *_dev) { + struct snd_seq_device *dev = to_seq_dev(_dev); struct snd_emux *emux; struct snd_emu10k1 *hw; struct snd_emu10k1_synth_arg *arg; @@ -79,8 +80,9 @@ static int snd_emu10k1_synth_new_device(struct snd_seq_device *dev) return 0; } -static int snd_emu10k1_synth_delete_device(struct snd_seq_device *dev) +static int snd_emu10k1_synth_remove(struct device *_dev) { + struct snd_seq_device *dev = to_seq_dev(_dev); struct snd_emux *emux; struct snd_emu10k1 *hw; unsigned long flags; @@ -104,21 +106,14 @@ static int snd_emu10k1_synth_delete_device(struct snd_seq_device *dev) * INIT part */ -static int __init alsa_emu10k1_synth_init(void) -{ - - static struct snd_seq_dev_ops ops = { - snd_emu10k1_synth_new_device, - snd_emu10k1_synth_delete_device, - }; - return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops, - sizeof(struct snd_emu10k1_synth_arg)); -} - -static void __exit alsa_emu10k1_synth_exit(void) -{ - snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH); -} - -module_init(alsa_emu10k1_synth_init) -module_exit(alsa_emu10k1_synth_exit) +static struct snd_seq_driver emu10k1_synth_driver = { + .driver = { + .name = KBUILD_MODNAME, + .probe = snd_emu10k1_synth_probe, + .remove = snd_emu10k1_synth_remove, + }, + .id = SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, + .argsize = sizeof(struct snd_emu10k1_synth_arg), +}; + +module_snd_seq_driver(emu10k1_synth_driver); -- cgit v1.2.3 From 5ecc5dc720307d3fb0167e2b14f50e97dd9a2233 Mon Sep 17 00:00:00 2001 From: Adrian Knoth Date: Tue, 17 Feb 2015 00:05:04 +0100 Subject: ALSA: hdspm - DRY cleanup in .open callbacks This commit removes code duplication between snd_hdspm_{capture,playback}_open. No semantic changes intended, this is purely cosmetic. Signed-off-by: Adrian Knoth Signed-off-by: Takashi Iwai --- sound/pci/rme9652/hdspm.c | 100 +++++++++++----------------------------------- 1 file changed, 24 insertions(+), 76 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c index ca67f896d117..51e984170b3d 100644 --- a/sound/pci/rme9652/hdspm.c +++ b/sound/pci/rme9652/hdspm.c @@ -6043,23 +6043,30 @@ hdspm_hw_constraints_aes32_sample_rates = { .mask = 0 }; -static int snd_hdspm_playback_open(struct snd_pcm_substream *substream) +static int snd_hdspm_open(struct snd_pcm_substream *substream) { struct hdspm *hdspm = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; + bool playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK); spin_lock_irq(&hdspm->lock); - snd_pcm_set_sync(substream); + runtime->hw = (playback) ? snd_hdspm_playback_subinfo : + snd_hdspm_capture_subinfo; + if (playback) { + if (hdspm->capture_substream == NULL) + hdspm_stop_audio(hdspm); - runtime->hw = snd_hdspm_playback_subinfo; - - if (hdspm->capture_substream == NULL) - hdspm_stop_audio(hdspm); + hdspm->playback_pid = current->pid; + hdspm->playback_substream = substream; + } else { + if (hdspm->playback_substream == NULL) + hdspm_stop_audio(hdspm); - hdspm->playback_pid = current->pid; - hdspm->playback_substream = substream; + hdspm->capture_pid = current->pid; + hdspm->capture_substream = substream; + } spin_unlock_irq(&hdspm->lock); @@ -6094,16 +6101,20 @@ static int snd_hdspm_playback_open(struct snd_pcm_substream *substream) &hdspm_hw_constraints_aes32_sample_rates); } else { snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, - snd_hdspm_hw_rule_rate_out_channels, hdspm, + (playback ? + snd_hdspm_hw_rule_rate_out_channels : + snd_hdspm_hw_rule_rate_in_channels), hdspm, SNDRV_PCM_HW_PARAM_CHANNELS, -1); } snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, - snd_hdspm_hw_rule_out_channels, hdspm, + (playback ? snd_hdspm_hw_rule_out_channels : + snd_hdspm_hw_rule_in_channels), hdspm, SNDRV_PCM_HW_PARAM_CHANNELS, -1); snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, - snd_hdspm_hw_rule_out_channels_rate, hdspm, + (playback ? snd_hdspm_hw_rule_out_channels_rate : + snd_hdspm_hw_rule_in_channels_rate), hdspm, SNDRV_PCM_HW_PARAM_RATE, -1); return 0; @@ -6123,69 +6134,6 @@ static int snd_hdspm_playback_release(struct snd_pcm_substream *substream) return 0; } - -static int snd_hdspm_capture_open(struct snd_pcm_substream *substream) -{ - struct hdspm *hdspm = snd_pcm_substream_chip(substream); - struct snd_pcm_runtime *runtime = substream->runtime; - - spin_lock_irq(&hdspm->lock); - snd_pcm_set_sync(substream); - runtime->hw = snd_hdspm_capture_subinfo; - - if (hdspm->playback_substream == NULL) - hdspm_stop_audio(hdspm); - - hdspm->capture_pid = current->pid; - hdspm->capture_substream = substream; - - spin_unlock_irq(&hdspm->lock); - - snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); - snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE); - - switch (hdspm->io_type) { - case AIO: - case RayDAT: - snd_pcm_hw_constraint_minmax(runtime, - SNDRV_PCM_HW_PARAM_PERIOD_SIZE, - 32, 4096); - snd_pcm_hw_constraint_minmax(runtime, - SNDRV_PCM_HW_PARAM_BUFFER_SIZE, - 16384, 16384); - break; - - default: - snd_pcm_hw_constraint_minmax(runtime, - SNDRV_PCM_HW_PARAM_PERIOD_SIZE, - 64, 8192); - snd_pcm_hw_constraint_minmax(runtime, - SNDRV_PCM_HW_PARAM_PERIODS, - 2, 2); - break; - } - - if (AES32 == hdspm->io_type) { - runtime->hw.rates |= SNDRV_PCM_RATE_KNOT; - snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, - &hdspm_hw_constraints_aes32_sample_rates); - } else { - snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, - snd_hdspm_hw_rule_rate_in_channels, hdspm, - SNDRV_PCM_HW_PARAM_CHANNELS, -1); - } - - snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, - snd_hdspm_hw_rule_in_channels, hdspm, - SNDRV_PCM_HW_PARAM_CHANNELS, -1); - - snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, - snd_hdspm_hw_rule_in_channels_rate, hdspm, - SNDRV_PCM_HW_PARAM_RATE, -1); - - return 0; -} - static int snd_hdspm_capture_release(struct snd_pcm_substream *substream) { struct hdspm *hdspm = snd_pcm_substream_chip(substream); @@ -6414,7 +6362,7 @@ static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, } static struct snd_pcm_ops snd_hdspm_playback_ops = { - .open = snd_hdspm_playback_open, + .open = snd_hdspm_open, .close = snd_hdspm_playback_release, .ioctl = snd_hdspm_ioctl, .hw_params = snd_hdspm_hw_params, @@ -6426,7 +6374,7 @@ static struct snd_pcm_ops snd_hdspm_playback_ops = { }; static struct snd_pcm_ops snd_hdspm_capture_ops = { - .open = snd_hdspm_capture_open, + .open = snd_hdspm_open, .close = snd_hdspm_capture_release, .ioctl = snd_hdspm_ioctl, .hw_params = snd_hdspm_hw_params, -- cgit v1.2.3 From 8b73b867294364ae3007affdf8cfd28f022b158c Mon Sep 17 00:00:00 2001 From: Adrian Knoth Date: Tue, 17 Feb 2015 00:05:05 +0100 Subject: ALSA: hdspm - DRY cleanup in .release callback This commit removes code duplication between snd_hdspm_{capture,playback}_release. No semantic changes intended, this is purely cosmetic. Signed-off-by: Adrian Knoth Signed-off-by: Takashi Iwai --- sound/pci/rme9652/hdspm.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c index 51e984170b3d..4e1cfb91a8d8 100644 --- a/sound/pci/rme9652/hdspm.c +++ b/sound/pci/rme9652/hdspm.c @@ -6120,33 +6120,26 @@ static int snd_hdspm_open(struct snd_pcm_substream *substream) return 0; } -static int snd_hdspm_playback_release(struct snd_pcm_substream *substream) +static int snd_hdspm_release(struct snd_pcm_substream *substream) { struct hdspm *hdspm = snd_pcm_substream_chip(substream); + bool playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK); spin_lock_irq(&hdspm->lock); - hdspm->playback_pid = -1; - hdspm->playback_substream = NULL; + if (playback) { + hdspm->playback_pid = -1; + hdspm->playback_substream = NULL; + } else { + hdspm->capture_pid = -1; + hdspm->capture_substream = NULL; + } spin_unlock_irq(&hdspm->lock); return 0; } -static int snd_hdspm_capture_release(struct snd_pcm_substream *substream) -{ - struct hdspm *hdspm = snd_pcm_substream_chip(substream); - - spin_lock_irq(&hdspm->lock); - - hdspm->capture_pid = -1; - hdspm->capture_substream = NULL; - - spin_unlock_irq(&hdspm->lock); - return 0; -} - static int snd_hdspm_hwdep_dummy_op(struct snd_hwdep *hw, struct file *file) { /* we have nothing to initialize but the call is required */ @@ -6363,7 +6356,7 @@ static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, static struct snd_pcm_ops snd_hdspm_playback_ops = { .open = snd_hdspm_open, - .close = snd_hdspm_playback_release, + .close = snd_hdspm_release, .ioctl = snd_hdspm_ioctl, .hw_params = snd_hdspm_hw_params, .hw_free = snd_hdspm_hw_free, @@ -6375,7 +6368,7 @@ static struct snd_pcm_ops snd_hdspm_playback_ops = { static struct snd_pcm_ops snd_hdspm_capture_ops = { .open = snd_hdspm_open, - .close = snd_hdspm_capture_release, + .close = snd_hdspm_release, .ioctl = snd_hdspm_ioctl, .hw_params = snd_hdspm_hw_params, .hw_free = snd_hdspm_hw_free, -- cgit v1.2.3 From 0c8d948565490d2a2db9d9a5aec388342c7d38ce Mon Sep 17 00:00:00 2001 From: Adrian Knoth Date: Tue, 17 Feb 2015 00:05:06 +0100 Subject: ALSA: hdspm - DRY cleanup of snd_pcm_ops This commit removes code duplication between snd_hdspm_{capture,playback}_ops. No semantic changes intended, this is purely cosmetic. Signed-off-by: Adrian Knoth Signed-off-by: Takashi Iwai --- sound/pci/rme9652/hdspm.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c index 4e1cfb91a8d8..cb666c73712d 100644 --- a/sound/pci/rme9652/hdspm.c +++ b/sound/pci/rme9652/hdspm.c @@ -6354,19 +6354,7 @@ static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, return 0; } -static struct snd_pcm_ops snd_hdspm_playback_ops = { - .open = snd_hdspm_open, - .close = snd_hdspm_release, - .ioctl = snd_hdspm_ioctl, - .hw_params = snd_hdspm_hw_params, - .hw_free = snd_hdspm_hw_free, - .prepare = snd_hdspm_prepare, - .trigger = snd_hdspm_trigger, - .pointer = snd_hdspm_hw_pointer, - .page = snd_pcm_sgbuf_ops_page, -}; - -static struct snd_pcm_ops snd_hdspm_capture_ops = { +static struct snd_pcm_ops snd_hdspm_ops = { .open = snd_hdspm_open, .close = snd_hdspm_release, .ioctl = snd_hdspm_ioctl, @@ -6462,9 +6450,9 @@ static int snd_hdspm_create_pcm(struct snd_card *card, strcpy(pcm->name, hdspm->card_name); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, - &snd_hdspm_playback_ops); + &snd_hdspm_ops); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, - &snd_hdspm_capture_ops); + &snd_hdspm_ops); pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX; -- cgit v1.2.3 From ef7449780ebb596b47d5019eb7ba7878c30a3404 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 17 Feb 2015 13:56:29 +0100 Subject: ALSA: hda - Drop hda_bus_template for snd_hda_bus_new() Instead of copying from the given template, let the caller fills the fields after creation. This simplifies the code after all. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_codec.c | 15 +----------- sound/pci/hda/hda_codec.h | 13 +--------- sound/pci/hda/hda_controller.c | 54 +++++++++++++++++++++++------------------- 3 files changed, 32 insertions(+), 50 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 2fe86d2e1b09..215bf048c668 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -861,14 +861,12 @@ static int snd_hda_bus_dev_disconnect(struct snd_device *device) /** * snd_hda_bus_new - create a HDA bus * @card: the card entry - * @temp: the template for hda_bus information * @busp: the pointer to store the created bus instance * * Returns 0 if successful, or a negative error code. */ int snd_hda_bus_new(struct snd_card *card, - const struct hda_bus_template *temp, - struct hda_bus **busp) + struct hda_bus **busp) { struct hda_bus *bus; int err; @@ -877,11 +875,6 @@ int snd_hda_bus_new(struct snd_card *card, .dev_free = snd_hda_bus_dev_free, }; - if (snd_BUG_ON(!temp)) - return -EINVAL; - if (snd_BUG_ON(!temp->ops.command || !temp->ops.get_response)) - return -EINVAL; - if (busp) *busp = NULL; @@ -892,12 +885,6 @@ int snd_hda_bus_new(struct snd_card *card, } bus->card = card; - bus->private_data = temp->private_data; - bus->pci = temp->pci; - bus->modelname = temp->modelname; - bus->power_save = temp->power_save; - bus->ops = temp->ops; - mutex_init(&bus->cmd_mutex); mutex_init(&bus->prepare_mutex); INIT_LIST_HEAD(&bus->codec_list); diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index 9c8820f21f94..5a6594884069 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h @@ -101,15 +101,6 @@ struct hda_bus_ops { #endif }; -/* template to pass to the bus constructor */ -struct hda_bus_template { - void *private_data; - struct pci_dev *pci; - const char *modelname; - int *power_save; - struct hda_bus_ops ops; -}; - /* * codec bus * @@ -119,7 +110,6 @@ struct hda_bus_template { struct hda_bus { struct snd_card *card; - /* copied from template */ void *private_data; struct pci_dev *pci; const char *modelname; @@ -420,8 +410,7 @@ enum { /* * constructors */ -int snd_hda_bus_new(struct snd_card *card, const struct hda_bus_template *temp, - struct hda_bus **busp); +int snd_hda_bus_new(struct snd_card *card, struct hda_bus **busp); int snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr, struct hda_codec **codecp); int snd_hda_codec_configure(struct hda_codec *codec); diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c index dfcb5e929f9f..31ff8b55f386 100644 --- a/sound/pci/hda/hda_controller.c +++ b/sound/pci/hda/hda_controller.c @@ -1815,39 +1815,45 @@ static int get_jackpoll_interval(struct azx *chip) return j; } +static struct hda_bus_ops bus_ops = { + .command = azx_send_cmd, + .get_response = azx_get_response, + .attach_pcm = azx_attach_pcm_stream, + .bus_reset = azx_bus_reset, +#ifdef CONFIG_PM + .pm_notify = azx_power_notify, +#endif +#ifdef CONFIG_SND_HDA_DSP_LOADER + .load_dsp_prepare = azx_load_dsp_prepare, + .load_dsp_trigger = azx_load_dsp_trigger, + .load_dsp_cleanup = azx_load_dsp_cleanup, +#endif +}; + /* Codec initialization */ int azx_codec_create(struct azx *chip, const char *model, unsigned int max_slots, int *power_save_to) { - struct hda_bus_template bus_temp; + struct hda_bus *bus; int c, codecs, err; - memset(&bus_temp, 0, sizeof(bus_temp)); - bus_temp.private_data = chip; - bus_temp.modelname = model; - bus_temp.pci = chip->pci; - bus_temp.ops.command = azx_send_cmd; - bus_temp.ops.get_response = azx_get_response; - bus_temp.ops.attach_pcm = azx_attach_pcm_stream; - bus_temp.ops.bus_reset = azx_bus_reset; -#ifdef CONFIG_PM - bus_temp.power_save = power_save_to; - bus_temp.ops.pm_notify = azx_power_notify; -#endif -#ifdef CONFIG_SND_HDA_DSP_LOADER - bus_temp.ops.load_dsp_prepare = azx_load_dsp_prepare; - bus_temp.ops.load_dsp_trigger = azx_load_dsp_trigger; - bus_temp.ops.load_dsp_cleanup = azx_load_dsp_cleanup; -#endif - - err = snd_hda_bus_new(chip->card, &bus_temp, &chip->bus); + err = snd_hda_bus_new(chip->card, &bus); if (err < 0) return err; + chip->bus = bus; + bus->private_data = chip; + bus->pci = chip->pci; + bus->modelname = model; + bus->ops = bus_ops; +#ifdef CONFIG_PM + bus->power_save = power_save_to; +#endif + if (chip->driver_caps & AZX_DCAPS_RIRB_DELAY) { dev_dbg(chip->card->dev, "Enable delay in RIRB handling\n"); - chip->bus->needs_damn_long_delay = 1; + bus->needs_damn_long_delay = 1; } codecs = 0; @@ -1883,15 +1889,15 @@ int azx_codec_create(struct azx *chip, const char *model, */ if (chip->driver_caps & AZX_DCAPS_SYNC_WRITE) { dev_dbg(chip->card->dev, "Enable sync_write for stable communication\n"); - chip->bus->sync_write = 1; - chip->bus->allow_bus_reset = 1; + bus->sync_write = 1; + bus->allow_bus_reset = 1; } /* Then create codec instances */ for (c = 0; c < max_slots; c++) { if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) { struct hda_codec *codec; - err = snd_hda_codec_new(chip->bus, c, &codec); + err = snd_hda_codec_new(bus, c, &codec); if (err < 0) continue; codec->jackpoll_interval = get_jackpoll_interval(chip); -- cgit v1.2.3 From 922c88a8368a61ee93653d4a2888a7f4ce263102 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 17 Feb 2015 14:46:40 +0100 Subject: ALSA: hda - Embed struct hda_bus_unsolicited into struct hda_bus There is no big merit to handle hda_bus_unsolicited object individually, as it's tightly coupled with the hda_bus object itself. Embedding it makes the code simpler in the end. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_codec.c | 39 ++++----------------------------------- sound/pci/hda/hda_codec.h | 13 +++++++++++-- sound/pci/hda/hda_local.h | 17 ----------------- 3 files changed, 15 insertions(+), 54 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 215bf048c668..0734cb35887d 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -762,10 +762,7 @@ int snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex) return 0; trace_hda_unsol_event(bus, res, res_ex); - unsol = bus->unsol; - if (!unsol) - return 0; - + unsol = &bus->unsol; wp = (unsol->wp + 1) % HDA_UNSOL_QUEUE_SIZE; unsol->wp = wp; @@ -784,9 +781,8 @@ EXPORT_SYMBOL_GPL(snd_hda_queue_unsol_event); */ static void process_unsol_events(struct work_struct *work) { - struct hda_bus_unsolicited *unsol = - container_of(work, struct hda_bus_unsolicited, work); - struct hda_bus *bus = unsol->bus; + struct hda_bus *bus = container_of(work, struct hda_bus, unsol.work); + struct hda_bus_unsolicited *unsol = &bus->unsol; struct hda_codec *codec; unsigned int rp, caddr, res; @@ -804,27 +800,6 @@ static void process_unsol_events(struct work_struct *work) } } -/* - * initialize unsolicited queue - */ -static int init_unsol_queue(struct hda_bus *bus) -{ - struct hda_bus_unsolicited *unsol; - - if (bus->unsol) /* already initialized */ - return 0; - - unsol = kzalloc(sizeof(*unsol), GFP_KERNEL); - if (!unsol) { - dev_err(bus->card->dev, "can't allocate unsolicited queue\n"); - return -ENOMEM; - } - INIT_WORK(&unsol->work, process_unsol_events); - unsol->bus = bus; - bus->unsol = unsol; - return 0; -} - /* * destructor */ @@ -836,7 +811,6 @@ static void snd_hda_bus_free(struct hda_bus *bus) WARN_ON(!list_empty(&bus->codec_list)); if (bus->workq) flush_workqueue(bus->workq); - kfree(bus->unsol); if (bus->ops.private_free) bus->ops.private_free(bus); if (bus->workq) @@ -888,6 +862,7 @@ int snd_hda_bus_new(struct snd_card *card, mutex_init(&bus->cmd_mutex); mutex_init(&bus->prepare_mutex); INIT_LIST_HEAD(&bus->codec_list); + INIT_WORK(&bus->unsol.work, process_unsol_events); snprintf(bus->workq_name, sizeof(bus->workq_name), "hd-audio%d", card->number); @@ -1689,12 +1664,6 @@ int snd_hda_codec_configure(struct hda_codec *codec) return err; } - if (codec->patch_ops.unsol_event) { - err = init_unsol_queue(codec->bus); - if (err < 0) - return err; - } - /* audio codec should override the mixer name */ if (codec->afg || !*codec->bus->card->mixername) snprintf(codec->bus->card->mixername, diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index 5a6594884069..96421a3b32cd 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h @@ -66,7 +66,6 @@ struct hda_beep; struct hda_codec; struct hda_pcm; struct hda_pcm_stream; -struct hda_bus_unsolicited; /* NID type */ typedef u16 hda_nid_t; @@ -101,6 +100,16 @@ struct hda_bus_ops { #endif }; +/* unsolicited event handler */ +#define HDA_UNSOL_QUEUE_SIZE 64 +struct hda_bus_unsolicited { + /* ring buffer */ + u32 queue[HDA_UNSOL_QUEUE_SIZE * 2]; + unsigned int rp, wp; + /* workqueue */ + struct work_struct work; +}; + /* * codec bus * @@ -126,7 +135,7 @@ struct hda_bus { struct mutex prepare_mutex; /* unsolicited event queue */ - struct hda_bus_unsolicited *unsol; + struct hda_bus_unsolicited unsol; char workq_name[16]; struct workqueue_struct *workq; /* common workqueue for codecs */ diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h index 62658f2f8c9f..49c08a7278c4 100644 --- a/sound/pci/hda/hda_local.h +++ b/sound/pci/hda/hda_local.h @@ -466,23 +466,6 @@ void snd_hda_pick_pin_fixup(struct hda_codec *codec, const struct snd_hda_pin_quirk *pin_quirk, const struct hda_fixup *fixlist); - -/* - * unsolicited event handler - */ - -#define HDA_UNSOL_QUEUE_SIZE 64 - -struct hda_bus_unsolicited { - /* ring buffer */ - u32 queue[HDA_UNSOL_QUEUE_SIZE * 2]; - unsigned int rp, wp; - - /* workqueue */ - struct work_struct work; - struct hda_bus *bus; -}; - /* helper macros to retrieve pin default-config values */ #define get_defcfg_connect(cfg) \ ((cfg & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT) -- cgit v1.2.3 From 364aa716f43c991052cbb4fa05e3754bacccb95c Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 19 Feb 2015 16:51:17 +0100 Subject: ALSA: hda - Introduce azx_has_pm_runtime() macro For making the debugging of runtime PM easier, introduce azx_has_pm_runtime() and use it in all places checking the runtime pm driver capability. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_controller.c | 4 ++-- sound/pci/hda/hda_intel.c | 12 +++++------- sound/pci/hda/hda_priv.h | 3 +++ 3 files changed, 10 insertions(+), 9 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c index 31ff8b55f386..3589fc2165b0 100644 --- a/sound/pci/hda/hda_controller.c +++ b/sound/pci/hda/hda_controller.c @@ -1681,7 +1681,7 @@ irqreturn_t azx_interrupt(int irq, void *dev_id) int i; #ifdef CONFIG_PM - if (chip->driver_caps & AZX_DCAPS_PM_RUNTIME) + if (azx_has_pm_runtime(chip)) if (!pm_runtime_active(chip->card->dev)) return IRQ_NONE; #endif @@ -1784,7 +1784,7 @@ static void azx_power_notify(struct hda_bus *bus, bool power_up) { struct azx *chip = bus->private_data; - if (!(chip->driver_caps & AZX_DCAPS_PM_RUNTIME)) + if (!azx_has_pm_runtime(chip)) return; if (power_up) diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index 36d2f20db7a4..589883291f4e 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c @@ -852,7 +852,7 @@ static int azx_runtime_suspend(struct device *dev) if (chip->disabled || hda->init_failed) return 0; - if (!(chip->driver_caps & AZX_DCAPS_PM_RUNTIME)) + if (!azx_has_pm_runtime(chip)) return 0; /* enable controller wake up event */ @@ -885,7 +885,7 @@ static int azx_runtime_resume(struct device *dev) if (chip->disabled || hda->init_failed) return 0; - if (!(chip->driver_caps & AZX_DCAPS_PM_RUNTIME)) + if (!azx_has_pm_runtime(chip)) return 0; if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) { @@ -928,8 +928,7 @@ static int azx_runtime_idle(struct device *dev) if (chip->disabled || hda->init_failed) return 0; - if (!power_save_controller || - !(chip->driver_caps & AZX_DCAPS_PM_RUNTIME)) + if (!power_save_controller || !azx_has_pm_runtime(chip)) return -EBUSY; return 0; @@ -1071,8 +1070,7 @@ static int azx_free(struct azx *chip) struct hda_intel *hda = container_of(chip, struct hda_intel, chip); int i; - if ((chip->driver_caps & AZX_DCAPS_PM_RUNTIME) - && chip->running) + if (azx_has_pm_runtime(chip) && chip->running) pm_runtime_get_noresume(&pci->dev); azx_del_card_list(chip); @@ -1938,7 +1936,7 @@ static int azx_probe_continue(struct azx *chip) power_down_all_codecs(chip); azx_notifier_register(chip); azx_add_card_list(chip); - if ((chip->driver_caps & AZX_DCAPS_PM_RUNTIME) || hda->use_vga_switcheroo) + if (azx_has_pm_runtime(chip) || hda->use_vga_switcheroo) pm_runtime_put_noidle(&pci->dev); out_free: diff --git a/sound/pci/hda/hda_priv.h b/sound/pci/hda/hda_priv.h index daf458299753..a7b4a25c571c 100644 --- a/sound/pci/hda/hda_priv.h +++ b/sound/pci/hda/hda_priv.h @@ -403,4 +403,7 @@ struct azx { #define azx_sd_readb(chip, dev, reg) \ ((chip)->ops->reg_readb((dev)->sd_addr + AZX_REG_##reg)) +#define azx_has_pm_runtime(chip) \ + (!AZX_DCAPS_PM_RUNTIME || ((chip)->driver_caps & AZX_DCAPS_PM_RUNTIME)) + #endif /* __SOUND_HDA_PRIV_H */ -- cgit v1.2.3 From 89a93fea6182a71cedce9de1d901e4f379322cf3 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 19 Feb 2015 18:04:17 +0100 Subject: ALSA: hda - Fold hda_priv.h into hda_controller.h There is no big reason to keep them separately. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_controller.c | 1 - sound/pci/hda/hda_controller.h | 391 ++++++++++++++++++++++++++++++++++++++- sound/pci/hda/hda_i915.c | 2 +- sound/pci/hda/hda_intel.c | 1 - sound/pci/hda/hda_intel.h | 2 +- sound/pci/hda/hda_priv.h | 409 ----------------------------------------- sound/pci/hda/hda_tegra.c | 1 - 7 files changed, 392 insertions(+), 415 deletions(-) delete mode 100644 sound/pci/hda/hda_priv.h (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c index 3589fc2165b0..6b3254d479e1 100644 --- a/sound/pci/hda/hda_controller.c +++ b/sound/pci/hda/hda_controller.c @@ -30,7 +30,6 @@ #include #include #include -#include "hda_priv.h" #include "hda_controller.h" #define CREATE_TRACE_POINTS diff --git a/sound/pci/hda/hda_controller.h b/sound/pci/hda/hda_controller.h index c90d10fd4d8f..bd50b49cdd0d 100644 --- a/sound/pci/hda/hda_controller.h +++ b/sound/pci/hda/hda_controller.h @@ -15,10 +15,399 @@ #ifndef __SOUND_HDA_CONTROLLER_H #define __SOUND_HDA_CONTROLLER_H +#include +#include #include +#include #include #include "hda_codec.h" -#include "hda_priv.h" + +/* + * registers + */ +#define AZX_REG_GCAP 0x00 +#define AZX_GCAP_64OK (1 << 0) /* 64bit address support */ +#define AZX_GCAP_NSDO (3 << 1) /* # of serial data out signals */ +#define AZX_GCAP_BSS (31 << 3) /* # of bidirectional streams */ +#define AZX_GCAP_ISS (15 << 8) /* # of input streams */ +#define AZX_GCAP_OSS (15 << 12) /* # of output streams */ +#define AZX_REG_VMIN 0x02 +#define AZX_REG_VMAJ 0x03 +#define AZX_REG_OUTPAY 0x04 +#define AZX_REG_INPAY 0x06 +#define AZX_REG_GCTL 0x08 +#define AZX_GCTL_RESET (1 << 0) /* controller reset */ +#define AZX_GCTL_FCNTRL (1 << 1) /* flush control */ +#define AZX_GCTL_UNSOL (1 << 8) /* accept unsol. response enable */ +#define AZX_REG_WAKEEN 0x0c +#define AZX_REG_STATESTS 0x0e +#define AZX_REG_GSTS 0x10 +#define AZX_GSTS_FSTS (1 << 1) /* flush status */ +#define AZX_REG_INTCTL 0x20 +#define AZX_REG_INTSTS 0x24 +#define AZX_REG_WALLCLK 0x30 /* 24Mhz source */ +#define AZX_REG_OLD_SSYNC 0x34 /* SSYNC for old ICH */ +#define AZX_REG_SSYNC 0x38 +#define AZX_REG_CORBLBASE 0x40 +#define AZX_REG_CORBUBASE 0x44 +#define AZX_REG_CORBWP 0x48 +#define AZX_REG_CORBRP 0x4a +#define AZX_CORBRP_RST (1 << 15) /* read pointer reset */ +#define AZX_REG_CORBCTL 0x4c +#define AZX_CORBCTL_RUN (1 << 1) /* enable DMA */ +#define AZX_CORBCTL_CMEIE (1 << 0) /* enable memory error irq */ +#define AZX_REG_CORBSTS 0x4d +#define AZX_CORBSTS_CMEI (1 << 0) /* memory error indication */ +#define AZX_REG_CORBSIZE 0x4e + +#define AZX_REG_RIRBLBASE 0x50 +#define AZX_REG_RIRBUBASE 0x54 +#define AZX_REG_RIRBWP 0x58 +#define AZX_RIRBWP_RST (1 << 15) /* write pointer reset */ +#define AZX_REG_RINTCNT 0x5a +#define AZX_REG_RIRBCTL 0x5c +#define AZX_RBCTL_IRQ_EN (1 << 0) /* enable IRQ */ +#define AZX_RBCTL_DMA_EN (1 << 1) /* enable DMA */ +#define AZX_RBCTL_OVERRUN_EN (1 << 2) /* enable overrun irq */ +#define AZX_REG_RIRBSTS 0x5d +#define AZX_RBSTS_IRQ (1 << 0) /* response irq */ +#define AZX_RBSTS_OVERRUN (1 << 2) /* overrun irq */ +#define AZX_REG_RIRBSIZE 0x5e + +#define AZX_REG_IC 0x60 +#define AZX_REG_IR 0x64 +#define AZX_REG_IRS 0x68 +#define AZX_IRS_VALID (1<<1) +#define AZX_IRS_BUSY (1<<0) + +#define AZX_REG_DPLBASE 0x70 +#define AZX_REG_DPUBASE 0x74 +#define AZX_DPLBASE_ENABLE 0x1 /* Enable position buffer */ + +/* SD offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */ +enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 }; + +/* stream register offsets from stream base */ +#define AZX_REG_SD_CTL 0x00 +#define AZX_REG_SD_STS 0x03 +#define AZX_REG_SD_LPIB 0x04 +#define AZX_REG_SD_CBL 0x08 +#define AZX_REG_SD_LVI 0x0c +#define AZX_REG_SD_FIFOW 0x0e +#define AZX_REG_SD_FIFOSIZE 0x10 +#define AZX_REG_SD_FORMAT 0x12 +#define AZX_REG_SD_BDLPL 0x18 +#define AZX_REG_SD_BDLPU 0x1c + +/* PCI space */ +#define AZX_PCIREG_TCSEL 0x44 + +/* + * other constants + */ + +/* max number of fragments - we may use more if allocating more pages for BDL */ +#define BDL_SIZE 4096 +#define AZX_MAX_BDL_ENTRIES (BDL_SIZE / 16) +#define AZX_MAX_FRAG 32 +/* max buffer size - no h/w limit, you can increase as you like */ +#define AZX_MAX_BUF_SIZE (1024*1024*1024) + +/* RIRB int mask: overrun[2], response[0] */ +#define RIRB_INT_RESPONSE 0x01 +#define RIRB_INT_OVERRUN 0x04 +#define RIRB_INT_MASK 0x05 + +/* STATESTS int mask: S3,SD2,SD1,SD0 */ +#define AZX_MAX_CODECS 8 +#define AZX_DEFAULT_CODECS 4 +#define STATESTS_INT_MASK ((1 << AZX_MAX_CODECS) - 1) + +/* SD_CTL bits */ +#define SD_CTL_STREAM_RESET 0x01 /* stream reset bit */ +#define SD_CTL_DMA_START 0x02 /* stream DMA start bit */ +#define SD_CTL_STRIPE (3 << 16) /* stripe control */ +#define SD_CTL_TRAFFIC_PRIO (1 << 18) /* traffic priority */ +#define SD_CTL_DIR (1 << 19) /* bi-directional stream */ +#define SD_CTL_STREAM_TAG_MASK (0xf << 20) +#define SD_CTL_STREAM_TAG_SHIFT 20 + +/* SD_CTL and SD_STS */ +#define SD_INT_DESC_ERR 0x10 /* descriptor error interrupt */ +#define SD_INT_FIFO_ERR 0x08 /* FIFO error interrupt */ +#define SD_INT_COMPLETE 0x04 /* completion interrupt */ +#define SD_INT_MASK (SD_INT_DESC_ERR|SD_INT_FIFO_ERR|\ + SD_INT_COMPLETE) + +/* SD_STS */ +#define SD_STS_FIFO_READY 0x20 /* FIFO ready */ + +/* INTCTL and INTSTS */ +#define AZX_INT_ALL_STREAM 0xff /* all stream interrupts */ +#define AZX_INT_CTRL_EN 0x40000000 /* controller interrupt enable bit */ +#define AZX_INT_GLOBAL_EN 0x80000000 /* global interrupt enable bit */ + +/* below are so far hardcoded - should read registers in future */ +#define AZX_MAX_CORB_ENTRIES 256 +#define AZX_MAX_RIRB_ENTRIES 256 + +/* driver quirks (capabilities) */ +/* bits 0-7 are used for indicating driver type */ +#define AZX_DCAPS_NO_TCSEL (1 << 8) /* No Intel TCSEL bit */ +#define AZX_DCAPS_NO_MSI (1 << 9) /* No MSI support */ +#define AZX_DCAPS_SNOOP_MASK (3 << 10) /* snoop type mask */ +#define AZX_DCAPS_SNOOP_OFF (1 << 12) /* snoop default off */ +#define AZX_DCAPS_RIRB_DELAY (1 << 13) /* Long delay in read loop */ +#define AZX_DCAPS_RIRB_PRE_DELAY (1 << 14) /* Put a delay before read */ +#define AZX_DCAPS_CTX_WORKAROUND (1 << 15) /* X-Fi workaround */ +#define AZX_DCAPS_POSFIX_LPIB (1 << 16) /* Use LPIB as default */ +#define AZX_DCAPS_POSFIX_VIA (1 << 17) /* Use VIACOMBO as default */ +#define AZX_DCAPS_NO_64BIT (1 << 18) /* No 64bit address */ +#define AZX_DCAPS_SYNC_WRITE (1 << 19) /* sync each cmd write */ +#define AZX_DCAPS_OLD_SSYNC (1 << 20) /* Old SSYNC reg for ICH */ +#define AZX_DCAPS_NO_ALIGN_BUFSIZE (1 << 21) /* no buffer size alignment */ +/* 22 unused */ +#define AZX_DCAPS_4K_BDLE_BOUNDARY (1 << 23) /* BDLE in 4k boundary */ +#define AZX_DCAPS_REVERSE_ASSIGN (1 << 24) /* Assign devices in reverse order */ +#define AZX_DCAPS_COUNT_LPIB_DELAY (1 << 25) /* Take LPIB as delay */ +#define AZX_DCAPS_PM_RUNTIME (1 << 26) /* runtime PM support */ +#define AZX_DCAPS_I915_POWERWELL (1 << 27) /* HSW i915 powerwell support */ +#define AZX_DCAPS_CORBRP_SELF_CLEAR (1 << 28) /* CORBRP clears itself after reset */ +#define AZX_DCAPS_NO_MSI64 (1 << 29) /* Stick to 32-bit MSIs */ +#define AZX_DCAPS_SEPARATE_STREAM_TAG (1 << 30) /* capture and playback use separate stream tag */ + +enum { + AZX_SNOOP_TYPE_NONE, + AZX_SNOOP_TYPE_SCH, + AZX_SNOOP_TYPE_ATI, + AZX_SNOOP_TYPE_NVIDIA, +}; + +/* HD Audio class code */ +#define PCI_CLASS_MULTIMEDIA_HD_AUDIO 0x0403 + +struct azx_dev { + struct snd_dma_buffer bdl; /* BDL buffer */ + u32 *posbuf; /* position buffer pointer */ + + unsigned int bufsize; /* size of the play buffer in bytes */ + unsigned int period_bytes; /* size of the period in bytes */ + unsigned int frags; /* number for period in the play buffer */ + unsigned int fifo_size; /* FIFO size */ + unsigned long start_wallclk; /* start + minimum wallclk */ + unsigned long period_wallclk; /* wallclk for period */ + + void __iomem *sd_addr; /* stream descriptor pointer */ + + u32 sd_int_sta_mask; /* stream int status mask */ + + /* pcm support */ + struct snd_pcm_substream *substream; /* assigned substream, + * set in PCM open + */ + unsigned int format_val; /* format value to be set in the + * controller and the codec + */ + unsigned char stream_tag; /* assigned stream */ + unsigned char index; /* stream index */ + int assigned_key; /* last device# key assigned to */ + + unsigned int opened:1; + unsigned int running:1; + unsigned int irq_pending:1; + unsigned int prepared:1; + unsigned int locked:1; + /* + * For VIA: + * A flag to ensure DMA position is 0 + * when link position is not greater than FIFO size + */ + unsigned int insufficient:1; + unsigned int wc_marked:1; + unsigned int no_period_wakeup:1; + + struct timecounter azx_tc; + struct cyclecounter azx_cc; + + int delay_negative_threshold; + +#ifdef CONFIG_SND_HDA_DSP_LOADER + /* Allows dsp load to have sole access to the playback stream. */ + struct mutex dsp_mutex; +#endif +}; + +/* CORB/RIRB */ +struct azx_rb { + u32 *buf; /* CORB/RIRB buffer + * Each CORB entry is 4byte, RIRB is 8byte + */ + dma_addr_t addr; /* physical address of CORB/RIRB buffer */ + /* for RIRB */ + unsigned short rp, wp; /* read/write pointers */ + int cmds[AZX_MAX_CODECS]; /* number of pending requests */ + u32 res[AZX_MAX_CODECS]; /* last read value */ +}; + +struct azx; + +/* Functions to read/write to hda registers. */ +struct hda_controller_ops { + /* Register Access */ + void (*reg_writel)(u32 value, u32 __iomem *addr); + u32 (*reg_readl)(u32 __iomem *addr); + void (*reg_writew)(u16 value, u16 __iomem *addr); + u16 (*reg_readw)(u16 __iomem *addr); + void (*reg_writeb)(u8 value, u8 __iomem *addr); + u8 (*reg_readb)(u8 __iomem *addr); + /* Disable msi if supported, PCI only */ + int (*disable_msi_reset_irq)(struct azx *); + /* Allocation ops */ + int (*dma_alloc_pages)(struct azx *chip, + int type, + size_t size, + struct snd_dma_buffer *buf); + void (*dma_free_pages)(struct azx *chip, struct snd_dma_buffer *buf); + int (*substream_alloc_pages)(struct azx *chip, + struct snd_pcm_substream *substream, + size_t size); + int (*substream_free_pages)(struct azx *chip, + struct snd_pcm_substream *substream); + void (*pcm_mmap_prepare)(struct snd_pcm_substream *substream, + struct vm_area_struct *area); + /* Check if current position is acceptable */ + int (*position_check)(struct azx *chip, struct azx_dev *azx_dev); +}; + +struct azx_pcm { + struct azx *chip; + struct snd_pcm *pcm; + struct hda_codec *codec; + struct hda_pcm_stream *hinfo[2]; + struct list_head list; +}; + +typedef unsigned int (*azx_get_pos_callback_t)(struct azx *, struct azx_dev *); +typedef int (*azx_get_delay_callback_t)(struct azx *, struct azx_dev *, unsigned int pos); + +struct azx { + struct snd_card *card; + struct pci_dev *pci; + int dev_index; + + /* chip type specific */ + int driver_type; + unsigned int driver_caps; + int playback_streams; + int playback_index_offset; + int capture_streams; + int capture_index_offset; + int num_streams; + const int *jackpoll_ms; /* per-card jack poll interval */ + + /* Register interaction. */ + const struct hda_controller_ops *ops; + + /* position adjustment callbacks */ + azx_get_pos_callback_t get_position[2]; + azx_get_delay_callback_t get_delay[2]; + + /* pci resources */ + unsigned long addr; + void __iomem *remap_addr; + int irq; + + /* locks */ + spinlock_t reg_lock; + struct mutex open_mutex; /* Prevents concurrent open/close operations */ + + /* streams (x num_streams) */ + struct azx_dev *azx_dev; + + /* PCM */ + struct list_head pcm_list; /* azx_pcm list */ + + /* HD codec */ + unsigned short codec_mask; + int codec_probe_mask; /* copied from probe_mask option */ + struct hda_bus *bus; + unsigned int beep_mode; + + /* CORB/RIRB */ + struct azx_rb corb; + struct azx_rb rirb; + + /* CORB/RIRB and position buffers */ + struct snd_dma_buffer rb; + struct snd_dma_buffer posbuf; + +#ifdef CONFIG_SND_HDA_PATCH_LOADER + const struct firmware *fw; +#endif + + /* flags */ + const int *bdl_pos_adj; + int poll_count; + unsigned int running:1; + unsigned int initialized:1; + unsigned int single_cmd:1; + unsigned int polling_mode:1; + unsigned int msi:1; + unsigned int probing:1; /* codec probing phase */ + unsigned int snoop:1; + unsigned int align_buffer_size:1; + unsigned int region_requested:1; + unsigned int disabled:1; /* disabled by VGA-switcher */ + + /* for debugging */ + unsigned int last_cmd[AZX_MAX_CODECS]; + + /* reboot notifier (for mysterious hangup problem at power-down) */ + struct notifier_block reboot_notifier; + +#ifdef CONFIG_SND_HDA_DSP_LOADER + struct azx_dev saved_azx_dev; +#endif +}; + +#ifdef CONFIG_X86 +#define azx_snoop(chip) ((chip)->snoop) +#else +#define azx_snoop(chip) true +#endif + +/* + * macros for easy use + */ + +#define azx_writel(chip, reg, value) \ + ((chip)->ops->reg_writel(value, (chip)->remap_addr + AZX_REG_##reg)) +#define azx_readl(chip, reg) \ + ((chip)->ops->reg_readl((chip)->remap_addr + AZX_REG_##reg)) +#define azx_writew(chip, reg, value) \ + ((chip)->ops->reg_writew(value, (chip)->remap_addr + AZX_REG_##reg)) +#define azx_readw(chip, reg) \ + ((chip)->ops->reg_readw((chip)->remap_addr + AZX_REG_##reg)) +#define azx_writeb(chip, reg, value) \ + ((chip)->ops->reg_writeb(value, (chip)->remap_addr + AZX_REG_##reg)) +#define azx_readb(chip, reg) \ + ((chip)->ops->reg_readb((chip)->remap_addr + AZX_REG_##reg)) + +#define azx_sd_writel(chip, dev, reg, value) \ + ((chip)->ops->reg_writel(value, (dev)->sd_addr + AZX_REG_##reg)) +#define azx_sd_readl(chip, dev, reg) \ + ((chip)->ops->reg_readl((dev)->sd_addr + AZX_REG_##reg)) +#define azx_sd_writew(chip, dev, reg, value) \ + ((chip)->ops->reg_writew(value, (dev)->sd_addr + AZX_REG_##reg)) +#define azx_sd_readw(chip, dev, reg) \ + ((chip)->ops->reg_readw((dev)->sd_addr + AZX_REG_##reg)) +#define azx_sd_writeb(chip, dev, reg, value) \ + ((chip)->ops->reg_writeb(value, (dev)->sd_addr + AZX_REG_##reg)) +#define azx_sd_readb(chip, dev, reg) \ + ((chip)->ops->reg_readb((dev)->sd_addr + AZX_REG_##reg)) + +#define azx_has_pm_runtime(chip) \ + (!AZX_DCAPS_PM_RUNTIME || ((chip)->driver_caps & AZX_DCAPS_PM_RUNTIME)) /* PCM setup */ static inline struct azx_dev *get_azx_dev(struct snd_pcm_substream *substream) diff --git a/sound/pci/hda/hda_i915.c b/sound/pci/hda/hda_i915.c index 714894527e06..52a85d87c23c 100644 --- a/sound/pci/hda/hda_i915.c +++ b/sound/pci/hda/hda_i915.c @@ -22,7 +22,7 @@ #include #include #include -#include "hda_priv.h" +#include "hda_controller.h" #include "hda_intel.h" /* Intel HSW/BDW display HDA controller Extended Mode registers. diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index 589883291f4e..ced44a75f8ea 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c @@ -62,7 +62,6 @@ #include #include "hda_codec.h" #include "hda_controller.h" -#include "hda_priv.h" #include "hda_intel.h" /* position fix mode */ 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 @@ #define __SOUND_HDA_INTEL_H #include -#include "hda_priv.h" +#include "hda_controller.h" struct hda_intel { struct azx chip; diff --git a/sound/pci/hda/hda_priv.h b/sound/pci/hda/hda_priv.h deleted file mode 100644 index a7b4a25c571c..000000000000 --- a/sound/pci/hda/hda_priv.h +++ /dev/null @@ -1,409 +0,0 @@ -/* - * Common defines for the alsa driver code base for HD Audio. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - */ - -#ifndef __SOUND_HDA_PRIV_H -#define __SOUND_HDA_PRIV_H - -#include -#include -#include - -/* - * registers - */ -#define AZX_REG_GCAP 0x00 -#define AZX_GCAP_64OK (1 << 0) /* 64bit address support */ -#define AZX_GCAP_NSDO (3 << 1) /* # of serial data out signals */ -#define AZX_GCAP_BSS (31 << 3) /* # of bidirectional streams */ -#define AZX_GCAP_ISS (15 << 8) /* # of input streams */ -#define AZX_GCAP_OSS (15 << 12) /* # of output streams */ -#define AZX_REG_VMIN 0x02 -#define AZX_REG_VMAJ 0x03 -#define AZX_REG_OUTPAY 0x04 -#define AZX_REG_INPAY 0x06 -#define AZX_REG_GCTL 0x08 -#define AZX_GCTL_RESET (1 << 0) /* controller reset */ -#define AZX_GCTL_FCNTRL (1 << 1) /* flush control */ -#define AZX_GCTL_UNSOL (1 << 8) /* accept unsol. response enable */ -#define AZX_REG_WAKEEN 0x0c -#define AZX_REG_STATESTS 0x0e -#define AZX_REG_GSTS 0x10 -#define AZX_GSTS_FSTS (1 << 1) /* flush status */ -#define AZX_REG_INTCTL 0x20 -#define AZX_REG_INTSTS 0x24 -#define AZX_REG_WALLCLK 0x30 /* 24Mhz source */ -#define AZX_REG_OLD_SSYNC 0x34 /* SSYNC for old ICH */ -#define AZX_REG_SSYNC 0x38 -#define AZX_REG_CORBLBASE 0x40 -#define AZX_REG_CORBUBASE 0x44 -#define AZX_REG_CORBWP 0x48 -#define AZX_REG_CORBRP 0x4a -#define AZX_CORBRP_RST (1 << 15) /* read pointer reset */ -#define AZX_REG_CORBCTL 0x4c -#define AZX_CORBCTL_RUN (1 << 1) /* enable DMA */ -#define AZX_CORBCTL_CMEIE (1 << 0) /* enable memory error irq */ -#define AZX_REG_CORBSTS 0x4d -#define AZX_CORBSTS_CMEI (1 << 0) /* memory error indication */ -#define AZX_REG_CORBSIZE 0x4e - -#define AZX_REG_RIRBLBASE 0x50 -#define AZX_REG_RIRBUBASE 0x54 -#define AZX_REG_RIRBWP 0x58 -#define AZX_RIRBWP_RST (1 << 15) /* write pointer reset */ -#define AZX_REG_RINTCNT 0x5a -#define AZX_REG_RIRBCTL 0x5c -#define AZX_RBCTL_IRQ_EN (1 << 0) /* enable IRQ */ -#define AZX_RBCTL_DMA_EN (1 << 1) /* enable DMA */ -#define AZX_RBCTL_OVERRUN_EN (1 << 2) /* enable overrun irq */ -#define AZX_REG_RIRBSTS 0x5d -#define AZX_RBSTS_IRQ (1 << 0) /* response irq */ -#define AZX_RBSTS_OVERRUN (1 << 2) /* overrun irq */ -#define AZX_REG_RIRBSIZE 0x5e - -#define AZX_REG_IC 0x60 -#define AZX_REG_IR 0x64 -#define AZX_REG_IRS 0x68 -#define AZX_IRS_VALID (1<<1) -#define AZX_IRS_BUSY (1<<0) - -#define AZX_REG_DPLBASE 0x70 -#define AZX_REG_DPUBASE 0x74 -#define AZX_DPLBASE_ENABLE 0x1 /* Enable position buffer */ - -/* SD offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */ -enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 }; - -/* stream register offsets from stream base */ -#define AZX_REG_SD_CTL 0x00 -#define AZX_REG_SD_STS 0x03 -#define AZX_REG_SD_LPIB 0x04 -#define AZX_REG_SD_CBL 0x08 -#define AZX_REG_SD_LVI 0x0c -#define AZX_REG_SD_FIFOW 0x0e -#define AZX_REG_SD_FIFOSIZE 0x10 -#define AZX_REG_SD_FORMAT 0x12 -#define AZX_REG_SD_BDLPL 0x18 -#define AZX_REG_SD_BDLPU 0x1c - -/* PCI space */ -#define AZX_PCIREG_TCSEL 0x44 - -/* - * other constants - */ - -/* max number of fragments - we may use more if allocating more pages for BDL */ -#define BDL_SIZE 4096 -#define AZX_MAX_BDL_ENTRIES (BDL_SIZE / 16) -#define AZX_MAX_FRAG 32 -/* max buffer size - no h/w limit, you can increase as you like */ -#define AZX_MAX_BUF_SIZE (1024*1024*1024) - -/* RIRB int mask: overrun[2], response[0] */ -#define RIRB_INT_RESPONSE 0x01 -#define RIRB_INT_OVERRUN 0x04 -#define RIRB_INT_MASK 0x05 - -/* STATESTS int mask: S3,SD2,SD1,SD0 */ -#define AZX_MAX_CODECS 8 -#define AZX_DEFAULT_CODECS 4 -#define STATESTS_INT_MASK ((1 << AZX_MAX_CODECS) - 1) - -/* SD_CTL bits */ -#define SD_CTL_STREAM_RESET 0x01 /* stream reset bit */ -#define SD_CTL_DMA_START 0x02 /* stream DMA start bit */ -#define SD_CTL_STRIPE (3 << 16) /* stripe control */ -#define SD_CTL_TRAFFIC_PRIO (1 << 18) /* traffic priority */ -#define SD_CTL_DIR (1 << 19) /* bi-directional stream */ -#define SD_CTL_STREAM_TAG_MASK (0xf << 20) -#define SD_CTL_STREAM_TAG_SHIFT 20 - -/* SD_CTL and SD_STS */ -#define SD_INT_DESC_ERR 0x10 /* descriptor error interrupt */ -#define SD_INT_FIFO_ERR 0x08 /* FIFO error interrupt */ -#define SD_INT_COMPLETE 0x04 /* completion interrupt */ -#define SD_INT_MASK (SD_INT_DESC_ERR|SD_INT_FIFO_ERR|\ - SD_INT_COMPLETE) - -/* SD_STS */ -#define SD_STS_FIFO_READY 0x20 /* FIFO ready */ - -/* INTCTL and INTSTS */ -#define AZX_INT_ALL_STREAM 0xff /* all stream interrupts */ -#define AZX_INT_CTRL_EN 0x40000000 /* controller interrupt enable bit */ -#define AZX_INT_GLOBAL_EN 0x80000000 /* global interrupt enable bit */ - -/* below are so far hardcoded - should read registers in future */ -#define AZX_MAX_CORB_ENTRIES 256 -#define AZX_MAX_RIRB_ENTRIES 256 - -/* driver quirks (capabilities) */ -/* bits 0-7 are used for indicating driver type */ -#define AZX_DCAPS_NO_TCSEL (1 << 8) /* No Intel TCSEL bit */ -#define AZX_DCAPS_NO_MSI (1 << 9) /* No MSI support */ -#define AZX_DCAPS_SNOOP_MASK (3 << 10) /* snoop type mask */ -#define AZX_DCAPS_SNOOP_OFF (1 << 12) /* snoop default off */ -#define AZX_DCAPS_RIRB_DELAY (1 << 13) /* Long delay in read loop */ -#define AZX_DCAPS_RIRB_PRE_DELAY (1 << 14) /* Put a delay before read */ -#define AZX_DCAPS_CTX_WORKAROUND (1 << 15) /* X-Fi workaround */ -#define AZX_DCAPS_POSFIX_LPIB (1 << 16) /* Use LPIB as default */ -#define AZX_DCAPS_POSFIX_VIA (1 << 17) /* Use VIACOMBO as default */ -#define AZX_DCAPS_NO_64BIT (1 << 18) /* No 64bit address */ -#define AZX_DCAPS_SYNC_WRITE (1 << 19) /* sync each cmd write */ -#define AZX_DCAPS_OLD_SSYNC (1 << 20) /* Old SSYNC reg for ICH */ -#define AZX_DCAPS_NO_ALIGN_BUFSIZE (1 << 21) /* no buffer size alignment */ -/* 22 unused */ -#define AZX_DCAPS_4K_BDLE_BOUNDARY (1 << 23) /* BDLE in 4k boundary */ -#define AZX_DCAPS_REVERSE_ASSIGN (1 << 24) /* Assign devices in reverse order */ -#define AZX_DCAPS_COUNT_LPIB_DELAY (1 << 25) /* Take LPIB as delay */ -#define AZX_DCAPS_PM_RUNTIME (1 << 26) /* runtime PM support */ -#define AZX_DCAPS_I915_POWERWELL (1 << 27) /* HSW i915 powerwell support */ -#define AZX_DCAPS_CORBRP_SELF_CLEAR (1 << 28) /* CORBRP clears itself after reset */ -#define AZX_DCAPS_NO_MSI64 (1 << 29) /* Stick to 32-bit MSIs */ -#define AZX_DCAPS_SEPARATE_STREAM_TAG (1 << 30) /* capture and playback use separate stream tag */ - -enum { - AZX_SNOOP_TYPE_NONE , - AZX_SNOOP_TYPE_SCH, - AZX_SNOOP_TYPE_ATI, - AZX_SNOOP_TYPE_NVIDIA, -}; - -/* HD Audio class code */ -#define PCI_CLASS_MULTIMEDIA_HD_AUDIO 0x0403 - -struct azx_dev { - struct snd_dma_buffer bdl; /* BDL buffer */ - u32 *posbuf; /* position buffer pointer */ - - unsigned int bufsize; /* size of the play buffer in bytes */ - unsigned int period_bytes; /* size of the period in bytes */ - unsigned int frags; /* number for period in the play buffer */ - unsigned int fifo_size; /* FIFO size */ - unsigned long start_wallclk; /* start + minimum wallclk */ - unsigned long period_wallclk; /* wallclk for period */ - - void __iomem *sd_addr; /* stream descriptor pointer */ - - u32 sd_int_sta_mask; /* stream int status mask */ - - /* pcm support */ - struct snd_pcm_substream *substream; /* assigned substream, - * set in PCM open - */ - unsigned int format_val; /* format value to be set in the - * controller and the codec - */ - unsigned char stream_tag; /* assigned stream */ - unsigned char index; /* stream index */ - int assigned_key; /* last device# key assigned to */ - - unsigned int opened:1; - unsigned int running:1; - unsigned int irq_pending:1; - unsigned int prepared:1; - unsigned int locked:1; - /* - * For VIA: - * A flag to ensure DMA position is 0 - * when link position is not greater than FIFO size - */ - unsigned int insufficient:1; - unsigned int wc_marked:1; - unsigned int no_period_wakeup:1; - - struct timecounter azx_tc; - struct cyclecounter azx_cc; - - int delay_negative_threshold; - -#ifdef CONFIG_SND_HDA_DSP_LOADER - /* Allows dsp load to have sole access to the playback stream. */ - struct mutex dsp_mutex; -#endif -}; - -/* CORB/RIRB */ -struct azx_rb { - u32 *buf; /* CORB/RIRB buffer - * Each CORB entry is 4byte, RIRB is 8byte - */ - dma_addr_t addr; /* physical address of CORB/RIRB buffer */ - /* for RIRB */ - unsigned short rp, wp; /* read/write pointers */ - int cmds[AZX_MAX_CODECS]; /* number of pending requests */ - u32 res[AZX_MAX_CODECS]; /* last read value */ -}; - -struct azx; - -/* Functions to read/write to hda registers. */ -struct hda_controller_ops { - /* Register Access */ - void (*reg_writel)(u32 value, u32 __iomem *addr); - u32 (*reg_readl)(u32 __iomem *addr); - void (*reg_writew)(u16 value, u16 __iomem *addr); - u16 (*reg_readw)(u16 __iomem *addr); - void (*reg_writeb)(u8 value, u8 __iomem *addr); - u8 (*reg_readb)(u8 __iomem *addr); - /* Disable msi if supported, PCI only */ - int (*disable_msi_reset_irq)(struct azx *); - /* Allocation ops */ - int (*dma_alloc_pages)(struct azx *chip, - int type, - size_t size, - struct snd_dma_buffer *buf); - void (*dma_free_pages)(struct azx *chip, struct snd_dma_buffer *buf); - int (*substream_alloc_pages)(struct azx *chip, - struct snd_pcm_substream *substream, - size_t size); - int (*substream_free_pages)(struct azx *chip, - struct snd_pcm_substream *substream); - void (*pcm_mmap_prepare)(struct snd_pcm_substream *substream, - struct vm_area_struct *area); - /* Check if current position is acceptable */ - int (*position_check)(struct azx *chip, struct azx_dev *azx_dev); -}; - -struct azx_pcm { - struct azx *chip; - struct snd_pcm *pcm; - struct hda_codec *codec; - struct hda_pcm_stream *hinfo[2]; - struct list_head list; -}; - -typedef unsigned int (*azx_get_pos_callback_t)(struct azx *, struct azx_dev *); -typedef int (*azx_get_delay_callback_t)(struct azx *, struct azx_dev *, unsigned int pos); - -struct azx { - struct snd_card *card; - struct pci_dev *pci; - int dev_index; - - /* chip type specific */ - int driver_type; - unsigned int driver_caps; - int playback_streams; - int playback_index_offset; - int capture_streams; - int capture_index_offset; - int num_streams; - const int *jackpoll_ms; /* per-card jack poll interval */ - - /* Register interaction. */ - const struct hda_controller_ops *ops; - - /* position adjustment callbacks */ - azx_get_pos_callback_t get_position[2]; - azx_get_delay_callback_t get_delay[2]; - - /* pci resources */ - unsigned long addr; - void __iomem *remap_addr; - int irq; - - /* locks */ - spinlock_t reg_lock; - struct mutex open_mutex; /* Prevents concurrent open/close operations */ - - /* streams (x num_streams) */ - struct azx_dev *azx_dev; - - /* PCM */ - struct list_head pcm_list; /* azx_pcm list */ - - /* HD codec */ - unsigned short codec_mask; - int codec_probe_mask; /* copied from probe_mask option */ - struct hda_bus *bus; - unsigned int beep_mode; - - /* CORB/RIRB */ - struct azx_rb corb; - struct azx_rb rirb; - - /* CORB/RIRB and position buffers */ - struct snd_dma_buffer rb; - struct snd_dma_buffer posbuf; - -#ifdef CONFIG_SND_HDA_PATCH_LOADER - const struct firmware *fw; -#endif - - /* flags */ - const int *bdl_pos_adj; - int poll_count; - unsigned int running:1; - unsigned int initialized:1; - unsigned int single_cmd:1; - unsigned int polling_mode:1; - unsigned int msi:1; - unsigned int probing:1; /* codec probing phase */ - unsigned int snoop:1; - unsigned int align_buffer_size:1; - unsigned int region_requested:1; - unsigned int disabled:1; /* disabled by VGA-switcher */ - - /* for debugging */ - unsigned int last_cmd[AZX_MAX_CODECS]; - - /* reboot notifier (for mysterious hangup problem at power-down) */ - struct notifier_block reboot_notifier; - -#ifdef CONFIG_SND_HDA_DSP_LOADER - struct azx_dev saved_azx_dev; -#endif -}; - -#ifdef CONFIG_X86 -#define azx_snoop(chip) ((chip)->snoop) -#else -#define azx_snoop(chip) true -#endif - -/* - * macros for easy use - */ - -#define azx_writel(chip, reg, value) \ - ((chip)->ops->reg_writel(value, (chip)->remap_addr + AZX_REG_##reg)) -#define azx_readl(chip, reg) \ - ((chip)->ops->reg_readl((chip)->remap_addr + AZX_REG_##reg)) -#define azx_writew(chip, reg, value) \ - ((chip)->ops->reg_writew(value, (chip)->remap_addr + AZX_REG_##reg)) -#define azx_readw(chip, reg) \ - ((chip)->ops->reg_readw((chip)->remap_addr + AZX_REG_##reg)) -#define azx_writeb(chip, reg, value) \ - ((chip)->ops->reg_writeb(value, (chip)->remap_addr + AZX_REG_##reg)) -#define azx_readb(chip, reg) \ - ((chip)->ops->reg_readb((chip)->remap_addr + AZX_REG_##reg)) - -#define azx_sd_writel(chip, dev, reg, value) \ - ((chip)->ops->reg_writel(value, (dev)->sd_addr + AZX_REG_##reg)) -#define azx_sd_readl(chip, dev, reg) \ - ((chip)->ops->reg_readl((dev)->sd_addr + AZX_REG_##reg)) -#define azx_sd_writew(chip, dev, reg, value) \ - ((chip)->ops->reg_writew(value, (dev)->sd_addr + AZX_REG_##reg)) -#define azx_sd_readw(chip, dev, reg) \ - ((chip)->ops->reg_readw((dev)->sd_addr + AZX_REG_##reg)) -#define azx_sd_writeb(chip, dev, reg, value) \ - ((chip)->ops->reg_writeb(value, (dev)->sd_addr + AZX_REG_##reg)) -#define azx_sd_readb(chip, dev, reg) \ - ((chip)->ops->reg_readb((dev)->sd_addr + AZX_REG_##reg)) - -#define azx_has_pm_runtime(chip) \ - (!AZX_DCAPS_PM_RUNTIME || ((chip)->driver_caps & AZX_DCAPS_PM_RUNTIME)) - -#endif /* __SOUND_HDA_PRIV_H */ diff --git a/sound/pci/hda/hda_tegra.c b/sound/pci/hda/hda_tegra.c index 375e94f4cf52..7d0d04480f48 100644 --- a/sound/pci/hda/hda_tegra.c +++ b/sound/pci/hda/hda_tegra.c @@ -37,7 +37,6 @@ #include "hda_codec.h" #include "hda_controller.h" -#include "hda_priv.h" /* Defines for Nvidia Tegra HDA support */ #define HDA_BAR0 0x8000 -- cgit v1.2.3 From b8f28d53641f13902790904ab15028ff8ecd0882 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 19 Feb 2015 18:06:45 +0100 Subject: ALSA: hda - Drop azx_mixer_create() It's just an indirection, so let the caller directly calling snd_hda_build_controls(). Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_controller.c | 7 ------- sound/pci/hda/hda_controller.h | 1 - sound/pci/hda/hda_intel.c | 2 +- sound/pci/hda/hda_tegra.c | 2 +- 4 files changed, 2 insertions(+), 10 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c index 6b3254d479e1..6fab39133051 100644 --- a/sound/pci/hda/hda_controller.c +++ b/sound/pci/hda/hda_controller.c @@ -1923,13 +1923,6 @@ int azx_codec_configure(struct azx *chip) } EXPORT_SYMBOL_GPL(azx_codec_configure); -/* mixer creation - all stuff is implemented in hda module */ -int azx_mixer_create(struct azx *chip) -{ - return snd_hda_build_controls(chip->bus); -} -EXPORT_SYMBOL_GPL(azx_mixer_create); - static bool is_input_stream(struct azx *chip, unsigned char index) { diff --git a/sound/pci/hda/hda_controller.h b/sound/pci/hda/hda_controller.h index bd50b49cdd0d..79808e1a79ac 100644 --- a/sound/pci/hda/hda_controller.h +++ b/sound/pci/hda/hda_controller.h @@ -436,7 +436,6 @@ int azx_codec_create(struct azx *chip, const char *model, unsigned int max_slots, int *power_save_to); int azx_codec_configure(struct azx *chip); -int azx_mixer_create(struct azx *chip); int azx_init_stream(struct azx *chip); void azx_notifier_register(struct azx *chip); diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index ced44a75f8ea..b0a05691abe7 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c @@ -1923,7 +1923,7 @@ static int azx_probe_continue(struct azx *chip) goto out_free; /* create mixer controls */ - err = azx_mixer_create(chip); + err = snd_hda_build_controls(chip->bus); if (err < 0) goto out_free; diff --git a/sound/pci/hda/hda_tegra.c b/sound/pci/hda/hda_tegra.c index 7d0d04480f48..f305c2a99206 100644 --- a/sound/pci/hda/hda_tegra.c +++ b/sound/pci/hda/hda_tegra.c @@ -516,7 +516,7 @@ static int hda_tegra_probe(struct platform_device *pdev) goto out_free; /* create mixer controls */ - err = azx_mixer_create(chip); + err = snd_hda_build_controls(chip->bus); if (err < 0) goto out_free; -- cgit v1.2.3 From 96d2bd6e3cdf57926f80605d6e28051bb6b24eb3 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 19 Feb 2015 18:12:22 +0100 Subject: ALSA: hda - Split azx_codec_create() to two phases azx_create_codec() function does actually two things: create a bus and probe codecs. For the future work, split this to two logical functions, azx_bus_create() and azx_probe_codecs(). Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_controller.c | 40 ++++++++++++++++++++++++---------------- sound/pci/hda/hda_controller.h | 5 ++--- sound/pci/hda/hda_intel.c | 8 +++++--- sound/pci/hda/hda_tegra.c | 6 +++++- 4 files changed, 36 insertions(+), 23 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c index 6fab39133051..2a674525e56f 100644 --- a/sound/pci/hda/hda_controller.c +++ b/sound/pci/hda/hda_controller.c @@ -1829,13 +1829,11 @@ static struct hda_bus_ops bus_ops = { #endif }; -/* Codec initialization */ -int azx_codec_create(struct azx *chip, const char *model, - unsigned int max_slots, - int *power_save_to) +/* HD-audio bus initialization */ +int azx_bus_create(struct azx *chip, const char *model, int *power_save_to) { struct hda_bus *bus; - int c, codecs, err; + int err; err = snd_hda_bus_new(chip->card, &bus); if (err < 0) @@ -1855,6 +1853,26 @@ int azx_codec_create(struct azx *chip, const char *model, bus->needs_damn_long_delay = 1; } + /* AMD chipsets often cause the communication stalls upon certain + * sequence like the pin-detection. It seems that forcing the synced + * access works around the stall. Grrr... + */ + if (chip->driver_caps & AZX_DCAPS_SYNC_WRITE) { + dev_dbg(chip->card->dev, "Enable sync_write for stable communication\n"); + bus->sync_write = 1; + bus->allow_bus_reset = 1; + } + + return 0; +} +EXPORT_SYMBOL_GPL(azx_bus_create); + +/* Probe codecs */ +int azx_probe_codecs(struct azx *chip, unsigned int max_slots) +{ + struct hda_bus *bus = chip->bus; + int c, codecs, err; + codecs = 0; if (!max_slots) max_slots = AZX_DEFAULT_CODECS; @@ -1882,16 +1900,6 @@ int azx_codec_create(struct azx *chip, const char *model, } } - /* AMD chipsets often cause the communication stalls upon certain - * sequence like the pin-detection. It seems that forcing the synced - * access works around the stall. Grrr... - */ - if (chip->driver_caps & AZX_DCAPS_SYNC_WRITE) { - dev_dbg(chip->card->dev, "Enable sync_write for stable communication\n"); - bus->sync_write = 1; - bus->allow_bus_reset = 1; - } - /* Then create codec instances */ for (c = 0; c < max_slots; c++) { if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) { @@ -1910,7 +1918,7 @@ int azx_codec_create(struct azx *chip, const char *model, } return 0; } -EXPORT_SYMBOL_GPL(azx_codec_create); +EXPORT_SYMBOL_GPL(azx_probe_codecs); /* configure each codec instance */ int azx_codec_configure(struct azx *chip) diff --git a/sound/pci/hda/hda_controller.h b/sound/pci/hda/hda_controller.h index 79808e1a79ac..0d09aa6b49ac 100644 --- a/sound/pci/hda/hda_controller.h +++ b/sound/pci/hda/hda_controller.h @@ -432,9 +432,8 @@ void azx_enter_link_reset(struct azx *chip); irqreturn_t azx_interrupt(int irq, void *dev_id); /* Codec interface */ -int azx_codec_create(struct azx *chip, const char *model, - unsigned int max_slots, - int *power_save_to); +int azx_bus_create(struct azx *chip, const char *model, int *power_save_to); +int azx_probe_codecs(struct azx *chip, unsigned int max_slots); int azx_codec_configure(struct azx *chip); int azx_init_stream(struct azx *chip); diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index b0a05691abe7..5e00cc4a722f 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c @@ -1893,12 +1893,14 @@ static int azx_probe_continue(struct azx *chip) #endif /* create codec instances */ - err = azx_codec_create(chip, model[dev], - azx_max_codecs[chip->driver_type], - power_save_addr); + err = azx_bus_create(chip, model[dev], power_save_addr); + if (err < 0) + goto out_free; + err = azx_probe_codecs(chip, azx_max_codecs[chip->driver_type]); if (err < 0) goto out_free; + #ifdef CONFIG_SND_HDA_PATCH_LOADER if (chip->fw) { err = snd_hda_load_patch(chip->bus, chip->fw->size, diff --git a/sound/pci/hda/hda_tegra.c b/sound/pci/hda/hda_tegra.c index f305c2a99206..1bd7a9e04046 100644 --- a/sound/pci/hda/hda_tegra.c +++ b/sound/pci/hda/hda_tegra.c @@ -502,7 +502,11 @@ static int hda_tegra_probe(struct platform_device *pdev) goto out_free; /* create codec instances */ - err = azx_codec_create(chip, NULL, 0, &power_save); + err = azx_bus_create(chip, NULL, &power_save); + if (err < 0) + goto out_free; + + err = azx_probe_codecs(chip, 0); if (err < 0) goto out_free; -- cgit v1.2.3 From 781c7b9615dc1441d6743124086eb3da14bf46e9 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 20 Feb 2015 10:26:25 +0100 Subject: ALSA: hda - Avoid unnecessary power-up at mixer amp changes When the mixer amp is touched by control elements, we don't have to power up always; if the codec was suspended at the time, we can just update the amp cache and it's reflected to the hardware upon resume. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_codec.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 0734cb35887d..5e755eb6f19a 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -2148,11 +2148,10 @@ EXPORT_SYMBOL_GPL(snd_hda_codec_amp_read); static int codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch, int direction, int idx, int mask, int val, - bool init_only) + bool init_only, bool cache_only) { struct hda_amp_info *info; unsigned int caps; - unsigned int cache_only; if (snd_BUG_ON(mask & ~0xff)) mask &= 0xff; @@ -2170,7 +2169,7 @@ static int codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch, return 0; } info->vol[ch] = val; - cache_only = info->head.dirty = codec->cached_write; + info->head.dirty |= cache_only; caps = info->amp_caps; mutex_unlock(&codec->hash_mutex); if (!cache_only) @@ -2194,7 +2193,8 @@ static int codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch, int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch, int direction, int idx, int mask, int val) { - return codec_amp_update(codec, nid, ch, direction, idx, mask, val, false); + return codec_amp_update(codec, nid, ch, direction, idx, mask, val, + false, codec->cached_write); } EXPORT_SYMBOL_GPL(snd_hda_codec_amp_update); @@ -2241,7 +2241,8 @@ EXPORT_SYMBOL_GPL(snd_hda_codec_amp_stereo); int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch, int dir, int idx, int mask, int val) { - return codec_amp_update(codec, nid, ch, dir, idx, mask, val, true); + return codec_amp_update(codec, nid, ch, dir, idx, mask, val, true, + codec->cached_write); } EXPORT_SYMBOL_GPL(snd_hda_codec_amp_init); @@ -2383,8 +2384,8 @@ update_amp_value(struct hda_codec *codec, hda_nid_t nid, maxval = get_amp_max_value(codec, nid, dir, 0); if (val > maxval) val = maxval; - return snd_hda_codec_amp_update(codec, nid, ch, dir, idx, - HDA_AMP_VOLMASK, val); + return codec_amp_update(codec, nid, ch, dir, idx, HDA_AMP_VOLMASK, val, + false, !hda_codec_is_power_on(codec)); } /** @@ -2434,14 +2435,12 @@ int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol, long *valp = ucontrol->value.integer.value; int change = 0; - snd_hda_power_up(codec); if (chs & 1) { change = update_amp_value(codec, nid, 0, dir, idx, ofs, *valp); valp++; } if (chs & 2) change |= update_amp_value(codec, nid, 1, dir, idx, ofs, *valp); - snd_hda_power_down(codec); return change; } EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_volume_put); @@ -3109,19 +3108,19 @@ int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol, long *valp = ucontrol->value.integer.value; int change = 0; - snd_hda_power_up(codec); if (chs & 1) { - change = snd_hda_codec_amp_update(codec, nid, 0, dir, idx, - HDA_AMP_MUTE, - *valp ? 0 : HDA_AMP_MUTE); + change = codec_amp_update(codec, nid, 0, dir, idx, + HDA_AMP_MUTE, + *valp ? 0 : HDA_AMP_MUTE, false, + !hda_codec_is_power_on(codec)); valp++; } if (chs & 2) - change |= snd_hda_codec_amp_update(codec, nid, 1, dir, idx, - HDA_AMP_MUTE, - *valp ? 0 : HDA_AMP_MUTE); + change |= codec_amp_update(codec, nid, 1, dir, idx, + HDA_AMP_MUTE, + *valp ? 0 : HDA_AMP_MUTE, false, + !hda_codec_is_power_on(codec)); hda_call_check_power_status(codec, nid); - snd_hda_power_down(codec); return change; } EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_switch_put); -- cgit v1.2.3 From 9e94df3a624b1b485f2c2ac5ab94032da01e45b3 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Fri, 13 Feb 2015 15:14:07 -0600 Subject: ALSA: hda: replace .wallclock by .get_time_info No real functional change, only take wall clock and system time in same routine and add accuracy report. Signed-off-by: Pierre-Louis Bossart Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_controller.c | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c index dfcb5e929f9f..7806f1d297cb 100644 --- a/sound/pci/hda/hda_controller.c +++ b/sound/pci/hda/hda_controller.c @@ -732,17 +732,32 @@ static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream) azx_get_position(chip, azx_dev)); } -static int azx_get_wallclock_tstamp(struct snd_pcm_substream *substream, - struct timespec *ts) +static int azx_get_time_info(struct snd_pcm_substream *substream, + struct timespec *system_ts, struct timespec *audio_ts, + struct snd_pcm_audio_tstamp_config *audio_tstamp_config, + struct snd_pcm_audio_tstamp_report *audio_tstamp_report) { struct azx_dev *azx_dev = get_azx_dev(substream); u64 nsec; - nsec = timecounter_read(&azx_dev->azx_tc); - nsec = div_u64(nsec, 3); /* can be optimized */ - nsec = azx_adjust_codec_delay(substream, nsec); + if ((substream->runtime->hw.info & SNDRV_PCM_INFO_HAS_LINK_ATIME) && + (audio_tstamp_config->type_requested == SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK)) { - *ts = ns_to_timespec(nsec); + snd_pcm_gettime(substream->runtime, system_ts); + + nsec = timecounter_read(&azx_dev->azx_tc); + nsec = div_u64(nsec, 3); /* can be optimized */ + if (audio_tstamp_config->report_delay) + nsec = azx_adjust_codec_delay(substream, nsec); + + *audio_ts = ns_to_timespec(nsec); + + audio_tstamp_report->actual_type = SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK; + audio_tstamp_report->accuracy_report = 1; /* rest of structure is valid */ + audio_tstamp_report->accuracy = 42; /* 24 MHz WallClock == 42ns resolution */ + + } else + audio_tstamp_report->actual_type = SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT; return 0; } @@ -756,7 +771,8 @@ static struct snd_pcm_hardware azx_pcm_hw = { /* SNDRV_PCM_INFO_RESUME |*/ SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START | - SNDRV_PCM_INFO_HAS_WALL_CLOCK | + SNDRV_PCM_INFO_HAS_WALL_CLOCK | /* legacy */ + SNDRV_PCM_INFO_HAS_LINK_ATIME | SNDRV_PCM_INFO_NO_PERIOD_WAKEUP), .formats = SNDRV_PCM_FMTBIT_S16_LE, .rates = SNDRV_PCM_RATE_48000, @@ -842,10 +858,12 @@ static int azx_pcm_open(struct snd_pcm_substream *substream) return -EINVAL; } - /* disable WALLCLOCK timestamps for capture streams + /* disable LINK_ATIME timestamps for capture streams until we figure out how to handle digital inputs */ - if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) - runtime->hw.info &= ~SNDRV_PCM_INFO_HAS_WALL_CLOCK; + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { + runtime->hw.info &= ~SNDRV_PCM_INFO_HAS_WALL_CLOCK; /* legacy */ + runtime->hw.info &= ~SNDRV_PCM_INFO_HAS_LINK_ATIME; + } spin_lock_irqsave(&chip->reg_lock, flags); azx_dev->substream = substream; @@ -877,7 +895,7 @@ static struct snd_pcm_ops azx_pcm_ops = { .prepare = azx_pcm_prepare, .trigger = azx_pcm_trigger, .pointer = azx_pcm_pointer, - .wall_clock = azx_get_wallclock_tstamp, + .get_time_info = azx_get_time_info, .mmap = azx_pcm_mmap, .page = snd_pcm_sgbuf_ops_page, }; -- cgit v1.2.3 From 327ef4f02582d01f7eedb291794106823b44a0cf Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 17 Feb 2015 17:15:04 +0100 Subject: ALSA: hda - Decouple PCM and hwdep devices from codec object This is a preliminary patch for the hda_bus implementation, removing the parent device setup to codec device. Since the bus and the class devices can't be crossed over, leave the sound devices to the default parent device as is. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_beep.c | 1 - sound/pci/hda/hda_controller.c | 3 --- sound/pci/hda/hda_hwdep.c | 3 --- 3 files changed, 7 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_beep.c b/sound/pci/hda/hda_beep.c index 1e7de08e77cb..d6be4e852c4d 100644 --- a/sound/pci/hda/hda_beep.c +++ b/sound/pci/hda/hda_beep.c @@ -168,7 +168,6 @@ static int snd_hda_do_attach(struct hda_beep *beep) input_dev->evbit[0] = BIT_MASK(EV_SND); input_dev->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE); input_dev->event = snd_hda_beep_event; - input_dev->dev.parent = &codec->dev; input_set_drvdata(input_dev, beep); beep->dev = input_dev; diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c index ebb7a644bd86..4c7a6f9bfcde 100644 --- a/sound/pci/hda/hda_controller.c +++ b/sound/pci/hda/hda_controller.c @@ -958,9 +958,6 @@ static int azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec, snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, chip->card->dev, size, MAX_PREALLOC_SIZE); - /* link to codec */ - for (s = 0; s < 2; s++) - pcm->streams[s].dev.parent = &codec->dev; return 0; } diff --git a/sound/pci/hda/hda_hwdep.c b/sound/pci/hda/hda_hwdep.c index 11b5a42b4ec8..125f3420fa6a 100644 --- a/sound/pci/hda/hda_hwdep.c +++ b/sound/pci/hda/hda_hwdep.c @@ -116,9 +116,6 @@ int snd_hda_create_hwdep(struct hda_codec *codec) hwdep->ops.ioctl_compat = hda_hwdep_ioctl_compat; #endif - /* link to codec */ - hwdep->dev.parent = &codec->dev; - /* for sysfs */ hwdep->dev.groups = snd_hda_dev_attr_groups; dev_set_drvdata(&hwdep->dev, codec); -- cgit v1.2.3 From d8a766a16ed90c4b3bd7afa6e1417f8d715db507 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 17 Feb 2015 15:25:37 +0100 Subject: ALSA: hda - Bind codecs via standard bus Now we create the standard HD-audio bus (/sys/bus/hdaudio), and bind the codec driver with the codec device over there. This is the first step of the whole transition so that the changes to each codec driver are kept as minimal as possible. Each codec driver needs to register hda_codec_driver struct containing the currently existing preset via the new helper macro module_hda_codec_driver(). The old hda_codec_preset_list is replaced with this infrastructure. The generic parsers (for HDMI and other) are also included in the preset with the special IDs to bind uniquely. In HD-audio core side, the device binding code is split to hda_bind.c. It provides the snd_hda_bus_type implementation to match the codec driver with the given codec vendor ID. It also manages the module auto-loading by itself like before: when the matching isn't found, it tries to probe the corresponding codec modules, and finally falls back to the generic drivers. (The special ID mentioned above is set at this stage.) The only visible change to outside is that the hdaudio sysfs entry now appears in /sys/bus/devices, not as a sound class device. More works to move the suspend/resume and remove ops will be (hopefully) done in later patches. Signed-off-by: Takashi Iwai --- sound/pci/hda/Makefile | 2 +- sound/pci/hda/hda_bind.c | 320 +++++++++++++++++++++++++++++++++++++++++ sound/pci/hda/hda_codec.c | 307 +++------------------------------------ sound/pci/hda/hda_codec.h | 27 ++-- sound/pci/hda/hda_generic.c | 18 ++- sound/pci/hda/hda_local.h | 18 ++- sound/pci/hda/patch_analog.c | 16 +-- sound/pci/hda/patch_ca0110.c | 16 +-- sound/pci/hda/patch_ca0132.c | 16 +-- sound/pci/hda/patch_cirrus.c | 16 +-- sound/pci/hda/patch_cmedia.c | 16 +-- sound/pci/hda/patch_conexant.c | 16 +-- sound/pci/hda/patch_hdmi.c | 27 +--- sound/pci/hda/patch_realtek.c | 16 +-- sound/pci/hda/patch_si3054.c | 16 +-- sound/pci/hda/patch_sigmatel.c | 16 +-- sound/pci/hda/patch_via.c | 16 +-- 17 files changed, 401 insertions(+), 478 deletions(-) create mode 100644 sound/pci/hda/hda_bind.c (limited to 'sound/pci') diff --git a/sound/pci/hda/Makefile b/sound/pci/hda/Makefile index 194f30935e77..96caaebfc19d 100644 --- a/sound/pci/hda/Makefile +++ b/sound/pci/hda/Makefile @@ -4,7 +4,7 @@ snd-hda-tegra-objs := hda_tegra.o # for haswell power well snd-hda-intel-$(CONFIG_SND_HDA_I915) += hda_i915.o -snd-hda-codec-y := hda_codec.o hda_jack.o hda_auto_parser.o hda_sysfs.o +snd-hda-codec-y := hda_bind.o hda_codec.o hda_jack.o hda_auto_parser.o hda_sysfs.o snd-hda-codec-$(CONFIG_PROC_FS) += hda_proc.o snd-hda-codec-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o snd-hda-codec-$(CONFIG_SND_HDA_INPUT_BEEP) += hda_beep.o diff --git a/sound/pci/hda/hda_bind.c b/sound/pci/hda/hda_bind.c new file mode 100644 index 000000000000..adf6b475dee1 --- /dev/null +++ b/sound/pci/hda/hda_bind.c @@ -0,0 +1,320 @@ +/* + * HD-audio codec driver binding + * Copyright (c) Takashi Iwai + */ + +#include +#include +#include +#include +#include +#include +#include "hda_codec.h" +#include "hda_local.h" + +/* codec vendor labels */ +struct hda_vendor_id { + unsigned int id; + const char *name; +}; + +static struct hda_vendor_id hda_vendor_ids[] = { + { 0x1002, "ATI" }, + { 0x1013, "Cirrus Logic" }, + { 0x1057, "Motorola" }, + { 0x1095, "Silicon Image" }, + { 0x10de, "Nvidia" }, + { 0x10ec, "Realtek" }, + { 0x1102, "Creative" }, + { 0x1106, "VIA" }, + { 0x111d, "IDT" }, + { 0x11c1, "LSI" }, + { 0x11d4, "Analog Devices" }, + { 0x13f6, "C-Media" }, + { 0x14f1, "Conexant" }, + { 0x17e8, "Chrontel" }, + { 0x1854, "LG" }, + { 0x1aec, "Wolfson Microelectronics" }, + { 0x1af4, "QEMU" }, + { 0x434d, "C-Media" }, + { 0x8086, "Intel" }, + { 0x8384, "SigmaTel" }, + {} /* terminator */ +}; + +/* + * find a matching codec preset + */ +static int hda_bus_match(struct device *dev, struct device_driver *drv) +{ + struct hda_codec *codec = container_of(dev, struct hda_codec, dev); + struct hda_codec_driver *driver = + container_of(drv, struct hda_codec_driver, driver); + const struct hda_codec_preset *preset; + /* check probe_id instead of vendor_id if set */ + u32 id = codec->probe_id ? codec->probe_id : codec->vendor_id; + + for (preset = driver->preset; preset->id; preset++) { + u32 mask = preset->mask; + + if (preset->afg && preset->afg != codec->afg) + continue; + if (preset->mfg && preset->mfg != codec->mfg) + continue; + if (!mask) + mask = ~0; + if (preset->id == (id & mask) && + (!preset->rev || preset->rev == codec->revision_id)) { + codec->preset = preset; + return 1; + } + } + return 0; +} + +/* reset the codec name from the preset */ +static int codec_refresh_name(struct hda_codec *codec, const char *name) +{ + char tmp[16]; + + kfree(codec->chip_name); + if (!name) { + sprintf(tmp, "ID %x", codec->vendor_id & 0xffff); + name = tmp; + } + codec->chip_name = kstrdup(name, GFP_KERNEL); + return codec->chip_name ? 0 : -ENOMEM; +} + +static int hda_codec_driver_probe(struct device *dev) +{ + struct hda_codec *codec = dev_to_hda_codec(dev); + struct module *owner = dev->driver->owner; + int err; + + if (WARN_ON(!codec->preset)) + return -EINVAL; + + err = codec_refresh_name(codec, codec->preset->name); + if (err < 0) + goto error; + + if (!try_module_get(owner)) { + err = -EINVAL; + goto error; + } + + err = codec->preset->patch(codec); + if (err < 0) { + module_put(owner); + goto error; + } + + return 0; + + error: + codec->preset = NULL; + memset(&codec->patch_ops, 0, sizeof(codec->patch_ops)); + return err; +} + +static int hda_codec_driver_remove(struct device *dev) +{ + struct hda_codec *codec = dev_to_hda_codec(dev); + + if (codec->patch_ops.free) + codec->patch_ops.free(codec); + codec->preset = NULL; + memset(&codec->patch_ops, 0, sizeof(codec->patch_ops)); + module_put(dev->driver->owner); + return 0; +} + +int __hda_codec_driver_register(struct hda_codec_driver *drv, const char *name, + struct module *owner) +{ + drv->driver.name = name; + drv->driver.owner = owner; + drv->driver.bus = &snd_hda_bus_type; + drv->driver.probe = hda_codec_driver_probe; + drv->driver.remove = hda_codec_driver_remove; + /* TODO: PM and others */ + return driver_register(&drv->driver); +} +EXPORT_SYMBOL_GPL(__hda_codec_driver_register); + +void hda_codec_driver_unregister(struct hda_codec_driver *drv) +{ + driver_unregister(&drv->driver); +} +EXPORT_SYMBOL_GPL(hda_codec_driver_unregister); + +static inline bool codec_probed(struct hda_codec *codec) +{ + return device_attach(hda_codec_dev(codec)) > 0 && codec->preset; +} + +/* try to auto-load and bind the codec module */ +static void codec_bind_module(struct hda_codec *codec) +{ +#ifdef MODULE + request_module("snd-hda-codec-id:%08x", codec->vendor_id); + if (codec_probed(codec)) + return; + request_module("snd-hda-codec-id:%04x*", + (codec->vendor_id >> 16) & 0xffff); + if (codec_probed(codec)) + return; +#endif +} + +/* store the codec vendor name */ +static int get_codec_vendor_name(struct hda_codec *codec) +{ + const struct hda_vendor_id *c; + const char *vendor = NULL; + u16 vendor_id = codec->vendor_id >> 16; + char tmp[16]; + + for (c = hda_vendor_ids; c->id; c++) { + if (c->id == vendor_id) { + vendor = c->name; + break; + } + } + if (!vendor) { + sprintf(tmp, "Generic %04x", vendor_id); + vendor = tmp; + } + codec->vendor_name = kstrdup(vendor, GFP_KERNEL); + if (!codec->vendor_name) + return -ENOMEM; + return 0; +} + +#if IS_ENABLED(CONFIG_SND_HDA_CODEC_HDMI) +/* if all audio out widgets are digital, let's assume the codec as a HDMI/DP */ +static bool is_likely_hdmi_codec(struct hda_codec *codec) +{ + hda_nid_t nid = codec->start_nid; + int i; + + for (i = 0; i < codec->num_nodes; i++, nid++) { + unsigned int wcaps = get_wcaps(codec, nid); + switch (get_wcaps_type(wcaps)) { + case AC_WID_AUD_IN: + return false; /* HDMI parser supports only HDMI out */ + case AC_WID_AUD_OUT: + if (!(wcaps & AC_WCAP_DIGITAL)) + return false; + break; + } + } + return true; +} +#else +/* no HDMI codec parser support */ +#define is_likely_hdmi_codec(codec) false +#endif /* CONFIG_SND_HDA_CODEC_HDMI */ + +static int codec_bind_generic(struct hda_codec *codec) +{ + if (codec->probe_id) + return -ENODEV; + + if (is_likely_hdmi_codec(codec)) { + codec->probe_id = HDA_CODEC_ID_GENERIC_HDMI; +#if IS_MODULE(CONFIG_SND_HDA_CODEC_HDMI) + request_module("snd-hda-codec-hdmi"); +#endif + if (codec_probed(codec)) + return 0; + } + + codec->probe_id = HDA_CODEC_ID_GENERIC; +#if IS_MODULE(CONFIG_SND_HDA_GENERIC) + request_module("snd-hda-codec-generic"); +#endif + if (codec_probed(codec)) + return 0; + return -ENODEV; +} + +#if IS_ENABLED(CONFIG_SND_HDA_GENERIC) +#define is_generic_config(codec) \ + (codec->modelname && !strcmp(codec->modelname, "generic")) +#else +#define is_generic_config(codec) 0 +#endif + +/** + * snd_hda_codec_configure - (Re-)configure the HD-audio codec + * @codec: the HDA codec + * + * Start parsing of the given codec tree and (re-)initialize the whole + * patch instance. + * + * Returns 0 if successful or a negative error code. + */ +int snd_hda_codec_configure(struct hda_codec *codec) +{ + int err; + + if (!codec->vendor_name) { + err = get_codec_vendor_name(codec); + if (err < 0) + return err; + } + + if (is_generic_config(codec)) + codec->probe_id = HDA_CODEC_ID_GENERIC; + else + codec->probe_id = 0; + + err = device_add(hda_codec_dev(codec)); + if (err < 0) + return err; + + if (!codec->preset) + codec_bind_module(codec); + if (!codec->preset) { + err = codec_bind_generic(codec); + if (err < 0) { + codec_err(codec, "Unable to bind the codec\n"); + goto error; + } + } + + /* audio codec should override the mixer name */ + if (codec->afg || !*codec->bus->card->mixername) + snprintf(codec->bus->card->mixername, + sizeof(codec->bus->card->mixername), + "%s %s", codec->vendor_name, codec->chip_name); + return 0; + + error: + device_del(hda_codec_dev(codec)); + return err; +} +EXPORT_SYMBOL_GPL(snd_hda_codec_configure); + +/* + * bus registration + */ +struct bus_type snd_hda_bus_type = { + .name = "hdaudio", + .match = hda_bus_match, +}; + +static int __init hda_codec_init(void) +{ + return bus_register(&snd_hda_bus_type); +} + +static void __exit hda_codec_exit(void) +{ + bus_unregister(&snd_hda_bus_type); +} + +module_init(hda_codec_init); +module_exit(hda_codec_exit); diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 5e755eb6f19a..61c8174e8013 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -40,69 +40,6 @@ #define CREATE_TRACE_POINTS #include "hda_trace.h" -/* - * vendor / preset table - */ - -struct hda_vendor_id { - unsigned int id; - const char *name; -}; - -/* codec vendor labels */ -static struct hda_vendor_id hda_vendor_ids[] = { - { 0x1002, "ATI" }, - { 0x1013, "Cirrus Logic" }, - { 0x1057, "Motorola" }, - { 0x1095, "Silicon Image" }, - { 0x10de, "Nvidia" }, - { 0x10ec, "Realtek" }, - { 0x1102, "Creative" }, - { 0x1106, "VIA" }, - { 0x111d, "IDT" }, - { 0x11c1, "LSI" }, - { 0x11d4, "Analog Devices" }, - { 0x13f6, "C-Media" }, - { 0x14f1, "Conexant" }, - { 0x17e8, "Chrontel" }, - { 0x1854, "LG" }, - { 0x1aec, "Wolfson Microelectronics" }, - { 0x1af4, "QEMU" }, - { 0x434d, "C-Media" }, - { 0x8086, "Intel" }, - { 0x8384, "SigmaTel" }, - {} /* terminator */ -}; - -static DEFINE_MUTEX(preset_mutex); -static LIST_HEAD(hda_preset_tables); - -/** - * snd_hda_add_codec_preset - Add a codec preset to the chain - * @preset: codec preset table to add - */ -int snd_hda_add_codec_preset(struct hda_codec_preset_list *preset) -{ - mutex_lock(&preset_mutex); - list_add_tail(&preset->list, &hda_preset_tables); - mutex_unlock(&preset_mutex); - return 0; -} -EXPORT_SYMBOL_GPL(snd_hda_add_codec_preset); - -/** - * snd_hda_delete_codec_preset - Delete a codec preset from the chain - * @preset: codec preset table to delete - */ -int snd_hda_delete_codec_preset(struct hda_codec_preset_list *preset) -{ - mutex_lock(&preset_mutex); - list_del(&preset->list); - mutex_unlock(&preset_mutex); - return 0; -} -EXPORT_SYMBOL_GPL(snd_hda_delete_codec_preset); - #ifdef CONFIG_PM #define codec_in_pm(codec) ((codec)->in_pm) static void hda_power_work(struct work_struct *work); @@ -885,111 +822,6 @@ int snd_hda_bus_new(struct snd_card *card, } EXPORT_SYMBOL_GPL(snd_hda_bus_new); -#if IS_ENABLED(CONFIG_SND_HDA_GENERIC) -#define is_generic_config(codec) \ - (codec->modelname && !strcmp(codec->modelname, "generic")) -#else -#define is_generic_config(codec) 0 -#endif - -#ifdef MODULE -#define HDA_MODREQ_MAX_COUNT 2 /* two request_modules()'s */ -#else -#define HDA_MODREQ_MAX_COUNT 0 /* all presets are statically linked */ -#endif - -/* - * find a matching codec preset - */ -static const struct hda_codec_preset * -find_codec_preset(struct hda_codec *codec) -{ - struct hda_codec_preset_list *tbl; - const struct hda_codec_preset *preset; - unsigned int mod_requested = 0; - - again: - mutex_lock(&preset_mutex); - list_for_each_entry(tbl, &hda_preset_tables, list) { - if (!try_module_get(tbl->owner)) { - codec_err(codec, "cannot module_get\n"); - continue; - } - for (preset = tbl->preset; preset->id; preset++) { - u32 mask = preset->mask; - if (preset->afg && preset->afg != codec->afg) - continue; - if (preset->mfg && preset->mfg != codec->mfg) - continue; - if (!mask) - mask = ~0; - if (preset->id == (codec->vendor_id & mask) && - (!preset->rev || - preset->rev == codec->revision_id)) { - mutex_unlock(&preset_mutex); - codec->owner = tbl->owner; - return preset; - } - } - module_put(tbl->owner); - } - mutex_unlock(&preset_mutex); - - if (mod_requested < HDA_MODREQ_MAX_COUNT) { - if (!mod_requested) - request_module("snd-hda-codec-id:%08x", - codec->vendor_id); - else - request_module("snd-hda-codec-id:%04x*", - (codec->vendor_id >> 16) & 0xffff); - mod_requested++; - goto again; - } - return NULL; -} - -/* - * get_codec_name - store the codec name - */ -static int get_codec_name(struct hda_codec *codec) -{ - const struct hda_vendor_id *c; - const char *vendor = NULL; - u16 vendor_id = codec->vendor_id >> 16; - char tmp[16]; - - if (codec->vendor_name) - goto get_chip_name; - - for (c = hda_vendor_ids; c->id; c++) { - if (c->id == vendor_id) { - vendor = c->name; - break; - } - } - if (!vendor) { - sprintf(tmp, "Generic %04x", vendor_id); - vendor = tmp; - } - codec->vendor_name = kstrdup(vendor, GFP_KERNEL); - if (!codec->vendor_name) - return -ENOMEM; - - get_chip_name: - if (codec->chip_name) - return 0; - - if (codec->preset && codec->preset->name) - codec->chip_name = kstrdup(codec->preset->name, GFP_KERNEL); - else { - sprintf(tmp, "ID %x", codec->vendor_id & 0xffff); - codec->chip_name = kstrdup(tmp, GFP_KERNEL); - } - if (!codec->chip_name) - return -ENOMEM; - return 0; -} - /* * look for an AFG and MFG nodes */ @@ -1300,20 +1132,6 @@ get_hda_cvt_setup(struct hda_codec *codec, hda_nid_t nid) return p; } -/* - * Dynamic symbol binding for the codec parsers - */ - -#define load_parser(codec, sym) \ - ((codec)->parser = (int (*)(struct hda_codec *))symbol_request(sym)) - -static void unload_parser(struct hda_codec *codec) -{ - if (codec->parser) - symbol_put_addr(codec->parser); - codec->parser = NULL; -} - /* * codec destructor */ @@ -1322,6 +1140,8 @@ static void snd_hda_codec_free(struct hda_codec *codec) if (!codec) return; cancel_delayed_work_sync(&codec->jackpoll_work); + if (device_is_registered(hda_codec_dev(codec))) + device_del(hda_codec_dev(codec)); snd_hda_jack_tbl_clear(codec); free_init_pincfgs(codec); #ifdef CONFIG_PM @@ -1335,12 +1155,8 @@ static void snd_hda_codec_free(struct hda_codec *codec) snd_array_free(&codec->spdif_out); remove_conn_list(codec); codec->bus->caddr_tbl[codec->addr] = NULL; - if (codec->patch_ops.free) - codec->patch_ops.free(codec); hda_call_pm_notify(codec, false); /* cancel leftover refcounts */ snd_hda_sysfs_clear(codec); - unload_parser(codec); - module_put(codec->owner); free_hda_cache(&codec->amp_cache); free_hda_cache(&codec->cmd_cache); kfree(codec->vendor_name); @@ -1348,7 +1164,7 @@ static void snd_hda_codec_free(struct hda_codec *codec) kfree(codec->modelname); kfree(codec->wcaps); codec->bus->num_codecs--; - put_device(&codec->dev); + put_device(hda_codec_dev(codec)); } static bool snd_hda_codec_get_supported_ps(struct hda_codec *codec, @@ -1360,10 +1176,7 @@ static unsigned int hda_set_power_state(struct hda_codec *codec, static int snd_hda_codec_dev_register(struct snd_device *device) { struct hda_codec *codec = device->device_data; - int err = device_add(&codec->dev); - if (err < 0) - return err; snd_hda_register_beep_device(codec); return 0; } @@ -1373,7 +1186,6 @@ static int snd_hda_codec_dev_disconnect(struct snd_device *device) struct hda_codec *codec = device->device_data; snd_hda_detach_beep_device(codec); - device_del(&codec->dev); return 0; } @@ -1386,7 +1198,7 @@ static int snd_hda_codec_dev_free(struct snd_device *device) /* just free the container */ static void snd_hda_codec_dev_release(struct device *dev) { - kfree(container_of(dev, struct hda_codec, dev)); + kfree(dev_to_hda_codec(dev)); } /** @@ -1402,6 +1214,7 @@ int snd_hda_codec_new(struct hda_bus *bus, struct hda_codec **codecp) { struct hda_codec *codec; + struct device *dev; char component[31]; hda_nid_t fg; int err; @@ -1429,14 +1242,14 @@ int snd_hda_codec_new(struct hda_bus *bus, return -ENOMEM; } - device_initialize(&codec->dev); - codec->dev.parent = &bus->card->card_dev; - codec->dev.class = sound_class; - codec->dev.release = snd_hda_codec_dev_release; - codec->dev.groups = snd_hda_dev_attr_groups; - dev_set_name(&codec->dev, "hdaudioC%dD%d", bus->card->number, - codec_addr); - dev_set_drvdata(&codec->dev, codec); /* for sysfs */ + dev = hda_codec_dev(codec); + device_initialize(dev); + dev->parent = bus->card->dev; + dev->bus = &snd_hda_bus_type; + dev->release = snd_hda_codec_dev_release; + dev->groups = snd_hda_dev_attr_groups; + dev_set_name(dev, "hdaudioC%dD%d", bus->card->number, codec_addr); + dev_set_drvdata(dev, codec); /* for sysfs */ codec->bus = bus; codec->addr = codec_addr; @@ -1587,92 +1400,6 @@ int snd_hda_codec_update_widgets(struct hda_codec *codec) } EXPORT_SYMBOL_GPL(snd_hda_codec_update_widgets); - -#if IS_ENABLED(CONFIG_SND_HDA_CODEC_HDMI) -/* if all audio out widgets are digital, let's assume the codec as a HDMI/DP */ -static bool is_likely_hdmi_codec(struct hda_codec *codec) -{ - hda_nid_t nid = codec->start_nid; - int i; - - for (i = 0; i < codec->num_nodes; i++, nid++) { - unsigned int wcaps = get_wcaps(codec, nid); - switch (get_wcaps_type(wcaps)) { - case AC_WID_AUD_IN: - return false; /* HDMI parser supports only HDMI out */ - case AC_WID_AUD_OUT: - if (!(wcaps & AC_WCAP_DIGITAL)) - return false; - break; - } - } - return true; -} -#else -/* no HDMI codec parser support */ -#define is_likely_hdmi_codec(codec) false -#endif /* CONFIG_SND_HDA_CODEC_HDMI */ - -/** - * snd_hda_codec_configure - (Re-)configure the HD-audio codec - * @codec: the HDA codec - * - * Start parsing of the given codec tree and (re-)initialize the whole - * patch instance. - * - * Returns 0 if successful or a negative error code. - */ -int snd_hda_codec_configure(struct hda_codec *codec) -{ - int (*patch)(struct hda_codec *) = NULL; - int err; - - codec->preset = find_codec_preset(codec); - if (!codec->vendor_name || !codec->chip_name) { - err = get_codec_name(codec); - if (err < 0) - return err; - } - - if (!is_generic_config(codec) && codec->preset) - patch = codec->preset->patch; - if (!patch) { - unload_parser(codec); /* to be sure */ - if (is_likely_hdmi_codec(codec)) { -#if IS_MODULE(CONFIG_SND_HDA_CODEC_HDMI) - patch = load_parser(codec, snd_hda_parse_hdmi_codec); -#elif IS_BUILTIN(CONFIG_SND_HDA_CODEC_HDMI) - patch = snd_hda_parse_hdmi_codec; -#endif - } - if (!patch) { -#if IS_MODULE(CONFIG_SND_HDA_GENERIC) - patch = load_parser(codec, snd_hda_parse_generic_codec); -#elif IS_BUILTIN(CONFIG_SND_HDA_GENERIC) - patch = snd_hda_parse_generic_codec; -#endif - } - if (!patch) { - codec_err(codec, "No codec parser is available\n"); - return -ENODEV; - } - } - - err = patch(codec); - if (err < 0) { - unload_parser(codec); - return err; - } - - /* audio codec should override the mixer name */ - if (codec->afg || !*codec->bus->card->mixername) - snprintf(codec->bus->card->mixername, - sizeof(codec->bus->card->mixername), - "%s %s", codec->vendor_name, codec->chip_name); - return 0; -} -EXPORT_SYMBOL_GPL(snd_hda_codec_configure); - /* update the stream-id if changed */ static void update_pcm_stream_id(struct hda_codec *codec, struct hda_cvt_setup *p, hda_nid_t nid, @@ -2739,8 +2466,9 @@ int snd_hda_codec_reset(struct hda_codec *codec) } } snd_hda_detach_beep_device(codec); - if (codec->patch_ops.free) - codec->patch_ops.free(codec); + if (device_is_registered(hda_codec_dev(codec))) + device_del(hda_codec_dev(codec)); + memset(&codec->patch_ops, 0, sizeof(codec->patch_ops)); snd_hda_jack_tbl_clear(codec); codec->proc_widget_hook = NULL; @@ -2759,9 +2487,6 @@ int snd_hda_codec_reset(struct hda_codec *codec) codec->preset = NULL; codec->slave_dig_outs = NULL; codec->spdif_status_reset = 0; - unload_parser(codec); - module_put(codec->owner); - codec->owner = NULL; /* allow device access again */ snd_hda_unlock_devices(bus); diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index 96421a3b32cd..3d42717e0e65 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h @@ -174,15 +174,22 @@ struct hda_codec_preset { int (*patch)(struct hda_codec *codec); }; -struct hda_codec_preset_list { +#define HDA_CODEC_ID_GENERIC_HDMI 0x00000101 +#define HDA_CODEC_ID_GENERIC 0x00000201 + +struct hda_codec_driver { + struct device_driver driver; const struct hda_codec_preset *preset; - struct module *owner; - struct list_head list; }; -/* initial hook */ -int snd_hda_add_codec_preset(struct hda_codec_preset_list *preset); -int snd_hda_delete_codec_preset(struct hda_codec_preset_list *preset); +int __hda_codec_driver_register(struct hda_codec_driver *drv, const char *name, + struct module *owner); +#define hda_codec_driver_register(drv) \ + __hda_codec_driver_register(drv, KBUILD_MODNAME, THIS_MODULE) +void hda_codec_driver_unregister(struct hda_codec_driver *drv); +#define module_hda_codec_driver(drv) \ + module_driver(drv, hda_codec_driver_register, \ + hda_codec_driver_unregister) /* ops set by the preset patch */ struct hda_codec_ops { @@ -286,11 +293,10 @@ struct hda_codec { u32 vendor_id; u32 subsystem_id; u32 revision_id; + u32 probe_id; /* overridden id for probing */ /* detected preset */ const struct hda_codec_preset *preset; - struct module *owner; - int (*parser)(struct hda_codec *codec); const char *vendor_name; /* codec vendor name */ const char *chip_name; /* codec chip name */ const char *modelname; /* model name for preset */ @@ -408,6 +414,11 @@ struct hda_codec { struct snd_array verbs; }; +#define dev_to_hda_codec(_dev) container_of(_dev, struct hda_codec, dev) +#define hda_codec_dev(_dev) (&(_dev)->dev) + +extern struct bus_type snd_hda_bus_type; + /* direction */ enum { HDA_INPUT, HDA_OUTPUT diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c index b680b4ec6331..947d1a50f384 100644 --- a/sound/pci/hda/hda_generic.c +++ b/sound/pci/hda/hda_generic.c @@ -5493,13 +5493,11 @@ static const struct hda_codec_ops generic_patch_ops = { #endif }; -/** +/* * snd_hda_parse_generic_codec - Generic codec parser * @codec: the HDA codec - * - * This should be called from the HDA codec core. */ -int snd_hda_parse_generic_codec(struct hda_codec *codec) +static int snd_hda_parse_generic_codec(struct hda_codec *codec) { struct hda_gen_spec *spec; int err; @@ -5525,7 +5523,17 @@ error: snd_hda_gen_free(codec); return err; } -EXPORT_SYMBOL_GPL(snd_hda_parse_generic_codec); + +static const struct hda_codec_preset snd_hda_preset_generic[] = { + { .id = HDA_CODEC_ID_GENERIC, .patch = snd_hda_parse_generic_codec }, + {} /* terminator */ +}; + +static struct hda_codec_driver generic_driver = { + .preset = snd_hda_preset_generic, +}; + +module_hda_codec_driver(generic_driver); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Generic HD-audio codec parser"); diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h index 49c08a7278c4..2f7d9646a41d 100644 --- a/sound/pci/hda/hda_local.h +++ b/sound/pci/hda/hda_local.h @@ -350,12 +350,6 @@ int snd_hda_multi_out_analog_prepare(struct hda_codec *codec, int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec, struct hda_multi_out *mout); -/* - * generic codec parser - */ -int snd_hda_parse_generic_codec(struct hda_codec *codec); -int snd_hda_parse_hdmi_codec(struct hda_codec *codec); - /* * generic proc interface */ @@ -783,9 +777,13 @@ void snd_print_channel_allocation(int spk_alloc, char *buf, int buflen); /* */ -#define codec_err(codec, fmt, args...) dev_err(&(codec)->dev, fmt, ##args) -#define codec_warn(codec, fmt, args...) dev_warn(&(codec)->dev, fmt, ##args) -#define codec_info(codec, fmt, args...) dev_info(&(codec)->dev, fmt, ##args) -#define codec_dbg(codec, fmt, args...) dev_dbg(&(codec)->dev, fmt, ##args) +#define codec_err(codec, fmt, args...) \ + dev_err(hda_codec_dev(codec), fmt, ##args) +#define codec_warn(codec, fmt, args...) \ + dev_warn(hda_codec_dev(codec), fmt, ##args) +#define codec_info(codec, fmt, args...) \ + dev_info(hda_codec_dev(codec), fmt, ##args) +#define codec_dbg(codec, fmt, args...) \ + dev_dbg(hda_codec_dev(codec), fmt, ##args) #endif /* __SOUND_HDA_LOCAL_H */ diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c index d285904cdb64..af4c7be86c27 100644 --- a/sound/pci/hda/patch_analog.c +++ b/sound/pci/hda/patch_analog.c @@ -1194,20 +1194,8 @@ MODULE_ALIAS("snd-hda-codec-id:11d4*"); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Analog Devices HD-audio codec"); -static struct hda_codec_preset_list analog_list = { +static struct hda_codec_driver analog_driver = { .preset = snd_hda_preset_analog, - .owner = THIS_MODULE, }; -static int __init patch_analog_init(void) -{ - return snd_hda_add_codec_preset(&analog_list); -} - -static void __exit patch_analog_exit(void) -{ - snd_hda_delete_codec_preset(&analog_list); -} - -module_init(patch_analog_init) -module_exit(patch_analog_exit) +module_hda_codec_driver(analog_driver); 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"); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Creative CA0110-IBG HD-audio codec"); -static struct hda_codec_preset_list ca0110_list = { +static struct hda_codec_driver ca0110_driver = { .preset = snd_hda_preset_ca0110, - .owner = THIS_MODULE, }; -static int __init patch_ca0110_init(void) -{ - return snd_hda_add_codec_preset(&ca0110_list); -} - -static void __exit patch_ca0110_exit(void) -{ - snd_hda_delete_codec_preset(&ca0110_list); -} - -module_init(patch_ca0110_init) -module_exit(patch_ca0110_exit) +module_hda_codec_driver(ca0110_driver); diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c index e0383eea9880..81991b4134cd 100644 --- a/sound/pci/hda/patch_ca0132.c +++ b/sound/pci/hda/patch_ca0132.c @@ -4702,20 +4702,8 @@ MODULE_ALIAS("snd-hda-codec-id:11020011"); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Creative Sound Core3D codec"); -static struct hda_codec_preset_list ca0132_list = { +static struct hda_codec_driver ca0132_driver = { .preset = snd_hda_preset_ca0132, - .owner = THIS_MODULE, }; -static int __init patch_ca0132_init(void) -{ - return snd_hda_add_codec_preset(&ca0132_list); -} - -static void __exit patch_ca0132_exit(void) -{ - snd_hda_delete_codec_preset(&ca0132_list); -} - -module_init(patch_ca0132_init) -module_exit(patch_ca0132_exit) +module_hda_codec_driver(ca0132_driver); diff --git a/sound/pci/hda/patch_cirrus.c b/sound/pci/hda/patch_cirrus.c index 1589c9bcce3e..1af133933bc0 100644 --- a/sound/pci/hda/patch_cirrus.c +++ b/sound/pci/hda/patch_cirrus.c @@ -1219,20 +1219,8 @@ MODULE_ALIAS("snd-hda-codec-id:10134213"); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Cirrus Logic HD-audio codec"); -static struct hda_codec_preset_list cirrus_list = { +static struct hda_codec_driver cirrus_driver = { .preset = snd_hda_preset_cirrus, - .owner = THIS_MODULE, }; -static int __init patch_cirrus_init(void) -{ - return snd_hda_add_codec_preset(&cirrus_list); -} - -static void __exit patch_cirrus_exit(void) -{ - snd_hda_delete_codec_preset(&cirrus_list); -} - -module_init(patch_cirrus_init) -module_exit(patch_cirrus_exit) +module_hda_codec_driver(cirrus_driver); 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"); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("C-Media HD-audio codec"); -static struct hda_codec_preset_list cmedia_list = { +static struct hda_codec_driver cmedia_driver = { .preset = snd_hda_preset_cmedia, - .owner = THIS_MODULE, }; -static int __init patch_cmedia_init(void) -{ - return snd_hda_add_codec_preset(&cmedia_list); -} - -static void __exit patch_cmedia_exit(void) -{ - snd_hda_delete_codec_preset(&cmedia_list); -} - -module_init(patch_cmedia_init) -module_exit(patch_cmedia_exit) +module_hda_codec_driver(cmedia_driver); diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c index fd3ed18670e9..15a0a7d38c35 100644 --- a/sound/pci/hda/patch_conexant.c +++ b/sound/pci/hda/patch_conexant.c @@ -1007,20 +1007,8 @@ MODULE_ALIAS("snd-hda-codec-id:14f151d7"); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Conexant HD-audio codec"); -static struct hda_codec_preset_list conexant_list = { +static struct hda_codec_driver conexant_driver = { .preset = snd_hda_preset_conexant, - .owner = THIS_MODULE, }; -static int __init patch_conexant_init(void) -{ - return snd_hda_add_codec_preset(&conexant_list); -} - -static void __exit patch_conexant_exit(void) -{ - snd_hda_delete_codec_preset(&conexant_list); -} - -module_init(patch_conexant_init) -module_exit(patch_conexant_exit) +module_hda_codec_driver(conexant_driver); diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c index b422e406a9cb..f1812aabd63e 100644 --- a/sound/pci/hda/patch_hdmi.c +++ b/sound/pci/hda/patch_hdmi.c @@ -3300,15 +3300,6 @@ static int patch_via_hdmi(struct hda_codec *codec) return patch_simple_hdmi(codec, VIAHDMI_CVT_NID, VIAHDMI_PIN_NID); } -/* - * called from hda_codec.c for generic HDMI support - */ -int snd_hda_parse_hdmi_codec(struct hda_codec *codec) -{ - return patch_generic_hdmi(codec); -} -EXPORT_SYMBOL_GPL(snd_hda_parse_hdmi_codec); - /* * patch entries */ @@ -3373,6 +3364,8 @@ static const struct hda_codec_preset snd_hda_preset_hdmi[] = { { .id = 0x80862882, .name = "Valleyview2 HDMI", .patch = patch_generic_hdmi }, { .id = 0x80862883, .name = "Braswell HDMI", .patch = patch_generic_hdmi }, { .id = 0x808629fb, .name = "Crestline HDMI", .patch = patch_generic_hdmi }, +/* special ID for generic HDMI */ +{ .id = HDA_CODEC_ID_GENERIC_HDMI, .patch = patch_generic_hdmi }, {} /* terminator */ }; @@ -3442,20 +3435,8 @@ MODULE_ALIAS("snd-hda-codec-intelhdmi"); MODULE_ALIAS("snd-hda-codec-nvhdmi"); MODULE_ALIAS("snd-hda-codec-atihdmi"); -static struct hda_codec_preset_list intel_list = { +static struct hda_codec_driver hdmi_driver = { .preset = snd_hda_preset_hdmi, - .owner = THIS_MODULE, }; -static int __init patch_hdmi_init(void) -{ - return snd_hda_add_codec_preset(&intel_list); -} - -static void __exit patch_hdmi_exit(void) -{ - snd_hda_delete_codec_preset(&intel_list); -} - -module_init(patch_hdmi_init) -module_exit(patch_hdmi_exit) +module_hda_codec_driver(hdmi_driver); diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c index b2b24a8b3dac..70808f92276a 100644 --- a/sound/pci/hda/patch_realtek.c +++ b/sound/pci/hda/patch_realtek.c @@ -6514,20 +6514,8 @@ MODULE_ALIAS("snd-hda-codec-id:10ec*"); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Realtek HD-audio codec"); -static struct hda_codec_preset_list realtek_list = { +static struct hda_codec_driver realtek_driver = { .preset = snd_hda_preset_realtek, - .owner = THIS_MODULE, }; -static int __init patch_realtek_init(void) -{ - return snd_hda_add_codec_preset(&realtek_list); -} - -static void __exit patch_realtek_exit(void) -{ - snd_hda_delete_codec_preset(&realtek_list); -} - -module_init(patch_realtek_init) -module_exit(patch_realtek_exit) +module_hda_codec_driver(realtek_driver); diff --git a/sound/pci/hda/patch_si3054.c b/sound/pci/hda/patch_si3054.c index 3208ad69583e..38a477333321 100644 --- a/sound/pci/hda/patch_si3054.c +++ b/sound/pci/hda/patch_si3054.c @@ -319,20 +319,8 @@ MODULE_ALIAS("snd-hda-codec-id:18540018"); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Si3054 HD-audio modem codec"); -static struct hda_codec_preset_list si3054_list = { +static struct hda_codec_driver si3054_driver = { .preset = snd_hda_preset_si3054, - .owner = THIS_MODULE, }; -static int __init patch_si3054_init(void) -{ - return snd_hda_add_codec_preset(&si3054_list); -} - -static void __exit patch_si3054_exit(void) -{ - snd_hda_delete_codec_preset(&si3054_list); -} - -module_init(patch_si3054_init) -module_exit(patch_si3054_exit) +module_hda_codec_driver(si3054_driver); diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c index 87eff3173ce9..6a2163056216 100644 --- a/sound/pci/hda/patch_sigmatel.c +++ b/sound/pci/hda/patch_sigmatel.c @@ -5091,20 +5091,8 @@ MODULE_ALIAS("snd-hda-codec-id:111d*"); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec"); -static struct hda_codec_preset_list sigmatel_list = { +static struct hda_codec_driver sigmatel_driver = { .preset = snd_hda_preset_sigmatel, - .owner = THIS_MODULE, }; -static int __init patch_sigmatel_init(void) -{ - return snd_hda_add_codec_preset(&sigmatel_list); -} - -static void __exit patch_sigmatel_exit(void) -{ - snd_hda_delete_codec_preset(&sigmatel_list); -} - -module_init(patch_sigmatel_init) -module_exit(patch_sigmatel_exit) +module_hda_codec_driver(sigmatel_driver); diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 3de6d3d779c9..2045f33b1ace 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -1884,23 +1884,11 @@ static const struct hda_codec_preset snd_hda_preset_via[] = { MODULE_ALIAS("snd-hda-codec-id:1106*"); -static struct hda_codec_preset_list via_list = { +static struct hda_codec_driver via_driver = { .preset = snd_hda_preset_via, - .owner = THIS_MODULE, }; MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("VIA HD-audio codec"); -static int __init patch_via_init(void) -{ - return snd_hda_add_codec_preset(&via_list); -} - -static void __exit patch_via_exit(void) -{ - snd_hda_delete_codec_preset(&via_list); -} - -module_init(patch_via_init) -module_exit(patch_via_exit) +module_hda_codec_driver(via_driver); -- cgit v1.2.3 From 59ed1eade1d6ec24751baca99305f9713a5d779e Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Wed, 18 Feb 2015 15:39:59 +0100 Subject: ALSA: hda - Move codec suspend/resume to codec driver This patch moves the suspend/resume mechanisms down to each codec driver level, as we have a proper codec driver bound on the bus now. Then we get the asynchronous PM gratis without fiddling much in the driver level. As a soft-landing transition, implement the common suspend/resume pm ops for hda_codec_driver and keep the each codec driver intact. Only the callers of suspend/resume in the controller side (azx_suspend() and azx_resume()) are removed. Another involved place is azx_bus_reset() calling the temporary suspend and resume as a hackish method of bus reset. The HD-audio core provide a helper function snd_hda_bus_reset() instead. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_bind.c | 3 +- sound/pci/hda/hda_codec.c | 93 +++++++++++++++--------------------------- sound/pci/hda/hda_codec.h | 6 +-- sound/pci/hda/hda_controller.c | 11 +---- sound/pci/hda/hda_intel.c | 6 --- sound/pci/hda/hda_tegra.c | 6 --- 6 files changed, 39 insertions(+), 86 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_bind.c b/sound/pci/hda/hda_bind.c index adf6b475dee1..ce2dd7b0dc07 100644 --- a/sound/pci/hda/hda_bind.c +++ b/sound/pci/hda/hda_bind.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "hda_codec.h" #include "hda_local.h" @@ -138,7 +139,7 @@ int __hda_codec_driver_register(struct hda_codec_driver *drv, const char *name, drv->driver.bus = &snd_hda_bus_type; drv->driver.probe = hda_codec_driver_probe; drv->driver.remove = hda_codec_driver_remove; - /* TODO: PM and others */ + drv->driver.pm = &hda_codec_driver_pm; return driver_register(&drv->driver); } EXPORT_SYMBOL_GPL(__hda_codec_driver_register); diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 61c8174e8013..3d6ff60e6c14 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -1250,6 +1250,7 @@ int snd_hda_codec_new(struct hda_bus *bus, dev->groups = snd_hda_dev_attr_groups; dev_set_name(dev, "hdaudioC%dD%d", bus->card->number, codec_addr); dev_set_drvdata(dev, codec); /* for sysfs */ + device_enable_async_suspend(dev); codec->bus = bus; codec->addr = codec_addr; @@ -3970,8 +3971,31 @@ static void hda_call_codec_resume(struct hda_codec *codec) codec->in_pm = 0; snd_hda_power_down(codec); /* flag down before returning */ } + +static int hda_codec_driver_suspend(struct device *dev) +{ + struct hda_codec *codec = dev_to_hda_codec(dev); + int i; + + cancel_delayed_work_sync(&codec->jackpoll_work); + for (i = 0; i < codec->num_pcms; i++) + snd_pcm_suspend_all(codec->pcm_info[i].pcm); + hda_call_codec_suspend(codec, false); + return 0; +} + +static int hda_codec_driver_resume(struct device *dev) +{ + hda_call_codec_resume(dev_to_hda_codec(dev)); + return 0; +} #endif /* CONFIG_PM */ +/* referred in hda_bind.c */ +const struct dev_pm_ops hda_codec_driver_pm = { + SET_SYSTEM_SLEEP_PM_OPS(hda_codec_driver_suspend, + hda_codec_driver_resume) +}; /** * snd_hda_build_controls - build mixer controls @@ -5505,77 +5529,26 @@ int snd_hda_add_imux_item(struct hda_codec *codec, } EXPORT_SYMBOL_GPL(snd_hda_add_imux_item); - -#ifdef CONFIG_PM -/* - * power management - */ - - -static void hda_async_suspend(void *data, async_cookie_t cookie) -{ - hda_call_codec_suspend(data, false); -} - -static void hda_async_resume(void *data, async_cookie_t cookie) -{ - hda_call_codec_resume(data); -} - /** - * snd_hda_suspend - suspend the codecs - * @bus: the HDA bus - * - * Returns 0 if successful. + * snd_hda_bus_reset - Reset the bus + * @bus: HD-audio bus */ -int snd_hda_suspend(struct hda_bus *bus) +void snd_hda_bus_reset(struct hda_bus *bus) { struct hda_codec *codec; - ASYNC_DOMAIN_EXCLUSIVE(domain); list_for_each_entry(codec, &bus->codec_list, list) { + /* FIXME: maybe a better way needed for forced reset */ cancel_delayed_work_sync(&codec->jackpoll_work); +#ifdef CONFIG_PM if (hda_codec_is_power_on(codec)) { - if (bus->num_codecs > 1) - async_schedule_domain(hda_async_suspend, codec, - &domain); - else - hda_call_codec_suspend(codec, false); - } - } - - if (bus->num_codecs > 1) - async_synchronize_full_domain(&domain); - - return 0; -} -EXPORT_SYMBOL_GPL(snd_hda_suspend); - -/** - * snd_hda_resume - resume the codecs - * @bus: the HDA bus - * - * Returns 0 if successful. - */ -int snd_hda_resume(struct hda_bus *bus) -{ - struct hda_codec *codec; - ASYNC_DOMAIN_EXCLUSIVE(domain); - - list_for_each_entry(codec, &bus->codec_list, list) { - if (bus->num_codecs > 1) - async_schedule_domain(hda_async_resume, codec, &domain); - else + hda_call_codec_suspend(codec, false); hda_call_codec_resume(codec); + } +#endif } - - if (bus->num_codecs > 1) - async_synchronize_full_domain(&domain); - - return 0; } -EXPORT_SYMBOL_GPL(snd_hda_resume); -#endif /* CONFIG_PM */ +EXPORT_SYMBOL_GPL(snd_hda_bus_reset); /* * generic arrays diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index 3d42717e0e65..1fa3dd9baf52 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h @@ -567,14 +567,12 @@ void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg, int snd_hda_lock_devices(struct hda_bus *bus); void snd_hda_unlock_devices(struct hda_bus *bus); +void snd_hda_bus_reset(struct hda_bus *bus); /* * power management */ -#ifdef CONFIG_PM -int snd_hda_suspend(struct hda_bus *bus); -int snd_hda_resume(struct hda_bus *bus); -#endif +extern const struct dev_pm_ops hda_codec_driver_pm; static inline int hda_call_check_power_status(struct hda_codec *codec, hda_nid_t nid) diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c index 4c7a6f9bfcde..30ddb751806a 100644 --- a/sound/pci/hda/hda_controller.c +++ b/sound/pci/hda/hda_controller.c @@ -1780,15 +1780,8 @@ static void azx_bus_reset(struct hda_bus *bus) bus->in_reset = 1; azx_stop_chip(chip); azx_init_chip(chip, true); -#ifdef CONFIG_PM - if (chip->initialized) { - struct azx_pcm *p; - list_for_each_entry(p, &chip->pcm_list, list) - snd_pcm_suspend_all(p->pcm); - snd_hda_suspend(chip->bus); - snd_hda_resume(chip->bus); - } -#endif + if (chip->initialized) + snd_hda_bus_reset(chip->bus); bus->in_reset = 0; } diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index 5e00cc4a722f..9db1b078801f 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c @@ -772,7 +772,6 @@ static int azx_suspend(struct device *dev) struct snd_card *card = dev_get_drvdata(dev); struct azx *chip; struct hda_intel *hda; - struct azx_pcm *p; if (!card) return 0; @@ -784,10 +783,6 @@ static int azx_suspend(struct device *dev) snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); azx_clear_irq_pending(chip); - list_for_each_entry(p, &chip->pcm_list, list) - snd_pcm_suspend_all(p->pcm); - if (chip->initialized) - snd_hda_suspend(chip->bus); azx_stop_chip(chip); azx_enter_link_reset(chip); if (chip->irq >= 0) { @@ -830,7 +825,6 @@ static int azx_resume(struct device *dev) azx_init_chip(chip, true); - snd_hda_resume(chip->bus); snd_power_change_state(card, SNDRV_CTL_POWER_D0); return 0; } diff --git a/sound/pci/hda/hda_tegra.c b/sound/pci/hda/hda_tegra.c index 1bd7a9e04046..f6949e413a50 100644 --- a/sound/pci/hda/hda_tegra.c +++ b/sound/pci/hda/hda_tegra.c @@ -249,14 +249,9 @@ static int hda_tegra_suspend(struct device *dev) { struct snd_card *card = dev_get_drvdata(dev); struct azx *chip = card->private_data; - struct azx_pcm *p; struct hda_tegra *hda = container_of(chip, struct hda_tegra, chip); snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); - list_for_each_entry(p, &chip->pcm_list, list) - snd_pcm_suspend_all(p->pcm); - if (chip->initialized) - snd_hda_suspend(chip->bus); azx_stop_chip(chip); azx_enter_link_reset(chip); @@ -277,7 +272,6 @@ static int hda_tegra_resume(struct device *dev) azx_init_chip(chip, 1); - snd_hda_resume(chip->bus); snd_power_change_state(card, SNDRV_CTL_POWER_D0); return 0; -- cgit v1.2.3 From cc72da7d4d063ab9e690e56e0ef1ca1c24ee1635 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 19 Feb 2015 16:00:22 +0100 Subject: ALSA: hda - Use standard runtime PM for codec power-save control Like the previous transition of suspend/resume, now move the power-save code to the standard runtime PM. As usual for runtime PM, it's a bit tricky, but this simplified codes a lot in the end. For keeping the usage compatibility, power_save module option still controls the whole power-saving behavior on all codecs. The value is translated to pm_runtime_*_autosuspend() and pm_runtime_allow() / pm_runtime_forbid() calls. snd_hda_power_up() and snd_hda_power_down() are translated to pm_runtime_get_sync() and pm_runtime_put_autosuspend(), respectively. Since we can do call pm_runtime_get_sync() more reliably, the sync version is used always and snd_hda_power_up_d3wait() is dropped. Another slight difference is that snd_hda_power_up()/down() don't call runtime_pm code during the suspend/resume transition phase. Calling them there isn't safe unlike our own code, resulted in unexpected behavior (endless wakeups). The hda_power_count tracepoint was removed, as it doesn't match well with the new code. Last but not least, we need to set ignore_children flag in the parent dev.power field so that the runtime PM of the controller chip won't get confused. The notification is still done in the bus pm_notify callback. We'll get rid of this hack in the later patch. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_codec.c | 241 ++++++++++++++++------------------------- sound/pci/hda/hda_codec.h | 67 ++---------- sound/pci/hda/hda_controller.c | 2 +- sound/pci/hda/hda_intel.c | 2 + sound/pci/hda/hda_trace.h | 24 ---- 5 files changed, 106 insertions(+), 230 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 3d6ff60e6c14..d0dbc62c9147 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include #include "hda_codec.h" #include @@ -41,10 +43,9 @@ #include "hda_trace.h" #ifdef CONFIG_PM -#define codec_in_pm(codec) ((codec)->in_pm) -static void hda_power_work(struct work_struct *work); -static void hda_keep_power_on(struct hda_codec *codec); -#define hda_codec_is_power_on(codec) ((codec)->power_on) +#define codec_in_pm(codec) atomic_read(&(codec)->in_pm) +#define hda_codec_is_power_on(codec) \ + (!pm_runtime_suspended(hda_codec_dev(codec))) static void hda_call_pm_notify(struct hda_codec *codec, bool power_up) { @@ -60,7 +61,6 @@ static void hda_call_pm_notify(struct hda_codec *codec, bool power_up) #else #define codec_in_pm(codec) 0 -static inline void hda_keep_power_on(struct hda_codec *codec) {} #define hda_codec_is_power_on(codec) 1 #define hda_call_pm_notify(codec, state) {} #endif @@ -1144,10 +1144,7 @@ static void snd_hda_codec_free(struct hda_codec *codec) device_del(hda_codec_dev(codec)); snd_hda_jack_tbl_clear(codec); free_init_pincfgs(codec); -#ifdef CONFIG_PM - cancel_delayed_work(&codec->power_work); flush_workqueue(codec->bus->workq); -#endif list_del(&codec->list); snd_array_free(&codec->mixers); snd_array_free(&codec->nids); @@ -1178,6 +1175,10 @@ static int snd_hda_codec_dev_register(struct snd_device *device) struct hda_codec *codec = device->device_data; snd_hda_register_beep_device(codec); + if (device_is_registered(hda_codec_dev(codec))) { + snd_hda_power_sync(codec); + pm_runtime_enable(hda_codec_dev(codec)); + } return 0; } @@ -1274,13 +1275,14 @@ int snd_hda_codec_new(struct hda_bus *bus, codec->fixup_id = HDA_FIXUP_ID_NOT_SET; #ifdef CONFIG_PM - spin_lock_init(&codec->power_lock); - INIT_DELAYED_WORK(&codec->power_work, hda_power_work); /* snd_hda_codec_new() marks the codec as power-up, and leave it as is. * the caller has to power down appropriatley after initialization * phase. */ - hda_keep_power_on(codec); + pm_runtime_set_active(hda_codec_dev(codec)); + pm_runtime_get_noresume(hda_codec_dev(codec)); + codec->power_jiffies = jiffies; + hda_call_pm_notify(codec, true); #endif snd_hda_sysfs_init(codec); @@ -2453,10 +2455,7 @@ int snd_hda_codec_reset(struct hda_codec *codec) /* OK, let it free */ cancel_delayed_work_sync(&codec->jackpoll_work); -#ifdef CONFIG_PM - cancel_delayed_work_sync(&codec->power_work); flush_workqueue(bus->workq); -#endif snd_hda_ctls_clear(codec); /* release PCMs */ for (i = 0; i < codec->num_pcms; i++) { @@ -3893,31 +3892,40 @@ static inline void hda_exec_init_verbs(struct hda_codec *codec) {} #endif #ifdef CONFIG_PM +/* update the power on/off account with the current jiffies */ +static void update_power_acct(struct hda_codec *codec, bool on) +{ + unsigned long delta = jiffies - codec->power_jiffies; + + if (on) + codec->power_on_acct += delta; + else + codec->power_off_acct += delta; + codec->power_jiffies += delta; +} + +void snd_hda_update_power_acct(struct hda_codec *codec) +{ + update_power_acct(codec, hda_codec_is_power_on(codec)); +} + /* * call suspend and power-down; used both from PM and power-save * this function returns the power state in the end */ -static unsigned int hda_call_codec_suspend(struct hda_codec *codec, bool in_wq) +static unsigned int hda_call_codec_suspend(struct hda_codec *codec) { unsigned int state; - codec->in_pm = 1; + atomic_inc(&codec->in_pm); if (codec->patch_ops.suspend) codec->patch_ops.suspend(codec); hda_cleanup_all_streams(codec); state = hda_set_power_state(codec, AC_PWRST_D3); - /* Cancel delayed work if we aren't currently running from it. */ - if (!in_wq) - cancel_delayed_work_sync(&codec->power_work); - spin_lock(&codec->power_lock); - snd_hda_update_power_acct(codec); trace_hda_power_down(codec); - codec->power_on = 0; - codec->power_transition = 0; - codec->power_jiffies = jiffies; - spin_unlock(&codec->power_lock); - codec->in_pm = 0; + update_power_acct(codec, true); + atomic_dec(&codec->in_pm); return state; } @@ -3942,14 +3950,14 @@ static void hda_mark_cmd_cache_dirty(struct hda_codec *codec) */ static void hda_call_codec_resume(struct hda_codec *codec) { - codec->in_pm = 1; + atomic_inc(&codec->in_pm); + trace_hda_power_up(codec); hda_mark_cmd_cache_dirty(codec); - /* set as if powered on for avoiding re-entering the resume - * in the resume / power-save sequence - */ - hda_keep_power_on(codec); + codec->power_jiffies = jiffies; + hda_call_pm_notify(codec, true); + hda_set_power_state(codec, AC_PWRST_D0); restore_shutup_pins(codec); hda_exec_init_verbs(codec); @@ -3967,34 +3975,38 @@ static void hda_call_codec_resume(struct hda_codec *codec) hda_jackpoll_work(&codec->jackpoll_work.work); else snd_hda_jack_report_sync(codec); - - codec->in_pm = 0; - snd_hda_power_down(codec); /* flag down before returning */ + atomic_dec(&codec->in_pm); } -static int hda_codec_driver_suspend(struct device *dev) +static int hda_codec_runtime_suspend(struct device *dev) { struct hda_codec *codec = dev_to_hda_codec(dev); + unsigned int state; int i; cancel_delayed_work_sync(&codec->jackpoll_work); for (i = 0; i < codec->num_pcms; i++) snd_pcm_suspend_all(codec->pcm_info[i].pcm); - hda_call_codec_suspend(codec, false); + state = hda_call_codec_suspend(codec); + if (!codec->bus->power_keep_link_on && (state & AC_PWRST_CLK_STOP_OK)) + hda_call_pm_notify(codec, false); return 0; } -static int hda_codec_driver_resume(struct device *dev) +static int hda_codec_runtime_resume(struct device *dev) { hda_call_codec_resume(dev_to_hda_codec(dev)); + pm_runtime_mark_last_busy(dev); return 0; } #endif /* CONFIG_PM */ /* referred in hda_bind.c */ const struct dev_pm_ops hda_codec_driver_pm = { - SET_SYSTEM_SLEEP_PM_OPS(hda_codec_driver_suspend, - hda_codec_driver_resume) + SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, + pm_runtime_force_resume) + SET_RUNTIME_PM_OPS(hda_codec_runtime_suspend, hda_codec_runtime_resume, + NULL) }; /** @@ -4733,127 +4745,66 @@ int snd_hda_add_new_ctls(struct hda_codec *codec, EXPORT_SYMBOL_GPL(snd_hda_add_new_ctls); #ifdef CONFIG_PM -static void hda_power_work(struct work_struct *work) +/** + * snd_hda_power_up - Power-up the codec + * @codec: HD-audio codec + * + * Increment the usage counter and resume the device if not done yet. + */ +void snd_hda_power_up(struct hda_codec *codec) { - struct hda_codec *codec = - container_of(work, struct hda_codec, power_work.work); - struct hda_bus *bus = codec->bus; - unsigned int state; + struct device *dev = hda_codec_dev(codec); - spin_lock(&codec->power_lock); - if (codec->power_transition > 0) { /* during power-up sequence? */ - spin_unlock(&codec->power_lock); + if (codec_in_pm(codec)) return; - } - if (!codec->power_on || codec->power_count) { - codec->power_transition = 0; - spin_unlock(&codec->power_lock); - return; - } - spin_unlock(&codec->power_lock); - - state = hda_call_codec_suspend(codec, true); - if (!bus->power_keep_link_on && (state & AC_PWRST_CLK_STOP_OK)) - hda_call_pm_notify(codec, false); + pm_runtime_get_sync(dev); } +EXPORT_SYMBOL_GPL(snd_hda_power_up); -static void hda_keep_power_on(struct hda_codec *codec) +/** + * snd_hda_power_down - Power-down the codec + * @codec: HD-audio codec + * + * Decrement the usage counter and schedules the autosuspend if none used. + */ +void snd_hda_power_down(struct hda_codec *codec) { - spin_lock(&codec->power_lock); - codec->power_count++; - codec->power_on = 1; - codec->power_jiffies = jiffies; - spin_unlock(&codec->power_lock); - hda_call_pm_notify(codec, true); -} + struct device *dev = hda_codec_dev(codec); -/* update the power on/off account with the current jiffies */ -void snd_hda_update_power_acct(struct hda_codec *codec) -{ - unsigned long delta = jiffies - codec->power_jiffies; - if (codec->power_on) - codec->power_on_acct += delta; - else - codec->power_off_acct += delta; - codec->power_jiffies += delta; -} - -/* Transition to powered up, if wait_power_down then wait for a pending - * transition to D3 to complete. A pending D3 transition is indicated - * with power_transition == -1. */ -/* call this with codec->power_lock held! */ -static void __snd_hda_power_up(struct hda_codec *codec, bool wait_power_down) -{ - /* Return if power_on or transitioning to power_on, unless currently - * powering down. */ - if ((codec->power_on || codec->power_transition > 0) && - !(wait_power_down && codec->power_transition < 0)) + if (codec_in_pm(codec)) return; - spin_unlock(&codec->power_lock); - - cancel_delayed_work_sync(&codec->power_work); - - spin_lock(&codec->power_lock); - /* If the power down delayed work was cancelled above before starting, - * then there is no need to go through power up here. - */ - if (codec->power_on) { - if (codec->power_transition < 0) - codec->power_transition = 0; - return; - } - - trace_hda_power_up(codec); - snd_hda_update_power_acct(codec); - codec->power_on = 1; - codec->power_jiffies = jiffies; - codec->power_transition = 1; /* avoid reentrance */ - spin_unlock(&codec->power_lock); - - hda_call_codec_resume(codec); - - spin_lock(&codec->power_lock); - codec->power_transition = 0; -} - -#define power_save(codec) \ - ((codec)->bus->power_save ? *(codec)->bus->power_save : 0) - -/* Transition to powered down */ -static void __snd_hda_power_down(struct hda_codec *codec) -{ - if (!codec->power_on || codec->power_count || codec->power_transition) - return; - - if (power_save(codec)) { - codec->power_transition = -1; /* avoid reentrance */ - queue_delayed_work(codec->bus->workq, &codec->power_work, - msecs_to_jiffies(power_save(codec) * 1000)); - } + pm_runtime_mark_last_busy(dev); + pm_runtime_put_autosuspend(dev); } +EXPORT_SYMBOL_GPL(snd_hda_power_down); /** - * snd_hda_power_save - Power-up/down/sync the codec + * snd_hda_power_sync - Synchronize the power_save option * @codec: HD-audio codec - * @delta: the counter delta to change - * @d3wait: sync for D3 transition complete * - * Change the power-up counter via @delta, and power up or down the hardware - * appropriately. For the power-down, queue to the delayed action. - * Passing zero to @delta means to synchronize the power state. + * Synchronize the runtime PM autosuspend state from the power_save option. */ -void snd_hda_power_save(struct hda_codec *codec, int delta, bool d3wait) +void snd_hda_power_sync(struct hda_codec *codec) { - spin_lock(&codec->power_lock); - codec->power_count += delta; - trace_hda_power_count(codec); - if (delta > 0) - __snd_hda_power_up(codec, d3wait); - else - __snd_hda_power_down(codec); - spin_unlock(&codec->power_lock); + struct device *dev = hda_codec_dev(codec); + int delay; + + if (!codec->bus->power_save) + return; + + delay = *codec->bus->power_save * 1000; + if (delay > 0) { + pm_runtime_set_autosuspend_delay(dev, delay); + pm_runtime_use_autosuspend(dev); + pm_runtime_allow(dev); + if (!pm_runtime_suspended(dev)) + pm_runtime_mark_last_busy(dev); + } else { + pm_runtime_dont_use_autosuspend(dev); + pm_runtime_forbid(dev); + } } -EXPORT_SYMBOL_GPL(snd_hda_power_save); +EXPORT_SYMBOL_GPL(snd_hda_power_sync); /** * snd_hda_check_amp_list_power - Check the amp list and update the power @@ -5542,7 +5493,7 @@ void snd_hda_bus_reset(struct hda_bus *bus) cancel_delayed_work_sync(&codec->jackpoll_work); #ifdef CONFIG_PM if (hda_codec_is_power_on(codec)) { - hda_call_codec_suspend(codec, false); + hda_call_codec_suspend(codec); hda_call_codec_resume(codec); } #endif diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index 1fa3dd9baf52..593956fc384b 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h @@ -372,17 +372,12 @@ struct hda_codec { unsigned int dp_mst:1; /* support DP1.2 Multi-stream transport */ unsigned int dump_coef:1; /* dump processing coefs in codec proc file */ #ifdef CONFIG_PM - unsigned int power_on :1; /* current (global) power-state */ unsigned int d3_stop_clk:1; /* support D3 operation without BCLK */ unsigned int pm_up_notified:1; /* PM notified to controller */ - unsigned int in_pm:1; /* suspend/resume being performed */ - int power_transition; /* power-state in transition */ - int power_count; /* current (global) power refcount */ - struct delayed_work power_work; /* delayed task for powerdown */ + atomic_t in_pm; /* suspend/resume being performed */ unsigned long power_on_acct; unsigned long power_off_acct; unsigned long power_jiffies; - spinlock_t power_lock; #endif /* filter the requested power state per nid */ @@ -595,64 +590,16 @@ const char *snd_hda_get_jack_location(u32 cfg); * power saving */ #ifdef CONFIG_PM -void snd_hda_power_save(struct hda_codec *codec, int delta, bool d3wait); +void snd_hda_power_up(struct hda_codec *codec); +void snd_hda_power_down(struct hda_codec *codec); +void snd_hda_power_sync(struct hda_codec *codec); void snd_hda_update_power_acct(struct hda_codec *codec); #else -static inline void snd_hda_power_save(struct hda_codec *codec, int delta, - bool d3wait) {} +static inline void snd_hda_power_up(struct hda_codec *codec) {} +static inline void snd_hda_power_down(struct hda_codec *codec) {} +static inline void snd_hda_power_sync(struct hda_codec *codec) {} #endif -/** - * snd_hda_power_up - Power-up the codec - * @codec: HD-audio codec - * - * Increment the power-up counter and power up the hardware really when - * not turned on yet. - */ -static inline void snd_hda_power_up(struct hda_codec *codec) -{ - snd_hda_power_save(codec, 1, false); -} - -/** - * snd_hda_power_up_d3wait - Power-up the codec after waiting for any pending - * D3 transition to complete. This differs from snd_hda_power_up() when - * power_transition == -1. snd_hda_power_up sees this case as a nop, - * snd_hda_power_up_d3wait waits for the D3 transition to complete then powers - * back up. - * @codec: HD-audio codec - * - * Cancel any power down operation hapenning on the work queue, then power up. - */ -static inline void snd_hda_power_up_d3wait(struct hda_codec *codec) -{ - snd_hda_power_save(codec, 1, true); -} - -/** - * snd_hda_power_down - Power-down the codec - * @codec: HD-audio codec - * - * Decrement the power-up counter and schedules the power-off work if - * the counter rearches to zero. - */ -static inline void snd_hda_power_down(struct hda_codec *codec) -{ - snd_hda_power_save(codec, -1, false); -} - -/** - * snd_hda_power_sync - Synchronize the power-save status - * @codec: HD-audio codec - * - * Synchronize the actual power state with the power account; - * called when power_save parameter is changed - */ -static inline void snd_hda_power_sync(struct hda_codec *codec) -{ - snd_hda_power_save(codec, 0, false); -} - #ifdef CONFIG_SND_HDA_PATCH_LOADER /* * patch firmware diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c index 30ddb751806a..522c54f94740 100644 --- a/sound/pci/hda/hda_controller.c +++ b/sound/pci/hda/hda_controller.c @@ -836,7 +836,7 @@ static int azx_pcm_open(struct snd_pcm_substream *substream) buff_step); snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, buff_step); - snd_hda_power_up_d3wait(apcm->codec); + snd_hda_power_up(apcm->codec); err = hinfo->ops.open(hinfo, apcm->codec, substream); if (err < 0) { azx_release_device(azx_dev); diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index 9db1b078801f..26510e60cbe2 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c @@ -1087,6 +1087,7 @@ static int azx_free(struct azx *chip) azx_stop_chip(chip); } + pci->dev.power.ignore_children = 0; /* FIXME */ if (chip->irq >= 0) free_irq(chip->irq, (void*)chip); if (chip->msi) @@ -1796,6 +1797,7 @@ static int azx_probe(struct pci_dev *pci, return err; } + pci->dev.power.ignore_children = 1; /* FIXME */ err = azx_create(card, pci, dev, pci_id->driver_data, &pci_hda_ops, &chip); if (err < 0) diff --git a/sound/pci/hda/hda_trace.h b/sound/pci/hda/hda_trace.h index 3a1c63161eb1..c0e1c7d24dbe 100644 --- a/sound/pci/hda/hda_trace.h +++ b/sound/pci/hda/hda_trace.h @@ -87,30 +87,6 @@ DEFINE_EVENT(hda_power, hda_power_up, TP_PROTO(struct hda_codec *codec), TP_ARGS(codec) ); - -TRACE_EVENT(hda_power_count, - TP_PROTO(struct hda_codec *codec), - TP_ARGS(codec), - TP_STRUCT__entry( - __field( unsigned int, card ) - __field( unsigned int, addr ) - __field( int, power_count ) - __field( int, power_on ) - __field( int, power_transition ) - ), - - TP_fast_assign( - __entry->card = (codec)->bus->card->number; - __entry->addr = (codec)->addr; - __entry->power_count = (codec)->power_count; - __entry->power_on = (codec)->power_on; - __entry->power_transition = (codec)->power_transition; - ), - - TP_printk("[%d:%d] power_count=%d, power_on=%d, power_transition=%d", - __entry->card, __entry->addr, __entry->power_count, - __entry->power_on, __entry->power_transition) -); #endif /* CONFIG_PM */ TRACE_EVENT(hda_unsol_event, -- cgit v1.2.3 From 7f788e0cc07dba7f4eee6ffea30edee3af86e2a5 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Wed, 25 Feb 2015 16:32:45 +0300 Subject: ALSA: azt3328: some indenting cleanups A few minor tweaks to make things line up correctly. Signed-off-by: Dan Carpenter Signed-off-by: Takashi Iwai --- sound/pci/azt3328.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'sound/pci') 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, .running) && (!chip->codecs[peer_codecs[codec_type].other2] .running)); - } - if (call_function) + } + if (call_function) snd_azf3328_ctrl_enable_codecs(chip, enable); /* ...and adjust clock, too @@ -2126,7 +2126,8 @@ static struct snd_pcm_ops snd_azf3328_i2s_out_ops = { static int snd_azf3328_pcm(struct snd_azf3328 *chip) { -enum { AZF_PCMDEV_STD, AZF_PCMDEV_I2S_OUT, NUM_AZF_PCMDEVS }; /* pcm devices */ + /* pcm devices */ + enum { AZF_PCMDEV_STD, AZF_PCMDEV_I2S_OUT, NUM_AZF_PCMDEVS }; struct snd_pcm *pcm; int err; -- cgit v1.2.3 From 9603cded0e2cef003a822985d84b5daff1c7232f Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Wed, 25 Feb 2015 16:33:57 +0300 Subject: ALSA: cmipci: remove a stray space character Signed-off-by: Dan Carpenter Signed-off-by: Takashi Iwai --- sound/pci/cmipci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sound/pci') 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, val = (snd_cmipci_mixer_read(cm, reg.right_reg) >> reg.right_shift) & reg.mask; if (reg.invert) val = reg.mask - val; - ucontrol->value.integer.value[1] = val; + ucontrol->value.integer.value[1] = val; } spin_unlock_irq(&cm->reg_lock); return 0; -- cgit v1.2.3 From bb573928e187fc5b1f91c3a7684791d5dfcca640 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 20 Feb 2015 09:26:04 +0100 Subject: ALSA: hda - Drop power_save value indirection in hda_bus We used to pass the power_save option value to hda_bus via a given pointer. This was needed to refer to the value from the HD-audio core side. However, after the transition to the runtime PM, this is no longer needed. This patch drops the power_save value indirection in hda_bus above, and let the controller driver reprograms the autosuspend value explicitly by a new helper, snd_hda_set_power_save(). Without this call, the HD-audio core doesn't set up the autosuspend and flip the runtime PM. (User may still be able to set up via sysfs, though.) Along with this change, the pointer argument of azx_bus_create() is dropped as well. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_codec.c | 34 ++++++++++++++++++---------------- sound/pci/hda/hda_codec.h | 5 ++--- sound/pci/hda/hda_controller.c | 5 +---- sound/pci/hda/hda_controller.h | 2 +- sound/pci/hda/hda_intel.c | 10 ++++------ sound/pci/hda/hda_tegra.c | 5 +++-- 6 files changed, 29 insertions(+), 32 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index d0dbc62c9147..36cebe0e76b2 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -1175,10 +1175,8 @@ static int snd_hda_codec_dev_register(struct snd_device *device) struct hda_codec *codec = device->device_data; snd_hda_register_beep_device(codec); - if (device_is_registered(hda_codec_dev(codec))) { - snd_hda_power_sync(codec); + if (device_is_registered(hda_codec_dev(codec))) pm_runtime_enable(hda_codec_dev(codec)); - } return 0; } @@ -4778,21 +4776,10 @@ void snd_hda_power_down(struct hda_codec *codec) } EXPORT_SYMBOL_GPL(snd_hda_power_down); -/** - * snd_hda_power_sync - Synchronize the power_save option - * @codec: HD-audio codec - * - * Synchronize the runtime PM autosuspend state from the power_save option. - */ -void snd_hda_power_sync(struct hda_codec *codec) +static void codec_set_power_save(struct hda_codec *codec, int delay) { struct device *dev = hda_codec_dev(codec); - int delay; - if (!codec->bus->power_save) - return; - - delay = *codec->bus->power_save * 1000; if (delay > 0) { pm_runtime_set_autosuspend_delay(dev, delay); pm_runtime_use_autosuspend(dev); @@ -4804,7 +4791,22 @@ void snd_hda_power_sync(struct hda_codec *codec) pm_runtime_forbid(dev); } } -EXPORT_SYMBOL_GPL(snd_hda_power_sync); + +/** + * snd_hda_set_power_save - reprogram autosuspend for the given delay + * @bus: HD-audio bus + * @delay: autosuspend delay in msec, 0 = off + * + * Synchronize the runtime PM autosuspend state from the power_save option. + */ +void snd_hda_set_power_save(struct hda_bus *bus, int delay) +{ + struct hda_codec *c; + + list_for_each_entry(c, &bus->codec_list, list) + codec_set_power_save(c, delay); +} +EXPORT_SYMBOL_GPL(snd_hda_set_power_save); /** * snd_hda_check_amp_list_power - Check the amp list and update the power diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index 593956fc384b..89908f5b9601 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h @@ -122,7 +122,6 @@ struct hda_bus { void *private_data; struct pci_dev *pci; const char *modelname; - int *power_save; struct hda_bus_ops ops; /* codec linked list */ @@ -592,12 +591,12 @@ const char *snd_hda_get_jack_location(u32 cfg); #ifdef CONFIG_PM void snd_hda_power_up(struct hda_codec *codec); void snd_hda_power_down(struct hda_codec *codec); -void snd_hda_power_sync(struct hda_codec *codec); +void snd_hda_set_power_save(struct hda_bus *bus, int delay); void snd_hda_update_power_acct(struct hda_codec *codec); #else static inline void snd_hda_power_up(struct hda_codec *codec) {} static inline void snd_hda_power_down(struct hda_codec *codec) {} -static inline void snd_hda_power_sync(struct hda_codec *codec) {} +static inline void snd_hda_set_power_save(struct hda_bus *bus, int delay) {} #endif #ifdef CONFIG_SND_HDA_PATCH_LOADER diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c index 522c54f94740..cfe2c55296b6 100644 --- a/sound/pci/hda/hda_controller.c +++ b/sound/pci/hda/hda_controller.c @@ -1838,7 +1838,7 @@ static struct hda_bus_ops bus_ops = { }; /* HD-audio bus initialization */ -int azx_bus_create(struct azx *chip, const char *model, int *power_save_to) +int azx_bus_create(struct azx *chip, const char *model) { struct hda_bus *bus; int err; @@ -1852,9 +1852,6 @@ int azx_bus_create(struct azx *chip, const char *model, int *power_save_to) bus->pci = chip->pci; bus->modelname = model; bus->ops = bus_ops; -#ifdef CONFIG_PM - bus->power_save = power_save_to; -#endif if (chip->driver_caps & AZX_DCAPS_RIRB_DELAY) { dev_dbg(chip->card->dev, "Enable delay in RIRB handling\n"); diff --git a/sound/pci/hda/hda_controller.h b/sound/pci/hda/hda_controller.h index 0d09aa6b49ac..e4f46a21698a 100644 --- a/sound/pci/hda/hda_controller.h +++ b/sound/pci/hda/hda_controller.h @@ -432,7 +432,7 @@ void azx_enter_link_reset(struct azx *chip); irqreturn_t azx_interrupt(int irq, void *dev_id); /* Codec interface */ -int azx_bus_create(struct azx *chip, const char *model, int *power_save_to); +int azx_bus_create(struct azx *chip, const char *model); int azx_probe_codecs(struct azx *chip, unsigned int max_slots); int azx_codec_configure(struct azx *chip); int azx_init_stream(struct azx *chip); diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index 26510e60cbe2..40540048b002 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c @@ -173,7 +173,6 @@ static struct kernel_param_ops param_ops_xint = { #define param_check_xint param_check_int static int power_save = CONFIG_SND_HDA_POWER_SAVE_DEFAULT; -static int *power_save_addr = &power_save; module_param(power_save, xint, 0644); MODULE_PARM_DESC(power_save, "Automatic power-saving timeout " "(in second, 0 = disable)."); @@ -186,7 +185,7 @@ static bool power_save_controller = 1; module_param(power_save_controller, bool, 0644); MODULE_PARM_DESC(power_save_controller, "Reset controller in power save mode."); #else -static int *power_save_addr; +#define power_save 0 #endif /* CONFIG_PM */ static int align_buffer_size = -1; @@ -740,7 +739,6 @@ static int param_set_xint(const char *val, const struct kernel_param *kp) { struct hda_intel *hda; struct azx *chip; - struct hda_codec *c; int prev = power_save; int ret = param_set_int(val, kp); @@ -752,8 +750,7 @@ static int param_set_xint(const char *val, const struct kernel_param *kp) chip = &hda->chip; if (!chip->bus || chip->disabled) continue; - list_for_each_entry(c, &chip->bus->codec_list, list) - snd_hda_power_sync(c); + snd_hda_set_power_save(chip->bus, power_save * 1000); } mutex_unlock(&card_list_lock); return 0; @@ -1889,7 +1886,7 @@ static int azx_probe_continue(struct azx *chip) #endif /* create codec instances */ - err = azx_bus_create(chip, model[dev], power_save_addr); + err = azx_bus_create(chip, model[dev]); if (err < 0) goto out_free; @@ -1933,6 +1930,7 @@ static int azx_probe_continue(struct azx *chip) power_down_all_codecs(chip); azx_notifier_register(chip); azx_add_card_list(chip); + snd_hda_set_power_save(chip->bus, power_save * 1000); if (azx_has_pm_runtime(chip) || hda->use_vga_switcheroo) pm_runtime_put_noidle(&pci->dev); diff --git a/sound/pci/hda/hda_tegra.c b/sound/pci/hda/hda_tegra.c index f6949e413a50..42bc17655df0 100644 --- a/sound/pci/hda/hda_tegra.c +++ b/sound/pci/hda/hda_tegra.c @@ -81,7 +81,7 @@ module_param(power_save, bint, 0644); MODULE_PARM_DESC(power_save, "Automatic power-saving timeout (in seconds, 0 = disable)."); #else -static int power_save = 0; +#define power_save 0 #endif /* @@ -496,7 +496,7 @@ static int hda_tegra_probe(struct platform_device *pdev) goto out_free; /* create codec instances */ - err = azx_bus_create(chip, NULL, &power_save); + err = azx_bus_create(chip, NULL); if (err < 0) goto out_free; @@ -525,6 +525,7 @@ static int hda_tegra_probe(struct platform_device *pdev) chip->running = 1; power_down_all_codecs(chip); azx_notifier_register(chip); + snd_hda_set_power_save(chip->bus, power_save * 1000); return 0; -- cgit v1.2.3 From 55ed9cd1feee80764937913afe760161b86cfb11 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 19 Feb 2015 17:35:32 +0100 Subject: ALSA: hda - Replace bus pm_notify with the standard runtime PM framework Now the final bit of runtime PM cleanup: instead of manual notification of the power up/down of the codec via hda_bus pm_notify ops, use the standard runtime PM feature. The child codec device will kick off the runtime PM of the parent (PCI) device upon suspend/resume automatically. For managing whether the link can be really turned off, we use the bit flags bus->codec_powered instead of the earlier bus->power_keep_link_on. flag. Each codec driver is responsible to set/clear the bit flag, and the controller device can be turned off only when all these bits are cleared. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_codec.c | 33 ++++++++------------------------- sound/pci/hda/hda_codec.h | 7 +------ sound/pci/hda/hda_controller.c | 19 ------------------- sound/pci/hda/hda_intel.c | 5 ++--- sound/pci/hda/patch_sigmatel.c | 4 +++- 5 files changed, 14 insertions(+), 54 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 36cebe0e76b2..33b8b71f8eaf 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -46,23 +46,9 @@ #define codec_in_pm(codec) atomic_read(&(codec)->in_pm) #define hda_codec_is_power_on(codec) \ (!pm_runtime_suspended(hda_codec_dev(codec))) - -static void hda_call_pm_notify(struct hda_codec *codec, bool power_up) -{ - struct hda_bus *bus = codec->bus; - - if ((power_up && codec->pm_up_notified) || - (!power_up && !codec->pm_up_notified)) - return; - if (bus->ops.pm_notify) - bus->ops.pm_notify(bus, power_up); - codec->pm_up_notified = power_up; -} - #else #define codec_in_pm(codec) 0 #define hda_codec_is_power_on(codec) 1 -#define hda_call_pm_notify(codec, state) {} #endif /** @@ -1152,7 +1138,7 @@ static void snd_hda_codec_free(struct hda_codec *codec) snd_array_free(&codec->spdif_out); remove_conn_list(codec); codec->bus->caddr_tbl[codec->addr] = NULL; - hda_call_pm_notify(codec, false); /* cancel leftover refcounts */ + clear_bit(codec->addr, &codec->bus->codec_powered); snd_hda_sysfs_clear(codec); free_hda_cache(&codec->amp_cache); free_hda_cache(&codec->cmd_cache); @@ -1277,10 +1263,10 @@ int snd_hda_codec_new(struct hda_bus *bus, * the caller has to power down appropriatley after initialization * phase. */ + set_bit(codec->addr, &bus->codec_powered); pm_runtime_set_active(hda_codec_dev(codec)); pm_runtime_get_noresume(hda_codec_dev(codec)); codec->power_jiffies = jiffies; - hda_call_pm_notify(codec, true); #endif snd_hda_sysfs_init(codec); @@ -1340,11 +1326,6 @@ int snd_hda_codec_new(struct hda_bus *bus, #endif codec->epss = snd_hda_codec_get_supported_ps(codec, fg, AC_PWRST_EPSS); -#ifdef CONFIG_PM - if (!codec->d3_stop_clk || !codec->epss) - bus->power_keep_link_on = 1; -#endif - /* power-up all before initialization */ hda_set_power_state(codec, AC_PWRST_D0); @@ -3954,7 +3935,6 @@ static void hda_call_codec_resume(struct hda_codec *codec) hda_mark_cmd_cache_dirty(codec); codec->power_jiffies = jiffies; - hda_call_pm_notify(codec, true); hda_set_power_state(codec, AC_PWRST_D0); restore_shutup_pins(codec); @@ -3986,14 +3966,17 @@ static int hda_codec_runtime_suspend(struct device *dev) for (i = 0; i < codec->num_pcms; i++) snd_pcm_suspend_all(codec->pcm_info[i].pcm); state = hda_call_codec_suspend(codec); - if (!codec->bus->power_keep_link_on && (state & AC_PWRST_CLK_STOP_OK)) - hda_call_pm_notify(codec, false); + if (codec->d3_stop_clk && codec->epss && (state & AC_PWRST_CLK_STOP_OK)) + clear_bit(codec->addr, &codec->bus->codec_powered); return 0; } static int hda_codec_runtime_resume(struct device *dev) { - hda_call_codec_resume(dev_to_hda_codec(dev)); + struct hda_codec *codec = dev_to_hda_codec(dev); + + set_bit(codec->addr, &codec->bus->codec_powered); + hda_call_codec_resume(codec); pm_runtime_mark_last_busy(dev); return 0; } diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index 89908f5b9601..457fc589eb46 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h @@ -83,10 +83,6 @@ struct hda_bus_ops { struct hda_pcm *pcm); /* reset bus for retry verb */ void (*bus_reset)(struct hda_bus *bus); -#ifdef CONFIG_PM - /* notify power-up/down from codec to controller */ - void (*pm_notify)(struct hda_bus *bus, bool power_up); -#endif #ifdef CONFIG_SND_HDA_DSP_LOADER /* prepare DSP transfer */ int (*load_dsp_prepare)(struct hda_bus *bus, unsigned int format, @@ -150,10 +146,10 @@ struct hda_bus { unsigned int rirb_error:1; /* error in codec communication */ unsigned int response_reset:1; /* controller was reset */ unsigned int in_reset:1; /* during reset operation */ - unsigned int power_keep_link_on:1; /* don't power off HDA link */ unsigned int no_response_fallback:1; /* don't fallback at RIRB error */ int primary_dig_out_type; /* primary digital out PCM type */ + unsigned long codec_powered; /* bit flags of powered codecs */ }; /* @@ -372,7 +368,6 @@ struct hda_codec { unsigned int dump_coef:1; /* dump processing coefs in codec proc file */ #ifdef CONFIG_PM unsigned int d3_stop_clk:1; /* support D3 operation without BCLK */ - unsigned int pm_up_notified:1; /* PM notified to controller */ atomic_t in_pm; /* suspend/resume being performed */ unsigned long power_on_acct; unsigned long power_off_acct; diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c index cfe2c55296b6..789ca66c3094 100644 --- a/sound/pci/hda/hda_controller.c +++ b/sound/pci/hda/hda_controller.c @@ -1785,22 +1785,6 @@ static void azx_bus_reset(struct hda_bus *bus) bus->in_reset = 0; } -#ifdef CONFIG_PM -/* power-up/down the controller */ -static void azx_power_notify(struct hda_bus *bus, bool power_up) -{ - struct azx *chip = bus->private_data; - - if (!azx_has_pm_runtime(chip)) - return; - - if (power_up) - pm_runtime_get_sync(chip->card->dev); - else - pm_runtime_put_sync(chip->card->dev); -} -#endif - static int get_jackpoll_interval(struct azx *chip) { int i; @@ -1827,9 +1811,6 @@ static struct hda_bus_ops bus_ops = { .get_response = azx_get_response, .attach_pcm = azx_attach_pcm_stream, .bus_reset = azx_bus_reset, -#ifdef CONFIG_PM - .pm_notify = azx_power_notify, -#endif #ifdef CONFIG_SND_HDA_DSP_LOADER .load_dsp_prepare = azx_load_dsp_prepare, .load_dsp_trigger = azx_load_dsp_trigger, diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index 40540048b002..738d332351d5 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c @@ -918,7 +918,8 @@ static int azx_runtime_idle(struct device *dev) if (chip->disabled || hda->init_failed) return 0; - if (!power_save_controller || !azx_has_pm_runtime(chip)) + if (!power_save_controller || !azx_has_pm_runtime(chip) || + chip->bus->codec_powered) return -EBUSY; return 0; @@ -1084,7 +1085,6 @@ static int azx_free(struct azx *chip) azx_stop_chip(chip); } - pci->dev.power.ignore_children = 0; /* FIXME */ if (chip->irq >= 0) free_irq(chip->irq, (void*)chip); if (chip->msi) @@ -1794,7 +1794,6 @@ static int azx_probe(struct pci_dev *pci, return err; } - pci->dev.power.ignore_children = 1; /* FIXME */ err = azx_create(card, pci, dev, pci_id->driver_data, &pci_hda_ops, &chip); if (err < 0) diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c index 6a2163056216..2956a6ba6bf0 100644 --- a/sound/pci/hda/patch_sigmatel.c +++ b/sound/pci/hda/patch_sigmatel.c @@ -2132,8 +2132,10 @@ static void stac92hd83xxx_fixup_hp_mic_led(struct hda_codec *codec, if (action == HDA_FIXUP_ACT_PRE_PROBE) { spec->mic_mute_led_gpio = 0x08; /* GPIO3 */ +#ifdef CONFIG_PM /* resetting controller clears GPIO, so we need to keep on */ - codec->bus->power_keep_link_on = 1; + codec->d3_stop_clk = 0; +#endif } } -- cgit v1.2.3 From 709949fbe9632941585dcacabc8a66010030ed10 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 20 Feb 2015 09:58:14 +0100 Subject: ALSA: hda - Power down codec automatically at registration So far, we let the controller driver power down the all codecs at the end of probe. But this can be done better in the codec's dev_register callback. This results in the reduction of duplicated codes in each control driver. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_codec.c | 5 +++-- sound/pci/hda/hda_intel.c | 14 -------------- sound/pci/hda/hda_tegra.c | 12 ------------ 3 files changed, 3 insertions(+), 28 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 33b8b71f8eaf..6580a367023e 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -1163,6 +1163,8 @@ static int snd_hda_codec_dev_register(struct snd_device *device) snd_hda_register_beep_device(codec); if (device_is_registered(hda_codec_dev(codec))) pm_runtime_enable(hda_codec_dev(codec)); + /* it was powered up in snd_hda_codec_new(), now all done */ + snd_hda_power_down(codec); return 0; } @@ -1260,8 +1262,7 @@ int snd_hda_codec_new(struct hda_bus *bus, #ifdef CONFIG_PM /* snd_hda_codec_new() marks the codec as power-up, and leave it as is. - * the caller has to power down appropriatley after initialization - * phase. + * it's powered down later in snd_hda_codec_dev_register(). */ set_bit(codec->addr, &bus->codec_powered); pm_runtime_set_active(hda_codec_dev(codec)); diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index 738d332351d5..e75e8137e296 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c @@ -1604,19 +1604,6 @@ static int azx_first_init(struct azx *chip) return 0; } -static void power_down_all_codecs(struct azx *chip) -{ -#ifdef CONFIG_PM - /* The codecs were powered up in snd_hda_codec_new(). - * Now all initialization done, so turn them down if possible - */ - struct hda_codec *codec; - list_for_each_entry(codec, &chip->bus->codec_list, list) { - snd_hda_power_down(codec); - } -#endif -} - #ifdef CONFIG_SND_HDA_PATCH_LOADER /* callback from request_firmware_nowait() */ static void azx_firmware_cb(const struct firmware *fw, void *context) @@ -1926,7 +1913,6 @@ static int azx_probe_continue(struct azx *chip) goto out_free; chip->running = 1; - power_down_all_codecs(chip); azx_notifier_register(chip); azx_add_card_list(chip); snd_hda_set_power_save(chip->bus, power_save * 1000); diff --git a/sound/pci/hda/hda_tegra.c b/sound/pci/hda/hda_tegra.c index 42bc17655df0..1359fdd20f02 100644 --- a/sound/pci/hda/hda_tegra.c +++ b/sound/pci/hda/hda_tegra.c @@ -337,17 +337,6 @@ static int hda_tegra_init_chip(struct azx *chip, struct platform_device *pdev) return 0; } -/* - * The codecs were powered up in snd_hda_codec_new(). - * Now all initialization done, so turn them down if possible - */ -static void power_down_all_codecs(struct azx *chip) -{ - struct hda_codec *codec; - list_for_each_entry(codec, &chip->bus->codec_list, list) - snd_hda_power_down(codec); -} - static int hda_tegra_first_init(struct azx *chip, struct platform_device *pdev) { struct snd_card *card = chip->card; @@ -523,7 +512,6 @@ static int hda_tegra_probe(struct platform_device *pdev) goto out_free; chip->running = 1; - power_down_all_codecs(chip); azx_notifier_register(chip); snd_hda_set_power_save(chip->bus, power_save * 1000); -- cgit v1.2.3 From 777ae1946813f1dea24d908c8f318754f090f41f Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 26 Feb 2015 14:35:59 +0100 Subject: ALSA: hda - Set parent of input beep devices Set the card device as the parent like other sound devices instead of leaving it empty. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_beep.c | 1 + 1 file changed, 1 insertion(+) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_beep.c b/sound/pci/hda/hda_beep.c index d6be4e852c4d..e98438e95e79 100644 --- a/sound/pci/hda/hda_beep.c +++ b/sound/pci/hda/hda_beep.c @@ -160,6 +160,7 @@ static int snd_hda_do_attach(struct hda_beep *beep) input_dev->name = "HDA Digital PCBeep"; input_dev->phys = beep->phys; input_dev->id.bustype = BUS_PCI; + input_dev->dev.parent = &codec->bus->card->card_dev; input_dev->id.vendor = codec->vendor_id >> 16; input_dev->id.product = codec->vendor_id & 0xffff; -- cgit v1.2.3 From 7e40b80da452770878943edfe7da80f10f8d25da Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 26 Feb 2015 09:42:04 +0100 Subject: ALSA: hda - Remove channel mode helper functions They are no longer used, let's kill them. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_codec.c | 82 ----------------------------------------------- sound/pci/hda/hda_local.h | 23 ------------- 2 files changed, 105 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 6580a367023e..db86b446743c 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -4843,88 +4843,6 @@ int snd_hda_check_amp_list_power(struct hda_codec *codec, EXPORT_SYMBOL_GPL(snd_hda_check_amp_list_power); #endif -/* - * Channel mode helper - */ - -/** - * snd_hda_ch_mode_info - Info callback helper for the channel mode enum - * @codec: the HDA codec - * @uinfo: pointer to get/store the data - * @chmode: channel mode array - * @num_chmodes: channel mode array size - */ -int snd_hda_ch_mode_info(struct hda_codec *codec, - struct snd_ctl_elem_info *uinfo, - const struct hda_channel_mode *chmode, - int num_chmodes) -{ - uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; - uinfo->count = 1; - uinfo->value.enumerated.items = num_chmodes; - if (uinfo->value.enumerated.item >= num_chmodes) - uinfo->value.enumerated.item = num_chmodes - 1; - sprintf(uinfo->value.enumerated.name, "%dch", - chmode[uinfo->value.enumerated.item].channels); - return 0; -} -EXPORT_SYMBOL_GPL(snd_hda_ch_mode_info); - -/** - * snd_hda_ch_mode_get - Get callback helper for the channel mode enum - * @codec: the HDA codec - * @ucontrol: pointer to get/store the data - * @chmode: channel mode array - * @num_chmodes: channel mode array size - * @max_channels: max number of channels - */ -int snd_hda_ch_mode_get(struct hda_codec *codec, - struct snd_ctl_elem_value *ucontrol, - const struct hda_channel_mode *chmode, - int num_chmodes, - int max_channels) -{ - int i; - - for (i = 0; i < num_chmodes; i++) { - if (max_channels == chmode[i].channels) { - ucontrol->value.enumerated.item[0] = i; - break; - } - } - return 0; -} -EXPORT_SYMBOL_GPL(snd_hda_ch_mode_get); - -/** - * snd_hda_ch_mode_put - Put callback helper for the channel mode enum - * @codec: the HDA codec - * @ucontrol: pointer to get/store the data - * @chmode: channel mode array - * @num_chmodes: channel mode array size - * @max_channelsp: pointer to store the max channels - */ -int snd_hda_ch_mode_put(struct hda_codec *codec, - struct snd_ctl_elem_value *ucontrol, - const struct hda_channel_mode *chmode, - int num_chmodes, - int *max_channelsp) -{ - unsigned int mode; - - mode = ucontrol->value.enumerated.item[0]; - if (mode >= num_chmodes) - return -EINVAL; - if (*max_channelsp == chmode[mode].channels) - return 0; - /* change the current channel setting */ - *max_channelsp = chmode[mode].channels; - if (chmode[mode].sequence) - snd_hda_sequence_write_cache(codec, chmode[mode].sequence); - return 1; -} -EXPORT_SYMBOL_GPL(snd_hda_ch_mode_put); - /* * input MUX helper */ diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h index 2f7d9646a41d..8588813163e3 100644 --- a/sound/pci/hda/hda_local.h +++ b/sound/pci/hda/hda_local.h @@ -272,29 +272,6 @@ int snd_hda_add_imux_item(struct hda_codec *codec, struct hda_input_mux *imux, const char *label, int index, int *type_index_ret); -/* - * Channel mode helper - */ -struct hda_channel_mode { - int channels; - const struct hda_verb *sequence; -}; - -int snd_hda_ch_mode_info(struct hda_codec *codec, - struct snd_ctl_elem_info *uinfo, - const struct hda_channel_mode *chmode, - int num_chmodes); -int snd_hda_ch_mode_get(struct hda_codec *codec, - struct snd_ctl_elem_value *ucontrol, - const struct hda_channel_mode *chmode, - int num_chmodes, - int max_channels); -int snd_hda_ch_mode_put(struct hda_codec *codec, - struct snd_ctl_elem_value *ucontrol, - const struct hda_channel_mode *chmode, - int num_chmodes, - int *max_channelsp); - /* * Multi-channel / digital-out PCM helper */ -- cgit v1.2.3 From 820cc6cf2c552155ea919e596a85e1f4e5dfa2b5 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 20 Feb 2015 12:50:46 +0100 Subject: ALSA: hda - Clear pcm pointer assigned to hda_pcm at device removal We leave the pcm field of struct hda_pcm at removal of each device, so far. This hasn't been a problem since unbinding the codec driver isn't supposed to happen and another route via snd_hda_codec_reset() clears all the once. However, for a proper unbind implementation, we need to care about it. This patch does the thing above properly: - Include struct hda_pcm pointer instead of struct hda_pcm_stream pointers in struct azx_dev. This allows us to point the hda_pcm object at dev_free callback. - Introduce to_hda_pcm_stream() macro for better readability. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_controller.c | 22 +++++++++++++++------- sound/pci/hda/hda_controller.h | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c index 789ca66c3094..1695f0e2bd9d 100644 --- a/sound/pci/hda/hda_controller.c +++ b/sound/pci/hda/hda_controller.c @@ -258,11 +258,18 @@ static void azx_timecounter_init(struct snd_pcm_substream *substream, tc->cycle_last = last; } +static inline struct hda_pcm_stream * +to_hda_pcm_stream(struct snd_pcm_substream *substream) +{ + struct azx_pcm *apcm = snd_pcm_substream_chip(substream); + return &apcm->info->stream[substream->stream]; +} + static u64 azx_adjust_codec_delay(struct snd_pcm_substream *substream, u64 nsec) { struct azx_pcm *apcm = snd_pcm_substream_chip(substream); - struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream]; + struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream); u64 codec_frames, codec_nsecs; if (!hinfo->ops.get_delay) @@ -398,7 +405,7 @@ static int azx_setup_periods(struct azx *chip, static int azx_pcm_close(struct snd_pcm_substream *substream) { struct azx_pcm *apcm = snd_pcm_substream_chip(substream); - struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream]; + struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream); struct azx *chip = apcm->chip; struct azx_dev *azx_dev = get_azx_dev(substream); unsigned long flags; @@ -440,7 +447,7 @@ static int azx_pcm_hw_free(struct snd_pcm_substream *substream) struct azx_pcm *apcm = snd_pcm_substream_chip(substream); struct azx_dev *azx_dev = get_azx_dev(substream); struct azx *chip = apcm->chip; - struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream]; + struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream); int err; /* reset BDL address */ @@ -467,7 +474,7 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream) struct azx_pcm *apcm = snd_pcm_substream_chip(substream); struct azx *chip = apcm->chip; struct azx_dev *azx_dev = get_azx_dev(substream); - struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream]; + struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream); struct snd_pcm_runtime *runtime = substream->runtime; unsigned int bufsize, period_bytes, format_val, stream_tag; int err; @@ -707,7 +714,7 @@ unsigned int azx_get_position(struct azx *chip, if (substream->runtime) { struct azx_pcm *apcm = snd_pcm_substream_chip(substream); - struct hda_pcm_stream *hinfo = apcm->hinfo[stream]; + struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream); if (chip->get_delay[stream]) delay += chip->get_delay[stream](chip, azx_dev, pos); @@ -790,7 +797,7 @@ static struct snd_pcm_hardware azx_pcm_hw = { static int azx_pcm_open(struct snd_pcm_substream *substream) { struct azx_pcm *apcm = snd_pcm_substream_chip(substream); - struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream]; + struct hda_pcm_stream *hinfo = to_hda_pcm_stream(substream); struct azx *chip = apcm->chip; struct azx_dev *azx_dev; struct snd_pcm_runtime *runtime = substream->runtime; @@ -904,6 +911,7 @@ static void azx_pcm_free(struct snd_pcm *pcm) struct azx_pcm *apcm = pcm->private_data; if (apcm) { list_del(&apcm->list); + apcm->info->pcm = NULL; kfree(apcm); } } @@ -940,6 +948,7 @@ static int azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec, apcm->chip = chip; apcm->pcm = pcm; apcm->codec = codec; + apcm->info = cpcm; pcm->private_data = apcm; pcm->private_free = azx_pcm_free; if (cpcm->pcm_type == HDA_PCM_TYPE_MODEM) @@ -947,7 +956,6 @@ static int azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec, list_add_tail(&apcm->list, &chip->pcm_list); cpcm->pcm = pcm; for (s = 0; s < 2; s++) { - apcm->hinfo[s] = &cpcm->stream[s]; if (cpcm->stream[s].substreams) snd_pcm_set_ops(pcm, s, &azx_pcm_ops); } diff --git a/sound/pci/hda/hda_controller.h b/sound/pci/hda/hda_controller.h index e4f46a21698a..94c1a4719f7f 100644 --- a/sound/pci/hda/hda_controller.h +++ b/sound/pci/hda/hda_controller.h @@ -283,7 +283,7 @@ struct azx_pcm { struct azx *chip; struct snd_pcm *pcm; struct hda_codec *codec; - struct hda_pcm_stream *hinfo[2]; + struct hda_pcm *info; struct list_head list; }; -- cgit v1.2.3 From 1a4ba30cced3002add8459eadcd65b8d3cd1515e Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 24 Feb 2015 11:50:11 +0100 Subject: ALSA: hda - Split snd_hda_build_pcms() snd_hda_build_pcms() does actually three things: let the codec driver build up hda_pcm list, set the PCM default values, and call the attach_pcm bus ops for each hda_pcm instance. The former two are basically independent from the bus implementation, so it'd make the code a bit more readable. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_codec.c | 102 +++++++++++++++++++++++++++------------------- sound/pci/hda/hda_codec.h | 1 + 2 files changed, 60 insertions(+), 43 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index db86b446743c..40300fcc5308 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -4569,71 +4569,87 @@ static int get_empty_pcm_device(struct hda_bus *bus, unsigned int type) return -EAGAIN; } -/* - * attach a new PCM stream - */ -static int snd_hda_attach_pcm(struct hda_codec *codec, struct hda_pcm *pcm) +/* call build_pcms ops of the given codec and set up the default parameters */ +int snd_hda_codec_parse_pcms(struct hda_codec *codec) { - struct hda_bus *bus = codec->bus; - struct hda_pcm_stream *info; - int stream, err; + unsigned int pcm; + int err; - if (snd_BUG_ON(!pcm->name)) - return -EINVAL; - for (stream = 0; stream < 2; stream++) { - info = &pcm->stream[stream]; - if (info->substreams) { + if (codec->num_pcms) + return 0; /* already parsed */ + + if (!codec->patch_ops.build_pcms) + return 0; + + err = codec->patch_ops.build_pcms(codec); + if (err < 0) { + codec_err(codec, "cannot build PCMs for #%d (error %d)\n", + codec->addr, err); + return err; + } + + for (pcm = 0; pcm < codec->num_pcms; pcm++) { + struct hda_pcm *cpcm = &codec->pcm_info[pcm]; + int stream; + + for (stream = 0; stream < 2; stream++) { + struct hda_pcm_stream *info = &cpcm->stream[stream]; + + if (!info->substreams) + continue; + if (snd_BUG_ON(!cpcm->name)) + return -EINVAL; err = set_pcm_default_values(codec, info); - if (err < 0) + if (err < 0) { + codec_warn(codec, + "fail to setup default for PCM %s\n", + cpcm->name); return err; + } } } - return bus->ops.attach_pcm(bus, codec, pcm); + + return 0; } /* assign all PCMs of the given codec */ int snd_hda_codec_build_pcms(struct hda_codec *codec) { + struct hda_bus *bus = codec->bus; unsigned int pcm; - int err; + int dev, err; - if (!codec->num_pcms) { - if (!codec->patch_ops.build_pcms) - return 0; - err = codec->patch_ops.build_pcms(codec); - if (err < 0) { - codec_err(codec, - "cannot build PCMs for #%d (error %d)\n", - codec->addr, err); - err = snd_hda_codec_reset(codec); - if (err < 0) { - codec_err(codec, - "cannot revert codec\n"); - return err; - } - } + if (snd_BUG_ON(!bus->ops.attach_pcm)) + return -EINVAL; + + err = snd_hda_codec_parse_pcms(codec); + if (err < 0) { + snd_hda_codec_reset(codec); + return err; } + + /* attach a new PCM streams */ for (pcm = 0; pcm < codec->num_pcms; pcm++) { struct hda_pcm *cpcm = &codec->pcm_info[pcm]; - int dev; + if (cpcm->pcm) + continue; /* already attached */ if (!cpcm->stream[0].substreams && !cpcm->stream[1].substreams) continue; /* no substreams assigned */ - if (!cpcm->pcm) { - dev = get_empty_pcm_device(codec->bus, cpcm->pcm_type); - if (dev < 0) - continue; /* no fatal error */ - cpcm->device = dev; - err = snd_hda_attach_pcm(codec, cpcm); - if (err < 0) { - codec_err(codec, - "cannot attach PCM stream %d for codec #%d\n", - dev, codec->addr); - continue; /* no fatal error */ - } + dev = get_empty_pcm_device(bus, cpcm->pcm_type); + if (dev < 0) + continue; /* no fatal error */ + cpcm->device = dev; + err = bus->ops.attach_pcm(bus, codec, cpcm); + if (err < 0) { + codec_err(codec, + "cannot attach PCM stream %d for codec #%d\n", + dev, codec->addr); + continue; /* no fatal error */ } } + return 0; } diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index 457fc589eb46..8cf70369cd10 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h @@ -517,6 +517,7 @@ int snd_hda_codec_build_controls(struct hda_codec *codec); * PCM */ int snd_hda_build_pcms(struct hda_bus *bus); +int snd_hda_codec_parse_pcms(struct hda_codec *codec); int snd_hda_codec_build_pcms(struct hda_codec *codec); int snd_hda_codec_prepare(struct hda_codec *codec, -- cgit v1.2.3 From 6efdd8513f182492c21fb7238592d4539d5c751a Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 27 Feb 2015 16:09:22 +0100 Subject: ALSA: hda - Add card field to hda_codec struct Allow the codec object to have an individual card pointer. Not only this simplifies the redirections in many places, also this will allow us to make each codec assigned to a different card object. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_beep.c | 4 ++-- sound/pci/hda/hda_bind.c | 6 +++--- sound/pci/hda/hda_codec.c | 30 +++++++++++++++--------------- sound/pci/hda/hda_codec.h | 5 +++-- sound/pci/hda/hda_controller.c | 2 +- sound/pci/hda/hda_hwdep.c | 2 +- sound/pci/hda/hda_jack.c | 8 ++++---- sound/pci/hda/hda_proc.c | 2 +- sound/pci/hda/hda_sysfs.c | 2 +- sound/pci/hda/hda_trace.h | 4 ++-- sound/pci/hda/patch_ca0132.c | 2 +- sound/pci/hda/patch_hdmi.c | 6 +++--- sound/pci/hda/patch_via.c | 8 ++++---- 13 files changed, 41 insertions(+), 40 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_beep.c b/sound/pci/hda/hda_beep.c index e98438e95e79..581b7fdef0e3 100644 --- a/sound/pci/hda/hda_beep.c +++ b/sound/pci/hda/hda_beep.c @@ -160,7 +160,7 @@ static int snd_hda_do_attach(struct hda_beep *beep) input_dev->name = "HDA Digital PCBeep"; input_dev->phys = beep->phys; input_dev->id.bustype = BUS_PCI; - input_dev->dev.parent = &codec->bus->card->card_dev; + input_dev->dev.parent = &codec->card->card_dev; input_dev->id.vendor = codec->vendor_id >> 16; input_dev->id.product = codec->vendor_id & 0xffff; @@ -224,7 +224,7 @@ int snd_hda_attach_beep_device(struct hda_codec *codec, int nid) if (beep == NULL) return -ENOMEM; snprintf(beep->phys, sizeof(beep->phys), - "card%d/codec#%d/beep0", codec->bus->card->number, codec->addr); + "card%d/codec#%d/beep0", codec->card->number, codec->addr); /* enable linear scale */ snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_2, 0x01); diff --git a/sound/pci/hda/hda_bind.c b/sound/pci/hda/hda_bind.c index ce2dd7b0dc07..2d00417494e2 100644 --- a/sound/pci/hda/hda_bind.c +++ b/sound/pci/hda/hda_bind.c @@ -287,9 +287,9 @@ int snd_hda_codec_configure(struct hda_codec *codec) } /* audio codec should override the mixer name */ - if (codec->afg || !*codec->bus->card->mixername) - snprintf(codec->bus->card->mixername, - sizeof(codec->bus->card->mixername), + if (codec->afg || !*codec->card->mixername) + snprintf(codec->card->mixername, + sizeof(codec->card->mixername), "%s %s", codec->vendor_name, codec->chip_name); return 0; diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 40300fcc5308..0533c862b539 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -1196,9 +1196,8 @@ static void snd_hda_codec_dev_release(struct device *dev) * * Returns 0 if successful, or a negative error code. */ -int snd_hda_codec_new(struct hda_bus *bus, - unsigned int codec_addr, - struct hda_codec **codecp) +int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card, + unsigned int codec_addr, struct hda_codec **codecp) { struct hda_codec *codec; struct device *dev; @@ -1217,7 +1216,7 @@ int snd_hda_codec_new(struct hda_bus *bus, return -EINVAL; if (bus->caddr_tbl[codec_addr]) { - dev_err(bus->card->dev, + dev_err(card->dev, "address 0x%x is already occupied\n", codec_addr); return -EBUSY; @@ -1225,21 +1224,22 @@ int snd_hda_codec_new(struct hda_bus *bus, codec = kzalloc(sizeof(*codec), GFP_KERNEL); if (codec == NULL) { - dev_err(bus->card->dev, "can't allocate struct hda_codec\n"); + dev_err(card->dev, "can't allocate struct hda_codec\n"); return -ENOMEM; } dev = hda_codec_dev(codec); device_initialize(dev); - dev->parent = bus->card->dev; + dev->parent = card->dev; dev->bus = &snd_hda_bus_type; dev->release = snd_hda_codec_dev_release; dev->groups = snd_hda_dev_attr_groups; - dev_set_name(dev, "hdaudioC%dD%d", bus->card->number, codec_addr); + dev_set_name(dev, "hdaudioC%dD%d", card->number, codec_addr); dev_set_drvdata(dev, codec); /* for sysfs */ device_enable_async_suspend(dev); codec->bus = bus; + codec->card = card; codec->addr = codec_addr; mutex_init(&codec->spdif_mutex); mutex_init(&codec->control_mutex); @@ -1300,7 +1300,7 @@ int snd_hda_codec_new(struct hda_bus *bus, setup_fg_nodes(codec); if (!codec->afg && !codec->mfg) { - dev_err(bus->card->dev, "no AFG or MFG node found\n"); + dev_err(card->dev, "no AFG or MFG node found\n"); err = -ENODEV; goto error; } @@ -1308,7 +1308,7 @@ int snd_hda_codec_new(struct hda_bus *bus, fg = codec->afg ? codec->afg : codec->mfg; err = read_widget_caps(codec, fg); if (err < 0) { - dev_err(bus->card->dev, "cannot malloc\n"); + dev_err(card->dev, "cannot malloc\n"); goto error; } err = read_pin_defaults(codec); @@ -1337,9 +1337,9 @@ int snd_hda_codec_new(struct hda_bus *bus, sprintf(component, "HDA:%08x,%08x,%08x", codec->vendor_id, codec->subsystem_id, codec->revision_id); - snd_component_add(codec->bus->card, component); + snd_component_add(card, component); - err = snd_device_new(bus->card, SNDRV_DEV_CODEC, codec, &dev_ops); + err = snd_device_new(card, SNDRV_DEV_CODEC, codec, &dev_ops); if (err < 0) goto error; @@ -2237,7 +2237,7 @@ find_mixer_ctl(struct hda_codec *codec, const char *name, int dev, int idx) if (snd_BUG_ON(strlen(name) >= sizeof(id.name))) return NULL; strcpy(id.name, name); - return snd_ctl_find_id(codec->bus->card, &id); + return snd_ctl_find_id(codec->card, &id); } /** @@ -2301,7 +2301,7 @@ int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid, nid = kctl->id.subdevice & 0xffff; if (kctl->id.subdevice & (HDA_SUBDEV_NID_FLAG|HDA_SUBDEV_AMP_FLAG)) kctl->id.subdevice = 0; - err = snd_ctl_add(codec->bus->card, kctl); + err = snd_ctl_add(codec->card, kctl); if (err < 0) return err; item = snd_array_new(&codec->mixers); @@ -2354,7 +2354,7 @@ void snd_hda_ctls_clear(struct hda_codec *codec) int i; struct hda_nid_item *items = codec->mixers.list; for (i = 0; i < codec->mixers.used; i++) - snd_ctl_remove(codec->bus->card, items[i].kctl); + snd_ctl_remove(codec->card, items[i].kctl); snd_array_free(&codec->mixers); snd_array_free(&codec->nids); } @@ -2427,7 +2427,7 @@ EXPORT_SYMBOL_GPL(snd_hda_unlock_devices); int snd_hda_codec_reset(struct hda_codec *codec) { struct hda_bus *bus = codec->bus; - struct snd_card *card = bus->card; + struct snd_card *card = codec->card; int i; if (snd_hda_lock_devices(bus) < 0) diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index 8cf70369cd10..8908a0768736 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h @@ -274,6 +274,7 @@ struct hda_pcm { struct hda_codec { struct device dev; struct hda_bus *bus; + struct snd_card *card; unsigned int addr; /* codec addr*/ struct list_head list; /* list point */ @@ -420,8 +421,8 @@ enum { * constructors */ int snd_hda_bus_new(struct snd_card *card, struct hda_bus **busp); -int snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr, - struct hda_codec **codecp); +int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card, + unsigned int codec_addr, struct hda_codec **codecp); int snd_hda_codec_configure(struct hda_codec *codec); int snd_hda_codec_update_widgets(struct hda_codec *codec); diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c index 1695f0e2bd9d..f50863a5159d 100644 --- a/sound/pci/hda/hda_controller.c +++ b/sound/pci/hda/hda_controller.c @@ -1898,7 +1898,7 @@ int azx_probe_codecs(struct azx *chip, unsigned int max_slots) for (c = 0; c < max_slots; c++) { if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) { struct hda_codec *codec; - err = snd_hda_codec_new(bus, c, &codec); + err = snd_hda_codec_new(bus, bus->card, c, &codec); if (err < 0) continue; codec->jackpoll_interval = get_jackpoll_interval(chip); diff --git a/sound/pci/hda/hda_hwdep.c b/sound/pci/hda/hda_hwdep.c index 125f3420fa6a..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) int err; sprintf(hwname, "HDA Codec %d", codec->addr); - err = snd_hwdep_new(codec->bus->card, hwname, codec->addr, &hwdep); + err = snd_hwdep_new(codec->card, hwname, codec->addr, &hwdep); if (err < 0) return err; codec->hwdep = hwdep; 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) #ifdef CONFIG_SND_HDA_INPUT_JACK /* free jack instances manually when clearing/reconfiguring */ if (!codec->bus->shutdown && jack->jack) - snd_device_free(codec->bus->card, jack->jack); + snd_device_free(codec->card, jack->jack); #endif for (cb = jack->callback; cb; cb = next) { next = cb->next; @@ -340,7 +340,7 @@ void snd_hda_jack_report_sync(struct hda_codec *codec) if (!jack->kctl || jack->block_report) continue; state = get_jack_plug_state(jack->pin_sense); - snd_kctl_jack_report(codec->bus->card, jack->kctl, state); + snd_kctl_jack_report(codec->card, jack->kctl, state); #ifdef CONFIG_SND_HDA_INPUT_JACK if (jack->jack) snd_jack_report(jack->jack, @@ -412,11 +412,11 @@ static int __snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid, jack->phantom_jack = !!phantom_jack; state = snd_hda_jack_detect(codec, nid); - snd_kctl_jack_report(codec->bus->card, kctl, state); + snd_kctl_jack_report(codec->card, kctl, state); #ifdef CONFIG_SND_HDA_INPUT_JACK if (!phantom_jack) { jack->type = get_input_jack_type(codec, nid); - err = snd_jack_new(codec->bus->card, name, jack->type, + err = snd_jack_new(codec->card, name, jack->type, &jack->jack); if (err < 0) return err; diff --git a/sound/pci/hda/hda_proc.c b/sound/pci/hda/hda_proc.c index ce5a6da83419..cc32b878ae2e 100644 --- a/sound/pci/hda/hda_proc.c +++ b/sound/pci/hda/hda_proc.c @@ -839,7 +839,7 @@ int snd_hda_codec_proc_new(struct hda_codec *codec) int err; snprintf(name, sizeof(name), "codec#%d", codec->addr); - err = snd_card_proc_new(codec->bus->card, name, &entry); + err = snd_card_proc_new(codec->card, name, &entry); if (err < 0) return err; diff --git a/sound/pci/hda/hda_sysfs.c b/sound/pci/hda/hda_sysfs.c index ccc962a1699f..e13c75d67847 100644 --- a/sound/pci/hda/hda_sysfs.c +++ b/sound/pci/hda/hda_sysfs.c @@ -149,7 +149,7 @@ static int reconfig_codec(struct hda_codec *codec) err = snd_hda_codec_build_controls(codec); if (err < 0) goto error; - err = snd_card_register(codec->bus->card); + err = snd_card_register(codec->card); error: snd_hda_power_down(codec); return err; diff --git a/sound/pci/hda/hda_trace.h b/sound/pci/hda/hda_trace.h index c0e1c7d24dbe..7fedfa862419 100644 --- a/sound/pci/hda/hda_trace.h +++ b/sound/pci/hda/hda_trace.h @@ -23,7 +23,7 @@ DECLARE_EVENT_CLASS(hda_cmd, ), TP_fast_assign( - __entry->card = (codec)->bus->card->number; + __entry->card = (codec)->card->number; __entry->addr = (codec)->addr; __entry->val = (val); ), @@ -71,7 +71,7 @@ DECLARE_EVENT_CLASS(hda_power, ), TP_fast_assign( - __entry->card = (codec)->bus->card->number; + __entry->card = (codec)->card->number; __entry->addr = (codec)->addr; ), diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c index 81991b4134cd..ced3e82d9e23 100644 --- a/sound/pci/hda/patch_ca0132.c +++ b/sound/pci/hda/patch_ca0132.c @@ -4352,7 +4352,7 @@ static bool ca0132_download_dsp_images(struct hda_codec *codec) const struct dsp_image_seg *dsp_os_image; const struct firmware *fw_entry; - if (request_firmware(&fw_entry, EFX_FILE, codec->bus->card->dev) != 0) + if (request_firmware(&fw_entry, EFX_FILE, codec->card->dev) != 0) return false; dsp_os_image = (struct dsp_image_seg *)(fw_entry->data); diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c index f1812aabd63e..0f8354cbc7a7 100644 --- a/sound/pci/hda/patch_hdmi.c +++ b/sound/pci/hda/patch_hdmi.c @@ -579,7 +579,7 @@ static int eld_proc_new(struct hdmi_spec_per_pin *per_pin, int index) int err; snprintf(name, sizeof(name), "eld#%d.%d", codec->addr, index); - err = snd_card_proc_new(codec->bus->card, name, &entry); + err = snd_card_proc_new(codec->card, name, &entry); if (err < 0) return err; @@ -594,7 +594,7 @@ static int eld_proc_new(struct hdmi_spec_per_pin *per_pin, int index) static void eld_proc_free(struct hdmi_spec_per_pin *per_pin) { if (!per_pin->codec->bus->shutdown && per_pin->proc_entry) { - snd_device_free(per_pin->codec->bus->card, per_pin->proc_entry); + snd_device_free(per_pin->codec->card, per_pin->proc_entry); per_pin->proc_entry = NULL; } } @@ -1624,7 +1624,7 @@ static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll) } if (eld_changed) - snd_ctl_notify(codec->bus->card, + snd_ctl_notify(codec->card, SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO, &per_pin->eld_ctl->id); unlock: diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 2045f33b1ace..57ad503ff940 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -907,16 +907,16 @@ static int patch_vt1708S(struct hda_codec *codec) if (get_codec_type(codec) == VT1708BCE) { kfree(codec->chip_name); codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL); - snprintf(codec->bus->card->mixername, - sizeof(codec->bus->card->mixername), + snprintf(codec->card->mixername, + sizeof(codec->card->mixername), "%s %s", codec->vendor_name, codec->chip_name); } /* correct names for VT1705 */ if (codec->vendor_id == 0x11064397) { kfree(codec->chip_name); codec->chip_name = kstrdup("VT1705", GFP_KERNEL); - snprintf(codec->bus->card->mixername, - sizeof(codec->bus->card->mixername), + snprintf(codec->card->mixername, + sizeof(codec->card->mixername), "%s %s", codec->vendor_name, codec->chip_name); } -- cgit v1.2.3 From f4de8fe6cffb449a779dff61f071bd1af9e18e0f Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 27 Feb 2015 16:17:18 +0100 Subject: ALSA: hda - Remove superfluous memory allocation error messages The memory allocators should have already given the kernel warning messages, thus we don't have to annoy again. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_codec.c | 16 ++++------------ sound/pci/hda/hda_controller.c | 18 ++++-------------- sound/pci/hda/hda_intel.c | 5 +---- 3 files changed, 9 insertions(+), 30 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 0533c862b539..262c41a8f96e 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -776,10 +776,8 @@ int snd_hda_bus_new(struct snd_card *card, *busp = NULL; bus = kzalloc(sizeof(*bus), GFP_KERNEL); - if (bus == NULL) { - dev_err(card->dev, "can't allocate struct hda_bus\n"); + if (!bus) return -ENOMEM; - } bus->card = card; mutex_init(&bus->cmd_mutex); @@ -1223,10 +1221,8 @@ int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card, } codec = kzalloc(sizeof(*codec), GFP_KERNEL); - if (codec == NULL) { - dev_err(card->dev, "can't allocate struct hda_codec\n"); + if (!codec) return -ENOMEM; - } dev = hda_codec_dev(codec); device_initialize(dev); @@ -1307,10 +1303,8 @@ int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card, fg = codec->afg ? codec->afg : codec->mfg; err = read_widget_caps(codec, fg); - if (err < 0) { - dev_err(card->dev, "cannot malloc\n"); + if (err < 0) goto error; - } err = read_pin_defaults(codec); if (err < 0) goto error; @@ -1371,10 +1365,8 @@ int snd_hda_codec_update_widgets(struct hda_codec *codec) kfree(codec->wcaps); fg = codec->afg ? codec->afg : codec->mfg; err = read_widget_caps(codec, fg); - if (err < 0) { - codec_err(codec, "cannot malloc\n"); + if (err < 0) return err; - } snd_array_free(&codec->init_pins); err = read_pin_defaults(codec); diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c index f50863a5159d..be02bca6f7e6 100644 --- a/sound/pci/hda/hda_controller.c +++ b/sound/pci/hda/hda_controller.c @@ -974,14 +974,9 @@ static int azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec, */ static int azx_alloc_cmd_io(struct azx *chip) { - int err; - /* single page (at least 4096 bytes) must suffice for both ringbuffes */ - err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV, - PAGE_SIZE, &chip->rb); - if (err < 0) - dev_err(chip->card->dev, "cannot allocate CORB/RIRB\n"); - return err; + return chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV, + PAGE_SIZE, &chip->rb); } EXPORT_SYMBOL_GPL(azx_alloc_cmd_io); @@ -1472,7 +1467,6 @@ static void azx_load_dsp_cleanup(struct hda_bus *bus, int azx_alloc_stream_pages(struct azx *chip) { int i, err; - struct snd_card *card = chip->card; for (i = 0; i < chip->num_streams; i++) { dsp_lock_init(&chip->azx_dev[i]); @@ -1480,18 +1474,14 @@ int azx_alloc_stream_pages(struct azx *chip) err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV, BDL_SIZE, &chip->azx_dev[i].bdl); - if (err < 0) { - dev_err(card->dev, "cannot allocate BDL\n"); + if (err < 0) return -ENOMEM; - } } /* allocate memory for the position buffer */ err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV, chip->num_streams * 8, &chip->posbuf); - if (err < 0) { - dev_err(card->dev, "cannot allocate posbuf\n"); + if (err < 0) return -ENOMEM; - } /* allocate CORB/RIRB */ err = azx_alloc_cmd_io(chip); diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index e75e8137e296..f7fb1b51d446 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c @@ -1383,7 +1383,6 @@ static int azx_create(struct snd_card *card, struct pci_dev *pci, hda = kzalloc(sizeof(*hda), GFP_KERNEL); if (!hda) { - dev_err(card->dev, "Cannot allocate hda\n"); pci_disable_device(pci); return -ENOMEM; } @@ -1564,10 +1563,8 @@ static int azx_first_init(struct azx *chip) chip->num_streams = chip->playback_streams + chip->capture_streams; chip->azx_dev = kcalloc(chip->num_streams, sizeof(*chip->azx_dev), GFP_KERNEL); - if (!chip->azx_dev) { - dev_err(card->dev, "cannot malloc azx_dev\n"); + if (!chip->azx_dev) return -ENOMEM; - } err = azx_alloc_stream_pages(chip); if (err < 0) -- cgit v1.2.3 From bbbc7e8502c95237dbd86cc4d0a12ca9a6b18c8f Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 27 Feb 2015 17:43:19 +0100 Subject: ALSA: hda - Allocate hda_pcm objects dynamically So far, the hda_codec object kept the hda_pcm list in an array, and the codec driver was expected to assign the array. However, this makes the object life cycle management harder, because the assigned array is freed at the codec driver detach while it might be still accessed by the opened streams. In this patch, we allocate each hda_pcm object dynamically and manage it as a linked list. Each object has a kref refcount, and both the codec driver binder and the PCM open/close touches it, so that the object won't be freed while in use. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_codec.c | 116 +++++++++++++++++++++++++++--------------- sound/pci/hda/hda_codec.h | 18 ++++++- sound/pci/hda/hda_generic.c | 28 +++++----- sound/pci/hda/hda_generic.h | 2 +- sound/pci/hda/hda_proc.c | 6 +-- sound/pci/hda/patch_ca0132.c | 29 +++++------ sound/pci/hda/patch_hdmi.c | 30 ++++------- sound/pci/hda/patch_realtek.c | 2 +- sound/pci/hda/patch_si3054.c | 11 ++-- sound/pci/hda/patch_via.c | 6 ++- 10 files changed, 145 insertions(+), 103 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 262c41a8f96e..20283bead10a 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -1116,6 +1116,60 @@ get_hda_cvt_setup(struct hda_codec *codec, hda_nid_t nid) return p; } +/* + * PCM device + */ +static void release_pcm(struct kref *kref) +{ + struct hda_pcm *pcm = container_of(kref, struct hda_pcm, kref); + + if (pcm->pcm) + snd_device_free(pcm->codec->card, pcm->pcm); + clear_bit(pcm->device, pcm->codec->bus->pcm_dev_bits); + kfree(pcm->name); + kfree(pcm); +} + +void snd_hda_codec_pcm_put(struct hda_pcm *pcm) +{ + kref_put(&pcm->kref, release_pcm); +} +EXPORT_SYMBOL_GPL(snd_hda_codec_pcm_put); + +struct hda_pcm *snd_hda_codec_pcm_new(struct hda_codec *codec, + const char *fmt, ...) +{ + struct hda_pcm *pcm; + va_list args; + + va_start(args, fmt); + pcm = kzalloc(sizeof(*pcm), GFP_KERNEL); + if (!pcm) + return NULL; + + pcm->codec = codec; + kref_init(&pcm->kref); + pcm->name = kvasprintf(GFP_KERNEL, fmt, args); + if (!pcm->name) { + kfree(pcm); + return NULL; + } + + list_add_tail(&pcm->list, &codec->pcm_list_head); + return pcm; +} +EXPORT_SYMBOL_GPL(snd_hda_codec_pcm_new); + +static void codec_release_pcms(struct hda_codec *codec) +{ + struct hda_pcm *pcm, *n; + + list_for_each_entry_safe(pcm, n, &codec->pcm_list_head, list) { + list_del_init(&pcm->list); + snd_hda_codec_pcm_put(pcm); + } +} + /* * codec destructor */ @@ -1124,6 +1178,7 @@ static void snd_hda_codec_free(struct hda_codec *codec) if (!codec) return; cancel_delayed_work_sync(&codec->jackpoll_work); + codec_release_pcms(codec); if (device_is_registered(hda_codec_dev(codec))) device_del(hda_codec_dev(codec)); snd_hda_jack_tbl_clear(codec); @@ -1251,6 +1306,7 @@ int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card, snd_array_init(&codec->jacktbl, sizeof(struct hda_jack_tbl), 16); snd_array_init(&codec->verbs, sizeof(struct hda_verb *), 8); INIT_LIST_HEAD(&codec->conn_list); + INIT_LIST_HEAD(&codec->pcm_list_head); INIT_DELAYED_WORK(&codec->jackpoll_work, hda_jackpoll_work); codec->depop_delay = -1; @@ -2370,9 +2426,8 @@ int snd_hda_lock_devices(struct hda_bus *bus) goto err_clear; list_for_each_entry(codec, &bus->codec_list, list) { - int pcm; - for (pcm = 0; pcm < codec->num_pcms; pcm++) { - struct hda_pcm *cpcm = &codec->pcm_info[pcm]; + struct hda_pcm *cpcm; + list_for_each_entry(cpcm, &codec->pcm_list_head, list) { if (!cpcm->pcm) continue; if (cpcm->pcm->streams[0].substream_opened || @@ -2419,8 +2474,6 @@ EXPORT_SYMBOL_GPL(snd_hda_unlock_devices); int snd_hda_codec_reset(struct hda_codec *codec) { struct hda_bus *bus = codec->bus; - struct snd_card *card = codec->card; - int i; if (snd_hda_lock_devices(bus) < 0) return -EBUSY; @@ -2429,14 +2482,7 @@ int snd_hda_codec_reset(struct hda_codec *codec) cancel_delayed_work_sync(&codec->jackpoll_work); flush_workqueue(bus->workq); snd_hda_ctls_clear(codec); - /* release PCMs */ - for (i = 0; i < codec->num_pcms; i++) { - if (codec->pcm_info[i].pcm) { - snd_device_free(card, codec->pcm_info[i].pcm); - clear_bit(codec->pcm_info[i].device, - bus->pcm_dev_bits); - } - } + codec_release_pcms(codec); snd_hda_detach_beep_device(codec); if (device_is_registered(hda_codec_dev(codec))) device_del(hda_codec_dev(codec)); @@ -2454,8 +2500,6 @@ int snd_hda_codec_reset(struct hda_codec *codec) snd_array_free(&codec->cvt_setups); snd_array_free(&codec->spdif_out); snd_array_free(&codec->verbs); - codec->num_pcms = 0; - codec->pcm_info = NULL; codec->preset = NULL; codec->slave_dig_outs = NULL; codec->spdif_status_reset = 0; @@ -3952,12 +3996,12 @@ static void hda_call_codec_resume(struct hda_codec *codec) static int hda_codec_runtime_suspend(struct device *dev) { struct hda_codec *codec = dev_to_hda_codec(dev); + struct hda_pcm *pcm; unsigned int state; - int i; cancel_delayed_work_sync(&codec->jackpoll_work); - for (i = 0; i < codec->num_pcms; i++) - snd_pcm_suspend_all(codec->pcm_info[i].pcm); + list_for_each_entry(pcm, &codec->pcm_list_head, list) + snd_pcm_suspend_all(pcm->pcm); state = hda_call_codec_suspend(codec); if (codec->d3_stop_clk && codec->epss && (state & AC_PWRST_CLK_STOP_OK)) clear_bit(codec->addr, &codec->bus->codec_powered); @@ -4018,22 +4062,21 @@ EXPORT_SYMBOL_GPL(snd_hda_build_controls); */ static int add_std_chmaps(struct hda_codec *codec) { - int i, str, err; + struct hda_pcm *pcm; + int str, err; - for (i = 0; i < codec->num_pcms; i++) { + list_for_each_entry(pcm, &codec->pcm_list_head, list) { for (str = 0; str < 2; str++) { - struct snd_pcm *pcm = codec->pcm_info[i].pcm; - struct hda_pcm_stream *hinfo = - &codec->pcm_info[i].stream[str]; + struct hda_pcm_stream *hinfo = &pcm->stream[str]; struct snd_pcm_chmap *chmap; const struct snd_pcm_chmap_elem *elem; - if (codec->pcm_info[i].own_chmap) + if (pcm->own_chmap) continue; if (!pcm || !hinfo->substreams) continue; elem = hinfo->chmap ? hinfo->chmap : snd_pcm_std_chmaps; - err = snd_pcm_add_chmap_ctls(pcm, str, elem, + err = snd_pcm_add_chmap_ctls(pcm->pcm, str, elem, hinfo->channels_max, 0, &chmap); if (err < 0) @@ -4564,10 +4607,10 @@ static int get_empty_pcm_device(struct hda_bus *bus, unsigned int type) /* call build_pcms ops of the given codec and set up the default parameters */ int snd_hda_codec_parse_pcms(struct hda_codec *codec) { - unsigned int pcm; + struct hda_pcm *cpcm; int err; - if (codec->num_pcms) + if (!list_empty(&codec->pcm_list_head)) return 0; /* already parsed */ if (!codec->patch_ops.build_pcms) @@ -4580,8 +4623,7 @@ int snd_hda_codec_parse_pcms(struct hda_codec *codec) return err; } - for (pcm = 0; pcm < codec->num_pcms; pcm++) { - struct hda_pcm *cpcm = &codec->pcm_info[pcm]; + list_for_each_entry(cpcm, &codec->pcm_list_head, list) { int stream; for (stream = 0; stream < 2; stream++) { @@ -4589,8 +4631,6 @@ int snd_hda_codec_parse_pcms(struct hda_codec *codec) if (!info->substreams) continue; - if (snd_BUG_ON(!cpcm->name)) - return -EINVAL; err = set_pcm_default_values(codec, info); if (err < 0) { codec_warn(codec, @@ -4608,7 +4648,7 @@ int snd_hda_codec_parse_pcms(struct hda_codec *codec) int snd_hda_codec_build_pcms(struct hda_codec *codec) { struct hda_bus *bus = codec->bus; - unsigned int pcm; + struct hda_pcm *cpcm; int dev, err; if (snd_BUG_ON(!bus->ops.attach_pcm)) @@ -4621,9 +4661,7 @@ int snd_hda_codec_build_pcms(struct hda_codec *codec) } /* attach a new PCM streams */ - for (pcm = 0; pcm < codec->num_pcms; pcm++) { - struct hda_pcm *cpcm = &codec->pcm_info[pcm]; - + list_for_each_entry(cpcm, &codec->pcm_list_head, list) { if (cpcm->pcm) continue; /* already attached */ if (!cpcm->stream[0].substreams && !cpcm->stream[1].substreams) @@ -4651,11 +4689,9 @@ int snd_hda_codec_build_pcms(struct hda_codec *codec) * * Create PCM information for each codec included in the bus. * - * The build_pcms codec patch is requested to set up codec->num_pcms and - * codec->pcm_info properly. The array is referred by the top-level driver - * to create its PCM instances. - * The allocated codec->pcm_info should be released in codec->patch_ops.free - * callback. + * The build_pcms codec patch is requested to create and assign new + * hda_pcm objects. The codec is responsible to call snd_hda_codec_pcm_new() + * and fills the fields. Later they are instantiated by this function. * * At least, substreams, channels_min and channels_max must be filled for * each stream. substreams = 0 indicates that the stream doesn't exist. diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index 8908a0768736..2ccd6f9a91fe 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h @@ -21,6 +21,7 @@ #ifndef __SOUND_HDA_CODEC_H #define __SOUND_HDA_CODEC_H +#include #include #include #include @@ -268,6 +269,10 @@ struct hda_pcm { int device; /* device number to assign */ struct snd_pcm *pcm; /* assigned PCM instance */ bool own_chmap; /* codec driver provides own channel maps */ + /* private: */ + struct hda_codec *codec; + struct kref kref; + struct list_head list; }; /* codec information */ @@ -301,8 +306,7 @@ struct hda_codec { struct hda_codec_ops patch_ops; /* PCM to create, set by patch_ops.build_pcms callback */ - unsigned int num_pcms; - struct hda_pcm *pcm_info; + struct list_head pcm_list_head; /* codec specific info */ void *spec; @@ -521,6 +525,16 @@ int snd_hda_build_pcms(struct hda_bus *bus); int snd_hda_codec_parse_pcms(struct hda_codec *codec); int snd_hda_codec_build_pcms(struct hda_codec *codec); +__printf(2, 3) +struct hda_pcm *snd_hda_codec_pcm_new(struct hda_codec *codec, + const char *fmt, ...); + +static inline void snd_hda_codec_pcm_get(struct hda_pcm *pcm) +{ + kref_get(&pcm->kref); +} +void snd_hda_codec_pcm_put(struct hda_pcm *pcm); + int snd_hda_codec_prepare(struct hda_codec *codec, struct hda_pcm_stream *hinfo, unsigned int stream, diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c index 947d1a50f384..092f06fd21bd 100644 --- a/sound/pci/hda/hda_generic.c +++ b/sound/pci/hda/hda_generic.c @@ -4644,7 +4644,7 @@ int snd_hda_gen_build_controls(struct hda_codec *codec) err = snd_hda_create_dig_out_ctls(codec, spec->multiout.dig_out_nid, spec->multiout.dig_out_nid, - spec->pcm_rec[1].pcm_type); + spec->pcm_rec[1]->pcm_type); if (err < 0) return err; if (!spec->no_analog) { @@ -5115,20 +5115,20 @@ static void fill_pcm_stream_name(char *str, size_t len, const char *sfx, int snd_hda_gen_build_pcms(struct hda_codec *codec) { struct hda_gen_spec *spec = codec->spec; - struct hda_pcm *info = spec->pcm_rec; + struct hda_pcm *info; const struct hda_pcm_stream *p; bool have_multi_adcs; - codec->num_pcms = 1; - codec->pcm_info = info; - if (spec->no_analog) goto skip_analog; fill_pcm_stream_name(spec->stream_name_analog, sizeof(spec->stream_name_analog), " Analog", codec->chip_name); - info->name = spec->stream_name_analog; + info = snd_hda_codec_pcm_new(codec, "%s", spec->stream_name_analog); + if (!info) + return -ENOMEM; + spec->pcm_rec[0] = info; if (spec->multiout.num_dacs > 0) { p = spec->stream_analog_playback; @@ -5161,10 +5161,12 @@ int snd_hda_gen_build_pcms(struct hda_codec *codec) fill_pcm_stream_name(spec->stream_name_digital, sizeof(spec->stream_name_digital), " Digital", codec->chip_name); - codec->num_pcms = 2; + info = snd_hda_codec_pcm_new(codec, "%s", + spec->stream_name_digital); + if (!info) + return -ENOMEM; codec->slave_dig_outs = spec->multiout.slave_dig_outs; - info = spec->pcm_rec + 1; - info->name = spec->stream_name_digital; + spec->pcm_rec[1] = info; if (spec->dig_out_type) info->pcm_type = spec->dig_out_type; else @@ -5198,9 +5200,11 @@ int snd_hda_gen_build_pcms(struct hda_codec *codec) fill_pcm_stream_name(spec->stream_name_alt_analog, sizeof(spec->stream_name_alt_analog), " Alt Analog", codec->chip_name); - codec->num_pcms = 3; - info = spec->pcm_rec + 2; - info->name = spec->stream_name_alt_analog; + info = snd_hda_codec_pcm_new(codec, "%s", + spec->stream_name_alt_analog); + if (!info) + return -ENOMEM; + spec->pcm_rec[2] = info; if (spec->alt_dac_nid) { p = spec->stream_analog_alt_playback; if (!p) diff --git a/sound/pci/hda/hda_generic.h b/sound/pci/hda/hda_generic.h index 3d852660443a..b211f889b335 100644 --- a/sound/pci/hda/hda_generic.h +++ b/sound/pci/hda/hda_generic.h @@ -144,7 +144,7 @@ struct hda_gen_spec { int const_channel_count; /* channel count for all */ /* PCM information */ - struct hda_pcm pcm_rec[3]; /* used in build_pcms() */ + struct hda_pcm *pcm_rec[3]; /* used in build_pcms() */ /* dynamic controls, init_verbs and input_mux */ struct auto_pin_cfg autocfg; diff --git a/sound/pci/hda/hda_proc.c b/sound/pci/hda/hda_proc.c index cc32b878ae2e..aeb983e7506d 100644 --- a/sound/pci/hda/hda_proc.c +++ b/sound/pci/hda/hda_proc.c @@ -99,10 +99,10 @@ static void print_nid_array(struct snd_info_buffer *buffer, static void print_nid_pcms(struct snd_info_buffer *buffer, struct hda_codec *codec, hda_nid_t nid) { - int pcm, type; + int type; struct hda_pcm *cpcm; - for (pcm = 0; pcm < codec->num_pcms; pcm++) { - cpcm = &codec->pcm_info[pcm]; + + list_for_each_entry(cpcm, &codec->pcm_list_head, list) { for (type = 0; type < 2; type++) { if (cpcm->stream[type].nid != nid || cpcm->pcm == NULL) continue; diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c index ced3e82d9e23..555781fad26f 100644 --- a/sound/pci/hda/patch_ca0132.c +++ b/sound/pci/hda/patch_ca0132.c @@ -719,7 +719,6 @@ struct ca0132_spec { unsigned int num_inputs; hda_nid_t shared_mic_nid; hda_nid_t shared_out_nid; - struct hda_pcm pcm_rec[5]; /* PCM information */ /* chip access */ struct mutex chipio_mutex; /* chip access mutex */ @@ -4036,12 +4035,11 @@ static struct hda_pcm_stream ca0132_pcm_digital_capture = { static int ca0132_build_pcms(struct hda_codec *codec) { struct ca0132_spec *spec = codec->spec; - struct hda_pcm *info = spec->pcm_rec; + struct hda_pcm *info; - codec->pcm_info = info; - codec->num_pcms = 0; - - info->name = "CA0132 Analog"; + info = snd_hda_codec_pcm_new(codec, "CA0132 Analog"); + if (!info) + return -ENOMEM; info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ca0132_pcm_analog_playback; info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dacs[0]; info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = @@ -4049,27 +4047,27 @@ static int ca0132_build_pcms(struct hda_codec *codec) info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture; info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1; info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[0]; - codec->num_pcms++; - info++; - info->name = "CA0132 Analog Mic-In2"; + info = snd_hda_codec_pcm_new(codec, "CA0132 Analog Mic-In2"); + if (!info) + return -ENOMEM; info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture; info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1; info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[1]; - codec->num_pcms++; - info++; - info->name = "CA0132 What U Hear"; + info = snd_hda_codec_pcm_new(codec, "CA0132 What U Hear"); + if (!info) + return -ENOMEM; info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture; info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1; info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[2]; - codec->num_pcms++; if (!spec->dig_out && !spec->dig_in) return 0; - info++; - info->name = "CA0132 Digital"; + info = snd_hda_codec_pcm_new(codec, "CA0132 Digital"); + if (!info) + return -ENOMEM; info->pcm_type = HDA_PCM_TYPE_SPDIF; if (spec->dig_out) { info->stream[SNDRV_PCM_STREAM_PLAYBACK] = @@ -4081,7 +4079,6 @@ static int ca0132_build_pcms(struct hda_codec *codec) ca0132_pcm_digital_capture; info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in; } - codec->num_pcms++; return 0; } diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c index 0f8354cbc7a7..708bbed15ea3 100644 --- a/sound/pci/hda/patch_hdmi.c +++ b/sound/pci/hda/patch_hdmi.c @@ -86,7 +86,6 @@ struct hdmi_spec_per_pin { bool non_pcm; bool chmap_set; /* channel-map override by ALSA API? */ unsigned char chmap[8]; /* ALSA API channel-map */ - char pcm_name[8]; /* filled in build_pcm callbacks */ #ifdef CONFIG_PROC_FS struct snd_info_entry *proc_entry; #endif @@ -132,7 +131,7 @@ struct hdmi_spec { int num_pins; struct snd_array pins; /* struct hdmi_spec_per_pin */ - struct snd_array pcm_rec; /* struct hda_pcm */ + struct hda_pcm *pcm_rec[16]; unsigned int channels_max; /* max over all cvts */ struct hdmi_eld temp_eld; @@ -355,8 +354,7 @@ static struct cea_channel_speaker_allocation channel_allocations[] = { ((struct hdmi_spec_per_pin *)snd_array_elem(&spec->pins, idx)) #define get_cvt(spec, idx) \ ((struct hdmi_spec_per_cvt *)snd_array_elem(&spec->cvts, idx)) -#define get_pcm_rec(spec, idx) \ - ((struct hda_pcm *)snd_array_elem(&spec->pcm_rec, idx)) +#define get_pcm_rec(spec, idx) ((spec)->pcm_rec[idx]) static int pin_nid_to_pin_index(struct hda_codec *codec, hda_nid_t pin_nid) { @@ -2056,11 +2054,10 @@ static int generic_hdmi_build_pcms(struct hda_codec *codec) struct hdmi_spec_per_pin *per_pin; per_pin = get_pin(spec, pin_idx); - sprintf(per_pin->pcm_name, "HDMI %d", pin_idx); - info = snd_array_new(&spec->pcm_rec); + info = snd_hda_codec_pcm_new(codec, "HDMI %d", pin_idx); if (!info) return -ENOMEM; - info->name = per_pin->pcm_name; + spec->pcm_rec[pin_idx] = info; info->pcm_type = HDA_PCM_TYPE_HDMI; info->own_chmap = true; @@ -2070,9 +2067,6 @@ static int generic_hdmi_build_pcms(struct hda_codec *codec) /* other pstr fields are set in open */ } - codec->num_pcms = spec->num_pins; - codec->pcm_info = spec->pcm_rec.list; - return 0; } @@ -2125,13 +2119,15 @@ static int generic_hdmi_build_controls(struct hda_codec *codec) /* add channel maps */ for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { + struct hda_pcm *pcm; struct snd_pcm_chmap *chmap; struct snd_kcontrol *kctl; int i; - if (!codec->pcm_info[pin_idx].pcm) + pcm = spec->pcm_rec[pin_idx]; + if (!pcm || !pcm->pcm) break; - err = snd_pcm_add_chmap_ctls(codec->pcm_info[pin_idx].pcm, + err = snd_pcm_add_chmap_ctls(pcm->pcm, SNDRV_PCM_STREAM_PLAYBACK, NULL, 0, pin_idx, &chmap); if (err < 0) @@ -2186,14 +2182,12 @@ static void hdmi_array_init(struct hdmi_spec *spec, int nums) { snd_array_init(&spec->pins, sizeof(struct hdmi_spec_per_pin), nums); snd_array_init(&spec->cvts, sizeof(struct hdmi_spec_per_cvt), nums); - snd_array_init(&spec->pcm_rec, sizeof(struct hda_pcm), nums); } static void hdmi_array_free(struct hdmi_spec *spec) { snd_array_free(&spec->pins); snd_array_free(&spec->cvts); - snd_array_free(&spec->pcm_rec); } static void generic_hdmi_free(struct hda_codec *codec) @@ -2381,11 +2375,10 @@ static int simple_playback_build_pcms(struct hda_codec *codec) chans = get_wcaps(codec, per_cvt->cvt_nid); chans = get_wcaps_channels(chans); - info = snd_array_new(&spec->pcm_rec); + info = snd_hda_codec_pcm_new(codec, "HDMI 0"); if (!info) return -ENOMEM; - info->name = get_pin(spec, 0)->pcm_name; - sprintf(info->name, "HDMI 0"); + spec->pcm_rec[0] = info; info->pcm_type = HDA_PCM_TYPE_HDMI; pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK]; *pstr = spec->pcm_playback; @@ -2393,9 +2386,6 @@ static int simple_playback_build_pcms(struct hda_codec *codec) if (pstr->channels_max <= 2 && chans && chans <= 16) pstr->channels_max = chans; - codec->num_pcms = 1; - codec->pcm_info = info; - return 0; } diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c index 70808f92276a..0a5a2246e57a 100644 --- a/sound/pci/hda/patch_realtek.c +++ b/sound/pci/hda/patch_realtek.c @@ -5843,7 +5843,7 @@ static void alc_fixup_bass_chmap(struct hda_codec *codec, { if (action == HDA_FIXUP_ACT_BUILD) { struct alc_spec *spec = codec->spec; - spec->gen.pcm_rec[0].stream[0].chmap = asus_pcm_2_1_chmaps; + spec->gen.pcm_rec[0]->stream[0].chmap = asus_pcm_2_1_chmaps; } } diff --git a/sound/pci/hda/patch_si3054.c b/sound/pci/hda/patch_si3054.c index 38a477333321..df243134baa8 100644 --- a/sound/pci/hda/patch_si3054.c +++ b/sound/pci/hda/patch_si3054.c @@ -83,7 +83,6 @@ struct si3054_spec { unsigned international; - struct hda_pcm pcm; }; @@ -199,11 +198,11 @@ static const struct hda_pcm_stream si3054_pcm = { static int si3054_build_pcms(struct hda_codec *codec) { - struct si3054_spec *spec = codec->spec; - struct hda_pcm *info = &spec->pcm; - codec->num_pcms = 1; - codec->pcm_info = info; - info->name = "Si3054 Modem"; + struct hda_pcm *info; + + info = snd_hda_codec_pcm_new(codec, "Si3054 Modem"); + if (!info) + return -ENOMEM; info->stream[SNDRV_PCM_STREAM_PLAYBACK] = si3054_pcm; info->stream[SNDRV_PCM_STREAM_CAPTURE] = si3054_pcm; info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = codec->mfg; diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 57ad503ff940..11a05638e03b 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -683,8 +683,10 @@ static int vt1708_build_pcms(struct hda_codec *codec) * 24bit samples are used. Until any workaround is found, * disable the 24bit format, so far. */ - for (i = 0; i < codec->num_pcms; i++) { - struct hda_pcm *info = &spec->gen.pcm_rec[i]; + for (i = 0; i < ARRAY_SIZE(spec->gen.pcm_rec); i++) { + struct hda_pcm *info = spec->gen.pcm_rec[i]; + if (!info) + continue; if (!info->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams || info->pcm_type != HDA_PCM_TYPE_AUDIO) continue; -- cgit v1.2.3 From 61ca4107a16828559e2463e49b87002990da0b98 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 27 Feb 2015 17:57:55 +0100 Subject: ALSA: hda - Don't assume non-NULL PCM ops The PCM ops might be set NULL, or cleared to NULL when the driver is unbound. Give a proper NULL check at each place to be more robust. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_codec.c | 9 +++++++-- sound/pci/hda/hda_controller.c | 30 +++++++++++++++++++----------- 2 files changed, 26 insertions(+), 13 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 20283bead10a..3bd9158addc2 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -4525,7 +4525,11 @@ int snd_hda_codec_prepare(struct hda_codec *codec, { int ret; mutex_lock(&codec->bus->prepare_mutex); - ret = hinfo->ops.prepare(hinfo, codec, stream, format, substream); + if (hinfo->ops.prepare) + ret = hinfo->ops.prepare(hinfo, codec, stream, format, + substream); + else + ret = -ENODEV; if (ret >= 0) purify_inactive_streams(codec); mutex_unlock(&codec->bus->prepare_mutex); @@ -4546,7 +4550,8 @@ void snd_hda_codec_cleanup(struct hda_codec *codec, struct snd_pcm_substream *substream) { mutex_lock(&codec->bus->prepare_mutex); - hinfo->ops.cleanup(hinfo, codec, substream); + if (hinfo->ops.cleanup) + hinfo->ops.cleanup(hinfo, codec, substream); mutex_unlock(&codec->bus->prepare_mutex); } EXPORT_SYMBOL_GPL(snd_hda_codec_cleanup); diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c index be02bca6f7e6..ad85f9bfaf57 100644 --- a/sound/pci/hda/hda_controller.c +++ b/sound/pci/hda/hda_controller.c @@ -416,7 +416,8 @@ static int azx_pcm_close(struct snd_pcm_substream *substream) azx_dev->running = 0; spin_unlock_irqrestore(&chip->reg_lock, flags); azx_release_device(azx_dev); - hinfo->ops.close(hinfo, apcm->codec, substream); + if (hinfo->ops.close) + hinfo->ops.close(hinfo, apcm->codec, substream); snd_hda_power_down(apcm->codec); mutex_unlock(&chip->open_mutex); return 0; @@ -808,8 +809,8 @@ static int azx_pcm_open(struct snd_pcm_substream *substream) mutex_lock(&chip->open_mutex); azx_dev = azx_assign_device(chip, substream); if (azx_dev == NULL) { - mutex_unlock(&chip->open_mutex); - return -EBUSY; + err = -EBUSY; + goto unlock; } runtime->hw = azx_pcm_hw; runtime->hw.channels_min = hinfo->channels_min; @@ -844,12 +845,13 @@ static int azx_pcm_open(struct snd_pcm_substream *substream) snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, buff_step); snd_hda_power_up(apcm->codec); - err = hinfo->ops.open(hinfo, apcm->codec, substream); + if (hinfo->ops.open) + err = hinfo->ops.open(hinfo, apcm->codec, substream); + else + err = -ENODEV; if (err < 0) { azx_release_device(azx_dev); - snd_hda_power_down(apcm->codec); - mutex_unlock(&chip->open_mutex); - return err; + goto powerdown; } snd_pcm_limit_hw_rates(runtime); /* sanity check */ @@ -858,10 +860,10 @@ static int azx_pcm_open(struct snd_pcm_substream *substream) snd_BUG_ON(!runtime->hw.formats) || snd_BUG_ON(!runtime->hw.rates)) { azx_release_device(azx_dev); - hinfo->ops.close(hinfo, apcm->codec, substream); - snd_hda_power_down(apcm->codec); - mutex_unlock(&chip->open_mutex); - return -EINVAL; + if (hinfo->ops.close) + hinfo->ops.close(hinfo, apcm->codec, substream); + err = -EINVAL; + goto powerdown; } /* disable LINK_ATIME timestamps for capture streams @@ -880,6 +882,12 @@ static int azx_pcm_open(struct snd_pcm_substream *substream) snd_pcm_set_sync(substream); mutex_unlock(&chip->open_mutex); return 0; + + powerdown: + snd_hda_power_down(apcm->codec); + unlock: + mutex_unlock(&chip->open_mutex); + return err; } static int azx_pcm_mmap(struct snd_pcm_substream *substream, -- cgit v1.2.3 From 9a6246ff78ac33af78f82704cde6fec361597eea Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 27 Feb 2015 18:17:28 +0100 Subject: ALSA: hda - Implement unbind more safely Now we have all pieces ready, and put them into places: - add the hda_pcm refcount to azx_pcm_open() and azx_pcm_close(), - call the most of cleanup code in hda_codec_reset() from the codec driver remove, - call the same code also from the hda_codec object free. Then the codec driver can be unbound more safely now. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_bind.c | 3 +- sound/pci/hda/hda_codec.c | 70 ++++++++++++++++++++++-------------------- sound/pci/hda/hda_codec.h | 1 + sound/pci/hda/hda_controller.c | 3 ++ sound/pci/hda/hda_local.h | 1 + 5 files changed, 43 insertions(+), 35 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_bind.c b/sound/pci/hda/hda_bind.c index 2d00417494e2..311896a23cd1 100644 --- a/sound/pci/hda/hda_bind.c +++ b/sound/pci/hda/hda_bind.c @@ -125,8 +125,7 @@ static int hda_codec_driver_remove(struct device *dev) if (codec->patch_ops.free) codec->patch_ops.free(codec); - codec->preset = NULL; - memset(&codec->patch_ops, 0, sizeof(codec->patch_ops)); + snd_hda_codec_cleanup_for_unbind(codec); module_put(dev->driver->owner); return 0; } diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 3bd9158addc2..2c7e481a9171 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -1160,36 +1160,62 @@ struct hda_pcm *snd_hda_codec_pcm_new(struct hda_codec *codec, } EXPORT_SYMBOL_GPL(snd_hda_codec_pcm_new); +/* + * codec destructor + */ static void codec_release_pcms(struct hda_codec *codec) { struct hda_pcm *pcm, *n; list_for_each_entry_safe(pcm, n, &codec->pcm_list_head, list) { list_del_init(&pcm->list); + if (pcm->pcm) + snd_device_disconnect(codec->card, pcm->pcm); snd_hda_codec_pcm_put(pcm); } } -/* - * codec destructor - */ +void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec) +{ + cancel_delayed_work_sync(&codec->jackpoll_work); + flush_workqueue(codec->bus->workq); + if (!codec->in_freeing) + snd_hda_ctls_clear(codec); + codec_release_pcms(codec); + snd_hda_detach_beep_device(codec); + memset(&codec->patch_ops, 0, sizeof(codec->patch_ops)); + snd_hda_jack_tbl_clear(codec); + codec->proc_widget_hook = NULL; + codec->spec = NULL; + + free_hda_cache(&codec->amp_cache); + free_hda_cache(&codec->cmd_cache); + init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info)); + init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head)); + + /* free only driver_pins so that init_pins + user_pins are restored */ + snd_array_free(&codec->driver_pins); + snd_array_free(&codec->cvt_setups); + snd_array_free(&codec->spdif_out); + snd_array_free(&codec->verbs); + codec->preset = NULL; + codec->slave_dig_outs = NULL; + codec->spdif_status_reset = 0; + snd_array_free(&codec->mixers); + snd_array_free(&codec->nids); + remove_conn_list(codec); +} + static void snd_hda_codec_free(struct hda_codec *codec) { if (!codec) return; - cancel_delayed_work_sync(&codec->jackpoll_work); - codec_release_pcms(codec); + codec->in_freeing = 1; if (device_is_registered(hda_codec_dev(codec))) device_del(hda_codec_dev(codec)); - snd_hda_jack_tbl_clear(codec); free_init_pincfgs(codec); flush_workqueue(codec->bus->workq); list_del(&codec->list); - snd_array_free(&codec->mixers); - snd_array_free(&codec->nids); - snd_array_free(&codec->cvt_setups); - snd_array_free(&codec->spdif_out); - remove_conn_list(codec); codec->bus->caddr_tbl[codec->addr] = NULL; clear_bit(codec->addr, &codec->bus->codec_powered); snd_hda_sysfs_clear(codec); @@ -2479,31 +2505,9 @@ int snd_hda_codec_reset(struct hda_codec *codec) return -EBUSY; /* OK, let it free */ - cancel_delayed_work_sync(&codec->jackpoll_work); - flush_workqueue(bus->workq); - snd_hda_ctls_clear(codec); - codec_release_pcms(codec); - snd_hda_detach_beep_device(codec); if (device_is_registered(hda_codec_dev(codec))) device_del(hda_codec_dev(codec)); - memset(&codec->patch_ops, 0, sizeof(codec->patch_ops)); - snd_hda_jack_tbl_clear(codec); - codec->proc_widget_hook = NULL; - codec->spec = NULL; - free_hda_cache(&codec->amp_cache); - free_hda_cache(&codec->cmd_cache); - init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info)); - init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head)); - /* free only driver_pins so that init_pins + user_pins are restored */ - snd_array_free(&codec->driver_pins); - snd_array_free(&codec->cvt_setups); - snd_array_free(&codec->spdif_out); - snd_array_free(&codec->verbs); - codec->preset = NULL; - codec->slave_dig_outs = NULL; - codec->spdif_status_reset = 0; - /* allow device access again */ snd_hda_unlock_devices(bus); return 0; diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index 2ccd6f9a91fe..fc62ca51fd35 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h @@ -350,6 +350,7 @@ struct hda_codec { #endif /* misc flags */ + unsigned int in_freeing:1; /* being released */ unsigned int spdif_status_reset :1; /* needs to toggle SPDIF for each * status change * (e.g. Realtek codecs) diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c index ad85f9bfaf57..cae50d5ffb81 100644 --- a/sound/pci/hda/hda_controller.c +++ b/sound/pci/hda/hda_controller.c @@ -420,6 +420,7 @@ static int azx_pcm_close(struct snd_pcm_substream *substream) hinfo->ops.close(hinfo, apcm->codec, substream); snd_hda_power_down(apcm->codec); mutex_unlock(&chip->open_mutex); + snd_hda_codec_pcm_put(apcm->info); return 0; } @@ -806,6 +807,7 @@ static int azx_pcm_open(struct snd_pcm_substream *substream) int err; int buff_step; + snd_hda_codec_pcm_get(apcm->info); mutex_lock(&chip->open_mutex); azx_dev = azx_assign_device(chip, substream); if (azx_dev == NULL) { @@ -887,6 +889,7 @@ static int azx_pcm_open(struct snd_pcm_substream *substream) snd_hda_power_down(apcm->codec); unlock: mutex_unlock(&chip->open_mutex); + snd_hda_codec_pcm_put(apcm->info); return err; } diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h index 8588813163e3..1d001647fc47 100644 --- a/sound/pci/hda/hda_local.h +++ b/sound/pci/hda/hda_local.h @@ -150,6 +150,7 @@ int __snd_hda_add_vmaster(struct hda_codec *codec, char *name, #define snd_hda_add_vmaster(codec, name, tlv, slaves, suffix) \ __snd_hda_add_vmaster(codec, name, tlv, slaves, suffix, true, NULL) int snd_hda_codec_reset(struct hda_codec *codec); +void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec); enum { HDA_VMUTE_OFF, -- cgit v1.2.3 From bcd96557bd0ab1129fcdde073d5700aed8fcb942 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 27 Feb 2015 20:44:54 +0100 Subject: ALSA: hda - Build PCMs and controls at codec driver probe This makes the code flow easier -- instead of the controller driver calling snd_hda_build_pcms() and snd_hda_build_controls() explicitly, the codec driver itself builds PCMs and controls at probe time. Then the controller driver only needs to call snd_card_register(). Also, this allows us the full bind/unbind control, too. Even when a codec driver is bound later, it automatically registers the new PCM and controls by itself. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_bind.c | 22 ++++++++++++---- sound/pci/hda/hda_codec.c | 67 ----------------------------------------------- sound/pci/hda/hda_codec.h | 2 -- sound/pci/hda/hda_intel.c | 10 ------- sound/pci/hda/hda_tegra.c | 10 ------- 5 files changed, 17 insertions(+), 94 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_bind.c b/sound/pci/hda/hda_bind.c index 311896a23cd1..a49bc45c2ea5 100644 --- a/sound/pci/hda/hda_bind.c +++ b/sound/pci/hda/hda_bind.c @@ -106,16 +106,28 @@ static int hda_codec_driver_probe(struct device *dev) } err = codec->preset->patch(codec); - if (err < 0) { - module_put(owner); - goto error; + if (err < 0) + goto error_module; + + err = snd_hda_codec_build_pcms(codec); + if (err < 0) + goto error_module; + err = snd_hda_codec_build_controls(codec); + if (err < 0) + goto error_module; + if (codec->card->registered) { + err = snd_card_register(codec->card); + if (err < 0) + goto error_module; } return 0; + error_module: + module_put(owner); + error: - codec->preset = NULL; - memset(&codec->patch_ops, 0, sizeof(codec->patch_ops)); + snd_hda_codec_cleanup_for_unbind(codec); return err; } diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 2c7e481a9171..7085d3733d0d 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -4031,36 +4031,6 @@ const struct dev_pm_ops hda_codec_driver_pm = { NULL) }; -/** - * snd_hda_build_controls - build mixer controls - * @bus: the BUS - * - * Creates mixer controls for each codec included in the bus. - * - * Returns 0 if successful, otherwise a negative error code. - */ -int snd_hda_build_controls(struct hda_bus *bus) -{ - struct hda_codec *codec; - - list_for_each_entry(codec, &bus->codec_list, list) { - int err = snd_hda_codec_build_controls(codec); - if (err < 0) { - codec_err(codec, - "cannot build controls for #%d (error %d)\n", - codec->addr, err); - err = snd_hda_codec_reset(codec); - if (err < 0) { - codec_err(codec, - "cannot revert codec\n"); - return err; - } - } - } - return 0; -} -EXPORT_SYMBOL_GPL(snd_hda_build_controls); - /* * add standard channel maps if not specified */ @@ -4692,43 +4662,6 @@ int snd_hda_codec_build_pcms(struct hda_codec *codec) return 0; } -/** - * snd_hda_build_pcms - build PCM information - * @bus: the BUS - * - * Create PCM information for each codec included in the bus. - * - * The build_pcms codec patch is requested to create and assign new - * hda_pcm objects. The codec is responsible to call snd_hda_codec_pcm_new() - * and fills the fields. Later they are instantiated by this function. - * - * At least, substreams, channels_min and channels_max must be filled for - * each stream. substreams = 0 indicates that the stream doesn't exist. - * When rates and/or formats are zero, the supported values are queried - * from the given nid. The nid is used also by the default ops.prepare - * and ops.cleanup callbacks. - * - * The driver needs to call ops.open in its open callback. Similarly, - * ops.close is supposed to be called in the close callback. - * ops.prepare should be called in the prepare or hw_params callback - * with the proper parameters for set up. - * ops.cleanup should be called in hw_free for clean up of streams. - * - * This function returns 0 if successful, or a negative error code. - */ -int snd_hda_build_pcms(struct hda_bus *bus) -{ - struct hda_codec *codec; - - list_for_each_entry(codec, &bus->codec_list, list) { - int err = snd_hda_codec_build_pcms(codec); - if (err < 0) - return err; - } - return 0; -} -EXPORT_SYMBOL_GPL(snd_hda_build_pcms); - /** * snd_hda_add_new_ctls - create controls from the array * @codec: the HDA codec diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index fc62ca51fd35..46d253e2f266 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h @@ -516,13 +516,11 @@ void snd_hda_spdif_ctls_assign(struct hda_codec *codec, int idx, hda_nid_t nid); /* * Mixer */ -int snd_hda_build_controls(struct hda_bus *bus); int snd_hda_codec_build_controls(struct hda_codec *codec); /* * PCM */ -int snd_hda_build_pcms(struct hda_bus *bus); int snd_hda_codec_parse_pcms(struct hda_codec *codec); int snd_hda_codec_build_pcms(struct hda_codec *codec); diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index f7fb1b51d446..e81461a413b8 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c @@ -1895,16 +1895,6 @@ static int azx_probe_continue(struct azx *chip) goto out_free; } - /* create PCM streams */ - err = snd_hda_build_pcms(chip->bus); - if (err < 0) - goto out_free; - - /* create mixer controls */ - err = snd_hda_build_controls(chip->bus); - if (err < 0) - goto out_free; - err = snd_card_register(chip->card); if (err < 0) goto out_free; diff --git a/sound/pci/hda/hda_tegra.c b/sound/pci/hda/hda_tegra.c index 1359fdd20f02..7586abe91dfb 100644 --- a/sound/pci/hda/hda_tegra.c +++ b/sound/pci/hda/hda_tegra.c @@ -497,16 +497,6 @@ static int hda_tegra_probe(struct platform_device *pdev) if (err < 0) goto out_free; - /* create PCM streams */ - err = snd_hda_build_pcms(chip->bus); - if (err < 0) - goto out_free; - - /* create mixer controls */ - err = snd_hda_build_controls(chip->bus); - if (err < 0) - goto out_free; - err = snd_card_register(chip->card); if (err < 0) goto out_free; -- cgit v1.2.3 From 2f35c630f7d49efdef29b58d81ed2531ddd916d9 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 27 Feb 2015 22:43:26 +0100 Subject: ALSA: hda - Use standard workqueue for unsol and jack events The events that are handled by HD-audio drivers are no frequent and urgent ones, so we can use the standard workqueue without any problem nowadays. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_codec.c | 26 +++++--------------------- sound/pci/hda/hda_codec.h | 2 -- sound/pci/hda/hda_intel.c | 8 ++++---- sound/pci/hda/patch_ca0132.c | 3 +-- sound/pci/hda/patch_hdmi.c | 8 +++----- sound/pci/hda/patch_via.c | 3 +-- 6 files changed, 14 insertions(+), 36 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 7085d3733d0d..f2ccb39a3788 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -681,7 +681,7 @@ int snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex) struct hda_bus_unsolicited *unsol; unsigned int wp; - if (!bus || !bus->workq) + if (!bus) return 0; trace_hda_unsol_event(bus, res, res_ex); @@ -693,7 +693,7 @@ int snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex) unsol->queue[wp] = res; unsol->queue[wp + 1] = res_ex; - queue_work(bus->workq, &unsol->work); + schedule_work(&unsol->work); return 0; } @@ -732,13 +732,9 @@ static void snd_hda_bus_free(struct hda_bus *bus) return; WARN_ON(!list_empty(&bus->codec_list)); - if (bus->workq) - flush_workqueue(bus->workq); + cancel_work_sync(&bus->unsol.work); if (bus->ops.private_free) bus->ops.private_free(bus); - if (bus->workq) - destroy_workqueue(bus->workq); - kfree(bus); } @@ -785,16 +781,6 @@ int snd_hda_bus_new(struct snd_card *card, INIT_LIST_HEAD(&bus->codec_list); INIT_WORK(&bus->unsol.work, process_unsol_events); - snprintf(bus->workq_name, sizeof(bus->workq_name), - "hd-audio%d", card->number); - bus->workq = create_singlethread_workqueue(bus->workq_name); - if (!bus->workq) { - dev_err(card->dev, "cannot create workqueue %s\n", - bus->workq_name); - kfree(bus); - return -ENOMEM; - } - err = snd_device_new(card, SNDRV_DEV_BUS, bus, &dev_ops); if (err < 0) { snd_hda_bus_free(bus); @@ -1068,8 +1054,8 @@ static void hda_jackpoll_work(struct work_struct *work) if (!codec->jackpoll_interval) return; - queue_delayed_work(codec->bus->workq, &codec->jackpoll_work, - codec->jackpoll_interval); + schedule_delayed_work(&codec->jackpoll_work, + codec->jackpoll_interval); } static void init_hda_cache(struct hda_cache_rec *cache, @@ -1178,7 +1164,6 @@ static void codec_release_pcms(struct hda_codec *codec) void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec) { cancel_delayed_work_sync(&codec->jackpoll_work); - flush_workqueue(codec->bus->workq); if (!codec->in_freeing) snd_hda_ctls_clear(codec); codec_release_pcms(codec); @@ -1214,7 +1199,6 @@ static void snd_hda_codec_free(struct hda_codec *codec) if (device_is_registered(hda_codec_dev(codec))) device_del(hda_codec_dev(codec)); free_init_pincfgs(codec); - flush_workqueue(codec->bus->workq); list_del(&codec->list); codec->bus->caddr_tbl[codec->addr] = NULL; clear_bit(codec->addr, &codec->bus->codec_powered); diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index 46d253e2f266..bf9efb7e1b9a 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h @@ -132,8 +132,6 @@ struct hda_bus { /* unsolicited event queue */ struct hda_bus_unsolicited unsol; - char workq_name[16]; - struct workqueue_struct *workq; /* common workqueue for codecs */ /* assigned PCMs */ DECLARE_BITMAP(pcm_dev_bits, SNDRV_PCM_DEVICES); diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index e81461a413b8..dbc5a593da46 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c @@ -528,10 +528,10 @@ static int azx_position_check(struct azx *chip, struct azx_dev *azx_dev) if (ok == 1) { azx_dev->irq_pending = 0; return ok; - } else if (ok == 0 && chip->bus && chip->bus->workq) { + } else if (ok == 0) { /* bogus IRQ, process it later */ azx_dev->irq_pending = 1; - queue_work(chip->bus->workq, &hda->irq_pending_work); + schedule_work(&hda->irq_pending_work); } return 0; } @@ -893,8 +893,8 @@ static int azx_runtime_resume(struct device *dev) if (status && bus) { list_for_each_entry(codec, &bus->codec_list, list) if (status & (1 << codec->addr)) - queue_delayed_work(codec->bus->workq, - &codec->jackpoll_work, codec->jackpoll_interval); + schedule_delayed_work(&codec->jackpoll_work, + codec->jackpoll_interval); } /* disable controller Wake Up event*/ diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c index 555781fad26f..72d20652df50 100644 --- a/sound/pci/hda/patch_ca0132.c +++ b/sound/pci/hda/patch_ca0132.c @@ -4410,8 +4410,7 @@ static void hp_callback(struct hda_codec *codec, struct hda_jack_callback *cb) * state machine run. */ cancel_delayed_work_sync(&spec->unsol_hp_work); - queue_delayed_work(codec->bus->workq, &spec->unsol_hp_work, - msecs_to_jiffies(500)); + schedule_delayed_work(&spec->unsol_hp_work, msecs_to_jiffies(500)); cb->tbl->block_report = 1; } diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c index 708bbed15ea3..7e9ff7b16e56 100644 --- a/sound/pci/hda/patch_hdmi.c +++ b/sound/pci/hda/patch_hdmi.c @@ -1576,9 +1576,8 @@ static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll) update_eld = true; } else if (repoll) { - queue_delayed_work(codec->bus->workq, - &per_pin->work, - msecs_to_jiffies(300)); + schedule_delayed_work(&per_pin->work, + msecs_to_jiffies(300)); goto unlock; } } @@ -2198,11 +2197,10 @@ static void generic_hdmi_free(struct hda_codec *codec) for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); - cancel_delayed_work(&per_pin->work); + cancel_delayed_work_sync(&per_pin->work); eld_proc_free(per_pin); } - flush_workqueue(codec->bus->workq); hdmi_array_free(spec); kfree(spec); } diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 11a05638e03b..2112fbe9e577 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -222,8 +222,7 @@ static void vt1708_update_hp_work(struct hda_codec *codec) if (!spec->hp_work_active) { codec->jackpoll_interval = msecs_to_jiffies(100); snd_hda_codec_write(codec, 0x1, 0, 0xf81, 0); - queue_delayed_work(codec->bus->workq, - &codec->jackpoll_work, 0); + schedule_delayed_work(&codec->jackpoll_work, 0); spec->hp_work_active = true; } } else if (!hp_detect_with_aa(codec)) -- cgit v1.2.3 From d56db741b8e688a0b9d4d5bb9caa11dfcb7c0b08 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 27 Feb 2015 23:25:35 +0100 Subject: ALSA: hda - Release resources in device release callback Move the destructor code to device release callback for the codec object instead. This is a safer place to release the resources than dev_free callback in general. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_codec.c | 51 +++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 28 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index f2ccb39a3788..6fecf57c8d7c 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -1191,28 +1191,6 @@ void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec) remove_conn_list(codec); } -static void snd_hda_codec_free(struct hda_codec *codec) -{ - if (!codec) - return; - codec->in_freeing = 1; - if (device_is_registered(hda_codec_dev(codec))) - device_del(hda_codec_dev(codec)); - free_init_pincfgs(codec); - list_del(&codec->list); - codec->bus->caddr_tbl[codec->addr] = NULL; - clear_bit(codec->addr, &codec->bus->codec_powered); - snd_hda_sysfs_clear(codec); - free_hda_cache(&codec->amp_cache); - free_hda_cache(&codec->cmd_cache); - kfree(codec->vendor_name); - kfree(codec->chip_name); - kfree(codec->modelname); - kfree(codec->wcaps); - codec->bus->num_codecs--; - put_device(hda_codec_dev(codec)); -} - static bool snd_hda_codec_get_supported_ps(struct hda_codec *codec, hda_nid_t fg, unsigned int power_state); @@ -1241,14 +1219,32 @@ static int snd_hda_codec_dev_disconnect(struct snd_device *device) static int snd_hda_codec_dev_free(struct snd_device *device) { - snd_hda_codec_free(device->device_data); + struct hda_codec *codec = device->device_data; + + codec->in_freeing = 1; + if (device_is_registered(hda_codec_dev(codec))) + device_del(hda_codec_dev(codec)); + put_device(hda_codec_dev(codec)); return 0; } -/* just free the container */ static void snd_hda_codec_dev_release(struct device *dev) { - kfree(dev_to_hda_codec(dev)); + struct hda_codec *codec = dev_to_hda_codec(dev); + + free_init_pincfgs(codec); + list_del(&codec->list); + codec->bus->caddr_tbl[codec->addr] = NULL; + clear_bit(codec->addr, &codec->bus->codec_powered); + snd_hda_sysfs_clear(codec); + free_hda_cache(&codec->amp_cache); + free_hda_cache(&codec->cmd_cache); + kfree(codec->vendor_name); + kfree(codec->chip_name); + kfree(codec->modelname); + kfree(codec->wcaps); + codec->bus->num_codecs--; + kfree(codec); } /** @@ -1362,7 +1358,7 @@ int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card, setup_fg_nodes(codec); if (!codec->afg && !codec->mfg) { - dev_err(card->dev, "no AFG or MFG node found\n"); + codec_err(codec, "no AFG or MFG node found\n"); err = -ENODEV; goto error; } @@ -1408,7 +1404,7 @@ int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card, return 0; error: - snd_hda_codec_free(codec); + put_device(hda_codec_dev(codec)); return err; } EXPORT_SYMBOL_GPL(snd_hda_codec_new); @@ -2464,7 +2460,6 @@ void snd_hda_unlock_devices(struct hda_bus *bus) { struct snd_card *card = bus->card; - card = bus->card; spin_lock(&card->files_lock); card->shutdown = 0; spin_unlock(&card->files_lock); -- cgit v1.2.3 From d6482288aadcf19e348cbccff7a605790a3b3875 Mon Sep 17 00:00:00 2001 From: "Maciej S. Szmigiero" Date: Fri, 6 Mar 2015 16:59:00 +0100 Subject: ALSA: ac97: Add VT1613 AC97 codec support Patch to add an VT1613 AC97 codec support. This codec has additional DC offset removal control, headphone output and no video input. Signed-off-by: Maciej Szmigiero Signed-off-by: Takashi Iwai --- sound/pci/ac97/ac97_codec.c | 1 + sound/pci/ac97/ac97_patch.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) (limited to 'sound/pci') diff --git a/sound/pci/ac97/ac97_codec.c b/sound/pci/ac97/ac97_codec.c index 5ee2f17c287c..5bca1a33fed6 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[] = { { 0x54524123, 0xffffffff, "TR28602", NULL, NULL }, // only guess --jk [TR28023 = eMicro EM28023 (new CT1297)] { 0x54584e03, 0xffffffff, "TLV320AIC27", NULL, NULL }, { 0x54584e20, 0xffffffff, "TLC320AD9xC", NULL, NULL }, +{ 0x56494120, 0xfffffff0, "VIA1613", patch_vt1613, NULL }, { 0x56494161, 0xffffffff, "VIA1612A", NULL, NULL }, // modified ICE1232 with S/PDIF { 0x56494170, 0xffffffff, "VIA1617A", patch_vt1617a, NULL }, // modified VT1616 with S/PDIF { 0x56494182, 0xffffffff, "VIA1618", patch_vt1618, NULL }, diff --git a/sound/pci/ac97/ac97_patch.c b/sound/pci/ac97/ac97_patch.c index ceaac1c41906..eca22100f70d 100644 --- a/sound/pci/ac97/ac97_patch.c +++ b/sound/pci/ac97/ac97_patch.c @@ -3351,6 +3351,39 @@ static int patch_cm9780(struct snd_ac97 *ac97) return 0; } +/* + * VIA VT1613 codec + */ +static const struct snd_kcontrol_new snd_ac97_controls_vt1613[] = { +AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0), +}; + +static int patch_vt1613_specific(struct snd_ac97 *ac97) +{ + int err; + + err = patch_build_controls(ac97, &snd_ac97_controls_vt1613[0], + ARRAY_SIZE(snd_ac97_controls_vt1613)); + if (err) + return err; + + return 0; +}; + +static const struct snd_ac97_build_ops patch_vt1613_ops = { + .build_specific = patch_vt1613_specific +}; + +static int patch_vt1613(struct snd_ac97 *ac97) +{ + ac97->build_ops = &patch_vt1613_ops; + + ac97->flags |= AC97_HAS_NO_VIDEO; + ac97->caps |= AC97_BC_HEADPHONE; + + return 0; +} + /* * VIA VT1616 codec */ -- cgit v1.2.3 From 5371fc0ecdf55b6811ade8a198de8ace2f4e5861 Mon Sep 17 00:00:00 2001 From: Fabio Estevam Date: Fri, 6 Mar 2015 13:41:42 -0300 Subject: ALSA: ac97: ac97_patch: Simplify patch_vt1613_specific() We can simplify the code by returning patch_build_controls() directly. Signed-off-by: Fabio Estevam Signed-off-by: Takashi Iwai --- sound/pci/ac97/ac97_patch.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/ac97/ac97_patch.c b/sound/pci/ac97/ac97_patch.c index eca22100f70d..f4234edb878c 100644 --- a/sound/pci/ac97/ac97_patch.c +++ b/sound/pci/ac97/ac97_patch.c @@ -3360,14 +3360,8 @@ AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0), static int patch_vt1613_specific(struct snd_ac97 *ac97) { - int err; - - err = patch_build_controls(ac97, &snd_ac97_controls_vt1613[0], - ARRAY_SIZE(snd_ac97_controls_vt1613)); - if (err) - return err; - - return 0; + return patch_build_controls(ac97, &snd_ac97_controls_vt1613[0], + ARRAY_SIZE(snd_ac97_controls_vt1613)); }; static const struct snd_ac97_build_ops patch_vt1613_ops = { -- cgit v1.2.3 From b2a0bafa758256442e04d1f34d6d0746b846d23d Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 5 Mar 2015 17:21:32 +0100 Subject: ALSA: hda - Use shutdown driver ops instead of reboot notifier The driver shutdown ops is simpler than registering reboot notifier manually. There should be no functional change by this -- the codec driver calls its own callback while the bus driver just calls azx_stop() like before. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_bind.c | 10 ++++++++++ sound/pci/hda/hda_codec.c | 18 ------------------ sound/pci/hda/hda_codec.h | 1 - sound/pci/hda/hda_controller.c | 26 -------------------------- sound/pci/hda/hda_controller.h | 6 ------ sound/pci/hda/hda_intel.c | 16 +++++++++++++--- sound/pci/hda/hda_tegra.c | 16 +++++++++++++--- 7 files changed, 36 insertions(+), 57 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_bind.c b/sound/pci/hda/hda_bind.c index a49bc45c2ea5..1f40ce3c1696 100644 --- a/sound/pci/hda/hda_bind.c +++ b/sound/pci/hda/hda_bind.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include "hda_codec.h" #include "hda_local.h" @@ -142,6 +143,14 @@ static int hda_codec_driver_remove(struct device *dev) return 0; } +static void hda_codec_driver_shutdown(struct device *dev) +{ + struct hda_codec *codec = dev_to_hda_codec(dev); + + if (!pm_runtime_suspended(dev) && codec->patch_ops.reboot_notify) + codec->patch_ops.reboot_notify(codec); +} + int __hda_codec_driver_register(struct hda_codec_driver *drv, const char *name, struct module *owner) { @@ -150,6 +159,7 @@ int __hda_codec_driver_register(struct hda_codec_driver *drv, const char *name, drv->driver.bus = &snd_hda_bus_type; drv->driver.probe = hda_codec_driver_probe; drv->driver.remove = hda_codec_driver_remove; + drv->driver.shutdown = hda_codec_driver_shutdown; drv->driver.pm = &hda_codec_driver_pm; return driver_register(&drv->driver); } diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 6fecf57c8d7c..3e4fb7a8fdcb 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -4941,24 +4941,6 @@ static void cleanup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid) } } -/** - * snd_hda_bus_reboot_notify - call the reboot notifier of each codec - * @bus: HD-audio bus - */ -void snd_hda_bus_reboot_notify(struct hda_bus *bus) -{ - struct hda_codec *codec; - - if (!bus) - return; - list_for_each_entry(codec, &bus->codec_list, list) { - if (hda_codec_is_power_on(codec) && - codec->patch_ops.reboot_notify) - codec->patch_ops.reboot_notify(codec); - } -} -EXPORT_SYMBOL_GPL(snd_hda_bus_reboot_notify); - /** * snd_hda_multi_out_dig_open - open the digital out in the exclusive mode * @codec: the HDA codec diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index bf9efb7e1b9a..70851e6d5f10 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h @@ -563,7 +563,6 @@ extern const struct snd_pcm_chmap_elem snd_pcm_2_1_chmaps[]; * Misc */ void snd_hda_get_codec_name(struct hda_codec *codec, char *name, int namelen); -void snd_hda_bus_reboot_notify(struct hda_bus *bus); void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg, unsigned int power_state); diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c index cae50d5ffb81..b1143f22a0c2 100644 --- a/sound/pci/hda/hda_controller.c +++ b/sound/pci/hda/hda_controller.c @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include "hda_controller.h" @@ -1972,30 +1971,5 @@ int azx_init_stream(struct azx *chip) } EXPORT_SYMBOL_GPL(azx_init_stream); -/* - * reboot notifier for hang-up problem at power-down - */ -static int azx_halt(struct notifier_block *nb, unsigned long event, void *buf) -{ - struct azx *chip = container_of(nb, struct azx, reboot_notifier); - snd_hda_bus_reboot_notify(chip->bus); - azx_stop_chip(chip); - return NOTIFY_OK; -} - -void azx_notifier_register(struct azx *chip) -{ - chip->reboot_notifier.notifier_call = azx_halt; - register_reboot_notifier(&chip->reboot_notifier); -} -EXPORT_SYMBOL_GPL(azx_notifier_register); - -void azx_notifier_unregister(struct azx *chip) -{ - if (chip->reboot_notifier.notifier_call) - unregister_reboot_notifier(&chip->reboot_notifier); -} -EXPORT_SYMBOL_GPL(azx_notifier_unregister); - MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Common HDA driver functions"); diff --git a/sound/pci/hda/hda_controller.h b/sound/pci/hda/hda_controller.h index 94c1a4719f7f..be1b7ded8d82 100644 --- a/sound/pci/hda/hda_controller.h +++ b/sound/pci/hda/hda_controller.h @@ -362,9 +362,6 @@ struct azx { /* for debugging */ unsigned int last_cmd[AZX_MAX_CODECS]; - /* reboot notifier (for mysterious hangup problem at power-down) */ - struct notifier_block reboot_notifier; - #ifdef CONFIG_SND_HDA_DSP_LOADER struct azx_dev saved_azx_dev; #endif @@ -437,7 +434,4 @@ int azx_probe_codecs(struct azx *chip, unsigned int max_slots); int azx_codec_configure(struct azx *chip); int azx_init_stream(struct azx *chip); -void azx_notifier_register(struct azx *chip); -void azx_notifier_unregister(struct azx *chip); - #endif /* __SOUND_HDA_CONTROLLER_H */ diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index dbc5a593da46..25668fde8480 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c @@ -1066,8 +1066,6 @@ static int azx_free(struct azx *chip) azx_del_card_list(chip); - azx_notifier_unregister(chip); - hda->init_failed = 1; /* to be sure */ complete_all(&hda->probe_wait); @@ -1900,7 +1898,6 @@ static int azx_probe_continue(struct azx *chip) goto out_free; chip->running = 1; - azx_notifier_register(chip); azx_add_card_list(chip); snd_hda_set_power_save(chip->bus, power_save * 1000); if (azx_has_pm_runtime(chip) || hda->use_vga_switcheroo) @@ -1921,6 +1918,18 @@ static void azx_remove(struct pci_dev *pci) snd_card_free(card); } +static void azx_shutdown(struct pci_dev *pci) +{ + struct snd_card *card = pci_get_drvdata(pci); + struct azx *chip; + + if (!card) + return; + chip = card->private_data; + if (chip && chip->running) + azx_stop_chip(chip); +} + /* PCI IDs */ static const struct pci_device_id azx_ids[] = { /* CPT */ @@ -2143,6 +2152,7 @@ static struct pci_driver azx_driver = { .id_table = azx_ids, .probe = azx_probe, .remove = azx_remove, + .shutdown = azx_shutdown, .driver = { .pm = AZX_PM_OPS, }, diff --git a/sound/pci/hda/hda_tegra.c b/sound/pci/hda/hda_tegra.c index 7586abe91dfb..2e4fd5c56d3b 100644 --- a/sound/pci/hda/hda_tegra.c +++ b/sound/pci/hda/hda_tegra.c @@ -290,8 +290,6 @@ static int hda_tegra_dev_free(struct snd_device *device) int i; struct azx *chip = device->device_data; - azx_notifier_unregister(chip); - if (chip->initialized) { for (i = 0; i < chip->num_streams; i++) azx_stream_stop(chip, &chip->azx_dev[i]); @@ -502,7 +500,6 @@ static int hda_tegra_probe(struct platform_device *pdev) goto out_free; chip->running = 1; - azx_notifier_register(chip); snd_hda_set_power_save(chip->bus, power_save * 1000); return 0; @@ -517,6 +514,18 @@ static int hda_tegra_remove(struct platform_device *pdev) return snd_card_free(dev_get_drvdata(&pdev->dev)); } +static void hda_tegra_shutdown(struct platform_device *pdev) +{ + struct snd_card *card = dev_get_drvdata(&pdev->dev); + struct azx *chip; + + if (!card) + return; + chip = card->private_data; + if (chip && chip->running) + azx_stop_chip(chip); +} + static struct platform_driver tegra_platform_hda = { .driver = { .name = "tegra-hda", @@ -525,6 +534,7 @@ static struct platform_driver tegra_platform_hda = { }, .probe = hda_tegra_probe, .remove = hda_tegra_remove, + .shutdown = hda_tegra_shutdown, }; module_platform_driver(tegra_platform_hda); -- cgit v1.2.3 From fb83b6351052bf78686df2559f7ea6b10e596850 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Mon, 16 Mar 2015 23:34:34 +0100 Subject: ALSA: hda - Simplify PCM setup overrides This patch does two things: - code refactoring with a local helper function, - allow codec drivers to provide the specific PCM stream info pointers only for overriding the non-NULL entries, instead of copying the whole. This simplifies the codec driver side (currently the only user is alc269's 44kHz fixed rate). Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_generic.c | 110 +++++++++++++++++++++++------------------- sound/pci/hda/patch_realtek.c | 41 ---------------- 2 files changed, 60 insertions(+), 91 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c index ebdbc023583d..27ce54701f0f 100644 --- a/sound/pci/hda/hda_generic.c +++ b/sound/pci/hda/hda_generic.c @@ -5137,6 +5137,33 @@ static void fill_pcm_stream_name(char *str, size_t len, const char *sfx, strlcat(str, sfx, len); } +/* copy PCM stream info from @default_str, and override non-NULL entries + * from @spec_str and @nid + */ +static void setup_pcm_stream(struct hda_pcm_stream *str, + const struct hda_pcm_stream *default_str, + const struct hda_pcm_stream *spec_str, + hda_nid_t nid) +{ + *str = *default_str; + if (nid) + str->nid = nid; + if (spec_str) { + if (spec_str->substreams) + str->substreams = spec_str->substreams; + if (spec_str->channels_min) + str->channels_min = spec_str->channels_min; + if (spec_str->channels_max) + str->channels_max = spec_str->channels_max; + if (spec_str->rates) + str->rates = spec_str->rates; + if (spec_str->formats) + str->formats = spec_str->formats; + if (spec_str->maxbps) + str->maxbps = spec_str->maxbps; + } +} + /** * snd_hda_gen_build_pcms - build PCM streams based on the parsed results * @codec: the HDA codec @@ -5147,7 +5174,6 @@ int snd_hda_gen_build_pcms(struct hda_codec *codec) { struct hda_gen_spec *spec = codec->spec; struct hda_pcm *info; - const struct hda_pcm_stream *p; bool have_multi_adcs; if (spec->no_analog) @@ -5162,11 +5188,10 @@ int snd_hda_gen_build_pcms(struct hda_codec *codec) spec->pcm_rec[0] = info; if (spec->multiout.num_dacs > 0) { - p = spec->stream_analog_playback; - if (!p) - p = &pcm_analog_playback; - info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; - info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0]; + setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK], + &pcm_analog_playback, + spec->stream_analog_playback, + spec->multiout.dac_nids[0]); info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels; if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT && @@ -5175,15 +5200,11 @@ int snd_hda_gen_build_pcms(struct hda_codec *codec) snd_pcm_2_1_chmaps; } if (spec->num_adc_nids) { - p = spec->stream_analog_capture; - if (!p) { - if (spec->dyn_adc_switch) - p = &dyn_adc_pcm_analog_capture; - else - p = &pcm_analog_capture; - } - info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; - info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; + setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE], + (spec->dyn_adc_switch ? + &dyn_adc_pcm_analog_capture : &pcm_analog_capture), + spec->stream_analog_capture, + spec->adc_nids[0]); } skip_analog: @@ -5202,20 +5223,16 @@ int snd_hda_gen_build_pcms(struct hda_codec *codec) info->pcm_type = spec->dig_out_type; else info->pcm_type = HDA_PCM_TYPE_SPDIF; - if (spec->multiout.dig_out_nid) { - p = spec->stream_digital_playback; - if (!p) - p = &pcm_digital_playback; - info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; - info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; - } - if (spec->dig_in_nid) { - p = spec->stream_digital_capture; - if (!p) - p = &pcm_digital_capture; - info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; - info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid; - } + if (spec->multiout.dig_out_nid) + setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK], + &pcm_digital_playback, + spec->stream_digital_playback, + spec->multiout.dig_out_nid); + if (spec->dig_in_nid) + setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE], + &pcm_digital_capture, + spec->stream_digital_capture, + spec->dig_in_nid); } if (spec->no_analog) @@ -5236,31 +5253,24 @@ int snd_hda_gen_build_pcms(struct hda_codec *codec) if (!info) return -ENOMEM; spec->pcm_rec[2] = info; - if (spec->alt_dac_nid) { - p = spec->stream_analog_alt_playback; - if (!p) - p = &pcm_analog_alt_playback; - info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; - info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = - spec->alt_dac_nid; - } else { - info->stream[SNDRV_PCM_STREAM_PLAYBACK] = - pcm_null_stream; - info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0; - } + if (spec->alt_dac_nid) + setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK], + &pcm_analog_alt_playback, + spec->stream_analog_alt_playback, + spec->alt_dac_nid); + else + setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK], + &pcm_null_stream, NULL, 0); if (have_multi_adcs) { - p = spec->stream_analog_alt_capture; - if (!p) - p = &pcm_analog_alt_capture; - info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; - info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = - spec->adc_nids[1]; + setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE], + &pcm_analog_alt_capture, + spec->stream_analog_alt_capture, + spec->adc_nids[1]); info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids - 1; } else { - info->stream[SNDRV_PCM_STREAM_CAPTURE] = - pcm_null_stream; - info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0; + setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE], + &pcm_null_stream, NULL, 0); } } diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c index 2a61bda8115d..124eacf67fc4 100644 --- a/sound/pci/hda/patch_realtek.c +++ b/sound/pci/hda/patch_realtek.c @@ -2602,53 +2602,12 @@ static int patch_alc268(struct hda_codec *codec) * ALC269 */ -static int playback_pcm_open(struct hda_pcm_stream *hinfo, - struct hda_codec *codec, - struct snd_pcm_substream *substream) -{ - struct hda_gen_spec *spec = codec->spec; - return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, - hinfo); -} - -static int playback_pcm_prepare(struct hda_pcm_stream *hinfo, - struct hda_codec *codec, - unsigned int stream_tag, - unsigned int format, - struct snd_pcm_substream *substream) -{ - struct hda_gen_spec *spec = codec->spec; - return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, - stream_tag, format, substream); -} - -static int playback_pcm_cleanup(struct hda_pcm_stream *hinfo, - struct hda_codec *codec, - struct snd_pcm_substream *substream) -{ - struct hda_gen_spec *spec = codec->spec; - return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); -} - static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = { - .substreams = 1, - .channels_min = 2, - .channels_max = 8, .rates = SNDRV_PCM_RATE_44100, /* fixed rate */ - /* NID is set in alc_build_pcms */ - .ops = { - .open = playback_pcm_open, - .prepare = playback_pcm_prepare, - .cleanup = playback_pcm_cleanup - }, }; static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = { - .substreams = 1, - .channels_min = 2, - .channels_max = 2, .rates = SNDRV_PCM_RATE_44100, /* fixed rate */ - /* NID is set in alc_build_pcms */ }; /* different alc269-variants */ -- cgit v1.2.3 From b56df151d3b97a95ba3d3a76c2867d00f2db7782 Mon Sep 17 00:00:00 2001 From: Clément Guedez Date: Wed, 18 Mar 2015 02:26:26 +0100 Subject: ALSA: ice1724: ESI W192M: Correct copy/paste from prodigy driver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Correct copy/paste name from prodigy driver, no behaviour change, only name. Signed-off-by: Clément Guedez Signed-off-by: Takashi Iwai --- sound/pci/ice1712/wtm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/ice1712/wtm.c b/sound/pci/ice1712/wtm.c index bcf30a387b87..f65ac193cf1a 100644 --- a/sound/pci/ice1712/wtm.c +++ b/sound/pci/ice1712/wtm.c @@ -463,7 +463,7 @@ static int wtm_add_controls(struct snd_ice1712 *ice) static int wtm_init(struct snd_ice1712 *ice) { - static unsigned short stac_inits_prodigy[] = { + static unsigned short stac_inits_wtm[] = { STAC946X_RESET, 0, (unsigned short)-1 }; @@ -475,7 +475,7 @@ static int wtm_init(struct snd_ice1712 *ice) ice->force_rdma1 = 1; /*initialize codec*/ - p = stac_inits_prodigy; + p = stac_inits_wtm; for (; *p != (unsigned short)-1; p += 2) { stac9460_put(ice, p[0], p[1]); stac9460_2_put(ice, p[0], p[1]); -- cgit v1.2.3 From 7127744a5e14455a4b69429757fd811aa50ec4b8 Mon Sep 17 00:00:00 2001 From: Clément Guedez Date: Wed, 18 Mar 2015 02:26:27 +0100 Subject: ALSA: ice1724: ESI W192M: Update eeprom structure to C99 standard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update eeprom structure to C99 standard to be compliant with change in alsa. It's just a notation change, no configuration change. Signed-off-by: Clément Guedez Signed-off-by: Takashi Iwai --- sound/pci/ice1712/wtm.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/ice1712/wtm.c b/sound/pci/ice1712/wtm.c index f65ac193cf1a..6e1026e0e56b 100644 --- a/sound/pci/ice1712/wtm.c +++ b/sound/pci/ice1712/wtm.c @@ -485,19 +485,19 @@ static int wtm_init(struct snd_ice1712 *ice) static unsigned char wtm_eeprom[] = { - 0x47, /*SYSCONF: clock 192KHz, 4ADC, 8DAC */ - 0x80, /* ACLINK : I2S */ - 0xf8, /* I2S: vol; 96k, 24bit, 192k */ - 0xc1 /*SPDIF: out-en, spidf ext out*/, - 0x9f, /* GPIO_DIR */ - 0xff, /* GPIO_DIR1 */ - 0x7f, /* GPIO_DIR2 */ - 0x9f, /* GPIO_MASK */ - 0xff, /* GPIO_MASK1 */ - 0x7f, /* GPIO_MASK2 */ - 0x16, /* GPIO_STATE */ - 0x80, /* GPIO_STATE1 */ - 0x00, /* GPIO_STATE2 */ + [ICE_EEP2_SYSCONF] = 0x47, /*SYSCONF: clock 192KHz, 4ADC, 8DAC */ + [ICE_EEP2_ACLINK] = 0x80, /* ACLINK : I2S */ + [ICE_EEP2_I2S] = 0xf8, /* I2S: vol; 96k, 24bit, 192k */ + [ICE_EEP2_SPDIF] = 0xc1, /*SPDIF: out-en, spidf ext out*/ + [ICE_EEP2_GPIO_DIR] = 0x9f, + [ICE_EEP2_GPIO_DIR1] = 0xff, + [ICE_EEP2_GPIO_DIR2] = 0x7f, + [ICE_EEP2_GPIO_MASK] = 0x9f, + [ICE_EEP2_GPIO_MASK1] = 0xff, + [ICE_EEP2_GPIO_MASK2] = 0x7f, + [ICE_EEP2_GPIO_STATE] = 0x16, + [ICE_EEP2_GPIO_STATE1] = 0x80, + [ICE_EEP2_GPIO_STATE2] = 0x00, }; -- cgit v1.2.3 From f8a8b3a835ef9e5f94163c9dc62fc2e2e375b10c Mon Sep 17 00:00:00 2001 From: Clément Guedez Date: Wed, 18 Mar 2015 02:26:28 +0100 Subject: ALSA: ice1724: ESI W192M: Enable midi i/o of port envy24 chip as available MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enable midi i/o port of envy24 chip as their are available on ESI W192M soundcard. Signed-off-by: Clément Guedez Signed-off-by: Takashi Iwai --- sound/pci/ice1712/wtm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'sound/pci') diff --git a/sound/pci/ice1712/wtm.c b/sound/pci/ice1712/wtm.c index 6e1026e0e56b..59483b4d6dd0 100644 --- a/sound/pci/ice1712/wtm.c +++ b/sound/pci/ice1712/wtm.c @@ -485,7 +485,8 @@ static int wtm_init(struct snd_ice1712 *ice) static unsigned char wtm_eeprom[] = { - [ICE_EEP2_SYSCONF] = 0x47, /*SYSCONF: clock 192KHz, 4ADC, 8DAC */ + [ICE_EEP2_SYSCONF] = 0x67, /*SYSCONF: clock 192KHz, mpu401, + 4ADC, 8DAC */ [ICE_EEP2_ACLINK] = 0x80, /* ACLINK : I2S */ [ICE_EEP2_I2S] = 0xf8, /* I2S: vol; 96k, 24bit, 192k */ [ICE_EEP2_SPDIF] = 0xc1, /*SPDIF: out-en, spidf ext out*/ -- cgit v1.2.3 From 16ddbe738a5bd2afe80aa10492f762f34b09cbf0 Mon Sep 17 00:00:00 2001 From: Clément Guedez Date: Wed, 18 Mar 2015 02:26:29 +0100 Subject: ALSA: ice1724: ESI W192M: Add TLV support for control value in dB scale MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add TLV support to control volume using dB scale for input and ouput on ESI W192M. Signed-off-by: Clément Guedez Signed-off-by: Takashi Iwai --- sound/pci/ice1712/wtm.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/ice1712/wtm.c b/sound/pci/ice1712/wtm.c index 59483b4d6dd0..c7ffafaa1c5c 100644 --- a/sound/pci/ice1712/wtm.c +++ b/sound/pci/ice1712/wtm.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "ice1712.h" #include "envy24ht.h" @@ -380,17 +381,25 @@ static int stac9460_mic_sw_put(struct snd_kcontrol *kcontrol, return change; } + +/*Limits value in dB for fader*/ +static const DECLARE_TLV_DB_SCALE(db_scale_dac, -19125, 75, 0); +static const DECLARE_TLV_DB_SCALE(db_scale_adc, 0, 150, 0); + /* * Control tabs */ static struct snd_kcontrol_new stac9640_controls[] = { { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, + .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | + SNDRV_CTL_ELEM_ACCESS_TLV_READ), .name = "Master Playback Switch", .info = stac9460_dac_mute_info, .get = stac9460_dac_mute_get, .put = stac9460_dac_mute_put, - .private_value = 1 + .private_value = 1, + .tlv = { .p = db_scale_dac } }, { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, @@ -419,11 +428,15 @@ static struct snd_kcontrol_new stac9640_controls[] = { }, { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, + .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | + SNDRV_CTL_ELEM_ACCESS_TLV_READ), + .name = "DAC Volume", .count = 8, .info = stac9460_dac_vol_info, .get = stac9460_dac_vol_get, .put = stac9460_dac_vol_put, + .tlv = { .p = db_scale_dac } }, { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, @@ -435,12 +448,15 @@ static struct snd_kcontrol_new stac9640_controls[] = { }, { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, + .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | + SNDRV_CTL_ELEM_ACCESS_TLV_READ), + .name = "ADC Volume", .count = 2, .info = stac9460_adc_vol_info, .get = stac9460_adc_vol_get, .put = stac9460_adc_vol_put, - + .tlv = { .p = db_scale_adc } } }; -- cgit v1.2.3 From ae8a9a11256a0906831a7db39b8cbcdec51ae28a Mon Sep 17 00:00:00 2001 From: Clément Guedez Date: Wed, 18 Mar 2015 02:26:30 +0100 Subject: ALSA: ice1724: ESI W192M: Add text Line in/Mic for selecting input gain state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add text Line in/Mic for selecting input gain state in mixer for ESI W192M. Signed-off-by: Clément Guedez Signed-off-by: Takashi Iwai --- sound/pci/ice1712/wtm.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/ice1712/wtm.c b/sound/pci/ice1712/wtm.c index c7ffafaa1c5c..6d3412f72855 100644 --- a/sound/pci/ice1712/wtm.c +++ b/sound/pci/ice1712/wtm.c @@ -339,8 +339,14 @@ static int stac9460_adc_vol_put(struct snd_kcontrol *kcontrol, /* * MIC / LINE switch fonction */ +static int stac9460_mic_sw_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) +{ + static const char * const texts[2] = { "Line In", "Mic" }; + + return snd_ctl_enum_info(uinfo, 1, 2, texts); +} -#define stac9460_mic_sw_info snd_ctl_boolean_mono_info static int stac9460_mic_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) @@ -354,7 +360,7 @@ static int stac9460_mic_sw_get(struct snd_kcontrol *kcontrol, val = stac9460_get(ice, STAC946X_GENERAL_PURPOSE); else val = stac9460_2_get(ice, STAC946X_GENERAL_PURPOSE); - ucontrol->value.integer.value[0] = ~val>>7 & 0x1; + ucontrol->value.enumerated.item[0] = (val >> 7) & 0x1; return 0; } @@ -370,7 +376,7 @@ static int stac9460_mic_sw_put(struct snd_kcontrol *kcontrol, old = stac9460_get(ice, STAC946X_GENERAL_PURPOSE); else old = stac9460_2_get(ice, STAC946X_GENERAL_PURPOSE); - new = (~ucontrol->value.integer.value[0] << 7 & 0x80) | (old & ~0x80); + new = (ucontrol->value.enumerated.item[0] << 7 & 0x80) | (old & ~0x80); change = (new != old); if (change) { if (id == 0) @@ -411,7 +417,7 @@ static struct snd_kcontrol_new stac9640_controls[] = { }, { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, - .name = "MIC/Line switch", + .name = "MIC/Line Input Enum", .count = 2, .info = stac9460_mic_sw_info, .get = stac9460_mic_sw_get, -- cgit v1.2.3 From 1aa9a4ea4fea5e4afe8be0229774b8f98db2e6c3 Mon Sep 17 00:00:00 2001 From: Clément Guedez Date: Wed, 18 Mar 2015 02:26:31 +0100 Subject: ALSA: ice1724: ESI W192M: Add sampling rate control of the ADC/DAC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add sampling rate control for ADC/DAC for ESI W192M. Allow to switch between 48K/96K/192K sampling rate. All DAC need to be mute when changing samplerate. Signed-off-by: Clément Guedez Signed-off-by: Takashi Iwai --- sound/pci/ice1712/wtm.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) (limited to 'sound/pci') diff --git a/sound/pci/ice1712/wtm.c b/sound/pci/ice1712/wtm.c index 6d3412f72855..9906119e0954 100644 --- a/sound/pci/ice1712/wtm.c +++ b/sound/pci/ice1712/wtm.c @@ -30,12 +30,18 @@ #include #include #include +#include #include "ice1712.h" #include "envy24ht.h" #include "wtm.h" #include "stac946x.h" +struct wtm_spec { + /* rate change needs atomic mute/unmute of all dacs*/ + struct mutex mute_mutex; +}; + /* * 2*ADC 6*DAC no1 ringbuffer r/w on i2c bus @@ -69,15 +75,65 @@ static inline unsigned char stac9460_2_get(struct snd_ice1712 *ice, int reg) /* * DAC mute control */ +static void stac9460_dac_mute_all(struct snd_ice1712 *ice, unsigned char mute, + unsigned short int *change_mask) +{ + unsigned char new, old; + int id, idx, change; + + /*stac9460 1*/ + for (id = 0; id < 7; id++) { + if (*change_mask & (0x01 << id)) { + if (id == 0) + idx = STAC946X_MASTER_VOLUME; + else + idx = STAC946X_LF_VOLUME - 1 + id; + old = stac9460_get(ice, idx); + new = (~mute << 7 & 0x80) | (old & ~0x80); + change = (new != old); + if (change) { + stac9460_put(ice, idx, new); + *change_mask = *change_mask | (0x01 << id); + } else { + *change_mask = *change_mask & ~(0x01 << id); + } + } + } + + /*stac9460 2*/ + for (id = 0; id < 3; id++) { + if (*change_mask & (0x01 << (id + 7))) { + if (id == 0) + idx = STAC946X_MASTER_VOLUME; + else + idx = STAC946X_LF_VOLUME - 1 + id; + old = stac9460_2_get(ice, idx); + new = (~mute << 7 & 0x80) | (old & ~0x80); + change = (new != old); + if (change) { + stac9460_2_put(ice, idx, new); + *change_mask = *change_mask | (0x01 << id); + } else { + *change_mask = *change_mask & ~(0x01 << id); + } + } + } +} + + + #define stac9460_dac_mute_info snd_ctl_boolean_mono_info static int stac9460_dac_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); + struct wtm_spec *spec = ice->spec; unsigned char val; int idx, id; + mutex_lock(&spec->mute_mutex); + if (kcontrol->private_value) { idx = STAC946X_MASTER_VOLUME; id = 0; @@ -90,6 +146,8 @@ static int stac9460_dac_mute_get(struct snd_kcontrol *kcontrol, else val = stac9460_2_get(ice, idx - 6); ucontrol->value.integer.value[0] = (~val >> 7) & 0x1; + + mutex_unlock(&spec->mute_mutex); return 0; } @@ -388,6 +446,44 @@ static int stac9460_mic_sw_put(struct snd_kcontrol *kcontrol, } +/* + * Handler for setting correct codec rate - called when rate change is detected + */ +static void stac9460_set_rate_val(struct snd_ice1712 *ice, unsigned int rate) +{ + unsigned char old, new; + unsigned short int changed; + struct wtm_spec *spec = ice->spec; + + if (rate == 0) /* no hint - S/PDIF input is master, simply return */ + return; + else if (rate <= 48000) + new = 0x08; /* 256x, base rate mode */ + else if (rate <= 96000) + new = 0x11; /* 256x, mid rate mode */ + else + new = 0x12; /* 128x, high rate mode */ + + old = stac9460_get(ice, STAC946X_MASTER_CLOCKING); + if (old == new) + return; + /* change detected, setting master clock, muting first */ + /* due to possible conflicts with mute controls - mutexing */ + mutex_lock(&spec->mute_mutex); + /* we have to remember current mute status for each DAC */ + changed = 0xFFFF; + stac9460_dac_mute_all(ice, 0, &changed); + /*printk(KERN_DEBUG "Rate change: %d, new MC: 0x%02x\n", rate, new);*/ + stac9460_put(ice, STAC946X_MASTER_CLOCKING, new); + stac9460_2_put(ice, STAC946X_MASTER_CLOCKING, new); + udelay(10); + /* unmuting - only originally unmuted dacs - + * i.e. those changed when muting */ + stac9460_dac_mute_all(ice, 1, &changed); + mutex_unlock(&spec->mute_mutex); +} + + /*Limits value in dB for fader*/ static const DECLARE_TLV_DB_SCALE(db_scale_dac, -19125, 75, 0); static const DECLARE_TLV_DB_SCALE(db_scale_adc, 0, 150, 0); @@ -487,21 +583,32 @@ static int wtm_init(struct snd_ice1712 *ice) { static unsigned short stac_inits_wtm[] = { STAC946X_RESET, 0, + STAC946X_MASTER_CLOCKING, 0x11, (unsigned short)-1 }; unsigned short *p; + struct wtm_spec *spec; /*WTM 192M*/ ice->num_total_dacs = 8; ice->num_total_adcs = 4; ice->force_rdma1 = 1; + /*init mutex for dac mute conflict*/ + spec = kzalloc(sizeof(*spec), GFP_KERNEL); + if (!spec) + return -ENOMEM; + ice->spec = spec; + mutex_init(&spec->mute_mutex); + + /*initialize codec*/ p = stac_inits_wtm; for (; *p != (unsigned short)-1; p += 2) { stac9460_put(ice, p[0], p[1]); stac9460_2_put(ice, p[0], p[1]); } + ice->gpio.set_pro_rate = stac9460_set_rate_val; return 0; } -- cgit v1.2.3 From e6feb5d08509be1af2ebc894dae35f32f7b92ab6 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Mon, 16 Mar 2015 21:32:11 +0100 Subject: ALSA: hda - Support advanced power state controls This patch enables the finer power state control of each widget depending on the jack plug state and streaming state in addition to the existing power_down_unused power optimization. The new feature is enabled only when codec->power_mgmt flag is set. Two new flags, pin_enabled and stream_enabled, are introduced in nid_path struct for marking the two individual power states: the pin plug/unplug and DAC/ADC stream, respectively. They can be set statically in case they are static routes (e.g. some mixer paths), too. The power up and down events for each pin are triggered via the standard hda_jack table. The call order is hard-coded, relying on the current implementation of jack event chain (a la FILO/stack order). One point to be dealt carefully is that DAC/ADC cannot be powered on/off while streaming. They are pinned as long as the stream is running. For controlling the power of DAC/ADC, a new patch_ops is added. The generic parser provides the default callback for that. As of this patch, only IDT/Sigmatel codec driver enables the flag. The support on other codecs will follow. An assumption we made in this code is that the widget state (e.g. amp, pinctl, connections) remains after the widget power transition (not about FG power transition). This is true for IDT codecs, at least. But if the widget state is lost at widget power transition, we'd need to implement additional code to sync the cached amp/verbs for the specific NID. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_codec.c | 4 + sound/pci/hda/hda_codec.h | 2 + sound/pci/hda/hda_generic.c | 301 ++++++++++++++++++++++++++++++++++------- sound/pci/hda/hda_generic.h | 5 +- sound/pci/hda/patch_sigmatel.c | 5 + 5 files changed, 269 insertions(+), 48 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 3e4fb7a8fdcb..7e38d6f7314b 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -1502,6 +1502,8 @@ void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid, if (!p) return; + if (codec->patch_ops.stream_pm) + codec->patch_ops.stream_pm(codec, nid, true); if (codec->pcm_format_first) update_pcm_format(codec, p, nid, format); update_pcm_stream_id(codec, p, nid, stream_tag, channel_id); @@ -1570,6 +1572,8 @@ static void really_cleanup_stream(struct hda_codec *codec, ); memset(q, 0, sizeof(*q)); q->nid = nid; + if (codec->patch_ops.stream_pm) + codec->patch_ops.stream_pm(codec, nid, false); } /* clean up the all conflicting obsolete streams */ diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index 70851e6d5f10..148e84ce61cf 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h @@ -200,6 +200,7 @@ struct hda_codec_ops { int (*check_power_status)(struct hda_codec *codec, hda_nid_t nid); #endif void (*reboot_notify)(struct hda_codec *codec); + void (*stream_pm)(struct hda_codec *codec, hda_nid_t nid, bool on); }; /* record for amp information cache */ @@ -370,6 +371,7 @@ struct hda_codec { unsigned int cached_write:1; /* write only to caches */ unsigned int dp_mst:1; /* support DP1.2 Multi-stream transport */ unsigned int dump_coef:1; /* dump processing coefs in codec proc file */ + unsigned int power_mgmt:1; /* advanced PM for each widget */ #ifdef CONFIG_PM unsigned int d3_stop_clk:1; /* support D3 operation without BCLK */ atomic_t in_pm; /* suspend/resume being performed */ diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c index 27ce54701f0f..8a5055d296f5 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) val = snd_hda_get_bool_hint(codec, "single_adc_amp"); if (val >= 0) codec->single_adc_amp = !!val; + val = snd_hda_get_bool_hint(codec, "power_mgmt"); + if (val >= 0) + codec->power_mgmt = !!val; val = snd_hda_get_bool_hint(codec, "auto_mute"); if (val >= 0) @@ -648,12 +651,21 @@ static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid, unsigned int dir, unsigned int idx) { struct hda_gen_spec *spec = codec->spec; + int type = get_wcaps_type(get_wcaps(codec, nid)); int i, n; for (n = 0; n < spec->paths.used; n++) { struct nid_path *path = snd_array_elem(&spec->paths, n); if (!path->active) continue; + if (codec->power_mgmt) { + if (!path->stream_enabled) + continue; + /* ignore unplugged paths except for DAC/ADC */ + if (!path->pin_enabled && + type != AC_WID_AUD_OUT && type != AC_WID_AUD_IN) + continue; + } for (i = 0; i < path->depth; i++) { if (path->path[i] == nid) { if (dir == HDA_OUTPUT || path->idx[i] == idx) @@ -807,6 +819,42 @@ static void activate_amp_in(struct hda_codec *codec, struct nid_path *path, } } +/* sync power of each widget in the the given path */ +static hda_nid_t path_power_update(struct hda_codec *codec, + struct nid_path *path, + bool allow_powerdown) +{ + hda_nid_t nid, changed = 0; + int i, state; + + for (i = 0; i < path->depth; i++) { + nid = path->path[i]; + if (!allow_powerdown || is_active_nid_for_any(codec, nid)) + state = AC_PWRST_D0; + else + state = AC_PWRST_D3; + if (!snd_hda_check_power_state(codec, nid, state)) { + snd_hda_codec_write(codec, nid, 0, + AC_VERB_SET_POWER_STATE, state); + changed = nid; + /* here we assume that widget attributes (e.g. amp, + * pinctl connection) don't change with local power + * state change. If not, need to sync the cache. + */ + } + } + return changed; +} + +/* do sync with the last power state change */ +static void sync_power_state_change(struct hda_codec *codec, hda_nid_t nid) +{ + if (nid) { + msleep(10); + snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_POWER_STATE, 0); + } +} + /** * snd_hda_activate_path - activate or deactivate the given path * @codec: the HDA codec @@ -825,15 +873,13 @@ void snd_hda_activate_path(struct hda_codec *codec, struct nid_path *path, if (!enable) path->active = false; + /* make sure the widget is powered up */ + if (enable && (spec->power_down_unused || codec->power_mgmt)) + path_power_update(codec, path, codec->power_mgmt); + for (i = path->depth - 1; i >= 0; i--) { hda_nid_t nid = path->path[i]; - if (enable && spec->power_down_unused) { - /* make sure the widget is powered up */ - if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D0)) - snd_hda_codec_write(codec, nid, 0, - AC_VERB_SET_POWER_STATE, - AC_PWRST_D0); - } + if (enable && path->multi[i]) snd_hda_codec_update_cache(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, @@ -853,28 +899,10 @@ EXPORT_SYMBOL_GPL(snd_hda_activate_path); static void path_power_down_sync(struct hda_codec *codec, struct nid_path *path) { struct hda_gen_spec *spec = codec->spec; - bool changed = false; - int i; - if (!spec->power_down_unused || path->active) + if (!(spec->power_down_unused || codec->power_mgmt) || path->active) return; - - for (i = 0; i < path->depth; i++) { - hda_nid_t nid = path->path[i]; - if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D3) && - !is_active_nid_for_any(codec, nid)) { - snd_hda_codec_write(codec, nid, 0, - AC_VERB_SET_POWER_STATE, - AC_PWRST_D3); - changed = true; - } - } - - if (changed) { - msleep(10); - snd_hda_codec_read(codec, path->path[0], 0, - AC_VERB_GET_POWER_STATE, 0); - } + sync_power_state_change(codec, path_power_update(codec, path, true)); } /* turn on/off EAPD on the given pin */ @@ -1574,6 +1602,7 @@ static int check_aamix_out_path(struct hda_codec *codec, int path_idx) return 0; /* print_nid_path(codec, "output-aamix", path); */ path->active = false; /* unused as default */ + path->pin_enabled = true; /* static route */ return snd_hda_get_path_idx(codec, path); } @@ -2998,6 +3027,7 @@ static int new_analog_input(struct hda_codec *codec, int input_idx, } path->active = true; + path->stream_enabled = true; /* no DAC/ADC involved */ err = add_loopback_list(spec, mix_nid, idx); if (err < 0) return err; @@ -3009,6 +3039,8 @@ static int new_analog_input(struct hda_codec *codec, int input_idx, if (path) { print_nid_path(codec, "loopback-merge", path); path->active = true; + path->pin_enabled = true; /* static route */ + path->stream_enabled = true; /* no DAC/ADC involved */ spec->loopback_merge_path = snd_hda_get_path_idx(codec, path); } @@ -3810,6 +3842,7 @@ static void parse_digital(struct hda_codec *codec) continue; print_nid_path(codec, "digout", path); path->active = true; + path->pin_enabled = true; /* no jack detection */ spec->digout_paths[i] = snd_hda_get_path_idx(codec, path); set_pin_target(codec, pin, PIN_OUT, false); if (!nums) { @@ -3837,6 +3870,7 @@ static void parse_digital(struct hda_codec *codec) if (path) { print_nid_path(codec, "digin", path); path->active = true; + path->pin_enabled = true; /* no jack */ spec->dig_in_nid = dig_nid; spec->digin_path = snd_hda_get_path_idx(codec, path); set_pin_target(codec, pin, PIN_IN, false); @@ -3896,6 +3930,148 @@ static int mux_select(struct hda_codec *codec, unsigned int adc_idx, return 1; } +/* power up/down widgets in the all paths that match with the given NID + * as terminals (either start- or endpoint) + * + * returns the last changed NID, or zero if unchanged. + */ +static hda_nid_t set_path_power(struct hda_codec *codec, hda_nid_t nid, + int pin_state, int stream_state) +{ + struct hda_gen_spec *spec = codec->spec; + hda_nid_t last, changed = 0; + struct nid_path *path; + int n; + + for (n = 0; n < spec->paths.used; n++) { + path = snd_array_elem(&spec->paths, n); + if (path->path[0] == nid || + path->path[path->depth - 1] == nid) { + bool pin_old = path->pin_enabled; + bool stream_old = path->stream_enabled; + + if (pin_state >= 0) + path->pin_enabled = pin_state; + if (stream_state >= 0) + path->stream_enabled = stream_state; + if (path->pin_enabled != pin_old || + path->stream_enabled != stream_old) { + last = path_power_update(codec, path, true); + if (last) + changed = last; + } + } + } + return changed; +} + +/* power up/down the paths of the given pin according to the jack state; + * power = 0/1 : only power up/down if it matches with the jack state, + * < 0 : force power up/down to follow the jack sate + * + * returns the last changed NID, or zero if unchanged. + */ +static hda_nid_t set_pin_power_jack(struct hda_codec *codec, hda_nid_t pin, + int power) +{ + bool on; + + if (!codec->power_mgmt) + return 0; + + on = snd_hda_jack_detect_state(codec, pin) != HDA_JACK_NOT_PRESENT; + if (power >= 0 && on != power) + return 0; + return set_path_power(codec, pin, on, -1); +} + +static void pin_power_callback(struct hda_codec *codec, + struct hda_jack_callback *jack, + bool on) +{ + if (jack && jack->tbl->nid) + sync_power_state_change(codec, + set_pin_power_jack(codec, jack->tbl->nid, on)); +} + +/* callback only doing power up -- called at first */ +static void pin_power_up_callback(struct hda_codec *codec, + struct hda_jack_callback *jack) +{ + pin_power_callback(codec, jack, true); +} + +/* callback only doing power down -- called at last */ +static void pin_power_down_callback(struct hda_codec *codec, + struct hda_jack_callback *jack) +{ + pin_power_callback(codec, jack, false); +} + +/* set up the power up/down callbacks */ +static void add_pin_power_ctls(struct hda_codec *codec, int num_pins, + const hda_nid_t *pins, bool on) +{ + int i; + hda_jack_callback_fn cb = + on ? pin_power_up_callback : pin_power_down_callback; + + for (i = 0; i < num_pins && pins[i]; i++) { + if (is_jack_detectable(codec, pins[i])) + snd_hda_jack_detect_enable_callback(codec, pins[i], cb); + else + set_path_power(codec, pins[i], true, -1); + } +} + +/* enabled power callback to each available I/O pin with jack detections; + * the digital I/O pins are excluded because of the unreliable detectsion + */ +static void add_all_pin_power_ctls(struct hda_codec *codec, bool on) +{ + struct hda_gen_spec *spec = codec->spec; + struct auto_pin_cfg *cfg = &spec->autocfg; + int i; + + if (!codec->power_mgmt) + return; + add_pin_power_ctls(codec, cfg->line_outs, cfg->line_out_pins, on); + if (cfg->line_out_type != AUTO_PIN_HP_OUT) + add_pin_power_ctls(codec, cfg->hp_outs, cfg->hp_pins, on); + if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) + add_pin_power_ctls(codec, cfg->speaker_outs, cfg->speaker_pins, on); + for (i = 0; i < cfg->num_inputs; i++) + add_pin_power_ctls(codec, 1, &cfg->inputs[i].pin, on); +} + +/* sync path power up/down with the jack states of given pins */ +static void sync_pin_power_ctls(struct hda_codec *codec, int num_pins, + const hda_nid_t *pins) +{ + int i; + + for (i = 0; i < num_pins && pins[i]; i++) + if (is_jack_detectable(codec, pins[i])) + set_pin_power_jack(codec, pins[i], -1); +} + +/* sync path power up/down with pins; called at init and resume */ +static void sync_all_pin_power_ctls(struct hda_codec *codec) +{ + struct hda_gen_spec *spec = codec->spec; + struct auto_pin_cfg *cfg = &spec->autocfg; + int i; + + if (!codec->power_mgmt) + return; + sync_pin_power_ctls(codec, cfg->line_outs, cfg->line_out_pins); + if (cfg->line_out_type != AUTO_PIN_HP_OUT) + sync_pin_power_ctls(codec, cfg->hp_outs, cfg->hp_pins); + if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) + sync_pin_power_ctls(codec, cfg->speaker_outs, cfg->speaker_pins); + for (i = 0; i < cfg->num_inputs; i++) + sync_pin_power_ctls(codec, 1, &cfg->inputs[i].pin); +} /* * Jack detections for HP auto-mute and mic-switch @@ -3933,6 +4109,10 @@ static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins, if (!nid) break; + oldval = snd_hda_codec_get_pin_target(codec, nid); + if (oldval & PIN_IN) + continue; /* no mute for inputs */ + if (spec->auto_mute_via_amp) { struct nid_path *path; hda_nid_t mute_nid; @@ -3947,29 +4127,33 @@ static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins, spec->mute_bits |= (1ULL << mute_nid); else spec->mute_bits &= ~(1ULL << mute_nid); - set_pin_eapd(codec, nid, !mute); continue; + } else { + /* don't reset VREF value in case it's controlling + * the amp (see alc861_fixup_asus_amp_vref_0f()) + */ + if (spec->keep_vref_in_automute) + val = oldval & ~PIN_HP; + else + val = 0; + if (!mute) + val |= oldval; + /* here we call update_pin_ctl() so that the pinctl is + * changed without changing the pinctl target value; + * the original target value will be still referred at + * the init / resume again + */ + update_pin_ctl(codec, nid, val); } - oldval = snd_hda_codec_get_pin_target(codec, nid); - if (oldval & PIN_IN) - continue; /* no mute for inputs */ - /* don't reset VREF value in case it's controlling - * the amp (see alc861_fixup_asus_amp_vref_0f()) - */ - if (spec->keep_vref_in_automute) - val = oldval & ~PIN_HP; - else - val = 0; - if (!mute) - val |= oldval; - /* here we call update_pin_ctl() so that the pinctl is changed - * without changing the pinctl target value; - * the original target value will be still referred at the - * init / resume again - */ - update_pin_ctl(codec, nid, val); set_pin_eapd(codec, nid, !mute); + if (codec->power_mgmt) { + bool on = !mute; + if (on) + on = snd_hda_jack_detect_state(codec, nid) + != HDA_JACK_NOT_PRESENT; + set_path_power(codec, nid, on, -1); + } } } @@ -4465,6 +4649,21 @@ static void mute_all_mixer_nid(struct hda_codec *codec, hda_nid_t mix) } } +/** + * snd_hda_gen_stream_pm - Stream power management callback + * @codec: the HDA codec + * @nid: audio widget + * @on: power on/off flag + * + * Set this in patch_ops.stream_pm. Only valid with power_mgmt flag. + */ +void snd_hda_gen_stream_pm(struct hda_codec *codec, hda_nid_t nid, bool on) +{ + if (codec->power_mgmt) + set_path_power(codec, nid, -1, on); +} +EXPORT_SYMBOL_GPL(snd_hda_gen_stream_pm); + /** * snd_hda_gen_parse_auto_config - Parse the given BIOS configuration and * set up the hda_gen_spec @@ -4549,6 +4748,9 @@ int snd_hda_gen_parse_auto_config(struct hda_codec *codec, if (err < 0) return err; + /* add power-down pin callbacks at first */ + add_all_pin_power_ctls(codec, false); + spec->const_channel_count = spec->ext_channel_count; /* check the multiple speaker and headphone pins */ if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) @@ -4618,6 +4820,9 @@ int snd_hda_gen_parse_auto_config(struct hda_codec *codec, } } + /* add power-up pin callbacks at last */ + add_all_pin_power_ctls(codec, true); + /* mute all aamix input initially */ if (spec->mixer_nid) mute_all_mixer_nid(codec, spec->mixer_nid); @@ -4625,7 +4830,7 @@ int snd_hda_gen_parse_auto_config(struct hda_codec *codec, dig_only: parse_digital(codec); - if (spec->power_down_unused) + if (spec->power_down_unused || codec->power_mgmt) codec->power_filter = snd_hda_gen_path_power_filter; if (!spec->no_analog && spec->beep_nid) { @@ -5478,6 +5683,8 @@ int snd_hda_gen_init(struct hda_codec *codec) clear_unsol_on_unused_pins(codec); + sync_all_pin_power_ctls(codec); + /* call init functions of standard auto-mute helpers */ update_automute_all(codec); diff --git a/sound/pci/hda/hda_generic.h b/sound/pci/hda/hda_generic.h index b211f889b335..54659b51fe16 100644 --- a/sound/pci/hda/hda_generic.h +++ b/sound/pci/hda/hda_generic.h @@ -46,7 +46,9 @@ struct nid_path { unsigned char idx[MAX_NID_PATH_DEPTH]; unsigned char multi[MAX_NID_PATH_DEPTH]; unsigned int ctls[NID_PATH_NUM_CTLS]; /* NID_PATH_XXX_CTL */ - bool active; + bool active:1; /* activated by driver */ + bool pin_enabled:1; /* pins are enabled */ + bool stream_enabled:1; /* stream is active */ }; /* mic/line-in auto switching entry */ @@ -340,5 +342,6 @@ int snd_hda_gen_check_power_status(struct hda_codec *codec, hda_nid_t nid); unsigned int snd_hda_gen_path_power_filter(struct hda_codec *codec, hda_nid_t nid, unsigned int power_state); +void snd_hda_gen_stream_pm(struct hda_codec *codec, hda_nid_t nid, bool on); #endif /* __SOUND_HDA_GENERIC_H */ diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c index 2956a6ba6bf0..86b944a6b0ed 100644 --- a/sound/pci/hda/patch_sigmatel.c +++ b/sound/pci/hda/patch_sigmatel.c @@ -4394,6 +4394,7 @@ static const struct hda_codec_ops stac_patch_ops = { #ifdef CONFIG_PM .suspend = stac_suspend, #endif + .stream_pm = snd_hda_gen_stream_pm, .reboot_notify = stac_shutup, }; @@ -4487,6 +4488,7 @@ static int patch_stac92hd73xx(struct hda_codec *codec) return err; spec = codec->spec; + codec->power_mgmt = 1; spec->linear_tone_beep = 0; spec->gen.mixer_nid = 0x1d; spec->have_spdif_mux = 1; @@ -4592,6 +4594,7 @@ static int patch_stac92hd83xxx(struct hda_codec *codec) codec->epss = 0; /* longer delay needed for D3 */ spec = codec->spec; + codec->power_mgmt = 1; spec->linear_tone_beep = 0; spec->gen.own_eapd_ctl = 1; spec->gen.power_down_unused = 1; @@ -4641,6 +4644,7 @@ static int patch_stac92hd95(struct hda_codec *codec) codec->epss = 0; /* longer delay needed for D3 */ spec = codec->spec; + codec->power_mgmt = 1; spec->linear_tone_beep = 0; spec->gen.own_eapd_ctl = 1; spec->gen.power_down_unused = 1; @@ -4682,6 +4686,7 @@ static int patch_stac92hd71bxx(struct hda_codec *codec) return err; spec = codec->spec; + codec->power_mgmt = 1; spec->linear_tone_beep = 0; spec->gen.own_eapd_ctl = 1; spec->gen.power_down_unused = 1; -- cgit v1.2.3 From 688b12cc3ca8a5155b95ce8d01e0e43006813b27 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 17 Mar 2015 15:56:05 +0100 Subject: ALSA: hda - Use the new power control for VIA codecs VIA codecs used to have the own power controls but they were disabled at transition to the generic parser due to the coding assuming the fixed routes. Now we get the proper support of equivalently fine power management in the generic parser, and the old kludges can be replaced with it. This results in the reduction of lots of dead codes. The advanced PM feature is disabled as default like before for keeping the compatible behavior. It's enabled via "Dynamic Power-Control" mixer element. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 662 +--------------------------------------------- 1 file changed, 12 insertions(+), 650 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 2112fbe9e577..d5d1dca4f11b 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -99,7 +99,6 @@ struct via_spec { /* HP mode source */ unsigned int dmic_enabled; - unsigned int no_pin_power_ctl; enum VIA_HDA_CODEC codec_type; /* analog low-power control */ @@ -108,9 +107,6 @@ struct via_spec { /* work to check hp jack state */ int hp_work_active; int vt1708_jack_detect; - - void (*set_widgets_power_state)(struct hda_codec *codec); - unsigned int dac_stream_tag[4]; }; static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec); @@ -133,11 +129,12 @@ static struct via_spec *via_new_spec(struct hda_codec *codec) /* VT1708BCE & VT1708S are almost same */ if (spec->codec_type == VT1708BCE) spec->codec_type = VT1708S; - spec->no_pin_power_ctl = 1; spec->gen.indep_hp = 1; spec->gen.keep_eapd_on = 1; spec->gen.pcm_playback_hook = via_playback_pcm_hook; spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO; + codec->power_mgmt = 1; + spec->gen.power_down_unused = 1; return spec; } @@ -229,90 +226,6 @@ static void vt1708_update_hp_work(struct hda_codec *codec) vt1708_stop_hp_work(codec); } -static void set_widgets_power_state(struct hda_codec *codec) -{ -#if 0 /* FIXME: the assumed connections don't match always with the - * actual routes by the generic parser, so better to disable - * the control for safety. - */ - struct via_spec *spec = codec->spec; - if (spec->set_widgets_power_state) - spec->set_widgets_power_state(codec); -#endif -} - -static void update_power_state(struct hda_codec *codec, hda_nid_t nid, - unsigned int parm) -{ - if (snd_hda_check_power_state(codec, nid, parm)) - return; - snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm); -} - -static void update_conv_power_state(struct hda_codec *codec, hda_nid_t nid, - unsigned int parm, unsigned int index) -{ - struct via_spec *spec = codec->spec; - unsigned int format; - - if (snd_hda_check_power_state(codec, nid, parm)) - return; - format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0); - if (format && (spec->dac_stream_tag[index] != format)) - spec->dac_stream_tag[index] = format; - - snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm); - if (parm == AC_PWRST_D0) { - format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0); - if (!format && (spec->dac_stream_tag[index] != format)) - snd_hda_codec_write(codec, nid, 0, - AC_VERB_SET_CHANNEL_STREAMID, - spec->dac_stream_tag[index]); - } -} - -static bool smart51_enabled(struct hda_codec *codec) -{ - struct via_spec *spec = codec->spec; - return spec->gen.ext_channel_count > 2; -} - -static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin) -{ - struct via_spec *spec = codec->spec; - int i; - - for (i = 0; i < spec->gen.multi_ios; i++) - if (spec->gen.multi_io[i].pin == pin) - return true; - return false; -} - -static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid, - unsigned int *affected_parm) -{ - unsigned parm; - unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid); - unsigned no_presence = (def_conf & AC_DEFCFG_MISC) - >> AC_DEFCFG_MISC_SHIFT - & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */ - struct via_spec *spec = codec->spec; - unsigned present = 0; - - no_presence |= spec->no_pin_power_ctl; - if (!no_presence) - present = snd_hda_jack_detect(codec, nid); - if ((smart51_enabled(codec) && is_smart51_pins(codec, nid)) - || ((no_presence || present) - && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) { - *affected_parm = AC_PWRST_D0; /* if it's connected */ - parm = AC_PWRST_D0; - } else - parm = AC_PWRST_D3; - - update_power_state(codec, nid, parm); -} - static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { @@ -323,8 +236,7 @@ static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); - struct via_spec *spec = codec->spec; - ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl; + ucontrol->value.enumerated.item[0] = codec->power_mgmt; return 0; } @@ -333,12 +245,12 @@ static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol, { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct via_spec *spec = codec->spec; - unsigned int val = !ucontrol->value.enumerated.item[0]; + bool val = !!ucontrol->value.enumerated.item[0]; - if (val == spec->no_pin_power_ctl) + if (val == codec->power_mgmt) return 0; - spec->no_pin_power_ctl = val; - set_widgets_power_state(codec); + codec->power_mgmt = val; + spec->gen.power_down_unused = val; analog_low_current_mode(codec); return 1; } @@ -383,7 +295,7 @@ static void __analog_low_current_mode(struct hda_codec *codec, bool force) bool enable; unsigned int verb, parm; - if (spec->no_pin_power_ctl) + if (!codec->power_mgmt) enable = false; else enable = is_aa_path_mute(codec) && !spec->gen.active_streams; @@ -440,8 +352,7 @@ static int via_build_controls(struct hda_codec *codec) if (err < 0) return err; - if (spec->set_widgets_power_state) - spec->mixers[spec->num_mixers++] = via_pin_power_ctl_enum; + spec->mixers[spec->num_mixers++] = via_pin_power_ctl_enum; for (i = 0; i < spec->num_mixers; i++) { err = snd_hda_add_new_ctls(codec, spec->mixers[i]); @@ -485,7 +396,6 @@ static int via_suspend(struct hda_codec *codec) static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid) { struct via_spec *spec = codec->spec; - set_widgets_power_state(codec); analog_low_current_mode(codec); vt1708_update_hp_work(codec); return snd_hda_check_amp_list_power(codec, &spec->gen.loopback, nid); @@ -573,34 +483,6 @@ static const struct snd_kcontrol_new vt1708_jack_detect_ctl[] = { {} /* terminator */ }; -static void via_jack_powerstate_event(struct hda_codec *codec, - struct hda_jack_callback *tbl) -{ - set_widgets_power_state(codec); -} - -static void via_set_jack_unsol_events(struct hda_codec *codec) -{ - struct via_spec *spec = codec->spec; - struct auto_pin_cfg *cfg = &spec->gen.autocfg; - hda_nid_t pin; - int i; - - for (i = 0; i < cfg->line_outs; i++) { - pin = cfg->line_out_pins[i]; - if (pin && is_jack_detectable(codec, pin)) - snd_hda_jack_detect_enable_callback(codec, pin, - via_jack_powerstate_event); - } - - for (i = 0; i < cfg->num_inputs; i++) { - pin = cfg->line_out_pins[i]; - if (pin && is_jack_detectable(codec, pin)) - snd_hda_jack_detect_enable_callback(codec, pin, - via_jack_powerstate_event); - } -} - static const struct badness_table via_main_out_badness = { .no_primary_dac = 0x10000, .no_dac = 0x4000, @@ -634,7 +516,9 @@ static int via_parse_auto_config(struct hda_codec *codec) if (err < 0) return err; - via_set_jack_unsol_events(codec); + /* disable widget PM at start for compatibility */ + codec->power_mgmt = 0; + spec->gen.power_down_unused = 0; return 0; } @@ -647,7 +531,6 @@ static int via_init(struct hda_codec *codec) snd_hda_sequence_write(codec, spec->init_verbs[i]); /* init power states */ - set_widgets_power_state(codec); __analog_low_current_mode(codec, true); snd_hda_gen_init(codec); @@ -767,78 +650,6 @@ static int patch_vt1709(struct hda_codec *codec) return 0; } -static void set_widgets_power_state_vt1708B(struct hda_codec *codec) -{ - struct via_spec *spec = codec->spec; - int imux_is_smixer; - unsigned int parm; - int is_8ch = 0; - if ((spec->codec_type != VT1708B_4CH) && - (codec->vendor_id != 0x11064397)) - is_8ch = 1; - - /* SW0 (17h) = stereo mixer */ - imux_is_smixer = - (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00) - == ((spec->codec_type == VT1708S) ? 5 : 0)); - /* inputs */ - /* PW 1/2/5 (1ah/1bh/1eh) */ - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x1a, &parm); - set_pin_power_state(codec, 0x1b, &parm); - set_pin_power_state(codec, 0x1e, &parm); - if (imux_is_smixer) - parm = AC_PWRST_D0; - /* SW0 (17h), AIW 0/1 (13h/14h) */ - update_power_state(codec, 0x17, parm); - update_power_state(codec, 0x13, parm); - update_power_state(codec, 0x14, parm); - - /* outputs */ - /* PW0 (19h), SW1 (18h), AOW1 (11h) */ - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x19, &parm); - if (smart51_enabled(codec)) - set_pin_power_state(codec, 0x1b, &parm); - update_power_state(codec, 0x18, parm); - update_power_state(codec, 0x11, parm); - - /* PW6 (22h), SW2 (26h), AOW2 (24h) */ - if (is_8ch) { - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x22, &parm); - if (smart51_enabled(codec)) - set_pin_power_state(codec, 0x1a, &parm); - update_power_state(codec, 0x26, parm); - update_power_state(codec, 0x24, parm); - } else if (codec->vendor_id == 0x11064397) { - /* PW7(23h), SW2(27h), AOW2(25h) */ - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x23, &parm); - if (smart51_enabled(codec)) - set_pin_power_state(codec, 0x1a, &parm); - update_power_state(codec, 0x27, parm); - update_power_state(codec, 0x25, parm); - } - - /* PW 3/4/7 (1ch/1dh/23h) */ - parm = AC_PWRST_D3; - /* force to D0 for internal Speaker */ - set_pin_power_state(codec, 0x1c, &parm); - set_pin_power_state(codec, 0x1d, &parm); - if (is_8ch) - set_pin_power_state(codec, 0x23, &parm); - - /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */ - update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm); - update_power_state(codec, 0x10, parm); - if (is_8ch) { - update_power_state(codec, 0x25, parm); - update_power_state(codec, 0x27, parm); - } else if (codec->vendor_id == 0x11064397 && spec->gen.indep_hp_enabled) - update_power_state(codec, 0x25, parm); -} - static int patch_vt1708S(struct hda_codec *codec); static int patch_vt1708B(struct hda_codec *codec) { @@ -863,9 +674,6 @@ static int patch_vt1708B(struct hda_codec *codec) } codec->patch_ops = via_patch_ops; - - spec->set_widgets_power_state = set_widgets_power_state_vt1708B; - return 0; } @@ -931,8 +739,6 @@ static int patch_vt1708S(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs; codec->patch_ops = via_patch_ops; - - spec->set_widgets_power_state = set_widgets_power_state_vt1708B; return 0; } @@ -946,36 +752,6 @@ static const struct hda_verb vt1702_init_verbs[] = { { } }; -static void set_widgets_power_state_vt1702(struct hda_codec *codec) -{ - int imux_is_smixer = - snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3; - unsigned int parm; - /* inputs */ - /* PW 1/2/5 (14h/15h/18h) */ - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x14, &parm); - set_pin_power_state(codec, 0x15, &parm); - set_pin_power_state(codec, 0x18, &parm); - if (imux_is_smixer) - parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */ - /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */ - update_power_state(codec, 0x13, parm); - update_power_state(codec, 0x12, parm); - update_power_state(codec, 0x1f, parm); - update_power_state(codec, 0x20, parm); - - /* outputs */ - /* PW 3/4 (16h/17h) */ - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x17, &parm); - set_pin_power_state(codec, 0x16, &parm); - /* MW0 (1ah), AOW 0/1 (10h/1dh) */ - update_power_state(codec, 0x1a, imux_is_smixer ? AC_PWRST_D0 : parm); - update_power_state(codec, 0x10, parm); - update_power_state(codec, 0x1d, parm); -} - static int patch_vt1702(struct hda_codec *codec) { struct via_spec *spec; @@ -1005,8 +781,6 @@ static int patch_vt1702(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs; codec->patch_ops = via_patch_ops; - - spec->set_widgets_power_state = set_widgets_power_state_vt1702; return 0; } @@ -1021,71 +795,6 @@ static const struct hda_verb vt1718S_init_verbs[] = { { } }; -static void set_widgets_power_state_vt1718S(struct hda_codec *codec) -{ - struct via_spec *spec = codec->spec; - int imux_is_smixer; - unsigned int parm, parm2; - /* MUX6 (1eh) = stereo mixer */ - imux_is_smixer = - snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5; - /* inputs */ - /* PW 5/6/7 (29h/2ah/2bh) */ - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x29, &parm); - set_pin_power_state(codec, 0x2a, &parm); - set_pin_power_state(codec, 0x2b, &parm); - if (imux_is_smixer) - parm = AC_PWRST_D0; - /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */ - update_power_state(codec, 0x1e, parm); - update_power_state(codec, 0x1f, parm); - update_power_state(codec, 0x10, parm); - update_power_state(codec, 0x11, parm); - - /* outputs */ - /* PW3 (27h), MW2 (1ah), AOW3 (bh) */ - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x27, &parm); - update_power_state(codec, 0x1a, parm); - parm2 = parm; /* for pin 0x0b */ - - /* PW2 (26h), AOW2 (ah) */ - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x26, &parm); - if (smart51_enabled(codec)) - set_pin_power_state(codec, 0x2b, &parm); - update_power_state(codec, 0xa, parm); - - /* PW0 (24h), AOW0 (8h) */ - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x24, &parm); - if (!spec->gen.indep_hp_enabled) /* check for redirected HP */ - set_pin_power_state(codec, 0x28, &parm); - update_power_state(codec, 0x8, parm); - if (!spec->gen.indep_hp_enabled && parm2 != AC_PWRST_D3) - parm = parm2; - update_power_state(codec, 0xb, parm); - /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */ - update_power_state(codec, 0x21, imux_is_smixer ? AC_PWRST_D0 : parm); - - /* PW1 (25h), AOW1 (9h) */ - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x25, &parm); - if (smart51_enabled(codec)) - set_pin_power_state(codec, 0x2a, &parm); - update_power_state(codec, 0x9, parm); - - if (spec->gen.indep_hp_enabled) { - /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */ - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x28, &parm); - update_power_state(codec, 0x1b, parm); - update_power_state(codec, 0x34, parm); - update_power_state(codec, 0xc, parm); - } -} - /* Add a connection to the primary DAC from AA-mixer for some codecs * This isn't listed from the raw info, but the chip has a secret connection. */ @@ -1146,9 +855,6 @@ static int patch_vt1718S(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs; codec->patch_ops = via_patch_ops; - - spec->set_widgets_power_state = set_widgets_power_state_vt1718S; - return 0; } @@ -1188,7 +894,6 @@ static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol, snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_CONNECT_SEL, index); spec->dmic_enabled = index; - set_widgets_power_state(codec); return 1; } @@ -1223,95 +928,6 @@ static const struct hda_verb vt1716S_init_verbs[] = { { } }; -static void set_widgets_power_state_vt1716S(struct hda_codec *codec) -{ - struct via_spec *spec = codec->spec; - int imux_is_smixer; - unsigned int parm; - unsigned int mono_out, present; - /* SW0 (17h) = stereo mixer */ - imux_is_smixer = - (snd_hda_codec_read(codec, 0x17, 0, - AC_VERB_GET_CONNECT_SEL, 0x00) == 5); - /* inputs */ - /* PW 1/2/5 (1ah/1bh/1eh) */ - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x1a, &parm); - set_pin_power_state(codec, 0x1b, &parm); - set_pin_power_state(codec, 0x1e, &parm); - if (imux_is_smixer) - parm = AC_PWRST_D0; - /* SW0 (17h), AIW0(13h) */ - update_power_state(codec, 0x17, parm); - update_power_state(codec, 0x13, parm); - - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x1e, &parm); - /* PW11 (22h) */ - if (spec->dmic_enabled) - set_pin_power_state(codec, 0x22, &parm); - else - update_power_state(codec, 0x22, AC_PWRST_D3); - - /* SW2(26h), AIW1(14h) */ - update_power_state(codec, 0x26, parm); - update_power_state(codec, 0x14, parm); - - /* outputs */ - /* PW0 (19h), SW1 (18h), AOW1 (11h) */ - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x19, &parm); - /* Smart 5.1 PW2(1bh) */ - if (smart51_enabled(codec)) - set_pin_power_state(codec, 0x1b, &parm); - update_power_state(codec, 0x18, parm); - update_power_state(codec, 0x11, parm); - - /* PW7 (23h), SW3 (27h), AOW3 (25h) */ - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x23, &parm); - /* Smart 5.1 PW1(1ah) */ - if (smart51_enabled(codec)) - set_pin_power_state(codec, 0x1a, &parm); - update_power_state(codec, 0x27, parm); - - /* Smart 5.1 PW5(1eh) */ - if (smart51_enabled(codec)) - set_pin_power_state(codec, 0x1e, &parm); - update_power_state(codec, 0x25, parm); - - /* Mono out */ - /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/ - present = snd_hda_jack_detect(codec, 0x1c); - - if (present) - mono_out = 0; - else { - present = snd_hda_jack_detect(codec, 0x1d); - if (!spec->gen.indep_hp_enabled && present) - mono_out = 0; - else - mono_out = 1; - } - parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3; - update_power_state(codec, 0x28, parm); - update_power_state(codec, 0x29, parm); - update_power_state(codec, 0x2a, parm); - - /* PW 3/4 (1ch/1dh) */ - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x1c, &parm); - set_pin_power_state(codec, 0x1d, &parm); - /* HP Independent Mode, power on AOW3 */ - if (spec->gen.indep_hp_enabled) - update_power_state(codec, 0x25, parm); - - /* force to D0 for internal Speaker */ - /* MW0 (16h), AOW0 (10h) */ - update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm); - update_power_state(codec, 0x10, mono_out ? AC_PWRST_D0 : parm); -} - static int patch_vt1716S(struct hda_codec *codec) { struct via_spec *spec; @@ -1339,8 +955,6 @@ static int patch_vt1716S(struct hda_codec *codec) spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer; codec->patch_ops = via_patch_ops; - - spec->set_widgets_power_state = set_widgets_power_state_vt1716S; return 0; } @@ -1366,98 +980,6 @@ static const struct hda_verb vt1802_init_verbs[] = { { } }; -static void set_widgets_power_state_vt2002P(struct hda_codec *codec) -{ - struct via_spec *spec = codec->spec; - int imux_is_smixer; - unsigned int parm; - unsigned int present; - /* MUX9 (1eh) = stereo mixer */ - imux_is_smixer = - snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3; - /* inputs */ - /* PW 5/6/7 (29h/2ah/2bh) */ - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x29, &parm); - set_pin_power_state(codec, 0x2a, &parm); - set_pin_power_state(codec, 0x2b, &parm); - parm = AC_PWRST_D0; - /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */ - update_power_state(codec, 0x1e, parm); - update_power_state(codec, 0x1f, parm); - update_power_state(codec, 0x10, parm); - update_power_state(codec, 0x11, parm); - - /* outputs */ - /* AOW0 (8h)*/ - update_power_state(codec, 0x8, parm); - - if (spec->codec_type == VT1802) { - /* PW4 (28h), MW4 (18h), MUX4(38h) */ - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x28, &parm); - update_power_state(codec, 0x18, parm); - update_power_state(codec, 0x38, parm); - } else { - /* PW4 (26h), MW4 (1ch), MUX4(37h) */ - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x26, &parm); - update_power_state(codec, 0x1c, parm); - update_power_state(codec, 0x37, parm); - } - - if (spec->codec_type == VT1802) { - /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */ - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x25, &parm); - update_power_state(codec, 0x15, parm); - update_power_state(codec, 0x35, parm); - } else { - /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */ - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x25, &parm); - update_power_state(codec, 0x19, parm); - update_power_state(codec, 0x35, parm); - } - - if (spec->gen.indep_hp_enabled) - update_power_state(codec, 0x9, AC_PWRST_D0); - - /* Class-D */ - /* PW0 (24h), MW0(18h/14h), MUX0(34h) */ - present = snd_hda_jack_detect(codec, 0x25); - - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x24, &parm); - parm = present ? AC_PWRST_D3 : AC_PWRST_D0; - if (spec->codec_type == VT1802) - update_power_state(codec, 0x14, parm); - else - update_power_state(codec, 0x18, parm); - update_power_state(codec, 0x34, parm); - - /* Mono Out */ - present = snd_hda_jack_detect(codec, 0x26); - - parm = present ? AC_PWRST_D3 : AC_PWRST_D0; - if (spec->codec_type == VT1802) { - /* PW15 (33h), MW8(1ch), MUX8(3ch) */ - update_power_state(codec, 0x33, parm); - update_power_state(codec, 0x1c, parm); - update_power_state(codec, 0x3c, parm); - } else { - /* PW15 (31h), MW8(17h), MUX8(3bh) */ - update_power_state(codec, 0x31, parm); - update_power_state(codec, 0x17, parm); - update_power_state(codec, 0x3b, parm); - } - /* MW9 (21h) */ - if (imux_is_smixer || !is_aa_path_mute(codec)) - update_power_state(codec, 0x21, AC_PWRST_D0); - else - update_power_state(codec, 0x21, AC_PWRST_D3); -} - /* * pin fix-up */ @@ -1541,8 +1063,6 @@ static int patch_vt2002P(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs; codec->patch_ops = via_patch_ops; - - spec->set_widgets_power_state = set_widgets_power_state_vt2002P; return 0; } @@ -1556,81 +1076,6 @@ static const struct hda_verb vt1812_init_verbs[] = { { } }; -static void set_widgets_power_state_vt1812(struct hda_codec *codec) -{ - struct via_spec *spec = codec->spec; - unsigned int parm; - unsigned int present; - /* inputs */ - /* PW 5/6/7 (29h/2ah/2bh) */ - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x29, &parm); - set_pin_power_state(codec, 0x2a, &parm); - set_pin_power_state(codec, 0x2b, &parm); - parm = AC_PWRST_D0; - /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */ - update_power_state(codec, 0x1e, parm); - update_power_state(codec, 0x1f, parm); - update_power_state(codec, 0x10, parm); - update_power_state(codec, 0x11, parm); - - /* outputs */ - /* AOW0 (8h)*/ - update_power_state(codec, 0x8, AC_PWRST_D0); - - /* PW4 (28h), MW4 (18h), MUX4(38h) */ - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x28, &parm); - update_power_state(codec, 0x18, parm); - update_power_state(codec, 0x38, parm); - - /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */ - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x25, &parm); - update_power_state(codec, 0x15, parm); - update_power_state(codec, 0x35, parm); - if (spec->gen.indep_hp_enabled) - update_power_state(codec, 0x9, AC_PWRST_D0); - - /* Internal Speaker */ - /* PW0 (24h), MW0(14h), MUX0(34h) */ - present = snd_hda_jack_detect(codec, 0x25); - - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x24, &parm); - if (present) { - update_power_state(codec, 0x14, AC_PWRST_D3); - update_power_state(codec, 0x34, AC_PWRST_D3); - } else { - update_power_state(codec, 0x14, AC_PWRST_D0); - update_power_state(codec, 0x34, AC_PWRST_D0); - } - - - /* Mono Out */ - /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */ - present = snd_hda_jack_detect(codec, 0x28); - - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x31, &parm); - if (present) { - update_power_state(codec, 0x1c, AC_PWRST_D3); - update_power_state(codec, 0x3c, AC_PWRST_D3); - update_power_state(codec, 0x3e, AC_PWRST_D3); - } else { - update_power_state(codec, 0x1c, AC_PWRST_D0); - update_power_state(codec, 0x3c, AC_PWRST_D0); - update_power_state(codec, 0x3e, AC_PWRST_D0); - } - - /* PW15 (33h), MW15 (1dh), MUX15(3dh) */ - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x33, &parm); - update_power_state(codec, 0x1d, parm); - update_power_state(codec, 0x3d, parm); - -} - /* patch for vt1812 */ static int patch_vt1812(struct hda_codec *codec) { @@ -1657,8 +1102,6 @@ static int patch_vt1812(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs; codec->patch_ops = via_patch_ops; - - spec->set_widgets_power_state = set_widgets_power_state_vt1812; return 0; } @@ -1674,84 +1117,6 @@ static const struct hda_verb vt3476_init_verbs[] = { { } }; -static void set_widgets_power_state_vt3476(struct hda_codec *codec) -{ - struct via_spec *spec = codec->spec; - int imux_is_smixer; - unsigned int parm, parm2; - /* MUX10 (1eh) = stereo mixer */ - imux_is_smixer = - snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 4; - /* inputs */ - /* PW 5/6/7 (29h/2ah/2bh) */ - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x29, &parm); - set_pin_power_state(codec, 0x2a, &parm); - set_pin_power_state(codec, 0x2b, &parm); - if (imux_is_smixer) - parm = AC_PWRST_D0; - /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */ - update_power_state(codec, 0x1e, parm); - update_power_state(codec, 0x1f, parm); - update_power_state(codec, 0x10, parm); - update_power_state(codec, 0x11, parm); - - /* outputs */ - /* PW3 (27h), MW3(37h), AOW3 (bh) */ - if (spec->codec_type == VT1705CF) { - parm = AC_PWRST_D3; - update_power_state(codec, 0x27, parm); - update_power_state(codec, 0x37, parm); - } else { - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x27, &parm); - update_power_state(codec, 0x37, parm); - } - - /* PW2 (26h), MW2(36h), AOW2 (ah) */ - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x26, &parm); - update_power_state(codec, 0x36, parm); - if (smart51_enabled(codec)) { - /* PW7(2bh), MW7(3bh), MUX7(1Bh) */ - set_pin_power_state(codec, 0x2b, &parm); - update_power_state(codec, 0x3b, parm); - update_power_state(codec, 0x1b, parm); - } - update_conv_power_state(codec, 0xa, parm, 2); - - /* PW1 (25h), MW1(35h), AOW1 (9h) */ - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x25, &parm); - update_power_state(codec, 0x35, parm); - if (smart51_enabled(codec)) { - /* PW6(2ah), MW6(3ah), MUX6(1ah) */ - set_pin_power_state(codec, 0x2a, &parm); - update_power_state(codec, 0x3a, parm); - update_power_state(codec, 0x1a, parm); - } - update_conv_power_state(codec, 0x9, parm, 1); - - /* PW4 (28h), MW4 (38h), MUX4(18h), AOW3(bh)/AOW0(8h) */ - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x28, &parm); - update_power_state(codec, 0x38, parm); - update_power_state(codec, 0x18, parm); - if (spec->gen.indep_hp_enabled) - update_conv_power_state(codec, 0xb, parm, 3); - parm2 = parm; /* for pin 0x0b */ - - /* PW0 (24h), MW0(34h), MW9(3fh), AOW0 (8h) */ - parm = AC_PWRST_D3; - set_pin_power_state(codec, 0x24, &parm); - update_power_state(codec, 0x34, parm); - if (!spec->gen.indep_hp_enabled && parm2 != AC_PWRST_D3) - parm = parm2; - update_conv_power_state(codec, 0x8, parm, 0); - /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */ - update_power_state(codec, 0x3f, imux_is_smixer ? AC_PWRST_D0 : parm); -} - static int patch_vt3476(struct hda_codec *codec) { struct via_spec *spec; @@ -1775,9 +1140,6 @@ static int patch_vt3476(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt3476_init_verbs; codec->patch_ops = via_patch_ops; - - spec->set_widgets_power_state = set_widgets_power_state_vt3476; - return 0; } -- cgit v1.2.3 From 5ccf835cc76d89bc0d426659c63d81f609050842 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Wed, 18 Mar 2015 09:23:10 +0100 Subject: ALSA: hda - Adjust power of beep widget and outputs As the widget PM may turn off the pins, this might lead to the silent output for beep when no explicit paths are given. This patch adds fake output paths for the beep widget so that the output pins are dynamically powered upon beep on/off. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_beep.c | 29 ++++++++++--------- sound/pci/hda/hda_beep.h | 1 + sound/pci/hda/hda_generic.c | 69 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 13 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_beep.c b/sound/pci/hda/hda_beep.c index 581b7fdef0e3..4cdac3a71cae 100644 --- a/sound/pci/hda/hda_beep.c +++ b/sound/pci/hda/hda_beep.c @@ -33,30 +33,36 @@ enum { DIGBEEP_HZ_MAX = 12000000, /* 12 KHz */ }; -static void snd_hda_generate_beep(struct work_struct *work) +/* generate or stop tone */ +static void generate_tone(struct hda_beep *beep, int tone) { - struct hda_beep *beep = - container_of(work, struct hda_beep, beep_work); struct hda_codec *codec = beep->codec; - int tone; - if (!beep->enabled) - return; - - tone = beep->tone; if (tone && !beep->playing) { snd_hda_power_up(codec); + if (beep->power_hook) + beep->power_hook(beep, true); beep->playing = 1; } - /* generate tone */ snd_hda_codec_write(codec, beep->nid, 0, AC_VERB_SET_BEEP_CONTROL, tone); if (!tone && beep->playing) { beep->playing = 0; + if (beep->power_hook) + beep->power_hook(beep, false); snd_hda_power_down(codec); } } +static void snd_hda_generate_beep(struct work_struct *work) +{ + struct hda_beep *beep = + container_of(work, struct hda_beep, beep_work); + + if (beep->enabled) + generate_tone(beep, beep->tone); +} + /* (non-standard) Linear beep tone calculation for IDT/STAC codecs * * The tone frequency of beep generator on IDT/STAC codecs is @@ -130,10 +136,7 @@ static void turn_off_beep(struct hda_beep *beep) cancel_work_sync(&beep->beep_work); if (beep->playing) { /* turn off beep */ - snd_hda_codec_write(beep->codec, beep->nid, 0, - AC_VERB_SET_BEEP_CONTROL, 0); - beep->playing = 0; - snd_hda_power_down(beep->codec); + generate_tone(beep, 0); } } 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 { unsigned int playing:1; struct work_struct beep_work; /* scheduled task for beep event */ struct mutex mutex; + void (*power_hook)(struct hda_beep *beep, bool on); }; #ifdef CONFIG_SND_HDA_INPUT_BEEP diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c index 8a5055d296f5..d7ca388651da 100644 --- a/sound/pci/hda/hda_generic.c +++ b/sound/pci/hda/hda_generic.c @@ -654,6 +654,9 @@ static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid, int type = get_wcaps_type(get_wcaps(codec, nid)); int i, n; + if (nid == codec->afg) + return true; + for (n = 0; n < spec->paths.used; n++) { struct nid_path *path = snd_array_elem(&spec->paths, n); if (!path->active) @@ -829,6 +832,8 @@ static hda_nid_t path_power_update(struct hda_codec *codec, for (i = 0; i < path->depth; i++) { nid = path->path[i]; + if (nid == codec->afg) + continue; if (!allow_powerdown || is_active_nid_for_any(codec, nid)) state = AC_PWRST_D0; else @@ -4073,6 +4078,64 @@ static void sync_all_pin_power_ctls(struct hda_codec *codec) sync_pin_power_ctls(codec, 1, &cfg->inputs[i].pin); } +/* add fake paths if not present yet */ +static int add_fake_paths(struct hda_codec *codec, hda_nid_t nid, + int num_pins, const hda_nid_t *pins) +{ + struct hda_gen_spec *spec = codec->spec; + struct nid_path *path; + int i; + + for (i = 0; i < num_pins; i++) { + if (!pins[i]) + break; + if (get_nid_path(codec, nid, pins[i], 0)) + continue; + path = snd_array_new(&spec->paths); + if (!path) + return -ENOMEM; + memset(path, 0, sizeof(*path)); + path->depth = 2; + path->path[0] = nid; + path->path[1] = pins[i]; + path->active = true; + } + return 0; +} + +/* create fake paths to all outputs from beep */ +static int add_fake_beep_paths(struct hda_codec *codec) +{ + struct hda_gen_spec *spec = codec->spec; + struct auto_pin_cfg *cfg = &spec->autocfg; + hda_nid_t nid = spec->beep_nid; + int err; + + if (!codec->power_mgmt || !nid) + return 0; + err = add_fake_paths(codec, nid, cfg->line_outs, cfg->line_out_pins); + if (err < 0) + return err; + if (cfg->line_out_type != AUTO_PIN_HP_OUT) { + err = add_fake_paths(codec, nid, cfg->hp_outs, cfg->hp_pins); + if (err < 0) + return err; + } + if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) { + err = add_fake_paths(codec, nid, cfg->speaker_outs, + cfg->speaker_pins); + if (err < 0) + return err; + } + return 0; +} + +/* power up/down beep widget and its output paths */ +static void beep_power_hook(struct hda_beep *beep, bool on) +{ + set_path_power(beep->codec, beep->nid, -1, on); +} + /* * Jack detections for HP auto-mute and mic-switch */ @@ -4837,6 +4900,12 @@ int snd_hda_gen_parse_auto_config(struct hda_codec *codec, err = snd_hda_attach_beep_device(codec, spec->beep_nid); if (err < 0) return err; + if (codec->beep && codec->power_mgmt) { + err = add_fake_beep_paths(codec); + if (err < 0) + return err; + codec->beep->power_hook = beep_power_hook; + } } return 1; -- cgit v1.2.3 From 6b275b140094b701f7ad15272f0597e9d954e5e4 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 20 Mar 2015 18:11:05 +0100 Subject: ALSA: hda - Fix power of pins used for mute LED with vrefs Some pins are used for controlling the LED with the VREF value. This patch changes the power behavior of such pins to be constantly up. A new state, pin_fixed, is introduced to nid_path to indicate that the path contains the fixed pin. This improves also the readability a bit for other static routes, too. Then a helper function snd_hda_gen_fix_pin_power() is called from the codec driver for such fixed pins, and it will create fake paths containing only these pins with pin_fixed=1 flag. Reported-by: David Henningsson Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_generic.c | 37 ++++++++++++++++++++++++++++++------- sound/pci/hda/hda_generic.h | 2 ++ sound/pci/hda/patch_sigmatel.c | 6 ++++++ 3 files changed, 38 insertions(+), 7 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c index d7ca388651da..1cafcbb9d391 100644 --- a/sound/pci/hda/hda_generic.c +++ b/sound/pci/hda/hda_generic.c @@ -665,7 +665,7 @@ static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid, if (!path->stream_enabled) continue; /* ignore unplugged paths except for DAC/ADC */ - if (!path->pin_enabled && + if (!(path->pin_enabled || path->pin_fixed) && type != AC_WID_AUD_OUT && type != AC_WID_AUD_IN) continue; } @@ -1607,7 +1607,7 @@ static int check_aamix_out_path(struct hda_codec *codec, int path_idx) return 0; /* print_nid_path(codec, "output-aamix", path); */ path->active = false; /* unused as default */ - path->pin_enabled = true; /* static route */ + path->pin_fixed = true; /* static route */ return snd_hda_get_path_idx(codec, path); } @@ -3044,7 +3044,7 @@ static int new_analog_input(struct hda_codec *codec, int input_idx, if (path) { print_nid_path(codec, "loopback-merge", path); path->active = true; - path->pin_enabled = true; /* static route */ + path->pin_fixed = true; /* static route */ path->stream_enabled = true; /* no DAC/ADC involved */ spec->loopback_merge_path = snd_hda_get_path_idx(codec, path); @@ -3847,7 +3847,7 @@ static void parse_digital(struct hda_codec *codec) continue; print_nid_path(codec, "digout", path); path->active = true; - path->pin_enabled = true; /* no jack detection */ + path->pin_fixed = true; /* no jack detection */ spec->digout_paths[i] = snd_hda_get_path_idx(codec, path); set_pin_target(codec, pin, PIN_OUT, false); if (!nums) { @@ -3875,7 +3875,7 @@ static void parse_digital(struct hda_codec *codec) if (path) { print_nid_path(codec, "digin", path); path->active = true; - path->pin_enabled = true; /* no jack */ + path->pin_fixed = true; /* no jack */ spec->dig_in_nid = dig_nid; spec->digin_path = snd_hda_get_path_idx(codec, path); set_pin_target(codec, pin, PIN_IN, false); @@ -3959,8 +3959,8 @@ static hda_nid_t set_path_power(struct hda_codec *codec, hda_nid_t nid, path->pin_enabled = pin_state; if (stream_state >= 0) path->stream_enabled = stream_state; - if (path->pin_enabled != pin_old || - path->stream_enabled != stream_old) { + if ((!path->pin_fixed && path->pin_enabled != pin_old) + || path->stream_enabled != stream_old) { last = path_power_update(codec, path, true); if (last) changed = last; @@ -4136,6 +4136,29 @@ static void beep_power_hook(struct hda_beep *beep, bool on) set_path_power(beep->codec, beep->nid, -1, on); } +/** + * snd_hda_gen_fix_pin_power - Fix the power of the given pin widget to D0 + * @codec: the HDA codec + * @pin: NID of pin to fix + */ +int snd_hda_gen_fix_pin_power(struct hda_codec *codec, hda_nid_t pin) +{ + struct hda_gen_spec *spec = codec->spec; + struct nid_path *path; + + path = snd_array_new(&spec->paths); + if (!path) + return -ENOMEM; + memset(path, 0, sizeof(*path)); + path->depth = 1; + path->path[0] = pin; + path->active = true; + path->pin_fixed = true; + path->stream_enabled = true; + return 0; +} +EXPORT_SYMBOL_GPL(snd_hda_gen_fix_pin_power); + /* * Jack detections for HP auto-mute and mic-switch */ diff --git a/sound/pci/hda/hda_generic.h b/sound/pci/hda/hda_generic.h index 54659b51fe16..56e4139b9032 100644 --- a/sound/pci/hda/hda_generic.h +++ b/sound/pci/hda/hda_generic.h @@ -48,6 +48,7 @@ struct nid_path { unsigned int ctls[NID_PATH_NUM_CTLS]; /* NID_PATH_XXX_CTL */ bool active:1; /* activated by driver */ bool pin_enabled:1; /* pins are enabled */ + bool pin_fixed:1; /* path with fixed pin */ bool stream_enabled:1; /* stream is active */ }; @@ -343,5 +344,6 @@ unsigned int snd_hda_gen_path_power_filter(struct hda_codec *codec, hda_nid_t nid, unsigned int power_state); void snd_hda_gen_stream_pm(struct hda_codec *codec, hda_nid_t nid, bool on); +int snd_hda_gen_fix_pin_power(struct hda_codec *codec, hda_nid_t pin); #endif /* __SOUND_HDA_GENERIC_H */ diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c index 86b944a6b0ed..7e531d5cde51 100644 --- a/sound/pci/hda/patch_sigmatel.c +++ b/sound/pci/hda/patch_sigmatel.c @@ -4225,6 +4225,12 @@ static int stac_parse_auto_config(struct hda_codec *codec) if (err < 0) return err; + if (spec->vref_mute_led_nid) { + err = snd_hda_gen_fix_pin_power(codec, spec->vref_mute_led_nid); + if (err < 0) + return err; + } + /* setup analog beep controls */ if (spec->anabeep_nid > 0) { err = stac_auto_create_beep_ctls(codec, -- cgit v1.2.3 From 967b1307b69b8ada8b331e01046ad1ef83742e99 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 20 Mar 2015 18:21:03 +0100 Subject: ALSA: hda - Rename power_mgmt flag with power_save_node David suggested that the name "power_mgmt" is too ambiguous. Rename the flag with a bit clearer one "power_save_node". Also, add the corresponding description to HD-Audio.txt, too. Reported-by: David Henningsson Signed-off-by: Takashi Iwai --- Documentation/sound/alsa/HD-Audio.txt | 6 +++++- sound/pci/hda/hda_codec.h | 2 +- sound/pci/hda/hda_generic.c | 30 +++++++++++++++--------------- sound/pci/hda/patch_sigmatel.c | 8 ++++---- sound/pci/hda/patch_via.c | 12 ++++++------ 5 files changed, 31 insertions(+), 27 deletions(-) (limited to 'sound/pci') diff --git a/Documentation/sound/alsa/HD-Audio.txt b/Documentation/sound/alsa/HD-Audio.txt index 42a0a39b77e6..e7193aac669c 100644 --- a/Documentation/sound/alsa/HD-Audio.txt +++ b/Documentation/sound/alsa/HD-Audio.txt @@ -466,7 +466,11 @@ The generic parser supports the following hints: - add_jack_modes (bool): add "xxx Jack Mode" enum controls to each I/O jack for allowing to change the headphone amp and mic bias VREF capabilities -- power_down_unused (bool): power down the unused widgets +- power_save_node (bool): advanced power management for each widget, + controlling the power sate (D0/D3) of each widget node depending on + the actual pin and stream states +- power_down_unused (bool): power down the unused widgets, a subset of + power_save_node, and will be dropped in future - add_hp_mic (bool): add the headphone to capture source if possible - hp_mic_detect (bool): enable/disable the hp/mic shared input for a single built-in mic case; default true diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index 148e84ce61cf..ccf355d4a8fa 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h @@ -371,7 +371,7 @@ struct hda_codec { unsigned int cached_write:1; /* write only to caches */ unsigned int dp_mst:1; /* support DP1.2 Multi-stream transport */ unsigned int dump_coef:1; /* dump processing coefs in codec proc file */ - unsigned int power_mgmt:1; /* advanced PM for each widget */ + unsigned int power_save_node:1; /* advanced PM for each widget */ #ifdef CONFIG_PM unsigned int d3_stop_clk:1; /* support D3 operation without BCLK */ atomic_t in_pm; /* suspend/resume being performed */ diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c index 1cafcbb9d391..0ef2459cd05f 100644 --- a/sound/pci/hda/hda_generic.c +++ b/sound/pci/hda/hda_generic.c @@ -140,9 +140,9 @@ static void parse_user_hints(struct hda_codec *codec) val = snd_hda_get_bool_hint(codec, "single_adc_amp"); if (val >= 0) codec->single_adc_amp = !!val; - val = snd_hda_get_bool_hint(codec, "power_mgmt"); + val = snd_hda_get_bool_hint(codec, "power_save_node"); if (val >= 0) - codec->power_mgmt = !!val; + codec->power_save_node = !!val; val = snd_hda_get_bool_hint(codec, "auto_mute"); if (val >= 0) @@ -661,7 +661,7 @@ static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid, struct nid_path *path = snd_array_elem(&spec->paths, n); if (!path->active) continue; - if (codec->power_mgmt) { + if (codec->power_save_node) { if (!path->stream_enabled) continue; /* ignore unplugged paths except for DAC/ADC */ @@ -879,8 +879,8 @@ void snd_hda_activate_path(struct hda_codec *codec, struct nid_path *path, path->active = false; /* make sure the widget is powered up */ - if (enable && (spec->power_down_unused || codec->power_mgmt)) - path_power_update(codec, path, codec->power_mgmt); + if (enable && (spec->power_down_unused || codec->power_save_node)) + path_power_update(codec, path, codec->power_save_node); for (i = path->depth - 1; i >= 0; i--) { hda_nid_t nid = path->path[i]; @@ -905,7 +905,7 @@ static void path_power_down_sync(struct hda_codec *codec, struct nid_path *path) { struct hda_gen_spec *spec = codec->spec; - if (!(spec->power_down_unused || codec->power_mgmt) || path->active) + if (!(spec->power_down_unused || codec->power_save_node) || path->active) return; sync_power_state_change(codec, path_power_update(codec, path, true)); } @@ -3981,7 +3981,7 @@ static hda_nid_t set_pin_power_jack(struct hda_codec *codec, hda_nid_t pin, { bool on; - if (!codec->power_mgmt) + if (!codec->power_save_node) return 0; on = snd_hda_jack_detect_state(codec, pin) != HDA_JACK_NOT_PRESENT; @@ -4038,7 +4038,7 @@ static void add_all_pin_power_ctls(struct hda_codec *codec, bool on) struct auto_pin_cfg *cfg = &spec->autocfg; int i; - if (!codec->power_mgmt) + if (!codec->power_save_node) return; add_pin_power_ctls(codec, cfg->line_outs, cfg->line_out_pins, on); if (cfg->line_out_type != AUTO_PIN_HP_OUT) @@ -4067,7 +4067,7 @@ static void sync_all_pin_power_ctls(struct hda_codec *codec) struct auto_pin_cfg *cfg = &spec->autocfg; int i; - if (!codec->power_mgmt) + if (!codec->power_save_node) return; sync_pin_power_ctls(codec, cfg->line_outs, cfg->line_out_pins); if (cfg->line_out_type != AUTO_PIN_HP_OUT) @@ -4111,7 +4111,7 @@ static int add_fake_beep_paths(struct hda_codec *codec) hda_nid_t nid = spec->beep_nid; int err; - if (!codec->power_mgmt || !nid) + if (!codec->power_save_node || !nid) return 0; err = add_fake_paths(codec, nid, cfg->line_outs, cfg->line_out_pins); if (err < 0) @@ -4233,7 +4233,7 @@ static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins, } set_pin_eapd(codec, nid, !mute); - if (codec->power_mgmt) { + if (codec->power_save_node) { bool on = !mute; if (on) on = snd_hda_jack_detect_state(codec, nid) @@ -4741,11 +4741,11 @@ static void mute_all_mixer_nid(struct hda_codec *codec, hda_nid_t mix) * @nid: audio widget * @on: power on/off flag * - * Set this in patch_ops.stream_pm. Only valid with power_mgmt flag. + * Set this in patch_ops.stream_pm. Only valid with power_save_node flag. */ void snd_hda_gen_stream_pm(struct hda_codec *codec, hda_nid_t nid, bool on) { - if (codec->power_mgmt) + if (codec->power_save_node) set_path_power(codec, nid, -1, on); } EXPORT_SYMBOL_GPL(snd_hda_gen_stream_pm); @@ -4916,14 +4916,14 @@ int snd_hda_gen_parse_auto_config(struct hda_codec *codec, dig_only: parse_digital(codec); - if (spec->power_down_unused || codec->power_mgmt) + if (spec->power_down_unused || codec->power_save_node) codec->power_filter = snd_hda_gen_path_power_filter; if (!spec->no_analog && spec->beep_nid) { err = snd_hda_attach_beep_device(codec, spec->beep_nid); if (err < 0) return err; - if (codec->beep && codec->power_mgmt) { + if (codec->beep && codec->power_save_node) { err = add_fake_beep_paths(codec); if (err < 0) return err; diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c index 7e531d5cde51..5b7c173adcb8 100644 --- a/sound/pci/hda/patch_sigmatel.c +++ b/sound/pci/hda/patch_sigmatel.c @@ -4494,7 +4494,7 @@ static int patch_stac92hd73xx(struct hda_codec *codec) return err; spec = codec->spec; - codec->power_mgmt = 1; + codec->power_save_node = 1; spec->linear_tone_beep = 0; spec->gen.mixer_nid = 0x1d; spec->have_spdif_mux = 1; @@ -4600,7 +4600,7 @@ static int patch_stac92hd83xxx(struct hda_codec *codec) codec->epss = 0; /* longer delay needed for D3 */ spec = codec->spec; - codec->power_mgmt = 1; + codec->power_save_node = 1; spec->linear_tone_beep = 0; spec->gen.own_eapd_ctl = 1; spec->gen.power_down_unused = 1; @@ -4650,7 +4650,7 @@ static int patch_stac92hd95(struct hda_codec *codec) codec->epss = 0; /* longer delay needed for D3 */ spec = codec->spec; - codec->power_mgmt = 1; + codec->power_save_node = 1; spec->linear_tone_beep = 0; spec->gen.own_eapd_ctl = 1; spec->gen.power_down_unused = 1; @@ -4692,7 +4692,7 @@ static int patch_stac92hd71bxx(struct hda_codec *codec) return err; spec = codec->spec; - codec->power_mgmt = 1; + codec->power_save_node = 1; spec->linear_tone_beep = 0; spec->gen.own_eapd_ctl = 1; spec->gen.power_down_unused = 1; diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index d5d1dca4f11b..485663bb9101 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -133,7 +133,7 @@ static struct via_spec *via_new_spec(struct hda_codec *codec) spec->gen.keep_eapd_on = 1; spec->gen.pcm_playback_hook = via_playback_pcm_hook; spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO; - codec->power_mgmt = 1; + codec->power_save_node = 1; spec->gen.power_down_unused = 1; return spec; } @@ -236,7 +236,7 @@ static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); - ucontrol->value.enumerated.item[0] = codec->power_mgmt; + ucontrol->value.enumerated.item[0] = codec->power_save_node; return 0; } @@ -247,9 +247,9 @@ static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol, struct via_spec *spec = codec->spec; bool val = !!ucontrol->value.enumerated.item[0]; - if (val == codec->power_mgmt) + if (val == codec->power_save_node) return 0; - codec->power_mgmt = val; + codec->power_save_node = val; spec->gen.power_down_unused = val; analog_low_current_mode(codec); return 1; @@ -295,7 +295,7 @@ static void __analog_low_current_mode(struct hda_codec *codec, bool force) bool enable; unsigned int verb, parm; - if (!codec->power_mgmt) + if (!codec->power_save_node) enable = false; else enable = is_aa_path_mute(codec) && !spec->gen.active_streams; @@ -517,7 +517,7 @@ static int via_parse_auto_config(struct hda_codec *codec) return err; /* disable widget PM at start for compatibility */ - codec->power_mgmt = 0; + codec->power_save_node = 0; spec->gen.power_down_unused = 0; return 0; } -- cgit v1.2.3 From e3d280fc6d42017b2379503fbda83655a05294fe Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 17 Feb 2015 21:46:37 +0100 Subject: ALSA: hda - Make snd_hda_bus_type public Define the common hd-audio driver and device types to bind over snd_hda_bus_type publicly. This allows to implement other type of device and driver code over hd-audio bus. Now both struct hda_codec and struct hda_codec_driver inherit these new struct hdac_device and struct hdac_driver, respectively. The bus registration is done in subsys_initcall() to assure it before any other driver registrations. Signed-off-by: Takashi Iwai --- include/sound/hdaudio.h | 42 ++++++++++++++++++++++++++++++++++++++++++ sound/Kconfig | 2 ++ sound/Makefile | 2 +- sound/hda/Kconfig | 2 ++ sound/hda/Makefile | 3 +++ sound/hda/hda_bus_type.c | 42 ++++++++++++++++++++++++++++++++++++++++++ sound/pci/hda/Kconfig | 1 + sound/pci/hda/hda_bind.c | 47 ++++++++++++++--------------------------------- sound/pci/hda/hda_codec.c | 1 + sound/pci/hda/hda_codec.h | 11 +++++------ 10 files changed, 113 insertions(+), 40 deletions(-) create mode 100644 include/sound/hdaudio.h create mode 100644 sound/hda/Kconfig create mode 100644 sound/hda/Makefile create mode 100644 sound/hda/hda_bus_type.c (limited to 'sound/pci') diff --git a/include/sound/hdaudio.h b/include/sound/hdaudio.h new file mode 100644 index 000000000000..2381509bee9f --- /dev/null +++ b/include/sound/hdaudio.h @@ -0,0 +1,42 @@ +/* + * HD-audio core stuff + */ + +#ifndef __SOUND_HDAUDIO_H +#define __SOUND_HDAUDIO_H + +#include + +/* + * exported bus type + */ +extern struct bus_type snd_hda_bus_type; + +/* + * HD-audio codec base device + */ +struct hdac_device { + struct device dev; + int type; +}; + +/* device/driver type used for matching */ +enum { + HDA_DEV_CORE, + HDA_DEV_LEGACY, +}; + +#define dev_to_hdac_dev(_dev) container_of(_dev, struct hdac_device, dev) + +/* + * HD-audio codec base driver + */ +struct hdac_driver { + struct device_driver driver; + int type; + int (*match)(struct hdac_device *dev, struct hdac_driver *drv); +}; + +#define drv_to_hdac_driver(_drv) container_of(_drv, struct hdac_driver, driver) + +#endif /* __SOUND_HDAUDIO_H */ 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" source "sound/pci/Kconfig" +source "sound/hda/Kconfig" + source "sound/ppc/Kconfig" source "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 obj-$(CONFIG_SOUND_PRIME) += oss/ obj-$(CONFIG_DMASOUND) += oss/ obj-$(CONFIG_SND) += core/ i2c/ drivers/ isa/ pci/ ppc/ arm/ sh/ synth/ usb/ \ - firewire/ sparc/ spi/ parisc/ pcmcia/ mips/ soc/ atmel/ + firewire/ sparc/ spi/ parisc/ pcmcia/ mips/ soc/ atmel/ hda/ obj-$(CONFIG_SND_AOA) += aoa/ # This one must be compilable even if sound is configured out diff --git a/sound/hda/Kconfig b/sound/hda/Kconfig new file mode 100644 index 000000000000..4f428ccf64ad --- /dev/null +++ b/sound/hda/Kconfig @@ -0,0 +1,2 @@ +config SND_HDA_CORE + tristate diff --git a/sound/hda/Makefile b/sound/hda/Makefile new file mode 100644 index 000000000000..59c8d1feb5aa --- /dev/null +++ b/sound/hda/Makefile @@ -0,0 +1,3 @@ +snd-hda-core-objs := hda_bus_type.o + +obj-$(CONFIG_SND_HDA_CORE) += snd-hda-core.o 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 @@ +/* + * HD-audio bus + */ +#include +#include +#include +#include +#include + +MODULE_DESCRIPTION("HD-audio bus"); +MODULE_LICENSE("GPL"); + +static int hda_bus_match(struct device *dev, struct device_driver *drv) +{ + struct hdac_device *hdev = dev_to_hdac_dev(dev); + struct hdac_driver *hdrv = drv_to_hdac_driver(drv); + + if (hdev->type != hdrv->type) + return 0; + if (hdrv->match) + return hdrv->match(hdev, hdrv); + return 1; +} + +struct bus_type snd_hda_bus_type = { + .name = "hdaudio", + .match = hda_bus_match, +}; +EXPORT_SYMBOL_GPL(snd_hda_bus_type); + +static int __init hda_bus_init(void) +{ + return bus_register(&snd_hda_bus_type); +} + +static void __exit hda_bus_exit(void) +{ + bus_unregister(&snd_hda_bus_type); +} + +subsys_initcall(hda_bus_init); +module_exit(hda_bus_exit); 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 select SND_PCM select SND_VMASTER select SND_KCTL_JACK + select SND_HDA_CORE config SND_HDA_INTEL tristate "HD Audio PCI" diff --git a/sound/pci/hda/hda_bind.c b/sound/pci/hda/hda_bind.c index 1f40ce3c1696..e3bd2807b644 100644 --- a/sound/pci/hda/hda_bind.c +++ b/sound/pci/hda/hda_bind.c @@ -47,11 +47,11 @@ static struct hda_vendor_id hda_vendor_ids[] = { /* * find a matching codec preset */ -static int hda_bus_match(struct device *dev, struct device_driver *drv) +static int hda_codec_match(struct hdac_device *dev, struct hdac_driver *drv) { - struct hda_codec *codec = container_of(dev, struct hda_codec, dev); + struct hda_codec *codec = container_of(dev, struct hda_codec, core); struct hda_codec_driver *driver = - container_of(drv, struct hda_codec_driver, driver); + container_of(drv, struct hda_codec_driver, core); const struct hda_codec_preset *preset; /* check probe_id instead of vendor_id if set */ u32 id = codec->probe_id ? codec->probe_id : codec->vendor_id; @@ -154,20 +154,22 @@ static void hda_codec_driver_shutdown(struct device *dev) int __hda_codec_driver_register(struct hda_codec_driver *drv, const char *name, struct module *owner) { - drv->driver.name = name; - drv->driver.owner = owner; - drv->driver.bus = &snd_hda_bus_type; - drv->driver.probe = hda_codec_driver_probe; - drv->driver.remove = hda_codec_driver_remove; - drv->driver.shutdown = hda_codec_driver_shutdown; - drv->driver.pm = &hda_codec_driver_pm; - return driver_register(&drv->driver); + drv->core.driver.name = name; + drv->core.driver.owner = owner; + drv->core.driver.bus = &snd_hda_bus_type; + drv->core.driver.probe = hda_codec_driver_probe; + drv->core.driver.remove = hda_codec_driver_remove; + drv->core.driver.shutdown = hda_codec_driver_shutdown; + drv->core.driver.pm = &hda_codec_driver_pm; + drv->core.type = HDA_DEV_LEGACY; + drv->core.match = hda_codec_match; + return driver_register(&drv->core.driver); } EXPORT_SYMBOL_GPL(__hda_codec_driver_register); void hda_codec_driver_unregister(struct hda_codec_driver *drv) { - driver_unregister(&drv->driver); + driver_unregister(&drv->core.driver); } EXPORT_SYMBOL_GPL(hda_codec_driver_unregister); @@ -319,24 +321,3 @@ int snd_hda_codec_configure(struct hda_codec *codec) return err; } EXPORT_SYMBOL_GPL(snd_hda_codec_configure); - -/* - * bus registration - */ -struct bus_type snd_hda_bus_type = { - .name = "hdaudio", - .match = hda_bus_match, -}; - -static int __init hda_codec_init(void) -{ - return bus_register(&snd_hda_bus_type); -} - -static void __exit hda_codec_exit(void) -{ - bus_unregister(&snd_hda_bus_type); -} - -module_init(hda_codec_init); -module_exit(hda_codec_exit); diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 7e38d6f7314b..e14f9f562874 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -1294,6 +1294,7 @@ int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card, dev_set_name(dev, "hdaudioC%dD%d", card->number, codec_addr); dev_set_drvdata(dev, codec); /* for sysfs */ device_enable_async_suspend(dev); + codec->core.type = HDA_DEV_LEGACY; codec->bus = bus; codec->card = card; diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index ccf355d4a8fa..31a9e10e5137 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h @@ -26,6 +26,7 @@ #include #include #include +#include #include /* @@ -172,7 +173,7 @@ struct hda_codec_preset { #define HDA_CODEC_ID_GENERIC 0x00000201 struct hda_codec_driver { - struct device_driver driver; + struct hdac_driver core; const struct hda_codec_preset *preset; }; @@ -276,7 +277,7 @@ struct hda_pcm { /* codec information */ struct hda_codec { - struct device dev; + struct hdac_device core; struct hda_bus *bus; struct snd_card *card; unsigned int addr; /* codec addr*/ @@ -409,10 +410,8 @@ struct hda_codec { struct snd_array verbs; }; -#define dev_to_hda_codec(_dev) container_of(_dev, struct hda_codec, dev) -#define hda_codec_dev(_dev) (&(_dev)->dev) - -extern struct bus_type snd_hda_bus_type; +#define dev_to_hda_codec(_dev) container_of(_dev, struct hda_codec, core.dev) +#define hda_codec_dev(_dev) (&(_dev)->core.dev) /* direction */ enum { -- cgit v1.2.3 From d068ebc25e6e1360510ad8023fe7bca3dacd204e Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Mon, 2 Mar 2015 23:22:59 +0100 Subject: ALSA: hda - Move some codes up to hdac_bus struct A few basic codes for communicating over HD-audio bus are moved to struct hdac_bus now. It has only command and get_response ops in addition to the unsolicited event handling. Note that the codec-side tracing support is disabled temporarily during this transition due to the code shuffling. It will be re-enabled later once when all pieces are settled down. Signed-off-by: Takashi Iwai --- include/sound/hdaudio.h | 61 +++++++++++++ sound/hda/Makefile | 2 +- sound/hda/hdac_bus.c | 181 ++++++++++++++++++++++++++++++++++++++ sound/pci/hda/hda_bind.c | 10 +++ sound/pci/hda/hda_codec.c | 191 ++++++++++++++--------------------------- sound/pci/hda/hda_codec.h | 34 +++----- sound/pci/hda/hda_controller.c | 8 +- sound/pci/hda/hda_intel.c | 4 +- sound/pci/hda/hda_sysfs.c | 2 +- sound/pci/hda/patch_conexant.c | 4 +- 10 files changed, 335 insertions(+), 162 deletions(-) create mode 100644 sound/hda/hdac_bus.c (limited to 'sound/pci') diff --git a/include/sound/hdaudio.h b/include/sound/hdaudio.h index 2381509bee9f..848ab6e68099 100644 --- a/include/sound/hdaudio.h +++ b/include/sound/hdaudio.h @@ -6,6 +6,11 @@ #define __SOUND_HDAUDIO_H #include +#include + +struct hdac_bus; +struct hdac_device; +struct hdac_driver; /* * exported bus type @@ -18,6 +23,9 @@ extern struct bus_type snd_hda_bus_type; struct hdac_device { struct device dev; int type; + struct hdac_bus *bus; + unsigned int addr; /* codec address */ + struct list_head list; /* list point for bus codec_list */ }; /* device/driver type used for matching */ @@ -35,8 +43,61 @@ struct hdac_driver { struct device_driver driver; int type; int (*match)(struct hdac_device *dev, struct hdac_driver *drv); + void (*unsol_event)(struct hdac_device *dev, unsigned int event); }; #define drv_to_hdac_driver(_drv) container_of(_drv, struct hdac_driver, driver) +/* + * HD-audio bus base driver + */ +struct hdac_bus_ops { + /* send a single command */ + int (*command)(struct hdac_bus *bus, unsigned int cmd); + /* get a response from the last command */ + int (*get_response)(struct hdac_bus *bus, unsigned int addr, + unsigned int *res); +}; + +#define HDA_UNSOL_QUEUE_SIZE 64 + +struct hdac_bus { + struct device *dev; + const struct hdac_bus_ops *ops; + + /* codec linked list */ + struct list_head codec_list; + unsigned int num_codecs; + + /* link caddr -> codec */ + struct hdac_device *caddr_tbl[HDA_MAX_CODEC_ADDRESS + 1]; + + /* unsolicited event queue */ + u32 unsol_queue[HDA_UNSOL_QUEUE_SIZE * 2]; /* ring buffer */ + unsigned int unsol_rp, unsol_wp; + struct work_struct unsol_work; + + /* bit flags of powered codecs */ + unsigned long codec_powered; + + /* flags */ + bool sync_write:1; /* sync after verb write */ + + /* locks */ + struct mutex cmd_mutex; +}; + +int snd_hdac_bus_init(struct hdac_bus *bus, struct device *dev, + const struct hdac_bus_ops *ops); +void snd_hdac_bus_exit(struct hdac_bus *bus); +int snd_hdac_bus_exec_verb(struct hdac_bus *bus, unsigned int addr, + unsigned int cmd, unsigned int *res); +int snd_hdac_bus_exec_verb_unlocked(struct hdac_bus *bus, unsigned int addr, + unsigned int cmd, unsigned int *res); +void snd_hdac_bus_queue_event(struct hdac_bus *bus, u32 res, u32 res_ex); + +int snd_hdac_bus_add_device(struct hdac_bus *bus, struct hdac_device *codec); +void snd_hdac_bus_remove_device(struct hdac_bus *bus, + struct hdac_device *codec); + #endif /* __SOUND_HDAUDIO_H */ diff --git a/sound/hda/Makefile b/sound/hda/Makefile index 59c8d1feb5aa..828680b282fa 100644 --- a/sound/hda/Makefile +++ b/sound/hda/Makefile @@ -1,3 +1,3 @@ -snd-hda-core-objs := hda_bus_type.o +snd-hda-core-objs := hda_bus_type.o hdac_bus.o obj-$(CONFIG_SND_HDA_CORE) += snd-hda-core.o diff --git a/sound/hda/hdac_bus.c b/sound/hda/hdac_bus.c new file mode 100644 index 000000000000..364f64c0e4a3 --- /dev/null +++ b/sound/hda/hdac_bus.c @@ -0,0 +1,181 @@ +/* + * HD-audio core bus driver + */ + +#include +#include +#include +#include +#include + +static void process_unsol_events(struct work_struct *work); + +/** + * snd_hdac_bus_init - initialize a HD-audio bas bus + * @bus: the pointer to bus object + * + * Returns 0 if successful, or a negative error code. + */ +int snd_hdac_bus_init(struct hdac_bus *bus, struct device *dev, + const struct hdac_bus_ops *ops) +{ + memset(bus, 0, sizeof(*bus)); + bus->dev = dev; + bus->ops = ops; + INIT_LIST_HEAD(&bus->codec_list); + INIT_WORK(&bus->unsol_work, process_unsol_events); + mutex_init(&bus->cmd_mutex); + return 0; +} +EXPORT_SYMBOL_GPL(snd_hdac_bus_init); + +/** + * snd_hdac_bus_exit - clean up a HD-audio bas bus + * @bus: the pointer to bus object + */ +void snd_hdac_bus_exit(struct hdac_bus *bus) +{ + WARN_ON(!list_empty(&bus->codec_list)); + cancel_work_sync(&bus->unsol_work); +} +EXPORT_SYMBOL_GPL(snd_hdac_bus_exit); + +/** + * snd_hdac_bus_exec_verb - execute a HD-audio verb on the given bus + * @bus: bus object + * @cmd: HD-audio encoded verb + * @res: pointer to store the response, NULL if performing asynchronously + * + * Returns 0 if successful, or a negative error code. + */ +int snd_hdac_bus_exec_verb(struct hdac_bus *bus, unsigned int addr, + unsigned int cmd, unsigned int *res) +{ + int err; + + mutex_lock(&bus->cmd_mutex); + err = snd_hdac_bus_exec_verb_unlocked(bus, addr, cmd, res); + mutex_unlock(&bus->cmd_mutex); + return err; +} +EXPORT_SYMBOL_GPL(snd_hdac_bus_exec_verb); + +/** + * snd_hdac_bus_exec_verb_unlocked - unlocked version + * @bus: bus object + * @cmd: HD-audio encoded verb + * @res: pointer to store the response, NULL if performing asynchronously + * + * Returns 0 if successful, or a negative error code. + */ +int snd_hdac_bus_exec_verb_unlocked(struct hdac_bus *bus, unsigned int addr, + unsigned int cmd, unsigned int *res) +{ + unsigned int tmp; + int err; + + if (cmd == ~0) + return -EINVAL; + + if (res) + *res = -1; + else if (bus->sync_write) + res = &tmp; + for (;;) { + err = bus->ops->command(bus, cmd); + if (err != -EAGAIN) + break; + /* process pending verbs */ + err = bus->ops->get_response(bus, addr, &tmp); + if (err) + break; + } + if (!err && res) + err = bus->ops->get_response(bus, addr, res); + return err; +} +EXPORT_SYMBOL_GPL(snd_hdac_bus_exec_verb_unlocked); + +/** + * snd_hdac_bus_queue_event - add an unsolicited event to queue + * @bus: the BUS + * @res: unsolicited event (lower 32bit of RIRB entry) + * @res_ex: codec addr and flags (upper 32bit or RIRB entry) + * + * Adds the given event to the queue. The events are processed in + * the workqueue asynchronously. Call this function in the interrupt + * hanlder when RIRB receives an unsolicited event. + */ +void snd_hdac_bus_queue_event(struct hdac_bus *bus, u32 res, u32 res_ex) +{ + unsigned int wp; + + if (!bus) + return; + + wp = (bus->unsol_wp + 1) % HDA_UNSOL_QUEUE_SIZE; + bus->unsol_wp = wp; + + wp <<= 1; + bus->unsol_queue[wp] = res; + bus->unsol_queue[wp + 1] = res_ex; + + schedule_work(&bus->unsol_work); +} +EXPORT_SYMBOL_GPL(snd_hdac_bus_queue_event); + +/* + * process queued unsolicited events + */ +static void process_unsol_events(struct work_struct *work) +{ + struct hdac_bus *bus = container_of(work, struct hdac_bus, unsol_work); + struct hdac_device *codec; + struct hdac_driver *drv; + unsigned int rp, caddr, res; + + while (bus->unsol_rp != bus->unsol_wp) { + rp = (bus->unsol_rp + 1) % HDA_UNSOL_QUEUE_SIZE; + bus->unsol_rp = rp; + rp <<= 1; + res = bus->unsol_queue[rp]; + caddr = bus->unsol_queue[rp + 1]; + if (!(caddr & (1 << 4))) /* no unsolicited event? */ + continue; + codec = bus->caddr_tbl[caddr & 0x0f]; + if (!codec || !codec->dev.driver) + continue; + drv = drv_to_hdac_driver(codec->dev.driver); + if (drv->unsol_event) + drv->unsol_event(codec, res); + } +} + +int snd_hdac_bus_add_device(struct hdac_bus *bus, struct hdac_device *codec) +{ + if (bus->caddr_tbl[codec->addr]) { + dev_err(bus->dev, "address 0x%x is already occupied\n", + codec->addr); + return -EBUSY; + } + + list_add_tail(&codec->list, &bus->codec_list); + bus->caddr_tbl[codec->addr] = codec; + set_bit(codec->addr, &bus->codec_powered); + bus->num_codecs++; + return 0; +} +EXPORT_SYMBOL_GPL(snd_hdac_bus_add_device); + +void snd_hdac_bus_remove_device(struct hdac_bus *bus, + struct hdac_device *codec) +{ + WARN_ON(bus != codec->bus); + if (list_empty(&codec->list)) + return; + list_del_init(&codec->list); + bus->caddr_tbl[codec->addr] = NULL; + clear_bit(codec->addr, &bus->codec_powered); + bus->num_codecs--; +} +EXPORT_SYMBOL_GPL(snd_hdac_bus_remove_device); diff --git a/sound/pci/hda/hda_bind.c b/sound/pci/hda/hda_bind.c index e3bd2807b644..0b9ea70c546b 100644 --- a/sound/pci/hda/hda_bind.c +++ b/sound/pci/hda/hda_bind.c @@ -74,6 +74,15 @@ static int hda_codec_match(struct hdac_device *dev, struct hdac_driver *drv) return 0; } +/* process an unsolicited event */ +static void hda_codec_unsol_event(struct hdac_device *dev, unsigned int ev) +{ + struct hda_codec *codec = container_of(dev, struct hda_codec, core); + + if (codec->patch_ops.unsol_event) + codec->patch_ops.unsol_event(codec, ev); +} + /* reset the codec name from the preset */ static int codec_refresh_name(struct hda_codec *codec, const char *name) { @@ -163,6 +172,7 @@ int __hda_codec_driver_register(struct hda_codec_driver *drv, const char *name, drv->core.driver.pm = &hda_codec_driver_pm; drv->core.type = HDA_DEV_LEGACY; drv->core.match = hda_codec_match; + drv->core.unsol_event = hda_codec_unsol_event; return driver_register(&drv->core.driver); } EXPORT_SYMBOL_GPL(__hda_codec_driver_register); diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index e14f9f562874..f96bff37c787 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -39,9 +39,6 @@ #include "hda_jack.h" #include -#define CREATE_TRACE_POINTS -#include "hda_trace.h" - #ifdef CONFIG_PM #define codec_in_pm(codec) atomic_read(&(codec)->in_pm) #define hda_codec_is_power_on(codec) \ @@ -128,16 +125,17 @@ static inline unsigned int make_codec_cmd(struct hda_codec *codec, hda_nid_t nid, int flags, unsigned int verb, unsigned int parm) { + unsigned int addr = codec->core.addr; u32 val; - if ((codec->addr & ~0xf) || (nid & ~0x7f) || + if ((addr & ~0xf) || (nid & ~0x7f) || (verb & ~0xfff) || (parm & ~0xffff)) { codec_err(codec, "hda-codec: out of range cmd %x:%x:%x:%x\n", - codec->addr, nid, verb, parm); + addr, nid, verb, parm); return ~0; } - val = (u32)codec->addr << 28; + val = (u32)addr << 28; val |= (u32)nid << 20; val |= verb << 8; val |= parm; @@ -156,33 +154,20 @@ static int codec_exec_verb(struct hda_codec *codec, unsigned int cmd, if (cmd == ~0) return -1; - if (res) - *res = -1; again: snd_hda_power_up(codec); - mutex_lock(&bus->cmd_mutex); + mutex_lock(&bus->core.cmd_mutex); if (flags & HDA_RW_NO_RESPONSE_FALLBACK) bus->no_response_fallback = 1; - for (;;) { - trace_hda_send_cmd(codec, cmd); - err = bus->ops.command(bus, cmd); - if (err != -EAGAIN) - break; - /* process pending verbs */ - bus->ops.get_response(bus, codec->addr); - } - if (!err && res) { - *res = bus->ops.get_response(bus, codec->addr); - trace_hda_get_response(codec, *res); - } + err = snd_hdac_bus_exec_verb_unlocked(&bus->core, codec->core.addr, + cmd, res); bus->no_response_fallback = 0; - mutex_unlock(&bus->cmd_mutex); + mutex_unlock(&bus->core.cmd_mutex); snd_hda_power_down(codec); - if (!codec_in_pm(codec) && res && *res == -1 && bus->rirb_error) { + if (!codec_in_pm(codec) && res && err < 0 && bus->rirb_error) { if (bus->response_reset) { codec_dbg(codec, "resetting BUS due to fatal communication error\n"); - trace_hda_bus_reset(bus); bus->ops.bus_reset(bus); } goto again; @@ -233,9 +218,7 @@ int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int flags, unsigned int verb, unsigned int parm) { unsigned int cmd = make_codec_cmd(codec, nid, flags, verb, parm); - unsigned int res; - return codec_exec_verb(codec, cmd, flags, - codec->bus->sync_write ? &res : NULL); + return codec_exec_verb(codec, cmd, flags, NULL); } EXPORT_SYMBOL_GPL(snd_hda_codec_write); @@ -664,65 +647,6 @@ int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid, return devices; } -/** - * snd_hda_queue_unsol_event - add an unsolicited event to queue - * @bus: the BUS - * @res: unsolicited event (lower 32bit of RIRB entry) - * @res_ex: codec addr and flags (upper 32bit or RIRB entry) - * - * Adds the given event to the queue. The events are processed in - * the workqueue asynchronously. Call this function in the interrupt - * hanlder when RIRB receives an unsolicited event. - * - * Returns 0 if successful, or a negative error code. - */ -int snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex) -{ - struct hda_bus_unsolicited *unsol; - unsigned int wp; - - if (!bus) - return 0; - - trace_hda_unsol_event(bus, res, res_ex); - unsol = &bus->unsol; - wp = (unsol->wp + 1) % HDA_UNSOL_QUEUE_SIZE; - unsol->wp = wp; - - wp <<= 1; - unsol->queue[wp] = res; - unsol->queue[wp + 1] = res_ex; - - schedule_work(&unsol->work); - - return 0; -} -EXPORT_SYMBOL_GPL(snd_hda_queue_unsol_event); - -/* - * process queued unsolicited events - */ -static void process_unsol_events(struct work_struct *work) -{ - struct hda_bus *bus = container_of(work, struct hda_bus, unsol.work); - struct hda_bus_unsolicited *unsol = &bus->unsol; - struct hda_codec *codec; - unsigned int rp, caddr, res; - - while (unsol->rp != unsol->wp) { - rp = (unsol->rp + 1) % HDA_UNSOL_QUEUE_SIZE; - unsol->rp = rp; - rp <<= 1; - res = unsol->queue[rp]; - caddr = unsol->queue[rp + 1]; - if (!(caddr & (1 << 4))) /* no unsolicited event? */ - continue; - codec = bus->caddr_tbl[caddr & 0x0f]; - if (codec && codec->patch_ops.unsol_event) - codec->patch_ops.unsol_event(codec, res); - } -} - /* * destructor */ @@ -730,11 +654,9 @@ static void snd_hda_bus_free(struct hda_bus *bus) { if (!bus) return; - - WARN_ON(!list_empty(&bus->codec_list)); - cancel_work_sync(&bus->unsol.work); if (bus->ops.private_free) bus->ops.private_free(bus); + snd_hdac_bus_exit(&bus->core); kfree(bus); } @@ -751,6 +673,26 @@ static int snd_hda_bus_dev_disconnect(struct snd_device *device) return 0; } +/* hdac_bus_ops translations */ +static int _hda_bus_command(struct hdac_bus *_bus, unsigned int cmd) +{ + struct hda_bus *bus = container_of(_bus, struct hda_bus, core); + return bus->ops.command(bus, cmd); +} + +static int _hda_bus_get_response(struct hdac_bus *_bus, unsigned int addr, + unsigned int *res) +{ + struct hda_bus *bus = container_of(_bus, struct hda_bus, core); + *res = bus->ops.get_response(bus, addr); + return bus->rirb_error ? -EIO : 0; +} + +static const struct hdac_bus_ops bus_ops = { + .command = _hda_bus_command, + .get_response = _hda_bus_get_response, +}; + /** * snd_hda_bus_new - create a HDA bus * @card: the card entry @@ -775,11 +717,14 @@ int snd_hda_bus_new(struct snd_card *card, if (!bus) return -ENOMEM; + err = snd_hdac_bus_init(&bus->core, card->dev, &bus_ops); + if (err < 0) { + kfree(bus); + return err; + } + bus->card = card; - mutex_init(&bus->cmd_mutex); mutex_init(&bus->prepare_mutex); - INIT_LIST_HEAD(&bus->codec_list); - INIT_WORK(&bus->unsol.work, process_unsol_events); err = snd_device_new(card, SNDRV_DEV_BUS, bus, &dev_ops); if (err < 0) { @@ -1233,9 +1178,7 @@ static void snd_hda_codec_dev_release(struct device *dev) struct hda_codec *codec = dev_to_hda_codec(dev); free_init_pincfgs(codec); - list_del(&codec->list); - codec->bus->caddr_tbl[codec->addr] = NULL; - clear_bit(codec->addr, &codec->bus->codec_powered); + snd_hdac_bus_remove_device(&codec->bus->core, &codec->core); snd_hda_sysfs_clear(codec); free_hda_cache(&codec->amp_cache); free_hda_cache(&codec->cmd_cache); @@ -1243,7 +1186,6 @@ static void snd_hda_codec_dev_release(struct device *dev) kfree(codec->chip_name); kfree(codec->modelname); kfree(codec->wcaps); - codec->bus->num_codecs--; kfree(codec); } @@ -1274,27 +1216,23 @@ int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card, if (snd_BUG_ON(codec_addr > HDA_MAX_CODEC_ADDRESS)) return -EINVAL; - if (bus->caddr_tbl[codec_addr]) { - dev_err(card->dev, - "address 0x%x is already occupied\n", - codec_addr); - return -EBUSY; - } - codec = kzalloc(sizeof(*codec), GFP_KERNEL); if (!codec) return -ENOMEM; + codec->core.bus = &bus->core; + codec->core.addr = codec_addr; + codec->core.type = HDA_DEV_LEGACY; + dev = hda_codec_dev(codec); device_initialize(dev); - dev->parent = card->dev; + dev->parent = bus->core.dev; dev->bus = &snd_hda_bus_type; dev->release = snd_hda_codec_dev_release; dev->groups = snd_hda_dev_attr_groups; dev_set_name(dev, "hdaudioC%dD%d", card->number, codec_addr); dev_set_drvdata(dev, codec); /* for sysfs */ device_enable_async_suspend(dev); - codec->core.type = HDA_DEV_LEGACY; codec->bus = bus; codec->card = card; @@ -1323,7 +1261,7 @@ int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card, /* snd_hda_codec_new() marks the codec as power-up, and leave it as is. * it's powered down later in snd_hda_codec_dev_register(). */ - set_bit(codec->addr, &bus->codec_powered); + set_bit(codec->core.addr, &bus->core.codec_powered); pm_runtime_set_active(hda_codec_dev(codec)); pm_runtime_get_noresume(hda_codec_dev(codec)); codec->power_jiffies = jiffies; @@ -1339,10 +1277,9 @@ int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card, } } - list_add_tail(&codec->list, &bus->codec_list); - bus->num_codecs++; - - bus->caddr_tbl[codec_addr] = codec; + err = snd_hdac_bus_add_device(&bus->core, &codec->core); + if (err < 0) + goto error; codec->vendor_id = snd_hda_param_read(codec, AC_NODE_ROOT, AC_PAR_VENDOR_ID); @@ -1516,7 +1453,7 @@ void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid, /* make other inactive cvts with the same stream-tag dirty */ type = get_wcaps_type(get_wcaps(codec, nid)); - list_for_each_entry(c, &codec->bus->codec_list, list) { + list_for_each_codec(c, codec->bus) { for (i = 0; i < c->cvt_setups.used; i++) { p = snd_array_elem(&c->cvt_setups, i); if (!p->active && p->stream_tag == stream_tag && @@ -1583,7 +1520,7 @@ static void purify_inactive_streams(struct hda_codec *codec) struct hda_codec *c; int i; - list_for_each_entry(c, &codec->bus->codec_list, list) { + list_for_each_codec(c, codec->bus) { for (i = 0; i < c->cvt_setups.used; i++) { struct hda_cvt_setup *p; p = snd_array_elem(&c->cvt_setups, i); @@ -2436,7 +2373,7 @@ int snd_hda_lock_devices(struct hda_bus *bus) if (!list_empty(&card->ctl_files)) goto err_clear; - list_for_each_entry(codec, &bus->codec_list, list) { + list_for_each_codec(codec, bus) { struct hda_pcm *cpcm; list_for_each_entry(cpcm, &codec->pcm_list_head, list) { if (!cpcm->pcm) @@ -3607,13 +3544,13 @@ int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid, verb = verb | (parm >> 8); parm &= 0xff; key = build_cmd_cache_key(nid, verb); - mutex_lock(&codec->bus->cmd_mutex); + mutex_lock(&codec->bus->core.cmd_mutex); c = get_alloc_hash(&codec->cmd_cache, key); if (c) { c->val = parm; c->dirty = cache_only; } - mutex_unlock(&codec->bus->cmd_mutex); + mutex_unlock(&codec->bus->core.cmd_mutex); return 0; } EXPORT_SYMBOL_GPL(snd_hda_codec_write_cache); @@ -3642,13 +3579,13 @@ int snd_hda_codec_update_cache(struct hda_codec *codec, hda_nid_t nid, verb = verb | (parm >> 8); parm &= 0xff; key = build_cmd_cache_key(nid, verb); - mutex_lock(&codec->bus->cmd_mutex); + mutex_lock(&codec->bus->core.cmd_mutex); c = get_hash(&codec->cmd_cache, key); if (c && c->val == parm) { - mutex_unlock(&codec->bus->cmd_mutex); + mutex_unlock(&codec->bus->core.cmd_mutex); return 0; } - mutex_unlock(&codec->bus->cmd_mutex); + mutex_unlock(&codec->bus->core.cmd_mutex); return snd_hda_codec_write_cache(codec, nid, flags, verb, parm); } EXPORT_SYMBOL_GPL(snd_hda_codec_update_cache); @@ -3927,7 +3864,6 @@ static unsigned int hda_call_codec_suspend(struct hda_codec *codec) codec->patch_ops.suspend(codec); hda_cleanup_all_streams(codec); state = hda_set_power_state(codec, AC_PWRST_D3); - trace_hda_power_down(codec); update_power_acct(codec, true); atomic_dec(&codec->in_pm); return state; @@ -3956,7 +3892,6 @@ static void hda_call_codec_resume(struct hda_codec *codec) { atomic_inc(&codec->in_pm); - trace_hda_power_up(codec); hda_mark_cmd_cache_dirty(codec); codec->power_jiffies = jiffies; @@ -3992,7 +3927,7 @@ static int hda_codec_runtime_suspend(struct device *dev) snd_pcm_suspend_all(pcm->pcm); state = hda_call_codec_suspend(codec); if (codec->d3_stop_clk && codec->epss && (state & AC_PWRST_CLK_STOP_OK)) - clear_bit(codec->addr, &codec->bus->codec_powered); + clear_bit(codec->core.addr, &codec->bus->core.codec_powered); return 0; } @@ -4000,7 +3935,7 @@ static int hda_codec_runtime_resume(struct device *dev) { struct hda_codec *codec = dev_to_hda_codec(dev); - set_bit(codec->addr, &codec->bus->codec_powered); + set_bit(codec->core.addr, &codec->bus->core.codec_powered); hda_call_codec_resume(codec); pm_runtime_mark_last_busy(dev); return 0; @@ -4582,7 +4517,7 @@ int snd_hda_codec_parse_pcms(struct hda_codec *codec) err = codec->patch_ops.build_pcms(codec); if (err < 0) { codec_err(codec, "cannot build PCMs for #%d (error %d)\n", - codec->addr, err); + codec->core.addr, err); return err; } @@ -4638,7 +4573,7 @@ int snd_hda_codec_build_pcms(struct hda_codec *codec) if (err < 0) { codec_err(codec, "cannot attach PCM stream %d for codec #%d\n", - dev, codec->addr); + dev, codec->core.addr); continue; /* no fatal error */ } } @@ -4681,8 +4616,8 @@ int snd_hda_add_new_ctls(struct hda_codec *codec, * the codec addr; if it still fails (or it's the * primary codec), then try another control index */ - if (!addr && codec->addr) - addr = codec->addr; + if (!addr && codec->core.addr) + addr = codec->core.addr; else if (!idx && !knew->index) { idx = find_empty_mixer_ctl_idx(codec, knew->name, 0); @@ -4757,7 +4692,7 @@ void snd_hda_set_power_save(struct hda_bus *bus, int delay) { struct hda_codec *c; - list_for_each_entry(c, &bus->codec_list, list) + list_for_each_codec(c, bus) codec_set_power_save(c, delay); } EXPORT_SYMBOL_GPL(snd_hda_set_power_save); @@ -5344,7 +5279,7 @@ void snd_hda_bus_reset(struct hda_bus *bus) { struct hda_codec *codec; - list_for_each_entry(codec, &bus->codec_list, list) { + list_for_each_codec(codec, bus) { /* FIXME: maybe a better way needed for forced reset */ cancel_delayed_work_sync(&codec->jackpoll_work); #ifdef CONFIG_PM diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index 31a9e10e5137..6efcb4ad6935 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h @@ -98,16 +98,6 @@ struct hda_bus_ops { #endif }; -/* unsolicited event handler */ -#define HDA_UNSOL_QUEUE_SIZE 64 -struct hda_bus_unsolicited { - /* ring buffer */ - u32 queue[HDA_UNSOL_QUEUE_SIZE * 2]; - unsigned int rp, wp; - /* workqueue */ - struct work_struct work; -}; - /* * codec bus * @@ -115,6 +105,8 @@ struct hda_bus_unsolicited { * A hda_bus contains several codecs in the list codec_list. */ struct hda_bus { + struct hdac_bus core; + struct snd_card *card; void *private_data; @@ -122,25 +114,14 @@ struct hda_bus { const char *modelname; struct hda_bus_ops ops; - /* codec linked list */ - struct list_head codec_list; - unsigned int num_codecs; - /* link caddr -> codec */ - struct hda_codec *caddr_tbl[HDA_MAX_CODEC_ADDRESS + 1]; - - struct mutex cmd_mutex; struct mutex prepare_mutex; - /* unsolicited event queue */ - struct hda_bus_unsolicited unsol; - /* assigned PCMs */ DECLARE_BITMAP(pcm_dev_bits, SNDRV_PCM_DEVICES); /* misc op flags */ unsigned int needs_damn_long_delay :1; unsigned int allow_bus_reset:1; /* allow bus reset at fatal error */ - unsigned int sync_write:1; /* sync after verb write */ /* status for codec/controller */ unsigned int shutdown :1; /* being unloaded */ unsigned int rirb_error:1; /* error in codec communication */ @@ -149,7 +130,6 @@ struct hda_bus { unsigned int no_response_fallback:1; /* don't fallback at RIRB error */ int primary_dig_out_type; /* primary digital out PCM type */ - unsigned long codec_powered; /* bit flags of powered codecs */ }; /* @@ -281,7 +261,6 @@ struct hda_codec { struct hda_bus *bus; struct snd_card *card; unsigned int addr; /* codec addr*/ - struct list_head list; /* list point */ hda_nid_t afg; /* AFG node id */ hda_nid_t mfg; /* MFG node id */ @@ -413,6 +392,9 @@ struct hda_codec { #define dev_to_hda_codec(_dev) container_of(_dev, struct hda_codec, core.dev) #define hda_codec_dev(_dev) (&(_dev)->core.dev) +#define list_for_each_codec(c, bus) \ + list_for_each_entry(c, &(bus)->core.codec_list, core.list) + /* direction */ enum { HDA_INPUT, HDA_OUTPUT @@ -473,7 +455,11 @@ void snd_hda_sequence_write(struct hda_codec *codec, const struct hda_verb *seq); /* unsolicited event */ -int snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex); +static inline void +snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex) +{ + snd_hdac_bus_queue_event(&bus->core, res, res_ex); +} /* cached write */ int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid, diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c index 4fd0b2ef26e9..26ce990592a0 100644 --- a/sound/pci/hda/hda_controller.c +++ b/sound/pci/hda/hda_controller.c @@ -1764,12 +1764,12 @@ static int probe_codec(struct azx *chip, int addr) (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID; unsigned int res; - mutex_lock(&chip->bus->cmd_mutex); + mutex_lock(&chip->bus->core.cmd_mutex); chip->probing = 1; azx_send_cmd(chip->bus, cmd); res = azx_get_response(chip->bus, addr); chip->probing = 0; - mutex_unlock(&chip->bus->cmd_mutex); + mutex_unlock(&chip->bus->core.cmd_mutex); if (res == -1) return -EIO; dev_dbg(chip->card->dev, "codec #%d probed OK\n", addr); @@ -1848,7 +1848,7 @@ int azx_bus_create(struct azx *chip, const char *model) */ if (chip->driver_caps & AZX_DCAPS_SYNC_WRITE) { dev_dbg(chip->card->dev, "Enable sync_write for stable communication\n"); - bus->sync_write = 1; + bus->core.sync_write = 1; bus->allow_bus_reset = 1; } @@ -1913,7 +1913,7 @@ EXPORT_SYMBOL_GPL(azx_probe_codecs); int azx_codec_configure(struct azx *chip) { struct hda_codec *codec; - list_for_each_entry(codec, &chip->bus->codec_list, list) { + list_for_each_codec(codec, chip->bus) { snd_hda_codec_configure(codec); } return 0; diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index 060f7a2b1aeb..feebc1dda912 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c @@ -891,7 +891,7 @@ static int azx_runtime_resume(struct device *dev) bus = chip->bus; if (status && bus) { - list_for_each_entry(codec, &bus->codec_list, list) + list_for_each_codec(codec, bus) if (status & (1 << codec->addr)) schedule_delayed_work(&codec->jackpoll_work, codec->jackpoll_interval); @@ -919,7 +919,7 @@ static int azx_runtime_idle(struct device *dev) return 0; if (!power_save_controller || !azx_has_pm_runtime(chip) || - chip->bus->codec_powered) + chip->bus->core.codec_powered) return -EBUSY; return 0; diff --git a/sound/pci/hda/hda_sysfs.c b/sound/pci/hda/hda_sysfs.c index e13c75d67847..3b5ed1108f9f 100644 --- a/sound/pci/hda/hda_sysfs.c +++ b/sound/pci/hda/hda_sysfs.c @@ -552,7 +552,7 @@ static void parse_codec_mode(char *buf, struct hda_bus *bus, *codecp = NULL; if (sscanf(buf, "%i %i %i", &vendorid, &subid, &caddr) == 3) { - list_for_each_entry(codec, &bus->codec_list, list) { + list_for_each_codec(codec, bus) { if ((vendorid <= 0 || codec->vendor_id == vendorid) && (subid <= 0 || codec->subsystem_id == subid) && codec->addr == caddr) { diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c index 5aa466a13e43..142a6cf786da 100644 --- a/sound/pci/hda/patch_conexant.c +++ b/sound/pci/hda/patch_conexant.c @@ -919,10 +919,10 @@ static int patch_conexant_auto(struct hda_codec *codec) * which falls into the single-cmd mode. * Better to make reset, then. */ - if (!codec->bus->sync_write) { + if (!codec->bus->core.sync_write) { codec_info(codec, "Enable sync_write for stable communication\n"); - codec->bus->sync_write = 1; + codec->bus->core.sync_write = 1; codec->bus->allow_bus_reset = 1; } -- cgit v1.2.3 From 7639a06c23c7d4cda34c2546bd7290d8753849ca Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 3 Mar 2015 10:07:24 +0100 Subject: ALSA: hda - Move a part of hda_codec stuff into hdac_device Now some codes and functionalities of hda_codec struct are moved to hdac_device struct. A few basic attributes like the codec address, vendor ID number, FG numbers, etc are moved to hdac_device, and they are accessed like codec->core.addr. The basic verb exec functions are moved, too. Signed-off-by: Takashi Iwai --- include/sound/hdaudio.h | 66 ++++++ sound/hda/Makefile | 2 +- sound/hda/hdac_device.c | 471 ++++++++++++++++++++++++++++++++++++++++ sound/hda/local.h | 19 ++ sound/pci/hda/hda_auto_parser.c | 33 ++- sound/pci/hda/hda_beep.c | 4 +- sound/pci/hda/hda_bind.c | 95 ++------ sound/pci/hda/hda_codec.c | 396 +++++---------------------------- sound/pci/hda/hda_codec.h | 43 +--- sound/pci/hda/hda_generic.c | 25 +-- sound/pci/hda/hda_local.h | 15 +- sound/pci/hda/hda_proc.c | 42 ++-- sound/pci/hda/hda_sysfs.c | 58 ++--- sound/pci/hda/local.h | 39 ++++ sound/pci/hda/patch_analog.c | 2 +- sound/pci/hda/patch_ca0132.c | 6 +- sound/pci/hda/patch_conexant.c | 16 +- sound/pci/hda/patch_hdmi.c | 20 +- sound/pci/hda/patch_realtek.c | 78 +++---- sound/pci/hda/patch_si3054.c | 6 +- sound/pci/hda/patch_sigmatel.c | 84 +++---- sound/pci/hda/patch_via.c | 23 +- sound/pci/hda/thinkpad_helper.c | 2 +- 23 files changed, 880 insertions(+), 665 deletions(-) create mode 100644 sound/hda/hdac_device.c create mode 100644 sound/hda/local.h create mode 100644 sound/pci/hda/local.h (limited to 'sound/pci') diff --git a/include/sound/hdaudio.h b/include/sound/hdaudio.h index 848ab6e68099..b81b4bec6f05 100644 --- a/include/sound/hdaudio.h +++ b/include/sound/hdaudio.h @@ -8,6 +8,9 @@ #include #include +/* codec node id */ +typedef u16 hda_nid_t; + struct hdac_bus; struct hdac_device; struct hdac_driver; @@ -26,6 +29,30 @@ struct hdac_device { struct hdac_bus *bus; unsigned int addr; /* codec address */ struct list_head list; /* list point for bus codec_list */ + + hda_nid_t afg; /* AFG node id */ + hda_nid_t mfg; /* MFG node id */ + + /* ids */ + unsigned int vendor_id; + unsigned int subsystem_id; + unsigned int revision_id; + unsigned int afg_function_id; + unsigned int mfg_function_id; + unsigned int afg_unsol:1; + unsigned int mfg_unsol:1; + + unsigned int power_caps; /* FG power caps */ + + const char *vendor_name; /* codec vendor name */ + const char *chip_name; /* codec chip name */ + + /* widgets */ + unsigned int num_nodes; + hda_nid_t start_nid, end_nid; + + /* misc flags */ + atomic_t in_pm; /* suspend/resume being performed */ }; /* device/driver type used for matching */ @@ -34,8 +61,37 @@ enum { HDA_DEV_LEGACY, }; +/* direction */ +enum { + HDA_INPUT, HDA_OUTPUT +}; + #define dev_to_hdac_dev(_dev) container_of(_dev, struct hdac_device, dev) +int snd_hdac_device_init(struct hdac_device *dev, struct hdac_bus *bus, + const char *name, unsigned int addr); +void snd_hdac_device_exit(struct hdac_device *dev); + +int snd_hdac_refresh_widgets(struct hdac_device *codec); + +unsigned int snd_hdac_make_cmd(struct hdac_device *codec, hda_nid_t nid, + unsigned int verb, unsigned int parm); +int snd_hdac_read(struct hdac_device *codec, hda_nid_t nid, + unsigned int verb, unsigned int parm, unsigned int *res); +int snd_hdac_read_parm(struct hdac_device *codec, hda_nid_t nid, int parm); +int snd_hdac_get_connections(struct hdac_device *codec, hda_nid_t nid, + hda_nid_t *conn_list, int max_conns); +int snd_hdac_get_sub_nodes(struct hdac_device *codec, hda_nid_t nid, + hda_nid_t *start_id); + +#ifdef CONFIG_PM +void snd_hdac_power_up(struct hdac_device *codec); +void snd_hdac_power_down(struct hdac_device *codec); +#else +static inline void snd_hdac_power_up(struct hdac_device *codec) {} +static inline void snd_hdac_power_down(struct hdac_device *codec) {} +#endif + /* * HD-audio codec base driver */ @@ -100,4 +156,14 @@ int snd_hdac_bus_add_device(struct hdac_bus *bus, struct hdac_device *codec); void snd_hdac_bus_remove_device(struct hdac_bus *bus, struct hdac_device *codec); +static inline void snd_hdac_codec_link_up(struct hdac_device *codec) +{ + set_bit(codec->addr, &codec->bus->codec_powered); +} + +static inline void snd_hdac_codec_link_down(struct hdac_device *codec) +{ + clear_bit(codec->addr, &codec->bus->codec_powered); +} + #endif /* __SOUND_HDAUDIO_H */ diff --git a/sound/hda/Makefile b/sound/hda/Makefile index 828680b282fa..3c7625e595cf 100644 --- a/sound/hda/Makefile +++ b/sound/hda/Makefile @@ -1,3 +1,3 @@ -snd-hda-core-objs := hda_bus_type.o hdac_bus.o +snd-hda-core-objs := hda_bus_type.o hdac_bus.o hdac_device.o obj-$(CONFIG_SND_HDA_CORE) += snd-hda-core.o diff --git a/sound/hda/hdac_device.c b/sound/hda/hdac_device.c new file mode 100644 index 000000000000..a3f52ad4de37 --- /dev/null +++ b/sound/hda/hdac_device.c @@ -0,0 +1,471 @@ +/* + * HD-audio codec core device + */ + +#include +#include +#include +#include +#include +#include +#include +#include "local.h" + +static void setup_fg_nodes(struct hdac_device *codec); +static int get_codec_vendor_name(struct hdac_device *codec); + +static void default_release(struct device *dev) +{ + snd_hdac_device_exit(container_of(dev, struct hdac_device, dev)); +} + +/** + * snd_hdac_device_init - initialize the HD-audio codec base device + * @codec: device to initialize + * @bus: but to attach + * @name: device name string + * @addr: codec address + * + * Returns zero for success or a negative error code. + * + * This function increments the runtime PM counter and marks it active. + * The caller needs to turn it off appropriately later. + * + * The caller needs to set the device's release op properly by itself. + */ +int snd_hdac_device_init(struct hdac_device *codec, struct hdac_bus *bus, + const char *name, unsigned int addr) +{ + struct device *dev; + hda_nid_t fg; + int err; + + dev = &codec->dev; + device_initialize(dev); + dev->parent = bus->dev; + dev->bus = &snd_hda_bus_type; + dev->release = default_release; + dev_set_name(dev, "%s", name); + device_enable_async_suspend(dev); + + codec->bus = bus; + codec->addr = addr; + codec->type = HDA_DEV_CORE; + pm_runtime_set_active(&codec->dev); + pm_runtime_get_noresume(&codec->dev); + atomic_set(&codec->in_pm, 0); + + err = snd_hdac_bus_add_device(bus, codec); + if (err < 0) + goto error; + + /* fill parameters */ + codec->vendor_id = snd_hdac_read_parm(codec, AC_NODE_ROOT, + AC_PAR_VENDOR_ID); + if (codec->vendor_id == -1) { + /* read again, hopefully the access method was corrected + * in the last read... + */ + codec->vendor_id = snd_hdac_read_parm(codec, AC_NODE_ROOT, + AC_PAR_VENDOR_ID); + } + + codec->subsystem_id = snd_hdac_read_parm(codec, AC_NODE_ROOT, + AC_PAR_SUBSYSTEM_ID); + codec->revision_id = snd_hdac_read_parm(codec, AC_NODE_ROOT, + AC_PAR_REV_ID); + + setup_fg_nodes(codec); + if (!codec->afg && !codec->mfg) { + dev_err(dev, "no AFG or MFG node found\n"); + err = -ENODEV; + goto error; + } + + fg = codec->afg ? codec->afg : codec->mfg; + + err = snd_hdac_refresh_widgets(codec); + if (err < 0) + goto error; + + codec->power_caps = snd_hdac_read_parm(codec, fg, AC_PAR_POWER_STATE); + /* reread ssid if not set by parameter */ + if (codec->subsystem_id == -1) + snd_hdac_read(codec, fg, AC_VERB_GET_SUBSYSTEM_ID, 0, + &codec->subsystem_id); + + err = get_codec_vendor_name(codec); + if (err < 0) + goto error; + + codec->chip_name = kasprintf(GFP_KERNEL, "ID %x", + codec->vendor_id & 0xffff); + if (!codec->chip_name) { + err = -ENOMEM; + goto error; + } + + return 0; + + error: + pm_runtime_put_noidle(&codec->dev); + put_device(&codec->dev); + return err; +} +EXPORT_SYMBOL_GPL(snd_hdac_device_init); + +/** + * snd_hdac_device_exit - clean up the HD-audio codec base device + * @codec: device to clean up + */ +void snd_hdac_device_exit(struct hdac_device *codec) +{ + /* pm_runtime_put_noidle(&codec->dev); */ + snd_hdac_bus_remove_device(codec->bus, codec); + kfree(codec->vendor_name); + kfree(codec->chip_name); +} +EXPORT_SYMBOL_GPL(snd_hdac_device_exit); + +/** + * snd_hdac_make_cmd - compose a 32bit command word to be sent to the + * HD-audio controller + * @codec: the codec object + * @nid: NID to encode + * @verb: verb to encode + * @parm: parameter to encode + * + * Return an encoded command verb or -1 for error. + */ +unsigned int snd_hdac_make_cmd(struct hdac_device *codec, hda_nid_t nid, + unsigned int verb, unsigned int parm) +{ + u32 val, addr; + + addr = codec->addr; + if ((addr & ~0xf) || (nid & ~0x7f) || + (verb & ~0xfff) || (parm & ~0xffff)) { + dev_err(&codec->dev, "out of range cmd %x:%x:%x:%x\n", + addr, nid, verb, parm); + return -1; + } + + val = addr << 28; + val |= (u32)nid << 20; + val |= verb << 8; + val |= parm; + return val; +} +EXPORT_SYMBOL_GPL(snd_hdac_make_cmd); + +/** + * snd_hdac_read - execute a verb + * @codec: the codec object + * @nid: NID to execute a verb + * @verb: verb to execute + * @parm: parameter for a verb + * @res: the pointer to store the result, NULL if running async + * + * Returns zero if successful, or a negative error code. + */ +int snd_hdac_read(struct hdac_device *codec, hda_nid_t nid, + unsigned int verb, unsigned int parm, unsigned int *res) +{ + unsigned int cmd = snd_hdac_make_cmd(codec, nid, verb, parm); + + return snd_hdac_bus_exec_verb(codec->bus, codec->addr, cmd, res); +} +EXPORT_SYMBOL_GPL(snd_hdac_read); + +/** + * snd_hdac_read_parm - read a codec parameter + * @codec: the codec object + * @nid: NID to read a parameter + * @parm: parameter to read + * + * Returns -1 for error. If you need to distinguish the error more + * strictly, use snd_hdac_read() directly. + */ +int snd_hdac_read_parm(struct hdac_device *codec, hda_nid_t nid, int parm) +{ + int val; + + if (snd_hdac_read(codec, nid, AC_VERB_PARAMETERS, parm, &val)) + return -1; + return val; +} +EXPORT_SYMBOL_GPL(snd_hdac_read_parm); + +/** + * snd_hdac_get_sub_nodes - get start NID and number of subtree nodes + * @codec: the codec object + * @nid: NID to inspect + * @start_id: the pointer to store the starting NID + * + * Returns the number of subtree nodes or zero if not found. + */ +int snd_hdac_get_sub_nodes(struct hdac_device *codec, hda_nid_t nid, + hda_nid_t *start_id) +{ + unsigned int parm; + + parm = snd_hdac_read_parm(codec, nid, AC_PAR_NODE_COUNT); + if (parm == -1) { + *start_id = 0; + return 0; + } + *start_id = (parm >> 16) & 0x7fff; + return (int)(parm & 0x7fff); +} +EXPORT_SYMBOL_GPL(snd_hdac_get_sub_nodes); + +/* + * look for an AFG and MFG nodes + */ +static void setup_fg_nodes(struct hdac_device *codec) +{ + int i, total_nodes, function_id; + hda_nid_t nid; + + total_nodes = snd_hdac_get_sub_nodes(codec, AC_NODE_ROOT, &nid); + for (i = 0; i < total_nodes; i++, nid++) { + function_id = snd_hdac_read_parm(codec, nid, + AC_PAR_FUNCTION_TYPE); + switch (function_id & 0xff) { + case AC_GRP_AUDIO_FUNCTION: + codec->afg = nid; + codec->afg_function_id = function_id & 0xff; + codec->afg_unsol = (function_id >> 8) & 1; + break; + case AC_GRP_MODEM_FUNCTION: + codec->mfg = nid; + codec->mfg_function_id = function_id & 0xff; + codec->mfg_unsol = (function_id >> 8) & 1; + break; + default: + break; + } + } +} + +/** + * snd_hdac_refresh_widgets - Reset the widget start/end nodes + * @codec: the codec object + */ +int snd_hdac_refresh_widgets(struct hdac_device *codec) +{ + hda_nid_t start_nid; + int nums; + + nums = snd_hdac_get_sub_nodes(codec, codec->afg, &start_nid); + if (!start_nid || nums <= 0 || nums >= 0xff) { + dev_err(&codec->dev, "cannot read sub nodes for FG 0x%02x\n", + codec->afg); + return -EINVAL; + } + + codec->num_nodes = nums; + codec->start_nid = start_nid; + codec->end_nid = start_nid + nums; + return 0; +} +EXPORT_SYMBOL_GPL(snd_hdac_refresh_widgets); + +/* return CONNLIST_LEN parameter of the given widget */ +static unsigned int get_num_conns(struct hdac_device *codec, hda_nid_t nid) +{ + unsigned int wcaps = get_wcaps(codec, nid); + unsigned int parm; + + if (!(wcaps & AC_WCAP_CONN_LIST) && + get_wcaps_type(wcaps) != AC_WID_VOL_KNB) + return 0; + + parm = snd_hdac_read_parm(codec, nid, AC_PAR_CONNLIST_LEN); + if (parm == -1) + parm = 0; + return parm; +} + +/** + * snd_hdac_get_connections - get a widget connection list + * @codec: the codec object + * @nid: NID + * @conn_list: the array to store the results, can be NULL + * @max_conns: the max size of the given array + * + * Returns the number of connected widgets, zero for no connection, or a + * negative error code. When the number of elements don't fit with the + * given array size, it returns -ENOSPC. + * + * When @conn_list is NULL, it just checks the number of connections. + */ +int snd_hdac_get_connections(struct hdac_device *codec, hda_nid_t nid, + hda_nid_t *conn_list, int max_conns) +{ + unsigned int parm; + int i, conn_len, conns, err; + unsigned int shift, num_elems, mask; + hda_nid_t prev_nid; + int null_count = 0; + + parm = get_num_conns(codec, nid); + if (!parm) + return 0; + + if (parm & AC_CLIST_LONG) { + /* long form */ + shift = 16; + num_elems = 2; + } else { + /* short form */ + shift = 8; + num_elems = 4; + } + conn_len = parm & AC_CLIST_LENGTH; + mask = (1 << (shift-1)) - 1; + + if (!conn_len) + return 0; /* no connection */ + + if (conn_len == 1) { + /* single connection */ + err = snd_hdac_read(codec, nid, AC_VERB_GET_CONNECT_LIST, 0, + &parm); + if (err < 0) + return err; + if (conn_list) + conn_list[0] = parm & mask; + return 1; + } + + /* multi connection */ + conns = 0; + prev_nid = 0; + for (i = 0; i < conn_len; i++) { + int range_val; + hda_nid_t val, n; + + if (i % num_elems == 0) { + err = snd_hdac_read(codec, nid, + AC_VERB_GET_CONNECT_LIST, i, + &parm); + if (err < 0) + return -EIO; + } + range_val = !!(parm & (1 << (shift-1))); /* ranges */ + val = parm & mask; + if (val == 0 && null_count++) { /* no second chance */ + dev_dbg(&codec->dev, + "invalid CONNECT_LIST verb %x[%i]:%x\n", + nid, i, parm); + return 0; + } + parm >>= shift; + if (range_val) { + /* ranges between the previous and this one */ + if (!prev_nid || prev_nid >= val) { + dev_warn(&codec->dev, + "invalid dep_range_val %x:%x\n", + prev_nid, val); + continue; + } + for (n = prev_nid + 1; n <= val; n++) { + if (conn_list) { + if (conns >= max_conns) + return -ENOSPC; + conn_list[conns] = n; + } + conns++; + } + } else { + if (conn_list) { + if (conns >= max_conns) + return -ENOSPC; + conn_list[conns] = val; + } + conns++; + } + prev_nid = val; + } + return conns; +} +EXPORT_SYMBOL_GPL(snd_hdac_get_connections); + +#ifdef CONFIG_PM +/** + * snd_hdac_power_up - increment the runtime pm counter + * @codec: the codec object + */ +void snd_hdac_power_up(struct hdac_device *codec) +{ + struct device *dev = &codec->dev; + + if (atomic_read(&codec->in_pm)) + return; + pm_runtime_get_sync(dev); +} +EXPORT_SYMBOL_GPL(snd_hdac_power_up); + +/** + * snd_hdac_power_up - decrement the runtime pm counter + * @codec: the codec object + */ +void snd_hdac_power_down(struct hdac_device *codec) +{ + struct device *dev = &codec->dev; + + if (atomic_read(&codec->in_pm)) + return; + pm_runtime_mark_last_busy(dev); + pm_runtime_put_autosuspend(dev); +} +EXPORT_SYMBOL_GPL(snd_hdac_power_down); +#endif + +/* codec vendor labels */ +struct hda_vendor_id { + unsigned int id; + const char *name; +}; + +static struct hda_vendor_id hda_vendor_ids[] = { + { 0x1002, "ATI" }, + { 0x1013, "Cirrus Logic" }, + { 0x1057, "Motorola" }, + { 0x1095, "Silicon Image" }, + { 0x10de, "Nvidia" }, + { 0x10ec, "Realtek" }, + { 0x1102, "Creative" }, + { 0x1106, "VIA" }, + { 0x111d, "IDT" }, + { 0x11c1, "LSI" }, + { 0x11d4, "Analog Devices" }, + { 0x13f6, "C-Media" }, + { 0x14f1, "Conexant" }, + { 0x17e8, "Chrontel" }, + { 0x1854, "LG" }, + { 0x1aec, "Wolfson Microelectronics" }, + { 0x1af4, "QEMU" }, + { 0x434d, "C-Media" }, + { 0x8086, "Intel" }, + { 0x8384, "SigmaTel" }, + {} /* terminator */ +}; + +/* store the codec vendor name */ +static int get_codec_vendor_name(struct hdac_device *codec) +{ + const struct hda_vendor_id *c; + u16 vendor_id = codec->vendor_id >> 16; + + for (c = hda_vendor_ids; c->id; c++) { + if (c->id == vendor_id) { + codec->vendor_name = kstrdup(c->name, GFP_KERNEL); + return codec->vendor_name ? 0 : -ENOMEM; + } + } + + codec->vendor_name = kasprintf(GFP_KERNEL, "Generic %04x", vendor_id); + return codec->vendor_name ? 0 : -ENOMEM; +} diff --git a/sound/hda/local.h b/sound/hda/local.h new file mode 100644 index 000000000000..a077d1f656f6 --- /dev/null +++ b/sound/hda/local.h @@ -0,0 +1,19 @@ +/* + * Local helper macros and functions for HD-audio core drivers + */ + +#ifndef __HDAC_LOCAL_H +#define __HDAC_LOCAL_H + +#define get_wcaps(codec, nid) \ + snd_hdac_read_parm(codec, nid, AC_PAR_AUDIO_WIDGET_CAP) + +/* get the widget type from widget capability bits */ +static inline int get_wcaps_type(unsigned int wcaps) +{ + if (!wcaps) + return -1; /* invalid type */ + return (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; +} + +#endif /* __HDAC_LOCAL_H */ 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, const hda_nid_t *ignore_nids, unsigned int cond_flags) { - hda_nid_t nid, end_nid; + hda_nid_t nid; short seq, assoc_line_out; struct auto_out_pin line_out[ARRAY_SIZE(cfg->line_out_pins)]; 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, memset(hp_out, 0, sizeof(hp_out)); assoc_line_out = 0; - end_nid = codec->start_nid + codec->num_nodes; - for (nid = codec->start_nid; nid < end_nid; nid++) { + for_each_hda_codec_node(nid, codec) { unsigned int wid_caps = get_wcaps(codec, nid); unsigned int wid_type = get_wcaps_type(wid_caps); unsigned int def_conf; @@ -410,7 +409,7 @@ int snd_hda_parse_pin_defcfg(struct hda_codec *codec, * debug prints of the parsed results */ codec_info(codec, "autoconfig for %s: line_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x) type:%s\n", - codec->chip_name, cfg->line_outs, cfg->line_out_pins[0], + codec->core.chip_name, cfg->line_outs, cfg->line_out_pins[0], cfg->line_out_pins[1], cfg->line_out_pins[2], cfg->line_out_pins[3], cfg->line_out_pins[4], 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) if (action != HDA_FIXUP_ACT_PRE_PROBE || !fix->v.pins) break; codec_dbg(codec, "%s: Apply pincfg for %s\n", - codec->chip_name, modelname); + codec->core.chip_name, modelname); snd_hda_apply_pincfgs(codec, fix->v.pins); break; case HDA_FIXUP_VERBS: if (action != HDA_FIXUP_ACT_PROBE || !fix->v.verbs) break; codec_dbg(codec, "%s: Apply fix-verbs for %s\n", - codec->chip_name, modelname); + codec->core.chip_name, modelname); snd_hda_add_verbs(codec, fix->v.verbs); break; case HDA_FIXUP_FUNC: if (!fix->v.func) break; codec_dbg(codec, "%s: Apply fix-func for %s\n", - codec->chip_name, modelname); + codec->core.chip_name, modelname); fix->v.func(codec, fix, action); break; case HDA_FIXUP_PINCTLS: if (action != HDA_FIXUP_ACT_PROBE || !fix->v.pins) break; codec_dbg(codec, "%s: Apply pinctl for %s\n", - codec->chip_name, modelname); + codec->core.chip_name, modelname); set_pin_targets(codec, fix->v.pins); break; default: codec_err(codec, "%s: Invalid fixup type %d\n", - codec->chip_name, fix->type); + codec->core.chip_name, fix->type); break; } if (!fix->chained || fix->chained_before) @@ -912,16 +911,16 @@ void snd_hda_pick_pin_fixup(struct hda_codec *codec, return; for (pq = pin_quirk; pq->subvendor; pq++) { - if ((codec->subsystem_id & 0xffff0000) != (pq->subvendor << 16)) + if ((codec->core.subsystem_id & 0xffff0000) != (pq->subvendor << 16)) continue; - if (codec->vendor_id != pq->codec) + if (codec->core.vendor_id != pq->codec) continue; if (pin_config_match(codec, pq->pins)) { codec->fixup_id = pq->value; #ifdef CONFIG_SND_DEBUG_VERBOSE codec->fixup_name = pq->name; codec_dbg(codec, "%s: picked fixup %s (pin match)\n", - codec->chip_name, codec->fixup_name); + codec->core.chip_name, codec->fixup_name); #endif codec->fixup_list = fixlist; return; @@ -963,7 +962,7 @@ void snd_hda_pick_fixup(struct hda_codec *codec, codec->fixup_name = NULL; codec->fixup_id = HDA_FIXUP_ID_NO_FIXUP; codec_dbg(codec, "%s: picked no fixup (nofixup specified)\n", - codec->chip_name); + codec->core.chip_name); return; } @@ -974,7 +973,7 @@ void snd_hda_pick_fixup(struct hda_codec *codec, codec->fixup_name = models->name; codec->fixup_list = fixlist; codec_dbg(codec, "%s: picked fixup %s (model specified)\n", - codec->chip_name, codec->fixup_name); + codec->core.chip_name, codec->fixup_name); return; } models++; @@ -987,7 +986,7 @@ void snd_hda_pick_fixup(struct hda_codec *codec, #ifdef CONFIG_SND_DEBUG_VERBOSE name = q->name; codec_dbg(codec, "%s: picked fixup %s (PCI SSID%s)\n", - codec->chip_name, name, q->subdevice_mask ? "" : " - vendor generic"); + codec->core.chip_name, name, q->subdevice_mask ? "" : " - vendor generic"); #endif } } @@ -996,12 +995,12 @@ void snd_hda_pick_fixup(struct hda_codec *codec, unsigned int vendorid = q->subdevice | (q->subvendor << 16); unsigned int mask = 0xffff0000 | q->subdevice_mask; - if ((codec->subsystem_id & mask) == (vendorid & mask)) { + if ((codec->core.subsystem_id & mask) == (vendorid & mask)) { id = q->value; #ifdef CONFIG_SND_DEBUG_VERBOSE name = q->name; codec_dbg(codec, "%s: picked fixup %s (codec SSID)\n", - codec->chip_name, name); + codec->core.chip_name, name); #endif break; } diff --git a/sound/pci/hda/hda_beep.c b/sound/pci/hda/hda_beep.c index 4cdac3a71cae..3364dc0fdeab 100644 --- a/sound/pci/hda/hda_beep.c +++ b/sound/pci/hda/hda_beep.c @@ -165,8 +165,8 @@ static int snd_hda_do_attach(struct hda_beep *beep) input_dev->id.bustype = BUS_PCI; input_dev->dev.parent = &codec->card->card_dev; - input_dev->id.vendor = codec->vendor_id >> 16; - input_dev->id.product = codec->vendor_id & 0xffff; + input_dev->id.vendor = codec->core.vendor_id >> 16; + input_dev->id.product = codec->core.vendor_id & 0xffff; input_dev->id.version = 0x01; input_dev->evbit[0] = BIT_MASK(EV_SND); diff --git a/sound/pci/hda/hda_bind.c b/sound/pci/hda/hda_bind.c index 0b9ea70c546b..ad276a9771db 100644 --- a/sound/pci/hda/hda_bind.c +++ b/sound/pci/hda/hda_bind.c @@ -14,36 +14,6 @@ #include "hda_codec.h" #include "hda_local.h" -/* codec vendor labels */ -struct hda_vendor_id { - unsigned int id; - const char *name; -}; - -static struct hda_vendor_id hda_vendor_ids[] = { - { 0x1002, "ATI" }, - { 0x1013, "Cirrus Logic" }, - { 0x1057, "Motorola" }, - { 0x1095, "Silicon Image" }, - { 0x10de, "Nvidia" }, - { 0x10ec, "Realtek" }, - { 0x1102, "Creative" }, - { 0x1106, "VIA" }, - { 0x111d, "IDT" }, - { 0x11c1, "LSI" }, - { 0x11d4, "Analog Devices" }, - { 0x13f6, "C-Media" }, - { 0x14f1, "Conexant" }, - { 0x17e8, "Chrontel" }, - { 0x1854, "LG" }, - { 0x1aec, "Wolfson Microelectronics" }, - { 0x1af4, "QEMU" }, - { 0x434d, "C-Media" }, - { 0x8086, "Intel" }, - { 0x8384, "SigmaTel" }, - {} /* terminator */ -}; - /* * find a matching codec preset */ @@ -54,19 +24,19 @@ static int hda_codec_match(struct hdac_device *dev, struct hdac_driver *drv) container_of(drv, struct hda_codec_driver, core); const struct hda_codec_preset *preset; /* check probe_id instead of vendor_id if set */ - u32 id = codec->probe_id ? codec->probe_id : codec->vendor_id; + u32 id = codec->probe_id ? codec->probe_id : codec->core.vendor_id; for (preset = driver->preset; preset->id; preset++) { u32 mask = preset->mask; - if (preset->afg && preset->afg != codec->afg) + if (preset->afg && preset->afg != codec->core.afg) continue; - if (preset->mfg && preset->mfg != codec->mfg) + if (preset->mfg && preset->mfg != codec->core.mfg) continue; if (!mask) mask = ~0; if (preset->id == (id & mask) && - (!preset->rev || preset->rev == codec->revision_id)) { + (!preset->rev || preset->rev == codec->core.revision_id)) { codec->preset = preset; return 1; } @@ -86,15 +56,11 @@ static void hda_codec_unsol_event(struct hdac_device *dev, unsigned int ev) /* reset the codec name from the preset */ static int codec_refresh_name(struct hda_codec *codec, const char *name) { - char tmp[16]; - - kfree(codec->chip_name); - if (!name) { - sprintf(tmp, "ID %x", codec->vendor_id & 0xffff); - name = tmp; + if (name) { + kfree(codec->core.chip_name); + codec->core.chip_name = kstrdup(name, GFP_KERNEL); } - codec->chip_name = kstrdup(name, GFP_KERNEL); - return codec->chip_name ? 0 : -ENOMEM; + return codec->core.chip_name ? 0 : -ENOMEM; } static int hda_codec_driver_probe(struct device *dev) @@ -192,48 +158,23 @@ static inline bool codec_probed(struct hda_codec *codec) static void codec_bind_module(struct hda_codec *codec) { #ifdef MODULE - request_module("snd-hda-codec-id:%08x", codec->vendor_id); + request_module("snd-hda-codec-id:%08x", codec->core.vendor_id); if (codec_probed(codec)) return; request_module("snd-hda-codec-id:%04x*", - (codec->vendor_id >> 16) & 0xffff); + (codec->core.vendor_id >> 16) & 0xffff); if (codec_probed(codec)) return; #endif } -/* store the codec vendor name */ -static int get_codec_vendor_name(struct hda_codec *codec) -{ - const struct hda_vendor_id *c; - const char *vendor = NULL; - u16 vendor_id = codec->vendor_id >> 16; - char tmp[16]; - - for (c = hda_vendor_ids; c->id; c++) { - if (c->id == vendor_id) { - vendor = c->name; - break; - } - } - if (!vendor) { - sprintf(tmp, "Generic %04x", vendor_id); - vendor = tmp; - } - codec->vendor_name = kstrdup(vendor, GFP_KERNEL); - if (!codec->vendor_name) - return -ENOMEM; - return 0; -} - #if IS_ENABLED(CONFIG_SND_HDA_CODEC_HDMI) /* if all audio out widgets are digital, let's assume the codec as a HDMI/DP */ static bool is_likely_hdmi_codec(struct hda_codec *codec) { - hda_nid_t nid = codec->start_nid; - int i; + hda_nid_t nid; - for (i = 0; i < codec->num_nodes; i++, nid++) { + for_each_hda_codec_node(nid, codec) { unsigned int wcaps = get_wcaps(codec, nid); switch (get_wcaps_type(wcaps)) { case AC_WID_AUD_IN: @@ -294,12 +235,6 @@ int snd_hda_codec_configure(struct hda_codec *codec) { int err; - if (!codec->vendor_name) { - err = get_codec_vendor_name(codec); - if (err < 0) - return err; - } - if (is_generic_config(codec)) codec->probe_id = HDA_CODEC_ID_GENERIC; else @@ -320,10 +255,10 @@ int snd_hda_codec_configure(struct hda_codec *codec) } /* audio codec should override the mixer name */ - if (codec->afg || !*codec->card->mixername) + if (codec->core.afg || !*codec->card->mixername) snprintf(codec->card->mixername, - sizeof(codec->card->mixername), - "%s %s", codec->vendor_name, codec->chip_name); + sizeof(codec->card->mixername), "%s %s", + codec->core.vendor_name, codec->core.chip_name); return 0; error: diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index f96bff37c787..ddfc0fbbee23 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -40,7 +40,7 @@ #include #ifdef CONFIG_PM -#define codec_in_pm(codec) atomic_read(&(codec)->in_pm) +#define codec_in_pm(codec) atomic_read(&(codec)->core.in_pm) #define hda_codec_is_power_on(codec) \ (!pm_runtime_suspended(hda_codec_dev(codec))) #else @@ -48,6 +48,11 @@ #define hda_codec_is_power_on(codec) 1 #endif +#define codec_has_epss(codec) \ + ((codec)->core.power_caps & AC_PWRST_EPSS) +#define codec_has_clkstop(codec) \ + ((codec)->core.power_caps & AC_PWRST_CLKSTOP) + /** * snd_hda_get_jack_location - Give a location string of the jack * @cfg: pin default config value @@ -118,30 +123,6 @@ const char *snd_hda_get_jack_type(u32 cfg) } EXPORT_SYMBOL_GPL(snd_hda_get_jack_type); -/* - * Compose a 32bit command word to be sent to the HD-audio controller - */ -static inline unsigned int -make_codec_cmd(struct hda_codec *codec, hda_nid_t nid, int flags, - unsigned int verb, unsigned int parm) -{ - unsigned int addr = codec->core.addr; - u32 val; - - if ((addr & ~0xf) || (nid & ~0x7f) || - (verb & ~0xfff) || (parm & ~0xffff)) { - codec_err(codec, "hda-codec: out of range cmd %x:%x:%x:%x\n", - addr, nid, verb, parm); - return ~0; - } - - val = (u32)addr << 28; - val |= (u32)nid << 20; - val |= verb << 8; - val |= parm; - return val; -} - /* * Send and receive a verb */ @@ -194,7 +175,7 @@ unsigned int snd_hda_codec_read(struct hda_codec *codec, hda_nid_t nid, int flags, unsigned int verb, unsigned int parm) { - unsigned cmd = make_codec_cmd(codec, nid, flags, verb, parm); + unsigned int cmd = snd_hdac_make_cmd(&codec->core, nid, verb, parm); unsigned int res; if (codec_exec_verb(codec, cmd, flags, &res)) return -1; @@ -217,7 +198,7 @@ EXPORT_SYMBOL_GPL(snd_hda_codec_read); int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int flags, unsigned int verb, unsigned int parm) { - unsigned int cmd = make_codec_cmd(codec, nid, flags, verb, parm); + unsigned int cmd = snd_hdac_make_cmd(&codec->core, nid, verb, parm); return codec_exec_verb(codec, cmd, flags, NULL); } EXPORT_SYMBOL_GPL(snd_hda_codec_write); @@ -237,30 +218,6 @@ void snd_hda_sequence_write(struct hda_codec *codec, const struct hda_verb *seq) } EXPORT_SYMBOL_GPL(snd_hda_sequence_write); -/** - * snd_hda_get_sub_nodes - get the range of sub nodes - * @codec: the HDA codec - * @nid: NID to parse - * @start_id: the pointer to store the start NID - * - * Parse the NID and store the start NID of its sub-nodes. - * Returns the number of sub-nodes. - */ -int snd_hda_get_sub_nodes(struct hda_codec *codec, hda_nid_t nid, - hda_nid_t *start_id) -{ - unsigned int parm; - - parm = snd_hda_param_read(codec, nid, AC_PAR_NODE_COUNT); - if (parm == -1) { - *start_id = 0; - return 0; - } - *start_id = (parm >> 16) & 0x7fff; - return (int)(parm & 0x7fff); -} -EXPORT_SYMBOL_GPL(snd_hda_get_sub_nodes); - /* connection list element */ struct hda_conn_list { struct list_head list; @@ -401,128 +358,6 @@ int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid, } EXPORT_SYMBOL_GPL(snd_hda_get_connections); -/* return CONNLIST_LEN parameter of the given widget */ -static unsigned int get_num_conns(struct hda_codec *codec, hda_nid_t nid) -{ - unsigned int wcaps = get_wcaps(codec, nid); - unsigned int parm; - - if (!(wcaps & AC_WCAP_CONN_LIST) && - get_wcaps_type(wcaps) != AC_WID_VOL_KNB) - return 0; - - parm = snd_hda_param_read(codec, nid, AC_PAR_CONNLIST_LEN); - if (parm == -1) - parm = 0; - return parm; -} - -int snd_hda_get_num_raw_conns(struct hda_codec *codec, hda_nid_t nid) -{ - return snd_hda_get_raw_connections(codec, nid, NULL, 0); -} - -/** - * snd_hda_get_raw_connections - copy connection list without cache - * @codec: the HDA codec - * @nid: NID to parse - * @conn_list: connection list array - * @max_conns: max. number of connections to store - * - * Like snd_hda_get_connections(), copy the connection list but without - * checking through the connection-list cache. - * Currently called only from hda_proc.c, so not exported. - */ -int snd_hda_get_raw_connections(struct hda_codec *codec, hda_nid_t nid, - hda_nid_t *conn_list, int max_conns) -{ - unsigned int parm; - int i, conn_len, conns; - unsigned int shift, num_elems, mask; - hda_nid_t prev_nid; - int null_count = 0; - - parm = get_num_conns(codec, nid); - if (!parm) - return 0; - - if (parm & AC_CLIST_LONG) { - /* long form */ - shift = 16; - num_elems = 2; - } else { - /* short form */ - shift = 8; - num_elems = 4; - } - conn_len = parm & AC_CLIST_LENGTH; - mask = (1 << (shift-1)) - 1; - - if (!conn_len) - return 0; /* no connection */ - - if (conn_len == 1) { - /* single connection */ - parm = snd_hda_codec_read(codec, nid, 0, - AC_VERB_GET_CONNECT_LIST, 0); - if (parm == -1 && codec->bus->rirb_error) - return -EIO; - if (conn_list) - conn_list[0] = parm & mask; - return 1; - } - - /* multi connection */ - conns = 0; - prev_nid = 0; - for (i = 0; i < conn_len; i++) { - int range_val; - hda_nid_t val, n; - - if (i % num_elems == 0) { - parm = snd_hda_codec_read(codec, nid, 0, - AC_VERB_GET_CONNECT_LIST, i); - if (parm == -1 && codec->bus->rirb_error) - return -EIO; - } - range_val = !!(parm & (1 << (shift-1))); /* ranges */ - val = parm & mask; - if (val == 0 && null_count++) { /* no second chance */ - codec_dbg(codec, - "invalid CONNECT_LIST verb %x[%i]:%x\n", - nid, i, parm); - return 0; - } - parm >>= shift; - if (range_val) { - /* ranges between the previous and this one */ - if (!prev_nid || prev_nid >= val) { - codec_warn(codec, - "invalid dep_range_val %x:%x\n", - prev_nid, val); - continue; - } - for (n = prev_nid + 1; n <= val; n++) { - if (conn_list) { - if (conns >= max_conns) - return -ENOSPC; - conn_list[conns] = n; - } - conns++; - } - } else { - if (conn_list) { - if (conns >= max_conns) - return -ENOSPC; - conn_list[conns] = val; - } - conns++; - } - prev_nid = val; - } - return conns; -} - /** * snd_hda_override_conn_list - add/modify the connection-list to cache * @codec: the HDA codec @@ -737,35 +572,6 @@ int snd_hda_bus_new(struct snd_card *card, } EXPORT_SYMBOL_GPL(snd_hda_bus_new); -/* - * look for an AFG and MFG nodes - */ -static void setup_fg_nodes(struct hda_codec *codec) -{ - int i, total_nodes, function_id; - hda_nid_t nid; - - total_nodes = snd_hda_get_sub_nodes(codec, AC_NODE_ROOT, &nid); - for (i = 0; i < total_nodes; i++, nid++) { - function_id = snd_hda_param_read(codec, nid, - AC_PAR_FUNCTION_TYPE); - switch (function_id & 0xff) { - case AC_GRP_AUDIO_FUNCTION: - codec->afg = nid; - codec->afg_function_id = function_id & 0xff; - codec->afg_unsol = (function_id >> 8) & 1; - break; - case AC_GRP_MODEM_FUNCTION: - codec->mfg = nid; - codec->mfg_function_id = function_id & 0xff; - codec->mfg_unsol = (function_id >> 8) & 1; - break; - default: - break; - } - } -} - /* * read widget caps for each widget and store in cache */ @@ -774,13 +580,11 @@ static int read_widget_caps(struct hda_codec *codec, hda_nid_t fg_node) int i; hda_nid_t nid; - codec->num_nodes = snd_hda_get_sub_nodes(codec, fg_node, - &codec->start_nid); - codec->wcaps = kmalloc(codec->num_nodes * 4, GFP_KERNEL); + codec->wcaps = kmalloc(codec->core.num_nodes * 4, GFP_KERNEL); if (!codec->wcaps) return -ENOMEM; - nid = codec->start_nid; - for (i = 0; i < codec->num_nodes; i++, nid++) + nid = codec->core.start_nid; + for (i = 0; i < codec->core.num_nodes; i++, nid++) codec->wcaps[i] = snd_hda_param_read(codec, nid, AC_PAR_AUDIO_WIDGET_CAP); return 0; @@ -789,10 +593,9 @@ static int read_widget_caps(struct hda_codec *codec, hda_nid_t fg_node) /* read all pin default configurations and save codec->init_pins */ static int read_pin_defaults(struct hda_codec *codec) { - int i; - hda_nid_t nid = codec->start_nid; + hda_nid_t nid; - for (i = 0; i < codec->num_nodes; i++, nid++) { + for_each_hda_codec_node(nid, codec) { struct hda_pincfg *pin; unsigned int wcaps = get_wcaps(codec, nid); unsigned int wid_type = get_wcaps_type(wcaps); @@ -1136,9 +939,6 @@ void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec) remove_conn_list(codec); } -static bool snd_hda_codec_get_supported_ps(struct hda_codec *codec, - hda_nid_t fg, unsigned int power_state); - static unsigned int hda_set_power_state(struct hda_codec *codec, unsigned int power_state); @@ -1178,12 +978,10 @@ static void snd_hda_codec_dev_release(struct device *dev) struct hda_codec *codec = dev_to_hda_codec(dev); free_init_pincfgs(codec); - snd_hdac_bus_remove_device(&codec->bus->core, &codec->core); + snd_hdac_device_exit(&codec->core); snd_hda_sysfs_clear(codec); free_hda_cache(&codec->amp_cache); free_hda_cache(&codec->cmd_cache); - kfree(codec->vendor_name); - kfree(codec->chip_name); kfree(codec->modelname); kfree(codec->wcaps); kfree(codec); @@ -1201,7 +999,6 @@ int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card, unsigned int codec_addr, struct hda_codec **codecp) { struct hda_codec *codec; - struct device *dev; char component[31]; hda_nid_t fg; int err; @@ -1220,19 +1017,16 @@ int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card, if (!codec) return -ENOMEM; - codec->core.bus = &bus->core; - codec->core.addr = codec_addr; - codec->core.type = HDA_DEV_LEGACY; + sprintf(component, "hdaudioC%dD%d", card->number, codec_addr); + err = snd_hdac_device_init(&codec->core, &bus->core, component, + codec_addr); + if (err < 0) { + kfree(codec); + return err; + } - dev = hda_codec_dev(codec); - device_initialize(dev); - dev->parent = bus->core.dev; - dev->bus = &snd_hda_bus_type; - dev->release = snd_hda_codec_dev_release; - dev->groups = snd_hda_dev_attr_groups; - dev_set_name(dev, "hdaudioC%dD%d", card->number, codec_addr); - dev_set_drvdata(dev, codec); /* for sysfs */ - device_enable_async_suspend(dev); + codec->core.dev.release = snd_hda_codec_dev_release; + codec->core.type = HDA_DEV_LEGACY; codec->bus = bus; codec->card = card; @@ -1258,12 +1052,6 @@ int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card, codec->fixup_id = HDA_FIXUP_ID_NOT_SET; #ifdef CONFIG_PM - /* snd_hda_codec_new() marks the codec as power-up, and leave it as is. - * it's powered down later in snd_hda_codec_dev_register(). - */ - set_bit(codec->core.addr, &bus->core.codec_powered); - pm_runtime_set_active(hda_codec_dev(codec)); - pm_runtime_get_noresume(hda_codec_dev(codec)); codec->power_jiffies = jiffies; #endif @@ -1277,31 +1065,7 @@ int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card, } } - err = snd_hdac_bus_add_device(&bus->core, &codec->core); - if (err < 0) - goto error; - - codec->vendor_id = snd_hda_param_read(codec, AC_NODE_ROOT, - AC_PAR_VENDOR_ID); - if (codec->vendor_id == -1) - /* read again, hopefully the access method was corrected - * in the last read... - */ - codec->vendor_id = snd_hda_param_read(codec, AC_NODE_ROOT, - AC_PAR_VENDOR_ID); - codec->subsystem_id = snd_hda_param_read(codec, AC_NODE_ROOT, - AC_PAR_SUBSYSTEM_ID); - codec->revision_id = snd_hda_param_read(codec, AC_NODE_ROOT, - AC_PAR_REV_ID); - - setup_fg_nodes(codec); - if (!codec->afg && !codec->mfg) { - codec_err(codec, "no AFG or MFG node found\n"); - err = -ENODEV; - goto error; - } - - fg = codec->afg ? codec->afg : codec->mfg; + fg = codec->core.afg ? codec->core.afg : codec->core.mfg; err = read_widget_caps(codec, fg); if (err < 0) goto error; @@ -1309,19 +1073,6 @@ int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card, if (err < 0) goto error; - if (!codec->subsystem_id) { - codec->subsystem_id = - snd_hda_codec_read(codec, fg, 0, - AC_VERB_GET_SUBSYSTEM_ID, 0); - } - -#ifdef CONFIG_PM - codec->d3_stop_clk = snd_hda_codec_get_supported_ps(codec, fg, - AC_PWRST_CLKSTOP); -#endif - codec->epss = snd_hda_codec_get_supported_ps(codec, fg, - AC_PWRST_EPSS); - /* power-up all before initialization */ hda_set_power_state(codec, AC_PWRST_D0); @@ -1329,8 +1080,8 @@ int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card, snd_hda_create_hwdep(codec); - sprintf(component, "HDA:%08x,%08x,%08x", codec->vendor_id, - codec->subsystem_id, codec->revision_id); + sprintf(component, "HDA:%08x,%08x,%08x", codec->core.vendor_id, + codec->core.subsystem_id, codec->core.revision_id); snd_component_add(card, component); err = snd_device_new(card, SNDRV_DEV_CODEC, codec, &dev_ops); @@ -1342,6 +1093,7 @@ int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card, return 0; error: + pm_runtime_put_noidle(hda_codec_dev(codec)); put_device(hda_codec_dev(codec)); return err; } @@ -1359,11 +1111,15 @@ int snd_hda_codec_update_widgets(struct hda_codec *codec) hda_nid_t fg; int err; + err = snd_hdac_refresh_widgets(&codec->core); + if (err < 0) + return err; + /* Assume the function group node does not change, * only the widget nodes may change. */ kfree(codec->wcaps); - fg = codec->afg ? codec->afg : codec->mfg; + fg = codec->core.afg ? codec->core.afg : codec->core.mfg; err = read_widget_caps(codec, fg); if (err < 0) return err; @@ -1663,7 +1419,7 @@ static unsigned int read_amp_cap(struct hda_codec *codec, hda_nid_t nid, int direction) { if (!(get_wcaps(codec, nid) & AC_WCAP_AMP_OVRD)) - nid = codec->afg; + nid = codec->core.afg; return snd_hda_param_read(codec, nid, direction == HDA_OUTPUT ? AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP); @@ -3664,10 +3420,9 @@ EXPORT_SYMBOL_GPL(snd_hda_codec_flush_cache); void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg, unsigned int power_state) { - hda_nid_t nid = codec->start_nid; - int i; + hda_nid_t nid; - for (i = 0; i < codec->num_nodes; i++, nid++) { + for_each_hda_codec_node(nid, codec) { unsigned int wcaps = get_wcaps(codec, nid); unsigned int state = power_state; if (!(wcaps & AC_WCAP_POWER)) @@ -3683,22 +3438,6 @@ void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg, } EXPORT_SYMBOL_GPL(snd_hda_codec_set_power_to_all); -/* - * supported power states check - */ -static bool snd_hda_codec_get_supported_ps(struct hda_codec *codec, hda_nid_t fg, - unsigned int power_state) -{ - int sup = snd_hda_param_read(codec, fg, AC_PAR_POWER_STATE); - - if (sup == -1) - return false; - if (sup & power_state) - return true; - else - return false; -} - /* * wait until the state is reached, returns the current state */ @@ -3738,7 +3477,7 @@ unsigned int snd_hda_codec_eapd_power_filter(struct hda_codec *codec, hda_nid_t nid, unsigned int power_state) { - if (nid == codec->afg || nid == codec->mfg) + if (nid == codec->core.afg || nid == codec->core.mfg) return power_state; if (power_state == AC_PWRST_D3 && get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_PIN && @@ -3758,7 +3497,7 @@ EXPORT_SYMBOL_GPL(snd_hda_codec_eapd_power_filter); static unsigned int hda_set_power_state(struct hda_codec *codec, unsigned int power_state) { - hda_nid_t fg = codec->afg ? codec->afg : codec->mfg; + hda_nid_t fg = codec->core.afg ? codec->core.afg : codec->core.mfg; int count; unsigned int state; int flags = 0; @@ -3766,7 +3505,7 @@ static unsigned int hda_set_power_state(struct hda_codec *codec, /* this delay seems necessary to avoid click noise at power-down */ if (power_state == AC_PWRST_D3) { if (codec->depop_delay < 0) - msleep(codec->epss ? 10 : 100); + msleep(codec_has_epss(codec) ? 10 : 100); else if (codec->depop_delay > 0) msleep(codec->depop_delay); flags = HDA_RW_NO_RESPONSE_FALLBACK; @@ -3800,14 +3539,13 @@ static unsigned int hda_set_power_state(struct hda_codec *codec, */ static void sync_power_up_states(struct hda_codec *codec) { - hda_nid_t nid = codec->start_nid; - int i; + hda_nid_t nid; /* don't care if no filter is used */ if (!codec->power_filter) return; - for (i = 0; i < codec->num_nodes; i++, nid++) { + for_each_hda_codec_node(nid, codec) { unsigned int wcaps = get_wcaps(codec, nid); unsigned int target; if (!(wcaps & AC_WCAP_POWER)) @@ -3858,14 +3596,14 @@ static unsigned int hda_call_codec_suspend(struct hda_codec *codec) { unsigned int state; - atomic_inc(&codec->in_pm); + atomic_inc(&codec->core.in_pm); if (codec->patch_ops.suspend) codec->patch_ops.suspend(codec); hda_cleanup_all_streams(codec); state = hda_set_power_state(codec, AC_PWRST_D3); update_power_acct(codec, true); - atomic_dec(&codec->in_pm); + atomic_dec(&codec->core.in_pm); return state; } @@ -3890,7 +3628,7 @@ static void hda_mark_cmd_cache_dirty(struct hda_codec *codec) */ static void hda_call_codec_resume(struct hda_codec *codec) { - atomic_inc(&codec->in_pm); + atomic_inc(&codec->core.in_pm); hda_mark_cmd_cache_dirty(codec); @@ -3913,7 +3651,7 @@ static void hda_call_codec_resume(struct hda_codec *codec) hda_jackpoll_work(&codec->jackpoll_work.work); else snd_hda_jack_report_sync(codec); - atomic_dec(&codec->in_pm); + atomic_dec(&codec->core.in_pm); } static int hda_codec_runtime_suspend(struct device *dev) @@ -3926,8 +3664,9 @@ static int hda_codec_runtime_suspend(struct device *dev) list_for_each_entry(pcm, &codec->pcm_list_head, list) snd_pcm_suspend_all(pcm->pcm); state = hda_call_codec_suspend(codec); - if (codec->d3_stop_clk && codec->epss && (state & AC_PWRST_CLK_STOP_OK)) - clear_bit(codec->core.addr, &codec->bus->core.codec_powered); + if (codec_has_clkstop(codec) && codec_has_epss(codec) && + (state & AC_PWRST_CLK_STOP_OK)) + snd_hdac_codec_link_down(&codec->core); return 0; } @@ -3935,7 +3674,7 @@ static int hda_codec_runtime_resume(struct device *dev) { struct hda_codec *codec = dev_to_hda_codec(dev); - set_bit(codec->core.addr, &codec->bus->core.codec_powered); + snd_hdac_codec_link_up(&codec->core); hda_call_codec_resume(codec); pm_runtime_mark_last_busy(dev); return 0; @@ -4129,11 +3868,11 @@ static unsigned int get_pcm_param(struct hda_codec *codec, hda_nid_t nid, int dir) { unsigned int val = 0; - if (nid != codec->afg && + if (nid != codec->core.afg && (get_wcaps(codec, nid) & AC_WCAP_FORMAT_OVRD)) val = snd_hda_param_read(codec, nid, AC_PAR_PCM); if (!val || val == -1) - val = snd_hda_param_read(codec, codec->afg, AC_PAR_PCM); + val = snd_hda_param_read(codec, codec->core.afg, AC_PAR_PCM); if (!val || val == -1) return 0; return val; @@ -4150,7 +3889,7 @@ static unsigned int get_stream_param(struct hda_codec *codec, hda_nid_t nid, { unsigned int streams = snd_hda_param_read(codec, nid, AC_PAR_STREAM); if (!streams || streams == -1) - streams = snd_hda_param_read(codec, codec->afg, AC_PAR_STREAM); + streams = snd_hda_param_read(codec, codec->core.afg, AC_PAR_STREAM); if (!streams || streams == -1) return 0; return streams; @@ -4632,39 +4371,6 @@ int snd_hda_add_new_ctls(struct hda_codec *codec, EXPORT_SYMBOL_GPL(snd_hda_add_new_ctls); #ifdef CONFIG_PM -/** - * snd_hda_power_up - Power-up the codec - * @codec: HD-audio codec - * - * Increment the usage counter and resume the device if not done yet. - */ -void snd_hda_power_up(struct hda_codec *codec) -{ - struct device *dev = hda_codec_dev(codec); - - if (codec_in_pm(codec)) - return; - pm_runtime_get_sync(dev); -} -EXPORT_SYMBOL_GPL(snd_hda_power_up); - -/** - * snd_hda_power_down - Power-down the codec - * @codec: HD-audio codec - * - * Decrement the usage counter and schedules the autosuspend if none used. - */ -void snd_hda_power_down(struct hda_codec *codec) -{ - struct device *dev = hda_codec_dev(codec); - - if (codec_in_pm(codec)) - return; - pm_runtime_mark_last_busy(dev); - pm_runtime_put_autosuspend(dev); -} -EXPORT_SYMBOL_GPL(snd_hda_power_down); - static void codec_set_power_save(struct hda_codec *codec, int delay) { struct device *dev = hda_codec_dev(codec); diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index 6efcb4ad6935..e7c47a439762 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h @@ -261,24 +261,10 @@ struct hda_codec { struct hda_bus *bus; struct snd_card *card; unsigned int addr; /* codec addr*/ - - hda_nid_t afg; /* AFG node id */ - hda_nid_t mfg; /* MFG node id */ - - /* ids */ - u8 afg_function_id; - u8 mfg_function_id; - u8 afg_unsol; - u8 mfg_unsol; - u32 vendor_id; - u32 subsystem_id; - u32 revision_id; u32 probe_id; /* overridden id for probing */ /* detected preset */ const struct hda_codec_preset *preset; - const char *vendor_name; /* codec vendor name */ - const char *chip_name; /* codec chip name */ const char *modelname; /* model name for preset */ /* set by patch */ @@ -295,8 +281,6 @@ struct hda_codec { unsigned int beep_mode; /* widget capabilities cache */ - unsigned int num_nodes; - hda_nid_t start_nid; u32 *wcaps; struct snd_array mixers; /* list of assigned mixer elements */ @@ -347,14 +331,11 @@ struct hda_codec { unsigned int inv_eapd:1; /* broken h/w: inverted EAPD control */ unsigned int inv_jack_detect:1; /* broken h/w: inverted detection bit */ unsigned int pcm_format_first:1; /* PCM format must be set first */ - unsigned int epss:1; /* supporting EPSS? */ unsigned int cached_write:1; /* write only to caches */ unsigned int dp_mst:1; /* support DP1.2 Multi-stream transport */ unsigned int dump_coef:1; /* dump processing coefs in codec proc file */ unsigned int power_save_node:1; /* advanced PM for each widget */ #ifdef CONFIG_PM - unsigned int d3_stop_clk:1; /* support D3 operation without BCLK */ - atomic_t in_pm; /* suspend/resume being performed */ unsigned long power_on_acct; unsigned long power_off_acct; unsigned long power_jiffies; @@ -395,11 +376,6 @@ struct hda_codec { #define list_for_each_codec(c, bus) \ list_for_each_entry(c, &(bus)->core.codec_list, core.list) -/* direction */ -enum { - HDA_INPUT, HDA_OUTPUT -}; - /* snd_hda_codec_read/write optional flags */ #define HDA_RW_NO_RESPONSE_FALLBACK (1 << 0) @@ -422,8 +398,8 @@ int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int flags, unsigned int verb, unsigned int parm); #define snd_hda_param_read(codec, nid, param) \ snd_hda_codec_read(codec, nid, 0, AC_VERB_PARAMETERS, param) -int snd_hda_get_sub_nodes(struct hda_codec *codec, hda_nid_t nid, - hda_nid_t *start_id); +#define snd_hda_get_sub_nodes(codec, nid, start_nid) \ + snd_hdac_get_sub_nodes(&(codec)->core, nid, start_nid) int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid, hda_nid_t *conn_list, int max_conns); static inline int @@ -431,9 +407,12 @@ snd_hda_get_num_conns(struct hda_codec *codec, hda_nid_t nid) { return snd_hda_get_connections(codec, nid, NULL, 0); } -int snd_hda_get_num_raw_conns(struct hda_codec *codec, hda_nid_t nid); -int snd_hda_get_raw_connections(struct hda_codec *codec, hda_nid_t nid, - hda_nid_t *conn_list, int max_conns); + +#define snd_hda_get_raw_connections(codec, nid, list, max_conns) \ + snd_hdac_get_connections(&(codec)->core, nid, list, max_conns) +#define snd_hda_get_num_raw_conns(codec, nid) \ + snd_hdac_get_connections(&(codec)->core, nid, NULL, 0); + int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid, const hda_nid_t **listp); int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int nums, @@ -582,14 +561,12 @@ const char *snd_hda_get_jack_location(u32 cfg); /* * power saving */ +#define snd_hda_power_up(codec) snd_hdac_power_up(&(codec)->core) +#define snd_hda_power_down(codec) snd_hdac_power_down(&(codec)->core) #ifdef CONFIG_PM -void snd_hda_power_up(struct hda_codec *codec); -void snd_hda_power_down(struct hda_codec *codec); void snd_hda_set_power_save(struct hda_bus *bus, int delay); void snd_hda_update_power_acct(struct hda_codec *codec); #else -static inline void snd_hda_power_up(struct hda_codec *codec) {} -static inline void snd_hda_power_down(struct hda_codec *codec) {} static inline void snd_hda_set_power_save(struct hda_bus *bus, int delay) {} #endif diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c index 0ef2459cd05f..4850f92c89c4 100644 --- a/sound/pci/hda/hda_generic.c +++ b/sound/pci/hda/hda_generic.c @@ -654,7 +654,7 @@ static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid, int type = get_wcaps_type(get_wcaps(codec, nid)); int i, n; - if (nid == codec->afg) + if (nid == codec->core.afg) return true; for (n = 0; n < spec->paths.used; n++) { @@ -832,7 +832,7 @@ static hda_nid_t path_power_update(struct hda_codec *codec, for (i = 0; i < path->depth; i++) { nid = path->path[i]; - if (nid == codec->afg) + if (nid == codec->core.afg) continue; if (!allow_powerdown || is_active_nid_for_any(codec, nid)) state = AC_PWRST_D0; @@ -1897,12 +1897,11 @@ static void debug_show_configs(struct hda_codec *codec, static void fill_all_dac_nids(struct hda_codec *codec) { struct hda_gen_spec *spec = codec->spec; - int i; - hda_nid_t nid = codec->start_nid; + hda_nid_t nid; spec->num_all_dacs = 0; memset(spec->all_dacs, 0, sizeof(spec->all_dacs)); - for (i = 0; i < codec->num_nodes; i++, nid++) { + for_each_hda_codec_node(nid, codec) { if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT) continue; if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) { @@ -3067,10 +3066,9 @@ static int fill_adc_nids(struct hda_codec *codec) hda_nid_t nid; hda_nid_t *adc_nids = spec->adc_nids; int max_nums = ARRAY_SIZE(spec->adc_nids); - int i, nums = 0; + int nums = 0; - nid = codec->start_nid; - for (i = 0; i < codec->num_nodes; i++, nid++) { + for_each_hda_codec_node(nid, codec) { unsigned int caps = get_wcaps(codec, nid); int type = get_wcaps_type(caps); @@ -3864,8 +3862,7 @@ static void parse_digital(struct hda_codec *codec) if (spec->autocfg.dig_in_pin) { pin = spec->autocfg.dig_in_pin; - dig_nid = codec->start_nid; - for (i = 0; i < codec->num_nodes; i++, dig_nid++) { + for_each_hda_codec_node(dig_nid, codec) { unsigned int wcaps = get_wcaps(codec, dig_nid); if (get_wcaps_type(wcaps) != AC_WID_AUD_IN) continue; @@ -4706,7 +4703,7 @@ unsigned int snd_hda_gen_path_power_filter(struct hda_codec *codec, hda_nid_t nid, unsigned int power_state) { - if (power_state != AC_PWRST_D0 || nid == codec->afg) + if (power_state != AC_PWRST_D0 || nid == codec->core.afg) return power_state; if (get_wcaps_type(get_wcaps(codec, nid)) >= AC_WID_POWER) return power_state; @@ -5478,7 +5475,7 @@ int snd_hda_gen_build_pcms(struct hda_codec *codec) fill_pcm_stream_name(spec->stream_name_analog, sizeof(spec->stream_name_analog), - " Analog", codec->chip_name); + " Analog", codec->core.chip_name); info = snd_hda_codec_pcm_new(codec, "%s", spec->stream_name_analog); if (!info) return -ENOMEM; @@ -5509,7 +5506,7 @@ int snd_hda_gen_build_pcms(struct hda_codec *codec) if (spec->multiout.dig_out_nid || spec->dig_in_nid) { fill_pcm_stream_name(spec->stream_name_digital, sizeof(spec->stream_name_digital), - " Digital", codec->chip_name); + " Digital", codec->core.chip_name); info = snd_hda_codec_pcm_new(codec, "%s", spec->stream_name_digital); if (!info) @@ -5544,7 +5541,7 @@ int snd_hda_gen_build_pcms(struct hda_codec *codec) if (spec->alt_dac_nid || have_multi_adcs) { fill_pcm_stream_name(spec->stream_name_alt_analog, sizeof(spec->stream_name_alt_analog), - " Alt Analog", codec->chip_name); + " Alt Analog", codec->core.chip_name); info = snd_hda_codec_pcm_new(codec, "%s", spec->stream_name_alt_analog); if (!info) diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h index 1d001647fc47..e0db30c66e5f 100644 --- a/sound/pci/hda/hda_local.h +++ b/sound/pci/hda/hda_local.h @@ -515,15 +515,18 @@ int snd_hda_codec_get_pin_target(struct hda_codec *codec, hda_nid_t nid); int snd_hda_codec_set_pin_target(struct hda_codec *codec, hda_nid_t nid, unsigned int val); +#define for_each_hda_codec_node(nid, codec) \ + for ((nid) = (codec)->core.start_nid; (nid) < (codec)->core.end_nid; (nid)++) + /* * get widget capabilities */ static inline u32 get_wcaps(struct hda_codec *codec, hda_nid_t nid) { - if (nid < codec->start_nid || - nid >= codec->start_nid + codec->num_nodes) + if (nid < codec->core.start_nid || + nid >= codec->core.start_nid + codec->core.num_nodes) return 0; - return codec->wcaps[nid - codec->start_nid]; + return codec->wcaps[nid - codec->core.start_nid]; } /* get the widget type from widget capability bits */ @@ -547,9 +550,9 @@ static inline unsigned int get_wcaps_channels(u32 wcaps) static inline void snd_hda_override_wcaps(struct hda_codec *codec, hda_nid_t nid, u32 val) { - if (nid >= codec->start_nid && - nid < codec->start_nid + codec->num_nodes) - codec->wcaps[nid - codec->start_nid] = val; + if (nid >= codec->core.start_nid && + nid < codec->core.start_nid + codec->core.num_nodes) + codec->wcaps[nid - codec->core.start_nid] = val; } u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction); diff --git a/sound/pci/hda/hda_proc.c b/sound/pci/hda/hda_proc.c index dacfe74a2a1f..a4f5a30f1d41 100644 --- a/sound/pci/hda/hda_proc.c +++ b/sound/pci/hda/hda_proc.c @@ -289,7 +289,7 @@ static void print_pin_caps(struct snd_info_buffer *buffer, snd_iprintf(buffer, " Balanced"); if (caps & AC_PINCAP_HDMI) { /* Realtek uses this bit as a different meaning */ - if ((codec->vendor_id >> 16) == 0x10ec) + if ((codec->core.vendor_id >> 16) == 0x10ec) snd_iprintf(buffer, " R/L"); else { if (caps & AC_PINCAP_HBR) @@ -597,7 +597,7 @@ static void print_gpio(struct snd_info_buffer *buffer, struct hda_codec *codec, hda_nid_t nid) { unsigned int gpio = - snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP); + snd_hda_param_read(codec, codec->core.afg, AC_PAR_GPIO_CAP); unsigned int enable, direction, wake, unsol, sticky, data; int i, max; snd_iprintf(buffer, "GPIO: io=%d, o=%d, i=%d, " @@ -667,13 +667,9 @@ static void print_device_list(struct snd_info_buffer *buffer, } } -static void print_codec_info(struct snd_info_entry *entry, - struct snd_info_buffer *buffer) +static void print_codec_core_info(struct hdac_device *codec, + struct snd_info_buffer *buffer) { - struct hda_codec *codec = entry->private_data; - hda_nid_t nid; - int i, nodes; - snd_iprintf(buffer, "Codec: "); if (codec->vendor_name && codec->chip_name) snd_iprintf(buffer, "%s %s\n", @@ -695,29 +691,39 @@ static void print_codec_info(struct snd_info_entry *entry, snd_iprintf(buffer, "Modem Function Group: 0x%x\n", codec->mfg); else snd_iprintf(buffer, "No Modem Function Group found\n"); +} + +static void print_codec_info(struct snd_info_entry *entry, + struct snd_info_buffer *buffer) +{ + struct hda_codec *codec = entry->private_data; + hda_nid_t nid, fg; + int i, nodes; - if (! codec->afg) + print_codec_core_info(&codec->core, buffer); + fg = codec->core.afg; + if (!fg) return; snd_hda_power_up(codec); snd_iprintf(buffer, "Default PCM:\n"); - print_pcm_caps(buffer, codec, codec->afg); + print_pcm_caps(buffer, codec, fg); snd_iprintf(buffer, "Default Amp-In caps: "); - print_amp_caps(buffer, codec, codec->afg, HDA_INPUT); + print_amp_caps(buffer, codec, fg, HDA_INPUT); snd_iprintf(buffer, "Default Amp-Out caps: "); - print_amp_caps(buffer, codec, codec->afg, HDA_OUTPUT); - snd_iprintf(buffer, "State of AFG node 0x%02x:\n", codec->afg); - print_power_state(buffer, codec, codec->afg); + print_amp_caps(buffer, codec, fg, HDA_OUTPUT); + snd_iprintf(buffer, "State of AFG node 0x%02x:\n", fg); + print_power_state(buffer, codec, fg); - nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid); + nodes = snd_hda_get_sub_nodes(codec, fg, &nid); if (! nid || nodes < 0) { snd_iprintf(buffer, "Invalid AFG subtree\n"); snd_hda_power_down(codec); return; } - print_gpio(buffer, codec, codec->afg); + print_gpio(buffer, codec, fg); if (codec->proc_widget_hook) - codec->proc_widget_hook(buffer, codec, codec->afg); + codec->proc_widget_hook(buffer, codec, fg); for (i = 0; i < nodes; i++, nid++) { unsigned int wid_caps = @@ -860,7 +866,7 @@ int snd_hda_codec_proc_new(struct hda_codec *codec) struct snd_info_entry *entry; int err; - snprintf(name, sizeof(name), "codec#%d", codec->addr); + snprintf(name, sizeof(name), "codec#%d", codec->core.addr); err = snd_card_proc_new(codec->card, name, &entry); if (err < 0) return err; diff --git a/sound/pci/hda/hda_sysfs.c b/sound/pci/hda/hda_sysfs.c index 3b5ed1108f9f..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); static DEVICE_ATTR_RO(power_off_acct); #endif /* CONFIG_PM */ -#define CODEC_INFO_SHOW(type) \ +#define CODEC_INFO_SHOW(type, field) \ static ssize_t type##_show(struct device *dev, \ struct device_attribute *attr, \ char *buf) \ { \ struct hda_codec *codec = dev_get_drvdata(dev); \ - return sprintf(buf, "0x%x\n", codec->type); \ + return sprintf(buf, "0x%x\n", codec->field); \ } -#define CODEC_INFO_STR_SHOW(type) \ +#define CODEC_INFO_STR_SHOW(type, field) \ static ssize_t type##_show(struct device *dev, \ struct device_attribute *attr, \ char *buf) \ { \ struct hda_codec *codec = dev_get_drvdata(dev); \ return sprintf(buf, "%s\n", \ - codec->type ? codec->type : ""); \ + codec->field ? codec->field : ""); \ } -CODEC_INFO_SHOW(vendor_id); -CODEC_INFO_SHOW(subsystem_id); -CODEC_INFO_SHOW(revision_id); -CODEC_INFO_SHOW(afg); -CODEC_INFO_SHOW(mfg); -CODEC_INFO_STR_SHOW(vendor_name); -CODEC_INFO_STR_SHOW(chip_name); -CODEC_INFO_STR_SHOW(modelname); +CODEC_INFO_SHOW(vendor_id, core.vendor_id); +CODEC_INFO_SHOW(subsystem_id, core.subsystem_id); +CODEC_INFO_SHOW(revision_id, core.revision_id); +CODEC_INFO_SHOW(afg, core.afg); +CODEC_INFO_SHOW(mfg, core.mfg); +CODEC_INFO_STR_SHOW(vendor_name, core.vendor_name); +CODEC_INFO_STR_SHOW(chip_name, core.chip_name); +CODEC_INFO_STR_SHOW(modelname, modelname); static ssize_t pin_configs_show(struct hda_codec *codec, struct snd_array *list, @@ -170,7 +170,7 @@ static char *kstrndup_noeol(const char *src, size_t len) return s; } -#define CODEC_INFO_STORE(type) \ +#define CODEC_INFO_STORE(type, field) \ static ssize_t type##_store(struct device *dev, \ struct device_attribute *attr, \ const char *buf, size_t count) \ @@ -180,11 +180,11 @@ static ssize_t type##_store(struct device *dev, \ int err = kstrtoul(buf, 0, &val); \ if (err < 0) \ return err; \ - codec->type = val; \ + codec->field = val; \ return count; \ } -#define CODEC_INFO_STR_STORE(type) \ +#define CODEC_INFO_STR_STORE(type, field) \ static ssize_t type##_store(struct device *dev, \ struct device_attribute *attr, \ const char *buf, size_t count) \ @@ -193,17 +193,17 @@ static ssize_t type##_store(struct device *dev, \ char *s = kstrndup_noeol(buf, 64); \ if (!s) \ return -ENOMEM; \ - kfree(codec->type); \ - codec->type = s; \ + kfree(codec->field); \ + codec->field = s; \ return count; \ } -CODEC_INFO_STORE(vendor_id); -CODEC_INFO_STORE(subsystem_id); -CODEC_INFO_STORE(revision_id); -CODEC_INFO_STR_STORE(vendor_name); -CODEC_INFO_STR_STORE(chip_name); -CODEC_INFO_STR_STORE(modelname); +CODEC_INFO_STORE(vendor_id, core.vendor_id); +CODEC_INFO_STORE(subsystem_id, core.subsystem_id); +CODEC_INFO_STORE(revision_id, core.revision_id); +CODEC_INFO_STR_STORE(vendor_name, core.vendor_name); +CODEC_INFO_STR_STORE(chip_name, core.chip_name); +CODEC_INFO_STR_STORE(modelname, modelname); #define CODEC_ACTION_STORE(type) \ static ssize_t type##_store(struct device *dev, \ @@ -553,9 +553,9 @@ static void parse_codec_mode(char *buf, struct hda_bus *bus, *codecp = NULL; if (sscanf(buf, "%i %i %i", &vendorid, &subid, &caddr) == 3) { list_for_each_codec(codec, bus) { - if ((vendorid <= 0 || codec->vendor_id == vendorid) && - (subid <= 0 || codec->subsystem_id == subid) && - codec->addr == caddr) { + if ((vendorid <= 0 || codec->core.vendor_id == vendorid) && + (subid <= 0 || codec->core.subsystem_id == subid) && + codec->core.addr == caddr) { *codecp = codec; break; } @@ -595,8 +595,8 @@ static void parse_model_mode(char *buf, struct hda_bus *bus, static void parse_chip_name_mode(char *buf, struct hda_bus *bus, struct hda_codec **codecp) { - kfree((*codecp)->chip_name); - (*codecp)->chip_name = kstrdup(buf, GFP_KERNEL); + kfree((*codecp)->core.chip_name); + (*codecp)->core.chip_name = kstrdup(buf, GFP_KERNEL); } #define DEFINE_PARSE_ID_MODE(name) \ @@ -605,7 +605,7 @@ static void parse_##name##_mode(char *buf, struct hda_bus *bus, \ { \ unsigned long val; \ if (!kstrtoul(buf, 0, &val)) \ - (*codecp)->name = val; \ + (*codecp)->core.name = val; \ } DEFINE_PARSE_ID_MODE(vendor_id); 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 @@ +/* + */ + +#ifndef __HDAC_LOCAL_H +#define __HDAC_LOCAL_H + +int hdac_read_parm(struct hdac_device *codec, hda_nid_t nid, int parm); + +#define get_wcaps(codec, nid) \ + hdac_read_parm(codec, nid, AC_PAR_AUDIO_WIDGET_CAP) +/* get the widget type from widget capability bits */ +static inline int get_wcaps_type(unsigned int wcaps) +{ + if (!wcaps) + return -1; /* invalid type */ + return (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; +} + +#define get_pin_caps(codec, nid) \ + hdac_read_parm(codec, nid, AC_PAR_PIN_CAP) + +static inline +unsigned int get_pin_cfg(struct hdac_device *codec, hda_nid_t nid) +{ + unsigned int val; + + if (snd_hdac_read(codec, nid, AC_VERB_GET_CONFIG_DEFAULT, 0, &val)) + return -1; + return val; +} + +#define get_amp_caps(codec, nid, dir) \ + hdac_read_parm(codec, nid, (dir) == HDA_OUTPUT ? \ + AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP) + +#define get_power_caps(codec, nid) \ + hdac_read_parm(codec, nid, AC_PAR_POWER_STATE) + +#endif /* __HDAC_LOCAL_H */ diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c index af4c7be86c27..2278e83234b5 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, static void ad198x_power_eapd(struct hda_codec *codec) { /* We currently only handle front, HP */ - switch (codec->vendor_id) { + switch (codec->core.vendor_id) { case 0x11d41882: case 0x11d4882a: case 0x11d41884: diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c index 72d20652df50..5aff35a09fd4 100644 --- a/sound/pci/hda/patch_ca0132.c +++ b/sound/pci/hda/patch_ca0132.c @@ -4243,13 +4243,9 @@ static void ca0132_refresh_widget_caps(struct hda_codec *codec) { struct ca0132_spec *spec = codec->spec; int i; - hda_nid_t nid; codec_dbg(codec, "ca0132_refresh_widget_caps.\n"); - nid = codec->start_nid; - for (i = 0; i < codec->num_nodes; i++, nid++) - codec->wcaps[i] = snd_hda_param_read(codec, nid, - AC_PAR_AUDIO_WIDGET_CAP); + snd_hda_codec_update_widgets(codec); for (i = 0; i < spec->multiout.num_dacs; i++) refresh_amp_caps(codec, spec->dacs[i], HDA_OUTPUT); diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c index 142a6cf786da..1e21f9fbd54b 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) static void cx_auto_parse_beep(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; - hda_nid_t nid, end_nid; + hda_nid_t nid; - end_nid = codec->start_nid + codec->num_nodes; - for (nid = codec->start_nid; nid < end_nid; nid++) + for_each_hda_codec_node(nid, codec) if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) { set_beep_amp(spec, nid, 0, HDA_OUTPUT); break; @@ -120,10 +119,9 @@ static void cx_auto_parse_beep(struct hda_codec *codec) static void cx_auto_parse_eapd(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; - hda_nid_t nid, end_nid; + hda_nid_t nid; - end_nid = codec->start_nid + codec->num_nodes; - for (nid = codec->start_nid; nid < end_nid; nid++) { + for_each_hda_codec_node(nid, codec) { if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) continue; if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) @@ -848,7 +846,7 @@ static int patch_conexant_auto(struct hda_codec *codec) struct conexant_spec *spec; int err; - codec_info(codec, "%s: BIOS auto-probing.\n", codec->chip_name); + codec_info(codec, "%s: BIOS auto-probing.\n", codec->core.chip_name); spec = kzalloc(sizeof(*spec), GFP_KERNEL); if (!spec) @@ -862,7 +860,7 @@ static int patch_conexant_auto(struct hda_codec *codec) if (spec->dynamic_eapd) spec->gen.vmaster_mute.hook = cx_auto_vmaster_hook; - switch (codec->vendor_id) { + switch (codec->core.vendor_id) { case 0x14f15045: codec->single_adc_amp = 1; spec->gen.mixer_nid = 0x17; @@ -896,7 +894,7 @@ static int patch_conexant_auto(struct hda_codec *codec) * others may use EAPD really as an amp switch, so it might be * not good to expose it blindly. */ - switch (codec->subsystem_id >> 16) { + switch (codec->core.subsystem_id >> 16) { case 0x103c: spec->gen.vmaster_mute_enum = 1; break; diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c index 7e9ff7b16e56..35d92a8a99ce 100644 --- a/sound/pci/hda/patch_hdmi.c +++ b/sound/pci/hda/patch_hdmi.c @@ -45,14 +45,14 @@ static bool static_hdmi_pcm; module_param(static_hdmi_pcm, bool, 0644); MODULE_PARM_DESC(static_hdmi_pcm, "Don't restrict PCM parameters per ELD info"); -#define is_haswell(codec) ((codec)->vendor_id == 0x80862807) -#define is_broadwell(codec) ((codec)->vendor_id == 0x80862808) -#define is_skylake(codec) ((codec)->vendor_id == 0x80862809) +#define is_haswell(codec) ((codec)->core.vendor_id == 0x80862807) +#define is_broadwell(codec) ((codec)->core.vendor_id == 0x80862808) +#define is_skylake(codec) ((codec)->core.vendor_id == 0x80862809) #define is_haswell_plus(codec) (is_haswell(codec) || is_broadwell(codec) \ || is_skylake(codec)) -#define is_valleyview(codec) ((codec)->vendor_id == 0x80862882) -#define is_cherryview(codec) ((codec)->vendor_id == 0x80862883) +#define is_valleyview(codec) ((codec)->core.vendor_id == 0x80862882) +#define is_cherryview(codec) ((codec)->core.vendor_id == 0x80862883) #define is_valleyview_plus(codec) (is_valleyview(codec) || is_cherryview(codec)) struct hdmi_spec_per_cvt { @@ -1391,13 +1391,12 @@ static void intel_not_share_assigned_cvt(struct hda_codec *codec, hda_nid_t pin_nid, int mux_idx) { struct hdmi_spec *spec = codec->spec; - hda_nid_t nid, end_nid; + hda_nid_t nid; int cvt_idx, curr; struct hdmi_spec_per_cvt *per_cvt; /* configure all pins, including "no physical connection" ones */ - end_nid = codec->start_nid + codec->num_nodes; - for (nid = codec->start_nid; nid < end_nid; nid++) { + for_each_hda_codec_node(nid, codec) { unsigned int wid_caps = get_wcaps(codec, nid); unsigned int wid_type = get_wcaps_type(wid_caps); @@ -1728,7 +1727,7 @@ static int hdmi_parse_codec(struct hda_codec *codec) hda_nid_t nid; int i, nodes; - nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid); + nodes = snd_hda_get_sub_nodes(codec, codec->core.afg, &nid); if (!nid || nodes < 0) { codec_warn(codec, "HDMI: failed to get afg sub nodes\n"); return -EINVAL; @@ -2928,7 +2927,8 @@ static int patch_nvhdmi(struct hda_codec *codec) */ #define is_amdhdmi_rev3_or_later(codec) \ - ((codec)->vendor_id == 0x1002aa01 && ((codec)->revision_id & 0xff00) >= 0x0300) + ((codec)->core.vendor_id == 0x1002aa01 && \ + ((codec)->core.revision_id & 0xff00) >= 0x0300) #define has_amd_full_remap_support(codec) is_amdhdmi_rev3_or_later(codec) /* ATI/AMD specific HDA pin verbs, see the AMD HDA Verbs specification */ diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c index 124eacf67fc4..eee4532ab5f6 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) coef = alc_get_coef0(codec); - switch (codec->vendor_id) { + switch (codec->core.vendor_id) { case 0x10ec0262: alc_update_coef_idx(codec, 0x7, 0, 1<<5); break; @@ -432,7 +432,7 @@ static void alc_auto_init_amp(struct hda_codec *codec, int type) snd_hda_sequence_write(codec, alc_gpio3_init_verbs); break; case ALC_INIT_DEFAULT: - switch (codec->vendor_id) { + switch (codec->core.vendor_id) { case 0x10ec0260: alc_update_coefex_idx(codec, 0x1a, 7, 0, 0x2010); break; @@ -498,18 +498,18 @@ static int alc_auto_parse_customize_define(struct hda_codec *codec) if (!codec->bus->pci) return -1; - ass = codec->subsystem_id & 0xffff; + ass = codec->core.subsystem_id & 0xffff; if (ass != codec->bus->pci->subsystem_device && (ass & 1)) goto do_sku; nid = 0x1d; - if (codec->vendor_id == 0x10ec0260) + if (codec->core.vendor_id == 0x10ec0260) nid = 0x17; ass = snd_hda_codec_get_pincfg(codec, nid); if (!(ass & 1)) { codec_info(codec, "%s: SKU not ready 0x%08x\n", - codec->chip_name, ass); + codec->core.chip_name, ass); return -1; } @@ -585,7 +585,7 @@ static int alc_subsystem_id(struct hda_codec *codec, const hda_nid_t *ports) goto do_sku; } - ass = codec->subsystem_id & 0xffff; + ass = codec->core.subsystem_id & 0xffff; if (codec->bus->pci && ass != codec->bus->pci->subsystem_device && (ass & 1)) goto do_sku; @@ -600,7 +600,7 @@ static int alc_subsystem_id(struct hda_codec *codec, const hda_nid_t *ports) * 0 : override */ nid = 0x1d; - if (codec->vendor_id == 0x10ec0260) + if (codec->core.vendor_id == 0x10ec0260) nid = 0x17; ass = snd_hda_codec_get_pincfg(codec, nid); codec_dbg(codec, @@ -621,7 +621,7 @@ static int alc_subsystem_id(struct hda_codec *codec, const hda_nid_t *ports) return 0; do_sku: codec_dbg(codec, "realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n", - ass & 0xffff, codec->vendor_id); + ass & 0xffff, codec->core.vendor_id); /* * 0 : override * 1 : Swap Jack @@ -826,9 +826,9 @@ static const struct hda_codec_ops alc_patch_ops = { /* replace the codec chip_name with the given string */ static int alc_codec_rename(struct hda_codec *codec, const char *name) { - kfree(codec->chip_name); - codec->chip_name = kstrdup(name, GFP_KERNEL); - if (!codec->chip_name) { + kfree(codec->core.chip_name); + codec->core.chip_name = kstrdup(name, GFP_KERNEL); + if (!codec->core.chip_name) { alc_free(codec); return -ENOMEM; } @@ -904,7 +904,7 @@ static int alc_codec_rename_from_preset(struct hda_codec *codec) const struct alc_codec_rename_pci_table *q; for (p = rename_tbl; p->vendor_id; p++) { - if (p->vendor_id != codec->vendor_id) + if (p->vendor_id != codec->core.vendor_id) continue; if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits) return alc_codec_rename(codec, p->name); @@ -913,7 +913,7 @@ static int alc_codec_rename_from_preset(struct hda_codec *codec) if (!codec->bus->pci) return 0; for (q = rename_pci_tbl; q->codec_vendor_id; q++) { - if (q->codec_vendor_id != codec->vendor_id) + if (q->codec_vendor_id != codec->core.vendor_id) continue; if (q->pci_subvendor != codec->bus->pci->subsystem_vendor) continue; @@ -1785,7 +1785,7 @@ static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted) { unsigned int gpiostate, gpiomask, gpiodir; - gpiostate = snd_hda_codec_read(codec, codec->afg, 0, + gpiostate = snd_hda_codec_read(codec, codec->core.afg, 0, AC_VERB_GET_GPIO_DATA, 0); if (!muted) @@ -1793,23 +1793,23 @@ static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted) else gpiostate &= ~(1 << pin); - gpiomask = snd_hda_codec_read(codec, codec->afg, 0, + gpiomask = snd_hda_codec_read(codec, codec->core.afg, 0, AC_VERB_GET_GPIO_MASK, 0); gpiomask |= (1 << pin); - gpiodir = snd_hda_codec_read(codec, codec->afg, 0, + gpiodir = snd_hda_codec_read(codec, codec->core.afg, 0, AC_VERB_GET_GPIO_DIRECTION, 0); gpiodir |= (1 << pin); - snd_hda_codec_write(codec, codec->afg, 0, + snd_hda_codec_write(codec, codec->core.afg, 0, AC_VERB_SET_GPIO_MASK, gpiomask); - snd_hda_codec_write(codec, codec->afg, 0, + snd_hda_codec_write(codec, codec->core.afg, 0, AC_VERB_SET_GPIO_DIRECTION, gpiodir); msleep(1); - snd_hda_codec_write(codec, codec->afg, 0, + snd_hda_codec_write(codec, codec->core.afg, 0, AC_VERB_SET_GPIO_DATA, gpiostate); } @@ -2269,7 +2269,7 @@ static int patch_alc882(struct hda_codec *codec) spec = codec->spec; - switch (codec->vendor_id) { + switch (codec->core.vendor_id) { case 0x10ec0882: case 0x10ec0885: case 0x10ec0900: @@ -3067,7 +3067,7 @@ static int alc269_resume(struct hda_codec *codec) * in the driver. */ if (spec->gpio_led) - snd_hda_codec_write(codec, codec->afg, 0, AC_VERB_SET_GPIO_DATA, + snd_hda_codec_write(codec, codec->core.afg, 0, AC_VERB_SET_GPIO_DATA, spec->gpio_led); if (spec->has_alc5505_dsp) @@ -3112,8 +3112,8 @@ static void alc271_fixup_dmic(struct hda_codec *codec, }; unsigned int cfg; - if (strcmp(codec->chip_name, "ALC271X") && - strcmp(codec->chip_name, "ALC269VB")) + if (strcmp(codec->core.chip_name, "ALC271X") && + strcmp(codec->core.chip_name, "ALC269VB")) return; cfg = snd_hda_codec_get_pincfg(codec, 0x12); if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED) @@ -3479,9 +3479,9 @@ static void alc280_fixup_hp_gpio2_mic_hotkey(struct hda_codec *codec, } snd_hda_add_verbs(codec, gpio_init); - snd_hda_codec_write_cache(codec, codec->afg, 0, + snd_hda_codec_write_cache(codec, codec->core.afg, 0, AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x04); - snd_hda_jack_detect_enable_callback(codec, codec->afg, + snd_hda_jack_detect_enable_callback(codec, codec->core.afg, gpio2_mic_hotkey_event); spec->gen.vmaster_mute.hook = alc_fixup_gpio_mute_hook; @@ -3564,7 +3564,7 @@ static void alc_headset_mode_unplugged(struct hda_codec *codec) {} }; - switch (codec->vendor_id) { + switch (codec->core.vendor_id) { case 0x10ec0255: alc_process_coef_fw(codec, coef0255); break; @@ -3619,7 +3619,7 @@ static void alc_headset_mode_mic_in(struct hda_codec *codec, hda_nid_t hp_pin, {} }; - switch (codec->vendor_id) { + switch (codec->core.vendor_id) { case 0x10ec0255: alc_write_coef_idx(codec, 0x45, 0xc489); snd_hda_set_pin_ctl_cache(codec, hp_pin, 0); @@ -3688,7 +3688,7 @@ static void alc_headset_mode_default(struct hda_codec *codec) {} }; - switch (codec->vendor_id) { + switch (codec->core.vendor_id) { case 0x10ec0255: alc_process_coef_fw(codec, coef0255); break; @@ -3742,7 +3742,7 @@ static void alc_headset_mode_ctia(struct hda_codec *codec) {} }; - switch (codec->vendor_id) { + switch (codec->core.vendor_id) { case 0x10ec0255: alc_process_coef_fw(codec, coef0255); break; @@ -3796,7 +3796,7 @@ static void alc_headset_mode_omtp(struct hda_codec *codec) {} }; - switch (codec->vendor_id) { + switch (codec->core.vendor_id) { case 0x10ec0255: alc_process_coef_fw(codec, coef0255); break; @@ -3841,7 +3841,7 @@ static void alc_determine_headset_type(struct hda_codec *codec) {} }; - switch (codec->vendor_id) { + switch (codec->core.vendor_id) { case 0x10ec0255: alc_process_coef_fw(codec, coef0255); msleep(300); @@ -4078,7 +4078,7 @@ static unsigned int alc_power_filter_xps13(struct hda_codec *codec, /* Avoid pop noises when headphones are plugged in */ if (spec->gen.hp_jack_present) - if (nid == codec->afg || nid == 0x02 || nid == 0x15) + if (nid == codec->core.afg || nid == 0x02 || nid == 0x15) return AC_PWRST_D0; return power_state; } @@ -5428,7 +5428,7 @@ static int patch_alc269(struct hda_codec *codec) if (has_cdefine_beep(codec)) spec->gen.beep_nid = 0x01; - switch (codec->vendor_id) { + switch (codec->core.vendor_id) { case 0x10ec0269: spec->codec_variant = ALC269_TYPE_ALC269VA; switch (alc_get_coef0(codec) & 0x00f0) { @@ -5772,9 +5772,9 @@ static int alc662_parse_auto_config(struct hda_codec *codec) static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 }; const hda_nid_t *ssids; - if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 || - codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670 || - codec->vendor_id == 0x10ec0671) + if (codec->core.vendor_id == 0x10ec0272 || codec->core.vendor_id == 0x10ec0663 || + codec->core.vendor_id == 0x10ec0665 || codec->core.vendor_id == 0x10ec0670 || + codec->core.vendor_id == 0x10ec0671) ssids = alc663_ssids; else ssids = alc662_ssids; @@ -5819,7 +5819,7 @@ static unsigned int gpio_led_power_filter(struct hda_codec *codec, unsigned int power_state) { struct alc_spec *spec = codec->spec; - if (nid == codec->afg && power_state == AC_PWRST_D3 && spec->gpio_led) + if (nid == codec->core.afg && power_state == AC_PWRST_D3 && spec->gpio_led) return AC_PWRST_D0; return power_state; } @@ -6317,7 +6317,7 @@ static int patch_alc662(struct hda_codec *codec) alc_fix_pll_init(codec, 0x20, 0x04, 15); - switch (codec->vendor_id) { + switch (codec->core.vendor_id) { case 0x10ec0668: spec->init_hook = alc668_restore_default_value; break; @@ -6347,7 +6347,7 @@ static int patch_alc662(struct hda_codec *codec) goto error; if (!spec->gen.no_analog && spec->gen.beep_nid) { - switch (codec->vendor_id) { + switch (codec->core.vendor_id) { case 0x10ec0662: set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); break; diff --git a/sound/pci/hda/patch_si3054.c b/sound/pci/hda/patch_si3054.c index df243134baa8..49b4868797a5 100644 --- a/sound/pci/hda/patch_si3054.c +++ b/sound/pci/hda/patch_si3054.c @@ -205,8 +205,8 @@ static int si3054_build_pcms(struct hda_codec *codec) return -ENOMEM; info->stream[SNDRV_PCM_STREAM_PLAYBACK] = si3054_pcm; info->stream[SNDRV_PCM_STREAM_CAPTURE] = si3054_pcm; - info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = codec->mfg; - info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = codec->mfg; + info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = codec->core.mfg; + info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = codec->core.mfg; info->pcm_type = HDA_PCM_TYPE_MODEM; return 0; } @@ -223,7 +223,7 @@ static int si3054_init(struct hda_codec *codec) u16 val; snd_hda_codec_write(codec, AC_NODE_ROOT, 0, AC_VERB_SET_CODEC_RESET, 0); - snd_hda_codec_write(codec, codec->mfg, 0, AC_VERB_SET_STREAM_FORMAT, 0); + snd_hda_codec_write(codec, codec->core.mfg, 0, AC_VERB_SET_STREAM_FORMAT, 0); SET_REG(codec, SI3054_LINE_RATE, 9600); SET_REG(codec, SI3054_LINE_LEVEL, SI3054_DTAG_MASK|SI3054_ATAG_MASK); SET_REG(codec, SI3054_EXTENDED_MID, 0); diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c index 5b7c173adcb8..b314551749f1 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, unsigned int dir_mask, unsigned int data) { unsigned int gpiostate, gpiomask, gpiodir; + hda_nid_t fg = codec->core.afg; codec_dbg(codec, "%s msk %x dir %x gpio %x\n", __func__, mask, dir_mask, data); - gpiostate = snd_hda_codec_read(codec, codec->afg, 0, + gpiostate = snd_hda_codec_read(codec, fg, 0, AC_VERB_GET_GPIO_DATA, 0); gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask); - gpiomask = snd_hda_codec_read(codec, codec->afg, 0, + gpiomask = snd_hda_codec_read(codec, fg, 0, AC_VERB_GET_GPIO_MASK, 0); gpiomask |= mask; - gpiodir = snd_hda_codec_read(codec, codec->afg, 0, + gpiodir = snd_hda_codec_read(codec, fg, 0, AC_VERB_GET_GPIO_DIRECTION, 0); gpiodir |= dir_mask; /* Configure GPIOx as CMOS */ - snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0); + snd_hda_codec_write(codec, fg, 0, 0x7e7, 0); - snd_hda_codec_write(codec, codec->afg, 0, + snd_hda_codec_write(codec, fg, 0, AC_VERB_SET_GPIO_MASK, gpiomask); - snd_hda_codec_read(codec, codec->afg, 0, + snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */ msleep(1); - snd_hda_codec_read(codec, codec->afg, 0, + snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */ } @@ -387,7 +388,7 @@ static unsigned int stac_vref_led_power_filter(struct hda_codec *codec, hda_nid_t nid, unsigned int power_state) { - if (nid == codec->afg && power_state == AC_PWRST_D3) + if (nid == codec->core.afg && power_state == AC_PWRST_D3) return AC_PWRST_D1; return snd_hda_gen_path_power_filter(codec, nid, power_state); } @@ -432,7 +433,7 @@ static void stac_update_outputs(struct hda_codec *codec) if (spec->gpio_mute) spec->gen.master_mute = - !(snd_hda_codec_read(codec, codec->afg, 0, + !(snd_hda_codec_read(codec, codec->core.afg, 0, AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute); snd_hda_gen_update_outputs(codec); @@ -476,7 +477,7 @@ static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid, if (val != spec->power_map_bits) { spec->power_map_bits = val; if (do_write) - snd_hda_codec_write(codec, codec->afg, 0, + snd_hda_codec_write(codec, codec->core.afg, 0, AC_VERB_IDT_SET_POWER_MAP, val); } } @@ -508,7 +509,8 @@ static void jack_update_power(struct hda_codec *codec, false); } - snd_hda_codec_write(codec, codec->afg, 0, AC_VERB_IDT_SET_POWER_MAP, + snd_hda_codec_write(codec, codec->core.afg, 0, + AC_VERB_IDT_SET_POWER_MAP, spec->power_map_bits); } @@ -517,10 +519,10 @@ static void stac_vref_event(struct hda_codec *codec, { unsigned int data; - data = snd_hda_codec_read(codec, codec->afg, 0, + data = snd_hda_codec_read(codec, codec->core.afg, 0, AC_VERB_GET_GPIO_DATA, 0); /* toggle VREF state based on GPIOx status */ - snd_hda_codec_write(codec, codec->afg, 0, 0x7e0, + snd_hda_codec_write(codec, codec->core.afg, 0, 0x7e0, !!(data & (1 << event->private_data))); } @@ -622,7 +624,7 @@ static int stac_aloopback_put(struct snd_kcontrol *kcontrol, /* Only return the bits defined by the shift value of the * first two bytes of the mask */ - dac_mode = snd_hda_codec_read(codec, codec->afg, 0, + dac_mode = snd_hda_codec_read(codec, codec->core.afg, 0, kcontrol->private_value & 0xFFFF, 0x0); dac_mode >>= spec->aloopback_shift; @@ -634,7 +636,7 @@ static int stac_aloopback_put(struct snd_kcontrol *kcontrol, dac_mode &= ~idx_val; } - snd_hda_codec_write_cache(codec, codec->afg, 0, + snd_hda_codec_write_cache(codec, codec->core.afg, 0, kcontrol->private_value >> 16, dac_mode); return 1; @@ -658,11 +660,11 @@ static int stac_aloopback_put(struct snd_kcontrol *kcontrol, /* check whether it's a HP laptop with a docking port */ static bool hp_bnb2011_with_dock(struct hda_codec *codec) { - if (codec->vendor_id != 0x111d7605 && - codec->vendor_id != 0x111d76d1) + if (codec->core.vendor_id != 0x111d7605 && + codec->core.vendor_id != 0x111d76d1) return false; - switch (codec->subsystem_id) { + switch (codec->core.subsystem_id) { case 0x103c1618: case 0x103c1619: case 0x103c161a: @@ -733,7 +735,7 @@ static void set_hp_led_gpio(struct hda_codec *codec) if (spec->gpio_led) return; - gpio = snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP); + gpio = snd_hda_param_read(codec, codec->core.afg, AC_PAR_GPIO_CAP); gpio &= AC_GPIO_IO_COUNT; if (gpio > 3) spec->gpio_led = 0x08; /* GPIO 3 */ @@ -777,7 +779,7 @@ static int find_mute_led_cfg(struct hda_codec *codec, int default_polarity) &spec->gpio_led_polarity, &spec->gpio_led) == 2) { unsigned int max_gpio; - max_gpio = snd_hda_param_read(codec, codec->afg, + max_gpio = snd_hda_param_read(codec, codec->core.afg, AC_PAR_GPIO_CAP); max_gpio &= AC_GPIO_IO_COUNT; if (spec->gpio_led < max_gpio) @@ -807,7 +809,7 @@ static int find_mute_led_cfg(struct hda_codec *codec, int default_polarity) * we statically set the GPIO - if not a B-series system * and default polarity is provided */ - if (!hp_blike_system(codec->subsystem_id) && + if (!hp_blike_system(codec->core.subsystem_id) && (default_polarity == 0 || default_polarity == 1)) { set_hp_led_gpio(codec); spec->gpio_led_polarity = default_polarity; @@ -2134,7 +2136,7 @@ static void stac92hd83xxx_fixup_hp_mic_led(struct hda_codec *codec, spec->mic_mute_led_gpio = 0x08; /* GPIO3 */ #ifdef CONFIG_PM /* resetting controller clears GPIO, so we need to keep on */ - codec->d3_stop_clk = 0; + codec->core.power_caps &= ~AC_PWRST_CLKSTOP; #endif } } @@ -3031,9 +3033,9 @@ static void stac92hd71bxx_fixup_hp_m4(struct hda_codec *codec, return; /* Enable VREF power saving on GPIO1 detect */ - snd_hda_codec_write_cache(codec, codec->afg, 0, + snd_hda_codec_write_cache(codec, codec->core.afg, 0, AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02); - jack = snd_hda_jack_detect_enable_callback(codec, codec->afg, + jack = snd_hda_jack_detect_enable_callback(codec, codec->core.afg, stac_vref_event); if (!IS_ERR(jack)) jack->private_data = 0x02; @@ -3093,7 +3095,7 @@ static void stac92hd71bxx_fixup_hp(struct hda_codec *codec, if (action != HDA_FIXUP_ACT_PRE_PROBE) return; - if (hp_blike_system(codec->subsystem_id)) { + if (hp_blike_system(codec->core.subsystem_id)) { unsigned int pin_cfg = snd_hda_codec_get_pincfg(codec, 0x0f); if (get_defcfg_device(pin_cfg) == AC_JACK_LINE_OUT || get_defcfg_device(pin_cfg) == AC_JACK_SPEAKER || @@ -3792,7 +3794,7 @@ static void stac927x_fixup_dell_dmic(struct hda_codec *codec, if (action != HDA_FIXUP_ACT_PRE_PROBE) return; - if (codec->subsystem_id != 0x1028022f) { + if (codec->core.subsystem_id != 0x1028022f) { /* GPIO2 High = Enable EAPD */ spec->eapd_mask = spec->gpio_mask = 0x04; spec->gpio_dir = spec->gpio_data = 0x04; @@ -4053,9 +4055,9 @@ static void stac9205_fixup_dell_m43(struct hda_codec *codec, snd_hda_apply_pincfgs(codec, dell_9205_m43_pin_configs); /* Enable unsol response for GPIO4/Dock HP connection */ - snd_hda_codec_write_cache(codec, codec->afg, 0, + snd_hda_codec_write_cache(codec, codec->core.afg, 0, AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10); - jack = snd_hda_jack_detect_enable_callback(codec, codec->afg, + jack = snd_hda_jack_detect_enable_callback(codec, codec->core.afg, stac_vref_event); if (!IS_ERR(jack)) jack->private_data = 0x01; @@ -4302,7 +4304,7 @@ static int stac_init(struct hda_codec *codec) /* sync the power-map */ if (spec->num_pwrs) - snd_hda_codec_write(codec, codec->afg, 0, + snd_hda_codec_write(codec, codec->core.afg, 0, AC_VERB_IDT_SET_POWER_MAP, spec->power_map_bits); @@ -4338,7 +4340,7 @@ static void stac_shutup(struct hda_codec *codec) static void stac92hd_proc_hook(struct snd_info_buffer *buffer, struct hda_codec *codec, hda_nid_t nid) { - if (nid == codec->afg) + if (nid == codec->core.afg) snd_iprintf(buffer, "Power-Map: 0x%02x\n", snd_hda_codec_read(codec, nid, 0, AC_VERB_IDT_GET_POWER_MAP, 0)); @@ -4349,7 +4351,7 @@ static void analog_loop_proc_hook(struct snd_info_buffer *buffer, unsigned int verb) { snd_iprintf(buffer, "Analog Loopback: 0x%02x\n", - snd_hda_codec_read(codec, codec->afg, 0, verb, 0)); + snd_hda_codec_read(codec, codec->core.afg, 0, verb, 0)); } /* stac92hd71bxx, stac92hd73xx */ @@ -4357,21 +4359,21 @@ static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer, struct hda_codec *codec, hda_nid_t nid) { stac92hd_proc_hook(buffer, codec, nid); - if (nid == codec->afg) + if (nid == codec->core.afg) analog_loop_proc_hook(buffer, codec, 0xfa0); } static void stac9205_proc_hook(struct snd_info_buffer *buffer, struct hda_codec *codec, hda_nid_t nid) { - if (nid == codec->afg) + if (nid == codec->core.afg) analog_loop_proc_hook(buffer, codec, 0xfe0); } static void stac927x_proc_hook(struct snd_info_buffer *buffer, struct hda_codec *codec, hda_nid_t nid) { - if (nid == codec->afg) + if (nid == codec->core.afg) analog_loop_proc_hook(buffer, codec, 0xfeb); } #else @@ -4597,7 +4599,8 @@ static int patch_stac92hd83xxx(struct hda_codec *codec) if (err < 0) return err; - codec->epss = 0; /* longer delay needed for D3 */ + /* longer delay needed for D3 */ + codec->core.power_caps &= ~AC_PWRST_EPSS; spec = codec->spec; codec->power_save_node = 1; @@ -4647,7 +4650,8 @@ static int patch_stac92hd95(struct hda_codec *codec) if (err < 0) return err; - codec->epss = 0; /* longer delay needed for D3 */ + /* longer delay needed for D3 */ + codec->core.power_caps &= ~AC_PWRST_EPSS; spec = codec->spec; codec->power_save_node = 1; @@ -4706,14 +4710,14 @@ static int patch_stac92hd71bxx(struct hda_codec *codec) spec->gpio_dir = 0x01; spec->gpio_data = 0x01; - switch (codec->vendor_id) { + switch (codec->core.vendor_id) { case 0x111d76b6: /* 4 Port without Analog Mixer */ case 0x111d76b7: unmute_init++; break; case 0x111d7608: /* 5 Port with Analog Mixer */ - if ((codec->revision_id & 0xf) == 0 || - (codec->revision_id & 0xf) == 1) + if ((codec->core.revision_id & 0xf) == 0 || + (codec->core.revision_id & 0xf) == 1) spec->stream_delay = 40; /* 40 milliseconds */ /* disable VSW */ @@ -4722,7 +4726,7 @@ static int patch_stac92hd71bxx(struct hda_codec *codec) snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3); break; case 0x111d7603: /* 6 Port with Analog Mixer */ - if ((codec->revision_id & 0xf) == 1) + if ((codec->core.revision_id & 0xf) == 1) spec->stream_delay = 40; /* 40 milliseconds */ break; diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 485663bb9101..a34d7671937f 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -140,7 +140,7 @@ static struct via_spec *via_new_spec(struct hda_codec *codec) static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec) { - u32 vendor_id = codec->vendor_id; + u32 vendor_id = codec->core.vendor_id; u16 ven_id = vendor_id >> 16; u16 dev_id = vendor_id & 0xffff; enum VIA_HDA_CODEC codec_type; @@ -335,7 +335,7 @@ static void __analog_low_current_mode(struct hda_codec *codec, bool force) return; /* other codecs are not supported */ } /* send verb */ - snd_hda_codec_write(codec, codec->afg, 0, verb, parm); + snd_hda_codec_write(codec, codec->core.afg, 0, verb, parm); } static void analog_low_current_mode(struct hda_codec *codec) @@ -558,7 +558,7 @@ static int vt1708_build_pcms(struct hda_codec *codec) int i, err; err = snd_hda_gen_build_pcms(codec); - if (err < 0 || codec->vendor_id != 0x11061708) + if (err < 0 || codec->core.vendor_id != 0x11061708) return err; /* We got noisy outputs on the right channel on VT1708 when @@ -714,19 +714,19 @@ static int patch_vt1708S(struct hda_codec *codec) /* correct names for VT1708BCE */ if (get_codec_type(codec) == VT1708BCE) { - kfree(codec->chip_name); - codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL); + kfree(codec->core.chip_name); + codec->core.chip_name = kstrdup("VT1708BCE", GFP_KERNEL); snprintf(codec->card->mixername, sizeof(codec->card->mixername), - "%s %s", codec->vendor_name, codec->chip_name); + "%s %s", codec->core.vendor_name, codec->core.chip_name); } /* correct names for VT1705 */ - if (codec->vendor_id == 0x11064397) { - kfree(codec->chip_name); - codec->chip_name = kstrdup("VT1705", GFP_KERNEL); + if (codec->core.vendor_id == 0x11064397) { + kfree(codec->core.chip_name); + codec->core.chip_name = kstrdup("VT1705", GFP_KERNEL); snprintf(codec->card->mixername, sizeof(codec->card->mixername), - "%s %s", codec->vendor_name, codec->chip_name); + "%s %s", codec->core.vendor_name, codec->core.chip_name); } /* automatic parse from the BIOS config */ @@ -815,8 +815,7 @@ static int add_secret_dac_path(struct hda_codec *codec) } /* find the primary DAC and add to the connection list */ - nid = codec->start_nid; - for (i = 0; i < codec->num_nodes; i++, nid++) { + for_each_hda_codec_node(nid, codec) { unsigned int caps = get_wcaps(codec, nid); if (get_wcaps_type(caps) == AC_WID_AUD_OUT && !(caps & AC_WCAP_DIGITAL)) { 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, static bool is_thinkpad(struct hda_codec *codec) { bool found = false; - if (codec->subsystem_id >> 16 != 0x17aa) + if (codec->core.subsystem_id >> 16 != 0x17aa) return false; if (ACPI_SUCCESS(acpi_get_devices("LEN0068", acpi_check_cb, &found, NULL)) && found) return true; -- cgit v1.2.3 From 3256be6537751f65c76b3ecfbb4e667f87525a2f Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 24 Feb 2015 14:59:42 +0100 Subject: ALSA: hda - Add widget sysfs tree This patch changes the sysfs files assigned to the codec device on the bus which were formerly identical with hwdep sysfs files. Now it shows only a few core parameter, vendor_id, subsystem_id, revision_id, afg, mfg, vendor_name and chip_name. In addition, now a widget tree is added to the bus device sysfs directory for showing the widget topology and attributes. It's just a flat tree consisting of subdirectories named as the widget NID including various attributes like widget capability bits. The AFG (usually NID 0x01) is always found there, and it contains always amp_in_caps, amp_out_caps and power_caps files. Each of these attributes show a single value. The rest are the widget nodes belonging to that AFG. Note that the child node might not start from 0x02 but from another value like 0x0a. Each child node may contain caps, pin_caps, amp_in_caps, amp_out_caps, power_caps and connections files. The caps (representing the widget capability bits) always contain a value. The rest may contain value(s) if the attribute exists on the node. Only connections file show multiple values while other attributes have zero or one single value. An example of ls -R output is like below: % ls -R /sys/bus/hdaudio/devices/hdaudioC0D0/ /sys/bus/hdaudio/devices/hdaudioC0D0/widgets/: 01/ 04/ 07/ 0a/ 0d/ 10/ 13/ 16/ 19/ 1c/ 1f/ 22/ 02/ 05/ 08/ 0b/ 0e/ 11/ 14/ 17/ 1a/ 1d/ 20/ 23/ 03/ 06/ 09/ 0c/ 0f/ 12/ 15/ 18/ 1b/ 1e/ 21/ /sys/bus/hdaudio/devices/hdaudioC0D0/widgets/01: amp_in_caps amp_out_caps power_caps /sys/bus/hdaudio/devices/hdaudioC0D0/widgets/02: amp_in_caps amp_out_caps caps connections pin_caps pin_cfg power_caps /sys/bus/hdaudio/devices/hdaudioC0D0/widgets/03: ..... Signed-off-by: Takashi Iwai --- include/sound/hdaudio.h | 6 + sound/hda/Makefile | 2 +- sound/hda/hdac_device.c | 35 ++++ sound/hda/hdac_sysfs.c | 404 ++++++++++++++++++++++++++++++++++++++++++++++ sound/hda/local.h | 4 + sound/pci/hda/hda_bind.c | 4 +- sound/pci/hda/hda_codec.c | 6 +- 7 files changed, 454 insertions(+), 7 deletions(-) create mode 100644 sound/hda/hdac_sysfs.c (limited to 'sound/pci') diff --git a/include/sound/hdaudio.h b/include/sound/hdaudio.h index b81b4bec6f05..6ed2b421e29e 100644 --- a/include/sound/hdaudio.h +++ b/include/sound/hdaudio.h @@ -14,6 +14,7 @@ typedef u16 hda_nid_t; struct hdac_bus; struct hdac_device; struct hdac_driver; +struct hdac_widget_tree; /* * exported bus type @@ -53,6 +54,9 @@ struct hdac_device { /* misc flags */ atomic_t in_pm; /* suspend/resume being performed */ + + /* sysfs */ + struct hdac_widget_tree *widgets; }; /* device/driver type used for matching */ @@ -71,6 +75,8 @@ enum { int snd_hdac_device_init(struct hdac_device *dev, struct hdac_bus *bus, const char *name, unsigned int addr); void snd_hdac_device_exit(struct hdac_device *dev); +int snd_hdac_device_register(struct hdac_device *codec); +void snd_hdac_device_unregister(struct hdac_device *codec); int snd_hdac_refresh_widgets(struct hdac_device *codec); diff --git a/sound/hda/Makefile b/sound/hda/Makefile index 3c7625e595cf..ae8b5128b5c3 100644 --- a/sound/hda/Makefile +++ b/sound/hda/Makefile @@ -1,3 +1,3 @@ -snd-hda-core-objs := hda_bus_type.o hdac_bus.o hdac_device.o +snd-hda-core-objs := hda_bus_type.o hdac_bus.o hdac_device.o hdac_sysfs.o obj-$(CONFIG_SND_HDA_CORE) += snd-hda-core.o diff --git a/sound/hda/hdac_device.c b/sound/hda/hdac_device.c index a3f52ad4de37..1470ecc354db 100644 --- a/sound/hda/hdac_device.c +++ b/sound/hda/hdac_device.c @@ -45,6 +45,7 @@ int snd_hdac_device_init(struct hdac_device *codec, struct hdac_bus *bus, dev->parent = bus->dev; dev->bus = &snd_hda_bus_type; dev->release = default_release; + dev->groups = hdac_dev_attr_groups; dev_set_name(dev, "%s", name); device_enable_async_suspend(dev); @@ -127,6 +128,40 @@ void snd_hdac_device_exit(struct hdac_device *codec) } EXPORT_SYMBOL_GPL(snd_hdac_device_exit); +/** + * snd_hdac_device_register - register the hd-audio codec base device + * codec: the device to register + */ +int snd_hdac_device_register(struct hdac_device *codec) +{ + int err; + + err = device_add(&codec->dev); + if (err < 0) + return err; + err = hda_widget_sysfs_init(codec); + if (err < 0) { + device_del(&codec->dev); + return err; + } + + return 0; +} +EXPORT_SYMBOL_GPL(snd_hdac_device_register); + +/** + * snd_hdac_device_unregister - unregister the hd-audio codec base device + * codec: the device to unregister + */ +void snd_hdac_device_unregister(struct hdac_device *codec) +{ + if (device_is_registered(&codec->dev)) { + hda_widget_sysfs_exit(codec); + device_del(&codec->dev); + } +} +EXPORT_SYMBOL_GPL(snd_hdac_device_unregister); + /** * snd_hdac_make_cmd - compose a 32bit command word to be sent to the * HD-audio controller diff --git a/sound/hda/hdac_sysfs.c b/sound/hda/hdac_sysfs.c new file mode 100644 index 000000000000..b358d5157802 --- /dev/null +++ b/sound/hda/hdac_sysfs.c @@ -0,0 +1,404 @@ +/* + * sysfs support for HD-audio core device + */ + +#include +#include +#include +#include +#include +#include "local.h" + +struct hdac_widget_tree { + struct kobject *root; + struct kobject *afg; + struct kobject **nodes; +}; + +#define CODEC_ATTR(type) \ +static ssize_t type##_show(struct device *dev, \ + struct device_attribute *attr, \ + char *buf) \ +{ \ + struct hdac_device *codec = dev_to_hdac_dev(dev); \ + return sprintf(buf, "0x%x\n", codec->type); \ +} \ +static DEVICE_ATTR_RO(type) + +#define CODEC_ATTR_STR(type) \ +static ssize_t type##_show(struct device *dev, \ + struct device_attribute *attr, \ + char *buf) \ +{ \ + struct hdac_device *codec = dev_to_hdac_dev(dev); \ + return sprintf(buf, "%s\n", \ + codec->type ? codec->type : ""); \ +} \ +static DEVICE_ATTR_RO(type) + +CODEC_ATTR(vendor_id); +CODEC_ATTR(subsystem_id); +CODEC_ATTR(revision_id); +CODEC_ATTR(afg); +CODEC_ATTR(mfg); +CODEC_ATTR_STR(vendor_name); +CODEC_ATTR_STR(chip_name); + +static struct attribute *hdac_dev_attrs[] = { + &dev_attr_vendor_id.attr, + &dev_attr_subsystem_id.attr, + &dev_attr_revision_id.attr, + &dev_attr_afg.attr, + &dev_attr_mfg.attr, + &dev_attr_vendor_name.attr, + &dev_attr_chip_name.attr, + NULL +}; + +static struct attribute_group hdac_dev_attr_group = { + .attrs = hdac_dev_attrs, +}; + +const struct attribute_group *hdac_dev_attr_groups[] = { + &hdac_dev_attr_group, + NULL +}; + +/* + * Widget tree sysfs + * + * This is a tree showing the attributes of each widget. It appears like + * /sys/bus/hdaudioC0D0/widgets/04/caps + */ + +struct widget_attribute; + +struct widget_attribute { + struct attribute attr; + ssize_t (*show)(struct hdac_device *codec, hda_nid_t nid, + struct widget_attribute *attr, char *buf); + ssize_t (*store)(struct hdac_device *codec, hda_nid_t nid, + struct widget_attribute *attr, + const char *buf, size_t count); +}; + +static int get_codec_nid(struct kobject *kobj, struct hdac_device **codecp) +{ + struct device *dev = kobj_to_dev(kobj->parent->parent); + int nid; + ssize_t ret; + + ret = kstrtoint(kobj->name, 16, &nid); + if (ret < 0) + return ret; + *codecp = dev_to_hdac_dev(dev); + return nid; +} + +static ssize_t widget_attr_show(struct kobject *kobj, struct attribute *attr, + char *buf) +{ + struct widget_attribute *wid_attr = + container_of(attr, struct widget_attribute, attr); + struct hdac_device *codec; + int nid; + + if (!wid_attr->show) + return -EIO; + nid = get_codec_nid(kobj, &codec); + if (nid < 0) + return nid; + return wid_attr->show(codec, nid, wid_attr, buf); +} + +static ssize_t widget_attr_store(struct kobject *kobj, struct attribute *attr, + const char *buf, size_t count) +{ + struct widget_attribute *wid_attr = + container_of(attr, struct widget_attribute, attr); + struct hdac_device *codec; + int nid; + + if (!wid_attr->store) + return -EIO; + nid = get_codec_nid(kobj, &codec); + if (nid < 0) + return nid; + return wid_attr->store(codec, nid, wid_attr, buf, count); +} + +static const struct sysfs_ops widget_sysfs_ops = { + .show = widget_attr_show, + .store = widget_attr_store, +}; + +static void widget_release(struct kobject *kobj) +{ + kfree(kobj); +} + +static struct kobj_type widget_ktype = { + .release = widget_release, + .sysfs_ops = &widget_sysfs_ops, +}; + +#define WIDGET_ATTR_RO(_name) \ + struct widget_attribute wid_attr_##_name = __ATTR_RO(_name) +#define WIDGET_ATTR_RW(_name) \ + struct widget_attribute wid_attr_##_name = __ATTR_RW(_name) + +static ssize_t caps_show(struct hdac_device *codec, hda_nid_t nid, + struct widget_attribute *attr, char *buf) +{ + return sprintf(buf, "0x%08x\n", get_wcaps(codec, nid)); +} + +static ssize_t pin_caps_show(struct hdac_device *codec, hda_nid_t nid, + struct widget_attribute *attr, char *buf) +{ + if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) + return 0; + return sprintf(buf, "0x%08x\n", + snd_hdac_read_parm(codec, nid, AC_PAR_PIN_CAP)); +} + +static ssize_t pin_cfg_show(struct hdac_device *codec, hda_nid_t nid, + struct widget_attribute *attr, char *buf) +{ + unsigned int val; + + if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) + return 0; + if (snd_hdac_read(codec, nid, AC_VERB_GET_CONFIG_DEFAULT, 0, &val)) + return 0; + return sprintf(buf, "0x%08x\n", val); +} + +static bool has_pcm_cap(struct hdac_device *codec, hda_nid_t nid) +{ + if (nid == codec->afg || nid == codec->mfg) + return true; + switch (get_wcaps_type(get_wcaps(codec, nid))) { + case AC_WID_AUD_OUT: + case AC_WID_AUD_IN: + return true; + default: + return false; + } +} + +static ssize_t pcm_caps_show(struct hdac_device *codec, hda_nid_t nid, + struct widget_attribute *attr, char *buf) +{ + if (!has_pcm_cap(codec, nid)) + return 0; + return sprintf(buf, "0x%08x\n", + snd_hdac_read_parm(codec, nid, AC_PAR_PCM)); +} + +static ssize_t pcm_formats_show(struct hdac_device *codec, hda_nid_t nid, + struct widget_attribute *attr, char *buf) +{ + if (!has_pcm_cap(codec, nid)) + return 0; + return sprintf(buf, "0x%08x\n", + snd_hdac_read_parm(codec, nid, AC_PAR_STREAM)); +} + +static ssize_t amp_in_caps_show(struct hdac_device *codec, hda_nid_t nid, + struct widget_attribute *attr, char *buf) +{ + if (nid != codec->afg && !(get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) + return 0; + return sprintf(buf, "0x%08x\n", + snd_hdac_read_parm(codec, nid, AC_PAR_AMP_IN_CAP)); +} + +static ssize_t amp_out_caps_show(struct hdac_device *codec, hda_nid_t nid, + struct widget_attribute *attr, char *buf) +{ + if (nid != codec->afg && !(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)) + return 0; + return sprintf(buf, "0x%08x\n", + snd_hdac_read_parm(codec, nid, AC_PAR_AMP_OUT_CAP)); +} + +static ssize_t power_caps_show(struct hdac_device *codec, hda_nid_t nid, + struct widget_attribute *attr, char *buf) +{ + if (nid != codec->afg && !(get_wcaps(codec, nid) & AC_WCAP_POWER)) + return 0; + return sprintf(buf, "0x%08x\n", + snd_hdac_read_parm(codec, nid, AC_PAR_POWER_STATE)); +} + +static ssize_t gpio_caps_show(struct hdac_device *codec, hda_nid_t nid, + struct widget_attribute *attr, char *buf) +{ + return sprintf(buf, "0x%08x\n", + snd_hdac_read_parm(codec, nid, AC_PAR_GPIO_CAP)); +} + +static ssize_t connections_show(struct hdac_device *codec, hda_nid_t nid, + struct widget_attribute *attr, char *buf) +{ + hda_nid_t list[32]; + int i, nconns; + ssize_t ret = 0; + + nconns = snd_hdac_get_connections(codec, nid, list, ARRAY_SIZE(list)); + if (nconns <= 0) + return nconns; + for (i = 0; i < nconns; i++) + ret += sprintf(buf + ret, "%s0x%02x", i ? " " : "", list[i]); + ret += sprintf(buf + ret, "\n"); + return ret; +} + +static WIDGET_ATTR_RO(caps); +static WIDGET_ATTR_RO(pin_caps); +static WIDGET_ATTR_RO(pin_cfg); +static WIDGET_ATTR_RO(pcm_caps); +static WIDGET_ATTR_RO(pcm_formats); +static WIDGET_ATTR_RO(amp_in_caps); +static WIDGET_ATTR_RO(amp_out_caps); +static WIDGET_ATTR_RO(power_caps); +static WIDGET_ATTR_RO(gpio_caps); +static WIDGET_ATTR_RO(connections); + +static struct attribute *widget_node_attrs[] = { + &wid_attr_caps.attr, + &wid_attr_pin_caps.attr, + &wid_attr_pin_cfg.attr, + &wid_attr_pcm_caps.attr, + &wid_attr_pcm_formats.attr, + &wid_attr_amp_in_caps.attr, + &wid_attr_amp_out_caps.attr, + &wid_attr_power_caps.attr, + &wid_attr_connections.attr, + NULL, +}; + +static struct attribute *widget_afg_attrs[] = { + &wid_attr_pcm_caps.attr, + &wid_attr_pcm_formats.attr, + &wid_attr_amp_in_caps.attr, + &wid_attr_amp_out_caps.attr, + &wid_attr_power_caps.attr, + &wid_attr_gpio_caps.attr, + NULL, +}; + +static const struct attribute_group widget_node_group = { + .attrs = widget_node_attrs, +}; + +static const struct attribute_group widget_afg_group = { + .attrs = widget_afg_attrs, +}; + +static void free_widget_node(struct kobject *kobj, + const struct attribute_group *group) +{ + if (kobj) { + sysfs_remove_group(kobj, group); + kobject_put(kobj); + } +} + +static void widget_tree_free(struct hdac_device *codec) +{ + struct hdac_widget_tree *tree = codec->widgets; + struct kobject **p; + + if (!tree) + return; + if (tree->nodes) { + for (p = tree->nodes; *p; p++) + free_widget_node(*p, &widget_node_group); + kfree(tree->nodes); + } + free_widget_node(tree->afg, &widget_afg_group); + if (tree->root) + kobject_put(tree->root); + kfree(tree); + codec->widgets = NULL; +} + +static int add_widget_node(struct kobject *parent, hda_nid_t nid, + const struct attribute_group *group, + struct kobject **res) +{ + struct kobject *kobj = kzalloc(sizeof(*kobj), GFP_KERNEL); + int err; + + if (!kobj) + return -ENOMEM; + kobject_init(kobj, &widget_ktype); + err = kobject_add(kobj, parent, "%02x", nid); + if (err < 0) + return err; + err = sysfs_create_group(kobj, group); + if (err < 0) { + kobject_put(kobj); + return err; + } + + *res = kobj; + return 0; +} + +static int widget_tree_create(struct hdac_device *codec) +{ + struct hdac_widget_tree *tree; + int i, err; + hda_nid_t nid; + + tree = codec->widgets = kzalloc(sizeof(*tree), GFP_KERNEL); + if (!tree) + return -ENOMEM; + + tree->root = kobject_create_and_add("widgets", &codec->dev.kobj); + if (!tree->root) + return -ENOMEM; + + if (codec->afg) { + err = add_widget_node(tree->root, codec->afg, + &widget_afg_group, &tree->afg); + if (err < 0) + return err; + } + + tree->nodes = kcalloc(codec->num_nodes + 1, sizeof(*tree->nodes), + GFP_KERNEL); + if (!tree->nodes) + return -ENOMEM; + + for (i = 0, nid = codec->start_nid; i < codec->num_nodes; i++, nid++) { + err = add_widget_node(tree->root, nid, &widget_node_group, + &tree->nodes[i]); + if (err < 0) + return err; + } + + kobject_uevent(tree->root, KOBJ_CHANGE); + return 0; +} + +int hda_widget_sysfs_init(struct hdac_device *codec) +{ + int err; + + err = widget_tree_create(codec); + if (err < 0) { + widget_tree_free(codec); + return err; + } + + return 0; +} + +void hda_widget_sysfs_exit(struct hdac_device *codec) +{ + widget_tree_free(codec); +} diff --git a/sound/hda/local.h b/sound/hda/local.h index a077d1f656f6..d692f417ddc0 100644 --- a/sound/hda/local.h +++ b/sound/hda/local.h @@ -16,4 +16,8 @@ static inline int get_wcaps_type(unsigned int wcaps) return (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; } +extern const struct attribute_group *hdac_dev_attr_groups[]; +int hda_widget_sysfs_init(struct hdac_device *codec); +void hda_widget_sysfs_exit(struct hdac_device *codec); + #endif /* __HDAC_LOCAL_H */ diff --git a/sound/pci/hda/hda_bind.c b/sound/pci/hda/hda_bind.c index ad276a9771db..130f672e6f37 100644 --- a/sound/pci/hda/hda_bind.c +++ b/sound/pci/hda/hda_bind.c @@ -240,7 +240,7 @@ int snd_hda_codec_configure(struct hda_codec *codec) else codec->probe_id = 0; - err = device_add(hda_codec_dev(codec)); + err = snd_hdac_device_register(&codec->core); if (err < 0) return err; @@ -262,7 +262,7 @@ int snd_hda_codec_configure(struct hda_codec *codec) return 0; error: - device_del(hda_codec_dev(codec)); + snd_hdac_device_unregister(&codec->core); return err; } EXPORT_SYMBOL_GPL(snd_hda_codec_configure); diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index ddfc0fbbee23..b162fc40348f 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -967,8 +967,7 @@ static int snd_hda_codec_dev_free(struct snd_device *device) struct hda_codec *codec = device->device_data; codec->in_freeing = 1; - if (device_is_registered(hda_codec_dev(codec))) - device_del(hda_codec_dev(codec)); + snd_hdac_device_unregister(&codec->core); put_device(hda_codec_dev(codec)); return 0; } @@ -2182,8 +2181,7 @@ int snd_hda_codec_reset(struct hda_codec *codec) return -EBUSY; /* OK, let it free */ - if (device_is_registered(hda_codec_dev(codec))) - device_del(hda_codec_dev(codec)); + snd_hdac_device_unregister(&codec->core); /* allow device access again */ snd_hda_unlock_devices(bus); -- cgit v1.2.3 From 05852448690d7d810175f8ceccefba083525aa89 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 3 Mar 2015 15:40:08 +0100 Subject: ALSA: hda - Support indirect execution of verbs Add an overriding exec_verb op to struct hdac_device so that the call via snd_hdac_exec_verb() can switch to a different route depending on the setup. The codec driver sets this field so that it can handle the errors or applying quirks appropriately. Furthermore, this mechanism will be used for smooth transition for the regmap support in later patches. Signed-off-by: Takashi Iwai --- include/sound/hdaudio.h | 6 ++++++ sound/hda/hdac_device.c | 24 +++++++++++++++++++++++- sound/pci/hda/hda_codec.c | 12 +++++++----- 3 files changed, 36 insertions(+), 6 deletions(-) (limited to 'sound/pci') diff --git a/include/sound/hdaudio.h b/include/sound/hdaudio.h index 6ed2b421e29e..675614dc2b88 100644 --- a/include/sound/hdaudio.h +++ b/include/sound/hdaudio.h @@ -48,6 +48,10 @@ struct hdac_device { const char *vendor_name; /* codec vendor name */ const char *chip_name; /* codec chip name */ + /* verb exec op override */ + int (*exec_verb)(struct hdac_device *dev, unsigned int cmd, + unsigned int flags, unsigned int *res); + /* widgets */ unsigned int num_nodes; hda_nid_t start_nid, end_nid; @@ -82,6 +86,8 @@ int snd_hdac_refresh_widgets(struct hdac_device *codec); unsigned int snd_hdac_make_cmd(struct hdac_device *codec, hda_nid_t nid, unsigned int verb, unsigned int parm); +int snd_hdac_exec_verb(struct hdac_device *codec, unsigned int cmd, + unsigned int flags, unsigned int *res); int snd_hdac_read(struct hdac_device *codec, hda_nid_t nid, unsigned int verb, unsigned int parm, unsigned int *res); int snd_hdac_read_parm(struct hdac_device *codec, hda_nid_t nid, int parm); diff --git a/sound/hda/hdac_device.c b/sound/hda/hdac_device.c index 1470ecc354db..aaece36247e7 100644 --- a/sound/hda/hdac_device.c +++ b/sound/hda/hdac_device.c @@ -193,6 +193,28 @@ unsigned int snd_hdac_make_cmd(struct hdac_device *codec, hda_nid_t nid, } EXPORT_SYMBOL_GPL(snd_hdac_make_cmd); +/** + * snd_hdac_exec_verb - execute an encoded verb + * @codec: the codec object + * @cmd: encoded verb to execute + * @flags: optional flags, pass zero for default + * @res: the pointer to store the result, NULL if running async + * + * Returns zero if successful, or a negative error code. + * + * This calls the exec_verb op when set in hdac_codec. If not, + * call the default snd_hdac_bus_exec_verb(). + */ +int snd_hdac_exec_verb(struct hdac_device *codec, unsigned int cmd, + unsigned int flags, unsigned int *res) +{ + if (codec->exec_verb) + return codec->exec_verb(codec, cmd, flags, res); + return snd_hdac_bus_exec_verb(codec->bus, codec->addr, cmd, res); +} +EXPORT_SYMBOL_GPL(snd_hdac_exec_verb); + + /** * snd_hdac_read - execute a verb * @codec: the codec object @@ -208,7 +230,7 @@ int snd_hdac_read(struct hdac_device *codec, hda_nid_t nid, { unsigned int cmd = snd_hdac_make_cmd(codec, nid, verb, parm); - return snd_hdac_bus_exec_verb(codec->bus, codec->addr, cmd, res); + return snd_hdac_exec_verb(codec, cmd, 0, res); } EXPORT_SYMBOL_GPL(snd_hdac_read); diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index b162fc40348f..36483f7dd3ce 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -124,11 +124,12 @@ const char *snd_hda_get_jack_type(u32 cfg) EXPORT_SYMBOL_GPL(snd_hda_get_jack_type); /* - * Send and receive a verb + * Send and receive a verb - passed to exec_verb override for hdac_device */ -static int codec_exec_verb(struct hda_codec *codec, unsigned int cmd, - int flags, unsigned int *res) +static int codec_exec_verb(struct hdac_device *dev, unsigned int cmd, + unsigned int flags, unsigned int *res) { + struct hda_codec *codec = container_of(dev, struct hda_codec, core); struct hda_bus *bus = codec->bus; int err; @@ -177,7 +178,7 @@ unsigned int snd_hda_codec_read(struct hda_codec *codec, hda_nid_t nid, { unsigned int cmd = snd_hdac_make_cmd(&codec->core, nid, verb, parm); unsigned int res; - if (codec_exec_verb(codec, cmd, flags, &res)) + if (snd_hdac_exec_verb(&codec->core, cmd, flags, &res)) return -1; return res; } @@ -199,7 +200,7 @@ int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int flags, unsigned int verb, unsigned int parm) { unsigned int cmd = snd_hdac_make_cmd(&codec->core, nid, verb, parm); - return codec_exec_verb(codec, cmd, flags, NULL); + return snd_hdac_exec_verb(&codec->core, cmd, flags, NULL); } EXPORT_SYMBOL_GPL(snd_hda_codec_write); @@ -1026,6 +1027,7 @@ int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card, codec->core.dev.release = snd_hda_codec_dev_release; codec->core.type = HDA_DEV_LEGACY; + codec->core.exec_verb = codec_exec_verb; codec->bus = bus; codec->card = card; -- cgit v1.2.3 From c4c2533f802d6877803c4d778def43d8a122f27b Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 3 Mar 2015 17:22:12 +0100 Subject: ALSA: hda - Fix possible runtime PM refcount unbalance When the driver is unloaded before the codec is bound, it still keeps the runtime PM refcount up, and results in the unbalance. This patch covers these cases by introducing a flag indicating the runtime PM initialization and handling the codec registration procedure more properly. It also fixes the missing input beep device as a gratis, too. Signed-off-by: Takashi Iwai --- sound/hda/hdac_device.c | 3 +-- sound/pci/hda/hda_bind.c | 1 + sound/pci/hda/hda_codec.c | 30 ++++++++++++++++++++++-------- sound/pci/hda/hda_codec.h | 1 + sound/pci/hda/hda_local.h | 1 + 5 files changed, 26 insertions(+), 10 deletions(-) (limited to 'sound/pci') diff --git a/sound/hda/hdac_device.c b/sound/hda/hdac_device.c index aaece36247e7..6e8ee1d6974a 100644 --- a/sound/hda/hdac_device.c +++ b/sound/hda/hdac_device.c @@ -109,7 +109,6 @@ int snd_hdac_device_init(struct hdac_device *codec, struct hdac_bus *bus, return 0; error: - pm_runtime_put_noidle(&codec->dev); put_device(&codec->dev); return err; } @@ -121,7 +120,7 @@ EXPORT_SYMBOL_GPL(snd_hdac_device_init); */ void snd_hdac_device_exit(struct hdac_device *codec) { - /* pm_runtime_put_noidle(&codec->dev); */ + pm_runtime_put_noidle(&codec->dev); snd_hdac_bus_remove_device(codec->bus, codec); kfree(codec->vendor_name); kfree(codec->chip_name); diff --git a/sound/pci/hda/hda_bind.c b/sound/pci/hda/hda_bind.c index 130f672e6f37..7b269c3237e3 100644 --- a/sound/pci/hda/hda_bind.c +++ b/sound/pci/hda/hda_bind.c @@ -95,6 +95,7 @@ static int hda_codec_driver_probe(struct device *dev) err = snd_card_register(codec->card); if (err < 0) goto error_module; + snd_hda_codec_register(codec); } return 0; diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 36483f7dd3ce..145cae7903b6 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -912,6 +912,13 @@ static void codec_release_pcms(struct hda_codec *codec) void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec) { + if (codec->registered) { + /* pm_runtime_put() is called in snd_hdac_device_exit() */ + pm_runtime_get_noresume(hda_codec_dev(codec)); + pm_runtime_disable(hda_codec_dev(codec)); + codec->registered = 0; + } + cancel_delayed_work_sync(&codec->jackpoll_work); if (!codec->in_freeing) snd_hda_ctls_clear(codec); @@ -943,15 +950,23 @@ void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec) static unsigned int hda_set_power_state(struct hda_codec *codec, unsigned int power_state); -static int snd_hda_codec_dev_register(struct snd_device *device) +/* also called from hda_bind.c */ +void snd_hda_codec_register(struct hda_codec *codec) { - struct hda_codec *codec = device->device_data; - - snd_hda_register_beep_device(codec); - if (device_is_registered(hda_codec_dev(codec))) + if (codec->registered) + return; + if (device_is_registered(hda_codec_dev(codec))) { + snd_hda_register_beep_device(codec); pm_runtime_enable(hda_codec_dev(codec)); - /* it was powered up in snd_hda_codec_new(), now all done */ - snd_hda_power_down(codec); + /* it was powered up in snd_hda_codec_new(), now all done */ + snd_hda_power_down(codec); + codec->registered = 1; + } +} + +static int snd_hda_codec_dev_register(struct snd_device *device) +{ + snd_hda_codec_register(device->device_data); return 0; } @@ -1094,7 +1109,6 @@ int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card, return 0; error: - pm_runtime_put_noidle(hda_codec_dev(codec)); put_device(hda_codec_dev(codec)); return err; } diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index e7c47a439762..76776164623d 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h @@ -314,6 +314,7 @@ struct hda_codec { /* misc flags */ unsigned int in_freeing:1; /* being released */ + unsigned int registered:1; /* codec was registered */ unsigned int spdif_status_reset :1; /* needs to toggle SPDIF for each * status change * (e.g. Realtek codecs) diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h index e0db30c66e5f..8a83775e0e27 100644 --- a/sound/pci/hda/hda_local.h +++ b/sound/pci/hda/hda_local.h @@ -150,6 +150,7 @@ int __snd_hda_add_vmaster(struct hda_codec *codec, char *name, #define snd_hda_add_vmaster(codec, name, tlv, slaves, suffix) \ __snd_hda_add_vmaster(codec, name, tlv, slaves, suffix, true, NULL) int snd_hda_codec_reset(struct hda_codec *codec); +void snd_hda_codec_register(struct hda_codec *codec); void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec); enum { -- cgit v1.2.3 From e311782acd196d17d25b323d115709c50c8f7d3f Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 10 Mar 2015 15:16:28 +0100 Subject: ALSA: hda - Re-add tracepoints to HD-audio core driver Now let's take the basic tracepoints back to the HD-audio driver. The three bus tracepoints, hda_send_cmd, hda_get_response and hda_unsol_event are revived but in a slightly different form. Since we don't assign the card number there, print the bus device name instead. Signed-off-by: Takashi Iwai --- sound/hda/Makefile | 3 ++ sound/hda/hdac_bus.c | 7 ++- sound/hda/trace.c | 6 +++ sound/hda/trace.h | 62 ++++++++++++++++++++++++ sound/pci/hda/Makefile | 1 - sound/pci/hda/hda_trace.h | 119 ---------------------------------------------- 6 files changed, 77 insertions(+), 121 deletions(-) create mode 100644 sound/hda/trace.c create mode 100644 sound/hda/trace.h delete mode 100644 sound/pci/hda/hda_trace.h (limited to 'sound/pci') diff --git a/sound/hda/Makefile b/sound/hda/Makefile index ae8b5128b5c3..eec5da03b41f 100644 --- a/sound/hda/Makefile +++ b/sound/hda/Makefile @@ -1,3 +1,6 @@ snd-hda-core-objs := hda_bus_type.o hdac_bus.o hdac_device.o hdac_sysfs.o +snd-hda-core-objs += trace.o +CFLAGS_trace.o := -I$(src) + obj-$(CONFIG_SND_HDA_CORE) += snd-hda-core.o diff --git a/sound/hda/hdac_bus.c b/sound/hda/hdac_bus.c index 364f64c0e4a3..8e262da74f6a 100644 --- a/sound/hda/hdac_bus.c +++ b/sound/hda/hdac_bus.c @@ -7,6 +7,7 @@ #include #include #include +#include "trace.h" static void process_unsol_events(struct work_struct *work); @@ -82,6 +83,7 @@ int snd_hdac_bus_exec_verb_unlocked(struct hdac_bus *bus, unsigned int addr, else if (bus->sync_write) res = &tmp; for (;;) { + trace_hda_send_cmd(bus, cmd); err = bus->ops->command(bus, cmd); if (err != -EAGAIN) break; @@ -90,8 +92,10 @@ int snd_hdac_bus_exec_verb_unlocked(struct hdac_bus *bus, unsigned int addr, if (err) break; } - if (!err && res) + if (!err && res) { err = bus->ops->get_response(bus, addr, res); + trace_hda_get_response(bus, addr, *res); + } return err; } EXPORT_SYMBOL_GPL(snd_hdac_bus_exec_verb_unlocked); @@ -113,6 +117,7 @@ void snd_hdac_bus_queue_event(struct hdac_bus *bus, u32 res, u32 res_ex) if (!bus) return; + trace_hda_unsol_event(bus, res, res_ex); wp = (bus->unsol_wp + 1) % HDA_UNSOL_QUEUE_SIZE; bus->unsol_wp = wp; 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 @@ +/* + * tracepoint definitions for HD-audio core drivers + */ + +#define CREATE_TRACE_POINTS +#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 @@ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM hda + +#if !defined(__HDAC_TRACE_H) || defined(TRACE_HEADER_MULTI_READ) +#define __HDAC_TRACE_H + +#include +#include +#include + +#ifndef HDAC_MSG_MAX +#define HDAC_MSG_MAX 500 +#endif + +struct hdac_bus; +struct hdac_codec; + +TRACE_EVENT(hda_send_cmd, + TP_PROTO(struct hdac_bus *bus, unsigned int cmd), + TP_ARGS(bus, cmd), + TP_STRUCT__entry(__dynamic_array(char, msg, HDAC_MSG_MAX)), + TP_fast_assign( + snprintf(__get_str(msg), HDAC_MSG_MAX, + "[%s:%d] val=0x%08x", + dev_name((bus)->dev), (cmd) >> 28, cmd); + ), + TP_printk("%s", __get_str(msg)) +); + +TRACE_EVENT(hda_get_response, + TP_PROTO(struct hdac_bus *bus, unsigned int addr, unsigned int res), + TP_ARGS(bus, addr, res), + TP_STRUCT__entry(__dynamic_array(char, msg, HDAC_MSG_MAX)), + TP_fast_assign( + snprintf(__get_str(msg), HDAC_MSG_MAX, + "[%s:%d] val=0x%08x", + dev_name((bus)->dev), addr, res); + ), + TP_printk("%s", __get_str(msg)) +); + +TRACE_EVENT(hda_unsol_event, + TP_PROTO(struct hdac_bus *bus, u32 res, u32 res_ex), + TP_ARGS(bus, res, res_ex), + TP_STRUCT__entry(__dynamic_array(char, msg, HDAC_MSG_MAX)), + TP_fast_assign( + snprintf(__get_str(msg), HDAC_MSG_MAX, + "[%s:%d] res=0x%08x, res_ex=0x%08x", + dev_name((bus)->dev), res_ex & 0x0f, res, res_ex); + ), + TP_printk("%s", __get_str(msg)) +); +#endif /* __HDAC_TRACE_H */ + +/* This part must be outside protection */ +#undef TRACE_INCLUDE_PATH +#define TRACE_INCLUDE_PATH . + +#undef TRACE_INCLUDE_FILE +#define TRACE_INCLUDE_FILE trace + +#include diff --git a/sound/pci/hda/Makefile b/sound/pci/hda/Makefile index 96caaebfc19d..af78fb33a4fd 100644 --- a/sound/pci/hda/Makefile +++ b/sound/pci/hda/Makefile @@ -10,7 +10,6 @@ snd-hda-codec-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o snd-hda-codec-$(CONFIG_SND_HDA_INPUT_BEEP) += hda_beep.o # for trace-points -CFLAGS_hda_codec.o := -I$(src) CFLAGS_hda_controller.o := -I$(src) snd-hda-codec-generic-objs := hda_generic.o diff --git a/sound/pci/hda/hda_trace.h b/sound/pci/hda/hda_trace.h deleted file mode 100644 index 7fedfa862419..000000000000 --- a/sound/pci/hda/hda_trace.h +++ /dev/null @@ -1,119 +0,0 @@ -#undef TRACE_SYSTEM -#define TRACE_SYSTEM hda -#define TRACE_INCLUDE_FILE hda_trace - -#if !defined(_TRACE_HDA_H) || defined(TRACE_HEADER_MULTI_READ) -#define _TRACE_HDA_H - -#include - -struct hda_bus; -struct hda_codec; - -DECLARE_EVENT_CLASS(hda_cmd, - - TP_PROTO(struct hda_codec *codec, unsigned int val), - - TP_ARGS(codec, val), - - TP_STRUCT__entry( - __field( unsigned int, card ) - __field( unsigned int, addr ) - __field( unsigned int, val ) - ), - - TP_fast_assign( - __entry->card = (codec)->card->number; - __entry->addr = (codec)->addr; - __entry->val = (val); - ), - - TP_printk("[%d:%d] val=%x", __entry->card, __entry->addr, __entry->val) -); - -DEFINE_EVENT(hda_cmd, hda_send_cmd, - TP_PROTO(struct hda_codec *codec, unsigned int val), - TP_ARGS(codec, val) -); - -DEFINE_EVENT(hda_cmd, hda_get_response, - TP_PROTO(struct hda_codec *codec, unsigned int val), - TP_ARGS(codec, val) -); - -TRACE_EVENT(hda_bus_reset, - - TP_PROTO(struct hda_bus *bus), - - TP_ARGS(bus), - - TP_STRUCT__entry( - __field( unsigned int, card ) - ), - - TP_fast_assign( - __entry->card = (bus)->card->number; - ), - - TP_printk("[%d]", __entry->card) -); - -#ifdef CONFIG_PM -DECLARE_EVENT_CLASS(hda_power, - - TP_PROTO(struct hda_codec *codec), - - TP_ARGS(codec), - - TP_STRUCT__entry( - __field( unsigned int, card ) - __field( unsigned int, addr ) - ), - - TP_fast_assign( - __entry->card = (codec)->card->number; - __entry->addr = (codec)->addr; - ), - - TP_printk("[%d:%d]", __entry->card, __entry->addr) -); - -DEFINE_EVENT(hda_power, hda_power_down, - TP_PROTO(struct hda_codec *codec), - TP_ARGS(codec) -); - -DEFINE_EVENT(hda_power, hda_power_up, - TP_PROTO(struct hda_codec *codec), - TP_ARGS(codec) -); -#endif /* CONFIG_PM */ - -TRACE_EVENT(hda_unsol_event, - - TP_PROTO(struct hda_bus *bus, u32 res, u32 res_ex), - - TP_ARGS(bus, res, res_ex), - - TP_STRUCT__entry( - __field( unsigned int, card ) - __field( u32, res ) - __field( u32, res_ex ) - ), - - TP_fast_assign( - __entry->card = (bus)->card->number; - __entry->res = res; - __entry->res_ex = res_ex; - ), - - TP_printk("[%d] res=%x, res_ex=%x", __entry->card, - __entry->res, __entry->res_ex) -); - -#endif /* _TRACE_HDA_H */ - -/* This part must be outside protection */ -#undef TRACE_INCLUDE_PATH -#define TRACE_INCLUDE_PATH . -#include -- cgit v1.2.3 From 71fc4c7ef5ef2d0ddd22f0545ede4c135b554b84 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 3 Mar 2015 17:33:10 +0100 Subject: ALSA: hda - Move generic array helpers to core lib This will be used by the regmap support. Signed-off-by: Takashi Iwai --- include/sound/hdaudio.h | 33 +++++++++++++++++++++++++++++++ sound/hda/Makefile | 3 ++- sound/hda/array.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++ sound/pci/hda/hda_codec.c | 46 -------------------------------------------- sound/pci/hda/hda_codec.h | 30 ----------------------------- 5 files changed, 84 insertions(+), 77 deletions(-) create mode 100644 sound/hda/array.c (limited to 'sound/pci') diff --git a/include/sound/hdaudio.h b/include/sound/hdaudio.h index 675614dc2b88..3abdd3f16528 100644 --- a/include/sound/hdaudio.h +++ b/include/sound/hdaudio.h @@ -21,6 +21,17 @@ struct hdac_widget_tree; */ extern struct bus_type snd_hda_bus_type; +/* + * generic arrays + */ +struct snd_array { + unsigned int used; + unsigned int alloced; + unsigned int elem_size; + unsigned int alloc_align; + void *list; +}; + /* * HD-audio codec base device */ @@ -178,4 +189,26 @@ static inline void snd_hdac_codec_link_down(struct hdac_device *codec) clear_bit(codec->addr, &codec->bus->codec_powered); } +/* + * generic array helpers + */ +void *snd_array_new(struct snd_array *array); +void snd_array_free(struct snd_array *array); +static inline void snd_array_init(struct snd_array *array, unsigned int size, + unsigned int align) +{ + array->elem_size = size; + array->alloc_align = align; +} + +static inline void *snd_array_elem(struct snd_array *array, unsigned int idx) +{ + return array->list + idx * array->elem_size; +} + +static inline unsigned int snd_array_index(struct snd_array *array, void *ptr) +{ + return (unsigned long)(ptr - array->list) / array->elem_size; +} + #endif /* __SOUND_HDAUDIO_H */ diff --git a/sound/hda/Makefile b/sound/hda/Makefile index eec5da03b41f..e508ba1102cb 100644 --- a/sound/hda/Makefile +++ b/sound/hda/Makefile @@ -1,4 +1,5 @@ -snd-hda-core-objs := hda_bus_type.o hdac_bus.o hdac_device.o hdac_sysfs.o +snd-hda-core-objs := hda_bus_type.o hdac_bus.o hdac_device.o hdac_sysfs.o \ + array.o snd-hda-core-objs += trace.o CFLAGS_trace.o := -I$(src) 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 @@ +/* + * generic arrays + */ + +#include +#include +#include + +/** + * snd_array_new - get a new element from the given array + * @array: the array object + * + * Get a new element from the given array. If it exceeds the + * pre-allocated array size, re-allocate the array. + * + * Returns NULL if allocation failed. + */ +void *snd_array_new(struct snd_array *array) +{ + if (snd_BUG_ON(!array->elem_size)) + return NULL; + if (array->used >= array->alloced) { + int num = array->alloced + array->alloc_align; + int size = (num + 1) * array->elem_size; + void *nlist; + if (snd_BUG_ON(num >= 4096)) + return NULL; + nlist = krealloc(array->list, size, GFP_KERNEL | __GFP_ZERO); + if (!nlist) + return NULL; + array->list = nlist; + array->alloced = num; + } + return snd_array_elem(array, array->used++); +} +EXPORT_SYMBOL_GPL(snd_array_new); + +/** + * snd_array_free - free the given array elements + * @array: the array object + */ +void snd_array_free(struct snd_array *array) +{ + kfree(array->list); + array->used = 0; + array->alloced = 0; + array->list = NULL; +} +EXPORT_SYMBOL_GPL(snd_array_free); diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 145cae7903b6..10e257ff9084 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -5012,52 +5012,6 @@ void snd_hda_bus_reset(struct hda_bus *bus) } EXPORT_SYMBOL_GPL(snd_hda_bus_reset); -/* - * generic arrays - */ - -/** - * snd_array_new - get a new element from the given array - * @array: the array object - * - * Get a new element from the given array. If it exceeds the - * pre-allocated array size, re-allocate the array. - * - * Returns NULL if allocation failed. - */ -void *snd_array_new(struct snd_array *array) -{ - if (snd_BUG_ON(!array->elem_size)) - return NULL; - if (array->used >= array->alloced) { - int num = array->alloced + array->alloc_align; - int size = (num + 1) * array->elem_size; - void *nlist; - if (snd_BUG_ON(num >= 4096)) - return NULL; - nlist = krealloc(array->list, size, GFP_KERNEL | __GFP_ZERO); - if (!nlist) - return NULL; - array->list = nlist; - array->alloced = num; - } - return snd_array_elem(array, array->used++); -} -EXPORT_SYMBOL_GPL(snd_array_new); - -/** - * snd_array_free - free the given array elements - * @array: the array object - */ -void snd_array_free(struct snd_array *array) -{ - kfree(array->list); - array->used = 0; - array->alloced = 0; - array->list = NULL; -} -EXPORT_SYMBOL_GPL(snd_array_free); - /** * snd_print_pcm_bits - Print the supported PCM fmt bits to the string buffer * @pcm: PCM caps bits diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index 76776164623d..3068163b3db2 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h @@ -29,36 +29,6 @@ #include #include -/* - * generic arrays - */ -struct snd_array { - unsigned int used; - unsigned int alloced; - unsigned int elem_size; - unsigned int alloc_align; - void *list; -}; - -void *snd_array_new(struct snd_array *array); -void snd_array_free(struct snd_array *array); -static inline void snd_array_init(struct snd_array *array, unsigned int size, - unsigned int align) -{ - array->elem_size = size; - array->alloc_align = align; -} - -static inline void *snd_array_elem(struct snd_array *array, unsigned int idx) -{ - return array->list + idx * array->elem_size; -} - -static inline unsigned int snd_array_index(struct snd_array *array, void *ptr) -{ - return (unsigned long)(ptr - array->list) / array->elem_size; -} - /* * Structures */ -- cgit v1.2.3 From 4d75faa0448a6bb2fd6d56051a3675a3937cbada Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Wed, 25 Feb 2015 14:42:38 +0100 Subject: ALSA: hda - Add regmap support This patch adds an infrastructure to support regmap-based verb accesses. Because o the asymmetric nature of HD-audio verbs, especially the amp verbs, we need to translate the verbs as a sort of pseudo registers to be mapped uniquely in regmap. In this patch, a pseudo register is built from the NID, the AC_VERB_GET_* and 8bit parameters, i.e. almost in the form to be sent to HD-audio bus but without codec address field. OTOH, for writing, the same pseudo register is translated to AC_VERB_SET_* automatically. The AC_VERB_SET_AMP_* verb is re-encoded from the corresponding AC_VERB_GET_AMP_* verb and parameter at writing. Some verbs has a single command for read but multiple for writes. A write for such a verb is split automatically to multiple verbs. The patch provides also a few handy helper functions. They are designed to be accessible even without regmap. When no regmap is set up (e.g. before the codec device instantiation), the direct hardware access is used. Also, it tries to avoid the unnecessary power-up. The power up/down sequence is performed only on demand. The codec driver needs to call snd_hdac_regmap_exit() and snd_hdac_regmap_exit() at probe and remove if it wants the regmap access. There is one flag added to hdac_device. When the flag lazy_cache is set, regmap helper ignores a write for a suspended device and returns as if it was actually written. It reduces the hardware access pretty much, e.g. when adjusting the mixer volume while in idle. This assumes that the driver will sync the cache later at resume properly, so use it carefully. Signed-off-by: Takashi Iwai --- include/sound/hda_regmap.h | 145 +++++++++++++++++++++ include/sound/hdaudio.h | 4 + sound/hda/Kconfig | 1 + sound/hda/Makefile | 2 +- sound/hda/hdac_regmap.c | 304 +++++++++++++++++++++++++++++++++++++++++++++ sound/pci/hda/hda_bind.c | 4 + sound/pci/hda/hda_codec.c | 1 + sound/pci/hda/hda_codec.h | 1 + 8 files changed, 461 insertions(+), 1 deletion(-) create mode 100644 include/sound/hda_regmap.h create mode 100644 sound/hda/hdac_regmap.c (limited to 'sound/pci') diff --git a/include/sound/hda_regmap.h b/include/sound/hda_regmap.h new file mode 100644 index 000000000000..95651d26437d --- /dev/null +++ b/include/sound/hda_regmap.h @@ -0,0 +1,145 @@ +/* + * HD-audio regmap helpers + */ + +#ifndef __SOUND_HDA_REGMAP_H +#define __SOUND_HDA_REGMAP_H + +#include +#include +#include + +int snd_hdac_regmap_init(struct hdac_device *codec); +void snd_hdac_regmap_exit(struct hdac_device *codec); + +int snd_hdac_regmap_read_raw(struct hdac_device *codec, unsigned int reg, + unsigned int *val); +int snd_hdac_regmap_write_raw(struct hdac_device *codec, unsigned int reg, + unsigned int val); +int snd_hdac_regmap_update_raw(struct hdac_device *codec, unsigned int reg, + unsigned int mask, unsigned int val); + +/** + * snd_hdac_regmap_encode_verb - encode the verb to a pseudo register + * @nid: widget NID + * @verb: codec verb + * + * Returns an encoded pseudo register. + */ +#define snd_hdac_regmap_encode_verb(nid, verb) \ + (((verb) << 8) | 0x80000 | ((unsigned int)(nid) << 20)) + +/** + * snd_hdac_regmap_encode_amp - encode the AMP verb to a pseudo register + * @nid: widget NID + * @ch: channel (left = 0, right = 1) + * @dir: direction (#HDA_INPUT, #HDA_OUTPUT) + * @idx: input index value + * + * Returns an encoded pseudo register. + */ +#define snd_hdac_regmap_encode_amp(nid, ch, dir, idx) \ + (snd_hdac_regmap_encode_verb(nid, AC_VERB_GET_AMP_GAIN_MUTE) | \ + ((ch) ? AC_AMP_GET_RIGHT : AC_AMP_GET_LEFT) | \ + ((dir) == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT) | \ + (idx)) + +/** + * snd_hdac_regmap_write - Write a verb with caching + * @nid: codec NID + * @reg: verb to write + * @val: value to write + * + * For writing an amp value, use snd_hda_regmap_amp_update(). + */ +static inline int +snd_hdac_regmap_write(struct hdac_device *codec, hda_nid_t nid, + unsigned int verb, unsigned int val) +{ + unsigned int cmd = snd_hdac_regmap_encode_verb(nid, verb); + + return snd_hdac_regmap_write_raw(codec, cmd, val); +} + +/** + * snd_hda_regmap_update - Update a verb value with caching + * @nid: codec NID + * @verb: verb to update + * @mask: bit mask to update + * @val: value to update + * + * For updating an amp value, use snd_hda_regmap_amp_update(). + */ +static inline int +snd_hdac_regmap_update(struct hdac_device *codec, hda_nid_t nid, + unsigned int verb, unsigned int mask, + unsigned int val) +{ + unsigned int cmd = snd_hdac_regmap_encode_verb(nid, verb); + + return snd_hdac_regmap_update_raw(codec, cmd, mask, val); +} + +/** + * snd_hda_regmap_read - Read a verb with caching + * @nid: codec NID + * @verb: verb to read + * @val: pointer to store the value + * + * For reading an amp value, use snd_hda_regmap_get_amp(). + */ +static inline int +snd_hdac_regmap_read(struct hdac_device *codec, hda_nid_t nid, + unsigned int verb, unsigned int *val) +{ + unsigned int cmd = snd_hdac_regmap_encode_verb(nid, verb); + + return snd_hdac_regmap_read_raw(codec, cmd, val); +} + +/** + * snd_hdac_regmap_get_amp - Read AMP value + * @codec: HD-audio codec + * @nid: NID to read the AMP value + * @ch: channel (left=0 or right=1) + * @direction: #HDA_INPUT or #HDA_OUTPUT + * @index: the index value (only for input direction) + * @val: the pointer to store the value + * + * Read AMP value. The volume is between 0 to 0x7f, 0x80 = mute bit. + * Returns the value or a negative error. + */ +static inline int +snd_hdac_regmap_get_amp(struct hdac_device *codec, hda_nid_t nid, + int ch, int dir, int idx) +{ + unsigned int cmd = snd_hdac_regmap_encode_amp(nid, ch, dir, idx); + int err, val; + + err = snd_hdac_regmap_read_raw(codec, cmd, &val); + return err < 0 ? err : val; +} + +/** + * snd_hdac_regmap_update_amp - update the AMP value + * @codec: HD-audio codec + * @nid: NID to read the AMP value + * @ch: channel (left=0 or right=1) + * @direction: #HDA_INPUT or #HDA_OUTPUT + * @idx: the index value (only for input direction) + * @mask: bit mask to set + * @val: the bits value to set + * + * Update the AMP value with a bit mask. + * Returns 0 if the value is unchanged, 1 if changed, or a negative error. + */ +static inline int +snd_hdac_regmap_update_amp(struct hdac_device *codec, hda_nid_t nid, + int ch, int dir, int idx, int mask, int val) +{ + unsigned int cmd = snd_hdac_regmap_encode_amp(nid, ch, dir, idx); + + return snd_hdac_regmap_update_raw(codec, cmd, mask, val); +} + +#endif /* __SOUND_HDA_REGMAP_H */ diff --git a/include/sound/hdaudio.h b/include/sound/hdaudio.h index 3abdd3f16528..47e20b741c51 100644 --- a/include/sound/hdaudio.h +++ b/include/sound/hdaudio.h @@ -72,6 +72,10 @@ struct hdac_device { /* sysfs */ struct hdac_widget_tree *widgets; + + /* regmap */ + struct regmap *regmap; + bool lazy_cache:1; /* don't wake up for writes */ }; /* device/driver type used for matching */ diff --git a/sound/hda/Kconfig b/sound/hda/Kconfig index 4f428ccf64ad..001c6588a5ff 100644 --- a/sound/hda/Kconfig +++ b/sound/hda/Kconfig @@ -1,2 +1,3 @@ config SND_HDA_CORE tristate + select REGMAP diff --git a/sound/hda/Makefile b/sound/hda/Makefile index e508ba1102cb..7a359f5b7e25 100644 --- a/sound/hda/Makefile +++ b/sound/hda/Makefile @@ -1,5 +1,5 @@ snd-hda-core-objs := hda_bus_type.o hdac_bus.o hdac_device.o hdac_sysfs.o \ - array.o + hdac_regmap.o array.o snd-hda-core-objs += trace.o CFLAGS_trace.o := -I$(src) diff --git a/sound/hda/hdac_regmap.c b/sound/hda/hdac_regmap.c new file mode 100644 index 000000000000..db03d60d9c99 --- /dev/null +++ b/sound/hda/hdac_regmap.c @@ -0,0 +1,304 @@ +/* + * Regmap support for HD-audio verbs + * + * A virtual register is translated to one or more hda verbs for write, + * vice versa for read. + * + * A few limitations: + * - Provided for not all verbs but only subset standard non-volatile verbs. + * - For reading, only AC_VERB_GET_* variants can be used. + * - For writing, mapped to the *corresponding* AC_VERB_SET_* variants, + * so can't handle asymmetric verbs for read and write + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef CONFIG_PM +#define codec_is_running(codec) \ + (atomic_read(&(codec)->in_pm) || \ + !pm_runtime_suspended(&(codec)->dev)) +#else +#define codec_is_running(codec) true +#endif + +#define get_verb(reg) (((reg) >> 8) & 0xfff) + +static bool hda_volatile_reg(struct device *dev, unsigned int reg) +{ + unsigned int verb = get_verb(reg); + + switch (verb) { + case AC_VERB_GET_PROC_COEF: + case AC_VERB_GET_COEF_INDEX: + case AC_VERB_GET_PROC_STATE: + case AC_VERB_GET_POWER_STATE: + case AC_VERB_GET_PIN_SENSE: + case AC_VERB_GET_HDMI_DIP_SIZE: + case AC_VERB_GET_HDMI_ELDD: + case AC_VERB_GET_HDMI_DIP_INDEX: + case AC_VERB_GET_HDMI_DIP_DATA: + case AC_VERB_GET_HDMI_DIP_XMIT: + case AC_VERB_GET_HDMI_CP_CTRL: + case AC_VERB_GET_HDMI_CHAN_SLOT: + case AC_VERB_GET_DEVICE_SEL: + case AC_VERB_GET_DEVICE_LIST: /* read-only volatile */ + return true; + } + + return false; +} + +static bool hda_writeable_reg(struct device *dev, unsigned int reg) +{ + unsigned int verb = get_verb(reg); + + switch (verb & 0xf00) { + case AC_VERB_GET_STREAM_FORMAT: + case AC_VERB_GET_AMP_GAIN_MUTE: + return true; + case 0xf00: + break; + default: + return false; + } + + switch (verb) { + case AC_VERB_GET_CONNECT_SEL: + case AC_VERB_GET_SDI_SELECT: + case AC_VERB_GET_CONV: + case AC_VERB_GET_PIN_WIDGET_CONTROL: + case AC_VERB_GET_UNSOLICITED_RESPONSE: /* only as SET_UNSOLICITED_ENABLE */ + case AC_VERB_GET_BEEP_CONTROL: + case AC_VERB_GET_EAPD_BTLENABLE: + case AC_VERB_GET_DIGI_CONVERT_1: + case AC_VERB_GET_DIGI_CONVERT_2: /* only for beep control */ + case AC_VERB_GET_VOLUME_KNOB_CONTROL: + case AC_VERB_GET_CONFIG_DEFAULT: + case AC_VERB_GET_GPIO_MASK: + case AC_VERB_GET_GPIO_DIRECTION: + case AC_VERB_GET_GPIO_DATA: /* not for volatile read */ + case AC_VERB_GET_GPIO_WAKE_MASK: + case AC_VERB_GET_GPIO_UNSOLICITED_RSP_MASK: + case AC_VERB_GET_GPIO_STICKY_MASK: + case AC_VERB_GET_CVT_CHAN_COUNT: + return true; + } + + return false; +} + +static bool hda_readable_reg(struct device *dev, unsigned int reg) +{ + unsigned int verb = get_verb(reg); + + switch (verb) { + case AC_VERB_PARAMETERS: + case AC_VERB_GET_CONNECT_LIST: + case AC_VERB_GET_SUBSYSTEM_ID: + return true; + } + + return hda_writeable_reg(dev, reg); +} + +static int hda_reg_read(void *context, unsigned int reg, unsigned int *val) +{ + struct hdac_device *codec = context; + + if (!codec_is_running(codec)) + return -EAGAIN; + reg |= (codec->addr << 28); + return snd_hdac_exec_verb(codec, reg, 0, val); +} + +static int hda_reg_write(void *context, unsigned int reg, unsigned int val) +{ + struct hdac_device *codec = context; + unsigned int verb; + int i, bytes, err; + + if (!codec_is_running(codec)) + return codec->lazy_cache ? 0 : -EAGAIN; + + reg &= ~0x00080000U; /* drop GET bit */ + reg |= (codec->addr << 28); + verb = get_verb(reg); + + switch (verb & 0xf00) { + case AC_VERB_SET_AMP_GAIN_MUTE: + verb = AC_VERB_SET_AMP_GAIN_MUTE; + if (reg & AC_AMP_GET_LEFT) + verb |= AC_AMP_SET_LEFT >> 8; + else + verb |= AC_AMP_SET_RIGHT >> 8; + if (reg & AC_AMP_GET_OUTPUT) { + verb |= AC_AMP_SET_OUTPUT >> 8; + } else { + verb |= AC_AMP_SET_INPUT >> 8; + verb |= reg & 0xf; + } + break; + } + + switch (verb) { + case AC_VERB_SET_DIGI_CONVERT_1: + bytes = 2; + break; + case AC_VERB_SET_CONFIG_DEFAULT_BYTES_0: + bytes = 4; + break; + default: + bytes = 1; + break; + } + + for (i = 0; i < bytes; i++) { + reg &= ~0xfffff; + reg |= (verb + i) << 8 | ((val >> (8 * i)) & 0xff); + err = snd_hdac_exec_verb(codec, reg, 0, NULL); + if (err < 0) + return err; + } + + return 0; +} + +static const struct regmap_config hda_regmap_cfg = { + .name = "hdaudio", + .reg_bits = 32, + .val_bits = 32, + .max_register = 0xfffffff, + .writeable_reg = hda_writeable_reg, + .readable_reg = hda_readable_reg, + .volatile_reg = hda_volatile_reg, + .cache_type = REGCACHE_RBTREE, + .reg_read = hda_reg_read, + .reg_write = hda_reg_write, +}; + +int snd_hdac_regmap_init(struct hdac_device *codec) +{ + struct regmap *regmap; + + regmap = regmap_init(&codec->dev, NULL, codec, &hda_regmap_cfg); + if (IS_ERR(regmap)) + return PTR_ERR(regmap); + codec->regmap = regmap; + return 0; +} +EXPORT_SYMBOL_GPL(snd_hdac_regmap_init); + +void snd_hdac_regmap_exit(struct hdac_device *codec) +{ + if (codec->regmap) { + regmap_exit(codec->regmap); + codec->regmap = NULL; + } +} +EXPORT_SYMBOL_GPL(snd_hdac_regmap_exit); + +/* + * helper functions + */ + +/* write a pseudo-register value (w/o power sequence) */ +static int reg_raw_write(struct hdac_device *codec, unsigned int reg, + unsigned int val) +{ + if (!codec->regmap) + return hda_reg_write(codec, reg, val); + else + return regmap_write(codec->regmap, reg, val); +} + +/** + * snd_hdac_regmap_write_raw - write a pseudo register with power mgmt + * @codec: the codec object + * @reg: pseudo register + * @val: value to write + * + * Returns zero if successful or a negative error code. + */ +int snd_hdac_regmap_write_raw(struct hdac_device *codec, unsigned int reg, + unsigned int val) +{ + int err; + + err = reg_raw_write(codec, reg, val); + if (err == -EAGAIN) { + snd_hdac_power_up(codec); + err = reg_raw_write(codec, reg, val); + snd_hdac_power_down(codec); + } + return err; +} +EXPORT_SYMBOL_GPL(snd_hdac_regmap_write_raw); + +static int reg_raw_read(struct hdac_device *codec, unsigned int reg, + unsigned int *val) +{ + if (!codec->regmap) + return hda_reg_read(codec, reg, val); + else + return regmap_read(codec->regmap, reg, val); +} + +/** + * snd_hdac_regmap_read_raw - read a pseudo register with power mgmt + * @codec: the codec object + * @reg: pseudo register + * @val: pointer to store the read value + * + * Returns zero if successful or a negative error code. + */ +int snd_hdac_regmap_read_raw(struct hdac_device *codec, unsigned int reg, + unsigned int *val) +{ + int err; + + err = reg_raw_read(codec, reg, val); + if (err == -EAGAIN) { + snd_hdac_power_up(codec); + err = reg_raw_read(codec, reg, val); + snd_hdac_power_down(codec); + } + return err; +} +EXPORT_SYMBOL_GPL(snd_hdac_regmap_read_raw); + +/** + * snd_hdac_regmap_update_raw - update a pseudo register with power mgmt + * @codec: the codec object + * @reg: pseudo register + * @mask: bit mask to udpate + * @val: value to update + * + * Returns zero if successful or a negative error code. + */ +int snd_hdac_regmap_update_raw(struct hdac_device *codec, unsigned int reg, + unsigned int mask, unsigned int val) +{ + unsigned int orig; + int err; + + val &= mask; + err = snd_hdac_regmap_read_raw(codec, reg, &orig); + if (err < 0) + return err; + val |= orig & ~mask; + if (val == orig) + return 0; + err = snd_hdac_regmap_write_raw(codec, reg, val); + if (err < 0) + return err; + return 1; +} +EXPORT_SYMBOL_GPL(snd_hdac_regmap_update_raw); diff --git a/sound/pci/hda/hda_bind.c b/sound/pci/hda/hda_bind.c index 7b269c3237e3..00aa31c5f08e 100644 --- a/sound/pci/hda/hda_bind.c +++ b/sound/pci/hda/hda_bind.c @@ -73,6 +73,9 @@ static int hda_codec_driver_probe(struct device *dev) return -EINVAL; err = codec_refresh_name(codec, codec->preset->name); + if (err < 0) + goto error; + err = snd_hdac_regmap_init(&codec->core); if (err < 0) goto error; @@ -98,6 +101,7 @@ static int hda_codec_driver_probe(struct device *dev) snd_hda_codec_register(codec); } + codec->core.lazy_cache = true; return 0; error_module: diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 10e257ff9084..8eb42f4226ff 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -945,6 +945,7 @@ void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec) snd_array_free(&codec->mixers); snd_array_free(&codec->nids); remove_conn_list(codec); + snd_hdac_regmap_exit(&codec->core); } static unsigned int hda_set_power_state(struct hda_codec *codec, diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index 3068163b3db2..0f5749ca1600 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h @@ -28,6 +28,7 @@ #include #include #include +#include /* * Structures -- cgit v1.2.3 From 01ed3c06c6d5e7e861650ae76117dd4194d87316 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 26 Feb 2015 13:57:47 +0100 Subject: ALSA: hda - Use regmap for codec parameter reads Let's start converting the access functions to regmap. The first one is the simplest, just converting the codec parameter read helper function snd_hda_param_read(). Signed-off-by: Takashi Iwai --- include/sound/hdaudio.h | 20 +++++++++++++++++++- sound/hda/hdac_device.c | 21 +++++++++------------ sound/pci/hda/hda_codec.h | 2 +- 3 files changed, 29 insertions(+), 14 deletions(-) (limited to 'sound/pci') diff --git a/include/sound/hdaudio.h b/include/sound/hdaudio.h index 47e20b741c51..ddfcc44970fa 100644 --- a/include/sound/hdaudio.h +++ b/include/sound/hdaudio.h @@ -105,12 +105,30 @@ int snd_hdac_exec_verb(struct hdac_device *codec, unsigned int cmd, unsigned int flags, unsigned int *res); int snd_hdac_read(struct hdac_device *codec, hda_nid_t nid, unsigned int verb, unsigned int parm, unsigned int *res); -int snd_hdac_read_parm(struct hdac_device *codec, hda_nid_t nid, int parm); +int _snd_hdac_read_parm(struct hdac_device *codec, hda_nid_t nid, int parm, + unsigned int *res); int snd_hdac_get_connections(struct hdac_device *codec, hda_nid_t nid, hda_nid_t *conn_list, int max_conns); int snd_hdac_get_sub_nodes(struct hdac_device *codec, hda_nid_t nid, hda_nid_t *start_id); +/** + * snd_hdac_read_parm - read a codec parameter + * @codec: the codec object + * @nid: NID to read a parameter + * @parm: parameter to read + * + * Returns -1 for error. If you need to distinguish the error more + * strictly, use _snd_hdac_read_parm() directly. + */ +static inline int snd_hdac_read_parm(struct hdac_device *codec, hda_nid_t nid, + int parm) +{ + unsigned int val; + + return _snd_hdac_read_parm(codec, nid, parm, &val) < 0 ? -1 : val; +} + #ifdef CONFIG_PM void snd_hdac_power_up(struct hdac_device *codec); void snd_hdac_power_down(struct hdac_device *codec); diff --git a/sound/hda/hdac_device.c b/sound/hda/hdac_device.c index 6e8ee1d6974a..ba9c1fc6e3ea 100644 --- a/sound/hda/hdac_device.c +++ b/sound/hda/hdac_device.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "local.h" static void setup_fg_nodes(struct hdac_device *codec); @@ -234,23 +235,19 @@ int snd_hdac_read(struct hdac_device *codec, hda_nid_t nid, EXPORT_SYMBOL_GPL(snd_hdac_read); /** - * snd_hdac_read_parm - read a codec parameter - * @codec: the codec object - * @nid: NID to read a parameter - * @parm: parameter to read + * _snd_hdac_read_parm - read a parmeter * - * Returns -1 for error. If you need to distinguish the error more - * strictly, use snd_hdac_read() directly. + * This function returns zero or an error unlike snd_hdac_read_parm(). */ -int snd_hdac_read_parm(struct hdac_device *codec, hda_nid_t nid, int parm) +int _snd_hdac_read_parm(struct hdac_device *codec, hda_nid_t nid, int parm, + unsigned int *res) { - int val; + unsigned int cmd; - if (snd_hdac_read(codec, nid, AC_VERB_PARAMETERS, parm, &val)) - return -1; - return val; + cmd = snd_hdac_regmap_encode_verb(nid, AC_VERB_PARAMETERS) | parm; + return snd_hdac_regmap_read_raw(codec, cmd, res); } -EXPORT_SYMBOL_GPL(snd_hdac_read_parm); +EXPORT_SYMBOL_GPL(_snd_hdac_read_parm); /** * snd_hdac_get_sub_nodes - get start NID and number of subtree nodes diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index 0f5749ca1600..135b70f066f1 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h @@ -369,7 +369,7 @@ unsigned int snd_hda_codec_read(struct hda_codec *codec, hda_nid_t nid, int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int flags, unsigned int verb, unsigned int parm); #define snd_hda_param_read(codec, nid, param) \ - snd_hda_codec_read(codec, nid, 0, AC_VERB_PARAMETERS, param) + snd_hdac_read_parm(&(codec)->core, nid, param) #define snd_hda_get_sub_nodes(codec, nid, start_nid) \ snd_hdac_get_sub_nodes(&(codec)->core, nid, start_nid) int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid, -- cgit v1.2.3 From 9ba17b4d132f56a680fa1ba0bc2a8f98b6263d93 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 3 Mar 2015 23:29:47 +0100 Subject: ALSA: hda - Implement uncached version of parameter reads Sometimes we need the uncached reads, e.g. for refreshing the tree. This patch provides the helper function for that and uses it for refreshing widgets, reading subtrees and the whole proc reads. Signed-off-by: Takashi Iwai --- include/sound/hdaudio.h | 2 ++ sound/hda/hdac_device.c | 26 +++++++++++++++++++++++++- sound/pci/hda/hda_codec.c | 4 ++-- sound/pci/hda/hda_proc.c | 28 ++++++++++++++-------------- 4 files changed, 43 insertions(+), 17 deletions(-) (limited to 'sound/pci') diff --git a/include/sound/hdaudio.h b/include/sound/hdaudio.h index ddfcc44970fa..65ea6429f3a7 100644 --- a/include/sound/hdaudio.h +++ b/include/sound/hdaudio.h @@ -107,6 +107,8 @@ int snd_hdac_read(struct hdac_device *codec, hda_nid_t nid, unsigned int verb, unsigned int parm, unsigned int *res); int _snd_hdac_read_parm(struct hdac_device *codec, hda_nid_t nid, int parm, unsigned int *res); +int snd_hdac_read_parm_uncached(struct hdac_device *codec, hda_nid_t nid, + int parm); int snd_hdac_get_connections(struct hdac_device *codec, hda_nid_t nid, hda_nid_t *conn_list, int max_conns); int snd_hdac_get_sub_nodes(struct hdac_device *codec, hda_nid_t nid, diff --git a/sound/hda/hdac_device.c b/sound/hda/hdac_device.c index ba9c1fc6e3ea..0dac746df7da 100644 --- a/sound/hda/hdac_device.c +++ b/sound/hda/hdac_device.c @@ -249,6 +249,29 @@ int _snd_hdac_read_parm(struct hdac_device *codec, hda_nid_t nid, int parm, } EXPORT_SYMBOL_GPL(_snd_hdac_read_parm); +/** + * snd_hdac_read_parm_uncached - read a codec parameter without caching + * @codec: the codec object + * @nid: NID to read a parameter + * @parm: parameter to read + * + * Returns -1 for error. If you need to distinguish the error more + * strictly, use snd_hdac_read() directly. + */ +int snd_hdac_read_parm_uncached(struct hdac_device *codec, hda_nid_t nid, + int parm) +{ + int val; + + if (codec->regmap) + regcache_cache_bypass(codec->regmap, true); + val = snd_hdac_read_parm(codec, nid, parm); + if (codec->regmap) + regcache_cache_bypass(codec->regmap, false); + return val; +} +EXPORT_SYMBOL_GPL(snd_hdac_read_parm_uncached); + /** * snd_hdac_get_sub_nodes - get start NID and number of subtree nodes * @codec: the codec object @@ -256,13 +279,14 @@ EXPORT_SYMBOL_GPL(_snd_hdac_read_parm); * @start_id: the pointer to store the starting NID * * Returns the number of subtree nodes or zero if not found. + * This function reads parameters always without caching. */ int snd_hdac_get_sub_nodes(struct hdac_device *codec, hda_nid_t nid, hda_nid_t *start_id) { unsigned int parm; - parm = snd_hdac_read_parm(codec, nid, AC_PAR_NODE_COUNT); + parm = snd_hdac_read_parm_uncached(codec, nid, AC_PAR_NODE_COUNT); if (parm == -1) { *start_id = 0; return 0; diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 8eb42f4226ff..39b5660653f0 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -586,8 +586,8 @@ static int read_widget_caps(struct hda_codec *codec, hda_nid_t fg_node) return -ENOMEM; nid = codec->core.start_nid; for (i = 0; i < codec->core.num_nodes; i++, nid++) - codec->wcaps[i] = snd_hda_param_read(codec, nid, - AC_PAR_AUDIO_WIDGET_CAP); + codec->wcaps[i] = snd_hdac_read_parm_uncached(&codec->core, + nid, AC_PAR_AUDIO_WIDGET_CAP); return 0; } diff --git a/sound/pci/hda/hda_proc.c b/sound/pci/hda/hda_proc.c index a4f5a30f1d41..ee6230767c64 100644 --- a/sound/pci/hda/hda_proc.c +++ b/sound/pci/hda/hda_proc.c @@ -32,6 +32,10 @@ static int dump_coef = -1; module_param(dump_coef, int, 0644); MODULE_PARM_DESC(dump_coef, "Dump processing coefficients in codec proc file (-1=auto, 0=disable, 1=enable)"); +/* always use noncached version */ +#define param_read(codec, nid, parm) \ + snd_hdac_read_parm_uncached(&(codec)->core, nid, parm) + static char *bits_names(unsigned int bits, char *names[], int size) { int i, n; @@ -119,9 +123,8 @@ static void print_amp_caps(struct snd_info_buffer *buffer, struct hda_codec *codec, hda_nid_t nid, int dir) { unsigned int caps; - caps = snd_hda_param_read(codec, nid, - dir == HDA_OUTPUT ? - AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP); + caps = param_read(codec, nid, dir == HDA_OUTPUT ? + AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP); if (caps == -1 || caps == 0) { snd_iprintf(buffer, "N/A\n"); return; @@ -225,8 +228,8 @@ static void print_pcm_formats(struct snd_info_buffer *buffer, static void print_pcm_caps(struct snd_info_buffer *buffer, struct hda_codec *codec, hda_nid_t nid) { - unsigned int pcm = snd_hda_param_read(codec, nid, AC_PAR_PCM); - unsigned int stream = snd_hda_param_read(codec, nid, AC_PAR_STREAM); + unsigned int pcm = param_read(codec, nid, AC_PAR_PCM); + unsigned int stream = param_read(codec, nid, AC_PAR_STREAM); if (pcm == -1 || stream == -1) { snd_iprintf(buffer, "N/A\n"); return; @@ -273,7 +276,7 @@ static void print_pin_caps(struct snd_info_buffer *buffer, static char *jack_conns[4] = { "Jack", "N/A", "Fixed", "Both" }; unsigned int caps, val; - caps = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP); + caps = param_read(codec, nid, AC_PAR_PIN_CAP); snd_iprintf(buffer, " Pincap 0x%08x:", caps); if (caps & AC_PINCAP_IN) snd_iprintf(buffer, " IN"); @@ -401,8 +404,7 @@ static void print_pin_ctls(struct snd_info_buffer *buffer, static void print_vol_knob(struct snd_info_buffer *buffer, struct hda_codec *codec, hda_nid_t nid) { - unsigned int cap = snd_hda_param_read(codec, nid, - AC_PAR_VOL_KNB_CAP); + unsigned int cap = param_read(codec, nid, AC_PAR_VOL_KNB_CAP); snd_iprintf(buffer, " Volume-Knob: delta=%d, steps=%d, ", (cap >> 7) & 1, cap & 0x7f); cap = snd_hda_codec_read(codec, nid, 0, @@ -487,7 +489,7 @@ static void print_power_state(struct snd_info_buffer *buffer, [ilog2(AC_PWRST_EPSS)] = "EPSS", }; - int sup = snd_hda_param_read(codec, nid, AC_PAR_POWER_STATE); + int sup = param_read(codec, nid, AC_PAR_POWER_STATE); int pwr = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_POWER_STATE, 0); if (sup != -1) @@ -531,8 +533,7 @@ static void print_proc_caps(struct snd_info_buffer *buffer, struct hda_codec *codec, hda_nid_t nid) { unsigned int i, ncoeff, oldindex; - unsigned int proc_caps = snd_hda_param_read(codec, nid, - AC_PAR_PROC_CAP); + unsigned int proc_caps = param_read(codec, nid, AC_PAR_PROC_CAP); ncoeff = (proc_caps & AC_PCAP_NUM_COEF) >> AC_PCAP_NUM_COEF_SHIFT; snd_iprintf(buffer, " Processing caps: benign=%d, ncoeff=%d\n", proc_caps & AC_PCAP_BENIGN, ncoeff); @@ -597,7 +598,7 @@ static void print_gpio(struct snd_info_buffer *buffer, struct hda_codec *codec, hda_nid_t nid) { unsigned int gpio = - snd_hda_param_read(codec, codec->core.afg, AC_PAR_GPIO_CAP); + param_read(codec, codec->core.afg, AC_PAR_GPIO_CAP); unsigned int enable, direction, wake, unsol, sticky, data; int i, max; snd_iprintf(buffer, "GPIO: io=%d, o=%d, i=%d, " @@ -727,8 +728,7 @@ static void print_codec_info(struct snd_info_entry *entry, for (i = 0; i < nodes; i++, nid++) { unsigned int wid_caps = - snd_hda_param_read(codec, nid, - AC_PAR_AUDIO_WIDGET_CAP); + param_read(codec, nid, AC_PAR_AUDIO_WIDGET_CAP); unsigned int wid_type = get_wcaps_type(wid_caps); hda_nid_t *conn = NULL; int conn_len = 0; -- cgit v1.2.3 From eeecd9d10d3da0b9efd6f58fad55c4355dcc246a Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Wed, 25 Feb 2015 15:18:50 +0100 Subject: ALSA: hda - Use regmap for amp accesses This patch converts the amp access functions to the regmap helpers. The amp values were formerly cached in the own hash table. Now it's dropped by the regmap's cache. The only tricky conversion is snd_hda_codec_amp_init(). This function shouldn't do anything if the amp was already initialized. For achieving this behavior, a value is read once at first temporarily in the cache-only mode. Only if it returns an error, i.e. the item still doesn't exist in the cache, it proceeds to the update. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_codec.c | 215 +++++------------------------------------- sound/pci/hda/hda_local.h | 10 +- sound/pci/hda/patch_hdmi.c | 2 +- sound/pci/hda/patch_realtek.c | 4 +- 4 files changed, 32 insertions(+), 199 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 39b5660653f0..52962f697825 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -1543,139 +1543,6 @@ int snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid, } EXPORT_SYMBOL_GPL(snd_hda_override_pin_caps); -/* read or sync the hash value with the current value; - * call within hash_mutex - */ -static struct hda_amp_info * -update_amp_hash(struct hda_codec *codec, hda_nid_t nid, int ch, - int direction, int index, bool init_only) -{ - struct hda_amp_info *info; - unsigned int parm, val = 0; - bool val_read = false; - - retry: - info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, index)); - if (!info) - return NULL; - if (!(info->head.val & INFO_AMP_VOL(ch))) { - if (!val_read) { - mutex_unlock(&codec->hash_mutex); - parm = ch ? AC_AMP_GET_RIGHT : AC_AMP_GET_LEFT; - parm |= direction == HDA_OUTPUT ? - AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT; - parm |= index; - val = snd_hda_codec_read(codec, nid, 0, - AC_VERB_GET_AMP_GAIN_MUTE, parm); - val &= 0xff; - val_read = true; - mutex_lock(&codec->hash_mutex); - goto retry; - } - info->vol[ch] = val; - info->head.val |= INFO_AMP_VOL(ch); - } else if (init_only) - return NULL; - return info; -} - -/* - * write the current volume in info to the h/w - */ -static void put_vol_mute(struct hda_codec *codec, unsigned int amp_caps, - hda_nid_t nid, int ch, int direction, int index, - int val) -{ - u32 parm; - - parm = ch ? AC_AMP_SET_RIGHT : AC_AMP_SET_LEFT; - parm |= direction == HDA_OUTPUT ? AC_AMP_SET_OUTPUT : AC_AMP_SET_INPUT; - parm |= index << AC_AMP_SET_INDEX_SHIFT; - if ((val & HDA_AMP_MUTE) && !(amp_caps & AC_AMPCAP_MUTE) && - (amp_caps & AC_AMPCAP_MIN_MUTE)) - ; /* set the zero value as a fake mute */ - else - parm |= val; - snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, parm); -} - -/** - * snd_hda_codec_amp_read - Read AMP value - * @codec: HD-audio codec - * @nid: NID to read the AMP value - * @ch: channel (left=0 or right=1) - * @direction: #HDA_INPUT or #HDA_OUTPUT - * @index: the index value (only for input direction) - * - * Read AMP value. The volume is between 0 to 0x7f, 0x80 = mute bit. - */ -int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch, - int direction, int index) -{ - struct hda_amp_info *info; - unsigned int val = 0; - - mutex_lock(&codec->hash_mutex); - info = update_amp_hash(codec, nid, ch, direction, index, false); - if (info) - val = info->vol[ch]; - mutex_unlock(&codec->hash_mutex); - return val; -} -EXPORT_SYMBOL_GPL(snd_hda_codec_amp_read); - -static int codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch, - int direction, int idx, int mask, int val, - bool init_only, bool cache_only) -{ - struct hda_amp_info *info; - unsigned int caps; - - if (snd_BUG_ON(mask & ~0xff)) - mask &= 0xff; - val &= mask; - - mutex_lock(&codec->hash_mutex); - info = update_amp_hash(codec, nid, ch, direction, idx, init_only); - if (!info) { - mutex_unlock(&codec->hash_mutex); - return 0; - } - val |= info->vol[ch] & ~mask; - if (info->vol[ch] == val) { - mutex_unlock(&codec->hash_mutex); - return 0; - } - info->vol[ch] = val; - info->head.dirty |= cache_only; - caps = info->amp_caps; - mutex_unlock(&codec->hash_mutex); - if (!cache_only) - put_vol_mute(codec, caps, nid, ch, direction, idx, val); - return 1; -} - -/** - * snd_hda_codec_amp_update - update the AMP value - * @codec: HD-audio codec - * @nid: NID to read the AMP value - * @ch: channel (left=0 or right=1) - * @direction: #HDA_INPUT or #HDA_OUTPUT - * @idx: the index value (only for input direction) - * @mask: bit mask to set - * @val: the bits value to set - * - * Update the AMP value with a bit mask. - * Returns 0 if the value is unchanged, 1 if changed. - */ -int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch, - int direction, int idx, int mask, int val) -{ - return codec_amp_update(codec, nid, ch, direction, idx, mask, val, - false, codec->cached_write); -} -EXPORT_SYMBOL_GPL(snd_hda_codec_amp_update); - /** * snd_hda_codec_amp_stereo - update the AMP stereo values * @codec: HD-audio codec @@ -1719,8 +1586,16 @@ EXPORT_SYMBOL_GPL(snd_hda_codec_amp_stereo); int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch, int dir, int idx, int mask, int val) { - return codec_amp_update(codec, nid, ch, dir, idx, mask, val, true, - codec->cached_write); + int orig; + + if (!codec->core.regmap) + return -EINVAL; + regcache_cache_only(codec->core.regmap, true); + orig = snd_hda_codec_amp_read(codec, nid, ch, dir, idx); + regcache_cache_only(codec->core.regmap, false); + if (orig >= 0) + return 0; + return snd_hda_codec_amp_update(codec, nid, ch, dir, idx, mask, val); } EXPORT_SYMBOL_GPL(snd_hda_codec_amp_init); @@ -1749,49 +1624,6 @@ int snd_hda_codec_amp_init_stereo(struct hda_codec *codec, hda_nid_t nid, } EXPORT_SYMBOL_GPL(snd_hda_codec_amp_init_stereo); -/** - * snd_hda_codec_resume_amp - Resume all AMP commands from the cache - * @codec: HD-audio codec - * - * Resume the all amp commands from the cache. - */ -void snd_hda_codec_resume_amp(struct hda_codec *codec) -{ - int i; - - mutex_lock(&codec->hash_mutex); - codec->cached_write = 0; - for (i = 0; i < codec->amp_cache.buf.used; i++) { - struct hda_amp_info *buffer; - u32 key; - hda_nid_t nid; - unsigned int idx, dir, ch; - struct hda_amp_info info; - - buffer = snd_array_elem(&codec->amp_cache.buf, i); - if (!buffer->head.dirty) - continue; - buffer->head.dirty = 0; - info = *buffer; - key = info.head.key; - if (!key) - continue; - nid = key & 0xff; - idx = (key >> 16) & 0xff; - dir = (key >> 24) & 0xff; - for (ch = 0; ch < 2; ch++) { - if (!(info.head.val & INFO_AMP_VOL(ch))) - continue; - mutex_unlock(&codec->hash_mutex); - put_vol_mute(codec, info.amp_caps, nid, ch, dir, idx, - info.vol[ch]); - mutex_lock(&codec->hash_mutex); - } - } - mutex_unlock(&codec->hash_mutex); -} -EXPORT_SYMBOL_GPL(snd_hda_codec_resume_amp); - static u32 get_amp_max_value(struct hda_codec *codec, hda_nid_t nid, int dir, unsigned int ofs) { @@ -1862,8 +1694,8 @@ update_amp_value(struct hda_codec *codec, hda_nid_t nid, maxval = get_amp_max_value(codec, nid, dir, 0); if (val > maxval) val = maxval; - return codec_amp_update(codec, nid, ch, dir, idx, HDA_AMP_VOLMASK, val, - false, !hda_codec_is_power_on(codec)); + return snd_hda_codec_amp_update(codec, nid, ch, dir, idx, + HDA_AMP_VOLMASK, val); } /** @@ -2546,17 +2378,15 @@ int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol, int change = 0; if (chs & 1) { - change = codec_amp_update(codec, nid, 0, dir, idx, - HDA_AMP_MUTE, - *valp ? 0 : HDA_AMP_MUTE, false, - !hda_codec_is_power_on(codec)); + change = snd_hda_codec_amp_update(codec, nid, 0, dir, idx, + HDA_AMP_MUTE, + *valp ? 0 : HDA_AMP_MUTE); valp++; } if (chs & 2) - change |= codec_amp_update(codec, nid, 1, dir, idx, - HDA_AMP_MUTE, - *valp ? 0 : HDA_AMP_MUTE, false, - !hda_codec_is_power_on(codec)); + change |= snd_hda_codec_amp_update(codec, nid, 1, dir, idx, + HDA_AMP_MUTE, + *valp ? 0 : HDA_AMP_MUTE); hda_call_check_power_status(codec, nid); return change; } @@ -3417,7 +3247,8 @@ EXPORT_SYMBOL_GPL(snd_hda_sequence_write_cache); */ void snd_hda_codec_flush_cache(struct hda_codec *codec) { - snd_hda_codec_resume_amp(codec); + if (codec->core.regmap) + regcache_sync(codec->core.regmap); snd_hda_codec_resume_cache(codec); } EXPORT_SYMBOL_GPL(snd_hda_codec_flush_cache); @@ -3645,6 +3476,9 @@ static void hda_call_codec_resume(struct hda_codec *codec) { atomic_inc(&codec->core.in_pm); + if (codec->core.regmap) + regcache_mark_dirty(codec->core.regmap); + hda_mark_cmd_cache_dirty(codec); codec->power_jiffies = jiffies; @@ -3658,7 +3492,8 @@ static void hda_call_codec_resume(struct hda_codec *codec) else { if (codec->patch_ops.init) codec->patch_ops.init(codec); - snd_hda_codec_resume_amp(codec); + if (codec->core.regmap) + regcache_sync(codec->core.regmap); snd_hda_codec_resume_cache(codec); } diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h index 8a83775e0e27..7023eeee8b9d 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, struct snd_ctl_elem_value *ucontrol); #endif /* lowlevel accessor with caching; use carefully */ -int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch, - int direction, int index); -int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch, - int direction, int idx, int mask, int val); +#define snd_hda_codec_amp_read(codec, nid, ch, dir, idx) \ + snd_hdac_regmap_get_amp(&(codec)->core, nid, ch, dir, idx) +#define snd_hda_codec_amp_update(codec, nid, ch, dir, idx, mask, val) \ + snd_hdac_regmap_update_amp(&(codec)->core, nid, ch, dir, idx, mask, val) int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid, int dir, int idx, int mask, int val); int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch, int direction, int idx, int mask, int val); int snd_hda_codec_amp_init_stereo(struct hda_codec *codec, hda_nid_t nid, int dir, int idx, int mask, int val); -void snd_hda_codec_resume_amp(struct hda_codec *codec); - void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir, unsigned int *tlv); struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec, diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c index 35d92a8a99ce..04c5ab20eb76 100644 --- a/sound/pci/hda/patch_hdmi.c +++ b/sound/pci/hda/patch_hdmi.c @@ -2211,7 +2211,7 @@ static int generic_hdmi_resume(struct hda_codec *codec) int pin_idx; codec->patch_ops.init(codec); - snd_hda_codec_resume_amp(codec); + regcache_sync(codec->core.regmap); snd_hda_codec_resume_cache(codec); for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c index eee4532ab5f6..a440e539230f 100644 --- a/sound/pci/hda/patch_realtek.c +++ b/sound/pci/hda/patch_realtek.c @@ -799,7 +799,7 @@ static int alc_resume(struct hda_codec *codec) if (!spec->no_depop_delay) msleep(150); /* to avoid pop noise */ codec->patch_ops.init(codec); - snd_hda_codec_resume_amp(codec); + regcache_sync(codec->core.regmap); snd_hda_codec_resume_cache(codec); hda_call_check_power_status(codec, 0x01); return 0; @@ -3058,7 +3058,7 @@ static int alc269_resume(struct hda_codec *codec) msleep(200); } - snd_hda_codec_resume_amp(codec); + regcache_sync(codec->core.regmap); snd_hda_codec_resume_cache(codec); hda_call_check_power_status(codec, 0x01); -- cgit v1.2.3 From faa75f8a2edf005a5caf43be4875ffeeb9bcb498 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 26 Feb 2015 08:54:56 +0100 Subject: ALSA: hda - Use regmap for parameter caches, too The amp hash table was used for recording the cached reads of some capability values like pin caps or amp caps. Now all these are moved to regmap as well. One addition to the regmap helper is codec->caps_overwriting flag. This is set in snd_hdac_override_parm(), and the regmap helper accepts any register while this flag is set, so that it can overwrite even the read-only verb like AC_VERB_PARAMETERS. The flag is cleared immediately in snd_hdac_override_parm(), as it's a once-off flag. Along with these changes, the no longer needed amp hash and relevant fields are removed from hda_codec struct now. Signed-off-by: Takashi Iwai --- include/sound/hdaudio.h | 3 + sound/hda/hdac_device.c | 23 ++++++++ sound/hda/hdac_regmap.c | 8 +++ sound/pci/hda/hda_codec.c | 144 +++++----------------------------------------- sound/pci/hda/hda_codec.h | 7 --- sound/pci/hda/hda_local.h | 38 +++++++++++- 6 files changed, 82 insertions(+), 141 deletions(-) (limited to 'sound/pci') diff --git a/include/sound/hdaudio.h b/include/sound/hdaudio.h index 65ea6429f3a7..ce7d8d1f59c6 100644 --- a/include/sound/hdaudio.h +++ b/include/sound/hdaudio.h @@ -76,6 +76,7 @@ struct hdac_device { /* regmap */ struct regmap *regmap; bool lazy_cache:1; /* don't wake up for writes */ + bool caps_overwriting:1; /* caps overwrite being in process */ }; /* device/driver type used for matching */ @@ -109,6 +110,8 @@ int _snd_hdac_read_parm(struct hdac_device *codec, hda_nid_t nid, int parm, unsigned int *res); int snd_hdac_read_parm_uncached(struct hdac_device *codec, hda_nid_t nid, int parm); +int snd_hdac_override_parm(struct hdac_device *codec, hda_nid_t nid, + unsigned int parm, unsigned int val); int snd_hdac_get_connections(struct hdac_device *codec, hda_nid_t nid, hda_nid_t *conn_list, int max_conns); int snd_hdac_get_sub_nodes(struct hdac_device *codec, hda_nid_t nid, diff --git a/sound/hda/hdac_device.c b/sound/hda/hdac_device.c index 0dac746df7da..72c584eb011b 100644 --- a/sound/hda/hdac_device.c +++ b/sound/hda/hdac_device.c @@ -272,6 +272,29 @@ int snd_hdac_read_parm_uncached(struct hdac_device *codec, hda_nid_t nid, } EXPORT_SYMBOL_GPL(snd_hdac_read_parm_uncached); +/** + * snd_hdac_override_parm - override read-only parameters + * @codec: the codec object + * @nid: NID for the parameter + * @parm: the parameter to change + * @val: the parameter value to overwrite + */ +int snd_hdac_override_parm(struct hdac_device *codec, hda_nid_t nid, + unsigned int parm, unsigned int val) +{ + unsigned int verb = (AC_VERB_PARAMETERS << 8) | (nid << 20) | parm; + int err; + + if (!codec->regmap) + return -EINVAL; + + codec->caps_overwriting = true; + err = snd_hdac_regmap_write_raw(codec, verb, val); + codec->caps_overwriting = false; + return err; +} +EXPORT_SYMBOL_GPL(snd_hdac_override_parm); + /** * snd_hdac_get_sub_nodes - get start NID and number of subtree nodes * @codec: the codec object diff --git a/sound/hda/hdac_regmap.c b/sound/hda/hdac_regmap.c index db03d60d9c99..933907b16457 100644 --- a/sound/hda/hdac_regmap.c +++ b/sound/hda/hdac_regmap.c @@ -58,8 +58,12 @@ static bool hda_volatile_reg(struct device *dev, unsigned int reg) static bool hda_writeable_reg(struct device *dev, unsigned int reg) { + struct hdac_device *codec = dev_to_hdac_dev(dev); unsigned int verb = get_verb(reg); + if (codec->caps_overwriting) + return true; + switch (verb & 0xf00) { case AC_VERB_GET_STREAM_FORMAT: case AC_VERB_GET_AMP_GAIN_MUTE: @@ -97,8 +101,12 @@ static bool hda_writeable_reg(struct device *dev, unsigned int reg) static bool hda_readable_reg(struct device *dev, unsigned int reg) { + struct hdac_device *codec = dev_to_hdac_dev(dev); unsigned int verb = get_verb(reg); + if (codec->caps_overwriting) + return true; + switch (verb) { case AC_VERB_PARAMETERS: case AC_VERB_GET_CONNECT_LIST: diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 52962f697825..b27f250088c1 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -929,9 +929,7 @@ void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec) codec->proc_widget_hook = NULL; codec->spec = NULL; - free_hda_cache(&codec->amp_cache); free_hda_cache(&codec->cmd_cache); - init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info)); init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head)); /* free only driver_pins so that init_pins + user_pins are restored */ @@ -996,7 +994,6 @@ static void snd_hda_codec_dev_release(struct device *dev) free_init_pincfgs(codec); snd_hdac_device_exit(&codec->core); snd_hda_sysfs_clear(codec); - free_hda_cache(&codec->amp_cache); free_hda_cache(&codec->cmd_cache); kfree(codec->modelname); kfree(codec->wcaps); @@ -1051,7 +1048,6 @@ int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card, mutex_init(&codec->spdif_mutex); mutex_init(&codec->control_mutex); mutex_init(&codec->hash_mutex); - init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info)); init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head)); snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 32); snd_array_init(&codec->nids, sizeof(struct hda_nid_item), 32); @@ -1380,67 +1376,6 @@ static struct hda_cache_head *get_alloc_hash(struct hda_cache_rec *cache, return info; } -/* query and allocate an amp hash entry */ -static inline struct hda_amp_info * -get_alloc_amp_hash(struct hda_codec *codec, u32 key) -{ - return (struct hda_amp_info *)get_alloc_hash(&codec->amp_cache, key); -} - -/* overwrite the value with the key in the caps hash */ -static int write_caps_hash(struct hda_codec *codec, u32 key, unsigned int val) -{ - struct hda_amp_info *info; - - mutex_lock(&codec->hash_mutex); - info = get_alloc_amp_hash(codec, key); - if (!info) { - mutex_unlock(&codec->hash_mutex); - return -EINVAL; - } - info->amp_caps = val; - info->head.val |= INFO_AMP_CAPS; - mutex_unlock(&codec->hash_mutex); - return 0; -} - -/* query the value from the caps hash; if not found, fetch the current - * value from the given function and store in the hash - */ -static unsigned int -query_caps_hash(struct hda_codec *codec, hda_nid_t nid, int dir, u32 key, - unsigned int (*func)(struct hda_codec *, hda_nid_t, int)) -{ - struct hda_amp_info *info; - unsigned int val; - - mutex_lock(&codec->hash_mutex); - info = get_alloc_amp_hash(codec, key); - if (!info) { - mutex_unlock(&codec->hash_mutex); - return 0; - } - if (!(info->head.val & INFO_AMP_CAPS)) { - mutex_unlock(&codec->hash_mutex); /* for reentrance */ - val = func(codec, nid, dir); - write_caps_hash(codec, key, val); - } else { - val = info->amp_caps; - mutex_unlock(&codec->hash_mutex); - } - return val; -} - -static unsigned int read_amp_cap(struct hda_codec *codec, hda_nid_t nid, - int direction) -{ - if (!(get_wcaps(codec, nid) & AC_WCAP_AMP_OVRD)) - nid = codec->core.afg; - return snd_hda_param_read(codec, nid, - direction == HDA_OUTPUT ? - AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP); -} - /** * query_amp_caps - query AMP capabilities * @codec: the HD-auio codec @@ -1455,9 +1390,11 @@ static unsigned int read_amp_cap(struct hda_codec *codec, hda_nid_t nid, */ u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction) { - return query_caps_hash(codec, nid, direction, - HDA_HASH_KEY(nid, direction, 0), - read_amp_cap); + if (!(get_wcaps(codec, nid) & AC_WCAP_AMP_OVRD)) + nid = codec->core.afg; + return snd_hda_param_read(codec, nid, + direction == HDA_OUTPUT ? + AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP); } EXPORT_SYMBOL_GPL(query_amp_caps); @@ -1498,50 +1435,14 @@ EXPORT_SYMBOL_GPL(snd_hda_check_amp_caps); int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, unsigned int caps) { - return write_caps_hash(codec, HDA_HASH_KEY(nid, dir, 0), caps); -} -EXPORT_SYMBOL_GPL(snd_hda_override_amp_caps); - -static unsigned int read_pin_cap(struct hda_codec *codec, hda_nid_t nid, - int dir) -{ - return snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP); -} - -/** - * snd_hda_query_pin_caps - Query PIN capabilities - * @codec: the HD-auio codec - * @nid: the NID to query - * - * Query PIN capabilities for the given widget. - * Returns the obtained capability bits. - * - * When cap bits have been already read, this doesn't read again but - * returns the cached value. - */ -u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid) -{ - return query_caps_hash(codec, nid, 0, HDA_HASH_PINCAP_KEY(nid), - read_pin_cap); -} -EXPORT_SYMBOL_GPL(snd_hda_query_pin_caps); + unsigned int parm; -/** - * snd_hda_override_pin_caps - Override the pin capabilities - * @codec: the CODEC - * @nid: the NID to override - * @caps: the capability bits to set - * - * Override the cached PIN capabilitiy bits value by the given one. - * - * Returns zero if successful or a negative error code. - */ -int snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid, - unsigned int caps) -{ - return write_caps_hash(codec, HDA_HASH_PINCAP_KEY(nid), caps); + snd_hda_override_wcaps(codec, nid, + get_wcaps(codec, nid) | AC_WCAP_AMP_OVRD); + parm = dir == HDA_OUTPUT ? AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP; + return snd_hdac_override_parm(&codec->core, nid, parm, caps); } -EXPORT_SYMBOL_GPL(snd_hda_override_pin_caps); +EXPORT_SYMBOL_GPL(snd_hda_override_amp_caps); /** * snd_hda_codec_amp_stereo - update the AMP stereo values @@ -3462,11 +3363,6 @@ static void hda_mark_cmd_cache_dirty(struct hda_codec *codec) cmd = snd_array_elem(&codec->cmd_cache.buf, i); cmd->dirty = 1; } - for (i = 0; i < codec->amp_cache.buf.used; i++) { - struct hda_amp_info *amp; - amp = snd_array_elem(&codec->amp_cache.buf, i); - amp->head.dirty = 1; - } } /* @@ -3714,8 +3610,7 @@ unsigned int snd_hda_calc_stream_format(struct hda_codec *codec, } EXPORT_SYMBOL_GPL(snd_hda_calc_stream_format); -static unsigned int get_pcm_param(struct hda_codec *codec, hda_nid_t nid, - int dir) +static unsigned int query_pcm_param(struct hda_codec *codec, hda_nid_t nid) { unsigned int val = 0; if (nid != codec->core.afg && @@ -3728,14 +3623,7 @@ static unsigned int get_pcm_param(struct hda_codec *codec, hda_nid_t nid, return val; } -static unsigned int query_pcm_param(struct hda_codec *codec, hda_nid_t nid) -{ - return query_caps_hash(codec, nid, 0, HDA_HASH_PARPCM_KEY(nid), - get_pcm_param); -} - -static unsigned int get_stream_param(struct hda_codec *codec, hda_nid_t nid, - int dir) +static unsigned int query_stream_param(struct hda_codec *codec, hda_nid_t nid) { unsigned int streams = snd_hda_param_read(codec, nid, AC_PAR_STREAM); if (!streams || streams == -1) @@ -3745,12 +3633,6 @@ static unsigned int get_stream_param(struct hda_codec *codec, hda_nid_t nid, return streams; } -static unsigned int query_stream_param(struct hda_codec *codec, hda_nid_t nid) -{ - return query_caps_hash(codec, nid, 0, HDA_HASH_PARSTR_KEY(nid), - get_stream_param); -} - /** * snd_hda_query_supported_pcm - query the supported PCM rates and formats * @codec: the HDA codec diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index 135b70f066f1..6af801a5bf89 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h @@ -163,12 +163,6 @@ struct hda_cache_head { u16 next; }; -struct hda_amp_info { - struct hda_cache_head head; - u32 amp_caps; /* amp capabilities */ - u16 vol[2]; /* current volume & mute */ -}; - struct hda_cache_rec { u16 hash[64]; /* hash table for index */ struct snd_array buf; /* record entries */ @@ -257,7 +251,6 @@ struct hda_codec { struct snd_array mixers; /* list of assigned mixer elements */ struct snd_array nids; /* list of mapped mixer elements */ - struct hda_cache_rec amp_cache; /* cache for amp access */ struct hda_cache_rec cmd_cache; /* cache for other commands */ struct list_head conn_list; /* linked-list of connection-list */ diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h index 7023eeee8b9d..3b567f42296b 100644 --- a/sound/pci/hda/hda_local.h +++ b/sound/pci/hda/hda_local.h @@ -557,9 +557,41 @@ static inline void snd_hda_override_wcaps(struct hda_codec *codec, u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction); int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, unsigned int caps); -u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid); -int snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid, - unsigned int caps); +/** + * snd_hda_query_pin_caps - Query PIN capabilities + * @codec: the HD-auio codec + * @nid: the NID to query + * + * Query PIN capabilities for the given widget. + * Returns the obtained capability bits. + * + * When cap bits have been already read, this doesn't read again but + * returns the cached value. + */ +static inline u32 +snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid) +{ + return snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP); + +} + +/** + * snd_hda_override_pin_caps - Override the pin capabilities + * @codec: the CODEC + * @nid: the NID to override + * @caps: the capability bits to set + * + * Override the cached PIN capabilitiy bits value by the given one. + * + * Returns zero if successful or a negative error code. + */ +static inline int +snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid, + unsigned int caps) +{ + return snd_hdac_override_parm(&codec->core, nid, AC_PAR_PIN_CAP, caps); +} + bool snd_hda_check_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, unsigned int bits); -- cgit v1.2.3 From a551d91473e5e3a591f6fe86ac5a5fb460c3f96a Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 26 Feb 2015 12:34:49 +0100 Subject: ALSA: hda - Use regmap for command verb caches, too Like the previous patches, this patch converts also to the regmap, at this time, the cached verb writes are the target. But this conversion needs a bit more caution than before. - In the old code, we just record any verbs as is, and restore them at resume. For the regmap scheme, this doesn't work, since a few verbs like AMP or DIGI_CONVERT are asymmetrical. Such verbs are converted either to the dedicated function (snd_hda_regmap_xxx_amp()) or changed to the unified verb. - Some verbs have to be declared as vendor-specific ones before accessing via regmap. Also, the minor optimization with codec->cached_write flag is dropped in a few places, as this would confuse the operation. Further optimizations will be brought in the later patches, if any. This conversion ends up with a drop of significant amount of codes, mostly the helper codes that are no longer used. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_codec.c | 271 ++++------------------------------------- sound/pci/hda/hda_codec.h | 34 ++---- sound/pci/hda/hda_generic.c | 14 +-- sound/pci/hda/patch_analog.c | 16 +-- sound/pci/hda/patch_conexant.c | 5 +- sound/pci/hda/patch_hdmi.c | 2 +- sound/pci/hda/patch_realtek.c | 2 - sound/pci/hda/patch_si3054.c | 4 + sound/pci/hda/patch_sigmatel.c | 25 ++-- 9 files changed, 64 insertions(+), 309 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index b27f250088c1..41851f9b48c1 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -807,10 +807,6 @@ static void hda_jackpoll_work(struct work_struct *work) codec->jackpoll_interval); } -static void init_hda_cache(struct hda_cache_rec *cache, - unsigned int record_size); -static void free_hda_cache(struct hda_cache_rec *cache); - /* release all pincfg lists */ static void free_init_pincfgs(struct hda_codec *codec) { @@ -929,9 +925,6 @@ void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec) codec->proc_widget_hook = NULL; codec->spec = NULL; - free_hda_cache(&codec->cmd_cache); - init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head)); - /* free only driver_pins so that init_pins + user_pins are restored */ snd_array_free(&codec->driver_pins); snd_array_free(&codec->cvt_setups); @@ -994,7 +987,6 @@ static void snd_hda_codec_dev_release(struct device *dev) free_init_pincfgs(codec); snd_hdac_device_exit(&codec->core); snd_hda_sysfs_clear(codec); - free_hda_cache(&codec->cmd_cache); kfree(codec->modelname); kfree(codec->wcaps); kfree(codec); @@ -1047,8 +1039,6 @@ int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card, codec->addr = codec_addr; mutex_init(&codec->spdif_mutex); mutex_init(&codec->control_mutex); - mutex_init(&codec->hash_mutex); - init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head)); snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 32); snd_array_init(&codec->nids, sizeof(struct hda_nid_item), 32); snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16); @@ -1316,66 +1306,6 @@ static void hda_cleanup_all_streams(struct hda_codec *codec) * amp access functions */ -/* FIXME: more better hash key? */ -#define HDA_HASH_KEY(nid, dir, idx) (u32)((nid) + ((idx) << 16) + ((dir) << 24)) -#define HDA_HASH_PINCAP_KEY(nid) (u32)((nid) + (0x02 << 24)) -#define HDA_HASH_PARPCM_KEY(nid) (u32)((nid) + (0x03 << 24)) -#define HDA_HASH_PARSTR_KEY(nid) (u32)((nid) + (0x04 << 24)) -#define INFO_AMP_CAPS (1<<0) -#define INFO_AMP_VOL(ch) (1 << (1 + (ch))) - -/* initialize the hash table */ -static void init_hda_cache(struct hda_cache_rec *cache, - unsigned int record_size) -{ - memset(cache, 0, sizeof(*cache)); - memset(cache->hash, 0xff, sizeof(cache->hash)); - snd_array_init(&cache->buf, record_size, 64); -} - -static void free_hda_cache(struct hda_cache_rec *cache) -{ - snd_array_free(&cache->buf); -} - -/* query the hash. allocate an entry if not found. */ -static struct hda_cache_head *get_hash(struct hda_cache_rec *cache, u32 key) -{ - u16 idx = key % (u16)ARRAY_SIZE(cache->hash); - u16 cur = cache->hash[idx]; - struct hda_cache_head *info; - - while (cur != 0xffff) { - info = snd_array_elem(&cache->buf, cur); - if (info->key == key) - return info; - cur = info->next; - } - return NULL; -} - -/* query the hash. allocate an entry if not found. */ -static struct hda_cache_head *get_alloc_hash(struct hda_cache_rec *cache, - u32 key) -{ - struct hda_cache_head *info = get_hash(cache, key); - if (!info) { - u16 idx, cur; - /* add a new hash entry */ - info = snd_array_new(&cache->buf); - if (!info) - return NULL; - cur = snd_array_index(&cache->buf, info); - info->key = key; - info->val = 0; - info->dirty = 0; - idx = key % (u16)ARRAY_SIZE(cache->hash); - info->next = cache->hash[idx]; - cache->hash[idx] = cur; - } - return info; -} - /** * query_amp_caps - query AMP capabilities * @codec: the HD-auio codec @@ -2589,25 +2519,35 @@ static unsigned int convert_to_spdif_status(unsigned short val) /* set digital convert verbs both for the given NID and its slaves */ static void set_dig_out(struct hda_codec *codec, hda_nid_t nid, - int verb, int val) + int mask, int val) { const hda_nid_t *d; - snd_hda_codec_write_cache(codec, nid, 0, verb, val); + snd_hdac_regmap_update(&codec->core, nid, AC_VERB_SET_DIGI_CONVERT_1, + mask, val); d = codec->slave_dig_outs; if (!d) return; for (; *d; d++) - snd_hda_codec_write_cache(codec, *d, 0, verb, val); + snd_hdac_regmap_update(&codec->core, nid, + AC_VERB_SET_DIGI_CONVERT_1, mask, val); } static inline void set_dig_out_convert(struct hda_codec *codec, hda_nid_t nid, int dig1, int dig2) { - if (dig1 != -1) - set_dig_out(codec, nid, AC_VERB_SET_DIGI_CONVERT_1, dig1); - if (dig2 != -1) - set_dig_out(codec, nid, AC_VERB_SET_DIGI_CONVERT_2, dig2); + unsigned int mask = 0; + unsigned int val = 0; + + if (dig1 != -1) { + mask |= 0xff; + val = dig1; + } + if (dig2 != -1) { + mask |= 0xff00; + val |= dig2 << 8; + } + set_dig_out(codec, nid, mask, val); } static int snd_hda_spdif_default_put(struct snd_kcontrol *kcontrol, @@ -2740,6 +2680,7 @@ int snd_hda_create_dig_out_ctls(struct hda_codec *codec, struct snd_kcontrol *kctl; struct snd_kcontrol_new *dig_mix; int idx = 0; + int val = 0; const int spdif_index = 16; struct hda_spdif_out *spdif; struct hda_bus *bus = codec->bus; @@ -2780,8 +2721,9 @@ int snd_hda_create_dig_out_ctls(struct hda_codec *codec, return err; } spdif->nid = cvt_nid; - spdif->ctls = snd_hda_codec_read(codec, cvt_nid, 0, - AC_VERB_GET_DIGI_CONVERT_1, 0); + snd_hdac_regmap_read(&codec->core, cvt_nid, + AC_VERB_GET_DIGI_CONVERT_1, &val); + spdif->ctls = val; spdif->status = convert_to_spdif_status(spdif->ctls); return 0; } @@ -2925,8 +2867,8 @@ static int snd_hda_spdif_in_switch_put(struct snd_kcontrol *kcontrol, change = codec->spdif_in_enable != val; if (change) { codec->spdif_in_enable = val; - snd_hda_codec_write_cache(codec, nid, 0, - AC_VERB_SET_DIGI_CONVERT_1, val); + snd_hdac_regmap_write(&codec->core, nid, + AC_VERB_SET_DIGI_CONVERT_1, val); } mutex_unlock(&codec->spdif_mutex); return change; @@ -2937,10 +2879,11 @@ static int snd_hda_spdif_in_status_get(struct snd_kcontrol *kcontrol, { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); hda_nid_t nid = kcontrol->private_value; - unsigned short val; + unsigned int val; unsigned int sbits; - val = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_DIGI_CONVERT_1, 0); + snd_hdac_regmap_read(&codec->core, nid, + AC_VERB_GET_DIGI_CONVERT_1, &val); sbits = convert_to_spdif_status(val); ucontrol->value.iec958.status[0] = sbits; ucontrol->value.iec958.status[1] = sbits >> 8; @@ -3006,154 +2949,6 @@ int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid) } EXPORT_SYMBOL_GPL(snd_hda_create_spdif_in_ctls); -/* - * command cache - */ - -/* build a 31bit cache key with the widget id and the command parameter */ -#define build_cmd_cache_key(nid, verb) ((verb << 8) | nid) -#define get_cmd_cache_nid(key) ((key) & 0xff) -#define get_cmd_cache_cmd(key) (((key) >> 8) & 0xffff) - -/** - * snd_hda_codec_write_cache - send a single command with caching - * @codec: the HDA codec - * @nid: NID to send the command - * @flags: optional bit flags - * @verb: the verb to send - * @parm: the parameter for the verb - * - * Send a single command without waiting for response. - * - * Returns 0 if successful, or a negative error code. - */ -int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid, - int flags, unsigned int verb, unsigned int parm) -{ - int err; - struct hda_cache_head *c; - u32 key; - unsigned int cache_only; - - cache_only = codec->cached_write; - if (!cache_only) { - err = snd_hda_codec_write(codec, nid, flags, verb, parm); - if (err < 0) - return err; - } - - /* parm may contain the verb stuff for get/set amp */ - verb = verb | (parm >> 8); - parm &= 0xff; - key = build_cmd_cache_key(nid, verb); - mutex_lock(&codec->bus->core.cmd_mutex); - c = get_alloc_hash(&codec->cmd_cache, key); - if (c) { - c->val = parm; - c->dirty = cache_only; - } - mutex_unlock(&codec->bus->core.cmd_mutex); - return 0; -} -EXPORT_SYMBOL_GPL(snd_hda_codec_write_cache); - -/** - * snd_hda_codec_update_cache - check cache and write the cmd only when needed - * @codec: the HDA codec - * @nid: NID to send the command - * @flags: optional bit flags - * @verb: the verb to send - * @parm: the parameter for the verb - * - * This function works like snd_hda_codec_write_cache(), but it doesn't send - * command if the parameter is already identical with the cached value. - * If not, it sends the command and refreshes the cache. - * - * Returns 0 if successful, or a negative error code. - */ -int snd_hda_codec_update_cache(struct hda_codec *codec, hda_nid_t nid, - int flags, unsigned int verb, unsigned int parm) -{ - struct hda_cache_head *c; - u32 key; - - /* parm may contain the verb stuff for get/set amp */ - verb = verb | (parm >> 8); - parm &= 0xff; - key = build_cmd_cache_key(nid, verb); - mutex_lock(&codec->bus->core.cmd_mutex); - c = get_hash(&codec->cmd_cache, key); - if (c && c->val == parm) { - mutex_unlock(&codec->bus->core.cmd_mutex); - return 0; - } - mutex_unlock(&codec->bus->core.cmd_mutex); - return snd_hda_codec_write_cache(codec, nid, flags, verb, parm); -} -EXPORT_SYMBOL_GPL(snd_hda_codec_update_cache); - -/** - * snd_hda_codec_resume_cache - Resume the all commands from the cache - * @codec: HD-audio codec - * - * Execute all verbs recorded in the command caches to resume. - */ -void snd_hda_codec_resume_cache(struct hda_codec *codec) -{ - int i; - - mutex_lock(&codec->hash_mutex); - codec->cached_write = 0; - for (i = 0; i < codec->cmd_cache.buf.used; i++) { - struct hda_cache_head *buffer; - u32 key; - - buffer = snd_array_elem(&codec->cmd_cache.buf, i); - key = buffer->key; - if (!key) - continue; - if (!buffer->dirty) - continue; - buffer->dirty = 0; - mutex_unlock(&codec->hash_mutex); - snd_hda_codec_write(codec, get_cmd_cache_nid(key), 0, - get_cmd_cache_cmd(key), buffer->val); - mutex_lock(&codec->hash_mutex); - } - mutex_unlock(&codec->hash_mutex); -} -EXPORT_SYMBOL_GPL(snd_hda_codec_resume_cache); - -/** - * snd_hda_sequence_write_cache - sequence writes with caching - * @codec: the HDA codec - * @seq: VERB array to send - * - * Send the commands sequentially from the given array. - * Thte commands are recorded on cache for power-save and resume. - * The array must be terminated with NID=0. - */ -void snd_hda_sequence_write_cache(struct hda_codec *codec, - const struct hda_verb *seq) -{ - for (; seq->nid; seq++) - snd_hda_codec_write_cache(codec, seq->nid, 0, seq->verb, - seq->param); -} -EXPORT_SYMBOL_GPL(snd_hda_sequence_write_cache); - -/** - * snd_hda_codec_flush_cache - Execute all pending (cached) amps / verbs - * @codec: HD-audio codec - */ -void snd_hda_codec_flush_cache(struct hda_codec *codec) -{ - if (codec->core.regmap) - regcache_sync(codec->core.regmap); - snd_hda_codec_resume_cache(codec); -} -EXPORT_SYMBOL_GPL(snd_hda_codec_flush_cache); - /** * snd_hda_codec_set_power_to_all - Set the power state to all widgets * @codec: the HDA codec @@ -3354,17 +3149,6 @@ static unsigned int hda_call_codec_suspend(struct hda_codec *codec) return state; } -/* mark all entries of cmd and amp caches dirty */ -static void hda_mark_cmd_cache_dirty(struct hda_codec *codec) -{ - int i; - for (i = 0; i < codec->cmd_cache.buf.used; i++) { - struct hda_cache_head *cmd; - cmd = snd_array_elem(&codec->cmd_cache.buf, i); - cmd->dirty = 1; - } -} - /* * kick up codec; used both from PM and power-save */ @@ -3375,8 +3159,6 @@ static void hda_call_codec_resume(struct hda_codec *codec) if (codec->core.regmap) regcache_mark_dirty(codec->core.regmap); - hda_mark_cmd_cache_dirty(codec); - codec->power_jiffies = jiffies; hda_set_power_state(codec, AC_PWRST_D0); @@ -3390,7 +3172,6 @@ static void hda_call_codec_resume(struct hda_codec *codec) codec->patch_ops.init(codec); if (codec->core.regmap) regcache_sync(codec->core.regmap); - snd_hda_codec_resume_cache(codec); } if (codec->jackpoll_interval) diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index 6af801a5bf89..26cbb1fa9729 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h @@ -155,19 +155,6 @@ struct hda_codec_ops { void (*stream_pm)(struct hda_codec *codec, hda_nid_t nid, bool on); }; -/* record for amp information cache */ -struct hda_cache_head { - u32 key:31; /* hash key */ - u32 dirty:1; - u16 val; /* assigned value */ - u16 next; -}; - -struct hda_cache_rec { - u16 hash[64]; /* hash table for index */ - struct snd_array buf; /* record entries */ -}; - /* PCM callbacks */ struct hda_pcm_ops { int (*open)(struct hda_pcm_stream *info, struct hda_codec *codec, @@ -251,13 +238,10 @@ struct hda_codec { struct snd_array mixers; /* list of assigned mixer elements */ struct snd_array nids; /* list of mapped mixer elements */ - struct hda_cache_rec cmd_cache; /* cache for other commands */ - struct list_head conn_list; /* linked-list of connection-list */ struct mutex spdif_mutex; struct mutex control_mutex; - struct mutex hash_mutex; struct snd_array spdif_out; unsigned int spdif_in_enable; /* SPDIF input enable? */ const hda_nid_t *slave_dig_outs; /* optional digital out slave widgets */ @@ -406,15 +390,15 @@ snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex) } /* cached write */ -int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid, - int flags, unsigned int verb, unsigned int parm); -void snd_hda_sequence_write_cache(struct hda_codec *codec, - const struct hda_verb *seq); -int snd_hda_codec_update_cache(struct hda_codec *codec, hda_nid_t nid, - int flags, unsigned int verb, unsigned int parm); -void snd_hda_codec_resume_cache(struct hda_codec *codec); -/* both for cmd & amp caches */ -void snd_hda_codec_flush_cache(struct hda_codec *codec); +static inline int +snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid, + int flags, unsigned int verb, unsigned int parm) +{ + return snd_hdac_regmap_write(&codec->core, nid, verb, parm); +} + +#define snd_hda_codec_update_cache(codec, nid, flags, verb, parm) \ + snd_hda_codec_write_cache(codec, nid, flags, verb, parm) /* the struct for codec->pin_configs */ struct hda_pincfg { diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c index 4850f92c89c4..f7ccef5559de 100644 --- a/sound/pci/hda/hda_generic.c +++ b/sound/pci/hda/hda_generic.c @@ -3381,11 +3381,6 @@ static int cap_put_caller(struct snd_kcontrol *kcontrol, imux = &spec->input_mux; adc_idx = kcontrol->id.index; mutex_lock(&codec->control_mutex); - /* we use the cache-only update at first since multiple input paths - * may shared the same amp; by updating only caches, the redundant - * writes to hardware can be reduced. - */ - codec->cached_write = 1; for (i = 0; i < imux->num_items; i++) { path = get_input_path(codec, adc_idx, i); if (!path || !path->ctls[type]) @@ -3393,12 +3388,9 @@ static int cap_put_caller(struct snd_kcontrol *kcontrol, kcontrol->private_value = path->ctls[type]; err = func(kcontrol, ucontrol); if (err < 0) - goto error; + break; } - error: - codec->cached_write = 0; mutex_unlock(&codec->control_mutex); - snd_hda_codec_flush_cache(codec); /* flush the updates */ if (err >= 0 && spec->cap_sync_hook) spec->cap_sync_hook(codec, kcontrol, ucontrol); return err; @@ -5760,8 +5752,6 @@ int snd_hda_gen_init(struct hda_codec *codec) snd_hda_apply_verbs(codec); - codec->cached_write = 1; - init_multi_out(codec); init_extra_out(codec); init_multi_io(codec); @@ -5777,7 +5767,7 @@ int snd_hda_gen_init(struct hda_codec *codec) /* call init functions of standard auto-mute helpers */ update_automute_all(codec); - snd_hda_codec_flush_cache(codec); + regcache_sync(codec->core.regmap); if (spec->vmaster_mute.sw_kctl && spec->vmaster_mute.hook) snd_hda_sync_vmaster_hook(&spec->vmaster_mute); diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c index 2278e83234b5..231f89029779 100644 --- a/sound/pci/hda/patch_analog.c +++ b/sound/pci/hda/patch_analog.c @@ -777,7 +777,6 @@ static int ad1988_auto_smux_enum_put(struct snd_kcontrol *kcontrol, return 0; mutex_lock(&codec->control_mutex); - codec->cached_write = 1; path = snd_hda_get_path_from_idx(codec, spec->smux_paths[spec->cur_smux]); if (path) @@ -786,9 +785,7 @@ static int ad1988_auto_smux_enum_put(struct snd_kcontrol *kcontrol, if (path) snd_hda_activate_path(codec, path, true, true); spec->cur_smux = val; - codec->cached_write = 0; mutex_unlock(&codec->control_mutex); - snd_hda_codec_flush_cache(codec); /* flush the updates */ return 1; } @@ -1004,18 +1001,17 @@ static void ad1884_fixup_hp_eapd(struct hda_codec *codec, const struct hda_fixup *fix, int action) { struct ad198x_spec *spec = codec->spec; - static const struct hda_verb gpio_init_verbs[] = { - {0x01, AC_VERB_SET_GPIO_MASK, 0x02}, - {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02}, - {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, - {}, - }; switch (action) { case HDA_FIXUP_ACT_PRE_PROBE: spec->gen.vmaster_mute.hook = ad1884_vmaster_hp_gpio_hook; spec->gen.own_eapd_ctl = 1; - snd_hda_sequence_write_cache(codec, gpio_init_verbs); + snd_hda_codec_write_cache(codec, 0x01, 0, + AC_VERB_SET_GPIO_MASK, 0x02); + snd_hda_codec_write_cache(codec, 0x01, 0, + AC_VERB_SET_GPIO_DIRECTION, 0x02); + snd_hda_codec_write_cache(codec, 0x01, 0, + AC_VERB_SET_GPIO_DATA, 0x02); break; case HDA_FIXUP_ACT_PROBE: if (spec->gen.autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT) diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c index 1e21f9fbd54b..f8f0dfbef149 100644 --- a/sound/pci/hda/patch_conexant.c +++ b/sound/pci/hda/patch_conexant.c @@ -302,6 +302,7 @@ static void cxt_fixup_headphone_mic(struct hda_codec *codec, switch (action) { case HDA_FIXUP_ACT_PRE_PROBE: spec->parse_flags |= HDA_PINCFG_HEADPHONE_MIC; + snd_hdac_regmap_add_vendor_verb(&codec->core, 0x410); break; case HDA_FIXUP_ACT_PROBE: spec->gen.cap_sync_hook = cxt_update_headset_mode_hook; @@ -409,15 +410,11 @@ static void olpc_xo_automic(struct hda_codec *codec, struct hda_jack_callback *jack) { struct conexant_spec *spec = codec->spec; - int saved_cached_write = codec->cached_write; - codec->cached_write = 1; /* in DC mode, we don't handle automic */ if (!spec->dc_enable) snd_hda_gen_mic_autoswitch(codec, jack); olpc_xo_update_mic_pins(codec); - snd_hda_codec_flush_cache(codec); - codec->cached_write = saved_cached_write; if (spec->dc_enable) olpc_xo_update_mic_boost(codec); } diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c index 04c5ab20eb76..ca0c05e1c42e 100644 --- a/sound/pci/hda/patch_hdmi.c +++ b/sound/pci/hda/patch_hdmi.c @@ -2212,7 +2212,6 @@ static int generic_hdmi_resume(struct hda_codec *codec) codec->patch_ops.init(codec); regcache_sync(codec->core.regmap); - snd_hda_codec_resume_cache(codec); for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); @@ -2299,6 +2298,7 @@ static void intel_haswell_fixup_enable_dp12(struct hda_codec *codec) /* enable DP1.2 mode */ vendor_param |= INTEL_EN_DP12; + snd_hdac_regmap_add_vendor_verb(&codec->core, INTEL_SET_VENDOR_VERB); snd_hda_codec_write_cache(codec, INTEL_VENDOR_NID, 0, INTEL_SET_VENDOR_VERB, vendor_param); } diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c index a440e539230f..d44cb7e37094 100644 --- a/sound/pci/hda/patch_realtek.c +++ b/sound/pci/hda/patch_realtek.c @@ -800,7 +800,6 @@ static int alc_resume(struct hda_codec *codec) msleep(150); /* to avoid pop noise */ codec->patch_ops.init(codec); regcache_sync(codec->core.regmap); - snd_hda_codec_resume_cache(codec); hda_call_check_power_status(codec, 0x01); return 0; } @@ -3059,7 +3058,6 @@ static int alc269_resume(struct hda_codec *codec) } regcache_sync(codec->core.regmap); - snd_hda_codec_resume_cache(codec); hda_call_check_power_status(codec, 0x01); /* on some machine, the BIOS will clear the codec gpio data when enter diff --git a/sound/pci/hda/patch_si3054.c b/sound/pci/hda/patch_si3054.c index 49b4868797a5..5104bebb2286 100644 --- a/sound/pci/hda/patch_si3054.c +++ b/sound/pci/hda/patch_si3054.c @@ -222,6 +222,10 @@ static int si3054_init(struct hda_codec *codec) unsigned wait_count; u16 val; + if (snd_hdac_regmap_add_vendor_verb(&codec->core, + SI3054_VERB_WRITE_NODE)) + return -ENOMEM; + snd_hda_codec_write(codec, AC_NODE_ROOT, 0, AC_VERB_SET_CODEC_RESET, 0); snd_hda_codec_write(codec, codec->core.mfg, 0, AC_VERB_SET_STREAM_FORMAT, 0); SET_REG(codec, SI3054_LINE_RATE, 9600); diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c index b314551749f1..43c99ce4a520 100644 --- a/sound/pci/hda/patch_sigmatel.c +++ b/sound/pci/hda/patch_sigmatel.c @@ -1050,12 +1050,9 @@ static const struct hda_verb stac92hd71bxx_core_init[] = { {} }; -static const struct hda_verb stac92hd71bxx_unmute_core_init[] = { +static const hda_nid_t stac92hd71bxx_unmute_nids[] = { /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */ - { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {} + 0x0f, 0x0a, 0x0d, 0 }; static const struct hda_verb stac925x_core_init[] = { @@ -4269,6 +4266,10 @@ static int stac_parse_auto_config(struct hda_codec *codec) if (spec->aloopback_ctl && snd_hda_get_bool_hint(codec, "loopback") == 1) { + unsigned int wr_verb = + spec->aloopback_ctl->private_value >> 16; + if (snd_hdac_regmap_add_vendor_verb(&codec->core, wr_verb)) + return -ENOMEM; if (!snd_hda_gen_add_kctl(&spec->gen, NULL, spec->aloopback_ctl)) return -ENOMEM; } @@ -4688,7 +4689,7 @@ static int patch_stac92hd95(struct hda_codec *codec) static int patch_stac92hd71bxx(struct hda_codec *codec) { struct sigmatel_spec *spec; - const struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init; + const hda_nid_t *unmute_nids = stac92hd71bxx_unmute_nids; int err; err = alloc_stac_spec(codec); @@ -4713,7 +4714,7 @@ static int patch_stac92hd71bxx(struct hda_codec *codec) switch (codec->core.vendor_id) { case 0x111d76b6: /* 4 Port without Analog Mixer */ case 0x111d76b7: - unmute_init++; + unmute_nids++; break; case 0x111d7608: /* 5 Port with Analog Mixer */ if ((codec->core.revision_id & 0xf) == 0 || @@ -4721,7 +4722,7 @@ static int patch_stac92hd71bxx(struct hda_codec *codec) spec->stream_delay = 40; /* 40 milliseconds */ /* disable VSW */ - unmute_init++; + unmute_nids++; snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0); snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3); break; @@ -4735,8 +4736,12 @@ static int patch_stac92hd71bxx(struct hda_codec *codec) if (get_wcaps_type(get_wcaps(codec, 0x28)) == AC_WID_VOL_KNB) snd_hda_add_verbs(codec, stac92hd71bxx_core_init); - if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP) - snd_hda_sequence_write_cache(codec, unmute_init); + if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP) { + const hda_nid_t *p; + for (p = unmute_nids; *p; p++) + snd_hda_codec_amp_init_stereo(codec, *p, HDA_INPUT, 0, + 0xff, 0x00); + } spec->aloopback_ctl = &stac92hd71bxx_loopback; spec->aloopback_mask = 0x50; -- cgit v1.2.3 From 77008b70fe0a9ffe354580d9dfda329cdde7f20b Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Mon, 23 Mar 2015 12:41:31 +0300 Subject: ALSA: echoaudio: read past end of array We need to cap "ucontrol->id.index / num_busses_in(chip)" so the we don't read beyond the end of the array. I also adding a check on "in" and changing the type in snd_echo_mixer_put() from short to unsigned int. Those changes are done for symmetry and are cosmetic. Signed-off-by: Dan Carpenter Signed-off-by: Takashi Iwai --- sound/pci/echoaudio/echoaudio.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'sound/pci') 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, static int snd_echo_mixer_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - struct echoaudio *chip; + struct echoaudio *chip = snd_kcontrol_chip(kcontrol); + unsigned int out = ucontrol->id.index / num_busses_in(chip); + unsigned int in = ucontrol->id.index % num_busses_in(chip); - chip = snd_kcontrol_chip(kcontrol); - ucontrol->value.integer.value[0] = - chip->monitor_gain[ucontrol->id.index / num_busses_in(chip)] - [ucontrol->id.index % num_busses_in(chip)]; + if (out >= ECHO_MAXAUDIOOUTPUTS || in >= ECHO_MAXAUDIOINPUTS) + return -EINVAL; + + ucontrol->value.integer.value[0] = chip->monitor_gain[out][in]; return 0; } @@ -1297,12 +1299,14 @@ static int snd_echo_mixer_put(struct snd_kcontrol *kcontrol, { struct echoaudio *chip; int changed, gain; - short out, in; + unsigned int out, in; changed = 0; chip = snd_kcontrol_chip(kcontrol); out = ucontrol->id.index / num_busses_in(chip); in = ucontrol->id.index % num_busses_in(chip); + if (out >= ECHO_MAXAUDIOOUTPUTS || in >= ECHO_MAXAUDIOINPUTS) + return -EINVAL; gain = ucontrol->value.integer.value[0]; if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT) return -EINVAL; -- cgit v1.2.3 From 46d212cbe4111351741b85b29dbb106b50d68532 Mon Sep 17 00:00:00 2001 From: Krzysztof Kozlowski Date: Tue, 24 Mar 2015 11:48:24 +0100 Subject: ALSA: asihpi: Fix duplicate const for clock sources Replace duplicated const keyword for 'sampleclock_sources' with proper array of const pointers to const strings. Signed-off-by: Krzysztof Kozlowski Signed-off-by: Takashi Iwai --- sound/pci/asihpi/asihpi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sound/pci') 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, /*------------------------------------------------------------ Sampleclock source controls ------------------------------------------------------------*/ -static const char const *sampleclock_sources[] = { +static const char * const sampleclock_sources[] = { "N/A", "Local PLL", "Digital Sync", "Word External", "Word Header", "SMPTE", "Digital1", "Auto", "Network", "Invalid", "Prev Module", "BLU-Link", -- cgit v1.2.3 From 44e39b985393e506d82b669c9765e850daed9dc5 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Wed, 25 Mar 2015 07:40:33 +0100 Subject: ALSA: hda - Remove superfluous hda_nid_t definition in hda_codec.h Just forgotten to remove. It's now in sound/hdaudio.h. Reported-by: Andrew Morton Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_codec.h | 3 --- 1 file changed, 3 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index 76776164623d..21632174744b 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h @@ -69,9 +69,6 @@ struct hda_codec; struct hda_pcm; struct hda_pcm_stream; -/* NID type */ -typedef u16 hda_nid_t; - /* bus operators */ struct hda_bus_ops { /* send a single command */ -- cgit v1.2.3 From 4738465c37298cd9228750f7e16aad88af8495c5 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 25 Mar 2015 00:43:42 -0700 Subject: ALSA: hda/via - Add beep controls to VIA codecs My codec has a beep-generating node: $ cat /proc/asound/card1/codec#0 Codec: VIA VT1802 ... Vendor Id: 0x11068446 Subsystem Id: 0x15587410 Revision Id: 0x100000 ... Node 0x22 [Beep Generator Widget] wcaps 0x70040c: Mono Amp-Out Amp-Out caps: ofs=0x0a, nsteps=0x12, stepsize=0x05, mute=1 Amp-Out vals: [0x0a] Power states: D0 D1 D2 D3 Power: setting=D0, actual=D0 ... But I was missing the: Control: name=... entries that I need to manage this widget from alsamixer. With this patch (based on the similar Mono Amp-Out handling in patch_conexant.c), I get a new: input: HDA Digital PCBeep as /devices/pci0000:00/0000:00:1b.0/sound/card1/hdaudioC1D0/input15 entry in dmesg and controls to manage that beep: $ cat /proc/asound/card1/codec#0 | grep -A5 Beep Node 0x22 [Beep Generator Widget] wcaps 0x70040c: Mono Amp-Out Control: name="Beep Playback Volume", index=0, device=0 ControlAmp: chs=1, dir=Out, idx=0, ofs=0 Control: name="Beep Playback Switch", index=0, device=0 ControlAmp: chs=1, dir=Out, idx=0, ofs=0 Amp-Out caps: ofs=0x0a, nsteps=0x12, stepsize=0x05, mute=1 Amp-Out vals: [0x12] Power states: D0 D1 D2 D3 Power: setting=D0, actual=D0 [rebased and modified for the latest tree by tiwai] Signed-off-by: W. Trevor King Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'sound/pci') diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index a34d7671937f..742087ef378f 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -107,6 +107,8 @@ struct via_spec { /* work to check hp jack state */ int hp_work_active; int vt1708_jack_detect; + + unsigned int beep_amp; }; static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec); @@ -266,6 +268,59 @@ static const struct snd_kcontrol_new via_pin_power_ctl_enum[] = { {} /* terminator */ }; +#ifdef CONFIG_SND_HDA_INPUT_BEEP +static inline void set_beep_amp(struct via_spec *spec, hda_nid_t nid, + int idx, int dir) +{ + spec->gen.beep_nid = nid; + spec->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir); +} + +/* additional beep mixers; the actual parameters are overwritten at build */ +static const struct snd_kcontrol_new cxt_beep_mixer[] = { + HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT), + HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT), + { } /* end */ +}; + +/* create beep controls if needed */ +static int add_beep_ctls(struct hda_codec *codec) +{ + struct via_spec *spec = codec->spec; + int err; + + if (spec->beep_amp) { + const struct snd_kcontrol_new *knew; + for (knew = cxt_beep_mixer; knew->name; knew++) { + struct snd_kcontrol *kctl; + kctl = snd_ctl_new1(knew, codec); + if (!kctl) + return -ENOMEM; + kctl->private_value = spec->beep_amp; + err = snd_hda_ctl_add(codec, 0, kctl); + if (err < 0) + return err; + } + } + return 0; +} + +static void auto_parse_beep(struct hda_codec *codec) +{ + struct via_spec *spec = codec->spec; + hda_nid_t nid; + + for_each_hda_codec_node(nid, codec) + if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) { + set_beep_amp(spec, nid, 0, HDA_OUTPUT); + break; + } +} +#else +#define set_beep_amp(spec, nid, idx, dir) /* NOP */ +#define add_beep_ctls(codec) 0 +#define auto_parse_beep(codec) +#endif /* check AA path's mute status */ static bool is_aa_path_mute(struct hda_codec *codec) @@ -352,6 +407,10 @@ static int via_build_controls(struct hda_codec *codec) if (err < 0) return err; + err = add_beep_ctls(codec); + if (err < 0) + return err; + spec->mixers[spec->num_mixers++] = via_pin_power_ctl_enum; for (i = 0; i < spec->num_mixers; i++) { @@ -512,6 +571,8 @@ static int via_parse_auto_config(struct hda_codec *codec) if (err < 0) return err; + auto_parse_beep(codec); + err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg); if (err < 0) return err; -- cgit v1.2.3 From d545a57c5f84c01b50187177921e232a450858c7 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Sat, 4 Apr 2015 12:17:28 +0200 Subject: ALSA: hda - Sync node attributes at resume from widget power saving So far we assumed that the node attributes like amp values remain during the power state transition of the node itself. While this is true for IDT/STAC codecs I've tested, but some other codecs don't seem behaving in that way. This patch implements a partial sync mechanism specific to the given widget node. Now we've merged the regmap support, and it can be easily written with regcache_sync_region(). Tested-by: Hui Wang Signed-off-by: Takashi Iwai --- include/sound/hda_regmap.h | 12 ++++++++++++ sound/pci/hda/hda_generic.c | 6 ++---- 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'sound/pci') diff --git a/include/sound/hda_regmap.h b/include/sound/hda_regmap.h index 76648ccfbbf8..53a18b3635e2 100644 --- a/include/sound/hda_regmap.h +++ b/include/sound/hda_regmap.h @@ -202,4 +202,16 @@ snd_hdac_regmap_update_amp_stereo(struct hdac_device *codec, hda_nid_t nid, return snd_hdac_regmap_update_raw(codec, cmd, mask, val); } +/** + * snd_hdac_regmap_sync_node - sync the widget node attributes + * @codec: HD-audio codec + * @nid: NID to sync + */ +static inline void +snd_hdac_regmap_sync_node(struct hdac_device *codec, hda_nid_t nid) +{ + regcache_mark_dirty(codec->regmap); + regcache_sync_region(codec->regmap, nid << 20, ((nid + 1) << 20) - 1); +} + #endif /* __SOUND_HDA_REGMAP_H */ diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c index f7ccef5559de..1f2ca7be1468 100644 --- a/sound/pci/hda/hda_generic.c +++ b/sound/pci/hda/hda_generic.c @@ -842,10 +842,8 @@ static hda_nid_t path_power_update(struct hda_codec *codec, snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, state); changed = nid; - /* here we assume that widget attributes (e.g. amp, - * pinctl connection) don't change with local power - * state change. If not, need to sync the cache. - */ + if (state == AC_PWRST_D0) + snd_hdac_regmap_sync_node(&codec->core, nid); } } return changed; -- cgit v1.2.3 From 382fd7becc409be9cc18dea8e3d53f6d184f9a5c Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Sat, 4 Apr 2015 12:24:00 +0200 Subject: ALSA: hda - Enable widget power saving for Realtek codecs Recent Realtek codecs support the finer power state control on each widget. Let's enable the new feature. Tested-by: Hui Wang Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_realtek.c | 1 + 1 file changed, 1 insertion(+) (limited to 'sound/pci') diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c index d44cb7e37094..e0c06f9a0e80 100644 --- a/sound/pci/hda/patch_realtek.c +++ b/sound/pci/hda/patch_realtek.c @@ -5413,6 +5413,7 @@ static int patch_alc269(struct hda_codec *codec) spec = codec->spec; spec->gen.shared_mic_vref_pin = 0x18; + codec->power_save_node = 1; snd_hda_pick_fixup(codec, alc269_fixup_models, alc269_fixup_tbl, alc269_fixups); -- cgit v1.2.3 From 751e2216899cb143fe1d5909fe762870faa945f6 Mon Sep 17 00:00:00 2001 From: Sudip Mukherjee Date: Thu, 2 Apr 2015 16:51:43 +0530 Subject: ALSA: hda: fix possible null dereference we are dereferencing pcm first then checking pcm. instead now lets put them in same if condition so that pcm is checked first. Signed-off-by: Sudip Mukherjee Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_codec.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 41851f9b48c1..16dfa1ed10dd 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -3230,9 +3230,8 @@ static int add_std_chmaps(struct hda_codec *codec) struct snd_pcm_chmap *chmap; const struct snd_pcm_chmap_elem *elem; - if (pcm->own_chmap) - continue; - if (!pcm || !hinfo->substreams) + if (!pcm || pcm->own_chmap || + !hinfo->substreams) continue; elem = hinfo->chmap ? hinfo->chmap : snd_pcm_std_chmaps; err = snd_pcm_add_chmap_ctls(pcm->pcm, str, elem, -- cgit v1.2.3 From eab0fbfa41040f4f76b173cad17c0c8ed40cba33 Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Sat, 4 Apr 2015 13:38:25 -0700 Subject: ALSA: Use const struct ac97_quirk Use const to reduce data by ~3Kb. Signed-off-by: Joe Perches Signed-off-by: Takashi Iwai --- include/sound/ac97_codec.h | 4 +++- sound/pci/ac97/ac97_codec.c | 3 ++- sound/pci/ad1889.c | 2 +- sound/pci/atiixp.c | 2 +- sound/pci/cs5535audio/cs5535audio.c | 2 +- sound/pci/intel8x0.c | 2 +- sound/pci/via82xx.c | 2 +- 7 files changed, 10 insertions(+), 7 deletions(-) (limited to 'sound/pci') diff --git a/include/sound/ac97_codec.h b/include/sound/ac97_codec.h index d315a08d6c6d..0e9d75b49bed 100644 --- a/include/sound/ac97_codec.h +++ b/include/sound/ac97_codec.h @@ -608,7 +608,9 @@ struct ac97_quirk { int type; /* quirk type above */ }; -int snd_ac97_tune_hardware(struct snd_ac97 *ac97, struct ac97_quirk *quirk, const char *override); +int snd_ac97_tune_hardware(struct snd_ac97 *ac97, + const struct ac97_quirk *quirk, + const char *override); int snd_ac97_set_rate(struct snd_ac97 *ac97, int reg, unsigned int rate); /* diff --git a/sound/pci/ac97/ac97_codec.c b/sound/pci/ac97/ac97_codec.c index 5bca1a33fed6..82259ca61e64 100644 --- a/sound/pci/ac97/ac97_codec.c +++ b/sound/pci/ac97/ac97_codec.c @@ -2902,7 +2902,8 @@ static int apply_quirk_str(struct snd_ac97 *ac97, const char *typestr) * Return: Zero if successful, or a negative error code on failure. */ -int snd_ac97_tune_hardware(struct snd_ac97 *ac97, struct ac97_quirk *quirk, const char *override) +int snd_ac97_tune_hardware(struct snd_ac97 *ac97, + const struct ac97_quirk *quirk, const char *override) { int result; 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) snd_info_set_text_ops(entry, chip, snd_ad1889_proc_read); } -static struct ac97_quirk ac97_quirks[] = { +static const struct ac97_quirk ac97_quirks[] = { { .subvendor = 0x11d4, /* AD */ .subdevice = 0x1889, /* AD1889 */ 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) * ac97 mixer section */ -static struct ac97_quirk ac97_quirks[] = { +static const struct ac97_quirk ac97_quirks[] = { { .subvendor = 0x103c, .subdevice = 0x006b, 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; module_param(ac97_quirk, charp, 0444); MODULE_PARM_DESC(ac97_quirk, "AC'97 board specific workarounds."); -static struct ac97_quirk ac97_quirks[] = { +static const struct ac97_quirk ac97_quirks[] = { #if 0 /* Not yet confirmed if all 5536 boards are HP only */ { .subvendor = PCI_VENDOR_ID_AMD, diff --git a/sound/pci/intel8x0.c b/sound/pci/intel8x0.c index 2c5484eeb963..749069aa6997 100644 --- a/sound/pci/intel8x0.c +++ b/sound/pci/intel8x0.c @@ -1795,7 +1795,7 @@ static struct ac97_pcm ac97_pcm_defs[] = { }, }; -static struct ac97_quirk ac97_quirks[] = { +static const struct ac97_quirk ac97_quirks[] = { { .subvendor = 0x0e11, .subdevice = 0x000e, 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) chip->ac97 = NULL; } -static struct ac97_quirk ac97_quirks[] = { +static const struct ac97_quirk ac97_quirks[] = { { .subvendor = 0x1106, .subdevice = 0x4161, -- cgit v1.2.3 From f32c1c1b46c2bd5fda77b49e28b9f9329cd830d1 Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Sat, 28 Mar 2015 19:20:35 +0100 Subject: ALSA: emu10k1: add Audigy 5/Rx The Audigy 5/Rx is essentially an Audigy 4 behind a PLX PCIe- bridge with an additional TOSLINK output. Signed-off-by: Michael Gernoth Signed-off-by: Takashi Iwai --- sound/pci/emu10k1/emu10k1_main.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'sound/pci') diff --git a/sound/pci/emu10k1/emu10k1_main.c b/sound/pci/emu10k1/emu10k1_main.c index b4458a630a7c..4887299011ef 100644 --- a/sound/pci/emu10k1/emu10k1_main.c +++ b/sound/pci/emu10k1/emu10k1_main.c @@ -1325,6 +1325,22 @@ static int snd_emu10k1_dev_free(struct snd_device *device) } static struct snd_emu_chip_details emu_chip_details[] = { + /* Audigy 5/Rx SB1550 */ + /* Tested by michael@gernoth.net 28 Mar 2015 */ + /* DSP: CA10300-IAT LF + * DAC: Cirrus Logic CS4382-KQZ + * ADC: Philips 1361T + * AC97: Sigmatel STAC9750 + * CA0151: None + */ + {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x10241102, + .driver = "Audigy2", .name = "SB Audigy 5/Rx [SB1550]", + .id = "Audigy2", + .emu10k2_chip = 1, + .ca0108_chip = 1, + .spk71 = 1, + .adc_1361t = 1, /* 24 bit capture instead of 16bit */ + .ac97_chip = 1}, /* Audigy4 (Not PRO) SB0610 */ /* Tested by James@superbug.co.uk 4th April 2006 */ /* A_IOCFG bits -- cgit v1.2.3 From 2d846c74027231264e57e4e34faf9576394e3ce0 Mon Sep 17 00:00:00 2001 From: Libin Yang Date: Tue, 7 Apr 2015 20:32:20 +0800 Subject: ALSA: hda_intel: add AZX_DCAPS_I915_POWERWELL for SKL and BSW HDMI/DP codec on SKL/BSW is in the power well. The power well must be turned on before probing the HDMI/DP codec. This is a temporary patch, which will power on the powerwell by adding AZX_DCAPS_I915_POWERWELL for SKL and BSW. After restructuring and new flag is added, this patch will be reverted. Signed-off-by: Libin Yang Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_intel.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index feebc1dda912..9bcc5457a83e 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c @@ -297,8 +297,12 @@ enum { AZX_DCAPS_PM_RUNTIME | AZX_DCAPS_I915_POWERWELL |\ AZX_DCAPS_SNOOP_TYPE(SCH)) +#define AZX_DCAPS_INTEL_BRASWELL \ + (AZX_DCAPS_INTEL_PCH | AZX_DCAPS_I915_POWERWELL) + #define AZX_DCAPS_INTEL_SKYLAKE \ - (AZX_DCAPS_INTEL_PCH | AZX_DCAPS_SEPARATE_STREAM_TAG) + (AZX_DCAPS_INTEL_PCH | AZX_DCAPS_SEPARATE_STREAM_TAG |\ + AZX_DCAPS_I915_POWERWELL) /* quirks for ATI SB / AMD Hudson */ #define AZX_DCAPS_PRESET_ATI_SB \ @@ -1991,7 +1995,7 @@ static const struct pci_device_id azx_ids[] = { .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH_NOPM }, /* Braswell */ { PCI_DEVICE(0x8086, 0x2284), - .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH }, + .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_BRASWELL }, /* ICH6 */ { PCI_DEVICE(0x8086, 0x2668), .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_INTEL_ICH }, -- cgit v1.2.3 From f3b703326541d0c1ce85f5e570f6d2b6bd4296ec Mon Sep 17 00:00:00 2001 From: Kailang Yang Date: Wed, 8 Apr 2015 15:01:17 +0800 Subject: ALSA: hda/realtek - Support headset mode for ALC286/288 Support headset mode for ALC286 and ALC288 platforms. Signed-off-by: Kailang Yang Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_realtek.c | 77 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) (limited to 'sound/pci') diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c index 7f46d063af57..ceb599a87803 100644 --- a/sound/pci/hda/patch_realtek.c +++ b/sound/pci/hda/patch_realtek.c @@ -3542,6 +3542,14 @@ static void alc_headset_mode_unplugged(struct hda_codec *codec) WRITE_COEF(0x32, 0x42a3), {} }; + static struct coef_fw coef0288[] = { + UPDATE_COEF(0x4f, 0xfcc0, 0xc400), + UPDATE_COEF(0x50, 0x2000, 0x2000), + UPDATE_COEF(0x56, 0x0006, 0x0006), + UPDATE_COEF(0x66, 0x0008, 0), + UPDATE_COEF(0x67, 0x2000, 0), + {} + }; static struct coef_fw coef0292[] = { WRITE_COEF(0x76, 0x000e), WRITE_COEF(0x6c, 0x2400), @@ -3573,6 +3581,10 @@ static void alc_headset_mode_unplugged(struct hda_codec *codec) case 0x10ec0283: alc_process_coef_fw(codec, coef0233); break; + case 0x10ec0286: + case 0x10ec0288: + alc_process_coef_fw(codec, coef0288); + break; case 0x10ec0292: alc_process_coef_fw(codec, coef0292); break; @@ -3602,6 +3614,14 @@ static void alc_headset_mode_mic_in(struct hda_codec *codec, hda_nid_t hp_pin, WRITE_COEF(0x26, 0x008c), {} }; + static struct coef_fw coef0288[] = { + UPDATE_COEF(0x50, 0x2000, 0), + UPDATE_COEF(0x56, 0x0006, 0), + UPDATE_COEF(0x4f, 0xfcc0, 0xc400), + UPDATE_COEF(0x66, 0x0008, 0x0008), + UPDATE_COEF(0x67, 0x2000, 0x2000), + {} + }; static struct coef_fw coef0292[] = { WRITE_COEF(0x19, 0xa208), WRITE_COEF(0x2e, 0xacf0), @@ -3635,6 +3655,13 @@ static void alc_headset_mode_mic_in(struct hda_codec *codec, hda_nid_t hp_pin, alc_process_coef_fw(codec, coef0233); snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50); break; + case 0x10ec0286: + case 0x10ec0288: + alc_update_coef_idx(codec, 0x4f, 0x000c, 0); + snd_hda_set_pin_ctl_cache(codec, hp_pin, 0); + alc_process_coef_fw(codec, coef0288); + snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50); + break; case 0x10ec0292: snd_hda_set_pin_ctl_cache(codec, hp_pin, 0); alc_process_coef_fw(codec, coef0292); @@ -3670,6 +3697,14 @@ static void alc_headset_mode_default(struct hda_codec *codec) WRITE_COEF(0x32, 0x4ea3), {} }; + static struct coef_fw coef0288[] = { + UPDATE_COEF(0x4f, 0xfcc0, 0xc400), /* Set to TRS type */ + UPDATE_COEF(0x50, 0x2000, 0x2000), + UPDATE_COEF(0x56, 0x0006, 0x0006), + UPDATE_COEF(0x66, 0x0008, 0), + UPDATE_COEF(0x67, 0x2000, 0), + {} + }; static struct coef_fw coef0292[] = { WRITE_COEF(0x76, 0x000e), WRITE_COEF(0x6c, 0x2400), @@ -3699,6 +3734,11 @@ static void alc_headset_mode_default(struct hda_codec *codec) case 0x10ec0283: alc_process_coef_fw(codec, coef0233); break; + case 0x10ec0286: + case 0x10ec0288: + alc_process_coef_fw(codec, coef0288); + break; + break; case 0x10ec0292: alc_process_coef_fw(codec, coef0292); break; @@ -3727,6 +3767,13 @@ static void alc_headset_mode_ctia(struct hda_codec *codec) WRITE_COEF(0x32, 0x4ea3), {} }; + static struct coef_fw coef0288[] = { + UPDATE_COEF(0x50, 0x2000, 0x2000), + UPDATE_COEF(0x56, 0x0006, 0x0006), + UPDATE_COEF(0x66, 0x0008, 0), + UPDATE_COEF(0x67, 0x2000, 0), + {} + }; static struct coef_fw coef0292[] = { WRITE_COEF(0x6b, 0xd429), WRITE_COEF(0x76, 0x0008), @@ -3754,6 +3801,12 @@ static void alc_headset_mode_ctia(struct hda_codec *codec) case 0x10ec0283: alc_process_coef_fw(codec, coef0233); break; + case 0x10ec0286: + case 0x10ec0288: + alc_update_coef_idx(codec, 0x4f, 0xfcc0, 0xd400); + msleep(300); + alc_process_coef_fw(codec, coef0288); + break; case 0x10ec0292: alc_process_coef_fw(codec, coef0292); break; @@ -3782,6 +3835,13 @@ static void alc_headset_mode_omtp(struct hda_codec *codec) WRITE_COEF(0x32, 0x4ea3), {} }; + static struct coef_fw coef0288[] = { + UPDATE_COEF(0x50, 0x2000, 0x2000), + UPDATE_COEF(0x56, 0x0006, 0x0006), + UPDATE_COEF(0x66, 0x0008, 0), + UPDATE_COEF(0x67, 0x2000, 0), + {} + }; static struct coef_fw coef0292[] = { WRITE_COEF(0x6b, 0xe429), WRITE_COEF(0x76, 0x0008), @@ -3809,6 +3869,12 @@ static void alc_headset_mode_omtp(struct hda_codec *codec) case 0x10ec0283: alc_process_coef_fw(codec, coef0233); break; + case 0x10ec0286: + case 0x10ec0288: + alc_update_coef_idx(codec, 0x4f, 0xfcc0, 0xe400); + msleep(300); + alc_process_coef_fw(codec, coef0288); + break; case 0x10ec0292: alc_process_coef_fw(codec, coef0292); break; @@ -3833,6 +3899,10 @@ static void alc_determine_headset_type(struct hda_codec *codec) conteol) */ {} }; + static struct coef_fw coef0288[] = { + UPDATE_COEF(0x4f, 0xfcc0, 0xd400), /* Check Type */ + {} + }; static struct coef_fw coef0293[] = { UPDATE_COEF(0x4a, 0x000f, 0x0008), /* Combo Jack auto detect */ WRITE_COEF(0x45, 0xD429), /* Set to ctia type */ @@ -3861,6 +3931,13 @@ static void alc_determine_headset_type(struct hda_codec *codec) val = alc_read_coef_idx(codec, 0x46); is_ctia = (val & 0x0070) == 0x0070; break; + case 0x10ec0286: + case 0x10ec0288: + alc_process_coef_fw(codec, coef0288); + msleep(350); + val = alc_read_coef_idx(codec, 0x50); + is_ctia = (val & 0x0070) == 0x0070; + break; case 0x10ec0292: alc_write_coef_idx(codec, 0x6b, 0xd429); msleep(300); -- cgit v1.2.3 From e1e62b98ebddc3234f3259019d3236f66fc667f8 Mon Sep 17 00:00:00 2001 From: Kailang Yang Date: Wed, 8 Apr 2015 16:01:22 +0800 Subject: ALSA: hda/realtek - Support Dell headset mode for ALC288 Dell create new platform with ALC288 codec. This patch will enable headset mode for Dino platform. [slight code refactoring and compile fix by tiwai] Signed-off-by: Kailang Yang Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_realtek.c | 67 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) (limited to 'sound/pci') diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c index ceb599a87803..7b5c93e0e78c 100644 --- a/sound/pci/hda/patch_realtek.c +++ b/sound/pci/hda/patch_realtek.c @@ -4121,6 +4121,29 @@ static void alc_fixup_headset_mode_alc255_no_hp_mic(struct hda_codec *codec, alc_fixup_headset_mode(codec, fix, action); } +static void alc288_update_headset_jack_cb(struct hda_codec *codec, + struct hda_jack_callback *jack) +{ + struct alc_spec *spec = codec->spec; + int present; + + alc_update_headset_jack_cb(codec, jack); + /* Headset Mic enable or disable, only for Dell Dino */ + present = spec->gen.hp_jack_present ? 0x40 : 0; + snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, + present); +} + +static void alc_fixup_headset_mode_dell_alc288(struct hda_codec *codec, + const struct hda_fixup *fix, int action) +{ + alc_fixup_headset_mode(codec, fix, action); + if (action == HDA_FIXUP_ACT_PROBE) { + struct alc_spec *spec = codec->spec; + spec->gen.hp_automute_hook = alc288_update_headset_jack_cb; + } +} + static void alc_fixup_auto_mute_via_amp(struct hda_codec *codec, const struct hda_fixup *fix, int action) { @@ -4460,6 +4483,9 @@ enum { ALC286_FIXUP_HP_GPIO_LED, ALC280_FIXUP_HP_GPIO2_MIC_HOTKEY, ALC280_FIXUP_HP_DOCK_PINS, + ALC288_FIXUP_DELL_HEADSET_MODE, + ALC288_FIXUP_DELL1_MIC_NO_PRESENCE, + ALC288_FIXUP_DELL_XPS_13_GPIO6, }; static const struct hda_fixup alc269_fixups[] = { @@ -4948,6 +4974,33 @@ static const struct hda_fixup alc269_fixups[] = { .chained = true, .chain_id = ALC280_FIXUP_HP_GPIO4 }, + [ALC288_FIXUP_DELL_HEADSET_MODE] = { + .type = HDA_FIXUP_FUNC, + .v.func = alc_fixup_headset_mode_dell_alc288, + .chained = true, + .chain_id = ALC255_FIXUP_DELL_WMI_MIC_MUTE_LED + }, + [ALC288_FIXUP_DELL1_MIC_NO_PRESENCE] = { + .type = HDA_FIXUP_PINS, + .v.pins = (const struct hda_pintbl[]) { + { 0x18, 0x01a1913c }, /* use as headset mic, without its own jack detect */ + { 0x1a, 0x01a1913d }, /* use as headphone mic, without its own jack detect */ + { } + }, + .chained = true, + .chain_id = ALC288_FIXUP_DELL_HEADSET_MODE + }, + [ALC288_FIXUP_DELL_XPS_13_GPIO6] = { + .type = HDA_FIXUP_VERBS, + .v.verbs = (const struct hda_verb[]) { + {0x01, AC_VERB_SET_GPIO_MASK, 0x40}, + {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x40}, + {0x01, AC_VERB_SET_GPIO_DATA, 0x00}, + { } + }, + .chained = true, + .chain_id = ALC288_FIXUP_DELL1_MIC_NO_PRESENCE + }, }; static const struct snd_pci_quirk alc269_fixup_tbl[] = { @@ -5174,6 +5227,13 @@ static const struct hda_model_fixup alc269_fixup_models[] = { {0x1b, 0x411111f0}, \ {0x1e, 0x411111f0} +#define ALC288_STANDARD_PINS \ + {0x17, 0x411111f0}, \ + {0x18, 0x411111f0}, \ + {0x19, 0x411111f0}, \ + {0x1a, 0x411111f0}, \ + {0x1e, 0x411111f0} + #define ALC290_STANDARD_PINS \ {0x12, 0x99a30130}, \ {0x13, 0x40000000}, \ @@ -5369,6 +5429,13 @@ static const struct snd_hda_pin_quirk alc269_pin_fixup_tbl[] = { {0x19, 0x03a11020}, {0x1d, 0x40e00001}, {0x21, 0x0321101f}), + SND_HDA_PIN_QUIRK(0x10ec0288, 0x1028, "Dell", ALC288_FIXUP_DELL_XPS_13_GPIO6, + ALC288_STANDARD_PINS, + {0x12, 0x90a60120}, + {0x13, 0x40000000}, + {0x14, 0x90170110}, + {0x1d, 0x4076832d}, + {0x21, 0x0321101f}), SND_HDA_PIN_QUIRK(0x10ec0290, 0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1, ALC290_STANDARD_PINS, {0x14, 0x411111f0}, -- cgit v1.2.3 From 664c715573c2c116c2d8f5de7d59ce85a98a1751 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Wed, 8 Apr 2015 11:43:14 +0200 Subject: ALSA: hda - Work around races of power up/down with runtime PM Currently, snd_hdac_power_up()/down() helpers checks whether the codec is being in pm (suspend/resume), and skips the call of runtime get/put during it. This is needed as there are lots of power up/down sequences called in the paths that are also used in the PM itself. An example is found in hda_codec.c::codec_exec_verb(), where this can power up the codec while it may be called again in its power up sequence, too. The above works in most cases, but sometimes we really want to wait for the real power up. For example, the control element get/put may want explicit power up so that the value change is assured to reach to the hardware. Using the current snd_hdac_power_up(), however, results in a race, e.g. when it's called during the runtime suspend is being performed. In the worst case, as found in patch_ca0132.c, it can even lead to the deadlock because the code assumes the power up while it was skipped due to the check above. For dealing with such cases, this patch makes snd_hdac_power_up() and _down() to two variants: with and without in_pm flag check. The version with pm flag check is named as snd_hdac_power_up_pm() while the version without pm flag check is still kept as snd_hdac_power_up(). (Just because the usage of the former is fewer.) Then finally, the patch replaces each call potentially done in PM with the new _pm() variant. In theory, we can implement a unified version -- if we can distinguish the current context whether it's in the pm path. But such an implementation is cumbersome, so leave the code like this a bit messy way for now... Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=96271 Signed-off-by: Takashi Iwai --- include/sound/hdaudio.h | 28 ++++++++++++++++++++++++++++ sound/hda/hdac_device.c | 16 +++++++--------- sound/hda/hdac_regmap.c | 8 ++++---- sound/pci/hda/hda_codec.c | 8 ++++---- sound/pci/hda/hda_codec.h | 2 ++ sound/pci/hda/patch_ca0132.c | 12 ++++++------ sound/pci/hda/patch_hdmi.c | 4 ++-- 7 files changed, 53 insertions(+), 25 deletions(-) (limited to 'sound/pci') diff --git a/include/sound/hdaudio.h b/include/sound/hdaudio.h index 95acc337aea5..30446f17c6a6 100644 --- a/include/sound/hdaudio.h +++ b/include/sound/hdaudio.h @@ -144,6 +144,34 @@ static inline void snd_hdac_power_up(struct hdac_device *codec) {} static inline void snd_hdac_power_down(struct hdac_device *codec) {} #endif +/** + * snd_hdac_power_up_pm - power up the codec + * @codec: the codec object + * + * This function can be called in a recursive code path like init code + * which may be called by PM suspend/resume again. OTOH, if a power-up + * call must wake up the sleeper (e.g. in a kctl callback), use + * snd_hdac_power_up() instead. + */ +static inline void snd_hdac_power_up_pm(struct hdac_device *codec) +{ + if (!atomic_read(&codec->in_pm)) + snd_hdac_power_up(codec); +} + +/** + * snd_hdac_power_down_pm - power down the codec + * @codec: the codec object + * + * Like snd_hdac_power_up_pm(), this function is used in a recursive + * code path like init code which may be called by PM suspend/resume again. + */ +static inline void snd_hdac_power_down_pm(struct hdac_device *codec) +{ + if (!atomic_read(&codec->in_pm)) + snd_hdac_power_down(codec); +} + /* * HD-audio codec base driver */ diff --git a/sound/hda/hdac_device.c b/sound/hda/hdac_device.c index d4a0e723af2c..92604bbcee5f 100644 --- a/sound/hda/hdac_device.c +++ b/sound/hda/hdac_device.c @@ -494,29 +494,27 @@ EXPORT_SYMBOL_GPL(snd_hdac_get_connections); #ifdef CONFIG_PM /** - * snd_hdac_power_up - increment the runtime pm counter + * snd_hdac_power_up - power up the codec * @codec: the codec object + * + * This function calls the runtime PM helper to power up the given codec. + * Unlike snd_hdac_power_up_pm(), you should call this only for the code + * path that isn't included in PM path. Otherwise it gets stuck. */ void snd_hdac_power_up(struct hdac_device *codec) { - struct device *dev = &codec->dev; - - if (atomic_read(&codec->in_pm)) - return; - pm_runtime_get_sync(dev); + pm_runtime_get_sync(&codec->dev); } EXPORT_SYMBOL_GPL(snd_hdac_power_up); /** - * snd_hdac_power_up - decrement the runtime pm counter + * snd_hdac_power_down - power down the codec * @codec: the codec object */ void snd_hdac_power_down(struct hdac_device *codec) { struct device *dev = &codec->dev; - if (atomic_read(&codec->in_pm)) - return; pm_runtime_mark_last_busy(dev); pm_runtime_put_autosuspend(dev); } diff --git a/sound/hda/hdac_regmap.c b/sound/hda/hdac_regmap.c index 1eb43209fe2c..64876fa357c9 100644 --- a/sound/hda/hdac_regmap.c +++ b/sound/hda/hdac_regmap.c @@ -402,9 +402,9 @@ int snd_hdac_regmap_write_raw(struct hdac_device *codec, unsigned int reg, err = reg_raw_write(codec, reg, val); if (err == -EAGAIN) { - snd_hdac_power_up(codec); + snd_hdac_power_up_pm(codec); err = reg_raw_write(codec, reg, val); - snd_hdac_power_down(codec); + snd_hdac_power_down_pm(codec); } return err; } @@ -434,9 +434,9 @@ int snd_hdac_regmap_read_raw(struct hdac_device *codec, unsigned int reg, err = reg_raw_read(codec, reg, val); if (err == -EAGAIN) { - snd_hdac_power_up(codec); + snd_hdac_power_up_pm(codec); err = reg_raw_read(codec, reg, val); - snd_hdac_power_down(codec); + snd_hdac_power_down_pm(codec); } return err; } diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 16dfa1ed10dd..e70a7fb393dd 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -137,7 +137,7 @@ static int codec_exec_verb(struct hdac_device *dev, unsigned int cmd, return -1; again: - snd_hda_power_up(codec); + snd_hda_power_up_pm(codec); mutex_lock(&bus->core.cmd_mutex); if (flags & HDA_RW_NO_RESPONSE_FALLBACK) bus->no_response_fallback = 1; @@ -145,7 +145,7 @@ static int codec_exec_verb(struct hdac_device *dev, unsigned int cmd, cmd, res); bus->no_response_fallback = 0; mutex_unlock(&bus->core.cmd_mutex); - snd_hda_power_down(codec); + snd_hda_power_down_pm(codec); if (!codec_in_pm(codec) && res && err < 0 && bus->rirb_error) { if (bus->response_reset) { codec_dbg(codec, @@ -3951,7 +3951,7 @@ int snd_hda_check_amp_list_power(struct hda_codec *codec, if (!(v & HDA_AMP_MUTE) && v > 0) { if (!check->power_on) { check->power_on = 1; - snd_hda_power_up(codec); + snd_hda_power_up_pm(codec); } return 1; } @@ -3959,7 +3959,7 @@ int snd_hda_check_amp_list_power(struct hda_codec *codec, } if (check->power_on) { check->power_on = 0; - snd_hda_power_down(codec); + snd_hda_power_down_pm(codec); } return 0; } diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index acf868c6a785..9075ac28dc4b 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h @@ -508,7 +508,9 @@ const char *snd_hda_get_jack_location(u32 cfg); * power saving */ #define snd_hda_power_up(codec) snd_hdac_power_up(&(codec)->core) +#define snd_hda_power_up_pm(codec) snd_hdac_power_up_pm(&(codec)->core) #define snd_hda_power_down(codec) snd_hdac_power_down(&(codec)->core) +#define snd_hda_power_down_pm(codec) snd_hdac_power_down_pm(&(codec)->core) #ifdef CONFIG_PM void snd_hda_set_power_save(struct hda_bus *bus, int delay); void snd_hda_update_power_acct(struct hda_codec *codec); diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c index 5aff35a09fd4..4a4e7b282e4f 100644 --- a/sound/pci/hda/patch_ca0132.c +++ b/sound/pci/hda/patch_ca0132.c @@ -3131,7 +3131,7 @@ static int ca0132_select_out(struct hda_codec *codec) codec_dbg(codec, "ca0132_select_out\n"); - snd_hda_power_up(codec); + snd_hda_power_up_pm(codec); auto_jack = spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID]; @@ -3215,7 +3215,7 @@ static int ca0132_select_out(struct hda_codec *codec) } exit: - snd_hda_power_down(codec); + snd_hda_power_down_pm(codec); return err < 0 ? err : 0; } @@ -3293,7 +3293,7 @@ static int ca0132_select_mic(struct hda_codec *codec) codec_dbg(codec, "ca0132_select_mic\n"); - snd_hda_power_up(codec); + snd_hda_power_up_pm(codec); auto_jack = spec->vnode_lswitch[VNID_AMIC1_ASEL - VNODE_START_NID]; @@ -3326,7 +3326,7 @@ static int ca0132_select_mic(struct hda_codec *codec) ca0132_effects_set(codec, VOICE_FOCUS, 0); } - snd_hda_power_down(codec); + snd_hda_power_down_pm(codec); return 0; } @@ -4546,7 +4546,7 @@ static int ca0132_init(struct hda_codec *codec) spec->dsp_state = DSP_DOWNLOAD_INIT; spec->curr_chip_addx = INVALID_CHIP_ADDRESS; - snd_hda_power_up(codec); + snd_hda_power_up_pm(codec); ca0132_init_unsol(codec); @@ -4577,7 +4577,7 @@ static int ca0132_init(struct hda_codec *codec) snd_hda_jack_report_sync(codec); - snd_hda_power_down(codec); + snd_hda_power_down_pm(codec); return 0; } diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c index ca0c05e1c42e..5f44f60a6389 100644 --- a/sound/pci/hda/patch_hdmi.c +++ b/sound/pci/hda/patch_hdmi.c @@ -1545,7 +1545,7 @@ static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll) bool eld_changed = false; bool ret; - snd_hda_power_up(codec); + snd_hda_power_up_pm(codec); present = snd_hda_pin_sense(codec, pin_nid); mutex_lock(&per_pin->lock); @@ -1631,7 +1631,7 @@ static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll) jack->block_report = !ret; mutex_unlock(&per_pin->lock); - snd_hda_power_down(codec); + snd_hda_power_down_pm(codec); return ret; } -- cgit v1.2.3 From 2206dc949286fe0010c69213d3d8b4c53e6a2295 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 9 Apr 2015 10:18:31 +0200 Subject: ALSA: hda/generic - Check power state cap at updating the widget power The new widget power-saving tries to apply the power change no matter whether the node has a power cap or not. It's bad (although most of codecs chip just ignore it). Check the capability properly beforehand. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_generic.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c index 1f2ca7be1468..afc6b1b0898c 100644 --- a/sound/pci/hda/hda_generic.c +++ b/sound/pci/hda/hda_generic.c @@ -832,6 +832,8 @@ static hda_nid_t path_power_update(struct hda_codec *codec, for (i = 0; i < path->depth; i++) { nid = path->path[i]; + if (!(get_wcaps(codec, nid) & AC_WCAP_POWER)) + continue; if (nid == codec->core.afg) continue; if (!allow_powerdown || is_active_nid_for_any(codec, nid)) -- cgit v1.2.3 From d5ac0100a9027bdf488cf20247b1041f26f796f3 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 9 Apr 2015 10:21:30 +0200 Subject: ALSA: hda/generic - Fix wrong initial power state for fixed pins When the widget power-saving is enabled, the first automute hook invocation checks through the whole pins and it also tries to synchronize the power state. However, this results in a wrong state because it calls unconditionally snd_hda_jack_detect_state(). This patch adds a check of jack detectability before the actual jack detection call. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_generic.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c index afc6b1b0898c..46b559832d2c 100644 --- a/sound/pci/hda/hda_generic.c +++ b/sound/pci/hda/hda_generic.c @@ -3959,6 +3959,14 @@ static hda_nid_t set_path_power(struct hda_codec *codec, hda_nid_t nid, return changed; } +/* check the jack status for power control */ +static bool detect_pin_state(struct hda_codec *codec, hda_nid_t pin) +{ + if (!is_jack_detectable(codec, pin)) + return true; + return snd_hda_jack_detect_state(codec, pin) != HDA_JACK_NOT_PRESENT; +} + /* power up/down the paths of the given pin according to the jack state; * power = 0/1 : only power up/down if it matches with the jack state, * < 0 : force power up/down to follow the jack sate @@ -3973,7 +3981,8 @@ static hda_nid_t set_pin_power_jack(struct hda_codec *codec, hda_nid_t pin, if (!codec->power_save_node) return 0; - on = snd_hda_jack_detect_state(codec, pin) != HDA_JACK_NOT_PRESENT; + on = detect_pin_state(codec, pin); + if (power >= 0 && on != power) return 0; return set_path_power(codec, pin, on, -1); @@ -4225,8 +4234,7 @@ static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins, if (codec->power_save_node) { bool on = !mute; if (on) - on = snd_hda_jack_detect_state(codec, nid) - != HDA_JACK_NOT_PRESENT; + on = detect_pin_state(codec, nid); set_path_power(codec, nid, on, -1); } } -- cgit v1.2.3 From b6c09b3c7b54743cbc58af8c27bbae8299c4f8cc Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 9 Apr 2015 10:25:03 +0200 Subject: ALSA: hda/generic - Make snd_hda_gen_path_power_filter() always applicable Add the check of power_save_node flag at the beginning of the function so that it skips the rest if the flag isn't set. In this way, we can call this function safely no matter whether the widget power-saving is really used or not. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_generic.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c index 46b559832d2c..f0475a19fad7 100644 --- a/sound/pci/hda/hda_generic.c +++ b/sound/pci/hda/hda_generic.c @@ -4703,6 +4703,10 @@ unsigned int snd_hda_gen_path_power_filter(struct hda_codec *codec, hda_nid_t nid, unsigned int power_state) { + struct hda_gen_spec *spec = codec->spec; + + if (!spec->power_down_unused && !codec->power_save_node) + return power_state; if (power_state != AC_PWRST_D0 || nid == codec->core.afg) return power_state; if (get_wcaps_type(get_wcaps(codec, nid)) >= AC_WID_POWER) -- cgit v1.2.3 From 24fef9022a83d789ee372a393ea4782dc22b9b51 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 9 Apr 2015 10:28:15 +0200 Subject: ALSA: hda/generic - Don't override power_filter when power_save_node is set Currently the generic parser sets codec->power_filter when power_save_node flag is set. But this overrides the existing filter that has been already set by the codec driver, thus it looses some features. Instead, set the default power_filter only when it's not set yet. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_generic.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c index f0475a19fad7..3d2597b7037b 100644 --- a/sound/pci/hda/hda_generic.c +++ b/sound/pci/hda/hda_generic.c @@ -4918,7 +4918,8 @@ int snd_hda_gen_parse_auto_config(struct hda_codec *codec, parse_digital(codec); if (spec->power_down_unused || codec->power_save_node) - codec->power_filter = snd_hda_gen_path_power_filter; + if (!codec->power_filter) + codec->power_filter = snd_hda_gen_path_power_filter; if (!spec->no_analog && spec->beep_nid) { err = snd_hda_attach_beep_device(codec, spec->beep_nid); -- cgit v1.2.3 From cffd39668177afe5566104a2f289242c3c5ce3d1 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 9 Apr 2015 10:30:25 +0200 Subject: ALSA: hda/realtek - Fix the regression by widget power-saving While enabling the widget power-saving for ALC269 & co, the important setup was forgotten -- stream_pm ops. Without this setup, the paths for PCM won't be powered up at all. Also, the power_filter callbacks used in ALC269 & co need to chain to the default snd_hda_gen_path_power_filter(). Tested-by: Hui Wang Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_realtek.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c index 7b5c93e0e78c..acccedf8a4be 100644 --- a/sound/pci/hda/patch_realtek.c +++ b/sound/pci/hda/patch_realtek.c @@ -3223,7 +3223,7 @@ static unsigned int led_power_filter(struct hda_codec *codec, snd_hda_set_pin_ctl(codec, nid, snd_hda_codec_get_pin_target(codec, nid)); - return AC_PWRST_D0; + return snd_hda_gen_path_power_filter(codec, nid, power_state); } static void alc269_fixup_hp_mute_led(struct hda_codec *codec, @@ -4186,7 +4186,7 @@ static unsigned int alc_power_filter_xps13(struct hda_codec *codec, if (spec->gen.hp_jack_present) if (nid == codec->core.afg || nid == 0x02 || nid == 0x15) return AC_PWRST_D0; - return power_state; + return snd_hda_gen_path_power_filter(codec, nid, power_state); } static void alc_fixup_dell_xps13(struct hda_codec *codec, @@ -5673,6 +5673,7 @@ static int patch_alc269(struct hda_codec *codec) set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT); codec->patch_ops = alc_patch_ops; + codec->patch_ops.stream_pm = snd_hda_gen_stream_pm, #ifdef CONFIG_PM codec->patch_ops.suspend = alc269_suspend; codec->patch_ops.resume = alc269_resume; -- cgit v1.2.3 From cfd3113e7cc358b68bc13a2ca46714b0445dca56 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 9 Apr 2015 15:23:59 +0200 Subject: ALSA: hda/via - Add missing stream_pm ops setup Similar like the case for Realtek, VIA codec driver needs this ops as well for making the widget power-save working. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 1 + 1 file changed, 1 insertion(+) (limited to 'sound/pci') diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 742087ef378f..31a95cca015d 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -472,6 +472,7 @@ static const struct hda_codec_ops via_patch_ops = { .init = via_init, .free = via_free, .unsol_event = snd_hda_jack_unsol_event, + .stream_pm = snd_hda_gen_stream_pm, #ifdef CONFIG_PM .suspend = via_suspend, .check_power_status = via_check_power_status, -- cgit v1.2.3 From f4d3129c2b580ad2b82aa3211a6216bbf7ad007c Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 10 Apr 2015 09:53:04 +0200 Subject: ALSA: hda/realtek - Fix a typo A comma was used instead of a semicolon, which may lead to a build error. Fixes: cffd39668177 ('ALSA: hda/realtek - Fix the regression by widget power-saving') Reported-by: kbuild test robot Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_realtek.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sound/pci') diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c index acccedf8a4be..12f62af507d9 100644 --- a/sound/pci/hda/patch_realtek.c +++ b/sound/pci/hda/patch_realtek.c @@ -5673,7 +5673,7 @@ static int patch_alc269(struct hda_codec *codec) set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT); codec->patch_ops = alc_patch_ops; - codec->patch_ops.stream_pm = snd_hda_gen_stream_pm, + codec->patch_ops.stream_pm = snd_hda_gen_stream_pm; #ifdef CONFIG_PM codec->patch_ops.suspend = alc269_suspend; codec->patch_ops.resume = alc269_resume; -- cgit v1.2.3 From fa863b2d5e62e2ea7d86ccfa9a888bd28dd79ebe Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Sat, 11 Apr 2015 14:34:44 +0200 Subject: ALSA: emu10k1: handle dock disconnects When the dock on an E-mu 1010 card is disconnected, all outputs get muted by the hardware. Add logic to detect a disconnect and unmute. Signed-off-by: Michael Gernoth Signed-off-by: Takashi Iwai --- sound/pci/emu10k1/emu10k1_main.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'sound/pci') diff --git a/sound/pci/emu10k1/emu10k1_main.c b/sound/pci/emu10k1/emu10k1_main.c index 4887299011ef..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) { struct snd_emu10k1 *emu = data; u32 tmp, tmp2, reg; + u32 last_reg = 0; int err; for (;;) { @@ -782,7 +783,15 @@ static int emu1010_firmware_thread(void *data) msleep(10); /* Unmute all. Default is muted after a firmware load */ snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE); + } else if (!reg && last_reg) { + /* Audio Dock removed */ + dev_info(emu->card->dev, + "emu1010: Audio Dock detached\n"); + /* Unmute all */ + snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE); } + + last_reg = reg; } dev_info(emu->card->dev, "emu1010: firmware thread stopping\n"); return 0; -- cgit v1.2.3 From 99dcab46b5a5b470074bec6d8386e2c7807684cf Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Sat, 11 Apr 2015 18:00:19 +0200 Subject: ALSA: emu10k1: add toggles for E-mu 1010 optical ports The optical ports on the E-mu 1010 (and dock) can be configured for ADAT- or S/PDIF-mode, which is currently hardcoded to ADAT. Add two mixer elements to expose this setting. Tested on an E-mu 1010 PCIe with connected Micro Dock. Signed-off-by: Michael Gernoth Signed-off-by: Takashi Iwai --- sound/pci/emu10k1/emumixer.c | 118 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) (limited to 'sound/pci') 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 = .put = snd_emu1010_internal_clock_put }; +static int snd_emu1010_optical_out_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) +{ + static const char * const texts[2] = { + "SPDIF", "ADAT" + }; + + return snd_ctl_enum_info(uinfo, 1, 2, texts); +} + +static int snd_emu1010_optical_out_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); + + ucontrol->value.enumerated.item[0] = emu->emu1010.optical_out; + return 0; +} + +static int snd_emu1010_optical_out_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); + unsigned int val; + u32 tmp; + int change = 0; + + val = ucontrol->value.enumerated.item[0]; + /* Limit: uinfo->value.enumerated.items = 2; */ + if (val >= 2) + return -EINVAL; + change = (emu->emu1010.optical_out != val); + if (change) { + emu->emu1010.optical_out = val; + tmp = (emu->emu1010.optical_in ? EMU_HANA_OPTICAL_IN_ADAT : 0) | + (emu->emu1010.optical_out ? EMU_HANA_OPTICAL_OUT_ADAT : 0); + snd_emu1010_fpga_write(emu, EMU_HANA_OPTICAL_TYPE, tmp); + } + return change; +} + +static struct snd_kcontrol_new snd_emu1010_optical_out = { + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, + .name = "Optical Output Mode", + .count = 1, + .info = snd_emu1010_optical_out_info, + .get = snd_emu1010_optical_out_get, + .put = snd_emu1010_optical_out_put +}; + +static int snd_emu1010_optical_in_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) +{ + static const char * const texts[2] = { + "SPDIF", "ADAT" + }; + + return snd_ctl_enum_info(uinfo, 1, 2, texts); +} + +static int snd_emu1010_optical_in_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); + + ucontrol->value.enumerated.item[0] = emu->emu1010.optical_in; + return 0; +} + +static int snd_emu1010_optical_in_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); + unsigned int val; + u32 tmp; + int change = 0; + + val = ucontrol->value.enumerated.item[0]; + /* Limit: uinfo->value.enumerated.items = 2; */ + if (val >= 2) + return -EINVAL; + change = (emu->emu1010.optical_in != val); + if (change) { + emu->emu1010.optical_in = val; + tmp = (emu->emu1010.optical_in ? EMU_HANA_OPTICAL_IN_ADAT : 0) | + (emu->emu1010.optical_out ? EMU_HANA_OPTICAL_OUT_ADAT : 0); + snd_emu1010_fpga_write(emu, EMU_HANA_OPTICAL_TYPE, tmp); + } + return change; +} + +static struct snd_kcontrol_new snd_emu1010_optical_in = { + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, + .name = "Optical Input Mode", + .count = 1, + .info = snd_emu1010_optical_in_info, + .get = snd_emu1010_optical_in_get, + .put = snd_emu1010_optical_in_put +}; + static int snd_audigy_i2c_capture_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { @@ -2051,6 +2153,14 @@ int snd_emu10k1_mixer(struct snd_emu10k1 *emu, snd_ctl_new1(&snd_emu1010_internal_clock, emu)); if (err < 0) return err; + err = snd_ctl_add(card, + snd_ctl_new1(&snd_emu1010_optical_out, emu)); + if (err < 0) + return err; + err = snd_ctl_add(card, + snd_ctl_new1(&snd_emu1010_optical_in, emu)); + if (err < 0) + return err; } else if (emu->card_capabilities->emu_model) { /* all other e-mu cards for now */ @@ -2086,6 +2196,14 @@ int snd_emu10k1_mixer(struct snd_emu10k1 *emu, snd_ctl_new1(&snd_emu1010_internal_clock, emu)); if (err < 0) return err; + err = snd_ctl_add(card, + snd_ctl_new1(&snd_emu1010_optical_out, emu)); + if (err < 0) + return err; + err = snd_ctl_add(card, + snd_ctl_new1(&snd_emu1010_optical_in, emu)); + if (err < 0) + return err; } if ( emu->card_capabilities->i2c_adc) { -- cgit v1.2.3