root/lm-sensors/trunk/kernel/chips/lm90.c @ 2816

Revision 2816, 23.0 KB (checked in by khali, 8 years ago)

Fix MAX6657, MAX6658 and MAX6659 detection (backport from Linux

2.6).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*
2 * lm90.c - Part of lm_sensors, Linux kernel modules for hardware
3 *          monitoring
4 * Copyright (C) 2003-2004  Jean Delvare <khali@linux-fr.org>
5 *
6 * Based on the lm83 driver. The LM90 is a sensor chip made by National
7 * Semiconductor. It reports up to two temperatures (its own plus up to
8 * one external one) with a 0.125 deg resolution (1 deg for local
9 * temperature) and a 3-4 deg accuracy. Complete datasheet can be
10 * obtained from National's website at:
11 *   http://www.national.com/pf/LM/LM90.html
12 *
13 * This driver also supports the LM89 and LM99, two other sensor chips
14 * made by National Semiconductor. Both have an increased remote
15 * temperature measurement accuracy (1 degree), and the LM99
16 * additionally shifts remote temperatures (measured and limits) by 16
17 * degrees, which allows for higher temperatures measurement. The
18 * driver doesn't handle it since it can be done easily in user-space.
19 * Complete datasheets can be obtained from National's website at:
20 *   http://www.national.com/pf/LM/LM89.html
21 *   http://www.national.com/pf/LM/LM99.html
22 * Note that there is no way to differenciate between both chips.
23 *
24 * This driver also supports the LM86, another sensor chip made by
25 * National Semiconductor. It is exactly similar to the LM90 except it
26 * has a higher accuracy.
27 * Complete datasheet can be obtained from National's website at:
28 *   http://www.national.com/pf/LM/LM86.html
29 *
30 * This driver also supports the ADM1032, a sensor chip made by Analog
31 * Devices. That chip is similar to the LM90, with a few differences
32 * that are not handled by this driver. Complete datasheet can be
33 * obtained from Analog's website at:
34 *   http://products.analog.com/products/info.asp?product=ADM1032
35 * Among others, it has a higher accuracy than the LM90, much like the
36 * LM86 does.
37 *
38 * This driver also supports the MAX6657, MAX6658 and MAX6659 sensor
39 * chips made by Maxim. These chips are similar to the LM86. Complete
40 * datasheet can be obtained at Maxim's website at:
41 *   http://www.maxim-ic.com/quick_view2.cfm/qv_pk/2578
42 * Note that there is no easy way to differenciate between the three
43 * variants. The extra address and features of the MAX6659 are not
44 * supported by this driver.
45 *
46 * Since the LM90 was the first chipset supported by this driver, most
47 * comments will refer to this chipset, but are actually general and
48 * concern all supported chipsets, unless mentioned otherwise.
49 *
50 * This program is free software; you can redistribute it and/or modify
51 * it under the terms of the GNU General Public License as published by
52 * the Free Software Foundation; either version 2 of the License, or
53 * (at your option) any later version.
54 *
55 * This program is distributed in the hope that it will be useful,
56 * but WITHOUT ANY WARRANTY; without even the implied warranty of
57 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
58 * GNU General Public License for more details.
59 *
60 * You should have received a copy of the GNU General Public License
61 * along with this program; if not, write to the Free Software
62 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
63 */
64
65#include <linux/module.h>
66#include <linux/slab.h>
67#include <linux/i2c.h>
68#include <linux/i2c-proc.h>
69#include <linux/init.h>
70#include "version.h"
71
72#ifndef I2C_DRIVERID_LM90
73#define I2C_DRIVERID_LM90       1042
74#endif
75
76/*
77 * Addresses to scan
78 * Address is fully defined internally and cannot be changed except for
79 * MAX6659.
80 * LM86, LM89, LM90, LM99, ADM1032, MAX6657 and MAX6658 have address 0x4c.
81 * LM89-1, and LM99-1 have address 0x4d.
82 * MAX6659 can have address 0x4c, 0x4d or 0x4e (unsupported).
83 */
84
85static unsigned short normal_i2c[] = { 0x4c, 0x4d, SENSORS_I2C_END };
86static unsigned short normal_i2c_range[] = { SENSORS_I2C_END };
87static unsigned int normal_isa[] = { SENSORS_ISA_END };
88static unsigned int normal_isa_range[] = { SENSORS_ISA_END };
89
90/*
91 * Insmod parameters
92 */
93
94SENSORS_INSMOD_5(lm90, adm1032, lm99, lm86, max6657);
95
96/*
97 * The LM90 registers
98 */
99
100#define LM90_REG_R_MAN_ID        0xFE
101#define LM90_REG_R_CHIP_ID       0xFF
102#define LM90_REG_R_CONFIG1       0x03
103#define LM90_REG_W_CONFIG1       0x09
104#define LM90_REG_R_CONFIG2       0xBF
105#define LM90_REG_W_CONFIG2       0xBF
106#define LM90_REG_R_CONVRATE      0x04
107#define LM90_REG_W_CONVRATE      0x0A
108#define LM90_REG_R_STATUS        0x02
109#define LM90_REG_R_LOCAL_TEMP    0x00
110#define LM90_REG_R_LOCAL_HIGH    0x05
111#define LM90_REG_W_LOCAL_HIGH    0x0B
112#define LM90_REG_R_LOCAL_LOW     0x06
113#define LM90_REG_W_LOCAL_LOW     0x0C
114#define LM90_REG_R_LOCAL_CRIT    0x20
115#define LM90_REG_W_LOCAL_CRIT    0x20
116#define LM90_REG_R_REMOTE_TEMPH  0x01
117#define LM90_REG_R_REMOTE_TEMPL  0x10
118#define LM90_REG_R_REMOTE_OFFSH  0x11
119#define LM90_REG_W_REMOTE_OFFSH  0x11
120#define LM90_REG_R_REMOTE_OFFSL  0x12
121#define LM90_REG_W_REMOTE_OFFSL  0x12
122#define LM90_REG_R_REMOTE_HIGHH  0x07
123#define LM90_REG_W_REMOTE_HIGHH  0x0D
124#define LM90_REG_R_REMOTE_HIGHL  0x13
125#define LM90_REG_W_REMOTE_HIGHL  0x13
126#define LM90_REG_R_REMOTE_LOWH   0x08
127#define LM90_REG_W_REMOTE_LOWH   0x0E
128#define LM90_REG_R_REMOTE_LOWL   0x14
129#define LM90_REG_W_REMOTE_LOWL   0x14
130#define LM90_REG_R_REMOTE_CRIT   0x19
131#define LM90_REG_W_REMOTE_CRIT   0x19
132#define LM90_REG_R_TCRIT_HYST    0x21
133#define LM90_REG_W_TCRIT_HYST    0x21
134
135/*
136 * Conversions and various macros
137 * For local temperatures and limits, critical limits and the hysteresis
138 * value, the LM90 uses signed 8-bit values with LSB = 1 degree Celcius.
139 * For remote temperatures and limits, it uses signed 11-bit values with
140 * LSB = 0.125 degree Celcius, left-justified in 16-bit registers.
141 */
142
143#define TEMP1_FROM_REG(val)     (val)
144#define TEMP1_TO_REG(val)       ((val) <= -128 ? -128 : \
145                                 (val) >= 127 ? 127 : (val))
146#define TEMP2_FROM_REG(val)     ((val) / 32 * 125 / 100)
147#define TEMP2_TO_REG(val)       ((val) <= -1280 ? 0x8000 : \
148                                 (val) >= 1270 ? 0x7FE0 : \
149                                 ((val) * 100 / 125 * 32))
150#define HYST_TO_REG(val)        ((val) <= 0 ? 0 : \
151                                 (val) >= 31 ? 31 : (val))
152
153/*
154 * Functions declaration
155 */
156
157static int lm90_attach_adapter(struct i2c_adapter *adapter);
158static int lm90_detect(struct i2c_adapter *adapter, int address,
159        unsigned short flags, int kind);
160static void lm90_init_client(struct i2c_client *client);
161static int lm90_detach_client(struct i2c_client *client);
162static void lm90_local_temp(struct i2c_client *client, int operation,
163        int ctl_name, int *nrels_mag, long *results);
164static void lm90_remote_temp(struct i2c_client *client, int operation,
165        int ctl_name, int *nrels_mag, long *results);
166static void lm90_local_tcrit(struct i2c_client *client, int operation,
167        int ctl_name, int *nrels_mag, long *results);
168static void lm90_remote_tcrit(struct i2c_client *client, int operation,
169        int ctl_name, int *nrels_mag, long *results);
170static void lm90_local_hyst(struct i2c_client *client, int operation,
171        int ctl_name, int *nrels_mag, long *results);
172static void lm90_remote_hyst(struct i2c_client *client, int operation,
173        int ctl_name, int *nrels_mag, long *results);
174static void lm90_alarms(struct i2c_client *client, int operation,
175        int ctl_name, int *nrels_mag, long *results);
176
177/*
178 * Driver data (common to all clients)
179 */
180
181static struct i2c_driver lm90_driver = {
182        .name           = "LM90/ADM1032 sensor driver",
183        .id             = I2C_DRIVERID_LM90,
184        .flags          = I2C_DF_NOTIFY,
185        .attach_adapter = lm90_attach_adapter,
186        .detach_client  = lm90_detach_client
187};
188
189/*
190 * Client data (each client gets its own)
191 */
192
193struct lm90_data
194{
195        struct i2c_client client;
196        int sysctl_id;
197
198        struct semaphore update_lock;
199        char valid; /* zero until following fields are valid */
200        unsigned long last_updated; /* in jiffies */
201
202        /* registers values */
203        s8 local_temp, local_high, local_low;
204        s16 remote_temp, remote_high, remote_low; /* combined */
205        s8 local_crit, remote_crit;
206        u8 hyst; /* linked to two sysctl files (hyst1 RW, hyst2 RO) */
207        u8 alarms; /* bitvector */
208};
209
210/*
211 * Proc entries
212 * These files are created for each detected LM90.
213 */
214
215/* -- SENSORS SYSCTL START -- */
216
217#define LM90_SYSCTL_LOCAL_TEMP    1200
218#define LM90_SYSCTL_REMOTE_TEMP   1201
219#define LM90_SYSCTL_LOCAL_TCRIT   1204
220#define LM90_SYSCTL_REMOTE_TCRIT  1205
221#define LM90_SYSCTL_LOCAL_HYST    1207
222#define LM90_SYSCTL_REMOTE_HYST   1208
223#define LM90_SYSCTL_ALARMS        1210
224
225#define LM90_ALARM_LOCAL_HIGH     0x40
226#define LM90_ALARM_LOCAL_LOW      0x20
227#define LM90_ALARM_LOCAL_CRIT     0x01
228#define LM90_ALARM_REMOTE_HIGH    0x10
229#define LM90_ALARM_REMOTE_LOW     0x08
230#define LM90_ALARM_REMOTE_CRIT    0x02
231#define LM90_ALARM_REMOTE_OPEN    0x04
232
233/* -- SENSORS SYSCTL END -- */
234
235
236static ctl_table lm90_dir_table_template[] =
237{
238        {LM90_SYSCTL_LOCAL_TEMP, "temp1", NULL, 0, 0644, NULL,
239         &i2c_proc_real, &i2c_sysctl_real, NULL, &lm90_local_temp},
240        {LM90_SYSCTL_REMOTE_TEMP, "temp2", NULL, 0, 0644, NULL,
241         &i2c_proc_real, &i2c_sysctl_real, NULL, &lm90_remote_temp},
242        {LM90_SYSCTL_LOCAL_TCRIT, "tcrit1", NULL, 0, 0644, NULL,
243         &i2c_proc_real, &i2c_sysctl_real, NULL, &lm90_local_tcrit},
244        {LM90_SYSCTL_REMOTE_TCRIT, "tcrit2", NULL, 0, 0644, NULL,
245         &i2c_proc_real, &i2c_sysctl_real, NULL, &lm90_remote_tcrit},
246        {LM90_SYSCTL_LOCAL_HYST, "hyst1", NULL, 0, 0644, NULL,
247         &i2c_proc_real, &i2c_sysctl_real, NULL, &lm90_local_hyst},
248        {LM90_SYSCTL_REMOTE_HYST, "hyst2", NULL, 0, 0444, NULL,
249         &i2c_proc_real, &i2c_sysctl_real, NULL, &lm90_remote_hyst},
250        {LM90_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL,
251         &i2c_proc_real, &i2c_sysctl_real, NULL, &lm90_alarms},
252        {0}
253};
254
255/*
256 * Internal variables
257 */
258
259static int lm90_id = 0;
260
261/*
262 * Real code
263 */
264
265static int lm90_attach_adapter(struct i2c_adapter *adapter)
266{
267        return i2c_detect(adapter, &addr_data, lm90_detect);
268}
269
270/*
271 * The following function does more than just detection. If detection
272 * succeeds, it also registers the new chip.
273 */
274static int lm90_detect(struct i2c_adapter *adapter, int address,
275        unsigned short flags, int kind)
276{
277        struct i2c_client *new_client;
278        struct lm90_data *data;
279        int err = 0;
280        const char *type_name = "";
281        const char *client_name = "";
282
283#ifdef DEBUG
284        if (i2c_is_isa_adapter(adapter))
285        {
286                printk("lm90.o: Called for an ISA bus adapter, aborting.\n");
287                return 0;
288        }
289#endif
290
291        if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
292        {
293#ifdef DEBUG
294                printk("lm90.o: I2C bus doesn't support byte read mode, "
295                       "skipping.\n");
296#endif
297                return 0;
298        }
299
300        if (!(data = kmalloc(sizeof(struct lm90_data), GFP_KERNEL)))
301        {
302                printk("lm90.o: Out of memory in lm90_detect (new_client).\n");
303                return -ENOMEM;
304        }
305
306        /*
307         * The common I2C client data is placed right before the
308         * LM90-specific data. The LM90-specific data is pointed to by the
309         * data field from the I2C client data.
310         */
311
312        new_client = &data->client;
313        new_client->addr = address;
314        new_client->data = data;
315        new_client->adapter = adapter;
316        new_client->driver = &lm90_driver;
317        new_client->flags = 0;
318
319        /*
320         * Now we do the remaining detection. A negative kind means that
321         * the driver was loaded with no force parameter (default), so we
322         * must both detect and identify the chip. A zero kind means that
323         * the driver was loaded with the force parameter, the detection
324         * step shall be skipped. A positive kind means that the driver
325         * was loaded with the force parameter and a given kind of chip is
326         * requested, so both the detection and the identification steps
327         * are skipped.
328         */
329
330        /* Default to an LM90 if forced */
331        if (kind == 0)
332                kind = lm90;
333
334        if (kind < 0) /* detection and identification */
335        {
336                u8 man_id, chip_id, reg_config1, reg_convrate;
337
338                man_id = i2c_smbus_read_byte_data(new_client,
339                        LM90_REG_R_MAN_ID);
340                chip_id = i2c_smbus_read_byte_data(new_client,
341                        LM90_REG_R_CHIP_ID);
342                reg_config1 = i2c_smbus_read_byte_data(new_client,
343                        LM90_REG_R_CONFIG1);
344                reg_convrate = i2c_smbus_read_byte_data(new_client,
345                        LM90_REG_R_CONVRATE);
346               
347                if (man_id == 0x01) /* National Semiconductor */
348                {
349                        u8 reg_config2;
350
351                        reg_config2 = i2c_smbus_read_byte_data(new_client,
352                                LM90_REG_R_CONFIG2);
353
354                        if ((reg_config1 & 0x2A) == 0x00
355                         && (reg_config2 & 0xF8) == 0x00
356                         && reg_convrate <= 0x09)
357                        {
358                                if (address == 0x4C
359                                 && (chip_id & 0xF0) == 0x20) /* LM90 */
360                                        kind = lm90;
361                                else if ((chip_id & 0xF0) == 0x30) /* LM89/LM99 */
362                                        kind = lm99;
363                                else if (address == 0x4C
364                                 && (chip_id & 0xF0) == 0x10) /* LM86 */
365                                        kind = lm99;
366                        }
367                }
368                else if (man_id == 0x41) /* Analog Devices */
369                {
370                        if (address == 0x4C
371                         && (chip_id & 0xF0) == 0x40 /* ADM1032 */
372                         && (reg_config1 & 0x3F) == 0x00
373                         && reg_convrate <= 0x0A)
374                                kind = adm1032;
375                }
376                else if (man_id == 0x4D) /* Maxim */
377                {
378                        /*
379                         * The Maxim variants do NOT have a chip_id register.
380                         * Reading from that address will return the last read
381                         * value, which in our case is those of the man_id
382                         * register. Likewise, the config1 register seems to
383                         * lack a low nibble, so the value will be those of the
384                         * previous read, so in our case those of the man_id
385                         * register.
386                         */
387                        if (chip_id == man_id
388                         && (reg_config1 & 0x1F) == (man_id & 0x0F)
389                         && reg_convrate <= 0x09)
390                                kind = max6657;
391                }
392        }
393
394        if (kind <= 0) /* identification failed */
395        {
396                printk("lm90.o: Unsupported chip.\n");
397                goto ERROR1;
398        }
399
400        if (kind == lm90)
401        {
402                type_name = "lm90";
403                client_name = "LM90 chip";
404        }
405        else if (kind == adm1032)
406        {
407                type_name = "adm1032";
408                client_name = "ADM1032 chip";
409        }
410        else if (kind == lm99)
411        {
412                type_name = "lm99";
413                client_name = "LM99 chip";
414        }
415        else if (kind == lm86)
416        {
417                type_name = "lm86";
418                client_name = "LM86 chip";
419        }
420        else if (kind == max6657)
421        {
422                type_name = "max6657";
423                client_name = "MAX6657 chip";
424        }
425        else
426        {
427                printk("lm90.o: Unknown kind %d.\n", kind);
428                goto ERROR1;
429        }
430
431        /*
432         * OK, we got a valid chip so we can fill in the remaining client
433         * fields.
434         */
435
436        strcpy(new_client->name, client_name);
437        new_client->id = lm90_id++;
438        data->valid = 0;
439        init_MUTEX(&data->update_lock);
440
441        /*
442         * Tell the I2C layer a new client has arrived.
443         */
444
445        if ((err = i2c_attach_client(new_client)))
446        {
447#ifdef DEBUG
448                printk("lm90.o: Failed attaching client.\n");
449#endif
450                goto ERROR1;
451        }
452
453        /*
454         * Register a new directory entry.
455         */
456
457        if ((err = i2c_register_entry(new_client, type_name,
458             lm90_dir_table_template, THIS_MODULE)) < 0)
459        {
460#ifdef DEBUG
461                printk("lm90.o: Failed registering directory entry.\n");
462#endif
463                goto ERROR2;
464        }
465        data->sysctl_id = err;
466
467        /*
468         * Initialize the LM90 chip.
469         */
470
471        lm90_init_client(new_client);
472        return 0;
473
474        ERROR2:
475        i2c_detach_client(new_client);
476        ERROR1:
477        kfree(data);
478        return err;
479}
480
481static void lm90_init_client(struct i2c_client *client)
482{
483        u8 config;
484
485        /*
486         * Start the conversions.
487         */
488
489        i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE,
490                5); /* 2 Hz */
491        config = i2c_smbus_read_byte_data(client, LM90_REG_R_CONFIG1);
492        if (config & 0x40)
493                i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,
494                        config & 0xBF); /* run */
495}
496
497
498static int lm90_detach_client(struct i2c_client *client)
499{
500        int err;
501
502        i2c_deregister_entry(((struct lm90_data *) (client->data))->sysctl_id);
503        if ((err = i2c_detach_client(client)))
504        {
505                printk("lm90.o: Client deregistration failed, client not "
506                       "detached.\n");
507                return err;
508        }
509
510        kfree(client->data);
511        return 0;
512}
513
514static void lm90_update_client(struct i2c_client *client)
515{
516        struct lm90_data *data = client->data;
517
518        down(&data->update_lock);
519
520        if ((jiffies - data->last_updated > HZ * 2) ||
521            (jiffies < data->last_updated) || !data->valid)
522        {
523                u8 oldh, newh;
524#ifdef DEBUG
525                printk("lm90.o: Updating data.\n");
526#endif
527
528                data->local_temp =
529                        i2c_smbus_read_byte_data(client, LM90_REG_R_LOCAL_TEMP);
530                data->local_high =
531                        i2c_smbus_read_byte_data(client, LM90_REG_R_LOCAL_HIGH);
532                data->local_low =
533                        i2c_smbus_read_byte_data(client, LM90_REG_R_LOCAL_LOW);
534                data->local_crit =
535                        i2c_smbus_read_byte_data(client, LM90_REG_R_LOCAL_CRIT);
536
537                /*
538                 * There is a trick here. We have to read two registers to
539                 * have the remote sensor temperature, but we have to beware
540                 * a conversion could occur inbetween the readings. The
541                 * datasheet says we should either use the one-shot
542                 * conversion register, which we don't want to do (disables
543                 * hardware monitoring) or monitor the busy bit, which is
544                 * impossible (we can't read the values and monitor that bit
545                 * at the exact same time). So the solution used here is to
546                 * read the high byte once, then the low byte, then the high
547                 * byte again. If the new high byte matches the old one,
548                 * then we have a valid reading. Else we have to read the low
549                 * byte again, and now we believe we have a correct reading.
550                 */
551
552                oldh =
553                        i2c_smbus_read_byte_data(client, LM90_REG_R_REMOTE_TEMPH);
554                data->remote_temp =
555                        i2c_smbus_read_byte_data(client, LM90_REG_R_REMOTE_TEMPL);
556                newh =
557                        i2c_smbus_read_byte_data(client, LM90_REG_R_REMOTE_TEMPH);
558                if (newh != oldh)
559                {
560                        data->remote_temp =
561                                i2c_smbus_read_byte_data(client, LM90_REG_R_REMOTE_TEMPL);
562#ifdef DEBUG
563                        oldh = /* actually newer */
564                                i2c_smbus_read_byte_data(client, LM90_REG_R_REMOTE_TEMPH);
565                        if (newh != oldh)
566                                printk("lm90.o: Remote temperature may be wrong.\n");
567#endif
568                }
569                data->remote_temp |= (newh << 8);
570                data->remote_high =
571                        (i2c_smbus_read_byte_data(client, LM90_REG_R_REMOTE_HIGHH) << 8)
572                        + i2c_smbus_read_byte_data(client, LM90_REG_R_REMOTE_HIGHL);
573                data->remote_low =
574                        (i2c_smbus_read_byte_data(client, LM90_REG_R_REMOTE_LOWH) << 8)
575                        + i2c_smbus_read_byte_data(client, LM90_REG_R_REMOTE_LOWL);
576                data->remote_crit =
577                        i2c_smbus_read_byte_data(client, LM90_REG_R_REMOTE_CRIT);
578
579                data->hyst =
580                        i2c_smbus_read_byte_data(client, LM90_REG_R_TCRIT_HYST);
581                data->alarms =
582                        i2c_smbus_read_byte_data(client, LM90_REG_R_STATUS);
583
584                data->last_updated = jiffies;
585                data->valid = 1;
586        }
587
588        up(&data->update_lock);
589}
590
591static void lm90_local_temp(struct i2c_client *client, int operation,
592        int ctl_name, int *nrels_mag, long *results)
593{
594        struct lm90_data *data = client->data;
595
596        if (operation == SENSORS_PROC_REAL_INFO)
597                *nrels_mag = 0; /* magnitude */
598        else if (operation == SENSORS_PROC_REAL_READ)
599        {
600                lm90_update_client(client);
601                results[0] = TEMP1_FROM_REG(data->local_high);
602                results[1] = TEMP1_FROM_REG(data->local_low);
603                results[2] = TEMP1_FROM_REG(data->local_temp);
604                *nrels_mag = 3;
605        }
606        else if (operation == SENSORS_PROC_REAL_WRITE)
607        {
608                if (*nrels_mag >= 1)
609                {
610                        data->local_high = TEMP1_TO_REG(results[0]);
611                        i2c_smbus_write_byte_data(client, LM90_REG_W_LOCAL_HIGH,
612                                data->local_high);
613                }
614                if (*nrels_mag >= 2)
615                {
616                        data->local_low = TEMP1_TO_REG(results[1]);
617                        i2c_smbus_write_byte_data(client, LM90_REG_W_LOCAL_LOW,
618                                data->local_low);
619                }
620        }
621}
622
623static void lm90_remote_temp(struct i2c_client *client, int operation,
624        int ctl_name, int *nrels_mag, long *results)
625{
626        struct lm90_data *data = client->data;
627
628        if (operation == SENSORS_PROC_REAL_INFO)
629                *nrels_mag = 1; /* magnitude */
630        else if (operation == SENSORS_PROC_REAL_READ)
631        {
632                lm90_update_client(client);
633                results[0] = TEMP2_FROM_REG(data->remote_high);
634                results[1] = TEMP2_FROM_REG(data->remote_low);
635                results[2] = TEMP2_FROM_REG(data->remote_temp);
636                *nrels_mag = 3;
637        }
638        else if (operation == SENSORS_PROC_REAL_WRITE)
639        {
640                if (*nrels_mag >= 1)
641                {
642                        data->remote_high = TEMP2_TO_REG(results[0]);
643                        i2c_smbus_write_byte_data(client, LM90_REG_W_REMOTE_HIGHH,
644                                data->remote_high >> 8);
645                        i2c_smbus_write_byte_data(client, LM90_REG_W_REMOTE_HIGHL,
646                                data->remote_high & 0xFF);
647                }
648                if (*nrels_mag >= 2)
649                {
650                        data->remote_low = TEMP2_TO_REG(results[1]);
651                        i2c_smbus_write_byte_data(client, LM90_REG_W_REMOTE_LOWH,
652                                data->remote_low >> 8);
653                        i2c_smbus_write_byte_data(client, LM90_REG_W_REMOTE_LOWL,
654                                data->remote_low & 0xFF);
655                }
656        }
657}
658
659static void lm90_local_tcrit(struct i2c_client *client, int operation,
660        int ctl_name, int *nrels_mag, long *results)
661{
662        struct lm90_data *data = client->data;
663
664        if (operation == SENSORS_PROC_REAL_INFO)
665                *nrels_mag = 0; /* magnitude */
666        else if (operation == SENSORS_PROC_REAL_READ)
667        {
668                lm90_update_client(client);
669                results[0] = TEMP1_FROM_REG(data->local_crit);
670                *nrels_mag = 1;
671        }
672        else if (operation == SENSORS_PROC_REAL_WRITE)
673        {
674                if (*nrels_mag >= 1)
675                {
676                        data->local_crit = TEMP1_TO_REG(results[0]);
677                        i2c_smbus_write_byte_data(client, LM90_REG_W_LOCAL_CRIT,
678                                data->local_crit);
679                }
680        }
681}
682
683static void lm90_remote_tcrit(struct i2c_client *client, int operation,
684        int ctl_name, int *nrels_mag, long *results)
685{
686        struct lm90_data *data = client->data;
687
688        if (operation == SENSORS_PROC_REAL_INFO)
689                *nrels_mag = 0; /* magnitude */
690        else if (operation == SENSORS_PROC_REAL_READ)
691        {
692                lm90_update_client(client);
693                results[0] = TEMP1_FROM_REG(data->remote_crit);
694                *nrels_mag = 1;
695        }
696        else if (operation == SENSORS_PROC_REAL_WRITE)
697        {
698                if (*nrels_mag >= 1)
699                {
700                        data->remote_crit = TEMP1_TO_REG(results[0]);
701                        i2c_smbus_write_byte_data(client, LM90_REG_W_REMOTE_CRIT,
702                                data->remote_crit);
703                }
704        }
705}
706
707/*
708 * One quick note about hysteresis. Internally, the hysteresis value
709 * is held in a single register by the LM90, as a relative value.
710 * This relative value applies to both the local critical temperature
711 * and the remote critical temperature. Since all temperatures exported
712 * through procfs have to be absolute, we have to do some conversions.
713 * The solution retained here is to export two absolute values, one for
714 * each critical temperature. In order not to confuse the users too
715 * much, only one file is writable. Would we fail to do so, users
716 * would probably attempt to write to both files, as if they were
717 * independant, and since they aren't, they wouldn't understand why
718 * setting one affects the other one (and would probably claim there's
719 * a bug in the driver).
720 */
721
722static void lm90_local_hyst(struct i2c_client *client, int operation,
723        int ctl_name, int *nrels_mag, long *results)
724{
725        struct lm90_data *data = client->data;
726
727        if (operation == SENSORS_PROC_REAL_INFO)
728                *nrels_mag = 0; /* magnitude */
729        else if (operation == SENSORS_PROC_REAL_READ)
730        {
731                lm90_update_client(client);
732                results[0] = TEMP1_FROM_REG(data->local_crit) -
733                        TEMP1_FROM_REG(data->hyst);
734                *nrels_mag = 1;
735        }
736        else if (operation == SENSORS_PROC_REAL_WRITE)
737        {
738                if (*nrels_mag >= 1)
739                {
740                        data->hyst = HYST_TO_REG(data->local_crit - results[0]);
741                        i2c_smbus_write_byte_data(client, LM90_REG_W_TCRIT_HYST,
742                                data->hyst);
743                }
744        }
745}
746
747static void lm90_remote_hyst(struct i2c_client *client, int operation,
748        int ctl_name, int *nrels_mag, long *results)
749{
750        struct lm90_data *data = client->data;
751
752        if (operation == SENSORS_PROC_REAL_INFO)
753                *nrels_mag = 0; /* magnitude */
754        else if (operation == SENSORS_PROC_REAL_READ)
755        {
756                lm90_update_client(client);
757                results[0] = TEMP1_FROM_REG(data->remote_crit) -
758                        TEMP1_FROM_REG(data->hyst);
759                *nrels_mag = 1;
760        }
761}
762
763static void lm90_alarms(struct i2c_client *client, int operation,
764        int ctl_name, int *nrels_mag, long *results)
765{
766        struct lm90_data *data = client->data;
767
768        if (operation == SENSORS_PROC_REAL_INFO)
769                *nrels_mag = 0; /* magnitude */
770        else if (operation == SENSORS_PROC_REAL_READ)
771        {
772                lm90_update_client(client);
773                results[0] = data->alarms;
774                *nrels_mag = 1;
775        }
776}
777
778static int __init sm_lm90_init(void)
779{
780        printk(KERN_INFO "lm90.o version %s (%s)\n", LM_VERSION, LM_DATE);
781        return i2c_add_driver(&lm90_driver);
782}
783
784static void __exit sm_lm90_exit(void)
785{
786        i2c_del_driver(&lm90_driver);
787}
788
789MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
790MODULE_DESCRIPTION("LM90/ADM1032 sensor driver");
791MODULE_LICENSE("GPL");
792
793module_init(sm_lm90_init);
794module_exit(sm_lm90_exit);
Note: See TracBrowser for help on using the browser.