hda-bus.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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
  7. //
  8. // Authors: Keyon Jie <yang.jie@linux.intel.com>
  9. #include <linux/io.h>
  10. #include <sound/hdaudio.h>
  11. #include <sound/hda_i915.h>
  12. #include <sound/hda_codec.h>
  13. #include <sound/hda_register.h>
  14. #include "../sof-priv.h"
  15. #include "hda.h"
  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. static void update_codec_wake_enable(struct hdac_bus *bus, unsigned int addr, bool link_power)
  20. {
  21. unsigned int mask = snd_hdac_chip_readw(bus, WAKEEN);
  22. if (link_power)
  23. mask &= ~BIT(addr);
  24. else
  25. mask |= BIT(addr);
  26. snd_hdac_chip_updatew(bus, WAKEEN, STATESTS_INT_MASK, mask);
  27. }
  28. static void sof_hda_bus_link_power(struct hdac_device *codec, bool enable)
  29. {
  30. struct hdac_bus *bus = codec->bus;
  31. bool oldstate = test_bit(codec->addr, &bus->codec_powered);
  32. snd_hdac_ext_bus_link_power(codec, enable);
  33. if (enable == oldstate)
  34. return;
  35. /*
  36. * Both codec driver and controller can hold references to
  37. * display power. To avoid unnecessary power-up/down cycles,
  38. * controller doesn't immediately release its reference.
  39. *
  40. * If the codec driver powers down the link, release
  41. * the controller reference as well.
  42. */
  43. if (codec->addr == HDA_IDISP_ADDR && !enable)
  44. snd_hdac_display_power(bus, HDA_CODEC_IDX_CONTROLLER, false);
  45. /* WAKEEN needs to be set for disabled links */
  46. update_codec_wake_enable(bus, codec->addr, enable);
  47. }
  48. static const struct hdac_bus_ops bus_core_ops = {
  49. .command = snd_hdac_bus_send_cmd,
  50. .get_response = snd_hdac_bus_get_response,
  51. .link_power = sof_hda_bus_link_power,
  52. };
  53. #endif
  54. /*
  55. * This can be used for both with/without hda link support.
  56. */
  57. void sof_hda_bus_init(struct snd_sof_dev *sdev, struct device *dev)
  58. {
  59. struct hdac_bus *bus = sof_to_bus(sdev);
  60. #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_LINK)
  61. #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC)
  62. const struct sof_intel_dsp_desc *chip = get_chip_info(sdev->pdata);
  63. snd_hdac_ext_bus_init(bus, dev, &bus_core_ops, sof_hda_ext_ops);
  64. if (chip && chip->hw_ip_version >= SOF_INTEL_ACE_2_0)
  65. bus->use_pio_for_commands = true;
  66. #else
  67. snd_hdac_ext_bus_init(bus, dev, NULL, NULL);
  68. #endif
  69. #else
  70. memset(bus, 0, sizeof(*bus));
  71. bus->dev = dev;
  72. INIT_LIST_HEAD(&bus->stream_list);
  73. bus->irq = -1;
  74. /*
  75. * There is only one HDA bus atm. keep the index as 0.
  76. * Need to fix when there are more than one HDA bus.
  77. */
  78. bus->idx = 0;
  79. spin_lock_init(&bus->reg_lock);
  80. #endif /* CONFIG_SND_SOC_SOF_HDA_LINK */
  81. }
  82. EXPORT_SYMBOL_NS(sof_hda_bus_init, SND_SOC_SOF_INTEL_HDA_COMMON);
  83. void sof_hda_bus_exit(struct snd_sof_dev *sdev)
  84. {
  85. #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_LINK)
  86. struct hdac_bus *bus = sof_to_bus(sdev);
  87. snd_hdac_ext_bus_exit(bus);
  88. #endif
  89. }
  90. EXPORT_SYMBOL_NS(sof_hda_bus_exit, SND_SOC_SOF_INTEL_HDA_COMMON);