s3c-adc-battery: Fix possible NULL pointer dereference
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / drm / nouveau / core / subdev / therm / priv.h
1 #ifndef __NVTHERM_PRIV_H__
2 #define __NVTHERM_PRIV_H__
3
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
28 #include <subdev/therm.h>
29
30 #include <subdev/bios/extdev.h>
31 #include <subdev/bios/gpio.h>
32 #include <subdev/bios/perf.h>
33 #include <subdev/bios/therm.h>
34 #include <subdev/timer.h>
35
36 struct nouveau_fan {
37         struct nouveau_therm *parent;
38         const char *type;
39
40         struct nvbios_therm_fan bios;
41         struct nvbios_perf_fan perf;
42
43         struct nouveau_alarm alarm;
44         spinlock_t lock;
45         int percent;
46
47         int (*get)(struct nouveau_therm *therm);
48         int (*set)(struct nouveau_therm *therm, int percent);
49
50         struct dcb_gpio_func tach;
51 };
52
53 enum nouveau_therm_thrs_direction {
54         NOUVEAU_THERM_THRS_FALLING = 0,
55         NOUVEAU_THERM_THRS_RISING = 1
56 };
57
58 enum nouveau_therm_thrs_state {
59         NOUVEAU_THERM_THRS_LOWER = 0,
60         NOUVEAU_THERM_THRS_HIGHER = 1
61 };
62
63 enum nouveau_therm_thrs {
64         NOUVEAU_THERM_THRS_FANBOOST = 0,
65         NOUVEAU_THERM_THRS_DOWNCLOCK = 1,
66         NOUVEAU_THERM_THRS_CRITICAL = 2,
67         NOUVEAU_THERM_THRS_SHUTDOWN = 3,
68         NOUVEAU_THERM_THRS_NR
69 };
70
71 struct nouveau_therm_priv {
72         struct nouveau_therm base;
73
74         /* automatic thermal management */
75         struct nouveau_alarm alarm;
76         spinlock_t lock;
77         struct nouveau_therm_trip_point *last_trip;
78         int mode;
79         int suspend;
80
81         /* bios */
82         struct nvbios_therm_sensor bios_sensor;
83
84         /* fan priv */
85         struct nouveau_fan *fan;
86
87         /* alarms priv */
88         struct {
89                 spinlock_t alarm_program_lock;
90                 struct nouveau_alarm therm_poll_alarm;
91                 enum nouveau_therm_thrs_state alarm_state[NOUVEAU_THERM_THRS_NR];
92                 void (*program_alarms)(struct nouveau_therm *);
93         } sensor;
94
95         /* what should be done if the card overheats */
96         struct {
97                 void (*downclock)(struct nouveau_therm *, bool active);
98                 void (*pause)(struct nouveau_therm *, bool active);
99         } emergency;
100
101         /* ic */
102         struct i2c_client *ic;
103 };
104
105 int nouveau_therm_mode(struct nouveau_therm *therm, int mode);
106 int nouveau_therm_attr_get(struct nouveau_therm *therm,
107                        enum nouveau_therm_attr_type type);
108 int nouveau_therm_attr_set(struct nouveau_therm *therm,
109                        enum nouveau_therm_attr_type type, int value);
110
111 void nouveau_therm_ic_ctor(struct nouveau_therm *therm);
112
113 int nouveau_therm_sensor_ctor(struct nouveau_therm *therm);
114
115 int nouveau_therm_fan_ctor(struct nouveau_therm *therm);
116 int nouveau_therm_fan_get(struct nouveau_therm *therm);
117 int nouveau_therm_fan_set(struct nouveau_therm *therm, bool now, int percent);
118 int nouveau_therm_fan_user_get(struct nouveau_therm *therm);
119 int nouveau_therm_fan_user_set(struct nouveau_therm *therm, int percent);
120
121 int nouveau_therm_fan_sense(struct nouveau_therm *therm);
122
123 int nouveau_therm_preinit(struct nouveau_therm *);
124
125 void nouveau_therm_sensor_set_threshold_state(struct nouveau_therm *therm,
126                                              enum nouveau_therm_thrs thrs,
127                                              enum nouveau_therm_thrs_state st);
128 enum nouveau_therm_thrs_state
129 nouveau_therm_sensor_get_threshold_state(struct nouveau_therm *therm,
130                                          enum nouveau_therm_thrs thrs);
131 void nouveau_therm_sensor_event(struct nouveau_therm *therm,
132                                 enum nouveau_therm_thrs thrs,
133                                 enum nouveau_therm_thrs_direction dir);
134 void nouveau_therm_program_alarms_polling(struct nouveau_therm *therm);
135
136 int nv50_fan_pwm_ctrl(struct nouveau_therm *, int, bool);
137 int nv50_fan_pwm_get(struct nouveau_therm *, int, u32 *, u32 *);
138 int nv50_fan_pwm_set(struct nouveau_therm *, int, u32, u32);
139 int nv50_fan_pwm_clock(struct nouveau_therm *);
140 int nv50_temp_get(struct nouveau_therm *therm);
141
142 int nva3_therm_fan_sense(struct nouveau_therm *);
143
144 int nouveau_fanpwm_create(struct nouveau_therm *, struct dcb_gpio_func *);
145 int nouveau_fantog_create(struct nouveau_therm *, struct dcb_gpio_func *);
146 int nouveau_fannil_create(struct nouveau_therm *);
147
148 #endif