linux/drivers/hwmon/lm85.c

// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * lm85.c - Part of lm_sensors, Linux kernel modules for hardware
 *	    monitoring
 * Copyright (c) 1998, 1999  Frodo Looijaard <[email protected]>
 * Copyright (c) 2002, 2003  Philip Pokorny <[email protected]>
 * Copyright (c) 2003        Margit Schubert-While <[email protected]>
 * Copyright (c) 2004        Justin Thiessen <[email protected]>
 * Copyright (C) 2007--2014  Jean Delvare <[email protected]>
 *
 * Chip details at	      <http://www.national.com/ds/LM/LM85.pdf>
 */

#include <linux/module.h>
#include <linux/of.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/jiffies.h>
#include <linux/i2c.h>
#include <linux/hwmon.h>
#include <linux/hwmon-vid.h>
#include <linux/hwmon-sysfs.h>
#include <linux/err.h>
#include <linux/mutex.h>
#include <linux/util_macros.h>

/* Addresses to scan */
static const unsigned short normal_i2c[] =;

enum chips {};

/* The LM85 registers */

#define LM85_REG_IN(nr)
#define LM85_REG_IN_MIN(nr)
#define LM85_REG_IN_MAX(nr)

#define LM85_REG_TEMP(nr)
#define LM85_REG_TEMP_MIN(nr)
#define LM85_REG_TEMP_MAX(nr)

/* Fan speeds are LSB, MSB (2 bytes) */
#define LM85_REG_FAN(nr)
#define LM85_REG_FAN_MIN(nr)

#define LM85_REG_PWM(nr)

#define LM85_REG_COMPANY
#define LM85_REG_VERSTEP

#define ADT7468_REG_CFG5
#define ADT7468_OFF64
#define ADT7468_HFPWM
#define IS_ADT7468_OFF64(data)
#define IS_ADT7468_HFPWM(data)

/* These are the recognized values for the above regs */
#define LM85_COMPANY_NATIONAL
#define LM85_COMPANY_ANALOG_DEV
#define LM85_COMPANY_SMSC
#define LM85_VERSTEP_LM85C
#define LM85_VERSTEP_LM85B
#define LM85_VERSTEP_LM96000_1
#define LM85_VERSTEP_LM96000_2
#define LM85_VERSTEP_ADM1027
#define LM85_VERSTEP_ADT7463
#define LM85_VERSTEP_ADT7463C
#define LM85_VERSTEP_ADT7468_1
#define LM85_VERSTEP_ADT7468_2
#define LM85_VERSTEP_EMC6D100_A0
#define LM85_VERSTEP_EMC6D100_A1
#define LM85_VERSTEP_EMC6D102
#define LM85_VERSTEP_EMC6D103_A0
#define LM85_VERSTEP_EMC6D103_A1
#define LM85_VERSTEP_EMC6D103S

#define LM85_REG_CONFIG

#define LM85_REG_ALARM1
#define LM85_REG_ALARM2

#define LM85_REG_VID

/* Automated FAN control */
#define LM85_REG_AFAN_CONFIG(nr)
#define LM85_REG_AFAN_RANGE(nr)
#define LM85_REG_AFAN_SPIKE1
#define LM85_REG_AFAN_MINPWM(nr)
#define LM85_REG_AFAN_LIMIT(nr)
#define LM85_REG_AFAN_CRITICAL(nr)
#define LM85_REG_AFAN_HYST1
#define LM85_REG_AFAN_HYST2

#define ADM1027_REG_EXTEND_ADC1
#define ADM1027_REG_EXTEND_ADC2

#define EMC6D100_REG_ALARM3
/* IN5, IN6 and IN7 */
#define EMC6D100_REG_IN(nr)
#define EMC6D100_REG_IN_MIN(nr)
#define EMC6D100_REG_IN_MAX(nr)
#define EMC6D102_REG_EXTEND_ADC1
#define EMC6D102_REG_EXTEND_ADC2
#define EMC6D102_REG_EXTEND_ADC3
#define EMC6D102_REG_EXTEND_ADC4

/*
 * Conversions. Rounding and limit checking is only done on the TO_REG
 * variants. Note that you should be a bit careful with which arguments
 * these macros are called: arguments may be evaluated more than once.
 */

