nv04_pm.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Copyright 2010 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_hw.h"
  27. #include "nouveau_pm.h"
  28. int
  29. nv04_pm_clocks_get(struct drm_device *dev, struct nouveau_pm_level *perflvl)
  30. {
  31. int ret;
  32. ret = nouveau_hw_get_clock(dev, PLL_CORE);
  33. if (ret < 0)
  34. return ret;
  35. perflvl->core = ret;
  36. ret = nouveau_hw_get_clock(dev, PLL_MEMORY);
  37. if (ret < 0)
  38. return ret;
  39. perflvl->memory = ret;
  40. return 0;
  41. }
  42. struct nv04_pm_clock {
  43. struct pll_lims pll;
  44. struct nouveau_pll_vals calc;
  45. };
  46. struct nv04_pm_state {
  47. struct nv04_pm_clock core;
  48. struct nv04_pm_clock memory;
  49. };
  50. static int
  51. calc_pll(struct drm_device *dev, u32 id, int khz, struct nv04_pm_clock *clk)
  52. {
  53. int ret;
  54. ret = get_pll_limits(dev, id, &clk->pll);
  55. if (ret)
  56. return ret;
  57. ret = nouveau_calc_pll_mnp(dev, &clk->pll, khz, &clk->calc);
  58. if (!ret)
  59. return -EINVAL;
  60. return 0;
  61. }
  62. void *
  63. nv04_pm_clocks_pre(struct drm_device *dev, struct nouveau_pm_level *perflvl)
  64. {
  65. struct nv04_pm_state *info;
  66. int ret;
  67. info = kzalloc(sizeof(*info), GFP_KERNEL);
  68. if (!info)
  69. return ERR_PTR(-ENOMEM);
  70. ret = calc_pll(dev, PLL_CORE, perflvl->core, &info->core);
  71. if (ret)
  72. goto error;
  73. if (perflvl->memory) {
  74. ret = calc_pll(dev, PLL_MEMORY, perflvl->memory, &info->memory);
  75. if (ret)
  76. goto error;
  77. }
  78. return info;
  79. error:
  80. kfree(info);
  81. return ERR_PTR(ret);
  82. }
  83. static void
  84. prog_pll(struct drm_device *dev, struct nv04_pm_clock *clk)
  85. {
  86. struct drm_nouveau_private *dev_priv = dev->dev_private;
  87. u32 reg = clk->pll.reg;
  88. /* thank the insane nouveau_hw_setpll() interface for this */
  89. if (dev_priv->card_type >= NV_40)
  90. reg += 4;
  91. nouveau_hw_setpll(dev, reg, &clk->calc);
  92. }
  93. int
  94. nv04_pm_clocks_set(struct drm_device *dev, void *pre_state)
  95. {
  96. struct drm_nouveau_private *dev_priv = dev->dev_private;
  97. struct nouveau_timer_engine *ptimer = &dev_priv->engine.timer;
  98. struct nv04_pm_state *state = pre_state;
  99. prog_pll(dev, &state->core);
  100. if (state->memory.pll.reg) {
  101. prog_pll(dev, &state->memory);
  102. if (dev_priv->card_type < NV_30) {
  103. if (dev_priv->card_type == NV_20)
  104. nv_mask(dev, 0x1002c4, 0, 1 << 20);
  105. /* Reset the DLLs */
  106. nv_mask(dev, 0x1002c0, 0, 1 << 8);
  107. }
  108. }
  109. ptimer->init(dev);
  110. kfree(state);
  111. return 0;
  112. }