| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 1 | /* | 
 | 2 | 	vt8231.c - Part of lm_sensors, Linux kernel modules | 
 | 3 | 				for hardware monitoring | 
 | 4 |  | 
| Roger Lucas | af86576 | 2008-02-13 07:52:06 -0500 | [diff] [blame] | 5 | 	Copyright (c) 2005 Roger Lucas <vt8231@hiddenengine.co.uk> | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 6 | 	Copyright (c) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com> | 
 | 7 | 			   Aaron M. Marsh <amarsh@sdf.lonestar.org> | 
 | 8 |  | 
 | 9 | 	This program is free software; you can redistribute it and/or modify | 
 | 10 | 	it under the terms of the GNU General Public License as published by | 
 | 11 | 	the Free Software Foundation; either version 2 of the License, or | 
 | 12 | 	(at your option) any later version. | 
 | 13 |  | 
 | 14 | 	This program is distributed in the hope that it will be useful, | 
 | 15 | 	but WITHOUT ANY WARRANTY; without even the implied warranty of | 
 | 16 | 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
 | 17 | 	GNU General Public License for more details. | 
 | 18 |  | 
 | 19 | 	You should have received a copy of the GNU General Public License | 
 | 20 | 	along with this program; if not, write to the Free Software | 
 | 21 | 	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 
 | 22 | */ | 
 | 23 |  | 
 | 24 | /* Supports VIA VT8231 South Bridge embedded sensors | 
 | 25 | */ | 
 | 26 |  | 
| Joe Perches | 9d72be0 | 2010-10-20 06:51:53 +0000 | [diff] [blame] | 27 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | 
 | 28 |  | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 29 | #include <linux/module.h> | 
 | 30 | #include <linux/init.h> | 
 | 31 | #include <linux/slab.h> | 
 | 32 | #include <linux/pci.h> | 
 | 33 | #include <linux/jiffies.h> | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 34 | #include <linux/platform_device.h> | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 35 | #include <linux/hwmon.h> | 
 | 36 | #include <linux/hwmon-sysfs.h> | 
 | 37 | #include <linux/hwmon-vid.h> | 
 | 38 | #include <linux/err.h> | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 39 | #include <linux/mutex.h> | 
| Jean Delvare | b9acb64 | 2009-01-07 16:37:35 +0100 | [diff] [blame] | 40 | #include <linux/acpi.h> | 
| H Hartley Sweeten | 6055fae | 2009-09-15 17:18:13 +0200 | [diff] [blame] | 41 | #include <linux/io.h> | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 42 |  | 
 | 43 | static int force_addr; | 
 | 44 | module_param(force_addr, int, 0); | 
 | 45 | MODULE_PARM_DESC(force_addr, "Initialize the base address of the sensors"); | 
 | 46 |  | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 47 | static struct platform_device *pdev; | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 48 |  | 
 | 49 | #define VT8231_EXTENT 0x80 | 
 | 50 | #define VT8231_BASE_REG 0x70 | 
 | 51 | #define VT8231_ENABLE_REG 0x74 | 
 | 52 |  | 
 | 53 | /* The VT8231 registers | 
 | 54 |  | 
 | 55 |    The reset value for the input channel configuration is used (Reg 0x4A=0x07) | 
 | 56 |    which sets the selected inputs marked with '*' below if multiple options are | 
 | 57 |    possible: | 
 | 58 |  | 
 | 59 | 	            Voltage Mode	  Temperature Mode | 
 | 60 | 	Sensor	      Linux Id	      Linux Id        VIA Id | 
 | 61 | 	--------      --------	      --------        ------ | 
 | 62 | 	CPU Diode	N/A		temp1		0 | 
 | 63 | 	UIC1		in0		temp2 *		1 | 
 | 64 | 	UIC2		in1 *		temp3   	2 | 
 | 65 | 	UIC3		in2 *		temp4		3 | 
 | 66 | 	UIC4		in3 *		temp5		4 | 
 | 67 | 	UIC5		in4 *		temp6		5 | 
 | 68 | 	3.3V		in5		N/A | 
 | 69 |  | 
 | 70 |    Note that the BIOS may set the configuration register to a different value | 
 | 71 |    to match the motherboard configuration. | 
 | 72 | */ | 
 | 73 |  | 
 | 74 | /* fans numbered 0-1 */ | 
 | 75 | #define VT8231_REG_FAN_MIN(nr)	(0x3b + (nr)) | 
 | 76 | #define VT8231_REG_FAN(nr)	(0x29 + (nr)) | 
 | 77 |  | 
 | 78 | /* Voltage inputs numbered 0-5 */ | 
 | 79 |  | 
 | 80 | static const u8 regvolt[]    = { 0x21, 0x22, 0x23, 0x24, 0x25, 0x26 }; | 
 | 81 | static const u8 regvoltmax[] = { 0x3d, 0x2b, 0x2d, 0x2f, 0x31, 0x33 }; | 
 | 82 | static const u8 regvoltmin[] = { 0x3e, 0x2c, 0x2e, 0x30, 0x32, 0x34 }; | 
 | 83 |  | 
 | 84 | /* Temperatures are numbered 1-6 according to the Linux kernel specification. | 
 | 85 | ** | 
 | 86 | ** In the VIA datasheet, however, the temperatures are numbered from zero. | 
 | 87 | ** Since it is important that this driver can easily be compared to the VIA | 
 | 88 | ** datasheet, we will use the VIA numbering within this driver and map the | 
 | 89 | ** kernel sysfs device name to the VIA number in the sysfs callback. | 
 | 90 | */ | 
 | 91 |  | 
 | 92 | #define VT8231_REG_TEMP_LOW01	0x49 | 
 | 93 | #define VT8231_REG_TEMP_LOW25	0x4d | 
 | 94 |  | 
 | 95 | static const u8 regtemp[]    = { 0x1f, 0x21, 0x22, 0x23, 0x24, 0x25 }; | 
 | 96 | static const u8 regtempmax[] = { 0x39, 0x3d, 0x2b, 0x2d, 0x2f, 0x31 }; | 
 | 97 | static const u8 regtempmin[] = { 0x3a, 0x3e, 0x2c, 0x2e, 0x30, 0x32 }; | 
 | 98 |  | 
 | 99 | #define TEMP_FROM_REG(reg)		(((253 * 4 - (reg)) * 550 + 105) / 210) | 
 | 100 | #define TEMP_MAXMIN_FROM_REG(reg)	(((253 - (reg)) * 2200 + 105) / 210) | 
 | 101 | #define TEMP_MAXMIN_TO_REG(val)		(253 - ((val) * 210 + 1100) / 2200) | 
 | 102 |  | 
 | 103 | #define VT8231_REG_CONFIG 0x40 | 
 | 104 | #define VT8231_REG_ALARM1 0x41 | 
 | 105 | #define VT8231_REG_ALARM2 0x42 | 
 | 106 | #define VT8231_REG_FANDIV 0x47 | 
 | 107 | #define VT8231_REG_UCH_CONFIG 0x4a | 
 | 108 | #define VT8231_REG_TEMP1_CONFIG 0x4b | 
 | 109 | #define VT8231_REG_TEMP2_CONFIG 0x4c | 
 | 110 |  | 
 | 111 | /* temps 0-5 as numbered in VIA datasheet - see later for mapping to Linux | 
 | 112 | ** numbering | 
 | 113 | */ | 
 | 114 | #define ISTEMP(i, ch_config) ((i) == 0 ? 1 : \ | 
 | 115 | 			      ((ch_config) >> ((i)+1)) & 0x01) | 
 | 116 | /* voltages 0-5 */ | 
 | 117 | #define ISVOLT(i, ch_config) ((i) == 5 ? 1 : \ | 
 | 118 | 			      !(((ch_config) >> ((i)+2)) & 0x01)) | 
 | 119 |  | 
 | 120 | #define DIV_FROM_REG(val) (1 << (val)) | 
 | 121 |  | 
 | 122 | /* NB  The values returned here are NOT temperatures.  The calibration curves | 
 | 123 | **     for the thermistor curves are board-specific and must go in the | 
 | 124 | **     sensors.conf file.  Temperature sensors are actually ten bits, but the | 
 | 125 | **     VIA datasheet only considers the 8 MSBs obtained from the regtemp[] | 
 | 126 | **     register.  The temperature value returned should have a magnitude of 3, | 
 | 127 | **     so we use the VIA scaling as the "true" scaling and use the remaining 2 | 
 | 128 | **     LSBs as fractional precision. | 
 | 129 | ** | 
 | 130 | **     All the on-chip hardware temperature comparisons for the alarms are only | 
 | 131 | **     8-bits wide, and compare against the 8 MSBs of the temperature.  The bits | 
 | 132 | **     in the registers VT8231_REG_TEMP_LOW01 and VT8231_REG_TEMP_LOW25 are | 
 | 133 | **     ignored. | 
 | 134 | */ | 
 | 135 |  | 
 | 136 | /******** FAN RPM CONVERSIONS ******** | 
 | 137 | ** This chip saturates back at 0, not at 255 like many the other chips. | 
 | 138 | ** So, 0 means 0 RPM | 
 | 139 | */ | 
 | 140 | static inline u8 FAN_TO_REG(long rpm, int div) | 
 | 141 | { | 
 | 142 | 	if (rpm == 0) | 
 | 143 | 		return 0; | 
 | 144 | 	return SENSORS_LIMIT(1310720 / (rpm * div), 1, 255); | 
 | 145 | } | 
 | 146 |  | 
 | 147 | #define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : 1310720 / ((val) * (div))) | 
 | 148 |  | 
 | 149 | struct vt8231_data { | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 150 | 	unsigned short addr; | 
 | 151 | 	const char *name; | 
 | 152 |  | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 153 | 	struct mutex update_lock; | 
| Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 154 | 	struct device *hwmon_dev; | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 155 | 	char valid;		/* !=0 if following fields are valid */ | 
 | 156 | 	unsigned long last_updated;	/* In jiffies */ | 
 | 157 |  | 
 | 158 | 	u8 in[6];		/* Register value */ | 
 | 159 | 	u8 in_max[6];		/* Register value */ | 
 | 160 | 	u8 in_min[6];		/* Register value */ | 
 | 161 | 	u16 temp[6];		/* Register value 10 bit, right aligned */ | 
 | 162 | 	u8 temp_max[6];		/* Register value */ | 
 | 163 | 	u8 temp_min[6];		/* Register value */ | 
 | 164 | 	u8 fan[2];		/* Register value */ | 
 | 165 | 	u8 fan_min[2];		/* Register value */ | 
 | 166 | 	u8 fan_div[2];		/* Register encoding, shifted right */ | 
 | 167 | 	u16 alarms;		/* Register encoding */ | 
 | 168 | 	u8 uch_config; | 
 | 169 | }; | 
 | 170 |  | 
 | 171 | static struct pci_dev *s_bridge; | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 172 | static int vt8231_probe(struct platform_device *pdev); | 