/* IN are scaled according to built-in resistors */
static const int lm85_scaling[] =;
#define SCALE(val, from, to)

#define INS_TO_REG(n, val)

#define INSEXT_FROM_REG(n, val, ext)

#define INS_FROM_REG(n, val)

/* FAN speed is measured using 90kHz clock */
static inline u16 FAN_TO_REG(unsigned long val)
{}
#define FAN_FROM_REG(val)

/* Temperature is reported in .001 degC increments */
#define TEMP_TO_REG(val)
#define TEMPEXT_FROM_REG(val, ext)
#define TEMP_FROM_REG(val)

#define PWM_TO_REG(val)
#define PWM_FROM_REG(val)

/*
 * ZONEs have the following parameters:
 *    Limit (low) temp,           1. degC
 *    Hysteresis (below limit),   1. degC (0-15)
 *    Range of speed control,     .1 degC (2-80)
 *    Critical (high) temp,       1. degC
 *
 * FAN PWMs have the following parameters:
 *    Reference Zone,                 1, 2, 3, etc.
 *    Spinup time,                    .05 sec
 *    PWM value at limit/low temp,    1 count
 *    PWM Frequency,                  1. Hz
 *    PWM is Min or OFF below limit,  flag
 *    Invert PWM output,              flag
 *
 * Some chips filter the temp, others the fan.
 *    Filter constant (or disabled)   .1 seconds
 */

/* These are the zone temperature range encodings in .001 degree C */
static const int lm85_range_map[] =;

static int RANGE_TO_REG(long range)
{}
#define RANGE_FROM_REG(val)

/* These are the PWM frequency encodings */
static const int lm85_freq_map[] =;

static const int lm96000_freq_map[] =;

static const int adm1027_freq_map[] =;

static int FREQ_TO_REG(const int *map,
		       unsigned int map_size, unsigned long freq)
{}

static int FREQ_FROM_REG(const int *map, unsigned int map_size, u8 reg)
{}

/*
 * Since we can't use strings, I'm abusing these numbers
 *   to stand in for the following meanings:
 *      1 -- PWM responds to Zone 1
 *      2 -- PWM responds to Zone 2
 *      3 -- PWM responds to Zone 3
 *     23 -- PWM responds to the higher temp of Zone 2 or 3
 *    123 -- PWM responds to highest of Zone 1, 2, or 3
 *      0 -- PWM is always at 0% (ie, off)
 *     -1 -- PWM is always at 100%
 *     -2 -- PWM responds to manual control
 */

static const int lm85_zone_map[] =;
#define ZONE_FROM_REG(val)

static int ZONE_TO_REG(int zone)
{}

#define HYST_TO_REG(val)
#define HYST_FROM_REG(val)

/*
 * Chip sampling rates
 *
 * Some sensors are not updated more frequently than once per second
 *    so it doesn't make sense to read them more often than that.
 *    We cache the results and return the saved data if the driver
 *    is called again before a second has elapsed.
 *
 * Also, there is significant configuration data for this chip
 *    given the automatic PWM fan control that is possible.  There
 *    are about 47 bytes of config data to only 22 bytes of actual
 *    readings.  So, we keep the config data up to date in the cache
 *    when it is written and only sample it once every 1 *minute*
 */
#define LM85_DATA_INTERVAL
#define LM85_CONFIG_INTERVAL

/*
 * LM85 can automatically adjust fan speeds based on temperature
 * This structure encapsulates an entire Zone config.  There are
 * three zones (one for each temperature input) on the lm85
 */
struct lm85_zone {};

struct lm85_autofan {};

/*
 * For each registered chip, we need to keep some data in memory.
 * The structure is dynamically allocated.
 */
struct lm85_data {};

static int lm85_read_value(struct i2c_client *client, u8 reg)
{}

static void lm85_write_value(struct i2c_client *client, u8 reg, int value)
{}

static struct lm85_data *lm85_update_device(struct device *dev)
{}

/* 4 Fans */
static ssize_t fan_show(struct device *dev, struct device_attribute *attr,
			char *buf)
{}

