nvc0_pm.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * Copyright 2011 Red Hat Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Ben Skeggs
  23. */
  24. #include "drmP.h"
  25. #include "nouveau_drv.h"
  26. #include "nouveau_bios.h"
  27. #include "nouveau_pm.h"
  28. static u32 read_div(struct drm_device *, int, u32, u32);
  29. static u32 read_pll(struct drm_device *, u32);
  30. static u32
  31. read_vco(struct drm_device *dev, u32 dsrc)
  32. {
  33. u32 ssrc = nv_rd32(dev, dsrc);
  34. if (!(ssrc & 0x00000100))
  35. return read_pll(dev, 0x00e800);
  36. return read_pll(dev, 0x00e820);
  37. }
  38. static u32
  39. read_pll(struct drm_device *dev, u32 pll)
  40. {
  41. u32 ctrl = nv_rd32(dev, pll + 0);
  42. u32 coef = nv_rd32(dev, pll + 4);
  43. u32 P = (coef & 0x003f0000) >> 16;
  44. u32 N = (coef & 0x0000ff00) >> 8;
  45. u32 M = (coef & 0x000000ff) >> 0;
  46. u32 sclk, doff;
  47. if (!(ctrl & 0x00000001))
  48. return 0;
  49. switch (pll & 0xfff000) {
  50. case 0x00e000:
  51. sclk = 27000;
  52. P = 1;
  53. break;
  54. case 0x137000:
  55. doff = (pll - 0x137000) / 0x20;
  56. sclk = read_div(dev, doff, 0x137120, 0x137140);
  57. break;
  58. case 0x132000:
  59. switch (pll) {
  60. case 0x132000:
  61. sclk = read_pll(dev, 0x132020);
  62. break;
  63. case 0x132020:
  64. sclk = read_div(dev, 0, 0x137320, 0x137330);
  65. break;
  66. default:
  67. return 0;
  68. }
  69. break;
  70. default:
  71. return 0;
  72. }
  73. return sclk * N / M / P;
  74. }
  75. static u32
  76. read_div(struct drm_device *dev, int doff, u32 dsrc, u32 dctl)
  77. {
  78. u32 ssrc = nv_rd32(dev, dsrc + (doff * 4));
  79. u32 sctl = nv_rd32(dev, dctl + (doff * 4));
  80. switch (ssrc & 0x00000003) {
  81. case 0:
  82. if ((ssrc & 0x00030000) != 0x00030000)
  83. return 27000;
  84. return 108000;
  85. case 2:
  86. return 100000;
  87. case 3:
  88. if (sctl & 0x80000000) {
  89. u32 sclk = read_vco(dev, dsrc + (doff * 4));
  90. u32 sdiv = (sctl & 0x0000003f) + 2;
  91. return (sclk * 2) / sdiv;
  92. }
  93. return read_vco(dev, dsrc + (doff * 4));
  94. default:
  95. return 0;
  96. }
  97. }
  98. static u32
  99. read_mem(struct drm_device *dev)
  100. {
  101. u32 ssel = nv_rd32(dev, 0x1373f0);
  102. if (ssel & 0x00000001)
  103. return read_div(dev, 0, 0x137300, 0x137310);
  104. return read_pll(dev, 0x132000);
  105. }
  106. static u32
  107. read_clk(struct drm_device *dev, int clk)
  108. {
  109. u32 sctl = nv_rd32(dev, 0x137250 + (clk * 4));
  110. u32 ssel = nv_rd32(dev, 0x137100);
  111. u32 sclk, sdiv;
  112. if (ssel & (1 << clk)) {
  113. if (clk < 7)
  114. sclk = read_pll(dev, 0x137000 + (clk * 0x20));
  115. else
  116. sclk = read_pll(dev, 0x1370e0);
  117. sdiv = ((sctl & 0x00003f00) >> 8) + 2;
  118. } else {
  119. sclk = read_div(dev, clk, 0x137160, 0x1371d0);
  120. sdiv = ((sctl & 0x0000003f) >> 0) + 2;
  121. }
  122. if (sctl & 0x80000000)
  123. return (sclk * 2) / sdiv;
  124. return sclk;
  125. }
  126. int
  127. nvc0_pm_clocks_get(struct drm_device *dev, struct nouveau_pm_level *perflvl)
  128. {
  129. perflvl->shader = read_clk(dev, 0x00);
  130. perflvl->core = perflvl->shader / 2;
  131. perflvl->memory = read_mem(dev);
  132. perflvl->rop = read_clk(dev, 0x01);
  133. perflvl->hub07 = read_clk(dev, 0x02);
  134. perflvl->hub06 = read_clk(dev, 0x07);
  135. perflvl->hub01 = read_clk(dev, 0x08);
  136. perflvl->copy = read_clk(dev, 0x09);
  137. perflvl->daemon = read_clk(dev, 0x0c);
  138. perflvl->vdec = read_clk(dev, 0x0e);
  139. return 0;
  140. }