Modernization of HD-audio bus and PM stuff
Subsystems (2)
cover Modernization of HD-audio bus and PM stuff
Hi,
here is yet another patchset for HD-audio modernization. The device binding is replaced with the standard bus, and the power-save stuff is rewritten with the standard runtime PM. In addition, a few cleanup patches follow.
There won't (and shouldn't) be big changes from the functionality POV. This is rather a large restructuring inside. It should work mostly without any visible changes. You can see a bit finer control for runtime PM in sysfs now, for example, but the original interface via power_save option is still kept.
Takashi
===
Takashi Iwai (10):
ALSA: hda - Decouple PCM and hwdep devices from codec object
ALSA: hda - Bind codecs via standard bus
ALSA: hda - Move codec suspend/resume to codec driver
ALSA: hda - Use standard runtime PM for codec power-save control
ALSA: hda - Drop power_save value indirection in hda_bus
ALSA: hda - Replace bus pm_notify with the standard runtime PM
framework
ALSA: hda - Power down codec automatically at registration
ALSA: hda - Set parent of input beep devices
ALSA: hda - Remove channel mode helper functions
ALSA: hda - Clear pcm pointer assigned to hda_pcm at device removal
sound/pci/hda/Makefile | 2 +- sound/pci/hda/hda_beep.c | 2 +- sound/pci/hda/hda_bind.c | 321 ++++++++++++++++++ sound/pci/hda/hda_codec.c | 731 ++++++++--------------------------------- sound/pci/hda/hda_codec.h | 108 ++---- sound/pci/hda/hda_controller.c | 62 ++-- sound/pci/hda/hda_controller.h | 4 +- sound/pci/hda/hda_generic.c | 18 +- sound/pci/hda/hda_hwdep.c | 3 - sound/pci/hda/hda_intel.c | 33 +- sound/pci/hda/hda_local.h | 41 +-- sound/pci/hda/hda_tegra.c | 23 +- sound/pci/hda/hda_trace.h | 24 -- 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 | 20 +- sound/pci/hda/patch_via.c | 16 +- 24 files changed, 572 insertions(+), 991 deletions(-) create mode 100644 sound/pci/hda/hda_bind.c
Signature · 1 line
2.3.0
PATCH 1/10 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.
--- 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(-)
sound/pci/hda/hda_beep.c +0 -1
@@ -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;
sound/pci/hda/hda_controller.c +0 -3
@@ -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 ; }
sound/pci/hda/hda_hwdep.c +0 -3
@@ -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);
Signature · 1 line
2.3.0
PATCH 2/10 ALSA: hda - Bind codecs via standard bus
In reply to Takashi IwaiNow 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.
--- 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
sound/pci/hda/Makefile +1 -1
@@ -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
sound/pci/hda/hda_bind.c new file +320 -0
320 lines not on this page · raw message
sound/pci/hda/hda_codec.c +16 -291
394 lines not on this page · raw message
sound/pci/hda/hda_codec.h +19 -8
@@ -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
sound/pci/hda/hda_generic.c +13 -5
@@ -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" );
sound/pci/hda/hda_local.h +8 -10
@@ -351,12 +351,6 @@ 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 */ #ifdef CONFIG_PROC_FS
@@ -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 */
sound/pci/hda/patch_analog.c +2 -14
@@ -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);
sound/pci/hda/patch_ca0110.c +2 -14
@@ -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);
sound/pci/hda/patch_ca0132.c +2 -14
@@ -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);
sound/pci/hda/patch_cirrus.c +2 -14
@@ -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);
sound/pci/hda/patch_cmedia.c +2 -14
@@ -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);
sound/pci/hda/patch_conexant.c +2 -14
@@ -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);
sound/pci/hda/patch_hdmi.c +4 -23
@@ -3301,15 +3301,6 @@ static int patch_via_hdmi(struct hda_codec *codec) }/* -* 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 */ static const struct hda_codec_preset snd_hda_preset_hdmi[] = {
@@ -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);
sound/pci/hda/patch_realtek.c +2 -14
@@ -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);
sound/pci/hda/patch_si3054.c +2 -14
@@ -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);
sound/pci/hda/patch_sigmatel.c +2 -14
@@ -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);
sound/pci/hda/patch_via.c +2 -14
@@ -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);
Signature · 1 line
2.3.0
Re: [PATCH 02/10] ALSA: hda - Bind codecs via standard bus
Quoted 20 lines · Takashi Iwai
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_driverstruct containing the currently existing preset via the new helper macromodule_hda_codec_driver(). The oldhda_codec_preset_listis 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 thesnd_hda_bus_typeimplementation 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.)
Quoted 5 lines
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.
Great stuff. AC'97 is next? ;)
[...]
sound/pci/hda/hda_bind.c line 140
Quoted 2 lines
sound/pci/hda/hda_bind.c new file +2
-0+ drv->driver.probe = hda_codec_driver_probe; + drv->driver.remove = hda_codec_driver_remove;
Small nitpick, in my opinion it would be cleaner to use the snd_hda_bus_type probe/remove callbacks for this.
Quoted 1 line
sound/pci/hda/hda_bind.c new file +1
-0+/* TODO: PM and others */
Re: [PATCH 02/10] ALSA: hda - Bind codecs via standard bus
At Sat, 28 Feb 2015 10:55:32 +0100,
Quoted 22 lines · Lars-Peter Clausen
Quoted 20 lines · Takashi Iwai
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_driverstruct containing the currently existing preset via the new helper macromodule_hda_codec_driver(). The oldhda_codec_preset_listis 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 thesnd_hda_bus_typeimplementation 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.)
Quoted 7 lines
Quoted 5 lines
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.
Great stuff. AC'97 is next? ;)
Feel free to join to the club 97! :)
Quoted 6 lines
[...]
sound/pci/hda/hda_bind.c line 140
Quoted 2 lines
sound/pci/hda/hda_bind.c new file +2
-0+ drv->driver.probe = hda_codec_driver_probe; + drv->driver.remove = hda_codec_driver_remove;Small nitpick, in my opinion it would be cleaner to use the
snd_hda_bus_typeprobe/remove callbacks for this.
Correct. However, this would need more changes. In this series, I'm trying a gradual transition without a big surprise. The merit of this patch is that you need minimum changes in the codec driver side.
So, yes, I'm going to move to that direction, but in a later stage.
thanks,
Takashi
Re: [PATCH 02/10] ALSA: hda - Bind codecs via standard bus
Quoted 41 lines · Takashi Iwai
At Sat, 28 Feb 2015 10:55:32 +0100,
Quoted 22 lines · Lars-Peter Clausen
Quoted 20 lines · Takashi Iwai
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_driverstruct containing the currently existing preset via the new helper macromodule_hda_codec_driver(). The oldhda_codec_preset_listis 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 thesnd_hda_bus_typeimplementation 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.)Quoted 7 lines
Quoted 5 lines
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.
Great stuff. AC'97 is next? ;)
Feel free to join to the club 97! :)
Quoted 6 lines
[...]
sound/pci/hda/hda_bind.c line 140
Quoted 2 lines
sound/pci/hda/hda_bind.c new file +2
-0+ drv->driver.probe = hda_codec_driver_probe; + drv->driver.remove = hda_codec_driver_remove;Small nitpick, in my opinion it would be cleaner to use the
snd_hda_bus_typeprobe/remove callbacks for this.
Quoted 3 lines
Correct. However, this would need more changes. In this series, I'm trying a gradual transition without a big surprise. The merit of this patch is that you need minimum changes in the codec driver side.
What I meant was instead of dynamically assigning the probe/remove callbacks of each driver struct, just statistically setup the probe/remove callbacks for the bus_type with the same callbacks. From a functional point of view there should not be any difference.
- Lars
Re: [PATCH 02/10] ALSA: hda - Bind codecs via standard bus
At Sat, 28 Feb 2015 11:24:55 +0100,
Quoted 43 lines · Lars-Peter Clausen
Quoted 41 lines · Takashi Iwai
At Sat, 28 Feb 2015 10:55:32 +0100,
Quoted 22 lines · Lars-Peter Clausen
Quoted 20 lines · Takashi Iwai
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_driverstruct containing the currently existing preset via the new helper macromodule_hda_codec_driver(). The oldhda_codec_preset_listis 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 thesnd_hda_bus_typeimplementation 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.)Quoted 7 lines
Quoted 5 lines
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.
Great stuff. AC'97 is next? ;)
Feel free to join to the club 97! :)
Quoted 6 lines
[...]
sound/pci/hda/hda_bind.c line 140
Quoted 2 lines
sound/pci/hda/hda_bind.c new file +2
-0+ drv->driver.probe = hda_codec_driver_probe; + drv->driver.remove = hda_codec_driver_remove;Small nitpick, in my opinion it would be cleaner to use the
snd_hda_bus_typeprobe/remove callbacks for this.
Quoted 8 lines
Quoted 3 lines
Correct. However, this would need more changes. In this series, I'm trying a gradual transition without a big surprise. The merit of this patch is that you need minimum changes in the codec driver side.
What I meant was instead of dynamically assigning the probe/remove callbacks of each driver struct, just statistically setup the probe/remove callbacks for the
bus_typewith the same callbacks. From a functional point of view there should not be any difference.
Point taken. Yes, it's feasible, but there is another plan for future to make the bus more accessible to other drivers over HD-audio bus, so the bus functionality is kept minimal as of now.
thanks,
Takashi
PATCH 3/10 ALSA: hda - Move codec suspend/resume to codec driver
In reply to Takashi IwaiThis 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.
--- 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(-)
sound/pci/hda/hda_bind.c +2 -1
@@ -8,6 +8,7 @@#include <linux/mutex.h> #include <linux/module.h> #include <linux/export.h> +#include <linux/pm.h> #include <sound/core.h> #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);
sound/pci/hda/hda_codec.c +33 -60
124 lines not on this page · raw message
sound/pci/hda/hda_codec.h +2 -4
@@ -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)
sound/pci/hda/hda_controller.c +2 -9
@@ -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 ; }
sound/pci/hda/hda_intel.c +0 -6
@@ -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 ; }
sound/pci/hda/hda_tegra.c +0 -6
@@ -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 ;
Signature · 1 line
2.3.0
PATCH 4/10 ALSA: hda - Use standard runtime PM for codec power-save control
In reply to Takashi IwaiLike 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.
--- 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(-)
sound/pci/hda/hda_codec.c +96 -145
@@ -26,6 +26,8 @@#include <linux/mutex.h> #include <linux/module.h> #include <linux/async.h> +#include <linux/pm.h> +#include <linux/pm_runtime.h> #include <sound/core.h> #include "hda_codec.h" #include <sound/asoundef.h>
@@ -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); elsesnd_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
sound/pci/hda/hda_codec.h +7 -60
88 lines not on this page · raw message
sound/pci/hda/hda_controller.c +1 -1
@@ -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);
sound/pci/hda/hda_intel.c +2 -0
@@ -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 )
sound/pci/hda/hda_trace.h +0 -24
@@ -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,
Signature · 1 line
2.3.0
PATCH 5/10 ALSA: hda - Drop power_save value indirection in hda_bus
In reply to Takashi IwaiWe 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.
--- 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(-)
sound/pci/hda/hda_codec.c +18 -16
@@ -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
sound/pci/hda/hda_codec.h +2 -3
@@ -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
sound/pci/hda/hda_controller.c +1 -4
@@ -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" );
sound/pci/hda/hda_controller.h +1 -1
@@ -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);
sound/pci/hda/hda_intel.c +4 -6
@@ -173,7 +173,6 @@ static struct kernel_param_ops param_ops_xint = {#define param_check_xint param_check_intstatic 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);
sound/pci/hda/hda_tegra.c +3 -2
@@ -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 ;
Signature · 1 line
2.3.0
PATCH 6/10 ALSA: hda - Replace bus pm_notify with the standard runtime PM framework
In reply to Takashi IwaiNow 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.
--- 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(-)
sound/pci/hda/hda_codec.c +8 -25
@@ -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 ; }
sound/pci/hda/hda_codec.h +1 -6
@@ -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;
sound/pci/hda/hda_controller.c +0 -19
@@ -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,
sound/pci/hda/hda_intel.c +2 -3
@@ -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 )
sound/pci/hda/patch_sigmatel.c +3 -1
@@ -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 } }
Signature · 1 line
2.3.0
PATCH 7/10 ALSA: hda - Power down codec automatically at registration
In reply to Takashi IwaiSo 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.
--- 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(-)
sound/pci/hda/hda_codec.c +3 -2
@@ -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));
sound/pci/hda/hda_intel.c +0 -14
@@ -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 );
sound/pci/hda/hda_tegra.c +0 -12
@@ -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 );
Signature · 1 line
2.3.0
PATCH 8/10 ALSA: hda - Set parent of input beep devices
In reply to Takashi IwaiSet the card device as the parent like other sound devices instead of leaving it empty.
--- sound/pci/hda/hda_beep.c | 1 + 1 file changed, 1 insertion(+)
sound/pci/hda/hda_beep.c +1 -0
@@ -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 ;
Signature · 1 line
2.3.0
PATCH 9/10 ALSA: hda - Remove channel mode helper functions
In reply to Takashi IwaiThey are no longer used, let's kill them.
--- sound/pci/hda/hda_codec.c | 82 ----------------------------------------------- sound/pci/hda/hda_local.h | 23 ------------- 2 files changed, 105 deletions(-)
sound/pci/hda/hda_codec.c +0 -82
@@ -4844,88 +4844,6 @@ 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 */
sound/pci/hda/hda_local.h +0 -23
@@ -273,29 +273,6 @@ int snd_hda_add_imux_item(struct hda_codec *codec, 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 */
Signature · 1 line
2.3.0
PATCH 10/10 ALSA: hda - Clear pcm pointer assigned to hda_pcm at device removal
In reply to Takashi IwaiWe 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.
--- sound/pci/hda/hda_controller.c | 22 +++++++++++++++------- sound/pci/hda/hda_controller.h | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-)
sound/pci/hda/hda_controller.c +15 -7
@@ -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); }
sound/pci/hda/hda_controller.h +1 -1
@@ -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; };
Signature · 1 line
2.3.0