static ssize_t fan_min_show(struct device *dev, struct device_attribute *attr,
			    char *buf)
{}

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

static SENSOR_DEVICE_ATTR_RO(fan1_input, fan, 0);
static SENSOR_DEVICE_ATTR_RW(fan1_min, fan_min, 0);
static SENSOR_DEVICE_ATTR_RO(fan2_input, fan, 1);
static SENSOR_DEVICE_ATTR_RW(fan2_min, fan_min, 1);
static SENSOR_DEVICE_ATTR_RO(fan3_input, fan, 2);
static SENSOR_DEVICE_ATTR_RW(fan3_min, fan_min, 2);
static SENSOR_DEVICE_ATTR_RO(fan4_input, fan, 3);
static SENSOR_DEVICE_ATTR_RW(fan4_min, fan_min, 3);

/* vid, vrm, alarms */

static ssize_t cpu0_vid_show(struct device *dev,
			     struct device_attribute *attr, char *buf)
{}

static DEVICE_ATTR_RO(cpu0_vid);

static ssize_t vrm_show(struct device *dev, struct device_attribute *attr,
			char *buf)
{}

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

static DEVICE_ATTR_RW(vrm);

static ssize_t alarms_show(struct device *dev, struct device_attribute *attr,
			   char *buf)
{}

static DEVICE_ATTR_RO(alarms);

static ssize_t alarm_show(struct device *dev, struct device_attribute *attr,
			  char *buf)
{}

static SENSOR_DEVICE_ATTR_RO(in0_alarm, alarm, 0);
static SENSOR_DEVICE_ATTR_RO(in1_alarm, alarm, 1);
static SENSOR_DEVICE_ATTR_RO(in2_alarm, alarm, 2);
static SENSOR_DEVICE_ATTR_RO(in3_alarm, alarm, 3);
static SENSOR_DEVICE_ATTR_RO(in4_alarm, alarm, 8);
static SENSOR_DEVICE_ATTR_RO(in5_alarm, alarm, 18);
static SENSOR_DEVICE_ATTR_RO(in6_alarm, alarm, 16);
static SENSOR_DEVICE_ATTR_RO(in7_alarm, alarm, 17);
static SENSOR_DEVICE_ATTR_RO(temp1_alarm, alarm, 4);
static SENSOR_DEVICE_ATTR_RO(temp1_fault, alarm, 14);
static SENSOR_DEVICE_ATTR_RO(temp2_alarm, alarm, 5);
static SENSOR_DEVICE_ATTR_RO(temp3_alarm, alarm, 6);
static SENSOR_DEVICE_ATTR_RO(temp3_fault, alarm, 15);
static SENSOR_DEVICE_ATTR_RO(fan1_alarm, alarm, 10);
static SENSOR_DEVICE_ATTR_RO(fan2_alarm, alarm, 11);
static SENSOR_DEVICE_ATTR_RO(fan3_alarm, alarm, 12);
static SENSOR_DEVICE_ATTR_RO(fan4_alarm, alarm, 13);

/* pwm */

static ssize_t pwm_show(struct device *dev, struct device_attribute *attr,
			char *buf)
{}

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

static ssize_t pwm_enable_show(struct device *dev,
			       struct device_attribute *attr, char *buf)
{}

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

static ssize_t pwm_freq_show(struct device *dev,
			     struct device_attribute *attr, char *buf)
{}

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

static SENSOR_DEVICE_ATTR_RW(pwm1, pwm, 0);
static SENSOR_DEVICE_ATTR_RW(pwm1_enable, pwm_enable, 0);
static SENSOR_DEVICE_ATTR_RW(pwm1_freq, pwm_freq, 0);
static SENSOR_DEVICE_ATTR_RW(pwm2, pwm, 1);
static SENSOR_DEVICE_ATTR_RW(pwm2_enable, pwm_enable, 1);
static SENSOR_DEVICE_ATTR_RW(pwm2_freq, pwm_freq, 1);
static SENSOR_DEVICE_ATTR_RW(pwm3, pwm, 2);
static SENSOR_DEVICE_ATTR_RW(pwm3_enable, pwm_enable, 2);
static SENSOR_DEVICE_ATTR_RW(pwm3_freq, pwm_freq, 2);

