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