1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2 //
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.
5 //
6 // Copyright(c) 2018 Intel Corporation. All rights reserved.
7 //
8 // Authors: Keyon Jie <yang.jie@linux.intel.com>
9
10 #include <linux/io.h>
11 #include <sound/hdaudio.h>
12 #include <sound/hda_i915.h>
13 #include "../sof-priv.h"
14 #include "hda.h"
15
16 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC)
17 #include "../../codecs/hdac_hda.h"
18 #define sof_hda_ext_ops snd_soc_hdac_hda_get_ops()
19 #else
20 #define sof_hda_ext_ops NULL
21 #endif
22
23 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
sof_hda_bus_link_power(struct hdac_device * codec,bool enable)24 static void sof_hda_bus_link_power(struct hdac_device *codec, bool enable)
25 {
26 struct hdac_bus *bus = codec->bus;
27 bool oldstate = test_bit(codec->addr, &bus->codec_powered);
28
29 snd_hdac_ext_bus_link_power(codec, enable);
30
31 if (enable == oldstate)
32 return;
33
34 /*
35 * Both codec driver and controller can hold references to
36 * display power. To avoid unnecessary power-up/down cycles,
37 * controller doesn't immediately release its reference.
38 *
39 * If the codec driver powers down the link, release
40 * the controller reference as well.
41 */
42 if (codec->addr == HDA_IDISP_ADDR && !enable)
43 snd_hdac_display_power(bus, HDA_CODEC_IDX_CONTROLLER, false);
44 }
45
46 static const struct hdac_bus_ops bus_core_ops = {
47 .command = snd_hdac_bus_send_cmd,
48 .get_response = snd_hdac_bus_get_response,
49 .link_power = sof_hda_bus_link_power,
50 };
51 #endif
52
53 /*
54 * This can be used for both with/without hda link support.
55 */
sof_hda_bus_init(struct hdac_bus * bus,struct device * dev)56 void sof_hda_bus_init(struct hdac_bus *bus, struct device *dev)
57 {
58 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
59 snd_hdac_ext_bus_init(bus, dev, &bus_core_ops, sof_hda_ext_ops);
60 #else /* CONFIG_SND_SOC_SOF_HDA */
61 memset(bus, 0, sizeof(*bus));
62 bus->dev = dev;
63
64 INIT_LIST_HEAD(&bus->stream_list);
65
66 bus->irq = -1;
67
68 /*
69 * There is only one HDA bus atm. keep the index as 0.
70 * Need to fix when there are more than one HDA bus.
71 */
72 bus->idx = 0;
73
74 spin_lock_init(&bus->reg_lock);
75 #endif /* CONFIG_SND_SOC_SOF_HDA */
76 }
77