cregit-Linux how code gets into the kernel

Release 4.11 drivers/hwmon/adm9240.c

Directory: drivers/hwmon
/*
 * adm9240.c    Part of lm_sensors, Linux kernel modules for hardware
 *              monitoring
 *
 * Copyright (C) 1999   Frodo Looijaard <frodol@dds.nl>
 *                      Philip Edelbrock <phil@netroedge.com>
 * Copyright (C) 2003   Michiel Rook <michiel@grendelproject.nl>
 * Copyright (C) 2005   Grant Coady <gcoady.lk@gmail.com> with valuable
 *                              guidance from Jean Delvare
 *
 * Driver supports      Analog Devices          ADM9240
 *                      Dallas Semiconductor    DS1780
 *                      National Semiconductor  LM81
 *
 * ADM9240 is the reference, DS1780 and LM81 are register compatibles
 *
 * Voltage      Six inputs are scaled by chip, VID also reported
 * Temperature  Chip temperature to 0.5'C, maximum and max_hysteris
 * Fans         2 fans, low speed alarm, automatic fan clock divider
 * Alarms       16-bit map of active alarms
 * Analog Out   0..1250 mV output
 *
 * Chassis Intrusion: clear CI latch with 'echo 0 > intrusion0_alarm'
 *
 * Test hardware: Intel SE440BX-2 desktop motherboard --Grant
 *
 * LM81 extended temp reading not implemented
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

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

/* Addresses to scan */

static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f,
					I2C_CLIENT_END };





enum chips { adm9240, ds1780, lm81 };

/* ADM9240 registers */

#define ADM9240_REG_MAN_ID		0x3e

#define ADM9240_REG_DIE_REV		0x3f

#define ADM9240_REG_CONFIG		0x40


#define ADM9240_REG_IN(nr)		(0x20 + (nr))   
/* 0..5 */

#define ADM9240_REG_IN_MAX(nr)		(0x2b + (nr) * 2)

#define ADM9240_REG_IN_MIN(nr)		(0x2c + (nr) * 2)

#define ADM9240_REG_FAN(nr)		(0x28 + (nr))   
/* 0..1 */

#define ADM9240_REG_FAN_MIN(nr)		(0x3b + (nr))

#define ADM9240_REG_INT(nr)		(0x41 + (nr))

#define ADM9240_REG_INT_MASK(nr)	(0x43 + (nr))

#define ADM9240_REG_TEMP		0x27

#define ADM9240_REG_TEMP_MAX(nr)	(0x39 + (nr)) 
/* 0, 1 = high, hyst */

#define ADM9240_REG_ANALOG_OUT		0x19

#define ADM9240_REG_CHASSIS_CLEAR	0x46

#define ADM9240_REG_VID_FAN_DIV		0x47

#define ADM9240_REG_I2C_ADDR		0x48

#define ADM9240_REG_VID4		0x49

#define ADM9240_REG_TEMP_CONF		0x4b

/* generalised scaling with integer rounding */

static inline int SCALE(long val, int mul, int div) { if (val < 0) return (val * mul - div / 2) / div; else return (val * mul + div / 2) / div; }

Contributors

PersonTokensPropCommitsCommitProp
Grant Coady49100.00%1100.00%
Total49100.00%1100.00%

/* adm9240 internally scales voltage measurements */ static const u16 nom_mv[] = { 2500, 2700, 3300, 5000, 12000, 2700 };
static inline unsigned int IN_FROM_REG(u8 reg, int n) { return SCALE(reg, nom_mv[n], 192); }

Contributors

PersonTokensPropCommitsCommitProp
Grant Coady27100.00%1100.00%
Total27100.00%1100.00%


static inline u8 IN_TO_REG(unsigned long val, int n) { val = clamp_val(val, 0, nom_mv[n] * 255 / 192); return SCALE(val, 192, nom_mv[n]); }

Contributors

PersonTokensPropCommitsCommitProp
Grant Coady2760.00%133.33%
Guenter Roeck1840.00%266.67%
Total45100.00%3100.00%

/* temperature range: -40..125, 127 disables temperature alarm */
static inline s8 TEMP_TO_REG(long val) { val = clamp_val(val, -40000, 127000); return SCALE(val, 1, 1000); }

Contributors

PersonTokensPropCommitsCommitProp
Grant Coady2062.50%133.33%
Guenter Roeck1237.50%266.67%
Total32100.00%3100.00%

