priv.h 4.8 KB
Newer Older
1 2
#ifndef __NVTHERM_PRIV_H__
#define __NVTHERM_PRIV_H__
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/*
 * Copyright 2012 The Nouveau community
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Authors: Martin Peres
 */
#include <subdev/therm.h>
27
#include <subdev/bios.h>
28
#include <subdev/bios/extdev.h>
29
#include <subdev/bios/gpio.h>
30 31
#include <subdev/bios/perf.h>
#include <subdev/bios/therm.h>
32
#include <subdev/timer.h>
33

34 35
struct nvkm_fan {
	struct nvkm_therm *parent;
36 37 38 39 40
	const char *type;

	struct nvbios_therm_fan bios;
	struct nvbios_perf_fan perf;

41
	struct nvkm_alarm alarm;
42 43 44
	spinlock_t lock;
	int percent;

45 46
	int (*get)(struct nvkm_therm *);
	int (*set)(struct nvkm_therm *, int percent);
47 48 49 50

	struct dcb_gpio_func tach;
};

51 52 53
enum nvkm_therm_thrs_direction {
	NVKM_THERM_THRS_FALLING = 0,
	NVKM_THERM_THRS_RISING = 1
54 55
};

56 57 58
enum nvkm_therm_thrs_state {
	NVKM_THERM_THRS_LOWER = 0,
	NVKM_THERM_THRS_HIGHER = 1
59 60
};

61 62 63 64 65 66
enum nvkm_therm_thrs {
	NVKM_THERM_THRS_FANBOOST = 0,
	NVKM_THERM_THRS_DOWNCLOCK = 1,
	NVKM_THERM_THRS_CRITICAL = 2,
	NVKM_THERM_THRS_SHUTDOWN = 3,
	NVKM_THERM_THRS_NR
67 68
};

69 70
struct nvkm_therm_priv {
	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 81 82 83
	/* bios */
	struct nvbios_therm_sensor bios_sensor;

	/* fan priv */
84
	struct nvkm_fan *fan;
85

86 87 88
	/* alarms priv */
	struct {
		spinlock_t alarm_program_lock;
89 90 91
		struct nvkm_alarm therm_poll_alarm;
		enum nvkm_therm_thrs_state alarm_state[NVKM_THERM_THRS_NR];
		void (*program_alarms)(struct nvkm_therm *);
92 93 94 95
	} sensor;

	/* what should be done if the card overheats */
	struct {
96 97
		void (*downclock)(struct nvkm_therm *, bool active);
		void (*pause)(struct nvkm_therm *, bool active);
98 99
	} emergency;

100 101 102 103
	/* ic */
	struct i2c_client *ic;
};

104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
int nvkm_therm_fan_mode(struct nvkm_therm *, int mode);
int nvkm_therm_attr_get(struct nvkm_therm *, enum nvkm_therm_attr_type);
int nvkm_therm_attr_set(struct nvkm_therm *, enum nvkm_therm_attr_type, int);

void nvkm_therm_ic_ctor(struct nvkm_therm *);

int nvkm_therm_sensor_ctor(struct nvkm_therm *);

int nvkm_therm_fan_ctor(struct nvkm_therm *);
int nvkm_therm_fan_init(struct nvkm_therm *);
int nvkm_therm_fan_fini(struct nvkm_therm *, bool suspend);
int nvkm_therm_fan_get(struct nvkm_therm *);
int nvkm_therm_fan_set(struct nvkm_therm *, bool now, int percent);
int nvkm_therm_fan_user_get(struct nvkm_therm *);
int nvkm_therm_fan_user_set(struct nvkm_therm *, int percent);

int nvkm_therm_fan_sense(struct nvkm_therm *);

int nvkm_therm_preinit(struct nvkm_therm *);

int  nvkm_therm_sensor_init(struct nvkm_therm *);
int  nvkm_therm_sensor_fini(struct nvkm_therm *, bool suspend);
void nvkm_therm_sensor_preinit(struct nvkm_therm *);
void nvkm_therm_sensor_set_threshold_state(struct nvkm_therm *,
					   enum nvkm_therm_thrs,
					   enum nvkm_therm_thrs_state);
enum nvkm_therm_thrs_state
nvkm_therm_sensor_get_threshold_state(struct nvkm_therm *,
				      enum nvkm_therm_thrs);
void nvkm_therm_sensor_event(struct nvkm_therm *, enum nvkm_therm_thrs,
			     enum nvkm_therm_thrs_direction);
void nvkm_therm_program_alarms_polling(struct nvkm_therm *);

void nv40_therm_intr(struct nvkm_subdev *);
int  nv50_fan_pwm_ctrl(struct nvkm_therm *, int, bool);
int  nv50_fan_pwm_get(struct nvkm_therm *, int, u32 *, u32 *);
int  nv50_fan_pwm_set(struct nvkm_therm *, int, u32, u32);
int  nv50_fan_pwm_clock(struct nvkm_therm *, int);
int  g84_temp_get(struct nvkm_therm *);
void g84_sensor_setup(struct nvkm_therm *);
int  g84_therm_fini(struct nvkm_object *, bool suspend);

int gt215_therm_fan_sense(struct nvkm_therm *);

int gf110_therm_init(struct nvkm_object *);

int nvkm_fanpwm_create(struct nvkm_therm *, struct dcb_gpio_func *);
int nvkm_fantog_create(struct nvkm_therm *, struct dcb_gpio_func *);
int nvkm_fannil_create(struct nvkm_therm *);
153
#endif