nv50_display.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  1. /*
  2. * Copyright (C) 2008 Maarten Maathuis.
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * The above copyright notice and this permission notice (including the
  14. * next paragraph) shall be included in all copies or substantial
  15. * portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  20. * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
  21. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. *
  25. */
  26. #include "nv50_display.h"
  27. #include "nouveau_crtc.h"
  28. #include "nouveau_encoder.h"
  29. #include "nouveau_connector.h"
  30. #include "nouveau_fb.h"
  31. #include "nouveau_fbcon.h"
  32. #include "nouveau_ramht.h"
  33. #include "drm_crtc_helper.h"
  34. static void nv50_display_isr(struct drm_device *);
  35. static inline int
  36. nv50_sor_nr(struct drm_device *dev)
  37. {
  38. struct drm_nouveau_private *dev_priv = dev->dev_private;
  39. if (dev_priv->chipset < 0x90 ||
  40. dev_priv->chipset == 0x92 ||
  41. dev_priv->chipset == 0xa0)
  42. return 2;
  43. return 4;
  44. }
  45. int
  46. nv50_display_early_init(struct drm_device *dev)
  47. {
  48. return 0;
  49. }
  50. void
  51. nv50_display_late_takedown(struct drm_device *dev)
  52. {
  53. }
  54. int
  55. nv50_display_init(struct drm_device *dev)
  56. {
  57. struct drm_nouveau_private *dev_priv = dev->dev_private;
  58. struct nouveau_gpio_engine *pgpio = &dev_priv->engine.gpio;
  59. struct drm_connector *connector;
  60. struct nouveau_channel *evo;
  61. int ret, i;
  62. u32 val;
  63. NV_DEBUG_KMS(dev, "\n");
  64. nv_wr32(dev, 0x00610184, nv_rd32(dev, 0x00614004));
  65. /*
  66. * I think the 0x006101XX range is some kind of main control area
  67. * that enables things.
  68. */
  69. /* CRTC? */
  70. for (i = 0; i < 2; i++) {
  71. val = nv_rd32(dev, 0x00616100 + (i * 0x800));
  72. nv_wr32(dev, 0x00610190 + (i * 0x10), val);
  73. val = nv_rd32(dev, 0x00616104 + (i * 0x800));
  74. nv_wr32(dev, 0x00610194 + (i * 0x10), val);
  75. val = nv_rd32(dev, 0x00616108 + (i * 0x800));
  76. nv_wr32(dev, 0x00610198 + (i * 0x10), val);
  77. val = nv_rd32(dev, 0x0061610c + (i * 0x800));
  78. nv_wr32(dev, 0x0061019c + (i * 0x10), val);
  79. }
  80. /* DAC */
  81. for (i = 0; i < 3; i++) {
  82. val = nv_rd32(dev, 0x0061a000 + (i * 0x800));
  83. nv_wr32(dev, 0x006101d0 + (i * 0x04), val);
  84. }
  85. /* SOR */
  86. for (i = 0; i < nv50_sor_nr(dev); i++) {
  87. val = nv_rd32(dev, 0x0061c000 + (i * 0x800));
  88. nv_wr32(dev, 0x006101e0 + (i * 0x04), val);
  89. }
  90. /* EXT */
  91. for (i = 0; i < 3; i++) {
  92. val = nv_rd32(dev, 0x0061e000 + (i * 0x800));
  93. nv_wr32(dev, 0x006101f0 + (i * 0x04), val);
  94. }
  95. for (i = 0; i < 3; i++) {
  96. nv_wr32(dev, NV50_PDISPLAY_DAC_DPMS_CTRL(i), 0x00550000 |
  97. NV50_PDISPLAY_DAC_DPMS_CTRL_PENDING);
  98. nv_wr32(dev, NV50_PDISPLAY_DAC_CLK_CTRL1(i), 0x00000001);
  99. }
  100. /* The precise purpose is unknown, i suspect it has something to do
  101. * with text mode.
  102. */
  103. if (nv_rd32(dev, NV50_PDISPLAY_INTR_1) & 0x100) {
  104. nv_wr32(dev, NV50_PDISPLAY_INTR_1, 0x100);
  105. nv_wr32(dev, 0x006194e8, nv_rd32(dev, 0x006194e8) & ~1);
  106. if (!nv_wait(dev, 0x006194e8, 2, 0)) {
  107. NV_ERROR(dev, "timeout: (0x6194e8 & 2) != 0\n");
  108. NV_ERROR(dev, "0x6194e8 = 0x%08x\n",
  109. nv_rd32(dev, 0x6194e8));
  110. return -EBUSY;
  111. }
  112. }
  113. for (i = 0; i < 2; i++) {
  114. nv_wr32(dev, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i), 0x2000);
  115. if (!nv_wait(dev, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i),
  116. NV50_PDISPLAY_CURSOR_CURSOR_CTRL2_STATUS, 0)) {
  117. NV_ERROR(dev, "timeout: CURSOR_CTRL2_STATUS == 0\n");
  118. NV_ERROR(dev, "CURSOR_CTRL2 = 0x%08x\n",
  119. nv_rd32(dev, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i)));
  120. return -EBUSY;
  121. }
  122. nv_wr32(dev, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i),
  123. NV50_PDISPLAY_CURSOR_CURSOR_CTRL2_ON);
  124. if (!nv_wait(dev, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i),
  125. NV50_PDISPLAY_CURSOR_CURSOR_CTRL2_STATUS,
  126. NV50_PDISPLAY_CURSOR_CURSOR_CTRL2_STATUS_ACTIVE)) {
  127. NV_ERROR(dev, "timeout: "
  128. "CURSOR_CTRL2_STATUS_ACTIVE(%d)\n", i);
  129. NV_ERROR(dev, "CURSOR_CTRL2(%d) = 0x%08x\n", i,
  130. nv_rd32(dev, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i)));
  131. return -EBUSY;
  132. }
  133. }
  134. nv_wr32(dev, NV50_PDISPLAY_PIO_CTRL, 0x00000000);
  135. nv_mask(dev, NV50_PDISPLAY_INTR_0, 0x00000000, 0x00000000);
  136. nv_wr32(dev, NV50_PDISPLAY_INTR_EN_0, 0x00000000);
  137. nv_mask(dev, NV50_PDISPLAY_INTR_1, 0x00000000, 0x00000000);
  138. nv_wr32(dev, NV50_PDISPLAY_INTR_EN_1,
  139. NV50_PDISPLAY_INTR_EN_1_CLK_UNK10 |
  140. NV50_PDISPLAY_INTR_EN_1_CLK_UNK20 |
  141. NV50_PDISPLAY_INTR_EN_1_CLK_UNK40);
  142. /* enable hotplug interrupts */
  143. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  144. struct nouveau_connector *conn = nouveau_connector(connector);
  145. if (conn->dcb->gpio_tag == 0xff)
  146. continue;
  147. pgpio->irq_enable(dev, conn->dcb->gpio_tag, true);
  148. }
  149. ret = nv50_evo_init(dev);
  150. if (ret)
  151. return ret;
  152. evo = nv50_display(dev)->master;
  153. nv_wr32(dev, NV50_PDISPLAY_OBJECTS, (evo->ramin->vinst >> 8) | 9);
  154. ret = RING_SPACE(evo, 11);
  155. if (ret)
  156. return ret;
  157. BEGIN_RING(evo, 0, NV50_EVO_UNK84, 2);
  158. OUT_RING(evo, NV50_EVO_UNK84_NOTIFY_DISABLED);
  159. OUT_RING(evo, NV50_EVO_DMA_NOTIFY_HANDLE_NONE);
  160. BEGIN_RING(evo, 0, NV50_EVO_CRTC(0, FB_DMA), 1);
  161. OUT_RING(evo, NV50_EVO_CRTC_FB_DMA_HANDLE_NONE);
  162. BEGIN_RING(evo, 0, NV50_EVO_CRTC(0, UNK0800), 1);
  163. OUT_RING(evo, 0);
  164. BEGIN_RING(evo, 0, NV50_EVO_CRTC(0, DISPLAY_START), 1);
  165. OUT_RING(evo, 0);
  166. BEGIN_RING(evo, 0, NV50_EVO_CRTC(0, UNK082C), 1);
  167. OUT_RING(evo, 0);
  168. FIRE_RING(evo);
  169. if (!nv_wait(dev, 0x640004, 0xffffffff, evo->dma.put << 2))
  170. NV_ERROR(dev, "evo pushbuf stalled\n");
  171. return 0;
  172. }
  173. static int nv50_display_disable(struct drm_device *dev)
  174. {
  175. struct drm_nouveau_private *dev_priv = dev->dev_private;
  176. struct nv50_display *disp = nv50_display(dev);
  177. struct nouveau_channel *evo = disp->master;
  178. struct drm_crtc *drm_crtc;
  179. int ret, i;
  180. NV_DEBUG_KMS(dev, "\n");
  181. list_for_each_entry(drm_crtc, &dev->mode_config.crtc_list, head) {
  182. struct nouveau_crtc *crtc = nouveau_crtc(drm_crtc);
  183. nv50_crtc_blank(crtc, true);
  184. }
  185. ret = RING_SPACE(evo, 2);
  186. if (ret == 0) {
  187. BEGIN_RING(evo, 0, NV50_EVO_UPDATE, 1);
  188. OUT_RING(evo, 0);
  189. }
  190. FIRE_RING(evo);
  191. /* Almost like ack'ing a vblank interrupt, maybe in the spirit of
  192. * cleaning up?
  193. */
  194. list_for_each_entry(drm_crtc, &dev->mode_config.crtc_list, head) {
  195. struct nouveau_crtc *crtc = nouveau_crtc(drm_crtc);
  196. uint32_t mask = NV50_PDISPLAY_INTR_1_VBLANK_CRTC_(crtc->index);
  197. if (!crtc->base.enabled)
  198. continue;
  199. nv_wr32(dev, NV50_PDISPLAY_INTR_1, mask);
  200. if (!nv_wait(dev, NV50_PDISPLAY_INTR_1, mask, mask)) {
  201. NV_ERROR(dev, "timeout: (0x610024 & 0x%08x) == "
  202. "0x%08x\n", mask, mask);
  203. NV_ERROR(dev, "0x610024 = 0x%08x\n",
  204. nv_rd32(dev, NV50_PDISPLAY_INTR_1));
  205. }
  206. }
  207. nv50_evo_fini(dev);
  208. for (i = 0; i < 3; i++) {
  209. if (!nv_wait(dev, NV50_PDISPLAY_SOR_DPMS_STATE(i),
  210. NV50_PDISPLAY_SOR_DPMS_STATE_WAIT, 0)) {
  211. NV_ERROR(dev, "timeout: SOR_DPMS_STATE_WAIT(%d) == 0\n", i);
  212. NV_ERROR(dev, "SOR_DPMS_STATE(%d) = 0x%08x\n", i,
  213. nv_rd32(dev, NV50_PDISPLAY_SOR_DPMS_STATE(i)));
  214. }
  215. }
  216. /* disable interrupts. */
  217. nv_wr32(dev, NV50_PDISPLAY_INTR_EN_1, 0x00000000);
  218. /* disable hotplug interrupts */
  219. nv_wr32(dev, 0xe054, 0xffffffff);
  220. nv_wr32(dev, 0xe050, 0x00000000);
  221. if (dev_priv->chipset >= 0x90) {
  222. nv_wr32(dev, 0xe074, 0xffffffff);
  223. nv_wr32(dev, 0xe070, 0x00000000);
  224. }
  225. return 0;
  226. }
  227. int nv50_display_create(struct drm_device *dev)
  228. {
  229. struct drm_nouveau_private *dev_priv = dev->dev_private;
  230. struct dcb_table *dcb = &dev_priv->vbios.dcb;
  231. struct drm_connector *connector, *ct;
  232. struct nv50_display *priv;
  233. int ret, i;
  234. NV_DEBUG_KMS(dev, "\n");
  235. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  236. if (!priv)
  237. return -ENOMEM;
  238. dev_priv->engine.display.priv = priv;
  239. /* init basic kernel modesetting */
  240. drm_mode_config_init(dev);
  241. /* Initialise some optional connector properties. */
  242. drm_mode_create_scaling_mode_property(dev);
  243. drm_mode_create_dithering_property(dev);
  244. dev->mode_config.min_width = 0;
  245. dev->mode_config.min_height = 0;
  246. dev->mode_config.funcs = (void *)&nouveau_mode_config_funcs;
  247. dev->mode_config.max_width = 8192;
  248. dev->mode_config.max_height = 8192;
  249. dev->mode_config.fb_base = dev_priv->fb_phys;
  250. /* Create CRTC objects */
  251. for (i = 0; i < 2; i++)
  252. nv50_crtc_create(dev, i);
  253. /* We setup the encoders from the BIOS table */
  254. for (i = 0 ; i < dcb->entries; i++) {
  255. struct dcb_entry *entry = &dcb->entry[i];
  256. if (entry->location != DCB_LOC_ON_CHIP) {
  257. NV_WARN(dev, "Off-chip encoder %d/%d unsupported\n",
  258. entry->type, ffs(entry->or) - 1);
  259. continue;
  260. }
  261. connector = nouveau_connector_create(dev, entry->connector);
  262. if (IS_ERR(connector))
  263. continue;
  264. switch (entry->type) {
  265. case OUTPUT_TMDS:
  266. case OUTPUT_LVDS:
  267. case OUTPUT_DP:
  268. nv50_sor_create(connector, entry);
  269. break;
  270. case OUTPUT_ANALOG:
  271. nv50_dac_create(connector, entry);
  272. break;
  273. default:
  274. NV_WARN(dev, "DCB encoder %d unknown\n", entry->type);
  275. continue;
  276. }
  277. }
  278. list_for_each_entry_safe(connector, ct,
  279. &dev->mode_config.connector_list, head) {
  280. if (!connector->encoder_ids[0]) {
  281. NV_WARN(dev, "%s has no encoders, removing\n",
  282. drm_get_connector_name(connector));
  283. connector->funcs->destroy(connector);
  284. }
  285. }
  286. INIT_WORK(&dev_priv->irq_work, nv50_display_irq_handler_bh);
  287. nouveau_irq_register(dev, 26, nv50_display_isr);
  288. ret = nv50_display_init(dev);
  289. if (ret) {
  290. nv50_display_destroy(dev);
  291. return ret;
  292. }
  293. return 0;
  294. }
  295. void
  296. nv50_display_destroy(struct drm_device *dev)
  297. {
  298. struct drm_nouveau_private *dev_priv = dev->dev_private;
  299. struct nv50_display *disp = nv50_display(dev);
  300. NV_DEBUG_KMS(dev, "\n");
  301. drm_mode_config_cleanup(dev);
  302. nv50_display_disable(dev);
  303. nouveau_irq_unregister(dev, 26);
  304. flush_work_sync(&dev_priv->irq_work);
  305. kfree(disp);
  306. }
  307. static u16
  308. nv50_display_script_select(struct drm_device *dev, struct dcb_entry *dcb,
  309. u32 mc, int pxclk)
  310. {
  311. struct drm_nouveau_private *dev_priv = dev->dev_private;
  312. struct nouveau_connector *nv_connector = NULL;
  313. struct drm_encoder *encoder;
  314. struct nvbios *bios = &dev_priv->vbios;
  315. u32 script = 0, or;
  316. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  317. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  318. if (nv_encoder->dcb != dcb)
  319. continue;
  320. nv_connector = nouveau_encoder_connector_get(nv_encoder);
  321. break;
  322. }
  323. or = ffs(dcb->or) - 1;
  324. switch (dcb->type) {
  325. case OUTPUT_LVDS:
  326. script = (mc >> 8) & 0xf;
  327. if (bios->fp_no_ddc) {
  328. if (bios->fp.dual_link)
  329. script |= 0x0100;
  330. if (bios->fp.if_is_24bit)
  331. script |= 0x0200;
  332. } else {
  333. if (pxclk >= bios->fp.duallink_transition_clk) {
  334. script |= 0x0100;
  335. if (bios->fp.strapless_is_24bit & 2)
  336. script |= 0x0200;
  337. } else
  338. if (bios->fp.strapless_is_24bit & 1)
  339. script |= 0x0200;
  340. if (nv_connector && nv_connector->edid &&
  341. (nv_connector->edid->revision >= 4) &&
  342. (nv_connector->edid->input & 0x70) >= 0x20)
  343. script |= 0x0200;
  344. }
  345. if (nouveau_uscript_lvds >= 0) {
  346. NV_INFO(dev, "override script 0x%04x with 0x%04x "
  347. "for output LVDS-%d\n", script,
  348. nouveau_uscript_lvds, or);
  349. script = nouveau_uscript_lvds;
  350. }
  351. break;
  352. case OUTPUT_TMDS:
  353. script = (mc >> 8) & 0xf;
  354. if (pxclk >= 165000)
  355. script |= 0x0100;
  356. if (nouveau_uscript_tmds >= 0) {
  357. NV_INFO(dev, "override script 0x%04x with 0x%04x "
  358. "for output TMDS-%d\n", script,
  359. nouveau_uscript_tmds, or);
  360. script = nouveau_uscript_tmds;
  361. }
  362. break;
  363. case OUTPUT_DP:
  364. script = (mc >> 8) & 0xf;
  365. break;
  366. case OUTPUT_ANALOG:
  367. script = 0xff;
  368. break;
  369. default:
  370. NV_ERROR(dev, "modeset on unsupported output type!\n");
  371. break;
  372. }
  373. return script;
  374. }
  375. static void
  376. nv50_display_vblank_crtc_handler(struct drm_device *dev, int crtc)
  377. {
  378. struct drm_nouveau_private *dev_priv = dev->dev_private;
  379. struct nouveau_channel *chan, *tmp;
  380. list_for_each_entry_safe(chan, tmp, &dev_priv->vbl_waiting,
  381. nvsw.vbl_wait) {
  382. if (chan->nvsw.vblsem_head != crtc)
  383. continue;
  384. nouveau_bo_wr32(chan->notifier_bo, chan->nvsw.vblsem_offset,
  385. chan->nvsw.vblsem_rval);
  386. list_del(&chan->nvsw.vbl_wait);
  387. drm_vblank_put(dev, crtc);
  388. }
  389. drm_handle_vblank(dev, crtc);
  390. }
  391. static void
  392. nv50_display_vblank_handler(struct drm_device *dev, uint32_t intr)
  393. {
  394. if (intr & NV50_PDISPLAY_INTR_1_VBLANK_CRTC_0)
  395. nv50_display_vblank_crtc_handler(dev, 0);
  396. if (intr & NV50_PDISPLAY_INTR_1_VBLANK_CRTC_1)
  397. nv50_display_vblank_crtc_handler(dev, 1);
  398. nv_wr32(dev, NV50_PDISPLAY_INTR_1, NV50_PDISPLAY_INTR_1_VBLANK_CRTC);
  399. }
  400. static void
  401. nv50_display_unk10_handler(struct drm_device *dev)
  402. {
  403. struct drm_nouveau_private *dev_priv = dev->dev_private;
  404. struct nv50_display *disp = nv50_display(dev);
  405. u32 unk30 = nv_rd32(dev, 0x610030), mc;
  406. int i, crtc, or, type = OUTPUT_ANY;
  407. NV_DEBUG_KMS(dev, "0x610030: 0x%08x\n", unk30);
  408. disp->irq.dcb = NULL;
  409. nv_wr32(dev, 0x619494, nv_rd32(dev, 0x619494) & ~8);
  410. /* Determine which CRTC we're dealing with, only 1 ever will be
  411. * signalled at the same time with the current nouveau code.
  412. */
  413. crtc = ffs((unk30 & 0x00000060) >> 5) - 1;
  414. if (crtc < 0)
  415. goto ack;
  416. /* Nothing needs to be done for the encoder */
  417. crtc = ffs((unk30 & 0x00000180) >> 7) - 1;
  418. if (crtc < 0)
  419. goto ack;
  420. /* Find which encoder was connected to the CRTC */
  421. for (i = 0; type == OUTPUT_ANY && i < 3; i++) {
  422. mc = nv_rd32(dev, NV50_PDISPLAY_DAC_MODE_CTRL_C(i));
  423. NV_DEBUG_KMS(dev, "DAC-%d mc: 0x%08x\n", i, mc);
  424. if (!(mc & (1 << crtc)))
  425. continue;
  426. switch ((mc & 0x00000f00) >> 8) {
  427. case 0: type = OUTPUT_ANALOG; break;
  428. case 1: type = OUTPUT_TV; break;
  429. default:
  430. NV_ERROR(dev, "invalid mc, DAC-%d: 0x%08x\n", i, mc);
  431. goto ack;
  432. }
  433. or = i;
  434. }
  435. for (i = 0; type == OUTPUT_ANY && i < nv50_sor_nr(dev); i++) {
  436. if (dev_priv->chipset < 0x90 ||
  437. dev_priv->chipset == 0x92 ||
  438. dev_priv->chipset == 0xa0)
  439. mc = nv_rd32(dev, NV50_PDISPLAY_SOR_MODE_CTRL_C(i));
  440. else
  441. mc = nv_rd32(dev, NV90_PDISPLAY_SOR_MODE_CTRL_C(i));
  442. NV_DEBUG_KMS(dev, "SOR-%d mc: 0x%08x\n", i, mc);
  443. if (!(mc & (1 << crtc)))
  444. continue;
  445. switch ((mc & 0x00000f00) >> 8) {
  446. case 0: type = OUTPUT_LVDS; break;
  447. case 1: type = OUTPUT_TMDS; break;
  448. case 2: type = OUTPUT_TMDS; break;
  449. case 5: type = OUTPUT_TMDS; break;
  450. case 8: type = OUTPUT_DP; break;
  451. case 9: type = OUTPUT_DP; break;
  452. default:
  453. NV_ERROR(dev, "invalid mc, SOR-%d: 0x%08x\n", i, mc);
  454. goto ack;
  455. }
  456. or = i;
  457. }
  458. /* There was no encoder to disable */
  459. if (type == OUTPUT_ANY)
  460. goto ack;
  461. /* Disable the encoder */
  462. for (i = 0; i < dev_priv->vbios.dcb.entries; i++) {
  463. struct dcb_entry *dcb = &dev_priv->vbios.dcb.entry[i];
  464. if (dcb->type == type && (dcb->or & (1 << or))) {
  465. nouveau_bios_run_display_table(dev, dcb, 0, -1);
  466. disp->irq.dcb = dcb;
  467. goto ack;
  468. }
  469. }
  470. NV_ERROR(dev, "no dcb for %d %d 0x%08x\n", or, type, mc);
  471. ack:
  472. nv_wr32(dev, NV50_PDISPLAY_INTR_1, NV50_PDISPLAY_INTR_1_CLK_UNK10);
  473. nv_wr32(dev, 0x610030, 0x80000000);
  474. }
  475. static void
  476. nv50_display_unk20_dp_hack(struct drm_device *dev, struct dcb_entry *dcb)
  477. {
  478. int or = ffs(dcb->or) - 1, link = !(dcb->dpconf.sor.link & 1);
  479. struct drm_encoder *encoder;
  480. uint32_t tmp, unk0 = 0, unk1 = 0;
  481. if (dcb->type != OUTPUT_DP)
  482. return;
  483. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  484. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  485. if (nv_encoder->dcb == dcb) {
  486. unk0 = nv_encoder->dp.unk0;
  487. unk1 = nv_encoder->dp.unk1;
  488. break;
  489. }
  490. }
  491. if (unk0 || unk1) {
  492. tmp = nv_rd32(dev, NV50_SOR_DP_CTRL(or, link));
  493. tmp &= 0xfffffe03;
  494. nv_wr32(dev, NV50_SOR_DP_CTRL(or, link), tmp | unk0);
  495. tmp = nv_rd32(dev, NV50_SOR_DP_UNK128(or, link));
  496. tmp &= 0xfef080c0;
  497. nv_wr32(dev, NV50_SOR_DP_UNK128(or, link), tmp | unk1);
  498. }
  499. }
  500. static void
  501. nv50_display_unk20_handler(struct drm_device *dev)
  502. {
  503. struct drm_nouveau_private *dev_priv = dev->dev_private;
  504. struct nv50_display *disp = nv50_display(dev);
  505. u32 unk30 = nv_rd32(dev, 0x610030), tmp, pclk, script, mc = 0;
  506. struct dcb_entry *dcb;
  507. int i, crtc, or, type = OUTPUT_ANY;
  508. NV_DEBUG_KMS(dev, "0x610030: 0x%08x\n", unk30);
  509. dcb = disp->irq.dcb;
  510. if (dcb) {
  511. nouveau_bios_run_display_table(dev, dcb, 0, -2);
  512. disp->irq.dcb = NULL;
  513. }
  514. /* CRTC clock change requested? */
  515. crtc = ffs((unk30 & 0x00000600) >> 9) - 1;
  516. if (crtc >= 0) {
  517. pclk = nv_rd32(dev, NV50_PDISPLAY_CRTC_P(crtc, CLOCK));
  518. pclk &= 0x003fffff;
  519. nv50_crtc_set_clock(dev, crtc, pclk);
  520. tmp = nv_rd32(dev, NV50_PDISPLAY_CRTC_CLK_CTRL2(crtc));
  521. tmp &= ~0x000000f;
  522. nv_wr32(dev, NV50_PDISPLAY_CRTC_CLK_CTRL2(crtc), tmp);
  523. }
  524. /* Nothing needs to be done for the encoder */
  525. crtc = ffs((unk30 & 0x00000180) >> 7) - 1;
  526. if (crtc < 0)
  527. goto ack;
  528. pclk = nv_rd32(dev, NV50_PDISPLAY_CRTC_P(crtc, CLOCK)) & 0x003fffff;
  529. /* Find which encoder is connected to the CRTC */
  530. for (i = 0; type == OUTPUT_ANY && i < 3; i++) {
  531. mc = nv_rd32(dev, NV50_PDISPLAY_DAC_MODE_CTRL_P(i));
  532. NV_DEBUG_KMS(dev, "DAC-%d mc: 0x%08x\n", i, mc);
  533. if (!(mc & (1 << crtc)))
  534. continue;
  535. switch ((mc & 0x00000f00) >> 8) {
  536. case 0: type = OUTPUT_ANALOG; break;
  537. case 1: type = OUTPUT_TV; break;
  538. default:
  539. NV_ERROR(dev, "invalid mc, DAC-%d: 0x%08x\n", i, mc);
  540. goto ack;
  541. }
  542. or = i;
  543. }
  544. for (i = 0; type == OUTPUT_ANY && i < nv50_sor_nr(dev); i++) {
  545. if (dev_priv->chipset < 0x90 ||
  546. dev_priv->chipset == 0x92 ||
  547. dev_priv->chipset == 0xa0)
  548. mc = nv_rd32(dev, NV50_PDISPLAY_SOR_MODE_CTRL_P(i));
  549. else
  550. mc = nv_rd32(dev, NV90_PDISPLAY_SOR_MODE_CTRL_P(i));
  551. NV_DEBUG_KMS(dev, "SOR-%d mc: 0x%08x\n", i, mc);
  552. if (!(mc & (1 << crtc)))
  553. continue;
  554. switch ((mc & 0x00000f00) >> 8) {
  555. case 0: type = OUTPUT_LVDS; break;
  556. case 1: type = OUTPUT_TMDS; break;
  557. case 2: type = OUTPUT_TMDS; break;
  558. case 5: type = OUTPUT_TMDS; break;
  559. case 8: type = OUTPUT_DP; break;
  560. case 9: type = OUTPUT_DP; break;
  561. default:
  562. NV_ERROR(dev, "invalid mc, SOR-%d: 0x%08x\n", i, mc);
  563. goto ack;
  564. }
  565. or = i;
  566. }
  567. if (type == OUTPUT_ANY)
  568. goto ack;
  569. /* Enable the encoder */
  570. for (i = 0; i < dev_priv->vbios.dcb.entries; i++) {
  571. dcb = &dev_priv->vbios.dcb.entry[i];
  572. if (dcb->type == type && (dcb->or & (1 << or)))
  573. break;
  574. }
  575. if (i == dev_priv->vbios.dcb.entries) {
  576. NV_ERROR(dev, "no dcb for %d %d 0x%08x\n", or, type, mc);
  577. goto ack;
  578. }
  579. script = nv50_display_script_select(dev, dcb, mc, pclk);
  580. nouveau_bios_run_display_table(dev, dcb, script, pclk);
  581. nv50_display_unk20_dp_hack(dev, dcb);
  582. if (dcb->type != OUTPUT_ANALOG) {
  583. tmp = nv_rd32(dev, NV50_PDISPLAY_SOR_CLK_CTRL2(or));
  584. tmp &= ~0x00000f0f;
  585. if (script & 0x0100)
  586. tmp |= 0x00000101;
  587. nv_wr32(dev, NV50_PDISPLAY_SOR_CLK_CTRL2(or), tmp);
  588. } else {
  589. nv_wr32(dev, NV50_PDISPLAY_DAC_CLK_CTRL2(or), 0);
  590. }
  591. disp->irq.dcb = dcb;
  592. disp->irq.pclk = pclk;
  593. disp->irq.script = script;
  594. ack:
  595. nv_wr32(dev, NV50_PDISPLAY_INTR_1, NV50_PDISPLAY_INTR_1_CLK_UNK20);
  596. nv_wr32(dev, 0x610030, 0x80000000);
  597. }
  598. /* If programming a TMDS output on a SOR that can also be configured for
  599. * DisplayPort, make sure NV50_SOR_DP_CTRL_ENABLE is forced off.
  600. *
  601. * It looks like the VBIOS TMDS scripts make an attempt at this, however,
  602. * the VBIOS scripts on at least one board I have only switch it off on
  603. * link 0, causing a blank display if the output has previously been
  604. * programmed for DisplayPort.
  605. */
  606. static void
  607. nv50_display_unk40_dp_set_tmds(struct drm_device *dev, struct dcb_entry *dcb)
  608. {
  609. int or = ffs(dcb->or) - 1, link = !(dcb->dpconf.sor.link & 1);
  610. struct drm_encoder *encoder;
  611. u32 tmp;
  612. if (dcb->type != OUTPUT_TMDS)
  613. return;
  614. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  615. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  616. if (nv_encoder->dcb->type == OUTPUT_DP &&
  617. nv_encoder->dcb->or & (1 << or)) {
  618. tmp = nv_rd32(dev, NV50_SOR_DP_CTRL(or, link));
  619. tmp &= ~NV50_SOR_DP_CTRL_ENABLED;
  620. nv_wr32(dev, NV50_SOR_DP_CTRL(or, link), tmp);
  621. break;
  622. }
  623. }
  624. }
  625. static void
  626. nv50_display_unk40_handler(struct drm_device *dev)
  627. {
  628. struct nv50_display *disp = nv50_display(dev);
  629. struct dcb_entry *dcb = disp->irq.dcb;
  630. u16 script = disp->irq.script;
  631. u32 unk30 = nv_rd32(dev, 0x610030), pclk = disp->irq.pclk;
  632. NV_DEBUG_KMS(dev, "0x610030: 0x%08x\n", unk30);
  633. disp->irq.dcb = NULL;
  634. if (!dcb)
  635. goto ack;
  636. nouveau_bios_run_display_table(dev, dcb, script, -pclk);
  637. nv50_display_unk40_dp_set_tmds(dev, dcb);
  638. ack:
  639. nv_wr32(dev, NV50_PDISPLAY_INTR_1, NV50_PDISPLAY_INTR_1_CLK_UNK40);
  640. nv_wr32(dev, 0x610030, 0x80000000);
  641. nv_wr32(dev, 0x619494, nv_rd32(dev, 0x619494) | 8);
  642. }
  643. void
  644. nv50_display_irq_handler_bh(struct work_struct *work)
  645. {
  646. struct drm_nouveau_private *dev_priv =
  647. container_of(work, struct drm_nouveau_private, irq_work);
  648. struct drm_device *dev = dev_priv->dev;
  649. for (;;) {
  650. uint32_t intr0 = nv_rd32(dev, NV50_PDISPLAY_INTR_0);
  651. uint32_t intr1 = nv_rd32(dev, NV50_PDISPLAY_INTR_1);
  652. NV_DEBUG_KMS(dev, "PDISPLAY_INTR_BH 0x%08x 0x%08x\n", intr0, intr1);
  653. if (intr1 & NV50_PDISPLAY_INTR_1_CLK_UNK10)
  654. nv50_display_unk10_handler(dev);
  655. else
  656. if (intr1 & NV50_PDISPLAY_INTR_1_CLK_UNK20)
  657. nv50_display_unk20_handler(dev);
  658. else
  659. if (intr1 & NV50_PDISPLAY_INTR_1_CLK_UNK40)
  660. nv50_display_unk40_handler(dev);
  661. else
  662. break;
  663. }
  664. nv_wr32(dev, NV03_PMC_INTR_EN_0, 1);
  665. }
  666. static void
  667. nv50_display_error_handler(struct drm_device *dev)
  668. {
  669. u32 channels = (nv_rd32(dev, NV50_PDISPLAY_INTR_0) & 0x001f0000) >> 16;
  670. u32 addr, data;
  671. int chid;
  672. for (chid = 0; chid < 5; chid++) {
  673. if (!(channels & (1 << chid)))
  674. continue;
  675. nv_wr32(dev, NV50_PDISPLAY_INTR_0, 0x00010000 << chid);
  676. addr = nv_rd32(dev, NV50_PDISPLAY_TRAPPED_ADDR(chid));
  677. data = nv_rd32(dev, NV50_PDISPLAY_TRAPPED_DATA(chid));
  678. NV_ERROR(dev, "EvoCh %d Mthd 0x%04x Data 0x%08x "
  679. "(0x%04x 0x%02x)\n", chid,
  680. addr & 0xffc, data, addr >> 16, (addr >> 12) & 0xf);
  681. nv_wr32(dev, NV50_PDISPLAY_TRAPPED_ADDR(chid), 0x90000000);
  682. }
  683. }
  684. static void
  685. nv50_display_isr(struct drm_device *dev)
  686. {
  687. struct drm_nouveau_private *dev_priv = dev->dev_private;
  688. uint32_t delayed = 0;
  689. while (nv_rd32(dev, NV50_PMC_INTR_0) & NV50_PMC_INTR_0_DISPLAY) {
  690. uint32_t intr0 = nv_rd32(dev, NV50_PDISPLAY_INTR_0);
  691. uint32_t intr1 = nv_rd32(dev, NV50_PDISPLAY_INTR_1);
  692. uint32_t clock;
  693. NV_DEBUG_KMS(dev, "PDISPLAY_INTR 0x%08x 0x%08x\n", intr0, intr1);
  694. if (!intr0 && !(intr1 & ~delayed))
  695. break;
  696. if (intr0 & 0x001f0000) {
  697. nv50_display_error_handler(dev);
  698. intr0 &= ~0x001f0000;
  699. }
  700. if (intr1 & NV50_PDISPLAY_INTR_1_VBLANK_CRTC) {
  701. nv50_display_vblank_handler(dev, intr1);
  702. intr1 &= ~NV50_PDISPLAY_INTR_1_VBLANK_CRTC;
  703. }
  704. clock = (intr1 & (NV50_PDISPLAY_INTR_1_CLK_UNK10 |
  705. NV50_PDISPLAY_INTR_1_CLK_UNK20 |
  706. NV50_PDISPLAY_INTR_1_CLK_UNK40));
  707. if (clock) {
  708. nv_wr32(dev, NV03_PMC_INTR_EN_0, 0);
  709. if (!work_pending(&dev_priv->irq_work))
  710. schedule_work(&dev_priv->irq_work);
  711. delayed |= clock;
  712. intr1 &= ~clock;
  713. }
  714. if (intr0) {
  715. NV_ERROR(dev, "unknown PDISPLAY_INTR_0: 0x%08x\n", intr0);
  716. nv_wr32(dev, NV50_PDISPLAY_INTR_0, intr0);
  717. }
  718. if (intr1) {
  719. NV_ERROR(dev,
  720. "unknown PDISPLAY_INTR_1: 0x%08x\n", intr1);
  721. nv_wr32(dev, NV50_PDISPLAY_INTR_1, intr1);
  722. }
  723. }
  724. }