Skip to contentSkip to conversation

Working on adt7475 driver

lm-sensors Hans de Goede 4 participants 9 messages Oct 5, 2007 – Dec 19, 2007

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hi all,

I just wanted to let everyone know that I've bought an asus m2n sli deluxe motherboard and that I now have a group of students working on writing a driver for the adt7475 as part of a Linux device driver course I'm teaching. They have gotten past the initial problems of learning kernel space thinking and leanring
to read datasheets, so I think they will succeed.

Depending on how much they like writing drivers they, or I myself, will submit this for review when its done.

I also have groups working on:
-watchdog support for the FSC hwmon IC's following the standard watchdog
userspace ABI, for the new fschmd driver
-pwm support for the f71882fg driver
-interrupt support for the intel801 i2c adapter driver

Regards,

Hans

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#1 lore raw

Hi Hans,

Quoted 10 lines · Hans de Goede

I just wanted to let everyone know that I've bought an asus m2n sli deluxe motherboard and that I now have a group of students working on writing a driver for the adt7475 as part of a Linux device driver course I'm teaching. They have gotten past the initial problems of learning kernel space thinking and leanring
to read datasheets, so I think they will succeed.

Depending on how much they like writing drivers they, or I myself, will submit this for review when its done.

I also have groups working on:

Review

Quoted 4 lines
(quoted diff) +0 -3
-watchdog support for the FSC hwmon IC's following the standard watchdog
  userspace ABI, for the new fschmd driver
-pwm support for the f71882fg driver
-interrupt support for the intel801 i2c adapter driver

Can you please update wiki/Devices accordingly?

Thanks,

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#2 lore raw
In reply to Hans de Goede
Quoted 12 lines · Jean Delvare

Hi Hans,

Quoted 9 lines · Hans de Goede

I just wanted to let everyone know that I've bought an asus m2n sli deluxe motherboard and that I now have a group of students working on writing a driver for the adt7475 as part of a Linux device driver course I'm teaching. They have gotten past the initial problems of learning kernel space thinking and leanring
to read datasheets, so I think they will succeed.

Depending on how much they like writing drivers they, or I myself, will submit this for review when its done.

Quoted 8 lines

Review

Quoted 5 lines

I also have groups working on:

(quoted diff) +0 -3
-watchdog support for the FSC hwmon IC's following the standard watchdog
  userspace ABI, for the new fschmd driver
-pwm support for the f71882fg driver
-interrupt support for the intel801 i2c adapter driver

Can you please update wiki/Devices accordingly?

Done.

Regards,

Hans

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#3 lore raw
In reply to Hans de Goede

Hi Hans,

Are your students in fact working on this driver? I ordered some samples of the ADT7475 & ADT7476 and could slap together a demo board and start working on a driver.

...juerg

Quoted 10 lines

I just wanted to let everyone know that I've bought an asus m2n sli deluxe motherboard and that I now have a group of students working on writing a driver for the adt7475 as part of a Linux device driver course I'm teaching. They have gotten past the initial problems of learning kernel space thinking and leanring
to read datasheets, so I think they will succeed.

Depending on how much they like writing drivers they, or I myself, will submit this for review when its done.

I also have groups working on:

Review

Quoted 4 lines
(quoted diff) +0 -3
-watchdog support for the FSC hwmon IC's following the standard watchdog
  userspace ABI, for the new fschmd driver
-pwm support for the f71882fg driver
-interrupt support for the intel801 i2c adapter driver

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#4 lore raw
In reply to Hans de Goede
Quoted 6 lines · Juerg Haefliger

Hi Hans,

Are your students in fact working on this driver? I ordered some samples of the ADT7475 & ADT7476 and could slap together a demo board and start working on a driver.

Yes,

They are actually working on this, still a demo bord would be good, as on the motherboard they are using for testing (Asus M2N SLI Deluxe) it is the second hwmon chip, mainly used to monitor and control additional fans.

I'll ask them to send what they have sofar my way and I'll send it to you, I'll see them again coming wednesday.

Regards,

Hans

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#5 lore raw
In reply to Hans de Goede

Hi Hans,

Quoted 8 lines · Hans de Goede
Quoted 6 lines · Juerg Haefliger

Hi Hans,

Are your students in fact working on this driver? I ordered some samples of the ADT7475 & ADT7476 and could slap together a demo board and start working on a driver.

Quoted 8 lines

Yes,

They are actually working on this, still a demo bord would be good, as on the motherboard they are using for testing (Asus M2N SLI Deluxe) it is the second hwmon chip, mainly used to monitor and control additional fans.

I'll ask them to send what they have sofar my way and I'll send it to you, I'll see them again coming wednesday.

OK I have a demo board with an ADT7476 ready. Whenever there's a driver ready that I can play around with, let me know. I have some other things I'm currently working on so no pressure.

...juerg

Quoted 5 lines

Regards,

Hans

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#6 lore raw
In reply to Hans de Goede
Quoted 17 lines · Juerg Haefliger

Hi Hans,

Quoted 13 lines · Hans de Goede
Quoted 6 lines · Juerg Haefliger

Hi Hans,

Are your students in fact working on this driver? I ordered some samples of the ADT7475 & ADT7476 and could slap together a demo board and start working on a driver.

Yes,

They are actually working on this, still a demo bord would be good, as on the motherboard they are using for testing (Asus M2N SLI Deluxe) it is the second hwmon chip, mainly used to monitor and control additional fans.

Quoted 7 lines
Quoted 2 lines

I'll ask them to send what they have sofar my way and I'll send it to you, I'll see them again coming wednesday.