| Jean Delvare | d054612 | 2007-07-22 12:09:48 +0200 | [diff] [blame] | 173 | static int __devexit vt8231_remove(struct platform_device *pdev); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 174 | static struct vt8231_data *vt8231_update_device(struct device *dev); | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 175 | static void vt8231_init_device(struct vt8231_data *data); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 176 |  | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 177 | static inline int vt8231_read_value(struct vt8231_data *data, u8 reg) | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 178 | { | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 179 | 	return inb_p(data->addr + reg); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 180 | } | 
 | 181 |  | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 182 | static inline void vt8231_write_value(struct vt8231_data *data, u8 reg, | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 183 | 					u8 value) | 
 | 184 | { | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 185 | 	outb_p(value, data->addr + reg); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 186 | } | 
 | 187 |  | 
 | 188 | /* following are the sysfs callback functions */ | 
 | 189 | static ssize_t show_in(struct device *dev, struct device_attribute *attr, | 
 | 190 | 		char *buf) | 
 | 191 | { | 
 | 192 | 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 
 | 193 | 	int nr = sensor_attr->index; | 
 | 194 | 	struct vt8231_data *data = vt8231_update_device(dev); | 
 | 195 |  | 
 | 196 | 	return sprintf(buf, "%d\n", ((data->in[nr] - 3) * 10000) / 958); | 
 | 197 | } | 
 | 198 |  | 
 | 199 | static ssize_t show_in_min(struct device *dev, struct device_attribute *attr, | 
 | 200 | 		char *buf) | 
 | 201 | { | 
 | 202 | 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 
 | 203 | 	int nr = sensor_attr->index; | 
 | 204 | 	struct vt8231_data *data = vt8231_update_device(dev); | 
 | 205 |  | 
 | 206 | 	return sprintf(buf, "%d\n", ((data->in_min[nr] - 3) * 10000) / 958); | 
 | 207 | } | 
 | 208 |  | 
 | 209 | static ssize_t show_in_max(struct device *dev, struct device_attribute *attr, | 
 | 210 | 		char *buf) | 
 | 211 | { | 
 | 212 | 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 
 | 213 | 	int nr = sensor_attr->index; | 
 | 214 | 	struct vt8231_data *data = vt8231_update_device(dev); | 
 | 215 |  | 
 | 216 | 	return sprintf(buf, "%d\n", (((data->in_max[nr] - 3) * 10000) / 958)); | 
 | 217 | } | 
 | 218 |  | 
 | 219 | static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, | 
 | 220 | 		const char *buf, size_t count) | 
 | 221 | { | 
 | 222 | 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 
 | 223 | 	int nr = sensor_attr->index; | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 224 | 	struct vt8231_data *data = dev_get_drvdata(dev); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 225 | 	unsigned long val = simple_strtoul(buf, NULL, 10); | 
 | 226 |  | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 227 | 	mutex_lock(&data->update_lock); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 228 | 	data->in_min[nr] = SENSORS_LIMIT(((val * 958) / 10000) + 3, 0, 255); | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 229 | 	vt8231_write_value(data, regvoltmin[nr], data->in_min[nr]); | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 230 | 	mutex_unlock(&data->update_lock); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 231 | 	return count; | 
 | 232 | } | 
 | 233 |  | 
 | 234 | static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, | 
 | 235 | 		const char *buf, size_t count) | 
 | 236 | { | 
 | 237 | 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 
 | 238 | 	int nr = sensor_attr->index; | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 239 | 	struct vt8231_data *data = dev_get_drvdata(dev); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 240 | 	unsigned long val = simple_strtoul(buf, NULL, 10); | 
 | 241 |  | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 242 | 	mutex_lock(&data->update_lock); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 243 | 	data->in_max[nr] = SENSORS_LIMIT(((val * 958) / 10000) + 3, 0, 255); | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 244 | 	vt8231_write_value(data, regvoltmax[nr], data->in_max[nr]); | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 245 | 	mutex_unlock(&data->update_lock); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 246 | 	return count; | 
 | 247 | } | 
 | 248 |  | 
 | 249 | /* Special case for input 5 as this has 3.3V scaling built into the chip */ | 
 | 250 | static ssize_t show_in5(struct device *dev, struct device_attribute *attr, | 
 | 251 | 		char *buf) | 
 | 252 | { | 
 | 253 | 	struct vt8231_data *data = vt8231_update_device(dev); | 
 | 254 |  | 
 | 255 | 	return sprintf(buf, "%d\n", | 
 | 256 | 		(((data->in[5] - 3) * 10000 * 54) / (958 * 34))); | 
 | 257 | } | 
 | 258 |  | 
 | 259 | static ssize_t show_in5_min(struct device *dev, struct device_attribute *attr, | 
 | 260 | 		char *buf) | 
 | 261 | { | 
 | 262 | 	struct vt8231_data *data = vt8231_update_device(dev); | 
 | 263 |  | 
 | 264 | 	return sprintf(buf, "%d\n", | 
 | 265 | 		(((data->in_min[5] - 3) * 10000 * 54) / (958 * 34))); | 
 | 266 | } | 
 | 267 |  | 
 | 268 | static ssize_t show_in5_max(struct device *dev, struct device_attribute *attr, | 
 | 269 | 		char *buf) | 
 | 270 | { | 
 | 271 | 	struct vt8231_data *data = vt8231_update_device(dev); | 
 | 272 |  | 
 | 273 | 	return sprintf(buf, "%d\n", | 
 | 274 | 		(((data->in_max[5] - 3) * 10000 * 54) / (958 * 34))); | 
 | 275 | } | 
 | 276 |  | 
 | 277 | static ssize_t set_in5_min(struct device *dev, struct device_attribute *attr, | 
 | 278 | 		const char *buf, size_t count) | 
 | 279 | { | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 280 | 	struct vt8231_data *data = dev_get_drvdata(dev); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 281 | 	unsigned long val = simple_strtoul(buf, NULL, 10); | 
 | 282 |  | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 283 | 	mutex_lock(&data->update_lock); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 284 | 	data->in_min[5] = SENSORS_LIMIT(((val * 958 * 34) / (10000 * 54)) + 3, | 
 | 285 | 					0, 255); | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 286 | 	vt8231_write_value(data, regvoltmin[5], data->in_min[5]); | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 287 | 	mutex_unlock(&data->update_lock); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 288 | 	return count; | 
 | 289 | } | 
 | 290 |  | 
 | 291 | static ssize_t set_in5_max(struct device *dev, struct device_attribute *attr, | 
 | 292 | 		const char *buf, size_t count) | 
 | 293 | { | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 294 | 	struct vt8231_data *data = dev_get_drvdata(dev); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 295 | 	unsigned long val = simple_strtoul(buf, NULL, 10); | 
 | 296 |  | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 297 | 	mutex_lock(&data->update_lock); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 298 | 	data->in_max[5] = SENSORS_LIMIT(((val * 958 * 34) / (10000 * 54)) + 3, | 
 | 299 | 					0, 255); | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 300 | 	vt8231_write_value(data, regvoltmax[5], data->in_max[5]); | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 301 | 	mutex_unlock(&data->update_lock); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 302 | 	return count; | 
 | 303 | } | 
 | 304 |  | 
 | 305 | #define define_voltage_sysfs(offset)				\ | 
 | 306 | static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO,		\ | 
 | 307 | 		show_in, NULL, offset);				\ | 
 | 308 | static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR,	\ | 
 | 309 | 		show_in_min, set_in_min, offset);		\ | 
 | 310 | static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR,	\ | 
 | 311 | 		show_in_max, set_in_max, offset) | 
 | 312 |  | 
 | 313 | define_voltage_sysfs(0); | 
 | 314 | define_voltage_sysfs(1); | 
 | 315 | define_voltage_sysfs(2); | 
 | 316 | define_voltage_sysfs(3); | 
 | 317 | define_voltage_sysfs(4); | 
 | 318 |  | 
 | 319 | static DEVICE_ATTR(in5_input, S_IRUGO, show_in5, NULL); | 
 | 320 | static DEVICE_ATTR(in5_min, S_IRUGO | S_IWUSR, show_in5_min, set_in5_min); | 
 | 321 | static DEVICE_ATTR(in5_max, S_IRUGO | S_IWUSR, show_in5_max, set_in5_max); | 
 | 322 |  | 
 | 323 | /* Temperatures */ | 
 | 324 | static ssize_t show_temp0(struct device *dev, struct device_attribute *attr, | 
 | 325 | 		char *buf) | 
 | 326 | { | 
 | 327 | 	struct vt8231_data *data = vt8231_update_device(dev); | 
 | 328 | 	return sprintf(buf, "%d\n", data->temp[0] * 250); | 
 | 329 | } | 
 | 330 |  | 
 | 331 | static ssize_t show_temp0_max(struct device *dev, struct device_attribute *attr, | 
 | 332 | 		char *buf) | 
 | 333 | { | 
 | 334 | 	struct vt8231_data *data = vt8231_update_device(dev); | 
 | 335 | 	return sprintf(buf, "%d\n", data->temp_max[0] * 1000); | 
 | 336 | } | 
 | 337 |  | 
 | 338 | static ssize_t show_temp0_min(struct device *dev, struct device_attribute *attr, | 
 | 339 | 		char *buf) | 
 | 340 | { | 
 | 341 | 	struct vt8231_data *data = vt8231_update_device(dev); | 
 | 342 | 	return sprintf(buf, "%d\n", data->temp_min[0] * 1000); | 
 | 343 | } | 
 | 344 |  | 
 | 345 | static ssize_t set_temp0_max(struct device *dev, struct device_attribute *attr, | 
 | 346 | 		const char *buf, size_t count) | 
 | 347 | { | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 348 | 	struct vt8231_data *data = dev_get_drvdata(dev); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 349 | 	int val = simple_strtol(buf, NULL, 10); | 
 | 350 |  | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 351 | 	mutex_lock(&data->update_lock); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 352 | 	data->temp_max[0] = SENSORS_LIMIT((val + 500) / 1000, 0, 255); | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 353 | 	vt8231_write_value(data, regtempmax[0], data->temp_max[0]); | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 354 | 	mutex_unlock(&data->update_lock); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 355 | 	return count; | 
 | 356 | } | 
 | 357 | static ssize_t set_temp0_min(struct device *dev, struct device_attribute *attr, | 
 | 358 | 		const char *buf, size_t count) | 
 | 359 | { | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 360 | 	struct vt8231_data *data = dev_get_drvdata(dev); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 361 | 	int val = simple_strtol(buf, NULL, 10); | 
 | 362 |  | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 363 | 	mutex_lock(&data->update_lock); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 364 | 	data->temp_min[0] = SENSORS_LIMIT((val + 500) / 1000, 0, 255); | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 365 | 	vt8231_write_value(data, regtempmin[0], data->temp_min[0]); | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 366 | 	mutex_unlock(&data->update_lock); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 367 | 	return count; | 
 | 368 | } | 
 | 369 |  | 
 | 370 | static ssize_t show_temp(struct device *dev, struct device_attribute *attr, | 
 | 371 | 		char *buf) | 
 | 372 | { | 
 | 373 | 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 
 | 374 | 	int nr = sensor_attr->index; | 
 | 375 | 	struct vt8231_data *data = vt8231_update_device(dev); | 
 | 376 | 	return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr])); | 
 | 377 | } | 
 | 378 |  | 
 | 379 | static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr, | 
 | 380 | 		char *buf) | 
 | 381 | { | 
 | 382 | 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 
 | 383 | 	int nr = sensor_attr->index; | 
 | 384 | 	struct vt8231_data *data = vt8231_update_device(dev); | 
 | 385 | 	return sprintf(buf, "%d\n", TEMP_MAXMIN_FROM_REG(data->temp_max[nr])); | 
 | 386 | } | 
 | 387 |  | 
 | 388 | static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr, | 
 | 389 | 		char *buf) | 
 | 390 | { | 
 | 391 | 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 
 | 392 | 	int nr = sensor_attr->index; | 
 | 393 | 	struct vt8231_data *data = vt8231_update_device(dev); | 
 | 394 | 	return sprintf(buf, "%d\n", TEMP_MAXMIN_FROM_REG(data->temp_min[nr])); | 
 | 395 | } | 
 | 396 |  | 
 | 397 | static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | 
 | 398 | 		const char *buf, size_t count) | 
 | 399 | { | 
 | 400 | 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 
 | 401 | 	int nr = sensor_attr->index; | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 402 | 	struct vt8231_data *data = dev_get_drvdata(dev); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 403 | 	int val = simple_strtol(buf, NULL, 10); | 
 | 404 |  | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 405 | 	mutex_lock(&data->update_lock); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 406 | 	data->temp_max[nr] = SENSORS_LIMIT(TEMP_MAXMIN_TO_REG(val), 0, 255); | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 407 | 	vt8231_write_value(data, regtempmax[nr], data->temp_max[nr]); | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 408 | 	mutex_unlock(&data->update_lock); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 409 | 	return count; | 
 | 410 | } | 
 | 411 | static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, | 
 | 412 | 		const char *buf, size_t count) | 
 | 413 | { | 
 | 414 | 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 
 | 415 | 	int nr = sensor_attr->index; | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 416 | 	struct vt8231_data *data = dev_get_drvdata(dev); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 417 | 	int val = simple_strtol(buf, NULL, 10); | 
 | 418 |  | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 419 | 	mutex_lock(&data->update_lock); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 420 | 	data->temp_min[nr] = SENSORS_LIMIT(TEMP_MAXMIN_TO_REG(val), 0, 255); | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 421 | 	vt8231_write_value(data, regtempmin[nr], data->temp_min[nr]); | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 422 | 	mutex_unlock(&data->update_lock); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 423 | 	return count; | 
 | 424 | } | 
 | 425 |  | 
 | 426 | /* Note that these map the Linux temperature sensor numbering (1-6) to the VIA | 
 | 427 | ** temperature sensor numbering (0-5) | 
 | 428 | */ | 
 | 429 | #define define_temperature_sysfs(offset)				\ | 
 | 430 | static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO,		\ | 
 | 431 | 		show_temp, NULL, offset - 1);				\ | 
 | 432 | static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR,	\ | 
 | 433 | 		show_temp_max, set_temp_max, offset - 1);		\ | 
