Ben Skeggs | 88524bc | 2013-03-05 10:53:54 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Red Hat Inc. |
| 3 | * |
| 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: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included in |
| 12 | * all copies or substantial portions of the Software. |
| 13 | * |
| 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. |
| 21 | * |
| 22 | * Authors: Ben Skeggs |
| 23 | */ |
Ben Skeggs | cf33601 | 2014-01-14 15:55:38 +1000 | [diff] [blame] | 24 | #include "nv50.h" |
Ben Skeggs | 88524bc | 2013-03-05 10:53:54 +1000 | [diff] [blame] | 25 | |
Ben Skeggs | a8c4362 | 2015-01-14 14:48:16 +1000 | [diff] [blame] | 26 | #include <subdev/bios.h> |
| 27 | #include <subdev/bios/init.h> |
| 28 | #include <subdev/bios/pll.h> |
| 29 | #include <subdev/clk/pll.h> |
| 30 | |
Ben Skeggs | 4bf23ea | 2014-02-24 12:28:37 +1000 | [diff] [blame] | 31 | int |
Ben Skeggs | a8c4362 | 2015-01-14 14:48:16 +1000 | [diff] [blame] | 32 | gf100_devinit_pll_set(struct nvkm_devinit *devinit, u32 type, u32 freq) |
Ben Skeggs | 88524bc | 2013-03-05 10:53:54 +1000 | [diff] [blame] | 33 | { |
Ben Skeggs | cf33601 | 2014-01-14 15:55:38 +1000 | [diff] [blame] | 34 | struct nv50_devinit_priv *priv = (void *)devinit; |
Ben Skeggs | a8c4362 | 2015-01-14 14:48:16 +1000 | [diff] [blame] | 35 | struct nvkm_bios *bios = nvkm_bios(priv); |
Ben Skeggs | 88524bc | 2013-03-05 10:53:54 +1000 | [diff] [blame] | 36 | struct nvbios_pll info; |
| 37 | int N, fN, M, P; |
| 38 | int ret; |
| 39 | |
| 40 | ret = nvbios_pll_parse(bios, type, &info); |
| 41 | if (ret) |
| 42 | return ret; |
| 43 | |
Ben Skeggs | a8c4362 | 2015-01-14 14:48:16 +1000 | [diff] [blame] | 44 | ret = gt215_pll_calc(nv_subdev(devinit), &info, freq, &N, &fN, &M, &P); |
Ben Skeggs | 88524bc | 2013-03-05 10:53:54 +1000 | [diff] [blame] | 45 | if (ret < 0) |
| 46 | return ret; |
| 47 | |
| 48 | switch (info.type) { |
| 49 | case PLL_VPLL0: |
| 50 | case PLL_VPLL1: |
| 51 | case PLL_VPLL2: |
| 52 | case PLL_VPLL3: |
| 53 | nv_mask(priv, info.reg + 0x0c, 0x00000000, 0x00000100); |
| 54 | nv_wr32(priv, info.reg + 0x04, (P << 16) | (N << 8) | M); |
| 55 | nv_wr32(priv, info.reg + 0x10, fN << 16); |
| 56 | break; |
| 57 | default: |
| 58 | nv_warn(priv, "0x%08x/%dKhz unimplemented\n", type, freq); |
| 59 | ret = -EINVAL; |
| 60 | break; |
| 61 | } |
| 62 | |
| 63 | return ret; |
| 64 | } |
| 65 | |
Ilia Mirkin | 4019aaa | 2014-01-14 16:29:06 +1000 | [diff] [blame] | 66 | static u64 |
Ben Skeggs | a8c4362 | 2015-01-14 14:48:16 +1000 | [diff] [blame] | 67 | gf100_devinit_disable(struct nvkm_devinit *devinit) |
Ilia Mirkin | 4019aaa | 2014-01-14 16:29:06 +1000 | [diff] [blame] | 68 | { |
| 69 | struct nv50_devinit_priv *priv = (void *)devinit; |
| 70 | u32 r022500 = nv_rd32(priv, 0x022500); |
| 71 | u64 disable = 0ULL; |
| 72 | |
| 73 | if (r022500 & 0x00000001) |
| 74 | disable |= (1ULL << NVDEV_ENGINE_DISP); |
| 75 | |
| 76 | if (r022500 & 0x00000002) { |
Ben Skeggs | 37a5d02 | 2015-01-14 12:50:04 +1000 | [diff] [blame] | 77 | disable |= (1ULL << NVDEV_ENGINE_MSPDEC); |
Ben Skeggs | fd8666f | 2015-01-14 12:26:28 +1000 | [diff] [blame] | 78 | disable |= (1ULL << NVDEV_ENGINE_MSPPP); |
Ilia Mirkin | 4019aaa | 2014-01-14 16:29:06 +1000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | if (r022500 & 0x00000004) |
Ben Skeggs | eccf7e8a | 2015-01-14 10:09:24 +1000 | [diff] [blame] | 82 | disable |= (1ULL << NVDEV_ENGINE_MSVLD); |
Ilia Mirkin | 4019aaa | 2014-01-14 16:29:06 +1000 | [diff] [blame] | 83 | if (r022500 & 0x00000008) |
Ben Skeggs | bd8369e | 2015-01-14 12:37:00 +1000 | [diff] [blame] | 84 | disable |= (1ULL << NVDEV_ENGINE_MSENC); |
Ilia Mirkin | 4019aaa | 2014-01-14 16:29:06 +1000 | [diff] [blame] | 85 | if (r022500 & 0x00000100) |
Ben Skeggs | aedf24f | 2015-01-14 11:50:20 +1000 | [diff] [blame] | 86 | disable |= (1ULL << NVDEV_ENGINE_CE0); |
Ilia Mirkin | 4019aaa | 2014-01-14 16:29:06 +1000 | [diff] [blame] | 87 | if (r022500 & 0x00000200) |
Ben Skeggs | aedf24f | 2015-01-14 11:50:20 +1000 | [diff] [blame] | 88 | disable |= (1ULL << NVDEV_ENGINE_CE1); |
Ilia Mirkin | 4019aaa | 2014-01-14 16:29:06 +1000 | [diff] [blame] | 89 | |
| 90 | return disable; |
| 91 | } |
| 92 | |
Ben Skeggs | 88524bc | 2013-03-05 10:53:54 +1000 | [diff] [blame] | 93 | static int |
Ben Skeggs | a8c4362 | 2015-01-14 14:48:16 +1000 | [diff] [blame] | 94 | gf100_devinit_ctor(struct nvkm_object *parent, struct nvkm_object *engine, |
| 95 | struct nvkm_oclass *oclass, void *data, u32 size, |
| 96 | struct nvkm_object **pobject) |
Ben Skeggs | 88524bc | 2013-03-05 10:53:54 +1000 | [diff] [blame] | 97 | { |
| 98 | struct nv50_devinit_priv *priv; |
| 99 | int ret; |
| 100 | |
Ben Skeggs | a8c4362 | 2015-01-14 14:48:16 +1000 | [diff] [blame] | 101 | ret = nvkm_devinit_create(parent, engine, oclass, &priv); |
Ben Skeggs | 88524bc | 2013-03-05 10:53:54 +1000 | [diff] [blame] | 102 | *pobject = nv_object(priv); |
| 103 | if (ret) |
| 104 | return ret; |
| 105 | |
Maarten Lankhorst | 791dc143 | 2013-06-27 17:35:53 +1000 | [diff] [blame] | 106 | if (nv_rd32(priv, 0x022500) & 0x00000001) |
| 107 | priv->base.post = true; |
Ben Skeggs | a8c4362 | 2015-01-14 14:48:16 +1000 | [diff] [blame] | 108 | |
Ben Skeggs | 88524bc | 2013-03-05 10:53:54 +1000 | [diff] [blame] | 109 | return 0; |
| 110 | } |
| 111 | |
Ben Skeggs | a8c4362 | 2015-01-14 14:48:16 +1000 | [diff] [blame] | 112 | struct nvkm_oclass * |
| 113 | gf100_devinit_oclass = &(struct nvkm_devinit_impl) { |
Ben Skeggs | cf33601 | 2014-01-14 15:55:38 +1000 | [diff] [blame] | 114 | .base.handle = NV_SUBDEV(DEVINIT, 0xc0), |
Ben Skeggs | a8c4362 | 2015-01-14 14:48:16 +1000 | [diff] [blame] | 115 | .base.ofuncs = &(struct nvkm_ofuncs) { |
| 116 | .ctor = gf100_devinit_ctor, |
| 117 | .dtor = _nvkm_devinit_dtor, |
Ben Skeggs | 88524bc | 2013-03-05 10:53:54 +1000 | [diff] [blame] | 118 | .init = nv50_devinit_init, |
Ben Skeggs | a8c4362 | 2015-01-14 14:48:16 +1000 | [diff] [blame] | 119 | .fini = _nvkm_devinit_fini, |
Ben Skeggs | 88524bc | 2013-03-05 10:53:54 +1000 | [diff] [blame] | 120 | }, |
Ben Skeggs | a8c4362 | 2015-01-14 14:48:16 +1000 | [diff] [blame] | 121 | .pll_set = gf100_devinit_pll_set, |
| 122 | .disable = gf100_devinit_disable, |
Ben Skeggs | e21fd7c | 2014-09-23 15:39:26 +1000 | [diff] [blame] | 123 | .post = nvbios_init, |
Ben Skeggs | cf33601 | 2014-01-14 15:55:38 +1000 | [diff] [blame] | 124 | }.base; |