Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2013 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  * Authors: Ben Skeggs
0023  */
0024 #include "nv50.h"
0025 
0026 #include <subdev/bios.h>
0027 #include <subdev/bios/init.h>
0028 #include <subdev/bios/pll.h>
0029 #include <subdev/clk/pll.h>
0030 
0031 int
0032 gf100_devinit_pll_set(struct nvkm_devinit *init, u32 type, u32 freq)
0033 {
0034     struct nvkm_subdev *subdev = &init->subdev;
0035     struct nvkm_device *device = subdev->device;
0036     struct nvbios_pll info;
0037     int N, fN, M, P;
0038     int ret;
0039 
0040     ret = nvbios_pll_parse(device->bios, type, &info);
0041     if (ret)
0042         return ret;
0043 
0044     ret = gt215_pll_calc(subdev, &info, freq, &N, &fN, &M, &P);
0045     if (ret < 0)
0046         return ret;
0047 
0048     switch (info.type) {
0049     case PLL_VPLL0:
0050     case PLL_VPLL1:
0051     case PLL_VPLL2:
0052     case PLL_VPLL3:
0053         nvkm_mask(device, info.reg + 0x0c, 0x00000000, 0x00000100);
0054         nvkm_wr32(device, info.reg + 0x04, (P << 16) | (N << 8) | M);
0055         nvkm_wr32(device, info.reg + 0x10, fN << 16);
0056         break;
0057     default:
0058         nvkm_warn(subdev, "%08x/%dKhz unimplemented\n", type, freq);
0059         ret = -EINVAL;
0060         break;
0061     }
0062 
0063     return ret;
0064 }
0065 
0066 static u64
0067 gf100_devinit_disable(struct nvkm_devinit *init)
0068 {
0069     struct nvkm_device *device = init->subdev.device;
0070     u32 r022500 = nvkm_rd32(device, 0x022500);
0071 
0072     if (r022500 & 0x00000001)
0073         nvkm_subdev_disable(device, NVKM_ENGINE_DISP, 0);
0074 
0075     if (r022500 & 0x00000002) {
0076         nvkm_subdev_disable(device, NVKM_ENGINE_MSPDEC, 0);
0077         nvkm_subdev_disable(device, NVKM_ENGINE_MSPPP, 0);
0078     }
0079 
0080     if (r022500 & 0x00000004)
0081         nvkm_subdev_disable(device, NVKM_ENGINE_MSVLD, 0);
0082     if (r022500 & 0x00000008)
0083         nvkm_subdev_disable(device, NVKM_ENGINE_MSENC, 0);
0084     if (r022500 & 0x00000100)
0085         nvkm_subdev_disable(device, NVKM_ENGINE_CE, 0);
0086     if (r022500 & 0x00000200)
0087         nvkm_subdev_disable(device, NVKM_ENGINE_CE, 1);
0088 
0089     return 0ULL;
0090 }
0091 
0092 void
0093 gf100_devinit_preinit(struct nvkm_devinit *base)
0094 {
0095     struct nv50_devinit *init = nv50_devinit(base);
0096     struct nvkm_subdev *subdev = &init->base.subdev;
0097     struct nvkm_device *device = subdev->device;
0098 
0099     /*
0100      * This bit is set by devinit, and flips back to 0 on suspend. We
0101      * can use it as a reliable way to know whether we should run devinit.
0102      */
0103     base->post = ((nvkm_rd32(device, 0x2240c) & BIT(1)) == 0);
0104 }
0105 
0106 static const struct nvkm_devinit_func
0107 gf100_devinit = {
0108     .preinit = gf100_devinit_preinit,
0109     .init = nv50_devinit_init,
0110     .post = nv04_devinit_post,
0111     .pll_set = gf100_devinit_pll_set,
0112     .disable = gf100_devinit_disable,
0113 };
0114 
0115 int
0116 gf100_devinit_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
0117           struct nvkm_devinit **pinit)
0118 {
0119     return nv50_devinit_new_(&gf100_devinit, device, type, inst, pinit);
0120 }