Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2021 Red Hat Inc.
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice shall be included in
0012  * all copies or substantial portions of the Software.
0013  *
0014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0017  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0018  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0020  * OTHER DEALINGS IN THE SOFTWARE.
0021  */
0022 #include "nv50.h"
0023 
0024 #include <subdev/bios.h>
0025 #include <subdev/bios/pll.h>
0026 #include <subdev/clk/pll.h>
0027 
0028 static int
0029 ga100_devinit_pll_set(struct nvkm_devinit *init, u32 type, u32 freq)
0030 {
0031     struct nvkm_subdev *subdev = &init->subdev;
0032     struct nvkm_device *device = subdev->device;
0033     struct nvbios_pll info;
0034     int head = type - PLL_VPLL0;
0035     int N, fN, M, P;
0036     int ret;
0037 
0038     ret = nvbios_pll_parse(device->bios, type, &info);
0039     if (ret)
0040         return ret;
0041 
0042     ret = gt215_pll_calc(subdev, &info, freq, &N, &fN, &M, &P);
0043     if (ret < 0)
0044         return ret;
0045 
0046     switch (info.type) {
0047     case PLL_VPLL0:
0048     case PLL_VPLL1:
0049     case PLL_VPLL2:
0050     case PLL_VPLL3:
0051         nvkm_wr32(device, 0x00ef00 + (head * 0x40), 0x02080004);
0052         nvkm_wr32(device, 0x00ef18 + (head * 0x40), (N << 16) | fN);
0053         nvkm_wr32(device, 0x00ef04 + (head * 0x40), (P << 16) | M);
0054         nvkm_wr32(device, 0x00e9c0 + (head * 0x04), 0x00000001);
0055         break;
0056     default:
0057         nvkm_warn(subdev, "%08x/%dKhz unimplemented\n", type, freq);
0058         ret = -EINVAL;
0059         break;
0060     }
0061 
0062     return ret;
0063 }
0064 
0065 static const struct nvkm_devinit_func
0066 ga100_devinit = {
0067     .init = nv50_devinit_init,
0068     .post = tu102_devinit_post,
0069     .pll_set = ga100_devinit_pll_set,
0070 };
0071 
0072 int
0073 ga100_devinit_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
0074           struct nvkm_devinit **pinit)
0075 {
0076     return nv50_devinit_new_(&ga100_devinit, device, type, inst, pinit);
0077 }