| Jean Delvare | e3efa5a | 2006-02-05 23:11:16 +0100 | [diff] [blame] | 434 | static SENSOR_DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO | S_IWUSR,	\ | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 435 | 		show_temp_min, set_temp_min, offset - 1) | 
 | 436 |  | 
 | 437 | static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp0, NULL); | 
 | 438 | static DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR, show_temp0_max, set_temp0_max); | 
| Jean Delvare | e3efa5a | 2006-02-05 23:11:16 +0100 | [diff] [blame] | 439 | static DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR, show_temp0_min, set_temp0_min); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 440 |  | 
 | 441 | define_temperature_sysfs(2); | 
 | 442 | define_temperature_sysfs(3); | 
 | 443 | define_temperature_sysfs(4); | 
 | 444 | define_temperature_sysfs(5); | 
 | 445 | define_temperature_sysfs(6); | 
 | 446 |  | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 447 | /* Fans */ | 
 | 448 | static ssize_t show_fan(struct device *dev, struct device_attribute *attr, | 
 | 449 | 		char *buf) | 
 | 450 | { | 
 | 451 | 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 
 | 452 | 	int nr = sensor_attr->index; | 
 | 453 | 	struct vt8231_data *data = vt8231_update_device(dev); | 
 | 454 | 	return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], | 
 | 455 | 				DIV_FROM_REG(data->fan_div[nr]))); | 
 | 456 | } | 
 | 457 |  | 
 | 458 | static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr, | 
 | 459 | 		char *buf) | 
 | 460 | { | 
 | 461 | 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 
 | 462 | 	int nr = sensor_attr->index; | 
 | 463 | 	struct vt8231_data *data = vt8231_update_device(dev); | 
 | 464 | 	return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr], | 
 | 465 | 			DIV_FROM_REG(data->fan_div[nr]))); | 
 | 466 | } | 
 | 467 |  | 
 | 468 | static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr, | 
 | 469 | 		char *buf) | 
 | 470 | { | 
 | 471 | 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 
 | 472 | 	int nr = sensor_attr->index; | 
 | 473 | 	struct vt8231_data *data = vt8231_update_device(dev); | 
 | 474 | 	return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr])); | 
 | 475 | } | 
 | 476 |  | 
 | 477 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, | 
 | 478 | 		const char *buf, size_t count) | 
 | 479 | { | 
 | 480 | 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 
 | 481 | 	int nr = sensor_attr->index; | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 482 | 	struct vt8231_data *data = dev_get_drvdata(dev); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 483 | 	int val = simple_strtoul(buf, NULL, 10); | 
 | 484 |  | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 485 | 	mutex_lock(&data->update_lock); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 486 | 	data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 487 | 	vt8231_write_value(data, VT8231_REG_FAN_MIN(nr), data->fan_min[nr]); | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 488 | 	mutex_unlock(&data->update_lock); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 489 | 	return count; | 
 | 490 | } | 
 | 491 |  | 
 | 492 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, | 
 | 493 | 		const char *buf, size_t count) | 
 | 494 | { | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 495 | 	struct vt8231_data *data = dev_get_drvdata(dev); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 496 | 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 
 | 497 | 	unsigned long val = simple_strtoul(buf, NULL, 10); | 
 | 498 | 	int nr = sensor_attr->index; | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 499 | 	int old = vt8231_read_value(data, VT8231_REG_FANDIV); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 500 | 	long min = FAN_FROM_REG(data->fan_min[nr], | 
 | 501 | 				 DIV_FROM_REG(data->fan_div[nr])); | 
 | 502 |  | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 503 | 	mutex_lock(&data->update_lock); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 504 | 	switch (val) { | 
 | 505 | 	case 1: data->fan_div[nr] = 0; break; | 
 | 506 | 	case 2: data->fan_div[nr] = 1; break; | 
 | 507 | 	case 4: data->fan_div[nr] = 2; break; | 
 | 508 | 	case 8: data->fan_div[nr] = 3; break; | 
 | 509 | 	default: | 
| Joe Perches | b20ff13 | 2007-11-19 17:48:07 -0800 | [diff] [blame] | 510 | 		dev_err(dev, "fan_div value %ld not supported. " | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 511 | 		        "Choose one of 1, 2, 4 or 8!\n", val); | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 512 | 		mutex_unlock(&data->update_lock); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 513 | 		return -EINVAL; | 
 | 514 | 	} | 
 | 515 |  | 
 | 516 | 	/* Correct the fan minimum speed */ | 
 | 517 | 	data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 518 | 	vt8231_write_value(data, VT8231_REG_FAN_MIN(nr), data->fan_min[nr]); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 519 |  | 
 | 520 | 	old = (old & 0x0f) | (data->fan_div[1] << 6) | (data->fan_div[0] << 4); | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 521 | 	vt8231_write_value(data, VT8231_REG_FANDIV, old); | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 522 | 	mutex_unlock(&data->update_lock); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 523 | 	return count; | 
 | 524 | } | 
 | 525 |  | 
 | 526 |  | 
 | 527 | #define define_fan_sysfs(offset)					\ | 
 | 528 | static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO,			\ | 
 | 529 | 		show_fan, NULL, offset - 1);				\ | 
 | 530 | static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR,		\ | 
 | 531 | 		show_fan_div, set_fan_div, offset - 1);			\ | 
 | 532 | static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR,		\ | 
 | 533 | 		show_fan_min, set_fan_min, offset - 1) | 
 | 534 |  | 
 | 535 | define_fan_sysfs(1); | 
 | 536 | define_fan_sysfs(2); | 
 | 537 |  | 
 | 538 | /* Alarms */ | 
 | 539 | static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, | 
 | 540 | 			   char *buf) | 
 | 541 | { | 
 | 542 | 	struct vt8231_data *data = vt8231_update_device(dev); | 
 | 543 | 	return sprintf(buf, "%d\n", data->alarms); | 
 | 544 | } | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 545 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); | 
 | 546 |  | 