OK I have a demo board with an ADT7476 ready. Whenever there's a driver ready that I can play around with, let me know. I have some other things I'm currently working on so no pressure.

I'm afraid that the motherboard used by the student has broken down somehow, so they can no longer continue their work. I've attached their latest wip, perhaps that can come in handy for you when working on a driver. The motherboard has been send in for repair once it returns I can use it for testing your work.

Regards,

Hans

/*
* adt7475.c - Part of lm_sensors, Linux kernel modules for hardware
* monitoring
* Copyright (C) 2007 Hans de Goede <[email protected]>
*
* 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. */

/*
* New merged Fujitsu Siemens hwmon driver, supporting the Poseidon, Hermes,
* Scylla, Hercules and Heimdall chips
*

 *  Based on the original 2.4 fscscy, 2.6 fscpos, 2.6 fscher and 2.6
 *  (candidate) fschmd drivers:
 *  Copyright (C) 2006 Thilo Cestonaro <[email protected]>
 *  Copyright (C) 2003, 2004 Reinhard Nissl <[email protected]>
 *  Copyright (C) 2000 Hermann Jung <[email protected]>
 *  Copyright (C) 1998, 1999 Frodo Looijaard <[email protected]>
 *  and Philip Edelbrock <[email protected]>

*/

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

/* Addresses to scan */
static unsigned short normal_i2c[] = { 0x2e, I2C_CLIENT_END };

/* Insmod parameters */
I2C_CLIENT_INSMOD_1(adt7475);

/* voltage supervision */
#define ADT7475_REG_IN_HIGH(nr) (0x21 + (nr))
#define ADT7475_REG_IN_LOW 0x76

/* voltage low, high limit registers */
#define ADT7475_REG_IN_LOW_LIMIT(nr) (0x46 + 2 * (nr))
#define ADT7475_REG_IN_HIGH_LIMIT(nr) (0x47 + 2 * (nr))

/* actual fan speed */
#define ADT7475_REG_FAN_ACT_LOW(nr) (0x28 + 2 * (nr))
#define ADT7475_REG_FAN_ACT_HIGH(nr) (0x29 + 2 * (nr))

/* ??? fan status registers */
static const u8 ADT7475_REG_FAN_STATE[1] = {1};

/* ??? fan ripple / divider registers */
static const u8 ADT7475_REG_FAN_RIPPLE[1] = {1};

/* fan low, high limit registers */
#define ADT7475_REG_FAN_LOW_LIMIT(nr) (0x54 + 2 * (nr))
#define ADT7475_REG_FAN_HIGH_LIMIT(nr) (0x55 + 2 * (nr))

/* fan puls register */
#define ADT7475_REG_FAN_PULS 0x7B

/* actual temperature registers */
#define ADT7475_REG_TEMP_ACT(nr) (0x25 + (nr))
#define ADT7475_REG_TEMP_LOW 0x77

/* temperature offset registers, NOTE only for twocomplement-mode*/
#define ADT7475_REG_TEMP_OFFSET(nr) (0x70 + (nr))

/* ??? temperature state registers */
#define ADT7475_REG_TEMP_STATE(nr) (0x25 + (nr))

/* temperature low, high limit registers */ #define ADT7475_REG_TEMP_LOW_LIMIT(nr) (0x4E + 2 * (nr)) #define ADT7475_REG_TEMP_HIGH_LIMIT(nr) (0x4F + 2 * (nr))

/* (Interrupt) status registers */
#define ADT7475_REG_INTR_STATUS(nr) (0x41 + (nr))

/* Interrupt mask registers */
#define ADT7475_REG_INTR_MASK(nr) (0x74 + (nr))

/* Configuration Registers */
static const u8 ADT7475_REG_CONFIG[7] = {0x40, 0x73, 0x78, 0x7D, 0x7C, 0x10, 0x11};

/* name */
#define ADT7475_NAME "adt7475"

/*
* Functions declarations
*/

static int adt7475_attach_adapter(struct i2c_adapter *adapter); static int adt7475_detach_client(struct i2c_client *client); static struct adt7475_data *adt7475_update_device(struct device *dev);

/*
* Driver data (common to all clients)
*/

static struct i2c_driver adt7475_driver = {
	.driver = {
		.name	= ADT7475_NAME,
	},
	.attach_adapter	= adt7475_attach_adapter,
	.detach_client	= adt7475_detach_client,
};

/*
* Client data (each client gets its own)
*/

struct adt7475_data {
	enum chips kind;
	struct i2c_client client;
	struct class_device *class_dev;
	struct mutex update_lock;
	char valid; /* zero until following fields are valid */
	unsigned long last_updated; /* in jiffies */

	/* register values */
	u8 global_control;	/* ??? global control register */
	u16 in[2];		/* voltage */ 
	u8 in_max[2];		/* high voltage limit */
	u8 in_min[2];		/* low voltage limit */
	u16 temp_act[3];	/* temperature  10 bit */
	u8 temp_status[3];	/* ??? status of sensor */
	u8 config[7];		/* Configuration Register 1-7*/
	u8 temp_max[3];		/* high temp limit */
	u8 temp_min[3];		/* low temp limit */
	u16 fan_act[4];		/* fans revolutions per second */
	u8 fan_status[4];	/* ??? fan status */
	u8 fan_min[4];		/* fan min value for rps */
	u8 fan_max[4];		/* fan max value for rps */
	u8 fan_ripple[4];	/* ??? divider for rps */
	u8 intr_status[2];	/* Interrupt status registers 1+2 */
};

