hda_i915.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * hda_i915.c - routines for Haswell HDA controller power well support
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the Free
  6. * Software Foundation; either version 2 of the License, or (at your option)
  7. * any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software Foundation,
  16. * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. #include <linux/init.h>
  19. #include <linux/module.h>
  20. #include <sound/core.h>
  21. #include <drm/i915_powerwell.h>
  22. #include "hda_priv.h"
  23. #include "hda_i915.h"
  24. /* Intel HSW/BDW display HDA controller Extended Mode registers.
  25. * EM4 (M value) and EM5 (N Value) are used to convert CDClk (Core Display
  26. * Clock) to 24MHz BCLK: BCLK = CDCLK * M / N
  27. * The values will be lost when the display power well is disabled.
  28. */
  29. #define AZX_REG_EM4 0x100c
  30. #define AZX_REG_EM5 0x1010
  31. static int (*get_power)(void);
  32. static int (*put_power)(void);
  33. static int (*get_cdclk)(void);
  34. int hda_display_power(bool enable)
  35. {
  36. if (!get_power || !put_power)
  37. return -ENODEV;
  38. pr_debug("HDA display power %s \n",
  39. enable ? "Enable" : "Disable");
  40. if (enable)
  41. return get_power();
  42. else
  43. return put_power();
  44. }
  45. void haswell_set_bclk(struct azx *chip)
  46. {
  47. int cdclk_freq;
  48. unsigned int bclk_m, bclk_n;
  49. if (!get_cdclk)
  50. return;
  51. cdclk_freq = get_cdclk();
  52. switch (cdclk_freq) {
  53. case 337500:
  54. bclk_m = 16;
  55. bclk_n = 225;
  56. break;
  57. case 450000:
  58. default: /* default CDCLK 450MHz */
  59. bclk_m = 4;
  60. bclk_n = 75;
  61. break;
  62. case 540000:
  63. bclk_m = 4;
  64. bclk_n = 90;
  65. break;
  66. case 675000:
  67. bclk_m = 8;
  68. bclk_n = 225;
  69. break;
  70. }
  71. azx_writew(chip, EM4, bclk_m);
  72. azx_writew(chip, EM5, bclk_n);
  73. }
  74. int hda_i915_init(void)
  75. {
  76. int err = 0;
  77. get_power = symbol_request(i915_request_power_well);
  78. if (!get_power) {
  79. pr_warn("hda-i915: get_power symbol get fail\n");
  80. return -ENODEV;
  81. }
  82. put_power = symbol_request(i915_release_power_well);
  83. if (!put_power) {
  84. symbol_put(i915_request_power_well);
  85. get_power = NULL;
  86. return -ENODEV;
  87. }
  88. get_cdclk = symbol_request(i915_get_cdclk_freq);
  89. if (!get_cdclk) /* may have abnormal BCLK and audio playback rate */
  90. pr_warn("hda-i915: get_cdclk symbol get fail\n");
  91. pr_debug("HDA driver get symbol successfully from i915 module\n");
  92. return err;
  93. }
  94. int hda_i915_exit(void)
  95. {
  96. if (get_power) {
  97. symbol_put(i915_request_power_well);
  98. get_power = NULL;
  99. }
  100. if (put_power) {
  101. symbol_put(i915_release_power_well);
  102. put_power = NULL;
  103. }
  104. if (get_cdclk) {
  105. symbol_put(i915_get_cdclk_freq);
  106. get_cdclk = NULL;
  107. }
  108. return 0;
  109. }