hda-bus.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 <[email protected]>
  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. #else
  20. #define sof_hda_ext_ops NULL
  21. #endif
  22. #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
  23. static void update_codec_wake_enable(struct hdac_bus *bus, unsigned int addr, bool link_power)
  24. {
  25. unsigned int mask = snd_hdac_chip_readw(bus, WAKEEN);
  26. if (link_power)
  27. mask &= ~BIT(addr);
  28. else
  29. mask |= BIT(addr);
  30. snd_hdac_chip_updatew(bus, WAKEEN, STATESTS_INT_MASK, mask);
  31. }
  32. static void sof_hda_bus_link_power(struct hdac_device *codec, bool enable)
  33. {
  34. struct hdac_bus *bus = codec->bus;
  35. bool oldstate = test_bit(codec->addr, &bus->codec_powered);
  36. snd_hdac_ext_bus_link_power(codec, enable);
  37. if (enable == oldstate)
  38. return;
  39. /*
  40. * Both codec driver and controller can hold references to
  41. * display power. To avoid unnecessary power-up/down cycles,
  42. * controller doesn't immediately release its reference.
  43. *
  44. * If the codec driver powers down the link, release
  45. * the controller reference as well.
  46. */
  47. if (codec->addr == HDA_IDISP_ADDR && !enable)
  48. snd_hdac_display_power(bus, HDA_CODEC_IDX_CONTROLLER, false);
  49. /* WAKEEN needs to be set for disabled links */
  50. update_codec_wake_enable(bus, codec->addr, enable);
  51. }
  52. static const struct hdac_bus_ops bus_core_ops = {
  53. .command = snd_hdac_bus_send_cmd,
  54. .get_response = snd_hdac_bus_get_response,
  55. .link_power = sof_hda_bus_link_power,
  56. };
  57. #endif
  58. /*
  59. * This can be used for both with/without hda link support.
  60. */
  61. void sof_hda_bus_init(struct hdac_bus *bus, struct device *dev)
  62. {
  63. #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
  64. snd_hdac_ext_bus_init(bus, dev, &bus_core_ops, sof_hda_ext_ops);
  65. #else /* CONFIG_SND_SOC_SOF_HDA */
  66. memset(bus, 0, sizeof(*bus));
  67. bus->dev = dev;
  68. INIT_LIST_HEAD(&bus->stream_list);
  69. bus->irq = -1;
  70. /*
  71. * There is only one HDA bus atm. keep the index as 0.
  72. * Need to fix when there are more than one HDA bus.
  73. */
  74. bus->idx = 0;
  75. spin_lock_init(&bus->reg_lock);
  76. #endif /* CONFIG_SND_SOC_SOF_HDA */
  77. }