/*
* Sysfs attr show / store functions
*/

static ssize_t show_in_value(struct device *dev, struct device_attribute *devattr, char *buf)

{
	const int factor[2] = {293, 420};
	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
	struct adt7475_data *data = adt7475_update_device(dev);

	return sprintf(buf, "%d\n", (data->in[attr->index] * factor[attr->index]) / 10);
}

static ssize_t show_in_max(struct device *dev, struct device_attribute *devattr, char *buf)

{
	const int factor[2] = {293, 420};
	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
	struct adt7475_data *data = adt7475_update_device(dev);

	return sprintf(buf, "%d\n", (data->in_max[attr->index] * factor[attr->index]) / 10 );
}

static ssize_t store_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 adt7475_data *data = i2c_get_clientdata(to_i2c_client(dev));
	long v = simple_strtol(buf, NULL, 10) / 1000;

	v = SENSORS_LIMIT(v, -128, 127);
	v += 128;

	mutex_lock(&data->update_lock);
	i2c_smbus_write_byte_data(&data->client, ADT7475_REG_IN_HIGH_LIMIT(attr->index), v);
	data->in_max[attr->index] = v;
	mutex_unlock(&data->update_lock);

	return count;
}

static ssize_t show_in_min(struct device *dev, struct device_attribute *devattr, char *buf)

{
	const int factor[2] = {293, 420};
	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
	struct adt7475_data *data = adt7475_update_device(dev);

	return sprintf(buf, "%d\n", (data->in_min[attr->index] * factor[attr->index]) / 10 );
}

static ssize_t store_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 adt7475_data *data = i2c_get_clientdata(to_i2c_client(dev));
	long v = simple_strtol(buf, NULL, 10) / 1000;

	v = SENSORS_LIMIT(v, -128, 127);
	v += 128;

	mutex_lock(&data->update_lock);
	i2c_smbus_write_byte_data(&data->client, ADT7475_REG_IN_LOW_LIMIT(attr->index), v);
	data->in_min[attr->index] = v;
	mutex_unlock(&data->update_lock);

	return count;
}

#define TEMP_FROM_REG_TWOSCOMPLEMENT_8(val) ((((val) & 0x80) ? (((val) & 0x01FF) - 128) : ((val) & 0x01FF)) * 1000)
#define TEMP_FROM_REG_EXTENDED(val) (((val) - 256) * 250)
#define TEMP_FROM_REG_TWOSCOMPLEMENT_10(val) ((((val) & 0x0200) ? (((val) & 0x01FF) - 512) : ((val) & 0x01FF)) * 250)

static ssize_t show_temp_value(struct device *dev, struct device_attribute *devattr, char *buf)

{
	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
	struct adt7475_data *data = adt7475_update_device(dev);

	if(data->config[4] & 0x01) return sprintf(buf, "%d\n", TEMP_FROM_REG_TWOSCOMPLEMENT_10(data->temp_act[attr->index]));
	else return sprintf(buf, "%d\n", TEMP_FROM_REG_EXTENDED(data->temp_act[attr->index]));
}

static ssize_t show_temp_max(struct device *dev, struct device_attribute *devattr, char *buf)

{
	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
	struct adt7475_data *data = adt7475_update_device(dev);

	return sprintf(buf, "%d\n", TEMP_FROM_REG_TWOSCOMPLEMENT_8( data->temp_max[attr->index]));
}

static ssize_t store_temp_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 adt7475_data *data = i2c_get_clientdata(to_i2c_client(dev));
	long v = simple_strtol(buf, NULL, 10) / 1000;

	v = SENSORS_LIMIT(v, -128, 127);
	v += 128;

	mutex_lock(&data->update_lock);
	i2c_smbus_write_byte_data(&data->client, ADT7475_REG_TEMP_HIGH_LIMIT(attr->index), v);
	data->temp_max[attr->index] = v;
	mutex_unlock(&data->update_lock);

	return count;
}

static ssize_t show_temp_min(struct device *dev, struct device_attribute *devattr, char *buf)

{
	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
	struct adt7475_data *data = adt7475_update_device(dev);

	return sprintf(buf, "%d\n", TEMP_FROM_REG_TWOSCOMPLEMENT_8( data->temp_min[attr->index]));
}

static ssize_t store_temp_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 adt7475_data *data = i2c_get_clientdata(to_i2c_client(dev));
	long v = simple_strtol(buf, NULL, 10) / 1000;

	v = SENSORS_LIMIT(v, -128, 127);
	v += 128;

	mutex_lock(&data->update_lock);
	i2c_smbus_write_byte_data(&data->client, ADT7475_REG_TEMP_LOW_LIMIT(attr->index), v);
	data->temp_min[attr->index] = v;
	mutex_unlock(&data->update_lock);

	return count;
}

static ssize_t show_temp_fault(struct device *dev, struct device_attribute *devattr, char *buf)

{
	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
	struct adt7475_data *data = adt7475_update_device(dev);
	u8 mask = 0x40 << attr->index;

	return sprintf(buf, "%d\n", ((data->intr_status[1] & mask) != 0));
}

/*
static ssize_t show_temp_fault(struct device *dev,
struct device_attribute *devattr, char *buf)

{
	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
	struct fschmd_data *data = fschmd_update_device(dev);

	*//* bit 0 set means sensor working ok, so no fault! *//*
	if (data->temp_status[attr->index] & 0x01)
		return sprintf(buf, "0\n");
	else
		return sprintf(buf, "1\n");
}

static ssize_t show_temp_alarm(struct device *dev,
struct device_attribute *devattr, char *buf)

{
	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
	struct fschmd_data *data = fschmd_update_device(dev);

	*//* only signal an alarm if the sensor is working and alert == 1 *//*
	if ((data->temp_status[attr->index] & 0x03) == 0x03)
		return sprintf(buf, "1\n");
	else
		return sprintf(buf, "0\n");
}

*/

