xref: /linux/Documentation/hwmon/hwmon-kernel-api.rst (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
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-------
22*aededf87SGuenter RoeckEach hardware monitoring driver must #include <linux/hwmon.h> and, in some
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_info(struct device *dev,
287ebd8b66SMauro Carvalho Chehab				  const char *name, void *drvdata,
297ebd8b66SMauro Carvalho Chehab				  const struct hwmon_chip_info *info,
307ebd8b66SMauro Carvalho Chehab				  const struct attribute_group **extra_groups);
317ebd8b66SMauro Carvalho Chehab
327ebd8b66SMauro Carvalho Chehab  struct device *
337ebd8b66SMauro Carvalho Chehab  devm_hwmon_device_register_with_info(struct device *dev,
347ebd8b66SMauro Carvalho Chehab				       const char *name,
357ebd8b66SMauro Carvalho Chehab				       void *drvdata,
367ebd8b66SMauro Carvalho Chehab				       const struct hwmon_chip_info *info,
377ebd8b66SMauro Carvalho Chehab				       const struct attribute_group **extra_groups);
387ebd8b66SMauro Carvalho Chehab
397ebd8b66SMauro Carvalho Chehab  void hwmon_device_unregister(struct device *dev);
407ebd8b66SMauro Carvalho Chehab
411ad6c3b7SMichael Walle  char *hwmon_sanitize_name(const char *name);
421ad6c3b7SMichael Walle
431ad6c3b7SMichael Walle  char *devm_hwmon_sanitize_name(struct device *dev, const char *name);
441ad6c3b7SMichael Walle
45*aededf87SGuenter Roeckhwmon_device_register_with_info registers a hardware monitoring device.
46*aededf87SGuenter RoeckIt creates the standard sysfs attributes in the hardware monitoring core,
47*aededf87SGuenter Roeckletting the driver focus on reading from and writing to the chip instead
48*aededf87SGuenter Roeckof having to bother with sysfs attributes. The parent device parameter
49*aededf87SGuenter Roeckas well as the chip parameter must not be NULL. Its parameters are described
50*aededf87SGuenter Roeckin more detail below.
517ebd8b66SMauro Carvalho Chehab
527ebd8b66SMauro Carvalho Chehabdevm_hwmon_device_register_with_info is similar to
537ebd8b66SMauro Carvalho Chehabhwmon_device_register_with_info. However, it is device managed, meaning the
547ebd8b66SMauro Carvalho Chehabhwmon device does not have to be removed explicitly by the removal function.
557ebd8b66SMauro Carvalho Chehab
56*aededf87SGuenter RoeckAll other hardware monitoring device registration functions are deprecated
57*aededf87SGuenter Roeckand must not be used in new drivers.
58*aededf87SGuenter Roeck
597ebd8b66SMauro Carvalho Chehabhwmon_device_unregister deregisters a registered hardware monitoring device.
607ebd8b66SMauro Carvalho ChehabThe parameter of this function is the pointer to the registered hardware
617ebd8b66SMauro Carvalho Chehabmonitoring device structure. This function must be called from the driver
627ebd8b66SMauro Carvalho Chehabremove function if the hardware monitoring device was registered with
63*aededf87SGuenter Roeckhwmon_device_register_with_info.
647ebd8b66SMauro Carvalho Chehab
657ebd8b66SMauro Carvalho ChehabAll supported hwmon device registration functions only accept valid device
667ebd8b66SMauro Carvalho Chehabnames. Device names including invalid characters (whitespace, '*', or '-')
677ebd8b66SMauro Carvalho Chehabwill be rejected. The 'name' parameter is mandatory.
687ebd8b66SMauro Carvalho Chehab
691ad6c3b7SMichael WalleIf the driver doesn't use a static device name (for example it uses
701ad6c3b7SMichael Walledev_name()), and therefore cannot make sure the name only contains valid
711ad6c3b7SMichael Wallecharacters, hwmon_sanitize_name can be used. This convenience function
721ad6c3b7SMichael Wallewill duplicate the string and replace any invalid characters with an
731ad6c3b7SMichael Walleunderscore. It will allocate memory for the new string and it is the
741ad6c3b7SMichael Walleresponsibility of the caller to release the memory when the device is
751ad6c3b7SMichael Walleremoved.
761ad6c3b7SMichael Walle
771ad6c3b7SMichael Walledevm_hwmon_sanitize_name is the resource managed version of
781ad6c3b7SMichael Wallehwmon_sanitize_name; the memory will be freed automatically on device
791ad6c3b7SMichael Walleremoval.
801ad6c3b7SMichael Walle
817ebd8b66SMauro Carvalho ChehabUsing devm_hwmon_device_register_with_info()
827ebd8b66SMauro Carvalho Chehab--------------------------------------------
837ebd8b66SMauro Carvalho Chehab
847ebd8b66SMauro Carvalho Chehabhwmon_device_register_with_info() registers a hardware monitoring device.
857ebd8b66SMauro Carvalho ChehabThe parameters to this function are
867ebd8b66SMauro Carvalho Chehab
877ebd8b66SMauro Carvalho Chehab=============================================== ===============================================
887ebd8b66SMauro Carvalho Chehab`struct device *dev`				Pointer to parent device
897ebd8b66SMauro Carvalho Chehab`const char *name`				Device name
907ebd8b66SMauro Carvalho Chehab`void *drvdata`					Driver private data
917ebd8b66SMauro Carvalho Chehab`const struct hwmon_chip_info *info`		Pointer to chip description.
927ebd8b66SMauro Carvalho Chehab`const struct attribute_group **extra_groups` 	Null-terminated list of additional non-standard
937ebd8b66SMauro Carvalho Chehab						sysfs attribute groups.
947ebd8b66SMauro Carvalho Chehab=============================================== ===============================================
957ebd8b66SMauro Carvalho Chehab
967ebd8b66SMauro Carvalho ChehabThis function returns a pointer to the created hardware monitoring device
977ebd8b66SMauro Carvalho Chehabon success and a negative error code for failure.
987ebd8b66SMauro Carvalho Chehab
997ebd8b66SMauro Carvalho ChehabThe hwmon_chip_info structure looks as follows::
1007ebd8b66SMauro Carvalho Chehab
1017ebd8b66SMauro Carvalho Chehab	struct hwmon_chip_info {
1027ebd8b66SMauro Carvalho Chehab		const struct hwmon_ops *ops;
103d8cc9415SKrzysztof Kozlowski		const struct hwmon_channel_info * const *info;
1047ebd8b66SMauro Carvalho Chehab	};
1057ebd8b66SMauro Carvalho Chehab
1067ebd8b66SMauro Carvalho ChehabIt contains the following fields:
1077ebd8b66SMauro Carvalho Chehab
1087ebd8b66SMauro Carvalho Chehab* ops:
1097ebd8b66SMauro Carvalho Chehab	Pointer to device operations.
1107ebd8b66SMauro Carvalho Chehab* info:
1117ebd8b66SMauro Carvalho Chehab	NULL-terminated list of device channel descriptors.
1127ebd8b66SMauro Carvalho Chehab
1137ebd8b66SMauro Carvalho ChehabThe list of hwmon operations is defined as::
1147ebd8b66SMauro Carvalho Chehab
1157ebd8b66SMauro Carvalho Chehab  struct hwmon_ops {
1167ebd8b66SMauro Carvalho Chehab	umode_t (*is_visible)(const void *, enum hwmon_sensor_types type,
1177ebd8b66SMauro Carvalho Chehab			      u32 attr, int);
1187ebd8b66SMauro Carvalho Chehab	int (*read)(struct device *, enum hwmon_sensor_types type,
1197ebd8b66SMauro Carvalho Chehab		    u32 attr, int, long *);
1207ebd8b66SMauro Carvalho Chehab	int (*write)(struct device *, enum hwmon_sensor_types type,
1217ebd8b66SMauro Carvalho Chehab		     u32 attr, int, long);
1227ebd8b66SMauro Carvalho Chehab  };
1237ebd8b66SMauro Carvalho Chehab
1247ebd8b66SMauro Carvalho ChehabIt defines the following operations.
1257ebd8b66SMauro Carvalho Chehab
1267ebd8b66SMauro Carvalho Chehab* is_visible:
1277ebd8b66SMauro Carvalho Chehab    Pointer to a function to return the file mode for each supported
1287ebd8b66SMauro Carvalho Chehab    attribute. This function is mandatory.
1297ebd8b66SMauro Carvalho Chehab
1307ebd8b66SMauro Carvalho Chehab* read:
1317ebd8b66SMauro Carvalho Chehab    Pointer to a function for reading a value from the chip. This function
1327ebd8b66SMauro Carvalho Chehab    is optional, but must be provided if any readable attributes exist.
1337ebd8b66SMauro Carvalho Chehab
1347ebd8b66SMauro Carvalho Chehab* write:
1357ebd8b66SMauro Carvalho Chehab    Pointer to a function for writing a value to the chip. This function is
1367ebd8b66SMauro Carvalho Chehab    optional, but must be provided if any writeable attributes exist.
1377ebd8b66SMauro Carvalho Chehab
1387ebd8b66SMauro Carvalho ChehabEach sensor channel is described with struct hwmon_channel_info, which is
1397ebd8b66SMauro Carvalho Chehabdefined as follows::
1407ebd8b66SMauro Carvalho Chehab
1417ebd8b66SMauro Carvalho Chehab	struct hwmon_channel_info {
1427ebd8b66SMauro Carvalho Chehab		enum hwmon_sensor_types type;
1437ebd8b66SMauro Carvalho Chehab		u32 *config;
1447ebd8b66SMauro Carvalho Chehab	};
1457ebd8b66SMauro Carvalho Chehab
1467ebd8b66SMauro Carvalho ChehabIt contains following fields:
1477ebd8b66SMauro Carvalho Chehab
1487ebd8b66SMauro Carvalho Chehab* type:
1497ebd8b66SMauro Carvalho Chehab    The hardware monitoring sensor type.
1507ebd8b66SMauro Carvalho Chehab
1517ebd8b66SMauro Carvalho Chehab    Supported sensor types are
1527ebd8b66SMauro Carvalho Chehab
1537ebd8b66SMauro Carvalho Chehab     ================== ==================================================
1547ebd8b66SMauro Carvalho Chehab     hwmon_chip		A virtual sensor type, used to describe attributes
1557ebd8b66SMauro Carvalho Chehab			which are not bound to a specific input or output
1567ebd8b66SMauro Carvalho Chehab     hwmon_temp		Temperature sensor
1577ebd8b66SMauro Carvalho Chehab     hwmon_in		Voltage sensor
1587ebd8b66SMauro Carvalho Chehab     hwmon_curr		Current sensor
1597ebd8b66SMauro Carvalho Chehab     hwmon_power		Power sensor
1607ebd8b66SMauro Carvalho Chehab     hwmon_energy	Energy sensor
1617ebd8b66SMauro Carvalho Chehab     hwmon_humidity	Humidity sensor
1627ebd8b66SMauro Carvalho Chehab     hwmon_fan		Fan speed sensor
1637ebd8b66SMauro Carvalho Chehab     hwmon_pwm		PWM control
1647ebd8b66SMauro Carvalho Chehab     ================== ==================================================
1657ebd8b66SMauro Carvalho Chehab
1667ebd8b66SMauro Carvalho Chehab* config:
1677ebd8b66SMauro Carvalho Chehab    Pointer to a 0-terminated list of configuration values for each
1687ebd8b66SMauro Carvalho Chehab    sensor of the given type. Each value is a combination of bit values
1697ebd8b66SMauro Carvalho Chehab    describing the attributes supposed by a single sensor.
1707ebd8b66SMauro Carvalho Chehab
1717ebd8b66SMauro Carvalho ChehabAs an example, here is the complete description file for a LM75 compatible
1727ebd8b66SMauro Carvalho Chehabsensor chip. The chip has a single temperature sensor. The driver wants to
1737ebd8b66SMauro Carvalho Chehabregister with the thermal subsystem (HWMON_C_REGISTER_TZ), and it supports
1747ebd8b66SMauro Carvalho Chehabthe update_interval attribute (HWMON_C_UPDATE_INTERVAL). The chip supports
1757ebd8b66SMauro Carvalho Chehabreading the temperature (HWMON_T_INPUT), it has a maximum temperature
1767ebd8b66SMauro Carvalho Chehabregister (HWMON_T_MAX) as well as a maximum temperature hysteresis register
1777ebd8b66SMauro Carvalho Chehab(HWMON_T_MAX_HYST)::
1787ebd8b66SMauro Carvalho Chehab
1797ebd8b66SMauro Carvalho Chehab	static const u32 lm75_chip_config[] = {
1807ebd8b66SMauro Carvalho Chehab		HWMON_C_REGISTER_TZ | HWMON_C_UPDATE_INTERVAL,
1817ebd8b66SMauro Carvalho Chehab		0
1827ebd8b66SMauro Carvalho Chehab	};
1837ebd8b66SMauro Carvalho Chehab
1847ebd8b66SMauro Carvalho Chehab	static const struct hwmon_channel_info lm75_chip = {
1857ebd8b66SMauro Carvalho Chehab		.type = hwmon_chip,
1867ebd8b66SMauro Carvalho Chehab		.config = lm75_chip_config,
1877ebd8b66SMauro Carvalho Chehab	};
1887ebd8b66SMauro Carvalho Chehab
1897ebd8b66SMauro Carvalho Chehab	static const u32 lm75_temp_config[] = {
1907ebd8b66SMauro Carvalho Chehab		HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MAX_HYST,
1917ebd8b66SMauro Carvalho Chehab		0
1927ebd8b66SMauro Carvalho Chehab	};
1937ebd8b66SMauro Carvalho Chehab
1947ebd8b66SMauro Carvalho Chehab	static const struct hwmon_channel_info lm75_temp = {
1957ebd8b66SMauro Carvalho Chehab		.type = hwmon_temp,
1967ebd8b66SMauro Carvalho Chehab		.config = lm75_temp_config,
1977ebd8b66SMauro Carvalho Chehab	};
1987ebd8b66SMauro Carvalho Chehab
199d8cc9415SKrzysztof Kozlowski	static const struct hwmon_channel_info * const lm75_info[] = {
2007ebd8b66SMauro Carvalho Chehab		&lm75_chip,
2017ebd8b66SMauro Carvalho Chehab		&lm75_temp,
2027ebd8b66SMauro Carvalho Chehab		NULL
2037ebd8b66SMauro Carvalho Chehab	};
2047ebd8b66SMauro Carvalho Chehab
2057ebd8b66SMauro Carvalho Chehab	The HWMON_CHANNEL_INFO() macro can and should be used when possible.
2067ebd8b66SMauro Carvalho Chehab	With this macro, the above example can be simplified to
2077ebd8b66SMauro Carvalho Chehab
208d8cc9415SKrzysztof Kozlowski	static const struct hwmon_channel_info * const lm75_info[] = {
2097ebd8b66SMauro Carvalho Chehab		HWMON_CHANNEL_INFO(chip,
2107ebd8b66SMauro Carvalho Chehab				HWMON_C_REGISTER_TZ | HWMON_C_UPDATE_INTERVAL),
2117ebd8b66SMauro Carvalho Chehab		HWMON_CHANNEL_INFO(temp,
2127ebd8b66SMauro Carvalho Chehab				HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MAX_HYST),
2137ebd8b66SMauro Carvalho Chehab		NULL
2147ebd8b66SMauro Carvalho Chehab	};
2157ebd8b66SMauro Carvalho Chehab
2167ebd8b66SMauro Carvalho Chehab	The remaining declarations are as follows.
2177ebd8b66SMauro Carvalho Chehab
2187ebd8b66SMauro Carvalho Chehab	static const struct hwmon_ops lm75_hwmon_ops = {
2197ebd8b66SMauro Carvalho Chehab		.is_visible = lm75_is_visible,
2207ebd8b66SMauro Carvalho Chehab		.read = lm75_read,
2217ebd8b66SMauro Carvalho Chehab		.write = lm75_write,
2227ebd8b66SMauro Carvalho Chehab	};
2237ebd8b66SMauro Carvalho Chehab
2247ebd8b66SMauro Carvalho Chehab	static const struct hwmon_chip_info lm75_chip_info = {
2257ebd8b66SMauro Carvalho Chehab		.ops = &lm75_hwmon_ops,
2267ebd8b66SMauro Carvalho Chehab		.info = lm75_info,
2277ebd8b66SMauro Carvalho Chehab	};
2287ebd8b66SMauro Carvalho Chehab
2297ebd8b66SMauro Carvalho ChehabA complete list of bit values indicating individual attribute support
2307ebd8b66SMauro Carvalho Chehabis defined in include/linux/hwmon.h. Definition prefixes are as follows.
2317ebd8b66SMauro Carvalho Chehab
2327ebd8b66SMauro Carvalho Chehab=============== =================================================
2337ebd8b66SMauro Carvalho ChehabHWMON_C_xxxx	Chip attributes, for use with hwmon_chip.
2347ebd8b66SMauro Carvalho ChehabHWMON_T_xxxx	Temperature attributes, for use with hwmon_temp.
2357ebd8b66SMauro Carvalho ChehabHWMON_I_xxxx	Voltage attributes, for use with hwmon_in.
2367ebd8b66SMauro Carvalho ChehabHWMON_C_xxxx	Current attributes, for use with hwmon_curr.
2377ebd8b66SMauro Carvalho Chehab		Notice the prefix overlap with chip attributes.
2387ebd8b66SMauro Carvalho ChehabHWMON_P_xxxx	Power attributes, for use with hwmon_power.
2397ebd8b66SMauro Carvalho ChehabHWMON_E_xxxx	Energy attributes, for use with hwmon_energy.
2407ebd8b66SMauro Carvalho ChehabHWMON_H_xxxx	Humidity attributes, for use with hwmon_humidity.
2417ebd8b66SMauro Carvalho ChehabHWMON_F_xxxx	Fan speed attributes, for use with hwmon_fan.
2427ebd8b66SMauro Carvalho ChehabHWMON_PWM_xxxx	PWM control attributes, for use with hwmon_pwm.
2437ebd8b66SMauro Carvalho Chehab=============== =================================================
2447ebd8b66SMauro Carvalho Chehab
2457ebd8b66SMauro Carvalho ChehabDriver callback functions
2467ebd8b66SMauro Carvalho Chehab-------------------------
2477ebd8b66SMauro Carvalho Chehab
2487ebd8b66SMauro Carvalho ChehabEach driver provides is_visible, read, and write functions. Parameters
2497ebd8b66SMauro Carvalho Chehaband return values for those functions are as follows::
2507ebd8b66SMauro Carvalho Chehab
2517ebd8b66SMauro Carvalho Chehab  umode_t is_visible_func(const void *data, enum hwmon_sensor_types type,
2527ebd8b66SMauro Carvalho Chehab			  u32 attr, int channel)
2537ebd8b66SMauro Carvalho Chehab
2547ebd8b66SMauro Carvalho ChehabParameters:
2557ebd8b66SMauro Carvalho Chehab	data:
2567ebd8b66SMauro Carvalho Chehab		Pointer to device private data structure.
2577ebd8b66SMauro Carvalho Chehab	type:
2587ebd8b66SMauro Carvalho Chehab		The sensor type.
2597ebd8b66SMauro Carvalho Chehab	attr:
2607ebd8b66SMauro Carvalho Chehab		Attribute identifier associated with a specific attribute.
2617ebd8b66SMauro Carvalho Chehab		For example, the attribute value for HWMON_T_INPUT would be
2627ebd8b66SMauro Carvalho Chehab		hwmon_temp_input. For complete mappings of bit fields to
2637ebd8b66SMauro Carvalho Chehab		attribute values please see include/linux/hwmon.h.
2647ebd8b66SMauro Carvalho Chehab	channel:
2657ebd8b66SMauro Carvalho Chehab		The sensor channel number.
2667ebd8b66SMauro Carvalho Chehab
2677ebd8b66SMauro Carvalho ChehabReturn value:
2687ebd8b66SMauro Carvalho Chehab	The file mode for this attribute. Typically, this will be 0 (the
26995a56de6SJoaquín Ignacio Aramendía	attribute will not be created), 0444, or 0644.
2707ebd8b66SMauro Carvalho Chehab
2717ebd8b66SMauro Carvalho Chehab::
2727ebd8b66SMauro Carvalho Chehab
2737ebd8b66SMauro Carvalho Chehab	int read_func(struct device *dev, enum hwmon_sensor_types type,
2747ebd8b66SMauro Carvalho Chehab		      u32 attr, int channel, long *val)
2757ebd8b66SMauro Carvalho Chehab
2767ebd8b66SMauro Carvalho ChehabParameters:
2777ebd8b66SMauro Carvalho Chehab	dev:
2787ebd8b66SMauro Carvalho Chehab		Pointer to the hardware monitoring device.
2797ebd8b66SMauro Carvalho Chehab	type:
2807ebd8b66SMauro Carvalho Chehab		The sensor type.
2817ebd8b66SMauro Carvalho Chehab	attr:
2827ebd8b66SMauro Carvalho Chehab		Attribute identifier associated with a specific attribute.
2837ebd8b66SMauro Carvalho Chehab		For example, the attribute value for HWMON_T_INPUT would be
2847ebd8b66SMauro Carvalho Chehab		hwmon_temp_input. For complete mappings please see
2857ebd8b66SMauro Carvalho Chehab		include/linux/hwmon.h.
2867ebd8b66SMauro Carvalho Chehab	channel:
2877ebd8b66SMauro Carvalho Chehab		The sensor channel number.
2887ebd8b66SMauro Carvalho Chehab	val:
2897ebd8b66SMauro Carvalho Chehab		Pointer to attribute value.
2907ebd8b66SMauro Carvalho Chehab
2917ebd8b66SMauro Carvalho ChehabReturn value:
2927ebd8b66SMauro Carvalho Chehab	0 on success, a negative error number otherwise.
2937ebd8b66SMauro Carvalho Chehab
2947ebd8b66SMauro Carvalho Chehab::
2957ebd8b66SMauro Carvalho Chehab
2967ebd8b66SMauro Carvalho Chehab	int write_func(struct device *dev, enum hwmon_sensor_types type,
2977ebd8b66SMauro Carvalho Chehab		       u32 attr, int channel, long val)
2987ebd8b66SMauro Carvalho Chehab
2997ebd8b66SMauro Carvalho ChehabParameters:
3007ebd8b66SMauro Carvalho Chehab	dev:
3017ebd8b66SMauro Carvalho Chehab		Pointer to the hardware monitoring device.
3027ebd8b66SMauro Carvalho Chehab	type:
3037ebd8b66SMauro Carvalho Chehab		The sensor type.
3047ebd8b66SMauro Carvalho Chehab	attr:
3057ebd8b66SMauro Carvalho Chehab		Attribute identifier associated with a specific attribute.
3067ebd8b66SMauro Carvalho Chehab		For example, the attribute value for HWMON_T_INPUT would be
3077ebd8b66SMauro Carvalho Chehab		hwmon_temp_input. For complete mappings please see
3087ebd8b66SMauro Carvalho Chehab		include/linux/hwmon.h.
3097ebd8b66SMauro Carvalho Chehab	channel:
3107ebd8b66SMauro Carvalho Chehab		The sensor channel number.
3117ebd8b66SMauro Carvalho Chehab	val:
3127ebd8b66SMauro Carvalho Chehab		The value to write to the chip.
3137ebd8b66SMauro Carvalho Chehab
3147ebd8b66SMauro Carvalho ChehabReturn value:
3157ebd8b66SMauro Carvalho Chehab	0 on success, a negative error number otherwise.
3167ebd8b66SMauro Carvalho Chehab
3177ebd8b66SMauro Carvalho Chehab
3187ebd8b66SMauro Carvalho ChehabDriver-provided sysfs attributes
3197ebd8b66SMauro Carvalho Chehab--------------------------------
3207ebd8b66SMauro Carvalho Chehab
321*aededf87SGuenter RoeckIn most situations it should not be necessary for a driver to provide sysfs
322*aededf87SGuenter Roeckattributes since the hardware monitoring core creates those internally.
323*aededf87SGuenter RoeckOnly additional non-standard sysfs attributes need to be provided.
3247ebd8b66SMauro Carvalho Chehab
3257ebd8b66SMauro Carvalho ChehabThe header file linux/hwmon-sysfs.h provides a number of useful macros to
3267ebd8b66SMauro Carvalho Chehabdeclare and use hardware monitoring sysfs attributes.
3277ebd8b66SMauro Carvalho Chehab
32812087a36SRandy DunlapIn many cases, you can use the existing define DEVICE_ATTR or its variants
3297ebd8b66SMauro Carvalho ChehabDEVICE_ATTR_{RW,RO,WO} to declare such attributes. This is feasible if an
3307ebd8b66SMauro Carvalho Chehabattribute has no additional context. However, in many cases there will be
3317ebd8b66SMauro Carvalho Chehabadditional information such as a sensor index which will need to be passed
3327ebd8b66SMauro Carvalho Chehabto the sysfs attribute handling function.
3337ebd8b66SMauro Carvalho Chehab
3347ebd8b66SMauro Carvalho ChehabSENSOR_DEVICE_ATTR and SENSOR_DEVICE_ATTR_2 can be used to define attributes
3357ebd8b66SMauro Carvalho Chehabwhich need such additional context information. SENSOR_DEVICE_ATTR requires
3367ebd8b66SMauro Carvalho Chehabone additional argument, SENSOR_DEVICE_ATTR_2 requires two.
3377ebd8b66SMauro Carvalho Chehab
3387ebd8b66SMauro Carvalho ChehabSimplified variants of SENSOR_DEVICE_ATTR and SENSOR_DEVICE_ATTR_2 are available
3397ebd8b66SMauro Carvalho Chehaband should be used if standard attribute permissions and function names are
3407ebd8b66SMauro Carvalho Chehabfeasible. Standard permissions are 0644 for SENSOR_DEVICE_ATTR[_2]_RW,
3417ebd8b66SMauro Carvalho Chehab0444 for SENSOR_DEVICE_ATTR[_2]_RO, and 0200 for SENSOR_DEVICE_ATTR[_2]_WO.
3427ebd8b66SMauro Carvalho ChehabStandard functions, similar to DEVICE_ATTR_{RW,RO,WO}, have _show and _store
3437ebd8b66SMauro Carvalho Chehabappended to the provided function name.
3447ebd8b66SMauro Carvalho Chehab
3457ebd8b66SMauro Carvalho ChehabSENSOR_DEVICE_ATTR and its variants define a struct sensor_device_attribute
3467ebd8b66SMauro Carvalho Chehabvariable. This structure has the following fields::
3477ebd8b66SMauro Carvalho Chehab
3487ebd8b66SMauro Carvalho Chehab	struct sensor_device_attribute {
3497ebd8b66SMauro Carvalho Chehab		struct device_attribute dev_attr;
3507ebd8b66SMauro Carvalho Chehab		int index;
3517ebd8b66SMauro Carvalho Chehab	};
3527ebd8b66SMauro Carvalho Chehab
3537ebd8b66SMauro Carvalho ChehabYou can use to_sensor_dev_attr to get the pointer to this structure from the
3547ebd8b66SMauro Carvalho Chehabattribute read or write function. Its parameter is the device to which the
3557ebd8b66SMauro Carvalho Chehabattribute is attached.
3567ebd8b66SMauro Carvalho Chehab
3577ebd8b66SMauro Carvalho ChehabSENSOR_DEVICE_ATTR_2 and its variants define a struct sensor_device_attribute_2
3587ebd8b66SMauro Carvalho Chehabvariable, which is defined as follows::
3597ebd8b66SMauro Carvalho Chehab
3607ebd8b66SMauro Carvalho Chehab	struct sensor_device_attribute_2 {
3617ebd8b66SMauro Carvalho Chehab		struct device_attribute dev_attr;
3627ebd8b66SMauro Carvalho Chehab		u8 index;
3637ebd8b66SMauro Carvalho Chehab		u8 nr;
3647ebd8b66SMauro Carvalho Chehab	};
3657ebd8b66SMauro Carvalho Chehab
3667ebd8b66SMauro Carvalho ChehabUse to_sensor_dev_attr_2 to get the pointer to this structure. Its parameter
3677ebd8b66SMauro Carvalho Chehabis the device to which the attribute is attached.
368