nouveau_compat.c 7.9 KB

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