8625d219f5cad006aa79fcdc47295a45980f9ffe
[deliverable/linux.git] / drivers / gpu / drm / nouveau / core / subdev / therm / nva3.c
1 /*
2 * Copyright 2012 Red Hat Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: Ben Skeggs
23 */
24
25 #include <subdev/gpio.h>
26
27 #include "priv.h"
28
29 struct nva3_therm_priv {
30 struct nouveau_therm_priv base;
31 };
32
33 int
34 nva3_therm_fan_sense(struct nouveau_therm *therm)
35 {
36 u32 tach = nv_rd32(therm, 0x00e728) & 0x0000ffff;
37 u32 ctrl = nv_rd32(therm, 0x00e720);
38 if (ctrl & 0x00000001)
39 return tach * 60;
40 return -ENODEV;
41 }
42
43 static int
44 nva3_therm_init(struct nouveau_object *object)
45 {
46 struct nva3_therm_priv *priv = (void *)object;
47 struct dcb_gpio_func *tach = &priv->base.fan->tach;
48 int ret;
49
50 ret = nouveau_therm_init(&priv->base.base);
51 if (ret)
52 return ret;
53
54 /* enable fan tach, count revolutions per-second */
55 nv_mask(priv, 0x00e720, 0x00000003, 0x00000002);
56 if (tach->func != DCB_GPIO_UNUSED) {
57 nv_wr32(priv, 0x00e724, nv_device(priv)->crystal * 1000);
58 nv_mask(priv, 0x00e720, 0x001f0000, tach->line << 16);
59 nv_mask(priv, 0x00e720, 0x00000001, 0x00000001);
60 }
61 nv_mask(priv, 0x00e720, 0x00000002, 0x00000000);
62
63 return 0;
64 }
65
66 static int
67 nva3_therm_ctor(struct nouveau_object *parent,
68 struct nouveau_object *engine,
69 struct nouveau_oclass *oclass, void *data, u32 size,
70 struct nouveau_object **pobject)
71 {
72 struct nva3_therm_priv *priv;
73 int ret;
74
75 ret = nouveau_therm_create(parent, engine, oclass, &priv);
76 *pobject = nv_object(priv);
77 if (ret)
78 return ret;
79
80 priv->base.base.pwm_ctrl = nv50_fan_pwm_ctrl;
81 priv->base.base.pwm_get = nv50_fan_pwm_get;
82 priv->base.base.pwm_set = nv50_fan_pwm_set;
83 priv->base.base.pwm_clock = nv50_fan_pwm_clock;
84 priv->base.base.temp_get = nv50_temp_get;
85 priv->base.base.fan_sense = nva3_therm_fan_sense;
86 return nouveau_therm_preinit(&priv->base.base);
87 }
88
89 struct nouveau_oclass
90 nva3_therm_oclass = {
91 .handle = NV_SUBDEV(THERM, 0xa3),
92 .ofuncs = &(struct nouveau_ofuncs) {
93 .ctor = nva3_therm_ctor,
94 .dtor = _nouveau_therm_dtor,
95 .init = nva3_therm_init,
96 .fini = _nouveau_therm_fini,
97 },
98 };
This page took 0.045152 seconds and 4 git commands to generate.