hwmon.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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. hwmon_fan,
  24. hwmon_pwm,
  25. };
  26. enum hwmon_chip_attributes {
  27. hwmon_chip_temp_reset_history,
  28. hwmon_chip_in_reset_history,
  29. hwmon_chip_curr_reset_history,
  30. hwmon_chip_power_reset_history,
  31. hwmon_chip_register_tz,
  32. hwmon_chip_update_interval,
  33. hwmon_chip_alarms,
  34. };
  35. #define HWMON_C_TEMP_RESET_HISTORY BIT(hwmon_chip_temp_reset_history)
  36. #define HWMON_C_IN_RESET_HISTORY BIT(hwmon_chip_in_reset_history)
  37. #define HWMON_C_CURR_RESET_HISTORY BIT(hwmon_chip_curr_reset_history)
  38. #define HWMON_C_POWER_RESET_HISTORY BIT(hwmon_chip_power_reset_history)
  39. #define HWMON_C_REGISTER_TZ BIT(hwmon_chip_register_tz)
  40. #define HWMON_C_UPDATE_INTERVAL BIT(hwmon_chip_update_interval)
  41. #define HWMON_C_ALARMS BIT(hwmon_chip_alarms)
  42. enum hwmon_temp_attributes {
  43. hwmon_temp_input = 0,
  44. hwmon_temp_type,
  45. hwmon_temp_lcrit,
  46. hwmon_temp_lcrit_hyst,
  47. hwmon_temp_min,
  48. hwmon_temp_min_hyst,
  49. hwmon_temp_max,
  50. hwmon_temp_max_hyst,
  51. hwmon_temp_crit,
  52. hwmon_temp_crit_hyst,
  53. hwmon_temp_emergency,
  54. hwmon_temp_emergency_hyst,
  55. hwmon_temp_alarm,
  56. hwmon_temp_lcrit_alarm,
  57. hwmon_temp_min_alarm,
  58. hwmon_temp_max_alarm,
  59. hwmon_temp_crit_alarm,
  60. hwmon_temp_emergency_alarm,
  61. hwmon_temp_fault,
  62. hwmon_temp_offset,
  63. hwmon_temp_label,
  64. hwmon_temp_lowest,
  65. hwmon_temp_highest,
  66. hwmon_temp_reset_history,
  67. };
  68. #define HWMON_T_INPUT BIT(hwmon_temp_input)
  69. #define HWMON_T_TYPE BIT(hwmon_temp_type)
  70. #define HWMON_T_LCRIT BIT(hwmon_temp_lcrit)
  71. #define HWMON_T_LCRIT_HYST BIT(hwmon_temp_lcrit_hyst)
  72. #define HWMON_T_MIN BIT(hwmon_temp_min)
  73. #define HWMON_T_MIN_HYST BIT(hwmon_temp_min_hyst)
  74. #define HWMON_T_MAX BIT(hwmon_temp_max)
  75. #define HWMON_T_MAX_HYST BIT(hwmon_temp_max_hyst)
  76. #define HWMON_T_CRIT BIT(hwmon_temp_crit)
  77. #define HWMON_T_CRIT_HYST BIT(hwmon_temp_crit_hyst)
  78. #define HWMON_T_EMERGENCY BIT(hwmon_temp_emergency)
  79. #define HWMON_T_EMERGENCY_HYST BIT(hwmon_temp_emergency_hyst)
  80. #define HWMON_T_MIN_ALARM BIT(hwmon_temp_min_alarm)
  81. #define HWMON_T_MAX_ALARM BIT(hwmon_temp_max_alarm)
  82. #define HWMON_T_CRIT_ALARM BIT(hwmon_temp_crit_alarm)
  83. #define HWMON_T_EMERGENCY_ALARM BIT(hwmon_temp_emergency_alarm)
  84. #define HWMON_T_FAULT BIT(hwmon_temp_fault)
  85. #define HWMON_T_OFFSET BIT(hwmon_temp_offset)
  86. #define HWMON_T_LABEL BIT(hwmon_temp_label)
  87. #define HWMON_T_LOWEST BIT(hwmon_temp_lowest)
  88. #define HWMON_T_HIGHEST BIT(hwmon_temp_highest)
  89. #define HWMON_T_RESET_HISTORY BIT(hwmon_temp_reset_history)
  90. enum hwmon_in_attributes {
  91. hwmon_in_input,
  92. hwmon_in_min,
  93. hwmon_in_max,
  94. hwmon_in_lcrit,
  95. hwmon_in_crit,
  96. hwmon_in_average,
  97. hwmon_in_lowest,
  98. hwmon_in_highest,
  99. hwmon_in_reset_history,
  100. hwmon_in_label,
  101. hwmon_in_alarm,
  102. hwmon_in_min_alarm,
  103. hwmon_in_max_alarm,
  104. hwmon_in_lcrit_alarm,
  105. hwmon_in_crit_alarm,
  106. };
  107. #define HWMON_I_INPUT BIT(hwmon_in_input)
  108. #define HWMON_I_MIN BIT(hwmon_in_min)
  109. #define HWMON_I_MAX BIT(hwmon_in_max)
  110. #define HWMON_I_LCRIT BIT(hwmon_in_lcrit)
  111. #define HWMON_I_CRIT BIT(hwmon_in_crit)
  112. #define HWMON_I_AVERAGE BIT(hwmon_in_average)
  113. #define HWMON_I_LOWEST BIT(hwmon_in_lowest)
  114. #define HWMON_I_HIGHEST BIT(hwmon_in_highest)
  115. #define HWMON_I_RESET_HISTORY BIT(hwmon_in_reset_history)
  116. #define HWMON_I_LABEL BIT(hwmon_in_label)
  117. #define HWMON_I_ALARM BIT(hwmon_in_alarm)
  118. #define HWMON_I_MIN_ALARM BIT(hwmon_in_min_alarm)
  119. #define HWMON_I_MAX_ALARM BIT(hwmon_in_max_alarm)
  120. #define HWMON_I_LCRIT_ALARM BIT(hwmon_in_lcrit_alarm)
  121. #define HWMON_I_CRIT_ALARM BIT(hwmon_in_crit_alarm)
  122. enum hwmon_curr_attributes {
  123. hwmon_curr_input,
  124. hwmon_curr_min,
  125. hwmon_curr_max,
  126. hwmon_curr_lcrit,
  127. hwmon_curr_crit,
  128. hwmon_curr_average,
  129. hwmon_curr_lowest,
  130. hwmon_curr_highest,
  131. hwmon_curr_reset_history,
  132. hwmon_curr_label,
  133. hwmon_curr_alarm,
  134. hwmon_curr_min_alarm,
  135. hwmon_curr_max_alarm,
  136. hwmon_curr_lcrit_alarm,
  137. hwmon_curr_crit_alarm,
  138. };
  139. #define HWMON_C_INPUT BIT(hwmon_curr_input)
  140. #define HWMON_C_MIN BIT(hwmon_curr_min)
  141. #define HWMON_C_MAX BIT(hwmon_curr_max)
  142. #define HWMON_C_LCRIT BIT(hwmon_curr_lcrit)
  143. #define HWMON_C_CRIT BIT(hwmon_curr_crit)
  144. #define HWMON_C_AVERAGE BIT(hwmon_curr_average)
  145. #define HWMON_C_LOWEST BIT(hwmon_curr_lowest)
  146. #define HWMON_C_HIGHEST BIT(hwmon_curr_highest)
  147. #define HWMON_C_RESET_HISTORY BIT(hwmon_curr_reset_history)
  148. #define HWMON_C_LABEL BIT(hwmon_curr_label)
  149. #define HWMON_C_ALARM BIT(hwmon_curr_alarm)
  150. #define HWMON_C_MIN_ALARM BIT(hwmon_curr_min_alarm)
  151. #define HWMON_C_MAX_ALARM BIT(hwmon_curr_max_alarm)
  152. #define HWMON_C_LCRIT_ALARM BIT(hwmon_curr_lcrit_alarm)
  153. #define HWMON_C_CRIT_ALARM BIT(hwmon_curr_crit_alarm)
  154. enum hwmon_power_attributes {
  155. hwmon_power_average,
  156. hwmon_power_average_interval,
  157. hwmon_power_average_interval_max,
  158. hwmon_power_average_interval_min,
  159. hwmon_power_average_highest,
  160. hwmon_power_average_lowest,
  161. hwmon_power_average_max,
  162. hwmon_power_average_min,
  163. hwmon_power_input,
  164. hwmon_power_input_highest,
  165. hwmon_power_input_lowest,
  166. hwmon_power_reset_history,
  167. hwmon_power_accuracy,
  168. hwmon_power_cap,
  169. hwmon_power_cap_hyst,
  170. hwmon_power_cap_max,
  171. hwmon_power_cap_min,
  172. hwmon_power_max,
  173. hwmon_power_crit,
  174. hwmon_power_label,
  175. hwmon_power_alarm,
  176. hwmon_power_cap_alarm,
  177. hwmon_power_max_alarm,
  178. hwmon_power_crit_alarm,
  179. };
  180. #define HWMON_P_AVERAGE BIT(hwmon_power_average)
  181. #define HWMON_P_AVERAGE_INTERVAL BIT(hwmon_power_average_interval)
  182. #define HWMON_P_AVERAGE_INTERVAL_MAX BIT(hwmon_power_average_interval_max)
  183. #define HWMON_P_AVERAGE_INTERVAL_MIN BIT(hwmon_power_average_interval_min)
  184. #define HWMON_P_AVERAGE_HIGHEST BIT(hwmon_power_average_highest)
  185. #define HWMON_P_AVERAGE_LOWEST BIT(hwmon_power_average_lowest)
  186. #define HWMON_P_AVERAGE_MAX BIT(hwmon_power_average_max)
  187. #define HWMON_P_AVERAGE_MIN BIT(hwmon_power_average_min)
  188. #define HWMON_P_INPUT BIT(hwmon_power_input)
  189. #define HWMON_P_INPUT_HIGHEST BIT(hwmon_power_input_highest)
  190. #define HWMON_P_INPUT_LOWEST BIT(hwmon_power_input_lowest)
  191. #define HWMON_P_RESET_HISTORY BIT(hwmon_power_reset_history)
  192. #define HWMON_P_ACCURACY BIT(hwmon_power_accuracy)
  193. #define HWMON_P_CAP BIT(hwmon_power_cap)
  194. #define HWMON_P_CAP_HYST BIT(hwmon_power_cap_hyst)
  195. #define HWMON_P_CAP_MAX BIT(hwmon_power_cap_max)
  196. #define HWMON_P_CAP_MIN BIT(hwmon_power_cap_min)
  197. #define HWMON_P_MAX BIT(hwmon_power_max)
  198. #define HWMON_P_CRIT BIT(hwmon_power_crit)
  199. #define HWMON_P_LABEL BIT(hwmon_power_label)
  200. #define HWMON_P_ALARM BIT(hwmon_power_alarm)
  201. #define HWMON_P_CAP_ALARM BIT(hwmon_power_cap_alarm)
  202. #define HWMON_P_MAX_ALARM BIT(hwmon_power_max_alarm)
  203. #define HWMON_P_CRIT_ALARM BIT(hwmon_power_crit_alarm)
  204. enum hwmon_energy_attributes {
  205. hwmon_energy_input,
  206. hwmon_energy_label,
  207. };
  208. #define HWMON_E_INPUT BIT(hwmon_energy_input)
  209. #define HWMON_E_LABEL BIT(hwmon_energy_label)
  210. enum hwmon_humidity_attributes {
  211. hwmon_humidity_input,
  212. hwmon_humidity_label,
  213. hwmon_humidity_min,
  214. hwmon_humidity_min_hyst,
  215. hwmon_humidity_max,
  216. hwmon_humidity_max_hyst,
  217. hwmon_humidity_alarm,
  218. hwmon_humidity_fault,
  219. };
  220. #define HWMON_H_INPUT BIT(hwmon_humidity_input)
  221. #define HWMON_H_LABEL BIT(hwmon_humidity_label)
  222. #define HWMON_H_MIN BIT(hwmon_humidity_min)
  223. #define HWMON_H_MIN_HYST BIT(hwmon_humidity_min_hyst)
  224. #define HWMON_H_MAX BIT(hwmon_humidity_max)
  225. #define HWMON_H_MAX_HYST BIT(hwmon_humidity_max_hyst)
  226. #define HWMON_H_ALARM BIT(hwmon_humidity_alarm)
  227. #define HWMON_H_FAULT BIT(hwmon_humidity_fault)
  228. enum hwmon_fan_attributes {
  229. hwmon_fan_input,
  230. hwmon_fan_label,
  231. hwmon_fan_min,
  232. hwmon_fan_max,
  233. hwmon_fan_div,
  234. hwmon_fan_pulses,
  235. hwmon_fan_target,
  236. hwmon_fan_alarm,
  237. hwmon_fan_min_alarm,
  238. hwmon_fan_max_alarm,
  239. hwmon_fan_fault,
  240. };
  241. #define HWMON_F_INPUT BIT(hwmon_fan_input)
  242. #define HWMON_F_LABEL BIT(hwmon_fan_label)
  243. #define HWMON_F_MIN BIT(hwmon_fan_min)
  244. #define HWMON_F_MAX BIT(hwmon_fan_max)
  245. #define HWMON_F_DIV BIT(hwmon_fan_div)
  246. #define HWMON_F_PULSES BIT(hwmon_fan_pulses)
  247. #define HWMON_F_TARGET BIT(hwmon_fan_target)
  248. #define HWMON_F_ALARM BIT(hwmon_fan_alarm)
  249. #define HWMON_F_MIN_ALARM BIT(hwmon_fan_min_alarm)
  250. #define HWMON_F_MAX_ALARM BIT(hwmon_fan_max_alarm)
  251. #define HWMON_F_FAULT BIT(hwmon_fan_fault)
  252. enum hwmon_pwm_attributes {
  253. hwmon_pwm_input,
  254. hwmon_pwm_enable,
  255. hwmon_pwm_mode,
  256. hwmon_pwm_freq,
  257. };
  258. #define HWMON_PWM_INPUT BIT(hwmon_pwm_input)
  259. #define HWMON_PWM_ENABLE BIT(hwmon_pwm_enable)
  260. #define HWMON_PWM_MODE BIT(hwmon_pwm_mode)
  261. #define HWMON_PWM_FREQ BIT(hwmon_pwm_freq)
  262. /**
  263. * struct hwmon_ops - hwmon device operations
  264. * @is_visible: Callback to return attribute visibility. Mandatory.
  265. * Parameters are:
  266. * @const void *drvdata:
  267. * Pointer to driver-private data structure passed
  268. * as argument to hwmon_device_register_with_info().
  269. * @type: Sensor type
  270. * @attr: Sensor attribute
  271. * @channel:
  272. * Channel number
  273. * The function returns the file permissions.
  274. * If the return value is 0, no attribute will be created.
  275. * @read: Read callback. Optional. If not provided, attributes
  276. * will not be readable.
  277. * Parameters are:
  278. * @dev: Pointer to hardware monitoring device
  279. * @type: Sensor type
  280. * @attr: Sensor attribute
  281. * @channel:
  282. * Channel number
  283. * @val: Pointer to returned value
  284. * The function returns 0 on success or a negative error number.
  285. * @write: Write callback. Optional. If not provided, attributes
  286. * will not be writable.
  287. * Parameters are:
  288. * @dev: Pointer to hardware monitoring device
  289. * @type: Sensor type
  290. * @attr: Sensor attribute
  291. * @channel:
  292. * Channel number
  293. * @val: Value to write
  294. * The function returns 0 on success or a negative error number.
  295. */
  296. struct hwmon_ops {
  297. umode_t (*is_visible)(const void *drvdata, enum hwmon_sensor_types type,
  298. u32 attr, int channel);
  299. int (*read)(struct device *dev, enum hwmon_sensor_types type,
  300. u32 attr, int channel, long *val);
  301. int (*write)(struct device *dev, enum hwmon_sensor_types type,
  302. u32 attr, int channel, long val);
  303. };
  304. /**
  305. * Channel information
  306. * @type: Channel type.
  307. * @config: Pointer to NULL-terminated list of channel parameters.
  308. * Use for per-channel attributes.
  309. */
  310. struct hwmon_channel_info {
  311. enum hwmon_sensor_types type;
  312. const u32 *config;
  313. };
  314. /**
  315. * Chip configuration
  316. * @ops: Pointer to hwmon operations.
  317. * @info: Null-terminated list of channel information.
  318. */
  319. struct hwmon_chip_info {
  320. const struct hwmon_ops *ops;
  321. const struct hwmon_channel_info **info;
  322. };
  323. struct device *hwmon_device_register(struct device *dev);
  324. struct device *
  325. hwmon_device_register_with_groups(struct device *dev, const char *name,
  326. void *drvdata,
  327. const struct attribute_group **groups);
  328. struct device *
  329. devm_hwmon_device_register_with_groups(struct device *dev, const char *name,
  330. void *drvdata,
  331. const struct attribute_group **groups);
  332. struct device *
  333. hwmon_device_register_with_info(struct device *dev,
  334. const char *name, void *drvdata,
  335. const struct hwmon_chip_info *info,
  336. const struct attribute_group **groups);
  337. struct device *
  338. devm_hwmon_device_register_with_info(struct device *dev,
  339. const char *name, void *drvdata,
  340. const struct hwmon_chip_info *info,
  341. const struct attribute_group **groups);
  342. void hwmon_device_unregister(struct device *dev);
  343. void devm_hwmon_device_unregister(struct device *dev);
  344. #endif