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