• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2014 Martin Peres
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: Martin Peres
23  */
24 #include "priv.h"
25 
26 static int
gm107_fan_pwm_ctrl(struct nvkm_therm * therm,int line,bool enable)27 gm107_fan_pwm_ctrl(struct nvkm_therm *therm, int line, bool enable)
28 {
29 	/* nothing to do, it seems hardwired */
30 	return 0;
31 }
32 
33 static int
gm107_fan_pwm_get(struct nvkm_therm * therm,int line,u32 * divs,u32 * duty)34 gm107_fan_pwm_get(struct nvkm_therm *therm, int line, u32 *divs, u32 *duty)
35 {
36 	struct nvkm_device *device = therm->subdev.device;
37 	*divs = nvkm_rd32(device, 0x10eb20) & 0x1fff;
38 	*duty = nvkm_rd32(device, 0x10eb24) & 0x1fff;
39 	return 0;
40 }
41 
42 static int
gm107_fan_pwm_set(struct nvkm_therm * therm,int line,u32 divs,u32 duty)43 gm107_fan_pwm_set(struct nvkm_therm *therm, int line, u32 divs, u32 duty)
44 {
45 	struct nvkm_device *device = therm->subdev.device;
46 	nvkm_mask(device, 0x10eb10, 0x1fff, divs); /* keep the high bits */
47 	nvkm_wr32(device, 0x10eb14, duty | 0x80000000);
48 	return 0;
49 }
50 
51 static int
gm107_fan_pwm_clock(struct nvkm_therm * therm,int line)52 gm107_fan_pwm_clock(struct nvkm_therm *therm, int line)
53 {
54 	return therm->subdev.device->crystal * 1000;
55 }
56 
57 static const struct nvkm_therm_func
58 gm107_therm = {
59 	.init = gf119_therm_init,
60 	.fini = g84_therm_fini,
61 	.pwm_ctrl = gm107_fan_pwm_ctrl,
62 	.pwm_get = gm107_fan_pwm_get,
63 	.pwm_set = gm107_fan_pwm_set,
64 	.pwm_clock = gm107_fan_pwm_clock,
65 	.temp_get = g84_temp_get,
66 	.fan_sense = gt215_therm_fan_sense,
67 	.program_alarms = nvkm_therm_program_alarms_polling,
68 };
69 
70 int
gm107_therm_new(struct nvkm_device * device,int index,struct nvkm_therm ** ptherm)71 gm107_therm_new(struct nvkm_device *device, int index,
72 		struct nvkm_therm **ptherm)
73 {
74 	return nvkm_therm_new_(&gm107_therm, device, index, ptherm);
75 }
76