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