/* two fans, each with low fan speed limit */
static inline unsigned int FAN_FROM_REG(u8 reg, u8 div) { if (!reg) /* error */ return -1; if (reg == 255) return 0; return SCALE(1350000, 1, reg * div); }

Contributors

PersonTokensPropCommitsCommitProp
Grant Coady45100.00%1100.00%
Total45100.00%1100.00%

/* analog out 0..1250mV */
static inline u8 AOUT_TO_REG(unsigned long val) { val = clamp_val(val, 0, 1250); return SCALE(val, 255, 1250); }

Contributors

PersonTokensPropCommitsCommitProp
Grant Coady2165.62%133.33%
Guenter Roeck1134.38%266.67%
Total32100.00%3100.00%


static inline unsigned int AOUT_FROM_REG(u8 reg) { return SCALE(reg, 1250, 255); }

Contributors

PersonTokensPropCommitsCommitProp
Grant Coady21100.00%1100.00%
Total21100.00%1100.00%

/* per client data */ struct adm9240_data { struct i2c_client *client; struct mutex update_lock; char valid; unsigned long last_updated_measure; unsigned long last_updated_config; u8 in[6]; /* ro in0_input */ u8 in_max[6]; /* rw in0_max */ u8 in_min[6]; /* rw in0_min */ u8 fan[2]; /* ro fan1_input */ u8 fan_min[2]; /* rw fan1_min */ u8 fan_div[2]; /* rw fan1_div, read-only accessor */ s16 temp; /* ro temp1_input, 9-bit sign-extended */ s8 temp_max[2]; /* rw 0 -> temp_max, 1 -> temp_max_hyst */ u16 alarms; /* ro alarms */ u8 aout; /* rw aout_output */ u8 vid; /* ro vid */ u8 vrm; /* -- vrm set on startup, no accessor */ }; /* write new fan div, callers must hold data->update_lock */
static void adm9240_write_fan_div(struct i2c_client *client, int nr, u8 fan_div) { u8 reg, old, shift = (nr + 2) * 2; reg = i2c_smbus_read_byte_data(client, ADM9240_REG_VID_FAN_DIV); old = (reg >> shift) & 3; reg &= ~(3 << shift); reg |= (fan_div << shift); i2c_smbus_write_byte_data(client, ADM9240_REG_VID_FAN_DIV, reg); dev_dbg(&client->dev, "fan%d clock divider changed from %u to %u\n", nr + 1, 1 << old, 1 << fan_div); }

Contributors

PersonTokensPropCommitsCommitProp
Axel Lin7878.79%133.33%
Grant Coady2121.21%266.67%
Total99100.00%3100.00%


static struct adm9240_data *adm9240_update_device(struct device *dev) { struct adm9240_data *data = dev_get_drvdata(dev); struct i2c_client *client = data->client; int i; mutex_lock(&data->update_lock); /* minimum measurement cycle: 1.75 seconds */ if (time_after(jiffies, data->last_updated_measure + (HZ * 7 / 4)) || !data->valid) { for (i = 0; i < 6; i++) { /* read voltages */ data->in[i] = i2c_smbus_read_byte_data(client, ADM9240_REG_IN(i)); } data->alarms = i2c_smbus_read_byte_data(client, ADM9240_REG_INT(0)) | i2c_smbus_read_byte_data(client, ADM9240_REG_INT(1)) << 8; /* * read temperature: assume temperature changes less than * 0.5'C per two measurement cycles thus ignore possible * but unlikely aliasing error on lsb reading. --Grant */ data->temp = (i2c_smbus_read_byte_data(client, ADM9240_REG_TEMP) << 8) | i2c_smbus_read_byte_data(client, ADM9240_REG_TEMP_CONF); for (i = 0; i < 2; i++) { /* read fans */ data->fan[i] = i2c_smbus_read_byte_data(client, ADM9240_REG_FAN(i)); /* adjust fan clock divider on overflow */ if (data->valid && data->fan[i] == 255 && data->fan_div[i] < 3) { adm9240_write_fan_div(client, i, ++data->fan_div[i]); /* adjust fan_min if active, but not to 0 */ if (data->fan_min[i] < 255 && data->fan_min[i] >= 2) data->fan_min[i] /= 2; } } data->last_updated_measure = jiffies; } /* minimum config reading cycle: 300 seconds */ if (time_after(jiffies, data->last_updated_config + (HZ * 300)) || !data->valid) { for (i = 0; i < 6; i++) { data->in_min[i] = i2c_smbus_read_byte_data(client, ADM9240_REG_IN_MIN(i)); data->in_max[i] = i2c_smbus_read_byte_data(client, ADM9240_REG_IN_MAX(i)); } for (i = 0; i < 2; i++) { data->fan_min[i] = i2c_smbus_read_byte_data(client, ADM9240_REG_FAN_MIN(i)); } data->temp_max[0] = i2c_smbus_read_byte_data(client, ADM9240_REG_TEMP_MAX(0)); data->temp_max[1] = i2c_smbus_read_byte_data(client, ADM9240_REG_TEMP_MAX(1)); /* read fan divs and 5-bit VID */ i = i2c_smbus_read_byte_data(client, ADM9240_REG_VID_FAN_DIV); data->fan_div[0] = (i >> 4) & 3; data->fan_div[1] = (i >> 6) & 3; data->vid = i & 0x0f; data->vid |= (i2c_smbus_read_byte_data(client, ADM9240_REG_VID4) & 1) << 4; /* read analog out */ data->aout = i2c_smbus_read_byte_data(client, ADM9240_REG_ANALOG_OUT); data->last_updated_config = jiffies; data->valid = 1; } mutex_unlock(&data->update_lock); return data; }

