nv50_display.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855
  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 = dev_priv->evo;
  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 drm_crtc *drm_crtc;
  177. int ret, i;
  178. NV_DEBUG_KMS(dev, "\n");
  179. list_for_each_entry(drm_crtc, &dev->mode_config.crtc_list, head) {
  180. struct nouveau_crtc *crtc = nouveau_crtc(drm_crtc);
  181. nv50_crtc_blank(crtc, true);
  182. }
  183. ret = RING_SPACE(dev_priv->evo, 2);
  184. if (ret == 0) {
  185. BEGIN_RING(dev_priv->evo, 0, NV50_EVO_UPDATE, 1);
  186. OUT_RING(dev_priv->evo, 0);
  187. }
  188. FIRE_RING(dev_priv->evo);
  189. /* Almost like ack'ing a vblank interrupt, maybe in the spirit of
  190. * cleaning up?
  191. */
  192. list_for_each_entry(drm_crtc, &dev->mode_config.crtc_list, head) {
  193. struct nouveau_crtc *crtc = nouveau_crtc(drm_crtc);
  194. uint32_t mask = NV50_PDISPLAY_INTR_1_VBLANK_CRTC_(crtc->index);
  195. if (!crtc->base.enabled)
  196. continue;
  197. nv_wr32(dev, NV50_PDISPLAY_INTR_1, mask);
  198. if (!nv_wait(dev, NV50_PDISPLAY_INTR_1, mask, mask)) {
  199. NV_ERROR(dev, "timeout: (0x610024 & 0x%08x) == "
  200. "0x%08x\n", mask, mask);
  201. NV_ERROR(dev, "0x610024 = 0x%08x\n",
  202. nv_rd32(dev, NV50_PDISPLAY_INTR_1));
  203. }
  204. }
  205. nv50_evo_fini(dev);
  206. for (i = 0; i < 3; i++) {
  207. if (!nv_wait(dev, NV50_PDISPLAY_SOR_DPMS_STATE(i),
  208. NV50_PDISPLAY_SOR_DPMS_STATE_WAIT, 0)) {
  209. NV_ERROR(dev, "timeout: SOR_DPMS_STATE_WAIT(%d) == 0\n", i);
  210. NV_ERROR(dev, "SOR_DPMS_STATE(%d) = 0x%08x\n", i,
  211. nv_rd32(dev, NV50_PDISPLAY_SOR_DPMS_STATE(i)));
  212. }
  213. }
  214. /* disable interrupts. */
  215. nv_wr32(dev, NV50_PDISPLAY_INTR_EN_1, 0x00000000);
  216. /* disable hotplug interrupts */
  217. nv_wr32(dev, 0xe054, 0xffffffff);
  218. nv_wr32(dev, 0xe050, 0x00000000);
  219. if (dev_priv->chipset >= 0x90) {
  220. nv_wr32(dev, 0xe074, 0xffffffff);
  221. nv_wr32(dev, 0xe070, 0x00000000);
  222. }
  223. return 0;
  224. }
  225. int nv50_display_create(struct drm_device *dev)
  226. {
  227. struct drm_nouveau_private *dev_priv = dev->dev_private;
  228. struct dcb_table *dcb = &dev_priv->vbios.dcb;
  229. struct drm_connector *connector, *ct;
  230. int ret, i;
  231. NV_DEBUG_KMS(dev, "\n");
  232. /* init basic kernel modesetting */
  233. drm_mode_config_init(dev);
  234. /* Initialise some optional connector properties. */
  235. drm_mode_create_scaling_mode_property(dev);
  236. drm_mode_create_dithering_property(dev);
  237. dev->mode_config.min_width = 0;
  238. dev->mode_config.min_height = 0;
  239. dev->mode_config.funcs = (void *)&nouveau_mode_config_funcs;
  240. dev->mode_config.max_width = 8192;
  241. dev->mode_config.max_height = 8192;
  242. dev->mode_config.fb_base = dev_priv->fb_phys;
  243. /* Create CRTC objects */
  244. for (i = 0; i < 2; i++)
  245. nv50_crtc_create(dev, i);
  246. /* We setup the encoders from the BIOS table */
  247. for (i = 0 ; i < dcb->entries; i++) {
  248. struct dcb_entry *entry = &dcb->entry[i];
  249. if (entry->location != DCB_LOC_ON_CHIP) {
  250. NV_WARN(dev, "Off-chip encoder %d/%d unsupported\n",
  251. entry->type, ffs(entry->or) - 1);
  252. continue;
  253. }
  254. connector = nouveau_connector_create(dev, entry->connector);
  255. if (IS_ERR(connector))
  256. continue;
  257. switch (entry->type) {
  258. case OUTPUT_TMDS:
  259. case OUTPUT_LVDS:
  260. case OUTPUT_DP:
  261. nv50_sor_create(connector, entry);
  262. break;
  263. case OUTPUT_ANALOG:
  264. nv50_dac_create(connector, entry);
  265. break;
  266. default:
  267. NV_WARN(dev, "DCB encoder %d unknown\n", entry->type);
  268. continue;
  269. }
  270. }
  271. list_for_each_entry_safe(connector, ct,
  272. &dev->mode_config.connector_list, head) {
  273. if (!connector->encoder_ids[0]) {
  274. NV_WARN(dev, "%s has no encoders, removing\n",
  275. drm_get_connector_name(connector));
  276. connector->funcs->destroy(connector);
  277. }
  278. }
  279. INIT_WORK(&dev_priv->irq_work, nv50_display_irq_handler_bh);
  280. nouveau_irq_register(dev, 26, nv50_display_isr);
  281. ret = nv50_display_init(dev);
  282. if (ret) {
  283. nv50_display_destroy(dev);
  284. return ret;
  285. }
  286. return 0;
  287. }
  288. void
  289. nv50_display_destroy(struct drm_device *dev)
  290. {
  291. NV_DEBUG_KMS(dev, "\n");
  292. drm_mode_config_cleanup(dev);
  293. nv50_display_disable(dev);
  294. nouveau_irq_unregister(dev, 26);
  295. }
  296. static u16
  297. nv50_display_script_select(struct drm_device *dev, struct dcb_entry *dcb,
  298. u32 mc, int pxclk)
  299. {
  300. struct drm_nouveau_private *dev_priv = dev->dev_private;
  301. struct nouveau_connector *nv_connector = NULL;
  302. struct drm_encoder *encoder;
  303. struct nvbios *bios = &dev_priv->vbios;
  304. u32 script = 0, or;
  305. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  306. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  307. if (nv_encoder->dcb != dcb)
  308. continue;
  309. nv_connector = nouveau_encoder_connector_get(nv_encoder);
  310. break;
  311. }
  312. or = ffs(dcb->or) - 1;
  313. switch (dcb->type) {
  314. case OUTPUT_LVDS:
  315. script = (mc >> 8) & 0xf;
  316. if (bios->fp_no_ddc) {
  317. if (bios->fp.dual_link)
  318. script |= 0x0100;
  319. if (bios->fp.if_is_24bit)
  320. script |= 0x0200;
  321. } else {
  322. if (pxclk >= bios->fp.duallink_transition_clk) {
  323. script |= 0x0100;
  324. if (bios->fp.strapless_is_24bit & 2)
  325. script |= 0x0200;
  326. } else
  327. if (bios->fp.strapless_is_24bit & 1)
  328. script |= 0x0200;
  329. if (nv_connector && nv_connector->edid &&
  330. (nv_connector->edid->revision >= 4) &&
  331. (nv_connector->edid->input & 0x70) >= 0x20)
  332. script |= 0x0200;
  333. }
  334. if (nouveau_uscript_lvds >= 0) {
  335. NV_INFO(dev, "override script 0x%04x with 0x%04x "
  336. "for output LVDS-%d\n", script,
  337. nouveau_uscript_lvds, or);
  338. script = nouveau_uscript_lvds;
  339. }
  340. break;
  341. case OUTPUT_TMDS:
  342. script = (mc >> 8) & 0xf;
  343. if (pxclk >= 165000)
  344. script |= 0x0100;
  345. if (nouveau_uscript_tmds >= 0) {
  346. NV_INFO(dev, "override script 0x%04x with 0x%04x "
  347. "for output TMDS-%d\n", script,
  348. nouveau_uscript_tmds, or);
  349. script = nouveau_uscript_tmds;
  350. }
  351. break;
  352. case OUTPUT_DP:
  353. script = (mc >> 8) & 0xf;
  354. break;
  355. case OUTPUT_ANALOG:
  356. script = 0xff;
  357. break;
  358. default:
  359. NV_ERROR(dev, "modeset on unsupported output type!\n");
  360. break;
  361. }
  362. return script;
  363. }
  364. static void
  365. nv50_display_vblank_crtc_handler(struct drm_device *dev, int crtc)
  366. {
  367. struct drm_nouveau_private *dev_priv = dev->dev_private;
  368. struct nouveau_channel *chan, *tmp;
  369. list_for_each_entry_safe(chan, tmp, &dev_priv->vbl_waiting,
  370. nvsw.vbl_wait) {
  371. if (chan->nvsw.vblsem_head != crtc)
  372. continue;
  373. nouveau_bo_wr32(chan->notifier_bo, chan->nvsw.vblsem_offset,
  374. chan->nvsw.vblsem_rval);
  375. list_del(&chan->nvsw.vbl_wait);
  376. drm_vblank_put(dev, crtc);
  377. }
  378. drm_handle_vblank(dev, crtc);
  379. }
  380. static void
  381. nv50_display_vblank_handler(struct drm_device *dev, uint32_t intr)
  382. {
  383. if (intr & NV50_PDISPLAY_INTR_1_VBLANK_CRTC_0)
  384. nv50_display_vblank_crtc_handler(dev, 0);
  385. if (intr & NV50_PDISPLAY_INTR_1_VBLANK_CRTC_1)
  386. nv50_display_vblank_crtc_handler(dev, 1);
  387. nv_wr32(dev, NV50_PDISPLAY_INTR_1, NV50_PDISPLAY_INTR_1_VBLANK_CRTC);
  388. }
  389. static void
  390. nv50_display_unk10_handler(struct drm_device *dev)
  391. {
  392. struct drm_nouveau_private *dev_priv = dev->dev_private;
  393. u32 unk30 = nv_rd32(dev, 0x610030), mc;
  394. int i, crtc, or, type = OUTPUT_ANY;
  395. NV_DEBUG_KMS(dev, "0x610030: 0x%08x\n", unk30);
  396. dev_priv->evo_irq.dcb = NULL;
  397. nv_wr32(dev, 0x619494, nv_rd32(dev, 0x619494) & ~8);
  398. /* Determine which CRTC we're dealing with, only 1 ever will be
  399. * signalled at the same time with the current nouveau code.
  400. */
  401. crtc = ffs((unk30 & 0x00000060) >> 5) - 1;
  402. if (crtc < 0)
  403. goto ack;
  404. /* Nothing needs to be done for the encoder */
  405. crtc = ffs((unk30 & 0x00000180) >> 7) - 1;
  406. if (crtc < 0)
  407. goto ack;
  408. /* Find which encoder was connected to the CRTC */
  409. for (i = 0; type == OUTPUT_ANY && i < 3; i++) {
  410. mc = nv_rd32(dev, NV50_PDISPLAY_DAC_MODE_CTRL_C(i));
  411. NV_DEBUG_KMS(dev, "DAC-%d mc: 0x%08x\n", i, mc);
  412. if (!(mc & (1 << crtc)))
  413. continue;
  414. switch ((mc & 0x00000f00) >> 8) {
  415. case 0: type = OUTPUT_ANALOG; break;
  416. case 1: type = OUTPUT_TV; break;
  417. default:
  418. NV_ERROR(dev, "invalid mc, DAC-%d: 0x%08x\n", i, mc);
  419. goto ack;
  420. }
  421. or = i;
  422. }
  423. for (i = 0; type == OUTPUT_ANY && i < nv50_sor_nr(dev); i++) {
  424. if (dev_priv->chipset < 0x90 ||
  425. dev_priv->chipset == 0x92 ||
  426. dev_priv->chipset == 0xa0)
  427. mc = nv_rd32(dev, NV50_PDISPLAY_SOR_MODE_CTRL_C(i));
  428. else
  429. mc = nv_rd32(dev, NV90_PDISPLAY_SOR_MODE_CTRL_C(i));
  430. NV_DEBUG_KMS(dev, "SOR-%d mc: 0x%08x\n", i, mc);
  431. if (!(mc & (1 << crtc)))
  432. continue;
  433. switch ((mc & 0x00000f00) >> 8) {
  434. case 0: type = OUTPUT_LVDS; break;
  435. case 1: type = OUTPUT_TMDS; break;
  436. case 2: type = OUTPUT_TMDS; break;
  437. case 5: type = OUTPUT_TMDS; break;
  438. case 8: type = OUTPUT_DP; break;
  439. case 9: type = OUTPUT_DP; break;
  440. default:
  441. NV_ERROR(dev, "invalid mc, SOR-%d: 0x%08x\n", i, mc);
  442. goto ack;
  443. }
  444. or = i;
  445. }
  446. /* There was no encoder to disable */
  447. if (type == OUTPUT_ANY)
  448. goto ack;
  449. /* Disable the encoder */
  450. for (i = 0; i < dev_priv->vbios.dcb.entries; i++) {
  451. struct dcb_entry *dcb = &dev_priv->vbios.dcb.entry[i];
  452. if (dcb->type == type && (dcb->or & (1 << or))) {
  453. nouveau_bios_run_display_table(dev, dcb, 0, -1);
  454. dev_priv->evo_irq.dcb = dcb;
  455. goto ack;
  456. }
  457. }
  458. NV_ERROR(dev, "no dcb for %d %d 0x%08x\n", or, type, mc);
  459. ack:
  460. nv_wr32(dev, NV50_PDISPLAY_INTR_1, NV50_PDISPLAY_INTR_1_CLK_UNK10);
  461. nv_wr32(dev, 0x610030, 0x80000000);
  462. }
  463. static void
  464. nv50_display_unk20_dp_hack(struct drm_device *dev, struct dcb_entry *dcb)
  465. {
  466. int or = ffs(dcb->or) - 1, link = !(dcb->dpconf.sor.link & 1);
  467. struct drm_encoder *encoder;
  468. uint32_t tmp, unk0 = 0, unk1 = 0;
  469. if (dcb->type != OUTPUT_DP)
  470. return;
  471. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  472. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  473. if (nv_encoder->dcb == dcb) {
  474. unk0 = nv_encoder->dp.unk0;
  475. unk1 = nv_encoder->dp.unk1;
  476. break;
  477. }
  478. }
  479. if (unk0 || unk1) {
  480. tmp = nv_rd32(dev, NV50_SOR_DP_CTRL(or, link));
  481. tmp &= 0xfffffe03;
  482. nv_wr32(dev, NV50_SOR_DP_CTRL(or, link), tmp | unk0);
  483. tmp = nv_rd32(dev, NV50_SOR_DP_UNK128(or, link));
  484. tmp &= 0xfef080c0;
  485. nv_wr32(dev, NV50_SOR_DP_UNK128(or, link), tmp | unk1);
  486. }
  487. }
  488. static void
  489. nv50_display_unk20_handler(struct drm_device *dev)
  490. {
  491. struct drm_nouveau_private *dev_priv = dev->dev_private;
  492. u32 unk30 = nv_rd32(dev, 0x610030), tmp, pclk, script, mc;
  493. struct dcb_entry *dcb;
  494. int i, crtc, or, type = OUTPUT_ANY;
  495. NV_DEBUG_KMS(dev, "0x610030: 0x%08x\n", unk30);
  496. dcb = dev_priv->evo_irq.dcb;
  497. if (dcb) {
  498. nouveau_bios_run_display_table(dev, dcb, 0, -2);
  499. dev_priv->evo_irq.dcb = NULL;
  500. }
  501. /* CRTC clock change requested? */
  502. crtc = ffs((unk30 & 0x00000600) >> 9) - 1;
  503. if (crtc >= 0) {
  504. pclk = nv_rd32(dev, NV50_PDISPLAY_CRTC_P(crtc, CLOCK));
  505. pclk &= 0x003fffff;
  506. nv50_crtc_set_clock(dev, crtc, pclk);
  507. tmp = nv_rd32(dev, NV50_PDISPLAY_CRTC_CLK_CTRL2(crtc));
  508. tmp &= ~0x000000f;
  509. nv_wr32(dev, NV50_PDISPLAY_CRTC_CLK_CTRL2(crtc), tmp);
  510. }
  511. /* Nothing needs to be done for the encoder */
  512. crtc = ffs((unk30 & 0x00000180) >> 7) - 1;
  513. if (crtc < 0)
  514. goto ack;
  515. pclk = nv_rd32(dev, NV50_PDISPLAY_CRTC_P(crtc, CLOCK)) & 0x003fffff;
  516. /* Find which encoder is connected to the CRTC */
  517. for (i = 0; type == OUTPUT_ANY && i < 3; i++) {
  518. mc = nv_rd32(dev, NV50_PDISPLAY_DAC_MODE_CTRL_P(i));
  519. NV_DEBUG_KMS(dev, "DAC-%d mc: 0x%08x\n", i, mc);
  520. if (!(mc & (1 << crtc)))
  521. continue;
  522. switch ((mc & 0x00000f00) >> 8) {
  523. case 0: type = OUTPUT_ANALOG; break;
  524. case 1: type = OUTPUT_TV; break;
  525. default:
  526. NV_ERROR(dev, "invalid mc, DAC-%d: 0x%08x\n", i, mc);
  527. goto ack;
  528. }
  529. or = i;
  530. }
  531. for (i = 0; type == OUTPUT_ANY && i < nv50_sor_nr(dev); i++) {
  532. if (dev_priv->chipset < 0x90 ||
  533. dev_priv->chipset == 0x92 ||
  534. dev_priv->chipset == 0xa0)
  535. mc = nv_rd32(dev, NV50_PDISPLAY_SOR_MODE_CTRL_P(i));
  536. else
  537. mc = nv_rd32(dev, NV90_PDISPLAY_SOR_MODE_CTRL_P(i));
  538. NV_DEBUG_KMS(dev, "SOR-%d mc: 0x%08x\n", i, mc);
  539. if (!(mc & (1 << crtc)))
  540. continue;
  541. switch ((mc & 0x00000f00) >> 8) {
  542. case 0: type = OUTPUT_LVDS; break;
  543. case 1: type = OUTPUT_TMDS; break;
  544. case 2: type = OUTPUT_TMDS; break;
  545. case 5: type = OUTPUT_TMDS; break;
  546. case 8: type = OUTPUT_DP; break;
  547. case 9: type = OUTPUT_DP; break;
  548. default:
  549. NV_ERROR(dev, "invalid mc, SOR-%d: 0x%08x\n", i, mc);
  550. goto ack;
  551. }
  552. or = i;
  553. }
  554. if (type == OUTPUT_ANY)
  555. goto ack;
  556. /* Enable the encoder */
  557. for (i = 0; i < dev_priv->vbios.dcb.entries; i++) {
  558. dcb = &dev_priv->vbios.dcb.entry[i];
  559. if (dcb->type == type && (dcb->or & (1 << or)))
  560. break;
  561. }
  562. if (i == dev_priv->vbios.dcb.entries) {
  563. NV_ERROR(dev, "no dcb for %d %d 0x%08x\n", or, type, mc);
  564. goto ack;
  565. }
  566. script = nv50_display_script_select(dev, dcb, mc, pclk);
  567. nouveau_bios_run_display_table(dev, dcb, script, pclk);
  568. nv50_display_unk20_dp_hack(dev, dcb);
  569. if (dcb->type != OUTPUT_ANALOG) {
  570. tmp = nv_rd32(dev, NV50_PDISPLAY_SOR_CLK_CTRL2(or));
  571. tmp &= ~0x00000f0f;
  572. if (script & 0x0100)
  573. tmp |= 0x00000101;
  574. nv_wr32(dev, NV50_PDISPLAY_SOR_CLK_CTRL2(or), tmp);
  575. } else {
  576. nv_wr32(dev, NV50_PDISPLAY_DAC_CLK_CTRL2(or), 0);
  577. }
  578. dev_priv->evo_irq.dcb = dcb;
  579. dev_priv->evo_irq.pclk = pclk;
  580. dev_priv->evo_irq.script = script;
  581. ack:
  582. nv_wr32(dev, NV50_PDISPLAY_INTR_1, NV50_PDISPLAY_INTR_1_CLK_UNK20);
  583. nv_wr32(dev, 0x610030, 0x80000000);
  584. }
  585. /* If programming a TMDS output on a SOR that can also be configured for
  586. * DisplayPort, make sure NV50_SOR_DP_CTRL_ENABLE is forced off.
  587. *
  588. * It looks like the VBIOS TMDS scripts make an attempt at this, however,
  589. * the VBIOS scripts on at least one board I have only switch it off on
  590. * link 0, causing a blank display if the output has previously been
  591. * programmed for DisplayPort.
  592. */
  593. static void
  594. nv50_display_unk40_dp_set_tmds(struct drm_device *dev, struct dcb_entry *dcb)
  595. {
  596. int or = ffs(dcb->or) - 1, link = !(dcb->dpconf.sor.link & 1);
  597. struct drm_encoder *encoder;
  598. u32 tmp;
  599. if (dcb->type != OUTPUT_TMDS)
  600. return;
  601. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  602. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  603. if (nv_encoder->dcb->type == OUTPUT_DP &&
  604. nv_encoder->dcb->or & (1 << or)) {
  605. tmp = nv_rd32(dev, NV50_SOR_DP_CTRL(or, link));
  606. tmp &= ~NV50_SOR_DP_CTRL_ENABLED;
  607. nv_wr32(dev, NV50_SOR_DP_CTRL(or, link), tmp);
  608. break;
  609. }
  610. }
  611. }
  612. static void
  613. nv50_display_unk40_handler(struct drm_device *dev)
  614. {
  615. struct drm_nouveau_private *dev_priv = dev->dev_private;
  616. struct dcb_entry *dcb = dev_priv->evo_irq.dcb;
  617. u16 script = dev_priv->evo_irq.script;
  618. u32 unk30 = nv_rd32(dev, 0x610030), pclk = dev_priv->evo_irq.pclk;
  619. NV_DEBUG_KMS(dev, "0x610030: 0x%08x\n", unk30);
  620. dev_priv->evo_irq.dcb = NULL;
  621. if (!dcb)
  622. goto ack;
  623. nouveau_bios_run_display_table(dev, dcb, script, -pclk);
  624. nv50_display_unk40_dp_set_tmds(dev, dcb);
  625. ack:
  626. nv_wr32(dev, NV50_PDISPLAY_INTR_1, NV50_PDISPLAY_INTR_1_CLK_UNK40);
  627. nv_wr32(dev, 0x610030, 0x80000000);
  628. nv_wr32(dev, 0x619494, nv_rd32(dev, 0x619494) | 8);
  629. }
  630. void
  631. nv50_display_irq_handler_bh(struct work_struct *work)
  632. {
  633. struct drm_nouveau_private *dev_priv =
  634. container_of(work, struct drm_nouveau_private, irq_work);
  635. struct drm_device *dev = dev_priv->dev;
  636. for (;;) {
  637. uint32_t intr0 = nv_rd32(dev, NV50_PDISPLAY_INTR_0);
  638. uint32_t intr1 = nv_rd32(dev, NV50_PDISPLAY_INTR_1);
  639. NV_DEBUG_KMS(dev, "PDISPLAY_INTR_BH 0x%08x 0x%08x\n", intr0, intr1);
  640. if (intr1 & NV50_PDISPLAY_INTR_1_CLK_UNK10)
  641. nv50_display_unk10_handler(dev);
  642. else
  643. if (intr1 & NV50_PDISPLAY_INTR_1_CLK_UNK20)
  644. nv50_display_unk20_handler(dev);
  645. else
  646. if (intr1 & NV50_PDISPLAY_INTR_1_CLK_UNK40)
  647. nv50_display_unk40_handler(dev);
  648. else
  649. break;
  650. }
  651. nv_wr32(dev, NV03_PMC_INTR_EN_0, 1);
  652. }
  653. static void
  654. nv50_display_error_handler(struct drm_device *dev)
  655. {
  656. u32 channels = (nv_rd32(dev, NV50_PDISPLAY_INTR_0) & 0x001f0000) >> 16;
  657. u32 addr, data;
  658. int chid;
  659. for (chid = 0; chid < 5; chid++) {
  660. if (!(channels & (1 << chid)))
  661. continue;
  662. nv_wr32(dev, NV50_PDISPLAY_INTR_0, 0x00010000 << chid);
  663. addr = nv_rd32(dev, NV50_PDISPLAY_TRAPPED_ADDR(chid));
  664. data = nv_rd32(dev, NV50_PDISPLAY_TRAPPED_DATA(chid));
  665. NV_ERROR(dev, "EvoCh %d Mthd 0x%04x Data 0x%08x "
  666. "(0x%04x 0x%02x)\n", chid,
  667. addr & 0xffc, data, addr >> 16, (addr >> 12) & 0xf);
  668. nv_wr32(dev, NV50_PDISPLAY_TRAPPED_ADDR(chid), 0x90000000);
  669. }
  670. }
  671. static void
  672. nv50_display_isr(struct drm_device *dev)
  673. {
  674. struct drm_nouveau_private *dev_priv = dev->dev_private;
  675. uint32_t delayed = 0;
  676. while (nv_rd32(dev, NV50_PMC_INTR_0) & NV50_PMC_INTR_0_DISPLAY) {
  677. uint32_t intr0 = nv_rd32(dev, NV50_PDISPLAY_INTR_0);
  678. uint32_t intr1 = nv_rd32(dev, NV50_PDISPLAY_INTR_1);
  679. uint32_t clock;
  680. NV_DEBUG_KMS(dev, "PDISPLAY_INTR 0x%08x 0x%08x\n", intr0, intr1);
  681. if (!intr0 && !(intr1 & ~delayed))
  682. break;
  683. if (intr0 & 0x001f0000) {
  684. nv50_display_error_handler(dev);
  685. intr0 &= ~0x001f0000;
  686. }
  687. if (intr1 & NV50_PDISPLAY_INTR_1_VBLANK_CRTC) {
  688. nv50_display_vblank_handler(dev, intr1);
  689. intr1 &= ~NV50_PDISPLAY_INTR_1_VBLANK_CRTC;
  690. }
  691. clock = (intr1 & (NV50_PDISPLAY_INTR_1_CLK_UNK10 |
  692. NV50_PDISPLAY_INTR_1_CLK_UNK20 |
  693. NV50_PDISPLAY_INTR_1_CLK_UNK40));
  694. if (clock) {
  695. nv_wr32(dev, NV03_PMC_INTR_EN_0, 0);
  696. if (!work_pending(&dev_priv->irq_work))
  697. queue_work(dev_priv->wq, &dev_priv->irq_work);
  698. delayed |= clock;
  699. intr1 &= ~clock;
  700. }
  701. if (intr0) {
  702. NV_ERROR(dev, "unknown PDISPLAY_INTR_0: 0x%08x\n", intr0);
  703. nv_wr32(dev, NV50_PDISPLAY_INTR_0, intr0);
  704. }
  705. if (intr1) {
  706. NV_ERROR(dev,
  707. "unknown PDISPLAY_INTR_1: 0x%08x\n", intr1);
  708. nv_wr32(dev, NV50_PDISPLAY_INTR_1, intr1);
  709. }
  710. }
  711. }