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
36struct 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
53enum nouveau_therm_thrs_direction {
54 NOUVEAU_THERM_THRS_FALLING = 0,
55 NOUVEAU_THERM_THRS_RISING = 1
56};
57
58enum nouveau_therm_thrs_state {
59 NOUVEAU_THERM_THRS_LOWER = 0,
60 NOUVEAU_THERM_THRS_HIGHER = 1
61};
62
63enum 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
71struct 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 cstate;
80 int suspend;
81
82 /* bios */
83 struct nvbios_therm_sensor bios_sensor;
84
85 /* fan priv */
86 struct nouveau_fan *fan;
87
88 /* alarms priv */
89 struct {
90 spinlock_t alarm_program_lock;
91 struct nouveau_alarm therm_poll_alarm;
92 enum nouveau_therm_thrs_state alarm_state[NOUVEAU_THERM_THRS_NR];
93 void (*program_alarms)(struct nouveau_therm *);
94 } sensor;
95
96 /* what should be done if the card overheats */
97 struct {
98 void (*downclock)(struct nouveau_therm *, bool active);
99 void (*pause)(struct nouveau_therm *, bool active);
100 } emergency;
101
102 /* ic */
103 struct i2c_client *ic;
104};
105
106int nouveau_therm_fan_mode(struct nouveau_therm *therm, int mode);
107int nouveau_therm_attr_get(struct nouveau_therm *therm,
108 enum nouveau_therm_attr_type type);
109int nouveau_therm_attr_set(struct nouveau_therm *therm,
110 enum nouveau_therm_attr_type type, int value);
111
112void nouveau_therm_ic_ctor(struct nouveau_therm *therm);
113
114int nouveau_therm_sensor_ctor(struct nouveau_therm *therm);
115
116int nouveau_therm_fan_ctor(struct nouveau_therm *therm);
117int nouveau_therm_fan_init(struct nouveau_therm *therm);
118int nouveau_therm_fan_fini(struct nouveau_therm *therm, bool suspend);
119int nouveau_therm_fan_get(struct nouveau_therm *therm);
120int nouveau_therm_fan_set(struct nouveau_therm *therm, bool now, int percent);
121int nouveau_therm_fan_user_get(struct nouveau_therm *therm);
122int nouveau_therm_fan_user_set(struct nouveau_therm *therm, int percent);
123
124int nouveau_therm_fan_sense(struct nouveau_therm *therm);
125
126int nouveau_therm_preinit(struct nouveau_therm *);
127
128int nouveau_therm_sensor_init(struct nouveau_therm *therm);
129int nouveau_therm_sensor_fini(struct nouveau_therm *therm, bool suspend);
130void nouveau_therm_sensor_preinit(struct nouveau_therm *);
131void nouveau_therm_sensor_set_threshold_state(struct nouveau_therm *therm,
132 enum nouveau_therm_thrs thrs,
133 enum nouveau_therm_thrs_state st);
134enum nouveau_therm_thrs_state
135nouveau_therm_sensor_get_threshold_state(struct nouveau_therm *therm,
136 enum nouveau_therm_thrs thrs);
137void nouveau_therm_sensor_event(struct nouveau_therm *therm,
138 enum nouveau_therm_thrs thrs,
139 enum nouveau_therm_thrs_direction dir);
140void nouveau_therm_program_alarms_polling(struct nouveau_therm *therm);
141
142void nv40_therm_intr(struct nouveau_subdev *);
143int nv50_fan_pwm_ctrl(struct nouveau_therm *, int, bool);
144int nv50_fan_pwm_get(struct nouveau_therm *, int, u32 *, u32 *);
145int nv50_fan_pwm_set(struct nouveau_therm *, int, u32, u32);
146int nv50_fan_pwm_clock(struct nouveau_therm *, int);
147int nv84_temp_get(struct nouveau_therm *therm);
148int nv84_therm_fini(struct nouveau_object *object, bool suspend);
149
150int nva3_therm_fan_sense(struct nouveau_therm *);
151
152int nouveau_fanpwm_create(struct nouveau_therm *, struct dcb_gpio_func *);
153int nouveau_fantog_create(struct nouveau_therm *, struct dcb_gpio_func *);
154int nouveau_fannil_create(struct nouveau_therm *);
155
156#endif
157