Contributors

PersonTokensPropCommitsCommitProp
Axel Lin38075.55%240.00%
Grant Coady11422.66%240.00%
Guenter Roeck91.79%120.00%
Total503100.00%5100.00%

/*** sysfs accessors ***/ /* temperature */
static ssize_t temp1_input_show(struct device *dev, struct device_attribute *dummy, char *buf) { struct adm9240_data *data = adm9240_update_device(dev); return sprintf(buf, "%d\n", data->temp / 128 * 500); /* 9-bit value */ }

Contributors

PersonTokensPropCommitsCommitProp
Axel Lin4289.36%125.00%
Grant Coady24.26%125.00%
Chris Packham24.26%125.00%
Julia Lawall12.13%125.00%
Total47100.00%4100.00%


static ssize_t show_max(struct device *dev, struct device_attribute *devattr, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct adm9240_data *data = adm9240_update_device(dev); return sprintf(buf, "%d\n", data->temp_max[attr->index] * 1000); }

Contributors

PersonTokensPropCommitsCommitProp
Axel Lin59100.00%1100.00%
Total59100.00%1100.00%


static ssize_t set_max(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct adm9240_data *data = dev_get_drvdata(dev); struct i2c_client *client = data->client; long val; int err; err = kstrtol(buf, 10, &val); if (err) return err; mutex_lock(&data->update_lock); data->temp_max[attr->index] = TEMP_TO_REG(val); i2c_smbus_write_byte_data(client, ADM9240_REG_TEMP_MAX(attr->index), data->temp_max[attr->index]); mutex_unlock(&data->update_lock); return count; }

Contributors

PersonTokensPropCommitsCommitProp
Grant Coady9874.24%342.86%
Guenter Roeck1712.88%114.29%
Axel Lin1511.36%228.57%
Ingo Molnar21.52%114.29%
Total132100.00%7100.00%

static DEVICE_ATTR_RO(temp1_input); static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_max, set_max, 0); static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IWUSR | S_IRUGO, show_max, set_max, 1); /* voltage */
static ssize_t show_in(struct device *dev, struct device_attribute *devattr, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct adm9240_data *data = adm9240_update_device(dev); return sprintf(buf, "%d\n", IN_FROM_REG(data->in[attr->index], attr->index)); }

Contributors

PersonTokensPropCommitsCommitProp
Grant Coady6195.31%266.67%
Axel Lin34.69%133.33%
Total64100.00%3100.00%


static ssize_t show_in_min(struct device *dev, struct device_attribute *devattr, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct adm9240_data *data = adm9240_update_device(dev); return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[attr->index], attr->index)); }

Contributors

PersonTokensPropCommitsCommitProp
Grant Coady6195.31%266.67%
Axel Lin34.69%133.33%
Total64100.00%3100.00%


static ssize_t show_in_max(struct device *dev, struct device_attribute *devattr, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct adm9240_data *data = adm9240_update_device(dev); return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[attr->index], attr->index)); }

Contributors

