nv50_calc.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 "drm_fixed.h"
  26. #include "nouveau_drv.h"
  27. #include "nouveau_hw.h"
  28. int
  29. nv50_calc_pll(struct drm_device *dev, struct pll_lims *pll, int clk,
  30. int *N1, int *M1, int *N2, int *M2, int *P)
  31. {
  32. struct nouveau_pll_vals pll_vals;
  33. int ret;
  34. ret = nouveau_calc_pll_mnp(dev, pll, clk, &pll_vals);
  35. if (ret <= 0)
  36. return ret;
  37. *N1 = pll_vals.N1;
  38. *M1 = pll_vals.M1;
  39. *N2 = pll_vals.N2;
  40. *M2 = pll_vals.M2;
  41. *P = pll_vals.log2P;
  42. return ret;
  43. }
  44. int
  45. nv50_calc_pll2(struct drm_device *dev, struct pll_lims *pll, int clk,
  46. int *N, int *fN, int *M, int *P)
  47. {
  48. fixed20_12 fb_div, a, b;
  49. *P = pll->vco1.maxfreq / clk;
  50. if (*P > pll->max_p)
  51. *P = pll->max_p;
  52. if (*P < pll->min_p)
  53. *P = pll->min_p;
  54. /* *M = ceil(refclk / pll->vco.max_inputfreq); */
  55. a.full = dfixed_const(pll->refclk);
  56. b.full = dfixed_const(pll->vco1.max_inputfreq);
  57. a.full = dfixed_div(a, b);
  58. a.full = dfixed_ceil(a);
  59. *M = dfixed_trunc(a);
  60. /* fb_div = (vco * *M) / refclk; */
  61. fb_div.full = dfixed_const(clk * *P);
  62. fb_div.full = dfixed_mul(fb_div, a);
  63. a.full = dfixed_const(pll->refclk);
  64. fb_div.full = dfixed_div(fb_div, a);
  65. /* *N = floor(fb_div); */
  66. a.full = dfixed_floor(fb_div);
  67. *N = dfixed_trunc(fb_div);
  68. /* *fN = (fmod(fb_div, 1.0) * 8192) - 4096; */
  69. b.full = dfixed_const(8192);
  70. a.full = dfixed_mul(a, b);
  71. fb_div.full = dfixed_mul(fb_div, b);
  72. fb_div.full = fb_div.full - a.full;
  73. *fN = dfixed_trunc(fb_div) - 4096;
  74. *fN &= 0xffff;
  75. return clk;
  76. }