linux/drivers/hwmon/hwmon.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * hwmon.c - part of lm_sensors, Linux kernel modules for hardware monitoring
 *
 * This file defines the sysfs class "hwmon", for use by sensors drivers.
 *
 * Copyright (C) 2005 Mark M. Hoffman <[email protected]>
 */

#define pr_fmt(fmt)

#include <linux/bitops.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/gfp.h>
#include <linux/hwmon.h>
#include <linux/i2c.h>
#include <linux/idr.h>
#include <linux/kstrtox.h>
#include <linux/list.h>
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/property.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/thermal.h>

#define CREATE_TRACE_POINTS
#include <trace/events/hwmon.h>

#define HWMON_ID_PREFIX
#define HWMON_ID_FORMAT

struct hwmon_device {};

#define to_hwmon_device(d)

#define MAX_SYSFS_ATTR_NAME_LENGTH

struct hwmon_device_attribute {};

#define to_hwmon_attr(d)
#define to_dev_attr(a)

/*
 * Thermal zone information
 */
struct hwmon_thermal_data {};

static ssize_t
name_show(struct device *dev, struct device_attribute *attr, char *buf)
{}
static DEVICE_ATTR_RO(name);

static ssize_t
label_show(struct device *dev, struct device_attribute *attr, char *buf)
{}
static DEVICE_ATTR_RO(label);

static struct attribute *hwmon_dev_attrs[] =;

static umode_t hwmon_dev_attr_is_visible(struct kobject *kobj,
					 struct attribute *attr, int n)
{}

static const struct attribute_group hwmon_dev_attr_group =;

static const struct attribute_group *hwmon_dev_attr_groups[] =;

static void hwmon_free_attrs(struct attribute **attrs)
{}

static void hwmon_dev_release(struct device *dev)
{}

static const struct class hwmon_class =;

static DEFINE_IDA(hwmon_ida);

/* Thermal zone handling */

/*
 * The complex conditional is necessary to avoid a cyclic dependency
 * between hwmon and thermal_sys modules.
 */
#ifdef CONFIG_THERMAL_OF
static int hwmon_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
{}

static int hwmon_thermal_set_trips(struct thermal_zone_device *tz, int low, int high)
{}

static const struct thermal_zone_device_ops hwmon_thermal_ops =;

static void hwmon_thermal_remove_sensor(void *data)
{}

static int hwmon_thermal_add_sensor(struct device *dev, int index)
{}

static int hwmon_thermal_register_sensors(struct device *dev)
{}

static void hwmon_thermal_notify(struct device *dev, int index)
{}

#else
static int hwmon_thermal_register_sensors(struct device *dev)
{
	return 0;
}

static void hwmon_thermal_notify(struct device *dev, int index) { }

#endif /* IS_REACHABLE(CONFIG_THERMAL) && ... */

static int hwmon_attr_base(enum hwmon_sensor_types type)
{}

#if IS_REACHABLE(CONFIG_I2C)

/*
 * PEC support
 *
 * The 'pec' attribute is attached to I2C client devices. It is only provided
 * if the i2c controller supports PEC.
 *
 * The mutex ensures that PEC configuration between i2c device and the hardware
 * is consistent. Use a single mutex because attribute writes are supposed to be
 * rare, and maintaining a separate mutex for each hardware monitoring device
 * would add substantial complexity to the driver for little if any gain.
 *
 * The hardware monitoring device is identified as child of the i2c client
 * device. This assumes that only a single hardware monitoring device is
 * attached to an i2c client device.
 */

static DEFINE_MUTEX(hwmon_pec_mutex);

static int hwmon_match_device(struct device *dev, void *data)
{}

static ssize_t pec_show(struct device *dev, struct device_attribute *dummy,
			char *buf)
{}

static ssize_t pec_store(struct device *dev, struct device_attribute *devattr,
			 const char *buf, size_t count)
{}

static DEVICE_ATTR_RW(pec);

