| 1 | /* $NetBSD: nouveau_subdev_clock_nv04.c,v 1.1.1.1 2014/08/06 12:36:29 riastradh Exp $ */ |
| 2 | |
| 3 | /* |
| 4 | * Copyright 2012 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 | * Authors: Ben Skeggs |
| 25 | */ |
| 26 | |
| 27 | #include <sys/cdefs.h> |
| 28 | __KERNEL_RCSID(0, "$NetBSD: nouveau_subdev_clock_nv04.c,v 1.1.1.1 2014/08/06 12:36:29 riastradh Exp $" ); |
| 29 | |
| 30 | #include <subdev/bios.h> |
| 31 | #include <subdev/bios/pll.h> |
| 32 | #include <subdev/clock.h> |
| 33 | #include <subdev/devinit/nv04.h> |
| 34 | |
| 35 | #include "pll.h" |
| 36 | |
| 37 | struct nv04_clock_priv { |
| 38 | struct nouveau_clock base; |
| 39 | }; |
| 40 | |
| 41 | int |
| 42 | nv04_clock_pll_calc(struct nouveau_clock *clock, struct nvbios_pll *info, |
| 43 | int clk, struct nouveau_pll_vals *pv) |
| 44 | { |
| 45 | int N1, M1, N2, M2, P; |
| 46 | int ret = nv04_pll_calc(nv_subdev(clock), info, clk, &N1, &M1, &N2, &M2, &P); |
| 47 | if (ret) { |
| 48 | pv->refclk = info->refclk; |
| 49 | pv->N1 = N1; |
| 50 | pv->M1 = M1; |
| 51 | pv->N2 = N2; |
| 52 | pv->M2 = M2; |
| 53 | pv->log2P = P; |
| 54 | } |
| 55 | return ret; |
| 56 | } |
| 57 | |
| 58 | int |
| 59 | nv04_clock_pll_prog(struct nouveau_clock *clk, u32 reg1, |
| 60 | struct nouveau_pll_vals *pv) |
| 61 | { |
| 62 | struct nouveau_devinit *devinit = nouveau_devinit(clk); |
| 63 | int cv = nouveau_bios(clk)->version.chip; |
| 64 | |
| 65 | if (cv == 0x30 || cv == 0x31 || cv == 0x35 || cv == 0x36 || |
| 66 | cv >= 0x40) { |
| 67 | if (reg1 > 0x405c) |
| 68 | setPLL_double_highregs(devinit, reg1, pv); |
| 69 | else |
| 70 | setPLL_double_lowregs(devinit, reg1, pv); |
| 71 | } else |
| 72 | setPLL_single(devinit, reg1, pv); |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | static struct nouveau_clocks |
| 78 | nv04_domain[] = { |
| 79 | { nv_clk_src_max } |
| 80 | }; |
| 81 | |
| 82 | static int |
| 83 | nv04_clock_ctor(struct nouveau_object *parent, struct nouveau_object *engine, |
| 84 | struct nouveau_oclass *oclass, void *data, u32 size, |
| 85 | struct nouveau_object **pobject) |
| 86 | { |
| 87 | struct nv04_clock_priv *priv; |
| 88 | int ret; |
| 89 | |
| 90 | ret = nouveau_clock_create(parent, engine, oclass, nv04_domain, &priv); |
| 91 | *pobject = nv_object(priv); |
| 92 | if (ret) |
| 93 | return ret; |
| 94 | |
| 95 | priv->base.pll_calc = nv04_clock_pll_calc; |
| 96 | priv->base.pll_prog = nv04_clock_pll_prog; |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | struct nouveau_oclass |
| 101 | nv04_clock_oclass = { |
| 102 | .handle = NV_SUBDEV(CLOCK, 0x04), |
| 103 | .ofuncs = &(struct nouveau_ofuncs) { |
| 104 | .ctor = nv04_clock_ctor, |
| 105 | .dtor = _nouveau_clock_dtor, |
| 106 | .init = _nouveau_clock_init, |
| 107 | .fini = _nouveau_clock_fini, |
| 108 | }, |
| 109 | }; |
| 110 | |