nv04.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright 2012 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 "priv.h"
  25. #include "pll.h"
  26. #include <subdev/bios.h>
  27. #include <subdev/bios/pll.h>
  28. #include <subdev/devinit/nv04.h>
  29. int
  30. nv04_clk_pll_calc(struct nvkm_clk *clock, struct nvbios_pll *info,
  31. int clk, struct nvkm_pll_vals *pv)
  32. {
  33. int N1, M1, N2, M2, P;
  34. int ret = nv04_pll_calc(&clock->subdev, info, clk, &N1, &M1, &N2, &M2, &P);
  35. if (ret) {
  36. pv->refclk = info->refclk;
  37. pv->N1 = N1;
  38. pv->M1 = M1;
  39. pv->N2 = N2;
  40. pv->M2 = M2;
  41. pv->log2P = P;
  42. }
  43. return ret;
  44. }
  45. int
  46. nv04_clk_pll_prog(struct nvkm_clk *clk, u32 reg1, struct nvkm_pll_vals *pv)
  47. {
  48. struct nvkm_device *device = clk->subdev.device;
  49. struct nvkm_devinit *devinit = device->devinit;
  50. int cv = device->bios->version.chip;
  51. if (cv == 0x30 || cv == 0x31 || cv == 0x35 || cv == 0x36 ||
  52. cv >= 0x40) {
  53. if (reg1 > 0x405c)
  54. setPLL_double_highregs(devinit, reg1, pv);
  55. else
  56. setPLL_double_lowregs(devinit, reg1, pv);
  57. } else
  58. setPLL_single(devinit, reg1, pv);
  59. return 0;
  60. }
  61. static const struct nvkm_clk_func
  62. nv04_clk = {
  63. .domains = {
  64. { nv_clk_src_max }
  65. }
  66. };
  67. int
  68. nv04_clk_new(struct nvkm_device *device, int index, struct nvkm_clk **pclk)
  69. {
  70. int ret = nvkm_clk_new_(&nv04_clk, device, index, false, pclk);
  71. if (ret == 0) {
  72. (*pclk)->pll_calc = nv04_clk_pll_calc;
  73. (*pclk)->pll_prog = nv04_clk_pll_prog;
  74. }
  75. return ret;
  76. }