PersonTokensPropCommitsCommitProp
Grant Coady5687.50%266.67%
Axel Lin812.50%133.33%
Total64100.00%3100.00%


static ssize_t set_in_min(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct adm9240_data *data = dev_get_drvdata(dev); struct i2c_client *client = data->client; unsigned long val; int err; err = kstrtoul(buf, 10, &val); if (err) return err; mutex_lock(&data->update_lock); data->in_min[attr->index] = IN_TO_REG(val, attr->index); i2c_smbus_write_byte_data(client, ADM9240_REG_IN_MIN(attr->index), data->in_min[attr->index]); mutex_unlock(&data->update_lock); return count; }

Contributors

PersonTokensPropCommitsCommitProp
Grant Coady6849.64%233.33%
Axel Lin4230.66%233.33%
Guenter Roeck2618.98%116.67%
Ingo Molnar10.73%116.67%
Total137100.00%6100.00%


static ssize_t set_in_max(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct adm9240_data *data = dev_get_drvdata(dev); struct i2c_client *client = data->client; unsigned long val; int err; err = kstrtoul(buf, 10, &val); if (err) return err; mutex_lock(&data->update_lock); data->in_max[attr->index] = IN_TO_REG(val, attr->index); i2c_smbus_write_byte_data(client, ADM9240_REG_IN_MAX(attr->index), data->in_max[attr->index]); mutex_unlock(&data->update_lock); return count; }

Contributors

PersonTokensPropCommitsCommitProp
Axel Lin8562.04%240.00%
Grant Coady5137.23%240.00%
Ingo Molnar10.73%120.00%
Total137100.00%5100.00%

#define vin(nr) \ static SENSOR_DEVICE_ATTR(in##nr##_input, S_IRUGO, \ show_in, NULL, nr); \ static SENSOR_DEVICE_ATTR(in##nr##_min, S_IRUGO | S_IWUSR, \ show_in_min, set_in_min, nr); \ static SENSOR_DEVICE_ATTR(in##nr##_max, S_IRUGO | S_IWUSR, \ show_in_max, set_in_max, nr); vin(0); vin(1); vin(2); vin(3); vin(4); vin(5); /* fans */
static ssize_t show_fan(struct device *dev, struct device_attribute *devattr, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct adm9240_data *data = adm9240_update_device(dev); return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[attr->index], 1 << data->fan_div[attr->index])); }

Contributors

PersonTokensPropCommitsCommitProp
Grant Coady3447.89%133.33%
Axel Lin3346.48%133.33%
Greg Kroah-Hartman45.63%133.33%
Total71100.00%3100.00%


static ssize_t show_fan_min(struct device *dev, struct device_attribute *devattr, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct adm9240_data *data = adm9240_update_device(dev); return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[attr->index], 1 << data->fan_div[attr->index])); }

Contributors

PersonTokensPropCommitsCommitProp
Jean Delvare4461.97%150.00%
Axel Lin2738.03%150.00%
Total71100.00%2100.00%


static ssize_t show_fan_div(struct device *dev, struct device_attribute *devattr, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct adm9240_data *data = adm9240_update_device(dev); return sprintf(buf, "%d\n", 1 << data->fan_div[attr->index]); }

Contributors

PersonTokensPropCommitsCommitProp
Grant Coady4169.49%133.33%
Axel Lin1423.73%133.33%
Greg Kroah-Hartman46.78%133.33%
Total59100.00%3100.00%

/* * set fan speed low limit: * * - value is zero: disable fan speed low limit alarm * * - value is below fan speed measurement range: enable fan speed low * limit alarm to be asserted while fan speed too slow to measure * * - otherwise: select fan clock divider to suit fan speed low limit, * measurement code may adjust registers to ensure fan speed reading */
static ssize_t set_fan_min(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct adm9240_data *data = dev_get_drvdata(dev); struct i2c_client *client = data->client; int nr = attr->index; u8 new_div; unsigned long val; int err; err = kstrtoul(buf, 10, &val); if (err) return err; mutex_lock(&data->update_lock); if (!val) { data->fan_min[nr] = 255; new_div = data->fan_div[nr]; dev_dbg(&client->dev, "fan%u low limit set disabled\n", nr + 1); } else if (val < 1350000 / (8 * 254)) { new_div = 3; data->fan_min[nr] = 254; dev_dbg(&client->dev, "fan%u low limit set minimum %u\n", nr + 1, FAN_FROM_REG(254, 1 << new_div)); } else { unsigned int new_min = 1350000 / val; new_div = 0; while (new_min > 192 && new_div < 3) { new_div++; new_min /= 2; } if (!new_min) /* keep > 0 */ new_min++; data->fan_min[nr] = new_min; dev_dbg(&client->dev, "fan%u low limit set fan speed %u\n", nr + 1, FAN_FROM_REG(new_min, 1 << new_div)); } if (new_div != data->fan_div[nr]) { data->fan_div[nr] = new_div; adm9240_write_fan_div(client, nr, new_div); } i2c_smbus_write_byte_data(client, ADM9240_REG_FAN_MIN(nr), data->fan_min[nr]); mutex_unlock(&data->update_lock); return count; }

