119 lines · c
1/*2 * Copyright 2013 Red Hat Inc.3 *4 * Permission is hereby granted, free of charge, to any person obtaining a5 * copy of this software and associated documentation files (the "Software"),6 * to deal in the Software without restriction, including without limitation7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,8 * and/or sell copies of the Software, and to permit persons to whom the9 * Software is furnished to do so, subject to the following conditions:10 *11 * The above copyright notice and this permission notice shall be included in12 * all copies or substantial portions of the Software.13 *14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR18 * 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 OR20 * OTHER DEALINGS IN THE SOFTWARE.21 *22 * Authors: Ben Skeggs23 */24#include "nv50.h"25 26#include <subdev/bios.h>27#include <subdev/bios/init.h>28#include <subdev/bios/pll.h>29#include <subdev/clk/pll.h>30 31int32gf100_devinit_pll_set(struct nvkm_devinit *init, u32 type, u32 freq)33{34 struct nvkm_subdev *subdev = &init->subdev;35 struct nvkm_device *device = subdev->device;36 struct nvbios_pll info;37 int N, fN, M, P;38 int ret;39 40 ret = nvbios_pll_parse(device->bios, type, &info);41 if (ret)42 return ret;43 44 ret = gt215_pll_calc(subdev, &info, freq, &N, &fN, &M, &P);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 nvkm_mask(device, info.reg + 0x0c, 0x00000000, 0x00000100);54 nvkm_wr32(device, info.reg + 0x04, (P << 16) | (N << 8) | M);55 nvkm_wr32(device, info.reg + 0x10, fN << 16);56 break;57 default:58 nvkm_warn(subdev, "%08x/%dKhz unimplemented\n", type, freq);59 ret = -EINVAL;60 break;61 }62 63 return ret;64}65 66static void67gf100_devinit_disable(struct nvkm_devinit *init)68{69 struct nvkm_device *device = init->subdev.device;70 u32 r022500 = nvkm_rd32(device, 0x022500);71 72 if (r022500 & 0x00000001)73 nvkm_subdev_disable(device, NVKM_ENGINE_DISP, 0);74 75 if (r022500 & 0x00000002) {76 nvkm_subdev_disable(device, NVKM_ENGINE_MSPDEC, 0);77 nvkm_subdev_disable(device, NVKM_ENGINE_MSPPP, 0);78 }79 80 if (r022500 & 0x00000004)81 nvkm_subdev_disable(device, NVKM_ENGINE_MSVLD, 0);82 if (r022500 & 0x00000008)83 nvkm_subdev_disable(device, NVKM_ENGINE_MSENC, 0);84 if (r022500 & 0x00000100)85 nvkm_subdev_disable(device, NVKM_ENGINE_CE, 0);86 if (r022500 & 0x00000200)87 nvkm_subdev_disable(device, NVKM_ENGINE_CE, 1);88}89 90void91gf100_devinit_preinit(struct nvkm_devinit *base)92{93 struct nv50_devinit *init = nv50_devinit(base);94 struct nvkm_subdev *subdev = &init->base.subdev;95 struct nvkm_device *device = subdev->device;96 97 /*98 * This bit is set by devinit, and flips back to 0 on suspend. We99 * can use it as a reliable way to know whether we should run devinit.100 */101 base->post = ((nvkm_rd32(device, 0x2240c) & BIT(1)) == 0);102}103 104static const struct nvkm_devinit_func105gf100_devinit = {106 .preinit = gf100_devinit_preinit,107 .init = nv50_devinit_init,108 .post = nv04_devinit_post,109 .pll_set = gf100_devinit_pll_set,110 .disable = gf100_devinit_disable,111};112 113int114gf100_devinit_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,115 struct nvkm_devinit **pinit)116{117 return nv50_devinit_new_(&gf100_devinit, device, type, inst, pinit);118}119