blob: 52e56d71d742262df500487eb26dc317fc0b4bcc [file] [log] [blame]
Mark M. Hoffman12364412005-07-15 21:38:08 -04001/*
2 hwmon.h - part of lm_sensors, Linux kernel modules for hardware monitoring
3
4 This file declares helper functions for the sysfs class "hwmon",
5 for use by sensors drivers.
6
7 Copyright (C) 2005 Mark M. Hoffman <mhoffman@lightlink.com>
8
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.
12*/
13
14#ifndef _HWMON_H_
15#define _HWMON_H_
16
Guenter Roeckd5601682015-08-26 19:38:11 -070017#include <linux/bitops.h>
18
Paul Gortmaker313162d2012-01-30 11:46:54 -050019struct device;
Guenter Roeckbab22432013-07-06 13:57:23 -070020struct attribute_group;
Mark M. Hoffman12364412005-07-15 21:38:08 -040021
Guenter Roeckd5601682015-08-26 19:38:11 -070022enum hwmon_sensor_types {
23 hwmon_chip,
24 hwmon_temp,
25 hwmon_in,
26 hwmon_curr,
27 hwmon_power,
28 hwmon_energy,
29};
30
31enum hwmon_chip_attributes {
32 hwmon_chip_temp_reset_history,
33 hwmon_chip_register_tz,
34 hwmon_chip_update_interval,
35 hwmon_chip_alarms,
36};
37
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)
43
44enum hwmon_temp_attributes {
45 hwmon_temp_input = 0,
46 hwmon_temp_type,
47 hwmon_temp_lcrit,
48 hwmon_temp_lcrit_hyst,
49 hwmon_temp_min,
50 hwmon_temp_min_hyst,
51 hwmon_temp_max,
52 hwmon_temp_max_hyst,
53 hwmon_temp_crit,
54 hwmon_temp_crit_hyst,
55 hwmon_temp_emergency,
56 hwmon_temp_emergency_hyst,
57 hwmon_temp_alarm,
58 hwmon_temp_lcrit_alarm,
59 hwmon_temp_min_alarm,
60 hwmon_temp_max_alarm,
61 hwmon_temp_crit_alarm,
62 hwmon_temp_emergency_alarm,
63 hwmon_temp_fault,
64 hwmon_temp_offset,
65 hwmon_temp_label,
66 hwmon_temp_lowest,
67 hwmon_temp_highest,
68 hwmon_temp_reset_history,
69};
70
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)
93
94/**
95 * struct hwmon_ops - hwmon device operations
96 * @is_visible: Callback to return attribute visibility. Mandatory.
97 * Parameters are:
98 * @const void *drvdata:
99 * Pointer to driver-private data structure passed
100 * as argument to hwmon_device_register_with_info().
101 * @type: Sensor type
102 * @attr: Sensor attribute
103 * @channel:
104 * Channel number
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.
109 * Parameters are:
110 * @dev: Pointer to hardware monitoring device
111 * @type: Sensor type
112 * @attr: Sensor attribute
113 * @channel:
114 * Channel number
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.
119 * Parameters are:
120 * @dev: Pointer to hardware monitoring device
121 * @type: Sensor type
122 * @attr: Sensor attribute
123 * @channel:
124 * Channel number
125 * @val: Value to write
126 * The function returns 0 on success or a negative error number.
127 */
128struct hwmon_ops {
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);
135};
136
137/**
138 * Channel information
139 * @type: Channel type.
140 * @config: Pointer to NULL-terminated list of channel parameters.
141 * Use for per-channel attributes.
142 */
143struct hwmon_channel_info {
144 enum hwmon_sensor_types type;
145 const u32 *config;
146};
147
148/**
149 * Chip configuration
150 * @ops: Pointer to hwmon operations.
151 * @info: Null-terminated list of channel information.
152 */
153struct hwmon_chip_info {
154 const struct hwmon_ops *ops;
155 const struct hwmon_channel_info **info;
156};
157
Tony Jones1beeffe2007-08-20 13:46:20 -0700158struct device *hwmon_device_register(struct device *dev);
Guenter Roeckbab22432013-07-06 13:57:23 -0700159struct device *
160hwmon_device_register_with_groups(struct device *dev, const char *name,
161 void *drvdata,
162 const struct attribute_group **groups);
Guenter Roeck74188cb2013-07-11 20:00:12 -0700163struct device *
164devm_hwmon_device_register_with_groups(struct device *dev, const char *name,
165 void *drvdata,
166 const struct attribute_group **groups);
Guenter Roeckd5601682015-08-26 19:38:11 -0700167struct device *
168hwmon_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);
172struct device *
173devm_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);
Mark M. Hoffman12364412005-07-15 21:38:08 -0400177
Tony Jones1beeffe2007-08-20 13:46:20 -0700178void hwmon_device_unregister(struct device *dev);
Guenter Roeck74188cb2013-07-11 20:00:12 -0700179void devm_hwmon_device_unregister(struct device *dev);
Mark M. Hoffman12364412005-07-15 21:38:08 -0400180
Mark M. Hoffman12364412005-07-15 21:38:08 -0400181#endif