/* Voltages */

static ssize_t in_show(struct device *dev, struct device_attribute *attr,
		       char *buf)
{}

static ssize_t in_min_show(struct device *dev, struct device_attribute *attr,
			   char *buf)
{}

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

static ssize_t in_max_show(struct device *dev, struct device_attribute *attr,
			   char *buf)
{}

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

static SENSOR_DEVICE_ATTR_RO(in0_input, in, 0);
static SENSOR_DEVICE_ATTR_RW(in0_min, in_min, 0);
static SENSOR_DEVICE_ATTR_RW(in0_max, in_max, 0);
static SENSOR_DEVICE_ATTR_RO(in1_input, in, 1);
static SENSOR_DEVICE_ATTR_RW(in1_min, in_min, 1);
static SENSOR_DEVICE_ATTR_RW(in1_max, in_max, 1);
static SENSOR_DEVICE_ATTR_RO(in2_input, in, 2);
static SENSOR_DEVICE_ATTR_RW(in2_min, in_min, 2);
static SENSOR_DEVICE_ATTR_RW(in2_max, in_max, 2);
static SENSOR_DEVICE_ATTR_RO(in3_input, in, 3);
static SENSOR_DEVICE_ATTR_RW(in3_min, in_min, 3);
static SENSOR_DEVICE_ATTR_RW(in3_max, in_max, 3);
static SENSOR_DEVICE_ATTR_RO(in4_input, in, 4);
static SENSOR_DEVICE_ATTR_RW(in4_min, in_min, 4);
static SENSOR_DEVICE_ATTR_RW(in4_max, in_max, 4);
static SENSOR_DEVICE_ATTR_RO(in5_input, in, 5);
static SENSOR_DEVICE_ATTR_RW(in5_min, in_min, 5);
static SENSOR_DEVICE_ATTR_RW(in5_max, in_max, 5);
static SENSOR_DEVICE_ATTR_RO(in6_input, in, 6);
static SENSOR_DEVICE_ATTR_RW(in6_min, in_min, 6);
static SENSOR_DEVICE_ATTR_RW(in6_max, in_max, 6);
static SENSOR_DEVICE_ATTR_RO(in7_input, in, 7);
static SENSOR_DEVICE_ATTR_RW(in7_min, in_min, 7);
static SENSOR_DEVICE_ATTR_RW(in7_max, in_max, 7);

/* Temps */

static ssize_t temp_show(struct device *dev, struct device_attribute *attr,
			 char *buf)
{}

static ssize_t temp_min_show(struct device *dev,
			     struct device_attribute *attr, char *buf)
{}

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

static ssize_t temp_max_show(struct device *dev,
			     struct device_attribute *attr, char *buf)
{}

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

static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, 0);
static SENSOR_DEVICE_ATTR_RW(temp1_min, temp_min, 0);
static SENSOR_DEVICE_ATTR_RW(temp1_max, temp_max, 0);
static SENSOR_DEVICE_ATTR_RO(temp2_input, temp, 1);
static SENSOR_DEVICE_ATTR_RW(temp2_min, temp_min, 1);
static SENSOR_DEVICE_ATTR_RW(temp2_max, temp_max, 1);
static SENSOR_DEVICE_ATTR_RO(temp3_input, temp, 2);
static SENSOR_DEVICE_ATTR_RW(temp3_min, temp_min, 2);
static SENSOR_DEVICE_ATTR_RW(temp3_max, temp_max, 2);

/* Automatic PWM control */

static ssize_t pwm_auto_channels_show(struct device *dev,
				      struct device_attribute *attr,
				      char *buf)
{}

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

static ssize_t pwm_auto_pwm_min_show(struct device *dev,
				     struct device_attribute *attr, char *buf)
{}

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

static ssize_t pwm_auto_pwm_minctl_show(struct device *dev,
					struct device_attribute *attr,
					char *buf)
{}

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