#define RPM_FROM_REG(val) (val == 0xFFFF) ? 0 : ((90000*60)/(val))

static ssize_t show_fan_value(struct device *dev, struct device_attribute *devattr, char *buf)

{
	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
	struct adt7475_data *data = adt7475_update_device(dev);

	return sprintf(buf, "%d\n", RPM_FROM_REG(data->fan_act[attr->index]));
}

static ssize_t show_fan_max(struct device *dev, struct device_attribute *devattr, char *buf)

{
	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
	struct adt7475_data *data = adt7475_update_device(dev);

	return sprintf(buf, "%d\n", data->fan_max[attr->index]);
}

static ssize_t store_fan_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 adt7475_data *data = i2c_get_clientdata(to_i2c_client(dev));
	long v = simple_strtol(buf, NULL, 10) / 1000;

	v = SENSORS_LIMIT(v, -128, 127);
	v += 128;

	mutex_lock(&data->update_lock);
	i2c_smbus_write_byte_data(&data->client, ADT7475_REG_FAN_HIGH_LIMIT(attr->index), v);
	data->fan_max[attr->index] = v;
	mutex_unlock(&data->update_lock);

	return count;
}

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 adt7475_data *data = adt7475_update_device(dev);

	return sprintf(buf, "%d\n", data->fan_min[attr->index]);
}

static ssize_t store_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 adt7475_data *data = i2c_get_clientdata(to_i2c_client(dev));
	long v = simple_strtol(buf, NULL, 10) / 1000;

	v = SENSORS_LIMIT(v, -128, 127);
	v += 128;

	mutex_lock(&data->update_lock);
	i2c_smbus_write_byte_data(&data->client, ADT7475_REG_FAN_LOW_LIMIT(attr->index), v);
	data->fan_min[attr->index] = v;
	mutex_unlock(&data->update_lock);

	return count;
}

static ssize_t show_fan_fault(struct device *dev, struct device_attribute *devattr, char *buf)

{
	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
	struct adt7475_data *data = adt7475_update_device(dev);
	u8 mask = 0x02 << attr->index;

	return sprintf(buf, "%d\n", (data->config[1] & mask));
}

/*
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 fschmd_data *data = fschmd_update_device(dev);

	*//* bits 2..7 reserved => mask with 3 *//*  
	return sprintf(buf, "%d\n", 1 << (data->fan_ripple[attr->index] & 3));
}

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

{
	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
	struct fschmd_data *data = fschmd_update_device(dev);
	*//* supported values: 2, 4, 8 *//*
	unsigned long v = simple_strtoul(buf, NULL, 10);

	switch (v) {
		case 2: v = 1; break;
		case 4: v = 2; break;
		case 8: v = 3; break;
		default:
			dev_err(&data->client.dev, "fan_div value %lu not "
				 "supported. Choose one of 2, 4 or 8!\n", v);
			return -EINVAL;
	}

	mutex_lock(&data->update_lock);

	*//* bits 2..7 reserved => mask with 0x03 *//*
	data->fan_ripple[attr->index] &= ~0x03;
	data->fan_ripple[attr->index] |= v;

	i2c_smbus_write_byte_data(&data->client,
		FSCHMD_REG_FAN_RIPPLE[data->kind][attr->index],
		data->fan_ripple[attr->index]);

	mutex_unlock(&data->update_lock);

	return count;
}

static ssize_t show_fan_alarm(struct device *dev,
struct device_attribute *devattr, char *buf)

{
	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
	struct fschmd_data *data = fschmd_update_device(dev);

	if (data->fan_status[attr->index] & 0x04)
		return sprintf(buf, "1\n");
	else
		return sprintf(buf, "0\n");
}

static ssize_t show_pwm_auto_point1_pwm(struct device *dev,
struct device_attribute *devattr, char *buf)

{
	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
	int val = fschmd_update_device(dev)->fan_min[attr->index];

	*//* 0 = allow turning off, 1-255 = 50-100% *//*
	if (val)
		val = val / 2 + 128;
	
	return sprintf(buf, "%d\n", val);
}

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

{
	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
	struct fschmd_data *data = i2c_get_clientdata(to_i2c_client(dev));
	unsigned long v = simple_strtoul(buf, NULL, 10);
	
	*//* register: 0 = allow turning off, 1-255 = 50-100% *//*
	if (v) {
		SENSORS_LIMIT(v, 128, 255);
		v = (v - 128) * 2 + 1;
	}

	mutex_lock(&data->update_lock);

	i2c_smbus_write_byte_data(&data->client,
		FSCHMD_REG_FAN_MIN[data->kind][attr->index], v);
	data->fan_min[attr->index] = v;

	mutex_unlock(&data->update_lock);
	
	return count;
}

*/

