root/lm-sensors/trunk/kernel/chips/fscscy.c @ 1224

Revision 1224, 29.4 KB (checked in by knobi, 12 years ago)

(MKN) Add workaround for kernels that don't have I2C_DRIVERID_FSCSCY defined

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*
2    fscscy.c - Part of lm_sensors, Linux kernel modules for hardware
3             monitoring
4    Copyright (c) 2001 Hermann Jung <hej@odn.de>
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21/*
22    fujitsu siemens scylla chip,
23    module based on lm80.c, fscpos.c
24    Copyright (c) 1998, 1999  Frodo Looijaard <frodol@dds.nl>
25    and Philip Edelbrock <phil@netroedge.com>
26*/
27
28#include <linux/version.h>
29#include <linux/module.h>
30#include <linux/slab.h>
31#include <linux/proc_fs.h>
32#include <linux/ioport.h>
33#include <linux/sysctl.h>
34#include <asm/errno.h>
35#include <asm/io.h>
36#include <linux/types.h>
37#include <linux/i2c.h>
38#include "version.h"
39#include "sensors.h"
40#include <linux/init.h>
41
42/* temp. because wasn't in kernel 2.4.13 patch */
43#ifndef I2C_DRIVERID_FSCSCY
44#define I2C_DRIVERID_FSCSCY 1029
45#endif
46
47#ifdef MODULE_LICENSE
48MODULE_LICENSE("GPL");
49#endif
50
51#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18)) || \
52    (LINUX_VERSION_CODE == KERNEL_VERSION(2,3,0))
53#define init_MUTEX(s) do { *(s) = MUTEX; } while(0)
54#endif
55
56#ifndef THIS_MODULE
57#define THIS_MODULE NULL
58#endif
59
60
61/* Addresses to scan */
62static unsigned short normal_i2c[] = { 0x73, SENSORS_I2C_END };
63static unsigned short normal_i2c_range[] = { SENSORS_I2C_END };
64static unsigned int normal_isa[] = { SENSORS_ISA_END };
65static unsigned int normal_isa_range[] = { SENSORS_ISA_END };
66
67/* Insmod parameters */
68SENSORS_INSMOD_1(fscscy);
69
70/* The FSCSCY registers */
71
72/* chip identification */
73#define FSCSCY_REG_IDENT_0    0x00
74#define FSCSCY_REG_IDENT_1    0x01
75#define FSCSCY_REG_IDENT_2    0x02
76#define FSCSCY_REG_REVISION   0x03
77
78/* global control and status */
79#define FSCSCY_REG_EVENT_STATE  0x04
80#define FSCSCY_REG_CONTROL       0x05
81
82/* watchdog */
83#define FSCSCY_REG_WDOG_PRESET      0x28
84#define FSCSCY_REG_WDOG_STATE       0x23
85#define FSCSCY_REG_WDOG_CONTROL     0x21
86
87/* fan 0  */
88#define FSCSCY_REG_FAN0_MIN     0x65
89#define FSCSCY_REG_FAN0_ACT     0x6b
90#define FSCSCY_REG_FAN0_STATE   0x62
91#define FSCSCY_REG_FAN0_RIPPLE  0x6f
92
93/* fan 1  */
94#define FSCSCY_REG_FAN1_MIN     FSCSCY_REG_FAN0_MIN
95#define FSCSCY_REG_FAN1_ACT     0x6c
96#define FSCSCY_REG_FAN1_STATE   0x61
97#define FSCSCY_REG_FAN1_RIPPLE  0x6f
98
99/* fan 2  */
100#define FSCSCY_REG_FAN2_MIN     0x55
101#define FSCSCY_REG_FAN2_ACT     0x0e
102#define FSCSCY_REG_FAN2_STATE   0x0d
103#define FSCSCY_REG_FAN2_RIPPLE  0x0f
104
105/* fan 3  */
106#define FSCSCY_REG_FAN3_MIN     0xa5
107#define FSCSCY_REG_FAN3_ACT     0xab
108#define FSCSCY_REG_FAN3_STATE   0xa2
109#define FSCSCY_REG_FAN3_RIPPLE  0xaf
110
111/* fan 4  */
112#define FSCSCY_REG_FAN4_MIN     FSCSCY_REG_FAN2_MIN
113#define FSCSCY_REG_FAN4_ACT     0x5c
114#define FSCSCY_REG_FAN4_STATE   0x52
115#define FSCSCY_REG_FAN4_RIPPLE  0x0f
116
117/* fan 5  */
118#define FSCSCY_REG_FAN5_MIN     FSCSCY_REG_FAN3_MIN
119#define FSCSCY_REG_FAN5_ACT     0xbb
120#define FSCSCY_REG_FAN5_STATE   0xb2
121#define FSCSCY_REG_FAN5_RIPPLE  0xbf
122
123/* voltage supervision */
124#define FSCSCY_REG_VOLT_12       0x45
125#define FSCSCY_REG_VOLT_5        0x42
126#define FSCSCY_REG_VOLT_BATT     0x48
127
128/* temperatures */
129/* sensor 0 */
130#define FSCSCY_REG_TEMP0_ACT    0x64
131#define FSCSCY_REG_TEMP0_STATE  0x71
132#define FSCSCY_REG_TEMP0_MAX    0x76
133
134/* sensor 1 */
135#define FSCSCY_REG_TEMP1_ACT    0xD0
136#define FSCSCY_REG_TEMP1_STATE  0xD1
137#define FSCSCY_REG_TEMP1_MAX    0xD6
138
139/* sensor 2 */
140#define FSCSCY_REG_TEMP2_ACT    0x32
141#define FSCSCY_REG_TEMP2_STATE  0x81
142#define FSCSCY_REG_TEMP2_MAX    0x86
143
144/* sensor3 */
145#define FSCSCY_REG_TEMP3_ACT    0x35
146#define FSCSCY_REG_TEMP3_STATE  0x91
147#define FSCSCY_REG_TEMP3_MAX    0x96
148
149/* PCI Load */
150#define FSCSCY_REG_PCILOAD      0x1a
151
152/* Intrusion Sensor */
153#define FSCSCY_REG_INTR_STATE   0x13
154#define FSCSCY_REG_INTR_CTRL    0x12
155
156/* Conversions. Rounding and limit checking is only done on the TO_REG
157   variants. Note that you should be a bit careful with which arguments
158   these macros are called: arguments may be evaluated more than once.
159   Fixing this is just not worth it. */
160
161#define IN_TO_REG(val,nr) (SENSORS_LIMIT((val),0,255))
162#define IN_FROM_REG(val,nr) (val)
163
164/* Initial limits */
165
166#ifdef MODULE
167extern int init_module(void);
168extern int cleanup_module(void);
169#endif                          /* MODULE */
170
171/* For each registered FSCSCY, we need to keep some data in memory. That
172   data is pointed to by fscscy_list[NR]->data. The structure itself is
173   dynamically allocated, at the same time when a new fscscy client is
174   allocated. */
175struct fscscy_data {
176        int sysctl_id;
177
178        struct semaphore update_lock;
179        char valid;             /* !=0 if following fields are valid */
180        unsigned long last_updated;     /* In jiffies */
181
182        u8  revision;        /* revision of chip */
183        u8  global_event;    /* global event status */
184        u8  global_control;  /* global control register */
185        u8  watchdog[3];     /* watchdog */
186        u8  volt[3];         /* 12, 5, battery current */ 
187        u8  temp_act[4];     /* temperature */
188        u8  temp_status[4];  /* status of sensor */
189        u8  temp_max[4];     /* maximum of sensor */
190        u8  fan_act[6];      /* fans revolutions per second */
191        u8  fan_status[6];   /* fan status */
192        u8  fan_min[6];      /* fan min value for rps */
193        u8  fan_ripple[6];   /* divider for rps */
194        u8  pciload;         /* PCILoad value */
195        u8  intr_status;     /* Intrusion Status */
196        u8  intr_control;    /* Intrusion Control */
197};
198
199
200#ifdef MODULE
201static
202#else
203extern
204#endif
205int __init sensors_fscscy_init(void);
206static int __init fscscy_cleanup(void);
207
208static int fscscy_attach_adapter(struct i2c_adapter *adapter);
209static int fscscy_detect(struct i2c_adapter *adapter, int address,
210                       unsigned short flags, int kind);
211static int fscscy_detach_client(struct i2c_client *client);
212static int fscscy_command(struct i2c_client *client, unsigned int cmd,
213                        void *arg);
214static void fscscy_inc_use(struct i2c_client *client);
215static void fscscy_dec_use(struct i2c_client *client);
216
217static int fscscy_read_value(struct i2c_client *client, u8 register);
218static int fscscy_write_value(struct i2c_client *client, u8 register,
219                            u8 value);
220static void fscscy_update_client(struct i2c_client *client);
221static void fscscy_init_client(struct i2c_client *client);
222
223
224static void fscscy_in(struct i2c_client *client, int operation, int ctl_name,
225                        int *nrels_mag, long *results);
226static void fscscy_fan(struct i2c_client *client, int operation,
227                        int ctl_name, int *nrels_mag, long *results);
228static void fscscy_fan_internal(struct i2c_client *client, int operation,
229                        int ctl_name, int *nrels_mag, long *results, 
230                        int nr, int reg_state, int reg_min, int res_ripple);
231static void fscscy_temp(struct i2c_client *client, int operation,
232                        int ctl_name, int *nrels_mag, long *results);
233static void fscscy_volt(struct i2c_client *client, int operation,
234                        int ctl_name, int *nrels_mag, long *results);
235static void fscscy_wdog(struct i2c_client *client, int operation,
236                        int ctl_name, int *nrels_mag, long *results);
237static void fscscy_pciload(struct i2c_client *client, int operation,
238                        int ctl_name, int *nrels_mag, long *results);
239static void fscscy_intrusion(struct i2c_client *client, int operation,
240                        int ctl_name, int *nrels_mag, long *results);
241
242static int fscscy_id = 0;
243
244static struct i2c_driver fscscy_driver = {
245        /* name */ "FSCSCY sensor driver",
246        /* id */ I2C_DRIVERID_FSCSCY,
247        /* flags */ I2C_DF_NOTIFY,
248        /* attach_adapter */ &fscscy_attach_adapter,
249        /* detach_client */ &fscscy_detach_client,
250        /* command */ &fscscy_command,
251        /* inc_use */ &fscscy_inc_use,
252        /* dec_use */ &fscscy_dec_use
253};
254
255/* Used by fscscy_init/cleanup */
256static int __initdata fscscy_initialized = 0;
257
258/* The /proc/sys entries */
259/* These files are created for each detected FSCSCY. This is just a template;
260   though at first sight, you might think we could use a statically
261   allocated list, we need some way to get back to the parent - which
262   is done through one of the 'extra' fields which are initialized
263   when a new copy is allocated. */
264static ctl_table fscscy_dir_table_template[] = {
265        {FSCSCY_SYSCTL_REV, "rev", NULL, 0, 0444, NULL, &i2c_proc_real,
266         &i2c_sysctl_real, NULL, &fscscy_in},
267        {FSCSCY_SYSCTL_EVENT, "alarms", NULL, 0, 0444, NULL, &i2c_proc_real,
268         &i2c_sysctl_real, NULL, &fscscy_in},
269        {FSCSCY_SYSCTL_CONTROL, "control", NULL, 0, 0644, NULL, &i2c_proc_real,
270         &i2c_sysctl_real, NULL, &fscscy_in},
271        {FSCSCY_SYSCTL_TEMP0, "temp1", NULL, 0, 0644, NULL, &i2c_proc_real,
272         &i2c_sysctl_real, NULL, &fscscy_temp},
273        {FSCSCY_SYSCTL_TEMP1, "temp2", NULL, 0, 0644, NULL, &i2c_proc_real,
274         &i2c_sysctl_real, NULL, &fscscy_temp},
275        {FSCSCY_SYSCTL_TEMP2, "temp3", NULL, 0, 0644, NULL, &i2c_proc_real,
276         &i2c_sysctl_real, NULL, &fscscy_temp},
277        {FSCSCY_SYSCTL_TEMP3, "temp4", NULL, 0, 0644, NULL, &i2c_proc_real,
278         &i2c_sysctl_real, NULL, &fscscy_temp},
279        {FSCSCY_SYSCTL_VOLT0, "in0", NULL, 0, 0444, NULL, &i2c_proc_real,
280         &i2c_sysctl_real, NULL, &fscscy_volt},
281        {FSCSCY_SYSCTL_VOLT1, "in1", NULL, 0, 0444, NULL, &i2c_proc_real,
282         &i2c_sysctl_real, NULL, &fscscy_volt},
283        {FSCSCY_SYSCTL_VOLT2, "in2", NULL, 0, 0444, NULL, &i2c_proc_real,
284         &i2c_sysctl_real, NULL, &fscscy_volt},
285        {FSCSCY_SYSCTL_FAN0, "fan1", NULL, 0, 0644, NULL, &i2c_proc_real,
286         &i2c_sysctl_real, NULL, &fscscy_fan},
287        {FSCSCY_SYSCTL_FAN1, "fan2", NULL, 0, 0644, NULL, &i2c_proc_real,
288         &i2c_sysctl_real, NULL, &fscscy_fan},
289        {FSCSCY_SYSCTL_FAN2, "fan3", NULL, 0, 0644, NULL, &i2c_proc_real,
290         &i2c_sysctl_real, NULL, &fscscy_fan},
291        {FSCSCY_SYSCTL_FAN3, "fan4", NULL, 0, 0644, NULL, &i2c_proc_real,
292         &i2c_sysctl_real, NULL, &fscscy_fan},
293        {FSCSCY_SYSCTL_FAN4, "fan5", NULL, 0, 0644, NULL, &i2c_proc_real,
294         &i2c_sysctl_real, NULL, &fscscy_fan},
295        {FSCSCY_SYSCTL_FAN5, "fan6", NULL, 0, 0644, NULL, &i2c_proc_real,
296         &i2c_sysctl_real, NULL, &fscscy_fan},
297        {FSCSCY_SYSCTL_WDOG, "wdog", NULL, 0, 0644, NULL, &i2c_proc_real,
298         &i2c_sysctl_real, NULL, &fscscy_wdog},
299        {FSCSCY_SYSCTL_PCILOAD, "pciload", NULL, 0, 0444, NULL, &i2c_proc_real,
300         &i2c_sysctl_real, NULL, &fscscy_pciload},
301        {FSCSCY_SYSCTL_INTRUSION, "intrusion", NULL, 0, 0644, NULL, &i2c_proc_real,
302         &i2c_sysctl_real, NULL, &fscscy_intrusion},
303        {0}
304};
305
306int fscscy_attach_adapter(struct i2c_adapter *adapter)
307{
308        return i2c_detect(adapter, &addr_data, fscscy_detect);
309}
310
311int fscscy_detect(struct i2c_adapter *adapter, int address,
312                unsigned short flags, int kind)
313{
314        int i;
315        struct i2c_client *new_client;
316        struct fscscy_data *data;
317        int err = 0;
318        const char *type_name, *client_name;
319
320        /* Make sure we aren't probing the ISA bus!! This is just a safety check
321           at this moment; i2c_detect really won't call us. */
322#ifdef DEBUG
323        if (i2c_is_isa_adapter(adapter)) {
324                printk
325                    ("fscscy.o: fscscy_detect called for an ISA bus adapter?!?\n");
326                return 0;
327        }
328#endif
329
330        if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
331                goto ERROR0;
332
333        /* OK. For now, we presume we have a valid client. We now create the
334           client structure, even though we cannot fill it completely yet.
335           But it allows us to access fscscy_{read,write}_value. */
336        if (!(new_client = kmalloc(sizeof(struct i2c_client) +
337                                   sizeof(struct fscscy_data),
338                                   GFP_KERNEL))) {
339                err = -ENOMEM;
340                goto ERROR0;
341        }
342
343        data = (struct fscscy_data *) (new_client + 1);
344        new_client->addr = address;
345        new_client->data = data;
346        new_client->adapter = adapter;
347        new_client->driver = &fscscy_driver;
348        new_client->flags = 0;
349
350        /* Do the remaining detection unless force or force_fscscy parameter */
351        if (kind < 0) {
352                if (fscscy_read_value(new_client, FSCSCY_REG_IDENT_0) != 0x53)
353                        goto ERROR1;
354                if (fscscy_read_value(new_client, FSCSCY_REG_IDENT_1) != 0x43)
355                        goto ERROR1;
356                if (fscscy_read_value(new_client, FSCSCY_REG_IDENT_2) != 0x59)
357                        goto ERROR1;
358        }
359
360        kind = fscscy;
361
362        type_name = "fscscy";
363        client_name = "fsc scylla chip";
364
365        /* Fill in the remaining client fields and put it into the global list */
366        strcpy(new_client->name, client_name);
367
368        new_client->id = fscscy_id++;
369        data->valid = 0;
370        init_MUTEX(&data->update_lock);
371
372        /* Tell the I2C layer a new client has arrived */
373        if ((err = i2c_attach_client(new_client)))
374                goto ERROR3;
375
376        /* Register a new directory entry with module sensors */
377        if ((i = i2c_register_entry(new_client, type_name,
378                                        fscscy_dir_table_template,
379                                        THIS_MODULE)) < 0) {
380                err = i;
381                goto ERROR4;
382        }
383        data->sysctl_id = i;
384
385        fscscy_init_client(new_client);
386        return 0;
387
388/* OK, this is not exactly good programming practice, usually. But it is
389   very code-efficient in this case. */
390      ERROR4:
391        i2c_detach_client(new_client);
392      ERROR3:
393      ERROR1:
394        kfree(new_client);
395      ERROR0:
396        return err;
397}
398
399int fscscy_detach_client(struct i2c_client *client)
400{
401        int err;
402
403        i2c_deregister_entry(((struct fscscy_data *) (client->data))->
404                                 sysctl_id);
405
406        if ((err = i2c_detach_client(client))) {
407                printk
408                    ("fscscy.o: Client deregistration failed, client not detached.\n");
409                return err;
410        }
411
412        kfree(client);
413
414        return 0;
415}
416
417/* No commands defined yet */
418int fscscy_command(struct i2c_client *client, unsigned int cmd, void *arg)
419{
420        return 0;
421}
422
423void fscscy_inc_use(struct i2c_client *client)
424{
425#ifdef MODULE
426        MOD_INC_USE_COUNT;
427#endif
428}
429
430void fscscy_dec_use(struct i2c_client *client)
431{
432#ifdef MODULE
433        MOD_DEC_USE_COUNT;
434#endif
435}
436
437
438int fscscy_read_value(struct i2c_client *client, u8 reg)
439{
440#ifdef DEBUG
441        printk("fscscy: read reg 0x%02x\n",reg);
442#endif
443        return i2c_smbus_read_byte_data(client, reg);
444}
445
446int fscscy_write_value(struct i2c_client *client, u8 reg, u8 value)
447{
448#ifdef DEBUG
449        printk("fscscy: write reg 0x%02x, val 0x%02x\n",reg, value);
450#endif
451        return i2c_smbus_write_byte_data(client, reg, value);
452}
453
454/* Called when we have found a new FSCSCY. It should set limits, etc. */
455void fscscy_init_client(struct i2c_client *client)
456{
457        struct fscscy_data *data = client->data;
458
459        /* read revision from chip */
460        data->revision =  fscscy_read_value(client,FSCSCY_REG_REVISION);
461        /* setup missing fan2_min value */
462        /* data->fan_min[2] = 0xff; */
463}
464
465void fscscy_update_client(struct i2c_client *client)
466{
467        struct fscscy_data *data = client->data;
468
469        down(&data->update_lock);
470
471        if ((jiffies - data->last_updated > 2 * HZ) ||
472            (jiffies < data->last_updated) || !data->valid) {
473
474#ifdef DEBUG
475                printk("Starting fscscy update\n");
476#endif
477                data->temp_act[0] = fscscy_read_value(client, FSCSCY_REG_TEMP0_ACT);
478                data->temp_act[1] = fscscy_read_value(client, FSCSCY_REG_TEMP1_ACT);
479                data->temp_act[2] = fscscy_read_value(client, FSCSCY_REG_TEMP2_ACT);
480                data->temp_act[3] = fscscy_read_value(client, FSCSCY_REG_TEMP3_ACT);
481                data->temp_status[0] = fscscy_read_value(client, FSCSCY_REG_TEMP0_STATE);
482                data->temp_status[1] = fscscy_read_value(client, FSCSCY_REG_TEMP1_STATE);
483                data->temp_status[2] = fscscy_read_value(client, FSCSCY_REG_TEMP2_STATE);
484                data->temp_status[3] = fscscy_read_value(client, FSCSCY_REG_TEMP3_STATE);
485                data->temp_max[0] = fscscy_read_value(client, FSCSCY_REG_TEMP0_MAX);
486                data->temp_max[1] = fscscy_read_value(client, FSCSCY_REG_TEMP1_MAX);
487                data->temp_max[2] = fscscy_read_value(client, FSCSCY_REG_TEMP2_MAX);
488                data->temp_max[3] = fscscy_read_value(client, FSCSCY_REG_TEMP3_MAX);
489
490                data->volt[0] = fscscy_read_value(client, FSCSCY_REG_VOLT_12);
491                data->volt[1] = fscscy_read_value(client, FSCSCY_REG_VOLT_5);
492                data->volt[2] = fscscy_read_value(client, FSCSCY_REG_VOLT_BATT);
493
494                data->fan_act[0] = fscscy_read_value(client, FSCSCY_REG_FAN0_ACT);
495                data->fan_act[1] = fscscy_read_value(client, FSCSCY_REG_FAN1_ACT);
496                data->fan_act[2] = fscscy_read_value(client, FSCSCY_REG_FAN2_ACT);
497                data->fan_act[3] = fscscy_read_value(client, FSCSCY_REG_FAN3_ACT);
498                data->fan_act[4] = fscscy_read_value(client, FSCSCY_REG_FAN4_ACT);
499                data->fan_act[5] = fscscy_read_value(client, FSCSCY_REG_FAN5_ACT);
500                data->fan_status[0] = fscscy_read_value(client, FSCSCY_REG_FAN0_STATE);
501                data->fan_status[1] = fscscy_read_value(client, FSCSCY_REG_FAN1_STATE);
502                data->fan_status[2] = fscscy_read_value(client, FSCSCY_REG_FAN2_STATE);
503                data->fan_status[3] = fscscy_read_value(client, FSCSCY_REG_FAN3_STATE);
504                data->fan_status[4] = fscscy_read_value(client, FSCSCY_REG_FAN4_STATE);
505                data->fan_status[5] = fscscy_read_value(client, FSCSCY_REG_FAN5_STATE);
506                data->fan_min[0] = fscscy_read_value(client, FSCSCY_REG_FAN0_MIN);
507                data->fan_min[1] = fscscy_read_value(client, FSCSCY_REG_FAN1_MIN);
508                data->fan_min[2] = fscscy_read_value(client, FSCSCY_REG_FAN2_MIN);
509                data->fan_min[3] = fscscy_read_value(client, FSCSCY_REG_FAN3_MIN);
510                data->fan_min[4] = fscscy_read_value(client, FSCSCY_REG_FAN4_MIN);
511                data->fan_min[5] = fscscy_read_value(client, FSCSCY_REG_FAN5_MIN);
512                data->fan_ripple[0] = fscscy_read_value(client, FSCSCY_REG_FAN0_RIPPLE);
513                data->fan_ripple[1] = fscscy_read_value(client, FSCSCY_REG_FAN1_RIPPLE);
514                data->fan_ripple[2] = fscscy_read_value(client, FSCSCY_REG_FAN2_RIPPLE);
515                data->fan_ripple[3] = fscscy_read_value(client, FSCSCY_REG_FAN3_RIPPLE);
516                data->fan_ripple[4] = fscscy_read_value(client, FSCSCY_REG_FAN4_RIPPLE);
517                data->fan_ripple[5] = fscscy_read_value(client, FSCSCY_REG_FAN5_RIPPLE);
518
519                data->watchdog[0] = fscscy_read_value(client, FSCSCY_REG_WDOG_PRESET);
520                data->watchdog[1] = fscscy_read_value(client, FSCSCY_REG_WDOG_STATE);
521                data->watchdog[2] = fscscy_read_value(client, FSCSCY_REG_WDOG_CONTROL);
522
523                data->global_event = fscscy_read_value(client, FSCSCY_REG_EVENT_STATE);
524                data->global_control = fscscy_read_value(client, FSCSCY_REG_CONTROL);
525                data->pciload = fscscy_read_value(client, FSCSCY_REG_PCILOAD);
526                data->intr_status = fscscy_read_value(client, FSCSCY_REG_INTR_STATE);
527                data->intr_control = fscscy_read_value(client, FSCSCY_REG_INTR_CTRL);
528
529                data->last_updated = jiffies;
530                data->valid = 1;                 
531        }
532
533        up(&data->update_lock);
534}
535
536
537/* The next few functions are the call-back functions of the /proc/sys and
538   sysctl files. Which function is used is defined in the ctl_table in
539   the extra1 field.
540   Each function must return the magnitude (power of 10 to divide the date
541   with) if it is called with operation==SENSORS_PROC_REAL_INFO. It must
542   put a maximum of *nrels elements in results reflecting the data of this
543   file, and set *nrels to the number it actually put in it, if operation==
544   SENSORS_PROC_REAL_READ. Finally, it must get upto *nrels elements from
545   results and write them to the chip, if operations==SENSORS_PROC_REAL_WRITE.
546   Note that on SENSORS_PROC_REAL_READ, I do not check whether results is
547   large enough (by checking the incoming value of *nrels). This is not very
548   good practice, but as long as you put less than about 5 values in results,
549   you can assume it is large enough. */
550void fscscy_in(struct i2c_client *client, int operation, int ctl_name,
551             int *nrels_mag, long *results)
552{
553        struct fscscy_data *data = client->data;
554
555        if (operation == SENSORS_PROC_REAL_INFO)
556                *nrels_mag = 0;
557        else if (operation == SENSORS_PROC_REAL_READ) {
558                fscscy_update_client(client);
559                switch(ctl_name) {
560                        case FSCSCY_SYSCTL_REV:
561                                results[0] = data->revision ;
562                                break;
563                        case FSCSCY_SYSCTL_EVENT:
564                                results[0] = data->global_event & 0x9f; /* MKN */
565                                break;
566                        case FSCSCY_SYSCTL_CONTROL:
567                                results[0] = data->global_control & 0x19; /* MKN */
568                                break;
569                        default:
570                                printk("fscscy: ctl_name %d not supported\n",
571                                        ctl_name);
572                                *nrels_mag = 0;
573                                return;
574                }
575                *nrels_mag = 1;
576        } else if (operation == SENSORS_PROC_REAL_WRITE) {
577                if((ctl_name == FSCSCY_SYSCTL_CONTROL) && (*nrels_mag >= 1)) {
578                        data->global_control = (data->global_control & 0x18) | (results[0] & 0x01); /* MKN */
579                        printk("fscscy: writing 0x%02x to global_control\n",
580                                data->global_control);
581                        fscscy_write_value(client,FSCSCY_REG_CONTROL,
582                                data->global_control);
583                }
584                else
585                        printk("fscscy: writing to chip not supported\n");
586        }
587}
588
589#define TEMP_FROM_REG(val)    (val-128)
590
591
592void fscscy_temp(struct i2c_client *client, int operation, int ctl_name,
593               int *nrels_mag, long *results)
594{
595        struct fscscy_data *data = client->data;
596
597        if (operation == SENSORS_PROC_REAL_INFO)
598                *nrels_mag = 0;
599        else if (operation == SENSORS_PROC_REAL_READ) {
600                fscscy_update_client(client);
601                switch(ctl_name) {
602                        case FSCSCY_SYSCTL_TEMP0:
603                                results[0] = data->temp_status[0] & 0x03;
604                                results[1] = TEMP_FROM_REG(data->temp_act[0]);
605                                results[2] = TEMP_FROM_REG(data->temp_max[0]);
606                                break;
607                        case FSCSCY_SYSCTL_TEMP1:
608                                results[0] = data->temp_status[1] & 0x03;
609                                results[1] = TEMP_FROM_REG(data->temp_act[1]);
610                                results[2] = TEMP_FROM_REG(data->temp_max[1]);
611                                break;
612                        case FSCSCY_SYSCTL_TEMP2:
613                                results[0] = data->temp_status[2] & 0x03;
614                                results[1] = TEMP_FROM_REG(data->temp_act[2]);
615                                results[2] = TEMP_FROM_REG(data->temp_max[2]);
616                                break;
617                        case FSCSCY_SYSCTL_TEMP3:
618                                results[0] = data->temp_status[3] & 0x03;
619                                results[1] = TEMP_FROM_REG(data->temp_act[3]);
620                                results[2] = TEMP_FROM_REG(data->temp_max[3]);
621                                break;
622                        default:
623                                printk("fscscy: ctl_name %d not supported\n",
624                                        ctl_name);
625                                *nrels_mag = 0;
626                                return;
627                }
628                *nrels_mag = 3;
629        } else if (operation == SENSORS_PROC_REAL_WRITE) {
630                if(*nrels_mag >= 1) {
631                        switch(ctl_name) {
632                                case FSCSCY_SYSCTL_TEMP0:
633                                        data->temp_status[0] = 
634                                                (data->temp_status[0] & ~0x02) 
635                                                | (results[0] & 0x02);
636                                        printk("fscscy: writing value 0x%02x "
637                                                "to temp0_status\n",
638                                                data->temp_status[0]);
639                                        fscscy_write_value(client,
640                                                FSCSCY_REG_TEMP0_STATE,
641                                                data->temp_status[0] & 0x02);
642                                        break;
643                                case FSCSCY_SYSCTL_TEMP1:
644                                        data->temp_status[1] = (data->temp_status[1] & ~0x02) | (results[0] & 0x02);
645                                        printk("fscscy: writing value 0x%02x to temp1_status\n", data->temp_status[1]);
646                                        fscscy_write_value(client,FSCSCY_REG_TEMP1_STATE,
647                                                data->temp_status[1] & 0x02);
648                                        break;
649                                case FSCSCY_SYSCTL_TEMP2:
650                                        data->temp_status[2] = (data->temp_status[2] & ~0x02) | (results[0] & 0x02);
651                                        printk("fscscy: writing value 0x%02x to temp2_status\n", data->temp_status[2]);
652                                        fscscy_write_value(client,FSCSCY_REG_TEMP2_STATE,
653                                                data->temp_status[2] & 0x02);
654                                        break;
655                                case FSCSCY_SYSCTL_TEMP3:
656                                        data->temp_status[3] = (data->temp_status[3] & ~0x02) | (results[0] & 0x02);
657                                        printk("fscscy: writing value 0x%02x to temp3_status\n", data->temp_status[3]);
658                                        fscscy_write_value(client,FSCSCY_REG_TEMP3_STATE,
659                                                data->temp_status[3] & 0x02);
660                                        break;
661                                default:
662                                        printk("fscscy: ctl_name %d not supported\n",ctl_name);
663                        }
664                }
665                else
666                        printk("fscscy: writing to chip not supported\n");
667        }
668}
669
670#define VOLT_FROM_REG(val,mult)    (val*mult/255)
671
672void fscscy_volt(struct i2c_client *client, int operation, int ctl_name,
673               int *nrels_mag, long *results)
674{
675        struct fscscy_data *data = client->data;
676        if (operation == SENSORS_PROC_REAL_INFO)
677                *nrels_mag = 2;
678        else if (operation == SENSORS_PROC_REAL_READ) {
679                fscscy_update_client(client);
680                switch(ctl_name) {
681                        case FSCSCY_SYSCTL_VOLT0:
682                                results[0] = VOLT_FROM_REG(data->volt[0],1420);
683                                break;
684                        case FSCSCY_SYSCTL_VOLT1:
685                                results[0] = VOLT_FROM_REG(data->volt[1],660);
686                                break;
687                        case FSCSCY_SYSCTL_VOLT2:
688                                results[0] = VOLT_FROM_REG(data->volt[2],330);
689                                break;
690                        default:
691                                printk("fscscy: ctl_name %d not supported\n",
692                                        ctl_name);
693                                *nrels_mag = 0;
694                                return;
695                }
696                *nrels_mag = 1;
697        } else if (operation == SENSORS_PROC_REAL_WRITE) {
698                        printk("fscscy: writing to chip not supported\n");
699        }
700}
701
702void fscscy_fan(struct i2c_client *client, int operation, int ctl_name,
703               int *nrels_mag, long *results)
704{
705
706        switch(ctl_name) {
707                case FSCSCY_SYSCTL_FAN0:
708                        fscscy_fan_internal(client,operation,ctl_name,nrels_mag,results,
709                                0,FSCSCY_REG_FAN0_STATE,FSCSCY_REG_FAN0_MIN,
710                                FSCSCY_REG_FAN0_RIPPLE);
711                        break;
712                case FSCSCY_SYSCTL_FAN1:
713                        fscscy_fan_internal(client,operation,ctl_name,nrels_mag,results,
714                                1,FSCSCY_REG_FAN1_STATE,FSCSCY_REG_FAN1_MIN,
715                                FSCSCY_REG_FAN1_RIPPLE);
716                        break;
717                case FSCSCY_SYSCTL_FAN2:
718                        fscscy_fan_internal(client,operation,ctl_name,nrels_mag,results,
719                                2,FSCSCY_REG_FAN2_STATE,FSCSCY_REG_FAN2_MIN,
720                                FSCSCY_REG_FAN2_RIPPLE);
721                        break;
722                case FSCSCY_SYSCTL_FAN3:
723                        fscscy_fan_internal(client,operation,ctl_name,nrels_mag,results,
724                                3,FSCSCY_REG_FAN3_STATE,FSCSCY_REG_FAN3_MIN,
725                                FSCSCY_REG_FAN3_RIPPLE);
726                        break;
727                case FSCSCY_SYSCTL_FAN4:
728                        fscscy_fan_internal(client,operation,ctl_name,nrels_mag,results,
729                                4,FSCSCY_REG_FAN4_STATE,FSCSCY_REG_FAN4_MIN,
730                                FSCSCY_REG_FAN4_RIPPLE);
731                        break;
732                case FSCSCY_SYSCTL_FAN5:
733                        fscscy_fan_internal(client,operation,ctl_name,nrels_mag,results,
734                                5,FSCSCY_REG_FAN5_STATE,FSCSCY_REG_FAN5_MIN,
735                                FSCSCY_REG_FAN5_RIPPLE);
736                        break;
737                default:
738                        printk("fscscy: illegal fan nr %d\n",ctl_name);
739        }
740}
741                       
742#define RPM_FROM_REG(val)   (val*60)
743
744void fscscy_fan_internal(struct i2c_client *client, int operation, int ctl_name,
745               int *nrels_mag, long *results, int nr,
746               int reg_state, int reg_min, int reg_ripple )
747{
748        struct fscscy_data *data = client->data;
749
750        if (operation == SENSORS_PROC_REAL_INFO)
751                *nrels_mag = 0;
752        else if (operation == SENSORS_PROC_REAL_READ) {
753                fscscy_update_client(client);
754                results[0] = data->fan_status[nr] & 0x0f; /* MKN */
755                results[1] = data->fan_min[nr];
756                results[2] = data->fan_ripple[nr] & 0x03;
757                results[3] = RPM_FROM_REG(data->fan_act[nr]);
758                *nrels_mag = 4;
759        } else if (operation == SENSORS_PROC_REAL_WRITE) {
760                if(*nrels_mag >= 1) {
761                        data->fan_status[nr] = (data->fan_status[nr] & 0x0b) | results[0] & 0x04; /* MKN */
762                        printk("fscscy: writing value 0x%02x to fan%d_status\n",
763                                data->fan_status[nr],nr);
764                        fscscy_write_value(client,reg_state,
765                                data->fan_status[nr]);
766                }
767                if((*nrels_mag >= 2) && (nr != 2) && (nr != 4)) { /* MIN Speed for Fan 2/4 is not supported */
768                        data->fan_min[nr] = results[1];
769                        printk("fscscy: writing value 0x%02x to fan%d_min\n",
770                                data->fan_min[nr],nr);
771                        fscscy_write_value(client,reg_min,
772                                data->fan_min[nr]);
773                }
774                if(*nrels_mag >= 3) {
775                        if((results[2] & 0x03) == 0) {
776                                printk("fscscy: fan%d ripple 0 not allowed\n",nr);
777                                return;
778                        }
779                        data->fan_ripple[nr] = results[2] & 0x03;
780                        printk("fscscy: writing value 0x%02x to fan%d_ripple\n",
781                                data->fan_ripple[nr],nr);
782                        fscscy_write_value(client,reg_ripple,
783                                data->fan_ripple[nr]);
784                }       
785        }
786}
787
788void fscscy_wdog(struct i2c_client *client, int operation, int ctl_name,
789             int *nrels_mag, long *results)
790{
791        struct fscscy_data *data = client->data;
792
793        if (operation == SENSORS_PROC_REAL_INFO)
794                *nrels_mag = 0;
795        else if (operation == SENSORS_PROC_REAL_READ) {
796                fscscy_update_client(client);
797                results[0] = data->watchdog[0] ;
798                results[1] = data->watchdog[1] & 0x02;
799                results[2] = data->watchdog[2] & 0xb0;
800                *nrels_mag = 3;
801        } else if (operation == SENSORS_PROC_REAL_WRITE) {
802                if (*nrels_mag >= 1) {
803                        data->watchdog[0] = results[0] & 0xff;
804                        printk("fscscy: writing value 0x%02x to wdog_preset\n",
805                                data->watchdog[0]); 
806                        fscscy_write_value(client,FSCSCY_REG_WDOG_PRESET,
807                                data->watchdog[0]);
808                } 
809                if (*nrels_mag >= 2) {
810                        data->watchdog[1] = results[1] & 0x02;
811                        printk("fscscy: writing value 0x%02x to wdog_state\n",
812                                data->watchdog[1]); 
813                        fscscy_write_value(client,FSCSCY_REG_WDOG_STATE,
814                                data->watchdog[1]);
815                }
816                if (*nrels_mag >= 3) {
817                        data->watchdog[2] = results[2] & 0xb0;
818                        printk("fscscy: writing value 0x%02x to wdog_control\n",
819                                data->watchdog[2]); 
820                        fscscy_write_value(client,FSCSCY_REG_WDOG_CONTROL,
821                                data->watchdog[2]);
822                }
823        }
824}
825
826void fscscy_pciload(struct i2c_client *client, int operation, int ctl_name,
827               int *nrels_mag, long *results)
828{
829        struct fscscy_data *data = client->data;
830        if (operation == SENSORS_PROC_REAL_INFO)
831                *nrels_mag = 0;
832        else if (operation == SENSORS_PROC_REAL_READ) {
833                fscscy_update_client(client);
834                results[0] = data->pciload;
835                *nrels_mag = 1;
836        } else if (operation == SENSORS_PROC_REAL_WRITE) {
837                        printk("fscscy: writing to chip not supported\n");
838        }
839}
840
841void fscscy_intrusion(struct i2c_client *client, int operation, int ctl_name,
842             int *nrels_mag, long *results)
843{
844        struct fscscy_data *data = client->data;
845
846        if (operation == SENSORS_PROC_REAL_INFO)
847                *nrels_mag = 0;
848        else if (operation == SENSORS_PROC_REAL_READ) {
849                fscscy_update_client(client);
850                results[0] = data->intr_control & 0x80;
851                results[1] = data->intr_status & 0xc0;
852                *nrels_mag = 2;
853        } else if (operation == SENSORS_PROC_REAL_WRITE) {
854                if (*nrels_mag >= 1) {
855                        data->intr_control = results[0] & 0x80;
856                        printk("fscscy: writing value 0x%02x to intr_control\n",
857                                data->intr_control); 
858                        fscscy_write_value(client,FSCSCY_REG_INTR_CTRL,
859                                data->intr_control);
860                } 
861        }
862}
863
864int __init sensors_fscscy_init(void)
865{
866        int res;
867
868        printk("fscscy.o version %s (%s)\n", LM_VERSION, LM_DATE);
869        fscscy_initialized = 0;
870
871        if ((res = i2c_add_driver(&fscscy_driver))) {
872                printk
873                    ("fscscy.o: Driver registration failed, module not inserted.\n");
874                fscscy_cleanup();
875                return res;
876        }
877        fscscy_initialized++;
878        return 0;
879}
880
881int __init fscscy_cleanup(void)
882{
883        int res;
884
885        if (fscscy_initialized >= 1) {
886                if ((res = i2c_del_driver(&fscscy_driver))) {
887                        printk
888                            ("fscscy.o: Driver deregistration failed, module not removed.\n");
889                        return res;
890                }
891                fscscy_initialized--;
892        }
893        return 0;
894}
895
896EXPORT_NO_SYMBOLS;
897
898#ifdef MODULE
899
900MODULE_AUTHOR
901    ("Hermann Jung <hej@odn.de> based on work from Frodo Looijaard <frodol@dds.nl> and Philip Edelbrock <phil@netroedge.com>");
902MODULE_DESCRIPTION("fujitsu siemens scylla chip driver");
903
904int init_module(void)
905{
906        return sensors_fscscy_init();
907}
908
909int cleanup_module(void)
910{
911        return fscscy_cleanup();
912}
913
914#endif                          /* MODULE */
Note: See TracBrowser for help on using the browser.