Minor HD-audio cleanups
Subsystems (2)
cover Minor HD-audio cleanups
Hi,
this is a series of minor cleanups for HD-audio codes. No functional changes but just code refactoring for the further works.
The patches are found in topic/hda-cleanup branch of sound git tree, too.
Takashi
===
Takashi Iwai (6):
ALSA: hda - Drop hda_bus_template for snd_hda_bus_new()
ALSA: hda - Embed struct hda_bus_unsolicited into struct hda_bus
ALSA: hda - Introduce azx_has_pm_runtime() macro
ALSA: hda - Fold hda_priv.h into hda_controller.h
ALSA: hda - Drop azx_mixer_create()
ALSA: hda - Split azx_codec_create() to two phases
sound/pci/hda/hda_codec.c | 54 +----- sound/pci/hda/hda_codec.h | 22 +-- sound/pci/hda/hda_controller.c | 96 +++++----- sound/pci/hda/hda_controller.h | 397 +++++++++++++++++++++++++++++++++++++++- sound/pci/hda/hda_i915.c | 2 +- sound/pci/hda/hda_intel.c | 23 ++- sound/pci/hda/hda_intel.h | 2 +- sound/pci/hda/hda_local.h | 17 -- sound/pci/hda/hda_priv.h | 406 ----------------------------------------- sound/pci/hda/hda_tegra.c | 9 +- 10 files changed, 477 insertions(+), 551 deletions(-) delete mode 100644 sound/pci/hda/hda_priv.h
Signature · 1 line
2.3.0
PATCH 1/6 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.
--- 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(-)
sound/pci/hda/hda_codec.c +1 -14
@@ -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);
sound/pci/hda/hda_codec.h +1 -12
@@ -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);
sound/pci/hda/hda_controller.c +30 -24
84 lines not on this page · raw message
Signature · 1 line
2.3.0
PATCH 2/6 ALSA: hda - Embed struct hda_bus_unsolicited into struct hda_bus
In reply to Takashi IwaiThere 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.
--- 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(-)
sound/pci/hda/hda_codec.c +4 -35
@@ -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;
@@ -805,27 +801,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 */ static void snd_hda_bus_free (struct hda_bus *bus)
@@ -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,
sound/pci/hda/hda_codec.h +11 -2
@@ -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 */
sound/pci/hda/hda_local.h +0 -17
@@ -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)
Signature · 1 line
2.3.0
PATCH 3/6 ALSA: hda - Introduce azx_has_pm_runtime() macro
In reply to Takashi IwaiFor making the debugging of runtime PM easier, introduce azx_has_pm_runtime() and use it in all places checking the runtime pm driver capability.
--- 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(-)
sound/pci/hda/hda_controller.c +2 -2
@@ -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)
sound/pci/hda/hda_intel.c +5 -7
@@ -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:
sound/pci/hda/hda_priv.h +3 -0
@@ -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 */
Signature · 1 line
2.3.0
PATCH 4/6 ALSA: hda - Fold hda_priv.h into hda_controller.h
In reply to Takashi IwaiThere is no big reason to keep them separately.
--- 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
sound/pci/hda/hda_controller.c +0 -1
@@ -30,7 +30,6 @@#include <linux/reboot.h> #include <sound/core.h> #include <sound/initval.h> -#include "hda_priv.h" #include "hda_controller.h" #define CREATE_TRACE_POINTS
sound/pci/hda/hda_controller.h +390 -1
400 lines not on this page · raw message
sound/pci/hda/hda_i915.c +1 -1
@@ -22,7 +22,7 @@#include <linux/component.h> #include <drm/i915_component.h> #include <sound/core.h> -#include "hda_priv.h" +#include "hda_controller.h" #include "hda_intel.h" /* Intel HSW/BDW display HDA controller Extended Mode registers.
sound/pci/hda/hda_intel.c +0 -1
@@ -62,7 +62,6 @@#include <linux/firmware.h> #include "hda_codec.h" #include "hda_controller.h" -#include "hda_priv.h" #include "hda_intel.h" /* position fix mode */
sound/pci/hda/hda_intel.h +1 -1
@@ -17,7 +17,7 @@#define __SOUND_HDA_INTEL_H#include <drm/i915_component.h> -#include "hda_priv.h" +#include "hda_controller.h" struct hda_intel {struct azx chip;
sound/pci/hda/hda_priv.h deleted +0 -409
409 lines not on this page · raw message
sound/pci/hda/hda_tegra.c +0 -1
@@ -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
Signature · 1 line
2.3.0
PATCH 5/6 ALSA: hda - Drop azx_mixer_create()
In reply to Takashi IwaiIt's just an indirection, so let the caller directly calling snd_hda_build_controls().
--- 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(-)
sound/pci/hda/hda_controller.c +0 -7
@@ -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) {
sound/pci/hda/hda_controller.h +0 -1
@@ -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);
sound/pci/hda/hda_intel.c +1 -1
@@ -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;
sound/pci/hda/hda_tegra.c +1 -1
@@ -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;
Signature · 1 line
2.3.0
PATCH 6/6 ALSA: hda - Split azx_codec_create() to two phases
In reply to Takashi Iwaiazx_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().
--- 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(-)
sound/pci/hda/hda_controller.c +24 -16
@@ -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)
sound/pci/hda/hda_controller.h +2 -3
@@ -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);
sound/pci/hda/hda_intel.c +5 -3
@@ -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,
sound/pci/hda/hda_tegra.c +5 -1
@@ -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;
Signature · 1 line
2.3.0