summaryrefslogtreecommitdiffstats
path: root/include/linux/hwmon.h
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2015-08-26 22:38:11 -0400
committerGuenter Roeck <linux@roeck-us.net>2016-09-09 00:34:15 -0400
commitd560168b5d0fb4a70c74b386564072a819d9bf71 (patch)
treea6547dcb07cfaa2ec52d6b52136d9ac9a66cecbc /include/linux/hwmon.h
parentc9ebbe6f23f43f4520d9e3c4fe1384963848088e (diff)
hwmon: (core) New hwmon registration API
Up to now, each hwmon driver has to implement its own sysfs attributes. This requires a lot of template code, and distracts from the driver's core function to read and write chip registers. To be able to reduce driver complexity, move sensor attribute handling and thermal zone registration into hwmon core. By using the new API, driver code and data size is typically reduced by 20-70%, depending on driver complexity and the number of sysfs attributes supported. With this patch, the new API only supports thermal sensors. Support for other sensor types will be added with subsequent patches. Acked-by: Punit Agrawal <punit.agrawal@arm.com> Reviewed-by: Jonathan Cameron <jic23@kernel.org> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'include/linux/hwmon.h')
-rw-r--r--include/linux/hwmon.h148
1 files changed, 148 insertions, 0 deletions
diff --git a/include/linux/hwmon.h b/include/linux/hwmon.h
index 09354f6c1d63..52e56d71d742 100644
--- a/include/linux/hwmon.h
+++ b/include/linux/hwmon.h
@@ -14,9 +14,147 @@
14#ifndef _HWMON_H_ 14#ifndef _HWMON_H_
15#define _HWMON_H_ 15#define _HWMON_H_
16 16
17#include <linux/bitops.h>
18
17struct device; 19struct device;
18struct attribute_group; 20struct attribute_group;
19 21
22enum 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
20struct device *hwmon_device_register(struct device *dev); 158struct device *hwmon_device_register(struct device *dev);
21struct device * 159struct device *
22hwmon_device_register_with_groups(struct device *dev, const char *name, 160hwmon_device_register_with_groups(struct device *dev, const char *name,
@@ -26,6 +164,16 @@ struct device *
26devm_hwmon_device_register_with_groups(struct device *dev, const char *name, 164devm_hwmon_device_register_with_groups(struct device *dev, const char *name,
27 void *drvdata, 165 void *drvdata,
28 const struct attribute_group **groups); 166 const struct attribute_group **groups);
167struct 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);
29 177
30void hwmon_device_unregister(struct device *dev); 178void hwmon_device_unregister(struct device *dev);
31void devm_hwmon_device_unregister(struct device *dev); 179void devm_hwmon_device_unregister(struct device *dev);