nv50_gpio.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * Copyright 2010 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 <linux/dmi.h>
  25. #include "drmP.h"
  26. #include "nouveau_drv.h"
  27. #include "nouveau_hw.h"
  28. #include "nouveau_gpio.h"
  29. #include "nv50_display.h"
  30. static int
  31. nv50_gpio_location(int line, u32 *reg, u32 *shift)
  32. {
  33. const uint32_t nv50_gpio_reg[4] = { 0xe104, 0xe108, 0xe280, 0xe284 };
  34. if (line >= 32)
  35. return -EINVAL;
  36. *reg = nv50_gpio_reg[line >> 3];
  37. *shift = (line & 7) << 2;
  38. return 0;
  39. }
  40. int
  41. nv50_gpio_drive(struct drm_device *dev, int line, int dir, int out)
  42. {
  43. u32 reg, shift;
  44. if (nv50_gpio_location(line, &reg, &shift))
  45. return -EINVAL;
  46. nv_mask(dev, reg, 7 << shift, (((dir ^ 1) << 1) | out) << shift);
  47. return 0;
  48. }
  49. int
  50. nv50_gpio_sense(struct drm_device *dev, int line)
  51. {
  52. u32 reg, shift;
  53. if (nv50_gpio_location(line, &reg, &shift))
  54. return -EINVAL;
  55. return !!(nv_rd32(dev, reg) & (4 << shift));
  56. }
  57. void
  58. nv50_gpio_irq_enable(struct drm_device *dev, int line, bool on)
  59. {
  60. u32 reg = line < 16 ? 0xe050 : 0xe070;
  61. u32 mask = 0x00010001 << (line & 0xf);
  62. nv_wr32(dev, reg + 4, mask);
  63. nv_mask(dev, reg + 0, mask, on ? mask : 0);
  64. }
  65. int
  66. nvd0_gpio_drive(struct drm_device *dev, int line, int dir, int out)
  67. {
  68. u32 data = ((dir ^ 1) << 13) | (out << 12);
  69. nv_mask(dev, 0x00d610 + (line * 4), 0x00003000, data);
  70. nv_mask(dev, 0x00d604, 0x00000001, 0x00000001); /* update? */
  71. return 0;
  72. }
  73. int
  74. nvd0_gpio_sense(struct drm_device *dev, int line)
  75. {
  76. return !!(nv_rd32(dev, 0x00d610 + (line * 4)) & 0x00004000);
  77. }
  78. static void
  79. nv50_gpio_isr(struct drm_device *dev)
  80. {
  81. struct drm_nouveau_private *dev_priv = dev->dev_private;
  82. u32 intr0, intr1 = 0;
  83. u32 hi, lo;
  84. intr0 = nv_rd32(dev, 0xe054) & nv_rd32(dev, 0xe050);
  85. if (dev_priv->chipset >= 0x90)
  86. intr1 = nv_rd32(dev, 0xe074) & nv_rd32(dev, 0xe070);
  87. hi = (intr0 & 0x0000ffff) | (intr1 << 16);
  88. lo = (intr0 >> 16) | (intr1 & 0xffff0000);
  89. nouveau_gpio_isr(dev, 0, hi | lo);
  90. nv_wr32(dev, 0xe054, intr0);
  91. if (dev_priv->chipset >= 0x90)
  92. nv_wr32(dev, 0xe074, intr1);
  93. }
  94. static struct dmi_system_id gpio_reset_ids[] = {
  95. {
  96. .ident = "Apple Macbook 10,1",
  97. .matches = {
  98. DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
  99. DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro10,1"),
  100. }
  101. },
  102. { }
  103. };
  104. int
  105. nv50_gpio_init(struct drm_device *dev)
  106. {
  107. struct drm_nouveau_private *dev_priv = dev->dev_private;
  108. /* initialise gpios and routing to vbios defaults */
  109. if (dmi_check_system(gpio_reset_ids))
  110. nouveau_gpio_reset(dev);
  111. /* disable, and ack any pending gpio interrupts */
  112. nv_wr32(dev, 0xe050, 0x00000000);
  113. nv_wr32(dev, 0xe054, 0xffffffff);
  114. if (dev_priv->chipset >= 0x90) {
  115. nv_wr32(dev, 0xe070, 0x00000000);
  116. nv_wr32(dev, 0xe074, 0xffffffff);
  117. }
  118. nouveau_irq_register(dev, 21, nv50_gpio_isr);
  119. return 0;
  120. }
  121. void
  122. nv50_gpio_fini(struct drm_device *dev)
  123. {
  124. struct drm_nouveau_private *dev_priv = dev->dev_private;
  125. nv_wr32(dev, 0xe050, 0x00000000);
  126. if (dev_priv->chipset >= 0x90)
  127. nv_wr32(dev, 0xe070, 0x00000000);
  128. nouveau_irq_unregister(dev, 21);
  129. }