1*7ebd8b66SMauro Carvalho ChehabThe Linux Hardware Monitoring kernel API 2*7ebd8b66SMauro Carvalho Chehab======================================== 3*7ebd8b66SMauro Carvalho Chehab 4*7ebd8b66SMauro Carvalho ChehabGuenter Roeck 5*7ebd8b66SMauro Carvalho Chehab 6*7ebd8b66SMauro Carvalho ChehabIntroduction 7*7ebd8b66SMauro Carvalho Chehab------------ 8*7ebd8b66SMauro Carvalho Chehab 9*7ebd8b66SMauro Carvalho ChehabThis document describes the API that can be used by hardware monitoring 10*7ebd8b66SMauro Carvalho Chehabdrivers that want to use the hardware monitoring framework. 11*7ebd8b66SMauro Carvalho Chehab 12*7ebd8b66SMauro Carvalho ChehabThis document does not describe what a hardware monitoring (hwmon) Driver or 13*7ebd8b66SMauro Carvalho ChehabDevice is. It also does not describe the API which can be used by user space 14*7ebd8b66SMauro Carvalho Chehabto communicate with a hardware monitoring device. If you want to know this 15*7ebd8b66SMauro Carvalho Chehabthen please read the following file: Documentation/hwmon/sysfs-interface.rst. 16*7ebd8b66SMauro Carvalho Chehab 17*7ebd8b66SMauro Carvalho ChehabFor additional guidelines on how to write and improve hwmon drivers, please 18*7ebd8b66SMauro Carvalho Chehabalso read Documentation/hwmon/submitting-patches.rst. 19*7ebd8b66SMauro Carvalho Chehab 20*7ebd8b66SMauro Carvalho ChehabThe API 21*7ebd8b66SMauro Carvalho Chehab------- 22*7ebd8b66SMauro Carvalho ChehabEach hardware monitoring driver must #include <linux/hwmon.h> and, in most 23*7ebd8b66SMauro Carvalho Chehabcases, <linux/hwmon-sysfs.h>. linux/hwmon.h declares the following 24*7ebd8b66SMauro Carvalho Chehabregister/unregister functions:: 25*7ebd8b66SMauro Carvalho Chehab 26*7ebd8b66SMauro Carvalho Chehab struct device * 27*7ebd8b66SMauro Carvalho Chehab hwmon_device_register_with_groups(struct device *dev, const char *name, 28*7ebd8b66SMauro Carvalho Chehab void *drvdata, 29*7ebd8b66SMauro Carvalho Chehab const struct attribute_group **groups); 30*7ebd8b66SMauro Carvalho Chehab 31*7ebd8b66SMauro Carvalho Chehab struct device * 32*7ebd8b66SMauro Carvalho Chehab devm_hwmon_device_register_with_groups(struct device *dev, 33*7ebd8b66SMauro Carvalho Chehab const char *name, void *drvdata, 34*7ebd8b66SMauro Carvalho Chehab const struct attribute_group **groups); 35*7ebd8b66SMauro Carvalho Chehab 36*7ebd8b66SMauro Carvalho Chehab struct device * 37*7ebd8b66SMauro Carvalho Chehab hwmon_device_register_with_info(struct device *dev, 38*7ebd8b66SMauro Carvalho Chehab const char *name, void *drvdata, 39*7ebd8b66SMauro Carvalho Chehab const struct hwmon_chip_info *info, 40*7ebd8b66SMauro Carvalho Chehab const struct attribute_group **extra_groups); 41*7ebd8b66SMauro Carvalho Chehab 42*7ebd8b66SMauro Carvalho Chehab struct device * 43*7ebd8b66SMauro Carvalho Chehab devm_hwmon_device_register_with_info(struct device *dev, 44*7ebd8b66SMauro Carvalho Chehab const char *name, 45*7ebd8b66SMauro Carvalho Chehab void *drvdata, 46*7ebd8b66SMauro Carvalho Chehab const struct hwmon_chip_info *info, 47*7ebd8b66SMauro Carvalho Chehab const struct attribute_group **extra_groups); 48*7ebd8b66SMauro Carvalho Chehab 49*7ebd8b66SMauro Carvalho Chehab void hwmon_device_unregister(struct device *dev); 50*7ebd8b66SMauro Carvalho Chehab 51*7ebd8b66SMauro Carvalho Chehab void devm_hwmon_device_unregister(struct device *dev); 52*7ebd8b66SMauro Carvalho Chehab 53*7ebd8b66SMauro Carvalho Chehabhwmon_device_register_with_groups registers a hardware monitoring device. 54*7ebd8b66SMauro Carvalho ChehabThe first parameter of this function is a pointer to the parent device. 55*7ebd8b66SMauro Carvalho ChehabThe name parameter is a pointer to the hwmon device name. The registration 56*7ebd8b66SMauro Carvalho Chehabfunction wil create a name sysfs attribute pointing to this name. 57*7ebd8b66SMauro Carvalho ChehabThe drvdata parameter is the pointer to the local driver data. 58*7ebd8b66SMauro Carvalho Chehabhwmon_device_register_with_groups will attach this pointer to the newly 59*7ebd8b66SMauro Carvalho Chehaballocated hwmon device. The pointer can be retrieved by the driver using 60*7ebd8b66SMauro Carvalho Chehabdev_get_drvdata() on the hwmon device pointer. The groups parameter is 61*7ebd8b66SMauro Carvalho Chehaba pointer to a list of sysfs attribute groups. The list must be NULL terminated. 62*7ebd8b66SMauro Carvalho Chehabhwmon_device_register_with_groups creates the hwmon device with name attribute 63*7ebd8b66SMauro Carvalho Chehabas well as all sysfs attributes attached to the hwmon device. 64*7ebd8b66SMauro Carvalho ChehabThis function returns a pointer to the newly created hardware monitoring device 65*7ebd8b66SMauro Carvalho Chehabor PTR_ERR for failure. 66*7ebd8b66SMauro Carvalho Chehab 67*7ebd8b66SMauro Carvalho Chehabdevm_hwmon_device_register_with_groups is similar to 68*7ebd8b66SMauro Carvalho Chehabhwmon_device_register_with_groups. However, it is device managed, meaning the 69*7ebd8b66SMauro Carvalho Chehabhwmon device does not have to be removed explicitly by the removal function. 70*7ebd8b66SMauro Carvalho Chehab 71*7ebd8b66SMauro Carvalho Chehabhwmon_device_register_with_info is the most comprehensive and preferred means 72*7ebd8b66SMauro Carvalho Chehabto register a hardware monitoring device. It creates the standard sysfs 73*7ebd8b66SMauro Carvalho Chehabattributes in the hardware monitoring core, letting the driver focus on reading 74*7ebd8b66SMauro Carvalho Chehabfrom and writing to the chip instead of having to bother with sysfs attributes. 75*7ebd8b66SMauro Carvalho ChehabThe parent device parameter cannot be NULL with non-NULL chip info. Its 76*7ebd8b66SMauro Carvalho Chehabparameters are described in more detail below. 77*7ebd8b66SMauro Carvalho Chehab 78*7ebd8b66SMauro Carvalho Chehabdevm_hwmon_device_register_with_info is similar to 79*7ebd8b66SMauro Carvalho Chehabhwmon_device_register_with_info. However, it is device managed, meaning the 80*7ebd8b66SMauro Carvalho Chehabhwmon device does not have to be removed explicitly by the removal function. 81*7ebd8b66SMauro Carvalho Chehab 82*7ebd8b66SMauro Carvalho Chehabhwmon_device_unregister deregisters a registered hardware monitoring device. 83*7ebd8b66SMauro Carvalho ChehabThe parameter of this function is the pointer to the registered hardware 84*7ebd8b66SMauro Carvalho Chehabmonitoring device structure. This function must be called from the driver 85*7ebd8b66SMauro Carvalho Chehabremove function if the hardware monitoring device was registered with 86*7ebd8b66SMauro Carvalho Chehabhwmon_device_register_with_groups or hwmon_device_register_with_info. 87*7ebd8b66SMauro Carvalho Chehab 88*7ebd8b66SMauro Carvalho Chehabdevm_hwmon_device_unregister does not normally have to be called. It is only 89*7ebd8b66SMauro Carvalho Chehabneeded for error handling, and only needed if the driver probe fails after 90*7ebd8b66SMauro Carvalho Chehabthe call to devm_hwmon_device_register_with_groups or 91*7ebd8b66SMauro Carvalho Chehabhwmon_device_register_with_info and if the automatic (device managed) 92*7ebd8b66SMauro Carvalho Chehabremoval would be too late. 93*7ebd8b66SMauro Carvalho Chehab 94*7ebd8b66SMauro Carvalho ChehabAll supported hwmon device registration functions only accept valid device 95*7ebd8b66SMauro Carvalho Chehabnames. Device names including invalid characters (whitespace, '*', or '-') 96*7ebd8b66SMauro Carvalho Chehabwill be rejected. The 'name' parameter is mandatory. 97*7ebd8b66SMauro Carvalho Chehab 98*7ebd8b66SMauro Carvalho ChehabUsing devm_hwmon_device_register_with_info() 99*7ebd8b66SMauro Carvalho Chehab-------------------------------------------- 100*7ebd8b66SMauro Carvalho Chehab 101*7ebd8b66SMauro Carvalho Chehabhwmon_device_register_with_info() registers a hardware monitoring device. 102*7ebd8b66SMauro Carvalho ChehabThe parameters to this function are 103*7ebd8b66SMauro Carvalho Chehab 104*7ebd8b66SMauro Carvalho Chehab=============================================== =============================================== 105*7ebd8b66SMauro Carvalho Chehab`struct device *dev` Pointer to parent device 106*7ebd8b66SMauro Carvalho Chehab`const char *name` Device name 107*7ebd8b66SMauro Carvalho Chehab`void *drvdata` Driver private data 108*7ebd8b66SMauro Carvalho Chehab`const struct hwmon_chip_info *info` Pointer to chip description. 109*7ebd8b66SMauro Carvalho Chehab`const struct attribute_group **extra_groups` Null-terminated list of additional non-standard 110*7ebd8b66SMauro Carvalho Chehab sysfs attribute groups. 111*7ebd8b66SMauro Carvalho Chehab=============================================== =============================================== 112*7ebd8b66SMauro Carvalho Chehab 113*7ebd8b66SMauro Carvalho ChehabThis function returns a pointer to the created hardware monitoring device 114*7ebd8b66SMauro Carvalho Chehabon success and a negative error code for failure. 115*7ebd8b66SMauro Carvalho Chehab 116*7ebd8b66SMauro Carvalho ChehabThe hwmon_chip_info structure looks as follows:: 117*7ebd8b66SMauro Carvalho Chehab 118*7ebd8b66SMauro Carvalho Chehab struct hwmon_chip_info { 119*7ebd8b66SMauro Carvalho Chehab const struct hwmon_ops *ops; 120*7ebd8b66SMauro Carvalho Chehab const struct hwmon_channel_info **info; 121*7ebd8b66SMauro Carvalho Chehab }; 122*7ebd8b66SMauro Carvalho Chehab 123*7ebd8b66SMauro Carvalho ChehabIt contains the following fields: 124*7ebd8b66SMauro Carvalho Chehab 125*7ebd8b66SMauro Carvalho Chehab* ops: 126*7ebd8b66SMauro Carvalho Chehab Pointer to device operations. 127*7ebd8b66SMauro Carvalho Chehab* info: 128*7ebd8b66SMauro Carvalho Chehab NULL-terminated list of device channel descriptors. 129*7ebd8b66SMauro Carvalho Chehab 130*7ebd8b66SMauro Carvalho ChehabThe list of hwmon operations is defined as:: 131*7ebd8b66SMauro Carvalho Chehab 132*7ebd8b66SMauro Carvalho Chehab struct hwmon_ops { 133*7ebd8b66SMauro Carvalho Chehab umode_t (*is_visible)(const void *, enum hwmon_sensor_types type, 134*7ebd8b66SMauro Carvalho Chehab u32 attr, int); 135*7ebd8b66SMauro Carvalho Chehab int (*read)(struct device *, enum hwmon_sensor_types type, 136*7ebd8b66SMauro Carvalho Chehab u32 attr, int, long *); 137*7ebd8b66SMauro Carvalho Chehab int (*write)(struct device *, enum hwmon_sensor_types type, 138*7ebd8b66SMauro Carvalho Chehab u32 attr, int, long); 139*7ebd8b66SMauro Carvalho Chehab }; 140*7ebd8b66SMauro Carvalho Chehab 141*7ebd8b66SMauro Carvalho ChehabIt defines the following operations. 142*7ebd8b66SMauro Carvalho Chehab 143*7ebd8b66SMauro Carvalho Chehab* is_visible: 144*7ebd8b66SMauro Carvalho Chehab Pointer to a function to return the file mode for each supported 145*7ebd8b66SMauro Carvalho Chehab attribute. This function is mandatory. 146*7ebd8b66SMauro Carvalho Chehab 147*7ebd8b66SMauro Carvalho Chehab* read: 148*7ebd8b66SMauro Carvalho Chehab Pointer to a function for reading a value from the chip. This function 149*7ebd8b66SMauro Carvalho Chehab is optional, but must be provided if any readable attributes exist. 150*7ebd8b66SMauro Carvalho Chehab 151*7ebd8b66SMauro Carvalho Chehab* write: 152*7ebd8b66SMauro Carvalho Chehab Pointer to a function for writing a value to the chip. This function is 153*7ebd8b66SMauro Carvalho Chehab optional, but must be provided if any writeable attributes exist. 154*7ebd8b66SMauro Carvalho Chehab 155*7ebd8b66SMauro Carvalho ChehabEach sensor channel is described with struct hwmon_channel_info, which is 156*7ebd8b66SMauro Carvalho Chehabdefined as follows:: 157*7ebd8b66SMauro Carvalho Chehab 158*7ebd8b66SMauro Carvalho Chehab struct hwmon_channel_info { 159*7ebd8b66SMauro Carvalho Chehab enum hwmon_sensor_types type; 160*7ebd8b66SMauro Carvalho Chehab u32 *config; 161*7ebd8b66SMauro Carvalho Chehab }; 162*7ebd8b66SMauro Carvalho Chehab 163*7ebd8b66SMauro Carvalho ChehabIt contains following fields: 164*7ebd8b66SMauro Carvalho Chehab 165*7ebd8b66SMauro Carvalho Chehab* type: 166*7ebd8b66SMauro Carvalho Chehab The hardware monitoring sensor type. 167*7ebd8b66SMauro Carvalho Chehab 168*7ebd8b66SMauro Carvalho Chehab Supported sensor types are 169*7ebd8b66SMauro Carvalho Chehab 170*7ebd8b66SMauro Carvalho Chehab ================== ================================================== 171*7ebd8b66SMauro Carvalho Chehab hwmon_chip A virtual sensor type, used to describe attributes 172*7ebd8b66SMauro Carvalho Chehab which are not bound to a specific input or output 173*7ebd8b66SMauro Carvalho Chehab hwmon_temp Temperature sensor 174*7ebd8b66SMauro Carvalho Chehab hwmon_in Voltage sensor 175*7ebd8b66SMauro Carvalho Chehab hwmon_curr Current sensor 176*7ebd8b66SMauro Carvalho Chehab hwmon_power Power sensor 177*7ebd8b66SMauro Carvalho Chehab hwmon_energy Energy sensor 178*7ebd8b66SMauro Carvalho Chehab hwmon_humidity Humidity sensor 179*7ebd8b66SMauro Carvalho Chehab hwmon_fan Fan speed sensor 180*7ebd8b66SMauro Carvalho Chehab hwmon_pwm PWM control 181*7ebd8b66SMauro Carvalho Chehab ================== ================================================== 182*7ebd8b66SMauro Carvalho Chehab 183*7ebd8b66SMauro Carvalho Chehab* config: 184*7ebd8b66SMauro Carvalho Chehab Pointer to a 0-terminated list of configuration values for each 185*7ebd8b66SMauro Carvalho Chehab sensor of the given type. Each value is a combination of bit values 186*7ebd8b66SMauro Carvalho Chehab describing the attributes supposed by a single sensor. 187*7ebd8b66SMauro Carvalho Chehab 188*7ebd8b66SMauro Carvalho ChehabAs an example, here is the complete description file for a LM75 compatible 189*7ebd8b66SMauro Carvalho Chehabsensor chip. The chip has a single temperature sensor. The driver wants to 190*7ebd8b66SMauro Carvalho Chehabregister with the thermal subsystem (HWMON_C_REGISTER_TZ), and it supports 191*7ebd8b66SMauro Carvalho Chehabthe update_interval attribute (HWMON_C_UPDATE_INTERVAL). The chip supports 192*7ebd8b66SMauro Carvalho Chehabreading the temperature (HWMON_T_INPUT), it has a maximum temperature 193*7ebd8b66SMauro Carvalho Chehabregister (HWMON_T_MAX) as well as a maximum temperature hysteresis register 194*7ebd8b66SMauro Carvalho Chehab(HWMON_T_MAX_HYST):: 195*7ebd8b66SMauro Carvalho Chehab 196*7ebd8b66SMauro Carvalho Chehab static const u32 lm75_chip_config[] = { 197*7ebd8b66SMauro Carvalho Chehab HWMON_C_REGISTER_TZ | HWMON_C_UPDATE_INTERVAL, 198*7ebd8b66SMauro Carvalho Chehab 0 199*7ebd8b66SMauro Carvalho Chehab }; 200*7ebd8b66SMauro Carvalho Chehab 201*7ebd8b66SMauro Carvalho Chehab static const struct hwmon_channel_info lm75_chip = { 202*7ebd8b66SMauro Carvalho Chehab .type = hwmon_chip, 203*7ebd8b66SMauro Carvalho Chehab .config = lm75_chip_config, 204*7ebd8b66SMauro Carvalho Chehab }; 205*7ebd8b66SMauro Carvalho Chehab 206*7ebd8b66SMauro Carvalho Chehab static const u32 lm75_temp_config[] = { 207*7ebd8b66SMauro Carvalho Chehab HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MAX_HYST, 208*7ebd8b66SMauro Carvalho Chehab 0 209*7ebd8b66SMauro Carvalho Chehab }; 210*7ebd8b66SMauro Carvalho Chehab 211*7ebd8b66SMauro Carvalho Chehab static const struct hwmon_channel_info lm75_temp = { 212*7ebd8b66SMauro Carvalho Chehab .type = hwmon_temp, 213*7ebd8b66SMauro Carvalho Chehab .config = lm75_temp_config, 214*7ebd8b66SMauro Carvalho Chehab }; 215*7ebd8b66SMauro Carvalho Chehab 216*7ebd8b66SMauro Carvalho Chehab static const struct hwmon_channel_info *lm75_info[] = { 217*7ebd8b66SMauro Carvalho Chehab &lm75_chip, 218*7ebd8b66SMauro Carvalho Chehab &lm75_temp, 219*7ebd8b66SMauro Carvalho Chehab NULL 220*7ebd8b66SMauro Carvalho Chehab }; 221*7ebd8b66SMauro Carvalho Chehab 222*7ebd8b66SMauro Carvalho Chehab The HWMON_CHANNEL_INFO() macro can and should be used when possible. 223*7ebd8b66SMauro Carvalho Chehab With this macro, the above example can be simplified to 224*7ebd8b66SMauro Carvalho Chehab 225*7ebd8b66SMauro Carvalho Chehab static const struct hwmon_channel_info *lm75_info[] = { 226*7ebd8b66SMauro Carvalho Chehab HWMON_CHANNEL_INFO(chip, 227*7ebd8b66SMauro Carvalho Chehab HWMON_C_REGISTER_TZ | HWMON_C_UPDATE_INTERVAL), 228*7ebd8b66SMauro Carvalho Chehab HWMON_CHANNEL_INFO(temp, 229*7ebd8b66SMauro Carvalho Chehab HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MAX_HYST), 230*7ebd8b66SMauro Carvalho Chehab NULL 231*7ebd8b66SMauro Carvalho Chehab }; 232*7ebd8b66SMauro Carvalho Chehab 233*7ebd8b66SMauro Carvalho Chehab The remaining declarations are as follows. 234*7ebd8b66SMauro Carvalho Chehab 235*7ebd8b66SMauro Carvalho Chehab static const struct hwmon_ops lm75_hwmon_ops = { 236*7ebd8b66SMauro Carvalho Chehab .is_visible = lm75_is_visible, 237*7ebd8b66SMauro Carvalho Chehab .read = lm75_read, 238*7ebd8b66SMauro Carvalho Chehab .write = lm75_write, 239*7ebd8b66SMauro Carvalho Chehab }; 240*7ebd8b66SMauro Carvalho Chehab 241*7ebd8b66SMauro Carvalho Chehab static const struct hwmon_chip_info lm75_chip_info = { 242*7ebd8b66SMauro Carvalho Chehab .ops = &lm75_hwmon_ops, 243*7ebd8b66SMauro Carvalho Chehab .info = lm75_info, 244*7ebd8b66SMauro Carvalho Chehab }; 245*7ebd8b66SMauro Carvalho Chehab 246*7ebd8b66SMauro Carvalho ChehabA complete list of bit values indicating individual attribute support 247*7ebd8b66SMauro Carvalho Chehabis defined in include/linux/hwmon.h. Definition prefixes are as follows. 248*7ebd8b66SMauro Carvalho Chehab 249*7ebd8b66SMauro Carvalho Chehab=============== ================================================= 250*7ebd8b66SMauro Carvalho ChehabHWMON_C_xxxx Chip attributes, for use with hwmon_chip. 251*7ebd8b66SMauro Carvalho ChehabHWMON_T_xxxx Temperature attributes, for use with hwmon_temp. 252*7ebd8b66SMauro Carvalho ChehabHWMON_I_xxxx Voltage attributes, for use with hwmon_in. 253*7ebd8b66SMauro Carvalho ChehabHWMON_C_xxxx Current attributes, for use with hwmon_curr. 254*7ebd8b66SMauro Carvalho Chehab Notice the prefix overlap with chip attributes. 255*7ebd8b66SMauro Carvalho ChehabHWMON_P_xxxx Power attributes, for use with hwmon_power. 256*7ebd8b66SMauro Carvalho ChehabHWMON_E_xxxx Energy attributes, for use with hwmon_energy. 257*7ebd8b66SMauro Carvalho ChehabHWMON_H_xxxx Humidity attributes, for use with hwmon_humidity. 258*7ebd8b66SMauro Carvalho ChehabHWMON_F_xxxx Fan speed attributes, for use with hwmon_fan. 259*7ebd8b66SMauro Carvalho ChehabHWMON_PWM_xxxx PWM control attributes, for use with hwmon_pwm. 260*7ebd8b66SMauro Carvalho Chehab=============== ================================================= 261*7ebd8b66SMauro Carvalho Chehab 262*7ebd8b66SMauro Carvalho ChehabDriver callback functions 263*7ebd8b66SMauro Carvalho Chehab------------------------- 264*7ebd8b66SMauro Carvalho Chehab 265*7ebd8b66SMauro Carvalho ChehabEach driver provides is_visible, read, and write functions. Parameters 266*7ebd8b66SMauro Carvalho Chehaband return values for those functions are as follows:: 267*7ebd8b66SMauro Carvalho Chehab 268*7ebd8b66SMauro Carvalho Chehab umode_t is_visible_func(const void *data, enum hwmon_sensor_types type, 269*7ebd8b66SMauro Carvalho Chehab u32 attr, int channel) 270*7ebd8b66SMauro Carvalho Chehab 271*7ebd8b66SMauro Carvalho ChehabParameters: 272*7ebd8b66SMauro Carvalho Chehab data: 273*7ebd8b66SMauro Carvalho Chehab Pointer to device private data structure. 274*7ebd8b66SMauro Carvalho Chehab type: 275*7ebd8b66SMauro Carvalho Chehab The sensor type. 276*7ebd8b66SMauro Carvalho Chehab attr: 277*7ebd8b66SMauro Carvalho Chehab Attribute identifier associated with a specific attribute. 278*7ebd8b66SMauro Carvalho Chehab For example, the attribute value for HWMON_T_INPUT would be 279*7ebd8b66SMauro Carvalho Chehab hwmon_temp_input. For complete mappings of bit fields to 280*7ebd8b66SMauro Carvalho Chehab attribute values please see include/linux/hwmon.h. 281*7ebd8b66SMauro Carvalho Chehab channel: 282*7ebd8b66SMauro Carvalho Chehab The sensor channel number. 283*7ebd8b66SMauro Carvalho Chehab 284*7ebd8b66SMauro Carvalho ChehabReturn value: 285*7ebd8b66SMauro Carvalho Chehab The file mode for this attribute. Typically, this will be 0 (the 286*7ebd8b66SMauro Carvalho Chehab attribute will not be created), S_IRUGO, or 'S_IRUGO | S_IWUSR'. 287*7ebd8b66SMauro Carvalho Chehab 288*7ebd8b66SMauro Carvalho Chehab:: 289*7ebd8b66SMauro Carvalho Chehab 290*7ebd8b66SMauro Carvalho Chehab int read_func(struct device *dev, enum hwmon_sensor_types type, 291*7ebd8b66SMauro Carvalho Chehab u32 attr, int channel, long *val) 292*7ebd8b66SMauro Carvalho Chehab 293*7ebd8b66SMauro Carvalho ChehabParameters: 294*7ebd8b66SMauro Carvalho Chehab dev: 295*7ebd8b66SMauro Carvalho Chehab Pointer to the hardware monitoring device. 296*7ebd8b66SMauro Carvalho Chehab type: 297*7ebd8b66SMauro Carvalho Chehab The sensor type. 298*7ebd8b66SMauro Carvalho Chehab attr: 299*7ebd8b66SMauro Carvalho Chehab Attribute identifier associated with a specific attribute. 300*7ebd8b66SMauro Carvalho Chehab For example, the attribute value for HWMON_T_INPUT would be 301*7ebd8b66SMauro Carvalho Chehab hwmon_temp_input. For complete mappings please see 302*7ebd8b66SMauro Carvalho Chehab include/linux/hwmon.h. 303*7ebd8b66SMauro Carvalho Chehab channel: 304*7ebd8b66SMauro Carvalho Chehab The sensor channel number. 305*7ebd8b66SMauro Carvalho Chehab val: 306*7ebd8b66SMauro Carvalho Chehab Pointer to attribute value. 307*7ebd8b66SMauro Carvalho Chehab 308*7ebd8b66SMauro Carvalho ChehabReturn value: 309*7ebd8b66SMauro Carvalho Chehab 0 on success, a negative error number otherwise. 310*7ebd8b66SMauro Carvalho Chehab 311*7ebd8b66SMauro Carvalho Chehab:: 312*7ebd8b66SMauro Carvalho Chehab 313*7ebd8b66SMauro Carvalho Chehab int write_func(struct device *dev, enum hwmon_sensor_types type, 314*7ebd8b66SMauro Carvalho Chehab u32 attr, int channel, long val) 315*7ebd8b66SMauro Carvalho Chehab 316*7ebd8b66SMauro Carvalho ChehabParameters: 317*7ebd8b66SMauro Carvalho Chehab dev: 318*7ebd8b66SMauro Carvalho Chehab Pointer to the hardware monitoring device. 319*7ebd8b66SMauro Carvalho Chehab type: 320*7ebd8b66SMauro Carvalho Chehab The sensor type. 321*7ebd8b66SMauro Carvalho Chehab attr: 322*7ebd8b66SMauro Carvalho Chehab Attribute identifier associated with a specific attribute. 323*7ebd8b66SMauro Carvalho Chehab For example, the attribute value for HWMON_T_INPUT would be 324*7ebd8b66SMauro Carvalho Chehab hwmon_temp_input. For complete mappings please see 325*7ebd8b66SMauro Carvalho Chehab include/linux/hwmon.h. 326*7ebd8b66SMauro Carvalho Chehab channel: 327*7ebd8b66SMauro Carvalho Chehab The sensor channel number. 328*7ebd8b66SMauro Carvalho Chehab val: 329*7ebd8b66SMauro Carvalho Chehab The value to write to the chip. 330*7ebd8b66SMauro Carvalho Chehab 331*7ebd8b66SMauro Carvalho ChehabReturn value: 332*7ebd8b66SMauro Carvalho Chehab 0 on success, a negative error number otherwise. 333*7ebd8b66SMauro Carvalho Chehab 334*7ebd8b66SMauro Carvalho Chehab 335*7ebd8b66SMauro Carvalho ChehabDriver-provided sysfs attributes 336*7ebd8b66SMauro Carvalho Chehab-------------------------------- 337*7ebd8b66SMauro Carvalho Chehab 338*7ebd8b66SMauro Carvalho ChehabIf the hardware monitoring device is registered with 339*7ebd8b66SMauro Carvalho Chehabhwmon_device_register_with_info or devm_hwmon_device_register_with_info, 340*7ebd8b66SMauro Carvalho Chehabit is most likely not necessary to provide sysfs attributes. Only additional 341*7ebd8b66SMauro Carvalho Chehabnon-standard sysfs attributes need to be provided when one of those registration 342*7ebd8b66SMauro Carvalho Chehabfunctions is used. 343*7ebd8b66SMauro Carvalho Chehab 344*7ebd8b66SMauro Carvalho ChehabThe header file linux/hwmon-sysfs.h provides a number of useful macros to 345*7ebd8b66SMauro Carvalho Chehabdeclare and use hardware monitoring sysfs attributes. 346*7ebd8b66SMauro Carvalho Chehab 347*7ebd8b66SMauro Carvalho ChehabIn many cases, you can use the exsting define DEVICE_ATTR or its variants 348*7ebd8b66SMauro Carvalho ChehabDEVICE_ATTR_{RW,RO,WO} to declare such attributes. This is feasible if an 349*7ebd8b66SMauro Carvalho Chehabattribute has no additional context. However, in many cases there will be 350*7ebd8b66SMauro Carvalho Chehabadditional information such as a sensor index which will need to be passed 351*7ebd8b66SMauro Carvalho Chehabto the sysfs attribute handling function. 352*7ebd8b66SMauro Carvalho Chehab 353*7ebd8b66SMauro Carvalho ChehabSENSOR_DEVICE_ATTR and SENSOR_DEVICE_ATTR_2 can be used to define attributes 354*7ebd8b66SMauro Carvalho Chehabwhich need such additional context information. SENSOR_DEVICE_ATTR requires 355*7ebd8b66SMauro Carvalho Chehabone additional argument, SENSOR_DEVICE_ATTR_2 requires two. 356*7ebd8b66SMauro Carvalho Chehab 357*7ebd8b66SMauro Carvalho ChehabSimplified variants of SENSOR_DEVICE_ATTR and SENSOR_DEVICE_ATTR_2 are available 358*7ebd8b66SMauro Carvalho Chehaband should be used if standard attribute permissions and function names are 359*7ebd8b66SMauro Carvalho Chehabfeasible. Standard permissions are 0644 for SENSOR_DEVICE_ATTR[_2]_RW, 360*7ebd8b66SMauro Carvalho Chehab0444 for SENSOR_DEVICE_ATTR[_2]_RO, and 0200 for SENSOR_DEVICE_ATTR[_2]_WO. 361*7ebd8b66SMauro Carvalho ChehabStandard functions, similar to DEVICE_ATTR_{RW,RO,WO}, have _show and _store 362*7ebd8b66SMauro Carvalho Chehabappended to the provided function name. 363*7ebd8b66SMauro Carvalho Chehab 364*7ebd8b66SMauro Carvalho ChehabSENSOR_DEVICE_ATTR and its variants define a struct sensor_device_attribute 365*7ebd8b66SMauro Carvalho Chehabvariable. This structure has the following fields:: 366*7ebd8b66SMauro Carvalho Chehab 367*7ebd8b66SMauro Carvalho Chehab struct sensor_device_attribute { 368*7ebd8b66SMauro Carvalho Chehab struct device_attribute dev_attr; 369*7ebd8b66SMauro Carvalho Chehab int index; 370*7ebd8b66SMauro Carvalho Chehab }; 371*7ebd8b66SMauro Carvalho Chehab 372*7ebd8b66SMauro Carvalho ChehabYou can use to_sensor_dev_attr to get the pointer to this structure from the 373*7ebd8b66SMauro Carvalho Chehabattribute read or write function. Its parameter is the device to which the 374*7ebd8b66SMauro Carvalho Chehabattribute is attached. 375*7ebd8b66SMauro Carvalho Chehab 376*7ebd8b66SMauro Carvalho ChehabSENSOR_DEVICE_ATTR_2 and its variants define a struct sensor_device_attribute_2 377*7ebd8b66SMauro Carvalho Chehabvariable, which is defined as follows:: 378*7ebd8b66SMauro Carvalho Chehab 379*7ebd8b66SMauro Carvalho Chehab struct sensor_device_attribute_2 { 380*7ebd8b66SMauro Carvalho Chehab struct device_attribute dev_attr; 381*7ebd8b66SMauro Carvalho Chehab u8 index; 382*7ebd8b66SMauro Carvalho Chehab u8 nr; 383*7ebd8b66SMauro Carvalho Chehab }; 384*7ebd8b66SMauro Carvalho Chehab 385*7ebd8b66SMauro Carvalho ChehabUse to_sensor_dev_attr_2 to get the pointer to this structure. Its parameter 386*7ebd8b66SMauro Carvalho Chehabis the device to which the attribute is attached. 387