0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/io.h>
0011 #include <sound/hdaudio.h>
0012 #include <sound/hda_i915.h>
0013 #include <sound/hda_codec.h>
0014 #include <sound/hda_register.h>
0015 #include "../sof-priv.h"
0016 #include "hda.h"
0017
0018 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC)
0019 #include "../../codecs/hdac_hda.h"
0020 #define sof_hda_ext_ops snd_soc_hdac_hda_get_ops()
0021 #else
0022 #define sof_hda_ext_ops NULL
0023 #endif
0024
0025 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
0026 static void update_codec_wake_enable(struct hdac_bus *bus, unsigned int addr, bool link_power)
0027 {
0028 unsigned int mask = snd_hdac_chip_readw(bus, WAKEEN);
0029
0030 if (link_power)
0031 mask &= ~BIT(addr);
0032 else
0033 mask |= BIT(addr);
0034
0035 snd_hdac_chip_updatew(bus, WAKEEN, STATESTS_INT_MASK, mask);
0036 }
0037
0038 static void sof_hda_bus_link_power(struct hdac_device *codec, bool enable)
0039 {
0040 struct hdac_bus *bus = codec->bus;
0041 bool oldstate = test_bit(codec->addr, &bus->codec_powered);
0042
0043 snd_hdac_ext_bus_link_power(codec, enable);
0044
0045 if (enable == oldstate)
0046 return;
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056 if (codec->addr == HDA_IDISP_ADDR && !enable)
0057 snd_hdac_display_power(bus, HDA_CODEC_IDX_CONTROLLER, false);
0058
0059
0060 update_codec_wake_enable(bus, codec->addr, enable);
0061 }
0062
0063 static const struct hdac_bus_ops bus_core_ops = {
0064 .command = snd_hdac_bus_send_cmd,
0065 .get_response = snd_hdac_bus_get_response,
0066 .link_power = sof_hda_bus_link_power,
0067 };
0068 #endif
0069
0070
0071
0072
0073 void sof_hda_bus_init(struct hdac_bus *bus, struct device *dev)
0074 {
0075 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
0076 snd_hdac_ext_bus_init(bus, dev, &bus_core_ops, sof_hda_ext_ops);
0077 #else
0078 memset(bus, 0, sizeof(*bus));
0079 bus->dev = dev;
0080
0081 INIT_LIST_HEAD(&bus->stream_list);
0082
0083 bus->irq = -1;
0084
0085
0086
0087
0088
0089 bus->idx = 0;
0090
0091 spin_lock_init(&bus->reg_lock);
0092 #endif
0093 }