1/* $NetBSD: nouveau_nvkm_subdev_devinit_tu102.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_tu102.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 33static int 34tu102_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 /*XXX*/ 61 nvkm_wr32(device, 0x00ef0c + (head * 0x40), 0x00000900); 62 nvkm_wr32(device, 0x00ef00 + (head * 0x40), 0x02000014); 63 break; 64 default: 65 nvkm_warn(subdev, "%08x/%dKhz unimplemented\n", type, freq); 66 ret = -EINVAL; 67 break; 68 } 69 70 return ret; 71} 72 73static int 74tu102_devinit_post(struct nvkm_devinit *base, bool post) 75{ 76 struct nv50_devinit *init = nv50_devinit(base); 77 gm200_devinit_preos(init, post); 78 return 0; 79} 80 81static const struct nvkm_devinit_func 82tu102_devinit = { 83 .init = nv50_devinit_init, 84 .post = tu102_devinit_post, 85 .pll_set = tu102_devinit_pll_set, 86 .disable = gm107_devinit_disable, 87}; 88 89int 90tu102_devinit_new(struct nvkm_device *device, int index, 91 struct nvkm_devinit **pinit) 92{ 93 return nv50_devinit_new_(&tu102_devinit, device, index, pinit); 94} 95