summaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/peci/common.h
blob: 734506b0eca26749ae85bec031447c7edf966d17 (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
/* SPDX-License-Identifier: GPL-2.0-only */
/* Copyright (c) 2021 Intel Corporation */

#include <linux/mutex.h>
#include <linux/types.h>

#ifndef __PECI_HWMON_COMMON_H
#define __PECI_HWMON_COMMON_H

#define PECI_HWMON_UPDATE_INTERVAL	HZ

/**
 * struct peci_sensor_state - PECI state information
 * @valid: flag to indicate the sensor value is valid
 * @last_updated: time of the last update in jiffies
 * @lock: mutex to protect sensor access
 */
struct peci_sensor_state {
	bool valid;
	unsigned long last_updated;
	struct mutex lock; /* protect sensor access */
};

/**
 * struct peci_sensor_data - PECI sensor information
 * @value: sensor value in milli units
 * @state: sensor update state
 */

struct peci_sensor_data {
	s32 value;
	struct peci_sensor_state state;
};

/**
 * peci_sensor_need_update() - check whether sensor update is needed or not
 * @sensor: pointer to sensor data struct
 *
 * Return: true if update is needed, false if not.
 */

static inline bool peci_sensor_need_update(struct peci_sensor_state *state)
{
	return !state->valid ||
	       time_after(jiffies, state->last_updated + PECI_HWMON_UPDATE_INTERVAL);
}

/**
 * peci_sensor_mark_updated() - mark the sensor is updated
 * @sensor: pointer to sensor data struct
 */
static inline void peci_sensor_mark_updated(struct peci_sensor_state *state)
{
	state->valid = true;
	state->last_updated = jiffies;
}

#endif /* __PECI_HWMON_COMMON_H */