OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [char/] [i8k.c] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
2
 * i8k.c -- Linux driver for accessing the SMM BIOS on Dell laptops.
3
 *          See http://www.debian.org/~dz/i8k/ for more information
4
 *          and for latest version of this driver.
5
 *
6
 * Copyright (C) 2001  Massimo Dal Zotto <dz@debian.org>
7
 *
8
 * This program is free software; you can redistribute it and/or modify it
9
 * under the terms of the GNU General Public License as published by the
10
 * Free Software Foundation; either version 2, or (at your option) any
11
 * later version.
12
 *
13
 * This program is distributed in the hope that it will be useful, but
14
 * WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * General Public License for more details.
17
 */
18
 
19
#include <linux/module.h>
20
#include <linux/version.h>
21
#include <linux/types.h>
22
#include <linux/init.h>
23
#include <linux/proc_fs.h>
24
#include <linux/apm_bios.h>
25
#include <linux/kbd_kern.h>
26
#include <linux/kbd_ll.h>
27
#include <linux/timer.h>
28
#include <asm/uaccess.h>
29
#include <asm/io.h>
30
 
31
#include <linux/i8k.h>
32
 
33
#define I8K_VERSION             "1.13 14/05/2002"
34
 
35
#define I8K_SMM_FN_STATUS       0x0025
36
#define I8K_SMM_POWER_STATUS    0x0069
37
#define I8K_SMM_SET_FAN         0x01a3
38
#define I8K_SMM_GET_FAN         0x00a3
39
#define I8K_SMM_GET_SPEED       0x02a3
40
#define I8K_SMM_GET_TEMP        0x10a3
41
#define I8K_SMM_GET_DELL_SIG    0xffa3
42
#define I8K_SMM_BIOS_VERSION    0x00a6
43
 
44
#define I8K_FAN_MULT            30
45
#define I8K_MAX_TEMP            127
46
 
47
#define I8K_FN_NONE             0x00
48
#define I8K_FN_UP               0x01
49
#define I8K_FN_DOWN             0x02
50
#define I8K_FN_MUTE             0x04
51
#define I8K_FN_MASK             0x07
52
#define I8K_FN_SHIFT            8
53
 
54
#define I8K_POWER_AC            0x05
55
#define I8K_POWER_BATTERY       0x01
56
 
57
#define I8K_TEMPERATURE_BUG     1
58
 
59
#define DELL_SIGNATURE          "Dell Computer"
60
 
61
/* Interval between polling of keys, in jiffies. */
62
#define I8K_POLL_INTERVAL       (HZ/20)
63
#define I8K_REPEAT_DELAY        250     /* 250 ms */
64
#define I8K_REPEAT_RATE         10
65
 
66
/*
67
 * (To be escaped) Scancodes for the keys.  These were chosen to match other
68
 * "Internet" keyboards.
69
 */
70
#define I8K_KEYS_UP_SCANCODE    0x30
71
#define I8K_KEYS_DOWN_SCANCODE  0x2e
72
#define I8K_KEYS_MUTE_SCANCODE  0x20
73
 
74
static char *supported_models[] = {
75
    "Inspiron",
76
    "Latitude",
77
    NULL
78
};
79
 
80
static char system_vendor[48] = "?";
81
static char product_name [48] = "?";
82
static char bios_version [4]  = "?";
83
static char serial_number[16] = "?";
84
 
85
int force = 0;
86
int restricted = 0;
87
int handle_buttons = 0;
88
int repeat_delay = I8K_REPEAT_DELAY;
89
int repeat_rate = I8K_REPEAT_RATE;
90
int power_status = 0;
91
 
92
static struct timer_list  i8k_keys_timer;
93
 
94
MODULE_AUTHOR("Massimo Dal Zotto (dz@debian.org)");
95
MODULE_DESCRIPTION("Driver for accessing SMM BIOS on Dell laptops");
96
MODULE_LICENSE("GPL");
97
MODULE_PARM(force, "i");
98
MODULE_PARM(restricted, "i");
99
MODULE_PARM(handle_buttons, "i");
100
MODULE_PARM(repeat_delay, "i");
101
MODULE_PARM(repeat_rate, "i");
102
MODULE_PARM(power_status, "i");
103
MODULE_PARM_DESC(force, "Force loading without checking for supported models");
104
MODULE_PARM_DESC(restricted, "Allow fan control if SYS_ADMIN capability set");
105
MODULE_PARM_DESC(handle_buttons, "Generate keyboard events for i8k buttons");
106
MODULE_PARM_DESC(repeat_delay, "I8k buttons repeat delay (ms)");
107
MODULE_PARM_DESC(repeat_rate, "I8k buttons repeat rate");
108
MODULE_PARM_DESC(power_status, "Report power status in /proc/i8k");
109
 