static void hwmon_remove_pec(void *dev)
{}

static int hwmon_pec_register(struct device *hdev)
{}

#else /* CONFIG_I2C */
static int hwmon_pec_register(struct device *hdev)
{
	return -EINVAL;
}
#endif /* CONFIG_I2C */

/* sysfs attribute management */

static ssize_t hwmon_attr_show(struct device *dev,
			       struct device_attribute *devattr, char *buf)
{}

static ssize_t hwmon_attr_show_string(struct device *dev,
				      struct device_attribute *devattr,
				      char *buf)
{}

static ssize_t hwmon_attr_store(struct device *dev,
				struct device_attribute *devattr,
				const char *buf, size_t count)
{}

static bool is_string_attr(enum hwmon_sensor_types type, u32 attr)
{}

static struct attribute *hwmon_genattr(const void *drvdata,
				       enum hwmon_sensor_types type,
				       u32 attr,
				       int index,
				       const char *template,
				       const struct hwmon_ops *ops)
{}

/*
 * Chip attributes are not attribute templates but actual sysfs attributes.
 * See hwmon_genattr() for special handling.
 */
static const char * const hwmon_chip_attrs[] =;

static const char * const hwmon_temp_attr_templates[] =;

static const char * const hwmon_in_attr_templates[] =;

static const char * const hwmon_curr_attr_templates[] =;

static const char * const hwmon_power_attr_templates[] =;

static const char * const hwmon_energy_attr_templates[] =;

static const char * const hwmon_humidity_attr_templates[] =;

static const char * const hwmon_fan_attr_templates[] =;

static const char * const hwmon_pwm_attr_templates[] =;

static const char * const hwmon_intrusion_attr_templates[] =;

static const char * const *__templates[] =;

static const int __templates_size[] =;

int hwmon_notify_event(struct device *dev, enum hwmon_sensor_types type,
		       u32 attr, int channel)
{}
EXPORT_SYMBOL_GPL();

static int hwmon_num_channel_attrs(const struct hwmon_channel_info *info)
{}

static int hwmon_genattrs(const void *drvdata,
			  struct attribute **attrs,
			  const struct hwmon_ops *ops,
			  const struct hwmon_channel_info *info)
{}

static struct attribute **
__hwmon_create_attrs(const void *drvdata, const struct hwmon_chip_info *chip)
{}

static struct device *
__hwmon_device_register(struct device *dev, const char *name, void *drvdata,
			const struct hwmon_chip_info *chip,
			const struct attribute_group **groups)
{}

/**
 * hwmon_device_register_with_groups - register w/ hwmon
 * @dev: the parent device
 * @name: hwmon name attribute
 * @drvdata: driver data to attach to created device
 * @groups: List of attribute groups to create
 *
 * hwmon_device_unregister() must be called when the device is no
 * longer needed.
 *
 * Returns the pointer to the new device.
 */
struct device *
hwmon_device_register_with_groups(struct device *dev, const char *name,
				  void *drvdata,
				  const struct attribute_group **groups)
{}
EXPORT_SYMBOL_GPL();

/**
 * hwmon_device_register_with_info - register w/ hwmon
 * @dev: the parent device (mandatory)
 * @name: hwmon name attribute (mandatory)
 * @drvdata: driver data to attach to created device (optional)
 * @chip: pointer to hwmon chip information (mandatory)
 * @extra_groups: pointer to list of additional non-standard attribute groups
 *	(optional)
 *
 * hwmon_device_unregister() must be called when the device is no
 * longer needed.
 *
 * Returns the pointer to the new device.
 */
struct device *
hwmon_device_register_with_info(struct device *dev, const char *name,
				void *drvdata,
				const struct hwmon_chip_info *chip,
				const struct attribute_group **extra_groups)
{}
EXPORT_SYMBOL_GPL();

