Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
0002 //
0003 // This file is provided under a dual BSD/GPLv2 license.  When using or
0004 // redistributing this file, you may do so under either license.
0005 //
0006 // Copyright(c) 2018 Intel Corporation. All rights reserved.
0007 //
0008 // Authors: Keyon Jie <yang.jie@linux.intel.com>
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      * Both codec driver and controller can hold references to
0050      * display power. To avoid unnecessary power-up/down cycles,
0051      * controller doesn't immediately release its reference.
0052      *
0053      * If the codec driver powers down the link, release
0054      * the controller reference as well.
0055      */
0056     if (codec->addr == HDA_IDISP_ADDR && !enable)
0057         snd_hdac_display_power(bus, HDA_CODEC_IDX_CONTROLLER, false);
0058 
0059     /* WAKEEN needs to be set for disabled links */
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  * This can be used for both with/without hda link support.
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 /* CONFIG_SND_SOC_SOF_HDA */
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      * There is only one HDA bus atm. keep the index as 0.
0087      * Need to fix when there are more than one HDA bus.
0088      */
0089     bus->idx = 0;
0090 
0091     spin_lock_init(&bus->reg_lock);
0092 #endif /* CONFIG_SND_SOC_SOF_HDA */
0093 }