61 switch (nv_device(drm->
device)->chipset) {
67 return nv_rd32(device, 0x004700);
71 return nv_rd32(device, 0x004800);
83 u32 rsel = nv_rd32(device, 0x00e18c);
86 switch (nv_device(drm->
device)->chipset) {
91 case 0x4028:
id = !!(rsel & 0x00000004);
break;
92 case 0x4008:
id = !!(rsel & 0x00000008);
break;
93 case 0x4030:
id = 0;
break;
95 NV_ERROR(drm,
"ref: bad pll 0x%06x\n", base);
99 coef = nv_rd32(device, 0x00e81c + (
id * 0x0c));
100 ref *= (coef & 0x01000000) ? 2 : 4;
101 P = (coef & 0x00070000) >> 16;
102 N = ((coef & 0x0000ff00) >> 8) + 1;
103 M = ((coef & 0x000000ff) >> 0) + 1;
108 coef = nv_rd32(device, 0x00e81c);
109 P = (coef & 0x00070000) >> 16;
110 N = (coef & 0x0000ff00) >> 8;
111 M = (coef & 0x000000ff) >> 0;
116 rsel = nv_rd32(device, 0x00c050);
118 case 0x4020: rsel = (rsel & 0x00000003) >> 0;
break;
119 case 0x4008: rsel = (rsel & 0x0000000c) >> 2;
break;
120 case 0x4028: rsel = (rsel & 0x00001800) >> 11;
break;
121 case 0x4030: rsel = 3;
break;
123 NV_ERROR(drm,
"ref: bad pll 0x%06x\n", base);
128 case 0:
id = 1;
break;
131 case 3:
id = 0;
break;
134 coef = nv_rd32(device, 0x00e81c + (
id * 0x28));
135 P = (nv_rd32(device, 0x00e824 + (
id * 0x28)) >> 16) & 7;
136 P += (coef & 0x00070000) >> 16;
137 N = (coef & 0x0000ff00) >> 8;
138 M = (coef & 0x000000ff) >> 0;
145 return (ref * N / M) >>
P;
154 u32 src, mast = nv_rd32(device, 0x00c040);
158 src = !!(mast & 0x00200000);
161 src = !!(mast & 0x00400000);
164 src = !!(mast & 0x00010000);
167 src = !!(mast & 0x02000000);
172 NV_ERROR(drm,
"bad pll 0x%06x\n", base);
178 return read_pll_src(dev, base);
186 u32 mast = nv_rd32(device, 0x00c040);
187 u32 ctrl = nv_rd32(device, base + 0);
188 u32 coef = nv_rd32(device, base + 4);
189 u32 ref = read_pll_ref(dev, base);
193 if (base == 0x004028 && (mast & 0x00100000)) {
195 if (nv_device(drm->
device)->chipset != 0xa0)
199 N2 = (coef & 0xff000000) >> 24;
200 M2 = (coef & 0x00ff0000) >> 16;
201 N1 = (coef & 0x0000ff00) >> 8;
202 M1 = (coef & 0x000000ff);
203 if ((ctrl & 0x80000000) && M1) {
205 if ((ctrl & 0x40000100) == 0x40000000) {
221 u32 mast = nv_rd32(device, 0x00c040);
236 switch (mast & 0x30000000) {
238 case 0x10000000:
break;
244 if (!(mast & 0x00100000))
245 P = (nv_rd32(device, 0x004028) & 0x00070000) >> 16;
246 switch (mast & 0x00000003) {
249 case 0x00000002:
return read_pll(dev, 0x004020) >>
P;
250 case 0x00000003:
return read_pll(dev, 0x004028) >>
P;
254 P = (nv_rd32(device, 0x004020) & 0x00070000) >> 16;
255 switch (mast & 0x00000030) {
257 if (mast & 0x00000080)
260 case 0x00000010:
break;
261 case 0x00000020:
return read_pll(dev, 0x004028) >>
P;
262 case 0x00000030:
return read_pll(dev, 0x004020) >>
P;
266 P = (nv_rd32(device, 0x004008) & 0x00070000) >> 16;
267 if (nv_rd32(device, 0x004008) & 0x00000200) {
268 switch (mast & 0x0000c000) {
276 return read_pll(dev, 0x004008) >>
P;
280 P = (read_div(dev) & 0x00000700) >> 8;
281 switch (nv_device(drm->
device)->chipset) {
288 switch (mast & 0x00000c00) {
290 if (nv_device(drm->
device)->chipset == 0xa0)
296 if (mast & 0x01000000)
297 return read_pll(dev, 0x004028) >>
P;
298 return read_pll(dev, 0x004030) >>
P;
304 switch (mast & 0x00000c00) {
318 switch (nv_device(drm->
device)->chipset) {
321 return read_pll(dev, 0x00e810) >> 2;
328 P = (read_div(dev) & 0x00000007) >> 0;
329 switch (mast & 0x0c000000) {
331 case 0x04000000:
break;
344 NV_DEBUG(drm,
"unknown clock source %d 0x%08x\n", src, mast);
352 if (nv_device(drm->
device)->chipset == 0xaa ||
353 nv_device(drm->
device)->chipset == 0xac)
359 if (nv_device(drm->
device)->chipset != 0x50) {
379 u32 clk,
int *N1,
int *M1,
int *log2P)
391 pll->
vco2.max_freq = 0;
392 pll->
refclk = read_pll_ref(dev, reg);
396 ret = pclk->
pll_calc(pclk, pll, clk, &coef);
410 for (*div = 0; *div <= 7; (*div)++) {
411 if (clk0 <= target) {
412 clk1 = clk0 << (*div ? 1 : 0);
418 if (target - clk0 <= clk1 - target)
427 return ((a / 1000) == (b / 1000));
436 hwsq_wr32(hwsq, 0x1002d4, 0x00000001);
445 hwsq_wr32(hwsq, 0x1002d0, 0x00000001);
454 hwsq_wr32(hwsq, 0x100210, enable ? 0x80000000 : 0x00000000);
463 hwsq_wr32(hwsq, 0x1002dc, enable ? 0x00000001 : 0x00000000);
473 hwsq_usec(hwsq, (nsec + 500) / 1000);
481 return nv_rd32(device, 0x1002c0 + ((mr - 0) * 4));
483 return nv_rd32(device, 0x1002e0 + ((mr - 2) * 4));
496 if (pfb->
ram.ranks > 1)
497 hwsq_wr32(hwsq, 0x1002c8 + ((mr - 0) * 4), data);
498 hwsq_wr32(hwsq, 0x1002c0 + ((mr - 0) * 4), data);
501 if (pfb->
ram.ranks > 1)
502 hwsq_wr32(hwsq, 0x1002e8 + ((mr - 2) * 4), data);
503 hwsq_wr32(hwsq, 0x1002e0 + ((mr - 2) * 4), data);
513 u32 ctrl = nv_rd32(device, 0x004008);
515 info->
mmast = nv_rd32(device, 0x00c040);
516 info->
mmast &= ~0xc0000000;
517 info->
mmast |= 0x0000c000;
519 hwsq_wr32(hwsq, 0xc040, info->
mmast);
520 hwsq_wr32(hwsq, 0x4008, ctrl | 0x00000200);
521 if (info->
mctrl & 0x80000000)
522 hwsq_wr32(hwsq, 0x400c, info->
mcoef);
523 hwsq_wr32(hwsq, 0x4008, info->
mctrl);
535 for (i = 0; i < 9; i++) {
536 u32 reg = 0x100220 + (i * 4);
537 u32 val = nv_rd32(device, reg);
538 if (val != perflvl->
timing.reg[i])
539 hwsq_wr32(hwsq, reg, perflvl->
timing.reg[i]);
552 .precharge = mclk_precharge,
553 .refresh = mclk_refresh,
554 .refresh_auto = mclk_refresh_auto,
555 .refresh_self = mclk_refresh_self,
559 .clock_set = mclk_clock_set,
560 .timing_set = mclk_timing_set,
569 info->
mctrl = nv_rd32(device, 0x004008);
570 info->
mctrl &= ~0x81ff0200;
572 info->
mctrl |= 0x00000200 | (
pll.bias_p << 19);
574 ret = calc_pll(dev, 0x4008, &
pll, perflvl->
memory, &N, &M, &P);
578 info->
mctrl |= 0x80000000 | (P << 22) | (P << 16);
580 info->
mcoef = (N << 8) | M;
586 hwsq_op5f(hwsq, crtc_mask, 0x00);
587 hwsq_op5f(hwsq, crtc_mask, 0x01);
589 if (nv_device(drm->
device)->chipset >= 0x92)
590 hwsq_wr32(hwsq, 0x611200, 0x00003300);
591 hwsq_setf(hwsq, 0x10, 0);
592 hwsq_op5f(hwsq, 0x00, 0x01);
598 hwsq_setf(hwsq, 0x10, 1);
599 hwsq_op5f(hwsq, 0x00, 0x00);
600 if (nv_device(drm->
device)->chipset >= 0x92)
601 hwsq_wr32(hwsq, 0x611200, 0x00003330);
618 if (nv_device(drm->
device)->chipset == 0xaa ||
619 nv_device(drm->
device)->chipset == 0xac)
631 ret = calc_mclk(dev, perflvl, info);
637 divs = read_div(dev);
643 hwsq_setf(hwsq, 0x10, 0);
644 hwsq_op5f(hwsq, 0x00, 0x01);
657 hwsq_wr32(hwsq, 0x00c040, mast);
665 clk = calc_div(perflvl->
core, perflvl->
vdec, &P1);
668 if (nv_device(drm->
device)->chipset != 0x98)
669 out = read_pll(dev, 0x004030);
672 out = calc_div(out, perflvl->
vdec, &P2);
675 if (
abs((
int)perflvl->
vdec - clk) <=
676 abs((
int)perflvl->
vdec - out)) {
677 if (nv_device(drm->
device)->chipset != 0x98)
697 clk = calc_div(clk, perflvl->
dom6, &P1);
705 switch (nv_device(drm->
device)->chipset) {
709 hwsq_wr32(hwsq, 0x004800, divs);
712 hwsq_wr32(hwsq, 0x004700, divs);
716 hwsq_wr32(hwsq, 0x00c040, mast);
721 if (nv_device(drm->
device)->chipset < 0x92)
722 mast = (mast & ~0x001000b0) | 0x00100080;
724 mast = (mast & ~0x000000b3) | 0x00000081;
726 hwsq_wr32(hwsq, 0x00c040, mast);
729 clk = calc_pll(dev, 0x4028, &pll, perflvl->
core, &N, &M, &P1);
733 ctrl = nv_rd32(device, 0x004028) & ~0xc03f0100;
737 hwsq_wr32(hwsq, 0x004028, 0x80000000 | (P1 << 19) | (P1 << 16) | ctrl);
738 hwsq_wr32(hwsq, 0x00402c, (N << 8) | M);
746 ctrl = nv_rd32(device, 0x004020) & ~0xc03f0100;
748 if (P1-- && perflvl->
shader == (perflvl->
core << 1)) {
749 hwsq_wr32(hwsq, 0x004020, (P1 << 19) | (P1 << 16) | ctrl);
750 hwsq_wr32(hwsq, 0x00c040, 0x00000020 | mast);
752 clk = calc_pll(dev, 0x4020, &pll, perflvl->
shader, &N, &M, &P1);
757 hwsq_wr32(hwsq, 0x004020, (P1 << 19) | (P1 << 16) | ctrl);
758 hwsq_wr32(hwsq, 0x004024, (N << 8) | M);
759 hwsq_wr32(hwsq, 0x00c040, 0x00000030 | mast);
762 hwsq_setf(hwsq, 0x10, 1);
763 hwsq_op5f(hwsq, 0x00, 0x00);
777 u32 hwsq_data, hwsq_kick;
780 if (nv_device(drm->
device)->chipset < 0x94) {
781 hwsq_data = 0x001400;
782 hwsq_kick = 0x00000003;
784 hwsq_data = 0x080000;
785 hwsq_kick = 0x00000001;
788 nv_mask(device, 0x001098, 0x00000008, 0x00000000);
789 nv_wr32(device, 0x001304, 0x00000000);
790 if (nv_device(drm->
device)->chipset >= 0x92)
791 nv_wr32(device, 0x001318, 0x00000000);
792 for (i = 0; i < hwsq->
len / 4; i++)
793 nv_wr32(device, hwsq_data + (i * 4), hwsq->
ptr.
u32[i]);
794 nv_mask(device, 0x001098, 0x00000018, 0x00000018);
797 nv_wr32(device, 0x00130c, hwsq_kick);
798 if (!
nv_wait(device, 0x001308, 0x00000100, 0x00000000)) {
799 NV_ERROR(drm,
"hwsq ucode exec timed out\n");
800 NV_ERROR(drm,
"0x001308: 0x%08x\n", nv_rd32(device, 0x001308));
801 for (i = 0; i < hwsq->
len / 4; i++) {
802 NV_ERROR(drm,
"0x%06x: 0x%08x\n", 0x1400 + (i * 4),
803 nv_rd32(device, 0x001400 + (i * 4)));
821 nv_mask(device, 0x002504, 0x00000001, 0x00000001);
822 if (!
nv_wait(device, 0x002504, 0x00000010, 0x00000010))
824 if (!
nv_wait(device, 0x00251c, 0x0000003f, 0x0000003f))
830 #define nouveau_bios_init_exec(a,b) nouveau_bios_run_init_table((a), (b), NULL, 0)
852 nv_mask(device, 0x002504, 0x00000001, 0x00000000);