blob: dbd283f0d4181829b38bed0a7cd360b57a8d19ca (
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
/* 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);
/*
* Holds thermal->lock.
*
* Does nothing if the thermal management is not supported.
*/
static inline void edgetpu_thermal_lock(struct edgetpu_thermal *thermal)
{
if (!IS_ERR_OR_NULL(thermal))
mutex_lock(&thermal->lock);
}
/*
* 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;
}
/*
* Releases thermal->lock.
*
* Does nothing if the thermal management is not supported.
*/
static inline void edgetpu_thermal_unlock(struct edgetpu_thermal *thermal)
{
if (!IS_ERR_OR_NULL(thermal))
mutex_unlock(&thermal->lock);
}
#endif /* __EDGETPU_THERMAL_H__ */
|