diff options
Diffstat (limited to 'drivers/hwmon/pc87360.c')
| -rw-r--r-- | drivers/hwmon/pc87360.c | 725 | 
1 files changed, 412 insertions, 313 deletions
diff --git a/drivers/hwmon/pc87360.c b/drivers/hwmon/pc87360.c index 68e69a49633..988181e4cfc 100644 --- a/drivers/hwmon/pc87360.c +++ b/drivers/hwmon/pc87360.c @@ -1,7 +1,7 @@  /*   *  pc87360.c - Part of lm_sensors, Linux kernel modules   *              for hardware monitoring - *  Copyright (C) 2004, 2007 Jean Delvare <khali@linux-fr.org> + *  Copyright (C) 2004, 2007 Jean Delvare <jdelvare@suse.de>   *   *  Copied from smsc47m1.c:   *  Copyright (C) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com> @@ -33,6 +33,8 @@   *  the standard Super-I/O addresses is used (0x2E/0x2F or 0x4E/0x4F).   */ +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +  #include <linux/module.h>  #include <linux/init.h>  #include <linux/slab.h> @@ -54,11 +56,11 @@ static u8 confreg[4];  static int init = 1;  module_param(init, int, 0);  MODULE_PARM_DESC(init, - "Chip initialization level:\n" - " 0: None\n" - "*1: Forcibly enable internal voltage and temperature channels, except in9\n" - " 2: Forcibly enable all voltage and temperature channels, except in9\n" - " 3: Forcibly enable all voltage and temperature channels, including in9"); +"Chip initialization level:\n" +" 0: None\n" +"*1: Forcibly enable internal voltage and temperature channels, except in9\n" +" 2: Forcibly enable all voltage and temperature channels, except in9\n" +" 3: Forcibly enable all voltage and temperature channels, including in9");  static unsigned short force_id;  module_param(force_id, ushort, 0); @@ -86,19 +88,19 @@ static const u8 logdev[LDNI_MAX] = { FSCM, VLM, TMS };  static inline void superio_outb(int sioaddr, int reg, int val)  {  	outb(reg, sioaddr); -	outb(val, sioaddr+1); +	outb(val, sioaddr + 1);  }  static inline int superio_inb(int sioaddr, int reg)  {  	outb(reg, sioaddr); -	return inb(sioaddr+1); +	return inb(sioaddr + 1);  }  static inline void superio_exit(int sioaddr)  {  	outb(0x02, sioaddr); -	outb(0x02, sioaddr+1); +	outb(0x02, sioaddr + 1);  }  /* @@ -120,18 +122,18 @@ static inline void superio_exit(int sioaddr)  #define PC87360_REG_FAN(nr)		(0x07 + 3 * (nr))  #define PC87360_REG_FAN_STATUS(nr)	(0x08 + 3 * (nr)) -#define FAN_FROM_REG(val,div)		((val) == 0 ? 0: \ -					 480000 / ((val)*(div))) -#define FAN_TO_REG(val,div)		((val) <= 100 ? 0 : \ -					 480000 / ((val)*(div))) -#define FAN_DIV_FROM_REG(val)		(1 << ((val >> 5) & 0x03)) +#define FAN_FROM_REG(val, div)		((val) == 0 ? 0 : \ +					 480000 / ((val) * (div))) +#define FAN_TO_REG(val, div)		((val) <= 100 ? 0 : \ +					 480000 / ((val) * (div))) +#define FAN_DIV_FROM_REG(val)		(1 << (((val) >> 5) & 0x03))  #define FAN_STATUS_FROM_REG(val)	((val) & 0x07) -#define FAN_CONFIG_MONITOR(val,nr)	(((val) >> (2 + nr * 3)) & 1) -#define FAN_CONFIG_CONTROL(val,nr)	(((val) >> (3 + nr * 3)) & 1) -#define FAN_CONFIG_INVERT(val,nr)	(((val) >> (4 + nr * 3)) & 1) +#define FAN_CONFIG_MONITOR(val, nr)	(((val) >> (2 + (nr) * 3)) & 1) +#define FAN_CONFIG_CONTROL(val, nr)	(((val) >> (3 + (nr) * 3)) & 1) +#define FAN_CONFIG_INVERT(val, nr)	(((val) >> (4 + (nr) * 3)) & 1) -#define PWM_FROM_REG(val,inv)		((inv) ? 255 - (val) : (val)) +#define PWM_FROM_REG(val, inv)		((inv) ? 255 - (val) : (val))  static inline u8 PWM_TO_REG(int val, int inv)  {  	if (inv) @@ -157,10 +159,10 @@ static inline u8 PWM_TO_REG(int val, int inv)  #define PC87365_REG_IN_ALARMS2		0x01  #define PC87365_REG_VID			0x06 -#define IN_FROM_REG(val,ref)		(((val) * (ref) + 128) / 256) -#define IN_TO_REG(val,ref)		((val) < 0 ? 0 : \ -					 (val)*256 >= (ref)*255 ? 255: \ -					 ((val) * 256 + (ref)/2) / (ref)) +#define IN_FROM_REG(val, ref)		(((val) * (ref) + 128) / 256) +#define IN_TO_REG(val, ref)		((val) < 0 ? 0 : \ +					 (val) * 256 >= (ref) * 255 ? 255 : \ +					 ((val) * 256 + (ref) / 2) / (ref))  /*   * Temperature registers and conversions @@ -226,7 +228,7 @@ struct pc87360_data {   */  static int pc87360_probe(struct platform_device *pdev); -static int __devexit pc87360_remove(struct platform_device *pdev); +static int pc87360_remove(struct platform_device *pdev);  static int pc87360_read_value(struct pc87360_data *data, u8 ldi, u8 bank,  			      u8 reg); @@ -246,50 +248,61 @@ static struct platform_driver pc87360_driver = {  		.name	= "pc87360",  	},  	.probe		= pc87360_probe, -	.remove		= __devexit_p(pc87360_remove), +	.remove		= pc87360_remove,  };  /*   * Sysfs stuff   */ -static ssize_t show_fan_input(struct device *dev, struct device_attribute *devattr, char *buf) +static ssize_t show_fan_input(struct device *dev, +			      struct device_attribute *devattr, char *buf)  {  	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);  	struct pc87360_data *data = pc87360_update_device(dev);  	return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan[attr->index],  		       FAN_DIV_FROM_REG(data->fan_status[attr->index])));  } -static ssize_t show_fan_min(struct device *dev, struct device_attribute *devattr, char *buf) +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 pc87360_data *data = pc87360_update_device(dev);  	return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan_min[attr->index],  		       FAN_DIV_FROM_REG(data->fan_status[attr->index])));  } -static ssize_t show_fan_div(struct device *dev, struct device_attribute *devattr, char *buf) +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 pc87360_data *data = pc87360_update_device(dev);  	return sprintf(buf, "%u\n",  		       FAN_DIV_FROM_REG(data->fan_status[attr->index]));  } -static ssize_t show_fan_status(struct device *dev, struct device_attribute *devattr, char *buf) +static ssize_t show_fan_status(struct device *dev, +			       struct device_attribute *devattr, char *buf)  {  	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);  	struct pc87360_data *data = pc87360_update_device(dev);  	return sprintf(buf, "%u\n",  		       FAN_STATUS_FROM_REG(data->fan_status[attr->index]));  } -static ssize_t set_fan_min(struct device *dev, struct device_attribute *devattr, const char *buf, +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 pc87360_data *data = dev_get_drvdata(dev); -	long fan_min = simple_strtol(buf, NULL, 10); +	long fan_min; +	int err; + +	err = kstrtol(buf, 10, &fan_min); +	if (err) +		return err;  	mutex_lock(&data->update_lock); -	fan_min = FAN_TO_REG(fan_min, FAN_DIV_FROM_REG(data->fan_status[attr->index])); +	fan_min = FAN_TO_REG(fan_min, +			     FAN_DIV_FROM_REG(data->fan_status[attr->index]));  	/* If it wouldn't fit, change clock divisor */  	while (fan_min > 255 @@ -299,11 +312,13 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *devattr,  		data->fan_status[attr->index] += 0x20;  	}  	data->fan_min[attr->index] = fan_min > 255 ? 255 : fan_min; -	pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_FAN_MIN(attr->index), +	pc87360_write_value(data, LD_FAN, NO_BANK, +			    PC87360_REG_FAN_MIN(attr->index),  			    data->fan_min[attr->index]);  	/* Write new divider, preserve alarm bits */ -	pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_FAN_STATUS(attr->index), +	pc87360_write_value(data, LD_FAN, NO_BANK, +			    PC87360_REG_FAN_STATUS(attr->index),  			    data->fan_status[attr->index] & 0xF9);  	mutex_unlock(&data->update_lock); @@ -331,13 +346,16 @@ static struct sensor_device_attribute fan_min[] = {  	SENSOR_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min, set_fan_min, 2),  }; -#define FAN_UNIT_ATTRS(X)	\ -	&fan_input[X].dev_attr.attr,	\ +#define FAN_UNIT_ATTRS(X)		\ +{	&fan_input[X].dev_attr.attr,	\  	&fan_status[X].dev_attr.attr,	\  	&fan_div[X].dev_attr.attr,	\ -	&fan_min[X].dev_attr.attr +	&fan_min[X].dev_attr.attr,	\ +	NULL				\ +} -static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, char *buf) +static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, +			char *buf)  {  	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);  	struct pc87360_data *data = pc87360_update_device(dev); @@ -346,12 +364,17 @@ static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, ch  				    FAN_CONFIG_INVERT(data->fan_conf,  						      attr->index)));  } -static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, const char *buf, -	size_t count) +static ssize_t set_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 pc87360_data *data = dev_get_drvdata(dev); -	long val = simple_strtol(buf, NULL, 10); +	long val; +	int err; + +	err = kstrtol(buf, 10, &val); +	if (err) +		return err;  	mutex_lock(&data->update_lock);  	data->pwm[attr->index] = PWM_TO_REG(val, @@ -368,52 +391,60 @@ static struct sensor_device_attribute pwm[] = {  	SENSOR_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 2),  }; -static struct attribute * pc8736x_fan_attr_array[] = { +static struct attribute *pc8736x_fan_attr[][5] = {  	FAN_UNIT_ATTRS(0),  	FAN_UNIT_ATTRS(1), -	FAN_UNIT_ATTRS(2), -	&pwm[0].dev_attr.attr, -	&pwm[1].dev_attr.attr, -	&pwm[2].dev_attr.attr, -	NULL +	FAN_UNIT_ATTRS(2)  }; -static const struct attribute_group pc8736x_fan_group = { -	.attrs = pc8736x_fan_attr_array, + +static const struct attribute_group pc8736x_fan_attr_group[] = { +	{ .attrs = pc8736x_fan_attr[0], }, +	{ .attrs = pc8736x_fan_attr[1], }, +	{ .attrs = pc8736x_fan_attr[2], },  }; -static ssize_t show_in_input(struct device *dev, struct device_attribute *devattr, char *buf) +static ssize_t show_in_input(struct device *dev, +			     struct device_attribute *devattr, char *buf)  {  	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);  	struct pc87360_data *data = pc87360_update_device(dev);  	return sprintf(buf, "%u\n", IN_FROM_REG(data->in[attr->index],  		       data->in_vref));  } -static ssize_t show_in_min(struct device *dev, struct device_attribute *devattr, char *buf) +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 pc87360_data *data = pc87360_update_device(dev);  	return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[attr->index],  		       data->in_vref));  } -static ssize_t show_in_max(struct device *dev, struct device_attribute *devattr, char *buf) +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 pc87360_data *data = pc87360_update_device(dev);  	return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[attr->index],  		       data->in_vref));  } -static ssize_t show_in_status(struct device *dev, struct device_attribute *devattr, char *buf) +static ssize_t show_in_status(struct device *dev, +			      struct device_attribute *devattr, char *buf)  {  	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);  	struct pc87360_data *data = pc87360_update_device(dev);  	return sprintf(buf, "%u\n", data->in_status[attr->index]);  } -static ssize_t set_in_min(struct device *dev, struct device_attribute *devattr, const char *buf, -	size_t count) +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 pc87360_data *data = dev_get_drvdata(dev); -	long val = simple_strtol(buf, NULL, 10); +	long val; +	int err; + +	err = kstrtol(buf, 10, &val); +	if (err) +		return err;  	mutex_lock(&data->update_lock);  	data->in_min[attr->index] = IN_TO_REG(val, data->in_vref); @@ -422,12 +453,17 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *devattr,  	mutex_unlock(&data->update_lock);  	return count;  } -static ssize_t set_in_max(struct device *dev, struct device_attribute *devattr, const char *buf, -	size_t count) +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 pc87360_data *data = dev_get_drvdata(dev); -	long val = simple_strtol(buf, NULL, 10); +	long val; +	int err; + +	err = kstrtol(buf, 10, &val); +	if (err) +		return err;  	mutex_lock(&data->update_lock);  	data->in_max[attr->index] = IN_TO_REG(val, @@ -496,9 +532,11 @@ static struct sensor_device_attribute in_max[] = {  #define CHAN_ALM_MAX	0x04	/* max limit exceeded */  #define TEMP_ALM_CRIT	0x08	/* temp crit exceeded (temp only) */ -/* show_in_min/max_alarm() reads data from the per-channel status -   register (sec 11.5.12), not the vin event status registers (sec -   11.5.2) that (legacy) show_in_alarm() resds (via data->in_alarms) */ +/* + * show_in_min/max_alarm() reads data from the per-channel status + * register (sec 11.5.12), not the vin event status registers (sec + * 11.5.2) that (legacy) show_in_alarm() resds (via data->in_alarms) + */  static ssize_t show_in_min_alarm(struct device *dev,  			struct device_attribute *devattr, char *buf) @@ -552,27 +590,38 @@ static struct sensor_device_attribute in_max_alarm[] = {  	&in_min_alarm[X].dev_attr.attr,	\  	&in_max_alarm[X].dev_attr.attr -static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf) +static ssize_t show_vid(struct device *dev, struct device_attribute *attr, +			char *buf)  {  	struct pc87360_data *data = pc87360_update_device(dev);  	return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm));  }  static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); -static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf) +static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, +			char *buf)  {  	struct pc87360_data *data = dev_get_drvdata(dev);  	return sprintf(buf, "%u\n", data->vrm);  } -static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) +static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, +		       const char *buf, size_t count)  {  	struct pc87360_data *data = dev_get_drvdata(dev); -	data->vrm = simple_strtoul(buf, NULL, 10); +	unsigned long val; +	int err; + +	err = kstrtoul(buf, 10, &val); +	if (err) +		return err; + +	data->vrm = val;  	return count;  }  static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm); -static ssize_t show_in_alarms(struct device *dev, struct device_attribute *attr, char *buf) +static ssize_t show_in_alarms(struct device *dev, +			      struct device_attribute *attr, char *buf)  {  	struct pc87360_data *data = pc87360_update_device(dev);  	return sprintf(buf, "%u\n", data->in_alarms); @@ -600,46 +649,58 @@ static const struct attribute_group pc8736x_vin_group = {  	.attrs = pc8736x_vin_attr_array,  }; -static ssize_t show_therm_input(struct device *dev, struct device_attribute *devattr, char *buf) +static ssize_t show_therm_input(struct device *dev, +				struct device_attribute *devattr, char *buf)  {  	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);  	struct pc87360_data *data = pc87360_update_device(dev);  	return sprintf(buf, "%u\n", IN_FROM_REG(data->in[attr->index],  		       data->in_vref));  } -static ssize_t show_therm_min(struct device *dev, struct device_attribute *devattr, char *buf) +static ssize_t show_therm_min(struct device *dev, +			      struct device_attribute *devattr, char *buf)  {  	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);  	struct pc87360_data *data = pc87360_update_device(dev);  	return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[attr->index],  		       data->in_vref));  } -static ssize_t show_therm_max(struct device *dev, struct device_attribute *devattr, char *buf) +static ssize_t show_therm_max(struct device *dev, +			      struct device_attribute *devattr, char *buf)  {  	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);  	struct pc87360_data *data = pc87360_update_device(dev);  	return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[attr->index],  		       data->in_vref));  } -static ssize_t show_therm_crit(struct device *dev, struct device_attribute *devattr, char *buf) +static ssize_t show_therm_crit(struct device *dev, +			       struct device_attribute *devattr, char *buf)  {  	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);  	struct pc87360_data *data = pc87360_update_device(dev);  	return sprintf(buf, "%u\n", IN_FROM_REG(data->in_crit[attr->index-11],  		       data->in_vref));  } -static ssize_t show_therm_status(struct device *dev, struct device_attribute *devattr, char *buf) +static ssize_t show_therm_status(struct device *dev, +				 struct device_attribute *devattr, char *buf)  {  	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);  	struct pc87360_data *data = pc87360_update_device(dev);  	return sprintf(buf, "%u\n", data->in_status[attr->index]);  } -static ssize_t set_therm_min(struct device *dev, struct device_attribute *devattr, const char *buf, -	size_t count) + +static ssize_t set_therm_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 pc87360_data *data = dev_get_drvdata(dev); -	long val = simple_strtol(buf, NULL, 10); +	long val; +	int err; + +	err = kstrtol(buf, 10, &val); +	if (err) +		return err;  	mutex_lock(&data->update_lock);  	data->in_min[attr->index] = IN_TO_REG(val, data->in_vref); @@ -648,12 +709,19 @@ static ssize_t set_therm_min(struct device *dev, struct device_attribute *devatt  	mutex_unlock(&data->update_lock);  	return count;  } -static ssize_t set_therm_max(struct device *dev, struct device_attribute *devattr, const char *buf, -	size_t count) + +static ssize_t set_therm_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 pc87360_data *data = dev_get_drvdata(dev); -	long val = simple_strtol(buf, NULL, 10); +	long val; +	int err; + +	err = kstrtol(buf, 10, &val); +	if (err) +		return err;  	mutex_lock(&data->update_lock);  	data->in_max[attr->index] = IN_TO_REG(val, data->in_vref); @@ -662,12 +730,18 @@ static ssize_t set_therm_max(struct device *dev, struct device_attribute *devatt  	mutex_unlock(&data->update_lock);  	return count;  } -static ssize_t set_therm_crit(struct device *dev, struct device_attribute *devattr, const char *buf, -	size_t count) +static ssize_t set_therm_crit(struct device *dev, +			      struct device_attribute *devattr, +			      const char *buf, size_t count)  {  	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);  	struct pc87360_data *data = dev_get_drvdata(dev); -	long val = simple_strtol(buf, NULL, 10); +	long val; +	int err; + +	err = kstrtol(buf, 10, &val); +	if (err) +		return err;  	mutex_lock(&data->update_lock);  	data->in_crit[attr->index-11] = IN_TO_REG(val, data->in_vref); @@ -677,46 +751,49 @@ static ssize_t set_therm_crit(struct device *dev, struct device_attribute *devat  	return count;  } -/* the +11 term below reflects the fact that VLM units 11,12,13 are -   used in the chip to measure voltage across the thermistors -*/ +/* + * the +11 term below reflects the fact that VLM units 11,12,13 are + * used in the chip to measure voltage across the thermistors + */  static struct sensor_device_attribute therm_input[] = { -	SENSOR_ATTR(temp4_input, S_IRUGO, show_therm_input, NULL, 0+11), -	SENSOR_ATTR(temp5_input, S_IRUGO, show_therm_input, NULL, 1+11), -	SENSOR_ATTR(temp6_input, S_IRUGO, show_therm_input, NULL, 2+11), +	SENSOR_ATTR(temp4_input, S_IRUGO, show_therm_input, NULL, 0 + 11), +	SENSOR_ATTR(temp5_input, S_IRUGO, show_therm_input, NULL, 1 + 11), +	SENSOR_ATTR(temp6_input, S_IRUGO, show_therm_input, NULL, 2 + 11),  };  static struct sensor_device_attribute therm_status[] = { -	SENSOR_ATTR(temp4_status, S_IRUGO, show_therm_status, NULL, 0+11), -	SENSOR_ATTR(temp5_status, S_IRUGO, show_therm_status, NULL, 1+11), -	SENSOR_ATTR(temp6_status, S_IRUGO, show_therm_status, NULL, 2+11), +	SENSOR_ATTR(temp4_status, S_IRUGO, show_therm_status, NULL, 0 + 11), +	SENSOR_ATTR(temp5_status, S_IRUGO, show_therm_status, NULL, 1 + 11), +	SENSOR_ATTR(temp6_status, S_IRUGO, show_therm_status, NULL, 2 + 11),  };  static struct sensor_device_attribute therm_min[] = {  	SENSOR_ATTR(temp4_min, S_IRUGO | S_IWUSR, -		    show_therm_min, set_therm_min, 0+11), +		    show_therm_min, set_therm_min, 0 + 11),  	SENSOR_ATTR(temp5_min, S_IRUGO | S_IWUSR, -		    show_therm_min, set_therm_min, 1+11), +		    show_therm_min, set_therm_min, 1 + 11),  	SENSOR_ATTR(temp6_min, S_IRUGO | S_IWUSR, -		    show_therm_min, set_therm_min, 2+11), +		    show_therm_min, set_therm_min, 2 + 11),  };  static struct sensor_device_attribute therm_max[] = {  	SENSOR_ATTR(temp4_max, S_IRUGO | S_IWUSR, -		    show_therm_max, set_therm_max, 0+11), +		    show_therm_max, set_therm_max, 0 + 11),  	SENSOR_ATTR(temp5_max, S_IRUGO | S_IWUSR, -		    show_therm_max, set_therm_max, 1+11), +		    show_therm_max, set_therm_max, 1 + 11),  	SENSOR_ATTR(temp6_max, S_IRUGO | S_IWUSR, -		    show_therm_max, set_therm_max, 2+11), +		    show_therm_max, set_therm_max, 2 + 11),  };  static struct sensor_device_attribute therm_crit[] = {  	SENSOR_ATTR(temp4_crit, S_IRUGO | S_IWUSR, -		    show_therm_crit, set_therm_crit, 0+11), +		    show_therm_crit, set_therm_crit, 0 + 11),  	SENSOR_ATTR(temp5_crit, S_IRUGO | S_IWUSR, -		    show_therm_crit, set_therm_crit, 1+11), +		    show_therm_crit, set_therm_crit, 1 + 11),  	SENSOR_ATTR(temp6_crit, S_IRUGO | S_IWUSR, -		    show_therm_crit, set_therm_crit, 2+11), +		    show_therm_crit, set_therm_crit, 2 + 11),  }; -/* show_therm_min/max_alarm() reads data from the per-channel voltage -   status register (sec 11.5.12) */ +/* + * show_therm_min/max_alarm() reads data from the per-channel voltage + * status register (sec 11.5.12) + */  static ssize_t show_therm_min_alarm(struct device *dev,  				struct device_attribute *devattr, char *buf) @@ -745,27 +822,27 @@ static ssize_t show_therm_crit_alarm(struct device *dev,  static struct sensor_device_attribute therm_min_alarm[] = {  	SENSOR_ATTR(temp4_min_alarm, S_IRUGO, -		    show_therm_min_alarm, NULL, 0+11), +		    show_therm_min_alarm, NULL, 0 + 11),  	SENSOR_ATTR(temp5_min_alarm, S_IRUGO, -		    show_therm_min_alarm, NULL, 1+11), +		    show_therm_min_alarm, NULL, 1 + 11),  	SENSOR_ATTR(temp6_min_alarm, S_IRUGO, -		    show_therm_min_alarm, NULL, 2+11), +		    show_therm_min_alarm, NULL, 2 + 11),  };  static struct sensor_device_attribute therm_max_alarm[] = {  	SENSOR_ATTR(temp4_max_alarm, S_IRUGO, -		    show_therm_max_alarm, NULL, 0+11), +		    show_therm_max_alarm, NULL, 0 + 11),  	SENSOR_ATTR(temp5_max_alarm, S_IRUGO, -		    show_therm_max_alarm, NULL, 1+11), +		    show_therm_max_alarm, NULL, 1 + 11),  	SENSOR_ATTR(temp6_max_alarm, S_IRUGO, -		    show_therm_max_alarm, NULL, 2+11), +		    show_therm_max_alarm, NULL, 2 + 11),  };  static struct sensor_device_attribute therm_crit_alarm[] = {  	SENSOR_ATTR(temp4_crit_alarm, S_IRUGO, -		    show_therm_crit_alarm, NULL, 0+11), +		    show_therm_crit_alarm, NULL, 0 + 11),  	SENSOR_ATTR(temp5_crit_alarm, S_IRUGO, -		    show_therm_crit_alarm, NULL, 1+11), +		    show_therm_crit_alarm, NULL, 1 + 11),  	SENSOR_ATTR(temp6_crit_alarm, S_IRUGO, -		    show_therm_crit_alarm, NULL, 2+11), +		    show_therm_crit_alarm, NULL, 2 + 11),  };  #define THERM_UNIT_ATTRS(X) \ @@ -778,7 +855,7 @@ static struct sensor_device_attribute therm_crit_alarm[] = {  	&therm_max_alarm[X].dev_attr.attr, \  	&therm_crit_alarm[X].dev_attr.attr -static struct attribute * pc8736x_therm_attr_array[] = { +static struct attribute *pc8736x_therm_attr_array[] = {  	THERM_UNIT_ATTRS(0),  	THERM_UNIT_ATTRS(1),  	THERM_UNIT_ATTRS(2), @@ -788,42 +865,59 @@ static const struct attribute_group pc8736x_therm_group = {  	.attrs = pc8736x_therm_attr_array,  }; -static ssize_t show_temp_input(struct device *dev, struct device_attribute *devattr, char *buf) +static ssize_t show_temp_input(struct device *dev, +			       struct device_attribute *devattr, char *buf)  {  	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);  	struct pc87360_data *data = pc87360_update_device(dev);  	return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[attr->index]));  } -static ssize_t show_temp_min(struct device *dev, struct device_attribute *devattr, char *buf) + +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 pc87360_data *data = pc87360_update_device(dev);  	return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[attr->index]));  } -static ssize_t show_temp_max(struct device *dev, struct device_attribute *devattr, char *buf) + +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 pc87360_data *data = pc87360_update_device(dev);  	return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[attr->index]));  } -static ssize_t show_temp_crit(struct device *dev, struct device_attribute *devattr, char *buf) + +static ssize_t show_temp_crit(struct device *dev, +			      struct device_attribute *devattr, char *buf)  {  	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);  	struct pc87360_data *data = pc87360_update_device(dev); -	return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit[attr->index])); +	return sprintf(buf, "%d\n", +		       TEMP_FROM_REG(data->temp_crit[attr->index]));  } -static ssize_t show_temp_status(struct device *dev, struct device_attribute *devattr, char *buf) + +static ssize_t show_temp_status(struct device *dev, +				struct device_attribute *devattr, char *buf)  {  	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);  	struct pc87360_data *data = pc87360_update_device(dev);  	return sprintf(buf, "%d\n", data->temp_status[attr->index]);  } -static ssize_t set_temp_min(struct device *dev, struct device_attribute *devattr, const char *buf, -	size_t count) + +static ssize_t set_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 pc87360_data *data = dev_get_drvdata(dev); -	long val = simple_strtol(buf, NULL, 10); +	long val; +	int err; + +	err = kstrtol(buf, 10, &val); +	if (err) +		return err;  	mutex_lock(&data->update_lock);  	data->temp_min[attr->index] = TEMP_TO_REG(val); @@ -832,12 +926,19 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *devattr  	mutex_unlock(&data->update_lock);  	return count;  } -static ssize_t set_temp_max(struct device *dev, struct device_attribute *devattr, const char *buf, -	size_t count) + +static ssize_t set_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 pc87360_data *data = dev_get_drvdata(dev); -	long val = simple_strtol(buf, NULL, 10); +	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); @@ -846,12 +947,19 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *devattr  	mutex_unlock(&data->update_lock);  	return count;  } -static ssize_t set_temp_crit(struct device *dev, struct device_attribute *devattr, const char *buf, -	size_t count) + +static ssize_t set_temp_crit(struct device *dev, +			     struct device_attribute *devattr, const char *buf, +			     size_t count)  {  	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);  	struct pc87360_data *data = dev_get_drvdata(dev); -	long val = simple_strtol(buf, NULL, 10); +	long val; +	int err; + +	err = kstrtol(buf, 10, &val); +	if (err) +		return err;  	mutex_lock(&data->update_lock);  	data->temp_crit[attr->index] = TEMP_TO_REG(val); @@ -896,16 +1004,20 @@ static struct sensor_device_attribute temp_crit[] = {  		    show_temp_crit, set_temp_crit, 2),  }; -static ssize_t show_temp_alarms(struct device *dev, struct device_attribute *attr, char *buf) +static ssize_t show_temp_alarms(struct device *dev, +				struct device_attribute *attr, char *buf)  {  	struct pc87360_data *data = pc87360_update_device(dev);  	return sprintf(buf, "%u\n", data->temp_alarms);  } +  static DEVICE_ATTR(alarms_temp, S_IRUGO, show_temp_alarms, NULL); -/* show_temp_min/max_alarm() reads data from the per-channel status -   register (sec 12.3.7), not the temp event status registers (sec -   12.3.2) that show_temp_alarm() reads (via data->temp_alarms) */ +/* + * show_temp_min/max_alarm() reads data from the per-channel status + * register (sec 12.3.7), not the temp event status registers (sec + * 12.3.2) that show_temp_alarm() reads (via data->temp_alarms) + */  static ssize_t show_temp_min_alarm(struct device *dev,  			struct device_attribute *devattr, char *buf) @@ -915,6 +1027,7 @@ static ssize_t show_temp_min_alarm(struct device *dev,  	return sprintf(buf, "%u\n", !!(data->temp_status[nr] & CHAN_ALM_MIN));  } +  static ssize_t show_temp_max_alarm(struct device *dev,  			struct device_attribute *devattr, char *buf)  { @@ -923,6 +1036,7 @@ static ssize_t show_temp_max_alarm(struct device *dev,  	return sprintf(buf, "%u\n", !!(data->temp_status[nr] & CHAN_ALM_MAX));  } +  static ssize_t show_temp_crit_alarm(struct device *dev,  			struct device_attribute *devattr, char *buf)  { @@ -937,11 +1051,13 @@ static struct sensor_device_attribute temp_min_alarm[] = {  	SENSOR_ATTR(temp2_min_alarm, S_IRUGO, show_temp_min_alarm, NULL, 1),  	SENSOR_ATTR(temp3_min_alarm, S_IRUGO, show_temp_min_alarm, NULL, 2),  }; +  static struct sensor_device_attribute temp_max_alarm[] = {  	SENSOR_ATTR(temp1_max_alarm, S_IRUGO, show_temp_max_alarm, NULL, 0),  	SENSOR_ATTR(temp2_max_alarm, S_IRUGO, show_temp_max_alarm, NULL, 1),  	SENSOR_ATTR(temp3_max_alarm, S_IRUGO, show_temp_max_alarm, NULL, 2),  }; +  static struct sensor_device_attribute temp_crit_alarm[] = {  	SENSOR_ATTR(temp1_crit_alarm, S_IRUGO, show_temp_crit_alarm, NULL, 0),  	SENSOR_ATTR(temp2_crit_alarm, S_IRUGO, show_temp_crit_alarm, NULL, 1), @@ -963,27 +1079,29 @@ static struct sensor_device_attribute temp_fault[] = {  	SENSOR_ATTR(temp3_fault, S_IRUGO, show_temp_fault, NULL, 2),  }; -#define TEMP_UNIT_ATTRS(X) \ -	&temp_input[X].dev_attr.attr,	\ -	&temp_status[X].dev_attr.attr,	\ -	&temp_min[X].dev_attr.attr,	\ -	&temp_max[X].dev_attr.attr,	\ -	&temp_crit[X].dev_attr.attr,	\ -	&temp_min_alarm[X].dev_attr.attr, \ -	&temp_max_alarm[X].dev_attr.attr, \ -	&temp_crit_alarm[X].dev_attr.attr, \ -	&temp_fault[X].dev_attr.attr - -static struct attribute * pc8736x_temp_attr_array[] = { +#define TEMP_UNIT_ATTRS(X)			\ +{	&temp_input[X].dev_attr.attr,		\ +	&temp_status[X].dev_attr.attr,		\ +	&temp_min[X].dev_attr.attr,		\ +	&temp_max[X].dev_attr.attr,		\ +	&temp_crit[X].dev_attr.attr,		\ +	&temp_min_alarm[X].dev_attr.attr,	\ +	&temp_max_alarm[X].dev_attr.attr,	\ +	&temp_crit_alarm[X].dev_attr.attr,	\ +	&temp_fault[X].dev_attr.attr,		\ +	NULL					\ +} + +static struct attribute *pc8736x_temp_attr[][10] = {  	TEMP_UNIT_ATTRS(0),  	TEMP_UNIT_ATTRS(1), -	TEMP_UNIT_ATTRS(2), -	/* include the few miscellaneous atts here */ -	&dev_attr_alarms_temp.attr, -	NULL +	TEMP_UNIT_ATTRS(2)  }; -static const struct attribute_group pc8736x_temp_group = { -	.attrs = pc8736x_temp_attr_array, + +static const struct attribute_group pc8736x_temp_attr_group[] = { +	{ .attrs = pc8736x_temp_attr[0] }, +	{ .attrs = pc8736x_temp_attr[1] }, +	{ .attrs = pc8736x_temp_attr[2] }  };  static ssize_t show_name(struct device *dev, @@ -992,13 +1110,15 @@ static ssize_t show_name(struct device *dev,  	struct pc87360_data *data = dev_get_drvdata(dev);  	return sprintf(buf, "%s\n", data->name);  } +  static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);  /*   * Device detection, registration and update   */ -static int __init pc87360_find(int sioaddr, u8 *devid, unsigned short *addresses) +static int __init pc87360_find(int sioaddr, u8 *devid, +			       unsigned short *addresses)  {  	u16 val;  	int i; @@ -1031,54 +1151,50 @@ static int __init pc87360_find(int sioaddr, u8 *devid, unsigned short *addresses  		val = superio_inb(sioaddr, ACT);  		if (!(val & 0x01)) { -			printk(KERN_INFO "pc87360: Device 0x%02x not " -			       "activated\n", logdev[i]); +			pr_info("Device 0x%02x not activated\n", logdev[i]);  			continue;  		}  		val = (superio_inb(sioaddr, BASE) << 8)  		    | superio_inb(sioaddr, BASE + 1);  		if (!val) { -			printk(KERN_INFO "pc87360: Base address not set for " -			       "device 0x%02x\n", logdev[i]); +			pr_info("Base address not set for device 0x%02x\n", +				logdev[i]);  			continue;  		}  		addresses[i] = val; -		if (i==0) { /* Fans */ +		if (i == 0) { /* Fans */  			confreg[0] = superio_inb(sioaddr, 0xF0);  			confreg[1] = superio_inb(sioaddr, 0xF1); -#ifdef DEBUG -			printk(KERN_DEBUG "pc87360: Fan 1: mon=%d " -			       "ctrl=%d inv=%d\n", (confreg[0]>>2)&1, -			       (confreg[0]>>3)&1, (confreg[0]>>4)&1); -			printk(KERN_DEBUG "pc87360: Fan 2: mon=%d " -			       "ctrl=%d inv=%d\n", (confreg[0]>>5)&1, -			       (confreg[0]>>6)&1, (confreg[0]>>7)&1); -			printk(KERN_DEBUG "pc87360: Fan 3: mon=%d " -			       "ctrl=%d inv=%d\n", confreg[1]&1, -			       (confreg[1]>>1)&1, (confreg[1]>>2)&1); -#endif -		} else if (i==1) { /* Voltages */ +			pr_debug("Fan %d: mon=%d ctrl=%d inv=%d\n", 1, +				 (confreg[0] >> 2) & 1, (confreg[0] >> 3) & 1, +				 (confreg[0] >> 4) & 1); +			pr_debug("Fan %d: mon=%d ctrl=%d inv=%d\n", 2, +				 (confreg[0] >> 5) & 1, (confreg[0] >> 6) & 1, +				 (confreg[0] >> 7) & 1); +			pr_debug("Fan %d: mon=%d ctrl=%d inv=%d\n", 3, +				 confreg[1] & 1, (confreg[1] >> 1) & 1, +				 (confreg[1] >> 2) & 1); +		} else if (i == 1) { /* Voltages */  			/* Are we using thermistors? */  			if (*devid == 0xE9) { /* PC87366 */ -				/* These registers are not logical-device -				   specific, just that we won't need them if -				   we don't use the VLM device */ +				/* +				 * These registers are not logical-device +				 * specific, just that we won't need them if +				 * we don't use the VLM device +				 */  				confreg[2] = superio_inb(sioaddr, 0x2B);  				confreg[3] = superio_inb(sioaddr, 0x25);  				if (confreg[2] & 0x40) { -					printk(KERN_INFO "pc87360: Using " -					       "thermistors for temperature " -					       "monitoring\n"); +					pr_info("Using thermistors for temperature monitoring\n");  				}  				if (confreg[3] & 0xE0) { -					printk(KERN_INFO "pc87360: VID " -					       "inputs routed (mode %u)\n", -					       confreg[3] >> 5); +					pr_info("VID inputs routed (mode %u)\n", +						confreg[3] >> 5);  				}  			}  		} @@ -1088,25 +1204,43 @@ static int __init pc87360_find(int sioaddr, u8 *devid, unsigned short *addresses  	return 0;  } -static int __devinit pc87360_probe(struct platform_device *pdev) +static void pc87360_remove_files(struct device *dev) +{ +	int i; + +	device_remove_file(dev, &dev_attr_name); +	device_remove_file(dev, &dev_attr_alarms_temp); +	for (i = 0; i < ARRAY_SIZE(pc8736x_temp_attr_group); i++) +		sysfs_remove_group(&dev->kobj, &pc8736x_temp_attr_group[i]); +	for (i = 0; i < ARRAY_SIZE(pc8736x_fan_attr_group); i++) { +		sysfs_remove_group(&pdev->dev.kobj, &pc8736x_fan_attr_group[i]); +		device_remove_file(dev, &pwm[i].dev_attr); +	} +	sysfs_remove_group(&dev->kobj, &pc8736x_therm_group); +	sysfs_remove_group(&dev->kobj, &pc8736x_vin_group); +} + +static int pc87360_probe(struct platform_device *pdev)  {  	int i;  	struct pc87360_data *data;  	int err = 0; -	const char *name = "pc87360"; +	const char *name;  	int use_thermistors = 0;  	struct device *dev = &pdev->dev; -	if (!(data = kzalloc(sizeof(struct pc87360_data), GFP_KERNEL))) +	data = devm_kzalloc(dev, sizeof(struct pc87360_data), GFP_KERNEL); +	if (!data)  		return -ENOMEM; -	data->fannr = 2; -	data->innr = 0; -	data->tempnr = 0; -  	switch (devid) { +	default: +		name = "pc87360"; +		data->fannr = 2; +		break;  	case 0xe8:  		name = "pc87363"; +		data->fannr = 2;  		break;  	case 0xe4:  		name = "pc87364"; @@ -1127,22 +1261,19 @@ static int __devinit pc87360_probe(struct platform_device *pdev)  	}  	data->name = name; -	data->valid = 0;  	mutex_init(&data->lock);  	mutex_init(&data->update_lock);  	platform_set_drvdata(pdev, data);  	for (i = 0; i < LDNI_MAX; i++) { -		if (((data->address[i] = extra_isa[i])) -		 && !request_region(extra_isa[i], PC87360_EXTENT, -		 		    pc87360_driver.driver.name)) { -			dev_err(dev, "Region 0x%x-0x%x already " -				"in use!\n", extra_isa[i], -				extra_isa[i]+PC87360_EXTENT-1); -			for (i--; i >= 0; i--) -				release_region(extra_isa[i], PC87360_EXTENT); -			err = -EBUSY; -			goto ERROR1; +		data->address[i] = extra_isa[i]; +		if (data->address[i] +		 && !devm_request_region(dev, extra_isa[i], PC87360_EXTENT, +					 pc87360_driver.driver.name)) { +			dev_err(dev, +				"Region 0x%x-0x%x already in use!\n", +				extra_isa[i], extra_isa[i]+PC87360_EXTENT-1); +			return -EBUSY;  		}  	} @@ -1150,9 +1281,11 @@ static int __devinit pc87360_probe(struct platform_device *pdev)  	if (data->fannr)  		data->fan_conf = confreg[0] | (confreg[1] << 8); -	/* Use the correct reference voltage -	   Unless both the VLM and the TMS logical devices agree to -	   use an external Vref, the internal one is used. */ +	/* +	 * Use the correct reference voltage +	 * Unless both the VLM and the TMS logical devices agree to +	 * use an external Vref, the internal one is used. +	 */  	if (data->innr) {  		i = pc87360_read_value(data, LD_IN, NO_BANK,  				       PC87365_REG_IN_CONFIG); @@ -1185,113 +1318,76 @@ static int __devinit pc87360_probe(struct platform_device *pdev)  	/* Register all-or-nothing sysfs groups */ -	if (data->innr && -	    (err = sysfs_create_group(&dev->kobj, -				      &pc8736x_vin_group))) -		goto ERROR3; +	if (data->innr) { +		err = sysfs_create_group(&dev->kobj, &pc8736x_vin_group); +		if (err) +			goto error; +	} -	if (data->innr == 14 && -	    (err = sysfs_create_group(&dev->kobj, -				      &pc8736x_therm_group))) -		goto ERROR3; +	if (data->innr == 14) { +		err = sysfs_create_group(&dev->kobj, &pc8736x_therm_group); +		if (err) +			goto error; +	}  	/* create device attr-files for varying sysfs groups */  	if (data->tempnr) {  		for (i = 0; i < data->tempnr; i++) { -			if ((err = device_create_file(dev, -					&temp_input[i].dev_attr)) -			    || (err = device_create_file(dev, -					&temp_min[i].dev_attr)) -			    || (err = device_create_file(dev, -					&temp_max[i].dev_attr)) -			    || (err = device_create_file(dev, -					&temp_crit[i].dev_attr)) -			    || (err = device_create_file(dev, -					&temp_status[i].dev_attr)) -			    || (err = device_create_file(dev, -					&temp_min_alarm[i].dev_attr)) -			    || (err = device_create_file(dev, -					&temp_max_alarm[i].dev_attr)) -			    || (err = device_create_file(dev, -					&temp_crit_alarm[i].dev_attr)) -			    || (err = device_create_file(dev, -					&temp_fault[i].dev_attr))) -				goto ERROR3; +			err = sysfs_create_group(&dev->kobj, +						 &pc8736x_temp_attr_group[i]); +			if (err) +				goto error;  		} -		if ((err = device_create_file(dev, &dev_attr_alarms_temp))) -			goto ERROR3; +		err = device_create_file(dev, &dev_attr_alarms_temp); +		if (err) +			goto error;  	}  	for (i = 0; i < data->fannr; i++) { -		if (FAN_CONFIG_MONITOR(data->fan_conf, i) -		    && ((err = device_create_file(dev, -					&fan_input[i].dev_attr)) -			|| (err = device_create_file(dev, -					&fan_min[i].dev_attr)) -			|| (err = device_create_file(dev, -					&fan_div[i].dev_attr)) -			|| (err = device_create_file(dev, -					&fan_status[i].dev_attr)))) -			goto ERROR3; - -		if (FAN_CONFIG_CONTROL(data->fan_conf, i) -		    && (err = device_create_file(dev, &pwm[i].dev_attr))) -			goto ERROR3; +		if (FAN_CONFIG_MONITOR(data->fan_conf, i)) { +			err = sysfs_create_group(&dev->kobj, +						 &pc8736x_fan_attr_group[i]); +			if (err) +				goto error; +		} +		if (FAN_CONFIG_CONTROL(data->fan_conf, i)) { +			err = device_create_file(dev, &pwm[i].dev_attr); +			if (err) +				goto error; +		}  	} -	if ((err = device_create_file(dev, &dev_attr_name))) -		goto ERROR3; +	err = device_create_file(dev, &dev_attr_name); +	if (err) +		goto error;  	data->hwmon_dev = hwmon_device_register(dev);  	if (IS_ERR(data->hwmon_dev)) {  		err = PTR_ERR(data->hwmon_dev); -		goto ERROR3; +		goto error;  	}  	return 0; -ERROR3: -	device_remove_file(dev, &dev_attr_name); -	/* can still remove groups whose members were added individually */ -	sysfs_remove_group(&dev->kobj, &pc8736x_temp_group); -	sysfs_remove_group(&dev->kobj, &pc8736x_fan_group); -	sysfs_remove_group(&dev->kobj, &pc8736x_therm_group); -	sysfs_remove_group(&dev->kobj, &pc8736x_vin_group); -	for (i = 0; i < 3; i++) { -		if (data->address[i]) { -			release_region(data->address[i], PC87360_EXTENT); -		} -	} -ERROR1: -	kfree(data); +error: +	pc87360_remove_files(dev);  	return err;  } -static int __devexit pc87360_remove(struct platform_device *pdev) +static int pc87360_remove(struct platform_device *pdev)  {  	struct pc87360_data *data = platform_get_drvdata(pdev); -	int i;  	hwmon_device_unregister(data->hwmon_dev); - -	device_remove_file(&pdev->dev, &dev_attr_name); -	sysfs_remove_group(&pdev->dev.kobj, &pc8736x_temp_group); -	sysfs_remove_group(&pdev->dev.kobj, &pc8736x_fan_group); -	sysfs_remove_group(&pdev->dev.kobj, &pc8736x_therm_group); -	sysfs_remove_group(&pdev->dev.kobj, &pc8736x_vin_group); - -	for (i = 0; i < 3; i++) { -		if (data->address[i]) { -			release_region(data->address[i], PC87360_EXTENT); -		} -	} -	kfree(data); +	pc87360_remove_files(&pdev->dev);  	return 0;  } -/* ldi is the logical device index -   bank is for voltages and temperatures only */ +/* + * ldi is the logical device index + * bank is for voltages and temperatures only + */  static int pc87360_read_value(struct pc87360_data *data, u8 ldi, u8 bank,  			      u8 reg)  { @@ -1338,8 +1434,8 @@ static void pc87360_init_device(struct platform_device *pdev,  	if (init >= 2 && data->innr) {  		reg = pc87360_read_value(data, LD_IN, NO_BANK,  					 PC87365_REG_IN_CONVRATE); -		dev_info(&pdev->dev, "VLM conversion set to " -			 "1s period, 160us delay\n"); +		dev_info(&pdev->dev, +			 "VLM conversion set to 1s period, 160us delay\n");  		pc87360_write_value(data, LD_IN, NO_BANK,  				    PC87365_REG_IN_CONVRATE,  				    (reg & 0xC0) | 0x11); @@ -1353,8 +1449,8 @@ static void pc87360_init_device(struct platform_device *pdev,  		if (init >= init_in[i]) {  			/* Forcibly enable voltage channel */  			if (!(reg & CHAN_ENA)) { -				dev_dbg(&pdev->dev, "Forcibly " -					"enabling in%d\n", i); +				dev_dbg(&pdev->dev, "Forcibly enabling in%d\n", +					i);  				pc87360_write_value(data, LD_IN, i,  						    PC87365_REG_IN_STATUS,  						    (reg & 0x68) | 0x87); @@ -1362,8 +1458,10 @@ static void pc87360_init_device(struct platform_device *pdev,  		}  	} -	/* We can't blindly trust the Super-I/O space configuration bit, -	   most BIOS won't set it properly */ +	/* +	 * We can't blindly trust the Super-I/O space configuration bit, +	 * most BIOS won't set it properly +	 */  	dev_dbg(&pdev->dev, "bios thermistors:%d\n", use_thermistors);  	for (i = 11; i < data->innr; i++) {  		reg = pc87360_read_value(data, LD_IN, i, @@ -1378,12 +1476,12 @@ static void pc87360_init_device(struct platform_device *pdev,  	for (; i < data->tempnr; i++) {  		reg = pc87360_read_value(data, LD_TEMP, i,  					 PC87365_REG_TEMP_STATUS); -		dev_dbg(&pdev->dev, "bios temp%d_status:0x%02x\n", i+1, reg); +		dev_dbg(&pdev->dev, "bios temp%d_status:0x%02x\n", i + 1, reg);  		if (init >= init_temp[i]) {  			/* Forcibly enable temperature channel */  			if (!(reg & CHAN_ENA)) { -				dev_dbg(&pdev->dev, "Forcibly " -					"enabling temp%d\n", i+1); +				dev_dbg(&pdev->dev, +					"Forcibly enabling temp%d\n", i + 1);  				pc87360_write_value(data, LD_TEMP, i,  						    PC87365_REG_TEMP_STATUS,  						    0xCF); @@ -1394,14 +1492,16 @@ static void pc87360_init_device(struct platform_device *pdev,  	if (use_thermistors) {  		for (i = 11; i < data->innr; i++) {  			if (init >= init_in[i]) { -				/* The pin may already be used by thermal -				   diodes */ +				/* +				 * The pin may already be used by thermal +				 * diodes +				 */  				reg = pc87360_read_value(data, LD_TEMP, -				      (i-11)/2, PC87365_REG_TEMP_STATUS); +				      (i - 11) / 2, PC87365_REG_TEMP_STATUS);  				if (reg & CHAN_ENA) { -					dev_dbg(&pdev->dev, "Skipping " -						"temp%d, pin already in use " -						"by temp%d\n", i-7, (i-11)/2); +					dev_dbg(&pdev->dev, +			"Skipping temp%d, pin already in use by temp%d\n", +						i - 7, (i - 11) / 2);  					continue;  				} @@ -1409,8 +1509,9 @@ static void pc87360_init_device(struct platform_device *pdev,  				reg = pc87360_read_value(data, LD_IN, i,  							 PC87365_REG_IN_STATUS);  				if (!(reg & CHAN_ENA)) { -					dev_dbg(&pdev->dev, "Forcibly " -						"enabling temp%d\n", i-7); +					dev_dbg(&pdev->dev, +						"Forcibly enabling temp%d\n", +						i - 7);  					pc87360_write_value(data, LD_IN, i,  						PC87365_REG_TEMP_STATUS,  						(reg & 0x60) | 0x8F); @@ -1424,8 +1525,8 @@ static void pc87360_init_device(struct platform_device *pdev,  					 PC87365_REG_IN_CONFIG);  		dev_dbg(&pdev->dev, "bios vin-cfg:0x%02x\n", reg);  		if (reg & CHAN_ENA) { -			dev_dbg(&pdev->dev, "Forcibly " -				"enabling monitoring (VLM)\n"); +			dev_dbg(&pdev->dev, +				"Forcibly enabling monitoring (VLM)\n");  			pc87360_write_value(data, LD_IN, NO_BANK,  					    PC87365_REG_IN_CONFIG,  					    reg & 0xFE); @@ -1437,8 +1538,8 @@ static void pc87360_init_device(struct platform_device *pdev,  					 PC87365_REG_TEMP_CONFIG);  		dev_dbg(&pdev->dev, "bios temp-cfg:0x%02x\n", reg);  		if (reg & CHAN_ENA) { -			dev_dbg(&pdev->dev, "Forcibly enabling " -				"monitoring (TMS)\n"); +			dev_dbg(&pdev->dev, +				"Forcibly enabling monitoring (TMS)\n");  			pc87360_write_value(data, LD_TEMP, NO_BANK,  					    PC87365_REG_TEMP_CONFIG,  					    reg & 0xFE); @@ -1447,10 +1548,12 @@ static void pc87360_init_device(struct platform_device *pdev,  		if (init >= 2) {  			/* Chip config as documented by National Semi. */  			pc87360_write_value(data, LD_TEMP, 0xF, 0xA, 0x08); -			/* We voluntarily omit the bank here, in case the -			   sequence itself matters. It shouldn't be a problem, -			   since nobody else is supposed to access the -			   device at that point. */ +			/* +			 * We voluntarily omit the bank here, in case the +			 * sequence itself matters. It shouldn't be a problem, +			 * since nobody else is supposed to access the +			 * device at that point. +			 */  			pc87360_write_value(data, LD_TEMP, NO_BANK, 0xB, 0x04);  			pc87360_write_value(data, LD_TEMP, NO_BANK, 0xC, 0x35);  			pc87360_write_value(data, LD_TEMP, NO_BANK, 0xD, 0x05); @@ -1471,9 +1574,9 @@ static void pc87360_autodiv(struct device *dev, int nr)  			data->fan_status[nr] += 0x20;  			data->fan_min[nr] >>= 1;  			data->fan[nr] >>= 1; -			dev_dbg(dev, "Increasing " -				"clock divider to %d for fan %d\n", -				FAN_DIV_FROM_REG(data->fan_status[nr]), nr+1); +			dev_dbg(dev, +				"Increasing clock divider to %d for fan %d\n", +				FAN_DIV_FROM_REG(data->fan_status[nr]), nr + 1);  		}  	} else {  		/* Decrease clock divider if possible */ @@ -1483,10 +1586,10 @@ static void pc87360_autodiv(struct device *dev, int nr)  			data->fan_status[nr] -= 0x20;  			data->fan_min[nr] <<= 1;  			data->fan[nr] <<= 1; -			dev_dbg(dev, "Decreasing " -				"clock divider to %d for fan %d\n", +			dev_dbg(dev, +				"Decreasing clock divider to %d for fan %d\n",  				FAN_DIV_FROM_REG(data->fan_status[nr]), -				nr+1); +				nr + 1);  		}  	} @@ -1616,7 +1719,7 @@ static int __init pc87360_device_add(unsigned short address)  	pdev = platform_device_alloc("pc87360", address);  	if (!pdev) {  		err = -ENOMEM; -		printk(KERN_ERR "pc87360: Device allocation failed\n"); +		pr_err("Device allocation failed\n");  		goto exit;  	} @@ -1639,15 +1742,13 @@ static int __init pc87360_device_add(unsigned short address)  	err = platform_device_add_resources(pdev, res, res_count);  	if (err) { -		printk(KERN_ERR "pc87360: Device resources addition failed " -		       "(%d)\n", err); +		pr_err("Device resources addition failed (%d)\n", err);  		goto exit_device_put;  	}  	err = platform_device_add(pdev);  	if (err) { -		printk(KERN_ERR "pc87360: Device addition failed (%d)\n", -		       err); +		pr_err("Device addition failed (%d)\n", err);  		goto exit_device_put;  	} @@ -1666,8 +1767,7 @@ static int __init pc87360_init(void)  	if (pc87360_find(0x2e, &devid, extra_isa)  	 && pc87360_find(0x4e, &devid, extra_isa)) { -		printk(KERN_WARNING "pc87360: PC8736x not detected, " -		       "module not inserted.\n"); +		pr_warn("PC8736x not detected, module not inserted\n");  		return -ENODEV;  	} @@ -1680,8 +1780,7 @@ static int __init pc87360_init(void)  	}  	if (address == 0x0000) { -		printk(KERN_WARNING "pc87360: No active logical device, " -		       "module not inserted.\n"); +		pr_warn("No active logical device, module not inserted\n");  		return -ENODEV;  	} @@ -1709,7 +1808,7 @@ static void __exit pc87360_exit(void)  } -MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); +MODULE_AUTHOR("Jean Delvare <jdelvare@suse.de>");  MODULE_DESCRIPTION("PC8736x hardware monitor");  MODULE_LICENSE("GPL");  | 
