| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | asb100.c - Part of lm_sensors, Linux kernel modules for hardware | 
|  | 3 | monitoring | 
|  | 4 |  | 
|  | 5 | Copyright (C) 2004 Mark M. Hoffman <mhoffman@lightlink.com> | 
|  | 6 |  | 
|  | 7 | (derived from w83781d.c) | 
|  | 8 |  | 
|  | 9 | Copyright (C) 1998 - 2003  Frodo Looijaard <frodol@dds.nl>, | 
|  | 10 | Philip Edelbrock <phil@netroedge.com>, and | 
|  | 11 | Mark Studebaker <mdsxyz123@yahoo.com> | 
|  | 12 |  | 
|  | 13 | This program is free software; you can redistribute it and/or modify | 
|  | 14 | it under the terms of the GNU General Public License as published by | 
|  | 15 | the Free Software Foundation; either version 2 of the License, or | 
|  | 16 | (at your option) any later version. | 
|  | 17 |  | 
|  | 18 | This program is distributed in the hope that it will be useful, | 
|  | 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|  | 21 | GNU General Public License for more details. | 
|  | 22 |  | 
|  | 23 | You should have received a copy of the GNU General Public License | 
|  | 24 | along with this program; if not, write to the Free Software | 
|  | 25 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 
|  | 26 | */ | 
|  | 27 |  | 
|  | 28 | /* | 
|  | 29 | This driver supports the hardware sensor chips: Asus ASB100 and | 
|  | 30 | ASB100-A "BACH". | 
|  | 31 |  | 
|  | 32 | ASB100-A supports pwm1, while plain ASB100 does not.  There is no known | 
|  | 33 | way for the driver to tell which one is there. | 
|  | 34 |  | 
|  | 35 | Chip	#vin	#fanin	#pwm	#temp	wchipid	vendid	i2c	ISA | 
|  | 36 | asb100	7	3	1	4	0x31	0x0694	yes	no | 
|  | 37 | */ | 
|  | 38 |  | 
| Joe Perches | 4d630e2 | 2010-10-20 06:51:29 +0000 | [diff] [blame] | 39 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | 
|  | 40 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <linux/module.h> | 
|  | 42 | #include <linux/slab.h> | 
|  | 43 | #include <linux/i2c.h> | 
| Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 44 | #include <linux/hwmon.h> | 
| Jean Delvare | fad33c5 | 2008-01-03 23:21:07 +0100 | [diff] [blame] | 45 | #include <linux/hwmon-sysfs.h> | 
| Jean Delvare | 303760b | 2005-07-31 21:52:01 +0200 | [diff] [blame] | 46 | #include <linux/hwmon-vid.h> | 
| Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 47 | #include <linux/err.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #include <linux/init.h> | 
| Dominik Hackl | ff32409 | 2005-05-16 18:12:18 +0200 | [diff] [blame] | 49 | #include <linux/jiffies.h> | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 50 | #include <linux/mutex.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include "lm75.h" | 
|  | 52 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | /* I2C addresses to scan */ | 
| Mark M. Hoffman | 25e9c86 | 2008-02-17 22:28:03 -0500 | [diff] [blame] | 54 | static const unsigned short normal_i2c[] = { 0x2d, I2C_CLIENT_END }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 |  | 
| Jean Delvare | 3aed198 | 2009-01-07 16:37:32 +0100 | [diff] [blame] | 56 | static unsigned short force_subclients[4]; | 
|  | 57 | module_param_array(force_subclients, short, NULL, 0); | 
|  | 58 | MODULE_PARM_DESC(force_subclients, "List of subclient addresses: " | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | "{bus, clientaddr, subclientaddr1, subclientaddr2}"); | 
|  | 60 |  | 
|  | 61 | /* Voltage IN registers 0-6 */ | 
|  | 62 | #define ASB100_REG_IN(nr)	(0x20 + (nr)) | 
|  | 63 | #define ASB100_REG_IN_MAX(nr)	(0x2b + (nr * 2)) | 
|  | 64 | #define ASB100_REG_IN_MIN(nr)	(0x2c + (nr * 2)) | 
|  | 65 |  | 
|  | 66 | /* FAN IN registers 1-3 */ | 
|  | 67 | #define ASB100_REG_FAN(nr)	(0x28 + (nr)) | 
|  | 68 | #define ASB100_REG_FAN_MIN(nr)	(0x3b + (nr)) | 
|  | 69 |  | 
|  | 70 | /* TEMPERATURE registers 1-4 */ | 
|  | 71 | static const u16 asb100_reg_temp[]	= {0, 0x27, 0x150, 0x250, 0x17}; | 
|  | 72 | static const u16 asb100_reg_temp_max[]	= {0, 0x39, 0x155, 0x255, 0x18}; | 
|  | 73 | static const u16 asb100_reg_temp_hyst[]	= {0, 0x3a, 0x153, 0x253, 0x19}; | 
|  | 74 |  | 
|  | 75 | #define ASB100_REG_TEMP(nr) (asb100_reg_temp[nr]) | 
|  | 76 | #define ASB100_REG_TEMP_MAX(nr) (asb100_reg_temp_max[nr]) | 
|  | 77 | #define ASB100_REG_TEMP_HYST(nr) (asb100_reg_temp_hyst[nr]) | 
|  | 78 |  | 
|  | 79 | #define ASB100_REG_TEMP2_CONFIG	0x0152 | 
|  | 80 | #define ASB100_REG_TEMP3_CONFIG	0x0252 | 
|  | 81 |  | 
|  | 82 |  | 
|  | 83 | #define ASB100_REG_CONFIG	0x40 | 
|  | 84 | #define ASB100_REG_ALARM1	0x41 | 
|  | 85 | #define ASB100_REG_ALARM2	0x42 | 
|  | 86 | #define ASB100_REG_SMIM1	0x43 | 
|  | 87 | #define ASB100_REG_SMIM2	0x44 | 
|  | 88 | #define ASB100_REG_VID_FANDIV	0x47 | 
|  | 89 | #define ASB100_REG_I2C_ADDR	0x48 | 
|  | 90 | #define ASB100_REG_CHIPID	0x49 | 
|  | 91 | #define ASB100_REG_I2C_SUBADDR	0x4a | 
|  | 92 | #define ASB100_REG_PIN		0x4b | 
|  | 93 | #define ASB100_REG_IRQ		0x4c | 
|  | 94 | #define ASB100_REG_BANK		0x4e | 
|  | 95 | #define ASB100_REG_CHIPMAN	0x4f | 
|  | 96 |  | 
|  | 97 | #define ASB100_REG_WCHIPID	0x58 | 
|  | 98 |  | 
|  | 99 | /* bit 7 -> enable, bits 0-3 -> duty cycle */ | 
|  | 100 | #define ASB100_REG_PWM1		0x59 | 
|  | 101 |  | 
|  | 102 | /* CONVERSIONS | 
|  | 103 | Rounding and limit checking is only done on the TO_REG variants. */ | 
|  | 104 |  | 
|  | 105 | /* These constants are a guess, consistent w/ w83781d */ | 
|  | 106 | #define ASB100_IN_MIN (   0) | 
|  | 107 | #define ASB100_IN_MAX (4080) | 
|  | 108 |  | 
|  | 109 | /* IN: 1/1000 V (0V to 4.08V) | 
|  | 110 | REG: 16mV/bit */ | 
|  | 111 | static u8 IN_TO_REG(unsigned val) | 
|  | 112 | { | 
|  | 113 | unsigned nval = SENSORS_LIMIT(val, ASB100_IN_MIN, ASB100_IN_MAX); | 
|  | 114 | return (nval + 8) / 16; | 
|  | 115 | } | 
|  | 116 |  | 
|  | 117 | static unsigned IN_FROM_REG(u8 reg) | 
|  | 118 | { | 
|  | 119 | return reg * 16; | 
|  | 120 | } | 
|  | 121 |  | 
|  | 122 | static u8 FAN_TO_REG(long rpm, int div) | 
|  | 123 | { | 
|  | 124 | if (rpm == -1) | 
|  | 125 | return 0; | 
|  | 126 | if (rpm == 0) | 
|  | 127 | return 255; | 
|  | 128 | rpm = SENSORS_LIMIT(rpm, 1, 1000000); | 
|  | 129 | return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254); | 
|  | 130 | } | 
|  | 131 |  | 
|  | 132 | static int FAN_FROM_REG(u8 val, int div) | 
|  | 133 | { | 
|  | 134 | return val==0 ? -1 : val==255 ? 0 : 1350000/(val*div); | 
|  | 135 | } | 
|  | 136 |  | 
|  | 137 | /* These constants are a guess, consistent w/ w83781d */ | 
|  | 138 | #define ASB100_TEMP_MIN (-128000) | 
|  | 139 | #define ASB100_TEMP_MAX ( 127000) | 
|  | 140 |  | 
|  | 141 | /* TEMP: 0.001C/bit (-128C to +127C) | 
|  | 142 | REG: 1C/bit, two's complement */ | 
| Christian Hohnstaedt | 5bfedac | 2007-08-16 11:40:10 +0200 | [diff] [blame] | 143 | static u8 TEMP_TO_REG(long temp) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | { | 
|  | 145 | int ntemp = SENSORS_LIMIT(temp, ASB100_TEMP_MIN, ASB100_TEMP_MAX); | 
|  | 146 | ntemp += (ntemp<0 ? -500 : 500); | 
|  | 147 | return (u8)(ntemp / 1000); | 
|  | 148 | } | 
|  | 149 |  | 
|  | 150 | static int TEMP_FROM_REG(u8 reg) | 
|  | 151 | { | 
|  | 152 | return (s8)reg * 1000; | 
|  | 153 | } | 
|  | 154 |  | 
|  | 155 | /* PWM: 0 - 255 per sensors documentation | 
|  | 156 | REG: (6.25% duty cycle per bit) */ | 
|  | 157 | static u8 ASB100_PWM_TO_REG(int pwm) | 
|  | 158 | { | 
|  | 159 | pwm = SENSORS_LIMIT(pwm, 0, 255); | 
|  | 160 | return (u8)(pwm / 16); | 
|  | 161 | } | 
|  | 162 |  | 
|  | 163 | static int ASB100_PWM_FROM_REG(u8 reg) | 
|  | 164 | { | 
|  | 165 | return reg * 16; | 
|  | 166 | } | 
|  | 167 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | #define DIV_FROM_REG(val) (1 << (val)) | 
|  | 169 |  | 
|  | 170 | /* FAN DIV: 1, 2, 4, or 8 (defaults to 2) | 
|  | 171 | REG: 0, 1, 2, or 3 (respectively) (defaults to 1) */ | 
|  | 172 | static u8 DIV_TO_REG(long val) | 
|  | 173 | { | 
|  | 174 | return val==8 ? 3 : val==4 ? 2 : val==1 ? 0 : 1; | 
|  | 175 | } | 
|  | 176 |  | 
|  | 177 | /* For each registered client, we need to keep some data in memory. That | 
|  | 178 | data is pointed to by client->data. The structure itself is | 
|  | 179 | dynamically allocated, at the same time the client itself is allocated. */ | 
|  | 180 | struct asb100_data { | 
| Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 181 | struct device *hwmon_dev; | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 182 | struct mutex lock; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 |  | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 184 | struct mutex update_lock; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | unsigned long last_updated;	/* In jiffies */ | 
|  | 186 |  | 
|  | 187 | /* array of 2 pointers to subclients */ | 
|  | 188 | struct i2c_client *lm75[2]; | 
|  | 189 |  | 
|  | 190 | char valid;		/* !=0 if following fields are valid */ | 
|  | 191 | u8 in[7];		/* Register value */ | 
|  | 192 | u8 in_max[7];		/* Register value */ | 
|  | 193 | u8 in_min[7];		/* Register value */ | 
|  | 194 | u8 fan[3];		/* Register value */ | 
|  | 195 | u8 fan_min[3];		/* Register value */ | 
|  | 196 | u16 temp[4];		/* Register value (0 and 3 are u8 only) */ | 
|  | 197 | u16 temp_max[4];	/* Register value (0 and 3 are u8 only) */ | 
|  | 198 | u16 temp_hyst[4];	/* Register value (0 and 3 are u8 only) */ | 
|  | 199 | u8 fan_div[3];		/* Register encoding, right justified */ | 
|  | 200 | u8 pwm;			/* Register encoding */ | 
|  | 201 | u8 vid;			/* Register encoding, combined */ | 
|  | 202 | u32 alarms;		/* Register encoding, combined */ | 
|  | 203 | u8 vrm; | 
|  | 204 | }; | 
|  | 205 |  | 
|  | 206 | static int asb100_read_value(struct i2c_client *client, u16 reg); | 
|  | 207 | static void asb100_write_value(struct i2c_client *client, u16 reg, u16 val); | 
|  | 208 |  | 
| Jean Delvare | 063675b | 2008-07-16 19:30:11 +0200 | [diff] [blame] | 209 | static int asb100_probe(struct i2c_client *client, | 
|  | 210 | const struct i2c_device_id *id); | 
| Jean Delvare | 310ec79 | 2009-12-14 21:17:23 +0100 | [diff] [blame] | 211 | static int asb100_detect(struct i2c_client *client, | 
| Jean Delvare | 063675b | 2008-07-16 19:30:11 +0200 | [diff] [blame] | 212 | struct i2c_board_info *info); | 
|  | 213 | static int asb100_remove(struct i2c_client *client); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | static struct asb100_data *asb100_update_device(struct device *dev); | 
|  | 215 | static void asb100_init_client(struct i2c_client *client); | 
|  | 216 |  | 
| Jean Delvare | 063675b | 2008-07-16 19:30:11 +0200 | [diff] [blame] | 217 | static const struct i2c_device_id asb100_id[] = { | 
| Jean Delvare | 1f86df4 | 2009-12-14 21:17:26 +0100 | [diff] [blame] | 218 | { "asb100", 0 }, | 
| Jean Delvare | 063675b | 2008-07-16 19:30:11 +0200 | [diff] [blame] | 219 | { } | 
|  | 220 | }; | 
|  | 221 | MODULE_DEVICE_TABLE(i2c, asb100_id); | 
|  | 222 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | static struct i2c_driver asb100_driver = { | 
| Jean Delvare | 063675b | 2008-07-16 19:30:11 +0200 | [diff] [blame] | 224 | .class		= I2C_CLASS_HWMON, | 
| Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 225 | .driver = { | 
| Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 226 | .name	= "asb100", | 
|  | 227 | }, | 
| Jean Delvare | 063675b | 2008-07-16 19:30:11 +0200 | [diff] [blame] | 228 | .probe		= asb100_probe, | 
|  | 229 | .remove		= asb100_remove, | 
|  | 230 | .id_table	= asb100_id, | 
|  | 231 | .detect		= asb100_detect, | 
| Jean Delvare | c3813d6 | 2009-12-14 21:17:25 +0100 | [diff] [blame] | 232 | .address_list	= normal_i2c, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | }; | 
|  | 234 |  | 
|  | 235 | /* 7 Voltages */ | 
|  | 236 | #define show_in_reg(reg) \ | 
| Jean Delvare | fad33c5 | 2008-01-03 23:21:07 +0100 | [diff] [blame] | 237 | static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \ | 
|  | 238 | char *buf) \ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | { \ | 
| Jean Delvare | fad33c5 | 2008-01-03 23:21:07 +0100 | [diff] [blame] | 240 | int nr = to_sensor_dev_attr(attr)->index; \ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | struct asb100_data *data = asb100_update_device(dev); \ | 
|  | 242 | return sprintf(buf, "%d\n", IN_FROM_REG(data->reg[nr])); \ | 
|  | 243 | } | 
|  | 244 |  | 
|  | 245 | show_in_reg(in) | 
|  | 246 | show_in_reg(in_min) | 
|  | 247 | show_in_reg(in_max) | 
|  | 248 |  | 
|  | 249 | #define set_in_reg(REG, reg) \ | 
| Jean Delvare | fad33c5 | 2008-01-03 23:21:07 +0100 | [diff] [blame] | 250 | static ssize_t set_in_##reg(struct device *dev, struct device_attribute *attr, \ | 
|  | 251 | const char *buf, size_t count) \ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | { \ | 
| Jean Delvare | fad33c5 | 2008-01-03 23:21:07 +0100 | [diff] [blame] | 253 | int nr = to_sensor_dev_attr(attr)->index; \ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | struct i2c_client *client = to_i2c_client(dev); \ | 
|  | 255 | struct asb100_data *data = i2c_get_clientdata(client); \ | 
|  | 256 | unsigned long val = simple_strtoul(buf, NULL, 10); \ | 
|  | 257 | \ | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 258 | mutex_lock(&data->update_lock); \ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | data->in_##reg[nr] = IN_TO_REG(val); \ | 
|  | 260 | asb100_write_value(client, ASB100_REG_IN_##REG(nr), \ | 
|  | 261 | data->in_##reg[nr]); \ | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 262 | mutex_unlock(&data->update_lock); \ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | return count; \ | 
|  | 264 | } | 
|  | 265 |  | 
|  | 266 | set_in_reg(MIN, min) | 
|  | 267 | set_in_reg(MAX, max) | 
|  | 268 |  | 
|  | 269 | #define sysfs_in(offset) \ | 
| Jean Delvare | fad33c5 | 2008-01-03 23:21:07 +0100 | [diff] [blame] | 270 | static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \ | 
|  | 271 | show_in, NULL, offset); \ | 
|  | 272 | static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ | 
|  | 273 | show_in_min, set_in_min, offset); \ | 
|  | 274 | static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ | 
|  | 275 | show_in_max, set_in_max, offset) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 |  | 
|  | 277 | sysfs_in(0); | 
|  | 278 | sysfs_in(1); | 
|  | 279 | sysfs_in(2); | 
|  | 280 | sysfs_in(3); | 
|  | 281 | sysfs_in(4); | 
|  | 282 | sysfs_in(5); | 
|  | 283 | sysfs_in(6); | 
|  | 284 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | /* 3 Fans */ | 
| Jean Delvare | fad33c5 | 2008-01-03 23:21:07 +0100 | [diff] [blame] | 286 | static ssize_t show_fan(struct device *dev, struct device_attribute *attr, | 
|  | 287 | char *buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | { | 
| Jean Delvare | fad33c5 | 2008-01-03 23:21:07 +0100 | [diff] [blame] | 289 | int nr = to_sensor_dev_attr(attr)->index; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | struct asb100_data *data = asb100_update_device(dev); | 
|  | 291 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], | 
|  | 292 | DIV_FROM_REG(data->fan_div[nr]))); | 
|  | 293 | } | 
|  | 294 |  | 
| Jean Delvare | fad33c5 | 2008-01-03 23:21:07 +0100 | [diff] [blame] | 295 | static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr, | 
|  | 296 | char *buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | { | 
| Jean Delvare | fad33c5 | 2008-01-03 23:21:07 +0100 | [diff] [blame] | 298 | int nr = to_sensor_dev_attr(attr)->index; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | struct asb100_data *data = asb100_update_device(dev); | 
|  | 300 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr], | 
|  | 301 | DIV_FROM_REG(data->fan_div[nr]))); | 
|  | 302 | } | 
|  | 303 |  | 
| Jean Delvare | fad33c5 | 2008-01-03 23:21:07 +0100 | [diff] [blame] | 304 | static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr, | 
|  | 305 | char *buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | { | 
| Jean Delvare | fad33c5 | 2008-01-03 23:21:07 +0100 | [diff] [blame] | 307 | int nr = to_sensor_dev_attr(attr)->index; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | struct asb100_data *data = asb100_update_device(dev); | 
|  | 309 | return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr])); | 
|  | 310 | } | 
|  | 311 |  | 
| Jean Delvare | fad33c5 | 2008-01-03 23:21:07 +0100 | [diff] [blame] | 312 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, | 
|  | 313 | const char *buf, size_t count) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | { | 
| Jean Delvare | fad33c5 | 2008-01-03 23:21:07 +0100 | [diff] [blame] | 315 | int nr = to_sensor_dev_attr(attr)->index; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | struct i2c_client *client = to_i2c_client(dev); | 
|  | 317 | struct asb100_data *data = i2c_get_clientdata(client); | 
|  | 318 | u32 val = simple_strtoul(buf, NULL, 10); | 
|  | 319 |  | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 320 | mutex_lock(&data->update_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); | 
|  | 322 | asb100_write_value(client, ASB100_REG_FAN_MIN(nr), data->fan_min[nr]); | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 323 | mutex_unlock(&data->update_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | return count; | 
|  | 325 | } | 
|  | 326 |  | 
|  | 327 | /* Note: we save and restore the fan minimum here, because its value is | 
|  | 328 | determined in part by the fan divisor.  This follows the principle of | 
| Andreas Mohr | d6e05ed | 2006-06-26 18:35:02 +0200 | [diff] [blame] | 329 | least surprise; the user doesn't expect the fan minimum to change just | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | because the divisor changed. */ | 
| Jean Delvare | fad33c5 | 2008-01-03 23:21:07 +0100 | [diff] [blame] | 331 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, | 
|  | 332 | const char *buf, size_t count) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | { | 
| Jean Delvare | fad33c5 | 2008-01-03 23:21:07 +0100 | [diff] [blame] | 334 | int nr = to_sensor_dev_attr(attr)->index; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | struct i2c_client *client = to_i2c_client(dev); | 
|  | 336 | struct asb100_data *data = i2c_get_clientdata(client); | 
|  | 337 | unsigned long min; | 
|  | 338 | unsigned long val = simple_strtoul(buf, NULL, 10); | 
|  | 339 | int reg; | 
| Jean Delvare | af22193 | 2008-01-03 23:15:49 +0100 | [diff] [blame] | 340 |  | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 341 | mutex_lock(&data->update_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 |  | 
|  | 343 | min = FAN_FROM_REG(data->fan_min[nr], | 
|  | 344 | DIV_FROM_REG(data->fan_div[nr])); | 
|  | 345 | data->fan_div[nr] = DIV_TO_REG(val); | 
|  | 346 |  | 
| Jean Delvare | af22193 | 2008-01-03 23:15:49 +0100 | [diff] [blame] | 347 | switch (nr) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | case 0:	/* fan 1 */ | 
|  | 349 | reg = asb100_read_value(client, ASB100_REG_VID_FANDIV); | 
|  | 350 | reg = (reg & 0xcf) | (data->fan_div[0] << 4); | 
|  | 351 | asb100_write_value(client, ASB100_REG_VID_FANDIV, reg); | 
|  | 352 | break; | 
|  | 353 |  | 
|  | 354 | case 1:	/* fan 2 */ | 
|  | 355 | reg = asb100_read_value(client, ASB100_REG_VID_FANDIV); | 
|  | 356 | reg = (reg & 0x3f) | (data->fan_div[1] << 6); | 
|  | 357 | asb100_write_value(client, ASB100_REG_VID_FANDIV, reg); | 
|  | 358 | break; | 
|  | 359 |  | 
|  | 360 | case 2:	/* fan 3 */ | 
|  | 361 | reg = asb100_read_value(client, ASB100_REG_PIN); | 
|  | 362 | reg = (reg & 0x3f) | (data->fan_div[2] << 6); | 
|  | 363 | asb100_write_value(client, ASB100_REG_PIN, reg); | 
|  | 364 | break; | 
|  | 365 | } | 
|  | 366 |  | 
|  | 367 | data->fan_min[nr] = | 
|  | 368 | FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); | 
|  | 369 | asb100_write_value(client, ASB100_REG_FAN_MIN(nr), data->fan_min[nr]); | 
|  | 370 |  | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 371 | mutex_unlock(&data->update_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 |  | 
|  | 373 | return count; | 
|  | 374 | } | 
|  | 375 |  | 
|  | 376 | #define sysfs_fan(offset) \ | 
| Jean Delvare | fad33c5 | 2008-01-03 23:21:07 +0100 | [diff] [blame] | 377 | static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ | 
|  | 378 | show_fan, NULL, offset - 1); \ | 
|  | 379 | static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ | 
|  | 380 | show_fan_min, set_fan_min, offset - 1); \ | 
|  | 381 | static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \ | 
|  | 382 | show_fan_div, set_fan_div, offset - 1) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 |  | 
|  | 384 | sysfs_fan(1); | 
|  | 385 | sysfs_fan(2); | 
|  | 386 | sysfs_fan(3); | 
|  | 387 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | /* 4 Temp. Sensors */ | 
|  | 389 | static int sprintf_temp_from_reg(u16 reg, char *buf, int nr) | 
|  | 390 | { | 
|  | 391 | int ret = 0; | 
|  | 392 |  | 
|  | 393 | switch (nr) { | 
|  | 394 | case 1: case 2: | 
|  | 395 | ret = sprintf(buf, "%d\n", LM75_TEMP_FROM_REG(reg)); | 
|  | 396 | break; | 
|  | 397 | case 0: case 3: default: | 
|  | 398 | ret = sprintf(buf, "%d\n", TEMP_FROM_REG(reg)); | 
|  | 399 | break; | 
|  | 400 | } | 
|  | 401 | return ret; | 
|  | 402 | } | 
| Jean Delvare | af22193 | 2008-01-03 23:15:49 +0100 | [diff] [blame] | 403 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | #define show_temp_reg(reg) \ | 
| Jean Delvare | fad33c5 | 2008-01-03 23:21:07 +0100 | [diff] [blame] | 405 | static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \ | 
|  | 406 | char *buf) \ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | { \ | 
| Jean Delvare | fad33c5 | 2008-01-03 23:21:07 +0100 | [diff] [blame] | 408 | int nr = to_sensor_dev_attr(attr)->index; \ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | struct asb100_data *data = asb100_update_device(dev); \ | 
|  | 410 | return sprintf_temp_from_reg(data->reg[nr], buf, nr); \ | 
|  | 411 | } | 
|  | 412 |  | 
|  | 413 | show_temp_reg(temp); | 
|  | 414 | show_temp_reg(temp_max); | 
|  | 415 | show_temp_reg(temp_hyst); | 
|  | 416 |  | 
|  | 417 | #define set_temp_reg(REG, reg) \ | 
| Jean Delvare | fad33c5 | 2008-01-03 23:21:07 +0100 | [diff] [blame] | 418 | static ssize_t set_##reg(struct device *dev, struct device_attribute *attr, \ | 
|  | 419 | const char *buf, size_t count) \ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | { \ | 
| Jean Delvare | fad33c5 | 2008-01-03 23:21:07 +0100 | [diff] [blame] | 421 | int nr = to_sensor_dev_attr(attr)->index; \ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | struct i2c_client *client = to_i2c_client(dev); \ | 
|  | 423 | struct asb100_data *data = i2c_get_clientdata(client); \ | 
| Christian Hohnstaedt | 5bfedac | 2007-08-16 11:40:10 +0200 | [diff] [blame] | 424 | long val = simple_strtol(buf, NULL, 10); \ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | \ | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 426 | mutex_lock(&data->update_lock); \ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | switch (nr) { \ | 
|  | 428 | case 1: case 2: \ | 
|  | 429 | data->reg[nr] = LM75_TEMP_TO_REG(val); \ | 
|  | 430 | break; \ | 
|  | 431 | case 0: case 3: default: \ | 
|  | 432 | data->reg[nr] = TEMP_TO_REG(val); \ | 
|  | 433 | break; \ | 
|  | 434 | } \ | 
|  | 435 | asb100_write_value(client, ASB100_REG_TEMP_##REG(nr+1), \ | 
|  | 436 | data->reg[nr]); \ | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 437 | mutex_unlock(&data->update_lock); \ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | return count; \ | 
|  | 439 | } | 
|  | 440 |  | 
|  | 441 | set_temp_reg(MAX, temp_max); | 
|  | 442 | set_temp_reg(HYST, temp_hyst); | 
|  | 443 |  | 
|  | 444 | #define sysfs_temp(num) \ | 
| Jean Delvare | fad33c5 | 2008-01-03 23:21:07 +0100 | [diff] [blame] | 445 | static SENSOR_DEVICE_ATTR(temp##num##_input, S_IRUGO, \ | 
|  | 446 | show_temp, NULL, num - 1); \ | 
|  | 447 | static SENSOR_DEVICE_ATTR(temp##num##_max, S_IRUGO | S_IWUSR, \ | 
|  | 448 | show_temp_max, set_temp_max, num - 1); \ | 
|  | 449 | static SENSOR_DEVICE_ATTR(temp##num##_max_hyst, S_IRUGO | S_IWUSR, \ | 
|  | 450 | show_temp_hyst, set_temp_hyst, num - 1) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 |  | 
|  | 452 | sysfs_temp(1); | 
|  | 453 | sysfs_temp(2); | 
|  | 454 | sysfs_temp(3); | 
|  | 455 | sysfs_temp(4); | 
|  | 456 |  | 
|  | 457 | /* VID */ | 
| Jean Delvare | af22193 | 2008-01-03 23:15:49 +0100 | [diff] [blame] | 458 | static ssize_t show_vid(struct device *dev, struct device_attribute *attr, | 
|  | 459 | char *buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | { | 
|  | 461 | struct asb100_data *data = asb100_update_device(dev); | 
|  | 462 | return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm)); | 
|  | 463 | } | 
|  | 464 |  | 
|  | 465 | static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 |  | 
|  | 467 | /* VRM */ | 
| Jean Delvare | af22193 | 2008-01-03 23:15:49 +0100 | [diff] [blame] | 468 | static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, | 
|  | 469 | char *buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | { | 
| Jean Delvare | 90d6619 | 2007-10-08 18:24:35 +0200 | [diff] [blame] | 471 | struct asb100_data *data = dev_get_drvdata(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | return sprintf(buf, "%d\n", data->vrm); | 
|  | 473 | } | 
|  | 474 |  | 
| Jean Delvare | af22193 | 2008-01-03 23:15:49 +0100 | [diff] [blame] | 475 | static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, | 
|  | 476 | const char *buf, size_t count) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | { | 
| Jean Delvare | 8f74efe | 2007-12-01 11:25:33 +0100 | [diff] [blame] | 478 | struct asb100_data *data = dev_get_drvdata(dev); | 
|  | 479 | data->vrm = simple_strtoul(buf, NULL, 10); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | return count; | 
|  | 481 | } | 
|  | 482 |  | 
|  | 483 | /* Alarms */ | 
|  | 484 | static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 |  | 
| Jean Delvare | af22193 | 2008-01-03 23:15:49 +0100 | [diff] [blame] | 486 | static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, | 
|  | 487 | char *buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | { | 
|  | 489 | struct asb100_data *data = asb100_update_device(dev); | 
| Jean Delvare | 68188ba | 2005-05-16 18:52:38 +0200 | [diff] [blame] | 490 | return sprintf(buf, "%u\n", data->alarms); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | } | 
|  | 492 |  | 
|  | 493 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 |  | 
| Jean Delvare | 636866b | 2008-01-03 23:24:24 +0100 | [diff] [blame] | 495 | static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, | 
|  | 496 | char *buf) | 
|  | 497 | { | 
|  | 498 | int bitnr = to_sensor_dev_attr(attr)->index; | 
|  | 499 | struct asb100_data *data = asb100_update_device(dev); | 
|  | 500 | return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); | 
|  | 501 | } | 
|  | 502 | static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0); | 
|  | 503 | static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1); | 
|  | 504 | static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2); | 
|  | 505 | static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3); | 
|  | 506 | static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8); | 
|  | 507 | static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6); | 
|  | 508 | static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7); | 
|  | 509 | static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 11); | 
|  | 510 | static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4); | 
|  | 511 | static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5); | 
|  | 512 | static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13); | 
|  | 513 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | /* 1 PWM */ | 
| Jean Delvare | af22193 | 2008-01-03 23:15:49 +0100 | [diff] [blame] | 515 | static ssize_t show_pwm1(struct device *dev, struct device_attribute *attr, | 
|  | 516 | char *buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | { | 
|  | 518 | struct asb100_data *data = asb100_update_device(dev); | 
|  | 519 | return sprintf(buf, "%d\n", ASB100_PWM_FROM_REG(data->pwm & 0x0f)); | 
|  | 520 | } | 
|  | 521 |  | 
| Jean Delvare | af22193 | 2008-01-03 23:15:49 +0100 | [diff] [blame] | 522 | static ssize_t set_pwm1(struct device *dev, struct device_attribute *attr, | 
|  | 523 | const char *buf, size_t count) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | { | 
|  | 525 | struct i2c_client *client = to_i2c_client(dev); | 
|  | 526 | struct asb100_data *data = i2c_get_clientdata(client); | 
|  | 527 | unsigned long val = simple_strtoul(buf, NULL, 10); | 
|  | 528 |  | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 529 | mutex_lock(&data->update_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | data->pwm &= 0x80; /* keep the enable bit */ | 
|  | 531 | data->pwm |= (0x0f & ASB100_PWM_TO_REG(val)); | 
|  | 532 | asb100_write_value(client, ASB100_REG_PWM1, data->pwm); | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 533 | mutex_unlock(&data->update_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | return count; | 
|  | 535 | } | 
|  | 536 |  | 
| Jean Delvare | af22193 | 2008-01-03 23:15:49 +0100 | [diff] [blame] | 537 | static ssize_t show_pwm_enable1(struct device *dev, | 
|  | 538 | struct device_attribute *attr, char *buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | { | 
|  | 540 | struct asb100_data *data = asb100_update_device(dev); | 
|  | 541 | return sprintf(buf, "%d\n", (data->pwm & 0x80) ? 1 : 0); | 
|  | 542 | } | 
|  | 543 |  | 
| Jean Delvare | af22193 | 2008-01-03 23:15:49 +0100 | [diff] [blame] | 544 | static ssize_t set_pwm_enable1(struct device *dev, | 
|  | 545 | struct device_attribute *attr, const char *buf, size_t count) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | { | 
|  | 547 | struct i2c_client *client = to_i2c_client(dev); | 
|  | 548 | struct asb100_data *data = i2c_get_clientdata(client); | 
|  | 549 | unsigned long val = simple_strtoul(buf, NULL, 10); | 
|  | 550 |  | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 551 | mutex_lock(&data->update_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | data->pwm &= 0x0f; /* keep the duty cycle bits */ | 
|  | 553 | data->pwm |= (val ? 0x80 : 0x00); | 
|  | 554 | asb100_write_value(client, ASB100_REG_PWM1, data->pwm); | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 555 | mutex_unlock(&data->update_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | return count; | 
|  | 557 | } | 
|  | 558 |  | 
|  | 559 | static DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm1, set_pwm1); | 
|  | 560 | static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, | 
|  | 561 | show_pwm_enable1, set_pwm_enable1); | 
| Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 562 |  | 
|  | 563 | static struct attribute *asb100_attributes[] = { | 
| Jean Delvare | fad33c5 | 2008-01-03 23:21:07 +0100 | [diff] [blame] | 564 | &sensor_dev_attr_in0_input.dev_attr.attr, | 
|  | 565 | &sensor_dev_attr_in0_min.dev_attr.attr, | 
|  | 566 | &sensor_dev_attr_in0_max.dev_attr.attr, | 
|  | 567 | &sensor_dev_attr_in1_input.dev_attr.attr, | 
|  | 568 | &sensor_dev_attr_in1_min.dev_attr.attr, | 
|  | 569 | &sensor_dev_attr_in1_max.dev_attr.attr, | 
|  | 570 | &sensor_dev_attr_in2_input.dev_attr.attr, | 
|  | 571 | &sensor_dev_attr_in2_min.dev_attr.attr, | 
|  | 572 | &sensor_dev_attr_in2_max.dev_attr.attr, | 
|  | 573 | &sensor_dev_attr_in3_input.dev_attr.attr, | 
|  | 574 | &sensor_dev_attr_in3_min.dev_attr.attr, | 
|  | 575 | &sensor_dev_attr_in3_max.dev_attr.attr, | 
|  | 576 | &sensor_dev_attr_in4_input.dev_attr.attr, | 
|  | 577 | &sensor_dev_attr_in4_min.dev_attr.attr, | 
|  | 578 | &sensor_dev_attr_in4_max.dev_attr.attr, | 
|  | 579 | &sensor_dev_attr_in5_input.dev_attr.attr, | 
|  | 580 | &sensor_dev_attr_in5_min.dev_attr.attr, | 
|  | 581 | &sensor_dev_attr_in5_max.dev_attr.attr, | 
|  | 582 | &sensor_dev_attr_in6_input.dev_attr.attr, | 
|  | 583 | &sensor_dev_attr_in6_min.dev_attr.attr, | 
|  | 584 | &sensor_dev_attr_in6_max.dev_attr.attr, | 
| Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 585 |  | 
| Jean Delvare | fad33c5 | 2008-01-03 23:21:07 +0100 | [diff] [blame] | 586 | &sensor_dev_attr_fan1_input.dev_attr.attr, | 
|  | 587 | &sensor_dev_attr_fan1_min.dev_attr.attr, | 
|  | 588 | &sensor_dev_attr_fan1_div.dev_attr.attr, | 
|  | 589 | &sensor_dev_attr_fan2_input.dev_attr.attr, | 
|  | 590 | &sensor_dev_attr_fan2_min.dev_attr.attr, | 
|  | 591 | &sensor_dev_attr_fan2_div.dev_attr.attr, | 
|  | 592 | &sensor_dev_attr_fan3_input.dev_attr.attr, | 
|  | 593 | &sensor_dev_attr_fan3_min.dev_attr.attr, | 
|  | 594 | &sensor_dev_attr_fan3_div.dev_attr.attr, | 
| Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 595 |  | 
| Jean Delvare | fad33c5 | 2008-01-03 23:21:07 +0100 | [diff] [blame] | 596 | &sensor_dev_attr_temp1_input.dev_attr.attr, | 
|  | 597 | &sensor_dev_attr_temp1_max.dev_attr.attr, | 
|  | 598 | &sensor_dev_attr_temp1_max_hyst.dev_attr.attr, | 
|  | 599 | &sensor_dev_attr_temp2_input.dev_attr.attr, | 
|  | 600 | &sensor_dev_attr_temp2_max.dev_attr.attr, | 
|  | 601 | &sensor_dev_attr_temp2_max_hyst.dev_attr.attr, | 
|  | 602 | &sensor_dev_attr_temp3_input.dev_attr.attr, | 
|  | 603 | &sensor_dev_attr_temp3_max.dev_attr.attr, | 
|  | 604 | &sensor_dev_attr_temp3_max_hyst.dev_attr.attr, | 
|  | 605 | &sensor_dev_attr_temp4_input.dev_attr.attr, | 
|  | 606 | &sensor_dev_attr_temp4_max.dev_attr.attr, | 
|  | 607 | &sensor_dev_attr_temp4_max_hyst.dev_attr.attr, | 
| Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 608 |  | 
| Jean Delvare | 636866b | 2008-01-03 23:24:24 +0100 | [diff] [blame] | 609 | &sensor_dev_attr_in0_alarm.dev_attr.attr, | 
|  | 610 | &sensor_dev_attr_in1_alarm.dev_attr.attr, | 
|  | 611 | &sensor_dev_attr_in2_alarm.dev_attr.attr, | 
|  | 612 | &sensor_dev_attr_in3_alarm.dev_attr.attr, | 
|  | 613 | &sensor_dev_attr_in4_alarm.dev_attr.attr, | 
|  | 614 | &sensor_dev_attr_fan1_alarm.dev_attr.attr, | 
|  | 615 | &sensor_dev_attr_fan2_alarm.dev_attr.attr, | 
|  | 616 | &sensor_dev_attr_fan3_alarm.dev_attr.attr, | 
|  | 617 | &sensor_dev_attr_temp1_alarm.dev_attr.attr, | 
|  | 618 | &sensor_dev_attr_temp2_alarm.dev_attr.attr, | 
|  | 619 | &sensor_dev_attr_temp3_alarm.dev_attr.attr, | 
|  | 620 |  | 
| Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 621 | &dev_attr_cpu0_vid.attr, | 
|  | 622 | &dev_attr_vrm.attr, | 
|  | 623 | &dev_attr_alarms.attr, | 
|  | 624 | &dev_attr_pwm1.attr, | 
|  | 625 | &dev_attr_pwm1_enable.attr, | 
|  | 626 |  | 
|  | 627 | NULL | 
|  | 628 | }; | 
|  | 629 |  | 
|  | 630 | static const struct attribute_group asb100_group = { | 
|  | 631 | .attrs = asb100_attributes, | 
|  | 632 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 |  | 
| Jean Delvare | 063675b | 2008-07-16 19:30:11 +0200 | [diff] [blame] | 634 | static int asb100_detect_subclients(struct i2c_client *client) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | { | 
|  | 636 | int i, id, err; | 
| Jean Delvare | 063675b | 2008-07-16 19:30:11 +0200 | [diff] [blame] | 637 | int address = client->addr; | 
|  | 638 | unsigned short sc_addr[2]; | 
| Jean Delvare | af22193 | 2008-01-03 23:15:49 +0100 | [diff] [blame] | 639 | struct asb100_data *data = i2c_get_clientdata(client); | 
| Jean Delvare | 063675b | 2008-07-16 19:30:11 +0200 | [diff] [blame] | 640 | struct i2c_adapter *adapter = client->adapter; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 |  | 
|  | 642 | id = i2c_adapter_id(adapter); | 
|  | 643 |  | 
|  | 644 | if (force_subclients[0] == id && force_subclients[1] == address) { | 
|  | 645 | for (i = 2; i <= 3; i++) { | 
|  | 646 | if (force_subclients[i] < 0x48 || | 
|  | 647 | force_subclients[i] > 0x4f) { | 
| Jean Delvare | af22193 | 2008-01-03 23:15:49 +0100 | [diff] [blame] | 648 | dev_err(&client->dev, "invalid subclient " | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | "address %d; must be 0x48-0x4f\n", | 
|  | 650 | force_subclients[i]); | 
|  | 651 | err = -ENODEV; | 
|  | 652 | goto ERROR_SC_2; | 
|  | 653 | } | 
|  | 654 | } | 
| Jean Delvare | af22193 | 2008-01-03 23:15:49 +0100 | [diff] [blame] | 655 | asb100_write_value(client, ASB100_REG_I2C_SUBADDR, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | (force_subclients[2] & 0x07) | | 
| Jean Delvare | af22193 | 2008-01-03 23:15:49 +0100 | [diff] [blame] | 657 | ((force_subclients[3] & 0x07) << 4)); | 
| Jean Delvare | 063675b | 2008-07-16 19:30:11 +0200 | [diff] [blame] | 658 | sc_addr[0] = force_subclients[2]; | 
|  | 659 | sc_addr[1] = force_subclients[3]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | } else { | 
| Jean Delvare | af22193 | 2008-01-03 23:15:49 +0100 | [diff] [blame] | 661 | int val = asb100_read_value(client, ASB100_REG_I2C_SUBADDR); | 
| Jean Delvare | 063675b | 2008-07-16 19:30:11 +0200 | [diff] [blame] | 662 | sc_addr[0] = 0x48 + (val & 0x07); | 
|  | 663 | sc_addr[1] = 0x48 + ((val >> 4) & 0x07); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | } | 
|  | 665 |  | 
| Jean Delvare | 063675b | 2008-07-16 19:30:11 +0200 | [diff] [blame] | 666 | if (sc_addr[0] == sc_addr[1]) { | 
| Jean Delvare | af22193 | 2008-01-03 23:15:49 +0100 | [diff] [blame] | 667 | dev_err(&client->dev, "duplicate addresses 0x%x " | 
| Jean Delvare | 063675b | 2008-07-16 19:30:11 +0200 | [diff] [blame] | 668 | "for subclients\n", sc_addr[0]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | err = -ENODEV; | 
|  | 670 | goto ERROR_SC_2; | 
|  | 671 | } | 
|  | 672 |  | 
| Jean Delvare | 063675b | 2008-07-16 19:30:11 +0200 | [diff] [blame] | 673 | data->lm75[0] = i2c_new_dummy(adapter, sc_addr[0]); | 
|  | 674 | if (!data->lm75[0]) { | 
| Jean Delvare | af22193 | 2008-01-03 23:15:49 +0100 | [diff] [blame] | 675 | dev_err(&client->dev, "subclient %d registration " | 
| Jean Delvare | 063675b | 2008-07-16 19:30:11 +0200 | [diff] [blame] | 676 | "at address 0x%x failed.\n", 1, sc_addr[0]); | 
|  | 677 | err = -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | goto ERROR_SC_2; | 
|  | 679 | } | 
|  | 680 |  | 
| Jean Delvare | 063675b | 2008-07-16 19:30:11 +0200 | [diff] [blame] | 681 | data->lm75[1] = i2c_new_dummy(adapter, sc_addr[1]); | 
|  | 682 | if (!data->lm75[1]) { | 
| Jean Delvare | af22193 | 2008-01-03 23:15:49 +0100 | [diff] [blame] | 683 | dev_err(&client->dev, "subclient %d registration " | 
| Jean Delvare | 063675b | 2008-07-16 19:30:11 +0200 | [diff] [blame] | 684 | "at address 0x%x failed.\n", 2, sc_addr[1]); | 
|  | 685 | err = -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | goto ERROR_SC_3; | 
|  | 687 | } | 
|  | 688 |  | 
|  | 689 | return 0; | 
|  | 690 |  | 
|  | 691 | /* Undo inits in case of errors */ | 
|  | 692 | ERROR_SC_3: | 
| Jean Delvare | 063675b | 2008-07-16 19:30:11 +0200 | [diff] [blame] | 693 | i2c_unregister_device(data->lm75[0]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | ERROR_SC_2: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | return err; | 
|  | 696 | } | 
|  | 697 |  | 
| Jean Delvare | 063675b | 2008-07-16 19:30:11 +0200 | [diff] [blame] | 698 | /* Return 0 if detection is successful, -ENODEV otherwise */ | 
| Jean Delvare | 310ec79 | 2009-12-14 21:17:23 +0100 | [diff] [blame] | 699 | static int asb100_detect(struct i2c_client *client, | 
| Jean Delvare | 063675b | 2008-07-16 19:30:11 +0200 | [diff] [blame] | 700 | struct i2c_board_info *info) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | { | 
| Jean Delvare | 063675b | 2008-07-16 19:30:11 +0200 | [diff] [blame] | 702 | struct i2c_adapter *adapter = client->adapter; | 
| Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 703 | int val1, val2; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | 
| Joe Perches | 4d630e2 | 2010-10-20 06:51:29 +0000 | [diff] [blame] | 706 | pr_debug("detect failed, smbus byte data not supported!\n"); | 
| Jean Delvare | 063675b | 2008-07-16 19:30:11 +0200 | [diff] [blame] | 707 | return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | } | 
|  | 709 |  | 
| Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 710 | val1 = i2c_smbus_read_byte_data(client, ASB100_REG_BANK); | 
|  | 711 | val2 = i2c_smbus_read_byte_data(client, ASB100_REG_CHIPMAN); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 |  | 
| Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 713 | /* If we're in bank 0 */ | 
|  | 714 | if ((!(val1 & 0x07)) && | 
|  | 715 | /* Check for ASB100 ID (low byte) */ | 
|  | 716 | (((!(val1 & 0x80)) && (val2 != 0x94)) || | 
|  | 717 | /* Check for ASB100 ID (high byte ) */ | 
|  | 718 | ((val1 & 0x80) && (val2 != 0x06)))) { | 
| Joe Perches | 4d630e2 | 2010-10-20 06:51:29 +0000 | [diff] [blame] | 719 | pr_debug("detect failed, bad chip id 0x%02x!\n", val2); | 
| Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 720 | return -ENODEV; | 
|  | 721 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 |  | 
| Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 723 | /* Put it now into bank 0 and Vendor ID High Byte */ | 
| Jean Delvare | 063675b | 2008-07-16 19:30:11 +0200 | [diff] [blame] | 724 | i2c_smbus_write_byte_data(client, ASB100_REG_BANK, | 
|  | 725 | (i2c_smbus_read_byte_data(client, ASB100_REG_BANK) & 0x78) | 
|  | 726 | | 0x80); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 |  | 
|  | 728 | /* Determine the chip type. */ | 
| Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 729 | val1 = i2c_smbus_read_byte_data(client, ASB100_REG_WCHIPID); | 
|  | 730 | val2 = i2c_smbus_read_byte_data(client, ASB100_REG_CHIPMAN); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 |  | 
| Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 732 | if (val1 != 0x31 || val2 != 0x06) | 
|  | 733 | return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 |  | 
| Jean Delvare | 063675b | 2008-07-16 19:30:11 +0200 | [diff] [blame] | 735 | strlcpy(info->type, "asb100", I2C_NAME_SIZE); | 
|  | 736 |  | 
|  | 737 | return 0; | 
|  | 738 | } | 
|  | 739 |  | 
|  | 740 | static int asb100_probe(struct i2c_client *client, | 
|  | 741 | const struct i2c_device_id *id) | 
|  | 742 | { | 
|  | 743 | int err; | 
|  | 744 | struct asb100_data *data; | 
|  | 745 |  | 
|  | 746 | data = kzalloc(sizeof(struct asb100_data), GFP_KERNEL); | 
|  | 747 | if (!data) { | 
| Joe Perches | 4d630e2 | 2010-10-20 06:51:29 +0000 | [diff] [blame] | 748 | pr_debug("probe failed, kzalloc failed!\n"); | 
| Jean Delvare | 063675b | 2008-07-16 19:30:11 +0200 | [diff] [blame] | 749 | err = -ENOMEM; | 
|  | 750 | goto ERROR0; | 
|  | 751 | } | 
|  | 752 |  | 
|  | 753 | i2c_set_clientdata(client, data); | 
|  | 754 | mutex_init(&data->lock); | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 755 | mutex_init(&data->update_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | /* Attach secondary lm75 clients */ | 
| Jean Delvare | 063675b | 2008-07-16 19:30:11 +0200 | [diff] [blame] | 758 | err = asb100_detect_subclients(client); | 
|  | 759 | if (err) | 
|  | 760 | goto ERROR1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 |  | 
|  | 762 | /* Initialize the chip */ | 
| Jean Delvare | af22193 | 2008-01-03 23:15:49 +0100 | [diff] [blame] | 763 | asb100_init_client(client); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 |  | 
|  | 765 | /* A few vars need to be filled upon startup */ | 
| Jean Delvare | af22193 | 2008-01-03 23:15:49 +0100 | [diff] [blame] | 766 | data->fan_min[0] = asb100_read_value(client, ASB100_REG_FAN_MIN(0)); | 
|  | 767 | data->fan_min[1] = asb100_read_value(client, ASB100_REG_FAN_MIN(1)); | 
|  | 768 | data->fan_min[2] = asb100_read_value(client, ASB100_REG_FAN_MIN(2)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 |  | 
|  | 770 | /* Register sysfs hooks */ | 
| Jean Delvare | af22193 | 2008-01-03 23:15:49 +0100 | [diff] [blame] | 771 | if ((err = sysfs_create_group(&client->dev.kobj, &asb100_group))) | 
| Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 772 | goto ERROR3; | 
|  | 773 |  | 
| Jean Delvare | af22193 | 2008-01-03 23:15:49 +0100 | [diff] [blame] | 774 | data->hwmon_dev = hwmon_device_register(&client->dev); | 
| Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 775 | if (IS_ERR(data->hwmon_dev)) { | 
|  | 776 | err = PTR_ERR(data->hwmon_dev); | 
| Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 777 | goto ERROR4; | 
| Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 778 | } | 
|  | 779 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | return 0; | 
|  | 781 |  | 
| Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 782 | ERROR4: | 
| Jean Delvare | af22193 | 2008-01-03 23:15:49 +0100 | [diff] [blame] | 783 | sysfs_remove_group(&client->dev.kobj, &asb100_group); | 
| Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 784 | ERROR3: | 
| Jean Delvare | 063675b | 2008-07-16 19:30:11 +0200 | [diff] [blame] | 785 | i2c_unregister_device(data->lm75[1]); | 
|  | 786 | i2c_unregister_device(data->lm75[0]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | ERROR1: | 
|  | 788 | kfree(data); | 
|  | 789 | ERROR0: | 
|  | 790 | return err; | 
|  | 791 | } | 
|  | 792 |  | 
| Jean Delvare | 063675b | 2008-07-16 19:30:11 +0200 | [diff] [blame] | 793 | static int asb100_remove(struct i2c_client *client) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | { | 
| Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 795 | struct asb100_data *data = i2c_get_clientdata(client); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 |  | 
| Jean Delvare | 063675b | 2008-07-16 19:30:11 +0200 | [diff] [blame] | 797 | hwmon_device_unregister(data->hwmon_dev); | 
|  | 798 | sysfs_remove_group(&client->dev.kobj, &asb100_group); | 
| Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 799 |  | 
| Jean Delvare | 063675b | 2008-07-16 19:30:11 +0200 | [diff] [blame] | 800 | i2c_unregister_device(data->lm75[1]); | 
|  | 801 | i2c_unregister_device(data->lm75[0]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 |  | 
| Jean Delvare | 063675b | 2008-07-16 19:30:11 +0200 | [diff] [blame] | 803 | kfree(data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 |  | 
|  | 805 | return 0; | 
|  | 806 | } | 
|  | 807 |  | 
|  | 808 | /* The SMBus locks itself, usually, but nothing may access the chip between | 
|  | 809 | bank switches. */ | 
|  | 810 | static int asb100_read_value(struct i2c_client *client, u16 reg) | 
|  | 811 | { | 
|  | 812 | struct asb100_data *data = i2c_get_clientdata(client); | 
|  | 813 | struct i2c_client *cl; | 
|  | 814 | int res, bank; | 
|  | 815 |  | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 816 | mutex_lock(&data->lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 |  | 
|  | 818 | bank = (reg >> 8) & 0x0f; | 
|  | 819 | if (bank > 2) | 
|  | 820 | /* switch banks */ | 
|  | 821 | i2c_smbus_write_byte_data(client, ASB100_REG_BANK, bank); | 
|  | 822 |  | 
|  | 823 | if (bank == 0 || bank > 2) { | 
|  | 824 | res = i2c_smbus_read_byte_data(client, reg & 0xff); | 
|  | 825 | } else { | 
|  | 826 | /* switch to subclient */ | 
|  | 827 | cl = data->lm75[bank - 1]; | 
|  | 828 |  | 
|  | 829 | /* convert from ISA to LM75 I2C addresses */ | 
|  | 830 | switch (reg & 0xff) { | 
|  | 831 | case 0x50: /* TEMP */ | 
| Jean Delvare | 90f4102 | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 832 | res = i2c_smbus_read_word_swapped(cl, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | break; | 
|  | 834 | case 0x52: /* CONFIG */ | 
|  | 835 | res = i2c_smbus_read_byte_data(cl, 1); | 
|  | 836 | break; | 
|  | 837 | case 0x53: /* HYST */ | 
| Jean Delvare | 90f4102 | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 838 | res = i2c_smbus_read_word_swapped(cl, 2); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | break; | 
|  | 840 | case 0x55: /* MAX */ | 
|  | 841 | default: | 
| Jean Delvare | 90f4102 | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 842 | res = i2c_smbus_read_word_swapped(cl, 3); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | break; | 
|  | 844 | } | 
|  | 845 | } | 
|  | 846 |  | 
|  | 847 | if (bank > 2) | 
|  | 848 | i2c_smbus_write_byte_data(client, ASB100_REG_BANK, 0); | 
|  | 849 |  | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 850 | mutex_unlock(&data->lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 |  | 
|  | 852 | return res; | 
|  | 853 | } | 
|  | 854 |  | 
|  | 855 | static void asb100_write_value(struct i2c_client *client, u16 reg, u16 value) | 
|  | 856 | { | 
|  | 857 | struct asb100_data *data = i2c_get_clientdata(client); | 
|  | 858 | struct i2c_client *cl; | 
|  | 859 | int bank; | 
|  | 860 |  | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 861 | mutex_lock(&data->lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 |  | 
|  | 863 | bank = (reg >> 8) & 0x0f; | 
|  | 864 | if (bank > 2) | 
|  | 865 | /* switch banks */ | 
|  | 866 | i2c_smbus_write_byte_data(client, ASB100_REG_BANK, bank); | 
|  | 867 |  | 
|  | 868 | if (bank == 0 || bank > 2) { | 
|  | 869 | i2c_smbus_write_byte_data(client, reg & 0xff, value & 0xff); | 
|  | 870 | } else { | 
|  | 871 | /* switch to subclient */ | 
|  | 872 | cl = data->lm75[bank - 1]; | 
|  | 873 |  | 
|  | 874 | /* convert from ISA to LM75 I2C addresses */ | 
|  | 875 | switch (reg & 0xff) { | 
|  | 876 | case 0x52: /* CONFIG */ | 
|  | 877 | i2c_smbus_write_byte_data(cl, 1, value & 0xff); | 
|  | 878 | break; | 
|  | 879 | case 0x53: /* HYST */ | 
| Jean Delvare | 90f4102 | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 880 | i2c_smbus_write_word_swapped(cl, 2, value); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | break; | 
|  | 882 | case 0x55: /* MAX */ | 
| Jean Delvare | 90f4102 | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 883 | i2c_smbus_write_word_swapped(cl, 3, value); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | break; | 
|  | 885 | } | 
|  | 886 | } | 
|  | 887 |  | 
|  | 888 | if (bank > 2) | 
|  | 889 | i2c_smbus_write_byte_data(client, ASB100_REG_BANK, 0); | 
|  | 890 |  | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 891 | mutex_unlock(&data->lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | } | 
|  | 893 |  | 
|  | 894 | static void asb100_init_client(struct i2c_client *client) | 
|  | 895 | { | 
|  | 896 | struct asb100_data *data = i2c_get_clientdata(client); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 |  | 
| Jean Delvare | 303760b | 2005-07-31 21:52:01 +0200 | [diff] [blame] | 898 | data->vrm = vid_which_vrm(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 |  | 
|  | 900 | /* Start monitoring */ | 
| Jean Delvare | af22193 | 2008-01-03 23:15:49 +0100 | [diff] [blame] | 901 | asb100_write_value(client, ASB100_REG_CONFIG, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | (asb100_read_value(client, ASB100_REG_CONFIG) & 0xf7) | 0x01); | 
|  | 903 | } | 
|  | 904 |  | 
|  | 905 | static struct asb100_data *asb100_update_device(struct device *dev) | 
|  | 906 | { | 
|  | 907 | struct i2c_client *client = to_i2c_client(dev); | 
|  | 908 | struct asb100_data *data = i2c_get_clientdata(client); | 
|  | 909 | int i; | 
|  | 910 |  | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 911 | mutex_lock(&data->update_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 |  | 
|  | 913 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) | 
|  | 914 | || !data->valid) { | 
|  | 915 |  | 
|  | 916 | dev_dbg(&client->dev, "starting device update...\n"); | 
|  | 917 |  | 
|  | 918 | /* 7 voltage inputs */ | 
|  | 919 | for (i = 0; i < 7; i++) { | 
|  | 920 | data->in[i] = asb100_read_value(client, | 
|  | 921 | ASB100_REG_IN(i)); | 
|  | 922 | data->in_min[i] = asb100_read_value(client, | 
|  | 923 | ASB100_REG_IN_MIN(i)); | 
|  | 924 | data->in_max[i] = asb100_read_value(client, | 
|  | 925 | ASB100_REG_IN_MAX(i)); | 
|  | 926 | } | 
|  | 927 |  | 
|  | 928 | /* 3 fan inputs */ | 
|  | 929 | for (i = 0; i < 3; i++) { | 
|  | 930 | data->fan[i] = asb100_read_value(client, | 
|  | 931 | ASB100_REG_FAN(i)); | 
|  | 932 | data->fan_min[i] = asb100_read_value(client, | 
|  | 933 | ASB100_REG_FAN_MIN(i)); | 
|  | 934 | } | 
|  | 935 |  | 
|  | 936 | /* 4 temperature inputs */ | 
|  | 937 | for (i = 1; i <= 4; i++) { | 
|  | 938 | data->temp[i-1] = asb100_read_value(client, | 
|  | 939 | ASB100_REG_TEMP(i)); | 
|  | 940 | data->temp_max[i-1] = asb100_read_value(client, | 
|  | 941 | ASB100_REG_TEMP_MAX(i)); | 
|  | 942 | data->temp_hyst[i-1] = asb100_read_value(client, | 
|  | 943 | ASB100_REG_TEMP_HYST(i)); | 
|  | 944 | } | 
|  | 945 |  | 
|  | 946 | /* VID and fan divisors */ | 
|  | 947 | i = asb100_read_value(client, ASB100_REG_VID_FANDIV); | 
|  | 948 | data->vid = i & 0x0f; | 
|  | 949 | data->vid |= (asb100_read_value(client, | 
|  | 950 | ASB100_REG_CHIPID) & 0x01) << 4; | 
|  | 951 | data->fan_div[0] = (i >> 4) & 0x03; | 
|  | 952 | data->fan_div[1] = (i >> 6) & 0x03; | 
|  | 953 | data->fan_div[2] = (asb100_read_value(client, | 
|  | 954 | ASB100_REG_PIN) >> 6) & 0x03; | 
|  | 955 |  | 
|  | 956 | /* PWM */ | 
|  | 957 | data->pwm = asb100_read_value(client, ASB100_REG_PWM1); | 
|  | 958 |  | 
|  | 959 | /* alarms */ | 
|  | 960 | data->alarms = asb100_read_value(client, ASB100_REG_ALARM1) + | 
|  | 961 | (asb100_read_value(client, ASB100_REG_ALARM2) << 8); | 
|  | 962 |  | 
|  | 963 | data->last_updated = jiffies; | 
|  | 964 | data->valid = 1; | 
|  | 965 |  | 
|  | 966 | dev_dbg(&client->dev, "... device update complete\n"); | 
|  | 967 | } | 
|  | 968 |  | 
| Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 969 | mutex_unlock(&data->update_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 |  | 
|  | 971 | return data; | 
|  | 972 | } | 
|  | 973 |  | 
|  | 974 | static int __init asb100_init(void) | 
|  | 975 | { | 
|  | 976 | return i2c_add_driver(&asb100_driver); | 
|  | 977 | } | 
|  | 978 |  | 
|  | 979 | static void __exit asb100_exit(void) | 
|  | 980 | { | 
|  | 981 | i2c_del_driver(&asb100_driver); | 
|  | 982 | } | 
|  | 983 |  | 
|  | 984 | MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>"); | 
|  | 985 | MODULE_DESCRIPTION("ASB100 Bach driver"); | 
|  | 986 | MODULE_LICENSE("GPL"); | 
|  | 987 |  | 
|  | 988 | module_init(asb100_init); | 
|  | 989 | module_exit(asb100_exit); |