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

Revision 584, 24.4 KB (checked in by frodo, 14 years ago)

`functionality' checking for clients implemented

  • 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/module.h>
24#include <linux/malloc.h>
25#include <linux/proc_fs.h>
26#include <linux/ioport.h>
27#include <linux/sysctl.h>
28#include <linux/pci.h>
29#if LINUX_VERSION_CODE < 0x020136 /* 2.1.54 */
30#include <linux/bios32.h>
31#endif
32#include <asm/errno.h>
33#include <asm/io.h>
34#include <linux/types.h>
35#include <linux/i2c.h>
36#include "version.h"
37#include "i2c-isa.h"
38#include "sensors.h"
39#include "compat.h"
40
41#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,53)
42#include <linux/init.h>
43#else
44#define __init
45#define __initdata
46#endif
47
48
49/* Addresses to scan.
50   Note that we can't determine the ISA address until we have initialized
51   our module */
52static unsigned short normal_i2c[] = {SENSORS_I2C_END};
53static unsigned short normal_i2c_range[] = {SENSORS_I2C_END};
54static unsigned int normal_isa[] = {0x0000,SENSORS_ISA_END};
55static unsigned int normal_isa_range[] = {SENSORS_ISA_END};
56
57/* Insmod parameters */
58SENSORS_INSMOD_1(sis5595);
59
60/*
61   SiS southbridge has a LM78-like chip integrated on the same IC.
62   This driver is a customized copy of lm78.c
63*/
64
65/* Many SIS5595 constants specified below */
66
67/* Length of ISA address segment */
68#define SIS5595_EXTENT 8
69#define SIS5595_BASE_REG 0x68
70
71/* Where are the ISA address/data registers relative to the base address */
72#define SIS5595_ADDR_REG_OFFSET 5
73#define SIS5595_DATA_REG_OFFSET 6
74
75/* The SIS5595 registers */
76#define SIS5595_REG_IN_MAX(nr) (0x2b + (nr) * 2)
77#define SIS5595_REG_IN_MIN(nr) (0x2c + (nr) * 2)
78#define SIS5595_REG_IN(nr) (0x20 + (nr))
79
80#define SIS5595_REG_FAN_MIN(nr) (0x3a + (nr))
81#define SIS5595_REG_FAN(nr) (0x27 + (nr))
82
83#define SIS5595_REG_TEMP 0x27
84#define SIS5595_REG_TEMP_OVER 0x39
85#define SIS5595_REG_TEMP_HYST 0x3a
86
87#define SIS5595_REG_ALARM1 0x41
88
89#define SIS5595_REG_FANDIV 0x47
90
91#define SIS5595_REG_CONFIG 0x40
92
93/* Conversions. Rounding and limit checking is only done on the TO_REG
94   variants. Note that you should be a bit careful with which arguments
95   these macros are called: arguments may be evaluated more than once.
96   Fixing this is just not worth it. */
97
98#define IN_TO_REG(val)  (SENSORS_LIMIT((((val) * 10 + 8)/16),0,255))
99#define IN_FROM_REG(val) (((val) *  16) / 10)
100
101extern inline u8 FAN_TO_REG(long rpm, int div)
102{
103  if (rpm == 0)
104    return 255;
105  rpm = SENSORS_LIMIT(rpm,1,1000000);
106  return SENSORS_LIMIT((1350000 + rpm*div/2) / (rpm*div),1,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
191       int __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, int kind);
196static int sis5595_detach_client(struct i2c_client *client);
197static int sis5595_command(struct i2c_client *client, unsigned int cmd, 
198                        void *arg);
199static void sis5595_inc_use (struct i2c_client *client);
200static void sis5595_dec_use (struct i2c_client *client);
201
202static int sis5595_read_value(struct i2c_client *client, u8 register);
203static int sis5595_write_value(struct i2c_client *client, u8 register, u8 value);
204static void sis5595_update_client(struct i2c_client *client);
205static void sis5595_init_client(struct i2c_client *client);
206static int sis5595_find_sis(int *address);
207
208
209static void sis5595_in(struct i2c_client *client, int operation, int ctl_name,
210                    int *nrels_mag, long *results);
211static void sis5595_fan(struct i2c_client *client, int operation, int ctl_name,
212                     int *nrels_mag, long *results);
213static void sis5595_temp(struct i2c_client *client, int operation, int ctl_name,
214                      int *nrels_mag, long *results);
215static void sis5595_alarms(struct i2c_client *client, int operation, int ctl_name,
216                        int *nrels_mag, long *results);
217static void sis5595_fan_div(struct i2c_client *client, int operation, int ctl_name,
218                         int *nrels_mag, long *results);
219
220static int sis5595_id = 0;
221
222/* The driver. I choose to use type i2c_driver, as at is identical to both
223   smbus_driver and isa_driver, and clients could be of either kind */
224static struct i2c_driver sis5595_driver = {
225  /* name */            "SiS 5595",
226  /* id */              I2C_DRIVERID_SIS5595,
227  /* flags */           I2C_DF_NOTIFY,
228  /* attach_adapter */  &sis5595_attach_adapter,
229  /* detach_client */   &sis5595_detach_client,
230  /* command */         &sis5595_command,
231  /* inc_use */         &sis5595_inc_use,
232  /* dec_use */         &sis5595_dec_use
233};
234
235/* Used by sis5595_init/cleanup */
236static int __initdata sis5595_initialized = 0;
237
238/* The /proc/sys entries */
239/* These files are created for each detected SIS5595. This is just a template;
240   though at first sight, you might think we could use a statically
241   allocated list, we need some way to get back to the parent - which
242   is done through one of the 'extra' fields which are initialized
243   when a new copy is allocated. */
244static ctl_table sis5595_dir_table_template[] = {
245  { SIS5595_SYSCTL_IN0, "in0", NULL, 0, 0644, NULL, &sensors_proc_real,
246    &sensors_sysctl_real, NULL, &sis5595_in },
247  { SIS5595_SYSCTL_IN1, "in1", NULL, 0, 0644, NULL, &sensors_proc_real,
248    &sensors_sysctl_real, NULL, &sis5595_in },
249  { SIS5595_SYSCTL_IN2, "in2", NULL, 0, 0644, NULL, &sensors_proc_real,
250    &sensors_sysctl_real, NULL, &sis5595_in },
251  { SIS5595_SYSCTL_IN3, "in3", NULL, 0, 0644, NULL, &sensors_proc_real,
252    &sensors_sysctl_real, NULL, &sis5595_in },
253  { SIS5595_SYSCTL_FAN1, "fan1", NULL, 0, 0644, NULL, &sensors_proc_real,
254    &sensors_sysctl_real, NULL, &sis5595_fan },
255  { SIS5595_SYSCTL_FAN2, "fan2", NULL, 0, 0644, NULL, &sensors_proc_real,
256    &sensors_sysctl_real, NULL, &sis5595_fan },
257  { SIS5595_SYSCTL_TEMP, "temp", NULL, 0, 0644, NULL, &sensors_proc_real,
258    &sensors_sysctl_real, NULL, &sis5595_temp },
259  { SIS5595_SYSCTL_FAN_DIV, "fan_div", NULL, 0, 0644, NULL, &sensors_proc_real,
260    &sensors_sysctl_real, NULL, &sis5595_fan_div },
261  { SIS5595_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &sensors_proc_real,
262    &sensors_sysctl_real, NULL, &sis5595_alarms },
263  { 0 }
264};
265
266/* This is called when the module is loaded */
267int sis5595_attach_adapter(struct i2c_adapter *adapter)
268{
269  return sensors_detect(adapter,&addr_data,sis5595_detect);
270}
271
272/* Locate SiS bridge and correct base address for SIS5595 */
273int sis5595_find_sis(int *address)
274{
275#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,54))
276  struct pci_dev *s_bridge;
277#else
278  unsigned char SIS_bus, SIS_devfn;
279#endif
280  u16 val;
281
282  if (! pci_present())
283    return -ENODEV;
284
285#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,54))
286  if (! (s_bridge = pci_find_device(
287                   PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503, NULL)))
288               
289#else
290  if(pcibios_find_device(
291                PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503, 0,
292                &SIS_bus, &SIS_devfn))
293#endif
294    return -ENODEV;
295
296
297  if ( PCIBIOS_SUCCESSFUL !=
298        pci_read_config_word_united(s_bridge, SIS_bus, SIS_devfn, 
299                                    SIS5595_BASE_REG, &val))
300    return -ENODEV;
301               
302  *address = (val & 0xfff8);
303  return 0;
304}
305
306int sis5595_detect(struct i2c_adapter *adapter, int address, int kind)
307{
308  int i;
309  struct i2c_client *new_client;
310  struct sis5595_data *data;
311  int err=0;
312  const char *type_name = "";
313  const char *client_name = "";
314
315  /* Make sure we are probing the ISA bus!!  */
316  if (!i2c_is_isa_adapter(adapter)) {
317    printk("sis5595.o: sis5595_detect called for an I2C bus adapter?!?\n");
318    return 0;
319  }
320
321  if (check_region(address,SIS5595_EXTENT))
322    goto ERROR0;
323
324  /* If this is the address as indicated by the SIS5595 chipset, we don't
325     do any futher probing */
326  if ((kind < 0) && (address == normal_isa[0]))
327    kind = 0;
328
329  /* Probe whether there is anything available on this address. */
330  if (kind < 0) {
331#define REALLY_SLOW_IO
332    /* We need the timeouts for at least some LM78-like chips. But only
333       if we read 'undefined' registers. */
334    i = inb_p(address + 1);
335    if (inb_p(address + 2) != i)
336      goto ERROR0;
337    if (inb_p(address + 3) != i)
338      goto ERROR0;
339    if (inb_p(address + 7) != i)
340      goto ERROR0;
341#undef REALLY_SLOW_IO
342
343    /* Let's just hope nothing breaks here */
344    i = inb_p(address + 5) & 0x7f;
345    outb_p(~i & 0x7f,address+5);
346    if ((inb_p(address + 5) & 0x7f) != (~i & 0x7f)) {
347      outb_p(i,address+5);
348      return 0;
349    }
350  }
351
352  /* OK. For now, we presume we have a valid client. We now create the
353     client structure, even though we cannot fill it completely yet.
354     But it allows us to access sis5595_{read,write}_value. */
355
356  if (! (new_client = kmalloc(sizeof(struct i2c_client) +
357                              sizeof(struct sis5595_data),
358                              GFP_KERNEL))) {
359    err = -ENOMEM;
360    goto ERROR0;
361  }
362
363  data = (struct sis5595_data *) (new_client + 1);
364  new_client->addr = address;
365  init_MUTEX(&data->lock);
366  new_client->data = data;
367  new_client->adapter = adapter;
368  new_client->driver = &sis5595_driver;
369
370  /* Now, we do the remaining detection. */
371
372  if (kind < 0) {
373    if (sis5595_read_value(new_client,SIS5595_REG_CONFIG) & 0x80)
374      goto ERROR1;
375  }
376
377  /* Determine the chip type. */
378  if (kind <= 0) 
379    kind = sis5595;
380
381  if (kind == sis5595) {
382    type_name = "sis5595";
383    client_name = "SIS5595 chip";
384  } else {
385#ifdef DEBUG
386    printk("sis5595.o: Internal error: unknown kind (%d)?!?",kind);
387#endif
388    goto ERROR1;
389  }
390
391  /* Reserve the ISA region */
392  request_region(address, SIS5595_EXTENT, type_name);
393
394  /* Fill in the remaining client fields and put it into the global list */
395  strcpy(new_client->name,client_name);
396
397  new_client->id = sis5595_id++;
398  data->valid = 0;
399  init_MUTEX(&data->update_lock);
400
401  /* Tell the I2C layer a new client has arrived */
402  if ((err = i2c_attach_client(new_client)))
403    goto ERROR3;
404
405  /* Register a new directory entry with module sensors */
406  if ((i = sensors_register_entry((struct i2c_client *) new_client,
407                                  type_name,
408                                  sis5595_dir_table_template)) < 0) {
409    err = i;
410    goto ERROR4;
411  }
412  data->sysctl_id = i;
413
414  /* Initialize the SIS5595 chip */
415  sis5595_init_client(new_client);
416  return 0;
417
418/* OK, this is not exactly good programming practice, usually. But it is
419   very code-efficient in this case. */
420
421ERROR4:
422  i2c_detach_client(new_client);
423ERROR3:
424  release_region(address,SIS5595_EXTENT);
425ERROR1:
426  kfree(new_client);
427ERROR0:
428  return err;
429}
430
431int sis5595_detach_client(struct i2c_client *client)
432{
433  int err;
434
435  sensors_deregister_entry(((struct sis5595_data *)(client->data))->sysctl_id);
436
437  if ((err = i2c_detach_client(client))) {
438    printk("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 semaphore *) (client->data));
479    down(& (((struct sis5595_data *) (client->data)) -> lock));
480    outb_p(reg,client->addr + SIS5595_ADDR_REG_OFFSET);
481    res = inb_p(client->addr + SIS5595_DATA_REG_OFFSET);
482    up( & (((struct sis5595_data *) (client->data)) -> lock));
483    return res;
484}
485
486/* The SMBus locks itself, but ISA access muse be locked explicitely!
487   There are some ugly typecasts here, but the good new is - they should
488   nowhere else be necessary! */
489int sis5595_write_value(struct i2c_client *client, u8 reg, u8 value)
490{
491    down(& (((struct sis5595_data *) (client->data)) -> lock));
492    outb_p(reg,client->addr + SIS5595_ADDR_REG_OFFSET);
493    outb_p(value,client->addr + SIS5595_DATA_REG_OFFSET);
494    up( & (((struct sis5595_data *) (client->data)) -> lock));
495    return 0;
496}
497
498/* Called when we have found a new SIS5595. It should set limits, etc. */
499void sis5595_init_client(struct i2c_client *client)
500{
501  /* Reset all except Watchdog values and last conversion values
502     This sets fan-divs to 2, among others */
503  sis5595_write_value(client,SIS5595_REG_CONFIG,0x80);
504
505  sis5595_write_value(client,SIS5595_REG_IN_MIN(0),IN_TO_REG(SIS5595_INIT_IN_MIN_0));
506  sis5595_write_value(client,SIS5595_REG_IN_MAX(0),IN_TO_REG(SIS5595_INIT_IN_MAX_0));
507  sis5595_write_value(client,SIS5595_REG_IN_MIN(1),IN_TO_REG(SIS5595_INIT_IN_MIN_1));
508  sis5595_write_value(client,SIS5595_REG_IN_MAX(1),IN_TO_REG(SIS5595_INIT_IN_MAX_1));
509  sis5595_write_value(client,SIS5595_REG_IN_MIN(2),IN_TO_REG(SIS5595_INIT_IN_MIN_2));
510  sis5595_write_value(client,SIS5595_REG_IN_MAX(2),IN_TO_REG(SIS5595_INIT_IN_MAX_2));
511  sis5595_write_value(client,SIS5595_REG_IN_MIN(3),IN_TO_REG(SIS5595_INIT_IN_MIN_3));
512  sis5595_write_value(client,SIS5595_REG_IN_MAX(3),IN_TO_REG(SIS5595_INIT_IN_MAX_3));
513  sis5595_write_value(client,SIS5595_REG_FAN_MIN(1),
514                   FAN_TO_REG(SIS5595_INIT_FAN_MIN_1,2));
515  sis5595_write_value(client,SIS5595_REG_FAN_MIN(2),
516                   FAN_TO_REG(SIS5595_INIT_FAN_MIN_2,2));
517  sis5595_write_value(client,SIS5595_REG_TEMP_OVER,TEMP_TO_REG(SIS5595_INIT_TEMP_OVER));
518  sis5595_write_value(client,SIS5595_REG_TEMP_HYST,TEMP_TO_REG(SIS5595_INIT_TEMP_HYST));
519
520  /* Start monitoring */
521  sis5595_write_value(client,SIS5595_REG_CONFIG,
522                   (sis5595_read_value(client,SIS5595_REG_CONFIG) & 0xf7) | 0x01);
523 
524}
525
526void sis5595_update_client(struct i2c_client *client)
527{
528  struct sis5595_data *data = client->data;
529  int i;
530
531  down(&data->update_lock);
532
533  if ((jiffies - data->last_updated > HZ+HZ/2 ) ||
534      (jiffies < data->last_updated) || ! data->valid) {
535
536#ifdef DEBUG
537    printk("Starting sis5595 update\n");
538#endif
539    for (i = 0; i <= 3; i++) {
540      data->in[i]     = sis5595_read_value(client,SIS5595_REG_IN(i));
541      data->in_min[i] = sis5595_read_value(client,SIS5595_REG_IN_MIN(i));
542      data->in_max[i] = sis5595_read_value(client,SIS5595_REG_IN_MAX(i));
543    }
544    for (i = 1; i <= 2; i++) {
545      data->fan[i-1] = sis5595_read_value(client,SIS5595_REG_FAN(i));
546      data->fan_min[i-1] = sis5595_read_value(client,SIS5595_REG_FAN_MIN(i));
547    }
548    data->temp = sis5595_read_value(client,SIS5595_REG_TEMP);
549    data->temp_over = sis5595_read_value(client,SIS5595_REG_TEMP_OVER);
550    data->temp_hyst = sis5595_read_value(client,SIS5595_REG_TEMP_HYST);
551    i = sis5595_read_value(client,SIS5595_REG_FANDIV);
552    data->fan_div[0] = (i >> 4) & 0x03;
553    data->fan_div[1] = i >> 6;
554    data->alarms = sis5595_read_value(client,SIS5595_REG_ALARM1);
555    data->last_updated = jiffies;
556    data->valid = 1;
557  }
558
559  up(&data->update_lock);
560}
561
562
563/* The next few functions are the call-back functions of the /proc/sys and
564   sysctl files. Which function is used is defined in the ctl_table in
565   the extra1 field.
566   Each function must return the magnitude (power of 10 to divide the date
567   with) if it is called with operation==SENSORS_PROC_REAL_INFO. It must
568   put a maximum of *nrels elements in results reflecting the data of this
569   file, and set *nrels to the number it actually put in it, if operation==
570   SENSORS_PROC_REAL_READ. Finally, it must get upto *nrels elements from
571   results and write them to the chip, if operations==SENSORS_PROC_REAL_WRITE.
572   Note that on SENSORS_PROC_REAL_READ, I do not check whether results is
573   large enough (by checking the incoming value of *nrels). This is not very
574   good practice, but as long as you put less than about 5 values in results,
575   you can assume it is large enough. */
576void sis5595_in(struct i2c_client *client, int operation, int ctl_name, 
577             int *nrels_mag, long *results)
578{
579  struct sis5595_data *data = client->data;
580  int nr = ctl_name - SIS5595_SYSCTL_IN0;
581
582  if (operation == SENSORS_PROC_REAL_INFO)
583    *nrels_mag = 2;
584  else if (operation == SENSORS_PROC_REAL_READ) {
585    sis5595_update_client(client);
586    results[0] = IN_FROM_REG(data->in_min[nr]);
587    results[1] = IN_FROM_REG(data->in_max[nr]);
588    results[2] = IN_FROM_REG(data->in[nr]);
589    *nrels_mag = 3;
590  } else if (operation == SENSORS_PROC_REAL_WRITE) {
591      if (*nrels_mag >= 1) {
592        data->in_min[nr] = IN_TO_REG(results[0]);
593        sis5595_write_value(client,SIS5595_REG_IN_MIN(nr),data->in_min[nr]);
594      }
595      if (*nrels_mag >= 2) {
596        data->in_max[nr] = IN_TO_REG(results[1]);
597        sis5595_write_value(client,SIS5595_REG_IN_MAX(nr),data->in_max[nr]);
598      }
599  }
600}
601
602void sis5595_fan(struct i2c_client *client, int operation, int ctl_name,
603              int *nrels_mag, long *results)
604{
605  struct sis5595_data *data = client->data;
606  int nr = ctl_name - SIS5595_SYSCTL_FAN1 + 1;
607
608  if (operation == SENSORS_PROC_REAL_INFO)
609    *nrels_mag = 0;
610  else if (operation == SENSORS_PROC_REAL_READ) {
611    sis5595_update_client(client);
612    results[0] = FAN_FROM_REG(data->fan_min[nr-1],
613                 DIV_FROM_REG(data->fan_div[nr-1]));
614    results[1] = FAN_FROM_REG(data->fan[nr-1],
615                 DIV_FROM_REG(data->fan_div[nr-1]));
616    *nrels_mag = 2;
617  } else if (operation == SENSORS_PROC_REAL_WRITE) {
618    if (*nrels_mag >= 1) {
619      data->fan_min[nr-1] = FAN_TO_REG(results[0],
620                            DIV_FROM_REG(data->fan_div[nr-1]));
621      sis5595_write_value(client,SIS5595_REG_FAN_MIN(nr),data->fan_min[nr-1]);
622    }
623  }
624}
625
626
627void sis5595_temp(struct i2c_client *client, int operation, int ctl_name,
628               int *nrels_mag, long *results)
629{
630  struct sis5595_data *data = client->data;
631  if (operation == SENSORS_PROC_REAL_INFO)
632    *nrels_mag = 1;
633  else if (operation == SENSORS_PROC_REAL_READ) {
634    sis5595_update_client(client);
635    results[0] = TEMP_FROM_REG(data->temp_over);
636    results[1] = TEMP_FROM_REG(data->temp_hyst);
637    results[2] = TEMP_FROM_REG(data->temp);
638    *nrels_mag = 3;
639  } else if (operation == SENSORS_PROC_REAL_WRITE) {
640    if (*nrels_mag >= 1) {
641      data->temp_over = TEMP_TO_REG(results[0]);
642      sis5595_write_value(client,SIS5595_REG_TEMP_OVER,data->temp_over);
643    }
644    if (*nrels_mag >= 2) {
645      data->temp_hyst = TEMP_TO_REG(results[1]);
646      sis5595_write_value(client,SIS5595_REG_TEMP_HYST,data->temp_hyst);
647    }
648  }
649}
650
651void sis5595_alarms(struct i2c_client *client, int operation, int ctl_name,
652                 int *nrels_mag, long *results)
653{
654  struct sis5595_data *data = client->data;
655  if (operation == SENSORS_PROC_REAL_INFO)
656    *nrels_mag = 0;
657  else if (operation == SENSORS_PROC_REAL_READ) {
658    sis5595_update_client(client);
659    results[0] = ALARMS_FROM_REG(data->alarms);
660    *nrels_mag = 1;
661  }
662}
663
664void sis5595_fan_div(struct i2c_client *client, int operation, int ctl_name,
665                  int *nrels_mag, long *results)
666{
667  struct sis5595_data *data = client->data;
668  int old;
669
670  if (operation == SENSORS_PROC_REAL_INFO)
671    *nrels_mag = 0;
672  else if (operation == SENSORS_PROC_REAL_READ) {
673    sis5595_update_client(client);
674    results[0] = DIV_FROM_REG(data->fan_div[0]);
675    results[1] = DIV_FROM_REG(data->fan_div[1]);
676    *nrels_mag = 2;
677  } else if (operation == SENSORS_PROC_REAL_WRITE) {
678    old = sis5595_read_value(client,SIS5595_REG_FANDIV);
679    if (*nrels_mag >= 2) {
680      data->fan_div[1] = DIV_TO_REG(results[1]);
681      old = (old & 0x3f) | (data->fan_div[1] << 6);
682    }
683    if (*nrels_mag >= 1) {
684      data->fan_div[0] = DIV_TO_REG(results[0]);
685      old = (old & 0xcf) | (data->fan_div[0] << 4);
686      sis5595_write_value(client,SIS5595_REG_FANDIV,old);
687    }
688  }
689}
690
691int __init sensors_sis5595_init(void)
692{
693  int res,addr;
694
695  printk("sis5595.o version %s (%s)\n",LM_VERSION,LM_DATE);
696  sis5595_initialized = 0;
697
698  if (sis5595_find_sis(&addr)) {
699    normal_isa[0] = SENSORS_ISA_END;
700    printk("sis5595.o: Warning: No SIS5595 southbridge found!\n");
701  } else
702    normal_isa[0] = addr;
703
704  if ((res =i2c_add_driver(&sis5595_driver))) {
705    printk("sis5595.o: Driver registration failed, module not inserted.\n");
706    sis5595_cleanup();
707    return res;
708  }
709  sis5595_initialized ++;
710  return 0;
711}
712
713int __init sis5595_cleanup(void)
714{
715  int res;
716
717  if (sis5595_initialized >= 1) {
718    if ((res = i2c_del_driver(&sis5595_driver))) {
719      printk("sis5595.o: Driver deregistration failed, module not removed.\n");
720      return res;
721    }
722    sis5595_initialized --;
723  }
724  return 0;
725}
726
727EXPORT_NO_SYMBOLS;
728
729#ifdef MODULE
730
731MODULE_AUTHOR("Kyösti Mälkki <kmalkki@cc.hut.fi>");
732MODULE_DESCRIPTION("SiS 5595 Sensor device");
733
734int init_module(void)
735{
736  return sensors_sis5595_init();
737}
738
739int cleanup_module(void)
740{
741  return sis5595_cleanup();
742}
743
744#endif /* MODULE */
745
Note: See TracBrowser for help on using the browser.