base.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 <core/option.h>
  26. #include <subdev/vga.h>
  27. u32
  28. nvkm_devinit_mmio(struct nvkm_devinit *init, u32 addr)
  29. {
  30. if (init->func->mmio)
  31. addr = init->func->mmio(init, addr);
  32. return addr;
  33. }
  34. int
  35. nvkm_devinit_pll_set(struct nvkm_devinit *init, u32 type, u32 khz)
  36. {
  37. return init->func->pll_set(init, type, khz);
  38. }
  39. void
  40. nvkm_devinit_meminit(struct nvkm_devinit *init)
  41. {
  42. if (init->func->meminit)
  43. init->func->meminit(init);
  44. }
  45. u64
  46. nvkm_devinit_disable(struct nvkm_devinit *init)
  47. {
  48. if (init && init->func->disable)
  49. return init->func->disable(init);
  50. return 0;
  51. }
  52. int
  53. nvkm_devinit_post(struct nvkm_devinit *init, u64 *disable)
  54. {
  55. int ret = 0;
  56. if (init && init->func->post)
  57. ret = init->func->post(init, init->post);
  58. *disable = nvkm_devinit_disable(init);
  59. return ret;
  60. }
  61. static int
  62. nvkm_devinit_fini(struct nvkm_subdev *subdev, bool suspend)
  63. {
  64. struct nvkm_devinit *init = nvkm_devinit(subdev);
  65. /* force full reinit on resume */
  66. if (suspend)
  67. init->post = true;
  68. return 0;
  69. }
  70. static int
  71. nvkm_devinit_preinit(struct nvkm_subdev *subdev)
  72. {
  73. struct nvkm_devinit *init = nvkm_devinit(subdev);
  74. if (init->func->preinit)
  75. init->func->preinit(init);
  76. /* Override the post flag during the first call if NvForcePost is set */
  77. if (init->force_post) {
  78. init->post = init->force_post;
  79. init->force_post = false;
  80. }
  81. /* unlock the extended vga crtc regs */
  82. nvkm_lockvgac(subdev->device, false);
  83. return 0;
  84. }
  85. static int
  86. nvkm_devinit_init(struct nvkm_subdev *subdev)
  87. {
  88. struct nvkm_devinit *init = nvkm_devinit(subdev);
  89. if (init->func->init)
  90. init->func->init(init);
  91. return 0;
  92. }
  93. static void *
  94. nvkm_devinit_dtor(struct nvkm_subdev *subdev)
  95. {
  96. struct nvkm_devinit *init = nvkm_devinit(subdev);
  97. void *data = init;
  98. if (init->func->dtor)
  99. data = init->func->dtor(init);
  100. /* lock crtc regs */
  101. nvkm_lockvgac(subdev->device, true);
  102. return data;
  103. }
  104. static const struct nvkm_subdev_func
  105. nvkm_devinit = {
  106. .dtor = nvkm_devinit_dtor,
  107. .preinit = nvkm_devinit_preinit,
  108. .init = nvkm_devinit_init,
  109. .fini = nvkm_devinit_fini,
  110. };
  111. void
  112. nvkm_devinit_ctor(const struct nvkm_devinit_func *func,
  113. struct nvkm_device *device, int index,
  114. struct nvkm_devinit *init)
  115. {
  116. nvkm_subdev_ctor(&nvkm_devinit, device, index, &init->subdev);
  117. init->func = func;
  118. init->force_post = nvkm_boolopt(device->cfgopt, "NvForcePost", false);
  119. }