1/* $NetBSD: nouveau_subdev_therm_nva3.c,v 1.1.1.1 2014/08/06 12:36:32 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_therm_nva3.c,v 1.1.1.1 2014/08/06 12:36:32 riastradh Exp $");
29
30#include <subdev/gpio.h>
31
32#include "priv.h"
33
34struct nva3_therm_priv {
35 struct nouveau_therm_priv base;
36};
37
38int
39nva3_therm_fan_sense(struct nouveau_therm *therm)
40{
41 u32 tach = nv_rd32(therm, 0x00e728) & 0x0000ffff;
42 u32 ctrl = nv_rd32(therm, 0x00e720);
43 if (ctrl & 0x00000001)
44 return tach * 60;
45 return -ENODEV;
46}
47
48static int
49nva3_therm_init(struct nouveau_object *object)
50{
51 struct nva3_therm_priv *priv = (void *)object;
52 struct dcb_gpio_func *tach = &priv->base.fan->tach;
53 int ret;
54
55 ret = nouveau_therm_init(&priv->base.base);
56 if (ret)
57 return ret;
58
59 /* enable fan tach, count revolutions per-second */
60 nv_mask(priv, 0x00e720, 0x00000003, 0x00000002);
61 if (tach->func != DCB_GPIO_UNUSED) {
62 nv_wr32(priv, 0x00e724, nv_device(priv)->crystal * 1000);
63 nv_mask(priv, 0x00e720, 0x001f0000, tach->line << 16);
64 nv_mask(priv, 0x00e720, 0x00000001, 0x00000001);
65 }
66 nv_mask(priv, 0x00e720, 0x00000002, 0x00000000);
67
68 return 0;
69}
70
71static int
72nva3_therm_ctor(struct nouveau_object *parent,
73 struct nouveau_object *engine,
74 struct nouveau_oclass *oclass, void *data, u32 size,
75 struct nouveau_object **pobject)
76{
77 struct nva3_therm_priv *priv;
78 int ret;
79
80 ret = nouveau_therm_create(parent, engine, oclass, &priv);
81 *pobject = nv_object(priv);
82 if (ret)
83 return ret;
84
85 priv->base.base.pwm_ctrl = nv50_fan_pwm_ctrl;
86 priv->base.base.pwm_get = nv50_fan_pwm_get;
87 priv->base.base.pwm_set = nv50_fan_pwm_set;
88 priv->base.base.pwm_clock = nv50_fan_pwm_clock;
89 priv->base.base.temp_get = nv84_temp_get;
90 priv->base.base.fan_sense = nva3_therm_fan_sense;
91 priv->base.sensor.program_alarms = nouveau_therm_program_alarms_polling;
92 return nouveau_therm_preinit(&priv->base.base);
93}
94
95struct nouveau_oclass
96nva3_therm_oclass = {
97 .handle = NV_SUBDEV(THERM, 0xa3),
98 .ofuncs = &(struct nouveau_ofuncs) {
99 .ctor = nva3_therm_ctor,
100 .dtor = _nouveau_therm_dtor,
101 .init = nva3_therm_init,
102 .fini = nv84_therm_fini,
103 },
104};
105