1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
3 // This file is provided under a dual BSD/GPLv2 license. When using or
4 // redistributing this file, you may do so under either license.
6 // Copyright(c) 2018 Intel Corporation. All rights reserved.
11 #include <sound/hdaudio.h>
12 #include <sound/hda_i915.h>
13 #include <sound/hda_codec.h>
14 #include <sound/hda_register.h>
15 #include "../sof-priv.h"
18 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC)
19 #include "../../codecs/hdac_hda.h"
20 #define sof_hda_ext_ops snd_soc_hdac_hda_get_ops()
22 static void update_codec_wake_enable(struct hdac_bus *bus, unsigned int addr, bool link_power)
24 unsigned int mask = snd_hdac_chip_readw(bus, WAKEEN);
31 snd_hdac_chip_updatew(bus, WAKEEN, STATESTS_INT_MASK, mask);
34 static void sof_hda_bus_link_power(struct hdac_device *codec, bool enable)
36 struct hdac_bus *bus = codec->bus;
37 bool oldstate = test_bit(codec->addr, &bus->codec_powered);
39 snd_hdac_ext_bus_link_power(codec, enable);
41 if (enable == oldstate)
45 * Both codec driver and controller can hold references to
46 * display power. To avoid unnecessary power-up/down cycles,
47 * controller doesn't immediately release its reference.
49 * If the codec driver powers down the link, release
50 * the controller reference as well.
52 if (codec->addr == HDA_IDISP_ADDR && !enable)
53 snd_hdac_display_power(bus, HDA_CODEC_IDX_CONTROLLER, false);
55 /* WAKEEN needs to be set for disabled links */
56 update_codec_wake_enable(bus, codec->addr, enable);
59 static const struct hdac_bus_ops bus_core_ops = {
60 .command = snd_hdac_bus_send_cmd,
61 .get_response = snd_hdac_bus_get_response,
62 .link_power = sof_hda_bus_link_power,
67 * This can be used for both with/without hda link support.
69 void sof_hda_bus_init(struct snd_sof_dev *sdev, struct device *dev)
71 struct hdac_bus *bus = sof_to_bus(sdev);
73 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC)
74 snd_hdac_ext_bus_init(bus, dev, &bus_core_ops, sof_hda_ext_ops);
75 #else /* CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC */
76 memset(bus, 0, sizeof(*bus));
79 INIT_LIST_HEAD(&bus->stream_list);
84 * There is only one HDA bus atm. keep the index as 0.
85 * Need to fix when there are more than one HDA bus.
89 spin_lock_init(&bus->reg_lock);
90 #endif /* CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC */
93 void sof_hda_bus_exit(struct snd_sof_dev *sdev)
95 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC)
96 struct hdac_bus *bus = sof_to_bus(sdev);
98 snd_hdac_ext_bus_exit(bus);