gk104.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. static void
  26. gk104_gpio_intr_stat(struct nvkm_gpio *gpio, u32 *hi, u32 *lo)
  27. {
  28. struct nvkm_device *device = gpio->subdev.device;
  29. u32 intr0 = nvkm_rd32(device, 0x00dc00);
  30. u32 intr1 = nvkm_rd32(device, 0x00dc80);
  31. u32 stat0 = nvkm_rd32(device, 0x00dc08) & intr0;
  32. u32 stat1 = nvkm_rd32(device, 0x00dc88) & intr1;
  33. *lo = (stat1 & 0xffff0000) | (stat0 >> 16);
  34. *hi = (stat1 << 16) | (stat0 & 0x0000ffff);
  35. nvkm_wr32(device, 0x00dc00, intr0);
  36. nvkm_wr32(device, 0x00dc80, intr1);
  37. }
  38. static void
  39. gk104_gpio_intr_mask(struct nvkm_gpio *gpio, u32 type, u32 mask, u32 data)
  40. {
  41. struct nvkm_device *device = gpio->subdev.device;
  42. u32 inte0 = nvkm_rd32(device, 0x00dc08);
  43. u32 inte1 = nvkm_rd32(device, 0x00dc88);
  44. if (type & NVKM_GPIO_LO)
  45. inte0 = (inte0 & ~(mask << 16)) | (data << 16);
  46. if (type & NVKM_GPIO_HI)
  47. inte0 = (inte0 & ~(mask & 0xffff)) | (data & 0xffff);
  48. mask >>= 16;
  49. data >>= 16;
  50. if (type & NVKM_GPIO_LO)
  51. inte1 = (inte1 & ~(mask << 16)) | (data << 16);
  52. if (type & NVKM_GPIO_HI)
  53. inte1 = (inte1 & ~mask) | data;
  54. nvkm_wr32(device, 0x00dc08, inte0);
  55. nvkm_wr32(device, 0x00dc88, inte1);
  56. }
  57. static const struct nvkm_gpio_func
  58. gk104_gpio = {
  59. .lines = 32,
  60. .intr_stat = gk104_gpio_intr_stat,
  61. .intr_mask = gk104_gpio_intr_mask,
  62. .drive = gf119_gpio_drive,
  63. .sense = gf119_gpio_sense,
  64. .reset = gf119_gpio_reset,
  65. };
  66. int
  67. gk104_gpio_new(struct nvkm_device *device, int index, struct nvkm_gpio **pgpio)
  68. {
  69. return nvkm_gpio_new_(&gk104_gpio, device, index, pgpio);
  70. }