Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / hwmon / peci / common.h
blob734506b0eca26749ae85bec031447c7edf966d17
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright (c) 2021 Intel Corporation */
4 #include <linux/mutex.h>
5 #include <linux/types.h>
7 #ifndef __PECI_HWMON_COMMON_H
8 #define __PECI_HWMON_COMMON_H
10 #define PECI_HWMON_UPDATE_INTERVAL HZ
12 /**
13 * struct peci_sensor_state - PECI state information
14 * @valid: flag to indicate the sensor value is valid
15 * @last_updated: time of the last update in jiffies
16 * @lock: mutex to protect sensor access
18 struct peci_sensor_state {
19 bool valid;
20 unsigned long last_updated;
21 struct mutex lock; /* protect sensor access */
24 /**
25 * struct peci_sensor_data - PECI sensor information
26 * @value: sensor value in milli units
27 * @state: sensor update state
30 struct peci_sensor_data {
31 s32 value;
32 struct peci_sensor_state state;
35 /**
36 * peci_sensor_need_update() - check whether sensor update is needed or not
37 * @sensor: pointer to sensor data struct
39 * Return: true if update is needed, false if not.
42 static inline bool peci_sensor_need_update(struct peci_sensor_state *state)
44 return !state->valid ||
45 time_after(jiffies, state->last_updated + PECI_HWMON_UPDATE_INTERVAL);
48 /**
49 * peci_sensor_mark_updated() - mark the sensor is updated
50 * @sensor: pointer to sensor data struct
52 static inline void peci_sensor_mark_updated(struct peci_sensor_state *state)
54 state->valid = true;
55 state->last_updated = jiffies;
58 #endif /* __PECI_HWMON_COMMON_H */