2 lm78.c - Part of lm_sensors, Linux kernel modules for hardware
4 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <linux/config.h>
22 #include <linux/module.h>
23 #include <linux/init.h>
24 #include <linux/slab.h>
25 #include <linux/i2c.h>
26 #include <linux/i2c-sensor.h>
29 /* Addresses to scan */
30 static unsigned short normal_i2c[] = { 0x20, 0x21, 0x22, 0x23, 0x24,
31 0x25, 0x26, 0x27, 0x28, 0x29,
32 0x2a, 0x2b, 0x2c, 0x2d, 0x2e,
33 0x2f, I2C_CLIENT_END };
34 static unsigned int normal_isa[] = { 0x0290, I2C_CLIENT_ISA_END };
36 /* Insmod parameters */
37 SENSORS_INSMOD_3(lm78, lm78j, lm79);
39 /* Many LM78 constants specified below */
41 /* Length of ISA address segment */
44 /* Where are the ISA address/data registers relative to the base address */
45 #define LM78_ADDR_REG_OFFSET 5
46 #define LM78_DATA_REG_OFFSET 6
48 /* The LM78 registers */
49 #define LM78_REG_IN_MAX(nr) (0x2b + (nr) * 2)
50 #define LM78_REG_IN_MIN(nr) (0x2c + (nr) * 2)
51 #define LM78_REG_IN(nr) (0x20 + (nr))
53 #define LM78_REG_FAN_MIN(nr) (0x3b + (nr))
54 #define LM78_REG_FAN(nr) (0x28 + (nr))
56 #define LM78_REG_TEMP 0x27
57 #define LM78_REG_TEMP_OVER 0x39
58 #define LM78_REG_TEMP_HYST 0x3a
60 #define LM78_REG_ALARM1 0x41
61 #define LM78_REG_ALARM2 0x42
63 #define LM78_REG_VID_FANDIV 0x47
65 #define LM78_REG_CONFIG 0x40
66 #define LM78_REG_CHIPID 0x49
67 #define LM78_REG_I2C_ADDR 0x48
70 /* Conversions. Rounding and limit checking is only done on the TO_REG
73 /* IN: mV, (0V to 4.08V)
75 static inline u8 IN_TO_REG(unsigned long val)
77 unsigned long nval = SENSORS_LIMIT(val, 0, 4080);
78 return (nval + 8) / 16;
80 #define IN_FROM_REG(val) ((val) * 16)
82 static inline u8 FAN_TO_REG(long rpm, int div)
86 rpm = SENSORS_LIMIT(rpm, 1, 1000000);
87 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
90 static inline int FAN_FROM_REG(u8 val, int div)
92 return val==0 ? -1 : val==255 ? 0 : 1350000/(val*div);
95 /* TEMP: mC (-128C to +127C)
96 REG: 1C/bit, two's complement */
97 static inline u8 TEMP_TO_REG(int val)
99 int nval = SENSORS_LIMIT(val, -128000, 127000) ;
100 return nval<0 ? (nval-500)/1000+0x100 : (nval+500)/1000;
103 static inline int TEMP_FROM_REG(u8 val)
105 return (val>=0x80 ? val-0x100 : val) * 1000;
109 REG: (see doc/vid) */
110 static inline int VID_FROM_REG(u8 val)
112 return val==0x1f ? 0 : val>=0x10 ? 5100-val*100 : 2050-val*50;
115 /* ALARMS: chip-specific bitmask
117 #define ALARMS_FROM_REG(val) (val)
119 /* FAN DIV: 1, 2, 4, or 8 (defaults to 2)
120 REG: 0, 1, 2, or 3 (respectively) (defaults to 1) */
121 static inline u8 DIV_TO_REG(int val)
123 return val==8 ? 3 : val==4 ? 2 : val==1 ? 0 : 1;
125 #define DIV_FROM_REG(val) (1 << (val))
127 /* There are some complications in a module like this. First off, LM78 chips
128 may be both present on the SMBus and the ISA bus, and we have to handle
129 those cases separately at some places. Second, there might be several
130 LM78 chips available (well, actually, that is probably never done; but
131 it is a clean illustration of how to handle a case like that). Finally,
132 a specific chip may be attached to *both* ISA and SMBus, and we would
133 not like to detect it double. Fortunately, in the case of the LM78 at
134 least, a register tells us what SMBus address we are on, so that helps
135 a bit - except if there could be more than one SMBus. Groan. No solution
138 /* This module may seem overly long and complicated. In fact, it is not so
139 bad. Quite a lot of bookkeeping is done. A real driver can often cut
142 /* For each registered LM78, we need to keep some data in memory. That
143 data is pointed to by lm78_list[NR]->data. The structure itself is
144 dynamically allocated, at the same time when a new lm78 client is
147 struct i2c_client client;
148 struct semaphore lock;
151 struct semaphore update_lock;
152 char valid; /* !=0 if following fields are valid */
153 unsigned long last_updated; /* In jiffies */
155 u8 in[7]; /* Register value */
156 u8 in_max[7]; /* Register value */
157 u8 in_min[7]; /* Register value */
158 u8 fan[3]; /* Register value */
159 u8 fan_min[3]; /* Register value */
160 u8 temp; /* Register value */
161 u8 temp_over; /* Register value */
162 u8 temp_hyst; /* Register value */
163 u8 fan_div[3]; /* Register encoding, shifted right */
164 u8 vid; /* Register encoding, combined */
165 u16 alarms; /* Register encoding, combined */
169 static int lm78_attach_adapter(struct i2c_adapter *adapter);
170 static int lm78_detect(struct i2c_adapter *adapter, int address, int kind);
171 static int lm78_detach_client(struct i2c_client *client);
173 static int lm78_read_value(struct i2c_client *client, u8 register);
174 static int lm78_write_value(struct i2c_client *client, u8 register, u8 value);
175 static struct lm78_data *lm78_update_device(struct device *dev);
176 static void lm78_init_client(struct i2c_client *client);
179 static struct i2c_driver lm78_driver = {
180 .owner = THIS_MODULE,
182 .id = I2C_DRIVERID_LM78,
183 .flags = I2C_DF_NOTIFY,
184 .attach_adapter = lm78_attach_adapter,
185 .detach_client = lm78_detach_client,
189 static ssize_t show_in(struct device *dev, char *buf, int nr)
191 struct lm78_data *data = lm78_update_device(dev);
192 return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr]));
195 static ssize_t show_in_min(struct device *dev, char *buf, int nr)
197 struct lm78_data *data = lm78_update_device(dev);
198 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr]));
201 static ssize_t show_in_max(struct device *dev, char *buf, int nr)
203 struct lm78_data *data = lm78_update_device(dev);
204 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr]));
207 static ssize_t set_in_min(struct device *dev, const char *buf,
208 size_t count, int nr)
210 struct i2c_client *client = to_i2c_client(dev);
211 struct lm78_data *data = i2c_get_clientdata(client);
212 unsigned long val = simple_strtoul(buf, NULL, 10);
213 data->in_min[nr] = IN_TO_REG(val);
214 lm78_write_value(client, LM78_REG_IN_MIN(nr), data->in_min[nr]);
218 static ssize_t set_in_max(struct device *dev, const char *buf,
219 size_t count, int nr)
221 struct i2c_client *client = to_i2c_client(dev);
222 struct lm78_data *data = i2c_get_clientdata(client);
223 unsigned long val = simple_strtoul(buf, NULL, 10);
224 data->in_max[nr] = IN_TO_REG(val);
225 lm78_write_value(client, LM78_REG_IN_MAX(nr), data->in_max[nr]);
229 #define show_in_offset(offset) \
231 show_in##offset (struct device *dev, char *buf) \
233 return show_in(dev, buf, offset); \
235 static DEVICE_ATTR(in##offset##_input, S_IRUGO, \
236 show_in##offset, NULL); \
238 show_in##offset##_min (struct device *dev, char *buf) \
240 return show_in_min(dev, buf, offset); \
243 show_in##offset##_max (struct device *dev, char *buf) \
245 return show_in_max(dev, buf, offset); \
247 static ssize_t set_in##offset##_min (struct device *dev, \
248 const char *buf, size_t count) \
250 return set_in_min(dev, buf, count, offset); \
252 static ssize_t set_in##offset##_max (struct device *dev, \
253 const char *buf, size_t count) \
255 return set_in_max(dev, buf, count, offset); \
257 static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
258 show_in##offset##_min, set_in##offset##_min); \
259 static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
260 show_in##offset##_max, set_in##offset##_max);
271 static ssize_t show_temp(struct device *dev, char *buf)
273 struct lm78_data *data = lm78_update_device(dev);
274 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp));
277 static ssize_t show_temp_over(struct device *dev, char *buf)
279 struct lm78_data *data = lm78_update_device(dev);
280 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_over));
283 static ssize_t set_temp_over(struct device *dev, const char *buf, size_t count)
285 struct i2c_client *client = to_i2c_client(dev);
286 struct lm78_data *data = i2c_get_clientdata(client);
287 long val = simple_strtol(buf, NULL, 10);
288 data->temp_over = TEMP_TO_REG(val);
289 lm78_write_value(client, LM78_REG_TEMP_OVER, data->temp_over);
293 static ssize_t show_temp_hyst(struct device *dev, char *buf)
295 struct lm78_data *data = lm78_update_device(dev);
296 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_hyst));
299 static ssize_t set_temp_hyst(struct device *dev, const char *buf, size_t count)
301 struct i2c_client *client = to_i2c_client(dev);
302 struct lm78_data *data = i2c_get_clientdata(client);
303 long val = simple_strtol(buf, NULL, 10);
304 data->temp_hyst = TEMP_TO_REG(val);
305 lm78_write_value(client, LM78_REG_TEMP_HYST, data->temp_hyst);
309 static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL);
310 static DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR,
311 show_temp_over, set_temp_over);
312 static DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR,
313 show_temp_hyst, set_temp_hyst);
316 static ssize_t show_fan(struct device *dev, char *buf, int nr)
318 struct lm78_data *data = lm78_update_device(dev);
319 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
320 DIV_FROM_REG(data->fan_div[nr])) );
323 static ssize_t show_fan_min(struct device *dev, char *buf, int nr)
325 struct lm78_data *data = lm78_update_device(dev);
326 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr],
327 DIV_FROM_REG(data->fan_div[nr])) );
330 static ssize_t set_fan_min(struct device *dev, const char *buf,
331 size_t count, int nr)
333 struct i2c_client *client = to_i2c_client(dev);
334 struct lm78_data *data = i2c_get_clientdata(client);
335 unsigned long val = simple_strtoul(buf, NULL, 10);
336 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
337 lm78_write_value(client, LM78_REG_FAN_MIN(nr), data->fan_min[nr]);
341 static ssize_t show_fan_div(struct device *dev, char *buf, int nr)
343 struct lm78_data *data = lm78_update_device(dev);
344 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]) );
347 /* Note: we save and restore the fan minimum here, because its value is
348 determined in part by the fan divisor. This follows the principle of
349 least suprise; the user doesn't expect the fan minimum to change just
350 because the divisor changed. */
351 static ssize_t set_fan_div(struct device *dev, const char *buf,
352 size_t count, int nr)
354 struct i2c_client *client = to_i2c_client(dev);
355 struct lm78_data *data = i2c_get_clientdata(client);
356 unsigned long min = FAN_FROM_REG(data->fan_min[nr],
357 DIV_FROM_REG(data->fan_div[nr]));
358 unsigned long val = simple_strtoul(buf, NULL, 10);
359 int reg = lm78_read_value(client, LM78_REG_VID_FANDIV);
360 data->fan_div[nr] = DIV_TO_REG(val);
363 reg = (reg & 0xcf) | (data->fan_div[nr] << 4);
366 reg = (reg & 0x3f) | (data->fan_div[nr] << 6);
369 lm78_write_value(client, LM78_REG_VID_FANDIV, reg);
371 FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
372 lm78_write_value(client, LM78_REG_FAN_MIN(nr), data->fan_min[nr]);
376 #define show_fan_offset(offset) \
377 static ssize_t show_fan_##offset (struct device *dev, char *buf) \
379 return show_fan(dev, buf, offset - 1); \
381 static ssize_t show_fan_##offset##_min (struct device *dev, char *buf) \
383 return show_fan_min(dev, buf, offset - 1); \
385 static ssize_t show_fan_##offset##_div (struct device *dev, char *buf) \
387 return show_fan_div(dev, buf, offset - 1); \
389 static ssize_t set_fan_##offset##_min (struct device *dev, \
390 const char *buf, size_t count) \
392 return set_fan_min(dev, buf, count, offset - 1); \
394 static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, NULL);\
395 static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
396 show_fan_##offset##_min, set_fan_##offset##_min);
398 static ssize_t set_fan_1_div(struct device *dev, const char *buf,
401 return set_fan_div(dev, buf, count, 0) ;
404 static ssize_t set_fan_2_div(struct device *dev, const char *buf,
407 return set_fan_div(dev, buf, count, 1) ;
414 /* Fan 3 divisor is locked in H/W */
415 static DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR,
416 show_fan_1_div, set_fan_1_div);
417 static DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR,
418 show_fan_2_div, set_fan_2_div);
419 static DEVICE_ATTR(fan3_div, S_IRUGO, show_fan_3_div, NULL);
422 static ssize_t show_vid(struct device *dev, char *buf)
424 struct lm78_data *data = lm78_update_device(dev);
425 return sprintf(buf, "%d\n", VID_FROM_REG(data->vid));
427 static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
430 static ssize_t show_alarms(struct device *dev, char *buf)
432 struct lm78_data *data = lm78_update_device(dev);
433 return sprintf(buf, "%d\n", ALARMS_FROM_REG(data->alarms));
435 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
437 /* This function is called when:
438 * lm78_driver is inserted (when this module is loaded), for each
440 * when a new adapter is inserted (and lm78_driver is still present) */
441 static int lm78_attach_adapter(struct i2c_adapter *adapter)
443 if (!(adapter->class & I2C_CLASS_HWMON))
445 return i2c_detect(adapter, &addr_data, lm78_detect);
448 /* This function is called by i2c_detect */
449 int lm78_detect(struct i2c_adapter *adapter, int address, int kind)
452 struct i2c_client *new_client;
453 struct lm78_data *data;
454 const char *client_name = "";
455 int is_isa = i2c_is_isa_adapter(adapter);
458 !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
463 /* Reserve the ISA region */
465 if (!request_region(address, LM78_EXTENT, lm78_driver.name)) {
470 /* Probe whether there is anything available on this address. Already
471 done for SMBus clients */
475 #define REALLY_SLOW_IO
476 /* We need the timeouts for at least some LM78-like
477 chips. But only if we read 'undefined' registers. */
478 i = inb_p(address + 1);
479 if (inb_p(address + 2) != i) {
483 if (inb_p(address + 3) != i) {
487 if (inb_p(address + 7) != i) {
491 #undef REALLY_SLOW_IO
493 /* Let's just hope nothing breaks here */
494 i = inb_p(address + 5) & 0x7f;
495 outb_p(~i & 0x7f, address + 5);
496 if ((inb_p(address + 5) & 0x7f) != (~i & 0x7f)) {
497 outb_p(i, address + 5);
504 /* OK. For now, we presume we have a valid client. We now create the
505 client structure, even though we cannot fill it completely yet.
506 But it allows us to access lm78_{read,write}_value. */
508 if (!(data = kmalloc(sizeof(struct lm78_data), GFP_KERNEL))) {
512 memset(data, 0, sizeof(struct lm78_data));
514 new_client = &data->client;
516 init_MUTEX(&data->lock);
517 i2c_set_clientdata(new_client, data);
518 new_client->addr = address;
519 new_client->adapter = adapter;
520 new_client->driver = &lm78_driver;
521 new_client->flags = 0;
523 /* Now, we do the remaining detection. */
525 if (lm78_read_value(new_client, LM78_REG_CONFIG) & 0x80) {
529 if (!is_isa && (lm78_read_value(
530 new_client, LM78_REG_I2C_ADDR) != address)) {
536 /* Determine the chip type. */
538 i = lm78_read_value(new_client, LM78_REG_CHIPID);
539 if (i == 0x00 || i == 0x20)
543 else if ((i & 0xfe) == 0xc0)
547 dev_warn(&adapter->dev, "Ignoring 'force' "
548 "parameter for unknown chip at "
549 "adapter %d, address 0x%02x\n",
550 i2c_adapter_id(adapter), address);
557 client_name = "lm78";
558 } else if (kind == lm78j) {
559 client_name = "lm78-j";
560 } else if (kind == lm79) {
561 client_name = "lm79";
564 /* Fill in the remaining client fields and put into the global list */
565 strlcpy(new_client->name, client_name, I2C_NAME_SIZE);
569 init_MUTEX(&data->update_lock);
571 /* Tell the I2C layer a new client has arrived */
572 if ((err = i2c_attach_client(new_client)))
575 /* Initialize the LM78 chip */
576 lm78_init_client(new_client);
578 /* A few vars need to be filled upon startup */
579 for (i = 0; i < 3; i++) {
580 data->fan_min[i] = lm78_read_value(new_client,
581 LM78_REG_FAN_MIN(i));
584 /* Register sysfs hooks */
585 device_create_file(&new_client->dev, &dev_attr_in0_input);
586 device_create_file(&new_client->dev, &dev_attr_in0_min);
587 device_create_file(&new_client->dev, &dev_attr_in0_max);
588 device_create_file(&new_client->dev, &dev_attr_in1_input);
589 device_create_file(&new_client->dev, &dev_attr_in1_min);
590 device_create_file(&new_client->dev, &dev_attr_in1_max);
591 device_create_file(&new_client->dev, &dev_attr_in2_input);
592 device_create_file(&new_client->dev, &dev_attr_in2_min);
593 device_create_file(&new_client->dev, &dev_attr_in2_max);
594 device_create_file(&new_client->dev, &dev_attr_in3_input);
595 device_create_file(&new_client->dev, &dev_attr_in3_min);
596 device_create_file(&new_client->dev, &dev_attr_in3_max);
597 device_create_file(&new_client->dev, &dev_attr_in4_input);
598 device_create_file(&new_client->dev, &dev_attr_in4_min);
599 device_create_file(&new_client->dev, &dev_attr_in4_max);
600 device_create_file(&new_client->dev, &dev_attr_in5_input);
601 device_create_file(&new_client->dev, &dev_attr_in5_min);
602 device_create_file(&new_client->dev, &dev_attr_in5_max);
603 device_create_file(&new_client->dev, &dev_attr_in6_input);
604 device_create_file(&new_client->dev, &dev_attr_in6_min);
605 device_create_file(&new_client->dev, &dev_attr_in6_max);
606 device_create_file(&new_client->dev, &dev_attr_temp1_input);
607 device_create_file(&new_client->dev, &dev_attr_temp1_max);
608 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
609 device_create_file(&new_client->dev, &dev_attr_fan1_input);
610 device_create_file(&new_client->dev, &dev_attr_fan1_min);
611 device_create_file(&new_client->dev, &dev_attr_fan1_div);
612 device_create_file(&new_client->dev, &dev_attr_fan2_input);
613 device_create_file(&new_client->dev, &dev_attr_fan2_min);
614 device_create_file(&new_client->dev, &dev_attr_fan2_div);
615 device_create_file(&new_client->dev, &dev_attr_fan3_input);
616 device_create_file(&new_client->dev, &dev_attr_fan3_min);
617 device_create_file(&new_client->dev, &dev_attr_fan3_div);
618 device_create_file(&new_client->dev, &dev_attr_alarms);
619 device_create_file(&new_client->dev, &dev_attr_cpu0_vid);
627 release_region(address, LM78_EXTENT);
632 static int lm78_detach_client(struct i2c_client *client)
636 /* release ISA region first */
637 if(i2c_is_isa_client(client))
638 release_region(client->addr, LM78_EXTENT);
640 /* now it's safe to scrap the rest */
641 if ((err = i2c_detach_client(client))) {
642 dev_err(&client->dev,
643 "Client deregistration failed, client not detached.\n");
647 kfree(i2c_get_clientdata(client));
652 /* The SMBus locks itself, but ISA access must be locked explicitely!
653 We don't want to lock the whole ISA bus, so we lock each client
655 We ignore the LM78 BUSY flag at this moment - it could lead to deadlocks,
656 would slow down the LM78 access and should not be necessary.
657 There are some ugly typecasts here, but the good new is - they should
658 nowhere else be necessary! */
659 static int lm78_read_value(struct i2c_client *client, u8 reg)
662 if (i2c_is_isa_client(client)) {
663 struct lm78_data *data = i2c_get_clientdata(client);
665 outb_p(reg, client->addr + LM78_ADDR_REG_OFFSET);
666 res = inb_p(client->addr + LM78_DATA_REG_OFFSET);
670 return i2c_smbus_read_byte_data(client, reg);
673 /* The SMBus locks itself, but ISA access muse be locked explicitely!
674 We don't want to lock the whole ISA bus, so we lock each client
676 We ignore the LM78 BUSY flag at this moment - it could lead to deadlocks,
677 would slow down the LM78 access and should not be necessary.
678 There are some ugly typecasts here, but the good new is - they should
679 nowhere else be necessary! */
680 static int lm78_write_value(struct i2c_client *client, u8 reg, u8 value)
682 if (i2c_is_isa_client(client)) {
683 struct lm78_data *data = i2c_get_clientdata(client);
685 outb_p(reg, client->addr + LM78_ADDR_REG_OFFSET);
686 outb_p(value, client->addr + LM78_DATA_REG_OFFSET);
690 return i2c_smbus_write_byte_data(client, reg, value);
693 /* Called when we have found a new LM78. It should set limits, etc. */
694 static void lm78_init_client(struct i2c_client *client)
696 u8 config = lm78_read_value(client, LM78_REG_CONFIG);
698 /* Start monitoring */
699 if (!(config & 0x01))
700 lm78_write_value(client, LM78_REG_CONFIG,
701 (config & 0xf7) | 0x01);
704 static struct lm78_data *lm78_update_device(struct device *dev)
706 struct i2c_client *client = to_i2c_client(dev);
707 struct lm78_data *data = i2c_get_clientdata(client);
710 down(&data->update_lock);
712 if ((jiffies - data->last_updated > HZ + HZ / 2) ||
713 (jiffies < data->last_updated) || !data->valid) {
715 dev_dbg(&client->dev, "Starting lm78 update\n");
717 for (i = 0; i <= 6; i++) {
719 lm78_read_value(client, LM78_REG_IN(i));
721 lm78_read_value(client, LM78_REG_IN_MIN(i));
723 lm78_read_value(client, LM78_REG_IN_MAX(i));
725 for (i = 0; i < 3; i++) {
727 lm78_read_value(client, LM78_REG_FAN(i));
729 lm78_read_value(client, LM78_REG_FAN_MIN(i));
731 data->temp = lm78_read_value(client, LM78_REG_TEMP);
733 lm78_read_value(client, LM78_REG_TEMP_OVER);
735 lm78_read_value(client, LM78_REG_TEMP_HYST);
736 i = lm78_read_value(client, LM78_REG_VID_FANDIV);
737 data->vid = i & 0x0f;
738 if (data->type == lm79)
740 (lm78_read_value(client, LM78_REG_CHIPID) &
744 data->fan_div[0] = (i >> 4) & 0x03;
745 data->fan_div[1] = i >> 6;
746 data->alarms = lm78_read_value(client, LM78_REG_ALARM1) +
747 (lm78_read_value(client, LM78_REG_ALARM2) << 8);
748 data->last_updated = jiffies;
751 data->fan_div[2] = 1;
754 up(&data->update_lock);
759 static int __init sm_lm78_init(void)
761 return i2c_add_driver(&lm78_driver);
764 static void __exit sm_lm78_exit(void)
766 i2c_del_driver(&lm78_driver);
771 MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>");
772 MODULE_DESCRIPTION("LM78, LM78-J and LM79 driver");
773 MODULE_LICENSE("GPL");
775 module_init(sm_lm78_init);
776 module_exit(sm_lm78_exit);