ALSA: hda: add link_power op to hdac_bus_ops
Subsystems (3)
Kai Vehmanen
reviewerv2 cover ALSA: hda: add link_power op to hdac_bus_ops
Here's the 2nd iteration of the patch to improve link management granularity between controllers using HDA extended bus and HDA codec drivers.
Based on feedback to V1, this now adds a new link_power op. This allows to decouple HDA codec drivers from the hdac_ext core.
I also included two patches to SOF to show how this interface is used in SOF.
Kai Vehmanen (3):
ALSA: hda: add link_power op to hdac_bus_ops
ASoC: SOF: Intel: hda: use hdac_ext fine-grained link management
ASoC: SOF: Intel: hda: release display power at link_power
include/sound/hdaudio.h | 14 ++++------- include/sound/hdaudio_ext.h | 2 ++ sound/hda/ext/hdac_ext_controller.c | 37 +++++++++++++++++++++++++++++ sound/hda/hdac_bus.c | 23 ++++++++++++++++++ sound/hda/hdac_controller.c | 14 +++++++++++ sound/soc/sof/intel/hda-bus.c | 33 ++++++++++++++++++++++++- sound/soc/sof/intel/hda.h | 3 ++- 7 files changed, 115 insertions(+), 11 deletions(-)
base-commit: 387740a5e9532db13dfb577bd4b8d1aa496487ab
Signature · 1 line
2.29.2
Kai Vehmanen
reviewerPATCH v2 1/3 ALSA: hda: add link_power op to hdac_bus_ops
The extended HDA bus (hdac_ext) provides interfaces for more fine-grained control of individual links than what plain HDA provides for. Links can be powered off when they are not used and if all links are released, controller can shut down the command DMA.
These interfaces are currently not used by common HDA codec drivers. When a HDA codec is runtime suspended, it calls snd_hdac_codec_link_down(), but there is no link to the HDA extended bus, and on controller side the links are shut down only when all codecs are suspended.
This patch adds link_power() to hdac_bus ops. Controllers using the HDA extended core, can use this to plug in snd_hdac_ext_bus_link_power() to implement more fine-grained control of link power.
No change is needed for plain HDA controllers nor to existing HDA codec drivers.
--- include/sound/hdaudio.h | 14 ++++------- include/sound/hdaudio_ext.h | 2 ++ sound/hda/ext/hdac_ext_controller.c | 37 +++++++++++++++++++++++++++++ sound/hda/hdac_bus.c | 23 ++++++++++++++++++ sound/hda/hdac_controller.c | 14 +++++++++++ 5 files changed, 81 insertions(+), 9 deletions(-)
include/sound/hdaudio.h +5 -9
@@ -241,6 +241,8 @@ struct hdac_bus_ops {/* get a response from the last command */ int (*get_response)(struct hdac_bus *bus,unsigned int addr,unsigned int *res); +/* notify of codec link power-up/down */ +void (*link_power)(struct hdac_device *hdev,bool enable); };/*
@@ -378,15 +380,8 @@ void snd_hdac_bus_exit(struct hdac_bus *bus);int snd_hdac_bus_exec_verb_unlocked (struct hdac_bus *bus,unsigned int addr,unsigned int cmd,unsigned int *res); -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); -} +void snd_hdac_codec_link_up (struct hdac_device *codec); +void snd_hdac_codec_link_down (struct hdac_device *codec);int snd_hdac_bus_send_cmd (struct hdac_bus *bus,unsigned int val); int snd_hdac_bus_get_response(struct hdac_bus *bus, unsigned int addr,
@@ -400,6 +395,7 @@ void snd_hdac_bus_stop_cmd_io(struct hdac_bus *bus);void snd_hdac_bus_enter_link_reset (struct hdac_bus *bus);void snd_hdac_bus_exit_link_reset (struct hdac_bus *bus);int snd_hdac_bus_reset_link (struct hdac_bus *bus,bool full_reset); +void snd_hdac_bus_link_power (struct hdac_device *hdev,bool enable);void snd_hdac_bus_update_rirb (struct hdac_bus *bus); int snd_hdac_bus_handle_stream_irq(struct hdac_bus *bus, unsigned int status,
include/sound/hdaudio_ext.h +2 -0
@@ -131,6 +131,8 @@ void snd_hdac_ext_link_clear_stream_id(struct hdac_ext_link *link,int snd_hdac_ext_bus_link_get (struct hdac_bus *bus,struct hdac_ext_link *link);int snd_hdac_ext_bus_link_put (struct hdac_bus *bus,struct hdac_ext_link *link); +void snd_hdac_ext_bus_link_power (struct hdac_device *codec,bool enable); +/* update register macro */ #define snd_hdac_updatel (addr, reg, mask, val) \ writel(((readl(addr + reg) & ~(mask)) | (val)), \
sound/hda/ext/hdac_ext_controller.c +37 -0
@@ -332,3 +332,40 @@ int snd_hdac_ext_bus_link_put(struct hdac_bus *bus,return ret; }EXPORT_SYMBOL_GPL (snd_hdac_ext_bus_link_put); + +static void hdac_ext_codec_link_up (struct hdac_device *codec) +{ +const char *devname =dev_name (&codec->dev); +struct hdac_ext_link *hlink = +snd_hdac_ext_bus_get_link (codec->bus, devname); + +if (hlink) +snd_hdac_ext_bus_link_get (codec->bus, hlink); +} + +static void hdac_ext_codec_link_down (struct hdac_device *codec) +{ +const char *devname =dev_name (&codec->dev); +struct hdac_ext_link *hlink = +snd_hdac_ext_bus_get_link (codec->bus, devname); + +if (hlink) +snd_hdac_ext_bus_link_put (codec->bus, hlink); +} + +void snd_hdac_ext_bus_link_power (struct hdac_device *codec,bool enable) +{ +struct hdac_bus *bus = codec->bus; +bool oldstate =test_bit (codec->addr, &bus->codec_powered); + +if (enable == oldstate) +return ; + +snd_hdac_bus_link_power (codec, enable); + +if (enable) +hdac_ext_codec_link_up (codec); +else +hdac_ext_codec_link_down (codec); +} +EXPORT_SYMBOL_GPL (snd_hdac_ext_bus_link_power);
sound/hda/hdac_bus.c +23 -0
@@ -17,6 +17,7 @@ static void snd_hdac_bus_process_unsol_events(struct work_struct *work);static const struct hdac_bus_ops default_ops = { .command = snd_hdac_bus_send_cmd, .get_response = snd_hdac_bus_get_response, + .link_power = snd_hdac_bus_link_power, };/**
@@ -264,3 +265,25 @@ void snd_hdac_aligned_write(unsigned int val, void __iomem *addr, }EXPORT_SYMBOL_GPL (snd_hdac_aligned_write);#endif /* CONFIG_SND_HDA_ALIGNED_MMIO */ + +void snd_hdac_codec_link_up (struct hdac_device *codec) +{ +struct hdac_bus *bus = codec->bus; + +if (bus->ops->link_power) + bus->ops->link_power (codec, true); +else +snd_hdac_bus_link_power (codec, true); +} +EXPORT_SYMBOL_GPL (snd_hdac_codec_link_up); + +void snd_hdac_codec_link_down (struct hdac_device *codec) +{ +struct hdac_bus *bus = codec->bus; + +if (bus->ops->link_power) + bus->ops->link_power (codec, false); +else +snd_hdac_bus_link_power (codec, false); +} +EXPORT_SYMBOL_GPL (snd_hdac_codec_link_down);
sound/hda/hdac_controller.c +14 -0
@@ -648,3 +648,17 @@ void snd_hdac_bus_free_stream_pages(struct hdac_bus *bus)snd_dma_free_pages (&bus->posbuf); }EXPORT_SYMBOL_GPL (snd_hdac_bus_free_stream_pages); + +/** +* snd_hdac_bus_link_power - power up/down codec link +* @codec: HD-audio device +* @enable: whether to power-up the link +*/ +void snd_hdac_bus_link_power (struct hdac_device *codec,bool enable) +{ +if (enable) +set_bit (codec->addr, &codec->bus->codec_powered); +else +clear_bit (codec->addr, &codec->bus->codec_powered); +} +EXPORT_SYMBOL_GPL (snd_hdac_bus_link_power);
Signature · 1 line
2.29.2
Kai Vehmanen
reviewerPATCH v2 2/3 ASoC: SOF: Intel: hda: use hdac_ext fine-grained link management
In reply to Kai VehmanenOpt-in to use snd_hdac_ext_bus_link_power() to manage HDA link power up/down events.
This allows to reduce power consumption in cases where some HDA codecs are suspended, but other child devices (HDA or non-HDA codecs) remain active and controller itself remains in active state.
By using snd_hdac_ext_bus_link_power(), the individual HDA links can be powered off and if all HDA codecs are powered down, the command DMA can also be shut down.
--- sound/soc/sof/intel/hda-bus.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
sound/soc/sof/intel/hda-bus.c +9 -1
@@ -19,13 +19,21 @@#define sof_hda_ext_ops NULL#endif +#if IS_ENABLED (CONFIG_SND_SOC_SOF_HDA ) +static const struct hdac_bus_ops bus_core_ops = { + .command = snd_hdac_bus_send_cmd, + .get_response = snd_hdac_bus_get_response, + .link_power = snd_hdac_ext_bus_link_power, +}; +#endif +/* * This can be used for both with/without hda link support. */ void sof_hda_bus_init (struct hdac_bus *bus,struct device *dev) {#if IS_ENABLED (CONFIG_SND_SOC_SOF_HDA ) -snd_hdac_ext_bus_init (bus, dev,NULL , sof_hda_ext_ops); +snd_hdac_ext_bus_init (bus, dev, &bus_core_ops, sof_hda_ext_ops);#else /* CONFIG_SND_SOC_SOF_HDA */ memset (bus,0 ,sizeof (*bus)); bus->dev = dev;
Signature · 1 line
2.29.2
Kai Vehmanen
reviewerPATCH v2 3/3 ASoC: SOF: Intel: hda: release display power at link_power
In reply to Kai VehmanenThe i915 display power is requested both by controller (for init and link reset) as well as by codec driver (for codec control).
There's an additional constraint that on some platforms frequent changes to display power state may cause visible flicker. To avoid this, the SOF hda controller requests display power whenever it is active and only releases it when runtime suspended.
This patch utilizes the new hdac_bus link_power op to plug into HDA link state changes. By monitoring link state changes, we can keep the controller side display power wakeref until the codec driver has completed its work, and only release the wakeref when codec driver is suspended.
--- sound/soc/sof/intel/hda-bus.c | 25 ++++++++++++++++++++++++- sound/soc/sof/intel/hda.h | 3 ++- 2 files changed, 26 insertions(+), 2 deletions(-)
sound/soc/sof/intel/hda-bus.c +24 -1
@@ -9,6 +9,7 @@#include <linux/io.h> #include <sound/hdaudio.h> +#include <sound/hda_i915.h> #include "../sof-priv.h" #include "hda.h"
@@ -20,10 +21,32 @@#endif #if IS_ENABLED (CONFIG_SND_SOC_SOF_HDA ) +static void sof_hda_bus_link_power (struct hdac_device *codec,bool enable) +{ +struct hdac_bus *bus = codec->bus; +bool oldstate =test_bit (codec->addr, &bus->codec_powered); + +snd_hdac_ext_bus_link_power (codec, enable); + +if (enable == oldstate) +return ; + +/* +* Both codec driver and controller can hold references to +* display power. To avoid unnecessary power-up/down cycles, +* controller doesn't immediately release its reference. +* +* If the codec driver powers down the link, release +* the controller reference as well. +*/ +if (codec->addr ==HDA_IDISP_ADDR && !enable) +snd_hdac_display_power (bus,HDA_CODEC_IDX_CONTROLLER , false); +} +static const struct hdac_bus_ops bus_core_ops = { .command = snd_hdac_bus_send_cmd, .get_response = snd_hdac_bus_get_response, - .link_power = snd_hdac_ext_bus_link_power, + .link_power = sof_hda_bus_link_power, };#endif
sound/soc/sof/intel/hda.h +2 -1
@@ -388,7 +388,8 @@#define SSP_SET_SFRM_SLAVE BIT(24)#define SSP_SET_SLAVE (SSP_SET_SCLK_SLAVE | SSP_SET_SFRM_SLAVE) -#define HDA_IDISP_CODEC (x) ((x) & BIT(2)) +#define HDA_IDISP_ADDR 2 +#define HDA_IDISP_CODEC (x) ((x) & BIT(HDA_IDISP_ADDR))struct sof_intel_dsp_bdl {__le32 addr_l;
Signature · 1 line
2.29.2
Quoted 8 lines · Kai Vehmanen
Here's the 2nd iteration of the patch to improve link management granularity between controllers using HDA extended bus and HDA codec drivers.
Based on feedback to V1, this now adds a new
link_powerop. This allows to decouple HDA codec drivers from thehdac_extcore.
Quoted 7 lines
I also included two patches to SOF to show how this interface is used in SOF.
Kai Vehmanen (3):
ALSA: hda: addlink_powerop tohdac_bus_ops
ASoC: SOF: Intel: hda: usehdac_extfine-grained link management
ASoC: SOF: Intel: hda: release display power atlink_power
The patch set looks good to me. If Mark can give an ack, I'll merge them through my tree later.
thanks,
Takashi
Quoted 9 lines · Takashi Iwai
Quoted 4 lines · Kai Vehmanen
Kai Vehmanen (3):
ALSA: hda: addlink_powerop tohdac_bus_ops
ASoC: SOF: Intel: hda: usehdac_extfine-grained link management
ASoC: SOF: Intel: hda: release display power atlink_powerThe patch set looks good to me. If Mark can give an ack, I'll merge them through my tree later.
Yeah, looks good to me too
Quoted 9 lines · Mark Brown
Quoted 6 lines · Takashi Iwai
Quoted 4 lines · Kai Vehmanen
Kai Vehmanen (3):
ALSA: hda: addlink_powerop tohdac_bus_ops
ASoC: SOF: Intel: hda: usehdac_extfine-grained link management
ASoC: SOF: Intel: hda: release display power atlink_power
Quoted 6 lines
Quoted 2 lines
The patch set looks good to me. If Mark can give an ack, I'll merge them through my tree later.
Yeah, looks good to me too
Acked-by Mark Brown <[email protected]>
OK, thanks. Now I applied all three patches to for-next branch.
Takashi