2 it87.c - Part of lm_sensors, Linux kernel modules for hardware
5 Supports: IT8705F Super I/O chip w/LPC interface
6 IT8712F Super I/O chip w/LPC interface & SMbus
7 Sis950 A clone of the IT8705F
9 Copyright (C) 2001 Chris Gauthron <chrisg@0-in.com>
10 Largely inspired by lm78.c of the same package
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 djg@pdp8.net David Gesswein 7/18/01
29 Modified to fix bug with not all alarms enabled.
30 Added ability to read battery voltage and select temperature sensor
31 type at module load time.
34 #include <linux/config.h>
35 #include <linux/module.h>
36 #include <linux/init.h>
37 #include <linux/slab.h>
38 #include <linux/i2c.h>
39 #include <linux/i2c-sensor.h>
40 #include <linux/i2c-vid.h>
44 /* Addresses to scan */
45 static unsigned short normal_i2c[] = { 0x20, 0x21, 0x22, 0x23, 0x24,
46 0x25, 0x26, 0x27, 0x28, 0x29,
47 0x2a, 0x2b, 0x2c, 0x2d, 0x2e,
48 0x2f, I2C_CLIENT_END };
49 static unsigned int normal_isa[] = { 0x0290, I2C_CLIENT_ISA_END };
51 /* Insmod parameters */
52 SENSORS_INSMOD_2(it87, it8712);
54 #define REG 0x2e /* The register to read/write */
55 #define DEV 0x07 /* Register: Logical device select */
56 #define VAL 0x2f /* The value to read/write */
57 #define PME 0x04 /* The device with the fan registers in it */
58 #define DEVID 0x20 /* Register: Device ID */
90 /* just IT8712F for now - this should be extended to support the other
92 #define IT8712F_DEVID 0x8712
93 #define IT87_ACT_REG 0x30
94 #define IT87_BASE_REG 0x60
96 /* Update battery voltage after every reading if true */
97 static int update_vbat;
99 /* Reset the registers on init if true */
104 static u16 chip_type;
106 /* Many IT87 constants specified below */
108 /* Length of ISA address segment */
109 #define IT87_EXTENT 8
111 /* Where are the ISA address/data registers relative to the base address */
112 #define IT87_ADDR_REG_OFFSET 5
113 #define IT87_DATA_REG_OFFSET 6
115 /*----- The IT87 registers -----*/
117 #define IT87_REG_CONFIG 0x00
119 #define IT87_REG_ALARM1 0x01
120 #define IT87_REG_ALARM2 0x02
121 #define IT87_REG_ALARM3 0x03
123 #define IT87_REG_VID 0x0a
124 #define IT87_REG_FAN_DIV 0x0b
126 /* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */
128 #define IT87_REG_FAN(nr) (0x0d + (nr))
129 #define IT87_REG_FAN_MIN(nr) (0x10 + (nr))
130 #define IT87_REG_FAN_MAIN_CTRL 0x13
132 #define IT87_REG_VIN(nr) (0x20 + (nr))
133 #define IT87_REG_TEMP(nr) (0x29 + (nr))
135 #define IT87_REG_VIN_MAX(nr) (0x30 + (nr) * 2)
136 #define IT87_REG_VIN_MIN(nr) (0x31 + (nr) * 2)
137 #define IT87_REG_TEMP_HIGH(nr) (0x40 + (nr) * 2)
138 #define IT87_REG_TEMP_LOW(nr) (0x41 + (nr) * 2)
140 #define IT87_REG_I2C_ADDR 0x48
142 #define IT87_REG_VIN_ENABLE 0x50
143 #define IT87_REG_TEMP_ENABLE 0x51
145 #define IT87_REG_CHIPID 0x58
147 #define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8)/16),0,255))
148 #define IN_FROM_REG(val) ((val) * 16)
150 static inline u8 FAN_TO_REG(long rpm, int div)
154 rpm = SENSORS_LIMIT(rpm, 1, 1000000);
155 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1,
159 #define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div)))
161 #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)<0?(((val)-500)/1000):\
162 ((val)+500)/1000),-128,127))
163 #define TEMP_FROM_REG(val) (((val)>0x80?(val)-0x100:(val))*1000)
165 #define ALARMS_FROM_REG(val) (val)
167 static int DIV_TO_REG(int val)
170 while ((val >>= 1) != 0)
174 #define DIV_FROM_REG(val) (1 << (val))
177 /* For each registered IT87, we need to keep some data in memory. That
178 data is pointed to by it87_list[NR]->data. The structure itself is
179 dynamically allocated, at the same time when a new it87 client is
182 struct i2c_client client;
183 struct semaphore lock;
186 struct semaphore update_lock;
187 char valid; /* !=0 if following fields are valid */
188 unsigned long last_updated; /* In jiffies */
190 u8 in[9]; /* Register value */
191 u8 in_max[9]; /* Register value */
192 u8 in_min[9]; /* Register value */
193 u8 fan[3]; /* Register value */
194 u8 fan_min[3]; /* Register value */
195 u8 temp[3]; /* Register value */
196 u8 temp_high[3]; /* Register value */
197 u8 temp_low[3]; /* Register value */
198 u8 sensor; /* Register value */
199 u8 fan_div[3]; /* Register encoding, shifted right */
200 u8 vid; /* Register encoding, combined */
202 u32 alarms; /* Register encoding, combined */
206 static int it87_attach_adapter(struct i2c_adapter *adapter);
207 static int it87_find(int *address);
208 static int it87_detect(struct i2c_adapter *adapter, int address, int kind);
209 static int it87_detach_client(struct i2c_client *client);
211 static int it87_read_value(struct i2c_client *client, u8 register);
212 static int it87_write_value(struct i2c_client *client, u8 register,
214 static struct it87_data *it87_update_device(struct device *dev);
215 static void it87_init_client(struct i2c_client *client, struct it87_data *data);
218 static struct i2c_driver it87_driver = {
219 .owner = THIS_MODULE,
221 .id = I2C_DRIVERID_IT87,
222 .flags = I2C_DF_NOTIFY,
223 .attach_adapter = it87_attach_adapter,
224 .detach_client = it87_detach_client,
229 static ssize_t show_in(struct device *dev, char *buf, int nr)
231 struct it87_data *data = it87_update_device(dev);
232 return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr]));
235 static ssize_t show_in_min(struct device *dev, char *buf, int nr)
237 struct it87_data *data = it87_update_device(dev);
238 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr]));
241 static ssize_t show_in_max(struct device *dev, char *buf, int nr)
243 struct it87_data *data = it87_update_device(dev);
244 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr]));
247 static ssize_t set_in_min(struct device *dev, const char *buf,
248 size_t count, int nr)
250 struct i2c_client *client = to_i2c_client(dev);
251 struct it87_data *data = i2c_get_clientdata(client);
252 unsigned long val = simple_strtoul(buf, NULL, 10);
253 data->in_min[nr] = IN_TO_REG(val);
254 it87_write_value(client, IT87_REG_VIN_MIN(nr),
258 static ssize_t set_in_max(struct device *dev, const char *buf,
259 size_t count, int nr)
261 struct i2c_client *client = to_i2c_client(dev);
262 struct it87_data *data = i2c_get_clientdata(client);
263 unsigned long val = simple_strtoul(buf, NULL, 10);
264 data->in_max[nr] = IN_TO_REG(val);
265 it87_write_value(client, IT87_REG_VIN_MAX(nr),
270 #define show_in_offset(offset) \
272 show_in##offset (struct device *dev, char *buf) \
274 return show_in(dev, buf, offset); \
276 static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in##offset, NULL);
278 #define limit_in_offset(offset) \
280 show_in##offset##_min (struct device *dev, char *buf) \
282 return show_in_min(dev, buf, offset); \
285 show_in##offset##_max (struct device *dev, char *buf) \
287 return show_in_max(dev, buf, offset); \
289 static ssize_t set_in##offset##_min (struct device *dev, \
290 const char *buf, size_t count) \
292 return set_in_min(dev, buf, count, offset); \
294 static ssize_t set_in##offset##_max (struct device *dev, \
295 const char *buf, size_t count) \
297 return set_in_max(dev, buf, count, offset); \
299 static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
300 show_in##offset##_min, set_in##offset##_min); \
301 static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
302 show_in##offset##_max, set_in##offset##_max);
323 static ssize_t show_temp(struct device *dev, char *buf, int nr)
325 struct it87_data *data = it87_update_device(dev);
326 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr]));
328 static ssize_t show_temp_max(struct device *dev, char *buf, int nr)
330 struct it87_data *data = it87_update_device(dev);
331 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_high[nr]));
333 static ssize_t show_temp_min(struct device *dev, char *buf, int nr)
335 struct it87_data *data = it87_update_device(dev);
336 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_low[nr]));
338 static ssize_t set_temp_max(struct device *dev, const char *buf,
339 size_t count, int nr)
341 struct i2c_client *client = to_i2c_client(dev);
342 struct it87_data *data = i2c_get_clientdata(client);
343 int val = simple_strtol(buf, NULL, 10);
344 data->temp_high[nr] = TEMP_TO_REG(val);
345 it87_write_value(client, IT87_REG_TEMP_HIGH(nr), data->temp_high[nr]);
348 static ssize_t set_temp_min(struct device *dev, const char *buf,
349 size_t count, int nr)
351 struct i2c_client *client = to_i2c_client(dev);
352 struct it87_data *data = i2c_get_clientdata(client);
353 int val = simple_strtol(buf, NULL, 10);
354 data->temp_low[nr] = TEMP_TO_REG(val);
355 it87_write_value(client, IT87_REG_TEMP_LOW(nr), data->temp_low[nr]);
358 #define show_temp_offset(offset) \
359 static ssize_t show_temp_##offset (struct device *dev, char *buf) \
361 return show_temp(dev, buf, offset - 1); \
364 show_temp_##offset##_max (struct device *dev, char *buf) \
366 return show_temp_max(dev, buf, offset - 1); \
369 show_temp_##offset##_min (struct device *dev, char *buf) \
371 return show_temp_min(dev, buf, offset - 1); \
373 static ssize_t set_temp_##offset##_max (struct device *dev, \
374 const char *buf, size_t count) \
376 return set_temp_max(dev, buf, count, offset - 1); \
378 static ssize_t set_temp_##offset##_min (struct device *dev, \
379 const char *buf, size_t count) \
381 return set_temp_min(dev, buf, count, offset - 1); \
383 static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp_##offset, NULL); \
384 static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
385 show_temp_##offset##_max, set_temp_##offset##_max); \
386 static DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
387 show_temp_##offset##_min, set_temp_##offset##_min);
393 static ssize_t show_sensor(struct device *dev, char *buf, int nr)
395 struct it87_data *data = it87_update_device(dev);
396 if (data->sensor & (1 << nr))
397 return sprintf(buf, "3\n"); /* thermal diode */
398 if (data->sensor & (8 << nr))
399 return sprintf(buf, "2\n"); /* thermistor */
400 return sprintf(buf, "0\n"); /* disabled */
402 static ssize_t set_sensor(struct device *dev, const char *buf,
403 size_t count, int nr)
405 struct i2c_client *client = to_i2c_client(dev);
406 struct it87_data *data = i2c_get_clientdata(client);
407 int val = simple_strtol(buf, NULL, 10);
409 data->sensor &= ~(1 << nr);
410 data->sensor &= ~(8 << nr);
411 /* 3 = thermal diode; 2 = thermistor; 0 = disabled */
413 data->sensor |= 1 << nr;
415 data->sensor |= 8 << nr;
418 it87_write_value(client, IT87_REG_TEMP_ENABLE, data->sensor);
421 #define show_sensor_offset(offset) \
422 static ssize_t show_sensor_##offset (struct device *dev, char *buf) \
424 return show_sensor(dev, buf, offset - 1); \
426 static ssize_t set_sensor_##offset (struct device *dev, \
427 const char *buf, size_t count) \
429 return set_sensor(dev, buf, count, offset - 1); \
431 static DEVICE_ATTR(temp##offset##_type, S_IRUGO | S_IWUSR, \
432 show_sensor_##offset, set_sensor_##offset);
434 show_sensor_offset(1);
435 show_sensor_offset(2);
436 show_sensor_offset(3);
439 static ssize_t show_fan(struct device *dev, char *buf, int nr)
441 struct it87_data *data = it87_update_device(dev);
442 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr],
443 DIV_FROM_REG(data->fan_div[nr])) );
445 static ssize_t show_fan_min(struct device *dev, char *buf, int nr)
447 struct it87_data *data = it87_update_device(dev);
448 return sprintf(buf,"%d\n",
449 FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])) );
451 static ssize_t show_fan_div(struct device *dev, char *buf, int nr)
453 struct it87_data *data = it87_update_device(dev);
454 return sprintf(buf,"%d\n", DIV_FROM_REG(data->fan_div[nr]) );
456 static ssize_t set_fan_min(struct device *dev, const char *buf,
457 size_t count, int nr)
459 struct i2c_client *client = to_i2c_client(dev);
460 struct it87_data *data = i2c_get_clientdata(client);
461 int val = simple_strtol(buf, NULL, 10);
462 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
463 it87_write_value(client, IT87_REG_FAN_MIN(nr), data->fan_min[nr]);
466 static ssize_t set_fan_div(struct device *dev, const char *buf,
467 size_t count, int nr)
469 struct i2c_client *client = to_i2c_client(dev);
470 struct it87_data *data = i2c_get_clientdata(client);
471 int val = simple_strtol(buf, NULL, 10);
473 u8 old = it87_read_value(client, IT87_REG_FAN_DIV);
475 for (i = 0; i < 3; i++)
476 min[i] = FAN_FROM_REG(data->fan_min[i], DIV_FROM_REG(data->fan_div[i]));
481 data->fan_div[nr] = DIV_TO_REG(val);
485 data->fan_div[nr] = 1;
487 data->fan_div[nr] = 3;
490 val |= (data->fan_div[0] & 0x07);
491 val |= (data->fan_div[1] & 0x07) << 3;
492 if (data->fan_div[2] == 3)
494 it87_write_value(client, IT87_REG_FAN_DIV, val);
496 for (i = 0; i < 3; i++) {
497 data->fan_min[i]=FAN_TO_REG(min[i], DIV_FROM_REG(data->fan_div[i]));
498 it87_write_value(client, IT87_REG_FAN_MIN(i), data->fan_min[i]);
503 #define show_fan_offset(offset) \
504 static ssize_t show_fan_##offset (struct device *dev, char *buf) \
506 return show_fan(dev, buf, offset - 1); \
508 static ssize_t show_fan_##offset##_min (struct device *dev, char *buf) \
510 return show_fan_min(dev, buf, offset - 1); \
512 static ssize_t show_fan_##offset##_div (struct device *dev, char *buf) \
514 return show_fan_div(dev, buf, offset - 1); \
516 static ssize_t set_fan_##offset##_min (struct device *dev, \
517 const char *buf, size_t count) \
519 return set_fan_min(dev, buf, count, offset - 1); \
521 static ssize_t set_fan_##offset##_div (struct device *dev, \
522 const char *buf, size_t count) \
524 return set_fan_div(dev, buf, count, offset - 1); \
526 static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, NULL); \
527 static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
528 show_fan_##offset##_min, set_fan_##offset##_min); \
529 static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
530 show_fan_##offset##_div, set_fan_##offset##_div);
537 static ssize_t show_alarms(struct device *dev, char *buf)
539 struct it87_data *data = it87_update_device(dev);
540 return sprintf(buf,"%d\n", ALARMS_FROM_REG(data->alarms));
542 static DEVICE_ATTR(alarms, S_IRUGO | S_IWUSR, show_alarms, NULL);
545 show_vrm_reg(struct device *dev, char *buf)
547 struct it87_data *data = it87_update_device(dev);
548 return sprintf(buf, "%ld\n", (long) data->vrm);
551 store_vrm_reg(struct device *dev, const char *buf, size_t count)
553 struct i2c_client *client = to_i2c_client(dev);
554 struct it87_data *data = i2c_get_clientdata(client);
557 val = simple_strtoul(buf, NULL, 10);
562 static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
563 #define device_create_file_vrm(client) \
564 device_create_file(&client->dev, &dev_attr_vrm)
567 show_vid_reg(struct device *dev, char *buf)
569 struct it87_data *data = it87_update_device(dev);
570 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
572 static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
573 #define device_create_file_vid(client) \
574 device_create_file(&client->dev, &dev_attr_cpu0_vid)
576 /* This function is called when:
577 * it87_driver is inserted (when this module is loaded), for each
579 * when a new adapter is inserted (and it87_driver is still present) */
580 static int it87_attach_adapter(struct i2c_adapter *adapter)
582 if (!(adapter->class & I2C_CLASS_HWMON))
584 return i2c_detect(adapter, &addr_data, it87_detect);
587 /* SuperIO detection - will change normal_isa[0] if a chip is found */
588 static int it87_find(int *address)
593 chip_type = (superio_inb(DEVID) << 8) |
594 superio_inb(DEVID + 1);
595 if (chip_type != IT8712F_DEVID) {
601 val = (superio_inb(IT87_BASE_REG) << 8) |
602 superio_inb(IT87_BASE_REG + 1);
604 *address = val & ~(IT87_EXTENT - 1);
611 /* This function is called by i2c_detect */
612 int it87_detect(struct i2c_adapter *adapter, int address, int kind)
615 struct i2c_client *new_client;
616 struct it87_data *data;
618 const char *name = "";
619 int is_isa = i2c_is_isa_adapter(adapter);
622 !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
625 /* Reserve the ISA region */
627 if (!request_region(address, IT87_EXTENT, name))
630 /* Probe whether there is anything available on this address. Already
631 done for SMBus clients */
635 #define REALLY_SLOW_IO
636 /* We need the timeouts for at least some IT87-like chips. But only
637 if we read 'undefined' registers. */
638 i = inb_p(address + 1);
639 if (inb_p(address + 2) != i
640 || inb_p(address + 3) != i
641 || inb_p(address + 7) != i) {
645 #undef REALLY_SLOW_IO
647 /* Let's just hope nothing breaks here */
648 i = inb_p(address + 5) & 0x7f;
649 outb_p(~i & 0x7f, address + 5);
650 if ((inb_p(address + 5) & 0x7f) != (~i & 0x7f)) {
651 outb_p(i, address + 5);
658 /* OK. For now, we presume we have a valid client. We now create the
659 client structure, even though we cannot fill it completely yet.
660 But it allows us to access it87_{read,write}_value. */
662 if (!(data = kmalloc(sizeof(struct it87_data), GFP_KERNEL))) {
666 memset(data, 0, sizeof(struct it87_data));
668 new_client = &data->client;
670 init_MUTEX(&data->lock);
671 i2c_set_clientdata(new_client, data);
672 new_client->addr = address;
673 new_client->adapter = adapter;
674 new_client->driver = &it87_driver;
675 new_client->flags = 0;
677 /* Now, we do the remaining detection. */
680 if ((it87_read_value(new_client, IT87_REG_CONFIG) & 0x80)
682 && it87_read_value(new_client, IT87_REG_I2C_ADDR) != address)) {
688 /* Determine the chip type. */
690 i = it87_read_value(new_client, IT87_REG_CHIPID);
693 if ((is_isa) && (chip_type == IT8712F_DEVID))
698 dev_info(&adapter->dev,
699 "Ignoring 'force' parameter for unknown chip at "
700 "adapter %d, address 0x%02x\n",
701 i2c_adapter_id(adapter), address);
709 } else if (kind == it8712) {
713 /* Fill in the remaining client fields and put it into the global list */
714 strlcpy(new_client->name, name, I2C_NAME_SIZE);
718 new_client->id = it87_id++;
720 init_MUTEX(&data->update_lock);
722 /* Tell the I2C layer a new client has arrived */
723 if ((err = i2c_attach_client(new_client)))
726 /* Initialize the IT87 chip */
727 it87_init_client(new_client, data);
729 /* Register sysfs hooks */
730 device_create_file(&new_client->dev, &dev_attr_in0_input);
731 device_create_file(&new_client->dev, &dev_attr_in1_input);
732 device_create_file(&new_client->dev, &dev_attr_in2_input);
733 device_create_file(&new_client->dev, &dev_attr_in3_input);
734 device_create_file(&new_client->dev, &dev_attr_in4_input);
735 device_create_file(&new_client->dev, &dev_attr_in5_input);
736 device_create_file(&new_client->dev, &dev_attr_in6_input);
737 device_create_file(&new_client->dev, &dev_attr_in7_input);
738 device_create_file(&new_client->dev, &dev_attr_in8_input);
739 device_create_file(&new_client->dev, &dev_attr_in0_min);
740 device_create_file(&new_client->dev, &dev_attr_in1_min);
741 device_create_file(&new_client->dev, &dev_attr_in2_min);
742 device_create_file(&new_client->dev, &dev_attr_in3_min);
743 device_create_file(&new_client->dev, &dev_attr_in4_min);
744 device_create_file(&new_client->dev, &dev_attr_in5_min);
745 device_create_file(&new_client->dev, &dev_attr_in6_min);
746 device_create_file(&new_client->dev, &dev_attr_in7_min);
747 device_create_file(&new_client->dev, &dev_attr_in0_max);
748 device_create_file(&new_client->dev, &dev_attr_in1_max);
749 device_create_file(&new_client->dev, &dev_attr_in2_max);
750 device_create_file(&new_client->dev, &dev_attr_in3_max);
751 device_create_file(&new_client->dev, &dev_attr_in4_max);
752 device_create_file(&new_client->dev, &dev_attr_in5_max);
753 device_create_file(&new_client->dev, &dev_attr_in6_max);
754 device_create_file(&new_client->dev, &dev_attr_in7_max);
755 device_create_file(&new_client->dev, &dev_attr_temp1_input);
756 device_create_file(&new_client->dev, &dev_attr_temp2_input);
757 device_create_file(&new_client->dev, &dev_attr_temp3_input);
758 device_create_file(&new_client->dev, &dev_attr_temp1_max);
759 device_create_file(&new_client->dev, &dev_attr_temp2_max);
760 device_create_file(&new_client->dev, &dev_attr_temp3_max);
761 device_create_file(&new_client->dev, &dev_attr_temp1_min);
762 device_create_file(&new_client->dev, &dev_attr_temp2_min);
763 device_create_file(&new_client->dev, &dev_attr_temp3_min);
764 device_create_file(&new_client->dev, &dev_attr_temp1_type);
765 device_create_file(&new_client->dev, &dev_attr_temp2_type);
766 device_create_file(&new_client->dev, &dev_attr_temp3_type);
767 device_create_file(&new_client->dev, &dev_attr_fan1_input);
768 device_create_file(&new_client->dev, &dev_attr_fan2_input);
769 device_create_file(&new_client->dev, &dev_attr_fan3_input);
770 device_create_file(&new_client->dev, &dev_attr_fan1_min);
771 device_create_file(&new_client->dev, &dev_attr_fan2_min);
772 device_create_file(&new_client->dev, &dev_attr_fan3_min);
773 device_create_file(&new_client->dev, &dev_attr_fan1_div);
774 device_create_file(&new_client->dev, &dev_attr_fan2_div);
775 device_create_file(&new_client->dev, &dev_attr_fan3_div);
776 device_create_file(&new_client->dev, &dev_attr_alarms);
778 if (data->type == it8712) {
779 device_create_file_vrm(new_client);
780 device_create_file_vid(new_client);
781 data->vrm = i2c_which_vrm();
790 release_region(address, IT87_EXTENT);
795 static int it87_detach_client(struct i2c_client *client)
799 if ((err = i2c_detach_client(client))) {
800 dev_err(&client->dev,
801 "Client deregistration failed, client not detached.\n");
805 if(i2c_is_isa_client(client))
806 release_region(client->addr, IT87_EXTENT);
807 kfree(i2c_get_clientdata(client));
812 /* The SMBus locks itself, but ISA access must be locked explicitely!
813 We don't want to lock the whole ISA bus, so we lock each client
815 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
816 would slow down the IT87 access and should not be necessary. */
817 static int it87_read_value(struct i2c_client *client, u8 reg)
819 struct it87_data *data = i2c_get_clientdata(client);
822 if (i2c_is_isa_client(client)) {
824 outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET);
825 res = inb_p(client->addr + IT87_DATA_REG_OFFSET);
829 return i2c_smbus_read_byte_data(client, reg);
832 /* The SMBus locks itself, but ISA access muse be locked explicitely!
833 We don't want to lock the whole ISA bus, so we lock each client
835 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
836 would slow down the IT87 access and should not be necessary. */
837 static int it87_write_value(struct i2c_client *client, u8 reg, u8 value)
839 struct it87_data *data = i2c_get_clientdata(client);
841 if (i2c_is_isa_client(client)) {
843 outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET);
844 outb_p(value, client->addr + IT87_DATA_REG_OFFSET);
848 return i2c_smbus_write_byte_data(client, reg, value);
851 /* Called when we have found a new IT87. */
852 static void it87_init_client(struct i2c_client *client, struct it87_data *data)
857 /* Reset all except Watchdog values and last conversion values
858 This sets fan-divs to 2, among others */
859 it87_write_value(client, IT87_REG_CONFIG, 0x80);
862 /* Check if temperature channnels are reset manually or by some reason */
863 tmp = it87_read_value(client, IT87_REG_TEMP_ENABLE);
864 if ((tmp & 0x3f) == 0) {
865 /* Temp1,Temp3=thermistor; Temp2=thermal diode */
866 tmp = (tmp & 0xc0) | 0x2a;
867 it87_write_value(client, IT87_REG_TEMP_ENABLE, tmp);
871 /* Check if voltage monitors are reset manually or by some reason */
872 tmp = it87_read_value(client, IT87_REG_VIN_ENABLE);
873 if ((tmp & 0xff) == 0) {
874 /* Enable all voltage monitors */
875 it87_write_value(client, IT87_REG_VIN_ENABLE, 0xff);
878 /* Check if tachometers are reset manually or by some reason */
879 tmp = it87_read_value(client, IT87_REG_FAN_MAIN_CTRL);
880 if ((tmp & 0x70) == 0) {
881 /* Enable all fan tachometers */
882 tmp = (tmp & 0x8f) | 0x70;
883 it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, tmp);
886 /* Start monitoring */
887 it87_write_value(client, IT87_REG_CONFIG,
888 (it87_read_value(client, IT87_REG_CONFIG) & 0x36)
889 | (update_vbat ? 0x41 : 0x01));
892 static struct it87_data *it87_update_device(struct device *dev)
894 struct i2c_client *client = to_i2c_client(dev);
895 struct it87_data *data = i2c_get_clientdata(client);
898 down(&data->update_lock);
900 if ((jiffies - data->last_updated > HZ + HZ / 2) ||
901 (jiffies < data->last_updated) || !data->valid) {
904 /* Cleared after each update, so reenable. Value
905 returned by this read will be previous value */
906 it87_write_value(client, IT87_REG_CONFIG,
907 it87_read_value(client, IT87_REG_CONFIG) | 0x40);
909 for (i = 0; i <= 7; i++) {
911 it87_read_value(client, IT87_REG_VIN(i));
913 it87_read_value(client, IT87_REG_VIN_MIN(i));
915 it87_read_value(client, IT87_REG_VIN_MAX(i));
918 it87_read_value(client, IT87_REG_VIN(8));
919 /* Temperature sensor doesn't have limit registers, set
920 to min and max value */
922 data->in_max[8] = 255;
924 for (i = 0; i < 3; i++) {
926 it87_read_value(client, IT87_REG_FAN(i));
928 it87_read_value(client, IT87_REG_FAN_MIN(i));
930 for (i = 0; i < 3; i++) {
932 it87_read_value(client, IT87_REG_TEMP(i));
934 it87_read_value(client, IT87_REG_TEMP_HIGH(i));
936 it87_read_value(client, IT87_REG_TEMP_LOW(i));
939 /* The 8705 does not have VID capability */
942 i = it87_read_value(client, IT87_REG_FAN_DIV);
943 data->fan_div[0] = i & 0x07;
944 data->fan_div[1] = (i >> 3) & 0x07;
945 data->fan_div[2] = (i & 0x40) ? 3 : 1;
948 it87_read_value(client, IT87_REG_ALARM1) |
949 (it87_read_value(client, IT87_REG_ALARM2) << 8) |
950 (it87_read_value(client, IT87_REG_ALARM3) << 16);
952 data->sensor = it87_read_value(client, IT87_REG_TEMP_ENABLE);
953 /* The 8705 does not have VID capability */
954 if (data->type == it8712) {
955 data->vid = it87_read_value(client, IT87_REG_VID);
958 data->last_updated = jiffies;
962 up(&data->update_lock);
967 static int __init sm_it87_init(void)
971 if (!it87_find(&addr)) {
972 normal_isa[0] = addr;
974 return i2c_add_driver(&it87_driver);
977 static void __exit sm_it87_exit(void)
979 i2c_del_driver(&it87_driver);
983 MODULE_AUTHOR("Chris Gauthron <chrisg@0-in.com>");
984 MODULE_DESCRIPTION("IT8705F, IT8712F, Sis950 driver");
985 module_param(update_vbat, bool, 0);
986 MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value");
987 module_param(reset, bool, 0);
988 MODULE_PARM_DESC(reset, "Reset the chip's registers, default no");
989 MODULE_LICENSE("GPL");
991 module_init(sm_it87_init);
992 module_exit(sm_it87_exit);