nouveau_compat.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #include "nouveau_drm.h"
  2. #include "nouveau_compat.h"
  3. #include <subdev/bios.h>
  4. #include <subdev/gpio.h>
  5. void *nouveau_newpriv(struct drm_device *);
  6. u8
  7. _nv_rd08(struct drm_device *dev, u32 reg)
  8. {
  9. struct nouveau_drm *drm = nouveau_newpriv(dev);
  10. return nv_ro08(drm->device, reg);
  11. }
  12. void
  13. _nv_wr08(struct drm_device *dev, u32 reg, u8 val)
  14. {
  15. struct nouveau_drm *drm = nouveau_newpriv(dev);
  16. nv_wo08(drm->device, reg, val);
  17. }
  18. u32
  19. _nv_rd32(struct drm_device *dev, u32 reg)
  20. {
  21. struct nouveau_drm *drm = nouveau_newpriv(dev);
  22. return nv_ro32(drm->device, reg);
  23. }
  24. void
  25. _nv_wr32(struct drm_device *dev, u32 reg, u32 val)
  26. {
  27. struct nouveau_drm *drm = nouveau_newpriv(dev);
  28. nv_wo32(drm->device, reg, val);
  29. }
  30. u32
  31. _nv_mask(struct drm_device *dev, u32 reg, u32 mask, u32 val)
  32. {
  33. u32 tmp = _nv_rd32(dev, reg);
  34. _nv_wr32(dev, reg, (tmp & ~mask) | val);
  35. return tmp;
  36. }
  37. bool
  38. _nv_bios(struct drm_device *dev, u8 **data, u32 *size)
  39. {
  40. struct nouveau_drm *drm = nouveau_newpriv(dev);
  41. struct nouveau_bios *bios = nouveau_bios(drm->device);
  42. *data = bios->data;
  43. *size = bios->size;
  44. return true;
  45. }
  46. void
  47. nouveau_gpio_reset(struct drm_device *dev)
  48. {
  49. struct nouveau_drm *drm = nouveau_newpriv(dev);
  50. struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
  51. gpio->reset(gpio);
  52. }
  53. int
  54. nouveau_gpio_find(struct drm_device *dev, int idx, u8 tag, u8 line,
  55. struct dcb_gpio_func *func)
  56. {
  57. struct nouveau_drm *drm = nouveau_newpriv(dev);
  58. struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
  59. return gpio->find(gpio, idx, tag, line, func);
  60. }
  61. bool
  62. nouveau_gpio_func_valid(struct drm_device *dev, u8 tag)
  63. {
  64. struct nouveau_drm *drm = nouveau_newpriv(dev);
  65. struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
  66. struct dcb_gpio_func func;
  67. return gpio->find(gpio, 0, tag, 0xff, &func) == 0;
  68. }
  69. int
  70. nouveau_gpio_func_set(struct drm_device *dev, u8 tag, int state)
  71. {
  72. struct nouveau_drm *drm = nouveau_newpriv(dev);
  73. struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
  74. if (gpio && gpio->get)
  75. return gpio->set(gpio, 0, tag, 0xff, state);
  76. return -ENODEV;
  77. }
  78. int
  79. nouveau_gpio_func_get(struct drm_device *dev, u8 tag)
  80. {
  81. struct nouveau_drm *drm = nouveau_newpriv(dev);
  82. struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
  83. if (gpio && gpio->get)
  84. return gpio->get(gpio, 0, tag, 0xff);
  85. return -ENODEV;
  86. }
  87. int
  88. nouveau_gpio_irq(struct drm_device *dev, int idx, u8 tag, u8 line, bool on)
  89. {
  90. struct nouveau_drm *drm = nouveau_newpriv(dev);
  91. struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
  92. if (gpio && gpio->irq)
  93. return gpio->irq(gpio, idx, tag, line, on);
  94. return -ENODEV;
  95. }
  96. int
  97. nouveau_gpio_isr_add(struct drm_device *dev, int idx, u8 tag, u8 line,
  98. void (*exec)(void *, int state), void *data)
  99. {
  100. struct nouveau_drm *drm = nouveau_newpriv(dev);
  101. struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
  102. if (gpio && gpio->isr_add)
  103. return gpio->isr_add(gpio, idx, tag, line, exec, data);
  104. return -ENODEV;
  105. }
  106. void
  107. nouveau_gpio_isr_del(struct drm_device *dev, int idx, u8 tag, u8 line,
  108. void (*exec)(void *, int state), void *data)
  109. {
  110. struct nouveau_drm *drm = nouveau_newpriv(dev);
  111. struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
  112. if (gpio && gpio->isr_del)
  113. gpio->isr_del(gpio, idx, tag, line, exec, data);
  114. }