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.
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>
34 nv50_devinit_pll_set(struct nouveau_devinit *devinit, u32 type, u32 freq)
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;
42 ret = nvbios_pll_parse(bios, type, &info);
44 nv_error(devinit, "failed to retrieve pll data, %d\n", ret);
48 ret = nv04_pll_calc(nv_subdev(devinit), &info, freq, &N1, &M1, &N2, &M2, &P);
50 nv_error(devinit, "failed pll calculation\n");
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) |
63 nv_mask(priv, info.reg + 0, 0x01ff0000, (P << 22) |
66 nv_wr32(priv, info.reg + 4, (N1 << 8) | M1);
69 nv_mask(priv, info.reg + 0, 0x00070000, (P << 16));
70 nv_wr32(priv, info.reg + 4, (N1 << 8) | M1);
78 nv50_devinit_disable(struct nouveau_devinit *devinit)
80 struct nv50_devinit_priv *priv = (void *)devinit;
81 u32 r001540 = nv_rd32(priv, 0x001540);
84 if (!(r001540 & 0x40000000))
85 disable |= (1ULL << NVDEV_ENGINE_MPEG);
91 nv50_devinit_init(struct nouveau_object *object)
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;
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;
108 ret = nouveau_devinit_init(&priv->base);
112 /* if we ran the init tables, we have to execute the first script
113 * pointer of each dcb entry's display encoder table in order
114 * to properly initialise each encoder.
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),
122 .offset = info.script[0],
137 nv50_devinit_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
138 struct nouveau_oclass *oclass, void *data, u32 size,
139 struct nouveau_object **pobject)
141 struct nv50_devinit_priv *priv;
144 ret = nouveau_devinit_create(parent, engine, oclass, &priv);
145 *pobject = nv_object(priv);
152 struct nouveau_oclass *
153 nv50_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,
161 .pll_set = nv50_devinit_pll_set,
162 .disable = nv50_devinit_disable,