| Jean Delvare | 2d1374c | 2008-01-06 15:46:02 +0100 | [diff] [blame] | 547 | static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, | 
 | 548 | 			  char *buf) | 
 | 549 | { | 
 | 550 | 	int bitnr = to_sensor_dev_attr(attr)->index; | 
 | 551 | 	struct vt8231_data *data = vt8231_update_device(dev); | 
 | 552 | 	return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); | 
 | 553 | } | 
 | 554 | static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4); | 
 | 555 | static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 11); | 
 | 556 | static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 0); | 
 | 557 | static SENSOR_DEVICE_ATTR(temp4_alarm, S_IRUGO, show_alarm, NULL, 1); | 
 | 558 | static SENSOR_DEVICE_ATTR(temp5_alarm, S_IRUGO, show_alarm, NULL, 3); | 
 | 559 | static SENSOR_DEVICE_ATTR(temp6_alarm, S_IRUGO, show_alarm, NULL, 8); | 
 | 560 | static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 11); | 
 | 561 | static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 0); | 
 | 562 | static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 1); | 
 | 563 | static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3); | 
 | 564 | static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8); | 
 | 565 | static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 2); | 
 | 566 | static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6); | 
 | 567 | static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7); | 
 | 568 |  | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 569 | static ssize_t show_name(struct device *dev, struct device_attribute | 
 | 570 | 			 *devattr, char *buf) | 
 | 571 | { | 
 | 572 | 	struct vt8231_data *data = dev_get_drvdata(dev); | 
 | 573 | 	return sprintf(buf, "%s\n", data->name); | 
 | 574 | } | 
 | 575 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); | 
 | 576 |  | 
