17ebd8b66SMauro Carvalho ChehabThe Linux Hardware Monitoring kernel API 27ebd8b66SMauro Carvalho Chehab======================================== 37ebd8b66SMauro Carvalho Chehab 47ebd8b66SMauro Carvalho ChehabGuenter Roeck 57ebd8b66SMauro Carvalho Chehab 67ebd8b66SMauro Carvalho ChehabIntroduction 77ebd8b66SMauro Carvalho Chehab------------ 87ebd8b66SMauro Carvalho Chehab 97ebd8b66SMauro Carvalho ChehabThis document describes the API that can be used by hardware monitoring 107ebd8b66SMauro Carvalho Chehabdrivers that want to use the hardware monitoring framework. 117ebd8b66SMauro Carvalho Chehab 127ebd8b66SMauro Carvalho ChehabThis document does not describe what a hardware monitoring (hwmon) Driver or 137ebd8b66SMauro Carvalho ChehabDevice is. It also does not describe the API which can be used by user space 147ebd8b66SMauro Carvalho Chehabto communicate with a hardware monitoring device. If you want to know this 157ebd8b66SMauro Carvalho Chehabthen please read the following file: Documentation/hwmon/sysfs-interface.rst. 167ebd8b66SMauro Carvalho Chehab 177ebd8b66SMauro Carvalho ChehabFor additional guidelines on how to write and improve hwmon drivers, please 187ebd8b66SMauro Carvalho Chehabalso read Documentation/hwmon/submitting-patches.rst. 197ebd8b66SMauro Carvalho Chehab 207ebd8b66SMauro Carvalho ChehabThe API 217ebd8b66SMauro Carvalho Chehab------- 227ebd8b66SMauro Carvalho ChehabEach hardware monitoring driver must #include <linux/hwmon.h> and, in most 237ebd8b66SMauro Carvalho Chehabcases, <linux/hwmon-sysfs.h>. linux/hwmon.h declares the following 247ebd8b66SMauro Carvalho Chehabregister/unregister functions:: 257ebd8b66SMauro Carvalho Chehab 267ebd8b66SMauro Carvalho Chehab struct device * 277ebd8b66SMauro Carvalho Chehab hwmon_device_register_with_groups(struct device *dev, const char *name, 287ebd8b66SMauro Carvalho Chehab void *drvdata, 297ebd8b66SMauro Carvalho Chehab const struct attribute_group **groups); 307ebd8b66SMauro Carvalho Chehab 317ebd8b66SMauro Carvalho Chehab struct device * 327ebd8b66SMauro Carvalho Chehab devm_hwmon_device_register_with_groups(struct device *dev, 337ebd8b66SMauro Carvalho Chehab const char *name, void *drvdata, 347ebd8b66SMauro Carvalho Chehab const struct attribute_group **groups); 357ebd8b66SMauro Carvalho Chehab 367ebd8b66SMauro Carvalho Chehab struct device * 377ebd8b66SMauro Carvalho Chehab hwmon_device_register_with_info(struct device *dev, 387ebd8b66SMauro Carvalho Chehab const char *name, void *drvdata, 397ebd8b66SMauro Carvalho Chehab const struct hwmon_chip_info *info, 407ebd8b66SMauro Carvalho Chehab const struct attribute_group **extra_groups); 417ebd8b66SMauro Carvalho Chehab 427ebd8b66SMauro Carvalho Chehab struct device * 437ebd8b66SMauro Carvalho Chehab devm_hwmon_device_register_with_info(struct device *dev, 447ebd8b66SMauro Carvalho Chehab const char *name, 457ebd8b66SMauro Carvalho Chehab void *drvdata, 467ebd8b66SMauro Carvalho Chehab const struct hwmon_chip_info *info, 477ebd8b66SMauro Carvalho Chehab const struct attribute_group **extra_groups); 487ebd8b66SMauro Carvalho Chehab 497ebd8b66SMauro Carvalho Chehab void hwmon_device_unregister(struct device *dev); 507ebd8b66SMauro Carvalho Chehab 517ebd8b66SMauro Carvalho Chehab void devm_hwmon_device_unregister(struct device *dev); 527ebd8b66SMauro Carvalho Chehab 531ad6c3b7SMichael Walle char *hwmon_sanitize_name(const char *name); 541ad6c3b7SMichael Walle 551ad6c3b7SMichael Walle char *devm_hwmon_sanitize_name(struct device *dev, const char *name); 561ad6c3b7SMichael Walle 577ebd8b66SMauro Carvalho Chehabhwmon_device_register_with_groups registers a hardware monitoring device. 587ebd8b66SMauro Carvalho ChehabThe first parameter of this function is a pointer to the parent device. 597ebd8b66SMauro Carvalho ChehabThe name parameter is a pointer to the hwmon device name. The registration 607ebd8b66SMauro Carvalho Chehabfunction wil create a name sysfs attribute pointing to this name. 617ebd8b66SMauro Carvalho ChehabThe drvdata parameter is the pointer to the local driver data. 627ebd8b66SMauro Carvalho Chehabhwmon_device_register_with_groups will attach this pointer to the newly 637ebd8b66SMauro Carvalho Chehaballocated hwmon device. The pointer can be retrieved by the driver using 647ebd8b66SMauro Carvalho Chehabdev_get_drvdata() on the hwmon device pointer. The groups parameter is 657ebd8b66SMauro Carvalho Chehaba pointer to a list of sysfs attribute groups. The list must be NULL terminated. 667ebd8b66SMauro Carvalho Chehabhwmon_device_register_with_groups creates the hwmon device with name attribute 677ebd8b66SMauro Carvalho Chehabas well as all sysfs attributes attached to the hwmon device. 687ebd8b66SMauro Carvalho ChehabThis function returns a pointer to the newly created hardware monitoring device 697ebd8b66SMauro Carvalho Chehabor PTR_ERR for failure. 707ebd8b66SMauro Carvalho Chehab 717ebd8b66SMauro Carvalho Chehabdevm_hwmon_device_register_with_groups is similar to 727ebd8b66SMauro Carvalho Chehabhwmon_device_register_with_groups. However, it is device managed, meaning the 737ebd8b66SMauro Carvalho Chehabhwmon device does not have to be removed explicitly by the removal function. 747ebd8b66SMauro Carvalho Chehab 757ebd8b66SMauro Carvalho Chehabhwmon_device_register_with_info is the most comprehensive and preferred means 767ebd8b66SMauro Carvalho Chehabto register a hardware monitoring device. It creates the standard sysfs 777ebd8b66SMauro Carvalho Chehabattributes in the hardware monitoring core, letting the driver focus on reading 787ebd8b66SMauro Carvalho Chehabfrom and writing to the chip instead of having to bother with sysfs attributes. 79ddaefa20SGuenter RoeckThe parent device parameter as well as the chip parameter must not be NULL. Its 807ebd8b66SMauro Carvalho Chehabparameters are described in more detail below. 817ebd8b66SMauro Carvalho Chehab 827ebd8b66SMauro Carvalho Chehabdevm_hwmon_device_register_with_info is similar to 837ebd8b66SMauro Carvalho Chehabhwmon_device_register_with_info. However, it is device managed, meaning the 847ebd8b66SMauro Carvalho Chehabhwmon device does not have to be removed explicitly by the removal function. 857ebd8b66SMauro Carvalho Chehab 867ebd8b66SMauro Carvalho Chehabhwmon_device_unregister deregisters a registered hardware monitoring device. 877ebd8b66SMauro Carvalho ChehabThe parameter of this function is the pointer to the registered hardware 887ebd8b66SMauro Carvalho Chehabmonitoring device structure. This function must be called from the driver 897ebd8b66SMauro Carvalho Chehabremove function if the hardware monitoring device was registered with 907ebd8b66SMauro Carvalho Chehabhwmon_device_register_with_groups or hwmon_device_register_with_info. 917ebd8b66SMauro Carvalho Chehab 927ebd8b66SMauro Carvalho Chehabdevm_hwmon_device_unregister does not normally have to be called. It is only 937ebd8b66SMauro Carvalho Chehabneeded for error handling, and only needed if the driver probe fails after 947ebd8b66SMauro Carvalho Chehabthe call to devm_hwmon_device_register_with_groups or 957ebd8b66SMauro Carvalho Chehabhwmon_device_register_with_info and if the automatic (device managed) 967ebd8b66SMauro Carvalho Chehabremoval would be too late. 977ebd8b66SMauro Carvalho Chehab 987ebd8b66SMauro Carvalho ChehabAll supported hwmon device registration functions only accept valid device 997ebd8b66SMauro Carvalho Chehabnames. Device names including invalid characters (whitespace, '*', or '-') 1007ebd8b66SMauro Carvalho Chehabwill be rejected. The 'name' parameter is mandatory. 1017ebd8b66SMauro Carvalho Chehab 1021ad6c3b7SMichael WalleIf the driver doesn't use a static device name (for example it uses 1031ad6c3b7SMichael Walledev_name()), and therefore cannot make sure the name only contains valid 1041ad6c3b7SMichael Wallecharacters, hwmon_sanitize_name can be used. This convenience function 1051ad6c3b7SMichael Wallewill duplicate the string and replace any invalid characters with an 1061ad6c3b7SMichael Walleunderscore. It will allocate memory for the new string and it is the 1071ad6c3b7SMichael Walleresponsibility of the caller to release the memory when the device is 1081ad6c3b7SMichael Walleremoved. 1091ad6c3b7SMichael Walle 1101ad6c3b7SMichael Walledevm_hwmon_sanitize_name is the resource managed version of 1111ad6c3b7SMichael Wallehwmon_sanitize_name; the memory will be freed automatically on device 1121ad6c3b7SMichael Walleremoval. 1131ad6c3b7SMichael Walle 1147ebd8b66SMauro Carvalho ChehabUsing devm_hwmon_device_register_with_info() 1157ebd8b66SMauro Carvalho Chehab-------------------------------------------- 1167ebd8b66SMauro Carvalho Chehab 1177ebd8b66SMauro Carvalho Chehabhwmon_device_register_with_info() registers a hardware monitoring device. 1187ebd8b66SMauro Carvalho ChehabThe parameters to this function are 1197ebd8b66SMauro Carvalho Chehab 1207ebd8b66SMauro Carvalho Chehab=============================================== =============================================== 1217ebd8b66SMauro Carvalho Chehab`struct device *dev` Pointer to parent device 1227ebd8b66SMauro Carvalho Chehab`const char *name` Device name 1237ebd8b66SMauro Carvalho Chehab`void *drvdata` Driver private data 1247ebd8b66SMauro Carvalho Chehab`const struct hwmon_chip_info *info` Pointer to chip description. 1257ebd8b66SMauro Carvalho Chehab`const struct attribute_group **extra_groups` Null-terminated list of additional non-standard 1267ebd8b66SMauro Carvalho Chehab sysfs attribute groups. 1277ebd8b66SMauro Carvalho Chehab=============================================== =============================================== 1287ebd8b66SMauro Carvalho Chehab 1297ebd8b66SMauro Carvalho ChehabThis function returns a pointer to the created hardware monitoring device 1307ebd8b66SMauro Carvalho Chehabon success and a negative error code for failure. 1317ebd8b66SMauro Carvalho Chehab 1327ebd8b66SMauro Carvalho ChehabThe hwmon_chip_info structure looks as follows:: 1337ebd8b66SMauro Carvalho Chehab 1347ebd8b66SMauro Carvalho Chehab struct hwmon_chip_info { 1357ebd8b66SMauro Carvalho Chehab const struct hwmon_ops *ops; 1367ebd8b66SMauro Carvalho Chehab const struct hwmon_channel_info **info; 1377ebd8b66SMauro Carvalho Chehab }; 1387ebd8b66SMauro Carvalho Chehab 1397ebd8b66SMauro Carvalho ChehabIt contains the following fields: 1407ebd8b66SMauro Carvalho Chehab 1417ebd8b66SMauro Carvalho Chehab* ops: 1427ebd8b66SMauro Carvalho Chehab Pointer to device operations. 1437ebd8b66SMauro Carvalho Chehab* info: 1447ebd8b66SMauro Carvalho Chehab NULL-terminated list of device channel descriptors. 1457ebd8b66SMauro Carvalho Chehab 1467ebd8b66SMauro Carvalho ChehabThe list of hwmon operations is defined as:: 1477ebd8b66SMauro Carvalho Chehab 1487ebd8b66SMauro Carvalho Chehab struct hwmon_ops { 1497ebd8b66SMauro Carvalho Chehab umode_t (*is_visible)(const void *, enum hwmon_sensor_types type, 1507ebd8b66SMauro Carvalho Chehab u32 attr, int); 1517ebd8b66SMauro Carvalho Chehab int (*read)(struct device *, enum hwmon_sensor_types type, 1527ebd8b66SMauro Carvalho Chehab u32 attr, int, long *); 1537ebd8b66SMauro Carvalho Chehab int (*write)(struct device *, enum hwmon_sensor_types type, 1547ebd8b66SMauro Carvalho Chehab u32 attr, int, long); 1557ebd8b66SMauro Carvalho Chehab }; 1567ebd8b66SMauro Carvalho Chehab 1577ebd8b66SMauro Carvalho ChehabIt defines the following operations. 1587ebd8b66SMauro Carvalho Chehab 1597ebd8b66SMauro Carvalho Chehab* is_visible: 1607ebd8b66SMauro Carvalho Chehab Pointer to a function to return the file mode for each supported 1617ebd8b66SMauro Carvalho Chehab attribute. This function is mandatory. 1627ebd8b66SMauro Carvalho Chehab 1637ebd8b66SMauro Carvalho Chehab* read: 1647ebd8b66SMauro Carvalho Chehab Pointer to a function for reading a value from the chip. This function 1657ebd8b66SMauro Carvalho Chehab is optional, but must be provided if any readable attributes exist. 1667ebd8b66SMauro Carvalho Chehab 1677ebd8b66SMauro Carvalho Chehab* write: 1687ebd8b66SMauro Carvalho Chehab Pointer to a function for writing a value to the chip. This function is 1697ebd8b66SMauro Carvalho Chehab optional, but must be provided if any writeable attributes exist. 1707ebd8b66SMauro Carvalho Chehab 1717ebd8b66SMauro Carvalho ChehabEach sensor channel is described with struct hwmon_channel_info, which is 1727ebd8b66SMauro Carvalho Chehabdefined as follows:: 1737ebd8b66SMauro Carvalho Chehab 1747ebd8b66SMauro Carvalho Chehab struct hwmon_channel_info { 1757ebd8b66SMauro Carvalho Chehab enum hwmon_sensor_types type; 1767ebd8b66SMauro Carvalho Chehab u32 *config; 1777ebd8b66SMauro Carvalho Chehab }; 1787ebd8b66SMauro Carvalho Chehab 1797ebd8b66SMauro Carvalho ChehabIt contains following fields: 1807ebd8b66SMauro Carvalho Chehab 1817ebd8b66SMauro Carvalho Chehab* type: 1827ebd8b66SMauro Carvalho Chehab The hardware monitoring sensor type. 1837ebd8b66SMauro Carvalho Chehab 1847ebd8b66SMauro Carvalho Chehab Supported sensor types are 1857ebd8b66SMauro Carvalho Chehab 1867ebd8b66SMauro Carvalho Chehab ================== ================================================== 1877ebd8b66SMauro Carvalho Chehab hwmon_chip A virtual sensor type, used to describe attributes 1887ebd8b66SMauro Carvalho Chehab which are not bound to a specific input or output 1897ebd8b66SMauro Carvalho Chehab hwmon_temp Temperature sensor 1907ebd8b66SMauro Carvalho Chehab hwmon_in Voltage sensor 1917ebd8b66SMauro Carvalho Chehab hwmon_curr Current sensor 1927ebd8b66SMauro Carvalho Chehab hwmon_power Power sensor 1937ebd8b66SMauro Carvalho Chehab hwmon_energy Energy sensor 1947ebd8b66SMauro Carvalho Chehab hwmon_humidity Humidity sensor 1957ebd8b66SMauro Carvalho Chehab hwmon_fan Fan speed sensor 1967ebd8b66SMauro Carvalho Chehab hwmon_pwm PWM control 1977ebd8b66SMauro Carvalho Chehab ================== ================================================== 1987ebd8b66SMauro Carvalho Chehab 1997ebd8b66SMauro Carvalho Chehab* config: 2007ebd8b66SMauro Carvalho Chehab Pointer to a 0-terminated list of configuration values for each 2017ebd8b66SMauro Carvalho Chehab sensor of the given type. Each value is a combination of bit values 2027ebd8b66SMauro Carvalho Chehab describing the attributes supposed by a single sensor. 2037ebd8b66SMauro Carvalho Chehab 2047ebd8b66SMauro Carvalho ChehabAs an example, here is the complete description file for a LM75 compatible 2057ebd8b66SMauro Carvalho Chehabsensor chip. The chip has a single temperature sensor. The driver wants to 2067ebd8b66SMauro Carvalho Chehabregister with the thermal subsystem (HWMON_C_REGISTER_TZ), and it supports 2077ebd8b66SMauro Carvalho Chehabthe update_interval attribute (HWMON_C_UPDATE_INTERVAL). The chip supports 2087ebd8b66SMauro Carvalho Chehabreading the temperature (HWMON_T_INPUT), it has a maximum temperature 2097ebd8b66SMauro Carvalho Chehabregister (HWMON_T_MAX) as well as a maximum temperature hysteresis register 2107ebd8b66SMauro Carvalho Chehab(HWMON_T_MAX_HYST):: 2117ebd8b66SMauro Carvalho Chehab 2127ebd8b66SMauro Carvalho Chehab static const u32 lm75_chip_config[] = { 2137ebd8b66SMauro Carvalho Chehab HWMON_C_REGISTER_TZ | HWMON_C_UPDATE_INTERVAL, 2147ebd8b66SMauro Carvalho Chehab 0 2157ebd8b66SMauro Carvalho Chehab }; 2167ebd8b66SMauro Carvalho Chehab 2177ebd8b66SMauro Carvalho Chehab static const struct hwmon_channel_info lm75_chip = { 2187ebd8b66SMauro Carvalho Chehab .type = hwmon_chip, 2197ebd8b66SMauro Carvalho Chehab .config = lm75_chip_config, 2207ebd8b66SMauro Carvalho Chehab }; 2217ebd8b66SMauro Carvalho Chehab 2227ebd8b66SMauro Carvalho Chehab static const u32 lm75_temp_config[] = { 2237ebd8b66SMauro Carvalho Chehab HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MAX_HYST, 2247ebd8b66SMauro Carvalho Chehab 0 2257ebd8b66SMauro Carvalho Chehab }; 2267ebd8b66SMauro Carvalho Chehab 2277ebd8b66SMauro Carvalho Chehab static const struct hwmon_channel_info lm75_temp = { 2287ebd8b66SMauro Carvalho Chehab .type = hwmon_temp, 2297ebd8b66SMauro Carvalho Chehab .config = lm75_temp_config, 2307ebd8b66SMauro Carvalho Chehab }; 2317ebd8b66SMauro Carvalho Chehab 2327ebd8b66SMauro Carvalho Chehab static const struct hwmon_channel_info *lm75_info[] = { 2337ebd8b66SMauro Carvalho Chehab &lm75_chip, 2347ebd8b66SMauro Carvalho Chehab &lm75_temp, 2357ebd8b66SMauro Carvalho Chehab NULL 2367ebd8b66SMauro Carvalho Chehab }; 2377ebd8b66SMauro Carvalho Chehab 2387ebd8b66SMauro Carvalho Chehab The HWMON_CHANNEL_INFO() macro can and should be used when possible. 2397ebd8b66SMauro Carvalho Chehab With this macro, the above example can be simplified to 2407ebd8b66SMauro Carvalho Chehab 2417ebd8b66SMauro Carvalho Chehab static const struct hwmon_channel_info *lm75_info[] = { 2427ebd8b66SMauro Carvalho Chehab HWMON_CHANNEL_INFO(chip, 2437ebd8b66SMauro Carvalho Chehab HWMON_C_REGISTER_TZ | HWMON_C_UPDATE_INTERVAL), 2447ebd8b66SMauro Carvalho Chehab HWMON_CHANNEL_INFO(temp, 2457ebd8b66SMauro Carvalho Chehab HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MAX_HYST), 2467ebd8b66SMauro Carvalho Chehab NULL 2477ebd8b66SMauro Carvalho Chehab }; 2487ebd8b66SMauro Carvalho Chehab 2497ebd8b66SMauro Carvalho Chehab The remaining declarations are as follows. 2507ebd8b66SMauro Carvalho Chehab 2517ebd8b66SMauro Carvalho Chehab static const struct hwmon_ops lm75_hwmon_ops = { 2527ebd8b66SMauro Carvalho Chehab .is_visible = lm75_is_visible, 2537ebd8b66SMauro Carvalho Chehab .read = lm75_read, 2547ebd8b66SMauro Carvalho Chehab .write = lm75_write, 2557ebd8b66SMauro Carvalho Chehab }; 2567ebd8b66SMauro Carvalho Chehab 2577ebd8b66SMauro Carvalho Chehab static const struct hwmon_chip_info lm75_chip_info = { 2587ebd8b66SMauro Carvalho Chehab .ops = &lm75_hwmon_ops, 2597ebd8b66SMauro Carvalho Chehab .info = lm75_info, 2607ebd8b66SMauro Carvalho Chehab }; 2617ebd8b66SMauro Carvalho Chehab 2627ebd8b66SMauro Carvalho ChehabA complete list of bit values indicating individual attribute support 2637ebd8b66SMauro Carvalho Chehabis defined in include/linux/hwmon.h. Definition prefixes are as follows. 2647ebd8b66SMauro Carvalho Chehab 2657ebd8b66SMauro Carvalho Chehab=============== ================================================= 2667ebd8b66SMauro Carvalho ChehabHWMON_C_xxxx Chip attributes, for use with hwmon_chip. 2677ebd8b66SMauro Carvalho ChehabHWMON_T_xxxx Temperature attributes, for use with hwmon_temp. 2687ebd8b66SMauro Carvalho ChehabHWMON_I_xxxx Voltage attributes, for use with hwmon_in. 2697ebd8b66SMauro Carvalho ChehabHWMON_C_xxxx Current attributes, for use with hwmon_curr. 2707ebd8b66SMauro Carvalho Chehab Notice the prefix overlap with chip attributes. 2717ebd8b66SMauro Carvalho ChehabHWMON_P_xxxx Power attributes, for use with hwmon_power. 2727ebd8b66SMauro Carvalho ChehabHWMON_E_xxxx Energy attributes, for use with hwmon_energy. 2737ebd8b66SMauro Carvalho ChehabHWMON_H_xxxx Humidity attributes, for use with hwmon_humidity. 2747ebd8b66SMauro Carvalho ChehabHWMON_F_xxxx Fan speed attributes, for use with hwmon_fan. 2757ebd8b66SMauro Carvalho ChehabHWMON_PWM_xxxx PWM control attributes, for use with hwmon_pwm. 2767ebd8b66SMauro Carvalho Chehab=============== ================================================= 2777ebd8b66SMauro Carvalho Chehab 2787ebd8b66SMauro Carvalho ChehabDriver callback functions 2797ebd8b66SMauro Carvalho Chehab------------------------- 2807ebd8b66SMauro Carvalho Chehab 2817ebd8b66SMauro Carvalho ChehabEach driver provides is_visible, read, and write functions. Parameters 2827ebd8b66SMauro Carvalho Chehaband return values for those functions are as follows:: 2837ebd8b66SMauro Carvalho Chehab 2847ebd8b66SMauro Carvalho Chehab umode_t is_visible_func(const void *data, enum hwmon_sensor_types type, 2857ebd8b66SMauro Carvalho Chehab u32 attr, int channel) 2867ebd8b66SMauro Carvalho Chehab 2877ebd8b66SMauro Carvalho ChehabParameters: 2887ebd8b66SMauro Carvalho Chehab data: 2897ebd8b66SMauro Carvalho Chehab Pointer to device private data structure. 2907ebd8b66SMauro Carvalho Chehab type: 2917ebd8b66SMauro Carvalho Chehab The sensor type. 2927ebd8b66SMauro Carvalho Chehab attr: 2937ebd8b66SMauro Carvalho Chehab Attribute identifier associated with a specific attribute. 2947ebd8b66SMauro Carvalho Chehab For example, the attribute value for HWMON_T_INPUT would be 2957ebd8b66SMauro Carvalho Chehab hwmon_temp_input. For complete mappings of bit fields to 2967ebd8b66SMauro Carvalho Chehab attribute values please see include/linux/hwmon.h. 2977ebd8b66SMauro Carvalho Chehab channel: 2987ebd8b66SMauro Carvalho Chehab The sensor channel number. 2997ebd8b66SMauro Carvalho Chehab 3007ebd8b66SMauro Carvalho ChehabReturn value: 3017ebd8b66SMauro Carvalho Chehab The file mode for this attribute. Typically, this will be 0 (the 302*95a56de6SJoaquín Ignacio Aramendía attribute will not be created), 0444, or 0644. 3037ebd8b66SMauro Carvalho Chehab 3047ebd8b66SMauro Carvalho Chehab:: 3057ebd8b66SMauro Carvalho Chehab 3067ebd8b66SMauro Carvalho Chehab int read_func(struct device *dev, enum hwmon_sensor_types type, 3077ebd8b66SMauro Carvalho Chehab u32 attr, int channel, long *val) 3087ebd8b66SMauro Carvalho Chehab 3097ebd8b66SMauro Carvalho ChehabParameters: 3107ebd8b66SMauro Carvalho Chehab dev: 3117ebd8b66SMauro Carvalho Chehab Pointer to the hardware monitoring device. 3127ebd8b66SMauro Carvalho Chehab type: 3137ebd8b66SMauro Carvalho Chehab The sensor type. 3147ebd8b66SMauro Carvalho Chehab attr: 3157ebd8b66SMauro Carvalho Chehab Attribute identifier associated with a specific attribute. 3167ebd8b66SMauro Carvalho Chehab For example, the attribute value for HWMON_T_INPUT would be 3177ebd8b66SMauro Carvalho Chehab hwmon_temp_input. For complete mappings please see 3187ebd8b66SMauro Carvalho Chehab include/linux/hwmon.h. 3197ebd8b66SMauro Carvalho Chehab channel: 3207ebd8b66SMauro Carvalho Chehab The sensor channel number. 3217ebd8b66SMauro Carvalho Chehab val: 3227ebd8b66SMauro Carvalho Chehab Pointer to attribute value. 3237ebd8b66SMauro Carvalho Chehab 3247ebd8b66SMauro Carvalho ChehabReturn value: 3257ebd8b66SMauro Carvalho Chehab 0 on success, a negative error number otherwise. 3267ebd8b66SMauro Carvalho Chehab 3277ebd8b66SMauro Carvalho Chehab:: 3287ebd8b66SMauro Carvalho Chehab 3297ebd8b66SMauro Carvalho Chehab int write_func(struct device *dev, enum hwmon_sensor_types type, 3307ebd8b66SMauro Carvalho Chehab u32 attr, int channel, long val) 3317ebd8b66SMauro Carvalho Chehab 3327ebd8b66SMauro Carvalho ChehabParameters: 3337ebd8b66SMauro Carvalho Chehab dev: 3347ebd8b66SMauro Carvalho Chehab Pointer to the hardware monitoring device. 3357ebd8b66SMauro Carvalho Chehab type: 3367ebd8b66SMauro Carvalho Chehab The sensor type. 3377ebd8b66SMauro Carvalho Chehab attr: 3387ebd8b66SMauro Carvalho Chehab Attribute identifier associated with a specific attribute. 3397ebd8b66SMauro Carvalho Chehab For example, the attribute value for HWMON_T_INPUT would be 3407ebd8b66SMauro Carvalho Chehab hwmon_temp_input. For complete mappings please see 3417ebd8b66SMauro Carvalho Chehab include/linux/hwmon.h. 3427ebd8b66SMauro Carvalho Chehab channel: 3437ebd8b66SMauro Carvalho Chehab The sensor channel number. 3447ebd8b66SMauro Carvalho Chehab val: 3457ebd8b66SMauro Carvalho Chehab The value to write to the chip. 3467ebd8b66SMauro Carvalho Chehab 3477ebd8b66SMauro Carvalho ChehabReturn value: 3487ebd8b66SMauro Carvalho Chehab 0 on success, a negative error number otherwise. 3497ebd8b66SMauro Carvalho Chehab 3507ebd8b66SMauro Carvalho Chehab 3517ebd8b66SMauro Carvalho ChehabDriver-provided sysfs attributes 3527ebd8b66SMauro Carvalho Chehab-------------------------------- 3537ebd8b66SMauro Carvalho Chehab 3547ebd8b66SMauro Carvalho ChehabIf the hardware monitoring device is registered with 3557ebd8b66SMauro Carvalho Chehabhwmon_device_register_with_info or devm_hwmon_device_register_with_info, 3567ebd8b66SMauro Carvalho Chehabit is most likely not necessary to provide sysfs attributes. Only additional 3577ebd8b66SMauro Carvalho Chehabnon-standard sysfs attributes need to be provided when one of those registration 3587ebd8b66SMauro Carvalho Chehabfunctions is used. 3597ebd8b66SMauro Carvalho Chehab 3607ebd8b66SMauro Carvalho ChehabThe header file linux/hwmon-sysfs.h provides a number of useful macros to 3617ebd8b66SMauro Carvalho Chehabdeclare and use hardware monitoring sysfs attributes. 3627ebd8b66SMauro Carvalho Chehab 3637ebd8b66SMauro Carvalho ChehabIn many cases, you can use the exsting define DEVICE_ATTR or its variants 3647ebd8b66SMauro Carvalho ChehabDEVICE_ATTR_{RW,RO,WO} to declare such attributes. This is feasible if an 3657ebd8b66SMauro Carvalho Chehabattribute has no additional context. However, in many cases there will be 3667ebd8b66SMauro Carvalho Chehabadditional information such as a sensor index which will need to be passed 3677ebd8b66SMauro Carvalho Chehabto the sysfs attribute handling function. 3687ebd8b66SMauro Carvalho Chehab 3697ebd8b66SMauro Carvalho ChehabSENSOR_DEVICE_ATTR and SENSOR_DEVICE_ATTR_2 can be used to define attributes 3707ebd8b66SMauro Carvalho Chehabwhich need such additional context information. SENSOR_DEVICE_ATTR requires 3717ebd8b66SMauro Carvalho Chehabone additional argument, SENSOR_DEVICE_ATTR_2 requires two. 3727ebd8b66SMauro Carvalho Chehab 3737ebd8b66SMauro Carvalho ChehabSimplified variants of SENSOR_DEVICE_ATTR and SENSOR_DEVICE_ATTR_2 are available 3747ebd8b66SMauro Carvalho Chehaband should be used if standard attribute permissions and function names are 3757ebd8b66SMauro Carvalho Chehabfeasible. Standard permissions are 0644 for SENSOR_DEVICE_ATTR[_2]_RW, 3767ebd8b66SMauro Carvalho Chehab0444 for SENSOR_DEVICE_ATTR[_2]_RO, and 0200 for SENSOR_DEVICE_ATTR[_2]_WO. 3777ebd8b66SMauro Carvalho ChehabStandard functions, similar to DEVICE_ATTR_{RW,RO,WO}, have _show and _store 3787ebd8b66SMauro Carvalho Chehabappended to the provided function name. 3797ebd8b66SMauro Carvalho Chehab 3807ebd8b66SMauro Carvalho ChehabSENSOR_DEVICE_ATTR and its variants define a struct sensor_device_attribute 3817ebd8b66SMauro Carvalho Chehabvariable. This structure has the following fields:: 3827ebd8b66SMauro Carvalho Chehab 3837ebd8b66SMauro Carvalho Chehab struct sensor_device_attribute { 3847ebd8b66SMauro Carvalho Chehab struct device_attribute dev_attr; 3857ebd8b66SMauro Carvalho Chehab int index; 3867ebd8b66SMauro Carvalho Chehab }; 3877ebd8b66SMauro Carvalho Chehab 3887ebd8b66SMauro Carvalho ChehabYou can use to_sensor_dev_attr to get the pointer to this structure from the 3897ebd8b66SMauro Carvalho Chehabattribute read or write function. Its parameter is the device to which the 3907ebd8b66SMauro Carvalho Chehabattribute is attached. 3917ebd8b66SMauro Carvalho Chehab 3927ebd8b66SMauro Carvalho ChehabSENSOR_DEVICE_ATTR_2 and its variants define a struct sensor_device_attribute_2 3937ebd8b66SMauro Carvalho Chehabvariable, which is defined as follows:: 3947ebd8b66SMauro Carvalho Chehab 3957ebd8b66SMauro Carvalho Chehab struct sensor_device_attribute_2 { 3967ebd8b66SMauro Carvalho Chehab struct device_attribute dev_attr; 3977ebd8b66SMauro Carvalho Chehab u8 index; 3987ebd8b66SMauro Carvalho Chehab u8 nr; 3997ebd8b66SMauro Carvalho Chehab }; 4007ebd8b66SMauro Carvalho Chehab 4017ebd8b66SMauro Carvalho ChehabUse to_sensor_dev_attr_2 to get the pointer to this structure. Its parameter 4027ebd8b66SMauro Carvalho Chehabis the device to which the attribute is attached. 403