root/lm-sensors/trunk/kernel/chips/adm1024.c @ 2445

Revision 2445, 25.0 KB (checked in by khali, 9 years ago)

Backport memory allocation reworking from Linux 2.6.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*
2    adm1024.c - Part of lm_sensors, Linux kernel modules for hardware
3             monitoring
4    Add by Ken Bowley <ken@opnix.com> from the adm1025.c written by
5    Gordon Wu <gwu@esoft.com> and from adm9240.c written by
6    Copyright (c) 1999  Frodo Looijaard <frodol@dds.nl>
7    and Philip Edelbrock <phil@netroedge.com>
8
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 2 of the License, or
12    (at your option) any later version.
13
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22*/
23
24/* Supports the Analog Devices ADM1024. See doc/chips/adm1024 for details */
25
26#include <linux/module.h>
27#include <linux/slab.h>
28#include <linux/i2c.h>
29#include <linux/i2c-proc.h>
30#include <linux/init.h>
31#include "version.h"
32
33/* Addresses to scan */
34static unsigned short normal_i2c[] = { SENSORS_I2C_END };
35static unsigned short normal_i2c_range[] = { 0x2c, 0x2e, SENSORS_I2C_END };
36static unsigned int normal_isa[] = { SENSORS_ISA_END };
37static unsigned int normal_isa_range[] = { SENSORS_ISA_END };
38
39/* Insmod parameters */
40SENSORS_INSMOD_1(adm1024);
41
42/* Many ADM1024 constants specified below */
43
44#define ADM1024_REG_IN_MAX(nr) (0x2b + (nr) * 2)
45#define ADM1024_REG_IN_MIN(nr) (0x2c + (nr) * 2)
46#define ADM1024_REG_IN(nr) (0x20 + (nr))
47
48/* The ADM1024 registers */
49#define ADM1024_REG_INT_TEMP_TRIP_SET 0x13
50#define ADM1024_REG_EXT_TEMP_TRIP_SET 0x14
51#define ADM1024_REG_TEST 0x15
52#define ADM1024_REG_CHANNEL_MODE 0x16
53#define ADM1024_REG_INT_TEMP_TRIP 0x17  /* read only */
54#define ADM1024_REG_EXT_TEMP_TRIP 0x18  /* read only */
55#define ADM1024_REG_ANALOG_OUT 0x19
56#define ADM1024_REG_AIN1_LOW_LIMIT 0x1A
57#define ADM1024_REG_AIN2_LOW_LIMIT 0x1B
58/* These are all read-only */
59#define ADM1024_REG_2_5V 0x20   /* 2.5V Measured Value/EXT Temp 2 */
60#define ADM1024_REG_VCCP1 0x21
61#define ADM1024_REG_3_3V 0x22   /* VCC Measured Value */
62#define ADM1024_REG_5V 0x23
63#define ADM1024_REG_12V 0x24
64#define ADM1024_REG_VCCP2 0x25
65#define ADM1024_REG_EXT_TEMP1 0x26
66#define ADM1024_REG_TEMP 0x27
67#define ADM1024_REG_FAN1 0x28   /* FAN1/AIN1 Value */
68#define ADM1024_REG_FAN2 0x29   /* FAN2/AIN2 Value */
69#define ADM1024_REG_COMPANY_ID 0x3E     /* 0x41 for ADM1024 */
70#define ADM1024_REG_DIE_REV 0x3F
71/* These are read/write */
72#define ADM1024_REG_2_5V_HIGH 0x2B      /* 2.5V/Ext Temp2 High Limit */
73#define ADM1024_REG_2_5V_LOW 0x2C       /* 2.5V/Ext Temp2 Low Limit */
74#define ADM1024_REG_VCCP1_HIGH 0x2D
75#define ADM1024_REG_VCCP1_LOW 0x2E
76#define ADM1024_REG_3_3V_HIGH 0x2F      /* VCC High Limit */
77#define ADM1024_REG_3_3V_LOW 0x30       /* VCC Low Limit */
78#define ADM1024_REG_5V_HIGH 0x31
79#define ADM1024_REG_5V_LOW 0x32
80#define ADM1024_REG_12V_HIGH 0x33
81#define ADM1024_REG_12V_LOW 0x34
82#define ADM1024_REG_VCCP2_HIGH 0x35
83#define ADM1024_REG_VCCP2_LOW 0x36
84#define ADM1024_REG_EXT_TEMP1_HIGH 0x37
85#define ADM1024_REG_EXT_TEMP1_LOW 0x38
86#define ADM1024_REG_TOS 0x39
87#define ADM1024_REG_THYST 0x3A
88#define ADM1024_REG_FAN1_MIN 0x3B
89#define ADM1024_REG_FAN2_MIN 0x3C
90
91#define ADM1024_REG_CONFIG 0x40
92#define ADM1024_REG_INT1_STAT 0x41
93#define ADM1024_REG_INT2_STAT 0x42
94#define ADM1024_REG_INT1_MASK 0x43
95#define ADM1024_REG_INT2_MASK 0x44
96
97#define ADM1024_REG_CHASSIS_CLEAR 0x46
98#define ADM1024_REG_VID_FAN_DIV 0x47
99#define ADM1024_REG_I2C_ADDR 0x48
100#define ADM1024_REG_VID4 0x49
101#define ADM1024_REG_CONFIG2 0x4A
102#define ADM1024_REG_TEMP_CONFIG 0x4B
103#define ADM1024_REG_EXTMODE1 0x4C       /* Interupt Status Register Mirror No. 1 */
104#define ADM1024_REG_EXTMODE2 0x4D       /* Interupt Status Register Mirror No. 2 */
105
106/* Conversions. Rounding and limit checking is only done on the TO_REG
107   variants. Note that you should be a bit careful with which arguments
108   these macros are called: arguments may be evaluated more than once.
109   Fixing this is just not worth it. */
110#define IN_TO_REG(val,nr) (SENSORS_LIMIT(((val) & 0xff),0,255))
111#define IN_FROM_REG(val,nr) (val)
112
113static inline u8 FAN_TO_REG(long rpm, int div)
114{
115        if (rpm == 0)
116                return 255;
117        rpm = SENSORS_LIMIT(rpm, 1, 1000000);
118        return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1,
119                             254);
120}
121
122#define FAN_FROM_REG(val,div) ((val)==0?-1:\
123                               (val)==255?0:1350000/((div)*(val)))
124
125#define TEMP_FROM_REG(temp) \
126   ((temp)<256?((((temp)&0x1fe) >> 1) * 10)      + ((temp) & 1) * 5:  \
127               ((((temp)&0x1fe) >> 1) -255) * 10 - ((temp) & 1) * 5)  \
128
129#define EXT_TEMP_FROM_REG(temp) (((temp)>0x80?(temp)-0x100:(temp))*10)
130   
131
132#define TEMP_LIMIT_FROM_REG(val) (((val)>0x80?(val)-0x100:(val))*10)
133
134#define TEMP_LIMIT_TO_REG(val) SENSORS_LIMIT(((val)<0?(((val)-5)/10):\
135                                                      ((val)+5)/10), \
136                                             0,255)
137
138#define ALARMS_FROM_REG(val) (val)
139
140#define DIV_FROM_REG(val) (1 << (val))
141#define DIV_TO_REG(val) ((val)==1?0:((val)==8?3:((val)==4?2:1)))
142
143#define VID_FROM_REG(val) ((val)==0x1f?0:(val)>=0x10?510-(val)*10:\
144                           205-(val)*5)
145
146/* For each registered ADM1024, we need to keep some data in memory. That
147   data is pointed to by adm1024_list[NR]->data. The structure itself is
148   dynamically allocated, at the same time when a new adm1024 client is
149   allocated. */
150struct adm1024_data {
151        struct i2c_client client;
152        int sysctl_id;
153        enum chips type;
154
155        struct semaphore update_lock;
156        char valid;             /* !=0 if following fields are valid */
157        unsigned long last_updated;     /* In jiffies */
158
159        u8 in[6];               /* Register value */
160        u8 in_max[6];           /* Register value */
161        u8 in_min[6];           /* Register value */
162        u8 fan[2];              /* Register value */
163        u8 fan_min[2];          /* Register value */
164        u8 fan_div[2];          /* Register encoding, shifted right */
165        int temp;               /* Temp, shifted right */
166        u8 temp_os_max;         /* Register value */
167        u8 temp_os_hyst;        /* Register value */
168        int temp1;              /* Ext Temp 1 */
169        u8 temp1_os_max;
170        u8 temp1_os_hyst;
171        int temp2;              /* Ext Temp 2 */
172        u8 temp2_os_max;
173        u8 temp2_os_hyst;
174        u16 alarms;             /* Register encoding, combined */
175        u8 analog_out;          /* Register value */
176        u8 vid;                 /* Register value combined */
177};
178
179
180
181static int adm1024_attach_adapter(struct i2c_adapter *adapter);
182static int adm1024_detect(struct i2c_adapter *adapter, int address,
183                          unsigned short flags, int kind);
184static int adm1024_detach_client(struct i2c_client *client);
185
186static int adm1024_read_value(struct i2c_client *client, u8 register);
187static int adm1024_write_value(struct i2c_client *client, u8 register,
188                               u8 value);
189static void adm1024_update_client(struct i2c_client *client);
190static void adm1024_init_client(struct i2c_client *client);
191
192
193static void adm1024_in(struct i2c_client *client, int operation,
194                       int ctl_name, int *nrels_mag, long *results);
195static void adm1024_fan(struct i2c_client *client, int operation,
196                        int ctl_name, int *nrels_mag, long *results);
197static void adm1024_temp(struct i2c_client *client, int operation,
198                         int ctl_name, int *nrels_mag, long *results);
199static void adm1024_temp1(struct i2c_client *client, int operation,
200                         int ctl_name, int *nrels_mag, long *results);
201static void adm1024_temp2(struct i2c_client *client, int operation,
202                         int ctl_name, int *nrels_mag, long *results);
203static void adm1024_alarms(struct i2c_client *client, int operation,
204                           int ctl_name, int *nrels_mag, long *results);
205static void adm1024_fan_div(struct i2c_client *client, int operation,
206                            int ctl_name, int *nrels_mag, long *results);
207static void adm1024_analog_out(struct i2c_client *client, int operation,
208                               int ctl_name, int *nrels_mag,
209                               long *results);
210static void adm1024_vid(struct i2c_client *client, int operation,
211                        int ctl_name, int *nrels_mag, long *results);
212
213static int adm1024_id = 0;
214
215static struct i2c_driver adm1024_driver = {
216        .owner          = THIS_MODULE,
217        .name           = "ADM1024 sensor driver",
218        .id             = I2C_DRIVERID_ADM1024,
219        .flags          = I2C_DF_NOTIFY,
220        .attach_adapter = adm1024_attach_adapter,
221        .detach_client  = adm1024_detach_client,
222};
223
224/* The /proc/sys entries */
225/* -- SENSORS SYSCTL START -- */
226
227#define ADM1024_SYSCTL_IN0 1000 /* Volts * 100 */
228#define ADM1024_SYSCTL_IN1 1001
229#define ADM1024_SYSCTL_IN2 1002
230#define ADM1024_SYSCTL_IN3 1003
231#define ADM1024_SYSCTL_IN4 1004
232#define ADM1024_SYSCTL_IN5 1005
233#define ADM1024_SYSCTL_FAN1 1101        /* Rotations/min */
234#define ADM1024_SYSCTL_FAN2 1102
235#define ADM1024_SYSCTL_TEMP 1250        /* Degrees Celcius * 100 */
236#define ADM1024_SYSCTL_TEMP1 1290       /* Degrees Celcius */
237#define ADM1024_SYSCTL_TEMP2 1295       /* Degrees Celcius */
238#define ADM1024_SYSCTL_FAN_DIV 2000     /* 1, 2, 4 or 8 */
239#define ADM1024_SYSCTL_ALARMS 2001      /* bitvector */
240#define ADM1024_SYSCTL_ANALOG_OUT 2002
241#define ADM1024_SYSCTL_VID 2003
242
243#define ADM1024_ALARM_IN0 0x0001
244#define ADM1024_ALARM_IN1 0x0002
245#define ADM1024_ALARM_IN2 0x0004
246#define ADM1024_ALARM_IN3 0x0008
247#define ADM1024_ALARM_IN4 0x0100
248#define ADM1024_ALARM_IN5 0x0200
249#define ADM1024_ALARM_FAN1 0x0040
250#define ADM1024_ALARM_FAN2 0x0080
251#define ADM1024_ALARM_TEMP 0x0010
252#define ADM1024_ALARM_TEMP1 0x0020
253#define ADM1024_ALARM_TEMP2 0x0001
254#define ADM1024_ALARM_CHAS 0x1000
255
256/* -- SENSORS SYSCTL END -- */
257
258/* These files are created for each detected ADM1024. This is just a template;
259   though at first sight, you might think we could use a statically
260   allocated list, we need some way to get back to the parent - which
261   is done through one of the 'extra' fields which are initialized
262   when a new copy is allocated. */
263static ctl_table adm1024_dir_table_template[] = {
264        {ADM1024_SYSCTL_IN0, "in0", NULL, 0, 0644, NULL, &i2c_proc_real,
265         &i2c_sysctl_real, NULL, &adm1024_in},
266        {ADM1024_SYSCTL_IN1, "in1", NULL, 0, 0644, NULL, &i2c_proc_real,
267         &i2c_sysctl_real, NULL, &adm1024_in},
268        {ADM1024_SYSCTL_IN2, "in2", NULL, 0, 0644, NULL, &i2c_proc_real,
269         &i2c_sysctl_real, NULL, &adm1024_in},
270        {ADM1024_SYSCTL_IN3, "in3", NULL, 0, 0644, NULL, &i2c_proc_real,
271         &i2c_sysctl_real, NULL, &adm1024_in},
272        {ADM1024_SYSCTL_IN4, "in4", NULL, 0, 0644, NULL, &i2c_proc_real,
273         &i2c_sysctl_real, NULL, &adm1024_in},
274        {ADM1024_SYSCTL_IN5, "in5", NULL, 0, 0644, NULL, &i2c_proc_real,
275         &i2c_sysctl_real, NULL, &adm1024_in},
276        {ADM1024_SYSCTL_FAN1, "fan1", NULL, 0, 0644, NULL, &i2c_proc_real,
277         &i2c_sysctl_real, NULL, &adm1024_fan},
278        {ADM1024_SYSCTL_FAN2, "fan2", NULL, 0, 0644, NULL, &i2c_proc_real,
279         &i2c_sysctl_real, NULL, &adm1024_fan},
280        {ADM1024_SYSCTL_TEMP, "temp1", NULL, 0, 0644, NULL, &i2c_proc_real,
281         &i2c_sysctl_real, NULL, &adm1024_temp},
282        {ADM1024_SYSCTL_TEMP1, "temp2", NULL, 0, 0644, NULL, &i2c_proc_real,
283         &i2c_sysctl_real, NULL, &adm1024_temp1},
284        {ADM1024_SYSCTL_TEMP2, "temp3", NULL, 0, 0644, NULL, &i2c_proc_real,
285         &i2c_sysctl_real, NULL, &adm1024_temp2},
286        {ADM1024_SYSCTL_FAN_DIV, "fan_div", NULL, 0, 0644, NULL, &i2c_proc_real,
287         &i2c_sysctl_real, NULL, &adm1024_fan_div},
288        {ADM1024_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &i2c_proc_real,
289         &i2c_sysctl_real, NULL, &adm1024_alarms},
290        {ADM1024_SYSCTL_ANALOG_OUT, "analog_out", NULL, 0, 0644, NULL, &i2c_proc_real,
291         &i2c_sysctl_real, NULL, &adm1024_analog_out},
292        {ADM1024_SYSCTL_VID, "vid", NULL, 0, 0444, NULL, &i2c_proc_real,
293         &i2c_sysctl_real, NULL, &adm1024_vid},
294        {0}
295};
296
297static int adm1024_attach_adapter(struct i2c_adapter *adapter)
298{
299        return i2c_detect(adapter, &addr_data, adm1024_detect);
300}
301
302static int adm1024_detect(struct i2c_adapter *adapter, int address,
303                          unsigned short flags, int kind)
304{
305        int i;
306        struct i2c_client *new_client;
307        struct adm1024_data *data;
308        int err = 0;
309        const char *type_name = "";
310        const char *client_name = "";
311
312        /* Make sure we aren't probing the ISA bus!! This is just a safety check
313           at this moment; i2c_detect really won't call us. */
314#ifdef DEBUG
315        if (i2c_is_isa_adapter(adapter)) {
316                printk
317                    ("adm1024.o: adm1024_detect called for an ISA bus adapter?!?\n");
318                return 0;
319        }
320#endif
321
322        if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
323                goto ERROR0;
324
325        /* OK. For now, we presume we have a valid client. We now create the
326           client structure, even though we cannot fill it completely yet.
327           But it allows us to access adm1024_{read,write}_value. */
328
329        if (!(data = kmalloc(sizeof(struct adm1024_data), GFP_KERNEL))) {
330                err = -ENOMEM;
331                goto ERROR0;
332        }
333
334        new_client = &data->client;
335        new_client->addr = address;
336        new_client->data = data;
337        new_client->adapter = adapter;
338        new_client->driver = &adm1024_driver;
339        new_client->flags = 0;
340
341        /* Now, we do the remaining detection. */
342
343        if (kind < 0) {
344                if((adm1024_read_value(new_client, ADM1024_REG_CONFIG) & 0x80) != 0x00)
345                        goto ERROR1;
346        }
347
348        /* Determine the chip type. */
349        if (kind <= 0) {
350                i = adm1024_read_value(new_client, ADM1024_REG_COMPANY_ID);
351                if (i == 0x41)
352                        kind = adm1024;
353                else {
354                        if (kind == 0)
355                                printk
356                                    ("adm1024.o: Ignoring 'force' parameter for unknown chip at "
357                                     "adapter %d, address 0x%02x\n",
358                                     i2c_adapter_id(adapter), address);
359                        goto ERROR1;
360                }
361        }
362
363        if (kind == adm1024) {
364                type_name = "adm1024";
365                client_name = "ADM1024 chip";
366        } else {
367#ifdef DEBUG
368                printk("adm1024.o: Internal error: unknown kind (%d)?!?",
369                       kind);
370#endif
371                goto ERROR1;
372        }
373
374        /* Fill in the remaining client fields and put it into the global list */
375        strcpy(new_client->name, client_name);
376        data->type = kind;
377
378        new_client->id = adm1024_id++;
379        data->valid = 0;
380        init_MUTEX(&data->update_lock);
381
382        /* Tell the I2C layer a new client has arrived */
383        if ((err = i2c_attach_client(new_client)))
384                goto ERROR3;
385
386        /* Register a new directory entry with module sensors */
387        if ((i = i2c_register_entry(new_client,
388                                        type_name,
389                                        adm1024_dir_table_template)) < 0) {
390                err = i;
391                goto ERROR4;
392        }
393        data->sysctl_id = i;
394
395        /* Initialize the ADM1024 chip */
396        adm1024_init_client(new_client);
397        return 0;
398
399/* OK, this is not exactly good programming practice, usually. But it is
400   very code-efficient in this case. */
401
402      ERROR4:
403        i2c_detach_client(new_client);
404      ERROR3:
405      ERROR1:
406        kfree(data);
407      ERROR0:
408        return err;
409}
410
411static int adm1024_detach_client(struct i2c_client *client)
412{
413        int err;
414
415        i2c_deregister_entry(((struct adm1024_data *) (client->data))->
416                                 sysctl_id);
417
418        if ((err = i2c_detach_client(client))) {
419                printk
420                    ("adm1024.o: Client deregistration failed, client not detached.\n");
421                return err;
422        }
423
424        kfree(client->data);
425
426        return 0;
427}
428
429static int adm1024_read_value(struct i2c_client *client, u8 reg)
430{
431        return 0xFF & i2c_smbus_read_byte_data(client, reg);
432}
433
434static int adm1024_write_value(struct i2c_client *client, u8 reg, u8 value)
435{
436        return i2c_smbus_write_byte_data(client, reg, value);
437}
438
439static void adm1024_init_client(struct i2c_client *client)
440{
441        /* Enable temperature channel 2 */
442        adm1024_write_value(client, ADM1024_REG_CHANNEL_MODE, adm1024_read_value(client, ADM1024_REG_CHANNEL_MODE) | 0x04);
443
444        /* Start monitoring */
445        adm1024_write_value(client, ADM1024_REG_CONFIG, 0x07);
446}
447
448static void adm1024_update_client(struct i2c_client *client)
449{
450        struct adm1024_data *data = client->data;
451        u8 i;
452
453        down(&data->update_lock);
454
455        if (
456            (jiffies - data->last_updated >
457             (data->type == adm1024 ? HZ / 2 : HZ * 2))
458            || (jiffies < data->last_updated) || !data->valid) {
459
460#ifdef DEBUG
461                printk("Starting adm1024 update\n");
462#endif
463                for (i = 0; i <= 5; i++) {
464                        data->in[i] =
465                            adm1024_read_value(client, ADM1024_REG_IN(i));
466                        data->in_min[i] =
467                            adm1024_read_value(client,
468                                               ADM1024_REG_IN_MIN(i));
469                        data->in_max[i] =
470                            adm1024_read_value(client,
471                                               ADM1024_REG_IN_MAX(i));
472                }
473                data->fan[0] =
474                    adm1024_read_value(client, ADM1024_REG_FAN1);
475                data->fan_min[0] =
476                    adm1024_read_value(client, ADM1024_REG_FAN1_MIN);
477                data->fan[1] =
478                    adm1024_read_value(client, ADM1024_REG_FAN2);
479                data->fan_min[1] =
480                    adm1024_read_value(client, ADM1024_REG_FAN2_MIN);
481                data->temp =
482                    (adm1024_read_value(client, ADM1024_REG_TEMP) << 1) +
483                    ((adm1024_read_value
484                      (client, ADM1024_REG_TEMP_CONFIG) & 0x80) >> 7);
485                data->temp_os_max =
486                    adm1024_read_value(client, ADM1024_REG_TOS);
487                data->temp_os_hyst =
488                    adm1024_read_value(client, ADM1024_REG_THYST);
489                data->temp1 =
490                    adm1024_read_value(client, ADM1024_REG_EXT_TEMP1);
491                data->temp1_os_max =
492                    adm1024_read_value(client, ADM1024_REG_EXT_TEMP1_HIGH);
493                data->temp1_os_hyst =
494                    adm1024_read_value(client, ADM1024_REG_EXT_TEMP1_LOW);
495                data->temp2 =
496                    adm1024_read_value(client, ADM1024_REG_2_5V);
497                data->temp2_os_max =
498                    adm1024_read_value(client, ADM1024_REG_2_5V_HIGH);
499                data->temp2_os_hyst =
500                    adm1024_read_value(client, ADM1024_REG_2_5V_LOW);
501
502                i = adm1024_read_value(client, ADM1024_REG_VID_FAN_DIV);
503                data->fan_div[0] = (i >> 4) & 0x03;
504                data->fan_div[1] = (i >> 6) & 0x03;
505                data->vid = i & 0x0f;
506                data->vid |=
507                    (adm1024_read_value(client, ADM1024_REG_VID4) & 0x01)
508                    << 4;
509
510                data->alarms =
511                    adm1024_read_value(client,
512                                       ADM1024_REG_INT1_STAT) +
513                    (adm1024_read_value(client, ADM1024_REG_INT2_STAT) <<
514                     8);
515                data->analog_out =
516                    adm1024_read_value(client, ADM1024_REG_ANALOG_OUT);
517                data->last_updated = jiffies;
518                data->valid = 1;
519        }
520
521        up(&data->update_lock);
522}
523
524
525/* The next few functions are the call-back functions of the /proc/sys and
526   sysctl files. Which function is used is defined in the ctl_table in
527   the extra1 field.
528   Each function must return the magnitude (power of 10 to divide the date
529   with) if it is called with operation==SENSORS_PROC_REAL_INFO. It must
530   put a maximum of *nrels elements in results reflecting the data of this
531   file, and set *nrels to the number it actually put in it, if operation==
532   SENSORS_PROC_REAL_READ. Finally, it must get upto *nrels elements from
533   results and write them to the chip, if operations==SENSORS_PROC_REAL_WRITE.
534   Note that on SENSORS_PROC_REAL_READ, I do not check whether results is
535   large enough (by checking the incoming value of *nrels). This is not very
536   good practice, but as long as you put less than about 5 values in results,
537   you can assume it is large enough. */
538void adm1024_in(struct i2c_client *client, int operation, int ctl_name,
539                int *nrels_mag, long *results)
540{
541
542        int scales[6] = { 250, 225, 330, 500, 1200, 270 };
543
544        struct adm1024_data *data = client->data;
545        int nr = ctl_name - ADM1024_SYSCTL_IN0;
546
547        if (operation == SENSORS_PROC_REAL_INFO)
548                *nrels_mag = 2;
549        else if (operation == SENSORS_PROC_REAL_READ) {
550                adm1024_update_client(client);
551                results[0] =
552                    IN_FROM_REG(data->in_min[nr], nr) * scales[nr] / 192;
553                results[1] =
554                    IN_FROM_REG(data->in_max[nr], nr) * scales[nr] / 192;
555                results[2] =
556                    IN_FROM_REG(data->in[nr], nr) * scales[nr] / 192;
557                *nrels_mag = 3;
558        } else if (operation == SENSORS_PROC_REAL_WRITE) {
559                if (*nrels_mag >= 1) {
560                        data->in_min[nr] =
561                            IN_TO_REG((results[0] * 192) / scales[nr], nr);
562                        adm1024_write_value(client, ADM1024_REG_IN_MIN(nr),
563                                            data->in_min[nr]);
564                }
565                if (*nrels_mag >= 2) {
566                        data->in_max[nr] =
567                            IN_TO_REG((results[1] * 192) / scales[nr], nr);
568                        adm1024_write_value(client, ADM1024_REG_IN_MAX(nr),
569                                            data->in_max[nr]);
570                }
571        }
572}
573
574void adm1024_fan(struct i2c_client *client, int operation, int ctl_name,
575                 int *nrels_mag, long *results)
576{
577        struct adm1024_data *data = client->data;
578        int nr = ctl_name - ADM1024_SYSCTL_FAN1 + 1;
579
580        if (operation == SENSORS_PROC_REAL_INFO)
581                *nrels_mag = 0;
582        else if (operation == SENSORS_PROC_REAL_READ) {
583                adm1024_update_client(client);
584                results[0] = FAN_FROM_REG(data->fan_min[nr - 1],
585                                          DIV_FROM_REG(data->
586                                                       fan_div[nr - 1]));
587                results[1] =
588                    FAN_FROM_REG(data->fan[nr - 1],
589                                 DIV_FROM_REG(data->fan_div[nr - 1]));
590                *nrels_mag = 2;
591        } else if (operation == SENSORS_PROC_REAL_WRITE) {
592                if (*nrels_mag >= 1) {
593                        data->fan_min[nr - 1] = FAN_TO_REG(results[0],
594                                                           DIV_FROM_REG
595                                                           (data->
596                                                            fan_div[nr -
597                                                                    1]));
598                        adm1024_write_value(client,
599                                            nr ==
600                                            1 ? ADM1024_REG_FAN1_MIN :
601                                            ADM1024_REG_FAN2_MIN,
602                                            data->fan_min[nr - 1]);
603                }
604        }
605}
606
607
608void adm1024_temp(struct i2c_client *client, int operation, int ctl_name,
609                  int *nrels_mag, long *results)
610{
611        struct adm1024_data *data = client->data;
612        if (operation == SENSORS_PROC_REAL_INFO)
613                *nrels_mag = 1;
614        else if (operation == SENSORS_PROC_REAL_READ) {
615                adm1024_update_client(client);
616                results[0] = TEMP_LIMIT_FROM_REG(data->temp_os_max);
617                results[1] = TEMP_LIMIT_FROM_REG(data->temp_os_hyst);
618                results[2] = TEMP_FROM_REG(data->temp);
619                *nrels_mag = 3;
620        } else if (operation == SENSORS_PROC_REAL_WRITE) {
621                if (*nrels_mag >= 1) {
622                        data->temp_os_max = TEMP_LIMIT_TO_REG(results[0]);
623                        adm1024_write_value(client, ADM1024_REG_TOS,
624                                            data->temp_os_max);
625                }
626                if (*nrels_mag >= 2) {
627                        data->temp_os_hyst = TEMP_LIMIT_TO_REG(results[1]);
628                        adm1024_write_value(client, ADM1024_REG_THYST,
629                                            data->temp_os_hyst);
630                }
631        }
632}
633
634void adm1024_temp1(struct i2c_client *client, int operation, int ctl_name,
635                  int *nrels_mag, long *results)
636{
637        struct adm1024_data *data = client->data;
638        if (operation == SENSORS_PROC_REAL_INFO)
639                *nrels_mag = 1;
640        else if (operation == SENSORS_PROC_REAL_READ) {
641                adm1024_update_client(client);
642                results[0] = TEMP_LIMIT_FROM_REG(data->temp1_os_max);
643                results[1] = TEMP_LIMIT_FROM_REG(data->temp1_os_hyst);
644                results[2] = EXT_TEMP_FROM_REG(data->temp1);
645                *nrels_mag = 3;
646        } else if (operation == SENSORS_PROC_REAL_WRITE) {
647                if (*nrels_mag >= 1) {
648                        data->temp1_os_max = TEMP_LIMIT_TO_REG(results[0]);
649                        adm1024_write_value(client, ADM1024_REG_EXT_TEMP1_HIGH,
650                                            data->temp1_os_max);
651                }
652                if (*nrels_mag >= 2) {
653                        data->temp1_os_hyst = TEMP_LIMIT_TO_REG(results[1]);
654                        adm1024_write_value(client, ADM1024_REG_EXT_TEMP1_LOW,
655                                            data->temp1_os_hyst);
656                }
657        }
658}
659
660void adm1024_temp2(struct i2c_client *client, int operation, int ctl_name,
661                  int *nrels_mag, long *results)
662{
663        struct adm1024_data *data = client->data;
664        if (operation == SENSORS_PROC_REAL_INFO)
665                *nrels_mag = 1;
666        else if (operation == SENSORS_PROC_REAL_READ) {
667                adm1024_update_client(client);
668                results[0] = TEMP_LIMIT_FROM_REG(data->temp2_os_max);
669                results[1] = TEMP_LIMIT_FROM_REG(data->temp2_os_hyst);
670                results[2] = EXT_TEMP_FROM_REG(data->temp2);
671                *nrels_mag = 3;
672        } else if (operation == SENSORS_PROC_REAL_WRITE) {
673                if (*nrels_mag >= 1) {
674                        data->temp2_os_max = TEMP_LIMIT_TO_REG(results[0]);
675                        adm1024_write_value(client, ADM1024_REG_2_5V_HIGH,
676                                            data->temp2_os_max);
677                }
678                if (*nrels_mag >= 2) {
679                        data->temp2_os_hyst = TEMP_LIMIT_TO_REG(results[1]);
680                        adm1024_write_value(client, ADM1024_REG_2_5V_LOW,
681                                            data->temp2_os_hyst);
682                }
683        }
684}
685
686void adm1024_alarms(struct i2c_client *client, int operation, int ctl_name,
687                    int *nrels_mag, long *results)
688{
689        struct adm1024_data *data = client->data;
690        if (operation == SENSORS_PROC_REAL_INFO)
691                *nrels_mag = 0;
692        else if (operation == SENSORS_PROC_REAL_READ) {
693                adm1024_update_client(client);
694                results[0] = ALARMS_FROM_REG(data->alarms);
695                *nrels_mag = 1;
696        }
697}
698
699void adm1024_fan_div(struct i2c_client *client, int operation,
700                     int ctl_name, int *nrels_mag, long *results)
701{
702        struct adm1024_data *data = client->data;
703        int old;
704
705        if (operation == SENSORS_PROC_REAL_INFO)
706                *nrels_mag = 0;
707        else if (operation == SENSORS_PROC_REAL_READ) {
708                adm1024_update_client(client);
709                results[0] = DIV_FROM_REG(data->fan_div[0]);
710                results[1] = DIV_FROM_REG(data->fan_div[1]);
711                *nrels_mag = 2;
712        } else if (operation == SENSORS_PROC_REAL_WRITE) {
713                old = adm1024_read_value(client, ADM1024_REG_VID_FAN_DIV);
714                if (*nrels_mag >= 2) {
715                        data->fan_div[1] = DIV_TO_REG(results[1]);
716                        old = (old & 0x3f) | (data->fan_div[1] << 6);
717                }
718                if (*nrels_mag >= 1) {
719                        data->fan_div[0] = DIV_TO_REG(results[0]);
720                        old = (old & 0xcf) | (data->fan_div[0] << 4);
721                        adm1024_write_value(client,
722                                            ADM1024_REG_VID_FAN_DIV, old);
723                }
724        }
725}
726
727void adm1024_analog_out(struct i2c_client *client, int operation,
728                        int ctl_name, int *nrels_mag, long *results)
729{
730        struct adm1024_data *data = client->data;
731
732        if (operation == SENSORS_PROC_REAL_INFO)
733                *nrels_mag = 0;
734        else if (operation == SENSORS_PROC_REAL_READ) {
735                adm1024_update_client(client);
736                results[0] = data->analog_out;
737                *nrels_mag = 1;
738        } else if (operation == SENSORS_PROC_REAL_WRITE) {
739                if (*nrels_mag >= 1) {
740                        data->analog_out = results[0];
741                        adm1024_write_value(client, ADM1024_REG_ANALOG_OUT,
742                                            data->analog_out);
743                }
744        }
745}
746
747void adm1024_vid(struct i2c_client *client, int operation, int ctl_name,
748                 int *nrels_mag, long *results)
749{
750        struct adm1024_data *data = client->data;
751
752        if (operation == SENSORS_PROC_REAL_INFO)
753                *nrels_mag = 2;
754        else if (operation == SENSORS_PROC_REAL_READ) {
755                adm1024_update_client(client);
756                results[0] = VID_FROM_REG(data->vid);
757                *nrels_mag = 1;
758        }
759}
760
761static int __init sm_adm1024_init(void)
762{
763        printk("adm1024.o version %s (%s)\n", LM_VERSION, LM_DATE);
764        return i2c_add_driver(&adm1024_driver);
765}
766
767static void __exit sm_adm1024_exit(void)
768{
769        i2c_del_driver(&adm1024_driver);
770}
771
772
773
774MODULE_AUTHOR
775    ("Frodo Looijaard <frodol@dds.nl> and Philip Edelbrock <phil@netroedge.com>");
776MODULE_DESCRIPTION("ADM1024 driver");
777
778MODULE_LICENSE("GPL");
779
780module_init(sm_adm1024_init);
781module_exit(sm_adm1024_exit);
Note: See TracBrowser for help on using the browser.