| 1 | /* $NetBSD: nouveau_subdev_devinit_nv50.c,v 1.1.1.1 2014/08/06 12:36:30 riastradh Exp $ */ |
| 2 | |
| 3 | /* |
| 4 | * Copyright 2013 Red Hat Inc. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 20 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 21 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 22 | * OTHER DEALINGS IN THE SOFTWARE. |
| 23 | * |
| 24 | * Authors: Ben Skeggs |
| 25 | */ |
| 26 | |
| 27 | #include <sys/cdefs.h> |
| 28 | __KERNEL_RCSID(0, "$NetBSD: nouveau_subdev_devinit_nv50.c,v 1.1.1.1 2014/08/06 12:36:30 riastradh Exp $" ); |
| 29 | |
| 30 | #include <subdev/bios.h> |
| 31 | #include <subdev/bios/dcb.h> |
| 32 | #include <subdev/bios/disp.h> |
| 33 | #include <subdev/bios/init.h> |
| 34 | #include <subdev/vga.h> |
| 35 | |
| 36 | #include "nv50.h" |
| 37 | |
| 38 | int |
| 39 | nv50_devinit_pll_set(struct nouveau_devinit *devinit, u32 type, u32 freq) |
| 40 | { |
| 41 | struct nv50_devinit_priv *priv = (void *)devinit; |
| 42 | struct nouveau_bios *bios = nouveau_bios(priv); |
| 43 | struct nvbios_pll info; |
| 44 | int N1, M1, N2, M2, P; |
| 45 | int ret; |
| 46 | |
| 47 | ret = nvbios_pll_parse(bios, type, &info); |
| 48 | if (ret) { |
| 49 | nv_error(devinit, "failed to retrieve pll data, %d\n" , ret); |
| 50 | return ret; |
| 51 | } |
| 52 | |
| 53 | ret = nv04_pll_calc(nv_subdev(devinit), &info, freq, &N1, &M1, &N2, &M2, &P); |
| 54 | if (!ret) { |
| 55 | nv_error(devinit, "failed pll calculation\n" ); |
| 56 | return ret; |
| 57 | } |
| 58 | |
| 59 | switch (info.type) { |
| 60 | case PLL_VPLL0: |
| 61 | case PLL_VPLL1: |
| 62 | nv_wr32(priv, info.reg + 0, 0x10000611); |
| 63 | nv_mask(priv, info.reg + 4, 0x00ff00ff, (M1 << 16) | N1); |
| 64 | nv_mask(priv, info.reg + 8, 0x7fff00ff, (P << 28) | |
| 65 | (M2 << 16) | N2); |
| 66 | break; |
| 67 | case PLL_MEMORY: |
| 68 | nv_mask(priv, info.reg + 0, 0x01ff0000, (P << 22) | |
| 69 | (info.bias_p << 19) | |
| 70 | (P << 16)); |
| 71 | nv_wr32(priv, info.reg + 4, (N1 << 8) | M1); |
| 72 | break; |
| 73 | default: |
| 74 | nv_mask(priv, info.reg + 0, 0x00070000, (P << 16)); |
| 75 | nv_wr32(priv, info.reg + 4, (N1 << 8) | M1); |
| 76 | break; |
| 77 | } |
| 78 | |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | static u64 |
| 83 | nv50_devinit_disable(struct nouveau_devinit *devinit) |
| 84 | { |
| 85 | struct nv50_devinit_priv *priv = (void *)devinit; |
| 86 | u32 r001540 = nv_rd32(priv, 0x001540); |
| 87 | u64 disable = 0ULL; |
| 88 | |
| 89 | if (!(r001540 & 0x40000000)) |
| 90 | disable |= (1ULL << NVDEV_ENGINE_MPEG); |
| 91 | |
| 92 | return disable; |
| 93 | } |
| 94 | |
| 95 | int |
| 96 | nv50_devinit_init(struct nouveau_object *object) |
| 97 | { |
| 98 | struct nouveau_bios *bios = nouveau_bios(object); |
| 99 | struct nv50_devinit_priv *priv = (void *)object; |
| 100 | struct nvbios_outp info; |
| 101 | struct dcb_output outp; |
| 102 | u8 ver = 0xff, hdr, cnt, len; |
| 103 | int ret, i = 0; |
| 104 | |
| 105 | if (!priv->base.post) { |
| 106 | if (!nv_rdvgac(priv, 0, 0x00) && |
| 107 | !nv_rdvgac(priv, 0, 0x1a)) { |
| 108 | nv_info(priv, "adaptor not initialised\n" ); |
| 109 | priv->base.post = true; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | ret = nouveau_devinit_init(&priv->base); |
| 114 | if (ret) |
| 115 | return ret; |
| 116 | |
| 117 | /* if we ran the init tables, we have to execute the first script |
| 118 | * pointer of each dcb entry's display encoder table in order |
| 119 | * to properly initialise each encoder. |
| 120 | */ |
| 121 | while (priv->base.post && dcb_outp_parse(bios, i, &ver, &hdr, &outp)) { |
| 122 | if (nvbios_outp_match(bios, outp.hasht, outp.hashm, |
| 123 | &ver, &hdr, &cnt, &len, &info)) { |
| 124 | struct nvbios_init init = { |
| 125 | .subdev = nv_subdev(priv), |
| 126 | .bios = bios, |
| 127 | .offset = info.script[0], |
| 128 | .outp = &outp, |
| 129 | .crtc = -1, |
| 130 | .execute = 1, |
| 131 | }; |
| 132 | |
| 133 | nvbios_exec(&init); |
| 134 | } |
| 135 | i++; |
| 136 | } |
| 137 | |
| 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | int |
| 142 | nv50_devinit_ctor(struct nouveau_object *parent, struct nouveau_object *engine, |
| 143 | struct nouveau_oclass *oclass, void *data, u32 size, |
| 144 | struct nouveau_object **pobject) |
| 145 | { |
| 146 | struct nv50_devinit_priv *priv; |
| 147 | int ret; |
| 148 | |
| 149 | ret = nouveau_devinit_create(parent, engine, oclass, &priv); |
| 150 | *pobject = nv_object(priv); |
| 151 | if (ret) |
| 152 | return ret; |
| 153 | |
| 154 | return 0; |
| 155 | } |
| 156 | |
| 157 | struct nouveau_oclass * |
| 158 | nv50_devinit_oclass = &(struct nouveau_devinit_impl) { |
| 159 | .base.handle = NV_SUBDEV(DEVINIT, 0x50), |
| 160 | .base.ofuncs = &(struct nouveau_ofuncs) { |
| 161 | .ctor = nv50_devinit_ctor, |
| 162 | .dtor = _nouveau_devinit_dtor, |
| 163 | .init = nv50_devinit_init, |
| 164 | .fini = _nouveau_devinit_fini, |
| 165 | }, |
| 166 | .pll_set = nv50_devinit_pll_set, |
| 167 | .disable = nv50_devinit_disable, |
| 168 | }.base; |
| 169 | |