nouveau_compat.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. #include "nouveau_drm.h"
  2. #include "nouveau_compat.h"
  3. #include <subdev/bios.h>
  4. #include <subdev/gpio.h>
  5. #include <subdev/i2c.h>
  6. void *nouveau_newpriv(struct drm_device *);
  7. u8
  8. _nv_rd08(struct drm_device *dev, u32 reg)
  9. {
  10. struct nouveau_drm *drm = nouveau_newpriv(dev);
  11. return nv_ro08(drm->device, reg);
  12. }
  13. void
  14. _nv_wr08(struct drm_device *dev, u32 reg, u8 val)
  15. {
  16. struct nouveau_drm *drm = nouveau_newpriv(dev);
  17. nv_wo08(drm->device, reg, val);
  18. }
  19. u32
  20. _nv_rd32(struct drm_device *dev, u32 reg)
  21. {
  22. struct nouveau_drm *drm = nouveau_newpriv(dev);
  23. return nv_ro32(drm->device, reg);
  24. }
  25. void
  26. _nv_wr32(struct drm_device *dev, u32 reg, u32 val)
  27. {
  28. struct nouveau_drm *drm = nouveau_newpriv(dev);
  29. nv_wo32(drm->device, reg, val);
  30. }
  31. u32
  32. _nv_mask(struct drm_device *dev, u32 reg, u32 mask, u32 val)
  33. {
  34. u32 tmp = _nv_rd32(dev, reg);
  35. _nv_wr32(dev, reg, (tmp & ~mask) | val);
  36. return tmp;
  37. }
  38. bool
  39. _nv_bios(struct drm_device *dev, u8 **data, u32 *size)
  40. {
  41. struct nouveau_drm *drm = nouveau_newpriv(dev);
  42. struct nouveau_bios *bios = nouveau_bios(drm->device);
  43. *data = bios->data;
  44. *size = bios->size;
  45. return true;
  46. }
  47. void
  48. nouveau_gpio_reset(struct drm_device *dev)
  49. {
  50. struct nouveau_drm *drm = nouveau_newpriv(dev);
  51. struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
  52. gpio->reset(gpio);
  53. }
  54. int
  55. nouveau_gpio_find(struct drm_device *dev, int idx, u8 tag, u8 line,
  56. struct dcb_gpio_func *func)
  57. {
  58. struct nouveau_drm *drm = nouveau_newpriv(dev);
  59. struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
  60. return gpio->find(gpio, idx, tag, line, func);
  61. }
  62. bool
  63. nouveau_gpio_func_valid(struct drm_device *dev, u8 tag)
  64. {
  65. struct nouveau_drm *drm = nouveau_newpriv(dev);
  66. struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
  67. struct dcb_gpio_func func;
  68. return gpio->find(gpio, 0, tag, 0xff, &func) == 0;
  69. }
  70. int
  71. nouveau_gpio_func_set(struct drm_device *dev, u8 tag, int state)
  72. {
  73. struct nouveau_drm *drm = nouveau_newpriv(dev);
  74. struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
  75. if (gpio && gpio->get)
  76. return gpio->set(gpio, 0, tag, 0xff, state);
  77. return -ENODEV;
  78. }
  79. int
  80. nouveau_gpio_func_get(struct drm_device *dev, u8 tag)
  81. {
  82. struct nouveau_drm *drm = nouveau_newpriv(dev);
  83. struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
  84. if (gpio && gpio->get)
  85. return gpio->get(gpio, 0, tag, 0xff);
  86. return -ENODEV;
  87. }
  88. int
  89. nouveau_gpio_irq(struct drm_device *dev, int idx, u8 tag, u8 line, bool on)
  90. {
  91. struct nouveau_drm *drm = nouveau_newpriv(dev);
  92. struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
  93. if (gpio && gpio->irq)
  94. return gpio->irq(gpio, idx, tag, line, on);
  95. return -ENODEV;
  96. }
  97. int
  98. nouveau_gpio_isr_add(struct drm_device *dev, int idx, u8 tag, u8 line,
  99. void (*exec)(void *, int state), void *data)
  100. {
  101. struct nouveau_drm *drm = nouveau_newpriv(dev);
  102. struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
  103. if (gpio && gpio->isr_add)
  104. return gpio->isr_add(gpio, idx, tag, line, exec, data);
  105. return -ENODEV;
  106. }
  107. void
  108. nouveau_gpio_isr_del(struct drm_device *dev, int idx, u8 tag, u8 line,
  109. void (*exec)(void *, int state), void *data)
  110. {
  111. struct nouveau_drm *drm = nouveau_newpriv(dev);
  112. struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
  113. if (gpio && gpio->isr_del)
  114. gpio->isr_del(gpio, idx, tag, line, exec, data);
  115. }
  116. struct nouveau_i2c_port *
  117. nouveau_i2c_find(struct drm_device *dev, u8 index)
  118. {
  119. struct nouveau_drm *drm = nouveau_newpriv(dev);
  120. struct nouveau_i2c *i2c = nouveau_i2c(drm->device);
  121. return i2c->find(i2c, index);
  122. }
  123. bool
  124. nouveau_probe_i2c_addr(struct nouveau_i2c_port *port, int addr)
  125. {
  126. return nv_probe_i2c(port, addr);
  127. }
  128. struct i2c_adapter *
  129. nouveau_i2c_adapter(struct nouveau_i2c_port *port)
  130. {
  131. return &port->adapter;
  132. }
  133. int
  134. nouveau_i2c_identify(struct drm_device *dev, const char *what,
  135. struct i2c_board_info *info,
  136. bool (*match)(struct nouveau_i2c_port *,
  137. struct i2c_board_info *),
  138. int index)
  139. {
  140. struct nouveau_drm *drm = nouveau_newpriv(dev);
  141. struct nouveau_i2c *i2c = nouveau_i2c(drm->device);
  142. return i2c->identify(i2c, index, what, info, match);
  143. }
  144. int
  145. auxch_rd(struct drm_device *dev, struct nouveau_i2c_port *port,
  146. u32 addr, u8 *data, u8 size)
  147. {
  148. return nv_rdaux(port, addr, data, size);
  149. }
  150. int
  151. auxch_wr(struct drm_device *dev, struct nouveau_i2c_port *port,
  152. u32 addr, u8 *data, u8 size)
  153. {
  154. return nv_wraux(port, addr, data, size);
  155. }