Contributors

PersonTokensPropCommitsCommitProp
Axel Lin21165.73%228.57%
Grant Coady5717.76%114.29%
Jean Delvare319.66%114.29%
Guenter Roeck175.30%114.29%
Greg Kroah-Hartman41.25%114.29%
Ingo Molnar10.31%114.29%
Total321100.00%7100.00%

#define fan(nr) \ static SENSOR_DEVICE_ATTR(fan##nr##_input, S_IRUGO, \ show_fan, NULL, nr - 1); \ static SENSOR_DEVICE_ATTR(fan##nr##_div, S_IRUGO, \ show_fan_div, NULL, nr - 1); \ static SENSOR_DEVICE_ATTR(fan##nr##_min, S_IRUGO | S_IWUSR, \ show_fan_min, set_fan_min, nr - 1); fan(1); fan(2); /* alarms */
static ssize_t alarms_show(struct device *dev, struct device_attribute *attr, char *buf) { struct adm9240_data *data = adm9240_update_device(dev); return sprintf(buf, "%u\n", data->alarms); }

Contributors

PersonTokensPropCommitsCommitProp
Axel Lin3788.10%133.33%
Jean Delvare49.52%133.33%
Julia Lawall12.38%133.33%
Total42100.00%3100.00%

static DEVICE_ATTR_RO(alarms);
static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, char *buf) { int bitnr = to_sensor_dev_attr(attr)->index; struct adm9240_data *data = adm9240_update_device(dev); return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); }

Contributors

PersonTokensPropCommitsCommitProp
Axel Lin4068.97%125.00%
Grant Coady915.52%125.00%
Jean Delvare58.62%125.00%
Mark M. Hoffman46.90%125.00%
Total58100.00%4100.00%

static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0); static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1); static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2); static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3); static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8); static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 9); static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4); static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6); static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7); /* vid */
static ssize_t cpu0_vid_show(struct device *dev, struct device_attribute *attr, char *buf) { struct adm9240_data *data = adm9240_update_device(dev); return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm)); }

Contributors

PersonTokensPropCommitsCommitProp
Axel Lin2448.98%120.00%
Jean Delvare1938.78%120.00%
Grant Coady36.12%120.00%
Guenter Roeck24.08%120.00%
Julia Lawall12.04%120.00%
Total49100.00%5100.00%

static DEVICE_ATTR_RO(cpu0_vid); /* analog output */
static ssize_t aout_output_show(struct device *dev, struct device_attribute *attr, char *buf) { struct adm9240_data *data = adm9240_update_device(dev); return sprintf(buf, "%d\n", AOUT_FROM_REG(data->aout)); }

Contributors

PersonTokensPropCommitsCommitProp
Axel Lin3271.11%125.00%
Mark M. Hoffman920.00%125.00%
Grant Coady36.67%125.00%
Julia Lawall12.22%125.00%
Total45100.00%4100.00%


static ssize_t aout_output_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct adm9240_data *data = dev_get_drvdata(dev); struct i2c_client *client = data->client; long val; int err; err = kstrtol(buf, 10, &val); if (err) return err; mutex_lock(&data->update_lock); data->aout = AOUT_TO_REG(val); i2c_smbus_write_byte_data(client, ADM9240_REG_ANALOG_OUT, data->aout); mutex_unlock(&data->update_lock); return count; }

Contributors

PersonTokensPropCommitsCommitProp
Axel Lin8377.57%233.33%
Mark M. Hoffman1614.95%233.33%
Grant Coady76.54%116.67%
Julia Lawall10.93%116.67%
Total107100.00%6100.00%

