dacnv50.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 "nv50.h"
  25. #include "outp.h"
  26. #include <core/client.h>
  27. #include <subdev/timer.h>
  28. #include <nvif/cl5070.h>
  29. #include <nvif/unpack.h>
  30. int
  31. nv50_dac_power(NV50_DISP_MTHD_V1)
  32. {
  33. struct nvkm_device *device = disp->base.engine.subdev.device;
  34. const u32 doff = outp->or * 0x800;
  35. union {
  36. struct nv50_disp_dac_pwr_v0 v0;
  37. } *args = data;
  38. u32 stat;
  39. int ret = -ENOSYS;
  40. nvif_ioctl(object, "disp dac pwr size %d\n", size);
  41. if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, false))) {
  42. nvif_ioctl(object, "disp dac pwr vers %d state %d data %d "
  43. "vsync %d hsync %d\n",
  44. args->v0.version, args->v0.state, args->v0.data,
  45. args->v0.vsync, args->v0.hsync);
  46. stat = 0x00000040 * !args->v0.state;
  47. stat |= 0x00000010 * !args->v0.data;
  48. stat |= 0x00000004 * !args->v0.vsync;
  49. stat |= 0x00000001 * !args->v0.hsync;
  50. } else
  51. return ret;
  52. nvkm_msec(device, 2000,
  53. if (!(nvkm_rd32(device, 0x61a004 + doff) & 0x80000000))
  54. break;
  55. );
  56. nvkm_mask(device, 0x61a004 + doff, 0xc000007f, 0x80000000 | stat);
  57. nvkm_msec(device, 2000,
  58. if (!(nvkm_rd32(device, 0x61a004 + doff) & 0x80000000))
  59. break;
  60. );
  61. return 0;
  62. }
  63. int
  64. nv50_dac_sense(NV50_DISP_MTHD_V1)
  65. {
  66. struct nvkm_subdev *subdev = &disp->base.engine.subdev;
  67. struct nvkm_device *device = subdev->device;
  68. union {
  69. struct nv50_disp_dac_load_v0 v0;
  70. } *args = data;
  71. const u32 doff = outp->or * 0x800;
  72. u32 loadval;
  73. int ret = -ENOSYS;
  74. nvif_ioctl(object, "disp dac load size %d\n", size);
  75. if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, false))) {
  76. nvif_ioctl(object, "disp dac load vers %d data %08x\n",
  77. args->v0.version, args->v0.data);
  78. if (args->v0.data & 0xfff00000)
  79. return -EINVAL;
  80. loadval = args->v0.data;
  81. } else
  82. return ret;
  83. nvkm_mask(device, 0x61a004 + doff, 0x807f0000, 0x80150000);
  84. nvkm_msec(device, 2000,
  85. if (!(nvkm_rd32(device, 0x61a004 + doff) & 0x80000000))
  86. break;
  87. );
  88. nvkm_wr32(device, 0x61a00c + doff, 0x00100000 | loadval);
  89. mdelay(9);
  90. udelay(500);
  91. loadval = nvkm_mask(device, 0x61a00c + doff, 0xffffffff, 0x00000000);
  92. nvkm_mask(device, 0x61a004 + doff, 0x807f0000, 0x80550000);
  93. nvkm_msec(device, 2000,
  94. if (!(nvkm_rd32(device, 0x61a004 + doff) & 0x80000000))
  95. break;
  96. );
  97. nvkm_debug(subdev, "DAC%d sense: %08x\n", outp->or, loadval);
  98. if (!(loadval & 0x80000000))
  99. return -ETIMEDOUT;
  100. args->v0.load = (loadval & 0x38000000) >> 27;
  101. return 0;
  102. }
  103. static const struct nvkm_output_func
  104. nv50_dac_output_func = {
  105. };
  106. int
  107. nv50_dac_output_new(struct nvkm_disp *disp, int index,
  108. struct dcb_output *dcbE, struct nvkm_output **poutp)
  109. {
  110. return nvkm_output_new_(&nv50_dac_output_func, disp,
  111. index, dcbE, poutp);
  112. }