0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef _HWMON_H_
0013 #define _HWMON_H_
0014
0015 #include <linux/bitops.h>
0016
0017 struct device;
0018 struct attribute_group;
0019
0020 enum hwmon_sensor_types {
0021 hwmon_chip,
0022 hwmon_temp,
0023 hwmon_in,
0024 hwmon_curr,
0025 hwmon_power,
0026 hwmon_energy,
0027 hwmon_humidity,
0028 hwmon_fan,
0029 hwmon_pwm,
0030 hwmon_intrusion,
0031 hwmon_max,
0032 };
0033
0034 enum hwmon_chip_attributes {
0035 hwmon_chip_temp_reset_history,
0036 hwmon_chip_in_reset_history,
0037 hwmon_chip_curr_reset_history,
0038 hwmon_chip_power_reset_history,
0039 hwmon_chip_register_tz,
0040 hwmon_chip_update_interval,
0041 hwmon_chip_alarms,
0042 hwmon_chip_samples,
0043 hwmon_chip_curr_samples,
0044 hwmon_chip_in_samples,
0045 hwmon_chip_power_samples,
0046 hwmon_chip_temp_samples,
0047 };
0048
0049 #define HWMON_C_TEMP_RESET_HISTORY BIT(hwmon_chip_temp_reset_history)
0050 #define HWMON_C_IN_RESET_HISTORY BIT(hwmon_chip_in_reset_history)
0051 #define HWMON_C_CURR_RESET_HISTORY BIT(hwmon_chip_curr_reset_history)
0052 #define HWMON_C_POWER_RESET_HISTORY BIT(hwmon_chip_power_reset_history)
0053 #define HWMON_C_REGISTER_TZ BIT(hwmon_chip_register_tz)
0054 #define HWMON_C_UPDATE_INTERVAL BIT(hwmon_chip_update_interval)
0055 #define HWMON_C_ALARMS BIT(hwmon_chip_alarms)
0056 #define HWMON_C_SAMPLES BIT(hwmon_chip_samples)
0057 #define HWMON_C_CURR_SAMPLES BIT(hwmon_chip_curr_samples)
0058 #define HWMON_C_IN_SAMPLES BIT(hwmon_chip_in_samples)
0059 #define HWMON_C_POWER_SAMPLES BIT(hwmon_chip_power_samples)
0060 #define HWMON_C_TEMP_SAMPLES BIT(hwmon_chip_temp_samples)
0061
0062 enum hwmon_temp_attributes {
0063 hwmon_temp_enable,
0064 hwmon_temp_input,
0065 hwmon_temp_type,
0066 hwmon_temp_lcrit,
0067 hwmon_temp_lcrit_hyst,
0068 hwmon_temp_min,
0069 hwmon_temp_min_hyst,
0070 hwmon_temp_max,
0071 hwmon_temp_max_hyst,
0072 hwmon_temp_crit,
0073 hwmon_temp_crit_hyst,
0074 hwmon_temp_emergency,
0075 hwmon_temp_emergency_hyst,
0076 hwmon_temp_alarm,
0077 hwmon_temp_lcrit_alarm,
0078 hwmon_temp_min_alarm,
0079 hwmon_temp_max_alarm,
0080 hwmon_temp_crit_alarm,
0081 hwmon_temp_emergency_alarm,
0082 hwmon_temp_fault,
0083 hwmon_temp_offset,
0084 hwmon_temp_label,
0085 hwmon_temp_lowest,
0086 hwmon_temp_highest,
0087 hwmon_temp_reset_history,
0088 hwmon_temp_rated_min,
0089 hwmon_temp_rated_max,
0090 };
0091
0092 #define HWMON_T_ENABLE BIT(hwmon_temp_enable)
0093 #define HWMON_T_INPUT BIT(hwmon_temp_input)
0094 #define HWMON_T_TYPE BIT(hwmon_temp_type)
0095 #define HWMON_T_LCRIT BIT(hwmon_temp_lcrit)
0096 #define HWMON_T_LCRIT_HYST BIT(hwmon_temp_lcrit_hyst)
0097 #define HWMON_T_MIN BIT(hwmon_temp_min)
0098 #define HWMON_T_MIN_HYST BIT(hwmon_temp_min_hyst)
0099 #define HWMON_T_MAX BIT(hwmon_temp_max)
0100 #define HWMON_T_MAX_HYST BIT(hwmon_temp_max_hyst)
0101 #define HWMON_T_CRIT BIT(hwmon_temp_crit)
0102 #define HWMON_T_CRIT_HYST BIT(hwmon_temp_crit_hyst)
0103 #define HWMON_T_EMERGENCY BIT(hwmon_temp_emergency)
0104 #define HWMON_T_EMERGENCY_HYST BIT(hwmon_temp_emergency_hyst)
0105 #define HWMON_T_ALARM BIT(hwmon_temp_alarm)
0106 #define HWMON_T_MIN_ALARM BIT(hwmon_temp_min_alarm)
0107 #define HWMON_T_MAX_ALARM BIT(hwmon_temp_max_alarm)
0108 #define HWMON_T_CRIT_ALARM BIT(hwmon_temp_crit_alarm)
0109 #define HWMON_T_LCRIT_ALARM BIT(hwmon_temp_lcrit_alarm)
0110 #define HWMON_T_EMERGENCY_ALARM BIT(hwmon_temp_emergency_alarm)
0111 #define HWMON_T_FAULT BIT(hwmon_temp_fault)
0112 #define HWMON_T_OFFSET BIT(hwmon_temp_offset)
0113 #define HWMON_T_LABEL BIT(hwmon_temp_label)
0114 #define HWMON_T_LOWEST BIT(hwmon_temp_lowest)
0115 #define HWMON_T_HIGHEST BIT(hwmon_temp_highest)
0116 #define HWMON_T_RESET_HISTORY BIT(hwmon_temp_reset_history)
0117 #define HWMON_T_RATED_MIN BIT(hwmon_temp_rated_min)
0118 #define HWMON_T_RATED_MAX BIT(hwmon_temp_rated_max)
0119
0120 enum hwmon_in_attributes {
0121 hwmon_in_enable,
0122 hwmon_in_input,
0123 hwmon_in_min,
0124 hwmon_in_max,
0125 hwmon_in_lcrit,
0126 hwmon_in_crit,
0127 hwmon_in_average,
0128 hwmon_in_lowest,
0129 hwmon_in_highest,
0130 hwmon_in_reset_history,
0131 hwmon_in_label,
0132 hwmon_in_alarm,
0133 hwmon_in_min_alarm,
0134 hwmon_in_max_alarm,
0135 hwmon_in_lcrit_alarm,
0136 hwmon_in_crit_alarm,
0137 hwmon_in_rated_min,
0138 hwmon_in_rated_max,
0139 };
0140
0141 #define HWMON_I_ENABLE BIT(hwmon_in_enable)
0142 #define HWMON_I_INPUT BIT(hwmon_in_input)
0143 #define HWMON_I_MIN BIT(hwmon_in_min)
0144 #define HWMON_I_MAX BIT(hwmon_in_max)
0145 #define HWMON_I_LCRIT BIT(hwmon_in_lcrit)
0146 #define HWMON_I_CRIT BIT(hwmon_in_crit)
0147 #define HWMON_I_AVERAGE BIT(hwmon_in_average)
0148 #define HWMON_I_LOWEST BIT(hwmon_in_lowest)
0149 #define HWMON_I_HIGHEST BIT(hwmon_in_highest)
0150 #define HWMON_I_RESET_HISTORY BIT(hwmon_in_reset_history)
0151 #define HWMON_I_LABEL BIT(hwmon_in_label)
0152 #define HWMON_I_ALARM BIT(hwmon_in_alarm)
0153 #define HWMON_I_MIN_ALARM BIT(hwmon_in_min_alarm)
0154 #define HWMON_I_MAX_ALARM BIT(hwmon_in_max_alarm)
0155 #define HWMON_I_LCRIT_ALARM BIT(hwmon_in_lcrit_alarm)
0156 #define HWMON_I_CRIT_ALARM BIT(hwmon_in_crit_alarm)
0157 #define HWMON_I_RATED_MIN BIT(hwmon_in_rated_min)
0158 #define HWMON_I_RATED_MAX BIT(hwmon_in_rated_max)
0159
0160 enum hwmon_curr_attributes {
0161 hwmon_curr_enable,
0162 hwmon_curr_input,
0163 hwmon_curr_min,
0164 hwmon_curr_max,
0165 hwmon_curr_lcrit,
0166 hwmon_curr_crit,
0167 hwmon_curr_average,
0168 hwmon_curr_lowest,
0169 hwmon_curr_highest,
0170 hwmon_curr_reset_history,
0171 hwmon_curr_label,
0172 hwmon_curr_alarm,
0173 hwmon_curr_min_alarm,
0174 hwmon_curr_max_alarm,
0175 hwmon_curr_lcrit_alarm,
0176 hwmon_curr_crit_alarm,
0177 hwmon_curr_rated_min,
0178 hwmon_curr_rated_max,
0179 };
0180
0181 #define HWMON_C_ENABLE BIT(hwmon_curr_enable)
0182 #define HWMON_C_INPUT BIT(hwmon_curr_input)
0183 #define HWMON_C_MIN BIT(hwmon_curr_min)
0184 #define HWMON_C_MAX BIT(hwmon_curr_max)
0185 #define HWMON_C_LCRIT BIT(hwmon_curr_lcrit)
0186 #define HWMON_C_CRIT BIT(hwmon_curr_crit)
0187 #define HWMON_C_AVERAGE BIT(hwmon_curr_average)
0188 #define HWMON_C_LOWEST BIT(hwmon_curr_lowest)
0189 #define HWMON_C_HIGHEST BIT(hwmon_curr_highest)
0190 #define HWMON_C_RESET_HISTORY BIT(hwmon_curr_reset_history)
0191 #define HWMON_C_LABEL BIT(hwmon_curr_label)
0192 #define HWMON_C_ALARM BIT(hwmon_curr_alarm)
0193 #define HWMON_C_MIN_ALARM BIT(hwmon_curr_min_alarm)
0194 #define HWMON_C_MAX_ALARM BIT(hwmon_curr_max_alarm)
0195 #define HWMON_C_LCRIT_ALARM BIT(hwmon_curr_lcrit_alarm)
0196 #define HWMON_C_CRIT_ALARM BIT(hwmon_curr_crit_alarm)
0197 #define HWMON_C_RATED_MIN BIT(hwmon_curr_rated_min)
0198 #define HWMON_C_RATED_MAX BIT(hwmon_curr_rated_max)
0199
0200 enum hwmon_power_attributes {
0201 hwmon_power_enable,
0202 hwmon_power_average,
0203 hwmon_power_average_interval,
0204 hwmon_power_average_interval_max,
0205 hwmon_power_average_interval_min,
0206 hwmon_power_average_highest,
0207 hwmon_power_average_lowest,
0208 hwmon_power_average_max,
0209 hwmon_power_average_min,
0210 hwmon_power_input,
0211 hwmon_power_input_highest,
0212 hwmon_power_input_lowest,
0213 hwmon_power_reset_history,
0214 hwmon_power_accuracy,
0215 hwmon_power_cap,
0216 hwmon_power_cap_hyst,
0217 hwmon_power_cap_max,
0218 hwmon_power_cap_min,
0219 hwmon_power_min,
0220 hwmon_power_max,
0221 hwmon_power_crit,
0222 hwmon_power_lcrit,
0223 hwmon_power_label,
0224 hwmon_power_alarm,
0225 hwmon_power_cap_alarm,
0226 hwmon_power_min_alarm,
0227 hwmon_power_max_alarm,
0228 hwmon_power_lcrit_alarm,
0229 hwmon_power_crit_alarm,
0230 hwmon_power_rated_min,
0231 hwmon_power_rated_max,
0232 };
0233
0234 #define HWMON_P_ENABLE BIT(hwmon_power_enable)
0235 #define HWMON_P_AVERAGE BIT(hwmon_power_average)
0236 #define HWMON_P_AVERAGE_INTERVAL BIT(hwmon_power_average_interval)
0237 #define HWMON_P_AVERAGE_INTERVAL_MAX BIT(hwmon_power_average_interval_max)
0238 #define HWMON_P_AVERAGE_INTERVAL_MIN BIT(hwmon_power_average_interval_min)
0239 #define HWMON_P_AVERAGE_HIGHEST BIT(hwmon_power_average_highest)
0240 #define HWMON_P_AVERAGE_LOWEST BIT(hwmon_power_average_lowest)
0241 #define HWMON_P_AVERAGE_MAX BIT(hwmon_power_average_max)
0242 #define HWMON_P_AVERAGE_MIN BIT(hwmon_power_average_min)
0243 #define HWMON_P_INPUT BIT(hwmon_power_input)
0244 #define HWMON_P_INPUT_HIGHEST BIT(hwmon_power_input_highest)
0245 #define HWMON_P_INPUT_LOWEST BIT(hwmon_power_input_lowest)
0246 #define HWMON_P_RESET_HISTORY BIT(hwmon_power_reset_history)
0247 #define HWMON_P_ACCURACY BIT(hwmon_power_accuracy)
0248 #define HWMON_P_CAP BIT(hwmon_power_cap)
0249 #define HWMON_P_CAP_HYST BIT(hwmon_power_cap_hyst)
0250 #define HWMON_P_CAP_MAX BIT(hwmon_power_cap_max)
0251 #define HWMON_P_CAP_MIN BIT(hwmon_power_cap_min)
0252 #define HWMON_P_MIN BIT(hwmon_power_min)
0253 #define HWMON_P_MAX BIT(hwmon_power_max)
0254 #define HWMON_P_LCRIT BIT(hwmon_power_lcrit)
0255 #define HWMON_P_CRIT BIT(hwmon_power_crit)
0256 #define HWMON_P_LABEL BIT(hwmon_power_label)
0257 #define HWMON_P_ALARM BIT(hwmon_power_alarm)
0258 #define HWMON_P_CAP_ALARM BIT(hwmon_power_cap_alarm)
0259 #define HWMON_P_MIN_ALARM BIT(hwmon_power_min_alarm)
0260 #define HWMON_P_MAX_ALARM BIT(hwmon_power_max_alarm)
0261 #define HWMON_P_LCRIT_ALARM BIT(hwmon_power_lcrit_alarm)
0262 #define HWMON_P_CRIT_ALARM BIT(hwmon_power_crit_alarm)
0263 #define HWMON_P_RATED_MIN BIT(hwmon_power_rated_min)
0264 #define HWMON_P_RATED_MAX BIT(hwmon_power_rated_max)
0265
0266 enum hwmon_energy_attributes {
0267 hwmon_energy_enable,
0268 hwmon_energy_input,
0269 hwmon_energy_label,
0270 };
0271
0272 #define HWMON_E_ENABLE BIT(hwmon_energy_enable)
0273 #define HWMON_E_INPUT BIT(hwmon_energy_input)
0274 #define HWMON_E_LABEL BIT(hwmon_energy_label)
0275
0276 enum hwmon_humidity_attributes {
0277 hwmon_humidity_enable,
0278 hwmon_humidity_input,
0279 hwmon_humidity_label,
0280 hwmon_humidity_min,
0281 hwmon_humidity_min_hyst,
0282 hwmon_humidity_max,
0283 hwmon_humidity_max_hyst,
0284 hwmon_humidity_alarm,
0285 hwmon_humidity_fault,
0286 hwmon_humidity_rated_min,
0287 hwmon_humidity_rated_max,
0288 };
0289
0290 #define HWMON_H_ENABLE BIT(hwmon_humidity_enable)
0291 #define HWMON_H_INPUT BIT(hwmon_humidity_input)
0292 #define HWMON_H_LABEL BIT(hwmon_humidity_label)
0293 #define HWMON_H_MIN BIT(hwmon_humidity_min)
0294 #define HWMON_H_MIN_HYST BIT(hwmon_humidity_min_hyst)
0295 #define HWMON_H_MAX BIT(hwmon_humidity_max)
0296 #define HWMON_H_MAX_HYST BIT(hwmon_humidity_max_hyst)
0297 #define HWMON_H_ALARM BIT(hwmon_humidity_alarm)
0298 #define HWMON_H_FAULT BIT(hwmon_humidity_fault)
0299 #define HWMON_H_RATED_MIN BIT(hwmon_humidity_rated_min)
0300 #define HWMON_H_RATED_MAX BIT(hwmon_humidity_rated_max)
0301
0302 enum hwmon_fan_attributes {
0303 hwmon_fan_enable,
0304 hwmon_fan_input,
0305 hwmon_fan_label,
0306 hwmon_fan_min,
0307 hwmon_fan_max,
0308 hwmon_fan_div,
0309 hwmon_fan_pulses,
0310 hwmon_fan_target,
0311 hwmon_fan_alarm,
0312 hwmon_fan_min_alarm,
0313 hwmon_fan_max_alarm,
0314 hwmon_fan_fault,
0315 };
0316
0317 #define HWMON_F_ENABLE BIT(hwmon_fan_enable)
0318 #define HWMON_F_INPUT BIT(hwmon_fan_input)
0319 #define HWMON_F_LABEL BIT(hwmon_fan_label)
0320 #define HWMON_F_MIN BIT(hwmon_fan_min)
0321 #define HWMON_F_MAX BIT(hwmon_fan_max)
0322 #define HWMON_F_DIV BIT(hwmon_fan_div)
0323 #define HWMON_F_PULSES BIT(hwmon_fan_pulses)
0324 #define HWMON_F_TARGET BIT(hwmon_fan_target)
0325 #define HWMON_F_ALARM BIT(hwmon_fan_alarm)
0326 #define HWMON_F_MIN_ALARM BIT(hwmon_fan_min_alarm)
0327 #define HWMON_F_MAX_ALARM BIT(hwmon_fan_max_alarm)
0328 #define HWMON_F_FAULT BIT(hwmon_fan_fault)
0329
0330 enum hwmon_pwm_attributes {
0331 hwmon_pwm_input,
0332 hwmon_pwm_enable,
0333 hwmon_pwm_mode,
0334 hwmon_pwm_freq,
0335 hwmon_pwm_auto_channels_temp,
0336 };
0337
0338 #define HWMON_PWM_INPUT BIT(hwmon_pwm_input)
0339 #define HWMON_PWM_ENABLE BIT(hwmon_pwm_enable)
0340 #define HWMON_PWM_MODE BIT(hwmon_pwm_mode)
0341 #define HWMON_PWM_FREQ BIT(hwmon_pwm_freq)
0342 #define HWMON_PWM_AUTO_CHANNELS_TEMP BIT(hwmon_pwm_auto_channels_temp)
0343
0344 enum hwmon_intrusion_attributes {
0345 hwmon_intrusion_alarm,
0346 hwmon_intrusion_beep,
0347 };
0348 #define HWMON_INTRUSION_ALARM BIT(hwmon_intrusion_alarm)
0349 #define HWMON_INTRUSION_BEEP BIT(hwmon_intrusion_beep)
0350
0351
0352
0353
0354
0355
0356
0357
0358
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368
0369
0370
0371
0372
0373
0374
0375
0376
0377
0378
0379
0380
0381
0382
0383
0384
0385
0386
0387
0388
0389
0390
0391
0392
0393
0394
0395
0396 struct hwmon_ops {
0397 umode_t (*is_visible)(const void *drvdata, enum hwmon_sensor_types type,
0398 u32 attr, int channel);
0399 int (*read)(struct device *dev, enum hwmon_sensor_types type,
0400 u32 attr, int channel, long *val);
0401 int (*read_string)(struct device *dev, enum hwmon_sensor_types type,
0402 u32 attr, int channel, const char **str);
0403 int (*write)(struct device *dev, enum hwmon_sensor_types type,
0404 u32 attr, int channel, long val);
0405 };
0406
0407
0408
0409
0410
0411
0412
0413 struct hwmon_channel_info {
0414 enum hwmon_sensor_types type;
0415 const u32 *config;
0416 };
0417
0418 #define HWMON_CHANNEL_INFO(stype, ...) \
0419 (&(struct hwmon_channel_info) { \
0420 .type = hwmon_##stype, \
0421 .config = (u32 []) { \
0422 __VA_ARGS__, 0 \
0423 } \
0424 })
0425
0426
0427
0428
0429
0430
0431 struct hwmon_chip_info {
0432 const struct hwmon_ops *ops;
0433 const struct hwmon_channel_info **info;
0434 };
0435
0436
0437 struct device *hwmon_device_register(struct device *dev);
0438
0439 struct device *
0440 hwmon_device_register_with_groups(struct device *dev, const char *name,
0441 void *drvdata,
0442 const struct attribute_group **groups);
0443 struct device *
0444 devm_hwmon_device_register_with_groups(struct device *dev, const char *name,
0445 void *drvdata,
0446 const struct attribute_group **groups);
0447 struct device *
0448 hwmon_device_register_with_info(struct device *dev,
0449 const char *name, void *drvdata,
0450 const struct hwmon_chip_info *info,
0451 const struct attribute_group **extra_groups);
0452 struct device *
0453 hwmon_device_register_for_thermal(struct device *dev, const char *name,
0454 void *drvdata);
0455 struct device *
0456 devm_hwmon_device_register_with_info(struct device *dev,
0457 const char *name, void *drvdata,
0458 const struct hwmon_chip_info *info,
0459 const struct attribute_group **extra_groups);
0460
0461 void hwmon_device_unregister(struct device *dev);
0462 void devm_hwmon_device_unregister(struct device *dev);
0463
0464 int hwmon_notify_event(struct device *dev, enum hwmon_sensor_types type,
0465 u32 attr, int channel);
0466
0467 char *hwmon_sanitize_name(const char *name);
0468 char *devm_hwmon_sanitize_name(struct device *dev, const char *name);
0469
0470
0471
0472
0473
0474
0475
0476
0477
0478
0479 static inline bool hwmon_is_bad_char(const char ch)
0480 {
0481 switch (ch) {
0482 case '-':
0483 case '*':
0484 case ' ':
0485 case '\t':
0486 case '\n':
0487 return true;
0488 default:
0489 return false;
0490 }
0491 }
0492
0493 #endif