nv10.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Copyright (C) 2009 Francisco Jerez.
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * The above copyright notice and this permission notice (including the
  14. * next paragraph) shall be included in all copies or substantial
  15. * portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  20. * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
  21. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. *
  25. */
  26. #include "priv.h"
  27. static int
  28. nv10_gpio_sense(struct nvkm_gpio *gpio, int line)
  29. {
  30. struct nvkm_device *device = gpio->subdev.device;
  31. if (line < 2) {
  32. line = line * 16;
  33. line = nvkm_rd32(device, 0x600818) >> line;
  34. return !!(line & 0x0100);
  35. } else
  36. if (line < 10) {
  37. line = (line - 2) * 4;
  38. line = nvkm_rd32(device, 0x60081c) >> line;
  39. return !!(line & 0x04);
  40. } else
  41. if (line < 14) {
  42. line = (line - 10) * 4;
  43. line = nvkm_rd32(device, 0x600850) >> line;
  44. return !!(line & 0x04);
  45. }
  46. return -EINVAL;
  47. }
  48. static int
  49. nv10_gpio_drive(struct nvkm_gpio *gpio, int line, int dir, int out)
  50. {
  51. struct nvkm_device *device = gpio->subdev.device;
  52. u32 reg, mask, data;
  53. if (line < 2) {
  54. line = line * 16;
  55. reg = 0x600818;
  56. mask = 0x00000011;
  57. data = (dir << 4) | out;
  58. } else
  59. if (line < 10) {
  60. line = (line - 2) * 4;
  61. reg = 0x60081c;
  62. mask = 0x00000003;
  63. data = (dir << 1) | out;
  64. } else
  65. if (line < 14) {
  66. line = (line - 10) * 4;
  67. reg = 0x600850;
  68. mask = 0x00000003;
  69. data = (dir << 1) | out;
  70. } else {
  71. return -EINVAL;
  72. }
  73. nvkm_mask(device, reg, mask << line, data << line);
  74. return 0;
  75. }
  76. static void
  77. nv10_gpio_intr_stat(struct nvkm_gpio *gpio, u32 *hi, u32 *lo)
  78. {
  79. struct nvkm_device *device = gpio->subdev.device;
  80. u32 intr = nvkm_rd32(device, 0x001104);
  81. u32 stat = nvkm_rd32(device, 0x001144) & intr;
  82. *lo = (stat & 0xffff0000) >> 16;
  83. *hi = (stat & 0x0000ffff);
  84. nvkm_wr32(device, 0x001104, intr);
  85. }
  86. static void
  87. nv10_gpio_intr_mask(struct nvkm_gpio *gpio, u32 type, u32 mask, u32 data)
  88. {
  89. struct nvkm_device *device = gpio->subdev.device;
  90. u32 inte = nvkm_rd32(device, 0x001144);
  91. if (type & NVKM_GPIO_LO)
  92. inte = (inte & ~(mask << 16)) | (data << 16);
  93. if (type & NVKM_GPIO_HI)
  94. inte = (inte & ~mask) | data;
  95. nvkm_wr32(device, 0x001144, inte);
  96. }
  97. static const struct nvkm_gpio_func
  98. nv10_gpio = {
  99. .lines = 16,
  100. .intr_stat = nv10_gpio_intr_stat,
  101. .intr_mask = nv10_gpio_intr_mask,
  102. .drive = nv10_gpio_drive,
  103. .sense = nv10_gpio_sense,
  104. };
  105. int
  106. nv10_gpio_new(struct nvkm_device *device, int index, struct nvkm_gpio **pgpio)
  107. {
  108. return nvkm_gpio_new_(&nv10_gpio, device, index, pgpio);
  109. }