nva3_pm.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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_bios.h"
  27. #include "nouveau_pm.h"
  28. /*XXX: boards using limits 0x40 need fixing, the register layout
  29. * is correct here, but, there's some other funny magic
  30. * that modifies things, so it's not likely we'll set/read
  31. * the correct timings yet.. working on it...
  32. */
  33. struct nva3_pm_state {
  34. struct pll_lims pll;
  35. int N, M, P;
  36. };
  37. int
  38. nva3_pm_clock_get(struct drm_device *dev, u32 id)
  39. {
  40. struct pll_lims pll;
  41. int P, N, M, ret;
  42. u32 reg;
  43. ret = get_pll_limits(dev, id, &pll);
  44. if (ret)
  45. return ret;
  46. reg = nv_rd32(dev, pll.reg + 4);
  47. P = (reg & 0x003f0000) >> 16;
  48. N = (reg & 0x0000ff00) >> 8;
  49. M = (reg & 0x000000ff);
  50. return pll.refclk * N / M / P;
  51. }
  52. void *
  53. nva3_pm_clock_pre(struct drm_device *dev, struct nouveau_pm_level *perflvl,
  54. u32 id, int khz)
  55. {
  56. struct nva3_pm_state *state;
  57. int dummy, ret;
  58. state = kzalloc(sizeof(*state), GFP_KERNEL);
  59. if (!state)
  60. return ERR_PTR(-ENOMEM);
  61. ret = get_pll_limits(dev, id, &state->pll);
  62. if (ret < 0) {
  63. kfree(state);
  64. return (ret == -ENOENT) ? NULL : ERR_PTR(ret);
  65. }
  66. ret = nv50_calc_pll2(dev, &state->pll, khz, &state->N, &dummy,
  67. &state->M, &state->P);
  68. if (ret < 0) {
  69. kfree(state);
  70. return ERR_PTR(ret);
  71. }
  72. return state;
  73. }
  74. void
  75. nva3_pm_clock_set(struct drm_device *dev, void *pre_state)
  76. {
  77. struct nva3_pm_state *state = pre_state;
  78. u32 reg = state->pll.reg;
  79. nv_wr32(dev, reg + 4, (state->P << 16) | (state->N << 8) | state->M);
  80. kfree(state);
  81. }