1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include <subdev/bios.h>
26#include <subdev/bios/dcb.h>
27#include <subdev/bios/disp.h>
28#include <subdev/bios/init.h>
29#include <subdev/vga.h>
30
31#include "nv50.h"
32
33int
34nv50_devinit_pll_set(struct nouveau_devinit *devinit, u32 type, u32 freq)
35{
36 struct nv50_devinit_priv *priv = (void *)devinit;
37 struct nouveau_bios *bios = nouveau_bios(priv);
38 struct nvbios_pll info;
39 int N1, M1, N2, M2, P;
40 int ret;
41
42 ret = nvbios_pll_parse(bios, type, &info);
43 if (ret) {
44 nv_error(devinit, "failed to retrieve pll data, %d\n", ret);
45 return ret;
46 }
47
48 ret = nv04_pll_calc(nv_subdev(devinit), &info, freq, &N1, &M1, &N2, &M2, &P);
49 if (!ret) {
50 nv_error(devinit, "failed pll calculation\n");
51 return ret;
52 }
53
54 switch (info.type) {
55 case PLL_VPLL0:
56 case PLL_VPLL1:
57 nv_wr32(priv, info.reg + 0, 0x10000611);
58 nv_mask(priv, info.reg + 4, 0x00ff00ff, (M1 << 16) | N1);
59 nv_mask(priv, info.reg + 8, 0x7fff00ff, (P << 28) |
60 (M2 << 16) | N2);
61 break;
62 case PLL_MEMORY:
63 nv_mask(priv, info.reg + 0, 0x01ff0000, (P << 22) |
64 (info.bias_p << 19) |
65 (P << 16));
66 nv_wr32(priv, info.reg + 4, (N1 << 8) | M1);
67 break;
68 default:
69 nv_mask(priv, info.reg + 0, 0x00070000, (P << 16));
70 nv_wr32(priv, info.reg + 4, (N1 << 8) | M1);
71 break;
72 }
73
74 return 0;
75}
76
77static u64
78nv50_devinit_disable(struct nouveau_devinit *devinit)
79{
80 struct nv50_devinit_priv *priv = (void *)devinit;
81 u32 r001540 = nv_rd32(priv, 0x001540);
82 u64 disable = 0ULL;
83
84 if (!(r001540 & 0x40000000))
85 disable |= (1ULL << NVDEV_ENGINE_MPEG);
86
87 return disable;
88}
89
90int
91nv50_devinit_init(struct nouveau_object *object)
92{
93 struct nouveau_bios *bios = nouveau_bios(object);
94 struct nv50_devinit_priv *priv = (void *)object;
95 struct nvbios_outp info;
96 struct dcb_output outp;
97 u8 ver = 0xff, hdr, cnt, len;
98 int ret, i = 0;
99
100 if (!priv->base.post) {
101 if (!nv_rdvgac(priv, 0, 0x00) &&
102 !nv_rdvgac(priv, 0, 0x1a)) {
103 nv_info(priv, "adaptor not initialised\n");
104 priv->base.post = true;
105 }
106 }
107
108 ret = nouveau_devinit_init(&priv->base);
109 if (ret)
110 return ret;
111
112
113
114
115
116 while (priv->base.post && dcb_outp_parse(bios, i, &ver, &hdr, &outp)) {
117 if (nvbios_outp_match(bios, outp.hasht, outp.hashm,
118 &ver, &hdr, &cnt, &len, &info)) {
119 struct nvbios_init init = {
120 .subdev = nv_subdev(priv),
121 .bios = bios,
122 .offset = info.script[0],
123 .outp = &outp,
124 .crtc = -1,
125 .execute = 1,
126 };
127
128 nvbios_exec(&init);
129 }
130 i++;
131 }
132
133 return 0;
134}
135
136int
137nv50_devinit_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
138 struct nouveau_oclass *oclass, void *data, u32 size,
139 struct nouveau_object **pobject)
140{
141 struct nv50_devinit_priv *priv;
142 int ret;
143
144 ret = nouveau_devinit_create(parent, engine, oclass, &priv);
145 *pobject = nv_object(priv);
146 if (ret)
147 return ret;
148
149 return 0;
150}
151
152struct nouveau_oclass *
153nv50_devinit_oclass = &(struct nouveau_devinit_impl) {
154 .base.handle = NV_SUBDEV(DEVINIT, 0x50),
155 .base.ofuncs = &(struct nouveau_ofuncs) {
156 .ctor = nv50_devinit_ctor,
157 .dtor = _nouveau_devinit_dtor,
158 .init = nv50_devinit_init,
159 .fini = _nouveau_devinit_fini,
160 },
161 .pll_set = nv50_devinit_pll_set,
162 .disable = nv50_devinit_disable,
163}.base;
164