xref: /netbsd-src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/devinit/nouveau_nvkm_subdev_devinit_gv100.c (revision 41ec02673d281bbb3d38e6c78504ce6e30c228c1)
1 /*	$NetBSD: nouveau_nvkm_subdev_devinit_gv100.c,v 1.2 2021/12/18 23:45:39 riastradh Exp $	*/
2 
3 /*
4  * Copyright 2018 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 #include <sys/cdefs.h>
25 __KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_subdev_devinit_gv100.c,v 1.2 2021/12/18 23:45:39 riastradh Exp $");
26 
27 #include "nv50.h"
28 
29 #include <subdev/bios.h>
30 #include <subdev/bios/pll.h>
31 #include <subdev/clk/pll.h>
32 
33 static int
gv100_devinit_pll_set(struct nvkm_devinit * init,u32 type,u32 freq)34 gv100_devinit_pll_set(struct nvkm_devinit *init, u32 type, u32 freq)
35 {
36 	struct nvkm_subdev *subdev = &init->subdev;
37 	struct nvkm_device *device = subdev->device;
38 	struct nvbios_pll info;
39 	int head = type - PLL_VPLL0;
40 	int N, fN, M, P;
41 	int ret;
42 
43 	ret = nvbios_pll_parse(device->bios, type, &info);
44 	if (ret)
45 		return ret;
46 
47 	ret = gt215_pll_calc(subdev, &info, freq, &N, &fN, &M, &P);
48 	if (ret < 0)
49 		return ret;
50 
51 	switch (info.type) {
52 	case PLL_VPLL0:
53 	case PLL_VPLL1:
54 	case PLL_VPLL2:
55 	case PLL_VPLL3:
56 		nvkm_wr32(device, 0x00ef10 + (head * 0x40), fN << 16);
57 		nvkm_wr32(device, 0x00ef04 + (head * 0x40), (P << 16) |
58 							    (N <<  8) |
59 							    (M <<  0));
60 		break;
61 	default:
62 		nvkm_warn(subdev, "%08x/%dKhz unimplemented\n", type, freq);
63 		ret = -EINVAL;
64 		break;
65 	}
66 
67 	return ret;
68 }
69 
70 static const struct nvkm_devinit_func
71 gv100_devinit = {
72 	.preinit = gf100_devinit_preinit,
73 	.init = nv50_devinit_init,
74 	.post = gm200_devinit_post,
75 	.pll_set = gv100_devinit_pll_set,
76 	.disable = gm107_devinit_disable,
77 };
78 
79 int
gv100_devinit_new(struct nvkm_device * device,int index,struct nvkm_devinit ** pinit)80 gv100_devinit_new(struct nvkm_device *device, int index,
81 		struct nvkm_devinit **pinit)
82 {
83 	return nv50_devinit_new_(&gv100_devinit, device, index, pinit);
84 }
85