static SENSOR_DEVICE_ATTR_RW(pwm1_auto_channels, pwm_auto_channels, 0);
static SENSOR_DEVICE_ATTR_RW(pwm1_auto_pwm_min, pwm_auto_pwm_min, 0);
static SENSOR_DEVICE_ATTR_RW(pwm1_auto_pwm_minctl, pwm_auto_pwm_minctl, 0);
static SENSOR_DEVICE_ATTR_RW(pwm2_auto_channels, pwm_auto_channels, 1);
static SENSOR_DEVICE_ATTR_RW(pwm2_auto_pwm_min, pwm_auto_pwm_min, 1);
static SENSOR_DEVICE_ATTR_RW(pwm2_auto_pwm_minctl, pwm_auto_pwm_minctl, 1);
static SENSOR_DEVICE_ATTR_RW(pwm3_auto_channels, pwm_auto_channels, 2);
static SENSOR_DEVICE_ATTR_RW(pwm3_auto_pwm_min, pwm_auto_pwm_min, 2);
static SENSOR_DEVICE_ATTR_RW(pwm3_auto_pwm_minctl, pwm_auto_pwm_minctl, 2);

/* Temperature settings for automatic PWM control */

static ssize_t temp_auto_temp_off_show(struct device *dev,
				       struct device_attribute *attr,
				       char *buf)
{}

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

static ssize_t temp_auto_temp_min_show(struct device *dev,
				       struct device_attribute *attr,
				       char *buf)
{}

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

static ssize_t temp_auto_temp_max_show(struct device *dev,
				       struct device_attribute *attr,
				       char *buf)
{}

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

static ssize_t temp_auto_temp_crit_show(struct device *dev,
					struct device_attribute *attr,
					char *buf)
{}

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

static SENSOR_DEVICE_ATTR_RW(temp1_auto_temp_off, temp_auto_temp_off, 0);
static SENSOR_DEVICE_ATTR_RW(temp1_auto_temp_min, temp_auto_temp_min, 0);
static SENSOR_DEVICE_ATTR_RW(temp1_auto_temp_max, temp_auto_temp_max, 0);
static SENSOR_DEVICE_ATTR_RW(temp1_auto_temp_crit, temp_auto_temp_crit, 0);
static SENSOR_DEVICE_ATTR_RW(temp2_auto_temp_off, temp_auto_temp_off, 1);
static SENSOR_DEVICE_ATTR_RW(temp2_auto_temp_min, temp_auto_temp_min, 1);
static SENSOR_DEVICE_ATTR_RW(temp2_auto_temp_max, temp_auto_temp_max, 1);
static SENSOR_DEVICE_ATTR_RW(temp2_auto_temp_crit, temp_auto_temp_crit, 1);
static SENSOR_DEVICE_ATTR_RW(temp3_auto_temp_off, temp_auto_temp_off, 2);
static SENSOR_DEVICE_ATTR_RW(temp3_auto_temp_min, temp_auto_temp_min, 2);
static SENSOR_DEVICE_ATTR_RW(temp3_auto_temp_max, temp_auto_temp_max, 2);
static SENSOR_DEVICE_ATTR_RW(temp3_auto_temp_crit, temp_auto_temp_crit, 2);

static struct attribute *lm85_attributes[] =;

static const struct attribute_group lm85_group =;

static struct attribute *lm85_attributes_minctl[] =;

static const struct attribute_group lm85_group_minctl =;

static struct attribute *lm85_attributes_temp_off[] =;

static const struct attribute_group lm85_group_temp_off =;

static struct attribute *lm85_attributes_in4[] =;

static const struct attribute_group lm85_group_in4 =;

static struct attribute *lm85_attributes_in567[] =;

static const struct attribute_group lm85_group_in567 =;

static void lm85_init_client(struct i2c_client *client)
{}

static int lm85_is_fake(struct i2c_client *client)
{}

/* Return 0 if detection is successful, -ENODEV otherwise */
static int lm85_detect(struct i2c_client *client, struct i2c_board_info *info)
{}

static int lm85_probe(struct i2c_client *client)
{}

static const struct i2c_device_id lm85_id[] =;
MODULE_DEVICE_TABLE(i2c, lm85_id);

static const struct of_device_id __maybe_unused lm85_of_match[] =;
MODULE_DEVICE_TABLE(of, lm85_of_match);

static struct i2c_driver lm85_driver =;

module_i2c_driver();

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