Commit f9e5fd1b authored by Kai Vehmanen's avatar Kai Vehmanen Committed by Takashi Iwai

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.
Co-developed-by: default avatarRanjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: default avatarRanjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: default avatarKai Vehmanen <kai.vehmanen@linux.intel.com>
Acked-by: default avatarMark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20210205184630.1938761-2-kai.vehmanen@linux.intel.comSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent c237813e
...@@ -241,6 +241,8 @@ struct hdac_bus_ops { ...@@ -241,6 +241,8 @@ struct hdac_bus_ops {
/* get a response from the last command */ /* get a response from the last command */
int (*get_response)(struct hdac_bus *bus, unsigned int addr, int (*get_response)(struct hdac_bus *bus, unsigned int addr,
unsigned int *res); 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); ...@@ -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, int snd_hdac_bus_exec_verb_unlocked(struct hdac_bus *bus, unsigned int addr,
unsigned int cmd, unsigned int *res); unsigned int cmd, unsigned int *res);
static inline void snd_hdac_codec_link_up(struct hdac_device *codec) void snd_hdac_codec_link_up(struct hdac_device *codec);
{ void snd_hdac_codec_link_down(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);
}
int snd_hdac_bus_send_cmd(struct hdac_bus *bus, unsigned int val); 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, 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); ...@@ -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_enter_link_reset(struct hdac_bus *bus);
void snd_hdac_bus_exit_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); 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); void snd_hdac_bus_update_rirb(struct hdac_bus *bus);
int snd_hdac_bus_handle_stream_irq(struct hdac_bus *bus, unsigned int status, int snd_hdac_bus_handle_stream_irq(struct hdac_bus *bus, unsigned int status,
......
...@@ -131,6 +131,8 @@ void snd_hdac_ext_link_clear_stream_id(struct hdac_ext_link *link, ...@@ -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_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); 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 */ /* update register macro */
#define snd_hdac_updatel(addr, reg, mask, val) \ #define snd_hdac_updatel(addr, reg, mask, val) \
writel(((readl(addr + reg) & ~(mask)) | (val)), \ writel(((readl(addr + reg) & ~(mask)) | (val)), \
......
...@@ -332,3 +332,40 @@ int snd_hdac_ext_bus_link_put(struct hdac_bus *bus, ...@@ -332,3 +332,40 @@ int snd_hdac_ext_bus_link_put(struct hdac_bus *bus,
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(snd_hdac_ext_bus_link_put); 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);
...@@ -17,6 +17,7 @@ static void snd_hdac_bus_process_unsol_events(struct work_struct *work); ...@@ -17,6 +17,7 @@ static void snd_hdac_bus_process_unsol_events(struct work_struct *work);
static const struct hdac_bus_ops default_ops = { static const struct hdac_bus_ops default_ops = {
.command = snd_hdac_bus_send_cmd, .command = snd_hdac_bus_send_cmd,
.get_response = snd_hdac_bus_get_response, .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, ...@@ -264,3 +265,25 @@ void snd_hdac_aligned_write(unsigned int val, void __iomem *addr,
} }
EXPORT_SYMBOL_GPL(snd_hdac_aligned_write); EXPORT_SYMBOL_GPL(snd_hdac_aligned_write);
#endif /* CONFIG_SND_HDA_ALIGNED_MMIO */ #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);
...@@ -648,3 +648,17 @@ void snd_hdac_bus_free_stream_pages(struct hdac_bus *bus) ...@@ -648,3 +648,17 @@ void snd_hdac_bus_free_stream_pages(struct hdac_bus *bus)
snd_dma_free_pages(&bus->posbuf); snd_dma_free_pages(&bus->posbuf);
} }
EXPORT_SYMBOL_GPL(snd_hdac_bus_free_stream_pages); 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);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment