2 hwmon.h - part of lm_sensors, Linux kernel modules for hardware monitoring
4 This file declares helper functions for the sysfs class "hwmon",
5 for use by sensors drivers.
7 Copyright (C) 2005 Mark M. Hoffman <mhoffman@lightlink.com>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
17 #include <linux/bitops.h>
20 struct attribute_group;
22 enum hwmon_sensor_types {
31 enum hwmon_chip_attributes {
32 hwmon_chip_temp_reset_history,
33 hwmon_chip_register_tz,
34 hwmon_chip_update_interval,
38 #define HWMON_C_TEMP_RESET_HISTORY BIT(hwmon_chip_temp_reset_history)
39 #define HWMON_C_IN_RESET_HISTORY BIT(hwmon_chip_in_reset_history)
40 #define HWMON_C_REGISTER_TZ BIT(hwmon_chip_register_tz)
41 #define HWMON_C_UPDATE_INTERVAL BIT(hwmon_chip_update_interval)
42 #define HWMON_C_ALARMS BIT(hwmon_chip_alarms)
44 enum hwmon_temp_attributes {
48 hwmon_temp_lcrit_hyst,
56 hwmon_temp_emergency_hyst,
58 hwmon_temp_lcrit_alarm,
61 hwmon_temp_crit_alarm,
62 hwmon_temp_emergency_alarm,
68 hwmon_temp_reset_history,
71 #define HWMON_T_INPUT BIT(hwmon_temp_input)
72 #define HWMON_T_TYPE BIT(hwmon_temp_type)
73 #define HWMON_T_LCRIT BIT(hwmon_temp_lcrit)
74 #define HWMON_T_LCRIT_HYST BIT(hwmon_temp_lcrit_hyst)
75 #define HWMON_T_MIN BIT(hwmon_temp_min)
76 #define HWMON_T_MIN_HYST BIT(hwmon_temp_min_hyst)
77 #define HWMON_T_MAX BIT(hwmon_temp_max)
78 #define HWMON_T_MAX_HYST BIT(hwmon_temp_max_hyst)
79 #define HWMON_T_CRIT BIT(hwmon_temp_crit)
80 #define HWMON_T_CRIT_HYST BIT(hwmon_temp_crit_hyst)
81 #define HWMON_T_EMERGENCY BIT(hwmon_temp_emergency)
82 #define HWMON_T_EMERGENCY_HYST BIT(hwmon_temp_emergency_hyst)
83 #define HWMON_T_MIN_ALARM BIT(hwmon_temp_min_alarm)
84 #define HWMON_T_MAX_ALARM BIT(hwmon_temp_max_alarm)
85 #define HWMON_T_CRIT_ALARM BIT(hwmon_temp_crit_alarm)
86 #define HWMON_T_EMERGENCY_ALARM BIT(hwmon_temp_emergency_alarm)
87 #define HWMON_T_FAULT BIT(hwmon_temp_fault)
88 #define HWMON_T_OFFSET BIT(hwmon_temp_offset)
89 #define HWMON_T_LABEL BIT(hwmon_temp_label)
90 #define HWMON_T_LOWEST BIT(hwmon_temp_lowest)
91 #define HWMON_T_HIGHEST BIT(hwmon_temp_highest)
92 #define HWMON_T_RESET_HISTORY BIT(hwmon_temp_reset_history)
95 * struct hwmon_ops - hwmon device operations
96 * @is_visible: Callback to return attribute visibility. Mandatory.
98 * @const void *drvdata:
99 * Pointer to driver-private data structure passed
100 * as argument to hwmon_device_register_with_info().
102 * @attr: Sensor attribute
105 * The function returns the file permissions.
106 * If the return value is 0, no attribute will be created.
107 * @read: Read callback. Optional. If not provided, attributes
108 * will not be readable.
110 * @dev: Pointer to hardware monitoring device
112 * @attr: Sensor attribute
115 * @val: Pointer to returned value
116 * The function returns 0 on success or a negative error number.
117 * @write: Write callback. Optional. If not provided, attributes
118 * will not be writable.
120 * @dev: Pointer to hardware monitoring device
122 * @attr: Sensor attribute
125 * @val: Value to write
126 * The function returns 0 on success or a negative error number.
129 umode_t (*is_visible)(const void *drvdata, enum hwmon_sensor_types type,
130 u32 attr, int channel);
131 int (*read)(struct device *dev, enum hwmon_sensor_types type,
132 u32 attr, int channel, long *val);
133 int (*write)(struct device *dev, enum hwmon_sensor_types type,
134 u32 attr, int channel, long val);
138 * Channel information
139 * @type: Channel type.
140 * @config: Pointer to NULL-terminated list of channel parameters.
141 * Use for per-channel attributes.
143 struct hwmon_channel_info {
144 enum hwmon_sensor_types type;
150 * @ops: Pointer to hwmon operations.
151 * @info: Null-terminated list of channel information.
153 struct hwmon_chip_info {
154 const struct hwmon_ops *ops;
155 const struct hwmon_channel_info **info;
158 struct device *hwmon_device_register(struct device *dev);
160 hwmon_device_register_with_groups(struct device *dev, const char *name,
162 const struct attribute_group **groups);
164 devm_hwmon_device_register_with_groups(struct device *dev, const char *name,
166 const struct attribute_group **groups);
168 hwmon_device_register_with_info(struct device *dev,
169 const char *name, void *drvdata,
170 const struct hwmon_chip_info *info,
171 const struct attribute_group **groups);
173 devm_hwmon_device_register_with_info(struct device *dev,
174 const char *name, void *drvdata,
175 const struct hwmon_chip_info *info,
176 const struct attribute_group **groups);
178 void hwmon_device_unregister(struct device *dev);
179 void devm_hwmon_device_unregister(struct device *dev);