/* The FSC hwmon family has the ability to force an attached alert led to flash
from software, we export this as an alert_led sysfs attr */
/*static ssize_t show_alert_led(struct device *dev,
struct device_attribute *devattr, char *buf)

{
	struct fschmd_data *data = fschmd_update_device(dev);

	if (data->global_control & 0x01)
		return sprintf(buf, "1\n");
	else
		return sprintf(buf, "0\n");
}

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

{
	struct fschmd_data *data = fschmd_update_device(dev);
	unsigned long v = simple_strtoul(buf, NULL, 10);

	mutex_lock(&data->update_lock);
	
	if (v)
		data->global_control |= 0x01;
	else
		data->global_control &= ~0x01;

	i2c_smbus_write_byte_data(&data->client, FSCHMD_REG_CONTROL, v);
	mutex_unlock(&data->update_lock);

	return count;
}*/
static struct sensor_device_attribute adt7475_in_attr[] = {
	SENSOR_ATTR(in0_input, 0444, show_in_value, NULL, 0),
	SENSOR_ATTR(in0_min,   0644, show_in_min, store_in_min, 0),
	SENSOR_ATTR(in0_max,   0644, show_in_max, store_in_max, 0),
	SENSOR_ATTR(in0_fault,   0444, show_in_fault, NULL, 0),
	SENSOR_ATTR(in1_input, 0444, show_in_value, NULL, 1),
	SENSOR_ATTR(in1_min,   0644, show_in_min, store_in_min, 1),
	SENSOR_ATTR(in1_max,   0644, show_in_max, store_in_max, 1),
	SENSOR_ATTR(in1_fault,   0444, show_in_fault, NULL, 1),
	//SENSOR_ATTR(alert_led, 0644, show_alert_led, store_alert_led, 0),
};
static struct sensor_device_attribute adt7475_temp_attr[] = {
	SENSOR_ATTR(temp1_input, 0444, show_temp_value, NULL, 0),
	SENSOR_ATTR(temp1_min,   0644, show_temp_min, store_temp_min, 0),
	SENSOR_ATTR(temp1_max,   0644, show_temp_max, store_temp_max, 0),
	//SENSOR_ATTR(temp1_fault, 0444, show_temp_fault, NULL, 0),
	//SENSOR_ATTR(temp1_alarm, 0444, show_temp_alarm, NULL, 0),
	SENSOR_ATTR(temp2_input, 0444, show_temp_value, NULL, 1),
	SENSOR_ATTR(temp2_min,   0644, show_temp_min, store_temp_min, 1),
	SENSOR_ATTR(temp2_max,   0644, show_temp_max, store_temp_max, 1),
	//SENSOR_ATTR(temp2_fault, 0444, show_temp_fault, NULL, 1),
	//SENSOR_ATTR(temp2_alarm, 0444, show_temp_alarm, NULL, 1),
	SENSOR_ATTR(temp3_input, 0444, show_temp_value, NULL, 2),
	SENSOR_ATTR(temp3_min,   0644, show_temp_min, store_temp_min, 2),
	SENSOR_ATTR(temp3_max,   0644, show_temp_max, store_temp_max, 2),
	//SENSOR_ATTR(temp3_fault, 0444, show_temp_fault, NULL, 2),
	//SENSOR_ATTR(temp3_alarm, 0444, show_temp_alarm, NULL, 2),
};
static struct sensor_device_attribute adt7475_fan_attr[] = {
	SENSOR_ATTR(fan1_input, 0444, show_fan_value, NULL, 0),
	SENSOR_ATTR(fan1_min,   0644, show_fan_min, store_fan_min, 0),
	SENSOR_ATTR(fan1_max,   0644, show_fan_max, store_fan_max, 0),
	//SENSOR_ATTR(fan1_div,   0644, show_fan_div, store_fan_div, 0),
	//SENSOR_ATTR(fan1_alarm, 0444, show_fan_alarm, NULL, 0),
	//SENSOR_ATTR(pwm1_auto_point1_pwm, 0644, show_pwm_auto_point1_pwm, store_pwm_auto_point1_pwm, 0),
	SENSOR_ATTR(fan2_input, 0444, show_fan_value, NULL, 1),
	SENSOR_ATTR(fan2_min,   0644, show_fan_min, store_fan_min, 1),
	SENSOR_ATTR(fan2_max,   0644, show_fan_max, store_fan_max, 1),
	//SENSOR_ATTR(fan2_div,   0644, show_fan_div, store_fan_div, 1),
	//SENSOR_ATTR(fan2_alarm, 0444, show_fan_alarm, NULL, 1),
	//SENSOR_ATTR(pwm2_auto_point1_pwm, 0644, show_pwm_auto_point1_pwm,store_pwm_auto_point1_pwm, 1),
	SENSOR_ATTR(fan3_input, 0444, show_fan_value, NULL, 2),
	SENSOR_ATTR(fan3_min,   0644, show_fan_min, store_fan_min, 2),
	SENSOR_ATTR(fan3_max,   0644, show_fan_max, store_fan_max, 2),
	//SENSOR_ATTR(fan3_div,   0644, show_fan_div, store_fan_div, 2),
	//SENSOR_ATTR(fan3_alarm, 0444, show_fan_alarm, NULL, 2),
	//SENSOR_ATTR(pwm3_auto_point1_pwm, 0644, show_pwm_auto_point1_pwm, store_pwm_auto_point1_pwm, 2),
	SENSOR_ATTR(fan4_input, 0444, show_fan_value, NULL, 3),
	SENSOR_ATTR(fan4_min,   0644, show_fan_min, store_fan_min, 3),
	SENSOR_ATTR(fan4_max,   0644, show_fan_max, store_fan_max, 3),
	//SENSOR_ATTR(fan4_div,   0644, show_fan_div, store_fan_div, 3),
	//SENSOR_ATTR(fan4_alarm, 0444, show_fan_alarm, NULL, 3),
	//SENSOR_ATTR(pwm4_auto_point1_pwm, 0644, show_pwm_auto_point1_pwm,store_pwm_auto_point1_pwm, 3),
};