110
static ssize_t i8k_read(struct file *, char *, size_t, loff_t *);
111
static int i8k_ioctl(struct inode *, struct file *, unsigned int,
112
                     unsigned long);
113
static void i8k_keys_set_timer(void);
114
 
115
static struct file_operations i8k_fops = {
116
    read:       i8k_read,
117
    ioctl:      i8k_ioctl,
118
};
119
 
120
typedef struct {
121
    unsigned int eax;
122
    unsigned int ebx __attribute__ ((packed));
123
    unsigned int ecx __attribute__ ((packed));
124
    unsigned int edx __attribute__ ((packed));
125
    unsigned int esi __attribute__ ((packed));
126
    unsigned int edi __attribute__ ((packed));
127
} SMMRegisters;
128
 
129
typedef struct {
130
    u8  type;
131
    u8  length;
132
    u16 handle;
133
} DMIHeader;
134
 
135
/*
136
 * Call the System Management Mode BIOS. Code provided by Jonathan Buzzard.
137
 */
138
static int i8k_smm(SMMRegisters *regs)
139
{
140
    int rc;
141
    int eax = regs->eax;
142
 
143
    asm("pushl %%eax\n\t" \
144
        "movl 0(%%eax),%%edx\n\t" \
145
        "push %%edx\n\t" \
146
        "movl 4(%%eax),%%ebx\n\t" \
147
        "movl 8(%%eax),%%ecx\n\t" \
148
        "movl 12(%%eax),%%edx\n\t" \
149
        "movl 16(%%eax),%%esi\n\t" \
150
        "movl 20(%%eax),%%edi\n\t" \
151
        "popl %%eax\n\t" \
152
        "out %%al,$0xb2\n\t" \
153
        "out %%al,$0x84\n\t" \
154
        "xchgl %%eax,(%%esp)\n\t"
155
        "movl %%ebx,4(%%eax)\n\t" \
156
        "movl %%ecx,8(%%eax)\n\t" \
157
        "movl %%edx,12(%%eax)\n\t" \
158
        "movl %%esi,16(%%eax)\n\t" \
159
        "movl %%edi,20(%%eax)\n\t" \
160
        "popl %%edx\n\t" \
161
        "movl %%edx,0(%%eax)\n\t" \
162
        "lahf\n\t" \
163
        "shrl $8,%%eax\n\t" \
164
        "andl $1,%%eax\n" \
165
        : "=a" (rc)
166
        : "a" (regs)
167
        : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
168
 
169
    if ((rc != 0) || ((regs->eax & 0xffff) == 0xffff) || (regs->eax == eax)) {
170
        return -EINVAL;
171
    }
172
 
173
    return 0;
174
}
175
 
176
/*
177
 * Read the bios version. Return the version as an integer corresponding
178
 * to the ascii value, for example "A17" is returned as 0x00413137.
179
 */
180
static int i8k_get_bios_version(void)
181
{
182
    SMMRegisters regs = { 0, 0, 0, 0, 0, 0 };
183
    int rc;
184
 
185
    regs.eax = I8K_SMM_BIOS_VERSION;
186
    if ((rc=i8k_smm(&regs)) < 0) {
187
        return rc;
188
    }
189
 
190
    return regs.eax;
191
}
192
 
193
/*
194
 * Read the machine id.
195
 */
196
static int i8k_get_serial_number(unsigned char *buff)
197
{
198
    strncpy(buff, serial_number, 16);
199
    return 0;
200
}
201
 
202
/*
203
 * Read the Fn key status.
204
 */
205
static int i8k_get_fn_status(void)
206
{
207
    SMMRegisters regs = { 0, 0, 0, 0, 0, 0 };
208
    int rc;
209
 
210
    regs.eax = I8K_SMM_FN_STATUS;
211
    if ((rc=i8k_smm(&regs)) < 0) {
212
        return rc;
213
    }
214
 
215
    switch ((regs.eax >> I8K_FN_SHIFT) & I8K_FN_MASK) {
216
    case I8K_FN_UP:
217
        return I8K_VOL_UP;
218
    case I8K_FN_DOWN:
219
        return I8K_VOL_DOWN;
220
    case I8K_FN_MUTE:
221
        return I8K_VOL_MUTE;
222
    default:
223
        return 0;
224
    }
225
}
226
 
227
/*
228
 * Read the power status.
229
 */
230
static int i8k_get_power_status(void)
231
{
232
    SMMRegisters regs = { 0, 0, 0, 0, 0, 0 };
233
    int rc;
234
 
235
    regs.eax = I8K_SMM_POWER_STATUS;
236
    if ((rc=i8k_smm(&regs)) < 0) {
237
        return rc;
238
    }
239
 
240
    switch (regs.eax & 0xff) {
241
    case I8K_POWER_AC:
242
        return I8K_AC;
243
    default:
244
        return I8K_BATTERY;
245
    }
246
}
247
 
248
/*
249
 * Read the fan status.
250
 */
251
static int i8k_get_fan_status(int fan)
252
{
253
    SMMRegisters regs = { 0, 0, 0, 0, 0, 0 };
254
    int rc;
255
 
256
    regs.eax = I8K_SMM_GET_FAN;
257
    regs.ebx = fan & 0xff;
258
    if ((rc=i8k_smm(&regs)) < 0) {
259
        return rc;
260
    }
261
 
262
    return (regs.eax & 0xff);
263
}
264
 
265
/*
266
 * Read the fan speed in RPM.
267
 */
268
static int i8k_get_fan_speed(int fan)
269
{
270
    SMMRegisters regs = { 0, 0, 0, 0, 0, 0 };
271
    int rc;
272
 
273
    regs.eax = I8K_SMM_GET_SPEED;
274
    regs.ebx = fan & 0xff;
275
    if ((rc=i8k_smm(&regs)) < 0) {
276
        return rc;
277
    }
278
 
279
    return (regs.eax & 0xffff) * I8K_FAN_MULT;
280
}
281
 
282
/*
283
 * Set the fan speed (off, low, high). Returns the new fan status.
284
 */
285
static int i8k_set_fan(int fan, int speed)
286
{
287
    SMMRegisters regs = { 0, 0, 0, 0, 0, 0 };
288
    int rc;
289
 
290
    speed = (speed < 0) ? 0 : ((speed > I8K_FAN_MAX) ? I8K_FAN_MAX : speed);
291
 
292
    regs.eax = I8K_SMM_SET_FAN;
293
    regs.ebx = (fan & 0xff) | (speed << 8);
294
    if ((rc=i8k_smm(&regs)) < 0) {
295
        return rc;
296
    }
297
 
298
    return (i8k_get_fan_status(fan));
299
}
300
 
301
/*
302
 * Read the cpu temperature.
303
 */
304
static int i8k_get_cpu_temp(void)
305
{
306
    SMMRegisters regs = { 0, 0, 0, 0, 0, 0 };
307
    int rc;
308
    int temp;
309
 
310
#ifdef I8K_TEMPERATURE_BUG
311
    static int prev = 0;
312
#endif
313
 
314
    regs.eax = I8K_SMM_GET_TEMP;
315
    if ((rc=i8k_smm(&regs)) < 0) {
316
        return rc;
317
    }
318
    temp = regs.eax & 0xff;
319
 
320
#ifdef I8K_TEMPERATURE_BUG
321
    /*
322
     * Sometimes the temperature sensor returns 0x99, which is out of range.
323
     * In this case we return (once) the previous cached value. For example:
324
     # 1003655137 00000058 00005a4b
325
     # 1003655138 00000099 00003a80 <--- 0x99 = 153 degrees
326
     # 1003655139 00000054 00005c52
327
     */
328
    if (temp > I8K_MAX_TEMP) {
329
        temp = prev;
330
        prev = I8K_MAX_TEMP;
331
    } else {
332
        prev = temp;
333
    }
334
#endif
335
 
336
    return temp;
337
}
338
 
339
static int i8k_get_dell_signature(void)
340
{
341
    SMMRegisters regs = { 0, 0, 0, 0, 0, 0 };
342
    int rc;
343
 
344
    regs.eax = I8K_SMM_GET_DELL_SIG;
345
    if ((rc=i8k_smm(&regs)) < 0) {
346
        return rc;
347
    }
348
 
349
    if ((regs.eax == 1145651527) && (regs.edx == 1145392204)) {
350
        return 0;
351
    } else {
352
        return -1;
353
    }
354
}
355
 
356
static int i8k_ioctl(struct inode *ip, struct file *fp, unsigned int cmd,
357
                     unsigned long arg)
358
{
359
    int val;
360
    int speed;
361
    unsigned char buff[16];
362
 
363
    if (!arg) {
364
        return -EINVAL;
365
    }
366
 
367
    switch (cmd) {
368
    case I8K_BIOS_VERSION:
369
        val = i8k_get_bios_version();
370
        break;
371
 
372
    case I8K_MACHINE_ID:
373
        memset(buff, 0, 16);
374
        val = i8k_get_serial_number(buff);
375
        break;
376
 
377
    case I8K_FN_STATUS:
378
        val = i8k_get_fn_status();
379
        break;
380
 
381
    case I8K_POWER_STATUS:
382
        val = i8k_get_power_status();
383
        break;
384
 
385
    case I8K_GET_TEMP:
386
        val = i8k_get_cpu_temp();
387
        break;
388
 
389
    case I8K_GET_SPEED:
390
        if (copy_from_user(&val, (int *)arg, sizeof(int))) {
391
            return -EFAULT;
392
        }
393
        val = i8k_get_fan_speed(val);
394
        break;
395
 
396
    case I8K_GET_FAN:
397
        if (copy_from_user(&val, (int *)arg, sizeof(int))) {
398
            return -EFAULT;
399
        }
400
        val = i8k_get_fan_status(val);
401
        break;
402
 
403
    case I8K_SET_FAN:
404
        if (restricted && !capable(CAP_SYS_ADMIN)) {
405
            return -EPERM;
406
        }
407
        if (copy_from_user(&val, (int *)arg, sizeof(int))) {
408
            return -EFAULT;
409
        }
410
        if (copy_from_user(&speed, (int *)arg+1, sizeof(int))) {
411
            return -EFAULT;
412
        }
413
        val = i8k_set_fan(val, speed);
414
        break;
415
 
416
    default:
417
        return -EINVAL;
418
    }
419
 
420
    if (val < 0) {
421
        return val;
422
    }
423
 
424
    switch (cmd) {
425
    case I8K_BIOS_VERSION:
426
        if (copy_to_user((int *)arg, &val, 4)) {
427
            return -EFAULT;
428
        }
429
        break;
430
    case I8K_MACHINE_ID:
431
        if (copy_to_user((int *)arg, buff, 16)) {
432
            return -EFAULT;
433
        }
434
        break;
435
    default:
436
        if (copy_to_user((int *)arg, &val, sizeof(int))) {
437
            return -EFAULT;
438
        }
439
        break;
440
    }
441
 
442
    return 0;
443
}
444
 
445
/*
446
 * Print the information for /proc/i8k.
447
 */
448
static int i8k_get_info(char *buffer, char **start, off_t fpos, int length)
449
{
450
    int n, fn_key, cpu_temp, ac_power;
451
    int left_fan, right_fan, left_speed, right_speed;
452
 
453
    cpu_temp     = i8k_get_cpu_temp();                  /* 11100 µs */
454
    left_fan     = i8k_get_fan_status(I8K_FAN_LEFT);    /*   580 µs */
455
    right_fan    = i8k_get_fan_status(I8K_FAN_RIGHT);   /*   580 µs */
456
    left_speed   = i8k_get_fan_speed(I8K_FAN_LEFT);     /*   580 µs */
457
    right_speed  = i8k_get_fan_speed(I8K_FAN_RIGHT);    /*   580 µs */
458
    fn_key       = i8k_get_fn_status();                 /*   750 µs */
459
    if (power_status) {
460
        ac_power = i8k_get_power_status();              /* 14700 µs */
461
    } else {
462
        ac_power = -1;
463
    }
464
 
465
    /*
466
     * Info:
467
     *
468
     * 1)  Format version (this will change if format changes)
469
     * 2)  BIOS version
470
     * 3)  BIOS machine ID
471
     * 4)  Cpu temperature
472
     * 5)  Left fan status
473
     * 6)  Right fan status
474
     * 7)  Left fan speed
475
     * 8)  Right fan speed
476
     * 9)  AC power
477
     * 10) Fn Key status
478
     */
479
    n = sprintf(buffer, "%s %s %s %d %d %d %d %d %d %d\n",
480
                I8K_PROC_FMT,
481
                bios_version,
482
                serial_number,
483
                cpu_temp,
484
                left_fan,
485
                right_fan,
486
                left_speed,
487
                right_speed,
488
                ac_power,
489
                fn_key);
490
 
491
    return n;
492
}
493
 
494
static ssize_t i8k_read(struct file *f, char *buffer, size_t len, loff_t *fpos)
495
{
496
    int n;
497
    char info[128];
498
 
499
    n = i8k_get_info(info, NULL, 0, 128);
500
    if (n <= 0) {
501
        return n;
502
    }
503
 
504
    if (*fpos >= n) {
505
        return 0;
506
    }
507
 
508
    if ((*fpos + len) >= n) {
509
        len = n - *fpos;
510
    }
511
 
512
    if (copy_to_user(buffer, info, len) != 0) {
513
        return -EFAULT;
514
    }
515
 
516
    *fpos += len;
517
    return len;
518
}
519
 
520
/*
521
 * i8k_keys stuff. Thanks to David Bustos <bustos@caltech.edu>
522
 */
523
 
524
static unsigned char i8k_keys_make_scancode(int x) {
525
    switch (x) {
526
    case I8K_FN_UP:     return I8K_KEYS_UP_SCANCODE;
527
    case I8K_FN_DOWN:   return I8K_KEYS_DOWN_SCANCODE;
528
    case I8K_FN_MUTE:   return I8K_KEYS_MUTE_SCANCODE;
529
    }
530
 
531
    return 0;
532
}
533
 
534
static void i8k_keys_poll(unsigned long data) {
535
    static int last = 0;
536
    static int repeat = 0;
537
 
538
    int  curr;
539
 
540
    curr = i8k_get_fn_status();
541
    if (curr >= 0) {
542
        if (curr != last) {
543
            repeat = jiffies + (HZ * repeat_delay / 1000);
544
 
545
            if (last != 0) {
546
                handle_scancode(0xe0, 0);
547
                handle_scancode(i8k_keys_make_scancode(last), 0);
548
            }
549
 
550
            if (curr != 0) {
551
                handle_scancode(0xe0, 1);
552
                handle_scancode(i8k_keys_make_scancode(curr), 1);
553
            }
554
        } else {
555
            /* Generate keyboard repeat events with current scancode -- dz */
556
            if ((curr) && (repeat_rate > 0) && (jiffies >= repeat)) {
557
                repeat = jiffies + (HZ / repeat_rate);
558
                handle_scancode(0xe0, 1);
559
                handle_scancode(i8k_keys_make_scancode(curr), 1);
560
            }
561
        }
562
 
563
        last = curr;
564
    }
565
 
566
    /* Reset the timer. */
567
    i8k_keys_set_timer();
568
}
569
 
570
static void i8k_keys_set_timer() {
571
    i8k_keys_timer.expires = jiffies + I8K_POLL_INTERVAL;
572
    add_timer(&i8k_keys_timer);
573
}
574
 
575
static char* __init string_trim(char *s, int size)
576
{
577
    int len;
578
    char *p;
579
 
580
    if ((len = strlen(s)) > size) {
581
        len = size;
582
    }
583
 
584
    for (p=s+len-1; len && (*p==' '); len--,p--) {
585
        *p = '\0';
586
    }
587
 
588
    return s;
589
}
590
 
591
/* DMI code, stolen from arch/i386/kernel/dmi_scan.c */
592
 
593
/*
594
 * |<-- dmi->length -->|
595
 * |                   |
596
 * |dmi header    s=N  | string1,\0, ..., stringN,\0, ..., \0
597
 *                |                       |
598
 *                +-----------------------+
599
 */
600
static char* __init dmi_string(DMIHeader *dmi, u8 s)
601
{
602
    u8 *p;
603
 
604
    if (!s) {
605
        return "";
606
    }
607
    s--;
608
 
609
    p = (u8 *)dmi + dmi->length;
610
    while (s > 0) {
611
        p += strlen(p);
612
        p++;
613
        s--;
614
    }
615
 
616
    return p;
617
}
618
 
619
static void __init dmi_decode(DMIHeader *dmi)
620
{
621
    u8 *data = (u8 *) dmi;
622
    char *p;
623
 
624
#ifdef I8K_DEBUG
625
    int i;
626
    printk("%08x ", (int)data);
627
    for (i=0; i<data[1] && i<64; i++) {
628
        printk("%02x ", data[i]);
629
    }
630
    printk("\n");
631
#endif
632
 
633
    switch (dmi->type) {
634
    case  0:     /* BIOS Information */
635
        p = dmi_string(dmi,data[5]);
636
        if (*p) {
637
            strncpy(bios_version, p, sizeof(bios_version));
638
            string_trim(bios_version, sizeof(bios_version));
639
        }
640
        break;
641
    case 1:     /* System Information */
642
        p = dmi_string(dmi,data[4]);
643
        if (*p) {
644
            strncpy(system_vendor, p, sizeof(system_vendor));
645
            string_trim(system_vendor, sizeof(system_vendor));
646
        }
647
        p = dmi_string(dmi,data[5]);
648
        if (*p) {
649
            strncpy(product_name, p, sizeof(product_name));
650
            string_trim(product_name, sizeof(product_name));
651
        }
652
        p = dmi_string(dmi,data[7]);
653
        if (*p) {
654
            strncpy(serial_number, p, sizeof(serial_number));
655
            string_trim(serial_number, sizeof(serial_number));
656
        }
657
        break;
658
    }
659
}
660
 
661
static int __init dmi_table(u32 base, int len, int num, void (*fn)(DMIHeader*))
662
{
663
    u8 *buf;
664
    u8 *data;
665
    DMIHeader *dmi;
666
    int i = 1;
667
 
668
    buf = ioremap(base, len);
669
    if (buf == NULL) {
670
        return -1;
671
    }
672
    data = buf;
673
 
674
    /*
675
     * Stop when we see al the items the table claimed to have
676
     * or we run off the end of the table (also happens)
677
     */
678
    while ((i<num) && ((data-buf) < len)) {
679
        dmi = (DMIHeader *)data;
680
        /*
681
         * Avoid misparsing crud if the length of the last
682
         * record is crap
683
         */
684
        if ((data-buf+dmi->length) >= len) {
685
            break;
686
        }
687
        fn(dmi);
688
        data += dmi->length;
689
        /*
690
         * Don't go off the end of the data if there is
691
         * stuff looking like string fill past the end
692
         */
693
        while (((data-buf) < len) && (*data || data[1])) {
694
            data++;
695
        }
696
        data += 2;
697
        i++;
698
    }
699
    iounmap(buf);
700
 
701
    return 0;
702
}
703
 
704
static int __init dmi_iterate(void (*decode)(DMIHeader *))
705
{
706
    unsigned char buf[20];
707
    long fp = 0x000e0000L;
708
    fp -= 16;
709
 
710
    while (fp < 0x000fffffL) {
711
        fp += 16;
712
        isa_memcpy_fromio(buf, fp, 20);
713
        if (memcmp(buf, "_DMI_", 5)==0) {
714
            u16 num  = buf[13]<<8  | buf[12];
715
            u16 len  = buf [7]<<8  | buf [6];
716
            u32 base = buf[11]<<24 | buf[10]<<16 | buf[9]<<8 | buf[8];
717
#ifdef I8K_DEBUG
718
            printk(KERN_INFO "DMI %d.%d present.\n",
719
                   buf[14]>>4, buf[14]&0x0F);
720
            printk(KERN_INFO "%d structures occupying %d bytes.\n",
721
                   buf[13]<<8 | buf[12],
722
                   buf [7]<<8 | buf[6]);
723
            printk(KERN_INFO "DMI table at 0x%08X.\n",
724
                   buf[11]<<24 | buf[10]<<16 | buf[9]<<8 | buf[8]);
725
#endif
726
            if (dmi_table(base, len, num, decode)==0) {
727
                return 0;
728
            }
729
        }
730
    }
731
    return -1;
732
}
733
/* end of DMI code */
734
 
735
/*
736
 * Get DMI information.
737
 */
738
static int __init i8k_dmi_probe(void)
739
{
740
    char **p;
741
 
742
    if (dmi_iterate(dmi_decode) != 0) {
743
        printk(KERN_INFO "i8k: unable to get DMI information\n");
744
        return -ENODEV;
745
    }
746
 
747
    if (strncmp(system_vendor,DELL_SIGNATURE,strlen(DELL_SIGNATURE)) != 0) {
748
        printk(KERN_INFO "i8k: not running on a Dell system\n");
749
        return -ENODEV;
750
    }
751
 
752
    for (p=supported_models; ; p++) {
753
        if (!*p) {
754
            printk(KERN_INFO "i8k: unsupported model: %s\n", product_name);
755
            return -ENODEV;
756
        }
757
        if (strncmp(product_name,*p,strlen(*p)) == 0) {
758
            break;
759
        }
760
    }
761
 
762
    return 0;
763
}
764
 
765
/*
766
 * Probe for the presence of a supported laptop.
767
 */
768
static int __init i8k_probe(void)
769
{
770
    char buff[4];
771
    int version;
772
    int smm_found = 0;
773
 
774
    /*
775
     * Get DMI information
776
     */
777
    if (i8k_dmi_probe() != 0) {
778
        printk(KERN_INFO "i8k: vendor=%s, model=%s, version=%s\n",
779
               system_vendor, product_name, bios_version);
780
    }
781
 
782
    /*
783
     * Get SMM Dell signature
784
     */
785
    if (i8k_get_dell_signature() != 0) {
786
        printk(KERN_INFO "i8k: unable to get SMM Dell signature\n");
787
    } else {
788
        smm_found = 1;
789
    }
790
 
791
    /*
792
     * Get SMM BIOS version.
793
     */
794
    version = i8k_get_bios_version();
795
    if (version <= 0) {
796
        printk(KERN_INFO "i8k: unable to get SMM BIOS version\n");
797
    } else {
798
        smm_found = 1;
799
        buff[0] = (version >> 16) & 0xff;
800
        buff[1] = (version >>  8) & 0xff;
801
        buff[2] = (version)       & 0xff;
802
        buff[3] = '\0';
803
        /*
804
         * If DMI BIOS version is unknown use SMM BIOS version.
805
         */
806
        if (bios_version[0] == '?') {
807
            strcpy(bios_version, buff);
808
        }
809
        /*
810
         * Check if the two versions match.
811
         */
812
        if (strncmp(buff,bios_version,sizeof(bios_version)) != 0) {
813
            printk(KERN_INFO "i8k: BIOS version mismatch: %s != %s\n",
814
                   buff, bios_version);
815
        }
816
    }
817
 
818
    if (!smm_found && !force) {
819
        return -ENODEV;
820
    }
821
 
822
    return 0;
823
}
824
 
825
#ifdef MODULE
826
static
827
#endif
828
int __init i8k_init(void)
829
{
830
    struct proc_dir_entry *proc_i8k;
831
 
832
    /* Are we running on an supported laptop? */
833
    if (i8k_probe() != 0) {
834
        return -ENODEV;
835
    }
836
 
837
    /* Register the proc entry */
838
    proc_i8k = create_proc_info_entry("i8k", 0, NULL, i8k_get_info);
839
    if (!proc_i8k) {
840
        return -ENOENT;
841
    }
842
    proc_i8k->proc_fops = &i8k_fops;
843
    SET_MODULE_OWNER(proc_i8k);
844
 
845
    printk(KERN_INFO
846
           "Dell laptop SMM driver v%s Massimo Dal Zotto (dz@debian.org)\n",
847
           I8K_VERSION);
848
 
849
    /* Register the i8k_keys timer. */
850
    if (handle_buttons) {
851
        printk(KERN_INFO
852
               "i8k: enabling buttons events, delay=%d, rate=%d\n",
853
               repeat_delay, repeat_rate);
854
        init_timer(&i8k_keys_timer);
855
        i8k_keys_timer.function = i8k_keys_poll;
856
        i8k_keys_set_timer();
857
    }
858
 
859
    return 0;
860
}
861
 
862
#ifdef MODULE
863
int init_module(void)
864
{
865
    return i8k_init();
866
}
867
 
868
void cleanup_module(void)
869
{
870
    /* Remove the proc entry */
871
    remove_proc_entry("i8k", NULL);
872
 
873
    /* Unregister the i8k_keys timer. */
874
    while (handle_buttons && !del_timer(&i8k_keys_timer)) {
875
        schedule_timeout(I8K_POLL_INTERVAL);
876
    }
877
 
878
    printk(KERN_INFO "i8k: module unloaded\n");
879
}
880
#endif
881
 
882
/* end of file */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.