brintos

brintos / linux-shallow public Read only

0
0
Text · 1.4 KiB · 734506b Raw
59 lines · c
1/* SPDX-License-Identifier: GPL-2.0-only */2/* Copyright (c) 2021 Intel Corporation */3 4#include <linux/mutex.h>5#include <linux/types.h>6 7#ifndef __PECI_HWMON_COMMON_H8#define __PECI_HWMON_COMMON_H9 10#define PECI_HWMON_UPDATE_INTERVAL	HZ11 12/**13 * struct peci_sensor_state - PECI state information14 * @valid: flag to indicate the sensor value is valid15 * @last_updated: time of the last update in jiffies16 * @lock: mutex to protect sensor access17 */18struct peci_sensor_state {19	bool valid;20	unsigned long last_updated;21	struct mutex lock; /* protect sensor access */22};23 24/**25 * struct peci_sensor_data - PECI sensor information26 * @value: sensor value in milli units27 * @state: sensor update state28 */29 30struct peci_sensor_data {31	s32 value;32	struct peci_sensor_state state;33};34 35/**36 * peci_sensor_need_update() - check whether sensor update is needed or not37 * @sensor: pointer to sensor data struct38 *39 * Return: true if update is needed, false if not.40 */41 42static inline bool peci_sensor_need_update(struct peci_sensor_state *state)43{44	return !state->valid ||45	       time_after(jiffies, state->last_updated + PECI_HWMON_UPDATE_INTERVAL);46}47 48/**49 * peci_sensor_mark_updated() - mark the sensor is updated50 * @sensor: pointer to sensor data struct51 */52static inline void peci_sensor_mark_updated(struct peci_sensor_state *state)53{54	state->valid = true;55	state->last_updated = jiffies;56}57 58#endif /* __PECI_HWMON_COMMON_H */59