/*
* Real code
*/

static int adt7475_detect(struct i2c_adapter *adapter, int address, int kind)

{
	struct i2c_client *new_client;
	struct adt7475_data *data;
	u8 revision;
	int i, err = 0;

	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
		return 0;

	/* OK. For now, we presume we have a valid client. We now create the
	 * client structure, even though we cannot fill it completely yet.
	 * But it allows us to access i2c_smbus_read_byte_data. */
	if (!(data = kzalloc(sizeof(struct adt7475_data), GFP_KERNEL)))
		return -ENOMEM;

	/* The common I2C client data is placed right before the
	 * Poseidon-specific data. */
	new_client = &data->client;
	i2c_set_clientdata(new_client, data);
	new_client->addr = address;
	new_client->adapter = adapter;
	new_client->driver = &adt7475_driver;
	new_client->flags = 0;
	strlcpy(new_client->name, ADT7475_NAME, I2C_NAME_SIZE);
	data->valid = 0;
	mutex_init(&data->update_lock);

	/* i2c kind goes from 1-4, we want from 0-3 to address arrays */
	data->kind = kind - 1;

	/* Tell the I2C layer a new client has arrived */
	if ((err = i2c_attach_client(new_client)))
		goto exit_free;

	/* Add attributes */
	for(i = 0; i < ARRAY_SIZE(adt7475_in_attr); ++i) 
	{
		err = device_create_file(&new_client->dev, &adt7475_in_attr[i].dev_attr);
		if (err) goto exit_remove_files;
	}

	for(i = 0; i < ARRAY_SIZE(adt7475_temp_attr); ++i) 
	{
		err = device_create_file(&new_client->dev, &adt7475_temp_attr[i].dev_attr);
		if (err) goto exit_remove_files;
	}

	for(i = 0; i < ARRAY_SIZE(adt7475_fan_attr); ++i) 
	{
		err = device_create_file(&new_client->dev,&adt7475_fan_attr[i].dev_attr);
		if (err) goto exit_remove_files;
	}

	data->class_dev = hwmon_device_register(&new_client->dev);
	if (IS_ERR(data->class_dev)) {
		err = PTR_ERR(data->class_dev);
		goto exit_remove_files;
	}

	// ??? revision = i2c_smbus_read_byte_data(new_client, ADT7475_REG_REVISION);
	printk(KERN_INFO "adt7475: Detected adt7475 chip\n");

	return 0;

exit_remove_files:

	for(i = 0; i < ARRAY_SIZE(adt7475_in_attr); ++i) device_remove_file(&new_client->dev, &adt7475_in_attr[i].dev_attr);
	for(i = 0; i < ARRAY_SIZE(adt7475_temp_attr); ++i) device_remove_file(&new_client->dev, &adt7475_temp_attr[i].dev_attr);
	for(i = 0; i < ARRAY_SIZE(adt7475_fan_attr); ++i) device_remove_file(&new_client->dev, &adt7475_fan_attr[i].dev_attr);

	i2c_detach_client(new_client);
exit_free:
	kfree(data);
	return err;
}

static int adt7475_attach_adapter(struct i2c_adapter *adapter)

{
	if (!(adapter->class & I2C_CLASS_HWMON)) return 0;
	return i2c_probe(adapter, &addr_data, adt7475_detect);
}

static int adt7475_detach_client(struct i2c_client *client)

{
	struct adt7475_data *data = i2c_get_clientdata(client);
	int i, err;

	hwmon_device_unregister(data->class_dev);

	for(i = 0; i < ARRAY_SIZE(adt7475_in_attr); ++i) device_remove_file(&client->dev, &adt7475_in_attr[i].dev_attr);
	for(i = 0; i < ARRAY_SIZE(adt7475_temp_attr); ++i) device_remove_file(&client->dev, &adt7475_temp_attr[i].dev_attr);
	for(i = 0; i < ARRAY_SIZE(adt7475_fan_attr); ++i) device_remove_file(&client->dev, &adt7475_fan_attr[i].dev_attr);


	if ((err = i2c_detach_client(client)))
		return err;

	kfree(data);
	return 0;
}

static struct adt7475_data *adt7475_update_device(struct device *dev)

{
	struct i2c_client *client = to_i2c_client(dev);
	struct adt7475_data *data = i2c_get_clientdata(client);
	u8 reg_in_low, reg_temp_low, fan_act_low;
	int i;

	mutex_lock(&data->update_lock);

