hwmon.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /*
  2. hwmon.h - part of lm_sensors, Linux kernel modules for hardware monitoring
  3. This file declares helper functions for the sysfs class "hwmon",
  4. for use by sensors drivers.
  5. Copyright (C) 2005 Mark M. Hoffman <mhoffman@lightlink.com>
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; version 2 of the License.
  9. */
  10. #ifndef _HWMON_H_
  11. #define _HWMON_H_
  12. #include <linux/bitops.h>
  13. struct device;
  14. struct attribute_group;
  15. enum hwmon_sensor_types {
  16. hwmon_chip,
  17. hwmon_temp,
  18. hwmon_in,
  19. hwmon_curr,
  20. hwmon_power,
  21. hwmon_energy,
  22. hwmon_humidity,
  23. };
  24. enum hwmon_chip_attributes {
  25. hwmon_chip_temp_reset_history,
  26. hwmon_chip_in_reset_history,
  27. hwmon_chip_curr_reset_history,
  28. hwmon_chip_power_reset_history,
  29. hwmon_chip_register_tz,
  30. hwmon_chip_update_interval,
  31. hwmon_chip_alarms,
  32. };
  33. #define HWMON_C_TEMP_RESET_HISTORY BIT(hwmon_chip_temp_reset_history)
  34. #define HWMON_C_IN_RESET_HISTORY BIT(hwmon_chip_in_reset_history)
  35. #define HWMON_C_CURR_RESET_HISTORY BIT(hwmon_chip_curr_reset_history)
  36. #define HWMON_C_POWER_RESET_HISTORY BIT(hwmon_chip_power_reset_history)
  37. #define HWMON_C_REGISTER_TZ BIT(hwmon_chip_register_tz)
  38. #define HWMON_C_UPDATE_INTERVAL BIT(hwmon_chip_update_interval)
  39. #define HWMON_C_ALARMS BIT(hwmon_chip_alarms)
  40. enum hwmon_temp_attributes {
  41. hwmon_temp_input = 0,
  42. hwmon_temp_type,
  43. hwmon_temp_lcrit,
  44. hwmon_temp_lcrit_hyst,
  45. hwmon_temp_min,
  46. hwmon_temp_min_hyst,
  47. hwmon_temp_max,
  48. hwmon_temp_max_hyst,
  49. hwmon_temp_crit,
  50. hwmon_temp_crit_hyst,
  51. hwmon_temp_emergency,
  52. hwmon_temp_emergency_hyst,
  53. hwmon_temp_alarm,
  54. hwmon_temp_lcrit_alarm,
  55. hwmon_temp_min_alarm,
  56. hwmon_temp_max_alarm,
  57. hwmon_temp_crit_alarm,
  58. hwmon_temp_emergency_alarm,
  59. hwmon_temp_fault,
  60. hwmon_temp_offset,
  61. hwmon_temp_label,
  62. hwmon_temp_lowest,
  63. hwmon_temp_highest,
  64. hwmon_temp_reset_history,
  65. };
  66. #define HWMON_T_INPUT BIT(hwmon_temp_input)
  67. #define HWMON_T_TYPE BIT(hwmon_temp_type)
  68. #define HWMON_T_LCRIT BIT(hwmon_temp_lcrit)
  69. #define HWMON_T_LCRIT_HYST BIT(hwmon_temp_lcrit_hyst)
  70. #define HWMON_T_MIN BIT(hwmon_temp_min)
  71. #define HWMON_T_MIN_HYST BIT(hwmon_temp_min_hyst)
  72. #define HWMON_T_MAX BIT(hwmon_temp_max)
  73. #define HWMON_T_MAX_HYST BIT(hwmon_temp_max_hyst)
  74. #define HWMON_T_CRIT BIT(hwmon_temp_crit)
  75. #define HWMON_T_CRIT_HYST BIT(hwmon_temp_crit_hyst)
  76. #define HWMON_T_EMERGENCY BIT(hwmon_temp_emergency)
  77. #define HWMON_T_EMERGENCY_HYST BIT(hwmon_temp_emergency_hyst)
  78. #define HWMON_T_MIN_ALARM BIT(hwmon_temp_min_alarm)
  79. #define HWMON_T_MAX_ALARM BIT(hwmon_temp_max_alarm)
  80. #define HWMON_T_CRIT_ALARM BIT(hwmon_temp_crit_alarm)
  81. #define HWMON_T_EMERGENCY_ALARM BIT(hwmon_temp_emergency_alarm)
  82. #define HWMON_T_FAULT BIT(hwmon_temp_fault)
  83. #define HWMON_T_OFFSET BIT(hwmon_temp_offset)
  84. #define HWMON_T_LABEL BIT(hwmon_temp_label)
  85. #define HWMON_T_LOWEST BIT(hwmon_temp_lowest)
  86. #define HWMON_T_HIGHEST BIT(hwmon_temp_highest)
  87. #define HWMON_T_RESET_HISTORY BIT(hwmon_temp_reset_history)
  88. enum hwmon_in_attributes {
  89. hwmon_in_input,
  90. hwmon_in_min,
  91. hwmon_in_max,
  92. hwmon_in_lcrit,
  93. hwmon_in_crit,
  94. hwmon_in_average,
  95. hwmon_in_lowest,
  96. hwmon_in_highest,
  97. hwmon_in_reset_history,
  98. hwmon_in_label,
  99. hwmon_in_alarm,
  100. hwmon_in_min_alarm,
  101. hwmon_in_max_alarm,
  102. hwmon_in_lcrit_alarm,
  103. hwmon_in_crit_alarm,
  104. };
  105. #define HWMON_I_INPUT BIT(hwmon_in_input)
  106. #define HWMON_I_MIN BIT(hwmon_in_min)
  107. #define HWMON_I_MAX BIT(hwmon_in_max)
  108. #define HWMON_I_LCRIT BIT(hwmon_in_lcrit)
  109. #define HWMON_I_CRIT BIT(hwmon_in_crit)
  110. #define HWMON_I_AVERAGE BIT(hwmon_in_average)
  111. #define HWMON_I_LOWEST BIT(hwmon_in_lowest)
  112. #define HWMON_I_HIGHEST BIT(hwmon_in_highest)
  113. #define HWMON_I_RESET_HISTORY BIT(hwmon_in_reset_history)
  114. #define HWMON_I_LABEL BIT(hwmon_in_label)
  115. #define HWMON_I_ALARM BIT(hwmon_in_alarm)
  116. #define HWMON_I_MIN_ALARM BIT(hwmon_in_min_alarm)
  117. #define HWMON_I_MAX_ALARM BIT(hwmon_in_max_alarm)
  118. #define HWMON_I_LCRIT_ALARM BIT(hwmon_in_lcrit_alarm)
  119. #define HWMON_I_CRIT_ALARM BIT(hwmon_in_crit_alarm)
  120. enum hwmon_curr_attributes {
  121. hwmon_curr_input,
  122. hwmon_curr_min,
  123. hwmon_curr_max,
  124. hwmon_curr_lcrit,
  125. hwmon_curr_crit,
  126. hwmon_curr_average,
  127. hwmon_curr_lowest,
  128. hwmon_curr_highest,
  129. hwmon_curr_reset_history,
  130. hwmon_curr_label,
  131. hwmon_curr_alarm,
  132. hwmon_curr_min_alarm,
  133. hwmon_curr_max_alarm,
  134. hwmon_curr_lcrit_alarm,
  135. hwmon_curr_crit_alarm,
  136. };
  137. #define HWMON_C_INPUT BIT(hwmon_curr_input)
  138. #define HWMON_C_MIN BIT(hwmon_curr_min)
  139. #define HWMON_C_MAX BIT(hwmon_curr_max)
  140. #define HWMON_C_LCRIT BIT(hwmon_curr_lcrit)
  141. #define HWMON_C_CRIT BIT(hwmon_curr_crit)
  142. #define HWMON_C_AVERAGE BIT(hwmon_curr_average)
  143. #define HWMON_C_LOWEST BIT(hwmon_curr_lowest)
  144. #define HWMON_C_HIGHEST BIT(hwmon_curr_highest)
  145. #define HWMON_C_RESET_HISTORY BIT(hwmon_curr_reset_history)
  146. #define HWMON_C_LABEL BIT(hwmon_curr_label)
  147. #define HWMON_C_ALARM BIT(hwmon_curr_alarm)
  148. #define HWMON_C_MIN_ALARM BIT(hwmon_curr_min_alarm)
  149. #define HWMON_C_MAX_ALARM BIT(hwmon_curr_max_alarm)
  150. #define HWMON_C_LCRIT_ALARM BIT(hwmon_curr_lcrit_alarm)
  151. #define HWMON_C_CRIT_ALARM BIT(hwmon_curr_crit_alarm)
  152. enum hwmon_power_attributes {
  153. hwmon_power_average,
  154. hwmon_power_average_interval,
  155. hwmon_power_average_interval_max,
  156. hwmon_power_average_interval_min,
  157. hwmon_power_average_highest,
  158. hwmon_power_average_lowest,
  159. hwmon_power_average_max,
  160. hwmon_power_average_min,
  161. hwmon_power_input,
  162. hwmon_power_input_highest,
  163. hwmon_power_input_lowest,
  164. hwmon_power_reset_history,
  165. hwmon_power_accuracy,
  166. hwmon_power_cap,
  167. hwmon_power_cap_hyst,
  168. hwmon_power_cap_max,
  169. hwmon_power_cap_min,
  170. hwmon_power_max,
  171. hwmon_power_crit,
  172. hwmon_power_label,
  173. hwmon_power_alarm,
  174. hwmon_power_cap_alarm,
  175. hwmon_power_max_alarm,
  176. hwmon_power_crit_alarm,
  177. };
  178. #define HWMON_P_AVERAGE BIT(hwmon_power_average)
  179. #define HWMON_P_AVERAGE_INTERVAL BIT(hwmon_power_average_interval)
  180. #define HWMON_P_AVERAGE_INTERVAL_MAX BIT(hwmon_power_average_interval_max)
  181. #define HWMON_P_AVERAGE_INTERVAL_MIN BIT(hwmon_power_average_interval_min)
  182. #define HWMON_P_AVERAGE_HIGHEST BIT(hwmon_power_average_highest)
  183. #define HWMON_P_AVERAGE_LOWEST BIT(hwmon_power_average_lowest)
  184. #define HWMON_P_AVERAGE_MAX BIT(hwmon_power_average_max)
  185. #define HWMON_P_AVERAGE_MIN BIT(hwmon_power_average_min)
  186. #define HWMON_P_INPUT BIT(hwmon_power_input)
  187. #define HWMON_P_INPUT_HIGHEST BIT(hwmon_power_input_highest)
  188. #define HWMON_P_INPUT_LOWEST BIT(hwmon_power_input_lowest)
  189. #define HWMON_P_RESET_HISTORY BIT(hwmon_power_reset_history)
  190. #define HWMON_P_ACCURACY BIT(hwmon_power_accuracy)
  191. #define HWMON_P_CAP BIT(hwmon_power_cap)
  192. #define HWMON_P_CAP_HYST BIT(hwmon_power_cap_hyst)
  193. #define HWMON_P_CAP_MAX BIT(hwmon_power_cap_max)
  194. #define HWMON_P_CAP_MIN BIT(hwmon_power_cap_min)
  195. #define HWMON_P_MAX BIT(hwmon_power_max)
  196. #define HWMON_P_CRIT BIT(hwmon_power_crit)
  197. #define HWMON_P_LABEL BIT(hwmon_power_label)
  198. #define HWMON_P_ALARM BIT(hwmon_power_alarm)
  199. #define HWMON_P_CAP_ALARM BIT(hwmon_power_cap_alarm)
  200. #define HWMON_P_MAX_ALARM BIT(hwmon_power_max_alarm)
  201. #define HWMON_P_CRIT_ALARM BIT(hwmon_power_crit_alarm)
  202. enum hwmon_energy_attributes {
  203. hwmon_energy_input,
  204. hwmon_energy_label,
  205. };
  206. #define HWMON_E_INPUT BIT(hwmon_energy_input)
  207. #define HWMON_E_LABEL BIT(hwmon_energy_label)
  208. enum hwmon_humidity_attributes {
  209. hwmon_humidity_input,
  210. hwmon_humidity_label,
  211. hwmon_humidity_min,
  212. hwmon_humidity_min_hyst,
  213. hwmon_humidity_max,
  214. hwmon_humidity_max_hyst,
  215. hwmon_humidity_alarm,
  216. hwmon_humidity_fault,
  217. };
  218. #define HWMON_H_INPUT BIT(hwmon_humidity_input)
  219. #define HWMON_H_LABEL BIT(hwmon_humidity_label)
  220. #define HWMON_H_MIN BIT(hwmon_humidity_min)
  221. #define HWMON_H_MIN_HYST BIT(hwmon_humidity_min_hyst)
  222. #define HWMON_H_MAX BIT(hwmon_humidity_max)
  223. #define HWMON_H_MAX_HYST BIT(hwmon_humidity_max_hyst)
  224. #define HWMON_H_ALARM BIT(hwmon_humidity_alarm)
  225. #define HWMON_H_FAULT BIT(hwmon_humidity_fault)
  226. /**
  227. * struct hwmon_ops - hwmon device operations
  228. * @is_visible: Callback to return attribute visibility. Mandatory.
  229. * Parameters are:
  230. * @const void *drvdata:
  231. * Pointer to driver-private data structure passed
  232. * as argument to hwmon_device_register_with_info().
  233. * @type: Sensor type
  234. * @attr: Sensor attribute
  235. * @channel:
  236. * Channel number
  237. * The function returns the file permissions.
  238. * If the return value is 0, no attribute will be created.
  239. * @read: Read callback. Optional. If not provided, attributes
  240. * will not be readable.
  241. * Parameters are:
  242. * @dev: Pointer to hardware monitoring device
  243. * @type: Sensor type
  244. * @attr: Sensor attribute
  245. * @channel:
  246. * Channel number
  247. * @val: Pointer to returned value
  248. * The function returns 0 on success or a negative error number.
  249. * @write: Write callback. Optional. If not provided, attributes
  250. * will not be writable.
  251. * Parameters are:
  252. * @dev: Pointer to hardware monitoring device
  253. * @type: Sensor type
  254. * @attr: Sensor attribute
  255. * @channel:
  256. * Channel number
  257. * @val: Value to write
  258. * The function returns 0 on success or a negative error number.
  259. */
  260. struct hwmon_ops {
  261. umode_t (*is_visible)(const void *drvdata, enum hwmon_sensor_types type,
  262. u32 attr, int channel);
  263. int (*read)(struct device *dev, enum hwmon_sensor_types type,
  264. u32 attr, int channel, long *val);
  265. int (*write)(struct device *dev, enum hwmon_sensor_types type,
  266. u32 attr, int channel, long val);
  267. };
  268. /**
  269. * Channel information
  270. * @type: Channel type.
  271. * @config: Pointer to NULL-terminated list of channel parameters.
  272. * Use for per-channel attributes.
  273. */
  274. struct hwmon_channel_info {
  275. enum hwmon_sensor_types type;
  276. const u32 *config;
  277. };
  278. /**
  279. * Chip configuration
  280. * @ops: Pointer to hwmon operations.
  281. * @info: Null-terminated list of channel information.
  282. */
  283. struct hwmon_chip_info {
  284. const struct hwmon_ops *ops;
  285. const struct hwmon_channel_info **info;
  286. };
  287. struct device *hwmon_device_register(struct device *dev);
  288. struct device *
  289. hwmon_device_register_with_groups(struct device *dev, const char *name,
  290. void *drvdata,
  291. const struct attribute_group **groups);
  292. struct device *
  293. devm_hwmon_device_register_with_groups(struct device *dev, const char *name,
  294. void *drvdata,
  295. const struct attribute_group **groups);
  296. struct device *
  297. hwmon_device_register_with_info(struct device *dev,
  298. const char *name, void *drvdata,
  299. const struct hwmon_chip_info *info,
  300. const struct attribute_group **groups);
  301. struct device *
  302. devm_hwmon_device_register_with_info(struct device *dev,
  303. const char *name, void *drvdata,
  304. const struct hwmon_chip_info *info,
  305. const struct attribute_group **groups);
  306. void hwmon_device_unregister(struct device *dev);
  307. void devm_hwmon_device_unregister(struct device *dev);
  308. #endif