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
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
{
20 unsigned long last_updated
;
21 struct mutex lock
; /* protect sensor access */
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
{
32 struct peci_sensor_state state
;
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
);
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
)
55 state
->last_updated
= jiffies
;
58 #endif /* __PECI_HWMON_COMMON_H */