	if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) 
	{	
		/* Read voltage */
		/* First read low byte because otherwise the high-registers will be frozen */
		reg_in_low = i2c_smbus_read_byte_data(client, ADT7475_REG_IN_LOW);
		for(i = 0; i < 2; i++)
		{
			/* Read high voltage */
			data->in[i] = i2c_smbus_read_byte_data(client, ADT7475_REG_IN_HIGH(i)) << 2 | (reg_in_low >> (2 + 2 * i) & 0x03);

			/* Read high limit, low limit voltage */
			data->in_max[i] = i2c_smbus_read_byte_data(client, ADT7475_REG_IN_HIGH_LIMIT(i));
			data->in_min[i] = i2c_smbus_read_byte_data(client, ADT7475_REG_IN_LOW_LIMIT(i));
		}

		/* Read Temperatures */
		/* First read low byte because otherwise the high-registers will be frozen */
		reg_temp_low = i2c_smbus_read_byte_data(client, ADT7475_REG_TEMP_LOW);
		for(i = 0; i < 3; i++)
		{
			/* Read high temp*/
			data->temp_act[i] = i2c_smbus_read_byte_data(client, ADT7475_REG_TEMP_ACT(i)) << 2 | (reg_temp_low >> (6 - 2 * i)& 0x03);

			/* Read high limit, low limit temperatures */
			data->temp_max[i] = i2c_smbus_read_byte_data(client, ADT7475_REG_TEMP_HIGH_LIMIT(i));
			data->temp_min[i] = i2c_smbus_read_byte_data(client, ADT7475_REG_TEMP_LOW_LIMIT(i));
		}

		/* Read fan speeds */
// !!! Er is geen maximale fan speed, dit is een 16 bit waarde
// !!! Need to read the HIGH register first to activate the fan measurement! adt7475 manual page 28
		/* First read low byte because otherwise the high-registers will be frozen */
		for(i = 0; i < 4; i++)
		{
			fan_act_low = i2c_smbus_read_byte_data(client, ADT7475_REG_FAN_ACT_LOW(i));
			data->fan_act[i] = i2c_smbus_read_byte_data(client, ADT7475_REG_FAN_ACT_HIGH(i)) << 8 | fan_act_low;

			// lees minimale fan waarde. 16bit

		}

		/* Read Configuration Registers */
		for(i = 0; i < ARRAY_SIZE(ADT7475_REG_CONFIG); i++)
			data->config[i] = i2c_smbus_read_byte_data(client, ADT7475_REG_CONFIG[i]);

		/* Read Status Registers */
		for(i = 0; i < 2; i++)
			data->intr_status[i] = i2c_smbus_read_byte_data(client, ADT7475_REG_INTR_STATUS(i));

		/* ??? Read Global */
		// data->global_control = i2c_smbus_read_byte_data(client, ADT7475_REG_CONTROL);

		data->last_updated = jiffies;
		data->valid = 1;
	}

	mutex_unlock(&data->update_lock);

	return data;
}

static int __init adt7475_init(void)

{
	printk(KERN_INFO "adt7475 driver loaded\n");
	return i2c_add_driver(&adt7475_driver);
}

static void __exit adt7475_exit(void)

{
	printk(KERN_INFO "adt7475 driver unloaded\n");
	i2c_del_driver(&adt7475_driver);
}

MODULE_AUTHOR("Hans de Goede <[email protected]>"); MODULE_DESCRIPTION("ADT7475 driver"); MODULE_LICENSE("GPL");

module_init(adt7475_init);
module_exit(adt7475_exit);

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#7 lore raw
In reply to Hans de Goede

Hi Hans,

Quoted 4 lines · Hans de Goede

I'm afraid that the motherboard used by the student has broken down somehow, so they can no longer continue their work. I've attached their latest wip, perhaps that can come in handy for you when working on a driver. The motherboard has been send in for repair once it returns I can use it for testing your work.

Please update wiki/Devices accordingly.

Quoted 4 lines

/*
* New merged Fujitsu Siemens hwmon driver, supporting the Poseidon, Hermes,
* Scylla, Hercules and Heimdall chips
*

Quoted 8 lines
 *  Based on the original 2.4 fscscy, 2.6 fscpos, 2.6 fscher and 2.6
 *  (candidate) fschmd drivers:
 *  Copyright (C) 2006 Thilo Cestonaro <[email protected]>
 *  Copyright (C) 2003, 2004 Reinhard Nissl <[email protected]>
 *  Copyright (C) 2000 Hermann Jung <[email protected]>
 *  Copyright (C) 1998, 1999 Frodo Looijaard <[email protected]>
 *  and Philip Edelbrock <[email protected]>

*/

This part looks completely bogus to me.

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#8 lore raw
In reply to Hans de Goede

In true open source style, I had also been working on an adt7475 driver around the same time as Hans and Juerg. I previously sent it to them in the hopes that it could be useful, and they kindly responded with some suggestions, which I have integrated here.

So I offer this freely - if this is interesting to anybody, please feel free to use it, otherwise ignore it. I also offer myself up as a testing resource if anybody needs it for subsequent drivers.

Jordan

Signature · 3 lines
Jordan Crouse
Systems Software Development Engineer 
Advanced Micro Devices, Inc.

[PATCH] hwmon: Add a driver for the ADT7475 thermal sensor

From: Jordan Crouse <[email protected]>

HWMON driver for the ADT7475 thermal sensor.

---

 Documentation/hwmon/adt7475 |  110 +++++
 drivers/hwmon/Kconfig       |   10 
 drivers/hwmon/Makefile      |    1 
 drivers/hwmon/adt7475.c     |  965 +++++++++++++++++++++++++++++++++++++++++++
 include/linux/i2c-id.h      |    2 
 5 files changed, 1087 insertions(+), 1 deletions(-)