static DEVICE_ATTR_RW(aout_output);
static ssize_t chassis_clear(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct adm9240_data *data = dev_get_drvdata(dev); struct i2c_client *client = data->client; unsigned long val; if (kstrtoul(buf, 10, &val) || val != 0) return -EINVAL; mutex_lock(&data->update_lock); i2c_smbus_write_byte_data(client, ADM9240_REG_CHASSIS_CLEAR, 0x80); data->valid = 0; /* Force cache refresh */ mutex_unlock(&data->update_lock); dev_dbg(&client->dev, "chassis intrusion latch cleared\n"); return count; }

Contributors

PersonTokensPropCommitsCommitProp
Axel Lin7163.39%233.33%
Grant Coady4136.61%466.67%
Total112100.00%6100.00%

static SENSOR_DEVICE_ATTR(intrusion0_alarm, S_IRUGO | S_IWUSR, show_alarm, chassis_clear, 12); static struct attribute *adm9240_attrs[] = { &sensor_dev_attr_in0_input.dev_attr.attr, &sensor_dev_attr_in0_min.dev_attr.attr, &sensor_dev_attr_in0_max.dev_attr.attr, &sensor_dev_attr_in0_alarm.dev_attr.attr, &sensor_dev_attr_in1_input.dev_attr.attr, &sensor_dev_attr_in1_min.dev_attr.attr, &sensor_dev_attr_in1_max.dev_attr.attr, &sensor_dev_attr_in1_alarm.dev_attr.attr, &sensor_dev_attr_in2_input.dev_attr.attr, &sensor_dev_attr_in2_min.dev_attr.attr, &sensor_dev_attr_in2_max.dev_attr.attr, &sensor_dev_attr_in2_alarm.dev_attr.attr, &sensor_dev_attr_in3_input.dev_attr.attr, &sensor_dev_attr_in3_min.dev_attr.attr, &sensor_dev_attr_in3_max.dev_attr.attr, &sensor_dev_attr_in3_alarm.dev_attr.attr, &sensor_dev_attr_in4_input.dev_attr.attr, &sensor_dev_attr_in4_min.dev_attr.attr, &sensor_dev_attr_in4_max.dev_attr.attr, &sensor_dev_attr_in4_alarm.dev_attr.attr, &sensor_dev_attr_in5_input.dev_attr.attr, &sensor_dev_attr_in5_min.dev_attr.attr, &sensor_dev_attr_in5_max.dev_attr.attr, &sensor_dev_attr_in5_alarm.dev_attr.attr, &dev_attr_temp1_input.attr, &sensor_dev_attr_temp1_max.dev_attr.attr, &sensor_dev_attr_temp1_max_hyst.dev_attr.attr, &sensor_dev_attr_temp1_alarm.dev_attr.attr, &sensor_dev_attr_fan1_input.dev_attr.attr, &sensor_dev_attr_fan1_div.dev_attr.attr, &sensor_dev_attr_fan1_min.dev_attr.attr, &sensor_dev_attr_fan1_alarm.dev_attr.attr, &sensor_dev_attr_fan2_input.dev_attr.attr, &sensor_dev_attr_fan2_div.dev_attr.attr, &sensor_dev_attr_fan2_min.dev_attr.attr, &sensor_dev_attr_fan2_alarm.dev_attr.attr, &dev_attr_alarms.attr, &dev_attr_aout_output.attr, &sensor_dev_attr_intrusion0_alarm.dev_attr.attr, &dev_attr_cpu0_vid.attr, NULL }; ATTRIBUTE_GROUPS(adm9240); /*** sensor chip detect and driver install ***/ /* Return 0 if detection is successful, -ENODEV otherwise */
static int adm9240_detect(struct i2c_client *new_client, struct i2c_board_info *info) { struct i2c_adapter *adapter = new_client->adapter; const char *name = ""; int address = new_client->addr; u8 man_id, die_rev; if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -ENODEV; /* verify chip: reg address should match i2c address */ if (i2c_smbus_read_byte_data(new_client, ADM9240_REG_I2C_ADDR) != address) { dev_err(&adapter->dev, "detect fail: address match, 0x%02x\n", address); return -ENODEV; } /* check known chip manufacturer */ man_id = i2c_smbus_read_byte_data(new_client, ADM9240_REG_MAN_ID); if (man_id == 0x23) { name = "adm9240"; } else if (man_id == 0xda) { name = "ds1780"; } else if (man_id == 0x01) { name = "lm81"; } else { dev_err(&adapter->dev, "detect fail: unknown manuf, 0x%02x\n", man_id); return -ENODEV; } /* successful detect, print chip info */ die_rev = i2c_smbus_read_byte_data(new_client, ADM9240_REG_DIE_REV); dev_info(&adapter->dev, "found %s revision %u\n", man_id == 0x23 ? "ADM9240" : man_id == 0xda ? "DS1780" : "LM81", die_rev); strlcpy(info->type, name, I2C_NAME_SIZE); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Axel Lin15676.10%133.33%
Grant Coady4923.90%266.67%
Total205100.00%3100.00%


static void adm9240_init_client(struct i2c_client *client) { struct adm9240_data *data = i2c_get_clientdata(client); u8 conf = i2c_smbus_read_byte_data(client, ADM9240_REG_CONFIG); u8 mode = i2c_smbus_read_byte_data(client, ADM9240_REG_TEMP_CONF) & 3; data->vrm = vid_which_vrm(); /* need this to report vid as mV */ dev_info(&client->dev, "Using VRM: %d.%d\n", data->vrm / 10, data->vrm % 10); if (conf & 1) { /* measurement cycle running: report state */ dev_info(&client->dev, "status: config 0x%02x mode %u\n", conf, mode); } else { /* cold start: open limits before starting chip */ int i; for (i = 0; i < 6; i++) { i2c_smbus_write_byte_data(client, ADM9240_REG_IN_MIN(i), 0); i2c_smbus_write_byte_data(client, ADM9240_REG_IN_MAX(i), 255); } i2c_smbus_write_byte_data(client, ADM9240_REG_FAN_MIN(0), 255); i2c_smbus_write_byte_data(client, ADM9240_REG_FAN_MIN(1), 255); i2c_smbus_write_byte_data(client, ADM9240_REG_TEMP_MAX(0), 127); i2c_smbus_write_byte_data(client, ADM9240_REG_TEMP_MAX(1), 127); /* start measurement cycle */ i2c_smbus_write_byte_data(client, ADM9240_REG_CONFIG, 1); dev_info(&client->dev, "cold start: config was 0x%02x mode %u\n", conf, mode); } }

Contributors

PersonTokensPropCommitsCommitProp
Axel Lin13663.55%133.33%
Grant Coady7836.45%266.67%
Total214100.00%3100.00%


static int adm9240_probe(struct i2c_client *new_client, const struct i2c_device_id *id) { struct device *dev = &new_client->dev; struct device *hwmon_dev; struct adm9240_data *data; data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); if (!data) return -ENOMEM; i2c_set_clientdata(new_client, data); data->client = new_client; mutex_init(&data->update_lock); adm9240_init_client(new_client); hwmon_dev = devm_hwmon_device_register_with_groups(dev, new_client->name, data, adm9240_groups); return PTR_ERR_OR_ZERO(hwmon_dev); }

