2 * Copyright 2012 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.
24 #include <subdev/bios.h>
25 #include <subdev/bios/bit.h>
26 #include <subdev/bios/bmp.h>
27 #include <subdev/bios/conn.h>
28 #include <subdev/bios/dcb.h>
29 #include <subdev/bios/dp.h>
30 #include <subdev/bios/gpio.h>
31 #include <subdev/bios/init.h>
32 #include <subdev/bios/ramcfg.h>
34 #include <subdev/devinit.h>
35 #include <subdev/gpio.h>
36 #include <subdev/i2c.h>
37 #include <subdev/vga.h>
39 #define bioslog(lvl, fmt, args...) do { \
40 nvkm_printk(init->subdev, lvl, info, "0x%04x[%c]: "fmt, \
41 init->offset, init_exec(init) ? \
42 '0' + (init->nested - 1) : ' ', ##args); \
44 #define cont(fmt, args...) do { \
45 if (init->subdev->debug >= NV_DBG_TRACE) \
46 printk(fmt, ##args); \
48 #define trace(fmt, args...) bioslog(TRACE, fmt, ##args)
49 #define warn(fmt, args...) bioslog(WARN, fmt, ##args)
50 #define error(fmt, args...) bioslog(ERROR, fmt, ##args)
52 /******************************************************************************
53 * init parser control flow helpers
54 *****************************************************************************/
57 init_exec(struct nvbios_init
*init
)
59 return (init
->execute
== 1) || ((init
->execute
& 5) == 5);
63 init_exec_set(struct nvbios_init
*init
, bool exec
)
65 if (exec
) init
->execute
&= 0xfd;
66 else init
->execute
|= 0x02;
70 init_exec_inv(struct nvbios_init
*init
)
72 init
->execute
^= 0x02;
76 init_exec_force(struct nvbios_init
*init
, bool exec
)
78 if (exec
) init
->execute
|= 0x04;
79 else init
->execute
&= 0xfb;
82 /******************************************************************************
83 * init parser wrappers for normal register/i2c/whatever accessors
84 *****************************************************************************/
87 init_or(struct nvbios_init
*init
)
89 if (init_exec(init
)) {
91 return ffs(init
->outp
->or) - 1;
92 error("script needs OR!!\n");
98 init_link(struct nvbios_init
*init
)
100 if (init_exec(init
)) {
102 return !(init
->outp
->sorconf
.link
& 1);
103 error("script needs OR link\n");
109 init_crtc(struct nvbios_init
*init
)
111 if (init_exec(init
)) {
114 error("script needs crtc\n");
120 init_conn(struct nvbios_init
*init
)
122 struct nvkm_bios
*bios
= init
->bios
;
123 struct nvbios_connE connE
;
127 if (init_exec(init
)) {
129 conn
= init
->outp
->connector
;
130 conn
= nvbios_connEp(bios
, conn
, &ver
, &hdr
, &connE
);
135 error("script needs connector type\n");
142 init_nvreg(struct nvbios_init
*init
, u32 reg
)
144 struct nvkm_devinit
*devinit
= init
->bios
->subdev
.device
->devinit
;
146 /* C51 (at least) sometimes has the lower bits set which the VBIOS
147 * interprets to mean that access needs to go through certain IO
148 * ports instead. The NVIDIA binary driver has been seen to access
149 * these through the NV register address, so lets assume we can
154 /* GF8+ display scripts need register addresses mangled a bit to
155 * select a specific CRTC/OR
157 if (init
->bios
->subdev
.device
->card_type
>= NV_50
) {
158 if (reg
& 0x80000000) {
159 reg
+= init_crtc(init
) * 0x800;
163 if (reg
& 0x40000000) {
164 reg
+= init_or(init
) * 0x800;
166 if (reg
& 0x20000000) {
167 reg
+= init_link(init
) * 0x80;
173 if (reg
& ~0x00fffffc)
174 warn("unknown bits in register 0x%08x\n", reg
);
176 return nvkm_devinit_mmio(devinit
, reg
);
180 init_rd32(struct nvbios_init
*init
, u32 reg
)
182 struct nvkm_device
*device
= init
->bios
->subdev
.device
;
183 reg
= init_nvreg(init
, reg
);
184 if (reg
!= ~0 && init_exec(init
))
185 return nvkm_rd32(device
, reg
);
190 init_wr32(struct nvbios_init
*init
, u32 reg
, u32 val
)
192 struct nvkm_device
*device
= init
->bios
->subdev
.device
;
193 reg
= init_nvreg(init
, reg
);
194 if (reg
!= ~0 && init_exec(init
))
195 nvkm_wr32(device
, reg
, val
);
199 init_mask(struct nvbios_init
*init
, u32 reg
, u32 mask
, u32 val
)
201 struct nvkm_device
*device
= init
->bios
->subdev
.device
;
202 reg
= init_nvreg(init
, reg
);
203 if (reg
!= ~0 && init_exec(init
)) {
204 u32 tmp
= nvkm_rd32(device
, reg
);
205 nvkm_wr32(device
, reg
, (tmp
& ~mask
) | val
);
212 init_rdport(struct nvbios_init
*init
, u16 port
)
215 return nvkm_rdport(init
->subdev
->device
, init
->crtc
, port
);
220 init_wrport(struct nvbios_init
*init
, u16 port
, u8 value
)
223 nvkm_wrport(init
->subdev
->device
, init
->crtc
, port
, value
);
227 init_rdvgai(struct nvbios_init
*init
, u16 port
, u8 index
)
229 struct nvkm_subdev
*subdev
= init
->subdev
;
230 if (init_exec(init
)) {
231 int head
= init
->crtc
< 0 ? 0 : init
->crtc
;
232 return nvkm_rdvgai(subdev
->device
, head
, port
, index
);
238 init_wrvgai(struct nvbios_init
*init
, u16 port
, u8 index
, u8 value
)
240 struct nvkm_device
*device
= init
->subdev
->device
;
242 /* force head 0 for updates to cr44, it only exists on first head */
243 if (device
->card_type
< NV_50
) {
244 if (port
== 0x03d4 && index
== 0x44)
248 if (init_exec(init
)) {
249 int head
= init
->crtc
< 0 ? 0 : init
->crtc
;
250 nvkm_wrvgai(device
, head
, port
, index
, value
);
253 /* select head 1 if cr44 write selected it */
254 if (device
->card_type
< NV_50
) {
255 if (port
== 0x03d4 && index
== 0x44 && value
== 3)
260 static struct i2c_adapter
*
261 init_i2c(struct nvbios_init
*init
, int index
)
263 struct nvkm_i2c
*i2c
= init
->bios
->subdev
.device
->i2c
;
264 struct nvkm_i2c_bus
*bus
;
267 index
= NVKM_I2C_BUS_PRI
;
268 if (init
->outp
&& init
->outp
->i2c_upper_default
)
269 index
= NVKM_I2C_BUS_SEC
;
272 index
= NVKM_I2C_BUS_PRI
;
275 index
= NVKM_I2C_BUS_SEC
;
278 bus
= nvkm_i2c_bus_find(i2c
, index
);
279 return bus
? &bus
->i2c
: NULL
;
283 init_rdi2cr(struct nvbios_init
*init
, u8 index
, u8 addr
, u8 reg
)
285 struct i2c_adapter
*adap
= init_i2c(init
, index
);
286 if (adap
&& init_exec(init
))
287 return nvkm_rdi2cr(adap
, addr
, reg
);
292 init_wri2cr(struct nvbios_init
*init
, u8 index
, u8 addr
, u8 reg
, u8 val
)
294 struct i2c_adapter
*adap
= init_i2c(init
, index
);
295 if (adap
&& init_exec(init
))
296 return nvkm_wri2cr(adap
, addr
, reg
, val
);
300 static struct nvkm_i2c_aux
*
301 init_aux(struct nvbios_init
*init
)
303 struct nvkm_i2c
*i2c
= init
->bios
->subdev
.device
->i2c
;
306 error("script needs output for aux\n");
309 return nvkm_i2c_aux_find(i2c
, init
->outp
->i2c_index
);
313 init_rdauxr(struct nvbios_init
*init
, u32 addr
)
315 struct nvkm_i2c_aux
*aux
= init_aux(init
);
318 if (aux
&& init_exec(init
)) {
319 int ret
= nvkm_rdaux(aux
, addr
, &data
, 1);
322 trace("auxch read failed with %d\n", ret
);
329 init_wrauxr(struct nvbios_init
*init
, u32 addr
, u8 data
)
331 struct nvkm_i2c_aux
*aux
= init_aux(init
);
332 if (aux
&& init_exec(init
)) {
333 int ret
= nvkm_wraux(aux
, addr
, &data
, 1);
335 trace("auxch write failed with %d\n", ret
);
342 init_prog_pll(struct nvbios_init
*init
, u32 id
, u32 freq
)
344 struct nvkm_devinit
*devinit
= init
->bios
->subdev
.device
->devinit
;
345 if (init_exec(init
)) {
346 int ret
= nvkm_devinit_pll_set(devinit
, id
, freq
);
348 warn("failed to prog pll 0x%08x to %dkHz\n", id
, freq
);
352 /******************************************************************************
353 * parsing of bios structures that are required to execute init tables
354 *****************************************************************************/
357 init_table(struct nvkm_bios
*bios
, u16
*len
)
359 struct bit_entry bit_I
;
361 if (!bit_entry(bios
, 'I', &bit_I
)) {
366 if (bmp_version(bios
) >= 0x0510) {
368 return bios
->bmp_offset
+ 75;
375 init_table_(struct nvbios_init
*init
, u16 offset
, const char *name
)
377 struct nvkm_bios
*bios
= init
->bios
;
378 u16 len
, data
= init_table(bios
, &len
);
380 if (len
>= offset
+ 2) {
381 data
= nvbios_rd16(bios
, data
+ offset
);
385 warn("%s pointer invalid\n", name
);
389 warn("init data too short for %s pointer", name
);
393 warn("init data not found\n");
397 #define init_script_table(b) init_table_((b), 0x00, "script table")
398 #define init_macro_index_table(b) init_table_((b), 0x02, "macro index table")
399 #define init_macro_table(b) init_table_((b), 0x04, "macro table")
400 #define init_condition_table(b) init_table_((b), 0x06, "condition table")
401 #define init_io_condition_table(b) init_table_((b), 0x08, "io condition table")
402 #define init_io_flag_condition_table(b) init_table_((b), 0x0a, "io flag conditon table")
403 #define init_function_table(b) init_table_((b), 0x0c, "function table")
404 #define init_xlat_table(b) init_table_((b), 0x10, "xlat table");
407 init_script(struct nvkm_bios
*bios
, int index
)
409 struct nvbios_init init
= { .bios
= bios
};
410 u16 bmp_ver
= bmp_version(bios
), data
;
412 if (bmp_ver
&& bmp_ver
< 0x0510) {
413 if (index
> 1 || bmp_ver
< 0x0100)
416 data
= bios
->bmp_offset
+ (bmp_ver
< 0x0200 ? 14 : 18);
417 return nvbios_rd16(bios
, data
+ (index
* 2));
420 data
= init_script_table(&init
);
422 return nvbios_rd16(bios
, data
+ (index
* 2));
428 init_unknown_script(struct nvkm_bios
*bios
)
430 u16 len
, data
= init_table(bios
, &len
);
431 if (data
&& len
>= 16)
432 return nvbios_rd16(bios
, data
+ 14);
437 init_ram_restrict_group_count(struct nvbios_init
*init
)
439 return nvbios_ramcfg_count(init
->bios
);
443 init_ram_restrict(struct nvbios_init
*init
)
445 /* This appears to be the behaviour of the VBIOS parser, and *is*
446 * important to cache the NV_PEXTDEV_BOOT0 on later chipsets to
447 * avoid fucking up the memory controller (somehow) by reading it
448 * on every INIT_RAM_RESTRICT_ZM_GROUP opcode.
450 * Preserving the non-caching behaviour on earlier chipsets just
451 * in case *not* re-reading the strap causes similar breakage.
453 if (!init
->ramcfg
|| init
->bios
->version
.major
< 0x70)
454 init
->ramcfg
= 0x80000000 | nvbios_ramcfg_index(init
->subdev
);
455 return (init
->ramcfg
& 0x7fffffff);
459 init_xlat_(struct nvbios_init
*init
, u8 index
, u8 offset
)
461 struct nvkm_bios
*bios
= init
->bios
;
462 u16 table
= init_xlat_table(init
);
464 u16 data
= nvbios_rd16(bios
, table
+ (index
* 2));
466 return nvbios_rd08(bios
, data
+ offset
);
467 warn("xlat table pointer %d invalid\n", index
);
472 /******************************************************************************
473 * utility functions used by various init opcode handlers
474 *****************************************************************************/
477 init_condition_met(struct nvbios_init
*init
, u8 cond
)
479 struct nvkm_bios
*bios
= init
->bios
;
480 u16 table
= init_condition_table(init
);
482 u32 reg
= nvbios_rd32(bios
, table
+ (cond
* 12) + 0);
483 u32 msk
= nvbios_rd32(bios
, table
+ (cond
* 12) + 4);
484 u32 val
= nvbios_rd32(bios
, table
+ (cond
* 12) + 8);
485 trace("\t[0x%02x] (R[0x%06x] & 0x%08x) == 0x%08x\n",
486 cond
, reg
, msk
, val
);
487 return (init_rd32(init
, reg
) & msk
) == val
;
493 init_io_condition_met(struct nvbios_init
*init
, u8 cond
)
495 struct nvkm_bios
*bios
= init
->bios
;
496 u16 table
= init_io_condition_table(init
);
498 u16 port
= nvbios_rd16(bios
, table
+ (cond
* 5) + 0);
499 u8 index
= nvbios_rd08(bios
, table
+ (cond
* 5) + 2);
500 u8 mask
= nvbios_rd08(bios
, table
+ (cond
* 5) + 3);
501 u8 value
= nvbios_rd08(bios
, table
+ (cond
* 5) + 4);
502 trace("\t[0x%02x] (0x%04x[0x%02x] & 0x%02x) == 0x%02x\n",
503 cond
, port
, index
, mask
, value
);
504 return (init_rdvgai(init
, port
, index
) & mask
) == value
;
510 init_io_flag_condition_met(struct nvbios_init
*init
, u8 cond
)
512 struct nvkm_bios
*bios
= init
->bios
;
513 u16 table
= init_io_flag_condition_table(init
);
515 u16 port
= nvbios_rd16(bios
, table
+ (cond
* 9) + 0);
516 u8 index
= nvbios_rd08(bios
, table
+ (cond
* 9) + 2);
517 u8 mask
= nvbios_rd08(bios
, table
+ (cond
* 9) + 3);
518 u8 shift
= nvbios_rd08(bios
, table
+ (cond
* 9) + 4);
519 u16 data
= nvbios_rd16(bios
, table
+ (cond
* 9) + 5);
520 u8 dmask
= nvbios_rd08(bios
, table
+ (cond
* 9) + 7);
521 u8 value
= nvbios_rd08(bios
, table
+ (cond
* 9) + 8);
522 u8 ioval
= (init_rdvgai(init
, port
, index
) & mask
) >> shift
;
523 return (nvbios_rd08(bios
, data
+ ioval
) & dmask
) == value
;
529 init_shift(u32 data
, u8 shift
)
532 return data
>> shift
;
533 return data
<< (0x100 - shift
);
537 init_tmds_reg(struct nvbios_init
*init
, u8 tmds
)
539 /* For mlv < 0x80, it is an index into a table of TMDS base addresses.
540 * For mlv == 0x80 use the "or" value of the dcb_entry indexed by
541 * CR58 for CR57 = 0 to index a table of offsets to the basic
543 * For mlv == 0x81 use the "or" value of the dcb_entry indexed by
544 * CR58 for CR57 = 0 to index a table of offsets to the basic
545 * 0x6808b0 address, and then flip the offset by 8.
547 const int pramdac_offset
[13] = {
548 0, 0, 0x8, 0, 0x2000, 0, 0, 0, 0x2008, 0, 0, 0, 0x2000 };
549 const u32 pramdac_table
[4] = {
550 0x6808b0, 0x6808b8, 0x6828b0, 0x6828b8 };
554 u32 dacoffset
= pramdac_offset
[init
->outp
->or];
557 return 0x6808b0 + dacoffset
;
561 error("tmds opcodes need dcb\n");
563 if (tmds
< ARRAY_SIZE(pramdac_table
))
564 return pramdac_table
[tmds
];
566 error("tmds selector 0x%02x unknown\n", tmds
);
572 /******************************************************************************
573 * init opcode handlers
574 *****************************************************************************/
577 * init_reserved - stub for various unknown/unused single-byte opcodes
581 init_reserved(struct nvbios_init
*init
)
583 u8 opcode
= nvbios_rd08(init
->bios
, init
->offset
);
595 trace("RESERVED 0x%02x\t", opcode
);
596 for (i
= 1; i
< length
; i
++)
597 cont(" 0x%02x", nvbios_rd08(init
->bios
, init
->offset
+ i
));
599 init
->offset
+= length
;
603 * INIT_DONE - opcode 0x71
607 init_done(struct nvbios_init
*init
)
610 init
->offset
= 0x0000;
614 * INIT_IO_RESTRICT_PROG - opcode 0x32
618 init_io_restrict_prog(struct nvbios_init
*init
)
620 struct nvkm_bios
*bios
= init
->bios
;
621 u16 port
= nvbios_rd16(bios
, init
->offset
+ 1);
622 u8 index
= nvbios_rd08(bios
, init
->offset
+ 3);
623 u8 mask
= nvbios_rd08(bios
, init
->offset
+ 4);
624 u8 shift
= nvbios_rd08(bios
, init
->offset
+ 5);
625 u8 count
= nvbios_rd08(bios
, init
->offset
+ 6);
626 u32 reg
= nvbios_rd32(bios
, init
->offset
+ 7);
629 trace("IO_RESTRICT_PROG\tR[0x%06x] = "
630 "((0x%04x[0x%02x] & 0x%02x) >> %d) [{\n",
631 reg
, port
, index
, mask
, shift
);
634 conf
= (init_rdvgai(init
, port
, index
) & mask
) >> shift
;
635 for (i
= 0; i
< count
; i
++) {
636 u32 data
= nvbios_rd32(bios
, init
->offset
);
639 trace("\t0x%08x *\n", data
);
640 init_wr32(init
, reg
, data
);
642 trace("\t0x%08x\n", data
);
651 * INIT_REPEAT - opcode 0x33
655 init_repeat(struct nvbios_init
*init
)
657 struct nvkm_bios
*bios
= init
->bios
;
658 u8 count
= nvbios_rd08(bios
, init
->offset
+ 1);
659 u16 repeat
= init
->repeat
;
661 trace("REPEAT\t0x%02x\n", count
);
664 init
->repeat
= init
->offset
;
665 init
->repend
= init
->offset
;
667 init
->offset
= init
->repeat
;
670 trace("REPEAT\t0x%02x\n", count
);
672 init
->offset
= init
->repend
;
673 init
->repeat
= repeat
;
677 * INIT_IO_RESTRICT_PLL - opcode 0x34
681 init_io_restrict_pll(struct nvbios_init
*init
)
683 struct nvkm_bios
*bios
= init
->bios
;
684 u16 port
= nvbios_rd16(bios
, init
->offset
+ 1);
685 u8 index
= nvbios_rd08(bios
, init
->offset
+ 3);
686 u8 mask
= nvbios_rd08(bios
, init
->offset
+ 4);
687 u8 shift
= nvbios_rd08(bios
, init
->offset
+ 5);
688 s8 iofc
= nvbios_rd08(bios
, init
->offset
+ 6);
689 u8 count
= nvbios_rd08(bios
, init
->offset
+ 7);
690 u32 reg
= nvbios_rd32(bios
, init
->offset
+ 8);
693 trace("IO_RESTRICT_PLL\tR[0x%06x] =PLL= "
694 "((0x%04x[0x%02x] & 0x%02x) >> 0x%02x) IOFCOND 0x%02x [{\n",
695 reg
, port
, index
, mask
, shift
, iofc
);
698 conf
= (init_rdvgai(init
, port
, index
) & mask
) >> shift
;
699 for (i
= 0; i
< count
; i
++) {
700 u32 freq
= nvbios_rd16(bios
, init
->offset
) * 10;
703 trace("\t%dkHz *\n", freq
);
704 if (iofc
> 0 && init_io_flag_condition_met(init
, iofc
))
706 init_prog_pll(init
, reg
, freq
);
708 trace("\t%dkHz\n", freq
);
717 * INIT_END_REPEAT - opcode 0x36
721 init_end_repeat(struct nvbios_init
*init
)
723 trace("END_REPEAT\n");
727 init
->repend
= init
->offset
;
733 * INIT_COPY - opcode 0x37
737 init_copy(struct nvbios_init
*init
)
739 struct nvkm_bios
*bios
= init
->bios
;
740 u32 reg
= nvbios_rd32(bios
, init
->offset
+ 1);
741 u8 shift
= nvbios_rd08(bios
, init
->offset
+ 5);
742 u8 smask
= nvbios_rd08(bios
, init
->offset
+ 6);
743 u16 port
= nvbios_rd16(bios
, init
->offset
+ 7);
744 u8 index
= nvbios_rd08(bios
, init
->offset
+ 9);
745 u8 mask
= nvbios_rd08(bios
, init
->offset
+ 10);
748 trace("COPY\t0x%04x[0x%02x] &= 0x%02x |= "
749 "((R[0x%06x] %s 0x%02x) & 0x%02x)\n",
750 port
, index
, mask
, reg
, (shift
& 0x80) ? "<<" : ">>",
751 (shift
& 0x80) ? (0x100 - shift
) : shift
, smask
);
754 data
= init_rdvgai(init
, port
, index
) & mask
;
755 data
|= init_shift(init_rd32(init
, reg
), shift
) & smask
;
756 init_wrvgai(init
, port
, index
, data
);
760 * INIT_NOT - opcode 0x38
764 init_not(struct nvbios_init
*init
)
772 * INIT_IO_FLAG_CONDITION - opcode 0x39
776 init_io_flag_condition(struct nvbios_init
*init
)
778 struct nvkm_bios
*bios
= init
->bios
;
779 u8 cond
= nvbios_rd08(bios
, init
->offset
+ 1);
781 trace("IO_FLAG_CONDITION\t0x%02x\n", cond
);
784 if (!init_io_flag_condition_met(init
, cond
))
785 init_exec_set(init
, false);
789 * INIT_DP_CONDITION - opcode 0x3a
793 init_dp_condition(struct nvbios_init
*init
)
795 struct nvkm_bios
*bios
= init
->bios
;
796 struct nvbios_dpout info
;
797 u8 cond
= nvbios_rd08(bios
, init
->offset
+ 1);
798 u8 unkn
= nvbios_rd08(bios
, init
->offset
+ 2);
799 u8 ver
, hdr
, cnt
, len
;
802 trace("DP_CONDITION\t0x%02x 0x%02x\n", cond
, unkn
);
807 if (init_conn(init
) != DCB_CONNECTOR_eDP
)
808 init_exec_set(init
, false);
813 (data
= nvbios_dpout_match(bios
, DCB_OUTPUT_DP
,
814 (init
->outp
->or << 0) |
815 (init
->outp
->sorconf
.link
<< 6),
816 &ver
, &hdr
, &cnt
, &len
, &info
)))
818 if (!(info
.flags
& cond
))
819 init_exec_set(init
, false);
824 warn("script needs dp output table data\n");
827 if (!(init_rdauxr(init
, 0x0d) & 1))
828 init_exec_set(init
, false);
831 warn("unknown dp condition 0x%02x\n", cond
);
837 * INIT_IO_MASK_OR - opcode 0x3b
841 init_io_mask_or(struct nvbios_init
*init
)
843 struct nvkm_bios
*bios
= init
->bios
;
844 u8 index
= nvbios_rd08(bios
, init
->offset
+ 1);
845 u8
or = init_or(init
);
848 trace("IO_MASK_OR\t0x03d4[0x%02x] &= ~(1 << 0x%02x)\n", index
, or);
851 data
= init_rdvgai(init
, 0x03d4, index
);
852 init_wrvgai(init
, 0x03d4, index
, data
&= ~(1 << or));
856 * INIT_IO_OR - opcode 0x3c
860 init_io_or(struct nvbios_init
*init
)
862 struct nvkm_bios
*bios
= init
->bios
;
863 u8 index
= nvbios_rd08(bios
, init
->offset
+ 1);
864 u8
or = init_or(init
);
867 trace("IO_OR\t0x03d4[0x%02x] |= (1 << 0x%02x)\n", index
, or);
870 data
= init_rdvgai(init
, 0x03d4, index
);
871 init_wrvgai(init
, 0x03d4, index
, data
| (1 << or));
875 * INIT_ANDN_REG - opcode 0x47
879 init_andn_reg(struct nvbios_init
*init
)
881 struct nvkm_bios
*bios
= init
->bios
;
882 u32 reg
= nvbios_rd32(bios
, init
->offset
+ 1);
883 u32 mask
= nvbios_rd32(bios
, init
->offset
+ 5);
885 trace("ANDN_REG\tR[0x%06x] &= ~0x%08x\n", reg
, mask
);
888 init_mask(init
, reg
, mask
, 0);
892 * INIT_OR_REG - opcode 0x48
896 init_or_reg(struct nvbios_init
*init
)
898 struct nvkm_bios
*bios
= init
->bios
;
899 u32 reg
= nvbios_rd32(bios
, init
->offset
+ 1);
900 u32 mask
= nvbios_rd32(bios
, init
->offset
+ 5);
902 trace("OR_REG\tR[0x%06x] |= 0x%08x\n", reg
, mask
);
905 init_mask(init
, reg
, 0, mask
);
909 * INIT_INDEX_ADDRESS_LATCHED - opcode 0x49
913 init_idx_addr_latched(struct nvbios_init
*init
)
915 struct nvkm_bios
*bios
= init
->bios
;
916 u32 creg
= nvbios_rd32(bios
, init
->offset
+ 1);
917 u32 dreg
= nvbios_rd32(bios
, init
->offset
+ 5);
918 u32 mask
= nvbios_rd32(bios
, init
->offset
+ 9);
919 u32 data
= nvbios_rd32(bios
, init
->offset
+ 13);
920 u8 count
= nvbios_rd08(bios
, init
->offset
+ 17);
922 trace("INDEX_ADDRESS_LATCHED\tR[0x%06x] : R[0x%06x]\n", creg
, dreg
);
923 trace("\tCTRL &= 0x%08x |= 0x%08x\n", mask
, data
);
927 u8 iaddr
= nvbios_rd08(bios
, init
->offset
+ 0);
928 u8 idata
= nvbios_rd08(bios
, init
->offset
+ 1);
930 trace("\t[0x%02x] = 0x%02x\n", iaddr
, idata
);
933 init_wr32(init
, dreg
, idata
);
934 init_mask(init
, creg
, ~mask
, data
| iaddr
);
939 * INIT_IO_RESTRICT_PLL2 - opcode 0x4a
943 init_io_restrict_pll2(struct nvbios_init
*init
)
945 struct nvkm_bios
*bios
= init
->bios
;
946 u16 port
= nvbios_rd16(bios
, init
->offset
+ 1);
947 u8 index
= nvbios_rd08(bios
, init
->offset
+ 3);
948 u8 mask
= nvbios_rd08(bios
, init
->offset
+ 4);
949 u8 shift
= nvbios_rd08(bios
, init
->offset
+ 5);
950 u8 count
= nvbios_rd08(bios
, init
->offset
+ 6);
951 u32 reg
= nvbios_rd32(bios
, init
->offset
+ 7);
954 trace("IO_RESTRICT_PLL2\t"
955 "R[0x%06x] =PLL= ((0x%04x[0x%02x] & 0x%02x) >> 0x%02x) [{\n",
956 reg
, port
, index
, mask
, shift
);
959 conf
= (init_rdvgai(init
, port
, index
) & mask
) >> shift
;
960 for (i
= 0; i
< count
; i
++) {
961 u32 freq
= nvbios_rd32(bios
, init
->offset
);
963 trace("\t%dkHz *\n", freq
);
964 init_prog_pll(init
, reg
, freq
);
966 trace("\t%dkHz\n", freq
);
974 * INIT_PLL2 - opcode 0x4b
978 init_pll2(struct nvbios_init
*init
)
980 struct nvkm_bios
*bios
= init
->bios
;
981 u32 reg
= nvbios_rd32(bios
, init
->offset
+ 1);
982 u32 freq
= nvbios_rd32(bios
, init
->offset
+ 5);
984 trace("PLL2\tR[0x%06x] =PLL= %dkHz\n", reg
, freq
);
987 init_prog_pll(init
, reg
, freq
);
991 * INIT_I2C_BYTE - opcode 0x4c
995 init_i2c_byte(struct nvbios_init
*init
)
997 struct nvkm_bios
*bios
= init
->bios
;
998 u8 index
= nvbios_rd08(bios
, init
->offset
+ 1);
999 u8 addr
= nvbios_rd08(bios
, init
->offset
+ 2) >> 1;
1000 u8 count
= nvbios_rd08(bios
, init
->offset
+ 3);
1002 trace("I2C_BYTE\tI2C[0x%02x][0x%02x]\n", index
, addr
);
1006 u8 reg
= nvbios_rd08(bios
, init
->offset
+ 0);
1007 u8 mask
= nvbios_rd08(bios
, init
->offset
+ 1);
1008 u8 data
= nvbios_rd08(bios
, init
->offset
+ 2);
1011 trace("\t[0x%02x] &= 0x%02x |= 0x%02x\n", reg
, mask
, data
);
1014 val
= init_rdi2cr(init
, index
, addr
, reg
);
1017 init_wri2cr(init
, index
, addr
, reg
, (val
& mask
) | data
);
1022 * INIT_ZM_I2C_BYTE - opcode 0x4d
1026 init_zm_i2c_byte(struct nvbios_init
*init
)
1028 struct nvkm_bios
*bios
= init
->bios
;
1029 u8 index
= nvbios_rd08(bios
, init
->offset
+ 1);
1030 u8 addr
= nvbios_rd08(bios
, init
->offset
+ 2) >> 1;
1031 u8 count
= nvbios_rd08(bios
, init
->offset
+ 3);
1033 trace("ZM_I2C_BYTE\tI2C[0x%02x][0x%02x]\n", index
, addr
);
1037 u8 reg
= nvbios_rd08(bios
, init
->offset
+ 0);
1038 u8 data
= nvbios_rd08(bios
, init
->offset
+ 1);
1040 trace("\t[0x%02x] = 0x%02x\n", reg
, data
);
1043 init_wri2cr(init
, index
, addr
, reg
, data
);
1048 * INIT_ZM_I2C - opcode 0x4e
1052 init_zm_i2c(struct nvbios_init
*init
)
1054 struct nvkm_bios
*bios
= init
->bios
;
1055 u8 index
= nvbios_rd08(bios
, init
->offset
+ 1);
1056 u8 addr
= nvbios_rd08(bios
, init
->offset
+ 2) >> 1;
1057 u8 count
= nvbios_rd08(bios
, init
->offset
+ 3);
1060 trace("ZM_I2C\tI2C[0x%02x][0x%02x]\n", index
, addr
);
1063 for (i
= 0; i
< count
; i
++) {
1064 data
[i
] = nvbios_rd08(bios
, init
->offset
);
1065 trace("\t0x%02x\n", data
[i
]);
1069 if (init_exec(init
)) {
1070 struct i2c_adapter
*adap
= init_i2c(init
, index
);
1071 struct i2c_msg msg
= {
1072 .addr
= addr
, .flags
= 0, .len
= count
, .buf
= data
,
1076 if (adap
&& (ret
= i2c_transfer(adap
, &msg
, 1)) != 1)
1077 warn("i2c wr failed, %d\n", ret
);
1082 * INIT_TMDS - opcode 0x4f
1086 init_tmds(struct nvbios_init
*init
)
1088 struct nvkm_bios
*bios
= init
->bios
;
1089 u8 tmds
= nvbios_rd08(bios
, init
->offset
+ 1);
1090 u8 addr
= nvbios_rd08(bios
, init
->offset
+ 2);
1091 u8 mask
= nvbios_rd08(bios
, init
->offset
+ 3);
1092 u8 data
= nvbios_rd08(bios
, init
->offset
+ 4);
1093 u32 reg
= init_tmds_reg(init
, tmds
);
1095 trace("TMDS\tT[0x%02x][0x%02x] &= 0x%02x |= 0x%02x\n",
1096 tmds
, addr
, mask
, data
);
1102 init_wr32(init
, reg
+ 0, addr
| 0x00010000);
1103 init_wr32(init
, reg
+ 4, data
| (init_rd32(init
, reg
+ 4) & mask
));
1104 init_wr32(init
, reg
+ 0, addr
);
1108 * INIT_ZM_TMDS_GROUP - opcode 0x50
1112 init_zm_tmds_group(struct nvbios_init
*init
)
1114 struct nvkm_bios
*bios
= init
->bios
;
1115 u8 tmds
= nvbios_rd08(bios
, init
->offset
+ 1);
1116 u8 count
= nvbios_rd08(bios
, init
->offset
+ 2);
1117 u32 reg
= init_tmds_reg(init
, tmds
);
1119 trace("TMDS_ZM_GROUP\tT[0x%02x]\n", tmds
);
1123 u8 addr
= nvbios_rd08(bios
, init
->offset
+ 0);
1124 u8 data
= nvbios_rd08(bios
, init
->offset
+ 1);
1126 trace("\t[0x%02x] = 0x%02x\n", addr
, data
);
1129 init_wr32(init
, reg
+ 4, data
);
1130 init_wr32(init
, reg
+ 0, addr
);
1135 * INIT_CR_INDEX_ADDRESS_LATCHED - opcode 0x51
1139 init_cr_idx_adr_latch(struct nvbios_init
*init
)
1141 struct nvkm_bios
*bios
= init
->bios
;
1142 u8 addr0
= nvbios_rd08(bios
, init
->offset
+ 1);
1143 u8 addr1
= nvbios_rd08(bios
, init
->offset
+ 2);
1144 u8 base
= nvbios_rd08(bios
, init
->offset
+ 3);
1145 u8 count
= nvbios_rd08(bios
, init
->offset
+ 4);
1148 trace("CR_INDEX_ADDR C[%02x] C[%02x]\n", addr0
, addr1
);
1151 save0
= init_rdvgai(init
, 0x03d4, addr0
);
1153 u8 data
= nvbios_rd08(bios
, init
->offset
);
1155 trace("\t\t[0x%02x] = 0x%02x\n", base
, data
);
1158 init_wrvgai(init
, 0x03d4, addr0
, base
++);
1159 init_wrvgai(init
, 0x03d4, addr1
, data
);
1161 init_wrvgai(init
, 0x03d4, addr0
, save0
);
1165 * INIT_CR - opcode 0x52
1169 init_cr(struct nvbios_init
*init
)
1171 struct nvkm_bios
*bios
= init
->bios
;
1172 u8 addr
= nvbios_rd08(bios
, init
->offset
+ 1);
1173 u8 mask
= nvbios_rd08(bios
, init
->offset
+ 2);
1174 u8 data
= nvbios_rd08(bios
, init
->offset
+ 3);
1177 trace("CR\t\tC[0x%02x] &= 0x%02x |= 0x%02x\n", addr
, mask
, data
);
1180 val
= init_rdvgai(init
, 0x03d4, addr
) & mask
;
1181 init_wrvgai(init
, 0x03d4, addr
, val
| data
);
1185 * INIT_ZM_CR - opcode 0x53
1189 init_zm_cr(struct nvbios_init
*init
)
1191 struct nvkm_bios
*bios
= init
->bios
;
1192 u8 addr
= nvbios_rd08(bios
, init
->offset
+ 1);
1193 u8 data
= nvbios_rd08(bios
, init
->offset
+ 2);
1195 trace("ZM_CR\tC[0x%02x] = 0x%02x\n", addr
, data
);
1198 init_wrvgai(init
, 0x03d4, addr
, data
);
1202 * INIT_ZM_CR_GROUP - opcode 0x54
1206 init_zm_cr_group(struct nvbios_init
*init
)
1208 struct nvkm_bios
*bios
= init
->bios
;
1209 u8 count
= nvbios_rd08(bios
, init
->offset
+ 1);
1211 trace("ZM_CR_GROUP\n");
1215 u8 addr
= nvbios_rd08(bios
, init
->offset
+ 0);
1216 u8 data
= nvbios_rd08(bios
, init
->offset
+ 1);
1218 trace("\t\tC[0x%02x] = 0x%02x\n", addr
, data
);
1221 init_wrvgai(init
, 0x03d4, addr
, data
);
1226 * INIT_CONDITION_TIME - opcode 0x56
1230 init_condition_time(struct nvbios_init
*init
)
1232 struct nvkm_bios
*bios
= init
->bios
;
1233 u8 cond
= nvbios_rd08(bios
, init
->offset
+ 1);
1234 u8 retry
= nvbios_rd08(bios
, init
->offset
+ 2);
1235 u8 wait
= min((u16
)retry
* 50, 100);
1237 trace("CONDITION_TIME\t0x%02x 0x%02x\n", cond
, retry
);
1240 if (!init_exec(init
))
1244 if (init_condition_met(init
, cond
))
1249 init_exec_set(init
, false);
1253 * INIT_LTIME - opcode 0x57
1257 init_ltime(struct nvbios_init
*init
)
1259 struct nvkm_bios
*bios
= init
->bios
;
1260 u16 msec
= nvbios_rd16(bios
, init
->offset
+ 1);
1262 trace("LTIME\t0x%04x\n", msec
);
1265 if (init_exec(init
))
1270 * INIT_ZM_REG_SEQUENCE - opcode 0x58
1274 init_zm_reg_sequence(struct nvbios_init
*init
)
1276 struct nvkm_bios
*bios
= init
->bios
;
1277 u32 base
= nvbios_rd32(bios
, init
->offset
+ 1);
1278 u8 count
= nvbios_rd08(bios
, init
->offset
+ 5);
1280 trace("ZM_REG_SEQUENCE\t0x%02x\n", count
);
1284 u32 data
= nvbios_rd32(bios
, init
->offset
);
1286 trace("\t\tR[0x%06x] = 0x%08x\n", base
, data
);
1289 init_wr32(init
, base
, data
);
1295 * INIT_PLL_INDIRECT - opcode 0x59
1299 init_pll_indirect(struct nvbios_init
*init
)
1301 struct nvkm_bios
*bios
= init
->bios
;
1302 u32 reg
= nvbios_rd32(bios
, init
->offset
+ 1);
1303 u16 addr
= nvbios_rd16(bios
, init
->offset
+ 5);
1304 u32 freq
= (u32
)nvbios_rd16(bios
, addr
) * 1000;
1306 trace("PLL_INDIRECT\tR[0x%06x] =PLL= VBIOS[%04x] = %dkHz\n",
1310 init_prog_pll(init
, reg
, freq
);
1314 * INIT_ZM_REG_INDIRECT - opcode 0x5a
1318 init_zm_reg_indirect(struct nvbios_init
*init
)
1320 struct nvkm_bios
*bios
= init
->bios
;
1321 u32 reg
= nvbios_rd32(bios
, init
->offset
+ 1);
1322 u16 addr
= nvbios_rd16(bios
, init
->offset
+ 5);
1323 u32 data
= nvbios_rd32(bios
, addr
);
1325 trace("ZM_REG_INDIRECT\tR[0x%06x] = VBIOS[0x%04x] = 0x%08x\n",
1329 init_wr32(init
, addr
, data
);
1333 * INIT_SUB_DIRECT - opcode 0x5b
1337 init_sub_direct(struct nvbios_init
*init
)
1339 struct nvkm_bios
*bios
= init
->bios
;
1340 u16 addr
= nvbios_rd16(bios
, init
->offset
+ 1);
1343 trace("SUB_DIRECT\t0x%04x\n", addr
);
1345 if (init_exec(init
)) {
1346 save
= init
->offset
;
1347 init
->offset
= addr
;
1348 if (nvbios_exec(init
)) {
1349 error("error parsing sub-table\n");
1352 init
->offset
= save
;
1359 * INIT_JUMP - opcode 0x5c
1363 init_jump(struct nvbios_init
*init
)
1365 struct nvkm_bios
*bios
= init
->bios
;
1366 u16 offset
= nvbios_rd16(bios
, init
->offset
+ 1);
1368 trace("JUMP\t0x%04x\n", offset
);
1370 if (init_exec(init
))
1371 init
->offset
= offset
;
1377 * INIT_I2C_IF - opcode 0x5e
1381 init_i2c_if(struct nvbios_init
*init
)
1383 struct nvkm_bios
*bios
= init
->bios
;
1384 u8 index
= nvbios_rd08(bios
, init
->offset
+ 1);
1385 u8 addr
= nvbios_rd08(bios
, init
->offset
+ 2);
1386 u8 reg
= nvbios_rd08(bios
, init
->offset
+ 3);
1387 u8 mask
= nvbios_rd08(bios
, init
->offset
+ 4);
1388 u8 data
= nvbios_rd08(bios
, init
->offset
+ 5);
1391 trace("I2C_IF\tI2C[0x%02x][0x%02x][0x%02x] & 0x%02x == 0x%02x\n",
1392 index
, addr
, reg
, mask
, data
);
1394 init_exec_force(init
, true);
1396 value
= init_rdi2cr(init
, index
, addr
, reg
);
1397 if ((value
& mask
) != data
)
1398 init_exec_set(init
, false);
1400 init_exec_force(init
, false);
1404 * INIT_COPY_NV_REG - opcode 0x5f
1408 init_copy_nv_reg(struct nvbios_init
*init
)
1410 struct nvkm_bios
*bios
= init
->bios
;
1411 u32 sreg
= nvbios_rd32(bios
, init
->offset
+ 1);
1412 u8 shift
= nvbios_rd08(bios
, init
->offset
+ 5);
1413 u32 smask
= nvbios_rd32(bios
, init
->offset
+ 6);
1414 u32 sxor
= nvbios_rd32(bios
, init
->offset
+ 10);
1415 u32 dreg
= nvbios_rd32(bios
, init
->offset
+ 14);
1416 u32 dmask
= nvbios_rd32(bios
, init
->offset
+ 18);
1419 trace("COPY_NV_REG\tR[0x%06x] &= 0x%08x |= "
1420 "((R[0x%06x] %s 0x%02x) & 0x%08x ^ 0x%08x)\n",
1421 dreg
, dmask
, sreg
, (shift
& 0x80) ? "<<" : ">>",
1422 (shift
& 0x80) ? (0x100 - shift
) : shift
, smask
, sxor
);
1425 data
= init_shift(init_rd32(init
, sreg
), shift
);
1426 init_mask(init
, dreg
, ~dmask
, (data
& smask
) ^ sxor
);
1430 * INIT_ZM_INDEX_IO - opcode 0x62
1434 init_zm_index_io(struct nvbios_init
*init
)
1436 struct nvkm_bios
*bios
= init
->bios
;
1437 u16 port
= nvbios_rd16(bios
, init
->offset
+ 1);
1438 u8 index
= nvbios_rd08(bios
, init
->offset
+ 3);
1439 u8 data
= nvbios_rd08(bios
, init
->offset
+ 4);
1441 trace("ZM_INDEX_IO\tI[0x%04x][0x%02x] = 0x%02x\n", port
, index
, data
);
1444 init_wrvgai(init
, port
, index
, data
);
1448 * INIT_COMPUTE_MEM - opcode 0x63
1452 init_compute_mem(struct nvbios_init
*init
)
1454 struct nvkm_devinit
*devinit
= init
->bios
->subdev
.device
->devinit
;
1456 trace("COMPUTE_MEM\n");
1459 init_exec_force(init
, true);
1460 if (init_exec(init
))
1461 nvkm_devinit_meminit(devinit
);
1462 init_exec_force(init
, false);
1466 * INIT_RESET - opcode 0x65
1470 init_reset(struct nvbios_init
*init
)
1472 struct nvkm_bios
*bios
= init
->bios
;
1473 u32 reg
= nvbios_rd32(bios
, init
->offset
+ 1);
1474 u32 data1
= nvbios_rd32(bios
, init
->offset
+ 5);
1475 u32 data2
= nvbios_rd32(bios
, init
->offset
+ 9);
1478 trace("RESET\tR[0x%08x] = 0x%08x, 0x%08x", reg
, data1
, data2
);
1480 init_exec_force(init
, true);
1482 savepci19
= init_mask(init
, 0x00184c, 0x00000f00, 0x00000000);
1483 init_wr32(init
, reg
, data1
);
1485 init_wr32(init
, reg
, data2
);
1486 init_wr32(init
, 0x00184c, savepci19
);
1487 init_mask(init
, 0x001850, 0x00000001, 0x00000000);
1489 init_exec_force(init
, false);
1493 * INIT_CONFIGURE_MEM - opcode 0x66
1497 init_configure_mem_clk(struct nvbios_init
*init
)
1499 u16 mdata
= bmp_mem_init_table(init
->bios
);
1501 mdata
+= (init_rdvgai(init
, 0x03d4, 0x3c) >> 4) * 66;
1506 init_configure_mem(struct nvbios_init
*init
)
1508 struct nvkm_bios
*bios
= init
->bios
;
1512 trace("CONFIGURE_MEM\n");
1515 if (bios
->version
.major
> 2) {
1519 init_exec_force(init
, true);
1521 mdata
= init_configure_mem_clk(init
);
1522 sdata
= bmp_sdr_seq_table(bios
);
1523 if (nvbios_rd08(bios
, mdata
) & 0x01)
1524 sdata
= bmp_ddr_seq_table(bios
);
1525 mdata
+= 6; /* skip to data */
1527 data
= init_rdvgai(init
, 0x03c4, 0x01);
1528 init_wrvgai(init
, 0x03c4, 0x01, data
| 0x20);
1530 for (; (addr
= nvbios_rd32(bios
, sdata
)) != 0xffffffff; sdata
+= 4) {
1532 case 0x10021c: /* CKE_NORMAL */
1533 case 0x1002d0: /* CMD_REFRESH */
1534 case 0x1002d4: /* CMD_PRECHARGE */
1538 data
= nvbios_rd32(bios
, mdata
);
1540 if (data
== 0xffffffff)
1545 init_wr32(init
, addr
, data
);
1548 init_exec_force(init
, false);
1552 * INIT_CONFIGURE_CLK - opcode 0x67
1556 init_configure_clk(struct nvbios_init
*init
)
1558 struct nvkm_bios
*bios
= init
->bios
;
1561 trace("CONFIGURE_CLK\n");
1564 if (bios
->version
.major
> 2) {
1568 init_exec_force(init
, true);
1570 mdata
= init_configure_mem_clk(init
);
1573 clock
= nvbios_rd16(bios
, mdata
+ 4) * 10;
1574 init_prog_pll(init
, 0x680500, clock
);
1577 clock
= nvbios_rd16(bios
, mdata
+ 2) * 10;
1578 if (nvbios_rd08(bios
, mdata
) & 0x01)
1580 init_prog_pll(init
, 0x680504, clock
);
1582 init_exec_force(init
, false);
1586 * INIT_CONFIGURE_PREINIT - opcode 0x68
1590 init_configure_preinit(struct nvbios_init
*init
)
1592 struct nvkm_bios
*bios
= init
->bios
;
1595 trace("CONFIGURE_PREINIT\n");
1598 if (bios
->version
.major
> 2) {
1602 init_exec_force(init
, true);
1604 strap
= init_rd32(init
, 0x101000);
1605 strap
= ((strap
<< 2) & 0xf0) | ((strap
& 0x40) >> 6);
1606 init_wrvgai(init
, 0x03d4, 0x3c, strap
);
1608 init_exec_force(init
, false);
1612 * INIT_IO - opcode 0x69
1616 init_io(struct nvbios_init
*init
)
1618 struct nvkm_bios
*bios
= init
->bios
;
1619 u16 port
= nvbios_rd16(bios
, init
->offset
+ 1);
1620 u8 mask
= nvbios_rd16(bios
, init
->offset
+ 3);
1621 u8 data
= nvbios_rd16(bios
, init
->offset
+ 4);
1624 trace("IO\t\tI[0x%04x] &= 0x%02x |= 0x%02x\n", port
, mask
, data
);
1627 /* ummm.. yes.. should really figure out wtf this is and why it's
1628 * needed some day.. it's almost certainly wrong, but, it also
1629 * somehow makes things work...
1631 if (bios
->subdev
.device
->card_type
>= NV_50
&&
1632 port
== 0x03c3 && data
== 0x01) {
1633 init_mask(init
, 0x614100, 0xf0800000, 0x00800000);
1634 init_mask(init
, 0x00e18c, 0x00020000, 0x00020000);
1635 init_mask(init
, 0x614900, 0xf0800000, 0x00800000);
1636 init_mask(init
, 0x000200, 0x40000000, 0x00000000);
1638 init_mask(init
, 0x00e18c, 0x00020000, 0x00000000);
1639 init_mask(init
, 0x000200, 0x40000000, 0x40000000);
1640 init_wr32(init
, 0x614100, 0x00800018);
1641 init_wr32(init
, 0x614900, 0x00800018);
1643 init_wr32(init
, 0x614100, 0x10000018);
1644 init_wr32(init
, 0x614900, 0x10000018);
1647 value
= init_rdport(init
, port
) & mask
;
1648 init_wrport(init
, port
, data
| value
);
1652 * INIT_SUB - opcode 0x6b
1656 init_sub(struct nvbios_init
*init
)
1658 struct nvkm_bios
*bios
= init
->bios
;
1659 u8 index
= nvbios_rd08(bios
, init
->offset
+ 1);
1662 trace("SUB\t0x%02x\n", index
);
1664 addr
= init_script(bios
, index
);
1665 if (addr
&& init_exec(init
)) {
1666 save
= init
->offset
;
1667 init
->offset
= addr
;
1668 if (nvbios_exec(init
)) {
1669 error("error parsing sub-table\n");
1672 init
->offset
= save
;
1679 * INIT_RAM_CONDITION - opcode 0x6d
1683 init_ram_condition(struct nvbios_init
*init
)
1685 struct nvkm_bios
*bios
= init
->bios
;
1686 u8 mask
= nvbios_rd08(bios
, init
->offset
+ 1);
1687 u8 value
= nvbios_rd08(bios
, init
->offset
+ 2);
1689 trace("RAM_CONDITION\t"
1690 "(R[0x100000] & 0x%02x) == 0x%02x\n", mask
, value
);
1693 if ((init_rd32(init
, 0x100000) & mask
) != value
)
1694 init_exec_set(init
, false);
1698 * INIT_NV_REG - opcode 0x6e
1702 init_nv_reg(struct nvbios_init
*init
)
1704 struct nvkm_bios
*bios
= init
->bios
;
1705 u32 reg
= nvbios_rd32(bios
, init
->offset
+ 1);
1706 u32 mask
= nvbios_rd32(bios
, init
->offset
+ 5);
1707 u32 data
= nvbios_rd32(bios
, init
->offset
+ 9);
1709 trace("NV_REG\tR[0x%06x] &= 0x%08x |= 0x%08x\n", reg
, mask
, data
);
1712 init_mask(init
, reg
, ~mask
, data
);
1716 * INIT_MACRO - opcode 0x6f
1720 init_macro(struct nvbios_init
*init
)
1722 struct nvkm_bios
*bios
= init
->bios
;
1723 u8 macro
= nvbios_rd08(bios
, init
->offset
+ 1);
1726 trace("MACRO\t0x%02x\n", macro
);
1728 table
= init_macro_table(init
);
1730 u32 addr
= nvbios_rd32(bios
, table
+ (macro
* 8) + 0);
1731 u32 data
= nvbios_rd32(bios
, table
+ (macro
* 8) + 4);
1732 trace("\t\tR[0x%06x] = 0x%08x\n", addr
, data
);
1733 init_wr32(init
, addr
, data
);
1740 * INIT_RESUME - opcode 0x72
1744 init_resume(struct nvbios_init
*init
)
1748 init_exec_set(init
, true);
1752 * INIT_STRAP_CONDITION - opcode 0x73
1756 init_strap_condition(struct nvbios_init
*init
)
1758 struct nvkm_bios
*bios
= init
->bios
;
1759 u32 mask
= nvbios_rd32(bios
, init
->offset
+ 1);
1760 u32 value
= nvbios_rd32(bios
, init
->offset
+ 5);
1762 trace("STRAP_CONDITION\t(R[0x101000] & 0x%08x) == 0x%08x\n", mask
, value
);
1765 if ((init_rd32(init
, 0x101000) & mask
) != value
)
1766 init_exec_set(init
, false);
1770 * INIT_TIME - opcode 0x74
1774 init_time(struct nvbios_init
*init
)
1776 struct nvkm_bios
*bios
= init
->bios
;
1777 u16 usec
= nvbios_rd16(bios
, init
->offset
+ 1);
1779 trace("TIME\t0x%04x\n", usec
);
1782 if (init_exec(init
)) {
1786 mdelay((usec
+ 900) / 1000);
1791 * INIT_CONDITION - opcode 0x75
1795 init_condition(struct nvbios_init
*init
)
1797 struct nvkm_bios
*bios
= init
->bios
;
1798 u8 cond
= nvbios_rd08(bios
, init
->offset
+ 1);
1800 trace("CONDITION\t0x%02x\n", cond
);
1803 if (!init_condition_met(init
, cond
))
1804 init_exec_set(init
, false);
1808 * INIT_IO_CONDITION - opcode 0x76
1812 init_io_condition(struct nvbios_init
*init
)
1814 struct nvkm_bios
*bios
= init
->bios
;
1815 u8 cond
= nvbios_rd08(bios
, init
->offset
+ 1);
1817 trace("IO_CONDITION\t0x%02x\n", cond
);
1820 if (!init_io_condition_met(init
, cond
))
1821 init_exec_set(init
, false);
1825 * INIT_ZM_REG16 - opcode 0x77
1829 init_zm_reg16(struct nvbios_init
*init
)
1831 struct nvkm_bios
*bios
= init
->bios
;
1832 u32 addr
= nvbios_rd32(bios
, init
->offset
+ 1);
1833 u16 data
= nvbios_rd16(bios
, init
->offset
+ 5);
1835 trace("ZM_REG\tR[0x%06x] = 0x%04x\n", addr
, data
);
1838 init_wr32(init
, addr
, data
);
1842 * INIT_INDEX_IO - opcode 0x78
1846 init_index_io(struct nvbios_init
*init
)
1848 struct nvkm_bios
*bios
= init
->bios
;
1849 u16 port
= nvbios_rd16(bios
, init
->offset
+ 1);
1850 u8 index
= nvbios_rd16(bios
, init
->offset
+ 3);
1851 u8 mask
= nvbios_rd08(bios
, init
->offset
+ 4);
1852 u8 data
= nvbios_rd08(bios
, init
->offset
+ 5);
1855 trace("INDEX_IO\tI[0x%04x][0x%02x] &= 0x%02x |= 0x%02x\n",
1856 port
, index
, mask
, data
);
1859 value
= init_rdvgai(init
, port
, index
) & mask
;
1860 init_wrvgai(init
, port
, index
, data
| value
);
1864 * INIT_PLL - opcode 0x79
1868 init_pll(struct nvbios_init
*init
)
1870 struct nvkm_bios
*bios
= init
->bios
;
1871 u32 reg
= nvbios_rd32(bios
, init
->offset
+ 1);
1872 u32 freq
= nvbios_rd16(bios
, init
->offset
+ 5) * 10;
1874 trace("PLL\tR[0x%06x] =PLL= %dkHz\n", reg
, freq
);
1877 init_prog_pll(init
, reg
, freq
);
1881 * INIT_ZM_REG - opcode 0x7a
1885 init_zm_reg(struct nvbios_init
*init
)
1887 struct nvkm_bios
*bios
= init
->bios
;
1888 u32 addr
= nvbios_rd32(bios
, init
->offset
+ 1);
1889 u32 data
= nvbios_rd32(bios
, init
->offset
+ 5);
1891 trace("ZM_REG\tR[0x%06x] = 0x%08x\n", addr
, data
);
1894 if (addr
== 0x000200)
1897 init_wr32(init
, addr
, data
);
1901 * INIT_RAM_RESTRICT_PLL - opcde 0x87
1905 init_ram_restrict_pll(struct nvbios_init
*init
)
1907 struct nvkm_bios
*bios
= init
->bios
;
1908 u8 type
= nvbios_rd08(bios
, init
->offset
+ 1);
1909 u8 count
= init_ram_restrict_group_count(init
);
1910 u8 strap
= init_ram_restrict(init
);
1913 trace("RAM_RESTRICT_PLL\t0x%02x\n", type
);
1916 for (cconf
= 0; cconf
< count
; cconf
++) {
1917 u32 freq
= nvbios_rd32(bios
, init
->offset
);
1919 if (cconf
== strap
) {
1920 trace("%dkHz *\n", freq
);
1921 init_prog_pll(init
, type
, freq
);
1923 trace("%dkHz\n", freq
);
1931 * INIT_GPIO - opcode 0x8e
1935 init_gpio(struct nvbios_init
*init
)
1937 struct nvkm_gpio
*gpio
= init
->bios
->subdev
.device
->gpio
;
1942 if (init_exec(init
))
1943 nvkm_gpio_reset(gpio
, DCB_GPIO_UNUSED
);
1947 * INIT_RAM_RESTRICT_ZM_GROUP - opcode 0x8f
1951 init_ram_restrict_zm_reg_group(struct nvbios_init
*init
)
1953 struct nvkm_bios
*bios
= init
->bios
;
1954 u32 addr
= nvbios_rd32(bios
, init
->offset
+ 1);
1955 u8 incr
= nvbios_rd08(bios
, init
->offset
+ 5);
1956 u8 num
= nvbios_rd08(bios
, init
->offset
+ 6);
1957 u8 count
= init_ram_restrict_group_count(init
);
1958 u8 index
= init_ram_restrict(init
);
1961 trace("RAM_RESTRICT_ZM_REG_GROUP\t"
1962 "R[0x%08x] 0x%02x 0x%02x\n", addr
, incr
, num
);
1965 for (i
= 0; i
< num
; i
++) {
1966 trace("\tR[0x%06x] = {\n", addr
);
1967 for (j
= 0; j
< count
; j
++) {
1968 u32 data
= nvbios_rd32(bios
, init
->offset
);
1971 trace("\t\t0x%08x *\n", data
);
1972 init_wr32(init
, addr
, data
);
1974 trace("\t\t0x%08x\n", data
);
1985 * INIT_COPY_ZM_REG - opcode 0x90
1989 init_copy_zm_reg(struct nvbios_init
*init
)
1991 struct nvkm_bios
*bios
= init
->bios
;
1992 u32 sreg
= nvbios_rd32(bios
, init
->offset
+ 1);
1993 u32 dreg
= nvbios_rd32(bios
, init
->offset
+ 5);
1995 trace("COPY_ZM_REG\tR[0x%06x] = R[0x%06x]\n", dreg
, sreg
);
1998 init_wr32(init
, dreg
, init_rd32(init
, sreg
));
2002 * INIT_ZM_REG_GROUP - opcode 0x91
2006 init_zm_reg_group(struct nvbios_init
*init
)
2008 struct nvkm_bios
*bios
= init
->bios
;
2009 u32 addr
= nvbios_rd32(bios
, init
->offset
+ 1);
2010 u8 count
= nvbios_rd08(bios
, init
->offset
+ 5);
2012 trace("ZM_REG_GROUP\tR[0x%06x] =\n", addr
);
2016 u32 data
= nvbios_rd32(bios
, init
->offset
);
2017 trace("\t0x%08x\n", data
);
2018 init_wr32(init
, addr
, data
);
2024 * INIT_XLAT - opcode 0x96
2028 init_xlat(struct nvbios_init
*init
)
2030 struct nvkm_bios
*bios
= init
->bios
;
2031 u32 saddr
= nvbios_rd32(bios
, init
->offset
+ 1);
2032 u8 sshift
= nvbios_rd08(bios
, init
->offset
+ 5);
2033 u8 smask
= nvbios_rd08(bios
, init
->offset
+ 6);
2034 u8 index
= nvbios_rd08(bios
, init
->offset
+ 7);
2035 u32 daddr
= nvbios_rd32(bios
, init
->offset
+ 8);
2036 u32 dmask
= nvbios_rd32(bios
, init
->offset
+ 12);
2037 u8 shift
= nvbios_rd08(bios
, init
->offset
+ 16);
2040 trace("INIT_XLAT\tR[0x%06x] &= 0x%08x |= "
2041 "(X%02x((R[0x%06x] %s 0x%02x) & 0x%02x) << 0x%02x)\n",
2042 daddr
, dmask
, index
, saddr
, (sshift
& 0x80) ? "<<" : ">>",
2043 (sshift
& 0x80) ? (0x100 - sshift
) : sshift
, smask
, shift
);
2046 data
= init_shift(init_rd32(init
, saddr
), sshift
) & smask
;
2047 data
= init_xlat_(init
, index
, data
) << shift
;
2048 init_mask(init
, daddr
, ~dmask
, data
);
2052 * INIT_ZM_MASK_ADD - opcode 0x97
2056 init_zm_mask_add(struct nvbios_init
*init
)
2058 struct nvkm_bios
*bios
= init
->bios
;
2059 u32 addr
= nvbios_rd32(bios
, init
->offset
+ 1);
2060 u32 mask
= nvbios_rd32(bios
, init
->offset
+ 5);
2061 u32 add
= nvbios_rd32(bios
, init
->offset
+ 9);
2064 trace("ZM_MASK_ADD\tR[0x%06x] &= 0x%08x += 0x%08x\n", addr
, mask
, add
);
2067 data
= init_rd32(init
, addr
);
2068 data
= (data
& mask
) | ((data
+ add
) & ~mask
);
2069 init_wr32(init
, addr
, data
);
2073 * INIT_AUXCH - opcode 0x98
2077 init_auxch(struct nvbios_init
*init
)
2079 struct nvkm_bios
*bios
= init
->bios
;
2080 u32 addr
= nvbios_rd32(bios
, init
->offset
+ 1);
2081 u8 count
= nvbios_rd08(bios
, init
->offset
+ 5);
2083 trace("AUXCH\tAUX[0x%08x] 0x%02x\n", addr
, count
);
2087 u8 mask
= nvbios_rd08(bios
, init
->offset
+ 0);
2088 u8 data
= nvbios_rd08(bios
, init
->offset
+ 1);
2089 trace("\tAUX[0x%08x] &= 0x%02x |= 0x%02x\n", addr
, mask
, data
);
2090 mask
= init_rdauxr(init
, addr
) & mask
;
2091 init_wrauxr(init
, addr
, mask
| data
);
2097 * INIT_AUXCH - opcode 0x99
2101 init_zm_auxch(struct nvbios_init
*init
)
2103 struct nvkm_bios
*bios
= init
->bios
;
2104 u32 addr
= nvbios_rd32(bios
, init
->offset
+ 1);
2105 u8 count
= nvbios_rd08(bios
, init
->offset
+ 5);
2107 trace("ZM_AUXCH\tAUX[0x%08x] 0x%02x\n", addr
, count
);
2111 u8 data
= nvbios_rd08(bios
, init
->offset
+ 0);
2112 trace("\tAUX[0x%08x] = 0x%02x\n", addr
, data
);
2113 init_wrauxr(init
, addr
, data
);
2119 * INIT_I2C_LONG_IF - opcode 0x9a
2123 init_i2c_long_if(struct nvbios_init
*init
)
2125 struct nvkm_bios
*bios
= init
->bios
;
2126 u8 index
= nvbios_rd08(bios
, init
->offset
+ 1);
2127 u8 addr
= nvbios_rd08(bios
, init
->offset
+ 2) >> 1;
2128 u8 reglo
= nvbios_rd08(bios
, init
->offset
+ 3);
2129 u8 reghi
= nvbios_rd08(bios
, init
->offset
+ 4);
2130 u8 mask
= nvbios_rd08(bios
, init
->offset
+ 5);
2131 u8 data
= nvbios_rd08(bios
, init
->offset
+ 6);
2132 struct i2c_adapter
*adap
;
2134 trace("I2C_LONG_IF\t"
2135 "I2C[0x%02x][0x%02x][0x%02x%02x] & 0x%02x == 0x%02x\n",
2136 index
, addr
, reglo
, reghi
, mask
, data
);
2139 adap
= init_i2c(init
, index
);
2141 u8 i
[2] = { reghi
, reglo
};
2143 struct i2c_msg msg
[] = {
2144 { .addr
= addr
, .flags
= 0, .len
= 2, .buf
= i
},
2145 { .addr
= addr
, .flags
= I2C_M_RD
, .len
= 1, .buf
= o
}
2149 ret
= i2c_transfer(adap
, msg
, 2);
2150 if (ret
== 2 && ((o
[0] & mask
) == data
))
2154 init_exec_set(init
, false);
2158 * INIT_GPIO_NE - opcode 0xa9
2162 init_gpio_ne(struct nvbios_init
*init
)
2164 struct nvkm_bios
*bios
= init
->bios
;
2165 struct nvkm_gpio
*gpio
= bios
->subdev
.device
->gpio
;
2166 struct dcb_gpio_func func
;
2167 u8 count
= nvbios_rd08(bios
, init
->offset
+ 1);
2168 u8 idx
= 0, ver
, len
;
2174 for (i
= init
->offset
; i
< init
->offset
+ count
; i
++)
2175 cont("0x%02x ", nvbios_rd08(bios
, i
));
2178 while ((data
= dcb_gpio_parse(bios
, 0, idx
++, &ver
, &len
, &func
))) {
2179 if (func
.func
!= DCB_GPIO_UNUSED
) {
2180 for (i
= init
->offset
; i
< init
->offset
+ count
; i
++) {
2181 if (func
.func
== nvbios_rd08(bios
, i
))
2185 trace("\tFUNC[0x%02x]", func
.func
);
2186 if (i
== (init
->offset
+ count
)) {
2188 if (init_exec(init
))
2189 nvkm_gpio_reset(gpio
, func
.func
);
2195 init
->offset
+= count
;
2198 static struct nvbios_init_opcode
{
2199 void (*exec
)(struct nvbios_init
*);
2201 [0x32] = { init_io_restrict_prog
},
2202 [0x33] = { init_repeat
},
2203 [0x34] = { init_io_restrict_pll
},
2204 [0x36] = { init_end_repeat
},
2205 [0x37] = { init_copy
},
2206 [0x38] = { init_not
},
2207 [0x39] = { init_io_flag_condition
},
2208 [0x3a] = { init_dp_condition
},
2209 [0x3b] = { init_io_mask_or
},
2210 [0x3c] = { init_io_or
},
2211 [0x47] = { init_andn_reg
},
2212 [0x48] = { init_or_reg
},
2213 [0x49] = { init_idx_addr_latched
},
2214 [0x4a] = { init_io_restrict_pll2
},
2215 [0x4b] = { init_pll2
},
2216 [0x4c] = { init_i2c_byte
},
2217 [0x4d] = { init_zm_i2c_byte
},
2218 [0x4e] = { init_zm_i2c
},
2219 [0x4f] = { init_tmds
},
2220 [0x50] = { init_zm_tmds_group
},
2221 [0x51] = { init_cr_idx_adr_latch
},
2222 [0x52] = { init_cr
},
2223 [0x53] = { init_zm_cr
},
2224 [0x54] = { init_zm_cr_group
},
2225 [0x56] = { init_condition_time
},
2226 [0x57] = { init_ltime
},
2227 [0x58] = { init_zm_reg_sequence
},
2228 [0x59] = { init_pll_indirect
},
2229 [0x5a] = { init_zm_reg_indirect
},
2230 [0x5b] = { init_sub_direct
},
2231 [0x5c] = { init_jump
},
2232 [0x5e] = { init_i2c_if
},
2233 [0x5f] = { init_copy_nv_reg
},
2234 [0x62] = { init_zm_index_io
},
2235 [0x63] = { init_compute_mem
},
2236 [0x65] = { init_reset
},
2237 [0x66] = { init_configure_mem
},
2238 [0x67] = { init_configure_clk
},
2239 [0x68] = { init_configure_preinit
},
2240 [0x69] = { init_io
},
2241 [0x6b] = { init_sub
},
2242 [0x6d] = { init_ram_condition
},
2243 [0x6e] = { init_nv_reg
},
2244 [0x6f] = { init_macro
},
2245 [0x71] = { init_done
},
2246 [0x72] = { init_resume
},
2247 [0x73] = { init_strap_condition
},
2248 [0x74] = { init_time
},
2249 [0x75] = { init_condition
},
2250 [0x76] = { init_io_condition
},
2251 [0x77] = { init_zm_reg16
},
2252 [0x78] = { init_index_io
},
2253 [0x79] = { init_pll
},
2254 [0x7a] = { init_zm_reg
},
2255 [0x87] = { init_ram_restrict_pll
},
2256 [0x8c] = { init_reserved
},
2257 [0x8d] = { init_reserved
},
2258 [0x8e] = { init_gpio
},
2259 [0x8f] = { init_ram_restrict_zm_reg_group
},
2260 [0x90] = { init_copy_zm_reg
},
2261 [0x91] = { init_zm_reg_group
},
2262 [0x92] = { init_reserved
},
2263 [0x96] = { init_xlat
},
2264 [0x97] = { init_zm_mask_add
},
2265 [0x98] = { init_auxch
},
2266 [0x99] = { init_zm_auxch
},
2267 [0x9a] = { init_i2c_long_if
},
2268 [0xa9] = { init_gpio_ne
},
2269 [0xaa] = { init_reserved
},
2272 #define init_opcode_nr (sizeof(init_opcode) / sizeof(init_opcode[0]))
2275 nvbios_exec(struct nvbios_init
*init
)
2278 while (init
->offset
) {
2279 u8 opcode
= nvbios_rd08(init
->bios
, init
->offset
);
2280 if (opcode
>= init_opcode_nr
|| !init_opcode
[opcode
].exec
) {
2281 error("unknown opcode 0x%02x\n", opcode
);
2285 init_opcode
[opcode
].exec(init
);
2292 nvbios_init(struct nvkm_subdev
*subdev
, bool execute
)
2294 struct nvkm_bios
*bios
= subdev
->device
->bios
;
2300 nvkm_debug(subdev
, "running init tables\n");
2301 while (!ret
&& (data
= (init_script(bios
, ++i
)))) {
2302 struct nvbios_init init
= {
2308 .execute
= execute
? 1 : 0,
2311 ret
= nvbios_exec(&init
);
2314 /* the vbios parser will run this right after the normal init
2315 * tables, whereas the binary driver appears to run it later.
2317 if (!ret
&& (data
= init_unknown_script(bios
))) {
2318 struct nvbios_init init
= {
2324 .execute
= execute
? 1 : 0,
2327 ret
= nvbios_exec(&init
);