Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / drivers / gpu / drm / nouveau / nvkm / subdev / therm / priv.h
1 #ifndef __NVTHERM_PRIV_H__
2 #define __NVTHERM_PRIV_H__
3 /*
4  * Copyright 2012 The Nouveau community
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22  * OTHER DEALINGS IN THE SOFTWARE.
23  *
24  * Authors: Martin Peres
25  */
26 #include <subdev/therm.h>
27 #include <subdev/bios.h>
28 #include <subdev/bios/extdev.h>
29 #include <subdev/bios/gpio.h>
30 #include <subdev/bios/perf.h>
31 #include <subdev/bios/therm.h>
32 #include <subdev/timer.h>
33
34 struct nvkm_fan {
35         struct nvkm_therm *parent;
36         const char *type;
37
38         struct nvbios_therm_fan bios;
39         struct nvbios_perf_fan perf;
40
41         struct nvkm_alarm alarm;
42         spinlock_t lock;
43         int percent;
44
45         int (*get)(struct nvkm_therm *);
46         int (*set)(struct nvkm_therm *, int percent);
47
48         struct dcb_gpio_func tach;
49 };
50
51 enum nvkm_therm_thrs_direction {
52         NVKM_THERM_THRS_FALLING = 0,
53         NVKM_THERM_THRS_RISING = 1
54 };
55
56 enum nvkm_therm_thrs_state {
57         NVKM_THERM_THRS_LOWER = 0,
58         NVKM_THERM_THRS_HIGHER = 1
59 };
60
61 enum nvkm_therm_thrs {
62         NVKM_THERM_THRS_FANBOOST = 0,
63         NVKM_THERM_THRS_DOWNCLOCK = 1,
64         NVKM_THERM_THRS_CRITICAL = 2,
65         NVKM_THERM_THRS_SHUTDOWN = 3,
66         NVKM_THERM_THRS_NR
67 };
68
69 struct nvkm_therm_priv {
70         struct nvkm_therm base;
71
72         /* automatic thermal management */
73         struct nvkm_alarm alarm;
74         spinlock_t lock;
75         struct nvbios_therm_trip_point *last_trip;
76         int mode;
77         int cstate;
78         int suspend;
79
80         /* bios */
81         struct nvbios_therm_sensor bios_sensor;
82
83         /* fan priv */
84         struct nvkm_fan *fan;
85
86         /* alarms priv */
87         struct {
88                 spinlock_t alarm_program_lock;
89                 struct nvkm_alarm therm_poll_alarm;
90                 enum nvkm_therm_thrs_state alarm_state[NVKM_THERM_THRS_NR];
91                 void (*program_alarms)(struct nvkm_therm *);
92         } sensor;
93
94         /* what should be done if the card overheats */
95         struct {
96                 void (*downclock)(struct nvkm_therm *, bool active);
97                 void (*pause)(struct nvkm_therm *, bool active);
98         } emergency;
99
100         /* ic */
101         struct i2c_client *ic;
102 };
103
104 int nvkm_therm_fan_mode(struct nvkm_therm *, int mode);
105 int nvkm_therm_attr_get(struct nvkm_therm *, enum nvkm_therm_attr_type);
106 int nvkm_therm_attr_set(struct nvkm_therm *, enum nvkm_therm_attr_type, int);
107
108 void nvkm_therm_ic_ctor(struct nvkm_therm *);
109
110 int nvkm_therm_sensor_ctor(struct nvkm_therm *);
111
112 int nvkm_therm_fan_ctor(struct nvkm_therm *);
113 int nvkm_therm_fan_init(struct nvkm_therm *);
114 int nvkm_therm_fan_fini(struct nvkm_therm *, bool suspend);
115 int nvkm_therm_fan_get(struct nvkm_therm *);
116 int nvkm_therm_fan_set(struct nvkm_therm *, bool now, int percent);
117 int nvkm_therm_fan_user_get(struct nvkm_therm *);
118 int nvkm_therm_fan_user_set(struct nvkm_therm *, int percent);
119
120 int nvkm_therm_fan_sense(struct nvkm_therm *);
121
122 int nvkm_therm_preinit(struct nvkm_therm *);
123
124 int  nvkm_therm_sensor_init(struct nvkm_therm *);
125 int  nvkm_therm_sensor_fini(struct nvkm_therm *, bool suspend);
126 void nvkm_therm_sensor_preinit(struct nvkm_therm *);
127 void nvkm_therm_sensor_set_threshold_state(struct nvkm_therm *,
128                                            enum nvkm_therm_thrs,
129                                            enum nvkm_therm_thrs_state);
130 enum nvkm_therm_thrs_state
131 nvkm_therm_sensor_get_threshold_state(struct nvkm_therm *,
132                                       enum nvkm_therm_thrs);
133 void nvkm_therm_sensor_event(struct nvkm_therm *, enum nvkm_therm_thrs,
134                              enum nvkm_therm_thrs_direction);
135 void nvkm_therm_program_alarms_polling(struct nvkm_therm *);
136
137 void nv40_therm_intr(struct nvkm_subdev *);
138 int  nv50_fan_pwm_ctrl(struct nvkm_therm *, int, bool);
139 int  nv50_fan_pwm_get(struct nvkm_therm *, int, u32 *, u32 *);
140 int  nv50_fan_pwm_set(struct nvkm_therm *, int, u32, u32);
141 int  nv50_fan_pwm_clock(struct nvkm_therm *, int);
142 int  g84_temp_get(struct nvkm_therm *);
143 void g84_sensor_setup(struct nvkm_therm *);
144 int  g84_therm_fini(struct nvkm_object *, bool suspend);
145
146 int gt215_therm_fan_sense(struct nvkm_therm *);
147
148 int gf110_therm_init(struct nvkm_object *);
149
150 int nvkm_fanpwm_create(struct nvkm_therm *, struct dcb_gpio_func *);
151 int nvkm_fantog_create(struct nvkm_therm *, struct dcb_gpio_func *);
152 int nvkm_fannil_create(struct nvkm_therm *);
153 #endif