drm/nouveau/therm: move thermal-related functions to the therm subdev
[linux-2.6.git] / drivers / gpu / drm / nouveau / core / subdev / therm / nv50.c
blobf7f51f35d18bfbcca0a2641f58d12ace184ca027
1 /*
2 * Copyright 2012 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
22 * Authors: Ben Skeggs
23 * Martin Peres
26 #include "priv.h"
28 static int
29 pwm_info(struct nouveau_therm *therm, int *line, int *ctrl, int *indx)
31 if (*line == 0x04) {
32 *ctrl = 0x00e100;
33 *line = 4;
34 *indx = 0;
35 } else
36 if (*line == 0x09) {
37 *ctrl = 0x00e100;
38 *line = 9;
39 *indx = 1;
40 } else
41 if (*line == 0x10) {
42 *ctrl = 0x00e28c;
43 *line = 0;
44 *indx = 0;
45 } else {
46 nv_error(therm, "unknown pwm ctrl for gpio %d\n", *line);
47 return -ENODEV;
50 return 0;
53 int
54 nv50_fan_pwm_get(struct nouveau_therm *therm, int line, u32 *divs, u32 *duty)
56 int ctrl, id, ret = pwm_info(therm, &line, &ctrl, &id);
57 if (ret)
58 return ret;
60 if (nv_rd32(therm, ctrl) & (1 << line)) {
61 *divs = nv_rd32(therm, 0x00e114 + (id * 8));
62 *duty = nv_rd32(therm, 0x00e118 + (id * 8));
63 return 0;
66 return -EINVAL;
69 int
70 nv50_fan_pwm_set(struct nouveau_therm *therm, int line, u32 divs, u32 duty)
72 int ctrl, id, ret = pwm_info(therm, &line, &ctrl, &id);
73 if (ret)
74 return ret;
76 nv_mask(therm, ctrl, 0x00010001 << line, 0x00000001 << line);
77 nv_wr32(therm, 0x00e114 + (id * 8), divs);
78 nv_wr32(therm, 0x00e118 + (id * 8), duty | 0x80000000);
79 return 0;
82 int
83 nv50_temp_get(struct nouveau_therm *therm)
85 return nv_rd32(therm, 0x20400);
88 static int
89 nv50_therm_ctor(struct nouveau_object *parent,
90 struct nouveau_object *engine,
91 struct nouveau_oclass *oclass, void *data, u32 size,
92 struct nouveau_object **pobject)
94 struct nouveau_therm_priv *priv;
95 struct nouveau_therm *therm;
96 int ret;
98 ret = nouveau_therm_create(parent, engine, oclass, &priv);
99 *pobject = nv_object(priv);
100 therm = (void *) priv;
101 if (ret)
102 return ret;
104 nouveau_therm_ic_ctor(therm);
105 nouveau_therm_sensor_ctor(therm);
106 nouveau_therm_fan_ctor(therm);
108 priv->fan.pwm_get = nv50_fan_pwm_get;
109 priv->fan.pwm_set = nv50_fan_pwm_set;
111 therm->temp_get = nv50_temp_get;
112 therm->fan_get = nouveau_therm_fan_get;
113 therm->fan_set = nouveau_therm_fan_set;
114 therm->fan_sense = nouveau_therm_fan_sense;
115 therm->attr_get = nouveau_therm_attr_get;
116 therm->attr_set = nouveau_therm_attr_set;
118 return 0;
121 struct nouveau_oclass
122 nv50_therm_oclass = {
123 .handle = NV_SUBDEV(THERM, 0x50),
124 .ofuncs = &(struct nouveau_ofuncs) {
125 .ctor = nv50_therm_ctor,
126 .dtor = _nouveau_therm_dtor,
127 .init = nouveau_therm_init,
128 .fini = nouveau_therm_fini,