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