gf100.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright 2013 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 "nv50.h"
  25. #include <subdev/bios.h>
  26. #include <subdev/bios/init.h>
  27. #include <subdev/bios/pll.h>
  28. #include <subdev/clk/pll.h>
  29. int
  30. gf100_devinit_pll_set(struct nvkm_devinit *init, u32 type, u32 freq)
  31. {
  32. struct nvkm_subdev *subdev = &init->subdev;
  33. struct nvkm_device *device = subdev->device;
  34. struct nvbios_pll info;
  35. int N, fN, M, P;
  36. int ret;
  37. ret = nvbios_pll_parse(device->bios, type, &info);
  38. if (ret)
  39. return ret;
  40. ret = gt215_pll_calc(subdev, &info, freq, &N, &fN, &M, &P);
  41. if (ret < 0)
  42. return ret;
  43. switch (info.type) {
  44. case PLL_VPLL0:
  45. case PLL_VPLL1:
  46. case PLL_VPLL2:
  47. case PLL_VPLL3:
  48. nvkm_mask(device, info.reg + 0x0c, 0x00000000, 0x00000100);
  49. nvkm_wr32(device, info.reg + 0x04, (P << 16) | (N << 8) | M);
  50. nvkm_wr32(device, info.reg + 0x10, fN << 16);
  51. break;
  52. default:
  53. nvkm_warn(subdev, "%08x/%dKhz unimplemented\n", type, freq);
  54. ret = -EINVAL;
  55. break;
  56. }
  57. return ret;
  58. }
  59. static u64
  60. gf100_devinit_disable(struct nvkm_devinit *init)
  61. {
  62. struct nvkm_device *device = init->subdev.device;
  63. u32 r022500 = nvkm_rd32(device, 0x022500);
  64. u64 disable = 0ULL;
  65. if (r022500 & 0x00000001)
  66. disable |= (1ULL << NVKM_ENGINE_DISP);
  67. if (r022500 & 0x00000002) {
  68. disable |= (1ULL << NVKM_ENGINE_MSPDEC);
  69. disable |= (1ULL << NVKM_ENGINE_MSPPP);
  70. }
  71. if (r022500 & 0x00000004)
  72. disable |= (1ULL << NVKM_ENGINE_MSVLD);
  73. if (r022500 & 0x00000008)
  74. disable |= (1ULL << NVKM_ENGINE_MSENC);
  75. if (r022500 & 0x00000100)
  76. disable |= (1ULL << NVKM_ENGINE_CE0);
  77. if (r022500 & 0x00000200)
  78. disable |= (1ULL << NVKM_ENGINE_CE1);
  79. return disable;
  80. }
  81. void
  82. gf100_devinit_preinit(struct nvkm_devinit *base)
  83. {
  84. struct nv50_devinit *init = nv50_devinit(base);
  85. struct nvkm_subdev *subdev = &init->base.subdev;
  86. struct nvkm_device *device = subdev->device;
  87. /*
  88. * This bit is set by devinit, and flips back to 0 on suspend. We
  89. * can use it as a reliable way to know whether we should run devinit.
  90. */
  91. base->post = ((nvkm_rd32(device, 0x2240c) & BIT(1)) == 0);
  92. }
  93. static const struct nvkm_devinit_func
  94. gf100_devinit = {
  95. .preinit = gf100_devinit_preinit,
  96. .init = nv50_devinit_init,
  97. .post = nv04_devinit_post,
  98. .pll_set = gf100_devinit_pll_set,
  99. .disable = gf100_devinit_disable,
  100. };
  101. int
  102. gf100_devinit_new(struct nvkm_device *device, int index,
  103. struct nvkm_devinit **pinit)
  104. {
  105. return nv50_devinit_new_(&gf100_devinit, device, index, pinit);
  106. }