• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: MIT */
2 #ifndef __NVKM_THERM_H__
3 #define __NVKM_THERM_H__
4 #include <core/subdev.h>
5 
6 #include <subdev/bios.h>
7 #include <subdev/bios/therm.h>
8 #include <subdev/timer.h>
9 
10 enum nvkm_therm_thrs_direction {
11 	NVKM_THERM_THRS_FALLING = 0,
12 	NVKM_THERM_THRS_RISING = 1
13 };
14 
15 enum nvkm_therm_thrs_state {
16 	NVKM_THERM_THRS_LOWER = 0,
17 	NVKM_THERM_THRS_HIGHER = 1
18 };
19 
20 enum nvkm_therm_thrs {
21 	NVKM_THERM_THRS_FANBOOST = 0,
22 	NVKM_THERM_THRS_DOWNCLOCK = 1,
23 	NVKM_THERM_THRS_CRITICAL = 2,
24 	NVKM_THERM_THRS_SHUTDOWN = 3,
25 	NVKM_THERM_THRS_NR
26 };
27 
28 enum nvkm_therm_fan_mode {
29 	NVKM_THERM_CTRL_NONE = 0,
30 	NVKM_THERM_CTRL_MANUAL = 1,
31 	NVKM_THERM_CTRL_AUTO = 2,
32 };
33 
34 enum nvkm_therm_attr_type {
35 	NVKM_THERM_ATTR_FAN_MIN_DUTY = 0,
36 	NVKM_THERM_ATTR_FAN_MAX_DUTY = 1,
37 	NVKM_THERM_ATTR_FAN_MODE = 2,
38 
39 	NVKM_THERM_ATTR_THRS_FAN_BOOST = 10,
40 	NVKM_THERM_ATTR_THRS_FAN_BOOST_HYST = 11,
41 	NVKM_THERM_ATTR_THRS_DOWN_CLK = 12,
42 	NVKM_THERM_ATTR_THRS_DOWN_CLK_HYST = 13,
43 	NVKM_THERM_ATTR_THRS_CRITICAL = 14,
44 	NVKM_THERM_ATTR_THRS_CRITICAL_HYST = 15,
45 	NVKM_THERM_ATTR_THRS_SHUTDOWN = 16,
46 	NVKM_THERM_ATTR_THRS_SHUTDOWN_HYST = 17,
47 };
48 
49 struct nvkm_therm_clkgate_init {
50 	u32 addr;
51 	u8  count;
52 	u32 data;
53 };
54 
55 struct nvkm_therm_clkgate_pack {
56 	const struct nvkm_therm_clkgate_init *init;
57 };
58 
59 struct nvkm_therm {
60 	const struct nvkm_therm_func *func;
61 	struct nvkm_subdev subdev;
62 
63 	/* automatic thermal management */
64 	struct nvkm_alarm alarm;
65 	spinlock_t lock;
66 	struct nvbios_therm_trip_point *last_trip;
67 	int mode;
68 	int cstate;
69 	int suspend;
70 
71 	/* bios */
72 	struct nvbios_therm_sensor bios_sensor;
73 
74 	/* fan priv */
75 	struct nvkm_fan *fan;
76 
77 	/* alarms priv */
78 	struct {
79 		spinlock_t alarm_program_lock;
80 		struct nvkm_alarm therm_poll_alarm;
81 		enum nvkm_therm_thrs_state alarm_state[NVKM_THERM_THRS_NR];
82 	} sensor;
83 
84 	/* what should be done if the card overheats */
85 	struct {
86 		void (*downclock)(struct nvkm_therm *, bool active);
87 		void (*pause)(struct nvkm_therm *, bool active);
88 	} emergency;
89 
90 	/* ic */
91 	struct i2c_client *ic;
92 
93 	int (*fan_get)(struct nvkm_therm *);
94 	int (*fan_set)(struct nvkm_therm *, int);
95 
96 	int (*attr_get)(struct nvkm_therm *, enum nvkm_therm_attr_type);
97 	int (*attr_set)(struct nvkm_therm *, enum nvkm_therm_attr_type, int);
98 
99 	bool clkgating_enabled;
100 };
101 
102 int nvkm_therm_temp_get(struct nvkm_therm *);
103 int nvkm_therm_fan_sense(struct nvkm_therm *);
104 int nvkm_therm_cstate(struct nvkm_therm *, int, int);
105 void nvkm_therm_clkgate_init(struct nvkm_therm *,
106 			     const struct nvkm_therm_clkgate_pack *);
107 void nvkm_therm_clkgate_enable(struct nvkm_therm *);
108 void nvkm_therm_clkgate_fini(struct nvkm_therm *, bool);
109 
110 int nv40_therm_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_therm **);
111 int nv50_therm_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_therm **);
112 int g84_therm_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_therm **);
113 int gt215_therm_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_therm **);
114 int gf119_therm_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_therm **);
115 int gk104_therm_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_therm **);
116 int gm107_therm_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_therm **);
117 int gm200_therm_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_therm **);
118 int gp100_therm_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_therm **);
119 #endif
120