| Jean Delvare | 2d1374c | 2008-01-06 15:46:02 +0100 | [diff] [blame] | 577 | static struct attribute *vt8231_attributes_temps[6][5] = { | 
| Roger Lucas | cbeeb5b | 2006-09-24 21:21:46 +0200 | [diff] [blame] | 578 | 	{ | 
 | 579 | 		&dev_attr_temp1_input.attr, | 
 | 580 | 		&dev_attr_temp1_max_hyst.attr, | 
 | 581 | 		&dev_attr_temp1_max.attr, | 
| Jean Delvare | 2d1374c | 2008-01-06 15:46:02 +0100 | [diff] [blame] | 582 | 		&sensor_dev_attr_temp1_alarm.dev_attr.attr, | 
| Roger Lucas | cbeeb5b | 2006-09-24 21:21:46 +0200 | [diff] [blame] | 583 | 		NULL | 
 | 584 | 	}, { | 
 | 585 | 		&sensor_dev_attr_temp2_input.dev_attr.attr, | 
 | 586 | 		&sensor_dev_attr_temp2_max_hyst.dev_attr.attr, | 
 | 587 | 		&sensor_dev_attr_temp2_max.dev_attr.attr, | 
| Jean Delvare | 2d1374c | 2008-01-06 15:46:02 +0100 | [diff] [blame] | 588 | 		&sensor_dev_attr_temp2_alarm.dev_attr.attr, | 
| Roger Lucas | cbeeb5b | 2006-09-24 21:21:46 +0200 | [diff] [blame] | 589 | 		NULL | 
 | 590 | 	}, { | 
 | 591 | 		&sensor_dev_attr_temp3_input.dev_attr.attr, | 
 | 592 | 		&sensor_dev_attr_temp3_max_hyst.dev_attr.attr, | 
 | 593 | 		&sensor_dev_attr_temp3_max.dev_attr.attr, | 
| Jean Delvare | 2d1374c | 2008-01-06 15:46:02 +0100 | [diff] [blame] | 594 | 		&sensor_dev_attr_temp3_alarm.dev_attr.attr, | 
| Roger Lucas | cbeeb5b | 2006-09-24 21:21:46 +0200 | [diff] [blame] | 595 | 		NULL | 
 | 596 | 	}, { | 
 | 597 | 		&sensor_dev_attr_temp4_input.dev_attr.attr, | 
 | 598 | 		&sensor_dev_attr_temp4_max_hyst.dev_attr.attr, | 
 | 599 | 		&sensor_dev_attr_temp4_max.dev_attr.attr, | 
| Jean Delvare | 2d1374c | 2008-01-06 15:46:02 +0100 | [diff] [blame] | 600 | 		&sensor_dev_attr_temp4_alarm.dev_attr.attr, | 
| Roger Lucas | cbeeb5b | 2006-09-24 21:21:46 +0200 | [diff] [blame] | 601 | 		NULL | 
 | 602 | 	}, { | 
 | 603 | 		&sensor_dev_attr_temp5_input.dev_attr.attr, | 
 | 604 | 		&sensor_dev_attr_temp5_max_hyst.dev_attr.attr, | 
 | 605 | 		&sensor_dev_attr_temp5_max.dev_attr.attr, | 
| Jean Delvare | 2d1374c | 2008-01-06 15:46:02 +0100 | [diff] [blame] | 606 | 		&sensor_dev_attr_temp5_alarm.dev_attr.attr, | 
| Roger Lucas | cbeeb5b | 2006-09-24 21:21:46 +0200 | [diff] [blame] | 607 | 		NULL | 
 | 608 | 	}, { | 
 | 609 | 		&sensor_dev_attr_temp6_input.dev_attr.attr, | 
 | 610 | 		&sensor_dev_attr_temp6_max_hyst.dev_attr.attr, | 
 | 611 | 		&sensor_dev_attr_temp6_max.dev_attr.attr, | 
| Jean Delvare | 2d1374c | 2008-01-06 15:46:02 +0100 | [diff] [blame] | 612 | 		&sensor_dev_attr_temp6_alarm.dev_attr.attr, | 
| Roger Lucas | cbeeb5b | 2006-09-24 21:21:46 +0200 | [diff] [blame] | 613 | 		NULL | 
 | 614 | 	} | 
 | 615 | }; | 
 | 616 |  | 
 | 617 | static const struct attribute_group vt8231_group_temps[6] = { | 
 | 618 | 	{ .attrs = vt8231_attributes_temps[0] }, | 
 | 619 | 	{ .attrs = vt8231_attributes_temps[1] }, | 
 | 620 | 	{ .attrs = vt8231_attributes_temps[2] }, | 
 | 621 | 	{ .attrs = vt8231_attributes_temps[3] }, | 
 | 622 | 	{ .attrs = vt8231_attributes_temps[4] }, | 
 | 623 | 	{ .attrs = vt8231_attributes_temps[5] }, | 
 | 624 | }; | 
 | 625 |  | 
