Home | History | Annotate | Line # | Download | only in devinit
      1 /*	$NetBSD: nouveau_nvkm_subdev_devinit_gf100.c,v 1.3 2021/12/18 23:45:39 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 #include <sys/cdefs.h>
     27 __KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_subdev_devinit_gf100.c,v 1.3 2021/12/18 23:45:39 riastradh Exp $");
     28 
     29 #include "nv50.h"
     30 
     31 #include <subdev/bios.h>
     32 #include <subdev/bios/init.h>
     33 #include <subdev/bios/pll.h>
     34 #include <subdev/clk/pll.h>
     35 
     36 int
     37 gf100_devinit_pll_set(struct nvkm_devinit *init, u32 type, u32 freq)
     38 {
     39 	struct nvkm_subdev *subdev = &init->subdev;
     40 	struct nvkm_device *device = subdev->device;
     41 	struct nvbios_pll info;
     42 	int N, fN, M, P;
     43 	int ret;
     44 
     45 	ret = nvbios_pll_parse(device->bios, type, &info);
     46 	if (ret)
     47 		return ret;
     48 
     49 	ret = gt215_pll_calc(subdev, &info, freq, &N, &fN, &M, &P);
     50 	if (ret < 0)
     51 		return ret;
     52 
     53 	switch (info.type) {
     54 	case PLL_VPLL0:
     55 	case PLL_VPLL1:
     56 	case PLL_VPLL2:
     57 	case PLL_VPLL3:
     58 		nvkm_mask(device, info.reg + 0x0c, 0x00000000, 0x00000100);
     59 		nvkm_wr32(device, info.reg + 0x04, (P << 16) | (N << 8) | M);
     60 		nvkm_wr32(device, info.reg + 0x10, fN << 16);
     61 		break;
     62 	default:
     63 		nvkm_warn(subdev, "%08x/%dKhz unimplemented\n", type, freq);
     64 		ret = -EINVAL;
     65 		break;
     66 	}
     67 
     68 	return ret;
     69 }
     70 
     71 static u64
     72 gf100_devinit_disable(struct nvkm_devinit *init)
     73 {
     74 	struct nvkm_device *device = init->subdev.device;
     75 	u32 r022500 = nvkm_rd32(device, 0x022500);
     76 	u64 disable = 0ULL;
     77 
     78 	if (r022500 & 0x00000001)
     79 		disable |= (1ULL << NVKM_ENGINE_DISP);
     80 
     81 	if (r022500 & 0x00000002) {
     82 		disable |= (1ULL << NVKM_ENGINE_MSPDEC);
     83 		disable |= (1ULL << NVKM_ENGINE_MSPPP);
     84 	}
     85 
     86 	if (r022500 & 0x00000004)
     87 		disable |= (1ULL << NVKM_ENGINE_MSVLD);
     88 	if (r022500 & 0x00000008)
     89 		disable |= (1ULL << NVKM_ENGINE_MSENC);
     90 	if (r022500 & 0x00000100)
     91 		disable |= (1ULL << NVKM_ENGINE_CE0);
     92 	if (r022500 & 0x00000200)
     93 		disable |= (1ULL << NVKM_ENGINE_CE1);
     94 
     95 	return disable;
     96 }
     97 
     98 void
     99 gf100_devinit_preinit(struct nvkm_devinit *base)
    100 {
    101 	struct nv50_devinit *init = nv50_devinit(base);
    102 	struct nvkm_subdev *subdev = &init->base.subdev;
    103 	struct nvkm_device *device = subdev->device;
    104 
    105 	/*
    106 	 * This bit is set by devinit, and flips back to 0 on suspend. We
    107 	 * can use it as a reliable way to know whether we should run devinit.
    108 	 */
    109 	base->post = ((nvkm_rd32(device, 0x2240c) & BIT(1)) == 0);
    110 }
    111 
    112 static const struct nvkm_devinit_func
    113 gf100_devinit = {
    114 	.preinit = gf100_devinit_preinit,
    115 	.init = nv50_devinit_init,
    116 	.post = nv04_devinit_post,
    117 	.pll_set = gf100_devinit_pll_set,
    118 	.disable = gf100_devinit_disable,
    119 };
    120 
    121 int
    122 gf100_devinit_new(struct nvkm_device *device, int index,
    123 		struct nvkm_devinit **pinit)
    124 {
    125 	return nv50_devinit_new_(&gf100_devinit, device, index, pinit);
    126 }
    127