2 * Copyright 2013 Red Hat Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
23 * Roy Spliet <rspliet@eclipso.eu>
29 #include <core/device.h>
30 #include <core/option.h>
31 #include <subdev/bios.h>
32 #include <subdev/bios/M0205.h>
33 #include <subdev/bios/rammap.h>
34 #include <subdev/bios/timing.h>
35 #include <subdev/clk/gt215.h>
36 #include <subdev/gpio.h>
38 /* XXX: Remove when memx gains GPIO support */
39 extern int nv50_gpio_location(int line
, u32
*reg
, u32
*shift
);
43 struct ramfuc_reg r_0x001610
;
44 struct ramfuc_reg r_0x001700
;
45 struct ramfuc_reg r_0x002504
;
46 struct ramfuc_reg r_0x004000
;
47 struct ramfuc_reg r_0x004004
;
48 struct ramfuc_reg r_0x004018
;
49 struct ramfuc_reg r_0x004128
;
50 struct ramfuc_reg r_0x004168
;
51 struct ramfuc_reg r_0x100080
;
52 struct ramfuc_reg r_0x100200
;
53 struct ramfuc_reg r_0x100210
;
54 struct ramfuc_reg r_0x100220
[9];
55 struct ramfuc_reg r_0x100264
;
56 struct ramfuc_reg r_0x1002d0
;
57 struct ramfuc_reg r_0x1002d4
;
58 struct ramfuc_reg r_0x1002dc
;
59 struct ramfuc_reg r_0x10053c
;
60 struct ramfuc_reg r_0x1005a0
;
61 struct ramfuc_reg r_0x1005a4
;
62 struct ramfuc_reg r_0x100700
;
63 struct ramfuc_reg r_0x100714
;
64 struct ramfuc_reg r_0x100718
;
65 struct ramfuc_reg r_0x10071c
;
66 struct ramfuc_reg r_0x100720
;
67 struct ramfuc_reg r_0x100760
;
68 struct ramfuc_reg r_0x1007a0
;
69 struct ramfuc_reg r_0x1007e0
;
70 struct ramfuc_reg r_0x100da0
;
71 struct ramfuc_reg r_0x10f804
;
72 struct ramfuc_reg r_0x1110e0
;
73 struct ramfuc_reg r_0x111100
;
74 struct ramfuc_reg r_0x111104
;
75 struct ramfuc_reg r_0x1111e0
;
76 struct ramfuc_reg r_0x111400
;
77 struct ramfuc_reg r_0x611200
;
78 struct ramfuc_reg r_mr
[4];
79 struct ramfuc_reg r_gpioFBVREF
;
85 NVA3_TRAIN_UNSUPPORTED
,
98 struct gt215_ramfuc fuc
;
99 struct gt215_ltrain ltrain
;
103 gt215_link_train_calc(u32
*vals
, struct gt215_ltrain
*train
)
106 u8 median
[8], bins
[4] = {0, 0, 0, 0}, bin
= 0, qty
= 0;
108 for (i
= 0; i
< 8; i
++) {
109 for (lo
= 0; lo
< 0x40; lo
++) {
110 if (!(vals
[lo
] & 0x80000000))
112 if (vals
[lo
] & (0x101 << i
))
119 for (hi
= lo
+ 1; hi
< 0x40; hi
++) {
120 if (!(vals
[lo
] & 0x80000000))
122 if (!(vals
[hi
] & (0x101 << i
))) {
128 median
[i
] = ((hi
- lo
) >> 1) + lo
;
129 bins
[(median
[i
] & 0xf0) >> 4]++;
133 /* Find the best value for 0x1111e0 */
134 for (i
= 0; i
< 4; i
++) {
142 for (i
= 0; i
< 8; i
++) {
143 median
[i
] = max(median
[i
], (u8
) (bin
<< 4));
144 median
[i
] = min(median
[i
], (u8
) ((bin
<< 4) | 0xf));
146 train
->r_100720
|= ((median
[i
] & 0x0f) << (i
<< 2));
149 train
->r_1111e0
= 0x02000000 | (bin
* 0x101);
150 train
->r_111400
= 0x0;
154 * Link training for (at least) DDR3
157 gt215_link_train(struct nvkm_fb
*pfb
)
159 struct nvkm_bios
*bios
= nvkm_bios(pfb
);
160 struct gt215_ram
*ram
= (void *)pfb
->ram
;
161 struct nvkm_clk
*clk
= nvkm_clk(pfb
);
162 struct gt215_ltrain
*train
= &ram
->ltrain
;
163 struct nvkm_device
*device
= nv_device(pfb
);
164 struct gt215_ramfuc
*fuc
= &ram
->fuc
;
167 struct nvbios_M0205T M0205T
= { 0 };
168 u8 ver
, hdr
, cnt
, len
, snr
, ssz
;
169 unsigned int clk_current
;
171 unsigned long *f
= &flags
;
173 if (nvkm_boolopt(device
->cfgopt
, "NvMemExec", true) != true)
176 /* XXX: Multiple partitions? */
177 result
= kmalloc(64 * sizeof(u32
), GFP_KERNEL
);
181 train
->state
= NVA3_TRAIN_EXEC
;
183 /* Clock speeds for training and back */
184 nvbios_M0205Tp(bios
, &ver
, &hdr
, &cnt
, &len
, &snr
, &ssz
, &M0205T
);
185 if (M0205T
.freq
== 0)
188 clk_current
= clk
->read(clk
, nv_clk_src_mem
);
190 ret
= gt215_clk_pre(clk
, f
);
194 /* First: clock up/down */
195 ret
= ram
->base
.calc(pfb
, (u32
) M0205T
.freq
* 1000);
199 /* Do this *after* calc, eliminates write in script */
200 nv_wr32(pfb
, 0x111400, 0x00000000);
201 /* XXX: Magic writes that improve train reliability? */
202 nv_mask(pfb
, 0x100674, 0x0000ffff, 0x00000000);
203 nv_mask(pfb
, 0x1005e4, 0x0000ffff, 0x00000000);
204 nv_mask(pfb
, 0x100b0c, 0x000000ff, 0x00000000);
205 nv_wr32(pfb
, 0x100c04, 0x00000400);
207 /* Now the training script */
208 r1700
= ram_rd32(fuc
, 0x001700);
210 ram_mask(fuc
, 0x100200, 0x00000800, 0x00000000);
211 ram_wr32(fuc
, 0x611200, 0x3300);
212 ram_wait_vblank(fuc
);
213 ram_wait(fuc
, 0x611200, 0x00000003, 0x00000000, 500000);
214 ram_mask(fuc
, 0x001610, 0x00000083, 0x00000003);
215 ram_mask(fuc
, 0x100080, 0x00000020, 0x00000000);
216 ram_mask(fuc
, 0x10f804, 0x80000000, 0x00000000);
217 ram_wr32(fuc
, 0x001700, 0x00000000);
222 ram_mask(fuc
, 0x10f804, 0x80000000, 0x80000000);
223 ram_wr32(fuc
, 0x10053c, 0x0);
224 ram_wr32(fuc
, 0x100720, train
->r_100720
);
225 ram_wr32(fuc
, 0x1111e0, train
->r_1111e0
);
226 ram_wr32(fuc
, 0x111400, train
->r_111400
);
227 ram_nuke(fuc
, 0x100080);
228 ram_mask(fuc
, 0x100080, 0x00000020, 0x00000020);
231 ram_wr32(fuc
, 0x001700, r1700
);
232 ram_mask(fuc
, 0x001610, 0x00000083, 0x00000080);
233 ram_wr32(fuc
, 0x611200, 0x3330);
234 ram_mask(fuc
, 0x100200, 0x00000800, 0x00000800);
238 ram
->base
.calc(pfb
, clk_current
);
241 /* Post-processing, avoids flicker */
242 nv_mask(pfb
, 0x616308, 0x10, 0x10);
243 nv_mask(pfb
, 0x616b08, 0x10, 0x10);
245 gt215_clk_post(clk
, f
);
247 ram_train_result(pfb
, result
, 64);
248 for (i
= 0; i
< 64; i
++)
249 nv_debug(pfb
, "Train: %08x", result
[i
]);
250 gt215_link_train_calc(result
, train
);
252 nv_debug(pfb
, "Train: %08x %08x %08x", train
->r_100720
,
253 train
->r_1111e0
, train
->r_111400
);
257 train
->state
= NVA3_TRAIN_DONE
;
265 train
->state
= NVA3_TRAIN_UNSUPPORTED
;
267 gt215_clk_post(clk
, f
);
272 gt215_link_train_init(struct nvkm_fb
*pfb
)
274 static const u32 pattern
[16] = {
275 0xaaaaaaaa, 0xcccccccc, 0xdddddddd, 0xeeeeeeee,
276 0x00000000, 0x11111111, 0x44444444, 0xdddddddd,
277 0x33333333, 0x55555555, 0x77777777, 0x66666666,
278 0x99999999, 0x88888888, 0xeeeeeeee, 0xbbbbbbbb,
280 struct nvkm_bios
*bios
= nvkm_bios(pfb
);
281 struct gt215_ram
*ram
= (void *)pfb
->ram
;
282 struct gt215_ltrain
*train
= &ram
->ltrain
;
283 struct nvkm_mem
*mem
;
284 struct nvbios_M0205E M0205E
;
285 u8 ver
, hdr
, cnt
, len
;
289 train
->state
= NVA3_TRAIN_UNSUPPORTED
;
291 /* We support type "5"
292 * XXX: training pattern table appears to be unused for this routine */
293 if (!nvbios_M0205Ep(bios
, i
, &ver
, &hdr
, &cnt
, &len
, &M0205E
))
296 if (M0205E
.type
!= 5)
299 train
->state
= NVA3_TRAIN_ONCE
;
301 ret
= pfb
->ram
->get(pfb
, 0x8000, 0x10000, 0, 0x800, &ram
->ltrain
.mem
);
305 mem
= ram
->ltrain
.mem
;
307 nv_wr32(pfb
, 0x100538, 0x10000000 | (mem
->offset
>> 16));
308 nv_wr32(pfb
, 0x1005a8, 0x0000ffff);
309 nv_mask(pfb
, 0x10f800, 0x00000001, 0x00000001);
311 for (i
= 0; i
< 0x30; i
++) {
312 nv_wr32(pfb
, 0x10f8c0, (i
<< 8) | i
);
313 nv_wr32(pfb
, 0x10f900, pattern
[i
% 16]);
316 for (i
= 0; i
< 0x30; i
++) {
317 nv_wr32(pfb
, 0x10f8e0, (i
<< 8) | i
);
318 nv_wr32(pfb
, 0x10f920, pattern
[i
% 16]);
321 /* And upload the pattern */
322 r001700
= nv_rd32(pfb
, 0x1700);
323 nv_wr32(pfb
, 0x1700, mem
->offset
>> 16);
324 for (i
= 0; i
< 16; i
++)
325 nv_wr32(pfb
, 0x700000 + (i
<< 2), pattern
[i
]);
326 for (i
= 0; i
< 16; i
++)
327 nv_wr32(pfb
, 0x700100 + (i
<< 2), pattern
[i
]);
328 nv_wr32(pfb
, 0x1700, r001700
);
330 train
->r_100720
= nv_rd32(pfb
, 0x100720);
331 train
->r_1111e0
= nv_rd32(pfb
, 0x1111e0);
332 train
->r_111400
= nv_rd32(pfb
, 0x111400);
337 gt215_link_train_fini(struct nvkm_fb
*pfb
)
339 struct gt215_ram
*ram
= (void *)pfb
->ram
;
342 pfb
->ram
->put(pfb
, &ram
->ltrain
.mem
);
348 #define T(t) cfg->timing_10_##t
350 gt215_ram_timing_calc(struct nvkm_fb
*pfb
, u32
*timing
)
352 struct gt215_ram
*ram
= (void *)pfb
->ram
;
353 struct nvbios_ramcfg
*cfg
= &ram
->base
.target
.bios
;
354 int tUNK_base
, tUNK_40_0
, prevCL
;
355 u32 cur2
, cur3
, cur7
, cur8
;
357 cur2
= nv_rd32(pfb
, 0x100228);
358 cur3
= nv_rd32(pfb
, 0x10022c);
359 cur7
= nv_rd32(pfb
, 0x10023c);
360 cur8
= nv_rd32(pfb
, 0x100240);
363 switch ((!T(CWL
)) * ram
->base
.type
) {
364 case NV_MEM_TYPE_DDR2
:
367 case NV_MEM_TYPE_GDDR3
:
368 T(CWL
) = ((cur2
& 0xff000000) >> 24) + 1;
372 prevCL
= (cur3
& 0x000000ff) + 1;
373 tUNK_base
= ((cur7
& 0x00ff0000) >> 16) - prevCL
;
375 timing
[0] = (T(RP
) << 24 | T(RAS
) << 16 | T(RFC
) << 8 | T(RC
));
376 timing
[1] = (T(WR
) + 1 + T(CWL
)) << 24 |
377 max_t(u8
,T(18), 1) << 16 |
378 (T(WTR
) + 1 + T(CWL
)) << 8 |
379 (5 + T(CL
) - T(CWL
));
380 timing
[2] = (T(CWL
) - 1) << 24 |
384 timing
[3] = (cur3
& 0x00ff0000) |
385 (0x30 + T(CL
)) << 24 |
388 timing
[4] = T(20) << 24 |
392 timing
[5] = T(RFC
) << 24 |
393 max_t(u8
,T(RCDRD
), T(RCDWR
)) << 16 |
394 max_t(u8
, (T(CWL
) + 6), (T(CL
) + 2)) << 8 |
396 timing
[6] = (0x5a + T(CL
)) << 16 |
397 max_t(u8
, 1, (6 - T(CL
) + T(CWL
))) << 8 |
398 (0x50 + T(CL
) - T(CWL
));
399 timing
[7] = (cur7
& 0xff000000) |
400 ((tUNK_base
+ T(CL
)) << 16) |
402 timing
[8] = cur8
& 0xffffff00;
404 switch (ram
->base
.type
) {
405 case NV_MEM_TYPE_DDR2
:
406 case NV_MEM_TYPE_GDDR3
:
407 tUNK_40_0
= prevCL
- (cur8
& 0xff);
415 nv_debug(pfb
, "Entry: 220: %08x %08x %08x %08x\n",
416 timing
[0], timing
[1], timing
[2], timing
[3]);
417 nv_debug(pfb
, " 230: %08x %08x %08x %08x\n",
418 timing
[4], timing
[5], timing
[6], timing
[7]);
419 nv_debug(pfb
, " 240: %08x\n", timing
[8]);
425 nvkm_sddr2_dll_reset(struct gt215_ramfuc
*fuc
)
427 ram_mask(fuc
, mr
[0], 0x100, 0x100);
429 ram_mask(fuc
, mr
[0], 0x100, 0x000);
434 nvkm_sddr3_dll_disable(struct gt215_ramfuc
*fuc
, u32
*mr
)
436 u32 mr1_old
= ram_rd32(fuc
, mr
[1]);
438 if (!(mr1_old
& 0x1)) {
439 ram_wr32(fuc
, 0x1002d4, 0x00000001);
440 ram_wr32(fuc
, mr
[1], mr
[1]);
446 nvkm_gddr3_dll_disable(struct gt215_ramfuc
*fuc
, u32
*mr
)
448 u32 mr1_old
= ram_rd32(fuc
, mr
[1]);
450 if (!(mr1_old
& 0x40)) {
451 ram_wr32(fuc
, mr
[1], mr
[1]);
457 gt215_ram_lock_pll(struct gt215_ramfuc
*fuc
, struct gt215_clk_info
*mclk
)
459 ram_wr32(fuc
, 0x004004, mclk
->pll
);
460 ram_mask(fuc
, 0x004000, 0x00000001, 0x00000001);
461 ram_mask(fuc
, 0x004000, 0x00000010, 0x00000000);
462 ram_wait(fuc
, 0x004000, 0x00020000, 0x00020000, 64000);
463 ram_mask(fuc
, 0x004000, 0x00000010, 0x00000010);
467 gt215_ram_fbvref(struct gt215_ramfuc
*fuc
, u32 val
)
469 struct nvkm_gpio
*gpio
= nvkm_gpio(fuc
->base
.pfb
);
470 struct dcb_gpio_func func
;
471 u32 reg
, sh
, gpio_val
;
474 if (gpio
->get(gpio
, 0, 0x2e, DCB_GPIO_UNUSED
) != val
) {
475 ret
= gpio
->find(gpio
, 0, 0x2e, DCB_GPIO_UNUSED
, &func
);
479 nv50_gpio_location(func
.line
, ®
, &sh
);
480 gpio_val
= ram_rd32(fuc
, gpioFBVREF
);
481 if (gpio_val
& (8 << sh
))
484 ram_mask(fuc
, gpioFBVREF
, (0x3 << sh
), ((val
| 0x2) << sh
));
485 ram_nsec(fuc
, 20000);
490 gt215_ram_calc(struct nvkm_fb
*pfb
, u32 freq
)
492 struct nvkm_bios
*bios
= nvkm_bios(pfb
);
493 struct gt215_ram
*ram
= (void *)pfb
->ram
;
494 struct gt215_ramfuc
*fuc
= &ram
->fuc
;
495 struct gt215_ltrain
*train
= &ram
->ltrain
;
496 struct gt215_clk_info mclk
;
497 struct nvkm_ram_data
*next
;
498 u8 ver
, hdr
, cnt
, len
, strap
;
500 u32 r004018
, r100760
, r100da0
, r111100
, ctrl
;
501 u32 unk714
, unk718
, unk71c
;
506 next
= &ram
->base
.target
;
508 ram
->base
.next
= next
;
510 if (ram
->ltrain
.state
== NVA3_TRAIN_ONCE
)
511 gt215_link_train(pfb
);
513 /* lookup memory config data relevant to the target frequency */
515 data
= nvbios_rammapEm(bios
, freq
/ 1000, &ver
, &hdr
, &cnt
, &len
,
517 if (!data
|| ver
!= 0x10 || hdr
< 0x05) {
518 nv_error(pfb
, "invalid/missing rammap entry\n");
522 /* locate specific data set for the attached memory */
523 strap
= nvbios_ramcfg_index(nv_subdev(pfb
));
525 nv_error(pfb
, "invalid ramcfg strap\n");
529 data
= nvbios_rammapSp(bios
, data
, ver
, hdr
, cnt
, len
, strap
,
530 &ver
, &hdr
, &next
->bios
);
531 if (!data
|| ver
!= 0x10 || hdr
< 0x09) {
532 nv_error(pfb
, "invalid/missing ramcfg entry\n");
536 /* lookup memory timings, if bios says they're present */
537 if (next
->bios
.ramcfg_timing
!= 0xff) {
538 data
= nvbios_timingEp(bios
, next
->bios
.ramcfg_timing
,
539 &ver
, &hdr
, &cnt
, &len
,
541 if (!data
|| ver
!= 0x10 || hdr
< 0x17) {
542 nv_error(pfb
, "invalid/missing timing entry\n");
547 ret
= gt215_pll_info(nvkm_clk(pfb
), 0x12, 0x4000, freq
, &mclk
);
549 nv_error(pfb
, "failed mclk calculation\n");
553 gt215_ram_timing_calc(pfb
, timing
);
555 ret
= ram_init(fuc
, pfb
);
559 /* Determine ram-specific MR values */
560 ram
->base
.mr
[0] = ram_rd32(fuc
, mr
[0]);
561 ram
->base
.mr
[1] = ram_rd32(fuc
, mr
[1]);
562 ram
->base
.mr
[2] = ram_rd32(fuc
, mr
[2]);
564 switch (ram
->base
.type
) {
565 case NV_MEM_TYPE_DDR2
:
566 ret
= nvkm_sddr2_calc(&ram
->base
);
568 case NV_MEM_TYPE_DDR3
:
569 ret
= nvkm_sddr3_calc(&ram
->base
);
571 case NV_MEM_TYPE_GDDR3
:
572 ret
= nvkm_gddr3_calc(&ram
->base
);
582 /* XXX: where the fuck does 750MHz come from? */
583 if (freq
<= 750000) {
584 r004018
= 0x10000000;
585 r100760
= 0x22222222;
586 r100da0
= 0x00000010;
588 r004018
= 0x00000000;
589 r100760
= 0x00000000;
590 r100da0
= 0x00000000;
593 if (!next
->bios
.ramcfg_10_DLLoff
)
594 r004018
|= 0x00004000;
596 /* pll2pll requires to switch to a safe clock first */
597 ctrl
= ram_rd32(fuc
, 0x004000);
598 pll2pll
= (!(ctrl
& 0x00000008)) && mclk
.pll
;
600 /* Pre, NVIDIA does this outside the script */
601 if (next
->bios
.ramcfg_10_02_10
) {
602 ram_mask(fuc
, 0x111104, 0x00000600, 0x00000000);
604 ram_mask(fuc
, 0x111100, 0x40000000, 0x40000000);
605 ram_mask(fuc
, 0x111104, 0x00000180, 0x00000000);
607 /* Always disable this bit during reclock */
608 ram_mask(fuc
, 0x100200, 0x00000800, 0x00000000);
610 /* If switching from non-pll to pll, lock before disabling FB */
611 if (mclk
.pll
&& !pll2pll
) {
612 ram_mask(fuc
, 0x004128, 0x003f3141, mclk
.clk
| 0x00000101);
613 gt215_ram_lock_pll(fuc
, &mclk
);
616 /* Start with disabling some CRTCs and PFIFO? */
617 ram_wait_vblank(fuc
);
618 ram_wr32(fuc
, 0x611200, 0x3300);
619 ram_mask(fuc
, 0x002504, 0x1, 0x1);
620 ram_nsec(fuc
, 10000);
621 ram_wait(fuc
, 0x002504, 0x10, 0x10, 20000); /* XXX: or longer? */
625 if (!next
->bios
.ramcfg_10_02_10
) {
626 if (ram
->base
.type
== NV_MEM_TYPE_GDDR3
)
627 ram_mask(fuc
, 0x111100, 0x04020000, 0x00020000);
629 ram_mask(fuc
, 0x111100, 0x04020000, 0x04020000);
632 /* If we're disabling the DLL, do it now */
633 switch (next
->bios
.ramcfg_10_DLLoff
* ram
->base
.type
) {
634 case NV_MEM_TYPE_DDR3
:
635 nvkm_sddr3_dll_disable(fuc
, ram
->base
.mr
);
637 case NV_MEM_TYPE_GDDR3
:
638 nvkm_gddr3_dll_disable(fuc
, ram
->base
.mr
);
642 if (fuc
->r_gpioFBVREF
.addr
&& next
->bios
.timing_10_ODT
)
643 gt215_ram_fbvref(fuc
, 0);
645 /* Brace RAM for impact */
646 ram_wr32(fuc
, 0x1002d4, 0x00000001);
647 ram_wr32(fuc
, 0x1002d0, 0x00000001);
648 ram_wr32(fuc
, 0x1002d0, 0x00000001);
649 ram_wr32(fuc
, 0x100210, 0x00000000);
650 ram_wr32(fuc
, 0x1002dc, 0x00000001);
653 if (nv_device(pfb
)->chipset
== 0xa3 && freq
<= 500000)
654 ram_mask(fuc
, 0x100700, 0x00000006, 0x00000006);
656 /* Fiddle with clocks */
657 /* There's 4 scenario's
658 * pll->pll: first switch to a 324MHz clock, set up new PLL, switch
659 * clk->pll: Set up new PLL, switch
660 * pll->clk: Set up clock, switch
661 * clk->clk: Overwrite ctrl and other bits, switch */
663 /* Switch to regular clock - 324MHz */
665 ram_mask(fuc
, 0x004000, 0x00000004, 0x00000004);
666 ram_mask(fuc
, 0x004168, 0x003f3141, 0x00083101);
667 ram_mask(fuc
, 0x004000, 0x00000008, 0x00000008);
668 ram_mask(fuc
, 0x1110e0, 0x00088000, 0x00088000);
669 ram_wr32(fuc
, 0x004018, 0x00001000);
670 gt215_ram_lock_pll(fuc
, &mclk
);
674 ram_mask(fuc
, 0x004000, 0x00000105, 0x00000105);
675 ram_wr32(fuc
, 0x004018, 0x00001000 | r004018
);
676 ram_wr32(fuc
, 0x100da0, r100da0
);
678 ram_mask(fuc
, 0x004168, 0x003f3141, mclk
.clk
| 0x00000101);
679 ram_mask(fuc
, 0x004000, 0x00000108, 0x00000008);
680 ram_mask(fuc
, 0x1110e0, 0x00088000, 0x00088000);
681 ram_wr32(fuc
, 0x004018, 0x00009000 | r004018
);
682 ram_wr32(fuc
, 0x100da0, r100da0
);
684 ram_nsec(fuc
, 20000);
686 if (next
->bios
.rammap_10_04_08
) {
687 ram_wr32(fuc
, 0x1005a0, next
->bios
.ramcfg_10_06
<< 16 |
688 next
->bios
.ramcfg_10_05
<< 8 |
689 next
->bios
.ramcfg_10_05
);
690 ram_wr32(fuc
, 0x1005a4, next
->bios
.ramcfg_10_08
<< 8 |
691 next
->bios
.ramcfg_10_07
);
692 ram_wr32(fuc
, 0x10f804, next
->bios
.ramcfg_10_09_f0
<< 20 |
693 next
->bios
.ramcfg_10_03_0f
<< 16 |
694 next
->bios
.ramcfg_10_09_0f
|
696 ram_mask(fuc
, 0x10053c, 0x00001000, 0x00000000);
698 if (train
->state
== NVA3_TRAIN_DONE
) {
699 ram_wr32(fuc
, 0x100080, 0x1020);
700 ram_mask(fuc
, 0x111400, 0xffffffff, train
->r_111400
);
701 ram_mask(fuc
, 0x1111e0, 0xffffffff, train
->r_1111e0
);
702 ram_mask(fuc
, 0x100720, 0xffffffff, train
->r_100720
);
704 ram_mask(fuc
, 0x10053c, 0x00001000, 0x00001000);
705 ram_mask(fuc
, 0x10f804, 0x80000000, 0x00000000);
706 ram_mask(fuc
, 0x100760, 0x22222222, r100760
);
707 ram_mask(fuc
, 0x1007a0, 0x22222222, r100760
);
708 ram_mask(fuc
, 0x1007e0, 0x22222222, r100760
);
711 if (nv_device(pfb
)->chipset
== 0xa3 && freq
> 500000) {
712 ram_mask(fuc
, 0x100700, 0x00000006, 0x00000000);
717 ram_mask(fuc
, 0x1110e0, 0x00088000, 0x00011000);
718 ram_mask(fuc
, 0x004000, 0x00000008, 0x00000000);
721 ram_wr32(fuc
, 0x1002dc, 0x00000000);
722 ram_wr32(fuc
, 0x1002d4, 0x00000001);
723 ram_wr32(fuc
, 0x100210, 0x80000000);
726 /* Set RAM MR parameters and timings */
727 for (i
= 2; i
>= 0; i
--) {
728 if (ram_rd32(fuc
, mr
[i
]) != ram
->base
.mr
[i
]) {
729 ram_wr32(fuc
, mr
[i
], ram
->base
.mr
[i
]);
734 ram_wr32(fuc
, 0x100220[3], timing
[3]);
735 ram_wr32(fuc
, 0x100220[1], timing
[1]);
736 ram_wr32(fuc
, 0x100220[6], timing
[6]);
737 ram_wr32(fuc
, 0x100220[7], timing
[7]);
738 ram_wr32(fuc
, 0x100220[2], timing
[2]);
739 ram_wr32(fuc
, 0x100220[4], timing
[4]);
740 ram_wr32(fuc
, 0x100220[5], timing
[5]);
741 ram_wr32(fuc
, 0x100220[0], timing
[0]);
742 ram_wr32(fuc
, 0x100220[8], timing
[8]);
745 ram_mask(fuc
, 0x100200, 0x00001000, !next
->bios
.ramcfg_10_02_08
<< 12);
747 /* XXX: A lot of "chipset"/"ram type" specific stuff...? */
748 unk714
= ram_rd32(fuc
, 0x100714) & ~0xf0000130;
749 unk718
= ram_rd32(fuc
, 0x100718) & ~0x00000100;
750 unk71c
= ram_rd32(fuc
, 0x10071c) & ~0x00000100;
751 r111100
= ram_rd32(fuc
, 0x111100) & ~0x3a800000;
753 if (next
->bios
.ramcfg_10_02_04
) {
754 switch (ram
->base
.type
) {
755 case NV_MEM_TYPE_DDR3
:
756 if (nv_device(pfb
)->chipset
!= 0xa8)
757 r111100
|= 0x00000004;
759 case NV_MEM_TYPE_DDR2
:
760 r111100
|= 0x08000000;
766 switch (ram
->base
.type
) {
767 case NV_MEM_TYPE_DDR2
:
768 r111100
|= 0x1a800000;
769 unk714
|= 0x00000010;
771 case NV_MEM_TYPE_DDR3
:
772 if (nv_device(pfb
)->chipset
== 0xa8) {
773 r111100
|= 0x08000000;
775 r111100
&= ~0x00000004;
776 r111100
|= 0x12800000;
778 unk714
|= 0x00000010;
780 case NV_MEM_TYPE_GDDR3
:
781 r111100
|= 0x30000000;
782 unk714
|= 0x00000020;
789 unk714
|= (next
->bios
.ramcfg_10_04_01
) << 8;
791 if (next
->bios
.ramcfg_10_02_20
)
792 unk714
|= 0xf0000000;
793 if (next
->bios
.ramcfg_10_02_02
)
794 unk718
|= 0x00000100;
795 if (next
->bios
.ramcfg_10_02_01
)
796 unk71c
|= 0x00000100;
797 if (next
->bios
.timing_10_24
!= 0xff) {
798 unk718
&= ~0xf0000000;
799 unk718
|= next
->bios
.timing_10_24
<< 28;
801 if (next
->bios
.ramcfg_10_02_10
)
802 r111100
&= ~0x04020000;
804 ram_mask(fuc
, 0x100714, 0xffffffff, unk714
);
805 ram_mask(fuc
, 0x10071c, 0xffffffff, unk71c
);
806 ram_mask(fuc
, 0x100718, 0xffffffff, unk718
);
807 ram_mask(fuc
, 0x111100, 0xffffffff, r111100
);
809 if (fuc
->r_gpioFBVREF
.addr
&& !next
->bios
.timing_10_ODT
)
810 gt215_ram_fbvref(fuc
, 1);
813 if (!next
->bios
.ramcfg_10_DLLoff
)
814 nvkm_sddr2_dll_reset(fuc
);
816 if (ram
->base
.type
== NV_MEM_TYPE_GDDR3
) {
817 ram_nsec(fuc
, 31000);
819 ram_nsec(fuc
, 14000);
822 if (ram
->base
.type
== NV_MEM_TYPE_DDR3
) {
823 ram_wr32(fuc
, 0x100264, 0x1);
827 ram_nuke(fuc
, 0x100700);
828 ram_mask(fuc
, 0x100700, 0x01000000, 0x01000000);
829 ram_mask(fuc
, 0x100700, 0x01000000, 0x00000000);
833 ram_wr32(fuc
, 0x611200, 0x3330);
836 if (next
->bios
.rammap_10_04_02
)
837 ram_mask(fuc
, 0x100200, 0x00000800, 0x00000800);
838 if (next
->bios
.ramcfg_10_02_10
) {
839 ram_mask(fuc
, 0x111104, 0x00000180, 0x00000180);
840 ram_mask(fuc
, 0x111100, 0x40000000, 0x00000000);
842 ram_mask(fuc
, 0x111104, 0x00000600, 0x00000600);
846 ram_mask(fuc
, 0x004168, 0x00000001, 0x00000000);
847 ram_mask(fuc
, 0x004168, 0x00000100, 0x00000000);
849 ram_mask(fuc
, 0x004000, 0x00000001, 0x00000000);
850 ram_mask(fuc
, 0x004128, 0x00000001, 0x00000000);
851 ram_mask(fuc
, 0x004128, 0x00000100, 0x00000000);
858 gt215_ram_prog(struct nvkm_fb
*pfb
)
860 struct nvkm_device
*device
= nv_device(pfb
);
861 struct gt215_ram
*ram
= (void *)pfb
->ram
;
862 struct gt215_ramfuc
*fuc
= &ram
->fuc
;
863 bool exec
= nvkm_boolopt(device
->cfgopt
, "NvMemExec", true);
866 nv_mask(pfb
, 0x001534, 0x2, 0x2);
870 /* Post-processing, avoids flicker */
871 nv_mask(pfb
, 0x002504, 0x1, 0x0);
872 nv_mask(pfb
, 0x001534, 0x2, 0x0);
874 nv_mask(pfb
, 0x616308, 0x10, 0x10);
875 nv_mask(pfb
, 0x616b08, 0x10, 0x10);
877 ram_exec(fuc
, false);
883 gt215_ram_tidy(struct nvkm_fb
*pfb
)
885 struct gt215_ram
*ram
= (void *)pfb
->ram
;
886 struct gt215_ramfuc
*fuc
= &ram
->fuc
;
887 ram_exec(fuc
, false);
891 gt215_ram_init(struct nvkm_object
*object
)
893 struct nvkm_fb
*pfb
= (void *)object
->parent
;
894 struct gt215_ram
*ram
= (void *)object
;
897 ret
= nvkm_ram_init(&ram
->base
);
901 gt215_link_train_init(pfb
);
906 gt215_ram_fini(struct nvkm_object
*object
, bool suspend
)
908 struct nvkm_fb
*pfb
= (void *)object
->parent
;
911 gt215_link_train_fini(pfb
);
917 gt215_ram_ctor(struct nvkm_object
*parent
, struct nvkm_object
*engine
,
918 struct nvkm_oclass
*oclass
, void *data
, u32 datasize
,
919 struct nvkm_object
**pobject
)
921 struct nvkm_fb
*pfb
= nvkm_fb(parent
);
922 struct nvkm_gpio
*gpio
= nvkm_gpio(pfb
);
923 struct dcb_gpio_func func
;
924 struct gt215_ram
*ram
;
928 ret
= nv50_ram_create(parent
, engine
, oclass
, &ram
);
929 *pobject
= nv_object(ram
);
933 switch (ram
->base
.type
) {
934 case NV_MEM_TYPE_DDR2
:
935 case NV_MEM_TYPE_DDR3
:
936 case NV_MEM_TYPE_GDDR3
:
937 ram
->base
.calc
= gt215_ram_calc
;
938 ram
->base
.prog
= gt215_ram_prog
;
939 ram
->base
.tidy
= gt215_ram_tidy
;
942 nv_warn(ram
, "reclocking of this ram type unsupported\n");
946 ram
->fuc
.r_0x001610
= ramfuc_reg(0x001610);
947 ram
->fuc
.r_0x001700
= ramfuc_reg(0x001700);
948 ram
->fuc
.r_0x002504
= ramfuc_reg(0x002504);
949 ram
->fuc
.r_0x004000
= ramfuc_reg(0x004000);
950 ram
->fuc
.r_0x004004
= ramfuc_reg(0x004004);
951 ram
->fuc
.r_0x004018
= ramfuc_reg(0x004018);
952 ram
->fuc
.r_0x004128
= ramfuc_reg(0x004128);
953 ram
->fuc
.r_0x004168
= ramfuc_reg(0x004168);
954 ram
->fuc
.r_0x100080
= ramfuc_reg(0x100080);
955 ram
->fuc
.r_0x100200
= ramfuc_reg(0x100200);
956 ram
->fuc
.r_0x100210
= ramfuc_reg(0x100210);
957 for (i
= 0; i
< 9; i
++)
958 ram
->fuc
.r_0x100220
[i
] = ramfuc_reg(0x100220 + (i
* 4));
959 ram
->fuc
.r_0x100264
= ramfuc_reg(0x100264);
960 ram
->fuc
.r_0x1002d0
= ramfuc_reg(0x1002d0);
961 ram
->fuc
.r_0x1002d4
= ramfuc_reg(0x1002d4);
962 ram
->fuc
.r_0x1002dc
= ramfuc_reg(0x1002dc);
963 ram
->fuc
.r_0x10053c
= ramfuc_reg(0x10053c);
964 ram
->fuc
.r_0x1005a0
= ramfuc_reg(0x1005a0);
965 ram
->fuc
.r_0x1005a4
= ramfuc_reg(0x1005a4);
966 ram
->fuc
.r_0x100700
= ramfuc_reg(0x100700);
967 ram
->fuc
.r_0x100714
= ramfuc_reg(0x100714);
968 ram
->fuc
.r_0x100718
= ramfuc_reg(0x100718);
969 ram
->fuc
.r_0x10071c
= ramfuc_reg(0x10071c);
970 ram
->fuc
.r_0x100720
= ramfuc_reg(0x100720);
971 ram
->fuc
.r_0x100760
= ramfuc_stride(0x100760, 4, ram
->base
.part_mask
);
972 ram
->fuc
.r_0x1007a0
= ramfuc_stride(0x1007a0, 4, ram
->base
.part_mask
);
973 ram
->fuc
.r_0x1007e0
= ramfuc_stride(0x1007e0, 4, ram
->base
.part_mask
);
974 ram
->fuc
.r_0x100da0
= ramfuc_stride(0x100da0, 4, ram
->base
.part_mask
);
975 ram
->fuc
.r_0x10f804
= ramfuc_reg(0x10f804);
976 ram
->fuc
.r_0x1110e0
= ramfuc_stride(0x1110e0, 4, ram
->base
.part_mask
);
977 ram
->fuc
.r_0x111100
= ramfuc_reg(0x111100);
978 ram
->fuc
.r_0x111104
= ramfuc_reg(0x111104);
979 ram
->fuc
.r_0x1111e0
= ramfuc_reg(0x1111e0);
980 ram
->fuc
.r_0x111400
= ramfuc_reg(0x111400);
981 ram
->fuc
.r_0x611200
= ramfuc_reg(0x611200);
983 if (ram
->base
.ranks
> 1) {
984 ram
->fuc
.r_mr
[0] = ramfuc_reg2(0x1002c0, 0x1002c8);
985 ram
->fuc
.r_mr
[1] = ramfuc_reg2(0x1002c4, 0x1002cc);
986 ram
->fuc
.r_mr
[2] = ramfuc_reg2(0x1002e0, 0x1002e8);
987 ram
->fuc
.r_mr
[3] = ramfuc_reg2(0x1002e4, 0x1002ec);
989 ram
->fuc
.r_mr
[0] = ramfuc_reg(0x1002c0);
990 ram
->fuc
.r_mr
[1] = ramfuc_reg(0x1002c4);
991 ram
->fuc
.r_mr
[2] = ramfuc_reg(0x1002e0);
992 ram
->fuc
.r_mr
[3] = ramfuc_reg(0x1002e4);
995 ret
= gpio
->find(gpio
, 0, 0x2e, DCB_GPIO_UNUSED
, &func
);
997 nv50_gpio_location(func
.line
, ®
, &shift
);
998 ram
->fuc
.r_gpioFBVREF
= ramfuc_reg(reg
);
1005 gt215_ram_oclass
= {
1006 .ofuncs
= &(struct nvkm_ofuncs
) {
1007 .ctor
= gt215_ram_ctor
,
1008 .dtor
= _nvkm_ram_dtor
,
1009 .init
= gt215_ram_init
,
1010 .fini
= gt215_ram_fini
,