| 1 | /* $NetBSD: nouveau_subdev_devinit_nvc0.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_nvc0.c,v 1.1.1.1 2014/08/06 12:36:30 riastradh Exp $" ); |
| 29 | |
| 30 | #include "nv50.h" |
| 31 | |
| 32 | int |
| 33 | nvc0_devinit_pll_set(struct nouveau_devinit *devinit, u32 type, u32 freq) |
| 34 | { |
| 35 | struct nv50_devinit_priv *priv = (void *)devinit; |
| 36 | struct nouveau_bios *bios = nouveau_bios(priv); |
| 37 | struct nvbios_pll info; |
| 38 | int N, fN, M, P; |
| 39 | int ret; |
| 40 | |
| 41 | ret = nvbios_pll_parse(bios, type, &info); |
| 42 | if (ret) |
| 43 | return ret; |
| 44 | |
| 45 | ret = nva3_pll_calc(nv_subdev(devinit), &info, freq, &N, &fN, &M, &P); |
| 46 | if (ret < 0) |
| 47 | return ret; |
| 48 | |
| 49 | switch (info.type) { |
| 50 | case PLL_VPLL0: |
| 51 | case PLL_VPLL1: |
| 52 | case PLL_VPLL2: |
| 53 | case PLL_VPLL3: |
| 54 | nv_mask(priv, info.reg + 0x0c, 0x00000000, 0x00000100); |
| 55 | nv_wr32(priv, info.reg + 0x04, (P << 16) | (N << 8) | M); |
| 56 | nv_wr32(priv, info.reg + 0x10, fN << 16); |
| 57 | break; |
| 58 | default: |
| 59 | nv_warn(priv, "0x%08x/%dKhz unimplemented\n" , type, freq); |
| 60 | ret = -EINVAL; |
| 61 | break; |
| 62 | } |
| 63 | |
| 64 | return ret; |
| 65 | } |
| 66 | |
| 67 | static u64 |
| 68 | nvc0_devinit_disable(struct nouveau_devinit *devinit) |
| 69 | { |
| 70 | struct nv50_devinit_priv *priv = (void *)devinit; |
| 71 | u32 r022500 = nv_rd32(priv, 0x022500); |
| 72 | u64 disable = 0ULL; |
| 73 | |
| 74 | if (r022500 & 0x00000001) |
| 75 | disable |= (1ULL << NVDEV_ENGINE_DISP); |
| 76 | |
| 77 | if (r022500 & 0x00000002) { |
| 78 | disable |= (1ULL << NVDEV_ENGINE_VP); |
| 79 | disable |= (1ULL << NVDEV_ENGINE_PPP); |
| 80 | } |
| 81 | |
| 82 | if (r022500 & 0x00000004) |
| 83 | disable |= (1ULL << NVDEV_ENGINE_BSP); |
| 84 | if (r022500 & 0x00000008) |
| 85 | disable |= (1ULL << NVDEV_ENGINE_VENC); |
| 86 | if (r022500 & 0x00000100) |
| 87 | disable |= (1ULL << NVDEV_ENGINE_COPY0); |
| 88 | if (r022500 & 0x00000200) |
| 89 | disable |= (1ULL << NVDEV_ENGINE_COPY1); |
| 90 | |
| 91 | return disable; |
| 92 | } |
| 93 | |
| 94 | static int |
| 95 | nvc0_devinit_ctor(struct nouveau_object *parent, struct nouveau_object *engine, |
| 96 | struct nouveau_oclass *oclass, void *data, u32 size, |
| 97 | struct nouveau_object **pobject) |
| 98 | { |
| 99 | struct nv50_devinit_priv *priv; |
| 100 | int ret; |
| 101 | |
| 102 | ret = nouveau_devinit_create(parent, engine, oclass, &priv); |
| 103 | *pobject = nv_object(priv); |
| 104 | if (ret) |
| 105 | return ret; |
| 106 | |
| 107 | if (nv_rd32(priv, 0x022500) & 0x00000001) |
| 108 | priv->base.post = true; |
| 109 | return 0; |
| 110 | } |
| 111 | |
| 112 | struct nouveau_oclass * |
| 113 | nvc0_devinit_oclass = &(struct nouveau_devinit_impl) { |
| 114 | .base.handle = NV_SUBDEV(DEVINIT, 0xc0), |
| 115 | .base.ofuncs = &(struct nouveau_ofuncs) { |
| 116 | .ctor = nvc0_devinit_ctor, |
| 117 | .dtor = _nouveau_devinit_dtor, |
| 118 | .init = nv50_devinit_init, |
| 119 | .fini = _nouveau_devinit_fini, |
| 120 | }, |
| 121 | .pll_set = nvc0_devinit_pll_set, |
| 122 | .disable = nvc0_devinit_disable, |
| 123 | }.base; |
| 124 | |