| Jean Delvare | 2d1374c | 2008-01-06 15:46:02 +0100 | [diff] [blame] | 626 | static struct attribute *vt8231_attributes_volts[6][5] = { | 
| Roger Lucas | cbeeb5b | 2006-09-24 21:21:46 +0200 | [diff] [blame] | 627 | 	{ | 
 | 628 | 		&sensor_dev_attr_in0_input.dev_attr.attr, | 
 | 629 | 		&sensor_dev_attr_in0_min.dev_attr.attr, | 
 | 630 | 		&sensor_dev_attr_in0_max.dev_attr.attr, | 
| Jean Delvare | 2d1374c | 2008-01-06 15:46:02 +0100 | [diff] [blame] | 631 | 		&sensor_dev_attr_in0_alarm.dev_attr.attr, | 
| Roger Lucas | cbeeb5b | 2006-09-24 21:21:46 +0200 | [diff] [blame] | 632 | 		NULL | 
 | 633 | 	}, { | 
 | 634 | 		&sensor_dev_attr_in1_input.dev_attr.attr, | 
 | 635 | 		&sensor_dev_attr_in1_min.dev_attr.attr, | 
 | 636 | 		&sensor_dev_attr_in1_max.dev_attr.attr, | 
| Jean Delvare | 2d1374c | 2008-01-06 15:46:02 +0100 | [diff] [blame] | 637 | 		&sensor_dev_attr_in1_alarm.dev_attr.attr, | 
| Roger Lucas | cbeeb5b | 2006-09-24 21:21:46 +0200 | [diff] [blame] | 638 | 		NULL | 
 | 639 | 	}, { | 
 | 640 | 		&sensor_dev_attr_in2_input.dev_attr.attr, | 
 | 641 | 		&sensor_dev_attr_in2_min.dev_attr.attr, | 
 | 642 | 		&sensor_dev_attr_in2_max.dev_attr.attr, | 
| Jean Delvare | 2d1374c | 2008-01-06 15:46:02 +0100 | [diff] [blame] | 643 | 		&sensor_dev_attr_in2_alarm.dev_attr.attr, | 
| Roger Lucas | cbeeb5b | 2006-09-24 21:21:46 +0200 | [diff] [blame] | 644 | 		NULL | 
 | 645 | 	}, { | 
 | 646 | 		&sensor_dev_attr_in3_input.dev_attr.attr, | 
 | 647 | 		&sensor_dev_attr_in3_min.dev_attr.attr, | 
 | 648 | 		&sensor_dev_attr_in3_max.dev_attr.attr, | 
| Jean Delvare | 2d1374c | 2008-01-06 15:46:02 +0100 | [diff] [blame] | 649 | 		&sensor_dev_attr_in3_alarm.dev_attr.attr, | 
| Roger Lucas | cbeeb5b | 2006-09-24 21:21:46 +0200 | [diff] [blame] | 650 | 		NULL | 
 | 651 | 	}, { | 
 | 652 | 		&sensor_dev_attr_in4_input.dev_attr.attr, | 
 | 653 | 		&sensor_dev_attr_in4_min.dev_attr.attr, | 
 | 654 | 		&sensor_dev_attr_in4_max.dev_attr.attr, | 
| Jean Delvare | 2d1374c | 2008-01-06 15:46:02 +0100 | [diff] [blame] | 655 | 		&sensor_dev_attr_in4_alarm.dev_attr.attr, | 
| Roger Lucas | cbeeb5b | 2006-09-24 21:21:46 +0200 | [diff] [blame] | 656 | 		NULL | 
 | 657 | 	}, { | 
 | 658 | 		&dev_attr_in5_input.attr, | 
 | 659 | 		&dev_attr_in5_min.attr, | 
 | 660 | 		&dev_attr_in5_max.attr, | 
| Jean Delvare | 2d1374c | 2008-01-06 15:46:02 +0100 | [diff] [blame] | 661 | 		&sensor_dev_attr_in5_alarm.dev_attr.attr, | 
| Roger Lucas | cbeeb5b | 2006-09-24 21:21:46 +0200 | [diff] [blame] | 662 | 		NULL | 
 | 663 | 	} | 
 | 664 | }; | 
 | 665 |  | 
 | 666 | static const struct attribute_group vt8231_group_volts[6] = { | 
 | 667 | 	{ .attrs = vt8231_attributes_volts[0] }, | 
 | 668 | 	{ .attrs = vt8231_attributes_volts[1] }, | 
 | 669 | 	{ .attrs = vt8231_attributes_volts[2] }, | 
 | 670 | 	{ .attrs = vt8231_attributes_volts[3] }, | 
 | 671 | 	{ .attrs = vt8231_attributes_volts[4] }, | 
 | 672 | 	{ .attrs = vt8231_attributes_volts[5] }, | 
 | 673 | }; | 
 | 674 |  | 
 | 675 | static struct attribute *vt8231_attributes[] = { | 
 | 676 | 	&sensor_dev_attr_fan1_input.dev_attr.attr, | 
 | 677 | 	&sensor_dev_attr_fan2_input.dev_attr.attr, | 
 | 678 | 	&sensor_dev_attr_fan1_min.dev_attr.attr, | 
 | 679 | 	&sensor_dev_attr_fan2_min.dev_attr.attr, | 
 | 680 | 	&sensor_dev_attr_fan1_div.dev_attr.attr, | 
 | 681 | 	&sensor_dev_attr_fan2_div.dev_attr.attr, | 
| Jean Delvare | 2d1374c | 2008-01-06 15:46:02 +0100 | [diff] [blame] | 682 | 	&sensor_dev_attr_fan1_alarm.dev_attr.attr, | 
 | 683 | 	&sensor_dev_attr_fan2_alarm.dev_attr.attr, | 
| Roger Lucas | cbeeb5b | 2006-09-24 21:21:46 +0200 | [diff] [blame] | 684 | 	&dev_attr_alarms.attr, | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 685 | 	&dev_attr_name.attr, | 
| Roger Lucas | cbeeb5b | 2006-09-24 21:21:46 +0200 | [diff] [blame] | 686 | 	NULL | 
 | 687 | }; | 
 | 688 |  | 
 | 689 | static const struct attribute_group vt8231_group = { | 
 | 690 | 	.attrs = vt8231_attributes, | 
 | 691 | }; | 
 | 692 |  | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 693 | static struct platform_driver vt8231_driver = { | 
| Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 694 | 	.driver = { | 
| Jean Delvare | 8721884 | 2006-09-03 22:36:14 +0200 | [diff] [blame] | 695 | 		.owner	= THIS_MODULE, | 
| Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 696 | 		.name	= "vt8231", | 
 | 697 | 	}, | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 698 | 	.probe	= vt8231_probe, | 
 | 699 | 	.remove	= __devexit_p(vt8231_remove), | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 700 | }; | 
 | 701 |  | 
| Márton Németh | 3dd3a15 | 2010-01-10 20:52:35 +0100 | [diff] [blame] | 702 | static const struct pci_device_id vt8231_pci_ids[] = { | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 703 | 	{ PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231_4) }, | 
 | 704 | 	{ 0, } | 
 | 705 | }; | 
 | 706 |  | 
 | 707 | MODULE_DEVICE_TABLE(pci, vt8231_pci_ids); | 
 | 708 |  | 
 | 709 | static int __devinit vt8231_pci_probe(struct pci_dev *dev, | 
 | 710 | 			 	      const struct pci_device_id *id); | 
 | 711 |  | 
 | 712 | static struct pci_driver vt8231_pci_driver = { | 
 | 713 | 	.name		= "vt8231", | 
 | 714 | 	.id_table	= vt8231_pci_ids, | 
 | 715 | 	.probe		= vt8231_pci_probe, | 
 | 716 | }; | 
 | 717 |  | 
