root/lm-sensors/trunk/kernel/chips/sis5595.c @ 707

Revision 707, 23.5 KB (checked in by frodo, 13 years ago)

`indent -kr -i8' on all kernel sources

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*
2    sis5595.c - Part of lm_sensors, Linux kernel modules
3                for hardware monitoring
4               
5    Copyright (c) 1998, 1999  Frodo Looijaard <frodol@dds.nl>,
6                        Kyösti Mälkki <kmalkki@cc.hut.fi>
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21*/
22
23#include <linux/version.h>
24#include <linux/module.h>
25#include <linux/malloc.h>
26#include <linux/proc_fs.h>
27#include <linux/ioport.h>
28#include <linux/sysctl.h>
29#include <linux/pci.h>
30#include <asm/errno.h>
31#include <asm/io.h>
32#include <linux/types.h>
33#include <linux/i2c.h>
34#include "version.h"
35#include "i2c-isa.h"
36#include "sensors.h"
37#include <linux/init.h>
38
39
40#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1))
41#define init_MUTEX(s) do { *(s) = MUTEX; } while(0)
42#endif
43
44#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,13)
45#define THIS_MODULE NULL
46#endif
47
48/* Addresses to scan.
49   Note that we can't determine the ISA address until we have initialized
50   our module */
51static unsigned short normal_i2c[] = { SENSORS_I2C_END };
52static unsigned short normal_i2c_range[] = { SENSORS_I2C_END };
53static unsigned int normal_isa[] = { 0x0000, SENSORS_ISA_END };
54static unsigned int normal_isa_range[] = { SENSORS_ISA_END };
55
56/* Insmod parameters */
57SENSORS_INSMOD_1(sis5595);
58
59/*
60   SiS southbridge has a LM78-like chip integrated on the same IC.
61   This driver is a customized copy of lm78.c
62*/
63
64/* Many SIS5595 constants specified below */
65
66/* Length of ISA address segment */
67#define SIS5595_EXTENT 8
68#define SIS5595_BASE_REG 0x68
69
70/* Where are the ISA address/data registers relative to the base address */
71#define SIS5595_ADDR_REG_OFFSET 5
72#define SIS5595_DATA_REG_OFFSET 6
73
74/* The SIS5595 registers */
75#define SIS5595_REG_IN_MAX(nr) (0x2b + (nr) * 2)
76#define SIS5595_REG_IN_MIN(nr) (0x2c + (nr) * 2)
77#define SIS5595_REG_IN(nr) (0x20 + (nr))
78
79#define SIS5595_REG_FAN_MIN(nr) (0x3a + (nr))
80#define SIS5595_REG_FAN(nr) (0x27 + (nr))
81
82#define SIS5595_REG_TEMP 0x27
83#define SIS5595_REG_TEMP_OVER 0x39
84#define SIS5595_REG_TEMP_HYST 0x3a
85
86#define SIS5595_REG_ALARM1 0x41
87
88#define SIS5595_REG_FANDIV 0x47
89
90#define SIS5595_REG_CONFIG 0x40
91
92/* Conversions. Rounding and limit checking is only done on the TO_REG
93   variants. Note that you should be a bit careful with which arguments
94   these macros are called: arguments may be evaluated more than once.
95   Fixing this is just not worth it. */
96
97#define IN_TO_REG(val)  (SENSORS_LIMIT((((val) * 10 + 8)/16),0,255))
98#define IN_FROM_REG(val) (((val) *  16) / 10)
99
100extern inline u8 FAN_TO_REG(long rpm, int div)
101{
102        if (rpm == 0)
103                return 255;
104        rpm = SENSORS_LIMIT(rpm, 1, 1000000);
105        return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1,
106                             254);
107}
108
109#define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div)))
110
111#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)<0?(((val)-5)/10):\
112                                                 ((val)+5)/10),0,255))
113#define TEMP_FROM_REG(val) (((val)>0x80?(val)-0x100:(val))*10)
114
115#define ALARMS_FROM_REG(val) (val)
116
117#define DIV_FROM_REG(val) (1 << (val))
118#define DIV_TO_REG(val) ((val)==8?3:(val)==4?2:(val)==1?0:1)
119
120/* Initial limits. To keep them sane, we use the 'standard' translation as
121   specified in the SIS5595 sheet. Use the config file to set better limits. */
122#define SIS5595_INIT_IN_0 (((1200)  * 10)/38)
123#define SIS5595_INIT_IN_1 (((500)   * 100)/168)
124#define SIS5595_INIT_IN_2 330
125#define SIS5595_INIT_IN_3 250
126
127#define SIS5595_INIT_IN_PERCENTAGE 10
128
129#define SIS5595_INIT_IN_MIN_0 \
130        (SIS5595_INIT_IN_0 - SIS5595_INIT_IN_0 * SIS5595_INIT_IN_PERCENTAGE / 100)
131#define SIS5595_INIT_IN_MAX_0 \
132        (SIS5595_INIT_IN_0 + SIS5595_INIT_IN_0 * SIS5595_INIT_IN_PERCENTAGE / 100)
133#define SIS5595_INIT_IN_MIN_1 \
134        (SIS5595_INIT_IN_1 - SIS5595_INIT_IN_1 * SIS5595_INIT_IN_PERCENTAGE / 100)
135#define SIS5595_INIT_IN_MAX_1 \
136        (SIS5595_INIT_IN_1 + SIS5595_INIT_IN_1 * SIS5595_INIT_IN_PERCENTAGE / 100)
137#define SIS5595_INIT_IN_MIN_2 \
138        (SIS5595_INIT_IN_2 - SIS5595_INIT_IN_2 * SIS5595_INIT_IN_PERCENTAGE / 100)
139#define SIS5595_INIT_IN_MAX_2 \
140        (SIS5595_INIT_IN_2 + SIS5595_INIT_IN_2 * SIS5595_INIT_IN_PERCENTAGE / 100)
141#define SIS5595_INIT_IN_MIN_3 \
142        (SIS5595_INIT_IN_3 - SIS5595_INIT_IN_3 * SIS5595_INIT_IN_PERCENTAGE / 100)
143#define SIS5595_INIT_IN_MAX_3 \
144        (SIS5595_INIT_IN_3 + SIS5595_INIT_IN_3 * SIS5595_INIT_IN_PERCENTAGE / 100)
145
146#define SIS5595_INIT_FAN_MIN_1 3000
147#define SIS5595_INIT_FAN_MIN_2 3000
148
149#define SIS5595_INIT_TEMP_OVER 600
150#define SIS5595_INIT_TEMP_HYST 500
151
152#ifdef MODULE
153extern int init_module(void);
154extern int cleanup_module(void);
155#endif                          /* MODULE */
156
157/* This module may seem overly long and complicated. In fact, it is not so
158   bad. Quite a lot of bookkeeping is done. A real driver can often cut
159   some corners. */
160
161/* For each registered SIS5595, we need to keep some data in memory. That
162   data is pointed to by sis5595_list[NR]->data. The structure itself is
163   dynamically allocated, at the same time when a new sis5595 client is
164   allocated. */
165struct sis5595_data {
166        struct semaphore lock;
167        int sysctl_id;
168
169        struct semaphore update_lock;
170        char valid;             /* !=0 if following fields are valid */
171        unsigned long last_updated;     /* In jiffies */
172
173        u8 in[4];               /* Register value */
174        u8 in_max[4];           /* Register value */
175        u8 in_min[4];           /* Register value */
176        u8 fan[2];              /* Register value */
177        u8 fan_min[2];          /* Register value */
178        u8 temp;                /* Register value */
179        u8 temp_over;           /* Register value */
180        u8 temp_hyst;           /* Register value */
181        u8 fan_div[2];          /* Register encoding, shifted right */
182        u8 alarms;              /* Register encoding, combined */
183};
184
185
186#ifdef MODULE
187static
188#else
189extern
190#endif
191int __init sensors_sis5595_init(void);
192static int __init sis5595_cleanup(void);
193
194static int sis5595_attach_adapter(struct i2c_adapter *adapter);
195static int sis5595_detect(struct i2c_adapter *adapter, int address,
196                          unsigned short flags, int kind);
197static int sis5595_detach_client(struct i2c_client *client);
198static int sis5595_command(struct i2c_client *client, unsigned int cmd,
199                           void *arg);
200static void sis5595_inc_use(struct i2c_client *client);
201static void sis5595_dec_use(struct i2c_client *client);
202
203static int sis5595_read_value(struct i2c_client *client, u8 register);
204static int sis5595_write_value(struct i2c_client *client, u8 register,
205                               u8 value);
206static void sis5595_update_client(struct i2c_client *client);
207static void sis5595_init_client(struct i2c_client *client);
208static int sis5595_find_sis(int *address);
209
210
211static void sis5595_in(struct i2c_client *client, int operation,
212                       int ctl_name, int *nrels_mag, long *results);
213static void sis5595_fan(struct i2c_client *client, int operation,
214                        int ctl_name, int *nrels_mag, long *results);
215static void sis5595_temp(struct i2c_client *client, int operation,
216                         int ctl_name, int *nrels_mag, long *results);
217static void sis5595_alarms(struct i2c_client *client, int operation,
218                           int ctl_name, int *nrels_mag, long *results);
219static void sis5595_fan_div(struct i2c_client *client, int operation,
220                            int ctl_name, int *nrels_mag, long *results);
221
222static int sis5595_id = 0;
223
224/* The driver. I choose to use type i2c_driver, as at is identical to both
225   smbus_driver and isa_driver, and clients could be of either kind */
226static struct i2c_driver sis5595_driver = {
227        /* name */ "SiS 5595",
228        /* id */ I2C_DRIVERID_SIS5595,
229        /* flags */ I2C_DF_NOTIFY,
230        /* attach_adapter */ &sis5595_attach_adapter,
231        /* detach_client */ &sis5595_detach_client,
232        /* command */ &sis5595_command,
233        /* inc_use */ &sis5595_inc_use,
234        /* dec_use */ &sis5595_dec_use
235};
236
237/* Used by sis5595_init/cleanup */
238static int __initdata sis5595_initialized = 0;
239
240/* The /proc/sys entries */
241/* These files are created for each detected SIS5595. This is just a template;
242   though at first sight, you might think we could use a statically
243   allocated list, we need some way to get back to the parent - which
244   is done through one of the 'extra' fields which are initialized
245   when a new copy is allocated. */
246static ctl_table sis5595_dir_table_template[] = {
247        {SIS5595_SYSCTL_IN0, "in0", NULL, 0, 0644, NULL, &sensors_proc_real,
248         &sensors_sysctl_real, NULL, &sis5595_in},
249        {SIS5595_SYSCTL_IN1, "in1", NULL, 0, 0644, NULL, &sensors_proc_real,
250         &sensors_sysctl_real, NULL, &sis5595_in},
251        {SIS5595_SYSCTL_IN2, "in2", NULL, 0, 0644, NULL, &sensors_proc_real,
252         &sensors_sysctl_real, NULL, &sis5595_in},
253        {SIS5595_SYSCTL_IN3, "in3", NULL, 0, 0644, NULL, &sensors_proc_real,
254         &sensors_sysctl_real, NULL, &sis5595_in},
255        {SIS5595_SYSCTL_FAN1, "fan1", NULL, 0, 0644, NULL, &sensors_proc_real,
256         &sensors_sysctl_real, NULL, &sis5595_fan},
257        {SIS5595_SYSCTL_FAN2, "fan2", NULL, 0, 0644, NULL, &sensors_proc_real,
258         &sensors_sysctl_real, NULL, &sis5595_fan},
259        {SIS5595_SYSCTL_TEMP, "temp", NULL, 0, 0644, NULL, &sensors_proc_real,
260         &sensors_sysctl_real, NULL, &sis5595_temp},
261        {SIS5595_SYSCTL_FAN_DIV, "fan_div", NULL, 0, 0644, NULL, &sensors_proc_real,
262         &sensors_sysctl_real, NULL, &sis5595_fan_div},
263        {SIS5595_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &sensors_proc_real,
264         &sensors_sysctl_real, NULL, &sis5595_alarms},
265        {0}
266};
267
268/* This is called when the module is loaded */
269int sis5595_attach_adapter(struct i2c_adapter *adapter)
270{
271        return sensors_detect(adapter, &addr_data, sis5595_detect);
272}
273
274/* Locate SiS bridge and correct base address for SIS5595 */
275int sis5595_find_sis(int *address)
276{
277        struct pci_dev *s_bridge;
278        u16 val;
279
280        if (!pci_present())
281                return -ENODEV;
282
283        if (!
284            (s_bridge =
285             pci_find_device(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503,
286                             NULL)))
287
288                return -ENODEV;
289
290
291        if (PCIBIOS_SUCCESSFUL !=
292            pci_read_config_word(s_bridge, SIS5595_BASE_REG, &val))
293                return -ENODEV;
294
295        *address = (val & 0xfff8);
296        return 0;
297}
298
299int sis5595_detect(struct i2c_adapter *adapter, int address,
300                   unsigned short flags, int kind)
301{
302        int i;
303        struct i2c_client *new_client;
304        struct sis5595_data *data;
305        int err = 0;
306        const char *type_name = "";
307        const char *client_name = "";
308
309        /* Make sure we are probing the ISA bus!!  */
310        if (!i2c_is_isa_adapter(adapter)) {
311                printk
312                    ("sis5595.o: sis5595_detect called for an I2C bus adapter?!?\n");
313                return 0;
314        }
315
316        if (check_region(address, SIS5595_EXTENT))
317                goto ERROR0;
318
319        /* If this is the address as indicated by the SIS5595 chipset, we don't
320           do any futher probing */
321        if ((kind < 0) && (address == normal_isa[0]))
322                kind = 0;
323
324        /* Probe whether there is anything available on this address. */
325        if (kind < 0) {
326#define REALLY_SLOW_IO
327                /* We need the timeouts for at least some LM78-like chips. But only
328                   if we read 'undefined' registers. */
329                i = inb_p(address + 1);
330                if (inb_p(address + 2) != i)
331                        goto ERROR0;
332                if (inb_p(address + 3) != i)
333                        goto ERROR0;
334                if (inb_p(address + 7) != i)
335                        goto ERROR0;
336#undef REALLY_SLOW_IO
337
338                /* Let's just hope nothing breaks here */
339                i = inb_p(address + 5) & 0x7f;
340                outb_p(~i & 0x7f, address + 5);
341                if ((inb_p(address + 5) & 0x7f) != (~i & 0x7f)) {
342                        outb_p(i, address + 5);
343                        return 0;
344                }
345        }
346
347        /* OK. For now, we presume we have a valid client. We now create the
348           client structure, even though we cannot fill it completely yet.
349           But it allows us to access sis5595_{read,write}_value. */
350
351        if (!(new_client = kmalloc(sizeof(struct i2c_client) +
352                                   sizeof(struct sis5595_data),
353                                   GFP_KERNEL))) {
354                err = -ENOMEM;
355                goto ERROR0;
356        }
357
358        data = (struct sis5595_data *) (new_client + 1);
359        new_client->addr = address;
360        init_MUTEX(&data->lock);
361        new_client->data = data;
362        new_client->adapter = adapter;
363        new_client->driver = &sis5595_driver;
364        new_client->flags = 0;
365
366        /* Now, we do the remaining detection. */
367
368        if (kind < 0) {
369                if (sis5595_read_value(new_client, SIS5595_REG_CONFIG) &
370                    0x80) goto ERROR1;
371        }
372
373        /* Determine the chip type. */
374        if (kind <= 0)
375                kind = sis5595;
376
377        if (kind == sis5595) {
378                type_name = "sis5595";
379                client_name = "SIS5595 chip";
380        } else {
381#ifdef DEBUG
382                printk("sis5595.o: Internal error: unknown kind (%d)?!?",
383                       kind);
384#endif
385                goto ERROR1;
386        }
387
388        /* Reserve the ISA region */
389        request_region(address, SIS5595_EXTENT, type_name);
390
391        /* Fill in the remaining client fields and put it into the global list */
392        strcpy(new_client->name, client_name);
393
394        new_client->id = sis5595_id++;
395        data->valid = 0;
396        init_MUTEX(&data->update_lock);
397
398        /* Tell the I2C layer a new client has arrived */
399        if ((err = i2c_attach_client(new_client)))
400                goto ERROR3;
401
402        /* Register a new directory entry with module sensors */
403        if ((i = sensors_register_entry((struct i2c_client *) new_client,
404                                        type_name,
405                                        sis5595_dir_table_template,
406                                        THIS_MODULE)) < 0) {
407                err = i;
408                goto ERROR4;
409        }
410        data->sysctl_id = i;
411
412        /* Initialize the SIS5595 chip */
413        sis5595_init_client(new_client);
414        return 0;
415
416/* OK, this is not exactly good programming practice, usually. But it is
417   very code-efficient in this case. */
418
419      ERROR4:
420        i2c_detach_client(new_client);
421      ERROR3:
422        release_region(address, SIS5595_EXTENT);
423      ERROR1:
424        kfree(new_client);
425      ERROR0:
426        return err;
427}
428
429int sis5595_detach_client(struct i2c_client *client)
430{
431        int err;
432
433        sensors_deregister_entry(((struct sis5595_data *) (client->data))->
434                                 sysctl_id);
435
436        if ((err = i2c_detach_client(client))) {
437                printk
438                    ("sis5595.o: Client deregistration failed, client not detached.\n");
439                return err;
440        }
441
442        release_region(client->addr, SIS5595_EXTENT);
443        kfree(client);
444
445        return 0;
446}
447
448/* No commands defined yet */
449int sis5595_command(struct i2c_client *client, unsigned int cmd, void *arg)
450{
451        return 0;
452}
453
454/* Nothing here yet */
455void sis5595_inc_use(struct i2c_client *client)
456{
457#ifdef MODULE
458        MOD_INC_USE_COUNT;
459#endif
460}
461
462/* Nothing here yet */
463void sis5595_dec_use(struct i2c_client *client)
464{
465#ifdef MODULE
466        MOD_DEC_USE_COUNT;
467#endif
468}
469
470
471/* The SMBus locks itself, but ISA access must be locked explicitely!
472   There are some ugly typecasts here, but the good new is - they should
473   nowhere else be necessary! */
474int sis5595_read_value(struct i2c_client *client, u8 reg)
475{
476        int res;
477
478        down(&(((struct sis5595_data *) (client->data))->lock));
479        outb_p(reg, client->addr + SIS5595_ADDR_REG_OFFSET);
480        res = inb_p(client->addr + SIS5595_DATA_REG_OFFSET);
481        up(&(((struct sis5595_data *) (client->data))->lock));
482        return res;
483}
484
485/* The SMBus locks itself, but ISA access muse be locked explicitely!
486   There are some ugly typecasts here, but the good new is - they should
487   nowhere else be necessary! */
488int sis5595_write_value(struct i2c_client *client, u8 reg, u8 value)
489{
490        down(&(((struct sis5595_data *) (client->data))->lock));
491        outb_p(reg, client->addr + SIS5595_ADDR_REG_OFFSET);
492        outb_p(value, client->addr + SIS5595_DATA_REG_OFFSET);
493        up(&(((struct sis5595_data *) (client->data))->lock));
494        return 0;
495}
496
497/* Called when we have found a new SIS5595. It should set limits, etc. */
498void sis5595_init_client(struct i2c_client *client)
499{
500        /* Reset all except Watchdog values and last conversion values
501           This sets fan-divs to 2, among others */
502        sis5595_write_value(client, SIS5595_REG_CONFIG, 0x80);
503
504        sis5595_write_value(client, SIS5595_REG_IN_MIN(0),
505                            IN_TO_REG(SIS5595_INIT_IN_MIN_0));
506        sis5595_write_value(client, SIS5595_REG_IN_MAX(0),
507                            IN_TO_REG(SIS5595_INIT_IN_MAX_0));
508        sis5595_write_value(client, SIS5595_REG_IN_MIN(1),
509                            IN_TO_REG(SIS5595_INIT_IN_MIN_1));
510        sis5595_write_value(client, SIS5595_REG_IN_MAX(1),
511                            IN_TO_REG(SIS5595_INIT_IN_MAX_1));
512        sis5595_write_value(client, SIS5595_REG_IN_MIN(2),
513                            IN_TO_REG(SIS5595_INIT_IN_MIN_2));
514        sis5595_write_value(client, SIS5595_REG_IN_MAX(2),
515                            IN_TO_REG(SIS5595_INIT_IN_MAX_2));
516        sis5595_write_value(client, SIS5595_REG_IN_MIN(3),
517                            IN_TO_REG(SIS5595_INIT_IN_MIN_3));
518        sis5595_write_value(client, SIS5595_REG_IN_MAX(3),
519                            IN_TO_REG(SIS5595_INIT_IN_MAX_3));
520        sis5595_write_value(client, SIS5595_REG_FAN_MIN(1),
521                            FAN_TO_REG(SIS5595_INIT_FAN_MIN_1, 2));
522        sis5595_write_value(client, SIS5595_REG_FAN_MIN(2),
523                            FAN_TO_REG(SIS5595_INIT_FAN_MIN_2, 2));
524        sis5595_write_value(client, SIS5595_REG_TEMP_OVER,
525                            TEMP_TO_REG(SIS5595_INIT_TEMP_OVER));
526        sis5595_write_value(client, SIS5595_REG_TEMP_HYST,
527                            TEMP_TO_REG(SIS5595_INIT_TEMP_HYST));
528
529        /* Start monitoring */
530        sis5595_write_value(client, SIS5595_REG_CONFIG,
531                            (sis5595_read_value(client, SIS5595_REG_CONFIG)
532                             & 0xf7) | 0x01);
533
534}
535
536void sis5595_update_client(struct i2c_client *client)
537{
538        struct sis5595_data *data = client->data;
539        int i;
540
541        down(&data->update_lock);
542
543        if ((jiffies - data->last_updated > HZ + HZ / 2) ||
544            (jiffies < data->last_updated) || !data->valid) {
545
546#ifdef DEBUG
547                printk("Starting sis5595 update\n");
548#endif
549                for (i = 0; i <= 3; i++) {
550                        data->in[i] =
551                            sis5595_read_value(client, SIS5595_REG_IN(i));
552                        data->in_min[i] =
553                            sis5595_read_value(client,
554                                               SIS5595_REG_IN_MIN(i));
555                        data->in_max[i] =
556                            sis5595_read_value(client,
557                                               SIS5595_REG_IN_MAX(i));
558                }
559                for (i = 1; i <= 2; i++) {
560                        data->fan[i - 1] =
561                            sis5595_read_value(client, SIS5595_REG_FAN(i));
562                        data->fan_min[i - 1] =
563                            sis5595_read_value(client,
564                                               SIS5595_REG_FAN_MIN(i));
565                }
566                data->temp = sis5595_read_value(client, SIS5595_REG_TEMP);
567                data->temp_over =
568                    sis5595_read_value(client, SIS5595_REG_TEMP_OVER);
569                data->temp_hyst =
570                    sis5595_read_value(client, SIS5595_REG_TEMP_HYST);
571                i = sis5595_read_value(client, SIS5595_REG_FANDIV);
572                data->fan_div[0] = (i >> 4) & 0x03;
573                data->fan_div[1] = i >> 6;
574                data->alarms =
575                    sis5595_read_value(client, SIS5595_REG_ALARM1);
576                data->last_updated = jiffies;
577                data->valid = 1;
578        }
579
580        up(&data->update_lock);
581}
582
583
584/* The next few functions are the call-back functions of the /proc/sys and
585   sysctl files. Which function is used is defined in the ctl_table in
586   the extra1 field.
587   Each function must return the magnitude (power of 10 to divide the date
588   with) if it is called with operation==SENSORS_PROC_REAL_INFO. It must
589   put a maximum of *nrels elements in results reflecting the data of this
590   file, and set *nrels to the number it actually put in it, if operation==
591   SENSORS_PROC_REAL_READ. Finally, it must get upto *nrels elements from
592   results and write them to the chip, if operations==SENSORS_PROC_REAL_WRITE.
593   Note that on SENSORS_PROC_REAL_READ, I do not check whether results is
594   large enough (by checking the incoming value of *nrels). This is not very
595   good practice, but as long as you put less than about 5 values in results,
596   you can assume it is large enough. */
597void sis5595_in(struct i2c_client *client, int operation, int ctl_name,
598                int *nrels_mag, long *results)
599{
600        struct sis5595_data *data = client->data;
601        int nr = ctl_name - SIS5595_SYSCTL_IN0;
602
603        if (operation == SENSORS_PROC_REAL_INFO)
604                *nrels_mag = 2;
605        else if (operation == SENSORS_PROC_REAL_READ) {
606                sis5595_update_client(client);
607                results[0] = IN_FROM_REG(data->in_min[nr]);
608                results[1] = IN_FROM_REG(data->in_max[nr]);
609                results[2] = IN_FROM_REG(data->in[nr]);
610                *nrels_mag = 3;
611        } else if (operation == SENSORS_PROC_REAL_WRITE) {
612                if (*nrels_mag >= 1) {
613                        data->in_min[nr] = IN_TO_REG(results[0]);
614                        sis5595_write_value(client, SIS5595_REG_IN_MIN(nr),
615                                            data->in_min[nr]);
616                }
617                if (*nrels_mag >= 2) {
618                        data->in_max[nr] = IN_TO_REG(results[1]);
619                        sis5595_write_value(client, SIS5595_REG_IN_MAX(nr),
620                                            data->in_max[nr]);
621                }
622        }
623}
624
625void sis5595_fan(struct i2c_client *client, int operation, int ctl_name,
626                 int *nrels_mag, long *results)
627{
628        struct sis5595_data *data = client->data;
629        int nr = ctl_name - SIS5595_SYSCTL_FAN1 + 1;
630
631        if (operation == SENSORS_PROC_REAL_INFO)
632                *nrels_mag = 0;
633        else if (operation == SENSORS_PROC_REAL_READ) {
634                sis5595_update_client(client);
635                results[0] = FAN_FROM_REG(data->fan_min[nr - 1],
636                                          DIV_FROM_REG(data->
637                                                       fan_div[nr - 1]));
638                results[1] =
639                    FAN_FROM_REG(data->fan[nr - 1],
640                                 DIV_FROM_REG(data->fan_div[nr - 1]));
641                *nrels_mag = 2;
642        } else if (operation == SENSORS_PROC_REAL_WRITE) {
643                if (*nrels_mag >= 1) {
644                        data->fan_min[nr - 1] = FAN_TO_REG(results[0],
645                                                           DIV_FROM_REG
646                                                           (data->
647                                                            fan_div[nr -
648                                                                    1]));
649                        sis5595_write_value(client,
650                                            SIS5595_REG_FAN_MIN(nr),
651                                            data->fan_min[nr - 1]);
652                }
653        }
654}
655
656
657void sis5595_temp(struct i2c_client *client, int operation, int ctl_name,
658                  int *nrels_mag, long *results)
659{
660        struct sis5595_data *data = client->data;
661        if (operation == SENSORS_PROC_REAL_INFO)
662                *nrels_mag = 1;
663        else if (operation == SENSORS_PROC_REAL_READ) {
664                sis5595_update_client(client);
665                results[0] = TEMP_FROM_REG(data->temp_over);
666                results[1] = TEMP_FROM_REG(data->temp_hyst);
667                results[2] = TEMP_FROM_REG(data->temp);
668                *nrels_mag = 3;
669        } else if (operation == SENSORS_PROC_REAL_WRITE) {
670                if (*nrels_mag >= 1) {
671                        data->temp_over = TEMP_TO_REG(results[0]);
672                        sis5595_write_value(client, SIS5595_REG_TEMP_OVER,
673                                            data->temp_over);
674                }
675                if (*nrels_mag >= 2) {
676                        data->temp_hyst = TEMP_TO_REG(results[1]);
677                        sis5595_write_value(client, SIS5595_REG_TEMP_HYST,
678                                            data->temp_hyst);
679                }
680        }
681}
682
683void sis5595_alarms(struct i2c_client *client, int operation, int ctl_name,
684                    int *nrels_mag, long *results)
685{
686        struct sis5595_data *data = client->data;
687        if (operation == SENSORS_PROC_REAL_INFO)
688                *nrels_mag = 0;
689        else if (operation == SENSORS_PROC_REAL_READ) {
690                sis5595_update_client(client);
691                results[0] = ALARMS_FROM_REG(data->alarms);
692                *nrels_mag = 1;
693        }
694}
695
696void sis5595_fan_div(struct i2c_client *client, int operation,
697                     int ctl_name, int *nrels_mag, long *results)
698{
699        struct sis5595_data *data = client->data;
700        int old;
701
702        if (operation == SENSORS_PROC_REAL_INFO)
703                *nrels_mag = 0;
704        else if (operation == SENSORS_PROC_REAL_READ) {
705                sis5595_update_client(client);
706                results[0] = DIV_FROM_REG(data->fan_div[0]);
707                results[1] = DIV_FROM_REG(data->fan_div[1]);
708                *nrels_mag = 2;
709        } else if (operation == SENSORS_PROC_REAL_WRITE) {
710                old = sis5595_read_value(client, SIS5595_REG_FANDIV);
711                if (*nrels_mag >= 2) {
712                        data->fan_div[1] = DIV_TO_REG(results[1]);
713                        old = (old & 0x3f) | (data->fan_div[1] << 6);
714                }
715                if (*nrels_mag >= 1) {
716                        data->fan_div[0] = DIV_TO_REG(results[0]);
717                        old = (old & 0xcf) | (data->fan_div[0] << 4);
718                        sis5595_write_value(client, SIS5595_REG_FANDIV,
719                                            old);
720                }
721        }
722}
723
724int __init sensors_sis5595_init(void)
725{
726        int res, addr;
727
728        printk("sis5595.o version %s (%s)\n", LM_VERSION, LM_DATE);
729        sis5595_initialized = 0;
730
731        if (sis5595_find_sis(&addr)) {
732                normal_isa[0] = SENSORS_ISA_END;
733                printk
734                    ("sis5595.o: Warning: No SIS5595 southbridge found!\n");
735        } else
736                normal_isa[0] = addr;
737
738        if ((res = i2c_add_driver(&sis5595_driver))) {
739                printk
740                    ("sis5595.o: Driver registration failed, module not inserted.\n");
741                sis5595_cleanup();
742                return res;
743        }
744        sis5595_initialized++;
745        return 0;
746}
747
748int __init sis5595_cleanup(void)
749{
750        int res;
751
752        if (sis5595_initialized >= 1) {
753                if ((res = i2c_del_driver(&sis5595_driver))) {
754                        printk
755                            ("sis5595.o: Driver deregistration failed, module not removed.\n");
756                        return res;
757                }
758                sis5595_initialized--;
759        }
760        return 0;
761}
762
763EXPORT_NO_SYMBOLS;
764
765#ifdef MODULE
766
767MODULE_AUTHOR("Kyösti Mälkki <kmalkki@cc.hut.fi>");
768MODULE_DESCRIPTION("SiS 5595 Sensor device");
769
770int init_module(void)
771{
772        return sensors_sis5595_init();
773}
774
775int cleanup_module(void)
776{
777        return sis5595_cleanup();
778}
779
780#endif                          /* MODULE */
Note: See TracBrowser for help on using the browser.