nouveau_compat.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. #include "nouveau_drm.h"
  2. #include "nouveau_compat.h"
  3. #include <subdev/bios.h>
  4. #include <subdev/bios/pll.h>
  5. #include <subdev/gpio.h>
  6. #include <subdev/i2c.h>
  7. #include <subdev/clock.h>
  8. void *nouveau_newpriv(struct drm_device *);
  9. u8
  10. _nv_rd08(struct drm_device *dev, u32 reg)
  11. {
  12. struct nouveau_drm *drm = nouveau_newpriv(dev);
  13. return nv_ro08(drm->device, reg);
  14. }
  15. void
  16. _nv_wr08(struct drm_device *dev, u32 reg, u8 val)
  17. {
  18. struct nouveau_drm *drm = nouveau_newpriv(dev);
  19. nv_wo08(drm->device, reg, val);
  20. }
  21. u32
  22. _nv_rd32(struct drm_device *dev, u32 reg)
  23. {
  24. struct nouveau_drm *drm = nouveau_newpriv(dev);
  25. return nv_ro32(drm->device, reg);
  26. }
  27. void
  28. _nv_wr32(struct drm_device *dev, u32 reg, u32 val)
  29. {
  30. struct nouveau_drm *drm = nouveau_newpriv(dev);
  31. nv_wo32(drm->device, reg, val);
  32. }
  33. u32
  34. _nv_mask(struct drm_device *dev, u32 reg, u32 mask, u32 val)
  35. {
  36. u32 tmp = _nv_rd32(dev, reg);
  37. _nv_wr32(dev, reg, (tmp & ~mask) | val);
  38. return tmp;
  39. }
  40. bool
  41. _nv_bios(struct drm_device *dev, u8 **data, u32 *size)
  42. {
  43. struct nouveau_drm *drm = nouveau_newpriv(dev);
  44. struct nouveau_bios *bios = nouveau_bios(drm->device);
  45. *data = bios->data;
  46. *size = bios->size;
  47. return true;
  48. }
  49. void
  50. nouveau_gpio_reset(struct drm_device *dev)
  51. {
  52. struct nouveau_drm *drm = nouveau_newpriv(dev);
  53. struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
  54. gpio->reset(gpio);
  55. }
  56. int
  57. nouveau_gpio_find(struct drm_device *dev, int idx, u8 tag, u8 line,
  58. struct dcb_gpio_func *func)
  59. {
  60. struct nouveau_drm *drm = nouveau_newpriv(dev);
  61. struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
  62. return gpio->find(gpio, idx, tag, line, func);
  63. }
  64. bool
  65. nouveau_gpio_func_valid(struct drm_device *dev, u8 tag)
  66. {
  67. struct nouveau_drm *drm = nouveau_newpriv(dev);
  68. struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
  69. struct dcb_gpio_func func;
  70. return gpio->find(gpio, 0, tag, 0xff, &func) == 0;
  71. }
  72. int
  73. nouveau_gpio_func_set(struct drm_device *dev, u8 tag, int state)
  74. {
  75. struct nouveau_drm *drm = nouveau_newpriv(dev);
  76. struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
  77. if (gpio && gpio->get)
  78. return gpio->set(gpio, 0, tag, 0xff, state);
  79. return -ENODEV;
  80. }
  81. int
  82. nouveau_gpio_func_get(struct drm_device *dev, u8 tag)
  83. {
  84. struct nouveau_drm *drm = nouveau_newpriv(dev);
  85. struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
  86. if (gpio && gpio->get)
  87. return gpio->get(gpio, 0, tag, 0xff);
  88. return -ENODEV;
  89. }
  90. int
  91. nouveau_gpio_irq(struct drm_device *dev, int idx, u8 tag, u8 line, bool on)
  92. {
  93. struct nouveau_drm *drm = nouveau_newpriv(dev);
  94. struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
  95. if (gpio && gpio->irq)
  96. return gpio->irq(gpio, idx, tag, line, on);
  97. return -ENODEV;
  98. }
  99. int
  100. nouveau_gpio_isr_add(struct drm_device *dev, int idx, u8 tag, u8 line,
  101. void (*exec)(void *, int state), void *data)
  102. {
  103. struct nouveau_drm *drm = nouveau_newpriv(dev);
  104. struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
  105. if (gpio && gpio->isr_add)
  106. return gpio->isr_add(gpio, idx, tag, line, exec, data);
  107. return -ENODEV;
  108. }
  109. void
  110. nouveau_gpio_isr_del(struct drm_device *dev, int idx, u8 tag, u8 line,
  111. void (*exec)(void *, int state), void *data)
  112. {
  113. struct nouveau_drm *drm = nouveau_newpriv(dev);
  114. struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
  115. if (gpio && gpio->isr_del)
  116. gpio->isr_del(gpio, idx, tag, line, exec, data);
  117. }
  118. struct nouveau_i2c_port *
  119. nouveau_i2c_find(struct drm_device *dev, u8 index)
  120. {
  121. struct nouveau_drm *drm = nouveau_newpriv(dev);
  122. struct nouveau_i2c *i2c = nouveau_i2c(drm->device);
  123. return i2c->find(i2c, index);
  124. }
  125. bool
  126. nouveau_probe_i2c_addr(struct nouveau_i2c_port *port, int addr)
  127. {
  128. return nv_probe_i2c(port, addr);
  129. }
  130. struct i2c_adapter *
  131. nouveau_i2c_adapter(struct nouveau_i2c_port *port)
  132. {
  133. return &port->adapter;
  134. }
  135. int
  136. nouveau_i2c_identify(struct drm_device *dev, const char *what,
  137. struct i2c_board_info *info,
  138. bool (*match)(struct nouveau_i2c_port *,
  139. struct i2c_board_info *),
  140. int index)
  141. {
  142. struct nouveau_drm *drm = nouveau_newpriv(dev);
  143. struct nouveau_i2c *i2c = nouveau_i2c(drm->device);
  144. return i2c->identify(i2c, index, what, info, match);
  145. }
  146. int
  147. auxch_rd(struct drm_device *dev, struct nouveau_i2c_port *port,
  148. u32 addr, u8 *data, u8 size)
  149. {
  150. return nv_rdaux(port, addr, data, size);
  151. }
  152. int
  153. auxch_wr(struct drm_device *dev, struct nouveau_i2c_port *port,
  154. u32 addr, u8 *data, u8 size)
  155. {
  156. return nv_wraux(port, addr, data, size);
  157. }
  158. u32
  159. get_pll_register(struct drm_device *dev, u32 type)
  160. {
  161. struct nouveau_drm *drm = nouveau_newpriv(dev);
  162. struct nouveau_bios *bios = nouveau_bios(drm->device);
  163. struct nvbios_pll info;
  164. if (nvbios_pll_parse(bios, type, &info))
  165. return 0;
  166. return info.reg;
  167. }
  168. int
  169. get_pll_limits(struct drm_device *dev, u32 type, struct nvbios_pll *info)
  170. {
  171. struct nouveau_drm *drm = nouveau_newpriv(dev);
  172. struct nouveau_bios *bios = nouveau_bios(drm->device);
  173. return nvbios_pll_parse(bios, type, info);
  174. }
  175. int
  176. setPLL(struct drm_device *dev, u32 reg, u32 freq)
  177. {
  178. struct nouveau_drm *drm = nouveau_newpriv(dev);
  179. struct nouveau_clock *clk = nouveau_clock(drm->device);
  180. int ret = -ENODEV;
  181. if (clk->pll_set)
  182. ret = clk->pll_set(clk, reg, freq);
  183. return ret;
  184. }
  185. int
  186. nouveau_calc_pll_mnp(struct drm_device *dev, struct nvbios_pll *info,
  187. int freq, struct nouveau_pll_vals *pv)
  188. {
  189. struct nouveau_drm *drm = nouveau_newpriv(dev);
  190. struct nouveau_clock *clk = nouveau_clock(drm->device);
  191. int ret = 0;
  192. if (clk->pll_calc)
  193. ret = clk->pll_calc(clk, info, freq, pv);
  194. return ret;
  195. }
  196. int
  197. nouveau_hw_setpll(struct drm_device *dev, u32 reg1,
  198. struct nouveau_pll_vals *pv)
  199. {
  200. struct nouveau_drm *drm = nouveau_newpriv(dev);
  201. struct nouveau_clock *clk = nouveau_clock(drm->device);
  202. int ret = -ENODEV;
  203. if (clk->pll_prog)
  204. ret = clk->pll_prog(clk, reg1, pv);
  205. return ret;
  206. }
  207. int nva3_pll_calc(struct nouveau_clock *, struct nvbios_pll *, u32 freq,
  208. int *N, int *fN, int *M, int *P);
  209. int
  210. nva3_calc_pll(struct drm_device *dev, struct nvbios_pll *info, u32 freq,
  211. int *N, int *fN, int *M, int *P)
  212. {
  213. struct nouveau_drm *drm = nouveau_newpriv(dev);
  214. struct nouveau_clock *clk = nouveau_clock(drm->device);
  215. return nva3_pll_calc(clk, info, freq, N, fN, M, P);
  216. }