1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include "nv50.h"
25
26#include <subdev/bios.h>
27#include <subdev/bios/dcb.h>
28#include <subdev/bios/disp.h>
29#include <subdev/bios/init.h>
30#include <subdev/bios/pll.h>
31#include <subdev/clk/pll.h>
32#include <subdev/vga.h>
33
34int
35nv50_devinit_pll_set(struct nvkm_devinit *init, u32 type, u32 freq)
36{
37 struct nvkm_subdev *subdev = &init->subdev;
38 struct nvkm_device *device = subdev->device;
39 struct nvkm_bios *bios = device->bios;
40 struct nvbios_pll info;
41 int N1, M1, N2, M2, P;
42 int ret;
43
44 ret = nvbios_pll_parse(bios, type, &info);
45 if (ret) {
46 nvkm_error(subdev, "failed to retrieve pll data, %d\n", ret);
47 return ret;
48 }
49
50 ret = nv04_pll_calc(subdev, &info, freq, &N1, &M1, &N2, &M2, &P);
51 if (!ret) {
52 nvkm_error(subdev, "failed pll calculation\n");
53 return ret;
54 }
55
56 switch (info.type) {
57 case PLL_VPLL0:
58 case PLL_VPLL1:
59 nvkm_wr32(device, info.reg + 0, 0x10000611);
60 nvkm_mask(device, info.reg + 4, 0x00ff00ff, (M1 << 16) | N1);
61 nvkm_mask(device, info.reg + 8, 0x7fff00ff, (P << 28) |
62 (M2 << 16) | N2);
63 break;
64 case PLL_MEMORY:
65 nvkm_mask(device, info.reg + 0, 0x01ff0000,
66 (P << 22) |
67 (info.bias_p << 19) |
68 (P << 16));
69 nvkm_wr32(device, info.reg + 4, (N1 << 8) | M1);
70 break;
71 default:
72 nvkm_mask(device, info.reg + 0, 0x00070000, (P << 16));
73 nvkm_wr32(device, info.reg + 4, (N1 << 8) | M1);
74 break;
75 }
76
77 return 0;
78}
79
80static u64
81nv50_devinit_disable(struct nvkm_devinit *init)
82{
83 struct nvkm_device *device = init->subdev.device;
84 u32 r001540 = nvkm_rd32(device, 0x001540);
85 u64 disable = 0ULL;
86
87 if (!(r001540 & 0x40000000))
88 disable |= (1ULL << NVKM_ENGINE_MPEG);
89
90 return disable;
91}
92
93void
94nv50_devinit_preinit(struct nvkm_devinit *base)
95{
96 struct nvkm_subdev *subdev = &base->subdev;
97 struct nvkm_device *device = subdev->device;
98
99
100
101
102
103 if (!base->post) {
104 u64 disable = nvkm_devinit_disable(base);
105 if (disable & (1ULL << NVKM_ENGINE_DISP))
106 base->post = true;
107 }
108
109
110
111
112 if (!base->post) {
113 if (!nvkm_rdvgac(device, 0, 0x00) &&
114 !nvkm_rdvgac(device, 0, 0x1a)) {
115 nvkm_debug(subdev, "adaptor not initialised\n");
116 base->post = true;
117 }
118 }
119}
120
121void
122nv50_devinit_init(struct nvkm_devinit *base)
123{
124 struct nv50_devinit *init = nv50_devinit(base);
125 struct nvkm_subdev *subdev = &init->base.subdev;
126 struct nvkm_device *device = subdev->device;
127 struct nvkm_bios *bios = device->bios;
128 struct nvbios_outp info;
129 struct dcb_output outp;
130 u8 ver = 0xff, hdr, cnt, len;
131 int i = 0;
132
133
134
135
136
137 while (init->base.post && dcb_outp_parse(bios, i, &ver, &hdr, &outp)) {
138 if (nvbios_outp_match(bios, outp.hasht, outp.hashm,
139 &ver, &hdr, &cnt, &len, &info)) {
140 struct nvbios_init exec = {
141 .subdev = subdev,
142 .bios = bios,
143 .offset = info.script[0],
144 .outp = &outp,
145 .crtc = -1,
146 .execute = 1,
147 };
148
149 nvbios_exec(&exec);
150 }
151 i++;
152 }
153}
154
155int
156nv50_devinit_new_(const struct nvkm_devinit_func *func,
157 struct nvkm_device *device, int index,
158 struct nvkm_devinit **pinit)
159{
160 struct nv50_devinit *init;
161
162 if (!(init = kzalloc(sizeof(*init), GFP_KERNEL)))
163 return -ENOMEM;
164 *pinit = &init->base;
165
166 nvkm_devinit_ctor(func, device, index, &init->base);
167 return 0;
168}
169
170static const struct nvkm_devinit_func
171nv50_devinit = {
172 .preinit = nv50_devinit_preinit,
173 .init = nv50_devinit_init,
174 .post = nv04_devinit_post,
175 .pll_set = nv50_devinit_pll_set,
176 .disable = nv50_devinit_disable,
177};
178
179int
180nv50_devinit_new(struct nvkm_device *device, int index,
181 struct nvkm_devinit **pinit)
182{
183 return nv50_devinit_new_(&nv50_devinit, device, index, pinit);
184}
185