nouveau_compat.c 6.8 KB

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