| Mark M. Hoffman | a022fef | 2007-10-14 15:00:24 -0400 | [diff] [blame] | 718 | static int vt8231_probe(struct platform_device *pdev) | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 719 | { | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 720 | 	struct resource *res; | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 721 | 	struct vt8231_data *data; | 
 | 722 | 	int err = 0, i; | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 723 |  | 
 | 724 | 	/* Reserve the ISA region */ | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 725 | 	res = platform_get_resource(pdev, IORESOURCE_IO, 0); | 
 | 726 | 	if (!request_region(res->start, VT8231_EXTENT, | 
 | 727 | 			    vt8231_driver.driver.name)) { | 
 | 728 | 		dev_err(&pdev->dev, "Region 0x%lx-0x%lx already in use!\n", | 
 | 729 | 			(unsigned long)res->start, (unsigned long)res->end); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 730 | 		return -ENODEV; | 
 | 731 | 	} | 
 | 732 |  | 
 | 733 | 	if (!(data = kzalloc(sizeof(struct vt8231_data), GFP_KERNEL))) { | 
 | 734 | 		err = -ENOMEM; | 
 | 735 | 		goto exit_release; | 
 | 736 | 	} | 
 | 737 |  | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 738 | 	platform_set_drvdata(pdev, data); | 
 | 739 | 	data->addr = res->start; | 
 | 740 | 	data->name = "vt8231"; | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 741 |  | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 742 | 	mutex_init(&data->update_lock); | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 743 | 	vt8231_init_device(data); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 744 |  | 
 | 745 | 	/* Register sysfs hooks */ | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 746 | 	if ((err = sysfs_create_group(&pdev->dev.kobj, &vt8231_group))) | 
 | 747 | 		goto exit_free; | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 748 |  | 
 | 749 | 	/* Must update device information to find out the config field */ | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 750 | 	data->uch_config = vt8231_read_value(data, VT8231_REG_UCH_CONFIG); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 751 |  | 
| Roger Lucas | cbeeb5b | 2006-09-24 21:21:46 +0200 | [diff] [blame] | 752 | 	for (i = 0; i < ARRAY_SIZE(vt8231_group_temps); i++) { | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 753 | 		if (ISTEMP(i, data->uch_config)) { | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 754 | 			if ((err = sysfs_create_group(&pdev->dev.kobj, | 
| Roger Lucas | cbeeb5b | 2006-09-24 21:21:46 +0200 | [diff] [blame] | 755 | 					&vt8231_group_temps[i]))) | 
 | 756 | 				goto exit_remove_files; | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 757 | 		} | 
 | 758 | 	} | 
 | 759 |  | 
| Roger Lucas | cbeeb5b | 2006-09-24 21:21:46 +0200 | [diff] [blame] | 760 | 	for (i = 0; i < ARRAY_SIZE(vt8231_group_volts); i++) { | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 761 | 		if (ISVOLT(i, data->uch_config)) { | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 762 | 			if ((err = sysfs_create_group(&pdev->dev.kobj, | 
| Roger Lucas | cbeeb5b | 2006-09-24 21:21:46 +0200 | [diff] [blame] | 763 | 					&vt8231_group_volts[i]))) | 
 | 764 | 				goto exit_remove_files; | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 765 | 		} | 
 | 766 | 	} | 
 | 767 |  | 
| Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 768 | 	data->hwmon_dev = hwmon_device_register(&pdev->dev); | 
 | 769 | 	if (IS_ERR(data->hwmon_dev)) { | 
 | 770 | 		err = PTR_ERR(data->hwmon_dev); | 
| Roger Lucas | cbeeb5b | 2006-09-24 21:21:46 +0200 | [diff] [blame] | 771 | 		goto exit_remove_files; | 
 | 772 | 	} | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 773 | 	return 0; | 
 | 774 |  | 
| Roger Lucas | cbeeb5b | 2006-09-24 21:21:46 +0200 | [diff] [blame] | 775 | exit_remove_files: | 
 | 776 | 	for (i = 0; i < ARRAY_SIZE(vt8231_group_volts); i++) | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 777 | 		sysfs_remove_group(&pdev->dev.kobj, &vt8231_group_volts[i]); | 
| Roger Lucas | cbeeb5b | 2006-09-24 21:21:46 +0200 | [diff] [blame] | 778 |  | 
 | 779 | 	for (i = 0; i < ARRAY_SIZE(vt8231_group_temps); i++) | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 780 | 		sysfs_remove_group(&pdev->dev.kobj, &vt8231_group_temps[i]); | 
| Roger Lucas | cbeeb5b | 2006-09-24 21:21:46 +0200 | [diff] [blame] | 781 |  | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 782 | 	sysfs_remove_group(&pdev->dev.kobj, &vt8231_group); | 
 | 783 |  | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 784 | exit_free: | 
| Jean Delvare | 04a6217 | 2007-06-12 13:57:19 +0200 | [diff] [blame] | 785 | 	platform_set_drvdata(pdev, NULL); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 786 | 	kfree(data); | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 787 |  | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 788 | exit_release: | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 789 | 	release_region(res->start, VT8231_EXTENT); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 790 | 	return err; | 
 | 791 | } | 
 | 792 |  | 