/**
 * hwmon_device_register_for_thermal - register hwmon device for thermal subsystem
 * @dev: the parent device
 * @name: hwmon name attribute
 * @drvdata: driver data to attach to created device
 *
 * The use of this function is restricted. It is provided for legacy reasons
 * and must only be called from the thermal subsystem.
 *
 * hwmon_device_unregister() must be called when the device is no
 * longer needed.
 *
 * Returns the pointer to the new device.
 */
struct device *
hwmon_device_register_for_thermal(struct device *dev, const char *name,
				  void *drvdata)
{}
EXPORT_SYMBOL_NS_GPL();

/**
 * hwmon_device_register - register w/ hwmon
 * @dev: the device to register
 *
 * hwmon_device_unregister() must be called when the device is no
 * longer needed.
 *
 * Returns the pointer to the new device.
 */
struct device *hwmon_device_register(struct device *dev)
{}
EXPORT_SYMBOL_GPL();

/**
 * hwmon_device_unregister - removes the previously registered class device
 *
 * @dev: the class device to destroy
 */
void hwmon_device_unregister(struct device *dev)
{}
EXPORT_SYMBOL_GPL();

static void devm_hwmon_release(struct device *dev, void *res)
{}

/**
 * devm_hwmon_device_register_with_groups - register w/ hwmon
 * @dev: the parent device
 * @name: hwmon name attribute
 * @drvdata: driver data to attach to created device
 * @groups: List of attribute groups to create
 *
 * Returns the pointer to the new device. The new device is automatically
 * unregistered with the parent device.
 */
struct device *
devm_hwmon_device_register_with_groups(struct device *dev, const char *name,
				       void *drvdata,
				       const struct attribute_group **groups)
{}
EXPORT_SYMBOL_GPL();

/**
 * devm_hwmon_device_register_with_info - register w/ hwmon
 * @dev:	the parent device
 * @name:	hwmon name attribute
 * @drvdata:	driver data to attach to created device
 * @chip:	pointer to hwmon chip information
 * @extra_groups: pointer to list of driver specific attribute groups
 *
 * Returns the pointer to the new device. The new device is automatically
 * unregistered with the parent device.
 */
struct device *
devm_hwmon_device_register_with_info(struct device *dev, const char *name,
				     void *drvdata,
				     const struct hwmon_chip_info *chip,
				     const struct attribute_group **extra_groups)
{}
EXPORT_SYMBOL_GPL();

static int devm_hwmon_match(struct device *dev, void *res, void *data)
{}

/**
 * devm_hwmon_device_unregister - removes a previously registered hwmon device
 *
 * @dev: the parent device of the device to unregister
 */
void devm_hwmon_device_unregister(struct device *dev)
{}
EXPORT_SYMBOL_GPL();

static char *__hwmon_sanitize_name(struct device *dev, const char *old_name)
{}

/**
 * hwmon_sanitize_name - Replaces invalid characters in a hwmon name
 * @name: NUL-terminated name
 *
 * Allocates a new string where any invalid characters will be replaced
 * by an underscore. It is the responsibility of the caller to release
 * the memory.
 *
 * Returns newly allocated name, or ERR_PTR on error.
 */
char *hwmon_sanitize_name(const char *name)
{}
EXPORT_SYMBOL_GPL();

/**
 * devm_hwmon_sanitize_name - resource managed hwmon_sanitize_name()
 * @dev: device to allocate memory for
 * @name: NUL-terminated name
 *
 * Allocates a new string where any invalid characters will be replaced
 * by an underscore.
 *
 * Returns newly allocated name, or ERR_PTR on error.
 */
char *devm_hwmon_sanitize_name(struct device *dev, const char *name)
{}
EXPORT_SYMBOL_GPL();

static void __init hwmon_pci_quirks(void)
{}

static int __init hwmon_init(void)
{}

static void __exit hwmon_exit(void)
{}

subsys_initcall(hwmon_init);
module_exit(hwmon_exit);

MODULE_AUTHOR();
MODULE_DESCRIPTION();
MODULE_LICENSE();