1/*	$NetBSD: priv.h,v 1.4 2021/12/19 11:34:46 riastradh Exp $	*/
2
3#ifndef __NVTHERM_PRIV_H__
4#define __NVTHERM_PRIV_H__
5#define nvkm_therm(p) container_of((p), struct nvkm_therm, subdev)
6/*
7 * Copyright 2012 The Nouveau community
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
22 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
26 *
27 * Authors: Martin Peres
28 */
29#include <subdev/therm.h>
30#include <subdev/bios.h>
31#include <subdev/bios/extdev.h>
32#include <subdev/bios/gpio.h>
33#include <subdev/bios/perf.h>
34
35int nvkm_therm_new_(const struct nvkm_therm_func *, struct nvkm_device *,
36		    int index, struct nvkm_therm **);
37void nvkm_therm_ctor(struct nvkm_therm *therm, struct nvkm_device *device,
38		     int index, const struct nvkm_therm_func *func);
39
40struct nvkm_fan {
41	struct nvkm_therm *parent;
42	const char *type;
43
44	struct nvbios_therm_fan bios;
45	struct nvbios_perf_fan perf;
46
47	struct nvkm_alarm alarm;
48	spinlock_t lock;
49	int percent;
50
51	int (*get)(struct nvkm_therm *);
52	int (*set)(struct nvkm_therm *, int percent);
53	void (*dtor)(struct nvkm_fan *);
54
55	struct dcb_gpio_func tach;
56};
57
58int nvkm_therm_fan_mode(struct nvkm_therm *, int mode);
59int nvkm_therm_attr_get(struct nvkm_therm *, enum nvkm_therm_attr_type);
60int nvkm_therm_attr_set(struct nvkm_therm *, enum nvkm_therm_attr_type, int);
61
62void nvkm_therm_ic_ctor(struct nvkm_therm *);
63
64int nvkm_therm_sensor_ctor(struct nvkm_therm *);
65
66int nvkm_therm_fan_ctor(struct nvkm_therm *);
67void nvkm_therm_fan_dtor(struct nvkm_therm *);
68int nvkm_therm_fan_init(struct nvkm_therm *);
69int nvkm_therm_fan_fini(struct nvkm_therm *, bool suspend);
70int nvkm_therm_fan_get(struct nvkm_therm *);
71int nvkm_therm_fan_set(struct nvkm_therm *, bool now, int percent);
72int nvkm_therm_fan_user_get(struct nvkm_therm *);
73int nvkm_therm_fan_user_set(struct nvkm_therm *, int percent);
74
75int  nvkm_therm_sensor_init(struct nvkm_therm *);
76int  nvkm_therm_sensor_fini(struct nvkm_therm *, bool suspend);
77void nvkm_therm_sensor_preinit(struct nvkm_therm *);
78void nvkm_therm_sensor_set_threshold_state(struct nvkm_therm *,
79					   enum nvkm_therm_thrs,
80					   enum nvkm_therm_thrs_state);
81enum nvkm_therm_thrs_state
82nvkm_therm_sensor_get_threshold_state(struct nvkm_therm *,
83				      enum nvkm_therm_thrs);
84void nvkm_therm_sensor_event(struct nvkm_therm *, enum nvkm_therm_thrs,
85			     enum nvkm_therm_thrs_direction);
86void nvkm_therm_program_alarms_polling(struct nvkm_therm *);
87
88struct nvkm_therm_func {
89	void (*init)(struct nvkm_therm *);
90	void (*fini)(struct nvkm_therm *);
91	void (*intr)(struct nvkm_therm *);
92
93	int (*pwm_ctrl)(struct nvkm_therm *, int line, bool);
94	int (*pwm_get)(struct nvkm_therm *, int line, u32 *, u32 *);
95	int (*pwm_set)(struct nvkm_therm *, int line, u32, u32);
96	int (*pwm_clock)(struct nvkm_therm *, int line);
97
98	int (*temp_get)(struct nvkm_therm *);
99
100	int (*fan_sense)(struct nvkm_therm *);
101
102	void (*program_alarms)(struct nvkm_therm *);
103
104	void (*clkgate_init)(struct nvkm_therm *,
105			     const struct nvkm_therm_clkgate_pack *);
106	void (*clkgate_enable)(struct nvkm_therm *);
107	void (*clkgate_fini)(struct nvkm_therm *, bool);
108};
109
110void nv40_therm_intr(struct nvkm_therm *);
111
112int  nv50_fan_pwm_ctrl(struct nvkm_therm *, int, bool);
113int  nv50_fan_pwm_get(struct nvkm_therm *, int, u32 *, u32 *);
114int  nv50_fan_pwm_set(struct nvkm_therm *, int, u32, u32);
115int  nv50_fan_pwm_clock(struct nvkm_therm *, int);
116
117int  g84_temp_get(struct nvkm_therm *);
118void g84_sensor_setup(struct nvkm_therm *);
119void g84_therm_fini(struct nvkm_therm *);
120
121int gt215_therm_fan_sense(struct nvkm_therm *);
122
123void gf100_clkgate_init(struct nvkm_therm *,
124			const struct nvkm_therm_clkgate_pack *);
125
126void g84_therm_init(struct nvkm_therm *);
127
128int gf119_fan_pwm_ctrl(struct nvkm_therm *, int, bool);
129int gf119_fan_pwm_get(struct nvkm_therm *, int, u32 *, u32 *);
130int gf119_fan_pwm_set(struct nvkm_therm *, int, u32, u32);
131int gf119_fan_pwm_clock(struct nvkm_therm *, int);
132void gf119_therm_init(struct nvkm_therm *);
133
134void gk104_therm_init(struct nvkm_therm *);
135void gk104_clkgate_enable(struct nvkm_therm *);
136void gk104_clkgate_fini(struct nvkm_therm *, bool);
137
138int nvkm_fanpwm_create(struct nvkm_therm *, struct dcb_gpio_func *);
139int nvkm_fantog_create(struct nvkm_therm *, struct dcb_gpio_func *);
140int nvkm_fannil_create(struct nvkm_therm *);
141#endif
142