| Jean Delvare | d054612 | 2007-07-22 12:09:48 +0200 | [diff] [blame] | 793 | static int __devexit vt8231_remove(struct platform_device *pdev) | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 794 | { | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 795 | 	struct vt8231_data *data = platform_get_drvdata(pdev); | 
 | 796 | 	int i; | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 797 |  | 
| Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 798 | 	hwmon_device_unregister(data->hwmon_dev); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 799 |  | 
| Roger Lucas | cbeeb5b | 2006-09-24 21:21:46 +0200 | [diff] [blame] | 800 | 	for (i = 0; i < ARRAY_SIZE(vt8231_group_volts); i++) | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 801 | 		sysfs_remove_group(&pdev->dev.kobj, &vt8231_group_volts[i]); | 
| Roger Lucas | cbeeb5b | 2006-09-24 21:21:46 +0200 | [diff] [blame] | 802 |  | 
 | 803 | 	for (i = 0; i < ARRAY_SIZE(vt8231_group_temps); i++) | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 804 | 		sysfs_remove_group(&pdev->dev.kobj, &vt8231_group_temps[i]); | 
| Roger Lucas | cbeeb5b | 2006-09-24 21:21:46 +0200 | [diff] [blame] | 805 |  | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 806 | 	sysfs_remove_group(&pdev->dev.kobj, &vt8231_group); | 
| Roger Lucas | cbeeb5b | 2006-09-24 21:21:46 +0200 | [diff] [blame] | 807 |  | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 808 | 	release_region(data->addr, VT8231_EXTENT); | 
 | 809 | 	platform_set_drvdata(pdev, NULL); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 810 | 	kfree(data); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 811 | 	return 0; | 
 | 812 | } | 
 | 813 |  | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 814 | static void vt8231_init_device(struct vt8231_data *data) | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 815 | { | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 816 | 	vt8231_write_value(data, VT8231_REG_TEMP1_CONFIG, 0); | 
 | 817 | 	vt8231_write_value(data, VT8231_REG_TEMP2_CONFIG, 0); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 818 | } | 
 | 819 |  | 
 | 820 | static struct vt8231_data *vt8231_update_device(struct device *dev) | 
 | 821 | { | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 822 | 	struct vt8231_data *data = dev_get_drvdata(dev); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 823 | 	int i; | 
 | 824 | 	u16 low; | 
 | 825 |  | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 826 | 	mutex_lock(&data->update_lock); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 827 |  | 
 | 828 | 	if (time_after(jiffies, data->last_updated + HZ + HZ / 2) | 
 | 829 | 	    || !data->valid) { | 
 | 830 | 		for (i = 0; i < 6; i++) { | 
 | 831 | 			if (ISVOLT(i, data->uch_config)) { | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 832 | 				data->in[i] = vt8231_read_value(data, | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 833 | 						regvolt[i]); | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 834 | 				data->in_min[i] = vt8231_read_value(data, | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 835 | 						regvoltmin[i]); | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 836 | 				data->in_max[i] = vt8231_read_value(data, | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 837 | 						regvoltmax[i]); | 
 | 838 | 			} | 
 | 839 | 		} | 
 | 840 | 		for (i = 0; i < 2; i++) { | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 841 | 			data->fan[i] = vt8231_read_value(data, | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 842 | 						VT8231_REG_FAN(i)); | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 843 | 			data->fan_min[i] = vt8231_read_value(data, | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 844 | 						VT8231_REG_FAN_MIN(i)); | 
 | 845 | 		} | 
 | 846 |  | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 847 | 		low = vt8231_read_value(data, VT8231_REG_TEMP_LOW01); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 848 | 		low = (low >> 6) | ((low & 0x30) >> 2) | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 849 | 		    | (vt8231_read_value(data, VT8231_REG_TEMP_LOW25) << 4); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 850 | 		for (i = 0; i < 6; i++) { | 
 | 851 | 			if (ISTEMP(i, data->uch_config)) { | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 852 | 				data->temp[i] = (vt8231_read_value(data, | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 853 | 						       regtemp[i]) << 2) | 
 | 854 | 						| ((low >> (2 * i)) & 0x03); | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 855 | 				data->temp_max[i] = vt8231_read_value(data, | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 856 | 						      regtempmax[i]); | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 857 | 				data->temp_min[i] = vt8231_read_value(data, | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 858 | 						      regtempmin[i]); | 
 | 859 | 			} | 
 | 860 | 		} | 
 | 861 |  | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 862 | 		i = vt8231_read_value(data, VT8231_REG_FANDIV); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 863 | 		data->fan_div[0] = (i >> 4) & 0x03; | 
 | 864 | 		data->fan_div[1] = i >> 6; | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 865 | 		data->alarms = vt8231_read_value(data, VT8231_REG_ALARM1) | | 
 | 866 | 			(vt8231_read_value(data, VT8231_REG_ALARM2) << 8); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 867 |  | 
 | 868 | 		/* Set alarm flags correctly */ | 
 | 869 | 		if (!data->fan[0] && data->fan_min[0]) { | 
 | 870 | 			data->alarms |= 0x40; | 
 | 871 | 		} else if (data->fan[0] && !data->fan_min[0]) { | 
 | 872 | 			data->alarms &= ~0x40; | 
 | 873 | 		} | 
 | 874 |  | 
 | 875 | 		if (!data->fan[1] && data->fan_min[1]) { | 
 | 876 | 			data->alarms |= 0x80; | 
 | 877 | 		} else if (data->fan[1] && !data->fan_min[1]) { | 
 | 878 | 			data->alarms &= ~0x80; | 
 | 879 | 		} | 
 | 880 |  | 
 | 881 | 		data->last_updated = jiffies; | 
 | 882 | 		data->valid = 1; | 
 | 883 | 	} | 
 | 884 |  | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 885 | 	mutex_unlock(&data->update_lock); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 886 |  | 
 | 887 | 	return data; | 
 | 888 | } | 
 | 889 |  | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 890 | static int __devinit vt8231_device_add(unsigned short address) | 
 | 891 | { | 
 | 892 | 	struct resource res = { | 
 | 893 | 		.start	= address, | 
 | 894 | 		.end	= address + VT8231_EXTENT - 1, | 
 | 895 | 		.name	= "vt8231", | 
 | 896 | 		.flags	= IORESOURCE_IO, | 
 | 897 | 	}; | 
 | 898 | 	int err; | 
 | 899 |  | 
| Jean Delvare | b9acb64 | 2009-01-07 16:37:35 +0100 | [diff] [blame] | 900 | 	err = acpi_check_resource_conflict(&res); | 
 | 901 | 	if (err) | 
 | 902 | 		goto exit; | 
 | 903 |  | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 904 | 	pdev = platform_device_alloc("vt8231", address); | 
 | 905 | 	if (!pdev) { | 
 | 906 | 		err = -ENOMEM; | 
| Joe Perches | 9d72be0 | 2010-10-20 06:51:53 +0000 | [diff] [blame] | 907 | 		pr_err("Device allocation failed\n"); | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 908 | 		goto exit; | 
 | 909 | 	} | 
 | 910 |  | 
 | 911 | 	err = platform_device_add_resources(pdev, &res, 1); | 
 | 912 | 	if (err) { | 
| Joe Perches | 9d72be0 | 2010-10-20 06:51:53 +0000 | [diff] [blame] | 913 | 		pr_err("Device resource addition failed (%d)\n", err); | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 914 | 		goto exit_device_put; | 
 | 915 | 	} | 
 | 916 |  | 
 | 917 | 	err = platform_device_add(pdev); | 
 | 918 | 	if (err) { | 
| Joe Perches | 9d72be0 | 2010-10-20 06:51:53 +0000 | [diff] [blame] | 919 | 		pr_err("Device addition failed (%d)\n", err); | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 920 | 		goto exit_device_put; | 
 | 921 | 	} | 
 | 922 |  | 
 | 923 | 	return 0; | 
 | 924 |  | 
 | 925 | exit_device_put: | 
 | 926 | 	platform_device_put(pdev); | 
 | 927 | exit: | 
 | 928 | 	return err; | 
 | 929 | } | 
 | 930 |  | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 931 | static int __devinit vt8231_pci_probe(struct pci_dev *dev, | 
 | 932 | 				const struct pci_device_id *id) | 
 | 933 | { | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 934 | 	u16 address, val; | 
 | 935 | 	if (force_addr) { | 
 | 936 | 		address = force_addr & 0xff00; | 
 | 937 | 		dev_warn(&dev->dev, "Forcing ISA address 0x%x\n", | 
 | 938 | 			 address); | 
 | 939 |  | 
 | 940 | 		if (PCIBIOS_SUCCESSFUL != | 
 | 941 | 		    pci_write_config_word(dev, VT8231_BASE_REG, address | 1)) | 
 | 942 | 			return -ENODEV; | 
 | 943 | 	} | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 944 |  | 
 | 945 | 	if (PCIBIOS_SUCCESSFUL != pci_read_config_word(dev, VT8231_BASE_REG, | 
 | 946 | 							&val)) | 
 | 947 | 		return -ENODEV; | 
 | 948 |  | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 949 | 	address = val & ~(VT8231_EXTENT - 1); | 
 | 950 | 	if (address == 0) { | 
| Joe Perches | 4cae787 | 2010-03-05 13:43:56 -0800 | [diff] [blame] | 951 | 		dev_err(&dev->dev, "base address not set - upgrade BIOS or use force_addr=0xaddr\n"); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 952 | 		return -ENODEV; | 
 | 953 | 	} | 
 | 954 |  | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 955 | 	if (PCIBIOS_SUCCESSFUL != pci_read_config_word(dev, VT8231_ENABLE_REG, | 
 | 956 | 							&val)) | 
 | 957 | 		return -ENODEV; | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 958 |  | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 959 | 	if (!(val & 0x0001)) { | 
 | 960 | 		dev_warn(&dev->dev, "enabling sensors\n"); | 
 | 961 | 		if (PCIBIOS_SUCCESSFUL != | 
 | 962 | 			pci_write_config_word(dev, VT8231_ENABLE_REG, | 
 | 963 | 							val | 0x0001)) | 
 | 964 | 			return -ENODEV; | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 965 | 	} | 
 | 966 |  | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 967 | 	if (platform_driver_register(&vt8231_driver)) | 
 | 968 | 		goto exit; | 
 | 969 |  | 
 | 970 | 	/* Sets global pdev as a side effect */ | 
 | 971 | 	if (vt8231_device_add(address)) | 
 | 972 | 		goto exit_unregister; | 
 | 973 |  | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 974 | 	/* Always return failure here.  This is to allow other drivers to bind | 
 | 975 | 	 * to this pci device.  We don't really want to have control over the | 
 | 976 | 	 * pci device, we only wanted to read as few register values from it. | 
 | 977 | 	 */ | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 978 |  | 
 | 979 | 	/* We do, however, mark ourselves as using the PCI device to stop it | 
 | 980 | 	   getting unloaded. */ | 
 | 981 | 	s_bridge = pci_dev_get(dev); | 
 | 982 | 	return -ENODEV; | 
 | 983 |  | 
 | 984 | exit_unregister: | 
 | 985 | 	platform_driver_unregister(&vt8231_driver); | 
 | 986 | exit: | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 987 | 	return -ENODEV; | 
 | 988 | } | 
 | 989 |  | 
 | 990 | static int __init sm_vt8231_init(void) | 
 | 991 | { | 
| Richard Knutsson | 93b4768 | 2005-11-30 01:00:35 +0100 | [diff] [blame] | 992 | 	return pci_register_driver(&vt8231_pci_driver); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 993 | } | 
 | 994 |  | 
 | 995 | static void __exit sm_vt8231_exit(void) | 
 | 996 | { | 
 | 997 | 	pci_unregister_driver(&vt8231_pci_driver); | 
 | 998 | 	if (s_bridge != NULL) { | 
| Roger Lucas | ec5e1a4 | 2007-06-12 21:04:08 +0200 | [diff] [blame] | 999 | 		platform_device_unregister(pdev); | 
 | 1000 | 		platform_driver_unregister(&vt8231_driver); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 1001 | 		pci_dev_put(s_bridge); | 
 | 1002 | 		s_bridge = NULL; | 
 | 1003 | 	} | 
 | 1004 | } | 
 | 1005 |  | 
| Roger Lucas | af86576 | 2008-02-13 07:52:06 -0500 | [diff] [blame] | 1006 | MODULE_AUTHOR("Roger Lucas <vt8231@hiddenengine.co.uk>"); | 
| Roger Lucas | 1de9e37 | 2005-11-26 20:20:05 +0100 | [diff] [blame] | 1007 | MODULE_DESCRIPTION("VT8231 sensors"); | 
 | 1008 | MODULE_LICENSE("GPL"); | 
 | 1009 |  | 
 | 1010 | module_init(sm_vt8231_init); | 
 | 1011 | module_exit(sm_vt8231_exit); |