summaryrefslogtreecommitdiff
path: root/drivers/edgetpu/edgetpu-thermal.h
blob: 0c163e0f0573421a0ff01e66e6838be6ef7aa55a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * EdgeTPU thermal driver header.
 *
 * Copyright (C) 2020 Google, Inc.
 */
#ifndef __EDGETPU_THERMAL_H__
#define __EDGETPU_THERMAL_H__

#include <linux/debugfs.h>
#include <linux/device.h>
#include <linux/mutex.h>
#include <linux/thermal.h>

#include "edgetpu-internal.h"

#define EDGETPU_COOLING_NAME "tpu_cooling"

struct edgetpu_thermal {
	struct device *dev;
	struct dentry *cooling_root;
	struct thermal_cooling_device *cdev;
	struct mutex lock;
	void *op_data;
	unsigned long cooling_state;
	unsigned long sysfs_req;
	unsigned int tpu_num_states;
	struct edgetpu_dev *etdev;
	bool thermal_suspended; /* TPU thermal suspended state */
};

struct edgetpu_state_pwr {
	unsigned long state;
	u32 power;
};

/*
 * Creates a managed edgetpu_thermal object.
 *
 * Returns -errno on error.
 */
struct edgetpu_thermal *devm_tpu_thermal_create(struct device *dev,
						struct edgetpu_dev *etdev);

/*
 * Marks the TPU is suspended and informs TPU device if it's powered.
 *
 * Returns 0 on success.
 */
int edgetpu_thermal_suspend(struct device *dev);
/*
 * Resumes the TPU from the suspend state and informs TPU CPU if it's powered.
 *
 * Returns 0 on success.
 */
int edgetpu_thermal_resume(struct device *dev);

/*
 * Checks whether device is thermal suspended.
 * Returns false if the thermal management is not supported.
 */
static inline bool edgetpu_thermal_is_suspended(struct edgetpu_thermal *thermal)
{
	if (!IS_ERR_OR_NULL(thermal))
		return thermal->thermal_suspended;
	return false;
}

#endif /* __EDGETPU_THERMAL_H__ */