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 void nvkm_therm_ctor(struct nvkm_therm *therm, struct nvkm_device *device,
36 		     int index, const struct nvkm_therm_func *func);
37 
38 struct nvkm_fan {
39 	struct nvkm_therm *parent;
40 	const char *type;
41 
42 	struct nvbios_therm_fan bios;
43 	struct nvbios_perf_fan perf;
44 
45 	struct nvkm_alarm alarm;
46 	spinlock_t lock;
47 	int percent;
48 
49 	int (*get)(struct nvkm_therm *);
50 	int (*set)(struct nvkm_therm *, int percent);
51 
52 	struct dcb_gpio_func tach;
53 };
54 
55 int nvkm_therm_fan_mode(struct nvkm_therm *, int mode);
56 int nvkm_therm_attr_get(struct nvkm_therm *, enum nvkm_therm_attr_type);
57 int nvkm_therm_attr_set(struct nvkm_therm *, enum nvkm_therm_attr_type, int);
58 
59 void nvkm_therm_ic_ctor(struct nvkm_therm *);
60 
61 int nvkm_therm_sensor_ctor(struct nvkm_therm *);
62 
63 int nvkm_therm_fan_ctor(struct nvkm_therm *);
64 int nvkm_therm_fan_init(struct nvkm_therm *);
65 int nvkm_therm_fan_fini(struct nvkm_therm *, bool suspend);
66 int nvkm_therm_fan_get(struct nvkm_therm *);
67 int nvkm_therm_fan_set(struct nvkm_therm *, bool now, int percent);
68 int nvkm_therm_fan_user_get(struct nvkm_therm *);
69 int nvkm_therm_fan_user_set(struct nvkm_therm *, int percent);
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 	void (*clkgate_init)(struct nvkm_therm *,
101 			     const struct nvkm_therm_clkgate_pack *);
102 	void (*clkgate_enable)(struct nvkm_therm *);
103 	void (*clkgate_fini)(struct nvkm_therm *, bool);
104 };
105 
106 void nv40_therm_intr(struct nvkm_therm *);
107 
108 int  nv50_fan_pwm_ctrl(struct nvkm_therm *, int, bool);
109 int  nv50_fan_pwm_get(struct nvkm_therm *, int, u32 *, u32 *);
110 int  nv50_fan_pwm_set(struct nvkm_therm *, int, u32, u32);
111 int  nv50_fan_pwm_clock(struct nvkm_therm *, int);
112 
113 int  g84_temp_get(struct nvkm_therm *);
114 void g84_sensor_setup(struct nvkm_therm *);
115 void g84_therm_fini(struct nvkm_therm *);
116 
117 int gt215_therm_fan_sense(struct nvkm_therm *);
118 
119 void gf100_clkgate_init(struct nvkm_therm *,
120 			const struct nvkm_therm_clkgate_pack *);
121 
122 void g84_therm_init(struct nvkm_therm *);
123 
124 int gf119_fan_pwm_ctrl(struct nvkm_therm *, int, bool);
125 int gf119_fan_pwm_get(struct nvkm_therm *, int, u32 *, u32 *);
126 int gf119_fan_pwm_set(struct nvkm_therm *, int, u32, u32);
127 int gf119_fan_pwm_clock(struct nvkm_therm *, int);
128 void gf119_therm_init(struct nvkm_therm *);
129 
130 void gk104_therm_init(struct nvkm_therm *);
131 void gk104_clkgate_enable(struct nvkm_therm *);
132 void gk104_clkgate_fini(struct nvkm_therm *, bool);
133 
134 int nvkm_fanpwm_create(struct nvkm_therm *, struct dcb_gpio_func *);
135 int nvkm_fantog_create(struct nvkm_therm *, struct dcb_gpio_func *);
136 int nvkm_fannil_create(struct nvkm_therm *);
137 #endif
138