Contributors

PersonTokensPropCommitsCommitProp
Axel Lin9688.89%266.67%
Grant Coady1211.11%133.33%
Total108100.00%3100.00%

static const struct i2c_device_id adm9240_id[] = { { "adm9240", adm9240 }, { "ds1780", ds1780 }, { "lm81", lm81 }, { } }; MODULE_DEVICE_TABLE(i2c, adm9240_id); static struct i2c_driver adm9240_driver = { .class = I2C_CLASS_HWMON, .driver = { .name = "adm9240", }, .probe = adm9240_probe, .id_table = adm9240_id, .detect = adm9240_detect, .address_list = normal_i2c, }; module_i2c_driver(adm9240_driver); MODULE_AUTHOR("Michiel Rook <michiel@grendelproject.nl>, " "Grant Coady <gcoady.lk@gmail.com> and others"); MODULE_DESCRIPTION("ADM9240/DS1780/LM81 driver"); MODULE_LICENSE("GPL");

Overall Contributors

PersonTokensPropCommitsCommitProp
Axel Lin223656.58%312.00%
Grant Coady141535.80%520.00%
Jean Delvare1152.91%624.00%
Guenter Roeck1142.88%416.00%
Mark M. Hoffman401.01%312.00%
Greg Kroah-Hartman120.30%14.00%
Julia Lawall90.23%14.00%
Ingo Molnar90.23%14.00%
Chris Packham20.05%14.00%
Total3952100.00%25100.00%
Directory: drivers/hwmon
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.