gt215.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. gt215_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. nvkm_wr32(device, info.reg + 0, 0x50000610);
  47. nvkm_mask(device, info.reg + 4, 0x003fffff,
  48. (P << 16) | (M << 8) | N);
  49. nvkm_wr32(device, info.reg + 8, fN);
  50. break;
  51. default:
  52. nvkm_warn(subdev, "%08x/%dKhz unimplemented\n", type, freq);
  53. ret = -EINVAL;
  54. break;
  55. }
  56. return ret;
  57. }
  58. static u64
  59. gt215_devinit_disable(struct nvkm_devinit *init)
  60. {
  61. struct nvkm_device *device = init->subdev.device;
  62. u32 r001540 = nvkm_rd32(device, 0x001540);
  63. u32 r00154c = nvkm_rd32(device, 0x00154c);
  64. u64 disable = 0ULL;
  65. if (!(r001540 & 0x40000000)) {
  66. disable |= (1ULL << NVKM_ENGINE_MSPDEC);
  67. disable |= (1ULL << NVKM_ENGINE_MSPPP);
  68. }
  69. if (!(r00154c & 0x00000004))
  70. disable |= (1ULL << NVKM_ENGINE_DISP);
  71. if (!(r00154c & 0x00000020))
  72. disable |= (1ULL << NVKM_ENGINE_MSVLD);
  73. if (!(r00154c & 0x00000200))
  74. disable |= (1ULL << NVKM_ENGINE_CE0);
  75. return disable;
  76. }
  77. static u32
  78. gt215_devinit_mmio_part[] = {
  79. 0x100720, 0x1008bc, 4,
  80. 0x100a20, 0x100adc, 4,
  81. 0x100d80, 0x100ddc, 4,
  82. 0x110000, 0x110f9c, 4,
  83. 0x111000, 0x11103c, 8,
  84. 0x111080, 0x1110fc, 4,
  85. 0x111120, 0x1111fc, 4,
  86. 0x111300, 0x1114bc, 4,
  87. 0,
  88. };
  89. static u32
  90. gt215_devinit_mmio(struct nvkm_devinit *base, u32 addr)
  91. {
  92. struct nv50_devinit *init = nv50_devinit(base);
  93. struct nvkm_device *device = init->base.subdev.device;
  94. u32 *mmio = gt215_devinit_mmio_part;
  95. /* the init tables on some boards have INIT_RAM_RESTRICT_ZM_REG_GROUP
  96. * instructions which touch registers that may not even exist on
  97. * some configurations (Quadro 400), which causes the register
  98. * interface to screw up for some amount of time after attempting to
  99. * write to one of these, and results in all sorts of things going
  100. * horribly wrong.
  101. *
  102. * the binary driver avoids touching these registers at all, however,
  103. * the video bios doesn't care and does what the scripts say. it's
  104. * presumed that the io-port access to init registers isn't effected
  105. * by the screw-up bug mentioned above.
  106. *
  107. * really, a new opcode should've been invented to handle these
  108. * requirements, but whatever, it's too late for that now.
  109. */
  110. while (mmio[0]) {
  111. if (addr >= mmio[0] && addr <= mmio[1]) {
  112. u32 part = (addr / mmio[2]) & 7;
  113. if (!init->r001540)
  114. init->r001540 = nvkm_rd32(device, 0x001540);
  115. if (part >= hweight8((init->r001540 >> 16) & 0xff))
  116. return ~0;
  117. return addr;
  118. }
  119. mmio += 3;
  120. }
  121. return addr;
  122. }
  123. static const struct nvkm_devinit_func
  124. gt215_devinit = {
  125. .preinit = nv50_devinit_preinit,
  126. .init = nv50_devinit_init,
  127. .post = nv04_devinit_post,
  128. .mmio = gt215_devinit_mmio,
  129. .pll_set = gt215_devinit_pll_set,
  130. .disable = gt215_devinit_disable,
  131. };
  132. int
  133. gt215_devinit_new(struct nvkm_device *device, int index,
  134. struct nvkm_devinit **pinit)
  135. {
  136. return nv50_devinit_new_(&gt215_devinit, device, index, pinit);
  137. }