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/ibus.h>
30 #include <subdev/vga.h>
35 nv50_devinit_pll_set(struct nouveau_devinit *devinit, u32 type, u32 freq)
37 struct nv50_devinit_priv *priv = (void *)devinit;
38 struct nouveau_bios *bios = nouveau_bios(priv);
39 struct nvbios_pll info;
40 int N1, M1, N2, M2, P;
43 ret = nvbios_pll_parse(bios, type, &info);
45 nv_error(devinit, "failed to retrieve pll data, %d\n", ret);
49 ret = nv04_pll_calc(nv_subdev(devinit), &info, freq, &N1, &M1, &N2, &M2, &P);
51 nv_error(devinit, "failed pll calculation\n");
58 nv_wr32(priv, info.reg + 0, 0x10000611);
59 nv_mask(priv, info.reg + 4, 0x00ff00ff, (M1 << 16) | N1);
60 nv_mask(priv, info.reg + 8, 0x7fff00ff, (P << 28) |
64 nv_mask(priv, info.reg + 0, 0x01ff0000, (P << 22) |
67 nv_wr32(priv, info.reg + 4, (N1 << 8) | M1);
70 nv_mask(priv, info.reg + 0, 0x00070000, (P << 16));
71 nv_wr32(priv, info.reg + 4, (N1 << 8) | M1);
79 nv50_devinit_disable(struct nouveau_devinit *devinit)
81 struct nv50_devinit_priv *priv = (void *)devinit;
82 u32 r001540 = nv_rd32(priv, 0x001540);
85 if (!(r001540 & 0x40000000))
86 disable |= (1ULL << NVDEV_ENGINE_MPEG);
92 nv50_devinit_init(struct nouveau_object *object)
94 struct nouveau_bios *bios = nouveau_bios(object);
95 struct nouveau_ibus *ibus = nouveau_ibus(object);
96 struct nv50_devinit_priv *priv = (void *)object;
97 struct nvbios_outp info;
98 struct dcb_output outp;
99 u8 ver = 0xff, hdr, cnt, len;
102 if (!priv->base.post) {
103 if (!nv_rdvgac(priv, 0, 0x00) &&
104 !nv_rdvgac(priv, 0, 0x1a)) {
105 nv_info(priv, "adaptor not initialised\n");
106 priv->base.post = true;
110 /* some boards appear to require certain priv register timeouts
111 * to be bumped before runing devinit scripts. not a clue why
112 * the vbios engineers didn't make the scripts just work...
114 if (priv->base.post && ibus)
115 nv_ofuncs(ibus)->init(nv_object(ibus));
117 ret = nouveau_devinit_init(&priv->base);
121 /* if we ran the init tables, we have to execute the first script
122 * pointer of each dcb entry's display encoder table in order
123 * to properly initialise each encoder.
125 while (priv->base.post && dcb_outp_parse(bios, i, &ver, &hdr, &outp)) {
126 if (nvbios_outp_match(bios, outp.hasht, outp.hashm,
127 &ver, &hdr, &cnt, &len, &info)) {
128 struct nvbios_init init = {
129 .subdev = nv_subdev(priv),
131 .offset = info.script[0],
146 nv50_devinit_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
147 struct nouveau_oclass *oclass, void *data, u32 size,
148 struct nouveau_object **pobject)
150 struct nv50_devinit_priv *priv;
153 ret = nouveau_devinit_create(parent, engine, oclass, &priv);
154 *pobject = nv_object(priv);
161 struct nouveau_oclass *
162 nv50_devinit_oclass = &(struct nouveau_devinit_impl) {
163 .base.handle = NV_SUBDEV(DEVINIT, 0x50),
164 .base.ofuncs = &(struct nouveau_ofuncs) {
165 .ctor = nv50_devinit_ctor,
166 .dtor = _nouveau_devinit_dtor,
167 .init = nv50_devinit_init,
168 .fini = _nouveau_devinit_fini,
170 .pll_set = nv50_devinit_pll_set,
171 .disable = nv50_devinit_disable,