Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2012 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 "priv.h"
0025 #include "pll.h"
0026 
0027 #include <subdev/bios.h>
0028 #include <subdev/bios/pll.h>
0029 #include <subdev/devinit/nv04.h>
0030 
0031 int
0032 nv04_clk_pll_calc(struct nvkm_clk *clock, struct nvbios_pll *info,
0033           int clk, struct nvkm_pll_vals *pv)
0034 {
0035     int N1, M1, N2, M2, P;
0036     int ret = nv04_pll_calc(&clock->subdev, info, clk, &N1, &M1, &N2, &M2, &P);
0037     if (ret) {
0038         pv->refclk = info->refclk;
0039         pv->N1 = N1;
0040         pv->M1 = M1;
0041         pv->N2 = N2;
0042         pv->M2 = M2;
0043         pv->log2P = P;
0044     }
0045     return ret;
0046 }
0047 
0048 int
0049 nv04_clk_pll_prog(struct nvkm_clk *clk, u32 reg1, struct nvkm_pll_vals *pv)
0050 {
0051     struct nvkm_device *device = clk->subdev.device;
0052     struct nvkm_devinit *devinit = device->devinit;
0053     int cv = device->bios->version.chip;
0054 
0055     if (cv == 0x30 || cv == 0x31 || cv == 0x35 || cv == 0x36 ||
0056         cv >= 0x40) {
0057         if (reg1 > 0x405c)
0058             setPLL_double_highregs(devinit, reg1, pv);
0059         else
0060             setPLL_double_lowregs(devinit, reg1, pv);
0061     } else
0062         setPLL_single(devinit, reg1, pv);
0063 
0064     return 0;
0065 }
0066 
0067 static const struct nvkm_clk_func
0068 nv04_clk = {
0069     .domains = {
0070         { nv_clk_src_max }
0071     }
0072 };
0073 
0074 int
0075 nv04_clk_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
0076          struct nvkm_clk **pclk)
0077 {
0078     int ret = nvkm_clk_new_(&nv04_clk, device, type, inst, false, pclk);
0079     if (ret == 0) {
0080         (*pclk)->pll_calc = nv04_clk_pll_calc;
0081         (*pclk)->pll_prog = nv04_clk_pll_prog;
0082     }
0083     return ret;
0084 }