FRV: Use generic show_interrupts()
[cris-mirror.git] / drivers / gpu / drm / nouveau / nouveau_hw.c
blob053edf9d2f67db4c6ed86536ea08f89d8c5b8b51
1 /*
2 * Copyright 2006 Dave Airlie
3 * Copyright 2007 Maarten Maathuis
4 * Copyright 2007-2009 Stuart Bennett
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
21 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
25 #include "drmP.h"
26 #include "nouveau_drv.h"
27 #include "nouveau_hw.h"
29 #define CHIPSET_NFORCE 0x01a0
30 #define CHIPSET_NFORCE2 0x01f0
33 * misc hw access wrappers/control functions
36 void
37 NVWriteVgaSeq(struct drm_device *dev, int head, uint8_t index, uint8_t value)
39 NVWritePRMVIO(dev, head, NV_PRMVIO_SRX, index);
40 NVWritePRMVIO(dev, head, NV_PRMVIO_SR, value);
43 uint8_t
44 NVReadVgaSeq(struct drm_device *dev, int head, uint8_t index)
46 NVWritePRMVIO(dev, head, NV_PRMVIO_SRX, index);
47 return NVReadPRMVIO(dev, head, NV_PRMVIO_SR);
50 void
51 NVWriteVgaGr(struct drm_device *dev, int head, uint8_t index, uint8_t value)
53 NVWritePRMVIO(dev, head, NV_PRMVIO_GRX, index);
54 NVWritePRMVIO(dev, head, NV_PRMVIO_GX, value);
57 uint8_t
58 NVReadVgaGr(struct drm_device *dev, int head, uint8_t index)
60 NVWritePRMVIO(dev, head, NV_PRMVIO_GRX, index);
61 return NVReadPRMVIO(dev, head, NV_PRMVIO_GX);
64 /* CR44 takes values 0 (head A), 3 (head B) and 4 (heads tied)
65 * it affects only the 8 bit vga io regs, which we access using mmio at
66 * 0xc{0,2}3c*, 0x60{1,3}3*, and 0x68{1,3}3d*
67 * in general, the set value of cr44 does not matter: reg access works as
68 * expected and values can be set for the appropriate head by using a 0x2000
69 * offset as required
70 * however:
71 * a) pre nv40, the head B range of PRMVIO regs at 0xc23c* was not exposed and
72 * cr44 must be set to 0 or 3 for accessing values on the correct head
73 * through the common 0xc03c* addresses
74 * b) in tied mode (4) head B is programmed to the values set on head A, and
75 * access using the head B addresses can have strange results, ergo we leave
76 * tied mode in init once we know to what cr44 should be restored on exit
78 * the owner parameter is slightly abused:
79 * 0 and 1 are treated as head values and so the set value is (owner * 3)
80 * other values are treated as literal values to set
82 void
83 NVSetOwner(struct drm_device *dev, int owner)
85 struct drm_nouveau_private *dev_priv = dev->dev_private;
87 if (owner == 1)
88 owner *= 3;
90 if (dev_priv->chipset == 0x11) {
91 /* This might seem stupid, but the blob does it and
92 * omitting it often locks the system up.
94 NVReadVgaCrtc(dev, 0, NV_CIO_SR_LOCK_INDEX);
95 NVReadVgaCrtc(dev, 1, NV_CIO_SR_LOCK_INDEX);
98 /* CR44 is always changed on CRTC0 */
99 NVWriteVgaCrtc(dev, 0, NV_CIO_CRE_44, owner);
101 if (dev_priv->chipset == 0x11) { /* set me harder */
102 NVWriteVgaCrtc(dev, 0, NV_CIO_CRE_2E, owner);
103 NVWriteVgaCrtc(dev, 0, NV_CIO_CRE_2E, owner);
107 void
108 NVBlankScreen(struct drm_device *dev, int head, bool blank)
110 unsigned char seq1;
112 if (nv_two_heads(dev))
113 NVSetOwner(dev, head);
115 seq1 = NVReadVgaSeq(dev, head, NV_VIO_SR_CLOCK_INDEX);
117 NVVgaSeqReset(dev, head, true);
118 if (blank)
119 NVWriteVgaSeq(dev, head, NV_VIO_SR_CLOCK_INDEX, seq1 | 0x20);
120 else
121 NVWriteVgaSeq(dev, head, NV_VIO_SR_CLOCK_INDEX, seq1 & ~0x20);
122 NVVgaSeqReset(dev, head, false);
126 * PLL setting
129 static int
130 powerctrl_1_shift(int chip_version, int reg)
132 int shift = -4;
134 if (chip_version < 0x17 || chip_version == 0x1a || chip_version == 0x20)
135 return shift;
137 switch (reg) {
138 case NV_RAMDAC_VPLL2:
139 shift += 4;
140 case NV_PRAMDAC_VPLL_COEFF:
141 shift += 4;
142 case NV_PRAMDAC_MPLL_COEFF:
143 shift += 4;
144 case NV_PRAMDAC_NVPLL_COEFF:
145 shift += 4;
149 * the shift for vpll regs is only used for nv3x chips with a single
150 * stage pll
152 if (shift > 4 && (chip_version < 0x32 || chip_version == 0x35 ||
153 chip_version == 0x36 || chip_version >= 0x40))
154 shift = -4;
156 return shift;
159 static void
160 setPLL_single(struct drm_device *dev, uint32_t reg, struct nouveau_pll_vals *pv)
162 struct drm_nouveau_private *dev_priv = dev->dev_private;
163 int chip_version = dev_priv->vbios.chip_version;
164 uint32_t oldpll = NVReadRAMDAC(dev, 0, reg);
165 int oldN = (oldpll >> 8) & 0xff, oldM = oldpll & 0xff;
166 uint32_t pll = (oldpll & 0xfff80000) | pv->log2P << 16 | pv->NM1;
167 uint32_t saved_powerctrl_1 = 0;
168 int shift_powerctrl_1 = powerctrl_1_shift(chip_version, reg);
170 if (oldpll == pll)
171 return; /* already set */
173 if (shift_powerctrl_1 >= 0) {
174 saved_powerctrl_1 = nvReadMC(dev, NV_PBUS_POWERCTRL_1);
175 nvWriteMC(dev, NV_PBUS_POWERCTRL_1,
176 (saved_powerctrl_1 & ~(0xf << shift_powerctrl_1)) |
177 1 << shift_powerctrl_1);
180 if (oldM && pv->M1 && (oldN / oldM < pv->N1 / pv->M1))
181 /* upclock -- write new post divider first */
182 NVWriteRAMDAC(dev, 0, reg, pv->log2P << 16 | (oldpll & 0xffff));
183 else
184 /* downclock -- write new NM first */
185 NVWriteRAMDAC(dev, 0, reg, (oldpll & 0xffff0000) | pv->NM1);
187 if (chip_version < 0x17 && chip_version != 0x11)
188 /* wait a bit on older chips */
189 msleep(64);
190 NVReadRAMDAC(dev, 0, reg);
192 /* then write the other half as well */
193 NVWriteRAMDAC(dev, 0, reg, pll);
195 if (shift_powerctrl_1 >= 0)
196 nvWriteMC(dev, NV_PBUS_POWERCTRL_1, saved_powerctrl_1);
199 static uint32_t
200 new_ramdac580(uint32_t reg1, bool ss, uint32_t ramdac580)
202 bool head_a = (reg1 == NV_PRAMDAC_VPLL_COEFF);
204 if (ss) /* single stage pll mode */
205 ramdac580 |= head_a ? NV_RAMDAC_580_VPLL1_ACTIVE :
206 NV_RAMDAC_580_VPLL2_ACTIVE;
207 else
208 ramdac580 &= head_a ? ~NV_RAMDAC_580_VPLL1_ACTIVE :
209 ~NV_RAMDAC_580_VPLL2_ACTIVE;
211 return ramdac580;
214 static void
215 setPLL_double_highregs(struct drm_device *dev, uint32_t reg1,
216 struct nouveau_pll_vals *pv)
218 struct drm_nouveau_private *dev_priv = dev->dev_private;
219 int chip_version = dev_priv->vbios.chip_version;
220 bool nv3035 = chip_version == 0x30 || chip_version == 0x35;
221 uint32_t reg2 = reg1 + ((reg1 == NV_RAMDAC_VPLL2) ? 0x5c : 0x70);
222 uint32_t oldpll1 = NVReadRAMDAC(dev, 0, reg1);
223 uint32_t oldpll2 = !nv3035 ? NVReadRAMDAC(dev, 0, reg2) : 0;
224 uint32_t pll1 = (oldpll1 & 0xfff80000) | pv->log2P << 16 | pv->NM1;
225 uint32_t pll2 = (oldpll2 & 0x7fff0000) | 1 << 31 | pv->NM2;
226 uint32_t oldramdac580 = 0, ramdac580 = 0;
227 bool single_stage = !pv->NM2 || pv->N2 == pv->M2; /* nv41+ only */
228 uint32_t saved_powerctrl_1 = 0, savedc040 = 0;
229 int shift_powerctrl_1 = powerctrl_1_shift(chip_version, reg1);
231 /* model specific additions to generic pll1 and pll2 set up above */
232 if (nv3035) {
233 pll1 = (pll1 & 0xfcc7ffff) | (pv->N2 & 0x18) << 21 |
234 (pv->N2 & 0x7) << 19 | 8 << 4 | (pv->M2 & 7) << 4;
235 pll2 = 0;
237 if (chip_version > 0x40 && reg1 >= NV_PRAMDAC_VPLL_COEFF) { /* !nv40 */
238 oldramdac580 = NVReadRAMDAC(dev, 0, NV_PRAMDAC_580);
239 ramdac580 = new_ramdac580(reg1, single_stage, oldramdac580);
240 if (oldramdac580 != ramdac580)
241 oldpll1 = ~0; /* force mismatch */
242 if (single_stage)
243 /* magic value used by nvidia in single stage mode */
244 pll2 |= 0x011f;
246 if (chip_version > 0x70)
247 /* magic bits set by the blob (but not the bios) on g71-73 */
248 pll1 = (pll1 & 0x7fffffff) | (single_stage ? 0x4 : 0xc) << 28;
250 if (oldpll1 == pll1 && oldpll2 == pll2)
251 return; /* already set */
253 if (shift_powerctrl_1 >= 0) {
254 saved_powerctrl_1 = nvReadMC(dev, NV_PBUS_POWERCTRL_1);
255 nvWriteMC(dev, NV_PBUS_POWERCTRL_1,
256 (saved_powerctrl_1 & ~(0xf << shift_powerctrl_1)) |
257 1 << shift_powerctrl_1);
260 if (chip_version >= 0x40) {
261 int shift_c040 = 14;
263 switch (reg1) {
264 case NV_PRAMDAC_MPLL_COEFF:
265 shift_c040 += 2;
266 case NV_PRAMDAC_NVPLL_COEFF:
267 shift_c040 += 2;
268 case NV_RAMDAC_VPLL2:
269 shift_c040 += 2;
270 case NV_PRAMDAC_VPLL_COEFF:
271 shift_c040 += 2;
274 savedc040 = nvReadMC(dev, 0xc040);
275 if (shift_c040 != 14)
276 nvWriteMC(dev, 0xc040, savedc040 & ~(3 << shift_c040));
279 if (oldramdac580 != ramdac580)
280 NVWriteRAMDAC(dev, 0, NV_PRAMDAC_580, ramdac580);
282 if (!nv3035)
283 NVWriteRAMDAC(dev, 0, reg2, pll2);
284 NVWriteRAMDAC(dev, 0, reg1, pll1);
286 if (shift_powerctrl_1 >= 0)
287 nvWriteMC(dev, NV_PBUS_POWERCTRL_1, saved_powerctrl_1);
288 if (chip_version >= 0x40)
289 nvWriteMC(dev, 0xc040, savedc040);
292 static void
293 setPLL_double_lowregs(struct drm_device *dev, uint32_t NMNMreg,
294 struct nouveau_pll_vals *pv)
296 /* When setting PLLs, there is a merry game of disabling and enabling
297 * various bits of hardware during the process. This function is a
298 * synthesis of six nv4x traces, nearly each card doing a subtly
299 * different thing. With luck all the necessary bits for each card are
300 * combined herein. Without luck it deviates from each card's formula
301 * so as to not work on any :)
304 uint32_t Preg = NMNMreg - 4;
305 bool mpll = Preg == 0x4020;
306 uint32_t oldPval = nvReadMC(dev, Preg);
307 uint32_t NMNM = pv->NM2 << 16 | pv->NM1;
308 uint32_t Pval = (oldPval & (mpll ? ~(0x77 << 16) : ~(7 << 16))) |
309 0xc << 28 | pv->log2P << 16;
310 uint32_t saved4600 = 0;
311 /* some cards have different maskc040s */
312 uint32_t maskc040 = ~(3 << 14), savedc040;
313 bool single_stage = !pv->NM2 || pv->N2 == pv->M2;
315 if (nvReadMC(dev, NMNMreg) == NMNM && (oldPval & 0xc0070000) == Pval)
316 return;
318 if (Preg == 0x4000)
319 maskc040 = ~0x333;
320 if (Preg == 0x4058)
321 maskc040 = ~(0xc << 24);
323 if (mpll) {
324 struct pll_lims pll_lim;
325 uint8_t Pval2;
327 if (get_pll_limits(dev, Preg, &pll_lim))
328 return;
330 Pval2 = pv->log2P + pll_lim.log2p_bias;
331 if (Pval2 > pll_lim.max_log2p)
332 Pval2 = pll_lim.max_log2p;
333 Pval |= 1 << 28 | Pval2 << 20;
335 saved4600 = nvReadMC(dev, 0x4600);
336 nvWriteMC(dev, 0x4600, saved4600 | 8 << 28);
338 if (single_stage)
339 Pval |= mpll ? 1 << 12 : 1 << 8;
341 nvWriteMC(dev, Preg, oldPval | 1 << 28);
342 nvWriteMC(dev, Preg, Pval & ~(4 << 28));
343 if (mpll) {
344 Pval |= 8 << 20;
345 nvWriteMC(dev, 0x4020, Pval & ~(0xc << 28));
346 nvWriteMC(dev, 0x4038, Pval & ~(0xc << 28));
349 savedc040 = nvReadMC(dev, 0xc040);
350 nvWriteMC(dev, 0xc040, savedc040 & maskc040);
352 nvWriteMC(dev, NMNMreg, NMNM);
353 if (NMNMreg == 0x4024)
354 nvWriteMC(dev, 0x403c, NMNM);
356 nvWriteMC(dev, Preg, Pval);
357 if (mpll) {
358 Pval &= ~(8 << 20);
359 nvWriteMC(dev, 0x4020, Pval);
360 nvWriteMC(dev, 0x4038, Pval);
361 nvWriteMC(dev, 0x4600, saved4600);
364 nvWriteMC(dev, 0xc040, savedc040);
366 if (mpll) {
367 nvWriteMC(dev, 0x4020, Pval & ~(1 << 28));
368 nvWriteMC(dev, 0x4038, Pval & ~(1 << 28));
372 void
373 nouveau_hw_setpll(struct drm_device *dev, uint32_t reg1,
374 struct nouveau_pll_vals *pv)
376 struct drm_nouveau_private *dev_priv = dev->dev_private;
377 int cv = dev_priv->vbios.chip_version;
379 if (cv == 0x30 || cv == 0x31 || cv == 0x35 || cv == 0x36 ||
380 cv >= 0x40) {
381 if (reg1 > 0x405c)
382 setPLL_double_highregs(dev, reg1, pv);
383 else
384 setPLL_double_lowregs(dev, reg1, pv);
385 } else
386 setPLL_single(dev, reg1, pv);
390 * PLL getting
393 static void
394 nouveau_hw_decode_pll(struct drm_device *dev, uint32_t reg1, uint32_t pll1,
395 uint32_t pll2, struct nouveau_pll_vals *pllvals)
397 struct drm_nouveau_private *dev_priv = dev->dev_private;
399 /* to force parsing as single stage (i.e. nv40 vplls) pass pll2 as 0 */
401 /* log2P is & 0x7 as never more than 7, and nv30/35 only uses 3 bits */
402 pllvals->log2P = (pll1 >> 16) & 0x7;
403 pllvals->N2 = pllvals->M2 = 1;
405 if (reg1 <= 0x405c) {
406 pllvals->NM1 = pll2 & 0xffff;
407 /* single stage NVPLL and VPLLs use 1 << 8, MPLL uses 1 << 12 */
408 if (!(pll1 & 0x1100))
409 pllvals->NM2 = pll2 >> 16;
410 } else {
411 pllvals->NM1 = pll1 & 0xffff;
412 if (nv_two_reg_pll(dev) && pll2 & NV31_RAMDAC_ENABLE_VCO2)
413 pllvals->NM2 = pll2 & 0xffff;
414 else if (dev_priv->chipset == 0x30 || dev_priv->chipset == 0x35) {
415 pllvals->M1 &= 0xf; /* only 4 bits */
416 if (pll1 & NV30_RAMDAC_ENABLE_VCO2) {
417 pllvals->M2 = (pll1 >> 4) & 0x7;
418 pllvals->N2 = ((pll1 >> 21) & 0x18) |
419 ((pll1 >> 19) & 0x7);
426 nouveau_hw_get_pllvals(struct drm_device *dev, enum pll_types plltype,
427 struct nouveau_pll_vals *pllvals)
429 struct drm_nouveau_private *dev_priv = dev->dev_private;
430 uint32_t reg1 = get_pll_register(dev, plltype), pll1, pll2 = 0;
431 struct pll_lims pll_lim;
432 int ret;
434 if (reg1 == 0)
435 return -ENOENT;
437 pll1 = nvReadMC(dev, reg1);
439 if (reg1 <= 0x405c)
440 pll2 = nvReadMC(dev, reg1 + 4);
441 else if (nv_two_reg_pll(dev)) {
442 uint32_t reg2 = reg1 + (reg1 == NV_RAMDAC_VPLL2 ? 0x5c : 0x70);
444 pll2 = nvReadMC(dev, reg2);
447 if (dev_priv->card_type == 0x40 && reg1 >= NV_PRAMDAC_VPLL_COEFF) {
448 uint32_t ramdac580 = NVReadRAMDAC(dev, 0, NV_PRAMDAC_580);
450 /* check whether vpll has been forced into single stage mode */
451 if (reg1 == NV_PRAMDAC_VPLL_COEFF) {
452 if (ramdac580 & NV_RAMDAC_580_VPLL1_ACTIVE)
453 pll2 = 0;
454 } else
455 if (ramdac580 & NV_RAMDAC_580_VPLL2_ACTIVE)
456 pll2 = 0;
459 nouveau_hw_decode_pll(dev, reg1, pll1, pll2, pllvals);
461 ret = get_pll_limits(dev, plltype, &pll_lim);
462 if (ret)
463 return ret;
465 pllvals->refclk = pll_lim.refclk;
467 return 0;
471 nouveau_hw_pllvals_to_clk(struct nouveau_pll_vals *pv)
473 /* Avoid divide by zero if called at an inappropriate time */
474 if (!pv->M1 || !pv->M2)
475 return 0;
477 return pv->N1 * pv->N2 * pv->refclk / (pv->M1 * pv->M2) >> pv->log2P;
481 nouveau_hw_get_clock(struct drm_device *dev, enum pll_types plltype)
483 struct nouveau_pll_vals pllvals;
484 int ret;
486 if (plltype == PLL_MEMORY &&
487 (dev->pci_device & 0x0ff0) == CHIPSET_NFORCE) {
488 uint32_t mpllP;
490 pci_read_config_dword(pci_get_bus_and_slot(0, 3), 0x6c, &mpllP);
491 if (!mpllP)
492 mpllP = 4;
494 return 400000 / mpllP;
495 } else
496 if (plltype == PLL_MEMORY &&
497 (dev->pci_device & 0xff0) == CHIPSET_NFORCE2) {
498 uint32_t clock;
500 pci_read_config_dword(pci_get_bus_and_slot(0, 5), 0x4c, &clock);
501 return clock;
504 ret = nouveau_hw_get_pllvals(dev, plltype, &pllvals);
505 if (ret)
506 return ret;
508 return nouveau_hw_pllvals_to_clk(&pllvals);
511 static void
512 nouveau_hw_fix_bad_vpll(struct drm_device *dev, int head)
514 /* the vpll on an unused head can come up with a random value, way
515 * beyond the pll limits. for some reason this causes the chip to
516 * lock up when reading the dac palette regs, so set a valid pll here
517 * when such a condition detected. only seen on nv11 to date
520 struct pll_lims pll_lim;
521 struct nouveau_pll_vals pv;
522 enum pll_types pll = head ? PLL_VPLL1 : PLL_VPLL0;
524 if (get_pll_limits(dev, pll, &pll_lim))
525 return;
526 nouveau_hw_get_pllvals(dev, pll, &pv);
528 if (pv.M1 >= pll_lim.vco1.min_m && pv.M1 <= pll_lim.vco1.max_m &&
529 pv.N1 >= pll_lim.vco1.min_n && pv.N1 <= pll_lim.vco1.max_n &&
530 pv.log2P <= pll_lim.max_log2p)
531 return;
533 NV_WARN(dev, "VPLL %d outwith limits, attempting to fix\n", head + 1);
535 /* set lowest clock within static limits */
536 pv.M1 = pll_lim.vco1.max_m;
537 pv.N1 = pll_lim.vco1.min_n;
538 pv.log2P = pll_lim.max_usable_log2p;
539 nouveau_hw_setpll(dev, pll_lim.reg, &pv);
543 * vga font save/restore
546 static void nouveau_vga_font_io(struct drm_device *dev,
547 void __iomem *iovram,
548 bool save, unsigned plane)
550 struct drm_nouveau_private *dev_priv = dev->dev_private;
551 unsigned i;
553 NVWriteVgaSeq(dev, 0, NV_VIO_SR_PLANE_MASK_INDEX, 1 << plane);
554 NVWriteVgaGr(dev, 0, NV_VIO_GX_READ_MAP_INDEX, plane);
555 for (i = 0; i < 16384; i++) {
556 if (save) {
557 dev_priv->saved_vga_font[plane][i] =
558 ioread32_native(iovram + i * 4);
559 } else {
560 iowrite32_native(dev_priv->saved_vga_font[plane][i],
561 iovram + i * 4);
566 void
567 nouveau_hw_save_vga_fonts(struct drm_device *dev, bool save)
569 uint8_t misc, gr4, gr5, gr6, seq2, seq4;
570 bool graphicsmode;
571 unsigned plane;
572 void __iomem *iovram;
574 if (nv_two_heads(dev))
575 NVSetOwner(dev, 0);
577 NVSetEnablePalette(dev, 0, true);
578 graphicsmode = NVReadVgaAttr(dev, 0, NV_CIO_AR_MODE_INDEX) & 1;
579 NVSetEnablePalette(dev, 0, false);
581 if (graphicsmode) /* graphics mode => framebuffer => no need to save */
582 return;
584 NV_INFO(dev, "%sing VGA fonts\n", save ? "Sav" : "Restor");
586 /* map first 64KiB of VRAM, holds VGA fonts etc */
587 iovram = ioremap(pci_resource_start(dev->pdev, 1), 65536);
588 if (!iovram) {
589 NV_ERROR(dev, "Failed to map VRAM, "
590 "cannot save/restore VGA fonts.\n");
591 return;
594 if (nv_two_heads(dev))
595 NVBlankScreen(dev, 1, true);
596 NVBlankScreen(dev, 0, true);
598 /* save control regs */
599 misc = NVReadPRMVIO(dev, 0, NV_PRMVIO_MISC__READ);
600 seq2 = NVReadVgaSeq(dev, 0, NV_VIO_SR_PLANE_MASK_INDEX);
601 seq4 = NVReadVgaSeq(dev, 0, NV_VIO_SR_MEM_MODE_INDEX);
602 gr4 = NVReadVgaGr(dev, 0, NV_VIO_GX_READ_MAP_INDEX);
603 gr5 = NVReadVgaGr(dev, 0, NV_VIO_GX_MODE_INDEX);
604 gr6 = NVReadVgaGr(dev, 0, NV_VIO_GX_MISC_INDEX);
606 NVWritePRMVIO(dev, 0, NV_PRMVIO_MISC__WRITE, 0x67);
607 NVWriteVgaSeq(dev, 0, NV_VIO_SR_MEM_MODE_INDEX, 0x6);
608 NVWriteVgaGr(dev, 0, NV_VIO_GX_MODE_INDEX, 0x0);
609 NVWriteVgaGr(dev, 0, NV_VIO_GX_MISC_INDEX, 0x5);
611 /* store font in planes 0..3 */
612 for (plane = 0; plane < 4; plane++)
613 nouveau_vga_font_io(dev, iovram, save, plane);
615 /* restore control regs */
616 NVWritePRMVIO(dev, 0, NV_PRMVIO_MISC__WRITE, misc);
617 NVWriteVgaGr(dev, 0, NV_VIO_GX_READ_MAP_INDEX, gr4);
618 NVWriteVgaGr(dev, 0, NV_VIO_GX_MODE_INDEX, gr5);
619 NVWriteVgaGr(dev, 0, NV_VIO_GX_MISC_INDEX, gr6);
620 NVWriteVgaSeq(dev, 0, NV_VIO_SR_PLANE_MASK_INDEX, seq2);
621 NVWriteVgaSeq(dev, 0, NV_VIO_SR_MEM_MODE_INDEX, seq4);
623 if (nv_two_heads(dev))
624 NVBlankScreen(dev, 1, false);
625 NVBlankScreen(dev, 0, false);
627 iounmap(iovram);
631 * mode state save/load
634 static void
635 rd_cio_state(struct drm_device *dev, int head,
636 struct nv04_crtc_reg *crtcstate, int index)
638 crtcstate->CRTC[index] = NVReadVgaCrtc(dev, head, index);
641 static void
642 wr_cio_state(struct drm_device *dev, int head,
643 struct nv04_crtc_reg *crtcstate, int index)
645 NVWriteVgaCrtc(dev, head, index, crtcstate->CRTC[index]);
648 static void
649 nv_save_state_ramdac(struct drm_device *dev, int head,
650 struct nv04_mode_state *state)
652 struct drm_nouveau_private *dev_priv = dev->dev_private;
653 struct nv04_crtc_reg *regp = &state->crtc_reg[head];
654 int i;
656 if (dev_priv->card_type >= NV_10)
657 regp->nv10_cursync = NVReadRAMDAC(dev, head, NV_RAMDAC_NV10_CURSYNC);
659 nouveau_hw_get_pllvals(dev, head ? PLL_VPLL1 : PLL_VPLL0, &regp->pllvals);
660 state->pllsel = NVReadRAMDAC(dev, 0, NV_PRAMDAC_PLL_COEFF_SELECT);
661 if (nv_two_heads(dev))
662 state->sel_clk = NVReadRAMDAC(dev, 0, NV_PRAMDAC_SEL_CLK);
663 if (dev_priv->chipset == 0x11)
664 regp->dither = NVReadRAMDAC(dev, head, NV_RAMDAC_DITHER_NV11);
666 regp->ramdac_gen_ctrl = NVReadRAMDAC(dev, head, NV_PRAMDAC_GENERAL_CONTROL);
668 if (nv_gf4_disp_arch(dev))
669 regp->ramdac_630 = NVReadRAMDAC(dev, head, NV_PRAMDAC_630);
670 if (dev_priv->chipset >= 0x30)
671 regp->ramdac_634 = NVReadRAMDAC(dev, head, NV_PRAMDAC_634);
673 regp->tv_setup = NVReadRAMDAC(dev, head, NV_PRAMDAC_TV_SETUP);
674 regp->tv_vtotal = NVReadRAMDAC(dev, head, NV_PRAMDAC_TV_VTOTAL);
675 regp->tv_vskew = NVReadRAMDAC(dev, head, NV_PRAMDAC_TV_VSKEW);
676 regp->tv_vsync_delay = NVReadRAMDAC(dev, head, NV_PRAMDAC_TV_VSYNC_DELAY);
677 regp->tv_htotal = NVReadRAMDAC(dev, head, NV_PRAMDAC_TV_HTOTAL);
678 regp->tv_hskew = NVReadRAMDAC(dev, head, NV_PRAMDAC_TV_HSKEW);
679 regp->tv_hsync_delay = NVReadRAMDAC(dev, head, NV_PRAMDAC_TV_HSYNC_DELAY);
680 regp->tv_hsync_delay2 = NVReadRAMDAC(dev, head, NV_PRAMDAC_TV_HSYNC_DELAY2);
682 for (i = 0; i < 7; i++) {
683 uint32_t ramdac_reg = NV_PRAMDAC_FP_VDISPLAY_END + (i * 4);
684 regp->fp_vert_regs[i] = NVReadRAMDAC(dev, head, ramdac_reg);
685 regp->fp_horiz_regs[i] = NVReadRAMDAC(dev, head, ramdac_reg + 0x20);
688 if (nv_gf4_disp_arch(dev)) {
689 regp->dither = NVReadRAMDAC(dev, head, NV_RAMDAC_FP_DITHER);
690 for (i = 0; i < 3; i++) {
691 regp->dither_regs[i] = NVReadRAMDAC(dev, head, NV_PRAMDAC_850 + i * 4);
692 regp->dither_regs[i + 3] = NVReadRAMDAC(dev, head, NV_PRAMDAC_85C + i * 4);
696 regp->fp_control = NVReadRAMDAC(dev, head, NV_PRAMDAC_FP_TG_CONTROL);
697 regp->fp_debug_0 = NVReadRAMDAC(dev, head, NV_PRAMDAC_FP_DEBUG_0);
698 if (!nv_gf4_disp_arch(dev) && head == 0) {
699 /* early chips don't allow access to PRAMDAC_TMDS_* without
700 * the head A FPCLK on (nv11 even locks up) */
701 NVWriteRAMDAC(dev, 0, NV_PRAMDAC_FP_DEBUG_0, regp->fp_debug_0 &
702 ~NV_PRAMDAC_FP_DEBUG_0_PWRDOWN_FPCLK);
704 regp->fp_debug_1 = NVReadRAMDAC(dev, head, NV_PRAMDAC_FP_DEBUG_1);
705 regp->fp_debug_2 = NVReadRAMDAC(dev, head, NV_PRAMDAC_FP_DEBUG_2);
707 regp->fp_margin_color = NVReadRAMDAC(dev, head, NV_PRAMDAC_FP_MARGIN_COLOR);
709 if (nv_gf4_disp_arch(dev))
710 regp->ramdac_8c0 = NVReadRAMDAC(dev, head, NV_PRAMDAC_8C0);
712 if (dev_priv->card_type == NV_40) {
713 regp->ramdac_a20 = NVReadRAMDAC(dev, head, NV_PRAMDAC_A20);
714 regp->ramdac_a24 = NVReadRAMDAC(dev, head, NV_PRAMDAC_A24);
715 regp->ramdac_a34 = NVReadRAMDAC(dev, head, NV_PRAMDAC_A34);
717 for (i = 0; i < 38; i++)
718 regp->ctv_regs[i] = NVReadRAMDAC(dev, head,
719 NV_PRAMDAC_CTV + 4*i);
723 static void
724 nv_load_state_ramdac(struct drm_device *dev, int head,
725 struct nv04_mode_state *state)
727 struct drm_nouveau_private *dev_priv = dev->dev_private;
728 struct nv04_crtc_reg *regp = &state->crtc_reg[head];
729 uint32_t pllreg = head ? NV_RAMDAC_VPLL2 : NV_PRAMDAC_VPLL_COEFF;
730 int i;
732 if (dev_priv->card_type >= NV_10)
733 NVWriteRAMDAC(dev, head, NV_RAMDAC_NV10_CURSYNC, regp->nv10_cursync);
735 nouveau_hw_setpll(dev, pllreg, &regp->pllvals);
736 NVWriteRAMDAC(dev, 0, NV_PRAMDAC_PLL_COEFF_SELECT, state->pllsel);
737 if (nv_two_heads(dev))
738 NVWriteRAMDAC(dev, 0, NV_PRAMDAC_SEL_CLK, state->sel_clk);
739 if (dev_priv->chipset == 0x11)
740 NVWriteRAMDAC(dev, head, NV_RAMDAC_DITHER_NV11, regp->dither);
742 NVWriteRAMDAC(dev, head, NV_PRAMDAC_GENERAL_CONTROL, regp->ramdac_gen_ctrl);
744 if (nv_gf4_disp_arch(dev))
745 NVWriteRAMDAC(dev, head, NV_PRAMDAC_630, regp->ramdac_630);
746 if (dev_priv->chipset >= 0x30)
747 NVWriteRAMDAC(dev, head, NV_PRAMDAC_634, regp->ramdac_634);
749 NVWriteRAMDAC(dev, head, NV_PRAMDAC_TV_SETUP, regp->tv_setup);
750 NVWriteRAMDAC(dev, head, NV_PRAMDAC_TV_VTOTAL, regp->tv_vtotal);
751 NVWriteRAMDAC(dev, head, NV_PRAMDAC_TV_VSKEW, regp->tv_vskew);
752 NVWriteRAMDAC(dev, head, NV_PRAMDAC_TV_VSYNC_DELAY, regp->tv_vsync_delay);
753 NVWriteRAMDAC(dev, head, NV_PRAMDAC_TV_HTOTAL, regp->tv_htotal);
754 NVWriteRAMDAC(dev, head, NV_PRAMDAC_TV_HSKEW, regp->tv_hskew);
755 NVWriteRAMDAC(dev, head, NV_PRAMDAC_TV_HSYNC_DELAY, regp->tv_hsync_delay);
756 NVWriteRAMDAC(dev, head, NV_PRAMDAC_TV_HSYNC_DELAY2, regp->tv_hsync_delay2);
758 for (i = 0; i < 7; i++) {
759 uint32_t ramdac_reg = NV_PRAMDAC_FP_VDISPLAY_END + (i * 4);
761 NVWriteRAMDAC(dev, head, ramdac_reg, regp->fp_vert_regs[i]);
762 NVWriteRAMDAC(dev, head, ramdac_reg + 0x20, regp->fp_horiz_regs[i]);
765 if (nv_gf4_disp_arch(dev)) {
766 NVWriteRAMDAC(dev, head, NV_RAMDAC_FP_DITHER, regp->dither);
767 for (i = 0; i < 3; i++) {
768 NVWriteRAMDAC(dev, head, NV_PRAMDAC_850 + i * 4, regp->dither_regs[i]);
769 NVWriteRAMDAC(dev, head, NV_PRAMDAC_85C + i * 4, regp->dither_regs[i + 3]);
773 NVWriteRAMDAC(dev, head, NV_PRAMDAC_FP_TG_CONTROL, regp->fp_control);
774 NVWriteRAMDAC(dev, head, NV_PRAMDAC_FP_DEBUG_0, regp->fp_debug_0);
775 NVWriteRAMDAC(dev, head, NV_PRAMDAC_FP_DEBUG_1, regp->fp_debug_1);
776 NVWriteRAMDAC(dev, head, NV_PRAMDAC_FP_DEBUG_2, regp->fp_debug_2);
778 NVWriteRAMDAC(dev, head, NV_PRAMDAC_FP_MARGIN_COLOR, regp->fp_margin_color);
780 if (nv_gf4_disp_arch(dev))
781 NVWriteRAMDAC(dev, head, NV_PRAMDAC_8C0, regp->ramdac_8c0);
783 if (dev_priv->card_type == NV_40) {
784 NVWriteRAMDAC(dev, head, NV_PRAMDAC_A20, regp->ramdac_a20);
785 NVWriteRAMDAC(dev, head, NV_PRAMDAC_A24, regp->ramdac_a24);
786 NVWriteRAMDAC(dev, head, NV_PRAMDAC_A34, regp->ramdac_a34);
788 for (i = 0; i < 38; i++)
789 NVWriteRAMDAC(dev, head,
790 NV_PRAMDAC_CTV + 4*i, regp->ctv_regs[i]);
794 static void
795 nv_save_state_vga(struct drm_device *dev, int head,
796 struct nv04_mode_state *state)
798 struct nv04_crtc_reg *regp = &state->crtc_reg[head];
799 int i;
801 regp->MiscOutReg = NVReadPRMVIO(dev, head, NV_PRMVIO_MISC__READ);
803 for (i = 0; i < 25; i++)
804 rd_cio_state(dev, head, regp, i);
806 NVSetEnablePalette(dev, head, true);
807 for (i = 0; i < 21; i++)
808 regp->Attribute[i] = NVReadVgaAttr(dev, head, i);
809 NVSetEnablePalette(dev, head, false);
811 for (i = 0; i < 9; i++)
812 regp->Graphics[i] = NVReadVgaGr(dev, head, i);
814 for (i = 0; i < 5; i++)
815 regp->Sequencer[i] = NVReadVgaSeq(dev, head, i);
818 static void
819 nv_load_state_vga(struct drm_device *dev, int head,
820 struct nv04_mode_state *state)
822 struct nv04_crtc_reg *regp = &state->crtc_reg[head];
823 int i;
825 NVWritePRMVIO(dev, head, NV_PRMVIO_MISC__WRITE, regp->MiscOutReg);
827 for (i = 0; i < 5; i++)
828 NVWriteVgaSeq(dev, head, i, regp->Sequencer[i]);
830 nv_lock_vga_crtc_base(dev, head, false);
831 for (i = 0; i < 25; i++)
832 wr_cio_state(dev, head, regp, i);
833 nv_lock_vga_crtc_base(dev, head, true);
835 for (i = 0; i < 9; i++)
836 NVWriteVgaGr(dev, head, i, regp->Graphics[i]);
838 NVSetEnablePalette(dev, head, true);
839 for (i = 0; i < 21; i++)
840 NVWriteVgaAttr(dev, head, i, regp->Attribute[i]);
841 NVSetEnablePalette(dev, head, false);
844 static void
845 nv_save_state_ext(struct drm_device *dev, int head,
846 struct nv04_mode_state *state)
848 struct drm_nouveau_private *dev_priv = dev->dev_private;
849 struct nv04_crtc_reg *regp = &state->crtc_reg[head];
850 int i;
852 rd_cio_state(dev, head, regp, NV_CIO_CRE_LCD__INDEX);
853 rd_cio_state(dev, head, regp, NV_CIO_CRE_RPC0_INDEX);
854 rd_cio_state(dev, head, regp, NV_CIO_CRE_RPC1_INDEX);
855 rd_cio_state(dev, head, regp, NV_CIO_CRE_LSR_INDEX);
856 rd_cio_state(dev, head, regp, NV_CIO_CRE_PIXEL_INDEX);
857 rd_cio_state(dev, head, regp, NV_CIO_CRE_HEB__INDEX);
858 rd_cio_state(dev, head, regp, NV_CIO_CRE_ENH_INDEX);
860 rd_cio_state(dev, head, regp, NV_CIO_CRE_FF_INDEX);
861 rd_cio_state(dev, head, regp, NV_CIO_CRE_FFLWM__INDEX);
862 rd_cio_state(dev, head, regp, NV_CIO_CRE_21);
864 if (dev_priv->card_type >= NV_20)
865 rd_cio_state(dev, head, regp, NV_CIO_CRE_47);
867 if (dev_priv->card_type >= NV_30)
868 rd_cio_state(dev, head, regp, 0x9f);
870 rd_cio_state(dev, head, regp, NV_CIO_CRE_49);
871 rd_cio_state(dev, head, regp, NV_CIO_CRE_HCUR_ADDR0_INDEX);
872 rd_cio_state(dev, head, regp, NV_CIO_CRE_HCUR_ADDR1_INDEX);
873 rd_cio_state(dev, head, regp, NV_CIO_CRE_HCUR_ADDR2_INDEX);
874 rd_cio_state(dev, head, regp, NV_CIO_CRE_ILACE__INDEX);
876 if (dev_priv->card_type >= NV_10) {
877 regp->crtc_830 = NVReadCRTC(dev, head, NV_PCRTC_830);
878 regp->crtc_834 = NVReadCRTC(dev, head, NV_PCRTC_834);
880 if (dev_priv->card_type >= NV_30)
881 regp->gpio_ext = NVReadCRTC(dev, head, NV_PCRTC_GPIO_EXT);
883 if (dev_priv->card_type == NV_40)
884 regp->crtc_850 = NVReadCRTC(dev, head, NV_PCRTC_850);
886 if (nv_two_heads(dev))
887 regp->crtc_eng_ctrl = NVReadCRTC(dev, head, NV_PCRTC_ENGINE_CTRL);
888 regp->cursor_cfg = NVReadCRTC(dev, head, NV_PCRTC_CURSOR_CONFIG);
891 regp->crtc_cfg = NVReadCRTC(dev, head, NV_PCRTC_CONFIG);
893 rd_cio_state(dev, head, regp, NV_CIO_CRE_SCRATCH3__INDEX);
894 rd_cio_state(dev, head, regp, NV_CIO_CRE_SCRATCH4__INDEX);
895 if (dev_priv->card_type >= NV_10) {
896 rd_cio_state(dev, head, regp, NV_CIO_CRE_EBR_INDEX);
897 rd_cio_state(dev, head, regp, NV_CIO_CRE_CSB);
898 rd_cio_state(dev, head, regp, NV_CIO_CRE_4B);
899 rd_cio_state(dev, head, regp, NV_CIO_CRE_TVOUT_LATENCY);
901 /* NV11 and NV20 don't have this, they stop at 0x52. */
902 if (nv_gf4_disp_arch(dev)) {
903 rd_cio_state(dev, head, regp, NV_CIO_CRE_53);
904 rd_cio_state(dev, head, regp, NV_CIO_CRE_54);
906 for (i = 0; i < 0x10; i++)
907 regp->CR58[i] = NVReadVgaCrtc5758(dev, head, i);
908 rd_cio_state(dev, head, regp, NV_CIO_CRE_59);
909 rd_cio_state(dev, head, regp, NV_CIO_CRE_5B);
911 rd_cio_state(dev, head, regp, NV_CIO_CRE_85);
912 rd_cio_state(dev, head, regp, NV_CIO_CRE_86);
915 regp->fb_start = NVReadCRTC(dev, head, NV_PCRTC_START);
918 static void
919 nv_load_state_ext(struct drm_device *dev, int head,
920 struct nv04_mode_state *state)
922 struct drm_nouveau_private *dev_priv = dev->dev_private;
923 struct nv04_crtc_reg *regp = &state->crtc_reg[head];
924 uint32_t reg900;
925 int i;
927 if (dev_priv->card_type >= NV_10) {
928 if (nv_two_heads(dev))
929 /* setting ENGINE_CTRL (EC) *must* come before
930 * CIO_CRE_LCD, as writing CRE_LCD sets bits 16 & 17 in
931 * EC that should not be overwritten by writing stale EC
933 NVWriteCRTC(dev, head, NV_PCRTC_ENGINE_CTRL, regp->crtc_eng_ctrl);
935 nvWriteVIDEO(dev, NV_PVIDEO_STOP, 1);
936 nvWriteVIDEO(dev, NV_PVIDEO_INTR_EN, 0);
937 nvWriteVIDEO(dev, NV_PVIDEO_OFFSET_BUFF(0), 0);
938 nvWriteVIDEO(dev, NV_PVIDEO_OFFSET_BUFF(1), 0);
939 nvWriteVIDEO(dev, NV_PVIDEO_LIMIT(0), dev_priv->fb_available_size - 1);
940 nvWriteVIDEO(dev, NV_PVIDEO_LIMIT(1), dev_priv->fb_available_size - 1);
941 nvWriteVIDEO(dev, NV_PVIDEO_UVPLANE_LIMIT(0), dev_priv->fb_available_size - 1);
942 nvWriteVIDEO(dev, NV_PVIDEO_UVPLANE_LIMIT(1), dev_priv->fb_available_size - 1);
943 nvWriteMC(dev, NV_PBUS_POWERCTRL_2, 0);
945 NVWriteCRTC(dev, head, NV_PCRTC_CURSOR_CONFIG, regp->cursor_cfg);
946 NVWriteCRTC(dev, head, NV_PCRTC_830, regp->crtc_830);
947 NVWriteCRTC(dev, head, NV_PCRTC_834, regp->crtc_834);
949 if (dev_priv->card_type >= NV_30)
950 NVWriteCRTC(dev, head, NV_PCRTC_GPIO_EXT, regp->gpio_ext);
952 if (dev_priv->card_type == NV_40) {
953 NVWriteCRTC(dev, head, NV_PCRTC_850, regp->crtc_850);
955 reg900 = NVReadRAMDAC(dev, head, NV_PRAMDAC_900);
956 if (regp->crtc_cfg == NV10_PCRTC_CONFIG_START_ADDRESS_HSYNC)
957 NVWriteRAMDAC(dev, head, NV_PRAMDAC_900, reg900 | 0x10000);
958 else
959 NVWriteRAMDAC(dev, head, NV_PRAMDAC_900, reg900 & ~0x10000);
963 NVWriteCRTC(dev, head, NV_PCRTC_CONFIG, regp->crtc_cfg);
965 wr_cio_state(dev, head, regp, NV_CIO_CRE_RPC0_INDEX);
966 wr_cio_state(dev, head, regp, NV_CIO_CRE_RPC1_INDEX);
967 wr_cio_state(dev, head, regp, NV_CIO_CRE_LSR_INDEX);
968 wr_cio_state(dev, head, regp, NV_CIO_CRE_PIXEL_INDEX);
969 wr_cio_state(dev, head, regp, NV_CIO_CRE_LCD__INDEX);
970 wr_cio_state(dev, head, regp, NV_CIO_CRE_HEB__INDEX);
971 wr_cio_state(dev, head, regp, NV_CIO_CRE_ENH_INDEX);
972 wr_cio_state(dev, head, regp, NV_CIO_CRE_FF_INDEX);
973 wr_cio_state(dev, head, regp, NV_CIO_CRE_FFLWM__INDEX);
975 if (dev_priv->card_type >= NV_20)
976 wr_cio_state(dev, head, regp, NV_CIO_CRE_47);
978 if (dev_priv->card_type >= NV_30)
979 wr_cio_state(dev, head, regp, 0x9f);
981 wr_cio_state(dev, head, regp, NV_CIO_CRE_49);
982 wr_cio_state(dev, head, regp, NV_CIO_CRE_HCUR_ADDR0_INDEX);
983 wr_cio_state(dev, head, regp, NV_CIO_CRE_HCUR_ADDR1_INDEX);
984 wr_cio_state(dev, head, regp, NV_CIO_CRE_HCUR_ADDR2_INDEX);
985 if (dev_priv->card_type == NV_40)
986 nv_fix_nv40_hw_cursor(dev, head);
987 wr_cio_state(dev, head, regp, NV_CIO_CRE_ILACE__INDEX);
989 wr_cio_state(dev, head, regp, NV_CIO_CRE_SCRATCH3__INDEX);
990 wr_cio_state(dev, head, regp, NV_CIO_CRE_SCRATCH4__INDEX);
991 if (dev_priv->card_type >= NV_10) {
992 wr_cio_state(dev, head, regp, NV_CIO_CRE_EBR_INDEX);
993 wr_cio_state(dev, head, regp, NV_CIO_CRE_CSB);
994 wr_cio_state(dev, head, regp, NV_CIO_CRE_4B);
995 wr_cio_state(dev, head, regp, NV_CIO_CRE_TVOUT_LATENCY);
997 /* NV11 and NV20 stop at 0x52. */
998 if (nv_gf4_disp_arch(dev)) {
999 if (dev_priv->card_type == NV_10) {
1000 /* Not waiting for vertical retrace before modifying
1001 CRE_53/CRE_54 causes lockups. */
1002 nouveau_wait_eq(dev, 650000000, NV_PRMCIO_INP0__COLOR, 0x8, 0x8);
1003 nouveau_wait_eq(dev, 650000000, NV_PRMCIO_INP0__COLOR, 0x8, 0x0);
1006 wr_cio_state(dev, head, regp, NV_CIO_CRE_53);
1007 wr_cio_state(dev, head, regp, NV_CIO_CRE_54);
1009 for (i = 0; i < 0x10; i++)
1010 NVWriteVgaCrtc5758(dev, head, i, regp->CR58[i]);
1011 wr_cio_state(dev, head, regp, NV_CIO_CRE_59);
1012 wr_cio_state(dev, head, regp, NV_CIO_CRE_5B);
1014 wr_cio_state(dev, head, regp, NV_CIO_CRE_85);
1015 wr_cio_state(dev, head, regp, NV_CIO_CRE_86);
1018 NVWriteCRTC(dev, head, NV_PCRTC_START, regp->fb_start);
1020 /* Enable vblank interrupts. */
1021 NVWriteCRTC(dev, head, NV_PCRTC_INTR_EN_0,
1022 (dev->vblank_enabled[head] ? 1 : 0));
1023 NVWriteCRTC(dev, head, NV_PCRTC_INTR_0, NV_PCRTC_INTR_0_VBLANK);
1026 static void
1027 nv_save_state_palette(struct drm_device *dev, int head,
1028 struct nv04_mode_state *state)
1030 int head_offset = head * NV_PRMDIO_SIZE, i;
1032 nv_wr08(dev, NV_PRMDIO_PIXEL_MASK + head_offset,
1033 NV_PRMDIO_PIXEL_MASK_MASK);
1034 nv_wr08(dev, NV_PRMDIO_READ_MODE_ADDRESS + head_offset, 0x0);
1036 for (i = 0; i < 768; i++) {
1037 state->crtc_reg[head].DAC[i] = nv_rd08(dev,
1038 NV_PRMDIO_PALETTE_DATA + head_offset);
1041 NVSetEnablePalette(dev, head, false);
1044 void
1045 nouveau_hw_load_state_palette(struct drm_device *dev, int head,
1046 struct nv04_mode_state *state)
1048 int head_offset = head * NV_PRMDIO_SIZE, i;
1050 nv_wr08(dev, NV_PRMDIO_PIXEL_MASK + head_offset,
1051 NV_PRMDIO_PIXEL_MASK_MASK);
1052 nv_wr08(dev, NV_PRMDIO_WRITE_MODE_ADDRESS + head_offset, 0x0);
1054 for (i = 0; i < 768; i++) {
1055 nv_wr08(dev, NV_PRMDIO_PALETTE_DATA + head_offset,
1056 state->crtc_reg[head].DAC[i]);
1059 NVSetEnablePalette(dev, head, false);
1062 void nouveau_hw_save_state(struct drm_device *dev, int head,
1063 struct nv04_mode_state *state)
1065 struct drm_nouveau_private *dev_priv = dev->dev_private;
1067 if (dev_priv->chipset == 0x11)
1068 /* NB: no attempt is made to restore the bad pll later on */
1069 nouveau_hw_fix_bad_vpll(dev, head);
1070 nv_save_state_ramdac(dev, head, state);
1071 nv_save_state_vga(dev, head, state);
1072 nv_save_state_palette(dev, head, state);
1073 nv_save_state_ext(dev, head, state);
1076 void nouveau_hw_load_state(struct drm_device *dev, int head,
1077 struct nv04_mode_state *state)
1079 NVVgaProtect(dev, head, true);
1080 nv_load_state_ramdac(dev, head, state);
1081 nv_load_state_ext(dev, head, state);
1082 nouveau_hw_load_state_palette(dev, head, state);
1083 nv_load_state_vga(dev, head, state);
1084 NVVgaProtect(dev, head, false);