gk20a.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved.
  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 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. #include <subdev/ibus.h>
  23. #include <subdev/timer.h>
  24. static void
  25. gk20a_ibus_init_ibus_ring(struct nvkm_subdev *ibus)
  26. {
  27. struct nvkm_device *device = ibus->device;
  28. nvkm_mask(device, 0x137250, 0x3f, 0);
  29. nvkm_mask(device, 0x000200, 0x20, 0);
  30. udelay(20);
  31. nvkm_mask(device, 0x000200, 0x20, 0x20);
  32. nvkm_wr32(device, 0x12004c, 0x4);
  33. nvkm_wr32(device, 0x122204, 0x2);
  34. nvkm_rd32(device, 0x122204);
  35. /*
  36. * Bug: increase clock timeout to avoid operation failure at high
  37. * gpcclk rate.
  38. */
  39. nvkm_wr32(device, 0x122354, 0x800);
  40. nvkm_wr32(device, 0x128328, 0x800);
  41. nvkm_wr32(device, 0x124320, 0x800);
  42. }
  43. static void
  44. gk20a_ibus_intr(struct nvkm_subdev *ibus)
  45. {
  46. struct nvkm_device *device = ibus->device;
  47. u32 status0 = nvkm_rd32(device, 0x120058);
  48. if (status0 & 0x7) {
  49. nvkm_debug(ibus, "resetting ibus ring\n");
  50. gk20a_ibus_init_ibus_ring(ibus);
  51. }
  52. /* Acknowledge interrupt */
  53. nvkm_mask(device, 0x12004c, 0x2, 0x2);
  54. nvkm_msec(device, 2000,
  55. if (!(nvkm_rd32(device, 0x12004c) & 0x0000003f))
  56. break;
  57. );
  58. }
  59. static int
  60. gk20a_ibus_init(struct nvkm_subdev *ibus)
  61. {
  62. gk20a_ibus_init_ibus_ring(ibus);
  63. return 0;
  64. }
  65. static const struct nvkm_subdev_func
  66. gk20a_ibus = {
  67. .init = gk20a_ibus_init,
  68. .intr = gk20a_ibus_intr,
  69. };
  70. int
  71. gk20a_ibus_new(struct nvkm_device *device, int index,
  72. struct nvkm_subdev **pibus)
  73. {
  74. struct nvkm_subdev *ibus;
  75. if (!(ibus = *pibus = kzalloc(sizeof(*ibus), GFP_KERNEL)))
  76. return -ENOMEM;
  77. nvkm_subdev_ctor(&gk20a_ibus, device, index, ibus);
  78. return 0;
  79. }