1 #ifndef __NVTHERM_PRIV_H__
2 #define __NVTHERM_PRIV_H__
3 #define nvkm_therm(p) container_of((p), struct nvkm_therm, subdev)
4 /*
5  * Copyright 2012 The Nouveau community
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation
10  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11  * and/or sell copies of the Software, and to permit persons to whom the
12  * Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
21  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23  * OTHER DEALINGS IN THE SOFTWARE.
24  *
25  * Authors: Martin Peres
26  */
27 #include <subdev/therm.h>
28 #include <subdev/bios.h>
29 #include <subdev/bios/extdev.h>
30 #include <subdev/bios/gpio.h>
31 #include <subdev/bios/perf.h>
32 
33 int nvkm_therm_new_(const struct nvkm_therm_func *, struct nvkm_device *,
34 		    int index, struct nvkm_therm **);
35 
36 struct nvkm_fan {
37 	struct nvkm_therm *parent;
38 	const char *type;
39 
40 	struct nvbios_therm_fan bios;
41 	struct nvbios_perf_fan perf;
42 
43 	struct nvkm_alarm alarm;
44 	spinlock_t lock;
45 	int percent;
46 
47 	int (*get)(struct nvkm_therm *);
48 	int (*set)(struct nvkm_therm *, int percent);
49 
50 	struct dcb_gpio_func tach;
51 };
52 
53 int nvkm_therm_fan_mode(struct nvkm_therm *, int mode);
54 int nvkm_therm_attr_get(struct nvkm_therm *, enum nvkm_therm_attr_type);
55 int nvkm_therm_attr_set(struct nvkm_therm *, enum nvkm_therm_attr_type, int);
56 
57 void nvkm_therm_ic_ctor(struct nvkm_therm *);
58 
59 int nvkm_therm_sensor_ctor(struct nvkm_therm *);
60 
61 int nvkm_therm_fan_ctor(struct nvkm_therm *);
62 int nvkm_therm_fan_init(struct nvkm_therm *);
63 int nvkm_therm_fan_fini(struct nvkm_therm *, bool suspend);
64 int nvkm_therm_fan_get(struct nvkm_therm *);
65 int nvkm_therm_fan_set(struct nvkm_therm *, bool now, int percent);
66 int nvkm_therm_fan_user_get(struct nvkm_therm *);
67 int nvkm_therm_fan_user_set(struct nvkm_therm *, int percent);
68 
69 int nvkm_therm_preinit(struct nvkm_therm *);
70 
71 int  nvkm_therm_sensor_init(struct nvkm_therm *);
72 int  nvkm_therm_sensor_fini(struct nvkm_therm *, bool suspend);
73 void nvkm_therm_sensor_preinit(struct nvkm_therm *);
74 void nvkm_therm_sensor_set_threshold_state(struct nvkm_therm *,
75 					   enum nvkm_therm_thrs,
76 					   enum nvkm_therm_thrs_state);
77 enum nvkm_therm_thrs_state
78 nvkm_therm_sensor_get_threshold_state(struct nvkm_therm *,
79 				      enum nvkm_therm_thrs);
80 void nvkm_therm_sensor_event(struct nvkm_therm *, enum nvkm_therm_thrs,
81 			     enum nvkm_therm_thrs_direction);
82 void nvkm_therm_program_alarms_polling(struct nvkm_therm *);
83 
84 struct nvkm_therm_func {
85 	void (*init)(struct nvkm_therm *);
86 	void (*fini)(struct nvkm_therm *);
87 	void (*intr)(struct nvkm_therm *);
88 
89 	int (*pwm_ctrl)(struct nvkm_therm *, int line, bool);
90 	int (*pwm_get)(struct nvkm_therm *, int line, u32 *, u32 *);
91 	int (*pwm_set)(struct nvkm_therm *, int line, u32, u32);
92 	int (*pwm_clock)(struct nvkm_therm *, int line);
93 
94 	int (*temp_get)(struct nvkm_therm *);
95 
96 	int (*fan_sense)(struct nvkm_therm *);
97 
98 	void (*program_alarms)(struct nvkm_therm *);
99 };
100 
101 void nv40_therm_intr(struct nvkm_therm *);
102 
103 int  nv50_fan_pwm_ctrl(struct nvkm_therm *, int, bool);
104 int  nv50_fan_pwm_get(struct nvkm_therm *, int, u32 *, u32 *);
105 int  nv50_fan_pwm_set(struct nvkm_therm *, int, u32, u32);
106 int  nv50_fan_pwm_clock(struct nvkm_therm *, int);
107 
108 int  g84_temp_get(struct nvkm_therm *);
109 void g84_sensor_setup(struct nvkm_therm *);
110 void g84_therm_fini(struct nvkm_therm *);
111 
112 int gt215_therm_fan_sense(struct nvkm_therm *);
113 
114 void gf119_therm_init(struct nvkm_therm *);
115 
116 int nvkm_fanpwm_create(struct nvkm_therm *, struct dcb_gpio_func *);
117 int nvkm_fantog_create(struct nvkm_therm *, struct dcb_gpio_func *);
118 int nvkm_fannil_create(struct nvkm_therm *);
119 #endif
120