Documentation/hwmon/adt7475 new file +110 -0
new file mode 100644
index 0000000..491e5e0
@@ -0,0 +1,110 @@
+This describes the interface for the ADT7475 driver:
+
+(there are 4 fans, numbered fan1 to fan4):
+
+fanX_input              Read the current speed of the fan (in RPMs)
+fanX_min                Read/write the minimum speed of the fan.  Dropping
+	   		below this sets an alarm.
+
+(there are three PWMs, numbered pwm1 to pwm3):
+
+pwmX                    Read/write the current duty cycle of the PWM.  Writes
+     			only have effect when auto mode is turned off (see
+			below).
+
+pwmX_enable             Read/write the PWM configuration based on the following
+                        table:
+
+		        0 - Remote1 temp controls PWMx (auto mode)
+		        1 - local temp controls PWMx (auto mode)
+	 	        2 - remote2 temp controls PWMx (auto mode)
+                        3 - PWMx runs at full speed
+                        4 - PWMx is disabled
+                        5 - Use fastest speed calculated by local and remote2
+                        6 - Use fastest speed calculated by all three channels
+                        7 - Manual mode
+
+pwmX_freq               Read/write the PWM frequency.  The value returned is
+	  	        an index into the following table:
+
+		        0x0 - 11.0 Hz
+		        0x1 - 14.7 Hz
+		        0x2 - 22.1 Hz
+		        0x3 - 29.4 Hz
+		        0x4 - 35.3 Hz
+		        0x5 - 44.1 Hz
+		        0x6 - 58.8 Hz
+		        0x7 - 88.2 Hz
+
+pwmX_max                Read/write the maximum PWM duty cycle.  The PWM
+                        duty cycle will never exceed this.
+
+pwmX_min                Read/write the minimum PWM duty cycle in automatic mode
+
+(there are three temperature settings numbered temp1 to temp3):
+
+tempX_input             Read the current temperature.  The value is in milli
+			degrees of Celsius.
+
+tempX_label		Returns the "name" of the sensor as described in the
+			datasheet (remote1, local, or remote2)
+
+tempX_max               Read/write the upper temperature limit - exceeding this
+	                will cause an alarm.
+
+tempX_min               Read/write the lower temperature limit - exceeding this
+                        will cause an alarm.
+
+tempX_offset            Read/write the temperature adjustment offset
+
+tempX_crit_max        Read/write the THERM limit for remote1.  Exceeding this
+                        causes the chip to force the processor off.
+
+tempX_auto_min   	Read/write the minimum temperature where the fans will
+                        turn on in automatic mode.
+
+tempX_auto_range  	Read/write the range over which the automatic fan
+			control will be executed.  The value returned is a
+			index into the following table:
+
+			0x0 - 2 C
+			0x1 - 2.5 C
+			0x2 - 3.33 C
+			0x3 - 4 C
+			0x4 - 5 C
+			0x5 - 6.67 C
+			0x6 - 8 C
+			0x7 - 10 C
+			0x8 - 13.33 C
+			0x9 - 16 C
+			0xA - 20 C
+			0xB - 26.67 C
+			0xC - 32 C
+			0xD - 40 C
+			0xE - 53.33 C
+			0xF - 80 C
+
+tempX_crit_hyst 	set the temperature range below crit_max where the
+                        fans will stay on - this helps drive the temperature
+                        low enough so it doesn't stay near the edge and
+                        cause THERM to keep tripping.
+
+tempX_alarm		Read a 1 if the max/min alarm is set
+tempX_crit_alarm	Read a 1 if the critical limit is exceeded
+tempX_fault		Read a 1 if either temp1 or temp3 diode has a fault
+
+(There are two voltage settings, in1 and in2):
+
+inX_input               Read the current voltage on VCC.  Value is in
+			millivolts.
+
+inX_min                 read/write the minimum voltage limit.
+			Dropping below this causes an alarm.
+
+inX_max   		read/write the maximum voltage limit.
+			Exceeding this causes an alarm.
+
+inX_label		Return the name of the input as specified in the
+			datasheet (vcc or vccp)
+
+inX_alarm		Read a 1 if the max/min alarm is set.
drivers/hwmon/Kconfig +10 -0
index a0445be..5c25fde 100644
@@ -143,6 +143,16 @@ config SENSORS_ADT7470
 	  This driver can also be built as a module. If so, the module
 	  will be called adt7470.
 
+config SENSORS_ADT7475
+	tristate "Analog Devices ADT7475"
+	depends on I2C && EXPERIMENTAL
+	help
+	  If you say yes here you get support for the Analog Devices
+	  ADT7475 sensor chip.
+
+	  This driver can also be build as a module.  If so, the module
+	  will be called adt7475.
+
 config SENSORS_K8TEMP
 	tristate "AMD Athlon64/FX or Opteron temperature sensor"
 	depends on X86 && PCI && EXPERIMENTAL
drivers/hwmon/Makefile +1 -0
index 55595f6..5c95b2b 100644
@@ -23,6 +23,7 @@ obj-$(CONFIG_SENSORS_ADM1029)	+= adm1029.o
 obj-$(CONFIG_SENSORS_ADM1031)	+= adm1031.o
 obj-$(CONFIG_SENSORS_ADM9240)	+= adm9240.o
 obj-$(CONFIG_SENSORS_ADT7470)	+= adt7470.o
+obj-$(CONFIG_SENSORS_ADT7475)   += adt7475.o
 obj-$(CONFIG_SENSORS_APPLESMC)	+= applesmc.o
 obj-$(CONFIG_SENSORS_AMS)	+= ams/
 obj-$(CONFIG_SENSORS_ATXP1)	+= atxp1.o
drivers/hwmon/adt7475.c new file +965 -0

965 lines not on this page · raw message

include/linux/i2c-id.h +1 -1
index 88c8140..6e3f8e0 100644
@@ -163,7 +163,7 @@
 #define I2C_DRIVERID_FSCHER 1046
 #define I2C_DRIVERID_W83L785TS 1047
 #define I2C_DRIVERID_OV7670 1048	/* Omnivision 7670 camera */
-
+#define I2C_DRIVERID_ADT74XX 1049
 /*
  * ---- Adapter types ----------------------------------------------------
  */

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors